Skip to content

Commit

Permalink
Rebase onto edk2-stable202105: restore AppleSupportLib
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
  • Loading branch information
shchuko committed Jun 30, 2021
1 parent 122db48 commit f14ef70
Show file tree
Hide file tree
Showing 23 changed files with 1,130 additions and 0 deletions.
5 changes: 5 additions & 0 deletions DarwinComponents.dsc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ OvmfDarwinPkg/OpenHfsPlus/OpenHfsPlus.inf
# APFS Support
#
OvmfDarwinPkg/ApfsDriverLoader/ApfsDriverLoader.inf

#
# AppleSupportLib requirement
#
IntelFrameworkModulePkg/Universal/DataHubDxe/DataHubDxe.inf
5 changes: 5 additions & 0 deletions DarwinComponents.fdf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ INF OvmfDarwinPkg/OpenHfsPlus/OpenHfsPlus.inf
# APFS Support
#
INF OvmfDarwinPkg/ApfsDriverLoader/ApfsDriverLoader.inf

#
# AppleSupportLib requirement
#
INF IntelFrameworkModulePkg/Universal/DataHubDxe/DataHubDxe.inf
8 changes: 8 additions & 0 deletions DarwinLibs.dsc.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2021, Vladislav Yaroshchuk <yaroshchuk2000@gmail.com
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#

[LibraryClasses.common]
AppleSupportLib|OvmfDarwinPkg/Library/AppleSupportLib/AppleSupportLib.inf
28 changes: 28 additions & 0 deletions Include/Guid/Darwin/AppleDataHub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _APPLE_DATA_HUB_GUID_H_
#define _APPLE_DATA_HUB_GUID_H_

// APPLE_SYSTEM_INFO_PRODUCER_NAME_GUID
#define APPLE_SYSTEM_INFO_PRODUCER_NAME_GUID \
{ 0x64517CC8, 0x6561, 0x4051, \
{ 0xB0, 0x3C, 0x59, 0x64, 0xB6, 0x0F, 0x4C, 0x7A } }

// APPLE_FSB_FREQUENCY_PROPERTY_GUID
#define APPLE_FSB_FREQUENCY_PROPERTY_GUID \
{ 0xD1A04D55, 0x75B9, 0x41A3, \
{ 0x90, 0x36, 0x8F, 0x4A, 0x26, 0x1C, 0xBB, 0xA2 } }

// APPLE_DEVICE_PATHS_SUPPORTED_GUID
#define APPLE_DEVICE_PATHS_SUPPORTED_GUID \
{ 0x5BB91CF7, 0xD816, 0x404B, \
{ 0x86, 0x72, 0x68, 0xF2, 0x7F, 0x78, 0x31, 0xDC } };

// gAppleSystemInfoProducerNameGuid
extern EFI_GUID gAppleSystemInfoProducerNameGuid;

// gAppleFsbFrequencyPropertyGuid
extern EFI_GUID gAppleFsbFrequencyPropertyGuid;

// gAppleDevicePathsSupportedGuid
extern EFI_GUID gAppleDevicePathsSupportedGuid;

#endif //_APPLE_DATA_HUB_GUID_H_
21 changes: 21 additions & 0 deletions Include/Guid/Darwin/AppleVariable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @file
Copyright (c) 2020, Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef _APPLE_VARIABLE_GUID_H_
#define _APPLE_VARIABLE_GUID_H_

#define APPLE_NVRAM_VARIABLE_GUID \
{0x7C436110, 0xAB2A, 0x4BBB, {0xA8, 0x80, 0xFE, 0x41, 0x99, 0x5C, 0x9F, 0x82}}

extern EFI_GUID gAppleNVRAMVariableGuid;

#define APPLE_FIRMWARE_VARIABLE_GUID \
{0x4D1EDE05, 0x38C7, 0x4A6A, {0x9C, 0xC6, 0x4B, 0xCC, 0xA8, 0xB3, 0x8C, 0x14}}

extern EFI_GUID gAppleFirmwareVariableGuid;


#endif //_APPLE_VARIABLE_GUID_H_
29 changes: 29 additions & 0 deletions Include/Library/Darwin/AppleSupportLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** @file
*
* Copyright (c) 2020, Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
* 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 IMPLIED.
*
**/

#ifndef _APPLESUPPORT_LIB_INCLUDED_
#define _APPLESUPPORT_LIB_INCLUDED_


#include <Guid/Darwin/AppleVariable.h>

EFI_STATUS
EFIAPI
InitializeAppleSupport (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

#endif
49 changes: 49 additions & 0 deletions Include/Protocol/Darwin/AppleBootPath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @file
*
* Copyright (c) 2021 Vladislav Yaroshchuk. 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.
*
* Module Name:
*
* AppleBootPath.h
*
* Abstract:
*
* Abstraction of Apple's boot.efi bootloader path retrieval
**/

#ifndef _APPLE_BOOT_PATH_PROTOCOL_H_
#define _APPLE_BOOT_PATH_PROTOCOL_H_

#define EFI_APPLE_BOOT_PATH_PROTOCOL_GUID \
{0x85e1deb6, 0xd97a, 0x4bea, {0xa0, 0xa0, 0xe6, 0xa9, 0x43, 0x32, 0x85, 0x09}}


typedef struct _EFI_APPLE_BOOT_PATH_PROTOCOL EFI_APPLE_BOOT_PATH_PROTOCOL;

/**
* Attempts to find Apple's boot.efi bootloader expanding media device path.
* Returns expanded device path if bootloader found, otherwise NULL
*/
typedef
EFI_DEVICE_PATH_PROTOCOL *
(EFIAPI *EFI_APPLE_BOOT_PATH_GET_BOOT_LOADER_PATH) (
IN EFI_APPLE_BOOT_PATH_PROTOCOL *This,
IN EFI_HANDLE Device
);


struct _EFI_APPLE_BOOT_PATH_PROTOCOL {
EFI_APPLE_BOOT_PATH_GET_BOOT_LOADER_PATH GetBootLoaderPath;
};

extern EFI_GUID gEfiAppleBootPathProtocolGuid;

#endif //_APPLE_BOOT_PATH_PROTOCOL_H_
122 changes: 122 additions & 0 deletions Include/Protocol/Darwin/ConsoleControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*++
Copyright (c) 2004 - 2010, Intel Corporation. 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.
Module Name:
ConsoleControl.h
Abstract:
Abstraction of a Text mode or GOP/UGA screen
--*/

#ifndef __CONSOLE_CONTROL_H__
#define __CONSOLE_CONTROL_H__

#define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \
{ 0xf42f7782, 0x12e, 0x4c12, {0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21} }

typedef struct _EFI_CONSOLE_CONTROL_PROTOCOL EFI_CONSOLE_CONTROL_PROTOCOL;


typedef enum {
EfiConsoleControlScreenText,
EfiConsoleControlScreenGraphics,
EfiConsoleControlScreenMaxValue
} EFI_CONSOLE_CONTROL_SCREEN_MODE;


typedef
EFI_STATUS
(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE) (
IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
OUT EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode,
OUT BOOLEAN *GopUgaExists, OPTIONAL
OUT BOOLEAN *StdInLocked OPTIONAL
)
/*++
Routine Description:
Return the current video mode information. Also returns info about existence
of Graphics Output devices or UGA Draw devices in system, and if the Std In
device is locked. All the arguments are optional and only returned if a non
NULL pointer is passed in.
Arguments:
This - Protocol instance pointer.
Mode - Are we in text of grahics mode.
GopUgaExists - TRUE if Console Spliter has found a GOP or UGA device
StdInLocked - TRUE if StdIn device is keyboard locked
Returns:
EFI_SUCCESS - Mode information returned.
--*/
;


typedef
EFI_STATUS
(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE) (
IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode
)
/*++
Routine Description:
Set the current mode to either text or graphics. Graphics is
for Quiet Boot.
Arguments:
This - Protocol instance pointer.
Mode - Mode to set the
Returns:
EFI_SUCCESS - Mode information returned.
--*/
;


typedef
EFI_STATUS
(EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN) (
IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
IN CHAR16 *Password
)
/*++
Routine Description:
Lock Std In devices until Password is typed.
Arguments:
This - Protocol instance pointer.
Password - Password needed to unlock screen. NULL means unlock keyboard
Returns:
EFI_SUCCESS - Mode information returned.
EFI_DEVICE_ERROR - Std In not locked
--*/
;



struct _EFI_CONSOLE_CONTROL_PROTOCOL {
EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE GetMode;
EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE SetMode;
EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN LockStdIn;
};

extern EFI_GUID gEfiConsoleControlProtocolGuid;

#endif
115 changes: 115 additions & 0 deletions Library/AppleSupportLib/AppleSupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/** @file
*
* Copyright (c) 2020, Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
* 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 IMPLIED.
*
**/

#include "Console.h"
#include "Datahub.h"
#include "Boot.h"
#include "SmBios.h"

/**
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 deleted.
@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 = 0x00000000;
UINT32 FwFeatures = 0x80000015;
UINT32 FwFeaturesMask = 0x800003ff;
CHAR8 BootArgs[] = "-v debug=0x14e keepsyms=1";

Status = gRT->SetVariable(L"BackgroundClear",
&gAppleFirmwareVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(BackgroundClear), &BackgroundClear);
ASSERT_EFI_ERROR (Status);

Status = gRT->SetVariable(L"FirmwareFeatures",
&gAppleFirmwareVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(FwFeatures), &FwFeatures);
ASSERT_EFI_ERROR (Status);

Status = gRT->SetVariable(L"FirmwareFeaturesMask",
&gAppleFirmwareVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(FwFeaturesMask), &FwFeaturesMask);
ASSERT_EFI_ERROR (Status);

DEBUG_CODE_BEGIN ();
Status = gRT->SetVariable(L"boot-args",
&gAppleNVRAMVariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(BootArgs), &BootArgs);
ASSERT_EFI_ERROR (Status);
DEBUG_CODE_END ();

return EFI_SUCCESS;
}

/**
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 = InitializeConsoleControl(ImageHandle);
ASSERT_EFI_ERROR (Status);

Status = InitializeDatahub(ImageHandle);
ASSERT_EFI_ERROR(Status);

Status = InitializeFirmware();
ASSERT_EFI_ERROR(Status);

Status = InitializeAppleBoot(ImageHandle);
ASSERT_EFI_ERROR(Status);

Status = InitializeSmBios ();
ASSERT_EFI_ERROR (Status);

return Status;
}
Loading

0 comments on commit f14ef70

Please sign in to comment.