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>
13 extern struct rte_pci_bus rte_pci_bus;
15 struct rte_pci_driver;
16 struct rte_pci_device;
19 * Scan the content of the PCI bus, and the devices in the devices
23 * 0 on success, negative on error
25 int rte_pci_scan(void);
28 * Find the name of a PCI device.
31 pci_name_set(struct rte_pci_device *dev);
34 * Validate whether a device with given PCI address should be ignored or not.
37 * PCI address of device to be validated
39 * true: if device is to be ignored,
40 * false: if device is to be scanned,
42 bool rte_pci_ignore_device(const struct rte_pci_addr *pci_addr);
45 * Add a PCI device to the PCI Bus (append to PCI Device list). This function
46 * also updates the bus references of the PCI Device (and the generic device
47 * object embedded within.
53 void rte_pci_add_device(struct rte_pci_device *pci_dev);
56 * Insert a PCI device in the PCI Bus at a particular location in the device
57 * list. It also updates the PCI Bus reference of the new devices to be
60 * @param exist_pci_dev
61 * Existing PCI device in PCI Bus
63 * PCI device to be added before exist_pci_dev
66 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
67 struct rte_pci_device *new_pci_dev);
70 * A structure describing a PCI mapping.
80 struct pci_msix_table {
87 * A structure describing a mapped PCI resource.
88 * For multi-process we need to reproduce all PCI mappings in secondary
89 * processes, so save them in a tailq.
91 struct mapped_pci_resource {
92 TAILQ_ENTRY(mapped_pci_resource) next;
94 struct rte_pci_addr pci_addr;
97 struct pci_map maps[PCI_MAX_RESOURCE];
98 struct pci_msix_table msix_table;
101 /** mapped pci device list */
102 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
105 * Map a particular resource from a file.
107 * @param requested_addr
108 * The starting address for the new mapping range.
110 * The file descriptor.
112 * The offset for the mapping range.
114 * The size for the mapping range.
115 * @param additional_flags
116 * The additional rte_mem_map() flags for the mapping range.
118 * - On success, the function returns a pointer to the mapped area.
119 * - On error, NULL is returned.
121 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
122 size_t size, int additional_flags);
125 * Unmap a particular resource.
127 * @param requested_addr
128 * The address for the unmapping range.
130 * The size for the unmapping range.
132 void pci_unmap_resource(void *requested_addr, size_t size);
135 * Map the PCI resource of a PCI device in virtual memory
137 * This function is private to EAL.
140 * 0 on success, negative on error
142 int pci_uio_map_resource(struct rte_pci_device *dev);
145 * Unmap the PCI resource of a PCI device
147 * This function is private to EAL.
149 void pci_uio_unmap_resource(struct rte_pci_device *dev);
152 * Allocate uio resource for PCI device
154 * This function is private to EAL.
157 * PCI device to allocate uio resource
159 * Pointer to uio resource.
160 * If the function returns 0, the pointer will be filled.
162 * 0 on success, negative on error
164 int pci_uio_alloc_resource(struct rte_pci_device *dev,
165 struct mapped_pci_resource **uio_res);
168 * Free uio resource for PCI device
170 * This function is private to EAL.
173 * PCI device to free uio resource
175 * Pointer to uio resource.
177 void pci_uio_free_resource(struct rte_pci_device *dev,
178 struct mapped_pci_resource *uio_res);
181 * Remap the PCI resource of a PCI device in anonymous virtual memory.
184 * Point to the struct rte pci device.
186 * - On success, zero.
187 * - On failure, a negative value.
190 pci_uio_remap_resource(struct rte_pci_device *dev);
193 * Map device memory to uio resource
195 * This function is private to EAL.
198 * PCI device that has memory information.
200 * Memory resource index of the PCI device.
202 * uio resource that will keep mapping information.
204 * Mapping information index of the uio resource.
206 * 0 on success, negative on error
208 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
209 struct mapped_pci_resource *uio_res, int map_idx);
212 * Match the PCI Driver and Device using the ID Table
215 * PCI driver from which ID table would be extracted
217 * PCI device to match against the driver
219 * 1 for successful match
220 * 0 for unsuccessful match
223 rte_pci_match(const struct rte_pci_driver *pci_drv,
224 const struct rte_pci_device *pci_dev);
227 * OS specific callbacks for rte_pci_get_iommu_class
231 pci_device_iommu_support_va(const struct rte_pci_device *dev);
234 pci_device_iova_mode(const struct rte_pci_driver *pci_drv,
235 const struct rte_pci_device *pci_dev);
238 * Get iommu class of PCI devices on the bus.
239 * And return their preferred iova mapping mode.
242 * - enum rte_iova_mode.
245 rte_pci_get_iommu_class(void);
248 * Iterate over internal devices,
249 * matching any device against the provided
253 * Iteration starting point.
256 * Device string to match against.
259 * (unused) iterator structure.
262 * A pointer to the next matching device if any.
266 rte_pci_dev_iterate(const void *start,
268 const struct rte_dev_iterator *it);
270 #endif /* _PCI_PRIVATE_H_ */