drm/prime: Remove duplicate forward declaration
Subsystems (4)
PATCH 1/5 drm/prime: Remove duplicate forward declaration
From: Thierry Reding <[email protected]>
struct device is forward-declared twice. Remove the second instance.
--- include/drm/drm_prime.h | 2 -- 1 file changed, 2 deletions(-)
include/drm/drm_prime.h +0 -2
@@ -59,8 +59,6 @@ struct drm_device;struct drm_gem_object ;struct drm_file ; -struct device ; -struct dma_buf *drm_gem_prime_export (struct drm_device *dev,struct drm_gem_object *obj,int flags);
Signature · 1 line
2.15.1
A message that is not in the archive (sent off-list or not yet received): 20180111214420.26203-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/5 drm/prime: Export more helpers for drivers
From: Thierry Reding <[email protected]>
Export some more of the helpers in order to allow drivers to more fine- grainedly select which helpers to use. This gives drivers an easy way to reuse a lot of the code in the helpers while at the same time allowing them to provide their own implementation for other functions in struct dma_buf_ops.
--- drivers/gpu/drm/drm_prime.c | 23 +++++++++++++---------- include/drm/drm_prime.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/drm_prime.c +13 -10
@@ -180,9 +180,8 @@ static int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fprireturn -ENOENT ; } -static int drm_gem_map_attach (struct dma_buf *dma_buf, -struct device *target_dev, -struct dma_buf_attachment *attach) +int drm_gem_map_attach (struct dma_buf *dma_buf,struct device *target_dev, +struct dma_buf_attachment *attach) {struct drm_prime_attachment *prime_attach;struct drm_gem_object *obj = dma_buf->priv;
@@ -200,9 +199,10 @@ static int drm_gem_map_attach(struct dma_buf *dma_buf,return dev->driver->gem_prime_pin (obj); } +EXPORT_SYMBOL (drm_gem_map_attach); -static void drm_gem_map_detach (struct dma_buf *dma_buf, -struct dma_buf_attachment *attach) +void drm_gem_map_detach (struct dma_buf *dma_buf, +struct dma_buf_attachment *attach) {struct drm_prime_attachment *prime_attach = attach->priv;struct drm_gem_object *obj = dma_buf->priv;
@@ -228,6 +228,7 @@ static void drm_gem_map_detach(struct dma_buf *dma_buf,kfree (prime_attach); attach->priv =NULL ; } +EXPORT_SYMBOL (drm_gem_map_detach);void drm_prime_remove_buf_handle_locked (struct drm_prime_file_private *prime_fpriv,struct dma_buf *dma_buf)
@@ -254,8 +255,8 @@ void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpr } } -static struct sg_table *drm_gem_map_dma_buf (struct dma_buf_attachment *attach, -enum dma_data_direction dir) +struct sg_table *drm_gem_map_dma_buf (struct dma_buf_attachment *attach, +enum dma_data_direction dir) {struct drm_prime_attachment *prime_attach = attach->priv;struct drm_gem_object *obj = attach->dmabuf->priv;
@@ -291,13 +292,15 @@ static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,return sgt; } +EXPORT_SYMBOL (drm_gem_map_dma_buf); -static void drm_gem_unmap_dma_buf (struct dma_buf_attachment *attach, -struct sg_table *sgt, -enum dma_data_direction dir) +void drm_gem_unmap_dma_buf (struct dma_buf_attachment *attach, +struct sg_table *sgt, +enum dma_data_direction dir) {/* nothing to be done here */ } +EXPORT_SYMBOL (drm_gem_unmap_dma_buf);/** * drm_gem_dmabuf_export - dma_buf export implementation for GEM
include/drm/drm_prime.h +12 -0
@@ -50,8 +50,10 @@ struct drm_prime_file_private {struct rb_root handles; }; +enum dma_data_direction ;struct device ; +struct dma_buf_attachment ;struct dma_buf_export_info ;struct dma_buf ;
@@ -59,6 +61,16 @@ struct drm_device;struct drm_gem_object ;struct drm_file ; +int drm_gem_map_attach (struct dma_buf *dma_buf,struct device *target_dev, +struct dma_buf_attachment *attach); +void drm_gem_map_detach (struct dma_buf *dma_buf, +struct dma_buf_attachment *attach); +struct sg_table *drm_gem_map_dma_buf (struct dma_buf_attachment *attach, +enum dma_data_direction dir); +void drm_gem_unmap_dma_buf (struct dma_buf_attachment *attach, +struct sg_table *sgt, +enum dma_data_direction dir); +struct dma_buf *drm_gem_prime_export (struct drm_device *dev,struct drm_gem_object *obj,int flags);
Signature · 1 line
2.15.1
A message that is not in the archive (sent off-list or not yet received): 20180111214420.26203-2-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [Nouveau] [PATCH 2/5] drm/prime: Export more helpers for drivers
Quoted 9 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Export some more of the helpers in order to allow drivers to more fine- grainedly select which helpers to use. This gives drivers an easy way to reuse a lot of the code in the helpers while at the same time allowing them to provide their own implementation for other functions in struct
dma_buf_ops.Signed-off-by Thierry Reding <[email protected]>
Same request as with the amd one: Pls supply a bit of kerneldoc and maybe polished intro section. Otherwise lgtm.
-Daniel
Quoted 111 lines
--- drivers/gpu/drm/drm_prime.c | 23 +++++++++++++---------- include/drm/drm_prime.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_prime.c +13
-10@@ -180,9 +180,8 @@ static int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fprireturn -ENOENT ; } -static int drm_gem_map_attach (struct dma_buf *dma_buf, -struct device *target_dev, -struct dma_buf_attachment *attach) +int drm_gem_map_attach (struct dma_buf *dma_buf,struct device *target_dev, +struct dma_buf_attachment *attach) {struct drm_prime_attachment *prime_attach;struct drm_gem_object *obj = dma_buf->priv;@@ -200,9 +199,10 @@ static int drm_gem_map_attach(struct dma_buf *dma_buf,return dev->driver->gem_prime_pin (obj); } +EXPORT_SYMBOL (drm_gem_map_attach); -static void drm_gem_map_detach (struct dma_buf *dma_buf, -struct dma_buf_attachment *attach) +void drm_gem_map_detach (struct dma_buf *dma_buf, +struct dma_buf_attachment *attach) {struct drm_prime_attachment *prime_attach = attach->priv;struct drm_gem_object *obj = dma_buf->priv;@@ -228,6 +228,7 @@ static void drm_gem_map_detach(struct dma_buf *dma_buf,kfree (prime_attach); attach->priv =NULL ; } +EXPORT_SYMBOL (drm_gem_map_detach);void drm_prime_remove_buf_handle_locked (struct drm_prime_file_private *prime_fpriv,struct dma_buf *dma_buf)@@ -254,8 +255,8 @@ void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpr } } -static struct sg_table *drm_gem_map_dma_buf (struct dma_buf_attachment *attach, -enum dma_data_direction dir) +struct sg_table *drm_gem_map_dma_buf (struct dma_buf_attachment *attach, +enum dma_data_direction dir) {struct drm_prime_attachment *prime_attach = attach->priv;struct drm_gem_object *obj = attach->dmabuf->priv;@@ -291,13 +292,15 @@ static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,return sgt; } +EXPORT_SYMBOL (drm_gem_map_dma_buf); -static void drm_gem_unmap_dma_buf (struct dma_buf_attachment *attach, -struct sg_table *sgt, -enum dma_data_direction dir) +void drm_gem_unmap_dma_buf (struct dma_buf_attachment *attach, +struct sg_table *sgt, +enum dma_data_direction dir) {/* nothing to be done here */ } +EXPORT_SYMBOL (drm_gem_unmap_dma_buf);/** * drm_gem_dmabuf_export - dma_buf export implementation for GEM include/drm/drm_prime.h +12
-0@@ -50,8 +50,10 @@ struct drm_prime_file_private {struct rb_root handles; }; +enum dma_data_direction ;struct device ; +struct dma_buf_attachment ;struct dma_buf_export_info ;struct dma_buf ;@@ -59,6 +61,16 @@ struct drm_device;struct drm_gem_object ;struct drm_file ; +int drm_gem_map_attach (struct dma_buf *dma_buf,struct device *target_dev, +struct dma_buf_attachment *attach); +void drm_gem_map_detach (struct dma_buf *dma_buf, +struct dma_buf_attachment *attach); +struct sg_table *drm_gem_map_dma_buf (struct dma_buf_attachment *attach, +enum dma_data_direction dir); +void drm_gem_unmap_dma_buf (struct dma_buf_attachment *attach, +struct sg_table *sgt, +enum dma_data_direction dir); +struct dma_buf *drm_gem_prime_export (struct drm_device *dev,struct drm_gem_object *obj,int flags);Signature · 6 lines
2.15.1 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 3/5 drm/nouveau: Provide custom struct dma_buf_ops
In reply to a message not in the archiveFrom: Thierry Reding <[email protected]>
Instead of relying on the DRM PRIME helpers to provide all of the DMA-BUF operations, provide a custom version of struct dma_buf_ops to allow additional functionality to be implemented.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 9 +- drivers/gpu/drm/nouveau/nouveau_gem.h | 15 +-- drivers/gpu/drm/nouveau/nouveau_prime.c | 157 +++++++++++++++++++++++++------- 3 files changed, 135 insertions(+), 46 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +3 -6
@@ -1081,15 +1081,12 @@ driver_stub = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_export = drm_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_export = nouveau_gem_prime_export, + .gem_prime_import = nouveau_gem_prime_import, .gem_prime_pin = nouveau_gem_prime_pin, - .gem_prime_res_obj = nouveau_gem_prime_res_obj, .gem_prime_unpin = nouveau_gem_prime_unpin, + .gem_prime_res_obj = nouveau_gem_prime_res_obj, .gem_prime_get_sg_table = nouveau_gem_prime_get_sg_table, - .gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table, - .gem_prime_vmap = nouveau_gem_prime_vmap, - .gem_prime_vunmap = nouveau_gem_prime_vunmap, .gem_free_object_unlocked = nouveau_gem_object_del, .gem_open_object = nouveau_gem_object_open,
drivers/gpu/drm/nouveau/nouveau_gem.h +8 -7
@@ -32,13 +32,14 @@ extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *,extern int nouveau_gem_ioctl_info (struct drm_device *,void *,struct drm_file *); -extern int nouveau_gem_prime_pin (struct drm_gem_object *); +struct dma_buf *nouveau_gem_prime_export (struct drm_device *dev, +struct drm_gem_object *obj, +int flags); +struct drm_gem_object *nouveau_gem_prime_import (struct drm_device *drm, +struct dma_buf *buf); +int nouveau_gem_prime_pin (struct drm_gem_object *obj); +void nouveau_gem_prime_unpin (struct drm_gem_object *obj);struct reservation_object *nouveau_gem_prime_res_obj (struct drm_gem_object *); -extern void nouveau_gem_prime_unpin (struct drm_gem_object *); -extern struct sg_table *nouveau_gem_prime_get_sg_table (struct drm_gem_object *); -extern struct drm_gem_object *nouveau_gem_prime_import_sg_table ( -struct drm_device *,struct dma_buf_attachment *,struct sg_table *); -extern void *nouveau_gem_prime_vmap (struct drm_gem_object *); -extern void nouveau_gem_prime_vunmap (struct drm_gem_object *,void *); +struct sg_table *nouveau_gem_prime_get_sg_table (struct drm_gem_object *obj);#endif
drivers/gpu/drm/nouveau/nouveau_prime.c +124 -33
196 lines not on this page · raw message
Signature · 1 line
2.15.1
PATCH 4/5 drm/nouveau: prime: Implement mmap()
In reply to a message not in the archiveFrom: Thierry Reding <[email protected]>
Provide an implementation of mmap() for PRIME exported buffers. This allows userspace to map these buffers and access them using the CPU.
--- drivers/gpu/drm/nouveau/nouveau_prime.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/gpu/drm/nouveau/nouveau_prime.c +32 -0
@@ -50,6 +50,37 @@ static void nouveau_gem_prime_kunmap(struct dma_buf *buf, unsigned long page, { } +static inline u64 nouveau_bo_mmap_offset (struct nouveau_bo *bo) +{ +return drm_vma_node_offset_addr (&bo->bo.vma_node) >>PAGE_SHIFT ; +} + +static int nouveau_gem_prime_mmap (struct dma_buf *buf, +struct vm_area_struct *vma) +{ +struct nouveau_bo *bo =nouveau_gem_object (buf->priv); +struct drm_gem_object *obj = buf->priv; +int ret; + +/* check for valid size */ +if (obj->size < vma->vm_end - vma->vm_start) +return -EINVAL ; + + vma->vm_pgoff +=nouveau_bo_mmap_offset (bo); + +if (unlikely (vma->vm_pgoff <DRM_FILE_PAGE_OFFSET )) +return drm_legacy_mmap (vma->vm_file, vma); + + ret =drm_vma_node_allow (&obj->vma_node, vma->vm_file->private_data); +if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, bo->bo.bdev); +drm_vma_node_revoke (&obj->vma_node, vma->vm_file->private_data); + +return ret; +} +static void *nouveau_gem_prime_vmap (struct dma_buf *buf) {struct nouveau_bo *bo =nouveau_gem_object (buf->priv);
@@ -79,6 +110,7 @@ static const struct dma_buf_ops nouveau_gem_prime_dmabuf_ops = { .unmap_atomic = nouveau_gem_prime_kunmap_atomic, .map = nouveau_gem_prime_kmap, .unmap = nouveau_gem_prime_kunmap, + .mmap = nouveau_gem_prime_mmap, .vmap = nouveau_gem_prime_vmap, .vunmap = nouveau_gem_prime_vunmap, };
Signature · 1 line
2.15.1
PATCH 5/5 drm/nouveau: prime: Implement cache maintenance
In reply to a message not in the archiveFrom: Thierry Reding <[email protected]>
Implement the ->begin_cpu_access() and ->end_cpu_access() callbacks to allow userspace to invalidate the cache before accessing a buffer that is exported using PRIME and flush the cache after modifying the buffer through its userspace mapping.
--- drivers/gpu/drm/nouveau/nouveau_prime.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/gpu/drm/nouveau/nouveau_prime.c +22 -0
@@ -29,6 +29,26 @@#include "nouveau_drv.h" #include "nouveau_gem.h" +static int nouveau_gem_prime_begin_cpu_access (struct dma_buf *buf, +enum dma_data_direction direction) +{ +struct nouveau_bo *bo =nouveau_gem_object (buf->priv); + +nouveau_bo_sync_for_cpu (bo); + +return 0 ; +} + +static int nouveau_gem_prime_end_cpu_access (struct dma_buf *buf, +enum dma_data_direction direction) +{ +struct nouveau_bo *bo =nouveau_gem_object (buf->priv); + +nouveau_bo_sync_for_device (bo); + +return 0 ; +} +static void *nouveau_gem_prime_kmap_atomic (struct dma_buf *buf,unsigned long page) {
@@ -106,6 +126,8 @@ static const struct dma_buf_ops nouveau_gem_prime_dmabuf_ops = { .map_dma_buf = drm_gem_map_dma_buf, .unmap_dma_buf = drm_gem_unmap_dma_buf, .release = drm_gem_dmabuf_release, + .begin_cpu_access = nouveau_gem_prime_begin_cpu_access, + .end_cpu_access = nouveau_gem_prime_end_cpu_access, .map_atomic = nouveau_gem_prime_kmap_atomic, .unmap_atomic = nouveau_gem_prime_kunmap_atomic, .map = nouveau_gem_prime_kmap,
Signature · 1 line
2.15.1