blob: 83de2424309a040b47aaf8563af22d2ccda4b6d7 [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 %}
Edison Aib262cc42019-12-20 14:47:52 +0800146 {% for service in manifest.manifest.services %}
147 {% if dependence == service.name %}
148#error "Please DO NOT include SP's own RoT Service '{{dependence}}', which will cause a deadlock!"
149 {% endif %}
150 {% endfor %}
Edison Aie728fbf2019-11-13 09:37:12 +0800151 {{dependence}}_SID,
152 {% endfor %}
153};
154 {% if manifest.attr.conditional %}
155#endif /* {{manifest.attr.conditional}} */
156 {% endif %}
157
158 {% endif %}
159{% endfor %}
160/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800161/** The static data of the partition list */
162/**************************************************************************/
163const struct spm_partition_static_data_t static_data_list[] =
164{
165 {
Edison Aif0501702019-10-11 14:36:42 +0800166#ifdef TFM_PSA_API
167 .psa_framework_version = 0x0100,
168#endif /* defined(TFM_PSA_API) */
Summer Qin423dbef2019-08-22 15:59:35 +0800169 .partition_id = TFM_SP_NON_SECURE_ID,
170#ifdef TFM_PSA_API
David Hu90128b72019-09-23 16:35:41 +0800171#if TFM_MULTI_CORE_TOPOLOGY
172 .partition_flags = SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_IPC,
173#else
Summer Qin423dbef2019-08-22 15:59:35 +0800174 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC,
David Hu90128b72019-09-23 16:35:41 +0800175#endif
Summer Qin423dbef2019-08-22 15:59:35 +0800176 .partition_priority = TFM_PRIORITY_LOW,
177 .partition_init = tfm_nspm_thread_entry,
178#else
179 .partition_flags = 0,
180#endif
181 },
182
183#ifndef TFM_PSA_API
184 {
185 .partition_id = TFM_SP_CORE_ID,
186 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
187 },
188#endif
189
190{% for manifest in manifests %}
191 {% if manifest.attr.conditional %}
192#ifdef {{manifest.attr.conditional}}
193 {% endif %}
194 {{'{'}}
Edison Aif0501702019-10-11 14:36:42 +0800195#ifdef TFM_PSA_API
196 {% if manifest.manifest.psa_framework_version == 1.0 %}
197 .psa_framework_version = 0x0100,
198 {% else %}
199 .psa_framework_version = 0,
200 {% endif %}
201#endif /* defined(TFM_PSA_API) */
Edison Aib2134e62019-10-11 18:24:47 +0800202 .partition_id = {{manifest.manifest.name}},
Summer Qin423dbef2019-08-22 15:59:35 +0800203 {% if manifest.attr.tfm_partition_ipc %}
204 .partition_flags = SPM_PART_FLAG_IPC
205 {% else %}
206 .partition_flags = 0
207 {% endif %}
208 {% if manifest.manifest.type == "APPLICATION-ROT" %}
209 | SPM_PART_FLAG_APP_ROT
210 {% elif manifest.manifest.type == "PSA-ROT" %}
211 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
212 {% else %}
213#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
214 {% endif %}
215 ,
216 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
217 .partition_init = {{manifest.manifest.entry_point}},
Edison Aie728fbf2019-11-13 09:37:12 +0800218 .dependencies_num = {{manifest.manifest.dependencies | length()}},
219 {% if manifest.manifest.dependencies %}
220 .p_dependencies = dependencies_{{manifest.manifest.name}},
221 {% else %}
222 .p_dependencies = NULL,
223 {% endif %}
Summer Qin423dbef2019-08-22 15:59:35 +0800224 {{'},'}}
225 {% if manifest.attr.conditional %}
226#endif /* {{manifest.attr.conditional}} */
227 {% endif %}
228
229{% endfor %}
230};
231
232/**************************************************************************/
233/** The platform data of the partition list */
234/**************************************************************************/
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100235{% for manifest in manifests %}
236 {% if manifest.manifest.mmio_regions %}
237 {% if manifest.attr.conditional %}
238#ifdef {{manifest.attr.conditional}}
239 {% endif %}
240const struct tfm_spm_partition_platform_data_t *
241 platform_data_list_{{manifest.manifest.name}}[] =
242{
243 {% for region in manifest.manifest.mmio_regions %}
244 {% if region.conditional %}
245#ifdef {{region.conditional}}
246 {% endif %}
247 {{region.name}},
248 {% if region.conditional %}
249#endif /* {{region.conditional}} */
250 {% endif %}
251 {% endfor %}
252 NULL
253};
254 {% if manifest.attr.conditional %}
255#endif /* {{manifest.attr.conditional}} */
256 {% endif %}
257
258 {% endif %}
259{% endfor %}
260const struct tfm_spm_partition_platform_data_t **platform_data_list_list[] =
Summer Qin423dbef2019-08-22 15:59:35 +0800261{
262 NULL,
263
264#ifndef TFM_PSA_API
265 NULL,
266#endif
267
268{% for manifest in manifests %}
269 {% if manifest.attr.conditional %}
270#ifdef {{manifest.attr.conditional}}
271 {% endif %}
272 {% if manifest.manifest.mmio_regions %}
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100273 platform_data_list_{{manifest.manifest.name}},
274 {% else %}{# if manifest.manifest.mmio_regions #}
Summer Qin423dbef2019-08-22 15:59:35 +0800275 NULL,
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100276 {% endif %}{# if manifest.manifest.mmio_regions #}
Summer Qin423dbef2019-08-22 15:59:35 +0800277 {% if manifest.attr.conditional %}
278#endif /* {{manifest.attr.conditional}} */
279 {% endif %}
280
281{% endfor %}
282};
283
284/**************************************************************************/
285/** The memory data of the partition list */
286/**************************************************************************/
287#ifdef TFM_PSA_API
288const struct tfm_spm_partition_memory_data_t memory_data_list[] =
289{
290 {
291 .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
292 .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit),
293 .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
294 },
295{% for manifest in manifests %}
296 {% if manifest.attr.conditional %}
297#ifdef {{manifest.attr.conditional}}
298 {% endif %}
299 {{'{'}}
Edison Aib2134e62019-10-11 18:24:47 +0800300 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Base),
301 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Limit),
302 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Base),
303 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Limit),
304 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base),
305 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit),
306 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base),
307 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit),
308 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base),
309 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit),
Summer Qin423dbef2019-08-22 15:59:35 +0800310 {{'},'}}
311 {% if manifest.attr.conditional %}
312#endif /* {{manifest.attr.conditional}} */
313 {% endif %}
314
315{% endfor %}
316};
317#endif /* defined(TFM_PSA_API) */
318
319/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200320/** The partition list for the DB */
321/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800322static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200323{
Summer Qin423dbef2019-08-22 15:59:35 +0800324 {{'{{}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800325#ifndef TFM_PSA_API
Summer Qin423dbef2019-08-22 15:59:35 +0800326 {{'{{}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800327#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200328
329{% for manifest in manifests %}
330 /* -----------------------------------------------------------------------*/
331 /* - Partition DB record for {{manifest.manifest.name}} */
332 /* -----------------------------------------------------------------------*/
333 {% if manifest.attr.conditional %}
334#ifdef {{manifest.attr.conditional}}
335 {% endif %}
336 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200337 /* Runtime data */
Summer Qin423dbef2019-08-22 15:59:35 +0800338 .runtime_data = {},
339 .static_data = NULL,
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100340 .platform_data_list = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200341 {{'},'}}
342 {% if manifest.attr.conditional %}
343#endif /* {{manifest.attr.conditional}} */
344 {% endif %}
345
346{% endfor %}
347};
348
349struct spm_partition_db_t g_spm_partition_db = {
350 .is_init = 0,
351 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800352#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200353 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800354#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200355 .partitions = partition_list,
356};
357
358#endif /* __TFM_SPM_DB_INC__ */