diff options
author | Andreas Färber <andreas.faerber@web.de> | 2012-01-03 02:42:46 +0100 |
---|---|---|
committer | Andreas Färber <andreas.faerber@web.de> | 2012-01-20 00:27:12 +0100 |
commit | 8ca8c7bce027d0f4aaa8ca108ebae37021361b98 (patch) | |
tree | acdb23f34691db3411c04539598ce5358b88fb93 | |
parent | 7e5610ff72b0d12feb24d1e973e4be303f422eb6 (diff) | |
download | qemu-8ca8c7bce027d0f4aaa8ca108ebae37021361b98.zip qemu-8ca8c7bce027d0f4aaa8ca108ebae37021361b98.tar.gz qemu-8ca8c7bce027d0f4aaa8ca108ebae37021361b98.tar.bz2 |
prep: qdev'ify Raven host bridge (SysBus)
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 <andreas.faerber@web.de>
Reviewed-by: Alexander Graf <agraf@suse.de>
Cc: Hervé Poussineau <hpoussin@reactos.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | hw/ppc_prep.c | 23 | ||||
-rw-r--r-- | hw/prep_pci.c | 67 | ||||
-rw-r--r-- | hw/prep_pci.h | 11 |
3 files changed, 63 insertions, 38 deletions
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 |