Imported Upstream version 16.07-rc1
[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 <stdio.h>
38 #include <rte_pci.h>
39
40 /**
41  * Initialize the memzone subsystem (private to eal).
42  *
43  * @return
44  *   - 0 on success
45  *   - Negative on error
46  */
47 int rte_eal_memzone_init(void);
48
49 /**
50  * Common log initialization function (private to eal).
51  *
52  * @param default_log
53  *   The default log stream to be used.
54  * @return
55  *   - 0 on success
56  *   - Negative on error
57  */
58 int rte_eal_common_log_init(FILE *default_log);
59
60 /**
61  * Fill configuration with number of physical and logical processors
62  *
63  * This function is private to EAL.
64  *
65  * Parse /proc/cpuinfo to get the number of physical and logical
66  * processors on the machine.
67  *
68  * @return
69  *   0 on success, negative on error
70  */
71 int rte_eal_cpu_init(void);
72
73 /**
74  * Map memory
75  *
76  * This function is private to EAL.
77  *
78  * Fill configuration structure with these infos, and return 0 on success.
79  *
80  * @return
81  *   0 on success, negative on error
82  */
83 int rte_eal_memory_init(void);
84
85 /**
86  * Configure timers
87  *
88  * This function is private to EAL.
89  *
90  * Mmap memory areas used by HPET (high precision event timer) that will
91  * provide our time reference, and configure the TSC frequency also for it
92  * to be used as a reference.
93  *
94  * @return
95  *   0 on success, negative on error
96  */
97 int rte_eal_timer_init(void);
98
99 /**
100  * Init early logs
101  *
102  * This function is private to EAL.
103  *
104  * @return
105  *   0 on success, negative on error
106  */
107 int rte_eal_log_early_init(void);
108
109 /**
110  * Init the default log stream
111  *
112  * This function is private to EAL.
113  *
114  * @return
115  *   0 on success, negative on error
116  */
117 int rte_eal_log_init(const char *id, int facility);
118
119 /**
120  * Init the default log stream
121  *
122  * This function is private to EAL.
123  *
124  * @return
125  *   0 on success, negative on error
126  */
127 int rte_eal_pci_init(void);
128
129 #ifdef RTE_LIBRTE_IVSHMEM
130 /**
131  * Init the memory from IVSHMEM devices
132  *
133  * This function is private to EAL.
134  *
135  * @return
136  *  0 on success, negative on error
137  */
138 int rte_eal_ivshmem_init(void);
139
140 /**
141  * Init objects in IVSHMEM devices
142  *
143  * This function is private to EAL.
144  *
145  * @return
146  *  0 on success, negative on error
147  */
148 int rte_eal_ivshmem_obj_init(void);
149 #endif
150
151 struct rte_pci_driver;
152 struct rte_pci_device;
153
154 /**
155  * Unbind kernel driver for this device
156  *
157  * This function is private to EAL.
158  *
159  * @return
160  *   0 on success, negative on error
161  */
162 int pci_unbind_kernel_driver(struct rte_pci_device *dev);
163
164 /**
165  * Map the PCI resource of a PCI device in virtual memory
166  *
167  * This function is private to EAL.
168  *
169  * @return
170  *   0 on success, negative on error
171  */
172 int pci_uio_map_resource(struct rte_pci_device *dev);
173
174 /**
175  * Unmap the PCI resource of a PCI device
176  *
177  * This function is private to EAL.
178  */
179 void pci_uio_unmap_resource(struct rte_pci_device *dev);
180
181 /**
182  * Allocate uio resource for PCI device
183  *
184  * This function is private to EAL.
185  *
186  * @param dev
187  *   PCI device to allocate uio resource
188  * @param uio_res
189  *   Pointer to uio resource.
190  *   If the function returns 0, the pointer will be filled.
191  * @return
192  *   0 on success, negative on error
193  */
194 int pci_uio_alloc_resource(struct rte_pci_device *dev,
195                 struct mapped_pci_resource **uio_res);
196
197 /**
198  * Free uio resource for PCI device
199  *
200  * This function is private to EAL.
201  *
202  * @param dev
203  *   PCI device to free uio resource
204  * @param uio_res
205  *   Pointer to uio resource.
206  */
207 void pci_uio_free_resource(struct rte_pci_device *dev,
208                 struct mapped_pci_resource *uio_res);
209
210 /**
211  * Map device memory to uio resource
212  *
213  * This function is private to EAL.
214  *
215  * @param dev
216  *   PCI device that has memory information.
217  * @param res_idx
218  *   Memory resource index of the PCI device.
219  * @param uio_res
220  *  uio resource that will keep mapping information.
221  * @param map_idx
222  *   Mapping information index of the uio resource.
223  * @return
224  *   0 on success, negative on error
225  */
226 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
227                 struct mapped_pci_resource *uio_res, int map_idx);
228
229 /**
230  * Init tail queues for non-EAL library structures. This is to allow
231  * the rings, mempools, etc. lists to be shared among multiple processes
232  *
233  * This function is private to EAL
234  *
235  * @return
236  *    0 on success, negative on error
237  */
238 int rte_eal_tailqs_init(void);
239
240 /**
241  * Init interrupt handling.
242  *
243  * This function is private to EAL.
244  *
245  * @return
246  *  0 on success, negative on error
247  */
248 int rte_eal_intr_init(void);
249
250 /**
251  * Init alarm mechanism. This is to allow a callback be called after
252  * specific time.
253  *
254  * This function is private to EAL.
255  *
256  * @return
257  *  0 on success, negative on error
258  */
259 int rte_eal_alarm_init(void);
260
261 /**
262  * This function initialises any virtual devices
263  *
264  * This function is private to the EAL.
265  */
266 int rte_eal_dev_init(void);
267
268 /**
269  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
270  * etc.) loaded.
271  *
272  * @param module_name
273  *      The module's name which need to be checked
274  *
275  * @return
276  *      -1 means some error happens(NULL pointer or open failure)
277  *      0  means the module not loaded
278  *      1  means the module loaded
279  */
280 int rte_eal_check_module(const char *module_name);
281
282 /**
283  * Get cpu core_id.
284  *
285  * This function is private to the EAL.
286  */
287 unsigned eal_cpu_core_id(unsigned lcore_id);
288
289 /**
290  * Check if cpu is present.
291  *
292  * This function is private to the EAL.
293  */
294 int eal_cpu_detected(unsigned lcore_id);
295
296 /**
297  * Set TSC frequency from precise value or estimation
298  *
299  * This function is private to the EAL.
300  */
301 void set_tsc_freq(void);
302
303 /**
304  * Get precise TSC frequency from system
305  *
306  * This function is private to the EAL.
307  */
308 uint64_t get_tsc_freq(void);
309
310 /**
311  * Prepare physical memory mapping
312  * i.e. hugepages on Linux and
313  *      contigmem on BSD.
314  *
315  * This function is private to the EAL.
316  */
317 int rte_eal_hugepage_init(void);
318
319 /**
320  * Creates memory mapping in secondary process
321  * i.e. hugepages on Linux and
322  *      contigmem on BSD.
323  *
324  * This function is private to the EAL.
325  */
326 int rte_eal_hugepage_attach(void);
327
328 #endif /* _EAL_PRIVATE_H_ */