blob: d9e6bb2756c67734e9ddfbc4f4d4e6f24d06c7e6 [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
Shawn Shancaefb8f2021-04-15 14:19:13 +080046{% if manifest.entry_init and manifest.entry_point %}
47#error "Both manifest.entry_init and manifest.entry_point exist, unsupported!"
48{% elif (manifest.model == "IPC" or manifest.psa_framework_version == 1.0) and (not manifest.entry_point) %}
49#error "The entry_point attribute is required, it should not be empty!"
50{% elif manifest.model == "SFN" and manifest.entry_point %}
51#error "The entry_point attribute should not be exist in SFN mode!"
52{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080053/* Entrypoint function declaration */
Shawn Shancaefb8f2021-04-15 14:19:13 +080054{% if manifest.entry_point %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080055extern void {{manifest.entry_point}}(void);
Shawn Shancaefb8f2021-04-15 14:19:13 +080056{% elif manifest.entry_init %}
57extern psa_status_t {{manifest.entry_init}}(void);
58{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080059
Kevin Pengec239bb2021-09-03 15:40:27 +080060/* Interrupt init functions */
61{% if counter.irq_counter > 0 %}
62 {% for irq in manifest.irqs %}
63 {% if irq.source is number %}}
64extern enum tfm_hal_status_t {{"irq_" + irq.source|string + "_init"}}(void *p_pt,
65 struct irq_load_info_t *p_ildi);
66 {% else %}
67extern enum tfm_hal_status_t {{irq.source|lower + "_init"}}(void *p_pt,
68 struct irq_load_info_t *p_ildi);
69 {% endif %}
70 {% endfor %}
71{% endif %}
72
Mingyang Sun8d004f72021-06-01 10:46:26 +080073/* partition load info type definition */
Ken Liu4520ce32021-05-11 22:49:10 +080074struct partition_{{manifest.name|lower}}_load_info_t {
Mingyang Sun8d004f72021-06-01 10:46:26 +080075 /* common length load data */
76 struct partition_load_info_t load_info;
77 /* per-partition variable length load data */
Ken Liuacd2a572021-05-12 16:19:04 +080078 uintptr_t stack_addr;
79 uintptr_t heap_addr;
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080080{% if counter.dep_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080081 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}];
82{% endif %}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080083{% if counter.service_counter > 0 %}
Ken Liuacd2a572021-05-12 16:19:04 +080084 struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}];
Mingyang Sunf6a78572021-04-02 16:51:05 +080085{% endif %}
Ken Liu86686282021-04-27 11:11:15 +080086#if TFM_LVL == 3
87 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
88#else
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080089{% if counter.asset_counter > 0 %}
Ken Liu86686282021-04-27 11:11:15 +080090 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
91{% endif %}
92#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +080093{% if counter.irq_counter > 0 %}
Kevin Peng27e42272021-05-24 17:58:53 +080094 struct irq_load_info_t irqs[{{(manifest.name|upper + "_NIRQS")}}];
95{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080096} __attribute__((aligned(4)));
97
Mingyang Sun8d004f72021-06-01 10:46:26 +080098/* Partition load, deps, service load data. Put to a dedicated section. */
Michel Jaouenf9de50e2021-08-03 17:42:30 +020099#if defined(__ICCARM__)
100#pragma location = ".part_load"
101__root
102#endif /* __ICCARM__ */
Mingyang Sun8d004f72021-06-01 10:46:26 +0800103const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load
104 __attribute__((used, section(".part_load"))) = {
105 .load_info = {
Mingyang Sunf6a78572021-04-02 16:51:05 +0800106{% if manifest.psa_framework_version == 1.0 %}
107 .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC,
108{% elif manifest.psa_framework_version == 1.1 %}
109 .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC,
110{% else %}
111#error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!"
112{% endif %}
113 .pid = {{manifest.name}},
114 .flags = 0
Shawn Shancaefb8f2021-04-15 14:19:13 +0800115{% 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 +0800116 | PARTITION_MODEL_IPC
Mingyang Sunf6a78572021-04-02 16:51:05 +0800117{% endif %}
118{% if manifest.type == "PSA-ROT" %}
Ken Liu897e8f12022-02-10 03:21:17 +0100119 | PARTITION_MODEL_PSA_ROT
Mingyang Sunf6a78572021-04-02 16:51:05 +0800120{% elif manifest.type != "APPLICATION-ROT" %}
121#error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!"
122{% endif %}
123 | PARTITION_PRI_{{manifest.priority}},
Shawn Shancaefb8f2021-04-15 14:19:13 +0800124{% if manifest.entry_point %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800125 .entry = ENTRY_TO_POSITION({{manifest.entry_point}}),
Shawn Shancaefb8f2021-04-15 14:19:13 +0800126{% elif manifest.entry_init %}
127 .entry = ENTRY_TO_POSITION({{manifest.entry_init}}),
128{% else %}
Ken Liuf39d8eb2021-10-07 12:55:33 +0800129 .entry = 0,
Shawn Shancaefb8f2021-04-15 14:19:13 +0800130{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800131 .stack_size = {{manifest.stack_size}},
132 .heap_size = 0,
133 .ndeps = {{(manifest.name|upper + "_NDEPS")}},
134 .nservices = {{(manifest.name|upper + "_NSERVS")}},
Ken Liu86686282021-04-27 11:11:15 +0800135 .nassets = {{(manifest.name|upper + "_NASSETS")}},
Kevin Peng27e42272021-05-24 17:58:53 +0800136 .nirqs = {{(manifest.name|upper + "_NIRQS")}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800137 },
Ken Liuacd2a572021-05-12 16:19:04 +0800138 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack,
139 .heap_addr = 0,
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800140{% if counter.dep_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800141 .deps = {
142 {% for dep in manifest.dependencies %}
143 {{dep}}_SID,
144 {% endfor %}
Kevin Pengcf7f8132021-10-25 15:36:26 +0800145 {% for dep in manifest.weak_dependencies %}
146#ifdef {{dep}}_SID
147 {{dep}}_SID,
148#endif
149 {% endfor %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800150 },
151{% endif %}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800152{% if counter.service_counter > 0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800153 .services = {
154 {% for service in manifest.services %}
155 {
156 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"),
Shawn Shancaefb8f2021-04-15 14:19:13 +0800157{% if manifest.psa_framework_version == 1.1 and manifest.model == "SFN" %}
158 .sfn = ENTRY_TO_POSITION({{service.name|lower}}_sfn),
159{% else %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800160 .signal = {{service.name}}_SIGNAL,
Shawn Shancaefb8f2021-04-15 14:19:13 +0800161{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800162 .sid = {{service.sid}},
163 .flags = 0
164 {% if service.non_secure_clients is sameas true %}
165 | SERVICE_FLAG_NS_ACCESSIBLE
166 {% endif %}
167 {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %}
Mingyang Suna03ad022021-06-01 20:41:15 +0800168 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800169 {% endif %}
Shawn Shan7d88ae92021-09-09 15:32:02 +0800170 {% if manifest.psa_framework_version > 1.0 and service.mm_iovec == "enable" %}
171 | SERVICE_FLAG_MM_IOVEC
172 {% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800173 {% if service.version_policy %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800174 | SERVICE_VERSION_POLICY_{{service.version_policy}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800175 {% else %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800176 | SERVICE_VERSION_POLICY_STRICT,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800177 {% endif %}
178 {% if service.version %}
179 .version = {{service.version}},
180 {% else %}
181 .version = 1,
182 {% endif %}
183 },
184 {% endfor %}
185 },
186{% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800187#if TFM_LVL == 3
188 .assets = {
189 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800190 .mem.start = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base),
191 .mem.limit = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base),
192 .attr = ASSET_ATTR_READ_WRITE,
Ken Liu86686282021-04-27 11:11:15 +0800193 },
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800194{% if counter.asset_counter > 0 %}
195 {% for region in manifest.mmio_regions %}
196 {% if region.conditional %}
Ken Liu86686282021-04-27 11:11:15 +0800197#ifdef {{region.conditional}}
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800198 {% endif %}
Mingyang Sundf02b852021-07-27 14:29:25 +0800199 {% if region.base and region.size %}
Ken Liu86686282021-04-27 11:11:15 +0800200 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800201 .mem.start = {{region.base}},
202 .mem.limit = {{region.base}} + {{region.size}},
203 .attr = ASSET_ATTR_NUMBERED_MMIO
204 {% elif region.name %}
205 {
206 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}),
207 .attr = ASSET_ATTR_NAMED_MMIO
208 {% endif %}
209 {% if region.permission == "READ-WRITE" %}
210 | ASSET_ATTR_READ_WRITE,
211 {% else %}
212 | ASSET_ATTR_READ_ONLY,
213 {% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800214 },
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800215 {% if region.conditional %}
Ken Liu86686282021-04-27 11:11:15 +0800216#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800217 {% endif %}
218 {% endfor %}
219{% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +0800220 },
Ken Liu86686282021-04-27 11:11:15 +0800221#else
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800222{% if counter.asset_counter > 0 %}
Ken Liu86686282021-04-27 11:11:15 +0800223 .assets = {
224 {% for region in manifest.mmio_regions %}
225 {% if region.conditional %}
226#ifdef {{region.conditional}}
227 {% endif %}
Mingyang Sundf02b852021-07-27 14:29:25 +0800228 {% if region.base and region.size %}
Ken Liu86686282021-04-27 11:11:15 +0800229 {
Mingyang Sundf02b852021-07-27 14:29:25 +0800230 .mem.start = {{region.base}},
231 .mem.limit = {{region.base}} + {{region.size}},
232 .attr = ASSET_ATTR_NUMBERED_MMIO
233 {% elif region.name %}
234 {
235 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}),
236 .attr = ASSET_ATTR_NAMED_MMIO
237 {% endif %}
238 {% if region.permission == "READ-WRITE" %}
239 | ASSET_ATTR_READ_WRITE,
240 {% else %}
241 | ASSET_ATTR_READ_ONLY,
242 {% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800243 },
244 {% if region.conditional %}
245#endif
246 {% endif %}
247 {% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800248 },
Ken Liu86686282021-04-27 11:11:15 +0800249{% endif %}
250#endif
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800251{% if counter.irq_counter > 0 %}
Kevin Peng27e42272021-05-24 17:58:53 +0800252 .irqs = {
253 {% for irq in manifest.irqs %}
254 {% set irq_info = namespace() %}
255 {% set irq_info.source = irq.source %}
Kevin Pengec239bb2021-09-03 15:40:27 +0800256 {% if irq.source is number %}}
257 {% set irq_info.source_symbol = "irq_" + irq.source|string %}
258 {% else %}
259 {% set irq_info.source_symbol = irq.source|lower %}
260 {% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +0800261 {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %}
Kevin Pengec239bb2021-09-03 15:40:27 +0800262 {% set irq_info.flih_func = irq.name|lower + "_flih" %}
Kevin Peng27e42272021-05-24 17:58:53 +0800263 {% else %}
264 {% set irq_info.flih_func = 0 %}
265 {% endif %}
266 {% if manifest.psa_framework_version == 1.0 %}
267 {% set irq_info.signal = irq.signal %}
268 {% else %}
269 {% set irq_info.signal = irq.name + "_SIGNAL" %}
270 {% endif %}
271 {
Kevin Pengec239bb2021-09-03 15:40:27 +0800272 .init = {{irq_info.source_symbol + "_init"}},
Kevin Peng27e42272021-05-24 17:58:53 +0800273 .flih_func = {{irq_info.flih_func}},
Kevin Pengec239bb2021-09-03 15:40:27 +0800274 .pid = {{manifest.name}},
275 .source = {{irq_info.source}},
276 .signal = {{irq_info.signal}},
Kevin Peng27e42272021-05-24 17:58:53 +0800277 },
278 {% endfor %}
279 },
280{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800281};
Ken Liuea45b0d2021-05-22 17:41:25 +0800282
283/* Placeholder for partition and service runtime space. Do not reference it. */
Michel Jaouenf9de50e2021-08-03 17:42:30 +0200284#if defined(__ICCARM__)
285#pragma location=".bss.part_runtime"
286__root
287#endif /* __ICCARM__ */
Ken Liuea45b0d2021-05-22 17:41:25 +0800288static struct partition_t {{manifest.name|lower}}_partition_runtime_item
289 __attribute__((used, section(".bss.part_runtime")));
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800290{% if counter.service_counter > 0 %}
Michel Jaouenf9de50e2021-08-03 17:42:30 +0200291#if defined(__ICCARM__)
292#pragma location = ".bss.serv_runtime"
293__root
294#endif /* __ICCARM__ */
Ken Liuea45b0d2021-05-22 17:41:25 +0800295static struct service_t {{manifest.name|lower}}_service_runtime_item[{{(manifest.name|upper + "_NSERVS")}}]
296 __attribute__((used, section(".bss.serv_runtime")));
Mingyang Sunb83b7bc2021-07-02 16:25:15 +0800297{% endif %}