1 /** @file 2 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. 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 <FspGlobalData.h> 24 #include <FspEas.h> 25 26 /** 27 Get system memory resource descriptor by owner. 28 29 @param[in] OwnerGuid resource owner guid 30 **/ 31 EFI_HOB_RESOURCE_DESCRIPTOR * 32 EFIAPI FspGetResourceDescriptorByOwner(IN EFI_GUID * OwnerGuid)33FspGetResourceDescriptorByOwner ( 34 IN EFI_GUID *OwnerGuid 35 ) 36 { 37 EFI_PEI_HOB_POINTERS Hob; 38 39 // 40 // Get the HOB list for processing 41 // 42 Hob.Raw = GetHobList (); 43 44 // 45 // Collect memory ranges 46 // 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; 52 } 53 } 54 Hob.Raw = GET_NEXT_HOB (Hob); 55 } 56 57 return NULL; 58 } 59 60 /** 61 Get system memory from HOB. 62 63 @param[in,out] LowMemoryLength less than 4G memory length 64 @param[in,out] HighMemoryLength greater than 4G memory length 65 **/ 66 VOID 67 EFIAPI FspGetSystemMemorySize(IN OUT UINT64 * LowMemoryLength,IN OUT UINT64 * HighMemoryLength)68FspGetSystemMemorySize ( 69 IN OUT UINT64 *LowMemoryLength, 70 IN OUT UINT64 *HighMemoryLength 71 ) 72 { 73 EFI_STATUS Status; 74 EFI_BOOT_MODE BootMode; 75 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute; 76 EFI_PEI_HOB_POINTERS Hob; 77 78 ResourceAttribute = ( 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 85 ); 86 87 Status = PeiServicesGetBootMode (&BootMode); 88 ASSERT_EFI_ERROR (Status); 89 90 if (BootMode != BOOT_ON_S3_RESUME) { 91 ResourceAttribute |= EFI_RESOURCE_ATTRIBUTE_TESTED; 92 } 93 94 *HighMemoryLength = 0; 95 *LowMemoryLength = SIZE_1MB; 96 // 97 // Get the HOB list for processing 98 // 99 Hob.Raw = GetHobList (); 100 101 // 102 // Collect memory ranges 103 // 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))) { 109 // 110 // Need memory above 1MB to be collected here 111 // 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); 117 } 118 } 119 } 120 Hob.Raw = GET_NEXT_HOB (Hob); 121 } 122 } 123