]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
DHCP6 bug fix:
[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
JY
105 if (ApiMode == 0) {\r
106 BootLoaderTempRamHob = BuildGuidHob (&gFspBootLoaderTempMemoryGuid, BootLoaderTempRamSize);\r
107 } else {\r
108 BootLoaderTempRamHob = (VOID *)AllocatePool (BootLoaderTempRamSize);\r
109 }\r
110\r
c8ec22a2
JY
111 CopyMem (BootLoaderTempRamHob, (VOID *)BootLoaderTempRamStart, BootLoaderTempRamSize);\r
112 OffsetGap = (UINT32)BootLoaderTempRamHob - BootLoaderTempRamStart;\r
113\r
114 //\r
115 // Set a new stack frame for the continuation function\r
116 //\r
d5fb1edf
JY
117 if (ApiMode == 0) {\r
118 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
119 FspInitRtBuffer = (FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr;\r
120 NewStackTop = (UINT32 *)FspInitRtBuffer->StackTop - 1;\r
121 SetFspCoreStackPointer (NewStackTop);\r
122 }\r
c8ec22a2
JY
123\r
124 //\r
125 // Fix the FspInit Parameter Pointers to the new location.\r
126 //\r
127 FspParamPtr = GetFspApiParameter ();\r
128 if (FspParamPtr >= BootLoaderTempRamStart && FspParamPtr < BootLoaderTempRamEnd) {\r
129 SetFspApiParameter(FspParamPtr + OffsetGap);\r
130 }\r
131\r
132 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
133 if ((UINT32)(FspInitParams->RtBufferPtr) >= BootLoaderTempRamStart &&\r
134 (UINT32)(FspInitParams->RtBufferPtr) < BootLoaderTempRamEnd) {\r
135 FspInitParams->RtBufferPtr = (VOID *)((UINT32)(FspInitParams->RtBufferPtr) + OffsetGap);\r
136 }\r
137\r
138 if ((UINT32)(FspInitParams->NvsBufferPtr) >= BootLoaderTempRamStart &&\r
139 (UINT32)(FspInitParams->NvsBufferPtr) < BootLoaderTempRamEnd) {\r
140 FspInitParams->NvsBufferPtr = (VOID *)((UINT32)(FspInitParams->NvsBufferPtr) + OffsetGap);\r
141 }\r
142\r
143 if ((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) >= BootLoaderTempRamStart &&\r
144 (UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) < BootLoaderTempRamEnd) {\r
145 ((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr = \\r
146 (VOID *)((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) + OffsetGap);\r
147 }\r
148\r
149 //\r
150 // Update UPD pointer in FSP Global Data\r
151 //\r
152 UpdDataRgnPtr = ((FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr)->UpdDataRgnPtr;\r
153 if (UpdDataRgnPtr != NULL) {\r
154 SetFspUpdDataPointer (UpdDataRgnPtr);\r
155 }\r
156\r
157 //\r
158 // Update Platform data pointer in FSP Global Data\r
159 //\r
160 PlatformDataPtr = GetFspPlatformDataPointer ();\r
161 if (((UINT32)PlatformDataPtr >= BootLoaderTempRamStart) &&\r
162 ((UINT32)PlatformDataPtr < BootLoaderTempRamEnd)) {\r
163 SetFspPlatformDataPointer ((UINT8 *)PlatformDataPtr + OffsetGap);\r
164 }\r
c8ec22a2 165}\r