[PATCH 00/19] Improve PCI memory mapping API

Damien Le Moal
2024-03-29T09:09:48Z

This series introduces the new functions pci_epc_map_align(),
pci_epc_mem_map() and pci_epc_mem_unmap() to improve handling of the
PCI address mapping alignment constraints of endpoint controllers in a
controller independent manner.

The issue fixed is that the fixed alignment defined by the "align" field
of struct pci_epc_features assumes that the alignment of the endpoint
memory used to map a RC PCI address range is independent of the PCI
address being mapped. But that is not the case for the rk3399 SoC
controller: in endpoint mode, this controller uses the lower bits of the
local endpoint memory address as the lower bits for the PCI addresses
for data transfers. That is, when mapping local memory, one must take
into account the number of bits of the RC PCI address that change from
the start address of the mapping.

To fix this, the new endpoint controller method .map_align is introduced
and called from pci_epc_map_align(). This method is optional and for
controllers that do not define it, the mapping information returned
is based of the fixed alignment constraint as defined by the align
feature.

The functions pci_epc_mem_map() is a helper function which obtains
mapping information, allocates endpoint controller memory according to
the mapping size obtained and maps the memory. pci_epc_mem_map() unmaps
and frees the endpoint memory.

This series is organized as follows:
- Patch 1 and 2 tidy up the epc core code
- Patch 3 and 4 introduces the new endpoint controller method and epc
functions.
- Patch 5 to 7 modify the test endpoint driver to use these new
functions and improve the code of this driver.
- Finally, Patch 8 to 19 fix the rk3399 endpoint driver, defining a
.map_align method for it and improving its overall code readability
and features.

Damien Le Moal (18):
PCI: endpoint: Introduce pci_epc_check_func()
PCI: endpoint: Improve pci_epc_mem_alloc_addr()
PCI: endpoint: Introduce pci_epc_map_align()
PCI: endpoint: Introduce pci_epc_mem_map()/unmap()
PCI: endpoint: test: Use pci_epc_mem_map/unmap()
PCI: endpoint: test: Synchronously cancel command handler work
PCI: endpoint: test: Implement link_down event operation
PCI: rockchip-ep: Fix address translation unit programming
PCI: rockchip-ep: use macro to define EP controller .align feature
PCI: rockchip-ep: Improve rockchip_pcie_ep_unmap_addr()
PCI: rockchip-ep: Improve rockchip_pcie_ep_map_addr()
PCI: rockchip-ep: Implement the map_info endpoint controller operation
PCI: rockchip-ep: Refactor rockchip_pcie_ep_probe() memory allocations
PCI: rockchip-ep: Refactor rockchip_pcie_ep_probe() MSIX hiding
PCI: rockchip-ep: Refactor endpoint link training enable
PCI: rockship-ep: Introduce rockchip_pcie_ep_stop()
PCI: rockchip-ep: Improve link training
PCI: rockchip-ep: Handle PERST signal in endpoint mode

Wilfred Mallawa (1):
dt-bindings: pci: rockchip,rk3399-pcie-ep: Add ep-gpios property

.../bindings/pci/rockchip,rk3399-pcie-ep.yaml | 3 +
drivers/pci/controller/pcie-rockchip-ep.c | 395 ++++++++++++++----
drivers/pci/controller/pcie-rockchip.c | 17 +-
drivers/pci/controller/pcie-rockchip.h | 22 +
drivers/pci/endpoint/functions/pci-epf-test.c | 390 +++++++++--------
drivers/pci/endpoint/pci-epc-core.c | 212 +++++++---
drivers/pci/endpoint/pci-epc-mem.c | 9 +-
include/linux/pci-epc.h | 39 ++
8 files changed, 774 insertions(+), 313 deletions(-)

--
2.44.0