diff --git a/Include/Library/OcConfigurationLib.h b/Include/Library/OcConfigurationLib.h index b5c5e6d5..bfb1a7eb 100644 --- a/Include/Library/OcConfigurationLib.h +++ b/Include/Library/OcConfigurationLib.h @@ -120,7 +120,6 @@ _(BOOLEAN , EnableSafeModeSlide , , FALSE , ()) \ _(BOOLEAN , EnableWriteUnprotector , , FALSE , ()) \ _(BOOLEAN , ForceExitBootServices , , FALSE , ()) \ - _(OC_BOOTER_WL_ARRAY , MmioWhitelist , , OC_CONSTR3 (OC_BOOTER_WL_ARRAY, _, __) , OC_DESTR (OC_BOOTER_WL_ARRAY)) \ _(BOOLEAN , ProtectCsmRegion , , FALSE , ()) \ _(BOOLEAN , ProvideCustomSlide , , FALSE , ()) \ _(BOOLEAN , SetupVirtualMap , , FALSE , ()) \ @@ -131,6 +130,7 @@ /// Apple bootloader section. /// #define OC_BOOTER_CONFIG_FIELDS(_, __) \ + _(OC_BOOTER_WL_ARRAY , MmioWhitelist , , OC_CONSTR2 (OC_BOOTER_WL_ARRAY, _, __) , OC_DESTR (OC_BOOTER_WL_ARRAY)) \ _(OC_BOOTER_QUIRKS , Quirks , , OC_CONSTR2 (OC_BOOTER_QUIRKS, _, __) , OC_DESTR (OC_BOOTER_QUIRKS)) OC_DECLARE (OC_BOOTER_CONFIG) diff --git a/Library/OcAppleBootCompatLib/BootCompatInternal.h b/Library/OcAppleBootCompatLib/BootCompatInternal.h index 626a9fc7..13556923 100644 --- a/Library/OcAppleBootCompatLib/BootCompatInternal.h +++ b/Library/OcAppleBootCompatLib/BootCompatInternal.h @@ -204,6 +204,10 @@ typedef struct SERVICES_OVERRIDE_STATE_ { /// TRUE if we are using custom KASLR slide (via boot arg). /// BOOLEAN AppleCustomSlide; + /// + /// TRUE if we are done reporting MMIO cleanup. + /// + BOOLEAN ReportedMmio; } SERVICES_OVERRIDE_STATE; /** diff --git a/Library/OcAppleBootCompatLib/ServiceOverrides.c b/Library/OcAppleBootCompatLib/ServiceOverrides.c index a5b2daa1..3f03cea4 100644 --- a/Library/OcAppleBootCompatLib/ServiceOverrides.c +++ b/Library/OcAppleBootCompatLib/ServiceOverrides.c @@ -169,7 +169,7 @@ ProtectCsmRegion ( Mark MMIO virtual memory regions as non-runtime to reduce the amount of virtual memory required by boot.efi. - @param[in] Context Settings context. + @param[in] Context Boot compatibility context. @param[in,out] MemoryMapSize Memory map size in bytes, updated on devirtualisation. @param[in,out] MemoryMap Memory map to devirtualise. @param[in] DescriptorSize Memory map descriptor size in bytes. @@ -190,9 +190,10 @@ DevirtualiseMmio ( CONST EFI_PHYSICAL_ADDRESS *Whitelist; UINTN WhitelistSize; BOOLEAN Skipped; + UINT64 PagesSaved; - Whitelist = ((OC_ABC_SETTINGS *) Context)->MmioWhitelist; - WhitelistSize = ((OC_ABC_SETTINGS *) Context)->MmioWhitelistSize; + Whitelist = ((BOOT_COMPAT_CONTEXT *) Context)->Settings.MmioWhitelist; + WhitelistSize = ((BOOT_COMPAT_CONTEXT *) Context)->Settings.MmioWhitelistSize; // // Some firmwares (normally Haswell and earlier) need certain MMIO areas to have @@ -205,8 +206,11 @@ DevirtualiseMmio ( Desc = MemoryMap; NumEntries = MemoryMapSize / DescriptorSize; + PagesSaved = 0; - DEBUG ((DEBUG_INFO, "OCABC: MMIO devirt start\n")); + if (!((BOOT_COMPAT_CONTEXT *) Context)->ServiceState.ReportedMmio) { + DEBUG ((DEBUG_INFO, "OCABC: MMIO devirt start\n")); + } for (Index = 0; Index < NumEntries; ++Index) { if (Desc->NumberOfPages > 0 @@ -222,24 +226,34 @@ DevirtualiseMmio ( } } - DEBUG (( - DEBUG_INFO, - "OCABC: MMIO devirt 0x%Lx (0x%Lx pages, 0x%Lx) skip %d\n", - (UINT64) Desc->PhysicalStart, - (UINT64) Desc->NumberOfPages, - (UINT64) Desc->Attribute, - Skipped - )); + if (!((BOOT_COMPAT_CONTEXT *) Context)->ServiceState.ReportedMmio) { + DEBUG (( + DEBUG_INFO, + "OCABC: MMIO devirt 0x%Lx (0x%Lx pages, 0x%Lx) skip %d\n", + (UINT64) Desc->PhysicalStart, + (UINT64) Desc->NumberOfPages, + (UINT64) Desc->Attribute, + Skipped + )); + } if (!Skipped) { Desc->Attribute &= ~EFI_MEMORY_RUNTIME; + PagesSaved += Desc->NumberOfPages; } } Desc = NEXT_MEMORY_DESCRIPTOR (Desc, DescriptorSize); } - DEBUG ((DEBUG_INFO, "OCABC: MMIO devirt end\n")); + if (!((BOOT_COMPAT_CONTEXT *) Context)->ServiceState.ReportedMmio) { + DEBUG (( + DEBUG_INFO, + "OCABC: MMIO devirt end, saved %Lu bytes\n", + EFI_PAGES_TO_SIZE (PagesSaved) + )); + ((BOOT_COMPAT_CONTEXT *) Context)->ServiceState.ReportedMmio = TRUE; + } } /** @@ -445,7 +459,7 @@ OcGetMemoryMap ( if (BootCompat->Settings.DevirtualiseMmio) { DevirtualiseMmio ( - &BootCompat->Settings, + BootCompat, *MemoryMapSize, MemoryMap, *DescriptorSize @@ -610,7 +624,7 @@ OcGetVariable ( BootCompat->ServicePtrs.GetVariable, BootCompat->ServicePtrs.GetMemoryMap, BootCompat->Settings.DevirtualiseMmio ? DevirtualiseMmio : NULL, - &BootCompat->Settings, + BootCompat, VariableName, VendorGuid, Attributes, diff --git a/Library/OcConfigurationLib/OcConfigurationLib.c b/Library/OcConfigurationLib/OcConfigurationLib.c index 91db3742..79f0443f 100644 --- a/Library/OcConfigurationLib/OcConfigurationLib.c +++ b/Library/OcConfigurationLib/OcConfigurationLib.c @@ -170,7 +170,6 @@ mBooterQuirksSchema[] = { OC_SCHEMA_BOOLEAN_IN ("EnableSafeModeSlide", OC_GLOBAL_CONFIG, Booter.Quirks.EnableSafeModeSlide), OC_SCHEMA_BOOLEAN_IN ("EnableWriteUnprotector", OC_GLOBAL_CONFIG, Booter.Quirks.EnableWriteUnprotector), OC_SCHEMA_BOOLEAN_IN ("ForceExitBootServices", OC_GLOBAL_CONFIG, Booter.Quirks.ForceExitBootServices), - OC_SCHEMA_ARRAY_IN ("MmioWhitelist", OC_GLOBAL_CONFIG, Booter.Quirks.MmioWhitelist, &mBooterWhitelistSchema), OC_SCHEMA_BOOLEAN_IN ("ProtectCsmRegion", OC_GLOBAL_CONFIG, Booter.Quirks.ProtectCsmRegion), OC_SCHEMA_BOOLEAN_IN ("ProvideCustomSlide", OC_GLOBAL_CONFIG, Booter.Quirks.ProvideCustomSlide), OC_SCHEMA_BOOLEAN_IN ("SetupVirtualMap", OC_GLOBAL_CONFIG, Booter.Quirks.SetupVirtualMap), @@ -180,7 +179,8 @@ mBooterQuirksSchema[] = { STATIC OC_SCHEMA mBooterConfigurationSchema[] = { - OC_SCHEMA_DICT ("Quirks", mBooterQuirksSchema), + OC_SCHEMA_ARRAY_IN ("MmioWhitelist", OC_GLOBAL_CONFIG, Booter.MmioWhitelist, &mBooterWhitelistSchema), + OC_SCHEMA_DICT ("Quirks", mBooterQuirksSchema), };