VmgExitLib.h 4.2 KB

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