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