All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Add support for QEMU's ramfb display
@ 2022-02-27 14:40 Alexander Graf
  2022-02-27 14:40 ` [PATCH 1/4] qfw: Add WRITE definition Alexander Graf
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 14:40 UTC (permalink / raw)
  To: u-boot
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

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

-- 
2.32.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] qfw: Add WRITE definition
  2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
@ 2022-02-27 14:40 ` Alexander Graf
  2022-03-12  2:25   ` Simon Glass
  2022-02-27 14:40 ` [PATCH 2/4] ramfb: Add driver for ramfb display Alexander Graf
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 14:40 UTC (permalink / raw)
  To: u-boot
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

The QEMU fw_cfg device supports writing entries as well. Add the constant
define for it so that we can leverage write functionality later.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 include/qfw.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/qfw.h b/include/qfw.h
index 7ca132e66a..e42960cbb4 100644
--- a/include/qfw.h
+++ b/include/qfw.h
@@ -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)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] ramfb: Add driver for ramfb display
  2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
  2022-02-27 14:40 ` [PATCH 1/4] qfw: Add WRITE definition Alexander Graf
@ 2022-02-27 14:40 ` Alexander Graf
  2022-03-12  2:25   ` Simon Glass
  2022-02-27 14:40 ` [PATCH 3/4] qfw: Spawn ramfb device if its file is present Alexander Graf
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 14:40 UTC (permalink / raw)
  To: u-boot
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

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 <agraf@csgraf.de>
---
 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

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index ff8e11f648..73a9e20534 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -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
diff --git a/drivers/video/MAINTAINERS b/drivers/video/MAINTAINERS
new file mode 100644
index 0000000000..74c258a314
--- /dev/null
+++ b/drivers/video/MAINTAINERS
@@ -0,0 +1,4 @@
+QEMU RAMFB VIDEO DRIVER
+M:	Alexander Graf <agraf@csgraf.de>
+S:	Maintained
+F:	drivers/video/ramfb.c
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 4038395b12..6cfec17072 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -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/
diff --git a/drivers/video/ramfb.c b/drivers/video/ramfb.c
new file mode 100644
index 0000000000..c46bfa3baa
--- /dev/null
+++ b/drivers/video/ramfb.c
@@ -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>
+
+#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 {
+	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;
+
+	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);
+	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();
+
+	/* 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,
+};
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] qfw: Spawn ramfb device if its file is present
  2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
  2022-02-27 14:40 ` [PATCH 1/4] qfw: Add WRITE definition Alexander Graf
  2022-02-27 14:40 ` [PATCH 2/4] ramfb: Add driver for ramfb display Alexander Graf
@ 2022-02-27 14:40 ` Alexander Graf
  2022-02-27 14:40 ` [PATCH 4/4] qemu-arm*: Enable ramfb by default Alexander Graf
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 14:40 UTC (permalink / raw)
  To: u-boot
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

Now 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.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 drivers/misc/qfw.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/misc/qfw.c b/drivers/misc/qfw.c
index 7c6ed41f48..fefa0bce86 100644
--- a/drivers/misc/qfw.c
+++ b/drivers/misc/qfw.c
@@ -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;
 }
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] qemu-arm*: Enable ramfb by default
  2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
                   ` (2 preceding siblings ...)
  2022-02-27 14:40 ` [PATCH 3/4] qfw: Spawn ramfb device if its file is present Alexander Graf
@ 2022-02-27 14:40 ` Alexander Graf
  2022-02-27 15:35 ` [PATCH 0/4] Add support for QEMU's ramfb display Heinrich Schuchardt
  2022-02-27 17:03 ` [PATCH 5/5] qemu-riscv: Enable ramfb by default Alexander Graf
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 14:40 UTC (permalink / raw)
  To: u-boot
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

Now 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.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 arch/arm/Kconfig                    |  4 ++++
 board/emulation/qemu-arm/qemu-arm.c | 14 ++++++++++++++
 include/configs/qemu-arm.h          |  9 +++++++++
 3 files changed, 27 insertions(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 391a77c2b4..1f8b881c73 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -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"
diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
index 16d5a97167..c898ea8a14 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -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;
diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h
index 7ae71e0029..ac67e89a98 100644
--- a/include/configs/qemu-arm.h
+++ b/include/configs/qemu-arm.h
@@ -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
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] Add support for QEMU's ramfb display
  2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
                   ` (3 preceding siblings ...)
  2022-02-27 14:40 ` [PATCH 4/4] qemu-arm*: Enable ramfb by default Alexander Graf
@ 2022-02-27 15:35 ` Heinrich Schuchardt
  2022-02-27 17:05   ` Alexander Graf
  2022-02-27 17:03 ` [PATCH 5/5] qemu-riscv: Enable ramfb by default Alexander Graf
  5 siblings, 1 reply; 10+ messages in thread
From: Heinrich Schuchardt @ 2022-02-27 15:35 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Anatolij Gustschin, u-boot

On 2/27/22 15:40, Alexander Graf wrote:
> 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

Please, enable the device on RISC-V too.

Best regards

Heinrich

>
>   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
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/5] qemu-riscv: Enable ramfb by default
  2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
                   ` (4 preceding siblings ...)
  2022-02-27 15:35 ` [PATCH 0/4] Add support for QEMU's ramfb display Heinrich Schuchardt
@ 2022-02-27 17:03 ` Alexander Graf
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 17:03 UTC (permalink / raw)
  To: u-boot
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

Now 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.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 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(+)

diff --git a/board/emulation/qemu-riscv/Kconfig b/board/emulation/qemu-riscv/Kconfig
index 02bf84725b..1967fb3a63 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -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
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
index ae3b7a3295..31799b8c3a 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -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)
 {
 	/*
diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
index 618c3b63d4..663ba50688 100644
--- a/include/configs/qemu-riscv.h
+++ b/include/configs/qemu-riscv.h
@@ -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
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] Add support for QEMU's ramfb display
  2022-02-27 15:35 ` [PATCH 0/4] Add support for QEMU's ramfb display Heinrich Schuchardt
@ 2022-02-27 17:05   ` Alexander Graf
  0 siblings, 0 replies; 10+ messages in thread
From: Alexander Graf @ 2022-02-27 17:05 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Tuomas Tynkkynen, Simon Glass, Mark Kettenis, Bin Meng,
	Asherah Connor, Anatolij Gustschin, u-boot


On 27.02.22 16:35, Heinrich Schuchardt wrote:
> On 2/27/22 15:40, Alexander Graf wrote:
>> 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
>
> Please, enable the device on RISC-V too.


Sure, I added a riscv enablement patch to the existing submission. It 
works like a charm :).


Alex



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] qfw: Add WRITE definition
  2022-02-27 14:40 ` [PATCH 1/4] qfw: Add WRITE definition Alexander Graf
@ 2022-03-12  2:25   ` Simon Glass
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Glass @ 2022-03-12  2:25 UTC (permalink / raw)
  To: Alex Graf
  Cc: U-Boot Mailing List, Tuomas Tynkkynen, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

On Sun, 27 Feb 2022 at 07:40, Alexander Graf <agraf@csgraf.de> wrote:
>
> The QEMU fw_cfg device supports writing entries as well. Add the constant
> define for it so that we can leverage write functionality later.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> ---
>  include/qfw.h | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] ramfb: Add driver for ramfb display
  2022-02-27 14:40 ` [PATCH 2/4] ramfb: Add driver for ramfb display Alexander Graf
@ 2022-03-12  2:25   ` Simon Glass
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Glass @ 2022-03-12  2:25 UTC (permalink / raw)
  To: Alex Graf
  Cc: U-Boot Mailing List, Tuomas Tynkkynen, Mark Kettenis, Bin Meng,
	Asherah Connor, Heinrich Schuchardt, Anatolij Gustschin

Hi Alex,

On Sun, 27 Feb 2022 at 07:40, Alexander Graf <agraf@csgraf.de> wrote:
>
> 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 <agraf@csgraf.de>
> ---
>  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
>
> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
> index ff8e11f648..73a9e20534 100644
> --- a/drivers/video/Kconfig
> +++ b/drivers/video/Kconfig
> @@ -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
> diff --git a/drivers/video/MAINTAINERS b/drivers/video/MAINTAINERS
> new file mode 100644
> index 0000000000..74c258a314
> --- /dev/null
> +++ b/drivers/video/MAINTAINERS
> @@ -0,0 +1,4 @@
> +QEMU RAMFB VIDEO DRIVER
> +M:     Alexander Graf <agraf@csgraf.de>
> +S:     Maintained
> +F:     drivers/video/ramfb.c
> diff --git a/drivers/video/Makefile b/drivers/video/Makefile
> index 4038395b12..6cfec17072 100644
> --- a/drivers/video/Makefile
> +++ b/drivers/video/Makefile
> @@ -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/
> diff --git a/drivers/video/ramfb.c b/drivers/video/ramfb.c
> new file mode 100644
> index 0000000000..c46bfa3baa
> --- /dev/null
> +++ b/drivers/video/ramfb.c
> @@ -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>
> +
> +#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.

> +       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;
> +
> +       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.

> +       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();
> +
> +       /* 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.

> +};
> --
> 2.32.0
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-03-12  2:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-27 14:40 [PATCH 0/4] Add support for QEMU's ramfb display Alexander Graf
2022-02-27 14:40 ` [PATCH 1/4] qfw: Add WRITE definition Alexander Graf
2022-03-12  2:25   ` Simon Glass
2022-02-27 14:40 ` [PATCH 2/4] ramfb: Add driver for ramfb display Alexander Graf
2022-03-12  2:25   ` Simon Glass
2022-02-27 14:40 ` [PATCH 3/4] qfw: Spawn ramfb device if its file is present Alexander Graf
2022-02-27 14:40 ` [PATCH 4/4] qemu-arm*: Enable ramfb by default Alexander Graf
2022-02-27 15:35 ` [PATCH 0/4] Add support for QEMU's ramfb display Heinrich Schuchardt
2022-02-27 17:05   ` Alexander Graf
2022-02-27 17:03 ` [PATCH 5/5] qemu-riscv: Enable ramfb by default Alexander Graf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.