Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019-2020, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SPMD_PRIVATE_H |
| 8 | #define SPMD_PRIVATE_H |
| 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 SPMD_C_RT_CTX_X19 0x0 |
| 17 | #define SPMD_C_RT_CTX_X20 0x8 |
| 18 | #define SPMD_C_RT_CTX_X21 0x10 |
| 19 | #define SPMD_C_RT_CTX_X22 0x18 |
| 20 | #define SPMD_C_RT_CTX_X23 0x20 |
| 21 | #define SPMD_C_RT_CTX_X24 0x28 |
| 22 | #define SPMD_C_RT_CTX_X25 0x30 |
| 23 | #define SPMD_C_RT_CTX_X26 0x38 |
| 24 | #define SPMD_C_RT_CTX_X27 0x40 |
| 25 | #define SPMD_C_RT_CTX_X28 0x48 |
| 26 | #define SPMD_C_RT_CTX_X29 0x50 |
| 27 | #define SPMD_C_RT_CTX_X30 0x58 |
| 28 | |
| 29 | #define SPMD_C_RT_CTX_SIZE 0x60 |
| 30 | #define SPMD_C_RT_CTX_ENTRIES (SPMD_C_RT_CTX_SIZE >> DWORD_SHIFT) |
| 31 | |
| 32 | #ifndef __ASSEMBLER__ |
| 33 | #include <services/spci_svc.h> |
| 34 | #include <stdint.h> |
| 35 | |
| 36 | /* |
| 37 | * Convert a function no. in a FID to a bit position. All function nos. are |
| 38 | * between 0 and 0x1f |
| 39 | */ |
| 40 | #define SPCI_FNO_TO_BIT_POS(_fid) (1 << ((_fid) & U(0x1f))) |
| 41 | |
| 42 | typedef enum spmc_state { |
| 43 | SPMC_STATE_RESET = 0, |
| 44 | SPMC_STATE_IDLE |
| 45 | } spmc_state_t; |
| 46 | |
| 47 | /* |
| 48 | * Data structure used by the SPM dispatcher (SPMD) in EL3 to track context of |
| 49 | * the SPM core (SPMC) at the next lower EL. |
| 50 | */ |
| 51 | typedef struct spmd_spm_core_context { |
| 52 | uint64_t c_rt_ctx; |
| 53 | cpu_context_t cpu_ctx; |
| 54 | spmc_state_t state; |
| 55 | } spmd_spm_core_context_t; |
| 56 | |
| 57 | /* |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 58 | * Reserve ID for NS physical SPCI Endpoint. |
| 59 | */ |
| 60 | #define SPCI_NS_ENDPOINT_ID U(0) |
| 61 | |
| 62 | /* Mask and shift to check valid secure SPCI Endpoint ID. */ |
| 63 | #define SPMC_SECURE_ID_MASK 0x1 |
| 64 | #define SPMC_SECURE_ID_SHIFT 15 |
| 65 | |
| 66 | /* |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 67 | * Data structure used by the SPM dispatcher (SPMD) in EL3 to track sequence of |
| 68 | * SPCI calls from lower ELs. |
| 69 | * |
| 70 | * next_smc_bit_map: Per-cpu bit map of SMCs from each world that are expected |
| 71 | * next. |
| 72 | */ |
| 73 | typedef struct spmd_spci_context { |
| 74 | uint32_t next_smc_bit_map[2]; |
| 75 | } spmd_spci_context_t; |
| 76 | |
| 77 | /* Functions used to enter/exit a Secure Partition synchronously */ |
| 78 | uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *ctx); |
| 79 | __dead2 void spmd_spm_core_sync_exit(uint64_t rc); |
| 80 | |
| 81 | /* Assembly helpers */ |
| 82 | uint64_t spmd_spm_core_enter(uint64_t *c_rt_ctx); |
| 83 | void __dead2 spmd_spm_core_exit(uint64_t c_rt_ctx, uint64_t ret); |
| 84 | |
| 85 | #endif /* __ASSEMBLER__ */ |
| 86 | |
| 87 | #endif /* SPMD_PRIVATE_H */ |