blob: b4b699ea438714013b326c1b0bb802d7605a6eed [file] [log] [blame]
Yann Gautier4353bb22018-07-16 10:54:09 +02001/*
Yann Gautiera9eda772020-09-15 12:24:46 +02002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Yann Gautier4353bb22018-07-16 10:54:09 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00007#include <platform_def.h>
8
Yann Gautier4353bb22018-07-16 10:54:09 +02009#include <arch.h>
10#include <asm_macros.S>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000011#include <common/bl_common.h>
12#include <drivers/st/stm32_gpio.h>
Yann Gautier278c34d2018-07-05 16:48:16 +020013
Yann Gautier1fc21302019-01-17 19:17:47 +010014#define GPIO_TX_SHIFT (DEBUG_UART_TX_GPIO_PORT << 1)
15#define GPIO_TX_ALT_SHIFT ((DEBUG_UART_TX_GPIO_PORT - GPIO_ALT_LOWER_LIMIT) << 2)
Yann Gautier4353bb22018-07-16 10:54:09 +020016
17 .globl platform_mem_init
18 .globl plat_report_exception
19 .globl plat_get_my_entrypoint
20 .globl plat_secondary_cold_boot_setup
21 .globl plat_reset_handler
22 .globl plat_is_my_cpu_primary
23 .globl plat_my_core_pos
Yann Gautier278c34d2018-07-05 16:48:16 +020024 .globl plat_crash_console_init
25 .globl plat_crash_console_flush
26 .globl plat_crash_console_putc
Yann Gautier4353bb22018-07-16 10:54:09 +020027 .globl plat_panic_handler
28
29func platform_mem_init
30 /* Nothing to do, don't need to init SYSRAM */
31 bx lr
32endfunc platform_mem_init
33
34func plat_report_exception
Yann Gautiera9eda772020-09-15 12:24:46 +020035#if DEBUG
36 mov r8, lr
37
38 /* Test if an abort occurred */
39 cmp r0, #MODE32_abt
40 bne undef_inst_lbl
41 ldr r4, =abort_str
42 bl asm_print_str
43 mrs r4, lr_abt
44 sub r4, r4, #4
45 b print_exception_info
46
47undef_inst_lbl:
48 /* Test for an undefined instruction */
49 cmp r0, #MODE32_und
50 bne other_exception_lbl
51 ldr r4, =undefined_str
52 bl asm_print_str
53 mrs r4, lr_und
54 b print_exception_info
55
56other_exception_lbl:
57 /* Other exceptions */
58 mov r9, r0
59 ldr r4, =exception_start_str
60 bl asm_print_str
61 mov r4, r9
62 bl asm_print_hex
63 ldr r4, =exception_end_str
64 bl asm_print_str
65 mov r4, r6
66
67print_exception_info:
68 bl asm_print_hex
69
70 ldr r4, =end_error_str
71 bl asm_print_str
72
73 bx r8
74#else
Yann Gautier4353bb22018-07-16 10:54:09 +020075 bx lr
Yann Gautiera9eda772020-09-15 12:24:46 +020076#endif
Yann Gautier4353bb22018-07-16 10:54:09 +020077endfunc plat_report_exception
78
79func plat_reset_handler
80 bx lr
81endfunc plat_reset_handler
82
83 /* ------------------------------------------------------------------
84 * unsigned long plat_get_my_entrypoint (void);
85 *
86 * Main job of this routine is to distinguish between a cold and warm
87 * boot.
88 *
89 * Currently supports only cold boot
90 * ------------------------------------------------------------------
91 */
92func plat_get_my_entrypoint
93 mov r0, #0
94 bx lr
95endfunc plat_get_my_entrypoint
96
97 /* ---------------------------------------------
98 * void plat_secondary_cold_boot_setup (void);
99 *
100 * Cold-booting secondary CPUs is not supported.
101 * ---------------------------------------------
102 */
103func plat_secondary_cold_boot_setup
104 b .
105endfunc plat_secondary_cold_boot_setup
106
107 /* -----------------------------------------------------
108 * unsigned int plat_is_my_cpu_primary (void);
109 *
110 * Find out whether the current cpu is the primary cpu.
111 * -----------------------------------------------------
112 */
113func plat_is_my_cpu_primary
114 ldcopr r0, MPIDR
115 ldr r1, =(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
116 and r0, r1
Yann Gautier3f9c9782019-02-14 11:13:39 +0100117 cmp r0, #STM32MP_PRIMARY_CPU
Yann Gautier4353bb22018-07-16 10:54:09 +0200118 moveq r0, #1
119 movne r0, #0
120 bx lr
121endfunc plat_is_my_cpu_primary
122
123 /* -------------------------------------------
124 * int plat_stm32mp1_get_core_pos(int mpidr);
125 *
126 * Return CorePos = (ClusterId * 4) + CoreId
127 * -------------------------------------------
128 */
129func plat_stm32mp1_get_core_pos
130 and r1, r0, #MPIDR_CPU_MASK
131 and r0, r0, #MPIDR_CLUSTER_MASK
132 add r0, r1, r0, LSR #6
133 bx lr
134endfunc plat_stm32mp1_get_core_pos
135
136 /* ------------------------------------
137 * unsigned int plat_my_core_pos(void)
138 * ------------------------------------
139 */
140func plat_my_core_pos
141 ldcopr r0, MPIDR
142 b plat_stm32mp1_get_core_pos
143endfunc plat_my_core_pos
Yann Gautier278c34d2018-07-05 16:48:16 +0200144
145 /* ---------------------------------------------
146 * int plat_crash_console_init(void)
147 *
148 * Initialize the crash console without a C Runtime stack.
149 * ---------------------------------------------
150 */
151func plat_crash_console_init
Yann Gautier1fc21302019-01-17 19:17:47 +0100152 /* Enable GPIOs for UART TX */
153 ldr r1, =(RCC_BASE + DEBUG_UART_TX_GPIO_BANK_CLK_REG)
Yann Gautier278c34d2018-07-05 16:48:16 +0200154 ldr r2, [r1]
Yann Gautier1fc21302019-01-17 19:17:47 +0100155 /* Configure GPIO */
156 orr r2, r2, #DEBUG_UART_TX_GPIO_BANK_CLK_EN
Yann Gautier278c34d2018-07-05 16:48:16 +0200157 str r2, [r1]
Yann Gautier1fc21302019-01-17 19:17:47 +0100158 ldr r1, =DEBUG_UART_TX_GPIO_BANK_ADDRESS
Yann Gautier278c34d2018-07-05 16:48:16 +0200159 /* Set GPIO mode alternate */
160 ldr r2, [r1, #GPIO_MODE_OFFSET]
161 bic r2, r2, #(GPIO_MODE_MASK << GPIO_TX_SHIFT)
162 orr r2, r2, #(GPIO_MODE_ALTERNATE << GPIO_TX_SHIFT)
163 str r2, [r1, #GPIO_MODE_OFFSET]
164 /* Set GPIO speed low */
165 ldr r2, [r1, #GPIO_SPEED_OFFSET]
166 bic r2, r2, #(GPIO_SPEED_MASK << GPIO_TX_SHIFT)
167 str r2, [r1, #GPIO_SPEED_OFFSET]
168 /* Set no-pull */
169 ldr r2, [r1, #GPIO_PUPD_OFFSET]
170 bic r2, r2, #(GPIO_PULL_MASK << GPIO_TX_SHIFT)
171 str r2, [r1, #GPIO_PUPD_OFFSET]
Yann Gautier1fc21302019-01-17 19:17:47 +0100172 /* Set alternate */
Yann Gautier278c34d2018-07-05 16:48:16 +0200173 ldr r2, [r1, #GPIO_AFRH_OFFSET]
174 bic r2, r2, #(GPIO_ALTERNATE_MASK << GPIO_TX_ALT_SHIFT)
Yann Gautier1fc21302019-01-17 19:17:47 +0100175 orr r2, r2, #(DEBUG_UART_TX_GPIO_ALTERNATE << GPIO_TX_ALT_SHIFT)
Yann Gautier278c34d2018-07-05 16:48:16 +0200176 str r2, [r1, #GPIO_AFRH_OFFSET]
Yann Gautier1fc21302019-01-17 19:17:47 +0100177 /* Enable UART clock, with its source */
178 ldr r1, =(RCC_BASE + DEBUG_UART_TX_CLKSRC_REG)
179 mov r2, #DEBUG_UART_TX_CLKSRC
Yann Gautier278c34d2018-07-05 16:48:16 +0200180 str r2, [r1]
Yann Gautier1fc21302019-01-17 19:17:47 +0100181 ldr r1, =(RCC_BASE + DEBUG_UART_TX_EN_REG)
Yann Gautier278c34d2018-07-05 16:48:16 +0200182 ldr r2, [r1]
Yann Gautier1fc21302019-01-17 19:17:47 +0100183 orr r2, r2, #DEBUG_UART_TX_EN
Yann Gautier278c34d2018-07-05 16:48:16 +0200184 str r2, [r1]
185
Yann Gautier3f9c9782019-02-14 11:13:39 +0100186 ldr r0, =STM32MP_DEBUG_USART_BASE
187 ldr r1, =STM32MP_DEBUG_USART_CLK_FRQ
188 ldr r2, =STM32MP_UART_BAUDRATE
Yann Gautiercce37d42018-11-14 18:46:15 +0100189 b console_stm32_core_init
Yann Gautier278c34d2018-07-05 16:48:16 +0200190endfunc plat_crash_console_init
191
192 /* ---------------------------------------------
193 * int plat_crash_console_flush(void)
194 *
195 * Flush the crash console without a C Runtime stack.
196 * ---------------------------------------------
197 */
198func plat_crash_console_flush
Yann Gautier3f9c9782019-02-14 11:13:39 +0100199 ldr r1, =STM32MP_DEBUG_USART_BASE
Yann Gautiercce37d42018-11-14 18:46:15 +0100200 b console_stm32_core_flush
Yann Gautier278c34d2018-07-05 16:48:16 +0200201endfunc plat_crash_console_flush
202
203 /* ---------------------------------------------
204 * int plat_crash_console_putc(int c)
205 *
206 * Print a character on the crash console without a C Runtime stack.
207 * Clobber list : r1 - r3
208 *
209 * In case of bootloading through uart, we keep console crash as this.
210 * Characters could be sent to the programmer, but will be ignored.
211 * No specific code in that case.
212 * ---------------------------------------------
213 */
214func plat_crash_console_putc
Yann Gautier3f9c9782019-02-14 11:13:39 +0100215 ldr r1, =STM32MP_DEBUG_USART_BASE
Yann Gautiercce37d42018-11-14 18:46:15 +0100216 b console_stm32_core_putc
Yann Gautier278c34d2018-07-05 16:48:16 +0200217endfunc plat_crash_console_putc
Yann Gautiera9eda772020-09-15 12:24:46 +0200218
219#if DEBUG
220.section .rodata.rev_err_str, "aS"
221abort_str:
222 .asciz "\nAbort at: 0x"
223undefined_str:
224 .asciz "\nUndefined instruction at: 0x"
225exception_start_str:
226 .asciz "\nException mode=0x"
227exception_end_str:
228 .asciz " at: 0x"
229end_error_str:
230 .asciz "\n\r"
231#endif