drm: dumb scanout create/mmap for intel/radeon (v3)
Subsystems (4)
Dave Airlie
maintainerPATCH 1/1 drm: dumb scanout create/mmap for intel/radeon (v3)
From: Dave Airlie <[email protected]>
This is just an idea that might or might not be a good idea, it basically adds two ioctls to create a dumb and map a dumb buffer suitable for scanout. The handle can be passed to the KMS ioctls to create a framebuffer.
It looks to me like it would be useful in the following cases:
a) in development drivers - we can always provide a shadowfb fallback.
b) libkms users - we can clean up libkms a lot and avoid linking to libdrm_*.
c) plymouth via libkms is a lot easier.
Userspace bits would be just calls + mmaps. We could probably mark these handles somehow as not being suitable for acceleartion so as top stop people who are dumber than dumb.
--- drivers/gpu/drm/drm_crtc.c | 33 +++++++++++ drivers/gpu/drm/drm_drv.c | 5 +- drivers/gpu/drm/drm_gem.c | 3 +- drivers/gpu/drm/i915/i915_drv.c | 3 + drivers/gpu/drm/i915/i915_drv.h | 7 ++ drivers/gpu/drm/i915/i915_gem.c | 103 ++++++++++++++++++++++++---------- drivers/gpu/drm/radeon/radeon.h | 9 +++ drivers/gpu/drm/radeon/radeon_drv.c | 13 ++++ drivers/gpu/drm/radeon/radeon_fb.c | 2 +- drivers/gpu/drm/radeon/radeon_gem.c | 53 ++++++++++++++++-- drivers/gpu/drm/radeon/radeon_mode.h | 1 + include/drm/drm.h | 4 + include/drm/drmP.h | 12 ++++ include/drm/drm_crtc.h | 7 ++ include/drm/drm_mode.h | 29 ++++++++++ 15 files changed, 246 insertions(+), 38 deletions(-)
drivers/gpu/drm/drm_crtc.c +33 -0
@@ -2674,3 +2674,36 @@ out:mutex_unlock (&dev->mode_config.mutex);return ret; } + +int drm_mode_create_dumb_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +struct drm_mode_create_dumb *args = data; + +if (!dev->driver->dumb_create) +return -ENOSYS ; +return dev->driver->dumb_create (file_priv, dev, args); +} + +int drm_mode_mmap_dumb_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +struct drm_mode_map_dumb *args = data; + +/* call driver ioctl to get mmap offset */ +if (!dev->driver->dumb_map_offset) +return -ENOSYS ; + +return dev->driver->dumb_map_offset (file_priv, dev, args->handle, &args->offset); +} + +int drm_mode_destroy_dumb_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +struct drm_mode_destroy_dumb *args = data; + +if (!dev->driver->dumb_destroy) +return -ENOSYS ; + +return dev->driver->dumb_destroy (file_priv, dev, args->handle); +}
drivers/gpu/drm/drm_drv.c +4 -1
@@ -150,7 +150,10 @@ static struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB , drm_mode_addfb,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_RMFB , drm_mode_rmfb,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_PAGE_FLIP , drm_mode_page_flip_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), - DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED) +DRM_IOCTL_DEF (DRM_IOCTL_MODE_DIRTYFB , drm_mode_dirtyfb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_CREATE_DUMB , drm_mode_create_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_MAP_DUMB , drm_mode_mmap_dumb_ioctl,DRM_MASTER |DRM_CONTROL_ALLOW |DRM_UNLOCKED ), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROY_DUMB, drm_mode_destroy_dumb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED) };#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
drivers/gpu/drm/drm_gem.c +2 -1
@@ -181,7 +181,7 @@ EXPORT_SYMBOL(drm_gem_object_alloc);/** * Removes the mapping from handle to filp for this object. */ -static int +int drm_gem_handle_delete (struct drm_file *filp,u32 handle) {struct drm_device *dev;
@@ -214,6 +214,7 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle)return 0 ; } +EXPORT_SYMBOL (drm_gem_handle_delete);/** * Create a handle for this object. This adds a handle reference
drivers/gpu/drm/i915/i915_drv.c +3 -0
@@ -678,6 +678,9 @@ static struct drm_driver driver = { .gem_init_object = i915_gem_init_object, .gem_free_object = i915_gem_free_object, .gem_vm_ops = &i915_gem_vm_ops, + .dumb_create = i915_gem_dumb_create, + .dumb_map_offset = i915_gem_mmap_gtt, + .dumb_destroy = i915_gem_dumb_destroy, .ioctls = i915_ioctls, .fops = { .owner = THIS_MODULE,
drivers/gpu/drm/i915/i915_drv.h +7 -0
@@ -1113,6 +1113,13 @@ void i915_gem_object_move_to_active(struct drm_i915_gem_object *obj,struct intel_ring_buffer *ring, u32 seqno); +int i915_gem_dumb_create (struct drm_file *file_priv, +struct drm_device *dev, +struct drm_mode_create_dumb *args); +int i915_gem_mmap_gtt (struct drm_file *file_priv,struct drm_device *dev, +uint32_t handle,uint64_t *offset); +int i915_gem_dumb_destroy (struct drm_file *file_priv,struct drm_device *dev, +uint32_t handle);/** * Returns true if seq1 is later than seq2. */
drivers/gpu/drm/i915/i915_gem.c +73 -30
152 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon.h +9 -0
@@ -287,6 +287,15 @@ int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain, uint64_t *gpu_addr);void radeon_gem_object_unpin (struct drm_gem_object *obj); +int radeon_mode_dumb_create (struct drm_file *file_priv, +struct drm_device *dev, +struct drm_mode_create_dumb *args); +int radeon_mode_dumb_mmap (struct drm_file *filp, +struct drm_device *dev, +uint32_t handle,uint64_t *offset_p); +int radeon_mode_dumb_destroy (struct drm_file *file_priv, +struct drm_device *dev, +uint32_t handle);/* * GART structures, functions & helpers
drivers/gpu/drm/radeon/radeon_drv.c +13 -0
@@ -84,6 +84,16 @@ extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc,extern struct drm_ioctl_desc radeon_ioctls_kms[];extern int radeon_max_kms_ioctl;int radeon_mmap (struct file *filp,struct vm_area_struct *vma); +int radeon_mode_dumb_mmap (struct drm_file *filp, +struct drm_device *dev, +uint32_t handle,uint64_t *offset_p); +int radeon_mode_dumb_create (struct drm_file *file_priv, +struct drm_device *dev, +struct drm_mode_create_dumb *args); +int radeon_mode_dumb_destroy (struct drm_file *file_priv, +struct drm_device *dev, +uint32_t handle); +#if defined(CONFIG_DEBUG_FS )int radeon_debugfs_init (struct drm_minor *minor);void radeon_debugfs_cleanup (struct drm_minor *minor);
@@ -318,6 +328,9 @@ static struct drm_driver kms_driver = { .gem_init_object = radeon_gem_object_init, .gem_free_object = radeon_gem_object_free, .dma_ioctl = radeon_dma_ioctl_kms, + .dumb_create = radeon_mode_dumb_create, + .dumb_map_offset = radeon_mode_dumb_mmap, + .dumb_destroy = radeon_mode_dumb_destroy, .fops = { .owner = THIS_MODULE, .open = drm_open,
drivers/gpu/drm/radeon/radeon_fb.c +1 -1
@@ -64,7 +64,7 @@ static struct fb_ops radeonfb_ops = { }; -static int radeon_align_pitch (struct radeon_device *rdev,int width,int bpp,bool tiled) +int radeon_align_pitch (struct radeon_device *rdev,int width,int bpp,bool tiled) {int aligned = width;int align_large = (ASIC_IS_AVIVO (rdev)) || tiled;
drivers/gpu/drm/radeon/radeon_gem.c +48 -5
74 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_mode.h +1 -0
@@ -665,4 +665,5 @@ void radeon_fb_output_poll_changed(struct radeon_device *rdev);void radeon_crtc_handle_flip (struct radeon_device *rdev,int crtc_id); +int radeon_align_pitch (struct radeon_device *rdev,int width,int bpp,bool tiled);#endif
include/drm/drm.h +4 -0
@@ -701,6 +701,10 @@ struct drm_gem_open {#define DRM_IOCTL_MODE_PAGE_FLIP DRM_IOWR(0xB0, struct drm_mode_crtc_page_flip)#define DRM_IOCTL_MODE_DIRTYFB DRM_IOWR(0xB1, struct drm_mode_fb_dirty_cmd) +#define DRM_IOCTL_MODE_CREATE_DUMB DRM_IOWR(0xB2, struct drm_mode_create_dumb) +#define DRM_IOCTL_MODE_MAP_DUMB DRM_IOWR(0xB3, struct drm_mode_map_dumb) +#define DRM_IOCTL_MODE_DESTROY_DUMB DRM_IOWR(0xB4, struct drm_mode_destroy_dumb) +/** * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x99.
include/drm/drmP.h +12 -0
@@ -880,6 +880,17 @@ struct drm_driver {/* vga arb irq handler */ void (*vgaarb_irq)(struct drm_device *dev,bool state); +/* dumb alloc support */ +int (*dumb_create)(struct drm_file *file_priv, +struct drm_device *dev, +struct drm_mode_create_dumb *args); +int (*dumb_map_offset)(struct drm_file *file_priv, +struct drm_device *dev,uint32_t handle, +uint64_t *offset); +int (*dumb_destroy)(struct drm_file *file_priv, +struct drm_device *dev, +uint32_t handle); +/* Driver private ops for this object */ struct vm_operations_struct *gem_vm_ops;
@@ -1544,6 +1555,7 @@ drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)int drm_gem_handle_create (struct drm_file *file_priv,struct drm_gem_object *obj,u32 *handlep); +int drm_gem_handle_delete (struct drm_file *filp,u32 handle);static inline void drm_gem_object_handle_reference (struct drm_gem_object *obj)
include/drm/drm_crtc.h +7 -0
@@ -791,4 +791,11 @@ extern int drm_add_modes_noedid(struct drm_connector *connector,extern bool drm_edid_is_valid (struct edid *edid);struct drm_display_mode *drm_mode_find_dmt (struct drm_device *dev,int hsize,int vsize,int fresh); + +extern int drm_mode_create_dumb_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); +extern int drm_mode_mmap_dumb_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv); +extern int drm_mode_destroy_dumb_ioctl (struct drm_device *dev, +void *data,struct drm_file *file_priv);#endif /* __DRM_CRTC_H__ */
include/drm/drm_mode.h +29 -0
@@ -344,4 +344,33 @@ struct drm_mode_crtc_page_flip { __u64 user_data; }; +/* create a dumb scanout buffer */ +struct drm_mode_create_dumb { +uint32_t height; +uint32_t width; +uint32_t bpp; +uint32_t flags; +/* handle, pitch, size will be returned */ +uint32_t handle; +uint32_t pitch; +uint64_t size; +}; + +/* set up for mmap of a dumb scanout buffer */ +struct drm_mode_map_dumb { +/** Handle for the object being mapped. */ +__u32 handle; +__u32 pad; +/** +* Fake offset to use for subsequent mmap call +* +* This is a fixed-size type for 32/64 compatibility. +*/ +__u64 offset; +}; + +struct drm_mode_destroy_dumb { +uint32_t handle; +}; +#endif
Signature · 1 line
1.7.1
Quoted 13 lines · Dave Airlie
From: Dave Airlie <[email protected]>
This is just an idea that might or might not be a good idea, it basically adds two ioctls to create a dumb and map a dumb buffer suitable for scanout. The handle can be passed to the KMS ioctls to create a framebuffer.
It looks to me like it would be useful in the following cases:
a) in development drivers - we can always provide a shadowfb fallback.
b) libkms users - we can clean up libkms a lot and avoid linking to libdrm_*.
c) plymouth via libkms is a lot easier.
Quoted 5 lines
Userspace bits would be just calls + mmaps. We could probably mark these handles somehow as not being suitable for acceleartion so as top stop people who are dumber than dumb.
Signed-off-by Dave Airlie <[email protected]>
Looks pretty reasonable. One thing from the IRC conversation on v2 was about cursors -- were they going to be handled through this patch?
~ C.
Signature · 4 lines
When the facts change, I change my mind. What do you do, sir? ~ Keynes Corbin Simpson <[email protected]>
drivers/gpu/drm/i915/i915_gem.c i915_gem_create_ioctl(struct drm_device *dev, void *data, · line 231
Quoted 7 lines · Dave Airlie
drivers/gpu/drm/i915/i915_gem.c +7
-0+int +i915_gem_dumb_create (struct drm_file *file, +struct drm_device *dev, +struct drm_mode_create_dumb *args) +{ +/* have to work out size/pitch and return them */ + args->pitch =ALIGN (args->width & ((args->bpp +1 ) /8 ),64 );
^ oops
I think you meant args->width * ((args->bpp + 7) /8)
drivers/gpu/drm/i915/i915_gem.c i915_gem_create_ioctl(struct drm_device *dev, void *data, · line 235
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem.c +4
-0+ args->size = args->pitch * args->height; +return i915_gem_create (file, dev, + args->size, &args->handle); +}
The only issue with the dumb libkms fb is the transition to X. Is the nature of the dumb fb such that we would be prohibited from blitting to the X fb, or can we use platform specific knowledge to know how we can abuse it?
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 13 lines · On Fri, 7 Jan 2011 09:16:51 +1000 Dave Airlie <[email protected]> wrote:
From: Dave Airlie <[email protected]>
This is just an idea that might or might not be a good idea, it basically adds two ioctls to create a dumb and map a dumb buffer suitable for scanout. The handle can be passed to the KMS ioctls to create a framebuffer.
It looks to me like it would be useful in the following cases:
a) in development drivers - we can always provide a shadowfb fallback.
b) libkms users - we can clean up libkms a lot and avoid linking to libdrm_*.
c) plymouth via libkms is a lot easier.
Quoted 3 lines
Userspace bits would be just calls + mmaps. We could probably mark these handles somehow as not being suitable for acceleartion so as top stop people who are dumber than dumb.
Would extracting libwfb from the server and providing it as a standalone fb access API from the server also fill these needs? It would be a bigger API, but presumably would allow us to share fbs between early boot and subsequent, accelerated usage. We'd still need to settle on the basic allocation API, but we seem to manage that on the server side...
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center