Skip to content

Commit d9dcbd1

Browse files
rleonkawasaki
authored andcommitted
PCI/P2PDMA: Export pci_p2pdma_map_type() function
Export the pci_p2pdma_map_type() function to allow external modules and subsystems to determine the appropriate mapping type for P2PDMA transfers between a provider and target device. The function determines whether peer-to-peer DMA transfers can be done directly through PCI switches (PCI_P2PDMA_MAP_BUS_ADDR) or must go through the host bridge (PCI_P2PDMA_MAP_THRU_HOST_BRIDGE), or if the transfer is not supported at all. This export enables subsystems like VFIO to properly handle P2PDMA operations by querying the mapping type before attempting transfers, ensuring correct DMA address programming and error handling. Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 2580da3 commit d9dcbd1

2 files changed

Lines changed: 59 additions & 41 deletions

File tree

drivers/pci/p2pdma.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,18 @@ void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
10221022
}
10231023
EXPORT_SYMBOL_GPL(pci_p2pmem_publish);
10241024

1025-
static enum pci_p2pdma_map_type
1026-
pci_p2pdma_map_type(struct p2pdma_provider *provider, struct device *dev)
1025+
/**
1026+
* pci_p2pdma_map_type - Determine the mapping type for P2PDMA transfers
1027+
* @provider: P2PDMA provider structure
1028+
* @dev: Target device for the transfer
1029+
*
1030+
* Determines how peer-to-peer DMA transfers should be mapped between
1031+
* the provider and the target device. The mapping type indicates whether
1032+
* the transfer can be done directly through PCI switches or must go
1033+
* through the host bridge.
1034+
*/
1035+
enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,
1036+
struct device *dev)
10271037
{
10281038
enum pci_p2pdma_map_type type = PCI_P2PDMA_MAP_NOT_SUPPORTED;
10291039
struct pci_dev *pdev = to_pci_dev(provider->owner);
@@ -1052,6 +1062,7 @@ pci_p2pdma_map_type(struct p2pdma_provider *provider, struct device *dev)
10521062

10531063
return type;
10541064
}
1065+
EXPORT_SYMBOL_GPL(pci_p2pdma_map_type);
10551066

10561067
void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,
10571068
struct device *dev, struct page *page)

include/linux/pci-p2pdma.h

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,45 @@ struct p2pdma_provider {
2626
u64 bus_offset;
2727
};
2828

29+
enum pci_p2pdma_map_type {
30+
/*
31+
* PCI_P2PDMA_MAP_UNKNOWN: Used internally as an initial state before
32+
* the mapping type has been calculated. Exported routines for the API
33+
* will never return this value.
34+
*/
35+
PCI_P2PDMA_MAP_UNKNOWN = 0,
36+
37+
/*
38+
* Not a PCI P2PDMA transfer.
39+
*/
40+
PCI_P2PDMA_MAP_NONE,
41+
42+
/*
43+
* PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will
44+
* traverse the host bridge and the host bridge is not in the
45+
* allowlist. DMA Mapping routines should return an error when
46+
* this is returned.
47+
*/
48+
PCI_P2PDMA_MAP_NOT_SUPPORTED,
49+
50+
/*
51+
* PCI_P2PDMA_MAP_BUS_ADDR: Indicates that two devices can talk to
52+
* each other directly through a PCI switch and the transaction will
53+
* not traverse the host bridge. Such a mapping should program
54+
* the DMA engine with PCI bus addresses.
55+
*/
56+
PCI_P2PDMA_MAP_BUS_ADDR,
57+
58+
/*
59+
* PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk
60+
* to each other, but the transaction traverses a host bridge on the
61+
* allowlist. In this case, a normal mapping either with CPU physical
62+
* addresses (in the case of dma-direct) or IOVA addresses (in the
63+
* case of IOMMUs) should be used to program the DMA engine.
64+
*/
65+
PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
66+
};
67+
2968
#ifdef CONFIG_PCI_P2PDMA
3069
struct p2pdma_provider *pci_p2pdma_enable(struct pci_dev *pdev);
3170
int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
@@ -45,6 +84,8 @@ int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
4584
bool *use_p2pdma);
4685
ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
4786
bool use_p2pdma);
87+
enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,
88+
struct device *dev);
4889
#else /* CONFIG_PCI_P2PDMA */
4990
static inline struct p2pdma_provider *pci_p2pdma_enable(struct pci_dev *pdev)
5091
{
@@ -105,6 +146,11 @@ static inline ssize_t pci_p2pdma_enable_show(char *page,
105146
{
106147
return sprintf(page, "none\n");
107148
}
149+
static inline enum pci_p2pdma_map_type
150+
pci_p2pdma_map_type(struct p2pdma_provider *provider, struct device *dev)
151+
{
152+
return PCI_P2PDMA_MAP_NOT_SUPPORTED;
153+
}
108154
#endif /* CONFIG_PCI_P2PDMA */
109155

110156

@@ -119,45 +165,6 @@ static inline struct pci_dev *pci_p2pmem_find(struct device *client)
119165
return pci_p2pmem_find_many(&client, 1);
120166
}
121167

122-
enum pci_p2pdma_map_type {
123-
/*
124-
* PCI_P2PDMA_MAP_UNKNOWN: Used internally as an initial state before
125-
* the mapping type has been calculated. Exported routines for the API
126-
* will never return this value.
127-
*/
128-
PCI_P2PDMA_MAP_UNKNOWN = 0,
129-
130-
/*
131-
* Not a PCI P2PDMA transfer.
132-
*/
133-
PCI_P2PDMA_MAP_NONE,
134-
135-
/*
136-
* PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will
137-
* traverse the host bridge and the host bridge is not in the
138-
* allowlist. DMA Mapping routines should return an error when
139-
* this is returned.
140-
*/
141-
PCI_P2PDMA_MAP_NOT_SUPPORTED,
142-
143-
/*
144-
* PCI_P2PDMA_MAP_BUS_ADDR: Indicates that two devices can talk to
145-
* each other directly through a PCI switch and the transaction will
146-
* not traverse the host bridge. Such a mapping should program
147-
* the DMA engine with PCI bus addresses.
148-
*/
149-
PCI_P2PDMA_MAP_BUS_ADDR,
150-
151-
/*
152-
* PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk
153-
* to each other, but the transaction traverses a host bridge on the
154-
* allowlist. In this case, a normal mapping either with CPU physical
155-
* addresses (in the case of dma-direct) or IOVA addresses (in the
156-
* case of IOMMUs) should be used to program the DMA engine.
157-
*/
158-
PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
159-
};
160-
161168
struct pci_p2pdma_map_state {
162169
struct p2pdma_provider *mem;
163170
enum pci_p2pdma_map_type map;

0 commit comments

Comments
 (0)