blob: b53e60dba151d6c2c62ee9f9b184f50a86ad1183 [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +00002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6#include <asm_macros.S>
7#include <platform_def.h>
8
Soby Mathewfec4eb72015-07-01 16:16:20 +01009 .weak plat_arm_calc_core_pos
10 .weak plat_my_core_pos
Dan Handley9df48042015-03-19 18:58:55 +000011 .globl plat_crash_console_init
12 .globl plat_crash_console_putc
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +000013 .globl plat_crash_console_flush
Sandrine Bailleuxaa94ffa2015-07-10 17:33:26 +010014 .globl platform_mem_init
dp-armee3457b2017-05-23 09:32:49 +010015 .globl arm_disable_spe
Dan Handley9df48042015-03-19 18:58:55 +000016
Soby Mathewfec4eb72015-07-01 16:16:20 +010017
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 /* -----------------------------------------------------
Soby Mathewa0fedc42016-06-16 14:52:04 +010030 * unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
Soby Mathewfec4eb72015-07-01 16:16:20 +010031 * 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
Dan Handley9df48042015-03-19 18:58:55 +000042
43 /* ---------------------------------------------
44 * int plat_crash_console_init(void)
45 * Function to initialize the crash console
46 * without a C Runtime to print crash report.
Juan Castilloe7ae6db2015-11-26 14:52:15 +000047 * Clobber list : x0 - x4
Dan Handley9df48042015-03-19 18:58:55 +000048 * ---------------------------------------------
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
Sandrine Bailleuxaa94ffa2015-07-10 17:33:26 +010068
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +000069 /* ---------------------------------------------
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
Sandrine Bailleuxaa94ffa2015-07-10 17:33:26 +010082 /* ---------------------------------------------------------------------
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
dp-armee3457b2017-05-23 09:32:49 +010090
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
Soby Mathew7e4d6652017-05-10 11:50:30 +0100118
119/*
120 * Need to use coherent stack when ARM Cryptocell is used to autheticate images
121 * since Cryptocell uses DMA to transfer data and it is not coherent with the
122 * AP CPU.
123 */
124#if ARM_CRYPTOCELL_INTEG
125#if defined(IMAGE_BL1) || defined(IMAGE_BL2)
126 .globl plat_get_my_stack
127 .globl plat_set_my_stack
128 .local platform_coherent_stacks
129
130 /* -------------------------------------------------------
131 * uintptr_t plat_get_my_stack ()
132 *
133 * For cold-boot BL images, only the primary CPU needs a
134 * stack. This function returns the stack pointer for a
135 * stack allocated in coherent memory.
136 * -------------------------------------------------------
137 */
138func plat_get_my_stack
139 get_up_stack platform_coherent_stacks, PLATFORM_STACK_SIZE
140 ret
141endfunc plat_get_my_stack
142
143 /* -------------------------------------------------------
144 * void plat_set_my_stack ()
145 *
146 * For cold-boot BL images, only the primary CPU needs a
147 * stack. This function sets the stack pointer to a stack
148 * allocated in coherent memory.
149 * -------------------------------------------------------
150 */
151func plat_set_my_stack
152 get_up_stack platform_coherent_stacks, PLATFORM_STACK_SIZE
153 mov sp, x0
154 ret
155endfunc plat_set_my_stack
156
157 /* ----------------------------------------------------
158 * Single cpu stack in coherent memory.
159 * ----------------------------------------------------
160 */
161declare_stack platform_coherent_stacks, tzfw_coherent_mem, \
162 PLATFORM_STACK_SIZE, 1, CACHE_WRITEBACK_GRANULE
163
164#endif /* defined(IMAGE_BL1) || defined(IMAGE_BL2) */
165#endif /* ARM_CRYPTOCELL_INTEG */