]>
Commit | Line | Data |
---|---|---|
24e4ad75 BS |
1 | /** @file\r |
2 | \r | |
3 | AMD Sev Dxe driver. This driver is dispatched early in DXE, due to being list\r | |
4 | in APRIORI. It clears C-bit from MMIO and NonExistent Memory space when SEV is\r | |
5 | enabled.\r | |
6 | \r | |
7 | Copyright (c) 2017, AMD Inc. All rights reserved.<BR>\r | |
8 | \r | |
9 | This program and the accompanying materials\r | |
10 | are licensed and made available under the terms and conditions of the BSD\r | |
11 | License which accompanies this distribution. The full text of the license may\r | |
12 | be found at http://opensource.org/licenses/bsd-license.php\r | |
13 | \r | |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
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 | |
29 | EFI_STATUS\r | |
30 | EFIAPI\r | |
31 | AmdSevDxeEntryPoint (\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 | |
50 | // memory space. The NonExistent memory space will be used for mapping the MMIO\r | |
51 | // space added later (eg PciRootBridge). By clearing both known MMIO and\r | |
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 | |
63 | Status = MemEncryptSevClearPageEncMask (0,\r | |
64 | Desc->BaseAddress,\r | |
65 | EFI_SIZE_TO_PAGES(Desc->Length),\r | |
66 | FALSE);\r | |
67 | ASSERT_EFI_ERROR (Status);\r | |
68 | }\r | |
69 | }\r | |
70 | \r | |
71 | FreePool (AllDescMap);\r | |
72 | }\r | |
73 | \r | |
74 | return EFI_SUCCESS;\r | |
75 | }\r |