提交 892f9fd1 编写于 作者: V vit9696

OpenCoreUefi: Added `AppleRtcRam` protocol implementation

closes acidanthera/bugtracker#765
上级 b508b429
......@@ -14,6 +14,7 @@ OpenCore Changelog
- Added memory region reservation support
- Added RtcRw tool to manipulate RTC memory
- Added `PatchAppleRtcChecksum` kernel quirk
- Added `AppleRtcRam` protocol implementation
#### v0.5.7
- Added TimeMachine detection to picker
......
......@@ -1987,8 +1987,8 @@ blocking.
kernel extension if this is desired.
\emph{Note 2}: This option will not protect areas from being overwritten
at firmware stage (e.g. macOS bootloader), see \texttt{RTC} (FIXME) section
if this is desired.
at firmware stage (e.g. macOS bootloader), see \texttt{AppleRtc} protocol
description if this is desired.
\item
\texttt{DummyPowerManagement}\\
......@@ -4826,6 +4826,18 @@ functioning. Feature highlights:
\textbf{Description}: Reinstalls Apple Key Map protocols with builtin
versions.
\item
\texttt{AppleRtc}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Description}: Reinstalls Apple RTC RAM protocol with builtin
version.
\emph{Note}: Builtin version of Apple RTC RAM protocol may filter out
I/O attempts to select RTC memory addresses. The list of addresses
can be specified in \texttt{4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:rtc-blacklist}
variable as a data array.
\item
\texttt{AppleSmcIo}\\
\textbf{Type}: \texttt{plist\ boolean}\\
......
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Tue Apr 7 19:32:13 2020
%DIF ADD ../Configuration.tex Sat Apr 18 15:39:07 2020
%DIF ADD ../Configuration.tex Sat Apr 18 22:12:54 2020
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
......@@ -2050,8 +2050,8 @@ blocking.
}
\emph{\DIFadd{Note 2}}\DIFadd{: This option will not protect areas from being overwritten
at firmware stage (e.g. macOS bootloader), see }\texttt{\DIFadd{RTC}} \DIFadd{(FIXME) section
if this is desired.
at firmware stage (e.g. macOS bootloader), see }\texttt{\DIFadd{AppleRtc}} \DIFadd{protocol
description if this is desired.
}
\item
......@@ -4911,7 +4911,21 @@ functioning. Feature highlights:
versions.
\item
\texttt{AppleSmcIo}\\
\DIFaddbegin \texttt{\DIFadd{AppleRtc}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{false}}\\
\textbf{\DIFadd{Description}}\DIFadd{: Reinstalls Apple RTC RAM protocol with builtin
version.
}
\emph{\DIFadd{Note}}\DIFadd{: Builtin version of Apple RTC RAM protocol may filter out
I/O attempts to select RTC memory addresses. The list of addresses
can be specified in }\texttt{\DIFadd{4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:rtc-blacklist}}
\DIFadd{variable as a data array.
}
\item
\DIFaddend \texttt{AppleSmcIo}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Description}: Reinstalls Apple SMC I/O protocol with a builtin
......
......@@ -683,6 +683,11 @@
<key>prev-lang:kbd</key>
<data>cnUtUlU6MjUy</data>
</dict>
<key>4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102</key>
<dict>
<key>rtc-blacklist</key>
<data></data>
</dict>
</dict>
<key>Block</key>
<dict>
......@@ -695,6 +700,10 @@
<array>
<string>boot-args</string>
</array>
<key>4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102</key>
<array>
<string>rtc-blacklist</string>
</array>
</dict>
<key>LegacyEnable</key>
<false/>
......@@ -864,6 +873,8 @@
<false/>
<key>AppleKeyMap</key>
<false/>
<key>AppleRtcRam</key>
<false/>
<key>AppleSmcIo</key>
<false/>
<key>AppleUserInterfaceTheme</key>
......
......@@ -683,6 +683,11 @@
<key>prev-lang:kbd</key>
<data>cnUtUlU6MjUy</data>
</dict>
<key>4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102</key>
<dict>
<key>rtc-blacklist</key>
<data></data>
</dict>
</dict>
<key>Block</key>
<dict>
......@@ -695,6 +700,10 @@
<array>
<string>boot-args</string>
</array>
<key>4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102</key>
<array>
<string>rtc-blacklist</string>
</array>
</dict>
<key>LegacyEnable</key>
<false/>
......@@ -967,6 +976,8 @@
<false/>
<key>AppleKeyMap</key>
<false/>
<key>AppleRtcRam</key>
<false/>
<key>AppleSmcIo</key>
<false/>
<key>AppleUserInterfaceTheme</key>
......
......@@ -77,6 +77,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
#define OC_ACPI_CPU_FREQUENCY_VARIABLE_NAME L"acpi-cpu-frequency"
//
// Variable used to mark blacklisted RTC values.
//
#define OC_RTC_BLACKLIST_VARIABLE_NAME L"rtc-blacklist"
//
// 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102
// This GUID is specifically used for normal variable access by Lilu kernel extension and its plugins.
......
......@@ -535,6 +535,7 @@ typedef enum {
_(BOOLEAN , AppleEvent , , FALSE , ()) \
_(BOOLEAN , AppleImageConversion , , FALSE , ()) \
_(BOOLEAN , AppleKeyMap , , FALSE , ()) \
_(BOOLEAN , AppleRtcRam , , FALSE , ()) \
_(BOOLEAN , AppleSmcIo , , FALSE , ()) \
_(BOOLEAN , AppleUserInterfaceTheme , , FALSE , ()) \
_(BOOLEAN , DataHub , , FALSE , ()) \
......
......@@ -547,6 +547,7 @@ mUefiProtocolsSchema[] = {
OC_SCHEMA_BOOLEAN_IN ("AppleEvent", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleEvent),
OC_SCHEMA_BOOLEAN_IN ("AppleImageConversion", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleImageConversion),
OC_SCHEMA_BOOLEAN_IN ("AppleKeyMap", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleKeyMap),
OC_SCHEMA_BOOLEAN_IN ("AppleRtcRam", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleRtcRam),
OC_SCHEMA_BOOLEAN_IN ("AppleSmcIo", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleSmcIo),
OC_SCHEMA_BOOLEAN_IN ("AppleUserInterfaceTheme", OC_GLOBAL_CONFIG, Uefi.Protocols.AppleUserInterfaceTheme),
OC_SCHEMA_BOOLEAN_IN ("DataHub", OC_GLOBAL_CONFIG, Uefi.Protocols.DataHub),
......
......@@ -16,9 +16,11 @@
**/
#include <Guid/OcVariables.h>
#include <Protocol/AppleRtcRam.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcRtcLib.h>
#include <Library/UefiBootServicesTableLib.h>
......@@ -26,6 +28,9 @@
#include "OcRtcLibInternal.h"
STATIC EFI_LOCK mAppleRtcRamLock;
STATIC UINT8 mEmulatedRtcArea[APPLE_RTC_TOTAL_SIZE];
STATIC BOOLEAN mEmulatedRtcStatus[APPLE_RTC_TOTAL_SIZE];
STATIC
EFI_STATUS
......@@ -36,6 +41,10 @@ SyncRtcRead (
{
EFI_STATUS Status;
if (mEmulatedRtcStatus[Address]) {
return mEmulatedRtcArea[Address];
}
Status = EfiAcquireLockOrFail (&mAppleRtcRamLock);
if (EFI_ERROR (Status)) {
return Status;
......@@ -55,6 +64,11 @@ SyncRtcWrite (
{
EFI_STATUS Status;
if (mEmulatedRtcStatus[Address]) {
mEmulatedRtcArea[Address] = Value;
return EFI_SUCCESS;
}
Status = EfiAcquireLockOrFail (&mAppleRtcRamLock);
if (EFI_ERROR (Status)) {
return Status;
......@@ -150,7 +164,7 @@ AppleRtcRamReadData (
return Status;
}
if (((UINT32) Temp ^ (UINT32) *Buffer) != 0xFF) {
if ((Temp ^ *Buffer) != 0xFF) {
*Buffer = 0;
}
}
......@@ -275,8 +289,11 @@ OcAppleRtcRamInstallProtocol (
IN BOOLEAN Reinstall
)
{
EFI_STATUS Status;
APPLE_RTC_RAM_PROTOCOL *Protocol;
EFI_STATUS Status;
APPLE_RTC_RAM_PROTOCOL *Protocol;
UINT8 *RtcBlacklist;
UINTN Index;
UINTN RtcBlacklistSize;
DEBUG ((DEBUG_VERBOSE, "OcAppleRtcRamInstallProtocol\n"));
......@@ -298,6 +315,31 @@ OcAppleRtcRamInstallProtocol (
}
}
DEBUG ((
DEBUG_INFO,
"OCRTC: Wake log is 0x%02X 0x%02X % 3d 0x%02X\n",
OcRtcRead (APPLE_RTC_TRACE_DATA_ADDR),
OcRtcRead (APPLE_RTC_WL_MASK_ADDR),
OcRtcRead (APPLE_RTC_WL_EVENT_ADDR),
OcRtcRead (APPLE_RTC_WL_EVENT_EXTRA_ADDR)
));
Status = GetVariable2 (
OC_RTC_BLACKLIST_VARIABLE_NAME,
&gOcVendorVariableGuid,
(VOID **) &RtcBlacklist,
&RtcBlacklistSize
);
if (!EFI_ERROR (Status)) {
for (Index = 0; Index < APPLE_RTC_TOTAL_SIZE; ++Index) {
mEmulatedRtcStatus[RtcBlacklist[Index]] = TRUE;
DEBUG ((DEBUG_INFO, "OCRTC: Blacklisted %02x address\n", RtcBlacklist[Index]));
}
FreePool (RtcBlacklist);
}
//
// Note, for debugging on QEMU this will need to changed to TPL_CALLBACK.
// By default we follow AppleRtcRam implementation.
......
......@@ -38,6 +38,9 @@
MdePkg/MdePkg.dec
OpenCorePkg/OpenCorePkg.dec
[Guids]
gOcVendorVariableGuid
[Protocols]
gAppleRtcRamProtocolGuid
......@@ -45,6 +48,7 @@
BaseMemoryLib
DebugLib
IoLib
MemoryAllocationLib
OcMiscLib
UefiLib
UefiBootServicesTableLib
......@@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/OcFirmwareVolumeLib.h>
#include <Library/OcHashServicesLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcRtcLib.h>
#include <Library/OcSmcLib.h>
#include <Library/OcOSInfoLib.h>
#include <Library/OcUnicodeCollationEngGenericLib.h>
......@@ -339,6 +340,10 @@ OcReinstallProtocols (
if (OcOSInfoInstallProtocol (Config->Uefi.Protocols.OSInfo) == NULL) {
DEBUG ((DEBUG_ERROR, "OC: Failed to install os info protocol\n"));
}
if (OcAppleRtcRamInstallProtocol (Config->Uefi.Protocols.AppleRtcRam) == NULL) {
DEBUG ((DEBUG_ERROR, "OC: Failed to install rtc ram protocol\n"));
}
}
VOID
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册