[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH ats_vtd 12/22] pci: add a pci-level initialization function for i
From: |
CLEMENT MATHIEU--DRIF |
Subject: |
[PATCH ats_vtd 12/22] pci: add a pci-level initialization function for iommu notifiers |
Date: |
Tue, 21 May 2024 13:11:46 +0000 |
We add a convenient way to initialize an device-iotlb notifier.
This is meant to be used by ATS-capable devices.
pci_device_iommu_memory_region_pasid is introduces in this commit and
will be used in several other SVM-related functions exposed in
the PCI API.
Signed-off-by: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com>
---
hw/pci/pci.c | 40 ++++++++++++++++++++++++++++++++++++++++
include/hw/pci/pci.h | 15 +++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 3fe47d4002..0e14ef4ab2 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2747,6 +2747,46 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice
*dev)
return &address_space_memory;
}
+static IOMMUMemoryRegion *pci_device_iommu_memory_region_pasid(PCIDevice *dev,
+ uint32_t pasid)
+{
+ PCIBus *bus;
+ PCIBus *iommu_bus;
+ int devfn;
+
+ /*
+ * This function is for internal use in the module,
+ * we can call it with PCI_NO_PASID
+ */
+ if (!dev->is_master ||
+ ((pasid != PCI_NO_PASID) && !pcie_pasid_enabled(dev))) {
+ return NULL;
+ }
+
+ pci_device_get_iommu_bus_devfn(dev, &bus, &iommu_bus, &devfn);
+ if (iommu_bus && iommu_bus->iommu_ops->get_memory_region_pasid) {
+ return iommu_bus->iommu_ops->get_memory_region_pasid(bus,
+ iommu_bus->iommu_opaque, devfn, pasid);
+ }
+ return NULL;
+}
+
+bool pci_iommu_init_iotlb_notifier(PCIDevice *dev, uint32_t pasid,
+ IOMMUNotifier *n, IOMMUNotify fn,
+ void* opaque)
+{
+ IOMMUMemoryRegion *iommu_mr = pci_device_iommu_memory_region_pasid(dev,
+ pasid);
+ if (!iommu_mr) {
+ return false;
+ }
+ iommu_notifier_init(n, fn, IOMMU_NOTIFIER_DEVIOTLB_EVENTS, 0, HWADDR_MAX,
+ memory_region_iommu_attrs_to_index(iommu_mr,
+
MEMTXATTRS_UNSPECIFIED));
+ n->opaque = opaque;
+ return true;
+}
+
AddressSpace *pci_device_iommu_address_space_pasid(PCIDevice *dev,
uint32_t pasid)
{
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 6c60f7a7c5..2147981423 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -458,6 +458,21 @@ bool pci_device_set_iommu_device(PCIDevice *dev,
HostIOMMUDevice *hiod,
Error **errp);
void pci_device_unset_iommu_device(PCIDevice *dev);
+/**
+ * pci_iommu_init_iotlb_notifier: initialize an IOMMU notifier
+ *
+ * This function is used by devices before registering an IOTLB notifier
+ *
+ * @dev: the device
+ * @pasid: the pasid of the address space to watch
+ * @n: the notifier to initialize
+ * @fn: the callback to be installed
+ * @opaque: user pointer that can be used to store a state
+ */
+bool pci_iommu_init_iotlb_notifier(PCIDevice *dev, uint32_t pasid,
+ IOMMUNotifier *n, IOMMUNotify fn,
+ void* opaque);
+
/**
* pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus
*
--
2.44.0
- [PATCH ats_vtd 13/22] intel_iommu: implement the get_address_space_pasid iommu operation, (continued)
- [PATCH ats_vtd 13/22] intel_iommu: implement the get_address_space_pasid iommu operation, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 19/22] memory: add an API for ATS support, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 17/22] atc: generic ATC that can be used by PCIe devices that support SVM, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 01/22] intel_iommu: fix FRCD construction macro., CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 07/22] pcie: helper functions to check if PASID and ATS are enabled, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 15/22] memory: Allow to store the PASID in IOMMUTLBEntry, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 22/22] intel_iommu: add support for ATS, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 20/22] pci: add a pci-level API for ATS, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 10/22] pci: add IOMMU operations to get address spaces and memory regions with PASID, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 11/22] memory: store user data pointer in the IOMMU notifiers, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 12/22] pci: add a pci-level initialization function for iommu notifiers,
CLEMENT MATHIEU--DRIF <=
- [PATCH ats_vtd 04/22] intel_iommu: do not consider wait_desc as an invalid descriptor, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 18/22] atc: add unit tests, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 14/22] intel_iommu: implement the get_memory_region_pasid iommu operation, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 09/22] pci: cache the bus mastering status in the device, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 02/22] intel_iommu: make types match, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 03/22] intel_iommu: return page walk level even when the translation fails, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 16/22] intel_iommu: fill the PASID field when creating an instance of IOMMUTLBEntry, CLEMENT MATHIEU--DRIF, 2024/05/21
- [PATCH ats_vtd 21/22] intel_iommu: set the address mask even when a translation fails, CLEMENT MATHIEU--DRIF, 2024/05/21