OvmfPkg/AmdSevDxe: sort #includes, and entries in INF file sections
[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
24e4ad75 19#include <Library/BaseLib.h>\r
24e4ad75 20#include <Library/BaseMemoryLib.h>\r
c6073a0e 21#include <Library/DebugLib.h>\r
24e4ad75
BS
22#include <Library/DxeServicesTableLib.h>\r
23#include <Library/MemEncryptSevLib.h>\r
c6073a0e
LE
24#include <Library/MemoryAllocationLib.h>\r
25#include <Library/UefiBootServicesTableLib.h>\r
26#include <PiDxe.h>\r
24e4ad75
BS
27\r
28EFI_STATUS\r
29EFIAPI\r
30AmdSevDxeEntryPoint (\r
31 IN EFI_HANDLE ImageHandle,\r
32 IN EFI_SYSTEM_TABLE *SystemTable\r
33 )\r
34{\r
35 EFI_STATUS Status;\r
36 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *AllDescMap;\r
37 UINTN NumEntries;\r
38 UINTN Index;\r
39\r
40 //\r
41 // Do nothing when SEV is not enabled\r
42 //\r
43 if (!MemEncryptSevIsEnabled ()) {\r
44 return EFI_UNSUPPORTED;\r
45 }\r
46\r
47 //\r
48 // Iterate through the GCD map and clear the C-bit from MMIO and NonExistent\r
c16d4e35
LE
49 // memory space. The NonExistent memory space will be used for mapping the\r
50 // MMIO space added later (eg PciRootBridge). By clearing both known MMIO and\r
24e4ad75
BS
51 // NonExistent memory space can gurantee that current and furture MMIO adds\r
52 // will have C-bit cleared.\r
53 //\r
54 Status = gDS->GetMemorySpaceMap (&NumEntries, &AllDescMap);\r
55 if (!EFI_ERROR (Status)) {\r
56 for (Index = 0; Index < NumEntries; Index++) {\r
57 CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc;\r
58\r
59 Desc = &AllDescMap[Index];\r
60 if (Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo ||\r
61 Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent) {\r
c16d4e35
LE
62 Status = MemEncryptSevClearPageEncMask (\r
63 0,\r
64 Desc->BaseAddress,\r
65 EFI_SIZE_TO_PAGES (Desc->Length),\r
66 FALSE\r
67 );\r
24e4ad75
BS
68 ASSERT_EFI_ERROR (Status);\r
69 }\r
70 }\r
71\r
72 FreePool (AllDescMap);\r
73 }\r
74\r
75 return EFI_SUCCESS;\r
76}\r