3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/MemoryAllocationLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/PcdLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/PeiServicesLib.h>
22 #include <Library/FspCommonLib.h>
23 #include <Guid/GuidHobFsp.h>
24 #include <FspGlobalData.h>
28 Get system memory from HOB.
30 @param[in,out] LowMemoryLength less than 4G memory length
31 @param[in,out] HighMemoryLength greater than 4G memory length
35 FspGetSystemMemorySize (
36 IN OUT UINT64
*LowMemoryLength
,
37 IN OUT UINT64
*HighMemoryLength
40 EFI_PEI_HOB_POINTERS Hob
;
42 *HighMemoryLength
= 0;
43 *LowMemoryLength
= SIZE_1MB
;
45 // Get the HOB list for processing
47 Hob
.Raw
= GetHobList ();
50 // Collect memory ranges
52 while (!END_OF_HOB_LIST (Hob
)) {
53 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
54 if (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) {
56 // Need memory above 1MB to be collected here
58 if (Hob
.ResourceDescriptor
->PhysicalStart
>= BASE_1MB
&&
59 Hob
.ResourceDescriptor
->PhysicalStart
< (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
60 *LowMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
61 } else if (Hob
.ResourceDescriptor
->PhysicalStart
>= (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
62 *HighMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
66 Hob
.Raw
= GET_NEXT_HOB (Hob
);
71 Migrate BootLoader data before destroying CAR.
76 FspMigrateTemporaryMemory (
80 FSP_INIT_RT_COMMON_BUFFER
*FspInitRtBuffer
;
81 UINT32 BootLoaderTempRamStart
;
82 UINT32 BootLoaderTempRamEnd
;
83 UINT32 BootLoaderTempRamSize
;
86 FSP_INIT_PARAMS
*FspInitParams
;
88 VOID
*BootLoaderTempRamHob
;
90 UINT32 MemoryInitUpdPtr
;
91 UINT32 SiliconInitUpdPtr
;
92 VOID
*PlatformDataPtr
;
95 ApiMode
= GetFspApiCallingMode ();
98 // Get the temporary memory range used by the BootLoader
100 BootLoaderTempRamStart
= PcdGet32(PcdTemporaryRamBase
);
101 BootLoaderTempRamSize
= PcdGet32(PcdTemporaryRamSize
) - PcdGet32(PcdFspTemporaryRamSize
);
102 BootLoaderTempRamEnd
= BootLoaderTempRamStart
+ BootLoaderTempRamSize
;
105 // Build a Boot Loader Temporary Memory GUID HOB
108 BootLoaderTempRamHob
= BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid
, BootLoaderTempRamSize
);
110 BootLoaderTempRamHob
= (VOID
*)AllocatePages (EFI_SIZE_TO_PAGES (BootLoaderTempRamSize
));
112 ASSERT(BootLoaderTempRamHob
!= NULL
);
114 CopyMem (BootLoaderTempRamHob
, (VOID
*)BootLoaderTempRamStart
, BootLoaderTempRamSize
);
115 OffsetGap
= (UINT32
)BootLoaderTempRamHob
- BootLoaderTempRamStart
;
118 // Set a new stack frame for the continuation function
121 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
122 FspInitRtBuffer
= (FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
;
123 NewStackTop
= (UINT32
*)FspInitRtBuffer
->StackTop
- 1;
124 SetFspCoreStackPointer (NewStackTop
);
128 // Fix the FspInit Parameter Pointers to the new location.
130 FspParamPtr
= GetFspApiParameter ();
131 if (FspParamPtr
>= BootLoaderTempRamStart
&& FspParamPtr
< BootLoaderTempRamEnd
) {
132 SetFspApiParameter(FspParamPtr
+ OffsetGap
);
135 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
136 if ((UINT32
)(FspInitParams
->RtBufferPtr
) >= BootLoaderTempRamStart
&&
137 (UINT32
)(FspInitParams
->RtBufferPtr
) < BootLoaderTempRamEnd
) {
138 FspInitParams
->RtBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->RtBufferPtr
) + OffsetGap
);
141 if ((UINT32
)(FspInitParams
->NvsBufferPtr
) >= BootLoaderTempRamStart
&&
142 (UINT32
)(FspInitParams
->NvsBufferPtr
) < BootLoaderTempRamEnd
) {
143 FspInitParams
->NvsBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->NvsBufferPtr
) + OffsetGap
);
146 if ((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) >= BootLoaderTempRamStart
&&
147 (UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) < BootLoaderTempRamEnd
) {
148 ((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
= \
149 (VOID
*)((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) + OffsetGap
);
153 // Update UPD pointer in FSP Global Data
156 UpdDataRgnPtr
= (UINT32
)((UINT32
*)GetFspUpdDataPointer ());
157 if (UpdDataRgnPtr
>= BootLoaderTempRamStart
&& UpdDataRgnPtr
< BootLoaderTempRamEnd
) {
158 MemoryInitUpdPtr
= (UINT32
)((UINT32
*)GetFspMemoryInitUpdDataPointer ());
159 SiliconInitUpdPtr
= (UINT32
)((UINT32
*)GetFspSiliconInitUpdDataPointer ());
160 SetFspUpdDataPointer ((VOID
*)(UpdDataRgnPtr
+ OffsetGap
));
161 SetFspMemoryInitUpdDataPointer ((VOID
*)(MemoryInitUpdPtr
+ OffsetGap
));
162 SetFspSiliconInitUpdDataPointer ((VOID
*)(SiliconInitUpdPtr
+ OffsetGap
));
165 MemoryInitUpdPtr
= (UINT32
)((UINT32
*)GetFspMemoryInitUpdDataPointer ());
166 if (MemoryInitUpdPtr
>= BootLoaderTempRamStart
&& MemoryInitUpdPtr
< BootLoaderTempRamEnd
) {
167 SetFspMemoryInitUpdDataPointer ((VOID
*)(MemoryInitUpdPtr
+ OffsetGap
));
172 // Update Platform data pointer in FSP Global Data
174 PlatformDataPtr
= GetFspPlatformDataPointer ();
175 if (((UINT32
)PlatformDataPtr
>= BootLoaderTempRamStart
) &&
176 ((UINT32
)PlatformDataPtr
< BootLoaderTempRamEnd
)) {
177 SetFspPlatformDataPointer ((UINT8
*)PlatformDataPtr
+ OffsetGap
);