VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/DevHdaStream.h@ 89510

Last change on this file since 89510 was 89406, checked in by vboxsync, 3 years ago

DevHda: Removed the stream mapping and leave such complications to the mixer buffer. (Still some cleanup to be done here.) bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.7 KB
Line 
1/* $Id: DevHdaStream.h 89406 2021-05-31 14:01:31Z vboxsync $ */
2/** @file
3 * Intel HD Audio Controller Emulation - Streams.
4 */
5
6/*
7 * Copyright (C) 2017-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_DevHdaStream_h
19#define VBOX_INCLUDED_SRC_Audio_DevHdaStream_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "DevHdaCommon.h"
25
26
27/**
28 * Structure containing HDA stream debug stuff, configurable at runtime.
29 */
30typedef struct HDASTREAMDEBUGRT
31{
32 /** Whether debugging is enabled or not. */
33 bool fEnabled;
34 uint8_t Padding[7];
35 /** File for dumping stream reads / writes.
36 * For input streams, this dumps data being written to the device FIFO,
37 * whereas for output streams this dumps data being read from the device FIFO. */
38 R3PTRTYPE(PAUDIOHLPFILE) pFileStream;
39 /** File for dumping raw DMA reads / writes.
40 * For input streams, this dumps data being written to the device DMA,
41 * whereas for output streams this dumps data being read from the device DMA. */
42 R3PTRTYPE(PAUDIOHLPFILE) pFileDMARaw;
43 /** File for dumping mapped (that is, extracted) DMA reads / writes. */
44 R3PTRTYPE(PAUDIOHLPFILE) pFileDMAMapped;
45} HDASTREAMDEBUGRT;
46
47/**
48 * Structure containing HDA stream debug information.
49 */
50typedef struct HDASTREAMDEBUG
51{
52 /** Runtime debug info. */
53 HDASTREAMDEBUGRT Runtime;
54#ifdef DEBUG
55 /** Critical section to serialize access if needed. */
56 RTCRITSECT CritSect;
57 uint32_t Padding0[2];
58 /** Number of total read accesses. */
59 uint64_t cReadsTotal;
60 /** Number of total DMA bytes read. */
61 uint64_t cbReadTotal;
62 /** Timestamp (in ns) of last read access. */
63 uint64_t tsLastReadNs;
64 /** Number of total write accesses. */
65 uint64_t cWritesTotal;
66 /** Number of total DMA bytes written. */
67 uint64_t cbWrittenTotal;
68 /** Number of total write accesses since last iteration (Hz). */
69 uint64_t cWritesHz;
70 /** Number of total DMA bytes written since last iteration (Hz). */
71 uint64_t cbWrittenHz;
72 /** Timestamp (in ns) of beginning a new write slot. */
73 uint64_t tsWriteSlotBegin;
74 /** Number of current silence samples in a (consecutive) row. */
75 uint64_t csSilence;
76 /** Number of silent samples in a row to consider an audio block as audio gap (silence). */
77 uint64_t cSilenceThreshold;
78 /** How many bytes to skip in an audio stream before detecting silence.
79 * (useful for intros and silence at the beginning of a song). */
80 uint64_t cbSilenceReadMin;
81#else
82 uint64_t au64Alignment[2];
83#endif
84} HDASTREAMDEBUG;
85typedef HDASTREAMDEBUG *PHDASTREAMDEBUG;
86
87/**
88 * Internal state of a HDA stream.
89 */
90typedef struct HDASTREAMSTATE
91{
92 /** Flag indicating whether this stream currently is
93 * in reset mode and therefore not acccessible by the guest. */
94 volatile bool fInReset;
95 /** Flag indicating if the stream is in running state or not. */
96 volatile bool fRunning;
97 /** The stream's I/O timer Hz rate. */
98 uint16_t uTimerIoHz;
99 /** How many interrupts are pending due to
100 * BDLE interrupt-on-completion (IOC) bits set. */
101 uint8_t cTransferPendingInterrupts;
102 /** Unused, padding. */
103 uint8_t abPadding1[2];
104 /** Input streams only: Set when we switch from feeding the guest silence and
105 * commits to proving actual audio input bytes. */
106 bool fInputPreBuffered;
107 /** Input streams only: The number of bytes we need to prebuffer. */
108 uint32_t cbInputPreBuffer;
109 uint32_t u32Padding2;
110 /** Timestamp (absolute, in timer ticks) of the last DMA data transfer.
111 * @note This is used for wall clock (WALCLK) calculations. */
112 uint64_t volatile tsTransferLast;
113 /** Timestamp (absolute, in timer ticks) of the next DMA data transfer.
114 * Next for determining the next scheduling window.
115 * Can be 0 if no next transfer is scheduled. */
116 uint64_t tsTransferNext;
117 /** Total transfer size (in bytes) of a transfer period.
118 * @note This is in host side frames, in case we're doing any mapping. */
119 uint32_t cbTransferSize;
120 /** The size of an average transfer. */
121 uint32_t cbAvgTransfer;
122 /** The stream's current host side configuration.
123 * This should match the SDnFMT in all respects but maybe the channel count as
124 * we may need to expand mono or into/from into stereo. The unmodified SDnFMT
125 * properties can be found in HDASTREAMR3::Mapping::PCMProps. */
126 PDMAUDIOSTREAMCFG Cfg;
127 /** Timestamp (real time, in ns) of last DMA transfer. */
128 uint64_t tsLastTransferNs;
129 /** Timestamp (real time, in ns) of last stream read (to backends).
130 * When running in async I/O mode, this differs from \a tsLastTransferNs,
131 * because reading / processing will be done in a separate stream. */
132 uint64_t tsLastReadNs;
133
134 /** This is set to the timer clock time when the msInitialDelay period is over.
135 * Once reached, this is set to zero to avoid unnecessary time queries. */
136 uint64_t tsAioDelayEnd;
137 /** The start time for the playback (on the timer clock). */
138 uint64_t tsStart;
139
140 /** @name DMA engine
141 * @{ */
142 /** The offset into the current BDLE. */
143 uint32_t offCurBdle;
144 /** LVI + 1 */
145 uint16_t cBdles;
146 /** The index of the current BDLE.
147 * This is the entry which period is currently "running" on the DMA timer. */
148 uint8_t idxCurBdle;
149 /** The number of prologue scheduling steps.
150 * This is used when the tail BDLEs doesn't have IOC set. */
151 uint8_t cSchedulePrologue;
152 /** Number of scheduling steps. */
153 uint16_t cSchedule;
154 /** Current scheduling step. */
155 uint16_t idxSchedule;
156 /** Current loop number within the current scheduling step. */
157 uint32_t idxScheduleLoop;
158
159 /** Buffer descriptors and additional timer scheduling state.
160 * (Same as HDABDLEDESC, with more sensible naming.) */
161 struct
162 {
163 /** The buffer address. */
164 uint64_t GCPhys;
165 /** The buffer size (guest bytes). */
166 uint32_t cb;
167 /** The flags (only bit 0 is defined). */
168 uint32_t fFlags;
169 } aBdl[256];
170 /** Scheduling steps. */
171 struct
172 {
173 /** Number of timer ticks per period.
174 * ASSUMES that we don't need a full second and that the timer resolution
175 * isn't much higher than nanoseconds. */
176 uint32_t cPeriodTicks;
177 /** The period length in host bytes. */
178 uint32_t cbPeriod;
179 /** Number of times to repeat the period. */
180 uint32_t cLoops;
181 /** The BDL index of the first entry. */
182 uint8_t idxFirst;
183 /** The number of BDL entries. */
184 uint8_t cEntries;
185 uint8_t abPadding[2];
186 } aSchedule[512+8];
187 /** @} */
188} HDASTREAMSTATE;
189AssertCompileSizeAlignment(HDASTREAMSTATE, 8);
190AssertCompileMemberAlignment(HDASTREAMSTATE, aBdl, 8);
191AssertCompileMemberAlignment(HDASTREAMSTATE, aBdl, 16);
192AssertCompileMemberAlignment(HDASTREAMSTATE, aSchedule, 16);
193
194/**
195 * An HDA stream (SDI / SDO) - shared.
196 *
197 * @note This HDA stream has nothing to do with a regular audio stream handled
198 * by the audio connector or the audio mixer. This HDA stream is a serial
199 * data in/out stream (SDI/SDO) defined in hardware and can contain
200 * multiple audio streams in one single SDI/SDO (interleaving streams).
201 *
202 * How a specific SDI/SDO is mapped to our internal audio streams relies on the
203 * stream channel mappings.
204 *
205 * Contains only register values which do *not* change until a stream reset
206 * occurs.
207 */
208typedef struct HDASTREAM
209{
210 /** Internal state of this stream. */
211 HDASTREAMSTATE State;
212
213 /** Stream descriptor number (SDn). */
214 uint8_t u8SD;
215 /** Current channel index.
216 * For a stereo stream, this is u8Channel + 1. */
217 uint8_t u8Channel;
218 /** FIFO Watermark (checked + translated in bytes, FIFOW).
219 * This will be update from hdaRegWriteSDFIFOW() and also copied
220 * hdaR3StreamInit() for some reason. */
221 uint8_t u8FIFOW;
222
223 /** @name Register values at stream setup.
224 * These will all be copied in hdaR3StreamInit().
225 * @{ */
226 /** FIFO Size (checked + translated in bytes, FIFOS).
227 * This is supposedly the max number of bytes we'll be DMA'ing in one chunk
228 * and correspondingly the LPIB & wall clock update jumps. However, we're
229 * not at all being honest with the guest about this. */
230 uint8_t u8FIFOS;
231 /** Cyclic Buffer Length (SDnCBL) - Represents the size of the ring buffer. */
232 uint32_t u32CBL;
233 /** Last Valid Index (SDnLVI). */
234 uint16_t u16LVI;
235 /** Format (SDnFMT). */
236 uint16_t u16FMT;
237 uint8_t abPadding[4];
238 /** DMA base address (SDnBDPU - SDnBDPL). */
239 uint64_t u64BDLBase;
240 /** @} */
241
242 /** The timer for pumping data thru the attached LUN drivers. */
243 TMTIMERHANDLE hTimer;
244
245 /** Pad the structure size to a 64 byte alignment. */
246 uint64_t au64Padding1[2];
247 /** Critical section for serialize access to the stream state between the async
248 * I/O thread and (basically) the guest. */
249 PDMCRITSECT CritSect;
250} HDASTREAM;
251AssertCompileMemberAlignment(HDASTREAM, State.aBdl, 16);
252AssertCompileMemberAlignment(HDASTREAM, State.aSchedule, 16);
253AssertCompileSizeAlignment(HDASTREAM, 64);
254/** Pointer to an HDA stream (SDI / SDO). */
255typedef HDASTREAM *PHDASTREAM;
256
257
258/**
259 * An HDA stream (SDI / SDO) - ring-3 bits.
260 */
261typedef struct HDASTREAMR3
262{
263 /** Stream descriptor number (SDn). */
264 uint8_t u8SD;
265 uint8_t abPadding[7];
266 /** The shared state for the parent HDA device. */
267 R3PTRTYPE(PHDASTATE) pHDAStateShared;
268 /** The ring-3 state for the parent HDA device. */
269 R3PTRTYPE(PHDASTATER3) pHDAStateR3;
270 /** Pointer to HDA sink this stream is attached to. */
271 R3PTRTYPE(PHDAMIXERSINK) pMixSink;
272 /** Internal state of this stream. */
273 struct
274 {
275 /** Circular buffer (FIFO) for holding DMA'ed data. */
276 R3PTRTYPE(PRTCIRCBUF) pCircBuf;
277 /** Current circular buffer read offset (for tracing & logging). */
278 uint64_t offRead;
279 /** Current circular buffer write offset (for tracing & logging). */
280 uint64_t offWrite;
281#ifdef HDA_USE_DMA_ACCESS_HANDLER
282 /** List of DMA handlers. */
283 RTLISTANCHORR3 lstDMAHandlers;
284#endif
285 /** The mixer sink this stream has registered AIO update callback with.
286 * This is NULL till we register it, typically in hdaR3StreamEnable.
287 * (The problem with following the pMixSink assignment is that hdaR3StreamReset
288 * sets it without updating the HDA sink structure, so things get out of
289 * wack in hdaR3MixerControl later in the initial device reset.) */
290 PAUDMIXSINK pAioRegSink;
291
292 /** Size of the DMA buffer (pCircBuf) in bytes. */
293 uint32_t StatDmaBufSize;
294 /** Number of used bytes in the DMA buffer (pCircBuf). */
295 uint32_t StatDmaBufUsed;
296 /** Counter for all under/overflows problems. */
297 STAMCOUNTER StatDmaFlowProblems;
298 /** Counter for unresovled under/overflows problems. */
299 STAMCOUNTER StatDmaFlowErrors;
300 /** Number of bytes involved in unresolved flow errors. */
301 STAMCOUNTER StatDmaFlowErrorBytes;
302
303 STAMPROFILE StatStart;
304 STAMPROFILE StatReset;
305 STAMPROFILE StatStop;
306 STAMPROFILE StatUnusedPadding;
307 } State;
308 /** Debug bits. */
309 HDASTREAMDEBUG Dbg;
310 uint64_t au64Alignment[2+4];
311} HDASTREAMR3;
312AssertCompileSizeAlignment(HDASTREAMR3, 64);
313/** Pointer to an HDA stream (SDI / SDO). */
314typedef HDASTREAMR3 *PHDASTREAMR3;
315
316/** @name Stream functions (shared).
317 * @{
318 */
319void hdaStreamLock(PHDASTREAM pStreamShared);
320void hdaStreamUnlock(PHDASTREAM pStreamShared);
321/** @} */
322
323#ifdef IN_RING3
324
325/** @name Stream functions (ring-3).
326 * @{
327 */
328int hdaR3StreamConstruct(PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, PHDASTATE pThis,
329 PHDASTATER3 pThisCC, uint8_t uSD);
330void hdaR3StreamDestroy(PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3);
331int hdaR3StreamSetUp(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStreamShared,
332 PHDASTREAMR3 pStreamR3, uint8_t uSD);
333void hdaR3StreamReset(PHDASTATE pThis, PHDASTATER3 pThisCC,
334 PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, uint8_t uSD);
335int hdaR3StreamEnable(PHDASTATE pThis, PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, bool fEnable);
336void hdaR3StreamMarkStarted(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStreamShared, uint64_t tsNow);
337void hdaR3StreamMarkStopped(PHDASTREAM pStreamShared);
338
339uint64_t hdaR3StreamTimerMain(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTATER3 pThisCC,
340 PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3);
341DECLCALLBACK(void) hdaR3StreamUpdateAsyncIoJob(PPDMDEVINS pDevIns, PAUDMIXSINK pSink, void *pvUser);
342# ifdef HDA_USE_DMA_ACCESS_HANDLER
343bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
344void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
345# endif
346/** @} */
347
348#endif /* IN_RING3 */
349#endif /* !VBOX_INCLUDED_SRC_Audio_DevHdaStream_h */
350
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette