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