diff options
Diffstat (limited to 'include/os/posix/posix-nvgpu_mem.c')
-rw-r--r-- | include/os/posix/posix-nvgpu_mem.c | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/include/os/posix/posix-nvgpu_mem.c b/include/os/posix/posix-nvgpu_mem.c deleted file mode 100644 index 26770e4..0000000 --- a/include/os/posix/posix-nvgpu_mem.c +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
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 <nvgpu/bug.h> | ||
24 | #include <nvgpu/dma.h> | ||
25 | #include <nvgpu/gmmu.h> | ||
26 | #include <nvgpu/kmem.h> | ||
27 | #include <nvgpu/nvgpu_mem.h> | ||
28 | |||
29 | /* | ||
30 | * These functions are somewhat meaningless. | ||
31 | */ | ||
32 | u64 nvgpu_mem_get_addr(struct gk20a *g, struct nvgpu_mem *mem) | ||
33 | { | ||
34 | return (u64)(uintptr_t)mem->cpu_va; | ||
35 | } | ||
36 | |||
37 | u64 nvgpu_mem_get_phys_addr(struct gk20a *g, struct nvgpu_mem *mem) | ||
38 | { | ||
39 | return (u64)(uintptr_t)mem->cpu_va; | ||
40 | } | ||
41 | |||
42 | static struct nvgpu_sgl *nvgpu_mem_sgl_next(struct nvgpu_sgl *sgl) | ||
43 | { | ||
44 | return NULL; | ||
45 | } | ||
46 | |||
47 | static u64 nvgpu_mem_sgl_phys(struct gk20a *g, struct nvgpu_sgl *sgl) | ||
48 | { | ||
49 | struct nvgpu_mem *mem = (struct nvgpu_mem *)sgl; | ||
50 | |||
51 | return (u64)(uintptr_t)mem->cpu_va; | ||
52 | } | ||
53 | |||
54 | static u64 nvgpu_mem_sgl_dma(struct nvgpu_sgl *sgl) | ||
55 | { | ||
56 | struct nvgpu_mem *mem = (struct nvgpu_mem *)sgl; | ||
57 | |||
58 | return (u64)(uintptr_t)mem->cpu_va; | ||
59 | } | ||
60 | |||
61 | static u64 nvgpu_mem_sgl_length(struct nvgpu_sgl *sgl) | ||
62 | { | ||
63 | struct nvgpu_mem *mem = (struct nvgpu_mem *)sgl; | ||
64 | |||
65 | return (u64)mem->aligned_size; | ||
66 | } | ||
67 | |||
68 | static u64 nvgpu_mem_sgl_gpu_addr(struct gk20a *g, struct nvgpu_sgl *sgl, | ||
69 | struct nvgpu_gmmu_attrs *attrs) | ||
70 | { | ||
71 | struct nvgpu_mem *mem = (struct nvgpu_mem *)sgl; | ||
72 | |||
73 | return mem->gpu_va; | ||
74 | } | ||
75 | |||
76 | static bool nvgpu_mem_sgt_iommuable(struct gk20a *g, struct nvgpu_sgt *sgt) | ||
77 | { | ||
78 | return nvgpu_iommuable(g); | ||
79 | } | ||
80 | |||
81 | static void nvgpu_mem_sgt_free(struct gk20a *g, struct nvgpu_sgt *sgt) | ||
82 | { | ||
83 | nvgpu_kfree(g, sgt); | ||
84 | } | ||
85 | |||
86 | static struct nvgpu_sgt_ops nvgpu_sgt_posix_ops = { | ||
87 | .sgl_next = nvgpu_mem_sgl_next, | ||
88 | .sgl_phys = nvgpu_mem_sgl_phys, | ||
89 | .sgl_dma = nvgpu_mem_sgl_dma, | ||
90 | .sgl_length = nvgpu_mem_sgl_length, | ||
91 | .sgl_gpu_addr = nvgpu_mem_sgl_gpu_addr, | ||
92 | .sgt_iommuable = nvgpu_mem_sgt_iommuable, | ||
93 | .sgt_free = nvgpu_mem_sgt_free, | ||
94 | }; | ||
95 | |||
96 | struct nvgpu_sgt *nvgpu_sgt_create_from_mem(struct gk20a *g, | ||
97 | struct nvgpu_mem *mem) | ||
98 | { | ||
99 | struct nvgpu_sgt *sgt = nvgpu_kzalloc(g, sizeof(*sgt)); | ||
100 | |||
101 | if (sgt == NULL) | ||
102 | return NULL; | ||
103 | |||
104 | /* | ||
105 | * The userspace implementation is simple: a single 'entry' (which we | ||
106 | * only need the mem struct to describe). Maybe this could be expanded | ||
107 | * to be more interesting some day. | ||
108 | */ | ||
109 | sgt->sgl = (struct nvgpu_sgl *)mem; | ||
110 | sgt->ops = &nvgpu_sgt_posix_ops; | ||
111 | |||
112 | return sgt; | ||
113 | } | ||
114 | |||
115 | int nvgpu_mem_create_from_mem(struct gk20a *g, | ||
116 | struct nvgpu_mem *dest, struct nvgpu_mem *src, | ||
117 | u64 start_page, int nr_pages) | ||
118 | { | ||
119 | u64 start = start_page * PAGE_SIZE; | ||
120 | u64 size = nr_pages * PAGE_SIZE; | ||
121 | |||
122 | if (src->aperture != APERTURE_SYSMEM) | ||
123 | return -EINVAL; | ||
124 | |||
125 | /* Some silly things a caller might do... */ | ||
126 | if (size > src->size) | ||
127 | return -EINVAL; | ||
128 | if ((start + size) > src->size) | ||
129 | return -EINVAL; | ||
130 | |||
131 | memset(dest, 0, sizeof(*dest)); | ||
132 | |||
133 | dest->cpu_va = ((char *)src->cpu_va) + start; | ||
134 | dest->mem_flags = src->mem_flags | NVGPU_MEM_FLAG_SHADOW_COPY; | ||
135 | dest->aperture = src->aperture; | ||
136 | dest->skip_wmb = src->skip_wmb; | ||
137 | dest->size = size; | ||
138 | |||
139 | return 0; | ||
140 | } | ||