diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpu/nvgpu/Makefile | 3 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/Makefile.sources | 3 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/dma.c (renamed from drivers/gpu/nvgpu/os/posix/dma.c) | 107 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/dma.h | 6 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/os/linux/linux-dma.c (renamed from drivers/gpu/nvgpu/os/linux/dma.c) | 173 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/os/posix/posix-dma.c | 88 |
6 files changed, 138 insertions, 242 deletions
diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index 43a36221..a3372cef 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile | |||
@@ -65,7 +65,7 @@ nvgpu-y += \ | |||
65 | os/linux/log.o \ | 65 | os/linux/log.o \ |
66 | os/linux/cond.o \ | 66 | os/linux/cond.o \ |
67 | os/linux/nvgpu_mem.o \ | 67 | os/linux/nvgpu_mem.o \ |
68 | os/linux/dma.o \ | 68 | os/linux/linux-dma.o \ |
69 | os/linux/driver_common.o \ | 69 | os/linux/driver_common.o \ |
70 | os/linux/firmware.o \ | 70 | os/linux/firmware.o \ |
71 | os/linux/thread.o \ | 71 | os/linux/thread.o \ |
@@ -180,6 +180,7 @@ nvgpu-y += \ | |||
180 | common/mm/nvgpu_mem.o \ | 180 | common/mm/nvgpu_mem.o \ |
181 | common/mm/comptags.o \ | 181 | common/mm/comptags.o \ |
182 | common/mm/mm.o \ | 182 | common/mm/mm.o \ |
183 | common/mm/dma.o \ | ||
183 | common/enabled.o \ | 184 | common/enabled.o \ |
184 | common/nvlink.o \ | 185 | common/nvlink.o \ |
185 | common/pramin.o \ | 186 | common/pramin.o \ |
diff --git a/drivers/gpu/nvgpu/Makefile.sources b/drivers/gpu/nvgpu/Makefile.sources index f09ebf78..7dc0251b 100644 --- a/drivers/gpu/nvgpu/Makefile.sources +++ b/drivers/gpu/nvgpu/Makefile.sources | |||
@@ -27,7 +27,7 @@ srcs := os/posix/nvgpu.c \ | |||
27 | os/posix/kmem.c \ | 27 | os/posix/kmem.c \ |
28 | os/posix/io.c \ | 28 | os/posix/io.c \ |
29 | os/posix/posix-nvgpu_mem.c \ | 29 | os/posix/posix-nvgpu_mem.c \ |
30 | os/posix/dma.c \ | 30 | os/posix/posix-dma.c \ |
31 | os/posix/posix-vm.c \ | 31 | os/posix/posix-vm.c \ |
32 | os/posix/timers.c \ | 32 | os/posix/timers.c \ |
33 | os/posix/posix-comptags.c \ | 33 | os/posix/posix-comptags.c \ |
@@ -56,6 +56,7 @@ srcs := os/posix/nvgpu.c \ | |||
56 | common/mm/nvgpu_mem.c \ | 56 | common/mm/nvgpu_mem.c \ |
57 | common/mm/comptags.c \ | 57 | common/mm/comptags.c \ |
58 | common/mm/mm.c \ | 58 | common/mm/mm.c \ |
59 | common/mm/dma.c \ | ||
59 | common/bus/bus_gk20a.c \ | 60 | common/bus/bus_gk20a.c \ |
60 | common/bus/bus_gm20b.c \ | 61 | common/bus/bus_gm20b.c \ |
61 | common/bus/bus_gp10b.c \ | 62 | common/bus/bus_gp10b.c \ |
diff --git a/drivers/gpu/nvgpu/os/posix/dma.c b/drivers/gpu/nvgpu/common/mm/dma.c index 95bb1a75..f7331f8e 100644 --- a/drivers/gpu/nvgpu/os/posix/dma.c +++ b/drivers/gpu/nvgpu/common/mm/dma.c | |||
@@ -20,45 +20,12 @@ | |||
20 | * DEALINGS IN THE SOFTWARE. | 20 | * DEALINGS IN THE SOFTWARE. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <stdlib.h> | ||
24 | |||
25 | #include <nvgpu/mm.h> | 23 | #include <nvgpu/mm.h> |
26 | #include <nvgpu/vm.h> | 24 | #include <nvgpu/vm.h> |
27 | #include <nvgpu/bug.h> | ||
28 | #include <nvgpu/dma.h> | 25 | #include <nvgpu/dma.h> |
29 | #include <nvgpu/gmmu.h> | 26 | #include <nvgpu/gmmu.h> |
30 | #include <nvgpu/nvgpu_mem.h> | ||
31 | #include <nvgpu/enabled.h> | 27 | #include <nvgpu/enabled.h> |
32 | 28 | #include <nvgpu/nvgpu_mem.h> | |
33 | /* | ||
34 | * In userspace vidmem vs sysmem is just a difference in what is placed in the | ||
35 | * aperture field. | ||
36 | */ | ||
37 | static int __nvgpu_do_dma_alloc(struct gk20a *g, unsigned long flags, | ||
38 | size_t size, struct nvgpu_mem *mem, | ||
39 | enum nvgpu_aperture ap) | ||
40 | { | ||
41 | void *memory = malloc(mem->aligned_size); | ||
42 | |||
43 | if (memory == NULL) | ||
44 | return -ENOMEM; | ||
45 | |||
46 | mem->cpu_va = memory; | ||
47 | mem->aperture = ap; | ||
48 | mem->size = size; | ||
49 | mem->aligned_size = PAGE_ALIGN(size); | ||
50 | mem->gpu_va = 0ULL; | ||
51 | mem->skip_wmb = true; | ||
52 | mem->vidmem_alloc = NULL; | ||
53 | mem->allocator = NULL; | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | bool nvgpu_iommuable(struct gk20a *g) | ||
59 | { | ||
60 | return false; | ||
61 | } | ||
62 | 29 | ||
63 | int nvgpu_dma_alloc(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | 30 | int nvgpu_dma_alloc(struct gk20a *g, size_t size, struct nvgpu_mem *mem) |
64 | { | 31 | { |
@@ -66,15 +33,22 @@ int nvgpu_dma_alloc(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | |||
66 | } | 33 | } |
67 | 34 | ||
68 | int nvgpu_dma_alloc_flags(struct gk20a *g, unsigned long flags, size_t size, | 35 | int nvgpu_dma_alloc_flags(struct gk20a *g, unsigned long flags, size_t size, |
69 | struct nvgpu_mem *mem) | 36 | struct nvgpu_mem *mem) |
70 | { | 37 | { |
71 | if (!nvgpu_is_enabled(g, NVGPU_MM_UNIFIED_MEMORY)) { | 38 | if (!nvgpu_is_enabled(g, NVGPU_MM_UNIFIED_MEMORY)) { |
72 | /* | 39 | /* |
73 | * First try vidmem. Obviously in userspace there's no such | 40 | * Force the no-kernel-mapping flag on because we don't support |
74 | * thing as vidmem per se but we will mark the aperture as | 41 | * the lack of it for vidmem - the user should not care when |
75 | * vidmem. | 42 | * using nvgpu_gmmu_alloc_map and it's vidmem, or if there's a |
43 | * difference, the user should use the flag explicitly anyway. | ||
44 | * | ||
45 | * Incoming flags are ignored here, since bits other than the | ||
46 | * no-kernel-mapping flag are ignored by the vidmem mapping | ||
47 | * functions anyway. | ||
76 | */ | 48 | */ |
77 | int err = nvgpu_dma_alloc_flags_vid(g, 0, size, mem); | 49 | int err = nvgpu_dma_alloc_flags_vid(g, |
50 | NVGPU_DMA_NO_KERNEL_MAPPING, | ||
51 | size, mem); | ||
78 | 52 | ||
79 | if (!err) | 53 | if (!err) |
80 | return 0; | 54 | return 0; |
@@ -85,7 +59,6 @@ int nvgpu_dma_alloc_flags(struct gk20a *g, unsigned long flags, size_t size, | |||
85 | } | 59 | } |
86 | 60 | ||
87 | return nvgpu_dma_alloc_flags_sys(g, flags, size, mem); | 61 | return nvgpu_dma_alloc_flags_sys(g, flags, size, mem); |
88 | |||
89 | } | 62 | } |
90 | 63 | ||
91 | int nvgpu_dma_alloc_sys(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | 64 | int nvgpu_dma_alloc_sys(struct gk20a *g, size_t size, struct nvgpu_mem *mem) |
@@ -93,45 +66,23 @@ int nvgpu_dma_alloc_sys(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | |||
93 | return nvgpu_dma_alloc_flags_sys(g, 0, size, mem); | 66 | return nvgpu_dma_alloc_flags_sys(g, 0, size, mem); |
94 | } | 67 | } |
95 | 68 | ||
96 | int nvgpu_dma_alloc_flags_sys(struct gk20a *g, unsigned long flags, | ||
97 | size_t size, struct nvgpu_mem *mem) | ||
98 | { | ||
99 | return __nvgpu_do_dma_alloc(g, flags, size, mem, APERTURE_SYSMEM); | ||
100 | } | ||
101 | |||
102 | int nvgpu_dma_alloc_vid(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | 69 | int nvgpu_dma_alloc_vid(struct gk20a *g, size_t size, struct nvgpu_mem *mem) |
103 | { | 70 | { |
104 | return nvgpu_dma_alloc_flags_vid(g, 0, size, mem); | 71 | return nvgpu_dma_alloc_flags_vid(g, |
72 | NVGPU_DMA_NO_KERNEL_MAPPING, size, mem); | ||
105 | } | 73 | } |
106 | 74 | ||
107 | int nvgpu_dma_alloc_flags_vid(struct gk20a *g, unsigned long flags, | 75 | int nvgpu_dma_alloc_flags_vid(struct gk20a *g, unsigned long flags, |
108 | size_t size, struct nvgpu_mem *mem) | 76 | size_t size, struct nvgpu_mem *mem) |
109 | { | 77 | { |
110 | return __nvgpu_do_dma_alloc(g, flags, size, mem, APERTURE_VIDMEM); | 78 | return nvgpu_dma_alloc_flags_vid_at(g, flags, size, mem, 0); |
111 | } | 79 | } |
112 | 80 | ||
113 | int nvgpu_dma_alloc_vid_at(struct gk20a *g, | 81 | int nvgpu_dma_alloc_vid_at(struct gk20a *g, |
114 | size_t size, struct nvgpu_mem *mem, u64 at) | 82 | size_t size, struct nvgpu_mem *mem, u64 at) |
115 | { | 83 | { |
116 | BUG(); | 84 | return nvgpu_dma_alloc_flags_vid_at(g, |
117 | 85 | NVGPU_DMA_NO_KERNEL_MAPPING, size, mem, at); | |
118 | return 0; | ||
119 | } | ||
120 | |||
121 | int nvgpu_dma_alloc_flags_vid_at(struct gk20a *g, unsigned long flags, | ||
122 | size_t size, struct nvgpu_mem *mem, u64 at) | ||
123 | { | ||
124 | BUG(); | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | void nvgpu_dma_free(struct gk20a *g, struct nvgpu_mem *mem) | ||
130 | { | ||
131 | if (!(mem->mem_flags & NVGPU_MEM_FLAG_SHADOW_COPY)) | ||
132 | free(mem->cpu_va); | ||
133 | |||
134 | memset(mem, 0, sizeof(*mem)); | ||
135 | } | 86 | } |
136 | 87 | ||
137 | int nvgpu_dma_alloc_map(struct vm_gk20a *vm, size_t size, | 88 | int nvgpu_dma_alloc_map(struct vm_gk20a *vm, size_t size, |
@@ -144,6 +95,12 @@ int nvgpu_dma_alloc_map_flags(struct vm_gk20a *vm, unsigned long flags, | |||
144 | size_t size, struct nvgpu_mem *mem) | 95 | size_t size, struct nvgpu_mem *mem) |
145 | { | 96 | { |
146 | if (!nvgpu_is_enabled(gk20a_from_vm(vm), NVGPU_MM_UNIFIED_MEMORY)) { | 97 | if (!nvgpu_is_enabled(gk20a_from_vm(vm), NVGPU_MM_UNIFIED_MEMORY)) { |
98 | /* | ||
99 | * Force the no-kernel-mapping flag on because we don't support | ||
100 | * the lack of it for vidmem - the user should not care when | ||
101 | * using nvgpu_dma_alloc_map and it's vidmem, or if there's a | ||
102 | * difference, the user should use the flag explicitly anyway. | ||
103 | */ | ||
147 | int err = nvgpu_dma_alloc_map_flags_vid(vm, | 104 | int err = nvgpu_dma_alloc_map_flags_vid(vm, |
148 | flags | NVGPU_DMA_NO_KERNEL_MAPPING, | 105 | flags | NVGPU_DMA_NO_KERNEL_MAPPING, |
149 | size, mem); | 106 | size, mem); |
@@ -218,6 +175,18 @@ fail_free: | |||
218 | return err; | 175 | return err; |
219 | } | 176 | } |
220 | 177 | ||
178 | void nvgpu_dma_free(struct gk20a *g, struct nvgpu_mem *mem) | ||
179 | { | ||
180 | switch (mem->aperture) { | ||
181 | case APERTURE_SYSMEM: | ||
182 | return nvgpu_dma_free_sys(g, mem); | ||
183 | case APERTURE_VIDMEM: | ||
184 | return nvgpu_dma_free_vid(g, mem); | ||
185 | default: | ||
186 | break; /* like free() on "null" memory */ | ||
187 | } | ||
188 | } | ||
189 | |||
221 | void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem) | 190 | void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem) |
222 | { | 191 | { |
223 | if (mem->gpu_va) | 192 | if (mem->gpu_va) |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/dma.h b/drivers/gpu/nvgpu/include/nvgpu/dma.h index d83346a3..f6f264cf 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/dma.h +++ b/drivers/gpu/nvgpu/include/nvgpu/dma.h | |||
@@ -352,4 +352,10 @@ int nvgpu_dma_alloc_map_flags_vid(struct vm_gk20a *vm, unsigned long flags, | |||
352 | */ | 352 | */ |
353 | void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem); | 353 | void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem); |
354 | 354 | ||
355 | /* | ||
356 | * Don't use these directly. Instead use nvgpu_dma_free(). | ||
357 | */ | ||
358 | void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem); | ||
359 | void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem); | ||
360 | |||
355 | #endif | 361 | #endif |
diff --git a/drivers/gpu/nvgpu/os/linux/dma.c b/drivers/gpu/nvgpu/os/linux/linux-dma.c index 77669493..a42e7cb5 100644 --- a/drivers/gpu/nvgpu/os/linux/dma.c +++ b/drivers/gpu/nvgpu/os/linux/linux-dma.c | |||
@@ -174,45 +174,6 @@ static void nvgpu_dma_flags_to_attrs(struct dma_attrs *attrs, | |||
174 | #undef ATTR_ARG | 174 | #undef ATTR_ARG |
175 | } | 175 | } |
176 | 176 | ||
177 | int nvgpu_dma_alloc(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | ||
178 | { | ||
179 | return nvgpu_dma_alloc_flags(g, 0, size, mem); | ||
180 | } | ||
181 | |||
182 | int nvgpu_dma_alloc_flags(struct gk20a *g, unsigned long flags, size_t size, | ||
183 | struct nvgpu_mem *mem) | ||
184 | { | ||
185 | if (!nvgpu_is_enabled(g, NVGPU_MM_UNIFIED_MEMORY)) { | ||
186 | /* | ||
187 | * Force the no-kernel-mapping flag on because we don't support | ||
188 | * the lack of it for vidmem - the user should not care when | ||
189 | * using nvgpu_gmmu_alloc_map and it's vidmem, or if there's a | ||
190 | * difference, the user should use the flag explicitly anyway. | ||
191 | * | ||
192 | * Incoming flags are ignored here, since bits other than the | ||
193 | * no-kernel-mapping flag are ignored by the vidmem mapping | ||
194 | * functions anyway. | ||
195 | */ | ||
196 | int err = nvgpu_dma_alloc_flags_vid(g, | ||
197 | NVGPU_DMA_NO_KERNEL_MAPPING, | ||
198 | size, mem); | ||
199 | |||
200 | if (!err) | ||
201 | return 0; | ||
202 | /* | ||
203 | * Fall back to sysmem (which may then also fail) in case | ||
204 | * vidmem is exhausted. | ||
205 | */ | ||
206 | } | ||
207 | |||
208 | return nvgpu_dma_alloc_flags_sys(g, flags, size, mem); | ||
209 | } | ||
210 | |||
211 | int nvgpu_dma_alloc_sys(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | ||
212 | { | ||
213 | return nvgpu_dma_alloc_flags_sys(g, 0, size, mem); | ||
214 | } | ||
215 | |||
216 | int nvgpu_dma_alloc_flags_sys(struct gk20a *g, unsigned long flags, | 177 | int nvgpu_dma_alloc_flags_sys(struct gk20a *g, unsigned long flags, |
217 | size_t size, struct nvgpu_mem *mem) | 178 | size_t size, struct nvgpu_mem *mem) |
218 | { | 179 | { |
@@ -302,25 +263,6 @@ fail_free_dma: | |||
302 | return err; | 263 | return err; |
303 | } | 264 | } |
304 | 265 | ||
305 | int nvgpu_dma_alloc_vid(struct gk20a *g, size_t size, struct nvgpu_mem *mem) | ||
306 | { | ||
307 | return nvgpu_dma_alloc_flags_vid(g, | ||
308 | NVGPU_DMA_NO_KERNEL_MAPPING, size, mem); | ||
309 | } | ||
310 | |||
311 | int nvgpu_dma_alloc_flags_vid(struct gk20a *g, unsigned long flags, | ||
312 | size_t size, struct nvgpu_mem *mem) | ||
313 | { | ||
314 | return nvgpu_dma_alloc_flags_vid_at(g, flags, size, mem, 0); | ||
315 | } | ||
316 | |||
317 | int nvgpu_dma_alloc_vid_at(struct gk20a *g, | ||
318 | size_t size, struct nvgpu_mem *mem, u64 at) | ||
319 | { | ||
320 | return nvgpu_dma_alloc_flags_vid_at(g, | ||
321 | NVGPU_DMA_NO_KERNEL_MAPPING, size, mem, at); | ||
322 | } | ||
323 | |||
324 | int nvgpu_dma_alloc_flags_vid_at(struct gk20a *g, unsigned long flags, | 266 | int nvgpu_dma_alloc_flags_vid_at(struct gk20a *g, unsigned long flags, |
325 | size_t size, struct nvgpu_mem *mem, u64 at) | 267 | size_t size, struct nvgpu_mem *mem, u64 at) |
326 | { | 268 | { |
@@ -405,97 +347,7 @@ fail_physfree: | |||
405 | #endif | 347 | #endif |
406 | } | 348 | } |
407 | 349 | ||
408 | int nvgpu_dma_alloc_map(struct vm_gk20a *vm, size_t size, | 350 | void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem) |
409 | struct nvgpu_mem *mem) | ||
410 | { | ||
411 | return nvgpu_dma_alloc_map_flags(vm, 0, size, mem); | ||
412 | } | ||
413 | |||
414 | int nvgpu_dma_alloc_map_flags(struct vm_gk20a *vm, unsigned long flags, | ||
415 | size_t size, struct nvgpu_mem *mem) | ||
416 | { | ||
417 | if (!nvgpu_is_enabled(gk20a_from_vm(vm), NVGPU_MM_UNIFIED_MEMORY)) { | ||
418 | /* | ||
419 | * Force the no-kernel-mapping flag on because we don't support | ||
420 | * the lack of it for vidmem - the user should not care when | ||
421 | * using nvgpu_dma_alloc_map and it's vidmem, or if there's a | ||
422 | * difference, the user should use the flag explicitly anyway. | ||
423 | */ | ||
424 | int err = nvgpu_dma_alloc_map_flags_vid(vm, | ||
425 | flags | NVGPU_DMA_NO_KERNEL_MAPPING, | ||
426 | size, mem); | ||
427 | |||
428 | if (!err) | ||
429 | return 0; | ||
430 | /* | ||
431 | * Fall back to sysmem (which may then also fail) in case | ||
432 | * vidmem is exhausted. | ||
433 | */ | ||
434 | } | ||
435 | |||
436 | return nvgpu_dma_alloc_map_flags_sys(vm, flags, size, mem); | ||
437 | } | ||
438 | |||
439 | int nvgpu_dma_alloc_map_sys(struct vm_gk20a *vm, size_t size, | ||
440 | struct nvgpu_mem *mem) | ||
441 | { | ||
442 | return nvgpu_dma_alloc_map_flags_sys(vm, 0, size, mem); | ||
443 | } | ||
444 | |||
445 | int nvgpu_dma_alloc_map_flags_sys(struct vm_gk20a *vm, unsigned long flags, | ||
446 | size_t size, struct nvgpu_mem *mem) | ||
447 | { | ||
448 | int err = nvgpu_dma_alloc_flags_sys(vm->mm->g, flags, size, mem); | ||
449 | |||
450 | if (err) | ||
451 | return err; | ||
452 | |||
453 | mem->gpu_va = nvgpu_gmmu_map(vm, mem, size, 0, | ||
454 | gk20a_mem_flag_none, false, | ||
455 | mem->aperture); | ||
456 | if (!mem->gpu_va) { | ||
457 | err = -ENOMEM; | ||
458 | goto fail_free; | ||
459 | } | ||
460 | |||
461 | return 0; | ||
462 | |||
463 | fail_free: | ||
464 | nvgpu_dma_free(vm->mm->g, mem); | ||
465 | return err; | ||
466 | } | ||
467 | |||
468 | int nvgpu_dma_alloc_map_vid(struct vm_gk20a *vm, size_t size, | ||
469 | struct nvgpu_mem *mem) | ||
470 | { | ||
471 | return nvgpu_dma_alloc_map_flags_vid(vm, | ||
472 | NVGPU_DMA_NO_KERNEL_MAPPING, size, mem); | ||
473 | } | ||
474 | |||
475 | int nvgpu_dma_alloc_map_flags_vid(struct vm_gk20a *vm, unsigned long flags, | ||
476 | size_t size, struct nvgpu_mem *mem) | ||
477 | { | ||
478 | int err = nvgpu_dma_alloc_flags_vid(vm->mm->g, flags, size, mem); | ||
479 | |||
480 | if (err) | ||
481 | return err; | ||
482 | |||
483 | mem->gpu_va = nvgpu_gmmu_map(vm, mem, size, 0, | ||
484 | gk20a_mem_flag_none, false, | ||
485 | mem->aperture); | ||
486 | if (!mem->gpu_va) { | ||
487 | err = -ENOMEM; | ||
488 | goto fail_free; | ||
489 | } | ||
490 | |||
491 | return 0; | ||
492 | |||
493 | fail_free: | ||
494 | nvgpu_dma_free(vm->mm->g, mem); | ||
495 | return err; | ||
496 | } | ||
497 | |||
498 | static void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem) | ||
499 | { | 351 | { |
500 | struct device *d = dev_from_gk20a(g); | 352 | struct device *d = dev_from_gk20a(g); |
501 | 353 | ||
@@ -551,7 +403,7 @@ static void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem) | |||
551 | mem->aperture = APERTURE_INVALID; | 403 | mem->aperture = APERTURE_INVALID; |
552 | } | 404 | } |
553 | 405 | ||
554 | static void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem) | 406 | void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem) |
555 | { | 407 | { |
556 | #if defined(CONFIG_GK20A_VIDMEM) | 408 | #if defined(CONFIG_GK20A_VIDMEM) |
557 | size_t mem_size = mem->size; | 409 | size_t mem_size = mem->size; |
@@ -590,27 +442,6 @@ static void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem) | |||
590 | #endif | 442 | #endif |
591 | } | 443 | } |
592 | 444 | ||
593 | void nvgpu_dma_free(struct gk20a *g, struct nvgpu_mem *mem) | ||
594 | { | ||
595 | switch (mem->aperture) { | ||
596 | case APERTURE_SYSMEM: | ||
597 | return nvgpu_dma_free_sys(g, mem); | ||
598 | case APERTURE_VIDMEM: | ||
599 | return nvgpu_dma_free_vid(g, mem); | ||
600 | default: | ||
601 | break; /* like free() on "null" memory */ | ||
602 | } | ||
603 | } | ||
604 | |||
605 | void nvgpu_dma_unmap_free(struct vm_gk20a *vm, struct nvgpu_mem *mem) | ||
606 | { | ||
607 | if (mem->gpu_va) | ||
608 | nvgpu_gmmu_unmap(vm, mem, mem->gpu_va); | ||
609 | mem->gpu_va = 0; | ||
610 | |||
611 | nvgpu_dma_free(vm->mm->g, mem); | ||
612 | } | ||
613 | |||
614 | int nvgpu_get_sgtable_attrs(struct gk20a *g, struct sg_table **sgt, | 445 | int nvgpu_get_sgtable_attrs(struct gk20a *g, struct sg_table **sgt, |
615 | void *cpuva, u64 iova, size_t size, unsigned long flags) | 446 | void *cpuva, u64 iova, size_t size, unsigned long flags) |
616 | { | 447 | { |
diff --git a/drivers/gpu/nvgpu/os/posix/posix-dma.c b/drivers/gpu/nvgpu/os/posix/posix-dma.c new file mode 100644 index 00000000..e8c5c9d4 --- /dev/null +++ b/drivers/gpu/nvgpu/os/posix/posix-dma.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | * copy of this software and associated documentation files (the "Software"), | ||
6 | * to deal in the Software without restriction, including without limitation | ||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | * and/or sell copies of the Software, and to permit persons to whom the | ||
9 | * Software is furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | * DEALINGS IN THE SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | |||
25 | #include <nvgpu/mm.h> | ||
26 | #include <nvgpu/vm.h> | ||
27 | #include <nvgpu/bug.h> | ||
28 | #include <nvgpu/dma.h> | ||
29 | #include <nvgpu/gmmu.h> | ||
30 | #include <nvgpu/nvgpu_mem.h> | ||
31 | #include <nvgpu/enabled.h> | ||
32 | |||
33 | /* | ||
34 | * In userspace vidmem vs sysmem is just a difference in what is placed in the | ||
35 | * aperture field. | ||
36 | */ | ||
37 | static int __nvgpu_do_dma_alloc(struct gk20a *g, unsigned long flags, | ||
38 | size_t size, struct nvgpu_mem *mem, | ||
39 | enum nvgpu_aperture ap) | ||
40 | { | ||
41 | void *memory = malloc(mem->aligned_size); | ||
42 | |||
43 | if (memory == NULL) | ||
44 | return -ENOMEM; | ||
45 | |||
46 | mem->cpu_va = memory; | ||
47 | mem->aperture = ap; | ||
48 | mem->size = size; | ||
49 | mem->aligned_size = PAGE_ALIGN(size); | ||
50 | mem->gpu_va = 0ULL; | ||
51 | mem->skip_wmb = true; | ||
52 | mem->vidmem_alloc = NULL; | ||
53 | mem->allocator = NULL; | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | bool nvgpu_iommuable(struct gk20a *g) | ||
59 | { | ||
60 | return false; | ||
61 | } | ||
62 | |||
63 | int nvgpu_dma_alloc_flags_sys(struct gk20a *g, unsigned long flags, | ||
64 | size_t size, struct nvgpu_mem *mem) | ||
65 | { | ||
66 | return __nvgpu_do_dma_alloc(g, flags, size, mem, APERTURE_SYSMEM); | ||
67 | } | ||
68 | |||
69 | int nvgpu_dma_alloc_flags_vid_at(struct gk20a *g, unsigned long flags, | ||
70 | size_t size, struct nvgpu_mem *mem, u64 at) | ||
71 | { | ||
72 | BUG(); | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | void nvgpu_dma_free_sys(struct gk20a *g, struct nvgpu_mem *mem) | ||
78 | { | ||
79 | if (!(mem->mem_flags & NVGPU_MEM_FLAG_SHADOW_COPY)) | ||
80 | free(mem->cpu_va); | ||
81 | |||
82 | memset(mem, 0, sizeof(*mem)); | ||
83 | } | ||
84 | |||
85 | void nvgpu_dma_free_vid(struct gk20a *g, struct nvgpu_mem *mem) | ||
86 | { | ||
87 | BUG(); | ||
88 | } | ||