blob: 24c283ab0aa5ca5bf13511493044dd84ffd6681c [file] [log] [blame]
Soby Mathewc704cbc2014-08-14 11:33:56 +01001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch.h>
32#include <asm_macros.S>
33#include <assert_macros.S>
34#include <cpu_macros.S>
35#if IMAGE_BL31
36#include <cpu_data.h>
37#endif
38
39 /* Reset fn is needed in BL at reset vector */
Yatharth Kochar36433d12014-11-20 18:09:41 +000040#if IMAGE_BL1 || IMAGE_BL31
Soby Mathewc704cbc2014-08-14 11:33:56 +010041 /*
42 * The reset handler common to all platforms. After a matching
43 * cpu_ops structure entry is found, the correponding reset_handler
44 * in the cpu_ops is invoked.
Soby Mathewb5a63042015-01-29 12:00:58 +000045 * Clobbers: x0 - x19, x30
Soby Mathewc704cbc2014-08-14 11:33:56 +010046 */
47 .globl reset_handler
48func reset_handler
Soby Mathewc0884332014-09-22 12:11:36 +010049 mov x19, x30
Soby Mathewc704cbc2014-08-14 11:33:56 +010050
Soby Mathewb5a63042015-01-29 12:00:58 +000051 /* The plat_reset_handler can clobber x0 - x18, x30 */
Soby Mathewf1785fd2014-08-14 12:22:32 +010052 bl plat_reset_handler
53
Soby Mathewc704cbc2014-08-14 11:33:56 +010054 /* Get the matching cpu_ops pointer */
55 bl get_cpu_ops_ptr
56#if ASM_ASSERTION
57 cmp x0, #0
58 ASM_ASSERT(ne)
59#endif
60
61 /* Get the cpu_ops reset handler */
62 ldr x2, [x0, #CPU_RESET_FUNC]
Soby Mathewc0884332014-09-22 12:11:36 +010063 mov x30, x19
Soby Mathewc704cbc2014-08-14 11:33:56 +010064 cbz x2, 1f
Soby Mathewb5a63042015-01-29 12:00:58 +000065
66 /* The cpu_ops reset handler can clobber x0 - x19, x30 */
Soby Mathewc0884332014-09-22 12:11:36 +010067 br x2
Soby Mathewc704cbc2014-08-14 11:33:56 +0100681:
Soby Mathewc0884332014-09-22 12:11:36 +010069 ret
Soby Mathewf1785fd2014-08-14 12:22:32 +010070
Yatharth Kochar36433d12014-11-20 18:09:41 +000071#endif /* IMAGE_BL1 || IMAGE_BL31 */
Soby Mathewc704cbc2014-08-14 11:33:56 +010072
Soby Mathew8e2f2872014-08-14 12:49:05 +010073#if IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */
74 /*
75 * The prepare core power down function for all platforms. After
76 * the cpu_ops pointer is retrieved from cpu_data, the corresponding
77 * pwr_dwn_core in the cpu_ops is invoked.
78 */
79 .globl prepare_core_pwr_dwn
80func prepare_core_pwr_dwn
81 mrs x1, tpidr_el3
82 ldr x0, [x1, #CPU_DATA_CPU_OPS_PTR]
83#if ASM_ASSERTION
84 cmp x0, #0
85 ASM_ASSERT(ne)
86#endif
87
88 /* Get the cpu_ops core_pwr_dwn handler */
89 ldr x1, [x0, #CPU_PWR_DWN_CORE]
90 br x1
91
92 /*
93 * The prepare cluster power down function for all platforms. After
94 * the cpu_ops pointer is retrieved from cpu_data, the corresponding
95 * pwr_dwn_cluster in the cpu_ops is invoked.
96 */
97 .globl prepare_cluster_pwr_dwn
98func prepare_cluster_pwr_dwn
99 mrs x1, tpidr_el3
100 ldr x0, [x1, #CPU_DATA_CPU_OPS_PTR]
101#if ASM_ASSERTION
102 cmp x0, #0
103 ASM_ASSERT(ne)
104#endif
105
106 /* Get the cpu_ops cluster_pwr_dwn handler */
107 ldr x1, [x0, #CPU_PWR_DWN_CLUSTER]
108 br x1
109
110
111 /*
112 * Initializes the cpu_ops_ptr if not already initialized
Vikram Kanigiri9b38fc82015-01-29 18:27:38 +0000113 * in cpu_data. This can be called without a runtime stack, but may
114 * only be called after the MMU is enabled.
Soby Mathew8e2f2872014-08-14 12:49:05 +0100115 * clobbers: x0 - x6, x10
116 */
117 .globl init_cpu_ops
118func init_cpu_ops
119 mrs x6, tpidr_el3
120 ldr x0, [x6, #CPU_DATA_CPU_OPS_PTR]
121 cbnz x0, 1f
122 mov x10, x30
123 bl get_cpu_ops_ptr
124#if ASM_ASSERTION
125 cmp x0, #0
126 ASM_ASSERT(ne)
127#endif
Soby Mathew7d861ea2014-11-18 10:14:14 +0000128 str x0, [x6, #CPU_DATA_CPU_OPS_PTR]!
Soby Mathew8e2f2872014-08-14 12:49:05 +0100129 mov x30, x10
1301:
131 ret
132#endif /* IMAGE_BL31 */
133
Soby Mathew38b4bc92014-08-14 13:36:41 +0100134#if IMAGE_BL31 && CRASH_REPORTING
135 /*
136 * The cpu specific registers which need to be reported in a crash
137 * are reported via cpu_ops cpu_reg_dump function. After a matching
138 * cpu_ops structure entry is found, the correponding cpu_reg_dump
139 * in the cpu_ops is invoked.
140 */
141 .globl do_cpu_reg_dump
142func do_cpu_reg_dump
143 mov x16, x30
144
145 /* Get the matching cpu_ops pointer */
146 bl get_cpu_ops_ptr
147 cbz x0, 1f
148
149 /* Get the cpu_ops cpu_reg_dump */
150 ldr x2, [x0, #CPU_REG_DUMP]
151 cbz x2, 1f
152 blr x2
1531:
154 mov x30, x16
155 ret
156#endif
157
Soby Mathewc704cbc2014-08-14 11:33:56 +0100158 /*
159 * The below function returns the cpu_ops structure matching the
160 * midr of the core. It reads the MIDR_EL1 and finds the matching
161 * entry in cpu_ops entries. Only the implementation and part number
162 * are used to match the entries.
163 * Return :
164 * x0 - The matching cpu_ops pointer on Success
165 * x0 - 0 on failure.
166 * Clobbers : x0 - x5
167 */
168 .globl get_cpu_ops_ptr
169func get_cpu_ops_ptr
170 /* Get the cpu_ops start and end locations */
171 adr x4, (__CPU_OPS_START__ + CPU_MIDR)
172 adr x5, (__CPU_OPS_END__ + CPU_MIDR)
173
174 /* Initialize the return parameter */
175 mov x0, #0
176
177 /* Read the MIDR_EL1 */
178 mrs x2, midr_el1
179 mov_imm x3, CPU_IMPL_PN_MASK
180
181 /* Retain only the implementation and part number using mask */
182 and w2, w2, w3
1831:
184 /* Check if we have reached end of list */
185 cmp x4, x5
186 b.eq error_exit
187
188 /* load the midr from the cpu_ops */
189 ldr x1, [x4], #CPU_OPS_SIZE
190 and w1, w1, w3
191
192 /* Check if midr matches to midr of this core */
193 cmp w1, w2
194 b.ne 1b
195
196 /* Subtract the increment and offset to get the cpu-ops pointer */
197 sub x0, x4, #(CPU_OPS_SIZE + CPU_MIDR)
198error_exit:
199 ret
Soby Mathewc0884332014-09-22 12:11:36 +0100200
201#if DEBUG
202 /*
203 * This function prints a warning message to the crash console
204 * if the CPU revision/part number does not match the errata
205 * workaround enabled in the build.
206 * Clobber: x30, x0 - x5
207 */
208.section .rodata.rev_warn_str, "aS"
209rev_warn_str:
210 .asciz "Warning: Skipping Errata workaround for non matching CPU revision number.\n"
211
212 .globl print_revision_warning
213func print_revision_warning
214 mov x5, x30
215 /* Ensure the console is initialized */
216 bl plat_crash_console_init
217 /* Check if the console is initialized */
218 cbz x0, 1f
219 /* The console is initialized */
220 adr x4, rev_warn_str
221 bl asm_print_str
2221:
223 ret x5
224#endif
225