1 /*
2  * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include <stdint.h>
9 #include <stddef.h>
10 #include "spm.h"
11 #include "load/partition_defs.h"
12 #include "load/service_defs.h"
13 #include "load/asset_defs.h"
14 /* Note that region_defs.h must be included before tfm_s_linker_alignments.h
15  * to let platform overwrite default alignment values.
16  */
17 #include "region_defs.h"
18 #include "tfm_s_linker_alignments.h"
19 
20 #if TFM_ISOLATION_LEVEL == 3
21 #define TFM_SP_IDLE_NASSETS     (1)
22 #endif
23 
24 /* Stack size must be aligned to satisfy platform alignment requirements */
25 #define IDLE_SP_STACK_SIZE \
26     ROUND_UP_TO_MULTIPLE(0x100, TFM_LINKER_IDLE_PARTITION_STACK_ALIGNMENT)
27 
28 struct partition_tfm_sp_idle_load_info_t {
29     /* common length load data */
30     struct partition_load_info_t    load_info;
31     /* per-partition variable length load data */
32     uintptr_t                       stack_addr;
33     uintptr_t                       heap_addr;
34 #if TFM_ISOLATION_LEVEL == 3
35     struct asset_desc_t             assets[TFM_SP_IDLE_NASSETS];
36 #endif
37 } __attribute__((aligned(4)));
38 
39 /* Entrypoint function declaration */
40 extern void tfm_idle_thread(void);
41 /* Stack */
42 uint8_t idle_sp_stack[IDLE_SP_STACK_SIZE] __attribute__((aligned(TFM_LINKER_IDLE_PARTITION_STACK_ALIGNMENT)));
43 
44 /* Partition load, deps, service load data. Put to a dedicated section. */
45 #if defined(__ICCARM__)
46 /* Section priority: lowest */
47 #pragma location = ".part_load_priority_00"
48 __root
49 #endif
50 const struct partition_tfm_sp_idle_load_info_t
51     tfm_sp_idle_load __attribute__((used, section(".part_load_priority_00"))) = {
52     .load_info = {
53         .psa_ff_ver                 = 0x0101 | PARTITION_INFO_MAGIC,
54         .pid                        = TFM_SP_IDLE,
55         .flags                      = PARTITION_PRI_LOWEST | PARTITION_MODEL_IPC
56                                       | PARTITION_MODEL_PSA_ROT,
57         .entry                      = ENTRY_TO_POSITION(tfm_idle_thread),
58         .stack_size                 = IDLE_SP_STACK_SIZE,
59         .heap_size                  = 0,
60         .ndeps                      = 0,
61         .nservices                  = 0,
62 #if TFM_ISOLATION_LEVEL == 3
63         .nassets                    = TFM_SP_IDLE_NASSETS,
64 #else
65         .nassets                    = 0,
66 #endif
67     },
68     .stack_addr                     = (uintptr_t)idle_sp_stack,
69     .heap_addr                      = 0,
70 #if TFM_ISOLATION_LEVEL == 3
71     .assets                         = {
72         {
73             .mem.start              = (uintptr_t)idle_sp_stack,
74 
75             .mem.limit              = (uintptr_t)&idle_sp_stack[IDLE_SP_STACK_SIZE],
76             .attr                   = ASSET_ATTR_READ_WRITE,
77         },
78     },
79 #endif
80 };
81 
82 /* Placeholder for partition runtime space. Do not reference it. */
83 #if defined(__ICCARM__)
84 /* Section priority: lowest */
85 #pragma location = ".bss.part_runtime_priority_00"
86 __root
87 #endif
88 static struct partition_t tfm_idle_partition_runtime_item
89     __attribute__((used, section(".bss.part_runtime_priority_00")));
90