aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-keystone2/odp_init.c
blob: 73b76540b70fbb47640646b6cad31464aac4325d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (c) 2014, Linaro Limited
 * Copyright (c) 2014, Texas Instruments Incorporated
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#include <odp/init.h>
#include <odp/plat/debug.h>
#include <odp/config.h>
#include <odp/hints.h>
#include <odp_internal.h>
#include <odp/plat/ti_openem.h>

struct odp_global_s *odp_global;
struct odp_proc_s odp_proc;
__thread struct odp_local_s odp_local;

int odp_init_global(const odp_init_t *params,
		    const odp_platform_init_t *platform_params ODP_UNUSED)
{
	odp_proc.log_fn = odp_override_log;
	odp_proc.abort_fn = odp_override_abort;

	if (params != NULL) {
		if (params->log_fn != NULL)
			odp_proc.log_fn = params->log_fn;
		if (params->abort_fn != NULL)
			odp_proc.abort_fn = params->abort_fn;
	}

	if (odp_system_info_init()) {
		ODP_ERR("ODP system_info init failed.\n");
		return -1;
	}


	if (odp_shm_init_global()) {
		odp_pr_err("ODP shm init failed.\n");
		return -1;
	}

	if (odp_thread_init_global()) {
		ODP_ERR("ODP thread init failed.\n");
		return -1;
	}

	/*
	 * At least the mcsdk_global_init() init requires the thread
	 * to be initialized here. So the odp_init_local() has to skip this
	 * step for the main thread.
	 */
	if (odp_thread_init_local(ODP_THREAD_CONTROL)) {
		ODP_ERR("ODP thread local init failed.\n");
		return -1;
	}
	odp_local.is_main_thread = 1; /*Prevent local_init on this thread */

	if (mcsdk_global_init()) {
		odp_pr_err("ODP McSDK init failed.\n");
		return -1;
	}

	if (odp_time_global_init()) {
		ODP_ERR("ODP time init failed.\n");
		return -1;
	}

	if (odp_pool_init_global()) {
		odp_pr_err("ODP buffer pool init failed.\n");
		return -1;
	}

	if (odp_queue_init_global()) {
		odp_pr_err("ODP queue init failed.\n");
		return -1;
	}

	if (odp_schedule_init_global()) {
		odp_pr_err("ODP schedule init failed.\n");
		return -1;
	}

	if (odp_pktio_init_global()) {
		odp_pr_err("ODP packet io init failed.\n");
		return -1;
	}

	if (odp_timer_init_global()) {
		odp_pr_err("ODP timer init failed.\n");
		return -1;
	}

	if (odp_crypto_init_global()) {
		odp_pr_err("ODP crypto init failed.\n");
		return -1;
	}

	if (odp_classification_init_global()) {
		ODP_ERR("ODP classification init failed.\n");
		return -1;
	}

	return 0;
}

int odp_term_global(void)
{
	int ret = 0;

	if (odp_classification_term_global()) {
		ODP_ERR("ODP classificatio term failed.\n");
		ret = -1;
	}

	if (odp_crypto_term_global()) {
		ODP_ERR("ODP crypto term failed.\n");
		ret = -1;
	}

	if (odp_pktio_term_global()) {
		ODP_ERR("ODP pktio term failed.\n");
		ret = -1;
	}

	if (odp_schedule_term_global()) {
		ODP_ERR("ODP schedule termination failed\n");
		ret = -1;
	}

	if (odp_queue_term_global()) {
		ODP_ERR("ODP queue term failed.\n");
		ret = -1;
	}

	if (odp_pool_term_global()) {
		ODP_ERR("ODP buffer pool term failed.\n");
		ret = -1;
	}

	if (mcsdk_global_term()) {
		ODP_ERR("McSDK termination failed\n");
		ret = -1;
	}

	if (odp_thread_term_global()) {
		ODP_ERR("ODP thread term failed.\n");
		ret = -1;
	}

	if (odp_shm_term_global()) {
		ODP_ERR("ODP shm term failed.\n");
		ret = -1;
	}

	return ret;
}

int odp_init_local(odp_thread_type_t thr_type)
{
	int ret = 0;
	int thread_id;

	/* Main thread already finished initialization for local thread */
	if (!odp_local.is_main_thread) {
		if (odp_thread_init_local(thr_type)) {
			ODP_ERR("ODP thread local init failed.\n");
			return -1;
		}
	} else if (thr_type != odp_thread_type()) {
		/* update thread type for main thread */
		odp_thread_term_local();
		if (odp_thread_init_local(thr_type)) {
			ODP_ERR("ODP thread local init failed.\n");
			return -1;
		}
	}

	/*
	 * TODO: check if we can to not initialize smth for control thread
	 */
	thread_id = odp_thread_id();

	ret = mcsdk_local_init(thread_id);
	if (ret < 0) {
		odp_pr_err("Failed to local init McSDK\n");
		return -1;
	}

	if (odp_schedule_init_local(thread_id)) {
		odp_pr_err("ODP schedule local init failed.\n");
		return -1;
	}

	return 0;
}

int odp_term_local(void)
{
	int r, ret = 0;

	if (odp_schedule_term_local()) {
		ODP_ERR("ODP schedule termination failed\n");
		ret = -1;
	}

	r = odp_thread_term_local();

	if (ret == -1 || r < 0)
		return -1;

	return !!r;
}