CcExitLib.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /** @file
  2. Public header file for the CcExitLib.
  3. This library class defines some routines used for below CcExit handler.
  4. - Invoking the VMGEXIT instruction in support of SEV-ES and to handle
  5. #VC exceptions.
  6. - Handle #VE exception in TDX.
  7. Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>
  8. Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
  9. SPDX-License-Identifier: BSD-2-Clause-Patent
  10. **/
  11. #ifndef CC_EXIT_LIB_H_
  12. #define CC_EXIT_LIB_H_
  13. #include <Protocol/DebugSupport.h>
  14. #include <Register/Amd/Ghcb.h>
  15. #define VE_EXCEPTION 20
  16. /**
  17. Perform VMGEXIT.
  18. Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
  19. then handles the return actions.
  20. @param[in, out] Ghcb A pointer to the GHCB
  21. @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode
  22. field of the GHCB.
  23. @param[in] ExitInfo1 VMGEXIT information to be assigned to the
  24. SwExitInfo1 field of the GHCB.
  25. @param[in] ExitInfo2 VMGEXIT information to be assigned to the
  26. SwExitInfo2 field of the GHCB.
  27. @retval 0 VMGEXIT succeeded.
  28. @return Exception number to be propagated, VMGEXIT
  29. processing did not succeed.
  30. **/
  31. UINT64
  32. EFIAPI
  33. VmgExit (
  34. IN OUT GHCB *Ghcb,
  35. IN UINT64 ExitCode,
  36. IN UINT64 ExitInfo1,
  37. IN UINT64 ExitInfo2
  38. );
  39. /**
  40. Perform pre-VMGEXIT initialization/preparation.
  41. Performs the necessary steps in preparation for invoking VMGEXIT. Must be
  42. called before setting any fields within the GHCB.
  43. @param[in, out] Ghcb A pointer to the GHCB
  44. @param[in, out] InterruptState A pointer to hold the current interrupt
  45. state, used for restoring in VmgDone ()
  46. **/
  47. VOID
  48. EFIAPI
  49. VmgInit (
  50. IN OUT GHCB *Ghcb,
  51. IN OUT BOOLEAN *InterruptState
  52. );
  53. /**
  54. Perform post-VMGEXIT cleanup.
  55. Performs the necessary steps to cleanup after invoking VMGEXIT. Must be
  56. called after obtaining needed fields within the GHCB.
  57. @param[in, out] Ghcb A pointer to the GHCB
  58. @param[in] InterruptState An indicator to conditionally (re)enable
  59. interrupts
  60. **/
  61. VOID
  62. EFIAPI
  63. VmgDone (
  64. IN OUT GHCB *Ghcb,
  65. IN BOOLEAN InterruptState
  66. );
  67. /**
  68. Marks a specified offset as valid in the GHCB.
  69. The ValidBitmap area represents the areas of the GHCB that have been marked
  70. valid. Set the bit in ValidBitmap for the input offset.
  71. @param[in, out] Ghcb A pointer to the GHCB
  72. @param[in] Offset Qword offset in the GHCB to mark valid
  73. **/
  74. VOID
  75. EFIAPI
  76. VmgSetOffsetValid (
  77. IN OUT GHCB *Ghcb,
  78. IN GHCB_REGISTER Offset
  79. );
  80. /**
  81. Checks if a specified offset is valid in the GHCB.
  82. The ValidBitmap area represents the areas of the GHCB that have been marked
  83. valid. Return whether the bit in the ValidBitmap is set for the input offset.
  84. @param[in] Ghcb A pointer to the GHCB
  85. @param[in] Offset Qword offset in the GHCB to mark valid
  86. @retval TRUE Offset is marked valid in the GHCB
  87. @retval FALSE Offset is not marked valid in the GHCB
  88. **/
  89. BOOLEAN
  90. EFIAPI
  91. VmgIsOffsetValid (
  92. IN GHCB *Ghcb,
  93. IN GHCB_REGISTER Offset
  94. );
  95. /**
  96. Handle a #VC exception.
  97. Performs the necessary processing to handle a #VC exception.
  98. The base library function returns an error equal to VC_EXCEPTION,
  99. to be propagated to the standard exception handling stack.
  100. @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set
  101. as value to use on error.
  102. @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT
  103. @retval EFI_SUCCESS Exception handled
  104. @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to
  105. propagate provided
  106. @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to
  107. propagate provided
  108. **/
  109. EFI_STATUS
  110. EFIAPI
  111. VmgExitHandleVc (
  112. IN OUT EFI_EXCEPTION_TYPE *ExceptionType,
  113. IN OUT EFI_SYSTEM_CONTEXT SystemContext
  114. );
  115. /**
  116. Handle a #VE exception.
  117. Performs the necessary processing to handle a #VE exception.
  118. The base library function returns an error equal to VE_EXCEPTION,
  119. to be propagated to the standard exception handling stack.
  120. @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set
  121. as value to use on error.
  122. @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT
  123. @retval EFI_SUCCESS Exception handled
  124. @retval EFI_UNSUPPORTED #VE not supported, (new) exception value to
  125. propagate provided
  126. @retval EFI_PROTOCOL_ERROR #VE handling failed, (new) exception value to
  127. propagate provided
  128. **/
  129. EFI_STATUS
  130. EFIAPI
  131. VmTdExitHandleVe (
  132. IN OUT EFI_EXCEPTION_TYPE *ExceptionType,
  133. IN OUT EFI_SYSTEM_CONTEXT SystemContext
  134. );
  135. #endif