blob: 2b52b4de2414233fa7af7932f63695e60215a4ff [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 %}
67/**************************************************************************/
68/** Context stacks for IRQ handling */
69/**************************************************************************/
70/* The max size of the context stack can be calculated as a function of the IRQ
71 * count of the secure partition:
72 *
73 * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size))
74 *
75 * where:
76 * intr_ctx: Frame pushed when the partition is interrupted
77 * hndl_ctx: Frame pushed when the partition is handling an interrupt
78 */
79{% for manifest in manifests %}
80 {% if manifest.attr.conditional %}
81#ifdef {{manifest.attr.conditional}}
82 {% endif %}
83static uint32_t ctx_stack_{{manifest.manifest.name}}[
84 (sizeof(struct interrupted_ctx_stack_frame_t) +
85 (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * (
86 sizeof(struct interrupted_ctx_stack_frame_t) +
87 sizeof(struct handler_ctx_stack_frame_t)
88 )) / sizeof(uint32_t)];
89 {% if manifest.attr.conditional %}
90#endif /* {{manifest.attr.conditional}} */
91 {% endif %}
92
93{% endfor %}
94/**************************************************************************/
95/** The partition list for the DB */
96/**************************************************************************/
97struct spm_partition_desc_t partition_list [] =
98{
99 {{'{{0}}'}}, /* placeholder for Non-secure internal partition */
100 {{'{{0}}'}}, /* placeholder for TF-M Core internal partition */
101
102{% for manifest in manifests %}
103 /* -----------------------------------------------------------------------*/
104 /* - Partition DB record for {{manifest.manifest.name}} */
105 /* -----------------------------------------------------------------------*/
106 {% if manifest.attr.conditional %}
107#ifdef {{manifest.attr.conditional}}
108 {% endif %}
109 {{'{'}}
110 /* Static data */
111 {{'{'}}
112 .partition_id = {{manifest.manifest.name}}_ID,
113 {% if manifest.attr.tfm_partition_ipc %}
114 .partition_flags = SPM_PART_FLAG_IPC
115 {% else %}
116 .partition_flags = 0
117 {% endif %}
118 {% if manifest.manifest.type == "APPLICATION-ROT" %}
119 | SPM_PART_FLAG_APP_ROT
120 {% elif manifest.manifest.type == "PSA-ROT" %}
121 | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT
122 {% else %}
123#error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!"
124 {% endif %}
125 ,
126 .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}),
127 .partition_init = {{manifest.manifest.entry_point}},
128 {{'},'}}
129
130 /* Runtime data */
131 {{'{'}}
132 .partition_state = SPM_PARTITION_STATE_UNINIT,
133 .caller_partition_idx = SPM_INVALID_PARTITION_IDX,
134 .caller_client_id = TFM_INVALID_CLIENT_ID,
135 .share = TFM_BUFFER_SHARE_DISABLE,
136#if TFM_LVL != 1
137 .stack_ptr = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit) -
138 sizeof(struct iovec_args_t),
139#else /* TFM_LVL != 1 */
140 .stack_ptr = 0,
141#endif /* TFM_LVL != 1 */
142 .lr = 0,
143 .iovec_api = TFM_SFN_API_IOVEC,
144 .iovec_args =
145 {
146 .in_vec = {{'{{0}}'}},
147 .in_len = 0,
148 .out_vec = {{'{{0}}'}},
149 .out_len = 0,
150 },
151 .orig_outvec = NULL,
152 .ctx_stack_ptr = ctx_stack_{{manifest.manifest.name}},
153 .signal_mask = 0,
154 {{'},'}}
155
156 {% if manifest.manifest.mmio_regions %}
157 /* platform data */
158 /* FIXME: Only adding the first mmio region */
159 {% for region in manifest.manifest.mmio_regions %}
160 {% if loop.first %}
161 {% if region.conditional %}
162#ifdef {{region.conditional}}
163 {% endif %}
164 .platform_data = {{region.name}},
165 {% if region.conditional %}
166#else /* {{region.conditional}} */
167 .platform_data = NULL,
168#endif /* {{region.conditional}} */
169 {% endif %}
170 {% else %} {# print nothing #} {% endif %}
171 {% endfor %}
172 {% else %}
173 .platform_data = NULL,
174 {% endif %}
175
176#if (TFM_LVL != 1) || defined(TFM_PSA_API)
177 /* memory_data */
178 .memory_data = {{'{'}}
179 .code_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$Base),
180 .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$Limit),
181 .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Base),
182 .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}, $$RO$$Limit),
183 .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Base),
184 .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$RW$$Limit),
185 .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Base),
186 .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}, _DATA$$ZI$$Limit),
187 .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Base),
188 .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}, _STACK$$ZI$$Limit),
189 {{'},'}}
190#endif
191
192#ifdef TFM_PSA_API
193 /* sp_thrd */
194 .sp_thrd = {
195 .pfn = NULL,
196 .param = NULL,
197 .sp_base = NULL,
198 .sp_top = NULL,
199 .prior = THRD_PRIOR_LOWEST,
200 .status = THRD_STAT_INVALID,
201 .state_ctx =
202 {
203 .ctxb = {0}, /* Fields are not detailed as they are architecture dependent*/
204 },
205 .next = NULL,
206 },
207#endif /* defined(TFM_PSA_API) */
208 {{'},'}}
209 {% if manifest.attr.conditional %}
210#endif /* {{manifest.attr.conditional}} */
211 {% endif %}
212
213{% endfor %}
214};
215
216struct spm_partition_db_t g_spm_partition_db = {
217 .is_init = 0,
218 .partition_count = sizeof(partition_list) / sizeof(partition_list[0]),
219 .running_partition_idx = 0,
220 .partitions = partition_list,
221};
222
223#endif /* __TFM_SPM_DB_INC__ */