blob: 0ce3e8db2641dfdf177a67b34de569d833242fe4 [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
Edison Ai1545bb92019-11-14 14:15:27 +080016{# Produce a build error if heap_size is presented in the manifest, because of the dynamic memory allocation is not supported now. #}
17{% for manifest in manifests %}
18 {% if manifest.manifest.heap_size %}
19#error "Please do not add 'heap_size' for partition '{{manifest.manifest.name}}', the dynamic memory allocation is not supported now!"
20 {% endif %}
21{% endfor %}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020022/**************************************************************************/
23/** IRQ count per partition */
24/**************************************************************************/
25{% for manifest in manifests %}
26 {% if manifest.attr.conditional %}
27#ifdef {{manifest.attr.conditional}}
28 {% endif %}
29 {% if manifest.manifest.irqs %}
30#define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT {{manifest.manifest.irqs | length() }}
31 {% else %}
32#define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT 0
33 {% endif %}
34 {% if manifest.attr.conditional %}
35#endif /* {{manifest.attr.conditional}} */
36 {% endif %}
37
38{% endfor %}
39/**************************************************************************/
40/** Declarations of partition init functions */
41/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +080042#ifdef TFM_PSA_API
Edison Ai9c48d202019-10-12 16:57:21 +080043extern void tfm_nspm_thread_entry(void);
Summer Qin423dbef2019-08-22 15:59:35 +080044#endif
45
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020046{% for manifest in manifests %}
47 {% if manifest.attr.conditional %}
48#ifdef {{manifest.attr.conditional}}
49 {% endif %}
Edison Ai9c48d202019-10-12 16:57:21 +080050extern void {{manifest.manifest.entry_point}}(void);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020051 {% if manifest.attr.conditional %}
52#endif /* {{manifest.attr.conditional}} */
53 {% endif %}
54
55{% endfor %}
56/**************************************************************************/
57/** Memory region declarations */
58/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +080059#ifdef TFM_PSA_API
60REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base);
61REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Limit);
62
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020063{% for manifest in manifests %}
64 {% if manifest.attr.conditional %}
65#ifdef {{manifest.attr.conditional}}
66 {% endif %}
Edison Aib2134e62019-10-11 18:24:47 +080067REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Base);
68REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Limit);
69REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Base);
70REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Limit);
71REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base);
72REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit);
73REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base);
74REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit);
75REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base);
76REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020077 {% if manifest.attr.conditional %}
78#endif /* {{manifest.attr.conditional}} */
79 {% endif %}
80
81{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +080082#endif /* defined(TFM_PSA_API) */
83
Edison Ai66fbdf12019-07-08 16:05:07 +080084#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020085/**************************************************************************/
86/** Context stacks for IRQ handling */
87/**************************************************************************/
88/* The max size of the context stack can be calculated as a function of the IRQ
89 * count of the secure partition:
90 *
91 * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size))
92 *
93 * where:
94 * intr_ctx: Frame pushed when the partition is interrupted
95 * hndl_ctx: Frame pushed when the partition is handling an interrupt
96 */
Summer Qin423dbef2019-08-22 15:59:35 +080097static uint32_t ns_interrupt_ctx_stack[
98 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
99
100static uint32_t tfm_core_interrupt_ctx_stack[
101 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
102
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200103{% for manifest in manifests %}
104 {% if manifest.attr.conditional %}
105#ifdef {{manifest.attr.conditional}}
106 {% endif %}
107static uint32_t ctx_stack_{{manifest.manifest.name}}[
108 (sizeof(struct interrupted_ctx_stack_frame_t) +
109 (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * (
110 sizeof(struct interrupted_ctx_stack_frame_t) +
111 sizeof(struct handler_ctx_stack_frame_t)
112 )) / sizeof(uint32_t)];
113 {% if manifest.attr.conditional %}
114#endif /* {{manifest.attr.conditional}} */
115 {% endif %}
116
117{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +0800118
119uint32_t *ctx_stack_list[] =
120{
121 ns_interrupt_ctx_stack,
122 tfm_core_interrupt_ctx_stack,
123{% for manifest in manifests %}
124 {% if manifest.attr.conditional %}
125#ifdef {{manifest.attr.conditional}}
126 {% endif %}
127 ctx_stack_{{manifest.manifest.name}},
128 {% if manifest.attr.conditional %}
129#endif /* {{manifest.attr.conditional}} */
130 {% endif %}
131{% endfor %}
132};
Edison Ai66fbdf12019-07-08 16:05:07 +0800133#endif /* !defined(TFM_PSA_API) */
134
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200135/**************************************************************************/
Edison Aie728fbf2019-11-13 09:37:12 +0800136/** Dependencies array for Secure Partition */
137/**************************************************************************/
138{% for manifest in manifests %}
139 {% if manifest.manifest.dependencies %}
140 {% if manifest.attr.conditional %}
141#ifdef {{manifest.attr.conditional}}
142 {% endif %}
143static int32_t dependencies_{{manifest.manifest.name}}[] =
144{
145 {% for dependence in manifest.manifest.dependencies %}
146 {{dependence}}_SID,
147 {% endfor %}
148};
149 {% if manifest.attr.conditional %}
150#endif /* {{manifest.attr.conditional}} */
151 {% endif %}
152
153 {% endif %}
154{% endfor %}
155/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800156/** The static data of the partition list */
157/**************************************************************************/
158const struct spm_partition_static_data_t static_data_list[] =
159{
160 {
Edison Aif0501702019-10-11 14:36:42 +0800161#ifdef TFM_PSA_API
162 .psa_framework_version = 0x0100,
163#endif /* defined(TFM_PSA_API) */
Summer Qin423dbef2019-08-22 15:59:35 +0800164 .partition_id = TFM_SP_NON_SECURE_ID,
165#ifdef TFM_PSA_API
David Hu90128b72019-09-23 16:35:41 +0800166#if TFM_MULTI_CORE_TOPOLOGY
167 .partition_flags = SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_IPC,
168#else
Summer Qin423dbef2019-08-22 15:59:35 +0800169 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC,
David Hu90128b72019-09-23 16:35:41 +0800170#endif
Summer Qin423dbef2019-08-22 15:59:35 +0800171 .partition_priority = TFM_PRIORITY_LOW,
172 .partition_init = tfm_nspm_thread_entry,
173#else
174 .partition_flags = 0,
175#endif
176 },
177
178#ifndef TFM_PSA_API
179 {
180 .partition_id = TFM_SP_CORE_ID,
181 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
182 },
183#endif
184
185{% for manifest in manifests %}
186 {% if manifest.attr.conditional %}
187#ifdef {{manifest.attr.conditional}}
188 {% endif %}
189 {{'{'}}
Edison Aif0501702019-10-11 14:36:42 +0800190#ifdef TFM_PSA_API
191 {% if manifest.manifest.psa_framework_version == 1.0 %}
192 .psa_framework_version = 0x0100,
193 {% else %}
194 .psa_framework_version = 0,
195 {% endif %}
196#endif /* defined(TFM_PSA_API) */
Edison Aib2134e62019-10-11 18:24:47 +0800197 .partition_id = {{manifest.manifest.name}},
Summer Qin423dbef2019-08-22 15:59:35 +0800198 {% if manifest.attr.tfm_partition_ipc %}
199 .partition_flags = SPM_PART_FLAG_IPC
200 {% else %}
201 .partition_flags = 0
202 {% endif %}
203 {% if manifest.manifest.type == "APPLICATION-ROT" %}
204 | SPM_PART_FLAG_APP_ROT
205 {% elif manifest.manifest.type == "PSA-ROT" %}
206 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
207 {% else %}
208#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
209 {% endif %}
210 ,
211 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
212 .partition_init = {{manifest.manifest.entry_point}},
Edison Aie728fbf2019-11-13 09:37:12 +0800213 .dependencies_num = {{manifest.manifest.dependencies | length()}},
214 {% if manifest.manifest.dependencies %}
215 .p_dependencies = dependencies_{{manifest.manifest.name}},
216 {% else %}
217 .p_dependencies = NULL,
218 {% endif %}
Summer Qin423dbef2019-08-22 15:59:35 +0800219 {{'},'}}
220 {% if manifest.attr.conditional %}
221#endif /* {{manifest.attr.conditional}} */
222 {% endif %}
223
224{% endfor %}
225};
226
227/**************************************************************************/
228/** The platform data of the partition list */
229/**************************************************************************/
230const struct tfm_spm_partition_platform_data_t *platform_data_list[] =
231{
232 NULL,
233
234#ifndef TFM_PSA_API
235 NULL,
236#endif
237
238{% for manifest in manifests %}
239 {% if manifest.attr.conditional %}
240#ifdef {{manifest.attr.conditional}}
241 {% endif %}
242 {% if manifest.manifest.mmio_regions %}
243 /* FIXME: Only adding the first mmio region */
244 {% for region in manifest.manifest.mmio_regions %}
245 {% if loop.first %}
246 {% if region.conditional %}
247#ifdef {{region.conditional}}
248 {% endif %}
249 {{region.name}},
250 {% if region.conditional %}
251#else /* {{region.conditional}} */
252 NULL,
253#endif /* {{region.conditional}} */
254 {% endif %}
255 {% else %} {# print nothing #} {% endif %}
256 {% endfor %}
257 {% else %}
258 NULL,
259 {% endif %}
260 {% if manifest.attr.conditional %}
261#endif /* {{manifest.attr.conditional}} */
262 {% endif %}
263
264{% endfor %}
265};
266
267/**************************************************************************/
268/** The memory data of the partition list */
269/**************************************************************************/
270#ifdef TFM_PSA_API
271const struct tfm_spm_partition_memory_data_t memory_data_list[] =
272{
273 {
274 .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
275 .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit),
276 .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
277 },
278{% for manifest in manifests %}
279 {% if manifest.attr.conditional %}
280#ifdef {{manifest.attr.conditional}}
281 {% endif %}
282 {{'{'}}
Edison Aib2134e62019-10-11 18:24:47 +0800283 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Base),
284 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Limit),
285 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Base),
286 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Limit),
287 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base),
288 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit),
289 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base),
290 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit),
291 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base),
292 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit),
Summer Qin423dbef2019-08-22 15:59:35 +0800293 {{'},'}}
294 {% if manifest.attr.conditional %}
295#endif /* {{manifest.attr.conditional}} */
296 {% endif %}
297
298{% endfor %}
299};
300#endif /* defined(TFM_PSA_API) */
301
302/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200303/** The partition list for the DB */
304/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800305static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200306{
Summer Qin423dbef2019-08-22 15:59:35 +0800307 {{'{{}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800308#ifndef TFM_PSA_API
Summer Qin423dbef2019-08-22 15:59:35 +0800309 {{'{{}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800310#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200311
312{% for manifest in manifests %}
313 /* -----------------------------------------------------------------------*/
314 /* - Partition DB record for {{manifest.manifest.name}} */
315 /* -----------------------------------------------------------------------*/
316 {% if manifest.attr.conditional %}
317#ifdef {{manifest.attr.conditional}}
318 {% endif %}
319 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200320 /* Runtime data */
Summer Qin423dbef2019-08-22 15:59:35 +0800321 .runtime_data = {},
322 .static_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200323 .platform_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200324
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200325 {{'},'}}
326 {% if manifest.attr.conditional %}
327#endif /* {{manifest.attr.conditional}} */
328 {% endif %}
329
330{% endfor %}
331};
332
333struct spm_partition_db_t g_spm_partition_db = {
334 .is_init = 0,
335 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800336#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200337 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800338#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200339 .partitions = partition_list,
340};
341
342#endif /* __TFM_SPM_DB_INC__ */