OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ResetAudioTrafficClass.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16
17#include <IndustryStandard/Pci.h>
18
19#include <Protocol/PciIo.h>
20
21#include <Library/BaseMemoryLib.h>
22#include <Library/DebugLib.h>
23#include <Library/IoLib.h>
24#include <Library/UefiBootServicesTableLib.h>
26
27#include "PciExtInternal.h"
28
29VOID
31 VOID
32 )
33{
34 EFI_STATUS Status;
35 UINTN HandleCount;
36 EFI_HANDLE *HandleBuffer;
37 UINTN Index;
38 EFI_PCI_IO_PROTOCOL *PciIo;
39 PCI_CLASSCODE ClassCode;
40 UINT8 TrafficClass;
41
42 Status = gBS->LocateHandleBuffer (
43 ByProtocol,
44 &gEfiPciIoProtocolGuid,
45 NULL,
46 &HandleCount,
47 &HandleBuffer
48 );
49
50 if (EFI_ERROR (Status)) {
51 DEBUG ((DEBUG_INFO, "OCDM: No PCI devices for TCSEL reset - %r\n", Status));
52 return;
53 }
54
55 for (Index = 0; Index < HandleCount; ++Index) {
56 Status = gBS->HandleProtocol (
57 HandleBuffer[Index],
58 &gEfiPciIoProtocolGuid,
59 (VOID **)&PciIo
60 );
61
62 if (EFI_ERROR (Status)) {
63 continue;
64 }
65
66 Status = PciIo->Pci.Read (
67 PciIo,
68 EfiPciIoWidthUint8,
69 PCI_CLASSCODE_OFFSET,
70 sizeof (PCI_CLASSCODE) / sizeof (UINT8),
71 &ClassCode
72 );
73 if (EFI_ERROR (Status)) {
74 continue;
75 }
76
77 if ((ClassCode.BaseCode == PCI_CLASS_MEDIA) &&
78 ((ClassCode.SubClassCode == PCI_CLASS_MEDIA_AUDIO) ||
79 (ClassCode.SubClassCode == PCI_CLASS_MEDIA_HDA)))
80 {
81 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, PCI_MEDIA_TCSEL_OFFSET, 1, &TrafficClass);
82 if (EFI_ERROR (Status)) {
83 continue;
84 }
85
86 DEBUG ((
87 DEBUG_INFO,
88 "OCDM: Discovered audio device at %u/%u with TCSEL %X\n",
89 (UINT32)(Index + 1),
90 (UINT32)HandleCount,
91 TrafficClass
92 ));
93
94 //
95 // Update Traffic Class Select Register to TC0.
96 // This is required for AppleHDA to output audio on some machines.
97 // See Intel I/O Controller Hub 9 (ICH9) Family Datasheet for more details.
98 //
99 if ((TrafficClass & TCSEL_CLASS_MASK) != 0) {
100 TrafficClass &= ~TCSEL_CLASS_MASK;
101 PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, PCI_MEDIA_TCSEL_OFFSET, 1, &TrafficClass);
102 }
103 }
104 }
105}
EFI_BOOT_SERVICES * gBS
#define PCI_MEDIA_TCSEL_OFFSET
#define TCSEL_CLASS_MASK
#define PCI_CLASS_MEDIA_HDA
VOID ResetAudioTrafficClass(VOID)