pci: merge mapping functions for linux and bsd
[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  * Called by environment-specific log initialization function to initialize
53  * log history.
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 int rte_eal_common_log_init(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 early logs
104  *
105  * This function is private to EAL.
106  *
107  * @return
108  *   0 on success, negative on error
109  */
110 int rte_eal_log_early_init(void);
111
112 /**
113  * Init the default log stream
114  *
115  * This function is private to EAL.
116  *
117  * @return
118  *   0 on success, negative on error
119  */
120 int rte_eal_log_init(const char *id, int facility);
121
122 /**
123  * Init the default log stream
124  *
125  * This function is private to EAL.
126  *
127  * @return
128  *   0 on success, negative on error
129  */
130 int rte_eal_pci_init(void);
131
132 #ifdef RTE_LIBRTE_IVSHMEM
133 /**
134  * Init the memory from IVSHMEM devices
135  *
136  * This function is private to EAL.
137  *
138  * @return
139  *  0 on success, negative on error
140  */
141 int rte_eal_ivshmem_init(void);
142
143 /**
144  * Init objects in IVSHMEM devices
145  *
146  * This function is private to EAL.
147  *
148  * @return
149  *  0 on success, negative on error
150  */
151 int rte_eal_ivshmem_obj_init(void);
152 #endif
153
154 struct rte_pci_driver;
155 struct rte_pci_device;
156
157 /**
158  * Map this device
159  *
160  * This function is private to EAL.
161  *
162  * @return
163  *   0 on success, negative on error
164  */
165 int pci_map_device(struct rte_pci_device *dev);
166
167 #ifdef RTE_LIBRTE_EAL_HOTPLUG
168 /**
169  * Unmap this device
170  *
171  * This function is private to EAL.
172  */
173 void pci_unmap_device(struct rte_pci_device *dev);
174 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
175
176 /**
177  * Map the PCI resource of a PCI device in virtual memory
178  *
179  * This function is private to EAL.
180  *
181  * @return
182  *   0 on success, negative on error
183  */
184 int pci_uio_map_resource(struct rte_pci_device *dev);
185
186 #ifdef RTE_LIBRTE_EAL_HOTPLUG
187 /**
188  * Unmap the PCI resource of a PCI device
189  *
190  * This function is private to EAL.
191  */
192 void pci_uio_unmap_resource(struct rte_pci_device *dev);
193 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
194
195 /**
196  * Mmap memory for single PCI device
197  *
198  * This function is private to EAL.
199  *
200  * @return
201  *   0 on success, negative on error
202  */
203 int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
204                 struct rte_pci_device *dev);
205
206 /**
207  * Munmap memory for single PCI device
208  *
209  * This function is private to EAL.
210  *
211  * @param       dr
212  *  The pointer to the pci driver structure
213  * @param       dev
214  *  The pointer to the pci device structure
215  * @return
216  *   0 on success, negative on error
217  */
218 int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr,
219                 struct rte_pci_device *dev);
220
221 /**
222  * Allocate uio resource for PCI device
223  *
224  * This function is private to EAL.
225  *
226  * @param dev
227  *   PCI device to allocate uio resource
228  * @param uio_res
229  *   Pointer to uio resource.
230  *   If the function returns 0, the pointer will be filled.
231  * @return
232  *   0 on success, negative on error
233  */
234 int pci_uio_alloc_resource(struct rte_pci_device *dev,
235                 struct mapped_pci_resource **uio_res);
236
237 /**
238  * Free uio resource for PCI device
239  *
240  * This function is private to EAL.
241  *
242  * @param dev
243  *   PCI device to free uio resource
244  * @param uio_res
245  *   Pointer to uio resource.
246  */
247 void pci_uio_free_resource(struct rte_pci_device *dev,
248                 struct mapped_pci_resource *uio_res);
249
250 /**
251  * Map device memory to uio resource
252  *
253  * This function is private to EAL.
254  *
255  * @param dev
256  *   PCI device that has memory information.
257  * @param res_idx
258  *   Memory resource index of the PCI device.
259  * @param uio_res
260  *  uio resource that will keep mapping information.
261  * @param map_idx
262  *   Mapping information index of the uio resource.
263  * @return
264  *   0 on success, negative on error
265  */
266 int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
267                 struct mapped_pci_resource *uio_res, int map_idx);
268
269 /**
270  * Init tail queues for non-EAL library structures. This is to allow
271  * the rings, mempools, etc. lists to be shared among multiple processes
272  *
273  * This function is private to EAL
274  *
275  * @return
276  *    0 on success, negative on error
277  */
278 int rte_eal_tailqs_init(void);
279
280 /**
281  * Init interrupt handling.
282  *
283  * This function is private to EAL.
284  *
285  * @return
286  *  0 on success, negative on error
287  */
288 int rte_eal_intr_init(void);
289
290 /**
291  * Init alarm mechanism. This is to allow a callback be called after
292  * specific time.
293  *
294  * This function is private to EAL.
295  *
296  * @return
297  *  0 on success, negative on error
298  */
299 int rte_eal_alarm_init(void);
300
301 /**
302  * This function initialises any virtual devices
303  *
304  * This function is private to the EAL.
305  */
306 int rte_eal_dev_init(void);
307
308 /**
309  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
310  * etc.) loaded.
311  *
312  * @param module_name
313  *      The module's name which need to be checked
314  *
315  * @return
316  *      -1 means some error happens(NULL pointer or open failure)
317  *      0  means the module not loaded
318  *      1  means the module loaded
319  */
320 int rte_eal_check_module(const char *module_name);
321
322 #endif /* _EAL_PRIVATE_H_ */