TianoCore EDK2 master
Loading...
Searching...
No Matches
NonMmramMapDxeSmm.c
Go to the documentation of this file.
1
8#include "PiSmmCpuCommon.h"
12
13//
14// attributes for reserved memory before it is promoted to system memory
15//
16#define EFI_MEMORY_PRESENT 0x0100000000000000ULL
17#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
18#define EFI_MEMORY_TESTED 0x0400000000000000ULL
19
20#define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
21 ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
22
23EFI_MEMORY_DESCRIPTOR *mUefiMemoryMap;
24UINTN mUefiMemoryMapSize;
25UINTN mUefiDescriptorSize;
26
28UINTN mGcdMemNumberOfDesc = 0;
29
30EFI_MEMORY_ATTRIBUTES_TABLE *mUefiMemoryAttributesTable = NULL;
31
41VOID
43 IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
44 IN UINTN MemoryMapSize,
45 IN UINTN DescriptorSize
46 )
47{
48 EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
49 EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
50 EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
51 EFI_MEMORY_DESCRIPTOR TempMemoryMap;
52
53 MemoryMapEntry = MemoryMap;
54 NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
55 MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
56 while (MemoryMapEntry < MemoryMapEnd) {
57 while (NextMemoryMapEntry < MemoryMapEnd) {
58 if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStart) {
59 CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
60 CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
61 CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DESCRIPTOR));
62 }
63
64 NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
65 }
66
67 MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
68 NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
69 }
70}
71
84BOOLEAN
86 IN EFI_MEMORY_DESCRIPTOR *MemoryMap
87 )
88{
89 switch (MemoryMap->Type) {
90 case EfiLoaderCode:
91 case EfiLoaderData:
97 return TRUE;
98 default:
99 return FALSE;
100 }
101}
102
117STATIC
118VOID
120 IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
121 IN OUT UINTN *MemoryMapSize,
122 IN UINTN DescriptorSize
123 )
124{
125 EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
126 EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
127 UINT64 MemoryBlockLength;
128 EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
129 EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
130
131 MemoryMapEntry = MemoryMap;
132 NewMemoryMapEntry = MemoryMap;
133 MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + *MemoryMapSize);
134 while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
135 CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
136 NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
137
138 do {
139 MemoryBlockLength = (UINT64)(EFI_PAGES_TO_SIZE ((UINTN)MemoryMapEntry->NumberOfPages));
140 if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) &&
141 IsUefiPageNotPresent (MemoryMapEntry) && IsUefiPageNotPresent (NextMemoryMapEntry) &&
142 ((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart))
143 {
144 MemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
145 if (NewMemoryMapEntry != MemoryMapEntry) {
146 NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
147 }
148
149 NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
150 continue;
151 } else {
152 MemoryMapEntry = PREVIOUS_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
153 break;
154 }
155 } while (TRUE);
156
157 MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
158 NewMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NewMemoryMapEntry, DescriptorSize);
159 }
160
161 *MemoryMapSize = (UINTN)NewMemoryMapEntry - (UINTN)MemoryMap;
162
163 return;
164}
165
169VOID
171 VOID
172 )
173{
174 UINTN NumberOfDescriptors;
176 EFI_STATUS Status;
177 UINTN Index;
178
179 Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemSpaceMap);
180 if (EFI_ERROR (Status)) {
181 return;
182 }
183
184 mGcdMemNumberOfDesc = 0;
185 for (Index = 0; Index < NumberOfDescriptors; Index++) {
186 if ((MemSpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
187 ((MemSpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
188 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
189 )
190 {
191 mGcdMemNumberOfDesc++;
192 }
193 }
194
195 mGcdMemSpace = AllocateZeroPool (mGcdMemNumberOfDesc * sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR));
196 ASSERT (mGcdMemSpace != NULL);
197 if (mGcdMemSpace == NULL) {
198 mGcdMemNumberOfDesc = 0;
199 gBS->FreePool (MemSpaceMap);
200 return;
201 }
202
203 mGcdMemNumberOfDesc = 0;
204 for (Index = 0; Index < NumberOfDescriptors; Index++) {
205 if ((MemSpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved) &&
206 ((MemSpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
207 (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED))
208 )
209 {
210 CopyMem (
211 &mGcdMemSpace[mGcdMemNumberOfDesc],
212 &MemSpaceMap[Index],
214 );
215 mGcdMemNumberOfDesc++;
216 }
217 }
218
219 gBS->FreePool (MemSpaceMap);
220}
221
225VOID
227 VOID
228 )
229{
230 EFI_STATUS Status;
231 EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
232 UINTN MemoryAttributesTableSize;
233
234 Status = EfiGetSystemConfigurationTable (&gEfiMemoryAttributesTableGuid, (VOID **)&MemoryAttributesTable);
235 if (!EFI_ERROR (Status) && (MemoryAttributesTable != NULL)) {
236 MemoryAttributesTableSize = sizeof (EFI_MEMORY_ATTRIBUTES_TABLE) + MemoryAttributesTable->DescriptorSize * MemoryAttributesTable->NumberOfEntries;
237 mUefiMemoryAttributesTable = AllocateCopyPool (MemoryAttributesTableSize, MemoryAttributesTable);
238 ASSERT (mUefiMemoryAttributesTable != NULL);
239 }
240}
241
245VOID
247 VOID
248 )
249{
250 EFI_STATUS Status;
251 UINTN MapKey;
252 UINT32 DescriptorVersion;
253 EFI_MEMORY_DESCRIPTOR *MemoryMap;
254 UINTN UefiMemoryMapSize;
255
256 DEBUG ((DEBUG_INFO, "GetUefiMemoryMap\n"));
257
258 UefiMemoryMapSize = 0;
259 MemoryMap = NULL;
260 Status = gBS->GetMemoryMap (
261 &UefiMemoryMapSize,
262 MemoryMap,
263 &MapKey,
264 &mUefiDescriptorSize,
265 &DescriptorVersion
266 );
267 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
268
269 do {
270 Status = gBS->AllocatePool (EfiBootServicesData, UefiMemoryMapSize, (VOID **)&MemoryMap);
271 ASSERT (MemoryMap != NULL);
272 if (MemoryMap == NULL) {
273 return;
274 }
275
276 Status = gBS->GetMemoryMap (
277 &UefiMemoryMapSize,
278 MemoryMap,
279 &MapKey,
280 &mUefiDescriptorSize,
281 &DescriptorVersion
282 );
283 if (EFI_ERROR (Status)) {
284 gBS->FreePool (MemoryMap);
285 MemoryMap = NULL;
286 }
287 } while (Status == EFI_BUFFER_TOO_SMALL);
288
289 if (MemoryMap == NULL) {
290 return;
291 }
292
293 SortMemoryMap (MemoryMap, UefiMemoryMapSize, mUefiDescriptorSize);
294 MergeMemoryMapForNotPresentEntry (MemoryMap, &UefiMemoryMapSize, mUefiDescriptorSize);
295
296 mUefiMemoryMapSize = UefiMemoryMapSize;
297 mUefiMemoryMap = AllocateCopyPool (UefiMemoryMapSize, MemoryMap);
298 ASSERT (mUefiMemoryMap != NULL);
299
300 gBS->FreePool (MemoryMap);
301
302 //
303 // Get additional information from GCD memory map.
304 //
306
307 //
308 // Get UEFI memory attributes table.
309 //
311}
312
317VOID
319 VOID
320 )
321{
322 BOOLEAN WriteProtect;
323 BOOLEAN CetEnabled;
324 EFI_STATUS Status;
325 UINTN Index;
326 UINT64 Limit;
327 UINT64 PreviousAddress;
328 UINTN PageTable;
329 UINT64 Base;
330 EFI_MEMORY_DESCRIPTOR *MemoryMap;
331 UINTN MemoryMapEntryCount;
333
334 DEBUG ((DEBUG_INFO, "UpdateUefiMemMapAttributes Start...\n"));
335
336 WRITE_UNPROTECT_RO_PAGES (WriteProtect, CetEnabled);
337
338 PageTable = AsmReadCr3 ();
339 Limit = LShiftU64 (1, mPhysicalAddressBits);
340
341 //
342 // [0, 4k] may be non-present.
343 //
344 PreviousAddress = ((FixedPcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT1) != 0) ? BASE_4KB : 0;
345
346 //
347 // NonMmram shall be non-executable after the SmmReadyToLock event occurs, regardless of whether
348 // RestrictedMemoryAccess is enabled, since all MM drivers located in NonMmram have already been dispatched and executed.
349 //
350 for (Index = 0; Index < mSmmCpuSmramRangeCount; Index++) {
351 Base = mSmmCpuSmramRanges[Index].CpuStart;
352 if (Base > PreviousAddress) {
353 Status = ConvertMemoryPageAttributes (PageTable, mPagingMode, PreviousAddress, Base - PreviousAddress, EFI_MEMORY_XP, TRUE, NULL);
354 ASSERT_RETURN_ERROR (Status);
355 }
356
357 PreviousAddress = mSmmCpuSmramRanges[Index].CpuStart + mSmmCpuSmramRanges[Index].PhysicalSize;
358 }
359
360 if (PreviousAddress < Limit) {
361 Status = ConvertMemoryPageAttributes (PageTable, mPagingMode, PreviousAddress, Limit - PreviousAddress, EFI_MEMORY_XP, TRUE, NULL);
362 ASSERT_RETURN_ERROR (Status);
363 }
364
365 //
366 // Set NonMmram to not-present by excluding "RT, Reserved and NVS" memory type when RestrictedMemoryAccess is enabled.
367 //
369 if (mUefiMemoryMap != NULL) {
370 MemoryMapEntryCount = mUefiMemoryMapSize/mUefiDescriptorSize;
371 MemoryMap = mUefiMemoryMap;
372 for (Index = 0; Index < MemoryMapEntryCount; Index++) {
373 if (IsUefiPageNotPresent (MemoryMap)) {
375 PageTable,
376 mPagingMode,
377 MemoryMap->PhysicalStart,
379 EFI_MEMORY_RP,
380 TRUE,
381 NULL
382 );
383 DEBUG ((
384 DEBUG_INFO,
385 "UefiMemory protection: 0x%lx - 0x%lx %r\n",
386 MemoryMap->PhysicalStart,
387 MemoryMap->PhysicalStart + (UINT64)EFI_PAGES_TO_SIZE ((UINTN)MemoryMap->NumberOfPages),
388 Status
389 ));
390 }
391
392 MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, mUefiDescriptorSize);
393 }
394 }
395
396 //
397 // Do not free mUefiMemoryMap, it will be checked in IsSmmCommBufferForbiddenAddress().
398 //
399
400 //
401 // Set untested NonMmram memory as not present.
402 //
403 if (mGcdMemSpace != NULL) {
404 for (Index = 0; Index < mGcdMemNumberOfDesc; Index++) {
406 PageTable,
407 mPagingMode,
408 mGcdMemSpace[Index].BaseAddress,
409 mGcdMemSpace[Index].Length,
410 EFI_MEMORY_RP,
411 TRUE,
412 NULL
413 );
414 DEBUG ((
415 DEBUG_INFO,
416 "GcdMemory protection: 0x%lx - 0x%lx %r\n",
417 mGcdMemSpace[Index].BaseAddress,
418 mGcdMemSpace[Index].BaseAddress + mGcdMemSpace[Index].Length,
419 Status
420 ));
421 }
422 }
423
424 //
425 // Do not free mGcdMemSpace, it will be checked in IsSmmCommBufferForbiddenAddress().
426 //
427
428 //
429 // Above logic sets the whole RT memory as present.
430 // Below logic is to set the RT code as not present.
431 //
432 if (mUefiMemoryAttributesTable != NULL) {
433 Entry = (EFI_MEMORY_DESCRIPTOR *)(mUefiMemoryAttributesTable + 1);
434 for (Index = 0; Index < mUefiMemoryAttributesTable->NumberOfEntries; Index++) {
435 if ((Entry->Type == EfiRuntimeServicesCode) || (Entry->Type == EfiRuntimeServicesData)) {
436 if ((Entry->Attribute & EFI_MEMORY_RO) != 0) {
438 PageTable,
439 mPagingMode,
440 Entry->PhysicalStart,
441 EFI_PAGES_TO_SIZE ((UINTN)Entry->NumberOfPages),
442 EFI_MEMORY_RP,
443 TRUE,
444 NULL
445 );
446 DEBUG ((
447 DEBUG_INFO,
448 "UefiMemoryAttribute protection: 0x%lx - 0x%lx %r\n",
449 Entry->PhysicalStart,
450 Entry->PhysicalStart + (UINT64)EFI_PAGES_TO_SIZE ((UINTN)Entry->NumberOfPages),
451 Status
452 ));
453 }
454 }
455
456 Entry = NEXT_MEMORY_DESCRIPTOR (Entry, mUefiMemoryAttributesTable->DescriptorSize);
457 }
458 }
459
460 //
461 // Do not free mUefiMemoryAttributesTable, it will be checked in IsSmmCommBufferForbiddenAddress().
462 //
463 }
464
465 //
466 // Flush TLB
467 //
468 CpuFlushTlb ();
469
470 //
471 // Set execute-disable flag
472 //
473 mXdEnabled = TRUE;
474
475 WRITE_PROTECT_RO_PAGES (WriteProtect, CetEnabled);
476
477 DEBUG ((DEBUG_INFO, "UpdateUefiMemMapAttributes Done.\n"));
478}
479
490 IN OUT UINT64 *Size
491 )
492{
493 EFI_STATUS Status;
495
496 ASSERT (Size != NULL);
497
498 *Size = PcdGet32 (PcdCpuSmmProfileSize);
499
500 Base = 0xFFFFFFFF;
501 Status = gBS->AllocatePages (
504 (UINTN)EFI_SIZE_TO_PAGES (*Size),
505 &Base
506 );
507 ASSERT_EFI_ERROR (Status);
508 ZeroMem ((VOID *)(UINTN)Base, (UINTN)*Size);
509
510 return Base;
511}
512
521BOOLEAN
523 IN UINT64 Address
524 )
525{
526 ASSERT (FALSE);
527
528 return TRUE;
529}
530
539BOOLEAN
541 IN UINT64 Address
542 )
543{
544 EFI_MEMORY_DESCRIPTOR *MemoryMap;
545 UINTN MemoryMapEntryCount;
546 UINTN Index;
548
549 if (!IsRestrictedMemoryAccess ()) {
550 return FALSE;
551 }
552
553 if (mUefiMemoryMap != NULL) {
554 MemoryMap = mUefiMemoryMap;
555 MemoryMapEntryCount = mUefiMemoryMapSize/mUefiDescriptorSize;
556 for (Index = 0; Index < MemoryMapEntryCount; Index++) {
557 if (IsUefiPageNotPresent (MemoryMap)) {
558 if ((Address >= MemoryMap->PhysicalStart) &&
559 (Address < MemoryMap->PhysicalStart + EFI_PAGES_TO_SIZE ((UINTN)MemoryMap->NumberOfPages)))
560 {
561 return TRUE;
562 }
563 }
564
565 MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, mUefiDescriptorSize);
566 }
567 }
568
569 if (mGcdMemSpace != NULL) {
570 for (Index = 0; Index < mGcdMemNumberOfDesc; Index++) {
571 if ((Address >= mGcdMemSpace[Index].BaseAddress) &&
572 (Address < mGcdMemSpace[Index].BaseAddress + mGcdMemSpace[Index].Length))
573 {
574 return TRUE;
575 }
576 }
577 }
578
579 if (mUefiMemoryAttributesTable != NULL) {
580 Entry = (EFI_MEMORY_DESCRIPTOR *)(mUefiMemoryAttributesTable + 1);
581 for (Index = 0; Index < mUefiMemoryAttributesTable->NumberOfEntries; Index++) {
582 if ((Entry->Type == EfiRuntimeServicesCode) || (Entry->Type == EfiRuntimeServicesData)) {
583 if ((Entry->Attribute & EFI_MEMORY_RO) != 0) {
584 if ((Address >= Entry->PhysicalStart) &&
585 (Address < Entry->PhysicalStart + LShiftU64 (Entry->NumberOfPages, EFI_PAGE_SHIFT)))
586 {
587 return TRUE;
588 }
589
590 Entry = NEXT_MEMORY_DESCRIPTOR (Entry, mUefiMemoryAttributesTable->DescriptorSize);
591 }
592 }
593 }
594 }
595
596 return FALSE;
597}
598
608VOID
610 OUT MM_CPU_MEMORY_REGION **MemoryRegion,
611 OUT UINTN *MemoryRegionCount
612 )
613{
614 UINTN Index;
615 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
616 UINTN NumberOfSpaceDescriptors;
617 UINTN MemoryRegionIndex;
618 UINTN Count;
619
620 MemorySpaceMap = NULL;
621 NumberOfSpaceDescriptors = 0;
622 Count = 0;
623
624 ASSERT (MemoryRegion != NULL && MemoryRegionCount != NULL);
625
626 *MemoryRegion = NULL;
627 *MemoryRegionCount = 0;
628
629 //
630 // Get MMIO ranges from GCD.
631 //
632 gDS->GetMemorySpaceMap (
633 &NumberOfSpaceDescriptors,
634 &MemorySpaceMap
635 );
636 for (Index = 0; Index < NumberOfSpaceDescriptors; Index++) {
637 if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
638 if (ADDRESS_IS_ALIGNED (MemorySpaceMap[Index].BaseAddress, SIZE_4KB) &&
639 (MemorySpaceMap[Index].Length % SIZE_4KB == 0))
640 {
641 Count++;
642 } else {
643 //
644 // Skip the MMIO range that BaseAddress and Length are not 4k aligned since
645 // the minimum granularity of the page table is 4k
646 //
647 DEBUG ((
648 DEBUG_WARN,
649 "MMIO range [0x%lx, 0x%lx] is skipped since it is not 4k aligned.\n",
650 MemorySpaceMap[Index].BaseAddress,
651 MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length
652 ));
653 }
654 }
655 }
656
657 *MemoryRegionCount = Count;
658
659 *MemoryRegion = (MM_CPU_MEMORY_REGION *)AllocateZeroPool (sizeof (MM_CPU_MEMORY_REGION) * Count);
660 ASSERT (*MemoryRegion != NULL);
661
662 MemoryRegionIndex = 0;
663 for (Index = 0; Index < NumberOfSpaceDescriptors; Index++) {
664 if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
665 ADDRESS_IS_ALIGNED (MemorySpaceMap[Index].BaseAddress, SIZE_4KB) &&
666 (MemorySpaceMap[Index].Length % SIZE_4KB == 0))
667 {
668 (*MemoryRegion)[MemoryRegionIndex].Base = MemorySpaceMap[Index].BaseAddress;
669 (*MemoryRegion)[MemoryRegionIndex].Length = MemorySpaceMap[Index].Length;
670 MemoryRegionIndex++;
671 }
672 }
673
674 return;
675}
676
688VOID
690 IN UINT8 PhysicalAddressBits,
691 OUT MM_CPU_MEMORY_REGION **MemoryRegion,
692 OUT UINTN *MemoryRegionCount
693 )
694{
695 UINT64 MaxLength;
696 UINTN Count;
697 UINTN Index;
698 UINT64 PreviousAddress;
699 UINT64 Base;
700 UINT64 Length;
701
702 ASSERT (MemoryRegion != NULL && MemoryRegionCount != NULL);
703
704 *MemoryRegion = NULL;
705 *MemoryRegionCount = 0;
706
707 MaxLength = LShiftU64 (1, PhysicalAddressBits);
708
709 //
710 // Build MemoryRegion to cover [0, 2^PhysicalAddressBits) by excluding all Smram range
711 //
712 Count = mSmmCpuSmramRangeCount + 1;
713
714 *MemoryRegionCount = Count;
715
716 *MemoryRegion = (MM_CPU_MEMORY_REGION *)AllocateZeroPool (sizeof (MM_CPU_MEMORY_REGION) * Count);
717 ASSERT (*MemoryRegion != NULL);
718
719 PreviousAddress = 0;
720 for (Index = 0; Index < mSmmCpuSmramRangeCount; Index++) {
721 Base = mSmmCpuSmramRanges[Index].CpuStart;
722 Length = mSmmCpuSmramRanges[Index].PhysicalSize;
723
724 ASSERT (MaxLength > Base + Length);
725
726 if (Base > PreviousAddress) {
727 (*MemoryRegion)[Index].Base = PreviousAddress;
728 (*MemoryRegion)[Index].Length = Base - PreviousAddress;
729 (*MemoryRegion)[Index].Attribute = 0;
730 }
731
732 PreviousAddress = Base + Length;
733 }
734
735 //
736 // Set the last remaining range
737 //
738 if (PreviousAddress < MaxLength) {
739 (*MemoryRegion)[Index].Base = PreviousAddress;
740 (*MemoryRegion)[Index].Length = MaxLength - PreviousAddress;
741 }
742}
UINT64 UINTN
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI CpuFlushTlb(VOID)
RETURN_STATUS ConvertMemoryPageAttributes(IN PAGE_TABLE_LIB_PAGING_CONTEXT *PagingContext OPTIONAL, IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN PAGE_ACTION PageAction, IN PAGE_TABLE_LIB_ALLOCATE_PAGES AllocatePagesFunc OPTIONAL, OUT BOOLEAN *IsSplitted OPTIONAL, OUT BOOLEAN *IsModified OPTIONAL)
Definition: CpuPageTable.c:719
EFI_DXE_SERVICES * gDS
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
UINTN EFIAPI AsmReadCr3(VOID)
BOOLEAN IsRestrictedMemoryAccess(VOID)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define ADDRESS_IS_ALIGNED(Address, Alignment)
Definition: Base.h:923
#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 ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define ASSERT_RETURN_ERROR(StatusParameter)
Definition: DebugLib.h:493
#define DEBUG(Expression)
Definition: DebugLib.h:434
BOOLEAN IsNonMmramLoggingAddress(IN UINT64 Address)
VOID CreateExtendedProtectionRange(OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
BOOLEAN IsUefiPageNotPresent(IN EFI_MEMORY_DESCRIPTOR *MemoryMap)
STATIC VOID MergeMemoryMapForNotPresentEntry(IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN OUT UINTN *MemoryMapSize, IN UINTN DescriptorSize)
VOID GetGcdMemoryMap(VOID)
EFI_PHYSICAL_ADDRESS GetSmmProfileData(IN OUT UINT64 *Size)
VOID GetUefiMemoryAttributesTable(VOID)
VOID CreateNonMmramMemMap(IN UINT8 PhysicalAddressBits, OUT MM_CPU_MEMORY_REGION **MemoryRegion, OUT UINTN *MemoryRegionCount)
VOID UpdateUefiMemMapAttributes(VOID)
STATIC VOID SortMemoryMap(IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN MemoryMapSize, IN UINTN DescriptorSize)
VOID GetUefiMemoryMap(VOID)
BOOLEAN IsSmmCommBufferForbiddenAddress(IN UINT64 Address)
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define FixedPcdGet8(TokenName)
Definition: PcdLib.h:64
@ EfiGcdMemoryTypeReserved
Definition: PiDxeCis.h:32
@ EfiGcdMemoryTypeMemoryMappedIo
Definition: PiDxeCis.h:44
#define WRITE_UNPROTECT_RO_PAGES(Wp, Cet)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
@ EfiUnusableMemory
@ EfiBootServicesData
@ EfiReservedMemoryType
@ EfiBootServicesCode
@ EfiConventionalMemory
@ EfiLoaderData
@ EfiACPIReclaimMemory
@ EfiLoaderCode
@ EfiRuntimeServicesCode
@ EfiRuntimeServicesData
@ AllocateMaxAddress
Definition: UefiSpec.h:38
EFI_PHYSICAL_ADDRESS BaseAddress
Definition: PiDxeCis.h:130
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: UefiSpec.h:155
EFI_PHYSICAL_ADDRESS CpuStart
Definition: PiMultiPhase.h:127