@@ -450,6 +450,44 @@ MmIplBuildResourceHobForUnblockedRegion (
450
450
* HobBufferSize = UsedSize ;
451
451
}
452
452
453
+ /**
454
+ Collect unblock memory regions.
455
+
456
+ @param[in, out] MemoryRegion Pointer to unblock memory regions.
457
+ @param[in, out] MemoryRegionCount Count of unblock memory regions.
458
+ **/
459
+ VOID
460
+ CollectUnblockMemoryRegions (
461
+ IN OUT MM_IPL_MEMORY_REGION * MemoryRegion ,
462
+ IN OUT UINTN * MemoryRegionCount
463
+ )
464
+ {
465
+ UINTN Index ;
466
+ EFI_HOB_GENERIC_HEADER * GuidHob ;
467
+ MM_UNBLOCK_REGION * UnblockRegion ;
468
+
469
+ ASSERT (MemoryRegionCount != NULL );
470
+ ASSERT (* MemoryRegionCount == 0 || MemoryRegion != NULL );
471
+
472
+ Index = 0 ;
473
+ //
474
+ // Collect unblock memory ranges
475
+ //
476
+ GuidHob = GetFirstGuidHob (& gMmUnblockRegionHobGuid );
477
+ while (GuidHob != NULL ) {
478
+ if (Index < * MemoryRegionCount ) {
479
+ UnblockRegion = GET_GUID_HOB_DATA (GuidHob );
480
+ MemoryRegion [Index ].Base = UnblockRegion -> PhysicalStart ;
481
+ MemoryRegion [Index ].Length = EFI_PAGES_TO_SIZE (UnblockRegion -> NumberOfPages );
482
+ }
483
+
484
+ Index ++ ;
485
+ GuidHob = GetNextGuidHob (& gMmUnblockRegionHobGuid , GET_NEXT_HOB (GuidHob ));
486
+ }
487
+
488
+ * MemoryRegionCount = Index ;
489
+ }
490
+
453
491
/**
454
492
Create MMIO memory map according to platform HOB.
455
493
@@ -564,16 +602,15 @@ MmIplCalculateMaximumSupportAddress (
564
602
565
603
/**
566
604
Build resource HOB to cover [0, PhysicalAddressBits length] by excluding
567
- all Mmram ranges, MM Profile data and MMIO ranges.
568
-
569
- @param[in] HobBuffer The pointer of new HOB buffer.
570
- @param[in, out] HobBufferSize The available size of the HOB buffer when as input.
571
- The used size of when as output.
572
- @param[in] PlatformHobList Platform HOB list.
573
- @param[in] PlatformHobSize Platform HOB size.
574
- @param[in] Block Pointer of MMRAM descriptor block.
575
- @param[in] MmProfileDataHob Pointer to MM profile data HOB.
576
-
605
+ all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges.
606
+
607
+ @param[in] HobBuffer The pointer of new HOB buffer.
608
+ @param[in, out] HobBufferSize The available size of the HOB buffer when as input.
609
+ The used size of when as output.
610
+ @param[in] PlatformHobList Platform HOB list.
611
+ @param[in] PlatformHobSize Platform HOB size.
612
+ @param[in] Block Pointer of MMRAM descriptor block.
613
+ @param[in] MmProfileDataHob Pointer to MM profile data HOB.
577
614
**/
578
615
VOID
579
616
MmIplBuildResourceHobForAllSystemMemory (
@@ -593,6 +630,7 @@ MmIplBuildResourceHobForAllSystemMemory (
593
630
UINT64 MaxAddress ;
594
631
MM_IPL_MEMORY_REGION * MemoryRegions ;
595
632
MM_IPL_MEMORY_REGION SortBuffer ;
633
+ UINTN UnblockRegionCount ;
596
634
597
635
MaxAddress = LShiftU64 (1 , MmIplCalculateMaximumSupportAddress ());
598
636
@@ -605,9 +643,16 @@ MmIplBuildResourceHobForAllSystemMemory (
605
643
}
606
644
607
645
//
608
- // Allocate buffer for platform memory regions, MM Profile data, MMRam ranges, an extra terminator.
646
+ // Get the count of platform memory regions
647
+ //
648
+ UnblockRegionCount = 0 ;
649
+ CollectUnblockMemoryRegions (NULL , & UnblockRegionCount );
650
+
651
+ //
652
+ // Allocate buffer for platform memory regions, unblock memory regions,
653
+ // MM Profile data, MMRam ranges, an extra terminator.
609
654
//
610
- Count = PlatformRegionCount + Block -> NumberOfMmReservedRegions + ((MmProfileDataHob != NULL ) ? 1 : 0 ) + 1 ;
655
+ Count = PlatformRegionCount + UnblockRegionCount + Block -> NumberOfMmReservedRegions + ((MmProfileDataHob != NULL ) ? 1 : 0 ) + 1 ;
611
656
MemoryRegions = AllocatePages (EFI_SIZE_TO_PAGES (Count * sizeof (* MemoryRegions )));
612
657
ASSERT (MemoryRegions != NULL );
613
658
if (MemoryRegions == NULL ) {
@@ -629,24 +674,31 @@ MmIplBuildResourceHobForAllSystemMemory (
629
674
CollectPlatformMemoryRegions (PlatformHobList , PlatformHobSize , MemoryRegions , & PlatformRegionCount );
630
675
}
631
676
677
+ //
678
+ // Collect unblock memory regions
679
+ //
680
+ if (UnblockRegionCount != 0 ) {
681
+ CollectUnblockMemoryRegions (& MemoryRegions [PlatformRegionCount ], & UnblockRegionCount );
682
+ }
683
+
632
684
//
633
685
// Collect SMRAM regions
634
686
//
635
687
for (Index = 0 ; Index < Block -> NumberOfMmReservedRegions ; Index ++ ) {
636
- MemoryRegions [PlatformRegionCount + Index ].Base = Block -> Descriptor [Index ].CpuStart ;
637
- MemoryRegions [PlatformRegionCount + Index ].Length = Block -> Descriptor [Index ].PhysicalSize ;
688
+ MemoryRegions [PlatformRegionCount + UnblockRegionCount + Index ].Base = Block -> Descriptor [Index ].CpuStart ;
689
+ MemoryRegions [PlatformRegionCount + UnblockRegionCount + Index ].Length = Block -> Descriptor [Index ].PhysicalSize ;
638
690
}
639
691
640
692
//
641
693
// Collect MM profile database region
642
694
//
643
695
if (MmProfileDataHob != NULL ) {
644
- MemoryRegions [PlatformRegionCount + Block -> NumberOfMmReservedRegions ].Base = MmProfileDataHob -> AllocDescriptor .MemoryBaseAddress ;
645
- MemoryRegions [PlatformRegionCount + Block -> NumberOfMmReservedRegions ].Length = MmProfileDataHob -> AllocDescriptor .MemoryLength ;
696
+ MemoryRegions [PlatformRegionCount + UnblockRegionCount + Block -> NumberOfMmReservedRegions ].Base = MmProfileDataHob -> AllocDescriptor .MemoryBaseAddress ;
697
+ MemoryRegions [PlatformRegionCount + UnblockRegionCount + Block -> NumberOfMmReservedRegions ].Length = MmProfileDataHob -> AllocDescriptor .MemoryLength ;
646
698
}
647
699
648
700
//
649
- // Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database.
701
+ // Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database, Unblocked memory regions .
650
702
//
651
703
QuickSort (MemoryRegions , Count , sizeof (* MemoryRegions ), MemoryRegionBaseAddressCompare , & SortBuffer );
652
704
UsedSize = 0 ;
@@ -843,24 +895,32 @@ CreateMmFoundationHobList (
843
895
UsedSize += HobLength ;
844
896
}
845
897
898
+ //
899
+ // Build resource HOB for unblocked region
900
+ //
846
901
HobLength = GetRemainingHobSize (* FoundationHobSize , UsedSize );
847
- if (PcdGetBool (PcdCpuSmmRestrictedMemoryAccess )) {
848
- //
849
- // Only unblocked memory regions are accessible
850
- //
851
- MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize , & HobLength );
852
- } else {
902
+ MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize , & HobLength );
903
+ UsedSize += HobLength ;
904
+
905
+ if (!PcdGetBool (PcdCpuSmmRestrictedMemoryAccess )) {
853
906
//
854
907
// All system memory (DRAM) is accessible.
855
908
// When SMM Profile is enabled:
856
- // * Access to regions reported from MmPlatformHobProducerLib do not require logging.
909
+ // * Access to regions included all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges do not require logging.
857
910
// * Access to other system memory requires logging.
858
911
//
859
- MmIplBuildResourceHobForAllSystemMemory (FoundationHobList + UsedSize , & HobLength , PlatformHobList , PlatformHobSize , Block , MmProfileDataHob );
912
+ HobLength = GetRemainingHobSize (* FoundationHobSize , UsedSize );
913
+ MmIplBuildResourceHobForAllSystemMemory (
914
+ FoundationHobList + UsedSize ,
915
+ & HobLength ,
916
+ PlatformHobList ,
917
+ PlatformHobSize ,
918
+ Block ,
919
+ MmProfileDataHob
920
+ );
921
+ UsedSize += HobLength ;
860
922
}
861
923
862
- UsedSize += HobLength ;
863
-
864
924
if (* FoundationHobSize < UsedSize ) {
865
925
Status = RETURN_BUFFER_TOO_SMALL ;
866
926
} else {
0 commit comments