VirtualBox

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

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

DevHDA: Cleanups. 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 82406 2019-12-05 00:47:02Z vboxsync $ */
2/** @file
3 * HDAStream.h - Stream functions 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
26#include "HDAStreamMap.h"
27#include "HDAStreamPeriod.h"
28
29
30typedef struct HDAMIXERSINK *PHDAMIXERSINK;
31
32#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
33/**
34 * Structure keeping the HDA stream's state for asynchronous I/O.
35 */
36typedef struct HDASTREAMSTATEAIO
37{
38 /** Thread handle for the actual I/O thread. */
39 RTTHREAD Thread;
40 /** Event for letting the thread know there is some data to process. */
41 RTSEMEVENT Event;
42 /** Critical section for synchronizing access. */
43 RTCRITSECT CritSect;
44 /** Started indicator. */
45 volatile bool fStarted;
46 /** Shutdown indicator. */
47 volatile bool fShutdown;
48 /** Whether the thread should do any data processing or not. */
49 volatile bool fEnabled;
50 uint32_t Padding1;
51} HDASTREAMSTATEAIO, *PHDASTREAMSTATEAIO;
52#endif
53
54/**
55 * Structure containing HDA stream debug stuff, configurable at runtime.
56 */
57typedef struct HDASTREAMDBGINFORT
58{
59 /** Whether debugging is enabled or not. */
60 bool fEnabled;
61 uint8_t Padding[7];
62 /** File for dumping stream reads / writes.
63 * For input streams, this dumps data being written to the device FIFO,
64 * whereas for output streams this dumps data being read from the device FIFO. */
65 R3PTRTYPE(PPDMAUDIOFILE) pFileStream;
66 /** File for dumping raw DMA reads / writes.
67 * For input streams, this dumps data being written to the device DMA,
68 * whereas for output streams this dumps data being read from the device DMA. */
69 R3PTRTYPE(PPDMAUDIOFILE) pFileDMARaw;
70 /** File for dumping mapped (that is, extracted) DMA reads / writes. */
71 R3PTRTYPE(PPDMAUDIOFILE) pFileDMAMapped;
72} HDASTREAMDBGINFORT, *PHDASTREAMDBGINFORT;
73
74/**
75 * Structure containing HDA stream debug information.
76 */
77typedef struct HDASTREAMDBGINFO
78{
79#ifdef DEBUG
80 /** Critical section to serialize access if needed. */
81 RTCRITSECT CritSect;
82 uint32_t Padding0[2];
83 /** Number of total read accesses. */
84 uint64_t cReadsTotal;
85 /** Number of total DMA bytes read. */
86 uint64_t cbReadTotal;
87 /** Timestamp (in ns) of last read access. */
88 uint64_t tsLastReadNs;
89 /** Number of total write accesses. */
90 uint64_t cWritesTotal;
91 /** Number of total DMA bytes written. */
92 uint64_t cbWrittenTotal;
93 /** Number of total write accesses since last iteration (Hz). */
94 uint64_t cWritesHz;
95 /** Number of total DMA bytes written since last iteration (Hz). */
96 uint64_t cbWrittenHz;
97 /** Timestamp (in ns) of beginning a new write slot. */
98 uint64_t tsWriteSlotBegin;
99 /** Number of current silence samples in a (consecutive) row. */
100 uint64_t csSilence;
101 /** Number of silent samples in a row to consider an audio block as audio gap (silence). */
102 uint64_t cSilenceThreshold;
103 /** How many bytes to skip in an audio stream before detecting silence.
104 * (useful for intros and silence at the beginning of a song). */
105 uint64_t cbSilenceReadMin;
106#endif
107 /** Runtime debug info. */
108 HDASTREAMDBGINFORT Runtime;
109} HDASTREAMDBGINFO ,*PHDASTREAMDBGINFO;
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);
187typedef HDASTREAMSTATE *PHDASTREAMSTATE;
188
189/**
190 * An HDA stream (SDI / SDO).
191 *
192 * @note This HDA stream has nothing to do with a regular audio stream handled
193 * by the audio connector or the audio mixer. This HDA stream is a serial
194 * data in/out stream (SDI/SDO) defined in hardware and can contain
195 * multiple audio streams in one single SDI/SDO (interleaving streams).
196 *
197 * How a specific SDI/SDO is mapped to our internal audio streams relies on the
198 * stream channel mappings.
199 *
200 * Contains only register values which do *not* change until a stream reset
201 * occurs.
202 */
203typedef struct HDASTREAM
204{
205 /** Stream descriptor number (SDn). */
206 uint8_t u8SD;
207 /** Current channel index.
208 * For a stereo stream, this is u8Channel + 1. */
209 uint8_t u8Channel;
210 uint8_t Padding0[6];
211 /** DMA base address (SDnBDPU - SDnBDPL).
212 * Will be updated in hdaR3StreamInit(). */
213 uint64_t u64BDLBase;
214 /** Cyclic Buffer Length (SDnCBL).
215 * Represents the size of the ring buffer.
216 * Will be updated in hdaR3StreamInit(). */
217 uint32_t u32CBL;
218 /** Format (SDnFMT).
219 * Will be updated in hdaR3StreamInit(). */
220 uint16_t u16FMT;
221 /** FIFO Size (FIFOS).
222 * Maximum number of bytes that may have been DMA'd into
223 * memory but not yet transmitted on the link.
224 *
225 * Will be updated in hdaR3StreamInit(). */
226 uint16_t u16FIFOS;
227 /** FIFO Watermark. */
228 uint16_t u16FIFOW;
229 /** Last Valid Index (SDnLVI).
230 * Will be updated in hdaR3StreamInit(). */
231 uint16_t u16LVI;
232 uint16_t Padding1[2];
233 /** Pointer to the HDA state this stream is attached to. */
234 R3PTRTYPE(PHDASTATE) pHDAState;
235 /** Pointer to HDA sink this stream is attached to. */
236 R3PTRTYPE(PHDAMIXERSINK) pMixSink;
237 /** The timer for pumping data thru the attached LUN drivers. */
238 TMTIMERHANDLE hTimer;
239 /** The stream'S critical section to serialize access. */
240 RTCRITSECT CritSect;
241 /** Internal state of this stream. */
242 HDASTREAMSTATE State;
243 /** Debug information. */
244 HDASTREAMDBGINFO Dbg;
245} HDASTREAM;
246/** Pointer to an HDA stream (SDI / SDO). */
247typedef HDASTREAM *PHDASTREAM;
248
249#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
250/**
251 * HDA stream thread context (arguments).
252 */
253typedef struct HDASTREAMTHREADCTX
254{
255 PHDASTATE pThis;
256 PHDASTREAM pStream;
257} HDASTREAMTHREADCTX, *PHDASTREAMTHREADCTX;
258#endif
259
260#ifdef IN_RING3
261
262/** @name Stream functions.
263 * @{
264 */
265int hdaR3StreamCreate(PHDASTREAM pStream, PHDASTATE pThis, uint8_t u8SD);
266void hdaR3StreamDestroy(PHDASTREAM pStream);
267int hdaR3StreamInit(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint8_t uSD);
268void hdaR3StreamReset(PHDASTATE pThis, PHDASTREAM pStream, uint8_t uSD);
269int hdaR3StreamEnable(PHDASTREAM pStream, bool fEnable);
270uint32_t hdaR3StreamGetPosition(PHDASTATE pThis, PHDASTREAM pStream);
271void hdaR3StreamSetPosition(PHDASTREAM pStream, uint32_t u32LPIB);
272uint32_t hdaR3StreamGetFree(PHDASTREAM pStream);
273uint32_t hdaR3StreamGetUsed(PHDASTREAM pStream);
274bool hdaR3StreamTransferIsScheduled(PHDASTREAM pStream, uint64_t tsNow);
275uint64_t hdaR3StreamTransferGetNext(PHDASTREAM pStream);
276void hdaR3StreamLock(PHDASTREAM pStream);
277void hdaR3StreamUnlock(PHDASTREAM pStream);
278int hdaR3StreamRead(PHDASTREAM pStream, uint32_t cbToRead, uint32_t *pcbRead);
279int hdaR3StreamWrite(PHDASTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
280void hdaR3StreamUpdate(PPDMDEVINS pDevIns, PHDASTREAM pStream, bool fAsync);
281# ifdef HDA_USE_DMA_ACCESS_HANDLER
282bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
283void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
284# endif /* HDA_USE_DMA_ACCESS_HANDLER */
285/** @} */
286
287/** @name Timer functions.
288 * @{
289 */
290DECLCALLBACK(void) hdaR3StreamTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
291/** @} */
292
293
294/** @name Async I/O stream functions.
295 * @{
296 */
297# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
298DECLCALLBACK(int) hdaR3StreamAsyncIOThread(RTTHREAD hThreadSelf, void *pvUser);
299int hdaR3StreamAsyncIOCreate(PHDASTREAM pStream);
300int hdaR3StreamAsyncIODestroy(PHDASTREAM pStream);
301int hdaR3StreamAsyncIONotify(PHDASTREAM pStream);
302void hdaR3StreamAsyncIOLock(PHDASTREAM pStream);
303void hdaR3StreamAsyncIOUnlock(PHDASTREAM pStream);
304void hdaR3StreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable);
305# endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */
306/** @} */
307
308#endif /* IN_RING3 */
309#endif /* !VBOX_INCLUDED_SRC_Audio_HDAStream_h */
310
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