drm: Add support for tiny LCD displays
Subsystems (2)
v2 cover drm: Add support for tiny LCD displays
This is an attempt at providing a DRM version of drivers/staging/fbtft.
I'm sending this early before cleaning up the code hoping to get some feedback in case there are better ways to structure this.
The tinydrm module provides a very simplified view of DRM for displays that has onboard video memory and is connected through a slow bus like SPI/I2C. A driver using tinydrm has to provide a function that will be called from the dirtyfb ioctl (or fbdev deferred io) and optional drm_panel functions which can be used to set up the display controller and control backlight.
Display controllers that have a similar register interface as the MIPI DBI/DCS controllers can use the lcdreg module for register access.
Changes since RFC v1:
- Add fb_deferred_io support to drm_fb_helper and drm_fb_cma_helper, and use drm_fb_cma_helper instead.
- Move display pipeline code to drm_simple_kms_helper.
- Don't use (struct drm_driver *)->load().
- Make tinydrm more like a library, exporting the internals.
- Move the struct drm_driver definition from the tinydrm module to the driver using a helper macro: TINYDRM_DRM_DRIVER.
- Remove dirtyfb() async code.
- Added support for partial display updates.
Noralf Trønnes (8):
drm/fb-helper: Add fb_deferred_io support drm/fb-cma-helper: Add fb_deferred_io support
drm: Add helper for simple kms drivers
drm: Add DRM support for tiny LCD displays drm/tinydrm: Add lcd register abstraction drm/tinydrm/lcdreg: Add SPI support
drm/tinydrm: Add mipi-dbi support
drm/tinydrm: Add support for several Adafruit TFT displays
drivers/gpu/drm/Kconfig | 9 + drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_fb_cma_helper.c | 149 ++++- drivers/gpu/drm/drm_fb_helper.c | 189 +++++- drivers/gpu/drm/drm_simple_kms_helper.c | 262 ++++++++ drivers/gpu/drm/tinydrm/Kconfig | 25 + drivers/gpu/drm/tinydrm/Makefile | 8 + drivers/gpu/drm/tinydrm/adafruit-tft.c | 257 ++++++++ drivers/gpu/drm/tinydrm/core/Makefile | 6 + drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 155 +++++ .../gpu/drm/tinydrm/core/tinydrm-display-pipe.c | 82 +++ drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c | 94 +++ drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c | 99 +++ drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 95 +++ drivers/gpu/drm/tinydrm/lcdreg/Kconfig | 8 + drivers/gpu/drm/tinydrm/lcdreg/Makefile | 5 + drivers/gpu/drm/tinydrm/lcdreg/internal.h | 8 + drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c | 190 ++++++ drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c | 281 ++++++++ drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c | 720 +++++++++++++++++++++ drivers/gpu/drm/tinydrm/mipi-dbi.c | 253 ++++++++ include/drm/drm_fb_cma_helper.h | 14 + include/drm/drm_fb_helper.h | 15 + include/drm/drm_simple_kms_helper.h | 44 ++ include/drm/tinydrm/ili9340.h | 47 ++ include/drm/tinydrm/lcdreg-spi.h | 63 ++ include/drm/tinydrm/lcdreg.h | 126 ++++ include/drm/tinydrm/mipi-dbi.h | 24 + include/drm/tinydrm/tinydrm.h | 143 ++++ 29 files changed, 3360 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/drm/drm_simple_kms_helper.c create mode 100644 drivers/gpu/drm/tinydrm/Kconfig create mode 100644 drivers/gpu/drm/tinydrm/Makefile create mode 100644 drivers/gpu/drm/tinydrm/adafruit-tft.c create mode 100644 drivers/gpu/drm/tinydrm/core/Makefile create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-core.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-display-pipe.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/Kconfig create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/Makefile create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/internal.h create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c create mode 100644 drivers/gpu/drm/tinydrm/mipi-dbi.c create mode 100644 include/drm/drm_simple_kms_helper.h create mode 100644 include/drm/tinydrm/ili9340.h create mode 100644 include/drm/tinydrm/lcdreg-spi.h create mode 100644 include/drm/tinydrm/lcdreg.h create mode 100644 include/drm/tinydrm/mipi-dbi.h create mode 100644 include/drm/tinydrm/tinydrm.h
--
2.2.2
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 1/8 drm/fb-helper: Add fb_deferred_io support
This adds deferred io support if CONFIG_FB_DEFERRED_IO is enabled. Accumulated fbdev framebuffer changes are signaled using the callback (struct drm_framebuffer_funcs *)->dirty()
The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a drm_clip_rect and passed to the framebuffer dirty() function.
The driver is responsible for setting up the fb_info.fbdefio structure and calling fb_deferred_io_init() using the provided callback:
(struct fb_info *)->fbdefio->deferred_io = drm_fb_helper_deferred_io;
--- drivers/gpu/drm/drm_fb_helper.c | 189 +++++++++++++++++++++++++++++++++++++++- include/drm/drm_fb_helper.h | 15 ++++ 2 files changed, 203 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +188 -1
@@ -48,6 +48,100 @@ MODULE_PARM_DESC(fbdev_emulation,static LIST_HEAD (kernel_fb_helper_list); +/* +* Where should I put these drm_clip_rect functions? +*/ + +/** +* drm_clip_rect_reset - Reset clip +* @clip: clip rectangle +* +* Sets clip to {0,0,0,0}. +*/ +static inline void drm_clip_rect_reset (struct drm_clip_rect *clip) +{ + clip->x1 =0 ; + clip->x2 =0 ; + clip->y1 =0 ; + clip->y2 =0 ; +} + +/** +* drm_clip_rect_is_empty - Is clip empty? +* @clip: clip rectangle +* +* Returns true if clip is {0,0,0,0}. +*/ +static inline bool drm_clip_rect_is_empty (struct drm_clip_rect *clip) +{ +return (!clip->x1 && !clip->x2 && !clip->y1 && !clip->y2); +} + +/** +* drm_clip_rect_sanetize - Make sure clip rectangle has sane values +* @clip: clip rectangle +* @width: maximum width of rectangle +* @height: maximum height of rectangle +* +* Makes sure the clip doesn't exceed the specified width and height and that +* x1 <= x2 and y1 <= y2. +*/ +void drm_clip_rect_sanetize (struct drm_clip_rect *clip,u32 width,u32 height) +{ +if (clip->x1 > clip->x2) +swap (clip->x1, clip->x2); +if (clip->y1 > clip->y2) +swap (clip->y1, clip->y2); + + clip->x1 =min_t (u32, clip->x1, width -1 ); + clip->x2 =min_t (u32, clip->x2, width -1 ); + clip->y1 =min_t (u32, clip->y1, height -1 ); + clip->y2 =min_t (u32, clip->y2, height -1 ); +} +EXPORT_SYMBOL (drm_clip_rect_sanetize); + +/** +* drm_clip_rect_merge - Merge clip rectangles +* @dst: destination clip rectangle +* @src: source clip rectangle(s), can be NULL +* @num_clips: number of source clip rectangles +* @width: width of rectangle if @src is NULL +* @height: height of rectangle if @src is NULL +* +* The dirtyfb ioctl allows for a NULL clip to be passed in, +* so if @src is NULL, width and height is used to set a full clip. +* @dst takes part in the merge unless it is empty {0,0,0,0}. +*/ +void drm_clip_rect_merge (struct drm_clip_rect *dst, +struct drm_clip_rect *src,unsigned num_clips, +unsigned flags,u32 width,u32 height) +{ +int i; + +if (!src || !num_clips) { + dst->x1 =0 ; + dst->x2 = width -1 ; + dst->y1 =0 ; + dst->y2 = height -1 ; +return ; + } + +if (drm_clip_rect_is_empty (dst)) { + dst->x1 = ~0 ; + dst->y1 = ~0 ; + } + +for (i =0 ; i < num_clips; i++) { +if (flags &DRM_MODE_FB_DIRTY_ANNOTATE_COPY ) + i++; + dst->x1 =min (dst->x1, src[i].x1); + dst->x2 =max (dst->x2, src[i].x2); + dst->y1 =min (dst->y1, src[i].y1); + dst->y2 =max (dst->y2, src[i].y2); + } +} +EXPORT_SYMBOL (drm_clip_rect_merge); +/** * DOC: fbdev helpers *
@@ -410,6 +504,13 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)drm_warn_on_modeset_not_all_locked (dev); +#ifdef CONFIG_FB_DEFERRED_IO +spin_lock (&fb_helper->dirty_lock); +drm_clip_rect_merge (&fb_helper->dirty_clip,NULL ,0 ,0 , + fb_helper->fbdev->var.xres, + fb_helper->fbdev->var.yres); +spin_unlock (&fb_helper->dirty_lock); +#endif if (fb_helper->atomic)return restore_fbdev_mode_atomic (fb_helper);
@@ -654,6 +755,9 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, const struct drm_fb_helper_funcs *funcs) {INIT_LIST_HEAD (&helper->kernel_fb_list); +#ifdef CONFIG_FB_DEFERRED_IO +spin_lock_init (&helper->dirty_lock); +#endif helper->funcs = funcs; helper->dev = dev; }
@@ -838,6 +942,76 @@ void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) }EXPORT_SYMBOL (drm_fb_helper_unlink_fbi); +#ifdef CONFIG_FB_DEFERRED_IO +void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist) +{ +struct drm_fb_helper *helper = info->par; +unsigned long start, end, min, max; +struct drm_clip_rect clip; +struct page *page; + +if (!helper->fb->funcs->dirty) +return ; + +spin_lock (&helper->dirty_lock); + clip = helper->dirty_clip; +drm_clip_rect_reset (&helper->dirty_clip); +spin_unlock (&helper->dirty_lock); + + min =ULONG_MAX ; + max =0 ; +list_for_each_entry (page, pagelist, lru) { + start = page->index <<PAGE_SHIFT ; + end = start +PAGE_SIZE -1 ; + min =min (min, start); + max =max (max, end); + } + +if (min < max) { + clip.x1 =0 ; + clip.x2 = info->var.xres -1 ; + clip.y1 = min / info->fix.line_length; + clip.y2 =min_t (u32, max / info->fix.line_length, + info->var.yres -1 ); + }else if (drm_clip_rect_is_empty (&clip)) { + clip.x1 =0 ; + clip.x2 = info->var.xres -1 ; + clip.y1 =0 ; + clip.y2 = info->var.yres -1 ; + } + + helper->fb->funcs->dirty (helper->fb,NULL ,0 ,0 , &clip,1 ); +} +EXPORT_SYMBOL (drm_fb_helper_deferred_io); + +static void drm_fb_helper_sys_deferred (struct fb_info *info,u32 x,u32 y, +u32 width,u32 height) +{ +struct drm_fb_helper *helper = info->par; +struct drm_clip_rect clip; + +if (!info->fbdefio) +return ; + + clip.x1 = x; + clip.x2 = x + width -1 ; + clip.y1 = y; + clip.y2 = y + height -1 ; + +spin_lock (&helper->dirty_lock); +drm_clip_rect_merge (&helper->dirty_clip, &clip,1 ,0 ,0 ,0 ); +spin_unlock (&helper->dirty_lock); + +schedule_delayed_work (&info->deferred_work, info->fbdefio->delay); +} +#else +static inline void drm_fb_helper_sys_deferred (struct fb_info *info,u32 x,u32 y, +u32 width,u32 height) +{ +} +#endif +/** * drm_fb_helper_sys_read - wrapper around fb_sys_read * @info: fb_info struct pointer
@@ -866,7 +1040,14 @@ EXPORT_SYMBOL(drm_fb_helper_sys_read);ssize_t drm_fb_helper_sys_write (struct fb_info *info,const char __user *buf,size_t count,loff_t *ppos) { -return fb_sys_write (info, buf, count, ppos); +ssize_t ret; + + ret =fb_sys_write (info, buf, count, ppos); +if (ret >0 ) +drm_fb_helper_sys_deferred (info,0 ,0 , + info->var.xres, info->var.yres); + +return ret; }EXPORT_SYMBOL (drm_fb_helper_sys_write);
@@ -881,6 +1062,8 @@ void drm_fb_helper_sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect) {sys_fillrect (info, rect); +drm_fb_helper_sys_deferred (info, rect->dx, rect->dy, + rect->width, rect->height); }EXPORT_SYMBOL (drm_fb_helper_sys_fillrect);
@@ -895,6 +1078,8 @@ void drm_fb_helper_sys_copyarea(struct fb_info *info, const struct fb_copyarea *area) {sys_copyarea (info, area); +drm_fb_helper_sys_deferred (info, area->dx, area->dy, + area->width, area->height); }EXPORT_SYMBOL (drm_fb_helper_sys_copyarea);
@@ -909,6 +1094,8 @@ void drm_fb_helper_sys_imageblit(struct fb_info *info, const struct fb_image *image) {sys_imageblit (info, image); +drm_fb_helper_sys_deferred (info, image->dx, image->dy, + image->width, image->height); }EXPORT_SYMBOL (drm_fb_helper_sys_imageblit);
include/drm/drm_fb_helper.h +15 -0
@@ -172,6 +172,9 @@ struct drm_fb_helper_connector {* @funcs: driver callbacks for fb helper * @fbdev: emulated fbdev device info struct * @pseudo_palette: fake palette of 16 colors +* @dirty_clip: clip rectangle used with deferred_io to accumulate damage to +* the screen buffer +* @dirty_lock: spinlock protecting @dirty_clip * * This is the main structure used by the fbdev helpers. Drivers supporting * fbdev emulation should embedded this into their overall driver structure.
@@ -189,6 +192,10 @@ struct drm_fb_helper {const struct drm_fb_helper_funcs *funcs;struct fb_info *fbdev;u32 pseudo_palette[17 ]; +#ifdef CONFIG_FB_DEFERRED_IO +struct drm_clip_rect dirty_clip; +spinlock_t dirty_lock; +#endif /** * @kernel_fb_list:
@@ -244,6 +251,9 @@ 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); +void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist); +ssize_t drm_fb_helper_sys_read (struct fb_info *info,char __user *buf,size_t count,loff_t *ppos); ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,
@@ -362,6 +372,11 @@ static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) { } +static inline void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist) +{ +} +static inline ssize_t drm_fb_helper_sys_read (struct fb_info *info,char __user *buf,size_t count,loff_t *ppos)
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
Quoted 26 lines · Noralf Trønnes
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_fb_helper.c | 189 +++++++++++++++++++++++++++++++++++++++- include/drm/drm_fb_helper.h | 15 ++++ 2 files changed, 203 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_fb_helper.c +0
-0
drivers/gpu/drm/drm_fb_helper.c MODULE_PARM_DESC(fbdev_emulation, · line 53
Quoted 6 lines
drivers/gpu/drm/drm_fb_helper.c +3
-0@@ -48,6 +48,100 @@ MODULE_PARM_DESC(fbdev_emulation,static LIST_HEAD (kernel_fb_helper_list); +/* +* Where should I put these drm_clip_rect functions? +*/
drm_rect.[hc] Some of them are there already but under different names (e.g. intersect instead of sanitize).
-Daniel
Quoted 292 lines
drivers/gpu/drm/drm_fb_helper.c +185
-1+ +/** +* drm_clip_rect_reset - Reset clip +* @clip: clip rectangle +* +* Sets clip to {0,0,0,0}. +*/ +static inline void drm_clip_rect_reset (struct drm_clip_rect *clip) +{ + clip->x1 =0 ; + clip->x2 =0 ; + clip->y1 =0 ; + clip->y2 =0 ; +} + +/** +* drm_clip_rect_is_empty - Is clip empty? +* @clip: clip rectangle +* +* Returns true if clip is {0,0,0,0}. +*/ +static inline bool drm_clip_rect_is_empty (struct drm_clip_rect *clip) +{ +return (!clip->x1 && !clip->x2 && !clip->y1 && !clip->y2); +} + +/** +* drm_clip_rect_sanetize - Make sure clip rectangle has sane values +* @clip: clip rectangle +* @width: maximum width of rectangle +* @height: maximum height of rectangle +* +* Makes sure the clip doesn't exceed the specified width and height and that +* x1 <= x2 and y1 <= y2. +*/ +void drm_clip_rect_sanetize (struct drm_clip_rect *clip,u32 width,u32 height) +{ +if (clip->x1 > clip->x2) +swap (clip->x1, clip->x2); +if (clip->y1 > clip->y2) +swap (clip->y1, clip->y2); + + clip->x1 =min_t (u32, clip->x1, width -1 ); + clip->x2 =min_t (u32, clip->x2, width -1 ); + clip->y1 =min_t (u32, clip->y1, height -1 ); + clip->y2 =min_t (u32, clip->y2, height -1 ); +} +EXPORT_SYMBOL (drm_clip_rect_sanetize); + +/** +* drm_clip_rect_merge - Merge clip rectangles +* @dst: destination clip rectangle +* @src: source clip rectangle(s), can be NULL +* @num_clips: number of source clip rectangles +* @width: width of rectangle if @src is NULL +* @height: height of rectangle if @src is NULL +* +* The dirtyfb ioctl allows for a NULL clip to be passed in, +* so if @src is NULL, width and height is used to set a full clip. +* @dst takes part in the merge unless it is empty {0,0,0,0}. +*/ +void drm_clip_rect_merge (struct drm_clip_rect *dst, +struct drm_clip_rect *src,unsigned num_clips, +unsigned flags,u32 width,u32 height) +{ +int i; + +if (!src || !num_clips) { + dst->x1 =0 ; + dst->x2 = width -1 ; + dst->y1 =0 ; + dst->y2 = height -1 ; +return ; + } + +if (drm_clip_rect_is_empty (dst)) { + dst->x1 = ~0 ; + dst->y1 = ~0 ; + } + +for (i =0 ; i < num_clips; i++) { +if (flags &DRM_MODE_FB_DIRTY_ANNOTATE_COPY ) + i++; + dst->x1 =min (dst->x1, src[i].x1); + dst->x2 =max (dst->x2, src[i].x2); + dst->y1 =min (dst->y1, src[i].y1); + dst->y2 =max (dst->y2, src[i].y2); + } +} +EXPORT_SYMBOL (drm_clip_rect_merge); +/** * DOC: fbdev helpers * @@ -410,6 +504,13 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)drm_warn_on_modeset_not_all_locked (dev); +#ifdef CONFIG_FB_DEFERRED_IO +spin_lock (&fb_helper->dirty_lock); +drm_clip_rect_merge (&fb_helper->dirty_clip,NULL ,0 ,0 , + fb_helper->fbdev->var.xres, + fb_helper->fbdev->var.yres); +spin_unlock (&fb_helper->dirty_lock); +#endif if (fb_helper->atomic)return restore_fbdev_mode_atomic (fb_helper);@@ -654,6 +755,9 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, const struct drm_fb_helper_funcs *funcs) {INIT_LIST_HEAD (&helper->kernel_fb_list); +#ifdef CONFIG_FB_DEFERRED_IO +spin_lock_init (&helper->dirty_lock); +#endif helper->funcs = funcs; helper->dev = dev; }@@ -838,6 +942,76 @@ void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) }EXPORT_SYMBOL (drm_fb_helper_unlink_fbi); +#ifdef CONFIG_FB_DEFERRED_IO +void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist) +{ +struct drm_fb_helper *helper = info->par; +unsigned long start, end, min, max; +struct drm_clip_rect clip; +struct page *page; + +if (!helper->fb->funcs->dirty) +return ; + +spin_lock (&helper->dirty_lock); + clip = helper->dirty_clip; +drm_clip_rect_reset (&helper->dirty_clip); +spin_unlock (&helper->dirty_lock); + + min =ULONG_MAX ; + max =0 ; +list_for_each_entry (page, pagelist, lru) { + start = page->index <<PAGE_SHIFT ; + end = start +PAGE_SIZE -1 ; + min =min (min, start); + max =max (max, end); + } + +if (min < max) { + clip.x1 =0 ; + clip.x2 = info->var.xres -1 ; + clip.y1 = min / info->fix.line_length; + clip.y2 =min_t (u32, max / info->fix.line_length, + info->var.yres -1 ); + }else if (drm_clip_rect_is_empty (&clip)) { + clip.x1 =0 ; + clip.x2 = info->var.xres -1 ; + clip.y1 =0 ; + clip.y2 = info->var.yres -1 ; + } + + helper->fb->funcs->dirty (helper->fb,NULL ,0 ,0 , &clip,1 ); +} +EXPORT_SYMBOL (drm_fb_helper_deferred_io); + +static void drm_fb_helper_sys_deferred (struct fb_info *info,u32 x,u32 y, +u32 width,u32 height) +{ +struct drm_fb_helper *helper = info->par; +struct drm_clip_rect clip; + +if (!info->fbdefio) +return ; + + clip.x1 = x; + clip.x2 = x + width -1 ; + clip.y1 = y; + clip.y2 = y + height -1 ; + +spin_lock (&helper->dirty_lock); +drm_clip_rect_merge (&helper->dirty_clip, &clip,1 ,0 ,0 ,0 ); +spin_unlock (&helper->dirty_lock); + +schedule_delayed_work (&info->deferred_work, info->fbdefio->delay); +} +#else +static inline void drm_fb_helper_sys_deferred (struct fb_info *info,u32 x,u32 y, +u32 width,u32 height) +{ +} +#endif +/** * drm_fb_helper_sys_read - wrapper around fb_sys_read * @info: fb_info struct pointer @@ -866,7 +1040,14 @@ EXPORT_SYMBOL(drm_fb_helper_sys_read);ssize_t drm_fb_helper_sys_write (struct fb_info *info,const char __user *buf,size_t count,loff_t *ppos) { -return fb_sys_write (info, buf, count, ppos); +ssize_t ret; + + ret =fb_sys_write (info, buf, count, ppos); +if (ret >0 ) +drm_fb_helper_sys_deferred (info,0 ,0 , + info->var.xres, info->var.yres); + +return ret; }EXPORT_SYMBOL (drm_fb_helper_sys_write);@@ -881,6 +1062,8 @@ void drm_fb_helper_sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect) {sys_fillrect (info, rect); +drm_fb_helper_sys_deferred (info, rect->dx, rect->dy, + rect->width, rect->height); }EXPORT_SYMBOL (drm_fb_helper_sys_fillrect);@@ -895,6 +1078,8 @@ void drm_fb_helper_sys_copyarea(struct fb_info *info, const struct fb_copyarea *area) {sys_copyarea (info, area); +drm_fb_helper_sys_deferred (info, area->dx, area->dy, + area->width, area->height); }EXPORT_SYMBOL (drm_fb_helper_sys_copyarea);@@ -909,6 +1094,8 @@ void drm_fb_helper_sys_imageblit(struct fb_info *info, const struct fb_image *image) {sys_imageblit (info, image); +drm_fb_helper_sys_deferred (info, image->dx, image->dy, + image->width, image->height); }EXPORT_SYMBOL (drm_fb_helper_sys_imageblit);include/drm/drm_fb_helper.h +15
-0@@ -172,6 +172,9 @@ struct drm_fb_helper_connector {* @funcs: driver callbacks for fb helper * @fbdev: emulated fbdev device info struct * @pseudo_palette: fake palette of 16 colors +* @dirty_clip: clip rectangle used with deferred_io to accumulate damage to +* the screen buffer +* @dirty_lock: spinlock protecting @dirty_clip * * This is the main structure used by the fbdev helpers. Drivers supporting * fbdev emulation should embedded this into their overall driver structure. @@ -189,6 +192,10 @@ struct drm_fb_helper {const struct drm_fb_helper_funcs *funcs;struct fb_info *fbdev;u32 pseudo_palette[17 ]; +#ifdef CONFIG_FB_DEFERRED_IO +struct drm_clip_rect dirty_clip; +spinlock_t dirty_lock; +#endif /** * @kernel_fb_list: @@ -244,6 +251,9 @@ 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); +void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist); +ssize_t drm_fb_helper_sys_read (struct fb_info *info,char __user *buf,size_t count,loff_t *ppos); ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,@@ -362,6 +372,11 @@ static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) { } +static inline void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist) +{ +} +static inline ssize_t drm_fb_helper_sys_read (struct fb_info *info,char __user *buf,size_t count,loff_t *ppos)Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
In reply to Noralf TrønnesQuoted 11 lines · Noralf Trønnes
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.
Quoted 5 lines
The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;Signed-off-by Noralf Trønnes <[email protected]>
For this one it'd be awesome to throw patches for qxl/udl on top to remove their own hand-rolled implementations. Just to maximize the testing coverage of this new code. Should be doable to set up a qxl virtual machine quickly, but even without that we should be able to pull it in (since it's mostly just about removing code from these two drivers). -Daniel
Quoted 308 lines
--- drivers/gpu/drm/drm_fb_helper.c | 189 +++++++++++++++++++++++++++++++++++++++- include/drm/drm_fb_helper.h | 15 ++++ 2 files changed, 203 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_fb_helper.c +188
-1@@ -48,6 +48,100 @@ MODULE_PARM_DESC(fbdev_emulation,static LIST_HEAD (kernel_fb_helper_list); +/* +* Where should I put these drm_clip_rect functions? +*/ + +/** +* drm_clip_rect_reset - Reset clip +* @clip: clip rectangle +* +* Sets clip to {0,0,0,0}. +*/ +static inline void drm_clip_rect_reset (struct drm_clip_rect *clip) +{ + clip->x1 =0 ; + clip->x2 =0 ; + clip->y1 =0 ; + clip->y2 =0 ; +} + +/** +* drm_clip_rect_is_empty - Is clip empty? +* @clip: clip rectangle +* +* Returns true if clip is {0,0,0,0}. +*/ +static inline bool drm_clip_rect_is_empty (struct drm_clip_rect *clip) +{ +return (!clip->x1 && !clip->x2 && !clip->y1 && !clip->y2); +} + +/** +* drm_clip_rect_sanetize - Make sure clip rectangle has sane values +* @clip: clip rectangle +* @width: maximum width of rectangle +* @height: maximum height of rectangle +* +* Makes sure the clip doesn't exceed the specified width and height and that +* x1 <= x2 and y1 <= y2. +*/ +void drm_clip_rect_sanetize (struct drm_clip_rect *clip,u32 width,u32 height) +{ +if (clip->x1 > clip->x2) +swap (clip->x1, clip->x2); +if (clip->y1 > clip->y2) +swap (clip->y1, clip->y2); + + clip->x1 =min_t (u32, clip->x1, width -1 ); + clip->x2 =min_t (u32, clip->x2, width -1 ); + clip->y1 =min_t (u32, clip->y1, height -1 ); + clip->y2 =min_t (u32, clip->y2, height -1 ); +} +EXPORT_SYMBOL (drm_clip_rect_sanetize); + +/** +* drm_clip_rect_merge - Merge clip rectangles +* @dst: destination clip rectangle +* @src: source clip rectangle(s), can be NULL +* @num_clips: number of source clip rectangles +* @width: width of rectangle if @src is NULL +* @height: height of rectangle if @src is NULL +* +* The dirtyfb ioctl allows for a NULL clip to be passed in, +* so if @src is NULL, width and height is used to set a full clip. +* @dst takes part in the merge unless it is empty {0,0,0,0}. +*/ +void drm_clip_rect_merge (struct drm_clip_rect *dst, +struct drm_clip_rect *src,unsigned num_clips, +unsigned flags,u32 width,u32 height) +{ +int i; + +if (!src || !num_clips) { + dst->x1 =0 ; + dst->x2 = width -1 ; + dst->y1 =0 ; + dst->y2 = height -1 ; +return ; + } + +if (drm_clip_rect_is_empty (dst)) { + dst->x1 = ~0 ; + dst->y1 = ~0 ; + } + +for (i =0 ; i < num_clips; i++) { +if (flags &DRM_MODE_FB_DIRTY_ANNOTATE_COPY ) + i++; + dst->x1 =min (dst->x1, src[i].x1); + dst->x2 =max (dst->x2, src[i].x2); + dst->y1 =min (dst->y1, src[i].y1); + dst->y2 =max (dst->y2, src[i].y2); + } +} +EXPORT_SYMBOL (drm_clip_rect_merge); +/** * DOC: fbdev helpers * @@ -410,6 +504,13 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)drm_warn_on_modeset_not_all_locked (dev); +#ifdef CONFIG_FB_DEFERRED_IO +spin_lock (&fb_helper->dirty_lock); +drm_clip_rect_merge (&fb_helper->dirty_clip,NULL ,0 ,0 , + fb_helper->fbdev->var.xres, + fb_helper->fbdev->var.yres); +spin_unlock (&fb_helper->dirty_lock); +#endif if (fb_helper->atomic)return restore_fbdev_mode_atomic (fb_helper);@@ -654,6 +755,9 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, const struct drm_fb_helper_funcs *funcs) {INIT_LIST_HEAD (&helper->kernel_fb_list); +#ifdef CONFIG_FB_DEFERRED_IO +spin_lock_init (&helper->dirty_lock); +#endif helper->funcs = funcs; helper->dev = dev; }@@ -838,6 +942,76 @@ void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) }EXPORT_SYMBOL (drm_fb_helper_unlink_fbi); +#ifdef CONFIG_FB_DEFERRED_IO +void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist) +{ +struct drm_fb_helper *helper = info->par; +unsigned long start, end, min, max; +struct drm_clip_rect clip; +struct page *page; + +if (!helper->fb->funcs->dirty) +return ; + +spin_lock (&helper->dirty_lock); + clip = helper->dirty_clip; +drm_clip_rect_reset (&helper->dirty_clip); +spin_unlock (&helper->dirty_lock); + + min =ULONG_MAX ; + max =0 ; +list_for_each_entry (page, pagelist, lru) { + start = page->index <<PAGE_SHIFT ; + end = start +PAGE_SIZE -1 ; + min =min (min, start); + max =max (max, end); + } + +if (min < max) { + clip.x1 =0 ; + clip.x2 = info->var.xres -1 ; + clip.y1 = min / info->fix.line_length; + clip.y2 =min_t (u32, max / info->fix.line_length, + info->var.yres -1 ); + }else if (drm_clip_rect_is_empty (&clip)) { + clip.x1 =0 ; + clip.x2 = info->var.xres -1 ; + clip.y1 =0 ; + clip.y2 = info->var.yres -1 ; + } + + helper->fb->funcs->dirty (helper->fb,NULL ,0 ,0 , &clip,1 ); +} +EXPORT_SYMBOL (drm_fb_helper_deferred_io); + +static void drm_fb_helper_sys_deferred (struct fb_info *info,u32 x,u32 y, +u32 width,u32 height) +{ +struct drm_fb_helper *helper = info->par; +struct drm_clip_rect clip; + +if (!info->fbdefio) +return ; + + clip.x1 = x; + clip.x2 = x + width -1 ; + clip.y1 = y; + clip.y2 = y + height -1 ; + +spin_lock (&helper->dirty_lock); +drm_clip_rect_merge (&helper->dirty_clip, &clip,1 ,0 ,0 ,0 ); +spin_unlock (&helper->dirty_lock); + +schedule_delayed_work (&info->deferred_work, info->fbdefio->delay); +} +#else +static inline void drm_fb_helper_sys_deferred (struct fb_info *info,u32 x,u32 y, +u32 width,u32 height) +{ +} +#endif +/** * drm_fb_helper_sys_read - wrapper around fb_sys_read * @info: fb_info struct pointer @@ -866,7 +1040,14 @@ EXPORT_SYMBOL(drm_fb_helper_sys_read);ssize_t drm_fb_helper_sys_write (struct fb_info *info,const char __user *buf,size_t count,loff_t *ppos) { -return fb_sys_write (info, buf, count, ppos); +ssize_t ret; + + ret =fb_sys_write (info, buf, count, ppos); +if (ret >0 ) +drm_fb_helper_sys_deferred (info,0 ,0 , + info->var.xres, info->var.yres); + +return ret; }EXPORT_SYMBOL (drm_fb_helper_sys_write);@@ -881,6 +1062,8 @@ void drm_fb_helper_sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect) {sys_fillrect (info, rect); +drm_fb_helper_sys_deferred (info, rect->dx, rect->dy, + rect->width, rect->height); }EXPORT_SYMBOL (drm_fb_helper_sys_fillrect);@@ -895,6 +1078,8 @@ void drm_fb_helper_sys_copyarea(struct fb_info *info, const struct fb_copyarea *area) {sys_copyarea (info, area); +drm_fb_helper_sys_deferred (info, area->dx, area->dy, + area->width, area->height); }EXPORT_SYMBOL (drm_fb_helper_sys_copyarea);@@ -909,6 +1094,8 @@ void drm_fb_helper_sys_imageblit(struct fb_info *info, const struct fb_image *image) {sys_imageblit (info, image); +drm_fb_helper_sys_deferred (info, image->dx, image->dy, + image->width, image->height); }EXPORT_SYMBOL (drm_fb_helper_sys_imageblit);include/drm/drm_fb_helper.h +15
-0@@ -172,6 +172,9 @@ struct drm_fb_helper_connector {* @funcs: driver callbacks for fb helper * @fbdev: emulated fbdev device info struct * @pseudo_palette: fake palette of 16 colors +* @dirty_clip: clip rectangle used with deferred_io to accumulate damage to +* the screen buffer +* @dirty_lock: spinlock protecting @dirty_clip * * This is the main structure used by the fbdev helpers. Drivers supporting * fbdev emulation should embedded this into their overall driver structure. @@ -189,6 +192,10 @@ struct drm_fb_helper {const struct drm_fb_helper_funcs *funcs;struct fb_info *fbdev;u32 pseudo_palette[17 ]; +#ifdef CONFIG_FB_DEFERRED_IO +struct drm_clip_rect dirty_clip; +spinlock_t dirty_lock; +#endif /** * @kernel_fb_list: @@ -244,6 +251,9 @@ 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); +void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist); +ssize_t drm_fb_helper_sys_read (struct fb_info *info,char __user *buf,size_t count,loff_t *ppos); ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,@@ -362,6 +372,11 @@ static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) { } +static inline void drm_fb_helper_deferred_io (struct fb_info *info, +struct list_head *pagelist) +{ +} +static inline ssize_t drm_fb_helper_sys_read (struct fb_info *info,char __user *buf,size_t count,loff_t *ppos)Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
Den 13.04.2016 13:09, skrev Daniel Vetter:
Quoted 16 lines · Noralf Trønnes
Quoted 15 lines
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;
Quoted 6 lines
Quoted 1 line
Signed-off-by Noralf Trønnes <[email protected]>For this one it'd be awesome to throw patches for qxl/udl on top to remove their own hand-rolled implementations. Just to maximize the testing coverage of this new code. Should be doable to set up a qxl virtual machine quickly, but even without that we should be able to pull it in (since it's mostly just about removing code from these two drivers).
There are three fb_deferred_io users in drivers/gpu/drm: qxl, udl and vmwgfx.
drivers/gpu/drm/vmwgfx
It doesn't use drm_fb_helper (uses the cfb_{fillrect,copyarea,imageblit} functions directly). This made me think that I should probably add fb_deferred_io support to drm_fb_helper_cfb_*() as well.
drivers/gpu/drm/udl
First of all it has had deferred io disabled by default since 2013 (commit 677d23b). Secondly it handles damage directly in it's fb_{fillrect,copyarea,imageblit} functions, but defers to the next call if it is in atomic context. My patch always defers those function to a worker. The driver uses the drm_fb_helper_sys_* functions, so my patch would mess it up if someone would enable deferred io (module_param: fb_defio). So this driver isn't a good candidate for easy conversion also because it has different code paths for fbdev mmap damage and the other damages (although the code is similar). But it needs a patch to use the sys_*() functions directly.
drivers/gpu/drm/qxl
This one uses a worker as a buffer between the mmap damage tracking and fb_*() functions, and flushing of the changes. I'll give it a go.
Studying these in detail and looking at the git log was useful as it showed me that the (struct fb_ops *)->fb_*() functions can be called in interrupt context. This means that I need the irq version of spin_lock(). It also validates my choice to defer these calls using the mmap defer damage worker ((struct fb_info).deferred_work), because it ensures that the dirty() call will always run in process context.
Noralf.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
Quoted 25 lines · Noralf Trønnes
Den 13.04.2016 13:09, skrev Daniel Vetter:
Quoted 16 lines · Noralf Trønnes
Quoted 15 lines
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;Quoted 6 lines
Quoted 1 line
Signed-off-by Noralf Trønnes <[email protected]>For this one it'd be awesome to throw patches for qxl/udl on top to remove their own hand-rolled implementations. Just to maximize the testing coverage of this new code. Should be doable to set up a qxl virtual machine quickly, but even without that we should be able to pull it in (since it's mostly just about removing code from these two drivers).
Quoted 7 lines
There are three
fb_deferred_iousers indrivers/gpu/drm: qxl, udl and vmwgfx.
drivers/gpu/drm/vmwgfx
It doesn't usedrm_fb_helper(uses the cfb_{fillrect,copyarea,imageblit} functions directly). This made me think that I should probably addfb_deferred_iosupport to drm_fb_helper_cfb_*() as well.
Yup, that one is special and can be ignored.
Quoted 11 lines
drivers/gpu/drm/udl
First of all it has had deferred io disabled by default since 2013 (commit 677d23b). Secondly it handles damage directly in it's fb_{fillrect,copyarea,imageblit} functions, but defers to the next call if it is in atomic context. My patch always defers those function to a worker. The driver uses the drm_fb_helper_sys_* functions, so my patch would mess it up if someone would enable deferred io (module_param:fb_defio). So this driver isn't a good candidate for easy conversion also because it has different code paths for fbdev mmap damage and the other damages (although the code is similar). But it needs a patch to use the sys_*() functions directly.
Since it's disabled by default I'd just do a conversion. It should result largely in deleting code and just using the fb helpers. What's special with the mmap handling, and do we care?
Quoted 10 lines
drivers/gpu/drm/qxl
This one uses a worker as a buffer between the mmap damage tracking and fb_*() functions, and flushing of the changes. I'll give it a go.Studying these in detail and looking at the git log was useful as it showed me that the (struct
fb_ops*)->fb_*() functions can be called in interrupt context. This means that I need the irq version ofspin_lock(). It also validates my choice to defer these calls using the mmap defer damage worker ((struct fb_info).deferred_work), because it ensures that thedirty()call will always run in process context.
Yeah, mostly I'd like to get qxl&udl converted so that all the lessons learned in those implementations aren't lost. Great work digging out those details ;-)
Thanks, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
Den 20.04.2016 13:12, skrev Daniel Vetter:
Quoted 44 lines · Noralf Trønnes
Quoted 23 lines
Den 13.04.2016 13:09, skrev Daniel Vetter:
Quoted 16 lines · Noralf Trønnes
Quoted 15 lines
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;Quoted 6 lines
Quoted 1 line
Signed-off-by Noralf Trønnes <[email protected]>For this one it'd be awesome to throw patches for qxl/udl on top to remove their own hand-rolled implementations. Just to maximize the testing coverage of this new code. Should be doable to set up a qxl virtual machine quickly, but even without that we should be able to pull it in (since it's mostly just about removing code from these two drivers).
Quoted 7 lines
There are three
fb_deferred_iousers indrivers/gpu/drm: qxl, udl and vmwgfx.
drivers/gpu/drm/vmwgfx
It doesn't usedrm_fb_helper(uses the cfb_{fillrect,copyarea,imageblit} functions directly). This made me think that I should probably addfb_deferred_iosupport to drm_fb_helper_cfb_*() as well.Yup, that one is special and can be ignored.
Quoted 11 lines
drivers/gpu/drm/udl
First of all it has had deferred io disabled by default since 2013 (commit 677d23b). Secondly it handles damage directly in it's fb_{fillrect,copyarea,imageblit} functions, but defers to the next call if it is in atomic context. My patch always defers those function to a worker. The driver uses the drm_fb_helper_sys_* functions, so my patch would mess it up if someone would enable deferred io (module_param:fb_defio). So this driver isn't a good candidate for easy conversion also because it has different code paths for fbdev mmap damage and the other damages (although the code is similar). But it needs a patch to use the sys_*() functions directly.
Quoted 3 lines
Since it's disabled by default I'd just do a conversion. It should result largely in deleting code and just using the fb helpers. What's special with the mmap handling, and do we care?
The git log mentions page list corruption, but I realised that I can just disable the deferred mmap code and keep the rest.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerRe: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
In reply to Noralf TrønnesQuoted 29 lines · Noralf Trønnes
Den 13.04.2016 13:09, skrev Daniel Vetter:
Quoted 18 lines · Noralf Trønnes
Quoted 16 lines
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;Quoted 7 lines
Quoted 1 line
Signed-off-by Noralf Trønnes <[email protected]>For this one it'd be awesome to throw patches for qxl/udl on top to remove their own hand-rolled implementations. Just to maximize the testing coverage of this new code. Should be doable to set up a qxl virtual machine quickly, but even without that we should be able to pull it in (since it's mostly just about removing code from these two drivers).
Quoted 2 lines
There are three
fb_deferred_iousers indrivers/gpu/drm: qxl, udl and vmwgfx.
So I'm a bit confused. For me fb defio is a thing which userspace users, without an ioctl.
So we keep track in the kernel of dirty pages in the fb and then flush those pages. Now the thing is that last time I tried this it interacted badly with gem/ttm as defio wanted to do something to the same pages etc.
So I disabled it in udl for that reasons.
if we are talking about just having some damage tracking and not doing the page level tracking then ignore me.
Dave.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 1/8] drm/fb-helper: Add fb_deferred_io support
Quoted 36 lines · Dave Airlie
Quoted 29 lines · Noralf Trønnes
Den 13.04.2016 13:09, skrev Daniel Vetter:
Quoted 18 lines · Noralf Trønnes
Quoted 16 lines
This adds deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. Accumulated fbdev framebuffer changes are signaled using the callback (structdrm_framebuffer_funcs*)->dirty()The drm_fb_helper_sys_*() functions will accumulate changes and schedule fb_info.deferred_work _if_ fb_info.fbdefio is set. This worker is used by the deferred io mmap code to signal that it has been collecting page faults. The page faults and/or other changes are then merged into a
drm_clip_rectand passed to the framebufferdirty()function.The driver is responsible for setting up the fb_info.fbdefio structure and calling
fb_deferred_io_init()using the provided callback:
(structfb_info*)->fbdefio->deferred_io =drm_fb_helper_deferred_io;Quoted 7 lines
Quoted 1 line
Signed-off-by Noralf Trønnes <[email protected]>For this one it'd be awesome to throw patches for qxl/udl on top to remove their own hand-rolled implementations. Just to maximize the testing coverage of this new code. Should be doable to set up a qxl virtual machine quickly, but even without that we should be able to pull it in (since it's mostly just about removing code from these two drivers).
Quoted 2 lines
There are three
fb_deferred_iousers indrivers/gpu/drm: qxl, udl and vmwgfx.So I'm a bit confused. For me fb defio is a thing which userspace users, without an ioctl.
Quoted 8 lines
So we keep track in the kernel of dirty pages in the fb and then flush those pages. Now the thing is that last time I tried this it interacted badly with gem/ttm as defio wanted to do something to the same pages etc.
So I disabled it in udl for that reasons.
if we are talking about just having some damage tracking and not doing the page level tracking then ignore me.
Yeah I read through the code, and with shmem it'll die because shmem and fb defio will fight over the page lru. But if you have your pages backed by cma, or the fbdev mmap pointing at an mmio range I think it should all work (and seems to at least for Noralf).
Either way it's all optional opt-in code (just shared) and drivers can still opt to only do defio for in-kernel rendering and either have broken fbdev mmap support (like udl today), or implement their own defio mmap support compatible with shmem (not that hard either, but meh). And Noralf's conversion patches should result in bug-for-bug compatibility.
Cheers, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 2/8 drm/fb-cma-helper: Add fb_deferred_io support
In reply to Noralf TrønnesThis adds fbdev deferred io support if CONFIG_FB_DEFERRED_IO is enabled. The driver has to provide a (struct drm_framebuffer_funcs *)->dirty() callback to get notification of fbdev framebuffer changes. If the dirty() hook is set, then fb_deferred_io is set up automatically by the helper.
Two functions have been added so that the driver can provide a dirty() function:
- drm_fbdev_cma_init_with_funcs()
This makes it possible for the driver to provided a custom (struct drm_fb_helper_funcs *)->fb_probe() function.
- drm_fbdev_cma_create_with_funcs()
This is used by the .fb_probe hook to set a driver provided (struct drm_framebuffer_funcs *)->dirty() function.
Example driver code:
static int driver_fbdev_fb_dirty(struct drm_framebuffer *fb,
struct drm_file *file_priv, unsigned flags, unsigned color, struct drm_clip_rect *clips, unsigned num_clips)
{
struct drm_gem_cma_object *cma = drm_fb_cma_get_gem_obj(fb, 0);
return 0;
}static struct drm_framebuffer_funcs driver_fbdev_fb_funcs = {
.destroy = drm_fb_cma_destroy,
.create_handle = drm_fb_cma_create_handle,
.dirty = driver_fbdev_fb_dirty,
};
static int driver_fbdev_create(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes)
{
return drm_fbdev_cma_create_with_funcs(helper, sizes,
&driver_fbdev_fb_funcs);
}static const struct drm_fb_helper_funcs driver_fb_helper_funcs = {
.fb_probe = driver_fbdev_create,
};
Driver probe:
fbdev = drm_fbdev_cma_init_with_funcs(dev, 16, dev->mode_config.num_crtc, dev->mode_config.num_connector, &driver_fb_helper_funcs);
--- drivers/gpu/drm/drm_fb_cma_helper.c | 149 +++++++++++++++++++++++++++++++++--- include/drm/drm_fb_cma_helper.h | 14 ++++ 2 files changed, 151 insertions(+), 12 deletions(-)
drivers/gpu/drm/drm_fb_cma_helper.c +137 -12
@@ -25,6 +25,8 @@#include <drm/drm_fb_cma_helper.h> #include <linux/module.h> +#define DEFAULT_FBDEFIO_DELAY_MS 50 +struct drm_fb_cma {struct drm_framebuffer fb;struct drm_gem_cma_object *obj[4 ];
@@ -45,7 +47,7 @@ static inline struct drm_fb_cma *to_fb_cma(struct drm_framebuffer *fb) return container_of(fb, struct drm_fb_cma, fb); } -static void drm_fb_cma_destroy (struct drm_framebuffer *fb) +void drm_fb_cma_destroy (struct drm_framebuffer *fb) {struct drm_fb_cma *fb_cma =to_fb_cma (fb);int i;
@@ -58,8 +60,9 @@ static void drm_fb_cma_destroy(struct drm_framebuffer *fb)drm_framebuffer_cleanup (fb);kfree (fb_cma); } +EXPORT_SYMBOL (drm_fb_cma_destroy); -static int drm_fb_cma_create_handle (struct drm_framebuffer *fb, +int drm_fb_cma_create_handle (struct drm_framebuffer *fb,struct drm_file *file_priv,unsigned int *handle) {struct drm_fb_cma *fb_cma =to_fb_cma (fb);
@@ -67,6 +70,7 @@ static int drm_fb_cma_create_handle(struct drm_framebuffer *fb,return drm_gem_handle_create (file_priv, &fb_cma->obj[0 ]->base, handle); } +EXPORT_SYMBOL (drm_fb_cma_create_handle);static struct drm_framebuffer_funcs drm_fb_cma_funcs = { .destroy = drm_fb_cma_destroy,
@@ -75,7 +79,7 @@ static struct drm_framebuffer_funcs drm_fb_cma_funcs = {static struct drm_fb_cma *drm_fb_cma_alloc (struct drm_device *dev,const const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_cma_object **obj, -unsigned int num_planes) +unsigned int num_planes,struct drm_framebuffer_funcs *funcs) {struct drm_fb_cma *fb_cma;int ret;
@@ -90,7 +94,7 @@ static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,for (i =0 ; i < num_planes; i++) fb_cma->obj[i] = obj[i]; - ret =drm_framebuffer_init (dev, &fb_cma->fb, &drm_fb_cma_funcs); + ret =drm_framebuffer_init (dev, &fb_cma->fb, funcs);if (ret) {dev_err (dev->dev,"Failed to initialize framebuffer: %d\n" , ret);kfree (fb_cma);
@@ -144,7 +148,7 @@ struct drm_framebuffer *drm_fb_cma_create(struct drm_device *dev, objs[i] =to_drm_gem_cma_obj (obj); } - fb_cma =drm_fb_cma_alloc (dev, mode_cmd, objs, i); + fb_cma =drm_fb_cma_alloc (dev, mode_cmd, objs, i, &drm_fb_cma_funcs);if (IS_ERR (fb_cma)) { ret =PTR_ERR (fb_cma); goto err_gem_object_unreference;
@@ -232,8 +236,93 @@ static struct fb_ops drm_fbdev_cma_ops = { .fb_setcmap = drm_fb_helper_setcmap, }; -static int drm_fbdev_cma_create (struct drm_fb_helper *helper, -struct drm_fb_helper_surface_size *sizes) +#ifdef CONFIG_FB_DEFERRED_IO +/* +* HACK +* fb_deferred_io_mmap() is not exported so I use this hack until it's clear +* that this patch will be used. +*/ +static int (*fb_deferred_io_mmap)(struct fb_info *info, +struct vm_area_struct *vma); +/* +* I sent a question about my need to set vm_page_prot to the fbdev ML, but +* I haven't heard back. So exporting fb_deferred_io_mmap() is probably +* the best solution. +*/ +static int drm_fbdev_cma_deferred_io_mmap (struct fb_info *info, +struct vm_area_struct *vma) +{ +fb_deferred_io_mmap (info, vma); + vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); + +return 0 ; +} + +static int drm_fbdev_cma_defio_init (struct fb_info *fbi, +struct drm_gem_cma_object *cma_obj) +{ +struct fb_deferred_io *fbdefio; +struct fb_ops *fbops; + +/* +* Per device structures are needed because: +* fbops: fb_deferred_io_cleanup() clears fbops.fb_mmap +* fbdefio: individual delays +*/ + fbdefio =kzalloc (sizeof (*fbdefio),GFP_KERNEL ); + fbops =kzalloc (sizeof (*fbops),GFP_KERNEL ); +if (!fbdefio || !fbops) { +kfree (fbdefio); +return -ENOMEM ; + } + +/* can't be offset from vaddr since dirty() uses cma_obj */ + fbi->screen_buffer = cma_obj->vaddr; +/* fb_deferred_io_fault() needs a physical address */ + fbi->fix.smem_start =page_to_phys (virt_to_page (fbi->screen_buffer)); + + *fbops = *fbi->fbops; + fbi->fbops = fbops; + + fbdefio->delay =msecs_to_jiffies (DEFAULT_FBDEFIO_DELAY_MS ); + fbdefio->deferred_io = drm_fb_helper_deferred_io; + fbi->fbdefio = fbdefio; +fb_deferred_io_init (fbi); + +if (!fb_deferred_io_mmap) + fb_deferred_io_mmap = fbi->fbops->fb_mmap; + fbi->fbops->fb_mmap = drm_fbdev_cma_deferred_io_mmap; + +return 0 ; +} + +static void drm_fbdev_cma_defio_fini (struct fb_info *fbi) +{ +if (!fbi->fbdefio) +return ; + +fb_deferred_io_cleanup (fbi); +kfree (fbi->fbdefio); +kfree (fbi->fbops); +} +#else +static inline int drm_fbdev_cma_defio_init (struct fb_info *fbi) +{ +return 0 ; +} + +static inline void drm_fbdev_cma_defio_fini (struct fb_info *fbi) +{ +} +#endif /* CONFIG_FB_DEFERRED_IO */ + +/* +* For use in a (struct drm_fb_helper_funcs *)->fb_probe callback function that +* needs custom struct drm_framebuffer_funcs, like dirty() for deferred_io use. +*/ +int drm_fbdev_cma_create_with_funcs (struct drm_fb_helper *helper, +struct drm_fb_helper_surface_size *sizes, +struct drm_framebuffer_funcs *funcs) {struct drm_fbdev_cma *fbdev_cma =to_fbdev_cma (helper);struct drm_mode_fb_cmd2 mode_cmd = {0 };
@@ -269,7 +358,7 @@ static int drm_fbdev_cma_create(struct drm_fb_helper *helper, goto err_gem_free_object; } - fbdev_cma->fb =drm_fb_cma_alloc (dev, &mode_cmd, &obj,1 ); + fbdev_cma->fb =drm_fb_cma_alloc (dev, &mode_cmd, &obj,1 , funcs);if (IS_ERR (fbdev_cma->fb)) {dev_err (dev->dev,"Failed to allocate DRM framebuffer.\n" ); ret =PTR_ERR (fbdev_cma->fb);
@@ -295,31 +384,48 @@ static int drm_fbdev_cma_create(struct drm_fb_helper *helper, fbi->screen_size = size; fbi->fix.smem_len = size; +if (funcs->dirty) { + ret =drm_fbdev_cma_defio_init (fbi, obj); +if (ret) + goto err_cma_destroy; + } +return 0 ; +err_cma_destroy: +drm_framebuffer_unregister_private (&fbdev_cma->fb->fb); +drm_fb_cma_destroy (&fbdev_cma->fb->fb); err_fb_info_destroy:drm_fb_helper_release_fbi (helper); err_gem_free_object: dev->driver->gem_free_object (&obj->base);return ret; } +EXPORT_SYMBOL (drm_fbdev_cma_create_with_funcs); + +static int drm_fbdev_cma_create (struct drm_fb_helper *helper, +struct drm_fb_helper_surface_size *sizes) +{ +return drm_fbdev_cma_create_with_funcs (helper, sizes, &drm_fb_cma_funcs); +}static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = { .fb_probe = drm_fbdev_cma_create, };/** -* drm_fbdev_cma_init() - Allocate and initializes a drm_fbdev_cma struct +* drm_fbdev_cma_init_with_funcs() - Allocate and initializes a drm_fbdev_cma struct * @dev: DRM device * @preferred_bpp: Preferred bits per pixel for the device * @num_crtc: Number of CRTCs * @max_conn_count: Maximum number of connectors +* @funcs: fb helper functions, in particular fb_probe() * * Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR. */ -struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev, +struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs (struct drm_device *dev,unsigned int preferred_bpp,unsigned int num_crtc, -unsigned int max_conn_count) +unsigned int max_conn_count,const struct drm_fb_helper_funcs *funcs) {struct drm_fbdev_cma *fbdev_cma;struct drm_fb_helper *helper;
@@ -333,7 +439,7 @@ struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev, helper = &fbdev_cma->fb_helper; -drm_fb_helper_prepare (dev, helper, &drm_fb_cma_helper_funcs); +drm_fb_helper_prepare (dev, helper, funcs); ret =drm_fb_helper_init (dev, helper, num_crtc, max_conn_count);if (ret <0 ) {
@@ -363,6 +469,24 @@ err_free:return ERR_PTR (ret); } +EXPORT_SYMBOL_GPL (drm_fbdev_cma_init_with_funcs); + +/** +* drm_fbdev_cma_init() - Allocate and initializes a drm_fbdev_cma struct +* @dev: DRM device +* @preferred_bpp: Preferred bits per pixel for the device +* @num_crtc: Number of CRTCs +* @max_conn_count: Maximum number of connectors +* +* Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR. +*/ +struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev, +unsigned int preferred_bpp,unsigned int num_crtc, +unsigned int max_conn_count) +{ +return drm_fbdev_cma_init_with_funcs (dev, preferred_bpp, num_crtc, + max_conn_count, &drm_fb_cma_helper_funcs); +}EXPORT_SYMBOL_GPL (drm_fbdev_cma_init);/**
@@ -372,6 +496,7 @@ EXPORT_SYMBOL_GPL(drm_fbdev_cma_init);void drm_fbdev_cma_fini (struct drm_fbdev_cma *fbdev_cma) {drm_fb_helper_unregister_fbi (&fbdev_cma->fb_helper); +drm_fbdev_cma_defio_fini (fbdev_cma->fb_helper.fbdev);drm_fb_helper_release_fbi (&fbdev_cma->fb_helper);if (fbdev_cma->fb) {
include/drm/drm_fb_cma_helper.h +14 -0
@@ -4,11 +4,18 @@struct drm_fbdev_cma ;struct drm_gem_cma_object ; +struct drm_fb_helper_surface_size ; +struct drm_framebuffer_funcs ; +struct drm_fb_helper_funcs ;struct drm_framebuffer ; +struct drm_fb_helper ;struct drm_device ;struct drm_file ;struct drm_mode_fb_cmd2 ; +struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs (struct drm_device *dev, +unsigned int preferred_bpp,unsigned int num_crtc, +unsigned int max_conn_count,const struct drm_fb_helper_funcs *funcs);struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev,unsigned int preferred_bpp,unsigned int num_crtc,unsigned int max_conn_count);
@@ -16,6 +23,13 @@ void drm_fbdev_cma_fini(struct drm_fbdev_cma *fbdev_cma);void drm_fbdev_cma_restore_mode (struct drm_fbdev_cma *fbdev_cma);void drm_fbdev_cma_hotplug_event (struct drm_fbdev_cma *fbdev_cma); +int drm_fbdev_cma_create_with_funcs (struct drm_fb_helper *helper, +struct drm_fb_helper_surface_size *sizes, +struct drm_framebuffer_funcs *funcs); + +void drm_fb_cma_destroy (struct drm_framebuffer *fb); +int drm_fb_cma_create_handle (struct drm_framebuffer *fb, +struct drm_file *file_priv,unsigned int *handle);struct drm_framebuffer *drm_fb_cma_create (struct drm_device *dev,struct drm_file *file_priv,const struct drm_mode_fb_cmd2 *mode_cmd);
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 2/8] drm/fb-cma-helper: Add fb_deferred_io support
Quoted 45 lines · Noralf Trønnes
This adds fbdev deferred io support if
CONFIG_FB_DEFERRED_IOis enabled. The driver has to provide a (structdrm_framebuffer_funcs*)->dirty() callback to get notification of fbdev framebuffer changes. If thedirty()hook is set, thenfb_deferred_iois set up automatically by the helper.Two functions have been added so that the driver can provide a
dirty()function:
-drm_fbdev_cma_init_with_funcs()
This makes it possible for the driver to provided a custom (structdrm_fb_helper_funcs*)->fb_probe() function.
-drm_fbdev_cma_create_with_funcs()
This is used by the .fb_probe hook to set a driver provided (structdrm_framebuffer_funcs*)->dirty() function.Example driver code:
static int driver_fbdev_fb_dirty(struct
drm_framebuffer*fb,
structdrm_file*file_priv, unsigned flags, unsigned color, structdrm_clip_rect*clips, unsignednum_clips){ struct drm_gem_cma_object *cma = drm_fb_cma_get_gem_obj(fb, 0); return 0; }static struct
drm_framebuffer_funcsdriver_fbdev_fb_funcs= {
.destroy =drm_fb_cma_destroy,
.create_handle =drm_fb_cma_create_handle,
.dirty =driver_fbdev_fb_dirty,
};static int driver_fbdev_create(struct
drm_fb_helper*helper,
structdrm_fb_helper_surface_size*sizes){ return drm_fbdev_cma_create_with_funcs(helper, sizes, &driver_fbdev_fb_funcs); }static const struct
drm_fb_helper_funcsdriver_fb_helper_funcs= {
.fb_probe =driver_fbdev_create,
};
Quoted 6 lines
Driver probe:
fbdev = drm_fbdev_cma_init_with_funcs(dev, 16, dev->mode_config.num_crtc, dev->mode_config.num_connector, &driver_fb_helper_funcs);
The above should be part of the cma kerneldoc help text I think. If you use drm-intel-nightly you can even properly quote source snippets and stuff:
http://blog.ffwll.ch/2016/01/better-markup-for-kernel-gpu-docbook.html
Quoted 1 line
Signed-off-by Noralf Trønnes <[email protected]>
For this patch we also need an ack from Laurent Pinchart. Please cc him on the next round.
-Daniel
Quoted 316 lines
--- drivers/gpu/drm/drm_fb_cma_helper.c | 149 +++++++++++++++++++++++++++++++++--- include/drm/drm_fb_cma_helper.h | 14 ++++ 2 files changed, 151 insertions(+), 12 deletions(-)drivers/gpu/drm/drm_fb_cma_helper.c +137
-12@@ -25,6 +25,8 @@#include <drm/drm_fb_cma_helper.h> #include <linux/module.h> +#define DEFAULT_FBDEFIO_DELAY_MS 50 +struct drm_fb_cma {struct drm_framebuffer fb;struct drm_gem_cma_object *obj[4 ];@@ -45,7 +47,7 @@ static inline struct drm_fb_cma *to_fb_cma(struct drm_framebuffer *fb) return container_of(fb, struct drm_fb_cma, fb); } -static void drm_fb_cma_destroy (struct drm_framebuffer *fb) +void drm_fb_cma_destroy (struct drm_framebuffer *fb) {struct drm_fb_cma *fb_cma =to_fb_cma (fb);int i;@@ -58,8 +60,9 @@ static void drm_fb_cma_destroy(struct drm_framebuffer *fb)drm_framebuffer_cleanup (fb);kfree (fb_cma); } +EXPORT_SYMBOL (drm_fb_cma_destroy); -static int drm_fb_cma_create_handle (struct drm_framebuffer *fb, +int drm_fb_cma_create_handle (struct drm_framebuffer *fb,struct drm_file *file_priv,unsigned int *handle) {struct drm_fb_cma *fb_cma =to_fb_cma (fb);@@ -67,6 +70,7 @@ static int drm_fb_cma_create_handle(struct drm_framebuffer *fb,return drm_gem_handle_create (file_priv, &fb_cma->obj[0 ]->base, handle); } +EXPORT_SYMBOL (drm_fb_cma_create_handle);static struct drm_framebuffer_funcs drm_fb_cma_funcs = { .destroy = drm_fb_cma_destroy,@@ -75,7 +79,7 @@ static struct drm_framebuffer_funcs drm_fb_cma_funcs = {static struct drm_fb_cma *drm_fb_cma_alloc (struct drm_device *dev,const const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_cma_object **obj, -unsigned int num_planes) +unsigned int num_planes,struct drm_framebuffer_funcs *funcs) {struct drm_fb_cma *fb_cma;int ret;@@ -90,7 +94,7 @@ static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,for (i =0 ; i < num_planes; i++) fb_cma->obj[i] = obj[i]; - ret =drm_framebuffer_init (dev, &fb_cma->fb, &drm_fb_cma_funcs); + ret =drm_framebuffer_init (dev, &fb_cma->fb, funcs);if (ret) {dev_err (dev->dev,"Failed to initialize framebuffer: %d\n" , ret);kfree (fb_cma);@@ -144,7 +148,7 @@ struct drm_framebuffer *drm_fb_cma_create(struct drm_device *dev, objs[i] =to_drm_gem_cma_obj (obj); } - fb_cma =drm_fb_cma_alloc (dev, mode_cmd, objs, i); + fb_cma =drm_fb_cma_alloc (dev, mode_cmd, objs, i, &drm_fb_cma_funcs);if (IS_ERR (fb_cma)) { ret =PTR_ERR (fb_cma); goto err_gem_object_unreference;@@ -232,8 +236,93 @@ static struct fb_ops drm_fbdev_cma_ops = { .fb_setcmap = drm_fb_helper_setcmap, }; -static int drm_fbdev_cma_create (struct drm_fb_helper *helper, -struct drm_fb_helper_surface_size *sizes) +#ifdef CONFIG_FB_DEFERRED_IO +/* +* HACK +* fb_deferred_io_mmap() is not exported so I use this hack until it's clear +* that this patch will be used. +*/ +static int (*fb_deferred_io_mmap)(struct fb_info *info, +struct vm_area_struct *vma); +/* +* I sent a question about my need to set vm_page_prot to the fbdev ML, but +* I haven't heard back. So exporting fb_deferred_io_mmap() is probably +* the best solution. +*/ +static int drm_fbdev_cma_deferred_io_mmap (struct fb_info *info, +struct vm_area_struct *vma) +{ +fb_deferred_io_mmap (info, vma); + vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); + +return 0 ; +} + +static int drm_fbdev_cma_defio_init (struct fb_info *fbi, +struct drm_gem_cma_object *cma_obj) +{ +struct fb_deferred_io *fbdefio; +struct fb_ops *fbops; + +/* +* Per device structures are needed because: +* fbops: fb_deferred_io_cleanup() clears fbops.fb_mmap +* fbdefio: individual delays +*/ + fbdefio =kzalloc (sizeof (*fbdefio),GFP_KERNEL ); + fbops =kzalloc (sizeof (*fbops),GFP_KERNEL ); +if (!fbdefio || !fbops) { +kfree (fbdefio); +return -ENOMEM ; + } + +/* can't be offset from vaddr since dirty() uses cma_obj */ + fbi->screen_buffer = cma_obj->vaddr; +/* fb_deferred_io_fault() needs a physical address */ + fbi->fix.smem_start =page_to_phys (virt_to_page (fbi->screen_buffer)); + + *fbops = *fbi->fbops; + fbi->fbops = fbops; + + fbdefio->delay =msecs_to_jiffies (DEFAULT_FBDEFIO_DELAY_MS ); + fbdefio->deferred_io = drm_fb_helper_deferred_io; + fbi->fbdefio = fbdefio; +fb_deferred_io_init (fbi); + +if (!fb_deferred_io_mmap) + fb_deferred_io_mmap = fbi->fbops->fb_mmap; + fbi->fbops->fb_mmap = drm_fbdev_cma_deferred_io_mmap; + +return 0 ; +} + +static void drm_fbdev_cma_defio_fini (struct fb_info *fbi) +{ +if (!fbi->fbdefio) +return ; + +fb_deferred_io_cleanup (fbi); +kfree (fbi->fbdefio); +kfree (fbi->fbops); +} +#else +static inline int drm_fbdev_cma_defio_init (struct fb_info *fbi) +{ +return 0 ; +} + +static inline void drm_fbdev_cma_defio_fini (struct fb_info *fbi) +{ +} +#endif /* CONFIG_FB_DEFERRED_IO */ + +/* +* For use in a (struct drm_fb_helper_funcs *)->fb_probe callback function that +* needs custom struct drm_framebuffer_funcs, like dirty() for deferred_io use. +*/ +int drm_fbdev_cma_create_with_funcs (struct drm_fb_helper *helper, +struct drm_fb_helper_surface_size *sizes, +struct drm_framebuffer_funcs *funcs) {struct drm_fbdev_cma *fbdev_cma =to_fbdev_cma (helper);struct drm_mode_fb_cmd2 mode_cmd = {0 };@@ -269,7 +358,7 @@ static int drm_fbdev_cma_create(struct drm_fb_helper *helper, goto err_gem_free_object; } - fbdev_cma->fb =drm_fb_cma_alloc (dev, &mode_cmd, &obj,1 ); + fbdev_cma->fb =drm_fb_cma_alloc (dev, &mode_cmd, &obj,1 , funcs);if (IS_ERR (fbdev_cma->fb)) {dev_err (dev->dev,"Failed to allocate DRM framebuffer.\n" ); ret =PTR_ERR (fbdev_cma->fb);@@ -295,31 +384,48 @@ static int drm_fbdev_cma_create(struct drm_fb_helper *helper, fbi->screen_size = size; fbi->fix.smem_len = size; +if (funcs->dirty) { + ret =drm_fbdev_cma_defio_init (fbi, obj); +if (ret) + goto err_cma_destroy; + } +return 0 ; +err_cma_destroy: +drm_framebuffer_unregister_private (&fbdev_cma->fb->fb); +drm_fb_cma_destroy (&fbdev_cma->fb->fb); err_fb_info_destroy:drm_fb_helper_release_fbi (helper); err_gem_free_object: dev->driver->gem_free_object (&obj->base);return ret; } +EXPORT_SYMBOL (drm_fbdev_cma_create_with_funcs); + +static int drm_fbdev_cma_create (struct drm_fb_helper *helper, +struct drm_fb_helper_surface_size *sizes) +{ +return drm_fbdev_cma_create_with_funcs (helper, sizes, &drm_fb_cma_funcs); +}static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = { .fb_probe = drm_fbdev_cma_create, };/** -* drm_fbdev_cma_init() - Allocate and initializes a drm_fbdev_cma struct +* drm_fbdev_cma_init_with_funcs() - Allocate and initializes a drm_fbdev_cma struct * @dev: DRM device * @preferred_bpp: Preferred bits per pixel for the device * @num_crtc: Number of CRTCs * @max_conn_count: Maximum number of connectors +* @funcs: fb helper functions, in particular fb_probe() * * Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR. */ -struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev, +struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs (struct drm_device *dev,unsigned int preferred_bpp,unsigned int num_crtc, -unsigned int max_conn_count) +unsigned int max_conn_count,const struct drm_fb_helper_funcs *funcs) {struct drm_fbdev_cma *fbdev_cma;struct drm_fb_helper *helper;@@ -333,7 +439,7 @@ struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev, helper = &fbdev_cma->fb_helper; -drm_fb_helper_prepare (dev, helper, &drm_fb_cma_helper_funcs); +drm_fb_helper_prepare (dev, helper, funcs); ret =drm_fb_helper_init (dev, helper, num_crtc, max_conn_count);if (ret <0 ) {@@ -363,6 +469,24 @@ err_free:return ERR_PTR (ret); } +EXPORT_SYMBOL_GPL (drm_fbdev_cma_init_with_funcs); + +/** +* drm_fbdev_cma_init() - Allocate and initializes a drm_fbdev_cma struct +* @dev: DRM device +* @preferred_bpp: Preferred bits per pixel for the device +* @num_crtc: Number of CRTCs +* @max_conn_count: Maximum number of connectors +* +* Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR. +*/ +struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev, +unsigned int preferred_bpp,unsigned int num_crtc, +unsigned int max_conn_count) +{ +return drm_fbdev_cma_init_with_funcs (dev, preferred_bpp, num_crtc, + max_conn_count, &drm_fb_cma_helper_funcs); +}EXPORT_SYMBOL_GPL (drm_fbdev_cma_init);/** @@ -372,6 +496,7 @@ EXPORT_SYMBOL_GPL(drm_fbdev_cma_init);void drm_fbdev_cma_fini (struct drm_fbdev_cma *fbdev_cma) {drm_fb_helper_unregister_fbi (&fbdev_cma->fb_helper); +drm_fbdev_cma_defio_fini (fbdev_cma->fb_helper.fbdev);drm_fb_helper_release_fbi (&fbdev_cma->fb_helper);if (fbdev_cma->fb) {include/drm/drm_fb_cma_helper.h +14
-0@@ -4,11 +4,18 @@struct drm_fbdev_cma ;struct drm_gem_cma_object ; +struct drm_fb_helper_surface_size ; +struct drm_framebuffer_funcs ; +struct drm_fb_helper_funcs ;struct drm_framebuffer ; +struct drm_fb_helper ;struct drm_device ;struct drm_file ;struct drm_mode_fb_cmd2 ; +struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs (struct drm_device *dev, +unsigned int preferred_bpp,unsigned int num_crtc, +unsigned int max_conn_count,const struct drm_fb_helper_funcs *funcs);struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev,unsigned int preferred_bpp,unsigned int num_crtc,unsigned int max_conn_count);@@ -16,6 +23,13 @@ void drm_fbdev_cma_fini(struct drm_fbdev_cma *fbdev_cma);void drm_fbdev_cma_restore_mode (struct drm_fbdev_cma *fbdev_cma);void drm_fbdev_cma_hotplug_event (struct drm_fbdev_cma *fbdev_cma); +int drm_fbdev_cma_create_with_funcs (struct drm_fb_helper *helper, +struct drm_fb_helper_surface_size *sizes, +struct drm_framebuffer_funcs *funcs); + +void drm_fb_cma_destroy (struct drm_framebuffer *fb); +int drm_fb_cma_create_handle (struct drm_framebuffer *fb, +struct drm_file *file_priv,unsigned int *handle);struct drm_framebuffer *drm_fb_cma_create (struct drm_device *dev,struct drm_file *file_priv,const struct drm_mode_fb_cmd2 *mode_cmd);Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 3/8 drm: Add helper for simple kms drivers
In reply to Noralf TrønnesProvides helper functions for drivers that have a simple display pipeline. Plane, crtc and encoder are collapsed into one entity.
--- drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_simple_kms_helper.c | 262 ++++++++++++++++++++++++++++++++ include/drm/drm_simple_kms_helper.h | 44 ++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/gpu/drm/drm_simple_kms_helper.c create mode 100644 include/drm/drm_simple_kms_helper.h
drivers/gpu/drm/Kconfig +7 -0
@@ -31,6 +31,13 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_SIMPLE_KMS_HELPER + tristate + depends on DRM + select DRM_KMS_HELPER + help + Helpers for very simple KMS drivers. + config DRM_KMS_FB_HELPER bool depends on DRM_KMS_HELPER
drivers/gpu/drm/Makefile +1 -0
@@ -28,6 +28,7 @@ drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o +obj-$(CONFIG_DRM_SIMPLE_KMS_HELPER) += drm_simple_kms_helper.o CFLAGS_drm_trace_points.o := -I$(src)
drivers/gpu/drm/drm_simple_kms_helper.c new file +262 -0
262 lines not on this page · raw message
include/drm/drm_simple_kms_helper.h new file +44 -0
44 lines not on this page · raw message
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 3/8] drm: Add helper for simple kms drivers
Quoted 4 lines · Noralf Trønnes
Provides helper functions for drivers that have a simple display pipeline. Plane, crtc and encoder are collapsed into one entity.
Signed-off-by Noralf Trønnes <[email protected]>
Looks good. A few comments below, but the big thing is adding kerneldoc and cross-referencing it (e.g. from drm_panel to drm_panel_connector). -Daniel
Quoted 73 lines
--- drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_simple_kms_helper.c | 262 ++++++++++++++++++++++++++++++++ include/drm/drm_simple_kms_helper.h | 44 ++++++ 4 files changed, 314 insertions(+) create mode 100644 drivers/gpu/drm/drm_simple_kms_helper.c create mode 100644 include/drm/drm_simple_kms_helper.hdrivers/gpu/drm/Kconfig +7
-0@@ -31,6 +31,13 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_SIMPLE_KMS_HELPER + tristate + depends on DRM + select DRM_KMS_HELPER + help + Helpers for very simple KMS drivers. + config DRM_KMS_FB_HELPER bool depends on DRM_KMS_HELPERdrivers/gpu/drm/Makefile +1
-0@@ -28,6 +28,7 @@ drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o +obj-$(CONFIG_DRM_SIMPLE_KMS_HELPER) += drm_simple_kms_helper.o CFLAGS_drm_trace_points.o := -I$(src)drivers/gpu/drm/drm_simple_kms_helper.c new file +28
-0@@ -0,0 +1,262 @@ +/* +* Copyright (C) 2016 Noralf Trønnes +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <drm/drmP.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_crtc_helper.h> +#include <drm/drm_panel.h> +#include <drm/drm_plane_helper.h> +#include <drm/drm_simple_kms_helper.h> +#include <linux/slab.h> + +struct drm_simple_kms_connector { +struct drm_connector base; +struct drm_panel *panel; +}; + +static inline struct drm_simple_kms_connector * +to_simple_connector (struct drm_connector *connector) +{ + return container_of(connector, struct drm_simple_kms_connector, base); +} +
drivers/gpu/drm/drm_simple_kms_helper.c line 38
Quoted 10 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +10
-0+static int drm_simple_kms_connector_get_modes (struct drm_connector *connector) +{ +return drm_panel_get_modes (to_simple_connector (connector)->panel); +} + +static struct drm_encoder * +drm_simple_kms_connector_best_encoder (struct drm_connector *connector) +{ +return drm_encoder_find (connector->dev, connector->encoder_ids[0 ]); +}
I think this would be useful for atomic drivers in general. I even thought we have it already somewhere ...
Quoted 26 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +26
-0+ +static const struct drm_connector_helper_funcs drm_simple_kms_connector_helper_funcs = { + .get_modes = drm_simple_kms_connector_get_modes, + .best_encoder = drm_simple_kms_connector_best_encoder, +}; + +static enum drm_connector_status +drm_simple_kms_connector_detect (struct drm_connector *connector,bool force) +{ +if (drm_device_is_unplugged (connector->dev)) +return connector_status_disconnected; + +return connector->status; +} + +static void drm_simple_kms_connector_destroy (struct drm_connector *connector) +{ +struct drm_simple_kms_connector *panel_connector; + + panel_connector =to_simple_connector (connector); +drm_panel_detach (panel_connector->panel); +drm_panel_remove (panel_connector->panel); +drm_connector_unregister (connector); +drm_connector_cleanup (connector); +kfree (panel_connector); +}
drivers/gpu/drm/drm_simple_kms_helper.c line 74
Quoted 10 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +10
-0+ +static const struct drm_connector_funcs drm_simple_kms_connector_funcs = { + .dpms = drm_atomic_helper_connector_dpms, + .reset = drm_atomic_helper_connector_reset, + .detect = drm_simple_kms_connector_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = drm_simple_kms_connector_destroy, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +};
drm_simple_kms_panel_connector is toooooooooooo long ;-) What about just drm_panel_connector instead? Also not entirely sure whether this is best placed here, or better in drm_panel.c, or maybe even in a new drm_panel_helper.c.
Imo drm_panel_connector and drm_simple_display_pipe should work as orthogonal helpers.
Or 3rd option: You just expose the above helpers for detect/get_modes only.
Quoted 49 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +49
-0+ +/** +* drm_simple_kms_panel_connector_create - Create simple connector for panel +* @dev: DRM device +* @panel: DRM panel +* @connector_type: user visible type of the connector +* +* Creates a simple connector for a panel. +* The panel needs to provide a get_modes() function. +* +* Returns: +* Pointer to new connector or ERR_PTR on failure. +*/ +struct drm_connector * +drm_simple_kms_panel_connector_create (struct drm_device *dev, +struct drm_panel *panel, +int connector_type) +{ +struct drm_simple_kms_connector *panel_connector; +struct drm_connector *connector; +int ret; + + panel_connector =kzalloc (sizeof (*panel_connector),GFP_KERNEL ); +if (!panel_connector) +return ERR_PTR (-ENOMEM ); + + panel_connector->panel = panel; + connector = &panel_connector->base; +drm_connector_helper_add (connector, &drm_simple_kms_connector_helper_funcs); + ret =drm_connector_init (dev, connector, &drm_simple_kms_connector_funcs, + connector_type); +if (ret) { +kfree (panel_connector); +return ERR_PTR (ret); + } + + connector->status = connector_status_connected; +drm_panel_init (panel); +drm_panel_add (panel); +drm_panel_attach (panel, connector); + +return connector; +} +EXPORT_SYMBOL (drm_simple_kms_panel_connector_create); + +static void drm_simple_kms_encoder_disable (struct drm_encoder *encoder) +{ +} +
drivers/gpu/drm/drm_simple_kms_helper.c line 133
Quoted 10 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +10
-0+static void drm_simple_kms_encoder_enable (struct drm_encoder *encoder) +{ +} + +static int drm_simple_kms_encoder_atomic_check (struct drm_encoder *encoder, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ +return 0 ; +}
Above dummy functions shouldn't be necessary.
Quoted 145 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +129
-0+ +static const struct drm_encoder_helper_funcs drm_simple_kms_encoder_helper_funcs = { + .disable = drm_simple_kms_encoder_disable, + .enable = drm_simple_kms_encoder_enable, + .atomic_check = drm_simple_kms_encoder_atomic_check, +}; + +static const struct drm_encoder_funcs drm_simple_kms_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +static void drm_simple_kms_crtc_enable (struct drm_crtc *crtc) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); +if (!pipe->funcs || !pipe->funcs->enable) +return ; + + pipe->funcs->enable (pipe, crtc->state); +} + +static void drm_simple_kms_crtc_disable (struct drm_crtc *crtc) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); +if (!pipe->funcs || !pipe->funcs->disable) +return ; + + pipe->funcs->disable (pipe); +} + +static const struct drm_crtc_helper_funcs drm_simple_kms_crtc_helper_funcs = { + .disable = drm_simple_kms_crtc_disable, + .enable = drm_simple_kms_crtc_enable, +}; + +static const struct drm_crtc_funcs drm_simple_kms_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static void drm_simple_kms_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); +if (!pipe->funcs || !pipe->funcs->plane_update) +return ; + + pipe->funcs->plane_update (pipe, old_state); +} + +static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { + .atomic_update = drm_simple_kms_plane_atomic_update, +}; + +static const struct drm_plane_funcs drm_simple_kms_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + .reset = drm_atomic_helper_plane_reset, + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, +}; + +/** +* drm_simple_display_pipe_init - Initialize a simple display pipe +* @dev: DRM device +* @pipe: simple display pipe object to initialize +* @funcs: callbacks for the display pipe +* @formats: array of supported formats (%DRM_FORMAT_*) +* @format_count: number of elements in @formats +* @connector: connector to attach and register +* +* Sets up a display pipe which consist of a really simple plane-crtc-encoder +* pipe coupled with the provided connector. +* +* Returns: +* Zero on success, error code on failure. +*/ +int drm_simple_display_pipe_init (struct drm_device *dev, +struct drm_simple_display_pipe *pipe, +struct drm_simple_display_pipe_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +struct drm_connector *connector) +{ +struct drm_encoder *encoder = &pipe->encoder; +struct drm_plane *plane = &pipe->plane; +struct drm_crtc *crtc = &pipe->crtc; +int ret; + + pipe->funcs = funcs; + +drm_plane_helper_add (plane, &drm_simple_kms_plane_helper_funcs); + ret =drm_universal_plane_init (dev, plane,0 , &drm_simple_kms_plane_funcs, + formats, format_count, +DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret) +return ret; + +drm_crtc_helper_add (crtc, &drm_simple_kms_crtc_helper_funcs); + ret =drm_crtc_init_with_planes (dev, crtc, plane,NULL , + &drm_simple_kms_crtc_funcs,NULL ); +if (ret) +return ret; + + encoder->possible_crtcs =1 <<drm_crtc_index (crtc); +drm_encoder_helper_add (encoder, &drm_simple_kms_encoder_helper_funcs); + ret =drm_encoder_init (dev, encoder, &drm_simple_kms_encoder_funcs, +DRM_MODE_ENCODER_NONE ,NULL ); +if (ret) +return ret; + + ret =drm_mode_connector_attach_encoder (connector, encoder); +if (ret) +return ret; + +return drm_connector_register (connector); +} +EXPORT_SYMBOL (drm_simple_display_pipe_init); + +MODULE_LICENSE ("GPL" );include/drm/drm_simple_kms_helper.h new file +10
-0@@ -0,0 +1,44 @@ +/* +* Copyright (C) 2016 Noralf Trønnes +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
include/drm/drm_simple_kms_helper.h line 20
Quoted 10 lines
include/drm/drm_simple_kms_helper.h new file +10
-0+#define __LINUX_DRM_SIMPLE_KMS_HELPER_H + +struct drm_simple_display_pipe ; + +struct drm_simple_display_pipe_funcs { +void (*enable)(struct drm_simple_display_pipe *pipe, +struct drm_crtc_state *crtc_state); +void (*disable)(struct drm_simple_display_pipe *pipe); +void (*plane_update)(struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state);
On 2nd thought maybe we want an atomic_check in here too, with same parameters *pipe, *crtc_state and *plane_state (so that it's useful for both plane-only updates and modeset changes).
Quoted 31 lines
include/drm/drm_simple_kms_helper.h new file +24
-0+}; + +struct drm_simple_display_pipe { +struct drm_crtc crtc; +struct drm_plane plane; +struct drm_encoder encoder; +struct drm_connector *connector; + +struct drm_simple_display_pipe_funcs *funcs; +}; + +int drm_simple_display_pipe_init (struct drm_device *dev, +struct drm_simple_display_pipe *pipe, +struct drm_simple_display_pipe_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +struct drm_connector *connector); +struct drm_connector * +drm_simple_kms_panel_connector_create (struct drm_device *dev, +struct drm_panel *panel, +int connector_type); + + + +#endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */ Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 3/8] drm: Add helper for simple kms drivers
Den 13.04.2016 13:05, skrev Daniel Vetter:
Quoted 5 lines · Noralf Trønnes
Quoted 4 lines
Provides helper functions for drivers that have a simple display pipeline. Plane, crtc and encoder are collapsed into one entity.
Signed-off-by Noralf Trønnes <[email protected]>
[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +7
-0+static void drm_simple_kms_encoder_disable (struct drm_encoder *encoder) +{ +} + +static void drm_simple_kms_encoder_enable (struct drm_encoder *encoder) +{ +}
Quoted 8 lines
drivers/gpu/drm/drm_simple_kms_helper.c line 133
Quoted 7 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +7
-0+ +static int drm_simple_kms_encoder_atomic_check (struct drm_encoder *encoder, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ +return 0 ; +}Above dummy functions shouldn't be necessary.
I could remove .atomic_check, but not .disable and .enable which gave me NULL pointer errors. I need .enable or .commit, and .disable or .dpms.
Gist:
void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
struct drm_atomic_state*old_state)
{
for_each_connector_in_state(old_state, connector,
old_conn_state, i) {
const struct drm_encoder_helper_funcs *funcs;
funcs = encoder->helper_private;
if (funcs->enable)
funcs->enable(encoder);
else
funcs->commit(encoder);static voiddisable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) {
for_each_connector_in_state(old_state, connector,
old_conn_state, i) {
const struct drm_encoder_helper_funcs *funcs;
funcs = encoder->helper_private;
if (connector->state->crtc && funcs->prepare)
funcs->prepare(encoder);
else if (funcs->disable)
funcs->disable(encoder);
else
funcs->dpms(encoder, DRM_MODE_DPMS_OFF);Quoted 151 lines
Quoted 151 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +129
-0+ +static const struct drm_encoder_helper_funcs drm_simple_kms_encoder_helper_funcs = { + .disable = drm_simple_kms_encoder_disable, + .enable = drm_simple_kms_encoder_enable, + .atomic_check = drm_simple_kms_encoder_atomic_check, +}; + +static const struct drm_encoder_funcs drm_simple_kms_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +static void drm_simple_kms_crtc_enable (struct drm_crtc *crtc) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); +if (!pipe->funcs || !pipe->funcs->enable) +return ; + + pipe->funcs->enable (pipe, crtc->state); +} + +static void drm_simple_kms_crtc_disable (struct drm_crtc *crtc) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); +if (!pipe->funcs || !pipe->funcs->disable) +return ; + + pipe->funcs->disable (pipe); +} + +static const struct drm_crtc_helper_funcs drm_simple_kms_crtc_helper_funcs = { + .disable = drm_simple_kms_crtc_disable, + .enable = drm_simple_kms_crtc_enable, +}; + +static const struct drm_crtc_funcs drm_simple_kms_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static void drm_simple_kms_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); +if (!pipe->funcs || !pipe->funcs->plane_update) +return ; + + pipe->funcs->plane_update (pipe, old_state); +} + +static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { + .atomic_update = drm_simple_kms_plane_atomic_update, +}; + +static const struct drm_plane_funcs drm_simple_kms_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + .reset = drm_atomic_helper_plane_reset, + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, +}; + +/** +* drm_simple_display_pipe_init - Initialize a simple display pipe +* @dev: DRM device +* @pipe: simple display pipe object to initialize +* @funcs: callbacks for the display pipe +* @formats: array of supported formats (%DRM_FORMAT_*) +* @format_count: number of elements in @formats +* @connector: connector to attach and register +* +* Sets up a display pipe which consist of a really simple plane-crtc-encoder +* pipe coupled with the provided connector. +* +* Returns: +* Zero on success, error code on failure. +*/ +int drm_simple_display_pipe_init (struct drm_device *dev, +struct drm_simple_display_pipe *pipe, +struct drm_simple_display_pipe_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +struct drm_connector *connector) +{ +struct drm_encoder *encoder = &pipe->encoder; +struct drm_plane *plane = &pipe->plane; +struct drm_crtc *crtc = &pipe->crtc; +int ret; + + pipe->funcs = funcs; + +drm_plane_helper_add (plane, &drm_simple_kms_plane_helper_funcs); + ret =drm_universal_plane_init (dev, plane,0 , &drm_simple_kms_plane_funcs, + formats, format_count, +DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret) +return ret; + +drm_crtc_helper_add (crtc, &drm_simple_kms_crtc_helper_funcs); + ret =drm_crtc_init_with_planes (dev, crtc, plane,NULL , + &drm_simple_kms_crtc_funcs,NULL ); +if (ret) +return ret; + + encoder->possible_crtcs =1 <<drm_crtc_index (crtc); +drm_encoder_helper_add (encoder, &drm_simple_kms_encoder_helper_funcs); + ret =drm_encoder_init (dev, encoder, &drm_simple_kms_encoder_funcs, +DRM_MODE_ENCODER_NONE ,NULL ); +if (ret) +return ret; + + ret =drm_mode_connector_attach_encoder (connector, encoder); +if (ret) +return ret; + +return drm_connector_register (connector); +} +EXPORT_SYMBOL (drm_simple_display_pipe_init); + +MODULE_LICENSE ("GPL" );include/drm/drm_simple_kms_helper.h new file +15
-0@@ -0,0 +1,44 @@ +/* +* Copyright (C) 2016 Noralf Trønnes +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H +#define __LINUX_DRM_SIMPLE_KMS_HELPER_H + +struct drm_simple_display_pipe ; + +struct drm_simple_display_pipe_funcs {
Quoted 8 lines
include/drm/drm_simple_kms_helper.h line 20
Quoted 5 lines
include/drm/drm_simple_kms_helper.h new file +5
-0+void (*enable)(struct drm_simple_display_pipe *pipe, +struct drm_crtc_state *crtc_state); +void (*disable)(struct drm_simple_display_pipe *pipe); +void (*plane_update)(struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state);On 2nd thought maybe we want an
atomic_checkin here too, with same parameters *pipe,*crtc_stateand*plane_state(so that it's useful for both plane-only updates and modeset changes).
I could do this for the plane:
struct drm_simple_display_pipe_funcs {
void (*plane_check)(struct drm_simple_display_pipe *pipe,
struct drm_plane_state *plane_state);
}
static void drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
struct drm_plane_state *state)
{
struct drm_simple_display_pipe *pipe;
pipe = container_of(plane, struct drm_simple_display_pipe, plane);
if (!pipe->funcs || !pipe->funcs->plane_check)
return;
pipe->funcs->plane_check(pipe, state);
}static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = {
.atomic_check = drm_simple_kms_plane_atomic_check,
};
But how should I do crtc_state ?
Noralf.
Quoted 27 lines
Quoted 27 lines
include/drm/drm_simple_kms_helper.h new file +24
-0+}; + +struct drm_simple_display_pipe { +struct drm_crtc crtc; +struct drm_plane plane; +struct drm_encoder encoder; +struct drm_connector *connector; + +struct drm_simple_display_pipe_funcs *funcs; +}; + +int drm_simple_display_pipe_init (struct drm_device *dev, +struct drm_simple_display_pipe *pipe, +struct drm_simple_display_pipe_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +struct drm_connector *connector); +struct drm_connector * +drm_simple_kms_panel_connector_create (struct drm_device *dev, +struct drm_panel *panel, +int connector_type); + + + +#endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */ Signature · 1 line
2.2.2
Quoted 4 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC v2 3/8] drm: Add helper for simple kms drivers
Quoted 50 lines · Noralf Trønnes
Den 13.04.2016 13:05, skrev Daniel Vetter:
Quoted 5 lines · Noralf Trønnes
Quoted 4 lines
Provides helper functions for drivers that have a simple display pipeline. Plane, crtc and encoder are collapsed into one entity.
Signed-off-by Noralf Trønnes <[email protected]>[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +7
-0+static void drm_simple_kms_encoder_disable (struct drm_encoder *encoder) +{ +} + +static void drm_simple_kms_encoder_enable (struct drm_encoder *encoder) +{ +}Quoted 8 lines
drivers/gpu/drm/drm_simple_kms_helper.c line 133
Quoted 7 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +7
-0+ +static int drm_simple_kms_encoder_atomic_check (struct drm_encoder *encoder, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ +return 0 ; +}Above dummy functions shouldn't be necessary.
I could remove .atomic_check, but not .disable and .enable which gave me NULL pointer errors. I need .enable or .commit, and .disable or .dpms.
Gist:
void drm_atomic_helper_commit_modeset_enables(struct
drm_device*dev,
structdrm_atomic_state*old_state)
{
for_each_connector_in_state(old_state, connector, old_conn_state, i){ const struct drm_encoder_helper_funcs *funcs; funcs = encoder->helper_private; if (funcs->enable) funcs->enable(encoder); else funcs->commit(encoder);static void
disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state){
for_each_connector_in_state(old_state, connector, old_conn_state, i)
Quoted 11 lines
{
const struct drm_encoder_helper_funcs *funcs;
funcs = encoder->helper_private;
if (connector->state->crtc && funcs->prepare)
funcs->prepare(encoder);
else if (funcs->disable)
funcs->disable(encoder);
else
funcs->dpms(encoder, DRM_MODE_DPMS_OFF);Hm right. I'm voting that we make them all optional, there's been an effort all over the place to not force drivers to type in silly dummy funcs.
Quoted 178 lines
Quoted 150 lines
Quoted 150 lines
drivers/gpu/drm/drm_simple_kms_helper.c new file +129
-0+ +static const struct drm_encoder_helper_funcs drm_simple_kms_encoder_helper_funcs = { + .disable = drm_simple_kms_encoder_disable, + .enable = drm_simple_kms_encoder_enable, + .atomic_check = drm_simple_kms_encoder_atomic_check, +}; + +static const struct drm_encoder_funcs drm_simple_kms_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +static void drm_simple_kms_crtc_enable (struct drm_crtc *crtc) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); +if (!pipe->funcs || !pipe->funcs->enable) +return ; + + pipe->funcs->enable (pipe, crtc->state); +} + +static void drm_simple_kms_crtc_disable (struct drm_crtc *crtc) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(crtc, struct drm_simple_display_pipe, crtc); +if (!pipe->funcs || !pipe->funcs->disable) +return ; + + pipe->funcs->disable (pipe); +} + +static const struct drm_crtc_helper_funcs drm_simple_kms_crtc_helper_funcs = { + .disable = drm_simple_kms_crtc_disable, + .enable = drm_simple_kms_crtc_enable, +}; + +static const struct drm_crtc_funcs drm_simple_kms_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static void drm_simple_kms_plane_atomic_update (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); +if (!pipe->funcs || !pipe->funcs->plane_update) +return ; + + pipe->funcs->plane_update (pipe, old_state); +} + +static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { + .atomic_update = drm_simple_kms_plane_atomic_update, +}; + +static const struct drm_plane_funcs drm_simple_kms_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + .reset = drm_atomic_helper_plane_reset, + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, +}; + +/** +* drm_simple_display_pipe_init - Initialize a simple display pipe +* @dev: DRM device +* @pipe: simple display pipe object to initialize +* @funcs: callbacks for the display pipe +* @formats: array of supported formats (%DRM_FORMAT_*) +* @format_count: number of elements in @formats +* @connector: connector to attach and register +* +* Sets up a display pipe which consist of a really simple plane-crtc-encoder +* pipe coupled with the provided connector. +* +* Returns: +* Zero on success, error code on failure. +*/ +int drm_simple_display_pipe_init (struct drm_device *dev, +struct drm_simple_display_pipe *pipe, +struct drm_simple_display_pipe_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +struct drm_connector *connector) +{ +struct drm_encoder *encoder = &pipe->encoder; +struct drm_plane *plane = &pipe->plane; +struct drm_crtc *crtc = &pipe->crtc; +int ret; + + pipe->funcs = funcs; + +drm_plane_helper_add (plane, &drm_simple_kms_plane_helper_funcs); + ret =drm_universal_plane_init (dev, plane,0 , &drm_simple_kms_plane_funcs, + formats, format_count, +DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret) +return ret; + +drm_crtc_helper_add (crtc, &drm_simple_kms_crtc_helper_funcs); + ret =drm_crtc_init_with_planes (dev, crtc, plane,NULL , + &drm_simple_kms_crtc_funcs,NULL ); +if (ret) +return ret; + + encoder->possible_crtcs =1 <<drm_crtc_index (crtc); +drm_encoder_helper_add (encoder, &drm_simple_kms_encoder_helper_funcs); + ret =drm_encoder_init (dev, encoder, &drm_simple_kms_encoder_funcs, +DRM_MODE_ENCODER_NONE ,NULL ); +if (ret) +return ret; + + ret =drm_mode_connector_attach_encoder (connector, encoder); +if (ret) +return ret; + +return drm_connector_register (connector); +} +EXPORT_SYMBOL (drm_simple_display_pipe_init); + +MODULE_LICENSE ("GPL" );include/drm/drm_simple_kms_helper.h new file +15
-0@@ -0,0 +1,44 @@ +/* +* Copyright (C) 2016 Noralf Trønnes +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H +#define __LINUX_DRM_SIMPLE_KMS_HELPER_H + +struct drm_simple_display_pipe ; + +struct drm_simple_display_pipe_funcs {Quoted 8 lines
include/drm/drm_simple_kms_helper.h line 20
Quoted 5 lines
include/drm/drm_simple_kms_helper.h new file +5
-0+void (*enable)(struct drm_simple_display_pipe *pipe, +struct drm_crtc_state *crtc_state); +void (*disable)(struct drm_simple_display_pipe *pipe); +void (*plane_update)(struct drm_simple_display_pipe *pipe, +struct drm_plane_state *plane_state);On 2nd thought maybe we want an
atomic_checkin here too, with same parameters *pipe,*crtc_stateand*plane_state(so that it's useful for both plane-only updates and modeset changes).I could do this for the plane:
struct
drm_simple_display_pipe_funcs{
void (*plane_check)(structdrm_simple_display_pipe*pipe,
structdrm_plane_state*plane_state);
}static void drm_simple_kms_plane_atomic_check(struct
drm_plane*plane,
structdrm_plane_state*state){ struct drm_simple_display_pipe *pipe; pipe = container_of(plane, struct drm_simple_display_pipe, plane); if (!pipe->funcs || !pipe->funcs->plane_check) return; pipe->funcs->plane_check(pipe, state); }
Quoted 6 lines
static const struct
drm_plane_helper_funcsdrm_simple_kms_plane_helper_funcs= {
.atomic_check =drm_simple_kms_plane_atomic_check,
};But how should I do
crtc_state?
Atomic core guarantees that if you have a plane state, then the crtc state for that plane is always hanging around. You should be able to get at it (but only for atomic_check functions, there's a different way in the commit hooks) using:
drm_atomic_get_existing_plane_state(plane_state->state,
plane_state->crtc);
Yes I know I should get around to documeting all the structures we have ... Unfortunately it's a bit a mess and I'd like to clean up the code organization first a bit.
Cheers, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 4/8 drm: Add DRM support for tiny LCD displays
In reply to Noralf Trønnestinydrm provides a very simplified view of DRM for displays that has onboard video memory and is connected through a slow bus like SPI/I2C.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/tinydrm/Kconfig | 11 ++ drivers/gpu/drm/tinydrm/Makefile | 1 + drivers/gpu/drm/tinydrm/core/Makefile | 6 + drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 155 +++++++++++++++++++++ .../gpu/drm/tinydrm/core/tinydrm-display-pipe.c | 82 +++++++++++ drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c | 94 +++++++++++++ drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c | 99 +++++++++++++ drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 95 +++++++++++++ include/drm/tinydrm/tinydrm.h | 143 +++++++++++++++++++ 11 files changed, 689 insertions(+) create mode 100644 drivers/gpu/drm/tinydrm/Kconfig create mode 100644 drivers/gpu/drm/tinydrm/Makefile create mode 100644 drivers/gpu/drm/tinydrm/core/Makefile create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-core.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-display-pipe.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c create mode 100644 include/drm/tinydrm/tinydrm.h
drivers/gpu/drm/Kconfig +2 -0
@@ -276,3 +276,5 @@ source "drivers/gpu/drm/imx/Kconfig" source "drivers/gpu/drm/vc4/Kconfig" source "drivers/gpu/drm/etnaviv/Kconfig" + +source "drivers/gpu/drm/tinydrm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -75,3 +75,4 @@ obj-y += panel/ obj-y += bridge/ obj-$(CONFIG_DRM_FSL_DCU) += fsl-dcu/ obj-$(CONFIG_DRM_ETNAVIV) += etnaviv/ +obj-$(CONFIG_DRM_TINYDRM) += tinydrm/
drivers/gpu/drm/tinydrm/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +menuconfig DRM_TINYDRM + tristate "Support for small TFT LCD display modules" + depends on DRM + select DRM_SIMPLE_KMS_HELPER + select DRM_KMS_CMA_HELPER + select DRM_PANEL + select VIDEOMODE_HELPERS + select FB_DEFERRED_IO if DRM_KMS_FB_HELPER + help + Choose this option if you have a tinydrm supported display. + If M is selected the module will be called tinydrm.
drivers/gpu/drm/tinydrm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_DRM_TINYDRM) += core/
drivers/gpu/drm/tinydrm/core/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +obj-$(CONFIG_DRM_TINYDRM) += tinydrm.o +tinydrm-y += tinydrm-core.o +tinydrm-y += tinydrm-display-pipe.o +tinydrm-y += tinydrm-framebuffer.o +tinydrm-y += tinydrm-helpers.o +tinydrm-$(CONFIG_DRM_KMS_FB_HELPER) += tinydrm-fbdev.o
drivers/gpu/drm/tinydrm/core/tinydrm-core.c new file +155 -0
155 lines not on this page · raw message
drivers/gpu/drm/tinydrm/core/tinydrm-display-pipe.c new file +82 -0
82 lines not on this page · raw message
drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c new file +94 -0
94 lines not on this page · raw message
drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c new file +99 -0
99 lines not on this page · raw message
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c new file +95 -0
95 lines not on this page · raw message
include/drm/tinydrm/tinydrm.h new file +143 -0
143 lines not on this page · raw message
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 5/8 drm/tinydrm: Add lcd register abstraction
In reply to Noralf TrønnesAdd LCD register abstraction for MIPI DBI/DCS like controllers. This hides LCD controller interface implementation details. When built with debugfs, the register is available to userspace.
--- drivers/gpu/drm/tinydrm/Kconfig | 2 + drivers/gpu/drm/tinydrm/Makefile | 1 + drivers/gpu/drm/tinydrm/lcdreg/Kconfig | 3 + drivers/gpu/drm/tinydrm/lcdreg/Makefile | 3 + drivers/gpu/drm/tinydrm/lcdreg/internal.h | 8 + drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c | 190 ++++++++++++++++ drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c | 281 ++++++++++++++++++++++++ include/drm/tinydrm/lcdreg.h | 126 +++++++++++ 8 files changed, 614 insertions(+) create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/Kconfig create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/Makefile create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/internal.h create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c create mode 100644 include/drm/tinydrm/lcdreg.h
drivers/gpu/drm/tinydrm/Kconfig +2 -0
@@ -9,3 +9,5 @@ menuconfig DRM_TINYDRM help Choose this option if you have a tinydrm supported display. If M is selected the module will be called tinydrm. + +source "drivers/gpu/drm/tinydrm/lcdreg/Kconfig"
drivers/gpu/drm/tinydrm/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_DRM_TINYDRM) += core/ +obj-$(CONFIG_LCDREG) += lcdreg/
drivers/gpu/drm/tinydrm/lcdreg/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ +config LCDREG + tristate + depends on GPIOLIB || COMPILE_TEST
drivers/gpu/drm/tinydrm/lcdreg/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_LCDREG) += lcdreg.o +lcdreg-y += lcdreg-core.o +lcdreg-$(CONFIG_DEBUG_FS) += lcdreg-debugfs.o
drivers/gpu/drm/tinydrm/lcdreg/internal.h new file +8 -0
@@ -0,0 +1,8 @@ + +#ifdef CONFIG_DEBUG_FS +void lcdreg_debugfs_init (struct lcdreg *reg); +void lcdreg_debugfs_exit (struct lcdreg *reg); +#else +static inline void lcdreg_debugfs_init (struct lcdreg *reg) { } +static inline void lcdreg_debugfs_exit (struct lcdreg *reg) { } +#endif
drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c new file +190 -0
190 lines not on this page · raw message
drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c new file +281 -0
281 lines not on this page · raw message
include/drm/tinydrm/lcdreg.h new file +126 -0
126 lines not on this page · raw message
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 6/8 drm/tinydrm/lcdreg: Add SPI support
In reply to Noralf TrønnesAdd SPI bus support to lcdreg.
Supports the following protocols:
- MIPI DBI type C interface option 1 (3-wire) and option 3 (4-wire).
- Option 3 also fits some controllers where all registers are 16-bit.
- 8/16-bit register transfers that need to start with a special startbyte.
It also supports emulation for 16 and 9-bit words if the SPI controller doesn't support it.
--- drivers/gpu/drm/tinydrm/lcdreg/Kconfig | 5 + drivers/gpu/drm/tinydrm/lcdreg/Makefile | 2 + drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c | 720 ++++++++++++++++++++++++++++ include/drm/tinydrm/lcdreg-spi.h | 63 +++ 4 files changed, 790 insertions(+) create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c create mode 100644 include/drm/tinydrm/lcdreg-spi.h
drivers/gpu/drm/tinydrm/lcdreg/Kconfig +5 -0
@@ -1,3 +1,8 @@ config LCDREG tristate depends on GPIOLIB || COMPILE_TEST + +config LCDREG_SPI + tristate + depends on SPI + select LCDREG
drivers/gpu/drm/tinydrm/lcdreg/Makefile +2 -0
@@ -1,3 +1,5 @@ obj-$(CONFIG_LCDREG) += lcdreg.o lcdreg-y += lcdreg-core.o lcdreg-$(CONFIG_DEBUG_FS) += lcdreg-debugfs.o + +obj-$(CONFIG_LCDREG_SPI) += lcdreg-spi.o
drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c new file +720 -0
720 lines not on this page · raw message
include/drm/tinydrm/lcdreg-spi.h new file +63 -0
63 lines not on this page · raw message
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 7/8 drm/tinydrm: Add mipi-dbi support
In reply to Noralf TrønnesAdd support for MIPI DBI interfaced controllers.
--- drivers/gpu/drm/tinydrm/Kconfig | 3 + drivers/gpu/drm/tinydrm/Makefile | 3 + drivers/gpu/drm/tinydrm/mipi-dbi.c | 253 +++++++++++++++++++++++++++++++++++++ include/drm/tinydrm/mipi-dbi.h | 24 ++++ 4 files changed, 283 insertions(+) create mode 100644 drivers/gpu/drm/tinydrm/mipi-dbi.c create mode 100644 include/drm/tinydrm/mipi-dbi.h
drivers/gpu/drm/tinydrm/Kconfig +3 -0
@@ -10,4 +10,7 @@ menuconfig DRM_TINYDRM Choose this option if you have a tinydrm supported display. If M is selected the module will be called tinydrm. +config TINYDRM_MIPI_DBI + tristate + source "drivers/gpu/drm/tinydrm/lcdreg/Kconfig"
drivers/gpu/drm/tinydrm/Makefile +3 -0
@@ -1,2 +1,5 @@ obj-$(CONFIG_DRM_TINYDRM) += core/ obj-$(CONFIG_LCDREG) += lcdreg/ + +# Controllers +obj-$(CONFIG_TINYDRM_MIPI_DBI) += mipi-dbi.o
drivers/gpu/drm/tinydrm/mipi-dbi.c new file +253 -0
253 lines not on this page · raw message
include/drm/tinydrm/mipi-dbi.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* MIPI Display Bus Interface (DBI) LCD controller support +* +* Copyright 2016 Noralf Trønnes +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_MIPI_DBI_H +#define __LINUX_MIPI_DBI_H + +struct tinydrm_device ; +struct drm_panel ; +struct lcdreg ; + +int mipi_dbi_init (struct device *dev,struct tinydrm_device *tdev); +bool mipi_dbi_display_is_on (struct lcdreg *reg); +void mipi_dbi_debug_dump_regs (struct lcdreg *reg); +int mipi_dbi_panel_unprepare (struct drm_panel *panel); + +#endif /* __LINUX_MIPI_DBI_H */
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC v2 8/8 drm/tinydrm: Add support for several Adafruit TFT displays
In reply to Noralf TrønnesAdd support for Adafruit MIPI DBI compatible SPI displays:
2.8" PiTFT 320x240 TFT+Touchscreen for Raspberry Pi (#1601)
--- drivers/gpu/drm/tinydrm/Kconfig | 9 ++ drivers/gpu/drm/tinydrm/Makefile | 3 + drivers/gpu/drm/tinydrm/adafruit-tft.c | 257 +++++++++++++++++++++++++++++++++ include/drm/tinydrm/ili9340.h | 47 ++++++ 4 files changed, 316 insertions(+) create mode 100644 drivers/gpu/drm/tinydrm/adafruit-tft.c create mode 100644 include/drm/tinydrm/ili9340.h
drivers/gpu/drm/tinydrm/Kconfig +9 -0
@@ -13,4 +13,13 @@ menuconfig DRM_TINYDRM config TINYDRM_MIPI_DBI tristate +config TINYDRM_ADAFRUIT_TFT + tristate "DRM driver for Adafruit SPI TFT displays" + depends on DRM_TINYDRM && SPI + select LCDREG_SPI + select TINYDRM_MIPI_DBI + help + DRM driver for the following Adafruit displays: + 2.8" PiTFT 320x240 for Raspberry Pi - ILI9340 (#1601) + source "drivers/gpu/drm/tinydrm/lcdreg/Kconfig"
drivers/gpu/drm/tinydrm/Makefile +3 -0
@@ -3,3 +3,6 @@ obj-$(CONFIG_LCDREG) += lcdreg/ # Controllers obj-$(CONFIG_TINYDRM_MIPI_DBI) += mipi-dbi.o + +# Displays +obj-$(CONFIG_TINYDRM_ADAFRUIT_TFT) += adafruit-tft.o
drivers/gpu/drm/tinydrm/adafruit-tft.c new file +257 -0
257 lines not on this page · raw message
include/drm/tinydrm/ili9340.h new file +47 -0
47 lines not on this page · raw message
Signature · 6 lines
2.2.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 5 lines · Noralf Trønnes
This is an attempt at providing a DRM version of
drivers/staging/fbtft.I'm sending this early before cleaning up the code hoping to get some feedback in case there are better ways to structure this.
Quoted 8 lines
The tinydrm module provides a very simplified view of DRM for displays that has onboard video memory and is connected through a slow bus like SPI/I2C. A driver using tinydrm has to provide a function that will be called from the dirtyfb ioctl (or fbdev deferred io) and optional
drm_panelfunctions which can be used to set up the display controller and control backlight.Display controllers that have a similar register interface as the MIPI DBI/DCS controllers can use the lcdreg module for register access.
I like this a lot. For the panel stuff itself I think it'd be good to have comments from Thierry Redding too. Otherwise I'd say let's polish the def io and simple kms stuff and start get that merged meanwhile. -Daniel
Quoted 83 lines
Changes since RFC v1:
- Addfb_deferred_iosupport todrm_fb_helperanddrm_fb_cma_helper, and usedrm_fb_cma_helperinstead.
- Move display pipeline code todrm_simple_kms_helper.
- Don't use (structdrm_driver*)->load().
- Make tinydrm more like a library, exporting the internals.
- Move the structdrm_driverdefinition from the tinydrm module to the driver using a helper macro:TINYDRM_DRM_DRIVER.
- Removedirtyfb()async code.
- Added support for partial display updates.Noralf Trønnes (8):
drm/fb-helper: Addfb_deferred_iosupport drm/fb-cma-helper: Addfb_deferred_iosupport
drm: Add helper for simple kms drivers
drm: Add DRM support for tiny LCD displays drm/tinydrm: Add lcd register abstraction drm/tinydrm/lcdreg: Add SPI support
drm/tinydrm: Add mipi-dbi support
drm/tinydrm: Add support for several Adafruit TFT displaysdrivers/gpu/drm/Kconfig | 9 + drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_fb_cma_helper.c | 149 ++++- drivers/gpu/drm/drm_fb_helper.c | 189 +++++- drivers/gpu/drm/drm_simple_kms_helper.c | 262 ++++++++ drivers/gpu/drm/tinydrm/Kconfig | 25 + drivers/gpu/drm/tinydrm/Makefile | 8 + drivers/gpu/drm/tinydrm/adafruit-tft.c | 257 ++++++++ drivers/gpu/drm/tinydrm/core/Makefile | 6 + drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 155 +++++ .../gpu/drm/tinydrm/core/tinydrm-display-pipe.c | 82 +++ drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c | 94 +++ drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c | 99 +++ drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 95 +++ drivers/gpu/drm/tinydrm/lcdreg/Kconfig | 8 + drivers/gpu/drm/tinydrm/lcdreg/Makefile | 5 + drivers/gpu/drm/tinydrm/lcdreg/internal.h | 8 + drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c | 190 ++++++ drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c | 281 ++++++++ drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c | 720 +++++++++++++++++++++ drivers/gpu/drm/tinydrm/mipi-dbi.c | 253 ++++++++ include/drm/drm_fb_cma_helper.h | 14 + include/drm/drm_fb_helper.h | 15 + include/drm/drm_simple_kms_helper.h | 44 ++ include/drm/tinydrm/ili9340.h | 47 ++ include/drm/tinydrm/lcdreg-spi.h | 63 ++ include/drm/tinydrm/lcdreg.h | 126 ++++ include/drm/tinydrm/mipi-dbi.h | 24 + include/drm/tinydrm/tinydrm.h | 143 ++++ 29 files changed, 3360 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/drm/drm_simple_kms_helper.c create mode 100644 drivers/gpu/drm/tinydrm/Kconfig create mode 100644 drivers/gpu/drm/tinydrm/Makefile create mode 100644 drivers/gpu/drm/tinydrm/adafruit-tft.c create mode 100644 drivers/gpu/drm/tinydrm/core/Makefile create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-core.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-display-pipe.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-fbdev.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-framebuffer.c create mode 100644 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/Kconfig create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/Makefile create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/internal.h create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-core.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-debugfs.c create mode 100644 drivers/gpu/drm/tinydrm/lcdreg/lcdreg-spi.c create mode 100644 drivers/gpu/drm/tinydrm/mipi-dbi.c create mode 100644 include/drm/drm_simple_kms_helper.h create mode 100644 include/drm/tinydrm/ili9340.h create mode 100644 include/drm/tinydrm/lcdreg-spi.h create mode 100644 include/drm/tinydrm/lcdreg.h create mode 100644 include/drm/tinydrm/mipi-dbi.h create mode 100644 include/drm/tinydrm/tinydrm.h--
2.2.2_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel