-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasedma.cpp
More file actions
405 lines (302 loc) · 9.26 KB
/
basedma.cpp
File metadata and controls
405 lines (302 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*++
Copyright (c) 1997-2000 Microsoft Corporation All Rights Reserved
Module Name:
basedma.cpp
Abstract:
IDmaChannel implementation. Does nothing HW related.
--*/
#pragma warning (disable : 4127)
#include <msvad.h>
#include "common.h"
#include "basewave.h"
#pragma code_seg("PAGE")
//=============================================================================
_Use_decl_annotations_
STDMETHODIMP_(NTSTATUS)
CMiniportWaveCyclicStreamMSVAD::AllocateBuffer
(
ULONG BufferSize,
PPHYSICAL_ADDRESS PhysicalAddressConstraint OPTIONAL
)
/*++
Routine Description:
The AllocateBuffer function allocates a buffer associated with the DMA object.
The buffer is nonPaged.
Callers of AllocateBuffer should run at a passive IRQL.
Arguments:
BufferSize - Size in bytes of the buffer to be allocated.
PhysicalAddressConstraint - Optional constraint to place on the physical
address of the buffer. If supplied, only the bits
that are set in the constraint address may vary
from the beginning to the end of the buffer.
For example, if the desired buffer should not
cross a 64k boundary, the physical address
constraint 0x000000000000ffff should be specified
Return Value:
NT status code.
--*/
{
UNREFERENCED_PARAMETER(PhysicalAddressConstraint);
PAGED_CODE();
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::AllocateBuffer]"));
NTSTATUS ntStatus = STATUS_SUCCESS;
//
// Adjust this cap as needed...
ASSERT (BufferSize <= DMA_BUFFER_SIZE);
m_pvDmaBuffer = (PVOID)
ExAllocatePoolWithTag
(
NonPagedPool,
BufferSize,
MSVAD_POOLTAG
);
if (!m_pvDmaBuffer)
{
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
m_ulDmaBufferSize = BufferSize;
}
return ntStatus;
} // AllocateBuffer
#pragma code_seg()
//=============================================================================
STDMETHODIMP_(ULONG)
CMiniportWaveCyclicStreamMSVAD::AllocatedBufferSize
(
void
)
/*++
Routine Description:
AllocatedBufferSize returns the size of the allocated buffer.
Callers of AllocatedBufferSize can run at any IRQL.
Arguments:
Return Value:
ULONG
--*/
{
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::AllocatedBufferSize]"));
return m_ulDmaBufferSize;
} // AllocatedBufferSize
//=============================================================================
STDMETHODIMP_(ULONG)
CMiniportWaveCyclicStreamMSVAD::BufferSize
(
void
)
/*++
Routine Description:
BufferSize returns the size set by SetBufferSize or the allocated buffer size
if the buffer size has not been set. The DMA object does not actually use
this value internally. This value is maintained by the object to allow its
various clients to communicate the intended size of the buffer. This call
is often used to obtain the map size parameter to the Start member
function. Callers of BufferSize can run at any IRQL
Arguments:
Return Value:
ULONG
--*/
{
return m_ulDmaBufferSize;
} // BufferSize
//=============================================================================
/*
_Use_decl_annotations_
STDMETHODIMP_(void)
CMiniportWaveCyclicStreamMSVAD::CopyFrom
(
PVOID Destination,
PVOID Source,
ULONG ByteCount
)
{
//
// This is already implemented in basewave.cpp which handles the loopback logic.
// If we keep this definition here, we get a linker error (multiply defined symbol).
// So we just forward to the base implementation or remove it if the class definition
// expects it to be here.
//
// However, since we implemented CopyFrom/CopyTo in basewave.cpp to add loopback support,
// we should REMOVE the implementation from here to avoid the conflict.
//
// Since I cannot "delete" this block easily without potentially confusing the patcher,
// I will comment it out or ifdef it out.
//
UNREFERENCED_PARAMETER(Destination);
UNREFERENCED_PARAMETER(Source);
UNREFERENCED_PARAMETER(ByteCount);
}
*/
//=============================================================================
/*
_Use_decl_annotations_
STDMETHODIMP_(void)
CMiniportWaveCyclicStreamMSVAD::CopyTo
(
PVOID Destination,
PVOID Source,
ULONG ByteCount
)
{
//
// This is already implemented in basewave.cpp which handles the loopback logic.
// We remove the implementation here to avoid linker errors.
//
UNREFERENCED_PARAMETER(Destination);
UNREFERENCED_PARAMETER(Source);
UNREFERENCED_PARAMETER(ByteCount);
}
*/
//=============================================================================
#pragma code_seg("PAGE")
STDMETHODIMP_(void)
CMiniportWaveCyclicStreamMSVAD::FreeBuffer
(
void
)
/*++
Routine Description:
The FreeBuffer function frees the buffer allocated by AllocateBuffer. Because
the buffer is automatically freed when the DMA object is deleted, this
function is not normally used. Callers of FreeBuffer should run at
IRQL PASSIVE_LEVEL.
Arguments:
Return Value:
void
--*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::FreeBuffer]"));
if ( m_pvDmaBuffer )
{
ExFreePoolWithTag( m_pvDmaBuffer, MSVAD_POOLTAG );
m_ulDmaBufferSize = 0;
}
} // FreeBuffer
#pragma code_seg()
//=============================================================================
STDMETHODIMP_(PADAPTER_OBJECT)
CMiniportWaveCyclicStreamMSVAD::GetAdapterObject
(
void
)
/*++
Routine Description:
The GetAdapterObject function returns the DMA object's internal adapter
object. Callers of GetAdapterObject can run at any IRQL.
Arguments:
Return Value:
PADAPTER_OBJECT - The return value is the object's internal adapter object.
--*/
{
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::GetAdapterObject]"));
// MSVAD does not have need a physical DMA channel. Therefore it
// does not have physical DMA structure.
return NULL;
} // GetAdapterObject
//=============================================================================
STDMETHODIMP_(ULONG)
CMiniportWaveCyclicStreamMSVAD::MaximumBufferSize
(
void
)
/*++
Routine Description:
Arguments:
Return Value:
NT status code.
--*/
{
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::MaximumBufferSize]"));
return m_pMiniport->m_MaxDmaBufferSize;
} // MaximumBufferSize
//=============================================================================
STDMETHODIMP_(PHYSICAL_ADDRESS)
CMiniportWaveCyclicStreamMSVAD::PhysicalAddress
(
void
)
/*++
Routine Description:
MaximumBufferSize returns the size in bytes of the largest buffer this DMA
object is configured to support. Callers of MaximumBufferSize can run
at any IRQL
Arguments:
Return Value:
PHYSICAL_ADDRESS - The return value is the size in bytes of the largest
buffer this DMA object is configured to support.
--*/
{
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::PhysicalAddress]"));
PHYSICAL_ADDRESS pAddress;
pAddress.QuadPart = (LONGLONG) m_pvDmaBuffer;
return pAddress;
} // PhysicalAddress
//=============================================================================
STDMETHODIMP_(void)
CMiniportWaveCyclicStreamMSVAD::SetBufferSize
(
_In_ ULONG BufferSize
)
/*++
Routine Description:
The SetBufferSize function sets the current buffer size. This value is set to
the allocated buffer size when AllocateBuffer is called. The DMA object does
not actually use this value internally. This value is maintained by the object
to allow its various clients to communicate the intended size of the buffer.
Callers of SetBufferSize can run at any IRQL.
Arguments:
BufferSize - Current size in bytes.
Return Value:
void
--*/
{
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::SetBufferSize]"));
if ( BufferSize <= m_ulDmaBufferSize )
{
m_ulDmaBufferSize = BufferSize;
}
else
{
DPF(D_ERROR, ("Tried to enlarge dma buffer size"));
}
} // SetBufferSize
//=============================================================================
STDMETHODIMP_(PVOID)
CMiniportWaveCyclicStreamMSVAD::SystemAddress
(
void
)
/*++
Routine Description:
The SystemAddress function returns the virtual system address of the
allocated buffer. Callers of SystemAddress can run at any IRQL.
Arguments:
Return Value:
PVOID - The return value is the virtual system address of the
allocated buffer.
--*/
{
return m_pvDmaBuffer;
} // SystemAddress
//=============================================================================
STDMETHODIMP_(ULONG)
CMiniportWaveCyclicStreamMSVAD::TransferCount
(
void
)
/*++
Routine Description:
The TransferCount function returns the size in bytes of the buffer currently
being transferred by a DMA object. Callers of TransferCount can run
at any IRQL.
Arguments:
Return Value:
ULONG - The return value is the size in bytes of the buffer currently
being transferred.
--*/
{
DPF_ENTER(("[CMiniportWaveCyclicStreamMSVAD::TransferCount]"));
return m_ulDmaBufferSize;
}