DRM driver for fbdev devices
Subsystems (3)
Thomas Zimmermann
maintainercover DRM driver for fbdev devices
Hi,
this RFC patch set implements fbdevdrm, a DRM driver on top of fbdev drivers. I'd appreciate feedback on the code and the idea in general.
The fbdev subsystem is considered legacy and will probably be removed at some point. This would mean the loss of a signifanct number of drivers. Some of the affected hardware is probably not in use any longer, but some hardware is still around and provides good(-enough) framebuffers.
OTOH, userspace programs that want to support a wide range of graphics hardware have to implement support for both DRM and fbdev interfaces. Such software would benefit from a single interface.
The fbdevdrm driver provides a way of running drivers for old and new hardware from the DRM subsystem and interfaces.
It's not intended to add new features or drivers to fbdev. Instead fbdevdrm is supposed to be a template for converting fbdev drivers to DRM. It contains a number of comments (labeled 'DRM porting note') that explain the required steps. The license is fairly liberal to allow for combination with existing fbdev code.
I tested the current patch set with the following drivers: atyfb, aty128fb, matroxfb, pm2fb, s3fb, savagefb, sisfb, tdfxfb and tridentfb. I was able to successfully start with fbcon enabled and then run weston or X.
Thomas Zimmermann (11):
drm/fbdevdrm: Add driver skeleton drm/fbdevdrm: Add fbdevdrm device drm/fbdevdrm: Add memory management drm/fbdevdrm: Add file operations drm/fbdevdrm: Add GEM and dumb interfaces drm/fbdevdrm: Add modesetting infrastructure drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion drm/fbdevdrm: Add mode conversion DRM <-> fbdev drm/fbdevdrm: Add primary plane
drm/fbdevdrm: Add CRTC
drm/fbdevdrm: Detect and validate display modes
drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 + drivers/gpu/drm/fbdevdrm/Makefile | 11 + drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 ++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 96 +++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 55 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 347 +++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 ++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 195 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 53 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 746 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 38 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 +++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 + 19 files changed, 3120 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h
--
2.21.0
Thomas Zimmermann
maintainerPATCH 1/11 drm/fbdevdrm: Add driver skeleton
The fbdevdrm driver runs DRM on top of fbdev framebuffer drivers. It allows for using legacy drivers with modern userspace and gives a template for converting fbdev drivers to DRM.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 +++++ drivers/gpu/drm/fbdevdrm/Makefile | 4 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 72 +++++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c
drivers/gpu/drm/Kconfig +2 -0
@@ -337,6 +337,8 @@ source "drivers/gpu/drm/xen/Kconfig" source "drivers/gpu/drm/vboxvideo/Kconfig" +source "drivers/gpu/drm/fbdevdrm/Kconfig" + # Keep legacy drivers last menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
@@ -111,3 +111,4 @@ obj-$(CONFIG_DRM_PL111) += pl111/ obj-$(CONFIG_DRM_TVE200) += tve200/ obj-$(CONFIG_DRM_XEN) += xen/ obj-$(CONFIG_DRM_VBOXVIDEO) += vboxvideo/ +obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm/
drivers/gpu/drm/fbdevdrm/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +config DRM_FBDEVDRM + tristate "DRM over FBDEV" + depends on DRM && PCI && AGP + select FB_NOTIFY + select FB_SYS_FILLRECT + select FB_SYS_COPYAREA + select FB_SYS_IMAGEBLIT + select DRM_KMS_HELPER + select DRM_KMS_FB_HELPER + select DRM_TTM + help + Choose this option to use fbdev video drivers within DRM. + If M is selected the module will be called fbdevdrm.
drivers/gpu/drm/fbdevdrm/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +ccflags-y = -Iinclude/drm +fbdevdrm-y := fbdevdrm_drv.o + +obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 2/11 drm/fbdevdrm: Add fbdevdrm device
In reply to Thomas ZimmermannThere's an fbdevdrm device for each supported fbdev device. The fbdevdrm driver listens for fb events, and creates and destroys fbdevdrm devices accordingly.
Only hardware-specific fbdev drivers are supported. Generic drivers, such as vga16fb or vesafb are not handled. DRM-based fbdev drivers are also not supported. This prevents the situation where a DRM drivers enables framebuffer emulation and fbdevdrm creates a second DRM device for the same hardware.
--- drivers/gpu/drm/fbdevdrm/Makefile | 3 +- drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 79 ++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 44 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 173 ++++++++++++++++++++- 4 files changed, 296 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h
drivers/gpu/drm/fbdevdrm/Makefile +2 -1
@@ -1,4 +1,5 @@ ccflags-y = -Iinclude/drm -fbdevdrm-y := fbdevdrm_drv.o +fbdevdrm-y := fbdevdrm_device.o \ + fbdevdrm_drv.o obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c new file +79 -0
79 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h new file +44 -0
44 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +170 -2
209 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 02/11] drm/fbdevdrm: Add fbdevdrm device
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c line 105
Quoted 13 lines · Thomas Zimmermann
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +13
-0+static bool is_generic_driver (const struct fb_info *fb_info) +{ +/* DRM porting note: We don't want to bind to vga16fb, vesafb, or any +* other generic fbdev driver. Usually, these drivers have limited +* capabilitis. We only continue if the fix structure indicates a +* hardware-specific drivers . This test will also sort out drivers +* registered via DRM's fbdev emulation. If you're porting an fbdev +* driver to DRM, you can remove this test. The module's PCI device +* ids will contain this information. +*/ +return !fb_info->fix.accel && + !!strcmp (fb_info->fix.id,"S3 Virge/DX" ); +}
This seems odd. s3fb sets fix.accel to NULL unconditionally AFAICT, not sure why you're testing for that explicitly.
I do have a question though: why _not_ support generic fbdev drivers? If I had that, and the ability to disable creation of /dev/fb*, I could expose a consistent video device enumeration to userspace. As it stands I have no reasonable way of knowing which fbdev and drm devices are pointed at the same hardware. If there were only drm devices...
- ajax
Thomas Zimmermann
maintainerRe: [PATCH 02/11] drm/fbdevdrm: Add fbdevdrm device
Hi
Am 26.03.19 um 17:03 schrieb Adam Jackson:
Quoted 18 lines · Thomas Zimmermann
Quoted 4 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +3
-0+static bool is_generic_driver (const struct fb_info *fb_info) +{ +/* DRM porting note: We don't want to bind to vga16fb, vesafb, or any drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c line 105
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +10
-0+* other generic fbdev driver. Usually, these drivers have limited +* capabilitis. We only continue if the fix structure indicates a +* hardware-specific drivers . This test will also sort out drivers +* registered via DRM's fbdev emulation. If you're porting an fbdev +* driver to DRM, you can remove this test. The module's PCI device +* ids will contain this information. +*/ +return !fb_info->fix.accel && + !!strcmp (fb_info->fix.id,"S3 Virge/DX" ); +}This seems odd. s3fb sets fix.accel to NULL unconditionally AFAICT, not sure why you're testing for that explicitly.
If accel is 0, it might be a generic driver. Hence, fbdevdrm ignored s3fb, so I added the exception.
Quoted 5 lines
I do have a question though: why _not_ support generic fbdev drivers? If I had that, and the ability to disable creation of
/dev/fb*, I could expose a consistent video device enumeration to userspace. As it stands I have no reasonable way of knowing which fbdev and drm devices are pointed at the same hardware. If there were only drm devices...
Ignoring generic drivers seemed like the safe bet for now. I found that vga16fb, vesafb, etc bind to hardware and later get replaced by HW-specific drivers; DRM drivers with FB emulation should not be handled by fbdevdrm. So for now, fbdevdrm ignores all this.
This all comes from using the event-reporting mechanism to hook into the fbdev module. Daniel suggested to copy over some of the fbdev drivers for porting, which would solve the problem.
Best regards
Thomas
Quoted 3 lines
- ajax
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Re: [PATCH 02/11] drm/fbdevdrm: Add fbdevdrm device
Quoted 3 lines · Thomas Zimmermann
This all comes from using the event-reporting mechanism to hook into the fbdev module. Daniel suggested to copy over some of the fbdev drivers for porting, which would solve the problem.
On the fbdev event reporting stuff: I have a patch series to remove that, and replace the fbdev->fbcon interactions with direct function calls. The locking in the notifier is a serious pain. I guess that would be another detail we'd need to change, if we go with this approach here.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Thomas Zimmermann
maintainerPATCH 3/11 drm/fbdevdrm: Add memory management
In reply to Thomas ZimmermannMemory management in fbdevdrm is provided by TTM. Fbdev implements page flipping via display pan operations, which require scanout buffers to be aligned at scanline boundaries. At the same time memory-mapping operations of individual buffers requires page alignment of each buffer. Fbdevdrm ensures that both requirements are met.
--- drivers/gpu/drm/fbdevdrm/Makefile | 6 +- drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 +++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 10 + drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 9 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 +++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 +++ 7 files changed, 594 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h
drivers/gpu/drm/fbdevdrm/Makefile +4 -2
@@ -1,5 +1,7 @@ ccflags-y = -Iinclude/drm -fbdevdrm-y := fbdevdrm_device.o \ - fbdevdrm_drv.o +fbdevdrm-y := fbdevdrm_bo.o \ + fbdevdrm_device.o \ + fbdevdrm_drv.o \ + fbdevdrm_ttm.o obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c new file +276 -0
276 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h new file +58 -0
58 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c +10 -0
@@ -33,9 +33,17 @@ int fbdevdrm_device_init(struct fbdevdrm_device *fdev, struct drm_driver *drv, fdev->dev.pdev = container_of(fb_info->device, struct pci_dev, dev); fdev->fb_info = fb_info; + ret =fbdevdrm_ttm_init (&fdev->ttm, &fdev->dev, fb_info); +if (ret) + goto err_drm_dev_fini; +INIT_LIST_HEAD (&fdev->device_list);return 0 ; + +err_drm_dev_fini: +drm_dev_fini (&fdev->dev); +return ret; }void fbdevdrm_device_cleanup (struct fbdevdrm_device *fdev)
@@ -47,6 +55,8 @@ void fbdevdrm_device_cleanup(struct fbdevdrm_device *fdev) "in device list\n"); } +fbdevdrm_ttm_cleanup (&fdev->ttm); +drm_dev_fini (dev); dev->dev_private =NULL ; }
drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h +9 -0
@@ -16,6 +16,7 @@#include <drm/drm_device.h> #include <linux/kernel.h> #include <linux/list.h> +#include "fbdevdrm_ttm.h" struct drm_driver ;struct fb_info ;
@@ -24,6 +25,8 @@ struct fbdevdrm_device {struct drm_device dev;struct fb_info *fb_info; +struct fbdevdrm_ttm ttm; +struct list_head device_list;/* entry in global device list */ };
@@ -33,6 +36,12 @@ static inline struct fbdevdrm_device* fbdevdrm_device_of_device_list( return list_entry(device_list, struct fbdevdrm_device, device_list); } +static inline struct fbdevdrm_device *fbdevdrm_device_of_dev ( +struct drm_device *dev) +{ + return container_of(dev, struct fbdevdrm_device, dev); +} +int fbdevdrm_device_init (struct fbdevdrm_device *fdev,struct drm_driver *drv,struct fb_info *fb_info);void fbdevdrm_device_cleanup (struct fbdevdrm_device *fdev);
drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c new file +202 -0
202 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_TTM_H +#define FBDEVDRM_TTM_H + +#include <drm/ttm/ttm_bo_driver.h> + +#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT) + +struct drm_device ; +struct fb_info ; + +struct fbdevdrm_ttm { +struct drm_device *dev; +struct fb_info *fb_info; + +size_t vram_size; +struct ttm_bo_device bdev; +}; + +int fbdevdrm_ttm_init (struct fbdevdrm_ttm *ttm,struct drm_device *dev, +struct fb_info *fb_info); +void fbdevdrm_ttm_cleanup (struct fbdevdrm_ttm *ttm); + +#endif
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 4/11 drm/fbdevdrm: Add file operations
In reply to Thomas Zimmermann--- drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +28 -1
@@ -11,6 +11,8 @@*/ #include <drm/drm_drv.h> +#include <drm/drm_file.h> +#include <drm/drm_ioctl.h> #include <drm/drm_print.h> #include <linux/console.h> /* for console_{un/lock}() */ #include <linux/fb.h>
@@ -38,6 +40,30 @@* DRM driver */ +static int driver_fops_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct drm_file *file_priv = filp->private_data; +struct fbdevdrm_device *fdev = file_priv->minor->dev->dev_private; + +if (unlikely (vma->vm_pgoff <DRM_FILE_PAGE_OFFSET )) +return -EINVAL ; + +return ttm_bo_mmap (filp, vma, &fdev->ttm.bdev); +} + +static const struct file_operations driver_fops = { + .owner =THIS_MODULE , + .open = drm_open, + .release = drm_release, + .unlocked_ioctl = drm_ioctl, + .mmap = driver_fops_mmap, + .poll = drm_poll, +#ifdef CONFIG_COMPAT + .compat_ioctl = drm_compat_ioctl, +#endif + .read = drm_read +}; +static struct drm_driver fbdevdrm_drv = {/* data fields */ .major =DRIVER_MAJOR ,
@@ -45,7 +71,8 @@ static struct drm_driver fbdevdrm_drv = { .patchlevel = DRIVER_PATCHLEVEL, .name = DRIVER_NAME, .desc = DRIVER_DESCRIPTION, - .date = DRIVER_DATE + .date = DRIVER_DATE, + .fops = &driver_fops };/* Device list */
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 5/11 drm/fbdevdrm: Add GEM and dumb interfaces
In reply to Thomas Zimmermann--- drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 77 +++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +77 -0
@@ -18,6 +18,7 @@#include <linux/fb.h> #include <linux/module.h> #include <linux/mutex.h> +#include "fbdevdrm_bo.h" #include "fbdevdrm_device.h" /* DRM porting note: Here are some general information about the driver,
@@ -64,7 +65,82 @@ static const struct file_operations driver_fops = { .read = drm_read }; +static void driver_gem_free_object (struct drm_gem_object *gobj) +{ +struct fbdevdrm_bo *fbo =fbdevdrm_bo_of_gem (gobj); +fbdevdrm_bo_put (fbo); +} + +static int driver_dumb_create (struct drm_file *file_priv, +struct drm_device *dev, +struct drm_mode_create_dumb *args) +{ +int ret; +struct fbdevdrm_bo *fbo; +u32 size, handle; + + args->pitch = args->width * ((args->bpp +7 ) /8 ); + args->size = args->pitch * args->height; + + size =roundup (args->size,PAGE_SIZE ); +if (!size) +return -EINVAL ; + +/* DRM porting note: FBdev aligns scanout buffers to multiples +* of the scanline size in bytes. TTM aligns buffers to page +* boundaries. To maintain FBdev buffers with TTM, we align BOs +* at both, the scanline offsets and the page offsets. Depending +* on resolution and color depth, this may result in some memory +* overhead. After porting an FBdev driver to DRM, you can remove +* this constrain and simply align to page boundaries. +*/ + fbo =fbdevdrm_bo_create_with_pitch (dev, size, args->pitch,0 ); +if (IS_ERR (fbo)) { + ret =PTR_ERR (fbo); +if (ret != -ERESTARTSYS ) +DRM_ERROR ("fbdevdrm: fbdevdrm_bo_create_with_pitch() " +"failed, error %d\n" , -ret); +return ret; + } + + ret =drm_gem_handle_create (file_priv, &fbo->gem, &handle); +drm_gem_object_put_unlocked (&fbo->gem);/* TODO: verify ref-count */ +if (ret <0 ) + goto err_fbdevdrm_bo_put; + + args->handle = handle; + +return 0 ; + +err_fbdevdrm_bo_put: +fbdevdrm_bo_put (fbo); +return ret; +} + +static int driver_dumb_mmap_offset (struct drm_file *file_priv, +struct drm_device *dev,uint32_t handle, +uint64_t *offset) +{ +struct drm_gem_object *obj; +struct fbdevdrm_bo *fbo; + + obj =drm_gem_object_lookup (file_priv, handle); +if (obj =NULL ) +return -ENOENT ; + + fbo =fbdevdrm_bo_of_gem (obj); + *offset =fbdevdrm_bo_mmap_offset (fbo); + +drm_gem_object_put_unlocked (obj); +return 0 ; +} +static struct drm_driver fbdevdrm_drv = { +/* GEM interfaces */ + .gem_free_object = driver_gem_free_object, +/* Dumb interfaces */ + .dumb_create = driver_dumb_create, + .dumb_map_offset = driver_dumb_mmap_offset,/* data fields */ .major =DRIVER_MAJOR , .minor =DRIVER_MINOR ,
@@ -72,6 +148,7 @@ static struct drm_driver fbdevdrm_drv = { .name = DRIVER_NAME, .desc = DRIVER_DESCRIPTION, .date = DRIVER_DATE, + .driver_features = DRIVER_GEM, .fops = &driver_fops };
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 6/11 drm/fbdevdrm: Add modesetting infrastructure
In reply to Thomas ZimmermannModesetting for fbdevdrm supports a single display pipeline with CRTC, primary plane, encoder and connector.
The fbdev device would have been an ideal candidate for using |struct drm_simple_display_pipe|. To better illustrate the conversion from fbdev to DRM drivers, fbdevdrm used the regular DRM data structures instead.
--- drivers/gpu/drm/fbdevdrm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 7 + drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 2 + drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 4 +- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 430 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 36 ++ 6 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h
drivers/gpu/drm/fbdevdrm/Makefile +1 -0
@@ -2,6 +2,7 @@ ccflags-y = -Iinclude/drm fbdevdrm-y := fbdevdrm_bo.o \ fbdevdrm_device.o \ fbdevdrm_drv.o \ + fbdevdrm_modeset.o \ fbdevdrm_ttm.o obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c +7 -0
@@ -37,10 +37,16 @@ int fbdevdrm_device_init(struct fbdevdrm_device *fdev, struct drm_driver *drv,if (ret) goto err_drm_dev_fini; + ret =fbdevdrm_modeset_init (&fdev->modeset, &fdev->dev, fb_info); +if (ret) + goto err_fbdevdrm_ttm_cleanup; +INIT_LIST_HEAD (&fdev->device_list);return 0 ; +err_fbdevdrm_ttm_cleanup: +fbdevdrm_ttm_cleanup (&fdev->ttm); err_drm_dev_fini:drm_dev_fini (&fdev->dev);return ret;
@@ -55,6 +61,7 @@ void fbdevdrm_device_cleanup(struct fbdevdrm_device *fdev) "in device list\n"); } +fbdevdrm_modeset_cleanup (&fdev->modeset);fbdevdrm_ttm_cleanup (&fdev->ttm);drm_dev_fini (dev);
drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h +2 -0
@@ -16,6 +16,7 @@#include <drm/drm_device.h> #include <linux/kernel.h> #include <linux/list.h> +#include "fbdevdrm_modeset.h" #include "fbdevdrm_ttm.h" struct drm_driver ;
@@ -26,6 +27,7 @@ struct fbdevdrm_device {struct fb_info *fb_info;struct fbdevdrm_ttm ttm; +struct fbdevdrm_modeset modeset;struct list_head device_list;/* entry in global device list */ };
drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c +3 -1
@@ -148,7 +148,9 @@ static struct drm_driver fbdevdrm_drv = { .name = DRIVER_NAME, .desc = DRIVER_DESCRIPTION, .date = DRIVER_DATE, - .driver_features = DRIVER_GEM, + .driver_features =DRIVER_ATOMIC | +DRIVER_GEM | + DRIVER_MODESET, .fops = &driver_fops };
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c new file +429 -0
429 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_MODESET_H +#define FBDEVDRM_MODESET_H + +#include <drm/drm_connector.h> +#include <drm/drm_crtc.h> +#include <drm/drm_encoder.h> + +struct drm_device ; +struct fb_info ; + +struct fbdevdrm_modeset { +struct drm_crtc crtc; +struct drm_encoder encoder; +struct drm_connector connector; + +struct drm_device *dev; +struct fb_info *fb_info; +}; + +int fbdevdrm_modeset_init (struct fbdevdrm_modeset *modeset, +struct drm_device *dev,struct fb_info *fb_info); +void fbdevdrm_modeset_cleanup (struct fbdevdrm_modeset *modeset); + +#endif
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 7/11 drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion
In reply to Thomas Zimmermann--- drivers/gpu/drm/fbdevdrm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 +++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 ++ 3 files changed, 468 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h
drivers/gpu/drm/fbdevdrm/Makefile +1 -0
@@ -2,6 +2,7 @@ ccflags-y = -Iinclude/drm fbdevdrm-y := fbdevdrm_bo.o \ fbdevdrm_device.o \ fbdevdrm_drv.o \ + fbdevdrm_format.o \ fbdevdrm_modeset.o \ fbdevdrm_ttm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +441 -0
441 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_FORMAT_H +#define FBDEVDRM_FORMAT_H + +#include <drm/drm_fourcc.h> + +struct fb_info ; +struct fb_var_screeninfo ; + +uint32_t fbdevdrm_format_of_fb_info (const struct fb_info *fb_info); + +int fbdevdrm_update_fb_var_screeninfo_from_format ( +struct fb_var_screeninfo *fb_var,uint32_t format); + +#endif
Signature · 1 line
2.21.0
Re: [PATCH 07/11] drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion
Quoted 58 lines · Thomas Zimmermann
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/fbdevdrm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 +++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 ++ 3 files changed, 468 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.hdrivers/gpu/drm/fbdevdrm/Makefile +1
-0@@ -2,6 +2,7 @@ ccflags-y = -Iinclude/drm fbdevdrm-y := fbdevdrm_bo.o \ fbdevdrm_device.o \ fbdevdrm_drv.o \ + fbdevdrm_format.o \ fbdevdrm_modeset.o \ fbdevdrm_ttm.odrivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +31
-0@@ -0,0 +1,441 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#include "fbdevdrm_format.h" +#include <asm/byteorder.h> +#include <linux/fb.h> + +#if defined __BIG_ENDIAN +#define HOST_FUNC (_func) \ + _func ## _be +#elif defined __LITTLE_ENDIAN +#define HOST_FUNC (_func) \ + _func ## _le +#else +#error "Unsupported endianess" +#endif + +static bool is_c8 (const struct fb_info * fb_info) +{ +return fb_info->var.bits_per_pixel =8 ; +} +
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c line 41
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +10
-0+static bool is_rgb565_be (const struct fb_info * fb_info) +{ +return (fb_info->var.bits_per_pixel =16 ) && + (fb_info->var.red.offset =0 ) && + (fb_info->var.red.length =5 ) && + (fb_info->var.green.offset =5 ) && + (fb_info->var.green.length =6 ) && + (fb_info->var.blue.offset =11 ) && + (fb_info->var.blue.length =5 ); +}
You can't distinguish LE vs. BE like this.
Maybe FBINFO_FOREIGN_ENDIAN is trustworthy?
Signature · 2 lines
Ville Syrjälä Intel
Thomas Zimmermann
maintainerRe: [PATCH 07/11] drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion
Hi
Am 26.03.19 um 17:29 schrieb Ville Syrjälä:
Quoted 19 lines
Quoted 6 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +6
-0+ +static bool is_c8 (const struct fb_info * fb_info) +{ +return fb_info->var.bits_per_pixel ==8 ; +} +drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c line 41
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +10
-0+static bool is_rgb565_be (const struct fb_info * fb_info) +{ +return (fb_info->var.bits_per_pixel ==16 ) && + (fb_info->var.red.offset ==0 ) && + (fb_info->var.red.length ==5 ) && + (fb_info->var.green.offset ==5 ) && + (fb_info->var.green.length ==6 ) && + (fb_info->var.blue.offset ==11 ) && + (fb_info->var.blue.length ==5 ); +}You can't distinguish LE vs. BE like this.
Quoted 2 lines
Maybe
FBINFO_FOREIGN_ENDIANis trustworthy?
The test function means 'is the framebuffer in RGB565 format if the host uses big-endian access'. Further below in the file, there are macros that reverse the order of fields for little-endian hosts.
However, mapping all this to DRM formats is confusing.
According to the documentation, DRM_FORMAT_ is always in little-endian format. But does that mean that the device uses little endian or that the host uses little endian? If the device and the host disagree on endianess, which takes precedence?
In the end, I tried different combinations of tests and DRM formats, and checked the resulting output on the screen.
Best regards
Thomas
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Re: [PATCH 07/11] drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion
Quoted 22 lines · Thomas Zimmermann
Hi
Am 26.03.19 um 17:29 schrieb Ville Syrjälä:
Quoted 19 lines
Quoted 6 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +6
-0+ +static bool is_c8 (const struct fb_info * fb_info) +{ +return fb_info->var.bits_per_pixel =8 ; +} +drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c line 41
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c new file +10
-0+static bool is_rgb565_be (const struct fb_info * fb_info) +{ +return (fb_info->var.bits_per_pixel =16 ) && + (fb_info->var.red.offset =0 ) && + (fb_info->var.red.length =5 ) && + (fb_info->var.green.offset =5 ) && + (fb_info->var.green.length =6 ) && + (fb_info->var.blue.offset =11 ) && + (fb_info->var.blue.length =5 ); +}You can't distinguish LE vs. BE like this.
Quoted 6 lines
Quoted 2 lines
Maybe
FBINFO_FOREIGN_ENDIANis trustworthy?The test function means 'is the framebuffer in RGB565 format if the host uses big-endian access'. Further below in the file, there are macros that reverse the order of fields for little-endian hosts.
And that does not work. Wrong endianness swaps bytes, not components.
Quoted 7 lines
However, mapping all this to DRM formats is confusing.
According to the documentation,
DRM_FORMAT_is always in little-endian format. But does that mean that the device uses little endian or that the host uses little endian? If the device and the host disagree on endianess, which takes precedence?
It just means "the pixel value listed is stored in memory least significant byte first".
Quoted 3 lines
In the end, I tried different combinations of tests and DRM formats, and checked the resulting output on the screen.
This was just pointed out to me recently:
https://github.com/afrantzis/pixel-format-guide
It seems to interpret drm formats correctly.
Though I wouldn't mind if someone improved the drm_fourcc.h docs since everyone except me seems to get confused by the current wording.
Signature · 2 lines
Ville Syrjälä Intel
Thomas Zimmermann
maintainerPATCH 8/11 drm/fbdevdrm: Add mode conversion DRM <-> fbdev
In reply to Thomas Zimmermann--- drivers/gpu/drm/fbdevdrm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 153 ++++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 46 +++++++ 3 files changed, 200 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h
drivers/gpu/drm/fbdevdrm/Makefile +1 -0
@@ -3,6 +3,7 @@ fbdevdrm-y := fbdevdrm_bo.o \ fbdevdrm_device.o \ fbdevdrm_drv.o \ fbdevdrm_format.o \ + fbdevdrm_modes.o \ fbdevdrm_modeset.o \ fbdevdrm_ttm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c new file +153 -0
153 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 9/11 drm/fbdevdrm: Add primary plane
In reply to Thomas Zimmermann--- drivers/gpu/drm/fbdevdrm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 42 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 7 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 9 +- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 2 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 ++ 7 files changed, 585 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h
drivers/gpu/drm/fbdevdrm/Makefile +1 -0
@@ -5,6 +5,7 @@ fbdevdrm-y := fbdevdrm_bo.o \ fbdevdrm_format.o \ fbdevdrm_modes.o \ fbdevdrm_modeset.o \ + fbdevdrm_primary.o \ fbdevdrm_ttm.o obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm.o
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +42 -0
53 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h +7 -0
@@ -13,8 +13,11 @@#ifndef FBDEVDRM_MODES_H #define FBDEVDRM_MODES_H +#include <linux/types.h> +struct drm_device ;struct drm_display_mode ; +struct drm_framebuffer ;struct fb_videomode ;struct fb_var_screeninfo ;
@@ -43,4 +46,8 @@ void fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var, const struct drm_display_mode *mode); +int fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( +struct fb_var_screeninfo *fb_var,struct drm_framebuffer *fb, +size_t vram_size); +#endif
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +8 -1
@@ -20,6 +20,7 @@#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_primary.h" /* * CRTC
@@ -376,7 +377,13 @@ int fbdevdrm_modeset_init(struct fbdevdrm_modeset *modeset,* connect them with each other. */ - ret =drm_crtc_init_with_planes (dev, &modeset->crtc,NULL ,NULL , + ret =fbdevdrm_init_primary_plane_from_fb_info ( + &modeset->primary_plane, dev,0 , fb_info); +if (ret) + goto err_drm_mode_config_cleanup; + + ret =drm_crtc_init_with_planes (dev, &modeset->crtc, + &modeset->primary_plane,NULL , &fbdevdrm_crtc_funcs,NULL );if (ret) goto err_drm_mode_config_cleanup;
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h +2 -0
@@ -16,11 +16,13 @@#include <drm/drm_connector.h> #include <drm/drm_crtc.h> #include <drm/drm_encoder.h> +#include <drm/drm_plane.h> struct drm_device ;struct fb_info ;struct fbdevdrm_modeset { +struct drm_plane primary_plane;struct drm_crtc crtc;struct drm_encoder encoder;struct drm_connector connector;
drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c new file +498 -0
498 lines not on this page · raw message
drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_PRIMARY_H +#define FBDEVDRM_PRIMARY_H + +#include <linux/types.h> + +struct drm_device ; +struct drm_plane ; +struct fb_info ; + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info); + +#endif
Signature · 1 line
2.21.0
Re: [PATCH 09/11] drm/fbdevdrm: Add primary plane
Quoted 54 lines · Thomas Zimmermann
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/fbdevdrm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 42 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 7 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 9 +- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 2 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 ++ 7 files changed, 585 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.hdrivers/gpu/drm/fbdevdrm/Makefile +1
-0@@ -5,6 +5,7 @@ fbdevdrm-y := fbdevdrm_bo.o \ fbdevdrm_format.o \ fbdevdrm_modes.o \ fbdevdrm_modeset.o \ + fbdevdrm_primary.o \ fbdevdrm_ttm.o obj-$(CONFIG_DRM_FBDEVDRM) += fbdevdrm.odrivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +11
-0@@ -11,8 +11,12 @@*/ #include "fbdevdrm_modes.h" +#include <drm/drm.h> +#include <linux/sched.h> /* for TASK_COMM_LEN in <drm/drm_framebuffer.h> */ +#include <drm/drm_framebuffer.h> #include <drm/drm_modes.h> #include <linux/fb.h> +#include "fbdevdrm_format.h" void drm_mode_update_from_fb_videomode (struct drm_display_mode *mode,const struct fb_videomode *fb_mode)@@ -151,3 +155,41 @@ fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *fb_var,memset (fb_var,0 ,sizeof (*fb_var));fbdevdrm_update_fb_var_screeninfo_from_mode (fb_var, mode); } + +int fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( +struct fb_var_screeninfo *fb_var,struct drm_framebuffer *fb, +size_t vram_size) +{ +unsigned int width, pitch; +uint64_t cpp, lines;
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *fb_var, · line 174
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +10
-0+int ret; + +/* Our virtual screen covers all the graphics memory (sans some +* trailing bytes). This allows for setting the scanout buffer's +* address with fb_pan_display(). +*/ + + width = fb->pitches[0 ]; + cpp =drm_format_plane_cpp (fb->format[0 ].format,0 ); +do_div (width, cpp);
A simple compile/test here leads to:
...../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~
In file included from ./arch/powerpc/include/generated/asm/div64.h:1,
from ../include/linux/kernel.h:18,
from ../include/linux/list.h:9,
from ../include/linux/rculist.h:10,
from ../include/linux/pid.h:5,
from ../include/linux/sched.h:14,
from ../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:15:
../include/asm-generic/div64.h:239:22: error: passing argument 1 of
'__div64_32' from incompatible pointer type
[-Werror=incompatible-pointer-types]
__rem = __div64_32(&(n), __base); \
^~~~../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~../include/asm-generic/div64.h:213:38: note: expected 'uint64_t *' {aka 'long long unsigned int *'} but argument is of type 'unsigned int *'
extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
...
Quoted 631 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +21
-0+ +if (width > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->xres_virtual */ + + pitch = fb->pitches[0 ]; + lines = vram_size; +do_div (lines, pitch); + +if (lines > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->yres_virtual */ + + fb_var->xres_virtual = width; + fb_var->yres_virtual = lines; + + ret =fbdevdrm_update_fb_var_screeninfo_from_format ( + fb_var, fb->format[0 ].format); +if (ret) +return ret; + +return 0 ; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h +7
-0@@ -13,8 +13,11 @@#ifndef FBDEVDRM_MODES_H #define FBDEVDRM_MODES_H +#include <linux/types.h> +struct drm_device ;struct drm_display_mode ; +struct drm_framebuffer ;struct fb_videomode ;struct fb_var_screeninfo ;@@ -43,4 +46,8 @@ void fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var, const struct drm_display_mode *mode); +int fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( +struct fb_var_screeninfo *fb_var,struct drm_framebuffer *fb, +size_t vram_size); +#endif drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +8
-1@@ -20,6 +20,7 @@#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_primary.h" /* * CRTC @@ -376,7 +377,13 @@ int fbdevdrm_modeset_init(struct fbdevdrm_modeset *modeset,* connect them with each other. */ - ret =drm_crtc_init_with_planes (dev, &modeset->crtc,NULL ,NULL , + ret =fbdevdrm_init_primary_plane_from_fb_info ( + &modeset->primary_plane, dev,0 , fb_info); +if (ret) + goto err_drm_mode_config_cleanup; + + ret =drm_crtc_init_with_planes (dev, &modeset->crtc, + &modeset->primary_plane,NULL , &fbdevdrm_crtc_funcs,NULL );if (ret) goto err_drm_mode_config_cleanup;drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h +2
-0@@ -16,11 +16,13 @@#include <drm/drm_connector.h> #include <drm/drm_crtc.h> #include <drm/drm_encoder.h> +#include <drm/drm_plane.h> struct drm_device ;struct fb_info ;struct fbdevdrm_modeset { +struct drm_plane primary_plane;struct drm_crtc crtc;struct drm_encoder encoder;struct drm_connector connector;drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c new file +498
-0@@ -0,0 +1,498 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#include "fbdevdrm_primary.h" +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_plane.h> +#include <linux/fb.h> +#include "fbdevdrm_bo.h" +#include "fbdevdrm_format.h" +#include "fbdevdrm_modes.h" +#include "fbdevdrm_modeset.h" + +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_primary_plane ( +struct drm_plane *primary_plane) +{ + return container_of(primary_plane, struct fbdevdrm_modeset, + primary_plane); +} + +/* +* Primary plane +*/ + +static int primary_plane_helper_prepare_fb (struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +int ret; + +if (!new_state->fb) +return 0 ; + + gem = new_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + ret =fbdevdrm_bo_pin (fbo,TTM_PL_FLAG_VRAM ); +if (ret) +return ret; + +return 0 ; +} + +static void primary_plane_helper_cleanup_fb (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; + +if (!old_state->fb) +return ; + + gem = old_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + +fbdevdrm_bo_unpin (fbo); +} + +static void fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( +struct fb_var_screeninfo *fb_var,struct drm_crtc_state * crtc_state) +{ +fbdevdrm_update_fb_var_screeninfo_from_mode (fb_var, &crtc_state->adjusted_mode); +} + +static int primary_plane_helper_atomic_check (struct drm_plane *plane, +struct drm_plane_state *state) +{ +struct drm_crtc_state *new_crtc_state; +int ret; +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; + +if (!state->crtc) +return 0 ; + + new_crtc_state =drm_atomic_get_new_crtc_state (state->state, + state->crtc); +if (!new_crtc_state) +return 0 ; + + ret =drm_atomic_helper_check_plane_state (state, new_crtc_state, +1 <<16 ,1 <<16 , + false, true); +if (ret <0 ) { +DRM_ERROR ("fbdrmdev: %s:%d ret=%d:\n" , __func__, __LINE__, ret); +return ret; + } + +if (!state->visible || !state->fb) +return 0 ; + +/* Virtual screen sizes are not supported. +*/ + +if (drm_rect_width (&state->dst) != state->fb->width || +drm_rect_height (&state->dst) != state->fb->height) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen sizes not supported\n" , __func__, __LINE__); +return -EINVAL ; + } +if (state->dst.x1 || state->dst.y1) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen offset not supported\n" , __func__, __LINE__); +return -EINVAL ; + } + +/* Pixel formats have to be compatible with fbdev. This is +* usually some variation of XRGB. +*/ + +if (!plane->state || + !plane->state->fb || + plane->state->fb->format[0 ].format != state->fb->format[0 ].format) { + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + +if (modeset->fb_info->fbops->fb_check_var) { +memcpy (&fb_var, &modeset->fb_info->var, +sizeof (fb_var)); +fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( + &fb_var, new_crtc_state); +fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, state->fb, + modeset->fb_info->fix.smem_len); + ret = modeset->fb_info->fbops->fb_check_var ( + &fb_var, modeset->fb_info); +if (ret <0 ) +return ret; + } + } + +return 0 ; +} + +static int set_palette_cmap (struct fb_info * fb_info) +{ +__u32 len; +const struct fb_cmap * default_cmap; +struct fb_cmap cmap; +int ret; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >31 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + + default_cmap =fb_default_cmap (1ul << len); +if (!default_cmap) +return -EINVAL ; + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap, default_cmap->len,0 ); +if (ret) +return ret; + ret =fb_copy_cmap (default_cmap, &cmap); +if (ret) + goto err_fb_dealloc_cmap; + ret =fb_set_cmap (&cmap, fb_info); +if (ret) +return ret; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return ret; +} + +static int set_linear_cmap (struct fb_info * fb_info) +{ +struct fb_cmap cmap; +int ret; +size_t i; +unsigned int j; +u16 *lut; +u16 incr; +u16 *gamma_lut[3 ]; +__u32 len; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >8 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap,1ul << len,0 ); +if (ret) +return ret; + + gamma_lut[0 ] = cmap.red; + gamma_lut[1 ] = cmap.green; + gamma_lut[2 ] = cmap.blue; + +for (i =0 ; i <ARRAY_SIZE (gamma_lut); ++i) { + lut = gamma_lut[i]; + len =1ul << gamma_len[i]; + incr =0x10000u >> gamma_len[i]; +for (j =0 ; j < len; ++j, ++lut) { + *lut = incr * j; + } +/* In order to have no intensity at index 0 and full +* intensity at the final index of the LUT, we fix-up the +* table's final entries. The fix-up makes intensity grow +* faster near the final entries of the gamma LUT. The human +* eye is more sensitive to changes to the lower intensities, +* so this is probably not directly perceivable. +*/ +for (lut -= gamma_len[i], j = gamma_len[i]; j >0 ; ++lut) { + --j; + *lut += (incr >> j) -1 ;/* subtract 1 to not +* overflow the LUT's +* final entry */ + } + } + + ret =fb_set_cmap (&cmap, fb_info); +if (ret) + goto err_fb_dealloc_cmap; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return -EINVAL ; +} + +static int set_cmap (struct fb_info *fb_info) +{ +int ret =0 ; + +switch (fb_info->fix.visual) { +case FB_VISUAL_PSEUDOCOLOR : + ret =set_palette_cmap (fb_info); +break ; +case FB_VISUAL_DIRECTCOLOR : + ret =set_linear_cmap (fb_info); +break ; +default : +break ; + } + +return ret; +} + +static void primary_plane_helper_atomic_update ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ +struct fbdevdrm_modeset *modeset; +uint32_t format; +struct fb_var_screeninfo fb_var; +int ret; +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +__u32 line_length; +uint64_t yoffset; +uint32_t xoffset; + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + + format =fbdevdrm_format_of_fb_info (modeset->fb_info); + +/* DRM porting notes: Some fbdev drivers report alpha channels for +* their framebuffer, even though they don't support transparent +* primary planes. For the format test below, we ignore the alpha +* channel and use the non-transparent equivalent of the pixel format. +* If you're porting an fbdev driver to DRM, remove this switch +* statement and report the correct format instead. +*/ +switch (format) { +case DRM_FORMAT_ARGB8888 : + format =DRM_FORMAT_XRGB8888 ; +break ; +case DRM_FORMAT_ABGR8888 : + format =DRM_FORMAT_XBGR8888 ; +break ; +case DRM_FORMAT_RGBA8888 : + format =DRM_FORMAT_RGBX8888 ; +break ; +case DRM_FORMAT_BGRA8888 : + format =DRM_FORMAT_BGRX8888 ; +break ; +default : +break ; + } + +if ((format != plane->state->fb->format[0 ].format) || + (modeset->fb_info->var.xres_virtual != plane->state->fb->width)) { + +/* Pixel format changed, update fb_info accordingly +*/ + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + ret =fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, plane->state->fb, + modeset->fb_info->fix.smem_len); +if (ret) +return ; + + fb_var.activate =FB_ACTIVATE_NOW ; + + ret =fb_set_var (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_set_var() failed: %d\n" , ret); +return ; + } + } + +if (!old_state->fb ||/* first-time update */ + (format != plane->state->fb->format[0 ].format)) { + +/* DRM porting notes: Below we set the LUTs for palette and +* gamma correction. This is required by some fbdev drivers, +* such as nvidiafb and atyfb, which don't initialize the +* table to pass-through the framebuffer values unchanged. This +* is actually CRTC state, but the respective function +* crtc_helper_mode_set_nofb() is only called when a CRTC +* property changes, changes in color formats are not handled +* there. When you're porting a fbdev driver to DRM, remove +* the call. Gamma LUTs are CRTC properties and should be +* handled there. Either remove gamma correction or set up +* the respective CRTC properties for userspace. +*/ +set_cmap (modeset->fb_info); + } + +/* With the fb interface, we cannot directly program +* the scanout buffer's address. Instead we use the +* panning function to point the graphics card to the +* buffer's location. +*/ + + gem = plane->state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + line_length = plane->state->fb->pitches[0 ]; + yoffset = fbo->bo.offset; + xoffset =do_div (yoffset, line_length); +if (yoffset > (__u32)-1 ) { +/* The value of yoffset doesn't fit into a 32-bit value, +* so we cannot use it for display panning. Either the +* graphics card has GiBs of VRAM or this is a bug with +* memory management. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + }else if (xoffset) { +/* The buffer starts in the middle of a scanline. The +* memory manager should have prevented this. This +* problem indicates a bug with the buffer aligning. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + } + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + fb_var.xoffset = xoffset; + fb_var.yoffset = yoffset; + + ret =fb_pan_display (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_pan_display() failed: %d\n" , ret); +return ; + } +} + +static void primary_plane_helper_atomic_disable ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ } + +static int primary_plane_helper_atomic_async_check ( +struct drm_plane *plane,struct drm_plane_state *state) +{ +return 0 ; +} + +static void primary_plane_helper_atomic_async_update ( +struct drm_plane *plane,struct drm_plane_state *new_state) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_helper_funcs primary_plane_helper_funcs = { + .prepare_fb = primary_plane_helper_prepare_fb, + .cleanup_fb = primary_plane_helper_cleanup_fb, + .atomic_check = primary_plane_helper_atomic_check, + .atomic_update = primary_plane_helper_atomic_update, + .atomic_disable = primary_plane_helper_atomic_disable, + .atomic_async_check = primary_plane_helper_atomic_async_check, + .atomic_async_update = primary_plane_helper_atomic_async_update +}; + +static void primary_plane_destroy (struct drm_plane *plane) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_funcs primary_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = primary_plane_destroy, + .reset = drm_atomic_helper_plane_reset, + .set_property =NULL ,/* unused */ + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .atomic_set_property =NULL ,/* unused */ + .atomic_get_property =NULL ,/* unused */ + .late_register =NULL ,/* unused */ + .early_unregister =NULL ,/* unused */ + .atomic_print_state =NULL ,/* unused */ + .format_mod_supported =NULL /* unused */ +}; + +static const uint32_t * +formats_from_fb_info (const struct fb_info * fb_info,unsigned int * format_count) +{ +/* TODO: Detect the actually supported formats or have some +* sort of whitelist for known hardware devices. +*/ +static const uint32_t formats[] = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 + }; + + *format_count =ARRAY_SIZE (formats); + +return formats; +} + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info) +{ +uint32_t cur_format; +const uint32_t * format; +unsigned int format_count; +int ret; + +/* We first try to find the supported pixel formats from the +* fb_info's hardware settings. If that fails, we take the +* current settings. */ + format =formats_from_fb_info (fb_info, &format_count); +if (!format_count) { + cur_format =fbdevdrm_format_of_fb_info (fb_info); + format = &cur_format; + format_count =1 ; + } +if (!format_count) +return -ENODEV ; + + ret =drm_universal_plane_init (dev, plane, possible_crtcs, + &primary_plane_funcs, + format, format_count, +NULL ,DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret <0 ) +return ret; +drm_plane_helper_add (plane, &primary_plane_helper_funcs); + + ret =drm_plane_create_rotation_property (plane,DRM_MODE_ROTATE_0 , +DRM_MODE_ROTATE_0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + + ret =drm_plane_create_zpos_immutable_property (plane,0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + +return 0 ; + +err_drm_plane_cleanup: +drm_plane_cleanup (plane); +return ret; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h new file +27
-1@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_PRIMARY_H +#define FBDEVDRM_PRIMARY_H + +#include <linux/types.h> + +struct drm_device ; +struct drm_plane ; +struct fb_info ; + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info); + +#endif --2.21.0
Thomas Zimmermann
maintainerRe: [PATCH 09/11] drm/fbdevdrm: Add primary plane
Hi
Am 26.03.19 um 14:33 schrieb Mathieu Malaterre:
Quoted 19 lines
A simple compile/test here leads to:
...
../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~
In file included from./arch/powerpc/include/generated/asm/div64.h:1,from ../include/linux/kernel.h:18, from ../include/linux/list.h:9, from ../include/linux/rculist.h:10, from ../include/linux/pid.h:5, from ../include/linux/sched.h:14, from ../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:15: ../include/asm-generic/div64.h:239:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] __rem = __div64_32(&(n), __base); \ ^~~~
Quoted 9 lines
../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~../include/asm-generic/div64.h:213:38: note: expected 'uint64_t*' {aka 'long long unsigned int *'} but argument is of type 'unsigned int *'
externuint32_t__div64_32(uint64_t *dividend, uint32_t divisor);
...
I used a 32-bit machine for testing, so that's probably the difference here. Anyway, thanks for testing. Will be fixed in the next iteration.
Best regards
Thomas
Quoted 632 lines
Quoted 632 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +21
-0+ +if (width > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->xres_virtual */ + + pitch = fb->pitches[0 ]; + lines = vram_size; +do_div (lines, pitch); + +if (lines > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->yres_virtual */ + + fb_var->xres_virtual = width; + fb_var->yres_virtual = lines; + + ret =fbdevdrm_update_fb_var_screeninfo_from_format ( + fb_var, fb->format[0 ].format); +if (ret) +return ret; + +return 0 ; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h +7
-0@@ -13,8 +13,11 @@#ifndef FBDEVDRM_MODES_H #define FBDEVDRM_MODES_H +#include <linux/types.h> +struct drm_device ;struct drm_display_mode ; +struct drm_framebuffer ;struct fb_videomode ;struct fb_var_screeninfo ;@@ -43,4 +46,8 @@ void fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var, const struct drm_display_mode *mode); +int fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( +struct fb_var_screeninfo *fb_var,struct drm_framebuffer *fb, +size_t vram_size); +#endif drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +8
-1@@ -20,6 +20,7 @@#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_primary.h" /* * CRTC @@ -376,7 +377,13 @@ int fbdevdrm_modeset_init(struct fbdevdrm_modeset *modeset,* connect them with each other. */ - ret =drm_crtc_init_with_planes (dev, &modeset->crtc,NULL ,NULL , + ret =fbdevdrm_init_primary_plane_from_fb_info ( + &modeset->primary_plane, dev,0 , fb_info); +if (ret) + goto err_drm_mode_config_cleanup; + + ret =drm_crtc_init_with_planes (dev, &modeset->crtc, + &modeset->primary_plane,NULL , &fbdevdrm_crtc_funcs,NULL );if (ret) goto err_drm_mode_config_cleanup;drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h +2
-0@@ -16,11 +16,13 @@#include <drm/drm_connector.h> #include <drm/drm_crtc.h> #include <drm/drm_encoder.h> +#include <drm/drm_plane.h> struct drm_device ;struct fb_info ;struct fbdevdrm_modeset { +struct drm_plane primary_plane;struct drm_crtc crtc;struct drm_encoder encoder;struct drm_connector connector;drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c new file +498
-0@@ -0,0 +1,498 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#include "fbdevdrm_primary.h" +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_plane.h> +#include <linux/fb.h> +#include "fbdevdrm_bo.h" +#include "fbdevdrm_format.h" +#include "fbdevdrm_modes.h" +#include "fbdevdrm_modeset.h" + +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_primary_plane ( +struct drm_plane *primary_plane) +{ + return container_of(primary_plane, struct fbdevdrm_modeset, + primary_plane); +} + +/* +* Primary plane +*/ + +static int primary_plane_helper_prepare_fb (struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +int ret; + +if (!new_state->fb) +return 0 ; + + gem = new_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + ret =fbdevdrm_bo_pin (fbo,TTM_PL_FLAG_VRAM ); +if (ret) +return ret; + +return 0 ; +} + +static void primary_plane_helper_cleanup_fb (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; + +if (!old_state->fb) +return ; + + gem = old_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + +fbdevdrm_bo_unpin (fbo); +} + +static void fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( +struct fb_var_screeninfo *fb_var,struct drm_crtc_state * crtc_state) +{ +fbdevdrm_update_fb_var_screeninfo_from_mode (fb_var, &crtc_state->adjusted_mode); +} + +static int primary_plane_helper_atomic_check (struct drm_plane *plane, +struct drm_plane_state *state) +{ +struct drm_crtc_state *new_crtc_state; +int ret; +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; + +if (!state->crtc) +return 0 ; + + new_crtc_state =drm_atomic_get_new_crtc_state (state->state, + state->crtc); +if (!new_crtc_state) +return 0 ; + + ret =drm_atomic_helper_check_plane_state (state, new_crtc_state, +1 <<16 ,1 <<16 , + false, true); +if (ret <0 ) { +DRM_ERROR ("fbdrmdev: %s:%d ret=%d:\n" , __func__, __LINE__, ret); +return ret; + } + +if (!state->visible || !state->fb) +return 0 ; + +/* Virtual screen sizes are not supported. +*/ + +if (drm_rect_width (&state->dst) != state->fb->width || +drm_rect_height (&state->dst) != state->fb->height) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen sizes not supported\n" , __func__, __LINE__); +return -EINVAL ; + } +if (state->dst.x1 || state->dst.y1) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen offset not supported\n" , __func__, __LINE__); +return -EINVAL ; + } + +/* Pixel formats have to be compatible with fbdev. This is +* usually some variation of XRGB. +*/ + +if (!plane->state || + !plane->state->fb || + plane->state->fb->format[0 ].format != state->fb->format[0 ].format) { + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + +if (modeset->fb_info->fbops->fb_check_var) { +memcpy (&fb_var, &modeset->fb_info->var, +sizeof (fb_var)); +fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( + &fb_var, new_crtc_state); +fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, state->fb, + modeset->fb_info->fix.smem_len); + ret = modeset->fb_info->fbops->fb_check_var ( + &fb_var, modeset->fb_info); +if (ret <0 ) +return ret; + } + } + +return 0 ; +} + +static int set_palette_cmap (struct fb_info * fb_info) +{ +__u32 len; +const struct fb_cmap * default_cmap; +struct fb_cmap cmap; +int ret; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >31 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + + default_cmap =fb_default_cmap (1ul << len); +if (!default_cmap) +return -EINVAL ; + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap, default_cmap->len,0 ); +if (ret) +return ret; + ret =fb_copy_cmap (default_cmap, &cmap); +if (ret) + goto err_fb_dealloc_cmap; + ret =fb_set_cmap (&cmap, fb_info); +if (ret) +return ret; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return ret; +} + +static int set_linear_cmap (struct fb_info * fb_info) +{ +struct fb_cmap cmap; +int ret; +size_t i; +unsigned int j; +u16 *lut; +u16 incr; +u16 *gamma_lut[3 ]; +__u32 len; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >8 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap,1ul << len,0 ); +if (ret) +return ret; + + gamma_lut[0 ] = cmap.red; + gamma_lut[1 ] = cmap.green; + gamma_lut[2 ] = cmap.blue; + +for (i =0 ; i <ARRAY_SIZE (gamma_lut); ++i) { + lut = gamma_lut[i]; + len =1ul << gamma_len[i]; + incr =0x10000u >> gamma_len[i]; +for (j =0 ; j < len; ++j, ++lut) { + *lut = incr * j; + } +/* In order to have no intensity at index 0 and full +* intensity at the final index of the LUT, we fix-up the +* table's final entries. The fix-up makes intensity grow +* faster near the final entries of the gamma LUT. The human +* eye is more sensitive to changes to the lower intensities, +* so this is probably not directly perceivable. +*/ +for (lut -= gamma_len[i], j = gamma_len[i]; j >0 ; ++lut) { + --j; + *lut += (incr >> j) -1 ;/* subtract 1 to not +* overflow the LUT's +* final entry */ + } + } + + ret =fb_set_cmap (&cmap, fb_info); +if (ret) + goto err_fb_dealloc_cmap; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return -EINVAL ; +} + +static int set_cmap (struct fb_info *fb_info) +{ +int ret =0 ; + +switch (fb_info->fix.visual) { +case FB_VISUAL_PSEUDOCOLOR : + ret =set_palette_cmap (fb_info); +break ; +case FB_VISUAL_DIRECTCOLOR : + ret =set_linear_cmap (fb_info); +break ; +default : +break ; + } + +return ret; +} + +static void primary_plane_helper_atomic_update ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ +struct fbdevdrm_modeset *modeset; +uint32_t format; +struct fb_var_screeninfo fb_var; +int ret; +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +__u32 line_length; +uint64_t yoffset; +uint32_t xoffset; + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + + format =fbdevdrm_format_of_fb_info (modeset->fb_info); + +/* DRM porting notes: Some fbdev drivers report alpha channels for +* their framebuffer, even though they don't support transparent +* primary planes. For the format test below, we ignore the alpha +* channel and use the non-transparent equivalent of the pixel format. +* If you're porting an fbdev driver to DRM, remove this switch +* statement and report the correct format instead. +*/ +switch (format) { +case DRM_FORMAT_ARGB8888 : + format =DRM_FORMAT_XRGB8888 ; +break ; +case DRM_FORMAT_ABGR8888 : + format =DRM_FORMAT_XBGR8888 ; +break ; +case DRM_FORMAT_RGBA8888 : + format =DRM_FORMAT_RGBX8888 ; +break ; +case DRM_FORMAT_BGRA8888 : + format =DRM_FORMAT_BGRX8888 ; +break ; +default : +break ; + } + +if ((format != plane->state->fb->format[0 ].format) || + (modeset->fb_info->var.xres_virtual != plane->state->fb->width)) { + +/* Pixel format changed, update fb_info accordingly +*/ + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + ret =fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, plane->state->fb, + modeset->fb_info->fix.smem_len); +if (ret) +return ; + + fb_var.activate =FB_ACTIVATE_NOW ; + + ret =fb_set_var (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_set_var() failed: %d\n" , ret); +return ; + } + } + +if (!old_state->fb ||/* first-time update */ + (format != plane->state->fb->format[0 ].format)) { + +/* DRM porting notes: Below we set the LUTs for palette and +* gamma correction. This is required by some fbdev drivers, +* such as nvidiafb and atyfb, which don't initialize the +* table to pass-through the framebuffer values unchanged. This +* is actually CRTC state, but the respective function +* crtc_helper_mode_set_nofb() is only called when a CRTC +* property changes, changes in color formats are not handled +* there. When you're porting a fbdev driver to DRM, remove +* the call. Gamma LUTs are CRTC properties and should be +* handled there. Either remove gamma correction or set up +* the respective CRTC properties for userspace. +*/ +set_cmap (modeset->fb_info); + } + +/* With the fb interface, we cannot directly program +* the scanout buffer's address. Instead we use the +* panning function to point the graphics card to the +* buffer's location. +*/ + + gem = plane->state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + line_length = plane->state->fb->pitches[0 ]; + yoffset = fbo->bo.offset; + xoffset =do_div (yoffset, line_length); +if (yoffset > (__u32)-1 ) { +/* The value of yoffset doesn't fit into a 32-bit value, +* so we cannot use it for display panning. Either the +* graphics card has GiBs of VRAM or this is a bug with +* memory management. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + }else if (xoffset) { +/* The buffer starts in the middle of a scanline. The +* memory manager should have prevented this. This +* problem indicates a bug with the buffer aligning. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + } + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + fb_var.xoffset = xoffset; + fb_var.yoffset = yoffset; + + ret =fb_pan_display (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_pan_display() failed: %d\n" , ret); +return ; + } +} + +static void primary_plane_helper_atomic_disable ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ } + +static int primary_plane_helper_atomic_async_check ( +struct drm_plane *plane,struct drm_plane_state *state) +{ +return 0 ; +} + +static void primary_plane_helper_atomic_async_update ( +struct drm_plane *plane,struct drm_plane_state *new_state) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_helper_funcs primary_plane_helper_funcs = { + .prepare_fb = primary_plane_helper_prepare_fb, + .cleanup_fb = primary_plane_helper_cleanup_fb, + .atomic_check = primary_plane_helper_atomic_check, + .atomic_update = primary_plane_helper_atomic_update, + .atomic_disable = primary_plane_helper_atomic_disable, + .atomic_async_check = primary_plane_helper_atomic_async_check, + .atomic_async_update = primary_plane_helper_atomic_async_update +}; + +static void primary_plane_destroy (struct drm_plane *plane) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_funcs primary_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = primary_plane_destroy, + .reset = drm_atomic_helper_plane_reset, + .set_property =NULL ,/* unused */ + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .atomic_set_property =NULL ,/* unused */ + .atomic_get_property =NULL ,/* unused */ + .late_register =NULL ,/* unused */ + .early_unregister =NULL ,/* unused */ + .atomic_print_state =NULL ,/* unused */ + .format_mod_supported =NULL /* unused */ +}; + +static const uint32_t * +formats_from_fb_info (const struct fb_info * fb_info,unsigned int * format_count) +{ +/* TODO: Detect the actually supported formats or have some +* sort of whitelist for known hardware devices. +*/ +static const uint32_t formats[] = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 + }; + + *format_count =ARRAY_SIZE (formats); + +return formats; +} + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info) +{ +uint32_t cur_format; +const uint32_t * format; +unsigned int format_count; +int ret; + +/* We first try to find the supported pixel formats from the +* fb_info's hardware settings. If that fails, we take the +* current settings. */ + format =formats_from_fb_info (fb_info, &format_count); +if (!format_count) { + cur_format =fbdevdrm_format_of_fb_info (fb_info); + format = &cur_format; + format_count =1 ; + } +if (!format_count) +return -ENODEV ; + + ret =drm_universal_plane_init (dev, plane, possible_crtcs, + &primary_plane_funcs, + format, format_count, +NULL ,DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret <0 ) +return ret; +drm_plane_helper_add (plane, &primary_plane_helper_funcs); + + ret =drm_plane_create_rotation_property (plane,DRM_MODE_ROTATE_0 , +DRM_MODE_ROTATE_0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + + ret =drm_plane_create_zpos_immutable_property (plane,0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + +return 0 ; + +err_drm_plane_cleanup: +drm_plane_cleanup (plane); +return ret; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h new file +27
-1@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_PRIMARY_H +#define FBDEVDRM_PRIMARY_H + +#include <linux/types.h> + +struct drm_device ; +struct drm_plane ; +struct fb_info ; + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info); + +#endif --2.21.0
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Thomas Zimmermann
maintainerRe: [PATCH 09/11] drm/fbdevdrm: Add primary plane
In reply to Mathieu MalaterreHi
Am 26.03.19 um 14:33 schrieb Mathieu Malaterre:
Quoted 18 lines
...
../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~
In file included from./arch/powerpc/include/generated/asm/div64.h:1,from ../include/linux/kernel.h:18, from ../include/linux/list.h:9, from ../include/linux/rculist.h:10, from ../include/linux/pid.h:5, from ../include/linux/sched.h:14, from ../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:15: ../include/asm-generic/div64.h:239:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] __rem = __div64_32(&(n), __base); \ ^~~~
Quoted 9 lines
../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~../include/asm-generic/div64.h:213:38: note: expected 'uint64_t*' {aka 'long long unsigned int *'} but argument is of type 'unsigned int *'
externuint32_t__div64_32(uint64_t *dividend, uint32_t divisor);
...
I didn't see this error in 64-bit builds either. Could you send me your kernel config? Thanks!
Best regards
Thomas
Quoted 637 lines
Quoted 630 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +21
-0+ +if (width > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->xres_virtual */ + + pitch = fb->pitches[0 ]; + lines = vram_size; +do_div (lines, pitch); + +if (lines > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->yres_virtual */ + + fb_var->xres_virtual = width; + fb_var->yres_virtual = lines; + + ret =fbdevdrm_update_fb_var_screeninfo_from_format ( + fb_var, fb->format[0 ].format); +if (ret) +return ret; + +return 0 ; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h +7
-0@@ -13,8 +13,11 @@#ifndef FBDEVDRM_MODES_H #define FBDEVDRM_MODES_H +#include <linux/types.h> +struct drm_device ;struct drm_display_mode ; +struct drm_framebuffer ;struct fb_videomode ;struct fb_var_screeninfo ;@@ -43,4 +46,8 @@ void fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var, const struct drm_display_mode *mode); +int fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( +struct fb_var_screeninfo *fb_var,struct drm_framebuffer *fb, +size_t vram_size); +#endif drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +8
-1@@ -20,6 +20,7 @@#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_primary.h" /* * CRTC @@ -376,7 +377,13 @@ int fbdevdrm_modeset_init(struct fbdevdrm_modeset *modeset,* connect them with each other. */ - ret =drm_crtc_init_with_planes (dev, &modeset->crtc,NULL ,NULL , + ret =fbdevdrm_init_primary_plane_from_fb_info ( + &modeset->primary_plane, dev,0 , fb_info); +if (ret) + goto err_drm_mode_config_cleanup; + + ret =drm_crtc_init_with_planes (dev, &modeset->crtc, + &modeset->primary_plane,NULL , &fbdevdrm_crtc_funcs,NULL );if (ret) goto err_drm_mode_config_cleanup;drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h +2
-0@@ -16,11 +16,13 @@#include <drm/drm_connector.h> #include <drm/drm_crtc.h> #include <drm/drm_encoder.h> +#include <drm/drm_plane.h> struct drm_device ;struct fb_info ;struct fbdevdrm_modeset { +struct drm_plane primary_plane;struct drm_crtc crtc;struct drm_encoder encoder;struct drm_connector connector;drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c new file +498
-0@@ -0,0 +1,498 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#include "fbdevdrm_primary.h" +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_plane.h> +#include <linux/fb.h> +#include "fbdevdrm_bo.h" +#include "fbdevdrm_format.h" +#include "fbdevdrm_modes.h" +#include "fbdevdrm_modeset.h" + +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_primary_plane ( +struct drm_plane *primary_plane) +{ + return container_of(primary_plane, struct fbdevdrm_modeset, + primary_plane); +} + +/* +* Primary plane +*/ + +static int primary_plane_helper_prepare_fb (struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +int ret; + +if (!new_state->fb) +return 0 ; + + gem = new_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + ret =fbdevdrm_bo_pin (fbo,TTM_PL_FLAG_VRAM ); +if (ret) +return ret; + +return 0 ; +} + +static void primary_plane_helper_cleanup_fb (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; + +if (!old_state->fb) +return ; + + gem = old_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + +fbdevdrm_bo_unpin (fbo); +} + +static void fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( +struct fb_var_screeninfo *fb_var,struct drm_crtc_state * crtc_state) +{ +fbdevdrm_update_fb_var_screeninfo_from_mode (fb_var, &crtc_state->adjusted_mode); +} + +static int primary_plane_helper_atomic_check (struct drm_plane *plane, +struct drm_plane_state *state) +{ +struct drm_crtc_state *new_crtc_state; +int ret; +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; + +if (!state->crtc) +return 0 ; + + new_crtc_state =drm_atomic_get_new_crtc_state (state->state, + state->crtc); +if (!new_crtc_state) +return 0 ; + + ret =drm_atomic_helper_check_plane_state (state, new_crtc_state, +1 <<16 ,1 <<16 , + false, true); +if (ret <0 ) { +DRM_ERROR ("fbdrmdev: %s:%d ret=%d:\n" , __func__, __LINE__, ret); +return ret; + } + +if (!state->visible || !state->fb) +return 0 ; + +/* Virtual screen sizes are not supported. +*/ + +if (drm_rect_width (&state->dst) != state->fb->width || +drm_rect_height (&state->dst) != state->fb->height) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen sizes not supported\n" , __func__, __LINE__); +return -EINVAL ; + } +if (state->dst.x1 || state->dst.y1) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen offset not supported\n" , __func__, __LINE__); +return -EINVAL ; + } + +/* Pixel formats have to be compatible with fbdev. This is +* usually some variation of XRGB. +*/ + +if (!plane->state || + !plane->state->fb || + plane->state->fb->format[0 ].format != state->fb->format[0 ].format) { + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + +if (modeset->fb_info->fbops->fb_check_var) { +memcpy (&fb_var, &modeset->fb_info->var, +sizeof (fb_var)); +fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( + &fb_var, new_crtc_state); +fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, state->fb, + modeset->fb_info->fix.smem_len); + ret = modeset->fb_info->fbops->fb_check_var ( + &fb_var, modeset->fb_info); +if (ret <0 ) +return ret; + } + } + +return 0 ; +} + +static int set_palette_cmap (struct fb_info * fb_info) +{ +__u32 len; +const struct fb_cmap * default_cmap; +struct fb_cmap cmap; +int ret; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >31 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + + default_cmap =fb_default_cmap (1ul << len); +if (!default_cmap) +return -EINVAL ; + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap, default_cmap->len,0 ); +if (ret) +return ret; + ret =fb_copy_cmap (default_cmap, &cmap); +if (ret) + goto err_fb_dealloc_cmap; + ret =fb_set_cmap (&cmap, fb_info); +if (ret) +return ret; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return ret; +} + +static int set_linear_cmap (struct fb_info * fb_info) +{ +struct fb_cmap cmap; +int ret; +size_t i; +unsigned int j; +u16 *lut; +u16 incr; +u16 *gamma_lut[3 ]; +__u32 len; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >8 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap,1ul << len,0 ); +if (ret) +return ret; + + gamma_lut[0 ] = cmap.red; + gamma_lut[1 ] = cmap.green; + gamma_lut[2 ] = cmap.blue; + +for (i =0 ; i <ARRAY_SIZE (gamma_lut); ++i) { + lut = gamma_lut[i]; + len =1ul << gamma_len[i]; + incr =0x10000u >> gamma_len[i]; +for (j =0 ; j < len; ++j, ++lut) { + *lut = incr * j; + } +/* In order to have no intensity at index 0 and full +* intensity at the final index of the LUT, we fix-up the +* table's final entries. The fix-up makes intensity grow +* faster near the final entries of the gamma LUT. The human +* eye is more sensitive to changes to the lower intensities, +* so this is probably not directly perceivable. +*/ +for (lut -= gamma_len[i], j = gamma_len[i]; j >0 ; ++lut) { + --j; + *lut += (incr >> j) -1 ;/* subtract 1 to not +* overflow the LUT's +* final entry */ + } + } + + ret =fb_set_cmap (&cmap, fb_info); +if (ret) + goto err_fb_dealloc_cmap; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return -EINVAL ; +} + +static int set_cmap (struct fb_info *fb_info) +{ +int ret =0 ; + +switch (fb_info->fix.visual) { +case FB_VISUAL_PSEUDOCOLOR : + ret =set_palette_cmap (fb_info); +break ; +case FB_VISUAL_DIRECTCOLOR : + ret =set_linear_cmap (fb_info); +break ; +default : +break ; + } + +return ret; +} + +static void primary_plane_helper_atomic_update ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ +struct fbdevdrm_modeset *modeset; +uint32_t format; +struct fb_var_screeninfo fb_var; +int ret; +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +__u32 line_length; +uint64_t yoffset; +uint32_t xoffset; + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + + format =fbdevdrm_format_of_fb_info (modeset->fb_info); + +/* DRM porting notes: Some fbdev drivers report alpha channels for +* their framebuffer, even though they don't support transparent +* primary planes. For the format test below, we ignore the alpha +* channel and use the non-transparent equivalent of the pixel format. +* If you're porting an fbdev driver to DRM, remove this switch +* statement and report the correct format instead. +*/ +switch (format) { +case DRM_FORMAT_ARGB8888 : + format =DRM_FORMAT_XRGB8888 ; +break ; +case DRM_FORMAT_ABGR8888 : + format =DRM_FORMAT_XBGR8888 ; +break ; +case DRM_FORMAT_RGBA8888 : + format =DRM_FORMAT_RGBX8888 ; +break ; +case DRM_FORMAT_BGRA8888 : + format =DRM_FORMAT_BGRX8888 ; +break ; +default : +break ; + } + +if ((format != plane->state->fb->format[0 ].format) || + (modeset->fb_info->var.xres_virtual != plane->state->fb->width)) { + +/* Pixel format changed, update fb_info accordingly +*/ + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + ret =fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, plane->state->fb, + modeset->fb_info->fix.smem_len); +if (ret) +return ; + + fb_var.activate =FB_ACTIVATE_NOW ; + + ret =fb_set_var (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_set_var() failed: %d\n" , ret); +return ; + } + } + +if (!old_state->fb ||/* first-time update */ + (format != plane->state->fb->format[0 ].format)) { + +/* DRM porting notes: Below we set the LUTs for palette and +* gamma correction. This is required by some fbdev drivers, +* such as nvidiafb and atyfb, which don't initialize the +* table to pass-through the framebuffer values unchanged. This +* is actually CRTC state, but the respective function +* crtc_helper_mode_set_nofb() is only called when a CRTC +* property changes, changes in color formats are not handled +* there. When you're porting a fbdev driver to DRM, remove +* the call. Gamma LUTs are CRTC properties and should be +* handled there. Either remove gamma correction or set up +* the respective CRTC properties for userspace. +*/ +set_cmap (modeset->fb_info); + } + +/* With the fb interface, we cannot directly program +* the scanout buffer's address. Instead we use the +* panning function to point the graphics card to the +* buffer's location. +*/ + + gem = plane->state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + line_length = plane->state->fb->pitches[0 ]; + yoffset = fbo->bo.offset; + xoffset =do_div (yoffset, line_length); +if (yoffset > (__u32)-1 ) { +/* The value of yoffset doesn't fit into a 32-bit value, +* so we cannot use it for display panning. Either the +* graphics card has GiBs of VRAM or this is a bug with +* memory management. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + }else if (xoffset) { +/* The buffer starts in the middle of a scanline. The +* memory manager should have prevented this. This +* problem indicates a bug with the buffer aligning. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + } + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + fb_var.xoffset = xoffset; + fb_var.yoffset = yoffset; + + ret =fb_pan_display (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_pan_display() failed: %d\n" , ret); +return ; + } +} + +static void primary_plane_helper_atomic_disable ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ } + +static int primary_plane_helper_atomic_async_check ( +struct drm_plane *plane,struct drm_plane_state *state) +{ +return 0 ; +} + +static void primary_plane_helper_atomic_async_update ( +struct drm_plane *plane,struct drm_plane_state *new_state) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_helper_funcs primary_plane_helper_funcs = { + .prepare_fb = primary_plane_helper_prepare_fb, + .cleanup_fb = primary_plane_helper_cleanup_fb, + .atomic_check = primary_plane_helper_atomic_check, + .atomic_update = primary_plane_helper_atomic_update, + .atomic_disable = primary_plane_helper_atomic_disable, + .atomic_async_check = primary_plane_helper_atomic_async_check, + .atomic_async_update = primary_plane_helper_atomic_async_update +}; + +static void primary_plane_destroy (struct drm_plane *plane) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_funcs primary_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = primary_plane_destroy, + .reset = drm_atomic_helper_plane_reset, + .set_property =NULL ,/* unused */ + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .atomic_set_property =NULL ,/* unused */ + .atomic_get_property =NULL ,/* unused */ + .late_register =NULL ,/* unused */ + .early_unregister =NULL ,/* unused */ + .atomic_print_state =NULL ,/* unused */ + .format_mod_supported =NULL /* unused */ +}; + +static const uint32_t * +formats_from_fb_info (const struct fb_info * fb_info,unsigned int * format_count) +{ +/* TODO: Detect the actually supported formats or have some +* sort of whitelist for known hardware devices. +*/ +static const uint32_t formats[] = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 + }; + + *format_count =ARRAY_SIZE (formats); + +return formats; +} + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info) +{ +uint32_t cur_format; +const uint32_t * format; +unsigned int format_count; +int ret; + +/* We first try to find the supported pixel formats from the +* fb_info's hardware settings. If that fails, we take the +* current settings. */ + format =formats_from_fb_info (fb_info, &format_count); +if (!format_count) { + cur_format =fbdevdrm_format_of_fb_info (fb_info); + format = &cur_format; + format_count =1 ; + } +if (!format_count) +return -ENODEV ; + + ret =drm_universal_plane_init (dev, plane, possible_crtcs, + &primary_plane_funcs, + format, format_count, +NULL ,DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret <0 ) +return ret; +drm_plane_helper_add (plane, &primary_plane_helper_funcs); + + ret =drm_plane_create_rotation_property (plane,DRM_MODE_ROTATE_0 , +DRM_MODE_ROTATE_0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + + ret =drm_plane_create_zpos_immutable_property (plane,0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + +return 0 ; + +err_drm_plane_cleanup: +drm_plane_cleanup (plane); +return ret; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h new file +27
-1@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_PRIMARY_H +#define FBDEVDRM_PRIMARY_H + +#include <linux/types.h> + +struct drm_device ; +struct drm_plane ; +struct fb_info ; + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info); + +#endif --Quoted 2 lines
2.21.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Re: [PATCH 09/11] drm/fbdevdrm: Add primary plane
Quoted 32 lines · Thomas Zimmermann
Hi
Am 26.03.19 um 14:33 schrieb Mathieu Malaterre:
Quoted 18 lines
...
../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~
In file included from./arch/powerpc/include/generated/asm/div64.h:1,from ../include/linux/kernel.h:18, from ../include/linux/list.h:9, from ../include/linux/rculist.h:10, from ../include/linux/pid.h:5, from ../include/linux/sched.h:14, from ../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:15: ../include/asm-generic/div64.h:239:22: error: passing argument 1 of '__div64_32' from incompatible pointer type [-Werror=incompatible-pointer-types] __rem = __div64_32(&(n), __base); \ ^~~~Quoted 9 lines
../drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c:174:2: note: in expansion of macro 'do_div'
do_div(width, cpp);
^~~~~~../include/asm-generic/div64.h:213:38: note: expected 'uint64_t*' {aka 'long long unsigned int *'} but argument is of type 'unsigned int *'
externuint32_t__div64_32(uint64_t *dividend, uint32_t divisor);
...
Quoted 2 lines
I didn't see this error in 64-bit builds either. Could you send me your kernel config? Thanks!
https://github.com/malaterre/linux/blob/g4/arch/powerpc/configs/g4_defconfig
I am using Debian/sid with the default cross compiler for powerpc:
$ make -j8 O=g4 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-
Quoted 649 lines
Best regards
ThomasQuoted 628 lines
Quoted 628 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c +21
-0+ +if (width > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->xres_virtual */ + + pitch = fb->pitches[0 ]; + lines = vram_size; +do_div (lines, pitch); + +if (lines > (__u32)-1 ) +return -EINVAL ;/* would overflow fb_var->yres_virtual */ + + fb_var->xres_virtual = width; + fb_var->yres_virtual = lines; + + ret =fbdevdrm_update_fb_var_screeninfo_from_format ( + fb_var, fb->format[0 ].format); +if (ret) +return ret; + +return 0 ; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h +7
-0@@ -13,8 +13,11 @@#ifndef FBDEVDRM_MODES_H #define FBDEVDRM_MODES_H +#include <linux/types.h> +struct drm_device ;struct drm_display_mode ; +struct drm_framebuffer ;struct fb_videomode ;struct fb_var_screeninfo ;@@ -43,4 +46,8 @@ void fbdevdrm_init_fb_var_screeninfo_from_mode(struct fb_var_screeninfo *var, const struct drm_display_mode *mode); +int fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( +struct fb_var_screeninfo *fb_var,struct drm_framebuffer *fb, +size_t vram_size); +#endif drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +8
-1@@ -20,6 +20,7 @@#include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_primary.h" /* * CRTC @@ -376,7 +377,13 @@ int fbdevdrm_modeset_init(struct fbdevdrm_modeset *modeset,* connect them with each other. */ - ret =drm_crtc_init_with_planes (dev, &modeset->crtc,NULL ,NULL , + ret =fbdevdrm_init_primary_plane_from_fb_info ( + &modeset->primary_plane, dev,0 , fb_info); +if (ret) + goto err_drm_mode_config_cleanup; + + ret =drm_crtc_init_with_planes (dev, &modeset->crtc, + &modeset->primary_plane,NULL , &fbdevdrm_crtc_funcs,NULL );if (ret) goto err_drm_mode_config_cleanup;drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h +2
-0@@ -16,11 +16,13 @@#include <drm/drm_connector.h> #include <drm/drm_crtc.h> #include <drm/drm_encoder.h> +#include <drm/drm_plane.h> struct drm_device ;struct fb_info ;struct fbdevdrm_modeset { +struct drm_plane primary_plane;struct drm_crtc crtc;struct drm_encoder encoder;struct drm_connector connector;drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c new file +498
-0@@ -0,0 +1,498 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#include "fbdevdrm_primary.h" +#include <drm/drm_atomic.h> +#include <drm/drm_atomic_helper.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_plane.h> +#include <linux/fb.h> +#include "fbdevdrm_bo.h" +#include "fbdevdrm_format.h" +#include "fbdevdrm_modes.h" +#include "fbdevdrm_modeset.h" + +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_primary_plane ( +struct drm_plane *primary_plane) +{ + return container_of(primary_plane, struct fbdevdrm_modeset, + primary_plane); +} + +/* +* Primary plane +*/ + +static int primary_plane_helper_prepare_fb (struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +int ret; + +if (!new_state->fb) +return 0 ; + + gem = new_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + ret =fbdevdrm_bo_pin (fbo,TTM_PL_FLAG_VRAM ); +if (ret) +return ret; + +return 0 ; +} + +static void primary_plane_helper_cleanup_fb (struct drm_plane *plane, +struct drm_plane_state *old_state) +{ +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; + +if (!old_state->fb) +return ; + + gem = old_state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + +fbdevdrm_bo_unpin (fbo); +} + +static void fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( +struct fb_var_screeninfo *fb_var,struct drm_crtc_state * crtc_state) +{ +fbdevdrm_update_fb_var_screeninfo_from_mode (fb_var, &crtc_state->adjusted_mode); +} + +static int primary_plane_helper_atomic_check (struct drm_plane *plane, +struct drm_plane_state *state) +{ +struct drm_crtc_state *new_crtc_state; +int ret; +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; + +if (!state->crtc) +return 0 ; + + new_crtc_state =drm_atomic_get_new_crtc_state (state->state, + state->crtc); +if (!new_crtc_state) +return 0 ; + + ret =drm_atomic_helper_check_plane_state (state, new_crtc_state, +1 <<16 ,1 <<16 , + false, true); +if (ret <0 ) { +DRM_ERROR ("fbdrmdev: %s:%d ret=%d:\n" , __func__, __LINE__, ret); +return ret; + } + +if (!state->visible || !state->fb) +return 0 ; + +/* Virtual screen sizes are not supported. +*/ + +if (drm_rect_width (&state->dst) != state->fb->width || +drm_rect_height (&state->dst) != state->fb->height) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen sizes not supported\n" , __func__, __LINE__); +return -EINVAL ; + } +if (state->dst.x1 || state->dst.y1) { +DRM_ERROR ("fbdevdrm: %s:%d: virtual screen offset not supported\n" , __func__, __LINE__); +return -EINVAL ; + } + +/* Pixel formats have to be compatible with fbdev. This is +* usually some variation of XRGB. +*/ + +if (!plane->state || + !plane->state->fb || + plane->state->fb->format[0 ].format != state->fb->format[0 ].format) { + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + +if (modeset->fb_info->fbops->fb_check_var) { +memcpy (&fb_var, &modeset->fb_info->var, +sizeof (fb_var)); +fbdevdrm_update_fb_var_screeninfo_from_crtc_state ( + &fb_var, new_crtc_state); +fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, state->fb, + modeset->fb_info->fix.smem_len); + ret = modeset->fb_info->fbops->fb_check_var ( + &fb_var, modeset->fb_info); +if (ret <0 ) +return ret; + } + } + +return 0 ; +} + +static int set_palette_cmap (struct fb_info * fb_info) +{ +__u32 len; +const struct fb_cmap * default_cmap; +struct fb_cmap cmap; +int ret; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >31 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + + default_cmap =fb_default_cmap (1ul << len); +if (!default_cmap) +return -EINVAL ; + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap, default_cmap->len,0 ); +if (ret) +return ret; + ret =fb_copy_cmap (default_cmap, &cmap); +if (ret) + goto err_fb_dealloc_cmap; + ret =fb_set_cmap (&cmap, fb_info); +if (ret) +return ret; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return ret; +} + +static int set_linear_cmap (struct fb_info * fb_info) +{ +struct fb_cmap cmap; +int ret; +size_t i; +unsigned int j; +u16 *lut; +u16 incr; +u16 *gamma_lut[3 ]; +__u32 len; +const __u32 gamma_len[3 ] = { + fb_info->var.red.length, + fb_info->var.green.length, + fb_info->var.blue.length + }; + + len =max3 (gamma_len[0 ], gamma_len[1 ], gamma_len[2 ]); +if (!len || (len >8 )) { +DRM_ERROR ("fbdevdrm: gamma LUT has invalid bit count" +" of %u\n" , (unsigned int )len); +return -EINVAL ; + } + +memset (&cmap,0 ,sizeof (cmap)); + ret =fb_alloc_cmap (&cmap,1ul << len,0 ); +if (ret) +return ret; + + gamma_lut[0 ] = cmap.red; + gamma_lut[1 ] = cmap.green; + gamma_lut[2 ] = cmap.blue; + +for (i =0 ; i <ARRAY_SIZE (gamma_lut); ++i) { + lut = gamma_lut[i]; + len =1ul << gamma_len[i]; + incr =0x10000u >> gamma_len[i]; +for (j =0 ; j < len; ++j, ++lut) { + *lut = incr * j; + } +/* In order to have no intensity at index 0 and full +* intensity at the final index of the LUT, we fix-up the +* table's final entries. The fix-up makes intensity grow +* faster near the final entries of the gamma LUT. The human +* eye is more sensitive to changes to the lower intensities, +* so this is probably not directly perceivable. +*/ +for (lut -= gamma_len[i], j = gamma_len[i]; j >0 ; ++lut) { + --j; + *lut += (incr >> j) -1 ;/* subtract 1 to not +* overflow the LUT's +* final entry */ + } + } + + ret =fb_set_cmap (&cmap, fb_info); +if (ret) + goto err_fb_dealloc_cmap; +fb_dealloc_cmap (&cmap); + +return 0 ; + +err_fb_dealloc_cmap: +fb_dealloc_cmap (&cmap); +return -EINVAL ; +} + +static int set_cmap (struct fb_info *fb_info) +{ +int ret =0 ; + +switch (fb_info->fix.visual) { +case FB_VISUAL_PSEUDOCOLOR : + ret =set_palette_cmap (fb_info); +break ; +case FB_VISUAL_DIRECTCOLOR : + ret =set_linear_cmap (fb_info); +break ; +default : +break ; + } + +return ret; +} + +static void primary_plane_helper_atomic_update ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ +struct fbdevdrm_modeset *modeset; +uint32_t format; +struct fb_var_screeninfo fb_var; +int ret; +struct drm_gem_object *gem; +struct fbdevdrm_bo *fbo; +__u32 line_length; +uint64_t yoffset; +uint32_t xoffset; + + modeset =fbdevdrm_modeset_of_primary_plane (plane); + + format =fbdevdrm_format_of_fb_info (modeset->fb_info); + +/* DRM porting notes: Some fbdev drivers report alpha channels for +* their framebuffer, even though they don't support transparent +* primary planes. For the format test below, we ignore the alpha +* channel and use the non-transparent equivalent of the pixel format. +* If you're porting an fbdev driver to DRM, remove this switch +* statement and report the correct format instead. +*/ +switch (format) { +case DRM_FORMAT_ARGB8888 : + format =DRM_FORMAT_XRGB8888 ; +break ; +case DRM_FORMAT_ABGR8888 : + format =DRM_FORMAT_XBGR8888 ; +break ; +case DRM_FORMAT_RGBA8888 : + format =DRM_FORMAT_RGBX8888 ; +break ; +case DRM_FORMAT_BGRA8888 : + format =DRM_FORMAT_BGRX8888 ; +break ; +default : +break ; + } + +if ((format != plane->state->fb->format[0 ].format) || + (modeset->fb_info->var.xres_virtual != plane->state->fb->width)) { + +/* Pixel format changed, update fb_info accordingly +*/ + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + ret =fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, plane->state->fb, + modeset->fb_info->fix.smem_len); +if (ret) +return ; + + fb_var.activate =FB_ACTIVATE_NOW ; + + ret =fb_set_var (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_set_var() failed: %d\n" , ret); +return ; + } + } + +if (!old_state->fb ||/* first-time update */ + (format != plane->state->fb->format[0 ].format)) { + +/* DRM porting notes: Below we set the LUTs for palette and +* gamma correction. This is required by some fbdev drivers, +* such as nvidiafb and atyfb, which don't initialize the +* table to pass-through the framebuffer values unchanged. This +* is actually CRTC state, but the respective function +* crtc_helper_mode_set_nofb() is only called when a CRTC +* property changes, changes in color formats are not handled +* there. When you're porting a fbdev driver to DRM, remove +* the call. Gamma LUTs are CRTC properties and should be +* handled there. Either remove gamma correction or set up +* the respective CRTC properties for userspace. +*/ +set_cmap (modeset->fb_info); + } + +/* With the fb interface, we cannot directly program +* the scanout buffer's address. Instead we use the +* panning function to point the graphics card to the +* buffer's location. +*/ + + gem = plane->state->fb->obj[0 ]; + fbo =fbdevdrm_bo_of_gem (gem); + + line_length = plane->state->fb->pitches[0 ]; + yoffset = fbo->bo.offset; + xoffset =do_div (yoffset, line_length); +if (yoffset > (__u32)-1 ) { +/* The value of yoffset doesn't fit into a 32-bit value, +* so we cannot use it for display panning. Either the +* graphics card has GiBs of VRAM or this is a bug with +* memory management. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + }else if (xoffset) { +/* The buffer starts in the middle of a scanline. The +* memory manager should have prevented this. This +* problem indicates a bug with the buffer aligning. */ +DRM_ERROR ("fbdevdrm: buffer object is not aligned to a " +"multiple of the scanline size.\n" ); +return ; + } + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); + fb_var.xoffset = xoffset; + fb_var.yoffset = yoffset; + + ret =fb_pan_display (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_pan_display() failed: %d\n" , ret); +return ; + } +} + +static void primary_plane_helper_atomic_disable ( +struct drm_plane *plane,struct drm_plane_state *old_state) +{ } + +static int primary_plane_helper_atomic_async_check ( +struct drm_plane *plane,struct drm_plane_state *state) +{ +return 0 ; +} + +static void primary_plane_helper_atomic_async_update ( +struct drm_plane *plane,struct drm_plane_state *new_state) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_helper_funcs primary_plane_helper_funcs = { + .prepare_fb = primary_plane_helper_prepare_fb, + .cleanup_fb = primary_plane_helper_cleanup_fb, + .atomic_check = primary_plane_helper_atomic_check, + .atomic_update = primary_plane_helper_atomic_update, + .atomic_disable = primary_plane_helper_atomic_disable, + .atomic_async_check = primary_plane_helper_atomic_async_check, + .atomic_async_update = primary_plane_helper_atomic_async_update +}; + +static void primary_plane_destroy (struct drm_plane *plane) +{ +drm_plane_cleanup (plane); +} + +static const struct drm_plane_funcs primary_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = primary_plane_destroy, + .reset = drm_atomic_helper_plane_reset, + .set_property =NULL ,/* unused */ + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .atomic_set_property =NULL ,/* unused */ + .atomic_get_property =NULL ,/* unused */ + .late_register =NULL ,/* unused */ + .early_unregister =NULL ,/* unused */ + .atomic_print_state =NULL ,/* unused */ + .format_mod_supported =NULL /* unused */ +}; + +static const uint32_t * +formats_from_fb_info (const struct fb_info * fb_info,unsigned int * format_count) +{ +/* TODO: Detect the actually supported formats or have some +* sort of whitelist for known hardware devices. +*/ +static const uint32_t formats[] = { +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_RGB565 + }; + + *format_count =ARRAY_SIZE (formats); + +return formats; +} + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info) +{ +uint32_t cur_format; +const uint32_t * format; +unsigned int format_count; +int ret; + +/* We first try to find the supported pixel formats from the +* fb_info's hardware settings. If that fails, we take the +* current settings. */ + format =formats_from_fb_info (fb_info, &format_count); +if (!format_count) { + cur_format =fbdevdrm_format_of_fb_info (fb_info); + format = &cur_format; + format_count =1 ; + } +if (!format_count) +return -ENODEV ; + + ret =drm_universal_plane_init (dev, plane, possible_crtcs, + &primary_plane_funcs, + format, format_count, +NULL ,DRM_PLANE_TYPE_PRIMARY ,NULL ); +if (ret <0 ) +return ret; +drm_plane_helper_add (plane, &primary_plane_helper_funcs); + + ret =drm_plane_create_rotation_property (plane,DRM_MODE_ROTATE_0 , +DRM_MODE_ROTATE_0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + + ret =drm_plane_create_zpos_immutable_property (plane,0 ); +if (ret <0 ) + goto err_drm_plane_cleanup; + +return 0 ; + +err_drm_plane_cleanup: +drm_plane_cleanup (plane); +return ret; +}drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h new file +26
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* One purpose of this driver is to allow for easy conversion of framebuffer +* drivers to DRM. As a special exception to the GNU GPL, you are allowed to +* relicense this file under the terms of a license of your choice if you're +* porting a framebuffer driver. In order to do so, update the SPDX license +* identifier to the new license and remove this exception. +* +* If you add code to this file, please ensure that it's compatible with the +* stated exception. +*/ + +#ifndef FBDEVDRM_PRIMARY_H +#define FBDEVDRM_PRIMARY_H + +#include <linux/types.h> + +struct drm_device ; +struct drm_plane ; +struct fb_info ; + +int fbdevdrm_init_primary_plane_from_fb_info (struct drm_plane *plane, +struct drm_device *dev, +uint32_t possible_crtcs, +struct fb_info *fb_info); +Quoted 9 lines
Quoted 4 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h new file +1
-1+#endif --2.21.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Thomas Zimmermann
maintainerPATCH 10/11 drm/fbdevdrm: Add CRTC
In reply to Thomas Zimmermann--- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 150 +++++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-)
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +149 -1
@@ -18,10 +18,18 @@#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_modeset_helper.h> #include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_print.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_modes.h" #include "fbdevdrm_primary.h" +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_crtc ( +struct drm_crtc *crtc) +{ + return container_of(crtc, struct fbdevdrm_modeset, crtc); +} +/* * CRTC */
@@ -29,18 +37,124 @@static enum drm_mode_status crtc_helper_mode_valid (struct drm_crtc *crtc,const struct drm_display_mode *mode) { +static const unsigned char bits_per_pixel[] = { +32 ,16 ,8 ,24 ,15 + }; + +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; +size_t i; +int ret; + + modeset =fbdevdrm_modeset_of_crtc (crtc); + +if (!modeset->fb_info->fbops->fb_check_var) +return MODE_OK ; + +for (i =0 ; i <ARRAY_SIZE (bits_per_pixel); ++i) { + +memcpy (&fb_var, &modeset->fb_info->var,sizeof (fb_var)); +fbdevdrm_update_fb_var_screeninfo_from_mode (&fb_var, mode); + fb_var.bits_per_pixel = bits_per_pixel[i]; + + ret = modeset->fb_info->fbops->fb_check_var (&fb_var, modeset->fb_info); +if (ret) +continue ;/* generally not supported */ +if ((mode->hdisplay != fb_var.xres) || + (mode->vdisplay != fb_var.yres)) +continue ;/* unsupported resolution */ +if (KHZ2PICOS (mode->clock) != fb_var.pixclock) +continue ;/* unsupported pixel clock */ + +break ;/* mode successfully tested */ + } +if (i =ARRAY_SIZE (bits_per_pixel)) +return MODE_BAD ;/* mode is not support */ +return MODE_OK ; } +static int fbdevdrm_update_fb_var_screeninfo_from_crtc ( +struct fb_var_screeninfo *fb_var,struct drm_crtc * crtc) +{ +struct drm_plane *primary = crtc->primary; +struct fbdevdrm_modeset *modeset =fbdevdrm_modeset_of_crtc (crtc); + +if (primary && primary->state && primary->state->fb) +return fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + fb_var, primary->state->fb, + modeset->fb_info->fix.smem_len); + + fb_var->xres_virtual = fb_var->xres; + fb_var->yres_virtual = fb_var->yres; + fb_var->bits_per_pixel = modeset->dev->mode_config.preferred_depth; + +return 0 ; +} +static bool crtc_helper_mode_fixup (struct drm_crtc *crtc,const struct drm_display_mode *mode,struct drm_display_mode *adjusted_mode) { +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; +int ret; + + modeset =fbdevdrm_modeset_of_crtc (crtc); + +if (!modeset->fb_info->fbops->fb_check_var) +return true; + +fbdevdrm_init_fb_var_screeninfo_from_mode (&fb_var, mode); + + ret =fbdevdrm_update_fb_var_screeninfo_from_crtc (&fb_var, crtc); +if (ret) +return true; + + ret = modeset->fb_info->fbops->fb_check_var (&fb_var, modeset->fb_info); +if (ret <0 ) +return false; + +drm_mode_update_from_fb_var_screeninfo (adjusted_mode, &fb_var); +return true; }static void crtc_helper_mode_set_nofb (struct drm_crtc *crtc) -{ } +{ +struct fbdevdrm_modeset *modeset; +struct fb_var_screeninfo fb_var; +int ret; + +/* As this is atomic mode setting, any function call is not +* allowed to fail. If it does, an additional test should be +* added to crtc_helper_atomic_check(). +*/ + + modeset =fbdevdrm_modeset_of_crtc (crtc); + +memset (&fb_var,0 ,sizeof (fb_var)); +fbdevdrm_update_fb_var_screeninfo_from_mode (&fb_var, &crtc->state->adjusted_mode); + +if (crtc->primary && crtc->primary->state && crtc->primary->state->fb) { + ret =fbdevdrm_update_fb_var_screeninfo_from_framebuffer ( + &fb_var, crtc->primary->state->fb, + modeset->fb_info->fix.smem_len); +if (ret) +return ; + }else { + fb_var.xres_virtual = fb_var.xres; + fb_var.yres_virtual = fb_var.yres; + } + + fb_var.activate =FB_ACTIVATE_NOW ; + + ret =fb_set_var (modeset->fb_info, &fb_var); +if (ret) { +DRM_ERROR ("fbdevdrm: fb_set_var() failed: %d\n" , ret); +return ; + } +} static int crtc_helper_mode_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
@@ -53,6 +167,40 @@ static int crtc_helper_mode_set_base_atomic(struct drm_crtc *crtc,static int crtc_helper_atomic_check (struct drm_crtc *crtc,struct drm_crtc_state *state) { +struct fbdevdrm_modeset *modeset; +struct fb_videomode fb_mode, fb_var_mode; + + modeset =fbdevdrm_modeset_of_crtc (crtc); + +/* DRM porting notes: when fbcon takes over the console, it regularly +* changes the display mode. Where's apparently no way to detect this +* directly from fbcon itself. DRM's mode information might therefore +* be out of data, after it takes over the display at a later time. +* Here, we test the CRTC's current mode with the fbdev state. If they +* do not match, we request a mode change from DRM. If you port an +* fbdev driver to DRM, you can remove this code section, DRM will +* be in full control of the display device and doesn't have to react +* to changes from external sources. +*/ + +if (!state->mode_changed && state->adjusted_mode.clock) { +fbdevdrm_init_fb_videomode_from_mode (&fb_mode, &state->adjusted_mode); +fb_var_to_videomode (&fb_var_mode, &modeset->fb_info->var); +if (!fb_mode_is_equal (&fb_mode, &fb_var_mode)) + state->mode_changed = true; + } + +/* TODO: The vblank interupt is currently not supported. We set +* the corresponding flag as a workaround. Some fbdev drivers +* support FBIO_WAITFORVSYNC, which we might use for querying +* vblanks. +* +* DRM porting notes: if you're porting an fbdev driver to DRM, +* remove this line and instead signal a vblank event from the +* interupt handler. +*/ + state->no_vblank = true; +return 0 ; }
Signature · 1 line
2.21.0
Thomas Zimmermann
maintainerPATCH 11/11 drm/fbdevdrm: Detect and validate display modes
In reply to Thomas ZimmermannMode detection currently reports the modes listed in fb_info::modelist. The list is either build from EDID information or, more often, a list of previously set modes. A later update to the mode detection could also take into account the modes in fb_monspecs::modedb or test pre-defined VESA modes.
--- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 163 +++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-)
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +161 -1
@@ -21,9 +21,16 @@#include <drm/drm_print.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_device.h" #include "fbdevdrm_modes.h" #include "fbdevdrm_primary.h" +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_connector ( +struct drm_connector *connector) +{ + return container_of(connector, struct fbdevdrm_modeset, connector); +} +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_crtc (struct drm_crtc *crtc) {
@@ -353,11 +360,130 @@ static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = {* Connector */ -static int connector_helper_get_modes (struct drm_connector *connector) +static int update_display_info (struct drm_display_info *info,struct fb_info *fb_info) +{ +int num_pixel; + +if (fb_info->fix.type !=FB_TYPE_PACKED_PIXELS ) +return -EINVAL ;/* rule out text mode, etc. */ + +if (fb_info->fix.id[0 ]) { +strncpy (info->name, fb_info->fix.id,sizeof (info->name) -1 ); + info->name[sizeof (info->name) -1 ] ='\0' ; + }else { +memset (info->name,'\0' ,sizeof (info->name)); + } + + info->width_mm = fb_info->var.width; + info->height_mm = fb_info->var.height; + info->pixel_clock =PICOS2KHZ (fb_info->var.pixclock); + + num_pixel =0 ; +if (fb_info->var.red.length) + ++num_pixel; +if (fb_info->var.green.length) + ++num_pixel; +if (fb_info->var.blue.length) + ++num_pixel; +if (fb_info->var.transp.length) + ++num_pixel; + +if (num_pixel) + info->bpc = fb_info->var.bits_per_pixel; +else + info->bpc =0 ; + + info->subpixel_order = SubPixelUnknown; + info->color_formats =DRM_COLOR_FORMAT_RGB444 ; + info->bus_formats = &info->color_formats; + info->num_bus_formats =1 ; + info->bus_flags =0 ; + info->max_tmds_clock =0 ; + info->dvi_dual = false; + info->has_hdmi_infoframe = false; + info->edid_hdmi_dc_modes =0 ; + info->cea_rev =0 ; +memset (&info->hdmi,0 ,sizeof (info->hdmi)); + info->non_desktop =0 ; + +return 0 ; +} + +static int drm_mode_probed_add_from_fb_videomode ( +struct drm_connector *connector,const struct fb_videomode *fb_mode, +struct fb_info *fb_info) { +struct drm_display_mode *mode; + + mode =drm_mode_create_from_fb_videomode (connector->dev, fb_mode); +if (!mode) +return -ENOMEM ; + + mode->width_mm = fb_info->var.width; + mode->height_mm = fb_info->var.height; + +drm_mode_probed_add (connector, mode); + +/* update connector properties from display mode */ +if (mode->flags &DRM_MODE_FLAG_INTERLACE ) + connector->interlace_allowed = true; +if (mode->flags &DRM_MODE_FLAG_DBLSCAN ) + connector->doublescan_allowed = true; +if (mode->flags &DRM_MODE_FLAG_3D_MASK ) + connector->stereo_allowed = true; +return 0 ; } +static int connector_helper_get_modes (struct drm_connector *connector) +{ +struct fbdevdrm_modeset *modeset; +struct list_head *pos; +int ret, num_modes =0 ; + + modeset =fbdevdrm_modeset_of_connector (connector); + + ret =update_display_info (&connector->display_info, modeset->fb_info); +if (ret) +return 0 ; + +/* update connector properties from video modes */ + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->stereo_allowed =0 ; + +if (!num_modes && modeset->fb_info->mode) { + ret =drm_mode_probed_add_from_fb_videomode ( + connector, modeset->fb_info->mode, modeset->fb_info); +if (!ret) + ++num_modes; + } + +if (!num_modes) { + +/* DRM backporting notes: we go through all modes in the +* fb_info's mode list and convert each to a DRM modes. If +* you convert an fbdev driver to DRM, replace this code +* with an actual hardware query. This will usually involve +* reading the monitor EDID via DDC. +*/ + +list_for_each (pos, &modeset->fb_info->modelist) { + const struct fb_modelist *modelist + container_of(pos, struct fb_modelist, list); + + ret =drm_mode_probed_add_from_fb_videomode ( + connector, &modelist->mode, + modeset->fb_info); +if (ret <0 ) +continue ; + ++num_modes; + } + } + +return num_modes; +} +static int connector_helper_detect_ctx (struct drm_connector *connector,struct drm_modeset_acquire_ctx *ctx,bool force)
@@ -368,6 +494,21 @@ static int connector_helper_detect_ctx(struct drm_connector *connector,static enum drm_mode_status connector_helper_mode_valid (struct drm_connector *connector,struct drm_display_mode *mode) { +struct fb_var_screeninfo fb_var; +int ret; +struct fbdevdrm_modeset *modeset =fbdevdrm_modeset_of_connector (connector); + +/* fb_validate_mode() requires fb_info->monspecs to contain valid +* data. Skip the test if the maximum clock looks bogus. */ +if (!modeset->fb_info->monspecs.dclkmax) +return MODE_OK ; + +fbdevdrm_init_fb_var_screeninfo_from_mode (&fb_var, mode); + + ret =fb_validate_mode (&fb_var, modeset->fb_info); +if (ret <0 ) +return MODE_BAD ; +return MODE_OK ; }
@@ -444,6 +585,26 @@ static const struct drm_connector_funcs fbdevdrm_connector_funcs = {static enum drm_mode_status mode_config_mode_valid (struct drm_device *dev,const struct drm_display_mode *mode) { +/* TODO: maybe detect maximum depth */ +static const unsigned int max_bpp =4 ;/* 32-bit depth */ + +size_t vram_size_2, fb_size; +struct fbdevdrm_device *fdev =fbdevdrm_device_of_dev (dev); + +/* DRM porting note: The atomic mode-setting framework requires +* two framebuffers to be present in VRAM during page flips. This +* is a problem for modes that require buffers larger than half +* the VRAM size. This can happen on older graphics cards with less +* than 16 MiB of VRAM. There's no point in reporting such modes, +* so we sort them out. If you're porting an fbdevdriver to DRM, you +* may want to keep this policy if the device has limited VRAM. +*/ + vram_size_2 = fdev->ttm.vram_size /2 ; + + fb_size = mode->hdisplay * mode->vdisplay * max_bpp; +if (fb_size > vram_size_2) +return MODE_MEM ; +return MODE_OK ; }
Signature · 1 line
2.21.0
Re: [PATCH 11/11] drm/fbdevdrm: Detect and validate display modes
Quoted 72 lines · Thomas Zimmermann
Mode detection currently reports the modes listed in
fb_info::modelist. The list is either build from EDID information or, more often, a list of previously set modes. A later update to the mode detection could also take into account the modes infb_monspecs::modedbor test pre-defined VESA modes.Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 163 +++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-)drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +42
-1@@ -21,9 +21,16 @@#include <drm/drm_print.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_device.h" #include "fbdevdrm_modes.h" #include "fbdevdrm_primary.h" +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_connector ( +struct drm_connector *connector) +{ + return container_of(connector, struct fbdevdrm_modeset, connector); +} +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_crtc (struct drm_crtc *crtc) {@@ -353,11 +360,130 @@ static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = {* Connector */ -static int connector_helper_get_modes (struct drm_connector *connector) +static int update_display_info (struct drm_display_info *info,struct fb_info *fb_info) +{ +int num_pixel; + +if (fb_info->fix.type !=FB_TYPE_PACKED_PIXELS ) +return -EINVAL ;/* rule out text mode, etc. */ + +if (fb_info->fix.id[0 ]) { +strncpy (info->name, fb_info->fix.id,sizeof (info->name) -1 ); + info->name[sizeof (info->name) -1 ] ='\0' ; + }else { +memset (info->name,'\0' ,sizeof (info->name)); + } + + info->width_mm = fb_info->var.width; + info->height_mm = fb_info->var.height; + info->pixel_clock =PICOS2KHZ (fb_info->var.pixclock); + + num_pixel =0 ; +if (fb_info->var.red.length) + ++num_pixel; +if (fb_info->var.green.length) + ++num_pixel; +if (fb_info->var.blue.length) + ++num_pixel; +if (fb_info->var.transp.length) + ++num_pixel; + +if (num_pixel) + info->bpc = fb_info->var.bits_per_pixel; +else + info->bpc =0 ; + + info->subpixel_order = SubPixelUnknown; + info->color_formats =DRM_COLOR_FORMAT_RGB444 ;
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = { · line 407
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +10
-0+ info->bus_formats = &info->color_formats; + info->num_bus_formats =1 ; + info->bus_flags =0 ; + info->max_tmds_clock =0 ; + info->dvi_dual = false; + info->has_hdmi_infoframe = false; + info->edid_hdmi_dc_modes =0 ; + info->cea_rev =0 ; +memset (&info->hdmi,0 ,sizeof (info->hdmi)); + info->non_desktop =0 ;
I think the only things here you may want to set are width_mm and height_mm. The rest should not matter.
Quoted 54 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +50
-0+ +return 0 ; +} + +static int drm_mode_probed_add_from_fb_videomode ( +struct drm_connector *connector,const struct fb_videomode *fb_mode, +struct fb_info *fb_info) { +struct drm_display_mode *mode; + + mode =drm_mode_create_from_fb_videomode (connector->dev, fb_mode); +if (!mode) +return -ENOMEM ; + + mode->width_mm = fb_info->var.width; + mode->height_mm = fb_info->var.height; + +drm_mode_probed_add (connector, mode); + +/* update connector properties from display mode */ +if (mode->flags &DRM_MODE_FLAG_INTERLACE ) + connector->interlace_allowed = true; +if (mode->flags &DRM_MODE_FLAG_DBLSCAN ) + connector->doublescan_allowed = true; +if (mode->flags &DRM_MODE_FLAG_3D_MASK ) + connector->stereo_allowed = true; +return 0 ; } +static int connector_helper_get_modes (struct drm_connector *connector) +{ +struct fbdevdrm_modeset *modeset; +struct list_head *pos; +int ret, num_modes =0 ; + + modeset =fbdevdrm_modeset_of_connector (connector); + + ret =update_display_info (&connector->display_info, modeset->fb_info); +if (ret) +return 0 ; + +/* update connector properties from video modes */ + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->stereo_allowed =0 ; + +if (!num_modes && modeset->fb_info->mode) { + ret =drm_mode_probed_add_from_fb_videomode ( + connector, modeset->fb_info->mode, modeset->fb_info); +if (!ret) + ++num_modes; + } +
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = { · line 471
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +10
-0+if (!num_modes) { + +/* DRM backporting notes: we go through all modes in the +* fb_info's mode list and convert each to a DRM modes. If +* you convert an fbdev driver to DRM, replace this code +* with an actual hardware query. This will usually involve +* reading the monitor EDID via DDC. +*/ + +list_for_each (pos, &modeset->fb_info->modelist) {
fbdev has a modelist? I guess it does. But not exposed to userspace, which is probably the reason I never realized this.
Signature · 2 lines
Ville Syrjälä Intel
Re: [PATCH 11/11] drm/fbdevdrm: Detect and validate display modes
Quoted 146 lines · Ville Syrjälä
Quoted 72 lines · Thomas Zimmermann
Mode detection currently reports the modes listed in
fb_info::modelist. The list is either build from EDID information or, more often, a list of previously set modes. A later update to the mode detection could also take into account the modes infb_monspecs::modedbor test pre-defined VESA modes.Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 163 +++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-)drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +42
-1@@ -21,9 +21,16 @@#include <drm/drm_print.h> #include <drm/drm_probe_helper.h> #include <linux/fb.h> +#include "fbdevdrm_device.h" #include "fbdevdrm_modes.h" #include "fbdevdrm_primary.h" +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_connector ( +struct drm_connector *connector) +{ + return container_of(connector, struct fbdevdrm_modeset, connector); +} +static struct fbdevdrm_modeset *fbdevdrm_modeset_of_crtc (struct drm_crtc *crtc) {@@ -353,11 +360,130 @@ static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = {* Connector */ -static int connector_helper_get_modes (struct drm_connector *connector) +static int update_display_info (struct drm_display_info *info,struct fb_info *fb_info) +{ +int num_pixel; + +if (fb_info->fix.type !=FB_TYPE_PACKED_PIXELS ) +return -EINVAL ;/* rule out text mode, etc. */ + +if (fb_info->fix.id[0 ]) { +strncpy (info->name, fb_info->fix.id,sizeof (info->name) -1 ); + info->name[sizeof (info->name) -1 ] ='\0' ; + }else { +memset (info->name,'\0' ,sizeof (info->name)); + } + + info->width_mm = fb_info->var.width; + info->height_mm = fb_info->var.height; + info->pixel_clock =PICOS2KHZ (fb_info->var.pixclock); + + num_pixel =0 ; +if (fb_info->var.red.length) + ++num_pixel; +if (fb_info->var.green.length) + ++num_pixel; +if (fb_info->var.blue.length) + ++num_pixel; +if (fb_info->var.transp.length) + ++num_pixel; + +if (num_pixel) + info->bpc = fb_info->var.bits_per_pixel; +else + info->bpc =0 ; + + info->subpixel_order = SubPixelUnknown; + info->color_formats =DRM_COLOR_FORMAT_RGB444 ;drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = { · line 407
Quoted 10 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +10
-0+ info->bus_formats = &info->color_formats; + info->num_bus_formats =1 ; + info->bus_flags =0 ; + info->max_tmds_clock =0 ; + info->dvi_dual = false; + info->has_hdmi_infoframe = false; + info->edid_hdmi_dc_modes =0 ; + info->cea_rev =0 ; +memset (&info->hdmi,0 ,sizeof (info->hdmi)); + info->non_desktop =0 ;I think the only things here you may want to set are
width_mmandheight_mm. The rest should not matter.Quoted 59 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +55
-0+ +return 0 ; +} + +static int drm_mode_probed_add_from_fb_videomode ( +struct drm_connector *connector,const struct fb_videomode *fb_mode, +struct fb_info *fb_info) { +struct drm_display_mode *mode; + + mode =drm_mode_create_from_fb_videomode (connector->dev, fb_mode); +if (!mode) +return -ENOMEM ; + + mode->width_mm = fb_info->var.width; + mode->height_mm = fb_info->var.height; + +drm_mode_probed_add (connector, mode); + +/* update connector properties from display mode */ +if (mode->flags &DRM_MODE_FLAG_INTERLACE ) + connector->interlace_allowed = true; +if (mode->flags &DRM_MODE_FLAG_DBLSCAN ) + connector->doublescan_allowed = true; +if (mode->flags &DRM_MODE_FLAG_3D_MASK ) + connector->stereo_allowed = true; +return 0 ; } +static int connector_helper_get_modes (struct drm_connector *connector) +{ +struct fbdevdrm_modeset *modeset; +struct list_head *pos; +int ret, num_modes =0 ; + + modeset =fbdevdrm_modeset_of_connector (connector); + + ret =update_display_info (&connector->display_info, modeset->fb_info); +if (ret) +return 0 ; + +/* update connector properties from video modes */ + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->stereo_allowed =0 ; + +if (!num_modes && modeset->fb_info->mode) { + ret =drm_mode_probed_add_from_fb_videomode ( + connector, modeset->fb_info->mode, modeset->fb_info); +if (!ret) + ++num_modes; + } + +if (!num_modes) { + +/* DRM backporting notes: we go through all modes in the +* fb_info's mode list and convert each to a DRM modes. If +* you convert an fbdev driver to DRM, replace this code
Quoted 8 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = { · line 471
Quoted 5 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +5
-0+* with an actual hardware query. This will usually involve +* reading the monitor EDID via DDC. +*/ + +list_for_each (pos, &modeset->fb_info->modelist) {fbdev has a modelist? I guess it does. But not exposed to userspace, which is probably the reason I never realized this.
It's exposed in sysfs.
Don't ask why I know this, it hurts.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Thomas Zimmermann
maintainerRe: [PATCH 11/11] drm/fbdevdrm: Detect and validate display modes
In reply to Ville SyrjäläHi
Am 26.03.19 um 17:47 schrieb Ville Syrjälä:
Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +28
-0+static int connector_helper_get_modes (struct drm_connector *connector) +{ +struct fbdevdrm_modeset *modeset; +struct list_head *pos; +int ret, num_modes =0 ; + + modeset =fbdevdrm_modeset_of_connector (connector); + + ret =update_display_info (&connector->display_info, modeset->fb_info); +if (ret) +return 0 ; + +/* update connector properties from video modes */ + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->stereo_allowed =0 ; + +if (!num_modes && modeset->fb_info->mode) { + ret =drm_mode_probed_add_from_fb_videomode ( + connector, modeset->fb_info->mode, modeset->fb_info); +if (!ret) + ++num_modes; + } + +if (!num_modes) { + +/* DRM backporting notes: we go through all modes in the +* fb_info's mode list and convert each to a DRM modes. If
Quoted 8 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c static const struct drm_encoder_funcs fbdevdrm_encoder_funcs = { · line 471
Quoted 6 lines
drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c +6
-0+* you convert an fbdev driver to DRM, replace this code +* with an actual hardware query. This will usually involve +* reading the monitor EDID via DDC. +*/ + +list_for_each (pos, &modeset->fb_info->modelist) {fbdev has a modelist?
Yes, and its content is surprisingly random! Some drivers fill it with 'real' values coming from DDC probing, some drivers fill it with modes that have worked before, and some drivers fill it with... something.
Best regards
Thomas
I guess it does. But not exposed to
Quoted 2 lines
userspace, which is probably the reason I never realized this.
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Quoted 27 lines · Thomas Zimmermann
Hi,
this RFC patch set implements fbdevdrm, a DRM driver on top of fbdev drivers. I'd appreciate feedback on the code and the idea in general.
The fbdev subsystem is considered legacy and will probably be removed at some point. This would mean the loss of a signifanct number of drivers. Some of the affected hardware is probably not in use any longer, but some hardware is still around and provides good(-enough) framebuffers.
OTOH, userspace programs that want to support a wide range of graphics hardware have to implement support for both DRM and fbdev interfaces. Such software would benefit from a single interface.
The fbdevdrm driver provides a way of running drivers for old and new hardware from the DRM subsystem and interfaces.
It's not intended to add new features or drivers to fbdev. Instead fbdevdrm is supposed to be a template for converting fbdev drivers to DRM. It contains a number of comments (labeled 'DRM porting note') that explain the required steps. The license is fairly liberal to allow for combination with existing fbdev code.
I tested the current patch set with the following drivers: atyfb, aty128fb, matroxfb, pm2fb, s3fb, savagefb, sisfb, tdfxfb and tridentfb. I was able to successfully start with fbcon enabled and then run weston or X.
Quoted 12 lines
Thomas Zimmermann (11):
drm/fbdevdrm: Add driver skeleton drm/fbdevdrm: Add fbdevdrm device drm/fbdevdrm: Add memory management drm/fbdevdrm: Add file operations drm/fbdevdrm: Add GEM and dumb interfaces drm/fbdevdrm: Add modesetting infrastructure drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion drm/fbdevdrm: Add mode conversion DRM <-> fbdev drm/fbdevdrm: Add primary plane
drm/fbdevdrm: Add CRTC
drm/fbdevdrm: Detect and validate display modes
Looks surprisingly clean, at least from a quick read. Only big thing I noticed on the implementation side is that you probably want to use the simple display helpers. At least that's a much better fit for simple display hw supported by these fbdev drivers.
What I'm not sure at all on is whether this is a good idea. It's a quick way of supporting a few drivers we might need from fbdev. But I fear for long-term ecosystem health it'll be a loss: Much less motivation to port the drivers to be native kms ones, and as a result, much less opportunities to extract helpers to make driver writing for such hw easier for everyone.
And the latter is really important, if you look at all the work people have done to improve the modeset helpers. Nowadays we have some examples where the kms native port of an fbdev driver turned out to be 2-3x smaller.
But I also see the benefit of making the fbdev->kms transition smoother. For discussion here's a pretty wild idea that we might want to consider:
- move the ttm based gem code into a helper library like the cma gem helpers. Only special piece we need to pass it is the fb_info structure, for that we can use the same hooks the cma helpers use to allow drivers to specify the right struct device to use for cma allocations. plus ofc an init function for the memory manager and all that, which drivers can put into their driver private device structure
- move the modeset compat code into a helper based on top of the simple display pipe helpers.
- for each fbdev driver we care about:
1. create bare-bones kms driver
2. copypaste the entire fbdev driver code into the drm driver
3. hook up the above two helper libraries, remove the register_framebuffer - I think we can still allocate the fb_info and all that for transition
4. transition the driver over. If we have the helpers a bit split up between display and buffer management side that should be a lot more gradual, and with the fbdevdrm midlayer inserted in the middle.
- Improve the other helpers we have as needed - there's probably room for a simple ttm version, inspired by all these simple display chips (e.g. ast/cirrus/bochs/mga all solve similar problems like this).
- Treat any such drivers as CONFIG_STAGING until they've become fully native, i.e. if no one bothers to convert them, we'll drop them again.
The above is kinda similar in spirit to the transitional helpers we've used to upgrade the big drivers from legacy kms to atomic.
Thoughts?
Cheers, Daniel
Quoted 42 lines
drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 + drivers/gpu/drm/fbdevdrm/Makefile | 11 + drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 ++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 96 +++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 55 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 347 +++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 ++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 195 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 53 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 746 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 38 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 +++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 + 19 files changed, 3120 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h--
2.21.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Thomas Zimmermann
maintainerHi,
first of all, thanks for the detailed feedback.
Am 26.03.19 um 15:53 schrieb Daniel Vetter:
Quoted 41 lines · Thomas Zimmermann
Quoted 27 lines
Hi,
this RFC patch set implements fbdevdrm, a DRM driver on top of fbdev drivers. I'd appreciate feedback on the code and the idea in general.
The fbdev subsystem is considered legacy and will probably be removed at some point. This would mean the loss of a signifanct number of drivers. Some of the affected hardware is probably not in use any longer, but some hardware is still around and provides good(-enough) framebuffers.
OTOH, userspace programs that want to support a wide range of graphics hardware have to implement support for both DRM and fbdev interfaces. Such software would benefit from a single interface.
The fbdevdrm driver provides a way of running drivers for old and new hardware from the DRM subsystem and interfaces.
It's not intended to add new features or drivers to fbdev. Instead fbdevdrm is supposed to be a template for converting fbdev drivers to DRM. It contains a number of comments (labeled 'DRM porting note') that explain the required steps. The license is fairly liberal to allow for combination with existing fbdev code.
I tested the current patch set with the following drivers: atyfb, aty128fb, matroxfb, pm2fb, s3fb, savagefb, sisfb, tdfxfb and tridentfb. I was able to successfully start with fbcon enabled and then run weston or X.
Quoted 12 lines
Thomas Zimmermann (11):
drm/fbdevdrm: Add driver skeleton drm/fbdevdrm: Add fbdevdrm device drm/fbdevdrm: Add memory management drm/fbdevdrm: Add file operations drm/fbdevdrm: Add GEM and dumb interfaces drm/fbdevdrm: Add modesetting infrastructure drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion drm/fbdevdrm: Add mode conversion DRM <-> fbdev drm/fbdevdrm: Add primary plane
drm/fbdevdrm: Add CRTC
drm/fbdevdrm: Detect and validate display modes
Quoted 4 lines
Looks surprisingly clean, at least from a quick read. Only big thing I noticed on the implementation side is that you probably want to use the simple display helpers. At least that's a much better fit for simple display hw supported by these fbdev drivers.
I thought about using the simple-DRM helpers, but found that a full DRM driver would be more helpful for porting over fbdev drivers. Unless simple DRM is a hard requirement, I'd prefer to leave it this way.
For those devices that only support a single pipeline, the conversion to simple DRM should then be mandatory during the porting process.
Quoted 11 lines
What I'm not sure at all on is whether this is a good idea. It's a quick way of supporting a few drivers we might need from fbdev. But I fear for long-term ecosystem health it'll be a loss: Much less motivation to port the drivers to be native kms ones, and as a result, much less opportunities to extract helpers to make driver writing for such hw easier for everyone.
And the latter is really important, if you look at all the work people have done to improve the modeset helpers. Nowadays we have some examples where the kms native port of an fbdev driver turned out to be 2-3x smaller.
I don't disagree with any of this. My intention is to simplify the graphics stack *without* loosing support for all the old hardware. I see fbdevdrm as help for porting drivers, or short-term solution for getting old framebuffer to work.
Quoted 13 lines
But I also see the benefit of making the
fbdev->kmstransition smoother. For discussion here's a pretty wild idea that we might want to consider:- move the ttm based gem code into a helper library like the cma gem helpers. Only special piece we need to pass it is the
fb_infostructure, for that we can use the same hooks the cma helpers use to allow drivers to specify the right struct device to use for cma allocations. plus ofc an init function for the memory manager and all that, which drivers can put into their driver private device structure- move the modeset compat code into a helper based on top of the simple display pipe helpers.
Quoted 9 lines
- for each fbdev driver we care about:
1. create bare-bones kms driver
2. copypaste the entire fbdev driver code into the drm driver
3. hook up the above two helper libraries, remove theregister_framebuffer- I think we can still allocate thefb_infoand all that for transition
4. transition the driver over. If we have the helpers a bit split up between display and buffer management side that should be a lot more gradual, and with the fbdevdrm midlayer inserted in the middle.
I use the current approach because it does not require modifications to DRM or fbdev. Not copying the fbdev driver code has the advantage that any fix that goes into fbdev is also used by fbdevdrm.
OTOH, that has some problems. At least the event-reporting hooks appear to be fragile. You mentioned that you have patches for replacing it. I'd be happy to use something else. Filtering out generic and DRM-based drivers is also not optimal.
Instead of adding the porting helpers to the DRM core, I'd suggest to add them to fbdevdrm. Fbdevdrm would have to duplicate some of the fbdev functionality and provide a replacement for register_framebuffer.
Porting would then mean to
1) create a new DRM driver by copying fbdevdrm, and
2) copy the fbdev driver code to the new DRM driver and rename the
function calls accordingly. At this point the new driver should already work to some extend.
3) Finally, do the refactoring and get it out of staging.
If the fbdev subsystem is ever going to be removed, the remaining drivers could be moved under fbdevdrm and have their function calls adapted. If anyone cares about a driver, it'd be available for refactoring; otherwise it'd just sit there doing nothing. It's all self-contained and doesn't pollute the DRM core.
Quoted 3 lines
- Improve the other helpers we have as needed - there's probably room for a simple ttm version, inspired by all these simple display chips (e.g. ast/cirrus/bochs/mga all solve similar problems like this).
Makes sense, but appears to be unrelated.
Best regards
Thomas
Quoted 53 lines
- Treat any such drivers as
CONFIG_STAGINGuntil they've become fully native, i.e. if no one bothers to convert them, we'll drop them again.The above is kinda similar in spirit to the transitional helpers we've used to upgrade the big drivers from legacy kms to atomic.
Thoughts?
Cheers, Daniel
Quoted 42 lines
drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 + drivers/gpu/drm/fbdevdrm/Makefile | 11 + drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 ++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 96 +++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 55 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 347 +++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 ++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 195 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 53 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 746 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 38 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 +++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 + 19 files changed, 3120 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h--
2.21.0
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Quoted 52 lines · Thomas Zimmermann
Hi,
first of all, thanks for the detailed feedback.
Am 26.03.19 um 15:53 schrieb Daniel Vetter:
Quoted 41 lines · Thomas Zimmermann
Quoted 27 lines
Hi,
this RFC patch set implements fbdevdrm, a DRM driver on top of fbdev drivers. I'd appreciate feedback on the code and the idea in general.
The fbdev subsystem is considered legacy and will probably be removed at some point. This would mean the loss of a signifanct number of drivers. Some of the affected hardware is probably not in use any longer, but some hardware is still around and provides good(-enough) framebuffers.
OTOH, userspace programs that want to support a wide range of graphics hardware have to implement support for both DRM and fbdev interfaces. Such software would benefit from a single interface.
The fbdevdrm driver provides a way of running drivers for old and new hardware from the DRM subsystem and interfaces.
It's not intended to add new features or drivers to fbdev. Instead fbdevdrm is supposed to be a template for converting fbdev drivers to DRM. It contains a number of comments (labeled 'DRM porting note') that explain the required steps. The license is fairly liberal to allow for combination with existing fbdev code.
I tested the current patch set with the following drivers: atyfb, aty128fb, matroxfb, pm2fb, s3fb, savagefb, sisfb, tdfxfb and tridentfb. I was able to successfully start with fbcon enabled and then run weston or X.
Quoted 12 lines
Thomas Zimmermann (11):
drm/fbdevdrm: Add driver skeleton drm/fbdevdrm: Add fbdevdrm device drm/fbdevdrm: Add memory management drm/fbdevdrm: Add file operations drm/fbdevdrm: Add GEM and dumb interfaces drm/fbdevdrm: Add modesetting infrastructure drm/fbdevdrm: Add DRM <-> fbdev pixel-format conversion drm/fbdevdrm: Add mode conversion DRM <-> fbdev drm/fbdevdrm: Add primary plane
drm/fbdevdrm: Add CRTC
drm/fbdevdrm: Detect and validate display modesQuoted 4 lines
Looks surprisingly clean, at least from a quick read. Only big thing I noticed on the implementation side is that you probably want to use the simple display helpers. At least that's a much better fit for simple display hw supported by these fbdev drivers.
Quoted 6 lines
I thought about using the simple-DRM helpers, but found that a full DRM driver would be more helpful for porting over fbdev drivers. Unless simple DRM is a hard requirement, I'd prefer to leave it this way.
For those devices that only support a single pipeline, the conversion to simple DRM should then be mandatory during the porting process.
fbdev only supports a single output, all multi-head extensions are driver specific ioctl hacks. Given that all you can do is switch it on or off (with a given mode), simple pipe helpers are the perfect fit for fbdev.
Some drivers might support more (like multiple heads, or at least different outputs), and those we should convert over. But at least for step 1 in converting fbdev drivers over, simple pipe is the right starting point I think.
Quoted 12 lines
Quoted 11 lines
What I'm not sure at all on is whether this is a good idea. It's a quick way of supporting a few drivers we might need from fbdev. But I fear for long-term ecosystem health it'll be a loss: Much less motivation to port the drivers to be native kms ones, and as a result, much less opportunities to extract helpers to make driver writing for such hw easier for everyone.
And the latter is really important, if you look at all the work people have done to improve the modeset helpers. Nowadays we have some examples where the kms native port of an fbdev driver turned out to be 2-3x smaller.
Quoted 4 lines
I don't disagree with any of this. My intention is to simplify the graphics stack *without* loosing support for all the old hardware. I see fbdevdrm as help for porting drivers, or short-term solution for getting old framebuffer to work.
Simplify for whom? If the goal is to make life easier for userspace I'm not sure - you already need at least legacy kms and atomic kms backends (except for the simplest stuff). And I'm not sure how many lines of code an fbdev backend really is.
Definitely won't simplify things for the kernel, since this way we'll never know which fbdev drivers are dead and which ones we need to keep supporting. This isn't the first time we've just dropped a pile of old hw support on the floor. What we should aim for though is to make the transition as easy as possible for those few drivers that aren't ported yet, but still needed.
Quoted 36 lines
Quoted 13 lines
But I also see the benefit of making the
fbdev->kmstransition smoother. For discussion here's a pretty wild idea that we might want to consider:- move the ttm based gem code into a helper library like the cma gem helpers. Only special piece we need to pass it is the
fb_infostructure, for that we can use the same hooks the cma helpers use to allow drivers to specify the right struct device to use for cma allocations. plus ofc an init function for the memory manager and all that, which drivers can put into their driver private device structure- move the modeset compat code into a helper based on top of the simple display pipe helpers.
Quoted 9 lines
- for each fbdev driver we care about:
1. create bare-bones kms driver
2. copypaste the entire fbdev driver code into the drm driver
3. hook up the above two helper libraries, remove theregister_framebuffer- I think we can still allocate thefb_infoand all that for transition
4. transition the driver over. If we have the helpers a bit split up between display and buffer management side that should be a lot more gradual, and with the fbdevdrm midlayer inserted in the middle.I use the current approach because it does not require modifications to DRM or fbdev. Not copying the fbdev driver code has the advantage that any fix that goes into fbdev is also used by fbdevdrm.
OTOH, that has some problems. At least the event-reporting hooks appear to be fragile. You mentioned that you have patches for replacing it. I'd be happy to use something else. Filtering out generic and DRM-based drivers is also not optimal.
Instead of adding the porting helpers to the DRM core, I'd suggest to add them to fbdevdrm. Fbdevdrm would have to duplicate some of the fbdev functionality and provide a replacement for
register_framebuffer.
Quoted 7 lines
Porting would then mean to
1) create a new DRM driver by copying fbdevdrm, and
2) copy the fbdev driver code to the new DRM driver and rename the
function calls accordingly. At this point the new driver should already work to some extend.
3) Finally, do the refactoring and get it out of staging.
Maybe the idea behind helpers isn't fully clear:
https://blog.ffwll.ch/2016/12/midlayers-once-more-with-feeling.html
The idea with helpers is essentially to have all the flexibility of copypasting (you can refactor as you see fit), without having to actually copypaste a lot of the code. That's why I think an fbdevdrm helper suits, at least as long as we're actively transitioning. Worked fairly well for the atomic transition at least.
Wrt what you need to provide: I think all that needs to be replaced is (un)register_framebuffer - all other fbdev functions and datastructures we should be able to continue to use, even for such a frankendriver transitioning from fbdev to drm.
Quoted 5 lines
If the fbdev subsystem is ever going to be removed, the remaining drivers could be moved under fbdevdrm and have their function calls adapted. If anyone cares about a driver, it'd be available for refactoring; otherwise it'd just sit there doing nothing. It's all self-contained and doesn't pollute the DRM core.
Maybe some confusions:
- We're not going to remove fbdev as long as there's users left. So this scenario isn't one to optimize for. The only thing that's not going to happen is adding more features/drivers to fbdev (except through drm drivers and drm's fbdev compat code).
- I don't think we need to port all drivers over to drm. Most of them are irrelevant by now, letting them quietly die feels like the best action. One reason for copypasting drivers to drm was to make sure there's someone who actually cares enough about that specific driver.
Quoted 5 lines
Quoted 3 lines
- Improve the other helpers we have as needed - there's probably room for a simple ttm version, inspired by all these simple display chips (e.g. ast/cirrus/bochs/mga all solve similar problems like this).
Makes sense, but appears to be unrelated.
It's the main reason to have drivers in upstream - sharing code and infrastructure. At least for me the main benefit in porting a bunch more fbdev drivers over isn't the old hw support (that hw is quietly dying anyway, we just have to wait). But improving support for new hw that fills similar niches, and making it easier for everyone else. Ofc I'm not going to stop anyone who's going to do all the porting work, but we can't realistically require it (e.g. legacy kms drivers also don't support atomic, since simply not possible without rewriting the driver).
Cheers, Daniel
Quoted 65 lines
Best regards
ThomasQuoted 53 lines
- Treat any such drivers as
CONFIG_STAGINGuntil they've become fully native, i.e. if no one bothers to convert them, we'll drop them again.The above is kinda similar in spirit to the transitional helpers we've used to upgrade the big drivers from legacy kms to atomic.
Thoughts?
Cheers, Daniel
Quoted 42 lines
drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 + drivers/gpu/drm/fbdevdrm/Makefile | 11 + drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 ++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 96 +++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 55 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 347 +++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 ++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 195 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 53 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 746 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 38 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 +++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 + 19 files changed, 3120 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h--
2.21.0--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 20 lines · Daniel Vetter
Quoted 7 lines · Thomas Zimmermann
Am 26.03.19 um 15:53 schrieb Daniel Vetter:
Quoted 5 lines
Looks surprisingly clean, at least from a quick read. Only big thing I noticed on the implementation side is that you probably want to use the simple display helpers. At least that's a much better fit for simple display hw supported by these fbdev drivers.
Quoted 6 lines
I thought about using the simple-DRM helpers, but found that a full DRM driver would be more helpful for porting over fbdev drivers. Unless simple DRM is a hard requirement, I'd prefer to leave it this way.
For those devices that only support a single pipeline, the conversion to simple DRM should then be mandatory during the porting process.
fbdev only supports a single output, all multi-head extensions are driver specific ioctl hacks. Given that all you can do is switch it on or off (with a given mode), simple pipe helpers are the perfect fit for fbdev.
Quoted 4 lines
Some drivers might support more (like multiple heads, or at least different outputs), and those we should convert over. But at least for step 1 in converting fbdev drivers over, simple pipe is the right starting point I think.
Converting an fbdev driver to a KMS one loses some features:
1) Dynamically switching modes / colour formats via fbdev.
2) fbcon acceleration (or maybe this can be preserved?).
In turn, it allows exposing additional functionality:
3) Multiple outputs via KMS.
Is there any benefit in converting a driver without adding 3)? If not, is simple pipe still a good starting point?
Signature · 2 lines
Earthling Michel Dänzer | https://www.amd.com Libre software enthusiast | Mesa and X developer
Quoted 22 lines · Michel Dänzer
Quoted 20 lines · Daniel Vetter
Quoted 7 lines · Thomas Zimmermann
Am 26.03.19 um 15:53 schrieb Daniel Vetter:
Quoted 5 lines
Looks surprisingly clean, at least from a quick read. Only big thing I noticed on the implementation side is that you probably want to use the simple display helpers. At least that's a much better fit for simple display hw supported by these fbdev drivers.
Quoted 6 lines
I thought about using the simple-DRM helpers, but found that a full DRM driver would be more helpful for porting over fbdev drivers. Unless simple DRM is a hard requirement, I'd prefer to leave it this way.
For those devices that only support a single pipeline, the conversion to simple DRM should then be mandatory during the porting process.
fbdev only supports a single output, all multi-head extensions are driver specific ioctl hacks. Given that all you can do is switch it on or off (with a given mode), simple pipe helpers are the perfect fit for fbdev.
Quoted 8 lines
Quoted 4 lines
Some drivers might support more (like multiple heads, or at least different outputs), and those we should convert over. But at least for step 1 in converting fbdev drivers over, simple pipe is the right starting point I think.
Converting an fbdev driver to a KMS one loses some features:
1) Dynamically switching modes / colour formats via fbdev.
Possible to add that to drm_fb_helper.c, it's just after 10+ years still no one cares, so it didn't happen. We have added a bunch of fbdev emulation features for stuff people wanted, so patches are welcome. And will be merged, if they exist.
Ofc will be rather limited since fbdev only has one output. But should be possible to at least faithfully map for the simple case of only 1 connected output. Ofc we still can't reallocate the fbdev bo, because fbdev really doesn't like when the aperture moves around. Fixing that is possible, if you fix the fbdev vs. fbcon locking, which is probably a few man-years of engineering (I looked at it recently for reasons, it's totally broken and full of ABBA issues, solved by simply not taking the other lock).
Quoted 1 line
2) fbcon acceleration (or maybe this can be preserved?).
gma500 has fbcon accel. i915 had patches, but wasn't worth it. It's possible, but demand for this seems approximately nil. We do support fbdev page flipping, through the overallocate parameter.
Quoted 3 lines
In turn, it allows exposing additional functionality:
3) Multiple outputs via KMS.
4) multi-master and multi-client (at least if we properly manage the vram with ttm for discrete, socs should use the cma helpers). I think that's the big one, and why compositors might want to have kms even for dumb display hw.
5) on socs: prime buffer sharing, that seems to be the main reason we gained a few fbdev conversion in kms recently
Quoted 2 lines
Is there any benefit in converting a driver without adding 3)? If not, is simple pipe still a good starting point?
simple pipe still allows multiple outputs if they're entirely separate. Only thing it limits is:
1) only 1 fixed plane per crtc
2) fixed crtc->output routing (but with the option to plug in drm_bridge transcoders into that fixed pipeline for code sharing).
I still think simple_pipe is a good starting point for most fbdev drivers left. All the fancy ones that support multiple outputs and output switching do have at least a basic kms driver already. Since atomic helpers are fairly modular (and simple pipe builds on top of atomic helpers) it should be easy to extend from simple pipe to full atomic once necessary.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Thomas Zimmermann
maintainerHi
Am 27.03.19 um 10:41 schrieb Daniel Vetter:
Quoted 23 lines
Quoted 13 lines
I use the current approach because it does not require modifications to DRM or fbdev. Not copying the fbdev driver code has the advantage that any fix that goes into fbdev is also used by fbdevdrm.
OTOH, that has some problems. At least the event-reporting hooks appear to be fragile. You mentioned that you have patches for replacing it. I'd be happy to use something else. Filtering out generic and DRM-based drivers is also not optimal.
Instead of adding the porting helpers to the DRM core, I'd suggest to add them to fbdevdrm. Fbdevdrm would have to duplicate some of the fbdev functionality and provide a replacement for
register_framebuffer.Quoted 7 lines
Porting would then mean to
1) create a new DRM driver by copying fbdevdrm, and
2) copy the fbdev driver code to the new DRM driver and rename the
function calls accordingly. At this point the new driver should already work to some extend.
3) Finally, do the refactoring and get it out of staging.Maybe the idea behind helpers isn't fully clear:
Quoted 7 lines
https://blog.ffwll.ch/2016/12/midlayers-once-more-with-feeling.html
The idea with helpers is essentially to have all the flexibility of copypasting (you can refactor as you see fit), without having to actually copypaste a lot of the code. That's why I think an fbdevdrm helper suits, at least as long as we're actively transitioning. Worked fairly well for the atomic transition at least.
That's not really a problem from my side, but maybe we misunderstood each other.
Modeling fbdevdrm after CMA helpers or simple drm would put it next to central DRM core and helper modules. That seems like an odd place for transitional helper functions that are supposed to be replaced by the actual DRM helpers.
I don't want some kind of abstraction layer. I'm proposing a design like tinydrm, where a separate module offers helpers for fbdev drivers that are about to be converted.
The difference might not be that significant, but just a question of were the code is located.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
- Improve the other helpers we have as needed - there's probably room for a simple ttm version, inspired by all these simple display chips (e.g. ast/cirrus/bochs/mga all solve similar problems like this).
Makes sense, but appears to be unrelated.
It's the main reason to have drivers in upstream - sharing code and infrastructure.
I meant that creating 'simple TTM' is unrelated to fbdevdrm. It would make sense in any case.
Best regards
Thomas
At least for me the main benefit in porting a bunch
Quoted 76 lines
more fbdev drivers over isn't the old hw support (that hw is quietly dying anyway, we just have to wait). But improving support for new hw that fills similar niches, and making it easier for everyone else. Ofc I'm not going to stop anyone who's going to do all the porting work, but we can't realistically require it (e.g. legacy kms drivers also don't support atomic, since simply not possible without rewriting the driver).
Cheers, Daniel
Quoted 65 lines
Best regards
ThomasQuoted 53 lines
- Treat any such drivers as
CONFIG_STAGINGuntil they've become fully native, i.e. if no one bothers to convert them, we'll drop them again.The above is kinda similar in spirit to the transitional helpers we've used to upgrade the big drivers from legacy kms to atomic.
Thoughts?
Cheers, Daniel
Quoted 42 lines
drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 + drivers/gpu/drm/fbdevdrm/Makefile | 11 + drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 ++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 96 +++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 55 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 347 +++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 ++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 195 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 53 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 746 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 38 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 +++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 + 19 files changed, 3120 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h--
2.21.0--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Quoted 35 lines · Thomas Zimmermann
Hi
Am 27.03.19 um 10:41 schrieb Daniel Vetter:
Quoted 23 lines
Quoted 13 lines
I use the current approach because it does not require modifications to DRM or fbdev. Not copying the fbdev driver code has the advantage that any fix that goes into fbdev is also used by fbdevdrm.
OTOH, that has some problems. At least the event-reporting hooks appear to be fragile. You mentioned that you have patches for replacing it. I'd be happy to use something else. Filtering out generic and DRM-based drivers is also not optimal.
Instead of adding the porting helpers to the DRM core, I'd suggest to add them to fbdevdrm. Fbdevdrm would have to duplicate some of the fbdev functionality and provide a replacement for
register_framebuffer.Quoted 7 lines
Porting would then mean to
1) create a new DRM driver by copying fbdevdrm, and
2) copy the fbdev driver code to the new DRM driver and rename the
function calls accordingly. At this point the new driver should already work to some extend.
3) Finally, do the refactoring and get it out of staging.Maybe the idea behind helpers isn't fully clear:
Quoted 7 lines
https://blog.ffwll.ch/2016/12/midlayers-once-more-with-feeling.html
The idea with helpers is essentially to have all the flexibility of copypasting (you can refactor as you see fit), without having to actually copypaste a lot of the code. That's why I think an fbdevdrm helper suits, at least as long as we're actively transitioning. Worked fairly well for the atomic transition at least.
Quoted 7 lines
That's not really a problem from my side, but maybe we misunderstood each other.
Modeling fbdevdrm after CMA helpers or simple drm would put it next to central DRM core and helper modules. That seems like an odd place for transitional helper functions that are supposed to be replaced by the actual DRM helpers.
That's exactly what we've done with the transitional atomic helpers too. I think that's perfectly fine, as long as we put a solid explanation next to the code what it is all about and how to use it.
Quoted 3 lines
I don't want some kind of abstraction layer. I'm proposing a design like tinydrm, where a separate module offers helpers for fbdev drivers that are about to be converted.
We merged tinydrm because reworking it all into proper helpers took a bit longer than what's reasonable to do out-of-tree. But it's disappearing (the very last patch series is pending merge I think now). It worked out well in the end, but I don't think it's a good model to emulate. There's even a patch to rename the directory to make it clear they're full drm drivers, just small one-file ones.
Having an entire driver sit in between the actual driver and drm core feels a lot like a midlayer, and we try very hard to avoid those. -Daniel
Quoted 104 lines
The difference might not be that significant, but just a question of were the code is located.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
- Improve the other helpers we have as needed - there's probably room for a simple ttm version, inspired by all these simple display chips (e.g. ast/cirrus/bochs/mga all solve similar problems like this).
Makes sense, but appears to be unrelated.
It's the main reason to have drivers in upstream - sharing code and infrastructure.
I meant that creating 'simple TTM' is unrelated to fbdevdrm. It would make sense in any case.
Best regards
ThomasAt least for me the main benefit in porting a bunch
Quoted 8 lines
more fbdev drivers over isn't the old hw support (that hw is quietly dying anyway, we just have to wait). But improving support for new hw that fills similar niches, and making it easier for everyone else. Ofc I'm not going to stop anyone who's going to do all the porting work, but we can't realistically require it (e.g. legacy kms drivers also don't support atomic, since simply not possible without rewriting the driver).
Quoted 68 lines
Cheers, Daniel
Quoted 65 lines
Best regards
ThomasQuoted 53 lines
- Treat any such drivers as
CONFIG_STAGINGuntil they've become fully native, i.e. if no one bothers to convert them, we'll drop them again.The above is kinda similar in spirit to the transitional helpers we've used to upgrade the big drivers from legacy kms to atomic.
Thoughts?
Cheers, Daniel
Quoted 42 lines
drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fbdevdrm/Kconfig | 13 + drivers/gpu/drm/fbdevdrm/Makefile | 11 + drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c | 276 ++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h | 58 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c | 96 +++ drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h | 55 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c | 347 +++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c | 441 ++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h | 26 + drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c | 195 +++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h | 53 ++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c | 746 ++++++++++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h | 38 + drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c | 498 +++++++++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h | 27 + drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c | 202 ++++++ drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h | 35 + 19 files changed, 3120 insertions(+) create mode 100644 drivers/gpu/drm/fbdevdrm/Kconfig create mode 100644 drivers/gpu/drm/fbdevdrm/Makefile create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_bo.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_device.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_drv.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_format.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modes.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_modeset.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_primary.h create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.c create mode 100644 drivers/gpu/drm/fbdevdrm/fbdevdrm_ttm.h--
2.21.0--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch