1 | /* $Id: DevHDA.h 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevHDA.h - VBox Intel HD Audio Controller.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2020 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 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_Audio_DevHDA_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Audio_DevHDA_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <iprt/path.h>
|
---|
25 |
|
---|
26 | #include <VBox/vmm/pdmdev.h>
|
---|
27 |
|
---|
28 | #include "AudioMixer.h"
|
---|
29 |
|
---|
30 | #include "HDACodec.h"
|
---|
31 | #include "HDAStream.h"
|
---|
32 | #include "HDAStreamMap.h"
|
---|
33 | #include "HDAStreamPeriod.h"
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * HDA mixer sink definition (ring-3).
|
---|
39 | *
|
---|
40 | * Its purpose is to know which audio mixer sink is bound to which SDn
|
---|
41 | * (SDI/SDO) device stream.
|
---|
42 | *
|
---|
43 | * This is needed in order to handle interleaved streams (that is, multiple
|
---|
44 | * channels in one stream) or non-interleaved streams (each channel has a
|
---|
45 | * dedicated stream).
|
---|
46 | *
|
---|
47 | * This is only known to the actual device emulation level.
|
---|
48 | */
|
---|
49 | typedef struct HDAMIXERSINK
|
---|
50 | {
|
---|
51 | R3PTRTYPE(PHDASTREAM) pStreamShared;
|
---|
52 | R3PTRTYPE(PHDASTREAMR3) pStreamR3;
|
---|
53 | /** Pointer to the actual audio mixer sink. */
|
---|
54 | R3PTRTYPE(PAUDMIXSINK) pMixSink;
|
---|
55 | } HDAMIXERSINK;
|
---|
56 | /** Pointer to an HDA mixer sink definition (ring-3). */
|
---|
57 | typedef HDAMIXERSINK *PHDAMIXERSINK;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Mapping a stream tag to an HDA stream (ring-3).
|
---|
61 | */
|
---|
62 | typedef struct HDATAG
|
---|
63 | {
|
---|
64 | /** Own stream tag. */
|
---|
65 | uint8_t uTag;
|
---|
66 | uint8_t Padding[7];
|
---|
67 | /** Pointer to associated stream. */
|
---|
68 | R3PTRTYPE(PHDASTREAMR3) pStreamR3;
|
---|
69 | } HDATAG;
|
---|
70 | /** Pointer to a HDA stream tag mapping. */
|
---|
71 | typedef HDATAG *PHDATAG;
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Shared ICH Intel HD audio controller state.
|
---|
75 | */
|
---|
76 | typedef struct HDASTATE
|
---|
77 | {
|
---|
78 | /** Critical section protecting the HDA state. */
|
---|
79 | PDMCRITSECT CritSect;
|
---|
80 | /** The HDA's register set. */
|
---|
81 | uint32_t au32Regs[HDA_NUM_REGS];
|
---|
82 | /** Internal stream states. */
|
---|
83 | HDASTREAM aStreams[HDA_MAX_STREAMS];
|
---|
84 | /** CORB buffer base address. */
|
---|
85 | uint64_t u64CORBBase;
|
---|
86 | /** RIRB buffer base address. */
|
---|
87 | uint64_t u64RIRBBase;
|
---|
88 | /** DMA base address.
|
---|
89 | * Made out of DPLBASE + DPUBASE (3.3.32 + 3.3.33). */
|
---|
90 | uint64_t u64DPBase;
|
---|
91 | /** Size in bytes of CORB buffer (#au32CorbBuf). */
|
---|
92 | uint32_t cbCorbBuf;
|
---|
93 | /** Size in bytes of RIRB buffer (#au64RirbBuf). */
|
---|
94 | uint32_t cbRirbBuf;
|
---|
95 | /** Response Interrupt Count (RINTCNT). */
|
---|
96 | uint16_t u16RespIntCnt;
|
---|
97 | /** Position adjustment (in audio frames).
|
---|
98 | *
|
---|
99 | * This is not an official feature of the HDA specs, but used by
|
---|
100 | * certain OS drivers (e.g. snd_hda_intel) to work around certain
|
---|
101 | * quirks by "real" HDA hardware implementations.
|
---|
102 | *
|
---|
103 | * The position adjustment specifies how many audio frames
|
---|
104 | * a stream is ahead from its actual reading/writing position when
|
---|
105 | * starting a stream.
|
---|
106 | */
|
---|
107 | uint16_t cPosAdjustFrames;
|
---|
108 | /** Whether the position adjustment is enabled or not. */
|
---|
109 | bool fPosAdjustEnabled;
|
---|
110 | /** DMA position buffer enable bit. */
|
---|
111 | bool fDMAPosition;
|
---|
112 | /** Current IRQ level. */
|
---|
113 | uint8_t u8IRQL;
|
---|
114 | #ifdef VBOX_STRICT
|
---|
115 | /** Wall clock (WALCLK) stale count.
|
---|
116 | * This indicates the number of set wall clock values which did not actually
|
---|
117 | * move the counter forward (stale). */
|
---|
118 | uint8_t u8WalClkStaleCnt;
|
---|
119 | #else
|
---|
120 | uint8_t bPadding1;
|
---|
121 | #endif
|
---|
122 | /** The device timer Hz rate. Defaults to HDA_TIMER_HZ_DEFAULT. */
|
---|
123 | uint16_t uTimerHz;
|
---|
124 | /** Padding for alignment. */
|
---|
125 | uint16_t au16Padding3[3];
|
---|
126 | /** Last updated wall clock (WALCLK) counter. */
|
---|
127 | uint64_t u64WalClk;
|
---|
128 | /** The CORB buffer. */
|
---|
129 | uint32_t au32CorbBuf[HDA_CORB_SIZE];
|
---|
130 | /** Pointer to RIRB buffer. */
|
---|
131 | uint64_t au64RirbBuf[HDA_RIRB_SIZE];
|
---|
132 |
|
---|
133 | /** PCI Region \#0: 16KB of MMIO stuff. */
|
---|
134 | IOMMMIOHANDLE hMmio;
|
---|
135 |
|
---|
136 | #ifdef VBOX_WITH_STATISTICS
|
---|
137 | STAMPROFILE StatIn;
|
---|
138 | STAMPROFILE StatOut;
|
---|
139 | STAMCOUNTER StatBytesRead;
|
---|
140 | STAMCOUNTER StatBytesWritten;
|
---|
141 |
|
---|
142 | /** @name Register statistics.
|
---|
143 | * The array members run parallel to g_aHdaRegMap.
|
---|
144 | * @{ */
|
---|
145 | STAMCOUNTER aStatRegReads[HDA_NUM_REGS];
|
---|
146 | STAMCOUNTER aStatRegReadsToR3[HDA_NUM_REGS];
|
---|
147 | STAMCOUNTER aStatRegWrites[HDA_NUM_REGS];
|
---|
148 | STAMCOUNTER aStatRegWritesToR3[HDA_NUM_REGS];
|
---|
149 | STAMCOUNTER StatRegMultiReadsRZ;
|
---|
150 | STAMCOUNTER StatRegMultiReadsR3;
|
---|
151 | STAMCOUNTER StatRegMultiWritesRZ;
|
---|
152 | STAMCOUNTER StatRegMultiWritesR3;
|
---|
153 | STAMCOUNTER StatRegSubWriteRZ;
|
---|
154 | STAMCOUNTER StatRegSubWriteR3;
|
---|
155 | STAMCOUNTER StatRegUnknownReads;
|
---|
156 | STAMCOUNTER StatRegUnknownWrites;
|
---|
157 | STAMCOUNTER StatRegWritesBlockedByReset;
|
---|
158 | STAMCOUNTER StatRegWritesBlockedByRun;
|
---|
159 | /** @} */
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | #ifdef DEBUG
|
---|
163 | /** Debug stuff.
|
---|
164 | * @todo Make STAM values out some of this? */
|
---|
165 | struct
|
---|
166 | {
|
---|
167 | # if 0 /* unused */
|
---|
168 | /** Timestamp (in ns) of the last timer callback (hdaTimer).
|
---|
169 | * Used to calculate the time actually elapsed between two timer callbacks. */
|
---|
170 | uint64_t tsTimerLastCalledNs;
|
---|
171 | # endif
|
---|
172 | /** IRQ debugging information. */
|
---|
173 | struct
|
---|
174 | {
|
---|
175 | /** Timestamp (in ns) of last processed (asserted / deasserted) IRQ. */
|
---|
176 | uint64_t tsProcessedLastNs;
|
---|
177 | /** Timestamp (in ns) of last asserted IRQ. */
|
---|
178 | uint64_t tsAssertedNs;
|
---|
179 | # if 0 /* unused */
|
---|
180 | /** How many IRQs have been asserted already. */
|
---|
181 | uint64_t cAsserted;
|
---|
182 | /** Accumulated elapsed time (in ns) of all IRQ being asserted. */
|
---|
183 | uint64_t tsAssertedTotalNs;
|
---|
184 | /** Timestamp (in ns) of last deasserted IRQ. */
|
---|
185 | uint64_t tsDeassertedNs;
|
---|
186 | /** How many IRQs have been deasserted already. */
|
---|
187 | uint64_t cDeasserted;
|
---|
188 | /** Accumulated elapsed time (in ns) of all IRQ being deasserted. */
|
---|
189 | uint64_t tsDeassertedTotalNs;
|
---|
190 | # endif
|
---|
191 | } IRQ;
|
---|
192 | } Dbg;
|
---|
193 | #endif
|
---|
194 | /** This is for checking that the build was correctly configured in all contexts.
|
---|
195 | * This is set to HDASTATE_ALIGNMENT_CHECK_MAGIC. */
|
---|
196 | uint64_t uAlignmentCheckMagic;
|
---|
197 | } HDASTATE;
|
---|
198 | /** Pointer to a shared HDA device state. */
|
---|
199 | typedef HDASTATE *PHDASTATE;
|
---|
200 |
|
---|
201 | /** Value for HDASTATE:uAlignmentCheckMagic. */
|
---|
202 | #define HDASTATE_ALIGNMENT_CHECK_MAGIC UINT64_C(0x1298afb75893e059)
|
---|
203 |
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Ring-3 ICH Intel HD audio controller state.
|
---|
207 | */
|
---|
208 | typedef struct HDASTATER3
|
---|
209 | {
|
---|
210 | /** Internal stream states. */
|
---|
211 | HDASTREAMR3 aStreams[HDA_MAX_STREAMS];
|
---|
212 | /** Mapping table between stream tags and stream states. */
|
---|
213 | HDATAG aTags[HDA_MAX_TAGS];
|
---|
214 | /** Number of active (running) SDn streams. */
|
---|
215 | uint8_t cStreamsActive;
|
---|
216 | uint8_t abPadding0[7];
|
---|
217 | /** R3 Pointer to the device instance. */
|
---|
218 | PPDMDEVINSR3 pDevIns;
|
---|
219 | /** The base interface for LUN\#0. */
|
---|
220 | PDMIBASE IBase;
|
---|
221 | /** Pointer to HDA codec to use. */
|
---|
222 | R3PTRTYPE(PHDACODEC) pCodec;
|
---|
223 | /** List of associated LUN drivers (HDADRIVER). */
|
---|
224 | RTLISTANCHORR3 lstDrv;
|
---|
225 | /** The device' software mixer. */
|
---|
226 | R3PTRTYPE(PAUDIOMIXER) pMixer;
|
---|
227 | /** HDA sink for (front) output. */
|
---|
228 | HDAMIXERSINK SinkFront;
|
---|
229 | #ifdef VBOX_WITH_AUDIO_HDA_51_SURROUND
|
---|
230 | /** HDA sink for center / LFE output. */
|
---|
231 | HDAMIXERSINK SinkCenterLFE;
|
---|
232 | /** HDA sink for rear output. */
|
---|
233 | HDAMIXERSINK SinkRear;
|
---|
234 | #endif
|
---|
235 | /** HDA mixer sink for line input. */
|
---|
236 | HDAMIXERSINK SinkLineIn;
|
---|
237 | #ifdef VBOX_WITH_AUDIO_HDA_MIC_IN
|
---|
238 | /** Audio mixer sink for microphone input. */
|
---|
239 | HDAMIXERSINK SinkMicIn;
|
---|
240 | #endif
|
---|
241 | /** Debug stuff. */
|
---|
242 | struct
|
---|
243 | {
|
---|
244 | /** Whether debugging is enabled or not. */
|
---|
245 | bool fEnabled;
|
---|
246 | /** Path where to dump the debug output to.
|
---|
247 | * Defaults to VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH. */
|
---|
248 | R3PTRTYPE(char *) pszOutPath;
|
---|
249 | } Dbg;
|
---|
250 | } HDASTATER3;
|
---|
251 | /** Pointer to a ring-3 HDA device state. */
|
---|
252 | typedef HDASTATER3 *PHDASTATER3;
|
---|
253 |
|
---|
254 |
|
---|
255 | #endif /* !VBOX_INCLUDED_SRC_Audio_DevHDA_h */
|
---|
256 |
|
---|