blob: ad36f5e4b82064f99d3ee9c5f6cdb4b6e7869c46 [file] [log] [blame]
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05301/*
David Cunadoc8833ea2017-04-16 17:15:08 +01002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05303 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05305 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef TLKD_PRIVATE_H
8#define TLKD_PRIVATE_H
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05309
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <platform_def.h>
11
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053012#include <arch.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <bl31/interrupt_mgmt.h>
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053014#include <context.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <lib/psci/psci.h>
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053016
17/*
David Cunadoc8833ea2017-04-16 17:15:08 +010018 * This flag is used by the TLKD to determine if the SP is servicing a yielding
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053019 * SMC request prior to programming the next entry into the SP e.g. if SP
20 * execution is preempted by a non-secure interrupt and handed control to the
21 * normal world. If another request which is distinct from what the SP was
22 * previously doing arrives, then this flag will be help the TLKD to either
23 * reject the new request or service it while ensuring that the previous context
24 * is not corrupted.
25 */
David Cunadoc8833ea2017-04-16 17:15:08 +010026#define YIELD_SMC_ACTIVE_FLAG_SHIFT 2
27#define YIELD_SMC_ACTIVE_FLAG_MASK 1
28#define get_yield_smc_active_flag(state) \
29 (((state) >> YIELD_SMC_ACTIVE_FLAG_SHIFT) \
30 & YIELD_SMC_ACTIVE_FLAG_MASK)
31#define set_yield_smc_active_flag(state) ((state) |= \
32 (1 << YIELD_SMC_ACTIVE_FLAG_SHIFT))
33#define clr_yield_smc_active_flag(state) ((state) &= \
34 ~(YIELD_SMC_ACTIVE_FLAG_MASK \
35 << YIELD_SMC_ACTIVE_FLAG_SHIFT))
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053036
37/*******************************************************************************
Varun Wadekar97625e32015-03-13 14:59:03 +053038 * Translate virtual address received from the NS world
39 ******************************************************************************/
40#define TLK_TRANSLATE_NS_VADDR 4
41
42/*******************************************************************************
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053043 * Secure Payload execution state information i.e. aarch32 or aarch64
44 ******************************************************************************/
45#define SP_AARCH32 MODE_RW_32
46#define SP_AARCH64 MODE_RW_64
47
48/*******************************************************************************
49 * Number of cpus that the present on this platform. TODO: Rely on a topology
50 * tree to determine this in the future to avoid assumptions about mpidr
51 * allocation
52 ******************************************************************************/
53#define TLKD_CORE_COUNT PLATFORM_CORE_COUNT
54
55/*******************************************************************************
56 * Constants that allow assembler code to preserve callee-saved registers of the
57 * C runtime context while performing a security state switch.
58 ******************************************************************************/
59#define TLKD_C_RT_CTX_X19 0x0
60#define TLKD_C_RT_CTX_X20 0x8
61#define TLKD_C_RT_CTX_X21 0x10
62#define TLKD_C_RT_CTX_X22 0x18
63#define TLKD_C_RT_CTX_X23 0x20
64#define TLKD_C_RT_CTX_X24 0x28
65#define TLKD_C_RT_CTX_X25 0x30
66#define TLKD_C_RT_CTX_X26 0x38
67#define TLKD_C_RT_CTX_X27 0x40
68#define TLKD_C_RT_CTX_X28 0x48
69#define TLKD_C_RT_CTX_X29 0x50
70#define TLKD_C_RT_CTX_X30 0x58
71#define TLKD_C_RT_CTX_SIZE 0x60
72#define TLKD_C_RT_CTX_ENTRIES (TLKD_C_RT_CTX_SIZE >> DWORD_SHIFT)
73
Julius Werner53456fc2019-07-09 13:49:11 -070074#ifndef __ASSEMBLER__
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053075
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053076#include <stdint.h>
77
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000078#include <lib/cassert.h>
79
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053080/* AArch64 callee saved general purpose register context structure. */
81DEFINE_REG_STRUCT(c_rt_regs, TLKD_C_RT_CTX_ENTRIES);
82
83/*
84 * Compile time assertion to ensure that both the compiler and linker
85 * have the same double word aligned view of the size of the C runtime
86 * register context.
87 */
Elyes Haouas183638f2023-02-13 10:05:41 +010088CASSERT(TLKD_C_RT_CTX_SIZE == sizeof(c_rt_regs_t),
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053089 assert_tlkd_c_rt_regs_size_mismatch);
90
91/*******************************************************************************
92 * Structure which helps the SPD to maintain the per-cpu state of the SP.
93 * 'state' - collection of flags to track SP state e.g. on/off
94 * 'mpidr' - mpidr to associate a context with a cpu
95 * 'c_rt_ctx' - stack address to restore C runtime context from after
96 * returning from a synchronous entry into the SP.
97 * 'cpu_ctx' - space to maintain SP architectural state
98 * 'saved_tsp_args' - space to store arguments for TSP arithmetic operations
99 * which will queried using the TSP_GET_ARGS SMC by TSP.
100 ******************************************************************************/
101typedef struct tlk_context {
102 uint32_t state;
103 uint64_t mpidr;
104 uint64_t c_rt_ctx;
105 cpu_context_t cpu_ctx;
106} tlk_context_t;
107
108/*******************************************************************************
109 * Function & Data prototypes
110 ******************************************************************************/
Varun Wadekar97625e32015-03-13 14:59:03 +0530111uint64_t tlkd_va_translate(uintptr_t va, int type);
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530112uint64_t tlkd_enter_sp(uint64_t *c_rt_ctx);
113void __dead2 tlkd_exit_sp(uint64_t c_rt_ctx, uint64_t ret);
114uint64_t tlkd_synchronous_sp_entry(tlk_context_t *tlk_ctx);
115void __dead2 tlkd_synchronous_sp_exit(tlk_context_t *tlk_ctx,
116 uint64_t ret);
117void tlkd_init_tlk_ep_state(struct entry_point_info *tlk_entry_point,
118 uint32_t rw,
119 uint64_t pc,
120 tlk_context_t *tlk_ctx);
121
Julius Werner53456fc2019-07-09 13:49:11 -0700122#endif /*__ASSEMBLER__*/
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530123
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000124#endif /* TLKD_PRIVATE_H */