blob: aecae88b688746f550f50836196c220b0e2cd880 [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,
142#if TFM_LVL != 1
143 .stack_ptr = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit) -
144 sizeof(struct iovec_args_t),
145#else /* TFM_LVL != 1 */
146 .stack_ptr = 0,
147#endif /* TFM_LVL != 1 */
148 .lr = 0,
149 .iovec_api = TFM_SFN_API_IOVEC,
150 .iovec_args =
151 {
152 .in_vec = {{'{{0}}'}},
153 .in_len = 0,
154 .out_vec = {{'{{0}}'}},
155 .out_len = 0,
156 },
157 .orig_outvec = NULL,
158 .ctx_stack_ptr = ctx_stack_{{manifest.manifest.name}},
Edison Ai66fbdf12019-07-08 16:05:07 +0800159#else /* !defined(TFM_PSA_API) */
160 .signal_evnt =
161 {
162 .magic = 0,
163 .owner = NULL,
164 },
165 .signals = 0,
166 .service_list =
167 {
168 .prev = NULL,
169 .next = NULL,
170 },
171#endif /* !defined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200172 .signal_mask = 0,
173 {{'},'}}
174
175 {% if manifest.manifest.mmio_regions %}
176 /* platform data */
177 /* FIXME: Only adding the first mmio region */
178 {% for region in manifest.manifest.mmio_regions %}
179 {% if loop.first %}
180 {% if region.conditional %}
181#ifdef {{region.conditional}}
182 {% endif %}
183 .platform_data = {{region.name}},
184 {% if region.conditional %}
185#else /* {{region.conditional}} */
186 .platform_data = NULL,
187#endif /* {{region.conditional}} */
188 {% endif %}
189 {% else %} {# print nothing #} {% endif %}
190 {% endfor %}
191 {% else %}
192 .platform_data = NULL,
193 {% endif %}
194
195#if (TFM_LVL != 1) || defined(TFM_PSA_API)
196 /* memory_data */
197 .memory_data = {{'{'}}
198 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$Base),
199 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$Limit),
200 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Base),
201 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Limit),
202 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Base),
203 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Limit),
204 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Base),
205 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Limit),
206 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Base),
207 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit),
208 {{'},'}}
209#endif
210
211#ifdef TFM_PSA_API
212 /* sp_thrd */
213 .sp_thrd = {
214 .pfn = NULL,
215 .param = NULL,
216 .sp_base = NULL,
217 .sp_top = NULL,
218 .prior = THRD_PRIOR_LOWEST,
219 .status = THRD_STAT_INVALID,
220 .state_ctx =
221 {
222 .ctxb = {0}, /* Fields are not detailed as they are architecture dependent*/
223 },
224 .next = NULL,
225 },
226#endif /* defined(TFM_PSA_API) */
227 {{'},'}}
228 {% if manifest.attr.conditional %}
229#endif /* {{manifest.attr.conditional}} */
230 {% endif %}
231
232{% endfor %}
233};
234
235struct spm_partition_db_t g_spm_partition_db = {
236 .is_init = 0,
237 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800238#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200239 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800240#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200241 .partitions = partition_list,
242};
243
244#endif /* __TFM_SPM_DB_INC__ */