TianoCore EDK2 master
Loading...
Searching...
No Matches
FspPlatformMemory.c
Go to the documentation of this file.
1
8#include <PiPei.h>
10#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
14#include <Library/PcdLib.h>
15#include <Library/HobLib.h>
18#include <FspGlobalData.h>
19#include <FspEas.h>
20
27EFIAPI
29 IN EFI_GUID *OwnerGuid
30 )
31{
33
34 //
35 // Get the HOB list for processing
36 //
37 Hob.Raw = GetHobList ();
38
39 //
40 // Collect memory ranges
41 //
42 while (!END_OF_HOB_LIST (Hob)) {
43 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
44 if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) && \
45 (CompareGuid (&Hob.ResourceDescriptor->Owner, OwnerGuid)))
46 {
47 return Hob.ResourceDescriptor;
48 }
49 }
50
51 Hob.Raw = GET_NEXT_HOB (Hob);
52 }
53
54 return NULL;
55}
56
63VOID
64EFIAPI
66 IN OUT UINT64 *LowMemoryLength,
67 IN OUT UINT64 *HighMemoryLength
68 )
69{
70 EFI_STATUS Status;
71 EFI_BOOT_MODE BootMode;
72 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
74
75 ResourceAttribute = (
76 EFI_RESOURCE_ATTRIBUTE_PRESENT |
77 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
78 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
79 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
80 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
81 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
82 );
83
84 Status = PeiServicesGetBootMode (&BootMode);
85 ASSERT_EFI_ERROR (Status);
86
87 if (BootMode != BOOT_ON_S3_RESUME) {
88 ResourceAttribute |= EFI_RESOURCE_ATTRIBUTE_TESTED;
89 }
90
91 *HighMemoryLength = 0;
92 *LowMemoryLength = SIZE_1MB;
93 //
94 // Get the HOB list for processing
95 //
96 Hob.Raw = GetHobList ();
97
98 //
99 // Collect memory ranges
100 //
101 while (!END_OF_HOB_LIST (Hob)) {
102 if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
103 if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) ||
104 ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) &&
105 (Hob.ResourceDescriptor->ResourceAttribute == ResourceAttribute)))
106 {
107 //
108 // Need memory above 1MB to be collected here
109 //
110 if ((Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB) &&
111 (Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS)BASE_4GB))
112 {
113 *LowMemoryLength += (UINT64)(Hob.ResourceDescriptor->ResourceLength);
114 } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS)BASE_4GB) {
115 *HighMemoryLength += (UINT64)(Hob.ResourceDescriptor->ResourceLength);
116 }
117 }
118 }
119
120 Hob.Raw = GET_NEXT_HOB (Hob);
121 }
122}
123
130VOID
131EFIAPI
133 IN UINT32 TemporaryRamBase,
134 OUT UINT32 *TemporaryRamSize
135 )
136{
138 UINT32 MsrNum;
139 UINT32 MsrNumEnd;
140
141 if (TemporaryRamBase == 0) {
142 return;
143 }
144
145 *TemporaryRamSize = 0;
146 Msr.Uint64 = AsmReadMsr64 (MSR_IA32_MTRRCAP);
147 MsrNumEnd = MSR_IA32_MTRR_PHYSBASE0 + (2 * (Msr.Bits.VCNT));
148
149 for (MsrNum = MSR_IA32_MTRR_PHYSBASE0; MsrNum < MsrNumEnd; MsrNum += 2) {
150 if ((AsmReadMsr64 (MsrNum+1) & BIT11) != 0 ) {
151 if (TemporaryRamBase == (AsmReadMsr64 (MsrNum) & 0xFFFFF000)) {
152 *TemporaryRamSize = (~(AsmReadMsr64 (MsrNum + 1) & 0xFFFFF000) + 1);
153 break;
154 }
155 }
156 }
157
158 return;
159}
VOID *EFIAPI GetHobList(VOID)
Definition: HobLib.c:76
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS EFIAPI PeiServicesGetBootMode(OUT EFI_BOOT_MODE *BootMode)
VOID EFIAPI ReadTemporaryRamSize(IN UINT32 TemporaryRamBase, OUT UINT32 *TemporaryRamSize)
VOID EFIAPI FspGetSystemMemorySize(IN OUT UINT64 *LowMemoryLength, IN OUT UINT64 *HighMemoryLength)
EFI_HOB_RESOURCE_DESCRIPTOR *EFIAPI FspGetResourceDescriptorByOwner(IN EFI_GUID *OwnerGuid)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition: GccInlinePriv.c:60
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define MSR_IA32_MTRR_PHYSBASE0
#define MSR_IA32_MTRRCAP
UINT32 EFI_BOOT_MODE
Definition: PiBootMode.h:18
UINT32 EFI_RESOURCE_ATTRIBUTE_TYPE
Definition: PiHob.h:241
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: PiHob.h:328
EFI_RESOURCE_TYPE ResourceType
Definition: PiHob.h:320
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
Definition: PiHob.h:324
Definition: Base.h:213