blob: 32d6e30dd98ac3236bddbf5f7daaca66b5fb3d61 [file] [log] [blame]
Mingyang Sunf6a78572021-04-02 16:51:05 +08001/*
Sherry Zhangf58f2bd2022-01-10 17:21:11 +08002 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
Chris Brandb8bf9a92021-11-02 17:22:54 -07003 * Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
Mingyang Sunf6a78572021-04-02 16:51:05 +08004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 */
8
Sherry Zhangf58f2bd2022-01-10 17:21:11 +08009/***********{{utilities.donotedit_warning}}***********/
Mingyang Sunf6a78572021-04-02 16:51:05 +080010
11#include <stdint.h>
12#include <stddef.h>
13#include "region.h"
Chris Brandb8bf9a92021-11-02 17:22:54 -070014#include "region_defs.h"
Ken Liuea45b0d2021-05-22 17:41:25 +080015#include "spm_ipc.h"
Ken Liu3dd92562021-08-17 16:22:54 +080016#include "load/interrupt_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080017#include "load/partition_defs.h"
18#include "load/service_defs.h"
Ken Liu86686282021-04-27 11:11:15 +080019#include "load/asset_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080020#include "tfm_peripherals_def.h"
21#include "psa_manifest/pid.h"
22#include "psa_manifest/sid.h"
Ken Liu861b0782021-05-22 13:15:08 +080023#include "psa_manifest/{{manifest_out_basename}}.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080024
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080025{% set counter = namespace() %}
Kevin Pengcf7f8132021-10-25 15:36:26 +080026{% set counter.dep_counter = manifest.dependencies|count + manifest.weak_dependencies|count %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080027#define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}})
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080028{% set counter.service_counter = manifest.services|count %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080029#define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}})
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080030{% set counter.asset_counter = manifest.mmio_regions|count %}
Ken Liu86686282021-04-27 11:11:15 +080031#if TFM_LVL == 3
32#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1)
33#else
34#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}})
35#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080036{% set counter.irq_counter = manifest.irqs|count %}
Kevin Peng27e42272021-05-24 17:58:53 +080037#define {{"%-55s"|format(manifest.name|upper + "_NIRQS")}} ({{"%d"|format(counter.irq_counter)}})
Mingyang Sunf6a78572021-04-02 16:51:05 +080038
39/* Memory region declaration */
40#if TFM_LVL == 3
41REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base);
42REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base);
43#endif
44extern uint8_t {{manifest.name|lower}}_stack[];
45
Kevin Pengec0e5ce2022-02-17 13:48:51 +080046{% if manifest.model == "IPC" %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080047/* Entrypoint function declaration */
48extern void {{manifest.entry_point}}(void);
Shawn Shancaefb8f2021-04-15 14:19:13 +080049{% elif manifest.entry_init %}
50extern psa_status_t {{manifest.entry_init}}(void);
51{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080052
Kevin Pengec239bb2021-09-03 15:40:27 +080053/* Interrupt init functions */
54{% if counter.irq_counter > 0 %}
55 {% for irq in manifest.irqs %}
56 {% if irq.source is number %}}
57extern enum tfm_hal_status_t {{"irq_" + irq.source|string + "_init"}}(void *p_pt,
58 struct irq_load_info_t *p_ildi);
59 {% else %}
60extern enum tfm_hal_status_t {{irq.source|lower + "_init"}}(void *p_pt,
61 struct irq_load_info_t *p_ildi);
62 {% endif %}
63 {% endfor %}
64{% endif %}
65
Mingyang Sun8d004f72021-06-01 10:46:26 +080066/* partition load info type definition */
Ken Liu4520ce32021-05-11 22:49:10 +080067struct partition_{{manifest.name|lower}}_load_info_t {
Mingyang Sun8d004f72021-06-01 10:46:26 +080068 /* common length load data */
69 struct partition_load_info_t load_info;
70 /* per-partition variable length load data */
Ken Liuacd2a572021-05-12 16:19:04 +080071 uintptr_t stack_addr;
72 uintptr_t heap_addr;
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080073{% if counter.dep_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080074 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}];
75{% endif %}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080076{% if counter.service_counter > 0 %}
Ken Liuacd2a572021-05-12 16:19:04 +080077 struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}];
Mingyang Sunf6a78572021-04-02 16:51:05 +080078{% endif %}
Ken Liu86686282021-04-27 11:11:15 +080079#if TFM_LVL == 3
80 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
81#else
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080082{% if counter.asset_counter > 0 %}
Ken Liu86686282021-04-27 11:11:15 +080083 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
84{% endif %}
85#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080086{% if counter.irq_counter > 0 %}
Kevin Peng27e42272021-05-24 17:58:53 +080087 struct irq_load_info_t irqs[{{(manifest.name|upper + "_NIRQS")}}];
88{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080089} __attribute__((aligned(4)));
90
Mingyang Sun8d004f72021-06-01 10:46:26 +080091/* Partition load, deps, service load data. Put to a dedicated section. */
Michel Jaouenf9de50e2021-08-03 17:42:30 +020092#if defined(__ICCARM__)
93#pragma location = ".part_load"
94__root
95#endif /* __ICCARM__ */
Mingyang Sun8d004f72021-06-01 10:46:26 +080096const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load
97 __attribute__((used, section(".part_load"))) = {
98 .load_info = {
Mingyang Sunf6a78572021-04-02 16:51:05 +080099{% if manifest.psa_framework_version == 1.0 %}
100 .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC,
101{% elif manifest.psa_framework_version == 1.1 %}
102 .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800103{% endif %}
104 .pid = {{manifest.name}},
105 .flags = 0
Kevin Peng5c3fee72022-02-16 22:25:22 +0800106{% if manifest.model == "IPC" %}
Ken Liu59728d02021-10-06 12:47:39 +0800107 | PARTITION_MODEL_IPC
Mingyang Sunf6a78572021-04-02 16:51:05 +0800108{% endif %}
109{% if manifest.type == "PSA-ROT" %}
Ken Liu897e8f12022-02-10 03:21:17 +0100110 | PARTITION_MODEL_PSA_ROT
Mingyang Sunf6a78572021-04-02 16:51:05 +0800111{% endif %}
112 | PARTITION_PRI_{{manifest.priority}},
Kevin Peng5c3fee72022-02-16 22:25:22 +0800113 .entry = ENTRY_TO_POSITION({{manifest.entry}}),
Mingyang Sunf6a78572021-04-02 16:51:05 +0800114 .stack_size = {{manifest.stack_size}},
115 .heap_size = 0,
116 .ndeps = {{(manifest.name|upper + "_NDEPS")}},
117 .nservices = {{(manifest.name|upper + "_NSERVS")}},
Ken Liu86686282021-04-27 11:11:15 +0800118 .nassets = {{(manifest.name|upper + "_NASSETS")}},
Kevin Peng27e42272021-05-24 17:58:53 +0800119 .nirqs = {{(manifest.name|upper + "_NIRQS")}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800120 },
Ken Liuacd2a572021-05-12 16:19:04 +0800121 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack,
122 .heap_addr = 0,
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800123{% if counter.dep_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800124 .deps = {
125 {% for dep in manifest.dependencies %}
126 {{dep}}_SID,
127 {% endfor %}
Kevin Pengcf7f8132021-10-25 15:36:26 +0800128 {% for dep in manifest.weak_dependencies %}
129#ifdef {{dep}}_SID
130 {{dep}}_SID,
131#endif
132 {% endfor %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800133 },
134{% endif %}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800135{% if counter.service_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800136 .services = {
137 {% for service in manifest.services %}
138 {
139 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"),
Kevin Peng5c3fee72022-02-16 22:25:22 +0800140 {% if manifest.model == "SFN" %}
Shawn Shancaefb8f2021-04-15 14:19:13 +0800141 .sfn = ENTRY_TO_POSITION({{service.name|lower}}_sfn),
Kevin Peng43160d52022-02-11 13:35:56 +0800142 {% else %}
143 .sfn = 0,
144 {% endif %}
145#if CONFIG_TFM_SPM_BACKEND_IPC == 1
Kevin Peng5c3fee72022-02-16 22:25:22 +0800146 {% if manifest.model == "SFN" %}
147 .signal = {{service.signal_value}},
Kevin Peng43160d52022-02-11 13:35:56 +0800148 {% else %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800149 .signal = {{service.name}}_SIGNAL,
Kevin Peng43160d52022-02-11 13:35:56 +0800150 {% endif %}
151#endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */
Mingyang Sunf6a78572021-04-02 16:51:05 +0800152 .sid = {{service.sid}},
153 .flags = 0
154 {% if service.non_secure_clients is sameas true %}
155 | SERVICE_FLAG_NS_ACCESSIBLE
156 {% endif %}
Kevin Peng5c3fee72022-02-16 22:25:22 +0800157 {% if service.connection_based is sameas false %}
Mingyang Suna03ad022021-06-01 20:41:15 +0800158 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800159 {% endif %}
Kevin Peng5c3fee72022-02-16 22:25:22 +0800160 {% if service.mm_iovec == "enable" %}
Shawn Shan7d88ae92021-09-09 15:32:02 +0800161 | SERVICE_FLAG_MM_IOVEC
162 {% endif %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800163 | SERVICE_VERSION_POLICY_{{service.version_policy}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800164 .version = {{service.version}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800165 },
166 {% endfor %}
167 },
168{% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800169#if TFM_LVL == 3
170 .assets = {
171 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800172 .mem.start = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base),
173 .mem.limit = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base),
174 .attr = ASSET_ATTR_READ_WRITE,
Ken Liu86686282021-04-27 11:11:15 +0800175 },
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800176{% if counter.asset_counter > 0 %}
177 {% for region in manifest.mmio_regions %}
178 {% if region.conditional %}
Ken Liu86686282021-04-27 11:11:15 +0800179#ifdef {{region.conditional}}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800180 {% endif %}
Mingyang Sundf02b852021-07-27 14:29:25 +0800181 {% if region.base and region.size %}
Ken Liu86686282021-04-27 11:11:15 +0800182 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800183 .mem.start = {{region.base}},
184 .mem.limit = {{region.base}} + {{region.size}},
185 .attr = ASSET_ATTR_NUMBERED_MMIO
186 {% elif region.name %}
187 {
188 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}),
189 .attr = ASSET_ATTR_NAMED_MMIO
190 {% endif %}
191 {% if region.permission == "READ-WRITE" %}
192 | ASSET_ATTR_READ_WRITE,
193 {% else %}
194 | ASSET_ATTR_READ_ONLY,
195 {% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800196 },
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800197 {% if region.conditional %}
Ken Liu86686282021-04-27 11:11:15 +0800198#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800199 {% endif %}
200 {% endfor %}
201{% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +0800202 },
Ken Liu86686282021-04-27 11:11:15 +0800203#else
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800204{% if counter.asset_counter > 0 %}
Ken Liu86686282021-04-27 11:11:15 +0800205 .assets = {
206 {% for region in manifest.mmio_regions %}
207 {% if region.conditional %}
208#ifdef {{region.conditional}}
209 {% endif %}
Mingyang Sundf02b852021-07-27 14:29:25 +0800210 {% if region.base and region.size %}
Ken Liu86686282021-04-27 11:11:15 +0800211 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800212 .mem.start = {{region.base}},
213 .mem.limit = {{region.base}} + {{region.size}},
214 .attr = ASSET_ATTR_NUMBERED_MMIO
215 {% elif region.name %}
216 {
217 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}),
218 .attr = ASSET_ATTR_NAMED_MMIO
219 {% endif %}
220 {% if region.permission == "READ-WRITE" %}
221 | ASSET_ATTR_READ_WRITE,
222 {% else %}
223 | ASSET_ATTR_READ_ONLY,
224 {% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800225 },
226 {% if region.conditional %}
227#endif
228 {% endif %}
229 {% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800230 },
Ken Liu86686282021-04-27 11:11:15 +0800231{% endif %}
232#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800233{% if counter.irq_counter > 0 %}
Kevin Peng27e42272021-05-24 17:58:53 +0800234 .irqs = {
235 {% for irq in manifest.irqs %}
236 {% set irq_info = namespace() %}
237 {% set irq_info.source = irq.source %}
Kevin Pengec239bb2021-09-03 15:40:27 +0800238 {% if irq.source is number %}}
239 {% set irq_info.source_symbol = "irq_" + irq.source|string %}
240 {% else %}
241 {% set irq_info.source_symbol = irq.source|lower %}
242 {% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +0800243 {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %}
Kevin Pengec239bb2021-09-03 15:40:27 +0800244 {% set irq_info.flih_func = irq.name|lower + "_flih" %}
Kevin Peng27e42272021-05-24 17:58:53 +0800245 {% else %}
246 {% set irq_info.flih_func = 0 %}
247 {% endif %}
248 {% if manifest.psa_framework_version == 1.0 %}
249 {% set irq_info.signal = irq.signal %}
250 {% else %}
251 {% set irq_info.signal = irq.name + "_SIGNAL" %}
252 {% endif %}
253 {
Kevin Pengec239bb2021-09-03 15:40:27 +0800254 .init = {{irq_info.source_symbol + "_init"}},
Kevin Peng27e42272021-05-24 17:58:53 +0800255 .flih_func = {{irq_info.flih_func}},
Kevin Pengec239bb2021-09-03 15:40:27 +0800256 .pid = {{manifest.name}},
257 .source = {{irq_info.source}},
258 .signal = {{irq_info.signal}},
Kevin Peng27e42272021-05-24 17:58:53 +0800259 },
260 {% endfor %}
261 },
262{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800263};
Ken Liuea45b0d2021-05-22 17:41:25 +0800264
265/* Placeholder for partition and service runtime space. Do not reference it. */
Michel Jaouenf9de50e2021-08-03 17:42:30 +0200266#if defined(__ICCARM__)
267#pragma location=".bss.part_runtime"
268__root
269#endif /* __ICCARM__ */
Ken Liuea45b0d2021-05-22 17:41:25 +0800270static struct partition_t {{manifest.name|lower}}_partition_runtime_item
271 __attribute__((used, section(".bss.part_runtime")));
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800272{% if counter.service_counter > 0 %}
Michel Jaouenf9de50e2021-08-03 17:42:30 +0200273#if defined(__ICCARM__)
274#pragma location = ".bss.serv_runtime"
275__root
276#endif /* __ICCARM__ */
Ken Liuea45b0d2021-05-22 17:41:25 +0800277static struct service_t {{manifest.name|lower}}_service_runtime_item[{{(manifest.name|upper + "_NSERVS")}}]
278 __attribute__((used, section(".bss.serv_runtime")));
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800279{% endif %}