blob: 5e12dd0b64a0ac4f03795bb27c531cb7257b4ec3 [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"
14
15/**************************************************************************/
16/** IRQ count per partition */
17/**************************************************************************/
18{% for manifest in manifests %}
19 {% if manifest.attr.conditional %}
20#ifdef {{manifest.attr.conditional}}
21 {% endif %}
22 {% if manifest.manifest.irqs %}
23#define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT {{manifest.manifest.irqs | length() }}
24 {% else %}
25#define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT 0
26 {% endif %}
27 {% if manifest.attr.conditional %}
28#endif /* {{manifest.attr.conditional}} */
29 {% endif %}
30
31{% endfor %}
32/**************************************************************************/
33/** Declarations of partition init functions */
34/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +080035#ifdef TFM_PSA_API
Edison Ai9c48d202019-10-12 16:57:21 +080036extern void tfm_nspm_thread_entry(void);
Summer Qin423dbef2019-08-22 15:59:35 +080037#endif
38
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020039{% for manifest in manifests %}
40 {% if manifest.attr.conditional %}
41#ifdef {{manifest.attr.conditional}}
42 {% endif %}
Edison Ai9c48d202019-10-12 16:57:21 +080043extern void {{manifest.manifest.entry_point}}(void);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020044 {% if manifest.attr.conditional %}
45#endif /* {{manifest.attr.conditional}} */
46 {% endif %}
47
48{% endfor %}
49/**************************************************************************/
50/** Memory region declarations */
51/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +080052#ifdef TFM_PSA_API
53REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base);
54REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Limit);
55
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020056{% for manifest in manifests %}
57 {% if manifest.attr.conditional %}
58#ifdef {{manifest.attr.conditional}}
59 {% endif %}
Edison Aib2134e62019-10-11 18:24:47 +080060REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Base);
61REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Limit);
62REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Base);
63REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Limit);
64REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base);
65REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit);
66REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base);
67REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit);
68REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base);
69REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020070 {% if manifest.attr.conditional %}
71#endif /* {{manifest.attr.conditional}} */
72 {% endif %}
73
74{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +080075#endif /* defined(TFM_PSA_API) */
76
Edison Ai66fbdf12019-07-08 16:05:07 +080077#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020078/**************************************************************************/
79/** Context stacks for IRQ handling */
80/**************************************************************************/
81/* The max size of the context stack can be calculated as a function of the IRQ
82 * count of the secure partition:
83 *
84 * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size))
85 *
86 * where:
87 * intr_ctx: Frame pushed when the partition is interrupted
88 * hndl_ctx: Frame pushed when the partition is handling an interrupt
89 */
Summer Qin423dbef2019-08-22 15:59:35 +080090static uint32_t ns_interrupt_ctx_stack[
91 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
92
93static uint32_t tfm_core_interrupt_ctx_stack[
94 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
95
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020096{% for manifest in manifests %}
97 {% if manifest.attr.conditional %}
98#ifdef {{manifest.attr.conditional}}
99 {% endif %}
100static uint32_t ctx_stack_{{manifest.manifest.name}}[
101 (sizeof(struct interrupted_ctx_stack_frame_t) +
102 (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * (
103 sizeof(struct interrupted_ctx_stack_frame_t) +
104 sizeof(struct handler_ctx_stack_frame_t)
105 )) / sizeof(uint32_t)];
106 {% if manifest.attr.conditional %}
107#endif /* {{manifest.attr.conditional}} */
108 {% endif %}
109
110{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +0800111
112uint32_t *ctx_stack_list[] =
113{
114 ns_interrupt_ctx_stack,
115 tfm_core_interrupt_ctx_stack,
116{% for manifest in manifests %}
117 {% if manifest.attr.conditional %}
118#ifdef {{manifest.attr.conditional}}
119 {% endif %}
120 ctx_stack_{{manifest.manifest.name}},
121 {% if manifest.attr.conditional %}
122#endif /* {{manifest.attr.conditional}} */
123 {% endif %}
124{% endfor %}
125};
Edison Ai66fbdf12019-07-08 16:05:07 +0800126#endif /* !defined(TFM_PSA_API) */
127
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200128/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800129/** The static data of the partition list */
130/**************************************************************************/
131const struct spm_partition_static_data_t static_data_list[] =
132{
133 {
Edison Aif0501702019-10-11 14:36:42 +0800134#ifdef TFM_PSA_API
135 .psa_framework_version = 0x0100,
136#endif /* defined(TFM_PSA_API) */
Summer Qin423dbef2019-08-22 15:59:35 +0800137 .partition_id = TFM_SP_NON_SECURE_ID,
138#ifdef TFM_PSA_API
David Hu90128b72019-09-23 16:35:41 +0800139#if TFM_MULTI_CORE_TOPOLOGY
140 .partition_flags = SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_IPC,
141#else
Summer Qin423dbef2019-08-22 15:59:35 +0800142 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC,
David Hu90128b72019-09-23 16:35:41 +0800143#endif
Summer Qin423dbef2019-08-22 15:59:35 +0800144 .partition_priority = TFM_PRIORITY_LOW,
145 .partition_init = tfm_nspm_thread_entry,
146#else
147 .partition_flags = 0,
148#endif
149 },
150
151#ifndef TFM_PSA_API
152 {
153 .partition_id = TFM_SP_CORE_ID,
154 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
155 },
156#endif
157
158{% for manifest in manifests %}
159 {% if manifest.attr.conditional %}
160#ifdef {{manifest.attr.conditional}}
161 {% endif %}
162 {{'{'}}
Edison Aif0501702019-10-11 14:36:42 +0800163#ifdef TFM_PSA_API
164 {% if manifest.manifest.psa_framework_version == 1.0 %}
165 .psa_framework_version = 0x0100,
166 {% else %}
167 .psa_framework_version = 0,
168 {% endif %}
169#endif /* defined(TFM_PSA_API) */
Edison Aib2134e62019-10-11 18:24:47 +0800170 .partition_id = {{manifest.manifest.name}},
Summer Qin423dbef2019-08-22 15:59:35 +0800171 {% if manifest.attr.tfm_partition_ipc %}
172 .partition_flags = SPM_PART_FLAG_IPC
173 {% else %}
174 .partition_flags = 0
175 {% endif %}
176 {% if manifest.manifest.type == "APPLICATION-ROT" %}
177 | SPM_PART_FLAG_APP_ROT
178 {% elif manifest.manifest.type == "PSA-ROT" %}
179 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
180 {% else %}
181#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
182 {% endif %}
183 ,
184 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
185 .partition_init = {{manifest.manifest.entry_point}},
186 {{'},'}}
187 {% if manifest.attr.conditional %}
188#endif /* {{manifest.attr.conditional}} */
189 {% endif %}
190
191{% endfor %}
192};
193
194/**************************************************************************/
195/** The platform data of the partition list */
196/**************************************************************************/
197const struct tfm_spm_partition_platform_data_t *platform_data_list[] =
198{
199 NULL,
200
201#ifndef TFM_PSA_API
202 NULL,
203#endif
204
205{% for manifest in manifests %}
206 {% if manifest.attr.conditional %}
207#ifdef {{manifest.attr.conditional}}
208 {% endif %}
209 {% if manifest.manifest.mmio_regions %}
210 /* FIXME: Only adding the first mmio region */
211 {% for region in manifest.manifest.mmio_regions %}
212 {% if loop.first %}
213 {% if region.conditional %}
214#ifdef {{region.conditional}}
215 {% endif %}
216 {{region.name}},
217 {% if region.conditional %}
218#else /* {{region.conditional}} */
219 NULL,
220#endif /* {{region.conditional}} */
221 {% endif %}
222 {% else %} {# print nothing #} {% endif %}
223 {% endfor %}
224 {% else %}
225 NULL,
226 {% endif %}
227 {% if manifest.attr.conditional %}
228#endif /* {{manifest.attr.conditional}} */
229 {% endif %}
230
231{% endfor %}
232};
233
234/**************************************************************************/
235/** The memory data of the partition list */
236/**************************************************************************/
237#ifdef TFM_PSA_API
238const struct tfm_spm_partition_memory_data_t memory_data_list[] =
239{
240 {
241 .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
242 .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit),
243 .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
244 },
245{% for manifest in manifests %}
246 {% if manifest.attr.conditional %}
247#ifdef {{manifest.attr.conditional}}
248 {% endif %}
249 {{'{'}}
Edison Aib2134e62019-10-11 18:24:47 +0800250 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Base),
251 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Limit),
252 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Base),
253 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Limit),
254 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base),
255 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit),
256 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base),
257 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit),
258 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base),
259 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit),
Summer Qin423dbef2019-08-22 15:59:35 +0800260 {{'},'}}
261 {% if manifest.attr.conditional %}
262#endif /* {{manifest.attr.conditional}} */
263 {% endif %}
264
265{% endfor %}
266};
267#endif /* defined(TFM_PSA_API) */
268
269/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200270/** The partition list for the DB */
271/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800272static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200273{
Summer Qin423dbef2019-08-22 15:59:35 +0800274 {{'{{}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800275#ifndef TFM_PSA_API
Summer Qin423dbef2019-08-22 15:59:35 +0800276 {{'{{}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800277#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200278
279{% for manifest in manifests %}
280 /* -----------------------------------------------------------------------*/
281 /* - Partition DB record for {{manifest.manifest.name}} */
282 /* -----------------------------------------------------------------------*/
283 {% if manifest.attr.conditional %}
284#ifdef {{manifest.attr.conditional}}
285 {% endif %}
286 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200287 /* Runtime data */
Summer Qin423dbef2019-08-22 15:59:35 +0800288 .runtime_data = {},
289 .static_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200290 .platform_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200291
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200292 {{'},'}}
293 {% if manifest.attr.conditional %}
294#endif /* {{manifest.attr.conditional}} */
295 {% endif %}
296
297{% endfor %}
298};
299
300struct spm_partition_db_t g_spm_partition_db = {
301 .is_init = 0,
302 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800303#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200304 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800305#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200306 .partitions = partition_list,
307};
308
309#endif /* __TFM_SPM_DB_INC__ */