blob: 27afe4035b098b2ad5aad9ff29769a0e94a60a2a [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 */
103 {{'{{0}}'}}, /* placeholder for TF-M Core internal partition */
104
105{% for manifest in manifests %}
106 /* -----------------------------------------------------------------------*/
107 /* - Partition DB record for {{manifest.manifest.name}} */
108 /* -----------------------------------------------------------------------*/
109 {% if manifest.attr.conditional %}
110#ifdef {{manifest.attr.conditional}}
111 {% endif %}
112 {{'{'}}
113 /* Static data */
114 {{'{'}}
115 .partition_id = {{manifest.manifest.name}}_ID,
116 {% if manifest.attr.tfm_partition_ipc %}
117 .partition_flags = SPM_PART_FLAG_IPC
118 {% else %}
119 .partition_flags = 0
120 {% endif %}
121 {% if manifest.manifest.type == "APPLICATION-ROT" %}
122 | SPM_PART_FLAG_APP_ROT
123 {% elif manifest.manifest.type == "PSA-ROT" %}
124 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
125 {% else %}
126#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
127 {% endif %}
128 ,
129 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
130 .partition_init = {{manifest.manifest.entry_point}},
131 {{'},'}}
132
133 /* Runtime data */
134 {{'{'}}
Edison Ai66fbdf12019-07-08 16:05:07 +0800135#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200136 .partition_state = SPM_PARTITION_STATE_UNINIT,
137 .caller_partition_idx = SPM_INVALID_PARTITION_IDX,
138 .caller_client_id = TFM_INVALID_CLIENT_ID,
139 .share = TFM_BUFFER_SHARE_DISABLE,
140#if TFM_LVL != 1
141 .stack_ptr = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit) -
142 sizeof(struct iovec_args_t),
143#else /* TFM_LVL != 1 */
144 .stack_ptr = 0,
145#endif /* TFM_LVL != 1 */
146 .lr = 0,
147 .iovec_api = TFM_SFN_API_IOVEC,
148 .iovec_args =
149 {
150 .in_vec = {{'{{0}}'}},
151 .in_len = 0,
152 .out_vec = {{'{{0}}'}},
153 .out_len = 0,
154 },
155 .orig_outvec = NULL,
156 .ctx_stack_ptr = ctx_stack_{{manifest.manifest.name}},
Edison Ai66fbdf12019-07-08 16:05:07 +0800157#else /* !defined(TFM_PSA_API) */
158 .signal_evnt =
159 {
160 .magic = 0,
161 .owner = NULL,
162 },
163 .signals = 0,
164 .service_list =
165 {
166 .prev = NULL,
167 .next = NULL,
168 },
169#endif /* !defined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200170 .signal_mask = 0,
171 {{'},'}}
172
173 {% if manifest.manifest.mmio_regions %}
174 /* platform data */
175 /* FIXME: Only adding the first mmio region */
176 {% for region in manifest.manifest.mmio_regions %}
177 {% if loop.first %}
178 {% if region.conditional %}
179#ifdef {{region.conditional}}
180 {% endif %}
181 .platform_data = {{region.name}},
182 {% if region.conditional %}
183#else /* {{region.conditional}} */
184 .platform_data = NULL,
185#endif /* {{region.conditional}} */
186 {% endif %}
187 {% else %} {# print nothing #} {% endif %}
188 {% endfor %}
189 {% else %}
190 .platform_data = NULL,
191 {% endif %}
192
193#if (TFM_LVL != 1) || defined(TFM_PSA_API)
194 /* memory_data */
195 .memory_data = {{'{'}}
196 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$Base),
197 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$Limit),
198 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Base),
199 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Limit),
200 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Base),
201 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Limit),
202 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Base),
203 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Limit),
204 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Base),
205 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit),
206 {{'},'}}
207#endif
208
209#ifdef TFM_PSA_API
210 /* sp_thrd */
211 .sp_thrd = {
212 .pfn = NULL,
213 .param = NULL,
214 .sp_base = NULL,
215 .sp_top = NULL,
216 .prior = THRD_PRIOR_LOWEST,
217 .status = THRD_STAT_INVALID,
218 .state_ctx =
219 {
220 .ctxb = {0}, /* Fields are not detailed as they are architecture dependent*/
221 },
222 .next = NULL,
223 },
224#endif /* defined(TFM_PSA_API) */
225 {{'},'}}
226 {% if manifest.attr.conditional %}
227#endif /* {{manifest.attr.conditional}} */
228 {% endif %}
229
230{% endfor %}
231};
232
233struct spm_partition_db_t g_spm_partition_db = {
234 .is_init = 0,
235 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
Edison Ai66fbdf12019-07-08 16:05:07 +0800236#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200237 .running_partition_idx = 0,
Edison Ai66fbdf12019-07-08 16:05:07 +0800238#endif
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +0200239 .partitions = partition_list,
240};
241
242#endif /* __TFM_SPM_DB_INC__ */