3 Copyright (c) 2014, 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/DebugLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/PeiServicesLib.h>
21 #include <Library/FspCommonLib.h>
22 #include <Guid/GuidHobFsp.h>
23 #include <FspGlobalData.h>
27 Get system memory from HOB.
29 @param[in,out] LowMemoryLength less than 4G memory length
30 @param[in,out] HighMemoryLength greater than 4G memory length
34 FspGetSystemMemorySize (
35 IN OUT UINT64
*LowMemoryLength
,
36 IN OUT UINT64
*HighMemoryLength
39 EFI_PEI_HOB_POINTERS Hob
;
41 *HighMemoryLength
= 0;
42 *LowMemoryLength
= SIZE_1MB
;
44 // Get the HOB list for processing
46 Hob
.Raw
= GetHobList ();
49 // Collect memory ranges
51 while (!END_OF_HOB_LIST (Hob
)) {
52 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
53 if (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) {
55 // Need memory above 1MB to be collected here
57 if (Hob
.ResourceDescriptor
->PhysicalStart
>= BASE_1MB
&&
58 Hob
.ResourceDescriptor
->PhysicalStart
< (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
59 *LowMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
60 } else if (Hob
.ResourceDescriptor
->PhysicalStart
>= (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
61 *HighMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
65 Hob
.Raw
= GET_NEXT_HOB (Hob
);
70 Migrate bootloader data before destroying CAR.
75 FspMigrateTemporaryMemory (
79 FSP_INIT_RT_COMMON_BUFFER
*FspInitRtBuffer
;
80 UINT32 BootLoaderTempRamStart
;
81 UINT32 BootLoaderTempRamEnd
;
82 UINT32 BootLoaderTempRamSize
;
85 FSP_INIT_PARAMS
*FspInitParams
;
87 VOID
*BootLoaderTempRamHob
;
89 VOID
*PlatformDataPtr
;
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
101 BootLoaderTempRamHob
= BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid
, BootLoaderTempRamSize
);
102 CopyMem (BootLoaderTempRamHob
, (VOID
*)BootLoaderTempRamStart
, BootLoaderTempRamSize
);
103 OffsetGap
= (UINT32
)BootLoaderTempRamHob
- BootLoaderTempRamStart
;
106 // Set a new stack frame for the continuation function
108 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
109 FspInitRtBuffer
= (FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
;
110 NewStackTop
= (UINT32
*)FspInitRtBuffer
->StackTop
- 1;
111 SetFspCoreStackPointer (NewStackTop
);
114 // Fix the FspInit Parameter Pointers to the new location.
116 FspParamPtr
= GetFspApiParameter ();
117 if (FspParamPtr
>= BootLoaderTempRamStart
&& FspParamPtr
< BootLoaderTempRamEnd
) {
118 SetFspApiParameter(FspParamPtr
+ OffsetGap
);
121 FspInitParams
= (FSP_INIT_PARAMS
*)GetFspApiParameter ();
122 if ((UINT32
)(FspInitParams
->RtBufferPtr
) >= BootLoaderTempRamStart
&&
123 (UINT32
)(FspInitParams
->RtBufferPtr
) < BootLoaderTempRamEnd
) {
124 FspInitParams
->RtBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->RtBufferPtr
) + OffsetGap
);
127 if ((UINT32
)(FspInitParams
->NvsBufferPtr
) >= BootLoaderTempRamStart
&&
128 (UINT32
)(FspInitParams
->NvsBufferPtr
) < BootLoaderTempRamEnd
) {
129 FspInitParams
->NvsBufferPtr
= (VOID
*)((UINT32
)(FspInitParams
->NvsBufferPtr
) + OffsetGap
);
132 if ((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) >= BootLoaderTempRamStart
&&
133 (UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) < BootLoaderTempRamEnd
) {
134 ((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
= \
135 (VOID
*)((UINT32
)(((FSP_INIT_RT_COMMON_BUFFER
*)(FspInitParams
->RtBufferPtr
))->UpdDataRgnPtr
) + OffsetGap
);
139 // Update UPD pointer in FSP Global Data
141 UpdDataRgnPtr
= ((FSP_INIT_RT_COMMON_BUFFER
*)FspInitParams
->RtBufferPtr
)->UpdDataRgnPtr
;
142 if (UpdDataRgnPtr
!= NULL
) {
143 SetFspUpdDataPointer (UpdDataRgnPtr
);
147 // Update Platform data pointer in FSP Global Data
149 PlatformDataPtr
= GetFspPlatformDataPointer ();
150 if (((UINT32
)PlatformDataPtr
>= BootLoaderTempRamStart
) &&
151 ((UINT32
)PlatformDataPtr
< BootLoaderTempRamEnd
)) {
152 SetFspPlatformDataPointer ((UINT8
*)PlatformDataPtr
+ OffsetGap
);