IntelFsp2Pkg BaseFspPlatformLib: Remove Boot Loader tempram Migration
[mirror_edk2.git] / IntelFsp2Pkg / Library / BaseFspPlatformLib / FspPlatformMemory.c
CommitLineData
cf1d4549
JY
1/** @file\r
2\r
3 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php.\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include <PiPei.h>\r
15#include <Library/BaseLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/MemoryAllocationLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/PcdLib.h>\r
20#include <Library/HobLib.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Library/FspCommonLib.h>\r
23#include <FspGlobalData.h>\r
24#include <FspEas.h>\r
25\r
26/**\r
27 Get system memory resource descriptor by owner.\r
28\r
29 @param[in] OwnerGuid resource owner guid\r
30**/\r
31EFI_HOB_RESOURCE_DESCRIPTOR *\r
32EFIAPI\r
33FspGetResourceDescriptorByOwner (\r
34 IN EFI_GUID *OwnerGuid\r
35 )\r
36{\r
37 EFI_PEI_HOB_POINTERS Hob;\r
38\r
39 //\r
40 // Get the HOB list for processing\r
41 //\r
42 Hob.Raw = GetHobList ();\r
43\r
44 //\r
45 // Collect memory ranges\r
46 //\r
47 while (!END_OF_HOB_LIST (Hob)) {\r
48 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
49 if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) && \\r
50 (CompareGuid (&Hob.ResourceDescriptor->Owner, OwnerGuid))) {\r
51 return Hob.ResourceDescriptor; \r
52 }\r
53 }\r
54 Hob.Raw = GET_NEXT_HOB (Hob);\r
55 }\r
56 \r
57 return NULL;\r
58}\r
59\r
60/**\r
61 Get system memory from HOB.\r
62\r
63 @param[in,out] LowMemoryLength less than 4G memory length\r
64 @param[in,out] HighMemoryLength greater than 4G memory length\r
65**/\r
66VOID\r
67EFIAPI\r
68FspGetSystemMemorySize (\r
69 IN OUT UINT64 *LowMemoryLength,\r
70 IN OUT UINT64 *HighMemoryLength\r
71 )\r
72{\r
73 EFI_STATUS Status;\r
74 EFI_BOOT_MODE BootMode;\r
75 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;\r
76 EFI_PEI_HOB_POINTERS Hob;\r
77\r
78 ResourceAttribute = (\r
79 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
80 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
81 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
82 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
83 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
84 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
85 );\r
86\r
87 Status = PeiServicesGetBootMode (&BootMode);\r
88 ASSERT_EFI_ERROR (Status);\r
89\r
90 if (BootMode != BOOT_ON_S3_RESUME) {\r
91 ResourceAttribute |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
92 }\r
93\r
94 *HighMemoryLength = 0;\r
95 *LowMemoryLength = SIZE_1MB;\r
96 //\r
97 // Get the HOB list for processing\r
98 //\r
99 Hob.Raw = GetHobList ();\r
100\r
101 //\r
102 // Collect memory ranges\r
103 //\r
104 while (!END_OF_HOB_LIST (Hob)) {\r
105 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
106 if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) ||\r
107 ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) &&\r
108 (Hob.ResourceDescriptor->ResourceAttribute == ResourceAttribute))) {\r
109 //\r
110 // Need memory above 1MB to be collected here\r
111 //\r
112 if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB &&\r
113 Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
114 *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
115 } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
116 *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
117 }\r
118 }\r
119 }\r
120 Hob.Raw = GET_NEXT_HOB (Hob);\r
121 }\r
122}\r