blob: 24278bdf6e9880725f402f3d8384ab7401e08127 [file] [log] [blame]
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00001/*
Antonio Nino Diaz1f470022018-03-27 09:39:47 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <assert_macros.S>
10#include <platform_def.h>
11
Andre Przywarabb6ef152019-07-09 11:44:14 +010012#include "../include/rpi_hw.h"
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000013
14 .globl plat_crash_console_flush
15 .globl plat_crash_console_init
16 .globl plat_crash_console_putc
17 .globl platform_mem_init
18 .globl plat_get_my_entrypoint
19 .globl plat_is_my_cpu_primary
20 .globl plat_my_core_pos
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000021 .globl plat_rpi3_calc_core_pos
22 .globl plat_secondary_cold_boot_setup
23
24 /* -----------------------------------------------------
25 * unsigned int plat_my_core_pos(void)
26 *
27 * This function uses the plat_rpi3_calc_core_pos()
28 * definition to get the index of the calling CPU.
29 * -----------------------------------------------------
30 */
31func plat_my_core_pos
32 mrs x0, mpidr_el1
33 b plat_rpi3_calc_core_pos
34endfunc plat_my_core_pos
35
36 /* -----------------------------------------------------
37 * unsigned int plat_rpi3_calc_core_pos(u_register_t mpidr);
38 *
39 * CorePos = (ClusterId * 4) + CoreId
40 * -----------------------------------------------------
41 */
42func plat_rpi3_calc_core_pos
43 and x1, x0, #MPIDR_CPU_MASK
44 and x0, x0, #MPIDR_CLUSTER_MASK
45 add x0, x1, x0, LSR #6
46 ret
47endfunc plat_rpi3_calc_core_pos
48
49 /* -----------------------------------------------------
50 * unsigned int plat_is_my_cpu_primary (void);
51 *
52 * Find out whether the current cpu is the primary
53 * cpu.
54 * -----------------------------------------------------
55 */
56func plat_is_my_cpu_primary
57 mrs x0, mpidr_el1
58 and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
59 cmp x0, #RPI3_PRIMARY_CPU
60 cset w0, eq
61 ret
62endfunc plat_is_my_cpu_primary
63
64 /* -----------------------------------------------------
65 * void plat_secondary_cold_boot_setup (void);
66 *
67 * This function performs any platform specific actions
68 * needed for a secondary cpu after a cold reset e.g
69 * mark the cpu's presence, mechanism to place it in a
70 * holding pen etc.
71 * -----------------------------------------------------
72 */
73func plat_secondary_cold_boot_setup
74 /* Calculate address of our hold entry */
75 bl plat_my_core_pos
76 lsl x0, x0, #3
77 mov_imm x2, PLAT_RPI3_TM_HOLD_BASE
78 add x0, x0, x2
79
80 /*
81 * This code runs way before requesting the warmboot of this core,
82 * so it is possible to clear the mailbox before getting a request
83 * to boot.
84 */
85 mov x1, PLAT_RPI3_TM_HOLD_STATE_WAIT
86 str x1,[x0]
87
88 /* Wait until we have a go */
89poll_mailbox:
90 wfe
91 ldr x1, [x0]
92 cmp x1, PLAT_RPI3_TM_HOLD_STATE_GO
93 bne poll_mailbox
94
95 /* Jump to the provided entrypoint */
96 mov_imm x0, PLAT_RPI3_TM_ENTRYPOINT
97 ldr x1, [x0]
98 br x1
99endfunc plat_secondary_cold_boot_setup
100
101 /* ---------------------------------------------------------------------
102 * uintptr_t plat_get_my_entrypoint (void);
103 *
104 * Main job of this routine is to distinguish between a cold and a warm
105 * boot.
106 *
107 * This functions returns:
108 * - 0 for a cold boot.
109 * - Any other value for a warm boot.
110 * ---------------------------------------------------------------------
111 */
112func plat_get_my_entrypoint
113 /* TODO: support warm boot */
114 mov x0, #0
115 ret
116endfunc plat_get_my_entrypoint
117
118 /* ---------------------------------------------
119 * void platform_mem_init (void);
120 *
121 * No need to carry out any memory initialization.
122 * ---------------------------------------------
123 */
124func platform_mem_init
125 ret
126endfunc platform_mem_init
127
128 /* ---------------------------------------------
129 * int plat_crash_console_init(void)
130 * Function to initialize the crash console
131 * without a C Runtime to print crash report.
132 * Clobber list : x0 - x3
133 * ---------------------------------------------
134 */
135func plat_crash_console_init
136 mov_imm x0, PLAT_RPI3_UART_BASE
137 mov_imm x1, PLAT_RPI3_UART_CLK_IN_HZ
138 mov_imm x2, PLAT_RPI3_UART_BAUDRATE
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100139 b console_16550_core_init
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000140endfunc plat_crash_console_init
141
142 /* ---------------------------------------------
143 * int plat_crash_console_putc(int c)
144 * Function to print a character on the crash
145 * console without a C Runtime.
146 * Clobber list : x1, x2
147 * ---------------------------------------------
148 */
149func plat_crash_console_putc
150 mov_imm x1, PLAT_RPI3_UART_BASE
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100151 b console_16550_core_putc
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000152endfunc plat_crash_console_putc
153
154 /* ---------------------------------------------
155 * int plat_crash_console_flush()
156 * Function to force a write of all buffered
157 * data that hasn't been output.
158 * Out : return -1 on error else return 0.
159 * Clobber list : x0, x1
160 * ---------------------------------------------
161 */
162func plat_crash_console_flush
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100163 mov_imm x0, PLAT_RPI3_UART_BASE
164 b console_16550_core_flush
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000165endfunc plat_crash_console_flush