From nobody Sat Nov 2 14:31:54 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1488856484602712.937066536162; Mon, 6 Mar 2017 19:14:44 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 43EF580356; Mon, 6 Mar 2017 19:14:39 -0800 (PST) Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7FC458034B for ; Mon, 6 Mar 2017 19:14:37 -0800 (PST) Received: by mail-qk0-x243.google.com with SMTP id j127so31381423qke.0 for ; Mon, 06 Mar 2017 19:14:37 -0800 (PST) Received: from foober.ini.cmu.edu (pool-108-39-248-175.pitbpa.fios.verizon.net. [108.39.248.175]) by smtp.gmail.com with ESMTPSA id v26sm2901013qtc.13.2017.03.06.19.14.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 19:14:35 -0800 (PST) X-Original-To: edk2-devel@ml01.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n5LFwM9HgxoBAMJcO5XE9ZGs7dIOF8m7Ez9x1PyrHz4=; b=YzaEYclI+wLdIFbVCAzylsvw7JXTEr3qdgEqDAwin6ba6ygv4Y8sfYLJEXqeVPD1cr U243vuQxmKs9Sn6wbOLTeutUTh11e368z4RbifdkdpcJproALXTbqXnbSe3PYM9PzTXu sQxDUA4pkWa+oCIw9Li/5t/s843ygg3RwLup3BdSw5Fucxr9KSadlewZtjVgYOgLr39f z34BahCyZLXCpaEoywSK4Ulbg77Yx82w+bRjCqj8qhQmLS289Cr/jCjm8lF/8p5sM8rs pvlATd93SaMK/9OO6puyp0HpGypzCzfGamcDSgnEAg2Qug1B5yTo1CSqxuWGV/p8OVEX 2DnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n5LFwM9HgxoBAMJcO5XE9ZGs7dIOF8m7Ez9x1PyrHz4=; b=mieALnYzqfOmxHfHyvPIlX1ZV7sNLM3TAduPQedHF2ZUwgg1lD3U5IB8zBk/FVWFcX NoxYl7Lo3bqqAs2XWG4x5OaEv88bInYiMORC/QQFHK96KK55Do/cn5U3pIdEqUe/3dto QuRlaJNm2GRQ5OdlppOoOFczMAngcY80LrdFxrMv4g0OUS+wCz2FkVH+tbvgtYXJLLGw 9ax31OGu38MUWoZzs0Ri7rcBSC6lawIDxoV4UgY4Wee5Fq3ris1VPq1gBiMHdfcHC3R1 kFxAO+Vl7DVu8Xgp/1t2qMNhVuYnFtEbhB21Q7WKSTgePvv5h8LVeVW8EnbmKrjdWFla 5njQ== X-Gm-Message-State: AMke39leNVdwok00Tgvq1Z4EFm9+Rzglyna5Ki3ouloP/9QD26pjQZRyK6IfIahJACSPsg== X-Received: by 10.55.169.135 with SMTP id s129mr13188532qke.91.1488856476325; Mon, 06 Mar 2017 19:14:36 -0800 (PST) From: "Gabriel L. Somlo" To: edk2-devel@ml01.01.org Date: Mon, 6 Mar 2017 22:14:24 -0500 Message-Id: <1488856465-8965-6-git-send-email-gsomlo@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488856465-8965-1-git-send-email-gsomlo@gmail.com> References: <1488856465-8965-1-git-send-email-gsomlo@gmail.com> Subject: [edk2] [RFC PATCH 5/6] OvmfPkg: add Apple boot support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jordan.l.justen@intel.com, lersek@redhat.com, agraf@suse.de MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Apple's boot.efi checks if the ConsoleControl protocol returns EFI_SUCCESS in both GetMode and SetMode. Apple uses a kernel extension to make parts of the DataHub protocol available to the xnu kernel. The xnu kernel then checks for FSB frequency and if it's not found fails with: "tsc_init: EFI not supported!" https://github.com/opensource-apple/xnu/blob/10.9/osfmk/i386/tsc.c Also, some firmware settings are added to AppleSupport and written to nvram. Lastly, use (already present) HFS+ filesystem driver to locate, load, and launch the Apple-provided OS X bootloader. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Reza Jelveh Signed-off-by: Gabriel Somlo --- OvmfPkg/Include/Library/AppleSupportLib.h | 28 ++++ OvmfPkg/Library/AppleSupportLib/AppleSupport.c | 107 +++++++++++++++ .../Library/AppleSupportLib/AppleSupportLib.inf | 50 +++++++ OvmfPkg/Library/AppleSupportLib/Bds.c | 151 +++++++++++++++++= ++++ OvmfPkg/Library/AppleSupportLib/Bds.h | 21 +++ OvmfPkg/Library/AppleSupportLib/Common.h | 24 ++++ OvmfPkg/Library/AppleSupportLib/Console.c | 86 ++++++++++++ OvmfPkg/Library/AppleSupportLib/Console.h | 28 ++++ OvmfPkg/Library/AppleSupportLib/Datahub.c | 104 ++++++++++++++ OvmfPkg/Library/AppleSupportLib/Datahub.h | 32 +++++ 10 files changed, 631 insertions(+) create mode 100644 OvmfPkg/Include/Library/AppleSupportLib.h create mode 100644 OvmfPkg/Library/AppleSupportLib/AppleSupport.c create mode 100644 OvmfPkg/Library/AppleSupportLib/AppleSupportLib.inf create mode 100644 OvmfPkg/Library/AppleSupportLib/Bds.c create mode 100644 OvmfPkg/Library/AppleSupportLib/Bds.h create mode 100644 OvmfPkg/Library/AppleSupportLib/Common.h create mode 100644 OvmfPkg/Library/AppleSupportLib/Console.c create mode 100644 OvmfPkg/Library/AppleSupportLib/Console.h create mode 100644 OvmfPkg/Library/AppleSupportLib/Datahub.c create mode 100644 OvmfPkg/Library/AppleSupportLib/Datahub.h diff --git a/OvmfPkg/Include/Library/AppleSupportLib.h b/OvmfPkg/Include/Li= brary/AppleSupportLib.h new file mode 100644 index 0000000..583d06b --- /dev/null +++ b/OvmfPkg/Include/Library/AppleSupportLib.h @@ -0,0 +1,28 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#ifndef _APPLESUPPORT_LIB_INCLUDED_ +#define _APPLESUPPORT_LIB_INCLUDED_ + +EFI_STATUS +EFIAPI +InitializeAppleSupport ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +EFI_STATUS +BdsBootApple (); + +#endif diff --git a/OvmfPkg/Library/AppleSupportLib/AppleSupport.c b/OvmfPkg/Libra= ry/AppleSupportLib/AppleSupport.c new file mode 100644 index 0000000..92f7d79 --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/AppleSupport.c @@ -0,0 +1,107 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#include "Console.h" +#include "Datahub.h" + +#include +#include +#include +#include +#include +#include +#include + + +EFI_GUID gAppleFirmwareVariableGuid =3D { + 0x4D1EDE05, 0x38C7, 0x4A6A, {0x9C, 0xC6, 0x4B, 0xCC, 0xA8, 0xB3, 0x8C,= 0x14 } +}; + +/** + Register Handler for the specified interrupt source. + + @param This Instance pointer for this protocol + @param Source Hardware source of the interrupt + @param Handler Callback for interrupt. NULL to unregister + + @retval EFI_SUCCESS The firmware has successfully stored the= variable and its data as + defined by the Attributes. + @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits= was supplied, or the + DataSize exceeds the maximum allowed. + @retval EFI_INVALID_PARAMETER VariableName is an empty Unicode string. + @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold = the variable and its data. + @retval EFI_DEVICE_ERROR The variable could not be saved due to a= hardware failure. + @retval EFI_WRITE_PROTECTED The variable in question is read-only. + @retval EFI_WRITE_PROTECTED The variable in question cannot be delet= ed. + @retval EFI_SECURITY_VIOLATION The variable could not be written due to= EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS + set but the AuthInfo does NOT pass the validation check carried + out by the firmware. + +**/ +EFI_STATUS +InitializeFirmware () +{ + EFI_STATUS Status; + + UINT32 BackgroundClear =3D 0x00000000; + UINT32 FwFeatures =3D 0x80000015; + UINT32 FwFeaturesMask =3D 0x800003ff; + + Status =3D gRT->SetVariable(L"BackgroundClear", + &gAppleFirmwareVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTS= ERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(BackgroundClear), &BackgroundClear); + + Status =3D gRT->SetVariable(L"FirmwareFeatures", + &gAppleFirmwareVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTS= ERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(FwFeatures), &FwFeatures); + + Status =3D gRT->SetVariable(L"FirmwareFeaturesMask", + &gAppleFirmwareVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTS= ERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(FwFeaturesMask), &FwFeaturesMask); + + return Status; +} + +/** + Register driver. + + @param ImageHandle of the loaded driver + @param SystemTable Pointer to the System Table + + @retval EFI_SUCCESS Driver registered + +**/ +EFI_STATUS +EFIAPI +InitializeAppleSupport ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D InitializeConsoleControl(ImageHandle); + ASSERT_EFI_ERROR (Status); + + Status =3D InitializeDatahub(ImageHandle); + ASSERT_EFI_ERROR(Status); + + Status =3D InitializeFirmware(); + ASSERT_EFI_ERROR(Status); + + return Status; +} diff --git a/OvmfPkg/Library/AppleSupportLib/AppleSupportLib.inf b/OvmfPkg/= Library/AppleSupportLib/AppleSupportLib.inf new file mode 100644 index 0000000..6caf29d --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/AppleSupportLib.inf @@ -0,0 +1,50 @@ +#/* @file +# Copyright (c) 2014, Reza Jelveh. All rights reserved. +# +# 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 IM= PLIED. +# +#*/ + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D AppleSupportLib + FILE_GUID =3D CEC880AF-68DF-4CDF-BBA5-FF9B202382AB + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D AppleSupportLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + AppleSupport.c + Console.c + Datahub.c + Bds.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + IntelFrameworkPkg/IntelFrameworkPkg.dec + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec + EdkCompatibilityPkg/EdkCompatibilityPkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + BaseLib + DebugLib + MemoryAllocationLib + BaseMemoryLib + +[Protocols] + gEfiConsoleControlProtocolGuid + gEfiDataHubProtocolGuid diff --git a/OvmfPkg/Library/AppleSupportLib/Bds.c b/OvmfPkg/Library/AppleS= upportLib/Bds.c new file mode 100644 index 0000000..88f7437 --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Bds.c @@ -0,0 +1,151 @@ +#include "Common.h" +#include "Bds.h" + +#include + +#include +#include +#include +#include + +#include + +EFI_STATUS +BdsFileSystemLoadImage ( + IN EFI_HANDLE Handle, + IN EFI_ALLOCATE_TYPE Type, + IN OUT EFI_PHYSICAL_ADDRESS* Image, + OUT UINTN *ImageSize + ) +{ + EFI_STATUS Status; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol; + EFI_FILE_PROTOCOL *Fs; + EFI_FILE_INFO *FileInfo; + EFI_FILE_PROTOCOL *File; + UINTN Size; + + /* FilePathDevicePath =3D (FILEPATH_DEVICE_PATH*)RemainingDevicePath; */ + + Status =3D gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGui= d, (VOID **)&FsProtocol); + if (EFI_ERROR (Status)) { + return Status; + } + + // Try to Open the volume and get root directory + Status =3D FsProtocol->OpenVolume (FsProtocol, &Fs); + if (EFI_ERROR (Status)) { + return Status; + } + + File =3D NULL; + Status =3D Fs->Open (Fs, &File, EFI_CORESERVICES, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR (Status)) { + return Status; + } + + Size =3D 0; + File->GetInfo (File, &gEfiFileInfoGuid, &Size, NULL); + FileInfo =3D AllocatePool (Size); + Status =3D File->GetInfo (File, &gEfiFileInfoGuid, &Size, FileInfo); + if (EFI_ERROR (Status)) { + return Status; + } + + // Get the file size + Size =3D FileInfo->FileSize; + if (ImageSize) { + *ImageSize =3D Size; + } + FreePool (FileInfo); + + Status =3D gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PA= GES(Size), Image); + // Try to allocate in any pages if failed to allocate memory at the defi= ned location + if ((Status =3D=3D EFI_OUT_OF_RESOURCES) && (Type !=3D AllocateAnyPages)= ) { + Status =3D gBS->AllocatePages (AllocateAnyPages, EfiBootServicesCode, = EFI_SIZE_TO_PAGES(Size), Image); + } + if (!EFI_ERROR (Status)) { + Status =3D File->Read (File, &Size, (VOID*)(UINTN)(*Image)); + } + + return Status; +} + + +/** + Start an EFI Application from a Device Path + + @param ParentImageHandle Handle of the calling image + @param DevicePath Location of the EFI Application + + @retval EFI_SUCCESS All drivers have been connected + @retval EFI_NOT_FOUND The Linux kernel Device Path has not been = found + @retval EFI_OUT_OF_RESOURCES There is not enough resource memory to sto= re the matching results. + +**/ +EFI_STATUS +BdsStartEfiApplication ( + IN EFI_HANDLE Handle, + IN EFI_HANDLE ParentImageHandle, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE ImageHandle; + EFI_PHYSICAL_ADDRESS BinaryBuffer; + UINTN BinarySize; + + // Find the nearest supported file loader + Status =3D BdsFileSystemLoadImage (Handle, AllocateAnyPages, &BinaryBuff= er, &BinarySize); + if (EFI_ERROR (Status)) { + DEBUG((EFI_D_INFO, "=3D=3D Bds could not load System image =3D=3D")); + return Status; + } + + // Load the image from the Buffer with Boot Services function + Status =3D gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, (VOID*)(= UINTN)BinaryBuffer, BinarySize, &ImageHandle); + if (EFI_ERROR (Status)) { + return Status; + } + + // Before calling the image, enable the Watchdog Timer for the 5 Minute= period + gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL); + // Start the image + Status =3D gBS->StartImage (ImageHandle, NULL, NULL); + // Clear the Watchdog Timer after the image returns + gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); + + return Status; +} + + +EFI_STATUS +BdsBootApple () +{ + UINTN Index; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_HANDLE *SimpleFileSystemHandles; + UINTN NumberSimpleFileSystemHandles; + + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleFileSystemProtocolGuid, + NULL, + &NumberSimpleFileSystemHandles, + &SimpleFileSystemHandles + ); + DEBUG((EFI_D_INFO, "Number Device File System: %d\n", NumberSimpleFileSy= stemHandles)); + for (Index =3D 0; Index < NumberSimpleFileSystemHandles; Index++) { + // + // Get the device path size of SimpleFileSystem handle + // + TempDevicePath =3D DevicePathFromHandle (SimpleFileSystemHandles[Index= ]); + BdsStartEfiApplication ( + SimpleFileSystemHandles[Index], + gImageHandle, + TempDevicePath + ); + + } + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Library/AppleSupportLib/Bds.h b/OvmfPkg/Library/AppleS= upportLib/Bds.h new file mode 100644 index 0000000..725d03b --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Bds.h @@ -0,0 +1,21 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + + +#ifndef _APPLESUPPORT_BDS_H_INCLUDED_ +#define _APPLESUPPORT_BDS_H_INCLUDED_ + +#define EFI_CORESERVICES L"System\\Library\\CoreServices\\boot.efi" + +#endif diff --git a/OvmfPkg/Library/AppleSupportLib/Common.h b/OvmfPkg/Library/App= leSupportLib/Common.h new file mode 100644 index 0000000..725f2af --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Common.h @@ -0,0 +1,24 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + + +#ifndef _APPLESUPPORT_COMMON_H_INCLUDED_ +#define _APPLESUPPORT_COMMON_H_INCLUDED_ + +#include +#include +#include +#include + +#endif diff --git a/OvmfPkg/Library/AppleSupportLib/Console.c b/OvmfPkg/Library/Ap= pleSupportLib/Console.c new file mode 100644 index 0000000..5f23300 --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Console.c @@ -0,0 +1,86 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#include "Console.h" + +EFI_STATUS EFIAPI +GetModeImpl( + IN EFI_CONSOLE_CONTROL_PROTOCOL *This, + OUT EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode, + OUT BOOLEAN *GopUgaExists, OPTIONAL + OUT BOOLEAN *StdInLocked OPTIONAL + ) +{ + *Mode =3D EfiConsoleControlScreenGraphics; + + if (GopUgaExists) + *GopUgaExists =3D TRUE; + if (StdInLocked) + *StdInLocked =3D FALSE; + return EFI_SUCCESS; +} + +EFI_STATUS EFIAPI +SetModeImpl( + IN EFI_CONSOLE_CONTROL_PROTOCOL *This, + IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS EFIAPI +LockStdInImpl( + IN EFI_CONSOLE_CONTROL_PROTOCOL *This, + IN CHAR16 *Password + ) +{ + return EFI_SUCCESS; +} + + + +EFI_CONSOLE_CONTROL_PROTOCOL gConsoleController =3D +{ + GetModeImpl, + SetModeImpl, +}; + +/** + Install ConsoleControl protocol, which is needed for Apple's + boot.efi + + @param ImageHandle of the loaded driver + + @retval EFI_SUCCESS Successfully installed protocol handler + @retval EFI_DEVICE_ERROR ConsoleProtocol could not be installed + +**/ +EFI_STATUS +EFIAPI +InitializeConsoleControl ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiConsoleControlProtocolGuid, + &gConsoleController, + NULL + ); + + return Status; +} diff --git a/OvmfPkg/Library/AppleSupportLib/Console.h b/OvmfPkg/Library/Ap= pleSupportLib/Console.h new file mode 100644 index 0000000..dabf902 --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Console.h @@ -0,0 +1,28 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#ifndef _APPLESUPPORT_CONSOLE_H_INCLUDED_ +#define _APPLESUPPORT_CONSOLE_H_INCLUDED_ + +#include "Common.h" + +#include + +EFI_STATUS +EFIAPI +InitializeConsoleControl ( + IN EFI_HANDLE ImageHandle + ); + +#endif diff --git a/OvmfPkg/Library/AppleSupportLib/Datahub.c b/OvmfPkg/Library/Ap= pleSupportLib/Datahub.c new file mode 100644 index 0000000..3f1ec56 --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Datahub.c @@ -0,0 +1,104 @@ +/** @file +* +* Copyright (c) 2011, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#include "Datahub.h" + +EFI_GUID gAppleSystemInfoProducerNameGuid =3D {0x64517CC8, 0x6561, 0x4051,= {0xB0, 0x3C, 0x59, 0x64, 0xB6, 0x0F, 0x4C, 0x7A}}; +EFI_GUID gAppleFsbFrequencyPropertyGuid =3D {0xD1A04D55, 0x75B9, 0x41A3, {= 0x90, 0x36, 0x8F, 0x4A, 0x26, 0x1C, 0xBB, 0xA2}}; +EFI_GUID gAppleDevicePathsSupportedGuid =3D {0x5BB91CF7, 0xD816, 0x404B, {= 0x86, 0x72, 0x68, 0xF2, 0x7F, 0x78, 0x31, 0xDC}}; + +typedef struct { + UINT32 DataNameSize; + UINT32 DataSize; +} EFI_PROPERTY_SUBCLASS_RECORD; + +typedef struct { + EFI_SUBCLASS_TYPE1_HEADER Header; + EFI_PROPERTY_SUBCLASS_RECORD Record; +} EFI_PROPERTY_SUBCLASS_DATA; + + +EFI_STATUS +SetEfiPlatformProperty ( + IN EFI_DATA_HUB_PROTOCOL *DataHub, + IN CONST EFI_STRING Name, + EFI_GUID EfiPropertyGuid, + VOID *Data, + UINT32 DataSize + ) +{ + EFI_STATUS Status; + UINT32 DataNameSize; + EFI_PROPERTY_SUBCLASS_DATA *DataRecord; + + DataNameSize =3D (UINT32)StrSize(Name); + + DataRecord =3D AllocateZeroPool (sizeof (EFI_PROPERTY_SUBCLASS_DATA) + D= ataNameSize + DataSize); + ASSERT (DataRecord !=3D NULL); + + DataRecord->Header.Version =3D EFI_DATA_RECORD_HEADER_VERSION; + DataRecord->Header.HeaderSize =3D sizeof(EFI_SUBCLASS_TYPE1_HEADER); + DataRecord->Header.Instance =3D 0xFFFF; + DataRecord->Header.SubInstance =3D 0xFFFF; + DataRecord->Header.RecordType =3D 0xFFFFFFFF; + DataRecord->Record.DataNameSize =3D DataNameSize; + DataRecord->Record.DataSize =3D DataSize; + + + CopyMem((UINT8 *)DataRecord + sizeof(EFI_PROPERTY_SUBCLASS_DATA), Name, = DataNameSize); + CopyMem((UINT8 *)DataRecord + sizeof(EFI_PROPERTY_SUBCLASS_DATA) + DataN= ameSize, Data, DataSize); + + Status =3D DataHub->LogData(DataHub, &EfiPropertyGuid, &gAppleSystemInfo= ProducerNameGuid, + EFI_DATA_RECORD_CLASS_DATA, + DataRecord, + sizeof(EFI_PROPERTY_SUBCLASS_DATA) + DataName= Size + DataSize); + + if (DataRecord) { + gBS->FreePool(DataRecord); + } + + return Status; +} + +/** + Initialize the DataHub protocols data for the xnu kernel to + detect an EFI boot. + + @param ImageHandle of the loaded driver + + @retval EFI_SUCCESS Source was updated to support Handler. + @retval EFI_DEVICE_ERROR Hardware could not be programmed. + +**/ +EFI_STATUS +EFIAPI +InitializeDatahub ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_DATA_HUB_PROTOCOL *DataHub; + + Status =3D gBS->LocateProtocol(&gEfiDataHubProtocolGuid, NULL, (VOID **)= &DataHub); + ASSERT_EFI_ERROR(Status); + + UINT64 FsbFrequency =3D 667000000; + UINT32 DevicePathsSupported =3D 1; + + SetEfiPlatformProperty(DataHub, L"FSBFrequency", gAppleFsbFrequencyPrope= rtyGuid, &FsbFrequency, sizeof(UINT64)); + SetEfiPlatformProperty(DataHub, L"DevicePathsSupported", gAppleDevicePat= hsSupportedGuid, &DevicePathsSupported, sizeof(UINT32)); + ASSERT_EFI_ERROR(Status); + + return Status; +} diff --git a/OvmfPkg/Library/AppleSupportLib/Datahub.h b/OvmfPkg/Library/Ap= pleSupportLib/Datahub.h new file mode 100644 index 0000000..d7f8806 --- /dev/null +++ b/OvmfPkg/Library/AppleSupportLib/Datahub.h @@ -0,0 +1,32 @@ +/** @file +* +* Copyright (c) 2014, Reza Jelveh. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#ifndef _APPLESUPPORT_DATAHUB_H_INCLUDED_ +#define _APPLESUPPORT_DATAHUB_H_INCLUDED_ + +#include "Common.h" + +#include +#include +#include +#include +#include + +EFI_STATUS +EFIAPI +InitializeDatahub ( + IN EFI_HANDLE ImageHandle + ); + +#endif --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel