]>
Commit | Line | Data |
---|---|---|
fb1d9738 JB |
1 | /************************************************************************** |
2 | * | |
3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA | |
4 | * All Rights Reserved. | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a | |
7 | * copy of this software and associated documentation files (the | |
8 | * "Software"), to deal in the Software without restriction, including | |
9 | * without limitation the rights to use, copy, modify, merge, publish, | |
10 | * distribute, sub license, and/or sell copies of the Software, and to | |
11 | * permit persons to whom the Software is furnished to do so, subject to | |
12 | * the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice (including the | |
15 | * next paragraph) shall be included in all copies or substantial portions | |
16 | * of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, | |
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. | |
25 | * | |
26 | **************************************************************************/ | |
27 | ||
28 | #include "vmwgfx_drv.h" | |
760285e7 DH |
29 | #include <drm/ttm/ttm_bo_driver.h> |
30 | #include <drm/ttm/ttm_placement.h> | |
31 | #include <drm/ttm/ttm_page_alloc.h> | |
fb1d9738 JB |
32 | |
33 | static uint32_t vram_placement_flags = TTM_PL_FLAG_VRAM | | |
34 | TTM_PL_FLAG_CACHED; | |
35 | ||
36 | static uint32_t vram_ne_placement_flags = TTM_PL_FLAG_VRAM | | |
37 | TTM_PL_FLAG_CACHED | | |
38 | TTM_PL_FLAG_NO_EVICT; | |
39 | ||
40 | static uint32_t sys_placement_flags = TTM_PL_FLAG_SYSTEM | | |
41 | TTM_PL_FLAG_CACHED; | |
42 | ||
135cba0d TH |
43 | static uint32_t gmr_placement_flags = VMW_PL_FLAG_GMR | |
44 | TTM_PL_FLAG_CACHED; | |
45 | ||
d991ef03 JB |
46 | static uint32_t gmr_ne_placement_flags = VMW_PL_FLAG_GMR | |
47 | TTM_PL_FLAG_CACHED | | |
48 | TTM_PL_FLAG_NO_EVICT; | |
49 | ||
fb1d9738 JB |
50 | struct ttm_placement vmw_vram_placement = { |
51 | .fpfn = 0, | |
52 | .lpfn = 0, | |
53 | .num_placement = 1, | |
54 | .placement = &vram_placement_flags, | |
55 | .num_busy_placement = 1, | |
56 | .busy_placement = &vram_placement_flags | |
57 | }; | |
58 | ||
135cba0d TH |
59 | static uint32_t vram_gmr_placement_flags[] = { |
60 | TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED, | |
61 | VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED | |
62 | }; | |
63 | ||
5bb39e81 TH |
64 | static uint32_t gmr_vram_placement_flags[] = { |
65 | VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED, | |
66 | TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED | |
67 | }; | |
68 | ||
135cba0d TH |
69 | struct ttm_placement vmw_vram_gmr_placement = { |
70 | .fpfn = 0, | |
71 | .lpfn = 0, | |
72 | .num_placement = 2, | |
73 | .placement = vram_gmr_placement_flags, | |
74 | .num_busy_placement = 1, | |
75 | .busy_placement = &gmr_placement_flags | |
76 | }; | |
77 | ||
d991ef03 JB |
78 | static uint32_t vram_gmr_ne_placement_flags[] = { |
79 | TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT, | |
80 | VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED | TTM_PL_FLAG_NO_EVICT | |
81 | }; | |
82 | ||
83 | struct ttm_placement vmw_vram_gmr_ne_placement = { | |
84 | .fpfn = 0, | |
85 | .lpfn = 0, | |
86 | .num_placement = 2, | |
87 | .placement = vram_gmr_ne_placement_flags, | |
88 | .num_busy_placement = 1, | |
89 | .busy_placement = &gmr_ne_placement_flags | |
90 | }; | |
91 | ||
8ba5152a TH |
92 | struct ttm_placement vmw_vram_sys_placement = { |
93 | .fpfn = 0, | |
94 | .lpfn = 0, | |
95 | .num_placement = 1, | |
96 | .placement = &vram_placement_flags, | |
97 | .num_busy_placement = 1, | |
98 | .busy_placement = &sys_placement_flags | |
99 | }; | |
100 | ||
fb1d9738 JB |
101 | struct ttm_placement vmw_vram_ne_placement = { |
102 | .fpfn = 0, | |
103 | .lpfn = 0, | |
104 | .num_placement = 1, | |
105 | .placement = &vram_ne_placement_flags, | |
106 | .num_busy_placement = 1, | |
107 | .busy_placement = &vram_ne_placement_flags | |
108 | }; | |
109 | ||
110 | struct ttm_placement vmw_sys_placement = { | |
111 | .fpfn = 0, | |
112 | .lpfn = 0, | |
113 | .num_placement = 1, | |
114 | .placement = &sys_placement_flags, | |
115 | .num_busy_placement = 1, | |
116 | .busy_placement = &sys_placement_flags | |
117 | }; | |
118 | ||
d991ef03 JB |
119 | static uint32_t evictable_placement_flags[] = { |
120 | TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED, | |
121 | TTM_PL_FLAG_VRAM | TTM_PL_FLAG_CACHED, | |
122 | VMW_PL_FLAG_GMR | TTM_PL_FLAG_CACHED | |
123 | }; | |
124 | ||
125 | struct ttm_placement vmw_evictable_placement = { | |
126 | .fpfn = 0, | |
127 | .lpfn = 0, | |
128 | .num_placement = 3, | |
129 | .placement = evictable_placement_flags, | |
130 | .num_busy_placement = 1, | |
131 | .busy_placement = &sys_placement_flags | |
132 | }; | |
133 | ||
5bb39e81 TH |
134 | struct ttm_placement vmw_srf_placement = { |
135 | .fpfn = 0, | |
136 | .lpfn = 0, | |
137 | .num_placement = 1, | |
138 | .num_busy_placement = 2, | |
139 | .placement = &gmr_placement_flags, | |
140 | .busy_placement = gmr_vram_placement_flags | |
141 | }; | |
142 | ||
649bf3ca JG |
143 | struct vmw_ttm_tt { |
144 | struct ttm_tt ttm; | |
135cba0d TH |
145 | struct vmw_private *dev_priv; |
146 | int gmr_id; | |
fb1d9738 JB |
147 | }; |
148 | ||
649bf3ca | 149 | static int vmw_ttm_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem) |
fb1d9738 | 150 | { |
649bf3ca | 151 | struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); |
135cba0d TH |
152 | |
153 | vmw_be->gmr_id = bo_mem->start; | |
154 | ||
649bf3ca JG |
155 | return vmw_gmr_bind(vmw_be->dev_priv, ttm->pages, |
156 | ttm->num_pages, vmw_be->gmr_id); | |
fb1d9738 JB |
157 | } |
158 | ||
649bf3ca | 159 | static int vmw_ttm_unbind(struct ttm_tt *ttm) |
fb1d9738 | 160 | { |
649bf3ca | 161 | struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); |
135cba0d TH |
162 | |
163 | vmw_gmr_unbind(vmw_be->dev_priv, vmw_be->gmr_id); | |
fb1d9738 JB |
164 | return 0; |
165 | } | |
166 | ||
649bf3ca | 167 | static void vmw_ttm_destroy(struct ttm_tt *ttm) |
fb1d9738 | 168 | { |
649bf3ca | 169 | struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm); |
fb1d9738 | 170 | |
8e7e7052 | 171 | ttm_tt_fini(ttm); |
fb1d9738 JB |
172 | kfree(vmw_be); |
173 | } | |
174 | ||
175 | static struct ttm_backend_func vmw_ttm_func = { | |
fb1d9738 JB |
176 | .bind = vmw_ttm_bind, |
177 | .unbind = vmw_ttm_unbind, | |
178 | .destroy = vmw_ttm_destroy, | |
179 | }; | |
180 | ||
649bf3ca JG |
181 | struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev, |
182 | unsigned long size, uint32_t page_flags, | |
183 | struct page *dummy_read_page) | |
fb1d9738 | 184 | { |
649bf3ca | 185 | struct vmw_ttm_tt *vmw_be; |
fb1d9738 JB |
186 | |
187 | vmw_be = kmalloc(sizeof(*vmw_be), GFP_KERNEL); | |
188 | if (!vmw_be) | |
189 | return NULL; | |
190 | ||
649bf3ca | 191 | vmw_be->ttm.func = &vmw_ttm_func; |
135cba0d | 192 | vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev); |
fb1d9738 | 193 | |
649bf3ca | 194 | if (ttm_tt_init(&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) { |
8e7e7052 | 195 | kfree(vmw_be); |
649bf3ca JG |
196 | return NULL; |
197 | } | |
198 | ||
199 | return &vmw_be->ttm; | |
fb1d9738 JB |
200 | } |
201 | ||
202 | int vmw_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) | |
203 | { | |
204 | return 0; | |
205 | } | |
206 | ||
207 | int vmw_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, | |
208 | struct ttm_mem_type_manager *man) | |
209 | { | |
fb1d9738 JB |
210 | switch (type) { |
211 | case TTM_PL_SYSTEM: | |
212 | /* System memory */ | |
213 | ||
214 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; | |
135cba0d | 215 | man->available_caching = TTM_PL_FLAG_CACHED; |
fb1d9738 JB |
216 | man->default_caching = TTM_PL_FLAG_CACHED; |
217 | break; | |
218 | case TTM_PL_VRAM: | |
219 | /* "On-card" video ram */ | |
d961db75 | 220 | man->func = &ttm_bo_manager_func; |
fb1d9738 | 221 | man->gpu_offset = 0; |
96bf8b87 | 222 | man->flags = TTM_MEMTYPE_FLAG_FIXED | TTM_MEMTYPE_FLAG_MAPPABLE; |
135cba0d TH |
223 | man->available_caching = TTM_PL_FLAG_CACHED; |
224 | man->default_caching = TTM_PL_FLAG_CACHED; | |
225 | break; | |
226 | case VMW_PL_GMR: | |
227 | /* | |
228 | * "Guest Memory Regions" is an aperture like feature with | |
229 | * one slot per bo. There is an upper limit of the number of | |
230 | * slots as well as the bo size. | |
231 | */ | |
232 | man->func = &vmw_gmrid_manager_func; | |
233 | man->gpu_offset = 0; | |
234 | man->flags = TTM_MEMTYPE_FLAG_CMA | TTM_MEMTYPE_FLAG_MAPPABLE; | |
235 | man->available_caching = TTM_PL_FLAG_CACHED; | |
236 | man->default_caching = TTM_PL_FLAG_CACHED; | |
fb1d9738 JB |
237 | break; |
238 | default: | |
239 | DRM_ERROR("Unsupported memory type %u\n", (unsigned)type); | |
240 | return -EINVAL; | |
241 | } | |
242 | return 0; | |
243 | } | |
244 | ||
245 | void vmw_evict_flags(struct ttm_buffer_object *bo, | |
246 | struct ttm_placement *placement) | |
247 | { | |
248 | *placement = vmw_sys_placement; | |
249 | } | |
250 | ||
251 | /** | |
252 | * FIXME: Proper access checks on buffers. | |
253 | */ | |
254 | ||
255 | static int vmw_verify_access(struct ttm_buffer_object *bo, struct file *filp) | |
256 | { | |
257 | return 0; | |
258 | } | |
259 | ||
96bf8b87 JG |
260 | static int vmw_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
261 | { | |
262 | struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; | |
263 | struct vmw_private *dev_priv = container_of(bdev, struct vmw_private, bdev); | |
264 | ||
265 | mem->bus.addr = NULL; | |
266 | mem->bus.is_iomem = false; | |
267 | mem->bus.offset = 0; | |
268 | mem->bus.size = mem->num_pages << PAGE_SHIFT; | |
269 | mem->bus.base = 0; | |
270 | if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) | |
271 | return -EINVAL; | |
272 | switch (mem->mem_type) { | |
273 | case TTM_PL_SYSTEM: | |
135cba0d | 274 | case VMW_PL_GMR: |
96bf8b87 JG |
275 | return 0; |
276 | case TTM_PL_VRAM: | |
d961db75 | 277 | mem->bus.offset = mem->start << PAGE_SHIFT; |
96bf8b87 JG |
278 | mem->bus.base = dev_priv->vram_start; |
279 | mem->bus.is_iomem = true; | |
280 | break; | |
281 | default: | |
282 | return -EINVAL; | |
283 | } | |
284 | return 0; | |
285 | } | |
286 | ||
287 | static void vmw_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) | |
288 | { | |
289 | } | |
290 | ||
291 | static int vmw_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) | |
292 | { | |
293 | return 0; | |
294 | } | |
295 | ||
fb1d9738 JB |
296 | /** |
297 | * FIXME: We're using the old vmware polling method to sync. | |
298 | * Do this with fences instead. | |
299 | */ | |
300 | ||
301 | static void *vmw_sync_obj_ref(void *sync_obj) | |
302 | { | |
ae2a1040 TH |
303 | |
304 | return (void *) | |
305 | vmw_fence_obj_reference((struct vmw_fence_obj *) sync_obj); | |
fb1d9738 JB |
306 | } |
307 | ||
308 | static void vmw_sync_obj_unref(void **sync_obj) | |
309 | { | |
ae2a1040 | 310 | vmw_fence_obj_unreference((struct vmw_fence_obj **) sync_obj); |
fb1d9738 JB |
311 | } |
312 | ||
dedfdffd | 313 | static int vmw_sync_obj_flush(void *sync_obj) |
fb1d9738 | 314 | { |
ae2a1040 | 315 | vmw_fence_obj_flush((struct vmw_fence_obj *) sync_obj); |
fb1d9738 JB |
316 | return 0; |
317 | } | |
318 | ||
dedfdffd | 319 | static bool vmw_sync_obj_signaled(void *sync_obj) |
fb1d9738 | 320 | { |
ae2a1040 | 321 | return vmw_fence_obj_signaled((struct vmw_fence_obj *) sync_obj, |
be013367 | 322 | DRM_VMW_FENCE_FLAG_EXEC); |
fb1d9738 | 323 | |
fb1d9738 JB |
324 | } |
325 | ||
dedfdffd | 326 | static int vmw_sync_obj_wait(void *sync_obj, bool lazy, bool interruptible) |
fb1d9738 | 327 | { |
ae2a1040 | 328 | return vmw_fence_obj_wait((struct vmw_fence_obj *) sync_obj, |
be013367 | 329 | DRM_VMW_FENCE_FLAG_EXEC, |
ae2a1040 TH |
330 | lazy, interruptible, |
331 | VMW_FENCE_WAIT_TIMEOUT); | |
fb1d9738 JB |
332 | } |
333 | ||
334 | struct ttm_bo_driver vmw_bo_driver = { | |
649bf3ca | 335 | .ttm_tt_create = &vmw_ttm_tt_create, |
b1e5f172 JG |
336 | .ttm_tt_populate = &ttm_pool_populate, |
337 | .ttm_tt_unpopulate = &ttm_pool_unpopulate, | |
fb1d9738 JB |
338 | .invalidate_caches = vmw_invalidate_caches, |
339 | .init_mem_type = vmw_init_mem_type, | |
340 | .evict_flags = vmw_evict_flags, | |
341 | .move = NULL, | |
342 | .verify_access = vmw_verify_access, | |
343 | .sync_obj_signaled = vmw_sync_obj_signaled, | |
344 | .sync_obj_wait = vmw_sync_obj_wait, | |
345 | .sync_obj_flush = vmw_sync_obj_flush, | |
346 | .sync_obj_unref = vmw_sync_obj_unref, | |
effe1105 | 347 | .sync_obj_ref = vmw_sync_obj_ref, |
135cba0d TH |
348 | .move_notify = NULL, |
349 | .swap_notify = NULL, | |
96bf8b87 JG |
350 | .fault_reserve_notify = &vmw_ttm_fault_reserve_notify, |
351 | .io_mem_reserve = &vmw_ttm_io_mem_reserve, | |
352 | .io_mem_free = &vmw_ttm_io_mem_free, | |
fb1d9738 | 353 | }; |