s390x: the big pci update
cover s390x: the big pci update
We had been looking at remodelling the pci representation for s390x to handle our slightly odd architecture correctly some time ago already, but now we have a patchset that we're happy with.
There's a bunch of bugfixes, cleanups and architecture conformance changes in there, but the most interesting part is the modelling (which, in some respects, takes a cue from what sPAPR does).
We introduce a 'zpci' device to hold s390x-specific properties like the uid and fid. This 'zpci' device is connected to a run-of-the-mill pci device via the 'target' property.
Example command line portion:
-device zpci,uid=1,fid=1,target=vpci0 \
-device vfio-pci,host=0000:00:00.0,id=vpci0 \
-device zpci,target=vpci1 \
-device vfio-pci,host=0001:00:00.0,id=vpci1 \
-device vfio-pci,host=0002:00:00.0,id=vpci2
For device vpci0, uid and fid are specified in the associated zpci device.
For device vpci1, uid and fid are automatically generated. For device vpci2, first an associated zpci device is generated and then autogenerated values for uid and fid are placed in it.
This should accomodate both specifying our special parameters and re-using standard statements for pci devices. You can still specify bus/slot/function for the pci device, but it will not be propagated into the guest (as the s390 pci architecture does not allow for it; the guest only sees uid/fid).
The "introduce S390PCI<foo>" patches are probably the most interesting for those looking at the modelling.
I'd love to see some feedback from a PCI perspective, as I'm happy from the s390x perspective (and I'd like to see this in 2.7).
Branch available at git://github.com/cohuck/qemu s390x-pci-update
Yi Min Zhao (17):
s390x/pci: fix failures of dma map/unmap s390x/pci: acceleration for getting S390pciState s390x/pci: write fid in CLP_QUERY_PCI_FN s390x/pci: unify FH_ macros
s390x/pci: refactor s390_pci_find_dev_by_fh s390x/pci: enforce zPCI state checking s390x/pci: introduce S390PCIBus
s390x/pci: introduce S390PCIIOMMU s390x/pci: introduce S390PCIBusDevice qdev s390x/pci: enable uid-checking
s390x/pci: enable zpci hot-plug/hot-unplug s390x/pci: add checkings in CLP_SET_PCI_FN s390x/pci: refactor s390_pci_find_dev_by_idx s390x/pci: refactor list_pci
s390x/pci: fix stpcifc_service_call s390x/pci: replace fid with idx in msg data of msix s390x/pci: make hot-unplug handler smoother
hw/s390x/s390-pci-bus.c | 579 +++++++++++++++++++++++++++++++++++------------ hw/s390x/s390-pci-bus.h | 77 ++++++- hw/s390x/s390-pci-inst.c | 266 ++++++++++++++++------ hw/s390x/s390-pci-inst.h | 7 +- include/hw/s390x/sclp.h | 1 + target-s390x/kvm.c | 4 +- 6 files changed, 718 insertions(+), 216 deletions(-)
Signature · 1 line
2.9.0
PATCH 1/17 s390x/pci: fix failures of dma map/unmap
From: Yi Min Zhao <[email protected]>
In commit d78c19b5cf4821d0c198f4132a085bdbf19dda4c, vfio code stores the IOMMU's offset_within_address_space and adjusts the IOVA before calling vfio_dma_map/vfio_dma_unmap. But s390_translate_iommu already considers the base address of an IOMMU memory region.
Thus we use pal as the size and 0x0 as the base address to initialize IOMMU memory subregion.
--- hw/s390x/s390-pci-bus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/s390x/s390-pci-bus.c +2 -4
@@ -498,11 +498,9 @@ static const MemoryRegionOps s390_msi_ctrl_ops = {void s390_pci_iommu_enable (S390PCIBusDevice *pbdev) { -uint64_t size = pbdev->pal - pbdev->pba +1 ; -memory_region_init_iommu (&pbdev->iommu_mr,OBJECT (&pbdev->mr), - &s390_iommu_ops,"iommu-s390" , size); -memory_region_add_subregion (&pbdev->mr, pbdev->pba, &pbdev->iommu_mr); + &s390_iommu_ops,"iommu-s390" , pbdev->pal +1 ); +memory_region_add_subregion (&pbdev->mr,0 , &pbdev->iommu_mr); pbdev->iommu_enabled = true; }
Signature · 1 line
2.9.0
PATCH 2/17 s390x/pci: acceleration for getting S390pciState
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
There are a number of places where the code needs to get the instance of S390pciState. It calls object_resolve_path() every time. This wastes a lot of time and leads to low performance. Thus we add s390_get_phb() to improve it.
Because we always have a phb, we remove all return checkings in the callers and add an assert in s390_get_phb() to make sure that phb is getted successfully.
--- hw/s390x/s390-pci-bus.c | 53 +++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 33 deletions(-)
hw/s390x/s390-pci-bus.c +20 -33
@@ -29,6 +29,19 @@ do { } while (0)#endif +static S390pciState *s390_get_phb (void ) +{ +static S390pciState *phb; + +if (!phb) { + phb =S390_PCI_HOST_BRIDGE ( +object_resolve_path (TYPE_S390_PCI_HOST_BRIDGE ,NULL )); +assert (phb !=NULL ); + } + +return phb; +} +int chsc_sei_nt2_get_event (void *res) {ChscSeiNt2Res *nt2_res = (ChscSeiNt2Res *)res;
@@ -36,12 +49,7 @@ 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 )); - -if (!s) { -return rc; - } +S390pciState *s =s390_get_phb (); sei_cont =QTAILQ_FIRST (&s->pending_sei);if (sei_cont) {
@@ -76,12 +84,7 @@ 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 )); - -if (!s) { -return 0 ; - } +S390pciState *s =s390_get_phb ();return !QTAILQ_EMPTY (&s->pending_sei); }
@@ -90,12 +93,7 @@ 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 )); - -if (!s) { -return NULL ; - } +S390pciState *s =s390_get_phb ();for (i =0 ; i <PCI_SLOT_MAX ; i++) { pbdev = &s->pbdev[i];
@@ -180,12 +178,7 @@ 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 )); - -if (!s) { -return NULL ; - } +S390pciState *s =s390_get_phb ();for (i =0 ; i <PCI_SLOT_MAX ; i++) { pbdev = &s->pbdev[i];
@@ -207,10 +200,9 @@ 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 )); +S390pciState *s =s390_get_phb (); -if (!s || !fh) { +if (!fh) {return NULL ; }
@@ -228,12 +220,7 @@ 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 )); - -if (!s) { -return ; - } +S390pciState *s =s390_get_phb (); sei_cont =g_malloc0 (sizeof (SeiContainer)); sei_cont->fh = fh;
Signature · 1 line
2.9.0
PATCH 3/17 s390x/pci: write fid in CLP_QUERY_PCI_FN
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
We forgot to write the fid; fix that.
--- hw/s390x/s390-pci-inst.c | 1 + 1 file changed, 1 insertion(+)
hw/s390x/s390-pci-inst.c +1 -0
@@ -256,6 +256,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)stq_p (&resquery->sdma,ZPCI_SDMA_ADDR );stq_p (&resquery->edma,ZPCI_EDMA_ADDR ); +stl_p (&resquery->fid, pbdev->fid);stw_p (&resquery->pchid,0 );stw_p (&resquery->ug,1 );stl_p (&resquery->uid, pbdev->fid);
Signature · 1 line
2.9.0
PATCH 4/17 s390x/pci: unify FH_ macros
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Present code uses some macros to structure PCI Function Handle. But their names don't have a uniform format. Let's use FH_MASK_ as the unified prefix.
While we're at it, differentiate the SHM bits: use different bits for vfio and emulated devices.
--- hw/s390x/s390-pci-bus.c | 6 +++--- hw/s390x/s390-pci-bus.h | 9 ++++++--- hw/s390x/s390-pci-inst.c | 18 +++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-)
hw/s390x/s390-pci-bus.c +3 -3
@@ -170,7 +170,7 @@ static uint32_t s390_pci_get_pfid(PCIDevice *pdev)static uint32_t s390_pci_get_pfh (PCIDevice *pdev) { -return PCI_SLOT (pdev->devfn) |FH_VIRT ; +return PCI_SLOT (pdev->devfn) |FH_SHM_VFIO ; }S390PCIBusDevice *s390_pci_find_dev_by_idx (uint32_t idx)
@@ -345,7 +345,7 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr, };if (!pbdev->configured || !pbdev->pdev || - !(pbdev->fh &FH_ENABLED ) || !pbdev->iommu_enabled) { + !(pbdev->fh &FH_MASK_ENABLE ) || !pbdev->iommu_enabled) {return ret; }
@@ -456,7 +456,7 @@ static void s390_msi_ctrl_write(void *opaque, hwaddr addr, uint64_t data,return ; } -if (!(pbdev->fh &FH_ENABLED )) { +if (!(pbdev->fh &FH_MASK_ENABLE )) {return ; }
hw/s390x/s390-pci-bus.h +6 -3
@@ -21,9 +21,12 @@#include "hw/s390x/css.h" #define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost" -#define FH_VIRT 0x00ff0000 -#define ENABLE_BIT_OFFSET 31 -#define FH_ENABLED (1 << ENABLE_BIT_OFFSET) +#define FH_MASK_ENABLE 0x80000000 +#define FH_MASK_INSTANCE 0x7f000000 +#define FH_MASK_SHM 0x00ff0000 +#define FH_MASK_INDEX 0x0000001f +#define FH_SHM_VFIO 0x00010000 +#define FH_SHM_EMUL 0x00020000#define S390_PCIPT_ADAPTER 2#define S390_PCI_HOST_BRIDGE (obj) \
hw/s390x/s390-pci-inst.c +9 -9
@@ -92,7 +92,7 @@ static int list_pci(ClpReqRspListPci *rrb, uint8_t *cc)stl_p (&rrb->response.fmt,0 );stq_p (&rrb->response.reserved1,0 );stq_p (&rrb->response.reserved2,0 ); -stl_p (&rrb->response.mdd,FH_VIRT ); +stl_p (&rrb->response.mdd,FH_MASK_SHM );stw_p (&rrb->response.max_fn,PCI_MAX_FUNCTIONS ); rrb->response.entry_size =sizeof (ClpFhListEntry); finish =0 ;
@@ -212,12 +212,12 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)switch (reqsetpci->oc) {case CLP_SET_ENABLE_PCI_FN : - pbdev->fh = pbdev->fh |FH_ENABLED ; + pbdev->fh |=FH_MASK_ENABLE ;stl_p (&ressetpci->fh, pbdev->fh);stw_p (&ressetpci->hdr.rsp,CLP_RC_OK );break ;case CLP_SET_DISABLE_PCI_FN : - pbdev->fh = pbdev->fh & ~FH_ENABLED ; + pbdev->fh &= ~FH_MASK_ENABLE ; pbdev->error_state = false; pbdev->lgstg_blocked = false;stl_p (&ressetpci->fh, pbdev->fh);
@@ -318,7 +318,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2) offset = env->regs[r2 +1 ]; pbdev =s390_pci_find_dev_by_fh (fh); -if (!pbdev || !(pbdev->fh &FH_ENABLED )) { +if (!pbdev || !(pbdev->fh &FH_MASK_ENABLE )) {DPRINTF ("pcilg no pci dev\n" );setcc (cpu,ZPCI_PCI_LS_INVAL_HANDLE );return 0 ;
@@ -435,7 +435,7 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2) offset = env->regs[r2 +1 ]; pbdev =s390_pci_find_dev_by_fh (fh); -if (!pbdev || !(pbdev->fh &FH_ENABLED )) { +if (!pbdev || !(pbdev->fh &FH_MASK_ENABLE )) {DPRINTF ("pcistg no pci dev\n" );setcc (cpu,ZPCI_PCI_LS_INVAL_HANDLE );return 0 ;
@@ -526,7 +526,7 @@ int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2) end = start + env->regs[r2 +1 ]; pbdev =s390_pci_find_dev_by_fh (fh); -if (!pbdev || !(pbdev->fh &FH_ENABLED )) { +if (!pbdev || !(pbdev->fh &FH_MASK_ENABLE )) {DPRINTF ("rpcit no pci dev\n" );setcc (cpu,ZPCI_PCI_LS_INVAL_HANDLE ); goto out;
@@ -590,7 +590,7 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr, } pbdev =s390_pci_find_dev_by_fh (fh); -if (!pbdev || !(pbdev->fh &FH_ENABLED )) { +if (!pbdev || !(pbdev->fh &FH_MASK_ENABLE )) {DPRINTF ("pcistb no pci dev fh 0x%x\n" , fh);setcc (cpu,ZPCI_PCI_LS_INVAL_HANDLE );return 0 ;
@@ -743,7 +743,7 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar) } pbdev =s390_pci_find_dev_by_fh (fh); -if (!pbdev || !(pbdev->fh &FH_ENABLED )) { +if (!pbdev || !(pbdev->fh &FH_MASK_ENABLE )) {DPRINTF ("mpcifc no pci dev fh 0x%x\n" , fh);setcc (cpu,ZPCI_PCI_LS_INVAL_HANDLE );return 0 ;
@@ -873,7 +873,7 @@ int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar) ((uint32_t )pbdev->sum <<7 ) | pbdev->routes.adapter.summary_offset;stl_p (&fib.data, data); -if (pbdev->fh &FH_ENABLED ) { +if (pbdev->fh &FH_MASK_ENABLE ) { fib.fc |=0x80 ; }
Signature · 1 line
2.9.0
PATCH 5/17 s390x/pci: refactor s390_pci_find_dev_by_fh
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Because this function is called very frequently, we should use a more effective way to find the zpci device. So we use the FH's index to get the device directly.
--- hw/s390x/s390-pci-bus.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
hw/s390x/s390-pci-bus.c +4 -11
@@ -198,19 +198,12 @@ 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_get_phb (); +S390PCIBusDevice *pbdev; -if (!fh) { -return NULL ; - } - -for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = &s->pbdev[i]; -if (pbdev->fh == fh) { -return pbdev; - } + pbdev = &s->pbdev[fh &FH_MASK_INDEX ]; +if (pbdev->fh !=0 && pbdev->fh == fh) { +return pbdev; }return NULL ;
Signature · 1 line
2.9.0
PATCH 6/17 s390x/pci: enforce zPCI state checking
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Current code uses some fields combinatorially to indicate the state of a s390 pci device. This patch introduces device states in order to make the code more readable and more logical.
--- hw/s390x/s390-pci-bus.c | 104 +++++++++++++++-------------- hw/s390x/s390-pci-bus.h | 34 +++++++++- hw/s390x/s390-pci-inst.c | 168 ++++++++++++++++++++++++++++++++++++++--------- hw/s390x/s390-pci-inst.h | 5 ++ include/hw/s390x/sclp.h | 1 + 5 files changed, 230 insertions(+), 82 deletions(-)
hw/s390x/s390-pci-bus.c +55 -49
@@ -116,16 +116,22 @@ void s390_pci_sclp_configure(SCCB *sccb) goto out; } -if (pbdev) { -if (pbdev->configured) { - rc =SCLP_RC_NO_ACTION_REQUIRED ; - }else { - pbdev->configured = true; - rc =SCLP_RC_NORMAL_COMPLETION ; - } - }else { +if (!pbdev) {DPRINTF ("sclp config no dev found\n" ); rc =SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED ; + goto out; + } + +switch (pbdev->state) { +case ZPCI_FS_RESERVED : + rc =SCLP_RC_ADAPTER_IN_RESERVED_STATE ; +break ; +case ZPCI_FS_STANDBY : + pbdev->state =ZPCI_FS_DISABLED ; + rc =SCLP_RC_NORMAL_COMPLETION ; +break ; +default : + rc =SCLP_RC_NO_ACTION_REQUIRED ; } out: psccb->header.response_code =cpu_to_be16 (rc);
@@ -142,22 +148,28 @@ void s390_pci_sclp_deconfigure(SCCB *sccb) goto out; } -if (pbdev) { -if (!pbdev->configured) { - rc =SCLP_RC_NO_ACTION_REQUIRED ; - }else { -if (pbdev->summary_ind) { -pci_dereg_irqs (pbdev); - } -if (pbdev->iommu_enabled) { -pci_dereg_ioat (pbdev); - } - pbdev->configured = false; - rc =SCLP_RC_NORMAL_COMPLETION ; - } - }else { +if (!pbdev) {DPRINTF ("sclp deconfig no dev found\n" ); rc =SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED ; + goto out; + } + +switch (pbdev->state) { +case ZPCI_FS_RESERVED : + rc =SCLP_RC_ADAPTER_IN_RESERVED_STATE ; +break ; +case ZPCI_FS_STANDBY : + rc =SCLP_RC_NO_ACTION_REQUIRED ; +break ; +default : +if (pbdev->summary_ind) { +pci_dereg_irqs (pbdev); + } +if (pbdev->iommu_enabled) { +pci_dereg_ioat (pbdev); + } + pbdev->state =ZPCI_FS_STANDBY ; + rc =SCLP_RC_NORMAL_COMPLETION ; } out: psccb->header.response_code =cpu_to_be16 (rc);
@@ -183,7 +195,7 @@ S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx)for (i =0 ; i <PCI_SLOT_MAX ; i++) { pbdev = &s->pbdev[i]; -if (pbdev->fh ==0 ) { +if (pbdev->state ==ZPCI_FS_RESERVED ) {continue ; }
@@ -233,9 +245,8 @@ static void s390_pci_generate_plug_event(uint16_t pec, uint32_t fh,s390_pci_generate_event (2 , pec, fh, fid,0 ,0 ); } -static void s390_pci_generate_error_event (uint16_t pec,uint32_t fh, -uint32_t fid,uint64_t faddr, -uint32_t e) +void s390_pci_generate_error_event (uint16_t pec,uint32_t fh,uint32_t fid, +uint64_t faddr,uint32_t e) {s390_pci_generate_event (1 , pec, fh, fid, faddr, e); }
@@ -337,8 +348,14 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr, .perm = IOMMU_NONE, }; -if (!pbdev->configured || !pbdev->pdev || - !(pbdev->fh &FH_MASK_ENABLE ) || !pbdev->iommu_enabled) { +switch (pbdev->state) { +case ZPCI_FS_ENABLED : +case ZPCI_FS_BLOCKED : +if (!pbdev->iommu_enabled) { +return ret; + } +break ; +default :return ret; }
@@ -357,30 +374,13 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr,return ret; } -if (!pbdev->g_iota) { - pbdev->error_state = true; - pbdev->lgstg_blocked = true; -s390_pci_generate_error_event (ERR_EVENT_INVALAS , pbdev->fh, pbdev->fid, - addr,0 ); -return ret; - } -if (addr < pbdev->pba || addr > pbdev->pal) { - pbdev->error_state = true; - pbdev->lgstg_blocked = true; -s390_pci_generate_error_event (ERR_EVENT_OORANGE , pbdev->fh, pbdev->fid, - addr,0 );return ret; } pte =s390_guest_io_table_walk (s390_pci_get_table_origin (pbdev->g_iota), addr); -if (!pte) { - pbdev->error_state = true; - pbdev->lgstg_blocked = true; -s390_pci_generate_error_event (ERR_EVENT_SERR , pbdev->fh, pbdev->fid, - addr,ERR_EVENT_Q_BIT );return ret; }
@@ -449,7 +449,7 @@ static void s390_msi_ctrl_write(void *opaque, hwaddr addr, uint64_t data,return ; } -if (!(pbdev->fh &FH_MASK_ENABLE )) { +if (pbdev->state !=ZPCI_FS_ENABLED ) {return ; }
@@ -571,7 +571,7 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, pbdev->fid =s390_pci_get_pfid (pci_dev); pbdev->pdev = pci_dev; - pbdev->configured = true; + pbdev->state =ZPCI_FS_DISABLED ; pbdev->fh =s390_pci_get_pfh (pci_dev);s390_pcihost_setup_msix (pbdev);
@@ -592,8 +592,12 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev, ->qbus.parent);S390PCIBusDevice *pbdev = &s->pbdev[PCI_SLOT (pci_dev->devfn)]; -if (pbdev->configured) { - pbdev->configured = false; +switch (pbdev->state) { +case ZPCI_FS_RESERVED : + goto out; +case ZPCI_FS_STANDBY : +break ; +default :s390_pci_generate_plug_event (HP_EVENT_CONFIGURED_TO_STBRES , pbdev->fh, pbdev->fid); }
@@ -603,6 +607,8 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev, pbdev->fh =0 ; pbdev->fid =0 ; pbdev->pdev =NULL ; + pbdev->state =ZPCI_FS_RESERVED ; +out:object_unparent (OBJECT (pci_dev)); }
hw/s390x/s390-pci-bus.h +31 -3
@@ -153,6 +153,34 @@ enum ZpciIoatDtype {#define ZPCI_TABLE_VALID_MASK 0x20#define ZPCI_TABLE_PROT_MASK 0x200 +/* PCI Function States +* +* reserved: default; device has just been plugged or is in progress of being +* unplugged +* standby: device is present but not configured; transition from any +* configured state/to this state via sclp configure/deconfigure +* +* The following states make up the "configured" meta-state: +* disabled: device is configured but not enabled; transition between this +* state and enabled via clp enable/disable +* enbaled: device is ready for use; transition to disabled via clp disable; +* may enter an error state +* blocked: ignore all DMA and interrupts; transition back to enabled or from +* error state via mpcifc +* error: an error occured; transition back to enabled via mpcifc +* permanent error: an unrecoverable error occured; transition to standby via +* sclp deconfigure +*/ +typedef enum { +ZPCI_FS_RESERVED , +ZPCI_FS_STANDBY , +ZPCI_FS_DISABLED , +ZPCI_FS_ENABLED , +ZPCI_FS_BLOCKED , +ZPCI_FS_ERROR , +ZPCI_FS_PERMANENT_ERROR , +}ZpciState ; + typedef struct SeiContainer { QTAILQ_ENTRY(SeiContainer) link; uint32_t fid;
@@ -219,9 +247,7 @@ typedef struct S390MsixInfo { typedef struct S390PCIBusDevice { PCIDevice *pdev; - bool configured; - bool error_state; - bool lgstg_blocked; + ZpciState state; bool iommu_enabled; uint32_t fh; uint32_t fid;
@@ -255,6 +281,8 @@ void s390_pci_sclp_configure(SCCB *sccb);void s390_pci_sclp_deconfigure (SCCB *sccb);void s390_pci_iommu_enable (S390PCIBusDevice *pbdev);void s390_pci_iommu_disable (S390PCIBusDevice *pbdev); +void s390_pci_generate_error_event (uint16_t pec,uint32_t fh,uint32_t fid, +uint64_t faddr,uint32_t e);S390PCIBusDevice *s390_pci_find_dev_by_idx (uint32_t idx);S390PCIBusDevice *s390_pci_find_dev_by_fh (uint32_t fh);S390PCIBusDevice *s390_pci_find_dev_by_fid (uint32_t fid);
hw/s390x/s390-pci-inst.c +138 -30
276 lines not on this page · raw message
hw/s390x/s390-pci-inst.h +5 -0
@@ -249,6 +249,11 @@ typedef struct ClpReqRspQueryPciGrp {#define ZPCI_MOD_FC_RESET_BLOCK 9#define ZPCI_MOD_FC_SET_MEASURE 10 +/* Store PCI Function Controls status codes */ +#define ZPCI_STPCIFC_ST_PERM_ERROR 8 +#define ZPCI_STPCIFC_ST_INVAL_DMAAS 28 +#define ZPCI_STPCIFC_ST_ERROR_RECOVER 40 +/* FIB function controls */ #define ZPCI_FIB_FC_ENABLED 0x80#define ZPCI_FIB_FC_ERROR 0x40
include/hw/s390x/sclp.h +1 -0
@@ -58,6 +58,7 @@#define SCLP_RC_CONTAINED_EQUIPMENT_CHECK 0x0340#define SCLP_RC_INSUFFICIENT_SCCB_LENGTH 0x0300#define SCLP_RC_STANDBY_READ_COMPLETION 0x0410 +#define SCLP_RC_ADAPTER_IN_RESERVED_STATE 0x05f0#define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED 0x09f0#define SCLP_RC_INVALID_FUNCTION 0x40f0#define SCLP_RC_NO_EVENT_BUFFERS_STORED 0x60f0
Signature · 1 line
2.9.0
PATCH 7/17 s390x/pci: introduce S390PCIBus
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
To enable S390PCIBusDevice as qdev, there should be a new bus to plug and manage all instances of S390PCIBusDevice. Due to this, S390PCIBus is introduced.
--- hw/s390x/s390-pci-bus.c | 10 ++++++++++ hw/s390x/s390-pci-bus.h | 8 ++++++++ 2 files changed, 18 insertions(+)
hw/s390x/s390-pci-bus.c +10 -0
@@ -527,6 +527,9 @@ static int s390_pcihost_init(SysBusDevice *dev) bus =BUS (b);qbus_set_hotplug_handler (bus,DEVICE (dev),NULL ); phb->bus = b; + + s->bus =S390_PCI_BUS (qbus_create (TYPE_S390_PCI_BUS ,DEVICE (s),NULL )); +QTAILQ_INIT (&s->pending_sei);return 0 ; }
@@ -636,9 +639,16 @@ static const TypeInfo s390_pcihost_info = { } }; +static const TypeInfo s390_pcibus_info = { + .name =TYPE_S390_PCI_BUS , + .parent =TYPE_BUS , + .instance_size =sizeof (S390PCIBus), +}; +static void s390_pci_register_types (void ) {type_register_static (&s390_pcihost_info); +type_register_static (&s390_pcibus_info); }type_init (s390_pci_register_types)
hw/s390x/s390-pci-bus.h +8 -0
@@ -21,6 +21,7 @@#include "hw/s390x/css.h" #define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost" +#define TYPE_S390_PCI_BUS "s390-pcibus"#define FH_MASK_ENABLE 0x80000000#define FH_MASK_INSTANCE 0x7f000000#define FH_MASK_SHM 0x00ff0000
@@ -31,6 +32,8 @@#define S390_PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE) +#define S390_PCI_BUS (obj) \ + OBJECT_CHECK(S390PCIBus, (obj), TYPE_S390_PCI_BUS)#define HP_EVENT_TO_CONFIGURED 0x0301#define HP_EVENT_RESERVED_TO_STANDBY 0x0302
@@ -267,8 +270,13 @@ typedef struct S390PCIBusDevice {IndAddr *indicator; } S390PCIBusDevice; +typedef struct S390PCIBus { +BusState qbus; +}S390PCIBus ; + typedef struct S390pciState { PCIHostState parent_obj; + S390PCIBus *bus; S390PCIBusDevice pbdev[PCI_SLOT_MAX]; AddressSpace msix_notify_as; MemoryRegion msix_notify_mr;
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 07/17] s390x/pci: introduce S390PCIBus
Quoted 29 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
To enable S390PCIBusDevice as qdev, there should be a new bus to plug and manage all instances of S390PCIBusDevice. Due to this, S390PCIBus is introduced.
Signed-off-by Yi Min Zhao <[email protected]>Reviewed-by Pierre Morel <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/s390-pci-bus.c | 10 ++++++++++ hw/s390x/s390-pci-bus.h | 8 ++++++++ 2 files changed, 18 insertions(+)hw/s390x/s390-pci-bus.c +3
-0@@ -527,6 +527,9 @@ static int s390_pcihost_init(SysBusDevice *dev) bus =BUS (b);qbus_set_hotplug_handler (bus,DEVICE (dev),NULL ); phb->bus = b; + + s->bus =S390_PCI_BUS (qbus_create (TYPE_S390_PCI_BUS ,DEVICE (s),NULL )); +QTAILQ_INIT (&s->pending_sei);return 0 ; }
hw/s390x/s390-pci-bus.c static const TypeInfo s390_pcihost_info = { · line 644
Quoted 6 lines
hw/s390x/s390-pci-bus.c +3
-0@@ -636,9 +639,16 @@ static const TypeInfo s390_pcihost_info = { } }; +static const TypeInfo s390_pcibus_info = { + .name =TYPE_S390_PCI_BUS , + .parent =TYPE_BUS ,
Hi,
The type is named TYPE_S390_PCI_BUS, but does not
derive from PCI_BUS. I find it a little confusing, anyway is just a thought. Maybe you should go with TYPE_S390_BUS.
Thanks,
Marcel
Quoted 46 lines
hw/s390x/s390-pci-bus.c +4
-0+ .instance_size = sizeof(S390PCIBus), +}; +static void s390_pci_register_types (void ) {type_register_static (&s390_pcihost_info); +type_register_static (&s390_pcibus_info); }type_init (s390_pci_register_types)hw/s390x/s390-pci-bus.h +8
-0@@ -21,6 +21,7 @@#include "hw/s390x/css.h" #define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost" +#define TYPE_S390_PCI_BUS "s390-pcibus"#define FH_MASK_ENABLE 0x80000000#define FH_MASK_INSTANCE 0x7f000000#define FH_MASK_SHM 0x00ff0000@@ -31,6 +32,8 @@#define S390_PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE) +#define S390_PCI_BUS (obj) \ + OBJECT_CHECK(S390PCIBus, (obj), TYPE_S390_PCI_BUS)#define HP_EVENT_TO_CONFIGURED 0x0301#define HP_EVENT_RESERVED_TO_STANDBY 0x0302@@ -267,8 +270,13 @@ typedef struct S390PCIBusDevice {IndAddr *indicator; } S390PCIBusDevice; +typedef struct S390PCIBus { +BusState qbus; +}S390PCIBus ; + typedef struct S390pciState { PCIHostState parent_obj; + S390PCIBus *bus; S390PCIBusDevice pbdev[PCI_SLOT_MAX]; AddressSpace msix_notify_as; MemoryRegion msix_notify_mr;
Re: [Qemu-devel] [PATCH 07/17] s390x/pci: introduce S390PCIBus
Quoted 39 lines · On Tue, 28 Jun 2016 17:39:30 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 29 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
To enable S390PCIBusDevice as qdev, there should be a new bus to plug and manage all instances of S390PCIBusDevice. Due to this, S390PCIBus is introduced.
Signed-off-by Yi Min Zhao <[email protected]>Reviewed-by Pierre Morel <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/s390-pci-bus.c | 10 ++++++++++ hw/s390x/s390-pci-bus.h | 8 ++++++++ 2 files changed, 18 insertions(+)hw/s390x/s390-pci-bus.c +3
-0@@ -527,6 +527,9 @@ static int s390_pcihost_init(SysBusDevice *dev) bus =BUS (b);qbus_set_hotplug_handler (bus,DEVICE (dev),NULL ); phb->bus = b; + + s->bus =S390_PCI_BUS (qbus_create (TYPE_S390_PCI_BUS ,DEVICE (s),NULL )); +QTAILQ_INIT (&s->pending_sei);return 0 ; }hw/s390x/s390-pci-bus.c static const TypeInfo s390_pcihost_info = { · line 644
Quoted 6 lines
hw/s390x/s390-pci-bus.c +3
-0@@ -636,9 +639,16 @@ static const TypeInfo s390_pcihost_info = { } }; +static const TypeInfo s390_pcibus_info = { + .name =TYPE_S390_PCI_BUS , + .parent =TYPE_BUS ,Hi,
Quoted 3 lines
The type is named
TYPE_S390_PCI_BUS, but does not
derive fromPCI_BUS. I find it a little confusing, anyway is just a thought. Maybe you should go withTYPE_S390_BUS.
I think that would be even more confusing, as this is not the only bus on s390 :)
I have trouble thinking of a better name, though. TYPE_S390PCI_BUS?
Re: [Qemu-devel] [PATCH 07/17] s390x/pci: introduce S390PCIBus
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Tue, 28 Jun 2016 17:39:30 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 29 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
To enable S390PCIBusDevice as qdev, there should be a new bus to plug and manage all instances of S390PCIBusDevice. Due to this, S390PCIBus is introduced.
Signed-off-by Yi Min Zhao <[email protected]>Reviewed-by Pierre Morel <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/s390-pci-bus.c | 10 ++++++++++ hw/s390x/s390-pci-bus.h | 8 ++++++++ 2 files changed, 18 insertions(+)hw/s390x/s390-pci-bus.c +3
-0@@ -527,6 +527,9 @@ static int s390_pcihost_init(SysBusDevice *dev) bus =BUS (b);qbus_set_hotplug_handler (bus,DEVICE (dev),NULL ); phb->bus = b; + + s->bus =S390_PCI_BUS (qbus_create (TYPE_S390_PCI_BUS ,DEVICE (s),NULL )); +QTAILQ_INIT (&s->pending_sei);return 0 ; }hw/s390x/s390-pci-bus.c static const TypeInfo s390_pcihost_info = { · line 644
Quoted 6 lines
hw/s390x/s390-pci-bus.c +3
-0@@ -636,9 +639,16 @@ static const TypeInfo s390_pcihost_info = { } }; +static const TypeInfo s390_pcibus_info = { + .name =TYPE_S390_PCI_BUS , + .parent =TYPE_BUS ,Hi,
Quoted 6 lines
Quoted 3 lines
The type is named
TYPE_S390_PCI_BUS, but does not
derive fromPCI_BUS. I find it a little confusing, anyway is just a thought. Maybe you should go withTYPE_S390_BUS.I think that would be even more confusing, as this is not the only bus on s390 :)
I suppose you mean S390 has a few bus types and this one is associated with PCI.
Quoted 3 lines
I have trouble thinking of a better name, though.
TYPE_S390PCI_BUS?
This would give a hint that we are referring to a special "S390PCI" bus, but is less readable. I like the previous name better :)
Maybe TYPE_ZPCI_BUS ? Anyway, maybe just being aware of it is enough.
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 07/17] s390x/pci: introduce S390PCIBus
Quoted 43 lines · On Tue, 28 Jun 2016 18:40:18 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 42 lines · Cornelia Huck
Quoted 39 lines · On Tue, 28 Jun 2016 17:39:30 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 29 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
To enable S390PCIBusDevice as qdev, there should be a new bus to plug and manage all instances of S390PCIBusDevice. Due to this, S390PCIBus is introduced.
Signed-off-by Yi Min Zhao <[email protected]>Reviewed-by Pierre Morel <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/s390-pci-bus.c | 10 ++++++++++ hw/s390x/s390-pci-bus.h | 8 ++++++++ 2 files changed, 18 insertions(+)hw/s390x/s390-pci-bus.c +3
-0@@ -527,6 +527,9 @@ static int s390_pcihost_init(SysBusDevice *dev) bus =BUS (b);qbus_set_hotplug_handler (bus,DEVICE (dev),NULL ); phb->bus = b; + + s->bus =S390_PCI_BUS (qbus_create (TYPE_S390_PCI_BUS ,DEVICE (s),NULL )); +QTAILQ_INIT (&s->pending_sei);return 0 ; }hw/s390x/s390-pci-bus.c static const TypeInfo s390_pcihost_info = { · line 644
Quoted 6 lines
hw/s390x/s390-pci-bus.c +3
-0@@ -636,9 +639,16 @@ static const TypeInfo s390_pcihost_info = { } }; +static const TypeInfo s390_pcibus_info = { + .name =TYPE_S390_PCI_BUS , + .parent =TYPE_BUS ,Hi,
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The type is named
TYPE_S390_PCI_BUS, but does not
derive fromPCI_BUS. I find it a little confusing, anyway is just a thought. Maybe you should go withTYPE_S390_BUS.I think that would be even more confusing, as this is not the only bus on s390 :)
I suppose you mean S390 has a few bus types and this one is associated with PCI.
Yes.
Quoted 8 lines
Quoted 4 lines
I have trouble thinking of a better name, though.
TYPE_S390PCI_BUS?This would give a hint that we are referring to a special "S390PCI" bus, but is less readable. I like the previous name better :)
MaybeTYPE_ZPCI_BUS? Anyway, maybe just being aware of it is enough.
Probably yes. I think most people tempted to look at this file already understand the purpose.
PATCH 8/17 s390x/pci: introduce S390PCIIOMMU
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Currently each zpci device holds its own DMA address space and memory region. At the same time, all instances of zpci device are stored in S390pciState. So duirng the initialization of S390pciState, all zpci devices are created and then all DMA address spaces are created. Thus, when initializing pci devices, their corresponding DMA address spaces could be found.
But zpci qdev will be introduced later. Zpci device may be initialized and plugged afterwards generic pci device. So we should initialize all DMA address spaces and memory regions before initializing zpci devices.
We introduce a new struct named S390PCIIOMMU. And a new field of S390pciState, which is an array to store all instances of S390PCIIOMMU, is added so that qemu pci code could find the corresponding DMA address space when initializing a generic pci device. And this should be done before the connection of a zpci device and a generic pci device is built.
--- hw/s390x/s390-pci-bus.c | 19 +++++++++++-------- hw/s390x/s390-pci-bus.h | 9 +++++++-- 2 files changed, 18 insertions(+), 10 deletions(-)
hw/s390x/s390-pci-bus.c +11 -8
@@ -406,7 +406,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->iommu[PCI_SLOT (devfn)]->as; }static uint8_t set_ind_atomic (uint64_t ind_loc,uint8_t to_be_set)
@@ -478,15 +478,15 @@ static const MemoryRegionOps s390_msi_ctrl_ops = {void s390_pci_iommu_enable (S390PCIBusDevice *pbdev) { -memory_region_init_iommu (&pbdev->iommu_mr,OBJECT (&pbdev->mr), +memory_region_init_iommu (&pbdev->iommu_mr,OBJECT (&pbdev->iommu->mr), &s390_iommu_ops,"iommu-s390" , pbdev->pal +1 ); -memory_region_add_subregion (&pbdev->mr,0 , &pbdev->iommu_mr); +memory_region_add_subregion (&pbdev->iommu->mr,0 , &pbdev->iommu_mr); pbdev->iommu_enabled = true; }void s390_pci_iommu_disable (S390PCIBusDevice *pbdev) { -memory_region_del_subregion (&pbdev->mr, &pbdev->iommu_mr); +memory_region_del_subregion (&pbdev->iommu->mr, &pbdev->iommu_mr);object_unparent (OBJECT (&pbdev->iommu_mr)); pbdev->iommu_enabled = false; }
@@ -494,13 +494,15 @@ void s390_pci_iommu_disable(S390PCIBusDevice *pbdev)static void s390_pcihost_init_as (S390pciState *s) {int i; -S390PCIBusDevice *pbdev; +S390PCIIOMMU *iommu;for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = &s->pbdev[i]; -memory_region_init (&pbdev->mr,OBJECT (s), + iommu =g_malloc0 (sizeof (S390PCIIOMMU )); +memory_region_init (&iommu->mr,OBJECT (s),"iommu-root-s390" ,UINT64_MAX ); -address_space_init (&pbdev->as, &pbdev->mr,"iommu-pci" ); +address_space_init (&iommu->as, &iommu->mr,"iommu-pci" ); + + s->iommu[i] = iommu; } memory_region_init_io(&s->msix_notify_mr, OBJECT(s),
@@ -576,6 +578,7 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, pbdev->pdev = pci_dev; pbdev->state =ZPCI_FS_DISABLED ; pbdev->fh =s390_pci_get_pfh (pci_dev); + pbdev->iommu = s->iommu[PCI_SLOT (pci_dev->devfn)];s390_pcihost_setup_msix (pbdev);
hw/s390x/s390-pci-bus.h +7 -2
@@ -248,6 +248,11 @@ typedef struct S390MsixInfo {uint32_t pba_offset; } S390MsixInfo; +typedef struct S390PCIIOMMU { +AddressSpace as; +MemoryRegion mr; +}S390PCIIOMMU ; + typedef struct S390PCIBusDevice { PCIDevice *pdev; ZpciState state;
@@ -263,8 +268,7 @@ typedef struct S390PCIBusDevice {uint8_t sum;S390MsixInfo msix;AdapterRoutes routes; -AddressSpace as; -MemoryRegion mr; +S390PCIIOMMU *iommu;MemoryRegion iommu_mr;IndAddr *summary_ind;IndAddr *indicator;
@@ -278,6 +282,7 @@ typedef struct S390pciState {PCIHostState parent_obj;S390PCIBus *bus;S390PCIBusDevice pbdev[PCI_SLOT_MAX ]; +S390PCIIOMMU *iommu[PCI_SLOT_MAX ];AddressSpace msix_notify_as;MemoryRegion msix_notify_mr; QTAILQ_HEAD(, SeiContainer) pending_sei;
Signature · 1 line
2.9.0
PATCH 9/17 s390x/pci: introduce S390PCIBusDevice qdev
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
To support definitions of s390 pci attributes in Qemu cmdline, we have to make current S390PCIBusDevice struct inherit DeviceState and add three properties for it. Currently we only support definitions of uid and fid.
'uid' is optionally defined by users, identifies a zpci device and must be defined with a 16-bit and non-zero unique value.
'fid' ranges from 0x0 to 0xFFFFFFFF. For fid property, we introduce a new PropertyInfo by the name of s390_pci_fid_propinfo with our special setter and getter. As 'fid' is optional, introduce 'fid_defined' to track whether the user specified a fid.
'target' field is to direct qemu to find the corresponding generic PCI device. It is equal to the 'id' value of one of generic pci devices. If the user doesn't specify 'id' parameter for a generic pci device, its 'id' value will be generated automatically and use this value as 'target' to create an associated zpci device.
If the user did not specify 'uid' or 'fid', values are generated automatically. 'target' is required.
In addition, if a pci device has no associated zpci device, the code will generate a zpci device automatically for it.
--- hw/s390x/s390-pci-bus.c | 257 ++++++++++++++++++++++++++++++++++++++++++++++-- hw/s390x/s390-pci-bus.h | 12 ++- 2 files changed, 261 insertions(+), 8 deletions(-)
hw/s390x/s390-pci-bus.c +250 -7
@@ -12,6 +12,8 @@*/ #include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/visitor.h" #include "qemu-common.h" #include "cpu.h" #include "s390-pci-bus.h"
@@ -96,8 +98,8 @@ S390PCIBusDevice *s390_pci_find_dev_by_fid(uint32_t fid)S390pciState *s =s390_get_phb ();for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = &s->pbdev[i]; -if ((pbdev->fh !=0 ) && (pbdev->fid == fid)) { + pbdev = s->pbdev[i]; +if (pbdev && pbdev->fid == fid) {return pbdev; } }
@@ -185,6 +187,50 @@ static uint32_t s390_pci_get_pfh(PCIDevice *pdev)return PCI_SLOT (pdev->devfn) |FH_SHM_VFIO ; } +static S390PCIBusDevice *s390_pci_find_dev_by_uid (uint16_t uid) +{ +int i; +S390PCIBusDevice *pbdev; +S390pciState *s =s390_get_phb (); + +for (i =0 ; i <PCI_SLOT_MAX ; i++) { + pbdev = s->pbdev[i]; +if (!pbdev) { +continue ; + } + +if (pbdev->uid == uid) { +return pbdev; + } + } + +return NULL ; +} + +static S390PCIBusDevice *s390_pci_find_dev_by_target (const char *target) +{ +int i; +S390PCIBusDevice *pbdev; +S390pciState *s =s390_get_phb (); + +if (!target) { +return NULL ; + } + +for (i =0 ; i <PCI_SLOT_MAX ; i++) { + pbdev = s->pbdev[i]; +if (!pbdev) { +continue ; + } + +if (!strcmp (pbdev->target, target)) { +return pbdev; + } + } + +return NULL ; +} +S390PCIBusDevice *s390_pci_find_dev_by_idx (uint32_t idx) {S390PCIBusDevice *pbdev;
@@ -193,7 +239,10 @@ S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx)S390pciState *s =s390_get_phb ();for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = &s->pbdev[i]; + pbdev = s->pbdev[i]; +if (!pbdev) { +continue ; + }if (pbdev->state ==ZPCI_FS_RESERVED ) {continue ;
@@ -213,8 +262,8 @@ S390PCIBusDevice *s390_pci_find_dev_by_fh(uint32_t fh)S390pciState *s =s390_get_phb ();S390PCIBusDevice *pbdev; - pbdev = &s->pbdev[fh &FH_MASK_INDEX ]; -if (pbdev->fh !=0 && pbdev->fh == fh) { + pbdev = s->pbdev[fh &FH_MASK_INDEX ]; +if (pbdev && pbdev->fh == fh) {return pbdev; }
@@ -564,6 +613,22 @@ static int s390_pcihost_setup_msix(S390PCIBusDevice *pbdev)return 0 ; } +static S390PCIBusDevice *s390_pci_device_new (const char *target) +{ +DeviceState *dev =NULL ; +S390pciState *s =s390_get_phb (); + + dev =qdev_try_create (BUS (s->bus),TYPE_S390_PCI_DEVICE ); +if (!dev) { +return NULL ; + } + +qdev_prop_set_string (dev,"target" , target); +qdev_init_nofail (dev); + +return S390_PCI_DEVICE (dev); +} +static void s390_pcihost_hot_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -572,8 +637,24 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,S390pciState *s =S390_PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev) ->qbus.parent); - pbdev = &s->pbdev[PCI_SLOT (pci_dev->devfn)]; +if (!dev->id) { +/* In the case the PCI device does not define an id */ +/* we generate one based on the PCI address */ + dev->id =g_strdup_printf ("auto_%02x:%02x.%01x" , +pci_bus_num (pci_dev->bus), +PCI_SLOT (pci_dev->devfn), +PCI_FUNC (pci_dev->devfn)); + } + + pbdev =s390_pci_find_dev_by_target (dev->id); +if (!pbdev) { + pbdev =s390_pci_device_new (dev->id); +if (!pbdev) { +error_setg (errp,"create zpci device failed" ); + } + } + s->pbdev[PCI_SLOT (pci_dev->devfn)] = pbdev; pbdev->fid =s390_pci_get_pfid (pci_dev); pbdev->pdev = pci_dev; pbdev->state =ZPCI_FS_DISABLED ;
@@ -596,7 +677,7 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,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 = s->pbdev[PCI_SLOT (pci_dev->devfn)];switch (pbdev->state) {case ZPCI_FS_RESERVED :
@@ -648,10 +729,172 @@ static const TypeInfo s390_pcibus_info = { .instance_size = sizeof(S390PCIBus), }; +static uint16_t s390_pci_generate_uid (void ) +{ +uint16_t uid =0 ; + +do { + uid++; +if (!s390_pci_find_dev_by_uid (uid)) { +return uid; + } + }while (uid <ZPCI_MAX_UID ); + +return UID_UNDEFINED ; +} + +static uint32_t s390_pci_generate_fid (Error **errp) +{ +uint32_t fid =0 ; + +while (fid <=ZPCI_MAX_FID ) { +if (!s390_pci_find_dev_by_fid (fid)) { +return fid; + } + +if (fid ==ZPCI_MAX_FID ) { +break ; + } + + fid++; + } + +error_setg (errp,"no free fid could be found" ); +return 0 ; +} + +static void s390_pci_device_realize (DeviceState *dev,Error **errp) +{ +S390PCIBusDevice *zpci =S390_PCI_DEVICE (dev); + +if (!zpci->target) { +error_setg (errp,"target must be defined" ); +return ; + } + +if (s390_pci_find_dev_by_target (zpci->target)) { +error_setg (errp,"target %s already has an associated zpci device" , + zpci->target); +return ; + } + +if (zpci->uid ==UID_UNDEFINED ) { + zpci->uid =s390_pci_generate_uid (); +if (!zpci->uid) { +error_setg (errp,"no free uid could be found" ); +return ; + } + }else if (s390_pci_find_dev_by_uid (zpci->uid)) { +error_setg (errp,"uid %u already in use" , zpci->uid); +return ; + } + +if (!zpci->fid_defined) { +Error *local_error =NULL ; + + zpci->fid =s390_pci_generate_fid (&local_error); +if (local_error) { +error_propagate (errp, local_error); +return ; + } + }else if (s390_pci_find_dev_by_fid (zpci->fid)) { +error_setg (errp,"fid %u already in use" , zpci->fid); +return ; + } + + zpci->state =ZPCI_FS_RESERVED ; +} + +static void s390_pci_device_reset (DeviceState *dev) +{ +S390PCIBusDevice *pbdev =S390_PCI_DEVICE (dev); + +switch (pbdev->state) { +case ZPCI_FS_RESERVED : +return ; +case ZPCI_FS_STANDBY : +break ; +default : + pbdev->fh &= ~FH_MASK_ENABLE ; + pbdev->state =ZPCI_FS_DISABLED ; +break ; + } + +if (pbdev->summary_ind) { +pci_dereg_irqs (pbdev); + } +if (pbdev->iommu_enabled) { +pci_dereg_ioat (pbdev); + } + + pbdev->fmb_addr =0 ; +} + +static void s390_pci_get_fid (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Property *prop = opaque; +uint32_t *ptr =qdev_get_prop_ptr (DEVICE (obj), prop); + +visit_type_uint32 (v, name, ptr, errp); +} + +static void s390_pci_set_fid (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +S390PCIBusDevice *zpci =S390_PCI_DEVICE (obj); +Property *prop = opaque; +uint32_t *ptr =qdev_get_prop_ptr (dev, prop); + +if (dev->realized) { +qdev_prop_set_after_realize (dev, name, errp); +return ; + } + +visit_type_uint32 (v, name, ptr, errp); + zpci->fid_defined = true; +} + +static PropertyInfo s390_pci_fid_propinfo = { + .name ="zpci_fid" , + .get = s390_pci_get_fid, + .set = s390_pci_set_fid, +}; + +#define DEFINE_PROP_S390_PCI_FID (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, s390_pci_fid_propinfo, uint32_t) + +static Property s390_pci_device_properties[] = { +DEFINE_PROP_UINT16 ("uid" , S390PCIBusDevice, uid,UID_UNDEFINED ), +DEFINE_PROP_S390_PCI_FID ("fid" , S390PCIBusDevice, fid), +DEFINE_PROP_STRING ("target" , S390PCIBusDevice, target), +DEFINE_PROP_END_OF_LIST (), +}; + +static void s390_pci_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="zpci device" ; + dc->reset = s390_pci_device_reset; + dc->bus_type =TYPE_S390_PCI_BUS ; + dc->realize = s390_pci_device_realize; + dc->props = s390_pci_device_properties; +} + +static const TypeInfo s390_pci_device_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_pcibus_info); +type_register_static (&s390_pci_device_info); }type_init (s390_pci_register_types)
hw/s390x/s390-pci-bus.h +11 -1
@@ -22,6 +22,7 @@#define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost"#define TYPE_S390_PCI_BUS "s390-pcibus" +#define TYPE_S390_PCI_DEVICE "zpci"#define FH_MASK_ENABLE 0x80000000#define FH_MASK_INSTANCE 0x7f000000#define FH_MASK_SHM 0x00ff0000
@@ -29,11 +30,16 @@#define FH_SHM_VFIO 0x00010000#define FH_SHM_EMUL 0x00020000#define S390_PCIPT_ADAPTER 2 +#define ZPCI_MAX_FID 0xffffffff +#define ZPCI_MAX_UID 0xffff +#define UID_UNDEFINED 0#define S390_PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)#define S390_PCI_BUS (obj) \ OBJECT_CHECK(S390PCIBus, (obj), TYPE_S390_PCI_BUS) +#define S390_PCI_DEVICE (obj) \ + OBJECT_CHECK(S390PCIBusDevice, (obj), TYPE_S390_PCI_DEVICE)#define HP_EVENT_TO_CONFIGURED 0x0301#define HP_EVENT_RESERVED_TO_STANDBY 0x0302
@@ -254,11 +260,15 @@ typedef struct S390PCIIOMMU { }S390PCIIOMMU ; typedef struct S390PCIBusDevice { + DeviceState qdev; PCIDevice *pdev; ZpciState state; bool iommu_enabled; + char *target; + uint16_t uid; uint32_t fh; uint32_t fid; + bool fid_defined; uint64_t g_iota; uint64_t pba; uint64_t pal;
@@ -281,7 +291,7 @@ typedef struct S390PCIBus { typedef struct S390pciState { PCIHostState parent_obj; S390PCIBus *bus; - S390PCIBusDevice pbdev[PCI_SLOT_MAX]; + S390PCIBusDevice *pbdev[PCI_SLOT_MAX]; S390PCIIOMMU *iommu[PCI_SLOT_MAX]; AddressSpace msix_notify_as; MemoryRegion msix_notify_mr;
Signature · 1 line
2.9.0
Re: [Qemu-devel] [PATCH 09/17] s390x/pci: introduce S390PCIBusDevice qdev
Quoted 342 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
To support definitions of s390 pci attributes in Qemu cmdline, we have to make current S390PCIBusDevice struct inherit DeviceState and add three properties for it. Currently we only support definitions of uid and fid.
'uid' is optionally defined by users, identifies a zpci device and must be defined with a 16-bit and non-zero unique value.
'fid' ranges from
0x0to0xFFFFFFFF. For fid property, we introduce a new PropertyInfo by the name ofs390_pci_fid_propinfowith our special setter and getter. As 'fid' is optional, introduce 'fid_defined' to track whether the user specified a fid.'target' field is to direct qemu to find the corresponding generic PCI device. It is equal to the 'id' value of one of generic pci devices. If the user doesn't specify 'id' parameter for a generic pci device, its 'id' value will be generated automatically and use this value as 'target' to create an associated zpci device.
If the user did not specify 'uid' or 'fid', values are generated automatically. 'target' is required.
In addition, if a pci device has no associated zpci device, the code will generate a zpci device automatically for it.
Signed-off-by Yi Min Zhao <[email protected]>Reviewed-by Pierre Morel <[email protected]>Signed-off-by Cornelia Huck <[email protected]>--- hw/s390x/s390-pci-bus.c | 257 ++++++++++++++++++++++++++++++++++++++++++++++-- hw/s390x/s390-pci-bus.h | 12 ++- 2 files changed, 261 insertions(+), 8 deletions(-)hw/s390x/s390-pci-bus.c +235
-7@@ -12,6 +12,8 @@*/ #include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/visitor.h" #include "qemu-common.h" #include "cpu.h" #include "s390-pci-bus.h" @@ -96,8 +98,8 @@ S390PCIBusDevice *s390_pci_find_dev_by_fid(uint32_t fid)S390pciState *s =s390_get_phb ();for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = &s->pbdev[i]; -if ((pbdev->fh !=0 ) && (pbdev->fid == fid)) { + pbdev = s->pbdev[i]; +if (pbdev && pbdev->fid == fid) {return pbdev; } }@@ -185,6 +187,50 @@ static uint32_t s390_pci_get_pfh(PCIDevice *pdev)return PCI_SLOT (pdev->devfn) |FH_SHM_VFIO ; } +static S390PCIBusDevice *s390_pci_find_dev_by_uid (uint16_t uid) +{ +int i; +S390PCIBusDevice *pbdev; +S390pciState *s =s390_get_phb (); + +for (i =0 ; i <PCI_SLOT_MAX ; i++) { + pbdev = s->pbdev[i]; +if (!pbdev) { +continue ; + } + +if (pbdev->uid == uid) { +return pbdev; + } + } + +return NULL ; +} + +static S390PCIBusDevice *s390_pci_find_dev_by_target (const char *target) +{ +int i; +S390PCIBusDevice *pbdev; +S390pciState *s =s390_get_phb (); + +if (!target) { +return NULL ; + } + +for (i =0 ; i <PCI_SLOT_MAX ; i++) { + pbdev = s->pbdev[i]; +if (!pbdev) { +continue ; + } + +if (!strcmp (pbdev->target, target)) { +return pbdev; + } + } + +return NULL ; +} +S390PCIBusDevice *s390_pci_find_dev_by_idx (uint32_t idx) {S390PCIBusDevice *pbdev;@@ -193,7 +239,10 @@ S390PCIBusDevice *s390_pci_find_dev_by_idx(uint32_t idx)S390pciState *s =s390_get_phb ();for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = &s->pbdev[i]; + pbdev = s->pbdev[i]; +if (!pbdev) { +continue ; + }if (pbdev->state ==ZPCI_FS_RESERVED ) {continue ;@@ -213,8 +262,8 @@ S390PCIBusDevice *s390_pci_find_dev_by_fh(uint32_t fh)S390pciState *s =s390_get_phb ();S390PCIBusDevice *pbdev; - pbdev = &s->pbdev[fh &FH_MASK_INDEX ]; -if (pbdev->fh !=0 && pbdev->fh == fh) { + pbdev = s->pbdev[fh &FH_MASK_INDEX ]; +if (pbdev && pbdev->fh == fh) {return pbdev; }@@ -564,6 +613,22 @@ static int s390_pcihost_setup_msix(S390PCIBusDevice *pbdev)return 0 ; } +static S390PCIBusDevice *s390_pci_device_new (const char *target) +{ +DeviceState *dev =NULL ; +S390pciState *s =s390_get_phb (); + + dev =qdev_try_create (BUS (s->bus),TYPE_S390_PCI_DEVICE ); +if (!dev) { +return NULL ; + } + +qdev_prop_set_string (dev,"target" , target); +qdev_init_nofail (dev); + +return S390_PCI_DEVICE (dev); +} +static void s390_pcihost_hot_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {@@ -572,8 +637,24 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,S390pciState *s =S390_PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev) ->qbus.parent); - pbdev = &s->pbdev[PCI_SLOT (pci_dev->devfn)]; +if (!dev->id) { +/* In the case the PCI device does not define an id */ +/* we generate one based on the PCI address */ + dev->id =g_strdup_printf ("auto_%02x:%02x.%01x" , +pci_bus_num (pci_dev->bus), +PCI_SLOT (pci_dev->devfn), +PCI_FUNC (pci_dev->devfn)); + } + + pbdev =s390_pci_find_dev_by_target (dev->id); +if (!pbdev) { + pbdev =s390_pci_device_new (dev->id); +if (!pbdev) { +error_setg (errp,"create zpci device failed" ); + } + } + s->pbdev[PCI_SLOT (pci_dev->devfn)] = pbdev; pbdev->fid =s390_pci_get_pfid (pci_dev); pbdev->pdev = pci_dev; pbdev->state =ZPCI_FS_DISABLED ;@@ -596,7 +677,7 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,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 = s->pbdev[PCI_SLOT (pci_dev->devfn)];switch (pbdev->state) {case ZPCI_FS_RESERVED :@@ -648,10 +729,172 @@ static const TypeInfo s390_pcibus_info = { .instance_size = sizeof(S390PCIBus), }; +static uint16_t s390_pci_generate_uid (void ) +{ +uint16_t uid =0 ; + +do { + uid++; +if (!s390_pci_find_dev_by_uid (uid)) { +return uid; + } + }while (uid <ZPCI_MAX_UID ); + +return UID_UNDEFINED ; +} + +static uint32_t s390_pci_generate_fid (Error **errp) +{ +uint32_t fid =0 ; + +while (fid <=ZPCI_MAX_FID ) { +if (!s390_pci_find_dev_by_fid (fid)) { +return fid; + } + +if (fid ==ZPCI_MAX_FID ) { +break ; + } + + fid++; + } + +error_setg (errp,"no free fid could be found" ); +return 0 ; +} + +static void s390_pci_device_realize (DeviceState *dev,Error **errp) +{ +S390PCIBusDevice *zpci =S390_PCI_DEVICE (dev); + +if (!zpci->target) { +error_setg (errp,"target must be defined" ); +return ; + } + +if (s390_pci_find_dev_by_target (zpci->target)) { +error_setg (errp,"target %s already has an associated zpci device" , + zpci->target); +return ; + } + +if (zpci->uid ==UID_UNDEFINED ) { + zpci->uid =s390_pci_generate_uid (); +if (!zpci->uid) { +error_setg (errp,"no free uid could be found" ); +return ; + } + }else if (s390_pci_find_dev_by_uid (zpci->uid)) { +error_setg (errp,"uid %u already in use" , zpci->uid); +return ; + } + +if (!zpci->fid_defined) { +Error *local_error =NULL ; + + zpci->fid =s390_pci_generate_fid (&local_error); +if (local_error) { +error_propagate (errp, local_error); +return ; + } + }else if (s390_pci_find_dev_by_fid (zpci->fid)) { +error_setg (errp,"fid %u already in use" , zpci->fid); +return ; + } + + zpci->state =ZPCI_FS_RESERVED ; +} + +static void s390_pci_device_reset (DeviceState *dev) +{ +S390PCIBusDevice *pbdev =S390_PCI_DEVICE (dev); + +switch (pbdev->state) { +case ZPCI_FS_RESERVED : +return ; +case ZPCI_FS_STANDBY : +break ; +default : + pbdev->fh &= ~FH_MASK_ENABLE ; + pbdev->state =ZPCI_FS_DISABLED ; +break ; + } + +if (pbdev->summary_ind) { +pci_dereg_irqs (pbdev); + } +if (pbdev->iommu_enabled) { +pci_dereg_ioat (pbdev); + } + + pbdev->fmb_addr =0 ; +} + +static void s390_pci_get_fid (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +Property *prop = opaque; +uint32_t *ptr =qdev_get_prop_ptr (DEVICE (obj), prop); + +visit_type_uint32 (v, name, ptr, errp); +} + +static void s390_pci_set_fid (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +S390PCIBusDevice *zpci =S390_PCI_DEVICE (obj); +Property *prop = opaque; +uint32_t *ptr =qdev_get_prop_ptr (dev, prop); + +if (dev->realized) { +qdev_prop_set_after_realize (dev, name, errp); +return ; + } + +visit_type_uint32 (v, name, ptr, errp); + zpci->fid_defined = true; +} + +static PropertyInfo s390_pci_fid_propinfo = { + .name ="zpci_fid" , + .get = s390_pci_get_fid, + .set = s390_pci_set_fid, +}; + +#define DEFINE_PROP_S390_PCI_FID (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, s390_pci_fid_propinfo, uint32_t) + +static Property s390_pci_device_properties[] = { +DEFINE_PROP_UINT16 ("uid" , S390PCIBusDevice, uid,UID_UNDEFINED ), +DEFINE_PROP_S390_PCI_FID ("fid" , S390PCIBusDevice, fid), +DEFINE_PROP_STRING ("target" , S390PCIBusDevice, target), +DEFINE_PROP_END_OF_LIST (), +}; + +static void s390_pci_device_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +
hw/s390x/s390-pci-bus.c static const TypeInfo s390_pcibus_info = { · line 888
Quoted 10 lines
hw/s390x/s390-pci-bus.c +10
-0+ dc->desc ="zpci device" ; + dc->reset = s390_pci_device_reset; + dc->bus_type =TYPE_S390_PCI_BUS ; + dc->realize = s390_pci_device_realize; + dc->props = s390_pci_device_properties; +} + +static const TypeInfo s390_pci_device_info = { + .name =TYPE_S390_PCI_DEVICE , + .parent =TYPE_DEVICE ,
Hi,
Here we have the same mismatch. TYPE_S390_PCI_DEVICE does not derive from TYPE_PCI_DEVICE. If I understand correctly the "zpci device" is a wrapper to the actual PCI device, maybe the name can reflect it.
Thanks,
Marcel
Quoted 67 lines
hw/s390x/s390-pci-bus.c +5
-0+ .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_pcibus_info); +type_register_static (&s390_pci_device_info); }type_init (s390_pci_register_types)hw/s390x/s390-pci-bus.h +11
-1@@ -22,6 +22,7 @@#define TYPE_S390_PCI_HOST_BRIDGE "s390-pcihost"#define TYPE_S390_PCI_BUS "s390-pcibus" +#define TYPE_S390_PCI_DEVICE "zpci"#define FH_MASK_ENABLE 0x80000000#define FH_MASK_INSTANCE 0x7f000000#define FH_MASK_SHM 0x00ff0000@@ -29,11 +30,16 @@#define FH_SHM_VFIO 0x00010000#define FH_SHM_EMUL 0x00020000#define S390_PCIPT_ADAPTER 2 +#define ZPCI_MAX_FID 0xffffffff +#define ZPCI_MAX_UID 0xffff +#define UID_UNDEFINED 0#define S390_PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)#define S390_PCI_BUS (obj) \ OBJECT_CHECK(S390PCIBus, (obj), TYPE_S390_PCI_BUS) +#define S390_PCI_DEVICE (obj) \ + OBJECT_CHECK(S390PCIBusDevice, (obj), TYPE_S390_PCI_DEVICE)#define HP_EVENT_TO_CONFIGURED 0x0301#define HP_EVENT_RESERVED_TO_STANDBY 0x0302@@ -254,11 +260,15 @@ typedef struct S390PCIIOMMU { }S390PCIIOMMU ; typedef struct S390PCIBusDevice { + DeviceState qdev; PCIDevice *pdev; ZpciState state; bool iommu_enabled; + char *target; + uint16_t uid; uint32_t fh; uint32_t fid; + bool fid_defined; uint64_t g_iota; uint64_t pba; uint64_t pal;@@ -281,7 +291,7 @@ typedef struct S390PCIBus { typedef struct S390pciState { PCIHostState parent_obj; S390PCIBus *bus; - S390PCIBusDevice pbdev[PCI_SLOT_MAX]; + S390PCIBusDevice *pbdev[PCI_SLOT_MAX]; S390PCIIOMMU *iommu[PCI_SLOT_MAX]; AddressSpace msix_notify_as; MemoryRegion msix_notify_mr;
Re: [Qemu-devel] [PATCH 09/17] s390x/pci: introduce S390PCIBusDevice qdev
Quoted 7 lines · On Tue, 28 Jun 2016 17:49:18 +0300 Marcel Apfelbaum <[email protected]> wrote:
hw/s390x/s390-pci-bus.c static const TypeInfo s390_pcibus_info = { · line 888
Quoted 5 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
hw/s390x/s390-pci-bus.c +3
-0+static const TypeInfo s390_pci_device_info = { + .name =TYPE_S390_PCI_DEVICE , + .parent =TYPE_DEVICE ,
Quoted 5 lines
Hi,
Here we have the same mismatch.
TYPE_S390_PCI_DEVICEdoes not derive fromTYPE_PCI_DEVICE. If I understand correctly the "zpci device" is a wrapper to the actual PCI device, maybe the name can reflect it.
TYPE_S390PCI_DEVICE?
Re: [Qemu-devel] [PATCH 09/17] s390x/pci: introduce S390PCIBusDevice qdev
Quoted 10 lines · Cornelia Huck
Quoted 7 lines · On Tue, 28 Jun 2016 17:49:18 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 5 lines · Cornelia Huck
From: Yi Min Zhao <[email protected]>
hw/s390x/s390-pci-bus.c +3
-0+static const TypeInfo s390_pci_device_info = { + .name =TYPE_S390_PCI_DEVICE , + .parent =TYPE_DEVICE ,
Quoted 8 lines
Quoted 5 lines
Hi,
Here we have the same mismatch.
TYPE_S390_PCI_DEVICEdoes not derive fromTYPE_PCI_DEVICE. If I understand correctly the "zpci device" is a wrapper to the actual PCI device, maybe the name can reflect it.
TYPE_S390PCI_DEVICE?
The same as on prev discussion, maybe TYPE_ZPCI_DEVICE, but is not *that* important.
Thanks,
Marcel
PATCH 10/17 s390x/pci: enable uid-checking
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
The uid-checking facility guarantees uniqueness of the uid within the vm and exposes the real uid to the guest when listing pci devices. Let's always enable it and present it to the guest in the response to the list pci clp command.
--- hw/s390x/s390-pci-bus.h | 1 + hw/s390x/s390-pci-inst.c | 7 +++---- hw/s390x/s390-pci-inst.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
hw/s390x/s390-pci-bus.h +1 -0
@@ -33,6 +33,7 @@#define ZPCI_MAX_FID 0xffffffff#define ZPCI_MAX_UID 0xffff#define UID_UNDEFINED 0 +#define UID_CHECKING_ENABLED 0x01#define S390_PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)
hw/s390x/s390-pci-inst.c +3 -4
@@ -56,8 +56,7 @@ static int list_pci(ClpReqRspListPci *rrb, uint8_t *cc) }if ((ldl_p (&rrb->request.fmt) & ~CLP_MASK_FMT ) !=0 || -ldq_p (&rrb->request.reserved1) !=0 || -ldq_p (&rrb->request.reserved2) !=0 ) { +ldq_p (&rrb->request.reserved1) !=0 ) { res_code =CLP_RC_RESNOT0 ; rc = -EINVAL ; goto out;
@@ -91,9 +90,9 @@ static int list_pci(ClpReqRspListPci *rrb, uint8_t *cc)stl_p (&rrb->response.fmt,0 );stq_p (&rrb->response.reserved1,0 ); -stq_p (&rrb->response.reserved2,0 );stl_p (&rrb->response.mdd,FH_MASK_SHM );stw_p (&rrb->response.max_fn,PCI_MAX_FUNCTIONS ); + rrb->response.flags =UID_CHECKING_ENABLED ; rrb->response.entry_size =sizeof (ClpFhListEntry); finish =0 ; idx = resume_token;
@@ -260,7 +259,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)stl_p (&resquery->fid, pbdev->fid);stw_p (&resquery->pchid,0 );stw_p (&resquery->ug,1 ); -stl_p (&resquery->uid, pbdev->fid); +stl_p (&resquery->uid, pbdev->uid);stw_p (&resquery->hdr.rsp,CLP_RC_OK );break ; }
hw/s390x/s390-pci-inst.h +1 -1
@@ -104,7 +104,7 @@ typedef struct ClpRspListPci {uint64_t resume_token;uint32_t mdd;uint16_t max_fn; -uint8_t reserved2; +uint8_t flags;uint8_t entry_size;ClpFhListEntry fh_list[CLP_FH_LIST_NR_ENTRIES ]; }QEMU_PACKED ClpRspListPci;
Signature · 1 line
2.9.0
PATCH 11/17 s390x/pci: enable zpci hot-plug/hot-unplug
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
We need to support hot-plug/hot-unplug for the new zpci devices as well. This patch enables the present hot-plug/hot-unplug handlers to support not only generic pci devices but also zpci devices.
--- hw/s390x/s390-pci-bus.c | 119 +++++++++++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 46 deletions(-)
hw/s390x/s390-pci-bus.c +73 -46
@@ -177,16 +177,6 @@ out: psccb->header.response_code =cpu_to_be16 (rc); } -static uint32_t s390_pci_get_pfid (PCIDevice *pdev) -{ -return PCI_SLOT (pdev->devfn); -} - -static uint32_t s390_pci_get_pfh (PCIDevice *pdev) -{ -return PCI_SLOT (pdev->devfn) |FH_SHM_VFIO ; -} -static S390PCIBusDevice *s390_pci_find_dev_by_uid (uint16_t uid) {int i;
@@ -580,6 +570,7 @@ static int s390_pcihost_init(SysBusDevice *dev) phb->bus = b; s->bus =S390_PCI_BUS (qbus_create (TYPE_S390_PCI_BUS ,DEVICE (s),NULL )); +qbus_set_hotplug_handler (BUS (s->bus),DEVICE (s),NULL );QTAILQ_INIT (&s->pending_sei);return 0 ;
@@ -632,52 +623,87 @@ static S390PCIBusDevice *s390_pci_device_new(const char *target)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 =NULL ; +S390PCIBusDevice *pbdev =NULL ; +S390pciState *s =s390_get_phb (); -if (!dev->id) { -/* In the case the PCI device does not define an id */ -/* we generate one based on the PCI address */ - dev->id =g_strdup_printf ("auto_%02x:%02x.%01x" , -pci_bus_num (pci_dev->bus), -PCI_SLOT (pci_dev->devfn), -PCI_FUNC (pci_dev->devfn)); - } +if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { + pdev =PCI_DEVICE (dev); - pbdev =s390_pci_find_dev_by_target (dev->id); -if (!pbdev) { - pbdev =s390_pci_device_new (dev->id); +if (!dev->id) { +/* In the case the PCI device does not define an id */ +/* we generate one based on the PCI address */ + dev->id =g_strdup_printf ("auto_%02x:%02x.%01x" , +pci_bus_num (pdev->bus), +PCI_SLOT (pdev->devfn), +PCI_FUNC (pdev->devfn)); + } + + pbdev =s390_pci_find_dev_by_target (dev->id);if (!pbdev) { -error_setg (errp,"create zpci device failed" ); + pbdev =s390_pci_device_new (dev->id); +if (!pbdev) { +error_setg (errp,"create zpci device failed" ); + } } - } - s->pbdev[PCI_SLOT (pci_dev->devfn)] = pbdev; - pbdev->fid =s390_pci_get_pfid (pci_dev); - pbdev->pdev = pci_dev; - pbdev->state =ZPCI_FS_DISABLED ; - pbdev->fh =s390_pci_get_pfh (pci_dev); - pbdev->iommu = s->iommu[PCI_SLOT (pci_dev->devfn)]; +if (object_dynamic_cast (OBJECT (dev),"vfio-pci" )) { + pbdev->fh |=FH_SHM_VFIO ; + }else { + pbdev->fh |=FH_SHM_EMUL ; + } -s390_pcihost_setup_msix (pbdev); + pbdev->pdev = pdev; + pbdev->iommu = s->iommu[PCI_SLOT (pdev->devfn)]; + pbdev->state =ZPCI_FS_STANDBY ; +s390_pcihost_setup_msix (pbdev); -if (dev->hotplugged) { -s390_pci_generate_plug_event (HP_EVENT_RESERVED_TO_STANDBY , - pbdev->fh, pbdev->fid); -s390_pci_generate_plug_event (HP_EVENT_TO_CONFIGURED , - pbdev->fh, pbdev->fid); +if (dev->hotplugged) { +s390_pci_generate_plug_event (HP_EVENT_RESERVED_TO_STANDBY , + pbdev->fh, pbdev->fid); + } + }else if (object_dynamic_cast (OBJECT (dev),TYPE_S390_PCI_DEVICE )) { +int idx; + + pbdev =S390_PCI_DEVICE (dev); +for (idx =0 ; idx <PCI_SLOT_MAX ; idx++) { +if (!s->pbdev[idx]) { + s->pbdev[idx] = pbdev; + pbdev->fh = idx; +return ; + } + } + +error_setg (errp,"no slot for plugging zpci device" ); } }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)]; +int i; +PCIDevice *pci_dev =NULL ; +S390PCIBusDevice *pbdev =NULL ; +S390pciState *s =s390_get_phb (); + +if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { + pci_dev =PCI_DEVICE (dev); + +for (i =0 ; i <PCI_SLOT_MAX ; i++) { +if (s->pbdev[i]->pdev == pci_dev) { + pbdev = s->pbdev[i]; +break ; + } + } + +if (!pbdev) { +object_unparent (OBJECT (pci_dev)); +return ; + } + }else if (object_dynamic_cast (OBJECT (dev),TYPE_S390_PCI_DEVICE )) { + pbdev =S390_PCI_DEVICE (dev); + pci_dev = pbdev->pdev; + }switch (pbdev->state) {case ZPCI_FS_RESERVED :
@@ -691,12 +717,13 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,s390_pci_generate_plug_event (HP_EVENT_STANDBY_TO_RESERVED , pbdev->fh, pbdev->fid); - pbdev->fh =0 ; - pbdev->fid =0 ; +object_unparent (OBJECT (pci_dev)); pbdev->pdev =NULL ; pbdev->state =ZPCI_FS_RESERVED ; out: -object_unparent (OBJECT (pci_dev)); + pbdev->fid =0 ; + s->pbdev[pbdev->fh &FH_MASK_INDEX ] =NULL ; +object_unparent (OBJECT (pbdev)); }static void s390_pcihost_class_init (ObjectClass *klass,void *data)
Signature · 1 line
2.9.0
PATCH 12/17 s390x/pci: add checkings in CLP_SET_PCI_FN
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
The code in CLP_SET_PCI_FN case misses some checkings. Let's add them.
--- hw/s390x/s390-pci-inst.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
hw/s390x/s390-pci-inst.c +21 -0
@@ -212,12 +212,33 @@ int clp_service_call(S390CPU *cpu, uint8_t r2)switch (reqsetpci->oc) {case CLP_SET_ENABLE_PCI_FN : +switch (reqsetpci->ndas) { +case 0 : +stw_p (&ressetpci->hdr.rsp,CLP_RC_SETPCIFN_DMAAS ); + goto out; +case 1 : +break ; +default : +stw_p (&ressetpci->hdr.rsp,CLP_RC_SETPCIFN_RES ); + goto out; + } + +if (pbdev->fh &FH_MASK_ENABLE ) { +stw_p (&ressetpci->hdr.rsp,CLP_RC_SETPCIFN_FHOP ); + goto out; + } + pbdev->fh |=FH_MASK_ENABLE ; pbdev->state =ZPCI_FS_ENABLED ;stl_p (&ressetpci->fh, pbdev->fh);stw_p (&ressetpci->hdr.rsp,CLP_RC_OK );break ;case CLP_SET_DISABLE_PCI_FN : +if (!(pbdev->fh &FH_MASK_ENABLE )) { +stw_p (&ressetpci->hdr.rsp,CLP_RC_SETPCIFN_FHOP ); + goto out; + } +device_reset (DEVICE (pbdev)); pbdev->fh &= ~FH_MASK_ENABLE ; pbdev->state =ZPCI_FS_DISABLED ;stl_p (&ressetpci->fh, pbdev->fh);
Signature · 1 line
2.9.0
PATCH 13/17 s390x/pci: refactor s390_pci_find_dev_by_idx
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
s390_find_dev_by_idx() only indexes usable zpci devices. It implies that the index value of each zpci device is dynamic and may change if a new zpci device is plugged. So we have to use a constant index to look up the device.
--- hw/s390x/s390-pci-bus.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-)
hw/s390x/s390-pci-bus.c +1 -20
@@ -223,28 +223,9 @@ static S390PCIBusDevice *s390_pci_find_dev_by_target(const char *target)S390PCIBusDevice *s390_pci_find_dev_by_idx (uint32_t idx) { -S390PCIBusDevice *pbdev; -int i; -int j =0 ;S390pciState *s =s390_get_phb (); -for (i =0 ; i <PCI_SLOT_MAX ; i++) { - pbdev = s->pbdev[i]; -if (!pbdev) { -continue ; - } - -if (pbdev->state ==ZPCI_FS_RESERVED ) { -continue ; - } - -if (j == idx) { -return pbdev; - } - j++; - } - -return NULL ; +return s->pbdev[idx &FH_MASK_INDEX ]; }S390PCIBusDevice *s390_pci_find_dev_by_fh (uint32_t fh)
Signature · 1 line
2.9.0
PATCH 14/17 s390x/pci: refactor list_pci
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Because of the refactor of s390_pci_find_dev_by_idx(), list_pci() should be updated. We introduce a new function to get the next available zpci device. It simplifies the code of looking up zpci devices.
--- hw/s390x/s390-pci-bus.c | 20 +++++++++++++++++++ hw/s390x/s390-pci-bus.h | 1 + hw/s390x/s390-pci-inst.c | 50 +++++++++++++++++++++++------------------------- 3 files changed, 45 insertions(+), 26 deletions(-)
hw/s390x/s390-pci-bus.c +20 -0
@@ -91,6 +91,26 @@ int chsc_sei_nt2_have_event(void)return !QTAILQ_EMPTY (&s->pending_sei); } +S390PCIBusDevice *s390_pci_find_next_avail_dev (S390PCIBusDevice *pbdev) +{ +int idx =0 ; +S390PCIBusDevice *dev =NULL ; +S390pciState *s =s390_get_phb (); + +if (pbdev) { + idx = (pbdev->fh &FH_MASK_INDEX ) +1 ; + } + +for (; idx <PCI_SLOT_MAX ; idx++) { + dev = s->pbdev[idx]; +if (dev && dev->state !=ZPCI_FS_RESERVED ) { +return dev; + } + } + +return NULL ; +} +S390PCIBusDevice *s390_pci_find_dev_by_fid (uint32_t fid) {S390PCIBusDevice *pbdev;
hw/s390x/s390-pci-bus.h +1 -0
@@ -310,5 +310,6 @@ void s390_pci_generate_error_event(uint16_t pec, uint32_t fh, uint32_t fid,S390PCIBusDevice *s390_pci_find_dev_by_idx (uint32_t idx);S390PCIBusDevice *s390_pci_find_dev_by_fh (uint32_t fh);S390PCIBusDevice *s390_pci_find_dev_by_fid (uint32_t fid); +S390PCIBusDevice *s390_pci_find_next_avail_dev (S390PCIBusDevice *pbdev);#endif
hw/s390x/s390-pci-inst.c +24 -26
79 lines not on this page · raw message
Signature · 1 line
2.9.0
PATCH 15/17 s390x/pci: fix stpcifc_service_call
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Firstly the function misses dmaas checking. This patch adds it.
Secondly the function uses s390_pci_find_dev_by_fh() to look up the zpci device. This may fail if the guest provides a valid and disabled fh but fh of the associated zpci device is enabled. Thus we use s390_pci_find_dev_by_idx() instead.
--- hw/s390x/s390-pci-inst.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-inst.c +9 -1
@@ -944,6 +944,7 @@ int mpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar)int stpcifc_service_call (S390CPU *cpu,uint8_t r1,uint64_t fiba,uint8_t ar) {CPUS390XState *env = &cpu->env; +uint8_t dmaas;uint32_t fh;ZpciFib fib;S390PCIBusDevice *pbdev;
@@ -956,13 +957,20 @@ int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar) } fh = env->regs[r1] >>32 ; + dmaas = (env->regs[r1] >>16 ) &0xff ; + +if (dmaas) { +setcc (cpu,ZPCI_PCI_LS_ERR ); +s390_set_status_code (env, r1,ZPCI_STPCIFC_ST_INVAL_DMAAS ); +return 0 ; + }if (fiba &0x7 ) {program_interrupt (env,PGM_SPECIFICATION ,6 );return 0 ; } - pbdev =s390_pci_find_dev_by_fh (fh); + pbdev =s390_pci_find_dev_by_idx (fh &FH_MASK_INDEX );if (!pbdev) {setcc (cpu,ZPCI_PCI_LS_INVAL_HANDLE );return 0 ;
Signature · 1 line
2.9.0
PATCH 16/17 s390x/pci: replace fid with idx in msg data of msix
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
Present code uses fid as the part of message data of msix for looking up the specific zpci device. However it limits the usable range of fid, and the code looking up the zpci device may fail due to truncation of the fid.
In addition, fh is composed of enabled bit, FH_VIRT and the array index. So we can use the array index as the identifier to store in msg data.
--- hw/s390x/s390-pci-bus.c | 8 ++++---- hw/s390x/s390-pci-inst.c | 3 ++- target-s390x/kvm.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-)
hw/s390x/s390-pci-bus.c +4 -4
@@ -474,18 +474,18 @@ static void s390_msi_ctrl_write(void *opaque, hwaddr addr, uint64_t data, {S390PCIBusDevice *pbdev;uint32_t io_int_word; -uint32_t fid = data >>ZPCI_MSI_VEC_BITS ; +uint32_t idx = data >>ZPCI_MSI_VEC_BITS ;uint32_t vec = data &ZPCI_MSI_VEC_MASK ;uint64_t ind_bit;uint32_t sum_bit;uint32_t e =0 ; -DPRINTF ("write_msix data 0x%" PRIx64" fid %d vec 0x%x\n" , data, fid, vec); +DPRINTF ("write_msix data 0x%" PRIx64" idx %d vec 0x%x\n" , data, idx, vec); - pbdev =s390_pci_find_dev_by_fid (fid); + pbdev =s390_pci_find_dev_by_idx (idx);if (!pbdev) { e |= (vec <<ERR_EVENT_MVN_OFFSET ); -s390_pci_generate_error_event (ERR_EVENT_NOMSI ,0 , fid, addr, e); +s390_pci_generate_error_event (ERR_EVENT_NOMSI , idx,0 , addr, e);return ; }
hw/s390x/s390-pci-inst.c +2 -1
@@ -419,7 +419,8 @@ static void update_msix_table_msg_data(S390PCIBusDevice *pbdev, uint64_t offset, msg_data = (uint8_t *)data - offset %PCI_MSIX_ENTRY_SIZE +PCI_MSIX_ENTRY_VECTOR_CTRL ; - val =pci_get_long (msg_data) | (pbdev->fid <<ZPCI_MSI_VEC_BITS ); + val =pci_get_long (msg_data) | + ((pbdev->fh &FH_MASK_INDEX ) <<ZPCI_MSI_VEC_BITS );pci_set_long (msg_data, val);DPRINTF ("update msix msg_data to 0x%" PRIx64"\n" , *data); }
target-s390x/kvm.c +2 -2
@@ -2246,10 +2246,10 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, uint64_t address, uint32_t data, PCIDevice *dev) { S390PCIBusDevice *pbdev; -uint32_t fid = data >>ZPCI_MSI_VEC_BITS ; +uint32_t idx = data >>ZPCI_MSI_VEC_BITS ;uint32_t vec = data &ZPCI_MSI_VEC_MASK ; - pbdev =s390_pci_find_dev_by_fid (fid); + pbdev =s390_pci_find_dev_by_idx (idx);if (!pbdev) {DPRINTF ("add_msi_route no dev\n" );return -ENODEV ;
Signature · 1 line
2.9.0
PATCH 17/17 s390x/pci: make hot-unplug handler smoother
In reply to Cornelia HuckFrom: Yi Min Zhao <[email protected]>
The current implementation of hot-unplug handler is abrupt. Any pci operation will be just rejected if pci device is unconfigured. Thus a pci device can not be reset or destroyed in a right, smooth and safe way.
Improve this as follows:
- Notify the guest via a HP_EVENT_DECONFIGURE_REQUEST(0x303) event in the unplug handler, giving it a chance to deconfigure the device via sclp and allowing us to continue hot-unplug afterwards.
- Set up a timer that will generate the HP_EVENT_CONFIGURE_TO_STBRES (0x304) event as before if the guest did not react after an adequate time.
--- hw/s390x/s390-pci-bus.c | 35 ++++++++++++++++++++++++++++++++++- hw/s390x/s390-pci-bus.h | 3 +++ 2 files changed, 37 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +34 -1
@@ -192,6 +192,10 @@ void s390_pci_sclp_deconfigure(SCCB *sccb) } pbdev->state =ZPCI_FS_STANDBY ; rc =SCLP_RC_NORMAL_COMPLETION ; + +if (pbdev->release_timer) { +qdev_unplug (DEVICE (pbdev->pdev),NULL ); + } } out: psccb->header.response_code =cpu_to_be16 (rc);
@@ -679,6 +683,23 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, } } +static void s390_pcihost_timer_cb (void *opaque) +{ +S390PCIBusDevice *pbdev = opaque; + +if (pbdev->summary_ind) { +pci_dereg_irqs (pbdev); + } +if (pbdev->iommu_enabled) { +pci_dereg_ioat (pbdev); + } + + pbdev->state =ZPCI_FS_STANDBY ; +s390_pci_generate_plug_event (HP_EVENT_CONFIGURED_TO_STBRES , + pbdev->fh, pbdev->fid); +qdev_unplug (DEVICE (pbdev),NULL ); +} +static void s390_pcihost_hot_unplug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -712,8 +733,20 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,case ZPCI_FS_STANDBY :break ;default : -s390_pci_generate_plug_event (HP_EVENT_CONFIGURED_TO_STBRES , +s390_pci_generate_plug_event (HP_EVENT_DECONFIGURE_REQUEST , pbdev->fh, pbdev->fid); + pbdev->release_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , + s390_pcihost_timer_cb, + pbdev); +timer_mod (pbdev->release_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +HOT_UNPLUG_TIMEOUT ); +return ; + } + +if (pbdev->release_timer &&timer_pending (pbdev->release_timer)) { +timer_del (pbdev->release_timer); +timer_free (pbdev->release_timer); + pbdev->release_timer =NULL ; } s390_pci_generate_plug_event(HP_EVENT_STANDBY_TO_RESERVED,
hw/s390x/s390-pci-bus.h +3 -0
@@ -34,6 +34,7 @@#define ZPCI_MAX_UID 0xffff#define UID_UNDEFINED 0#define UID_CHECKING_ENABLED 0x01 +#define HOT_UNPLUG_TIMEOUT (NANOSECONDS_PER_SECOND * 60 * 5)#define S390_PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)
@@ -44,6 +45,7 @@#define HP_EVENT_TO_CONFIGURED 0x0301#define HP_EVENT_RESERVED_TO_STANDBY 0x0302 +#define HP_EVENT_DECONFIGURE_REQUEST 0x0303#define HP_EVENT_CONFIGURED_TO_STBRES 0x0304#define HP_EVENT_STANDBY_TO_RESERVED 0x0308
@@ -283,6 +285,7 @@ typedef struct S390PCIBusDevice {MemoryRegion iommu_mr;IndAddr *summary_ind;IndAddr *indicator; +QEMUTimer *release_timer; } S390PCIBusDevice; typedef struct S390PCIBus {
Signature · 1 line
2.9.0
Quoted 20 lines · Cornelia Huck
We had been looking at remodelling the pci representation for s390x to handle our slightly odd architecture correctly some time ago already, but now we have a patchset that we're happy with.
There's a bunch of bugfixes, cleanups and architecture conformance changes in there, but the most interesting part is the modelling (which, in some respects, takes a cue from what sPAPR does).
We introduce a 'zpci' device to hold s390x-specific properties like the uid and fid. This 'zpci' device is connected to a run-of-the-mill pci device via the 'target' property.
Example command line portion:
(quoted diff) +0
-5-device zpci,uid=1,fid=1,target=vpci0 \ -device vfio-pci,host=0000:00:00.0,id=vpci0 \ -device zpci,target=vpci1 \ -device vfio-pci,host=0001:00:00.0,id=vpci1 \ -device vfio-pci,host=0002:00:00.0,id=vpci2
Quoted 8 lines
For device vpci0, uid and fid are specified in the associated zpci device.
For device vpci1, uid and fid are automatically generated. For device vpci2, first an associated zpci device is generated and then autogenerated values for uid and fid are placed in it.This should accomodate both specifying our special parameters and re-using standard statements for pci devices.
[...]
You can still specify
Quoted 4 lines
bus/slot/function for the pci device, but it will not be propagated into the guest (as the s390 pci architecture does not allow for it; the guest only sees uid/fid).
Hi,
Please excuse my lack of s390 knowledge, but I find hard to understand how it works. If using bus/slot/function is not an option,
how can one access the configuration space? This configuration is not PCI compliant?
Thanks,
Marcel
[...]
Quoted 38 lines · On Tue, 28 Jun 2016 17:33:58 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 20 lines · Cornelia Huck
We had been looking at remodelling the pci representation for s390x to handle our slightly odd architecture correctly some time ago already, but now we have a patchset that we're happy with.
There's a bunch of bugfixes, cleanups and architecture conformance changes in there, but the most interesting part is the modelling (which, in some respects, takes a cue from what sPAPR does).
We introduce a 'zpci' device to hold s390x-specific properties like the uid and fid. This 'zpci' device is connected to a run-of-the-mill pci device via the 'target' property.
Example command line portion:
(quoted diff) +0
-5-device zpci,uid=1,fid=1,target=vpci0 \ -device vfio-pci,host=0000:00:00.0,id=vpci0 \ -device zpci,target=vpci1 \ -device vfio-pci,host=0001:00:00.0,id=vpci1 \ -device vfio-pci,host=0002:00:00.0,id=vpci2Quoted 8 lines
For device vpci0, uid and fid are specified in the associated zpci device.
For device vpci1, uid and fid are automatically generated. For device vpci2, first an associated zpci device is generated and then autogenerated values for uid and fid are placed in it.This should accomodate both specifying our special parameters and re-using standard statements for pci devices.
[...]
You can still specify
Quoted 4 lines
bus/slot/function for the pci device, but it will not be propagated into the guest (as the s390 pci architecture does not allow for it; the guest only sees uid/fid).
Quoted 5 lines
Hi,
Please excuse my lack of s390 knowledge, but I find hard to understand how it works. If using bus/slot/function is not an option,
how can one access the configuration space? This configuration is not PCI compliant?
Yes, pci on s390 is... odd. Basically, we have some special instructions for it.
For device discovery, the guest OS uses an instruction CLP (with a subfunction) to list the pci functions available: see list_pci() in hw/s390x/s390-pci-inst.c. This list contains the function handle (fh) and the fid for each function.
For nearly all subsequent operations that target a pci function (like config space accesses), the guest OS will use other instructions that take the fh as an argument (see also hw/s390x/s390-pci-inst.c, for example pci{lg,stg}_service_call() for reading/writing). The fid is used for enabling/disabling via yet another instruction.
As an example of how this is used (and how one may construct a pci "topology" from this), see arch/s390/pci/ in the Linux kernel. That's why we have bus/slot/function in the host, even though they are entirely synthetic.
Quoted 61 lines · Cornelia Huck
Quoted 38 lines · On Tue, 28 Jun 2016 17:33:58 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 20 lines · Cornelia Huck
We had been looking at remodelling the pci representation for s390x to handle our slightly odd architecture correctly some time ago already, but now we have a patchset that we're happy with.
There's a bunch of bugfixes, cleanups and architecture conformance changes in there, but the most interesting part is the modelling (which, in some respects, takes a cue from what sPAPR does).
We introduce a 'zpci' device to hold s390x-specific properties like the uid and fid. This 'zpci' device is connected to a run-of-the-mill pci device via the 'target' property.
Example command line portion:
(quoted diff) +0
-5-device zpci,uid=1,fid=1,target=vpci0 \ -device vfio-pci,host=0000:00:00.0,id=vpci0 \ -device zpci,target=vpci1 \ -device vfio-pci,host=0001:00:00.0,id=vpci1 \ -device vfio-pci,host=0002:00:00.0,id=vpci2Quoted 8 lines
For device vpci0, uid and fid are specified in the associated zpci device.
For device vpci1, uid and fid are automatically generated. For device vpci2, first an associated zpci device is generated and then autogenerated values for uid and fid are placed in it.This should accomodate both specifying our special parameters and re-using standard statements for pci devices.
[...]
You can still specify
Quoted 4 lines
bus/slot/function for the pci device, but it will not be propagated into the guest (as the s390 pci architecture does not allow for it; the guest only sees uid/fid).
Quoted 5 lines
Hi,
Please excuse my lack of s390 knowledge, but I find hard to understand how it works. If using bus/slot/function is not an option,
how can one access the configuration space? This configuration is not PCI compliant?Yes, pci on s390 is... odd. Basically, we have some special instructions for it.
For device discovery, the guest OS uses an instruction CLP (with a subfunction) to list the pci functions available: see
list_pci()inhw/s390x/s390-pci-inst.c. This list contains the function handle (fh) and the fid for each function.For nearly all subsequent operations that target a pci function (like config space accesses), the guest OS will use other instructions that take the fh as an argument (see also
hw/s390x/s390-pci-inst.c, for example pci{lg,stg}_service_call() for reading/writing). The fid is used for enabling/disabling via yet another instruction.
Quoted 5 lines
As an example of how this is used (and how one may construct a pci "topology" from this), see
arch/s390/pci/in the Linux kernel. That's why we have bus/slot/function in the host, even though they are entirely synthetic.
Thank you for the detailed explanations.
I had a quick look at the kernel bits and it makes more sense now. The upper layers call the usual PCI API and the s390 pci code "translates" it to s390 architecture, so the kernel can work as "usual".
Thanks,
Marcel
Quoted 59 lines · On Fri, 24 Jun 2016 15:28:49 +0200 Cornelia Huck <[email protected]>…
We had been looking at remodelling the pci representation for s390x to handle our slightly odd architecture correctly some time ago already, but now we have a patchset that we're happy with.
There's a bunch of bugfixes, cleanups and architecture conformance changes in there, but the most interesting part is the modelling (which, in some respects, takes a cue from what sPAPR does).
We introduce a 'zpci' device to hold s390x-specific properties like the uid and fid. This 'zpci' device is connected to a run-of-the-mill pci device via the 'target' property.
Example command line portion:
(quoted diff) +0
-5-device zpci,uid=1,fid=1,target=vpci0 \ -device vfio-pci,host=0000:00:00.0,id=vpci0 \ -device zpci,target=vpci1 \ -device vfio-pci,host=0001:00:00.0,id=vpci1 \ -device vfio-pci,host=0002:00:00.0,id=vpci2For device vpci0, uid and fid are specified in the associated zpci device.
For device vpci1, uid and fid are automatically generated. For device vpci2, first an associated zpci device is generated and then autogenerated values for uid and fid are placed in it.This should accomodate both specifying our special parameters and re-using standard statements for pci devices. You can still specify bus/slot/function for the pci device, but it will not be propagated into the guest (as the s390 pci architecture does not allow for it; the guest only sees uid/fid).
The "introduce S390PCI<foo>" patches are probably the most interesting for those looking at the modelling.
I'd love to see some feedback from a PCI perspective, as I'm happy from the s390x perspective (and I'd like to see this in 2.7).
Branch available at
git://github.com/cohuck/qemus390x-pci-updateYi Min Zhao (17):
s390x/pci: fix failures of dma map/unmap s390x/pci: acceleration for getting S390pciState s390x/pci: write fid inCLP_QUERY_PCI_FNs390x/pci: unifyFH_macros
s390x/pci: refactors390_pci_find_dev_by_fhs390x/pci: enforce zPCI state checking s390x/pci: introduce S390PCIBus
s390x/pci: introduce S390PCIIOMMU s390x/pci: introduce S390PCIBusDevice qdev s390x/pci: enable uid-checking
s390x/pci: enable zpci hot-plug/hot-unplug s390x/pci: add checkings inCLP_SET_PCI_FNs390x/pci: refactors390_pci_find_dev_by_idxs390x/pci: refactorlist_pci
s390x/pci: fixstpcifc_service_calls390x/pci: replace fid with idx in msg data of msix s390x/pci: make hot-unplug handler smoother
Quoted 8 lines
hw/s390x/s390-pci-bus.c | 579 +++++++++++++++++++++++++++++++++++------------ hw/s390x/s390-pci-bus.h | 77 ++++++- hw/s390x/s390-pci-inst.c | 266 ++++++++++++++++------ hw/s390x/s390-pci-inst.h | 7 +- include/hw/s390x/sclp.h | 1 + target-s390x/kvm.c | 4 +- 6 files changed, 718 insertions(+), 216 deletions(-)
FWIW: I plan to include this in the next s390x pullreq for 2.7, unless someone objects.
Quoted 32 lines · On Fri, 24 Jun 2016 15:28:49 +0200 Cornelia Huck <[email protected]>…
We had been looking at remodelling the pci representation for s390x to handle our slightly odd architecture correctly some time ago already, but now we have a patchset that we're happy with.
There's a bunch of bugfixes, cleanups and architecture conformance changes in there, but the most interesting part is the modelling (which, in some respects, takes a cue from what sPAPR does).
We introduce a 'zpci' device to hold s390x-specific properties like the uid and fid. This 'zpci' device is connected to a run-of-the-mill pci device via the 'target' property.
Example command line portion:
(quoted diff) +0
-5-device zpci,uid=1,fid=1,target=vpci0 \ -device vfio-pci,host=0000:00:00.0,id=vpci0 \ -device zpci,target=vpci1 \ -device vfio-pci,host=0001:00:00.0,id=vpci1 \ -device vfio-pci,host=0002:00:00.0,id=vpci2For device vpci0, uid and fid are specified in the associated zpci device.
For device vpci1, uid and fid are automatically generated. For device vpci2, first an associated zpci device is generated and then autogenerated values for uid and fid are placed in it.This should accomodate both specifying our special parameters and re-using standard statements for pci devices. You can still specify bus/slot/function for the pci device, but it will not be propagated into the guest (as the s390 pci architecture does not allow for it; the guest only sees uid/fid).
Quoted 7 lines
The "introduce S390PCI<foo>" patches are probably the most interesting for those looking at the modelling.
I'd love to see some feedback from a PCI perspective, as I'm happy from the s390x perspective (and I'd like to see this in 2.7).
Branch available at
git://github.com/cohuck/qemus390x-pci-update
Added to my s390-next branch (on top of the patches I sent today).
Quoted 28 lines
Yi Min Zhao (17):
s390x/pci: fix failures of dma map/unmap s390x/pci: acceleration for getting S390pciState s390x/pci: write fid inCLP_QUERY_PCI_FNs390x/pci: unifyFH_macros
s390x/pci: refactors390_pci_find_dev_by_fhs390x/pci: enforce zPCI state checking s390x/pci: introduce S390PCIBus
s390x/pci: introduce S390PCIIOMMU s390x/pci: introduce S390PCIBusDevice qdev s390x/pci: enable uid-checking
s390x/pci: enable zpci hot-plug/hot-unplug s390x/pci: add checkings inCLP_SET_PCI_FNs390x/pci: refactors390_pci_find_dev_by_idxs390x/pci: refactorlist_pci
s390x/pci: fixstpcifc_service_calls390x/pci: replace fid with idx in msg data of msix s390x/pci: make hot-unplug handler smootherhw/s390x/s390-pci-bus.c | 579 +++++++++++++++++++++++++++++++++++------------ hw/s390x/s390-pci-bus.h | 77 ++++++- hw/s390x/s390-pci-inst.c | 266 ++++++++++++++++------ hw/s390x/s390-pci-inst.h | 7 +- include/hw/s390x/sclp.h | 1 + target-s390x/kvm.c | 4 +- 6 files changed, 718 insertions(+), 216 deletions(-)