Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 1 | /* |
Jit Loon Lim | 86f6fb3 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2023, ARM Limited and Contributors. All rights reserved. |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | #include <cpu_macros.S> |
| 10 | #include <platform_def.h> |
Hadi Asyrafi | 0563a85 | 2019-10-22 12:59:32 +0800 | [diff] [blame] | 11 | #include <el3_common_macros.S> |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 12 | |
| 13 | .globl plat_secondary_cold_boot_setup |
| 14 | .globl platform_is_primary_cpu |
| 15 | .globl plat_is_my_cpu_primary |
| 16 | .globl plat_my_core_pos |
| 17 | .globl plat_crash_console_init |
| 18 | .globl plat_crash_console_putc |
| 19 | .globl plat_crash_console_flush |
| 20 | .globl platform_mem_init |
Hadi Asyrafi | 0563a85 | 2019-10-22 12:59:32 +0800 | [diff] [blame] | 21 | .globl plat_secondary_cpus_bl31_entry |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 22 | |
| 23 | .globl plat_get_my_entrypoint |
| 24 | |
| 25 | /* ----------------------------------------------------- |
| 26 | * void plat_secondary_cold_boot_setup (void); |
| 27 | * |
| 28 | * This function performs any platform specific actions |
| 29 | * needed for a secondary cpu after a cold reset e.g |
| 30 | * mark the cpu's presence, mechanism to place it in a |
| 31 | * holding pen etc. |
| 32 | * ----------------------------------------------------- |
| 33 | */ |
| 34 | func plat_secondary_cold_boot_setup |
| 35 | /* Wait until the it gets reset signal from rstmgr gets populated */ |
| 36 | poll_mailbox: |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 37 | #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 |
| 38 | mov_imm x0, PLAT_SEC_ENTRY |
| 39 | cbz x0, poll_mailbox |
| 40 | br x0 |
| 41 | #else |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 42 | wfi |
Hadi Asyrafi | 309ac01 | 2019-08-01 14:48:39 +0800 | [diff] [blame] | 43 | mov_imm x0, PLAT_SEC_ENTRY |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 44 | ldr x1, [x0] |
| 45 | mov_imm x2, PLAT_CPUID_RELEASE |
| 46 | ldr x3, [x2] |
| 47 | mrs x4, mpidr_el1 |
| 48 | and x4, x4, #0xff |
| 49 | cmp x3, x4 |
| 50 | b.ne poll_mailbox |
| 51 | br x1 |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 52 | #endif |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 53 | endfunc plat_secondary_cold_boot_setup |
| 54 | |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 55 | #if ((PLATFORM_MODEL == PLAT_SOCFPGA_STRATIX10) || \ |
| 56 | (PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX) || \ |
| 57 | (PLATFORM_MODEL == PLAT_SOCFPGA_N5X)) |
| 58 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 59 | func platform_is_primary_cpu |
| 60 | and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK) |
| 61 | cmp x0, #PLAT_PRIMARY_CPU |
| 62 | cset x0, eq |
| 63 | ret |
| 64 | endfunc platform_is_primary_cpu |
| 65 | |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 66 | #else |
| 67 | |
| 68 | func platform_is_primary_cpu |
| 69 | and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK) |
| 70 | cmp x0, #(PLAT_PRIMARY_CPU_A76) |
| 71 | b.eq primary_cpu |
| 72 | cmp x0, #(PLAT_PRIMARY_CPU_A55) |
| 73 | b.eq primary_cpu |
| 74 | primary_cpu: |
| 75 | cset x0, eq |
| 76 | ret |
| 77 | endfunc platform_is_primary_cpu |
| 78 | |
| 79 | #endif |
| 80 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 81 | func plat_is_my_cpu_primary |
| 82 | mrs x0, mpidr_el1 |
| 83 | b platform_is_primary_cpu |
| 84 | endfunc plat_is_my_cpu_primary |
| 85 | |
| 86 | func plat_my_core_pos |
| 87 | mrs x0, mpidr_el1 |
| 88 | and x1, x0, #MPIDR_CPU_MASK |
| 89 | and x0, x0, #MPIDR_CLUSTER_MASK |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 90 | #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 |
| 91 | add x0, x1, x0, LSR #8 |
| 92 | #else |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 93 | add x0, x1, x0, LSR #6 |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 94 | #endif |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 95 | ret |
| 96 | endfunc plat_my_core_pos |
| 97 | |
Hadi Asyrafi | 5fae68f | 2019-10-22 14:23:57 +0800 | [diff] [blame] | 98 | func warm_reset_req |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 99 | #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 |
| 100 | bl plat_is_my_cpu_primary |
| 101 | cbnz x0, warm_reset |
| 102 | warm_reset: |
| 103 | mov_imm x1, PLAT_SEC_ENTRY |
| 104 | str xzr, [x1] |
| 105 | mrs x1, rmr_el3 |
| 106 | orr x1, x1, #0x02 |
| 107 | msr rmr_el3, x1 |
| 108 | isb |
| 109 | dsb sy |
| 110 | #else |
Hadi Asyrafi | 5fae68f | 2019-10-22 14:23:57 +0800 | [diff] [blame] | 111 | str xzr, [x4] |
| 112 | bl plat_is_my_cpu_primary |
| 113 | cbz x0, cpu_in_wfi |
| 114 | mov_imm x1, PLAT_SEC_ENTRY |
| 115 | str xzr, [x1] |
| 116 | mrs x1, rmr_el3 |
| 117 | orr x1, x1, #0x02 |
| 118 | msr rmr_el3, x1 |
| 119 | isb |
| 120 | dsb sy |
| 121 | cpu_in_wfi: |
| 122 | wfi |
| 123 | b cpu_in_wfi |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 124 | #endif |
Hadi Asyrafi | 5fae68f | 2019-10-22 14:23:57 +0800 | [diff] [blame] | 125 | endfunc warm_reset_req |
| 126 | |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 127 | /* TODO: Zephyr warm reset test */ |
| 128 | #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 129 | func plat_get_my_entrypoint |
Hadi Asyrafi | 5fae68f | 2019-10-22 14:23:57 +0800 | [diff] [blame] | 130 | ldr x4, =L2_RESET_DONE_REG |
| 131 | ldr x5, [x4] |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 132 | ldr x1, =PLAT_L2_RESET_REQ |
| 133 | cmp x1, x5 |
| 134 | b.eq zephyr_reset_req |
| 135 | mov_imm x1, PLAT_SEC_ENTRY |
| 136 | ldr x0, [x1] |
| 137 | ret |
| 138 | zephyr_reset_req: |
| 139 | ldr x0, =0x00 |
| 140 | ret |
| 141 | endfunc plat_get_my_entrypoint |
| 142 | #else |
| 143 | func plat_get_my_entrypoint |
| 144 | ldr x4, =L2_RESET_DONE_REG |
| 145 | ldr x5, [x4] |
Hadi Asyrafi | 5fae68f | 2019-10-22 14:23:57 +0800 | [diff] [blame] | 146 | ldr x1, =L2_RESET_DONE_STATUS |
| 147 | cmp x1, x5 |
| 148 | b.eq warm_reset_req |
Hadi Asyrafi | 309ac01 | 2019-08-01 14:48:39 +0800 | [diff] [blame] | 149 | mov_imm x1, PLAT_SEC_ENTRY |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 150 | ldr x0, [x1] |
| 151 | ret |
| 152 | endfunc plat_get_my_entrypoint |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 153 | #endif |
Hadi Asyrafi | 5fae68f | 2019-10-22 14:23:57 +0800 | [diff] [blame] | 154 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 155 | /* --------------------------------------------- |
| 156 | * int plat_crash_console_init(void) |
| 157 | * Function to initialize the crash console |
| 158 | * without a C Runtime to print crash report. |
| 159 | * Clobber list : x0, x1, x2 |
| 160 | * --------------------------------------------- |
| 161 | */ |
| 162 | func plat_crash_console_init |
Boon Khai Ng | b19ac61 | 2021-08-06 01:16:46 +0800 | [diff] [blame] | 163 | mov_imm x0, CRASH_CONSOLE_BASE |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 164 | mov_imm x1, PLAT_UART_CLOCK |
| 165 | mov_imm x2, PLAT_BAUDRATE |
| 166 | b console_16550_core_init |
| 167 | endfunc plat_crash_console_init |
| 168 | |
| 169 | /* --------------------------------------------- |
| 170 | * int plat_crash_console_putc(void) |
| 171 | * Function to print a character on the crash |
| 172 | * console without a C Runtime. |
| 173 | * Clobber list : x1, x2 |
| 174 | * --------------------------------------------- |
| 175 | */ |
| 176 | func plat_crash_console_putc |
Boon Khai Ng | b19ac61 | 2021-08-06 01:16:46 +0800 | [diff] [blame] | 177 | mov_imm x1, CRASH_CONSOLE_BASE |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 178 | b console_16550_core_putc |
| 179 | endfunc plat_crash_console_putc |
| 180 | |
| 181 | func plat_crash_console_flush |
| 182 | mov_imm x0, CRASH_CONSOLE_BASE |
| 183 | b console_16550_core_flush |
| 184 | endfunc plat_crash_console_flush |
| 185 | |
| 186 | |
| 187 | /* -------------------------------------------------------- |
| 188 | * void platform_mem_init (void); |
| 189 | * |
| 190 | * Any memory init, relocation to be done before the |
| 191 | * platform boots. Called very early in the boot process. |
| 192 | * -------------------------------------------------------- |
| 193 | */ |
| 194 | func platform_mem_init |
| 195 | mov x0, #0 |
| 196 | ret |
| 197 | endfunc platform_mem_init |
Hadi Asyrafi | 0563a85 | 2019-10-22 12:59:32 +0800 | [diff] [blame] | 198 | |
Jit Loon Lim | 4c249f1 | 2023-05-17 12:26:11 +0800 | [diff] [blame] | 199 | /* -------------------------------------------------------- |
| 200 | * macro plat_secondary_cpus_bl31_entry; |
| 201 | * |
| 202 | * el3_entrypoint_common init param configuration. |
| 203 | * Called very early in the secondary cores boot process. |
| 204 | * -------------------------------------------------------- |
| 205 | */ |
Hadi Asyrafi | 0563a85 | 2019-10-22 12:59:32 +0800 | [diff] [blame] | 206 | func plat_secondary_cpus_bl31_entry |
| 207 | el3_entrypoint_common \ |
| 208 | _init_sctlr=0 \ |
| 209 | _warm_boot_mailbox=!PROGRAMMABLE_RESET_ADDRESS \ |
| 210 | _secondary_cold_boot=!COLD_BOOT_SINGLE_CPU \ |
| 211 | _init_memory=1 \ |
| 212 | _init_c_runtime=1 \ |
| 213 | _exception_vectors=runtime_exceptions \ |
| 214 | _pie_fixup_size=BL31_LIMIT - BL31_BASE |
| 215 | endfunc plat_secondary_cpus_bl31_entry |