2 Main SEC phase code. Handles initial TDX Hob List Processing
4 Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/BaseLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HobLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/PciLib.h>
17 #include <Library/PrePiLib.h>
18 #include <Library/QemuFwCfgLib.h>
19 #include <IndustryStandard/Tdx.h>
20 #include <IndustryStandard/UefiTcgPlatform.h>
21 #include <Library/PlatformInitLib.h>
22 #include <OvmfPlatforms.h>
23 #include <Pi/PrePiHob.h>
24 #include "PeilessStartupInternal.h"
27 * Construct the HobList in SEC phase.
29 * @return EFI_SUCCESS Successfully construct the firmware hoblist.
30 * @return EFI_NOT_FOUND Cannot find a memory region to be the fw hoblist.
38 UINT32 LowMemoryStart
;
40 EFI_HOB_HANDOFF_INFO_TABLE
*HobList
;
41 EFI_HOB_PLATFORM_INFO PlatformInfoHob
;
43 ZeroMem (&PlatformInfoHob
, sizeof (PlatformInfoHob
));
44 PlatformInfoHob
.HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
45 PlatformGetSystemMemorySizeBelow4gb (&PlatformInfoHob
);
46 LowMemorySize
= PlatformInfoHob
.LowMemory
;
47 ASSERT (LowMemorySize
!= 0);
48 LowMemoryStart
= FixedPcdGet32 (PcdOvmfDxeMemFvBase
) + FixedPcdGet32 (PcdOvmfDxeMemFvSize
);
49 LowMemorySize
-= LowMemoryStart
;
51 DEBUG ((DEBUG_INFO
, "LowMemory Start and End: %x, %x\n", LowMemoryStart
, LowMemoryStart
+ LowMemorySize
));
52 HobList
= HobConstructor (
53 (VOID
*)(UINTN
)LowMemoryStart
,
55 (VOID
*)(UINTN
)LowMemoryStart
,
56 (VOID
*)(UINTN
)(LowMemoryStart
+ LowMemorySize
)
59 SetHobList ((VOID
*)(UINT64
)HobList
);
65 * This function is to find a memory region which is the largest one below 4GB.
66 * It will be used as the firmware hoblist.
68 * @param VmmHobList Vmm passed hoblist which constains the memory information.
69 * @return EFI_SUCCESS Successfully construct the firmware hoblist.
74 IN CONST VOID
*VmmHobList
77 EFI_PEI_HOB_POINTERS Hob
;
78 EFI_PHYSICAL_ADDRESS PhysicalEnd
;
79 UINT64 ResourceLength
;
80 EFI_PHYSICAL_ADDRESS LowMemoryStart
;
81 UINT64 LowMemoryLength
;
83 ASSERT (VmmHobList
!= NULL
);
85 Hob
.Raw
= (UINT8
*)VmmHobList
;
91 // Parse the HOB list until end of list or matching type is found.
93 while (!END_OF_HOB_LIST (Hob
)) {
94 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
95 if (Hob
.ResourceDescriptor
->ResourceType
== BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED
) {
96 PhysicalEnd
= Hob
.ResourceDescriptor
->PhysicalStart
+ Hob
.ResourceDescriptor
->ResourceLength
;
97 ResourceLength
= Hob
.ResourceDescriptor
->ResourceLength
;
99 if (PhysicalEnd
<= BASE_4GB
) {
100 if (ResourceLength
> LowMemoryLength
) {
101 LowMemoryStart
= Hob
.ResourceDescriptor
->PhysicalStart
;
102 LowMemoryLength
= ResourceLength
;
110 Hob
.Raw
= GET_NEXT_HOB (Hob
);
113 if (LowMemoryLength
== 0) {
114 DEBUG ((DEBUG_ERROR
, "Cannot find a memory region under 4GB for Fw hoblist.\n"));
115 return EFI_NOT_FOUND
;
119 // HobLib doesn't like HobStart at address 0 so adjust is needed
121 if (LowMemoryStart
== 0) {
122 LowMemoryStart
+= EFI_PAGE_SIZE
;
123 LowMemoryLength
-= EFI_PAGE_SIZE
;
126 DEBUG ((DEBUG_INFO
, "LowMemory Start and End: %x, %x\n", LowMemoryStart
, LowMemoryStart
+ LowMemoryLength
));
128 (VOID
*)LowMemoryStart
,
130 (VOID
*)LowMemoryStart
,
131 (VOID
*)(LowMemoryStart
+ LowMemoryLength
)
134 SetHobList ((VOID
*)(UINT64
)LowMemoryStart
);