Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * PCI Peer 2 Peer DMA support.
0004  *
0005  * Copyright (c) 2016-2018, Logan Gunthorpe
0006  * Copyright (c) 2016-2017, Microsemi Corporation
0007  * Copyright (c) 2017, Christoph Hellwig
0008  * Copyright (c) 2018, Eideticom Inc.
0009  */
0010 
0011 #ifndef _LINUX_PCI_P2PDMA_H
0012 #define _LINUX_PCI_P2PDMA_H
0013 
0014 #include <linux/pci.h>
0015 
0016 struct block_device;
0017 struct scatterlist;
0018 
0019 #ifdef CONFIG_PCI_P2PDMA
0020 int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
0021         u64 offset);
0022 int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
0023                  int num_clients, bool verbose);
0024 bool pci_has_p2pmem(struct pci_dev *pdev);
0025 struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients);
0026 void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size);
0027 void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size);
0028 pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, void *addr);
0029 struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
0030                      unsigned int *nents, u32 length);
0031 void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);
0032 void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);
0033 int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
0034                 bool *use_p2pdma);
0035 ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
0036                    bool use_p2pdma);
0037 #else /* CONFIG_PCI_P2PDMA */
0038 static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar,
0039         size_t size, u64 offset)
0040 {
0041     return -EOPNOTSUPP;
0042 }
0043 static inline int pci_p2pdma_distance_many(struct pci_dev *provider,
0044     struct device **clients, int num_clients, bool verbose)
0045 {
0046     return -1;
0047 }
0048 static inline bool pci_has_p2pmem(struct pci_dev *pdev)
0049 {
0050     return false;
0051 }
0052 static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients,
0053                            int num_clients)
0054 {
0055     return NULL;
0056 }
0057 static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size)
0058 {
0059     return NULL;
0060 }
0061 static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr,
0062         size_t size)
0063 {
0064 }
0065 static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev,
0066                             void *addr)
0067 {
0068     return 0;
0069 }
0070 static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
0071         unsigned int *nents, u32 length)
0072 {
0073     return NULL;
0074 }
0075 static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,
0076         struct scatterlist *sgl)
0077 {
0078 }
0079 static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
0080 {
0081 }
0082 static inline int pci_p2pdma_enable_store(const char *page,
0083         struct pci_dev **p2p_dev, bool *use_p2pdma)
0084 {
0085     *use_p2pdma = false;
0086     return 0;
0087 }
0088 static inline ssize_t pci_p2pdma_enable_show(char *page,
0089         struct pci_dev *p2p_dev, bool use_p2pdma)
0090 {
0091     return sprintf(page, "none\n");
0092 }
0093 #endif /* CONFIG_PCI_P2PDMA */
0094 
0095 
0096 static inline int pci_p2pdma_distance(struct pci_dev *provider,
0097     struct device *client, bool verbose)
0098 {
0099     return pci_p2pdma_distance_many(provider, &client, 1, verbose);
0100 }
0101 
0102 static inline struct pci_dev *pci_p2pmem_find(struct device *client)
0103 {
0104     return pci_p2pmem_find_many(&client, 1);
0105 }
0106 
0107 #endif /* _LINUX_PCI_P2P_H */