Skip to contentSkip to conversation

Add emulation for VirtIO Frame Buffer device

PATCH In review Alexander Graf 2 participants 4 messages Nov 2, 2009 – Nov 3, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add emulation for VirtIO Frame Buffer device

Since Linux now understands how to talk to us graphics over VirtIO, let's add support for it in qemu.

The good part about graphics over VirtIO is that you don't need PCI to use it. So if there's any platform out there trying to use graphics, but not capable of MMIO, it can use this one!

---
 Makefile.target |    1 +
 hw/virtio-fb.c  |  434 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio.h     |    1 +
 3 files changed, 436 insertions(+), 0 deletions(-)
 create mode 100644 hw/virtio-fb.c
Makefile.target +1 -0
index fefd7ac..260a6a8 100644
@@ -158,6 +158,7 @@ obj-y = vl.o async.o monitor.o pci.o machine.o gdbstub.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o
+obj-y += virtio-fb.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 LIBS+=-lz
hw/virtio-fb.c new file +434 -0

434 lines not on this page · raw message

hw/virtio.h +1 -0
index 15ad910..9055f60 100644
@@ -167,6 +167,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo);
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf);
 VirtIODevice *virtio_console_init(DeviceState *dev);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
+VirtIODevice *virtio_fb_init(DeviceState *dev);
 
 void virtio_net_exit(VirtIODevice *vdev);
 
Signature · 1 line
1.6.0.2
#1 lore raw

PATCH 2/2 Add PCI virtio support for frame buffer

We now know how to use a frame buffer on VirtIO, but we still can't use it on x86. In order to leverage the power of VirtIO FB, we need to wrap it through virtio-pci.

So let's add all the shiny wrappers and add a -vga option.

---
 hw/pc.c         |    5 +++++
 hw/pci.h        |    1 +
 hw/virtio-pci.c |   29 +++++++++++++++++++++++++++++
 sysemu.h        |    3 ++-
 vl.c            |    2 ++
 5 files changed, 39 insertions(+), 1 deletions(-)
hw/pc.c +5 -0
index bf4718e..4b0d019 100644
@@ -1190,6 +1190,11 @@ static void pc_init1(ram_addr_t ram_size,
         } else {
             isa_vga_init();
         }
+    } else if (virtio_fb_enabled) {
+        if (pci_enabled)
+            pci_create_simple(pci_bus, -1, "virtio-fb-pci");
+        else
+            fprintf(stderr, "%s: virtio_fb: no PCI bus\n", __FUNCTION__);
     }
 
     rtc_state = rtc_init(2000);
hw/pci.h +1 -0
index 93f93fb..b65a6df 100644
@@ -70,6 +70,7 @@ extern target_phys_addr_t pci_mem_base;
 #define PCI_DEVICE_ID_VIRTIO_BLOCK       0x1001
 #define PCI_DEVICE_ID_VIRTIO_BALLOON     0x1002
 #define PCI_DEVICE_ID_VIRTIO_CONSOLE     0x1003
+#define PCI_DEVICE_ID_VIRTIO_FB          0x1004
 
 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
                                 uint32_t address, uint32_t data, int len);
hw/virtio-pci.c +29 -0
index 1665b59..34937de 100644
@@ -490,6 +490,25 @@ static int virtio_console_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
+static int virtio_fb_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;
+
+    if (proxy->class_code != PCI_CLASS_DISPLAY_OTHER)
+        proxy->class_code = PCI_CLASS_DISPLAY_OTHER;
+
+    vdev = virtio_fb_init(&pci_dev->qdev);
+    if (!vdev) {
+        return -1;
+    }
+    virtio_init_pci(proxy, vdev,
+                    PCI_VENDOR_ID_REDHAT_QUMRANET,
+                    PCI_DEVICE_ID_VIRTIO_FB,
+                    proxy->class_code, 0x00);
+    return 0;
+}
+
 static int virtio_net_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -574,6 +593,16 @@ static PCIDeviceInfo virtio_info[] = {
         },
         .qdev.reset = virtio_pci_reset,
     },{
+        .qdev.name = "virtio-fb-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_fb_init_pci,
+        .exit      = virtio_exit_pci,
+        .qdev.props = (Property[]) {
+            DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+            DEFINE_PROP_END_OF_LIST(),
+        },
+        .qdev.reset = virtio_pci_reset,
+    },{
         .qdev.name = "virtio-balloon-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
         .init      = virtio_balloon_init_pci,
sysemu.h +2 -1
index 96804b4..c1bc5a3 100644
@@ -104,13 +104,14 @@ extern int autostart;
 extern int bios_size;
 
 typedef enum {
-    VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB
+    VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_VIRTIO
 } VGAInterfaceType;
 
 extern int vga_interface_type;
 #define cirrus_vga_enabled (vga_interface_type == VGA_CIRRUS)
 #define std_vga_enabled (vga_interface_type == VGA_STD)
 #define xenfb_enabled (vga_interface_type == VGA_XENFB)
+#define virtio_fb_enabled (vga_interface_type == VGA_VIRTIO)
 #define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
 
 extern int graphic_width;
vl.c +2 -0
index e57f58f..f999514 100644
@@ -4297,6 +4297,8 @@ static void select_vgahw (const char *p)
         vga_interface_type = VGA_VMWARE;
     } else if (strstart(p, "xenfb", &opts)) {
         vga_interface_type = VGA_XENFB;
+    } else if (strstart(p, "virtio", &opts)) {
+        vga_interface_type = VGA_VIRTIO;
     } else if (!strstart(p, "none", &opts)) {
     invalid_vga:
         fprintf(stderr, "Unknown vga type: %s\n", p);
Signature · 1 line
1.6.0.2
#2 lore raw
In reply to Alexander Graf
Quoted 7 lines · Alexander Graf

Since Linux now understands how to talk to us graphics over VirtIO, let's add support for it in qemu.

The good part about graphics over VirtIO is that you don't need PCI to use it. So if there's any platform out there trying to use graphics, but not capable of MMIO, it can use this one!

Which platforms are these?

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#3 lore raw
Quoted 10 lines · Avi Kivity
Quoted 7 lines · Alexander Graf

Since Linux now understands how to talk to us graphics over VirtIO, let's add support for it in qemu.

The good part about graphics over VirtIO is that you don't need PCI to use it. So if there's any platform out there trying to use graphics, but not capable of MMIO, it can use this one!

Which platforms are these?

For now S390 comes to mind first ... :-). I'd use and improve the spice stuff, but that hasn't exactly been open-source friendly so far...

Alex