eal/windows: add minimum viable code
[dpdk.git] / lib / librte_eal / windows / eal / eal.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #include <io.h>
6 #include <fcntl.h>
7 #include <rte_debug.h>
8 #include <rte_eal.h>
9 #include <rte_errno.h>
10 #include <rte_lcore.h>
11 #include <eal_thread.h>
12 #include <eal_private.h>
13
14 /* Address of global and public configuration */
15 static struct rte_config rte_config;
16
17 /* internal configuration (per-core) */
18 struct lcore_config lcore_config[RTE_MAX_LCORE];
19
20 /* Return a pointer to the configuration structure */
21 struct rte_config *
22 rte_eal_get_configuration(void)
23 {
24         return &rte_config;
25 }
26
27 static int
28 sync_func(void *arg __rte_unused)
29 {
30         return 0;
31 }
32
33 static void
34 rte_eal_init_alert(const char *msg)
35 {
36         fprintf(stderr, "EAL: FATAL: %s\n", msg);
37         RTE_LOG(ERR, EAL, "%s\n", msg);
38 }
39
40  /* Launch threads, called at application init(). */
41 int
42 rte_eal_init(int argc __rte_unused, char **argv __rte_unused)
43 {
44         int i;
45
46         /* create a map of all processors in the system */
47         eal_create_cpu_map();
48
49         if (rte_eal_cpu_init() < 0) {
50                 rte_eal_init_alert("Cannot detect lcores.");
51                 rte_errno = ENOTSUP;
52                 return -1;
53         }
54
55         eal_thread_init_master(rte_config.master_lcore);
56
57         RTE_LCORE_FOREACH_SLAVE(i) {
58
59                 /*
60                  * create communication pipes between master thread
61                  * and children
62                  */
63                 if (_pipe(lcore_config[i].pipe_master2slave,
64                         sizeof(char), _O_BINARY) < 0)
65                         rte_panic("Cannot create pipe\n");
66                 if (_pipe(lcore_config[i].pipe_slave2master,
67                         sizeof(char), _O_BINARY) < 0)
68                         rte_panic("Cannot create pipe\n");
69
70                 lcore_config[i].state = WAIT;
71
72                 /* create a thread for each lcore */
73                 if (eal_thread_create(&lcore_config[i].thread_id) != 0)
74                         rte_panic("Cannot create thread\n");
75         }
76
77         /*
78          * Launch a dummy function on all slave lcores, so that master lcore
79          * knows they are all ready when this function returns.
80          */
81         rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
82         rte_eal_mp_wait_lcore();
83         return 0;
84 }