]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
Fix an issue on FixedMtreProgramming - AND/OR mask incorrect.
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformMemory.c
... / ...
CommitLineData
1/** @file\r
2\r
3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
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
17#include <Library/DebugLib.h>\r
18#include <Library/PcdLib.h>\r
19#include <Library/HobLib.h>\r
20#include <Library/PeiServicesLib.h>\r
21#include <Library/FspCommonLib.h>\r
22#include <Guid/GuidHobFsp.h>\r
23#include <FspGlobalData.h>\r
24#include <FspApi.h>\r
25\r
26/**\r
27 Get system memory from HOB.\r
28\r
29 @param[in,out] LowMemoryLength less than 4G memory length\r
30 @param[in,out] HighMemoryLength greater than 4G memory length\r
31**/\r
32VOID\r
33EFIAPI\r
34FspGetSystemMemorySize (\r
35 IN OUT UINT64 *LowMemoryLength,\r
36 IN OUT UINT64 *HighMemoryLength\r
37 )\r
38{\r
39 EFI_PEI_HOB_POINTERS Hob;\r
40\r
41 *HighMemoryLength = 0;\r
42 *LowMemoryLength = SIZE_1MB;\r
43 //\r
44 // Get the HOB list for processing\r
45 //\r
46 Hob.Raw = GetHobList ();\r
47\r
48 //\r
49 // Collect memory ranges\r
50 //\r
51 while (!END_OF_HOB_LIST (Hob)) {\r
52 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
53 if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
54 //\r
55 // Need memory above 1MB to be collected here\r
56 //\r
57 if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB &&\r
58 Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
59 *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
60 } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
61 *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
62 }\r
63 }\r
64 }\r
65 Hob.Raw = GET_NEXT_HOB (Hob);\r
66 }\r
67}\r
68\r
69/**\r
70 Migrate bootloader data before destroying CAR.\r
71\r
72**/\r
73VOID\r
74EFIAPI\r
75FspMigrateTemporaryMemory (\r
76 VOID\r
77 )\r
78{\r
79 FSP_INIT_RT_COMMON_BUFFER *FspInitRtBuffer;\r
80 UINT32 BootLoaderTempRamStart;\r
81 UINT32 BootLoaderTempRamEnd;\r
82 UINT32 BootLoaderTempRamSize;\r
83 UINT32 OffsetGap;\r
84 UINT32 FspParamPtr;\r
85 FSP_INIT_PARAMS *FspInitParams;\r
86 UINT32 *NewStackTop;\r
87 VOID *BootLoaderTempRamHob;\r
88 VOID *UpdDataRgnPtr;\r
89 VOID *PlatformDataPtr;\r
90\r
91 //\r
92 // Get the temporary memory range used by the bootloader\r
93 //\r
94 BootLoaderTempRamStart = PcdGet32(PcdTemporaryRamBase);\r
95 BootLoaderTempRamSize = PcdGet32(PcdTemporaryRamSize) - PcdGet32(PcdFspTemporaryRamSize);\r
96 BootLoaderTempRamEnd = BootLoaderTempRamStart + BootLoaderTempRamSize;\r
97\r
98 //\r
99 // Build a Boot Loader Temporary Memory GUID HOB\r
100 //\r
101 BootLoaderTempRamHob = BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid, BootLoaderTempRamSize);\r
102 CopyMem (BootLoaderTempRamHob, (VOID *)BootLoaderTempRamStart, BootLoaderTempRamSize);\r
103 OffsetGap = (UINT32)BootLoaderTempRamHob - BootLoaderTempRamStart;\r
104\r
105 //\r
106 // Set a new stack frame for the continuation function\r
107 //\r
108 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
109 FspInitRtBuffer = (FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr;\r
110 NewStackTop = (UINT32 *)FspInitRtBuffer->StackTop - 1;\r
111 SetFspCoreStackPointer (NewStackTop);\r
112\r
113 //\r
114 // Fix the FspInit Parameter Pointers to the new location.\r
115 //\r
116 FspParamPtr = GetFspApiParameter ();\r
117 if (FspParamPtr >= BootLoaderTempRamStart && FspParamPtr < BootLoaderTempRamEnd) {\r
118 SetFspApiParameter(FspParamPtr + OffsetGap);\r
119 }\r
120\r
121 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
122 if ((UINT32)(FspInitParams->RtBufferPtr) >= BootLoaderTempRamStart &&\r
123 (UINT32)(FspInitParams->RtBufferPtr) < BootLoaderTempRamEnd) {\r
124 FspInitParams->RtBufferPtr = (VOID *)((UINT32)(FspInitParams->RtBufferPtr) + OffsetGap);\r
125 }\r
126\r
127 if ((UINT32)(FspInitParams->NvsBufferPtr) >= BootLoaderTempRamStart &&\r
128 (UINT32)(FspInitParams->NvsBufferPtr) < BootLoaderTempRamEnd) {\r
129 FspInitParams->NvsBufferPtr = (VOID *)((UINT32)(FspInitParams->NvsBufferPtr) + OffsetGap);\r
130 }\r
131\r
132 if ((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) >= BootLoaderTempRamStart &&\r
133 (UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) < BootLoaderTempRamEnd) {\r
134 ((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr = \\r
135 (VOID *)((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) + OffsetGap);\r
136 }\r
137\r
138 //\r
139 // Update UPD pointer in FSP Global Data\r
140 //\r
141 UpdDataRgnPtr = ((FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr)->UpdDataRgnPtr;\r
142 if (UpdDataRgnPtr != NULL) {\r
143 SetFspUpdDataPointer (UpdDataRgnPtr);\r
144 }\r
145\r
146 //\r
147 // Update Platform data pointer in FSP Global Data\r
148 //\r
149 PlatformDataPtr = GetFspPlatformDataPointer ();\r
150 if (((UINT32)PlatformDataPtr >= BootLoaderTempRamStart) &&\r
151 ((UINT32)PlatformDataPtr < BootLoaderTempRamEnd)) {\r
152 SetFspPlatformDataPointer ((UINT8 *)PlatformDataPtr + OffsetGap);\r
153 }\r
154\r
155}\r