1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2014 6WIND S.A.
5 #ifndef _RTE_DEVARGS_H_
6 #define _RTE_DEVARGS_H_
11 * RTE devargs: list of devices and their user arguments
13 * This file stores a list of devices and their arguments given by
14 * the user when a DPDK application is started. These devices can be PCI
15 * devices or virtual devices. These devices are stored at startup in a
16 * list of rte_devargs structures.
24 #include <sys/queue.h>
25 #include <rte_compat.h>
29 * Bus type key in global devargs syntax.
31 * Legacy devargs parser doesn't use this key as bus type
32 * is resolved as first optional value separated by ":".
34 #define RTE_DEVARGS_KEY_BUS "bus"
37 * Class type key in global devargs syntax.
39 * Legacy devargs parser doesn't parse class type. PMD driver is
40 * encouraged to use this key to resolve class type.
42 #define RTE_DEVARGS_KEY_CLASS "class"
45 * Driver type key in global devargs syntax.
47 * Legacy devargs parser doesn't parse driver type. PMD driver is
48 * encouraged to use this key to resolve driver type.
50 #define RTE_DEVARGS_KEY_DRIVER "driver"
53 * Type of generic device
62 * Structure that stores a device given by the user with its arguments
64 * A user device is a physical or a virtual device given by the user to
65 * the DPDK application at startup through command line arguments.
67 * The structure stores the configuration of the device, its PCI
68 * identifier if it's a PCI device or the driver name if it's a virtual
73 TAILQ_ENTRY(rte_devargs) next;
74 /** Type of device. */
75 enum rte_devtype type;
77 enum rte_dev_policy policy;
78 /** Name of the device. */
79 char name[RTE_DEV_NAME_MAX_LEN];
82 const char *args; /**< legacy name. */
83 const char *drv_str; /**< driver-related part of device string. */
85 struct rte_bus *bus; /**< bus handle. */
86 struct rte_class *cls; /**< class handle. */
87 const char *bus_str; /**< bus-related part of device string. */
88 const char *cls_str; /**< class-related part of device string. */
89 char *data; /**< raw string including bus, class and driver parts. */
93 * Parse a device string.
95 * Verify that a bus is capable of handling the device passed
96 * in argument. Store which bus will handle the device, its name
97 * and the eventual device parameters.
101 * bus:device_identifier,arg1=val1,arg2=val2
103 * where "bus:" is the bus name followed by any character separator.
104 * The bus name is optional. If no bus name is specified, each bus
105 * will attempt to recognize the device identifier. The first one
106 * to succeed will be used.
110 * pci:0000:05.00.0,arg=val
115 * The devargs structure holding the device information.
118 * String describing a device.
122 * - Negative errno on error.
125 rte_devargs_parse(struct rte_devargs *da, const char *dev);
128 * Parse a device string.
130 * Verify that a bus is capable of handling the device passed
131 * in argument. Store which bus will handle the device, its name
132 * and the eventual device parameters.
134 * The device string is built with a printf-like syntax.
138 * bus:device_identifier,arg1=val1,arg2=val2
140 * where "bus:" is the bus name followed by any character separator.
141 * The bus name is optional. If no bus name is specified, each bus
142 * will attempt to recognize the device identifier. The first one
143 * to succeed will be used.
147 * pci:0000:05.00.0,arg=val
152 * The devargs structure holding the device information.
154 * Format string describing a device.
158 * - Negative errno on error.
161 rte_devargs_parsef(struct rte_devargs *da,
162 const char *format, ...)
163 __rte_format_printf(2, 0);
166 * Free resources in devargs.
169 * The devargs structure holding the device information.
173 rte_devargs_reset(struct rte_devargs *da);
176 * Insert an rte_devargs in the global list.
179 * The devargs structure to insert.
180 * If a devargs for the same device is already inserted,
181 * it will be updated and returned. It means *da pointer can change.
185 * - Negative on error.
188 rte_devargs_insert(struct rte_devargs **da);
191 * Add a device to the user device list
192 * See rte_devargs_parse() for details.
195 * The type of the device.
197 * The arguments as given by the user.
201 * - A negative value on error
203 int rte_devargs_add(enum rte_devtype devtype, const char *devargs_str);
206 * Remove a device from the user device list.
207 * Its resources are freed.
208 * If the devargs cannot be found, nothing happens.
211 * The instance or a copy of devargs to remove.
216 * >0 if the devargs was not within the user device list.
218 int rte_devargs_remove(struct rte_devargs *devargs);
221 * Count the number of user devices of a specified type
224 * The type of the devices to counted.
227 * The number of devices.
230 rte_devargs_type_count(enum rte_devtype devtype);
233 * This function dumps the list of user device and their arguments.
236 * A pointer to a file for output
238 void rte_devargs_dump(FILE *f);
241 * Find next rte_devargs matching the provided bus name.
244 * Limit the iteration to devargs related to buses
245 * matching this name.
246 * Will return any next rte_devargs if NULL.
249 * Starting iteration point. The iteration will start at
250 * the first rte_devargs if NULL.
253 * Next rte_devargs entry matching the requested bus,
254 * NULL if there is none.
257 rte_devargs_next(const char *busname, const struct rte_devargs *start);
260 * Iterate over all rte_devargs for a specific bus.
262 #define RTE_EAL_DEVARGS_FOREACH(busname, da) \
263 for (da = rte_devargs_next(busname, NULL); \
265 da = rte_devargs_next(busname, da)) \
271 #endif /* _RTE_DEVARGS_H_ */