Logan Gunthorpe | 5291698 | 2018-10-04 15:27:35 -0600 | [diff] [blame^] | 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 | #else /* CONFIG_PCI_P2PDMA */ |
| 34 | static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, |
| 35 | size_t size, u64 offset) |
| 36 | { |
| 37 | return -EOPNOTSUPP; |
| 38 | } |
| 39 | static inline int pci_p2pdma_distance_many(struct pci_dev *provider, |
| 40 | struct device **clients, int num_clients, bool verbose) |
| 41 | { |
| 42 | return -1; |
| 43 | } |
| 44 | static inline bool pci_has_p2pmem(struct pci_dev *pdev) |
| 45 | { |
| 46 | return false; |
| 47 | } |
| 48 | static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients, |
| 49 | int num_clients) |
| 50 | { |
| 51 | return NULL; |
| 52 | } |
| 53 | static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size) |
| 54 | { |
| 55 | return NULL; |
| 56 | } |
| 57 | static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr, |
| 58 | size_t size) |
| 59 | { |
| 60 | } |
| 61 | static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, |
| 62 | void *addr) |
| 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, |
| 67 | unsigned int *nents, u32 length) |
| 68 | { |
| 69 | return NULL; |
| 70 | } |
| 71 | static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev, |
| 72 | struct scatterlist *sgl) |
| 73 | { |
| 74 | } |
| 75 | static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) |
| 76 | { |
| 77 | } |
| 78 | #endif /* CONFIG_PCI_P2PDMA */ |
| 79 | |
| 80 | |
| 81 | static inline int pci_p2pdma_distance(struct pci_dev *provider, |
| 82 | struct device *client, bool verbose) |
| 83 | { |
| 84 | return pci_p2pdma_distance_many(provider, &client, 1, verbose); |
| 85 | } |
| 86 | |
| 87 | static inline struct pci_dev *pci_p2pmem_find(struct device *client) |
| 88 | { |
| 89 | return pci_p2pmem_find_many(&client, 1); |
| 90 | } |
| 91 | |
| 92 | #endif /* _LINUX_PCI_P2P_H */ |