Skip to contentSkip to conversation

qdev: convert devices

PATCH In review Gerd Hoffmann 2 participants 5 messages Jul 21, 2009 – Jul 22, 2009

lore
Share & tools
lore
#0 lore raw

cover qdev: convert devices

Hi,

Two little patches which convert devices to qdev. The first converts all vga devices. The second converts i440fx.

The i440fx conversion isn't complete and it will probably take some time until it is because that requires all pc cpu + pic/apic bits being converted too so we can wind up the interrupts qdev-ish. Nevertheless I'd like to see it merged. Even the partial conversion is very useful IMHO as almost all pc devices are connected via i440fx. Working on qdev is *much* easier with that patch applied.

thanks,
Gerd

#1 lore raw

PATCH 1/2 qdev: convert all vga devices.

---
 hw/cirrus_vga.c |   85 ++++++++++++++++++++++++++---------------------
 hw/vga.c        |   98 ++++++++++++++++++++++++++++++++++--------------------
 hw/vmware_vga.c |   26 +++++++++++---
 3 files changed, 129 insertions(+), 80 deletions(-)
hw/cirrus_vga.c +47 -38
index 0460f97..95d822a 100644
@@ -3302,46 +3302,55 @@ static void pci_cirrus_write_config(PCIDevice *d,
     cirrus_update_memory_access(s);
 }
 
+static void pci_cirrus_vga_initfn(PCIDevice *dev)
+{
+     PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
+     CirrusVGAState *s = &d->cirrus_vga;
+     uint8_t *pci_conf = d->dev.config;
+     int device_id = CIRRUS_ID_CLGD5446;
+
+     /* setup VGA */
+     vga_common_init(&s->vga, VGA_RAM_SIZE);
+     cirrus_init_common(s, device_id, 1);
+     s->vga.pci_dev = (PCIDevice *)d;
+     s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
+                                      s->vga.screen_dump, s->vga.text_update,
+                                      &s->vga);
+
+     /* setup PCI */
+     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
+     pci_config_set_device_id(pci_conf, device_id);
+     pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
+     pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
+     pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
+
+     /* setup memory space */
+     /* memory #0 LFB */
+     /* memory #1 memory-mapped I/O */
+     /* XXX: s->vga.vram_size must be a power of two */
+     pci_register_bar((PCIDevice *)d, 0, 0x2000000,
+                      PCI_ADDRESS_SPACE_MEM_PREFETCH, cirrus_pci_lfb_map);
+     if (device_id == CIRRUS_ID_CLGD5446) {
+         pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
+                          PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
+     }
+     /* XXX: ROM BIOS */
+}
+
 void pci_cirrus_vga_init(PCIBus *bus)
 {
-    PCICirrusVGAState *d;
-    uint8_t *pci_conf;
-    CirrusVGAState *s;
-    int device_id;
-
-    device_id = CIRRUS_ID_CLGD5446;
-
-    /* setup PCI configuration registers */
-    d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
-                                                 sizeof(PCICirrusVGAState),
-                                                 -1, NULL, pci_cirrus_write_config);
-    pci_conf = d->dev.config;
-    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
-    pci_config_set_device_id(pci_conf, device_id);
-    pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
-    pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
-    pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
-
-    /* setup VGA */
-    s = &d->cirrus_vga;
-    vga_common_init(&s->vga, VGA_RAM_SIZE);
-    cirrus_init_common(s, device_id, 1);
-
-    s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
-                                     s->vga.screen_dump, s->vga.text_update,
-                                     &s->vga);
+    pci_create_simple(bus, -1, "Cirrus VGA");
+}
 
-    s->vga.pci_dev = (PCIDevice *)d;
+static PCIDeviceInfo cirrus_vga_info = {
+    .qdev.name    = "Cirrus VGA",
+    .qdev.size    = sizeof(PCICirrusVGAState),
+    .init         = pci_cirrus_vga_initfn,
+    .config_write = pci_cirrus_write_config,
+};
 
-    /* setup memory space */
-    /* memory #0 LFB */
-    /* memory #1 memory-mapped I/O */
-    /* XXX: s->vga.vram_size must be a power of two */
-    pci_register_bar((PCIDevice *)d, 0, 0x2000000,
-			   PCI_ADDRESS_SPACE_MEM_PREFETCH, cirrus_pci_lfb_map);
-    if (device_id == CIRRUS_ID_CLGD5446) {
-        pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
-                               PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
-    }
-    /* XXX: ROM BIOS */
+static void cirrus_vga_register(void)
+{
+    pci_qdev_register(&cirrus_vga_info);
 }
+device_init(cirrus_vga_register);
hw/vga.c +63 -37

115 lines not on this page · raw message

hw/vmware_vga.c +20 -6
index accdac4..5ceebf1 100644
@@ -1210,14 +1210,11 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
                     iomemtype);
 }
 
-void pci_vmsvga_init(PCIBus *bus)
+static void pci_vmsvga_initfn(PCIDevice *dev)
 {
-    struct pci_vmsvga_state_s *s;
+    struct pci_vmsvga_state_s *s =
+        DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
 
-    /* Setup PCI configuration */
-    s = (struct pci_vmsvga_state_s *)
-        pci_register_device(bus, "QEMUware SVGA",
-                sizeof(struct pci_vmsvga_state_s), -1, NULL, NULL);
     pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
     pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
     s->card.config[PCI_COMMAND]		= 0x07;		/* I/O + Memory */
@@ -1240,3 +1237,20 @@ void pci_vmsvga_init(PCIBus *bus)
 
     register_savevm("vmware_vga", 0, 0, pci_vmsvga_save, pci_vmsvga_load, s);
 }
+
+void pci_vmsvga_init(PCIBus *bus)
+{
+    pci_create_simple(bus, -1, "QEMUware SVGA");
+}
+
+static PCIDeviceInfo vmsvga_info = {
+    .qdev.name    = "QEMUware SVGA",
+    .qdev.size    = sizeof(struct pci_vmsvga_state_s),
+    .init         = pci_vmsvga_initfn,
+};
+
+static void vmsvga_register(void)
+{
+    pci_qdev_register(&vmsvga_info);
+}
+device_init(vmsvga_register);
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/2 qdev/pci: hook up i440fx.

In reply to Gerd Hoffmann

Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev. Tag as no-user.

---
 hw/pci_host.h |    3 ++
 hw/piix_pci.c |  108 +++++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 85 insertions(+), 26 deletions(-)
hw/pci_host.h +3 -0
index 757b0e2..48862b5 100644
@@ -28,6 +28,8 @@
 /* debug PCI */
 //#define DEBUG_PCI
 
+#include "sysbus.h"
+
 #ifdef DEBUG_PCI
 #define PCI_DPRINTF(fmt, ...) \
 do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
@@ -36,6 +38,7 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
 #endif
 
 typedef struct {
+    SysBusDevice busdev;
     uint32_t config_reg;
     PCIBus *bus;
 } PCIHostState;
hw/piix_pci.c +82 -26

170 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx.

Quoted 5 lines · Gerd Hoffmann

Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev. Tag as no-user.

I get an immediate SEGV with this patch:

#0 strlen () at ../sysdeps/x86_64/strlen.S:48
#1 0x00000000004698cb in qemu_strdup (str=0x0)
at /home/anthony/git/qemu/qemu-malloc.c:76
#2 0x00000000004aeb9c in qbus_create (info=0x8132e0, parent=0x1fb8010,
name=0x0) at /home/anthony/git/qemu/hw/qdev.c:239
#3 0x0000000000415a62 in pci_register_bus (parent=<value optimized out>,
name=<value optimized out>, set_irq=0x463300 <piix3_set_irq>,
map_irq=0,
pic=0xfefefefefefefeff, devfn_min=2097152, nirq=4)
at /home/anthony/git/qemu/hw/pci.c:134
#4 0x00000000004632b9 in i440fx_init (pi440fx_state=0xb9ab08, pic=0x1f4f5c0)
at /home/anthony/git/qemu/hw/piix_pci.c:210
#5 0x0000000000447898 in pc_init1 (ram_size=<value optimized out>,
boot_device=0x7fffaddd1670 "cad", kernel_filename=0x571e4c "ne2k_pci", kernel_cmdline=0x5b06eb "", initrd_filename=0x0, cpu_model=<value optimized out>, pci_enabled=1, compat_level=0) at /home/anthony/git/qemu/hw/pc.c:1277
#6 0x0000000000447c58 in pc_init_pci (ram_size=0, boot_device=0x0,
kernel_filename=0x0, kernel_cmdline=0x0, initrd_filename=0xfefefefefefefeff <Address 0xfefefefefefefeff out
of bounds>, cpu_model=0x200000 <Address 0x200000 out of bounds>)
at /home/anthony/git/qemu/hw/pc.c:1474
#7 0x000000000040d983 in main (argc=6, argv=0x7fffaddd1808,
envp=<value optimized out>) at /home/anthony/git/qemu/vl.c:5976

Regards,

Anthony Liguori

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx.

Quoted 5 lines · Anthony Liguori
Quoted 4 lines · Gerd Hoffmann

Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev. Tag as no-user.

Quoted 7 lines
Quoted 1 line

I get an immediate SEGV with this patch:

#3 0x0000000000415a62 in pci_register_bus (parent=<value optimized out>, name=<value optimized out>, set_irq=0x463300 <piix3_set_irq>, map_irq=0, pic=0xfefefefefefefeff, devfn_min=2097152, nirq=4)
at /home/anthony/git/qemu/hw/pci.c:134

Ouch. It calls pci_register_bus(name=NULL). That doesn't work without this patch: http://lists.nongnu.org/archive/html/qemu-devel/2009-07/msg01139.html

Attached a fixed versin with s/NULL/"pci.0"/.

cheers,
Gerd

Quoted 1 line

From 9e3f57932de11786f791c5b74e51d4c127b4e0f5 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Fri, 5 Jun 2009 23:38:37 +0200
Subject: [PATCH] qdev/pci: hook up i440fx.

Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev. Tag as no-user.

---
 hw/pci_host.h |    3 ++
 hw/piix_pci.c |  108 +++++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 85 insertions(+), 26 deletions(-)
hw/pci_host.h +3 -0
index 757b0e2..48862b5 100644
@@ -28,6 +28,8 @@
 /* debug PCI */
 //#define DEBUG_PCI
 
+#include "sysbus.h"
+
 #ifdef DEBUG_PCI
 #define PCI_DPRINTF(fmt, ...) \
 do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
@@ -36,6 +38,7 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
 #endif
 
 typedef struct {
+    SysBusDevice busdev;
     uint32_t config_reg;
     PCIBus *bus;
 } PCIHostState;
hw/piix_pci.c +82 -26

170 lines not on this page · raw message

Signature · 1 line
1.6.2.5