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