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