[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 06/15] intel-iommu: Implement get_attr() method
From: |
Joao Martins |
Subject: |
[PATCH v4 06/15] intel-iommu: Implement get_attr() method |
Date: |
Thu, 22 Jun 2023 22:48:36 +0100 |
Implement IOMMU MR get_attr() method and use the dma_translation
property to report the IOMMU_ATTR_DMA_TRANSLATION attribute.
Additionally add the necessary get_iommu_attr into the PCIIOMMUOps to
support pci_device_iommu_get_attr().
The callback in there acts as a IOMMU-specific address space walker
which will call get_attr in the IOMMUMemoryRegion backing the device to
fetch the desired attribute.
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
hw/i386/intel_iommu.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 1606d1b952d0..ed2a46e008df 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3861,6 +3861,29 @@ static void vtd_iommu_replay(IOMMUMemoryRegion
*iommu_mr, IOMMUNotifier *n)
return;
}
+static int vtd_iommu_get_attr(IOMMUMemoryRegion *iommu_mr,
+ enum IOMMUMemoryRegionAttr attr, void *data)
+{
+ VTDAddressSpace *vtd_as = container_of(iommu_mr, VTDAddressSpace, iommu);
+ IntelIOMMUState *s = vtd_as->iommu_state;
+ int ret = 0;
+
+ switch (attr) {
+ case IOMMU_ATTR_DMA_TRANSLATION:
+ {
+ bool *enabled = (bool *)(uintptr_t) data;
+
+ *enabled = s->dma_translation;
+ break;
+ }
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
/* Do the initialization. It will also be called when reset, so pay
* attention when adding new initialization stuff.
*/
@@ -4032,8 +4055,24 @@ static AddressSpace *vtd_host_dma_iommu(PCIBus *bus,
void *opaque, int devfn)
return &vtd_as->as;
}
+static int vtd_get_iommu_attr(PCIBus *bus, void *opaque, int32_t devfn,
+ enum IOMMUMemoryRegionAttr attr, void *data)
+{
+ IntelIOMMUState *s = opaque;
+ VTDAddressSpace *vtd_as;
+
+ assert(0 <= devfn && devfn < PCI_DEVFN_MAX);
+
+ vtd_as = vtd_find_add_as(s, bus, devfn, PCI_NO_PASID);
+ if (!vtd_as)
+ return -EINVAL;
+
+ return memory_region_iommu_get_attr(&vtd_as->iommu, attr, data);
+}
+
static PCIIOMMUOps vtd_iommu_ops = {
.get_address_space = vtd_host_dma_iommu,
+ .get_iommu_attr = vtd_get_iommu_attr,
};
static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)
@@ -4197,6 +4236,7 @@ static void
vtd_iommu_memory_region_class_init(ObjectClass *klass,
imrc->translate = vtd_iommu_translate;
imrc->notify_flag_changed = vtd_iommu_notify_flag_changed;
imrc->replay = vtd_iommu_replay;
+ imrc->get_attr = vtd_iommu_get_attr;
}
static const TypeInfo vtd_iommu_memory_region_info = {
--
2.17.2
- [PATCH v4 00/15] vfio: VFIO migration support with vIOMMU, Joao Martins, 2023/06/22
- [PATCH v4 01/15] hw/pci: Add a pci_setup_iommu_ops() helper, Joao Martins, 2023/06/22
- [PATCH v4 02/15] hw/pci: Refactor pci_device_iommu_address_space(), Joao Martins, 2023/06/22
- [PATCH v4 03/15] hw/pci: Introduce pci_device_iommu_get_attr(), Joao Martins, 2023/06/22
- [PATCH v4 04/15] intel-iommu: Switch to pci_setup_iommu_ops(), Joao Martins, 2023/06/22
- [PATCH v4 05/15] memory/iommu: Add IOMMU_ATTR_DMA_TRANSLATION attribute, Joao Martins, 2023/06/22
- [PATCH v4 06/15] intel-iommu: Implement get_attr() method,
Joao Martins <=
- [PATCH v4 07/15] vfio/common: Track whether DMA Translation is enabled on the vIOMMU, Joao Martins, 2023/06/22
- [PATCH v4 08/15] vfio/common: Relax vIOMMU detection when DMA translation is off, Joao Martins, 2023/06/22
- [PATCH v4 09/15] memory/iommu: Add IOMMU_ATTR_MAX_IOVA attribute, Joao Martins, 2023/06/22
- [PATCH v4 10/15] intel-iommu: Implement IOMMU_ATTR_MAX_IOVA get_attr() attribute, Joao Martins, 2023/06/22
- [PATCH v4 11/15] vfio/common: Move dirty tracking ranges update to helper, Joao Martins, 2023/06/22
- [PATCH v4 14/15] vfio/common: Optimize device dirty page tracking with vIOMMU, Joao Martins, 2023/06/22
- [PATCH v4 13/15] vfio/common: Extract vIOMMU code from vfio_sync_dirty_bitmap(), Joao Martins, 2023/06/22
- [PATCH v4 15/15] vfio/common: Block migration with vIOMMUs without address width limits, Joao Martins, 2023/06/22
- [PATCH v4 12/15] vfio/common: Support device dirty page tracking with vIOMMU, Joao Martins, 2023/06/22
- Re: [PATCH v4 00/15] vfio: VFIO migration support with vIOMMU, Joao Martins, 2023/06/22