On Mon, 2026-09-28 at 14:19 +0300, Leon Romanovsky wrote:
From: Leon Romanovsky leonro@nvidia.com
The PCIe ATS Enable bit covers the whole device, so P2PDMA cannot tell from it whether a client will translate a given address. Most devices translate any address once ATS is enabled, but some choose ATS per DMA mapping and can still use bus addresses for the rest.
Add pcim_p2pdma_set_ats_per_mapping() so the driver of such a device can declare that before P2PDMA starts treating clients with ATS enabled as translating everything. Keep it in the device's P2PDMA state, which already ends with the driver binding.
Signed-off-by: Leon Romanovsky leonro@nvidia.com
Reviewed-by: Thomas Hellström thomas.hellstrom@linux.intel.com
drivers/pci/p2pdma.c | 27 +++++++++++++++++++++++++++ include/linux/pci-p2pdma.h | 4 ++++ 2 files changed, 31 insertions(+)
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 1f4bf0125a5c..ae676509f9f3 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -26,6 +26,7 @@ struct pci_p2pdma { struct gen_pool *pool; bool p2pmem_published;
- bool ats_per_mapping;
struct xarray map_types; struct p2pdma_provider mem[PCI_STD_NUM_BARS]; }; @@ -1568,6 +1569,32 @@ void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) } EXPORT_SYMBOL_GPL(pci_p2pmem_publish); +/**
- pcim_p2pdma_set_ats_per_mapping - Declare per-mapping ATS for a
client
- @pdev: PCI device that initiates peer-to-peer DMA
- Declare that @pdev issues Translated Requests only for the DMA
mappings its
- driver sets up to use ATS, rather than for any address once ATS
is enabled.
- P2PDMA then takes the Address Type of this client's Requests from
the TLP
- flags its callers pass.
- */
+void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev) +{
- struct pci_p2pdma *p2p;
- p2p = rcu_dereference_protected(pdev->p2pdma, 1);
- if (!p2p)
/** ats_per_mapping is a performance optimization,* if pcim_p2pdma_init() didn't set pdev->p2pdmapointer
* for some reason, let's simply use ATS globalsettings.
*/return;- p2p->ats_per_mapping = true;
+} +EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);
/** * pci_p2pdma_map_type_tlp - Determine the mapping type for P2PDMA transfers * @provider: P2PDMA provider structure diff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h index 36045b1b730c..543a09426a11 100644 --- a/include/linux/pci-p2pdma.h +++ b/include/linux/pci-p2pdma.h @@ -109,6 +109,7 @@ struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, unsigned int *nents, u32 length); void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl); void pci_p2pmem_publish(struct pci_dev *pdev, bool publish); +void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev); int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev, bool *use_p2pdma); ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev, @@ -166,6 +167,9 @@ static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev, static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) { } +static inline void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev) +{ +} static inline int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev, bool *use_p2pdma) {