net/mlx5: fix meter policy flow match item
[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
11 #include <rte_bus_pci.h>
12 #include <rte_os_shim.h>
13 #include <rte_pci.h>
14
15 extern struct rte_pci_bus rte_pci_bus;
16
17 struct rte_pci_driver;
18 struct rte_pci_device;
19
20 /**
21  * Scan the content of the PCI bus, and the devices in the devices
22  * list
23  *
24  * @return
25  *  0 on success, negative on error
26  */
27 int rte_pci_scan(void);
28
29 /**
30  * Find the name of a PCI device.
31  */
32 void
33 pci_name_set(struct rte_pci_device *dev);
34
35 /**
36  * Validate whether a device with given PCI address should be ignored or not.
37  *
38  * @param pci_addr
39  *      PCI address of device to be validated
40  * @return
41  *      true: if device is to be ignored,
42  *      false: if device is to be scanned,
43  */
44 bool rte_pci_ignore_device(const struct rte_pci_addr *pci_addr);
45
46 /**
47  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
48  * also updates the bus references of the PCI Device (and the generic device
49  * object embedded within.
50  *
51  * @param pci_dev
52  *      PCI device to add
53  * @return void
54  */
55 void rte_pci_add_device(struct rte_pci_device *pci_dev);
56
57 /**
58  * Insert a PCI device in the PCI Bus at a particular location in the device
59  * list. It also updates the PCI Bus reference of the new devices to be
60  * inserted.
61  *
62  * @param exist_pci_dev
63  *      Existing PCI device in PCI Bus
64  * @param new_pci_dev
65  *      PCI device to be added before exist_pci_dev
66  * @return void
67  */
68 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
69                 struct rte_pci_device *new_pci_dev);
70
71 /**
72  * A structure describing a PCI mapping.
73  */
74 struct pci_map {
75         void *addr;
76         char *path;
77         uint64_t offset;
78         uint64_t size;
79         uint64_t phaddr;
80 };
81
82 struct pci_msix_table {
83         int bar_index;
84         uint32_t offset;
85         uint32_t size;
86 };
87
88 /**
89  * A structure describing a mapped PCI resource.
90  * For multi-process we need to reproduce all PCI mappings in secondary
91  * processes, so save them in a tailq.
92  */
93 struct mapped_pci_resource {
94         TAILQ_ENTRY(mapped_pci_resource) next;
95
96         struct rte_pci_addr pci_addr;
97         char path[PATH_MAX];
98         int nb_maps;
99         struct pci_map maps[PCI_MAX_RESOURCE];
100         struct pci_msix_table msix_table;
101 };
102
103 /** mapped pci device list */
104 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
105
106 /**
107  * Map a particular resource from a file.
108  *
109  * @param requested_addr
110  *      The starting address for the new mapping range.
111  * @param fd
112  *      The file descriptor.
113  * @param offset
114  *      The offset for the mapping range.
115  * @param size
116  *      The size for the mapping range.
117  * @param additional_flags
118  *      The additional rte_mem_map() flags for the mapping range.
119  * @return
120  *   - On success, the function returns a pointer to the mapped area.
121  *   - On error, NULL is returned.
122  */
123 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
124                 size_t size, int additional_flags);
125
126 /**
127  * Unmap a particular resource.
128  *
129  * @param requested_addr
130  *      The address for the unmapping range.
131  * @param size
132  *      The size for the unmapping range.
133  */
134 void pci_unmap_resource(void *requested_addr, size_t size);
135
136 /**
137  * Map the PCI resource of a PCI device in virtual memory
138  *
139  * This function is private to EAL.
140  *
141  * @return
142  *   0 on success, negative on error
143  */
144 int pci_uio_map_resource(struct rte_pci_device *dev);
145
146 /**
147  * Unmap the PCI resource of a PCI device
148  *
149  * This function is private to EAL.
150  */
151 void pci_uio_unmap_resource(struct rte_pci_device *dev);
152
153 /**
154  * Allocate uio resource for PCI device
155  *
156  * This function is private to EAL.
157  *
158  * @param dev
159  *   PCI device to allocate uio resource
160  * @param uio_res
161  *   Pointer to uio resource.
162  *   If the function returns 0, the pointer will be filled.
163  * @return
164  *   0 on success, negative on error
165  */
166 int pci_uio_alloc_resource(struct rte_pci_device *dev,
167                 struct mapped_pci_resource **uio_res);
168
169 /**
170  * Free uio resource for PCI device
171  *
172  * This function is private to EAL.
173  *
174  * @param dev
175  *   PCI device to free uio resource
176  * @param uio_res
177  *   Pointer to uio resource.
178  */
179 void pci_uio_free_resource(struct rte_pci_device *dev,
180                 struct mapped_pci_resource *uio_res);
181
182 /**
183  * Remap the PCI resource of a PCI device in anonymous virtual memory.
184  *
185  * @param dev
186  *   Point to the struct rte pci device.
187  * @return
188  *   - On success, zero.
189  *   - On failure, a negative value.
190  */
191 int
192 pci_uio_remap_resource(struct rte_pci_device *dev);
193
194 /**
195  * Map device memory to uio resource
196  *
197  * This function is private to EAL.
198  *
199  * @param dev
200  *   PCI device that has memory information.
201  * @param res_idx
202  *   Memory resource index of the PCI device.
203  * @param uio_res
204  *  uio resource that will keep mapping information.
205  * @param map_idx
206  *   Mapping information index of the uio resource.
207  * @return
208  *   0 on success, negative on error
209  */
210 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
211                 struct mapped_pci_resource *uio_res, int map_idx);
212
213 /*
214  * Match the PCI Driver and Device using the ID Table
215  *
216  * @param pci_drv
217  *      PCI driver from which ID table would be extracted
218  * @param pci_dev
219  *      PCI device to match against the driver
220  * @return
221  *      1 for successful match
222  *      0 for unsuccessful match
223  */
224 int
225 rte_pci_match(const struct rte_pci_driver *pci_drv,
226               const struct rte_pci_device *pci_dev);
227
228 /**
229  * OS specific callbacks for rte_pci_get_iommu_class
230  *
231  */
232 bool
233 pci_device_iommu_support_va(const struct rte_pci_device *dev);
234
235 enum rte_iova_mode
236 pci_device_iova_mode(const struct rte_pci_driver *pci_drv,
237                      const struct rte_pci_device *pci_dev);
238
239 /**
240  * Get iommu class of PCI devices on the bus.
241  * And return their preferred iova mapping mode.
242  *
243  * @return
244  *   - enum rte_iova_mode.
245  */
246 enum rte_iova_mode
247 rte_pci_get_iommu_class(void);
248
249 /*
250  * Iterate over internal devices,
251  * matching any device against the provided
252  * string.
253  *
254  * @param start
255  *   Iteration starting point.
256  *
257  * @param str
258  *   Device string to match against.
259  *
260  * @param it
261  *   (unused) iterator structure.
262  *
263  * @return
264  *   A pointer to the next matching device if any.
265  *   NULL otherwise.
266  */
267 void *
268 rte_pci_dev_iterate(const void *start,
269                     const char *str,
270                     const struct rte_dev_iterator *it);
271
272 #endif /* _PCI_PRIVATE_H_ */