OcDeviceMiscLib: Move misc device manipulation to a separate library

This commit is contained in:
vit9696 2021-02-28 12:44:15 +03:00
parent bb6a760938
commit 9bd1d3b497
21 changed files with 217 additions and 103 deletions

View File

@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDeviceMiscLib.h>
#include <Library/OcMiscLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>

View File

@ -41,6 +41,7 @@
[LibraryClasses]
BaseLib
DebugLib
OcDeviceMiscLib
OcMiscLib
UefiApplicationEntryPoint
UefiBootServicesTableLib

Binary file not shown.

View File

@ -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

Binary file not shown.

View File

@ -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

Binary file not shown.

View File

@ -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 <Uefi.h>
#include <Library/OcStringLib.h>
/**
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

View File

@ -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().

View File

@ -108,6 +108,7 @@
OcAppleSecureBootLib
OcConsoleLib
OcCryptoLib
OcDeviceMiscLib
OcDevicePathLib
OcGuardLib
OcFileLib

View File

@ -23,6 +23,7 @@
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcDeviceMiscLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcStringLib.h>
#include <Library/PrintLib.h>

View File

@ -11,6 +11,7 @@
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/OcDeviceMiscLib.h>
VOID
DirectResetCold (

View File

@ -0,0 +1,48 @@
## @file
#
# Component description file for OcMisclibrary.
#
# Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.<BR>
#
# 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

View File

@ -22,6 +22,7 @@
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/OcDeviceMiscLib.h>
#define XHC_HCCPARAMS_OFFSET 0x10
#define XHC_NEXT_CAPABILITY_MASK 0xFF00

View File

@ -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 <Uefi.h>
#include <IndustryStandard/Pci.h>
#include <Protocol/PciIo.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/OcDeviceMiscLib.h>
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);
}
}
}
}

View File

@ -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

View File

@ -37,6 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/OcCpuLib.h>
#include <Library/OcDataHubLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDeviceMiscLib.h>
#include <Library/OcDevicePropertyLib.h>
#include <Library/OcDriverConnectionLib.h>
#include <Library/OcFirmwareVolumeLib.h>

View File

@ -17,9 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Guid/AppleVariable.h>
#include <Guid/OcVariable.h>
#include <Guid/GlobalVariable.h>
#include <IndustryStandard/Pci30.h>
#include <Protocol/AudioDecode.h>
#include <Protocol/PciIo.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
@ -36,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/OcConsoleLib.h>
#include <Library/OcCpuLib.h>
#include <Library/OcDataHubLib.h>
#include <Library/OcDeviceMiscLib.h>
#include <Library/OcDevicePropertyLib.h>
#include <Library/OcDriverConnectionLib.h>
#include <Library/OcFirmwareVolumeLib.h>
@ -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,

View File

@ -47,7 +47,5 @@
[Sources]
DataPatcher.c
DirectReset.c
ImageRunner.c
ReleaseUsbOwnership.c
ProtocolSupport.c

View File

@ -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

View File

@ -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