1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 6WIND S.A.
5 #ifndef _PCI_PRIVATE_H_
6 #define _PCI_PRIVATE_H_
11 #include <rte_bus_pci.h>
12 #include <rte_os_shim.h>
15 extern struct rte_pci_bus rte_pci_bus;
17 struct rte_pci_driver;
18 struct rte_pci_device;
21 * Scan the content of the PCI bus, and the devices in the devices
25 * 0 on success, negative on error
27 int rte_pci_scan(void);
30 * Find the name of a PCI device.
33 pci_name_set(struct rte_pci_device *dev);
36 * Validate whether a device with given PCI address should be ignored or not.
39 * PCI address of device to be validated
41 * true: if device is to be ignored,
42 * false: if device is to be scanned,
44 bool rte_pci_ignore_device(const struct rte_pci_addr *pci_addr);
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.
55 void rte_pci_add_device(struct rte_pci_device *pci_dev);
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
62 * @param exist_pci_dev
63 * Existing PCI device in PCI Bus
65 * PCI device to be added before exist_pci_dev
68 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
69 struct rte_pci_device *new_pci_dev);
72 * A structure describing a PCI mapping.
82 struct pci_msix_table {
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.
93 struct mapped_pci_resource {
94 TAILQ_ENTRY(mapped_pci_resource) next;
96 struct rte_pci_addr pci_addr;
99 struct pci_map maps[PCI_MAX_RESOURCE];
100 struct pci_msix_table msix_table;
103 /** mapped pci device list */
104 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
107 * Map a particular resource from a file.
109 * @param requested_addr
110 * The starting address for the new mapping range.
112 * The file descriptor.
114 * The offset for the mapping range.
116 * The size for the mapping range.
117 * @param additional_flags
118 * The additional rte_mem_map() flags for the mapping range.
120 * - On success, the function returns a pointer to the mapped area.
121 * - On error, NULL is returned.
123 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
124 size_t size, int additional_flags);
127 * Unmap a particular resource.
129 * @param requested_addr
130 * The address for the unmapping range.
132 * The size for the unmapping range.
134 void pci_unmap_resource(void *requested_addr, size_t size);
137 * Map the PCI resource of a PCI device in virtual memory
139 * This function is private to EAL.
142 * 0 on success, negative on error
144 int pci_uio_map_resource(struct rte_pci_device *dev);
147 * Unmap the PCI resource of a PCI device
149 * This function is private to EAL.
151 void pci_uio_unmap_resource(struct rte_pci_device *dev);
154 * Allocate uio resource for PCI device
156 * This function is private to EAL.
159 * PCI device to allocate uio resource
161 * Pointer to uio resource.
162 * If the function returns 0, the pointer will be filled.
164 * 0 on success, negative on error
166 int pci_uio_alloc_resource(struct rte_pci_device *dev,
167 struct mapped_pci_resource **uio_res);
170 * Free uio resource for PCI device
172 * This function is private to EAL.
175 * PCI device to free uio resource
177 * Pointer to uio resource.
179 void pci_uio_free_resource(struct rte_pci_device *dev,
180 struct mapped_pci_resource *uio_res);
183 * Remap the PCI resource of a PCI device in anonymous virtual memory.
186 * Point to the struct rte pci device.
188 * - On success, zero.
189 * - On failure, a negative value.
192 pci_uio_remap_resource(struct rte_pci_device *dev);
195 * Map device memory to uio resource
197 * This function is private to EAL.
200 * PCI device that has memory information.
202 * Memory resource index of the PCI device.
204 * uio resource that will keep mapping information.
206 * Mapping information index of the uio resource.
208 * 0 on success, negative on error
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);
214 * Match the PCI Driver and Device using the ID Table
217 * PCI driver from which ID table would be extracted
219 * PCI device to match against the driver
221 * 1 for successful match
222 * 0 for unsuccessful match
225 rte_pci_match(const struct rte_pci_driver *pci_drv,
226 const struct rte_pci_device *pci_dev);
229 * OS specific callbacks for rte_pci_get_iommu_class
233 pci_device_iommu_support_va(const struct rte_pci_device *dev);
236 pci_device_iova_mode(const struct rte_pci_driver *pci_drv,
237 const struct rte_pci_device *pci_dev);
240 * Get iommu class of PCI devices on the bus.
241 * And return their preferred iova mapping mode.
244 * - enum rte_iova_mode.
247 rte_pci_get_iommu_class(void);
250 * Iterate over internal devices,
251 * matching any device against the provided
255 * Iteration starting point.
258 * Device string to match against.
261 * (unused) iterator structure.
264 * A pointer to the next matching device if any.
268 rte_pci_dev_iterate(const void *start,
270 const struct rte_dev_iterator *it);
272 #endif /* _PCI_PRIVATE_H_ */