blob: 3f2137ad76bb5da63fe15067007b168e6a89bcc7 [file] [log] [blame]
Mingyang Sunf6a78572021-04-02 16:51:05 +08001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8{{utilities.donotedit_warning}}
9
10#include <stdint.h>
11#include <stddef.h>
12#include "region.h"
Ken Liuea45b0d2021-05-22 17:41:25 +080013#include "spm_ipc.h"
Ken Liu3dd92562021-08-17 16:22:54 +080014#include "load/interrupt_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080015#include "load/partition_defs.h"
16#include "load/service_defs.h"
Ken Liu86686282021-04-27 11:11:15 +080017#include "load/asset_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080018#include "tfm_peripherals_def.h"
19#include "psa_manifest/pid.h"
20#include "psa_manifest/sid.h"
Ken Liu861b0782021-05-22 13:15:08 +080021#include "psa_manifest/{{manifest_out_basename}}.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080022
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080023{% set counter = namespace() %}
24{% set counter.dep_counter = manifest.dependencies|count %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080025#define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}})
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080026{% set counter.service_counter = manifest.services|count %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080027#define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}})
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080028{% set counter.asset_counter = manifest.mmio_regions|count %}
Ken Liu86686282021-04-27 11:11:15 +080029#if TFM_LVL == 3
30#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1)
31#else
32#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}})
33#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080034{% set counter.irq_counter = manifest.irqs|count %}
Kevin Peng27e42272021-05-24 17:58:53 +080035#define {{"%-55s"|format(manifest.name|upper + "_NIRQS")}} ({{"%d"|format(counter.irq_counter)}})
Mingyang Sunf6a78572021-04-02 16:51:05 +080036
37/* Memory region declaration */
38#if TFM_LVL == 3
39REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base);
40REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base);
41#endif
42extern uint8_t {{manifest.name|lower}}_stack[];
43
Shawn Shancaefb8f2021-04-15 14:19:13 +080044{% if manifest.entry_init and manifest.entry_point %}
45#error "Both manifest.entry_init and manifest.entry_point exist, unsupported!"
46{% elif (manifest.model == "IPC" or manifest.psa_framework_version == 1.0) and (not manifest.entry_point) %}
47#error "The entry_point attribute is required, it should not be empty!"
48{% elif manifest.model == "SFN" and manifest.entry_point %}
49#error "The entry_point attribute should not be exist in SFN mode!"
50{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080051/* Entrypoint function declaration */
Shawn Shancaefb8f2021-04-15 14:19:13 +080052{% if manifest.entry_point %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080053extern void {{manifest.entry_point}}(void);
Shawn Shancaefb8f2021-04-15 14:19:13 +080054{% elif manifest.entry_init %}
55extern psa_status_t {{manifest.entry_init}}(void);
56{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080057
Kevin Pengec239bb2021-09-03 15:40:27 +080058/* Interrupt init functions */
59{% if counter.irq_counter > 0 %}
60 {% for irq in manifest.irqs %}
61 {% if irq.source is number %}}
62extern enum tfm_hal_status_t {{"irq_" + irq.source|string + "_init"}}(void *p_pt,
63 struct irq_load_info_t *p_ildi);
64 {% else %}
65extern enum tfm_hal_status_t {{irq.source|lower + "_init"}}(void *p_pt,
66 struct irq_load_info_t *p_ildi);
67 {% endif %}
68 {% endfor %}
69{% endif %}
70
Mingyang Sun8d004f72021-06-01 10:46:26 +080071/* partition load info type definition */
Ken Liu4520ce32021-05-11 22:49:10 +080072struct partition_{{manifest.name|lower}}_load_info_t {
Mingyang Sun8d004f72021-06-01 10:46:26 +080073 /* common length load data */
74 struct partition_load_info_t load_info;
75 /* per-partition variable length load data */
Ken Liuacd2a572021-05-12 16:19:04 +080076 uintptr_t stack_addr;
77 uintptr_t heap_addr;
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080078{% if counter.dep_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080079 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}];
80{% endif %}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080081{% if counter.service_counter > 0 %}
Ken Liuacd2a572021-05-12 16:19:04 +080082 struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}];
Mingyang Sunf6a78572021-04-02 16:51:05 +080083{% endif %}
Ken Liu86686282021-04-27 11:11:15 +080084#if TFM_LVL == 3
85 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
86#else
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080087{% if counter.asset_counter > 0 %}
Ken Liu86686282021-04-27 11:11:15 +080088 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
89{% endif %}
90#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080091{% if counter.irq_counter > 0 %}
Kevin Peng27e42272021-05-24 17:58:53 +080092 struct irq_load_info_t irqs[{{(manifest.name|upper + "_NIRQS")}}];
93{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080094} __attribute__((aligned(4)));
95
Mingyang Sun8d004f72021-06-01 10:46:26 +080096/* Partition load, deps, service load data. Put to a dedicated section. */
Michel Jaouenf9de50e2021-08-03 17:42:30 +020097#if defined(__ICCARM__)
98#pragma location = ".part_load"
99__root
100#endif /* __ICCARM__ */
Mingyang Sun8d004f72021-06-01 10:46:26 +0800101const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load
102 __attribute__((used, section(".part_load"))) = {
103 .load_info = {
Mingyang Sunf6a78572021-04-02 16:51:05 +0800104{% if manifest.psa_framework_version == 1.0 %}
105 .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC,
106{% elif manifest.psa_framework_version == 1.1 %}
107 .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC,
108{% else %}
109#error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!"
110{% endif %}
111 .pid = {{manifest.name}},
112 .flags = 0
Shawn Shancaefb8f2021-04-15 14:19:13 +0800113{% if (manifest.psa_framework_version == 1.1 and manifest.model == "IPC") or manifest.psa_framework_version == 1.0 %}
Ken Liu59728d02021-10-06 12:47:39 +0800114 | PARTITION_MODEL_IPC
Mingyang Sunf6a78572021-04-02 16:51:05 +0800115{% endif %}
116{% if manifest.type == "PSA-ROT" %}
Shawn Shana3657e82021-10-18 14:37:09 +0800117 | PARTITION_MODEL_PSA_ROT
Mingyang Sunf6a78572021-04-02 16:51:05 +0800118{% elif manifest.type != "APPLICATION-ROT" %}
119#error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!"
120{% endif %}
121 | PARTITION_PRI_{{manifest.priority}},
Shawn Shancaefb8f2021-04-15 14:19:13 +0800122{% if manifest.entry_point %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800123 .entry = ENTRY_TO_POSITION({{manifest.entry_point}}),
Shawn Shancaefb8f2021-04-15 14:19:13 +0800124{% elif manifest.entry_init %}
125 .entry = ENTRY_TO_POSITION({{manifest.entry_init}}),
126{% else %}
127 .entry = NULL,
128{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800129 .stack_size = {{manifest.stack_size}},
130 .heap_size = 0,
131 .ndeps = {{(manifest.name|upper + "_NDEPS")}},
132 .nservices = {{(manifest.name|upper + "_NSERVS")}},
Ken Liu86686282021-04-27 11:11:15 +0800133 .nassets = {{(manifest.name|upper + "_NASSETS")}},
Kevin Peng27e42272021-05-24 17:58:53 +0800134 .nirqs = {{(manifest.name|upper + "_NIRQS")}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800135 },
Ken Liuacd2a572021-05-12 16:19:04 +0800136 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack,
137 .heap_addr = 0,
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800138{% if counter.dep_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800139 .deps = {
140 {% for dep in manifest.dependencies %}
141 {{dep}}_SID,
142 {% endfor %}
143 },
144{% endif %}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800145{% if counter.service_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800146 .services = {
147 {% for service in manifest.services %}
148 {
149 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"),
Shawn Shancaefb8f2021-04-15 14:19:13 +0800150{% if manifest.psa_framework_version == 1.1 and manifest.model == "SFN" %}
151 .sfn = ENTRY_TO_POSITION({{service.name|lower}}_sfn),
152{% else %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800153 .signal = {{service.name}}_SIGNAL,
Shawn Shancaefb8f2021-04-15 14:19:13 +0800154{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800155 .sid = {{service.sid}},
156 .flags = 0
157 {% if service.non_secure_clients is sameas true %}
158 | SERVICE_FLAG_NS_ACCESSIBLE
159 {% endif %}
160 {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %}
Mingyang Suna03ad022021-06-01 20:41:15 +0800161 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800162 {% endif %}
Shawn Shan7d88ae92021-09-09 15:32:02 +0800163 {% if manifest.psa_framework_version > 1.0 and service.mm_iovec == "enable" %}
164 | SERVICE_FLAG_MM_IOVEC
165 {% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800166 {% if service.version_policy %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800167 | SERVICE_VERSION_POLICY_{{service.version_policy}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800168 {% else %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800169 | SERVICE_VERSION_POLICY_STRICT,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800170 {% endif %}
171 {% if service.version %}
172 .version = {{service.version}},
173 {% else %}
174 .version = 1,
175 {% endif %}
176 },
177 {% endfor %}
178 },
179{% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800180#if TFM_LVL == 3
181 .assets = {
182 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800183 .mem.start = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base),
184 .mem.limit = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base),
185 .attr = ASSET_ATTR_READ_WRITE,
Ken Liu86686282021-04-27 11:11:15 +0800186 },
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800187{% if counter.asset_counter > 0 %}
188 {% for region in manifest.mmio_regions %}
189 {% if region.conditional %}
Ken Liu86686282021-04-27 11:11:15 +0800190#ifdef {{region.conditional}}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800191 {% endif %}
Mingyang Sundf02b852021-07-27 14:29:25 +0800192 {% if region.base and region.size %}
Ken Liu86686282021-04-27 11:11:15 +0800193 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800194 .mem.start = {{region.base}},
195 .mem.limit = {{region.base}} + {{region.size}},
196 .attr = ASSET_ATTR_NUMBERED_MMIO
197 {% elif region.name %}
198 {
199 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}),
200 .attr = ASSET_ATTR_NAMED_MMIO
201 {% endif %}
202 {% if region.permission == "READ-WRITE" %}
203 | ASSET_ATTR_READ_WRITE,
204 {% else %}
205 | ASSET_ATTR_READ_ONLY,
206 {% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800207 },
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800208 {% if region.conditional %}
Ken Liu86686282021-04-27 11:11:15 +0800209#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800210 {% endif %}
211 {% endfor %}
212{% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +0800213 },
Ken Liu86686282021-04-27 11:11:15 +0800214#else
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800215{% if counter.asset_counter > 0 %}
Ken Liu86686282021-04-27 11:11:15 +0800216 .assets = {
217 {% for region in manifest.mmio_regions %}
218 {% if region.conditional %}
219#ifdef {{region.conditional}}
220 {% endif %}
Mingyang Sundf02b852021-07-27 14:29:25 +0800221 {% if region.base and region.size %}
Ken Liu86686282021-04-27 11:11:15 +0800222 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800223 .mem.start = {{region.base}},
224 .mem.limit = {{region.base}} + {{region.size}},
225 .attr = ASSET_ATTR_NUMBERED_MMIO
226 {% elif region.name %}
227 {
228 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}),
229 .attr = ASSET_ATTR_NAMED_MMIO
230 {% endif %}
231 {% if region.permission == "READ-WRITE" %}
232 | ASSET_ATTR_READ_WRITE,
233 {% else %}
234 | ASSET_ATTR_READ_ONLY,
235 {% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800236 },
237 {% if region.conditional %}
238#endif
239 {% endif %}
240 {% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800241 },
Ken Liu86686282021-04-27 11:11:15 +0800242{% endif %}
243#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800244{% if counter.irq_counter > 0 %}
Kevin Peng27e42272021-05-24 17:58:53 +0800245 .irqs = {
246 {% for irq in manifest.irqs %}
247 {% set irq_info = namespace() %}
248 {% set irq_info.source = irq.source %}
Kevin Pengec239bb2021-09-03 15:40:27 +0800249 {% if irq.source is number %}}
250 {% set irq_info.source_symbol = "irq_" + irq.source|string %}
251 {% else %}
252 {% set irq_info.source_symbol = irq.source|lower %}
253 {% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +0800254 {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %}
Kevin Pengec239bb2021-09-03 15:40:27 +0800255 {% set irq_info.flih_func = irq.name|lower + "_flih" %}
Kevin Peng27e42272021-05-24 17:58:53 +0800256 {% else %}
257 {% set irq_info.flih_func = 0 %}
258 {% endif %}
259 {% if manifest.psa_framework_version == 1.0 %}
260 {% set irq_info.signal = irq.signal %}
261 {% else %}
262 {% set irq_info.signal = irq.name + "_SIGNAL" %}
263 {% endif %}
264 {
Kevin Pengec239bb2021-09-03 15:40:27 +0800265 .init = {{irq_info.source_symbol + "_init"}},
Kevin Peng27e42272021-05-24 17:58:53 +0800266 .flih_func = {{irq_info.flih_func}},
Kevin Pengec239bb2021-09-03 15:40:27 +0800267 .pid = {{manifest.name}},
268 .source = {{irq_info.source}},
269 .signal = {{irq_info.signal}},
Kevin Peng27e42272021-05-24 17:58:53 +0800270 },
271 {% endfor %}
272 },
273{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800274};
Ken Liuea45b0d2021-05-22 17:41:25 +0800275
276/* Placeholder for partition and service runtime space. Do not reference it. */
Michel Jaouenf9de50e2021-08-03 17:42:30 +0200277#if defined(__ICCARM__)
278#pragma location=".bss.part_runtime"
279__root
280#endif /* __ICCARM__ */
Ken Liuea45b0d2021-05-22 17:41:25 +0800281static struct partition_t {{manifest.name|lower}}_partition_runtime_item
282 __attribute__((used, section(".bss.part_runtime")));
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800283{% if counter.service_counter > 0 %}
Michel Jaouenf9de50e2021-08-03 17:42:30 +0200284#if defined(__ICCARM__)
285#pragma location = ".bss.serv_runtime"
286__root
287#endif /* __ICCARM__ */
Ken Liuea45b0d2021-05-22 17:41:25 +0800288static struct service_t {{manifest.name|lower}}_service_runtime_item[{{(manifest.name|upper + "_NSERVS")}}]
289 __attribute__((used, section(".bss.serv_runtime")));
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800290{% endif %}