xref: /dpdk/lib/eal/include/rte_bus.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 NXP
3  */
4 
5 #ifndef _RTE_BUS_H_
6 #define _RTE_BUS_H_
7 
8 /**
9  * @file
10  *
11  * DPDK device bus interface
12  *
13  * This file exposes API and interfaces for bus abstraction
14  * over the devices and drivers in EAL.
15  */
16 
17 #include <stdio.h>
18 
19 #include <rte_eal.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 struct rte_bus;
26 struct rte_device;
27 
28 /**
29  * Retrieve a bus name.
30  *
31  * @param bus
32  *   A pointer to a rte_bus structure.
33  * @return
34  *   A pointer to the bus name string.
35  */
36 const char *rte_bus_name(const struct rte_bus *bus);
37 
38 /**
39  * Scan all the buses.
40  *
41  * @return
42  *   0 in case of success in scanning all buses
43  *  !0 in case of failure to scan
44  */
45 int rte_bus_scan(void);
46 
47 /**
48  * For each device on the buses, perform a driver 'match' and call the
49  * driver-specific probe for device initialization.
50  *
51  * @return
52  *	 0 for successful match/probe
53  *	!0 otherwise
54  */
55 int rte_bus_probe(void);
56 
57 /**
58  * Dump information of all the buses registered with EAL.
59  *
60  * @param f
61  *	 A valid and open output stream handle
62  */
63 void rte_bus_dump(FILE *f);
64 
65 /**
66  * Bus comparison function.
67  *
68  * @param bus
69  *	Bus under test.
70  *
71  * @param data
72  *	Data to compare against.
73  *
74  * @return
75  *	0 if the bus matches the data.
76  *	!0 if the bus does not match.
77  *	<0 if ordering is possible and the bus is lower than the data.
78  *	>0 if ordering is possible and the bus is greater than the data.
79  */
80 typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data);
81 
82 /**
83  * Bus iterator to find a particular bus.
84  *
85  * This function compares each registered bus to find one that matches
86  * the data passed as parameter.
87  *
88  * If the comparison function returns zero this function will stop iterating
89  * over any more buses. To continue a search the bus of a previous search can
90  * be passed via the start parameter.
91  *
92  * @param start
93  *	Starting point for the iteration.
94  *
95  * @param cmp
96  *	Comparison function.
97  *
98  * @param data
99  *	 Data to pass to comparison function.
100  *
101  * @return
102  *	 A pointer to a rte_bus structure or NULL in case no bus matches
103  */
104 struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
105 			     const void *data);
106 
107 /**
108  * Find the registered bus for a particular device.
109  */
110 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
111 
112 /**
113  * Find the registered bus for a given name.
114  */
115 struct rte_bus *rte_bus_find_by_name(const char *busname);
116 
117 
118 /**
119  * Get the common iommu class of devices bound on to buses available in the
120  * system. RTE_IOVA_DC means that no preference has been expressed.
121  *
122  * @return
123  *     enum rte_iova_mode value.
124  */
125 enum rte_iova_mode rte_bus_get_iommu_class(void);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif /* _RTE_BUS_H */
132