]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
b26f0cf9 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e4a1d5a7
BS
7\r
8**/\r
9\r
10#include <Library/BaseMemoryLib.h>\r
11#include <Library/DebugLib.h>\r
12#include <Library/PcdLib.h>\r
13#include <Library/MemEncryptSevLib.h>\r
14\r
15#include "QemuFlash.h"\r
16\r
17VOID\r
18QemuFlashBeforeProbe (\r
ac0a286f
MK
19 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
20 IN UINTN FdBlockSize,\r
21 IN UINTN FdBlockCount\r
e4a1d5a7
BS
22 )\r
23{\r
ac0a286f 24 EFI_STATUS Status;\r
e4a1d5a7
BS
25\r
26 ASSERT (FeaturePcdGet (PcdSmmSmramRequire));\r
27\r
28 if (!MemEncryptSevIsEnabled ()) {\r
29 return;\r
30 }\r
31\r
32 //\r
33 // When SEV is enabled, AmdSevDxe runs early in DXE phase and clears the\r
34 // C-bit from the NonExistent entry -- which is later split and accommodate\r
35 // the flash MMIO but the driver runs in non SMM context hence it cleared the\r
36 // flash ranges from non SMM page table. When SMM is enabled, the flash\r
37 // services are accessed from the SMM mode hence we explicitly clear the\r
38 // C-bit on flash ranges from SMM page table.\r
39 //\r
40\r
8ee4e52b 41 Status = MemEncryptSevClearMmioPageEncMask (\r
e4a1d5a7
BS
42 0,\r
43 BaseAddress,\r
8ee4e52b 44 EFI_SIZE_TO_PAGES (FdBlockSize * FdBlockCount)\r
e4a1d5a7
BS
45 );\r
46 ASSERT_EFI_ERROR (Status);\r
47}\r
437eb3f7
TL
48\r
49/**\r
50 Write to QEMU Flash\r
51\r
52 @param[in] Ptr Pointer to the location to write.\r
53 @param[in] Value The value to write.\r
54\r
55**/\r
56VOID\r
57QemuFlashPtrWrite (\r
ac0a286f
MK
58 IN volatile UINT8 *Ptr,\r
59 IN UINT8 Value\r
437eb3f7
TL
60 )\r
61{\r
62 *Ptr = Value;\r
63}\r