1 | /* $Id: DevCodec.h 33810 2010-11-05 19:03:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevCodec - VBox ICH Intel HD Audio Codec.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #ifndef DEV_CODEC_H
|
---|
18 | #define DEV_CODEC_H
|
---|
19 | struct CODECState;
|
---|
20 | struct INTELHDLinkState;
|
---|
21 |
|
---|
22 | typedef DECLCALLBACK(int) FNCODECVERBPROCESSOR(struct CODECState *pState, uint32_t cmd, uint64_t *pResp);
|
---|
23 | typedef FNCODECVERBPROCESSOR *PFNCODECVERBPROCESSOR;
|
---|
24 | typedef FNCODECVERBPROCESSOR **PPFNCODECVERBPROCESSOR;
|
---|
25 |
|
---|
26 | /* RPM 5.3.1 */
|
---|
27 | #define CODEC_RESPONSE_UNSOLICITED RT_BIT_64(34)
|
---|
28 |
|
---|
29 | typedef struct CODECVERB
|
---|
30 | {
|
---|
31 | uint32_t verb;
|
---|
32 | /* operation bitness mask */
|
---|
33 | uint32_t mask;
|
---|
34 | PFNCODECVERBPROCESSOR pfn;
|
---|
35 | } CODECVERB;
|
---|
36 |
|
---|
37 | #define CODECNODE_F0_PARAM_LENGTH 0x14
|
---|
38 | #define CODECNODE_F02_PARAM_LENGTH 16
|
---|
39 | typedef struct CODECCOMMONNODE
|
---|
40 | {
|
---|
41 | uint8_t id; /* 7 - bit format */
|
---|
42 | const char *name;
|
---|
43 | /* RPM 5.3.6 */
|
---|
44 | uint32_t au32F00_param[CODECNODE_F0_PARAM_LENGTH];
|
---|
45 | uint32_t au32F02_param[CODECNODE_F02_PARAM_LENGTH];
|
---|
46 | } CODECCOMMONNODE, *PCODECCOMMONNODE;
|
---|
47 |
|
---|
48 | typedef struct ROOTCODECNODE
|
---|
49 | {
|
---|
50 | CODECCOMMONNODE node;
|
---|
51 | }ROOTCODECNODE, *PROOTCODECNODE;
|
---|
52 |
|
---|
53 | #define AMPLIFIER_SIZE 60
|
---|
54 | typedef uint32_t AMPLIFIER[AMPLIFIER_SIZE];
|
---|
55 | #define AMPLIFIER_IN 0
|
---|
56 | #define AMPLIFIER_OUT 1
|
---|
57 | #define AMPLIFIER_LEFT 1
|
---|
58 | #define AMPLIFIER_RIGHT 0
|
---|
59 | #define AMPLIFIER_REGISTER(amp, inout, side, index) ((amp)[30*(inout) + 15*(side) + (index)])
|
---|
60 | typedef struct DACNODE
|
---|
61 | {
|
---|
62 | CODECCOMMONNODE node;
|
---|
63 | uint32_t u32F0d_param;
|
---|
64 | uint32_t u32F04_param;
|
---|
65 | uint32_t u32F05_param;
|
---|
66 | uint32_t u32F06_param;
|
---|
67 | uint32_t u32F0c_param;
|
---|
68 |
|
---|
69 | uint32_t u32A_param;
|
---|
70 | AMPLIFIER B_params;
|
---|
71 |
|
---|
72 | } DACNODE, *PDACNODE;
|
---|
73 |
|
---|
74 | typedef struct ADCNODE
|
---|
75 | {
|
---|
76 | CODECCOMMONNODE node;
|
---|
77 | uint32_t u32F03_param;
|
---|
78 | uint32_t u32F05_param;
|
---|
79 | uint32_t u32F06_param;
|
---|
80 | uint32_t u32F09_param;
|
---|
81 |
|
---|
82 | uint32_t u32A_param;
|
---|
83 | uint32_t u32F01_param;
|
---|
84 | AMPLIFIER B_params;
|
---|
85 | } ADCNODE, *PADCNODE;
|
---|
86 |
|
---|
87 | typedef struct SPDIFOUTNODE
|
---|
88 | {
|
---|
89 | CODECCOMMONNODE node;
|
---|
90 | uint32_t u32F05_param;
|
---|
91 | uint32_t u32F06_param;
|
---|
92 | uint32_t u32F09_param;
|
---|
93 | uint32_t u32F0d_param;
|
---|
94 |
|
---|
95 | uint32_t u32A_param;
|
---|
96 | AMPLIFIER B_params;
|
---|
97 | } SPDIFOUTNODE, *PSPDIFOUTNODE;
|
---|
98 |
|
---|
99 | typedef struct SPDIFINNODE
|
---|
100 | {
|
---|
101 | CODECCOMMONNODE node;
|
---|
102 | uint32_t u32F05_param;
|
---|
103 | uint32_t u32F06_param;
|
---|
104 | uint32_t u32F09_param;
|
---|
105 | uint32_t u32F0d_param;
|
---|
106 |
|
---|
107 | uint32_t u32A_param;
|
---|
108 | AMPLIFIER B_params;
|
---|
109 | } SPDIFINNODE, *PSPDIFINNODE;
|
---|
110 |
|
---|
111 | typedef struct AFGCODECNODE
|
---|
112 | {
|
---|
113 | CODECCOMMONNODE node;
|
---|
114 | uint32_t u32F05_param;
|
---|
115 | uint32_t u32F08_param;
|
---|
116 | uint32_t u32F20_param;
|
---|
117 | uint32_t u32F17_param;
|
---|
118 | } AFGCODECNODE, *PAFGCODECNODE;
|
---|
119 |
|
---|
120 | typedef struct PORTNODE
|
---|
121 | {
|
---|
122 | CODECCOMMONNODE node;
|
---|
123 | uint32_t u32F07_param;
|
---|
124 | uint32_t u32F08_param;
|
---|
125 | uint32_t u32F09_param;
|
---|
126 | uint32_t u32F01_param;
|
---|
127 | uint32_t u32F1c_param;
|
---|
128 | AMPLIFIER B_params;
|
---|
129 | } PORTNODE, *PPORTNODE;
|
---|
130 |
|
---|
131 | typedef struct DIGOUTNODE
|
---|
132 | {
|
---|
133 | CODECCOMMONNODE node;
|
---|
134 | uint32_t u32F01_param;
|
---|
135 | uint32_t u32F08_param;
|
---|
136 | uint32_t u32F07_param;
|
---|
137 | uint32_t u32F09_param;
|
---|
138 | uint32_t u32F1c_param;
|
---|
139 | } DIGOUTNODE, *PDIGOUTNODE;
|
---|
140 |
|
---|
141 | typedef struct DIGINNODE
|
---|
142 | {
|
---|
143 | CODECCOMMONNODE node;
|
---|
144 | uint32_t u32F05_param;
|
---|
145 | uint32_t u32F07_param;
|
---|
146 | uint32_t u32F08_param;
|
---|
147 | uint32_t u32F09_param;
|
---|
148 | uint32_t u32F0c_param;
|
---|
149 | uint32_t u32F1c_param;
|
---|
150 | uint32_t u32F1e_param;
|
---|
151 | } DIGINNODE, *PDIGINNODE;
|
---|
152 |
|
---|
153 | typedef struct ADCMUXNODE
|
---|
154 | {
|
---|
155 | CODECCOMMONNODE node;
|
---|
156 | uint32_t u32F01_param;
|
---|
157 |
|
---|
158 | uint32_t u32A_param;
|
---|
159 | AMPLIFIER B_params;
|
---|
160 | } ADCMUXNODE, *PADCMUXNODE;
|
---|
161 |
|
---|
162 | typedef struct PCBEEPNODE
|
---|
163 | {
|
---|
164 | CODECCOMMONNODE node;
|
---|
165 | uint32_t u32F07_param;
|
---|
166 | uint32_t u32F0a_param;
|
---|
167 |
|
---|
168 | uint32_t u32A_param;
|
---|
169 | AMPLIFIER B_params;
|
---|
170 | uint32_t u32F1c_param;
|
---|
171 | } PCBEEPNODE, *PPCBEEPNODE;
|
---|
172 |
|
---|
173 | typedef struct CDNODE
|
---|
174 | {
|
---|
175 | CODECCOMMONNODE node;
|
---|
176 | uint32_t u32F07_param;
|
---|
177 | uint32_t u32F1c_param;
|
---|
178 | } CDNODE, *PCDNODE;
|
---|
179 |
|
---|
180 | typedef struct VOLUMEKNOBNODE
|
---|
181 | {
|
---|
182 | CODECCOMMONNODE node;
|
---|
183 | uint32_t u32F08_param;
|
---|
184 | uint32_t u32F0f_param;
|
---|
185 | } VOLUMEKNOBNODE, *PVOLUMEKNOBNODE;
|
---|
186 |
|
---|
187 | typedef struct ADCVOLNODE
|
---|
188 | {
|
---|
189 | CODECCOMMONNODE node;
|
---|
190 | uint32_t u32F0c_param;
|
---|
191 | uint32_t u32F01_param;
|
---|
192 | uint32_t u32A_params;
|
---|
193 | AMPLIFIER B_params;
|
---|
194 | } ADCVOLNODE, *PADCVOLNODE;
|
---|
195 |
|
---|
196 | typedef struct RESNODE
|
---|
197 | {
|
---|
198 | CODECCOMMONNODE node;
|
---|
199 | uint32_t u32F05_param;
|
---|
200 | uint32_t u32F06_param;
|
---|
201 | uint32_t u32F07_param;
|
---|
202 | uint32_t u32F1c_param;
|
---|
203 | } RESNODE, *PRESNODE;
|
---|
204 |
|
---|
205 | typedef union CODECNODE
|
---|
206 | {
|
---|
207 | CODECCOMMONNODE node;
|
---|
208 | ROOTCODECNODE root;
|
---|
209 | AFGCODECNODE afg;
|
---|
210 | DACNODE dac;
|
---|
211 | ADCNODE adc;
|
---|
212 | SPDIFOUTNODE spdifout;
|
---|
213 | SPDIFINNODE spdifin;
|
---|
214 | PORTNODE port;
|
---|
215 | DIGOUTNODE digout;
|
---|
216 | DIGINNODE digin;
|
---|
217 | ADCMUXNODE adcmux;
|
---|
218 | PCBEEPNODE pcbeep;
|
---|
219 | CDNODE cdnode;
|
---|
220 | VOLUMEKNOBNODE volumeKnob;
|
---|
221 | ADCVOLNODE adcvol;
|
---|
222 | RESNODE reserved;
|
---|
223 | } CODECNODE, *PCODECNODE;
|
---|
224 |
|
---|
225 | typedef enum
|
---|
226 | {
|
---|
227 | PI_INDEX = 0, /* PCM in */
|
---|
228 | PO_INDEX, /* PCM out */
|
---|
229 | MC_INDEX, /* Mic in */
|
---|
230 | LAST_INDEX
|
---|
231 | } ENMSOUNDSOURCE;
|
---|
232 |
|
---|
233 | typedef enum
|
---|
234 | {
|
---|
235 | STAC9220_CODEC,
|
---|
236 | ALC885_CODEC
|
---|
237 | } ENMCODEC;
|
---|
238 |
|
---|
239 | #define AFMT_IN In
|
---|
240 | #define AFMT_OUT Out
|
---|
241 |
|
---|
242 | #ifdef VBOX_WITH_AUDIO_FLEXIBLE_FORMAT
|
---|
243 | # define MAX_AUDIO_FORMAT 64
|
---|
244 | typedef SWVoiceIn *CODECAUDIOINFORMAT[MAX_AUDIO_FORMAT];
|
---|
245 | typedef SWVoiceOut *CODECAUDIOOUTFORMAT[MAX_AUDIO_FORMAT];
|
---|
246 | # define AUDIO_FORMAT_SELECTOR(pState, dir, hz, mult, divizor) ((pState)->aSwVoice##dir[(hz)*24 + (mult)*8 + (divizor)])
|
---|
247 | # define AFMT_HZ_48K 0
|
---|
248 | # define AFMT_HZ_44_1K 1
|
---|
249 | # define AFMT_MULT_X1 0
|
---|
250 | # define AFMT_MULT_X2 1
|
---|
251 | # define AFMT_MULT_X3 2 /* reserved for stac9220 */
|
---|
252 | # define AFMT_MULT_X4 3
|
---|
253 | # define AFMT_DIV_X1 0
|
---|
254 | # define AFMT_DIV_X2 1
|
---|
255 | # define AFMT_DIV_X3 2
|
---|
256 | # define AFMT_DIV_X4 3
|
---|
257 | # define AFMT_DIV_X5 4
|
---|
258 | # define AFMT_DIV_X6 5
|
---|
259 | # define AFMT_DIV_X7 6
|
---|
260 | # define AFMT_DIV_X8 7
|
---|
261 | #else
|
---|
262 | # define AUDIO_FORMAT_SELECTOR(pState, dir, hz, mult, divizor) ((pState)->SwVoice##dir)
|
---|
263 | #endif
|
---|
264 |
|
---|
265 |
|
---|
266 | typedef struct CODECState
|
---|
267 | {
|
---|
268 | uint16_t id;
|
---|
269 | uint16_t u16VendorId;
|
---|
270 | uint16_t u16DeviceId;
|
---|
271 | uint8_t u8BSKU;
|
---|
272 | uint8_t u8AssemblyId;
|
---|
273 | CODECVERB *pVerbs;
|
---|
274 | int cVerbs;
|
---|
275 | PCODECNODE pNodes;
|
---|
276 | QEMUSoundCard card;
|
---|
277 | #ifndef VBOX_WITH_AUDIO_FLEXIBLE_FORMAT
|
---|
278 | /** PCM in */
|
---|
279 | SWVoiceIn *SwVoiceIn;
|
---|
280 | /** PCM out */
|
---|
281 | SWVoiceOut *SwVoiceOut;
|
---|
282 | /** Mic in */
|
---|
283 | SWVoiceIn *voice_mc;
|
---|
284 | #else
|
---|
285 | CODECAUDIOOUTFORMAT aSwVoiceOut;
|
---|
286 | CODECAUDIOINFORMAT aSwVoiceIn;
|
---|
287 | #endif
|
---|
288 | ENMCODEC enmCodec;
|
---|
289 | void *pHDAState;
|
---|
290 | bool fInReset;
|
---|
291 | const uint8_t cTotalNodes;
|
---|
292 | const uint8_t *au8Ports;
|
---|
293 | const uint8_t *au8Dacs;
|
---|
294 | const uint8_t *au8AdcVols;
|
---|
295 | const uint8_t *au8Adcs;
|
---|
296 | const uint8_t *au8AdcMuxs;
|
---|
297 | const uint8_t *au8Pcbeeps;
|
---|
298 | const uint8_t *au8SpdifIns;
|
---|
299 | const uint8_t *au8SpdifOuts;
|
---|
300 | const uint8_t *au8DigInPins;
|
---|
301 | const uint8_t *au8DigOutPins;
|
---|
302 | const uint8_t *au8Cds;
|
---|
303 | const uint8_t *au8VolKnobs;
|
---|
304 | const uint8_t *au8Reserveds;
|
---|
305 | const uint8_t u8AdcVolsLineIn;
|
---|
306 | const uint8_t u8DacLineOut;
|
---|
307 | DECLR3CALLBACKMEMBER(int, pfnProcess, (struct CODECState *));
|
---|
308 | DECLR3CALLBACKMEMBER(int, pfnLookup, (struct CODECState *pState, uint32_t verb, PPFNCODECVERBPROCESSOR));
|
---|
309 | DECLR3CALLBACKMEMBER(int, pfnReset, (struct CODECState *pState));
|
---|
310 | DECLR3CALLBACKMEMBER(void, pfnTransfer, (struct CODECState *pState, ENMSOUNDSOURCE, int avail));
|
---|
311 | DECLR3CALLBACKMEMBER(int, pfnCodecNodeReset, (struct CODECState *pState, uint8_t, PCODECNODE));
|
---|
312 |
|
---|
313 | } CODECState;
|
---|
314 |
|
---|
315 | int codecConstruct(CODECState *pCodecState, ENMCODEC enmCodec);
|
---|
316 | int codecDestruct(CODECState *pCodecState);
|
---|
317 | int codecSaveState(CODECState *pCodecState, PSSMHANDLE pSSMHandle);
|
---|
318 | int codecLoadState(CODECState *pCodecState, PSSMHANDLE pSSMHandle);
|
---|
319 |
|
---|
320 | #endif
|
---|