xref: /arm-trusted-firmware/plat/hisilicon/hikey960/aarch64/hikey960_helpers.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu#include <arch.h>
8*91f16700Schasinglulu#include <asm_macros.S>
9*91f16700Schasinglulu#include <cortex_a53.h>
10*91f16700Schasinglulu#include <cortex_a73.h>
11*91f16700Schasinglulu#include "../hikey960_def.h"
12*91f16700Schasinglulu
13*91f16700Schasinglulu	.globl	plat_my_core_pos
14*91f16700Schasinglulu	.globl	platform_mem_init
15*91f16700Schasinglulu	.globl	plat_crash_console_init
16*91f16700Schasinglulu	.globl	plat_crash_console_putc
17*91f16700Schasinglulu	.globl	plat_crash_console_flush
18*91f16700Schasinglulu	.globl	plat_report_exception
19*91f16700Schasinglulu	.globl	plat_reset_handler
20*91f16700Schasinglulu	.globl	clr_ex
21*91f16700Schasinglulu	.globl	nop
22*91f16700Schasinglulu
23*91f16700Schasinglulufunc plat_my_core_pos
24*91f16700Schasinglulu	mrs	x0, mpidr_el1
25*91f16700Schasinglulu	and	x1, x0, #MPIDR_CPU_MASK
26*91f16700Schasinglulu	and	x0, x0, #MPIDR_CLUSTER_MASK
27*91f16700Schasinglulu	add	x0, x1, x0, LSR #6
28*91f16700Schasinglulu	ret
29*91f16700Schasingluluendfunc plat_my_core_pos
30*91f16700Schasinglulu
31*91f16700Schasinglulu	/* -----------------------------------------------------
32*91f16700Schasinglulu	 * void platform_mem_init(void);
33*91f16700Schasinglulu	 *
34*91f16700Schasinglulu	 * We don't need to carry out any memory initialization
35*91f16700Schasinglulu	 * on HIKEY. The Secure RAM is accessible straight away.
36*91f16700Schasinglulu	 * -----------------------------------------------------
37*91f16700Schasinglulu	 */
38*91f16700Schasinglulufunc platform_mem_init
39*91f16700Schasinglulu	ret
40*91f16700Schasingluluendfunc platform_mem_init
41*91f16700Schasinglulu
42*91f16700Schasinglulu	/* ---------------------------------------------
43*91f16700Schasinglulu	 * int plat_crash_console_init(void)
44*91f16700Schasinglulu	 * Function to initialize the crash console
45*91f16700Schasinglulu	 * without a C Runtime to print crash report.
46*91f16700Schasinglulu	 * Clobber list : x0, x1, x2
47*91f16700Schasinglulu	 * ---------------------------------------------
48*91f16700Schasinglulu	 */
49*91f16700Schasinglulufunc plat_crash_console_init
50*91f16700Schasinglulu	mov_imm	x0, CRASH_CONSOLE_BASE
51*91f16700Schasinglulu	mov_imm	x1, PL011_UART_CLK_IN_HZ
52*91f16700Schasinglulu	mov_imm	x2, PL011_BAUDRATE
53*91f16700Schasinglulu	b	console_pl011_core_init
54*91f16700Schasingluluendfunc plat_crash_console_init
55*91f16700Schasinglulu
56*91f16700Schasinglulu	/* ---------------------------------------------
57*91f16700Schasinglulu	 * int plat_crash_console_putc(int c)
58*91f16700Schasinglulu	 * Function to print a character on the crash
59*91f16700Schasinglulu	 * console without a C Runtime.
60*91f16700Schasinglulu	 * Clobber list : x1, x2
61*91f16700Schasinglulu	 * ---------------------------------------------
62*91f16700Schasinglulu	 */
63*91f16700Schasinglulufunc plat_crash_console_putc
64*91f16700Schasinglulu	mov_imm	x1, CRASH_CONSOLE_BASE
65*91f16700Schasinglulu	b	console_pl011_core_putc
66*91f16700Schasingluluendfunc plat_crash_console_putc
67*91f16700Schasinglulu
68*91f16700Schasinglulu	/* ---------------------------------------------
69*91f16700Schasinglulu	 * void plat_crash_console_flush()
70*91f16700Schasinglulu	 * Function to force a write of all buffered
71*91f16700Schasinglulu	 * data that hasn't been output.
72*91f16700Schasinglulu	 * Out : void.
73*91f16700Schasinglulu	 * Clobber list : x0, x1
74*91f16700Schasinglulu	 * ---------------------------------------------
75*91f16700Schasinglulu	 */
76*91f16700Schasinglulufunc plat_crash_console_flush
77*91f16700Schasinglulu	mov_imm	x0, CRASH_CONSOLE_BASE
78*91f16700Schasinglulu	b	console_pl011_core_flush
79*91f16700Schasingluluendfunc plat_crash_console_flush
80*91f16700Schasinglulu
81*91f16700Schasinglulu	/* ---------------------------------------------
82*91f16700Schasinglulu	 * void plat_report_exception(unsigned int type)
83*91f16700Schasinglulu	 * Function to report an unhandled exception
84*91f16700Schasinglulu	 * with platform-specific means.
85*91f16700Schasinglulu	 * On HIKEY platform, it updates the LEDs
86*91f16700Schasinglulu	 * to indicate where we are
87*91f16700Schasinglulu	 * ---------------------------------------------
88*91f16700Schasinglulu	 */
89*91f16700Schasinglulufunc plat_report_exception
90*91f16700Schasinglulu	mov	x8, x30
91*91f16700Schasinglulu
92*91f16700Schasinglulu	/* Turn on LED according to x0 (0 -- f) */
93*91f16700Schasinglulu	ldr	x2, =0xf7020000
94*91f16700Schasinglulu	and	x1, x0, #1
95*91f16700Schasinglulu	str	w1, [x2, #4]
96*91f16700Schasinglulu	and	x1, x0, #2
97*91f16700Schasinglulu	str	w1, [x2, #8]
98*91f16700Schasinglulu	and	x1, x0, #4
99*91f16700Schasinglulu	str	w1, [x2, #16]
100*91f16700Schasinglulu	and	x1, x0, #8
101*91f16700Schasinglulu	str	w1, [x2, #32]
102*91f16700Schasinglulu
103*91f16700Schasinglulu	mrs	x2, currentel
104*91f16700Schasinglulu	and	x2, x2, #0x0c
105*91f16700Schasinglulu	/* Check EL1 */
106*91f16700Schasinglulu	cmp	x2, #0x04
107*91f16700Schasinglulu	beq	plat_report_el1
108*91f16700Schasinglulu
109*91f16700Schasinglulu	adr	x4, plat_err_str
110*91f16700Schasinglulu	bl	asm_print_str
111*91f16700Schasinglulu
112*91f16700Schasinglulu	adr	x4, esr_el3_str
113*91f16700Schasinglulu	bl	asm_print_str
114*91f16700Schasinglulu
115*91f16700Schasinglulu	mrs	x4, esr_el3
116*91f16700Schasinglulu	bl	asm_print_hex
117*91f16700Schasinglulu
118*91f16700Schasinglulu	adr	x4, elr_el3_str
119*91f16700Schasinglulu	bl	asm_print_str
120*91f16700Schasinglulu
121*91f16700Schasinglulu	mrs	x4, elr_el3
122*91f16700Schasinglulu	bl	asm_print_hex
123*91f16700Schasinglulu	b	plat_report_end
124*91f16700Schasinglulu
125*91f16700Schasingluluplat_report_el1:
126*91f16700Schasinglulu	adr	x4, plat_err_str
127*91f16700Schasinglulu	bl	asm_print_str
128*91f16700Schasinglulu
129*91f16700Schasinglulu	adr	x4, esr_el1_str
130*91f16700Schasinglulu	bl	asm_print_str
131*91f16700Schasinglulu
132*91f16700Schasinglulu	mrs	x4, esr_el1
133*91f16700Schasinglulu	bl	asm_print_hex
134*91f16700Schasinglulu
135*91f16700Schasinglulu	adr	x4, elr_el1_str
136*91f16700Schasinglulu	bl	asm_print_str
137*91f16700Schasinglulu
138*91f16700Schasinglulu	mrs	x4, elr_el1
139*91f16700Schasinglulu	bl	asm_print_hex
140*91f16700Schasingluluplat_report_end:
141*91f16700Schasinglulu	mov	x30, x8
142*91f16700Schasinglulu	ret
143*91f16700Schasingluluendfunc plat_report_exception
144*91f16700Schasinglulu
145*91f16700Schasinglulu	/* -----------------------------------------------------
146*91f16700Schasinglulu	 * void plat_reset_handler(void);
147*91f16700Schasinglulu	 * -----------------------------------------------------
148*91f16700Schasinglulu	 */
149*91f16700Schasinglulufunc plat_reset_handler
150*91f16700Schasinglulu	ret
151*91f16700Schasingluluendfunc plat_reset_handler
152*91f16700Schasinglulu
153*91f16700Schasinglulu	/* -----------------------------------------------------
154*91f16700Schasinglulu	 * void clrex(void);
155*91f16700Schasinglulu	 * -----------------------------------------------------
156*91f16700Schasinglulu	 */
157*91f16700Schasinglulufunc clr_ex
158*91f16700Schasinglulu	clrex
159*91f16700Schasinglulu	ret
160*91f16700Schasingluluendfunc clr_ex
161*91f16700Schasinglulu
162*91f16700Schasinglulu	/* -----------------------------------------------------
163*91f16700Schasinglulu	 * void nop(void);
164*91f16700Schasinglulu	 * -----------------------------------------------------
165*91f16700Schasinglulu	 */
166*91f16700Schasinglulufunc nop
167*91f16700Schasinglulu	nop
168*91f16700Schasinglulu	ret
169*91f16700Schasingluluendfunc nop
170*91f16700Schasinglulu
171*91f16700Schasinglulu.section .rodata.rev_err_str, "aS"
172*91f16700Schasingluluplat_err_str:
173*91f16700Schasinglulu	.asciz "\nPlatform exception reporting:"
174*91f16700Schasingluluesr_el3_str:
175*91f16700Schasinglulu	.asciz "\nESR_EL3: "
176*91f16700Schasingluluelr_el3_str:
177*91f16700Schasinglulu	.asciz "\nELR_EL3: "
178*91f16700Schasingluluesr_el1_str:
179*91f16700Schasinglulu	.asciz "\nESR_EL1: "
180*91f16700Schasingluluelr_el1_str:
181*91f16700Schasinglulu	.asciz "\nELR_EL1: "
182