3 Copyright (c) 2014 - 2018, 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
);