#include <Library/DebugLib.h>\r
#include <Library/DevicePathLib.h>\r
#include <Library/DxeServicesTableLib.h>\r
+#include <Library/MemEncryptSevLib.h>\r
#include <Library/PcdLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/UefiRuntimeLib.h>\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
+ //\r
+ // When SEV is active, AmdSevDxe mapped the BaseAddress with C=0 but\r
+ // SetMemorySpaceAttributes() remaps the range with C=1. Let's restore\r
+ // the mapping so that both guest and hyervisor can access the flash\r
+ // memory range.\r
+ //\r
+ if (MemEncryptSevIsEnabled ()) {\r
+ Status = MemEncryptSevClearPageEncMask (\r
+ 0,\r
+ BaseAddress,\r
+ EFI_SIZE_TO_PAGES (Length),\r
+ FALSE\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
return Status;\r
}\r