6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of NXP nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * DPDK device bus interface
41 * This file exposes API and interfaces for bus abstraction
42 * over the devices and drivers in EAL.
50 #include <sys/queue.h>
55 /** Double linked list of buses */
56 TAILQ_HEAD(rte_bus_list, rte_bus);
62 * IOVA mapping mode is iommu programming mode of a device.
63 * That device (for example: IOMMU backed DMA device) based
64 * on rte_iova_mode will generate physical or virtual address.
68 RTE_IOVA_DC = 0, /* Don't care mode */
69 RTE_IOVA_PA = (1 << 0), /* DMA using physical address */
70 RTE_IOVA_VA = (1 << 1) /* DMA using virtual address */
74 * Bus specific scan for devices attached on the bus.
75 * For each bus object, the scan would be responsible for finding devices and
76 * adding them to its private device list.
78 * A bus should mandatorily implement this method.
81 * 0 for successful scan
82 * <0 for unsuccessful scan with error value
84 typedef int (*rte_bus_scan_t)(void);
87 * Implementation specific probe function which is responsible for linking
88 * devices on that bus with applicable drivers.
90 * This is called while iterating over each registered bus.
93 * 0 for successful probe
94 * !0 for any error while probing
96 typedef int (*rte_bus_probe_t)(void);
99 * Device iterator to find a device on a bus.
101 * This function returns an rte_device if one of those held by the bus
102 * matches the data passed as parameter.
104 * If the comparison function returns zero this function should stop iterating
105 * over any more devices. To continue a search the device of a previous search
106 * can be passed via the start parameter.
109 * Comparison function.
112 * Data to compare each device against.
115 * starting point for the iteration
118 * The first device matching the data, NULL if none exists.
120 typedef struct rte_device *
121 (*rte_bus_find_device_t)(const struct rte_device *start, rte_dev_cmp_t cmp,
125 * Implementation specific probe function which is responsible for linking
126 * devices on that bus with applicable drivers.
129 * Device pointer that was returned by a previous call to find_device.
135 typedef int (*rte_bus_plug_t)(struct rte_device *dev);
138 * Implementation specific remove function which is responsible for unlinking
139 * devices on that bus from assigned driver.
142 * Device pointer that was returned by a previous call to find_device.
148 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
151 * Bus specific parsing function.
152 * Validates the syntax used in the textual representation of a device,
153 * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
154 * device representation to ``addr``.
157 * device textual description
160 * device information location address, into which parsed info
161 * should be written. If NULL, nothing should be written, which
165 * 0 if parsing was successful.
168 typedef int (*rte_bus_parse_t)(const char *name, void *addr);
171 * Device level DMA map function.
172 * After a successful call, the memory segment will be mapped to the
178 * Virtual address to map.
180 * IOVA address to map.
182 * Length of the memory segment being mapped.
185 * 0 if mapping was successful.
186 * Negative value and rte_errno is set otherwise.
188 typedef int (*rte_dev_dma_map_t)(struct rte_device *dev, void *addr,
189 uint64_t iova, size_t len);
192 * Device level DMA unmap function.
193 * After a successful call, the memory segment will no longer be
194 * accessible by the given device.
199 * Virtual address to unmap.
201 * IOVA address to unmap.
203 * Length of the memory segment being mapped.
206 * 0 if un-mapping was successful.
207 * Negative value and rte_errno is set otherwise.
209 typedef int (*rte_dev_dma_unmap_t)(struct rte_device *dev, void *addr,
210 uint64_t iova, size_t len);
213 * Implement a specific hot-unplug handler, which is responsible for
214 * handle the failure when device be hot-unplugged. When the event of
215 * hot-unplug be detected, it could call this function to handle
216 * the hot-unplug failure and avoid app crash.
218 * Pointer of the device structure.
224 typedef int (*rte_bus_hot_unplug_handler_t)(struct rte_device *dev);
227 * Implement a specific sigbus handler, which is responsible for handling
228 * the sigbus error which is either original memory error, or specific memory
229 * error that caused of device be hot-unplugged. When sigbus error be captured,
230 * it could call this function to handle sigbus error.
231 * @param failure_addr
232 * Pointer of the fault address of the sigbus error.
235 * 0 for success handle the sigbus for hot-unplug.
236 * 1 for not process it, because it is a generic sigbus error.
237 * -1 for failed to handle the sigbus for hot-unplug.
239 typedef int (*rte_bus_sigbus_handler_t)(const void *failure_addr);
244 enum rte_bus_scan_mode {
245 RTE_BUS_SCAN_UNDEFINED,
246 RTE_BUS_SCAN_WHITELIST,
247 RTE_BUS_SCAN_BLACKLIST,
251 * A structure used to configure bus operations.
253 struct rte_bus_conf {
254 enum rte_bus_scan_mode scan_mode; /**< Scan policy. */
259 * Get common iommu class of the all the devices on the bus. The bus may
260 * check that those devices are attached to iommu driver.
261 * If no devices are attached to the bus. The bus may return with don't care
263 * Otherwise, The bus will return appropriate _pa or _va iova mode.
266 * enum rte_iova_mode value.
268 typedef enum rte_iova_mode (*rte_bus_get_iommu_class_t)(void);
272 * A structure describing a generic bus.
275 TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */
276 const char *name; /**< Name of the bus */
277 rte_bus_scan_t scan; /**< Scan for devices attached to bus */
278 rte_bus_probe_t probe; /**< Probe devices on bus */
279 rte_bus_find_device_t find_device; /**< Find a device on the bus */
280 rte_bus_plug_t plug; /**< Probe single device for drivers */
281 rte_bus_unplug_t unplug; /**< Remove single device from driver */
282 rte_bus_parse_t parse; /**< Parse a device name */
283 rte_dev_dma_map_t dma_map; /**< DMA map for device in the bus */
284 rte_dev_dma_unmap_t dma_unmap; /**< DMA unmap for device in the bus */
285 struct rte_bus_conf conf; /**< Bus configuration */
286 rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */
287 rte_dev_iterate_t dev_iterate; /**< Device iterator. */
288 rte_bus_hot_unplug_handler_t hot_unplug_handler;
289 /**< handle hot-unplug failure on the bus */
290 rte_bus_sigbus_handler_t sigbus_handler;
291 /**< handle sigbus error on the bus */
296 * Register a Bus handler.
299 * A pointer to a rte_bus structure describing the bus
302 void rte_bus_register(struct rte_bus *bus);
305 * Unregister a Bus handler.
308 * A pointer to a rte_bus structure describing the bus
309 * to be unregistered.
311 void rte_bus_unregister(struct rte_bus *bus);
314 * Scan all the buses.
317 * 0 in case of success in scanning all buses
318 * !0 in case of failure to scan
320 int rte_bus_scan(void);
323 * For each device on the buses, perform a driver 'match' and call the
324 * driver-specific probe for device initialization.
327 * 0 for successful match/probe
330 int rte_bus_probe(void);
333 * Dump information of all the buses registered with EAL.
336 * A valid and open output stream handle
338 void rte_bus_dump(FILE *f);
341 * Bus comparison function.
347 * Data to compare against.
350 * 0 if the bus matches the data.
351 * !0 if the bus does not match.
352 * <0 if ordering is possible and the bus is lower than the data.
353 * >0 if ordering is possible and the bus is greater than the data.
355 typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data);
358 * Bus iterator to find a particular bus.
360 * This function compares each registered bus to find one that matches
361 * the data passed as parameter.
363 * If the comparison function returns zero this function will stop iterating
364 * over any more buses. To continue a search the bus of a previous search can
365 * be passed via the start parameter.
368 * Starting point for the iteration.
371 * Comparison function.
374 * Data to pass to comparison function.
377 * A pointer to a rte_bus structure or NULL in case no bus matches
379 struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
383 * Find the registered bus for a particular device.
385 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
388 * Find the registered bus for a given name.
390 struct rte_bus *rte_bus_find_by_name(const char *busname);
394 * Get the common iommu class of devices bound on to buses available in the
395 * system. RTE_IOVA_DC means that no preferrence has been expressed.
398 * enum rte_iova_mode value.
400 enum rte_iova_mode rte_bus_get_iommu_class(void);
403 * Helper for Bus registration.
404 * The constructor has higher priority than PMD constructors.
406 #define RTE_REGISTER_BUS(nm, bus) \
407 RTE_INIT_PRIO(businitfn_ ##nm, BUS) \
409 (bus).name = RTE_STR(nm);\
410 rte_bus_register(&bus); \
417 #endif /* _RTE_BUS_H */