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.
35 #include <sys/queue.h>
39 #include "eal_private.h"
41 struct rte_bus_list rte_bus_list =
42 TAILQ_HEAD_INITIALIZER(rte_bus_list);
45 rte_bus_register(struct rte_bus *bus)
48 RTE_VERIFY(bus->name && strlen(bus->name));
49 /* A bus should mandatorily have the scan implemented */
50 RTE_VERIFY(bus->scan);
51 RTE_VERIFY(bus->probe);
52 RTE_VERIFY(bus->find_device);
53 /* Buses supporting driver plug also require unplug. */
54 RTE_VERIFY(!bus->plug || bus->unplug);
56 TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
57 RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name);
61 rte_bus_unregister(struct rte_bus *bus)
63 TAILQ_REMOVE(&rte_bus_list, bus, next);
64 RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", bus->name);
67 /* Scan all the buses for registered devices */
72 struct rte_bus *bus = NULL;
74 TAILQ_FOREACH(bus, &rte_bus_list, next) {
77 RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n",
84 /* Probe all devices of all buses */
89 struct rte_bus *bus, *vbus = NULL;
91 TAILQ_FOREACH(bus, &rte_bus_list, next) {
92 if (!strcmp(bus->name, "vdev")) {
99 RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
106 RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
113 /* Dump information of a single bus */
115 bus_dump_one(FILE *f, struct rte_bus *bus)
119 /* For now, dump only the bus name */
120 ret = fprintf(f, " %s\n", bus->name);
122 /* Error in case of inability in writing to stream */
130 rte_bus_dump(FILE *f)
135 TAILQ_FOREACH(bus, &rte_bus_list, next) {
136 ret = bus_dump_one(f, bus);
138 RTE_LOG(ERR, EAL, "Unable to write to stream (%d)\n",
146 rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
149 struct rte_bus *bus = NULL;
151 TAILQ_FOREACH(bus, &rte_bus_list, next) {
152 if (start && bus == start) {
153 start = NULL; /* starting point found */
156 if (cmp(bus, data) == 0)
163 cmp_rte_device(const struct rte_device *dev1, const void *_dev2)
165 const struct rte_device *dev2 = _dev2;
171 bus_find_device(const struct rte_bus *bus, const void *_dev)
173 struct rte_device *dev;
175 dev = bus->find_device(NULL, cmp_rte_device, _dev);
180 rte_bus_find_by_device(const struct rte_device *dev)
182 return rte_bus_find(NULL, bus_find_device, (const void *)dev);
186 cmp_bus_name(const struct rte_bus *bus, const void *_name)
188 const char *name = _name;
190 return strcmp(bus->name, name);
194 rte_bus_find_by_name(const char *busname)
196 return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
200 bus_can_parse(const struct rte_bus *bus, const void *_name)
202 const char *name = _name;
204 return !(bus->parse && bus->parse(name, NULL) == 0);
208 rte_bus_find_by_device_name(const char *str)
210 char name[RTE_DEV_NAME_MAX_LEN];
213 snprintf(name, sizeof(name), "%s", str);
214 c = strchr(name, ',');
217 return rte_bus_find(NULL, bus_can_parse, name);
222 * Get iommu class of devices on the bus.
225 rte_bus_get_iommu_class(void)
227 int mode = RTE_IOVA_DC;
230 TAILQ_FOREACH(bus, &rte_bus_list, next) {
232 if (bus->get_iommu_class)
233 mode |= bus->get_iommu_class();
236 if (mode != RTE_IOVA_VA) {
237 /* Use default IOVA mode */