blob: 7b74aba4a17fa02a654ace903049058c562dab19 [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +01002 * Copyright (c) 2017-2019, 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
Edison Ai807fedb2019-03-07 11:22:03 +080011
Edison Aibb614aa2018-11-21 15:15:00 +080012#ifdef TFM_PSA_API
13#include "tfm_thread.h"
14#endif
15
16struct spm_partition_desc_t;
17struct spm_partition_db_t;
18
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010019typedef psa_status_t(*sp_init_function)(void);
Miklos Balint386b8b52017-11-29 13:12:32 +000020
Edison Aibb614aa2018-11-21 15:15:00 +080021#define TFM_PARTITION_TYPE_APP "APPLICATION-ROT"
22#define TFM_PARTITION_TYPE_PSA "PSA-ROT"
23
24#ifdef TFM_PSA_API
Hugues de Valon99578562019-06-18 16:08:51 +010025#define TFM_PRIORITY_LOW THRD_PRIOR_LOWEST
26#define TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM
27#define TFM_PRIORITY_HIGH THRD_PRIOR_HIGHEST
Edison Aibb614aa2018-11-21 15:15:00 +080028#else
Hugues de Valon99578562019-06-18 16:08:51 +010029#define TFM_PRIORITY_LOW 0xFF
30#define TFM_PRIORITY_NORMAL 0x7F
31#define TFM_PRIORITY_HIGH 0
Edison Aibb614aa2018-11-21 15:15:00 +080032#endif
33
34#define TFM_PRIORITY(LEVEL) TFM_PRIORITY_##LEVEL
35
Mate Toth-Pale1475332018-04-09 17:28:49 +020036/**
37 * Holds the fields of the partition DB used by the SPM code. The values of
38 * these fields are calculated at compile time, and set during initialisation
39 * phase.
40 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +010041struct spm_partition_static_data_t {
Edison Ai66fbdf12019-07-08 16:05:07 +080042 int32_t index; /* Partition index */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010043 uint32_t partition_id;
Mate Toth-Pal59398712018-02-28 17:06:40 +010044 uint32_t partition_flags;
Edison Aibb614aa2018-11-21 15:15:00 +080045 uint32_t partition_priority;
Mate Toth-Pal349714a2018-02-23 15:30:24 +010046 sp_init_function partition_init;
Miklos Balint386b8b52017-11-29 13:12:32 +000047};
Mate Toth-Pal18b83922018-02-26 17:58:18 +010048
Mate Toth-Pale1475332018-04-09 17:28:49 +020049/**
50 * Holds the fields that define a partition for SPM. The fields are further
51 * divided to structures, to keep the related fields close to each other.
52 */
Mate Toth-Pal936c33b2018-04-10 14:02:07 +020053struct spm_partition_desc_t {
Mate Toth-Pal18b83922018-02-26 17:58:18 +010054 struct spm_partition_static_data_t static_data;
55 struct spm_partition_runtime_data_t runtime_data;
Mate Toth-Pal936c33b2018-04-10 14:02:07 +020056 struct tfm_spm_partition_platform_data_t *platform_data;
Miklos Balintdd02bb32019-05-26 21:13:12 +020057#if (TFM_LVL != 1) || defined(TFM_PSA_API)
Mate Toth-Pal936c33b2018-04-10 14:02:07 +020058 struct tfm_spm_partition_memory_data_t memory_data;
Miklos Balintdd02bb32019-05-26 21:13:12 +020059#endif
Edison Ai764d41f2018-09-21 15:56:36 +080060#ifdef TFM_PSA_API
61 struct tfm_thrd_ctx sp_thrd;
Edison Ai788bae22019-02-18 17:38:59 +080062#endif
Mate Toth-Pal18b83922018-02-26 17:58:18 +010063};
Miklos Balint386b8b52017-11-29 13:12:32 +000064
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020065struct spm_partition_db_t {
66 uint32_t is_init;
67 uint32_t partition_count;
Edison Ai66fbdf12019-07-08 16:05:07 +080068#ifndef TFM_PSA_API
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020069 uint32_t running_partition_idx;
Edison Ai66fbdf12019-07-08 16:05:07 +080070#endif /* !defined(TFM_PSA_API) */
Mate Toth-Pal3ad2e3e2019-07-11 21:43:37 +020071 struct spm_partition_desc_t *partitions;
72};
73
Mate Toth-Pal936c33b2018-04-10 14:02:07 +020074/* Macros to pick linker symbols and allow to form the partition data base */
75#define REGION(a, b, c) a##b##c
76#define REGION_NAME(a, b, c) REGION(a, b, c)
Miklos Balintdd02bb32019-05-26 21:13:12 +020077#if (TFM_LVL == 1) && !defined(TFM_PSA_API)
78#define REGION_DECLARE(a, b, c)
79#else
Mate Toth-Pal936c33b2018-04-10 14:02:07 +020080#define REGION_DECLARE(a, b, c) extern uint32_t REGION_NAME(a, b, c)
81#define PART_REGION_ADDR(partition, region) \
82 (uint32_t)&REGION_NAME(Image$$, partition, region)
Miklos Balintdd02bb32019-05-26 21:13:12 +020083#endif
Mate Toth-Pal936c33b2018-04-10 14:02:07 +020084
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010085#endif /* __SPM_DB_H__ */