eal/linux: support running as unprivileged user
[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  * Update a pci device object by asking the kernel for the latest information.
127  *
128  * This function is private to EAL.
129  *
130  * @param addr
131  *      The PCI Bus-Device-Function address to look for
132  * @return
133  *   - 0 on success.
134  *   - negative on error.
135  */
136 int pci_update_device(const struct rte_pci_addr *addr);
137
138 /**
139  * Unbind kernel driver for this device
140  *
141  * This function is private to EAL.
142  *
143  * @return
144  *   0 on success, negative on error
145  */
146 int pci_unbind_kernel_driver(struct rte_pci_device *dev);
147
148 /**
149  * Map the PCI resource of a PCI device in virtual memory
150  *
151  * This function is private to EAL.
152  *
153  * @return
154  *   0 on success, negative on error
155  */
156 int pci_uio_map_resource(struct rte_pci_device *dev);
157
158 /**
159  * Unmap the PCI resource of a PCI device
160  *
161  * This function is private to EAL.
162  */
163 void pci_uio_unmap_resource(struct rte_pci_device *dev);
164
165 /**
166  * Allocate uio resource for PCI device
167  *
168  * This function is private to EAL.
169  *
170  * @param dev
171  *   PCI device to allocate uio resource
172  * @param uio_res
173  *   Pointer to uio resource.
174  *   If the function returns 0, the pointer will be filled.
175  * @return
176  *   0 on success, negative on error
177  */
178 int pci_uio_alloc_resource(struct rte_pci_device *dev,
179                 struct mapped_pci_resource **uio_res);
180
181 /**
182  * Free uio resource for PCI device
183  *
184  * This function is private to EAL.
185  *
186  * @param dev
187  *   PCI device to free uio resource
188  * @param uio_res
189  *   Pointer to uio resource.
190  */
191 void pci_uio_free_resource(struct rte_pci_device *dev,
192                 struct mapped_pci_resource *uio_res);
193
194 /**
195  * Map device memory to uio resource
196  *
197  * This function is private to EAL.
198  *
199  * @param dev
200  *   PCI device that has memory information.
201  * @param res_idx
202  *   Memory resource index of the PCI device.
203  * @param uio_res
204  *  uio resource that will keep mapping information.
205  * @param map_idx
206  *   Mapping information index of the uio resource.
207  * @return
208  *   0 on success, negative on error
209  */
210 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
211                 struct mapped_pci_resource *uio_res, int map_idx);
212
213 /**
214  * Init tail queues for non-EAL library structures. This is to allow
215  * the rings, mempools, etc. lists to be shared among multiple processes
216  *
217  * This function is private to EAL
218  *
219  * @return
220  *    0 on success, negative on error
221  */
222 int rte_eal_tailqs_init(void);
223
224 /**
225  * Init interrupt handling.
226  *
227  * This function is private to EAL.
228  *
229  * @return
230  *  0 on success, negative on error
231  */
232 int rte_eal_intr_init(void);
233
234 /**
235  * Init alarm mechanism. This is to allow a callback be called after
236  * specific time.
237  *
238  * This function is private to EAL.
239  *
240  * @return
241  *  0 on success, negative on error
242  */
243 int rte_eal_alarm_init(void);
244
245 /**
246  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
247  * etc.) loaded.
248  *
249  * @param module_name
250  *      The module's name which need to be checked
251  *
252  * @return
253  *      -1 means some error happens(NULL pointer or open failure)
254  *      0  means the module not loaded
255  *      1  means the module loaded
256  */
257 int rte_eal_check_module(const char *module_name);
258
259 /**
260  * Get cpu core_id.
261  *
262  * This function is private to the EAL.
263  */
264 unsigned eal_cpu_core_id(unsigned lcore_id);
265
266 /**
267  * Check if cpu is present.
268  *
269  * This function is private to the EAL.
270  */
271 int eal_cpu_detected(unsigned lcore_id);
272
273 /**
274  * Set TSC frequency from precise value or estimation
275  *
276  * This function is private to the EAL.
277  */
278 void set_tsc_freq(void);
279
280 /**
281  * Get precise TSC frequency from system
282  *
283  * This function is private to the EAL.
284  */
285 uint64_t get_tsc_freq(void);
286
287 /**
288  * Prepare physical memory mapping
289  * i.e. hugepages on Linux and
290  *      contigmem on BSD.
291  *
292  * This function is private to the EAL.
293  */
294 int rte_eal_hugepage_init(void);
295
296 /**
297  * Creates memory mapping in secondary process
298  * i.e. hugepages on Linux and
299  *      contigmem on BSD.
300  *
301  * This function is private to the EAL.
302  */
303 int rte_eal_hugepage_attach(void);
304
305 /**
306  * Returns true if the system is able to obtain
307  * physical addresses. Return false if using DMA
308  * addresses through an IOMMU.
309  *
310  * Drivers based on uio will not load unless physical
311  * addresses are obtainable. It is only possible to get
312  * physical addresses when running as a privileged user.
313  */
314 bool rte_eal_using_phys_addrs(void);
315
316 #endif /* _EAL_PRIVATE_H_ */