Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 2a4fe4f | 2018-02-01 18:42:24 +0900 | [diff] [blame] | 2 | * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 8 | #include <asm_macros.S> |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 9 | #include <console.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 11 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 12 | .weak plat_report_exception |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 13 | .weak plat_crash_console_init |
| 14 | .weak plat_crash_console_putc |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 15 | .weak plat_crash_console_flush |
Soby Mathew | f1785fd | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 16 | .weak plat_reset_handler |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 17 | .weak plat_disable_acp |
Juan Castillo | d1413b2 | 2015-10-05 16:59:38 +0100 | [diff] [blame] | 18 | .weak bl1_plat_prepare_exit |
Antonio Nino Diaz | 1f21bcf | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 19 | .weak plat_panic_handler |
Jeenu Viswambharan | e834ee1 | 2018-04-27 15:17:03 +0100 | [diff] [blame] | 20 | .weak bl31_plat_enable_mmu |
| 21 | .weak bl32_plat_enable_mmu |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 22 | |
Jeenu Viswambharan | 9d4c9c1 | 2018-05-17 09:52:36 +0100 | [diff] [blame] | 23 | .weak plat_handle_uncontainable_ea |
Jeenu Viswambharan | 93bc4bd | 2018-05-17 11:24:01 +0100 | [diff] [blame] | 24 | .weak plat_handle_double_fault |
Jeenu Viswambharan | 911fcc9 | 2018-07-06 16:50:06 +0100 | [diff] [blame] | 25 | .weak plat_handle_el3_ea |
Jeenu Viswambharan | 9d4c9c1 | 2018-05-17 09:52:36 +0100 | [diff] [blame] | 26 | |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 27 | #if !ENABLE_PLAT_COMPAT |
| 28 | .globl platform_get_core_pos |
| 29 | |
| 30 | #define MPIDR_RES_BIT_MASK 0xff000000 |
| 31 | |
| 32 | /* ------------------------------------------------------------------ |
| 33 | * int platform_get_core_pos(int mpidr) |
| 34 | * Returns the CPU index of the CPU specified by mpidr. This is |
| 35 | * defined when platform compatibility is disabled to enable Trusted |
| 36 | * Firmware components like SPD using the old platform API to work. |
| 37 | * This API is deprecated and it assumes that the mpidr specified is |
| 38 | * that of a valid and present CPU. Instead, plat_my_core_pos() |
| 39 | * should be used for CPU index of the current CPU and |
| 40 | * plat_core_pos_by_mpidr() should be used for CPU index of a |
| 41 | * CPU specified by its mpidr. |
| 42 | * ------------------------------------------------------------------ |
| 43 | */ |
| 44 | func_deprecated platform_get_core_pos |
| 45 | bic x0, x0, #MPIDR_RES_BIT_MASK |
| 46 | mrs x1, mpidr_el1 |
| 47 | bic x1, x1, #MPIDR_RES_BIT_MASK |
| 48 | cmp x0, x1 |
| 49 | beq plat_my_core_pos |
| 50 | b platform_core_pos_helper |
| 51 | endfunc_deprecated platform_get_core_pos |
| 52 | #endif |
| 53 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 54 | /* ----------------------------------------------------- |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 55 | * Placeholder function which should be redefined by |
| 56 | * each platform. |
| 57 | * ----------------------------------------------------- |
| 58 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 59 | func plat_report_exception |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 60 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 61 | endfunc plat_report_exception |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 62 | |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 63 | #if MULTI_CONSOLE_API |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 64 | /* ----------------------------------------------------- |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 65 | * int plat_crash_console_init(void) |
| 66 | * Use normal console by default. Switch it to crash |
| 67 | * mode so serial consoles become active again. |
| 68 | * NOTE: This default implementation will only work for |
| 69 | * crashes that occur after a normal console (marked |
| 70 | * valid for the crash state) has been registered with |
| 71 | * the console framework. To debug crashes that occur |
| 72 | * earlier, the platform has to override these functions |
| 73 | * with an implementation that initializes a console |
| 74 | * driver with hardcoded parameters. See |
| 75 | * docs/porting-guide.rst for more information. |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 76 | * ----------------------------------------------------- |
| 77 | */ |
| 78 | func plat_crash_console_init |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 79 | #if defined(IMAGE_BL1) |
| 80 | /* |
| 81 | * BL1 code can possibly crash so early that the data segment is not yet |
| 82 | * accessible. Don't risk undefined behavior by trying to run the normal |
| 83 | * console framework. Platforms that want to debug BL1 will need to |
| 84 | * override this with custom functions that can run from registers only. |
| 85 | */ |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 86 | mov x0, #0 |
| 87 | ret |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 88 | #else /* IMAGE_BL1 */ |
| 89 | mov x3, x30 |
| 90 | mov x0, #CONSOLE_FLAG_CRASH |
| 91 | bl console_switch_state |
| 92 | mov x0, #1 |
| 93 | ret x3 |
| 94 | #endif |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 95 | endfunc plat_crash_console_init |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 96 | |
| 97 | /* ----------------------------------------------------- |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 98 | * void plat_crash_console_putc(int character) |
| 99 | * Output through the normal console by default. |
Soby Mathew | 066f713 | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 100 | * ----------------------------------------------------- |
| 101 | */ |
| 102 | func plat_crash_console_putc |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 103 | b console_putc |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 104 | endfunc plat_crash_console_putc |
Soby Mathew | f1785fd | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 105 | |
| 106 | /* ----------------------------------------------------- |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 107 | * void plat_crash_console_flush(void) |
| 108 | * Flush normal console by default. |
| 109 | * ----------------------------------------------------- |
| 110 | */ |
| 111 | func plat_crash_console_flush |
| 112 | b console_flush |
| 113 | endfunc plat_crash_console_flush |
| 114 | |
| 115 | #else /* MULTI_CONSOLE_API */ |
| 116 | |
| 117 | /* ----------------------------------------------------- |
| 118 | * In the old API these are all no-op stubs that need to |
| 119 | * be overridden by the platform to be useful. |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 120 | * ----------------------------------------------------- |
| 121 | */ |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 122 | func plat_crash_console_init |
| 123 | mov x0, #0 |
| 124 | ret |
| 125 | endfunc plat_crash_console_init |
| 126 | |
| 127 | func plat_crash_console_putc |
| 128 | ret |
| 129 | endfunc plat_crash_console_putc |
| 130 | |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 131 | func plat_crash_console_flush |
| 132 | ret |
| 133 | endfunc plat_crash_console_flush |
Julius Werner | aae9bb1 | 2017-09-18 16:49:48 -0700 | [diff] [blame] | 134 | #endif |
Antonio Nino Diaz | d3ec543 | 2017-02-17 17:11:27 +0000 | [diff] [blame] | 135 | |
| 136 | /* ----------------------------------------------------- |
| 137 | * Placeholder function which should be redefined by |
Masahiro Yamada | 4c165ca | 2016-09-24 18:07:46 +0900 | [diff] [blame] | 138 | * each platform. This function should preserve x19 - x29. |
Soby Mathew | f1785fd | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 139 | * ----------------------------------------------------- |
| 140 | */ |
| 141 | func plat_reset_handler |
| 142 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 143 | endfunc plat_reset_handler |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 144 | |
| 145 | /* ----------------------------------------------------- |
| 146 | * Placeholder function which should be redefined by |
| 147 | * each platform. This function is allowed to use |
| 148 | * registers x0 - x17. |
| 149 | * ----------------------------------------------------- |
| 150 | */ |
| 151 | func plat_disable_acp |
| 152 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 153 | endfunc plat_disable_acp |
Juan Castillo | d1413b2 | 2015-10-05 16:59:38 +0100 | [diff] [blame] | 154 | |
| 155 | /* ----------------------------------------------------- |
Sandrine Bailleux | 87322b3 | 2015-11-10 15:01:57 +0000 | [diff] [blame] | 156 | * void bl1_plat_prepare_exit(entry_point_info_t *ep_info); |
Juan Castillo | d1413b2 | 2015-10-05 16:59:38 +0100 | [diff] [blame] | 157 | * Called before exiting BL1. Default: do nothing |
| 158 | * ----------------------------------------------------- |
| 159 | */ |
| 160 | func bl1_plat_prepare_exit |
| 161 | ret |
| 162 | endfunc bl1_plat_prepare_exit |
Juan Castillo | 26ae583 | 2015-09-25 15:41:14 +0100 | [diff] [blame] | 163 | |
| 164 | /* ----------------------------------------------------- |
Antonio Nino Diaz | 1f21bcf | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 165 | * void plat_panic_handler(void) __dead2; |
| 166 | * Endless loop by default. |
| 167 | * ----------------------------------------------------- |
| 168 | */ |
| 169 | func plat_panic_handler |
Sandrine Bailleux | 628198b | 2016-08-18 09:24:40 +0100 | [diff] [blame] | 170 | wfi |
Antonio Nino Diaz | 1f21bcf | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 171 | b plat_panic_handler |
| 172 | endfunc plat_panic_handler |
Jeenu Viswambharan | e834ee1 | 2018-04-27 15:17:03 +0100 | [diff] [blame] | 173 | |
| 174 | /* ----------------------------------------------------- |
| 175 | * void bl31_plat_enable_mmu(uint32_t flags); |
| 176 | * |
| 177 | * Enable MMU in BL31. |
| 178 | * ----------------------------------------------------- |
| 179 | */ |
| 180 | func bl31_plat_enable_mmu |
| 181 | b enable_mmu_direct_el3 |
| 182 | endfunc bl31_plat_enable_mmu |
| 183 | |
| 184 | /* ----------------------------------------------------- |
| 185 | * void bl32_plat_enable_mmu(uint32_t flags); |
| 186 | * |
| 187 | * Enable MMU in BL32. |
| 188 | * ----------------------------------------------------- |
| 189 | */ |
| 190 | func bl32_plat_enable_mmu |
| 191 | b enable_mmu_direct_el1 |
| 192 | endfunc bl32_plat_enable_mmu |
Jeenu Viswambharan | 9d4c9c1 | 2018-05-17 09:52:36 +0100 | [diff] [blame] | 193 | |
| 194 | |
| 195 | /* ----------------------------------------------------- |
| 196 | * Platform handler for Uncontainable External Abort. |
| 197 | * |
| 198 | * x0: EA reason |
| 199 | * x1: EA syndrome |
| 200 | * ----------------------------------------------------- |
| 201 | */ |
| 202 | func plat_handle_uncontainable_ea |
| 203 | b report_unhandled_exception |
| 204 | endfunc plat_handle_uncontainable_ea |
Jeenu Viswambharan | 93bc4bd | 2018-05-17 11:24:01 +0100 | [diff] [blame] | 205 | |
| 206 | /* ----------------------------------------------------- |
| 207 | * Platform handler for Double Fault. |
| 208 | * |
| 209 | * x0: EA reason |
| 210 | * x1: EA syndrome |
| 211 | * ----------------------------------------------------- |
| 212 | */ |
| 213 | func plat_handle_double_fault |
| 214 | b report_unhandled_exception |
| 215 | endfunc plat_handle_double_fault |
Jeenu Viswambharan | 911fcc9 | 2018-07-06 16:50:06 +0100 | [diff] [blame] | 216 | |
| 217 | /* ----------------------------------------------------- |
| 218 | * Platform handler for EL3 External Abort. |
| 219 | * ----------------------------------------------------- |
| 220 | */ |
| 221 | func plat_handle_el3_ea |
| 222 | b report_unhandled_exception |
| 223 | endfunc plat_handle_el3_ea |