TianoCore EDK2 master
Loading...
Searching...
No Matches
NonMmramMapStandaloneMm.c
Go to the documentation of this file.
1
8#include "PiSmmCpuCommon.h"
9
21 IN OUT UINT64 *Size
22 )
23{
24 EFI_PEI_HOB_POINTERS SmmProfileDataHob;
25
26 ASSERT (Size != NULL);
27
28 //
29 // Get Smm Profile Base from Memory Allocation HOB
30 //
31 SmmProfileDataHob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
32 while (SmmProfileDataHob.Raw != NULL) {
33 //
34 // Find gMmProfileDataHobGuid
35 //
36 if (CompareGuid (&SmmProfileDataHob.MemoryAllocation->AllocDescriptor.Name, &gMmProfileDataHobGuid)) {
37 break;
38 }
39
40 SmmProfileDataHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (SmmProfileDataHob));
41 }
42
43 if (SmmProfileDataHob.Raw == NULL) {
44 *Size = 0;
45 return 0;
46 }
47
48 *Size = SmmProfileDataHob.MemoryAllocation->AllocDescriptor.MemoryLength;
49
50 return SmmProfileDataHob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress;
51}
52
61BOOLEAN
63 IN UINT64 Address
64 )
65{
67
68 Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
69 while (Hob.Raw != NULL) {
70 if ((Address >= Hob.ResourceDescriptor->PhysicalStart) && (Address < Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength)) {
71 if ((Hob.ResourceDescriptor->ResourceAttribute & MM_RESOURCE_ATTRIBUTE_LOGGING) != 0) {
72 return TRUE;
73 }
74
75 return FALSE;
76 }
77
78 Hob.Raw = GET_NEXT_HOB (Hob);
79 Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);
80 }
81
82 return FALSE;
83}
84
93BOOLEAN
95 IN UINT64 Address
96 )
97{
99
100 Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
101 while (Hob.Raw != NULL) {
102 if ((Address >= Hob.ResourceDescriptor->PhysicalStart) && (Address < Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength)) {
103 return FALSE;
104 }
105
106 Hob.Raw = GET_NEXT_HOB (Hob);
107 Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);
108 }
109
110 return TRUE;
111}
112
119VOID
121 OUT MM_CPU_MEMORY_REGION **MemoryRegion,
122 OUT UINTN *MemoryRegionCount
123 )
124{
126 UINTN Count;
127 UINTN Index;
128
129 ASSERT (MemoryRegion != NULL && MemoryRegionCount != NULL);
130
131 *MemoryRegion = NULL;
132 *MemoryRegionCount = 0;
133
134 //
135 // Get the count.
136 //
137 Count = 0;
138 Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
139 while (Hob.Raw != NULL) {
140 if ((Hob.ResourceDescriptor->ResourceAttribute & MM_RESOURCE_ATTRIBUTE_LOGGING) == 0) {
141 //
142 // Resource HOBs describe all accessible non-smram regions.
143 // Logging attribute range is treated as not present. Not-present ranges are not included in this memory map.
144 //
145 Count++;
146 }
147
148 Hob.Raw = GET_NEXT_HOB (Hob);
149 Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);
150 }
151
152 *MemoryRegionCount = Count;
153
154 *MemoryRegion = (MM_CPU_MEMORY_REGION *)AllocateZeroPool (sizeof (MM_CPU_MEMORY_REGION) * Count);
155 ASSERT (*MemoryRegion != NULL);
156
157 Index = 0;
158 Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
159 while (Hob.Raw != NULL) {
160 if ((Hob.ResourceDescriptor->ResourceAttribute & MM_RESOURCE_ATTRIBUTE_LOGGING) == 0) {
161 ASSERT (Index < Count);
162 (*MemoryRegion)[Index].Base = Hob.ResourceDescriptor->PhysicalStart;
163 (*MemoryRegion)[Index].Length = Hob.ResourceDescriptor->ResourceLength;
164 (*MemoryRegion)[Index].Attribute = EFI_MEMORY_XP;
165 if (Hob.ResourceDescriptor->ResourceAttribute == EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED) {
166 (*MemoryRegion)[Index].Attribute |= EFI_MEMORY_RO;
167 }
168
169 Index++;
170 }
171
172 Hob.Raw = GET_NEXT_HOB (Hob);
173 Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);
174 }
175
176 return;
177}
178
187VOID
189 OUT MM_CPU_MEMORY_REGION **MemoryRegion,
190 OUT UINTN *MemoryRegionCount
191 )
192{
193 BuildMemoryMapFromResDescHobs (MemoryRegion, MemoryRegionCount);
194}
195
206VOID
208 IN UINT8 PhysicalAddressBits,
209 OUT MM_CPU_MEMORY_REGION **MemoryRegion,
210 OUT UINTN *MemoryRegionCount
211 )
212{
213 BuildMemoryMapFromResDescHobs (MemoryRegion, MemoryRegionCount);
214}
UINT64 UINTN
VOID *EFIAPI GetFirstHob(IN UINT16 Type)
Definition: HobLib.c:142
VOID *EFIAPI GetNextHob(IN UINT16 Type, IN CONST VOID *HobStart)
Definition: HobLib.c:103
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define MM_RESOURCE_ATTRIBUTE_LOGGING
Definition: MmProfileData.h:31
VOID BuildMemoryMapFromResDescHobs(OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
BOOLEAN IsNonMmramLoggingAddress(IN UINT64 Address)
VOID CreateExtendedProtectionRange(OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
EFI_PHYSICAL_ADDRESS GetSmmProfileData(IN OUT UINT64 *Size)
VOID CreateNonMmramMemMap(IN UINT8 PhysicalAddressBits, OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
BOOLEAN IsSmmCommBufferForbiddenAddress(IN UINT64 Address)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
EFI_PHYSICAL_ADDRESS MemoryBaseAddress
Definition: PiHob.h:119
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor
Definition: PiHob.h:153
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: PiHob.h:328
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
Definition: PiHob.h:324