Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux-block.git] / include / linux / pci-p2pdma.h
CommitLineData
52916982
LG
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
16struct block_device;
17struct scatterlist;
18
19#ifdef CONFIG_PCI_P2PDMA
20int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
21 u64 offset);
22int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
23 int num_clients, bool verbose);
24bool pci_has_p2pmem(struct pci_dev *pdev);
25struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients);
26void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size);
27void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size);
28pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, void *addr);
29struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
30 unsigned int *nents, u32 length);
31void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);
32void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);
977196b8
LG
33int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
34 enum dma_data_direction dir);
2d7bc010
LG
35int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
36 bool *use_p2pdma);
37ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
38 bool use_p2pdma);
52916982
LG
39#else /* CONFIG_PCI_P2PDMA */
40static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar,
41 size_t size, u64 offset)
42{
43 return -EOPNOTSUPP;
44}
45static inline int pci_p2pdma_distance_many(struct pci_dev *provider,
46 struct device **clients, int num_clients, bool verbose)
47{
48 return -1;
49}
50static inline bool pci_has_p2pmem(struct pci_dev *pdev)
51{
52 return false;
53}
54static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients,
55 int num_clients)
56{
57 return NULL;
58}
59static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size)
60{
61 return NULL;
62}
63static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr,
64 size_t size)
65{
66}
67static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev,
68 void *addr)
69{
70 return 0;
71}
72static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
73 unsigned int *nents, u32 length)
74{
75 return NULL;
76}
77static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,
78 struct scatterlist *sgl)
79{
80}
81static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
82{
83}
977196b8
LG
84static inline int pci_p2pdma_map_sg(struct device *dev,
85 struct scatterlist *sg, int nents, enum dma_data_direction dir)
86{
87 return 0;
88}
2d7bc010
LG
89static inline int pci_p2pdma_enable_store(const char *page,
90 struct pci_dev **p2p_dev, bool *use_p2pdma)
91{
92 *use_p2pdma = false;
93 return 0;
94}
95static inline ssize_t pci_p2pdma_enable_show(char *page,
96 struct pci_dev *p2p_dev, bool use_p2pdma)
97{
98 return sprintf(page, "none\n");
99}
52916982
LG
100#endif /* CONFIG_PCI_P2PDMA */
101
102
103static inline int pci_p2pdma_distance(struct pci_dev *provider,
104 struct device *client, bool verbose)
105{
106 return pci_p2pdma_distance_many(provider, &client, 1, verbose);
107}
108
109static inline struct pci_dev *pci_p2pmem_find(struct device *client)
110{
111 return pci_p2pmem_find_many(&client, 1);
112}
113
114#endif /* _LINUX_PCI_P2P_H */