ReactOS 0.4.15-dev-5666-gc548b97
driver.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/legacy/stream/driver.c
5 * PURPOSE: WDM Codec Class Driver
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9#include "stream.h"
10
16{
17 PSTREAM_CLASS_DRIVER_EXTENSION DriverObjectExtension;
19 PSTREAM_DEVICE_EXTENSION DeviceExtension;
20 PKSOBJECT_CREATE_ITEM ItemList;
22
23 /* Fetch driver object extension */
25 if (!DriverObjectExtension)
26 {
27 /* Failed to get driver extension */
29 }
30 /* Allocate Create Item */
31 ItemList = ExAllocatePool(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
32 if (!ItemList)
33 {
34 /* Failed to allocated Create Item */
36 }
37
38 /* Create the FDO */
40 if (!NT_SUCCESS(Status))
41 {
42 /* Failed to create the FDO */
43 ExFreePool(ItemList);
44 return Status;
45 }
46
47 /* Attach to device stack */
50 {
51 /* Failed to attach */
53 ExFreePool(ItemList);
55 }
56
57 /* Zero Create item */
58 RtlZeroMemory(ItemList, sizeof(KSOBJECT_CREATE_ITEM));
59 /* Setup object class */
60 RtlInitUnicodeString(&ItemList->ObjectClass, L"GLOBAL");
61 /* Setup CreateDispatch routine */
62 ItemList->Create = StreamClassCreateFilter;
63
64 /* Get device extension */
66 /* Zero device extension */
67 RtlZeroMemory(DeviceExtension, sizeof(STREAM_DEVICE_EXTENSION));
68 /* Initialize Ks streaming */
69 Status = KsAllocateDeviceHeader(&DeviceExtension->Header, 1, ItemList);
70 if (!NT_SUCCESS(Status))
71 {
72 /* Cleanup resources */
75 ExFreePool(ItemList);
76 return Status;
77 }
78
79 /* Store lower device object */
80 DeviceExtension->LowerDeviceObject = LowerDeviceObject;
81
82 /* Store physical device object */
84 /* Store driver object extension */
85 DeviceExtension->DriverExtension = DriverObjectExtension;
86 /* Initialize memory list */
87 InitializeListHead(&DeviceExtension->MemoryResourceList);
88 /* Setup device extension */
89 DeviceExtension->DeviceExtension = (PVOID) (DeviceExtension + 1);
90 /* Init interrupt dpc */
91 KeInitializeDpc(&DeviceExtension->InterruptDpc, StreamClassInterruptDpc, (PVOID)DeviceExtension);
92
93 /* Set device transfer method */
95 /* Clear init flag */
96 DeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
97
98 return Status;
99}
100
101/*
102 *@implemented
103 */
110{
112 PSTREAM_CLASS_DRIVER_EXTENSION DriverObjectExtension;
114
115 /* Allocate driver extension */
117 if (!NT_SUCCESS(Status))
118 {
119 /* Failed to allocate */
121 }
122
123 /* Zero driver object extension */
124 RtlZeroMemory(DriverObjectExtension, sizeof(STREAM_CLASS_DRIVER_EXTENSION));
125
126 /* copy HwInitializationData */
127 RtlCopyMemory(&DriverObjectExtension->Data, HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
128
129 /* Setup device init methods */
130 DriverObject->DriverExtension->AddDevice = StreamClassAddDevice;
131 DriverObject->DriverUnload = KsNullDriverUnload;
132
133 /* Setup irp handlers */
134 DriverObject->MajorFunction[IRP_MJ_PNP] = StreamClassPnp;
140
141 /* Let Ks handle these */
144
145 return STATUS_SUCCESS;
146}
147
148/*
149 *@implemented
150 */
151
152VOID
153NTAPI
155 IN PVOID HwDeviceExtension,
156 IN ULONG StreamDescriptorSize)
157{
158 HW_STREAM_REQUEST_BLOCK_EXT RequestBlock;
159 PSTREAM_DEVICE_EXTENSION DeviceExtension;
160 PHW_STREAM_DESCRIPTOR StreamDescriptor;
161
162 if (!HwDeviceExtension || !StreamDescriptorSize)
163 return;
164
165 StreamDescriptor = ExAllocatePool(NonPagedPool, StreamDescriptorSize);
166 if (!StreamDescriptor)
167 return;
168
169 /* Zero stream descriptor */
170 RtlZeroMemory(StreamDescriptor, StreamDescriptorSize);
171
172 /* Get our DeviceExtension */
173 DeviceExtension = (PSTREAM_DEVICE_EXTENSION) ((ULONG_PTR)HwDeviceExtension - sizeof(STREAM_DEVICE_EXTENSION));
174 ASSERT(DeviceExtension->DeviceExtension == HwDeviceExtension);
175
176
177 /* Zero RequestBlock */
178 RtlZeroMemory(&RequestBlock, sizeof(HW_STREAM_REQUEST_BLOCK_EXT));
179
180 /* Setup get stream info struct */
181 RequestBlock.Block.SizeOfThisPacket = sizeof(HW_STREAM_REQUEST_BLOCK);
182 RequestBlock.Block.Command = SRB_GET_STREAM_INFO;
183 RequestBlock.Block.CommandData.StreamBuffer = StreamDescriptor;
185
186 /* FIXME SYNCHRONIZATION */
187
188 /* Send the request */
189 DeviceExtension->DriverExtension->Data.HwReceivePacket ((PHW_STREAM_REQUEST_BLOCK)&RequestBlock);
190
191 /* Is the device already completed? */
192 if (RequestBlock.Block.Status == STATUS_PENDING)
193 {
194 /* Request is pending, wait for result */
196 }
197
198 if (!NT_SUCCESS(RequestBlock.Block.Status))
199 {
200 /* Release Stream descriptor */
201 ExFreePool(StreamDescriptor);
202 }
203 else
204 {
205 if (DeviceExtension->StreamDescriptor)
206 {
207 /* Release old stream descriptor */
208 ExFreePool(DeviceExtension->StreamDescriptor);
209 }
210
211 /* Store stream descriptor */
212 DeviceExtension->StreamDescriptor = StreamDescriptor;
213 DeviceExtension->StreamDescriptorSize = StreamDescriptorSize;
214 }
215
216}
217
218/*
219 *@implemented
220 */
221
222VOID
223NTAPI
225 IN PCHAR File,
226 IN ULONG Line,
227 IN PCHAR AssertText,
228 IN ULONG AssertValue)
229{
230#if DBG
232#endif
233}
234
235/*
236 *@implemented
237 */
238VOID
241 IN STREAM_DEBUG_LEVEL DebugPrintLevel,
242 IN PCCHAR DebugMessage,
243 ...)
244{
245#if DBG
246 va_list ap;
247
248 if (DebugPrintLevel <=STREAMDEBUG_LEVEL)
249 {
250 va_start(ap, DebugMessage);
251
252 DbgPrint(DebugMessage, ap);
253
254 va_end(ap);
255 }
256#endif
257
258}
259
260/*
261 *@unimplemented
262 */
263VOID
267 IN PVOID HwDeviceExtension,
269 IN PKSEVENT_ENTRY EventEntry,
270 IN GUID *EventSet,
271 IN ULONG EventId)
272{
273 PHW_STREAM_REQUEST_BLOCK_EXT RequestBlock;
275 {
276 RequestBlock = (PHW_STREAM_REQUEST_BLOCK_EXT)pSrb;
277
278 KeSetEvent(&RequestBlock->Event, 0, FALSE);
279 return;
280 }
281
283}
284
285/*
286 *@implemented
287 */
288PVOID
291 IN PVOID HwDeviceExtension)
292{
293 PSTREAM_DEVICE_EXTENSION DeviceExtension;
294
295 /* Get our DeviceExtension */
296 DeviceExtension = (PSTREAM_DEVICE_EXTENSION) ((ULONG_PTR)HwDeviceExtension - sizeof(STREAM_DEVICE_EXTENSION));
297 ASSERT(DeviceExtension->DeviceExtension == HwDeviceExtension);
298
299 return DeviceExtension->DmaCommonBuffer;
300}
301
303NTAPI
306 IN PIRP Irp,
308{
310
311 IoStatusBlock->Information = Irp->IoStatus.Information;
312 IoStatusBlock->Status = Irp->IoStatus.Status;
313
314 return STATUS_SUCCESS;
315}
316
317/*
318 *@implemented
319 */
323 IN PVOID HwDeviceExtension,
326 IN ULONG OffSet,
328{
329 PIRP Irp;
332 PSTREAM_DEVICE_EXTENSION DeviceExtension;
334 IO_STATUS_BLOCK StatusBlock;
336
337 /* Get our DeviceExtension */
338 DeviceExtension = (PSTREAM_DEVICE_EXTENSION) ((ULONG_PTR)HwDeviceExtension - sizeof(STREAM_DEVICE_EXTENSION));
339 ASSERT(DeviceExtension->DeviceExtension == HwDeviceExtension);
340
341 if (Read)
342 {
343 /* Zero input buffer */
345 }
346
347 /* Set request type */
349
350 /* Initialize event */
352
353 /* Set offset */
354 Offset.QuadPart = OffSet;
355
356 /* Pre-init status block */
357 StatusBlock.Status = STATUS_NOT_SUPPORTED;
358
359 /* Create Irp */
361 DeviceExtension->LowerDeviceObject, /* Verify */
362 Buffer,
363 Length,
364 &Offset,
365 &Event,
366 &StatusBlock);
367
368 if (!Irp)
369 {
370 /* Failed to allocate memory */
371 return FALSE;
372 }
373
374 /* Setup a completion routine */
376
377 /* Call driver */
378 Status = IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
379
380 if (Status == STATUS_PENDING)
381 {
382 /* Request is pending, wait for result */
384 /* Fetch result */
385 Status = StatusBlock.Status;
386 }
387
388 if (!NT_SUCCESS(Status))
389 {
390 return FALSE;
391 }
392
393 /* FIXME Handle Length != InputLength */
394 return TRUE;
395}
unsigned char BOOLEAN
#define __cdecl
Definition: accygwin.h:79
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
LONG NTSTATUS
Definition: precomp.h:26
#define UNIMPLEMENTED
Definition: debug.h:115
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
Definition: bufpool.h:45
Definition: File.h:16
_In_z_ PCCHAR _In_ PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:983
_In_ PVOID Argument2
Definition: classpnp.h:721
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
KSDDKAPI NTSTATUS NTAPI KsAllocateDeviceHeader(OUT KSDEVICE_HEADER *OutHeader, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL)
Definition: api.c:522
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler(IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
Definition: irp.c:2029
KSDDKAPI VOID NTAPI KsNullDriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: irp.c:1157
NTSTATUS NTAPI StreamClassSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: control.c:27
NTSTATUS NTAPI StreamClassCleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: control.c:39
NTSTATUS NTAPI StreamClassFlushBuffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: control.c:51
NTSTATUS NTAPI StreamClassDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: control.c:63
NTSTATUS NTAPI StreamClassPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: control.c:15
NTSTATUS NTAPI StreamClassAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: driver.c:13
PVOID STREAMAPI StreamClassGetDmaBuffer(IN PVOID HwDeviceExtension)
Definition: driver.c:290
NTSTATUS STREAMAPI StreamClassRegisterAdapter(IN PVOID Argument1, IN PVOID Argument2, IN PHW_INITIALIZATION_DATA HwInitializationData)
Definition: driver.c:106
BOOLEAN STREAMAPI StreamClassReadWriteConfig(IN PVOID HwDeviceExtension, IN BOOLEAN Read, IN PVOID Buffer, IN ULONG OffSet, IN ULONG Length)
Definition: driver.c:322
VOID NTAPI StreamClassDebugAssert(IN PCHAR File, IN ULONG Line, IN PCHAR AssertText, IN ULONG AssertValue)
Definition: driver.c:224
VOID __cdecl StreamClassDebugPrint(IN STREAM_DEBUG_LEVEL DebugPrintLevel, IN PCCHAR DebugMessage,...)
Definition: driver.c:240
VOID NTAPI StreamClassReenumerateStreams(IN PVOID HwDeviceExtension, IN ULONG StreamDescriptorSize)
Definition: driver.c:154
NTSTATUS NTAPI StreamClassRWCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: driver.c:304
VOID __cdecl StreamClassDeviceNotification(IN STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE NotificationType, IN PVOID HwDeviceExtension, IN PHW_STREAM_REQUEST_BLOCK pSrb, IN PKSEVENT_ENTRY EventEntry, IN GUID *EventSet, IN ULONG EventId)
Definition: driver.c:265
NTSTATUS NTAPI StreamClassCreateFilter(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:261
NTSTATUS NTAPI StreamClassPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pnp.c:456
VOID NTAPI StreamClassInterruptDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: pnp.c:74
#define STREAMDEBUG_LEVEL
Definition: stream.h:7
struct HW_STREAM_REQUEST_BLOCK_EXT * PHW_STREAM_REQUEST_BLOCK_EXT
struct STREAM_DEVICE_EXTENSION * PSTREAM_DEVICE_EXTENSION
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
struct _IO_STATUS_BLOCK * PIO_STATUS_BLOCK
Definition: change.c:34
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
struct _KSEVENT_ENTRY * PKSEVENT_ENTRY
Definition: ks.h:2101
signed char * PCHAR
Definition: retypes.h:7
void * PVOID
Definition: retypes.h:9
unsigned int ULONG
Definition: retypes.h:1
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define KernelMode
Definition: asm.h:34
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ NotificationEvent
@ SynchronizationEvent
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1889
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1811
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_KS
Definition: winioctl.h:153
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA * HwInitializationData
Definition: srb.h:897
Console I/O streams.
#define STATUS_SUCCESS
Definition: shellext.h:65
@ SRB_GET_STREAM_INFO
Definition: strmini.h:191
#define STREAMAPI
Definition: strmini.h:8
enum _STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE
@ DeviceRequestComplete
Definition: strmini.h:330
struct _HW_STREAM_REQUEST_BLOCK HW_STREAM_REQUEST_BLOCK
STREAM_DEBUG_LEVEL
Definition: strmini.h:11
_In_ BOOLEAN Read
Definition: strmini.h:479
HW_STREAM_REQUEST_BLOCK Block
Definition: stream.h:53
Definition: ncftp.h:79
HW_INITIALIZATION_DATA Data
Definition: stream.h:13
PSTREAM_CLASS_DRIVER_EXTENSION DriverExtension
Definition: stream.h:44
KSDEVICE_HEADER Header
Definition: stream.h:26
PHW_STREAM_DESCRIPTOR StreamDescriptor
Definition: stream.h:43
PDEVICE_OBJECT PhysicalDeviceObject
Definition: stream.h:28
ULONG StreamDescriptorSize
Definition: stream.h:42
PDEVICE_OBJECT LowerDeviceObject
Definition: stream.h:27
LIST_ENTRY MemoryResourceList
Definition: stream.h:40
PHW_RECEIVE_DEVICE_SRB HwReceivePacket
Definition: strmini.h:356
ULONG DeviceExtensionSize
Definition: srb.h:574
SRB_COMMAND Command
Definition: strmini.h:224
union _HW_STREAM_REQUEST_BLOCK::_CommandData CommandData
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PHW_STREAM_DESCRIPTOR StreamBuffer
Definition: strmini.h:232
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDF_SPECIAL_FILE_TYPE NotificationType
Definition: wdfdevice.h:1024
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:696
struct _DRIVER_OBJECT * PDRIVER_OBJECT
#define DO_POWER_PAGABLE
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_FLUSH_BUFFERS
#define IRP_MJ_POWER
#define IRP_MJ_CLEANUP
@ Executive
Definition: ketypes.h:403