pci: make it possible to keep devices bound to uio
[dpdk.git] / lib / librte_eal / common / include / rte_pci.h
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 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  */
34
35 #ifndef _RTE_PCI_H_
36 #define _RTE_PCI_H_
37
38 /**
39  * @file
40  *
41  * RTE PCI Interface
42  */
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #include <limits.h>
49 #include <sys/queue.h>
50 #include <stdint.h>
51 #include <inttypes.h>
52 #include <rte_interrupts.h>
53
54 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
55 TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
56
57 extern struct pci_driver_list driver_list; /**< Global list of PCI drivers. */
58 extern struct pci_device_list device_list; /**< Global list of PCI devices. */
59
60 /** Pathname of PCI devices directory. */
61 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
62
63 /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */
64 #define PCI_PRI_FMT "%.4"PRIx16":%.2"PRIx8":%.2"PRIx8".%"PRIx8
65
66 /** Nb. of values in PCI device identifier format string. */
67 #define PCI_FMT_NVAL 4
68
69 /** Nb. of values in PCI resource format. */
70 #define PCI_RESOURCE_FMT_NVAL 3
71
72 /**
73  * A structure describing a PCI resource.
74  */
75 struct rte_pci_resource {
76         uint64_t phys_addr;   /**< Physical address, 0 if no resource. */
77         uint64_t len;         /**< Length of the resource. */
78         void *addr;           /**< Virtual address, NULL when not mapped. */
79 };
80
81 /** Maximum number of PCI resources. */
82 #define PCI_MAX_RESOURCE 7
83
84 /**
85  * A structure describing an ID for a PCI driver. Each driver provides a
86  * table of these IDs for each device that it supports.
87  */
88 struct rte_pci_id {
89         uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
90         uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
91         uint16_t subsystem_vendor_id; /**< Subsystem vendor ID or PCI_ANY_ID. */
92         uint16_t subsystem_device_id; /**< Subsystem device ID or PCI_ANY_ID. */
93 };
94
95 /**
96  * A structure describing the location of a PCI device.
97  */
98 struct rte_pci_addr {
99         uint16_t domain;                /**< Device domain */
100         uint8_t bus;                    /**< Device bus */
101         uint8_t devid;                  /**< Device ID */
102         uint8_t function;               /**< Device function. */
103 };
104
105 /**
106  * A structure describing a PCI device.
107  */
108 struct rte_pci_device {
109         TAILQ_ENTRY(rte_pci_device) next;       /**< Next probed PCI device. */
110         struct rte_pci_addr addr;               /**< PCI location. */
111         struct rte_pci_id id;                   /**< PCI ID. */
112         struct rte_pci_resource mem_resource;   /**< PCI Memory Resource */
113         struct rte_intr_handle intr_handle;     /**< Interrupt handle */
114         char previous_dr[PATH_MAX];             /**< path for pre-dpdk driver*/
115         const struct rte_pci_driver *driver;    /**< Associated driver */
116         unsigned int blacklisted:1;             /**< Device is blacklisted */
117 };
118
119 /** Any PCI device identifier (vendor, device, ...) */
120 #define PCI_ANY_ID (0xffff)
121
122 #ifdef __cplusplus
123 /** C++ macro used to help building up tables of device IDs */
124 #define RTE_PCI_DEVICE(vend, dev) \
125         (vend),                   \
126         (dev),                    \
127         PCI_ANY_ID,               \
128         PCI_ANY_ID
129 #else
130 /** Macro used to help building up tables of device IDs */
131 #define RTE_PCI_DEVICE(vend, dev)          \
132         .vendor_id = (vend),               \
133         .device_id = (dev),                \
134         .subsystem_vendor_id = PCI_ANY_ID, \
135         .subsystem_device_id = PCI_ANY_ID
136 #endif
137
138 struct rte_pci_driver;
139
140 /**
141  * Initialisation function for the driver called during PCI probing.
142  */
143 typedef int (pci_devinit_t)(struct rte_pci_driver *, struct rte_pci_device *);
144
145 /**
146  * A structure describing a PCI driver.
147  */
148 struct rte_pci_driver {
149         TAILQ_ENTRY(rte_pci_driver) next;       /**< Next in list. */
150         const char *name;                       /**< Driver name. */
151         pci_devinit_t *devinit;                 /**< Device init. function. */
152         struct rte_pci_id *id_table;            /**< ID table, NULL terminated. */
153         uint32_t drv_flags;                     /**< Flags contolling handling of device. */
154 };
155
156 /**< Device needs igb_uio kernel module */
157 #define RTE_PCI_DRV_NEED_IGB_UIO 0x0001
158
159 /**
160  * Perform clean up of pci drivers on application exits.
161  * */
162 void rte_eal_pci_exit(void);
163
164 /**
165  * Probe the PCI bus for registered drivers.
166  *
167  * Scan the content of the PCI bus, and call the probe() function for
168  * all registered drivers that have a matching entry in its id_table
169  * for discovered devices.
170  *
171  * @return
172  *   - 0 on success.
173  *   - Negative on error.
174  */
175 int rte_eal_pci_probe(void);
176
177 /**
178  * Dump the content of the PCI bus.
179  */
180 void rte_eal_pci_dump(void);
181
182 /**
183  * Register a PCI driver.
184  *
185  * @param driver
186  *   A pointer to a rte_pci_driver structure describing the driver
187  *   to be registered.
188  */
189 void rte_eal_pci_register(struct rte_pci_driver *driver);
190
191 /**
192  * Register a list of PCI locations that will be blacklisted (not used by DPDK).
193  *
194  * @param blacklist
195  *   List of PCI device addresses that will not be used by DPDK.
196  * @param size
197  *   Number of items in the list.
198  */
199 void rte_eal_pci_set_blacklist(struct rte_pci_addr *blacklist, unsigned size);
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif /* _RTE_PCI_H_ */