blob: f58dd30810b8ec14fa2a3609978f51250eebef03 [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
36extern psa_status_t tfm_nspm_thread_entry(void);
37#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 %}
43extern int32_t {{manifest.manifest.entry_point}}(void);
44 {% 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 %}
60REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$Base);
61REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$Limit);
62REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$RO$$Base);
63REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$RO$$Limit);
64REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$RW$$Base);
65REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$RW$$Limit);
66REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$ZI$$Base);
67REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$ZI$$Limit);
68REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _STACK$$ZI$$Base);
69REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _STACK$$ZI$$Limit);
70 {% 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 {
134 .partition_id = TFM_SP_NON_SECURE_ID,
135#ifdef TFM_PSA_API
136 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC,
137 .partition_priority = TFM_PRIORITY_LOW,
138 .partition_init = tfm_nspm_thread_entry,
139#else
140 .partition_flags = 0,
141#endif
142 },
143
144#ifndef TFM_PSA_API
145 {
146 .partition_id = TFM_SP_CORE_ID,
147 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
148 },
149#endif
150
151{% for manifest in manifests %}
152 {% if manifest.attr.conditional %}
153#ifdef {{manifest.attr.conditional}}
154 {% endif %}
155 {{'{'}}
156 .partition_id = {{manifest.manifest.name}}_ID,
157 {% if manifest.attr.tfm_partition_ipc %}
158 .partition_flags = SPM_PART_FLAG_IPC
159 {% else %}
160 .partition_flags = 0
161 {% endif %}
162 {% if manifest.manifest.type == "APPLICATION-ROT" %}
163 | SPM_PART_FLAG_APP_ROT
164 {% elif manifest.manifest.type == "PSA-ROT" %}
165 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
166 {% else %}
167#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
168 {% endif %}
169 ,
170 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
171 .partition_init = {{manifest.manifest.entry_point}},
172 {{'},'}}
173 {% if manifest.attr.conditional %}
174#endif /* {{manifest.attr.conditional}} */
175 {% endif %}
176
177{% endfor %}
178};
179
180/**************************************************************************/
181/** The platform data of the partition list */
182/**************************************************************************/
183const struct tfm_spm_partition_platform_data_t *platform_data_list[] =
184{
185 NULL,
186
187#ifndef TFM_PSA_API
188 NULL,
189#endif
190
191{% for manifest in manifests %}
192 {% if manifest.attr.conditional %}
193#ifdef {{manifest.attr.conditional}}
194 {% endif %}
195 {% if manifest.manifest.mmio_regions %}
196 /* FIXME: Only adding the first mmio region */
197 {% for region in manifest.manifest.mmio_regions %}
198 {% if loop.first %}
199 {% if region.conditional %}
200#ifdef {{region.conditional}}
201 {% endif %}
202 {{region.name}},
203 {% if region.conditional %}
204#else /* {{region.conditional}} */
205 NULL,
206#endif /* {{region.conditional}} */
207 {% endif %}
208 {% else %} {# print nothing #} {% endif %}
209 {% endfor %}
210 {% else %}
211 NULL,
212 {% endif %}
213 {% if manifest.attr.conditional %}
214#endif /* {{manifest.attr.conditional}} */
215 {% endif %}
216
217{% endfor %}
218};
219
220/**************************************************************************/
221/** The memory data of the partition list */
222/**************************************************************************/
223#ifdef TFM_PSA_API
224const struct tfm_spm_partition_memory_data_t memory_data_list[] =
225{
226 {
227 .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
228 .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit),
229 .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
230 },
231{% for manifest in manifests %}
232 {% if manifest.attr.conditional %}
233#ifdef {{manifest.attr.conditional}}
234 {% endif %}
235 {{'{'}}
236 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$Base),
237 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$Limit),
238 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Base),
239 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Limit),
240 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Base),
241 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Limit),
242 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Base),
243 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Limit),
244 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Base),
245 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit),
246 {{'},'}}
247 {% if manifest.attr.conditional %}
248#endif /* {{manifest.attr.conditional}} */
249 {% endif %}
250
251{% endfor %}
252};
253#endif /* defined(TFM_PSA_API) */
254
255/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200256/** The partition list for the DB */
257/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800258static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200259{
Summer Qin423dbef2019-08-22 15:59:35 +0800260 {{'{{}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800261#ifndef TFM_PSA_API
Summer Qin423dbef2019-08-22 15:59:35 +0800262 {{'{{}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800263#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200264
265{% for manifest in manifests %}
266 /* -----------------------------------------------------------------------*/
267 /* - Partition DB record for {{manifest.manifest.name}} */
268 /* -----------------------------------------------------------------------*/
269 {% if manifest.attr.conditional %}
270#ifdef {{manifest.attr.conditional}}
271 {% endif %}
272 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200273 /* Runtime data */
Summer Qin423dbef2019-08-22 15:59:35 +0800274 .runtime_data = {},
275 .static_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200276 .platform_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200277
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200278 {{'},'}}
279 {% if manifest.attr.conditional %}
280#endif /* {{manifest.attr.conditional}} */
281 {% endif %}
282
283{% endfor %}
284};
285
286struct spm_partition_db_t g_spm_partition_db = {
287 .is_init = 0,
288 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800289#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200290 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800291#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200292 .partitions = partition_list,
293};
294
295#endif /* __TFM_SPM_DB_INC__ */