1/*
2 * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#include <asm_macros.S>
7#include <platform_def.h>
8
9	.weak	plat_arm_calc_core_pos
10	.weak	plat_my_core_pos
11	.globl	plat_crash_console_init
12	.globl	plat_crash_console_putc
13	.globl	plat_crash_console_flush
14
15	/* -----------------------------------------------------
16	 *  unsigned int plat_my_core_pos(void)
17	 *  This function uses the plat_arm_calc_core_pos()
18	 *  definition to get the index of the calling CPU.
19	 * -----------------------------------------------------
20	 */
21func plat_my_core_pos
22	ldcopr	r0, MPIDR
23	b	plat_arm_calc_core_pos
24endfunc plat_my_core_pos
25
26	/* -----------------------------------------------------
27	 *  unsigned int plat_arm_calc_core_pos(uint64_t mpidr)
28	 *  Helper function to calculate the core position.
29	 *  With this function: CorePos = (ClusterId * 4) +
30	 *  				  CoreId
31	 * -----------------------------------------------------
32	 */
33func plat_arm_calc_core_pos
34	and	r1, r0, #MPIDR_CPU_MASK
35	and	r0, r0, #MPIDR_CLUSTER_MASK
36	add	r0, r1, r0, LSR #6
37	bx	lr
38endfunc plat_arm_calc_core_pos
39
40	/* ---------------------------------------------
41	 * int plat_crash_console_init(void)
42	 * Function to initialize the crash console
43	 * without a C Runtime to print crash report.
44	 * Clobber list : r0 - r3
45	 * ---------------------------------------------
46	 */
47func plat_crash_console_init
48	ldr	r0, =PLAT_ARM_CRASH_UART_BASE
49	ldr	r1, =PLAT_ARM_CRASH_UART_CLK_IN_HZ
50	ldr	r2, =ARM_CONSOLE_BAUDRATE
51	b	console_pl011_core_init
52endfunc plat_crash_console_init
53
54	/* ---------------------------------------------
55	 * int plat_crash_console_putc(int c)
56	 * Function to print a character on the crash
57	 * console without a C Runtime.
58	 * Clobber list : r1 - r2
59	 * ---------------------------------------------
60	 */
61func plat_crash_console_putc
62	ldr	r1, =PLAT_ARM_CRASH_UART_BASE
63	b	console_pl011_core_putc
64endfunc plat_crash_console_putc
65
66	/* ---------------------------------------------
67	 * void plat_crash_console_flush()
68	 * Function to force a write of all buffered
69	 * data that hasn't been output.
70	 * Out : void.
71	 * Clobber list : r0
72	 * ---------------------------------------------
73	 */
74func plat_crash_console_flush
75	ldr	r0, =PLAT_ARM_CRASH_UART_BASE
76	b	console_pl011_core_flush
77endfunc plat_crash_console_flush
78