plat_trampoline.S 3.52 KB
Newer Older
1
/*
2
 * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3
4
5
6
7
8
9
10
11
12
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <asm_macros.S>
#include <plat/common/common_def.h>
#include <memctrl_v2.h>
#include <tegra_def.h>

13
14
#define TEGRA194_STATE_SYSTEM_SUSPEND	0x5C7
#define TEGRA194_STATE_SYSTEM_RESUME	0x600D
15
#define TEGRA194_MC_CTX_SIZE		0xFB
16
17

	.align 4
18
	.globl	tegra194_cpu_reset_handler
19
20

/* CPU reset handler routine */
21
func tegra194_cpu_reset_handler
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
	/* check if we are exiting system suspend state */
	adr	x0, __tegra194_system_suspend_state
	ldr	x1, [x0]
	mov	x2, #TEGRA194_STATE_SYSTEM_SUSPEND
	lsl	x2, x2, #16
	add	x2, x2, #TEGRA194_STATE_SYSTEM_SUSPEND
	cmp	x1, x2
	bne	boot_cpu

	/* set system resume state */
	mov	x1, #TEGRA194_STATE_SYSTEM_RESUME
	lsl	x1, x1, #16
	mov	x2, #TEGRA194_STATE_SYSTEM_RESUME
	add	x1, x1, x2
	str	x1, [x0]
	dsb	sy
38

39
	/* prepare to relocate to TZSRAM */
40
	mov	x0, #BL31_BASE
41
42
	adr	x1, __tegra194_cpu_reset_handler_end
	adr	x2, __tegra194_cpu_reset_handler_data
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	ldr	x2, [x2, #8]

	/* memcpy16 */
m_loop16:
	cmp	x2, #16
	b.lt	m_loop1
	ldp	x3, x4, [x1], #16
	stp	x3, x4, [x0], #16
	sub	x2, x2, #16
	b	m_loop16
	/* copy byte per byte */
m_loop1:
	cbz	x2, boot_cpu
	ldrb	w3, [x1], #1
	strb	w3, [x0], #1
	subs	x2, x2, #1
	b.ne	m_loop1

61
62
63
64
65
66
67
	/*
	 * Synchronization barriers to make sure that memory is flushed out
	 * before we start execution in SysRAM.
	 */
	dsb	sy
	isb

68
boot_cpu:
69
	adr	x0, __tegra194_cpu_reset_handler_data
70
71
	ldr	x0, [x0]
	br	x0
72
endfunc tegra194_cpu_reset_handler
73
74

	/*
75
	 * Tegra194 reset data (offset 0x0 - 0x2490)
76
	 *
77
78
	 * 0x0000: secure world's entrypoint
	 * 0x0008: BL31 size (RO + RW)
79
80
	 * 0x0010: MC context start
	 * 0x2490: MC context end
81
82
83
	 */

	.align 4
84
85
86
	.type	__tegra194_cpu_reset_handler_data, %object
	.globl	__tegra194_cpu_reset_handler_data
__tegra194_cpu_reset_handler_data:
87
88
	.quad	tegra_secure_entrypoint
	.quad	__BL31_END__ - BL31_BASE
89
90
91
92
	.globl	__tegra194_system_suspend_state
__tegra194_system_suspend_state:
	.quad	0

93
	.align 4
94
95
__tegra194_mc_context:
	.rept	TEGRA194_MC_CTX_SIZE
96
97
	.quad	0
	.endr
98
99
	.size	__tegra194_cpu_reset_handler_data, \
		. - __tegra194_cpu_reset_handler_data
100
101

	.align 4
102
103
	.globl	__tegra194_cpu_reset_handler_end
__tegra194_cpu_reset_handler_end:
104
105
106

	.globl tegra194_get_cpu_reset_handler_size
	.globl tegra194_get_cpu_reset_handler_base
107
	.globl tegra194_get_mc_ctx_offset
108
	.globl tegra194_set_system_suspend_entry
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

/* return size of the CPU reset handler */
func tegra194_get_cpu_reset_handler_size
	adr	x0, __tegra194_cpu_reset_handler_end
	adr	x1, tegra194_cpu_reset_handler
	sub	x0, x0, x1
	ret
endfunc tegra194_get_cpu_reset_handler_size

/* return the start address of the CPU reset handler */
func tegra194_get_cpu_reset_handler_base
	adr	x0, tegra194_cpu_reset_handler
	ret
endfunc tegra194_get_cpu_reset_handler_base

124
125
126
/* return the size of the MC context */
func tegra194_get_mc_ctx_offset
	adr	x0, __tegra194_mc_context
127
128
129
	adr	x1, tegra194_cpu_reset_handler
	sub	x0, x0, x1
	ret
130
endfunc tegra194_get_mc_ctx_offset
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

/* set system suspend state before SC7 entry */
func tegra194_set_system_suspend_entry
	mov	x0, #TEGRA_MC_BASE
	mov	x3, #MC_SECURITY_CFG3_0
	ldr	w1, [x0, x3]
	lsl	x1, x1, #32
	mov	x3, #MC_SECURITY_CFG0_0
	ldr	w2, [x0, x3]
	orr	x3, x1, x2			/* TZDRAM base */
	adr	x0, __tegra194_system_suspend_state
	adr	x1, tegra194_cpu_reset_handler
	sub	x2, x0, x1			/* offset in TZDRAM */
	mov	x0, #TEGRA194_STATE_SYSTEM_SUSPEND
	lsl	x0, x0, #16
	add	x0, x0, #TEGRA194_STATE_SYSTEM_SUSPEND
	str	x0, [x3, x2]			/* set value in TZDRAM */
	dsb	sy
	ret
endfunc tegra194_set_system_suspend_entry