VirtualBox

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

Last change on this file since 82425 was 82420, checked in by vboxsync, 5 years ago

DevHDA: The HDASTREAM::CritSect is not needed unless VBOX_WITH_AUDIO_HDA_ASYNC_IO is defined, the critical section of the device will take care of the serializing then. The hdaR3StreamLock/Unlock functions are left as no-ops (strict builds checks for device critsect ownership). bugref:9218

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* $Id: HDAStream.h 82420 2019-12-05 13:51:16Z vboxsync $ */
2/** @file
3 * HDAStream.h - Streams for HD Audio.
4 */
5
6/*
7 * Copyright (C) 2017-2019 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 Thread;
37 /** Event for letting the thread know there is some data to process. */
38 RTSEMEVENT Event;
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 Padding0[4];
126#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
127 /** Asynchronous I/O state members. */
128 HDASTREAMSTATEAIO AIO;
129#endif
130 /** This stream's data mapping. */
131 HDASTREAMMAP Mapping;
132 /** Current BDLE (Buffer Descriptor List Entry). */
133 HDABDLE BDLE;
134 /** Circular buffer (FIFO) for holding DMA'ed data. */
135 R3PTRTYPE(PRTCIRCBUF) pCircBuf;
136#if HC_ARCH_BITS == 32
137 RTR3PTR Padding1;
138#endif
139 /** Timestamp of the last DMA data transfer. */
140 uint64_t tsTransferLast;
141 /** Timestamp of the next DMA data transfer.
142 * Next for determining the next scheduling window.
143 * Can be 0 if no next transfer is scheduled. */
144 uint64_t tsTransferNext;
145 /** Total transfer size (in bytes) of a transfer period. */
146 uint32_t cbTransferSize;
147 /** Transfer chunk size (in bytes) of a transfer period. */
148 uint32_t cbTransferChunk;
149 /** How many bytes already have been processed in within
150 * the current transfer period. */
151 uint32_t cbTransferProcessed;
152 /** How many interrupts are pending due to
153 * BDLE interrupt-on-completion (IOC) bits set. */
154 uint8_t cTransferPendingInterrupts;
155 uint8_t Padding2[2];
156 /** The stream's timer Hz rate.
157 * This value can can be different from the device's default Hz rate,
158 * depending on the rate the stream expects (e.g. for 5.1 speaker setups).
159 * Set in hdaR3StreamInit(). */
160 uint16_t uTimerHz;
161 /** Number of audio data frames for the position adjustment.
162 * 0 if no position adjustment is needed. */
163 uint16_t cfPosAdjustDefault;
164 /** How many audio data frames are left to be processed
165 * for the position adjustment handling.
166 *
167 * 0 if position adjustment handling is done or inactive. */
168 uint16_t cfPosAdjustLeft;
169 /** (Virtual) clock ticks per byte. */
170 uint64_t cTicksPerByte;
171 /** (Virtual) clock ticks per transfer. */
172 uint64_t cTransferTicks;
173 /** The stream's period. Need for timing. */
174 HDASTREAMPERIOD Period;
175 /** The stream's current configuration.
176 * Should match SDFMT. */
177 PDMAUDIOSTREAMCFG Cfg;
178 uint32_t Padding4;
179#ifdef HDA_USE_DMA_ACCESS_HANDLER
180 /** List of DMA handlers. */
181 RTLISTANCHORR3 lstDMAHandlers;
182#endif
183 /** Timestamp (in ns) of last stream update. */
184 uint64_t tsLastUpdateNs;
185} HDASTREAMSTATE;
186AssertCompileSizeAlignment(HDASTREAMSTATE, 8);
187/** Pointer to the internal state of an HDA stream. */
188typedef HDASTREAMSTATE *PHDASTREAMSTATE;
189
190/**
191 * An HDA stream (SDI / SDO).
192 *
193 * @note This HDA stream has nothing to do with a regular audio stream handled
194 * by the audio connector or the audio mixer. This HDA stream is a serial
195 * data in/out stream (SDI/SDO) defined in hardware and can contain
196 * multiple audio streams in one single SDI/SDO (interleaving streams).
197 *
198 * How a specific SDI/SDO is mapped to our internal audio streams relies on the
199 * stream channel mappings.
200 *
201 * Contains only register values which do *not* change until a stream reset
202 * occurs.
203 */
204typedef struct HDASTREAM
205{
206 /** Stream descriptor number (SDn). */
207 uint8_t u8SD;
208 /** Current channel index.
209 * For a stereo stream, this is u8Channel + 1. */
210 uint8_t u8Channel;
211 uint8_t abPadding0[6];
212 /** DMA base address (SDnBDPU - SDnBDPL).
213 * Will be updated in hdaR3StreamInit(). */
214 uint64_t u64BDLBase;
215 /** Cyclic Buffer Length (SDnCBL).
216 * Represents the size of the ring buffer.
217 * Will be updated in hdaR3StreamInit(). */
218 uint32_t u32CBL;
219 /** Format (SDnFMT).
220 * Will be updated in hdaR3StreamInit(). */
221 uint16_t u16FMT;
222 /** FIFO Size (FIFOS).
223 * Maximum number of bytes that may have been DMA'd into
224 * memory but not yet transmitted on the link.
225 *
226 * Will be updated in hdaR3StreamInit(). */
227 uint16_t u16FIFOS;
228 /** FIFO Watermark. */
229 uint16_t u16FIFOW;
230 /** Last Valid Index (SDnLVI).
231 * Will be updated in hdaR3StreamInit(). */
232 uint16_t u16LVI;
233 uint16_t au16Padding1[2];
234 /** Pointer to the HDA state this stream is attached to. */
235 R3PTRTYPE(PHDASTATE) pHDAState;
236 /** Pointer to HDA sink this stream is attached to. */
237 R3PTRTYPE(PHDAMIXERSINK) pMixSink;
238 /** The timer for pumping data thru the attached LUN drivers. */
239 TMTIMERHANDLE hTimer;
240#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
241 /** The stream's critical section to serialize access between the async I/O
242 * thread and (basically) the guest. */
243 RTCRITSECT CritSect;
244#endif
245 /** Internal state of this stream. */
246 HDASTREAMSTATE State;
247 /** Debug information. */
248 HDASTREAMDEBUG Dbg;
249} HDASTREAM;
250/** Pointer to an HDA stream (SDI / SDO). */
251typedef HDASTREAM *PHDASTREAM;
252
253#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
254/**
255 * HDA stream thread context (arguments).
256 */
257typedef struct HDASTREAMTHREADCTX
258{
259 PHDASTATE pThis;
260 PHDASTREAM pStream;
261} HDASTREAMTHREADCTX, *PHDASTREAMTHREADCTX;
262#endif
263
264#ifdef IN_RING3
265
266/** @name Stream functions.
267 * @{
268 */
269int hdaR3StreamCreate(PHDASTREAM pStream, PHDASTATE pThis, uint8_t u8SD);
270void hdaR3StreamDestroy(PHDASTREAM pStream);
271int hdaR3StreamInit(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint8_t uSD);
272void hdaR3StreamReset(PHDASTATE pThis, PHDASTREAM pStream, uint8_t uSD);
273int hdaR3StreamEnable(PHDASTREAM pStream, bool fEnable);
274uint32_t hdaR3StreamGetPosition(PHDASTATE pThis, PHDASTREAM pStream);
275void hdaR3StreamSetPosition(PHDASTREAM pStream, uint32_t u32LPIB);
276uint32_t hdaR3StreamGetFree(PHDASTREAM pStream);
277uint32_t hdaR3StreamGetUsed(PHDASTREAM pStream);
278bool hdaR3StreamTransferIsScheduled(PHDASTREAM pStream, uint64_t tsNow);
279uint64_t hdaR3StreamTransferGetNext(PHDASTREAM pStream);
280void hdaR3StreamLock(PHDASTREAM pStream);
281void hdaR3StreamUnlock(PHDASTREAM pStream);
282int hdaR3StreamRead(PHDASTREAM pStream, uint32_t cbToRead, uint32_t *pcbRead);
283int hdaR3StreamWrite(PHDASTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
284void hdaR3StreamUpdate(PPDMDEVINS pDevIns, PHDASTREAM pStream, bool fAsync);
285# ifdef HDA_USE_DMA_ACCESS_HANDLER
286bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
287void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
288# endif
289/** @} */
290
291/** @name Async I/O stream functions.
292 * @{
293 */
294# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
295DECLCALLBACK(int) hdaR3StreamAsyncIOThread(RTTHREAD hThreadSelf, void *pvUser);
296int hdaR3StreamAsyncIOCreate(PHDASTREAM pStream);
297int hdaR3StreamAsyncIODestroy(PHDASTREAM pStream);
298int hdaR3StreamAsyncIONotify(PHDASTREAM pStream);
299void hdaR3StreamAsyncIOLock(PHDASTREAM pStream);
300void hdaR3StreamAsyncIOUnlock(PHDASTREAM pStream);
301void hdaR3StreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable);
302# endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */
303/** @} */
304
305#endif /* IN_RING3 */
306#endif /* !VBOX_INCLUDED_SRC_Audio_HDAStream_h */
307
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