drm: Support simple-framebuffer devices and firmware fbs
Subsystems (5)
Thomas Zimmermann
maintainerv2 cover drm: Support simple-framebuffer devices and firmware fbs
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbs
v2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups
[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/
Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch to drm_fb_memcpy_dstclip() drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers into drm_aperture.h drm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebuffer
Documentation/gpu/drm-internals.rst | 12 + MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +- 14 files changed, 1466 insertions(+), 60 deletions(-) create mode 100644 drivers/gpu/drm/drm_aperture.c create mode 100644 drivers/gpu/drm/tiny/simpledrm.c create mode 100644 include/drm/drm_aperture.h
--
2.30.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v2 1/10 drm/format-helper: Pass destination pitch to drm_fb_memcpy_dstclip()
The memcpy's destination buffer might have a different pitch than the source. Support different pitches as function argument.
--- drivers/gpu/drm/drm_format_helper.c | 9 +++++---- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/tiny/cirrus.c | 2 +- include/drm/drm_format_helper.h | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_format_helper.c +5 -4
@@ -52,6 +52,7 @@ EXPORT_SYMBOL(drm_fb_memcpy);/** * drm_fb_memcpy_dstclip - Copy clip buffer * @dst: Destination buffer (iomem) +* @dst_pitch: Number of bytes between two consecutive scanlines within dst * @vaddr: Source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy
@@ -59,12 +60,12 @@ EXPORT_SYMBOL(drm_fb_memcpy);* This function applies clipping on dst, i.e. the destination is a * full (iomem) framebuffer but only the clip rect content is copied over. */ -void drm_fb_memcpy_dstclip (void __iomem *dst,void *vaddr, -struct drm_framebuffer *fb, +void drm_fb_memcpy_dstclip (void __iomem *dst,unsigned int dst_pitch, +void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip) {unsigned int cpp = fb->format->cpp[0 ]; -unsigned int offset =clip_offset (clip, fb->pitches[0 ], cpp); +unsigned int offset =clip_offset (clip, dst_pitch, cpp);size_t len = (clip->x2 - clip->x1) * cpp;unsigned int y, lines = clip->y2 - clip->y1;
@@ -73,7 +74,7 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,for (y =0 ; y < lines; y++) {memcpy_toio (dst, vaddr, len); vaddr += fb->pitches[0 ]; - dst += fb->pitches[0 ]; + dst += dst_pitch; } }EXPORT_SYMBOL (drm_fb_memcpy_dstclip);
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -1
@@ -1554,7 +1554,7 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, {void *vmap = map->vaddr;/* TODO: Use mapping abstraction properly */ -drm_fb_memcpy_dstclip (mdev->vram, vmap, fb, clip); +drm_fb_memcpy_dstclip (mdev->vram, fb->pitches[0 ], vmap, fb, clip);/* Always scanout image at VRAM offset 0 */ mgag200_set_startadd (mdev, (u32 )0 );
drivers/gpu/drm/tiny/cirrus.c +1 -1
@@ -323,7 +323,7 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, const struct dma_buf_return -ENODEV ;if (cirrus->cpp == fb->format->cpp[0 ]) -drm_fb_memcpy_dstclip (cirrus->vram, +drm_fb_memcpy_dstclip (cirrus->vram, fb->pitches[0 ], vmap, fb, rect);else if (fb->format->cpp[0 ] ==4 && cirrus->cpp ==2 )
include/drm/drm_format_helper.h +1 -1
@@ -11,7 +11,7 @@ struct drm_rect;void drm_fb_memcpy (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip); -void drm_fb_memcpy_dstclip (void __iomem *dst,void *vaddr, +void drm_fb_memcpy_dstclip (void __iomem *dst,unsigned int dst_pitch,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip); void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v2 2/10 drm/format-helper: Add blitter functions
In reply to Thomas ZimmermannThe blitter functions copy a framebuffer to I/O memory using one of the existing conversion functions.
--- drivers/gpu/drm/drm_format_helper.c | 87 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 8 +++ 2 files changed, 95 insertions(+)
drivers/gpu/drm/drm_format_helper.c +87 -0
@@ -344,3 +344,90 @@ void drm_fb_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_xrgb8888_to_gray8); +/** +* drm_fb_blit_rect_dstclip - Copy parts of a framebuffer to display memory +* @dst: The display memory to copy to +* @dst_pitch: Number of bytes between two consecutive scanlines within dst +* @dst_format: FOURCC code of the display's color format +* @vmap: The framebuffer memory to copy from +* @fb: The framebuffer to copy from +* @clip: Clip rectangle area to copy +* +* This function copies parts of a framebuffer to display memory. If the +* formats of the display and the framebuffer mismatch, the blit function +* will attempt to convert between them. +* +* Use drm_fb_blit_dstclip() to copy the full framebuffer. +* +* Returns: +* 0 on success, or +* -EINVAL if the color-format conversion failed, or +* a negative error code otherwise. +*/ +int drm_fb_blit_rect_dstclip (void __iomem *dst,unsigned int dst_pitch, +uint32_t dst_format,void *vmap, +struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +uint32_t fb_format = fb->format->format; + +/* treat alpha channel like filler bits */ +if (fb_format ==DRM_FORMAT_ARGB8888 ) + fb_format =DRM_FORMAT_XRGB8888 ; +if (dst_format ==DRM_FORMAT_ARGB8888 ) + dst_format =DRM_FORMAT_XRGB8888 ; + +if (dst_format == fb_format) { +drm_fb_memcpy_dstclip (dst, dst_pitch, vmap, fb, clip); +return 0 ; + + }else if (dst_format ==DRM_FORMAT_RGB565 ) { +if (fb_format ==DRM_FORMAT_XRGB8888 ) { +drm_fb_xrgb8888_to_rgb565_dstclip (dst, dst_pitch, + vmap, fb, clip, + false); +return 0 ; + } + }else if (dst_format ==DRM_FORMAT_RGB888 ) { +if (fb_format ==DRM_FORMAT_XRGB8888 ) { +drm_fb_xrgb8888_to_rgb888_dstclip (dst, dst_pitch, + vmap, fb, clip); +return 0 ; + } + } + +return -EINVAL ; +} +EXPORT_SYMBOL (drm_fb_blit_rect_dstclip); + +/** +* drm_fb_blit_dstclip - Copy framebuffer to display memory +* @dst: The display memory to copy to +* @dst_pitch: Number of bytes between two consecutive scanlines within dst +* @dst_format: FOURCC code of the display's color format +* @vmap: The framebuffer memory to copy from +* @fb: The framebuffer to copy from +* +* This function copies a full framebuffer to display memory. If the formats +* of the display and the framebuffer mismatch, the copy function will +* attempt to convert between them. +* +* See drm_fb_blit_rect_dstclip() for more inforamtion. +* +* Returns: +* 0 on success, or a negative error code otherwise. +*/ +int drm_fb_blit_dstclip (void __iomem *dst,unsigned int dst_pitch, +uint32_t dst_format,void *vmap, +struct drm_framebuffer *fb) +{ +struct drm_rect fullscreen = { + .x1 =0 , + .x2 = fb->width, + .y1 =0 , + .y2 = fb->height, + }; +return drm_fb_blit_rect_dstclip (dst, dst_pitch, dst_format, vmap, fb, + &fullscreen); +} +EXPORT_SYMBOL (drm_fb_blit_dstclip);
include/drm/drm_format_helper.h +8 -0
@@ -28,4 +28,12 @@ void drm_fb_xrgb8888_to_rgb888_dstclip(void __iomem *dst, unsigned int dst_pitchvoid drm_fb_xrgb8888_to_gray8 (u8 *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip); +int drm_fb_blit_rect_dstclip (void __iomem *dst,unsigned int dst_pitch, +uint32_t dst_format,void *vmap, +struct drm_framebuffer *fb, +struct drm_rect *rect); +int drm_fb_blit_dstclip (void __iomem *dst,unsigned int dst_pitch, +uint32_t dst_format,void *vmap, +struct drm_framebuffer *fb); +#endif /* __LINUX_DRM_FORMAT_HELPER_H */
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v2 3/10 drm/aperture: Move fbdev conflict helpers into drm_aperture.h
In reply to Thomas ZimmermannFbdev's helpers for handling conflicting framebuffers are related to framebuffer apertures, not console emulation. Therefore move them into a drm_aperture.h, which will contain the interfaces for the new aperture helpers.
--- Documentation/gpu/drm-internals.rst | 6 +++ include/drm/drm_aperture.h | 60 +++++++++++++++++++++++++++++ include/drm/drm_fb_helper.h | 56 ++------------------------- 3 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 include/drm/drm_aperture.h
Documentation/gpu/drm-internals.rst +6 -0
@@ -75,6 +75,12 @@ update it, its value is mostly useless. The DRM core prints it to the kernel log at initialization time and passes it to userspace through the DRM_IOCTL_VERSION ioctl. +Managing Ownership of the Framebuffer Aperture +---------------------------------------------- + +.. kernel-doc:: include/drm/drm_aperture.h + :internal: + Device Instance and Driver Handling -----------------------------------
include/drm/drm_aperture.h new file +60 -0
60 lines not on this page · raw message
include/drm/drm_fb_helper.h +3 -53
70 lines not on this page · raw message
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 03/10] drm/aperture: Move fbdev conflict helpers into drm_aperture.h
Quoted 37 lines · Thomas Zimmermann
Fbdev's helpers for handling conflicting framebuffers are related to framebuffer apertures, not console emulation. Therefore move them into a
drm_aperture.h, which will contain the interfaces for the new aperture helpers.Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>--- Documentation/gpu/drm-internals.rst | 6 +++ include/drm/drm_aperture.h | 60 +++++++++++++++++++++++++++++ include/drm/drm_fb_helper.h | 56 ++------------------------- 3 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 include/drm/drm_aperture.hDocumentation/gpu/drm-internals.rst +6
-0@@ -75,6 +75,12 @@ update it, its value is mostly useless. The DRM core prints it to the kernel log at initialization time and passes it to userspace through the DRM_IOCTL_VERSION ioctl. +Managing Ownership of the Framebuffer Aperture +---------------------------------------------- + +.. kernel-doc:: include/drm/drm_aperture.h + :internal: + Device Instance and Driver Handling -----------------------------------include/drm/drm_aperture.h new file +0
-0
include/drm/drm_aperture.h line 10
Quoted 10 lines
include/drm/drm_aperture.h new file +10
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef _DRM_APERTURE_H_ +#define _DRM_APERTURE_H_ + +#include <linux/fb.h> +#include <linux/vgaarb.h> + +/** +* drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers
Annoying bikeshed, but I'd give them drm_aperture_ prefixes, for ocd consistency. Also make them real functions, they're quite big and will grow more in the next patch.
I'm also not super happy about the naming here but oh well.
Either way: Acked-by: Daniel Vetter <[email protected]>
Quoted 129 lines
include/drm/drm_aperture.h new file +50
-0+* @a: memory range, users of which are to be removed +* @name: requesting driver name +* @primary: also kick vga16fb if present +* +* This function removes framebuffer devices (initialized by firmware/bootloader) +* which use memory range described by @a. If @a is NULL all such devices are +* removed. +*/ +static inline int +drm_fb_helper_remove_conflicting_framebuffers (struct apertures_struct *a, +const char *name,bool primary) +{ +#if IS_REACHABLE (CONFIG_FB ) +return remove_conflicting_framebuffers (a, name, primary); +#else +return 0 ; +#endif +} + +/** +* drm_fb_helper_remove_conflicting_pci_framebuffers - remove firmware-configured +* framebuffers for PCI devices +* @pdev: PCI device +* @name: requesting driver name +* +* This function removes framebuffer devices (eg. initialized by firmware) +* using memory range configured for any of @pdev's memory bars. +* +* The function assumes that PCI device with shadowed ROM drives a primary +* display and so kicks out vga16fb. +*/ +static inline int +drm_fb_helper_remove_conflicting_pci_framebuffers (struct pci_dev *pdev, +const char *name) +{ +int ret =0 ; + +/* +* WARNING: Apparently we must kick fbdev drivers before vgacon, +* otherwise the vga fbdev driver falls over. +*/ +#if IS_REACHABLE (CONFIG_FB ) + ret =remove_conflicting_pci_framebuffers (pdev, name); +#endif +if (ret ==0 ) + ret =vga_remove_vgacon (pdev); +return ret; +} + +#endif include/drm/drm_fb_helper.h +3
-53@@ -30,13 +30,13 @@#ifndef DRM_FB_HELPER_H #define DRM_FB_HELPER_H -struct drm_fb_helper ; - +#include <drm/drm_aperture.h> #include <drm/drm_client.h> #include <drm/drm_crtc.h> #include <drm/drm_device.h> #include <linux/kgdb.h> -#include <linux/vgaarb.h> + +struct drm_fb_helper ;enum mode_set_atomic { LEAVE_ATOMIC_MODE_SET,@@ -451,54 +451,4 @@ drm_fbdev_generic_setup(struct drm_device *dev, unsigned int preferred_bpp)#endif -/** -* drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers -* @a: memory range, users of which are to be removed -* @name: requesting driver name -* @primary: also kick vga16fb if present -* -* This function removes framebuffer devices (initialized by firmware/bootloader) -* which use memory range described by @a. If @a is NULL all such devices are -* removed. -*/ -static inline int -drm_fb_helper_remove_conflicting_framebuffers (struct apertures_struct *a, -const char *name,bool primary) -{ -#if IS_REACHABLE (CONFIG_FB ) -return remove_conflicting_framebuffers (a, name, primary); -#else -return 0 ; -#endif -} - -/** -* drm_fb_helper_remove_conflicting_pci_framebuffers - remove firmware-configured framebuffers for PCI devices -* @pdev: PCI device -* @name: requesting driver name -* -* This function removes framebuffer devices (eg. initialized by firmware) -* using memory range configured for any of @pdev's memory bars. -* -* The function assumes that PCI device with shadowed ROM drives a primary -* display and so kicks out vga16fb. -*/ -static inline int -drm_fb_helper_remove_conflicting_pci_framebuffers (struct pci_dev *pdev, -const char *name) -{ -int ret =0 ; - -/* -* WARNING: Apparently we must kick fbdev drivers before vgacon, -* otherwise the vga fbdev driver falls over. -*/ -#if IS_REACHABLE (CONFIG_FB ) - ret =remove_conflicting_pci_framebuffers (pdev, name); -#endif -if (ret ==0 ) - ret =vga_remove_vgacon (pdev); -return ret; -} -#endif Signature · 1 line
2.30.1
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v2 03/10] drm/aperture: Move fbdev conflict helpers into drm_aperture.h
Hi
Am 08.04.21 um 11:50 schrieb Daniel Vetter:
Quoted 53 lines · Thomas Zimmermann
Quoted 37 lines
Fbdev's helpers for handling conflicting framebuffers are related to framebuffer apertures, not console emulation. Therefore move them into a
drm_aperture.h, which will contain the interfaces for the new aperture helpers.Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>--- Documentation/gpu/drm-internals.rst | 6 +++ include/drm/drm_aperture.h | 60 +++++++++++++++++++++++++++++ include/drm/drm_fb_helper.h | 56 ++------------------------- 3 files changed, 69 insertions(+), 53 deletions(-)create mode 100644
include/drm/drm_aperture.hDocumentation/gpu/drm-internals.rst +6
-0@@ -75,6 +75,12 @@ update it, its value is mostly useless. The DRM core prints it to the kernel log at initialization time and passes it to userspace through the DRM_IOCTL_VERSION ioctl. +Managing Ownership of the Framebuffer Aperture +---------------------------------------------- + +.. kernel-doc:: include/drm/drm_aperture.h + :internal: + Device Instance and Driver Handling -----------------------------------include/drm/drm_aperture.h new file +0
-0include/drm/drm_aperture.h line 10
Quoted 10 lines
include/drm/drm_aperture.h new file +10
-0@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef _DRM_APERTURE_H_ +#define _DRM_APERTURE_H_ + +#include <linux/fb.h> +#include <linux/vgaarb.h> + +/** +* drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers Annoying bikeshed, but I'd give them
drm_aperture_prefixes, for ocd consistency. Also make them real functions, they're quite big and will grow more in the next patch.
Quoted 1 line
I'm also not super happy about the naming here but oh well.
The original name for this was platform helpers, which was worse. So it's not like we're not improving. :)
I'll take this patch + some docs from patch 4 + your feedback and turn it into a separate patchset. It should be useful even without simpledrm.
Best regards
Thomas
Quoted 133 lines
Either way: Acked-by: Daniel Vetter <[email protected]>
Quoted 129 lines
include/drm/drm_aperture.h new file +50
-0+* @a: memory range, users of which are to be removed +* @name: requesting driver name +* @primary: also kick vga16fb if present +* +* This function removes framebuffer devices (initialized by firmware/bootloader) +* which use memory range described by @a. If @a is NULL all such devices are +* removed. +*/ +static inline int +drm_fb_helper_remove_conflicting_framebuffers (struct apertures_struct *a, +const char *name,bool primary) +{ +#if IS_REACHABLE (CONFIG_FB ) +return remove_conflicting_framebuffers (a, name, primary); +#else +return 0 ; +#endif +} + +/** +* drm_fb_helper_remove_conflicting_pci_framebuffers - remove firmware-configured +* framebuffers for PCI devices +* @pdev: PCI device +* @name: requesting driver name +* +* This function removes framebuffer devices (eg. initialized by firmware) +* using memory range configured for any of @pdev's memory bars. +* +* The function assumes that PCI device with shadowed ROM drives a primary +* display and so kicks out vga16fb. +*/ +static inline int +drm_fb_helper_remove_conflicting_pci_framebuffers (struct pci_dev *pdev, +const char *name) +{ +int ret =0 ; + +/* +* WARNING: Apparently we must kick fbdev drivers before vgacon, +* otherwise the vga fbdev driver falls over. +*/ +#if IS_REACHABLE (CONFIG_FB ) + ret =remove_conflicting_pci_framebuffers (pdev, name); +#endif +if (ret ==0 ) + ret =vga_remove_vgacon (pdev); +return ret; +} + +#endif include/drm/drm_fb_helper.h +3
-53@@ -30,13 +30,13 @@#ifndef DRM_FB_HELPER_H #define DRM_FB_HELPER_H -struct drm_fb_helper ; - +#include <drm/drm_aperture.h> #include <drm/drm_client.h> #include <drm/drm_crtc.h> #include <drm/drm_device.h> #include <linux/kgdb.h> -#include <linux/vgaarb.h> + +struct drm_fb_helper ;enum mode_set_atomic { LEAVE_ATOMIC_MODE_SET,@@ -451,54 +451,4 @@ drm_fbdev_generic_setup(struct drm_device *dev, unsigned int preferred_bpp)#endif -/** -* drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers -* @a: memory range, users of which are to be removed -* @name: requesting driver name -* @primary: also kick vga16fb if present -* -* This function removes framebuffer devices (initialized by firmware/bootloader) -* which use memory range described by @a. If @a is NULL all such devices are -* removed. -*/ -static inline int -drm_fb_helper_remove_conflicting_framebuffers (struct apertures_struct *a, -const char *name,bool primary) -{ -#if IS_REACHABLE (CONFIG_FB ) -return remove_conflicting_framebuffers (a, name, primary); -#else -return 0 ; -#endif -} - -/** -* drm_fb_helper_remove_conflicting_pci_framebuffers - remove firmware-configured framebuffers for PCI devices -* @pdev: PCI device -* @name: requesting driver name -* -* This function removes framebuffer devices (eg. initialized by firmware) -* using memory range configured for any of @pdev's memory bars. -* -* The function assumes that PCI device with shadowed ROM drives a primary -* display and so kicks out vga16fb. -*/ -static inline int -drm_fb_helper_remove_conflicting_pci_framebuffers (struct pci_dev *pdev, -const char *name) -{ -int ret =0 ; - -/* -* WARNING: Apparently we must kick fbdev drivers before vgacon, -* otherwise the vga fbdev driver falls over. -*/ -#if IS_REACHABLE (CONFIG_FB ) - ret =remove_conflicting_pci_framebuffers (pdev, name); -#endif -if (ret ==0 ) - ret =vga_remove_vgacon (pdev); -return ret; -} -#endif Signature · 1 line
2.30.1
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v2 4/10 drm/aperture: Add infrastructure for aperture ownership
In reply to Thomas ZimmermannPlatform devices might operate on firmware framebuffers, such as VESA or EFI. Before a native driver for the graphics hardware can take over the device, it has to remove any platform driver that operates on the firmware framebuffer. Aperture helpers provide the infrastructure for platform drivers to acquire firmware framebuffers, and for native drivers to remove them later on.
It works similar to the related fbdev mechanism. During initialization, the platform driver acquires the firmware framebuffer's I/O memory and provides a callback to be removed. The native driver later uses this information to remove any platform driver for it's framebuffer I/O memory.
The aperture removal code is integrated into the existing code for removing conflicting framebuffers, so native drivers use it automatically.
v2:
* rename plaform helpers to aperture helpers
* tie to device lifetime with devm_ functions
* removed unsued remove() callback
* rename kickout to detach
* make struct drm_aperture private
* rebase onto existing drm_aperture.h header file
* use MIT license only for simplicity
* documentation
--- Documentation/gpu/drm-internals.rst | 6 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++++++++++++++++++++++ include/drm/drm_aperture.h | 38 +++- 5 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_aperture.c
Documentation/gpu/drm-internals.rst +6 -0
@@ -78,9 +78,15 @@ DRM_IOCTL_VERSION ioctl. Managing Ownership of the Framebuffer Aperture ---------------------------------------------- +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :doc: overview + .. kernel-doc:: include/drm/drm_aperture.h :internal: +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :export: + Device Instance and Driver Handling -----------------------------------
drivers/gpu/drm/Kconfig +7 -0
@@ -221,6 +221,13 @@ config DRM_SCHED tristate depends on DRM +config DRM_APERTURE + bool + depends on DRM + help + Controls ownership of graphics apertures. Required to + synchronize with firmware-based drivers. + source "drivers/gpu/drm/i2c/Kconfig" source "drivers/gpu/drm/arm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_PCI) += drm_pci.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_APERTURE) += drm_aperture.o drm_vram_helper-y := drm_gem_vram_helper.o obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.o
drivers/gpu/drm/drm_aperture.c new file +287 -0
287 lines not on this page · raw message
include/drm/drm_aperture.h +37 -1
@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed
@@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else
@@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon,
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Quoted 25 lines · Thomas Zimmermann
Platform devices might operate on firmware framebuffers, such as VESA or EFI. Before a native driver for the graphics hardware can take over the device, it has to remove any platform driver that operates on the firmware framebuffer. Aperture helpers provide the infrastructure for platform drivers to acquire firmware framebuffers, and for native drivers to remove them later on.
It works similar to the related fbdev mechanism. During initialization, the platform driver acquires the firmware framebuffer's I/O memory and provides a callback to be removed. The native driver later uses this information to remove any platform driver for it's framebuffer I/O memory.
The aperture removal code is integrated into the existing code for removing conflicting framebuffers, so native drivers use it automatically.
v2:
* rename plaform helpers to aperture helpers
* tie to device lifetime withdevm_functions
* removed unsuedremove()callback
* rename kickout to detach
* make structdrm_apertureprivate
* rebase onto existingdrm_aperture.hheader file
* use MIT license only for simplicity
* documentation
Quoted 2 lines
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>
Bunch of bikesheds for your considerations below, but overall lgtm.
Cheers, Daniel
Quoted 34 lines
--- Documentation/gpu/drm-internals.rst | 6 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++++++++++++++++++++++ include/drm/drm_aperture.h | 38 +++- 5 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_aperture.cDocumentation/gpu/drm-internals.rst +6
-0@@ -78,9 +78,15 @@ DRM_IOCTL_VERSION ioctl. Managing Ownership of the Framebuffer Aperture ---------------------------------------------- +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :doc: overview + .. kernel-doc:: include/drm/drm_aperture.h :internal: +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :export: + Device Instance and Driver Handling -----------------------------------drivers/gpu/drm/Kconfig +0
-0
drivers/gpu/drm/Kconfig config DRM_SCHED · line 229
Quoted 9 lines
drivers/gpu/drm/Kconfig +6
-0@@ -221,6 +221,13 @@ config DRM_SCHED tristate depends on DRM +config DRM_APERTURE + bool + depends on DRM + help + Controls ownership of graphics apertures. Required to + synchronize with firmware-based drivers.
Uh I'm not a big fan of Kconfig and .ko modules for every little helper code. Imo just stuff this into the drm kms helpers and done. Or stuff it into drm core code, I think either is a good case for this. Everything is its own module means we need to EXPORT_SYMBOL more stuff, and then drivers get funny ideas about using these internals ...
Quoted 84 lines
drivers/gpu/drm/Kconfig +1
-0+ source "drivers/gpu/drm/i2c/Kconfig" source "drivers/gpu/drm/arm/Kconfig"drivers/gpu/drm/Makefile +1
-0@@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_PCI) += drm_pci.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_APERTURE) += drm_aperture.o drm_vram_helper-y := drm_gem_vram_helper.o obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.odrivers/gpu/drm/drm_aperture.c new file +62
-0@@ -0,0 +1,287 @@ +// SPDX-License-Identifier: MIT + +#include <linux/device.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/types.h> + +#include <drm/drm_aperture.h> +#include <drm/drm_drv.h> +#include <drm/drm_print.h> + +/** +* DOC: overview +* +* A graphics device might be supported by different drivers, but only one +* driver can be active at any given time. Many systems load a generic +* graphics drivers, such as EFI-GOP or VESA, early during the boot process. +* During later boot stages, they replace the generic driver with a dedicated, +* hardware-specific driver. To take over the device the dedicated driver +* first has to remove the generic driver. DRM aperture functions manage +* ownership of DRM framebuffer memory and hand-over between drivers. +* +* DRM drivers should call drm_fb_helper_remove_conflicting_framebuffers() +* at the top of their probe function. The function removes any generic +* driver that is currently associated with the given framebuffer memory. +* If the framebuffer is located at PCI BAR 0, the rsp code looks as in the +* example given below. +* +* .. code-block:: c +* +* static int remove_conflicting_framebuffers(struct pci_dev *pdev) +* { +* struct apertures_struct *ap; +* bool primary = false; +* int ret; +* +* ap = alloc_apertures(1); +* if (!ap) +* return -ENOMEM; +* +* ap->ranges[0].base = pci_resource_start(pdev, 0); +* ap->ranges[0].size = pci_resource_len(pdev, 0); +* +* #ifdef CONFIG_X86 +* primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; +* #endif +* ret = drm_fb_helper_remove_conflicting_framebuffers(ap, "example driver", primary); +* kfree(ap); +* +* return ret; +* } +* +* static int probe(struct pci_dev *pdev) +* { +* int ret; +* +* // Remove any generic drivers... +* ret = remove_conflicting_framebuffers(pdev); +* if (ret) +* return ret; +*
drivers/gpu/drm/drm_aperture.c line 72
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+* // ... and initialize the hardware. +* ... +* +* drm_dev_register(); +* +* return 0; +* } +* +* For PCI devices it is often sufficient to use drm_fb_helper_remove_conflicting_pci_framebuffers() +* and let it detect the framebuffer apertures automatically.
Maybe just me, but to avoid overstretching the attention spawn of doc readers I'd avoid this example here. And maybe make the recommendation stronger, e.g. "PCI device drivers can avoid open-coding remove_conflicting_framebuffers() by calling drm_fb_helper_remove_conflicting_pci_framebuffers()."
Quoted 21 lines
drivers/gpu/drm/drm_aperture.c new file +21
-0+* +* .. code-block:: c +* +* static int probe(struct pci_dev *pdev) +* { +* int ret; +* +* // Remove any generic drivers... +* ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "example driver"); +* if (ret) +* return ret; +* +* // ... and initialize the hardware. +* ... +* +* drm_dev_register(); +* +* return 0; +* } +* +* Drivers that are susceptible to being removed be other drivers, such as
drivers/gpu/drm/drm_aperture.c line 103
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+* generic EFI or VESA drivers, have to register themselves as owners of their +* given framebuffer memory. Ownership of the framebuffer memory is achived +* by calling devm_aperture_acquire(). On success, the driver is the owner +* of the framebuffer range. The function fails if the framebuffer is already +* by another driver. See below for an example. +* +* .. code-block:: c +* +* static struct drm_aperture_funcs ap_funcs = { +* .detach = ...
Is there really value in allowing/forcing drivers to set up their own detach ops? You already make this specific to struct drm_device, an implementation that just calls drm_dev_unplug feels like the right thing to do?
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
drivers/gpu/drm/drm_aperture.c new file +84
-0+* }; +* +* static int acquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev) +* { +* resource_size_t start, len; +* struct drm_aperture *ap; +* +* base = pci_resource_start(pdev, 0); +* size = pci_resource_len(pdev, 0); +* +* ap = devm_acquire_aperture(dev, base, size, &ap_funcs); +* if (IS_ERR(ap)) +* return PTR_ERR(ap); +* +* return 0; +* } +* +* static int probe(struct pci_dev *pdev) +* { +* struct drm_device *dev; +* int ret; +* +* // ... Initialize the device... +* dev = devm_drm_dev_alloc(); +* ... +* +* // ... and acquire ownership of the framebuffer. +* ret = acquire_framebuffers(dev, pdev); +* if (ret) +* return ret; +* +* drm_dev_register(); +* +* return 0; +* } +* +* The generic driver is now subject to forced removal by other drivers. This +* is when the detach function in struct &drm_aperture_funcs comes into play. +* When a driver calls drm_fb_helper_remove_conflicting_framebuffers() et al +* for the registered framebuffer range, the DRM core calls struct +* &drm_aperture_funcs.detach and the generic driver has to onload itself. It +* may not access the device's registers, framebuffer memory, ROM, etc after +* detach returned. If the driver supports hotplugging, detach can be treated +* like an unplug event. +* +* .. code-block:: c +* +* static void detach_from_device(struct drm_device *dev, +* resource_size_t base, +* resource_size_t size) +* { +* // Signal unplug +* drm_dev_unplug(dev); +* +* // Maybe do other clean-up operations +* ... +* } +* +* static struct drm_aperture_funcs ap_funcs = { +* .detach = detach_from_device, +* }; +*/ + +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)
drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)
Uh this needs a comment that if ap->dev is NULL then we're called from drm_aperture_detach_drivers() and hence the lock is already held.
drivers/gpu/drm/drm_aperture.c line 198
Quoted 1 line
drivers/gpu/drm/drm_aperture.c new file +1
-0+mutex_lock (&drm_apertures_lock);
and an
else locdep_assert_held(&drm_apertures_lock);
here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 79 lines
drivers/gpu/drm/drm_aperture.c new file +79
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on behalf of a DRM driver. +* @dev: the DRM device to own the framebuffer memory +* @base: the framebuffer's byte offset in physical memory +* @size: the framebuffer size in bytes +* @funcs: callback functions +* +* Installs the given device as the new owner. The function fails if the +* framebuffer range, or parts of it, is currently owned by another driver. +* To evict current owners, callers should use +* drm_fb_helper_remove_conflicting_framebuffers() et al. before calling this +* function. Acquired apertures are released automatically if the underlying +* device goes away. +* +* Returns: +* An instance of struct &drm_aperture on success, or a pointer-encoded +* errno value otherwise. +*/ +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ;
drivers/gpu/drm/drm_aperture.c line 287
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+ + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size); + } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);
Is this just exported because of the inline functions in the headers? Imo better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 68 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Thomas Zimmermann
maintainerRe: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Hi
Am 08.04.21 um 11:48 schrieb Daniel Vetter:
Quoted 6 lines
Maybe just me, but to avoid overstretching the attention spawn of doc readers I'd avoid this example here. And maybe make the recommendation stronger, e.g. "PCI device drivers can avoid open-coding
remove_conflicting_framebuffers()by callingdrm_fb_helper_remove_conflicting_pci_framebuffers()."
It's a tutorial. In my expectation, everyone just copies the tutorial code and fills the gaps.
Quoted 33 lines
Quoted 24 lines
+ *
+ * .. code-block:: c
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * int ret;
+ *
+ * // Remove any generic drivers...
+ * ret =drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "example driver");
+ * if (ret)
+ * return ret;
+ *
+ * // ... and initialize the hardware.
+ * ...
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * Drivers that are susceptible to being removed be other drivers, such as
+ * generic EFI or VESA drivers, have to register themselves as owners of their
+ * given framebuffer memory. Ownership of the framebuffer memory is achivedQuoted 8 lines
+ * by calling
devm_aperture_acquire(). On success, the driver is the owner
+ * of the framebuffer range. The function fails if the framebuffer is already
+ * by another driver. See below for an example.
+ *
+ * .. code-block:: c
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach = ...
Quoted 4 lines
Is there really value in allowing/forcing drivers to set up their own detach ops? You already make this specific to struct
drm_device, an implementation that just callsdrm_dev_unplugfeels like the right thing to do?
Is it that easy? simepldrm's detach function has code to synchronize with concurrent hotplug removals. If we can use drm_dev_unplug() for everything, I'm all for it.
Best regards
Thomas
Quoted 280 lines
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
+ * };
+ *
+ * static intacquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev)
+ * {
+ *resource_size_tstart, len;
+ * structdrm_aperture*ap;
+ *
+ * base =pci_resource_start(pdev, 0);
+ * size =pci_resource_len(pdev, 0);
+ *
+ * ap =devm_acquire_aperture(dev, base, size, &ap_funcs);
+ * if (IS_ERR(ap))
+ * returnPTR_ERR(ap);
+ *
+ * return 0;
+ * }
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * structdrm_device*dev;
+ * int ret;
+ *
+ * // ... Initialize the device...
+ * dev =devm_drm_dev_alloc();
+ * ...
+ *
+ * // ... and acquire ownership of the framebuffer.
+ * ret =acquire_framebuffers(dev, pdev);
+ * if (ret)
+ * return ret;
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * The generic driver is now subject to forced removal by other drivers. This
+ * is when the detach function in struct&drm_aperture_funcscomes into play.
+ * When a driver callsdrm_fb_helper_remove_conflicting_framebuffers()et al
+ * for the registered framebuffer range, the DRM core calls struct
+ * &drm_aperture_funcs.detach and the generic driver has to onload itself. It
+ * may not access the device's registers, framebuffer memory, ROM, etc after
+ * detach returned. If the driver supports hotplugging, detach can be treated
+ * like an unplug event.
+ *
+ * .. code-block:: c
+ *
+ * static void detach_from_device(structdrm_device*dev,
+ *resource_size_tbase,
+ *resource_size_tsize)
+ * {
+ * // Signal unplug
+ *drm_dev_unplug(dev);
+ *
+ * // Maybe do other clean-up operations
+ * ...
+ * }
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach =detach_from_device,
+ * };
+ */drivers/gpu/drm/drm_aperture.c new file +22
-0+ +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.Review
Quoted 1 line
(quoted diff) +1
-0+ mutex_lock(&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 79 lines
drivers/gpu/drm/drm_aperture.c new file +79
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on behalf of a DRM driver. +* @dev: the DRM device to own the framebuffer memory +* @base: the framebuffer's byte offset in physical memory +* @size: the framebuffer size in bytes +* @funcs: callback functions +* +* Installs the given device as the new owner. The function fails if the +* framebuffer range, or parts of it, is currently owned by another driver. +* To evict current owners, callers should use +* drm_fb_helper_remove_conflicting_framebuffers() et al. before calling this +* function. Acquired apertures are released automatically if the underlying +* device goes away. +* +* Returns: +* An instance of struct &drm_aperture on success, or a pointer-encoded +* errno value otherwise. +*/ +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ;drivers/gpu/drm/drm_aperture.c line 287
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+ + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size); + } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers? Imo better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 68 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Re: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Quoted 4 lines · Thomas Zimmermann
Hi
Am 08.04.21 um 11:48 schrieb Daniel Vetter:
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Maybe just me, but to avoid overstretching the attention spawn of doc readers I'd avoid this example here. And maybe make the recommendation stronger, e.g. "PCI device drivers can avoid open-coding
remove_conflicting_framebuffers()by callingdrm_fb_helper_remove_conflicting_pci_framebuffers()."It's a tutorial. In my expectation, everyone just copies the tutorial code and fills the gaps.
Sure, but we also have default functions for most common cases, so most people just end up copypasting the single function call. Feels like overkill to have a tutorial for that.
Imo tutorial/pseudo-code are good if there's more involved code flow that many places need to copypaste and customize. Or to show how different functions work together collectively. This doesn't quite feel like it's clearing that bar.
And please don't get me wrong, solid docs is great. It's just that I think we need to have reader's attention span in mind too (and mine personally might be on the extremely short side here) to make sure our docs are effective at conveying information.
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
+ *
+ * .. code-block:: c
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * int ret;
+ *
+ * // Remove any generic drivers...
+ * ret =drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "example driver");
+ * if (ret)
+ * return ret;
+ *
+ * // ... and initialize the hardware.
+ * ...
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * Drivers that are susceptible to being removed be other drivers, such as
+ * generic EFI or VESA drivers, have to register themselves as owners of their
+ * given framebuffer memory. Ownership of the framebuffer memory is achived
+ * by callingdevm_aperture_acquire(). On success, the driver is the owner
+ * of the framebuffer range. The function fails if the framebuffer is already
+ * by another driver. See below for an example.
+ *
+ * .. code-block:: c
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach = ...
Quoted 8 lines
Quoted 4 lines
Is there really value in allowing/forcing drivers to set up their own detach ops? You already make this specific to struct
drm_device, an implementation that just callsdrm_dev_unplugfeels like the right thing to do?Is it that easy? simepldrm's detach function has code to synchronize with concurrent hotplug removals. If we can use
drm_dev_unplug()for everything, I'm all for it.
Uh, I should have looked at the code instead of just asking silly questions :-)
Now I'm even more scared, and also more convinced that we're recreating a bad version of some of the core driver model concepts.
I think the ideal option here would be if drm_aperture could unload (unbind really) the platform driver for us, through the driver model. Then there's only one place that keeps track whether the driver is unbound or not. I'm not sure whether this can be done fully generic on a struct device, or whether we need special code for each type. Since atm we only have simpledrm we can just specialize on platform_device and it's good enough.
I think best here would be to Cc: gregkh on this patch and the simpledrm ->detach implementatation, and ask for his feedback as driver model maintainer. Maybe if you could hack together the platform_device unbind path as proof of concept would be even better.
Either way, this is really tricky.
-Daniel
Quoted 290 lines
Best regards
ThomasQuoted 277 lines
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
+ * };
+ *
+ * static intacquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev)
+ * {
+ *resource_size_tstart, len;
+ * structdrm_aperture*ap;
+ *
+ * base =pci_resource_start(pdev, 0);
+ * size =pci_resource_len(pdev, 0);
+ *
+ * ap =devm_acquire_aperture(dev, base, size, &ap_funcs);
+ * if (IS_ERR(ap))
+ * returnPTR_ERR(ap);
+ *
+ * return 0;
+ * }
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * structdrm_device*dev;
+ * int ret;
+ *
+ * // ... Initialize the device...
+ * dev =devm_drm_dev_alloc();
+ * ...
+ *
+ * // ... and acquire ownership of the framebuffer.
+ * ret =acquire_framebuffers(dev, pdev);
+ * if (ret)
+ * return ret;
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * The generic driver is now subject to forced removal by other drivers. This
+ * is when the detach function in struct&drm_aperture_funcscomes into play.
+ * When a driver callsdrm_fb_helper_remove_conflicting_framebuffers()et al
+ * for the registered framebuffer range, the DRM core calls struct
+ * &drm_aperture_funcs.detach and the generic driver has to onload itself. It
+ * may not access the device's registers, framebuffer memory, ROM, etc after
+ * detach returned. If the driver supports hotplugging, detach can be treated
+ * like an unplug event.
+ *
+ * .. code-block:: c
+ *
+ * static void detach_from_device(structdrm_device*dev,
+ *resource_size_tbase,
+ *resource_size_tsize)
+ * {
+ * // Signal unplug
+ *drm_dev_unplug(dev);
+ *
+ * // Maybe do other clean-up operations
+ * ...
+ * }
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach =detach_from_device,
+ * };
+ */drivers/gpu/drm/drm_aperture.c new file +22
-0+ +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.Review
Quoted 1 line
(quoted diff) +1
-0+ mutex_lock(&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 79 lines
drivers/gpu/drm/drm_aperture.c new file +79
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on behalf of a DRM driver. +* @dev: the DRM device to own the framebuffer memory +* @base: the framebuffer's byte offset in physical memory +* @size: the framebuffer size in bytes +* @funcs: callback functions +* +* Installs the given device as the new owner. The function fails if the +* framebuffer range, or parts of it, is currently owned by another driver. +* To evict current owners, callers should use +* drm_fb_helper_remove_conflicting_framebuffers() et al. before calling this +* function. Acquired apertures are released automatically if the underlying +* device goes away. +* +* Returns: +* An instance of struct &drm_aperture on success, or a pointer-encoded +* errno value otherwise. +*/ +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ;drivers/gpu/drm/drm_aperture.c line 287
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+ + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size); + } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers? Imo better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 65 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Hi
Am 09.04.21 um 11:22 schrieb Daniel Vetter:
Quoted 8 lines
Quoted 3 lines
Is it that easy? simepldrm's detach function has code to synchronize with concurrent hotplug removals. If we can use
drm_dev_unplug()for everything, I'm all for it.Uh, I should have looked at the code instead of just asking silly questions :-)
Now I'm even more scared, and also more convinced that we're recreating
a
Quoted 9 lines
bad version of some of the core driver model concepts.
I think the ideal option here would be if
drm_aperturecould unload (unbind really) the platform driver for us, through the driver model. Then there's only one place that keeps track whether the driver is unbound or not. I'm not sure whether this can be done fully generic on a struct device, or whether we need special code for each type. Since atm we only have simpledrm we can just specialize onplatform_deviceand it's good enough.
I meanwhile found that calling platform_device_unregister() is the right thing to do. It is like a hot-unplug event. It's simple to implement and removes the generic device as well. Any memory ranges for the generic device are gone as well. Only the native driver's native device will remain. That's better than the existing simplefb driver.
Which unregister function to call still driver-specific, so I kept the callback.
Best regards
Thomas
Quoted 130 lines
I think best here would be to Cc: gregkh on this patch and the simpledrm ->detach implementatation, and ask for his feedback as driver model maintainer. Maybe if you could hack together the
platform_deviceunbind path as proof of concept would be even better.Either way, this is really tricky.
-DanielQuoted 121 lines
Best regards
ThomasQuoted 117 lines
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
+ * };
+ *
+ * static intacquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev)
+ * {
+ *resource_size_tstart, len;
+ * structdrm_aperture*ap;
+ *
+ * base =pci_resource_start(pdev, 0);
+ * size =pci_resource_len(pdev, 0);
+ *
+ * ap =devm_acquire_aperture(dev, base, size, &ap_funcs);
+ * if (IS_ERR(ap))
+ * returnPTR_ERR(ap);
+ *
+ * return 0;
+ * }
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * structdrm_device*dev;
+ * int ret;
+ *
+ * // ... Initialize the device...
+ * dev =devm_drm_dev_alloc();
+ * ...
+ *
+ * // ... and acquire ownership of the framebuffer.
+ * ret =acquire_framebuffers(dev, pdev);
+ * if (ret)
+ * return ret;
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * The generic driver is now subject to forced removal by other drivers. This
+ * is when the detach function in struct&drm_aperture_funcscomes into play.
+ * When a driver callsdrm_fb_helper_remove_conflicting_framebuffers()et al
+ * for the registered framebuffer range, the DRM core calls struct
+ * &drm_aperture_funcs.detach and the generic driver has to onload itself. It
+ * may not access the device's registers, framebuffer memory, ROM, etc after
+ * detach returned. If the driver supports hotplugging, detach can be treated
+ * like an unplug event.
+ *
+ * .. code-block:: c
+ *
+ * static void detach_from_device(structdrm_device*dev,
+ *resource_size_tbase,
+ *resource_size_tsize)
+ * {
+ * // Signal unplug
+ *drm_dev_unplug(dev);
+ *
+ * // Maybe do other clean-up operations
+ * ...
+ * }
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach =detach_from_device,
+ * };
+ */drivers/gpu/drm/drm_aperture.c new file +22
-0+ +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.Review
Quoted 1 line
(quoted diff) +1
-0+ mutex_lock(&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_aperture.c new file +8
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ *
devm_aperture_acquire- Acquires ownership of a framebuffer on behalf of a DRM driver.
+ * @dev: the DRM device to own the framebuffer memory
+ * @base: the framebuffer's byte offset in physical memory
+ * @size: the framebuffer size in bytes
+ * @funcs: callback functions
+ *
+ * Installs the given device as the new owner. The function fails if the
+ * framebuffer range, or parts of it, is currently owned by another
driver.
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
+ * To evict current owners, callers should use
+ *drm_fb_helper_remove_conflicting_framebuffers()et al. before calling this
+ * function. Acquired apertures are released automatically if the underlying
+ * device goes away.
+ *
+ * Returns:
+ * An instance of struct&drm_apertureon success, or a pointer-encoded
+ * errno value otherwise.
+ */drivers/gpu/drm/drm_aperture.c new file +58
-0+struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ; + + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_aperture.c line 287
Quoted 6 lines
drivers/gpu/drm/drm_aperture.c new file +6
-0+ ap->funcs->detach (dev, ap->base, ap->size); + } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers?
Imo
Quoted 82 lines
Quoted 78 lines
Quoted 69 lines
better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 65 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Quoted 22 lines · Thomas Zimmermann
Hi
Am 09.04.21 um 11:22 schrieb Daniel Vetter:
Quoted 8 lines
Quoted 3 lines
Is it that easy? simepldrm's detach function has code to synchronize with concurrent hotplug removals. If we can use
drm_dev_unplug()for everything, I'm all for it.Uh, I should have looked at the code instead of just asking silly questions :-)
Now I'm even more scared, and also more convinced that we're recreating
a
Quoted 9 lines
bad version of some of the core driver model concepts.
I think the ideal option here would be if
drm_aperturecould unload (unbind really) the platform driver for us, through the driver model. Then there's only one place that keeps track whether the driver is unbound or not. I'm not sure whether this can be done fully generic on a struct device, or whether we need special code for each type. Since atm we only have simpledrm we can just specialize onplatform_deviceand it's good enough.
Quoted 5 lines
I meanwhile found that calling
platform_device_unregister()is the right thing to do. It is like a hot-unplug event. It's simple to implement and removes the generic device as well. Any memory ranges for the generic device are gone as well. Only the native driver's native device will remain. That's better than the existing simplefb driver.
That sounds great.
Quoted 2 lines
Which unregister function to call still driver-specific, so I kept the callback.
Could we have the callback in core code, and you do something like drm_aperture_acquire_platform (and later on drm_aperture_acquire_pci or whatever, although tbh I'm not sure we ever get anything else than platform). That function can do a runtime check that drm_device->dev is actually a platform dev.
Another idea: Do the runtime casting in the core without anything? Atm we have platform that needs support, maybe pci device, so we could easily extend this and just let it do the right thing. Then no callback is needed. I.e.
if (is_platform_dev(drm_device->dev)) platform_device_unregister(drm_device->dev); else WARN(1, "not yet implemented\n");
or something like that.
I just find the callback to essentially unregister a device a bit redundant.
-Daniel
Quoted 320 lines
Best regards
ThomasQuoted 139 lines
I think best here would be to Cc: gregkh on this patch and the simpledrm ->detach implementatation, and ask for his feedback as driver model maintainer. Maybe if you could hack together the
platform_deviceunbind path as proof of concept would be even better.Either way, this is really tricky.
-DanielQuoted 130 lines
Best regards
ThomasQuoted 126 lines
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
+ * };
+ *
+ * static intacquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev)
+ * {
+ *resource_size_tstart, len;
+ * structdrm_aperture*ap;
+ *
+ * base =pci_resource_start(pdev, 0);
+ * size =pci_resource_len(pdev, 0);
+ *
+ * ap =devm_acquire_aperture(dev, base, size, &ap_funcs);
+ * if (IS_ERR(ap))
+ * returnPTR_ERR(ap);
+ *
+ * return 0;
+ * }
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * structdrm_device*dev;
+ * int ret;
+ *
+ * // ... Initialize the device...
+ * dev =devm_drm_dev_alloc();
+ * ...
+ *
+ * // ... and acquire ownership of the framebuffer.
+ * ret =acquire_framebuffers(dev, pdev);
+ * if (ret)
+ * return ret;
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * The generic driver is now subject to forced removal by other drivers. This
+ * is when the detach function in struct&drm_aperture_funcscomes into play.
+ * When a driver callsdrm_fb_helper_remove_conflicting_framebuffers()et al
+ * for the registered framebuffer range, the DRM core calls struct
+ * &drm_aperture_funcs.detach and the generic driver has to onload itself. It
+ * may not access the device's registers, framebuffer memory, ROM, etc after
+ * detach returned. If the driver supports hotplugging, detach can be treated
+ * like an unplug event.
+ *
+ * .. code-block:: c
+ *
+ * static void detach_from_device(structdrm_device*dev,
+ *resource_size_tbase,
+ *resource_size_tsize)
+ * {
+ * // Signal unplug
+ *drm_dev_unplug(dev);
+ *
+ * // Maybe do other clean-up operations
+ * ...
+ * }
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach =detach_from_device,
+ * };
+ */drivers/gpu/drm/drm_aperture.c new file +22
-0+ +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.Review
Quoted 1 line
(quoted diff) +1
-0+ mutex_lock(&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 9 lines
drivers/gpu/drm/drm_aperture.c new file +9
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on behalf of a DRM driver. Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ * @dev: the DRM device to own the framebuffer memory
+ * @base: the framebuffer's byte offset in physical memory
+ * @size: the framebuffer size in bytes
+ * @funcs: callback functions
+ *
+ * Installs the given device as the new owner. The function fails if the
+ * framebuffer range, or parts of it, is currently owned by anotherdriver.
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
+ * To evict current owners, callers should use
+ *drm_fb_helper_remove_conflicting_framebuffers()et al. before calling this
+ * function. Acquired apertures are released automatically if the underlying
+ * device goes away.
+ *
+ * Returns:
+ * An instance of struct&drm_apertureon success, or a pointer-encoded
+ * errno value otherwise.
+ */drivers/gpu/drm/drm_aperture.c new file +59
-0+struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ; + + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_aperture.c line 287
Quoted 5 lines
drivers/gpu/drm/drm_aperture.c new file +5
-0+ } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers?
Imo
Quoted 82 lines
Quoted 78 lines
Quoted 69 lines
better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 65 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix ImendörfferSignature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Hi
Am 15.04.21 um 14:57 schrieb Daniel Vetter:
Quoted 5 lines · Thomas Zimmermann
Quoted 4 lines
Hi
Am 09.04.21 um 11:22 schrieb Daniel Vetter:
Quoted 1 line
Quoted 1 line
Is it that easy? simepldrm's detach function has code to synchronize
with
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
concurrent hotplug removals. If we can use
drm_dev_unplug()for everything, I'm all for it.Uh, I should have looked at the code instead of just asking silly questions :-)
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Now I'm even more scared, and also more convinced that we're recreating
a
Quoted 4 lines
bad version of some of the core driver model concepts.
I think the ideal option here would be if
drm_aperturecould unload (unbind really) the platform driver for us, through the driver model.
Then
Quoted 1 line
Quoted 1 line
Quoted 1 line
there's only one place that keeps track whether the driver is unbound
or
Quoted 13 lines
Quoted 10 lines
Quoted 4 lines
not. I'm not sure whether this can be done fully generic on a struct device, or whether we need special code for each type. Since atm we only have simpledrm we can just specialize on
platform_deviceand it's good enough.I meanwhile found that calling
platform_device_unregister()is the right thing to do. It is like a hot-unplug event. It's simple to implement and removes the generic device as well. Any memory ranges for the generic device are gone as well. Only the native driver's native device will remain. That's better than the existing simplefb driver.That sounds great.
Quoted 8 lines
Quoted 2 lines
Which unregister function to call still driver-specific, so I kept the callback.
Could we have the callback in core code, and you do something like
drm_aperture_acquire_platform(and later ondrm_aperture_acquire_pcior whatever, although tbh I'm not sure we ever get anything else than platform). That function can do a runtime check thatdrm_device->devis actually a platform dev.
Somehow I knew you wouldn't like the current abstraction. :)
Quoted 6 lines
Another idea: Do the runtime casting in the core without anything? Atm we have platform that needs support, maybe pci device, so we could easily extend this and just let it do the right thing. Then no callback is needed. I.e.
Quoted 6 lines
if (is_platform_dev(drm_device->dev)) platform_device_unregister(drm_device->dev); else WARN(1, "not yet implemented\n");or something like that.
I don't like that. I spend time to remove the usb and pci device pointers from code and structs. I don't want to introduce a new hard-coded special case here.
Quoted 3 lines
I just find the callback to essentially unregister a device a bit redundant.
I'd like to go with your first idea. The callback would be internal and the public acquire function is specifically for firmware-based platform devices. That covers simple-framebuffer, VESA, EFI, and probably any other generic interface that fbdev supported in the last 20+ yrs. I don't think we'll ever need anything else.
Still, I'd like to have some abstraction between the internals of the aperture helpers and our actual use case. I'll update the patchset accordingly.
Best regards
Thomas
Quoted 30 lines
-Daniel
Quoted 28 lines
Best regards
ThomasQuoted 24 lines
I think best here would be to Cc: gregkh on this patch and the simpledrm ->detach implementatation, and ask for his feedback as driver model maintainer. Maybe if you could hack together the
platform_deviceunbind path as proof of concept would be even better.Either way, this is really tricky.
-DanielQuoted 15 lines
Best regards
ThomasQuoted 11 lines
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 3 lines
+ * };
+ *
+ * static int acquire_framebuffers(structdrm_device*dev, struct
pci_dev *pdev)
Quoted 106 lines
Quoted 106 lines
Quoted 106 lines
Quoted 106 lines
Quoted 106 lines
Quoted 81 lines
+ * {
+ *resource_size_tstart, len;
+ * structdrm_aperture*ap;
+ *
+ * base =pci_resource_start(pdev, 0);
+ * size =pci_resource_len(pdev, 0);
+ *
+ * ap =devm_acquire_aperture(dev, base, size, &ap_funcs);
+ * if (IS_ERR(ap))
+ * returnPTR_ERR(ap);
+ *
+ * return 0;
+ * }
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * structdrm_device*dev;
+ * int ret;
+ *
+ * // ... Initialize the device...
+ * dev =devm_drm_dev_alloc();
+ * ...
+ *
+ * // ... and acquire ownership of the framebuffer.
+ * ret =acquire_framebuffers(dev, pdev);
+ * if (ret)
+ * return ret;
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * The generic driver is now subject to forced removal by other drivers. This
+ * is when the detach function in struct&drm_aperture_funcscomes into play.
+ * When a driver callsdrm_fb_helper_remove_conflicting_framebuffers()et al
+ * for the registered framebuffer range, the DRM core calls struct
+ * &drm_aperture_funcs.detach and the generic driver has to onload itself. It
+ * may not access the device's registers, framebuffer memory, ROM, etc after
+ * detach returned. If the driver supports hotplugging, detach can be treated
+ * like an unplug event.
+ *
+ * .. code-block:: c
+ *
+ * static void detach_from_device(structdrm_device*dev,
+ *resource_size_tbase,
+ *resource_size_tsize)
+ * {
+ * // Signal unplug
+ *drm_dev_unplug(dev);
+ *
+ * // Maybe do other clean-up operations
+ * ...
+ * }
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach =detach_from_device,
+ * };
+ */drivers/gpu/drm/drm_aperture.c new file +22
-0+ +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.Review
Quoted 1 line
(quoted diff) +1
-0+ mutex_lock(&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/drm_aperture.c
Quoted 9 lines
drivers/gpu/drm/drm_aperture.c new file +9
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on
behalf of a DRM driver.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+ * @dev: the DRM device to own the framebuffer memory
+ * @base: the framebuffer's byte offset in physical memory
+ * @size: the framebuffer size in bytes
+ * @funcs: callback functions
+ *
+ * Installs the given device as the new owner. The function fails
if the
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * framebuffer range, or parts of it, is currently owned by another
driver.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ * To evict current owners, callers should use
+ *drm_fb_helper_remove_conflicting_framebuffers()et al. before calling this
+ * function. Acquired apertures are released automatically if the
underlying
Quoted 95 lines
Quoted 95 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
+ * device goes away.
+ *
+ * Returns:
+ * An instance of struct&drm_apertureon success, or a pointer-encoded
+ * errno value otherwise.
+ */drivers/gpu/drm/drm_aperture.c new file +59
-0+struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ; + + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_aperture.c line 287
Quoted 5 lines
drivers/gpu/drm/drm_aperture.c new file +5
-0+ } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers?
Imo
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 18 lines
include/drm/drm_aperture.h +10
-0@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire(struct drm_device *dev,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/drm/drm_aperture.h
Quoted 8 lines
include/drm/drm_aperture.h +8
-0+ resource_size_t base, resource_size_t size, + const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers(resource_size_t base, resource_size_t
size)
Quoted 66 lines
Quoted 62 lines
Quoted 53 lines
Quoted 49 lines
Quoted 40 lines
Quoted 39 lines
include/drm/drm_aperture.h +19
-1+{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix ImendörfferSignature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Re: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Quoted 78 lines · Thomas Zimmermann
Hi
Am 15.04.21 um 14:57 schrieb Daniel Vetter:
Quoted 6 lines · Thomas Zimmermann
Quoted 5 lines
Hi
Am 09.04.21 um 11:22 schrieb Daniel Vetter:
Quoted 2 lines
Quoted 2 lines
Is it that easy? simepldrm's detach function has code to synchronize
with
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
concurrent hotplug removals. If we can use
drm_dev_unplug()for everything, I'm all for it.Uh, I should have looked at the code instead of just asking silly questions :-)
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Now I'm even more scared, and also more convinced that we're recreating
a
Quoted 5 lines
bad version of some of the core driver model concepts.
I think the ideal option here would be if
drm_aperturecould unload (unbind really) the platform driver for us, through the driver model.Then
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
there's only one place that keeps track whether the driver is unbound
or
Quoted 13 lines
Quoted 10 lines
Quoted 4 lines
not. I'm not sure whether this can be done fully generic on a struct device, or whether we need special code for each type. Since atm we only have simpledrm we can just specialize on
platform_deviceand it's good enough.I meanwhile found that calling
platform_device_unregister()is the right thing to do. It is like a hot-unplug event. It's simple to implement and removes the generic device as well. Any memory ranges for the generic device are gone as well. Only the native driver's native device will remain. That's better than the existing simplefb driver.That sounds great.
Quoted 8 lines
Quoted 2 lines
Which unregister function to call still driver-specific, so I kept the callback.
Could we have the callback in core code, and you do something like
drm_aperture_acquire_platform(and later ondrm_aperture_acquire_pcior whatever, although tbh I'm not sure we ever get anything else than platform). That function can do a runtime check thatdrm_device->devis actually a platform dev.Somehow I knew you wouldn't like the current abstraction. :)
Quoted 6 lines
Another idea: Do the runtime casting in the core without anything? Atm we have platform that needs support, maybe pci device, so we could easily extend this and just let it do the right thing. Then no callback is needed. I.e.
Quoted 6 lines
if (is_platform_dev(drm_device->dev)) platform_device_unregister(drm_device->dev); else WARN(1, "not yet implemented\n");or something like that.
I don't like that. I spend time to remove the usb and pci device pointers from code and structs. I don't want to introduce a new hard-coded special case here.
Quoted 3 lines
I just find the callback to essentially unregister a device a bit redundant.
I'd like to go with your first idea. The callback would be internal and the public acquire function is specifically for firmware-based platform devices. That covers simple-framebuffer, VESA, EFI, and probably any other generic interface that fbdev supported in the last 20+ yrs. I don't think we'll ever need anything else.
Quoted 3 lines
Still, I'd like to have some abstraction between the internals of the aperture helpers and our actual use case. I'll update the patchset accordingly.
Makes sense and I'm happy with that pick of color choice. That keeps the noise out of drivers, and also keeps the concepts clean internally. -Daniel
Quoted 349 lines
Best regards
ThomasQuoted 31 lines
-Daniel
Quoted 29 lines
Best regards
ThomasQuoted 25 lines
I think best here would be to Cc: gregkh on this patch and the simpledrm ->detach implementatation, and ask for his feedback as driver model maintainer. Maybe if you could hack together the
platform_deviceunbind path as proof of concept would be even better.Either way, this is really tricky.
-DanielQuoted 16 lines
Best regards
ThomasQuoted 12 lines
Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 4 lines
+ * };
+ *
+ * static int acquire_framebuffers(structdrm_device*dev, struct
pci_dev*pdev)Quoted 106 lines
Quoted 106 lines
Quoted 106 lines
Quoted 106 lines
Quoted 106 lines
Quoted 81 lines
+ * {
+ *resource_size_tstart, len;
+ * structdrm_aperture*ap;
+ *
+ * base =pci_resource_start(pdev, 0);
+ * size =pci_resource_len(pdev, 0);
+ *
+ * ap =devm_acquire_aperture(dev, base, size, &ap_funcs);
+ * if (IS_ERR(ap))
+ * returnPTR_ERR(ap);
+ *
+ * return 0;
+ * }
+ *
+ * static intprobe(struct pci_dev *pdev)
+ * {
+ * structdrm_device*dev;
+ * int ret;
+ *
+ * // ... Initialize the device...
+ * dev =devm_drm_dev_alloc();
+ * ...
+ *
+ * // ... and acquire ownership of the framebuffer.
+ * ret =acquire_framebuffers(dev, pdev);
+ * if (ret)
+ * return ret;
+ *
+ *drm_dev_register();
+ *
+ * return 0;
+ * }
+ *
+ * The generic driver is now subject to forced removal by other drivers. This
+ * is when the detach function in struct&drm_aperture_funcscomes into play.
+ * When a driver callsdrm_fb_helper_remove_conflicting_framebuffers()et al
+ * for the registered framebuffer range, the DRM core calls struct
+ * &drm_aperture_funcs.detach and the generic driver has to onload itself. It
+ * may not access the device's registers, framebuffer memory, ROM, etc after
+ * detach returned. If the driver supports hotplugging, detach can be treated
+ * like an unplug event.
+ *
+ * .. code-block:: c
+ *
+ * static void detach_from_device(structdrm_device*dev,
+ *resource_size_tbase,
+ *resource_size_tsize)
+ * {
+ * // Signal unplug
+ *drm_dev_unplug(dev);
+ *
+ * // Maybe do other clean-up operations
+ * ...
+ * }
+ *
+ * static structdrm_aperture_funcsap_funcs= {
+ * .detach =detach_from_device,
+ * };
+ */(quoted diff) +22
-0+ +/** + * struct drm_aperture - Represents a DRM framebuffer aperture + * + * This structure has no public fields. + */ +struct drm_aperture { + struct drm_device *dev; + resource_size_t base; + resource_size_t size; + + const struct drm_aperture_funcs *funcs; + + struct list_head lh; +}; + +static LIST_HEAD(drm_apertures); + +static DEFINE_MUTEX(drm_apertures_lock); + +static bool overlap(resource_size_t base1, resource_size_t end1, + resource_size_t base2, resource_size_t end2)Review
Quoted 10 lines
(quoted diff) +10
-0+{ + return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release(void *data) +{ + struct drm_aperture *ap = data; + bool detached = !ap->dev; + + if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.Review
Quoted 1 line
(quoted diff) +1
-0+ mutex_lock(&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
(quoted diff) +9
-0+ + list_del(&ap->lh); + + if (!detached) + mutex_unlock(&drm_apertures_lock); +} + +/** + * devm_aperture_acquire - Acquires ownership of aframebuffer on
behalf of a DRM driver.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ * @dev: the DRM device to own the framebuffer memory
+ * @base: the framebuffer's byte offset in physical memory
+ * @size: the framebuffer size in bytes
+ * @funcs: callback functions
+ *
+ * Installs the given device as the new owner. The function failsif the
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * framebuffer range, or parts of it, is currently owned by another
driver.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * To evict current owners, callers should use
+ *drm_fb_helper_remove_conflicting_framebuffers()et al. before calling this
+ * function. Acquired apertures are released
automatically if theunderlying
Quoted 96 lines
Quoted 96 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
+ * device goes away.
+ *
+ * Returns:
+ * An instance of struct&drm_apertureon success, or a pointer-encoded
+ * errno value otherwise.
+ */(quoted diff) +59
-0+struct drm_aperture * +devm_aperture_acquire(struct drm_device *dev, + resource_size_t base, resource_size_t size, + const struct drm_aperture_funcs *funcs) +{ + size_t end = base + size; + struct list_head *pos; + struct drm_aperture *ap; + int ret; + + mutex_lock(&drm_apertures_lock); + + list_for_each(pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); + if (overlap(base, end, ap->base, ap->base + ap->size)) + return ERR_PTR(-EBUSY); + } + + ap = devm_kzalloc(dev->dev, sizeof(*ap), GFP_KERNEL); + if (!ap) + return ERR_PTR(-ENOMEM); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; + INIT_LIST_HEAD(&ap->lh); + + list_add(&ap->lh, &drm_apertures); + + mutex_unlock(&drm_apertures_lock); + + ret = devm_add_action_or_reset(dev->dev, devm_aperture_acquire_release, ap); + if (ret) + return ERR_PTR(ret); + + return ap; +} +EXPORT_SYMBOL(devm_aperture_acquire); + +void drm_aperture_detach_drivers(resource_size_t base, resource_size_t size) +{ + resource_size_t end = base + size; + struct list_head *pos, *n; + + mutex_lock(&drm_apertures_lock); + + list_for_each_safe(pos, n, &drm_apertures) { + struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); + struct drm_device *dev = ap->dev; + + if (!overlap(base, end, ap->base, ap->base + ap->size)) + continue; + + ap->dev = NULL; /* detach from device */ + if (drm_WARN_ON(dev, !ap->funcs->detach)) + continue; + ap->funcs->detach(dev, ap->base, ap->size);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ } + + mutex_unlock(&drm_apertures_lock); +} +EXPORT_SYMBOL(drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers?
Imo
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 19 lines
include/drm/drm_aperture.h +11
-0@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire(struct drm_device *dev, + resource_size_t base, resource_size_t size,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/drm/drm_aperture.h +7
-0+ const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers(resource_size_t base,
resource_size_tsize)
Quoted 66 lines
Quoted 62 lines
Quoted 53 lines
Quoted 49 lines
Quoted 40 lines
Quoted 39 lines
include/drm/drm_aperture.h +19
-1+{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix ImendörfferSignature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix ImendörfferSignature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
In reply to Daniel VetterHi
Am 08.04.21 um 11:48 schrieb Daniel Vetter:
Quoted 72 lines · Thomas Zimmermann
Quoted 25 lines
Platform devices might operate on firmware framebuffers, such as VESA or EFI. Before a native driver for the graphics hardware can take over the device, it has to remove any platform driver that operates on the firmware framebuffer. Aperture helpers provide the infrastructure for platform drivers to acquire firmware framebuffers, and for native drivers to remove them later on.
It works similar to the related fbdev mechanism. During initialization, the platform driver acquires the firmware framebuffer's I/O memory and provides a callback to be removed. The native driver later uses this information to remove any platform driver for it's framebuffer I/O memory.
The aperture removal code is integrated into the existing code for removing conflicting framebuffers, so native drivers use it automatically.
v2:
* rename plaform helpers to aperture helpers
* tie to device lifetime withdevm_functions
* removed unsuedremove()callback
* rename kickout to detach
* make structdrm_apertureprivate
* rebase onto existingdrm_aperture.hheader file
* use MIT license only for simplicity
* documentationQuoted 2 lines
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>Bunch of bikesheds for your considerations below, but overall lgtm.
Acked-by Daniel Vetter <[email protected]>Cheers, Daniel
Quoted 37 lines
--- Documentation/gpu/drm-internals.rst | 6 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++++++++++++++++++++++ include/drm/drm_aperture.h | 38 +++- 5 files changed, 338 insertions(+), 1 deletion(-)create mode 100644
drivers/gpu/drm/drm_aperture.cDocumentation/gpu/drm-internals.rst +6
-0@@ -78,9 +78,15 @@ DRM_IOCTL_VERSION ioctl. Managing Ownership of the Framebuffer Aperture ---------------------------------------------- +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :doc: overview + .. kernel-doc:: include/drm/drm_aperture.h :internal: +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :export: + Device Instance and Driver Handling -----------------------------------drivers/gpu/drm/Kconfig +0
-0@@ -221,6 +221,13 @@ config DRM_SCHED tristate depends on DRM
Quoted 12 lines
drivers/gpu/drm/Kconfig config DRM_SCHED · line 229
Quoted 6 lines
drivers/gpu/drm/Kconfig +6
-0+config DRM_APERTURE + bool + depends on DRM + help + Controls ownership of graphics apertures. Required to + synchronize with firmware-based drivers.Uh I'm not a big fan of
Kconfigand .ko modules for every little helper code. Imo just stuff this into the drm kms helpers and done. Or stuff it into drm core code, I think either is a good case for this. Everything is its own module means we need toEXPORT_SYMBOLmore stuff, and then drivers get funny ideas about using these internals ...
The code lives in the DRM core module. There's no extra ko file. But I'd like to keep the Kconfig option. The aperture helpers will only be required if there are generic drivers in the kernel and for many systems this is not the case.
Best regards
Thomas
Quoted 418 lines
Quoted 85 lines
drivers/gpu/drm/Kconfig +1
-0+ source "drivers/gpu/drm/i2c/Kconfig" source "drivers/gpu/drm/arm/Kconfig"drivers/gpu/drm/Makefile +1
-0@@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_PCI) += drm_pci.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_APERTURE) += drm_aperture.o drm_vram_helper-y := drm_gem_vram_helper.o obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.odrivers/gpu/drm/drm_aperture.c new file +62
-0@@ -0,0 +1,287 @@ +// SPDX-License-Identifier: MIT + +#include <linux/device.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/types.h> + +#include <drm/drm_aperture.h> +#include <drm/drm_drv.h> +#include <drm/drm_print.h> + +/** +* DOC: overview +* +* A graphics device might be supported by different drivers, but only one +* driver can be active at any given time. Many systems load a generic +* graphics drivers, such as EFI-GOP or VESA, early during the boot process. +* During later boot stages, they replace the generic driver with a dedicated, +* hardware-specific driver. To take over the device the dedicated driver +* first has to remove the generic driver. DRM aperture functions manage +* ownership of DRM framebuffer memory and hand-over between drivers. +* +* DRM drivers should call drm_fb_helper_remove_conflicting_framebuffers() +* at the top of their probe function. The function removes any generic +* driver that is currently associated with the given framebuffer memory. +* If the framebuffer is located at PCI BAR 0, the rsp code looks as in the +* example given below. +* +* .. code-block:: c +* +* static int remove_conflicting_framebuffers(struct pci_dev *pdev) +* { +* struct apertures_struct *ap; +* bool primary = false; +* int ret; +* +* ap = alloc_apertures(1); +* if (!ap) +* return -ENOMEM; +* +* ap->ranges[0].base = pci_resource_start(pdev, 0); +* ap->ranges[0].size = pci_resource_len(pdev, 0); +* +* #ifdef CONFIG_X86 +* primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; +* #endif +* ret = drm_fb_helper_remove_conflicting_framebuffers(ap, "example driver", primary); +* kfree(ap); +* +* return ret; +* } +* +* static int probe(struct pci_dev *pdev) +* { +* int ret; +* +* // Remove any generic drivers... +* ret = remove_conflicting_framebuffers(pdev); +* if (ret) +* return ret; +* drivers/gpu/drm/drm_aperture.c line 72
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+* // ... and initialize the hardware. +* ... +* +* drm_dev_register(); +* +* return 0; +* } +* +* For PCI devices it is often sufficient to use drm_fb_helper_remove_conflicting_pci_framebuffers() +* and let it detect the framebuffer apertures automatically. Maybe just me, but to avoid overstretching the attention spawn of doc readers I'd avoid this example here. And maybe make the recommendation stronger, e.g. "PCI device drivers can avoid open-coding
remove_conflicting_framebuffers()by callingdrm_fb_helper_remove_conflicting_pci_framebuffers()."Quoted 21 lines
drivers/gpu/drm/drm_aperture.c new file +21
-0+* +* .. code-block:: c +* +* static int probe(struct pci_dev *pdev) +* { +* int ret; +* +* // Remove any generic drivers... +* ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "example driver"); +* if (ret) +* return ret; +* +* // ... and initialize the hardware. +* ... +* +* drm_dev_register(); +* +* return 0; +* } +* +* Drivers that are susceptible to being removed be other drivers, such as drivers/gpu/drm/drm_aperture.c line 103
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+* generic EFI or VESA drivers, have to register themselves as owners of their +* given framebuffer memory. Ownership of the framebuffer memory is achived +* by calling devm_aperture_acquire(). On success, the driver is the owner +* of the framebuffer range. The function fails if the framebuffer is already +* by another driver. See below for an example. +* +* .. code-block:: c +* +* static struct drm_aperture_funcs ap_funcs = { +* .detach = ... Is there really value in allowing/forcing drivers to set up their own detach ops? You already make this specific to struct
drm_device, an implementation that just callsdrm_dev_unplugfeels like the right thing to do?Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
drivers/gpu/drm/drm_aperture.c new file +84
-0+* }; +* +* static int acquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev) +* { +* resource_size_t start, len; +* struct drm_aperture *ap; +* +* base = pci_resource_start(pdev, 0); +* size = pci_resource_len(pdev, 0); +* +* ap = devm_acquire_aperture(dev, base, size, &ap_funcs); +* if (IS_ERR(ap)) +* return PTR_ERR(ap); +* +* return 0; +* } +* +* static int probe(struct pci_dev *pdev) +* { +* struct drm_device *dev; +* int ret; +* +* // ... Initialize the device... +* dev = devm_drm_dev_alloc(); +* ... +* +* // ... and acquire ownership of the framebuffer. +* ret = acquire_framebuffers(dev, pdev); +* if (ret) +* return ret; +* +* drm_dev_register(); +* +* return 0; +* } +* +* The generic driver is now subject to forced removal by other drivers. This +* is when the detach function in struct &drm_aperture_funcs comes into play. +* When a driver calls drm_fb_helper_remove_conflicting_framebuffers() et al +* for the registered framebuffer range, the DRM core calls struct +* &drm_aperture_funcs.detach and the generic driver has to onload itself. It +* may not access the device's registers, framebuffer memory, ROM, etc after +* detach returned. If the driver supports hotplugging, detach can be treated +* like an unplug event. +* +* .. code-block:: c +* +* static void detach_from_device(struct drm_device *dev, +* resource_size_t base, +* resource_size_t size) +* { +* // Signal unplug +* drm_dev_unplug(dev); +* +* // Maybe do other clean-up operations +* ... +* } +* +* static struct drm_aperture_funcs ap_funcs = { +* .detach = detach_from_device, +* }; +*/ + +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.drivers/gpu/drm/drm_aperture.c line 198
Quoted 1 line
drivers/gpu/drm/drm_aperture.c new file +1
-0+mutex_lock (&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 79 lines
drivers/gpu/drm/drm_aperture.c new file +79
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on behalf of a DRM driver. +* @dev: the DRM device to own the framebuffer memory +* @base: the framebuffer's byte offset in physical memory +* @size: the framebuffer size in bytes +* @funcs: callback functions +* +* Installs the given device as the new owner. The function fails if the +* framebuffer range, or parts of it, is currently owned by another driver. +* To evict current owners, callers should use +* drm_fb_helper_remove_conflicting_framebuffers() et al. before calling this +* function. Acquired apertures are released automatically if the underlying +* device goes away. +* +* Returns: +* An instance of struct &drm_aperture on success, or a pointer-encoded +* errno value otherwise. +*/ +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ;drivers/gpu/drm/drm_aperture.c line 287
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+ + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size); + } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers? Imo better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 68 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 04/10] drm/aperture: Add infrastructure for aperture ownership
Quoted 84 lines · Thomas Zimmermann
Hi
Am 08.04.21 um 11:48 schrieb Daniel Vetter:
Quoted 72 lines · Thomas Zimmermann
Quoted 25 lines
Platform devices might operate on firmware framebuffers, such as VESA or EFI. Before a native driver for the graphics hardware can take over the device, it has to remove any platform driver that operates on the firmware framebuffer. Aperture helpers provide the infrastructure for platform drivers to acquire firmware framebuffers, and for native drivers to remove them later on.
It works similar to the related fbdev mechanism. During initialization, the platform driver acquires the firmware framebuffer's I/O memory and provides a callback to be removed. The native driver later uses this information to remove any platform driver for it's framebuffer I/O memory.
The aperture removal code is integrated into the existing code for removing conflicting framebuffers, so native drivers use it automatically.
v2:
* rename plaform helpers to aperture helpers
* tie to device lifetime withdevm_functions
* removed unsuedremove()callback
* rename kickout to detach
* make structdrm_apertureprivate
* rebase onto existingdrm_aperture.hheader file
* use MIT license only for simplicity
* documentationQuoted 2 lines
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>Bunch of bikesheds for your considerations below, but overall lgtm.
Acked-by Daniel Vetter <[email protected]>Cheers, Daniel
Quoted 37 lines
--- Documentation/gpu/drm-internals.rst | 6 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++++++++++++++++++++++ include/drm/drm_aperture.h | 38 +++- 5 files changed, 338 insertions(+), 1 deletion(-)create mode 100644
drivers/gpu/drm/drm_aperture.cDocumentation/gpu/drm-internals.rst +6
-0@@ -78,9 +78,15 @@ DRM_IOCTL_VERSION ioctl. Managing Ownership of the Framebuffer Aperture ---------------------------------------------- +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :doc: overview + .. kernel-doc:: include/drm/drm_aperture.h :internal: +.. kernel-doc:: drivers/gpu/drm/drm_aperture.c + :export: + Device Instance and Driver Handling -----------------------------------drivers/gpu/drm/Kconfig +4
-0@@ -221,6 +221,13 @@ config DRM_SCHED tristate depends on DRM +config DRM_APERTURE + bool + depends on DRM + helpQuoted 8 lines
drivers/gpu/drm/Kconfig config DRM_SCHED · line 229
Quoted 2 lines
drivers/gpu/drm/Kconfig +2
-0+ Controls ownership of graphics apertures. Required to + synchronize with firmware-based drivers.Uh I'm not a big fan of
Kconfigand .ko modules for every little helper code. Imo just stuff this into the drm kms helpers and done. Or stuff it into drm core code, I think either is a good case for this. Everything is its own module means we need toEXPORT_SYMBOLmore stuff, and then drivers get funny ideas about using these internals ...
Quoted 4 lines
The code lives in the DRM core module. There's no extra ko file. But I'd like to keep the
Kconfigoption. The aperture helpers will only be required if there are generic drivers in the kernel and for many systems this is not the case.
Imo this kind of optimization is what LTO is for. Having hundreds of Kconfig symbols just to shave of 2 functions, or something like that, in each case just doesn't feel like it's justified spending of effort and complexity. Configuring out entire subsystems, sure, but not individual pieces like this.
So minimally a new Kconfig like this needs to show in a a) real world config b) actual relevant savings in terms of bytes. Otherwise it's really just cargo culting. I also feel like Kconfig symbols for everything is an appeasement tactic to sneak code int that has seen some resistance about potential overhead and all that. The cost in maintenance and complexity in keeping all the combinations working is much, much bigger though. Just look at the absolute endless amounts of pain that disabling CONFIG_BACKLIGHT is causing drm drivers. We do not want more of that, except if it's really solidly justified.
And for the "this saves memory" justification, we've done that for i915 to kick out support code for old platforms. LTO is what gives you actual real-world benefits here, since anything else means a bazillion of Kconfig options, each for minimal gain, resulting in an overall unmaintainable mess.
</rant>
Cheers, Daniel
Quoted 426 lines
Best regards
ThomasQuoted 413 lines
Quoted 83 lines
drivers/gpu/drm/Kconfig +1
-0+ source "drivers/gpu/drm/i2c/Kconfig" source "drivers/gpu/drm/arm/Kconfig"drivers/gpu/drm/Makefile +1
-0@@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_PCI) += drm_pci.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_APERTURE) += drm_aperture.o drm_vram_helper-y := drm_gem_vram_helper.o obj-$(CONFIG_DRM_VRAM_HELPER) += drm_vram_helper.odrivers/gpu/drm/drm_aperture.c new file +62
-0@@ -0,0 +1,287 @@ +// SPDX-License-Identifier: MIT + +#include <linux/device.h> +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/types.h> + +#include <drm/drm_aperture.h> +#include <drm/drm_drv.h> +#include <drm/drm_print.h> + +/** +* DOC: overview +* +* A graphics device might be supported by different drivers, but only one +* driver can be active at any given time. Many systems load a generic +* graphics drivers, such as EFI-GOP or VESA, early during the boot process. +* During later boot stages, they replace the generic driver with a dedicated, +* hardware-specific driver. To take over the device the dedicated driver +* first has to remove the generic driver. DRM aperture functions manage +* ownership of DRM framebuffer memory and hand-over between drivers. +* +* DRM drivers should call drm_fb_helper_remove_conflicting_framebuffers() +* at the top of their probe function. The function removes any generic +* driver that is currently associated with the given framebuffer memory. +* If the framebuffer is located at PCI BAR 0, the rsp code looks as in the +* example given below. +* +* .. code-block:: c +* +* static int remove_conflicting_framebuffers(struct pci_dev *pdev) +* { +* struct apertures_struct *ap; +* bool primary = false; +* int ret; +* +* ap = alloc_apertures(1); +* if (!ap) +* return -ENOMEM; +* +* ap->ranges[0].base = pci_resource_start(pdev, 0); +* ap->ranges[0].size = pci_resource_len(pdev, 0); +* +* #ifdef CONFIG_X86 +* primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; +* #endif +* ret = drm_fb_helper_remove_conflicting_framebuffers(ap, "example driver", primary); +* kfree(ap); +* +* return ret; +* } +* +* static int probe(struct pci_dev *pdev) +* { +* int ret; +* +* // Remove any generic drivers... +* ret = remove_conflicting_framebuffers(pdev); +* if (ret) +* return ret; +* drivers/gpu/drm/drm_aperture.c line 72
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+* // ... and initialize the hardware. +* ... +* +* drm_dev_register(); +* +* return 0; +* } +* +* For PCI devices it is often sufficient to use drm_fb_helper_remove_conflicting_pci_framebuffers() +* and let it detect the framebuffer apertures automatically. Maybe just me, but to avoid overstretching the attention spawn of doc readers I'd avoid this example here. And maybe make the recommendation stronger, e.g. "PCI device drivers can avoid open-coding
remove_conflicting_framebuffers()by callingdrm_fb_helper_remove_conflicting_pci_framebuffers()."Quoted 21 lines
drivers/gpu/drm/drm_aperture.c new file +21
-0+* +* .. code-block:: c +* +* static int probe(struct pci_dev *pdev) +* { +* int ret; +* +* // Remove any generic drivers... +* ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "example driver"); +* if (ret) +* return ret; +* +* // ... and initialize the hardware. +* ... +* +* drm_dev_register(); +* +* return 0; +* } +* +* Drivers that are susceptible to being removed be other drivers, such as drivers/gpu/drm/drm_aperture.c line 103
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+* generic EFI or VESA drivers, have to register themselves as owners of their +* given framebuffer memory. Ownership of the framebuffer memory is achived +* by calling devm_aperture_acquire(). On success, the driver is the owner +* of the framebuffer range. The function fails if the framebuffer is already +* by another driver. See below for an example. +* +* .. code-block:: c +* +* static struct drm_aperture_funcs ap_funcs = { +* .detach = ... Is there really value in allowing/forcing drivers to set up their own detach ops? You already make this specific to struct
drm_device, an implementation that just callsdrm_dev_unplugfeels like the right thing to do?Or maybe we should tie this more into the struct device mode and force an unload that way? That way devm cleanup would work as one expects, and avoid the need for anything specific (hopefully) in this detach callback.
Just feels a bit like we're reinventing half of the driver model here, badly.
Quoted 84 lines
drivers/gpu/drm/drm_aperture.c new file +84
-0+* }; +* +* static int acquire_framebuffers(struct drm_device *dev, struct pci_dev *pdev) +* { +* resource_size_t start, len; +* struct drm_aperture *ap; +* +* base = pci_resource_start(pdev, 0); +* size = pci_resource_len(pdev, 0); +* +* ap = devm_acquire_aperture(dev, base, size, &ap_funcs); +* if (IS_ERR(ap)) +* return PTR_ERR(ap); +* +* return 0; +* } +* +* static int probe(struct pci_dev *pdev) +* { +* struct drm_device *dev; +* int ret; +* +* // ... Initialize the device... +* dev = devm_drm_dev_alloc(); +* ... +* +* // ... and acquire ownership of the framebuffer. +* ret = acquire_framebuffers(dev, pdev); +* if (ret) +* return ret; +* +* drm_dev_register(); +* +* return 0; +* } +* +* The generic driver is now subject to forced removal by other drivers. This +* is when the detach function in struct &drm_aperture_funcs comes into play. +* When a driver calls drm_fb_helper_remove_conflicting_framebuffers() et al +* for the registered framebuffer range, the DRM core calls struct +* &drm_aperture_funcs.detach and the generic driver has to onload itself. It +* may not access the device's registers, framebuffer memory, ROM, etc after +* detach returned. If the driver supports hotplugging, detach can be treated +* like an unplug event. +* +* .. code-block:: c +* +* static void detach_from_device(struct drm_device *dev, +* resource_size_t base, +* resource_size_t size) +* { +* // Signal unplug +* drm_dev_unplug(dev); +* +* // Maybe do other clean-up operations +* ... +* } +* +* static struct drm_aperture_funcs ap_funcs = { +* .detach = detach_from_device, +* }; +*/ + +/** +* struct drm_aperture - Represents a DRM framebuffer aperture +* +* This structure has no public fields. +*/ +struct drm_aperture { +struct drm_device *dev; +resource_size_t base; +resource_size_t size; + +const struct drm_aperture_funcs *funcs; + +struct list_head lh; +}; + +static LIST_HEAD (drm_apertures); + +static DEFINE_MUTEX (drm_apertures_lock); + +static bool overlap (resource_size_t base1,resource_size_t end1, +resource_size_t base2,resource_size_t end2)drivers/gpu/drm/drm_aperture.c line 197
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+{ +return (base1 < end2) && (end1 > base2); +} + +static void devm_aperture_acquire_release (void *data) +{ +struct drm_aperture *ap = data; +bool detached = !ap->dev; + +if (!detached)Uh this needs a comment that if
ap->devis NULL then we're called fromdrm_aperture_detach_drivers()and hence the lock is already held.drivers/gpu/drm/drm_aperture.c line 198
Quoted 1 line
drivers/gpu/drm/drm_aperture.c new file +1
-0+mutex_lock (&drm_apertures_lock);and an
else locdep_assert_held(&drm_apertures_lock);here to check that. I was scratching my head first quite a bit how you'd solve the deadlock, this is a neat solution (much simpler than anything I came up with in my head). But needs comments.
Quoted 79 lines
drivers/gpu/drm/drm_aperture.c new file +79
-0+ +list_del (&ap->lh); + +if (!detached) +mutex_unlock (&drm_apertures_lock); +} + +/** +* devm_aperture_acquire - Acquires ownership of a framebuffer on behalf of a DRM driver. +* @dev: the DRM device to own the framebuffer memory +* @base: the framebuffer's byte offset in physical memory +* @size: the framebuffer size in bytes +* @funcs: callback functions +* +* Installs the given device as the new owner. The function fails if the +* framebuffer range, or parts of it, is currently owned by another driver. +* To evict current owners, callers should use +* drm_fb_helper_remove_conflicting_framebuffers() et al. before calling this +* function. Acquired apertures are released automatically if the underlying +* device goes away. +* +* Returns: +* An instance of struct &drm_aperture on success, or a pointer-encoded +* errno value otherwise. +*/ +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs) +{ +size_t end = base + size; +struct list_head *pos; +struct drm_aperture *ap; +int ret; + +mutex_lock (&drm_apertures_lock); + +list_for_each (pos, &drm_apertures) { + ap = container_of(pos, struct drm_aperture, lh); +if (overlap (base, end, ap->base, ap->base + ap->size)) +return ERR_PTR (-EBUSY ); + } + + ap =devm_kzalloc (dev->dev,sizeof (*ap),GFP_KERNEL ); +if (!ap) +return ERR_PTR (-ENOMEM ); + + ap->dev = dev; + ap->base = base; + ap->size = size; + ap->funcs = funcs; +INIT_LIST_HEAD (&ap->lh); + +list_add (&ap->lh, &drm_apertures); + +mutex_unlock (&drm_apertures_lock); + + ret =devm_add_action_or_reset (dev->dev, devm_aperture_acquire_release, ap); +if (ret) +return ERR_PTR (ret); + +return ap; +} +EXPORT_SYMBOL (devm_aperture_acquire); + +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +resource_size_t end = base + size; +struct list_head *pos, *n; + +mutex_lock (&drm_apertures_lock); + +list_for_each_safe (pos, n, &drm_apertures) { +struct drm_aperture *ap = + container_of(pos, struct drm_aperture, lh); +struct drm_device *dev = ap->dev; + +if (!overlap (base, end, ap->base, ap->base + ap->size)) +continue ;drivers/gpu/drm/drm_aperture.c line 287
Quoted 10 lines
drivers/gpu/drm/drm_aperture.c new file +10
-0+ + ap->dev =NULL ;/* detach from device */ +if (drm_WARN_ON (dev, !ap->funcs->detach)) +continue ; + ap->funcs->detach (dev, ap->base, ap->size); + } + +mutex_unlock (&drm_apertures_lock); +} +EXPORT_SYMBOL (drm_aperture_detach_drivers);Is this just exported because of the inline functions in the headers? Imo better to make them proper functions (they're big after your patch¬ perf critical, so not good candidates for inlining anyway).
Quoted 65 lines
include/drm/drm_aperture.h +37
-1@@ -4,8 +4,30 @@#define _DRM_APERTURE_H_#include <linux/fb.h> +#include <linux/pci.h> #include <linux/vgaarb.h> +struct drm_aperture ; +struct drm_device ; + +struct drm_aperture_funcs { +void (*detach)(struct drm_device *dev,resource_size_t base,resource_size_t size); +}; + +struct drm_aperture * +devm_aperture_acquire (struct drm_device *dev, +resource_size_t base,resource_size_t size, +const struct drm_aperture_funcs *funcs); + +#if defined(CONFIG_DRM_APERTURE ) +void drm_aperture_detach_drivers (resource_size_t base,resource_size_t size); +#else +static inline void +drm_aperture_detach_drivers (resource_size_t base,resource_size_t size) +{ +} +#endif +/** * drm_fb_helper_remove_conflicting_framebuffers - remove firmware-configured framebuffers * @a: memory range, users of which are to be removed @@ -20,6 +42,11 @@ static inline int drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary) { + int i; + +for (i =0 ; i < a->count; ++i) +drm_aperture_detach_drivers (a->ranges[i].base, a->ranges[i].size); +#if IS_REACHABLE (CONFIG_FB )return remove_conflicting_framebuffers (a, name, primary);#else @@ -43,7 +70,16 @@ static inline int drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const char *name) { - int ret = 0; + resource_size_t base, size; +int bar, ret =0 ; + +for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) { +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) +continue ; + base =pci_resource_start (pdev, bar); + size =pci_resource_len (pdev, bar); +drm_aperture_detach_drivers (base, size); + }/* * WARNING: Apparently we must kick fbdev drivers before vgacon, Signature · 1 line
2.30.1Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v2 5/10 drm: Add simpledrm driver
In reply to Thomas ZimmermannThe simpledrm driver is a DRM driver for simplefb framebuffers as provided by the kernel's boot code. This driver enables basic graphical output on many different graphics devices that are provided by the platform (e.g., EFI, VESA, embedded framebuffers).
With the kernel's simplefb infrastructure, the kernel receives a pre-configured framebuffer from the system (i.e., firmware, boot loader). It creates a platform device to which simpledrm attaches. The system's framebuffer consists of a memory range, size and format. Based on these values, simpledrm creates a DRM devices. No actual modesetting is possible.
v2:
* rename driver to simpledrm
* add dri-devel to MAINTAINERS entry
* put native format first in primary-plane format list (Daniel)
* inline simplekms_device_cleanup() (Daniel)
* use helpers for shadow-buffered planes
* fix whitespace errors
--- MAINTAINERS | 7 + drivers/gpu/drm/tiny/Kconfig | 16 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/simpledrm.c | 527 +++++++++++++++++++++++++++++++ 4 files changed, 551 insertions(+) create mode 100644 drivers/gpu/drm/tiny/simpledrm.c
MAINTAINERS +7 -0
@@ -5744,6 +5744,13 @@ S: Orphan / Obsolete F: drivers/gpu/drm/savage/ F: include/uapi/drm/savage_drm.h +DRM DRIVER FOR SIMPLE FRAMEBUFFERS +M: Thomas Zimmermann <[email protected]> +L: [email protected] +S: Maintained +T: git git://anongit.freedesktop.org/drm/drm-misc +F: drivers/gpu/drm/tiny/simplekms.c + DRM DRIVER FOR SIS VIDEO CARDS S: Orphan / Obsolete F: drivers/gpu/drm/sis/
drivers/gpu/drm/tiny/Kconfig +16 -0
@@ -38,6 +38,22 @@ config DRM_GM12U320 This is a KMS driver for projectors which use the GM12U320 chipset for video transfer over USB2/3, such as the Acer C120 mini projector. +config DRM_SIMPLEDRM + tristate "Simple framebuffer driver" + depends on DRM + select DRM_GEM_SHMEM_HELPER + select DRM_KMS_HELPER + help + DRM driver for simple platform-provided framebuffers. + + This driver assumes that the display hardware has been initialized + by the firmware or bootloader before the kernel boots. Scanout + buffer, size, and display format must be provided via device tree, + UEFI, VESA, etc. + + On x86 and compatible, you should also select CONFIG_X86_SYSFB to + use UEFI and VESA framebuffers. + config TINYDRM_HX8357D tristate "DRM support for HX8357D display panels" depends on DRM && SPI
drivers/gpu/drm/tiny/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus.o obj-$(CONFIG_DRM_GM12U320) += gm12u320.o +obj-$(CONFIG_DRM_SIMPLEDRM) += simpledrm.o obj-$(CONFIG_TINYDRM_HX8357D) += hx8357d.o obj-$(CONFIG_TINYDRM_ILI9225) += ili9225.o obj-$(CONFIG_TINYDRM_ILI9341) += ili9341.o
drivers/gpu/drm/tiny/simpledrm.c new file +527 -0
527 lines not on this page · raw message
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v2 6/10 drm/simpledrm: Add fbdev emulation
In reply to Thomas ZimmermannThis displays a console on simpledrm's framebuffer. The default framebuffer format is being used.
--- drivers/gpu/drm/tiny/simpledrm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +3 -0
@@ -8,6 +8,7 @@#include <drm/drm_damage_helper.h> #include <drm/drm_device.h> #include <drm/drm_drv.h> +#include <drm/drm_fb_helper.h> #include <drm/drm_format_helper.h> #include <drm/drm_gem_atomic_helper.h> #include <drm/drm_gem_framebuffer_helper.h>
@@ -500,6 +501,8 @@ static int simpledrm_probe(struct platform_device *pdev)if (ret)return ret; +drm_fbdev_generic_setup (dev,0 ); +return 0 ; }
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v2 7/10 drm/simpledrm: Initialize framebuffer data from device-tree node
In reply to Thomas ZimmermannA firmware framebuffer might also be specified via device-tree files. If no device platform data is given, try the DT device node.
v2:
* add Device Tree match table
* clean-up parser wrappers
--- drivers/gpu/drm/tiny/simpledrm.c | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +89 -0
@@ -114,6 +114,74 @@ simplefb_get_format_pd(struct drm_device *dev,return simplefb_get_validated_format (dev, pd->format); } +static int +simplefb_read_u32_of (struct drm_device *dev,struct device_node *of_node, +const char *name,u32 *value) +{ +int ret =of_property_read_u32 (of_node, name, value); + +if (ret) +drm_err (dev,"simplefb: cannot parse framebuffer %s: error %d\n" , + name, ret); +return ret; +} + +static int +simplefb_read_string_of (struct drm_device *dev,struct device_node *of_node, +const char *name,const char **value) +{ +int ret =of_property_read_string (of_node, name, value); + +if (ret) +drm_err (dev,"simplefb: cannot parse framebuffer %s: error %d\n" , + name, ret); +return ret; +} + +static int +simplefb_get_width_of (struct drm_device *dev,struct device_node *of_node) +{ +u32 width; +int ret =simplefb_read_u32_of (dev, of_node,"width" , &width); + +if (ret) +return ret; +return simplefb_get_validated_int0 (dev,"width" , width); +} + +static int +simplefb_get_height_of (struct drm_device *dev,struct device_node *of_node) +{ +u32 height; +int ret =simplefb_read_u32_of (dev, of_node,"height" , &height); + +if (ret) +return ret; +return simplefb_get_validated_int0 (dev,"height" , height); +} + +static int +simplefb_get_stride_of (struct drm_device *dev,struct device_node *of_node) +{ +u32 stride; +int ret =simplefb_read_u32_of (dev, of_node,"stride" , &stride); + +if (ret) +return ret; +return simplefb_get_validated_int (dev,"stride" , stride); +} + +static const struct drm_format_info * +simplefb_get_format_of (struct drm_device *dev,struct device_node *of_node) +{ +const char *format; +int ret =simplefb_read_string_of (dev, of_node,"format" , &format); + +if (ret) +return ERR_PTR (ret); +return simplefb_get_validated_format (dev, format); +} +/* * Simple Framebuffer device */
@@ -166,6 +234,7 @@ static int simpledrm_device_init_fb(struct simpledrm_device *sdev)struct drm_device *dev = &sdev->dev;struct platform_device *pdev = sdev->pdev;const struct simplefb_platform_data *pd =dev_get_platdata (&pdev->dev); +struct device_node *of_node = pdev->dev.of_node;if (pd) { width =simplefb_get_width_pd (dev, pd);
@@ -180,6 +249,19 @@ static int simpledrm_device_init_fb(struct simpledrm_device *sdev) format =simplefb_get_format_pd (dev, pd);if (IS_ERR (format))return PTR_ERR (format); + }else if (of_node) { + width =simplefb_get_width_of (dev, of_node); +if (width <0 ) +return width; + height =simplefb_get_height_of (dev, of_node); +if (height <0 ) +return height; + stride =simplefb_get_stride_of (dev, of_node); +if (stride <0 ) +return stride; + format =simplefb_get_format_of (dev, of_node); +if (IS_ERR (format)) +return PTR_ERR (format); }else {drm_err (dev,"no simplefb configuration found\n" );return -ENODEV ;
@@ -516,9 +598,16 @@ static int simpledrm_remove(struct platform_device *pdev)return 0 ; } +static const struct of_device_id simpledrm_of_match_table[] = { + { .compatible ="simple-framebuffer" , }, + { }, +}; +MODULE_DEVICE_TABLE (of, simpledrm_of_match_table); +static struct platform_driver simpledrm_platform_driver = { .driver = { .name ="simple-framebuffer" ,/* connect to sysfb */ + .of_match_table = simpledrm_of_match_table, }, .probe = simpledrm_probe, .remove = simpledrm_remove,
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v2 8/10 drm/simpledrm: Acquire clocks from DT device node
In reply to Thomas ZimmermannMake sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
--- drivers/gpu/drm/tiny/simpledrm.c | 108 +++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +108 -0
@@ -1,5 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only +#include <linux/clk.h> +#include <linux/of_clk.h> #include <linux/platform_data/simplefb.h> #include <linux/platform_device.h>
@@ -190,6 +192,12 @@ struct simpledrm_device {struct drm_device dev;struct platform_device *pdev; +/* clocks */ +#if definedCONFIG_OF && definedCONFIG_COMMON_CLK +unsigned int clk_count; +struct clk **clks; +#endif +/* simplefb settings */ struct drm_display_mode mode;const struct drm_format_info *format;
@@ -211,6 +219,103 @@ static struct simpledrm_device *simpledrm_device_of_dev(struct drm_device *dev) return container_of(dev, struct simpledrm_device, dev); } +/* +* Hardware +*/ + +#if definedCONFIG_OF && definedCONFIG_COMMON_CLK +/* +* Clock handling code. +* +* Here we handle the clocks property of our "simple-framebuffer" dt node. +* This is necessary so that we can make sure that any clocks needed by +* the display engine that the bootloader set up for us (and for which it +* provided a simplefb dt node), stay up, for the life of the simplefb +* driver. +* +* When the driver unloads, we cleanly disable, and then release the clocks. +* +* We only complain about errors here, no action is taken as the most likely +* error can only happen due to a mismatch between the bootloader which set +* up simplefb, and the clock definitions in the device tree. Chances are +* that there are no adverse effects, and if there are, a clean teardown of +* the fb probe will not help us much either. So just complain and carry on, +* and hope that the user actually gets a working fb at the end of things. +*/ + +static void simpledrm_device_release_clocks (void *res) +{ +struct simpledrm_device *sdev =simpledrm_device_of_dev (res); +unsigned int i; + +for (i =0 ; i < sdev->clk_count; ++i) { +if (sdev->clks[i]) { +clk_disable_unprepare (sdev->clks[i]); +clk_put (sdev->clks[i]); + } + } +} + +static int simpledrm_device_init_clocks (struct simpledrm_device *sdev) +{ +struct drm_device *dev = &sdev->dev; +struct platform_device *pdev = sdev->pdev; +struct device_node *of_node = pdev->dev.of_node; +struct clk *clock; +unsigned int i; +int ret; + +if (dev_get_platdata (&pdev->dev) || !of_node) +return 0 ; + + sdev->clk_count =of_clk_get_parent_count (of_node); +if (!sdev->clk_count) +return 0 ; + + sdev->clks =drmm_kzalloc (dev, sdev->clk_count *sizeof (sdev->clks[0 ]), +GFP_KERNEL ); +if (!sdev->clks) +return -ENOMEM ; + +for (i =0 ; i < sdev->clk_count; ++i) { + clock =of_clk_get (of_node, i); +if (IS_ERR (clock)) { + ret =PTR_ERR (clock); +if (ret == -EPROBE_DEFER ) + goto err; +drm_err (dev,"clock %u not found: %d\n" , i, ret); +continue ; + } + ret =clk_prepare_enable (clock); +if (ret) { +drm_err (dev,"failed to enable clock %u: %d\n" , + i, ret); +clk_put (clock); + } + sdev->clks[i] = clock; + } + +return devm_add_action_or_reset (&pdev->dev, + simpledrm_device_release_clocks, + sdev); + +err: +while (i) { + --i; +if (sdev->clks[i]) { +clk_disable_unprepare (sdev->clks[i]); +clk_put (sdev->clks[i]); + } + } +return ret; +} +#else +static int simpledrm_device_init_clocks (struct simpledrm_device *sdev) +{ +return 0 ; +} +#endif +/* * Simplefb settings */
@@ -534,6 +639,9 @@ simpledrm_device_create(struct drm_driver *drv, struct platform_device *pdev)return ERR_CAST (sdev); sdev->pdev = pdev; + ret =simpledrm_device_init_clocks (sdev); +if (ret) +return ERR_PTR (ret); ret =simpledrm_device_init_fb (sdev);if (ret)return ERR_PTR (ret);
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
Hi Thomas,
Quoted 8 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>
Thanks for your patch!
Quoted 31 lines
drivers/gpu/drm/tiny/simpledrm.c +28
-0+static int simpledrm_device_init_clocks (struct simpledrm_device *sdev) +{ +struct drm_device *dev = &sdev->dev; +struct platform_device *pdev = sdev->pdev; +struct device_node *of_node = pdev->dev.of_node; +struct clk *clock; +unsigned int i; +int ret; + +if (dev_get_platdata (&pdev->dev) || !of_node) +return 0 ; + + sdev->clk_count =of_clk_get_parent_count (of_node); +if (!sdev->clk_count) +return 0 ; + + sdev->clks =drmm_kzalloc (dev, sdev->clk_count *sizeof (sdev->clks[0 ]), +GFP_KERNEL ); +if (!sdev->clks) +return -ENOMEM ; + +for (i =0 ; i < sdev->clk_count; ++i) { + clock =of_clk_get (of_node, i); +if (IS_ERR (clock)) { + ret =PTR_ERR (clock); +if (ret == -EPROBE_DEFER ) + goto err; +drm_err (dev,"clock %u not found: %d\n" , i, ret);
drivers/gpu/drm/tiny/simpledrm.c static struct simpledrm_device *simpledrm_device_of_dev(struct drm_device *dev) · line 296
Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +10
-0+continue ; + } + ret =clk_prepare_enable (clock); +if (ret) { +drm_err (dev,"failed to enable clock %u: %d\n" , + i, ret); +clk_put (clock); + } + sdev->clks[i] = clock; + }
of_clk_bulk_get_all() + clk_bulk_prepare_enable()?
There's also devm_clk_bulk_get_all(), but not for the OF variant.
Gr{oetje,eeting}s,
Geert
Signature · 9 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
Hi
Am 18.03.21 um 11:39 schrieb Geert Uytterhoeven:
Quoted 58 lines
Hi Thomas,
Quoted 8 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>Thanks for your patch!
Quoted 31 lines
drivers/gpu/drm/tiny/simpledrm.c +28
-0+static int simpledrm_device_init_clocks (struct simpledrm_device *sdev) +{ +struct drm_device *dev = &sdev->dev; +struct platform_device *pdev = sdev->pdev; +struct device_node *of_node = pdev->dev.of_node; +struct clk *clock; +unsigned int i; +int ret; + +if (dev_get_platdata (&pdev->dev) || !of_node) +return 0 ; + + sdev->clk_count =of_clk_get_parent_count (of_node); +if (!sdev->clk_count) +return 0 ; + + sdev->clks =drmm_kzalloc (dev, sdev->clk_count *sizeof (sdev->clks[0 ]), +GFP_KERNEL ); +if (!sdev->clks) +return -ENOMEM ; + +for (i =0 ; i < sdev->clk_count; ++i) { + clock =of_clk_get (of_node, i); +if (IS_ERR (clock)) { + ret =PTR_ERR (clock); +if (ret == -EPROBE_DEFER ) + goto err; +drm_err (dev,"clock %u not found: %d\n" , i, ret);drivers/gpu/drm/tiny/simpledrm.c static struct simpledrm_device *simpledrm_device_of_dev(struct drm_device *dev) · line 296
Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +10
-0+continue ; + } + ret =clk_prepare_enable (clock); +if (ret) { +drm_err (dev,"failed to enable clock %u: %d\n" , + i, ret); +clk_put (clock); + } + sdev->clks[i] = clock; + }
of_clk_bulk_get_all()+clk_bulk_prepare_enable()?
Quoted 1 line
There's also
devm_clk_bulk_get_all(), but not for the OF variant.
Right, you mentioned this on the original patch set. I tried to use the functions, but TBH I found them to obfuscate the overall logic of the function. So I went back to the original code. Hopefully this is not too much of an issue.
Best regards
Thomas
Quoted 5 lines
Gr{oetje,eeting}s,
Geert
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
In reply to Thomas ZimmermannHi,
Quoted 8 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>
Even though it's definitely simpler to review, merging the driver first and then the clocks and regulators will break bisection on the platforms that rely on them
Another thing worth considering is also that both drivers will probe if they are enabled (which is pretty likely), which is not great :)
I guess we should make them mutually exclusive through Kconfig
Maxime
Thomas Zimmermann
maintainerRe: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
Hi
Am 08.04.21 um 10:13 schrieb Maxime Ripard:
Quoted 9 lines
Hi,
Quoted 6 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>Even though it's definitely simpler to review, merging the driver first and then the clocks and regulators will break bisection on the platforms that rely on them
I'd like to keep the patches separate for now, but can squash patches 6 to 8 them into one before pushing them. OK?
Quoted 5 lines
Another thing worth considering is also that both drivers will probe if they are enabled (which is pretty likely), which is not great :)
I guess we should make them mutually exclusive through
Kconfig
We already have several drivers in fbdev and DRM that handle the same hardware. We don't do this for any other pair, why bother now?
Best regards
Thomas
Quoted 3 lines
Maxime
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Re: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
Hi,
Quoted 13 lines · Thomas Zimmermann
Am 08.04.21 um 10:13 schrieb Maxime Ripard:
Quoted 12 lines
Hi,
Quoted 8 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>
Quoted 6 lines
Quoted 3 lines
Even though it's definitely simpler to review, merging the driver first and then the clocks and regulators will break bisection on the platforms that rely on them
I'd like to keep the patches separate for now, but can squash patches 6 to 8 them into one before pushing them. OK?
Yep, that works for me :)
Quoted 8 lines
Quoted 5 lines
Another thing worth considering is also that both drivers will probe if they are enabled (which is pretty likely), which is not great :)
I guess we should make them mutually exclusive through
KconfigWe already have several drivers in fbdev and DRM that handle the same hardware. We don't do this for any other pair, why bother now?
Yeah, but simplefb/simpledrm are going to be enabled pretty much everywhere, as opposed to the other drivers that are more specialized.
Maxime
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
Hi
Am 15.04.21 um 11:21 schrieb Maxime Ripard:
Quoted 29 lines
Hi,
Quoted 13 lines · Thomas Zimmermann
Am 08.04.21 um 10:13 schrieb Maxime Ripard:
Quoted 12 lines
Hi,
Quoted 8 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>Quoted 6 lines
Quoted 3 lines
Even though it's definitely simpler to review, merging the driver first and then the clocks and regulators will break bisection on the platforms that rely on them
I'd like to keep the patches separate for now, but can squash patches 6 to 8 them into one before pushing them. OK?
Yep, that works for me :)
Quoted 4 lines
Quoted 4 lines
Another thing worth considering is also that both drivers will probe if they are enabled (which is pretty likely), which is not great :)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I guess we should make them mutually exclusive through
KconfigWe already have several drivers in fbdev and DRM that handle the same hardware. We don't do this for any other pair, why bother now?
Yeah, but simplefb/simpledrm are going to be enabled pretty much everywhere, as opposed to the other drivers that are more specialized.
Well, OK. But I'd like to give simpledrm preference over simplefb. There should be an incentive to switch to DRM.
Best regards
Thomas
Quoted 3 lines
Maxime
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2 08/10] drm/simpledrm: Acquire clocks from DT device node
Quoted 34 lines · Thomas Zimmermann
Hi
Am 15.04.21 um 11:21 schrieb Maxime Ripard:
Quoted 31 lines
Hi,
Quoted 13 lines · Thomas Zimmermann
Am 08.04.21 um 10:13 schrieb Maxime Ripard:
Quoted 12 lines
Hi,
Quoted 8 lines · Thomas Zimmermann
Make sure required hardware clocks are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Clocks are released automatically via devres helpers.
Signed-off-by Thomas Zimmermann <[email protected]>Tested-by nerdopolis <[email protected]>Quoted 6 lines
Quoted 3 lines
Even though it's definitely simpler to review, merging the driver first and then the clocks and regulators will break bisection on the platforms that rely on them
I'd like to keep the patches separate for now, but can squash patches 6 to 8 them into one before pushing them. OK?
Yep, that works for me :)
Quoted 6 lines
Quoted 5 lines
Another thing worth considering is also that both drivers will probe if they are enabled (which is pretty likely), which is not great :)
I guess we should make them mutually exclusive through
Kconfig
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
We already have several drivers in fbdev and DRM that handle the same hardware. We don't do this for any other pair, why bother now?
Yeah, but simplefb/simpledrm are going to be enabled pretty much everywhere, as opposed to the other drivers that are more specialized.
Well, OK. But I'd like to give simpledrm preference over simplefb. There should be an incentive to switch to DRM.
Yeah that makes total sense :)
Maxime
Thomas Zimmermann
maintainerPATCH v2 9/10 drm/simpledrm: Acquire regulators from DT device node
In reply to Thomas ZimmermannMake sure required hardware regulators are enabled while the firmware framebuffer is in use.
The basic code has been taken from the simplefb driver and adapted to DRM. Regulators are released automatically via devres helpers.
v2:
* use strscpy()
--- drivers/gpu/drm/tiny/simpledrm.c | 128 +++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +128 -0
@@ -4,6 +4,7 @@#include <linux/of_clk.h> #include <linux/platform_data/simplefb.h> #include <linux/platform_device.h> +#include <linux/regulator/consumer.h> #include <drm/drm_atomic_state_helper.h> #include <drm/drm_connector.h>
@@ -197,6 +198,11 @@ struct simpledrm_device {unsigned int clk_count;struct clk **clks;#endif +/* regulators */ +#if definedCONFIG_OF && definedCONFIG_REGULATOR +unsigned int regulator_count; +struct regulator **regulators; +#endif /* simplefb settings */ struct drm_display_mode mode;
@@ -316,6 +322,125 @@ static int simpledrm_device_init_clocks(struct simpledrm_device *sdev) }#endif +#if definedCONFIG_OF && definedCONFIG_REGULATOR + +#define SUPPLY_SUFFIX "-supply" + +/* +* Regulator handling code. +* +* Here we handle the num-supplies and vin*-supply properties of our +* "simple-framebuffer" dt node. This is necessary so that we can make sure +* that any regulators needed by the display hardware that the bootloader +* set up for us (and for which it provided a simplefb dt node), stay up, +* for the life of the simplefb driver. +* +* When the driver unloads, we cleanly disable, and then release the +* regulators. +* +* We only complain about errors here, no action is taken as the most likely +* error can only happen due to a mismatch between the bootloader which set +* up simplefb, and the regulator definitions in the device tree. Chances are +* that there are no adverse effects, and if there are, a clean teardown of +* the fb probe will not help us much either. So just complain and carry on, +* and hope that the user actually gets a working fb at the end of things. +*/ + +static void simpledrm_device_release_regulators (void *res) +{ +struct simpledrm_device *sdev =simpledrm_device_of_dev (res); +unsigned int i; + +for (i =0 ; i < sdev->regulator_count; ++i) { +if (sdev->regulators[i]) { +regulator_disable (sdev->regulators[i]); +regulator_put (sdev->regulators[i]); + } + } +} + +static int simpledrm_device_init_regulators (struct simpledrm_device *sdev) +{ +struct drm_device *dev = &sdev->dev; +struct platform_device *pdev = sdev->pdev; +struct device_node *of_node = pdev->dev.of_node; +struct property *prop; +struct regulator *regulator; +const char *p; +unsigned int count =0 , i =0 ; +int ret; + +if (dev_get_platdata (&pdev->dev) || !of_node) +return 0 ; + +/* Count the number of regulator supplies */ +for_each_property_of_node (of_node, prop) { + p =strstr (prop->name,SUPPLY_SUFFIX ); +if (p && p != prop->name) + ++count; + } + +if (!count) +return 0 ; + + sdev->regulators =drmm_kzalloc (dev, + count *sizeof (sdev->regulators[0 ]), +GFP_KERNEL ); +if (!sdev->regulators) +return -ENOMEM ; + +for_each_property_of_node (of_node, prop) { +char name[32 ];/* 32 is max size of property name */ +size_t len; + + p =strstr (prop->name,SUPPLY_SUFFIX ); +if (!p || p == prop->name) +continue ; + len =strlen (prop->name) -strlen (SUPPLY_SUFFIX ) +1 ; +strscpy (name, prop->name,min (sizeof (name), len)); + + regulator =regulator_get_optional (&pdev->dev, name); +if (IS_ERR (regulator)) { + ret =PTR_ERR (regulator); +if (ret == -EPROBE_DEFER ) + goto err; +drm_err (dev,"regulator %s not found: %d\n" , + name, ret); +continue ; + } + + ret =regulator_enable (regulator); +if (ret) { +drm_err (dev,"failed to enable regulator %u: %d\n" , + i, ret); +regulator_put (regulator); + } + + sdev->regulators[i++] = regulator; + } + sdev->regulator_count = i; + +return devm_add_action_or_reset (&pdev->dev, + simpledrm_device_release_regulators, + sdev); + +err: +while (i) { + --i; +if (sdev->regulators[i]) { +regulator_disable (sdev->regulators[i]); +regulator_put (sdev->regulators[i]); + } + } +return ret; +} +#else +static int simpledrm_device_init_regulators (struct simpledrm_device *sdev) +{ +return 0 ; +} +#endif +/* * Simplefb settings */
@@ -640,6 +765,9 @@ simpledrm_device_create(struct drm_driver *drv, struct platform_device *pdev) sdev->pdev = pdev; ret =simpledrm_device_init_clocks (sdev); +if (ret) +return ERR_PTR (ret); + ret =simpledrm_device_init_regulators (sdev);if (ret)return ERR_PTR (ret); ret =simpledrm_device_init_fb (sdev);
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v2 10/10 drm/simpledrm: Acquire memory aperture for framebuffer
In reply to Thomas ZimmermannWe register the simplekms device with the DRM platform helpers. A native driver for the graphics hardware will kick-out the simpledrm driver before taking over the device.
v2:
* adapt to aperture changes
* use drm_dev_unplug() and drm_dev_enter/exit()
* don't split error string
--- drivers/gpu/drm/tiny/Kconfig | 1 + drivers/gpu/drm/tiny/simpledrm.c | 83 ++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 3 deletions(-)
drivers/gpu/drm/tiny/Kconfig +1 -0
@@ -41,6 +41,7 @@ config DRM_GM12U320 config DRM_SIMPLEDRM tristate "Simple framebuffer driver" depends on DRM + select DRM_APERTURE select DRM_GEM_SHMEM_HELPER select DRM_KMS_HELPER help
drivers/gpu/drm/tiny/simpledrm.c +80 -3
146 lines not on this page · raw message
Signature · 6 lines
2.30.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Hi,
Quoted 28 lines · Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Quoted 6 lines
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
Thank you for your work on this, this is very interesting.
Quoted 14 lines
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
Quoted 7 lines
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
I'm not sure what you mean with this ? Currently deferred-takeover is handled in the fbcon code. Current flickerfree boot works like this (assuming a single LCD panel in a laptop):
1. EFI/GOP sets up the framebuffer, draws a vendor logo
2. The bootloader runs in silent mode and does not touch anything gfx related
3. kernel boots, with a loglevel of 3 so only CRIT/EMERG messages are shown
2. efifb loads; and tells fbcon that a framebuffer is now available for it to "bind" to. Since CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y fbcon defers taking over the console and leaves the dummy-console driver in place (unless there have already been kernel messages logged, which there shouldn't because loglevel=3)
3. i915 loads, reads out the hw state compares this to the preferred-mode for the panel which it would set, they match, nothing happens. i915 takes ownership of the scanout-buffer set up by the GOP, but leaves it in place.
i915 also removes the efifb /dev/fb0 and installs its own /dev/fb0 fbdev compat device, fbcon is notified of this, but is still deferred and leaves the dummy console driver in place as console driver.
4. Plymouth loads, allocates a new scan-out buffer at the panel's preferred resolution, plymouth reads the vendor-logo through the BGRT ACPI interface and fills the scanout-buffer with the vendor-logo + a spinner. Then plymouth installs the new scanout-buffer on the crtc, this is done atomically during vsync, so the user sees no changes, other then the spinner appearing
(note the active VT is now in graphical mode)
5. From here on not flickering is a userspace problem
AFAICT this should work fine with simplekms too, unless it clears the screen to black when it binds.
An addition to the above sequence, if at any time either the kernel or userspace prints a message to the console; and at that time a fbdev is registered then fbcon will takeover as the console driver from the dummy driver and it will start drawing to the registered fbdev (1), destroying the framebuffer contents. Also if any messages where printend while no fbdev was registered, then fbcon will takeover the console as soon as a fbdev gets registered.
So since we already have deferred-takeover in the fbcon code, I wonder what you mean when you are talking about "provide deferred takeover" for simplekms?
Regards,
Hans
1) Except when the VT has been switched to GFX mode when this happens, then fbcon will delay using the fbdev until the VT is switched back to text mode.
p.s.
This has the interesting side effect then when logging into a desktop GUI session:
kernel -> plymouth -> gdm -> GNOME user session
There never is any output to the text-console and fbcon never takes-over, so on many Laptops running say Fedora workstation the fbcon code is actually unused until the user manually switches to another virtual-console to log in in text-mode:
[hans@x1 ~]$ dmesg | grep -E 'fbcon|Console:|Truecolor'
[ 0.258904] Console: colour dummy device 80x25 [ 1.274726] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0 [ 1.274768] fbcon: Deferring console take-over [ 2.540894] fbcon: i915drmfb (fb0) is primary device [ 2.540896] fbcon: Deferring console take-over
[hans@x1 ~]$ uptime
12:29:39 up 4:19, 1 user, load average: 0.58, 0.75, 0.81
Look mom no fbcon
Quoted 45 lines
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 + MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +- 14 files changed, 1466 insertions(+), 60 deletions(-) create mode 100644 drivers/gpu/drm/drm_aperture.c create mode 100644 drivers/gpu/drm/tiny/simpledrm.c create mode 100644 include/drm/drm_aperture.h
Quoted 3 lines
--
2.30.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerHi
Am 25.03.21 um 12:29 schrieb Hans de Goede:
Quoted 87 lines
Hi,
Quoted 28 lines · Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Quoted 6 lines
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
Thank you for your work on this, this is very interesting.
Quoted 14 lines
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
Quoted 7 lines
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
I'm not sure what you mean with this ? Currently deferred-takeover is handled in the fbcon code. Current flickerfree boot works like this (assuming a single LCD panel in a laptop):
1. EFI/GOP sets up the framebuffer, draws a vendor logo
2. The bootloader runs in silent mode and does not touch anything gfx related
3. kernel boots, with a loglevel of 3 so only CRIT/EMERG messages are shown
2. efifb loads; and tells fbcon that a framebuffer is now available for it to "bind" to. SinceCONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=yfbcon defers taking over the console and leaves the dummy-console driver in place (unless there have already been kernel messages logged, which there shouldn't because loglevel=3)
3. i915 loads, reads out the hw state compares this to the preferred-mode for the panel which it would set, they match, nothing happens. i915 takes ownership of the scanout-buffer set up by the GOP, but leaves it in place.
i915 also removes the efifb/dev/fb0and installs its own/dev/fb0fbdev compat device, fbcon is notified of this, but is still deferred and leaves the dummy console driver in place as console driver.
4. Plymouth loads, allocates a new scan-out buffer at the panel's preferred resolution, plymouth reads the vendor-logo through the BGRT ACPI interface and fills the scanout-buffer with the vendor-logo + a spinner. Then plymouth installs the new scanout-buffer on the crtc, this is done atomically during vsync, so the user sees no changes, other then the spinner appearing
(note the active VT is now in graphical mode)
5. From here on not flickering is a userspace problem
Quoted 2 lines
AFAICT this should work fine with simplekms too, unless it clears the screen to black when it binds.
I forgot to add the code that clears the screen, but that's the case here.
Instead of a plane-disable operation, simpledrm can at best clear the screen. This would happen during the initial mode-config reset IIRC. But we need to keep the display content stored in a framebuffer, so read-out helpers are required. There are more users of these read-out helpers. Adding them at some point probably makes sense.
Other drivers might also want to read the initial config from simpledrm via read-out helpers. I think only i915 currently supports something like that ATM.
Best regards
Thomas
Quoted 93 lines
An addition to the above sequence, if at any time either the kernel or userspace prints a message to the console; and at that time a fbdev is registered then fbcon will takeover as the console driver from the dummy driver and it will start drawing to the registered fbdev (1), destroying the framebuffer contents. Also if any messages where printend while no fbdev was registered, then fbcon will takeover the console as soon as a fbdev gets registered.
So since we already have deferred-takeover in the fbcon code, I wonder what you mean when you are talking about "provide deferred takeover" for simplekms?
Regards,
Hans
1) Except when the VT has been switched to GFX mode when this happens, then fbcon will delay using the fbdev until the VT is switched back to text mode.
p.s.
This has the interesting side effect then when logging into a desktop GUI session:
kernel -> plymouth -> gdm -> GNOME user sessionThere never is any output to the text-console and fbcon never takes-over, so on many Laptops running say Fedora workstation the fbcon code is actually unused until the user manually switches to another virtual-console to log in in text-mode:
[hans@x1 ~]$ dmesg | grep -E 'fbcon|Console:|Truecolor'
[ 0.258904] Console: colour dummy device 80x25 [ 1.274726] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0 [ 1.274768] fbcon: Deferring console take-over [ 2.540894] fbcon: i915drmfb (fb0) is primary device [ 2.540896] fbcon: Deferring console take-over[hans@x1 ~]$ uptime
12:29:39 up 4:19, 1 user, load average: 0.58, 0.75, 0.81Look mom no fbcon
Quoted 48 lines
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 + MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +- 14 files changed, 1466 insertions(+), 60 deletions(-)create mode 100644
drivers/gpu/drm/drm_aperture.ccreate mode 100644drivers/gpu/drm/tiny/simpledrm.ccreate mode 100644include/drm/drm_aperture.h--
2.30.1
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi,
Quoted 90 lines · Thomas Zimmermann
Hi
Am 25.03.21 um 12:29 schrieb Hans de Goede:
Quoted 87 lines
Hi,
Quoted 28 lines · Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Quoted 6 lines
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
Thank you for your work on this, this is very interesting.
Quoted 14 lines
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
Quoted 7 lines
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
I'm not sure what you mean with this ? Currently deferred-takeover is handled in the fbcon code. Current flickerfree boot works like this (assuming a single LCD panel in a laptop):
1. EFI/GOP sets up the framebuffer, draws a vendor logo
2. The bootloader runs in silent mode and does not touch anything gfx related
3. kernel boots, with a loglevel of 3 so only CRIT/EMERG messages are shown
2. efifb loads; and tells fbcon that a framebuffer is now available for it to "bind" to. SinceCONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=yfbcon defers taking over the console and leaves the dummy-console driver in place (unless there have already been kernel messages logged, which there shouldn't because loglevel=3)
3. i915 loads, reads out the hw state compares this to the preferred-mode for the panel which it would set, they match, nothing happens. i915 takes ownership of the scanout-buffer set up by the GOP, but leaves it in place.
i915 also removes the efifb/dev/fb0and installs its own/dev/fb0fbdev compat device, fbcon is notified of this, but is still deferred and leaves the dummy console driver in place as console driver.
4. Plymouth loads, allocates a new scan-out buffer at the panel's preferred resolution, plymouth reads the vendor-logo through the BGRT ACPI interface and fills the scanout-buffer with the vendor-logo + a spinner. Then plymouth installs the new scanout-buffer on the crtc, this is done atomically during vsync, so the user sees no changes, other then the spinner appearing
(note the active VT is now in graphical mode)
5. From here on not flickering is a userspace problem
Quoted 6 lines
Quoted 2 lines
AFAICT this should work fine with simplekms too, unless it clears the screen to black when it binds.
I forgot to add the code that clears the screen, but that's the case here.
Instead of a plane-disable operation, simpledrm can at best clear the screen. This would happen during the initial mode-config reset IIRC.
Hmm, clearing the screen without any (atomic) modesets being initiated by either an in kernel drm-client or userspace seems wrong, this is certainly different from what the i915 driver does. The way I see it either a drm client provides a new framebuffer in which case you copy that over the old contents, effectively clearing it. Or a drm-client gets a handle and draws to the current fb directly, in which case it is the clients responsibility to clear it itself first.
IOW I believe that simpledrm should not clear the screen itself at all.
Regards,
Hans
Quoted 101 lines
But we need to keep the display content stored in a framebuffer, so read-out helpers are required. There are more users of these read-out helpers. Adding them at some point probably makes sense.
Other drivers might also want to read the initial config from simpledrm via read-out helpers. I think only i915 currently supports something like that ATM.
Best regards
ThomasQuoted 93 lines
An addition to the above sequence, if at any time either the kernel or userspace prints a message to the console; and at that time a fbdev is registered then fbcon will takeover as the console driver from the dummy driver and it will start drawing to the registered fbdev (1), destroying the framebuffer contents. Also if any messages where printend while no fbdev was registered, then fbcon will takeover the console as soon as a fbdev gets registered.
So since we already have deferred-takeover in the fbcon code, I wonder what you mean when you are talking about "provide deferred takeover" for simplekms?
Regards,
Hans
1) Except when the VT has been switched to GFX mode when this happens, then fbcon will delay using the fbdev until the VT is switched back to text mode.
p.s.
This has the interesting side effect then when logging into a desktop GUI session:
kernel -> plymouth -> gdm -> GNOME user sessionThere never is any output to the text-console and fbcon never takes-over, so on many Laptops running say Fedora workstation the fbcon code is actually unused until the user manually switches to another virtual-console to log in in text-mode:
[hans@x1 ~]$ dmesg | grep -E 'fbcon|Console:|Truecolor' [ 0.258904] Console: colour dummy device 80x25
[ 1.274726] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0 [ 1.274768] fbcon: Deferring console take-over
[ 2.540894] fbcon: i915drmfb (fb0) is primary device [ 2.540896] fbcon: Deferring console take-over [hans@x1 ~]$ uptime
12:29:39 up 4:19, 1 user, load average: 0.58, 0.75, 0.81Look mom no fbcon
Quoted 48 lines
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 +
MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++-drivers/gpu/drm/mgag200/mgag200_mode.c| 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +-14 files changed, 1466 insertions(+), 60 deletions(-)create mode 100644
drivers/gpu/drm/drm_aperture.ccreate mode 100644drivers/gpu/drm/tiny/simpledrm.ccreate mode 100644include/drm/drm_aperture.hSignature · 1 line
2.30.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerHi
Am 29.03.21 um 16:50 schrieb Hans de Goede:
Quoted 100 lines
Hi,
Quoted 90 lines · Thomas Zimmermann
Hi
Am 25.03.21 um 12:29 schrieb Hans de Goede:
Quoted 87 lines
Hi,
Quoted 28 lines · Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Quoted 6 lines
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
Thank you for your work on this, this is very interesting.
Quoted 14 lines
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
Quoted 7 lines
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
I'm not sure what you mean with this ? Currently deferred-takeover is handled in the fbcon code. Current flickerfree boot works like this (assuming a single LCD panel in a laptop):
1. EFI/GOP sets up the framebuffer, draws a vendor logo
2. The bootloader runs in silent mode and does not touch anything gfx related
3. kernel boots, with a loglevel of 3 so only CRIT/EMERG messages are shown
2. efifb loads; and tells fbcon that a framebuffer is now available for it to "bind" to. SinceCONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=yfbcon defers taking over the console and leaves the dummy-console driver in place (unless there have already been kernel messages logged, which there shouldn't because loglevel=3)
3. i915 loads, reads out the hw state compares this to the preferred-mode for the panel which it would set, they match, nothing happens. i915 takes ownership of the scanout-buffer set up by the GOP, but leaves it in place.
i915 also removes the efifb/dev/fb0and installs its own/dev/fb0fbdev compat device, fbcon is notified of this, but is still deferred and leaves the dummy console driver in place as console driver.
4. Plymouth loads, allocates a new scan-out buffer at the panel's preferred resolution, plymouth reads the vendor-logo through the BGRT ACPI interface and fills the scanout-buffer with the vendor-logo + a spinner. Then plymouth installs the new scanout-buffer on the crtc, this is done atomically during vsync, so the user sees no changes, other then the spinner appearing
(note the active VT is now in graphical mode)
5. From here on not flickering is a userspace problemQuoted 6 lines
Quoted 2 lines
AFAICT this should work fine with simplekms too, unless it clears the screen to black when it binds.
I forgot to add the code that clears the screen, but that's the case here.
Instead of a plane-disable operation, simpledrm can at best clear the screen. This would happen during the initial mode-config reset IIRC.
Quoted 8 lines
Hmm, clearing the screen without any (atomic) modesets being initiated by either an in kernel drm-client or userspace seems wrong, this is certainly different from what the i915 driver does. The way I see it either a drm client provides a new framebuffer in which case you copy that over the old contents, effectively clearing it. Or a drm-client gets a handle and draws to the current fb directly, in which case it is the clients responsibility to clear it itself first.
IOW I believe that simpledrm should not clear the screen itself at all.
I do as well. And when I boot with simpledrm + native driver it's flicker-free from what I can tell. But drm_mode_config_reset() is supposed to reset HW and software state. There could be some corner case where we'd have to clear the screen. For now, it should be fine.
BTW if you have the time I'd appreciate your review of the patchset.
Best regards
Thomas
Quoted 114 lines
Regards,
Hans
Quoted 101 lines
But we need to keep the display content stored in a framebuffer, so read-out helpers are required. There are more users of these read-out helpers. Adding them at some point probably makes sense.
Other drivers might also want to read the initial config from simpledrm via read-out helpers. I think only i915 currently supports something like that ATM.
Best regards
ThomasQuoted 93 lines
An addition to the above sequence, if at any time either the kernel or userspace prints a message to the console; and at that time a fbdev is registered then fbcon will takeover as the console driver from the dummy driver and it will start drawing to the registered fbdev (1), destroying the framebuffer contents. Also if any messages where printend while no fbdev was registered, then fbcon will takeover the console as soon as a fbdev gets registered.
So since we already have deferred-takeover in the fbcon code, I wonder what you mean when you are talking about "provide deferred takeover" for simplekms?
Regards,
Hans
1) Except when the VT has been switched to GFX mode when this happens, then fbcon will delay using the fbdev until the VT is switched back to text mode.
p.s.
This has the interesting side effect then when logging into a desktop GUI session:
kernel -> plymouth -> gdm -> GNOME user sessionThere never is any output to the text-console and fbcon never takes-over, so on many Laptops running say Fedora workstation the fbcon code is actually unused until the user manually switches to another virtual-console to log in in text-mode:
[hans@x1 ~]$ dmesg | grep -E 'fbcon|Console:|Truecolor' [ 0.258904] Console: colour dummy device 80x25
[ 1.274726] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0 [ 1.274768] fbcon: Deferring console take-over
[ 2.540894] fbcon: i915drmfb (fb0) is primary device [ 2.540896] fbcon: Deferring console take-over [hans@x1 ~]$ uptime
12:29:39 up 4:19, 1 user, load average: 0.58, 0.75, 0.81Look mom no fbcon
Quoted 48 lines
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 + MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +- 14 files changed, 1466 insertions(+), 60 deletions(-)create mode 100644
drivers/gpu/drm/drm_aperture.ccreate mode 100644drivers/gpu/drm/tiny/simpledrm.ccreate mode 100644include/drm/drm_aperture.hSignature · 1 line
2.30.1_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi,
Quoted 110 lines · Thomas Zimmermann
Hi
Am 29.03.21 um 16:50 schrieb Hans de Goede:
Quoted 107 lines
Hi,
Quoted 90 lines · Thomas Zimmermann
Hi
Am 25.03.21 um 12:29 schrieb Hans de Goede:
Quoted 87 lines
Hi,
Quoted 28 lines · Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Quoted 6 lines
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
Thank you for your work on this, this is very interesting.
Quoted 14 lines
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
Quoted 7 lines
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
I'm not sure what you mean with this ? Currently deferred-takeover is handled in the fbcon code. Current flickerfree boot works like this (assuming a single LCD panel in a laptop):
1. EFI/GOP sets up the framebuffer, draws a vendor logo
2. The bootloader runs in silent mode and does not touch anything gfx related
3. kernel boots, with a loglevel of 3 so only CRIT/EMERG messages are shown
2. efifb loads; and tells fbcon that a framebuffer is now available for it to "bind" to. SinceCONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=yfbcon defers taking over the console and leaves the dummy-console driver in place (unless there have already been kernel messages logged, which there shouldn't because loglevel=3)
3. i915 loads, reads out the hw state compares this to the preferred-mode for the panel which it would set, they match, nothing happens. i915 takes ownership of the scanout-buffer set up by the GOP, but leaves it in place.
i915 also removes the efifb/dev/fb0and installs its own/dev/fb0fbdev compat device, fbcon is notified of this, but is still deferred and leaves the dummy console driver in place as console driver.
4. Plymouth loads, allocates a new scan-out buffer at the panel's preferred resolution, plymouth reads the vendor-logo through the BGRT ACPI interface and fills the scanout-buffer with the vendor-logo + a spinner. Then plymouth installs the new scanout-buffer on the crtc, this is done atomically during vsync, so the user sees no changes, other then the spinner appearing
(note the active VT is now in graphical mode)
5. From here on not flickering is a userspace problemQuoted 6 lines
Quoted 2 lines
AFAICT this should work fine with simplekms too, unless it clears the screen to black when it binds.
I forgot to add the code that clears the screen, but that's the case here.
Instead of a plane-disable operation, simpledrm can at best clear the screen. This would happen during the initial mode-config reset IIRC.
Hmm, clearing the screen without any (atomic) modesets being initiated by either an in kernel drm-client or userspace seems wrong, this is certainly different from what the i915 driver does. The way I see it either a drm client provides a new framebuffer in which case you copy that over the old contents, effectively clearing it. Or a drm-client gets a handle and draws to the current fb directly, in which case it is the clients responsibility to clear it itself first.
Quoted 3 lines
Quoted 1 line
IOW I believe that simpledrm should not clear the screen itself at all.
I do as well. And when I boot with simpledrm + native driver it's flicker-free from what I can tell. But
drm_mode_config_reset()is supposed to reset HW and software state. There could be some corner case where we'd have to clear the screen. For now, it should be fine.
Sounds good, thanks.
Quoted 1 line
BTW if you have the time I'd appreciate your review of the patchset.
Sorry, but I'm burried under a whole pile of other work. So although I would like to help it is better to say no.
Regards,
Hans
Quoted 102 lines
Quoted 102 lines
Quoted 101 lines
But we need to keep the display content stored in a framebuffer, so read-out helpers are required. There are more users of these read-out helpers. Adding them at some point probably makes sense.
Other drivers might also want to read the initial config from simpledrm via read-out helpers. I think only i915 currently supports something like that ATM.
Best regards
ThomasQuoted 93 lines
An addition to the above sequence, if at any time either the kernel or userspace prints a message to the console; and at that time a fbdev is registered then fbcon will takeover as the console driver from the dummy driver and it will start drawing to the registered fbdev (1), destroying the framebuffer contents. Also if any messages where printend while no fbdev was registered, then fbcon will takeover the console as soon as a fbdev gets registered.
So since we already have deferred-takeover in the fbcon code, I wonder what you mean when you are talking about "provide deferred takeover" for simplekms?
Regards,
Hans
1) Except when the VT has been switched to GFX mode when this happens, then fbcon will delay using the fbdev until the VT is switched back to text mode.
p.s.
This has the interesting side effect then when logging into a desktop GUI session:
kernel -> plymouth -> gdm -> GNOME user sessionThere never is any output to the text-console and fbcon never takes-over, so on many Laptops running say Fedora workstation the fbcon code is actually unused until the user manually switches to another virtual-console to log in in text-mode:
[hans@x1 ~]$ dmesg | grep -E 'fbcon|Console:|Truecolor' [ 0.258904] Console: colour dummy device 80x25
[ 1.274726] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0 [ 1.274768] fbcon: Deferring console take-over
[ 2.540894] fbcon: i915drmfb (fb0) is primary device [ 2.540896] fbcon: Deferring console take-over [hans@x1 ~]$ uptime
12:29:39 up 4:19, 1 user, load average: 0.58, 0.75, 0.81Look mom no fbcon
Quoted 48 lines
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 +
MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++-drivers/gpu/drm/mgag200/mgag200_mode.c| 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +-14 files changed, 1466 insertions(+), 60 deletions(-)create mode 100644
drivers/gpu/drm/drm_aperture.ccreate mode 100644drivers/gpu/drm/tiny/simpledrm.ccreate mode 100644include/drm/drm_aperture.h--
2.30.1
Quoted 6 lines
Quoted 5 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 113 lines · Hans de Goede
Hi,
Quoted 110 lines · Thomas Zimmermann
Hi
Am 29.03.21 um 16:50 schrieb Hans de Goede:
Quoted 107 lines
Hi,
Quoted 90 lines · Thomas Zimmermann
Hi
Am 25.03.21 um 12:29 schrieb Hans de Goede:
Quoted 87 lines
Hi,
Quoted 28 lines · Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Quoted 6 lines
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
Thank you for your work on this, this is very interesting.
Quoted 14 lines
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
Quoted 7 lines
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
I'm not sure what you mean with this ? Currently deferred-takeover is handled in the fbcon code. Current flickerfree boot works like this (assuming a single LCD panel in a laptop):
1. EFI/GOP sets up the framebuffer, draws a vendor logo
2. The bootloader runs in silent mode and does not touch anything gfx related
3. kernel boots, with a loglevel of 3 so only CRIT/EMERG messages are shown
2. efifb loads; and tells fbcon that a framebuffer is now available for it to "bind" to. SinceCONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=yfbcon defers taking over the console and leaves the dummy-console driver in place (unless there have already been kernel messages logged, which there shouldn't because loglevel=3)
3. i915 loads, reads out the hw state compares this to the preferred-mode for the panel which it would set, they match, nothing happens. i915 takes ownership of the scanout-buffer set up by the GOP, but leaves it in place.
i915 also removes the efifb/dev/fb0and installs its own/dev/fb0fbdev compat device, fbcon is notified of this, but is still deferred and leaves the dummy console driver in place as console driver.
4. Plymouth loads, allocates a new scan-out buffer at the panel's preferred resolution, plymouth reads the vendor-logo through the BGRT ACPI interface and fills the scanout-buffer with the vendor-logo + a spinner. Then plymouth installs the new scanout-buffer on the crtc, this is done atomically during vsync, so the user sees no changes, other then the spinner appearing
(note the active VT is now in graphical mode)
5. From here on not flickering is a userspace problemQuoted 6 lines
Quoted 2 lines
AFAICT this should work fine with simplekms too, unless it clears the screen to black when it binds.
I forgot to add the code that clears the screen, but that's the case here.
Instead of a plane-disable operation, simpledrm can at best clear the screen. This would happen during the initial mode-config reset IIRC.
Hmm, clearing the screen without any (atomic) modesets being initiated by either an in kernel drm-client or userspace seems wrong, this is certainly different from what the i915 driver does. The way I see it either a drm client provides a new framebuffer in which case you copy that over the old contents, effectively clearing it. Or a drm-client gets a handle and draws to the current fb directly, in which case it is the clients responsibility to clear it itself first.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
IOW I believe that simpledrm should not clear the screen itself at all.
I do as well. And when I boot with simpledrm + native driver it's flicker-free from what I can tell. But
drm_mode_config_reset()is supposed to reset HW and software state. There could be some corner case where we'd have to clear the screen. For now, it should be fine.Sounds good, thanks.
To clarify: Atomic assumes that the sw state always matches hw state, even at boot-up. Most drivers use drm_mode_config_reset to achieve that, which forces everything to off. But that breaks flicker-free boot.
To avoid that i915 (and it's the only driver doing so) has fairly elaborate state-readout code, to make sure we do faithfully preserve the full boot-up display state. This is anything but trivial to implement.
For simpledrm it's a bit simple, since state recover boils down to reading out the fb and putting it into the new one, since there's not even provisions (afaiui) for simpledrm to enable/disable the output physically.
So i915 is the exception here allowing flicker-free boot, not the rule. -Daniel
Quoted 121 lines
Quoted 1 line
BTW if you have the time I'd appreciate your review of the patchset.
Sorry, but I'm burried under a whole pile of other work. So although I would like to help it is better to say no.
Regards,
Hans
Quoted 108 lines
Quoted 107 lines
Quoted 101 lines
But we need to keep the display content stored in a framebuffer, so read-out helpers are required. There are more users of these read-out helpers. Adding them at some point probably makes sense.
Other drivers might also want to read the initial config from simpledrm via read-out helpers. I think only i915 currently supports something like that ATM.
Best regards
ThomasQuoted 93 lines
An addition to the above sequence, if at any time either the kernel or userspace prints a message to the console; and at that time a fbdev is registered then fbcon will takeover as the console driver from the dummy driver and it will start drawing to the registered fbdev (1), destroying the framebuffer contents. Also if any messages where printend while no fbdev was registered, then fbcon will takeover the console as soon as a fbdev gets registered.
So since we already have deferred-takeover in the fbcon code, I wonder what you mean when you are talking about "provide deferred takeover" for simplekms?
Regards,
Hans
1) Except when the VT has been switched to GFX mode when this happens, then fbcon will delay using the fbdev until the VT is switched back to text mode.
p.s.
This has the interesting side effect then when logging into a desktop GUI session:
kernel -> plymouth -> gdm -> GNOME user sessionThere never is any output to the text-console and fbcon never takes-over, so on many Laptops running say Fedora workstation the fbcon code is actually unused until the user manually switches to another virtual-console to log in in text-mode:
[hans@x1 ~]$ dmesg | grep -E 'fbcon|Console:|Truecolor' [ 0.258904] Console: colour dummy device 80x25
[ 1.274726] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0 [ 1.274768] fbcon: Deferring console take-over
[ 2.540894] fbcon: i915drmfb (fb0) is primary device [ 2.540896] fbcon: Deferring console take-over [hans@x1 ~]$ uptime
12:29:39 up 4:19, 1 user, load average: 0.58, 0.75, 0.81Look mom no fbcon
Quoted 48 lines
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 +
MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++-drivers/gpu/drm/mgag200/mgag200_mode.c| 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +-14 files changed, 1466 insertions(+), 60 deletions(-)create mode 100644
drivers/gpu/drm/drm_aperture.ccreate mode 100644drivers/gpu/drm/tiny/simpledrm.ccreate mode 100644include/drm/drm_aperture.h--
2.30.1_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 101 lines · EDT Thomas Zimmermann
This patchset adds support for simple-framebuffer platform devices and a handover mechanism for native drivers to take-over control of the hardware.
The new driver, called simpledrm, binds to a simple-frambuffer platform device. The kernel's boot code creates such devices for firmware-provided framebuffers, such as EFI-GOP or VESA. Typically the BIOS, UEFI or boot loader sets up the framebuffers. Description via device tree is also an option.
Simpledrm is small enough to be linked into the kernel. The driver's main purpose is to provide graphical output during the early phases of the boot process, before the native DRM drivers are available. Native drivers are typically loaded from an initrd ram disk. Occationally simpledrm can also serve as interim solution on graphics hardware without native DRM driver.
So far distributions rely on fbdev drivers, such as efifb, vesafb or simplefb, for early-boot graphical output. However fbdev is deprecated and the drivers do not provide DRM interfaces for modern userspace.
Patches 1 and 2 prepare the DRM format helpers for simpledrm.
Patches 3 and 4 add a hand-over mechanism. Simpledrm acquires it's framebuffer's I/O-memory range and provides a callback function to be removed by a native driver. The native driver will remove simpledrm before taking over the hardware. The removal is integrated into existing helpers, so drivers use it automatically.
Patches 5 to 10 add the simpledrm driver. It's build on simple DRM helpers and SHMEM. It supports 16-bit, 24-bit and 32-bit RGB framebuffers. During pageflips, SHMEM buffers are copied into the framebuffer memory, similar to cirrus or mgag200. The code in patches 8 and 9 handles clocks and regulators. It's based on the simplefb drivers, but has been modified for DRM.
I've also been working on fastboot support (i.e., flicker-free booting). This requires state-readout from simpledrm via generic interfaces, as outlined in [1]. I do have some prototype code, but it will take a while to get this ready. Simpledrm will then support it.
I've tested simpledrm with x86 EFI and VESA framebuffers, which both work reliably. The fbdev console and Weston work automatically. Xorg requires manual configuration of the device. Xorgs current modesetting driver does not work with both, platform and PCI device, for the same physical hardware. Once configured, X11 works. I looked into X11, but couldn't see an easy way of fixing the problem. With the push towards Wayland+Xwayland I expect the problem to become a non-issue soon. Additional testing has been reported at [2].
One cosmetical issue is that simpledrm's device file is card0 and the native driver's device file is card1. After simpledrm has been kicked out, only card1 is left. This does not seem to be a practical problem however.
TODO/IDEAS:
* provide deferred takeover
* provide bootsplash DRM client
* make simplekms usable with ARM-EFI fbsv2:
* rename to simpledrm, aperture helpers
* reorganized patches
* use hotplug helpers for removal (Daniel)
* added DT match tables (Rob)
* use shadow-plane helpers
* lots of minor cleanups[1] https://lore.kernel.org/dri-devel/CAKMK7uHtqHy_oz4W7F+hmp9iqp7W5Ra8CxPvJ=9BwmvfU-O0gg@mail.gmail.com/
[2] https://lore.kernel.org/dri-devel/1761762.3HQLrFs1K7@nerdopolis/Thomas Zimmermann (10):
drm/format-helper: Pass destination pitch todrm_fb_memcpy_dstclip()drm/format-helper: Add blitter functions
drm/aperture: Move fbdev conflict helpers intodrm_aperture.hdrm/aperture: Add infrastructure for aperture ownership
drm: Add simpledrm driver
drm/simpledrm: Add fbdev emulation
drm/simpledrm: Initialize framebuffer data from device-tree node drm/simpledrm: Acquire clocks from DT device node drm/simpledrm: Acquire regulators from DT device node drm/simpledrm: Acquire memory aperture for framebufferDocumentation/gpu/drm-internals.rst | 12 + MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_aperture.c | 287 ++++++++ drivers/gpu/drm/drm_format_helper.c | 96 ++- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 +- drivers/gpu/drm/tiny/Kconfig | 17 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/cirrus.c | 2 +- drivers/gpu/drm/tiny/simpledrm.c | 932 +++++++++++++++++++++++++ include/drm/drm_aperture.h | 96 +++ include/drm/drm_fb_helper.h | 56 +- include/drm/drm_format_helper.h | 10 +- 14 files changed, 1466 insertions(+), 60 deletions(-) create mode 100644 drivers/gpu/drm/drm_aperture.c create mode 100644 drivers/gpu/drm/tiny/simpledrm.c create mode 100644 include/drm/drm_aperture.h
Quoted 8 lines
--
2.30.1_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi
Testing the new version against drm-next and it works! I found I had to turn off building CONFIG_FB_SIMPLE as it was taking over as the VGA device before simpledrm (or something. But it works, and as with the older version, testing with the 'vmware' device that QEMU supports as a graphics device now has mode setting support which is pretty cool
Thanks
Thanks
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel