blob: 818c24b49e3e996b6438448e62ccccea2443a78f [file] [log] [blame]
Varun Wadekar93bed2a2016-03-18 13:07:33 -07001/*
Varun Wadekarfadd5382019-01-11 14:48:41 -08002 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
Pritesh Raithatha75c94432018-08-03 15:48:15 +05303 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar93bed2a2016-03-18 13:07:33 -07004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar93bed2a2016-03-18 13:07:33 -07006 */
7
8#include <arch.h>
9#include <asm_macros.S>
Varun Wadekarfadd5382019-01-11 14:48:41 -080010#include <common/bl_common.h>
Varun Wadekar93bed2a2016-03-18 13:07:33 -070011#include <memctrl_v2.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <plat/common/common_def.h>
Varun Wadekar93bed2a2016-03-18 13:07:33 -070013#include <tegra_def.h>
14
Varun Wadekar2a7d87e2017-11-10 10:26:57 -080015#define TEGRA186_STATE_SYSTEM_SUSPEND 0x5C7
16#define TEGRA186_STATE_SYSTEM_RESUME 0x600D
Pritesh Raithatha75c94432018-08-03 15:48:15 +053017#define TEGRA186_MC_CTX_SIZE 0x93
Varun Wadekar93bed2a2016-03-18 13:07:33 -070018
Varun Wadekar93bed2a2016-03-18 13:07:33 -070019 .globl tegra186_cpu_reset_handler
20
21/* CPU reset handler routine */
Julius Wernerb4c75e92017-08-01 15:16:36 -070022func tegra186_cpu_reset_handler _align=4
Varun Wadekar2a7d87e2017-11-10 10:26:57 -080023 /* check if we are exiting system suspend state */
24 adr x0, __tegra186_system_suspend_state
25 ldr x1, [x0]
26 mov x2, #TEGRA186_STATE_SYSTEM_SUSPEND
27 lsl x2, x2, #16
28 add x2, x2, #TEGRA186_STATE_SYSTEM_SUSPEND
29 cmp x1, x2
30 bne boot_cpu
31
32 /* set system resume state */
33 mov x1, #TEGRA186_STATE_SYSTEM_RESUME
34 lsl x1, x1, #16
35 mov x2, #TEGRA186_STATE_SYSTEM_RESUME
36 add x1, x1, x2
37 str x1, [x0]
38 dsb sy
Varun Wadekar93bed2a2016-03-18 13:07:33 -070039
Varun Wadekar2a7d87e2017-11-10 10:26:57 -080040 /* prepare to relocate to TZSRAM */
Varun Wadekar93bed2a2016-03-18 13:07:33 -070041 mov x0, #BL31_BASE
42 adr x1, __tegra186_cpu_reset_handler_end
43 adr x2, __tegra186_cpu_reset_handler_data
44 ldr x2, [x2, #8]
45
46 /* memcpy16 */
47m_loop16:
48 cmp x2, #16
49 b.lt m_loop1
50 ldp x3, x4, [x1], #16
51 stp x3, x4, [x0], #16
52 sub x2, x2, #16
53 b m_loop16
54 /* copy byte per byte */
55m_loop1:
56 cbz x2, boot_cpu
57 ldrb w3, [x1], #1
58 strb w3, [x0], #1
59 subs x2, x2, #1
60 b.ne m_loop1
61
62boot_cpu:
63 adr x0, __tegra186_cpu_reset_handler_data
64 ldr x0, [x0]
65 br x0
66endfunc tegra186_cpu_reset_handler
67
68 /*
69 * Tegra186 reset data (offset 0x0 - 0x430)
70 *
71 * 0x000: secure world's entrypoint
72 * 0x008: BL31 size (RO + RW)
Pritesh Raithatha75c94432018-08-03 15:48:15 +053073 * 0x00C: MC context start
74 * 0x42C: MC context end
Varun Wadekar93bed2a2016-03-18 13:07:33 -070075 */
76
77 .align 4
78 .type __tegra186_cpu_reset_handler_data, %object
79 .globl __tegra186_cpu_reset_handler_data
80__tegra186_cpu_reset_handler_data:
81 .quad tegra_secure_entrypoint
82 .quad __BL31_END__ - BL31_BASE
Varun Wadekarfa887672017-11-08 14:45:08 -080083
Varun Wadekar2a7d87e2017-11-10 10:26:57 -080084 .globl __tegra186_system_suspend_state
85__tegra186_system_suspend_state:
86 .quad 0
87
Varun Wadekarfa887672017-11-08 14:45:08 -080088 .align 4
Pritesh Raithatha75c94432018-08-03 15:48:15 +053089 .globl __tegra186_mc_context
90__tegra186_mc_context:
91 .rept TEGRA186_MC_CTX_SIZE
Varun Wadekar93bed2a2016-03-18 13:07:33 -070092 .quad 0
93 .endr
94 .size __tegra186_cpu_reset_handler_data, \
95 . - __tegra186_cpu_reset_handler_data
96
97 .align 4
98 .globl __tegra186_cpu_reset_handler_end
99__tegra186_cpu_reset_handler_end:
Varun Wadekar8304fc82017-10-25 11:52:07 -0700100
101 .globl tegra186_get_cpu_reset_handler_size
102 .globl tegra186_get_cpu_reset_handler_base
Pritesh Raithatha75c94432018-08-03 15:48:15 +0530103 .globl tegra186_get_mc_ctx_offset
Varun Wadekar2a7d87e2017-11-10 10:26:57 -0800104 .globl tegra186_set_system_suspend_entry
Varun Wadekar8304fc82017-10-25 11:52:07 -0700105
106/* return size of the CPU reset handler */
107func tegra186_get_cpu_reset_handler_size
108 adr x0, __tegra186_cpu_reset_handler_end
109 adr x1, tegra186_cpu_reset_handler
110 sub x0, x0, x1
111 ret
112endfunc tegra186_get_cpu_reset_handler_size
113
114/* return the start address of the CPU reset handler */
115func tegra186_get_cpu_reset_handler_base
116 adr x0, tegra186_cpu_reset_handler
117 ret
118endfunc tegra186_get_cpu_reset_handler_base
Varun Wadekarfa887672017-11-08 14:45:08 -0800119
Pritesh Raithatha75c94432018-08-03 15:48:15 +0530120/* return the size of the MC context */
121func tegra186_get_mc_ctx_offset
122 adr x0, __tegra186_mc_context
Varun Wadekarfa887672017-11-08 14:45:08 -0800123 adr x1, tegra186_cpu_reset_handler
124 sub x0, x0, x1
125 ret
Pritesh Raithatha75c94432018-08-03 15:48:15 +0530126endfunc tegra186_get_mc_ctx_offset
Varun Wadekar2a7d87e2017-11-10 10:26:57 -0800127
128/* set system suspend state before SC7 entry */
129func tegra186_set_system_suspend_entry
130 mov x0, #TEGRA_MC_BASE
131 mov x3, #MC_SECURITY_CFG3_0
132 ldr w1, [x0, x3]
133 lsl x1, x1, #32
134 mov x3, #MC_SECURITY_CFG0_0
135 ldr w2, [x0, x3]
136 orr x3, x1, x2 /* TZDRAM base */
137 adr x0, __tegra186_system_suspend_state
138 adr x1, tegra186_cpu_reset_handler
139 sub x2, x0, x1 /* offset in TZDRAM */
140 mov x0, #TEGRA186_STATE_SYSTEM_SUSPEND
141 lsl x0, x0, #16
142 add x0, x0, #TEGRA186_STATE_SYSTEM_SUSPEND
143 str x0, [x3, x2] /* set value in TZDRAM */
144 dsb sy
145 ret
146endfunc tegra186_set_system_suspend_entry