devargs: make devargs list private
[dpdk.git] / lib / librte_eal / common / include / rte_devargs.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2014 6WIND S.A.
3  */
4
5 #ifndef _RTE_DEVARGS_H_
6 #define _RTE_DEVARGS_H_
7
8 /**
9  * @file
10  *
11  * RTE devargs: list of devices and their user arguments
12  *
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.
17  */
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #include <stdio.h>
24 #include <sys/queue.h>
25 #include <rte_compat.h>
26 #include <rte_bus.h>
27
28 /**
29  * Type of generic device
30  */
31 enum rte_devtype {
32         RTE_DEVTYPE_WHITELISTED_PCI,
33         RTE_DEVTYPE_BLACKLISTED_PCI,
34         RTE_DEVTYPE_VIRTUAL,
35 };
36
37 /**
38  * Structure that stores a device given by the user with its arguments
39  *
40  * A user device is a physical or a virtual device given by the user to
41  * the DPDK application at startup through command line arguments.
42  *
43  * The structure stores the configuration of the device, its PCI
44  * identifier if it's a PCI device or the driver name if it's a virtual
45  * device.
46  */
47 struct rte_devargs {
48         /** Next in list. */
49         TAILQ_ENTRY(rte_devargs) next;
50         /** Type of device. */
51         enum rte_devtype type;
52         /** Device policy. */
53         enum rte_dev_policy policy;
54         /** Bus handle for the device. */
55         struct rte_bus *bus;
56         /** Name of the device. */
57         char name[RTE_DEV_NAME_MAX_LEN];
58         /** Arguments string as given by user or "" for no argument. */
59         char *args;
60 };
61
62 /**
63  * Parse a devargs string.
64  *
65  * For PCI devices, the format of arguments string is "PCI_ADDR" or
66  * "PCI_ADDR,key=val,key2=val2,...". Examples: "08:00.1", "0000:5:00.0",
67  * "04:00.0,arg=val".
68  *
69  * For virtual devices, the format of arguments string is "DRIVER_NAME*"
70  * or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring",
71  * "net_ring0", "net_pmdAnything,arg=0:arg2=1".
72  *
73  * The function parses the arguments string to get driver name and driver
74  * arguments.
75  *
76  * @param devargs_str
77  *   The arguments as given by the user.
78  * @param drvname
79  *   The pointer to the string to store parsed driver name.
80  * @param drvargs
81  *   The pointer to the string to store parsed driver arguments.
82  *
83  * @return
84  *   - 0 on success
85  *   - A negative value on error
86  */
87 int rte_eal_parse_devargs_str(const char *devargs_str,
88                                 char **drvname, char **drvargs);
89
90 /**
91  * Parse a device string.
92  *
93  * Verify that a bus is capable of handling the device passed
94  * in argument. Store which bus will handle the device, its name
95  * and the eventual device parameters.
96  *
97  * @param dev
98  *   The device declaration string.
99  * @param da
100  *   The devargs structure holding the device information.
101  *
102  * @return
103  *   - 0 on success.
104  *   - Negative errno on error.
105  */
106 int __rte_experimental
107 rte_eal_devargs_parse(const char *dev,
108                       struct rte_devargs *da);
109
110 /**
111  * Insert an rte_devargs in the global list.
112  *
113  * @param da
114  *  The devargs structure to insert.
115  *
116  * @return
117  *   - 0 on success
118  *   - Negative on error.
119  */
120 int __rte_experimental
121 rte_eal_devargs_insert(struct rte_devargs *da);
122
123 /**
124  * Add a device to the user device list
125  *
126  * For PCI devices, the format of arguments string is "PCI_ADDR" or
127  * "PCI_ADDR,key=val,key2=val2,...". Examples: "08:00.1", "0000:5:00.0",
128  * "04:00.0,arg=val".
129  *
130  * For virtual devices, the format of arguments string is "DRIVER_NAME*"
131  * or "DRIVER_NAME*,key=val,key2=val2,...". Examples: "net_ring",
132  * "net_ring0", "net_pmdAnything,arg=0:arg2=1". The validity of the
133  * driver name is not checked by this function, it is done when probing
134  * the drivers.
135  *
136  * @param devtype
137  *   The type of the device.
138  * @param devargs_str
139  *   The arguments as given by the user.
140  *
141  * @return
142  *   - 0 on success
143  *   - A negative value on error
144  */
145 int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str);
146
147 /**
148  * Remove a device from the user device list.
149  * Its resources are freed.
150  * If the devargs cannot be found, nothing happens.
151  *
152  * @param busname
153  *   bus name of the devargs to remove.
154  *
155  * @param devname
156  *   device name of the devargs to remove.
157  *
158  * @return
159  *   0 on success.
160  *   <0 on error.
161  *   >0 if the devargs was not within the user device list.
162  */
163 int __rte_experimental rte_eal_devargs_remove(const char *busname,
164                                           const char *devname);
165
166 /**
167  * Count the number of user devices of a specified type
168  *
169  * @param devtype
170  *   The type of the devices to counted.
171  *
172  * @return
173  *   The number of devices.
174  */
175 unsigned int
176 rte_eal_devargs_type_count(enum rte_devtype devtype);
177
178 /**
179  * This function dumps the list of user device and their arguments.
180  *
181  * @param f
182  *   A pointer to a file for output
183  */
184 void rte_eal_devargs_dump(FILE *f);
185
186 /**
187  * Find next rte_devargs matching the provided bus name.
188  *
189  * @param busname
190  *   Limit the iteration to devargs related to buses
191  *   matching this name.
192  *   Will return any next rte_devargs if NULL.
193  *
194  * @param start
195  *   Starting iteration point. The iteration will start at
196  *   the first rte_devargs if NULL.
197  *
198  * @return
199  *   Next rte_devargs entry matching the requested bus,
200  *   NULL if there is none.
201  */
202 __rte_experimental
203 struct rte_devargs *
204 rte_eal_devargs_next(const char *busname, const struct rte_devargs *start);
205
206 /**
207  * Iterate over all rte_devargs for a specific bus.
208  */
209 #define RTE_EAL_DEVARGS_FOREACH(busname, da) \
210         for (da = rte_eal_devargs_next(busname, NULL); \
211              da != NULL; \
212              da = rte_eal_devargs_next(busname, da)) \
213
214 #ifdef __cplusplus
215 }
216 #endif
217
218 #endif /* _RTE_DEVARGS_H_ */