blob: 45b68712c4ee682cd03e4dca1b9e7207e96266e6 [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
Mate Toth-Pal52674ab2018-02-26 09:47:56 +01008#ifndef __SPM_DB_H__
9#define __SPM_DB_H__
Miklos Balint386b8b52017-11-29 13:12:32 +000010
11#include <stdint.h>
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010012#include "platform_retarget.h"
13#include "target_cfg.h"
14#include "spm_partition_defs.h"
Miklos Balint386b8b52017-11-29 13:12:32 +000015
16/* This limit is only used to define the size of the database reserved for
Mate Toth-Pal349714a2018-02-23 15:30:24 +010017 * partitions. There's no requirement that it match the number of partitions
Miklos Balint386b8b52017-11-29 13:12:32 +000018 * that get registered in a specific build
19 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010020#define SPM_MAX_PARTITIONS (6)
Miklos Balint386b8b52017-11-29 13:12:32 +000021
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010022struct spm_partition_desc_t;
23struct spm_partition_db_t;
24
25uint32_t get_partition_idx(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000026
Mate Toth-Pal349714a2018-02-23 15:30:24 +010027typedef int32_t(*sp_init_function)(void);
Miklos Balint386b8b52017-11-29 13:12:32 +000028
Mate Toth-Pal18b83922018-02-26 17:58:18 +010029struct spm_partition_static_data_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010030 uint32_t partition_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010031#if TFM_LVL != 1
Miklos Balint386b8b52017-11-29 13:12:32 +000032 uint32_t code_start;
33 uint32_t code_limit;
34 uint32_t ro_start;
35 uint32_t ro_limit;
36 uint32_t rw_start;
37 uint32_t rw_limit;
38 uint32_t zi_start;
39 uint32_t zi_limit;
40 uint32_t stack_bottom;
41 uint32_t stack_top;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010042#endif
Miklos Balint386b8b52017-11-29 13:12:32 +000043 uint32_t periph_start;
44 uint32_t periph_limit;
45 uint16_t periph_ppc_bank;
46 uint16_t periph_ppc_loc;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010047 sp_init_function partition_init;
Miklos Balint386b8b52017-11-29 13:12:32 +000048};
Mate Toth-Pal18b83922018-02-26 17:58:18 +010049
50struct spm_partition_desc_t {
51 struct spm_partition_static_data_t static_data;
52 struct spm_partition_runtime_data_t runtime_data;
53};
Miklos Balint386b8b52017-11-29 13:12:32 +000054
Mate Toth-Pal349714a2018-02-23 15:30:24 +010055struct spm_partition_db_t {
Miklos Balint386b8b52017-11-29 13:12:32 +000056 uint32_t is_init;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010057 uint32_t partition_count;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010058 uint32_t running_partition_idx;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010059 struct spm_partition_desc_t partitions[SPM_MAX_PARTITIONS];
Miklos Balint386b8b52017-11-29 13:12:32 +000060};
61
Mate Toth-Pal349714a2018-02-23 15:30:24 +010062/* Macros to pick linker symbols and allow to form the partition data base */
Miklos Balint386b8b52017-11-29 13:12:32 +000063#define REGION(a, b, c) a##b##c
64#define REGION_NAME(a, b, c) REGION(a, b, c)
65#if TFM_LVL == 1
66#define REGION_DECLARE(a, b, c)
67#else
68#define REGION_DECLARE(a, b, c) extern uint32_t REGION_NAME(a, b, c)
Mate Toth-Pal18b83922018-02-26 17:58:18 +010069#define PART_REGION_ADDR(partition, region) \
70 (uint32_t)&REGION_NAME(Image$$, partition, region)
Miklos Balint386b8b52017-11-29 13:12:32 +000071#endif
72
Miklos Balint386b8b52017-11-29 13:12:32 +000073
74#if TFM_LVL == 1
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010075#define PARTITION_INIT_STATIC_DATA(data, partition) \
76 do { \
77 data.partition_id = partition##_ID; \
78 data.periph_start = 0U; \
79 data.periph_limit = 0U; \
80 data.periph_ppc_bank = 0U; \
81 data.periph_ppc_loc = 0U; \
82 data.partition_init = 0U; \
83 } while (0)
Miklos Balint386b8b52017-11-29 13:12:32 +000084#else
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010085#define PARTITION_INIT_STATIC_DATA(data, partition) \
86 do { \
87 data.partition_id = partition##_ID; \
88 data.code_start = PART_REGION_ADDR(partition, $$Base); \
89 data.code_limit = PART_REGION_ADDR(partition, $$Limit); \
90 data.ro_start = PART_REGION_ADDR(partition, $$RO$$Base); \
91 data.ro_limit = PART_REGION_ADDR(partition, $$RO$$Limit); \
92 data.rw_start = PART_REGION_ADDR(partition, _DATA$$RW$$Base); \
93 data.rw_limit = PART_REGION_ADDR(partition, _DATA$$RW$$Limit); \
94 data.zi_start = PART_REGION_ADDR(partition, _DATA$$ZI$$Base); \
95 data.zi_limit = PART_REGION_ADDR(partition, _DATA$$ZI$$Limit); \
96 data.stack_bottom = PART_REGION_ADDR(partition, _STACK$$ZI$$Base); \
97 data.stack_top = PART_REGION_ADDR(partition, _STACK$$ZI$$Limit); \
98 data.periph_start = 0U; \
99 data.periph_limit = 0U; \
100 data.periph_ppc_bank = 0U; \
101 data.periph_ppc_loc = 0U; \
102 data.partition_init = 0U; \
103 } while (0)
Miklos Balint386b8b52017-11-29 13:12:32 +0000104#endif
105
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100106#if TFM_LVL == 1
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100107#define PARTITION_INIT_RUNTIME_DATA(data, partition) \
108 do { \
109 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
110 data.caller_partition_idx = 0U; \
111 data.orig_psp = 0U; \
112 data.orig_psplim = 0U; \
113 data.orig_lr = 0U; \
114 data.share = 0U; \
115 } while (0)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100116#else
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100117#define PARTITION_INIT_RUNTIME_DATA(data, partition) \
118 do { \
119 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
120 data.caller_partition_idx = 0U; \
121 data.orig_psp = 0U; \
122 data.orig_psplim = 0U; \
123 data.orig_lr = 0U; \
124 data.share = 0U; \
125 data.stack_ptr = \
126 PART_REGION_ADDR(partition, _STACK$$ZI$$Limit); \
127 } while (0)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100128#endif
129
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100130#define PARTITION_DECLARE(partition) \
131 do { \
132 REGION_DECLARE(Image$$, partition, $$Base); \
133 REGION_DECLARE(Image$$, partition, $$Limit); \
134 REGION_DECLARE(Image$$, partition, $$RO$$Base); \
135 REGION_DECLARE(Image$$, partition, $$RO$$Limit); \
136 REGION_DECLARE(Image$$, partition, _DATA$$RW$$Base); \
137 REGION_DECLARE(Image$$, partition, _DATA$$RW$$Limit); \
138 REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Base); \
139 REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Limit); \
140 REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Base); \
141 REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Limit); \
142 struct spm_partition_desc_t *part_ptr; \
143 if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
144 return SPM_ERR_INVALID_CONFIG; \
145 } \
146 part_ptr = &(g_spm_partition_db.partitions[ \
147 g_spm_partition_db.partition_count]); \
148 PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition); \
149 PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \
150 ++g_spm_partition_db.partition_count; \
151 } while (0)
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100152
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100153#define PARTITION_ADD_INIT_FUNC(partition, init_func) \
154 do { \
155 extern int32_t init_func(void); \
156 uint32_t partition_idx = get_partition_idx(partition##_ID); \
157 struct spm_partition_desc_t *part_ptr = \
158 &(g_spm_partition_db.partitions[partition_idx]); \
159 part_ptr->static_data.partition_init = init_func; \
160 } while (0)
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100161
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100162#define PARTITION_ADD_PERIPHERAL(partition, start, limit, bank, loc) \
163 do { \
164 uint32_t partition_idx = get_partition_idx(partition##_ID); \
165 struct spm_partition_desc_t *part_ptr = \
166 &(g_spm_partition_db.partitions[partition_idx]); \
167 part_ptr->static_data.periph_start = start; \
168 part_ptr->static_data.periph_limit = limit; \
169 part_ptr->static_data.periph_ppc_bank = bank; \
170 part_ptr->static_data.periph_ppc_loc = loc; \
171 } while (0)
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100172
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100173#endif /* __SPM_DB_H__ */