]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/AmdSevDxe/AmdSevDxe.c
OvmfPkg/AmdSevDxe: rewrap to 79 characters width
[mirror_edk2.git] / OvmfPkg / AmdSevDxe / AmdSevDxe.c
1 /** @file
2
3 AMD Sev Dxe driver. This driver is dispatched early in DXE, due to being list
4 in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV
5 is enabled.
6
7 Copyright (c) 2017, AMD Inc. All rights reserved.<BR>
8
9 This program and the accompanying materials are licensed and made available
10 under the terms and conditions of the BSD License which accompanies this
11 distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
15 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18
19 #include <PiDxe.h>
20
21 #include <Library/BaseLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/MemoryAllocationLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/DxeServicesTableLib.h>
27 #include <Library/MemEncryptSevLib.h>
28
29 EFI_STATUS
30 EFIAPI
31 AmdSevDxeEntryPoint (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35 {
36 EFI_STATUS Status;
37 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *AllDescMap;
38 UINTN NumEntries;
39 UINTN Index;
40
41 //
42 // Do nothing when SEV is not enabled
43 //
44 if (!MemEncryptSevIsEnabled ()) {
45 return EFI_UNSUPPORTED;
46 }
47
48 //
49 // Iterate through the GCD map and clear the C-bit from MMIO and NonExistent
50 // memory space. The NonExistent memory space will be used for mapping the
51 // MMIO space added later (eg PciRootBridge). By clearing both known MMIO and
52 // NonExistent memory space can gurantee that current and furture MMIO adds
53 // will have C-bit cleared.
54 //
55 Status = gDS->GetMemorySpaceMap (&NumEntries, &AllDescMap);
56 if (!EFI_ERROR (Status)) {
57 for (Index = 0; Index < NumEntries; Index++) {
58 CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc;
59
60 Desc = &AllDescMap[Index];
61 if (Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo ||
62 Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
63 Status = MemEncryptSevClearPageEncMask (
64 0,
65 Desc->BaseAddress,
66 EFI_SIZE_TO_PAGES (Desc->Length),
67 FALSE
68 );
69 ASSERT_EFI_ERROR (Status);
70 }
71 }
72
73 FreePool (AllDescMap);
74 }
75
76 return EFI_SUCCESS;
77 }