4 * Copyright 2014 6WIND S.A.
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 6WIND S.A nor the names of its contributors
17 * may be used to endorse or promote products derived from this
18 * 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.
33 /* This file manages the list of devices and their arguments, as given
34 * by the user at startup
36 * Code here should not call rte_log since the EAL environment
37 * may not be initialized.
43 #include <rte_devargs.h>
44 #include "eal_private.h"
46 /** Global list of user devices */
47 struct rte_devargs_list devargs_list =
48 TAILQ_HEAD_INITIALIZER(devargs_list);
51 rte_eal_parse_devargs_str(const char *devargs_str,
52 char **drvname, char **drvargs)
56 if ((devargs_str) == NULL || (drvname) == NULL || (drvargs == NULL))
59 *drvname = strdup(devargs_str);
63 /* set the first ',' to '\0' to split name and arguments */
64 sep = strchr(*drvname, ',');
67 *drvargs = strdup(sep + 1);
69 *drvargs = strdup("");
72 if (*drvargs == NULL) {
81 bus_name_cmp(const struct rte_bus *bus, const void *name)
83 return strncmp(bus->name, name, strlen(bus->name));
86 /* store a whitelist parameter for later parsing */
88 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
90 struct rte_devargs *devargs = NULL;
91 struct rte_bus *bus = NULL;
96 /* use malloc instead of rte_malloc as it's called early at init */
97 devargs = malloc(sizeof(*devargs));
101 memset(devargs, 0, sizeof(*devargs));
102 devargs->type = devtype;
104 if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
108 bus = rte_bus_find(bus, bus_name_cmp, dev);
111 devname = dev + strlen(bus->name) + 1;
112 if (rte_bus_find_by_device_name(devname) == bus)
117 bus = rte_bus_find_by_device_name(devname);
119 fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
125 /* save device name. */
126 ret = snprintf(devargs->name, sizeof(devargs->name), "%s", devname);
127 if (ret < 0 || ret >= (int)sizeof(devargs->name))
129 if (devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) {
130 if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED) {
131 bus->conf.scan_mode = RTE_BUS_SCAN_WHITELIST;
132 } else if (bus->conf.scan_mode == RTE_BUS_SCAN_BLACKLIST) {
133 fprintf(stderr, "ERROR: incompatible device type and bus scan mode\n");
136 } else if (devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
137 if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED) {
138 bus->conf.scan_mode = RTE_BUS_SCAN_BLACKLIST;
139 } else if (bus->conf.scan_mode == RTE_BUS_SCAN_WHITELIST) {
140 fprintf(stderr, "ERROR: incompatible device type and bus scan mode\n");
146 TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
159 /* count the number of devices of a specified type */
161 rte_eal_devargs_type_count(enum rte_devtype devtype)
163 struct rte_devargs *devargs;
164 unsigned int count = 0;
166 TAILQ_FOREACH(devargs, &devargs_list, next) {
167 if (devargs->type != devtype)
174 /* dump the user devices on the console */
176 rte_eal_devargs_dump(FILE *f)
178 struct rte_devargs *devargs;
180 fprintf(f, "User device list:\n");
181 TAILQ_FOREACH(devargs, &devargs_list, next) {
182 fprintf(f, " [%s]: %s %s\n",
183 (devargs->bus ? devargs->bus->name : "??"),
184 devargs->name, devargs->args);