Add new API to support access pci mmio memory directly
This issue should go together with pull request for sbsa:
https://github.com/ARM-software/sbsa-acs/pull/226
`From 6db899ec1904399dc5d6a144d394a9bd54c23404 Mon Sep 17 00:00:00 2001 From: Tuan Phan tphan@amperecomputing.com Date: Fri, 18 Mar 2022 11:58:58 -0700 Subject: [PATCH] Add API to get pci host address from bar index
This API needed for testcase 405 when trying to access memory directly.
tphan@amperecomputing.com
Signed-off-by: Tuan Phan.../files/platform/pal_linux/files/src/pal_pcie.c | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+)
diff --git a/sbsa-acs-drv/files/platform/pal_linux/files/src/pal_pcie.c b/sbsa-acs-drv/files/platform/pal_linux/files/src/pal_pcie.c index f5d12bd..9ae545a 100644 --- a/sbsa-acs-drv/files/platform/pal_linux/files/src/pal_pcie.c +++ b/sbsa-acs-drv/files/platform/pal_linux/files/src/pal_pcie.c @@ -30,6 +30,11 @@ #include <linux/pci-acpi.h> #include <linux/interrupt.h>
+#define PCIE_EXTRACT_BDF_SEG(bdf) ((bdf >> 24) & 0xFF) +#define PCIE_EXTRACT_BDF_BUS(bdf) ((bdf >> 16) & 0xFF) +#define PCIE_EXTRACT_BDF_DEV(bdf) ((bdf >> 8) & 0xFF) +#define PCIE_EXTRACT_BDF_FUNC(bdf) (bdf & 0xFF) + /** @brief Read a device MSI(X) vector
@@ -655,3 +660,55 @@ pal_pcie_check_device_list() { return 0; } + +/**
- @brief Reads 32-bit data from PCIe MMIO space pointed by Bus,
-
Device, Function, Bar index and memory offset, using UEFI PciIoProtocol
- @param Bdf - BDF value for the device
- @param bar - Bar index
- @param offset - Register offset within a device PCIe config space
- @param *data - 32 bit value at offset
- @return success/failure +**/ +uint32_t pal_pcie_mmio_read(uint32_t Bdf, uint32_t bar, uint64_t offset, uint32_t *data) +{
- return PCIE_NO_MAPPING; +}
+/**
- @brief Writes 32-bit data to PCIe MMIO space pointed by Bus,
-
Device, Function, Bar index and memory offset, using UEFI PciIoProtocol
- @param Bdf - BDF value for the device
- @param bar - Bar index
- @param offset - Register offset within a device PCIe config space
- @param data - 32 bit value at offset
- @return success/failure +**/ +uint32_t pal_pcie_mmio_write(uint32_t Bdf, uint32_t bar, uint64_t offset, uint32_t *data) +{
- return PCIE_NO_MAPPING; +}
+/**
- @brief Get bus address base from bar index
- @param bdf - BDF value for the device
- @param bar - Bar index
- @return Returns 0 if no bus address, otherwise bus address base. +**/ +uint64_t pal_pcie_bar_to_bus_address(uint32_t bdf, uint32_t bar) +{
- struct pci_dev *pdev;
- uint32_t bus = PCIE_EXTRACT_BDF_BUS(bdf);
- uint32_t dev = PCIE_EXTRACT_BDF_DEV(bdf);
- uint32_t func = PCIE_EXTRACT_BDF_FUNC(bdf);
- uint32_t seg = PCIE_EXTRACT_BDF_SEG(bdf);
- pdev = pci_get_domain_bus_and_slot(seg, bus, PCI_DEVFN(dev, func));
- if (!pdev) {
- return 0;
- }
- return pdev->resource[bar].start; +} -- 2.7.4
`