4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Copyright(c) 2013 6WIND.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name of 6WIND S.A. nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 #include <sys/queue.h>
71 #include <rte_interrupts.h>
74 #include <rte_per_lcore.h>
75 #include <rte_memory.h>
76 #include <rte_memzone.h>
77 #include <rte_tailq.h>
79 #include <rte_string_fns.h>
80 #include <rte_common.h>
81 #include <rte_devargs.h>
83 #include "eal_private.h"
85 struct pci_driver_list pci_driver_list;
86 struct pci_device_list pci_device_list;
88 static int is_blacklisted(struct rte_pci_device *dev)
90 struct rte_devargs *devargs;
92 TAILQ_FOREACH(devargs, &devargs_list, next) {
93 if (devargs->type != RTE_DEVTYPE_BLACKLISTED_PCI)
95 if (!memcmp(&dev->addr, &devargs->pci.addr, sizeof(dev->addr)))
98 return 0; /* not in blacklist */
102 * If vendor/device ID match, call the devinit() function of all
103 * registered driver for the given device. Return -1 if no driver is
104 * found for this device.
105 * For drivers with the RTE_PCI_DRV_MULTIPLE flag enabled, register
106 * the same device multiple times until failure to do so.
107 * It is required for non-Intel NIC drivers provided by third-parties such
111 pci_probe_all_drivers(struct rte_pci_device *dev)
113 struct rte_pci_driver *dr = NULL;
116 dev->blacklisted = !!is_blacklisted(dev);
117 TAILQ_FOREACH(dr, &pci_driver_list, next) {
118 rc = rte_eal_pci_probe_one_driver(dr, dev);
120 /* negative value is an error */
123 /* positive value means driver not found */
125 /* initialize subsequent driver instances for this device */
126 if ((dr->drv_flags & RTE_PCI_DRV_MULTIPLE) &&
128 while (rte_eal_pci_probe_one_driver(dr, dev) == 0)
136 * Check if a device is ok to use according to whitelist rules.
139 pcidev_is_whitelisted(struct rte_pci_device *dev)
141 struct rte_devargs *devargs;
143 TAILQ_FOREACH(devargs, &devargs_list, next) {
144 if (devargs->type != RTE_DEVTYPE_WHITELISTED_PCI)
146 if (!memcmp(&dev->addr, &devargs->pci.addr, sizeof(dev->addr)))
153 * Scan the content of the PCI bus, and call the devinit() function for
154 * all registered drivers that have a matching entry in its id_table
155 * for discovered devices.
158 rte_eal_pci_probe(void)
160 struct rte_pci_device *dev = NULL;
163 if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0)
166 TAILQ_FOREACH(dev, &pci_device_list, next) {
168 pci_probe_all_drivers(dev);
169 else if (pcidev_is_whitelisted(dev) && pci_probe_all_drivers(dev) < 0)
170 rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT
171 " cannot be used\n", dev->addr.domain, dev->addr.bus,
172 dev->addr.devid, dev->addr.function);
178 /* dump one device */
180 pci_dump_one_device(struct rte_pci_device *dev)
184 printf(PCI_PRI_FMT, dev->addr.domain, dev->addr.bus,
185 dev->addr.devid, dev->addr.function);
186 printf(" - vendor:%x device:%x\n", dev->id.vendor_id,
189 for (i = 0; i != sizeof(dev->mem_resource) /
190 sizeof(dev->mem_resource[0]); i++) {
191 printf(" %16.16"PRIx64" %16.16"PRIx64"\n",
192 dev->mem_resource[i].phys_addr,
193 dev->mem_resource[i].len);
198 /* dump devices on the bus */
200 rte_eal_pci_dump(void)
202 struct rte_pci_device *dev = NULL;
204 TAILQ_FOREACH(dev, &pci_device_list, next) {
205 pci_dump_one_device(dev);
209 /* register a driver */
211 rte_eal_pci_register(struct rte_pci_driver *driver)
213 TAILQ_INSERT_TAIL(&pci_driver_list, driver, next);
216 /* unregister a driver */
218 rte_eal_pci_unregister(struct rte_pci_driver *driver)
220 TAILQ_REMOVE(&pci_driver_list, driver, next);