VOID\r
);\r
\r
+#if defined (MDE_CPU_X64)\r
+//\r
+// The page size for the PVALIDATE instruction\r
+//\r
+typedef enum {\r
+ PvalidatePageSize4K = 0,\r
+ PvalidatePageSize2MB,\r
+} PVALIDATE_PAGE_SIZE;\r
+\r
+//\r
+// PVALIDATE Return Code.\r
+//\r
+#define PVALIDATE_RET_SUCCESS 0\r
+#define PVALIDATE_RET_FAIL_INPUT 1\r
+#define PVALIDATE_RET_SIZE_MISMATCH 6\r
+\r
+//\r
+// The PVALIDATE instruction did not make any changes to the RMP entry.\r
+//\r
+#define PVALIDATE_RET_NO_RMPUPDATE 255\r
+\r
+/**\r
+ Execute a PVALIDATE instruction to validate or to rescinds validation of a guest\r
+ page's RMP entry.\r
+\r
+ The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=1.\r
+\r
+ The function is available on X64.\r
+\r
+ @param[in] PageSize The page size to use.\r
+ @param[in] Validate If TRUE, validate the guest virtual address\r
+ otherwise invalidate the guest virtual address.\r
+ @param[in] Address The guest virtual address.\r
+\r
+ @retval PVALIDATE_RET_SUCCESS The PVALIDATE instruction succeeded, and\r
+ updated the RMP entry.\r
+ @retval PVALIDATE_RET_NO_RMPUPDATE The PVALIDATE instruction succeeded, but\r
+ did not update the RMP entry.\r
+ @return Failure code from the PVALIDATE\r
+ instruction.\r
+**/\r
+UINT32\r
+EFIAPI\r
+AsmPvalidate (\r
+ IN PVALIDATE_PAGE_SIZE PageSize,\r
+ IN BOOLEAN Validate,\r
+ IN PHYSICAL_ADDRESS Address\r
+ );\r
+#endif\r
+\r
\r
#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
///\r
DB 0xF3, 0x48, 0x0F, 0xAE, 0xE8\r
%endmacro\r
\r
+;\r
+; Macro for the PVALIDATE instruction, defined in AMD APM volume 3.\r
+; NASM feature request URL: https://bugzilla.nasm.us/show_bug.cgi?id=3392753\r
+;\r
+%macro PVALIDATE 0\r
+ DB 0xF2, 0x0F, 0x01, 0xFF\r
+%endmacro\r
+\r
; NASM provides built-in macros STRUC and ENDSTRUC for structure definition.\r
; For example, to define a structure called mytype containing a longword,\r
; a word, a byte and a string of bytes, you might code\r
--- /dev/null
+;-----------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2021, AMD. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+;-----------------------------------------------------------------------------\r
+\r
+%include "Nasm.inc"\r
+\r
+ SECTION .text\r
+\r
+;-----------------------------------------------------------------------------\r
+; UINT32\r
+; EFIAPI\r
+; AsmPvalidate (\r
+; IN UINT32 PageSize\r
+; IN UINT32 Validate,\r
+; IN UINT64 Address\r
+; )\r
+;-----------------------------------------------------------------------------\r
+global ASM_PFX(AsmPvalidate)\r
+ASM_PFX(AsmPvalidate):\r
+ mov rax, r8\r
+\r
+ PVALIDATE\r
+\r
+ ; Save the carry flag.\r
+ setc dl\r
+\r
+ ; The PVALIDATE instruction returns the status in rax register.\r
+ cmp rax, 0\r
+ jne PvalidateExit\r
+\r
+ ; Check the carry flag to determine if RMP entry was updated.\r
+ cmp dl, 0\r
+ je PvalidateExit\r
+\r
+ ; Return the PVALIDATE_RET_NO_RMPUPDATE.\r
+ mov rax, 255\r
+\r
+PvalidateExit:\r
+ ret\r