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