[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 05/19] pcie: Add helper to declare PASID capability for a pcie
From: |
CLEMENT MATHIEU--DRIF |
Subject: |
[PATCH v1 05/19] pcie: Add helper to declare PASID capability for a pcie device |
Date: |
Fri, 29 Nov 2024 07:43:52 +0000 |
From: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com>
Signed-off-by: Clément Mathieu--Drif <clement.mathieu--drif@eviden.com>
---
hw/pci/pcie.c | 24 ++++++++++++++++++++++++
include/hw/pci/pcie.h | 6 +++++-
include/hw/pci/pcie_regs.h | 5 +++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 0b455c8654..5b896496ae 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -1210,3 +1210,27 @@ void pcie_acs_reset(PCIDevice *dev)
pci_set_word(dev->config + dev->exp.acs_cap + PCI_ACS_CTRL, 0);
}
}
+
+/* PASID */
+void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width,
+ bool exec_perm, bool priv_mod)
+{
+ assert(pasid_width <= PCI_EXT_CAP_PASID_MAX_WIDTH);
+ static const uint16_t control_reg_rw_mask = 0x07;
+ uint16_t capability_reg = pasid_width;
+
+ pcie_add_capability(dev, PCI_EXT_CAP_ID_PASID, PCI_PASID_VER, offset,
+ PCI_EXT_CAP_PASID_SIZEOF);
+
+ capability_reg <<= PCI_PASID_CAP_WIDTH_SHIFT;
+ capability_reg |= exec_perm ? PCI_PASID_CAP_EXEC : 0;
+ capability_reg |= priv_mod ? PCI_PASID_CAP_PRIV : 0;
+ pci_set_word(dev->config + offset + PCI_PASID_CAP, capability_reg);
+
+ /* Everything is disabled by default */
+ pci_set_word(dev->config + offset + PCI_PASID_CTRL, 0);
+
+ pci_set_word(dev->wmask + offset + PCI_PASID_CTRL, control_reg_rw_mask);
+
+ dev->exp.pasid_cap = offset;
+}
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index b8d59732bc..aa040c3e97 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -72,8 +72,9 @@ struct PCIExpressDevice {
uint16_t aer_cap;
PCIEAERLog aer_log;
- /* Offset of ATS capability in config space */
+ /* Offset of ATS and PASID capabilities in config space */
uint16_t ats_cap;
+ uint16_t pasid_cap;
/* ACS */
uint16_t acs_cap;
@@ -152,4 +153,7 @@ void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev,
Error **errp);
void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp);
+
+void pcie_pasid_init(PCIDevice *dev, uint16_t offset, uint8_t pasid_width,
+ bool exec_perm, bool priv_mod);
#endif /* QEMU_PCIE_H */
diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h
index 9d3b6868dc..4d9cf4a29c 100644
--- a/include/hw/pci/pcie_regs.h
+++ b/include/hw/pci/pcie_regs.h
@@ -86,6 +86,11 @@ typedef enum PCIExpLinkWidth {
#define PCI_ARI_VER 1
#define PCI_ARI_SIZEOF 8
+/* PASID */
+#define PCI_PASID_VER 1
+#define PCI_EXT_CAP_PASID_MAX_WIDTH 20
+#define PCI_PASID_CAP_WIDTH_SHIFT 8
+
/* AER */
#define PCI_ERR_VER 2
#define PCI_ERR_SIZEOF 0x48
--
2.47.0
- [PATCH v1 00/19] Rebase ATS onto lastest Qemu mailing list state, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 02/19] intel_iommu: Declare supported PASID size, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 05/19] pcie: Add helper to declare PASID capability for a pcie device,
CLEMENT MATHIEU--DRIF <=
- [PATCH v1 07/19] pcie: Helper function to check if ATS is enabled, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 08/19] pci: Cache the bus mastering status in the device, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 13/19] atc: Generic ATC that can be used by PCIe devices that support SVM, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 15/19] memory: Add an API for ATS support, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 16/19] pci: Add a pci-level API for ATS, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 11/19] memory: Store user data pointer in the IOMMU notifiers, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 18/19] intel_iommu: Return page walk level even when the translation fails, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 03/19] memory: Allow to store the PASID in IOMMUTLBEntry, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 01/19] memory: Add permissions in IOMMUAccessFlags, CLEMENT MATHIEU--DRIF, 2024/11/29
- [PATCH v1 04/19] intel_iommu: Fill the PASID field when creating an IOMMUTLBEntry, CLEMENT MATHIEU--DRIF, 2024/11/29