devargs: add in doc
[dpdk.git] / lib / librte_eal / common / eal_common_nonpci_devs.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  * 
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  * 
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  * 
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <string.h>
36 #include <inttypes.h>
37 #include <rte_string_fns.h>
38 #ifdef RTE_LIBRTE_PMD_RING
39 #include <rte_eth_ring.h>
40 #endif
41 #ifdef RTE_LIBRTE_PMD_PCAP
42 #include <rte_eth_pcap.h>
43 #endif
44 #ifdef RTE_LIBRTE_PMD_XENVIRT
45 #include <rte_eth_xenvirt.h>
46 #endif
47 #include <rte_debug.h>
48 #include <rte_devargs.h>
49 #include "eal_private.h"
50
51 struct device_init {
52         const char *dev_prefix;
53         int (*init_fn)(const char*, const char *);
54 };
55
56 #define NUM_DEV_TYPES (sizeof(dev_types)/sizeof(dev_types[0]))
57 struct device_init dev_types[] = {
58 #ifdef RTE_LIBRTE_PMD_RING
59                 {
60                         .dev_prefix = RTE_ETH_RING_PARAM_NAME,
61                         .init_fn = rte_pmd_ring_init
62                 },
63 #endif
64 #ifdef RTE_LIBRTE_PMD_PCAP
65                 {
66                         .dev_prefix = RTE_ETH_PCAP_PARAM_NAME,
67                         .init_fn = rte_pmd_pcap_init
68                 },
69 #endif
70 #ifdef RTE_LIBRTE_PMD_XENVIRT
71                 {
72                         .dev_prefix = RTE_ETH_XENVIRT_PARAM_NAME,
73                         .init_fn = rte_pmd_xenvirt_init
74                 },
75 #endif
76                 {
77                         .dev_prefix = "-nodev-",
78                         .init_fn = NULL
79                 }
80 };
81
82 int
83 rte_eal_non_pci_ethdev_init(void)
84 {
85         struct rte_devargs *devargs;
86         uint8_t i;
87
88         /* call the init function for each virtual device */
89         TAILQ_FOREACH(devargs, &devargs_list, next) {
90
91                 if (devargs->type != RTE_DEVTYPE_VIRTUAL)
92                         continue;
93
94                 for (i = 0; i < NUM_DEV_TYPES; i++) {
95                         /* search a driver prefix in virtual device name */
96                         if (!strncmp(dev_types[i].dev_prefix,
97                                     devargs->virtual.drv_name,
98                                      sizeof(dev_types[i].dev_prefix) - 1)) {
99                                 dev_types[i].init_fn(devargs->virtual.drv_name,
100                                                      devargs->args);
101                                 break;
102                         }
103                 }
104
105                 if (i == NUM_DEV_TYPES) {
106                         rte_panic("no driver found for %s\n",
107                                   devargs->virtual.drv_name);
108                 }
109         }
110         return 0;
111 }