drm/tinydrm: Use vmalloc BO
Subsystems (3)
cover drm/tinydrm: Use vmalloc BO
This patchset adds a library for vmalloc buffer objects and makes use of it in tinydrm.
The reason I want to move away from the cma helper, is that it restricts which drivers to PRIME import from, since cma requires the buffer to be physically continuous. Initially I looked at udl and decided to use shmem, but have later decided against it since shmem doesn't work with fbdev deferred I/O, they both use page->lru and page->mapping. This meant adding a shadow buffer for fbdev with increased complexity, so I fell back to the KISS principle.
I'm trying to make tinydrm support drivers like simpledrm and udl, so if using vmalloc blocks those use cases, please let me know.
I will do a follow up for the cma library which removes struct drm_fbdev_cma and wrappers.
Noralf.
Noralf Trønnes (8):
drm/fb-helper: Handle function NULL argument
drm: Add drm_device->fbdev pointer
drm/fb-helper: Add simple init/fini functions drm/fb-helper: Add .last_close and .output_poll_changed helpers drm/gem-fb-helper: Add drm_gem_fb_debugfs_show()
drm: Add vmalloc BO helper
drm/tinydrm: Use drm_vmalloc_bo
drm/tinydrm: Relax buffer line prefetch
Documentation/gpu/drm-kms-helpers.rst | 12 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_fb_helper.c | 223 +++++++++++++++++- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 45 ++++ drivers/gpu/drm/drm_vmalloc_bo_helper.c | 305 +++++++++++++++++++++++++ drivers/gpu/drm/tinydrm/Kconfig | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 134 +++-------- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 56 +++-- drivers/gpu/drm/tinydrm/mi0283qt.c | 8 +- drivers/gpu/drm/tinydrm/mipi-dbi.c | 12 +- drivers/gpu/drm/tinydrm/repaper.c | 12 +- drivers/gpu/drm/tinydrm/st7586.c | 14 +- include/drm/drm_device.h | 8 + include/drm/drm_fb_helper.h | 32 +++ include/drm/drm_gem_framebuffer_helper.h | 6 + include/drm/drm_vmalloc_bo_helper.h | 88 +++++++ include/drm/tinydrm/mipi-dbi.h | 2 + include/drm/tinydrm/tinydrm.h | 38 +-- 19 files changed, 811 insertions(+), 194 deletions(-) create mode 100644 drivers/gpu/drm/drm_vmalloc_bo_helper.c create mode 100644 include/drm/drm_vmalloc_bo_helper.h
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/8 drm/fb-helper: Handle function NULL argument
Make functions tolerate that the drm_fb_helper argument is NULL. This is useful for drivers that continue probing when fbdev emulation fails and not having to do this check themselves.
Update docs for functions that already handles this.
--- drivers/gpu/drm/drm_fb_helper.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +17 -11
@@ -150,6 +150,9 @@ int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, {int err; +if (!fb_helper) +return 0 ; +mutex_lock (&fb_helper->lock); err =__drm_fb_helper_add_one_connector (fb_helper, connector);mutex_unlock (&fb_helper->lock);
@@ -161,7 +164,7 @@ EXPORT_SYMBOL(drm_fb_helper_add_one_connector);/** * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev * emulation helper -* @fb_helper: fbdev initialized with drm_fb_helper_init +* @fb_helper: fbdev initialized with drm_fb_helper_init, can be NULL * * This functions adds all the available connectors for use with the given * fb_helper. This is a separate step to allow drivers to freely assign
@@ -179,7 +182,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)struct drm_connector_list_iter conn_iter;int i, ret =0 ; -if (!drm_fbdev_emulation) +if (!drm_fbdev_emulation || !fb_helper)return 0 ;mutex_lock (&fb_helper->lock);
@@ -245,6 +248,9 @@ int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, {int err; +if (!fb_helper) +return 0 ; +mutex_lock (&fb_helper->lock); err =__drm_fb_helper_remove_one_connector (fb_helper, connector);mutex_unlock (&fb_helper->lock);
@@ -484,7 +490,7 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)/** * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration -* @fb_helper: fbcon to restore +* @fb_helper: driver-allocated fbdev helper, can be NULL * * This should be called from driver's drm &drm_driver.lastclose callback * when implementing an fbcon on top of kms using this helper. This ensures that
@@ -498,7 +504,7 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)bool do_delayed;int ret; -if (!drm_fbdev_emulation) +if (!drm_fbdev_emulation || !fb_helper)return -ENODEV ;if (READ_ONCE (fb_helper->deferred_setup))
@@ -883,7 +889,7 @@ EXPORT_SYMBOL(drm_fb_helper_alloc_fbi);/** * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device -* @fb_helper: driver-allocated fbdev helper +* @fb_helper: driver-allocated fbdev helper, can be NULL * * A wrapper around unregister_framebuffer, to release the fb_info * framebuffer device. This must be called before releasing all resources for
@@ -898,7 +904,7 @@ EXPORT_SYMBOL(drm_fb_helper_unregister_fbi);/** * drm_fb_helper_fini - finialize a &struct drm_fb_helper -* @fb_helper: driver-allocated fbdev helper +* @fb_helper: driver-allocated fbdev helper, can be NULL * * This cleans up all remaining resources associated with @fb_helper. Must be * called after drm_fb_helper_unlink_fbi() was called.
@@ -937,7 +943,7 @@ EXPORT_SYMBOL(drm_fb_helper_fini);/** * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer -* @fb_helper: driver-allocated fbdev helper +* @fb_helper: driver-allocated fbdev helper, can be NULL * * A wrapper around unlink_framebuffer implemented by fbdev core */
@@ -1138,7 +1144,7 @@ EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit);/** * drm_fb_helper_set_suspend - wrapper around fb_set_suspend -* @fb_helper: driver-allocated fbdev helper +* @fb_helper: driver-allocated fbdev helper, can be NULL * @suspend: whether to suspend or resume * * A wrapper around fb_set_suspend implemented by fbdev core.
@@ -1155,7 +1161,7 @@ EXPORT_SYMBOL(drm_fb_helper_set_suspend);/** * drm_fb_helper_set_suspend_unlocked - wrapper around fb_set_suspend that also * takes the console lock -* @fb_helper: driver-allocated fbdev helper +* @fb_helper: driver-allocated fbdev helper, can be NULL * @suspend: whether to suspend or resume * * A wrapper around fb_set_suspend() that takes the console lock. If the lock
@@ -2568,7 +2574,7 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);/** * drm_fb_helper_hotplug_event - respond to a hotplug notification by * probing all the outputs attached to the fb -* @fb_helper: the drm_fb_helper +* @fb_helper: driver-allocated fbdev helper, can be NULL * * Scan the connectors attached to the fb_helper and try to put together a * setup after notification of a change in output configuration.
@@ -2590,7 +2596,7 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) {int err =0 ; -if (!drm_fbdev_emulation) +if (!drm_fbdev_emulation || !fb_helper)return 0 ;mutex_lock (&fb_helper->lock);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/8 drm: Add drm_device->fbdev pointer
In reply to Noralf Trønnesdrm_fb_helper is *the* way of doing fbdev emulation so add a pointer to struct drm_device. This makes it possible to add callback helpers for .last_close and .output_poll_changed further reducing fbdev emulation footprint in drivers.
--- include/drm/drm_device.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/drm/drm_device.h +8 -0
@@ -17,6 +17,7 @@ struct drm_vblank_crtc;struct drm_sg_mem ;struct drm_local_map ;struct drm_vma_offset_manager ; +struct drm_fb_helper ;struct inode ;
@@ -185,6 +186,13 @@ struct drm_device {struct drm_vma_offset_manager *vma_offset_manager;/*@} */ int switch_power_state; + +/** +* @fbdev: +* +* Optional pointer to the fbdev emulation structure. +*/ + struct drm_fb_helper *fbdev; };#endif
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/8 drm/fb-helper: Add simple init/fini functions
In reply to Noralf TrønnesThis adds some simple init/fini helpers for drivers that don't need anything special in their fbdev emulation setup.
--- drivers/gpu/drm/drm_fb_helper.c | 163 ++++++++++++++++++++++++++++++++++++++++ include/drm/drm_fb_helper.h | 22 ++++++ 2 files changed, 185 insertions(+)
drivers/gpu/drm/drm_fb_helper.c +163 -0
@@ -105,6 +105,127 @@ static DEFINE_MUTEX(kernel_fb_helper_lock);* mmap page writes. */ +/** +* drm_fb_helper_simple_init - Simple fbdev emulation setup +* @dev: DRM device +* @funcs: Pointer to structure of functions associated with this helper +* @bpp: Bits per pixel value to use for the framebuffer configuration. +* @dev->mode_config.preferred_depth is used if this is zero. +* @max_conn: Max connector count. @dev->mode_config.num_connector is used if +* this is zero. +* +* Simple fbdev emulation initialization. This function allocates a +* &drm_fb_helper structure attaches it to &drm_device->fbdev and calls: +* drm_fb_helper_prepare(), drm_fb_helper_init(), +* drm_fb_helper_single_add_all_connectors() and +* drm_fb_helper_initial_config(). +* +* If fbdev emulation is disabled, this function does nothing. In that case +* &drm_device->fbdev will be NULL. All drm_fb_helper entry function can handle +* a NULL argument. +* +* fbdev deferred I/O users should use the drm_fb_helper_defio_init() function +* in their &drm_fb_helper_funcs.fb_probe callback. +* +* Returns: +* Zero on success or if fbdev emulation is disabled, negative error code on +* failure. +*/ +int drm_fb_helper_simple_init (struct drm_device *dev, +const struct drm_fb_helper_funcs *funcs, +unsigned int bpp,int max_conn) +{ +struct drm_fb_helper *fb_helper; +int ret; + +if (!drm_fbdev_emulation) +return 0 ; + +if (!bpp) + bpp = dev->mode_config.preferred_depth; + +if (!max_conn) + max_conn = dev->mode_config.num_connector; + + fb_helper =kzalloc (sizeof (*fb_helper),GFP_KERNEL ); +if (!fb_helper) +return -ENOMEM ; + +drm_fb_helper_prepare (dev, fb_helper, funcs); + + ret =drm_fb_helper_init (dev, fb_helper, max_conn); +if (ret <0 ) { +DRM_DEV_ERROR (dev->dev,"Failed to initialize fb helper.\n" ); + goto err_drm_fb_helper_free; + } + + ret =drm_fb_helper_single_add_all_connectors (fb_helper); +if (ret <0 ) { +DRM_DEV_ERROR (dev->dev,"Failed to add connectors.\n" ); + goto err_drm_fb_helper_fini; + } + + ret =drm_fb_helper_initial_config (fb_helper, bpp); +if (ret <0 ) { +DRM_DEV_ERROR (dev->dev,"Failed to set initial hw config.\n" ); + goto err_drm_fb_helper_fini; + } + + dev->fbdev = fb_helper; + +return 0 ; + +err_drm_fb_helper_fini: +drm_fb_helper_fini (fb_helper); +err_drm_fb_helper_free: +kfree (fb_helper); + +return ret; +} +EXPORT_SYMBOL_GPL (drm_fb_helper_simple_init); + +/** +* drm_fb_helper_simple_fini - Simple fbdev cleanup +* @dev: DRM device +* +* Simple fbdev emulation cleanup. This function unregisters fbdev if it is not +* done, cleans up deferred IO if necessary, removes framebuffer, finalizes +* @fb_helper and frees the structure. +*/ +void drm_fb_helper_simple_fini (struct drm_device *dev) +{ +struct drm_fb_helper *fb_helper = dev->fbdev; +struct fb_info *info; +struct fb_ops *fbops; + +if (!fb_helper) +return ; + + dev->fbdev =NULL ; + info = fb_helper->fbdev; + +/* Make sure it hasn't been unregistered already */ +if (info && info->dev) +drm_fb_helper_unregister_fbi (fb_helper); + +if (info && info->fbdefio) { +fb_deferred_io_cleanup (info); +kfree (info->fbdefio); + fbops = info->fbops; + } + +drm_fb_helper_fini (fb_helper); + +if (info && info->fbdefio) +kfree (fbops); + +if (fb_helper->fb) +drm_framebuffer_remove (fb_helper->fb); + +kfree (fb_helper); +} +EXPORT_SYMBOL_GPL (drm_fb_helper_simple_fini); +#define drm_fb_helper_for_each_connector (fbh, i__) \ for (({ lockdep_assert_held(&(fbh)->lock); }), \ i__ = 0; i__ < (fbh)->connector_count; i__++)
@@ -954,6 +1075,48 @@ void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) }EXPORT_SYMBOL (drm_fb_helper_unlink_fbi); +/** +* drm_fb_helper_defio_init - fbdev deferred I/O initialization +* @fb_helper: driver-allocated fbdev helper +* +* This function allocates &fb_deferred_io, sets callback to +* drm_fb_helper_deferred_io(), delay to 50ms and calls fb_deferred_io_init(). +* +* NOTE: A copy of &fb_ops is made and assigned to &info->fbops. This is done +* because fb_deferred_io_cleanup() clears &fbops->fb_mmap and would thereby +* affect other instances of that &fb_ops. This copy is freed in +* drm_fb_helper_simple_fini(). +* +* Returns: +* 0 on success or a negative error code on failure. +*/ +int drm_fb_helper_defio_init (struct drm_fb_helper *fb_helper) +{ +struct fb_info *info = fb_helper->fbdev; +struct fb_deferred_io *fbdefio; +struct fb_ops *fbops; + + fbdefio =kzalloc (sizeof (*fbdefio),GFP_KERNEL ); + fbops =kzalloc (sizeof (*fbops),GFP_KERNEL ); +if (!fbdefio || !fbops) { +kfree (fbdefio); +kfree (fbops); +return -ENOMEM ; + } + + info->fbdefio = fbdefio; + fbdefio->delay =msecs_to_jiffies (50 ); + fbdefio->deferred_io = drm_fb_helper_deferred_io; + + *fbops = *info->fbops; + info->fbops = fbops; + +fb_deferred_io_init (info); + +return 0 ; +} +EXPORT_SYMBOL (drm_fb_helper_defio_init); +static void drm_fb_helper_dirty (struct fb_info *info,u32 x,u32 y,u32 width,u32 height) {
include/drm/drm_fb_helper.h +22 -0
@@ -242,6 +242,10 @@ struct drm_fb_helper { .fb_ioctl = drm_fb_helper_ioctl#ifdef CONFIG_DRM_FBDEV_EMULATION +int drm_fb_helper_simple_init (struct drm_device *dev, +const struct drm_fb_helper_funcs *funcs, +unsigned int bpp,int max_conn); +void drm_fb_helper_simple_fini (struct drm_device *dev);void drm_fb_helper_prepare (struct drm_device *dev,struct drm_fb_helper *helper,const struct drm_fb_helper_funcs *funcs); int drm_fb_helper_init(struct drm_device *dev,
@@ -265,6 +269,7 @@ void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,void drm_fb_helper_unlink_fbi (struct drm_fb_helper *fb_helper); +int drm_fb_helper_defio_init (struct drm_fb_helper *fb_helper);void drm_fb_helper_deferred_io (struct fb_info *info,struct list_head *pagelist);
@@ -311,6 +316,18 @@ int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_int drm_fb_helper_remove_one_connector (struct drm_fb_helper *fb_helper,struct drm_connector *connector);#else +static inline int +drm_fb_helper_simple_init (struct drm_device *dev, +const struct drm_fb_helper_funcs *funcs, +unsigned int bpp,int max_conn) +{ +return 0 ; +} + +static inline void drm_fb_helper_simple_fini (struct drm_device *dev) +{ +} +static inline void drm_fb_helper_prepare (struct drm_device *dev,struct drm_fb_helper *helper,const struct drm_fb_helper_funcs *funcs)
@@ -393,6 +410,11 @@ static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) { } +static inline int drm_fb_helper_defio_init (struct drm_fb_helper *fb_helper) +{ +return -ENODEV ; +} +static inline void drm_fb_helper_deferred_io (struct fb_info *info,struct list_head *pagelist) {
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/8 drm/fb-helper: Add .last_close and .output_poll_changed helpers
In reply to Noralf TrønnesThis adds helpers for the drm_driver->last_close and the drm_mode_config_funcs->output_poll_changed callbacks.
--- drivers/gpu/drm/drm_fb_helper.c | 32 ++++++++++++++++++++++++++++++++ include/drm/drm_fb_helper.h | 10 ++++++++++ 2 files changed, 42 insertions(+)
drivers/gpu/drm/drm_fb_helper.c +32 -0
@@ -226,6 +226,38 @@ void drm_fb_helper_simple_fini(struct drm_device *dev) }EXPORT_SYMBOL_GPL (drm_fb_helper_simple_fini); +/** +* drm_fb_helper_lastclose - DRM driver lastclose helper for fbdev emulation +* @dev: DRM device +* +* This function can be used as the &drm_driver->lastclose callback for drivers +* that only need to call drm_fb_helper_restore_fbdev_mode_unlocked(). +* +* Note: &drm_device->fbdev needs to be set. +*/ +void drm_fb_helper_lastclose (struct drm_device *dev) +{ +drm_fb_helper_restore_fbdev_mode_unlocked (dev->fbdev); +} +EXPORT_SYMBOL (drm_fb_helper_lastclose); + +/** +* drm_fb_helper_output_poll_changed - DRM mode config \.output_poll_changed +* helper for fbdev emulation +* @dev: DRM device +* +* This function can be used as the +* &drm_mode_config_funcs.output_poll_changed callback for drivers that only +* need to call drm_fb_helper_hotplug_event(). +* +* Note: &drm_device->fbdev needs to be set. +*/ +void drm_fb_helper_output_poll_changed (struct drm_device *dev) +{ +drm_fb_helper_hotplug_event (dev->fbdev); +} +EXPORT_SYMBOL (drm_fb_helper_output_poll_changed); +#define drm_fb_helper_for_each_connector (fbh, i__) \ for (({ lockdep_assert_held(&(fbh)->lock); }), \ i__ = 0; i__ < (fbh)->connector_count; i__++)
include/drm/drm_fb_helper.h +10 -0
@@ -246,6 +246,8 @@ int drm_fb_helper_simple_init(struct drm_device *dev,const struct drm_fb_helper_funcs *funcs, unsigned int bpp, int max_conn);void drm_fb_helper_simple_fini (struct drm_device *dev); +void drm_fb_helper_lastclose (struct drm_device *dev); +void drm_fb_helper_output_poll_changed (struct drm_device *dev);void drm_fb_helper_prepare (struct drm_device *dev,struct drm_fb_helper *helper,const struct drm_fb_helper_funcs *funcs); int drm_fb_helper_init(struct drm_device *dev,
@@ -328,6 +330,14 @@ static inline void drm_fb_helper_simple_fini(struct drm_device *dev) { } +static inline void drm_fb_helper_lastclose (struct drm_device *dev) +{ +} + +static inline void drm_fb_helper_output_poll_changed (struct drm_device *dev) +{ +} +static inline void drm_fb_helper_prepare (struct drm_device *dev,struct drm_fb_helper *helper,const struct drm_fb_helper_funcs *funcs)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/8 drm/gem-fb-helper: Add drm_gem_fb_debugfs_show()
In reply to Noralf TrønnesAdd drm_gem_fb_debugfs_show() function to provide a debugfs representation of the framebuffer and GEM object(s).
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 45 ++++++++++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 6 ++++ 2 files changed, 51 insertions(+)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +45 -0
@@ -245,6 +245,51 @@ int drm_gem_fb_prepare_fb(struct drm_plane *plane, }EXPORT_SYMBOL_GPL (drm_gem_fb_prepare_fb); +#ifdef CONFIG_DEBUG_FS +static void drm_gem_fb_describe (struct drm_framebuffer *fb,struct seq_file *m) +{ +struct drm_gem_object *obj; +unsigned int i; + +seq_printf (m,"[FB:%d] %dx%d@%4.4s\n" , fb->base.id, fb->width, + fb->height, (char *)&fb->format->format); + +for (i =0 ; i < fb->format->num_planes; i++) { + obj = fb->obj[i]; +seq_printf (m,"\t%u: offset=%d pitch=%d, GEM: name=%d" , + i, fb->offsets[i], fb->pitches[i], obj->name); +seq_printf (m," refcount=%d start=%08lx size=%zu%s\n" , +kref_read (&obj->refcount), +drm_vma_node_start (&obj->vma_node), obj->size, + obj->import_attach ?" (imported)" :"" ); + } +} + +/** +* drm_gem_fb_debugfs_show() - Helper to list GEM backed framebuffer objects +* in debugfs. +* @m: Output file +* @arg: Private data for the callback +* +* This function gives a debugfs representation of the framebuffers with their +* backing GEM objects. See drm_debugfs_create_files() for more info. +*/ +int drm_gem_fb_debugfs_show (struct seq_file *m,void *arg) +{ +struct drm_info_node *node = m->private; +struct drm_device *dev = node->minor->dev; +struct drm_framebuffer *fb; + +mutex_lock (&dev->mode_config.fb_lock); +drm_for_each_fb (fb, dev) +drm_gem_fb_describe (fb, m); +mutex_unlock (&dev->mode_config.fb_lock); + +return 0 ; +} +EXPORT_SYMBOL_GPL (drm_gem_fb_debugfs_show); +#endif +/** * drm_gem_fbdev_fb_create - Create a drm_framebuffer for fbdev emulation * @dev: DRM device
include/drm/drm_gem_framebuffer_helper.h +6 -0
@@ -28,6 +28,12 @@ drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,int drm_gem_fb_prepare_fb (struct drm_plane *plane,struct drm_plane_state *state); +#ifdef CONFIG_DEBUG_FS +struct seq_file ; + +int drm_gem_fb_debugfs_show (struct seq_file *m,void *arg); +#endif +struct drm_framebuffer * drm_gem_fbdev_fb_create(struct drm_device *dev, struct drm_fb_helper_surface_size *sizes,
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/8 drm: Add vmalloc BO helper
In reply to Noralf TrønnesAdd vmalloc buffer object helper that can be useful for modesetting drivers, particularly the framebuffer flushing kind.
--- Documentation/gpu/drm-kms-helpers.rst | 12 ++ drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_vmalloc_bo_helper.c | 305 ++++++++++++++++++++++++++++++++ include/drm/drm_vmalloc_bo_helper.h | 88 +++++++++ 5 files changed, 413 insertions(+) create mode 100644 drivers/gpu/drm/drm_vmalloc_bo_helper.c create mode 100644 include/drm/drm_vmalloc_bo_helper.h
Documentation/gpu/drm-kms-helpers.rst +12 -0
@@ -305,3 +305,15 @@ Framebuffer GEM Helper Reference .. kernel-doc:: drivers/gpu/drm/drm_gem_framebuffer_helper.c :export: + +vmalloc buffer object helper +============================ + +.. kernel-doc:: drivers/gpu/drm/drm_vmalloc_bo_helper.c + :doc: overview + +.. kernel-doc:: include/drm/drm_vmalloc_bo_helper.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_vmalloc_bo_helper.c + :export:
drivers/gpu/drm/Kconfig +7 -0
@@ -145,6 +145,13 @@ config DRM_KMS_CMA_HELPER help Choose this if you need the KMS CMA helper functions +config DRM_VMALLOC_BO_HELPER + bool + depends on DRM + select DRM_KMS_HELPER + help + Choose this if you need the vmalloc buffer object helper functions + config DRM_VM bool depends on DRM && MMU
drivers/gpu/drm/Makefile +1 -0
@@ -39,6 +39,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \ drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o +drm_kms_helper-$(CONFIG_DRM_VMALLOC_BO_HELPER) += drm_vmalloc_bo_helper.o drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
drivers/gpu/drm/drm_vmalloc_bo_helper.c new file +305 -0
305 lines not on this page · raw message
include/drm/drm_vmalloc_bo_helper.h new file +88 -0
88 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/8 drm/tinydrm: Use drm_vmalloc_bo
In reply to Noralf TrønnesUse the vmalloc BO helper instead of the cma helper to be able to PRIME import from more drivers. The cma helper can only import physically continuous buffers, but tinydrm only requires the buffer to be virtually continuous.
This switch also makes it possible to use the drm_fb_helper_lastclose() helper.
Some extra includes were necessary in tinydrm-helpers.c, because it relied on includes in tinydrm.h that are now gone.
--- drivers/gpu/drm/tinydrm/Kconfig | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 134 +++++-------------------- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 2 + drivers/gpu/drm/tinydrm/mi0283qt.c | 8 +- drivers/gpu/drm/tinydrm/mipi-dbi.c | 12 +-- drivers/gpu/drm/tinydrm/repaper.c | 12 ++- drivers/gpu/drm/tinydrm/st7586.c | 14 +-- include/drm/tinydrm/mipi-dbi.h | 2 + include/drm/tinydrm/tinydrm.h | 38 ++----- 9 files changed, 65 insertions(+), 159 deletions(-)
drivers/gpu/drm/tinydrm/Kconfig +1 -1
@@ -2,7 +2,7 @@ menuconfig DRM_TINYDRM tristate "Support for simple displays" depends on DRM select DRM_KMS_HELPER - select DRM_KMS_CMA_HELPER + select DRM_VMALLOC_BO_HELPER select BACKLIGHT_LCD_SUPPORT select BACKLIGHT_CLASS_DEVICE help
drivers/gpu/drm/tinydrm/core/tinydrm-core.c +26 -108
191 lines not on this page · raw message
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +2 -0
@@ -9,10 +9,12 @@#include <linux/backlight.h> #include <linux/dma-buf.h> +#include <linux/moduleparam.h> #include <linux/pm.h> #include <linux/spi/spi.h> #include <linux/swab.h> +#include <drm/drmP.h> #include <drm/tinydrm/tinydrm.h> #include <drm/tinydrm/tinydrm-helpers.h>
drivers/gpu/drm/tinydrm/mi0283qt.c +5 -3
@@ -9,6 +9,8 @@* (at your option) any later version. */ +#include <drm/drm_fb_helper.h> +#include <drm/drm_vmalloc_bo_helper.h> #include <drm/tinydrm/ili9341.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -132,14 +134,14 @@ static const struct drm_display_mode mi0283qt_mode = {TINYDRM_MODE (320 ,240 ,58 ,43 ), }; -DEFINE_DRM_GEM_CMA_FOPS (mi0283qt_fops); +DEFINE_DRM_VMALLOC_BO_FOPS (mi0283qt_fops);static struct drm_driver mi0283qt_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &mi0283qt_fops, -TINYDRM_GEM_DRIVER_OPS , - .lastclose = tinydrm_lastclose, +DRM_VMALLOC_BO_DRIVER_OPS , + .lastclose = drm_fb_helper_lastclose, .debugfs_init = mipi_dbi_debugfs_init, .name ="mi0283qt" , .desc = "Multi-Inno MI0283QT",
drivers/gpu/drm/tinydrm/mipi-dbi.c +6 -6
@@ -10,6 +10,7 @@*/ #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_vmalloc_bo_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h> #include <linux/debugfs.h>
@@ -157,10 +158,10 @@ EXPORT_SYMBOL(mipi_dbi_command_buf);static int mipi_dbi_buf_copy (void *dst,struct drm_framebuffer *fb,struct drm_clip_rect *clip,bool swap) { -struct drm_gem_cma_object *cma_obj =drm_fb_cma_get_gem_obj (fb,0 ); -struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; +struct drm_gem_object *obj =drm_gem_fb_get_obj (fb,0 ); +struct dma_buf_attachment *import_attach = obj->import_attach; +void *src =drm_vmalloc_bo_fb_vaddr (fb);struct drm_format_name_buf format_name; -void *src = cma_obj->vaddr;int ret =0 ;if (import_attach) {
@@ -199,7 +200,6 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); struct tinydrm_device *tdev = fb->dev->dev_private;struct mipi_dbi *mipi =mipi_dbi_from_tinydrm (tdev);bool swap = mipi->swap_bytes;
@@ -230,7 +230,7 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,if (ret) goto out_unlock; }else { - tr = cma_obj->vaddr; + tr =drm_vmalloc_bo_fb_vaddr (fb); } mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS,
@@ -962,7 +962,7 @@ static const struct file_operations mipi_dbi_debugfs_command_fops = { };static const struct drm_info_list mipi_dbi_debugfs_list[] = { - {"fb" , drm_fb_cma_debugfs_show,0 }, + {"fb" , drm_gem_fb_debugfs_show,0 }, };/**
drivers/gpu/drm/tinydrm/repaper.c +7 -5
@@ -26,6 +26,7 @@#include <linux/spi/spi.h> #include <linux/thermal.h> +#include <drm/drm_vmalloc_bo_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/tinydrm/tinydrm.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -527,10 +528,11 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); -struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; + struct drm_gem_object *obj = drm_gem_fb_get_obj(fb, 0); +struct dma_buf_attachment *import_attach = obj->import_attach;struct tinydrm_device *tdev = fb->dev->dev_private;struct repaper_epd *epd =epd_from_tinydrm (tdev); +void *src =drm_vmalloc_bo_fb_vaddr (fb);struct drm_clip_rect clip;u8 *buf =NULL ;int ret =0 ;
@@ -568,7 +570,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, goto out_unlock; } -tinydrm_xrgb8888_to_gray8 (buf, cma_obj->vaddr, fb, &clip); +tinydrm_xrgb8888_to_gray8 (buf, src, fb, &clip);if (import_attach) { ret = dma_buf_end_cpu_access(import_attach->dmabuf,
@@ -888,13 +890,13 @@ static const struct drm_display_mode repaper_e2271cs021_mode = {static const u8 repaper_e2271cs021_cs[] = {0x00 ,0x00 ,0x00 ,0x7f ,0xff ,0xfe ,0x00 ,0x00 }; -DEFINE_DRM_GEM_CMA_FOPS (repaper_fops); +DEFINE_DRM_VMALLOC_BO_FOPS (repaper_fops);static struct drm_driver repaper_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &repaper_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_VMALLOC_BO_DRIVER_OPS , .name ="repaper" , .desc ="Pervasive Displays RePaper e-ink panels" , .date ="20170405" ,
drivers/gpu/drm/tinydrm/st7586.c +8 -6
@@ -17,7 +17,9 @@#include <linux/spi/spi.h> #include <video/mipi_display.h> +#include <drm/drm_fb_helper.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_vmalloc_bo_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -87,9 +89,9 @@ static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr,static int st7586_buf_copy (void *dst,struct drm_framebuffer *fb,struct drm_clip_rect *clip) { -struct drm_gem_cma_object *cma_obj =drm_fb_cma_get_gem_obj (fb,0 ); -struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; -void *src = cma_obj->vaddr; +struct drm_gem_object *obj =drm_gem_fb_get_obj (fb,0 ); +struct dma_buf_attachment *import_attach = obj->import_attach; +void *src =drm_vmalloc_bo_fb_vaddr (fb);int ret =0 ;if (import_attach) {
@@ -313,14 +315,14 @@ static const struct drm_display_mode st7586_mode = {TINYDRM_MODE (178 ,128 ,37 ,27 ), }; -DEFINE_DRM_GEM_CMA_FOPS (st7586_fops); +DEFINE_DRM_VMALLOC_BO_FOPS (st7586_fops);static struct drm_driver st7586_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &st7586_fops, -TINYDRM_GEM_DRIVER_OPS , - .lastclose = tinydrm_lastclose, +DRM_VMALLOC_BO_DRIVER_OPS , + .lastclose = drm_fb_helper_lastclose, .debugfs_init = mipi_dbi_debugfs_init, .name ="st7586" , .desc = "Sitronix ST7586",
include/drm/tinydrm/mipi-dbi.h +2 -0
@@ -95,6 +95,8 @@ int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len); })#ifdef CONFIG_DEBUG_FS +struct drm_minor ; +int mipi_dbi_debugfs_init (struct drm_minor *minor);#else #define mipi_dbi_debugfs_init NULL
include/drm/tinydrm/tinydrm.h +8 -30
@@ -10,16 +10,21 @@#ifndef __LINUX_TINYDRM_H#define __LINUX_TINYDRM_H -#include <drm/drm_gem_cma_helper.h> -#include <drm/drm_fb_cma_helper.h> +#include <linux/mutex.h> #include <drm/drm_simple_kms_helper.h> +struct device ; +struct drm_atomic_state ; +struct drm_device ; +struct drm_driver ; +struct drm_framebuffer_funcs ; +struct drm_plane_state ; +/** * struct tinydrm_device - tinydrm device * @drm: DRM device * @pipe: Display pipe structure * @dirty_lock: Serializes framebuffer flushing -* @fbdev_cma: CMA fbdev structure * @suspend_state: Atomic state when suspended * @fb_funcs: Framebuffer functions used when creating framebuffers */
@@ -27,7 +32,6 @@ struct tinydrm_device {struct drm_device *drm;struct drm_simple_display_pipe pipe;struct mutex dirty_lock; -struct drm_fbdev_cma *fbdev_cma;struct drm_atomic_state *suspend_state;const struct drm_framebuffer_funcs *fb_funcs; };
@@ -39,26 +43,6 @@ pipe_to_tinydrm(struct drm_simple_display_pipe *pipe) }/** -* TINYDRM_GEM_DRIVER_OPS - default tinydrm gem operations -* -* This macro provides a shortcut for setting the tinydrm GEM operations in -* the &drm_driver structure. -*/ -#define TINYDRM_GEM_DRIVER_OPS \ - .gem_free_object = tinydrm_gem_cma_free_object, \ - .gem_vm_ops = &drm_gem_cma_vm_ops, \ - .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \ - .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \ - .gem_prime_import = drm_gem_prime_import, \ - .gem_prime_export = drm_gem_prime_export, \ - .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, \ - .gem_prime_import_sg_table = tinydrm_gem_cma_prime_import_sg_table, \ - .gem_prime_vmap = drm_gem_cma_prime_vmap, \ - .gem_prime_vunmap = drm_gem_cma_prime_vunmap, \ - .gem_prime_mmap = drm_gem_cma_prime_mmap, \ - .dumb_create = drm_gem_cma_dumb_create - -/** * TINYDRM_MODE - tinydrm display mode * @hd: Horizontal resolution, width * @vd: Vertical resolution, height
@@ -81,12 +65,6 @@ pipe_to_tinydrm(struct drm_simple_display_pipe *pipe) .type = DRM_MODE_TYPE_DRIVER, \ .clock = 1 /* pass validation */ -void tinydrm_lastclose (struct drm_device *drm); -void tinydrm_gem_cma_free_object (struct drm_gem_object *gem_obj); -struct drm_gem_object * -tinydrm_gem_cma_prime_import_sg_table (struct drm_device *drm, -struct dma_buf_attachment *attach, -struct sg_table *sgt);int devm_tinydrm_init (struct device *parent,struct tinydrm_device *tdev,const struct drm_framebuffer_funcs *fb_funcs,struct drm_driver *driver);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/8 drm/tinydrm: Relax buffer line prefetch
In reply to Noralf Trønnesvmalloc BO's gives us cached reads, so no need to prefetch in that case. Prefetching gives a ~20% speedup on a cma buffer using the mi0283qt driver on a Raspberry Pi 1.
--- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 54 ++++++++++++++------------ 1 file changed, 30 insertions(+), 24 deletions(-)
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +30 -24
@@ -15,6 +15,8 @@#include <linux/swab.h> #include <drm/drmP.h> +#include <drm/drm_gem.h> +#include <drm/drm_gem_framebuffer_helper.h> #include <drm/tinydrm/tinydrm.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -115,22 +117,25 @@ void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb, struct drm_clip_rect *clip) {size_t len = (clip->x2 - clip->x1) *sizeof (u16); +u16 *src, *buf =NULL ;unsigned int x, y; -u16 *src, *buf;/* -* The cma memory is write-combined so reads are uncached. -* Speed up by fetching one line at a time. +* Imported buffers are likely to be write-combined with uncached +* reads. Speed up by fetching one line at a time. +* prefetch_range() was tried, but didn't give any noticeable speedup +* on the Raspberry Pi 1. */ - buf =kmalloc (len,GFP_KERNEL ); -if (!buf) -return ; +if (drm_gem_fb_get_obj (fb,0 )->import_attach) + buf =kmalloc (len,GFP_KERNEL );for (y = clip->y1; y < clip->y2; y++) { src = vaddr + (y * fb->pitches[0 ]); src += clip->x1; -memcpy (buf, src, len); - src = buf; +if (buf) { +memcpy (buf, src, len); + src = buf; + }for (x = clip->x1; x < clip->x2; x++) *dst++ =swab16 (*src++); }
@@ -155,19 +160,21 @@ void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr, struct drm_clip_rect *clip, bool swap) { size_t len = (clip->x2 - clip->x1) * sizeof(u32); +u32 *src, *buf =NULL ;unsigned int x, y; -u32 *src, *buf;u16 val16; - buf =kmalloc (len,GFP_KERNEL ); -if (!buf) -return ; +/* See tinydrm_swab16() for an explanation */ +if (drm_gem_fb_get_obj (fb,0 )->import_attach) + buf =kmalloc (len,GFP_KERNEL );for (y = clip->y1; y < clip->y2; y++) { src = vaddr + (y * fb->pitches[0 ]); src += clip->x1; -memcpy (buf, src, len); - src = buf; +if (buf) { +memcpy (buf, src, len); + src = buf; + }for (x = clip->x1; x < clip->x2; x++) { val16 = ((*src &0x00F80000 ) >>8 ) | ((*src & 0x0000FC00) >> 5) |
@@ -205,24 +212,23 @@ void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, {unsigned int len = (clip->x2 - clip->x1) *sizeof (u32);unsigned int x, y; -void *buf; +void *buf =NULL ;u32 *src;if (WARN_ON (fb->format->format !=DRM_FORMAT_XRGB8888 ))return ; -/* -* The cma memory is write-combined so reads are uncached. -* Speed up by fetching one line at a time. -*/ - buf =kmalloc (len,GFP_KERNEL ); -if (!buf) -return ; + +/* See tinydrm_swab16() for an explanation */ +if (drm_gem_fb_get_obj (fb,0 )->import_attach) + buf =kmalloc (len,GFP_KERNEL );for (y = clip->y1; y < clip->y2; y++) { src = vaddr + (y * fb->pitches[0 ]); src += clip->x1; -memcpy (buf, src, len); - src = buf; +if (buf) { +memcpy (buf, src, len); + src = buf; + }for (x = clip->x1; x < clip->x2; x++) {u8 r = (*src &0x00ff0000 ) >>16 ;u8 g = (*src &0x0000ff00 ) >>8 ;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel