blob: 01aed35b76d8535e7b5daf7effcea58d0927d691 [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Mate Toth-Pal65291f32018-02-23 14:35:22 +01002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __SPM_SPM_DB_H__
9#define __SPM_SPM_DB_H__
10
11#include <stdint.h>
12
13/* This limit is only used to define the size of the database reserved for
Mate Toth-Pal349714a2018-02-23 15:30:24 +010014 * partitions. There's no requirement that it match the number of partitions
Miklos Balint386b8b52017-11-29 13:12:32 +000015 * that get registered in a specific build
16 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010017#define SPM_MAX_PARTITIONS (6)
Miklos Balint386b8b52017-11-29 13:12:32 +000018
Mate Toth-Pal349714a2018-02-23 15:30:24 +010019#define PARTITION_ID_GET(id) (id - TFM_SP_BASE)
Miklos Balint386b8b52017-11-29 13:12:32 +000020
Mate Toth-Pal349714a2018-02-23 15:30:24 +010021typedef int32_t(*sp_init_function)(void);
Miklos Balint386b8b52017-11-29 13:12:32 +000022
Mate Toth-Pal18b83922018-02-26 17:58:18 +010023struct spm_partition_static_data_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010024 uint32_t partition_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010025#if TFM_LVL != 1
Miklos Balint386b8b52017-11-29 13:12:32 +000026 uint32_t code_start;
27 uint32_t code_limit;
28 uint32_t ro_start;
29 uint32_t ro_limit;
30 uint32_t rw_start;
31 uint32_t rw_limit;
32 uint32_t zi_start;
33 uint32_t zi_limit;
34 uint32_t stack_bottom;
35 uint32_t stack_top;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010036#endif
Miklos Balint386b8b52017-11-29 13:12:32 +000037 uint32_t periph_start;
38 uint32_t periph_limit;
39 uint16_t periph_ppc_bank;
40 uint16_t periph_ppc_loc;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010041 sp_init_function partition_init;
Miklos Balint386b8b52017-11-29 13:12:32 +000042};
Mate Toth-Pal18b83922018-02-26 17:58:18 +010043
44struct spm_partition_desc_t {
45 struct spm_partition_static_data_t static_data;
46 struct spm_partition_runtime_data_t runtime_data;
47};
Miklos Balint386b8b52017-11-29 13:12:32 +000048
Mate Toth-Pal349714a2018-02-23 15:30:24 +010049struct spm_partition_db_t {
Miklos Balint386b8b52017-11-29 13:12:32 +000050 uint32_t is_init;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010051 uint32_t partition_count;
52 uint32_t running_partition_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010053 struct spm_partition_desc_t partitions[SPM_MAX_PARTITIONS];
Miklos Balint386b8b52017-11-29 13:12:32 +000054};
55
Mate Toth-Pal349714a2018-02-23 15:30:24 +010056/* Macros to pick linker symbols and allow to form the partition data base */
Miklos Balint386b8b52017-11-29 13:12:32 +000057#define REGION(a, b, c) a##b##c
58#define REGION_NAME(a, b, c) REGION(a, b, c)
59#if TFM_LVL == 1
60#define REGION_DECLARE(a, b, c)
61#else
62#define REGION_DECLARE(a, b, c) extern uint32_t REGION_NAME(a, b, c)
Mate Toth-Pal18b83922018-02-26 17:58:18 +010063#define PART_REGION_ADDR(partition, region) \
64 (uint32_t)&REGION_NAME(Image$$, partition, region)
Miklos Balint386b8b52017-11-29 13:12:32 +000065#endif
66
Mate Toth-Pal349714a2018-02-23 15:30:24 +010067#define PARTITION_DECLARE(partition) \
68 REGION_DECLARE(Image$$, partition, $$Base); \
69 REGION_DECLARE(Image$$, partition, $$Limit); \
70 REGION_DECLARE(Image$$, partition, $$RO$$Base); \
71 REGION_DECLARE(Image$$, partition, $$RO$$Limit); \
72 REGION_DECLARE(Image$$, partition, _DATA$$RW$$Base); \
73 REGION_DECLARE(Image$$, partition, _DATA$$RW$$Limit); \
74 REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Base); \
75 REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Limit); \
76 REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Base); \
77 REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Limit); \
Miklos Balint386b8b52017-11-29 13:12:32 +000078
79
80#if TFM_LVL == 1
Mate Toth-Pal18b83922018-02-26 17:58:18 +010081#define PARTITION_INIT_STATIC_DATA(data, partition) \
82 data.partition_id = partition##_ID; \
83 data.periph_start = 0U; \
84 data.periph_limit = 0U; \
85 data.periph_ppc_bank = 0U; \
86 data.periph_ppc_loc = 0U; \
87 data.partition_init = 0U
Miklos Balint386b8b52017-11-29 13:12:32 +000088#else
Mate Toth-Pal18b83922018-02-26 17:58:18 +010089#define PARTITION_INIT_STATIC_DATA(data, partition) \
90 data.partition_id = partition##_ID; \
91 data.code_start = PART_REGION_ADDR(partition, $$Base); \
92 data.code_limit = PART_REGION_ADDR(partition, $$Limit); \
93 data.ro_start = PART_REGION_ADDR(partition, $$RO$$Base); \
94 data.ro_limit = PART_REGION_ADDR(partition, $$RO$$Limit); \
95 data.rw_start = PART_REGION_ADDR(partition, _DATA$$RW$$Base); \
96 data.rw_limit = PART_REGION_ADDR(partition, _DATA$$RW$$Limit); \
97 data.zi_start = PART_REGION_ADDR(partition, _DATA$$ZI$$Base); \
98 data.zi_limit = PART_REGION_ADDR(partition, _DATA$$ZI$$Limit); \
99 data.stack_bottom = PART_REGION_ADDR(partition, _STACK$$ZI$$Base); \
100 data.stack_top = PART_REGION_ADDR(partition, _STACK$$ZI$$Limit); \
101 data.periph_start = 0U; \
102 data.periph_limit = 0U; \
103 data.periph_ppc_bank = 0U; \
104 data.periph_ppc_loc = 0U; \
105 data.partition_init = 0U
Miklos Balint386b8b52017-11-29 13:12:32 +0000106#endif
107
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100108#if TFM_LVL == 1
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100109#define DUMMY_PARTITION_INIT_STATIC_DATA(data, partition) \
110 /* In case of TFM_LVL1 the static data is initialised the same way */ \
111 PARTITION_INIT_STATIC_DATA(data, partition)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100112#else
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100113#define DUMMY_PARTITION_INIT_STATIC_DATA(data, partition) \
114 data.partition_id = partition##_ID; \
115 data.code_start = 0U; \
116 data.code_limit = 0U; \
117 data.ro_start = 0U; \
118 data.ro_limit = 0U; \
119 data.rw_start = 0U; \
120 data.rw_limit = 0U; \
121 data.zi_start = 0U; \
122 data.zi_limit = 0U; \
123 data.stack_bottom = 0U; \
124 data.stack_top = 0U; \
125 data.periph_start = 0U; \
126 data.periph_limit = 0U; \
127 data.periph_ppc_bank = 0U; \
128 data.periph_ppc_loc = 0U; \
129 data.partition_init = 0U
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100130#endif
131
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100132
133#if TFM_LVL == 1
134#define PARTITION_INIT_RUNTIME_DATA(data, partition) \
135 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
136 data.caller_partition_id = 0U; \
137 data.orig_psp = 0U; \
138 data.orig_psplim = 0U; \
139 data.orig_lr = 0U; \
140 data.share = 0U
141#else
142#define PARTITION_INIT_RUNTIME_DATA(data, partition) \
143 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
144 data.caller_partition_id = 0U; \
145 data.orig_psp = 0U; \
146 data.orig_psplim = 0U; \
147 data.orig_lr = 0U; \
148 data.share = 0U; \
149 data.stack_ptr = PART_REGION_ADDR(partition, _STACK$$ZI$$Limit)
150#endif
151
152#if TFM_LVL == 1
153#define DUMMY_PARTITION_INIT_RUNTIME_DATA(data, partition) \
154 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
155 data.caller_partition_id = 0U; \
156 data.orig_psp = 0U; \
157 data.orig_psplim = 0U; \
158 data.orig_lr = 0U; \
159 data.share = 0U
160#else
161#define DUMMY_PARTITION_INIT_RUNTIME_DATA(data, partition) \
162 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
163 data.caller_partition_id = 0U; \
164 data.orig_psp = 0U; \
165 data.orig_psplim = 0U; \
166 data.orig_lr = 0U; \
167 data.share = 0U; \
168 data.stack_ptr = 0U
169#endif
170
171#define PARTITION_ADD(partition) { \
172 if (index >= max_partitions) { \
173 return max_partitions; \
174 } \
175 part_ptr = (struct spm_partition_desc_t *)&(db->partitions[index]); \
176 PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition); \
177 PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \
178 index++; \
Miklos Balint386b8b52017-11-29 13:12:32 +0000179 }
180
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100181#define DUMMY_PARTITION_ADD(partition) { \
182 if (index >= max_partitions) { \
183 return max_partitions; \
184 } \
185 part_ptr = (struct spm_partition_desc_t *)&(db->partitions[index]); \
186 DUMMY_PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition); \
187 /* The runtime data is the same for the dummy partitions*/ \
188 DUMMY_PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \
189 index++; \
190 }
191
192#define PARTITION_ADD_PERIPHERAL(partition, start, limit, bank, loc) { \
193 part_ptr = &(db->partitions[PARTITION_ID_GET(partition##_ID)]); \
194 ((struct spm_partition_desc_t *)part_ptr)-> \
195 static_data.periph_start = start; \
196 ((struct spm_partition_desc_t *)part_ptr)-> \
197 static_data.periph_limit = limit; \
198 ((struct spm_partition_desc_t *)part_ptr)-> \
199 static_data.periph_ppc_bank = bank; \
200 ((struct spm_partition_desc_t *)part_ptr)-> \
201 static_data.periph_ppc_loc = loc; \
202 }
203
204#define PARTITION_ADD_INIT_FUNC(partition, init_func) { \
205 extern int32_t init_func(void); \
206 part_ptr = &(db->partitions[PARTITION_ID_GET(partition##_ID)]); \
207 ((struct spm_partition_desc_t *)part_ptr)-> \
208 static_data.partition_init = init_func; \
Miklos Balint386b8b52017-11-29 13:12:32 +0000209 }
210
211/*This file is meant to be included twice*/
212#include "user_service_defines.inc"
213
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100214struct spm_partition_db_t;
Miklos Balint386b8b52017-11-29 13:12:32 +0000215
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100216uint32_t create_user_partition_db(struct spm_partition_db_t *db,
217 uint32_t max_partitions)
Miklos Balint386b8b52017-11-29 13:12:32 +0000218{
219 uint32_t index = 0;
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100220 struct spm_partition_desc_t *part_ptr;
Miklos Balint386b8b52017-11-29 13:12:32 +0000221
222#include "user_service_defines.inc"
223
224 return index;
225}
226
227#endif /* __SPM_SPM_DB_H__ */