stm32mp1_helper.S 6.65 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
8
#include <platform_def.h>

9
10
#include <arch.h>
#include <asm_macros.S>
11
12
#include <common/bl_common.h>
#include <drivers/st/stm32_gpio.h>
Yann Gautier's avatar
Yann Gautier committed
13

14
#define GPIO_TX_SHIFT		(DEBUG_UART_TX_GPIO_PORT << 1)
15
16
17
18
19
20
21
22

	.globl	platform_mem_init
	.globl	plat_report_exception
	.globl	plat_get_my_entrypoint
	.globl	plat_secondary_cold_boot_setup
	.globl	plat_reset_handler
	.globl	plat_is_my_cpu_primary
	.globl	plat_my_core_pos
Yann Gautier's avatar
Yann Gautier committed
23
24
25
	.globl	plat_crash_console_init
	.globl	plat_crash_console_flush
	.globl	plat_crash_console_putc
26
27
28
29
30
31
32
33
	.globl	plat_panic_handler

func platform_mem_init
	/* Nothing to do, don't need to init SYSRAM */
	bx	lr
endfunc platform_mem_init

func plat_report_exception
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#if DEBUG
	mov	r8, lr

	/* Test if an abort occurred */
	cmp	r0, #MODE32_abt
	bne	undef_inst_lbl
	ldr	r4, =abort_str
	bl	asm_print_str
	mrs	r4, lr_abt
	sub	r4, r4, #4
	b	print_exception_info

undef_inst_lbl:
	/* Test for an undefined instruction */
	cmp	r0, #MODE32_und
	bne	other_exception_lbl
	ldr	r4, =undefined_str
	bl	asm_print_str
	mrs	r4, lr_und
	b	print_exception_info

other_exception_lbl:
	/* Other exceptions */
	mov	r9, r0
	ldr	r4, =exception_start_str
	bl	asm_print_str
	mov	r4, r9
	bl	asm_print_hex
	ldr	r4, =exception_end_str
	bl	asm_print_str
	mov	r4, r6

print_exception_info:
	bl	asm_print_hex

	ldr	r4, =end_error_str
	bl	asm_print_str

	bx	r8
#else
74
	bx	lr
75
#endif
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
endfunc plat_report_exception

func plat_reset_handler
	bx	lr
endfunc plat_reset_handler

	/* ------------------------------------------------------------------
	 * unsigned long plat_get_my_entrypoint (void);
	 *
	 * Main job of this routine is to distinguish between a cold and warm
	 * boot.
	 *
	 * Currently supports only cold boot
	 * ------------------------------------------------------------------
	 */
func plat_get_my_entrypoint
	mov	r0, #0
	bx	lr
endfunc plat_get_my_entrypoint

	/* ---------------------------------------------
	 * void plat_secondary_cold_boot_setup (void);
	 *
	 * Cold-booting secondary CPUs is not supported.
	 * ---------------------------------------------
	 */
func plat_secondary_cold_boot_setup
	b	.
endfunc plat_secondary_cold_boot_setup

	/* -----------------------------------------------------
	 * unsigned int plat_is_my_cpu_primary (void);
	 *
	 * Find out whether the current cpu is the primary cpu.
	 * -----------------------------------------------------
	 */
func plat_is_my_cpu_primary
	ldcopr	r0, MPIDR
	ldr	r1, =(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
	and	r0, r1
116
	cmp	r0, #STM32MP_PRIMARY_CPU
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
	moveq	r0, #1
	movne	r0, #0
	bx	lr
endfunc plat_is_my_cpu_primary

	/* -------------------------------------------
	 *  int plat_stm32mp1_get_core_pos(int mpidr);
	 *
	 *  Return CorePos = (ClusterId * 4) + CoreId
	 * -------------------------------------------
	 */
func plat_stm32mp1_get_core_pos
	and	r1, r0, #MPIDR_CPU_MASK
	and	r0, r0, #MPIDR_CLUSTER_MASK
	add	r0, r1, r0, LSR #6
	bx	lr
endfunc plat_stm32mp1_get_core_pos

	/* ------------------------------------
	 *  unsigned int plat_my_core_pos(void)
	 * ------------------------------------
	 */
func plat_my_core_pos
	ldcopr	r0, MPIDR
	b	plat_stm32mp1_get_core_pos
endfunc plat_my_core_pos
Yann Gautier's avatar
Yann Gautier committed
143
144
145
146
147
148
149
150

	/* ---------------------------------------------
	 * int plat_crash_console_init(void)
	 *
	 * Initialize the crash console without a C Runtime stack.
	 * ---------------------------------------------
	 */
func plat_crash_console_init
151
152
	/* Enable GPIOs for UART TX */
	ldr	r1, =(RCC_BASE + DEBUG_UART_TX_GPIO_BANK_CLK_REG)
Yann Gautier's avatar
Yann Gautier committed
153
	ldr	r2, [r1]
154
155
	/* Configure GPIO */
	orr	r2, r2, #DEBUG_UART_TX_GPIO_BANK_CLK_EN
Yann Gautier's avatar
Yann Gautier committed
156
	str	r2, [r1]
157
	ldr	r1, =DEBUG_UART_TX_GPIO_BANK_ADDRESS
Yann Gautier's avatar
Yann Gautier committed
158
159
160
161
162
163
164
165
166
167
168
169
170
	/* Set GPIO mode alternate */
	ldr	r2, [r1, #GPIO_MODE_OFFSET]
	bic	r2, r2, #(GPIO_MODE_MASK << GPIO_TX_SHIFT)
	orr	r2, r2, #(GPIO_MODE_ALTERNATE << GPIO_TX_SHIFT)
	str	r2, [r1, #GPIO_MODE_OFFSET]
	/* Set GPIO speed low */
	ldr	r2, [r1, #GPIO_SPEED_OFFSET]
	bic	r2, r2, #(GPIO_SPEED_MASK << GPIO_TX_SHIFT)
	str	r2, [r1, #GPIO_SPEED_OFFSET]
	/* Set no-pull */
	ldr	r2, [r1, #GPIO_PUPD_OFFSET]
	bic	r2, r2, #(GPIO_PULL_MASK << GPIO_TX_SHIFT)
	str	r2, [r1, #GPIO_PUPD_OFFSET]
171
	/* Set alternate */
172
#if DEBUG_UART_TX_GPIO_PORT >= GPIO_ALT_LOWER_LIMIT
Yann Gautier's avatar
Yann Gautier committed
173
	ldr	r2, [r1, #GPIO_AFRH_OFFSET]
174
175
176
177
	bic	r2, r2, #(GPIO_ALTERNATE_MASK << \
				((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2))
	orr	r2, r2, #(DEBUG_UART_TX_GPIO_ALTERNATE << \
				((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2))
Yann Gautier's avatar
Yann Gautier committed
178
	str	r2, [r1, #GPIO_AFRH_OFFSET]
179
180
181
182
183
184
#else
	ldr	r2, [r1, #GPIO_AFRL_OFFSET]
	bic	r2, r2, #(GPIO_ALTERNATE_MASK << (DEBUG_UART_TX_GPIO_PORT << 2))
	orr	r2, r2, #(DEBUG_UART_TX_GPIO_ALTERNATE << (DEBUG_UART_TX_GPIO_PORT << 2))
	str	r2, [r1, #GPIO_AFRL_OFFSET]
#endif
185
186
187
	/* Enable UART clock, with its source */
	ldr	r1, =(RCC_BASE + DEBUG_UART_TX_CLKSRC_REG)
	mov	r2, #DEBUG_UART_TX_CLKSRC
Yann Gautier's avatar
Yann Gautier committed
188
	str	r2, [r1]
189
	ldr	r1, =(RCC_BASE + DEBUG_UART_TX_EN_REG)
Yann Gautier's avatar
Yann Gautier committed
190
	ldr	r2, [r1]
191
	orr	r2, r2, #DEBUG_UART_TX_EN
Yann Gautier's avatar
Yann Gautier committed
192
193
	str	r2, [r1]

194
195
196
	ldr	r0, =STM32MP_DEBUG_USART_BASE
	ldr	r1, =STM32MP_DEBUG_USART_CLK_FRQ
	ldr	r2, =STM32MP_UART_BAUDRATE
Yann Gautier's avatar
Yann Gautier committed
197
	b	console_stm32_core_init
Yann Gautier's avatar
Yann Gautier committed
198
199
200
endfunc plat_crash_console_init

	/* ---------------------------------------------
201
	 * void plat_crash_console_flush(void)
Yann Gautier's avatar
Yann Gautier committed
202
203
204
205
206
	 *
	 * Flush the crash console without a C Runtime stack.
	 * ---------------------------------------------
	 */
func plat_crash_console_flush
207
	ldr	r1, =STM32MP_DEBUG_USART_BASE
Yann Gautier's avatar
Yann Gautier committed
208
	b	console_stm32_core_flush
Yann Gautier's avatar
Yann Gautier committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
endfunc plat_crash_console_flush

	/* ---------------------------------------------
	 * int plat_crash_console_putc(int c)
	 *
	 * Print a character on the crash console without a C Runtime stack.
	 * Clobber list : r1 - r3
	 *
	 * In case of bootloading through uart, we keep console crash as this.
	 * Characters could be sent to the programmer, but will be ignored.
	 * No specific code in that case.
	 * ---------------------------------------------
	 */
func plat_crash_console_putc
223
	ldr	r1, =STM32MP_DEBUG_USART_BASE
Yann Gautier's avatar
Yann Gautier committed
224
	b	console_stm32_core_putc
Yann Gautier's avatar
Yann Gautier committed
225
endfunc plat_crash_console_putc
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
	/* ----------------------------------------------------------
	 * void plat_panic_handler(void) __dead2;
	 * Report exception + endless loop.
	 *
	 * r6 holds the address where the fault occurred.
	 * Filling lr with this value allows debuggers to reconstruct
	 * the backtrace.
	 * ----------------------------------------------------------
	 */
func plat_panic_handler
	mrs	r0, cpsr
	and	r0, #MODE32_MASK
	bl	plat_report_exception
	mov	lr, r6
	b	.
endfunc plat_panic_handler

244
245
246
247
248
249
250
251
252
253
254
255
256
#if DEBUG
.section .rodata.rev_err_str, "aS"
abort_str:
	.asciz "\nAbort at: 0x"
undefined_str:
	.asciz "\nUndefined instruction at: 0x"
exception_start_str:
	.asciz "\nException mode=0x"
exception_end_str:
	.asciz " at: 0x"
end_error_str:
	.asciz "\n\r"
#endif