]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/PeilessStartupLib/Hob.c
OvmfPkg/PlatformInitLib: Add PlatformScanE820 and GetFirstNonAddressCB
[mirror_edk2.git] / OvmfPkg / Library / PeilessStartupLib / Hob.c
CommitLineData
4fe26784
MX
1/** @file\r
2 Main SEC phase code. Handles initial TDX Hob List Processing\r
3\r
4 Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include <PiPei.h>\r
12#include <Library/BaseLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/HobLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/PciLib.h>\r
17#include <Library/PrePiLib.h>\r
18#include <Library/QemuFwCfgLib.h>\r
19#include <IndustryStandard/Tdx.h>\r
20#include <IndustryStandard/UefiTcgPlatform.h>\r
21#include <Library/PlatformInitLib.h>\r
22#include <OvmfPlatforms.h>\r
9b648112 23#include <Pi/PrePiHob.h>\r
4fe26784
MX
24#include "PeilessStartupInternal.h"\r
25\r
26/**\r
27 * Construct the HobList in SEC phase.\r
28 *\r
29 * @return EFI_SUCCESS Successfully construct the firmware hoblist.\r
30 * @return EFI_NOT_FOUND Cannot find a memory region to be the fw hoblist.\r
31 */\r
32EFI_STATUS\r
33EFIAPI\r
34ConstructSecHobList (\r
35 )\r
36{\r
37 UINT32 LowMemorySize;\r
38 UINT32 LowMemoryStart;\r
39\r
40 EFI_HOB_HANDOFF_INFO_TABLE *HobList;\r
41 EFI_HOB_PLATFORM_INFO PlatformInfoHob;\r
42\r
43 ZeroMem (&PlatformInfoHob, sizeof (PlatformInfoHob));\r
44 PlatformInfoHob.HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
45 LowMemorySize = PlatformGetSystemMemorySizeBelow4gb (&PlatformInfoHob);\r
46 ASSERT (LowMemorySize != 0);\r
47 LowMemoryStart = FixedPcdGet32 (PcdOvmfDxeMemFvBase) + FixedPcdGet32 (PcdOvmfDxeMemFvSize);\r
48 LowMemorySize -= LowMemoryStart;\r
49\r
50 DEBUG ((DEBUG_INFO, "LowMemory Start and End: %x, %x\n", LowMemoryStart, LowMemoryStart + LowMemorySize));\r
51 HobList = HobConstructor (\r
52 (VOID *)(UINTN)LowMemoryStart,\r
53 LowMemorySize,\r
54 (VOID *)(UINTN)LowMemoryStart,\r
55 (VOID *)(UINTN)(LowMemoryStart + LowMemorySize)\r
56 );\r
57\r
58 SetHobList ((VOID *)(UINT64)HobList);\r
59\r
60 return EFI_SUCCESS;\r
61}\r
62\r
63/**\r
64 * This function is to find a memory region which is the largest one below 4GB.\r
65 * It will be used as the firmware hoblist.\r
66 *\r
67 * @param VmmHobList Vmm passed hoblist which constains the memory information.\r
68 * @return EFI_SUCCESS Successfully construct the firmware hoblist.\r
69 */\r
70EFI_STATUS\r
71EFIAPI\r
72ConstructFwHobList (\r
73 IN CONST VOID *VmmHobList\r
74 )\r
75{\r
76 EFI_PEI_HOB_POINTERS Hob;\r
77 EFI_PHYSICAL_ADDRESS PhysicalEnd;\r
78 UINT64 ResourceLength;\r
79 EFI_PHYSICAL_ADDRESS LowMemoryStart;\r
80 UINT64 LowMemoryLength;\r
81\r
82 ASSERT (VmmHobList != NULL);\r
83\r
84 Hob.Raw = (UINT8 *)VmmHobList;\r
85\r
86 LowMemoryLength = 0;\r
87 LowMemoryStart = 0;\r
88\r
89 //\r
90 // Parse the HOB list until end of list or matching type is found.\r
91 //\r
92 while (!END_OF_HOB_LIST (Hob)) {\r
93 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
9b648112 94 if (Hob.ResourceDescriptor->ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {\r
4fe26784
MX
95 PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;\r
96 ResourceLength = Hob.ResourceDescriptor->ResourceLength;\r
97\r
98 if (PhysicalEnd <= BASE_4GB) {\r
99 if (ResourceLength > LowMemoryLength) {\r
100 LowMemoryStart = Hob.ResourceDescriptor->PhysicalStart;\r
101 LowMemoryLength = ResourceLength;\r
102 }\r
103 } else {\r
104 break;\r
105 }\r
106 }\r
107 }\r
108\r
109 Hob.Raw = GET_NEXT_HOB (Hob);\r
110 }\r
111\r
112 if (LowMemoryLength == 0) {\r
113 DEBUG ((DEBUG_ERROR, "Cannot find a memory region under 4GB for Fw hoblist.\n"));\r
114 return EFI_NOT_FOUND;\r
115 }\r
116\r
117 //\r
118 // HobLib doesn't like HobStart at address 0 so adjust is needed\r
119 //\r
120 if (LowMemoryStart == 0) {\r
121 LowMemoryStart += EFI_PAGE_SIZE;\r
122 LowMemoryLength -= EFI_PAGE_SIZE;\r
123 }\r
124\r
125 DEBUG ((DEBUG_INFO, "LowMemory Start and End: %x, %x\n", LowMemoryStart, LowMemoryStart + LowMemoryLength));\r
126 HobConstructor (\r
127 (VOID *)LowMemoryStart,\r
128 LowMemoryLength,\r
129 (VOID *)LowMemoryStart,\r
130 (VOID *)(LowMemoryStart + LowMemoryLength)\r
131 );\r
132\r
133 SetHobList ((VOID *)(UINT64)LowMemoryStart);\r
134\r
135 return EFI_SUCCESS;\r
136}\r