[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v7 14/26] vfio: Helper to get IRQ info including capabilities
From: |
Eric Auger |
Subject: |
[RFC v7 14/26] vfio: Helper to get IRQ info including capabilities |
Date: |
Mon, 16 Nov 2020 19:13:37 +0100 |
As done for vfio regions, add helpers to retrieve irq info
including their optional capabilities.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
include/hw/vfio/vfio-common.h | 7 +++
hw/vfio/common.c | 97 +++++++++++++++++++++++++++++++++++
hw/vfio/trace-events | 1 +
3 files changed, 105 insertions(+)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c61720ccf9..8153cbae92 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -227,6 +227,13 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info
*info,
unsigned int *avail);
struct vfio_info_cap_header *
vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
+int vfio_get_irq_info(VFIODevice *vbasedev, int index,
+ struct vfio_irq_info **info);
+int vfio_get_dev_irq_info(VFIODevice *vbasedev, uint32_t type,
+ uint32_t subtype, struct vfio_irq_info **info);
+bool vfio_has_irq_cap(VFIODevice *vbasedev, int irq, uint16_t cap_type);
+struct vfio_info_cap_header *
+vfio_get_irq_info_cap(struct vfio_irq_info *info, uint16_t id);
#endif
extern const MemoryListener vfio_prereg_listener;
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index ab7dd36ead..8700d2b9d6 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1379,6 +1379,25 @@ bool vfio_get_info_dma_avail(struct
vfio_iommu_type1_info *info,
return true;
}
+struct vfio_info_cap_header *
+vfio_get_irq_info_cap(struct vfio_irq_info *info, uint16_t id)
+{
+ struct vfio_info_cap_header *hdr;
+ void *ptr = info;
+
+ if (!(info->flags & VFIO_IRQ_INFO_FLAG_CAPS)) {
+ return NULL;
+ }
+
+ for (hdr = ptr + info->cap_offset; hdr != ptr; hdr = ptr + hdr->next) {
+ if (hdr->id == id) {
+ return hdr;
+ }
+ }
+
+ return NULL;
+}
+
static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
struct vfio_region_info *info)
{
@@ -2311,6 +2330,33 @@ retry:
return 0;
}
+int vfio_get_irq_info(VFIODevice *vbasedev, int index,
+ struct vfio_irq_info **info)
+{
+ size_t argsz = sizeof(struct vfio_irq_info);
+
+ *info = g_malloc0(argsz);
+
+ (*info)->index = index;
+retry:
+ (*info)->argsz = argsz;
+
+ if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_IRQ_INFO, *info)) {
+ g_free(*info);
+ *info = NULL;
+ return -errno;
+ }
+
+ if ((*info)->argsz > argsz) {
+ argsz = (*info)->argsz;
+ *info = g_realloc(*info, argsz);
+
+ goto retry;
+ }
+
+ return 0;
+}
+
int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
uint32_t subtype, struct vfio_region_info **info)
{
@@ -2346,6 +2392,42 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev,
uint32_t type,
return -ENODEV;
}
+int vfio_get_dev_irq_info(VFIODevice *vbasedev, uint32_t type,
+ uint32_t subtype, struct vfio_irq_info **info)
+{
+ int i;
+
+ for (i = 0; i < vbasedev->num_irqs; i++) {
+ struct vfio_info_cap_header *hdr;
+ struct vfio_irq_info_cap_type *cap_type;
+
+ if (vfio_get_irq_info(vbasedev, i, info)) {
+ continue;
+ }
+
+ hdr = vfio_get_irq_info_cap(*info, VFIO_IRQ_INFO_CAP_TYPE);
+ if (!hdr) {
+ g_free(*info);
+ continue;
+ }
+
+ cap_type = container_of(hdr, struct vfio_irq_info_cap_type, header);
+
+ trace_vfio_get_dev_irq(vbasedev->name, i,
+ cap_type->type, cap_type->subtype);
+
+ if (cap_type->type == type && cap_type->subtype == subtype) {
+ return 0;
+ }
+
+ g_free(*info);
+ }
+
+ *info = NULL;
+ return -ENODEV;
+}
+
+
bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
{
struct vfio_region_info *info = NULL;
@@ -2361,6 +2443,21 @@ bool vfio_has_region_cap(VFIODevice *vbasedev, int
region, uint16_t cap_type)
return ret;
}
+bool vfio_has_irq_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
+{
+ struct vfio_region_info *info = NULL;
+ bool ret = false;
+
+ if (!vfio_get_region_info(vbasedev, region, &info)) {
+ if (vfio_get_region_info_cap(info, cap_type)) {
+ ret = true;
+ }
+ g_free(info);
+ }
+
+ return ret;
+}
+
/*
* Interfaces for IBM EEH (Enhanced Error Handling)
*/
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 63c3e08725..447b7ed9f5 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -117,6 +117,7 @@ vfio_region_unmap(const char *name, unsigned long offset,
unsigned long end) "Re
vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas)
"Device %s region %d: %d sparse mmap entries"
vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end)
"sparse entry %d [0x%lx - 0x%lx]"
vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t
subtype) "%s index %d, %08x/%0x8"
+vfio_get_dev_irq(const char *name, int index, uint32_t type, uint32_t subtype)
"%s index %d, %08x/%0x8"
vfio_dma_unmap_overflow_workaround(void) ""
vfio_iommu_addr_inv_iotlb(int asid, uint64_t addr, uint64_t size, uint64_t
nb_granules, bool leaf) "nested IOTLB invalidate asid=%d, addr=0x%"PRIx64"
granule_size=0x%"PRIx64" nb_granules=0x%"PRIx64" leaf=%d"
vfio_iommu_asid_inv_iotlb(int asid) "nested IOTLB invalidate asid=%d"
--
2.21.3
- [RFC v7 04/26] memory: Add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, (continued)
- [RFC v7 04/26] memory: Add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, Eric Auger, 2020/11/16
- [RFC v7 05/26] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2020/11/16
- [RFC v7 06/26] memory: Add arch_id and leaf fields in IOTLBEntry, Eric Auger, 2020/11/16
- [RFC v7 07/26] iommu: Introduce generic header, Eric Auger, 2020/11/16
- [RFC v7 08/26] pci: introduce PCIPASIDOps to PCIDevice, Eric Auger, 2020/11/16
- [RFC v7 09/26] vfio: Force nested if iommu requires it, Eric Auger, 2020/11/16
- [RFC v7 10/26] vfio: Introduce hostwin_from_range helper, Eric Auger, 2020/11/16
- [RFC v7 11/26] vfio: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2020/11/16
- [RFC v7 12/26] vfio: Set up nested stage mappings, Eric Auger, 2020/11/16
- [RFC v7 13/26] vfio: Pass stage 1 MSI bindings to the host, Eric Auger, 2020/11/16
- [RFC v7 14/26] vfio: Helper to get IRQ info including capabilities,
Eric Auger <=
- [RFC v7 15/26] vfio/pci: Register handler for iommu fault, Eric Auger, 2020/11/16
- [RFC v7 16/26] vfio/pci: Set up the DMA FAULT region, Eric Auger, 2020/11/16
- [RFC v7 17/26] vfio/pci: Implement the DMA fault handler, Eric Auger, 2020/11/16
- [RFC v7 18/26] hw/arm/smmuv3: Advertise MSI_TRANSLATE attribute, Eric Auger, 2020/11/16
- [RFC v7 19/26] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2020/11/16
- [RFC v7 20/26] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2020/11/16
- [RFC v7 21/26] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2020/11/16
- [RFC v7 23/26] hw/arm/smmuv3: Implement fault injection, Eric Auger, 2020/11/16
- [RFC v7 22/26] hw/arm/smmuv3: Pass stage 1 configurations to the host, Eric Auger, 2020/11/16
- [RFC v7 24/26] hw/arm/smmuv3: Allow MAP notifiers, Eric Auger, 2020/11/16