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 VOID
*PlatformDataPtr
;
93 ApiMode
= GetFspApiCallingMode ();
96 // Get the temporary memory range used by the BootLoader
98 BootLoaderTempRamStart
= PcdGet32(PcdTemporaryRamBase
);
99 BootLoaderTempRamSize
= PcdGet32(PcdTemporaryRamSize
) - PcdGet32(PcdFspTemporaryRamSize
);
100 BootLoaderTempRamEnd
= BootLoaderTempRamStart
+ BootLoaderTempRamSize
;
103 // Build a Boot Loader Temporary Memory GUID HOB
106 BootLoaderTempRamHob
= BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid
, BootLoaderTempRamSize
);
108 BootLoaderTempRamHob
= (VOID
*)AllocatePool (BootLoaderTempRamSize
);
110 ASSERT(BootLoaderTempRamHob
!= NULL
);
112 CopyMem (BootLoaderTempRamHob
, (VOID
*)BootLoaderTempRamStart
, BootLoaderTempRamSize
);
113 OffsetGap
= (UINT32
)BootLoaderTempRamHob
- BootLoaderTempRamStart
;
116 // Set a new stack frame for the continuation function
119 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
120 FspInitRtBuffer
= (FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
;
121 NewStackTop
= (UINT32
*)FspInitRtBuffer
->StackTop
- 1;
122 SetFspCoreStackPointer (NewStackTop
);
126 // Fix the FspInit Parameter Pointers to the new location.
128 FspParamPtr
= GetFspApiParameter ();
129 if (FspParamPtr
>= BootLoaderTempRamStart
&& FspParamPtr
< BootLoaderTempRamEnd
) {
130 SetFspApiParameter(FspParamPtr
+ OffsetGap
);
133 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
134 if ((UINT32
)(FspInitParams
->RtBufferPtr
) >= BootLoaderTempRamStart
&&
135 (UINT32
)(FspInitParams
->RtBufferPtr
) < BootLoaderTempRamEnd
) {
136 FspInitParams
->RtBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->RtBufferPtr
) + OffsetGap
);
139 if ((UINT32
)(FspInitParams
->NvsBufferPtr
) >= BootLoaderTempRamStart
&&
140 (UINT32
)(FspInitParams
->NvsBufferPtr
) < BootLoaderTempRamEnd
) {
141 FspInitParams
->NvsBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->NvsBufferPtr
) + OffsetGap
);
144 if ((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) >= BootLoaderTempRamStart
&&
145 (UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) < BootLoaderTempRamEnd
) {
146 ((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
= \
147 (VOID
*)((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) + OffsetGap
);
151 // Update UPD pointer in FSP Global Data
153 UpdDataRgnPtr
= ((FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
)->UpdDataRgnPtr
;
154 if (UpdDataRgnPtr
!= NULL
) {
155 SetFspUpdDataPointer (UpdDataRgnPtr
);
159 // Update Platform data pointer in FSP Global Data
161 PlatformDataPtr
= GetFspPlatformDataPointer ();
162 if (((UINT32
)PlatformDataPtr
>= BootLoaderTempRamStart
) &&
163 ((UINT32
)PlatformDataPtr
< BootLoaderTempRamEnd
)) {
164 SetFspPlatformDataPointer ((UINT8
*)PlatformDataPtr
+ OffsetGap
);