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