[PATCH v1 4/8] pci: declare structures and IOMMU operation for PRI

CLEMENT MATHIEU--DRIF posted 8 patches 5 months, 4 weeks ago
[PATCH v1 4/8] pci: declare structures and IOMMU operation for PRI
Posted by CLEMENT MATHIEU--DRIF 5 months, 4 weeks ago
The API deliberately designed to be similar to the ATS one.
We define a struct that stores a function pointer to the device's callback.
Registering and unregistering a notifier is done using a pair of functions
that will be added in a future commit of this series.

An IOMMU can support PRI by implementing the iommu_pri_request_page
operation declared in IOMMUMemoryRegionClass.

Signed-off-by: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com>
---
 include/exec/memory.h    | 30 ++++++++++++++++++++++++++++++
 include/hw/pci/pci_bus.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 0ced7c33b1..f4780d3920 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -218,6 +218,25 @@ typedef struct IOMMUTLBEvent {
     IOMMUTLBEntry entry;
 } IOMMUTLBEvent;
 
+/* Page Request Interface */
+#define IOMMU_PRI_RESP_CODE_SUCCESS(val)            (!(val))
+#define IOMMU_PRI_RESP_CODE_INVALID_REQUEST(val)    ((val) == 0x1u)
+#define IOMMU_PRI_RESP_CODE_FAILURE(val)            ((val) & 0xeu)
+
+typedef struct IOMMUPRIResponse {
+    uint8_t response_code;
+    uint16_t prgi;
+} IOMMUPRIResponse;
+
+struct IOMMUPRINotifier;
+
+typedef void (*IOMMUPRINotify)(struct IOMMUPRINotifier *notifier,
+                               IOMMUPRIResponse *response);
+
+typedef struct IOMMUPRINotifier {
+    IOMMUPRINotify notify;
+} IOMMUPRINotifier;
+
 /* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */
 #define RAM_PREALLOC   (1 << 0)
 
@@ -589,6 +608,16 @@ struct IOMMUMemoryRegionClass {
                                              IOMMUTLBEntry *result,
                                              size_t result_length,
                                              uint32_t *err_count);
+
+    /**
+     * @iommu_pri_request_page:
+     * This method must be implemented if the IOMMU has PRI enabled
+     *
+     * @see pci_pri_request_page_pasid
+     */
+    int (*iommu_pri_request_page)(IOMMUMemoryRegion *iommu, hwaddr addr,
+                                  bool lpig, uint16_t prgi, bool is_read,
+                                  bool is_write, bool exec_req, bool priv_req);
 };
 
 typedef struct RamDiscardListener RamDiscardListener;
@@ -878,6 +907,7 @@ struct IOMMUMemoryRegion {
 
     QLIST_HEAD(, IOMMUNotifier) iommu_notify;
     IOMMUNotifierFlag iommu_notify_flags;
+    IOMMUPRINotifier *pri_notifier;
 };
 
 #define IOMMU_NOTIFIER_FOREACH(n, mr) \
diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h
index 2261312546..eaa777fde4 100644
--- a/include/hw/pci/pci_bus.h
+++ b/include/hw/pci/pci_bus.h
@@ -29,6 +29,7 @@ enum PCIBusFlags {
 };
 
 #define PCI_NO_PASID UINT32_MAX
+#define PCI_PRI_PRGI_MASK 0x1ffU
 
 struct PCIBus {
     BusState qbus;
-- 
2.45.1