1 /* SPDX-License-Identifier: BSD-3-Clause
11 * DPDK device bus interface
13 * This file exposes API and interfaces for bus abstraction
14 * over the devices and drivers in EAL.
22 #include <sys/queue.h>
27 /** Double linked list of buses */
28 TAILQ_HEAD(rte_bus_list, rte_bus);
34 * IOVA mapping mode is iommu programming mode of a device.
35 * That device (for example: IOMMU backed DMA device) based
36 * on rte_iova_mode will generate physical or virtual address.
40 RTE_IOVA_DC = 0, /* Don't care mode */
41 RTE_IOVA_PA = (1 << 0), /* DMA using physical address */
42 RTE_IOVA_VA = (1 << 1) /* DMA using virtual address */
46 * Bus specific scan for devices attached on the bus.
47 * For each bus object, the scan would be responsible for finding devices and
48 * adding them to its private device list.
50 * A bus should mandatorily implement this method.
53 * 0 for successful scan
54 * <0 for unsuccessful scan with error value
56 typedef int (*rte_bus_scan_t)(void);
59 * Implementation specific probe function which is responsible for linking
60 * devices on that bus with applicable drivers.
62 * This is called while iterating over each registered bus.
65 * 0 for successful probe
66 * !0 for any error while probing
68 typedef int (*rte_bus_probe_t)(void);
71 * Device iterator to find a device on a bus.
73 * This function returns an rte_device if one of those held by the bus
74 * matches the data passed as parameter.
76 * If the comparison function returns zero this function should stop iterating
77 * over any more devices. To continue a search the device of a previous search
78 * can be passed via the start parameter.
81 * Comparison function.
84 * Data to compare each device against.
87 * starting point for the iteration
90 * The first device matching the data, NULL if none exists.
92 typedef struct rte_device *
93 (*rte_bus_find_device_t)(const struct rte_device *start, rte_dev_cmp_t cmp,
97 * Implementation specific probe function which is responsible for linking
98 * devices on that bus with applicable drivers.
101 * Device pointer that was returned by a previous call to find_device.
107 typedef int (*rte_bus_plug_t)(struct rte_device *dev);
110 * Implementation specific remove function which is responsible for unlinking
111 * devices on that bus from assigned driver.
114 * Device pointer that was returned by a previous call to find_device.
120 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
123 * Bus specific parsing function.
124 * Validates the syntax used in the textual representation of a device,
125 * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
126 * device representation to ``addr``.
129 * device textual description
132 * device information location address, into which parsed info
133 * should be written. If NULL, nothing should be written, which
137 * 0 if parsing was successful.
140 typedef int (*rte_bus_parse_t)(const char *name, void *addr);
143 * Device level DMA map function.
144 * After a successful call, the memory segment will be mapped to the
150 * Virtual address to map.
152 * IOVA address to map.
154 * Length of the memory segment being mapped.
157 * 0 if mapping was successful.
158 * Negative value and rte_errno is set otherwise.
160 typedef int (*rte_dev_dma_map_t)(struct rte_device *dev, void *addr,
161 uint64_t iova, size_t len);
164 * Device level DMA unmap function.
165 * After a successful call, the memory segment will no longer be
166 * accessible by the given device.
171 * Virtual address to unmap.
173 * IOVA address to unmap.
175 * Length of the memory segment being mapped.
178 * 0 if un-mapping was successful.
179 * Negative value and rte_errno is set otherwise.
181 typedef int (*rte_dev_dma_unmap_t)(struct rte_device *dev, void *addr,
182 uint64_t iova, size_t len);
185 * Implement a specific hot-unplug handler, which is responsible for
186 * handle the failure when device be hot-unplugged. When the event of
187 * hot-unplug be detected, it could call this function to handle
188 * the hot-unplug failure and avoid app crash.
190 * Pointer of the device structure.
196 typedef int (*rte_bus_hot_unplug_handler_t)(struct rte_device *dev);
199 * Implement a specific sigbus handler, which is responsible for handling
200 * the sigbus error which is either original memory error, or specific memory
201 * error that caused of device be hot-unplugged. When sigbus error be captured,
202 * it could call this function to handle sigbus error.
203 * @param failure_addr
204 * Pointer of the fault address of the sigbus error.
207 * 0 for success handle the sigbus for hot-unplug.
208 * 1 for not process it, because it is a generic sigbus error.
209 * -1 for failed to handle the sigbus for hot-unplug.
211 typedef int (*rte_bus_sigbus_handler_t)(const void *failure_addr);
216 enum rte_bus_scan_mode {
217 RTE_BUS_SCAN_UNDEFINED,
218 RTE_BUS_SCAN_ALLOWLIST,
219 RTE_BUS_SCAN_BLOCKLIST,
222 /* Backwards compatibility will be removed */
223 #define RTE_BUS_SCAN_WHITELIST \
224 RTE_DEPRECATED(RTE_BUS_SCAN_WHITELIST) RTE_BUS_SCAN_ALLOWLIST
225 #define RTE_BUS_SCAN_BLACKLIST \
226 RTE_DEPRECATED(RTE_BUS_SCAN_BLACKLIST) RTE_BUS_SCAN_BLOCKLIST
229 * A structure used to configure bus operations.
231 struct rte_bus_conf {
232 enum rte_bus_scan_mode scan_mode; /**< Scan policy. */
237 * Get common iommu class of the all the devices on the bus. The bus may
238 * check that those devices are attached to iommu driver.
239 * If no devices are attached to the bus. The bus may return with don't care
241 * Otherwise, The bus will return appropriate _pa or _va iova mode.
244 * enum rte_iova_mode value.
246 typedef enum rte_iova_mode (*rte_bus_get_iommu_class_t)(void);
250 * A structure describing a generic bus.
253 TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */
254 const char *name; /**< Name of the bus */
255 rte_bus_scan_t scan; /**< Scan for devices attached to bus */
256 rte_bus_probe_t probe; /**< Probe devices on bus */
257 rte_bus_find_device_t find_device; /**< Find a device on the bus */
258 rte_bus_plug_t plug; /**< Probe single device for drivers */
259 rte_bus_unplug_t unplug; /**< Remove single device from driver */
260 rte_bus_parse_t parse; /**< Parse a device name */
261 rte_dev_dma_map_t dma_map; /**< DMA map for device in the bus */
262 rte_dev_dma_unmap_t dma_unmap; /**< DMA unmap for device in the bus */
263 struct rte_bus_conf conf; /**< Bus configuration */
264 rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */
265 rte_dev_iterate_t dev_iterate; /**< Device iterator. */
266 rte_bus_hot_unplug_handler_t hot_unplug_handler;
267 /**< handle hot-unplug failure on the bus */
268 rte_bus_sigbus_handler_t sigbus_handler;
269 /**< handle sigbus error on the bus */
274 * Register a Bus handler.
277 * A pointer to a rte_bus structure describing the bus
280 void rte_bus_register(struct rte_bus *bus);
283 * Unregister a Bus handler.
286 * A pointer to a rte_bus structure describing the bus
287 * to be unregistered.
289 void rte_bus_unregister(struct rte_bus *bus);
292 * Scan all the buses.
295 * 0 in case of success in scanning all buses
296 * !0 in case of failure to scan
298 int rte_bus_scan(void);
301 * For each device on the buses, perform a driver 'match' and call the
302 * driver-specific probe for device initialization.
305 * 0 for successful match/probe
308 int rte_bus_probe(void);
311 * Dump information of all the buses registered with EAL.
314 * A valid and open output stream handle
316 void rte_bus_dump(FILE *f);
319 * Bus comparison function.
325 * Data to compare against.
328 * 0 if the bus matches the data.
329 * !0 if the bus does not match.
330 * <0 if ordering is possible and the bus is lower than the data.
331 * >0 if ordering is possible and the bus is greater than the data.
333 typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data);
336 * Bus iterator to find a particular bus.
338 * This function compares each registered bus to find one that matches
339 * the data passed as parameter.
341 * If the comparison function returns zero this function will stop iterating
342 * over any more buses. To continue a search the bus of a previous search can
343 * be passed via the start parameter.
346 * Starting point for the iteration.
349 * Comparison function.
352 * Data to pass to comparison function.
355 * A pointer to a rte_bus structure or NULL in case no bus matches
357 struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
361 * Find the registered bus for a particular device.
363 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
366 * Find the registered bus for a given name.
368 struct rte_bus *rte_bus_find_by_name(const char *busname);
372 * Get the common iommu class of devices bound on to buses available in the
373 * system. RTE_IOVA_DC means that no preference has been expressed.
376 * enum rte_iova_mode value.
378 enum rte_iova_mode rte_bus_get_iommu_class(void);
381 * Helper for Bus registration.
382 * The constructor has higher priority than PMD constructors.
384 #define RTE_REGISTER_BUS(nm, bus) \
385 RTE_INIT_PRIO(businitfn_ ##nm, BUS) \
387 (bus).name = RTE_STR(nm);\
388 rte_bus_register(&bus); \
395 #endif /* _RTE_BUS_H */