blob: f0528cda07ba0e3156d27c7b151c018828738d72 [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/**************************************************************************/
35{% for manifest in manifests %}
36 {% if manifest.attr.conditional %}
37#ifdef {{manifest.attr.conditional}}
38 {% endif %}
39extern int32_t {{manifest.manifest.entry_point}}(void);
40 {% if manifest.attr.conditional %}
41#endif /* {{manifest.attr.conditional}} */
42 {% endif %}
43
44{% endfor %}
45/**************************************************************************/
46/** Memory region declarations */
47/**************************************************************************/
48{% for manifest in manifests %}
49 {% if manifest.attr.conditional %}
50#ifdef {{manifest.attr.conditional}}
51 {% endif %}
52REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$Base);
53REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$Limit);
54REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$RO$$Base);
55REGION_DECLARE(Image$$, {{manifest.manifest.name}}, $$RO$$Limit);
56REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$RW$$Base);
57REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$RW$$Limit);
58REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$ZI$$Base);
59REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _DATA$$ZI$$Limit);
60REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _STACK$$ZI$$Base);
61REGION_DECLARE(Image$$, {{manifest.manifest.name}}, _STACK$$ZI$$Limit);
62 {% if manifest.attr.conditional %}
63#endif /* {{manifest.attr.conditional}} */
64 {% endif %}
65
66{% endfor %}
Edison Ai66fbdf12019-07-08 16:05:07 +080067#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020068/**************************************************************************/
69/** Context stacks for IRQ handling */
70/**************************************************************************/
71/* The max size of the context stack can be calculated as a function of the IRQ
72 * count of the secure partition:
73 *
74 * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size))
75 *
76 * where:
77 * intr_ctx: Frame pushed when the partition is interrupted
78 * hndl_ctx: Frame pushed when the partition is handling an interrupt
79 */
80{% for manifest in manifests %}
81 {% if manifest.attr.conditional %}
82#ifdef {{manifest.attr.conditional}}
83 {% endif %}
84static uint32_t ctx_stack_{{manifest.manifest.name}}[
85 (sizeof(struct interrupted_ctx_stack_frame_t) +
86 (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * (
87 sizeof(struct interrupted_ctx_stack_frame_t) +
88 sizeof(struct handler_ctx_stack_frame_t)
89 )) / sizeof(uint32_t)];
90 {% if manifest.attr.conditional %}
91#endif /* {{manifest.attr.conditional}} */
92 {% endif %}
93
94{% endfor %}
Edison Ai66fbdf12019-07-08 16:05:07 +080095#endif /* !defined(TFM_PSA_API) */
96
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020097/**************************************************************************/
98/** The partition list for the DB */
99/**************************************************************************/
100struct spm_partition_desc_t partition_list [] =
101{
102 {{'{{0}}'}}, /* placeholder for Non-secure internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800103#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200104 {{'{{0}}'}}, /* placeholder for TF-M Core internal partition */
Mingyang Sunda01a972019-07-12 17:32:59 +0800105#endif /* !ifndefined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200106
107{% for manifest in manifests %}
108 /* -----------------------------------------------------------------------*/
109 /* - Partition DB record for {{manifest.manifest.name}} */
110 /* -----------------------------------------------------------------------*/
111 {% if manifest.attr.conditional %}
112#ifdef {{manifest.attr.conditional}}
113 {% endif %}
114 {{'{'}}
115 /* Static data */
116 {{'{'}}
117 .partition_id = {{manifest.manifest.name}}_ID,
118 {% if manifest.attr.tfm_partition_ipc %}
119 .partition_flags = SPM_PART_FLAG_IPC
120 {% else %}
121 .partition_flags = 0
122 {% endif %}
123 {% if manifest.manifest.type == "APPLICATION-ROT" %}
124 | SPM_PART_FLAG_APP_ROT
125 {% elif manifest.manifest.type == "PSA-ROT" %}
126 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
127 {% else %}
128#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
129 {% endif %}
130 ,
131 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
132 .partition_init = {{manifest.manifest.entry_point}},
133 {{'},'}}
134
135 /* Runtime data */
136 {{'{'}}
Edison Ai66fbdf12019-07-08 16:05:07 +0800137#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200138 .partition_state = SPM_PARTITION_STATE_UNINIT,
139 .caller_partition_idx = SPM_INVALID_PARTITION_IDX,
140 .caller_client_id = TFM_INVALID_CLIENT_ID,
141 .share = TFM_BUFFER_SHARE_DISABLE,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200142 .stack_ptr = 0,
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200143 .lr = 0,
144 .iovec_api = TFM_SFN_API_IOVEC,
145 .iovec_args =
146 {
147 .in_vec = {{'{{0}}'}},
148 .in_len = 0,
149 .out_vec = {{'{{0}}'}},
150 .out_len = 0,
151 },
152 .orig_outvec = NULL,
153 .ctx_stack_ptr = ctx_stack_{{manifest.manifest.name}},
Edison Ai66fbdf12019-07-08 16:05:07 +0800154#else /* !defined(TFM_PSA_API) */
155 .signal_evnt =
156 {
157 .magic = 0,
158 .owner = NULL,
159 },
160 .signals = 0,
161 .service_list =
162 {
163 .prev = NULL,
164 .next = NULL,
165 },
166#endif /* !defined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200167 .signal_mask = 0,
168 {{'},'}}
169
170 {% if manifest.manifest.mmio_regions %}
171 /* platform data */
172 /* FIXME: Only adding the first mmio region */
173 {% for region in manifest.manifest.mmio_regions %}
174 {% if loop.first %}
175 {% if region.conditional %}
176#ifdef {{region.conditional}}
177 {% endif %}
178 .platform_data = {{region.name}},
179 {% if region.conditional %}
180#else /* {{region.conditional}} */
181 .platform_data = NULL,
182#endif /* {{region.conditional}} */
183 {% endif %}
184 {% else %} {# print nothing #} {% endif %}
185 {% endfor %}
186 {% else %}
187 .platform_data = NULL,
188 {% endif %}
189
Edison Ai7aff9e82019-07-11 14:56:46 +0800190#ifdef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200191 /* memory_data */
192 .memory_data = {{'{'}}
193 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$Base),
194 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$Limit),
195 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Base),
196 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Limit),
197 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Base),
198 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Limit),
199 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Base),
200 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Limit),
201 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Base),
202 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit),
203 {{'},'}}
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200204
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200205 /* sp_thrd */
206 .sp_thrd = {
207 .pfn = NULL,
208 .param = NULL,
209 .sp_base = NULL,
210 .sp_top = NULL,
211 .prior = THRD_PRIOR_LOWEST,
212 .status = THRD_STAT_INVALID,
213 .state_ctx =
214 {
215 .ctxb = {0}, /* Fields are not detailed as they are architecture dependent*/
216 },
217 .next = NULL,
218 },
219#endif /* defined(TFM_PSA_API) */
220 {{'},'}}
221 {% if manifest.attr.conditional %}
222#endif /* {{manifest.attr.conditional}} */
223 {% endif %}
224
225{% endfor %}
226};
227
228struct spm_partition_db_t g_spm_partition_db = {
229 .is_init = 0,
230 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800231#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200232 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800233#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200234 .partitions = partition_list,
235};
236
237#endif /* __TFM_SPM_DB_INC__ */