04bffa6e7785cc6969ea934d68a488220f3df4dd
[dpdk.git] / drivers / bus / pci / private.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 6WIND S.A.
3  */
4
5 #ifndef _PCI_PRIVATE_H_
6 #define _PCI_PRIVATE_H_
7
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <rte_pci.h>
11 #include <rte_bus_pci.h>
12
13 extern struct rte_pci_bus rte_pci_bus;
14
15 struct rte_pci_driver;
16 struct rte_pci_device;
17
18 extern struct rte_pci_bus rte_pci_bus;
19
20 /**
21  * Probe the PCI bus
22  *
23  * @return
24  *   - 0 on success.
25  *   - !0 on error.
26  */
27 int
28 rte_pci_probe(void);
29
30 /**
31  * Scan the content of the PCI bus, and the devices in the devices
32  * list
33  *
34  * @return
35  *  0 on success, negative on error
36  */
37 int rte_pci_scan(void);
38
39 /**
40  * Find the name of a PCI device.
41  */
42 void
43 pci_name_set(struct rte_pci_device *dev);
44
45 /**
46  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
47  * also updates the bus references of the PCI Device (and the generic device
48  * object embedded within.
49  *
50  * @param pci_dev
51  *      PCI device to add
52  * @return void
53  */
54 void rte_pci_add_device(struct rte_pci_device *pci_dev);
55
56 /**
57  * Insert a PCI device in the PCI Bus at a particular location in the device
58  * list. It also updates the PCI Bus reference of the new devices to be
59  * inserted.
60  *
61  * @param exist_pci_dev
62  *      Existing PCI device in PCI Bus
63  * @param new_pci_dev
64  *      PCI device to be added before exist_pci_dev
65  * @return void
66  */
67 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
68                 struct rte_pci_device *new_pci_dev);
69
70 /**
71  * Update a pci device object by asking the kernel for the latest information.
72  *
73  * This function is private to EAL.
74  *
75  * @param addr
76  *      The PCI Bus-Device-Function address to look for
77  * @return
78  *   - 0 on success.
79  *   - negative on error.
80  */
81 int pci_update_device(const struct rte_pci_addr *addr);
82
83 /**
84  * Map the PCI resource of a PCI device in virtual memory
85  *
86  * This function is private to EAL.
87  *
88  * @return
89  *   0 on success, negative on error
90  */
91 int pci_uio_map_resource(struct rte_pci_device *dev);
92
93 /**
94  * Unmap the PCI resource of a PCI device
95  *
96  * This function is private to EAL.
97  */
98 void pci_uio_unmap_resource(struct rte_pci_device *dev);
99
100 /**
101  * Allocate uio resource for PCI device
102  *
103  * This function is private to EAL.
104  *
105  * @param dev
106  *   PCI device to allocate uio resource
107  * @param uio_res
108  *   Pointer to uio resource.
109  *   If the function returns 0, the pointer will be filled.
110  * @return
111  *   0 on success, negative on error
112  */
113 int pci_uio_alloc_resource(struct rte_pci_device *dev,
114                 struct mapped_pci_resource **uio_res);
115
116 /**
117  * Free uio resource for PCI device
118  *
119  * This function is private to EAL.
120  *
121  * @param dev
122  *   PCI device to free uio resource
123  * @param uio_res
124  *   Pointer to uio resource.
125  */
126 void pci_uio_free_resource(struct rte_pci_device *dev,
127                 struct mapped_pci_resource *uio_res);
128
129 /**
130  * Map device memory to uio resource
131  *
132  * This function is private to EAL.
133  *
134  * @param dev
135  *   PCI device that has memory information.
136  * @param res_idx
137  *   Memory resource index of the PCI device.
138  * @param uio_res
139  *  uio resource that will keep mapping information.
140  * @param map_idx
141  *   Mapping information index of the uio resource.
142  * @return
143  *   0 on success, negative on error
144  */
145 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
146                 struct mapped_pci_resource *uio_res, int map_idx);
147
148 /*
149  * Match the PCI Driver and Device using the ID Table
150  *
151  * @param pci_drv
152  *      PCI driver from which ID table would be extracted
153  * @param pci_dev
154  *      PCI device to match against the driver
155  * @return
156  *      1 for successful match
157  *      0 for unsuccessful match
158  */
159 int
160 rte_pci_match(const struct rte_pci_driver *pci_drv,
161               const struct rte_pci_device *pci_dev);
162
163 /**
164  * Get iommu class of PCI devices on the bus.
165  * And return their preferred iova mapping mode.
166  *
167  * @return
168  *   - enum rte_iova_mode.
169  */
170 enum rte_iova_mode
171 rte_pci_get_iommu_class(void);
172
173 /*
174  * Iterate over internal devices,
175  * matching any device against the provided
176  * string.
177  *
178  * @param start
179  *   Iteration starting point.
180  *
181  * @param str
182  *   Device string to match against.
183  *
184  * @param it
185  *   (unused) iterator structure.
186  *
187  * @return
188  *   A pointer to the next matching device if any.
189  *   NULL otherwise.
190  */
191 void *
192 rte_pci_dev_iterate(const void *start,
193                     const char *str,
194                     const struct rte_dev_iterator *it);
195
196 #endif /* _PCI_PRIVATE_H_ */