ReactOS 0.4.15-dev-7924-g5949c20
stream2.cpp
Go to the documentation of this file.
1// Every debug output has "Modulname text"
2#define STR_MODULENAME "AC97 Stream2: "
3
4#include "shared.h"
5#include "miniport.h"
6
7#ifdef _MSC_VER
8#pragma code_seg("PAGE")
9#endif
10
12{
13 // get DMA_ADAPTER object
14 PDMA_ADAPTER AdapterObject = (PDMA_ADAPTER)
15 Miniport->DmaChannel->GetAdapterObject();
16
17 // allocate DBList
18 BDList = (tBDEntry *)AdapterObject->DmaOperations->
19 AllocateCommonBuffer (AdapterObject,
20 MAX_BDL_ENTRIES * sizeof (tBDEntry),
22 return BDList;
23}
24
26{
27 if (BDList)
28 {
29 // get DMA_ADAPTER object
30 PDMA_ADAPTER AdapterObject = (PDMA_ADAPTER)
31 Miniport->DmaChannel->GetAdapterObject();
32
33 // free DBList
34 AdapterObject->DmaOperations->
35 FreeCommonBuffer (AdapterObject,
39 FALSE);
40 BDList = NULL;
41 }
42}
43
44/*****************************************************************************
45 * CMiniportStream::PowerChangeNotify
46 *****************************************************************************
47 * This functions saves and maintains the stream state through power changes.
48 */
49
51(
52 IN POWER_STATE NewState
53)
54{
55 if(NewState.DeviceState == PowerDeviceD0)
56 {
57 //
58 // The scatter gather list is already arranged. A reset of the DMA
59 // brings all pointers to the default state. From there we can start.
60 //
61
62 ResetDMA ();
63 }
64 else
65 {
66 // Disable interrupts and stop DMA just in case.
67 Miniport->AdapterCommon->WriteBMControlRegister (m_ulBDAddr + X_CR, (UCHAR)0);
68 }
69}
70
71
72/*****************************************************************************
73 * CMiniportStream::SetState
74 *****************************************************************************
75 * This routine sets/changes the DMA engine state to play, stop, or pause
76 */
78(
80)
81{
82 DOUT (DBG_PRINT, ("[CMiniportStream::SetState]"));
83 DOUT (DBG_STREAM, ("SetState to %d", State));
84
85
86 //
87 // Start or stop the DMA engine dependent of the state.
88 //
89 switch (State)
90 {
91 case KSSTATE_STOP:
92 // We reset the DMA engine which will also reset the position pointers.
93 ResetDMA ();
94 break;
95
96 case KSSTATE_ACQUIRE:
97 break;
98
99 case KSSTATE_PAUSE:
100 // pause now.
101 PauseDMA ();
102 break;
103
104 case KSSTATE_RUN:
105 //
106 // Let's rock.
107 //
108 // Make sure we are not running already.
110 {
111 return STATUS_SUCCESS;
112 }
113
114 // Kick DMA again just in case.
115 ResumeDMA ();
117 break;
118 }
119
120 return STATUS_SUCCESS;
121}
122
123/*****************************************************************************
124 * Non paged code begins here
125 *****************************************************************************
126 */
127
128#ifdef _MSC_VER
129#pragma code_seg()
130#endif
131
132/*****************************************************************************
133 * CMiniportStream::NormalizePhysicalPosition
134 *****************************************************************************
135 * Given a physical position based on the actual number of bytes transferred,
136 * this function converts the position to a time-based value of 100ns units.
137 */
139(
140 _Inout_ PLONGLONG PhysicalPosition
141)
142{
143 ULONG SampleSize;
144
145 DOUT (DBG_PRINT, ("NormalizePhysicalPosition"));
146
147 //
148 // Determine the sample size in bytes
149 //
150 SampleSize = DataFormat->WaveFormatEx.nChannels * 2;
151
152 //
153 // Calculate the time in 100ns steps.
154 //
155 *PhysicalPosition = (_100NS_UNITS_PER_SECOND / SampleSize *
156 *PhysicalPosition) / CurrentRate;
157
158 return STATUS_SUCCESS;
159}
LONG NTSTATUS
Definition: precomp.h:26
tBDEntry * BDList
Definition: stream.h:61
PVOID BDList_Alloc()
Definition: stream2.cpp:11
void ResumeDMA(ULONG state=DMA_ENGINE_ON)
Definition: stream.cpp:599
ULONG CurrentRate
Definition: stream.h:56
void BDList_Free()
Definition: stream2.cpp:25
CMiniport * Miniport
Definition: stream.h:42
void ResetDMA(void)
Definition: stream.cpp:544
NTSTATUS NormalizePhysicalPosition(_Inout_ PLONGLONG PhysicalPosition)
Definition: stream2.cpp:139
void UpdateLviCyclic()
Definition: stream.h:172
virtual void PowerChangeNotify_(IN POWER_STATE NewState)
Definition: stream2.cpp:51
void PauseDMA(void)
Definition: stream.cpp:614
NTSTATUS SetState(_In_ KSSTATE State)
Definition: stream2.cpp:78
ULONG DMAEngineState
Definition: stream.h:57
PHYSICAL_ADDRESS BDList_PhysAddr
Definition: stream.h:60
ULONG m_ulBDAddr
Definition: stream.h:58
PADAPTERCOMMON AdapterCommon
Definition: miniport.h:31
PDMACHANNEL DmaChannel
Definition: miniport.h:33
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
const int DBG_STREAM
Definition: debug.h:22
#define DOUT(lvl, strings)
Definition: debug.h:82
const int MAX_BDL_ENTRIES
Definition: stream.h:16
const int DMA_ENGINE_ON
Definition: stream.h:7
#define PAGE_SIZE
Definition: env_spec_w32.h:49
const ULONG X_CR
Definition: ichreg.h:56
KSSTATE
Definition: ks.h:1214
@ KSSTATE_ACQUIRE
Definition: ks.h:1216
@ KSSTATE_PAUSE
Definition: ks.h:1217
@ KSSTATE_RUN
Definition: ks.h:1218
@ KSSTATE_STOP
Definition: ks.h:1215
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
@ PowerDeviceD0
Definition: ntpoapi.h:49
#define _100NS_UNITS_PER_SECOND
Definition: portcls.h:159
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define DBG_PRINT(ppi, ch, level)
Definition: win32kdebug.h:168
struct _DMA_ADAPTER * PDMA_ADAPTER
unsigned char UCHAR
Definition: xmlstorage.h:181