Commit a745fb1c authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/gem: Update internal GEM vmap/vunmap interfaces to use struct dma_buf_map

GEM's vmap and vunmap interfaces now wrap memory pointers in struct
dma_buf_map.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Tested-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20201103093015.1063-8-tzimmermann@suse.de
parent 49a3f51d
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Copyright 2018 Noralf Trønnes * Copyright 2018 Noralf Trønnes
*/ */
#include <linux/dma-buf-map.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -304,7 +305,8 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u ...@@ -304,7 +305,8 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u
*/ */
void *drm_client_buffer_vmap(struct drm_client_buffer *buffer) void *drm_client_buffer_vmap(struct drm_client_buffer *buffer)
{ {
void *vaddr; struct dma_buf_map map;
int ret;
if (buffer->vaddr) if (buffer->vaddr)
return buffer->vaddr; return buffer->vaddr;
...@@ -317,13 +319,13 @@ void *drm_client_buffer_vmap(struct drm_client_buffer *buffer) ...@@ -317,13 +319,13 @@ void *drm_client_buffer_vmap(struct drm_client_buffer *buffer)
* fd_install step out of the driver backend hooks, to make that * fd_install step out of the driver backend hooks, to make that
* final step optional for internal users. * final step optional for internal users.
*/ */
vaddr = drm_gem_vmap(buffer->gem); ret = drm_gem_vmap(buffer->gem, &map);
if (IS_ERR(vaddr)) if (ret)
return vaddr; return ERR_PTR(ret);
buffer->vaddr = vaddr; buffer->vaddr = map.vaddr;
return vaddr; return map.vaddr;
} }
EXPORT_SYMBOL(drm_client_buffer_vmap); EXPORT_SYMBOL(drm_client_buffer_vmap);
...@@ -337,7 +339,9 @@ EXPORT_SYMBOL(drm_client_buffer_vmap); ...@@ -337,7 +339,9 @@ EXPORT_SYMBOL(drm_client_buffer_vmap);
*/ */
void drm_client_buffer_vunmap(struct drm_client_buffer *buffer) void drm_client_buffer_vunmap(struct drm_client_buffer *buffer)
{ {
drm_gem_vunmap(buffer->gem, buffer->vaddr); struct dma_buf_map map = DMA_BUF_MAP_INIT_VADDR(buffer->vaddr);
drm_gem_vunmap(buffer->gem, &map);
buffer->vaddr = NULL; buffer->vaddr = NULL;
} }
EXPORT_SYMBOL(drm_client_buffer_vunmap); EXPORT_SYMBOL(drm_client_buffer_vunmap);
......
...@@ -1206,32 +1206,32 @@ void drm_gem_unpin(struct drm_gem_object *obj) ...@@ -1206,32 +1206,32 @@ void drm_gem_unpin(struct drm_gem_object *obj)
obj->funcs->unpin(obj); obj->funcs->unpin(obj);
} }
void *drm_gem_vmap(struct drm_gem_object *obj) int drm_gem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
{ {
struct dma_buf_map map;
int ret; int ret;
if (!obj->funcs->vmap) if (!obj->funcs->vmap)
return ERR_PTR(-EOPNOTSUPP); return -EOPNOTSUPP;
ret = obj->funcs->vmap(obj, &map); ret = obj->funcs->vmap(obj, map);
if (ret) if (ret)
return ERR_PTR(ret); return ret;
else if (dma_buf_map_is_null(&map)) else if (dma_buf_map_is_null(map))
return ERR_PTR(-ENOMEM); return -ENOMEM;
return map.vaddr; return 0;
} }
void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr) void drm_gem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map)
{ {
struct dma_buf_map map = DMA_BUF_MAP_INIT_VADDR(vaddr); if (dma_buf_map_is_null(map))
if (!vaddr)
return; return;
if (obj->funcs->vunmap) if (obj->funcs->vunmap)
obj->funcs->vunmap(obj, &map); obj->funcs->vunmap(obj, map);
/* Always set the mapping to NULL. Callers may rely on this. */
dma_buf_map_clear(map);
} }
/** /**
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
struct dentry; struct dentry;
struct dma_buf; struct dma_buf;
struct dma_buf_map;
struct drm_connector; struct drm_connector;
struct drm_crtc; struct drm_crtc;
struct drm_framebuffer; struct drm_framebuffer;
...@@ -187,8 +188,8 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent, ...@@ -187,8 +188,8 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent,
int drm_gem_pin(struct drm_gem_object *obj); int drm_gem_pin(struct drm_gem_object *obj);
void drm_gem_unpin(struct drm_gem_object *obj); void drm_gem_unpin(struct drm_gem_object *obj);
void *drm_gem_vmap(struct drm_gem_object *obj); int drm_gem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr); void drm_gem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map);
/* drm_debugfs.c drm_debugfs_crc.c */ /* drm_debugfs.c drm_debugfs_crc.c */
#if defined(CONFIG_DEBUG_FS) #if defined(CONFIG_DEBUG_FS)
......
...@@ -667,21 +667,15 @@ EXPORT_SYMBOL(drm_gem_unmap_dma_buf); ...@@ -667,21 +667,15 @@ EXPORT_SYMBOL(drm_gem_unmap_dma_buf);
* *
* Sets up a kernel virtual mapping. This can be used as the &dma_buf_ops.vmap * Sets up a kernel virtual mapping. This can be used as the &dma_buf_ops.vmap
* callback. Calls into &drm_gem_object_funcs.vmap for device specific handling. * callback. Calls into &drm_gem_object_funcs.vmap for device specific handling.
* The kernel virtual address is returned in map.
* *
* Returns the kernel virtual address or NULL on failure. * Returns 0 on success or a negative errno code otherwise.
*/ */
int drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct dma_buf_map *map) int drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct dma_buf_map *map)
{ {
struct drm_gem_object *obj = dma_buf->priv; struct drm_gem_object *obj = dma_buf->priv;
void *vaddr;
vaddr = drm_gem_vmap(obj); return drm_gem_vmap(obj, map);
if (IS_ERR(vaddr))
return PTR_ERR(vaddr);
dma_buf_map_set_vaddr(map, vaddr);
return 0;
} }
EXPORT_SYMBOL(drm_gem_dmabuf_vmap); EXPORT_SYMBOL(drm_gem_dmabuf_vmap);
...@@ -697,7 +691,7 @@ void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct dma_buf_map *map) ...@@ -697,7 +691,7 @@ void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct dma_buf_map *map)
{ {
struct drm_gem_object *obj = dma_buf->priv; struct drm_gem_object *obj = dma_buf->priv;
drm_gem_vunmap(obj, map->vaddr); drm_gem_vunmap(obj, map);
} }
EXPORT_SYMBOL(drm_gem_dmabuf_vunmap); EXPORT_SYMBOL(drm_gem_dmabuf_vunmap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment