Received: from eggs.gnu.org ([208.118.235.92]:59397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3VSm-0004jr-7k for qemu-devel@nongnu.org; Mon, 20 Aug 2012 13:08:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3VSk-0005qH-7G for qemu-devel@nongnu.org; Mon, 20 Aug 2012 13:08:28 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 20 Aug 2012 19:08:05 +0200 Message-Id: <1345482489-5789-11-git-send-email-afaerber@suse.de> In-Reply-To: <1345482489-5789-1-git-send-email-afaerber@suse.de> References: <1345482489-5789-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-1.2 v7 10/14] spapr_pci: QOM'ify sPAPR PCI host bridge List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mst@redhat.com, Alexander Graf , "open list:sPAPR" , anthony@codemonkey.ws, =?UTF-8?q?Andreas=20F=C3=A4rber?= , David Gibson Introduce type constant. Introduce cast macro to drop bogus busdev field that would've broken SYS_BUS_DEVICE(). Avoid accessing parent fields directly. Free the identifier phb as acronym for PCI_HOST_BRIDGE. Updated against conflicting merge from branch 'agraf/ppc-for-upstream' (0d16fdd732d1b211842fa96b7c90ddf9e6bde0e4), which removed busdev field differently, moved some code around and added new occurrences of 'phb'. Signed-off-by: Andreas F=C3=A4rber --- hw/spapr.c | 7 ++-- hw/spapr_pci.c | 90 +++++++++++++++++++++++++++++---------------------= ----- hw/spapr_pci.h | 5 +++ 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/hw/spapr.c b/hw/spapr.c index be533ee..f8b53e9 100644 --- a/hw/spapr.c +++ b/hw/spapr.c @@ -612,6 +612,7 @@ static void ppc_spapr_init(ram_addr_t ram_size, { PowerPCCPU *cpu; CPUPPCState *env; + PCIHostState *phb; int i; MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *ram =3D g_new(MemoryRegion, 1); @@ -742,6 +743,7 @@ static void ppc_spapr_init(ram_addr_t ram_size, SPAPR_PCI_MEM_WIN_SIZE, SPAPR_PCI_IO_WIN_ADDR, SPAPR_PCI_MSI_WIN_ADDR); + phb =3D &QLIST_FIRST(&spapr->phbs)->host_state; =20 for (i =3D 0; i < nb_nics; i++) { NICInfo *nd =3D &nd_table[i]; @@ -762,13 +764,12 @@ static void ppc_spapr_init(ram_addr_t ram_size, } =20 /* Graphics */ - if (spapr_vga_init(QLIST_FIRST(&spapr->phbs)->host_state.bus)) { + if (spapr_vga_init(phb->bus)) { spapr->has_graphics =3D true; } =20 if (usb_enabled) { - pci_create_simple(QLIST_FIRST(&spapr->phbs)->host_state.bus, - -1, "pci-ohci"); + pci_create_simple(phb->bus, -1, "pci-ohci"); if (spapr->has_graphics) { usbdevice_create("keyboard"); usbdevice_create("mouse"); diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c index c57ab1e..f9dd2a8 100644 --- a/hw/spapr_pci.c +++ b/hw/spapr_pci.c @@ -48,13 +48,13 @@ =20 static sPAPRPHBState *find_phb(sPAPREnvironment *spapr, uint64_t buid) { - sPAPRPHBState *phb; + sPAPRPHBState *sphb; =20 - QLIST_FOREACH(phb, &spapr->phbs, list) { - if (phb->buid !=3D buid) { + QLIST_FOREACH(sphb, &spapr->phbs, list) { + if (sphb->buid !=3D buid) { continue; } - return phb; + return sphb; } =20 return NULL; @@ -63,7 +63,9 @@ static sPAPRPHBState *find_phb(sPAPREnvironment *spapr,= uint64_t buid) static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, uint32_t config_addr) { - sPAPRPHBState *phb =3D find_phb(spapr, buid); + sPAPRPHBState *sphb =3D find_phb(spapr, buid); + PCIHostState *phb =3D &sphb->host_state; + BusState *bus =3D BUS(phb->bus); BusChild *kid; int devfn =3D (config_addr >> 8) & 0xFF; =20 @@ -71,7 +73,7 @@ static PCIDevice *find_dev(sPAPREnvironment *spapr, uin= t64_t buid, return NULL; } =20 - QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { + QTAILQ_FOREACH(kid, &bus->children, sibling) { PCIDevice *dev =3D (PCIDevice *)kid->child; if (dev->devfn =3D=3D devfn) { return dev; @@ -514,23 +516,24 @@ static DMAContext *spapr_pci_dma_context_fn(PCIBus = *bus, void *opaque, =20 static int spapr_phb_init(SysBusDevice *s) { - sPAPRPHBState *phb =3D DO_UPCAST(sPAPRPHBState, host_state.busdev, s= ); + sPAPRPHBState *sphb =3D SPAPR_PCI_HOST_BRIDGE(s); + PCIHostState *phb =3D FROM_SYSBUS(PCIHostState, s); char *namebuf; int i; PCIBus *bus; =20 - phb->dtbusname =3D g_strdup_printf("pci@%" PRIx64, phb->buid); - namebuf =3D alloca(strlen(phb->dtbusname) + 32); + sphb->dtbusname =3D g_strdup_printf("pci@%" PRIx64, sphb->buid); + namebuf =3D alloca(strlen(sphb->dtbusname) + 32); =20 /* Initialize memory regions */ - sprintf(namebuf, "%s.mmio", phb->dtbusname); - memory_region_init(&phb->memspace, namebuf, INT64_MAX); + sprintf(namebuf, "%s.mmio", sphb->dtbusname); + memory_region_init(&sphb->memspace, namebuf, INT64_MAX); =20 - sprintf(namebuf, "%s.mmio-alias", phb->dtbusname); - memory_region_init_alias(&phb->memwindow, namebuf, &phb->memspace, - SPAPR_PCI_MEM_WIN_BUS_OFFSET, phb->mem_win_= size); - memory_region_add_subregion(get_system_memory(), phb->mem_win_addr, - &phb->memwindow); + sprintf(namebuf, "%s.mmio-alias", sphb->dtbusname); + memory_region_init_alias(&sphb->memwindow, namebuf, &sphb->memspace, + SPAPR_PCI_MEM_WIN_BUS_OFFSET, sphb->mem_win= _size); + memory_region_add_subregion(get_system_memory(), sphb->mem_win_addr, + &sphb->memwindow); =20 /* On ppc, we only have MMIO no specific IO space from the CPU * perspective. In theory we ought to be able to embed the PCI IO @@ -540,42 +543,42 @@ static int spapr_phb_init(SysBusDevice *s) * system io address space. This hack to bounce things via * system_io works around the problem until all the users of * old_portion are updated */ - sprintf(namebuf, "%s.io", phb->dtbusname); - memory_region_init(&phb->iospace, namebuf, SPAPR_PCI_IO_WIN_SIZE); + sprintf(namebuf, "%s.io", sphb->dtbusname); + memory_region_init(&sphb->iospace, namebuf, SPAPR_PCI_IO_WIN_SIZE); /* FIXME: fix to support multiple PHBs */ - memory_region_add_subregion(get_system_io(), 0, &phb->iospace); + memory_region_add_subregion(get_system_io(), 0, &sphb->iospace); =20 - sprintf(namebuf, "%s.io-alias", phb->dtbusname); - memory_region_init_io(&phb->iowindow, &spapr_io_ops, phb, + sprintf(namebuf, "%s.io-alias", sphb->dtbusname); + memory_region_init_io(&sphb->iowindow, &spapr_io_ops, sphb, namebuf, SPAPR_PCI_IO_WIN_SIZE); - memory_region_add_subregion(get_system_memory(), phb->io_win_addr, - &phb->iowindow); + memory_region_add_subregion(get_system_memory(), sphb->io_win_addr, + &sphb->iowindow); =20 /* As MSI/MSIX interrupts trigger by writing at MSI/MSIX vectors, * we need to allocate some memory to catch those writes coming * from msi_notify()/msix_notify() */ if (msi_supported) { - sprintf(namebuf, "%s.msi", phb->dtbusname); - memory_region_init_io(&phb->msiwindow, &spapr_msi_ops, phb, + sprintf(namebuf, "%s.msi", sphb->dtbusname); + memory_region_init_io(&sphb->msiwindow, &spapr_msi_ops, sphb, namebuf, SPAPR_MSIX_MAX_DEVS * 0x10000); - memory_region_add_subregion(get_system_memory(), phb->msi_win_ad= dr, - &phb->msiwindow); + memory_region_add_subregion(get_system_memory(), sphb->msi_win_a= ddr, + &sphb->msiwindow); } =20 - bus =3D pci_register_bus(&phb->host_state.busdev.qdev, - phb->busname ? phb->busname : phb->dtbusname, - pci_spapr_set_irq, pci_spapr_map_irq, phb, - &phb->memspace, &phb->iospace, + bus =3D pci_register_bus(DEVICE(s), + sphb->busname ? sphb->busname : sphb->dtbusna= me, + pci_spapr_set_irq, pci_spapr_map_irq, sphb, + &sphb->memspace, &sphb->iospace, PCI_DEVFN(0, 0), PCI_NUM_PINS); - phb->host_state.bus =3D bus; + phb->bus =3D bus; =20 - phb->dma_liobn =3D SPAPR_PCI_BASE_LIOBN | (pci_find_domain(bus) << 1= 6); - phb->dma_window_start =3D 0; - phb->dma_window_size =3D 0x40000000; - phb->dma =3D spapr_tce_new_dma_context(phb->dma_liobn, phb->dma_wind= ow_size); - pci_setup_iommu(bus, spapr_pci_dma_context_fn, phb); + sphb->dma_liobn =3D SPAPR_PCI_BASE_LIOBN | (pci_find_domain(bus) << = 16); + sphb->dma_window_start =3D 0; + sphb->dma_window_size =3D 0x40000000; + sphb->dma =3D spapr_tce_new_dma_context(sphb->dma_liobn, sphb->dma_w= indow_size); + pci_setup_iommu(bus, spapr_pci_dma_context_fn, sphb); =20 - QLIST_INSERT_HEAD(&spapr->phbs, phb, list); + QLIST_INSERT_HEAD(&spapr->phbs, sphb, list); =20 /* Initialize the LSI table */ for (i =3D 0; i < PCI_NUM_PINS; i++) { @@ -586,7 +589,7 @@ static int spapr_phb_init(SysBusDevice *s) return -1; } =20 - phb->lsi_table[i].irq =3D irq; + sphb->lsi_table[i].irq =3D irq; } =20 return 0; @@ -613,7 +616,7 @@ static void spapr_phb_class_init(ObjectClass *klass, = void *data) } =20 static const TypeInfo spapr_phb_info =3D { - .name =3D "spapr-pci-host-bridge", + .name =3D TYPE_SPAPR_PCI_HOST_BRIDGE, .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(sPAPRPHBState), .class_init =3D spapr_phb_class_init, @@ -626,7 +629,7 @@ void spapr_create_phb(sPAPREnvironment *spapr, { DeviceState *dev; =20 - dev =3D qdev_create(NULL, spapr_phb_info.name); + dev =3D qdev_create(NULL, TYPE_SPAPR_PCI_HOST_BRIDGE); =20 if (busname) { qdev_prop_set_string(dev, "busname", g_strdup(busname)); @@ -750,8 +753,9 @@ void spapr_pci_rtas_init(void) } } =20 -static void register_types(void) +static void spapr_pci_register_types(void) { type_register_static(&spapr_phb_info); } -type_init(register_types) + +type_init(spapr_pci_register_types) diff --git a/hw/spapr_pci.h b/hw/spapr_pci.h index 7518899..4140ee6 100644 --- a/hw/spapr_pci.h +++ b/hw/spapr_pci.h @@ -29,6 +29,11 @@ =20 #define SPAPR_MSIX_MAX_DEVS 32 =20 +#define TYPE_SPAPR_PCI_HOST_BRIDGE "spapr-pci-host-bridge" + +#define SPAPR_PCI_HOST_BRIDGE(obj) \ + OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE) + typedef struct sPAPRPHBState { PCIHostState host_state; =20 --=20 1.7.7