]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Clear C-bit when SEV is active
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / QemuFlashSmm.c
CommitLineData
e4a1d5a7
BS
1/** @file\r
2 Define the module hooks used while probing the QEMU flash device.\r
3\r
4 Copyright (C) 2018, Advanced Micro Devices. All rights reserved.\r
5\r
6 This program and the accompanying materials are licensed and made available\r
7 under the terms and conditions of the BSD License which accompanies this\r
8 distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/PcdLib.h>\r
19#include <Library/MemEncryptSevLib.h>\r
20\r
21#include "QemuFlash.h"\r
22\r
23VOID\r
24QemuFlashBeforeProbe (\r
25 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
26 IN UINTN FdBlockSize,\r
27 IN UINTN FdBlockCount\r
28 )\r
29{\r
30 EFI_STATUS Status;\r
31\r
32 ASSERT (FeaturePcdGet (PcdSmmSmramRequire));\r
33\r
34 if (!MemEncryptSevIsEnabled ()) {\r
35 return;\r
36 }\r
37\r
38 //\r
39 // When SEV is enabled, AmdSevDxe runs early in DXE phase and clears the\r
40 // C-bit from the NonExistent entry -- which is later split and accommodate\r
41 // the flash MMIO but the driver runs in non SMM context hence it cleared the\r
42 // flash ranges from non SMM page table. When SMM is enabled, the flash\r
43 // services are accessed from the SMM mode hence we explicitly clear the\r
44 // C-bit on flash ranges from SMM page table.\r
45 //\r
46\r
47 Status = MemEncryptSevClearPageEncMask (\r
48 0,\r
49 BaseAddress,\r
50 EFI_SIZE_TO_PAGES (FdBlockSize * FdBlockCount),\r
51 FALSE\r
52 );\r
53 ASSERT_EFI_ERROR (Status);\r
54}\r