pci: Create PCI Express bus type
cover pci: Create PCI Express bus type
When setting PCIe capabilities we need to know the type of bus we have. On secondary buses we could poke around on the parent bridge device to infer this data, but on root buses there's no parent device. By creating a new PCIE TypeInfo we can inherit everything about PCI buses while still allowing us to differentiate and potentially extend in the future.
The first benefactor of this change is included here, mangling Endpoints to Root Complex Integrated Endpoints, allowing nec-usb-xhci to work on the root bus of q35 with Windows. I also plan to use this to drop link capabilities, control, and status on all Integrated Endpoints and for PCIe capability modifications on assigned devices. Thanks,
Alex
---
Alex Williamson (7):
pci: Create and register a new PCI Express TypeInfo
pci: Move PCI and PCIE type defines
pci: Allow PCI bus creation interfaces to specify the type of bus
pci: Q35, Root Ports, and Switches create PCI Express buses
pci: Create pci_bus_is_express helper
pci: Create and use API to determine root buses
pcie: Mangle types to match topology
hw/alpha_typhoon.c | 2 +- hw/apb_pci.c | 4 ++-- hw/bonito.c | 2 +- hw/dec_pci.c | 7 ++++++- hw/grackle_pci.c | 2 +- hw/gt64xxx.c | 2 +- hw/i82801b11.c | 2 +- hw/ioh3420.c | 2 +- hw/pci/pci.c | 36 ++++++++++++++++++++++++++---------- hw/pci/pci.h | 13 ++++++++++--- hw/pci/pci_bridge.c | 5 ++--- hw/pci/pci_bridge.h | 2 +- hw/pci/pci_bus.h | 3 --- hw/pci/pcie.c | 13 +++++++++++++ hw/pci_bridge_dev.c | 2 +- hw/piix_pci.c | 2 +- hw/ppc4xx_pci.c | 2 +- hw/ppce500_pci.c | 2 +- hw/prep_pci.c | 2 +- hw/q35.c | 3 ++- hw/sh_pci.c | 2 +- hw/spapr_pci.c | 2 +- hw/unin_pci.c | 4 ++-- hw/versatile_pci.c | 2 +- hw/xio3130_downstream.c | 2 +- hw/xio3130_upstream.c | 2 +- 26 files changed, 80 insertions(+), 42 deletions(-)
PATCH 1/7 pci: Create and register a new PCI Express TypeInfo
This will allow us to differentiate Express and Legacy buses.
--- hw/pci/pci.c | 6 ++++++ hw/pci/pci_bus.h | 1 + 2 files changed, 7 insertions(+)
hw/pci/pci.c +6 -0
@@ -75,6 +75,11 @@ static const TypeInfo pci_bus_info = { .class_init = pci_bus_class_init, }; +static const TypeInfo pcie_bus_info = { + .name =TYPE_PCIE_BUS , + .parent =TYPE_PCI_BUS , +}; +static PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num);static void pci_update_mappings (PCIDevice *d);static void pci_set_irq (void *opaque,int irq_num,int level);
@@ -2231,6 +2236,7 @@ static const TypeInfo pci_device_type_info = {static void pci_register_types (void ) {type_register_static (&pci_bus_info); +type_register_static (&pcie_bus_info);type_register_static (&pci_device_type_info); }
hw/pci/pci_bus.h +1 -0
@@ -10,6 +10,7 @@#define TYPE_PCI_BUS "PCI"#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +#define TYPE_PCIE_BUS "PCIE"struct PCIBus {BusState qbus;
PATCH 2/7 pci: Move PCI and PCIE type defines
In reply to Alex WilliamsonMove these so that we can reference them from a more common header instead of including pci_bus.h everywhere.
--- hw/pci/pci.h | 5 +++++ hw/pci/pci_bus.h | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-)
hw/pci/pci.h +5 -0
@@ -339,6 +339,11 @@ typedef enum {typedef int (*pci_hotplug_fn )(DeviceState *qdev,PCIDevice *pci_dev,PCIHotplugState state); + +#define TYPE_PCI_BUS "PCI" +#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +#define TYPE_PCIE_BUS "PCIE" + void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
hw/pci/pci_bus.h +0 -4
@@ -8,10 +8,6 @@* use accessor functions in pci.h, pci_bridge.h */ -#define TYPE_PCI_BUS "PCI" -#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) -#define TYPE_PCIE_BUS "PCIE" -struct PCIBus {BusState qbus;PCIDMAContextFunc dma_context_fn;
PATCH 3/7 pci: Allow PCI bus creation interfaces to specify the type of bus
In reply to Alex WilliamsonNo change to any types.
--- hw/alpha_typhoon.c | 2 +- hw/apb_pci.c | 4 ++-- hw/bonito.c | 2 +- hw/dec_pci.c | 7 ++++++- hw/grackle_pci.c | 2 +- hw/gt64xxx.c | 2 +- hw/i82801b11.c | 2 +- hw/ioh3420.c | 2 +- hw/pci/pci.c | 12 ++++++------ hw/pci/pci.h | 6 +++--- hw/pci/pci_bridge.c | 5 ++--- hw/pci/pci_bridge.h | 2 +- hw/pci_bridge_dev.c | 2 +- hw/piix_pci.c | 2 +- hw/ppc4xx_pci.c | 2 +- hw/ppce500_pci.c | 2 +- hw/prep_pci.c | 2 +- hw/q35.c | 3 ++- hw/sh_pci.c | 2 +- hw/spapr_pci.c | 2 +- hw/unin_pci.c | 4 ++-- hw/versatile_pci.c | 2 +- hw/xio3130_downstream.c | 2 +- hw/xio3130_upstream.c | 2 +- 24 files changed, 40 insertions(+), 35 deletions(-)
hw/alpha_typhoon.c +1 -1
@@ -775,7 +775,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus, b =pci_register_bus (dev,"pci" , typhoon_set_irq, sys_map_irq, s, - &s->pchip.reg_mem, addr_space_io,0 ,64 ); + &s->pchip.reg_mem, addr_space_io,0 ,64 ,TYPE_PCI_BUS ); phb->bus = b;/* Pchip0 PCI special/interrupt acknowledge, 0x801.F800.0000, 64MB. */
hw/apb_pci.c +2 -2
@@ -329,7 +329,7 @@ static int apb_pci_bridge_initfn(PCIDevice *dev) {int rc; - rc =pci_bridge_initfn (dev); + rc =pci_bridge_initfn (dev,TYPE_PCI_BUS );if (rc <0 ) {return rc; }
@@ -381,7 +381,7 @@ PCIBus *pci_apb_init(hwaddr special_base, pci_apb_set_irq, pci_pbm_map_irq, d, &d->pci_mmio,get_system_io (), - 0, 32); + 0, 32, TYPE_PCI_BUS); *pbm_irqs = d->pbm_irqs; d->ivec_irqs = ivec_irqs;
hw/bonito.c +1 -1
@@ -707,7 +707,7 @@ static int bonito_pcihost_initfn(SysBusDevice *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 ); +0x28 ,32 ,TYPE_PCI_BUS );return 0 ; }
hw/dec_pci.c +6 -1
@@ -51,12 +51,17 @@ static int dec_map_irq(PCIDevice *pci_dev, int irq_num)return irq_num; } +static int dec_pci_bridge_initfn (PCIDevice *pci_dev) +{ +return pci_bridge_initfn (pci_dev,TYPE_PCI_BUS ); +} +static void dec_21154_pci_bridge_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); - k->init = pci_bridge_initfn; + k->init = dec_pci_bridge_initfn; k->exit = pci_bridge_exitfn; k->vendor_id =PCI_VENDOR_ID_DEC ; k->device_id =PCI_DEVICE_ID_DEC_21154 ;
hw/grackle_pci.c +1 -1
@@ -88,7 +88,7 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic, pic, &d->pci_mmio, address_space_io, - 0, 4); + 0, 4, TYPE_PCI_BUS);pci_create_simple (phb->bus,0 ,"grackle" );
hw/gt64xxx.c +1 -1
@@ -1107,7 +1107,7 @@ PCIBus *gt64120_register(qemu_irq *pic) pic,get_system_memory (),get_system_io (), - PCI_DEVFN(18, 0), 4); + PCI_DEVFN(18, 0), 4, TYPE_PCI_BUS);memory_region_init_io (&d->ISD_mem, &isd_mem_ops, d,"isd-mem" ,0x1000 );pci_create_simple (phb->bus,PCI_DEVFN (0 ,0 ),"gt64120_pci" );
hw/i82801b11.c +1 -1
@@ -59,7 +59,7 @@ static int i82801b11_bridge_initfn(PCIDevice *d) {int rc; - rc =pci_bridge_initfn (d); + rc =pci_bridge_initfn (d,TYPE_PCI_BUS );if (rc <0 ) {return rc; }
hw/ioh3420.c +1 -1
@@ -97,7 +97,7 @@ static int ioh3420_initfn(PCIDevice *d)PCIESlot *s =DO_UPCAST (PCIESlot, port, p);int rc; - rc =pci_bridge_initfn (d); + rc =pci_bridge_initfn (d,TYPE_PCI_BUS );if (rc <0 ) {return rc; }
hw/pci/pci.c +6 -6
@@ -301,9 +301,9 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,const char *name, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, - uint8_t devfn_min) + uint8_t devfn_min, const char *typename) { -qbus_create_inplace (bus ,TYPE_PCI_BUS ,parent ,name ); +qbus_create_inplace (bus ,typename ,parent ,name );pci_bus_init (bus, parent, name, address_space_mem, address_space_io, devfn_min); }
@@ -311,11 +311,11 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,PCIBus *pci_bus_new (DeviceState *parent,const char *name,MemoryRegion *address_space_mem,MemoryRegion *address_space_io, -uint8_t devfn_min) +uint8_t devfn_min,const char *typename) {PCIBus *bus; - bus =PCI_BUS (qbus_create (TYPE_PCI_BUS , parent, name)); + bus =PCI_BUS (qbus_create (typename, parent, name));pci_bus_init (bus, parent, name, address_space_mem, address_space_io, devfn_min);return bus;
@@ -343,12 +343,12 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,void *irq_opaque, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, - uint8_t devfn_min, int nirq) + uint8_t devfn_min, int nirq, const char *typename) { PCIBus *bus; bus =pci_bus_new (parent, name, address_space_mem, - address_space_io, devfn_min); + address_space_io, devfn_min, typename);pci_bus_irqs (bus, set_irq, map_irq, irq_opaque, nirq);return bus; }
hw/pci/pci.h +3 -3
@@ -348,11 +348,11 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,const char *name, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, - uint8_t devfn_min); + uint8_t devfn_min, const char *typename);PCIBus *pci_bus_new (DeviceState *parent,const char *name,MemoryRegion *address_space_mem,MemoryRegion *address_space_io, -uint8_t devfn_min); +uint8_t devfn_min,const char *typename);void pci_bus_irqs (PCIBus *bus,pci_set_irq_fn set_irq,pci_map_irq_fn map_irq,void *irq_opaque,int nirq);int pci_bus_get_irq_level (PCIBus *bus,int irq_num);
@@ -364,7 +364,7 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,void *irq_opaque, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, - uint8_t devfn_min, int nirq); + uint8_t devfn_min, int nirq, const char *typename);void pci_bus_set_route_irq_fn (PCIBus *,pci_route_irq_fn );PCIINTxRoute pci_device_route_intx_to_irq (PCIDevice *dev,int pin);bool pci_intx_route_changed (PCIINTxRoute *old,PCIINTxRoute *new);
hw/pci/pci_bridge.c +2 -3
@@ -328,7 +328,7 @@ void pci_bridge_reset(DeviceState *qdev) }/* default qdev initialization function for PCI-to-PCI bridge */ -int pci_bridge_initfn (PCIDevice *dev) +int pci_bridge_initfn (PCIDevice *dev,const char *typename) {PCIBus *parent = dev->bus;PCIBridge *br =DO_UPCAST (PCIBridge, dev, dev);
@@ -364,8 +364,7 @@ int pci_bridge_initfn(PCIDevice *dev) br->bus_name = dev->qdev.id; } -qbus_create_inplace (&sec_bus->qbus,TYPE_PCI_BUS , &dev->qdev, - br->bus_name); +qbus_create_inplace (&sec_bus->qbus, typename, &dev->qdev, br->bus_name); sec_bus->parent_dev = dev; sec_bus->map_irq = br->map_irq ? br->map_irq : pci_swizzle_map_irq_fn; sec_bus->address_space_mem = &br->address_space_mem;
hw/pci/pci_bridge.h +1 -1
@@ -43,7 +43,7 @@ void pci_bridge_disable_base_limit(PCIDevice *dev);void pci_bridge_reset_reg (PCIDevice *dev);void pci_bridge_reset (DeviceState *qdev); -int pci_bridge_initfn (PCIDevice *pci_dev); +int pci_bridge_initfn (PCIDevice *pci_dev,const char *typename);void pci_bridge_exitfn (PCIDevice *pci_dev);
hw/pci_bridge_dev.c +1 -1
@@ -42,7 +42,7 @@ static int pci_bridge_dev_initfn(PCIDevice *dev)PCIBridgeDev *bridge_dev =DO_UPCAST (PCIBridgeDev, bridge, br);int err; - err =pci_bridge_initfn (dev); + err =pci_bridge_initfn (dev,TYPE_PCI_BUS );if (err) { goto bridge_error; }
hw/piix_pci.c +1 -1
@@ -245,7 +245,7 @@ static PCIBus *i440fx_common_init(const char *device_name, dev =qdev_create (NULL ,"i440FX-pcihost" ); s =PCI_HOST_BRIDGE (dev); b =pci_bus_new (dev,NULL , pci_address_space, - address_space_io,0 ); + address_space_io,0 ,TYPE_PCI_BUS ); s->bus = b;object_property_add_child (qdev_get_machine (),"i440fx" ,OBJECT (dev),NULL );qdev_init_nofail (dev);
hw/ppc4xx_pci.c +1 -1
@@ -349,7 +349,7 @@ static int ppc4xx_pcihost_initfn(SysBusDevice *dev) 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 ); +get_system_io (),0 ,4 ,TYPE_PCI_BUS ); h->bus = b;pci_create_simple (b,0 ,"ppc4xx-host-bridge" );
hw/ppce500_pci.c +1 -1
@@ -356,7 +356,7 @@ static int e500_pcihost_initfn(SysBusDevice *dev) b =pci_register_bus (DEVICE (dev),NULL , mpc85xx_pci_set_irq, mpc85xx_pci_map_irq, s->irq, address_space_mem, - &s->pio,PCI_DEVFN (s->first_slot,0 ),4 ); + &s->pio,PCI_DEVFN (s->first_slot,0 ),4 ,TYPE_PCI_BUS ); h->bus = b;pci_create_simple (b,0 ,"e500-host-bridge" );
hw/prep_pci.c +1 -1
@@ -154,7 +154,7 @@ static void raven_pcihost_initfn(Object *obj)DeviceState *pci_dev;pci_bus_new_inplace (&s->pci_bus,DEVICE (obj),NULL , - address_space_mem, address_space_io,0 ); + address_space_mem, address_space_io,0 ,TYPE_PCI_BUS ); h->bus = &s->pci_bus;object_initialize (&s->pci_dev,TYPE_RAVEN_PCI_DEVICE );
hw/q35.c +2 -1
@@ -54,7 +54,8 @@ static int q35_host_init(SysBusDevice *dev)return -1 ; } b =pci_bus_new (&s->host.pci.busdev.qdev,"pcie.0" , - s->mch.pci_address_space, s->mch.address_space_io,0 ); + s->mch.pci_address_space, s->mch.address_space_io, +0 ,TYPE_PCI_BUS ); s->host.pci.bus = b;qdev_set_parent_bus (DEVICE (&s->mch),BUS (b));qdev_init_nofail (DEVICE (&s->mch));
hw/sh_pci.c +1 -1
@@ -124,7 +124,7 @@ static int sh_pci_device_init(SysBusDevice *dev) s->irq,get_system_memory (),get_system_io (), - PCI_DEVFN(0, 0), 4); + PCI_DEVFN(0, 0), 4, TYPE_PCI_BUS);memory_region_init_io (&s->memconfig_p4, &sh_pci_reg_ops, s,"sh_pci" ,0x224 ); memory_region_init_alias(&s->memconfig_a7, "sh_pci.2", &s->memconfig_p4,
hw/spapr_pci.c +1 -1
@@ -624,7 +624,7 @@ static int spapr_phb_init(SysBusDevice *s) bus =pci_register_bus (DEVICE (s), sphb->busname, pci_spapr_set_irq, pci_spapr_map_irq, sphb, &sphb->memspace, &sphb->iospace, -PCI_DEVFN (0 ,0 ),PCI_NUM_PINS ); +PCI_DEVFN (0 ,0 ),PCI_NUM_PINS ,TYPE_PCI_BUS ); phb->bus = bus; sphb->dma_window_start =0 ;
hw/unin_pci.c +2 -2
@@ -239,7 +239,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic, pic, &d->pci_mmio, address_space_io, - PCI_DEVFN(11, 0), 4); + PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);#if 0 pci_create_simple (h->bus,PCI_DEVFN (11 ,0 ),"uni-north" );
@@ -305,7 +305,7 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic, pic, &d->pci_mmio, address_space_io, - PCI_DEVFN(11, 0), 4); + PCI_DEVFN(11, 0), 4, TYPE_PCI_BUS);sysbus_mmio_map (s,0 ,0xf0800000 );sysbus_mmio_map (s,1 ,0xf0c00000 );
hw/versatile_pci.c +1 -1
@@ -70,7 +70,7 @@ static int pci_vpb_init(SysBusDevice *dev) bus =pci_register_bus (&dev->qdev,"pci" , pci_vpb_set_irq, pci_vpb_map_irq, s->irq,get_system_memory (),get_system_io (), -PCI_DEVFN (11 ,0 ),4 ); +PCI_DEVFN (11 ,0 ),4 ,TYPE_PCI_BUS );/* ??? Register memory space. */
hw/xio3130_downstream.c +1 -1
@@ -61,7 +61,7 @@ static int xio3130_downstream_initfn(PCIDevice *d)PCIESlot *s =DO_UPCAST (PCIESlot, port, p);int rc; - rc =pci_bridge_initfn (d); + rc =pci_bridge_initfn (d,TYPE_PCI_BUS );if (rc <0 ) {return rc; }
hw/xio3130_upstream.c +1 -1
@@ -57,7 +57,7 @@ static int xio3130_upstream_initfn(PCIDevice *d)PCIEPort *p =DO_UPCAST (PCIEPort, br, br);int rc; - rc =pci_bridge_initfn (d); + rc =pci_bridge_initfn (d,TYPE_PCI_BUS );if (rc <0 ) {return rc; }
PATCH 4/7 pci: Q35, Root Ports, and Switches create PCI Express buses
In reply to Alex WilliamsonConvert q35, ioh3420, xio3130_upstream, and xio3130_downstream to use the new TYPE_PCIE_BUS.
--- hw/ioh3420.c | 2 +- hw/q35.c | 2 +- hw/xio3130_downstream.c | 2 +- hw/xio3130_upstream.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
hw/ioh3420.c +1 -1
@@ -97,7 +97,7 @@ static int ioh3420_initfn(PCIDevice *d)PCIESlot *s =DO_UPCAST (PCIESlot, port, p);int rc; - rc =pci_bridge_initfn (d,TYPE_PCI_BUS ); + rc =pci_bridge_initfn (d,TYPE_PCIE_BUS );if (rc <0 ) {return rc; }
hw/q35.c +1 -1
@@ -55,7 +55,7 @@ static int q35_host_init(SysBusDevice *dev) } b =pci_bus_new (&s->host.pci.busdev.qdev,"pcie.0" , s->mch.pci_address_space, s->mch.address_space_io, -0 ,TYPE_PCI_BUS ); +0 ,TYPE_PCIE_BUS ); s->host.pci.bus = b;qdev_set_parent_bus (DEVICE (&s->mch),BUS (b));qdev_init_nofail (DEVICE (&s->mch));
hw/xio3130_downstream.c +1 -1
@@ -61,7 +61,7 @@ static int xio3130_downstream_initfn(PCIDevice *d)PCIESlot *s =DO_UPCAST (PCIESlot, port, p);int rc; - rc =pci_bridge_initfn (d,TYPE_PCI_BUS ); + rc =pci_bridge_initfn (d,TYPE_PCIE_BUS );if (rc <0 ) {return rc; }
hw/xio3130_upstream.c +1 -1
@@ -57,7 +57,7 @@ static int xio3130_upstream_initfn(PCIDevice *d)PCIEPort *p =DO_UPCAST (PCIEPort, br, br);int rc; - rc =pci_bridge_initfn (d,TYPE_PCI_BUS ); + rc =pci_bridge_initfn (d,TYPE_PCIE_BUS );if (rc <0 ) {return rc; }
PATCH 5/7 pci: Create pci_bus_is_express helper
In reply to Alex WilliamsonFor testing the bus type.
--- hw/pci/pci.c | 5 +++++ hw/pci/pci.h | 1 + 2 files changed, 6 insertions(+)
hw/pci/pci.c +5 -0
@@ -297,6 +297,11 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); } +bool pci_bus_is_express (PCIBus *bus) +{ +return object_dynamic_cast (OBJECT (bus),TYPE_PCIE_BUS ); +} + void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
hw/pci/pci.h +1 -0
@@ -344,6 +344,7 @@ typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev,#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)#define TYPE_PCIE_BUS "PCIE" +bool pci_bus_is_express (PCIBus *bus); void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
PATCH 6/7 pci: Create and use API to determine root buses
In reply to Alex Williamson--- hw/pci/pci.c | 13 +++++++++---- hw/pci/pci.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-)
hw/pci/pci.c +9 -4
@@ -302,6 +302,11 @@ bool pci_bus_is_express(PCIBus *bus)return object_dynamic_cast (OBJECT (bus),TYPE_PCIE_BUS ); } +bool pci_bus_is_root (PCIBus *bus) +{ +return !bus->parent_dev; +} + void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
@@ -360,7 +365,7 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,int pci_bus_num (PCIBus *s) { -if (!s->parent_dev) +if (pci_bus_is_root (s))return 0 ;/* pci host bridge */ return s->parent_dev->config[PCI_SECONDARY_BUS ]; }
@@ -1186,7 +1191,7 @@ static void pci_set_irq(void *opaque, int irq_num, int level)/* Special hooks used by device assignment */ void pci_bus_set_route_irq_fn (PCIBus *bus,pci_route_irq_fn route_intx_to_irq) { -assert (!bus->parent_dev); +assert (pci_bus_is_root (bus)); bus->route_intx_to_irq = route_intx_to_irq; }
@@ -1651,7 +1656,7 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num) }/* Consider all bus numbers in range for the host pci bridge. */ -if (bus->parent_dev && +if (!pci_bus_is_root (bus) && !pci_secondary_bus_in_range (bus->parent_dev, bus_num)) {return NULL ; }
@@ -1659,7 +1664,7 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num)/* try child bus */ for (; bus; bus = sec) { QLIST_FOREACH(sec, &bus->child, sibling) { -assert (sec->parent_dev); +assert (!pci_bus_is_root (sec));if (sec->parent_dev->config[PCI_SECONDARY_BUS ] == bus_num) {return sec; }
hw/pci/pci.h +1 -0
@@ -345,6 +345,7 @@ typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev,#define TYPE_PCIE_BUS "PCIE"bool pci_bus_is_express (PCIBus *bus); +bool pci_bus_is_root (PCIBus *bus); void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
PATCH 7/7 pcie: Mangle types to match topology
In reply to Alex WilliamsonWindows will fail to start drivers for devices with an Endpoint type PCIe capability attached to a Root Complex (code 10 - Device cannot start). The proper type for such a device is Root Complex Integrated Endpoint. Devices don't care which they are, so do this conversion automatically.
This allows the Windows driver to load for nec-usb-xhci when attached to pcie.0 of a q35 machine.
--- hw/pci/pcie.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/pci/pcie.c +13 -0
@@ -48,6 +48,19 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port)assert (pci_is_express (dev)); +/* +* Mangle type to convert Endpoints to Root Complex Integrated Endpoints. +* Windows will report Code 10 (device cannot start) for regular Endpoints +* on the Root Complex. +*/ +if (pci_bus_is_express (dev->bus) &&pci_bus_is_root (dev->bus)) { +switch (type) { +case PCI_EXP_TYPE_ENDPOINT : + type =PCI_EXP_TYPE_RC_END ; +break ; + } + } + pos =pci_add_capability (dev,PCI_CAP_ID_EXP , offset,PCI_EXP_VER2_SIZEOF );if (pos <0 ) {
Re: [Qemu-devel] [PATCH 7/7] pcie: Mangle types to match topology
Quoted 10 lines · Alex Williamson
Windows will fail to start drivers for devices with an Endpoint type PCIe capability attached to a Root Complex (code 10 - Device cannot start). The proper type for such a device is Root Complex Integrated Endpoint. Devices don't care which they are, so do this conversion automatically.
This allows the Windows driver to load for nec-usb-xhci when attached to pcie.0 of a q35 machine.
Signed-off-by Alex Williamson <[email protected]>
I think it's a bit ugly from the API perspective,
in that an integrated endpoint is not converted to a regular one.
I think it would be cleaner to have pcie_cap_init do exactly what it's told to do, maybe failing if you give it an incorrect configuration. On top of this add pcie_endpoint_cap_init which sets the type explicitly. Hmm?
Not critical, so applied as is for now.
Quoted 28 lines
--- hw/pci/pcie.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)hw/pci/pcie.c +13
-0@@ -48,6 +48,19 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port)assert (pci_is_express (dev)); +/* +* Mangle type to convert Endpoints to Root Complex Integrated Endpoints. +* Windows will report Code 10 (device cannot start) for regular Endpoints +* on the Root Complex. +*/ +if (pci_bus_is_express (dev->bus) &&pci_bus_is_root (dev->bus)) { +switch (type) { +case PCI_EXP_TYPE_ENDPOINT : + type =PCI_EXP_TYPE_RC_END ; +break ; + } + } + pos =pci_add_capability (dev,PCI_CAP_ID_EXP , offset,PCI_EXP_VER2_SIZEOF );if (pos <0 ) {
Re: [Qemu-devel] [PATCH 7/7] pcie: Mangle types to match topology
Quoted 15 lines · Michael S. Tsirkin
Quoted 10 lines · Alex Williamson
Windows will fail to start drivers for devices with an Endpoint type PCIe capability attached to a Root Complex (code 10 - Device cannot start). The proper type for such a device is Root Complex Integrated Endpoint. Devices don't care which they are, so do this conversion automatically.
This allows the Windows driver to load for nec-usb-xhci when attached to pcie.0 of a q35 machine.
Signed-off-by Alex Williamson <[email protected]>I think it's a bit ugly from the API perspective,
in that an integrated endpoint is not converted to a regular one.
Quoted 7 lines
I think it would be cleaner to have
pcie_cap_initdo exactly what it's told to do, maybe failing if you give it an incorrect configuration. On top of this addpcie_endpoint_cap_initwhich sets the type explicitly. Hmm?Not critical, so applied as is for now.
Thanks! I like the pcie_endpoint_cap_init idea, I'll make a wrapper that adds that and selects the correct type for the bus. Thanks,
Alex
Michael S. Tsirkin
AppliedQuoted 7 lines · Alex Williamson
When setting PCIe capabilities we need to know the type of bus we have. On secondary buses we could poke around on the parent bridge device to infer this data, but on root buses there's no parent device. By creating a new PCIE TypeInfo we can inherit everything about PCI buses while still allowing us to differentiate and potentially extend in the future.
Quoted 8 lines
The first benefactor of this change is included here, mangling Endpoints to Root Complex Integrated Endpoints, allowing nec-usb-xhci to work on the root bus of q35 with Windows. I also plan to use this to drop link capabilities, control, and status on all Integrated Endpoints and for PCIe capability modifications on assigned devices. Thanks,
Alex
Applied, thanks!
Quoted 39 lines
---
Alex Williamson (7):
pci: Create and register a new PCI Express TypeInfo
pci: Move PCI and PCIE type defines
pci: Allow PCI bus creation interfaces to specify the type of bus
pci: Q35, Root Ports, and Switches create PCI Express buses
pci: Createpci_bus_is_expresshelper
pci: Create and use API to determine root buses
pcie: Mangle types to match topologyhw/alpha_typhoon.c | 2 +- hw/apb_pci.c | 4 ++-- hw/bonito.c | 2 +- hw/dec_pci.c | 7 ++++++- hw/grackle_pci.c | 2 +- hw/gt64xxx.c | 2 +- hw/i82801b11.c | 2 +- hw/ioh3420.c | 2 +- hw/pci/pci.c | 36 ++++++++++++++++++++++++++---------- hw/pci/pci.h | 13 ++++++++++--- hw/pci/pci_bridge.c | 5 ++--- hw/pci/pci_bridge.h | 2 +- hw/pci/pci_bus.h | 3 --- hw/pci/pcie.c | 13 +++++++++++++ hw/pci_bridge_dev.c | 2 +- hw/piix_pci.c | 2 +- hw/ppc4xx_pci.c | 2 +- hw/ppce500_pci.c | 2 +- hw/prep_pci.c | 2 +- hw/q35.c | 3 ++- hw/sh_pci.c | 2 +- hw/spapr_pci.c | 2 +- hw/unin_pci.c | 4 ++-- hw/versatile_pci.c | 2 +- hw/xio3130_downstream.c | 2 +- hw/xio3130_upstream.c | 2 +- 26 files changed, 80 insertions(+), 42 deletions(-)