[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-ppc] [PATCH v5 2/6] prep: qdev'ify Raven host bridge (SysBus)
From: |
Andreas Färber |
Subject: |
[Qemu-ppc] [PATCH v5 2/6] prep: qdev'ify Raven host bridge (SysBus) |
Date: |
Mon, 16 Jan 2012 17:18:04 +0100 |
Drop pci_prep_init() in favor of extended device state. Inspired by
patches from Hervé and Alex.
Assign the 4 IRQs from the board after device instantiation. This moves
the knowledge out of prep_pci and allows for future machines with
different IRQ wiring (IBM 40P). Suggested by Alex.
Signed-off-by: Andreas Färber <address@hidden>
Reviewed-by: Alexander Graf <address@hidden>
Cc: Hervé Poussineau <address@hidden>
Cc: Michael S. Tsirkin <address@hidden>
Cc: Anthony Liguori <address@hidden>
---
hw/ppc_prep.c | 23 +++++++++++++++++-
hw/prep_pci.c | 67 +++++++++++++++++++++++++++++++++++---------------------
hw/prep_pci.h | 11 ---------
3 files changed, 63 insertions(+), 38 deletions(-)
delete mode 100644 hw/prep_pci.h
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 1cc0ae0..62d0e36 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -29,7 +29,7 @@
#include "sysemu.h"
#include "isa.h"
#include "pci.h"
-#include "prep_pci.h"
+#include "pci_host.h"
#include "usb-ohci.h"
#include "ppc.h"
#include "boards.h"
@@ -522,6 +522,9 @@ static void ppc_prep_init (ram_addr_t ram_size,
MemoryRegion *bios = g_new(MemoryRegion, 1);
uint32_t kernel_base, initrd_base;
long kernel_size, initrd_size;
+ DeviceState *dev;
+ SysBusDevice *sys;
+ PCIHostState *pcihost;
PCIBus *pci_bus;
ISABus *isa_bus;
qemu_irq *i8259;
@@ -633,7 +636,23 @@ static void ppc_prep_init (ram_addr_t ram_size,
/* Hmm, prep has no pci-isa bridge ??? */
isa_bus = isa_bus_new(NULL, get_system_io());
i8259 = i8259_init(isa_bus, first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
- pci_bus = pci_prep_init(i8259, get_system_memory(), get_system_io());
+
+ dev = qdev_create(NULL, "raven-pcihost");
+ sys = sysbus_from_qdev(dev);
+ pcihost = DO_UPCAST(PCIHostState, busdev, sys);
+ pcihost->address_space = get_system_memory();
+ qdev_init_nofail(dev);
+ qdev_property_add_child(qdev_get_root(), "raven", dev, NULL);
+ pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
+ if (pci_bus == NULL) {
+ fprintf(stderr, "Couldn't create PCI host controller.\n");
+ exit(1);
+ }
+ sysbus_connect_irq(&pcihost->busdev, 0, i8259[9]);
+ sysbus_connect_irq(&pcihost->busdev, 1, i8259[11]);
+ sysbus_connect_irq(&pcihost->busdev, 2, i8259[9]);
+ sysbus_connect_irq(&pcihost->busdev, 3, i8259[11]);
+
isa_bus_irqs(isa_bus, i8259);
// pci_bus = i440fx_init();
/* Register 8 MB of ISA IO space (needed for non-contiguous map) */
diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index 2600e26..4961eed 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -25,9 +25,12 @@
#include "hw.h"
#include "pci.h"
#include "pci_host.h"
-#include "prep_pci.h"
+#include "exec-memory.h"
-typedef PCIHostState PREPPCIState;
+typedef struct PRePPCIState {
+ PCIHostState host_state;
+ qemu_irq irq[4];
+} PREPPCIState;
typedef struct RavenPCIState {
PCIDevice dev;
@@ -48,14 +51,14 @@ static void ppc_pci_io_write(void *opaque,
target_phys_addr_t addr,
uint64_t val, unsigned int size)
{
PREPPCIState *s = opaque;
- pci_data_write(s->bus, PPC_PCIIO_config(addr), val, size);
+ pci_data_write(s->host_state.bus, PPC_PCIIO_config(addr), val, size);
}
static uint64_t ppc_pci_io_read(void *opaque, target_phys_addr_t addr,
unsigned int size)
{
PREPPCIState *s = opaque;
- return pci_data_read(s->bus, PPC_PCIIO_config(addr), size);
+ return pci_data_read(s->host_state.bus, PPC_PCIIO_config(addr), size);
}
static const MemoryRegionOps PPC_PCIIO_ops = {
@@ -73,38 +76,43 @@ static void prep_set_irq(void *opaque, int irq_num, int
level)
{
qemu_irq *pic = opaque;
- qemu_set_irq(pic[(irq_num & 1) ? 11 : 9] , level);
+ qemu_set_irq(pic[irq_num] , level);
}
-PCIBus *pci_prep_init(qemu_irq *pic,
- MemoryRegion *address_space_mem,
- MemoryRegion *address_space_io)
+static int raven_pcihost_init(SysBusDevice *dev)
{
- PREPPCIState *s;
+ PCIHostState *h = FROM_SYSBUS(PCIHostState, dev);
+ PREPPCIState *s = DO_UPCAST(PREPPCIState, host_state, h);
+ MemoryRegion *address_space_mem = get_system_memory();
+ MemoryRegion *address_space_io = get_system_io();
+ PCIBus *bus;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ sysbus_init_irq(dev, &s->irq[i]);
+ }
- s = g_malloc0(sizeof(PREPPCIState));
- s->bus = pci_register_bus(NULL, "pci",
- prep_set_irq, prep_map_irq, pic,
- address_space_mem,
- address_space_io,
- 0, 4);
+ bus = pci_register_bus(&h->busdev.qdev, NULL,
+ prep_set_irq, prep_map_irq, s->irq,
+ address_space_mem, address_space_io, 0, 4);
+ h->bus = bus;
- memory_region_init_io(&s->conf_mem, &pci_host_conf_be_ops, s,
+ memory_region_init_io(&h->conf_mem, &pci_host_conf_be_ops, s,
"pci-conf-idx", 1);
- memory_region_add_subregion(address_space_io, 0xcf8, &s->conf_mem);
- sysbus_init_ioports(&s->busdev, 0xcf8, 1);
+ sysbus_add_io(dev, 0xcf8, &h->conf_mem);
+ sysbus_init_ioports(&h->busdev, 0xcf8, 1);
- memory_region_init_io(&s->data_mem, &pci_host_data_be_ops, s,
+ memory_region_init_io(&h->data_mem, &pci_host_data_be_ops, s,
"pci-conf-data", 1);
- memory_region_add_subregion(address_space_io, 0xcfc, &s->data_mem);
- sysbus_init_ioports(&s->busdev, 0xcfc, 1);
+ sysbus_add_io(dev, 0xcfc, &h->data_mem);
+ sysbus_init_ioports(&h->busdev, 0xcfc, 1);
- memory_region_init_io(&s->mmcfg, &PPC_PCIIO_ops, s, "pciio", 0x00400000);
- memory_region_add_subregion(address_space_mem, 0x80800000, &s->mmcfg);
+ memory_region_init_io(&h->mmcfg, &PPC_PCIIO_ops, s, "pciio", 0x00400000);
+ memory_region_add_subregion(address_space_mem, 0x80800000, &h->mmcfg);
- pci_create_simple(s->bus, 0, "raven");
+ pci_create_simple(bus, 0, "raven");
- return s->bus;
+ return 0;
}
static int raven_init(PCIDevice *d)
@@ -143,8 +151,17 @@ static PCIDeviceInfo raven_info = {
},
};
+static SysBusDeviceInfo raven_pcihost_info = {
+ .qdev.name = "raven-pcihost",
+ .qdev.fw_name = "pci",
+ .qdev.size = sizeof(PREPPCIState),
+ .qdev.no_user = 1,
+ .init = raven_pcihost_init,
+};
+
static void raven_register_devices(void)
{
+ sysbus_register_withprop(&raven_pcihost_info);
pci_qdev_register(&raven_info);
}
diff --git a/hw/prep_pci.h b/hw/prep_pci.h
deleted file mode 100644
index b6b481a..0000000
--- a/hw/prep_pci.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef QEMU_PREP_PCI_H
-#define QEMU_PREP_PCI_H
-
-#include "qemu-common.h"
-#include "memory.h"
-
-PCIBus *pci_prep_init(qemu_irq *pic,
- MemoryRegion *address_space_mem,
- MemoryRegion *address_space_io);
-
-#endif
--
1.7.7
- [Qemu-ppc] [PATCH v4 2/8] prep_pci: Simplify I/O endianness, (continued)
- [Qemu-ppc] [PATCH v4 2/8] prep_pci: Simplify I/O endianness, Andreas Färber, 2012/01/13
- [Qemu-ppc] [PATCH v4 5/8] MAINTAINERS: Add PCI host bridge files to PReP machine, Andreas Färber, 2012/01/13
- [Qemu-ppc] [PATCH v4 4/8] prep: qdev'ify Raven host bridge (SysBus), Andreas Färber, 2012/01/13
- [Qemu-ppc] [PATCH v4 8/8] prep: Use i82378 PCI->ISA bridge for 'prep' machine, Andreas Färber, 2012/01/13
- [Qemu-ppc] [PATCH v4 6/8] prep: Add i82374 DMA emulation, Andreas Färber, 2012/01/13
- [Qemu-ppc] [PATCH v4 7/8] prep: Add i82378 PCI-to-ISA bridge emulation, Andreas Färber, 2012/01/13
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v4 0/8] qdev'ify PReP PCI host bridge and add PCI-to-ISA bridge, Andreas Färber, 2012/01/16
- [Qemu-ppc] [PATCH v5 0/6] qdev'ify PReP PCI host bridge and add PCI-to-ISA bridge, Andreas Färber, 2012/01/16
- [Qemu-ppc] [PATCH v5 1/6] prep_pci: Update I/O to MemoryRegion ops, Andreas Färber, 2012/01/16
- [Qemu-ppc] [PATCH v5 3/6] MAINTAINERS: Add PCI host bridge files to PReP machine, Andreas Färber, 2012/01/16
- [Qemu-ppc] [PATCH v5 2/6] prep: qdev'ify Raven host bridge (SysBus),
Andreas Färber <=
- [Qemu-ppc] [PATCH v5 6/6] prep: Use i82378 PCI->ISA bridge for 'prep' machine, Andreas Färber, 2012/01/16
- [Qemu-ppc] [PATCH v5 5/6] prep: Add i82378 PCI-to-ISA bridge emulation, Andreas Färber, 2012/01/16
- [Qemu-ppc] [PATCH v5 4/6] prep: Add i82374 DMA emulation, Andreas Färber, 2012/01/16
- Re: [Qemu-ppc] [Qemu-devel] [PATCH v5 0/6] qdev'ify PReP PCI host bridge and add PCI-to-ISA bridge, Andreas Färber, 2012/01/19