Skip to contentSkip to conversation

ramfb: simple boot framebuffer, no legacy vga

PATCH Superseded Gerd Hoffmann 2 participants 6 messages Nov 17, 2017

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover ramfb: simple boot framebuffer, no legacy vga

Hi,

Ok folks, here is a experimental patch series for a legacy free boot framebuffer. If you want play with it I recommend getting the bits from

https://www.kraxel.org/cgit/qemu/log/?h=sirius/ramfb

because they come with an updated seabios and a new vgabios rom.

The boot framebuffer is expected to be configured by the firmware, so it uses fw_cfg as interface. Initialization goes as follows:

(1) Check whenever etc/ramfb is present.
(2) Allocate framebuffer from RAM.
(3) Fill struct RAMFBCfg, write it to etc/ramfb.

Done. You can write stuff to the framebuffer now, and it should appear automagically on the screen.

Note that this isn't very efficient because it does a full display update on each refresh. No dirty tracking. Dirty tracking would have to be active for the whole ram slot, so that wouldn't be very efficient either. So it is *really* intended to be only active for a short time at boot, before the guest loaded the drivers for the real display hardware.

seavgabios is able to emulate vga text mode on top of a framebuffer, for coreboot native graphics initialialization. Which works fine for everything which writes text using the vgabios interface (basically everyhing which works with sgabios).

So I hacked that up to work with ramfb. Right now it's proof-of-concept code with too much cut+paste, so it will clearly need a bunch of cleanups if this approach turns out to be workable. Look here:
https://www.kraxe.org/cgit/seabios/log/?h=ramfb

So, how to play?

There is ramfb-testdev. Standalone device, for testing purposes. Also listens on vga ports and logs any access, so we can see the bad boys ;) Use "qemu -vga none -device ramfb-testdev".

There is virtio-ramfb. Simlar to virtio-vga, but using ramfb instead of adding vga compatibility. Shows how you can wire up ramfb support to some display device. Unlike virtio-vga it should work fine on arm. Use "qemu -vga none -device virtio-ramfb" for this one.

What works?

Boot loaders all use vgabios calls for text mode, so they show up just fine. Also ipxe, seabios itself of course. So you can boot up your linux guest. vesafb works too.

What doesn't work?

vgacon (direct vga hardware access).

Windows (bios mode). Boot logo shows up just fine. But at some point windows does lots of vga register accesses (even though it sets the video mode via vesa bios interface) and appears to be unhappy that things don't work as expected because there is no actual vga hardware.

Future plans:

Try use that as vgpu boot display. Requires solving that windows issue somehow, otherwise it's going to be a non-starter.

Trick László into writing a UEFI driver for that. Linux will use efifb not vgacon then, and hopefully Windows doesn't try access vga registers either.

Comments?
Hints on the windows issue anyone?

enjoy,
Gerd

Gerd Hoffmann (4):
[testing] update bios, add vgabios-ramfb
ramfb: simple boot framebuffer living in guest ram add virtio-ramfb
add ramfb-testdev

 include/hw/display/ramfb.h |   8 +++
 hw/display/ramfb-testdev.c |  87 ++++++++++++++++++++++++++
 hw/display/ramfb.c         |  94 ++++++++++++++++++++++++++++
 hw/display/virtio-ramfb.c  | 149 +++++++++++++++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs   |   5 +-
 pc-bios/bios-256k.bin      | Bin 262144 -> 262144 bytes
 pc-bios/vgabios-ramfb.bin  | Bin 0 -> 28160 bytes
 7 files changed, 342 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/display/ramfb.h
 create mode 100644 hw/display/ramfb-testdev.c
 create mode 100644 hw/display/ramfb.c
 create mode 100644 hw/display/virtio-ramfb.c
 create mode 100644 pc-bios/vgabios-ramfb.bin
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/4 update bios, add vgabios-ramfb

source code: https://www.kraxe.org/cgit/seabios/log/?h=ramfb

---
 pc-bios/bios-256k.bin     | Bin 262144 -> 262144 bytes
 pc-bios/vgabios-ramfb.bin | Bin 0 -> 28160 bytes
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 pc-bios/vgabios-ramfb.bin
pc-bios/bios-256k.bin binary +0 -0
index e1d6b159277844320e3b1dfcbc74946ddef29026..ee51c3d61ce16a2f2139b704f073f06640a282f8 100644
GIT binary patch
pc-bios/vgabios-ramfb.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2f632cb21dfcca61704ab8dac18137cda43f30d4
GIT binary patch
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/4 ramfb: simple boot framebuffer living in guest ram

In reply to Gerd Hoffmann
---
 include/hw/display/ramfb.h |  8 ++++
 hw/display/ramfb.c         | 94 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs   |  2 +
 3 files changed, 104 insertions(+)
 create mode 100644 include/hw/display/ramfb.h
 create mode 100644 hw/display/ramfb.c
include/hw/display/ramfb.h new file +8 -0
new file mode 100644
index 0000000000..f3a772e99e
@@ -0,0 +1,8 @@
+#ifndef RAMFB_H
+#define RAMFB_H
+
+typedef struct RAMFBState RAMFBState;
+void ramfb_display_update(QemuConsole *con, RAMFBState *s);
+RAMFBState *ramfb_setup(Error **errp);
+
+#endif /* RAMFB_H */
hw/display/ramfb.c new file +94 -0

94 lines not on this page · raw message

hw/display/Makefile.objs +2 -0
index 551c050a6a..4e8ff48b55 100644
@@ -1,3 +1,5 @@
+common-obj-y += ramfb.o
+
 common-obj-$(CONFIG_ADS7846) += ads7846.o
 common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
 common-obj-$(CONFIG_G364FB) += g364fb.o
Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/4 add virtio-ramfb

In reply to Gerd Hoffmann
---
 hw/display/virtio-ramfb.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs  |   2 +-
 2 files changed, 150 insertions(+), 1 deletion(-)
 create mode 100644 hw/display/virtio-ramfb.c
hw/display/virtio-ramfb.c new file +149 -0
new file mode 100644
index 0000000000..7611c16d39
@@ -0,0 +1,149 @@
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/pci/pci.h"
+#include "ui/console.h"
+#include "hw/virtio/virtio-pci.h"
+#include "hw/display/ramfb.h"
+#include "qapi/error.h"
+
+/*
+ * virtio-vga: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_RAMFB "virtio-ramfb"
+#define VIRTIO_RAMFB(obj) \
+        OBJECT_CHECK(VirtIORAMFB, (obj), TYPE_VIRTIO_RAMFB)
+
+typedef struct VirtIORAMFB {
+    VirtIOPCIProxy parent_obj;
+    VirtIOGPU      vdev;
+    RAMFBState     *ramfb;
+} VirtIORAMFB;
+
+static void virtio_ramfb_invalidate_display(void *opaque)
+{
+    VirtIORAMFB *vramfb = opaque;
+
+    if (vramfb->vdev.enable) {
+        virtio_gpu_ops.invalidate(&vramfb->vdev);
+    }
+}
+
+static void virtio_ramfb_update_display(void *opaque)
+{
+    VirtIORAMFB *vramfb = opaque;
+    VirtIOGPU *g = &vramfb->vdev;
+
+    if (vramfb->vdev.enable) {
+        virtio_gpu_ops.gfx_update(&vramfb->vdev);
+    } else {
+        ramfb_display_update(g->scanout[0].con, vramfb->ramfb);
+    }
+}
+
+static int virtio_ramfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
+{
+    VirtIORAMFB *vramfb = opaque;
+
+    if (virtio_gpu_ops.ui_info) {
+        return virtio_gpu_ops.ui_info(&vramfb->vdev, idx, info);
+    }
+    return -1;
+}
+
+static void virtio_ramfb_gl_block(void *opaque, bool block)
+{
+    VirtIORAMFB *vramfb = opaque;
+
+    if (virtio_gpu_ops.gl_block) {
+        virtio_gpu_ops.gl_block(&vramfb->vdev, block);
+    }
+}
+
+static const GraphicHwOps virtio_ramfb_ops = {
+    .invalidate = virtio_ramfb_invalidate_display,
+    .gfx_update = virtio_ramfb_update_display,
+    .ui_info = virtio_ramfb_ui_info,
+    .gl_block = virtio_ramfb_gl_block,
+};
+
+static const VMStateDescription vmstate_virtio_ramfb = {
+    .name = "virtio-ramfb",
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        /* no pci stuff here, saving the virtio device will handle that */
+        /* FIXME */
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+/* RAMFB device wrapper around PCI device around virtio GPU */
+static void virtio_ramfb_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+    VirtIORAMFB *vramfb = VIRTIO_RAMFB(vpci_dev);
+    VirtIOGPU *g = &vramfb->vdev;
+    Error *err = NULL;
+    int i;
+
+    /* init virtio bits */
+    qdev_set_parent_bus(DEVICE(g), BUS(&vpci_dev->bus));
+    virtio_pci_force_virtio_1(vpci_dev);
+    object_property_set_bool(OBJECT(g), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    /* add stdramfb mmio regions */
+    vramfb->ramfb = ramfb_setup(errp);
+    graphic_console_set_hwops(g->scanout[0].con, &virtio_ramfb_ops, vramfb);
+
+    for (i = 0; i < g->conf.max_outputs; i++) {
+        object_property_set_link(OBJECT(g->scanout[i].con),
+                                 OBJECT(vpci_dev),
+                                 "device", errp);
+    }
+}
+
+static Property virtio_ramfb_properties[] = {
+    DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_ramfb_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+    PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
+    dc->props = virtio_ramfb_properties;
+    dc->vmsd = &vmstate_virtio_ramfb;
+    dc->hotpluggable = false;
+
+    k->realize = virtio_ramfb_realize;
+    pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
+}
+
+static void virtio_ramfb_inst_initfn(Object *obj)
+{
+    VirtIORAMFB *dev = VIRTIO_RAMFB(obj);
+
+    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+                                TYPE_VIRTIO_GPU);
+}
+
+static TypeInfo virtio_ramfb_info = {
+    .name          = TYPE_VIRTIO_RAMFB,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(struct VirtIORAMFB),
+    .instance_init = virtio_ramfb_inst_initfn,
+    .class_init    = virtio_ramfb_class_init,
+};
+
+static void virtio_ramfb_register_types(void)
+{
+    type_register_static(&virtio_ramfb_info);
+}
+
+type_init(virtio_ramfb_register_types)
hw/display/Makefile.objs +1 -1
index 4e8ff48b55..646012478f 100644
@@ -35,7 +35,7 @@ obj-$(CONFIG_VGA) += vga.o
 common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
 
 obj-$(CONFIG_VIRTIO) += virtio-gpu.o virtio-gpu-3d.o
-obj-$(CONFIG_VIRTIO_PCI) += virtio-gpu-pci.o
+obj-$(CONFIG_VIRTIO_PCI) += virtio-gpu-pci.o virtio-ramfb.o
 obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
 virtio-gpu.o-cflags := $(VIRGL_CFLAGS)
 virtio-gpu.o-libs += $(VIRGL_LIBS)
Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/4 add ramfb-testdev

In reply to Gerd Hoffmann
---
 hw/display/ramfb-testdev.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs   |  1 +
 2 files changed, 88 insertions(+)
 create mode 100644 hw/display/ramfb-testdev.c
hw/display/ramfb-testdev.c new file +87 -0
new file mode 100644
index 0000000000..1310ac1288
@@ -0,0 +1,87 @@
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/loader.h"
+#include "hw/isa/isa.h"
+#include "hw/display/ramfb.h"
+#include "ui/console.h"
+#include "sysemu/sysemu.h"
+
+#define TYPE_RAMFB "ramfb-testdev"
+#define RAMFB(obj) OBJECT_CHECK(ISARAMFBState, (obj), TYPE_RAMFB)
+
+typedef struct ISARAMFBState {
+    ISADevice parent_obj;
+    QemuConsole *con;
+    RAMFBState *state;
+    PortioList vga_port_list;
+} ISARAMFBState;
+
+/* log vga port activity, for trouble-shooting purposes */
+static uint32_t vga_log_read(void *opaque, uint32_t addr)
+{
+    fprintf(stderr, "%s: port 0x%x\n", __func__, addr);
+    return -1;
+}
+
+static void vga_log_write(void *opaque, uint32_t addr, uint32_t val)
+{
+    fprintf(stderr, "%s: port 0x%x, value 0x%x\n", __func__, addr, val);
+}
+
+static const MemoryRegionPortio vga_portio_list[] = {
+    { 0x04,  2, 1, .read = vga_log_read, .write = vga_log_write }, /* 3b4 */
+    { 0x0a,  1, 1, .read = vga_log_read, .write = vga_log_write }, /* 3ba */
+    { 0x10, 16, 1, .read = vga_log_read, .write = vga_log_write }, /* 3c0 */
+    { 0x24,  2, 1, .read = vga_log_read, .write = vga_log_write }, /* 3d4 */
+    { 0x2a,  1, 1, .read = vga_log_read, .write = vga_log_write }, /* 3da */
+    PORTIO_END_OF_LIST(),
+};
+
+static void display_update_wrapper(void *dev)
+{
+    ISARAMFBState *ramfb = RAMFB(dev);
+
+    if (0 /* native driver active */) {
+        /* non-test device would run native display update here */;
+    } else {
+        ramfb_display_update(ramfb->con, ramfb->state);
+    }
+}
+
+static const GraphicHwOps wrapper_ops = {
+    .gfx_update = display_update_wrapper,
+};
+
+static void ramfb_realizefn(DeviceState *dev, Error **errp)
+{
+    ISARAMFBState *ramfb = RAMFB(dev);
+
+    ramfb->con = graphic_console_init(dev, 0, &wrapper_ops, dev);
+    ramfb->state = ramfb_setup(errp);
+
+    isa_register_portio_list(ISA_DEVICE(dev), &ramfb->vga_port_list,
+                             0x3b0, vga_portio_list, NULL, "vga");
+}
+
+static void ramfb_class_initfn(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
+    dc->realize = ramfb_realizefn;
+    dc->desc = "ram framebuffer test device";
+}
+
+static const TypeInfo ramfb_info = {
+    .name          = TYPE_RAMFB,
+    .parent        = TYPE_ISA_DEVICE,
+    .instance_size = sizeof(ISARAMFBState),
+    .class_init    = ramfb_class_initfn,
+};
+
+static void ramfb_register_types(void)
+{
+    type_register_static(&ramfb_info);
+}
+
+type_init(ramfb_register_types)
hw/display/Makefile.objs +1 -0
index 646012478f..2c9a2e2ef6 100644
@@ -1,4 +1,5 @@
 common-obj-y += ramfb.o
+common-obj-$(CONFIG_VGA_ISA) += ramfb-testdev.o
 
 common-obj-$(CONFIG_ADS7846) += ads7846.o
 common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
Signature · 1 line
2.9.3
#5 lore raw
In reply to Gerd Hoffmann

CC Ard & Drew

Hi,

Quoted 7 lines · Gerd Hoffmann

Hi,

Ok folks, here is a experimental patch series for a legacy free boot framebuffer. If you want play with it I recommend getting the bits from

https://www.kraxel.org/cgit/qemu/log/?h=sirius/ramfb

Quoted 8 lines

because they come with an updated seabios and a new vgabios rom.

The boot framebuffer is expected to be configured by the firmware, so it uses fw_cfg as interface. Initialization goes as follows:

(1) Check whenever etc/ramfb is present.
(2) Allocate framebuffer from RAM.
(3) Fill struct RAMFBCfg, write it to etc/ramfb.

Please add documentation on the "fourcc" (pixel format?) and "flags" fields. Also please document the endianness of the integer fields.

Quoted 23 lines

Done. You can write stuff to the framebuffer now, and it should appear automagically on the screen.

Note that this isn't very efficient because it does a full display update on each refresh. No dirty tracking. Dirty tracking would have to be active for the whole ram slot, so that wouldn't be very efficient either. So it is *really* intended to be only active for a short time at boot, before the guest loaded the drivers for the real display hardware.

seavgabios is able to emulate vga text mode on top of a framebuffer, for coreboot native graphics initialialization. Which works fine for everything which writes text using the vgabios interface (basically everyhing which works with sgabios).

So I hacked that up to work with ramfb. Right now it's proof-of-concept code with too much cut+paste, so it will clearly need a bunch of cleanups if this approach turns out to be workable. Look here:
https://www.kraxe.org/cgit/seabios/log/?h=ramfb

So, how to play?

Quoted 8 lines

There is ramfb-testdev. Standalone device, for testing purposes. Also listens on vga ports and logs any access, so we can see the bad boys ;) Use "qemu -vga none -device ramfb-testdev".

There is virtio-ramfb. Simlar to virtio-vga, but using ramfb instead of adding vga compatibility. Shows how you can wire up ramfb support to some display device. Unlike virtio-vga it should work fine on arm. Use "qemu -vga none -device virtio-ramfb" for this one.

(Side note: <https://bugzilla.tianocore.org/show_bug.cgi?id=785>.)

We should make sure that any device model that combines ramfb with another PCI display device is not matched by the OVMF driver for that PCI display device. IOW, we should use separate PCI IDs or subsystem IDs (I don't recall the details off-hand). I'd like to avoid messing with the current device probing code in OVMF. It just wouldn't be nice if two independent drivers (e.g. VirtioGpuDxe and a supposed "RamFbDxe") bound the two interfaces at the same time.

This device will take a DXE driver or UEFI driver that does not follow the UEFI driver model because there's no "controller handle" to bind. (The thing to probe is an fw_cfg file.)

Quoted 16 lines

What works?

Boot loaders all use vgabios calls for text mode, so they show up just fine. Also ipxe, seabios itself of course. So you can boot up your linux guest. vesafb works too.

What doesn't work?

vgacon (direct vga hardware access).

Windows (bios mode). Boot logo shows up just fine. But at some point windows does lots of vga register accesses (even though it sets the video mode via vesa bios interface) and appears to be unhappy that things don't work as expected because there is no actual vga hardware.

Quoted 6 lines

Future plans:

Try use that as vgpu boot display. Requires solving that windows issue somehow, otherwise it's going to be a non-starter.

Trick László into writing a UEFI driver for that.

I cannot imagine when I'll get to this. :(

Feel free to file a BZ somewhere (TianoCore or RH Bugzilla) and/or poke me occasionally. My TODO list is full of things than are *all* more urgenterer than all the other things on the list.

I'm nearing TODO list bankruptcy (IRL too).

Quoted 6 lines

Linux will use efifb
not vgacon then, and hopefully Windows doesn't try access vga registers either.

Comments?
Hints on the windows issue anyone?

We looked into those when we worked on the Int10h VBE shim in OVMF. We decided the VGA register accesses were way too complicated and so we did the shim for BOCHS VGA and QXL only. IIRC. (I could be conflating things.)

This looks like a great job, honestly; I'm sorry I can't say more positive things about a GOP driver for it right now.

Thanks,
Laszlo

Quoted 24 lines

enjoy,
Gerd

Gerd Hoffmann (4):
[testing] update bios, add vgabios-ramfb
ramfb: simple boot framebuffer living in guest ram add virtio-ramfb
add ramfb-testdev

 include/hw/display/ramfb.h |   8 +++
 hw/display/ramfb-testdev.c |  87 ++++++++++++++++++++++++++
 hw/display/ramfb.c         |  94 ++++++++++++++++++++++++++++
 hw/display/virtio-ramfb.c  | 149 +++++++++++++++++++++++++++++++++++++++++++++
 hw/display/Makefile.objs   |   5 +-
 pc-bios/bios-256k.bin      | Bin 262144 -> 262144 bytes
 pc-bios/vgabios-ramfb.bin  | Bin 0 -> 28160 bytes
 7 files changed, 342 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/display/ramfb.h
 create mode 100644 hw/display/ramfb-testdev.c
 create mode 100644 hw/display/ramfb.c
 create mode 100644 hw/display/virtio-ramfb.c
 create mode 100644 pc-bios/vgabios-ramfb.bin