VirtualBox

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

Last change on this file since 89089 was 88943, checked in by vboxsync, 4 years ago

DevHda: hdaR3StreamSetPositionAdd should be static. hdaR3StreamR3ToShared doesn't exists. bugref:9890

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