4 * Copyright(c) 2016 NXP
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of NXP nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * DPDK device bus interface
42 * This file exposes API and interfaces for bus abstraction
43 * over the devices and drivers in EAL.
51 #include <sys/queue.h>
56 /** Double linked list of buses */
57 TAILQ_HEAD(rte_bus_list, rte_bus);
60 * Bus specific scan for devices attached on the bus.
61 * For each bus object, the scan would be responsible for finding devices and
62 * adding them to its private device list.
64 * A bus should mandatorily implement this method.
67 * 0 for successful scan
68 * <0 for unsuccessful scan with error value
70 typedef int (*rte_bus_scan_t)(void);
73 * Implementation specific probe function which is responsible for linking
74 * devices on that bus with applicable drivers.
76 * This is called while iterating over each registered bus.
79 * 0 for successful probe
80 * !0 for any error while probing
82 typedef int (*rte_bus_probe_t)(void);
85 * Device iterator to find a device on a bus.
87 * This function returns an rte_device if one of those held by the bus
88 * matches the data passed as parameter.
90 * If the comparison function returns zero this function should stop iterating
91 * over any more devices. To continue a search the device of a previous search
92 * can be passed via the start parameter.
95 * Comparison function.
98 * Data to compare each device against.
101 * starting point for the iteration
104 * The first device matching the data, NULL if none exists.
106 typedef struct rte_device *
107 (*rte_bus_find_device_t)(const struct rte_device *start, rte_dev_cmp_t cmp,
111 * Implementation specific probe function which is responsible for linking
112 * devices on that bus with applicable drivers.
115 * Device pointer that was returned by a previous call to find_device.
118 * Device declaration.
124 typedef int (*rte_bus_plug_t)(struct rte_device *dev,
125 const char *devargs);
128 * Implementation specific remove function which is responsible for unlinking
129 * devices on that bus from assigned driver.
132 * Device pointer that was returned by a previous call to find_device.
138 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
141 * Bus specific parsing function.
142 * Validates the syntax used in the textual representation of a device,
143 * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
144 * device representation to ``addr``.
147 * device textual description
150 * device information location address, into which parsed info
151 * should be written. If NULL, nothing should be written, which
155 * 0 if parsing was successful.
158 typedef int (*rte_bus_parse_t)(const char *name, void *addr);
163 enum rte_bus_scan_mode {
164 RTE_BUS_SCAN_UNDEFINED,
165 RTE_BUS_SCAN_WHITELIST,
166 RTE_BUS_SCAN_BLACKLIST,
170 * A structure used to configure bus operations.
172 struct rte_bus_conf {
173 enum rte_bus_scan_mode scan_mode; /**< Scan policy. */
177 * A structure describing a generic bus.
180 TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */
181 const char *name; /**< Name of the bus */
182 rte_bus_scan_t scan; /**< Scan for devices attached to bus */
183 rte_bus_probe_t probe; /**< Probe devices on bus */
184 rte_bus_find_device_t find_device; /**< Find a device on the bus */
185 rte_bus_plug_t plug; /**< Probe single device for drivers */
186 rte_bus_unplug_t unplug; /**< Remove single device from driver */
187 rte_bus_parse_t parse; /**< Parse a device name */
188 struct rte_bus_conf conf; /**< Bus configuration */
192 * Register a Bus handler.
195 * A pointer to a rte_bus structure describing the bus
198 void rte_bus_register(struct rte_bus *bus);
201 * Unregister a Bus handler.
204 * A pointer to a rte_bus structure describing the bus
205 * to be unregistered.
207 void rte_bus_unregister(struct rte_bus *bus);
210 * Scan all the buses.
213 * 0 in case of success in scanning all buses
214 * !0 in case of failure to scan
216 int rte_bus_scan(void);
219 * For each device on the buses, perform a driver 'match' and call the
220 * driver-specific probe for device initialization.
223 * 0 for successful match/probe
226 int rte_bus_probe(void);
229 * Dump information of all the buses registered with EAL.
232 * A valid and open output stream handle
235 * 0 in case of success
236 * !0 in case there is error in opening the output stream
238 void rte_bus_dump(FILE *f);
241 * Bus comparison function.
247 * Data to compare against.
250 * 0 if the bus matches the data.
251 * !0 if the bus does not match.
252 * <0 if ordering is possible and the bus is lower than the data.
253 * >0 if ordering is possible and the bus is greater than the data.
255 typedef int (*rte_bus_cmp_t)(const struct rte_bus *bus, const void *data);
258 * Bus iterator to find a particular bus.
260 * This function compares each registered bus to find one that matches
261 * the data passed as parameter.
263 * If the comparison function returns zero this function will stop iterating
264 * over any more buses. To continue a search the bus of a previous search can
265 * be passed via the start parameter.
268 * Starting point for the iteration.
271 * Comparison function.
274 * Data to pass to comparison function.
277 * A pointer to a rte_bus structure or NULL in case no bus matches
279 struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
283 * Find the registered bus for a particular device.
285 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
288 * Find the registered bus for a given name.
290 struct rte_bus *rte_bus_find_by_name(const char *busname);
293 * Helper for Bus registration.
294 * The constructor has higher priority than PMD constructors.
296 #define RTE_REGISTER_BUS(nm, bus) \
297 RTE_INIT_PRIO(businitfn_ ##nm, 101); \
298 static void businitfn_ ##nm(void) \
300 (bus).name = RTE_STR(nm);\
301 rte_bus_register(&bus); \
308 #endif /* _RTE_BUS_H */