blob: a8234c36f08ee6b7a84e34d417f2c12de4bd3ff2 [file] [log] [blame]
Antonio Nino Diazc41f2062017-10-24 10:07:35 +01001/*
Antonio Nino Diaz2ac9a442018-05-23 11:40:46 +01002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diazc41f2062017-10-24 10:07:35 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef SPM_PRIVATE_H
8#define SPM_PRIVATE_H
Antonio Nino Diazc41f2062017-10-24 10:07:35 +01009
10#include <context.h>
11
12/*******************************************************************************
13 * Constants that allow assembler code to preserve callee-saved registers of the
14 * C runtime context while performing a security state switch.
15 ******************************************************************************/
16#define SP_C_RT_CTX_X19 0x0
17#define SP_C_RT_CTX_X20 0x8
18#define SP_C_RT_CTX_X21 0x10
19#define SP_C_RT_CTX_X22 0x18
20#define SP_C_RT_CTX_X23 0x20
21#define SP_C_RT_CTX_X24 0x28
22#define SP_C_RT_CTX_X25 0x30
23#define SP_C_RT_CTX_X26 0x38
24#define SP_C_RT_CTX_X27 0x40
25#define SP_C_RT_CTX_X28 0x48
26#define SP_C_RT_CTX_X29 0x50
27#define SP_C_RT_CTX_X30 0x58
28
29#define SP_C_RT_CTX_SIZE 0x60
30#define SP_C_RT_CTX_ENTRIES (SP_C_RT_CTX_SIZE >> DWORD_SHIFT)
31
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010032#ifndef __ASSEMBLY__
33
Antonio Nino Diaz496f54d2018-01-08 09:59:33 +000034#include <spinlock.h>
Antonio Nino Diaz840627f2018-11-27 08:36:02 +000035#include <sp_res_desc.h>
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010036#include <stdint.h>
37#include <xlat_tables_v2.h>
38
Antonio Nino Diazda50cd02018-06-15 16:21:01 +010039typedef enum sp_state {
Antonio Nino Diazc4f27522018-05-23 09:09:41 +010040 SP_STATE_RESET = 0,
41 SP_STATE_IDLE,
42 SP_STATE_BUSY
43} sp_state_t;
44
Antonio Nino Diaz28759312018-05-22 16:26:48 +010045typedef struct sp_context {
Antonio Nino Diaz8cc23f92018-10-30 11:35:30 +000046 /* 1 if the partition is present, 0 otherwise */
47 int is_present;
48
Antonio Nino Diaz840627f2018-11-27 08:36:02 +000049 /* Location of the image in physical memory */
50 unsigned long long image_base;
51 size_t image_size;
52
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010053 uint64_t c_rt_ctx;
54 cpu_context_t cpu_ctx;
Antonio Nino Diaz2ac9a442018-05-23 11:40:46 +010055 xlat_ctx_t *xlat_ctx_handle;
Antonio Nino Diaz840627f2018-11-27 08:36:02 +000056 struct sp_res_desc rd;
Antonio Nino Diazc4f27522018-05-23 09:09:41 +010057
58 sp_state_t state;
59 spinlock_t state_lock;
Antonio Nino Diazbb7d1cd2018-10-30 11:34:23 +000060
61 /* Base and size of the shared SPM<->SP buffer */
62 uintptr_t spm_sp_buffer_base;
63 size_t spm_sp_buffer_size;
Antonio Nino Diaz8c83ad82018-11-08 14:21:19 +000064 spinlock_t spm_sp_buffer_lock;
Antonio Nino Diaz28759312018-05-22 16:26:48 +010065} sp_context_t;
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010066
Antonio Nino Diaz8c83ad82018-11-08 14:21:19 +000067/* Functions used to enter/exit a Secure Partition synchronously */
68uint64_t spm_sp_synchronous_entry(sp_context_t *sp_ctx);
69__dead2 void spm_sp_synchronous_exit(uint64_t rc);
70
Antonio Nino Diaz2ac9a442018-05-23 11:40:46 +010071/* Assembly helpers */
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010072uint64_t spm_secure_partition_enter(uint64_t *c_rt_ctx);
73void __dead2 spm_secure_partition_exit(uint64_t c_rt_ctx, uint64_t ret);
Antonio Nino Diaz2ac9a442018-05-23 11:40:46 +010074
Antonio Nino Diazbb7d1cd2018-10-30 11:34:23 +000075/* Secure Partition setup */
Antonio Nino Diaz28759312018-05-22 16:26:48 +010076void spm_sp_setup(sp_context_t *sp_ctx);
Antonio Nino Diaz2ac9a442018-05-23 11:40:46 +010077
Antonio Nino Diaz8c83ad82018-11-08 14:21:19 +000078/* Secure Partition state management helpers */
79void sp_state_set(sp_context_t *sp_ptr, sp_state_t state);
80void sp_state_wait_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to);
81int sp_state_try_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to);
82
Antonio Nino Diazbb7d1cd2018-10-30 11:34:23 +000083/* Functions related to the translation tables management */
Antonio Nino Diaz8cc23f92018-10-30 11:35:30 +000084xlat_ctx_t *spm_sp_xlat_context_alloc(void);
Antonio Nino Diazbb7d1cd2018-10-30 11:34:23 +000085void sp_map_memory_regions(sp_context_t *sp_ctx);
Antonio Nino Diaz7b28b542018-05-22 16:45:35 +010086
Antonio Nino Diaz28759312018-05-22 16:26:48 +010087int32_t spm_memory_attributes_get_smc_handler(sp_context_t *sp_ctx,
Antonio Nino Diaz7b28b542018-05-22 16:45:35 +010088 uintptr_t base_va);
Antonio Nino Diaz28759312018-05-22 16:26:48 +010089int spm_memory_attributes_set_smc_handler(sp_context_t *sp_ctx,
Antonio Nino Diaz7b28b542018-05-22 16:45:35 +010090 u_register_t page_address,
91 u_register_t pages_count,
92 u_register_t smc_attributes);
93
Antonio Nino Diaz8cc23f92018-10-30 11:35:30 +000094/* Functions to handle Secure Partition contexts */
95void spm_cpu_set_sp_ctx(unsigned int linear_id, sp_context_t *sp_ctx);
96sp_context_t *spm_cpu_get_sp_ctx(unsigned int linear_id);
Antonio Nino Diazb5b585a2018-11-08 14:20:07 +000097sp_context_t *spm_sp_get_by_uuid(const uint32_t (*svc_uuid)[4]);
Antonio Nino Diaz8cc23f92018-10-30 11:35:30 +000098
Antonio Nino Diazc41f2062017-10-24 10:07:35 +010099#endif /* __ASSEMBLY__ */
100
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000101#endif /* SPM_PRIVATE_H */