mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
247 lines
5.3 KiB
C
247 lines
5.3 KiB
C
/** @file
|
|
OpenCore driver.
|
|
|
|
Copyright (c) 2019, vit9696. All rights reserved.<BR>
|
|
This program and the accompanying materials
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
**/
|
|
|
|
#include <OpenCore.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/MemoryAllocationLib.h>
|
|
#include <Library/PrintLib.h>
|
|
#include <Library/OcCpuLib.h>
|
|
#include <Library/OcMiscLib.h>
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
#include <Protocol/DevicePath.h>
|
|
#include <Protocol/GraphicsOutput.h>
|
|
|
|
STATIC EFI_EVENT mReleaseUsbOwnershipEvent;
|
|
|
|
STATIC
|
|
VOID
|
|
OcLoadDrivers (
|
|
IN OC_STORAGE_CONTEXT *Storage,
|
|
IN OC_GLOBAL_CONFIG *Config
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
VOID *Driver;
|
|
UINT32 DriverSize;
|
|
UINT32 Index;
|
|
CHAR16 DriverPath[64];
|
|
EFI_HANDLE ImageHandle;
|
|
|
|
DEBUG ((DEBUG_INFO, "OC: Got %u drivers\n", Config->Uefi.Drivers.Count));
|
|
|
|
for (Index = 0; Index < Config->Uefi.Drivers.Count; ++Index) {
|
|
DEBUG ((
|
|
DEBUG_INFO,
|
|
"OC: Driver %a at %u is being loaded...\n",
|
|
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index]),
|
|
Index
|
|
));
|
|
|
|
UnicodeSPrint (
|
|
DriverPath,
|
|
sizeof (DriverPath),
|
|
OPEN_CORE_UEFI_DRIVER_PATH "%a",
|
|
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index])
|
|
);
|
|
|
|
Driver = OcStorageReadFileUnicode (Storage, DriverPath, &DriverSize);
|
|
if (Driver == NULL) {
|
|
DEBUG ((
|
|
DEBUG_ERROR,
|
|
"OC: Driver %a at %u cannot be found!\n",
|
|
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index]),
|
|
Index
|
|
));
|
|
//
|
|
// TODO: This should cause security violation if configured!
|
|
//
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// TODO: Use AppleLoadedImage!!
|
|
//
|
|
ImageHandle = NULL;
|
|
Status = gBS->LoadImage (
|
|
FALSE,
|
|
gImageHandle,
|
|
NULL,
|
|
Driver,
|
|
DriverSize,
|
|
&ImageHandle
|
|
);
|
|
if (EFI_ERROR (Status)) {
|
|
DEBUG ((
|
|
DEBUG_ERROR,
|
|
"OC: Driver %a at %u cannot be loaded - %r!\n",
|
|
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index]),
|
|
Index,
|
|
Status
|
|
));
|
|
FreePool (Driver);
|
|
continue;
|
|
}
|
|
|
|
Status = gBS->StartImage (
|
|
ImageHandle,
|
|
NULL,
|
|
NULL
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
DEBUG ((
|
|
DEBUG_ERROR,
|
|
"OC: Driver %a at %u cannot be started - %r!\n",
|
|
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index]),
|
|
Index,
|
|
Status
|
|
));
|
|
gBS->UnloadImage (ImageHandle);
|
|
}
|
|
|
|
FreePool (Driver);
|
|
}
|
|
}
|
|
|
|
STATIC
|
|
VOID
|
|
OcConnectDrivers (
|
|
VOID
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
UINTN HandleCount;
|
|
EFI_HANDLE *HandleBuffer;
|
|
UINTN Index;
|
|
VOID *DriverBinding;
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
AllHandles,
|
|
NULL,
|
|
NULL,
|
|
&HandleCount,
|
|
&HandleBuffer
|
|
);
|
|
if (EFI_ERROR (Status)) {
|
|
return;
|
|
}
|
|
|
|
for (Index = 0; Index < HandleCount; ++Index) {
|
|
Status = gBS->HandleProtocol (
|
|
HandleBuffer[Index],
|
|
&gEfiDevicePathProtocolGuid,
|
|
&DriverBinding
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
//
|
|
// Calling ConnectController on non-driver results in freezes on APTIO IV.
|
|
//
|
|
continue;
|
|
}
|
|
|
|
gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
|
|
}
|
|
|
|
FreePool (HandleBuffer);
|
|
}
|
|
|
|
STATIC
|
|
VOID
|
|
OcProvideConsoleGop (
|
|
VOID
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
VOID *Gop;
|
|
|
|
Gop = NULL;
|
|
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, &Gop);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
DEBUG ((DEBUG_WARN, "Missing GOP on ConsoleOutHandle - %r\n", Status));
|
|
Status = gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NULL, &Gop);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
&gST->ConsoleOutHandle,
|
|
&gEfiGraphicsOutputProtocolGuid,
|
|
Gop,
|
|
NULL
|
|
);
|
|
if (EFI_ERROR (Status)) {
|
|
DEBUG ((DEBUG_WARN, "Failed to install GOP on ConsoleOutHandle - %r\n", Status));
|
|
}
|
|
} else {
|
|
DEBUG ((DEBUG_WARN, "Missing GOP entirely - %r\n", Status));
|
|
}
|
|
}
|
|
}
|
|
|
|
STATIC
|
|
VOID
|
|
EFIAPI
|
|
OcReleaseUsbOwnership (
|
|
IN EFI_EVENT Event,
|
|
IN VOID *Context
|
|
)
|
|
{
|
|
EFI_STATUS Status;
|
|
|
|
Status = ReleaseUsbOwnership ();
|
|
|
|
DEBUG ((DEBUG_INFO, "ReleaseUsbOwnership status - %r\n", Status));
|
|
}
|
|
|
|
VOID
|
|
OcLoadUefiSupport (
|
|
IN OC_STORAGE_CONTEXT *Storage,
|
|
IN OC_GLOBAL_CONFIG *Config,
|
|
IN OC_CPU_INFO *CpuInfo
|
|
)
|
|
{
|
|
if (Config->Uefi.Quirks.DisableWatchDog) {
|
|
//
|
|
// boot.efi kills watchdog only in FV2 UI.
|
|
//
|
|
gBS->SetWatchdogTimer (0, 0, 0, NULL);
|
|
}
|
|
|
|
if (Config->Uefi.Quirks.IgnoreInvalidFlexRatio) {
|
|
OcCpuCorrectFlexRatio (CpuInfo);
|
|
}
|
|
|
|
if (Config->Uefi.Quirks.ProvideConsoleGop) {
|
|
OcProvideConsoleGop ();
|
|
}
|
|
|
|
if (Config->Uefi.Quirks.ReleaseUsbOwnership) {
|
|
gBS->CreateEvent (
|
|
EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
|
TPL_NOTIFY,
|
|
OcReleaseUsbOwnership,
|
|
NULL,
|
|
&mReleaseUsbOwnershipEvent
|
|
);
|
|
}
|
|
|
|
OcLoadDrivers (Storage, Config);
|
|
|
|
if (Config->Uefi.ConnectDrivers) {
|
|
OcConnectDrivers ();
|
|
}
|
|
}
|