xref: /openbmc/linux/include/linux/pci-p2pdma.h (revision 0d06132f)
152916982SLogan Gunthorpe /* SPDX-License-Identifier: GPL-2.0 */
252916982SLogan Gunthorpe /*
352916982SLogan Gunthorpe  * PCI Peer 2 Peer DMA support.
452916982SLogan Gunthorpe  *
552916982SLogan Gunthorpe  * Copyright (c) 2016-2018, Logan Gunthorpe
652916982SLogan Gunthorpe  * Copyright (c) 2016-2017, Microsemi Corporation
752916982SLogan Gunthorpe  * Copyright (c) 2017, Christoph Hellwig
852916982SLogan Gunthorpe  * Copyright (c) 2018, Eideticom Inc.
952916982SLogan Gunthorpe  */
1052916982SLogan Gunthorpe 
1152916982SLogan Gunthorpe #ifndef _LINUX_PCI_P2PDMA_H
1252916982SLogan Gunthorpe #define _LINUX_PCI_P2PDMA_H
1352916982SLogan Gunthorpe 
1452916982SLogan Gunthorpe #include <linux/pci.h>
1552916982SLogan Gunthorpe 
1652916982SLogan Gunthorpe struct block_device;
1752916982SLogan Gunthorpe struct scatterlist;
1852916982SLogan Gunthorpe 
1952916982SLogan Gunthorpe #ifdef CONFIG_PCI_P2PDMA
2052916982SLogan Gunthorpe int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
2152916982SLogan Gunthorpe 		u64 offset);
2252916982SLogan Gunthorpe int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
2352916982SLogan Gunthorpe 			     int num_clients, bool verbose);
2452916982SLogan Gunthorpe bool pci_has_p2pmem(struct pci_dev *pdev);
2552916982SLogan Gunthorpe struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients);
2652916982SLogan Gunthorpe void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size);
2752916982SLogan Gunthorpe void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size);
2852916982SLogan Gunthorpe pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, void *addr);
2952916982SLogan Gunthorpe struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
3052916982SLogan Gunthorpe 					 unsigned int *nents, u32 length);
3152916982SLogan Gunthorpe void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);
3252916982SLogan Gunthorpe void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);
332d7bc010SLogan Gunthorpe int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
342d7bc010SLogan Gunthorpe 			    bool *use_p2pdma);
352d7bc010SLogan Gunthorpe ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
362d7bc010SLogan Gunthorpe 			       bool use_p2pdma);
3752916982SLogan Gunthorpe #else /* CONFIG_PCI_P2PDMA */
pci_p2pdma_add_resource(struct pci_dev * pdev,int bar,size_t size,u64 offset)3852916982SLogan Gunthorpe static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar,
3952916982SLogan Gunthorpe 		size_t size, u64 offset)
4052916982SLogan Gunthorpe {
4152916982SLogan Gunthorpe 	return -EOPNOTSUPP;
4252916982SLogan Gunthorpe }
pci_p2pdma_distance_many(struct pci_dev * provider,struct device ** clients,int num_clients,bool verbose)4352916982SLogan Gunthorpe static inline int pci_p2pdma_distance_many(struct pci_dev *provider,
4452916982SLogan Gunthorpe 	struct device **clients, int num_clients, bool verbose)
4552916982SLogan Gunthorpe {
4652916982SLogan Gunthorpe 	return -1;
4752916982SLogan Gunthorpe }
pci_has_p2pmem(struct pci_dev * pdev)4852916982SLogan Gunthorpe static inline bool pci_has_p2pmem(struct pci_dev *pdev)
4952916982SLogan Gunthorpe {
5052916982SLogan Gunthorpe 	return false;
5152916982SLogan Gunthorpe }
pci_p2pmem_find_many(struct device ** clients,int num_clients)5252916982SLogan Gunthorpe static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients,
5352916982SLogan Gunthorpe 						   int num_clients)
5452916982SLogan Gunthorpe {
5552916982SLogan Gunthorpe 	return NULL;
5652916982SLogan Gunthorpe }
pci_alloc_p2pmem(struct pci_dev * pdev,size_t size)5752916982SLogan Gunthorpe static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size)
5852916982SLogan Gunthorpe {
5952916982SLogan Gunthorpe 	return NULL;
6052916982SLogan Gunthorpe }
pci_free_p2pmem(struct pci_dev * pdev,void * addr,size_t size)6152916982SLogan Gunthorpe static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr,
6252916982SLogan Gunthorpe 		size_t size)
6352916982SLogan Gunthorpe {
6452916982SLogan Gunthorpe }
pci_p2pmem_virt_to_bus(struct pci_dev * pdev,void * addr)6552916982SLogan Gunthorpe static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev,
6652916982SLogan Gunthorpe 						    void *addr)
6752916982SLogan Gunthorpe {
6852916982SLogan Gunthorpe 	return 0;
6952916982SLogan Gunthorpe }
pci_p2pmem_alloc_sgl(struct pci_dev * pdev,unsigned int * nents,u32 length)7052916982SLogan Gunthorpe static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
7152916982SLogan Gunthorpe 		unsigned int *nents, u32 length)
7252916982SLogan Gunthorpe {
7352916982SLogan Gunthorpe 	return NULL;
7452916982SLogan Gunthorpe }
pci_p2pmem_free_sgl(struct pci_dev * pdev,struct scatterlist * sgl)7552916982SLogan Gunthorpe static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,
7652916982SLogan Gunthorpe 		struct scatterlist *sgl)
7752916982SLogan Gunthorpe {
7852916982SLogan Gunthorpe }
pci_p2pmem_publish(struct pci_dev * pdev,bool publish)7952916982SLogan Gunthorpe static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
8052916982SLogan Gunthorpe {
8152916982SLogan Gunthorpe }
pci_p2pdma_enable_store(const char * page,struct pci_dev ** p2p_dev,bool * use_p2pdma)822d7bc010SLogan Gunthorpe static inline int pci_p2pdma_enable_store(const char *page,
832d7bc010SLogan Gunthorpe 		struct pci_dev **p2p_dev, bool *use_p2pdma)
842d7bc010SLogan Gunthorpe {
852d7bc010SLogan Gunthorpe 	*use_p2pdma = false;
862d7bc010SLogan Gunthorpe 	return 0;
872d7bc010SLogan Gunthorpe }
pci_p2pdma_enable_show(char * page,struct pci_dev * p2p_dev,bool use_p2pdma)882d7bc010SLogan Gunthorpe static inline ssize_t pci_p2pdma_enable_show(char *page,
892d7bc010SLogan Gunthorpe 		struct pci_dev *p2p_dev, bool use_p2pdma)
902d7bc010SLogan Gunthorpe {
912d7bc010SLogan Gunthorpe 	return sprintf(page, "none\n");
922d7bc010SLogan Gunthorpe }
9352916982SLogan Gunthorpe #endif /* CONFIG_PCI_P2PDMA */
9452916982SLogan Gunthorpe 
9552916982SLogan Gunthorpe 
pci_p2pdma_distance(struct pci_dev * provider,struct device * client,bool verbose)9652916982SLogan Gunthorpe static inline int pci_p2pdma_distance(struct pci_dev *provider,
9752916982SLogan Gunthorpe 	struct device *client, bool verbose)
9852916982SLogan Gunthorpe {
9952916982SLogan Gunthorpe 	return pci_p2pdma_distance_many(provider, &client, 1, verbose);
10052916982SLogan Gunthorpe }
10152916982SLogan Gunthorpe 
pci_p2pmem_find(struct device * client)10252916982SLogan Gunthorpe static inline struct pci_dev *pci_p2pmem_find(struct device *client)
10352916982SLogan Gunthorpe {
10452916982SLogan Gunthorpe 	return pci_p2pmem_find_many(&client, 1);
10552916982SLogan Gunthorpe }
10652916982SLogan Gunthorpe 
10752916982SLogan Gunthorpe #endif /* _LINUX_PCI_P2P_H */
108