blob: 7d71f48266e29b1ce60e6f08efaf45411cd0834f [file] [log] [blame]
Jiafei Pan46367ad2018-03-02 07:23:30 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8#include <console.h>
9#include <platform_def.h>
10
11 .weak plat_my_core_pos
12 .globl plat_crash_console_init
13 .globl plat_crash_console_putc
14 .globl plat_crash_console_flush
15 .weak platform_mem_init
16 .globl plat_ls_calc_core_pos
17
18
19 /* -----------------------------------------------------
20 * unsigned int plat_my_core_pos(void)
21 * This function uses the plat_ls_calc_core_pos()
22 * definition to get the index of the calling CPU.
23 * -----------------------------------------------------
24 */
25func plat_my_core_pos
26 mrs x0, mpidr_el1
27 b plat_ls_calc_core_pos
28endfunc plat_my_core_pos
29
30 /* -----------------------------------------------------
31 * unsigned int plat_ls_calc_core_pos(u_register_t mpidr)
32 * Helper function to calculate the core position.
33 * With this function: CorePos = (ClusterId * 4) +
34 * CoreId
35 * -----------------------------------------------------
36 */
37func plat_ls_calc_core_pos
38 and x1, x0, #MPIDR_CPU_MASK
39 and x0, x0, #MPIDR_CLUSTER_MASK
40 add x0, x1, x0, LSR #6
41 ret
42endfunc plat_ls_calc_core_pos
43
44 /* ---------------------------------------------
45 * int plat_crash_console_init(void)
46 * Function to initialize the crash console
47 * without a C Runtime to print crash report.
48 * Clobber list : x0 - x4
49 * ---------------------------------------------
50 */
51
52#if MULTI_CONSOLE_API
53 /* -----------------------------------------------------
54 * int plat_crash_console_init(void)
55 * Use normal console by default. Switch it to crash
56 * mode so serial consoles become active again.
57 * NOTE: This default implementation will only work for
58 * crashes that occur after a normal console (marked
59 * valid for the crash state) has been registered with
60 * the console framework. To debug crashes that occur
61 * earlier, the platform has to override these functions
62 * with an implementation that initializes a console
63 * driver with hardcoded parameters. See
64 * docs/porting-guide.rst for more information.
65 * -----------------------------------------------------
66 */
67func plat_crash_console_init
68#if defined(IMAGE_BL1)
69 /*
70 * BL1 code can possibly crash so early that the data segment is not yet
71 * accessible. Don't risk undefined behavior by trying to run the normal
72 * console framework. Platforms that want to debug BL1 will need to
73 * override this with custom functions that can run from registers only.
74 */
75 mov x0, #0
76 ret
77#else /* IMAGE_BL1 */
78 mov x3, x30
79 mov x0, #CONSOLE_FLAG_CRASH
80 bl console_switch_state
81 mov x0, #1
82 ret x3
83#endif
84endfunc plat_crash_console_init
85
86 /* -----------------------------------------------------
87 * void plat_crash_console_putc(int character)
88 * Output through the normal console by default.
89 * -----------------------------------------------------
90 */
91func plat_crash_console_putc
92 b console_putc
93endfunc plat_crash_console_putc
94
95 /* -----------------------------------------------------
96 * void plat_crash_console_flush(void)
97 * Flush normal console by default.
98 * -----------------------------------------------------
99 */
100func plat_crash_console_flush
101 b console_flush
102endfunc plat_crash_console_flush
103
104#else /* MULTI_CONSOLE_API */
105
106 /* -----------------------------------------------------
107 * In the old API these are all no-op stubs that need to
108 * be overridden by the platform to be useful.
109 * -----------------------------------------------------
110 */
111func plat_crash_console_init
112 mov_imm x0, PLAT_LS1043_UART_BASE
113 mov_imm x1, PLAT_LS1043_UART_CLOCK
114 mov_imm x2, PLAT_LS1043_UART_BAUDRATE
115 b console_core_init
116endfunc plat_crash_console_init
117
118 /* ---------------------------------------------
119 * int plat_crash_console_putc(int c)
120 * Function to print a character on the crash
121 * console without a C Runtime.
122 * Clobber list : x1, x2
123 * ---------------------------------------------
124 */
125func plat_crash_console_putc
126 mov_imm x1, PLAT_LS1043_UART_BASE
127 b console_core_putc
128endfunc plat_crash_console_putc
129
130 /* ---------------------------------------------
131 * int plat_crash_console_flush()
132 * Function to force a write of all buffered
133 * data that hasn't been output.
134 * Out : return -1 on error else return 0.
135 * Clobber list : r0 - r1
136 * ---------------------------------------------
137 */
138func plat_crash_console_flush
139 mov_imm x1, PLAT_LS1043_UART_BASE
140 b console_core_flush
141endfunc plat_crash_console_flush
142#endif
143 /* ---------------------------------------------------------------------
144 * We don't need to carry out any memory initialization on LS
145 * platforms. The Secure SRAM is accessible straight away.
146 * ---------------------------------------------------------------------
147 */
148func platform_mem_init
149 ret
150endfunc platform_mem_init