System Framebuffer Bus (sysfb)
cover System Framebuffer Bus (sysfb)
Hi
This series tries to fix the mess with global system framebuffer access in device drivers. Currently, architecture initialization sets the "screen_info" object according to the system framebuffer that was detected during boot. The device driver that can map VMEM first gets access to it. There is no way to give a specific driver access to the device and no _proper_ way to revoke access again. In fact, some drivers don't even check whether they mapped the VMEM successfully, letting multiple drivers to access the system framebuffer at the same time.
This series introduces a new bus in patch #1. Global system framebuffers are added as devices to this bus and drivers can register as bus drivers. Via sysfs we can now bind/unbind the drivers. This guarantees that only one driver has access to a single system-framebuffer at a time. But we can also easily control which driver gets loaded (and extend this logic at a central place if we want).
If a real hardware drivers gets loaded via another bus that actually provides the system-framebuffer (like pci-bus), these drivers can use a special BUS function to claim the system framebuffer and unload all other drivers from this device. This can be used by _real_ DRM drivers that want to kill all other generic framebuffer drivers.
This series adds a SYSFB_VBE (VESA/VBE) framebuffer type as example, but the bus can be used with any other system-framebuffer type. Any other architecture can add their own type like SYSFB_VBE. Patch #3 is currently a HACK to provide the VBE framebuffer on all architectures. However, the platform-device for system-framebuffers should instead be provided by architecture code.
Why a new BUS type?
We need a way to allow transition from a generic driver to a real hardware driver (like most DRM drivers or special fbdev drivers). We could implement this logic separately, but the BUS driver-core code is available, anyway. So lets use it and save a lot of .text space.
Additionally, we get some extra features like driver binding/unbinding via sysfs for free (which is really handy for debugging).
The new bus is actually implemented in <200 lines of code. I don't think we can get a smaller implementation when not using the bus-core code.
Patch #4 fixes vesafb.c to be hotplug-capable. It doesn't depend on this new bus so it would be nice if it could get applied right away. It allows vesafb to be compiled as a module.
Patch #5 makes vesafb.c register as new bus driver on the system-framebuffer bus.
Patch #6-#9 introduce DVBE. It's a DRM driver based on VBE/VESA. It also uses the new system-framebuffer bus and provides merely the same functionality as vesafb.c but with a sane user-space API and without any fbdev dependency.
What needs to be done?
All drivers that use screen_info currently don't _have_ to be converted to the new bus as the request_memory() calls protect the drivers from interfering. So this new bus works even if no other driver gets converted. However, we really _should_ convert the drivers. I will do that if a maintainer agrees to take the bus code through their tree. But I hope to avoid converting all drivers if no maintainer thinks this bus is a good idea.
The DVBE and vesafb drivers show how it is done.
I also like to see the system-framebuffer platform-devices being registered during architecture initialization. I haven't worked much there so any comments are welcome. Otherwise, I will keep the HACK to add the devices during sysfb module-init.
Regards
David
David Herrmann (9):
video: introduce system framebuffer bus
video: sysfb: new vbefb device type
video: sysfb: always provide vbefb device
video: vesafb: allow building as module
video: vesafb: use sysfb bus
drm: new sysfb DRM bus module
drm: new VESA BIOS Extension DRM driver stub
drm: dvbe: implement VBE/VESA blitting backend
drm: dvbe: add optional fbdev frontend
drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_sysfb.c | 145 +++++++++++++ drivers/gpu/drm/dvbe/Kconfig | 47 +++++ drivers/gpu/drm/dvbe/Makefile | 5 + drivers/gpu/drm/dvbe/dvbe.h | 121 +++++++++++ drivers/gpu/drm/dvbe/dvbe_drv.c | 104 +++++++++ drivers/gpu/drm/dvbe/dvbe_fbdev.c | 235 +++++++++++++++++++++ drivers/gpu/drm/dvbe/dvbe_main.c | 432 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/dvbe/dvbe_mem.c | 269 ++++++++++++++++++++++++ drivers/gpu/drm/dvbe/dvbe_vesa.c | 263 +++++++++++++++++++++++ drivers/video/Kconfig | 20 +- drivers/video/Makefile | 1 + drivers/video/sysfb.c | 315 +++++++++++++++++++++++++++ drivers/video/vesafb.c | 105 ++++----- include/drm/drmP.h | 4 + include/drm/drm_sysfb.h | 35 +++ include/linux/sysfb.h | 137 ++++++++++++ 18 files changed, 2197 insertions(+), 50 deletions(-) create mode 100644 drivers/gpu/drm/drm_sysfb.c create mode 100644 drivers/gpu/drm/dvbe/Kconfig create mode 100644 drivers/gpu/drm/dvbe/Makefile create mode 100644 drivers/gpu/drm/dvbe/dvbe.h create mode 100644 drivers/gpu/drm/dvbe/dvbe_drv.c create mode 100644 drivers/gpu/drm/dvbe/dvbe_fbdev.c create mode 100644 drivers/gpu/drm/dvbe/dvbe_main.c create mode 100644 drivers/gpu/drm/dvbe/dvbe_mem.c create mode 100644 drivers/gpu/drm/dvbe/dvbe_vesa.c create mode 100644 drivers/video/sysfb.c create mode 100644 include/drm/drm_sysfb.h create mode 100644 include/linux/sysfb.h
Signature · 1 line
1.8.1.3
PATCH 1/9 video: introduce system framebuffer bus
From: David Herrmann <[email protected]>
For a long time now we have the problem that there are multiple drivers available that try to use system framebuffers (like EFI, VESA/VBE, ...). There is no way to control which driver gets access to the devices, but instead works on a first-come-first-serve basis.
Furthermore, hardware drivers (eg., gpu/drm/*) that get loaded on the real hardware bus (eg., pci-bus) of the framebuffer devices have a hard time unloading other drivers that currently use system framebuffers.
This introduces a new bus-type: sysfb (system framebuffer bus)
Any available system framebuffer gets registered as a device on this bus. A bus-driver can then pick up the device and use it. Standard sysfs bind/unbind interfaces can be used to change drivers on-the-fly.
There are actually two types of drivers: generic and real drivers
Generic drivers use the generic framebuffer interface exclusively. They are often used as a fallback interface where no real driver for the hardware is available. Generic drivers register as sysfb drivers to the sysfb bus and will get loaded dynamically. User-space can bind/unbind them via sysfs to control which driver should get access.
Only one driver can be active per device. During probe the driver can retrieve additional information via a screen_info object of the device. Generic drivers include: efifb, (u)vesafb, vgacon, ...
Real drivers work differently. Instead of being loaded via sysfb, they register as drivers on the real bus (eg., pci-bus). During probe they should verify whether their real device provides a system-framebuffer. If it does, they call sysfb_claim() to claim exclusive access to the device. This guarantees that any generic driver gets unloaded and the real hardware driver can gain access. This also guarantees that a real hardware driver always takes precedence over generic fallback drivers. Real drivers include: i915, radeon, nouveau, ...
--- drivers/video/Kconfig | 17 ++++ drivers/video/Makefile | 1 + drivers/video/sysfb.c | 230 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfb.h | 134 ++++++++++++++++++++++++++++ 4 files changed, 382 insertions(+) create mode 100644 drivers/video/sysfb.c create mode 100644 include/linux/sysfb.h
drivers/video/Kconfig +17 -0
@@ -27,6 +27,23 @@ config VGASTATE tristate default n +config SYSFB + tristate "System Framebuffer Bus" + help + Framebuffers like VGA, VESA/VBE, EFI and others can be handled by many + different drivers. This bus provides an infrastructure for drivers to + register themselves and then get bound/unbound to these system-wide + framebuffers. + This bus prevents framebuffers from being used by multiple drivers + simultaneously and also provides a sysfs API to bind/rebind different + drivers to each device from userspace. + + Chipset-specific drivers (like real GPU drivers) will always take + precedence over generic framebuffer drivers. + + A driver should normally select this bus-option automatically. Enable + it only if you need out-of-tree builds. + config VIDEO_OUTPUT_CONTROL tristate "Lowlevel video output switch controls" help
drivers/video/Makefile +1 -0
@@ -5,6 +5,7 @@ # Each configuration option enables a list of files. obj-$(CONFIG_VGASTATE) += vgastate.o +obj-$(CONFIG_SYSFB) += sysfb.o obj-y += fb_notify.o obj-$(CONFIG_FB) += fb.o fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \
drivers/video/sysfb.c new file +230 -0
230 lines not on this page · raw message
include/linux/sysfb.h new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH 2/9 video: sysfb: new vbefb device type
In reply to David HerrmannFrom: David Herrmann <[email protected]>
This adds the VESA BIOS Extension (VBE) device type. Platform code needs to provide the "vbefb" platform-device with a screen_info structure as platform code.
All drivers that depend on VBE can now register as bus drivers and bind to SYSFB_VBE devices. There is no distinction between graphics framebuffers or plain text VGA. Drivers ought to inspect the screen_info and return -ENODEV during probe() is they cannot make use of the device.
Only one framebuffer of type SYSFB_VBE is available on a system at a time.
--- drivers/video/sysfb.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfb.h | 5 +++- 2 files changed, 81 insertions(+), 1 deletion(-)
drivers/video/sysfb.c +77 -0
@@ -205,6 +205,72 @@ void sysfb_taint(struct sysfb_device *sdev, bool set) }EXPORT_SYMBOL (sysfb_taint); +static void sysfb_dev_release (struct device *dev) +{ +struct sysfb_device *sdev =to_sysfb_device (dev); + +kfree (sdev); +} + +static struct sysfb_device *sysfb_dev_new (struct device *parent) +{ +struct sysfb_device *sdev; + + sdev =kzalloc (sizeof (*sdev),GFP_KERNEL ); +if (!sdev) +return NULL ; + +device_initialize (&sdev->dev); + sdev->dev.release = sysfb_dev_release; + sdev->dev.bus = &sysfb_bus_type; + sdev->dev.parent = parent; + +return sdev; +} + +static int sysfb_vbe_probe (struct platform_device *pdev) +{ +int ret; +struct sysfb_device *sdev; + + sdev =sysfb_dev_new (&pdev->dev); +if (!sdev) +return -ENOMEM ; + +dev_set_name (&sdev->dev,"vbefb" ); + sdev->type =SYSFB_VBE ; + sdev->screen = pdev->dev.platform_data; + + ret =device_add (&sdev->dev); +if (ret) + goto err_free; + +platform_set_drvdata (pdev, sdev); +return 0 ; + +err_free: +put_device (&sdev->dev); +return ret; +} + +static int sysfb_vbe_remove (struct platform_device *pdev) +{ +struct sysfb_device *sdev =platform_get_drvdata (pdev); + +device_del (&sdev->dev); +put_device (&sdev->dev); +return 0 ; +} + +static struct platform_driver sysfb_vbe_driver = { + .driver = { + .name ="vbefb" , + .owner =THIS_MODULE , + }, + .probe = sysfb_vbe_probe, + .remove = sysfb_vbe_remove, +}; +static int __init sysfb_init (void ) {int ret;
@@ -215,11 +281,22 @@ static int __init sysfb_init(void)return ret; } + ret =platform_driver_register (&sysfb_vbe_driver); +if (ret) { +pr_err ("cannot register VBE framebuffer driver\n" ); + goto err_bus; + } +return 0 ; + +err_bus: +bus_unregister (&sysfb_bus_type); +return ret; } static void __exit sysfb_exit(void) { +platform_driver_unregister (&sysfb_vbe_driver);bus_unregister (&sysfb_bus_type); }
include/linux/sysfb.h +4 -1
@@ -20,6 +20,7 @@/** * sysfb_type +* @SYSFB_VBE: VESA BIOS Extension compatible device (includes VGA devices) * * Different types of available framebuffer devices. Only one device of each * type can be available at a time. In most systems there even is only one
@@ -29,7 +30,9 @@* devices. */ enum sysfb_type { -SYSFB_TYPES =0 , +SYSFB_VBE =0x01 , + +SYSFB_TYPES =SYSFB_VBE , };/**
Signature · 1 line
1.8.1.3
PATCH 3/9 video: sysfb: always provide vbefb device
In reply to David HerrmannFrom: David Herrmann <[email protected]>
HACK: This should be provided by architecture setup code. But to show how it is supposed to work, we now simply add a "vbefb" device during initialization.
The better way to do this is by moving this into arch-code. So for instance the x86 boot initialization should create this platform-device after VBE/VESA screen detection. Other architectures can do the same or introduce other framebuffer types than SYSFB_VBE.
--- drivers/video/sysfb.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/video/sysfb.c +8 -0
@@ -271,6 +271,8 @@ static struct platform_driver sysfb_vbe_driver = { .remove = sysfb_vbe_remove, }; +static struct platform_device *sysfb_vbe_device; +static int __init sysfb_init (void ) {int ret;
@@ -287,6 +289,12 @@ static int __init sysfb_init(void) goto err_bus; } + sysfb_vbe_device =platform_device_register_data (NULL ,"vbefb" ,-1 , + &screen_info, +sizeof (screen_info)); +if (!sysfb_vbe_device) +pr_warn ("cannot create vbefb device\n" ); +return 0 ; err_bus:
Signature · 1 line
1.8.1.3
PATCH 4/9 video: vesafb: allow building as module
In reply to David HerrmannFrom: David Herrmann <[email protected]>
Fix the vesafb module to no longer use any static __init data. Also add a module_exit() function that destroys the platform device.
Note that fbdev hotplugging is broken and the self-reference actually prevents sane module-unloading. Anyway, this at least allows delayed module loading of vesafb and helps debugging vesafb a lot.
--- drivers/video/Kconfig | 2 +- drivers/video/vesafb.c | 100 +++++++++++++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 38 deletions(-)
drivers/video/Kconfig +1 -1
@@ -770,7 +770,7 @@ config FB_UVESA If unsure, say N. config FB_VESA - bool "VESA VGA graphics support" + tristate "VESA VGA graphics support" depends on (FB = y) && X86 select FB_CFB_FILLRECT select FB_CFB_COPYAREA
drivers/video/vesafb.c +63 -37
180 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH 5/9 video: vesafb: use sysfb bus
In reply to David HerrmannInstead of using our own platform device, we now register as sysfb driver and get notified whenever we are loaded on a system VBE device. This allows other VBE drivers to be loaded at the same time and users can bind/unbind drivers via sysfs. We also no longer need to fake a platform-device because the sysfb bus provides all devices now.
--- drivers/video/Kconfig | 1 + drivers/video/vesafb.c | 49 +++++++++++++++---------------------------------- 2 files changed, 16 insertions(+), 34 deletions(-)
drivers/video/Kconfig +1 -0
@@ -776,6 +776,7 @@ config FB_VESA select FB_CFB_COPYAREA select FB_CFB_IMAGEBLIT select FB_BOOT_VESA_SUPPORT + select SYSFB help This is the frame buffer device driver for generic VESA 2.0 compliant graphic cards. The older VESA 1.2 cards are not supported.
drivers/video/vesafb.c +15 -34
94 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH 6/9 drm: new sysfb DRM bus module
In reply to David HerrmannThis provides a new DRM bus helper for the system framebuffer bus. It is very similar in its functionality to the DRM_USB helper. It allows to write DRM drivers that register as SYSFB drivers to the system.
--- drivers/gpu/drm/Kconfig | 5 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_sysfb.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 4 ++ include/drm/drm_sysfb.h | 35 +++++++++++ 5 files changed, 190 insertions(+) create mode 100644 drivers/gpu/drm/drm_sysfb.c create mode 100644 include/drm/drm_sysfb.h
drivers/gpu/drm/Kconfig +5 -0
@@ -25,6 +25,11 @@ config DRM_USB depends on USB_SUPPORT && USB_ARCH_HAS_HCD select USB +config DRM_SYSFB + tristate + depends on DRM + select SYSFB + config DRM_KMS_HELPER tristate depends on DRM
drivers/gpu/drm/Makefile +1 -0
@@ -29,6 +29,7 @@ CFLAGS_drm_trace_points.o := -I$(src) obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_USB) += drm_usb.o +obj-$(CONFIG_DRM_SYSFB) += drm_sysfb.o obj-$(CONFIG_DRM_TTM) += ttm/ obj-$(CONFIG_DRM_TDFX) += tdfx/ obj-$(CONFIG_DRM_R128) += r128/
drivers/gpu/drm/drm_sysfb.c new file +145 -0
145 lines not on this page · raw message
include/drm/drmP.h +4 -0
@@ -71,6 +71,7 @@#endif #include <linux/workqueue.h> #include <linux/poll.h> +#include <linux/sysfb.h> #include <asm/pgalloc.h> #include <drm/drm.h> #include <drm/drm_sarea.h>
@@ -157,6 +158,7 @@ int drm_err(const char *func, const char *format, ...);#define DRIVER_BUS_PCI 0x1#define DRIVER_BUS_PLATFORM 0x2#define DRIVER_BUS_USB 0x3 +#define DRIVER_BUS_SYSFB 0x4/***********************************************************************/ /** \name Begin the DRM... */
@@ -953,6 +955,7 @@ struct drm_driver {struct pci_driver *pci;struct platform_device *platform_device;struct usb_driver *usb; +struct sysfb_driver *sysfb; } kdriver;struct drm_bus *bus;
@@ -1173,6 +1176,7 @@ struct drm_device {struct platform_device *platformdev;/**< Platform device struture */ struct usb_device *usbdev; +struct sysfb_device *sysfbdev;struct drm_sg_mem *sg;/**< Scatter gather memory */ unsigned int num_crtcs;/**< Number of CRTCs on this device */
include/drm/drm_sysfb.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef __DRM_SYSFB_H +#define __DRM_SYSFB_H +/* +* DRM Bus for sysfb drivers +* +* Copyright 2013 David Herrmann <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <drmP.h> +#include <linux/sysfb.h> + +int drm_sysfb_init (struct drm_driver *driver,struct sysfb_driver *sdrv); +void drm_sysfb_exit (struct drm_driver *driver,struct sysfb_driver *sdrv); +int drm_get_sysfb_dev (struct sysfb_device *sdev, +struct drm_driver *driver); + +#endif /* __DRM_SYSFB_H */
Signature · 1 line
1.8.1.3
PATCH 7/9 drm: new VESA BIOS Extension DRM driver stub
In reply to David HerrmannThis driver uses the VESA BIOS Extensions to control the display device. Modesetting has to be done during the boot-process by the architecture code (same way as vesafb requires it). No runtime modesetting is allowed due to RealMode/ProtectedMode restrictions.
This patch only introduces the stub DRM driver without any VESA/VBE backend that actually touches the hardware.
The driver simply provides a single crtc+encoder+connector combination that user-space can use to access the VBE framebuffer. No page-flips are supported and users must explicitly mark buffers as dirty to get them copied into the framebuffer.
All buffer objects are backed by shmem so we can later add PRIME support.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/dvbe/Kconfig | 28 +++ drivers/gpu/drm/dvbe/Makefile | 4 + drivers/gpu/drm/dvbe/dvbe.h | 73 +++++++ drivers/gpu/drm/dvbe/dvbe_drv.c | 104 ++++++++++ drivers/gpu/drm/dvbe/dvbe_main.c | 399 +++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/dvbe/dvbe_mem.c | 269 ++++++++++++++++++++++++++ 8 files changed, 880 insertions(+) create mode 100644 drivers/gpu/drm/dvbe/Kconfig create mode 100644 drivers/gpu/drm/dvbe/Makefile create mode 100644 drivers/gpu/drm/dvbe/dvbe.h create mode 100644 drivers/gpu/drm/dvbe/dvbe_drv.c create mode 100644 drivers/gpu/drm/dvbe/dvbe_main.c create mode 100644 drivers/gpu/drm/dvbe/dvbe_mem.c
drivers/gpu/drm/Kconfig +2 -0
@@ -215,3 +215,5 @@ source "drivers/gpu/drm/mgag200/Kconfig" source "drivers/gpu/drm/cirrus/Kconfig" source "drivers/gpu/drm/shmobile/Kconfig" + +source "drivers/gpu/drm/dvbe/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -49,4 +49,5 @@ obj-$(CONFIG_DRM_GMA500) += gma500/ obj-$(CONFIG_DRM_UDL) += udl/ obj-$(CONFIG_DRM_AST) += ast/ obj-$(CONFIG_DRM_SHMOBILE) +=shmobile/ +obj-$(CONFIG_DRM_DVBE) += dvbe/ obj-y += i2c/
drivers/gpu/drm/dvbe/Kconfig new file +28 -0
@@ -0,0 +1,28 @@ +config DRM_DVBE + tristate "VESA BIOS Extension DRM Driver" + depends on DRM + select DRM_KMS_HELPER + select DRM_SYSFB + help + This is a DRM/KMS driver for VESA BIOS Extension (VBE) compatible + cards. At least VBE 2.0 is needed. Older VBE 1.2 cards are not + supported. + Nearly all modern x86 graphics cards support VBE 2.0 so this driver + should work with all those graphics cards. However, it does not allow + mode-switching during runtime but requires the kernel to setup the + mode with the vga= kernel command line option. If you want full + support for your graphics card, please select a driver for your + specific model. + + This driver can be enabled together with any other DRM graphics + driver. If another driver probes a device that conflicts with DVBE, + then DVBE will automatically drop the device and let the + model-specific driver take precedence. + + This driver replaces the old vesafb framebuffer driver and provides + full backwards compatibility. + + If unsure, say Y. + + To compile this driver as a module, choose M here: the + module will be called dvbe.
drivers/gpu/drm/dvbe/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +ccflags-y := -Iinclude/drm + +dvbe-y := dvbe_drv.o dvbe_main.o dvbe_mem.o +obj-$(CONFIG_DRM_DVBE) := dvbe.o
drivers/gpu/drm/dvbe/dvbe.h new file +73 -0
73 lines not on this page · raw message
drivers/gpu/drm/dvbe/dvbe_drv.c new file +104 -0
104 lines not on this page · raw message
drivers/gpu/drm/dvbe/dvbe_main.c new file +399 -0
399 lines not on this page · raw message
drivers/gpu/drm/dvbe/dvbe_mem.c new file +269 -0
269 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH 8/9 drm: dvbe: implement VBE/VESA blitting backend
In reply to David HerrmannExtend the dvbe core driver by a VESA/VBE backend that simply blits the data from a framebuffer into the hardware framebuffer on damage. Modesetting has to be done during the boot-process by the architecture code (same way as vesafb requires it). No runtime modesetting is allowed due to RealMode/ProtectedMode restrictions.
On dirty-ioctls we simply vmap the framebuffer memory and copy each pixel into the target framebuffer. Unfortunately, the VBE bpp/depth combinations cannot easily be forwarded to the user via the DRM API as it allows a lot more combinations. Hence, we need to convert each pixel from the user's buffer format into the target format while blitting. Fast-paths for xrgb32/etc. could be implemented if we want to improve blitting performance.
--- drivers/gpu/drm/dvbe/Kconfig | 1 + drivers/gpu/drm/dvbe/Makefile | 2 +- drivers/gpu/drm/dvbe/dvbe.h | 25 ++++ drivers/gpu/drm/dvbe/dvbe_main.c | 39 +++++- drivers/gpu/drm/dvbe/dvbe_vesa.c | 263 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 325 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/dvbe/dvbe_vesa.c
drivers/gpu/drm/dvbe/Kconfig +1 -0
@@ -3,6 +3,7 @@ config DRM_DVBE depends on DRM select DRM_KMS_HELPER select DRM_SYSFB + select FB_BOOT_VESA_SUPPORT help This is a DRM/KMS driver for VESA BIOS Extension (VBE) compatible cards. At least VBE 2.0 is needed. Older VBE 1.2 cards are not
drivers/gpu/drm/dvbe/Makefile +1 -1
@@ -1,4 +1,4 @@ ccflags-y := -Iinclude/drm -dvbe-y := dvbe_drv.o dvbe_main.o dvbe_mem.o +dvbe-y := dvbe_drv.o dvbe_main.o dvbe_mem.o dvbe_vesa.o obj-$(CONFIG_DRM_DVBE) := dvbe.o
drivers/gpu/drm/dvbe/dvbe.h +25 -0
@@ -25,6 +25,23 @@struct dvbe_device {struct drm_device *ddev; +/* vbe information */ +unsigned long vbe_addr; +unsigned long vbe_vsize; +unsigned long vbe_size; +unsigned int vbe_depth; +unsigned int vbe_bpp; +unsigned int vbe_width; +unsigned int vbe_height; +unsigned int vbe_stride; +uint8_t vbe_red_size; +uint8_t vbe_red_pos; +uint8_t vbe_green_size; +uint8_t vbe_green_pos; +uint8_t vbe_blue_size; +uint8_t vbe_blue_pos; +uint8_t *vbe_map; +/* mode-setting objects */ struct drm_crtc crtc;struct drm_encoder enc;
@@ -70,4 +87,12 @@ struct dvbe_framebuffer {#define to_dvbe_fb (x) container_of(x, struct dvbe_framebuffer, base) +/* vesa helpers */ + +int dvbe_vesa_init (struct dvbe_device *dvbe); +void dvbe_vesa_cleanup (struct dvbe_device *dvbe); +int dvbe_vesa_damage (struct dvbe_device *dvbe,struct dvbe_framebuffer *fb, +unsigned int flags,unsigned int color, +struct drm_clip_rect *clips,unsigned int num); +#endif /* DVBE_DRV_H */
drivers/gpu/drm/dvbe/dvbe_main.c +35 -4
@@ -46,6 +46,15 @@ static bool dvbe_crtc_mode_fixup(struct drm_crtc *crtc,const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { + struct dvbe_device *dvbe = crtc->dev->dev_private; + +if (mode->hdisplay != dvbe->vbe_width || + mode->vdisplay != dvbe->vbe_height) { +dev_dbg (dvbe->ddev->dev,"invalid mode %ux%u\n" , + mode->hdisplay, mode->vdisplay); +return false; + } +drm_mode_copy (adjusted_mode, mode);return true; }
@@ -66,6 +75,7 @@ static int dvbe_crtc_mode_set(struct drm_crtc *crtc, int x, int y, struct drm_framebuffer *old_fb) { + struct dvbe_device *dvbe = crtc->dev->dev_private;struct dvbe_framebuffer *dfb =to_dvbe_fb (crtc->fb);/* We can scan out any framebuffer that is given. The framebuffer
@@ -79,7 +89,7 @@ static int dvbe_crtc_mode_set(struct drm_crtc *crtc,if (x >= dfb->base.width || y >= dfb->base.height)return -EINVAL ; -return 0 ; +return dvbe_vesa_damage (dvbe, dfb,0 ,0 ,NULL ,0 ); }/*
@@ -89,12 +99,13 @@ static int dvbe_crtc_mode_set(struct drm_crtc *crtc,static int dvbe_crtc_mode_set_base (struct drm_crtc *crtc,int x,int y,struct drm_framebuffer *fb) { +struct dvbe_device *dvbe = crtc->dev->dev_private;struct dvbe_framebuffer *dfb =to_dvbe_fb (crtc->fb);if (x >= dfb->base.width || y >= dfb->base.height)return -EINVAL ; -return 0 ; +return dvbe_vesa_damage (dvbe, dfb,0 ,0 ,NULL ,0 ); }static const struct drm_crtc_helper_funcs dvbe_crtc_helper_ops = {
@@ -159,7 +170,19 @@ static const struct drm_encoder_funcs dvbe_enc_ops = {static int dvbe_conn_get_modes (struct drm_connector *conn) { -return 0 ; +struct dvbe_device *dvbe = conn->dev->dev_private; +struct drm_display_mode *mode; + + mode =drm_gtf_mode (dvbe->ddev, dvbe->vbe_width, dvbe->vbe_height, +60 ,0 ,0 ); +if (!mode) +return 0 ; + + mode->type =DRM_MODE_TYPE_DRIVER |DRM_MODE_TYPE_PREFERRED ; +drm_mode_probed_add (conn, mode); + dvbe->mode = mode; + +return 1 ; } static int dvbe_conn_mode_valid(struct drm_connector *conn,
@@ -226,11 +249,12 @@ static int dvbe_fb_dirty(struct drm_framebuffer *fb, struct drm_file *file, struct drm_clip_rect *clips, unsigned int num) {struct dvbe_device *dvbe = fb->dev->dev_private; +struct dvbe_framebuffer *dfb =to_dvbe_fb (fb);if (dvbe->crtc.fb != fb)return 0 ; -return 0 ; +return dvbe_vesa_damage (dvbe, dfb, flags, color, clips, num); }static void dvbe_fb_destroy (struct drm_framebuffer *fb)
@@ -334,6 +358,10 @@ int dvbe_drm_load(struct drm_device *ddev, unsigned long flags) dvbe->ddev = ddev; ddev->dev_private = dvbe; + ret =dvbe_vesa_init (dvbe); +if (ret) + goto err_free; +drm_mode_config_init (ddev); ddev->mode_config.min_width =0 ; ddev->mode_config.min_height =0 ;
@@ -384,6 +412,8 @@ int dvbe_drm_load(struct drm_device *ddev, unsigned long flags) err_cleanup:drm_mode_config_cleanup (ddev); +dvbe_vesa_cleanup (dvbe); +err_free:kfree (dvbe);return ret; }
@@ -393,6 +423,7 @@ int dvbe_drm_unload(struct drm_device *ddev)struct dvbe_device *dvbe = ddev->dev_private;drm_mode_config_cleanup (ddev); +dvbe_vesa_cleanup (dvbe);kfree (dvbe);return 0 ;
drivers/gpu/drm/dvbe/dvbe_vesa.c new file +263 -0
263 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH 9/9 drm: dvbe: add optional fbdev frontend
In reply to David HerrmannThis adds a new fbdev frontend to the dvbe driver. It allows userspace to access the dvbe driver via an fbdev frontend.
It is disabled by default so you can use dvbe without CONFIG_FB. It should only be used for backwards-compatibility. Use the DRM dumb API to access dvbe buffers properly.
--- drivers/gpu/drm/dvbe/Kconfig | 18 +++ drivers/gpu/drm/dvbe/Makefile | 1 + drivers/gpu/drm/dvbe/dvbe.h | 23 ++++ drivers/gpu/drm/dvbe/dvbe_fbdev.c | 235 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/dvbe/dvbe_main.c | 2 + 5 files changed, 279 insertions(+) create mode 100644 drivers/gpu/drm/dvbe/dvbe_fbdev.c
drivers/gpu/drm/dvbe/Kconfig +18 -0
@@ -27,3 +27,21 @@ config DRM_DVBE To compile this driver as a module, choose M here: the module will be called dvbe. + +config DRM_DVBE_FBDEV + bool "VESA BIOS Extension DRM fbdev Compatibility Layer" + depends on DRM_DVBE && FB + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + help + This provides an fbdev frontend (via /dev/fbX) for the DVBE VESA + driver. Old userspace that depends on the fbdev API can access the + DVBE driver this way. It provides full backwards compatibility to the + old vesafb driver. + + Newer userspace accesses graphics devices via the DRM API and the old + fbdev compatibility layer is not needed. Activate it only if you + really need to run old userspace programs. + + If unsure, say N.
drivers/gpu/drm/dvbe/Makefile +1 -0
@@ -1,4 +1,5 @@ ccflags-y := -Iinclude/drm dvbe-y := dvbe_drv.o dvbe_main.o dvbe_mem.o dvbe_vesa.o +dvbe-$(CONFIG_DRM_DVBE_FBDEV) += dvbe_fbdev.o obj-$(CONFIG_DRM_DVBE) := dvbe.o
drivers/gpu/drm/dvbe/dvbe.h +23 -0
@@ -14,6 +14,7 @@#define DVBE_DRV_H #include <linux/errno.h> +#include <linux/fb.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/module.h>
@@ -47,6 +48,9 @@ struct dvbe_device {struct drm_encoder enc;struct drm_connector conn;struct drm_display_mode *mode; + +/* fbdev */ +void *fbdev; };int dvbe_drm_load (struct drm_device *ddev,unsigned long flags);
@@ -95,4 +99,23 @@ int dvbe_vesa_damage(struct dvbe_device *dvbe, struct dvbe_framebuffer *fb, unsigned int flags, unsigned int color, struct drm_clip_rect *clips, unsigned int num); +/* fbdev helpers */ + +#ifdef CONFIG_DRM_DVBE_FBDEV + +void dvbe_fbdev_init (struct dvbe_device *dvbe); +void dvbe_fbdev_cleanup (struct dvbe_device *dvbe); + +#else /* CONFIG_DRM_DVBE_FBDEV */ + +static inline void dvbe_fbdev_init (struct dvbe_device *dvbe) +{ +} + +static inline void dvbe_fbdev_cleanup (struct dvbe_device *dvbe) +{ +} + +#endif /* CONFIG_DRM_DVBE_FBDEV */ +#endif /* DVBE_DRV_H */
drivers/gpu/drm/dvbe/dvbe_fbdev.c new file +235 -0
235 lines not on this page · raw message
drivers/gpu/drm/dvbe/dvbe_main.c +2 -0
@@ -408,6 +408,7 @@ int dvbe_drm_load(struct drm_device *ddev, unsigned long flags)if (ret) goto err_cleanup; +dvbe_fbdev_init (dvbe);return 0 ; err_cleanup:
@@ -422,6 +423,7 @@ int dvbe_drm_unload(struct drm_device *ddev) {struct dvbe_device *dvbe = ddev->dev_private; +dvbe_fbdev_cleanup (dvbe);drm_mode_config_cleanup (ddev);dvbe_vesa_cleanup (dvbe);kfree (dvbe);
Signature · 1 line
1.8.1.3
Dave Airlie
maintainerQuoted 9 lines
This series tries to fix the mess with global system framebuffer access in device drivers. Currently, architecture initialization sets the "
screen_info" object according to the system framebuffer that was detected during boot. The device driver that can map VMEM first gets access to it. There is no way to give a specific driver access to the device and no _proper_ way to revoke access again. In fact, some drivers don't even check whether they mapped the VMEM successfully, letting multiple drivers to access the system framebuffer at the same time.
I'm unsure if I like this or not, and I don't see why its greatly more useful than the interface we have now.
It doesn't solve the main problem with the current interface, which is that if somebody opens has vesafb /dev/fb0, mmaps it, and modprobes a real driver, things will fail either miserably or crappy from a users pov.
The internal reference counts stop vesafb from unloading due to the mmaps, then i915 loads anyways and one bashes the other, or we fix so i915 doesn't load and the user gets fail.
Dave.
Hi Dave
Quoted 10 lines · Dave Airlie
Quoted 9 lines
This series tries to fix the mess with global system framebuffer access in device drivers. Currently, architecture initialization sets the "
screen_info" object according to the system framebuffer that was detected during boot. The device driver that can map VMEM first gets access to it. There is no way to give a specific driver access to the device and no _proper_ way to revoke access again. In fact, some drivers don't even check whether they mapped the VMEM successfully, letting multiple drivers to access the system framebuffer at the same time.
Quoted 2 lines
I'm unsure if I like this or not, and I don't see why its greatly more useful than the interface we have now.
This interface at least solves the problem with having vesafb, uvesafb, vgacon, vga16fb, efifb, dvbe, defi and all other similar drivers from accessing the system framebuffer simultaneously. And provides a sane way of registering devices and drivers for it.
It also provides a way for real drivers to unload these drivers (sysfb_claim()) instead of using remove_conflicting_framebuffers(), which is horribly broken and has lots of race-conditions. (I tried fixing the fbdev refcounting/locking, but every time I tried, some driver broke because they worked around the bug. And fixing all drivers is just a lot of work...).
And remove_conflicting_framebuffers() also doesn't work with vgacon/etc. which do _not_ use fbdev.
We could simplify this approach by removing the bus and just providing the platform-device for vbefb/etc. from the arch-code. But I thought the bus-infrastructure allows nice rebinding of drivers if we need it at almost no cost.
You could even register an oops/panic-screen as driver there and switch to it if necessary.
Quoted 8 lines
It doesn't solve the main problem with the current interface, which is that if somebody opens has vesafb
/dev/fb0, mmaps it, and modprobes a real driver, things will fail either miserably or crappy from a users pov.The internal reference counts stop vesafb from unloading due to the mmaps, then i915 loads anyways and one bashes the other, or we fix so i915 doesn't load and the user gets fail.
It's not the mmap that prevents vesafb from unloading, it's the open-file instead. If a user does open(), mmap(), close(), they can still access the mapped memory but vesafb might get unloaded (this is, in fact, used by several user-space apps). So it's not about whether vesafb is still loaded, but rather what to do about users which have vesafb mmaped but don't expect it to go away.
So what do you propose to detect this case? Keep track of every user who mmap's vesafb? How can we detect when they unmap the memory? I think the only way to detect this is to wait for the pages' "mmap-count" to drop to zero and then release the memory.
So lets compare this to other subsystems. If you unlink a file that is still mmaped, I think the file isn't removed from memory until the last user unmaps it. However, the memory-mapping is 'dead' in that it doesn't have any effect on real files.
So why not copy that behavior to framebuffers? When a real DRM driver is loaded, simply reserve the VBE framebuffer-memory in VMEM until the last user unmaps it. But mark it 'dead' so it doesn't really belong to a _real_ framebuffer.
So any access to the mmap'ed framebuffers will be a no-op as it just modifies 'dead' framebuffers.
Another idea is copying the VBE framebuffer into the DRM driver so all old memory-maps are still valid. However, this prevents us from doing any kind of mode-setting in the DRM driver until the last fbdev user is gone (because there is no way to notify fbdev users of mode-setting).
So in this case we are also stuck in a situation where we need to wait for all users to unmap their framebuffers.
Any comments? If you have a plan on how it is supposed to work (or what the user-space semantics should be), tell me and I will try to make it work.
I still think a central system-framebuffer registry like sysfb-bus (which does _not_ explicitly depend on fbdev) is the way to go. Whether it's a bus or not is just a matter of taste. I am willing to rework this.
Thanks
David
Dave Airlie
maintainerQuoted 7 lines
Quoted 2 lines
I'm unsure if I like this or not, and I don't see why its greatly more useful than the interface we have now.
This interface at least solves the problem with having vesafb, uvesafb, vgacon, vga16fb, efifb, dvbe, defi and all other similar drivers from accessing the system framebuffer simultaneously. And provides a sane way of registering devices and drivers for it.
But do we have the problem now? or is it more when we get dvbe/defi?
Also vgacon is kinda different since fbcon kicks it off, not a driver,
Quoted 8 lines
It also provides a way for real drivers to unload these drivers (
sysfb_claim()) instead of usingremove_conflicting_framebuffers(), which is horribly broken and has lots of race-conditions. (I tried fixing the fbdev refcounting/locking, but every time I tried, some driver broke because they worked around the bug. And fixing all drivers is just a lot of work...).
Andremove_conflicting_framebuffers()also doesn't work with vgacon/etc. which do _not_ use fbdev.
but vgacon is always kicked off by fbcon, so I'm not sure what etc there is apart from it. I'd like to make fbcon a bool as well, so we don't have to deal with it appearing after the drivers.
Quoted 4 lines
We could simplify this approach by removing the bus and just providing the platform-device for vbefb/etc. from the arch-code. But I thought the bus-infrastructure allows nice rebinding of drivers if we need it at almost no cost.
I suspect a platform device is the right answer, since vesafb is that,
I think we should resolve vesafb vs dvbe by just making them not config compatible, and dvbe vs defi seems like the same solution as vesafb vs efi.
I'm just trying to work out what exactly you are fixing here, the problems we have now don't seem to be addressed by this, if it addresses future problems then it needs to be more upfront.
Quoted 9 lines
Quoted 8 lines
It doesn't solve the main problem with the current interface, which is that if somebody opens has vesafb
/dev/fb0, mmaps it, and modprobes a real driver, things will fail either miserably or crappy from a users pov.The internal reference counts stop vesafb from unloading due to the mmaps, then i915 loads anyways and one bashes the other, or we fix so i915 doesn't load and the user gets fail.
Quoted 6 lines
It's not the mmap that prevents vesafb from unloading, it's the open-file instead. If a user does
open(),mmap(),close(), they can still access the mapped memory but vesafb might get unloaded (this is, in fact, used by several user-space apps). So it's not about whether vesafb is still loaded, but rather what to do about users which have vesafb mmaped but don't expect it to go away.
In theory we'd have to do like GEM/TTM, and unmap_mapping_range for all the open fd's mmaps and just point them to map something useless or even just return -EFAULT, because really userspace needs to be told something :-)
Quoted 16 lines
So what do you propose to detect this case? Keep track of every user who mmap's vesafb? How can we detect when they unmap the memory? I think the only way to detect this is to wait for the pages' "mmap-count" to drop to zero and then release the memory.
So lets compare this to other subsystems. If you unlink a file that is still mmaped, I think the file isn't removed from memory until the last user unmaps it. However, the memory-mapping is 'dead' in that it doesn't have any effect on real files.
So why not copy that behavior to framebuffers? When a real DRM driver is loaded, simply reserve the VBE framebuffer-memory in VMEM until the last user unmaps it. But mark it 'dead' so it doesn't really belong to a _real_ framebuffer.
So any access to the mmap'ed framebuffers will be a no-op as it just modifies 'dead' framebuffers.
Quoted 7 lines
Another idea is copying the VBE framebuffer into the DRM driver so all old memory-maps are still valid. However, this prevents us from doing any kind of mode-setting in the DRM driver until the last fbdev user is gone (because there is no way to notify fbdev users of mode-setting).
So in this case we are also stuck in a situation where we need to wait for all users to unmap their framebuffers.
It all kinda sucks, from the problems we've had previously with things like plymouth
racing, (which all this will make much worse if we have kms vbe devices) really what we want the system to do is give the user the proper driver asap, stalling waiting for endless other things to let go is just going to screw users, so I think
we need to be as upfront and brutal in the userspace interface if people mmaping vesafb or efifb or any generic interface then expect to load a real driver, then their old apps get killed.
Quoted 7 lines
Any comments? If you have a plan on how it is supposed to work (or what the user-space semantics should be), tell me and I will try to make it work.
I still think a central system-framebuffer registry like sysfb-bus (which does _not_ explicitly depend on fbdev) is the way to go. Whether it's a bus or not is just a matter of taste. I am willing to rework this.
As I said maybe I'm concentrating on the problem you aren't trying to fix, but then I'm not sure I've enough information on the problem you are trying to fix,
remove_confilicting_framebuffers might be ugly but it does 90% of what we want, I just want to understand why this will make it better,
Dave.
Hi Dave
Sorry, I was busy reworking the HIDP layer. I finally got time to continue my work on this again. See below:
On Mon, Feb 18, 2013 at 12:47 AM, Dave Airlie <[email protected]> wrote:
[..snap..]
Quoted 6 lines
As I said maybe I'm concentrating on the problem you aren't trying to fix, but then I'm not sure I've enough information on the problem you are trying to fix,
remove_confilicting_framebuffersmight be ugly but it does 90% of what we want, I just want to understand why this will make it better,
Ok, let me describe the problem in more detail:
We currently have different drivers that can make use of "system framebuffers" (as I call them for now):
- vgacon
- fbdev
- DRM
(- vgalog) (similar to fblog/drmlog but using vga/VBE)
Scenarios:
- Imagine you have CONFIG_FB=n but VGACON=y for debugging. Who is then responsible of kicking out VGACON when DRM drivers are loaded? (and vice versa)
- i915 is loaded and the user does a "modprobe vesafb". Who prevents vesafb from loading?
- If I use vgalog, who unloads it when fbdev/DRM drivers are loaded? (and vice versa)
Our current solution consists of "vgacon_cleanup()" and "remove_conflicting_frambuffers()". We could add similar helpers for all other scenarios, but I promise, this will get pretty complex.
Another problem: All VBE/EFI framebuffer drivers currently do something like:
platform_driver_register("my-device"...); platform_device_add("my-device"...);
Why not provide a unique platform-device-name and add the device in architecture setup code? This would prevent multiple drivers from being probed on a single platform device.
My bus-solution was the most straightforward to implement and makes testing really easy (as you can probe/remove drivers from userspace). However, I understand if we don't want to introduce any ABI.
So I was rethinking this idea and maybe we simplify the bus-solution and instead use some priority-based driver loading. That is, the architecture code creates a platform-device for all available system-framebuffers (which is probably always at most one device). Then drivers simply provide platform-drivers that can be loaded on the device. But instead of using platform_driver_register(), they use vbe_driver_register() or something similar and pass in the platform-driver _plus_ a priority. The wrapper then compares the priorities, unloads the old driver and probes the new one. This guarantees that a new driver will only replace the current driver if it has a higher priority. vgacon/vgalog->fbdev->DRM
How does that fix the problems you described?
Well, it doesn't. But it makes them more obvious as there is now a central place that manages the hand-over.
On the other hand, I don't understand why the problems you described have anything to do with the hand-over itself? They also occur on driver-unloading without any handover, don't they?
So I think we simply need to fix vesafb, efifb, ... to unmap any pending user-space mappings during unloading. This also guarantees that these mappings are dead when any other driver takes over. And with the platform-devices that I want to introduce, we guarantee that the drivers get unloaded correctly even during hand-over.
The remove_conflicting_framebuffers() call can stay for all other conflicts, although I think these _really_ should be handled by Kconfig. But ok, I don't mind this call. It doesn't break anything.
Why am I doing this?
To get dvbe/defi and vbelog working. I use these on my machine as nouveau doesn't work and fbdev is just ugly to work with. I was also told that they proved to be useful in virtualization environments. I don't mind setting dvbe as "depends on !<any-drm-driver> && !CONFIG_FB && !CONFIG_VT" but I thought fixing this directly where it is broken ought to be the better way.
So, any comments welcome.
If there are no major objections, I will try to implement it and also try to fix vesafb to unmap the mmap()s during unloading. If that turns out to work well, I can also fix the other drivers.
Thanks for the comments
David
Quoted 6 lines · David Herrmann
We currently have different drivers that can make use of "system framebuffers" (as I call them for now):
- vgacon
- fbdev
- DRM
(- vgalog) (similar to fblog/drmlog but using vga/VBE)
offb
Gr{oetje,eeting}s,
Geert
--
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