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