3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseLib.h>
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/MemoryAllocationLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/PcdLib.h>
14 #include <Library/HobLib.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/FspCommonLib.h>
17 #include <Guid/GuidHobFsp.h>
18 #include <FspGlobalData.h>
22 Get system memory from HOB.
24 @param[in,out] LowMemoryLength less than 4G memory length
25 @param[in,out] HighMemoryLength greater than 4G memory length
29 FspGetSystemMemorySize (
30 IN OUT UINT64
*LowMemoryLength
,
31 IN OUT UINT64
*HighMemoryLength
34 EFI_PEI_HOB_POINTERS Hob
;
36 *HighMemoryLength
= 0;
37 *LowMemoryLength
= SIZE_1MB
;
39 // Get the HOB list for processing
41 Hob
.Raw
= GetHobList ();
44 // Collect memory ranges
46 while (!END_OF_HOB_LIST (Hob
)) {
47 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
48 if (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) {
50 // Need memory above 1MB to be collected here
52 if (Hob
.ResourceDescriptor
->PhysicalStart
>= BASE_1MB
&&
53 Hob
.ResourceDescriptor
->PhysicalStart
< (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
54 *LowMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
55 } else if (Hob
.ResourceDescriptor
->PhysicalStart
>= (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
56 *HighMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
60 Hob
.Raw
= GET_NEXT_HOB (Hob
);
65 Migrate BootLoader data before destroying CAR.
70 FspMigrateTemporaryMemory (
74 FSP_INIT_RT_COMMON_BUFFER
*FspInitRtBuffer
;
75 UINT32 BootLoaderTempRamStart
;
76 UINT32 BootLoaderTempRamEnd
;
77 UINT32 BootLoaderTempRamSize
;
80 FSP_INIT_PARAMS
*FspInitParams
;
82 VOID
*BootLoaderTempRamHob
;
84 UINT32 MemoryInitUpdPtr
;
85 UINT32 SiliconInitUpdPtr
;
86 VOID
*PlatformDataPtr
;
89 ApiMode
= GetFspApiCallingMode ();
92 // Get the temporary memory range used by the BootLoader
94 BootLoaderTempRamStart
= PcdGet32(PcdTemporaryRamBase
);
95 BootLoaderTempRamSize
= PcdGet32(PcdTemporaryRamSize
) - PcdGet32(PcdFspTemporaryRamSize
);
96 BootLoaderTempRamEnd
= BootLoaderTempRamStart
+ BootLoaderTempRamSize
;
99 // Build a Boot Loader Temporary Memory GUID HOB
102 BootLoaderTempRamHob
= BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid
, BootLoaderTempRamSize
);
104 BootLoaderTempRamHob
= (VOID
*)AllocatePages (EFI_SIZE_TO_PAGES (BootLoaderTempRamSize
));
106 ASSERT(BootLoaderTempRamHob
!= NULL
);
108 CopyMem (BootLoaderTempRamHob
, (VOID
*)BootLoaderTempRamStart
, BootLoaderTempRamSize
);
109 OffsetGap
= (UINT32
)BootLoaderTempRamHob
- BootLoaderTempRamStart
;
112 // Set a new stack frame for the continuation function
115 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
116 FspInitRtBuffer
= (FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
;
117 NewStackTop
= (UINT32
*)FspInitRtBuffer
->StackTop
- 1;
118 SetFspCoreStackPointer (NewStackTop
);
122 // Fix the FspInit Parameter Pointers to the new location.
124 FspParamPtr
= GetFspApiParameter ();
125 if (FspParamPtr
>= BootLoaderTempRamStart
&& FspParamPtr
< BootLoaderTempRamEnd
) {
126 SetFspApiParameter(FspParamPtr
+ OffsetGap
);
129 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
130 if ((UINT32
)(FspInitParams
->RtBufferPtr
) >= BootLoaderTempRamStart
&&
131 (UINT32
)(FspInitParams
->RtBufferPtr
) < BootLoaderTempRamEnd
) {
132 FspInitParams
->RtBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->RtBufferPtr
) + OffsetGap
);
135 if ((UINT32
)(FspInitParams
->NvsBufferPtr
) >= BootLoaderTempRamStart
&&
136 (UINT32
)(FspInitParams
->NvsBufferPtr
) < BootLoaderTempRamEnd
) {
137 FspInitParams
->NvsBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->NvsBufferPtr
) + OffsetGap
);
140 if ((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) >= BootLoaderTempRamStart
&&
141 (UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) < BootLoaderTempRamEnd
) {
142 ((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
= \
143 (VOID
*)((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) + OffsetGap
);
147 // Update UPD pointer in FSP Global Data
150 UpdDataRgnPtr
= (UINT32
)((UINT32
*)GetFspUpdDataPointer ());
151 if (UpdDataRgnPtr
>= BootLoaderTempRamStart
&& UpdDataRgnPtr
< BootLoaderTempRamEnd
) {
152 MemoryInitUpdPtr
= (UINT32
)((UINT32
*)GetFspMemoryInitUpdDataPointer ());
153 SiliconInitUpdPtr
= (UINT32
)((UINT32
*)GetFspSiliconInitUpdDataPointer ());
154 SetFspUpdDataPointer ((VOID
*)(UpdDataRgnPtr
+ OffsetGap
));
155 SetFspMemoryInitUpdDataPointer ((VOID
*)(MemoryInitUpdPtr
+ OffsetGap
));
156 SetFspSiliconInitUpdDataPointer ((VOID
*)(SiliconInitUpdPtr
+ OffsetGap
));
159 MemoryInitUpdPtr
= (UINT32
)((UINT32
*)GetFspMemoryInitUpdDataPointer ());
160 if (MemoryInitUpdPtr
>= BootLoaderTempRamStart
&& MemoryInitUpdPtr
< BootLoaderTempRamEnd
) {
161 SetFspMemoryInitUpdDataPointer ((VOID
*)(MemoryInitUpdPtr
+ OffsetGap
));
166 // Update Platform data pointer in FSP Global Data
168 PlatformDataPtr
= GetFspPlatformDataPointer ();
169 if (((UINT32
)PlatformDataPtr
>= BootLoaderTempRamStart
) &&
170 ((UINT32
)PlatformDataPtr
< BootLoaderTempRamEnd
)) {
171 SetFspPlatformDataPointer ((UINT8
*)PlatformDataPtr
+ OffsetGap
);