blob: 54f92578819551e90007e1d2a6d1ae1f94383ce0 [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"
Kevin Peng27e42272021-05-24 17:58:53 +080013#include "load/irq_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080014#include "load/partition_defs.h"
15#include "load/service_defs.h"
Ken Liu86686282021-04-27 11:11:15 +080016#include "load/asset_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080017#include "tfm_peripherals_def.h"
18#include "psa_manifest/pid.h"
19#include "psa_manifest/sid.h"
Ken Liu861b0782021-05-22 13:15:08 +080020#include "psa_manifest/{{manifest_out_basename}}.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080021
Kevin Peng27e42272021-05-24 17:58:53 +080022{% set counter = namespace(dep_counter=0, service_counter=0, asset_counter=0, irq_counter=0) %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080023{% if manifest.dependencies %}
24 {% for dep in manifest.dependencies %}
25 {% set counter.dep_counter = counter.dep_counter + 1 %}
26 {% endfor %}
27{% endif %}
28{% if manifest.services %}
29 {% for service in manifest.services %}
30 {% set counter.service_counter = counter.service_counter + 1 %}
31 {% endfor %}
32{% endif %}
Ken Liu86686282021-04-27 11:11:15 +080033{% if manifest.mmio_regions %}
34 {% for asset in manifest.mmio_regions %}
35 {% set counter.asset_counter = counter.asset_counter + 1 %}
36 {% endfor %}
37{% endif %}
Kevin Peng27e42272021-05-24 17:58:53 +080038{% if manifest.irqs %}
39 {% for irq in manifest.irqs %}
40 {% set counter.irq_counter = counter.irq_counter + 1 %}
41 {% endfor %}
42{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080043#define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}})
44#define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}})
Ken Liu86686282021-04-27 11:11:15 +080045#if TFM_LVL == 3
46#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1)
47#else
48#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}})
49#endif
Kevin Peng27e42272021-05-24 17:58:53 +080050#define {{"%-55s"|format(manifest.name|upper + "_NIRQS")}} ({{"%d"|format(counter.irq_counter)}})
Mingyang Sunf6a78572021-04-02 16:51:05 +080051
52/* Memory region declaration */
53#if TFM_LVL == 3
54REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base);
55REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base);
56#endif
57extern uint8_t {{manifest.name|lower}}_stack[];
58
Shawn Shancaefb8f2021-04-15 14:19:13 +080059{% if manifest.entry_init and manifest.entry_point %}
60#error "Both manifest.entry_init and manifest.entry_point exist, unsupported!"
61{% elif (manifest.model == "IPC" or manifest.psa_framework_version == 1.0) and (not manifest.entry_point) %}
62#error "The entry_point attribute is required, it should not be empty!"
63{% elif manifest.model == "SFN" and manifest.entry_point %}
64#error "The entry_point attribute should not be exist in SFN mode!"
65{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080066/* Entrypoint function declaration */
Shawn Shancaefb8f2021-04-15 14:19:13 +080067{% if manifest.entry_point %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080068extern void {{manifest.entry_point}}(void);
Shawn Shancaefb8f2021-04-15 14:19:13 +080069{% elif manifest.entry_init %}
70extern psa_status_t {{manifest.entry_init}}(void);
71{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080072
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 Sunf6a78572021-04-02 16:51:05 +080080{% if manifest.dependencies %}
81 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}];
82{% endif %}
83{% if manifest.services %}
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
89{% if manifest.mmio_regions %}
90 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
91{% endif %}
92#endif
Kevin Peng27e42272021-05-24 17:58:53 +080093{% if manifest.irqs %}
94 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. */
99const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load
100 __attribute__((used, section(".part_load"))) = {
101 .load_info = {
Mingyang Sunf6a78572021-04-02 16:51:05 +0800102{% if manifest.psa_framework_version == 1.0 %}
103 .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC,
104{% elif manifest.psa_framework_version == 1.1 %}
105 .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC,
106{% else %}
107#error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!"
108{% endif %}
109 .pid = {{manifest.name}},
110 .flags = 0
Shawn Shancaefb8f2021-04-15 14:19:13 +0800111{% if (manifest.psa_framework_version == 1.1 and manifest.model == "IPC") or manifest.psa_framework_version == 1.0 %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800112 | SPM_PART_FLAG_IPC
113{% endif %}
114{% if manifest.type == "PSA-ROT" %}
115 | SPM_PART_FLAG_PSA_ROT
116{% elif manifest.type != "APPLICATION-ROT" %}
117#error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!"
118{% endif %}
119 | PARTITION_PRI_{{manifest.priority}},
Shawn Shancaefb8f2021-04-15 14:19:13 +0800120{% if manifest.entry_point %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800121 .entry = ENTRY_TO_POSITION({{manifest.entry_point}}),
Shawn Shancaefb8f2021-04-15 14:19:13 +0800122{% elif manifest.entry_init %}
123 .entry = ENTRY_TO_POSITION({{manifest.entry_init}}),
124{% else %}
125 .entry = NULL,
126{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800127 .stack_size = {{manifest.stack_size}},
128 .heap_size = 0,
129 .ndeps = {{(manifest.name|upper + "_NDEPS")}},
130 .nservices = {{(manifest.name|upper + "_NSERVS")}},
Ken Liu86686282021-04-27 11:11:15 +0800131 .nassets = {{(manifest.name|upper + "_NASSETS")}},
Kevin Peng27e42272021-05-24 17:58:53 +0800132 .nirqs = {{(manifest.name|upper + "_NIRQS")}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800133 },
Ken Liuacd2a572021-05-12 16:19:04 +0800134 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack,
135 .heap_addr = 0,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800136{% if manifest.dependencies %}
137 .deps = {
138 {% for dep in manifest.dependencies %}
139 {{dep}}_SID,
140 {% endfor %}
141 },
142{% endif %}
143{% if manifest.services %}
144 .services = {
145 {% for service in manifest.services %}
146 {
147 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"),
Shawn Shancaefb8f2021-04-15 14:19:13 +0800148{% if manifest.psa_framework_version == 1.1 and manifest.model == "SFN" %}
149 .sfn = ENTRY_TO_POSITION({{service.name|lower}}_sfn),
150{% else %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800151 .signal = {{service.name}}_SIGNAL,
Shawn Shancaefb8f2021-04-15 14:19:13 +0800152{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800153 .sid = {{service.sid}},
154 .flags = 0
155 {% if service.non_secure_clients is sameas true %}
156 | SERVICE_FLAG_NS_ACCESSIBLE
157 {% endif %}
158 {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %}
Mingyang Suna03ad022021-06-01 20:41:15 +0800159 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800160 {% endif %}
161 {% if service.version_policy %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800162 | SERVICE_VERSION_POLICY_{{service.version_policy}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800163 {% else %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800164 | SERVICE_VERSION_POLICY_STRICT,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800165 {% endif %}
166 {% if service.version %}
167 .version = {{service.version}},
168 {% else %}
169 .version = 1,
170 {% endif %}
171 },
172 {% endfor %}
173 },
174{% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800175#if TFM_LVL == 3
176 .assets = {
177 {
178 .mem.addr_x = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base),
179 .mem.addr_y = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base),
180 .attr = ASSET_MEM_RD_BIT | ASSET_MEM_WR_BIT,
181 },
182{% for region in manifest.mmio_regions %}
183 {% if region.conditional %}
184#ifdef {{region.conditional}}
185 {% endif %}
186 {
Ken Liuacd2a572021-05-12 16:19:04 +0800187 .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}),
Ken Liu86686282021-04-27 11:11:15 +0800188 .attr = ASSET_DEV_REF_BIT,
189 },
190 {% if region.conditional %}
191#endif
192 {% endif %}
193{% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800194 },
Ken Liu86686282021-04-27 11:11:15 +0800195#else
196{% if manifest.mmio_regions %}
197 .assets = {
198 {% for region in manifest.mmio_regions %}
199 {% if region.conditional %}
200#ifdef {{region.conditional}}
201 {% endif %}
202 {
Ken Liuacd2a572021-05-12 16:19:04 +0800203 .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}),
Ken Liu86686282021-04-27 11:11:15 +0800204 .attr = ASSET_DEV_REF_BIT,
205 },
206 {% if region.conditional %}
207#endif
208 {% endif %}
209 {% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800210 },
Ken Liu86686282021-04-27 11:11:15 +0800211{% endif %}
212#endif
Kevin Peng27e42272021-05-24 17:58:53 +0800213{% if manifest.irqs %}
214 .irqs = {
215 {% for irq in manifest.irqs %}
216 {% set irq_info = namespace() %}
217 {% set irq_info.source = irq.source %}
218 {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %}
219 {% set irq_info.flih_func = "(uint32_t)" + irq.name|lower + "_flih" %}
220 {% else %}
221 {% set irq_info.flih_func = 0 %}
222 {% endif %}
223 {% if manifest.psa_framework_version == 1.0 %}
224 {% set irq_info.signal = irq.signal %}
225 {% else %}
226 {% set irq_info.signal = irq.name + "_SIGNAL" %}
227 {% endif %}
228 {
229 .source = {{irq_info.source}},
230 .flih_func = {{irq_info.flih_func}},
231 .signal = {{irq_info.signal}},
232 },
233 {% endfor %}
234 },
235{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800236};