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>
38 #include <rte_debug.h>
40 #include "eal_private.h"
42 struct rte_bus_list rte_bus_list =
43 TAILQ_HEAD_INITIALIZER(rte_bus_list);
46 rte_bus_register(struct rte_bus *bus)
49 RTE_VERIFY(bus->name && strlen(bus->name));
50 /* A bus should mandatorily have the scan implemented */
51 RTE_VERIFY(bus->scan);
52 RTE_VERIFY(bus->probe);
53 RTE_VERIFY(bus->find_device);
54 /* Buses supporting driver plug also require unplug. */
55 RTE_VERIFY(!bus->plug || bus->unplug);
57 TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
58 RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name);
62 rte_bus_unregister(struct rte_bus *bus)
64 TAILQ_REMOVE(&rte_bus_list, bus, next);
65 RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", bus->name);
68 /* Scan all the buses for registered devices */
73 struct rte_bus *bus = NULL;
75 TAILQ_FOREACH(bus, &rte_bus_list, next) {
78 RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n",
85 /* Probe all devices of all buses */
90 struct rte_bus *bus, *vbus = NULL;
92 TAILQ_FOREACH(bus, &rte_bus_list, next) {
93 if (!strcmp(bus->name, "vdev")) {
100 RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
107 RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
114 /* Dump information of a single bus */
116 bus_dump_one(FILE *f, struct rte_bus *bus)
120 /* For now, dump only the bus name */
121 ret = fprintf(f, " %s\n", bus->name);
123 /* Error in case of inability in writing to stream */
131 rte_bus_dump(FILE *f)
136 TAILQ_FOREACH(bus, &rte_bus_list, next) {
137 ret = bus_dump_one(f, bus);
139 RTE_LOG(ERR, EAL, "Unable to write to stream (%d)\n",
147 rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,
153 bus = TAILQ_NEXT(start, next);
155 bus = TAILQ_FIRST(&rte_bus_list);
156 while (bus != NULL) {
157 if (cmp(bus, data) == 0)
159 bus = TAILQ_NEXT(bus, next);
165 cmp_rte_device(const struct rte_device *dev1, const void *_dev2)
167 const struct rte_device *dev2 = _dev2;
173 bus_find_device(const struct rte_bus *bus, const void *_dev)
175 struct rte_device *dev;
177 dev = bus->find_device(NULL, cmp_rte_device, _dev);
182 rte_bus_find_by_device(const struct rte_device *dev)
184 return rte_bus_find(NULL, bus_find_device, (const void *)dev);
188 cmp_bus_name(const struct rte_bus *bus, const void *_name)
190 const char *name = _name;
192 return strcmp(bus->name, name);
196 rte_bus_find_by_name(const char *busname)
198 return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
202 bus_can_parse(const struct rte_bus *bus, const void *_name)
204 const char *name = _name;
206 return !(bus->parse && bus->parse(name, NULL) == 0);
210 rte_bus_find_by_device_name(const char *str)
212 char name[RTE_DEV_NAME_MAX_LEN];
215 snprintf(name, sizeof(name), "%s", str);
216 c = strchr(name, ',');
219 return rte_bus_find(NULL, bus_can_parse, name);
224 * Get iommu class of devices on the bus.
227 rte_bus_get_iommu_class(void)
229 int mode = RTE_IOVA_DC;
232 TAILQ_FOREACH(bus, &rte_bus_list, next) {
234 if (bus->get_iommu_class)
235 mode |= bus->get_iommu_class();
238 if (mode != RTE_IOVA_VA) {
239 /* Use default IOVA mode */