diff --git a/Application/ResetSystem/ResetSystem.c b/Application/ResetSystem/ResetSystem.c index 7fd9e5aa..ef5eccf8 100644 --- a/Application/ResetSystem/ResetSystem.c +++ b/Application/ResetSystem/ResetSystem.c @@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include diff --git a/Application/ResetSystem/ResetSystem.inf b/Application/ResetSystem/ResetSystem.inf index e8619661..267a86bf 100644 --- a/Application/ResetSystem/ResetSystem.inf +++ b/Application/ResetSystem/ResetSystem.inf @@ -41,6 +41,7 @@ [LibraryClasses] BaseLib DebugLib + OcDeviceMiscLib OcMiscLib UefiApplicationEntryPoint UefiBootServicesTableLib diff --git a/Docs/Configuration.pdf b/Docs/Configuration.pdf index 19315493..fa056c0c 100644 Binary files a/Docs/Configuration.pdf and b/Docs/Configuration.pdf differ diff --git a/Docs/Configuration.tex b/Docs/Configuration.tex index 19f6ced8..ea2f8a2f 100755 --- a/Docs/Configuration.tex +++ b/Docs/Configuration.tex @@ -3516,6 +3516,7 @@ nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-log | \item \texttt{OCDC} --- OcDriverConnectionLib \item \texttt{OCDH} --- OcDataHubLib \item \texttt{OCDI} --- OcAppleDiskImageLib + \item \texttt{OCDM} --- OcDeviceMiscLib \item \texttt{OCFS} --- OcFileLib \item \texttt{OCFV} --- OcFirmwareVolumeLib \item \texttt{OCHS} --- OcHashServicesLib @@ -3525,6 +3526,7 @@ nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-log | \item \texttt{OCJS} --- OcApfsLib \item \texttt{OCKM} --- OcAppleKeyMapLib \item \texttt{OCL} --- OcDebugLogLib + \item \texttt{OCM} --- OcMiscLib \item \texttt{OCMCO} --- OcMachoLib \item \texttt{OCME} --- OcHeciLib \item \texttt{OCMM} --- OcMemoryLib diff --git a/Docs/Differences/Differences.pdf b/Docs/Differences/Differences.pdf index a4d5fabc..c106cbb1 100644 Binary files a/Docs/Differences/Differences.pdf and b/Docs/Differences/Differences.pdf differ diff --git a/Docs/Differences/Differences.tex b/Docs/Differences/Differences.tex index 4f6d8b29..346fff4b 100644 --- a/Docs/Differences/Differences.tex +++ b/Docs/Differences/Differences.tex @@ -1,7 +1,7 @@ \documentclass[]{article} %DIF LATEXDIFF DIFFERENCE FILE %DIF DEL PreviousConfiguration.tex Sat Feb 6 18:51:55 2021 -%DIF ADD ../Configuration.tex Sat Feb 27 20:05:47 2021 +%DIF ADD ../Configuration.tex Sun Feb 28 12:38:24 2021 \usepackage{lmodern} \usepackage{amssymb,amsmath} @@ -3809,7 +3809,8 @@ nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-log | \item \texttt{OCDC} --- OcDriverConnectionLib \item \texttt{OCDH} --- OcDataHubLib \item \texttt{OCDI} --- OcAppleDiskImageLib - \item \texttt{OCFS} --- OcFileLib + \item \DIFaddbegin \texttt{\DIFadd{OCDM}} \DIFadd{--- OcDeviceMiscLib + }\item \DIFaddend \texttt{OCFS} --- OcFileLib \item \texttt{OCFV} --- OcFirmwareVolumeLib \item \texttt{OCHS} --- OcHashServicesLib \item \texttt{OCI4} --- OcAppleImg4Lib @@ -3818,7 +3819,8 @@ nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-log | \item \texttt{OCJS} --- OcApfsLib \item \texttt{OCKM} --- OcAppleKeyMapLib \item \texttt{OCL} --- OcDebugLogLib - \item \texttt{OCMCO} --- OcMachoLib + \item \DIFaddbegin \texttt{\DIFadd{OCM}} \DIFadd{--- OcMiscLib + }\item \DIFaddend \texttt{OCMCO} --- OcMachoLib \item \texttt{OCME} --- OcHeciLib \item \texttt{OCMM} --- OcMemoryLib \item \texttt{OCPE} --- OcPeCoffLib, OcPeCoffExtLib diff --git a/Docs/Errata/Errata.pdf b/Docs/Errata/Errata.pdf index 4e063f66..33fe3a6b 100644 Binary files a/Docs/Errata/Errata.pdf and b/Docs/Errata/Errata.pdf differ diff --git a/Include/Acidanthera/Library/OcDeviceMiscLib.h b/Include/Acidanthera/Library/OcDeviceMiscLib.h new file mode 100755 index 00000000..872cafb5 --- /dev/null +++ b/Include/Acidanthera/Library/OcDeviceMiscLib.h @@ -0,0 +1,46 @@ +/** @file + Copyright (C) 2021, vit9696. All rights reserved. + + 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 OC_DEVICE_MISC_LIB_H +#define OC_DEVICE_MISC_LIB_H + +#include +#include + +/** + Release UEFI ownership from USB controllers at booting. +**/ +EFI_STATUS +ReleaseUsbOwnership ( + VOID + ); + +/** + Perform cold reboot directly bypassing UEFI services. Does not return. + Supposed to work in any modern physical or virtual environment. +**/ +VOID +DirectResetCold ( + VOID + ); + +/** + Reset HDA TCSEL to TC0 state. +**/ +VOID +ResetAudioTrafficClass ( + VOID + ); + +#endif // OC_DEVICE_MISC_LIB_H diff --git a/Include/Acidanthera/Library/OcMiscLib.h b/Include/Acidanthera/Library/OcMiscLib.h index 941db8d0..c4d72c88 100755 --- a/Include/Acidanthera/Library/OcMiscLib.h +++ b/Include/Acidanthera/Library/OcMiscLib.h @@ -122,23 +122,6 @@ OcLoadAndRunImage ( OUT EFI_HANDLE *ImageHandle OPTIONAL ); -/** - Release UEFI ownership from USB controllers at booting. -**/ -EFI_STATUS -ReleaseUsbOwnership ( - VOID - ); - -/** - Perform cold reboot directly bypassing UEFI services. Does not return. - Supposed to work in any modern physical or virtual environment. -**/ -VOID -DirectResetCold ( - VOID - ); - /** Internal worker macro that calls DebugPrint(). diff --git a/Library/OcBootManagementLib/OcBootManagementLib.inf b/Library/OcBootManagementLib/OcBootManagementLib.inf index 3339c6ee..79b974aa 100644 --- a/Library/OcBootManagementLib/OcBootManagementLib.inf +++ b/Library/OcBootManagementLib/OcBootManagementLib.inf @@ -108,6 +108,7 @@ OcAppleSecureBootLib OcConsoleLib OcCryptoLib + OcDeviceMiscLib OcDevicePathLib OcGuardLib OcFileLib diff --git a/Library/OcBootManagementLib/VariableManagement.c b/Library/OcBootManagementLib/VariableManagement.c index fa014ab1..77aa3452 100644 --- a/Library/OcBootManagementLib/VariableManagement.c +++ b/Library/OcBootManagementLib/VariableManagement.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/Library/OcMiscLib/DirectReset.c b/Library/OcDeviceMiscLib/DirectReset.c similarity index 93% rename from Library/OcMiscLib/DirectReset.c rename to Library/OcDeviceMiscLib/DirectReset.c index 5fe91205..31ac24fd 100644 --- a/Library/OcMiscLib/DirectReset.c +++ b/Library/OcDeviceMiscLib/DirectReset.c @@ -11,6 +11,7 @@ #include #include #include +#include VOID DirectResetCold ( diff --git a/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf b/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf new file mode 100755 index 00000000..69c65d92 --- /dev/null +++ b/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf @@ -0,0 +1,48 @@ +## @file +# +# Component description file for OcMisclibrary. +# +# Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.
+# +# 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. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = OcDeviceMiscLib + FILE_GUID = 4CABEB89-2EBC-434A-84C5-E093FFD34174 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = OcDeviceMiscLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION DXE_SMM_DRIVER + +# VALID_ARCHITECTURES = IA32 X64 + +[Packages] + OpenCorePkg/OpenCorePkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Protocols] + gEfiPciIoProtocolGuid + +[LibraryClasses] + BaseLib + DebugLib + IoLib + OcGuardLib + UefiLib + UefiBootServicesTableLib + +[Sources] + DirectReset.c + ReleaseUsbOwnership.c + ResetAudioTrafficClass.c diff --git a/Library/OcMiscLib/ReleaseUsbOwnership.c b/Library/OcDeviceMiscLib/ReleaseUsbOwnership.c similarity index 99% rename from Library/OcMiscLib/ReleaseUsbOwnership.c rename to Library/OcDeviceMiscLib/ReleaseUsbOwnership.c index f28c9592..e6688e76 100644 --- a/Library/OcMiscLib/ReleaseUsbOwnership.c +++ b/Library/OcDeviceMiscLib/ReleaseUsbOwnership.c @@ -22,6 +22,7 @@ #include #include #include +#include #define XHC_HCCPARAMS_OFFSET 0x10 #define XHC_NEXT_CAPABILITY_MASK 0xFF00 diff --git a/Library/OcDeviceMiscLib/ResetAudioTrafficClass.c b/Library/OcDeviceMiscLib/ResetAudioTrafficClass.c new file mode 100644 index 00000000..e927fef3 --- /dev/null +++ b/Library/OcDeviceMiscLib/ResetAudioTrafficClass.c @@ -0,0 +1,102 @@ +/** @file + Copyright (C) 2016 - 2017, The HermitCrabs Lab. All rights reserved. + + 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 + +#include + +#include + +#include +#include +#include +#include +#include + +VOID +ResetAudioTrafficClass ( + VOID + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + UINTN Index; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT32 ClassCode; + UINT8 TrafficClass; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "OCDM: No PCI devices for TCSEL reset - %r\n", Status)); + return; + } + + for (Index = 0; Index < HandleCount; ++Index) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo + ); + + if (EFI_ERROR (Status)) { + continue; + } + + Status = PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint32, + OFFSET_OF (PCI_DEVICE_INDEPENDENT_REGION, RevisionID), + 1, + &ClassCode + ); + if (EFI_ERROR (Status)) { + continue; + } + + ClassCode >>= 16U; ///< Drop revision and minor codes. + if (ClassCode == (PCI_CLASS_MEDIA << 8 | PCI_CLASS_MEDIA_AUDIO) + || ClassCode == (PCI_CLASS_MEDIA << 8 | 0x3 /* PCI_CLASS_MEDIA_HDA */)) { + Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x44 /* TCSEL */, 1, &TrafficClass); + if (EFI_ERROR (Status)) { + continue; + } + + DEBUG (( + DEBUG_INFO, + "OCDM: Discovered audio device at %u/%u with TCSEL %X\n", + (UINT32) (Index + 1), + (UINT32) HandleCount, + TrafficClass + )); + + // + // Update Traffic Class Select Register to TC0. + // This is required for AppleHDA to output audio on some machines. + // See Intel I/O Controller Hub 9 (ICH9) Family Datasheet for more details. + // + if ((TrafficClass & 0x7U) != 0) { + TrafficClass &= ~0x7U; + PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 0x44 /* TCSEL */, 1, &TrafficClass); + } + } + } +} diff --git a/Library/OcMainLib/OcMainLib.inf b/Library/OcMainLib/OcMainLib.inf index 07cc3b67..087c6a4e 100644 --- a/Library/OcMainLib/OcMainLib.inf +++ b/Library/OcMainLib/OcMainLib.inf @@ -51,7 +51,6 @@ gOcInterfaceProtocolGuid ## SOMETIMES_CONSUMES gEfiSecurityArchProtocolGuid ## SOMETIMES_CONSUMES gEfiSecurity2ArchProtocolGuid ## SOMETIMES_CONSUMES - gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES [LibraryClasses] DevicePathLib @@ -73,6 +72,7 @@ OcConfigurationLib OcConsoleLib OcDataHubLib + OcDeviceMiscLib OcDevicePathLib OcDevicePropertyLib OcDriverConnectionLib diff --git a/Library/OcMainLib/OpenCoreUefi.c b/Library/OcMainLib/OpenCoreUefi.c index 23ad004b..bde7ed45 100644 --- a/Library/OcMainLib/OpenCoreUefi.c +++ b/Library/OcMainLib/OpenCoreUefi.c @@ -37,6 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include diff --git a/Library/OcMainLib/OpenCoreUefiAudio.c b/Library/OcMainLib/OpenCoreUefiAudio.c index 3ecb0b66..754bcf7c 100644 --- a/Library/OcMainLib/OpenCoreUefiAudio.c +++ b/Library/OcMainLib/OpenCoreUefiAudio.c @@ -17,9 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #include -#include #include #include @@ -36,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include @@ -471,84 +470,6 @@ OcAudioExitBootServices ( OcAudio->StopPlayback (OcAudio, TRUE); } -STATIC -VOID -ResetAudioTrafficClass ( - VOID - ) -{ - EFI_STATUS Status; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - UINTN Index; - EFI_PCI_IO_PROTOCOL *PciIo; - UINT32 ClassCode; - UINT8 TrafficClass; - - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_INFO, "OC: No PCI devices for TCSEL reset - %r\n", Status)); - return; - } - - for (Index = 0; Index < HandleCount; ++Index) { - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiPciIoProtocolGuid, - (VOID **) &PciIo - ); - - if (EFI_ERROR (Status)) { - continue; - } - - Status = PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint32, - OFFSET_OF (PCI_DEVICE_INDEPENDENT_REGION, RevisionID), - 1, - &ClassCode - ); - if (EFI_ERROR (Status)) { - continue; - } - - ClassCode >>= 16U; ///< Drop revision and minor codes. - if (ClassCode == (PCI_CLASS_MEDIA << 8 | PCI_CLASS_MEDIA_AUDIO) - || ClassCode == (PCI_CLASS_MEDIA << 8 | 0x3 /* PCI_CLASS_MEDIA_HDA */)) { - Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x44 /* TCSEL */, 1, &TrafficClass); - if (EFI_ERROR (Status)) { - continue; - } - - DEBUG (( - DEBUG_INFO, - "OC: Discovered audio device at %u/%u with TCSEL %X\n", - (UINT32) (Index + 1), - (UINT32) HandleCount, - TrafficClass - )); - - // - // Update Traffic Class Select Register to TC0. - // This is required for AppleHDA to output audio on some machines. - // See Intel I/O Controller Hub 9 (ICH9) Family Datasheet for more details. - // - if ((TrafficClass & 0x7U) != 0) { - TrafficClass &= ~0x7U; - PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 0x44 /* TCSEL */, 1, &TrafficClass); - } - } - } -} - VOID OcLoadUefiAudioSupport ( IN OC_STORAGE_CONTEXT *Storage, diff --git a/Library/OcMiscLib/OcMiscLib.inf b/Library/OcMiscLib/OcMiscLib.inf index c599d5b1..05318824 100755 --- a/Library/OcMiscLib/OcMiscLib.inf +++ b/Library/OcMiscLib/OcMiscLib.inf @@ -47,7 +47,5 @@ [Sources] DataPatcher.c - DirectReset.c ImageRunner.c - ReleaseUsbOwnership.c ProtocolSupport.c diff --git a/OpenCorePkg.dec b/OpenCorePkg.dec index 65dcac01..fd2e1568 100755 --- a/OpenCorePkg.dec +++ b/OpenCorePkg.dec @@ -810,6 +810,9 @@ ## @libraryclass OcDebugLogLib|Include/Acidanthera/Library/OcDebugLogLib.h + ## @libraryclass + OcDeviceMiscLib|Include/Acidanthera/Library/OcDeviceMiscLib.h + ## @libraryclass OcDevicePathLib|Include/Acidanthera/Library/OcDevicePathLib.h diff --git a/OpenCorePkg.dsc b/OpenCorePkg.dsc index 2c7400ef..a52ea9b8 100755 --- a/OpenCorePkg.dsc +++ b/OpenCorePkg.dsc @@ -75,6 +75,7 @@ OcCryptoLib|OpenCorePkg/Library/OcCryptoLib/OcCryptoLib.inf OcDataHubLib|OpenCorePkg/Library/OcDataHubLib/OcDataHubLib.inf OcDebugLogLib|OpenCorePkg/Library/OcDebugLogLib/OcDebugLogLib.inf + OcDeviceMiscLib|OpenCorePkg/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf OcDevicePathLib|OpenCorePkg/Library/OcDevicePathLib/OcDevicePathLib.inf OcDevicePropertyLib|OpenCorePkg/Library/OcDevicePropertyLib/OcDevicePropertyLib.inf OcDeviceTreeLib|OpenCorePkg/Library/OcDeviceTreeLib/OcDeviceTreeLib.inf @@ -210,6 +211,7 @@ OpenCorePkg/Library/OcCryptoLib/OcCryptoLib.inf OpenCorePkg/Library/OcDataHubLib/OcDataHubLib.inf OpenCorePkg/Library/OcDebugLogLib/OcDebugLogLib.inf + OpenCorePkg/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf OpenCorePkg/Library/OcDevicePathLib/OcDevicePathLib.inf OpenCorePkg/Library/OcDevicePropertyLib/OcDevicePropertyLib.inf OpenCorePkg/Library/OcDeviceTreeLib/OcDeviceTreeLib.inf