*HobBufferSize = UsedSize;\r
}\r
\r
+/**\r
+ Collect unblock memory regions.\r
+\r
+ @param[in, out] MemoryRegion Pointer to unblock memory regions.\r
+ @param[in, out] MemoryRegionCount Count of unblock memory regions.\r
+**/\r
+VOID\r
+CollectUnblockMemoryRegions (\r
+ IN OUT MM_IPL_MEMORY_REGION *MemoryRegion,\r
+ IN OUT UINTN *MemoryRegionCount\r
+ )\r
+{\r
+ UINTN Index;\r
+ EFI_HOB_GENERIC_HEADER *GuidHob;\r
+ MM_UNBLOCK_REGION *UnblockRegion;\r
+\r
+ ASSERT (MemoryRegionCount != NULL);\r
+ ASSERT (*MemoryRegionCount == 0 || MemoryRegion != NULL);\r
+\r
+ Index = 0;\r
+ //\r
+ // Collect unblock memory ranges\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gMmUnblockRegionHobGuid);\r
+ while (GuidHob != NULL) {\r
+ if (Index < *MemoryRegionCount) {\r
+ UnblockRegion = GET_GUID_HOB_DATA (GuidHob);\r
+ MemoryRegion[Index].Base = UnblockRegion->PhysicalStart;\r
+ MemoryRegion[Index].Length = EFI_PAGES_TO_SIZE (UnblockRegion->NumberOfPages);\r
+ }\r
+\r
+ Index++;\r
+ GuidHob = GetNextGuidHob (&gMmUnblockRegionHobGuid, GET_NEXT_HOB (GuidHob));\r
+ }\r
+\r
+ *MemoryRegionCount = Index;\r
+}\r
+\r
/**\r
Create MMIO memory map according to platform HOB.\r
\r
\r
/**\r
Build resource HOB to cover [0, PhysicalAddressBits length] by excluding\r
- all Mmram ranges, MM Profile data and MMIO ranges.\r
-\r
- @param[in] HobBuffer The pointer of new HOB buffer.\r
- @param[in, out] HobBufferSize The available size of the HOB buffer when as input.\r
- The used size of when as output.\r
- @param[in] PlatformHobList Platform HOB list.\r
- @param[in] PlatformHobSize Platform HOB size.\r
- @param[in] Block Pointer of MMRAM descriptor block.\r
- @param[in] MmProfileDataHob Pointer to MM profile data HOB.\r
-\r
+ all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges.\r
+\r
+ @param[in] HobBuffer The pointer of new HOB buffer.\r
+ @param[in, out] HobBufferSize The available size of the HOB buffer when as input.\r
+ The used size of when as output.\r
+ @param[in] PlatformHobList Platform HOB list.\r
+ @param[in] PlatformHobSize Platform HOB size.\r
+ @param[in] Block Pointer of MMRAM descriptor block.\r
+ @param[in] MmProfileDataHob Pointer to MM profile data HOB.\r
**/\r
VOID\r
MmIplBuildResourceHobForAllSystemMemory (\r
UINT64 MaxAddress;\r
MM_IPL_MEMORY_REGION *MemoryRegions;\r
MM_IPL_MEMORY_REGION SortBuffer;\r
+ UINTN UnblockRegionCount;\r
\r
MaxAddress = LShiftU64 (1, MmIplCalculateMaximumSupportAddress ());\r
\r
}\r
\r
//\r
- // Allocate buffer for platform memory regions, MM Profile data, MMRam ranges, an extra terminator.\r
+ // Get the count of platform memory regions\r
+ //\r
+ UnblockRegionCount = 0;\r
+ CollectUnblockMemoryRegions (NULL, &UnblockRegionCount);\r
+\r
+ //\r
+ // Allocate buffer for platform memory regions, unblock memory regions,\r
+ // MM Profile data, MMRam ranges, an extra terminator.\r
//\r
- Count = PlatformRegionCount + Block->NumberOfMmReservedRegions + ((MmProfileDataHob != NULL) ? 1 : 0) + 1;\r
+ Count = PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions + ((MmProfileDataHob != NULL) ? 1 : 0) + 1;\r
MemoryRegions = AllocatePages (EFI_SIZE_TO_PAGES (Count * sizeof (*MemoryRegions)));\r
ASSERT (MemoryRegions != NULL);\r
if (MemoryRegions == NULL) {\r
CollectPlatformMemoryRegions (PlatformHobList, PlatformHobSize, MemoryRegions, &PlatformRegionCount);\r
}\r
\r
+ //\r
+ // Collect unblock memory regions\r
+ //\r
+ if (UnblockRegionCount != 0) {\r
+ CollectUnblockMemoryRegions (&MemoryRegions[PlatformRegionCount], &UnblockRegionCount);\r
+ }\r
+\r
//\r
// Collect SMRAM regions\r
//\r
for (Index = 0; Index < Block->NumberOfMmReservedRegions; Index++) {\r
- MemoryRegions[PlatformRegionCount + Index].Base = Block->Descriptor[Index].CpuStart;\r
- MemoryRegions[PlatformRegionCount + Index].Length = Block->Descriptor[Index].PhysicalSize;\r
+ MemoryRegions[PlatformRegionCount + UnblockRegionCount + Index].Base = Block->Descriptor[Index].CpuStart;\r
+ MemoryRegions[PlatformRegionCount + UnblockRegionCount + Index].Length = Block->Descriptor[Index].PhysicalSize;\r
}\r
\r
//\r
// Collect MM profile database region\r
//\r
if (MmProfileDataHob != NULL) {\r
- MemoryRegions[PlatformRegionCount + Block->NumberOfMmReservedRegions].Base = MmProfileDataHob->AllocDescriptor.MemoryBaseAddress;\r
- MemoryRegions[PlatformRegionCount + Block->NumberOfMmReservedRegions].Length = MmProfileDataHob->AllocDescriptor.MemoryLength;\r
+ MemoryRegions[PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions].Base = MmProfileDataHob->AllocDescriptor.MemoryBaseAddress;\r
+ MemoryRegions[PlatformRegionCount + UnblockRegionCount + Block->NumberOfMmReservedRegions].Length = MmProfileDataHob->AllocDescriptor.MemoryLength;\r
}\r
\r
//\r
- // Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database.\r
+ // Build system memory resource HOBs excluding platform memory regions, SMRAM regions, MmProfile database, Unblocked memory regions.\r
//\r
QuickSort (MemoryRegions, Count, sizeof (*MemoryRegions), MemoryRegionBaseAddressCompare, &SortBuffer);\r
UsedSize = 0;\r
UsedSize += HobLength;\r
}\r
\r
+ //\r
+ // Build resource HOB for unblocked region\r
+ //\r
HobLength = GetRemainingHobSize (*FoundationHobSize, UsedSize);\r
- if (PcdGetBool (PcdCpuSmmRestrictedMemoryAccess)) {\r
- //\r
- // Only unblocked memory regions are accessible\r
- //\r
- MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize, &HobLength);\r
- } else {\r
+ MmIplBuildResourceHobForUnblockedRegion (FoundationHobList + UsedSize, &HobLength);\r
+ UsedSize += HobLength;\r
+\r
+ if (!PcdGetBool (PcdCpuSmmRestrictedMemoryAccess)) {\r
//\r
// All system memory (DRAM) is accessible.\r
// When SMM Profile is enabled:\r
- // * Access to regions reported from MmPlatformHobProducerLib do not require logging.\r
+ // * Access to regions included all Mmram ranges, MM Profile data, Unblock memory ranges and MMIO ranges do not require logging.\r
// * Access to other system memory requires logging.\r
//\r
- MmIplBuildResourceHobForAllSystemMemory (FoundationHobList + UsedSize, &HobLength, PlatformHobList, PlatformHobSize, Block, MmProfileDataHob);\r
+ HobLength = GetRemainingHobSize (*FoundationHobSize, UsedSize);\r
+ MmIplBuildResourceHobForAllSystemMemory (\r
+ FoundationHobList + UsedSize,\r
+ &HobLength,\r
+ PlatformHobList,\r
+ PlatformHobSize,\r
+ Block,\r
+ MmProfileDataHob\r
+ );\r
+ UsedSize += HobLength;\r
}\r
\r
- UsedSize += HobLength;\r
-\r
if (*FoundationHobSize < UsedSize) {\r
Status = RETURN_BUFFER_TOO_SMALL;\r
} else {\r