pci_host: Convert to QOM
v5 cover pci_host: Convert to QOM
Hello Anthony and Michael,
Here's a fixed version of the series making pci_host a first-class QOM type.
MAINTAINERS entries for the ppc devices touched herein are stripped from the series but being used for sending. They can be applied later through ppc-next.
This series is a prerequisite for the i440fx refactoring and q35 introduction.
I have verified this to apply cleanly to both master and pci branch now.
mst: Followups for i440fx by Wanpeng were on the list already, but feel free not to apply the slimmed-down final patch if we can then finally move on!
Regards,
Andreas
v4 -> v5:
* Resolved PCI_HOST_BRIDGE(s)->bus usage in alpha_typhoon (forgotten in v4).
* Update Wanpeng's email address in SoB to avoid bounces.
* Leave out MAINTAINERS additions, still valid but no ack from Alex yet and open question from Peter on ordering.
v3 -> v4:
* Moved spapr_pci.c:register_types() rename to later dedicated spapr_pci patch.
* Added proposed patches for related MAINTAINERS machine entries w/ PHB files. Anthony requested the QOM cast discussion to be held elsewhere, so no change.
v2 -> v3:
* Renamed PCI_HOST to PCI_HOST_BRIDGE, suggested by mst.
* Split off const changes to clarify the name/parent changes.
* Split off cleanups per host bridge.
* Prepared and enforced QOM-style field access through explicit types.
v1 -> v2:
* Converted remaining PCI host bridges to new type.
Andreas Färber (14):
pci: Make host bridge TypeInfos const
alpha_typhoon: QOM'ify Typhoon PCI host bridge
bonito: QOM'ify Bonito PCI host bridge
dec_pci: QOM'ify DEC 21154 PCI-PCI bridge
grackle_pci: QOM'ify Grackle PCI host bridge
gt64xxx: QOM'ify GT64120 PCI host bridge
ppc4xx_pci: QOM'ify ppc4xx PCI host bridge
ppce500_pci: QOM'ify e500 PCI host bridge
prep_pci: QOM'ify Raven PCI host bridge
spapr_pci: QOM'ify sPAPR PCI host bridge
unin_pci: QOM'ify UniNorth PCI host bridges
pci_host: Turn into SysBus-derived QOM type
pci: Derive PCI host bridges from TYPE_PCI_HOST_BRIDGE
pci: Tidy up PCI host bridges
hw/alpha_typhoon.c | 26 +++++--- hw/bonito.c | 152 ++++++++++++++++++++++++++----------------- hw/dec_pci.c | 31 +++++---- hw/dec_pci.h | 2 + hw/grackle_pci.c | 65 +++++++++--------- hw/gt64xxx.c | 67 +++++++++++-------- hw/pci_host.c | 12 ++++ hw/pci_host.h | 5 ++ hw/piix_pci.c | 22 ++++--- hw/ppc440_bamboo.c | 3 +- hw/ppc4xx.h | 2 + hw/ppc4xx_pci.c | 27 +++++--- hw/ppc_mac.h | 1 + hw/ppc_prep.c | 4 +- hw/ppce500_pci.c | 24 ++++--- hw/prep_pci.c | 33 ++++++---- hw/spapr_pci.c | 29 +++++---- hw/spapr_pci.h | 8 ++- hw/unin_pci.c | 183 +++++++++++++++++++++++++++------------------------- 19 files changed, 402 insertions(+), 294 deletions(-)
Signature · 1 line
1.7.7
PATCH v5 1/14 pci: Make host bridge TypeInfos const
During the QOM migration they were amended with further info but this is no longer the case. All static TypeInfos can be const these days.
--- hw/alpha_typhoon.c | 2 +- hw/bonito.c | 4 ++-- hw/dec_pci.c | 6 +++--- hw/grackle_pci.c | 4 ++-- hw/gt64xxx.c | 4 ++-- hw/piix_pci.c | 8 ++++---- hw/ppc4xx_pci.c | 4 ++-- hw/ppce500_pci.c | 4 ++-- hw/prep_pci.c | 4 ++-- hw/spapr_pci.c | 2 +- hw/unin_pci.c | 16 ++++++++-------- 11 files changed, 29 insertions(+), 29 deletions(-)
hw/alpha_typhoon.c +1 -1
@@ -817,7 +817,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo typhoon_pcihost_info = { +static const TypeInfo typhoon_pcihost_info = { .name ="typhoon-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (TyphoonState),
hw/bonito.c +2 -2
@@ -781,7 +781,7 @@ static void bonito_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_bonito; } -static TypeInfo bonito_info = { +static const TypeInfo bonito_info = { .name ="Bonito" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIBonitoState),
@@ -797,7 +797,7 @@ static void bonito_pcihost_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo bonito_pcihost_info = { +static const TypeInfo bonito_pcihost_info = { .name ="Bonito-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (BonitoState),
hw/dec_pci.c +3 -3
@@ -66,7 +66,7 @@ static void dec_21154_pci_bridge_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_pci_device; } -static TypeInfo dec_21154_pci_bridge_info = { +static const TypeInfo dec_21154_pci_bridge_info = { .name ="dec-21154-p2p-bridge" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIBridge),
@@ -119,7 +119,7 @@ static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data) k->is_bridge =1 ; } -static TypeInfo dec_21154_pci_host_info = { +static const TypeInfo dec_21154_pci_host_info = { .name ="dec-21154" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -133,7 +133,7 @@ static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data) sdc->init = pci_dec_21154_device_init; } -static TypeInfo pci_dec_21154_device_info = { +static const TypeInfo pci_dec_21154_device_info = { .name ="dec-21154-sysbus" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (DECState),
hw/grackle_pci.c +2 -2
@@ -134,7 +134,7 @@ static void grackle_pci_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo grackle_pci_info = { +static const TypeInfo grackle_pci_info = { .name ="grackle" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -150,7 +150,7 @@ static void pci_grackle_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo grackle_pci_host_info = { +static const TypeInfo grackle_pci_host_info = { .name ="grackle-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (GrackleState),
hw/gt64xxx.c +2 -2
@@ -1147,7 +1147,7 @@ static void gt64120_pci_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_HOST ; } -static TypeInfo gt64120_pci_info = { +static const TypeInfo gt64120_pci_info = { .name ="gt64120_pci" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -1161,7 +1161,7 @@ static void gt64120_class_init(ObjectClass *klass, void *data) sdc->init = gt64120_init; } -static TypeInfo gt64120_info = { +static const TypeInfo gt64120_info = { .name ="gt64120" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (GT64120State),
hw/piix_pci.c +4 -4
@@ -537,7 +537,7 @@ static void piix3_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_ISA ; } -static TypeInfo piix3_info = { +static const TypeInfo piix3_info = { .name ="PIIX3" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PIIX3State),
@@ -560,7 +560,7 @@ static void piix3_xen_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_ISA ; }; -static TypeInfo piix3_xen_info = { +static const TypeInfo piix3_xen_info = { .name ="PIIX3-xen" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PIIX3State),
@@ -584,7 +584,7 @@ static void i440fx_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_i440fx; } -static TypeInfo i440fx_info = { +static const TypeInfo i440fx_info = { .name ="i440FX" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCII440FXState),
@@ -601,7 +601,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo i440fx_pcihost_info = { +static const TypeInfo i440fx_pcihost_info = { .name ="i440FX-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (I440FXState),
hw/ppc4xx_pci.c +2 -2
@@ -377,7 +377,7 @@ static void ppc4xx_host_bridge_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_OTHER ; } -static TypeInfo ppc4xx_host_bridge_info = { +static const TypeInfo ppc4xx_host_bridge_info = { .name ="ppc4xx-host-bridge" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -393,7 +393,7 @@ static void ppc4xx_pcihost_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_ppc4xx_pci; } -static TypeInfo ppc4xx_pcihost_info = { +static const TypeInfo ppc4xx_pcihost_info = { .name ="ppc4xx-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (PPC4xxPCIState),
hw/ppce500_pci.c +2 -2
@@ -350,7 +350,7 @@ static void e500_host_bridge_class_init(ObjectClass *klass, void *data) dc->desc ="Host bridge" ; } -static TypeInfo e500_host_bridge_info = { +static const TypeInfo e500_host_bridge_info = { .name ="e500-host-bridge" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -366,7 +366,7 @@ static void e500_pcihost_class_init(ObjectClass *klass, void *data) dc->vmsd = &vmstate_ppce500_pci; } -static TypeInfo e500_pcihost_info = { +static const TypeInfo e500_pcihost_info = { .name ="e500-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (PPCE500PCIState),
hw/prep_pci.c +2 -2
@@ -166,7 +166,7 @@ static void raven_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo raven_info = { +static const TypeInfo raven_info = { .name ="raven" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (RavenPCIState),
@@ -183,7 +183,7 @@ static void raven_pcihost_class_init(ObjectClass *klass, void *data) dc->no_user =1 ; } -static TypeInfo raven_pcihost_info = { +static const TypeInfo raven_pcihost_info = { .name ="raven-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (PREPPCIState),
hw/spapr_pci.c +1 -1
@@ -368,7 +368,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)spapr_rtas_register ("ibm,write-pci-config" , rtas_ibm_write_pci_config); } -static TypeInfo spapr_phb_info = { +static const TypeInfo spapr_phb_info = { .name ="spapr-pci-host-bridge" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (sPAPRPHBState),
hw/unin_pci.c +8 -8
@@ -350,7 +350,7 @@ static void unin_main_pci_host_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_HOST ; } -static TypeInfo unin_main_pci_host_info = { +static const TypeInfo unin_main_pci_host_info = { .name ="uni-north-pci" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -368,7 +368,7 @@ static void u3_agp_pci_host_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_HOST ; } -static TypeInfo u3_agp_pci_host_info = { +static const TypeInfo u3_agp_pci_host_info = { .name ="u3-agp" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -386,7 +386,7 @@ static void unin_agp_pci_host_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_HOST ; } -static TypeInfo unin_agp_pci_host_info = { +static const TypeInfo unin_agp_pci_host_info = { .name ="uni-north-agp" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -404,7 +404,7 @@ static void unin_internal_pci_host_class_init(ObjectClass *klass, void *data) k->class_id =PCI_CLASS_BRIDGE_HOST ; } -static TypeInfo unin_internal_pci_host_info = { +static const TypeInfo unin_internal_pci_host_info = { .name ="uni-north-internal-pci" , .parent =TYPE_PCI_DEVICE , .instance_size =sizeof (PCIDevice),
@@ -418,7 +418,7 @@ static void pci_unin_main_class_init(ObjectClass *klass, void *data) sbc->init = pci_unin_main_init_device; } -static TypeInfo pci_unin_main_info = { +static const TypeInfo pci_unin_main_info = { .name ="uni-north-pci-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState),
@@ -432,7 +432,7 @@ static void pci_u3_agp_class_init(ObjectClass *klass, void *data) sbc->init = pci_u3_agp_init_device; } -static TypeInfo pci_u3_agp_info = { +static const TypeInfo pci_u3_agp_info = { .name ="u3-agp-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState),
@@ -446,7 +446,7 @@ static void pci_unin_agp_class_init(ObjectClass *klass, void *data) sbc->init = pci_unin_agp_init_device; } -static TypeInfo pci_unin_agp_info = { +static const TypeInfo pci_unin_agp_info = { .name ="uni-north-agp-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState),
@@ -460,7 +460,7 @@ static void pci_unin_internal_class_init(ObjectClass *klass, void *data) sbc->init = pci_unin_internal_init_device; } -static TypeInfo pci_unin_internal_info = { +static const TypeInfo pci_unin_internal_info = { .name ="uni-north-internal-pci-pcihost" , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState),
Signature · 1 line
1.7.7
PATCH v5 2/14 alpha_typhoon: QOM'ify Typhoon PCI host bridge
In reply to Andreas FärberIntroduce type constant and cast macro. Don't access DeviceState or PCIHostState indirectly through parent fields.
--- hw/alpha_typhoon.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-)
hw/alpha_typhoon.c +13 -7
@@ -15,6 +15,8 @@#include "exec-memory.h" +#define TYPE_TYPHOON_PCI_HOST_BRIDGE "typhoon-pcihost" + typedef struct TyphoonCchip { MemoryRegion region; uint64_t misc;
@@ -40,8 +42,12 @@ typedef struct TyphoonPchip {TyphoonWindow win[4 ]; } TyphoonPchip; +#define TYPHOON_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(TyphoonState, (obj), TYPE_TYPHOON_PCI_HOST_BRIDGE) + typedef struct TyphoonState { PCIHostState host; + TyphoonCchip cchip; TyphoonPchip pchip; MemoryRegion dchip_region;
@@ -700,16 +706,16 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,MemoryRegion *addr_space =get_system_memory ();MemoryRegion *addr_space_io =get_system_io ();DeviceState *dev; -PCIHostState *p;TyphoonState *s; +PCIHostState *phb;PCIBus *b;int i; - dev =qdev_create (NULL ,"typhoon-pcihost" ); + dev =qdev_create (NULL ,TYPE_TYPHOON_PCI_HOST_BRIDGE );qdev_init_nofail (dev); - p =FROM_SYSBUS (PCIHostState,sysbus_from_qdev (dev)); - s =container_of (p, TyphoonState, host); + s =TYPHOON_PCI_HOST_BRIDGE (dev); + phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (dev));/* Remember the CPUs so that we can deliver interrupts to them. */ for (i =0 ; i <4 ; i++) {
@@ -763,10 +769,10 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,memory_region_add_subregion (addr_space,0x801fc000000ULL , &s->pchip.reg_io); - b =pci_register_bus (&s->host.busdev.qdev,"pci" , + b =pci_register_bus (dev,"pci" , typhoon_set_irq, sys_map_irq, s, &s->pchip.reg_mem, addr_space_io,0 ,64 ); - s->host.bus = b; + phb->bus = b;/* Pchip0 PCI special/interrupt acknowledge, 0x801.F800.0000, 64MB. */ memory_region_init_io(&s->pchip.reg_iack, &alpha_pci_iack_ops, b,
@@ -818,7 +824,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, void *data) }static const TypeInfo typhoon_pcihost_info = { - .name ="typhoon-pcihost" , + .name =TYPE_TYPHOON_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (TyphoonState), .class_init = typhoon_pcihost_class_init,
Signature · 1 line
1.7.7
PATCH v5 3/14 bonito: QOM'ify Bonito PCI host bridge
In reply to Andreas FärberIntroduce type constant. Avoid accessing DeviceState or SysBusDevice indirectly through PCIHostState field.
Drop global state by passing BonitoState as opaque and adding the IRQs and a pointer to PCIBonitoState to its state.
--- hw/bonito.c | 146 ++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 90 insertions(+), 56 deletions(-)
hw/bonito.c +90 -56
@@ -180,11 +180,14 @@#define PCI_ADDR (busno,devno,funno,regno) \ ((((busno)<<16)&0xff0000) + (((devno)<<11)&0xf800) + (((funno)<<8)&0x700) + (regno)) -typedef PCIHostState BonitoState ; +#define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost" + +typedef struct BonitoState BonitoState ; typedef struct PCIBonitoState { PCIDevice dev; + BonitoState *pcihost; uint32_t regs[BONITO_REGS];
@@ -218,7 +221,16 @@ typedef struct PCIBonitoState } PCIBonitoState; -PCIBonitoState * bonito_state; +#define BONITO_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(BonitoState, (obj), TYPE_BONITO_PCI_HOST_BRIDGE) + +struct BonitoState { +PCIHostState parent_obj; + +qemu_irq *pic; + +PCIBonitoState *pci_dev; +};static void bonito_writel (void *opaque,target_phys_addr_t addr,uint64_t val,unsigned size)
@@ -314,9 +326,10 @@ static void bonito_pciconf_writel(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s);DPRINTF ("bonito_pciconf_writel " TARGET_FMT_plx" val %x\n" , addr, val); - s->dev.config_write (&s->dev, addr, val,4 ); + d->config_write (d, addr, val,4 ); } static uint64_t bonito_pciconf_readl(void *opaque, target_phys_addr_t addr,
@@ -324,9 +337,10 @@ static uint64_t bonito_pciconf_readl(void *opaque, target_phys_addr_t addr, {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s);DPRINTF ("bonito_pciconf_readl " TARGET_FMT_plx"\n" , addr); -return s->dev.config_read (&s->dev, addr,4 ); +return d->config_read (d, addr,4 ); }/* north bridge PCI configure space. 0x1fe0 0000 - 0x1fe0 00ff */
@@ -402,6 +416,7 @@ static const MemoryRegionOps bonito_cop_ops = {static uint32_t bonito_sbridge_pciaddr (void *opaque,target_phys_addr_t addr) {PCIBonitoState *s = opaque; +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t cfgaddr;uint32_t idsel;uint32_t devno;
@@ -423,13 +438,13 @@ static uint32_t bonito_sbridge_pciaddr(void *opaque, target_phys_addr_t addr) regno = (cfgaddr &BONITO_PCICONF_REG_MASK ) >>BONITO_PCICONF_REG_OFFSET ;if (idsel ==0 ) { -fprintf (stderr,"error in bonito pci config address" TARGET_FMT_plx +fprintf (stderr,"error in bonito pci config address " TARGET_FMT_plx",pcimap_cfg=%x\n" , addr, s->regs[BONITO_PCIMAP_CFG ]);exit (1 ); } - pciaddr =PCI_ADDR (pci_bus_num (s->pcihost->bus), devno, funno, regno); + pciaddr =PCI_ADDR (pci_bus_num (phb->bus), devno, funno, regno);DPRINTF ("cfgaddr %x pciaddr %x busno %x devno %d funno %d regno %d\n" , - cfgaddr, pciaddr,pci_bus_num (s->pcihost->bus), devno, funno, regno); + cfgaddr, pciaddr,pci_bus_num (phb->bus), devno, funno, regno);return pciaddr; }
@@ -438,6 +453,8 @@ static void bonito_spciconf_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s); +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t pciaddr;uint16_t status;
@@ -449,24 +466,26 @@ static void bonito_spciconf_writeb(void *opaque, target_phys_addr_t addr, }/* set the pci address in s->config_reg */ - s->pcihost->config_reg = (pciaddr) | (1u <<31 ); -pci_data_write (s->pcihost->bus, s->pcihost->config_reg, val &0xff ,1 ); + phb->config_reg = (pciaddr) | (1u <<31 ); +pci_data_write (phb->bus, phb->config_reg, val &0xff ,1 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ - status =pci_get_word (s->dev.config +PCI_STATUS ); + status =pci_get_word (d->config +PCI_STATUS ); status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT ); -pci_set_word (s->dev.config +PCI_STATUS , status); +pci_set_word (d->config +PCI_STATUS , status); }static void bonito_spciconf_writew (void *opaque,target_phys_addr_t addr,uint32_t val) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s); +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t pciaddr;uint16_t status;DPRINTF ("bonito_spciconf_writew " TARGET_FMT_plx" val %x\n" , addr, val); -assert ((addr&0x1 )==0 ); +assert ((addr &0x1 ) ==0 ); pciaddr =bonito_sbridge_pciaddr (s, addr);
@@ -475,24 +494,26 @@ static void bonito_spciconf_writew(void *opaque, target_phys_addr_t addr, }/* set the pci address in s->config_reg */ - s->pcihost->config_reg = (pciaddr) | (1u <<31 ); -pci_data_write (s->pcihost->bus, s->pcihost->config_reg, val,2 ); + phb->config_reg = (pciaddr) | (1u <<31 ); +pci_data_write (phb->bus, phb->config_reg, val,2 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ - status =pci_get_word (s->dev.config +PCI_STATUS ); + status =pci_get_word (d->config +PCI_STATUS ); status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT ); -pci_set_word (s->dev.config +PCI_STATUS , status); +pci_set_word (d->config +PCI_STATUS , status); }static void bonito_spciconf_writel (void *opaque,target_phys_addr_t addr,uint32_t val) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s); +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t pciaddr;uint16_t status;DPRINTF ("bonito_spciconf_writel " TARGET_FMT_plx" val %x\n" , addr, val); -assert ((addr&0x3 )==0 ); +assert ((addr &0x3 ) ==0 ); pciaddr =bonito_sbridge_pciaddr (s, addr);
@@ -501,18 +522,20 @@ static void bonito_spciconf_writel(void *opaque, target_phys_addr_t addr, }/* set the pci address in s->config_reg */ - s->pcihost->config_reg = (pciaddr) | (1u <<31 ); -pci_data_write (s->pcihost->bus, s->pcihost->config_reg, val,4 ); + phb->config_reg = (pciaddr) | (1u <<31 ); +pci_data_write (phb->bus, phb->config_reg, val,4 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ - status =pci_get_word (s->dev.config +PCI_STATUS ); + status =pci_get_word (d->config +PCI_STATUS ); status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT ); -pci_set_word (s->dev.config +PCI_STATUS , status); +pci_set_word (d->config +PCI_STATUS , status); }static uint32_t bonito_spciconf_readb (void *opaque,target_phys_addr_t addr) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s); +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t pciaddr;uint16_t status;
@@ -524,24 +547,26 @@ static uint32_t bonito_spciconf_readb(void *opaque, target_phys_addr_t addr) }/* set the pci address in s->config_reg */ - s->pcihost->config_reg = (pciaddr) | (1u <<31 ); + phb->config_reg = (pciaddr) | (1u <<31 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ - status =pci_get_word (s->dev.config +PCI_STATUS ); + status =pci_get_word (d->config +PCI_STATUS ); status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT ); -pci_set_word (s->dev.config +PCI_STATUS , status); +pci_set_word (d->config +PCI_STATUS , status); -return pci_data_read (s->pcihost->bus, s->pcihost->config_reg,1 ); +return pci_data_read (phb->bus, phb->config_reg,1 ); }static uint32_t bonito_spciconf_readw (void *opaque,target_phys_addr_t addr) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s); +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t pciaddr;uint16_t status;DPRINTF ("bonito_spciconf_readw " TARGET_FMT_plx"\n" , addr); -assert ((addr&0x1 )==0 ); +assert ((addr &0x1 ) ==0 ); pciaddr =bonito_sbridge_pciaddr (s, addr);
@@ -550,24 +575,26 @@ static uint32_t bonito_spciconf_readw(void *opaque, target_phys_addr_t addr) }/* set the pci address in s->config_reg */ - s->pcihost->config_reg = (pciaddr) | (1u <<31 ); + phb->config_reg = (pciaddr) | (1u <<31 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ - status =pci_get_word (s->dev.config +PCI_STATUS ); + status =pci_get_word (d->config +PCI_STATUS ); status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT ); -pci_set_word (s->dev.config +PCI_STATUS , status); +pci_set_word (d->config +PCI_STATUS , status); -return pci_data_read (s->pcihost->bus, s->pcihost->config_reg,2 ); +return pci_data_read (phb->bus, phb->config_reg,2 ); }static uint32_t bonito_spciconf_readl (void *opaque,target_phys_addr_t addr) {PCIBonitoState *s = opaque; +PCIDevice *d =PCI_DEVICE (s); +PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost));uint32_t pciaddr;uint16_t status;DPRINTF ("bonito_spciconf_readl " TARGET_FMT_plx"\n" , addr); -assert ((addr&0x3 ) ==0 ); +assert ((addr &0x3 ) ==0 ); pciaddr =bonito_sbridge_pciaddr (s, addr);
@@ -576,14 +603,14 @@ static uint32_t bonito_spciconf_readl(void *opaque, target_phys_addr_t addr) }/* set the pci address in s->config_reg */ - s->pcihost->config_reg = (pciaddr) | (1u <<31 ); + phb->config_reg = (pciaddr) | (1u <<31 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ - status =pci_get_word (s->dev.config +PCI_STATUS ); + status =pci_get_word (d->config +PCI_STATUS ); status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT ); -pci_set_word (s->dev.config +PCI_STATUS , status); +pci_set_word (d->config +PCI_STATUS , status); -return pci_data_read (s->pcihost->bus, s->pcihost->config_reg,4 ); +return pci_data_read (phb->bus, phb->config_reg,4 ); }/* south bridge PCI configure space. 0x1fe8 0000 - 0x1fef ffff */
@@ -607,13 +634,15 @@ static const MemoryRegionOps bonito_spciconf_ops = {static void pci_bonito_set_irq (void *opaque,int irq_num,int level) { -qemu_irq *pic = opaque; +BonitoState *s = opaque; +qemu_irq *pic = s->pic; +PCIBonitoState *bonito_state = s->pci_dev;int internal_irq = irq_num -BONITO_IRQ_BASE ; -if (bonito_state->regs[BONITO_INTEDGE ] & (1 <<internal_irq)) { +if (bonito_state->regs[BONITO_INTEDGE ] & (1 << internal_irq)) {qemu_irq_pulse (*pic); }else {/* level triggered */ -if (bonito_state->regs[BONITO_INTPOL ] & (1 <<internal_irq)) { +if (bonito_state->regs[BONITO_INTPOL ] & (1 << internal_irq)) {qemu_irq_raise (*pic); }else {qemu_irq_lower (*pic);
@@ -673,13 +702,21 @@ static const VMStateDescription vmstate_bonito = {static int bonito_pcihost_initfn (SysBusDevice *dev) { +PCIHostState *phb =FROM_SYSBUS (PCIHostState, dev); + + phb->bus =pci_register_bus (DEVICE (dev),"pci" , + pci_bonito_set_irq, pci_bonito_map_irq, dev, +get_system_memory (),get_system_io (), +0x28 ,32 ); +return 0 ; }static int bonito_initfn (PCIDevice *dev) {PCIBonitoState *s =DO_UPCAST (PCIBonitoState, dev, dev); -SysBusDevice *sysbus = &s->pcihost->busdev; +SysBusDevice *sysbus =SYS_BUS_DEVICE (s->pcihost); +PCIHostState *phb =FROM_SYSBUS (PCIHostState, sysbus);/* Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are "undefined" */ pci_config_set_prog_interface (dev->config,0x00 );
@@ -691,15 +728,15 @@ static int bonito_initfn(PCIDevice *dev)sysbus_mmio_map (sysbus,0 ,BONITO_INTERNAL_REG_BASE );/* set the north bridge pci configure mapping */ -memory_region_init_io (&s->pcihost->conf_mem, &bonito_pciconf_ops, s, +memory_region_init_io (&phb->conf_mem, &bonito_pciconf_ops, s,"north-bridge-pci-config" ,BONITO_PCICONFIG_SIZE ); -sysbus_init_mmio (sysbus, &s->pcihost->conf_mem); +sysbus_init_mmio (sysbus, &phb->conf_mem);sysbus_mmio_map (sysbus,1 ,BONITO_PCICONFIG_BASE );/* set the south bridge pci configure mapping */ -memory_region_init_io (&s->pcihost->data_mem, &bonito_spciconf_ops, s, +memory_region_init_io (&phb->data_mem, &bonito_spciconf_ops, s,"south-bridge-pci-config" ,BONITO_SPCICONFIG_SIZE ); -sysbus_init_mmio (sysbus, &s->pcihost->data_mem); +sysbus_init_mmio (sysbus, &phb->data_mem);sysbus_mmio_map (sysbus,2 ,BONITO_SPCICONFIG_BASE ); memory_region_init_io(&s->iomem_ldma, &bonito_ldma_ops, s,
@@ -742,28 +779,25 @@ static int bonito_initfn(PCIDevice *dev)PCIBus *bonito_init (qemu_irq *pic) {DeviceState *dev; -PCIBus *b;BonitoState *pcihost; +PCIHostState *phb;PCIBonitoState *s;PCIDevice *d; - dev =qdev_create (NULL ,"Bonito-pcihost" ); - pcihost =FROM_SYSBUS (BonitoState,sysbus_from_qdev (dev)); - b =pci_register_bus (&pcihost->busdev.qdev,"pci" , pci_bonito_set_irq, - pci_bonito_map_irq, pic,get_system_memory (), -get_system_io (), -0x28 ,32 ); - pcihost->bus = b; + dev =qdev_create (NULL ,TYPE_BONITO_PCI_HOST_BRIDGE ); + phb =FROM_SYSBUS (PCIHostState,sysbus_from_qdev (dev)); + pcihost =BONITO_PCI_HOST_BRIDGE (dev); + pcihost->pic = pic;qdev_init_nofail (dev);/* set the pcihost pointer before bonito_initfn is called */ - d =pci_create (b,PCI_DEVFN (0 ,0 ),"Bonito" ); + d =pci_create (phb->bus,PCI_DEVFN (0 ,0 ),"Bonito" ); s =DO_UPCAST (PCIBonitoState, dev, d); s->pcihost = pcihost; - bonito_state = s; -qdev_init_nofail (&d->qdev); + pcihost->pci_dev = s; +qdev_init_nofail (DEVICE (d)); -return b; +return phb->bus; }static void bonito_class_init (ObjectClass *klass,void *data)
@@ -798,7 +832,7 @@ static void bonito_pcihost_class_init(ObjectClass *klass, void *data) }static const TypeInfo bonito_pcihost_info = { - .name ="Bonito-pcihost" , + .name =TYPE_BONITO_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (BonitoState), .class_init = bonito_pcihost_class_init,
Signature · 1 line
1.7.7
PATCH v5 4/14 dec_pci: QOM'ify DEC 21154 PCI-PCI bridge
In reply to Andreas FärberIntroduce type constant. Introduce cast macro and drop dummy busdev field used with FROM_SYSBUS() that would've broken SYS_BUS_DEVICE(). Avoid accessing parent fields directly.
--- hw/dec_pci.c | 21 +++++++++++---------- hw/dec_pci.h | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-)
hw/dec_pci.c +11 -10
@@ -40,8 +40,9 @@#define DEC_DPRINTF (fmt, ...)#endif +#define DEC_21154 (obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154) +typedef struct DECState { -SysBusDevice busdev;PCIHostState host_state; }DECState ;
@@ -88,16 +89,16 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)static int pci_dec_21154_device_init (SysBusDevice *dev) { -DECState *s; +PCIHostState *phb; - s =FROM_SYSBUS (DECState, dev); + phb =FROM_SYSBUS (PCIHostState, dev); -memory_region_init_io (&s->host_state.conf_mem, &pci_host_conf_le_ops, - &s->host_state,"pci-conf-idx" ,0x1000 ); -memory_region_init_io (&s->host_state.data_mem, &pci_host_data_le_ops, - &s->host_state,"pci-data-idx" ,0x1000 ); -sysbus_init_mmio (dev, &s->host_state.conf_mem); -sysbus_init_mmio (dev, &s->host_state.data_mem); +memory_region_init_io (&phb->conf_mem, &pci_host_conf_le_ops, + dev,"pci-conf-idx" ,0x1000 ); +memory_region_init_io (&phb->data_mem, &pci_host_data_le_ops, + dev,"pci-data-idx" ,0x1000 ); +sysbus_init_mmio (dev, &phb->conf_mem); +sysbus_init_mmio (dev, &phb->data_mem);return 0 ; }
@@ -134,7 +135,7 @@ static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data) }static const TypeInfo pci_dec_21154_device_info = { - .name ="dec-21154-sysbus" , + .name =TYPE_DEC_21154 , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (DECState), .class_init = pci_dec_21154_device_class_init,
hw/dec_pci.h +2 -0
@@ -3,6 +3,8 @@#include "qemu-common.h" +#define TYPE_DEC_21154 "dec-21154-sysbus" +PCIBus *pci_dec_21154_init (PCIBus *parent_bus,int devfn);#endif
Signature · 1 line
1.7.7
PATCH v5 5/14 grackle_pci: QOM'ify Grackle PCI host bridge
In reply to Andreas FärberIntroduce type constant. Introduce cast macro to drop dummy busdev field used with FROM_SYSBUS() that would've broken SYS_BUS_DEVICE(). Avoid accessing parent fields directly.
Drop no-op reset function.
--- hw/grackle_pci.c | 57 ++++++++++++++++++++++++++--------------------------- hw/ppc_mac.h | 1 + 2 files changed, 29 insertions(+), 29 deletions(-)
hw/grackle_pci.c +28 -29
@@ -23,10 +23,9 @@* THE SOFTWARE. */ -#include "sysbus.h" +#include "pci_host.h" #include "ppc_mac.h" #include "pci.h" -#include "pci_host.h" /* debug Grackle */ //#define DEBUG_GRACKLE
@@ -38,9 +37,12 @@#define GRACKLE_DPRINTF (fmt, ...)#endif +#define GRACKLE_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(GrackleState, (obj), TYPE_GRACKLE_PCI_HOST_BRIDGE) +typedef struct GrackleState { -SysBusDevice busdev;PCIHostState host_state; +MemoryRegion pci_mmio;MemoryRegion pci_hole; }GrackleState ;
@@ -59,22 +61,20 @@ static void pci_grackle_set_irq(void *opaque, int irq_num, int level)qemu_set_irq (pic[irq_num +0x15 ], level); } -static void pci_grackle_reset (void *opaque) -{ -} -PCIBus *pci_grackle_init (uint32_t base,qemu_irq *pic,MemoryRegion *address_space_mem,MemoryRegion *address_space_io) {DeviceState *dev;SysBusDevice *s; +PCIHostState *phb;GrackleState *d; - dev =qdev_create (NULL ,"grackle-pcihost" ); + dev =qdev_create (NULL ,TYPE_GRACKLE_PCI_HOST_BRIDGE );qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); - d =FROM_SYSBUS (GrackleState, s); + s =SYS_BUS_DEVICE (dev); + phb =FROM_SYSBUS (PCIHostState, s); + d =GRACKLE_PCI_HOST_BRIDGE (dev);memory_region_init (&d->pci_mmio,"pci-mmio" ,0x100000000ULL ); memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
@@ -82,36 +82,35 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,memory_region_add_subregion (address_space_mem,0x80000000ULL , &d->pci_hole); - d->host_state.bus =pci_register_bus (&d->busdev.qdev,"pci" , - pci_grackle_set_irq, - pci_grackle_map_irq, - pic, - &d->pci_mmio, - address_space_io, -0 ,4 ); + phb->bus =pci_register_bus (dev,"pci" , + pci_grackle_set_irq, + pci_grackle_map_irq, + pic, + &d->pci_mmio, + address_space_io, +0 ,4 ); -pci_create_simple (d->host_state.bus,0 ,"grackle" ); +pci_create_simple (phb->bus,0 ,"grackle" );sysbus_mmio_map (s,0 , base);sysbus_mmio_map (s,1 , base +0x00200000 ); -return d->host_state.bus; +return phb->bus; }static int pci_grackle_init_device (SysBusDevice *dev) { -GrackleState *s; +PCIHostState *phb; - s =FROM_SYSBUS (GrackleState, dev); + phb =FROM_SYSBUS (PCIHostState, dev); -memory_region_init_io (&s->host_state.conf_mem, &pci_host_conf_le_ops, - &s->host_state,"pci-conf-idx" ,0x1000 ); -memory_region_init_io (&s->host_state.data_mem, &pci_host_data_le_ops, - &s->host_state,"pci-data-idx" ,0x1000 ); -sysbus_init_mmio (dev, &s->host_state.conf_mem); -sysbus_init_mmio (dev, &s->host_state.data_mem); +memory_region_init_io (&phb->conf_mem, &pci_host_conf_le_ops, + dev,"pci-conf-idx" ,0x1000 ); +memory_region_init_io (&phb->data_mem, &pci_host_data_le_ops, + dev,"pci-data-idx" ,0x1000 ); +sysbus_init_mmio (dev, &phb->conf_mem); +sysbus_init_mmio (dev, &phb->data_mem); -qemu_register_reset (pci_grackle_reset, &s->host_state);return 0 ; }
@@ -151,7 +150,7 @@ static void pci_grackle_class_init(ObjectClass *klass, void *data) }static const TypeInfo grackle_pci_host_info = { - .name ="grackle-pcihost" , + .name =TYPE_GRACKLE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (GrackleState), .class_init = pci_grackle_class_init,
hw/ppc_mac.h +1 -0
@@ -55,6 +55,7 @@ qemu_irq *heathrow_pic_init(MemoryRegion **pmem, int nb_cpus, qemu_irq **irqs);/* Grackle PCI */ +#define TYPE_GRACKLE_PCI_HOST_BRIDGE "grackle-pcihost"PCIBus *pci_grackle_init (uint32_t base,qemu_irq *pic,MemoryRegion *address_space_mem,MemoryRegion *address_space_io);
Signature · 1 line
1.7.7
PATCH v5 6/14 gt64xxx: QOM'ify GT64120 PCI host bridge
In reply to Andreas FärberIntroduce type constant. Introduce cast macro to drop dummy busdev field used with FROM_SYSBUS() macro that would've broken SYS_BUS_DEVICE(). Avoid accessing DeviceState indirectly through PCIHostState.
--- hw/gt64xxx.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-)
hw/gt64xxx.c +20 -15
@@ -229,9 +229,14 @@ target_phys_addr_t regname ##_length; \ MemoryRegion regname ##_mem +#define TYPE_GT64120_PCI_HOST_BRIDGE "gt64120" + +#define GT64120_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(GT64120State, (obj), TYPE_GT64120_PCI_HOST_BRIDGE) + typedef struct GT64120State { - SysBusDevice busdev; PCIHostState pci; + uint32_t regs[GT_REGS]; PCI_MAPPING_ENTRY(PCI0IO); PCI_MAPPING_ENTRY(ISD);
@@ -1083,31 +1088,31 @@ static void gt64120_reset(void *opaque)PCIBus *gt64120_register (qemu_irq *pic) { -SysBusDevice *s;GT64120State *d; +PCIHostState *phb;DeviceState *dev; - dev =qdev_create (NULL ,"gt64120" ); + dev =qdev_create (NULL ,TYPE_GT64120_PCI_HOST_BRIDGE );qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); - d =FROM_SYSBUS (GT64120State, s); - d->pci.bus =pci_register_bus (&d->busdev.qdev,"pci" , - gt64120_pci_set_irq, gt64120_pci_map_irq, - pic, -get_system_memory (), -get_system_io (), -PCI_DEVFN (18 ,0 ),4 ); + d =GT64120_PCI_HOST_BRIDGE (dev); + phb = &d->pci; + phb->bus =pci_register_bus (dev,"pci" , + gt64120_pci_set_irq, gt64120_pci_map_irq, + pic, +get_system_memory (), +get_system_io (), +PCI_DEVFN (18 ,0 ),4 );memory_region_init_io (&d->ISD_mem, &isd_mem_ops, d,"isd-mem" ,0x1000 ); -pci_create_simple (d->pci.bus,PCI_DEVFN (0 ,0 ),"gt64120_pci" ); -return d->pci.bus; +pci_create_simple (phb->bus,PCI_DEVFN (0 ,0 ),"gt64120_pci" ); +return phb->bus; }static int gt64120_init (SysBusDevice *dev) {GT64120State *s; - s =FROM_SYSBUS (GT64120State, dev); + s =GT64120_PCI_HOST_BRIDGE (dev);/* FIXME: This value is computed from registers during reset, but some devices (e.g. VGA card) need to know it when they are registered.
@@ -1162,7 +1167,7 @@ static void gt64120_class_init(ObjectClass *klass, void *data) }static const TypeInfo gt64120_info = { - .name ="gt64120" , + .name =TYPE_GT64120_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (GT64120State), .class_init = gt64120_class_init,
Signature · 1 line
1.7.7
PATCH v5 7/14 ppc4xx_pci: QOM'ify ppc4xx PCI host bridge
In reply to Andreas FärberIntroduce type constant and cast macro. Avoid accessing its parent field directly.
--- hw/ppc440_bamboo.c | 3 ++- hw/ppc4xx.h | 2 ++ hw/ppc4xx_pci.c | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-)
hw/ppc440_bamboo.c +2 -1
@@ -216,7 +216,8 @@ static void bamboo_init(ram_addr_t ram_size, ram_bases, ram_sizes, 1);/* PCI */ - dev =sysbus_create_varargs ("ppc4xx-pcihost" ,PPC440EP_PCI_CONFIG , + dev =sysbus_create_varargs (TYPE_PPC4xx_PCI_HOST_BRIDGE, +PPC440EP_PCI_CONFIG , pic[pci_irq_nrs[0 ]], pic[pci_irq_nrs[1 ]], pic[pci_irq_nrs[2 ]], pic[pci_irq_nrs[3 ]],NULL );
hw/ppc4xx.h +2 -0
@@ -53,6 +53,8 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,target_phys_addr_t *ram_sizes, int do_init); +#define TYPE_PPC4xx_PCI_HOST_BRIDGE "ppc4xx-pcihost" + PCIBus *ppc4xx_pci_init(CPUPPCState *env, qemu_irq pci_irqs[4], target_phys_addr_t config_space, target_phys_addr_t int_ack,
hw/ppc4xx_pci.c +8 -5
@@ -45,6 +45,9 @@ struct PCITargetMap {uint32_t la; }; +#define PPC4xx_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(PPC4xxPCIState, (obj), TYPE_PPC4xx_PCI_HOST_BRIDGE) +#define PPC4xx_PCI_NR_PMMS 3#define PPC4xx_PCI_NR_PTMS 2
@@ -335,17 +338,17 @@ static int ppc4xx_pcihost_initfn(SysBusDevice *dev)PCIBus *b;int i; - h =FROM_SYSBUS (PCIHostState,sysbus_from_qdev (dev)); - s =DO_UPCAST (PPC4xxPCIState, pci_state, h); + h =FROM_SYSBUS (PCIHostState, dev); + s =PPC4xx_PCI_HOST_BRIDGE (dev);for (i =0 ; i <ARRAY_SIZE (s->irq); i++) {sysbus_init_irq (dev, &s->irq[i]); } - b =pci_register_bus (&s->pci_state.busdev.qdev,NULL , ppc4xx_pci_set_irq, + b =pci_register_bus (DEVICE (dev),NULL , ppc4xx_pci_set_irq, ppc4xx_pci_map_irq, s->irq,get_system_memory (),get_system_io (),0 ,4 ); - s->pci_state.bus = b; + h->bus = b;pci_create_simple (b,0 ,"ppc4xx-host-bridge" );
@@ -394,7 +397,7 @@ static void ppc4xx_pcihost_class_init(ObjectClass *klass, void *data) }static const TypeInfo ppc4xx_pcihost_info = { - .name ="ppc4xx-pcihost" , + .name = TYPE_PPC4xx_PCI_HOST_BRIDGE, .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (PPC4xxPCIState), .class_init = ppc4xx_pcihost_class_init,
Signature · 1 line
1.7.7
PATCH v5 8/14 ppce500_pci: QOM'ify e500 PCI host bridge
In reply to Andreas FärberIntroduce type constant and cast macro. Avoid accessing parent fields directly.
--- hw/ppce500_pci.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-)
hw/ppce500_pci.c +11 -5
@@ -72,8 +72,14 @@ struct pci_inbound {uint32_t piwar; }; +#define TYPE_PPC_E500_PCI_HOST_BRIDGE "e500-pcihost" + +#define PPC_E500_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(PPCE500PCIState, (obj), TYPE_PPC_E500_PCI_HOST_BRIDGE) +struct PPCE500PCIState {PCIHostState pci_state; +struct pci_outbound pob[PPCE500_PCI_NR_POBS ];struct pci_inbound pib[PPCE500_PCI_NR_PIBS ];uint32_t gasket_time;
@@ -310,17 +316,17 @@ static int e500_pcihost_initfn(SysBusDevice *dev)MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *address_space_io =get_system_io (); - h =FROM_SYSBUS (PCIHostState,sysbus_from_qdev (dev)); - s =DO_UPCAST (PPCE500PCIState, pci_state, h); + h =FROM_SYSBUS (PCIHostState, dev); + s =PPC_E500_PCI_HOST_BRIDGE (dev);for (i =0 ; i <ARRAY_SIZE (s->irq); i++) {sysbus_init_irq (dev, &s->irq[i]); } - b =pci_register_bus (&s->pci_state.busdev.qdev,NULL , mpc85xx_pci_set_irq, + b =pci_register_bus (DEVICE (dev),NULL , mpc85xx_pci_set_irq, mpc85xx_pci_map_irq, s->irq, address_space_mem, address_space_io,PCI_DEVFN (0x11 ,0 ),4 ); - s->pci_state.bus = b; + h->bus = b;pci_create_simple (b,0 ,"e500-host-bridge" );
@@ -367,7 +373,7 @@ static void e500_pcihost_class_init(ObjectClass *klass, void *data) }static const TypeInfo e500_pcihost_info = { - .name ="e500-pcihost" , + .name =TYPE_PPC_E500_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (PPCE500PCIState), .class_init = e500_pcihost_class_init,
Signature · 1 line
1.7.7
PATCH v5 9/14 prep_pci: QOM'ify Raven PCI host bridge
In reply to Andreas FärberIntroduce type constant and cast macro. Avoid accessing parent fields directly.
Also add missing space and braces.
--- hw/prep_pci.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-)
hw/prep_pci.c +12 -5
@@ -28,8 +28,14 @@#include "pc.h" #include "exec-memory.h" +#define TYPE_RAVEN_PCI_HOST_BRIDGE "raven-pcihost" + +#define RAVEN_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE) +typedef struct PRePPCIState {PCIHostState host_state; +MemoryRegion intack;qemu_irq irq[4 ]; }PREPPCIState ;
@@ -42,9 +48,10 @@ static inline uint32_t PPC_PCIIO_config(target_phys_addr_t addr) {int i; -for (i =0 ; i <11 ; i++) { -if ((addr & (1 << (11 + i))) !=0 ) +for (i =0 ; i <11 ; i++) { +if ((addr & (1 << (11 + i))) !=0 ) {break ; + } }return (addr &0x7ff ) | (i <<11 ); }
@@ -97,7 +104,7 @@ static void prep_set_irq(void *opaque, int irq_num, int level)static int raven_pcihost_init (SysBusDevice *dev) {PCIHostState *h =FROM_SYSBUS (PCIHostState, dev); -PREPPCIState *s =DO_UPCAST (PREPPCIState, host_state, h); +PREPPCIState *s =RAVEN_PCI_HOST_BRIDGE (dev);MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *address_space_io =get_system_io ();PCIBus *bus;
@@ -107,7 +114,7 @@ static int raven_pcihost_init(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq[i]); } - bus =pci_register_bus (&h->busdev.qdev,NULL , + bus =pci_register_bus (DEVICE (dev),NULL , prep_set_irq, prep_map_irq, s->irq, address_space_mem, address_space_io,0 ,4 ); h->bus = bus;
@@ -184,7 +191,7 @@ static void raven_pcihost_class_init(ObjectClass *klass, void *data) }static const TypeInfo raven_pcihost_info = { - .name ="raven-pcihost" , + .name =TYPE_RAVEN_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (PREPPCIState), .class_init = raven_pcihost_class_init,
Signature · 1 line
1.7.7
PATCH v5 10/14 spapr_pci: QOM'ify sPAPR PCI host bridge
In reply to Andreas FärberIntroduce type constant. Introduce cast macro to drop bogus busdev field that would've broken SYS_BUS_DEVICE().
--- hw/spapr_pci.c | 13 +++++++------ hw/spapr_pci.h | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-)
hw/spapr_pci.c +7 -6
@@ -276,7 +276,7 @@ static DMAContext *spapr_pci_dma_context_fn(PCIBus *bus, void *opaque,static int spapr_phb_init (SysBusDevice *s) { -sPAPRPHBState *phb =FROM_SYSBUS (sPAPRPHBState, s); +sPAPRPHBState *phb =SPAPR_PCI_HOST_BRIDGE (s);char *namebuf;int i;PCIBus *bus;
@@ -314,7 +314,7 @@ static int spapr_phb_init(SysBusDevice *s)memory_region_add_subregion (get_system_memory (), phb->io_win_addr, &phb->iowindow); - bus = pci_register_bus(&phb->busdev.qdev, + bus = pci_register_bus(DEVICE(s), phb->busname ? phb->busname : phb->dtbusname, pci_spapr_set_irq, pci_spapr_map_irq, phb, &phb->memspace, &phb->iospace,
@@ -369,7 +369,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data) }static const TypeInfo spapr_phb_info = { - .name ="spapr-pci-host-bridge" , + .name =TYPE_SPAPR_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (sPAPRPHBState), .class_init = spapr_phb_class_init,
@@ -382,7 +382,7 @@ void spapr_create_phb(sPAPREnvironment *spapr, {DeviceState *dev; - dev =qdev_create (NULL , spapr_phb_info.name); + dev =qdev_create (NULL ,TYPE_SPAPR_PCI_HOST_BRIDGE );if (busname) {qdev_prop_set_string (dev,"busname" ,g_strdup (busname));
@@ -490,8 +490,9 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,return 0 ; } -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)
hw/spapr_pci.h +5 -1
@@ -27,8 +27,12 @@#include "hw/pci_host.h" #include "hw/xics.h" +#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 { - SysBusDevice busdev; PCIHostState host_state; uint64_t buid;
Signature · 1 line
1.7.7
PATCH v5 11/14 unin_pci: QOM'ify UniNorth PCI host bridges
In reply to Andreas FärberIntroduce type constants and cast macros.
Avoid accessing parent fields directly.
--- hw/unin_pci.c | 133 ++++++++++++++++++++++++++++++--------------------------- 1 files changed, 70 insertions(+), 63 deletions(-)
hw/unin_pci.c +70 -63
@@ -38,8 +38,23 @@static const int unin_irq_line[] = {0x1b ,0x1c ,0x1d ,0x1e }; +#define TYPE_UNI_NORTH_PCI_HOST_BRIDGE "uni-north-pci-pcihost" +#define TYPE_UNI_NORTH_AGP_HOST_BRIDGE "uni-north-agp-pcihost" +#define TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE "uni-north-internal-pci-pcihost" +#define TYPE_U3_AGP_HOST_BRIDGE "u3-agp-pcihost" + +#define UNI_NORTH_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_PCI_HOST_BRIDGE) +#define UNI_NORTH_AGP_HOST_BRIDGE (obj) \ + OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_AGP_HOST_BRIDGE) +#define UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE) +#define U3_AGP_HOST_BRIDGE (obj) \ + OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE) +typedef struct UNINState {PCIHostState host_state; +MemoryRegion pci_mmio;MemoryRegion pci_hole; }UNINState ;
@@ -130,19 +145,17 @@ static const MemoryRegionOps unin_data_ops = {static int pci_unin_main_init_device (SysBusDevice *dev) {PCIHostState *h; -UNINState *s;/* Use values found on a real PowerMac */ /* Uninorth main bus */ h =FROM_SYSBUS (PCIHostState, dev); - s =DO_UPCAST (UNINState, host_state, h); -memory_region_init_io (&s->host_state.conf_mem, &pci_host_conf_le_ops, - &s->host_state,"pci-conf-idx" ,0x1000 ); -memory_region_init_io (&s->host_state.data_mem, &unin_data_ops, s, +memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, + dev,"pci-conf-idx" ,0x1000 ); +memory_region_init_io (&h->data_mem, &unin_data_ops, dev,"pci-conf-data" ,0x1000 ); -sysbus_init_mmio (dev, &s->host_state.conf_mem); -sysbus_init_mmio (dev, &s->host_state.data_mem); +sysbus_init_mmio (dev, &h->conf_mem); +sysbus_init_mmio (dev, &h->data_mem);return 0 ; }
@@ -151,18 +164,16 @@ static int pci_unin_main_init_device(SysBusDevice *dev)static int pci_u3_agp_init_device (SysBusDevice *dev) {PCIHostState *h; -UNINState *s;/* Uninorth U3 AGP bus */ h =FROM_SYSBUS (PCIHostState, dev); - s =DO_UPCAST (UNINState, host_state, h); -memory_region_init_io (&s->host_state.conf_mem, &pci_host_conf_le_ops, - &s->host_state,"pci-conf-idx" ,0x1000 ); -memory_region_init_io (&s->host_state.data_mem, &unin_data_ops, s, +memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, + dev,"pci-conf-idx" ,0x1000 ); +memory_region_init_io (&h->data_mem, &unin_data_ops, dev,"pci-conf-data" ,0x1000 ); -sysbus_init_mmio (dev, &s->host_state.conf_mem); -sysbus_init_mmio (dev, &s->host_state.data_mem); +sysbus_init_mmio (dev, &h->conf_mem); +sysbus_init_mmio (dev, &h->data_mem);return 0 ; }
@@ -170,36 +181,32 @@ static int pci_u3_agp_init_device(SysBusDevice *dev)static int pci_unin_agp_init_device (SysBusDevice *dev) {PCIHostState *h; -UNINState *s;/* Uninorth AGP bus */ h =FROM_SYSBUS (PCIHostState, dev); - s =DO_UPCAST (UNINState, host_state, h); -memory_region_init_io (&s->host_state.conf_mem, &pci_host_conf_le_ops, - &s->host_state,"pci-conf-idx" ,0x1000 ); -memory_region_init_io (&s->host_state.data_mem, &pci_host_data_le_ops, - &s->host_state,"pci-conf-data" ,0x1000 ); -sysbus_init_mmio (dev, &s->host_state.conf_mem); -sysbus_init_mmio (dev, &s->host_state.data_mem); +memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, + dev,"pci-conf-idx" ,0x1000 ); +memory_region_init_io (&h->data_mem, &pci_host_data_le_ops, + dev,"pci-conf-data" ,0x1000 ); +sysbus_init_mmio (dev, &h->conf_mem); +sysbus_init_mmio (dev, &h->data_mem);return 0 ; }static int pci_unin_internal_init_device (SysBusDevice *dev) {PCIHostState *h; -UNINState *s;/* Uninorth internal bus */ h =FROM_SYSBUS (PCIHostState, dev); - s =DO_UPCAST (UNINState, host_state, h); -memory_region_init_io (&s->host_state.conf_mem, &pci_host_conf_le_ops, - &s->host_state,"pci-conf-idx" ,0x1000 ); -memory_region_init_io (&s->host_state.data_mem, &pci_host_data_le_ops, - &s->host_state,"pci-conf-data" ,0x1000 ); -sysbus_init_mmio (dev, &s->host_state.conf_mem); -sysbus_init_mmio (dev, &s->host_state.data_mem); +memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, + dev,"pci-conf-idx" ,0x1000 ); +memory_region_init_io (&h->data_mem, &pci_host_data_le_ops, + dev,"pci-conf-data" ,0x1000 ); +sysbus_init_mmio (dev, &h->conf_mem); +sysbus_init_mmio (dev, &h->data_mem);return 0 ; }
@@ -214,26 +221,26 @@ PCIBus *pci_pmac_init(qemu_irq *pic,/* Use values found on a real PowerMac */ /* Uninorth main bus */ - dev =qdev_create (NULL ,"uni-north-pci-pcihost" ); + dev =qdev_create (NULL ,TYPE_UNI_NORTH_PCI_HOST_BRIDGE );qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); + s =SYS_BUS_DEVICE (dev); h =FROM_SYSBUS (PCIHostState, s); - d =DO_UPCAST (UNINState, host_state, h); + d =UNI_NORTH_PCI_HOST_BRIDGE (dev);memory_region_init (&d->pci_mmio,"pci-mmio" ,0x100000000ULL );memory_region_init_alias (&d->pci_hole,"pci-hole" , &d->pci_mmio,0x80000000ULL ,0x70000000ULL );memory_region_add_subregion (address_space_mem,0x80000000ULL , &d->pci_hole); - d->host_state.bus =pci_register_bus (dev,"pci" , - pci_unin_set_irq, pci_unin_map_irq, - pic, - &d->pci_mmio, - address_space_io, -PCI_DEVFN (11 ,0 ),4 ); + h->bus =pci_register_bus (dev,"pci" , + pci_unin_set_irq, pci_unin_map_irq, + pic, + &d->pci_mmio, + address_space_io, +PCI_DEVFN (11 ,0 ),4 );#if 0 -pci_create_simple (d->host_state.bus,PCI_DEVFN (11 ,0 ),"uni-north" ); +pci_create_simple (h->bus,PCI_DEVFN (11 ,0 ),"uni-north" );#endif sysbus_mmio_map (s,0 ,0xf2800000 );
@@ -242,30 +249,30 @@ PCIBus *pci_pmac_init(qemu_irq *pic,/* DEC 21154 bridge */ #if 0 /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */ -pci_create_simple (d->host_state.bus,PCI_DEVFN (12 ,0 ),"dec-21154" ); +pci_create_simple (h->bus,PCI_DEVFN (12 ,0 ),"dec-21154" );#endif /* Uninorth AGP bus */ -pci_create_simple (d->host_state.bus,PCI_DEVFN (11 ,0 ),"uni-north-agp" ); - dev =qdev_create (NULL ,"uni-north-agp-pcihost" ); +pci_create_simple (h->bus,PCI_DEVFN (11 ,0 ),"uni-north-agp" ); + dev =qdev_create (NULL ,TYPE_UNI_NORTH_AGP_HOST_BRIDGE );qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); + s =SYS_BUS_DEVICE (dev);sysbus_mmio_map (s,0 ,0xf0800000 );sysbus_mmio_map (s,1 ,0xf0c00000 );/* Uninorth internal bus */ #if 0 /* XXX: not needed for now */ -pci_create_simple (d->host_state.bus,PCI_DEVFN (14 ,0 ), +pci_create_simple (h->bus,PCI_DEVFN (14 ,0 ),"uni-north-internal-pci" ); - dev =qdev_create (NULL ,"uni-north-internal-pci-pcihost" ); + dev =qdev_create (NULL ,TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE );qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); + s =SYS_BUS_DEVICE (dev);sysbus_mmio_map (s,0 ,0xf4800000 );sysbus_mmio_map (s,1 ,0xf4c00000 );#endif -return d->host_state.bus; +return h->bus; } PCIBus *pci_pmac_u3_init(qemu_irq *pic,
@@ -279,11 +286,11 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,/* Uninorth AGP bus */ - dev =qdev_create (NULL ,"u3-agp-pcihost" ); + dev =qdev_create (NULL ,TYPE_U3_AGP_HOST_BRIDGE );qdev_init_nofail (dev); - s =sysbus_from_qdev (dev); + s =SYS_BUS_DEVICE (dev); h =FROM_SYSBUS (PCIHostState, s); - d =DO_UPCAST (UNINState, host_state, h); + d =U3_AGP_HOST_BRIDGE (dev);memory_region_init (&d->pci_mmio,"pci-mmio" ,0x100000000ULL ); memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
@@ -291,19 +298,19 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic,memory_region_add_subregion (address_space_mem,0x80000000ULL , &d->pci_hole); - d->host_state.bus =pci_register_bus (dev,"pci" , - pci_unin_set_irq, pci_unin_map_irq, - pic, - &d->pci_mmio, - address_space_io, -PCI_DEVFN (11 ,0 ),4 ); + h->bus =pci_register_bus (dev,"pci" , + pci_unin_set_irq, pci_unin_map_irq, + pic, + &d->pci_mmio, + address_space_io, +PCI_DEVFN (11 ,0 ),4 );sysbus_mmio_map (s,0 ,0xf0800000 );sysbus_mmio_map (s,1 ,0xf0c00000 ); -pci_create_simple (d->host_state.bus,11 <<3 ,"u3-agp" ); +pci_create_simple (h->bus,11 <<3 ,"u3-agp" ); -return d->host_state.bus; +return h->bus; }static int unin_main_pci_host_init (PCIDevice *d)
@@ -419,7 +426,7 @@ static void pci_unin_main_class_init(ObjectClass *klass, void *data) }static const TypeInfo pci_unin_main_info = { - .name ="uni-north-pci-pcihost" , + .name =TYPE_UNI_NORTH_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState), .class_init = pci_unin_main_class_init,
@@ -433,7 +440,7 @@ static void pci_u3_agp_class_init(ObjectClass *klass, void *data) }static const TypeInfo pci_u3_agp_info = { - .name ="u3-agp-pcihost" , + .name =TYPE_U3_AGP_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState), .class_init = pci_u3_agp_class_init,
@@ -447,7 +454,7 @@ static void pci_unin_agp_class_init(ObjectClass *klass, void *data) }static const TypeInfo pci_unin_agp_info = { - .name ="uni-north-agp-pcihost" , + .name =TYPE_UNI_NORTH_AGP_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState), .class_init = pci_unin_agp_class_init,
@@ -461,7 +468,7 @@ static void pci_unin_internal_class_init(ObjectClass *klass, void *data) }static const TypeInfo pci_unin_internal_info = { - .name ="uni-north-internal-pci-pcihost" , + .name =TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (UNINState), .class_init = pci_unin_internal_class_init,
Signature · 1 line
1.7.7
PATCH v5 12/14 pci_host: Turn into SysBus-derived QOM type
In reply to Andreas FärberFrom: Andreas Färber <[email protected]>
The preceding commits fixed misuses of FROM_SYSBUS() that led people to add a bogus busdev field. For qdev the field order was less relevant but for QOM the PCIHostState field (including the SysBusDevice actually initialized with a value) must be placed first within the state struct.
To facilitate accessing the PCIHostState fields, derive all PCI host bridges from TYPE_PCI_HOST_BRIDGE rather than TYPE_SYS_BUS_DEVICE.
We can now access PCIHostState QOM-style, with PCI_HOST_BRIDGE() macro.
--- hw/pci_host.c | 12 ++++++++++++ hw/pci_host.h | 5 +++++ 2 files changed, 17 insertions(+), 0 deletions(-)
hw/pci_host.c +12 -0
@@ -165,4 +165,16 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_host_type_info = { + .name =TYPE_PCI_HOST_BRIDGE , + .parent =TYPE_SYS_BUS_DEVICE , + .abstract = true, + .instance_size =sizeof (PCIHostState), +}; + +static void pci_host_register_types (void ) +{ +type_register_static (&pci_host_type_info); +} +type_init (pci_host_register_types)
hw/pci_host.h +5 -0
@@ -30,8 +30,13 @@#include "sysbus.h" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge" +#define PCI_HOST_BRIDGE (obj) \ + OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE) +struct PCIHostState {SysBusDevice busdev; +MemoryRegion conf_mem;MemoryRegion data_mem;MemoryRegion mmcfg;
Signature · 1 line
1.7.7
PATCH v5 13/14 pci: Derive PCI host bridges from TYPE_PCI_HOST_BRIDGE
In reply to Andreas FärberSome typedef'ed their state to PCIHostState. Use a proper struct, and use PCIHostState and PCI_HOST_BRIDGE() where appropriate.
--- hw/alpha_typhoon.c | 4 ++-- hw/bonito.c | 22 +++++++++++----------- hw/dec_pci.c | 4 ++-- hw/grackle_pci.c | 6 +++--- hw/gt64xxx.c | 4 ++-- hw/piix_pci.c | 8 ++++---- hw/ppc4xx_pci.c | 4 ++-- hw/ppc_prep.c | 4 +--- hw/ppce500_pci.c | 4 ++-- hw/prep_pci.c | 4 ++-- hw/spapr_pci.c | 2 +- hw/unin_pci.c | 20 ++++++++++---------- 12 files changed, 42 insertions(+), 44 deletions(-)
hw/alpha_typhoon.c +2 -2
@@ -715,7 +715,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,qdev_init_nofail (dev); s =TYPHOON_PCI_HOST_BRIDGE (dev); - phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (dev)); + phb =PCI_HOST_BRIDGE (dev);/* Remember the CPUs so that we can deliver interrupts to them. */ for (i =0 ; i <4 ; i++) {
@@ -825,7 +825,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)static const TypeInfo typhoon_pcihost_info = { .name =TYPE_TYPHOON_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (TyphoonState), .class_init = typhoon_pcihost_class_init, };
hw/bonito.c +11 -11
@@ -416,7 +416,7 @@ static const MemoryRegionOps bonito_cop_ops = {static uint32_t bonito_sbridge_pciaddr (void *opaque,target_phys_addr_t addr) {PCIBonitoState *s = opaque; -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t cfgaddr;uint32_t idsel;uint32_t devno;
@@ -454,7 +454,7 @@ static void bonito_spciconf_writeb(void *opaque, target_phys_addr_t addr, {PCIBonitoState *s = opaque;PCIDevice *d =PCI_DEVICE (s); -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t pciaddr;uint16_t status;
@@ -480,7 +480,7 @@ static void bonito_spciconf_writew(void *opaque, target_phys_addr_t addr, {PCIBonitoState *s = opaque;PCIDevice *d =PCI_DEVICE (s); -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t pciaddr;uint16_t status;
@@ -508,7 +508,7 @@ static void bonito_spciconf_writel(void *opaque, target_phys_addr_t addr, {PCIBonitoState *s = opaque;PCIDevice *d =PCI_DEVICE (s); -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t pciaddr;uint16_t status;
@@ -535,7 +535,7 @@ static uint32_t bonito_spciconf_readb(void *opaque, target_phys_addr_t addr) {PCIBonitoState *s = opaque;PCIDevice *d =PCI_DEVICE (s); -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t pciaddr;uint16_t status;
@@ -561,7 +561,7 @@ static uint32_t bonito_spciconf_readw(void *opaque, target_phys_addr_t addr) {PCIBonitoState *s = opaque;PCIDevice *d =PCI_DEVICE (s); -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t pciaddr;uint16_t status;
@@ -589,7 +589,7 @@ static uint32_t bonito_spciconf_readl(void *opaque, target_phys_addr_t addr) {PCIBonitoState *s = opaque;PCIDevice *d =PCI_DEVICE (s); -PCIHostState *phb =FROM_SYSBUS (PCIHostState,SYS_BUS_DEVICE (s->pcihost)); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);uint32_t pciaddr;uint16_t status;
@@ -702,7 +702,7 @@ static const VMStateDescription vmstate_bonito = {static int bonito_pcihost_initfn (SysBusDevice *dev) { -PCIHostState *phb =FROM_SYSBUS (PCIHostState, dev); +PCIHostState *phb =PCI_HOST_BRIDGE (dev); phb->bus = pci_register_bus(DEVICE(dev), "pci", pci_bonito_set_irq, pci_bonito_map_irq, dev,
@@ -716,7 +716,7 @@ static int bonito_initfn(PCIDevice *dev) {PCIBonitoState *s =DO_UPCAST (PCIBonitoState, dev, dev);SysBusDevice *sysbus =SYS_BUS_DEVICE (s->pcihost); -PCIHostState *phb =FROM_SYSBUS (PCIHostState, sysbus); +PCIHostState *phb =PCI_HOST_BRIDGE (s->pcihost);/* Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are "undefined" */ pci_config_set_prog_interface (dev->config,0x00 );
@@ -785,7 +785,7 @@ PCIBus *bonito_init(qemu_irq *pic)PCIDevice *d; dev =qdev_create (NULL ,TYPE_BONITO_PCI_HOST_BRIDGE ); - phb =FROM_SYSBUS (PCIHostState,sysbus_from_qdev (dev)); + phb =PCI_HOST_BRIDGE (dev); pcihost =BONITO_PCI_HOST_BRIDGE (dev); pcihost->pic = pic;qdev_init_nofail (dev);
@@ -833,7 +833,7 @@ static void bonito_pcihost_class_init(ObjectClass *klass, void *data)static const TypeInfo bonito_pcihost_info = { .name =TYPE_BONITO_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (BonitoState), .class_init = bonito_pcihost_class_init, };
hw/dec_pci.c +2 -2
@@ -91,7 +91,7 @@ static int pci_dec_21154_device_init(SysBusDevice *dev) {PCIHostState *phb; - phb =FROM_SYSBUS (PCIHostState, dev); + phb =PCI_HOST_BRIDGE (dev);memory_region_init_io (&phb->conf_mem, &pci_host_conf_le_ops, dev,"pci-conf-idx" ,0x1000 );
@@ -136,7 +136,7 @@ static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)static const TypeInfo pci_dec_21154_device_info = { .name =TYPE_DEC_21154 , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (DECState), .class_init = pci_dec_21154_device_class_init, };
hw/grackle_pci.c +3 -3
@@ -73,7 +73,7 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic, dev =qdev_create (NULL ,TYPE_GRACKLE_PCI_HOST_BRIDGE );qdev_init_nofail (dev); s =SYS_BUS_DEVICE (dev); - phb =FROM_SYSBUS (PCIHostState, s); + phb =PCI_HOST_BRIDGE (dev); d =GRACKLE_PCI_HOST_BRIDGE (dev);memory_region_init (&d->pci_mmio,"pci-mmio" ,0x100000000ULL );
@@ -102,7 +102,7 @@ static int pci_grackle_init_device(SysBusDevice *dev) {PCIHostState *phb; - phb =FROM_SYSBUS (PCIHostState, dev); + phb =PCI_HOST_BRIDGE (dev);memory_region_init_io (&phb->conf_mem, &pci_host_conf_le_ops, dev,"pci-conf-idx" ,0x1000 );
@@ -151,7 +151,7 @@ static void pci_grackle_class_init(ObjectClass *klass, void *data)static const TypeInfo grackle_pci_host_info = { .name =TYPE_GRACKLE_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (GrackleState), .class_init = pci_grackle_class_init, };
hw/gt64xxx.c +2 -2
@@ -1095,7 +1095,7 @@ PCIBus *gt64120_register(qemu_irq *pic) dev =qdev_create (NULL ,TYPE_GT64120_PCI_HOST_BRIDGE );qdev_init_nofail (dev); d =GT64120_PCI_HOST_BRIDGE (dev); - phb = &d->pci; + phb =PCI_HOST_BRIDGE (dev); phb->bus = pci_register_bus(dev, "pci", gt64120_pci_set_irq, gt64120_pci_map_irq, pic,
@@ -1168,7 +1168,7 @@ static void gt64120_class_init(ObjectClass *klass, void *data)static const TypeInfo gt64120_info = { .name =TYPE_GT64120_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (GT64120State), .class_init = gt64120_class_init, };
hw/piix_pci.c +4 -4
@@ -225,7 +225,7 @@ static const VMStateDescription vmstate_i440fx = {static int i440fx_pcihost_initfn (SysBusDevice *dev) { -I440FXState *s =FROM_SYSBUS (I440FXState, dev); +PCIHostState *s =PCI_HOST_BRIDGE (dev);memory_region_init_io (&s->conf_mem, &pci_host_conf_le_ops, s,"pci-conf-idx" ,4 );
@@ -267,12 +267,12 @@ static PCIBus *i440fx_common_init(const char *device_name,DeviceState *dev;PCIBus *b;PCIDevice *d; -I440FXState *s; +PCIHostState *s;PIIX3State *piix3;PCII440FXState *f; dev =qdev_create (NULL ,"i440FX-pcihost" ); - s =FROM_SYSBUS (I440FXState,sysbus_from_qdev (dev)); + s =PCI_HOST_BRIDGE (dev); s->address_space = address_space_mem; b =pci_bus_new (&s->busdev.qdev,NULL , pci_address_space, address_space_io,0 );
@@ -603,7 +603,7 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)static const TypeInfo i440fx_pcihost_info = { .name ="i440FX-pcihost" , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (I440FXState), .class_init = i440fx_pcihost_class_init, };
hw/ppc4xx_pci.c +2 -2
@@ -338,7 +338,7 @@ static int ppc4xx_pcihost_initfn(SysBusDevice *dev)PCIBus *b;int i; - h =FROM_SYSBUS (PCIHostState, dev); + h =PCI_HOST_BRIDGE (dev); s =PPC4xx_PCI_HOST_BRIDGE (dev);for (i =0 ; i <ARRAY_SIZE (s->irq); i++) {
@@ -398,7 +398,7 @@ static void ppc4xx_pcihost_class_init(ObjectClass *klass, void *data)static const TypeInfo ppc4xx_pcihost_info = { .name = TYPE_PPC4xx_PCI_HOST_BRIDGE, - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (PPC4xxPCIState), .class_init = ppc4xx_pcihost_class_init, };
hw/ppc_prep.c +1 -3
@@ -470,7 +470,6 @@ static void ppc_prep_init (ram_addr_t ram_size,uint32_t kernel_base, initrd_base;long kernel_size, initrd_size;DeviceState *dev; -SysBusDevice *sys;PCIHostState *pcihost;PCIBus *pci_bus;PCIDevice *pci;
@@ -583,8 +582,7 @@ static void ppc_prep_init (ram_addr_t ram_size, } dev =qdev_create (NULL ,"raven-pcihost" ); - sys =sysbus_from_qdev (dev); - pcihost =DO_UPCAST (PCIHostState, busdev, sys); + pcihost =PCI_HOST_BRIDGE (dev); pcihost->address_space =get_system_memory ();object_property_add_child (qdev_get_machine (),"raven" ,OBJECT (dev),NULL );qdev_init_nofail (dev);
hw/ppce500_pci.c +2 -2
@@ -316,7 +316,7 @@ static int e500_pcihost_initfn(SysBusDevice *dev)MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *address_space_io =get_system_io (); - h =FROM_SYSBUS (PCIHostState, dev); + h =PCI_HOST_BRIDGE (dev); s =PPC_E500_PCI_HOST_BRIDGE (dev);for (i =0 ; i <ARRAY_SIZE (s->irq); i++) {
@@ -374,7 +374,7 @@ static void e500_pcihost_class_init(ObjectClass *klass, void *data)static const TypeInfo e500_pcihost_info = { .name =TYPE_PPC_E500_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (PPCE500PCIState), .class_init = e500_pcihost_class_init, };
hw/prep_pci.c +2 -2
@@ -103,7 +103,7 @@ static void prep_set_irq(void *opaque, int irq_num, int level)static int raven_pcihost_init (SysBusDevice *dev) { -PCIHostState *h =FROM_SYSBUS (PCIHostState, dev); +PCIHostState *h =PCI_HOST_BRIDGE (dev);PREPPCIState *s =RAVEN_PCI_HOST_BRIDGE (dev);MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *address_space_io =get_system_io ();
@@ -192,7 +192,7 @@ static void raven_pcihost_class_init(ObjectClass *klass, void *data)static const TypeInfo raven_pcihost_info = { .name =TYPE_RAVEN_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (PREPPCIState), .class_init = raven_pcihost_class_init, };
hw/spapr_pci.c +1 -1
@@ -370,7 +370,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)static const TypeInfo spapr_phb_info = { .name =TYPE_SPAPR_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (sPAPRPHBState), .class_init = spapr_phb_class_init, };
hw/unin_pci.c +10 -10
@@ -148,7 +148,7 @@ static int pci_unin_main_init_device(SysBusDevice *dev)/* Use values found on a real PowerMac */ /* Uninorth main bus */ - h =FROM_SYSBUS (PCIHostState, dev); + h =PCI_HOST_BRIDGE (dev);memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, dev,"pci-conf-idx" ,0x1000 );
@@ -166,7 +166,7 @@ static int pci_u3_agp_init_device(SysBusDevice *dev)PCIHostState *h;/* Uninorth U3 AGP bus */ - h =FROM_SYSBUS (PCIHostState, dev); + h =PCI_HOST_BRIDGE (dev);memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, dev,"pci-conf-idx" ,0x1000 );
@@ -183,7 +183,7 @@ static int pci_unin_agp_init_device(SysBusDevice *dev)PCIHostState *h;/* Uninorth AGP bus */ - h =FROM_SYSBUS (PCIHostState, dev); + h =PCI_HOST_BRIDGE (dev);memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, dev,"pci-conf-idx" ,0x1000 );
@@ -199,7 +199,7 @@ static int pci_unin_internal_init_device(SysBusDevice *dev)PCIHostState *h;/* Uninorth internal bus */ - h =FROM_SYSBUS (PCIHostState, dev); + h =PCI_HOST_BRIDGE (dev);memory_region_init_io (&h->conf_mem, &pci_host_conf_le_ops, dev,"pci-conf-idx" ,0x1000 );
@@ -224,7 +224,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic, dev =qdev_create (NULL ,TYPE_UNI_NORTH_PCI_HOST_BRIDGE );qdev_init_nofail (dev); s =SYS_BUS_DEVICE (dev); - h =FROM_SYSBUS (PCIHostState, s); + h =PCI_HOST_BRIDGE (s); d =UNI_NORTH_PCI_HOST_BRIDGE (dev);memory_region_init (&d->pci_mmio,"pci-mmio" ,0x100000000ULL ); memory_region_init_alias(&d->pci_hole, "pci-hole", &d->pci_mmio,
@@ -289,7 +289,7 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic, dev =qdev_create (NULL ,TYPE_U3_AGP_HOST_BRIDGE );qdev_init_nofail (dev); s =SYS_BUS_DEVICE (dev); - h =FROM_SYSBUS (PCIHostState, s); + h =PCI_HOST_BRIDGE (dev); d =U3_AGP_HOST_BRIDGE (dev);memory_region_init (&d->pci_mmio,"pci-mmio" ,0x100000000ULL );
@@ -427,7 +427,7 @@ static void pci_unin_main_class_init(ObjectClass *klass, void *data)static const TypeInfo pci_unin_main_info = { .name =TYPE_UNI_NORTH_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (UNINState), .class_init = pci_unin_main_class_init, };
@@ -441,7 +441,7 @@ static void pci_u3_agp_class_init(ObjectClass *klass, void *data)static const TypeInfo pci_u3_agp_info = { .name =TYPE_U3_AGP_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (UNINState), .class_init = pci_u3_agp_class_init, };
@@ -455,7 +455,7 @@ static void pci_unin_agp_class_init(ObjectClass *klass, void *data)static const TypeInfo pci_unin_agp_info = { .name =TYPE_UNI_NORTH_AGP_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (UNINState), .class_init = pci_unin_agp_class_init, };
@@ -469,7 +469,7 @@ static void pci_unin_internal_class_init(ObjectClass *klass, void *data)static const TypeInfo pci_unin_internal_info = { .name =TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE , - .parent =TYPE_SYS_BUS_DEVICE , + .parent =TYPE_PCI_HOST_BRIDGE , .instance_size =sizeof (UNINState), .class_init = pci_unin_internal_class_init, };
Signature · 1 line
1.7.7
PATCH v5 14/14 pci: Tidy up PCI host bridges
In reply to Andreas FärberUglify the parent field to enforce QOM-style access via casts. Don't just typedef PCIHostState, either use it directly or embed it.
--- hw/alpha_typhoon.c | 2 +- hw/dec_pci.c | 2 +- hw/grackle_pci.c | 2 +- hw/gt64xxx.c | 26 ++++++++++++++++---------- hw/piix_pci.c | 6 ++++-- hw/ppc4xx_pci.c | 8 +++++--- hw/ppce500_pci.c | 2 +- hw/prep_pci.c | 8 +++++--- hw/spapr_pci.c | 12 +++++++----- hw/spapr_pci.h | 2 +- hw/unin_pci.c | 14 +++++++------- 11 files changed, 49 insertions(+), 35 deletions(-)
hw/alpha_typhoon.c +1 -1
@@ -46,7 +46,7 @@ typedef struct TyphoonPchip { OBJECT_CHECK(TyphoonState, (obj), TYPE_TYPHOON_PCI_HOST_BRIDGE) typedef struct TyphoonState { - PCIHostState host; + PCIHostState parent_obj; TyphoonCchip cchip; TyphoonPchip pchip;
hw/dec_pci.c +1 -1
@@ -43,7 +43,7 @@#define DEC_21154 (obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)typedef struct DECState { -PCIHostState host_state; +PCIHostState parent_obj; }DECState ;static int dec_map_irq (PCIDevice *pci_dev,int irq_num)
hw/grackle_pci.c +1 -1
@@ -41,7 +41,7 @@ OBJECT_CHECK(GrackleState, (obj), TYPE_GRACKLE_PCI_HOST_BRIDGE) typedef struct GrackleState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole;
hw/gt64xxx.c +16 -10
@@ -235,7 +235,7 @@ OBJECT_CHECK(GT64120State, (obj), TYPE_GT64120_PCI_HOST_BRIDGE) typedef struct GT64120State { - PCIHostState pci; + PCIHostState parent_obj; uint32_t regs[GT_REGS]; PCI_MAPPING_ENTRY(PCI0IO);
@@ -315,6 +315,7 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) {GT64120State *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (s);uint32_t saddr;if (!(s->regs[GT_CPU ] &0x00001000 ))
@@ -535,13 +536,15 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr,/* not implemented */ break ;case GT_PCI0_CFGADDR : - s->pci.config_reg = val &0x80fffffc ; + phb->config_reg = val &0x80fffffc ;break ;case GT_PCI0_CFGDATA : -if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci.config_reg &0x00fff800 )) +if (!(s->regs[GT_PCI0_CMD ] &1 ) && (phb->config_reg &0x00fff800 )) { val =bswap32 (val); -if (s->pci.config_reg & (1u <<31 )) -pci_data_write (s->pci.bus, s->pci.config_reg, val,4 ); + } +if (phb->config_reg & (1u <<31 )) { +pci_data_write (phb->bus, phb->config_reg, val,4 ); + }break ;/* Interrupts */
@@ -594,6 +597,7 @@ static uint64_t gt64120_readl (void *opaque, target_phys_addr_t addr, unsigned size) {GT64120State *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (s);uint32_t val;uint32_t saddr;
@@ -775,15 +779,17 @@ static uint64_t gt64120_readl (void *opaque,/* PCI Internal */ case GT_PCI0_CFGADDR : - val = s->pci.config_reg; + val = phb->config_reg;break ;case GT_PCI0_CFGDATA : -if (!(s->pci.config_reg & (1 <<31 ))) +if (!(phb->config_reg & (1 <<31 ))) { val =0xffffffff ; -else - val =pci_data_read (s->pci.bus, s->pci.config_reg,4 ); -if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci.config_reg &0x00fff800 )) + }else { + val =pci_data_read (phb->bus, phb->config_reg,4 ); + } +if (!(s->regs[GT_PCI0_CMD ] &1 ) && (phb->config_reg &0x00fff800 )) { val =bswap32 (val); + }break ;case GT_PCI0_CMD :
hw/piix_pci.c +4 -2
@@ -36,7 +36,9 @@* http://download.intel.com/design/chipsets/datashts/29054901.pdf */ -typedef PCIHostState I440FXState ; +typedef struct I440FXState { +PCIHostState parent_obj; +}I440FXState ;#define PIIX_NUM_PIC_IRQS 16/* i8259 * 2 */ #define PIIX_NUM_PIRQS 4ULL/* PIRQ[A-D] */
@@ -274,7 +276,7 @@ static PCIBus *i440fx_common_init(const char *device_name, dev =qdev_create (NULL ,"i440FX-pcihost" ); s =PCI_HOST_BRIDGE (dev); s->address_space = address_space_mem; - b =pci_bus_new (&s->busdev.qdev,NULL , pci_address_space, + b =pci_bus_new (dev,NULL , pci_address_space, address_space_io,0 ); s->bus = b;object_property_add_child (qdev_get_machine (),"i440fx" ,OBJECT (dev),NULL );
hw/ppc4xx_pci.c +5 -3
@@ -52,7 +52,7 @@ struct PCITargetMap {#define PPC4xx_PCI_NR_PTMS 2struct PPC4xxPCIState { -PCIHostState pci_state; +PCIHostState parent_obj;struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];
@@ -96,16 +96,18 @@ static uint64_t pci4xx_cfgaddr_read(void *opaque, target_phys_addr_t addr, unsigned size) {PPC4xxPCIState *ppc4xx_pci = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (ppc4xx_pci); -return ppc4xx_pci->pci_state.config_reg; +return phb->config_reg; }static void pci4xx_cfgaddr_write (void *opaque,target_phys_addr_t addr,uint64_t value,unsigned size) {PPC4xxPCIState *ppc4xx_pci = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (ppc4xx_pci); - ppc4xx_pci->pci_state.config_reg = value & ~0x3 ; + phb->config_reg = value & ~0x3 ; }static const MemoryRegionOps pci4xx_cfgaddr_ops = {
hw/ppce500_pci.c +1 -1
@@ -78,7 +78,7 @@ struct pci_inbound { OBJECT_CHECK(PPCE500PCIState, (obj), TYPE_PPC_E500_PCI_HOST_BRIDGE)struct PPCE500PCIState { -PCIHostState pci_state; +PCIHostState parent_obj;struct pci_outbound pob[PPCE500_PCI_NR_POBS ];struct pci_inbound pib[PPCE500_PCI_NR_PIBS ];
hw/prep_pci.c +5 -3
@@ -34,7 +34,7 @@ OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE) typedef struct PRePPCIState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion intack; qemu_irq irq[4];
@@ -60,14 +60,16 @@ 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->host_state.bus,PPC_PCIIO_config (addr), val, size); +PCIHostState *phb =PCI_HOST_BRIDGE (s); +pci_data_write (phb->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->host_state.bus,PPC_PCIIO_config (addr), size); +PCIHostState *phb =PCI_HOST_BRIDGE (s); +return pci_data_read (phb->bus,PPC_PCIIO_config (addr), size); }static const MemoryRegionOps PPC_PCIIO_ops = {
hw/spapr_pci.c +7 -5
@@ -36,16 +36,18 @@ static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, uint32_t config_addr) { int devfn = (config_addr >> 8) & 0xFF; -sPAPRPHBState *phb; +sPAPRPHBState *sphb; - QLIST_FOREACH(phb, &spapr->phbs, list) { + QLIST_FOREACH(sphb, &spapr->phbs, list) { +PCIHostState *phb;BusChild *kid; -if (phb->buid != buid) { +if (sphb->buid != buid) {continue ; } - QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { + phb =PCI_HOST_BRIDGE (sphb); + QTAILQ_FOREACH(kid, &BUS(phb->bus)->children, sibling) {PCIDevice *dev = (PCIDevice *)kid->child;if (dev->devfn == devfn) {return dev;
@@ -319,7 +321,7 @@ static int spapr_phb_init(SysBusDevice *s) pci_spapr_set_irq, pci_spapr_map_irq, phb, &phb->memspace, &phb->iospace, PCI_DEVFN(0, 0), PCI_NUM_PINS); - phb->host_state.bus = bus; +PCI_HOST_BRIDGE (phb)->bus = bus; liobn =SPAPR_PCI_BASE_LIOBN | (pci_find_domain (bus) <<16 ); phb->dma =spapr_tce_new_dma_context (liobn,0x40000000 );
hw/spapr_pci.h +1 -1
@@ -33,7 +33,7 @@ OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE) typedef struct sPAPRPHBState { - PCIHostState host_state; + PCIHostState parent_obj; uint64_t buid; char *busname;
hw/unin_pci.c +7 -7
@@ -53,7 +53,7 @@ static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e }; OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE) typedef struct UNINState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole;
@@ -114,22 +114,22 @@ static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)static void unin_data_write (void *opaque,target_phys_addr_t addr,uint64_t val,unsigned len) { -UNINState *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (opaque);UNIN_DPRINTF ("write addr %" TARGET_FMT_plx" len %d val %" PRIx64"\n" , addr, len, val); -pci_data_write (s->host_state.bus, -unin_get_config_reg (s->host_state.config_reg, addr), +pci_data_write (phb->bus, +unin_get_config_reg (phb->config_reg, addr), val, len); }static uint64_t unin_data_read (void *opaque,target_phys_addr_t addr,unsigned len) { -UNINState *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (opaque);uint32_t val; - val =pci_data_read (s->host_state.bus, -unin_get_config_reg (s->host_state.config_reg, addr), + val =pci_data_read (phb->bus, +unin_get_config_reg (phb->config_reg, addr), len);UNIN_DPRINTF ("read addr %" TARGET_FMT_plx" len %d val %x\n" , addr, len, val);
Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH for-1.2 v5 14/14] pci: Tidy up PCI host bridges
Quoted 4 lines · Andreas Färber
Uglify the parent field to enforce QOM-style access via casts. Don't just typedef PCIHostState, either use it directly or embed it.
Signed-off-by Andreas Färber <[email protected]>
NAK I'd prefer to drop this one for now.
Quoted 321 lines
--- hw/alpha_typhoon.c | 2 +- hw/dec_pci.c | 2 +- hw/grackle_pci.c | 2 +- hw/gt64xxx.c | 26 ++++++++++++++++---------- hw/piix_pci.c | 6 ++++-- hw/ppc4xx_pci.c | 8 +++++--- hw/ppce500_pci.c | 2 +- hw/prep_pci.c | 8 +++++--- hw/spapr_pci.c | 12 +++++++----- hw/spapr_pci.h | 2 +- hw/unin_pci.c | 14 +++++++------- 11 files changed, 49 insertions(+), 35 deletions(-)hw/alpha_typhoon.c +1
-1@@ -46,7 +46,7 @@ typedef struct TyphoonPchip { OBJECT_CHECK(TyphoonState, (obj), TYPE_TYPHOON_PCI_HOST_BRIDGE) typedef struct TyphoonState { - PCIHostState host; + PCIHostState parent_obj; TyphoonCchip cchip; TyphoonPchip pchip;hw/dec_pci.c +1
-1@@ -43,7 +43,7 @@#define DEC_21154 (obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)typedef struct DECState { -PCIHostState host_state; +PCIHostState parent_obj; }DECState ;static int dec_map_irq (PCIDevice *pci_dev,int irq_num)hw/grackle_pci.c +1
-1@@ -41,7 +41,7 @@ OBJECT_CHECK(GrackleState, (obj), TYPE_GRACKLE_PCI_HOST_BRIDGE) typedef struct GrackleState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole;hw/gt64xxx.c +16
-10@@ -235,7 +235,7 @@ OBJECT_CHECK(GT64120State, (obj), TYPE_GT64120_PCI_HOST_BRIDGE) typedef struct GT64120State { - PCIHostState pci; + PCIHostState parent_obj; uint32_t regs[GT_REGS]; PCI_MAPPING_ENTRY(PCI0IO);@@ -315,6 +315,7 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) {GT64120State *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (s);uint32_t saddr;if (!(s->regs[GT_CPU ] &0x00001000 ))@@ -535,13 +536,15 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr,/* not implemented */ break ;case GT_PCI0_CFGADDR : - s->pci.config_reg = val &0x80fffffc ; + phb->config_reg = val &0x80fffffc ;break ;case GT_PCI0_CFGDATA : -if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci.config_reg &0x00fff800 )) +if (!(s->regs[GT_PCI0_CMD ] &1 ) && (phb->config_reg &0x00fff800 )) { val =bswap32 (val); -if (s->pci.config_reg & (1u <<31 )) -pci_data_write (s->pci.bus, s->pci.config_reg, val,4 ); + } +if (phb->config_reg & (1u <<31 )) { +pci_data_write (phb->bus, phb->config_reg, val,4 ); + }break ;/* Interrupts */ @@ -594,6 +597,7 @@ static uint64_t gt64120_readl (void *opaque, target_phys_addr_t addr, unsigned size) {GT64120State *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (s);uint32_t val;uint32_t saddr;@@ -775,15 +779,17 @@ static uint64_t gt64120_readl (void *opaque,/* PCI Internal */ case GT_PCI0_CFGADDR : - val = s->pci.config_reg; + val = phb->config_reg;break ;case GT_PCI0_CFGDATA : -if (!(s->pci.config_reg & (1 <<31 ))) +if (!(phb->config_reg & (1 <<31 ))) { val =0xffffffff ; -else - val =pci_data_read (s->pci.bus, s->pci.config_reg,4 ); -if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci.config_reg &0x00fff800 )) + }else { + val =pci_data_read (phb->bus, phb->config_reg,4 ); + } +if (!(s->regs[GT_PCI0_CMD ] &1 ) && (phb->config_reg &0x00fff800 )) { val =bswap32 (val); + }break ;case GT_PCI0_CMD :hw/piix_pci.c +4
-2@@ -36,7 +36,9 @@* http://download.intel.com/design/chipsets/datashts/29054901.pdf */ -typedef PCIHostState I440FXState ; +typedef struct I440FXState { +PCIHostState parent_obj; +}I440FXState ;#define PIIX_NUM_PIC_IRQS 16/* i8259 * 2 */ #define PIIX_NUM_PIRQS 4ULL/* PIRQ[A-D] */ @@ -274,7 +276,7 @@ static PCIBus *i440fx_common_init(const char *device_name, dev =qdev_create (NULL ,"i440FX-pcihost" ); s =PCI_HOST_BRIDGE (dev); s->address_space = address_space_mem; - b =pci_bus_new (&s->busdev.qdev,NULL , pci_address_space, + b =pci_bus_new (dev,NULL , pci_address_space, address_space_io,0 ); s->bus = b;object_property_add_child (qdev_get_machine (),"i440fx" ,OBJECT (dev),NULL );hw/ppc4xx_pci.c +5
-3@@ -52,7 +52,7 @@ struct PCITargetMap {#define PPC4xx_PCI_NR_PTMS 2struct PPC4xxPCIState { -PCIHostState pci_state; +PCIHostState parent_obj;struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];@@ -96,16 +96,18 @@ static uint64_t pci4xx_cfgaddr_read(void *opaque, target_phys_addr_t addr, unsigned size) {PPC4xxPCIState *ppc4xx_pci = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (ppc4xx_pci); -return ppc4xx_pci->pci_state.config_reg; +return phb->config_reg; }static void pci4xx_cfgaddr_write (void *opaque,target_phys_addr_t addr,uint64_t value,unsigned size) {PPC4xxPCIState *ppc4xx_pci = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (ppc4xx_pci); - ppc4xx_pci->pci_state.config_reg = value & ~0x3 ; + phb->config_reg = value & ~0x3 ; }static const MemoryRegionOps pci4xx_cfgaddr_ops = {hw/ppce500_pci.c +1
-1@@ -78,7 +78,7 @@ struct pci_inbound { OBJECT_CHECK(PPCE500PCIState, (obj), TYPE_PPC_E500_PCI_HOST_BRIDGE)struct PPCE500PCIState { -PCIHostState pci_state; +PCIHostState parent_obj;struct pci_outbound pob[PPCE500_PCI_NR_POBS ];struct pci_inbound pib[PPCE500_PCI_NR_PIBS ];hw/prep_pci.c +5
-3@@ -34,7 +34,7 @@ OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE) typedef struct PRePPCIState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion intack; qemu_irq irq[4];@@ -60,14 +60,16 @@ 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->host_state.bus,PPC_PCIIO_config (addr), val, size); +PCIHostState *phb =PCI_HOST_BRIDGE (s); +pci_data_write (phb->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->host_state.bus,PPC_PCIIO_config (addr), size); +PCIHostState *phb =PCI_HOST_BRIDGE (s); +return pci_data_read (phb->bus,PPC_PCIIO_config (addr), size); }static const MemoryRegionOps PPC_PCIIO_ops = {hw/spapr_pci.c +7
-5@@ -36,16 +36,18 @@ static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, uint32_t config_addr) { int devfn = (config_addr >> 8) & 0xFF; -sPAPRPHBState *phb; +sPAPRPHBState *sphb; - QLIST_FOREACH(phb, &spapr->phbs, list) { + QLIST_FOREACH(sphb, &spapr->phbs, list) { +PCIHostState *phb;BusChild *kid; -if (phb->buid != buid) { +if (sphb->buid != buid) {continue ; } - QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { + phb =PCI_HOST_BRIDGE (sphb); + QTAILQ_FOREACH(kid, &BUS(phb->bus)->children, sibling) {PCIDevice *dev = (PCIDevice *)kid->child;if (dev->devfn == devfn) {return dev;@@ -319,7 +321,7 @@ static int spapr_phb_init(SysBusDevice *s) pci_spapr_set_irq, pci_spapr_map_irq, phb, &phb->memspace, &phb->iospace, PCI_DEVFN(0, 0), PCI_NUM_PINS); - phb->host_state.bus = bus; +PCI_HOST_BRIDGE (phb)->bus = bus; liobn =SPAPR_PCI_BASE_LIOBN | (pci_find_domain (bus) <<16 ); phb->dma =spapr_tce_new_dma_context (liobn,0x40000000 );hw/spapr_pci.h +1
-1@@ -33,7 +33,7 @@ OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE) typedef struct sPAPRPHBState { - PCIHostState host_state; + PCIHostState parent_obj; uint64_t buid; char *busname;hw/unin_pci.c +7
-7@@ -53,7 +53,7 @@ static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e }; OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE) typedef struct UNINState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole;@@ -114,22 +114,22 @@ static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)static void unin_data_write (void *opaque,target_phys_addr_t addr,uint64_t val,unsigned len) { -UNINState *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (opaque);UNIN_DPRINTF ("write addr %" TARGET_FMT_plx" len %d val %" PRIx64"\n" , addr, len, val); -pci_data_write (s->host_state.bus, -unin_get_config_reg (s->host_state.config_reg, addr), +pci_data_write (phb->bus, +unin_get_config_reg (phb->config_reg, addr), val, len); }static uint64_t unin_data_read (void *opaque,target_phys_addr_t addr,unsigned len) { -UNINState *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (opaque);uint32_t val; - val =pci_data_read (s->host_state.bus, -unin_get_config_reg (s->host_state.config_reg, addr), + val =pci_data_read (phb->bus, +unin_get_config_reg (phb->config_reg, addr), len);UNIN_DPRINTF ("read addr %" TARGET_FMT_plx" len %d val %x\n" , addr, len, val);Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH for-1.2 v5 14/14] pci: Tidy up PCI host bridges
In reply to Andreas FärberQuoted 260 lines · Andreas Färber
Uglify the parent field to enforce QOM-style access via casts. Don't just typedef PCIHostState, either use it directly or embed it.
Signed-off-by Andreas Färber <[email protected]>--- hw/alpha_typhoon.c | 2 +- hw/dec_pci.c | 2 +- hw/grackle_pci.c | 2 +- hw/gt64xxx.c | 26 ++++++++++++++++---------- hw/piix_pci.c | 6 ++++-- hw/ppc4xx_pci.c | 8 +++++--- hw/ppce500_pci.c | 2 +- hw/prep_pci.c | 8 +++++--- hw/spapr_pci.c | 12 +++++++----- hw/spapr_pci.h | 2 +- hw/unin_pci.c | 14 +++++++------- 11 files changed, 49 insertions(+), 35 deletions(-)hw/alpha_typhoon.c +1
-1@@ -46,7 +46,7 @@ typedef struct TyphoonPchip { OBJECT_CHECK(TyphoonState, (obj), TYPE_TYPHOON_PCI_HOST_BRIDGE) typedef struct TyphoonState { - PCIHostState host; + PCIHostState parent_obj; TyphoonCchip cchip; TyphoonPchip pchip;hw/dec_pci.c +1
-1@@ -43,7 +43,7 @@#define DEC_21154 (obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)typedef struct DECState { -PCIHostState host_state; +PCIHostState parent_obj; }DECState ;static int dec_map_irq (PCIDevice *pci_dev,int irq_num)hw/grackle_pci.c +1
-1@@ -41,7 +41,7 @@ OBJECT_CHECK(GrackleState, (obj), TYPE_GRACKLE_PCI_HOST_BRIDGE) typedef struct GrackleState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole;hw/gt64xxx.c +16
-10@@ -235,7 +235,7 @@ OBJECT_CHECK(GT64120State, (obj), TYPE_GT64120_PCI_HOST_BRIDGE) typedef struct GT64120State { - PCIHostState pci; + PCIHostState parent_obj; uint32_t regs[GT_REGS]; PCI_MAPPING_ENTRY(PCI0IO);@@ -315,6 +315,7 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) {GT64120State *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (s);uint32_t saddr;if (!(s->regs[GT_CPU ] &0x00001000 ))@@ -535,13 +536,15 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr,/* not implemented */ break ;case GT_PCI0_CFGADDR : - s->pci.config_reg = val &0x80fffffc ; + phb->config_reg = val &0x80fffffc ;break ;case GT_PCI0_CFGDATA : -if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci.config_reg &0x00fff800 )) +if (!(s->regs[GT_PCI0_CMD ] &1 ) && (phb->config_reg &0x00fff800 )) { val =bswap32 (val); -if (s->pci.config_reg & (1u <<31 )) -pci_data_write (s->pci.bus, s->pci.config_reg, val,4 ); + } +if (phb->config_reg & (1u <<31 )) { +pci_data_write (phb->bus, phb->config_reg, val,4 ); + }break ;/* Interrupts */ @@ -594,6 +597,7 @@ static uint64_t gt64120_readl (void *opaque, target_phys_addr_t addr, unsigned size) {GT64120State *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (s);uint32_t val;uint32_t saddr;@@ -775,15 +779,17 @@ static uint64_t gt64120_readl (void *opaque,/* PCI Internal */ case GT_PCI0_CFGADDR : - val = s->pci.config_reg; + val = phb->config_reg;break ;case GT_PCI0_CFGDATA : -if (!(s->pci.config_reg & (1 <<31 ))) +if (!(phb->config_reg & (1 <<31 ))) { val =0xffffffff ; -else - val =pci_data_read (s->pci.bus, s->pci.config_reg,4 ); -if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci.config_reg &0x00fff800 )) + }else { + val =pci_data_read (phb->bus, phb->config_reg,4 ); + } +if (!(s->regs[GT_PCI0_CMD ] &1 ) && (phb->config_reg &0x00fff800 )) { val =bswap32 (val); + }break ;case GT_PCI0_CMD :hw/piix_pci.c +4
-2@@ -36,7 +36,9 @@* http://download.intel.com/design/chipsets/datashts/29054901.pdf */ -typedef PCIHostState I440FXState ; +typedef struct I440FXState { +PCIHostState parent_obj; +}I440FXState ;#define PIIX_NUM_PIC_IRQS 16/* i8259 * 2 */ #define PIIX_NUM_PIRQS 4ULL/* PIRQ[A-D] */ @@ -274,7 +276,7 @@ static PCIBus *i440fx_common_init(const char *device_name, dev =qdev_create (NULL ,"i440FX-pcihost" ); s =PCI_HOST_BRIDGE (dev); s->address_space = address_space_mem; - b =pci_bus_new (&s->busdev.qdev,NULL , pci_address_space, + b =pci_bus_new (dev,NULL , pci_address_space, address_space_io,0 ); s->bus = b;object_property_add_child (qdev_get_machine (),"i440fx" ,OBJECT (dev),NULL );hw/ppc4xx_pci.c +5
-3@@ -52,7 +52,7 @@ struct PCITargetMap {#define PPC4xx_PCI_NR_PTMS 2struct PPC4xxPCIState { -PCIHostState pci_state; +PCIHostState parent_obj;struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];@@ -96,16 +96,18 @@ static uint64_t pci4xx_cfgaddr_read(void *opaque, target_phys_addr_t addr, unsigned size) {PPC4xxPCIState *ppc4xx_pci = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (ppc4xx_pci); -return ppc4xx_pci->pci_state.config_reg; +return phb->config_reg; }static void pci4xx_cfgaddr_write (void *opaque,target_phys_addr_t addr,uint64_t value,unsigned size) {PPC4xxPCIState *ppc4xx_pci = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (ppc4xx_pci); - ppc4xx_pci->pci_state.config_reg = value & ~0x3 ; + phb->config_reg = value & ~0x3 ; }static const MemoryRegionOps pci4xx_cfgaddr_ops = {hw/ppce500_pci.c +1
-1@@ -78,7 +78,7 @@ struct pci_inbound { OBJECT_CHECK(PPCE500PCIState, (obj), TYPE_PPC_E500_PCI_HOST_BRIDGE)struct PPCE500PCIState { -PCIHostState pci_state; +PCIHostState parent_obj;struct pci_outbound pob[PPCE500_PCI_NR_POBS ];struct pci_inbound pib[PPCE500_PCI_NR_PIBS ];hw/prep_pci.c +5
-3@@ -34,7 +34,7 @@ OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE) typedef struct PRePPCIState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion intack; qemu_irq irq[4];@@ -60,14 +60,16 @@ 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->host_state.bus,PPC_PCIIO_config (addr), val, size); +PCIHostState *phb =PCI_HOST_BRIDGE (s); +pci_data_write (phb->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->host_state.bus,PPC_PCIIO_config (addr), size); +PCIHostState *phb =PCI_HOST_BRIDGE (s); +return pci_data_read (phb->bus,PPC_PCIIO_config (addr), size); }static const MemoryRegionOps PPC_PCIIO_ops = {hw/spapr_pci.c +6
-4@@ -36,16 +36,18 @@ static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, uint32_t config_addr) { int devfn = (config_addr >> 8) & 0xFF; -sPAPRPHBState *phb; +sPAPRPHBState *sphb; - QLIST_FOREACH(phb, &spapr->phbs, list) { + QLIST_FOREACH(sphb, &spapr->phbs, list) { +PCIHostState *phb;BusChild *kid; -if (phb->buid != buid) { +if (sphb->buid != buid) {continue ; } - QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { + phb =PCI_HOST_BRIDGE (sphb); + QTAILQ_FOREACH(kid, &BUS(phb->bus)->children, sibling) {PCIDevice *dev = (PCIDevice *)kid->child;if (dev->devfn == devfn) {return dev;
hw/spapr_pci.c static int spapr_phb_init(SysBusDevice *s) · line 324
Quoted 5 lines
hw/spapr_pci.c +1
-1@@ -319,7 +321,7 @@ static int spapr_phb_init(SysBusDevice *s) pci_spapr_set_irq, pci_spapr_map_irq, phb, &phb->memspace, &phb->iospace, PCI_DEVFN(0, 0), PCI_NUM_PINS); - phb->host_state.bus = bus; +PCI_HOST_BRIDGE (phb)->bus = bus;
I think you meant:
PCI_HOST_BRIDGE(sphb)->bus
But really you meant:
phb->bus = bus;
Regards,
Anthony Liguori
Quoted 60 lines
hw/spapr_pci.c +0
-0liobn =SPAPR_PCI_BASE_LIOBN | (pci_find_domain (bus) <<16 ); phb->dma =spapr_tce_new_dma_context (liobn,0x40000000 );hw/spapr_pci.h +1
-1@@ -33,7 +33,7 @@ OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE) typedef struct sPAPRPHBState { - PCIHostState host_state; + PCIHostState parent_obj; uint64_t buid; char *busname;hw/unin_pci.c +7
-7@@ -53,7 +53,7 @@ static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e }; OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE) typedef struct UNINState { - PCIHostState host_state; + PCIHostState parent_obj; MemoryRegion pci_mmio; MemoryRegion pci_hole;@@ -114,22 +114,22 @@ static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)static void unin_data_write (void *opaque,target_phys_addr_t addr,uint64_t val,unsigned len) { -UNINState *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (opaque);UNIN_DPRINTF ("write addr %" TARGET_FMT_plx" len %d val %" PRIx64"\n" , addr, len, val); -pci_data_write (s->host_state.bus, -unin_get_config_reg (s->host_state.config_reg, addr), +pci_data_write (phb->bus, +unin_get_config_reg (phb->config_reg, addr), val, len); }static uint64_t unin_data_read (void *opaque,target_phys_addr_t addr,unsigned len) { -UNINState *s = opaque; +PCIHostState *phb =PCI_HOST_BRIDGE (opaque);uint32_t val; - val =pci_data_read (s->host_state.bus, -unin_get_config_reg (s->host_state.config_reg, addr), + val =pci_data_read (phb->bus, +unin_get_config_reg (phb->config_reg, addr), len);UNIN_DPRINTF ("read addr %" TARGET_FMT_plx" len %d val %x\n" , addr, len, val);Signature · 1 line
1.7.7
Re: [Qemu-devel] [PATCH for-1.2 v5 14/14] pci: Tidy up PCI host bridges
Am 13.08.2012 15:14, schrieb Anthony Liguori:
Quoted 39 lines
Quoted 29 lines · Andreas Färber
hw/spapr_pci.c +6
-4@@ -36,16 +36,18 @@ static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, uint32_t config_addr) { int devfn = (config_addr >> 8) & 0xFF; -sPAPRPHBState *phb; +sPAPRPHBState *sphb; - QLIST_FOREACH(phb, &spapr->phbs, list) { + QLIST_FOREACH(sphb, &spapr->phbs, list) { +PCIHostState *phb;BusChild *kid; -if (phb->buid != buid) { +if (sphb->buid != buid) {continue ; } - QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { + phb =PCI_HOST_BRIDGE (sphb); + QTAILQ_FOREACH(kid, &BUS(phb->bus)->children, sibling) {PCIDevice *dev = (PCIDevice *)kid->child;if (dev->devfn == devfn) {return dev;hw/spapr_pci.c static int spapr_phb_init(SysBusDevice *s) · line 324
Quoted 5 lines
hw/spapr_pci.c +1
-1@@ -319,7 +321,7 @@ static int spapr_phb_init(SysBusDevice *s) pci_spapr_set_irq, pci_spapr_map_irq, phb, &phb->memspace, &phb->iospace, PCI_DEVFN(0, 0), PCI_NUM_PINS); - phb->host_state.bus = bus; +PCI_HOST_BRIDGE (phb)->bus = bus;I think you meant:
Quoted 5 lines
PCI_HOST_BRIDGE(sphb)->bus
But really you meant:
phb->bus= bus;
The patch is misleading here, in the initfn phb historically is sPAPRPHBState, not PCIHostState.
But you are right that this inline macro usage should be fixed - will solve by squashing phb -> sphb renaming into the spapr_pci patch.
Thanks,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH for-1.2 v5 14/14] pci: Tidy up PCI host bridges
In reply to Andreas FärberQuoted 4 lines · Andreas Färber
Uglify the parent field to enforce QOM-style access via casts. Don't just typedef PCIHostState, either use it directly or embed it.
Signed-off-by Andreas Färber <[email protected]>
IMHO only one chunk from this patch should be applied (below). Below it is split out but needs to be rebased on top of patches 1-13.
-->
From: Andreas Färber <[email protected]>
piix: minor code simplification
There's no need to deal with qdev internals in piix - we get device state from qdev_create so just use that.
---
hw/piix_pci.c +1 -1
@@ -274,7 +274,7 @@ static PCIBus *i440fx_common_init(const char *device_name, dev =qdev_create (NULL ,"i440FX-pcihost" ); s =FROM_SYSBUS (I440FXState,sysbus_from_qdev (dev)); s->address_space = address_space_mem; - b =pci_bus_new (&s->busdev.qdev,NULL , pci_address_space, + b =pci_bus_new (&dev,NULL , pci_address_space, address_space_io,0 ); s->bus = b;object_property_add_child (qdev_get_machine (),"i440fx" ,OBJECT (dev),NULL );
Re: [Qemu-devel] [PATCH for-1.2 v5 14/14] pci: Tidy up PCI host bridges
Quoted 10 lines · Michael S. Tsirkin
Quoted 4 lines · Andreas Färber
Uglify the parent field to enforce QOM-style access via casts. Don't just typedef PCIHostState, either use it directly or embed it.
Signed-off-by Andreas Färber <[email protected]>IMHO only one chunk from this patch should be applied (below). Below it is split out but needs to be rebased on top of patches 1-13.
I understand what your objection is but it's unreasonable IMHO. The purpose of QOM is to bring consistency across large swaths of code in QEMU that have historically done things there own way.
This means expressing concepts like inheritence and casting in the same way across the board. The common way (the QOM way) is to make the parent type the first member of the struct (typically named parent or parent_obj) and then to use cast macros to upcast and downcast.
This patch is 100% correct in that regard and I'm going to apply it once Andreas makes the change I requested.
For my part, I'm long over due in writing up a device authoring style guide that I promised a few weeks ago. I'll write that up this afternoon and send it out today.
We can debate the merits of this sort of thing in the style guide.
Regards,
Anthony Liguori
Quoted 28 lines
-->
From: Andreas Färber <[email protected]>
piix: minor code simplification
There's no need to deal with qdev internals in piix - we get device state from
qdev_createso just use that.Signed-off-by Andreas Färber <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
hw/piix_pci.c +1
-1@@ -274,7 +274,7 @@ static PCIBus *i440fx_common_init(const char *device_name, dev =qdev_create (NULL ,"i440FX-pcihost" ); s =FROM_SYSBUS (I440FXState,sysbus_from_qdev (dev)); s->address_space = address_space_mem; - b =pci_bus_new (&s->busdev.qdev,NULL , pci_address_space, + b =pci_bus_new (&dev,NULL , pci_address_space, address_space_io,0 ); s->bus = b;object_property_add_child (qdev_get_machine (),"i440fx" ,OBJECT (dev),NULL );
Re: [Qemu-devel] [PATCH for-1.2 v5 14/14] pci: Tidy up PCI host bridges
Quoted 9 lines · Anthony Liguori
I understand what your objection is but it's unreasonable IMHO. The purpose of QOM is to bring consistency across large swaths of code in QEMU that have historically done things there own way.
This means expressing concepts like inheritence and casting in the same way across the board. The common way (the QOM way) is to make the parent type the first member of the struct (typically named parent or
parent_obj) and then to use cast macros to upcast and downcast.
Quoted 8 lines
This patch is 100% correct in that regard and I'm going to apply it once Andreas makes the change I requested.
For my part, I'm long over due in writing up a device authoring style guide that I promised a few weeks ago. I'll write that up this afternoon and send it out today.
We can debate the merits of this sort of thing in the style guide.
Yes please! I've spent quite a fair bit of time over the past couple of weeks in this area, and have found the lack of documentation related to trying to create a new hardware device fairly frustrating. The hardest part is not the coding, but figuring which of the following I should be using out of:
qom
qdev
qmp
hmp
sysbus
VMState
(I think that half of these are now obsolete interfaces, but a general document which explains how these things are related and which ones I should be using would be very welcome)
ATB,
Mark.
Quoted 11 lines · Andreas Färber
Hello Anthony and Michael,
Here's a fixed version of the series making
pci_hosta first-class QOM type.
MAINTAINERSentries for the ppc devices touched herein are stripped from the series but being used for sending. They can be applied later through ppc-next.This series is a prerequisite for the i440fx refactoring and q35 introduction.
I have verified this to apply cleanly to both master and pci branch now.
Quoted 8 lines
mst: Followups for i440fx by Wanpeng were on the list already, but feel free not to apply the slimmed-down final patch if we can then finally move on!
Regards,
AndreasCc Anthony Liguori <[email protected]>Cc Michael S. Tsirkin <[email protected]>
ACK patches 1-13.
Quoted 66 lines
Cc Wanpeng Li <[email protected]>Cc Jason Baron <[email protected]>Cc Jan Kiszka <[email protected]>Cc Alexander Graf <[email protected]>Cc Peter Maydell <[email protected]>v4 -> v5:
* Resolved PCI_HOST_BRIDGE(s)->bus usage inalpha_typhoon(forgotten in v4).
* Update Wanpeng's email address in SoB to avoid bounces.
* Leave outMAINTAINERSadditions, still valid but no ack from Alex yet and open question from Peter on ordering.v3 -> v4:
* Moved spapr_pci.c:register_types() rename to later dedicatedspapr_pcipatch.
* Added proposed patches for relatedMAINTAINERSmachine entries w/ PHB files. Anthony requested the QOM cast discussion to be held elsewhere, so no change.v2 -> v3:
* RenamedPCI_HOSTtoPCI_HOST_BRIDGE, suggested by mst.
* Split off const changes to clarify the name/parent changes.
* Split off cleanups per host bridge.
* Prepared and enforced QOM-style field access through explicit types.v1 -> v2:
* Converted remaining PCI host bridges to new type.Andreas Färber (14):
pci: Make host bridge TypeInfos const
alpha_typhoon: QOM'ify Typhoon PCI host bridge
bonito: QOM'ify Bonito PCI host bridge
dec_pci: QOM'ify DEC 21154 PCI-PCI bridge
grackle_pci: QOM'ify Grackle PCI host bridge
gt64xxx: QOM'ify GT64120 PCI host bridge
ppc4xx_pci: QOM'ify ppc4xx PCI host bridge
ppce500_pci: QOM'ify e500 PCI host bridge
prep_pci: QOM'ify Raven PCI host bridge
spapr_pci: QOM'ify sPAPR PCI host bridge
unin_pci: QOM'ify UniNorth PCI host bridges
pci_host: Turn into SysBus-derived QOM type
pci: Derive PCI host bridges fromTYPE_PCI_HOST_BRIDGE
pci: Tidy up PCI host bridgeshw/alpha_typhoon.c | 26 +++++--- hw/bonito.c | 152 ++++++++++++++++++++++++++----------------- hw/dec_pci.c | 31 +++++---- hw/dec_pci.h | 2 + hw/grackle_pci.c | 65 +++++++++--------- hw/gt64xxx.c | 67 +++++++++++-------- hw/pci_host.c | 12 ++++ hw/pci_host.h | 5 ++ hw/piix_pci.c | 22 ++++--- hw/ppc440_bamboo.c | 3 +- hw/ppc4xx.h | 2 + hw/ppc4xx_pci.c | 27 +++++--- hw/ppc_mac.h | 1 + hw/ppc_prep.c | 4 +- hw/ppce500_pci.c | 24 ++++--- hw/prep_pci.c | 33 ++++++---- hw/spapr_pci.c | 29 +++++---- hw/spapr_pci.h | 8 ++- hw/unin_pci.c | 183 +++++++++++++++++++++++++++------------------------- 19 files changed, 402 insertions(+), 294 deletions(-)Signature · 1 line
1.7.7
Am 02.08.2012 10:30, schrieb Michael S. Tsirkin:
Quoted 15 lines · Andreas Färber
Quoted 14 lines
Hello Anthony and Michael,
Here's a fixed version of the series making
pci_hosta first-class QOM type.
MAINTAINERSentries for the ppc devices touched herein are stripped from the series but being used for sending. They can be applied later through ppc-next.This series is a prerequisite for the i440fx refactoring and q35 introduction.
I have verified this to apply cleanly to both master and pci branch now.
mst: Followups for i440fx by Wanpeng were on the list already, but feel free not to apply the slimmed-down final patch if we can then finally move on!
Quoted 8 lines
Quoted 5 lines
Regards,
AndreasCc Anthony Liguori <[email protected]>Cc Michael S. Tsirkin <[email protected]>ACK patches 1-13.
Ping! I don't see these on the pci branch. Should they be picked up by Anthony directly?
Thanks,
Andreas
Quoted 68 lines
Quoted 67 lines
Cc Wanpeng Li <[email protected]>Cc Jason Baron <[email protected]>Cc Jan Kiszka <[email protected]>Cc Alexander Graf <[email protected]>Cc Peter Maydell <[email protected]>v4 -> v5:
* Resolved PCI_HOST_BRIDGE(s)->bus usage inalpha_typhoon(forgotten in v4).
* Update Wanpeng's email address in SoB to avoid bounces.
* Leave outMAINTAINERSadditions, still valid but no ack from Alex yet and open question from Peter on ordering.v3 -> v4:
* Moved spapr_pci.c:register_types() rename to later dedicatedspapr_pcipatch.
* Added proposed patches for relatedMAINTAINERSmachine entries w/ PHB files. Anthony requested the QOM cast discussion to be held elsewhere, so no change.v2 -> v3:
* RenamedPCI_HOSTtoPCI_HOST_BRIDGE, suggested by mst.
* Split off const changes to clarify the name/parent changes.
* Split off cleanups per host bridge.
* Prepared and enforced QOM-style field access through explicit types.v1 -> v2:
* Converted remaining PCI host bridges to new type.Andreas Färber (14):
pci: Make host bridge TypeInfos const
alpha_typhoon: QOM'ify Typhoon PCI host bridge
bonito: QOM'ify Bonito PCI host bridge
dec_pci: QOM'ify DEC 21154 PCI-PCI bridge
grackle_pci: QOM'ify Grackle PCI host bridge
gt64xxx: QOM'ify GT64120 PCI host bridge
ppc4xx_pci: QOM'ify ppc4xx PCI host bridge
ppce500_pci: QOM'ify e500 PCI host bridge
prep_pci: QOM'ify Raven PCI host bridge
spapr_pci: QOM'ify sPAPR PCI host bridge
unin_pci: QOM'ify UniNorth PCI host bridges
pci_host: Turn into SysBus-derived QOM type
pci: Derive PCI host bridges fromTYPE_PCI_HOST_BRIDGE
pci: Tidy up PCI host bridgeshw/alpha_typhoon.c | 26 +++++--- hw/bonito.c | 152 ++++++++++++++++++++++++++----------------- hw/dec_pci.c | 31 +++++---- hw/dec_pci.h | 2 + hw/grackle_pci.c | 65 +++++++++--------- hw/gt64xxx.c | 67 +++++++++++-------- hw/pci_host.c | 12 ++++ hw/pci_host.h | 5 ++ hw/piix_pci.c | 22 ++++--- hw/ppc440_bamboo.c | 3 +- hw/ppc4xx.h | 2 + hw/ppc4xx_pci.c | 27 +++++--- hw/ppc_mac.h | 1 + hw/ppc_prep.c | 4 +- hw/ppce500_pci.c | 24 ++++--- hw/prep_pci.c | 33 ++++++---- hw/spapr_pci.c | 29 +++++---- hw/spapr_pci.h | 8 ++- hw/unin_pci.c | 183 +++++++++++++++++++++++++++------------------------- 19 files changed, 402 insertions(+), 294 deletions(-)Signature · 1 line
1.7.7
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Am 09.08.2012 17:09, schrieb Andreas Färber:
Quoted 7 lines
Am 02.08.2012 10:30, schrieb Michael S. Tsirkin:
Quoted 6 lines · Andreas Färber
Quoted 5 lines
Here's a fixed version of the series making
pci_hosta first-class QOM type.
MAINTAINERSentries for the ppc devices touched herein are stripped from the series but being used for sending. They can be applied later through ppc-next.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
This series is a prerequisite for the i440fx refactoring and q35 introduction.
I have verified this to apply cleanly to both master and pci branch now.
ACK patches 1-13.
Ping! I don't see these on the pci branch. Should they be picked up by Anthony directly?
Ping^2! If you want a PULL, let me know.
/-F
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg