OpenCore  1.0.4
OpenCore Bootloader
1.0.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OcAudioDump.c
Go to the documentation of this file.
1
16
17#include <Library/BaseLib.h>
18#include <Library/BaseMemoryLib.h>
19#include <Library/BaseOverflowLib.h>
20#include <Library/DebugLib.h>
21#include <Library/DevicePathLib.h>
22#include <Library/MemoryAllocationLib.h>
23#include <Library/OcAudioLib.h>
25#include <Library/OcFileLib.h>
26#include <Library/OcMiscLib.h>
27#include <Library/OcStringLib.h>
28#include <Library/PrintLib.h>
29#include <Library/UefiBootServicesTableLib.h>
30
31#include <Protocol/DevicePathToText.h>
32#include <Protocol/HdaIo.h>
35
36#include "OcAudioInternal.h"
37
38//
39// Widget names.
40//
41STATIC
43{
44 "Audio Output",
45 "Audio Input",
46 "Audio Mixer",
47 "Audio Selector",
48 "Pin Complex",
49 "Power Widget",
50 "Volume Knob Widget",
51 "Beep Generator Widget",
52 "Reserved",
53 "Reserved",
54 "Reserved",
55 "Reserved",
56 "Reserved",
57 "Reserved",
58 "Reserved",
59 "Vendor Defined Widget"
60};
61
62//
63// Port names.
64//
65STATIC
67{
68 "Jack",
69 "None",
70 "Fixed",
71 "Int Jack"
72};
73
74//
75// Device names.
76//
77STATIC
79{
80 "Line Out",
81 "Speaker",
82 "HP Out",
83 "CD",
84 "SPDIF Out",
85 "Digital Out",
86 "Modem Line",
87 "Modem Handset",
88 "Line In",
89 "Aux",
90 "Mic",
91 "Telephone",
92 "SPDIF In",
93 "Digital In",
94 "Reserved",
95 "Other"
96};
97
98//
99// Port surface type names.
100//
101STATIC
102CHAR8 *mSurfaces[4] =
103{
104 "Ext",
105 "Int",
106 "Ext",
107 "Other"
108};
109
110//
111// Port location names.
112//
113STATIC
114CHAR8 *mLocations[0xF + 1] =
115{
116 "N/A",
117 "Rear",
118 "Front",
119 "Left",
120 "Right",
121 "Top",
122 "Bottom",
123 "Special",
124 "Special",
125 "Special",
126 "Reserved",
127 "Reserved",
128 "Reserved",
129 "Reserved"
130};
131
132//
133// Connection type names.
134//
135STATIC
137{
138 "Unknown",
139 "1/8",
140 "1/4",
141 "ATAPI",
142 "RCA",
143 "Optical",
144 "Digital",
145 "Analog",
146 "Multi",
147 "XLR",
148 "RJ11",
149 "Combo",
150 "Other",
151 "Other",
152 "Other",
153 "Other"
154};
155
156//
157// Port color names.
158STATIC
160{
161 "Unknown",
162 "Black",
163 "Grey",
164 "Blue",
165 "Green",
166 "Red",
167 "Orange",
168 "Yellow",
169 "Purple",
170 "Pink",
171 "Reserved",
172 "Reserved",
173 "Reserved",
174 "Reserved",
175 "White",
176 "Other"
177};
178
179STATIC
180VOID
182 IN OUT CHAR8 **AsciiBuffer,
183 IN UINTN *AsciiBufferSize,
184 IN UINT32 Rates,
185 IN UINT32 Formats
186 )
187{
188 //
189 // Print sample rates.
190 //
191 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " rates [0x%X]:", (UINT16)Rates);
193 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 8000");
194 }
195
197 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 11025");
198 }
199
201 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 16000");
202 }
203
205 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 22050");
206 }
207
209 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 32000");
210 }
211
213 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 44100");
214 }
215
217 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 48000");
218 }
219
221 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 88200");
222 }
223
225 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 96000");
226 }
227
229 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 176400");
230 }
231
233 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 192000");
234 }
235
237 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 384000");
238 }
239
240 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
241
242 //
243 // Print sample bits.
244 //
245 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " bits [0x%X]:", (UINT16)(Rates >> 16));
247 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 8");
248 }
249
251 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 16");
252 }
253
255 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 20");
256 }
257
259 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 24");
260 }
261
263 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 32");
264 }
265
266 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
267
268 //
269 // Print sample formats.
270 //
271 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " formats [0x%X]:", Formats);
273 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " PCM");
274 }
275
277 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " FLOAT32");
278 }
279
281 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " AC3");
282 }
283
284 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
285}
286
287STATIC
288VOID
290 IN OUT CHAR8 **AsciiBuffer,
291 IN UINTN *AsciiBufferSize,
292 IN UINT32 AmpCaps
293 )
294{
295 if (AmpCaps != 0) {
297 AsciiBuffer,
298 AsciiBufferSize,
299 "ofs=0x%2X, nsteps=0x%2X, stepsize=0x%2X, mute=%u\n",
303 (AmpCaps & HDA_PARAMETER_AMP_CAPS_MUTE) != 0
304 );
305 } else {
306 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "N/A\n");
307 }
308}
309
310STATIC
311VOID
313 IN OUT CHAR8 **AsciiBuffer,
314 IN UINTN *AsciiBufferSize,
315 IN HDA_WIDGET *HdaWidget
316 )
317{
318 UINT32 Index;
319 UINT8 VrefCaps;
320 UINT8 VrefCtrl;
321
322 //
323 // Node header and widget capabilities.
324 //
326 AsciiBuffer,
327 AsciiBufferSize,
328 "Node 0x%2X (%u) [%a] wcaps 0x%X:",
329 HdaWidget->NodeId,
330 HdaWidget->NodeId,
331 mWidgetNames[HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities)],
332 HdaWidget->Capabilities
333 );
334
335 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) {
336 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Stereo");
337 } else {
338 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Mono");
339 }
340
341 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_DIGITAL) {
342 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Digital");
343 }
344
345 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_IN_AMP) {
346 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In");
347 }
348
349 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_OUT_AMP) {
350 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out");
351 }
352
353 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_L_R_SWAP) {
354 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " R/L");
355 }
356
357 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
358
359 //
360 // Input amp capabilities and defaults.
361 //
362 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_IN_AMP) {
363 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In caps: ");
364 PrintAmpCaps (AsciiBuffer, AsciiBufferSize, HdaWidget->AmpInCapabilities);
365
366 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In vals:");
367 for (Index = 0; Index < HdaWidget->ConnectionCount; Index++) {
368 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) {
370 AsciiBuffer,
371 AsciiBufferSize,
372 " [0x%2X 0x%2X]",
373 HdaWidget->AmpInLeftDefaultGainMute[Index],
374 HdaWidget->AmpInRightDefaultGainMute[Index]
375 );
376 } else {
377 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " [0x%2X]", HdaWidget->AmpInLeftDefaultGainMute[Index]);
378 }
379 }
380
381 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
382 }
383
384 //
385 // Output amp capabilities and defaults.
386 //
387 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_OUT_AMP) {
388 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out caps: ");
389 PrintAmpCaps (AsciiBuffer, AsciiBufferSize, HdaWidget->AmpOutCapabilities);
390
391 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out vals:");
392 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) {
394 AsciiBuffer,
395 AsciiBufferSize,
396 " [0x%2X 0x%2X]",
397 HdaWidget->AmpOutLeftDefaultGainMute,
398 HdaWidget->AmpOutRightDefaultGainMute
399 );
400 } else {
401 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " [0x%2X]", HdaWidget->AmpOutLeftDefaultGainMute);
402 }
403
404 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
405 }
406
407 //
408 // Input/output capabilities and defaults.
409 //
410 if ( (HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities) == HDA_WIDGET_TYPE_INPUT)
411 || (HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities) == HDA_WIDGET_TYPE_OUTPUT))
412 {
414 AsciiBuffer,
415 AsciiBufferSize,
416 " Converter: stream=%u, channel=%u\n",
417 HDA_VERB_GET_CONVERTER_STREAM_STR (HdaWidget->DefaultConvStreamChannel),
418 HDA_VERB_GET_CONVERTER_STREAM_CHAN (HdaWidget->DefaultConvStreamChannel)
419 );
420
421 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_FORMAT_OVERRIDE) {
422 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " PCM:\n");
423 PrintRatesFormats (AsciiBuffer, AsciiBufferSize, HdaWidget->SupportedPcmRates, HdaWidget->SupportedFormats);
424 }
425 }
426
427 //
428 // Pin complex capabilities and defaults.
429 //
430 if (HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities) == HDA_WIDGET_TYPE_PIN_COMPLEX) {
431 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Pincap 0x%8X:", HdaWidget->PinCapabilities);
432 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_INPUT) {
433 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " IN");
434 }
435
436 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_OUTPUT) {
437 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " OUT");
438 }
439
440 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_HEADPHONE) {
441 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HP");
442 }
443
444 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_EAPD) {
445 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " EAPD");
446 }
447
448 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_TRIGGER) {
449 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Trigger");
450 }
451
452 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_PRESENCE) {
453 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Detect");
454 }
455
456 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_HBR) {
457 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HBR");
458 }
459
460 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_HDMI) {
461 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HDMI");
462 }
463
464 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_DISPLAYPORT) {
465 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " DP");
466 }
467
468 VrefCaps = HDA_PARAMETER_PIN_CAPS_VREF (HdaWidget->PinCapabilities);
469 if (VrefCaps & HDA_PARAMETER_PIN_CAPS_VREF_HIZ) {
470 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_HIZ");
471 }
472
473 if (VrefCaps & HDA_PARAMETER_PIN_CAPS_VREF_GRD) {
474 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_GRD");
475 }
476
477 if (VrefCaps & HDA_PARAMETER_PIN_CAPS_VREF_50) {
478 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_50");
479 }
480
481 if (VrefCaps & HDA_PARAMETER_PIN_CAPS_VREF_80) {
482 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_80");
483 }
484
485 if (VrefCaps & HDA_PARAMETER_PIN_CAPS_VREF_100) {
486 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_100");
487 }
488
489 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
490
491 if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_EAPD) {
492 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " EAPD 0x%X:", HdaWidget->DefaultEapd);
493 if (HdaWidget->DefaultEapd & HDA_EAPD_BTL_ENABLE_BTL) {
494 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " BTL");
495 }
496
497 if (HdaWidget->DefaultEapd & HDA_EAPD_BTL_ENABLE_EAPD) {
498 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " EAPD");
499 }
500
501 if (HdaWidget->DefaultEapd & HDA_EAPD_BTL_ENABLE_L_R_SWAP) {
502 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " R/L");
503 }
504
505 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
506 }
507
509 AsciiBuffer,
510 AsciiBufferSize,
511 " Pin Default 0x%8X: [%a] %a at %a %a\n",
512 HdaWidget->DefaultConfiguration,
513 mPortConnectivities[HDA_VERB_GET_CONFIGURATION_DEFAULT_PORT_CONN (HdaWidget->DefaultConfiguration)],
514 mDefaultDevices[HDA_VERB_GET_CONFIGURATION_DEFAULT_DEVICE (HdaWidget->DefaultConfiguration)],
515 mSurfaces[HDA_VERB_GET_CONFIGURATION_DEFAULT_SURF (HdaWidget->DefaultConfiguration)],
516 mLocations[HDA_VERB_GET_CONFIGURATION_DEFAULT_LOC (HdaWidget->DefaultConfiguration)]
517 );
518
520 AsciiBuffer,
521 AsciiBufferSize,
522 " Conn = %a, Color = %a\n",
523 mConnTypes[HDA_VERB_GET_CONFIGURATION_DEFAULT_CONN_TYPE (HdaWidget->DefaultConfiguration)],
524 mColors[HDA_VERB_GET_CONFIGURATION_DEFAULT_COLOR (HdaWidget->DefaultConfiguration)]
525 );
526
528 AsciiBuffer,
529 AsciiBufferSize,
530 " DefAssociation = 0x%X, Sequence = 0x%X\n",
531 HDA_VERB_GET_CONFIGURATION_DEFAULT_ASSOCIATION (HdaWidget->DefaultConfiguration),
532 HDA_VERB_GET_CONFIGURATION_DEFAULT_SEQUENCE (HdaWidget->DefaultConfiguration)
533 );
534
535 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "Pin-ctls: 0x%2X:", HdaWidget->DefaultPinControl);
536 if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_IN_EN) {
537 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " IN");
538 }
539
540 if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_OUT_EN) {
541 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " OUT");
542 }
543
544 if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_HP_EN) {
545 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HP");
546 }
547
548 VrefCtrl = HDA_PIN_WIDGET_CONTROL_VREF (HdaWidget->DefaultPinControl);
549 if (VrefCtrl == HDA_PIN_WIDGET_CONTROL_VREF_HIZ) {
550 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_HIZ");
551 } else if (VrefCtrl == HDA_PIN_WIDGET_CONTROL_VREF_GRD) {
552 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_GRD");
553 } else if (VrefCtrl == HDA_PIN_WIDGET_CONTROL_VREF_50) {
554 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_50");
555 } else if (VrefCtrl == HDA_PIN_WIDGET_CONTROL_VREF_80) {
556 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_80");
557 } else if (VrefCtrl == HDA_PIN_WIDGET_CONTROL_VREF_100) {
558 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF_100");
559 }
560
561 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
562 }
563
564 //
565 // Connections to other widgets.
566 //
567 if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_CONN_LIST) {
568 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Connection: %u\n ", HdaWidget->ConnectionCount);
569 for (Index = 0; Index < HdaWidget->ConnectionCount; Index++) {
570 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 0x%2X", HdaWidget->Connections[Index]);
571 }
572
573 OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n");
574 }
575}
576
577EFI_STATUS
579 IN EFI_FILE_PROTOCOL *Root
580 )
581{
582 EFI_STATUS Status;
583 UINTN HandleCount;
584 EFI_HANDLE *HandleBuffer;
585 UINT32 Index;
586
587 EFI_HDA_CONTROLLER_INFO_PROTOCOL *HdaControllerInfo;
588 EFI_HDA_CODEC_INFO_PROTOCOL *HdaCodecInfo;
589 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
590
591 CHAR8 *FileBuffer;
592 UINTN FileBufferSize;
593 CHAR16 TmpFileName[32];
594
595 CONST CHAR16 *Name;
596 CHAR16 *DevicePathStr;
597 BOOLEAN TmpBool;
598 UINT8 Tmp8;
599 UINT32 Tmp32A;
600 UINT32 Tmp32B;
601
602 HDA_WIDGET *HdaWidgets;
603 UINTN HdaWidgetCount;
604 UINT32 HdaWidgetIndex;
605
606 HandleCount = 0;
607
608 //
609 // Get all HDA controller instances.
610 //
611 Status = gBS->LocateHandleBuffer (
612 ByProtocol,
614 NULL,
615 &HandleCount,
616 &HandleBuffer
617 );
618 DEBUG ((DEBUG_INFO, "OCAU: %u HDA controllers installed - %r\n", (UINT32)HandleCount, Status));
619
620 if (!EFI_ERROR (Status)) {
621 for (Index = 0; Index < HandleCount; Index++) {
622 Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiHdaControllerInfoProtocolGuid, (VOID **)&HdaControllerInfo);
623 DEBUG ((DEBUG_INFO, "OCAU: HDA controller %u info open result - %r\n", Index, Status));
624 if (EFI_ERROR (Status)) {
625 continue;
626 }
627
628 FileBufferSize = SIZE_1KB;
629 FileBuffer = AllocateZeroPool (FileBufferSize);
630 if (FileBuffer == NULL) {
631 return EFI_OUT_OF_RESOURCES;
632 }
633
634 //
635 // Get device path of controller.
636 //
637 DevicePath = DevicePathFromHandle (HandleBuffer[Index]);
638 DevicePathStr = NULL;
639 if (DevicePath != NULL) {
640 DevicePathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE);
641 }
642
643 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Device path: %s\n", DevicePathStr != NULL ? DevicePathStr : L"<NULL>");
644 DEBUG ((DEBUG_INFO, "OCAU: Dumping controller at %s\n", DevicePathStr != NULL ? DevicePathStr : L"<NULL>"));
645 if (DevicePathStr != NULL) {
646 FreePool (DevicePathStr);
647 }
648
649 Status = HdaControllerInfo->GetName (HdaControllerInfo, &Name);
650 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Controller: %s\n", Status == EFI_SUCCESS ? Name : L"<NULL>");
651
652 Status = HdaControllerInfo->GetVendorId (HdaControllerInfo, &Tmp32A);
653 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Vendor Id: 0x%X\n", Tmp32A);
654
655 //
656 // Save dumped controller data to file.
657 //
658 if (FileBuffer != NULL) {
659 UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"Controller%u.txt", Index);
660 Status = OcSetFileData (Root, TmpFileName, FileBuffer, (UINT32)AsciiStrLen (FileBuffer));
661 DEBUG ((DEBUG_INFO, "OCAU: Dumped HDA controller %u info result - %r\n", Index, Status));
662
663 FreePool (FileBuffer);
664 }
665 }
666
667 FreePool (HandleBuffer);
668 }
669
670 HandleCount = 0;
671
672 //
673 // Get all HDA codec instances.
674 //
675 Status = gBS->LocateHandleBuffer (
676 ByProtocol,
678 NULL,
679 &HandleCount,
680 &HandleBuffer
681 );
682 DEBUG ((DEBUG_INFO, "OCAU: %u HDA codecs installed - %r\n", (UINT32)HandleCount, Status));
683
684 if (!EFI_ERROR (Status)) {
685 for (Index = 0; Index < HandleCount; Index++) {
686 Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiHdaCodecInfoProtocolGuid, (VOID **)&HdaCodecInfo);
687 DEBUG ((DEBUG_INFO, "OCAU: HDA codec %u info open result - %r\n", Index, Status));
688 if (EFI_ERROR (Status)) {
689 continue;
690 }
691
692 Status = HdaCodecInfo->GetWidgets (HdaCodecInfo, &HdaWidgets, &HdaWidgetCount);
693 if (EFI_ERROR (Status)) {
694 continue;
695 }
696
697 if (BaseOverflowMulAddUN (SIZE_4KB, HdaWidgetCount, SIZE_4KB, &FileBufferSize)) {
698 HdaCodecInfo->FreeWidgetsBuffer (HdaWidgets, HdaWidgetCount);
699 continue;
700 }
701
702 FileBuffer = AllocateZeroPool (FileBufferSize);
703 if (FileBuffer == NULL) {
704 HdaCodecInfo->FreeWidgetsBuffer (HdaWidgets, HdaWidgetCount);
705 return EFI_OUT_OF_RESOURCES;
706 }
707
708 //
709 // Get device path of codec.
710 //
711 DevicePath = DevicePathFromHandle (HandleBuffer[Index]);
712 DevicePathStr = NULL;
713 if (DevicePath != NULL) {
714 DevicePathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE);
715 }
716
717 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Device path: %s\n", DevicePathStr != NULL ? DevicePathStr : L"<NULL>");
718 DEBUG ((DEBUG_INFO, "OCAU: Dumping codec at %s\n", DevicePathStr != NULL ? DevicePathStr : L"<NULL>"));
719 if (DevicePathStr != NULL) {
720 FreePool (DevicePathStr);
721 }
722
723 Status = HdaCodecInfo->GetAddress (HdaCodecInfo, &Tmp8);
724 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Address: 0x%X\n\n", Tmp8);
725
726 Status = HdaCodecInfo->GetName (HdaCodecInfo, &Name);
727 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Codec: %s\n", Status == EFI_SUCCESS ? Name : L"<NULL>");
728
729 Status = HdaCodecInfo->GetAudioFuncId (HdaCodecInfo, &Tmp8, &TmpBool);
730 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "AFG Function Id: 0x%X (unsol %u)\n", Tmp8, TmpBool);
731
732 Status = HdaCodecInfo->GetVendorId (HdaCodecInfo, &Tmp32A);
733 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Vendor Id: 0x%X\n", Tmp32A);
734
735 Status = HdaCodecInfo->GetRevisionId (HdaCodecInfo, &Tmp32A);
736 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Revision Id: 0x%X\n", Tmp32A);
737
738 Status = HdaCodecInfo->GetDefaultRatesFormats (HdaCodecInfo, &Tmp32A, &Tmp32B);
739 if (!EFI_ERROR (Status) && ((Tmp32A != 0) || (Tmp32B != 0))) {
740 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default PCM:\n");
741 PrintRatesFormats (&FileBuffer, &FileBufferSize, Tmp32A, Tmp32B);
742 } else {
743 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default PCM: N/A\n");
744 }
745
746 Status = HdaCodecInfo->GetDefaultAmpCaps (HdaCodecInfo, &Tmp32A, &Tmp32B);
747 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default Amp-In caps: ");
748 PrintAmpCaps (&FileBuffer, &FileBufferSize, Status == EFI_SUCCESS ? Tmp32A : 0);
749 OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default Amp-Out caps: ");
750 PrintAmpCaps (&FileBuffer, &FileBufferSize, Status == EFI_SUCCESS ? Tmp32B : 0);
751
752 //
753 // Print all widgets.
754 //
755 for (HdaWidgetIndex = 0; HdaWidgetIndex < HdaWidgetCount; HdaWidgetIndex++) {
756 PrintWidget (&FileBuffer, &FileBufferSize, &HdaWidgets[HdaWidgetIndex]);
757 }
758
759 HdaCodecInfo->FreeWidgetsBuffer (HdaWidgets, HdaWidgetCount);
760
761 //
762 // Save dumped codec data to file.
763 //
764 if (FileBuffer != NULL) {
765 UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"Codec%u.txt", Index);
766 Status = OcSetFileData (Root, TmpFileName, FileBuffer, (UINT32)AsciiStrLen (FileBuffer));
767 DEBUG ((DEBUG_INFO, "OCAU: Dumped HDA codec %u info result - %r\n", Index, Status));
768
769 FreePool (FileBuffer);
770 }
771 }
772
773 FreePool (HandleBuffer);
774 }
775
776 return EFI_SUCCESS;
777}
EFI_GUID gEfiHdaCodecInfoProtocolGuid
EFI_GUID gEfiHdaControllerInfoProtocolGuid
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_DEVICE(a)
Definition HdaVerbs.h:275
#define HDA_PARAMETER_WIDGET_CAPS_DIGITAL
Definition HdaVerbs.h:410
#define HDA_VERB_GET_CONVERTER_STREAM_CHAN(a)
Definition HdaVerbs.h:104
#define HDA_PARAMETER_PIN_CAPS_EAPD
Definition HdaVerbs.h:471
#define HDA_PIN_WIDGET_CONTROL_OUT_EN
Definition HdaVerbs.h:118
#define HDA_PIN_WIDGET_CONTROL_VREF_50
50%
Definition HdaVerbs.h:113
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_CONN_TYPE(a)
Definition HdaVerbs.h:258
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_PCM
Definition HdaVerbs.h:451
#define HDA_PARAMETER_PIN_CAPS_VREF_GRD
Ground.
Definition HdaVerbs.h:468
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_24BIT
Definition HdaVerbs.h:446
#define HDA_VERB_GET_CONVERTER_STREAM_STR(a)
Definition HdaVerbs.h:105
#define HDA_PARAMETER_PIN_CAPS_VREF(a)
Definition HdaVerbs.h:465
#define HDA_PARAMETER_PIN_CAPS_HBR
Definition HdaVerbs.h:473
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16KHZ
Definition HdaVerbs.h:433
#define HDA_PARAMETER_PIN_CAPS_VREF_100
100%
Definition HdaVerbs.h:470
#define HDA_CONFIG_DEFAULT_DEVICE_OTHER
Definition HdaVerbs.h:291
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_88KHZ
Definition HdaVerbs.h:438
#define HDA_PARAMETER_WIDGET_CAPS_FORMAT_OVERRIDE
Definition HdaVerbs.h:405
#define HDA_WIDGET_TYPE_PIN_COMPLEX
Definition HdaVerbs.h:423
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_192KHZ
Definition HdaVerbs.h:441
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_LOC(a)
Definition HdaVerbs.h:294
#define HDA_PIN_WIDGET_CONTROL_HP_EN
Definition HdaVerbs.h:119
#define HDA_WIDGET_TYPE_VENDOR
Definition HdaVerbs.h:427
#define HDA_EAPD_BTL_ENABLE_L_R_SWAP
Definition HdaVerbs.h:163
#define HDA_PARAMETER_WIDGET_CAPS_IN_AMP
Definition HdaVerbs.h:402
#define HDA_PIN_WIDGET_CONTROL_VREF_80
80%
Definition HdaVerbs.h:115
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16BIT
Definition HdaVerbs.h:444
#define HDA_PIN_WIDGET_CONTROL_VREF_GRD
Ground.
Definition HdaVerbs.h:114
#define HDA_PARAMETER_PIN_CAPS_VREF_HIZ
Hi-Z.
Definition HdaVerbs.h:466
#define HDA_PARAMETER_PIN_CAPS_OUTPUT
Definition HdaVerbs.h:461
#define HDA_EAPD_BTL_ENABLE_EAPD
Definition HdaVerbs.h:162
#define HDA_PARAMETER_AMP_CAPS_NUM_STEPS(a)
Definition HdaVerbs.h:479
#define HDA_PARAMETER_PIN_CAPS_DISPLAYPORT
Definition HdaVerbs.h:472
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8BIT
Definition HdaVerbs.h:443
#define HDA_PARAMETER_AMP_CAPS_STEP_SIZE(a)
Definition HdaVerbs.h:480
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_44KHZ
Definition HdaVerbs.h:436
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_176KHZ
Definition HdaVerbs.h:440
#define HDA_PARAMETER_WIDGET_CAPS_CONN_LIST
Definition HdaVerbs.h:409
#define HDA_PIN_WIDGET_CONTROL_IN_EN
Definition HdaVerbs.h:117
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32BIT
Definition HdaVerbs.h:447
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8KHZ
Definition HdaVerbs.h:431
#define HDA_PARAMETER_PIN_CAPS_INPUT
Definition HdaVerbs.h:462
#define HDA_PARAMETER_PIN_CAPS_TRIGGER
Definition HdaVerbs.h:458
#define HDA_PIN_WIDGET_CONTROL_VREF(a)
Definition HdaVerbs.h:111
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_ASSOCIATION(a)
Definition HdaVerbs.h:235
#define HDA_PARAMETER_AMP_CAPS_OFFSET(a)
Definition HdaVerbs.h:478
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_SEQUENCE(a)
Definition HdaVerbs.h:231
#define HDA_CONFIG_DEFAULT_CONN_OTHER
Definition HdaVerbs.h:272
#define HDA_WIDGET_TYPE_OUTPUT
Definition HdaVerbs.h:419
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_11KHZ
Definition HdaVerbs.h:432
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_384KHZ
Definition HdaVerbs.h:442
#define HDA_PARAMETER_WIDGET_CAPS_L_R_SWAP
Definition HdaVerbs.h:412
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32KHZ
Definition HdaVerbs.h:435
#define HDA_PIN_WIDGET_CONTROL_VREF_100
100%
Definition HdaVerbs.h:116
#define HDA_PARAMETER_PIN_CAPS_VREF_80
80%
Definition HdaVerbs.h:469
#define HDA_PARAMETER_PIN_CAPS_HDMI
Definition HdaVerbs.h:464
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_FLOAT32
Definition HdaVerbs.h:452
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_48KHZ
Definition HdaVerbs.h:437
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_22KHZ
Definition HdaVerbs.h:434
#define HDA_PARAMETER_PIN_CAPS_HEADPHONE
Definition HdaVerbs.h:460
#define HDA_CONFIG_DEFAULT_COLOR_OTHER
Definition HdaVerbs.h:255
#define HDA_PIN_WIDGET_CONTROL_VREF_HIZ
Hi-Z.
Definition HdaVerbs.h:112
#define HDA_PARAMETER_WIDGET_CAPS_TYPE(a)
Definition HdaVerbs.h:416
#define HDA_PARAMETER_PIN_CAPS_VREF_50
50%
Definition HdaVerbs.h:467
#define HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_AC3
Definition HdaVerbs.h:453
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_PORT_CONN(a)
Definition HdaVerbs.h:312
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_COLOR(a)
Definition HdaVerbs.h:242
#define HDA_VERB_GET_CONFIGURATION_DEFAULT_SURF(a)
Definition HdaVerbs.h:304
#define HDA_PARAMETER_PIN_CAPS_PRESENCE
Definition HdaVerbs.h:459
#define HDA_PARAMETER_AMP_CAPS_MUTE
Definition HdaVerbs.h:481
#define HDA_EAPD_BTL_ENABLE_BTL
Definition HdaVerbs.h:161
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_20BIT
Definition HdaVerbs.h:445
#define HDA_WIDGET_TYPE_INPUT
Definition HdaVerbs.h:420
#define HDA_PARAMETER_WIDGET_CAPS_STEREO
Definition HdaVerbs.h:401
#define HDA_PARAMETER_WIDGET_CAPS_OUT_AMP
Definition HdaVerbs.h:403
#define HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_96KHZ
Definition HdaVerbs.h:439
STATIC CHAR8 * mConnTypes[HDA_CONFIG_DEFAULT_CONN_OTHER+1]
STATIC VOID PrintAmpCaps(IN OUT CHAR8 **AsciiBuffer, IN UINTN *AsciiBufferSize, IN UINT32 AmpCaps)
STATIC CHAR8 * mDefaultDevices[HDA_CONFIG_DEFAULT_DEVICE_OTHER+1]
Definition OcAudioDump.c:78
STATIC CHAR8 * mPortConnectivities[4]
Definition OcAudioDump.c:66
STATIC VOID PrintWidget(IN OUT CHAR8 **AsciiBuffer, IN UINTN *AsciiBufferSize, IN HDA_WIDGET *HdaWidget)
STATIC CHAR8 * mWidgetNames[HDA_WIDGET_TYPE_VENDOR+1]
Definition OcAudioDump.c:42
STATIC VOID PrintRatesFormats(IN OUT CHAR8 **AsciiBuffer, IN UINTN *AsciiBufferSize, IN UINT32 Rates, IN UINT32 Formats)
EFI_STATUS OcAudioDump(IN EFI_FILE_PROTOCOL *Root)
STATIC CHAR8 * mSurfaces[4]
STATIC CHAR8 * mColors[HDA_CONFIG_DEFAULT_COLOR_OTHER+1]
STATIC CHAR8 * mLocations[0xF+1]
EFI_BOOT_SERVICES * gBS
EFI_STATUS OcSetFileData(IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL, IN CONST CHAR16 *FileName, IN CONST VOID *Buffer, IN UINT32 Size)
VOID EFIAPI OcAsciiPrintBuffer(IN OUT CHAR8 **AsciiBuffer, IN OUT UINTN *AsciiBufferSize, IN CONST CHAR8 *FormatString,...)
Definition OcAsciiLib.c:510
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DevicePathFromHandle(IN EFI_HANDLE Handle)
Definition UserMisc.c:680