Skip to contentSkip to conversation

s390 pci infrastructure modeling

PATCH New Yi Min Zhao 1 participant 2 messages Aug 20, 2015

lore
Share & tools
lore
#0 lore raw

v5 cover s390 pci infrastructure modeling

From: Yi Min Zhao <[email protected]>

This patch extends the current s390 pci implementation to provide more flexibility in configuration of s390 specific device handling.

For each vfio pci device, I create a zpci device to store s390 specific informations. And attach all of these special zpci devices to the s390 facility bus. A zpci device references the corresponding PCI device via device id.

The new design allows to define multiple host bridges, each host bridge could hold 32 zpci devices at most. Add a new property named index to s390-pcihost device and must assign a unique value to it in qemu command line.

The topology for this implementation could be:

dev: s390-pcihost, id ""

    index=1
    bus: pci.0
      type PCI
      dev: vfio-pci, id "vpci1"
        host = "0000:00:00.0"
	......
      dev: vfio-pci, id "vpci2"
        host = "0001:00:00.0"
	......
  dev: s390-pci-facility, id ""
    bus: s390-pci-fac-bus.0
      type s390-pci-fac-bus
      dev: zpci, id "zpci1"
        fid = 1 (0x1)
        uid = 2 (0x2)
        pci_id = "vpci1"
      dev: zpci, id "zpci2"
        fid = 6 (0x6)
        uid = 7 (0x7)
        pci_id = "vpci2"

To make the review easier, I keep all of the old names, such as S390PCIBusDevice to name a zpci device. I will make a cleanup patch later to change these names to a more suitable name.

Comparing to v4, this patch does the following change:
1.Add index property to s390-pcihost device.
2.Add index to s390PCIBusDevice. Its value is assigned by logical
OR s390-pcihost device's index and pci slot.
3.Add three usable macros to get zpci index and s390pcihost index. 4.Add a bool member to s390PCIBustDevice named "available" to judge
whether the relationship of zpci and vfio pci is established. This change fixed a bug generated by previous code in case that only define zpci device and then hot unplug it will fail.
5.Rework s390_pci_find_dev_by_idx function.
6.Rework s390_pci_device_hot_unplug_request function to be more
stable.
7.Rework s390_pci_device_unrealize function to make the process of
pci device unplug more logical and stable.

Comparing to v3, this patch does the following change:
1.Exchange vfio-pci and zpci definitions. Define zpci device firstly
then define vfio-pci device.
2.Unplug either vfio-pci device or zpci device can remove both of them.

Yi Min Zhao (1):
s390x: pci infrastructure modeling

 hw/s390x/s390-pci-bus.c    |  379 ++++++++++++++++++++++++++++++++++----------
 hw/s390x/s390-pci-bus.h    |   54 ++++++-
 hw/s390x/s390-pci-inst.c   |   80 ++++++----
 hw/s390x/s390-virtio-ccw.c |    5 +-
 4 files changed, 392 insertions(+), 126 deletions(-)
Signature · 1 line
1.7.9
#1 lore raw

PATCH v5 1/1 s390x: pci infrastructure modeling

From: Yi Min Zhao <[email protected]>

This patch introduce a new facility(and bus) to hold devices representing information actually provided by s390 firmware and I/O configuration. usage example:
-device s390-pcihost,index=1
-device zpci,fid=2,uid=5,pci_id=vpci1,id=zpci1 -device vfio-pci,host=0000:00:00.0,id=vpci1

The first line will create a s390 pci host bridge and init the root bus. And user must assign a unique value to index which is a new property of s390-pcihost device.
The second line will create a s390 pci device to store s390 specific information, and references the corresponding vfio pci device via device id. We create a s390 pci facility bus to hold all the zpci devices.
The third line will create a standard vfio pci device, and attach it to the root bus. These are similiar to the standard process to define a pci device on other platform.

---
 hw/s390x/s390-pci-bus.c    |  379 ++++++++++++++++++++++++++++++++++----------
 hw/s390x/s390-pci-bus.h    |   54 ++++++-
 hw/s390x/s390-pci-inst.c   |   80 ++++++----
 hw/s390x/s390-virtio-ccw.c |    5 +-
 4 files changed, 392 insertions(+), 126 deletions(-)
hw/s390x/s390-pci-bus.c +292 -87
index 560b66a..524dd79 100644
@@ -32,16 +32,16 @@ int chsc_sei_nt2_get_event(void *res)
     PciCcdfErr *eccdf;
     int rc = 1;
     SeiContainer *sei_cont;
-    S390pciState *s = S390_PCI_HOST_BRIDGE(
-        object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    if (!s) {
+    if (!f) {
         return rc;
     }
 
-    sei_cont = QTAILQ_FIRST(&s->pending_sei);
+    sei_cont = QTAILQ_FIRST(&f->pending_sei);
     if (sei_cont) {
-        QTAILQ_REMOVE(&s->pending_sei, sei_cont, link);
+        QTAILQ_REMOVE(&f->pending_sei, sei_cont, link);
         nt2_res->nt = 2;
         nt2_res->cc = sei_cont->cc;
         nt2_res->length = cpu_to_be16(sizeof(ChscSeiNt2Res));
@@ -72,30 +72,41 @@ int chsc_sei_nt2_get_event(void *res)
 
 int chsc_sei_nt2_have_event(void)
 {
-    S390pciState *s = S390_PCI_HOST_BRIDGE(
-        object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    if (!s) {
+    if (!f) {
         return 0;
     }
 
-    return !QTAILQ_EMPTY(&s->pending_sei);
+    return !QTAILQ_EMPTY(&f->pending_sei);
+}
+
+void s390_pci_device_enable(S390PCIBusDevice *zpci)
+{
+    zpci->fh = zpci->fh | 1 << ENABLE_BIT_OFFSET;
+}
+
+void s390_pci_device_disable(S390PCIBusDevice *zpci)
+{
+    zpci->fh = zpci->fh & ~(1 << ENABLE_BIT_OFFSET);
+    if (zpci->is_unplugged) {
+        object_unparent(OBJECT(zpci));
+    }
 }
 
 S390PCIBusDevice *s390_pci_find_dev_by_fid(uint32_t fid)
 {
     S390PCIBusDevice *pbdev;
-    int i;
-    S390pciState *s = S390_PCI_HOST_BRIDGE(
-        object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    if (!s) {
+    if (!f) {
         return NULL;
     }
 
-    for (i = 0; i < PCI_SLOT_MAX; i++) {
-        pbdev = &s->pbdev[i];
-        if ((pbdev->fh != 0) && (pbdev->fid == fid)) {
+    QTAILQ_FOREACH(pbdev, &f->zpci_list, next) {
+        if (pbdev->fid == fid) {
             return pbdev;
         }
     }
@@ -126,39 +137,20 @@ void s390_pci_sclp_configure(int configure, SCCB *sccb)
     return;
 }
 
-static uint32_t s390_pci_get_pfid(PCIDevice *pdev)
-{
-    return PCI_SLOT(pdev->devfn);
-}
-
-static uint32_t s390_pci_get_pfh(PCIDevice *pdev)
+S390PCIBusDevice *s390_pci_find_dev_by_idx(uint64_t idx)
 {
-    return PCI_SLOT(pdev->devfn) | FH_VIRT;
-}
-
-S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx)
-{
-    S390PCIBusDevice *pbdev;
-    int i;
-    int j = 0;
-    S390pciState *s = S390_PCI_HOST_BRIDGE(
-        object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
+    S390PCIBusDevice *tmp;
+    S390PCIFacility *fac = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    if (!s) {
+    if (!fac) {
         return NULL;
     }
 
-    for (i = 0; i < PCI_SLOT_MAX; i++) {
-        pbdev = &s->pbdev[i];
-
-        if (pbdev->fh == 0) {
-            continue;
-        }
-
-        if (j == idx) {
-            return pbdev;
+    QTAILQ_FOREACH(tmp, &fac->zpci_list, next) {
+        if (idx == tmp->idx && tmp->available) {
+            return tmp;
         }
-        j++;
     }
 
     return NULL;
@@ -167,16 +159,14 @@ S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx)
 S390PCIBusDevice *s390_pci_find_dev_by_fh(uint32_t fh)
 {
     S390PCIBusDevice *pbdev;
-    int i;
-    S390pciState *s = S390_PCI_HOST_BRIDGE(
-        object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    if (!s || !fh) {
+    if (!f || !fh) {
         return NULL;
     }
 
-    for (i = 0; i < PCI_SLOT_MAX; i++) {
-        pbdev = &s->pbdev[i];
+    QTAILQ_FOREACH(pbdev, &f->zpci_list, next) {
         if (pbdev->fh == fh) {
             return pbdev;
         }
@@ -189,10 +179,10 @@ static void s390_pci_generate_event(uint8_t cc, uint16_t pec, uint32_t fh,
                                     uint32_t fid, uint64_t faddr, uint32_t e)
 {
     SeiContainer *sei_cont;
-    S390pciState *s = S390_PCI_HOST_BRIDGE(
-        object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE, NULL));
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    if (!s) {
+    if (!f) {
         return;
     }
 
@@ -204,7 +194,7 @@ static void s390_pci_generate_event(uint8_t cc, uint16_t pec, uint32_t fh,
     sei_cont->faddr = faddr;
     sei_cont->e = e;
 
-    QTAILQ_INSERT_TAIL(&s->pending_sei, sei_cont, link);
+    QTAILQ_INSERT_TAIL(&f->pending_sei, sei_cont, link);
     css_generate_css_crws(0);
 }
 
@@ -308,7 +298,10 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr,
 {
     uint64_t pte;
     uint32_t flags;
-    S390PCIBusDevice *pbdev = container_of(iommu, S390PCIBusDevice, mr);
+    S390PCIDeviceConn *conn = container_of(iommu, S390PCIDeviceConn,
+                                           iommu_mr);
+    S390PCIBusDevice *pbdev = conn->zpci;
+
     S390pciState *s = S390_PCI_HOST_BRIDGE(pci_device_root_bus(pbdev->pdev)
                                            ->qbus.parent);
     IOMMUTLBEntry ret = {
@@ -382,7 +375,7 @@ static AddressSpace *s390_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
 {
     S390pciState *s = opaque;
 
-    return &s->pbdev[PCI_SLOT(devfn)].as;
+    return &s->conn[PCI_SLOT(devfn)].iommu_as;
 }
 
 static uint8_t set_ind_atomic(uint64_t ind_loc, uint8_t to_be_set)
@@ -455,9 +448,10 @@ static void s390_pcihost_init_as(S390pciState *s)
     int i;
 
     for (i = 0; i < PCI_SLOT_MAX; i++) {
-        memory_region_init_iommu(&s->pbdev[i].mr, OBJECT(s),
+        memory_region_init_iommu(&s->conn[i].iommu_mr, OBJECT(s),
                                  &s390_iommu_ops, "iommu-s390", UINT64_MAX);
-        address_space_init(&s->pbdev[i].as, &s->pbdev[i].mr, "iommu-pci");
+        address_space_init(&s->conn[i].iommu_as, &s->conn[i].iommu_mr,
+                           "iommu-pci");
     }
 
     memory_region_init_io(&s->msix_notify_mr, OBJECT(s),
@@ -465,27 +459,57 @@ static void s390_pcihost_init_as(S390pciState *s)
     address_space_init(&s->msix_notify_as, &s->msix_notify_mr, "msix-pci");
 }
 
-static int s390_pcihost_init(SysBusDevice *dev)
+static S390pciState *s390_find_pcihost_by_idx(uint32_t idx)
+{
+    S390pciState *s;
+    S390PCIFacility *fac = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
+
+    QTAILQ_FOREACH(s, &fac->zpcistate_list, next) {
+        if (s->idx == idx) {
+            return s;
+        }
+    }
+
+    return NULL;
+}
+
+static void s390_pcihost_realize(DeviceState *dev, Error **errp)
 {
     PCIBus *b;
     BusState *bus;
     PCIHostState *phb = PCI_HOST_BRIDGE(dev);
     S390pciState *s = S390_PCI_HOST_BRIDGE(dev);
+    S390PCIFacility *fac = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
     DPRINTF("host_init\n");
 
+    if (s->idx == (uint32_t)-1) {
+        error_setg(errp, "s390 pci host bridge index not specified");
+        return;
+    }
+
+    if (s390_find_pcihost_by_idx(s->idx)) {
+        error_setg(errp, "s390 pci host bridge must have unique index");
+        return;
+    }
+
     b = pci_register_bus(DEVICE(dev), NULL,
                          s390_pci_set_irq, s390_pci_map_irq, NULL,
                          get_system_memory(), get_system_io(), 0, 64,
                          TYPE_PCI_BUS);
+
     s390_pcihost_init_as(s);
     pci_setup_iommu(b, s390_pci_dma_iommu, s);
 
     bus = BUS(b);
     qbus_set_hotplug_handler(bus, DEVICE(dev), NULL);
     phb->bus = b;
-    QTAILQ_INIT(&s->pending_sei);
-    return 0;
+
+    QTAILQ_INSERT_HEAD(&fac->zpcistate_list, s, next);
+
+    return;
 }
 
 static int s390_pcihost_setup_msix(S390PCIBusDevice *pbdev)
@@ -519,25 +543,37 @@ static int s390_pcihost_setup_msix(S390PCIBusDevice *pbdev)
 static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
                                   DeviceState *dev, Error **errp)
 {
-    PCIDevice *pci_dev = PCI_DEVICE(dev);
-    S390PCIBusDevice *pbdev;
-    S390pciState *s = S390_PCI_HOST_BRIDGE(pci_device_root_bus(pci_dev)
-                                           ->qbus.parent);
+    PCIDevice *pdev = PCI_DEVICE(dev);
+    S390PCIBusDevice *zpci;
+    S390pciState *s;
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
 
-    pbdev = &s->pbdev[PCI_SLOT(pci_dev->devfn)];
+    QTAILQ_FOREACH(zpci, &f->zpci_list, next) {
+        if (!strcmp(zpci->pci_id, pdev->qdev.id)) {
+            break;
+        }
+    }
 
-    pbdev->fid = s390_pci_get_pfid(pci_dev);
-    pbdev->pdev = pci_dev;
-    pbdev->configured = true;
-    pbdev->fh = s390_pci_get_pfh(pci_dev);
+    if (!zpci) {
+        error_setg(errp, "zpci device %s not found", pdev->qdev.id);
+        return;
+    }
 
-    s390_pcihost_setup_msix(pbdev);
+    s = S390_PCI_HOST_BRIDGE(pci_device_root_bus(pdev)->qbus.parent);
+    s->conn[PCI_SLOT(pdev->devfn)].zpci = zpci;
+    zpci->available = true;
+    zpci->configured = true;
+    zpci->pdev = pdev;
+    zpci->fh = zpci->fid | FH_VIRT;
+    zpci->idx = S390_ZPCI_IDX(s->idx, PCI_SLOT(pdev->devfn));
+    s390_pcihost_setup_msix(zpci);
 
     if (dev->hotplugged) {
         s390_pci_generate_plug_event(HP_EVENT_RESERVED_TO_STANDBY,
-                                     pbdev->fh, pbdev->fid);
+                                     zpci->fh, zpci->fid);
         s390_pci_generate_plug_event(HP_EVENT_TO_CONFIGURED,
-                                     pbdev->fh, pbdev->fid);
+                                     zpci->fh, zpci->fid);
     }
     return;
 }
@@ -546,34 +582,44 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,
                                     DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_dev = PCI_DEVICE(dev);
-    S390pciState *s = S390_PCI_HOST_BRIDGE(pci_device_root_bus(pci_dev)
-                                           ->qbus.parent);
-    S390PCIBusDevice *pbdev = &s->pbdev[PCI_SLOT(pci_dev->devfn)];
+    S390PCIBusDevice *pbdev;
+    HotplugHandler *hotplug_ctrl;
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(f);
+    HotplugHandlerClass *hdc = HOTPLUG_HANDLER_CLASS(k);
+
+    /* unplug corresponding zpci device */
+    QTAILQ_FOREACH(pbdev, &f->zpci_list, next) {
+        if (!strcmp(pbdev->pci_id, pci_dev->qdev.id)) {
+            break;
+        }
+    }
 
-    if (pbdev->configured) {
-        pbdev->configured = false;
-        s390_pci_generate_plug_event(HP_EVENT_CONFIGURED_TO_STBRES,
-                                     pbdev->fh, pbdev->fid);
+    if (pbdev) {
+        hotplug_ctrl = pbdev->qdev.parent_bus->hotplug_handler;
+        if (hdc->unplug_request) {
+            hdc->unplug_request(hotplug_ctrl, &pbdev->qdev, errp);
+        }
     }
 
-    s390_pci_generate_plug_event(HP_EVENT_STANDBY_TO_RESERVED,
-                                 pbdev->fh, pbdev->fid);
-    pbdev->fh = 0;
-    pbdev->fid = 0;
-    pbdev->pdev = NULL;
     object_unparent(OBJECT(pci_dev));
 }
 
+static Property s390_pcihost_properties[] = {
+    DEFINE_PROP_UINT32("index", S390pciState, idx, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void s390_pcihost_class_init(ObjectClass *klass, void *data)
 {
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
 
-    dc->cannot_instantiate_with_device_add_yet = true;
-    k->init = s390_pcihost_init;
+    dc->realize = s390_pcihost_realize;
     hc->plug = s390_pcihost_hot_plug;
     hc->unplug = s390_pcihost_hot_unplug;
+    dc->props = s390_pcihost_properties;
     msi_supported = true;
 }
 
@@ -588,9 +634,168 @@ static const TypeInfo s390_pcihost_info = {
     }
 };
 
+static void s390_pci_device_hot_plug(HotplugHandler *hotplug_dev,
+                                     DeviceState *dev, Error **errp)
+{
+    S390PCIBusDevice *zpci = S390_PCI_DEVICE(dev);
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
+
+    QTAILQ_INSERT_HEAD(&f->zpci_list, zpci, next);
+}
+
+static void s390_pci_device_hot_unplug_request(HotplugHandler *hotplug_dev,
+                                       DeviceState *dev, Error **errp)
+{
+    S390PCIBusDevice *zpci = S390_PCI_DEVICE(dev);
+
+    if (!zpci->available) {
+        object_unparent(OBJECT(zpci));
+        return;
+    }
+
+    zpci->is_unplugged = true;
+    if (zpci->configured) {
+        zpci->configured = false;
+        s390_pci_generate_plug_event(HP_EVENT_CONFIGURED_TO_STBRES,
+                                     zpci->fh, zpci->fid);
+    }
+
+    s390_pci_generate_plug_event(HP_EVENT_STANDBY_TO_RESERVED,
+                                 zpci->fh, zpci->fid);
+}
+
+static const TypeInfo s390_pci_fac_bus_info = {
+    .name = TYPE_S390_PCI_FAC_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = sizeof(S390PCIFacBus),
+};
+
+static int s390_pci_facility_init(SysBusDevice *dev)
+{
+    S390PCIFacility *f = S390_PCI_FACILITY(dev);
+    DeviceState *s = DEVICE(f);
+
+    QTAILQ_INIT(&f->zpcistate_list);
+    QTAILQ_INIT(&f->zpci_list);
+    QTAILQ_INIT(&f->pending_sei);
+    msi_supported = true;
+    f->fbus = S390_PCI_FAC_BUS(qbus_create(TYPE_S390_PCI_FAC_BUS, s, NULL));
+    qbus_set_hotplug_handler(BUS(&f->fbus->qbus), DEVICE(s), NULL);
+
+    return 0;
+}
+
+static void s390_pci_facility_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(k);
+
+    k->init = s390_pci_facility_init;
+    hc->plug = s390_pci_device_hot_plug;
+    hc->unplug_request = s390_pci_device_hot_unplug_request;
+}
+
+static const TypeInfo s390_pci_facility_info = {
+    .name          = TYPE_S390_PCI_FACILITY,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(S390PCIFacility),
+    .class_init    = s390_pci_facility_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_HOTPLUG_HANDLER },
+        { }
+    }
+};
+
+static void s390_pci_device_realize(DeviceState *dev, Error **errp)
+{
+    S390PCIBusDevice *zpci = S390_PCI_DEVICE(dev);
+    S390PCIBusDevice *tmp;
+    PCIDevice *pdev;
+    int ret;
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
+
+    ret = pci_qdev_find_device(zpci->pci_id, &pdev);
+    if (!ret) {
+        error_setg(errp, "there is already vfio pci device %s", zpci->pci_id);
+        return;
+    }
+
+    QTAILQ_FOREACH(tmp, &f->zpci_list, next) {
+        if (tmp->fid == zpci->fid || tmp->uid == zpci->uid ||
+            !strcmp(tmp->pci_id, zpci->pci_id)) {
+            error_setg(errp, "zpci needs unique fid, uid and pci_id");
+            return;
+        }
+    }
+}
+
+static void s390_pci_device_unrealize(DeviceState *dev, Error **errp)
+{
+    S390pciState *s;
+    S390PCIBusDevice *zpci = S390_PCI_DEVICE(dev);
+    S390PCIFacility *f = S390_PCI_FACILITY(
+        object_resolve_path(TYPE_S390_PCI_FACILITY, NULL));
+    PCIDevice *pdev;
+    HotplugHandler *hotplug_ctrl;
+    SysBusDeviceClass *k;
+    HotplugHandlerClass *hdc;
+    int ret;
+
+    if (zpci->available) {
+        s = s390_find_pcihost_by_idx(S390_PCISTATE_IDX(zpci->idx));
+        s->conn[S390_ZPCI_SLOT(zpci->idx)].zpci = NULL;
+    }
+
+    QTAILQ_REMOVE(&f->zpci_list, zpci, next);
+    zpci->fh = 0;
+    zpci->fid = 0;
+    zpci->idx = 0;
+    zpci->pdev = NULL;
+
+    ret = pci_qdev_find_device(zpci->pci_id, &pdev);
+    if (!ret) {
+        hotplug_ctrl = pdev->qdev.parent_bus->hotplug_handler;
+        k = SYS_BUS_DEVICE_GET_CLASS(s);
+        hdc = HOTPLUG_HANDLER_CLASS(k);
+        if (hdc->unplug) {
+            hdc->unplug(hotplug_ctrl, &pdev->qdev, errp);
+        }
+    }
+}
+
+static Property s390_pci_device_properties[] = {
+    DEFINE_PROP_UINT32("fid", S390PCIBusDevice, fid, 0),
+    DEFINE_PROP_UINT32("uid", S390PCIBusDevice, uid, 0),
+    DEFINE_PROP_STRING("pci_id", S390PCIBusDevice, pci_id),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void s390_pci_device_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->desc = "s390 pci device";
+    dc->bus_type = TYPE_S390_PCI_FAC_BUS;
+    dc->realize = s390_pci_device_realize;
+    dc->unrealize = s390_pci_device_unrealize;
+    dc->props = s390_pci_device_properties;
+}
+
+static const TypeInfo s390_pci_device_type_info = {
+    .name = TYPE_S390_PCI_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(S390PCIBusDevice),
+    .class_init = s390_pci_device_class_init,
+};
+
 static void s390_pci_register_types(void)
 {
     type_register_static(&s390_pcihost_info);
+    type_register_static(&s390_pci_facility_info);
+    type_register_static(&s390_pci_fac_bus_info);
+    type_register_static(&s390_pci_device_type_info);
 }
 
 type_init(s390_pci_register_types)
hw/s390x/s390-pci-bus.h +49 -5

95 lines not on this page · raw message

hw/s390x/s390-pci-inst.c +48 -32

114 lines not on this page · raw message

hw/s390x/s390-virtio-ccw.c +3 -2
index b370b96..aa8b7c0 100644
@@ -130,8 +130,8 @@ static void ccw_init(MachineState *machine)
                       machine->initrd_filename, "s390-ccw.img", true);
     s390_flic_init();
 
-    dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
-    object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
+    dev = qdev_create(NULL, TYPE_S390_PCI_FACILITY);
+    object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_FACILITY,
                               OBJECT(dev), NULL);
     qdev_init_nofail(dev);
 
@@ -174,6 +174,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data)
     mc->use_sclp = 1;
     mc->max_cpus = 255;
     mc->hot_add_cpu = ccw_hot_add_cpu;
+    mc->has_dynamic_sysbus = true;
     nc->nmi_monitor_handler = s390_nmi;
 }
 
Signature · 1 line
1.7.9