doc: whitespace changes in licenses
[dpdk.git] / lib / librte_eal / common / include / rte_pci.h
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  * 
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
16  *       distribution.
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.
20  * 
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.
32  */
33 /*   BSD LICENSE
34  *
35  *   Copyright(c) 2013 6WIND.
36  *
37  *   Redistribution and use in source and binary forms, with or without
38  *   modification, are permitted provided that the following conditions
39  *   are met:
40  *
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
46  *       distribution.
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.
50  *
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.
62  */
63
64 #ifndef _RTE_PCI_H_
65 #define _RTE_PCI_H_
66
67 /**
68  * @file
69  *
70  * RTE PCI Interface
71  */
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76
77 #include <limits.h>
78 #include <sys/queue.h>
79 #include <stdint.h>
80 #include <inttypes.h>
81 #include <rte_interrupts.h>
82
83 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
84 TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
85
86 extern struct pci_driver_list driver_list; /**< Global list of PCI drivers. */
87 extern struct pci_device_list device_list; /**< Global list of PCI devices. */
88
89 /** Pathname of PCI devices directory. */
90 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
91
92 /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
93 #define PCI_PRI_FMT "%.4"PRIx16":%.2"PRIx8":%.2"PRIx8".%"PRIx8
94
95 /** Nb. of values in PCI device identifier format string. */
96 #define PCI_FMT_NVAL 4
97
98 /** Nb. of values in PCI resource format. */
99 #define PCI_RESOURCE_FMT_NVAL 3
100
101 /**
102  * A structure describing a PCI resource.
103  */
104 struct rte_pci_resource {
105         uint64_t phys_addr;   /**< Physical address, 0 if no resource. */
106         uint64_t len;         /**< Length of the resource. */
107         void *addr;           /**< Virtual address, NULL when not mapped. */
108 };
109
110 /** Maximum number of PCI resources. */
111 #define PCI_MAX_RESOURCE 7
112
113 /**
114  * A structure describing an ID for a PCI driver. Each driver provides a
115  * table of these IDs for each device that it supports.
116  */
117 struct rte_pci_id {
118         uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
119         uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
120         uint16_t subsystem_vendor_id; /**< Subsystem vendor ID or PCI_ANY_ID. */
121         uint16_t subsystem_device_id; /**< Subsystem device ID or PCI_ANY_ID. */
122 };
123
124 /**
125  * A structure describing the location of a PCI device.
126  */
127 struct rte_pci_addr {
128         uint16_t domain;                /**< Device domain */
129         uint8_t bus;                    /**< Device bus */
130         uint8_t devid;                  /**< Device ID */
131         uint8_t function;               /**< Device function. */
132 };
133
134 /**
135  * A structure describing a PCI device.
136  */
137 struct rte_pci_device {
138         TAILQ_ENTRY(rte_pci_device) next;       /**< Next probed PCI device. */
139         struct rte_pci_addr addr;               /**< PCI location. */
140         struct rte_pci_id id;                   /**< PCI ID. */
141         struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE];   /**< PCI Memory Resource */
142         struct rte_intr_handle intr_handle;     /**< Interrupt handle */
143         const struct rte_pci_driver *driver;    /**< Associated driver */
144         uint16_t max_vfs;                       /**< sriov enable if not zero */
145         int numa_node;                          /**< NUMA node connection */
146         unsigned int blacklisted:1;             /**< Device is blacklisted */
147 };
148
149 /** Any PCI device identifier (vendor, device, ...) */
150 #define PCI_ANY_ID (0xffff)
151
152 #ifdef __cplusplus
153 /** C++ macro used to help building up tables of device IDs */
154 #define RTE_PCI_DEVICE(vend, dev) \
155         (vend),                   \
156         (dev),                    \
157         PCI_ANY_ID,               \
158         PCI_ANY_ID
159 #else
160 /** Macro used to help building up tables of device IDs */
161 #define RTE_PCI_DEVICE(vend, dev)          \
162         .vendor_id = (vend),               \
163         .device_id = (dev),                \
164         .subsystem_vendor_id = PCI_ANY_ID, \
165         .subsystem_device_id = PCI_ANY_ID
166 #endif
167
168 struct rte_pci_driver;
169
170 /**
171  * Initialisation function for the driver called during PCI probing.
172  */
173 typedef int (pci_devinit_t)(struct rte_pci_driver *, struct rte_pci_device *);
174
175 /**
176  * A structure describing a PCI driver.
177  */
178 struct rte_pci_driver {
179         TAILQ_ENTRY(rte_pci_driver) next;       /**< Next in list. */
180         const char *name;                       /**< Driver name. */
181         pci_devinit_t *devinit;                 /**< Device init. function. */
182         struct rte_pci_id *id_table;            /**< ID table, NULL terminated. */
183         uint32_t drv_flags;                     /**< Flags contolling handling of device. */
184 };
185
186 #ifdef RTE_EAL_UNBIND_PORTS
187 /** Device needs igb_uio kernel module */
188 #define RTE_PCI_DRV_NEED_IGB_UIO 0x0001
189 #endif
190 /** Device driver must be registered several times until failure */
191 #define RTE_PCI_DRV_MULTIPLE 0x0002
192
193 /**
194  * Probe the PCI bus for registered drivers.
195  *
196  * Scan the content of the PCI bus, and call the probe() function for
197  * all registered drivers that have a matching entry in its id_table
198  * for discovered devices.
199  *
200  * @return
201  *   - 0 on success.
202  *   - Negative on error.
203  */
204 int rte_eal_pci_probe(void);
205
206 /**
207  * Dump the content of the PCI bus.
208  */
209 void rte_eal_pci_dump(void);
210
211 /**
212  * Register a PCI driver.
213  *
214  * @param driver
215  *   A pointer to a rte_pci_driver structure describing the driver
216  *   to be registered.
217  */
218 void rte_eal_pci_register(struct rte_pci_driver *driver);
219
220 /**
221  * Unregister a PCI driver.
222  *
223  * @param driver
224  *   A pointer to a rte_pci_driver structure describing the driver
225  *   to be unregistered.
226  */
227 void rte_eal_pci_unregister(struct rte_pci_driver *driver);
228
229 /**
230  * Register a list of PCI locations that will be blacklisted (not used by DPDK).
231  *
232  * @param blacklist
233  *   List of PCI device addresses that will not be used by DPDK.
234  * @param size
235  *   Number of items in the list.
236  */
237 void rte_eal_pci_set_blacklist(struct rte_pci_addr *blacklist, unsigned size);
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif /* _RTE_PCI_H_ */