+ // For RuntimeSevicesData and RuntimeServicesCode, they are BFV or DxeCore.\r
+ // The memory type is assigned in EfiLdr\r
+ //\r
+ Status = gDS->GetMemorySpaceDescriptor (MemoryDescHob.MemDesc[Index].PhysicalStart, &Descriptor);\r
+ if (EFI_ERROR (Status)) {\r
+ continue;\r
+ }\r
+ if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeReserved) {\r
+ //\r
+ // BFV or tested DXE core\r
+ //\r
+ continue;\r
+ }\r
+ //\r
+ // Untested DXE Core region, free and remove\r
+ //\r
+ Status = gDS->FreeMemorySpace (\r
+ MemoryDescHob.MemDesc[Index].PhysicalStart,\r
+ LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "FreeMemorySpace fail - %r!\n", Status));\r
+ continue;\r
+ }\r
+ Status = gDS->RemoveMemorySpace (\r
+ MemoryDescHob.MemDesc[Index].PhysicalStart,\r
+ LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "RemoveMemorySpace fail - %r!\n", Status));\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Convert Runtime type to BootTime type\r
+ //\r
+ if (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) {\r
+ MemoryDescHob.MemDesc[Index].Type = EfiBootServicesData;\r
+ } else {\r
+ MemoryDescHob.MemDesc[Index].Type = EfiBootServicesCode;\r
+ }\r
+\r
+ //\r
+ // PassThrough, let below code add and alloate.\r