summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-04-10 17:04:15 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-05-11 09:04:12 -0400
commitc3fa78b1d9cba28547ca59154207d434931ae746 (patch)
tree42117714f2d8dd217229e6c183d4b6affd29c7d1 /drivers/gpu/nvgpu/common
parent36c1fdccc994d337fc15dd2b67ff05435f37dec9 (diff)
gpu: nvgpu: Separate GMMU out of mm_gk20a.c
Begin moving (and renaming) the GMMU code into common/mm/gmmu.c. This block of code will be responsible for handling the platform/OS independent GMMU operations. JIRA NVGPU-12 JIRA NVGPU-30 Change-Id: Ide761bab75e5d84be3dcb977c4842ae4b3a7c1b3 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1464083 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r--drivers/gpu/nvgpu/common/linux/dma.c10
-rw-r--r--drivers/gpu/nvgpu/common/linux/ioctl_as.c2
-rw-r--r--drivers/gpu/nvgpu/common/mm/gmmu.c109
-rw-r--r--drivers/gpu/nvgpu/common/semaphore.c20
4 files changed, 122 insertions, 19 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/dma.c b/drivers/gpu/nvgpu/common/linux/dma.c
index eb2d0ac4..d3d51f18 100644
--- a/drivers/gpu/nvgpu/common/linux/dma.c
+++ b/drivers/gpu/nvgpu/common/linux/dma.c
@@ -20,6 +20,7 @@
20#include <nvgpu/dma.h> 20#include <nvgpu/dma.h>
21#include <nvgpu/lock.h> 21#include <nvgpu/lock.h>
22#include <nvgpu/bug.h> 22#include <nvgpu/bug.h>
23#include <nvgpu/gmmu.h>
23 24
24#include <nvgpu/linux/dma.h> 25#include <nvgpu/linux/dma.h>
25 26
@@ -71,7 +72,7 @@ int nvgpu_dma_alloc_flags(struct gk20a *g, unsigned long flags, size_t size,
71 /* 72 /*
72 * Force the no-kernel-mapping flag on because we don't support 73 * Force the no-kernel-mapping flag on because we don't support
73 * the lack of it for vidmem - the user should not care when 74 * the lack of it for vidmem - the user should not care when
74 * using gk20a_gmmu_alloc_map and it's vidmem, or if there's a 75 * using nvgpu_gmmu_alloc_map and it's vidmem, or if there's a
75 * difference, the user should use the flag explicitly anyway. 76 * difference, the user should use the flag explicitly anyway.
76 */ 77 */
77 int err = nvgpu_dma_alloc_flags_vid(g, 78 int err = nvgpu_dma_alloc_flags_vid(g,
@@ -285,7 +286,7 @@ int nvgpu_dma_alloc_map_flags_sys(struct vm_gk20a *vm, unsigned long flags,
285 if (err) 286 if (err)
286 return err; 287 return err;
287 288
288 mem->gpu_va = gk20a_gmmu_map(vm, &mem->priv.sgt, size, 0, 289 mem->gpu_va = nvgpu_gmmu_map(vm, mem, size, 0,
289 gk20a_mem_flag_none, false, 290 gk20a_mem_flag_none, false,
290 mem->aperture); 291 mem->aperture);
291 if (!mem->gpu_va) { 292 if (!mem->gpu_va) {
@@ -315,7 +316,7 @@ int nvgpu_dma_alloc_map_flags_vid(struct vm_gk20a *vm, unsigned long flags,
315 if (err) 316 if (err)
316 return err; 317 return err;
317 318
318 mem->gpu_va = gk20a_gmmu_map(vm, &mem->priv.sgt, size, 0, 319 mem->gpu_va = nvgpu_gmmu_map(vm, mem, size, 0,
319 gk20a_mem_flag_none, false, 320 gk20a_mem_flag_none, false,
320 mem->aperture); 321 mem->aperture);
321 if (!mem->gpu_va) { 322 if (!mem->gpu_va) {
@@ -420,8 +421,7 @@ void nvgpu_dma_free(struct gk20a *g, struct nvgpu_mem *mem)
420void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem) 421void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem)
421{ 422{
422 if (mem->gpu_va) 423 if (mem->gpu_va)
423 gk20a_gmmu_unmap(vm, mem->gpu_va, 424 nvgpu_gmmu_unmap(vm, mem, mem->gpu_va);
424 mem->size, gk20a_mem_flag_none);
425 mem->gpu_va = 0; 425 mem->gpu_va = 0;
426 426
427 nvgpu_dma_free(vm->mm->g, mem); 427 nvgpu_dma_free(vm->mm->g, mem);
diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_as.c b/drivers/gpu/nvgpu/common/linux/ioctl_as.c
index 6a9d3811..31d99d26 100644
--- a/drivers/gpu/nvgpu/common/linux/ioctl_as.c
+++ b/drivers/gpu/nvgpu/common/linux/ioctl_as.c
@@ -23,6 +23,8 @@
23 23
24#include <uapi/linux/nvgpu.h> 24#include <uapi/linux/nvgpu.h>
25 25
26#include <nvgpu/gmmu.h>
27
26#include "gk20a/gk20a.h" 28#include "gk20a/gk20a.h"
27#include "ioctl_as.h" 29#include "ioctl_as.h"
28 30
diff --git a/drivers/gpu/nvgpu/common/mm/gmmu.c b/drivers/gpu/nvgpu/common/mm/gmmu.c
new file mode 100644
index 00000000..a2ed3f3a
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/mm/gmmu.c
@@ -0,0 +1,109 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <nvgpu/log.h>
18#include <nvgpu/gmmu.h>
19#include <nvgpu/nvgpu_mem.h>
20
21#include "gk20a/gk20a.h"
22#include "gk20a/mm_gk20a.h"
23
24/*
25 * Core GMMU map function for the kernel to use. If @addr is 0 then the GPU
26 * VA will be allocated for you. If addr is non-zero then the buffer will be
27 * mapped at @addr.
28 */
29static u64 __nvgpu_gmmu_map(struct vm_gk20a *vm,
30 struct nvgpu_mem *mem,
31 u64 addr,
32 u64 size,
33 u32 flags,
34 int rw_flag,
35 bool priv,
36 enum nvgpu_aperture aperture)
37{
38 struct gk20a *g = gk20a_from_vm(vm);
39 u64 vaddr;
40
41 struct sg_table *sgt = mem->priv.sgt;
42
43 nvgpu_mutex_acquire(&vm->update_gmmu_lock);
44 vaddr = g->ops.mm.gmmu_map(vm, addr,
45 sgt, /* sg table */
46 0, /* sg offset */
47 size,
48 gmmu_page_size_kernel,
49 0, /* kind */
50 0, /* ctag_offset */
51 flags, rw_flag,
52 false, /* clear_ctags */
53 false, /* sparse */
54 priv, /* priv */
55 NULL, /* mapping_batch handle */
56 aperture);
57 nvgpu_mutex_release(&vm->update_gmmu_lock);
58 if (!vaddr) {
59 nvgpu_err(g, "failed to allocate va space");
60 return 0;
61 }
62
63 return vaddr;
64}
65
66u64 nvgpu_gmmu_map(struct vm_gk20a *vm,
67 struct nvgpu_mem *mem,
68 u64 size,
69 u32 flags,
70 int rw_flag,
71 bool priv,
72 enum nvgpu_aperture aperture)
73{
74 return __nvgpu_gmmu_map(vm, mem, 0, size, flags, rw_flag, priv,
75 aperture);
76}
77
78/*
79 * Like nvgpu_gmmu_map() except it can work on a fixed address instead.
80 */
81u64 nvgpu_gmmu_map_fixed(struct vm_gk20a *vm,
82 struct nvgpu_mem *mem,
83 u64 addr,
84 u64 size,
85 u32 flags,
86 int rw_flag,
87 bool priv,
88 enum nvgpu_aperture aperture)
89{
90 return __nvgpu_gmmu_map(vm, mem, addr, size, flags, rw_flag, priv,
91 aperture);
92}
93
94void nvgpu_gmmu_unmap(struct vm_gk20a *vm, struct nvgpu_mem *mem, u64 gpu_va)
95{
96 struct gk20a *g = gk20a_from_vm(vm);
97
98 nvgpu_mutex_acquire(&vm->update_gmmu_lock);
99 g->ops.mm.gmmu_unmap(vm,
100 gpu_va,
101 mem->size,
102 gmmu_page_size_kernel,
103 true, /*va_allocated */
104 gk20a_mem_flag_none,
105 false,
106 NULL);
107
108 nvgpu_mutex_release(&vm->update_gmmu_lock);
109}
diff --git a/drivers/gpu/nvgpu/common/semaphore.c b/drivers/gpu/nvgpu/common/semaphore.c
index fa86985b..a54ce831 100644
--- a/drivers/gpu/nvgpu/common/semaphore.c
+++ b/drivers/gpu/nvgpu/common/semaphore.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <nvgpu/dma.h> 16#include <nvgpu/dma.h>
17#include <nvgpu/gmmu.h>
17#include <nvgpu/semaphore.h> 18#include <nvgpu/semaphore.h>
18#include <nvgpu/kmem.h> 19#include <nvgpu/kmem.h>
19#include <nvgpu/bug.h> 20#include <nvgpu/bug.h>
@@ -197,7 +198,7 @@ int nvgpu_semaphore_pool_map(struct nvgpu_semaphore_pool *p,
197 */ 198 */
198 __lock_sema_sea(p->sema_sea); 199 __lock_sema_sea(p->sema_sea);
199 200
200 addr = gk20a_gmmu_fixed_map(vm, &p->sema_sea->sea_mem.priv.sgt, 201 addr = nvgpu_gmmu_map_fixed(vm, &p->sema_sea->sea_mem,
201 p->sema_sea->gpu_va, 202 p->sema_sea->gpu_va,
202 p->sema_sea->map_size, 203 p->sema_sea->map_size,
203 0, gk20a_mem_flag_read_only, 0, 204 0, gk20a_mem_flag_read_only, 0,
@@ -225,7 +226,7 @@ int nvgpu_semaphore_pool_map(struct nvgpu_semaphore_pool *p,
225 if (err) 226 if (err)
226 goto fail_unmap; 227 goto fail_unmap;
227 228
228 addr = gk20a_gmmu_map(vm, &p->rw_mem.priv.sgt, SZ_4K, 0, 229 addr = nvgpu_gmmu_map(vm, &p->rw_mem, SZ_4K, 0,
229 gk20a_mem_flag_none, 0, 230 gk20a_mem_flag_none, 0,
230 p->rw_mem.aperture); 231 p->rw_mem.aperture);
231 232
@@ -250,10 +251,7 @@ int nvgpu_semaphore_pool_map(struct nvgpu_semaphore_pool *p,
250fail_free_submem: 251fail_free_submem:
251 nvgpu_dma_free(pool_to_gk20a(p), &p->rw_mem); 252 nvgpu_dma_free(pool_to_gk20a(p), &p->rw_mem);
252fail_unmap: 253fail_unmap:
253 gk20a_gmmu_unmap(vm, 254 nvgpu_gmmu_unmap(vm, &p->sema_sea->sea_mem, p->gpu_va_ro);
254 p->sema_sea->sea_mem.gpu_va,
255 p->sema_sea->map_size,
256 gk20a_mem_flag_none);
257 gpu_sema_dbg(pool_to_gk20a(p), 255 gpu_sema_dbg(pool_to_gk20a(p),
258 " %d: Failed to map semaphore pool!", p->page_idx); 256 " %d: Failed to map semaphore pool!", p->page_idx);
259fail_unlock: 257fail_unlock:
@@ -269,14 +267,8 @@ void nvgpu_semaphore_pool_unmap(struct nvgpu_semaphore_pool *p,
269{ 267{
270 __lock_sema_sea(p->sema_sea); 268 __lock_sema_sea(p->sema_sea);
271 269
272 gk20a_gmmu_unmap(vm, 270 nvgpu_gmmu_unmap(vm, &p->sema_sea->sea_mem, p->gpu_va_ro);
273 p->sema_sea->sea_mem.gpu_va, 271 nvgpu_gmmu_unmap(vm, &p->rw_mem, p->gpu_va);
274 p->sema_sea->sea_mem.size,
275 gk20a_mem_flag_none);
276 gk20a_gmmu_unmap(vm,
277 p->rw_mem.gpu_va,
278 p->rw_mem.size,
279 gk20a_mem_flag_none);
280 nvgpu_dma_free(pool_to_gk20a(p), &p->rw_mem); 272 nvgpu_dma_free(pool_to_gk20a(p), &p->rw_mem);
281 273
282 p->gpu_va = 0; 274 p->gpu_va = 0;