plat_common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <inttypes.h>
  8. #include <stdint.h>
  9. #include <arch_helpers.h>
  10. #include <common/debug.h>
  11. #include <drivers/console.h>
  12. #if ENABLE_FEAT_RAS
  13. #include <lib/extensions/ras.h>
  14. #endif
  15. #include <lib/xlat_tables/xlat_mmu_helpers.h>
  16. #include <plat/common/platform.h>
  17. /* Pointer and function to register platform function to load alernate images */
  18. const struct plat_try_images_ops *plat_try_img_ops;
  19. void plat_setup_try_img_ops(const struct plat_try_images_ops *plat_try_ops)
  20. {
  21. plat_try_img_ops = plat_try_ops;
  22. }
  23. /*
  24. * The following platform setup functions are weakly defined. They
  25. * provide typical implementations that may be re-used by multiple
  26. * platforms but may also be overridden by a platform if required.
  27. */
  28. #pragma weak bl31_plat_runtime_setup
  29. #if SDEI_SUPPORT
  30. #pragma weak plat_sdei_handle_masked_trigger
  31. #pragma weak plat_sdei_validate_entry_point
  32. #endif
  33. #if FFH_SUPPORT
  34. #pragma weak plat_ea_handler = plat_default_ea_handler
  35. #endif
  36. void bl31_plat_runtime_setup(void)
  37. {
  38. }
  39. /*
  40. * Helper function for platform_get_pos() when platform compatibility is
  41. * disabled. This is to enable SPDs using the older platform API to continue
  42. * to work.
  43. */
  44. unsigned int platform_core_pos_helper(unsigned long mpidr)
  45. {
  46. int idx = plat_core_pos_by_mpidr(mpidr);
  47. assert(idx >= 0);
  48. return idx;
  49. }
  50. #if SDEI_SUPPORT
  51. /*
  52. * Function that handles spurious SDEI interrupts while events are masked.
  53. */
  54. void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr)
  55. {
  56. WARN("Spurious SDEI interrupt %u on masked PE %" PRIx64 "\n", intr, mpidr);
  57. }
  58. /*
  59. * Default Function to validate SDEI entry point, which returns success.
  60. * Platforms may override this with their own validation mechanism.
  61. */
  62. int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode)
  63. {
  64. return 0;
  65. }
  66. #endif
  67. const char *get_el_str(unsigned int el)
  68. {
  69. switch (el) {
  70. case MODE_EL3:
  71. return "EL3";
  72. case MODE_EL2:
  73. return "EL2";
  74. case MODE_EL1:
  75. return "EL1";
  76. case MODE_EL0:
  77. return "EL0";
  78. default:
  79. assert(false);
  80. return NULL;
  81. }
  82. }
  83. #if FFH_SUPPORT
  84. /* Handler for External Aborts from lower EL including RAS errors */
  85. void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
  86. void *handle, uint64_t flags)
  87. {
  88. #if ENABLE_FEAT_RAS
  89. /* Call RAS EA handler */
  90. int handled = ras_ea_handler(ea_reason, syndrome, cookie, handle, flags);
  91. if (handled != 0)
  92. return;
  93. #endif
  94. unsigned int level = (unsigned int)GET_EL(read_spsr_el3());
  95. ERROR_NL();
  96. ERROR("Unhandled External Abort received on 0x%lx from %s\n",
  97. read_mpidr_el1(), get_el_str(level));
  98. ERROR("exception reason=%u syndrome=0x%" PRIx64 "\n", ea_reason, syndrome);
  99. /* We reached here due to a panic from a lower EL and assuming this is the default
  100. * platform registered handler that we could call on a lower EL panic.
  101. */
  102. lower_el_panic();
  103. }
  104. #endif