blob: 4b92557bae347f47611d9533d7be3efaba99f2b8 [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
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010016struct spm_partition_desc_t;
17struct spm_partition_db_t;
18
19uint32_t get_partition_idx(uint32_t partition_id);
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-Pal59398712018-02-28 17:06:40 +010025 uint32_t partition_flags;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010026#if TFM_LVL != 1
Miklos Balint386b8b52017-11-29 13:12:32 +000027 uint32_t code_start;
28 uint32_t code_limit;
29 uint32_t ro_start;
30 uint32_t ro_limit;
31 uint32_t rw_start;
32 uint32_t rw_limit;
33 uint32_t zi_start;
34 uint32_t zi_limit;
35 uint32_t stack_bottom;
36 uint32_t stack_top;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010037#endif
Miklos Balint386b8b52017-11-29 13:12:32 +000038 uint32_t periph_start;
39 uint32_t periph_limit;
40 uint16_t periph_ppc_bank;
41 uint16_t periph_ppc_loc;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010042 sp_init_function partition_init;
Miklos Balint386b8b52017-11-29 13:12:32 +000043};
Mate Toth-Pal18b83922018-02-26 17:58:18 +010044
45struct spm_partition_desc_t {
46 struct spm_partition_static_data_t static_data;
47 struct spm_partition_runtime_data_t runtime_data;
48};
Miklos Balint386b8b52017-11-29 13:12:32 +000049
Mate Toth-Pal349714a2018-02-23 15:30:24 +010050struct spm_partition_db_t {
Miklos Balint386b8b52017-11-29 13:12:32 +000051 uint32_t is_init;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010052 uint32_t partition_count;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010053 uint32_t running_partition_idx;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010054 struct spm_partition_desc_t partitions[SPM_MAX_PARTITIONS];
Miklos Balint386b8b52017-11-29 13:12:32 +000055};
56
Mate Toth-Pal349714a2018-02-23 15:30:24 +010057/* Macros to pick linker symbols and allow to form the partition data base */
Miklos Balint386b8b52017-11-29 13:12:32 +000058#define REGION(a, b, c) a##b##c
59#define REGION_NAME(a, b, c) REGION(a, b, c)
60#if TFM_LVL == 1
61#define REGION_DECLARE(a, b, c)
62#else
63#define REGION_DECLARE(a, b, c) extern uint32_t REGION_NAME(a, b, c)
Mate Toth-Pal18b83922018-02-26 17:58:18 +010064#define PART_REGION_ADDR(partition, region) \
65 (uint32_t)&REGION_NAME(Image$$, partition, region)
Miklos Balint386b8b52017-11-29 13:12:32 +000066#endif
67
Miklos Balint386b8b52017-11-29 13:12:32 +000068
69#if TFM_LVL == 1
Mate Toth-Pal59398712018-02-28 17:06:40 +010070#define PARTITION_INIT_STATIC_DATA(data, partition, flags) \
71 do { \
72 data.partition_id = partition##_ID; \
73 data.partition_flags = flags; \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010074 } while (0)
Miklos Balint386b8b52017-11-29 13:12:32 +000075#else
Mate Toth-Pal59398712018-02-28 17:06:40 +010076#define PARTITION_INIT_STATIC_DATA(data, partition, flags) \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010077 do { \
78 data.partition_id = partition##_ID; \
Mate Toth-Pal59398712018-02-28 17:06:40 +010079 data.partition_flags = flags; \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010080 data.code_start = PART_REGION_ADDR(partition, $$Base); \
81 data.code_limit = PART_REGION_ADDR(partition, $$Limit); \
82 data.ro_start = PART_REGION_ADDR(partition, $$RO$$Base); \
83 data.ro_limit = PART_REGION_ADDR(partition, $$RO$$Limit); \
84 data.rw_start = PART_REGION_ADDR(partition, _DATA$$RW$$Base); \
85 data.rw_limit = PART_REGION_ADDR(partition, _DATA$$RW$$Limit); \
86 data.zi_start = PART_REGION_ADDR(partition, _DATA$$ZI$$Base); \
87 data.zi_limit = PART_REGION_ADDR(partition, _DATA$$ZI$$Limit); \
88 data.stack_bottom = PART_REGION_ADDR(partition, _STACK$$ZI$$Base); \
89 data.stack_top = PART_REGION_ADDR(partition, _STACK$$ZI$$Limit); \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010090 } while (0)
Miklos Balint386b8b52017-11-29 13:12:32 +000091#endif
92
Mate Toth-Pal65291f32018-02-23 14:35:22 +010093#if TFM_LVL == 1
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010094#define PARTITION_INIT_RUNTIME_DATA(data, partition) \
95 do { \
96 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010097 } while (0)
Mate Toth-Pal65291f32018-02-23 14:35:22 +010098#else
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010099#define PARTITION_INIT_RUNTIME_DATA(data, partition) \
100 do { \
101 data.partition_state = SPM_PARTITION_STATE_UNINIT; \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100102 data.stack_ptr = \
103 PART_REGION_ADDR(partition, _STACK$$ZI$$Limit); \
104 } while (0)
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100105#endif
106
Mate Toth-Pal59398712018-02-28 17:06:40 +0100107#define PARTITION_DECLARE(partition, flags) \
108 do { \
109 REGION_DECLARE(Image$$, partition, $$Base); \
110 REGION_DECLARE(Image$$, partition, $$Limit); \
111 REGION_DECLARE(Image$$, partition, $$RO$$Base); \
112 REGION_DECLARE(Image$$, partition, $$RO$$Limit); \
113 REGION_DECLARE(Image$$, partition, _DATA$$RW$$Base); \
114 REGION_DECLARE(Image$$, partition, _DATA$$RW$$Limit); \
115 REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Base); \
116 REGION_DECLARE(Image$$, partition, _DATA$$ZI$$Limit); \
117 REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Base); \
118 REGION_DECLARE(Image$$, partition, _STACK$$ZI$$Limit); \
119 struct spm_partition_desc_t *part_ptr; \
120 if (g_spm_partition_db.partition_count >= SPM_MAX_PARTITIONS) { \
121 return SPM_ERR_INVALID_CONFIG; \
122 } \
123 part_ptr = &(g_spm_partition_db.partitions[ \
124 g_spm_partition_db.partition_count]); \
125 PARTITION_INIT_STATIC_DATA(part_ptr->static_data, partition, flags); \
126 PARTITION_INIT_RUNTIME_DATA(part_ptr->runtime_data, partition); \
127 ++g_spm_partition_db.partition_count; \
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100128 } while (0)
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100129
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100130#define PARTITION_ADD_INIT_FUNC(partition, init_func) \
131 do { \
132 extern int32_t init_func(void); \
133 uint32_t partition_idx = get_partition_idx(partition##_ID); \
134 struct spm_partition_desc_t *part_ptr = \
135 &(g_spm_partition_db.partitions[partition_idx]); \
136 part_ptr->static_data.partition_init = init_func; \
137 } while (0)
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100138
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100139#define PARTITION_ADD_PERIPHERAL(partition, start, limit, bank, loc) \
140 do { \
141 uint32_t partition_idx = get_partition_idx(partition##_ID); \
142 struct spm_partition_desc_t *part_ptr = \
143 &(g_spm_partition_db.partitions[partition_idx]); \
144 part_ptr->static_data.periph_start = start; \
145 part_ptr->static_data.periph_limit = limit; \
146 part_ptr->static_data.periph_ppc_bank = bank; \
147 part_ptr->static_data.periph_ppc_loc = loc; \
148 } while (0)
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100149
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100150#endif /* __SPM_DB_H__ */