Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | {{utilities.donotedit_warning}} |
| 9 | |
| 10 | #ifndef __TFM_SPM_DB_INC__ |
| 11 | #define __TFM_SPM_DB_INC__ |
| 12 | |
| 13 | #include "spm_api.h" |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 14 | #include "psa_manifest/sid.h" |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 15 | |
Edison Ai | 1545bb9 | 2019-11-14 14:15:27 +0800 | [diff] [blame^] | 16 | {# Produce a build error if heap_size is presented in the manifest, because of the dynamic memory allocation is not supported now. #} |
| 17 | {% for manifest in manifests %} |
| 18 | {% if manifest.manifest.heap_size %} |
| 19 | #error "Please do not add 'heap_size' for partition '{{manifest.manifest.name}}', the dynamic memory allocation is not supported now!" |
| 20 | {% endif %} |
| 21 | {% endfor %} |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 22 | /**************************************************************************/ |
| 23 | /** IRQ count per partition */ |
| 24 | /**************************************************************************/ |
| 25 | {% for manifest in manifests %} |
| 26 | {% if manifest.attr.conditional %} |
| 27 | #ifdef {{manifest.attr.conditional}} |
| 28 | {% endif %} |
| 29 | {% if manifest.manifest.irqs %} |
| 30 | #define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT {{manifest.manifest.irqs | length() }} |
| 31 | {% else %} |
| 32 | #define TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT 0 |
| 33 | {% endif %} |
| 34 | {% if manifest.attr.conditional %} |
| 35 | #endif /* {{manifest.attr.conditional}} */ |
| 36 | {% endif %} |
| 37 | |
| 38 | {% endfor %} |
| 39 | /**************************************************************************/ |
| 40 | /** Declarations of partition init functions */ |
| 41 | /**************************************************************************/ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 42 | #ifdef TFM_PSA_API |
Edison Ai | 9c48d20 | 2019-10-12 16:57:21 +0800 | [diff] [blame] | 43 | extern void tfm_nspm_thread_entry(void); |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 44 | #endif |
| 45 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 46 | {% for manifest in manifests %} |
| 47 | {% if manifest.attr.conditional %} |
| 48 | #ifdef {{manifest.attr.conditional}} |
| 49 | {% endif %} |
Edison Ai | 9c48d20 | 2019-10-12 16:57:21 +0800 | [diff] [blame] | 50 | extern void {{manifest.manifest.entry_point}}(void); |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 51 | {% if manifest.attr.conditional %} |
| 52 | #endif /* {{manifest.attr.conditional}} */ |
| 53 | {% endif %} |
| 54 | |
| 55 | {% endfor %} |
| 56 | /**************************************************************************/ |
| 57 | /** Memory region declarations */ |
| 58 | /**************************************************************************/ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 59 | #ifdef TFM_PSA_API |
| 60 | REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Base); |
| 61 | REGION_DECLARE(Image$$, ARM_LIB_STACK, $$ZI$$Limit); |
| 62 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 63 | {% for manifest in manifests %} |
| 64 | {% if manifest.attr.conditional %} |
| 65 | #ifdef {{manifest.attr.conditional}} |
| 66 | {% endif %} |
Edison Ai | b2134e6 | 2019-10-11 18:24:47 +0800 | [diff] [blame] | 67 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Base); |
| 68 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$Limit); |
| 69 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Base); |
| 70 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, $$RO$$Limit); |
| 71 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base); |
| 72 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit); |
| 73 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base); |
| 74 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit); |
| 75 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base); |
| 76 | REGION_DECLARE(Image$$, {{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit); |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 77 | {% if manifest.attr.conditional %} |
| 78 | #endif /* {{manifest.attr.conditional}} */ |
| 79 | {% endif %} |
| 80 | |
| 81 | {% endfor %} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 82 | #endif /* defined(TFM_PSA_API) */ |
| 83 | |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 84 | #ifndef TFM_PSA_API |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 85 | /**************************************************************************/ |
| 86 | /** Context stacks for IRQ handling */ |
| 87 | /**************************************************************************/ |
| 88 | /* The max size of the context stack can be calculated as a function of the IRQ |
| 89 | * count of the secure partition: |
| 90 | * |
| 91 | * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size)) |
| 92 | * |
| 93 | * where: |
| 94 | * intr_ctx: Frame pushed when the partition is interrupted |
| 95 | * hndl_ctx: Frame pushed when the partition is handling an interrupt |
| 96 | */ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 97 | static uint32_t ns_interrupt_ctx_stack[ |
| 98 | sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)]; |
| 99 | |
| 100 | static uint32_t tfm_core_interrupt_ctx_stack[ |
| 101 | sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)]; |
| 102 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 103 | {% for manifest in manifests %} |
| 104 | {% if manifest.attr.conditional %} |
| 105 | #ifdef {{manifest.attr.conditional}} |
| 106 | {% endif %} |
| 107 | static uint32_t ctx_stack_{{manifest.manifest.name}}[ |
| 108 | (sizeof(struct interrupted_ctx_stack_frame_t) + |
| 109 | (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * ( |
| 110 | sizeof(struct interrupted_ctx_stack_frame_t) + |
| 111 | sizeof(struct handler_ctx_stack_frame_t) |
| 112 | )) / sizeof(uint32_t)]; |
| 113 | {% if manifest.attr.conditional %} |
| 114 | #endif /* {{manifest.attr.conditional}} */ |
| 115 | {% endif %} |
| 116 | |
| 117 | {% endfor %} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 118 | |
| 119 | uint32_t *ctx_stack_list[] = |
| 120 | { |
| 121 | ns_interrupt_ctx_stack, |
| 122 | tfm_core_interrupt_ctx_stack, |
| 123 | {% for manifest in manifests %} |
| 124 | {% if manifest.attr.conditional %} |
| 125 | #ifdef {{manifest.attr.conditional}} |
| 126 | {% endif %} |
| 127 | ctx_stack_{{manifest.manifest.name}}, |
| 128 | {% if manifest.attr.conditional %} |
| 129 | #endif /* {{manifest.attr.conditional}} */ |
| 130 | {% endif %} |
| 131 | {% endfor %} |
| 132 | }; |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 133 | #endif /* !defined(TFM_PSA_API) */ |
| 134 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 135 | /**************************************************************************/ |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 136 | /** Dependencies array for Secure Partition */ |
| 137 | /**************************************************************************/ |
| 138 | {% for manifest in manifests %} |
| 139 | {% if manifest.manifest.dependencies %} |
| 140 | {% if manifest.attr.conditional %} |
| 141 | #ifdef {{manifest.attr.conditional}} |
| 142 | {% endif %} |
| 143 | static int32_t dependencies_{{manifest.manifest.name}}[] = |
| 144 | { |
| 145 | {% for dependence in manifest.manifest.dependencies %} |
| 146 | {{dependence}}_SID, |
| 147 | {% endfor %} |
| 148 | }; |
| 149 | {% if manifest.attr.conditional %} |
| 150 | #endif /* {{manifest.attr.conditional}} */ |
| 151 | {% endif %} |
| 152 | |
| 153 | {% endif %} |
| 154 | {% endfor %} |
| 155 | /**************************************************************************/ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 156 | /** The static data of the partition list */ |
| 157 | /**************************************************************************/ |
| 158 | const struct spm_partition_static_data_t static_data_list[] = |
| 159 | { |
| 160 | { |
Edison Ai | f050170 | 2019-10-11 14:36:42 +0800 | [diff] [blame] | 161 | #ifdef TFM_PSA_API |
| 162 | .psa_framework_version = 0x0100, |
| 163 | #endif /* defined(TFM_PSA_API) */ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 164 | .partition_id = TFM_SP_NON_SECURE_ID, |
| 165 | #ifdef TFM_PSA_API |
David Hu | 90128b7 | 2019-09-23 16:35:41 +0800 | [diff] [blame] | 166 | #if TFM_MULTI_CORE_TOPOLOGY |
| 167 | .partition_flags = SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_IPC, |
| 168 | #else |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 169 | .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_IPC, |
David Hu | 90128b7 | 2019-09-23 16:35:41 +0800 | [diff] [blame] | 170 | #endif |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 171 | .partition_priority = TFM_PRIORITY_LOW, |
| 172 | .partition_init = tfm_nspm_thread_entry, |
| 173 | #else |
| 174 | .partition_flags = 0, |
| 175 | #endif |
| 176 | }, |
| 177 | |
| 178 | #ifndef TFM_PSA_API |
| 179 | { |
| 180 | .partition_id = TFM_SP_CORE_ID, |
| 181 | .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT, |
| 182 | }, |
| 183 | #endif |
| 184 | |
| 185 | {% for manifest in manifests %} |
| 186 | {% if manifest.attr.conditional %} |
| 187 | #ifdef {{manifest.attr.conditional}} |
| 188 | {% endif %} |
| 189 | {{'{'}} |
Edison Ai | f050170 | 2019-10-11 14:36:42 +0800 | [diff] [blame] | 190 | #ifdef TFM_PSA_API |
| 191 | {% if manifest.manifest.psa_framework_version == 1.0 %} |
| 192 | .psa_framework_version = 0x0100, |
| 193 | {% else %} |
| 194 | .psa_framework_version = 0, |
| 195 | {% endif %} |
| 196 | #endif /* defined(TFM_PSA_API) */ |
Edison Ai | b2134e6 | 2019-10-11 18:24:47 +0800 | [diff] [blame] | 197 | .partition_id = {{manifest.manifest.name}}, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 198 | {% if manifest.attr.tfm_partition_ipc %} |
| 199 | .partition_flags = SPM_PART_FLAG_IPC |
| 200 | {% else %} |
| 201 | .partition_flags = 0 |
| 202 | {% endif %} |
| 203 | {% if manifest.manifest.type == "APPLICATION-ROT" %} |
| 204 | | SPM_PART_FLAG_APP_ROT |
| 205 | {% elif manifest.manifest.type == "PSA-ROT" %} |
| 206 | | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT |
| 207 | {% else %} |
| 208 | #error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!" |
| 209 | {% endif %} |
| 210 | , |
| 211 | .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}), |
| 212 | .partition_init = {{manifest.manifest.entry_point}}, |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 213 | .dependencies_num = {{manifest.manifest.dependencies | length()}}, |
| 214 | {% if manifest.manifest.dependencies %} |
| 215 | .p_dependencies = dependencies_{{manifest.manifest.name}}, |
| 216 | {% else %} |
| 217 | .p_dependencies = NULL, |
| 218 | {% endif %} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 219 | {{'},'}} |
| 220 | {% if manifest.attr.conditional %} |
| 221 | #endif /* {{manifest.attr.conditional}} */ |
| 222 | {% endif %} |
| 223 | |
| 224 | {% endfor %} |
| 225 | }; |
| 226 | |
| 227 | /**************************************************************************/ |
| 228 | /** The platform data of the partition list */ |
| 229 | /**************************************************************************/ |
| 230 | const struct tfm_spm_partition_platform_data_t *platform_data_list[] = |
| 231 | { |
| 232 | NULL, |
| 233 | |
| 234 | #ifndef TFM_PSA_API |
| 235 | NULL, |
| 236 | #endif |
| 237 | |
| 238 | {% for manifest in manifests %} |
| 239 | {% if manifest.attr.conditional %} |
| 240 | #ifdef {{manifest.attr.conditional}} |
| 241 | {% endif %} |
| 242 | {% if manifest.manifest.mmio_regions %} |
| 243 | /* FIXME: Only adding the first mmio region */ |
| 244 | {% for region in manifest.manifest.mmio_regions %} |
| 245 | {% if loop.first %} |
| 246 | {% if region.conditional %} |
| 247 | #ifdef {{region.conditional}} |
| 248 | {% endif %} |
| 249 | {{region.name}}, |
| 250 | {% if region.conditional %} |
| 251 | #else /* {{region.conditional}} */ |
| 252 | NULL, |
| 253 | #endif /* {{region.conditional}} */ |
| 254 | {% endif %} |
| 255 | {% else %} {# print nothing #} {% endif %} |
| 256 | {% endfor %} |
| 257 | {% else %} |
| 258 | NULL, |
| 259 | {% endif %} |
| 260 | {% if manifest.attr.conditional %} |
| 261 | #endif /* {{manifest.attr.conditional}} */ |
| 262 | {% endif %} |
| 263 | |
| 264 | {% endfor %} |
| 265 | }; |
| 266 | |
| 267 | /**************************************************************************/ |
| 268 | /** The memory data of the partition list */ |
| 269 | /**************************************************************************/ |
| 270 | #ifdef TFM_PSA_API |
| 271 | const struct tfm_spm_partition_memory_data_t memory_data_list[] = |
| 272 | { |
| 273 | { |
| 274 | .stack_bottom = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base), |
| 275 | .stack_top = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Limit), |
| 276 | .rw_start = PART_REGION_ADDR(ARM_LIB_STACK, $$ZI$$Base), |
| 277 | }, |
| 278 | {% for manifest in manifests %} |
| 279 | {% if manifest.attr.conditional %} |
| 280 | #ifdef {{manifest.attr.conditional}} |
| 281 | {% endif %} |
| 282 | {{'{'}} |
Edison Ai | b2134e6 | 2019-10-11 18:24:47 +0800 | [diff] [blame] | 283 | .code_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Base), |
| 284 | .code_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$Limit), |
| 285 | .ro_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Base), |
| 286 | .ro_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, $$RO$$Limit), |
| 287 | .rw_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Base), |
| 288 | .rw_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$RW$$Limit), |
| 289 | .zi_start = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Base), |
| 290 | .zi_limit = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _DATA$$ZI$$Limit), |
| 291 | .stack_bottom = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Base), |
| 292 | .stack_top = PART_REGION_ADDR({{manifest.manifest.name}}_LINKER, _STACK$$ZI$$Limit), |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 293 | {{'},'}} |
| 294 | {% if manifest.attr.conditional %} |
| 295 | #endif /* {{manifest.attr.conditional}} */ |
| 296 | {% endif %} |
| 297 | |
| 298 | {% endfor %} |
| 299 | }; |
| 300 | #endif /* defined(TFM_PSA_API) */ |
| 301 | |
| 302 | /**************************************************************************/ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 303 | /** The partition list for the DB */ |
| 304 | /**************************************************************************/ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 305 | static struct spm_partition_desc_t partition_list [] = |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 306 | { |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 307 | {{'{{}}'}}, /* placeholder for Non-secure internal partition */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 308 | #ifndef TFM_PSA_API |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 309 | {{'{{}}'}}, /* placeholder for TF-M Core internal partition */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 310 | #endif /* !ifndefined(TFM_PSA_API) */ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 311 | |
| 312 | {% for manifest in manifests %} |
| 313 | /* -----------------------------------------------------------------------*/ |
| 314 | /* - Partition DB record for {{manifest.manifest.name}} */ |
| 315 | /* -----------------------------------------------------------------------*/ |
| 316 | {% if manifest.attr.conditional %} |
| 317 | #ifdef {{manifest.attr.conditional}} |
| 318 | {% endif %} |
| 319 | {{'{'}} |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 320 | /* Runtime data */ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 321 | .runtime_data = {}, |
| 322 | .static_data = NULL, |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 323 | .platform_data = NULL, |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 324 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 325 | {{'},'}} |
| 326 | {% if manifest.attr.conditional %} |
| 327 | #endif /* {{manifest.attr.conditional}} */ |
| 328 | {% endif %} |
| 329 | |
| 330 | {% endfor %} |
| 331 | }; |
| 332 | |
| 333 | struct spm_partition_db_t g_spm_partition_db = { |
| 334 | .is_init = 0, |
| 335 | .partition_count = sizeof(partition_list) / sizeof(partition_list[0]), |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 336 | #ifndef TFM_PSA_API |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 337 | .running_partition_idx = 0, |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 338 | #endif |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 339 | .partitions = partition_list, |
| 340 | }; |
| 341 | |
| 342 | #endif /* __TFM_SPM_DB_INC__ */ |