pci: add bus driver
[dpdk.git] / lib / librte_eal / common / eal_private.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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 #ifndef _EAL_PRIVATE_H_
35 #define _EAL_PRIVATE_H_
36
37 #include <stdbool.h>
38 #include <stdio.h>
39 #include <rte_pci.h>
40
41 /**
42  * Initialize the memzone subsystem (private to eal).
43  *
44  * @return
45  *   - 0 on success
46  *   - Negative on error
47  */
48 int rte_eal_memzone_init(void);
49
50 /**
51  * Common log initialization function (private to eal).  Determines
52  * where log data is written when no call to rte_openlog_stream is
53  * in effect.
54  *
55  * @param default_log
56  *   The default log stream to be used.
57  * @return
58  *   - 0 on success
59  *   - Negative on error
60  */
61 void eal_log_set_default(FILE *default_log);
62
63 /**
64  * Fill configuration with number of physical and logical processors
65  *
66  * This function is private to EAL.
67  *
68  * Parse /proc/cpuinfo to get the number of physical and logical
69  * processors on the machine.
70  *
71  * @return
72  *   0 on success, negative on error
73  */
74 int rte_eal_cpu_init(void);
75
76 /**
77  * Map memory
78  *
79  * This function is private to EAL.
80  *
81  * Fill configuration structure with these infos, and return 0 on success.
82  *
83  * @return
84  *   0 on success, negative on error
85  */
86 int rte_eal_memory_init(void);
87
88 /**
89  * Configure timers
90  *
91  * This function is private to EAL.
92  *
93  * Mmap memory areas used by HPET (high precision event timer) that will
94  * provide our time reference, and configure the TSC frequency also for it
95  * to be used as a reference.
96  *
97  * @return
98  *   0 on success, negative on error
99  */
100 int rte_eal_timer_init(void);
101
102 /**
103  * Init the default log stream
104  *
105  * This function is private to EAL.
106  *
107  * @return
108  *   0 on success, negative on error
109  */
110 int rte_eal_log_init(const char *id, int facility);
111
112 /**
113  * Init the PCI infrastructure
114  *
115  * This function is private to EAL.
116  *
117  * @return
118  *   0 on success, negative on error
119  */
120 int rte_eal_pci_init(void);
121
122 struct rte_pci_driver;
123 struct rte_pci_device;
124
125 /**
126  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
127  * also updates the bus references of the PCI Device (and the generic device
128  * object embedded within.
129  *
130  * @param pci_dev
131  *      PCI device to add
132  * @return void
133  */
134 void rte_eal_pci_add_device(struct rte_pci_device *pci_dev);
135
136 /**
137  * Insert a PCI device in the PCI Bus at a particular location in the device
138  * list. It also updates the PCI Bus reference of the new devices to be
139  * inserted.
140  *
141  * @param exist_pci_dev
142  *      Existing PCI device in PCI Bus
143  * @param new_pci_dev
144  *      PCI device to be added before exist_pci_dev
145  * @return void
146  */
147 void rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
148                                struct rte_pci_device *new_pci_dev);
149
150 /**
151  * Remove a PCI device from the PCI Bus. This sets to NULL the bus references
152  * in the PCI device object as well as the generic device object.
153  *
154  * @param pci_device
155  *      PCI device to be removed from PCI Bus
156  * @return void
157  */
158 void rte_eal_pci_remove_device(struct rte_pci_device *pci_device);
159
160 /**
161  * Update a pci device object by asking the kernel for the latest information.
162  *
163  * This function is private to EAL.
164  *
165  * @param addr
166  *      The PCI Bus-Device-Function address to look for
167  * @return
168  *   - 0 on success.
169  *   - negative on error.
170  */
171 int pci_update_device(const struct rte_pci_addr *addr);
172
173 /**
174  * Unbind kernel driver for this device
175  *
176  * This function is private to EAL.
177  *
178  * @return
179  *   0 on success, negative on error
180  */
181 int pci_unbind_kernel_driver(struct rte_pci_device *dev);
182
183 /**
184  * Map the PCI resource of a PCI device in virtual memory
185  *
186  * This function is private to EAL.
187  *
188  * @return
189  *   0 on success, negative on error
190  */
191 int pci_uio_map_resource(struct rte_pci_device *dev);
192
193 /**
194  * Unmap the PCI resource of a PCI device
195  *
196  * This function is private to EAL.
197  */
198 void pci_uio_unmap_resource(struct rte_pci_device *dev);
199
200 /**
201  * Allocate uio resource for PCI device
202  *
203  * This function is private to EAL.
204  *
205  * @param dev
206  *   PCI device to allocate uio resource
207  * @param uio_res
208  *   Pointer to uio resource.
209  *   If the function returns 0, the pointer will be filled.
210  * @return
211  *   0 on success, negative on error
212  */
213 int pci_uio_alloc_resource(struct rte_pci_device *dev,
214                 struct mapped_pci_resource **uio_res);
215
216 /**
217  * Free uio resource for PCI device
218  *
219  * This function is private to EAL.
220  *
221  * @param dev
222  *   PCI device to free uio resource
223  * @param uio_res
224  *   Pointer to uio resource.
225  */
226 void pci_uio_free_resource(struct rte_pci_device *dev,
227                 struct mapped_pci_resource *uio_res);
228
229 /**
230  * Map device memory to uio resource
231  *
232  * This function is private to EAL.
233  *
234  * @param dev
235  *   PCI device that has memory information.
236  * @param res_idx
237  *   Memory resource index of the PCI device.
238  * @param uio_res
239  *  uio resource that will keep mapping information.
240  * @param map_idx
241  *   Mapping information index of the uio resource.
242  * @return
243  *   0 on success, negative on error
244  */
245 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
246                 struct mapped_pci_resource *uio_res, int map_idx);
247
248 /**
249  * Init tail queues for non-EAL library structures. This is to allow
250  * the rings, mempools, etc. lists to be shared among multiple processes
251  *
252  * This function is private to EAL
253  *
254  * @return
255  *    0 on success, negative on error
256  */
257 int rte_eal_tailqs_init(void);
258
259 /**
260  * Init interrupt handling.
261  *
262  * This function is private to EAL.
263  *
264  * @return
265  *  0 on success, negative on error
266  */
267 int rte_eal_intr_init(void);
268
269 /**
270  * Init alarm mechanism. This is to allow a callback be called after
271  * specific time.
272  *
273  * This function is private to EAL.
274  *
275  * @return
276  *  0 on success, negative on error
277  */
278 int rte_eal_alarm_init(void);
279
280 /**
281  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
282  * etc.) loaded.
283  *
284  * @param module_name
285  *      The module's name which need to be checked
286  *
287  * @return
288  *      -1 means some error happens(NULL pointer or open failure)
289  *      0  means the module not loaded
290  *      1  means the module loaded
291  */
292 int rte_eal_check_module(const char *module_name);
293
294 /**
295  * Get cpu core_id.
296  *
297  * This function is private to the EAL.
298  */
299 unsigned eal_cpu_core_id(unsigned lcore_id);
300
301 /**
302  * Check if cpu is present.
303  *
304  * This function is private to the EAL.
305  */
306 int eal_cpu_detected(unsigned lcore_id);
307
308 /**
309  * Set TSC frequency from precise value or estimation
310  *
311  * This function is private to the EAL.
312  */
313 void set_tsc_freq(void);
314
315 /**
316  * Get precise TSC frequency from system
317  *
318  * This function is private to the EAL.
319  */
320 uint64_t get_tsc_freq(void);
321
322 /**
323  * Prepare physical memory mapping
324  * i.e. hugepages on Linux and
325  *      contigmem on BSD.
326  *
327  * This function is private to the EAL.
328  */
329 int rte_eal_hugepage_init(void);
330
331 /**
332  * Creates memory mapping in secondary process
333  * i.e. hugepages on Linux and
334  *      contigmem on BSD.
335  *
336  * This function is private to the EAL.
337  */
338 int rte_eal_hugepage_attach(void);
339
340 /**
341  * Returns true if the system is able to obtain
342  * physical addresses. Return false if using DMA
343  * addresses through an IOMMU.
344  *
345  * Drivers based on uio will not load unless physical
346  * addresses are obtainable. It is only possible to get
347  * physical addresses when running as a privileged user.
348  */
349 bool rte_eal_using_phys_addrs(void);
350
351 #endif /* _EAL_PRIVATE_H_ */