]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
6fb4dca7657cf985f2099895e1cc57e832dd5755
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformMemory.c
1 /** @file
2
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.
8
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.
11
12 **/
13
14 #include <PiPei.h>
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>
25 #include <FspApi.h>
26
27 /**
28 Get system memory from HOB.
29
30 @param[in,out] LowMemoryLength less than 4G memory length
31 @param[in,out] HighMemoryLength greater than 4G memory length
32 **/
33 VOID
34 EFIAPI
35 FspGetSystemMemorySize (
36 IN OUT UINT64 *LowMemoryLength,
37 IN OUT UINT64 *HighMemoryLength
38 )
39 {
40 EFI_PEI_HOB_POINTERS Hob;
41
42 *HighMemoryLength = 0;
43 *LowMemoryLength = SIZE_1MB;
44 //
45 // Get the HOB list for processing
46 //
47 Hob.Raw = GetHobList ();
48
49 //
50 // Collect memory ranges
51 //
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) {
55 //
56 // Need memory above 1MB to be collected here
57 //
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);
63 }
64 }
65 }
66 Hob.Raw = GET_NEXT_HOB (Hob);
67 }
68 }
69
70 /**
71 Migrate bootloader data before destroying CAR.
72
73 **/
74 VOID
75 EFIAPI
76 FspMigrateTemporaryMemory (
77 VOID
78 )
79 {
80 FSP_INIT_RT_COMMON_BUFFER *FspInitRtBuffer;
81 UINT32 BootLoaderTempRamStart;
82 UINT32 BootLoaderTempRamEnd;
83 UINT32 BootLoaderTempRamSize;
84 UINT32 OffsetGap;
85 UINT32 FspParamPtr;
86 FSP_INIT_PARAMS *FspInitParams;
87 UINT32 *NewStackTop;
88 VOID *BootLoaderTempRamHob;
89 VOID *UpdDataRgnPtr;
90 VOID *PlatformDataPtr;
91 UINT8 ApiMode;
92
93 ApiMode = GetFspApiCallingMode ();
94
95 //
96 // Get the temporary memory range used by the bootloader
97 //
98 BootLoaderTempRamStart = PcdGet32(PcdTemporaryRamBase);
99 BootLoaderTempRamSize = PcdGet32(PcdTemporaryRamSize) - PcdGet32(PcdFspTemporaryRamSize);
100 BootLoaderTempRamEnd = BootLoaderTempRamStart + BootLoaderTempRamSize;
101
102 //
103 // Build a Boot Loader Temporary Memory GUID HOB
104 //
105 if (ApiMode == 0) {
106 BootLoaderTempRamHob = BuildGuidHob (&gFspBootLoaderTempMemoryGuid, BootLoaderTempRamSize);
107 } else {
108 BootLoaderTempRamHob = (VOID *)AllocatePool (BootLoaderTempRamSize);
109 }
110
111 CopyMem (BootLoaderTempRamHob, (VOID *)BootLoaderTempRamStart, BootLoaderTempRamSize);
112 OffsetGap = (UINT32)BootLoaderTempRamHob - BootLoaderTempRamStart;
113
114 //
115 // Set a new stack frame for the continuation function
116 //
117 if (ApiMode == 0) {
118 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();
119 FspInitRtBuffer = (FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr;
120 NewStackTop = (UINT32 *)FspInitRtBuffer->StackTop - 1;
121 SetFspCoreStackPointer (NewStackTop);
122 }
123
124 //
125 // Fix the FspInit Parameter Pointers to the new location.
126 //
127 FspParamPtr = GetFspApiParameter ();
128 if (FspParamPtr >= BootLoaderTempRamStart && FspParamPtr < BootLoaderTempRamEnd) {
129 SetFspApiParameter(FspParamPtr + OffsetGap);
130 }
131
132 FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();
133 if ((UINT32)(FspInitParams->RtBufferPtr) >= BootLoaderTempRamStart &&
134 (UINT32)(FspInitParams->RtBufferPtr) < BootLoaderTempRamEnd) {
135 FspInitParams->RtBufferPtr = (VOID *)((UINT32)(FspInitParams->RtBufferPtr) + OffsetGap);
136 }
137
138 if ((UINT32)(FspInitParams->NvsBufferPtr) >= BootLoaderTempRamStart &&
139 (UINT32)(FspInitParams->NvsBufferPtr) < BootLoaderTempRamEnd) {
140 FspInitParams->NvsBufferPtr = (VOID *)((UINT32)(FspInitParams->NvsBufferPtr) + OffsetGap);
141 }
142
143 if ((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) >= BootLoaderTempRamStart &&
144 (UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) < BootLoaderTempRamEnd) {
145 ((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr = \
146 (VOID *)((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) + OffsetGap);
147 }
148
149 //
150 // Update UPD pointer in FSP Global Data
151 //
152 UpdDataRgnPtr = ((FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr)->UpdDataRgnPtr;
153 if (UpdDataRgnPtr != NULL) {
154 SetFspUpdDataPointer (UpdDataRgnPtr);
155 }
156
157 //
158 // Update Platform data pointer in FSP Global Data
159 //
160 PlatformDataPtr = GetFspPlatformDataPointer ();
161 if (((UINT32)PlatformDataPtr >= BootLoaderTempRamStart) &&
162 ((UINT32)PlatformDataPtr < BootLoaderTempRamEnd)) {
163 SetFspPlatformDataPointer ((UINT8 *)PlatformDataPtr + OffsetGap);
164 }
165 }