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