blob: 8f424b8f7e923f918d09f861ecb4abce433e72fc [file] [log] [blame]
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +02001/*
TTornblom83d96372019-11-19 12:53:16 +01002 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8{{utilities.donotedit_warning}}
9
Shawn Shan071d86d2020-05-25 17:32:58 +080010#ifndef __TFM_SPM_DB_FUNC_INC__
11#define __TFM_SPM_DB_FUNC_INC__
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020012
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/**************************************************************************/
42{% for manifest in manifests %}
43 {% if manifest.attr.conditional %}
44#ifdef {{manifest.attr.conditional}}
45 {% endif %}
Edison Ai9c48d202019-10-12 16:57:21 +080046extern void {{manifest.manifest.entry_point}}(void);
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020047 {% if manifest.attr.conditional %}
48#endif /* {{manifest.attr.conditional}} */
49 {% endif %}
50
51{% endfor %}
52/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020053/** Context stacks for IRQ handling */
54/**************************************************************************/
55/* The max size of the context stack can be calculated as a function of the IRQ
56 * count of the secure partition:
57 *
58 * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size))
59 *
60 * where:
61 * intr_ctx: Frame pushed when the partition is interrupted
62 * hndl_ctx: Frame pushed when the partition is handling an interrupt
63 */
Summer Qin423dbef2019-08-22 15:59:35 +080064static uint32_t ns_interrupt_ctx_stack[
65 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
66
67static uint32_t tfm_core_interrupt_ctx_stack[
68 sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)];
69
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020070{% for manifest in manifests %}
71 {% if manifest.attr.conditional %}
72#ifdef {{manifest.attr.conditional}}
73 {% endif %}
74static uint32_t ctx_stack_{{manifest.manifest.name}}[
75 (sizeof(struct interrupted_ctx_stack_frame_t) +
76 (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * (
77 sizeof(struct interrupted_ctx_stack_frame_t) +
78 sizeof(struct handler_ctx_stack_frame_t)
79 )) / sizeof(uint32_t)];
80 {% if manifest.attr.conditional %}
81#endif /* {{manifest.attr.conditional}} */
82 {% endif %}
83
84{% endfor %}
Summer Qin423dbef2019-08-22 15:59:35 +080085uint32_t *ctx_stack_list[] =
86{
87 ns_interrupt_ctx_stack,
88 tfm_core_interrupt_ctx_stack,
89{% for manifest in manifests %}
90 {% if manifest.attr.conditional %}
91#ifdef {{manifest.attr.conditional}}
92 {% endif %}
93 ctx_stack_{{manifest.manifest.name}},
94 {% if manifest.attr.conditional %}
95#endif /* {{manifest.attr.conditional}} */
96 {% endif %}
97{% endfor %}
98};
Edison Ai66fbdf12019-07-08 16:05:07 +080099
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200100/**************************************************************************/
Edison Aie728fbf2019-11-13 09:37:12 +0800101/** Dependencies array for Secure Partition */
102/**************************************************************************/
103{% for manifest in manifests %}
104 {% if manifest.manifest.dependencies %}
105 {% if manifest.attr.conditional %}
106#ifdef {{manifest.attr.conditional}}
107 {% endif %}
108static int32_t dependencies_{{manifest.manifest.name}}[] =
109{
110 {% for dependence in manifest.manifest.dependencies %}
Edison Aib262cc42019-12-20 14:47:52 +0800111 {% for service in manifest.manifest.services %}
112 {% if dependence == service.name %}
113#error "Please DO NOT include SP's own RoT Service '{{dependence}}', which will cause a deadlock!"
114 {% endif %}
115 {% endfor %}
Edison Aie728fbf2019-11-13 09:37:12 +0800116 {{dependence}}_SID,
117 {% endfor %}
118};
119 {% if manifest.attr.conditional %}
120#endif /* {{manifest.attr.conditional}} */
121 {% endif %}
122
123 {% endif %}
124{% endfor %}
125/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800126/** The static data of the partition list */
127/**************************************************************************/
128const struct spm_partition_static_data_t static_data_list[] =
129{
130 {
131 .partition_id = TFM_SP_NON_SECURE_ID,
Summer Qin423dbef2019-08-22 15:59:35 +0800132 .partition_flags = 0,
Summer Qin423dbef2019-08-22 15:59:35 +0800133 },
134
Summer Qin423dbef2019-08-22 15:59:35 +0800135 {
136 .partition_id = TFM_SP_CORE_ID,
137 .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT,
138 },
Summer Qin423dbef2019-08-22 15:59:35 +0800139
140{% for manifest in manifests %}
141 {% if manifest.attr.conditional %}
142#ifdef {{manifest.attr.conditional}}
143 {% endif %}
144 {{'{'}}
Edison Aib2134e62019-10-11 18:24:47 +0800145 .partition_id = {{manifest.manifest.name}},
Summer Qin423dbef2019-08-22 15:59:35 +0800146 {% if manifest.attr.tfm_partition_ipc %}
147 .partition_flags = SPM_PART_FLAG_IPC
148 {% else %}
149 .partition_flags = 0
150 {% endif %}
151 {% if manifest.manifest.type == "APPLICATION-ROT" %}
152 | SPM_PART_FLAG_APP_ROT
153 {% elif manifest.manifest.type == "PSA-ROT" %}
154 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
155 {% else %}
156#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
157 {% endif %}
158 ,
159 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
160 .partition_init = {{manifest.manifest.entry_point}},
Edison Aie728fbf2019-11-13 09:37:12 +0800161 .dependencies_num = {{manifest.manifest.dependencies | length()}},
162 {% if manifest.manifest.dependencies %}
163 .p_dependencies = dependencies_{{manifest.manifest.name}},
164 {% else %}
165 .p_dependencies = NULL,
166 {% endif %}
Summer Qin423dbef2019-08-22 15:59:35 +0800167 {{'},'}}
168 {% if manifest.attr.conditional %}
169#endif /* {{manifest.attr.conditional}} */
170 {% endif %}
171
172{% endfor %}
173};
174
175/**************************************************************************/
176/** The platform data of the partition list */
177/**************************************************************************/
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100178{% for manifest in manifests %}
179 {% if manifest.manifest.mmio_regions %}
180 {% if manifest.attr.conditional %}
181#ifdef {{manifest.attr.conditional}}
182 {% endif %}
183const struct tfm_spm_partition_platform_data_t *
184 platform_data_list_{{manifest.manifest.name}}[] =
185{
186 {% for region in manifest.manifest.mmio_regions %}
187 {% if region.conditional %}
188#ifdef {{region.conditional}}
189 {% endif %}
190 {{region.name}},
191 {% if region.conditional %}
192#endif /* {{region.conditional}} */
193 {% endif %}
194 {% endfor %}
195 NULL
196};
197 {% if manifest.attr.conditional %}
198#endif /* {{manifest.attr.conditional}} */
199 {% endif %}
200
201 {% endif %}
202{% endfor %}
203const struct tfm_spm_partition_platform_data_t **platform_data_list_list[] =
Summer Qin423dbef2019-08-22 15:59:35 +0800204{
205 NULL,
Summer Qin423dbef2019-08-22 15:59:35 +0800206 NULL,
Summer Qin423dbef2019-08-22 15:59:35 +0800207
208{% for manifest in manifests %}
209 {% if manifest.attr.conditional %}
210#ifdef {{manifest.attr.conditional}}
211 {% endif %}
212 {% if manifest.manifest.mmio_regions %}
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100213 platform_data_list_{{manifest.manifest.name}},
214 {% else %}{# if manifest.manifest.mmio_regions #}
Summer Qin423dbef2019-08-22 15:59:35 +0800215 NULL,
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100216 {% endif %}{# if manifest.manifest.mmio_regions #}
Summer Qin423dbef2019-08-22 15:59:35 +0800217 {% if manifest.attr.conditional %}
218#endif /* {{manifest.attr.conditional}} */
219 {% endif %}
220
221{% endfor %}
222};
223
224/**************************************************************************/
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200225/** The partition list for the DB */
226/**************************************************************************/
Summer Qin423dbef2019-08-22 15:59:35 +0800227static struct spm_partition_desc_t partition_list [] =
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200228{
TTornblom83d96372019-11-19 12:53:16 +0100229 {{'{{0}}'}}, /* placeholder for Non-secure internal partition */
TTornblom83d96372019-11-19 12:53:16 +0100230 {{'{{0}}'}}, /* placeholder for TF-M Core internal partition */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200231
232{% for manifest in manifests %}
233 /* -----------------------------------------------------------------------*/
234 /* - Partition DB record for {{manifest.manifest.name}} */
235 /* -----------------------------------------------------------------------*/
236 {% if manifest.attr.conditional %}
237#ifdef {{manifest.attr.conditional}}
238 {% endif %}
239 {{'{'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200240 /* Runtime data */
TTornblom83d96372019-11-19 12:53:16 +0100241 .runtime_data = {0},
Summer Qin423dbef2019-08-22 15:59:35 +0800242 .static_data = NULL,
Mate Toth-Pal8ac98a72019-11-21 17:30:10 +0100243 .platform_data_list = NULL,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200244 {{'},'}}
245 {% if manifest.attr.conditional %}
246#endif /* {{manifest.attr.conditional}} */
247 {% endif %}
248
249{% endfor %}
250};
251
252struct spm_partition_db_t g_spm_partition_db = {
253 .is_init = 0,
254 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
255 .running_partition_idx = 0,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200256 .partitions = partition_list,
257};
258
Shawn Shan071d86d2020-05-25 17:32:58 +0800259#endif /* __TFM_SPM_DB_FUNC_INC__ */