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 * Update a pci device object by asking the kernel for the latest information.
72 * This function is private to EAL.
75 * The PCI Bus-Device-Function address to look for
78 * - negative on error.
80 int pci_update_device(const struct rte_pci_addr *addr);
83 * A structure describing a PCI mapping.
93 struct pci_msix_table {
100 * A structure describing a mapped PCI resource.
101 * For multi-process we need to reproduce all PCI mappings in secondary
102 * processes, so save them in a tailq.
104 struct mapped_pci_resource {
105 TAILQ_ENTRY(mapped_pci_resource) next;
107 struct rte_pci_addr pci_addr;
110 struct pci_map maps[PCI_MAX_RESOURCE];
111 struct pci_msix_table msix_table;
114 /** mapped pci device list */
115 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
118 * Map a particular resource from a file.
120 * @param requested_addr
121 * The starting address for the new mapping range.
123 * The file descriptor.
125 * The offset for the mapping range.
127 * The size for the mapping range.
128 * @param additional_flags
129 * The additional rte_mem_map() flags for the mapping range.
131 * - On success, the function returns a pointer to the mapped area.
132 * - On error, NULL is returned.
134 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
135 size_t size, int additional_flags);
138 * Unmap a particular resource.
140 * @param requested_addr
141 * The address for the unmapping range.
143 * The size for the unmapping range.
145 void pci_unmap_resource(void *requested_addr, size_t size);
148 * Map the PCI resource of a PCI device in virtual memory
150 * This function is private to EAL.
153 * 0 on success, negative on error
155 int pci_uio_map_resource(struct rte_pci_device *dev);
158 * Unmap the PCI resource of a PCI device
160 * This function is private to EAL.
162 void pci_uio_unmap_resource(struct rte_pci_device *dev);
165 * Allocate uio resource for PCI device
167 * This function is private to EAL.
170 * PCI device to allocate uio resource
172 * Pointer to uio resource.
173 * If the function returns 0, the pointer will be filled.
175 * 0 on success, negative on error
177 int pci_uio_alloc_resource(struct rte_pci_device *dev,
178 struct mapped_pci_resource **uio_res);
181 * Free uio resource for PCI device
183 * This function is private to EAL.
186 * PCI device to free uio resource
188 * Pointer to uio resource.
190 void pci_uio_free_resource(struct rte_pci_device *dev,
191 struct mapped_pci_resource *uio_res);
194 * Remap the PCI resource of a PCI device in anonymous virtual memory.
197 * Point to the struct rte pci device.
199 * - On success, zero.
200 * - On failure, a negative value.
203 pci_uio_remap_resource(struct rte_pci_device *dev);
206 * Map device memory to uio resource
208 * This function is private to EAL.
211 * PCI device that has memory information.
213 * Memory resource index of the PCI device.
215 * uio resource that will keep mapping information.
217 * Mapping information index of the uio resource.
219 * 0 on success, negative on error
221 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
222 struct mapped_pci_resource *uio_res, int map_idx);
225 * Match the PCI Driver and Device using the ID Table
228 * PCI driver from which ID table would be extracted
230 * PCI device to match against the driver
232 * 1 for successful match
233 * 0 for unsuccessful match
236 rte_pci_match(const struct rte_pci_driver *pci_drv,
237 const struct rte_pci_device *pci_dev);
240 * OS specific callbacks for rte_pci_get_iommu_class
244 pci_device_iommu_support_va(const struct rte_pci_device *dev);
247 pci_device_iova_mode(const struct rte_pci_driver *pci_drv,
248 const struct rte_pci_device *pci_dev);
251 * Get iommu class of PCI devices on the bus.
252 * And return their preferred iova mapping mode.
255 * - enum rte_iova_mode.
258 rte_pci_get_iommu_class(void);
261 * Iterate over internal devices,
262 * matching any device against the provided
266 * Iteration starting point.
269 * Device string to match against.
272 * (unused) iterator structure.
275 * A pointer to the next matching device if any.
279 rte_pci_dev_iterate(const void *start,
281 const struct rte_dev_iterator *it);
283 #endif /* _PCI_PRIVATE_H_ */