1 | /* $Id: DevHDA.h 69919 2017-12-04 14:00:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevHDA.h - VBox Intel HD Audio Controller.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2017 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 DEV_HDA_H
|
---|
19 | #define DEV_HDA_H
|
---|
20 |
|
---|
21 | /*********************************************************************************************************************************
|
---|
22 | * Header Files *
|
---|
23 | *********************************************************************************************************************************/
|
---|
24 | #include <VBox/vmm/pdmdev.h>
|
---|
25 |
|
---|
26 | #include "AudioMixer.h"
|
---|
27 |
|
---|
28 | #include "HDACodec.h"
|
---|
29 | #include "HDAStream.h"
|
---|
30 | #include "HDAStreamMap.h"
|
---|
31 | #include "HDAStreamPeriod.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | /*********************************************************************************************************************************
|
---|
35 | * Defines *
|
---|
36 | *********************************************************************************************************************************/
|
---|
37 |
|
---|
38 |
|
---|
39 | /*********************************************************************************************************************************
|
---|
40 | * Structures and Typedefs *
|
---|
41 | *********************************************************************************************************************************/
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Structure defining an HDA mixer sink.
|
---|
45 | * Its purpose is to know which audio mixer sink is bound to
|
---|
46 | * which SDn (SDI/SDO) device stream.
|
---|
47 | *
|
---|
48 | * This is needed in order to handle interleaved streams
|
---|
49 | * (that is, multiple channels in one stream) or non-interleaved
|
---|
50 | * streams (each channel has a dedicated stream).
|
---|
51 | *
|
---|
52 | * This is only known to the actual device emulation level.
|
---|
53 | */
|
---|
54 | typedef struct HDAMIXERSINK
|
---|
55 | {
|
---|
56 | /** SDn ID this sink is assigned to. 0 if not assigned. */
|
---|
57 | uint8_t uSD;
|
---|
58 | /** Channel ID of SDn ID. Only valid if SDn ID is valid. */
|
---|
59 | uint8_t uChannel;
|
---|
60 | uint8_t Padding[3];
|
---|
61 | /** Pointer to the actual audio mixer sink. */
|
---|
62 | R3PTRTYPE(PAUDMIXSINK) pMixSink;
|
---|
63 | } HDAMIXERSINK, *PHDAMIXERSINK;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Structure for mapping a stream tag to an HDA stream.
|
---|
67 | */
|
---|
68 | typedef struct HDATAG
|
---|
69 | {
|
---|
70 | /** Own stream tag. */
|
---|
71 | uint8_t uTag;
|
---|
72 | uint8_t Padding[7];
|
---|
73 | /** Pointer to associated stream. */
|
---|
74 | R3PTRTYPE(PHDASTREAM) pStream;
|
---|
75 | } HDATAG, *PHDATAG;
|
---|
76 |
|
---|
77 | #ifdef DEBUG
|
---|
78 | /** @todo Make STAM values out of this? */
|
---|
79 | typedef struct HDASTATEDBGINFO
|
---|
80 | {
|
---|
81 | /** Timestamp (in ns) of the last timer callback (hdaTimer).
|
---|
82 | * Used to calculate the time actually elapsed between two timer callbacks. */
|
---|
83 | uint64_t tsTimerLastCalledNs;
|
---|
84 | /** IRQ debugging information. */
|
---|
85 | struct
|
---|
86 | {
|
---|
87 | /** Timestamp (in ns) of last processed (asserted / deasserted) IRQ. */
|
---|
88 | uint64_t tsProcessedLastNs;
|
---|
89 | /** Timestamp (in ns) of last asserted IRQ. */
|
---|
90 | uint64_t tsAssertedNs;
|
---|
91 | /** How many IRQs have been asserted already. */
|
---|
92 | uint64_t cAsserted;
|
---|
93 | /** Accumulated elapsed time (in ns) of all IRQ being asserted. */
|
---|
94 | uint64_t tsAssertedTotalNs;
|
---|
95 | /** Timestamp (in ns) of last deasserted IRQ. */
|
---|
96 | uint64_t tsDeassertedNs;
|
---|
97 | /** How many IRQs have been deasserted already. */
|
---|
98 | uint64_t cDeasserted;
|
---|
99 | /** Accumulated elapsed time (in ns) of all IRQ being deasserted. */
|
---|
100 | uint64_t tsDeassertedTotalNs;
|
---|
101 | } IRQ;
|
---|
102 | } HDASTATEDBGINFO, *PHDASTATEDBGINFO;
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * ICH Intel HD Audio Controller state.
|
---|
107 | */
|
---|
108 | typedef struct HDASTATE
|
---|
109 | {
|
---|
110 | /** The PCI device structure. */
|
---|
111 | PDMPCIDEV PciDev;
|
---|
112 | /** R3 Pointer to the device instance. */
|
---|
113 | PPDMDEVINSR3 pDevInsR3;
|
---|
114 | /** R0 Pointer to the device instance. */
|
---|
115 | PPDMDEVINSR0 pDevInsR0;
|
---|
116 | /** R0 Pointer to the device instance. */
|
---|
117 | PPDMDEVINSRC pDevInsRC;
|
---|
118 | /** Padding for alignment. */
|
---|
119 | uint32_t u32Padding;
|
---|
120 | /** Critical section protecting the HDA state. */
|
---|
121 | PDMCRITSECT CritSect;
|
---|
122 | /** The base interface for LUN\#0. */
|
---|
123 | PDMIBASE IBase;
|
---|
124 | RTGCPHYS MMIOBaseAddr;
|
---|
125 | /** The HDA's register set. */
|
---|
126 | uint32_t au32Regs[HDA_NUM_REGS];
|
---|
127 | /** Internal stream states. */
|
---|
128 | HDASTREAM aStreams[HDA_MAX_STREAMS];
|
---|
129 | /** Mapping table between stream tags and stream states. */
|
---|
130 | HDATAG aTags[HDA_MAX_TAGS];
|
---|
131 | /** CORB buffer base address. */
|
---|
132 | uint64_t u64CORBBase;
|
---|
133 | /** RIRB buffer base address. */
|
---|
134 | uint64_t u64RIRBBase;
|
---|
135 | /** DMA base address.
|
---|
136 | * Made out of DPLBASE + DPUBASE (3.3.32 + 3.3.33). */
|
---|
137 | uint64_t u64DPBase;
|
---|
138 | /** Pointer to CORB buffer. */
|
---|
139 | R3PTRTYPE(uint32_t *) pu32CorbBuf;
|
---|
140 | /** Size in bytes of CORB buffer. */
|
---|
141 | uint32_t cbCorbBuf;
|
---|
142 | /** Padding for alignment. */
|
---|
143 | uint32_t u32Padding1;
|
---|
144 | /** Pointer to RIRB buffer. */
|
---|
145 | R3PTRTYPE(uint64_t *) pu64RirbBuf;
|
---|
146 | /** Size in bytes of RIRB buffer. */
|
---|
147 | uint32_t cbRirbBuf;
|
---|
148 | /** DMA position buffer enable bit. */
|
---|
149 | bool fDMAPosition;
|
---|
150 | /** Flag whether the R0 part is enabled. */
|
---|
151 | bool fR0Enabled;
|
---|
152 | /** Flag whether the RC part is enabled. */
|
---|
153 | bool fRCEnabled;
|
---|
154 | /** Number of active (running) SDn streams. */
|
---|
155 | uint8_t cStreamsActive;
|
---|
156 | /** The timer for pumping data thru the attached LUN drivers. */
|
---|
157 | PTMTIMERR3 pTimer;
|
---|
158 | #ifdef VBOX_WITH_STATISTICS
|
---|
159 | STAMPROFILE StatTimer;
|
---|
160 | STAMPROFILE StatIn;
|
---|
161 | STAMPROFILE StatOut;
|
---|
162 | STAMCOUNTER StatBytesRead;
|
---|
163 | STAMCOUNTER StatBytesWritten;
|
---|
164 | #endif
|
---|
165 | /** Pointer to HDA codec to use. */
|
---|
166 | R3PTRTYPE(PHDACODEC) pCodec;
|
---|
167 | /** List of associated LUN drivers (HDADRIVER). */
|
---|
168 | RTLISTANCHORR3 lstDrv;
|
---|
169 | /** The device' software mixer. */
|
---|
170 | R3PTRTYPE(PAUDIOMIXER) pMixer;
|
---|
171 | /** HDA sink for (front) output. */
|
---|
172 | HDAMIXERSINK SinkFront;
|
---|
173 | #ifdef VBOX_WITH_AUDIO_HDA_51_SURROUND
|
---|
174 | /** HDA sink for center / LFE output. */
|
---|
175 | HDAMIXERSINK SinkCenterLFE;
|
---|
176 | /** HDA sink for rear output. */
|
---|
177 | HDAMIXERSINK SinkRear;
|
---|
178 | #endif
|
---|
179 | /** HDA mixer sink for line input. */
|
---|
180 | HDAMIXERSINK SinkLineIn;
|
---|
181 | #ifdef VBOX_WITH_AUDIO_HDA_MIC_IN
|
---|
182 | /** Audio mixer sink for microphone input. */
|
---|
183 | HDAMIXERSINK SinkMicIn;
|
---|
184 | #endif
|
---|
185 | /** Last updated wall clock (WALCLK) counter. */
|
---|
186 | uint64_t u64WalClk;
|
---|
187 | #ifdef VBOX_STRICT
|
---|
188 | /** Wall clock (WALCLK) stale count.
|
---|
189 | * This indicates the number of set wall clock
|
---|
190 | * values which did not actually move the counter forward (stale). */
|
---|
191 | uint8_t u8WalClkStaleCnt;
|
---|
192 | uint8_t au8Padding2[7];
|
---|
193 | #endif
|
---|
194 | /** Response Interrupt Count (RINTCNT). */
|
---|
195 | uint16_t u16RespIntCnt;
|
---|
196 | /** Position adjustment (in audio frames).
|
---|
197 | *
|
---|
198 | * This is not an official feature of the HDA specs, but used by
|
---|
199 | * certain OS drivers (e.g. snd_hda_intel) to work around certain
|
---|
200 | * quirks by "real" HDA hardware implementations.
|
---|
201 | *
|
---|
202 | * The position adjustment specifies how many audio frames
|
---|
203 | * a stream is ahead from its actual reading/writing position when
|
---|
204 | * starting a stream.
|
---|
205 | */
|
---|
206 | uint16_t cPosAdjustFrames;
|
---|
207 | /** Whether the position adjustment is enabled or not. */
|
---|
208 | bool fPosAdjustEnabled;
|
---|
209 | uint8_t Padding1[3];
|
---|
210 | /** Current IRQ level. */
|
---|
211 | uint8_t u8IRQL;
|
---|
212 | /** The device timer Hz rate. Defaults to HDA_TIMER_HZ_DEFAULT. */
|
---|
213 | uint16_t u16TimerHz;
|
---|
214 | /** Padding for alignment. */
|
---|
215 | uint8_t au8Padding3[3];
|
---|
216 | #ifdef DEBUG
|
---|
217 | HDASTATEDBGINFO Dbg;
|
---|
218 | #endif
|
---|
219 | } HDASTATE, *PHDASTATE;
|
---|
220 | #endif /* !DEV_HDA_H */
|
---|
221 |
|
---|