14f6ad66aSAchin Gupta/* 20fc50a86SMasahiro Yamada * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 54f6ad66aSAchin Gupta */ 64f6ad66aSAchin Gupta 74f6ad66aSAchin Gupta#include <arch.h> 80a30cf54SAndrew Thoelke#include <asm_macros.S> 917cd67d2SJulius Werner#include <console.h> 105f0cdb05SDan Handley#include <platform_def.h> 114f6ad66aSAchin Gupta 124f6ad66aSAchin Gupta .weak plat_report_exception 13c67b09bdSSoby Mathew .weak plat_crash_console_init 14c67b09bdSSoby Mathew .weak plat_crash_console_putc 15801cf93cSAntonio Nino Diaz .weak plat_crash_console_flush 1624fb838fSSoby Mathew .weak plat_reset_handler 17add40351SSoby Mathew .weak plat_disable_acp 18e3f67124SJuan Castillo .weak bl1_plat_prepare_exit 191c3ea103SAntonio Nino Diaz .weak plat_panic_handler 2064ee263eSJeenu Viswambharan .weak bl31_plat_enable_mmu 2164ee263eSJeenu Viswambharan .weak bl32_plat_enable_mmu 224f6ad66aSAchin Gupta 23b56dc2a9SJeenu Viswambharan .weak plat_handle_uncontainable_ea 24d5a23af5SJeenu Viswambharan .weak plat_handle_double_fault 25*eaeaa4d0SJeenu Viswambharan .weak plat_handle_el3_ea 26b56dc2a9SJeenu Viswambharan 275c8babcdSSoby Mathew#if !ENABLE_PLAT_COMPAT 285c8babcdSSoby Mathew .globl platform_get_core_pos 295c8babcdSSoby Mathew 305c8babcdSSoby Mathew#define MPIDR_RES_BIT_MASK 0xff000000 315c8babcdSSoby Mathew 325c8babcdSSoby Mathew /* ------------------------------------------------------------------ 335c8babcdSSoby Mathew * int platform_get_core_pos(int mpidr) 345c8babcdSSoby Mathew * Returns the CPU index of the CPU specified by mpidr. This is 355c8babcdSSoby Mathew * defined when platform compatibility is disabled to enable Trusted 365c8babcdSSoby Mathew * Firmware components like SPD using the old platform API to work. 375c8babcdSSoby Mathew * This API is deprecated and it assumes that the mpidr specified is 385c8babcdSSoby Mathew * that of a valid and present CPU. Instead, plat_my_core_pos() 395c8babcdSSoby Mathew * should be used for CPU index of the current CPU and 405c8babcdSSoby Mathew * plat_core_pos_by_mpidr() should be used for CPU index of a 415c8babcdSSoby Mathew * CPU specified by its mpidr. 425c8babcdSSoby Mathew * ------------------------------------------------------------------ 435c8babcdSSoby Mathew */ 445c8babcdSSoby Mathewfunc_deprecated platform_get_core_pos 455c8babcdSSoby Mathew bic x0, x0, #MPIDR_RES_BIT_MASK 465c8babcdSSoby Mathew mrs x1, mpidr_el1 475c8babcdSSoby Mathew bic x1, x1, #MPIDR_RES_BIT_MASK 485c8babcdSSoby Mathew cmp x0, x1 495c8babcdSSoby Mathew beq plat_my_core_pos 505c8babcdSSoby Mathew b platform_core_pos_helper 515c8babcdSSoby Mathewendfunc_deprecated platform_get_core_pos 525c8babcdSSoby Mathew#endif 535c8babcdSSoby Mathew 544f6ad66aSAchin Gupta /* ----------------------------------------------------- 554f6ad66aSAchin Gupta * Placeholder function which should be redefined by 564f6ad66aSAchin Gupta * each platform. 574f6ad66aSAchin Gupta * ----------------------------------------------------- 584f6ad66aSAchin Gupta */ 590a30cf54SAndrew Thoelkefunc plat_report_exception 604f6ad66aSAchin Gupta ret 618b779620SKévin Petitendfunc plat_report_exception 62c67b09bdSSoby Mathew 6317cd67d2SJulius Werner#if MULTI_CONSOLE_API 64c67b09bdSSoby Mathew /* ----------------------------------------------------- 6517cd67d2SJulius Werner * int plat_crash_console_init(void) 6617cd67d2SJulius Werner * Use normal console by default. Switch it to crash 6717cd67d2SJulius Werner * mode so serial consoles become active again. 6817cd67d2SJulius Werner * NOTE: This default implementation will only work for 6917cd67d2SJulius Werner * crashes that occur after a normal console (marked 7017cd67d2SJulius Werner * valid for the crash state) has been registered with 7117cd67d2SJulius Werner * the console framework. To debug crashes that occur 7217cd67d2SJulius Werner * earlier, the platform has to override these functions 7317cd67d2SJulius Werner * with an implementation that initializes a console 7417cd67d2SJulius Werner * driver with hardcoded parameters. See 7517cd67d2SJulius Werner * docs/porting-guide.rst for more information. 7617cd67d2SJulius Werner * ----------------------------------------------------- 7717cd67d2SJulius Werner */ 7817cd67d2SJulius Wernerfunc plat_crash_console_init 7917cd67d2SJulius Werner#if defined(IMAGE_BL1) 8017cd67d2SJulius Werner /* 8117cd67d2SJulius Werner * BL1 code can possibly crash so early that the data segment is not yet 8217cd67d2SJulius Werner * accessible. Don't risk undefined behavior by trying to run the normal 8317cd67d2SJulius Werner * console framework. Platforms that want to debug BL1 will need to 8417cd67d2SJulius Werner * override this with custom functions that can run from registers only. 8517cd67d2SJulius Werner */ 8617cd67d2SJulius Werner mov x0, #0 8717cd67d2SJulius Werner ret 8817cd67d2SJulius Werner#else /* IMAGE_BL1 */ 8917cd67d2SJulius Werner mov x3, x30 9017cd67d2SJulius Werner mov x0, #CONSOLE_FLAG_CRASH 9117cd67d2SJulius Werner bl console_switch_state 9217cd67d2SJulius Werner mov x0, #1 9317cd67d2SJulius Werner ret x3 9417cd67d2SJulius Werner#endif 9517cd67d2SJulius Wernerendfunc plat_crash_console_init 9617cd67d2SJulius Werner 9717cd67d2SJulius Werner /* ----------------------------------------------------- 9817cd67d2SJulius Werner * void plat_crash_console_putc(int character) 9917cd67d2SJulius Werner * Output through the normal console by default. 10017cd67d2SJulius Werner * ----------------------------------------------------- 10117cd67d2SJulius Werner */ 10217cd67d2SJulius Wernerfunc plat_crash_console_putc 10317cd67d2SJulius Werner b console_putc 10417cd67d2SJulius Wernerendfunc plat_crash_console_putc 10517cd67d2SJulius Werner 10617cd67d2SJulius Werner /* ----------------------------------------------------- 10717cd67d2SJulius Werner * void plat_crash_console_flush(void) 10817cd67d2SJulius Werner * Flush normal console by default. 10917cd67d2SJulius Werner * ----------------------------------------------------- 11017cd67d2SJulius Werner */ 11117cd67d2SJulius Wernerfunc plat_crash_console_flush 11217cd67d2SJulius Werner b console_flush 11317cd67d2SJulius Wernerendfunc plat_crash_console_flush 11417cd67d2SJulius Werner 11517cd67d2SJulius Werner#else /* MULTI_CONSOLE_API */ 11617cd67d2SJulius Werner 11717cd67d2SJulius Werner /* ----------------------------------------------------- 11817cd67d2SJulius Werner * In the old API these are all no-op stubs that need to 11917cd67d2SJulius Werner * be overridden by the platform to be useful. 120c67b09bdSSoby Mathew * ----------------------------------------------------- 121c67b09bdSSoby Mathew */ 122c67b09bdSSoby Mathewfunc plat_crash_console_init 123c67b09bdSSoby Mathew mov x0, #0 124c67b09bdSSoby Mathew ret 1258b779620SKévin Petitendfunc plat_crash_console_init 126c67b09bdSSoby Mathew 127c67b09bdSSoby Mathewfunc plat_crash_console_putc 128c67b09bdSSoby Mathew ret 1298b779620SKévin Petitendfunc plat_crash_console_putc 13024fb838fSSoby Mathew 131801cf93cSAntonio Nino Diazfunc plat_crash_console_flush 132801cf93cSAntonio Nino Diaz ret 133801cf93cSAntonio Nino Diazendfunc plat_crash_console_flush 13417cd67d2SJulius Werner#endif 135801cf93cSAntonio Nino Diaz 136801cf93cSAntonio Nino Diaz /* ----------------------------------------------------- 137801cf93cSAntonio Nino Diaz * Placeholder function which should be redefined by 138240b3140SMasahiro Yamada * each platform. This function should preserve x19 - x29. 13924fb838fSSoby Mathew * ----------------------------------------------------- 14024fb838fSSoby Mathew */ 14124fb838fSSoby Mathewfunc plat_reset_handler 14224fb838fSSoby Mathew ret 1438b779620SKévin Petitendfunc plat_reset_handler 144add40351SSoby Mathew 145add40351SSoby Mathew /* ----------------------------------------------------- 146add40351SSoby Mathew * Placeholder function which should be redefined by 147add40351SSoby Mathew * each platform. This function is allowed to use 148add40351SSoby Mathew * registers x0 - x17. 149add40351SSoby Mathew * ----------------------------------------------------- 150add40351SSoby Mathew */ 151add40351SSoby Mathewfunc plat_disable_acp 152add40351SSoby Mathew ret 1538b779620SKévin Petitendfunc plat_disable_acp 154e3f67124SJuan Castillo 155e3f67124SJuan Castillo /* ----------------------------------------------------- 156862b5dc2SSandrine Bailleux * void bl1_plat_prepare_exit(entry_point_info_t *ep_info); 157e3f67124SJuan Castillo * Called before exiting BL1. Default: do nothing 158e3f67124SJuan Castillo * ----------------------------------------------------- 159e3f67124SJuan Castillo */ 160e3f67124SJuan Castillofunc bl1_plat_prepare_exit 161e3f67124SJuan Castillo ret 162e3f67124SJuan Castilloendfunc bl1_plat_prepare_exit 16340fc6cd1SJuan Castillo 16440fc6cd1SJuan Castillo /* ----------------------------------------------------- 1651c3ea103SAntonio Nino Diaz * void plat_panic_handler(void) __dead2; 1661c3ea103SAntonio Nino Diaz * Endless loop by default. 1671c3ea103SAntonio Nino Diaz * ----------------------------------------------------- 1681c3ea103SAntonio Nino Diaz */ 1691c3ea103SAntonio Nino Diazfunc plat_panic_handler 1708c9e1af0SSandrine Bailleux wfi 1711c3ea103SAntonio Nino Diaz b plat_panic_handler 1721c3ea103SAntonio Nino Diazendfunc plat_panic_handler 17364ee263eSJeenu Viswambharan 17464ee263eSJeenu Viswambharan /* ----------------------------------------------------- 17564ee263eSJeenu Viswambharan * void bl31_plat_enable_mmu(uint32_t flags); 17664ee263eSJeenu Viswambharan * 17764ee263eSJeenu Viswambharan * Enable MMU in BL31. 17864ee263eSJeenu Viswambharan * ----------------------------------------------------- 17964ee263eSJeenu Viswambharan */ 18064ee263eSJeenu Viswambharanfunc bl31_plat_enable_mmu 18164ee263eSJeenu Viswambharan b enable_mmu_direct_el3 18264ee263eSJeenu Viswambharanendfunc bl31_plat_enable_mmu 18364ee263eSJeenu Viswambharan 18464ee263eSJeenu Viswambharan /* ----------------------------------------------------- 18564ee263eSJeenu Viswambharan * void bl32_plat_enable_mmu(uint32_t flags); 18664ee263eSJeenu Viswambharan * 18764ee263eSJeenu Viswambharan * Enable MMU in BL32. 18864ee263eSJeenu Viswambharan * ----------------------------------------------------- 18964ee263eSJeenu Viswambharan */ 19064ee263eSJeenu Viswambharanfunc bl32_plat_enable_mmu 19164ee263eSJeenu Viswambharan b enable_mmu_direct_el1 19264ee263eSJeenu Viswambharanendfunc bl32_plat_enable_mmu 193b56dc2a9SJeenu Viswambharan 194b56dc2a9SJeenu Viswambharan 195b56dc2a9SJeenu Viswambharan /* ----------------------------------------------------- 196b56dc2a9SJeenu Viswambharan * Platform handler for Uncontainable External Abort. 197b56dc2a9SJeenu Viswambharan * 198b56dc2a9SJeenu Viswambharan * x0: EA reason 199b56dc2a9SJeenu Viswambharan * x1: EA syndrome 200b56dc2a9SJeenu Viswambharan * ----------------------------------------------------- 201b56dc2a9SJeenu Viswambharan */ 202b56dc2a9SJeenu Viswambharanfunc plat_handle_uncontainable_ea 203b56dc2a9SJeenu Viswambharan b report_unhandled_exception 204b56dc2a9SJeenu Viswambharanendfunc plat_handle_uncontainable_ea 205d5a23af5SJeenu Viswambharan 206d5a23af5SJeenu Viswambharan /* ----------------------------------------------------- 207d5a23af5SJeenu Viswambharan * Platform handler for Double Fault. 208d5a23af5SJeenu Viswambharan * 209d5a23af5SJeenu Viswambharan * x0: EA reason 210d5a23af5SJeenu Viswambharan * x1: EA syndrome 211d5a23af5SJeenu Viswambharan * ----------------------------------------------------- 212d5a23af5SJeenu Viswambharan */ 213d5a23af5SJeenu Viswambharanfunc plat_handle_double_fault 214d5a23af5SJeenu Viswambharan b report_unhandled_exception 215d5a23af5SJeenu Viswambharanendfunc plat_handle_double_fault 216*eaeaa4d0SJeenu Viswambharan 217*eaeaa4d0SJeenu Viswambharan /* ----------------------------------------------------- 218*eaeaa4d0SJeenu Viswambharan * Platform handler for EL3 External Abort. 219*eaeaa4d0SJeenu Viswambharan * ----------------------------------------------------- 220*eaeaa4d0SJeenu Viswambharan */ 221*eaeaa4d0SJeenu Viswambharanfunc plat_handle_el3_ea 222*eaeaa4d0SJeenu Viswambharan b report_unhandled_exception 223*eaeaa4d0SJeenu Viswambharanendfunc plat_handle_el3_ea 224