* [Qemu-devel] [PATCH 0/2] qdev: convert devices
@ 2009-07-21 12:54 Gerd Hoffmann
2009-07-21 12:54 ` [Qemu-devel] [PATCH 1/2] qdev: convert all vga devices Gerd Hoffmann
2009-07-21 12:55 ` [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx Gerd Hoffmann
0 siblings, 2 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2009-07-21 12:54 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] qdev: convert all vga devices.
2009-07-21 12:54 [Qemu-devel] [PATCH 0/2] qdev: convert devices Gerd Hoffmann
@ 2009-07-21 12:54 ` Gerd Hoffmann
2009-07-21 12:55 ` [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx Gerd Hoffmann
1 sibling, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2009-07-21 12:54 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/cirrus_vga.c | 85 ++++++++++++++++++++++++++---------------------
hw/vga.c | 98 ++++++++++++++++++++++++++++++++++--------------------
hw/vmware_vga.c | 26 +++++++++++---
3 files changed, 129 insertions(+), 80 deletions(-)
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 0460f97..95d822a 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -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);
diff --git a/hw/vga.c b/hw/vga.c
index 91a6852..50af4b7 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2480,52 +2480,78 @@ static void pci_vga_write_config(PCIDevice *d,
s->map_addr = 0;
}
-int pci_vga_init(PCIBus *bus,
- unsigned long vga_bios_offset, int vga_bios_size)
-{
- PCIVGAState *d;
- VGAState *s;
- uint8_t *pci_conf;
-
- d = (PCIVGAState *)pci_register_device(bus, "VGA",
- sizeof(PCIVGAState),
- -1, NULL, pci_vga_write_config);
- if (!d)
- return -1;
- s = &d->vga_state;
-
- vga_common_init(s, VGA_RAM_SIZE);
- vga_init(s);
-
- s->ds = graphic_console_init(s->update, s->invalidate,
- s->screen_dump, s->text_update, s);
-
- s->pci_dev = &d->dev;
-
- pci_conf = d->dev.config;
- // dummy VGA (same as Bochs ID)
- pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
- pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
- pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
- pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
-
- /* XXX: VGA_RAM_SIZE must be a power of two */
- pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
- PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
- if (vga_bios_size != 0) {
+static void pci_vga_initfn(PCIDevice *dev)
+{
+ PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
+ VGAState *s = &d->vga_state;
+ uint8_t *pci_conf = d->dev.config;
+
+ // vga + console init
+ vga_common_init(s, VGA_RAM_SIZE);
+ vga_init(s);
+ s->pci_dev = &d->dev;
+ s->ds = graphic_console_init(s->update, s->invalidate,
+ s->screen_dump, s->text_update, s);
+
+ // dummy VGA (same as Bochs ID)
+ pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
+ pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
+ pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
+ pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
+
+ /* XXX: VGA_RAM_SIZE must be a power of two */
+ pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
+ PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
+
+ if (s->bios_size) {
unsigned int bios_total_size;
- s->bios_offset = vga_bios_offset;
- s->bios_size = vga_bios_size;
/* must be a power of two */
bios_total_size = 1;
- while (bios_total_size < vga_bios_size)
+ while (bios_total_size < s->bios_size)
bios_total_size <<= 1;
pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size,
- PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
+ PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
}
+}
+
+int pci_vga_init(PCIBus *bus,
+ unsigned long vga_bios_offset, int vga_bios_size)
+{
+ PCIDevice *dev;
+
+ dev = pci_create("VGA", NULL);
+ qdev_prop_set_uint32(&dev->qdev, "bios-offset", vga_bios_offset);
+ qdev_prop_set_uint32(&dev->qdev, "bios-size", vga_bios_offset);
+ qdev_init(&dev->qdev);
+
return 0;
}
+static PCIDeviceInfo vga_info = {
+ .qdev.name = "VGA",
+ .qdev.size = sizeof(PCIVGAState),
+ .init = pci_vga_initfn,
+ .config_write = pci_vga_write_config,
+ .qdev.props = (Property[]) {
+ {
+ .name = "bios-offset",
+ .info = &qdev_prop_hex32,
+ .offset = offsetof(PCIVGAState, vga_state.bios_offset),
+ },{
+ .name = "bios-size",
+ .info = &qdev_prop_hex32,
+ .offset = offsetof(PCIVGAState, vga_state.bios_size),
+ },
+ {/* end of list */}
+ }
+};
+
+static void vga_register(void)
+{
+ pci_qdev_register(&vga_info);
+}
+device_init(vga_register);
+
/********************************************************/
/* vga screen dump */
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index accdac4..5ceebf1 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -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);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx.
2009-07-21 12:54 [Qemu-devel] [PATCH 0/2] qdev: convert devices Gerd Hoffmann
2009-07-21 12:54 ` [Qemu-devel] [PATCH 1/2] qdev: convert all vga devices Gerd Hoffmann
@ 2009-07-21 12:55 ` Gerd Hoffmann
2009-07-22 12:49 ` Anthony Liguori
1 sibling, 1 reply; 5+ messages in thread
From: Gerd Hoffmann @ 2009-07-21 12:55 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev.
Tag as no-user.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/pci_host.h | 3 ++
hw/piix_pci.c | 108 +++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 85 insertions(+), 26 deletions(-)
diff --git a/hw/pci_host.h b/hw/pci_host.h
index 757b0e2..48862b5 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -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;
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index fce01d4..91cebc9 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -25,6 +25,7 @@
#include "hw.h"
#include "pc.h"
#include "pci.h"
+#include "sysbus.h"
typedef uint32_t pci_addr_t;
#include "pci_host.h"
@@ -169,16 +170,9 @@ static int i440fx_load(QEMUFile* f, void *opaque, int version_id)
return 0;
}
-PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+static void i440fx_pcihost_initfn(SysBusDevice *dev)
{
- PCIBus *b;
- PCIDevice *d;
- I440FXState *s;
-
- s = qemu_mallocz(sizeof(I440FXState));
- b = pci_register_bus(NULL, "pci",
- piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
- s->bus = b;
+ I440FXState *s = FROM_SYSBUS(I440FXState, dev);
register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s);
register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s);
@@ -189,10 +183,10 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s);
register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
+}
- d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
- NULL, i440fx_write_config);
-
+static void i440fx_initfn(PCIDevice *d)
+{
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(d->config, PCI_DEVICE_ID_INTEL_82441);
d->config[0x08] = 0x02; // revision
@@ -202,7 +196,25 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
d->config[0x72] = 0x02; /* SMRAM */
register_savevm("I440FX", 0, 2, i440fx_save, i440fx_load, d);
+}
+
+PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+{
+ DeviceState *dev;
+ PCIBus *b;
+ PCIDevice *d;
+ I440FXState *s;
+
+ dev = qdev_create(NULL, "i440FX-pcihost");
+ s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev));
+ b = pci_register_bus(&s->busdev.qdev, NULL,
+ piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
+ s->bus = b;
+ qdev_init(dev);
+
+ d = pci_create_simple(b, 0, "i440FX");
*pi440fx_state = d;
+
return b;
}
@@ -326,49 +338,93 @@ static int piix_load(QEMUFile* f, void *opaque, int version_id)
return pci_device_load(d, f);
}
-int piix3_init(PCIBus *bus, int devfn)
+static void piix3_initfn(PCIDevice *d)
{
- PCIDevice *d;
uint8_t *pci_conf;
- d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice),
- devfn, NULL, NULL);
register_savevm("PIIX3", 0, 2, piix_save, piix_load, d);
- piix3_dev = d;
pci_conf = d->config;
-
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_0); // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
pci_conf[PCI_HEADER_TYPE] =
PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
+ piix3_dev = d;
piix3_reset(d);
qemu_register_reset(piix3_reset, d);
- return d->devfn;
}
-int piix4_init(PCIBus *bus, int devfn)
+static void piix4_initfn(PCIDevice *d)
{
- PCIDevice *d;
uint8_t *pci_conf;
- d = pci_register_device(bus, "PIIX4", sizeof(PCIDevice),
- devfn, NULL, NULL);
register_savevm("PIIX4", 0, 2, piix_save, piix_load, d);
- piix4_dev = d;
pci_conf = d->config;
-
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_0); // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
pci_conf[PCI_HEADER_TYPE] =
PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
-
+ piix4_dev = d;
piix4_reset(d);
qemu_register_reset(piix4_reset, d);
+}
+
+int piix3_init(PCIBus *bus, int devfn)
+{
+ PCIDevice *d;
+
+ d = pci_create_simple(bus, devfn, "PIIX3");
return d->devfn;
}
+
+int piix4_init(PCIBus *bus, int devfn)
+{
+ PCIDevice *d;
+
+ d = pci_create_simple(bus, devfn, "PIIX4");
+ return d->devfn;
+}
+
+static PCIDeviceInfo i440fx_info[] = {
+ {
+ .qdev.name = "i440FX",
+ .qdev.desc = "Host bridge",
+ .qdev.size = sizeof(PCIDevice),
+ .qdev.no_user = 1,
+ .init = i440fx_initfn,
+ .config_write = i440fx_write_config,
+ },{
+ .qdev.name = "PIIX3",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PCIDevice),
+ .qdev.no_user = 1,
+ .init = piix3_initfn,
+ },{
+ .qdev.name = "PIIX4",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PCIDevice),
+ .qdev.no_user = 1,
+ .init = piix4_initfn,
+ },{
+ /* end of list */
+ }
+};
+
+static SysBusDeviceInfo i440fx_pcihost_info = {
+ .init = i440fx_pcihost_initfn,
+ .qdev.name = "i440FX-pcihost",
+ .qdev.size = sizeof(I440FXState),
+ .qdev.no_user = 1,
+};
+
+static void i440fx_register(void)
+{
+ sysbus_register_withprop(&i440fx_pcihost_info);
+ pci_qdev_register_many(i440fx_info);
+}
+device_init(i440fx_register);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx.
2009-07-21 12:55 ` [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx Gerd Hoffmann
@ 2009-07-22 12:49 ` Anthony Liguori
2009-07-22 13:17 ` Gerd Hoffmann
0 siblings, 1 reply; 5+ messages in thread
From: Anthony Liguori @ 2009-07-22 12:49 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel
Gerd Hoffmann wrote:
> Hook i44fx pcihost into sysbus.
> Convert Host bridge and ISA bridge pci devices to qdev.
> Tag as no-user.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx.
2009-07-22 12:49 ` Anthony Liguori
@ 2009-07-22 13:17 ` Gerd Hoffmann
0 siblings, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2009-07-22 13:17 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 743 bytes --]
On 07/22/09 14:49, Anthony Liguori wrote:
> Gerd Hoffmann wrote:
>> Hook i44fx pcihost into sysbus.
>> Convert Host bridge and ISA bridge pci devices to qdev.
>> Tag as no-user.
>>
>> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> 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
[-- Attachment #2: 0001-qdev-pci-hook-up-i440fx.patch --]
[-- Type: text/plain, Size: 6430 bytes --]
>From 9e3f57932de11786f791c5b74e51d4c127b4e0f5 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
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.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/pci_host.h | 3 ++
hw/piix_pci.c | 108 +++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 85 insertions(+), 26 deletions(-)
diff --git a/hw/pci_host.h b/hw/pci_host.h
index 757b0e2..48862b5 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -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;
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index fce01d4..db40ed3 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -25,6 +25,7 @@
#include "hw.h"
#include "pc.h"
#include "pci.h"
+#include "sysbus.h"
typedef uint32_t pci_addr_t;
#include "pci_host.h"
@@ -169,16 +170,9 @@ static int i440fx_load(QEMUFile* f, void *opaque, int version_id)
return 0;
}
-PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+static void i440fx_pcihost_initfn(SysBusDevice *dev)
{
- PCIBus *b;
- PCIDevice *d;
- I440FXState *s;
-
- s = qemu_mallocz(sizeof(I440FXState));
- b = pci_register_bus(NULL, "pci",
- piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
- s->bus = b;
+ I440FXState *s = FROM_SYSBUS(I440FXState, dev);
register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s);
register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s);
@@ -189,10 +183,10 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s);
register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
+}
- d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
- NULL, i440fx_write_config);
-
+static void i440fx_initfn(PCIDevice *d)
+{
pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(d->config, PCI_DEVICE_ID_INTEL_82441);
d->config[0x08] = 0x02; // revision
@@ -202,7 +196,25 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
d->config[0x72] = 0x02; /* SMRAM */
register_savevm("I440FX", 0, 2, i440fx_save, i440fx_load, d);
+}
+
+PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+{
+ DeviceState *dev;
+ PCIBus *b;
+ PCIDevice *d;
+ I440FXState *s;
+
+ dev = qdev_create(NULL, "i440FX-pcihost");
+ s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev));
+ b = pci_register_bus(&s->busdev.qdev, "pci.0",
+ piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
+ s->bus = b;
+ qdev_init(dev);
+
+ d = pci_create_simple(b, 0, "i440FX");
*pi440fx_state = d;
+
return b;
}
@@ -326,49 +338,93 @@ static int piix_load(QEMUFile* f, void *opaque, int version_id)
return pci_device_load(d, f);
}
-int piix3_init(PCIBus *bus, int devfn)
+static void piix3_initfn(PCIDevice *d)
{
- PCIDevice *d;
uint8_t *pci_conf;
- d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice),
- devfn, NULL, NULL);
register_savevm("PIIX3", 0, 2, piix_save, piix_load, d);
- piix3_dev = d;
pci_conf = d->config;
-
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_0); // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
pci_conf[PCI_HEADER_TYPE] =
PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
+ piix3_dev = d;
piix3_reset(d);
qemu_register_reset(piix3_reset, d);
- return d->devfn;
}
-int piix4_init(PCIBus *bus, int devfn)
+static void piix4_initfn(PCIDevice *d)
{
- PCIDevice *d;
uint8_t *pci_conf;
- d = pci_register_device(bus, "PIIX4", sizeof(PCIDevice),
- devfn, NULL, NULL);
register_savevm("PIIX4", 0, 2, piix_save, piix_load, d);
- piix4_dev = d;
pci_conf = d->config;
-
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_0); // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
pci_conf[PCI_HEADER_TYPE] =
PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
-
+ piix4_dev = d;
piix4_reset(d);
qemu_register_reset(piix4_reset, d);
+}
+
+int piix3_init(PCIBus *bus, int devfn)
+{
+ PCIDevice *d;
+
+ d = pci_create_simple(bus, devfn, "PIIX3");
return d->devfn;
}
+
+int piix4_init(PCIBus *bus, int devfn)
+{
+ PCIDevice *d;
+
+ d = pci_create_simple(bus, devfn, "PIIX4");
+ return d->devfn;
+}
+
+static PCIDeviceInfo i440fx_info[] = {
+ {
+ .qdev.name = "i440FX",
+ .qdev.desc = "Host bridge",
+ .qdev.size = sizeof(PCIDevice),
+ .qdev.no_user = 1,
+ .init = i440fx_initfn,
+ .config_write = i440fx_write_config,
+ },{
+ .qdev.name = "PIIX3",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PCIDevice),
+ .qdev.no_user = 1,
+ .init = piix3_initfn,
+ },{
+ .qdev.name = "PIIX4",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PCIDevice),
+ .qdev.no_user = 1,
+ .init = piix4_initfn,
+ },{
+ /* end of list */
+ }
+};
+
+static SysBusDeviceInfo i440fx_pcihost_info = {
+ .init = i440fx_pcihost_initfn,
+ .qdev.name = "i440FX-pcihost",
+ .qdev.size = sizeof(I440FXState),
+ .qdev.no_user = 1,
+};
+
+static void i440fx_register(void)
+{
+ sysbus_register_withprop(&i440fx_pcihost_info);
+ pci_qdev_register_many(i440fx_info);
+}
+device_init(i440fx_register);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-07-22 13:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-21 12:54 [Qemu-devel] [PATCH 0/2] qdev: convert devices Gerd Hoffmann
2009-07-21 12:54 ` [Qemu-devel] [PATCH 1/2] qdev: convert all vga devices Gerd Hoffmann
2009-07-21 12:55 ` [Qemu-devel] [PATCH 2/2] qdev/pci: hook up i440fx Gerd Hoffmann
2009-07-22 12:49 ` Anthony Liguori
2009-07-22 13:17 ` Gerd Hoffmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).