1/* 2 * Copyright (c) 2021-2024, Arm Limited. All rights reserved. 3 * Copyright (c) 2021-2023 Cypress Semiconductor Corporation (an Infineon 4 * company) or an affiliate of Cypress Semiconductor Corporation. All rights 5 * reserved. 6 * 7 * SPDX-License-Identifier: BSD-3-Clause 8 * 9 */ 10 11/***********{{utilities.donotedit_warning}}***********/ 12 13#include <stdint.h> 14#include <stddef.h> 15#include "config_tfm.h" 16#include "region.h" 17#include "region_defs.h" 18#include "spm.h" 19#include "load/interrupt_defs.h" 20#include "load/partition_defs.h" 21#include "load/service_defs.h" 22#include "load/asset_defs.h" 23#include "tfm_peripherals_def.h" 24#include "psa_manifest/pid.h" 25#include "psa_manifest/sid.h" 26#include "psa_manifest/{{manifest_out_basename}}.h" 27 28{% set counter = namespace() %} 29{% set counter.dep_counter = manifest.dependencies|count + manifest.weak_dependencies|count %} 30#define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}}) 31{% set counter.service_counter = manifest.services|count %} 32#define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}}) 33{% set counter.asset_counter = manifest.mmio_regions|count %} 34#if TFM_ISOLATION_LEVEL == 3 35#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1) 36#else 37#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}}) 38#endif 39{% set counter.irq_counter = manifest.irqs|count %} 40#define {{"%-55s"|format(manifest.name|upper + "_NIRQS")}} ({{"%d"|format(counter.irq_counter)}}) 41 42/* Memory region declaration */ 43#if TFM_ISOLATION_LEVEL == 3 44REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base); 45REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base); 46#endif 47 48{% if config_impl['CONFIG_TFM_SPM_BACKEND_IPC'] == '1' or manifest.model == "IPC" %} 49extern uint8_t {{manifest.name|lower}}_stack[]; 50{% endif %} 51 52{% if manifest.model == "IPC" %} 53/* Entrypoint function declaration */ 54extern void {{manifest.entry_point}}(void); 55{% elif manifest.entry_init %} 56extern psa_status_t {{manifest.entry_init}}(void); 57{% endif %} 58 59/* Interrupt init functions */ 60{% if counter.irq_counter > 0 %} 61 {% for irq in manifest.irqs %} 62 {% if irq.source is number %}} 63extern enum tfm_hal_status_t {{"irq_" + irq.source|string + "_init"}}(void *p_pt, 64 const struct irq_load_info_t *p_ildi); 65 {% else %} 66extern enum tfm_hal_status_t {{irq.source|lower + "_init"}}(void *p_pt, 67 const struct irq_load_info_t *p_ildi); 68 {% endif %} 69 {% endfor %} 70{% endif %} 71 72/* partition load info type definition */ 73struct partition_{{manifest.name|lower}}_load_info_t { 74 /* common length load data */ 75 struct partition_load_info_t load_info; 76 /* per-partition variable length load data */ 77 uintptr_t stack_addr; 78 uintptr_t heap_addr; 79{% if counter.dep_counter > 0 %} 80 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}]; 81{% endif %} 82{% if counter.service_counter > 0 %} 83 struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}]; 84{% endif %} 85#if TFM_ISOLATION_LEVEL == 3 86 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}]; 87#else 88{% if counter.asset_counter > 0 %} 89 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}]; 90{% endif %} 91#endif 92{% if counter.irq_counter > 0 %} 93 struct irq_load_info_t irqs[{{(manifest.name|upper + "_NIRQS")}}]; 94{% endif %} 95} __attribute__((aligned(4))); 96 97/* Partition load, deps, service load data. Put to a dedicated section. */ 98#if defined(__ICCARM__) 99#pragma location = ".part_load_priority_{{numbered_priority}}" 100__root 101#endif /* __ICCARM__ */ 102const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load 103 __attribute__((used, section(".part_load_priority_{{numbered_priority}}"))) = { 104 .load_info = { 105{% if manifest.psa_framework_version == 1.0 %} 106 .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC, 107{% elif manifest.psa_framework_version == 1.1 %} 108 .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC, 109{% endif %} 110 .pid = {{manifest.name}}, 111 .flags = 0 112{% if manifest.model == "IPC" %} 113 | PARTITION_MODEL_IPC 114{% endif %} 115{% if manifest.type == "PSA-ROT" %} 116 | PARTITION_MODEL_PSA_ROT 117{% endif %} 118{% if manifest.ns_agent is sameas true %} 119 | PARTITION_NS_AGENT_MB 120{% endif %} 121 | PARTITION_PRI_{{manifest.priority}}, 122 .entry = ENTRY_TO_POSITION({{manifest.entry}}), 123{% if config_impl['CONFIG_TFM_SPM_BACKEND_IPC'] == '1' or manifest.model == "IPC" %} 124 .stack_size = {{manifest.stack_size}}, 125{% else %} 126 .stack_size = 0, 127{% endif %} 128 .heap_size = 0, 129 .ndeps = {{(manifest.name|upper + "_NDEPS")}}, 130 .nservices = {{(manifest.name|upper + "_NSERVS")}}, 131 .nassets = {{(manifest.name|upper + "_NASSETS")}}, 132 .nirqs = {{(manifest.name|upper + "_NIRQS")}}, 133{% if manifest.ns_agent is sameas true %} 134 .client_id_base = {{manifest.client_id_base}}, 135 .client_id_limit = {{manifest.client_id_limit}}, 136{% endif %} 137 }, 138{% if config_impl['CONFIG_TFM_SPM_BACKEND_IPC'] == '1' or manifest.model == "IPC" %} 139 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack, 140{% else %} 141 .stack_addr = 0, 142{% endif %} 143 .heap_addr = 0, 144{% if counter.dep_counter > 0 %} 145 .deps = { 146 {% for dep in manifest.dependencies %} 147 {{dep}}_SID, 148 {% endfor %} 149 {% for dep in manifest.weak_dependencies %} 150#ifdef {{dep}}_SID 151 {{dep}}_SID, 152#endif 153 {% endfor %} 154 }, 155{% endif %} 156{% if counter.service_counter > 0 %} 157 .services = { 158 {% for service in manifest.services %} 159 { 160 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"), 161 {% if manifest.model == "SFN" %} 162 .sfn = ENTRY_TO_POSITION({{service.name|lower}}_sfn), 163 {% else %} 164 .sfn = 0, 165 {% endif %} 166{% if config_impl['CONFIG_TFM_SPM_BACKEND_IPC'] == '1' %} 167 {% if manifest.model == "SFN" %} 168 .signal = {{service.signal_value}}, 169 {% else %} 170 .signal = {{service.name}}_SIGNAL, 171 {% endif %} 172{% endif %} 173 174 .sid = {{service.sid}}, 175 .flags = 0 176 {% if service.non_secure_clients is sameas true %} 177 | SERVICE_FLAG_NS_ACCESSIBLE 178 {% endif %} 179 {% if service.connection_based is sameas false %} 180 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}} 181 {% endif %} 182 {% if service.mm_iovec == "enable" %} 183 | SERVICE_FLAG_MM_IOVEC 184 {% endif %} 185 | SERVICE_VERSION_POLICY_{{service.version_policy}}, 186 .version = {{service.version}}, 187 }, 188 {% endfor %} 189 }, 190{% endif %} 191#if TFM_ISOLATION_LEVEL == 3 192 .assets = { 193 { 194 .mem.start = (uintptr_t)®ION_NAME(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base), 195 .mem.limit = (uintptr_t)®ION_NAME(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base), 196 .attr = ASSET_ATTR_READ_WRITE, 197 }, 198{% if counter.asset_counter > 0 %} 199 {% for region in manifest.mmio_regions %} 200 {% if region.conditional %} 201#ifdef {{region.conditional}} 202 {% endif %} 203 {% if region.base and region.size %} 204 { 205 .mem.start = {{region.base}}, 206 .mem.limit = {{region.base}} + {{region.size}}, 207 .attr = ASSET_ATTR_NUMBERED_MMIO 208 {% elif region.name %} 209 { 210 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}), 211 .attr = ASSET_ATTR_NAMED_MMIO 212 {% endif %} 213 {% if region.permission == "READ-WRITE" %} 214 | ASSET_ATTR_READ_WRITE, 215 {% else %} 216 | ASSET_ATTR_READ_ONLY, 217 {% endif %} 218 }, 219 {% if region.conditional %} 220#endif 221 {% endif %} 222 {% endfor %} 223{% endif %} 224 }, 225#else 226{% if counter.asset_counter > 0 %} 227 .assets = { 228 {% for region in manifest.mmio_regions %} 229 {% if region.conditional %} 230#ifdef {{region.conditional}} 231 {% endif %} 232 {% if region.base and region.size %} 233 { 234 .mem.start = {{region.base}}, 235 .mem.limit = {{region.base}} + {{region.size}}, 236 .attr = ASSET_ATTR_NUMBERED_MMIO 237 {% elif region.name %} 238 { 239 .dev.dev_ref = PTR_TO_REFERENCE({{region.name}}), 240 .attr = ASSET_ATTR_NAMED_MMIO 241 {% endif %} 242 {% if region.permission == "READ-WRITE" %} 243 | ASSET_ATTR_READ_WRITE, 244 {% else %} 245 | ASSET_ATTR_READ_ONLY, 246 {% endif %} 247 }, 248 {% if region.conditional %} 249#endif 250 {% endif %} 251 {% endfor %} 252 }, 253{% endif %} 254#endif 255{% if counter.irq_counter > 0 %} 256 .irqs = { 257 {% for irq in manifest.irqs %} 258 {% set irq_info = namespace() %} 259 {% set irq_info.source = irq.source %} 260 {% if irq.source is number %}} 261 {% set irq_info.source_symbol = "irq_" + irq.source|string %} 262 {% else %} 263 {% set irq_info.source_symbol = irq.source|lower %} 264 {% endif %} 265 {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %} 266 {% set irq_info.flih_func = irq.name|lower + "_flih" %} 267 {% else %} 268 {% set irq_info.flih_func = 0 %} 269 {% endif %} 270 {% if manifest.psa_framework_version == 1.0 %} 271 {% set irq_info.signal = irq.signal %} 272 {% else %} 273 {% set irq_info.signal = irq.name + "_SIGNAL" %} 274 {% endif %} 275 {% if manifest.ns_agent is sameas true %} 276 {% set irq_info.client_id_base = irq.client_id_base %} 277 {% set irq_info.client_id_limit = irq.client_id_limit %} 278 {% endif %} 279 { 280 .init = {{irq_info.source_symbol + "_init"}}, 281 .flih_func = {{irq_info.flih_func}}, 282 .pid = {{manifest.name}}, 283 .source = {{irq_info.source}}, 284 .signal = {{irq_info.signal}}, 285 {% if manifest.ns_agent is sameas true %} 286 .client_id_base = {{irq_info.client_id_base}}, 287 .client_id_limit = {{irq_info.client_id_limit}}, 288 {% endif %} 289 }, 290 {% endfor %} 291 }, 292{% endif %} 293}; 294 295/* Placeholder for partition and service runtime space. Do not reference it. */ 296#if defined(__ICCARM__) 297#pragma location=".bss.part_runtime_priority_{{numbered_priority}}" 298__root 299#endif /* __ICCARM__ */ 300static struct partition_t {{manifest.name|lower}}_partition_runtime_item 301 __attribute__((used, section(".bss.part_runtime_priority_{{numbered_priority}}"))); 302{% if counter.service_counter > 0 %} 303#if defined(__ICCARM__) 304#pragma location = ".bss.serv_runtime_priority_{{numbered_priority}}" 305__root 306#endif /* __ICCARM__ */ 307static struct service_t {{manifest.name|lower}}_service_runtime_item[{{(manifest.name|upper + "_NSERVS")}}] 308 __attribute__((used, section(".bss.serv_runtime_priority_{{numbered_priority}}"))); 309{% endif %} 310