1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * PCI Peer 2 Peer DMA support.
4 *
5 * Copyright (c) 2016-2018, Logan Gunthorpe
6 * Copyright (c) 2016-2017, Microsemi Corporation
7 * Copyright (c) 2017, Christoph Hellwig
8 * Copyright (c) 2018, Eideticom Inc.
9 */
10
11 #ifndef _LINUX_PCI_P2PDMA_H
12 #define _LINUX_PCI_P2PDMA_H
13
14 #include <linux/pci.h>
15
16 struct block_device;
17 struct scatterlist;
18
19 #ifdef CONFIG_PCI_P2PDMA
20 int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
21 u64 offset);
22 int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
23 int num_clients, bool verbose);
24 bool pci_has_p2pmem(struct pci_dev *pdev);
25 struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients);
26 void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size);
27 void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size);
28 pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, void *addr);
29 struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
30 unsigned int *nents, u32 length);
31 void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);
32 void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);
33 int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
34 int nents, enum dma_data_direction dir, unsigned long attrs);
35 void pci_p2pdma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
36 int nents, enum dma_data_direction dir, unsigned long attrs);
37 int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
38 bool *use_p2pdma);
39 ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
40 bool use_p2pdma);
41 #else /* CONFIG_PCI_P2PDMA */
pci_p2pdma_add_resource(struct pci_dev * pdev,int bar,size_t size,u64 offset)42 static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar,
43 size_t size, u64 offset)
44 {
45 return -EOPNOTSUPP;
46 }
pci_p2pdma_distance_many(struct pci_dev * provider,struct device ** clients,int num_clients,bool verbose)47 static inline int pci_p2pdma_distance_many(struct pci_dev *provider,
48 struct device **clients, int num_clients, bool verbose)
49 {
50 return -1;
51 }
pci_has_p2pmem(struct pci_dev * pdev)52 static inline bool pci_has_p2pmem(struct pci_dev *pdev)
53 {
54 return false;
55 }
pci_p2pmem_find_many(struct device ** clients,int num_clients)56 static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients,
57 int num_clients)
58 {
59 return NULL;
60 }
pci_alloc_p2pmem(struct pci_dev * pdev,size_t size)61 static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size)
62 {
63 return NULL;
64 }
pci_free_p2pmem(struct pci_dev * pdev,void * addr,size_t size)65 static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr,
66 size_t size)
67 {
68 }
pci_p2pmem_virt_to_bus(struct pci_dev * pdev,void * addr)69 static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev,
70 void *addr)
71 {
72 return 0;
73 }
pci_p2pmem_alloc_sgl(struct pci_dev * pdev,unsigned int * nents,u32 length)74 static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
75 unsigned int *nents, u32 length)
76 {
77 return NULL;
78 }
pci_p2pmem_free_sgl(struct pci_dev * pdev,struct scatterlist * sgl)79 static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,
80 struct scatterlist *sgl)
81 {
82 }
pci_p2pmem_publish(struct pci_dev * pdev,bool publish)83 static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
84 {
85 }
pci_p2pdma_map_sg_attrs(struct device * dev,struct scatterlist * sg,int nents,enum dma_data_direction dir,unsigned long attrs)86 static inline int pci_p2pdma_map_sg_attrs(struct device *dev,
87 struct scatterlist *sg, int nents, enum dma_data_direction dir,
88 unsigned long attrs)
89 {
90 return 0;
91 }
pci_p2pdma_unmap_sg_attrs(struct device * dev,struct scatterlist * sg,int nents,enum dma_data_direction dir,unsigned long attrs)92 static inline void pci_p2pdma_unmap_sg_attrs(struct device *dev,
93 struct scatterlist *sg, int nents, enum dma_data_direction dir,
94 unsigned long attrs)
95 {
96 }
pci_p2pdma_enable_store(const char * page,struct pci_dev ** p2p_dev,bool * use_p2pdma)97 static inline int pci_p2pdma_enable_store(const char *page,
98 struct pci_dev **p2p_dev, bool *use_p2pdma)
99 {
100 *use_p2pdma = false;
101 return 0;
102 }
pci_p2pdma_enable_show(char * page,struct pci_dev * p2p_dev,bool use_p2pdma)103 static inline ssize_t pci_p2pdma_enable_show(char *page,
104 struct pci_dev *p2p_dev, bool use_p2pdma)
105 {
106 return sprintf(page, "none\n");
107 }
108 #endif /* CONFIG_PCI_P2PDMA */
109
110
pci_p2pdma_distance(struct pci_dev * provider,struct device * client,bool verbose)111 static inline int pci_p2pdma_distance(struct pci_dev *provider,
112 struct device *client, bool verbose)
113 {
114 return pci_p2pdma_distance_many(provider, &client, 1, verbose);
115 }
116
pci_p2pmem_find(struct device * client)117 static inline struct pci_dev *pci_p2pmem_find(struct device *client)
118 {
119 return pci_p2pmem_find_many(&client, 1);
120 }
121
pci_p2pdma_map_sg(struct device * dev,struct scatterlist * sg,int nents,enum dma_data_direction dir)122 static inline int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg,
123 int nents, enum dma_data_direction dir)
124 {
125 return pci_p2pdma_map_sg_attrs(dev, sg, nents, dir, 0);
126 }
127
pci_p2pdma_unmap_sg(struct device * dev,struct scatterlist * sg,int nents,enum dma_data_direction dir)128 static inline void pci_p2pdma_unmap_sg(struct device *dev,
129 struct scatterlist *sg, int nents, enum dma_data_direction dir)
130 {
131 pci_p2pdma_unmap_sg_attrs(dev, sg, nents, dir, 0);
132 }
133
134 #endif /* _LINUX_PCI_P2P_H */
135