blob: 6c40c55dbb31d3d3557efe16304c369c15d056a0 [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
59/* Entrypoint function declaration */
60extern void {{manifest.entry_point}}(void);
61
Mingyang Sun8d004f72021-06-01 10:46:26 +080062/* partition load info type definition */
Ken Liu4520ce32021-05-11 22:49:10 +080063struct partition_{{manifest.name|lower}}_load_info_t {
Mingyang Sun8d004f72021-06-01 10:46:26 +080064 /* common length load data */
65 struct partition_load_info_t load_info;
66 /* per-partition variable length load data */
Ken Liuacd2a572021-05-12 16:19:04 +080067 uintptr_t stack_addr;
68 uintptr_t heap_addr;
Mingyang Sunf6a78572021-04-02 16:51:05 +080069{% if manifest.dependencies %}
70 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}];
71{% endif %}
72{% if manifest.services %}
Ken Liuacd2a572021-05-12 16:19:04 +080073 struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}];
Mingyang Sunf6a78572021-04-02 16:51:05 +080074{% endif %}
Ken Liu86686282021-04-27 11:11:15 +080075#if TFM_LVL == 3
76 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
77#else
78{% if manifest.mmio_regions %}
79 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
80{% endif %}
81#endif
Kevin Peng27e42272021-05-24 17:58:53 +080082{% if manifest.irqs %}
83 struct irq_load_info_t irqs[{{(manifest.name|upper + "_NIRQS")}}];
84{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080085} __attribute__((aligned(4)));
86
Mingyang Sun8d004f72021-06-01 10:46:26 +080087/* Partition load, deps, service load data. Put to a dedicated section. */
88const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load
89 __attribute__((used, section(".part_load"))) = {
90 .load_info = {
Mingyang Sunf6a78572021-04-02 16:51:05 +080091{% if manifest.psa_framework_version == 1.0 %}
92 .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC,
93{% elif manifest.psa_framework_version == 1.1 %}
94 .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC,
95{% else %}
96#error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!"
97{% endif %}
98 .pid = {{manifest.name}},
99 .flags = 0
100{% if manifest.psa_framework_version == 1.0 and attr.tfm_partition_ipc is sameas true %}
101 | SPM_PART_FLAG_IPC
102{% elif manifest.psa_framework_version == 1.1 and manifest.model == "IPC" %}
103 | SPM_PART_FLAG_IPC
104{% endif %}
105{% if manifest.type == "PSA-ROT" %}
106 | SPM_PART_FLAG_PSA_ROT
107{% elif manifest.type != "APPLICATION-ROT" %}
108#error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!"
109{% endif %}
110 | PARTITION_PRI_{{manifest.priority}},
111 .entry = ENTRY_TO_POSITION({{manifest.entry_point}}),
112 .stack_size = {{manifest.stack_size}},
113 .heap_size = 0,
114 .ndeps = {{(manifest.name|upper + "_NDEPS")}},
115 .nservices = {{(manifest.name|upper + "_NSERVS")}},
Ken Liu86686282021-04-27 11:11:15 +0800116 .nassets = {{(manifest.name|upper + "_NASSETS")}},
Kevin Peng27e42272021-05-24 17:58:53 +0800117 .nirqs = {{(manifest.name|upper + "_NIRQS")}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800118 },
Ken Liuacd2a572021-05-12 16:19:04 +0800119 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack,
120 .heap_addr = 0,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800121{% if manifest.dependencies %}
122 .deps = {
123 {% for dep in manifest.dependencies %}
124 {{dep}}_SID,
125 {% endfor %}
126 },
127{% endif %}
128{% if manifest.services %}
129 .services = {
130 {% for service in manifest.services %}
131 {
132 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"),
133 .signal = {{service.name}}_SIGNAL,
134 .sid = {{service.sid}},
135 .flags = 0
136 {% if service.non_secure_clients is sameas true %}
137 | SERVICE_FLAG_NS_ACCESSIBLE
138 {% endif %}
139 {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %}
Mingyang Suna03ad022021-06-01 20:41:15 +0800140 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800141 {% endif %}
142 {% if service.version_policy %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800143 | SERVICE_VERSION_POLICY_{{service.version_policy}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800144 {% else %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800145 | SERVICE_VERSION_POLICY_STRICT,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800146 {% endif %}
147 {% if service.version %}
148 .version = {{service.version}},
149 {% else %}
150 .version = 1,
151 {% endif %}
152 },
153 {% endfor %}
154 },
155{% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800156#if TFM_LVL == 3
157 .assets = {
158 {
159 .mem.addr_x = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base),
160 .mem.addr_y = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base),
161 .attr = ASSET_MEM_RD_BIT | ASSET_MEM_WR_BIT,
162 },
163{% for region in manifest.mmio_regions %}
164 {% if region.conditional %}
165#ifdef {{region.conditional}}
166 {% endif %}
167 {
Ken Liuacd2a572021-05-12 16:19:04 +0800168 .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}),
Ken Liu86686282021-04-27 11:11:15 +0800169 .attr = ASSET_DEV_REF_BIT,
170 },
171 {% if region.conditional %}
172#endif
173 {% endif %}
174{% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800175 },
Ken Liu86686282021-04-27 11:11:15 +0800176#else
177{% if manifest.mmio_regions %}
178 .assets = {
179 {% for region in manifest.mmio_regions %}
180 {% if region.conditional %}
181#ifdef {{region.conditional}}
182 {% endif %}
183 {
Ken Liuacd2a572021-05-12 16:19:04 +0800184 .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}),
Ken Liu86686282021-04-27 11:11:15 +0800185 .attr = ASSET_DEV_REF_BIT,
186 },
187 {% if region.conditional %}
188#endif
189 {% endif %}
190 {% endfor %}
Kevin Peng27e42272021-05-24 17:58:53 +0800191 },
Ken Liu86686282021-04-27 11:11:15 +0800192{% endif %}
193#endif
Kevin Peng27e42272021-05-24 17:58:53 +0800194{% if manifest.irqs %}
195 .irqs = {
196 {% for irq in manifest.irqs %}
197 {% set irq_info = namespace() %}
198 {% set irq_info.source = irq.source %}
199 {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %}
200 {% set irq_info.flih_func = "(uint32_t)" + irq.name|lower + "_flih" %}
201 {% else %}
202 {% set irq_info.flih_func = 0 %}
203 {% endif %}
204 {% if manifest.psa_framework_version == 1.0 %}
205 {% set irq_info.signal = irq.signal %}
206 {% else %}
207 {% set irq_info.signal = irq.name + "_SIGNAL" %}
208 {% endif %}
209 {
210 .source = {{irq_info.source}},
211 .flih_func = {{irq_info.flih_func}},
212 .signal = {{irq_info.signal}},
213 },
214 {% endfor %}
215 },
216{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800217};