drm: base prime/dma-buf support (v5)
Subsystems (2)
Dave Airlie
maintainerPATCH 1/1 drm: base prime/dma-buf support (v5)
From: Dave Airlie <[email protected]>
This adds the basic drm dma-buf interface layer, called PRIME,
The main APIs exposed to userspace allow translating a 32-bit object handle to a file descriptor, and a file descriptor to a 32-bit object handle.
The flags value is currently limited to O_CLOEXEC.
Acknowledgements:
Daniel Vetter: lots of review
Rob Clark: cleaned up lots of the internals and did lifetime review.
v2: rename some functions after Chris preferred a green shed fix IS_ERR_OR_NULL -> IS_ERR
v3: Fix Ville pointed out using buffer + kmalloc
v4: add locking as per ickle review
v5: allow re-exporting the original dma-buf (Daniel)
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 4 + drivers/gpu/drm/drm_fops.c | 7 + drivers/gpu/drm/drm_gem.c | 9 ++ drivers/gpu/drm/drm_prime.c | 299 +++++++++++++++++++++++++++++++++++++++++++ include/drm/drm.h | 14 ++- include/drm/drmP.h | 62 +++++++++ 8 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/drm_prime.c
drivers/gpu/drm/Kconfig +1 -0
@@ -9,6 +9,7 @@ menuconfig DRM depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU select I2C select I2C_ALGOBIT + select DMA_SHARED_BUFFER help Kernel-level support for the Direct Rendering Infrastructure (DRI) introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/Makefile +1 -1
@@ -12,7 +12,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \ drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \ drm_crtc.o drm_modes.o drm_edid.o \ drm_info.o drm_debugfs.o drm_encoder_slave.o \ - drm_trace_points.o drm_global.o + drm_trace_points.o drm_global.o drm_prime.o drm-$(CONFIG_COMPAT) += drm_ioc32.o
drivers/gpu/drm/drm_drv.c +4 -0
@@ -136,6 +136,10 @@ static struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_GEM_OPEN , drm_gem_open_ioctl,DRM_AUTH |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETRESOURCES , drm_mode_getresources,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + +DRM_IOCTL_DEF (DRM_IOCTL_PRIME_HANDLE_TO_FD , drm_prime_handle_to_fd_ioctl,DRM_AUTH |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_PRIME_FD_TO_HANDLE , drm_prime_fd_to_handle_ioctl,DRM_AUTH |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETPLANERESOURCES , drm_mode_getplane_res,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETCRTC , drm_mode_getcrtc,DRM_CONTROL_ALLOW |DRM_UNLOCKED ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
drivers/gpu/drm/drm_fops.c +7 -0
@@ -271,6 +271,9 @@ static int drm_open_helper(struct inode *inode, struct file *filp,if (dev->driver->driver_features &DRIVER_GEM )drm_gem_open (dev, priv); +if (drm_core_check_feature (dev,DRIVER_PRIME )) +drm_prime_init_file_private (&priv->prime); +if (dev->driver->open) { ret = dev->driver->open (dev, priv);if (ret <0 )
@@ -571,6 +574,10 @@ int drm_release(struct inode *inode, struct file *filp)if (dev->driver->postclose) dev->driver->postclose (dev, file_priv); + +if (drm_core_check_feature (dev,DRIVER_PRIME )) +drm_prime_destroy_file_private (&file_priv->prime); +kfree (file_priv);/* ========================================================
drivers/gpu/drm/drm_gem.c +9 -0
@@ -35,6 +35,7 @@#include <linux/mman.h> #include <linux/pagemap.h> #include <linux/shmem_fs.h> +#include <linux/dma-buf.h> #include "drmP.h" /** @file drm_gem.c
@@ -232,6 +233,10 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle)idr_remove (&filp->object_idr, handle);spin_unlock (&filp->table_lock); +if (obj->import_attach) +drm_prime_remove_imported_buf_handle (&filp->prime, + obj->import_attach->dmabuf); +if (dev->driver->gem_close_object) dev->driver->gem_close_object (obj, filp);drm_gem_object_handle_unreference_unlocked (obj);
@@ -527,6 +532,10 @@ drm_gem_object_release_handle(int id, void *ptr, void *data)struct drm_gem_object *obj = ptr;struct drm_device *dev = obj->dev; +if (obj->import_attach) +drm_prime_remove_imported_buf_handle (&file_priv->prime, + obj->import_attach->dmabuf); +if (dev->driver->gem_close_object) dev->driver->gem_close_object (obj, file_priv);
drivers/gpu/drm/drm_prime.c new file +299 -0
299 lines not on this page · raw message
include/drm/drm.h +13 -1
@@ -617,6 +617,17 @@ struct drm_get_cap {__u64 value; }; +#define DRM_CLOEXEC O_CLOEXEC +struct drm_prime_handle { +__u32 handle; + +/** Flags.. only applicable for handle->fd */ +__u32 flags; + +/** Returned dmabuf file descriptor */ +__s32 fd; +}; +#include "drm_mode.h" #define DRM_IOCTL_BASE 'd'
@@ -673,7 +684,8 @@ struct drm_get_cap {#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock)#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock) -#define DRM_IOCTL_GEM_PRIME_OPEN DRM_IOWR(0x2e, struct drm_gem_open) +#define DRM_IOCTL_PRIME_HANDLE_TO_FD DRM_IOWR(0x2d, struct drm_prime_handle) +#define DRM_IOCTL_PRIME_FD_TO_HANDLE DRM_IOWR(0x2e, struct drm_prime_handle)#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30)#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31)
include/drm/drmP.h +62 -0
116 lines not on this page · raw message
Signature · 6 lines
1.7.7.6 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 13 lines · Dave Airlie
From: Dave Airlie <[email protected]>
This adds the basic drm dma-buf interface layer, called PRIME,
The main APIs exposed to userspace allow translating a 32-bit object handle to a file descriptor, and a file descriptor to a 32-bit object handle.
The flags value is currently limited to
O_CLOEXEC.Acknowledgements:
Daniel Vetter: lots of review
Rob Clark: cleaned up lots of the internals and did lifetime review.
Quoted 7 lines
v2: rename some functions after Chris preferred a green shed fix
IS_ERR_OR_NULL->IS_ERR
v3: Fix Ville pointed out using buffer + kmalloc
v4: add locking as per ickle review
v5: allow re-exporting the original dma-buf (Daniel)Signed-off-by Dave Airlie <[email protected]>
With the little comment about self-importing we've discussed on irc added, this is:
Signature · 3 lines
Daniel Vetter Mail: [email protected] Mobile: +41 (0)79 365 57 48
Rob Clark
Reviewed-byQuoted 20 lines · Daniel Vetter
Quoted 19 lines · Dave Airlie
From: Dave Airlie <[email protected]>
This adds the basic drm dma-buf interface layer, called PRIME,
The main APIs exposed to userspace allow translating a 32-bit object handle to a file descriptor, and a file descriptor to a 32-bit object handle.
The flags value is currently limited to
O_CLOEXEC.Acknowledgements:
Daniel Vetter: lots of review
Rob Clark: cleaned up lots of the internals and did lifetime review.v2: rename some functions after Chris preferred a green shed fix
IS_ERR_OR_NULL->IS_ERR
v3: Fix Ville pointed out using buffer + kmalloc
v4: add locking as per ickle review
v5: allow re-exporting the original dma-buf (Daniel)
Quoted 6 lines
Quoted 1 line
Signed-off-by Dave Airlie <[email protected]>With the little comment about self-importing we've discussed on irc added, this is:
Reviewed-by Daniel Vetter <[email protected]>
Quoted 8 lines
--
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Rob Clark
Quoted 6 lines · Daniel Vetter
Quoted 5 lines · Dave Airlie
From: Dave Airlie <[email protected]>
This adds the basic drm dma-buf interface layer, called PRIME,
The main APIs exposed to userspace allow translating a 32-bit object
handle
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
to a file descriptor, and a file descriptor to a 32-bit object handle.
The flags value is currently limited to
O_CLOEXEC.Acknowledgements:
Daniel Vetter: lots of review
Rob Clark: cleaned up lots of the internals and did lifetime review.v2: rename some functions after Chris preferred a green shed fix
IS_ERR_OR_NULL->IS_ERR
v3: Fix Ville pointed out using buffer + kmalloc
v4: add locking as per ickle review
v5: allow re-exporting the original dma-buf (Daniel)
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Dave Airlie <[email protected]>With the little comment about self-importing we've discussed on irc
added,
Quoted 5 lines
Quoted 3 lines
this is:
Reviewed-by Daniel Vetter <[email protected]>Reviewed-by Rob Clark <[email protected]>
Fwiw: Reviewed-by: Sumit Semwal <[email protected]>
Quoted 12 lines
Quoted 11 lines
--
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines
_______________________________________________
Linaro-mm-sig mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/linaro-mm-sig
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
InKi Dae
Reviewed-by2012년 3월 28일 수요일에 Sumit Semwal<[email protected]>님이 작성:
Quoted 10 lines · Rob Clark
Quoted 8 lines · Daniel Vetter
Quoted 6 lines · Dave Airlie
Quoted 5 lines
From: Dave Airlie <[email protected]>
This adds the basic drm dma-buf interface layer, called PRIME,
The main APIs exposed to userspace allow translating a 32-bit object
handle
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
to a file descriptor, and a file descriptor to a 32-bit object handle.
The flags value is currently limited to
O_CLOEXEC.Acknowledgements:
Daniel Vetter: lots of review
Rob Clark: cleaned up lots of the internals and did lifetime review.v2: rename some functions after Chris preferred a green shed fix
IS_ERR_OR_NULL->IS_ERR
v3: Fix Ville pointed out using buffer + kmalloc
v4: add locking as per ickle review
v5: allow re-exporting the original dma-buf (Daniel)
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Dave Airlie <[email protected]>With the little comment about self-importing we've discussed on irc
added,
Quoted 23 lines
Quoted 5 lines
Quoted 3 lines
this is:
Reviewed-by Daniel Vetter <[email protected]>Reviewed-by Rob Clark <[email protected]>Fwiw: Reviewed-by: Sumit Semwal <[email protected]>
Quoted 16 lines
Quoted 11 lines
--
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
Linaro-mm-sig mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/linaro-mm-sig
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 14 lines · On Tue, 27 Mar 2012 10:47:46 +0100 Dave Airlie <[email protected]> wrote:
From: Dave Airlie <[email protected]>
This adds the basic drm dma-buf interface layer, called PRIME,
The main APIs exposed to userspace allow translating a 32-bit object handle to a file descriptor, and a file descriptor to a 32-bit object handle.
The flags value is currently limited to
O_CLOEXEC.Acknowledgements:
Daniel Vetter: lots of review
Rob Clark: cleaned up lots of the internals and did lifetime review.
Quoted 7 lines
v2: rename some functions after Chris preferred a green shed fix
IS_ERR_OR_NULL->IS_ERR
v3: Fix Ville pointed out using buffer + kmalloc
v4: add locking as per ickle review
v5: allow re-exporting the original dma-buf (Daniel)Signed-off-by Dave Airlie <[email protected]>
I swear there was some other reason for the global hash... if only I could remember it.