Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef SPM_PRIVATE_H |
| 8 | #define SPM_PRIVATE_H |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 9 | |
| 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 Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 32 | #ifndef __ASSEMBLY__ |
| 33 | |
Antonio Nino Diaz | 496f54d | 2018-01-08 09:59:33 +0000 | [diff] [blame] | 34 | #include <spinlock.h> |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 35 | #include <sp_res_desc.h> |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 36 | #include <stdint.h> |
| 37 | #include <xlat_tables_v2.h> |
| 38 | |
Antonio Nino Diaz | da50cd0 | 2018-06-15 16:21:01 +0100 | [diff] [blame] | 39 | typedef enum sp_state { |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 40 | SP_STATE_RESET = 0, |
| 41 | SP_STATE_IDLE, |
| 42 | SP_STATE_BUSY |
| 43 | } sp_state_t; |
| 44 | |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 45 | typedef struct sp_context { |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 46 | /* Location of the image in physical memory */ |
| 47 | unsigned long long image_base; |
| 48 | size_t image_size; |
| 49 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 50 | uint64_t c_rt_ctx; |
| 51 | cpu_context_t cpu_ctx; |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 52 | xlat_ctx_t *xlat_ctx_handle; |
Antonio Nino Diaz | 840627f | 2018-11-27 08:36:02 +0000 | [diff] [blame] | 53 | struct sp_res_desc rd; |
Antonio Nino Diaz | c4f2752 | 2018-05-23 09:09:41 +0100 | [diff] [blame] | 54 | |
| 55 | sp_state_t state; |
| 56 | spinlock_t state_lock; |
Antonio Nino Diaz | bb7d1cd | 2018-10-30 11:34:23 +0000 | [diff] [blame] | 57 | |
| 58 | /* Base and size of the shared SPM<->SP buffer */ |
| 59 | uintptr_t spm_sp_buffer_base; |
| 60 | size_t spm_sp_buffer_size; |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 61 | } sp_context_t; |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 62 | |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 63 | /* Assembly helpers */ |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 64 | uint64_t spm_secure_partition_enter(uint64_t *c_rt_ctx); |
| 65 | void __dead2 spm_secure_partition_exit(uint64_t c_rt_ctx, uint64_t ret); |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 66 | |
Antonio Nino Diaz | bb7d1cd | 2018-10-30 11:34:23 +0000 | [diff] [blame] | 67 | /* Secure Partition setup */ |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 68 | void spm_sp_setup(sp_context_t *sp_ctx); |
Antonio Nino Diaz | 2ac9a44 | 2018-05-23 11:40:46 +0100 | [diff] [blame] | 69 | |
Antonio Nino Diaz | bb7d1cd | 2018-10-30 11:34:23 +0000 | [diff] [blame] | 70 | /* Functions related to the translation tables management */ |
Antonio Nino Diaz | 7b28b54 | 2018-05-22 16:45:35 +0100 | [diff] [blame] | 71 | xlat_ctx_t *spm_get_sp_xlat_context(void); |
Antonio Nino Diaz | bb7d1cd | 2018-10-30 11:34:23 +0000 | [diff] [blame] | 72 | void sp_map_memory_regions(sp_context_t *sp_ctx); |
Antonio Nino Diaz | 7b28b54 | 2018-05-22 16:45:35 +0100 | [diff] [blame] | 73 | |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 74 | int32_t spm_memory_attributes_get_smc_handler(sp_context_t *sp_ctx, |
Antonio Nino Diaz | 7b28b54 | 2018-05-22 16:45:35 +0100 | [diff] [blame] | 75 | uintptr_t base_va); |
Antonio Nino Diaz | 2875931 | 2018-05-22 16:26:48 +0100 | [diff] [blame] | 76 | int spm_memory_attributes_set_smc_handler(sp_context_t *sp_ctx, |
Antonio Nino Diaz | 7b28b54 | 2018-05-22 16:45:35 +0100 | [diff] [blame] | 77 | u_register_t page_address, |
| 78 | u_register_t pages_count, |
| 79 | u_register_t smc_attributes); |
| 80 | |
Antonio Nino Diaz | c41f206 | 2017-10-24 10:07:35 +0100 | [diff] [blame] | 81 | #endif /* __ASSEMBLY__ */ |
| 82 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 83 | #endif /* SPM_PRIVATE_H */ |