]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/VmgExitLib/VmgExitLib.c
OvmfPkg/VmgExitLib: Implement new VmgExitLib interfaces
[mirror_edk2.git] / OvmfPkg / Library / VmgExitLib / VmgExitLib.c
index 53040cc6f6495c5122ac459cb6a5ff5469e17c1e..21f68b19c94e2ce645b79ed7035d62e4b7056fad 100644 (file)
@@ -157,3 +157,57 @@ VmgDone (
 {\r
 }\r
 \r
+/**\r
+  Marks a field at the specified offset as valid in the GHCB.\r
+\r
+  The ValidBitmap area represents the areas of the GHCB that have been marked\r
+  valid. Set the bit in ValidBitmap for the input offset.\r
+\r
+  @param[in, out] Ghcb    Pointer to the Guest-Hypervisor Communication Block\r
+  @param[in]      Offset  Qword offset in the GHCB to mark valid\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VmgSetOffsetValid (\r
+  IN OUT GHCB                *Ghcb,\r
+  IN     GHCB_REGISTER       Offset\r
+  )\r
+{\r
+  UINT32  OffsetIndex;\r
+  UINT32  OffsetBit;\r
+\r
+  OffsetIndex = Offset / 8;\r
+  OffsetBit   = Offset % 8;\r
+\r
+  Ghcb->SaveArea.ValidBitmap[OffsetIndex] |= (1 << OffsetBit);\r
+}\r
+\r
+/**\r
+  Checks if a specified offset is valid in the GHCB.\r
+\r
+  The ValidBitmap area represents the areas of the GHCB that have been marked\r
+  valid. Return whether the bit in the ValidBitmap is set for the input offset.\r
+\r
+  @param[in]  Ghcb            A pointer to the GHCB\r
+  @param[in]  Offset          Qword offset in the GHCB to mark valid\r
+\r
+  @retval TRUE                Offset is marked valid in the GHCB\r
+  @retval FALSE               Offset is not marked valid in the GHCB\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+VmgIsOffsetValid (\r
+  IN GHCB                    *Ghcb,\r
+  IN GHCB_REGISTER           Offset\r
+  )\r
+{\r
+  UINT32  OffsetIndex;\r
+  UINT32  OffsetBit;\r
+\r
+  OffsetIndex = Offset / 8;\r
+  OffsetBit   = Offset % 8;\r
+\r
+  return ((Ghcb->SaveArea.ValidBitmap[OffsetIndex] & (1 << OffsetBit)) != 0);\r
+}\r