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 */
40 #include <rte_devargs.h>
41 #include "eal_private.h"
43 /** Global list of user devices */
44 struct rte_devargs_list devargs_list =
45 TAILQ_HEAD_INITIALIZER(devargs_list);
47 /* store a whitelist parameter for later parsing */
49 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
51 struct rte_devargs *devargs = NULL;
56 /* use malloc instead of rte_malloc as it's called early at init */
57 devargs = malloc(sizeof(*devargs));
58 if (devargs == NULL) {
59 RTE_LOG(ERR, EAL, "cannot allocate devargs\n");
62 memset(devargs, 0, sizeof(*devargs));
63 devargs->type = devtype;
65 buf = strdup(devargs_str);
67 RTE_LOG(ERR, EAL, "cannot allocate temp memory for devargs\n");
71 /* set the first ',' to '\0' to split name and arguments */
72 sep = strchr(buf, ',');
75 devargs->args = strdup(sep + 1);
77 devargs->args = strdup("");
80 if (devargs->args == NULL) {
81 RTE_LOG(ERR, EAL, "cannot allocate for devargs args\n");
85 switch (devargs->type) {
86 case RTE_DEVTYPE_WHITELISTED_PCI:
87 case RTE_DEVTYPE_BLACKLISTED_PCI:
88 /* try to parse pci identifier */
89 if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
90 eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0) {
91 RTE_LOG(ERR, EAL, "invalid PCI identifier <%s>\n", buf);
95 case RTE_DEVTYPE_VIRTUAL:
96 /* save driver name */
97 ret = snprintf(devargs->virtual.drv_name,
98 sizeof(devargs->virtual.drv_name), "%s", buf);
99 if (ret < 0 || ret >= (int)sizeof(devargs->virtual.drv_name)) {
100 RTE_LOG(ERR, EAL, "driver name too large: <%s>\n", buf);
107 TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
120 /* count the number of devices of a specified type */
122 rte_eal_devargs_type_count(enum rte_devtype devtype)
124 struct rte_devargs *devargs;
125 unsigned int count = 0;
127 TAILQ_FOREACH(devargs, &devargs_list, next) {
128 if (devargs->type != devtype)
135 /* dump the user devices on the console */
137 rte_eal_devargs_dump(FILE *f)
139 struct rte_devargs *devargs;
141 fprintf(f, "User device white list:\n");
142 TAILQ_FOREACH(devargs, &devargs_list, next) {
143 if (devargs->type == RTE_DEVTYPE_WHITELISTED_PCI)
144 fprintf(f, " PCI whitelist " PCI_PRI_FMT " %s\n",
145 devargs->pci.addr.domain,
146 devargs->pci.addr.bus,
147 devargs->pci.addr.devid,
148 devargs->pci.addr.function,
150 else if (devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI)
151 fprintf(f, " PCI blacklist " PCI_PRI_FMT " %s\n",
152 devargs->pci.addr.domain,
153 devargs->pci.addr.bus,
154 devargs->pci.addr.devid,
155 devargs->pci.addr.function,
157 else if (devargs->type == RTE_DEVTYPE_VIRTUAL)
158 fprintf(f, " VIRTUAL %s %s\n",
159 devargs->virtual.drv_name,
162 fprintf(f, " UNKNOWN %s\n", devargs->args);