Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 1 | /* |
TTornblom | 83d9637 | 2019-11-19 12:53:16 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | {{utilities.donotedit_warning}} |
| 9 | |
Shawn Shan | 071d86d | 2020-05-25 17:32:58 +0800 | [diff] [blame] | 10 | #ifndef __TFM_SPM_DB_FUNC_INC__ |
| 11 | #define __TFM_SPM_DB_FUNC_INC__ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 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 | /**************************************************************************/ |
| 42 | {% for manifest in manifests %} |
| 43 | {% if manifest.attr.conditional %} |
| 44 | #ifdef {{manifest.attr.conditional}} |
| 45 | {% endif %} |
Edison Ai | 9c48d20 | 2019-10-12 16:57:21 +0800 | [diff] [blame] | 46 | extern void {{manifest.manifest.entry_point}}(void); |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 47 | {% if manifest.attr.conditional %} |
| 48 | #endif /* {{manifest.attr.conditional}} */ |
| 49 | {% endif %} |
| 50 | |
| 51 | {% endfor %} |
| 52 | /**************************************************************************/ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 53 | /** Context stacks for IRQ handling */ |
| 54 | /**************************************************************************/ |
| 55 | /* The max size of the context stack can be calculated as a function of the IRQ |
| 56 | * count of the secure partition: |
| 57 | * |
| 58 | * max_stack_size = intr_ctx_size + (IRQ_CNT * (intr_ctx_size + hndl_ctx_size)) |
| 59 | * |
| 60 | * where: |
| 61 | * intr_ctx: Frame pushed when the partition is interrupted |
| 62 | * hndl_ctx: Frame pushed when the partition is handling an interrupt |
| 63 | */ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 64 | static uint32_t ns_interrupt_ctx_stack[ |
| 65 | sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)]; |
| 66 | |
| 67 | static uint32_t tfm_core_interrupt_ctx_stack[ |
| 68 | sizeof(struct interrupted_ctx_stack_frame_t) / sizeof(uint32_t)]; |
| 69 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 70 | {% for manifest in manifests %} |
| 71 | {% if manifest.attr.conditional %} |
| 72 | #ifdef {{manifest.attr.conditional}} |
| 73 | {% endif %} |
| 74 | static uint32_t ctx_stack_{{manifest.manifest.name}}[ |
| 75 | (sizeof(struct interrupted_ctx_stack_frame_t) + |
| 76 | (TFM_PARTITION_{{manifest.manifest.name}}_IRQ_COUNT) * ( |
| 77 | sizeof(struct interrupted_ctx_stack_frame_t) + |
| 78 | sizeof(struct handler_ctx_stack_frame_t) |
| 79 | )) / sizeof(uint32_t)]; |
| 80 | {% if manifest.attr.conditional %} |
| 81 | #endif /* {{manifest.attr.conditional}} */ |
| 82 | {% endif %} |
| 83 | |
| 84 | {% endfor %} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 85 | uint32_t *ctx_stack_list[] = |
| 86 | { |
| 87 | ns_interrupt_ctx_stack, |
| 88 | tfm_core_interrupt_ctx_stack, |
| 89 | {% for manifest in manifests %} |
| 90 | {% if manifest.attr.conditional %} |
| 91 | #ifdef {{manifest.attr.conditional}} |
| 92 | {% endif %} |
| 93 | ctx_stack_{{manifest.manifest.name}}, |
| 94 | {% if manifest.attr.conditional %} |
| 95 | #endif /* {{manifest.attr.conditional}} */ |
| 96 | {% endif %} |
| 97 | {% endfor %} |
| 98 | }; |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 99 | |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 100 | /**************************************************************************/ |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 101 | /** Dependencies array for Secure Partition */ |
| 102 | /**************************************************************************/ |
| 103 | {% for manifest in manifests %} |
| 104 | {% if manifest.manifest.dependencies %} |
| 105 | {% if manifest.attr.conditional %} |
| 106 | #ifdef {{manifest.attr.conditional}} |
| 107 | {% endif %} |
| 108 | static int32_t dependencies_{{manifest.manifest.name}}[] = |
| 109 | { |
| 110 | {% for dependence in manifest.manifest.dependencies %} |
Edison Ai | b262cc4 | 2019-12-20 14:47:52 +0800 | [diff] [blame] | 111 | {% for service in manifest.manifest.services %} |
| 112 | {% if dependence == service.name %} |
| 113 | #error "Please DO NOT include SP's own RoT Service '{{dependence}}', which will cause a deadlock!" |
| 114 | {% endif %} |
| 115 | {% endfor %} |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 116 | {{dependence}}_SID, |
| 117 | {% endfor %} |
| 118 | }; |
| 119 | {% if manifest.attr.conditional %} |
| 120 | #endif /* {{manifest.attr.conditional}} */ |
| 121 | {% endif %} |
| 122 | |
| 123 | {% endif %} |
| 124 | {% endfor %} |
| 125 | /**************************************************************************/ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 126 | /** The static data of the partition list */ |
| 127 | /**************************************************************************/ |
| 128 | const struct spm_partition_static_data_t static_data_list[] = |
| 129 | { |
| 130 | { |
| 131 | .partition_id = TFM_SP_NON_SECURE_ID, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 132 | .partition_flags = 0, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 133 | }, |
| 134 | |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 135 | { |
| 136 | .partition_id = TFM_SP_CORE_ID, |
| 137 | .partition_flags = SPM_PART_FLAG_APP_ROT | SPM_PART_FLAG_PSA_ROT, |
| 138 | }, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 139 | |
| 140 | {% for manifest in manifests %} |
| 141 | {% if manifest.attr.conditional %} |
| 142 | #ifdef {{manifest.attr.conditional}} |
| 143 | {% endif %} |
| 144 | {{'{'}} |
Edison Ai | b2134e6 | 2019-10-11 18:24:47 +0800 | [diff] [blame] | 145 | .partition_id = {{manifest.manifest.name}}, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 146 | {% if manifest.attr.tfm_partition_ipc %} |
| 147 | .partition_flags = SPM_PART_FLAG_IPC |
| 148 | {% else %} |
| 149 | .partition_flags = 0 |
| 150 | {% endif %} |
| 151 | {% if manifest.manifest.type == "APPLICATION-ROT" %} |
| 152 | | SPM_PART_FLAG_APP_ROT |
| 153 | {% elif manifest.manifest.type == "PSA-ROT" %} |
| 154 | | SPM_PART_FLAG_PSA_ROT | SPM_PART_FLAG_APP_ROT |
| 155 | {% else %} |
| 156 | #error "Unsupported type '{{manifest.manifest.type}}' for partition '{{manifest.manifest.name}}'!" |
| 157 | {% endif %} |
| 158 | , |
| 159 | .partition_priority = TFM_PRIORITY({{manifest.manifest.priority}}), |
| 160 | .partition_init = {{manifest.manifest.entry_point}}, |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 161 | .dependencies_num = {{manifest.manifest.dependencies | length()}}, |
| 162 | {% if manifest.manifest.dependencies %} |
| 163 | .p_dependencies = dependencies_{{manifest.manifest.name}}, |
| 164 | {% else %} |
| 165 | .p_dependencies = NULL, |
| 166 | {% endif %} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 167 | {{'},'}} |
| 168 | {% if manifest.attr.conditional %} |
| 169 | #endif /* {{manifest.attr.conditional}} */ |
| 170 | {% endif %} |
| 171 | |
| 172 | {% endfor %} |
| 173 | }; |
| 174 | |
| 175 | /**************************************************************************/ |
| 176 | /** The platform data of the partition list */ |
| 177 | /**************************************************************************/ |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 178 | {% for manifest in manifests %} |
| 179 | {% if manifest.manifest.mmio_regions %} |
| 180 | {% if manifest.attr.conditional %} |
| 181 | #ifdef {{manifest.attr.conditional}} |
| 182 | {% endif %} |
| 183 | const struct tfm_spm_partition_platform_data_t * |
| 184 | platform_data_list_{{manifest.manifest.name}}[] = |
| 185 | { |
| 186 | {% for region in manifest.manifest.mmio_regions %} |
| 187 | {% if region.conditional %} |
| 188 | #ifdef {{region.conditional}} |
| 189 | {% endif %} |
| 190 | {{region.name}}, |
| 191 | {% if region.conditional %} |
| 192 | #endif /* {{region.conditional}} */ |
| 193 | {% endif %} |
| 194 | {% endfor %} |
| 195 | NULL |
| 196 | }; |
| 197 | {% if manifest.attr.conditional %} |
| 198 | #endif /* {{manifest.attr.conditional}} */ |
| 199 | {% endif %} |
| 200 | |
| 201 | {% endif %} |
| 202 | {% endfor %} |
| 203 | const struct tfm_spm_partition_platform_data_t **platform_data_list_list[] = |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 204 | { |
| 205 | NULL, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 206 | NULL, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 207 | |
| 208 | {% for manifest in manifests %} |
| 209 | {% if manifest.attr.conditional %} |
| 210 | #ifdef {{manifest.attr.conditional}} |
| 211 | {% endif %} |
| 212 | {% if manifest.manifest.mmio_regions %} |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 213 | platform_data_list_{{manifest.manifest.name}}, |
| 214 | {% else %}{# if manifest.manifest.mmio_regions #} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 215 | NULL, |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 216 | {% endif %}{# if manifest.manifest.mmio_regions #} |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 217 | {% if manifest.attr.conditional %} |
| 218 | #endif /* {{manifest.attr.conditional}} */ |
| 219 | {% endif %} |
| 220 | |
| 221 | {% endfor %} |
| 222 | }; |
| 223 | |
| 224 | /**************************************************************************/ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 225 | /** The partition list for the DB */ |
| 226 | /**************************************************************************/ |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 227 | static struct spm_partition_desc_t partition_list [] = |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 228 | { |
TTornblom | 83d9637 | 2019-11-19 12:53:16 +0100 | [diff] [blame] | 229 | {{'{{0}}'}}, /* placeholder for Non-secure internal partition */ |
TTornblom | 83d9637 | 2019-11-19 12:53:16 +0100 | [diff] [blame] | 230 | {{'{{0}}'}}, /* placeholder for TF-M Core internal partition */ |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 231 | |
| 232 | {% for manifest in manifests %} |
| 233 | /* -----------------------------------------------------------------------*/ |
| 234 | /* - Partition DB record for {{manifest.manifest.name}} */ |
| 235 | /* -----------------------------------------------------------------------*/ |
| 236 | {% if manifest.attr.conditional %} |
| 237 | #ifdef {{manifest.attr.conditional}} |
| 238 | {% endif %} |
| 239 | {{'{'}} |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 240 | /* Runtime data */ |
TTornblom | 83d9637 | 2019-11-19 12:53:16 +0100 | [diff] [blame] | 241 | .runtime_data = {0}, |
Summer Qin | 423dbef | 2019-08-22 15:59:35 +0800 | [diff] [blame] | 242 | .static_data = NULL, |
Mate Toth-Pal | 8ac98a7 | 2019-11-21 17:30:10 +0100 | [diff] [blame] | 243 | .platform_data_list = NULL, |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 244 | {{'},'}} |
| 245 | {% if manifest.attr.conditional %} |
| 246 | #endif /* {{manifest.attr.conditional}} */ |
| 247 | {% endif %} |
| 248 | |
| 249 | {% endfor %} |
| 250 | }; |
| 251 | |
| 252 | struct spm_partition_db_t g_spm_partition_db = { |
| 253 | .is_init = 0, |
| 254 | .partition_count = sizeof(partition_list) / sizeof(partition_list[0]), |
| 255 | .running_partition_idx = 0, |
Mate Toth-Pal | 3ad2e3e | 2019-07-11 21:43:37 +0200 | [diff] [blame] | 256 | .partitions = partition_list, |
| 257 | }; |
| 258 | |
Shawn Shan | 071d86d | 2020-05-25 17:32:58 +0800 | [diff] [blame] | 259 | #endif /* __TFM_SPM_DB_FUNC_INC__ */ |