blob: c3bb13cb9a64fed63962e022b0e3f920a61041c3 [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
David Hu90128b72019-09-23 16:35:41 +0800136#if TFM_MULTI_CORE_TOPOLOGY
137 .partition_flags = SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_IPC,
138#else
Summer Qin423dbef2019-08-22 15:59:35 +0800139 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC,
David Hu90128b72019-09-23 16:35:41 +0800140#endif
Summer Qin423dbef2019-08-22 15:59:35 +0800141 .partition_priority = TFM_PRIORITY_LOW,
142 .partition_init = tfm_nspm_thread_entry,
143#else
144 .partition_flags = 0,
145#endif
146 },
147
148#ifndef TFM_PSA_API
149 {
150 .partition_id = TFM_SP_CORE_ID,
151 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
152 },
153#endif
154
155{% for manifest in manifests %}
156 {% if manifest.attr.conditional %}
157#ifdef {{manifest.attr.conditional}}
158 {% endif %}
159 {{'{'}}
160 .partition_id = {{manifest.manifest.name}}_ID,
161 {% if manifest.attr.tfm_partition_ipc %}
162 .partition_flags = SPM_PART_FLAG_IPC
163 {% else %}
164 .partition_flags = 0
165 {% endif %}
166 {% if manifest.manifest.type == "APPLICATION-ROT" %}
167 | SPM_PART_FLAG_APP_ROT
168 {% elif manifest.manifest.type == "PSA-ROT" %}
169 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
170 {% else %}
171#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
172 {% endif %}
173 ,
174 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
175 .partition_init = {{manifest.manifest.entry_point}},
176 {{'},'}}
177 {% if manifest.attr.conditional %}
178#endif /* {{manifest.attr.conditional}} */
179 {% endif %}
180
181{% endfor %}
182};
183
184/**************************************************************************/
185/** The platform data of the partition list */
186/**************************************************************************/
187const struct tfm_spm_partition_platform_data_t *platform_data_list[] =
188{
189 NULL,
190
191#ifndef TFM_PSA_API
192 NULL,
193#endif
194
195{% for manifest in manifests %}
196 {% if manifest.attr.conditional %}
197#ifdef {{manifest.attr.conditional}}
198 {% endif %}
199 {% if manifest.manifest.mmio_regions %}
200 /* FIXME: Only adding the first mmio region */
201 {% for region in manifest.manifest.mmio_regions %}
202 {% if loop.first %}
203 {% if region.conditional %}
204#ifdef {{region.conditional}}
205 {% endif %}
206 {{region.name}},
207 {% if region.conditional %}
208#else /* {{region.conditional}} */
209 NULL,
210#endif /* {{region.conditional}} */
211 {% endif %}
212 {% else %} {# print nothing #} {% endif %}
213 {% endfor %}
214 {% else %}
215 NULL,
216 {% endif %}
217 {% if manifest.attr.conditional %}
218#endif /* {{manifest.attr.conditional}} */
219 {% endif %}
220
221{% endfor %}
222};
223
224/**************************************************************************/
225/** The memory data of the partition list */
226/**************************************************************************/
227#ifdef TFM_PSA_API
228const struct tfm_spm_partition_memory_data_t memory_data_list[] =
229{
230 {
231 .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
232 .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit),
233 .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base),
234 },
235{% for manifest in manifests %}
236 {% if manifest.attr.conditional %}
237#ifdef {{manifest.attr.conditional}}
238 {% endif %}
239 {{'{'}}
240 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$Base),
241 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$Limit),
242 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Base),
243 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Limit),
244 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Base),
245 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Limit),
246 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Base),
247 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Limit),
248 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Base),
249 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit),
250 {{'},'}}
251 {% if manifest.attr.conditional %}
252#endif /* {{manifest.attr.conditional}} */
253 {% endif %}
254
255{% endfor %}
256};
257#endif /* defined(TFM_PSA_API) */
258
259/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200260/** The partition list for the DB */
261/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800262static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200263{
Summer Qin423dbef2019-08-22 15:59:35 +0800264 {{'{{}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800265#ifndef TFM_PSA_API
Summer Qin423dbef2019-08-22 15:59:35 +0800266 {{'{{}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800267#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200268
269{% for manifest in manifests %}
270 /* -----------------------------------------------------------------------*/
271 /* - Partition DB record for {{manifest.manifest.name}} */
272 /* -----------------------------------------------------------------------*/
273 {% if manifest.attr.conditional %}
274#ifdef {{manifest.attr.conditional}}
275 {% endif %}
276 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200277 /* Runtime data */
Summer Qin423dbef2019-08-22 15:59:35 +0800278 .runtime_data = {},
279 .static_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200280 .platform_data = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200281
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200282 {{'},'}}
283 {% if manifest.attr.conditional %}
284#endif /* {{manifest.attr.conditional}} */
285 {% endif %}
286
287{% endfor %}
288};
289
290struct spm_partition_db_t g_spm_partition_db = {
291 .is_init = 0,
292 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800293#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200294 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800295#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200296 .partitions = partition_list,
297};
298
299#endif /* __TFM_SPM_DB_INC__ */