blob: 5e84b5dd0902951a83f3861a02f698bef5879efe [file] [log] [blame]
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +02001/*
2 * Copyright (c) 2019, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8{{utilities.donotedit_warning}}
9
10#ifndef __TFM_SPM_DB_INC__
11#define __TFM_SPM_DB_INC__
12
13#include "spm_api.h"
Edison Aie728fbf2019-11-13 09:37:12 +080014#include "psa_manifest/sid.h"
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020015
16/**************************************************************************/
17/** IRQ count per partition */
18/**************************************************************************/
19{% for manifest in manifests %}
20 {% if manifest.attr.conditional %}
21#ifdef {{manifest.attr.conditional}}
22 {% endif %}
23 {% if manifest.manifest.irqs %}
24#define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT {{manifest.manifest.irqs | length() }}
25 {% else %}
26#define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT 0
27 {% endif %}
28 {% if manifest.attr.conditional %}
29#endif /* {{manifest.attr.conditional}} */
30 {% endif %}
31
32{% endfor %}
33/**************************************************************************/
34/** Declarations of partition init functions */
35/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +080036#ifdef TFM_PSA_API
Edison Ai9c48d202019-10-12 16:57:21 +080037extern void tfm_nspm_thread_entry(void);
Summer Qin423dbef2019-08-22 15:59:35 +080038#endif
39
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020040{% for manifest in manifests %}
41 {% if manifest.attr.conditional %}
42#ifdef {{manifest.attr.conditional}}
43 {% endif %}
Edison Ai9c48d202019-10-12 16:57:21 +080044extern void {{manifest.manifest.entry_point}}(void);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020045 {% if manifest.attr.conditional %}
46#endif /* {{manifest.attr.conditional}} */
47 {% endif %}
48
49{% endfor %}
50/**************************************************************************/
51/** Memory region declarations */
52/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +080053#ifdef TFM_PSA_API
54REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base);
55REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Limit);
56
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020057{% for manifest in manifests %}
58 {% if manifest.attr.conditional %}
59#ifdef {{manifest.attr.conditional}}
60 {% endif %}
Edison Aib2134e62019-10-11 18:24:47 +080061REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Base);
62REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Limit);
63REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Base);
64REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Limit);
65REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base);
66REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit);
67REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base);
68REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit);
69REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base);
70REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020071 {% if manifest.attr.conditional %}
72#endif /* {{manifest.attr.conditional}} */
73 {% endif %}
74
75{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +080076#endif /* defined(TFM_PSA_API) */
77
Edison Ai66fbdf12019-07-08 16:05:07 +080078#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020079/**************************************************************************/
80/** Context stacks for IRQ handling */
81/**************************************************************************/
82/* The max size of the context stack can be calculated as a function of the IRQ
83 * count of the secure partition:
84 *
85 * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size))
86 *
87 * where:
88 * intr_ctx: Frame pushed when the partition is interrupted
89 * hndl_ctx: Frame pushed when the partition is handling an interrupt
90 */
Summer Qin423dbef2019-08-22 15:59:35 +080091static uint32_t ns_interrupt_ctx_stack[
92 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
93
94static uint32_t tfm_core_interrupt_ctx_stack[
95 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
96
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020097{% for manifest in manifests %}
98 {% if manifest.attr.conditional %}
99#ifdef {{manifest.attr.conditional}}
100 {% endif %}
101static uint32_t ctx_stack_{{manifest.manifest.name}}[
102 (sizeof(struct interrupted_ctx_stack_frame_t) +
103 (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * (
104 sizeof(struct interrupted_ctx_stack_frame_t) +
105 sizeof(struct handler_ctx_stack_frame_t)
106 )) / sizeof(uint32_t)];
107 {% if manifest.attr.conditional %}
108#endif /* {{manifest.attr.conditional}} */
109 {% endif %}
110
111{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +0800112
113uint32_t *ctx_stack_list[] =
114{
115 ns_interrupt_ctx_stack,
116 tfm_core_interrupt_ctx_stack,
117{% for manifest in manifests %}
118 {% if manifest.attr.conditional %}
119#ifdef {{manifest.attr.conditional}}
120 {% endif %}
121 ctx_stack_{{manifest.manifest.name}},
122 {% if manifest.attr.conditional %}
123#endif /* {{manifest.attr.conditional}} */
124 {% endif %}
125{% endfor %}
126};
Edison Ai66fbdf12019-07-08 16:05:07 +0800127#endif /* !defined(TFM_PSA_API) */
128
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200129/**************************************************************************/
Edison Aie728fbf2019-11-13 09:37:12 +0800130/** Dependencies array for Secure Partition */
131/**************************************************************************/
132{% for manifest in manifests %}
133 {% if manifest.manifest.dependencies %}
134 {% if manifest.attr.conditional %}
135#ifdef {{manifest.attr.conditional}}
136 {% endif %}
137static int32_t dependencies_{{manifest.manifest.name}}[] =
138{
139 {% for dependence in manifest.manifest.dependencies %}
140 {{dependence}}_SID,
141 {% endfor %}
142};
143 {% if manifest.attr.conditional %}
144#endif /* {{manifest.attr.conditional}} */
145 {% endif %}
146
147 {% endif %}
148{% endfor %}
149/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800150/** The static data of the partition list */
151/**************************************************************************/
152const struct spm_partition_static_data_t static_data_list[] =
153{
154 {
Edison Aif0501702019-10-11 14:36:42 +0800155#ifdef TFM_PSA_API
156 .psa_framework_version = 0x0100,
157#endif /* defined(TFM_PSA_API) */
Summer Qin423dbef2019-08-22 15:59:35 +0800158 .partition_id = TFM_SP_NON_SECURE_ID,
159#ifdef TFM_PSA_API
David Hu90128b72019-09-23 16:35:41 +0800160#if TFM_MULTI_CORE_TOPOLOGY
161 .partition_flags = SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_IPC,
162#else
Summer Qin423dbef2019-08-22 15:59:35 +0800163 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC,
David Hu90128b72019-09-23 16:35:41 +0800164#endif
Summer Qin423dbef2019-08-22 15:59:35 +0800165 .partition_priority = TFM_PRIORITY_LOW,
166 .partition_init = tfm_nspm_thread_entry,
167#else
168 .partition_flags = 0,
169#endif
170 },
171
172#ifndef TFM_PSA_API
173 {
174 .partition_id = TFM_SP_CORE_ID,
175 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
176 },
177#endif
178
179{% for manifest in manifests %}
180 {% if manifest.attr.conditional %}
181#ifdef {{manifest.attr.conditional}}
182 {% endif %}
183 {{'{'}}
Edison Aif0501702019-10-11 14:36:42 +0800184#ifdef TFM_PSA_API
185 {% if manifest.manifest.psa_framework_version == 1.0 %}
186 .psa_framework_version = 0x0100,
187 {% else %}
188 .psa_framework_version = 0,
189 {% endif %}
190#endif /* defined(TFM_PSA_API) */
Edison Aib2134e62019-10-11 18:24:47 +0800191 .partition_id = {{manifest.manifest.name}},
Summer Qin423dbef2019-08-22 15:59:35 +0800192 {% if manifest.attr.tfm_partition_ipc %}
193 .partition_flags = SPM_PART_FLAG_IPC
194 {% else %}
195 .partition_flags = 0
196 {% endif %}
197 {% if manifest.manifest.type == "APPLICATION-ROT" %}
198 | SPM_PART_FLAG_APP_ROT
199 {% elif manifest.manifest.type == "PSA-ROT" %}
200 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
201 {% else %}
202#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
203 {% endif %}
204 ,
205 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
206 .partition_init = {{manifest.manifest.entry_point}},
Edison Aie728fbf2019-11-13 09:37:12 +0800207 .dependencies_num = {{manifest.manifest.dependencies | length()}},
208 {% if manifest.manifest.dependencies %}
209 .p_dependencies = dependencies_{{manifest.manifest.name}},
210 {% else %}
211 .p_dependencies = NULL,
212 {% endif %}
Summer Qin423dbef2019-08-22 15:59:35 +0800213 {{'},'}}
214 {% if manifest.attr.conditional %}
215#endif /* {{manifest.attr.conditional}} */
216 {% endif %}
217
218{% endfor %}
219};
220
221/**************************************************************************/
222/** The platform data of the partition list */
223/**************************************************************************/
224const struct tfm_spm_partition_platform_data_t *platform_data_list[] =
225{
226 NULL,
227
228#ifndef TFM_PSA_API
229 NULL,
230#endif
231
232{% for manifest in manifests %}
233 {% if manifest.attr.conditional %}
234#ifdef {{manifest.attr.conditional}}
235 {% endif %}
236 {% if manifest.manifest.mmio_regions %}
237 /* FIXME: Only adding the first mmio region */
238 {% for region in manifest.manifest.mmio_regions %}
239 {% if loop.first %}
240 {% if region.conditional %}
241#ifdef {{region.conditional}}
242 {% endif %}
243 {{region.name}},
244 {% if region.conditional %}
245#else /* {{region.conditional}} */
246 NULL,
247#endif /* {{region.conditional}} */
248 {% endif %}
249 {% else %} {# print nothing #} {% endif %}
250 {% endfor %}
251 {% else %}
252 NULL,
253 {% endif %}
254 {% if manifest.attr.conditional %}
255#endif /* {{manifest.attr.conditional}} */
256 {% endif %}
257
258{% endfor %}
259};
260
261/**************************************************************************/
262/** The memory data of the partition list */
263/**************************************************************************/
264#ifdef TFM_PSA_API
265const struct tfm_spm_partition_memory_data_t memory_data_list[] =
266{
267 {
268 .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
269 .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit),
270 .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
271 },
272{% for manifest in manifests %}
273 {% if manifest.attr.conditional %}
274#ifdef {{manifest.attr.conditional}}
275 {% endif %}
276 {{'{'}}
Edison Aib2134e62019-10-11 18:24:47 +0800277 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Base),
278 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Limit),
279 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Base),
280 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Limit),
281 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base),
282 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit),
283 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base),
284 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit),
285 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base),
286 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit),
Summer Qin423dbef2019-08-22 15:59:35 +0800287 {{'},'}}
288 {% if manifest.attr.conditional %}
289#endif /* {{manifest.attr.conditional}} */
290 {% endif %}
291
292{% endfor %}
293};
294#endif /* defined(TFM_PSA_API) */
295
296/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200297/** The partition list for the DB */
298/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800299static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200300{
Summer Qin423dbef2019-08-22 15:59:35 +0800301 {{'{{}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800302#ifndef TFM_PSA_API
Summer Qin423dbef2019-08-22 15:59:35 +0800303 {{'{{}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800304#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200305
306{% for manifest in manifests %}
307 /* -----------------------------------------------------------------------*/
308 /* - Partition DB record for {{manifest.manifest.name}} */
309 /* -----------------------------------------------------------------------*/
310 {% if manifest.attr.conditional %}
311#ifdef {{manifest.attr.conditional}}
312 {% endif %}
313 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200314 /* Runtime data */
Summer Qin423dbef2019-08-22 15:59:35 +0800315 .runtime_data = {},
316 .static_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200317 .platform_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200318
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200319 {{'},'}}
320 {% if manifest.attr.conditional %}
321#endif /* {{manifest.attr.conditional}} */
322 {% endif %}
323
324{% endfor %}
325};
326
327struct spm_partition_db_t g_spm_partition_db = {
328 .is_init = 0,
329 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800330#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200331 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800332#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200333 .partitions = partition_list,
334};
335
336#endif /* __TFM_SPM_DB_INC__ */