aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2011-11-25 10:21:02 -0500
committerDave Airlie <airlied@redhat.com>2012-03-30 06:52:44 -0400
commit3248877ea1796915419fba7c89315fdbf00cb56a (patch)
tree4fab8743212004bc033e71e02a2e051b64001606 /include
parentf52b69f86e27903d6896ed5fa7cd280fec8de532 (diff)
drm: base prime/dma-buf support (v5)
This adds the basic drm dma-buf interface layer, called PRIME. This commit doesn't add any driver support, it is simply and agreed upon starting point so we can work towards merging driver support for the next merge window. Current drivers with work done are nouveau, i915, udl, exynos and omap. 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) Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Rob Clark <rob.clark@linaro.org> Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org> Reviewed-by: Inki Dae <inki.dae@samsung.com> Acked-by: Ben Widawsky <benjamin.widawsky@intel.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/drm/drm.h14
-rw-r--r--include/drm/drmP.h62
2 files changed, 75 insertions, 1 deletions
diff --git a/include/drm/drm.h b/include/drm/drm.h
index 34a7b89fd006..64ff02d5b730 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -617,6 +617,17 @@ struct drm_get_cap {
617 __u64 value; 617 __u64 value;
618}; 618};
619 619
620#define DRM_CLOEXEC O_CLOEXEC
621struct drm_prime_handle {
622 __u32 handle;
623
624 /** Flags.. only applicable for handle->fd */
625 __u32 flags;
626
627 /** Returned dmabuf file descriptor */
628 __s32 fd;
629};
630
620#include "drm_mode.h" 631#include "drm_mode.h"
621 632
622#define DRM_IOCTL_BASE 'd' 633#define DRM_IOCTL_BASE 'd'
@@ -673,7 +684,8 @@ struct drm_get_cap {
673#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock) 684#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock)
674#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock) 685#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock)
675 686
676#define DRM_IOCTL_GEM_PRIME_OPEN DRM_IOWR(0x2e, struct drm_gem_open) 687#define DRM_IOCTL_PRIME_HANDLE_TO_FD DRM_IOWR(0x2d, struct drm_prime_handle)
688#define DRM_IOCTL_PRIME_FD_TO_HANDLE DRM_IOWR(0x2e, struct drm_prime_handle)
677 689
678#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30) 690#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30)
679#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31) 691#define DRM_IOCTL_AGP_RELEASE DRM_IO( 0x31)
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 574bd1c81ebd..dd731043fecd 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -91,6 +91,7 @@ struct drm_device;
91#define DRM_UT_CORE 0x01 91#define DRM_UT_CORE 0x01
92#define DRM_UT_DRIVER 0x02 92#define DRM_UT_DRIVER 0x02
93#define DRM_UT_KMS 0x04 93#define DRM_UT_KMS 0x04
94#define DRM_UT_PRIME 0x08
94/* 95/*
95 * Three debug levels are defined. 96 * Three debug levels are defined.
96 * drm_core, drm_driver, drm_kms 97 * drm_core, drm_driver, drm_kms
@@ -150,6 +151,7 @@ int drm_err(const char *func, const char *format, ...);
150#define DRIVER_IRQ_VBL2 0x800 151#define DRIVER_IRQ_VBL2 0x800
151#define DRIVER_GEM 0x1000 152#define DRIVER_GEM 0x1000
152#define DRIVER_MODESET 0x2000 153#define DRIVER_MODESET 0x2000
154#define DRIVER_PRIME 0x4000
153 155
154#define DRIVER_BUS_PCI 0x1 156#define DRIVER_BUS_PCI 0x1
155#define DRIVER_BUS_PLATFORM 0x2 157#define DRIVER_BUS_PLATFORM 0x2
@@ -215,6 +217,11 @@ int drm_err(const char *func, const char *format, ...);
215 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \ 217 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME, \
216 __func__, fmt, ##args); \ 218 __func__, fmt, ##args); \
217 } while (0) 219 } while (0)
220#define DRM_DEBUG_PRIME(fmt, args...) \
221 do { \
222 drm_ut_debug_printk(DRM_UT_PRIME, DRM_NAME, \
223 __func__, fmt, ##args); \
224 } while (0)
218#define DRM_LOG(fmt, args...) \ 225#define DRM_LOG(fmt, args...) \
219 do { \ 226 do { \
220 drm_ut_debug_printk(DRM_UT_CORE, NULL, \ 227 drm_ut_debug_printk(DRM_UT_CORE, NULL, \
@@ -238,6 +245,7 @@ int drm_err(const char *func, const char *format, ...);
238#else 245#else
239#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0) 246#define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
240#define DRM_DEBUG_KMS(fmt, args...) do { } while (0) 247#define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
248#define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
241#define DRM_DEBUG(fmt, arg...) do { } while (0) 249#define DRM_DEBUG(fmt, arg...) do { } while (0)
242#define DRM_LOG(fmt, arg...) do { } while (0) 250#define DRM_LOG(fmt, arg...) do { } while (0)
243#define DRM_LOG_KMS(fmt, args...) do { } while (0) 251#define DRM_LOG_KMS(fmt, args...) do { } while (0)
@@ -410,6 +418,12 @@ struct drm_pending_event {
410 void (*destroy)(struct drm_pending_event *event); 418 void (*destroy)(struct drm_pending_event *event);
411}; 419};
412 420
421/* initial implementaton using a linked list - todo hashtab */
422struct drm_prime_file_private {
423 struct list_head head;
424 struct mutex lock;
425};
426
413/** File private data */ 427/** File private data */
414struct drm_file { 428struct drm_file {
415 int authenticated; 429 int authenticated;
@@ -437,6 +451,8 @@ struct drm_file {
437 wait_queue_head_t event_wait; 451 wait_queue_head_t event_wait;
438 struct list_head event_list; 452 struct list_head event_list;
439 int event_space; 453 int event_space;
454
455 struct drm_prime_file_private prime;
440}; 456};
441 457
442/** Wait queue */ 458/** Wait queue */
@@ -652,6 +668,12 @@ struct drm_gem_object {
652 uint32_t pending_write_domain; 668 uint32_t pending_write_domain;
653 669
654 void *driver_private; 670 void *driver_private;
671
672 /* dma buf exported from this GEM object */
673 struct dma_buf *export_dma_buf;
674
675 /* dma buf attachment backing this object */
676 struct dma_buf_attachment *import_attach;
655}; 677};
656 678
657#include "drm_crtc.h" 679#include "drm_crtc.h"
@@ -890,6 +912,20 @@ struct drm_driver {
890 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *); 912 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
891 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *); 913 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
892 914
915 /* prime: */
916 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
917 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
918 uint32_t handle, uint32_t flags, int *prime_fd);
919 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
920 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
921 int prime_fd, uint32_t *handle);
922 /* export GEM -> dmabuf */
923 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
924 struct drm_gem_object *obj, int flags);
925 /* import dmabuf -> GEM */
926 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
927 struct dma_buf *dma_buf);
928
893 /* vga arb irq handler */ 929 /* vga arb irq handler */
894 void (*vgaarb_irq)(struct drm_device *dev, bool state); 930 void (*vgaarb_irq)(struct drm_device *dev, bool state);
895 931
@@ -1509,6 +1545,32 @@ extern int drm_vblank_info(struct seq_file *m, void *data);
1509extern int drm_clients_info(struct seq_file *m, void* data); 1545extern int drm_clients_info(struct seq_file *m, void* data);
1510extern int drm_gem_name_info(struct seq_file *m, void *data); 1546extern int drm_gem_name_info(struct seq_file *m, void *data);
1511 1547
1548
1549extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1550 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1551 int *prime_fd);
1552extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1553 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1554
1555extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1556 struct drm_file *file_priv);
1557extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1558 struct drm_file *file_priv);
1559
1560extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1561extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1562
1563
1564void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1565void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1566int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1567int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1568void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1569
1570int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1571int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1572 struct drm_gem_object **obj);
1573
1512#if DRM_DEBUG_CODE 1574#if DRM_DEBUG_CODE
1513extern int drm_vma_info(struct seq_file *m, void *data); 1575extern int drm_vma_info(struct seq_file *m, void *data);
1514#endif 1576#endif