VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/HDAStream.h@ 87875

Last change on this file since 87875 was 87830, checked in by vboxsync, 4 years ago

Audio/HDA: A bit of header cleanup / docs. ticketoem2ref:36

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1/* $Id: HDAStream.h 87830 2021-02-22 08:40:44Z vboxsync $ */
2/** @file
3 * HDAStream.h - Streams for HD Audio.
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_HDAStream_h
19#define VBOX_INCLUDED_SRC_Audio_HDAStream_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "DevHDACommon.h"
25#include "HDAStreamMap.h"
26#include "HDAStreamPeriod.h"
27
28
29#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
30/**
31 * HDA stream's state for asynchronous I/O.
32 */
33typedef struct HDASTREAMSTATEAIO
34{
35 /** Thread handle for the actual I/O thread. */
36 RTTHREAD hThread;
37 /** Event for letting the thread know there is some data to process. */
38 RTSEMEVENT hEvent;
39 /** Critical section for synchronizing access. */
40 RTCRITSECT CritSect;
41 /** Started indicator. */
42 volatile bool fStarted;
43 /** Shutdown indicator. */
44 volatile bool fShutdown;
45 /** Whether the thread should do any data processing or not. */
46 volatile bool fEnabled;
47 bool afPadding[1+4];
48} HDASTREAMSTATEAIO;
49/** Pointer to a HDA stream's asynchronous I/O state. */
50typedef HDASTREAMSTATEAIO *PHDASTREAMSTATEAIO;
51#endif
52
53/**
54 * Structure containing HDA stream debug stuff, configurable at runtime.
55 */
56typedef struct HDASTREAMDEBUGRT
57{
58 /** Whether debugging is enabled or not. */
59 bool fEnabled;
60 uint8_t Padding[7];
61 /** File for dumping stream reads / writes.
62 * For input streams, this dumps data being written to the device FIFO,
63 * whereas for output streams this dumps data being read from the device FIFO. */
64 R3PTRTYPE(PPDMAUDIOFILE) pFileStream;
65 /** File for dumping raw DMA reads / writes.
66 * For input streams, this dumps data being written to the device DMA,
67 * whereas for output streams this dumps data being read from the device DMA. */
68 R3PTRTYPE(PPDMAUDIOFILE) pFileDMARaw;
69 /** File for dumping mapped (that is, extracted) DMA reads / writes. */
70 R3PTRTYPE(PPDMAUDIOFILE) pFileDMAMapped;
71} HDASTREAMDEBUGRT;
72
73/**
74 * Structure containing HDA stream debug information.
75 */
76typedef struct HDASTREAMDEBUG
77{
78#ifdef DEBUG
79 /** Critical section to serialize access if needed. */
80 RTCRITSECT CritSect;
81 uint32_t Padding0[2];
82 /** Number of total read accesses. */
83 uint64_t cReadsTotal;
84 /** Number of total DMA bytes read. */
85 uint64_t cbReadTotal;
86 /** Timestamp (in ns) of last read access. */
87 uint64_t tsLastReadNs;
88 /** Number of total write accesses. */
89 uint64_t cWritesTotal;
90 /** Number of total DMA bytes written. */
91 uint64_t cbWrittenTotal;
92 /** Number of total write accesses since last iteration (Hz). */
93 uint64_t cWritesHz;
94 /** Number of total DMA bytes written since last iteration (Hz). */
95 uint64_t cbWrittenHz;
96 /** Timestamp (in ns) of beginning a new write slot. */
97 uint64_t tsWriteSlotBegin;
98 /** Number of current silence samples in a (consecutive) row. */
99 uint64_t csSilence;
100 /** Number of silent samples in a row to consider an audio block as audio gap (silence). */
101 uint64_t cSilenceThreshold;
102 /** How many bytes to skip in an audio stream before detecting silence.
103 * (useful for intros and silence at the beginning of a song). */
104 uint64_t cbSilenceReadMin;
105#endif
106 /** Runtime debug info. */
107 HDASTREAMDEBUGRT Runtime;
108} HDASTREAMDEBUG;
109typedef HDASTREAMDEBUG *PHDASTREAMDEBUG;
110
111/**
112 * Internal state of a HDA stream.
113 */
114typedef struct HDASTREAMSTATE
115{
116 /** Current BDLE to use. Wraps around to 0 if
117 * maximum (cBDLE) is reached. */
118 uint16_t uCurBDLE;
119 /** Flag indicating whether this stream currently is
120 * in reset mode and therefore not acccessible by the guest. */
121 volatile bool fInReset;
122 /** Flag indicating if the stream is in running state or not. */
123 volatile bool fRunning;
124 /** Unused, padding. */
125 uint8_t abPadding0[4];
126 /** Current BDLE (Buffer Descriptor List Entry). */
127 HDABDLE BDLE;
128 /** Timestamp (absolute, in timer ticks) of the last DMA data transfer. */
129 uint64_t tsTransferLast;
130 /** Timestamp (absolute, in timer ticks) of the next DMA data transfer.
131 * Next for determining the next scheduling window.
132 * Can be 0 if no next transfer is scheduled. */
133 uint64_t tsTransferNext;
134 /** Total transfer size (in bytes) of a transfer period. */
135 uint32_t cbTransferSize;
136 /** Transfer chunk size (in bytes) of a transfer period. */
137 uint32_t cbTransferChunk;
138 /** How many interrupts are pending due to
139 * BDLE interrupt-on-completion (IOC) bits set. */
140 uint8_t cTransferPendingInterrupts;
141 uint8_t abPadding2[7];
142 /** The stream's I/O timer Hz rate. */
143 uint16_t uTimerIoHz;
144 /** Number of audio data frames for the position adjustment.
145 * 0 if no position adjustment is needed. */
146 uint16_t cfPosAdjustDefault;
147 /** How many audio data frames are left to be processed
148 * for the position adjustment handling.
149 *
150 * 0 if position adjustment handling is done or inactive. */
151 uint16_t cfPosAdjustLeft;
152 uint16_t u16Padding3;
153 /** (Virtual) clock ticks per byte. */
154 uint64_t cTicksPerByte;
155 /** (Virtual) clock ticks per transfer. */
156 uint64_t cTransferTicks;
157 /** The stream's period. Need for timing. */
158 HDASTREAMPERIOD Period;
159 /** The stream's current configuration.
160 * Should match SDFMT. */
161 PDMAUDIOSTREAMCFG Cfg;
162 /** Timestamp (real time, in ns) of last DMA transfer. */
163 uint64_t tsLastTransferNs;
164 /** Timestamp (real time, in ns) of last stream read (to backends).
165 * When running in async I/O mode, this differs from \a tsLastTransferNs,
166 * because reading / processing will be done in a separate stream. */
167 uint64_t tsLastReadNs;
168} HDASTREAMSTATE;
169AssertCompileSizeAlignment(HDASTREAMSTATE, 8);
170
171/**
172 * An HDA stream (SDI / SDO) - shared.
173 *
174 * @note This HDA stream has nothing to do with a regular audio stream handled
175 * by the audio connector or the audio mixer. This HDA stream is a serial
176 * data in/out stream (SDI/SDO) defined in hardware and can contain
177 * multiple audio streams in one single SDI/SDO (interleaving streams).
178 *
179 * How a specific SDI/SDO is mapped to our internal audio streams relies on the
180 * stream channel mappings.
181 *
182 * Contains only register values which do *not* change until a stream reset
183 * occurs.
184 */
185typedef struct HDASTREAM
186{
187 /** Stream descriptor number (SDn). */
188 uint8_t u8SD;
189 /** Current channel index.
190 * For a stereo stream, this is u8Channel + 1. */
191 uint8_t u8Channel;
192 uint8_t abPadding0[6];
193#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
194 /** The stream's shared r0/r3 critical section to serialize access between the async I/O
195 * thread and (basically) the guest. */
196 PDMCRITSECT CritSect;
197#endif
198 /** DMA base address (SDnBDPU - SDnBDPL).
199 * Will be updated in hdaR3StreamInit(). */
200 uint64_t u64BDLBase;
201 /** Cyclic Buffer Length (SDnCBL).
202 * Represents the size of the ring buffer.
203 * Will be updated in hdaR3StreamInit(). */
204 uint32_t u32CBL;
205 /** Format (SDnFMT).
206 * Will be updated in hdaR3StreamInit(). */
207 uint16_t u16FMT;
208 /** FIFO Size (checked + translated in bytes, FIFOS).
209 * Maximum number of bytes that may have been DMA'd into
210 * memory but not yet transmitted on the link.
211 *
212 * Will be updated in hdaR3StreamInit(). */
213 uint8_t u8FIFOS;
214 /** FIFO Watermark (checked + translated in bytes, FIFOW). */
215 uint8_t u8FIFOW;
216 uint8_t abPadding1[2];
217 /** FIFO scratch buffer, to avoid intermediate (re-)allocations. */
218 uint8_t abFIFO[HDA_FIFO_MAX + 1];
219 /** Last Valid Index (SDnLVI).
220 * Will be updated in hdaR3StreamInit(). */
221 uint16_t u16LVI;
222 /** The timer for pumping data thru the attached LUN drivers. */
223 TMTIMERHANDLE hTimer;
224 /** Internal state of this stream. */
225 HDASTREAMSTATE State;
226} HDASTREAM;
227/** Pointer to an HDA stream (SDI / SDO). */
228typedef HDASTREAM *PHDASTREAM;
229
230
231/**
232 * An HDA stream (SDI / SDO) - ring-3 bits.
233 */
234typedef struct HDASTREAMR3
235{
236 /** Stream descriptor number (SDn). */
237 uint8_t u8SD;
238 uint8_t abPadding[7];
239 /** The shared state for the parent HDA device. */
240 R3PTRTYPE(PHDASTATE) pHDAStateShared;
241 /** The ring-3 state for the parent HDA device. */
242 R3PTRTYPE(PHDASTATER3) pHDAStateR3;
243 /** Pointer to HDA sink this stream is attached to. */
244 R3PTRTYPE(PHDAMIXERSINK) pMixSink;
245 /** Internal state of this stream. */
246 struct
247 {
248 /** This stream's data mapping. */
249 HDASTREAMMAP Mapping;
250 /** Circular buffer (FIFO) for holding DMA'ed data. */
251 R3PTRTYPE(PRTCIRCBUF) pCircBuf;
252#ifdef HDA_USE_DMA_ACCESS_HANDLER
253 /** List of DMA handlers. */
254 RTLISTANCHORR3 lstDMAHandlers;
255#endif
256#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
257 /** Asynchronous I/O state members. */
258 HDASTREAMSTATEAIO AIO;
259#endif
260 } State;
261 /** Debug bits. */
262 HDASTREAMDEBUG Dbg;
263} HDASTREAMR3;
264/** Pointer to an HDA stream (SDI / SDO). */
265typedef HDASTREAMR3 *PHDASTREAMR3;
266
267#ifdef IN_RING3
268
269/** @name Stream functions (shared).
270 * @{
271 */
272void hdaStreamLock(PHDASTREAM pStreamShared);
273void hdaStreamUnlock(PHDASTREAM pStreamShared);
274/** @} */
275
276/** @name Stream functions (ring-3).
277 * @{
278 */
279int hdaR3StreamConstruct(PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, PHDASTATE pThis,
280 PHDASTATER3 pThisCC, uint8_t uSD);
281void hdaR3StreamDestroy(PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3);
282int hdaR3StreamSetUp(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStreamShared,
283 PHDASTREAMR3 pStreamR3, uint8_t uSD);
284void hdaR3StreamReset(PHDASTATE pThis, PHDASTATER3 pThisCC,
285 PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, uint8_t uSD);
286int hdaR3StreamEnable(PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, bool fEnable);
287void hdaR3StreamSetPositionAdd(PHDASTREAM pStreamShared, PPDMDEVINS pDevIns, PHDASTATE pThis, uint32_t uToAdd);
288bool hdaR3StreamTransferIsScheduled(PHDASTREAM pStreamShared, uint64_t tsNow);
289uint64_t hdaR3StreamTransferGetNext(PHDASTREAM pStreamShared);
290void hdaR3StreamUpdate(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTATER3 pThisCC,
291 PHDASTREAM pStreamShared, PHDASTREAMR3 pStreamR3, bool fInTimer);
292PHDASTREAM hdaR3StreamR3ToShared(PHDASTREAMR3 pStreamCC);
293# ifdef HDA_USE_DMA_ACCESS_HANDLER
294bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
295void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
296# endif
297/** @} */
298
299/** @name Async I/O stream functions (ring-3).
300 * @{
301 */
302# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
303int hdaR3StreamAsyncIOCreate(PHDASTREAMR3 pStreamR3);
304void hdaR3StreamAsyncIOLock(PHDASTREAMR3 pStreamR3);
305void hdaR3StreamAsyncIOUnlock(PHDASTREAMR3 pStreamR3);
306void hdaR3StreamAsyncIOEnable(PHDASTREAMR3 pStreamR3, bool fEnable);
307# endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */
308/** @} */
309
310#endif /* IN_RING3 */
311#endif /* !VBOX_INCLUDED_SRC_Audio_HDAStream_h */
312
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