Skip to content

Commit ca2c2e4

Browse files
Christoph Hellwigmszyprow
authored andcommitted
dma-mapping: move the PCI P2PDMA mapping helpers to pci-p2pdma.h
To support the upcoming non-scatterlist mapping helpers, we need to go back to have them called outside of the DMA API. Thus move them out of dma-map-ops.h, which is only for DMA API implementations to pci-p2pdma.h, which is for driver use. Note that the core helper is still not exported as the mapping is expected to be done only by very highlevel subsystem code at least for now. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Tested-by: Jens Axboe <axboe@kernel.dk> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
1 parent a25e796 commit ca2c2e4

File tree

4 files changed

+87
-85
lines changed

4 files changed

+87
-85
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/msi.h>
2828
#include <linux/of_iommu.h>
2929
#include <linux/pci.h>
30+
#include <linux/pci-p2pdma.h>
3031
#include <linux/scatterlist.h>
3132
#include <linux/spinlock.h>
3233
#include <linux/swiotlb.h>

include/linux/dma-map-ops.h

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -434,89 +434,4 @@ static inline void debug_dma_dump_mappings(struct device *dev)
434434
#endif /* CONFIG_DMA_API_DEBUG */
435435

436436
extern const struct dma_map_ops dma_dummy_ops;
437-
438-
enum pci_p2pdma_map_type {
439-
/*
440-
* PCI_P2PDMA_MAP_UNKNOWN: Used internally for indicating the mapping
441-
* type hasn't been calculated yet. Functions that return this enum
442-
* never return this value.
443-
*/
444-
PCI_P2PDMA_MAP_UNKNOWN = 0,
445-
446-
/*
447-
* Not a PCI P2PDMA transfer.
448-
*/
449-
PCI_P2PDMA_MAP_NONE,
450-
451-
/*
452-
* PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will
453-
* traverse the host bridge and the host bridge is not in the
454-
* allowlist. DMA Mapping routines should return an error when
455-
* this is returned.
456-
*/
457-
PCI_P2PDMA_MAP_NOT_SUPPORTED,
458-
459-
/*
460-
* PCI_P2PDMA_BUS_ADDR: Indicates that two devices can talk to
461-
* each other directly through a PCI switch and the transaction will
462-
* not traverse the host bridge. Such a mapping should program
463-
* the DMA engine with PCI bus addresses.
464-
*/
465-
PCI_P2PDMA_MAP_BUS_ADDR,
466-
467-
/*
468-
* PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk
469-
* to each other, but the transaction traverses a host bridge on the
470-
* allowlist. In this case, a normal mapping either with CPU physical
471-
* addresses (in the case of dma-direct) or IOVA addresses (in the
472-
* case of IOMMUs) should be used to program the DMA engine.
473-
*/
474-
PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
475-
};
476-
477-
struct pci_p2pdma_map_state {
478-
struct dev_pagemap *pgmap;
479-
enum pci_p2pdma_map_type map;
480-
u64 bus_off;
481-
};
482-
483-
/* helper for pci_p2pdma_state(), do not use directly */
484-
void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,
485-
struct device *dev, struct page *page);
486-
487-
/**
488-
* pci_p2pdma_state - check the P2P transfer state of a page
489-
* @state: P2P state structure
490-
* @dev: device to transfer to/from
491-
* @page: page to map
492-
*
493-
* Check if @page is a PCI P2PDMA page, and if yes of what kind. Returns the
494-
* map type, and updates @state with all information needed for a P2P transfer.
495-
*/
496-
static inline enum pci_p2pdma_map_type
497-
pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev,
498-
struct page *page)
499-
{
500-
if (IS_ENABLED(CONFIG_PCI_P2PDMA) && is_pci_p2pdma_page(page)) {
501-
if (state->pgmap != page_pgmap(page))
502-
__pci_p2pdma_update_state(state, dev, page);
503-
return state->map;
504-
}
505-
return PCI_P2PDMA_MAP_NONE;
506-
}
507-
508-
/**
509-
* pci_p2pdma_bus_addr_map - map a PCI_P2PDMA_MAP_BUS_ADDR P2P transfer
510-
* @state: P2P state structure
511-
* @paddr: physical address to map
512-
*
513-
* Map a physically contiguous PCI_P2PDMA_MAP_BUS_ADDR transfer.
514-
*/
515-
static inline dma_addr_t
516-
pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t paddr)
517-
{
518-
WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR);
519-
return paddr + state->bus_off;
520-
}
521-
522437
#endif /* _LINUX_DMA_MAP_OPS_H */

include/linux/pci-p2pdma.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,89 @@ static inline struct pci_dev *pci_p2pmem_find(struct device *client)
104104
return pci_p2pmem_find_many(&client, 1);
105105
}
106106

107+
enum pci_p2pdma_map_type {
108+
/*
109+
* PCI_P2PDMA_MAP_UNKNOWN: Used internally as an initial state before
110+
* the mapping type has been calculated. Exported routines for the API
111+
* will never return this value.
112+
*/
113+
PCI_P2PDMA_MAP_UNKNOWN = 0,
114+
115+
/*
116+
* Not a PCI P2PDMA transfer.
117+
*/
118+
PCI_P2PDMA_MAP_NONE,
119+
120+
/*
121+
* PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will
122+
* traverse the host bridge and the host bridge is not in the
123+
* allowlist. DMA Mapping routines should return an error when
124+
* this is returned.
125+
*/
126+
PCI_P2PDMA_MAP_NOT_SUPPORTED,
127+
128+
/*
129+
* PCI_P2PDMA_MAP_BUS_ADDR: Indicates that two devices can talk to
130+
* each other directly through a PCI switch and the transaction will
131+
* not traverse the host bridge. Such a mapping should program
132+
* the DMA engine with PCI bus addresses.
133+
*/
134+
PCI_P2PDMA_MAP_BUS_ADDR,
135+
136+
/*
137+
* PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk
138+
* to each other, but the transaction traverses a host bridge on the
139+
* allowlist. In this case, a normal mapping either with CPU physical
140+
* addresses (in the case of dma-direct) or IOVA addresses (in the
141+
* case of IOMMUs) should be used to program the DMA engine.
142+
*/
143+
PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
144+
};
145+
146+
struct pci_p2pdma_map_state {
147+
struct dev_pagemap *pgmap;
148+
enum pci_p2pdma_map_type map;
149+
u64 bus_off;
150+
};
151+
152+
/* helper for pci_p2pdma_state(), do not use directly */
153+
void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,
154+
struct device *dev, struct page *page);
155+
156+
/**
157+
* pci_p2pdma_state - check the P2P transfer state of a page
158+
* @state: P2P state structure
159+
* @dev: device to transfer to/from
160+
* @page: page to map
161+
*
162+
* Check if @page is a PCI P2PDMA page, and if yes of what kind. Returns the
163+
* map type, and updates @state with all information needed for a P2P transfer.
164+
*/
165+
static inline enum pci_p2pdma_map_type
166+
pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev,
167+
struct page *page)
168+
{
169+
if (IS_ENABLED(CONFIG_PCI_P2PDMA) && is_pci_p2pdma_page(page)) {
170+
if (state->pgmap != page_pgmap(page))
171+
__pci_p2pdma_update_state(state, dev, page);
172+
return state->map;
173+
}
174+
return PCI_P2PDMA_MAP_NONE;
175+
}
176+
177+
/**
178+
* pci_p2pdma_bus_addr_map - Translate a physical address to a bus address
179+
* for a PCI_P2PDMA_MAP_BUS_ADDR transfer.
180+
* @state: P2P state structure
181+
* @paddr: physical address to map
182+
*
183+
* Map a physically contiguous PCI_P2PDMA_MAP_BUS_ADDR transfer.
184+
*/
185+
static inline dma_addr_t
186+
pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t paddr)
187+
{
188+
WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR);
189+
return paddr + state->bus_off;
190+
}
191+
107192
#endif /* _LINUX_PCI_P2P_H */

kernel/dma/direct.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/vmalloc.h>
1414
#include <linux/set_memory.h>
1515
#include <linux/slab.h>
16+
#include <linux/pci-p2pdma.h>
1617
#include "direct.h"
1718

1819
/*

0 commit comments

Comments
 (0)