597d82e4454f1480dd44f3ff0270d006cf65a8af
[deb_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 struct rte_pci_driver;
113 struct rte_pci_device;
114
115 /**
116  * Find the name of a PCI device.
117  */
118 void pci_name_set(struct rte_pci_device *dev);
119
120 /**
121  * Add a PCI device to the PCI Bus (append to PCI Device list). This function
122  * also updates the bus references of the PCI Device (and the generic device
123  * object embedded within.
124  *
125  * @param pci_dev
126  *      PCI device to add
127  * @return void
128  */
129 void rte_pci_add_device(struct rte_pci_device *pci_dev);
130
131 /**
132  * Insert a PCI device in the PCI Bus at a particular location in the device
133  * list. It also updates the PCI Bus reference of the new devices to be
134  * inserted.
135  *
136  * @param exist_pci_dev
137  *      Existing PCI device in PCI Bus
138  * @param new_pci_dev
139  *      PCI device to be added before exist_pci_dev
140  * @return void
141  */
142 void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
143                 struct rte_pci_device *new_pci_dev);
144
145 /**
146  * Remove a PCI device from the PCI Bus. This sets to NULL the bus references
147  * in the PCI device object as well as the generic device object.
148  *
149  * @param pci_device
150  *      PCI device to be removed from PCI Bus
151  * @return void
152  */
153 void rte_pci_remove_device(struct rte_pci_device *pci_device);
154
155 /**
156  * Update a pci device object by asking the kernel for the latest information.
157  *
158  * This function is private to EAL.
159  *
160  * @param addr
161  *      The PCI Bus-Device-Function address to look for
162  * @return
163  *   - 0 on success.
164  *   - negative on error.
165  */
166 int pci_update_device(const struct rte_pci_addr *addr);
167
168 /**
169  * Unbind kernel driver for this device
170  *
171  * This function is private to EAL.
172  *
173  * @return
174  *   0 on success, negative on error
175  */
176 int pci_unbind_kernel_driver(struct rte_pci_device *dev);
177
178 /**
179  * Map the PCI resource of a PCI device in virtual memory
180  *
181  * This function is private to EAL.
182  *
183  * @return
184  *   0 on success, negative on error
185  */
186 int pci_uio_map_resource(struct rte_pci_device *dev);
187
188 /**
189  * Unmap the PCI resource of a PCI device
190  *
191  * This function is private to EAL.
192  */
193 void pci_uio_unmap_resource(struct rte_pci_device *dev);
194
195 /**
196  * Allocate uio resource for PCI device
197  *
198  * This function is private to EAL.
199  *
200  * @param dev
201  *   PCI device to allocate uio resource
202  * @param uio_res
203  *   Pointer to uio resource.
204  *   If the function returns 0, the pointer will be filled.
205  * @return
206  *   0 on success, negative on error
207  */
208 int pci_uio_alloc_resource(struct rte_pci_device *dev,
209                 struct mapped_pci_resource **uio_res);
210
211 /**
212  * Free uio resource for PCI device
213  *
214  * This function is private to EAL.
215  *
216  * @param dev
217  *   PCI device to free uio resource
218  * @param uio_res
219  *   Pointer to uio resource.
220  */
221 void pci_uio_free_resource(struct rte_pci_device *dev,
222                 struct mapped_pci_resource *uio_res);
223
224 /**
225  * Map device memory to uio resource
226  *
227  * This function is private to EAL.
228  *
229  * @param dev
230  *   PCI device that has memory information.
231  * @param res_idx
232  *   Memory resource index of the PCI device.
233  * @param uio_res
234  *  uio resource that will keep mapping information.
235  * @param map_idx
236  *   Mapping information index of the uio resource.
237  * @return
238  *   0 on success, negative on error
239  */
240 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
241                 struct mapped_pci_resource *uio_res, int map_idx);
242
243 /**
244  * Init tail queues for non-EAL library structures. This is to allow
245  * the rings, mempools, etc. lists to be shared among multiple processes
246  *
247  * This function is private to EAL
248  *
249  * @return
250  *    0 on success, negative on error
251  */
252 int rte_eal_tailqs_init(void);
253
254 /**
255  * Init interrupt handling.
256  *
257  * This function is private to EAL.
258  *
259  * @return
260  *  0 on success, negative on error
261  */
262 int rte_eal_intr_init(void);
263
264 /**
265  * Init alarm mechanism. This is to allow a callback be called after
266  * specific time.
267  *
268  * This function is private to EAL.
269  *
270  * @return
271  *  0 on success, negative on error
272  */
273 int rte_eal_alarm_init(void);
274
275 /**
276  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
277  * etc.) loaded.
278  *
279  * @param module_name
280  *      The module's name which need to be checked
281  *
282  * @return
283  *      -1 means some error happens(NULL pointer or open failure)
284  *      0  means the module not loaded
285  *      1  means the module loaded
286  */
287 int rte_eal_check_module(const char *module_name);
288
289 /**
290  * Get cpu core_id.
291  *
292  * This function is private to the EAL.
293  */
294 unsigned eal_cpu_core_id(unsigned lcore_id);
295
296 /**
297  * Check if cpu is present.
298  *
299  * This function is private to the EAL.
300  */
301 int eal_cpu_detected(unsigned lcore_id);
302
303 /**
304  * Set TSC frequency from precise value or estimation
305  *
306  * This function is private to the EAL.
307  */
308 void set_tsc_freq(void);
309
310 /**
311  * Get precise TSC frequency from system
312  *
313  * This function is private to the EAL.
314  */
315 uint64_t get_tsc_freq(void);
316
317 /**
318  * Prepare physical memory mapping
319  * i.e. hugepages on Linux and
320  *      contigmem on BSD.
321  *
322  * This function is private to the EAL.
323  */
324 int rte_eal_hugepage_init(void);
325
326 /**
327  * Creates memory mapping in secondary process
328  * i.e. hugepages on Linux and
329  *      contigmem on BSD.
330  *
331  * This function is private to the EAL.
332  */
333 int rte_eal_hugepage_attach(void);
334
335 /**
336  * Returns true if the system is able to obtain
337  * physical addresses. Return false if using DMA
338  * addresses through an IOMMU.
339  *
340  * Drivers based on uio will not load unless physical
341  * addresses are obtainable. It is only possible to get
342  * physical addresses when running as a privileged user.
343  */
344 bool rte_eal_using_phys_addrs(void);
345
346 /**
347  * Find a bus capable of identifying a device.
348  *
349  * @param str
350  *   A device identifier (PCI address, virtual PMD name, ...).
351  *
352  * @return
353  *   A valid bus handle if found.
354  *   NULL if no bus is able to parse this device.
355  */
356 struct rte_bus *rte_bus_find_by_device_name(const char *str);
357
358 #endif /* _EAL_PRIVATE_H_ */