blob: d609a144bb7b53db895db022f13c932f0d86314c [file] [log] [blame]
Varun Wadekar93bed2a2016-03-18 13:07:33 -07001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar93bed2a2016-03-18 13:07:33 -07005 */
6
7#include <arch.h>
8#include <asm_macros.S>
Varun Wadekar93bed2a2016-03-18 13:07:33 -07009#include <memctrl_v2.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <plat/common/common_def.h>
Varun Wadekar93bed2a2016-03-18 13:07:33 -070011#include <tegra_def.h>
12
13#define TEGRA186_SMMU_CTX_SIZE 0x420
14
Varun Wadekar93bed2a2016-03-18 13:07:33 -070015 .globl tegra186_cpu_reset_handler
16
17/* CPU reset handler routine */
Julius Wernerb4c75e92017-08-01 15:16:36 -070018func tegra186_cpu_reset_handler _align=4
Varun Wadekar93bed2a2016-03-18 13:07:33 -070019 /*
Varun Wadekar0a6eba32016-08-08 11:53:14 -070020 * 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.
Varun Wadekar93bed2a2016-03-18 13:07:33 -070024 */
Varun Wadekar0a6eba32016-08-08 11:53:14 -070025 mov x0, #BL31_BASE
26 ldr x0, [x0]
27 cbnz x0, boot_cpu
Varun Wadekar93bed2a2016-03-18 13:07:33 -070028
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
Varun Wadekarfa887672017-11-08 14:45:08 -080072
73 .align 4
Varun Wadekar27155fc2017-04-20 18:56:09 -070074 .globl __tegra186_smmu_context
75__tegra186_smmu_context:
Varun Wadekar93bed2a2016-03-18 13:07:33 -070076 .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:
Varun Wadekar8304fc82017-10-25 11:52:07 -070085
86 .globl tegra186_get_cpu_reset_handler_size
87 .globl tegra186_get_cpu_reset_handler_base
Varun Wadekarfa887672017-11-08 14:45:08 -080088 .globl tegra186_get_smmu_ctx_offset
Varun Wadekar8304fc82017-10-25 11:52:07 -070089
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
Varun Wadekarfa887672017-11-08 14:45:08 -0800103
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