xref: /rk3399_ARM-atf/plat/arm/common/aarch64/arm_helpers.S (revision d70a7d0ce02c0b73891cc1e26fc2c568d7120b84)
1/*
2 * Copyright (c) 2015-2017, 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	.globl	platform_mem_init
15	.globl	arm_disable_spe
16
17
18	/* -----------------------------------------------------
19	 *  unsigned int plat_my_core_pos(void)
20	 *  This function uses the plat_arm_calc_core_pos()
21	 *  definition to get the index of the calling CPU.
22	 * -----------------------------------------------------
23	 */
24func plat_my_core_pos
25	mrs	x0, mpidr_el1
26	b	plat_arm_calc_core_pos
27endfunc plat_my_core_pos
28
29	/* -----------------------------------------------------
30	 *  unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
31	 *  Helper function to calculate the core position.
32	 *  With this function: CorePos = (ClusterId * 4) +
33	 *  				  CoreId
34	 * -----------------------------------------------------
35	 */
36func plat_arm_calc_core_pos
37	and	x1, x0, #MPIDR_CPU_MASK
38	and	x0, x0, #MPIDR_CLUSTER_MASK
39	add	x0, x1, x0, LSR #6
40	ret
41endfunc plat_arm_calc_core_pos
42
43	/* ---------------------------------------------
44	 * int plat_crash_console_init(void)
45	 * Function to initialize the crash console
46	 * without a C Runtime to print crash report.
47	 * Clobber list : x0 - x4
48	 * ---------------------------------------------
49	 */
50func plat_crash_console_init
51	mov_imm	x0, PLAT_ARM_CRASH_UART_BASE
52	mov_imm	x1, PLAT_ARM_CRASH_UART_CLK_IN_HZ
53	mov_imm	x2, ARM_CONSOLE_BAUDRATE
54	b	console_core_init
55endfunc plat_crash_console_init
56
57	/* ---------------------------------------------
58	 * int plat_crash_console_putc(int c)
59	 * Function to print a character on the crash
60	 * console without a C Runtime.
61	 * Clobber list : x1, x2
62	 * ---------------------------------------------
63	 */
64func plat_crash_console_putc
65	mov_imm	x1, PLAT_ARM_CRASH_UART_BASE
66	b	console_core_putc
67endfunc plat_crash_console_putc
68
69	/* ---------------------------------------------
70	 * int plat_crash_console_flush()
71	 * Function to force a write of all buffered
72	 * data that hasn't been output.
73	 * Out : return -1 on error else return 0.
74	 * Clobber list : r0 - r1
75	 * ---------------------------------------------
76	 */
77func plat_crash_console_flush
78	mov_imm	x1, PLAT_ARM_CRASH_UART_BASE
79	b	console_core_flush
80endfunc plat_crash_console_flush
81
82	/* ---------------------------------------------------------------------
83	 * We don't need to carry out any memory initialization on ARM
84	 * platforms. The Secure RAM is accessible straight away.
85	 * ---------------------------------------------------------------------
86	 */
87func platform_mem_init
88	ret
89endfunc platform_mem_init
90
91	/* -----------------------------------------------------
92	 * void arm_disable_spe (void);
93	 * -----------------------------------------------------
94	 */
95#if ENABLE_SPE_FOR_LOWER_ELS
96func arm_disable_spe
97	/* Detect if SPE is implemented */
98	mrs	x0, id_aa64dfr0_el1
99	ubfx	x0, x0, #ID_AA64DFR0_PMS_SHIFT, #ID_AA64DFR0_PMS_LENGTH
100	cmp	x0, #0x1
101	b.ne	1f
102
103	/* Drain buffered data */
104	.arch	armv8.2-a+profile
105	psb	csync
106	dsb	nsh
107
108	/* Disable Profiling Buffer */
109	mrs	x0, pmblimitr_el1
110	bic	x0, x0, #1
111	msr	pmblimitr_el1, x0
112	isb
113	.arch	armv8-a
1141:
115	ret
116endfunc arm_disable_spe
117#endif
118