1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * PCI Peer 2 Peer DMA support. 3 * PCI Peer 2 Peer DMA support. 4 * 4 * 5 * Copyright (c) 2016-2018, Logan Gunthorpe 5 * Copyright (c) 2016-2018, Logan Gunthorpe 6 * Copyright (c) 2016-2017, Microsemi Corporat 6 * Copyright (c) 2016-2017, Microsemi Corporation 7 * Copyright (c) 2017, Christoph Hellwig 7 * Copyright (c) 2017, Christoph Hellwig 8 * Copyright (c) 2018, Eideticom Inc. 8 * Copyright (c) 2018, Eideticom Inc. 9 */ 9 */ 10 10 11 #ifndef _LINUX_PCI_P2PDMA_H 11 #ifndef _LINUX_PCI_P2PDMA_H 12 #define _LINUX_PCI_P2PDMA_H 12 #define _LINUX_PCI_P2PDMA_H 13 13 14 #include <linux/pci.h> 14 #include <linux/pci.h> 15 15 16 struct block_device; 16 struct block_device; 17 struct scatterlist; 17 struct scatterlist; 18 18 19 #ifdef CONFIG_PCI_P2PDMA 19 #ifdef CONFIG_PCI_P2PDMA 20 int pci_p2pdma_add_resource(struct pci_dev *pd 20 int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size, 21 u64 offset); 21 u64 offset); 22 int pci_p2pdma_distance_many(struct pci_dev *p 22 int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients, 23 int num_clients, 23 int num_clients, bool verbose); 24 bool pci_has_p2pmem(struct pci_dev *pdev); 24 bool pci_has_p2pmem(struct pci_dev *pdev); 25 struct pci_dev *pci_p2pmem_find_many(struct de 25 struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients); 26 void *pci_alloc_p2pmem(struct pci_dev *pdev, s 26 void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size); 27 void pci_free_p2pmem(struct pci_dev *pdev, voi 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 p 28 pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, void *addr); 29 struct scatterlist *pci_p2pmem_alloc_sgl(struc 29 struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, 30 unsig 30 unsigned int *nents, u32 length); 31 void pci_p2pmem_free_sgl(struct pci_dev *pdev, 31 void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl); 32 void pci_p2pmem_publish(struct pci_dev *pdev, 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); 33 int pci_p2pdma_enable_store(const char *page, 37 int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev, 34 bool *use_p2pdma); 38 bool *use_p2pdma); 35 ssize_t pci_p2pdma_enable_show(char *page, str 39 ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev, 36 bool use_p2pdma 40 bool use_p2pdma); 37 #else /* CONFIG_PCI_P2PDMA */ 41 #else /* CONFIG_PCI_P2PDMA */ 38 static inline int pci_p2pdma_add_resource(stru 42 static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, 39 size_t size, u64 offset) 43 size_t size, u64 offset) 40 { 44 { 41 return -EOPNOTSUPP; 45 return -EOPNOTSUPP; 42 } 46 } 43 static inline int pci_p2pdma_distance_many(str 47 static inline int pci_p2pdma_distance_many(struct pci_dev *provider, 44 struct device **clients, int num_clien 48 struct device **clients, int num_clients, bool verbose) 45 { 49 { 46 return -1; 50 return -1; 47 } 51 } 48 static inline bool pci_has_p2pmem(struct pci_d 52 static inline bool pci_has_p2pmem(struct pci_dev *pdev) 49 { 53 { 50 return false; 54 return false; 51 } 55 } 52 static inline struct pci_dev *pci_p2pmem_find_ 56 static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients, 53 57 int num_clients) 54 { 58 { 55 return NULL; 59 return NULL; 56 } 60 } 57 static inline void *pci_alloc_p2pmem(struct pc 61 static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size) 58 { 62 { 59 return NULL; 63 return NULL; 60 } 64 } 61 static inline void pci_free_p2pmem(struct pci_ 65 static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr, 62 size_t size) 66 size_t size) 63 { 67 { 64 } 68 } 65 static inline pci_bus_addr_t pci_p2pmem_virt_t 69 static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, 66 70 void *addr) 67 { 71 { 68 return 0; 72 return 0; 69 } 73 } 70 static inline struct scatterlist *pci_p2pmem_a 74 static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, 71 unsigned int *nents, u32 lengt 75 unsigned int *nents, u32 length) 72 { 76 { 73 return NULL; 77 return NULL; 74 } 78 } 75 static inline void pci_p2pmem_free_sgl(struct 79 static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev, 76 struct scatterlist *sgl) 80 struct scatterlist *sgl) 77 { 81 { 78 } 82 } 79 static inline void pci_p2pmem_publish(struct p 83 static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) 80 { 84 { 81 } 85 } >> 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 } >> 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 } 82 static inline int pci_p2pdma_enable_store(cons 97 static inline int pci_p2pdma_enable_store(const char *page, 83 struct pci_dev **p2p_dev, bool 98 struct pci_dev **p2p_dev, bool *use_p2pdma) 84 { 99 { 85 *use_p2pdma = false; 100 *use_p2pdma = false; 86 return 0; 101 return 0; 87 } 102 } 88 static inline ssize_t pci_p2pdma_enable_show(c 103 static inline ssize_t pci_p2pdma_enable_show(char *page, 89 struct pci_dev *p2p_dev, bool 104 struct pci_dev *p2p_dev, bool use_p2pdma) 90 { 105 { 91 return sprintf(page, "none\n"); 106 return sprintf(page, "none\n"); 92 } 107 } 93 #endif /* CONFIG_PCI_P2PDMA */ 108 #endif /* CONFIG_PCI_P2PDMA */ 94 109 95 110 96 static inline int pci_p2pdma_distance(struct p 111 static inline int pci_p2pdma_distance(struct pci_dev *provider, 97 struct device *client, bool verbose) 112 struct device *client, bool verbose) 98 { 113 { 99 return pci_p2pdma_distance_many(provid 114 return pci_p2pdma_distance_many(provider, &client, 1, verbose); 100 } 115 } 101 116 102 static inline struct pci_dev *pci_p2pmem_find( 117 static inline struct pci_dev *pci_p2pmem_find(struct device *client) 103 { 118 { 104 return pci_p2pmem_find_many(&client, 1 119 return pci_p2pmem_find_many(&client, 1); >> 120 } >> 121 >> 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 >> 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); 105 } 132 } 106 133 107 #endif /* _LINUX_PCI_P2P_H */ 134 #endif /* _LINUX_PCI_P2P_H */ 108 135
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.