xref: /rk3399_ARM-atf/plat/nvidia/tegra/soc/t194/plat_trampoline.S (revision 653fc38026d223bd111a57826e169edef36c6486)
1/*
2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <plat/common/common_def.h>
10#include <memctrl_v2.h>
11#include <tegra_def.h>
12
13#define TEGRA194_SMMU_CTX_SIZE		0x490
14
15	.align 4
16	.globl	tegra194_cpu_reset_handler
17
18/* CPU reset handler routine */
19func tegra194_cpu_reset_handler
20	/*
21	 * The TZRAM loses state during System Suspend. We use this
22	 * information to decide if the reset handler is running after a
23	 * System Suspend. Resume from system suspend requires restoring
24	 * the entire state from TZDRAM to TZRAM.
25	 */
26	mov	x0, #BL31_BASE
27	ldr	x0, [x0]
28	cbnz	x0, boot_cpu
29
30	/* resume from system suspend */
31	mov	x0, #BL31_BASE
32	adr	x1, __tegra194_cpu_reset_handler_end
33	adr	x2, __tegra194_cpu_reset_handler_data
34	ldr	x2, [x2, #8]
35
36	/* memcpy16 */
37m_loop16:
38	cmp	x2, #16
39	b.lt	m_loop1
40	ldp	x3, x4, [x1], #16
41	stp	x3, x4, [x0], #16
42	sub	x2, x2, #16
43	b	m_loop16
44	/* copy byte per byte */
45m_loop1:
46	cbz	x2, boot_cpu
47	ldrb	w3, [x1], #1
48	strb	w3, [x0], #1
49	subs	x2, x2, #1
50	b.ne	m_loop1
51
52boot_cpu:
53	adr	x0, __tegra194_cpu_reset_handler_data
54	ldr	x0, [x0]
55	br	x0
56endfunc tegra194_cpu_reset_handler
57
58	/*
59	 * Tegra194 reset data (offset 0x0 - 0x2490)
60	 *
61	 * 0x0000: secure world's entrypoint
62	 * 0x0008: BL31 size (RO + RW)
63	 * 0x0010: SMMU context start
64	 * 0x2490: SMMU context end
65	 */
66
67	.align 4
68	.type	__tegra194_cpu_reset_handler_data, %object
69	.globl	__tegra194_cpu_reset_handler_data
70__tegra194_cpu_reset_handler_data:
71	.quad	tegra_secure_entrypoint
72	.quad	__BL31_END__ - BL31_BASE
73
74	.align 4
75__tegra194_smmu_context:
76	.rept	TEGRA194_SMMU_CTX_SIZE
77	.quad	0
78	.endr
79	.size	__tegra194_cpu_reset_handler_data, \
80		. - __tegra194_cpu_reset_handler_data
81
82	.align 4
83	.globl	__tegra194_cpu_reset_handler_end
84__tegra194_cpu_reset_handler_end:
85
86	.globl tegra194_get_cpu_reset_handler_size
87	.globl tegra194_get_cpu_reset_handler_base
88	.globl tegra194_get_smmu_ctx_offset
89
90/* return size of the CPU reset handler */
91func tegra194_get_cpu_reset_handler_size
92	adr	x0, __tegra194_cpu_reset_handler_end
93	adr	x1, tegra194_cpu_reset_handler
94	sub	x0, x0, x1
95	ret
96endfunc tegra194_get_cpu_reset_handler_size
97
98/* return the start address of the CPU reset handler */
99func tegra194_get_cpu_reset_handler_base
100	adr	x0, tegra194_cpu_reset_handler
101	ret
102endfunc tegra194_get_cpu_reset_handler_base
103
104/* return the size of the SMMU context */
105func tegra194_get_smmu_ctx_offset
106	adr	x0, __tegra194_smmu_context
107	adr	x1, tegra194_cpu_reset_handler
108	sub	x0, x0, x1
109	ret
110endfunc tegra194_get_smmu_ctx_offset
111