From 73c5de043a6083cfc9fa2f70b407c353bc188e6e Mon Sep 17 00:00:00 2001 From: vit9696 Date: Thu, 23 Jan 2020 22:42:18 +0300 Subject: [PATCH] OpenCoreUefi: Improved driver connection performance on APTIO IV closes acidanthera/bugtracker#669 --- Changelog.md | 2 + OpenCorePkg.dsc | 1 + Platform/OpenCore/OpenCore.inf | 1 + Platform/OpenCore/OpenCoreUefi.c | 96 +++++++++++++++++++++----------- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/Changelog.md b/Changelog.md index 765c020d..286df3a8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,8 @@ OpenCore Changelog - Improved OpenCore rerun detection for new versions - Fixed loading picker on boot failure when it is hidden - Added PMC ACPI sample for 300-series chipsets +- Improved driver connection performance on APTIO IV +- Fixed boot option saving in LogoutHook.command #### v0.5.4 - Added Enter key handling in boot menu for quick proceed diff --git a/OpenCorePkg.dsc b/OpenCorePkg.dsc index 593ef116..8caa0c9d 100755 --- a/OpenCorePkg.dsc +++ b/OpenCorePkg.dsc @@ -63,6 +63,7 @@ OcDevicePathLib|OcSupportPkg/Library/OcDevicePathLib/OcDevicePathLib.inf OcDevicePropertyLib|OcSupportPkg/Library/OcDevicePropertyLib/OcDevicePropertyLib.inf OcDeviceTreeLib|OcSupportPkg/Library/OcDeviceTreeLib/OcDeviceTreeLib.inf + OcDriverConnectionLib|OcSupportPkg/Library/OcDriverConnectionLib/OcDriverConnectionLib.inf OcFileLib|OcSupportPkg/Library/OcFileLib/OcFileLib.inf OcFirmwarePasswordLib|OcSupportPkg/Library/OcFirmwarePasswordLib/OcFirmwarePasswordLib.inf OcFirmwareVolumeLib|OcSupportPkg/Library/OcFirmwareVolumeLib/OcFirmwareVolumeLib.inf diff --git a/Platform/OpenCore/OpenCore.inf b/Platform/OpenCore/OpenCore.inf index 9537e8df..11ddc6f9 100644 --- a/Platform/OpenCore/OpenCore.inf +++ b/Platform/OpenCore/OpenCore.inf @@ -83,6 +83,7 @@ OcDataHubLib OcDevicePathLib OcDevicePropertyLib + OcDriverConnectionLib OcFirmwareVolumeLib OcGuardLib OcHashServicesLib diff --git a/Platform/OpenCore/OpenCoreUefi.c b/Platform/OpenCore/OpenCoreUefi.c index 9e55f257..f071a180 100644 --- a/Platform/OpenCore/OpenCoreUefi.c +++ b/Platform/OpenCore/OpenCoreUefi.c @@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include @@ -50,8 +51,9 @@ STATIC EFI_EVENT mOcExitBootServicesEvent; STATIC VOID OcLoadDrivers ( - IN OC_STORAGE_CONTEXT *Storage, - IN OC_GLOBAL_CONFIG *Config + IN OC_STORAGE_CONTEXT *Storage, + IN OC_GLOBAL_CONFIG *Config, + OUT EFI_HANDLE **DriversToConnect OPTIONAL ) { EFI_STATUS Status; @@ -60,6 +62,13 @@ OcLoadDrivers ( UINT32 Index; CHAR16 DriverPath[64]; EFI_HANDLE ImageHandle; + EFI_HANDLE *DriversToConnectIterator; + VOID *DriverBinding; + + DriversToConnectIterator = NULL; + if (DriversToConnect != NULL) { + *DriversToConnect = NULL; + } DEBUG ((DEBUG_INFO, "OC: Got %u drivers\n", Config->Uefi.Drivers.Count)); @@ -140,39 +149,54 @@ OcLoadDrivers ( OC_BLOB_GET (Config->Uefi.Drivers.Values[Index]), Index )); - } - FreePool (Driver); - } -} + if (DriversToConnect != NULL) { + Status = gBS->HandleProtocol ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, + (VOID **) &DriverBinding + ); -STATIC -VOID -OcConnectDrivers ( - VOID - ) -{ - EFI_STATUS Status; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; + if (!EFI_ERROR (Status)) { + if (*DriversToConnect == NULL) { + // + // Allocate enough entries for the drivers to connect. + // + *DriversToConnect = AllocatePool ( + (Config->Uefi.Drivers.Count + 1 - Index) * sizeof (**DriversToConnect) + ); - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiDevicePathProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return; - } + if (*DriversToConnect != NULL) { + DriversToConnectIterator = *DriversToConnect; + } else { + DEBUG ((DEBUG_ERROR, "OC: Failed to allocate memory for drivers to connect\n")); + FreePool (Driver); + return; + } + } + + *DriversToConnectIterator = ImageHandle; + ++DriversToConnectIterator; + + DEBUG (( + DEBUG_INFO, + "OC: Driver %a at %u needs connection.\n", + OC_BLOB_GET (Config->Uefi.Drivers.Values[Index]), + Index + )); + } + } + } - for (Index = 0; Index < HandleCount; ++Index) { - gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); + FreePool (Driver); } - FreePool (HandleBuffer); + // + // Driver connection list should be null-terminated. + // + if (*DriversToConnectIterator != NULL) { + *DriversToConnectIterator = NULL; + } } STATIC @@ -482,6 +506,7 @@ OcLoadUefiSupport ( ) { EFI_STATUS Status; + EFI_HANDLE *DriversToConnect; UINTN Index; UINTN Index2; UINT16 *BootOrder; @@ -595,11 +620,16 @@ OcLoadUefiSupport ( OcMiscUefiQuirksLoaded (Config); - OcLoadDrivers (Storage, Config); - - DEBUG ((DEBUG_INFO, "OC: Connecting drivers...\n")); - if (Config->Uefi.ConnectDrivers) { + OcLoadDrivers (Storage, Config, &DriversToConnect); + DEBUG ((DEBUG_INFO, "OC: Connecting drivers...\n")); + OcRegisterDriversToHighestPriority (DriversToConnect); + // + // DriversToConnect is not freed as it is owned by OcRegisterDriversToHighestPriority. + // OcConnectDrivers (); + DEBUG ((DEBUG_INFO, "OC: Connecting drivers done...\n")); + } else { + OcLoadDrivers (Storage, Config, NULL); } } -- GitLab