SmmException.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /** @file
  2. CPU exception handler library implementation for SMM modules.
  3. Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiSmm.h>
  7. #include "CpuExceptionCommon.h"
  8. CONST UINTN mDoFarReturnFlag = 1;
  9. //
  10. // Spin lock for CPU information display
  11. //
  12. SPIN_LOCK mDisplayMessageSpinLock;
  13. RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
  14. EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
  15. EXCEPTION_HANDLER_DATA mExceptionHandlerData;
  16. /**
  17. Common exception handler.
  18. @param ExceptionType Exception type.
  19. @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
  20. **/
  21. VOID
  22. EFIAPI
  23. CommonExceptionHandler (
  24. IN EFI_EXCEPTION_TYPE ExceptionType,
  25. IN EFI_SYSTEM_CONTEXT SystemContext
  26. )
  27. {
  28. CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
  29. }
  30. /**
  31. Initializes all CPU exceptions entries and provides the default exception handlers.
  32. Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
  33. persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
  34. If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
  35. If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
  36. @param[in] VectorInfo Pointer to reserved vector list.
  37. @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
  38. with default exception handlers.
  39. @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
  40. @retval EFI_UNSUPPORTED This function is not supported.
  41. **/
  42. EFI_STATUS
  43. EFIAPI
  44. InitializeCpuExceptionHandlers (
  45. IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
  46. )
  47. {
  48. mExceptionHandlerData.ReservedVectors = mReservedVectorsData;
  49. mExceptionHandlerData.ExternalInterruptHandler = mExternalInterruptHandlerTable;
  50. InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);
  51. return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData);
  52. }
  53. /**
  54. Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
  55. Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
  56. persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
  57. If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
  58. If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
  59. @param[in] VectorInfo Pointer to reserved vector list.
  60. @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized
  61. with default interrupt/exception handlers.
  62. @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
  63. @retval EFI_UNSUPPORTED This function is not supported.
  64. **/
  65. EFI_STATUS
  66. EFIAPI
  67. InitializeCpuInterruptHandlers (
  68. IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
  69. )
  70. {
  71. return EFI_UNSUPPORTED;
  72. }
  73. /**
  74. Registers a function to be called from the processor interrupt handler.
  75. This function registers and enables the handler specified by InterruptHandler for a processor
  76. interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
  77. handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
  78. The installed handler is called once for each processor interrupt or exception.
  79. NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
  80. InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
  81. @param[in] InterruptType Defines which interrupt or exception to hook.
  82. @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
  83. when a processor interrupt occurs. If this parameter is NULL, then the handler
  84. will be uninstalled.
  85. @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
  86. @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
  87. previously installed.
  88. @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
  89. previously installed.
  90. @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
  91. or this function is not supported.
  92. **/
  93. EFI_STATUS
  94. EFIAPI
  95. RegisterCpuInterruptHandler (
  96. IN EFI_EXCEPTION_TYPE InterruptType,
  97. IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
  98. )
  99. {
  100. return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
  101. }
  102. /**
  103. Initializes all CPU exceptions entries with optional extra initializations.
  104. By default, this method should include all functionalities implemented by
  105. InitializeCpuExceptionHandlers(), plus extra initialization works, if any.
  106. This could be done by calling InitializeCpuExceptionHandlers() directly
  107. in this method besides the extra works.
  108. InitData is optional and its use and content are processor arch dependent.
  109. The typical usage of it is to convey resources which have to be reserved
  110. elsewhere and are necessary for the extra initializations of exception.
  111. @param[in] VectorInfo Pointer to reserved vector list.
  112. @param[in] InitData Pointer to data optional for extra initializations
  113. of exception.
  114. @retval EFI_SUCCESS The exceptions have been successfully
  115. initialized.
  116. @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid
  117. content.
  118. **/
  119. EFI_STATUS
  120. EFIAPI
  121. InitializeCpuExceptionHandlersEx (
  122. IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
  123. IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
  124. )
  125. {
  126. return InitializeCpuExceptionHandlers (VectorInfo);
  127. }