diff options
Diffstat (limited to 'drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c')
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c index d45d2caffa5a..d59d9dd16ebc 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c | |||
@@ -323,3 +323,54 @@ void vmw_bo_pin_reserved(struct vmw_dma_buffer *vbo, bool pin) | |||
323 | 323 | ||
324 | BUG_ON(ret != 0 || bo->mem.mem_type != old_mem_type); | 324 | BUG_ON(ret != 0 || bo->mem.mem_type != old_mem_type); |
325 | } | 325 | } |
326 | |||
327 | |||
328 | /* | ||
329 | * vmw_dma_buffer_unmap - Tear down a cached buffer object map. | ||
330 | * | ||
331 | * @vbo: The buffer object whose map we are tearing down. | ||
332 | * | ||
333 | * This function tears down a cached map set up using | ||
334 | * vmw_dma_buffer_map_and_cache(). | ||
335 | */ | ||
336 | void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo) | ||
337 | { | ||
338 | if (vbo->map.bo == NULL) | ||
339 | return; | ||
340 | |||
341 | ttm_bo_kunmap(&vbo->map); | ||
342 | } | ||
343 | |||
344 | |||
345 | /* | ||
346 | * vmw_dma_buffer_map_and_cache - Map a buffer object and cache the map | ||
347 | * | ||
348 | * @vbo: The buffer object to map | ||
349 | * Return: A kernel virtual address or NULL if mapping failed. | ||
350 | * | ||
351 | * This function maps a buffer object into the kernel address space, or | ||
352 | * returns the virtual kernel address of an already existing map. The virtual | ||
353 | * address remains valid as long as the buffer object is pinned or reserved. | ||
354 | * The cached map is torn down on either | ||
355 | * 1) Buffer object move | ||
356 | * 2) Buffer object swapout | ||
357 | * 3) Buffer object destruction | ||
358 | * | ||
359 | */ | ||
360 | void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo) | ||
361 | { | ||
362 | struct ttm_buffer_object *bo = &vbo->base; | ||
363 | bool not_used; | ||
364 | void *virtual; | ||
365 | int ret; | ||
366 | |||
367 | virtual = ttm_kmap_obj_virtual(&vbo->map, ¬_used); | ||
368 | if (virtual) | ||
369 | return virtual; | ||
370 | |||
371 | ret = ttm_bo_kmap(bo, 0, bo->num_pages, &vbo->map); | ||
372 | if (ret) | ||
373 | DRM_ERROR("Buffer object map failed: %d.\n", ret); | ||
374 | |||
375 | return ttm_kmap_obj_virtual(&vbo->map, ¬_used); | ||
376 | } | ||