3 Copyright (c) 2014 - 2016, 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.
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.
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 <FspGlobalData.h>
27 Get system memory resource descriptor by owner.
29 @param[in] OwnerGuid resource owner guid
31 EFI_HOB_RESOURCE_DESCRIPTOR
*
33 FspGetResourceDescriptorByOwner (
34 IN EFI_GUID
*OwnerGuid
37 EFI_PEI_HOB_POINTERS Hob
;
40 // Get the HOB list for processing
42 Hob
.Raw
= GetHobList ();
45 // Collect memory ranges
47 while (!END_OF_HOB_LIST (Hob
)) {
48 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
49 if ((Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_MEMORY_RESERVED
) && \
50 (CompareGuid (&Hob
.ResourceDescriptor
->Owner
, OwnerGuid
))) {
51 return Hob
.ResourceDescriptor
;
54 Hob
.Raw
= GET_NEXT_HOB (Hob
);
61 Get system memory from HOB.
63 @param[in,out] LowMemoryLength less than 4G memory length
64 @param[in,out] HighMemoryLength greater than 4G memory length
68 FspGetSystemMemorySize (
69 IN OUT UINT64
*LowMemoryLength
,
70 IN OUT UINT64
*HighMemoryLength
74 EFI_BOOT_MODE BootMode
;
75 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
;
76 EFI_PEI_HOB_POINTERS Hob
;
79 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
80 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
81 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
82 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
83 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
84 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
87 Status
= PeiServicesGetBootMode (&BootMode
);
88 ASSERT_EFI_ERROR (Status
);
90 if (BootMode
!= BOOT_ON_S3_RESUME
) {
91 ResourceAttribute
|= EFI_RESOURCE_ATTRIBUTE_TESTED
;
94 *HighMemoryLength
= 0;
95 *LowMemoryLength
= SIZE_1MB
;
97 // Get the HOB list for processing
99 Hob
.Raw
= GetHobList ();
102 // Collect memory ranges
104 while (!END_OF_HOB_LIST (Hob
)) {
105 if (Hob
.Header
->HobType
== EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
106 if ((Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) ||
107 ((Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_MEMORY_RESERVED
) &&
108 (Hob
.ResourceDescriptor
->ResourceAttribute
== ResourceAttribute
))) {
110 // Need memory above 1MB to be collected here
112 if (Hob
.ResourceDescriptor
->PhysicalStart
>= BASE_1MB
&&
113 Hob
.ResourceDescriptor
->PhysicalStart
< (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
114 *LowMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
115 } else if (Hob
.ResourceDescriptor
->PhysicalStart
>= (EFI_PHYSICAL_ADDRESS
) BASE_4GB
) {
116 *HighMemoryLength
+= (UINT64
) (Hob
.ResourceDescriptor
->ResourceLength
);
120 Hob
.Raw
= GET_NEXT_HOB (Hob
);
125 Migrate BootLoader data before destroying CAR.
130 FspMigrateTemporaryMemory (
134 UINT32 BootLoaderTempRamStart
;
135 UINT32 BootLoaderTempRamEnd
;
136 UINT32 BootLoaderTempRamSize
;
139 VOID
*BootLoaderTempRamHob
;
140 UINT32 MemoryInitUpdPtr
;
141 VOID
*PlatformDataPtr
;
144 // Get the temporary memory range used by the BootLoader
146 BootLoaderTempRamStart
= GetFspCarBase ();
147 BootLoaderTempRamSize
= GetFspCarSize () - PcdGet32(PcdFspTemporaryRamSize
);
149 BootLoaderTempRamEnd
= BootLoaderTempRamStart
+ BootLoaderTempRamSize
;
152 // Build a Boot Loader Temporary Memory GUID HOB
154 BootLoaderTempRamHob
= (VOID
*)AllocatePages (EFI_SIZE_TO_PAGES (BootLoaderTempRamSize
));
155 ASSERT(BootLoaderTempRamHob
!= NULL
);
157 DEBUG ((DEBUG_INFO
, "FSP_BOOT_LOADER_TEMPORARY_MEMORY_HOB\n"));
158 DEBUG ((DEBUG_INFO
, "FspBootLoaderTemporaryMemory Base : %x\n", BootLoaderTempRamStart
));
159 DEBUG ((DEBUG_INFO
, "FspBootLoaderTemporaryMemory Size : %x\n", BootLoaderTempRamSize
));
161 CopyMem (BootLoaderTempRamHob
, (VOID
*)BootLoaderTempRamStart
, BootLoaderTempRamSize
);
162 OffsetGap
= (UINT32
)BootLoaderTempRamHob
- BootLoaderTempRamStart
;
165 // Fix the FspMemoryinit Parameter Pointers to the new location.
167 FspParamPtr
= GetFspApiParameter ();
168 if ((VOID
*)FspParamPtr
!= NULL
&& FspParamPtr
>= BootLoaderTempRamStart
&&
169 FspParamPtr
< BootLoaderTempRamEnd
) {
170 SetFspApiParameter (FspParamPtr
+ OffsetGap
);
174 // Update UPD pointer in FSP Global Data
176 MemoryInitUpdPtr
= (UINT32
)((UINT32
*)GetFspMemoryInitUpdDataPointer ());
177 if (MemoryInitUpdPtr
>= BootLoaderTempRamStart
&& MemoryInitUpdPtr
< BootLoaderTempRamEnd
) {
178 SetFspMemoryInitUpdDataPointer ((VOID
*)(MemoryInitUpdPtr
+ OffsetGap
));
182 // Update Platform data pointer in FSP Global Data
184 PlatformDataPtr
= GetFspPlatformDataPointer ();
185 if (((UINT32
)PlatformDataPtr
>= BootLoaderTempRamStart
) &&
186 ((UINT32
)PlatformDataPtr
< BootLoaderTempRamEnd
)) {
187 SetFspPlatformDataPointer ((UINT8
*)PlatformDataPtr
+ OffsetGap
);