tlkd_private.h 4.79 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
8
#ifndef TLKD_PRIVATE_H
#define TLKD_PRIVATE_H
9
10
11
12
13
14
15
16

#include <arch.h>
#include <context.h>
#include <interrupt_mgmt.h>
#include <platform_def.h>
#include <psci.h>

/*
17
 * This flag is used by the TLKD to determine if the SP is servicing a yielding
18
19
20
21
22
23
24
 * SMC request prior to programming the next entry into the SP e.g. if SP
 * execution is preempted by a non-secure interrupt and handed control to the
 * normal world. If another request which is distinct from what the SP was
 * previously doing arrives, then this flag will be help the TLKD to either
 * reject the new request or service it while ensuring that the previous context
 * is not corrupted.
 */
25
26
27
28
29
30
31
32
33
34
#define YIELD_SMC_ACTIVE_FLAG_SHIFT	2
#define YIELD_SMC_ACTIVE_FLAG_MASK	1
#define get_yield_smc_active_flag(state)				\
			(((state) >> YIELD_SMC_ACTIVE_FLAG_SHIFT)	\
			& YIELD_SMC_ACTIVE_FLAG_MASK)
#define set_yield_smc_active_flag(state)	((state) |=		\
					 (1 << YIELD_SMC_ACTIVE_FLAG_SHIFT))
#define clr_yield_smc_active_flag(state)	((state) &=		\
					 ~(YIELD_SMC_ACTIVE_FLAG_MASK	\
					 << YIELD_SMC_ACTIVE_FLAG_SHIFT))
35

36
37
38
39
40
/*******************************************************************************
 * Translate virtual address received from the NS world
 ******************************************************************************/
#define TLK_TRANSLATE_NS_VADDR		4

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Secure Payload execution state information i.e. aarch32 or aarch64
 ******************************************************************************/
#define SP_AARCH32		MODE_RW_32
#define SP_AARCH64		MODE_RW_64

/*******************************************************************************
 * Number of cpus that the present on this platform. TODO: Rely on a topology
 * tree to determine this in the future to avoid assumptions about mpidr
 * allocation
 ******************************************************************************/
#define TLKD_CORE_COUNT		PLATFORM_CORE_COUNT

/*******************************************************************************
 * Constants that allow assembler code to preserve callee-saved registers of the
 * C runtime context while performing a security state switch.
 ******************************************************************************/
#define TLKD_C_RT_CTX_X19		0x0
#define TLKD_C_RT_CTX_X20		0x8
#define TLKD_C_RT_CTX_X21		0x10
#define TLKD_C_RT_CTX_X22		0x18
#define TLKD_C_RT_CTX_X23		0x20
#define TLKD_C_RT_CTX_X24		0x28
#define TLKD_C_RT_CTX_X25		0x30
#define TLKD_C_RT_CTX_X26		0x38
#define TLKD_C_RT_CTX_X27		0x40
#define TLKD_C_RT_CTX_X28		0x48
#define TLKD_C_RT_CTX_X29		0x50
#define TLKD_C_RT_CTX_X30		0x58
#define TLKD_C_RT_CTX_SIZE		0x60
#define TLKD_C_RT_CTX_ENTRIES		(TLKD_C_RT_CTX_SIZE >> DWORD_SHIFT)

#ifndef __ASSEMBLY__

#include <cassert.h>
#include <stdint.h>

/* AArch64 callee saved general purpose register context structure. */
DEFINE_REG_STRUCT(c_rt_regs, TLKD_C_RT_CTX_ENTRIES);

/*
 * Compile time assertion to ensure that both the compiler and linker
 * have the same double word aligned view of the size of the C runtime
 * register context.
 */
CASSERT(TLKD_C_RT_CTX_SIZE == sizeof(c_rt_regs_t),	\
	assert_tlkd_c_rt_regs_size_mismatch);

/*******************************************************************************
 * Structure which helps the SPD to maintain the per-cpu state of the SP.
 * 'state'          - collection of flags to track SP state e.g. on/off
 * 'mpidr'          - mpidr to associate a context with a cpu
 * 'c_rt_ctx'       - stack address to restore C runtime context from after
 *                    returning from a synchronous entry into the SP.
 * 'cpu_ctx'        - space to maintain SP architectural state
 * 'saved_tsp_args' - space to store arguments for TSP arithmetic operations
 *                    which will queried using the TSP_GET_ARGS SMC by TSP.
 ******************************************************************************/
typedef struct tlk_context {
	uint32_t state;
	uint64_t mpidr;
	uint64_t c_rt_ctx;
	cpu_context_t cpu_ctx;
} tlk_context_t;

/*******************************************************************************
 * Function & Data prototypes
 ******************************************************************************/
109
uint64_t tlkd_va_translate(uintptr_t va, int type);
110
111
112
113
114
115
116
117
118
119
120
121
uint64_t tlkd_enter_sp(uint64_t *c_rt_ctx);
void __dead2 tlkd_exit_sp(uint64_t c_rt_ctx, uint64_t ret);
uint64_t tlkd_synchronous_sp_entry(tlk_context_t *tlk_ctx);
void __dead2 tlkd_synchronous_sp_exit(tlk_context_t *tlk_ctx,
			uint64_t ret);
void tlkd_init_tlk_ep_state(struct entry_point_info *tlk_entry_point,
				uint32_t rw,
				uint64_t pc,
				tlk_context_t *tlk_ctx);

#endif /*__ASSEMBLY__*/

122
#endif /* TLKD_PRIVATE_H */