From: Matthew Rosato <mjrosato@linux.ibm.com>
To: cohuck@redhat.com
Cc: walling@linux.ibm.com, alex.williamson@redhat.com,
pmorel@linux.ibm.com, david@redhat.com, mst@redhat.com,
qemu-devel@nongnu.org, pasic@linux.ibm.com,
borntraeger@de.ibm.com, qemu-s390x@nongnu.org,
pbonzini@redhat.com, rth@twiddle.net
Subject: [Qemu-devel] [PATCH v3 5/5] s390: vfio_pci: Get zPCI function info from host
Date: Fri, 6 Sep 2019 20:16:29 -0400 [thread overview]
Message-ID: <1567815389-18229-6-git-send-email-mjrosato@linux.ibm.com> (raw)
In-Reply-To: <1567815389-18229-1-git-send-email-mjrosato@linux.ibm.com>
From: Pierre Morel <pmorel@linux.ibm.com>
We use the VFIO_REGION_SUBTYPE_ZDEV_CLP subregion of
PCI_VENDOR_ID_IBM to retrieve the CLP information the
kernel exports.
To be compatible with previous kernel versions we fall back
on previous predefined values, same as the emulation values,
when the region is not found or when any problem happens
during the search for the information.
Once we retrieved the host device information, we take care to
- use the virtual UID and FID
- Disable all the IOMMU flags we do not support yet.
Just keeping the refresh bit.
Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
hw/s390x/s390-pci-bus.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++--
hw/s390x/s390-pci-bus.h | 2 ++
2 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 0d404c3..5069795 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -15,6 +15,8 @@
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "cpu.h"
+#include "s390-pci-clp.h"
+#include <linux/vfio_zdev.h>
#include "s390-pci-bus.h"
#include "s390-pci-inst.h"
#include "hw/pci/pci_bus.h"
@@ -24,6 +26,9 @@
#include "qemu/error-report.h"
#include "qemu/module.h"
+#include "hw/vfio/pci.h"
+#include <sys/ioctl.h>
+
#ifndef DEBUG_S390PCI_BUS
#define DEBUG_S390PCI_BUS 0
#endif
@@ -781,6 +786,76 @@ static void set_pbdev_info(S390PCIBusDevice *pbdev)
pbdev->pci_grp = s390_grp_find(ZPCI_DEFAULT_FN_GRP);
}
+static int get_pbdev_info(S390PCIBusDevice *pbdev)
+{
+ VFIOPCIDevice *vfio_pci;
+ VFIODevice *vdev;
+ struct vfio_region_info *info;
+ CLPRegion *clp_region;
+ int size;
+ int ret;
+
+ vfio_pci = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+ vdev = &vfio_pci->vbasedev;
+
+ if (vdev->num_regions < VFIO_PCI_NUM_REGIONS + 1) {
+ /* Fall back to old handling */
+ return -ENODEV;
+ }
+
+ ret = vfio_get_dev_region_info(vdev,
+ PCI_VENDOR_ID_IBM |
+ VFIO_REGION_TYPE_PCI_VENDOR_TYPE,
+ VFIO_REGION_SUBTYPE_ZDEV_CLP, &info);
+ if (ret) {
+ /* Fall back to old handling */
+ return -EIO;
+ }
+
+ if (info->size != (sizeof(CLPRegion) + CLP_UTIL_STR_LEN)) {
+ /* Fall back to old handling */
+ g_free(info);
+ return -ENOMEM;
+ }
+ clp_region = g_malloc0(sizeof(*clp_region) + CLP_UTIL_STR_LEN);
+ size = pread(vdev->fd, clp_region, (sizeof(*clp_region) + CLP_UTIL_STR_LEN),
+ info->offset);
+ if (size != (sizeof(*clp_region) + CLP_UTIL_STR_LEN)) {
+ goto end;
+ }
+
+ pbdev->zpci_fn.fid = pbdev->fid;
+ pbdev->zpci_fn.uid = pbdev->uid;
+ pbdev->zpci_fn.sdma = clp_region->start_dma;
+ pbdev->zpci_fn.edma = clp_region->end_dma;
+ pbdev->zpci_fn.pchid = clp_region->pchid;
+ pbdev->zpci_fn.ug = clp_region->gid;
+ pbdev->pci_grp = s390_grp_find(clp_region->gid);
+
+ if (!pbdev->pci_grp) {
+ ClpRspQueryPciGrp *resgrp;
+
+ pbdev->pci_grp = s390_grp_create(clp_region->gid);
+
+ resgrp = &pbdev->pci_grp->zpci_grp;
+ if (clp_region->flags & VFIO_PCI_ZDEV_FLAGS_REFRESH) {
+ resgrp->fr = 1;
+ }
+ stq_p(&resgrp->dasm, clp_region->dasm);
+ stq_p(&resgrp->msia, clp_region->msi_addr);
+ stw_p(&resgrp->mui, clp_region->mui);
+ stw_p(&resgrp->i, clp_region->noi);
+ /* These two must be queried in a next iteration */
+ stw_p(&resgrp->maxstbl, 128);
+ resgrp->version = 0;
+ }
+
+end:
+ g_free(info);
+ g_free(clp_region);
+ return ret;
+}
+
static void s390_pcihost_realize(DeviceState *dev, Error **errp)
{
PCIBus *b;
@@ -853,7 +928,8 @@ static int s390_pci_msix_init(S390PCIBusDevice *pbdev)
name = g_strdup_printf("msix-s390-%04x", pbdev->uid);
memory_region_init_io(&pbdev->msix_notify_mr, OBJECT(pbdev),
&s390_msi_ctrl_ops, pbdev, name, PAGE_SIZE);
- memory_region_add_subregion(&pbdev->iommu->mr, ZPCI_MSI_ADDR,
+ memory_region_add_subregion(&pbdev->iommu->mr,
+ pbdev->pci_grp->zpci_grp.msia,
&pbdev->msix_notify_mr);
g_free(name);
@@ -1003,12 +1079,15 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
pbdev->iommu = s390_pci_get_iommu(s, pci_get_bus(pdev), pdev->devfn);
pbdev->iommu->pbdev = pbdev;
pbdev->state = ZPCI_FS_DISABLED;
- set_pbdev_info(pbdev);
if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
pbdev->fh |= FH_SHM_VFIO;
+ if (get_pbdev_info(pbdev) != 0) {
+ set_pbdev_info(pbdev);
+ }
} else {
pbdev->fh |= FH_SHM_EMUL;
+ set_pbdev_info(pbdev);
}
if (s390_pci_msix_init(pbdev)) {
diff --git a/hw/s390x/s390-pci-bus.h b/hw/s390x/s390-pci-bus.h
index 8c969d1..151e2d0 100644
--- a/hw/s390x/s390-pci-bus.h
+++ b/hw/s390x/s390-pci-bus.h
@@ -320,6 +320,8 @@ typedef struct S390PCIGroup {
} S390PCIGroup;
S390PCIGroup *s390_grp_find(int ug);
+typedef struct vfio_region_zpci_info CLPRegion;
+
struct S390PCIBusDevice {
DeviceState qdev;
PCIDevice *pdev;
--
1.8.3.1
prev parent reply other threads:[~2019-09-07 0:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-07 0:16 [Qemu-devel] [PATCH v3 0/5] Retrieving zPCI specific info from QEMU Matthew Rosato
2019-09-07 0:16 ` [Qemu-devel] [PATCH v3 1/5] vfio: vfio_iommu_type1: linux header place holder Matthew Rosato
2019-09-08 13:08 ` Michael S. Tsirkin
2019-09-07 0:16 ` [Qemu-devel] [PATCH v3 2/5] s390: PCI: Creation a header dedicated to PCI CLP Matthew Rosato
2019-09-07 0:16 ` [Qemu-devel] [PATCH v3 3/5] s390: vfio_pci: Use a PCI Group structure Matthew Rosato
2019-09-09 5:18 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2019-09-09 16:21 ` Matthew Rosato
2019-09-07 0:16 ` [Qemu-devel] [PATCH v3 4/5] s390: vfio_pci: Use a PCI Function structure Matthew Rosato
2019-09-07 0:16 ` Matthew Rosato [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1567815389-18229-6-git-send-email-mjrosato@linux.ibm.com \
--to=mjrosato@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=pmorel@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rth@twiddle.net \
--cc=walling@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).