OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
HdaCodecInfo.c
Go to the documentation of this file.
1/*
2 * File: HdaCodecInfo.c
3 *
4 * Copyright (c) 2018 John Davis
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include "HdaCodec.h"
26
27EFI_STATUS
28EFIAPI
31 OUT UINT8 *Address
32 )
33{
34 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
35
36 if ((This == NULL) || (Address == NULL)) {
37 return EFI_INVALID_PARAMETER;
38 }
39
40 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
41
42 return HdaPrivateData->HdaCodecDev->HdaIo->GetAddress (HdaPrivateData->HdaCodecDev->HdaIo, Address);
43}
44
54EFI_STATUS
55EFIAPI
58 OUT CONST CHAR16 **CodecName
59 )
60{
61 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetCodecName(): start\n"));
62
63 // Create variables.
64 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
65
66 // If parameters are null, fail.
67 if ((This == NULL) || (CodecName == NULL)) {
68 return EFI_INVALID_PARAMETER;
69 }
70
71 // Get private data and fill codec name parameter.
72 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
73 *CodecName = HdaPrivateData->HdaCodecDev->Name;
74 return EFI_SUCCESS;
75}
76
86EFI_STATUS
87EFIAPI
90 OUT UINT32 *VendorId
91 )
92{
93 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetVendorId(): start\n"));
94
95 // Create variables.
96 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
97
98 // If parameters are null, fail.
99 if ((This == NULL) || (VendorId == NULL)) {
100 return EFI_INVALID_PARAMETER;
101 }
102
103 // Get private data and fill vendor ID parameter.
104 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
105 *VendorId = HdaPrivateData->HdaCodecDev->VendorId;
106 return EFI_SUCCESS;
107}
108
118EFI_STATUS
119EFIAPI
122 OUT UINT32 *RevisionId
123 )
124{
125 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetRevisionId(): start\n"));
126
127 // Create variables.
128 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
129
130 // If parameters are null, fail.
131 if ((This == NULL) || (RevisionId == NULL)) {
132 return EFI_INVALID_PARAMETER;
133 }
134
135 // Get private data and fill revision ID parameter.
136 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
137 *RevisionId = HdaPrivateData->HdaCodecDev->RevisionId;
138 return EFI_SUCCESS;
139}
140
150EFI_STATUS
151EFIAPI
154 OUT UINT8 *AudioFuncId,
155 OUT BOOLEAN *UnsolCapable
156 )
157{
158 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetAudioFuncId(): start\n"));
159
160 // Create variables.
161 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
162
163 // If parameters are null, fail.
164 if ((This == NULL) || (AudioFuncId == NULL) || (UnsolCapable == NULL)) {
165 return EFI_INVALID_PARAMETER;
166 }
167
168 // Get private data and fill node ID parameter.
169 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
170 *AudioFuncId = HdaPrivateData->HdaCodecDev->AudioFuncGroup->NodeId;
171 *UnsolCapable = HdaPrivateData->HdaCodecDev->AudioFuncGroup->UnsolCapable;
172 return EFI_SUCCESS;
173}
174
185EFI_STATUS
186EFIAPI
189 OUT UINT32 *Rates,
190 OUT UINT32 *Formats
191 )
192{
193 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetDefaultRatesFormats(): start\n"));
194
195 // Create variables.
196 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
197
198 // If parameters are null, fail.
199 if ((This == NULL) || (Rates == NULL) || (Formats == NULL)) {
200 return EFI_INVALID_PARAMETER;
201 }
202
203 // Get private data and fill rates and formats parameters.
204 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
205 *Rates = HdaPrivateData->HdaCodecDev->AudioFuncGroup->SupportedPcmRates;
206 *Formats = HdaPrivateData->HdaCodecDev->AudioFuncGroup->SupportedFormats;
207 return EFI_SUCCESS;
208}
209
220EFI_STATUS
221EFIAPI
224 OUT UINT32 *AmpInCaps,
225 OUT UINT32 *AmpOutCaps
226 )
227{
228 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetDefaultAmpCaps(): start\n"));
229
230 // Create variables.
231 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
232
233 // If parameters are null, fail.
234 if ((This == NULL) || (AmpInCaps == NULL) || (AmpOutCaps == NULL)) {
235 return EFI_INVALID_PARAMETER;
236 }
237
238 // Get private data and fill amp caps parameters.
239 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
240 *AmpInCaps = HdaPrivateData->HdaCodecDev->AudioFuncGroup->AmpInCapabilities;
241 *AmpOutCaps = HdaPrivateData->HdaCodecDev->AudioFuncGroup->AmpOutCapabilities;
242 return EFI_SUCCESS;
243}
244
256EFI_STATUS
257EFIAPI
260 OUT HDA_WIDGET **Widgets,
261 OUT UINTN *WidgetCount
262 )
263{
264 // DEBUG((DEBUG_INFO, "HdaCodecInfoGetWidgets(): start\n"));
265
266 // Create variables.
267 HDA_CODEC_INFO_PRIVATE_DATA *HdaPrivateData;
268 HDA_WIDGET_DEV *HdaWidgetDev;
269 UINT32 AmpInCount;
270 HDA_WIDGET *HdaWidgets;
271 UINTN HdaWidgetsCount;
272
273 // If parameters are null, fail.
274 if ((This == NULL) || (Widgets == NULL) || (WidgetCount == NULL)) {
275 return EFI_INVALID_PARAMETER;
276 }
277
278 // Get private data and allocate widgets array.
279 HdaPrivateData = HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS (This);
280 HdaWidgetsCount = HdaPrivateData->HdaCodecDev->AudioFuncGroup->WidgetsCount;
281 HdaWidgets = AllocateZeroPool (sizeof (HDA_WIDGET) * HdaWidgetsCount);
282 if (HdaWidgets == NULL) {
283 return EFI_OUT_OF_RESOURCES;
284 }
285
286 // Populate widgets array.
287 for (UINTN w = 0; w < HdaWidgetsCount; w++) {
288 // Get widget.
289 HdaWidgetDev = HdaPrivateData->HdaCodecDev->AudioFuncGroup->Widgets + w;
290
291 // Get basic data.
292 HdaWidgets[w].NodeId = HdaWidgetDev->NodeId;
293 HdaWidgets[w].Capabilities = HdaWidgetDev->Capabilities;
294 HdaWidgets[w].DefaultUnSol = HdaWidgetDev->DefaultUnSol;
295 HdaWidgets[w].DefaultEapd = HdaWidgetDev->DefaultEapd;
296
297 // Get connections.
298 HdaWidgets[w].ConnectionCount = HdaWidgetDev->ConnectionCount;
299 HdaWidgets[w].Connections = AllocateZeroPool (sizeof (UINT16) * HdaWidgetDev->ConnectionCount);
300 if (HdaWidgets[w].Connections == NULL) {
301 goto FREE_WIDGETS;
302 }
303
304 CopyMem (HdaWidgets[w].Connections, HdaWidgetDev->Connections, sizeof (UINT16) * HdaWidgetDev->ConnectionCount);
305
306 // Get power info.
307 HdaWidgets[w].SupportedPowerStates = HdaWidgetDev->SupportedPowerStates;
308 HdaWidgets[w].DefaultPowerState = HdaWidgetDev->DefaultPowerState;
309
310 // Get input amps.
311 HdaWidgets[w].AmpInCapabilities = HdaWidgetDev->AmpInCapabilities;
313 // Determine number of input amps.
314 AmpInCount = HdaWidgetDev->ConnectionCount;
315 if (AmpInCount < 1) {
316 AmpInCount = 1;
317 }
318
319 // Allocate arrays.
320 HdaWidgets[w].AmpInLeftDefaultGainMute = AllocateZeroPool (sizeof (UINT8) * AmpInCount);
321 HdaWidgets[w].AmpInRightDefaultGainMute = AllocateZeroPool (sizeof (UINT8) * AmpInCount);
322 if ((HdaWidgets[w].AmpInLeftDefaultGainMute == NULL) ||
323 (HdaWidgets[w].AmpInRightDefaultGainMute == NULL))
324 {
325 goto FREE_WIDGETS;
326 }
327
328 // Copy arrays.
329 CopyMem (
330 HdaWidgets[w].AmpInLeftDefaultGainMute,
331 HdaWidgetDev->AmpInLeftDefaultGainMute,
332 sizeof (UINT8) * AmpInCount
333 );
334 CopyMem (
335 HdaWidgets[w].AmpInRightDefaultGainMute,
336 HdaWidgetDev->AmpInRightDefaultGainMute,
337 sizeof (UINT8) * AmpInCount
338 );
339 }
340
341 // Get output amp.
342 HdaWidgets[w].AmpOutCapabilities = HdaWidgetDev->AmpOutCapabilities;
343 HdaWidgets[w].AmpOutLeftDefaultGainMute = HdaWidgetDev->AmpOutLeftDefaultGainMute;
344 HdaWidgets[w].AmpOutRightDefaultGainMute = HdaWidgetDev->AmpOutRightDefaultGainMute;
345
346 // Get input/output data.
347 HdaWidgets[w].SupportedPcmRates = HdaWidgetDev->SupportedPcmRates;
348 HdaWidgets[w].SupportedFormats = HdaWidgetDev->SupportedFormats;
349 HdaWidgets[w].DefaultConvFormat = HdaWidgetDev->DefaultConvFormat;
350 HdaWidgets[w].DefaultConvStreamChannel = HdaWidgetDev->DefaultConvStreamChannel;
351 HdaWidgets[w].DefaultConvChannelCount = HdaWidgetDev->DefaultConvChannelCount;
352
353 // Get pin complex data.
354 HdaWidgets[w].PinCapabilities = HdaWidgetDev->PinCapabilities;
355 HdaWidgets[w].DefaultPinControl = HdaWidgetDev->DefaultPinControl;
356 HdaWidgets[w].DefaultConfiguration = HdaWidgetDev->DefaultConfiguration;
357
358 // Get volume knob data.
359 HdaWidgets[w].VolumeCapabilities = HdaWidgetDev->VolumeCapabilities;
360 HdaWidgets[w].DefaultVolume = HdaWidgetDev->DefaultVolume;
361 }
362
363 // Fill parameters.
364 *WidgetCount = HdaWidgetsCount;
365 *Widgets = HdaWidgets;
366 return EFI_SUCCESS;
367
368FREE_WIDGETS:
369 HdaCodecInfoFreeWidgetsBuffer (HdaWidgets, HdaWidgetsCount);
370 return EFI_OUT_OF_RESOURCES;
371}
372
382EFI_STATUS
383EFIAPI
385 IN HDA_WIDGET *Widgets,
386 IN UINTN WidgetCount
387 )
388{
389 // DEBUG((DEBUG_INFO, "HdaCodecInfoFreeWidgetsBuffer(): start\n"));
390
391 // If parameter is null, fail.
392 if (Widgets == NULL) {
393 return EFI_INVALID_PARAMETER;
394 }
395
396 // Free pool buffers.
397 for (UINTN w = 0; w < WidgetCount; w++) {
398 if (Widgets[w].Connections != NULL) {
399 FreePool (Widgets[w].Connections);
400 }
401
402 if (Widgets[w].AmpInLeftDefaultGainMute != NULL) {
403 FreePool (Widgets[w].AmpInLeftDefaultGainMute);
404 }
405
406 if (Widgets[w].AmpInRightDefaultGainMute != NULL) {
407 FreePool (Widgets[w].AmpInRightDefaultGainMute);
408 }
409 }
410
411 FreePool (Widgets);
412 return EFI_SUCCESS;
413}
#define HDA_CODEC_INFO_PRIVATE_DATA_FROM_THIS(This)
Definition HdaCodec.h:143
EFI_STATUS EFIAPI HdaCodecInfoGetCodecName(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT CONST CHAR16 **CodecName)
EFI_STATUS EFIAPI HdaCodecInfoGetWidgets(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT HDA_WIDGET **Widgets, OUT UINTN *WidgetCount)
EFI_STATUS EFIAPI HdaCodecInfoGetAudioFuncId(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT UINT8 *AudioFuncId, OUT BOOLEAN *UnsolCapable)
EFI_STATUS EFIAPI HdaCodecInfoGetRevisionId(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT UINT32 *RevisionId)
EFI_STATUS EFIAPI HdaCodecInfoFreeWidgetsBuffer(IN HDA_WIDGET *Widgets, IN UINTN WidgetCount)
EFI_STATUS EFIAPI HdaCodecInfoGetVendorId(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT UINT32 *VendorId)
EFI_STATUS EFIAPI HdaCodecInfoGetAddress(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT UINT8 *Address)
EFI_STATUS EFIAPI HdaCodecInfoGetDefaultRatesFormats(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT UINT32 *Rates, OUT UINT32 *Formats)
EFI_STATUS EFIAPI HdaCodecInfoGetDefaultAmpCaps(IN EFI_HDA_CODEC_INFO_PROTOCOL *This, OUT UINT32 *AmpInCaps, OUT UINT32 *AmpOutCaps)
#define HDA_PARAMETER_WIDGET_CAPS_IN_AMP
Definition HdaVerbs.h:402
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_HDA_IO_PROTOCOL * HdaIo
Definition HdaCodec.h:109
UINT32 RevisionId
Definition HdaCodec.h:119
UINT32 VendorId
Definition HdaCodec.h:118
HDA_FUNC_GROUP * AudioFuncGroup
Definition HdaCodec.h:124
CHAR16 * Name
Definition HdaCodec.h:120
HDA_CODEC_DEV * HdaCodecDev
Definition HdaCodec.h:140
UINT32 AmpOutCapabilities
Definition HdaCodec.h:96
UINT8 WidgetsCount
Definition HdaCodec.h:101
HDA_WIDGET_DEV * Widgets
Definition HdaCodec.h:100
UINT32 SupportedFormats
Definition HdaCodec.h:94
UINT32 SupportedPcmRates
Definition HdaCodec.h:93
UINT32 AmpInCapabilities
Definition HdaCodec.h:95
BOOLEAN UnsolCapable
Definition HdaCodec.h:88
UINT8 DefaultConvChannelCount
Definition HdaCodec.h:72
UINT8 * AmpInRightDefaultGainMute
Definition HdaCodec.h:63
UINT8 DefaultVolume
Definition HdaCodec.h:82
UINT32 DefaultPowerState
Definition HdaCodec.h:56
UINT32 AmpOutCapabilities
Definition HdaCodec.h:61
UINT8 AmpOutLeftDefaultGainMute
Definition HdaCodec.h:64
UINT8 DefaultConvStreamChannel
Definition HdaCodec.h:71
UINT32 ConnectionCount
Definition HdaCodec.h:50
UINT32 DefaultConfiguration
Definition HdaCodec.h:78
UINT8 AmpOutRightDefaultGainMute
Definition HdaCodec.h:65
UINT16 * Connections
Definition HdaCodec.h:48
UINT32 VolumeCapabilities
Definition HdaCodec.h:81
UINT8 * AmpInLeftDefaultGainMute
Definition HdaCodec.h:62
UINT8 DefaultUnSol
Definition HdaCodec.h:44
UINT32 SupportedPowerStates
Definition HdaCodec.h:55
UINT32 AmpInCapabilities
Definition HdaCodec.h:60
UINT16 DefaultConvFormat
Definition HdaCodec.h:70
UINT8 DefaultEapd
Definition HdaCodec.h:76
UINT32 SupportedFormats
Definition HdaCodec.h:69
UINT32 PinCapabilities
Definition HdaCodec.h:75
UINT8 DefaultPinControl
Definition HdaCodec.h:77
UINT32 Capabilities
Definition HdaCodec.h:43
UINT32 SupportedPcmRates
Definition HdaCodec.h:68
EFI_HDA_IO_GET_ADDRESS GetAddress
Definition HdaIo.h:177
UINT8 DefaultPinControl
UINT8 DefaultEapd
UINT32 AmpInCapabilities
UINT32 DefaultConfiguration
UINT8 DefaultConvChannelCount
UINT32 ConnectionCount
UINT32 SupportedPcmRates
UINT32 DefaultPowerState
UINT8 AmpOutRightDefaultGainMute
UINT32 SupportedPowerStates
UINT32 VolumeCapabilities
UINT16 * Connections
UINT32 SupportedFormats
UINT8 DefaultVolume
UINT8 * AmpInLeftDefaultGainMute
UINT8 DefaultConvStreamChannel
UINT32 Capabilities
UINT8 DefaultUnSol
UINT8 AmpOutLeftDefaultGainMute
UINT16 DefaultConvFormat
UINT32 PinCapabilities
UINT8 * AmpInRightDefaultGainMute
UINT32 AmpOutCapabilities