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