Fsp1.1 update.
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformMemory.c
CommitLineData
c8ec22a2
JY
1/** @file\r
2\r
d5fb1edf 3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
c8ec22a2
JY
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include <PiPei.h>\r
15#include <Library/BaseLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
d5fb1edf 17#include <Library/MemoryAllocationLib.h>\r
c8ec22a2
JY
18#include <Library/DebugLib.h>\r
19#include <Library/PcdLib.h>\r
20#include <Library/HobLib.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Library/FspCommonLib.h>\r
23#include <Guid/GuidHobFsp.h>\r
24#include <FspGlobalData.h>\r
25#include <FspApi.h>\r
26\r
27/**\r
28 Get system memory from HOB.\r
29\r
30 @param[in,out] LowMemoryLength less than 4G memory length\r
31 @param[in,out] HighMemoryLength greater than 4G memory length\r
32**/\r
33VOID\r
34EFIAPI\r
35FspGetSystemMemorySize (\r
36 IN OUT UINT64 *LowMemoryLength,\r
37 IN OUT UINT64 *HighMemoryLength\r
38 )\r
39{\r
40 EFI_PEI_HOB_POINTERS Hob;\r
41\r
42 *HighMemoryLength = 0;\r
43 *LowMemoryLength = SIZE_1MB;\r
44 //\r
45 // Get the HOB list for processing\r
46 //\r
47 Hob.Raw = GetHobList ();\r
48\r
49 //\r
50 // Collect memory ranges\r
51 //\r
52 while (!END_OF_HOB_LIST (Hob)) {\r
53 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
54 if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
55 //\r
56 // Need memory above 1MB to be collected here\r
57 //\r
58 if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB &&\r
59 Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
60 *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
61 } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
62 *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
63 }\r
64 }\r
65 }\r
66 Hob.Raw = GET_NEXT_HOB (Hob);\r
67 }\r
68}\r
69\r
70/**\r
71 Migrate bootloader data before destroying CAR.\r
72\r
73**/\r
74VOID\r
75EFIAPI\r
76FspMigrateTemporaryMemory (\r
77 VOID\r
78 )\r
79{\r
d5fb1edf
JY
80 FSP_INIT_RT_COMMON_BUFFER *FspInitRtBuffer;\r
81 UINT32 BootLoaderTempRamStart;\r
82 UINT32 BootLoaderTempRamEnd;\r
83 UINT32 BootLoaderTempRamSize;\r
84 UINT32 OffsetGap;\r
85 UINT32 FspParamPtr;\r
86 FSP_INIT_PARAMS *FspInitParams;\r
87 UINT32 *NewStackTop;\r
88 VOID *BootLoaderTempRamHob;\r
89 VOID *UpdDataRgnPtr;\r
90 VOID *PlatformDataPtr;\r
91 UINT8 ApiMode;\r
92 \r
93 ApiMode = GetFspApiCallingMode ();\r
c8ec22a2
JY
94\r
95 //\r
96 // Get the temporary memory range used by the bootloader\r
97 //\r
98 BootLoaderTempRamStart = PcdGet32(PcdTemporaryRamBase);\r
99 BootLoaderTempRamSize = PcdGet32(PcdTemporaryRamSize) - PcdGet32(PcdFspTemporaryRamSize);\r
100 BootLoaderTempRamEnd = BootLoaderTempRamStart + BootLoaderTempRamSize;\r
101\r
102 //\r
103 // Build a Boot Loader Temporary Memory GUID HOB\r
104 //\r
d5fb1edf 105 if (ApiMode == 0) {\r
95c95ac0 106 BootLoaderTempRamHob = BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid, BootLoaderTempRamSize);\r
d5fb1edf 107 } else {\r
95c95ac0 108 BootLoaderTempRamHob = (VOID *)AllocatePool (BootLoaderTempRamSize);\r
d5fb1edf 109 }\r
95c95ac0 110 ASSERT(BootLoaderTempRamHob != NULL);\r
d5fb1edf 111\r
c8ec22a2
JY
112 CopyMem (BootLoaderTempRamHob, (VOID *)BootLoaderTempRamStart, BootLoaderTempRamSize);\r
113 OffsetGap = (UINT32)BootLoaderTempRamHob - BootLoaderTempRamStart;\r
114\r
115 //\r
116 // Set a new stack frame for the continuation function\r
117 //\r
d5fb1edf
JY
118 if (ApiMode == 0) {\r
119 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
120 FspInitRtBuffer = (FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr;\r
121 NewStackTop = (UINT32 *)FspInitRtBuffer->StackTop - 1;\r
122 SetFspCoreStackPointer (NewStackTop);\r
123 }\r
c8ec22a2
JY
124\r
125 //\r
126 // Fix the FspInit Parameter Pointers to the new location.\r
127 //\r
128 FspParamPtr = GetFspApiParameter ();\r
129 if (FspParamPtr >= BootLoaderTempRamStart && FspParamPtr < BootLoaderTempRamEnd) {\r
130 SetFspApiParameter(FspParamPtr + OffsetGap);\r
131 }\r
132\r
133 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
134 if ((UINT32)(FspInitParams->RtBufferPtr) >= BootLoaderTempRamStart &&\r
135 (UINT32)(FspInitParams->RtBufferPtr) < BootLoaderTempRamEnd) {\r
136 FspInitParams->RtBufferPtr = (VOID *)((UINT32)(FspInitParams->RtBufferPtr) + OffsetGap);\r
137 }\r
138\r
139 if ((UINT32)(FspInitParams->NvsBufferPtr) >= BootLoaderTempRamStart &&\r
140 (UINT32)(FspInitParams->NvsBufferPtr) < BootLoaderTempRamEnd) {\r
141 FspInitParams->NvsBufferPtr = (VOID *)((UINT32)(FspInitParams->NvsBufferPtr) + OffsetGap);\r
142 }\r
143\r
144 if ((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) >= BootLoaderTempRamStart &&\r
145 (UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) < BootLoaderTempRamEnd) {\r
146 ((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr = \\r
147 (VOID *)((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) + OffsetGap);\r
148 }\r
149\r
150 //\r
151 // Update UPD pointer in FSP Global Data\r
152 //\r
153 UpdDataRgnPtr = ((FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr)->UpdDataRgnPtr;\r
154 if (UpdDataRgnPtr != NULL) {\r
155 SetFspUpdDataPointer (UpdDataRgnPtr);\r
156 }\r
157\r
158 //\r
159 // Update Platform data pointer in FSP Global Data\r
160 //\r
161 PlatformDataPtr = GetFspPlatformDataPointer ();\r
162 if (((UINT32)PlatformDataPtr >= BootLoaderTempRamStart) &&\r
163 ((UINT32)PlatformDataPtr < BootLoaderTempRamEnd)) {\r
164 SetFspPlatformDataPointer ((UINT8 *)PlatformDataPtr + OffsetGap);\r
165 }\r
c8ec22a2 166}\r