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