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