blob: fac1b2075a5311f6a79d5d00bbfc1380128f84da [file] [log] [blame]
Andre Przywara6d471e12019-07-09 11:25:57 +01001/*
2 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
3 *
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#include <cortex_a72.h>
12
Andre Przywara6d471e12019-07-09 11:25:57 +010013 .globl plat_crash_console_flush
14 .globl plat_crash_console_init
15 .globl plat_crash_console_putc
16 .globl platform_mem_init
17 .globl plat_get_my_entrypoint
18 .globl plat_is_my_cpu_primary
19 .globl plat_my_core_pos
20 .globl plat_reset_handler
21 .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, #RPI4_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
Andre Przywara57ccecc2020-03-10 12:33:16 +0000136 mov_imm x0, PLAT_RPI_MINI_UART_BASE
Andre Przywaraeb10a862019-12-12 16:31:11 +0000137 mov x1, xzr
138 mov x2, xzr
Andre Przywara6d471e12019-07-09 11:25:57 +0100139 b console_16550_core_init
140endfunc 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
Andre Przywara57ccecc2020-03-10 12:33:16 +0000150 mov_imm x1, PLAT_RPI_MINI_UART_BASE
Andre Przywara6d471e12019-07-09 11:25:57 +0100151 b console_16550_core_putc
152endfunc 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
Andre Przywara57ccecc2020-03-10 12:33:16 +0000163 mov_imm x0, PLAT_RPI_MINI_UART_BASE
Andre Przywara6d471e12019-07-09 11:25:57 +0100164 b console_16550_core_flush
165endfunc plat_crash_console_flush
166
167 /* ---------------------------------------------
168 * void plat_reset_handler(void);
169 * ---------------------------------------------
170 */
171func plat_reset_handler
172 /* ------------------------------------------------
173 * Set L2 read/write cache latency:
174 * - L2 Data RAM latency: 3 cycles (0b010)
175 * - L2 Data RAM setup: 1 cycle (bit 5)
176 * ------------------------------------------------
177 */
178 mrs x0, CORTEX_A72_L2CTLR_EL1
179 mov x1, #0x22
180 orr x0, x0, x1
181 msr CORTEX_A72_L2CTLR_EL1, x0
182 isb
183
184 ret
185endfunc plat_reset_handler