Add support for QEMU's ramfb display
Subsystems (4)
cover Add support for QEMU's ramfb display
QEMU implements multiple ways to expose graphics output to the virt machine, but most of them are incompatible with hardware virtualization.
The one that does work reliably is ramfb. It's a very simple mechanism in which the guest reserves a memory region for the frame buffer and then notifies the host about its location and properties. The host then just displays the contents of the frame buffer on screen.
This patch set adds support to drive the ramfb device in our QEMU arm targets. Theoretically, it should work as is with any of the other architectures as well though.
With this driver, we have a very simple, KVM compatible way to expose GOP via UEFI to payloads and thus enable development and testing of graphical OS functionality with QEMU's -M virt.
Alexander Graf (4):
qfw: Add WRITE definition
ramfb: Add driver for ramfb display
qfw: Spawn ramfb device if its file is present
qemu-arm*: Enable ramfb by default
arch/arm/Kconfig | 4 ++ board/emulation/qemu-arm/qemu-arm.c | 14 ++++ drivers/misc/qfw.c | 23 ++++++ drivers/video/Kconfig | 8 +++ drivers/video/MAINTAINERS | 4 ++ drivers/video/Makefile | 1 + drivers/video/ramfb.c | 104 ++++++++++++++++++++++++++++ include/configs/qemu-arm.h | 9 +++ include/qfw.h | 1 + 9 files changed, 168 insertions(+) create mode 100644 drivers/video/MAINTAINERS create mode 100644 drivers/video/ramfb.c
Signature · 1 line
2.32.0
PATCH 1/4 qfw: Add WRITE definition
The QEMU fw_cfg device supports writing entries as well. Add the constant define for it so that we can leverage write functionality later.
--- include/qfw.h | 1 + 1 file changed, 1 insertion(+)
include/qfw.h +1 -0
@@ -70,6 +70,7 @@ enum {#define FW_CFG_DMA_READ (1 << 1)#define FW_CFG_DMA_SKIP (1 << 2)#define FW_CFG_DMA_SELECT (1 << 3) +#define FW_CFG_DMA_WRITE (1 << 4)/* Bit set in FW_CFG_ID response to indicate DMA interface availability. */ #define FW_CFG_DMA_ENABLED (1 << 1)
Signature · 1 line
2.32.0
Re: [PATCH 1/4] qfw: Add WRITE definition
Quoted 8 lines · Alexander Graf
The QEMU
fw_cfgdevice supports writing entries as well. Add the constant define for it so that we can leverage write functionality later.Signed-off-by Alexander Graf <[email protected]>--- include/qfw.h | 1 + 1 file changed, 1 insertion(+)
PATCH 2/4 ramfb: Add driver for ramfb display
In reply to Alexander GrafQEMU implements multiple ways to expose graphics output to the virt machine, but most of them are incompatible with hardware virtualization.
The one that does work reliably is ramfb. It's a very simple mechanism in which the guest reserves a memory region for the frame buffer and then notifies the host about its location and properties. The host then just displays the contents of the frame buffer on screen.
This patch implements a trivial version of a ramfb driver - hard coded to a single resolution.
--- drivers/video/Kconfig | 8 +++ drivers/video/MAINTAINERS | 4 ++ drivers/video/Makefile | 1 + drivers/video/ramfb.c | 104 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 drivers/video/MAINTAINERS create mode 100644 drivers/video/ramfb.c
drivers/video/Kconfig +8 -0
@@ -871,6 +871,14 @@ config VIDEO_MCDE_SIMPLE before u-boot starts, and u-boot will simply render to the pre- allocated frame buffer surface. +config VIDEO_RAMFB + bool "QEMU ramfb display driver for in-RAM display" + depends on EFI_LOADER && DM_VIDEO && QFW + help + Enables a RAM based simple frame buffer driver which uses qfw to + notify the hypervisor about the location of a Frame Buffer allocated + in guest RAM as well as its properties. + config OSD bool "Enable OSD support" depends on DM
drivers/video/MAINTAINERS new file +4 -0
@@ -0,0 +1,4 @@ +QEMU RAMFB VIDEO DRIVER +M: Alexander Graf <[email protected]> +S: Maintained +F: drivers/video/ramfb.c
drivers/video/Makefile +1 -0
@@ -74,6 +74,7 @@ obj-$(CONFIG_VIDEO_TEGRA20) += tegra.o obj-$(CONFIG_VIDEO_VCXK) += bus_vcxk.o obj-$(CONFIG_VIDEO_VESA) += vesa.o obj-$(CONFIG_VIDEO_SEPS525) += seps525.o +obj-$(CONFIG_VIDEO_RAMFB) += ramfb.o obj-y += bridge/ obj-y += sunxi/
drivers/video/ramfb.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH 2/4] ramfb: Add driver for ramfb display
Hi Alex,
Quoted 82 lines · Alexander Graf
QEMU implements multiple ways to expose graphics output to the virt machine, but most of them are incompatible with hardware virtualization.
The one that does work reliably is ramfb. It's a very simple mechanism in which the guest reserves a memory region for the frame buffer and then notifies the host about its location and properties. The host then just displays the contents of the frame buffer on screen.
This patch implements a trivial version of a ramfb driver - hard coded to a single resolution.
Signed-off-by Alexander Graf <[email protected]>--- drivers/video/Kconfig | 8 +++ drivers/video/MAINTAINERS | 4 ++ drivers/video/Makefile | 1 + drivers/video/ramfb.c | 104 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 drivers/video/MAINTAINERS create mode 100644 drivers/video/ramfb.cdrivers/video/Kconfig +8
-0@@ -871,6 +871,14 @@ config VIDEO_MCDE_SIMPLE before u-boot starts, and u-boot will simply render to the pre- allocated frame buffer surface. +config VIDEO_RAMFB + bool "QEMU ramfb display driver for in-RAM display" + depends on EFI_LOADER && DM_VIDEO && QFW + help + Enables a RAM based simple frame buffer driver which uses qfw to + notify the hypervisor about the location of a Frame Buffer allocated + in guest RAM as well as its properties. + config OSD bool "Enable OSD support" depends on DMdrivers/video/MAINTAINERS new file +4
-0@@ -0,0 +1,4 @@ +QEMU RAMFB VIDEO DRIVER +M: Alexander Graf <[email protected]> +S: Maintained +F: drivers/video/ramfb.cdrivers/video/Makefile +1
-0@@ -74,6 +74,7 @@ obj-$(CONFIG_VIDEO_TEGRA20) += tegra.o obj-$(CONFIG_VIDEO_VCXK) += bus_vcxk.o obj-$(CONFIG_VIDEO_VESA) += vesa.o obj-$(CONFIG_VIDEO_SEPS525) += seps525.o +obj-$(CONFIG_VIDEO_RAMFB) += ramfb.o obj-y += bridge/ obj-y += sunxi/drivers/video/ramfb.c new file +13
-0@@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2022 Alexander Graf +*/ + +#include <common.h> +#include <dm.h> +#include <log.h> +#include <video.h> +#include <asm/global_data.h> +#include <efi_loader.h> +#include <qfw.h> +
drivers/video/ramfb.c line 23
Quoted 10 lines
drivers/video/ramfb.c new file +10
-0+#define fourcc_code (a, b, c, d) ((u32)(a) | ((u32)(b) << 8) | \ + ((u32)(c) << 16) | ((u32)(d) << 24)) +#define DRM_FORMAT_XRGB8888 fourcc_code('X', 'R', '2', '4') + +#define DEFAULT_WIDTH 1280 +#define DEFAULT_HEIGHT 900 +#define DEFAULT_BPIX VIDEO_BPP32 +#define DEFAULT_FORMAT VIDEO_X8R8G8B8 + +struct ramfb_cfg {
Should that be in a qemu header file somewhere? Anyway, please add comments.
Quoted 37 lines
drivers/video/ramfb.c new file +37
-0+u64 addr; +u32 fourcc; +u32 flags; +u32 width; +u32 height; +u32 stride; +} __packed; + +static int ramfb_probe (struct udevice *dev) +{ +struct video_uc_plat *plat =dev_get_uclass_plat (dev); +struct video_priv *uc_priv =dev_get_uclass_priv (dev); +u32 selector; +u64 base; +u64 size; +efi_status_t ret; +struct fw_file *file; +struct udevice *qfw; +struct dm_qfw_ops *ops; +struct qfw_dma dma = {}; +struct ramfb_cfg cfg = { + .addr =0 , + .fourcc =cpu_to_be32 (DRM_FORMAT_XRGB8888 ), + .flags =0 , + .width =cpu_to_be32 (DEFAULT_WIDTH ), + .height =cpu_to_be32 (DEFAULT_HEIGHT ), + .stride =0 , + }; + + ret =qfw_get_dev (&qfw); +if (ret) +return -EPROBE_DEFER ; + + ops =dm_qfw_get_ops (qfw); +if (!ops) +return -EPROBE_DEFER ; +
drivers/video/ramfb.c line 70
Quoted 10 lines
drivers/video/ramfb.c new file +10
-0+ file =qfw_find_file (qfw,"etc/ramfb" ); +if (!file) { +/* No ramfb available. At least we tried. */ +return -ENOENT ; + } + + size =DEFAULT_WIDTH *DEFAULT_HEIGHT *VNBYTES (DEFAULT_BPIX ); + ret =efi_allocate_pages (EFI_ALLOCATE_ANY_PAGES , +EFI_RESERVED_MEMORY_TYPE , +efi_size_in_pages (size), &base);
Please see video-uclass.c for how to to allocate the frame buffer. This has nothing to do with EFI.
Quoted 23 lines
drivers/video/ramfb.c new file +23
-0+if (ret !=EFI_SUCCESS ) +return -ENOMEM ; + +debug ("%s: base=%llx, size=%llu\n" , __func__, base, size); + + cfg.addr =cpu_to_be64 (base); + plat->base = base; + plat->size = size; + uc_priv->xsize =DEFAULT_WIDTH ; + uc_priv->ysize =DEFAULT_HEIGHT ; + uc_priv->bpix =DEFAULT_BPIX ; + uc_priv->format =DEFAULT_FORMAT ; + uc_priv->fb = (void *)base; + uc_priv->fb_size = size; + + selector =be16_to_cpu (file->cfg.select); + dma.length =cpu_to_be32 (sizeof (cfg)); + dma.address =cpu_to_be64 ((uintptr_t )&cfg); + dma.control =cpu_to_be32 (FW_CFG_DMA_WRITE |FW_CFG_DMA_SELECT | + (selector <<16 )); + +barrier (); +
drivers/video/ramfb.c line 103
Quoted 10 lines
drivers/video/ramfb.c new file +10
-0+/* Send a DMA write request which enables the screen */ + ops->read_entry_dma (qfw, &dma); + +return 0 ; +} + +U_BOOT_DRIVER (ramfb) = { + .name ="ramfb" , + .id =UCLASS_VIDEO , + .probe = ramfb_probe,
You need a bind() method too.
Quoted 4 lines
drivers/video/ramfb.c new file +1
-1+}; --2.32.0
Regards,
Simon
PATCH 3/4 qfw: Spawn ramfb device if its file is present
In reply to Alexander GrafNow that we have a ramfb device driver, let's add the necessary glueing magic to also spawn it when we find its qfw file node.
--- drivers/misc/qfw.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/misc/qfw.c +23 -0
@@ -13,6 +13,7 @@#include <malloc.h> #include <qfw.h> #include <dm.h> +#include <dm/lists.h> #include <misc.h> #include <tables_csum.h> #if defined(CONFIG_GENERATE_ACPI_TABLE ) && !defined(CONFIG_ARM )
@@ -309,6 +310,26 @@ void qfw_read_entry(struct udevice *dev, u16 entry, u32 size, void *address)qfw_read_entry_io (qdev, entry, size, address); } +static void qfw_bind_ramfb (struct udevice *dev) +{ +#ifdef CONFIG_VIDEO_RAMFB +struct fw_file *file; +int ret; + + ret =qfw_read_firmware_list (dev); +if (ret) +return ; + + file =qfw_find_file (dev,"etc/ramfb" ); +if (!file) { +/* No ramfb available. */ +return ; + } + +device_bind_driver (dev,"ramfb" ,"qfw-ramfb" ,NULL ); +#endif +} +int qfw_register (struct udevice *dev) {struct qfw_dev *qdev =dev_get_uclass_priv (dev);
@@ -325,6 +346,8 @@ int qfw_register(struct udevice *dev)if (dma_enabled &FW_CFG_DMA_ENABLED ) qdev->dma_present = true; +qfw_bind_ramfb (dev); +return 0 ; }
Signature · 1 line
2.32.0
PATCH 4/4 qemu-arm*: Enable ramfb by default
In reply to Alexander GrafNow that we have everything in place to support ramfb, let's wire it up by default in the ARM QEMU targets. That way, you can easily use a graphical console by just passing -device ramfb to the QEMU command line.
--- arch/arm/Kconfig | 4 ++++ board/emulation/qemu-arm/qemu-arm.c | 14 ++++++++++++++ include/configs/qemu-arm.h | 9 +++++++++ 3 files changed, 27 insertions(+)
arch/arm/Kconfig +4 -0
@@ -979,6 +979,10 @@ config ARCH_QEMU imply DM_RTC imply RTC_PL031 imply OF_HAS_PRIOR_STAGE + imply BOARD_EARLY_INIT_R + imply DM_VIDEO + imply VIDEO_RAMFB + imply SYS_CONSOLE_IS_IN_ENV config ARCH_RMOBILE bool "Renesas ARM SoCs"
board/emulation/qemu-arm/qemu-arm.c +14 -0
@@ -9,6 +9,7 @@#include <fdtdec.h> #include <init.h> #include <log.h> +#include <qfw.h> #include <virtio_types.h> #include <virtio.h>
@@ -63,6 +64,19 @@ static struct mm_region qemu_arm64_mem_map[] = {struct mm_region *mem_map = qemu_arm64_mem_map;#endif +int board_early_init_r (void ) +{ +struct udevice *qfw_dev; + +/* +* Make sure we enumerate the QEMU Firmware device to find ramfb +* before console init starts. +*/ +qfw_get_dev (&qfw_dev); + +return 0 ; +} +int board_init (void ) {return 0 ;
include/configs/qemu-arm.h +9 -0
@@ -58,6 +58,12 @@ BOOT_TARGET_NVME(func) \ BOOT_TARGET_DHCP(func) +#ifdef CONFIG_VIDEO_RAMFB +# define QEMU_STDOUT "serial,vidconsole" +#else +# define QEMU_STDOUT "serial" +#endif +#include <config_distro_bootcmd.h> #define CONFIG_EXTRA_ENV_SETTINGS \
@@ -68,6 +74,9 @@"pxefile_addr_r=0x40300000\0" \"kernel_addr_r=0x40400000\0" \"ramdisk_addr_r=0x44000000\0" \ +"stdin=serial\0" \ +"stdout=" QEMU_STDOUT "\0" \ +"stderr=" QEMU_STDOUT "\0" \ BOOTENV#define CONFIG_SYS_CBSIZE 512
Signature · 1 line
2.32.0
Quoted 16 lines · Alexander Graf
QEMU implements multiple ways to expose graphics output to the virt machine, but most of them are incompatible with hardware virtualization.
The one that does work reliably is ramfb. It's a very simple mechanism in which the guest reserves a memory region for the frame buffer and then notifies the host about its location and properties. The host then just displays the contents of the frame buffer on screen.
This patch set adds support to drive the ramfb device in our QEMU arm targets. Theoretically, it should work as is with any of the other architectures as well though.
With this driver, we have a very simple, KVM compatible way to expose GOP via UEFI to payloads and thus enable development and testing of graphical OS functionality with QEMU's -M virt.
Quoted 5 lines
Alexander Graf (4):
qfw: Add WRITE definition
ramfb: Add driver for ramfb display
qfw: Spawn ramfb device if its file is present
qemu-arm*: Enable ramfb by default
Please, enable the device on RISC-V too.
Best regards
Heinrich
Quoted 14 lines
arch/arm/Kconfig | 4 ++ board/emulation/qemu-arm/qemu-arm.c | 14 ++++ drivers/misc/qfw.c | 23 ++++++ drivers/video/Kconfig | 8 +++ drivers/video/MAINTAINERS | 4 ++ drivers/video/Makefile | 1 + drivers/video/ramfb.c | 104 ++++++++++++++++++++++++++++ include/configs/qemu-arm.h | 9 +++ include/qfw.h | 1 + 9 files changed, 168 insertions(+)create mode 100644
drivers/video/MAINTAINERS
create mode 100644drivers/video/ramfb.c
Quoted 17 lines · Heinrich Schuchardt
Quoted 16 lines · Alexander Graf
QEMU implements multiple ways to expose graphics output to the virt machine, but most of them are incompatible with hardware virtualization.
The one that does work reliably is ramfb. It's a very simple mechanism in which the guest reserves a memory region for the frame buffer and then notifies the host about its location and properties. The host then just displays the contents of the frame buffer on screen.
This patch set adds support to drive the ramfb device in our QEMU arm targets. Theoretically, it should work as is with any of the other architectures as well though.
With this driver, we have a very simple, KVM compatible way to expose GOP via UEFI to payloads and thus enable development and testing of graphical OS functionality with QEMU's -M virt.
Quoted 7 lines
Quoted 5 lines
Alexander Graf (4):
qfw: Add WRITE definition
ramfb: Add driver for ramfb display
qfw: Spawn ramfb device if its file is present
qemu-arm*: Enable ramfb by defaultPlease, enable the device on RISC-V too.
Sure, I added a riscv enablement patch to the existing submission. It works like a charm :).
Alex
PATCH 5/5 qemu-riscv: Enable ramfb by default
In reply to Alexander GrafNow that we have everything in place to support ramfb, let's wire it up by default in the RISC-V QEMU targets. That way, you can easily use a graphical console by just passing -device ramfb to the QEMU command line.
--- board/emulation/qemu-riscv/Kconfig | 6 ++++++ board/emulation/qemu-riscv/qemu-riscv.c | 15 +++++++++++++++ include/configs/qemu-riscv.h | 9 +++++++++ 3 files changed, 30 insertions(+)
board/emulation/qemu-riscv/Kconfig +6 -0
@@ -67,5 +67,11 @@ config BOARD_SPECIFIC_OPTIONS # dummy imply MTD_NOR_FLASH imply CFI_FLASH imply OF_HAS_PRIOR_STAGE + imply BOARD_EARLY_INIT_R + imply DM_VIDEO + imply VIDEO_RAMFB + imply SYS_CONSOLE_IS_IN_ENV + imply CMD_QFW + imply QFW_MMIO endif
board/emulation/qemu-riscv/qemu-riscv.c +15 -0
@@ -10,6 +10,7 @@#include <fdtdec.h> #include <image.h> #include <log.h> +#include <qfw.h> #include <spl.h> #include <init.h> #include <virtio_types.h>
@@ -28,6 +29,20 @@ int is_flash_available(void) }#endif +int board_early_init_r (void ) +{ +struct udevice *qfw_dev; + +/* +* Make sure we enumerate the QEMU Firmware device to find ramfb +* before console init starts. +*/ +if (IS_ENABLED (CONFIG_CMD_QFW )) +qfw_get_dev (&qfw_dev); + +return 0 ; +} +int board_init (void ) {/*
include/configs/qemu-riscv.h +9 -0
@@ -39,6 +39,12 @@ func(SCSI, scsi, 0) \ func(DHCP, dhcp, na) +#ifdef CONFIG_VIDEO_RAMFB +# define QEMU_STDOUT "serial,vidconsole" +#else +# define QEMU_STDOUT "serial" +#endif +#include <config_distro_bootcmd.h> #define BOOTENV_DEV_QEMU (devtypeu, devtypel, instance) \
@@ -58,6 +64,9 @@"scriptaddr=0x88100000\0" \"pxefile_addr_r=0x88200000\0" \"ramdisk_addr_r=0x88300000\0" \ +"stdin=serial\0" \ +"stdout=" QEMU_STDOUT "\0" \ +"stderr=" QEMU_STDOUT "\0" \ BOOTENV#endif
Signature · 1 line
2.32.0