ReactOS 0.4.16-dev-297-gc569aee
driver.c File Reference
#include "stream.h"
Include dependency graph for driver.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI StreamClassAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
 
NTSTATUS STREAMAPI StreamClassRegisterAdapter (IN PVOID Argument1, IN PVOID Argument2, IN PHW_INITIALIZATION_DATA HwInitializationData)
 
VOID NTAPI StreamClassReenumerateStreams (IN PVOID HwDeviceExtension, IN ULONG StreamDescriptorSize)
 
VOID NTAPI StreamClassDebugAssert (IN PCHAR File, IN ULONG Line, IN PCHAR AssertText, IN ULONG AssertValue)
 
VOID __cdecl StreamClassDebugPrint (IN STREAM_DEBUG_LEVEL DebugPrintLevel, IN PCCHAR DebugMessage,...)
 
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)
 
PVOID STREAMAPI StreamClassGetDmaBuffer (IN PVOID HwDeviceExtension)
 
NTSTATUS NTAPI StreamClassRWCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
BOOLEAN STREAMAPI StreamClassReadWriteConfig (IN PVOID HwDeviceExtension, IN BOOLEAN Read, IN PVOID Buffer, IN ULONG OffSet, IN ULONG Length)
 

Function Documentation

◆ StreamClassAddDevice()

NTSTATUS NTAPI StreamClassAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 13 of file driver.c.

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}
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
_In_z_ PCCHAR _In_ PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:983
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
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
NTSTATUS NTAPI StreamClassAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: driver.c:13
NTSTATUS NTAPI StreamClassCreateFilter(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: filter.c:261
VOID NTAPI StreamClassInterruptDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: pnp.c:74
struct STREAM_DEVICE_EXTENSION * PSTREAM_DEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#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 FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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:1904
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_KS
Definition: winioctl.h:92
HW_INITIALIZATION_DATA Data
Definition: stream.h:14
PSTREAM_CLASS_DRIVER_EXTENSION DriverExtension
Definition: stream.h:45
KSDEVICE_HEADER Header
Definition: stream.h:27
PDEVICE_OBJECT PhysicalDeviceObject
Definition: stream.h:29
PDEVICE_OBJECT LowerDeviceObject
Definition: stream.h:28
LIST_ENTRY MemoryResourceList
Definition: stream.h:41
ULONG DeviceExtensionSize
Definition: srb.h:574
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define DO_POWER_PAGABLE

Referenced by StreamClassAddDevice(), StreamClassRegisterAdapter(), and StreamClassStartDevice().

◆ StreamClassDebugAssert()

VOID NTAPI StreamClassDebugAssert ( IN PCHAR  File,
IN ULONG  Line,
IN PCHAR  AssertText,
IN ULONG  AssertValue 
)

Definition at line 224 of file driver.c.

229{
230#if DBG
232#endif
233}
NTSYSAPI void WINAPI DbgBreakPoint(void)

◆ StreamClassDebugPrint()

VOID __cdecl StreamClassDebugPrint ( IN STREAM_DEBUG_LEVEL  DebugPrintLevel,
IN PCCHAR  DebugMessage,
  ... 
)

Definition at line 240 of file driver.c.

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}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define STREAMDEBUG_LEVEL
Definition: stream.h:8
#define DbgPrint
Definition: hal.h:12
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

◆ StreamClassDeviceNotification()

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 at line 265 of file driver.c.

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}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define FALSE
Definition: types.h:117
struct HW_STREAM_REQUEST_BLOCK_EXT * PHW_STREAM_REQUEST_BLOCK_EXT
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
@ DeviceRequestComplete
Definition: strmini.h:330
_In_ WDF_SPECIAL_FILE_TYPE NotificationType
Definition: wdfdevice.h:1024

◆ StreamClassGetDmaBuffer()

PVOID STREAMAPI StreamClassGetDmaBuffer ( IN PVOID  HwDeviceExtension)

Definition at line 290 of file driver.c.

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}
#define ASSERT(a)
Definition: mode.c:44
uint32_t ULONG_PTR
Definition: typedefs.h:65

◆ StreamClassReadWriteConfig()

BOOLEAN STREAMAPI StreamClassReadWriteConfig ( IN PVOID  HwDeviceExtension,
IN BOOLEAN  Read,
IN PVOID  Buffer,
IN ULONG  OffSet,
IN ULONG  Length 
)

Definition at line 322 of file driver.c.

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}
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI StreamClassRWCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: driver.c:304
#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 IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define KernelMode
Definition: asm.h:34
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ NotificationEvent
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 IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
_In_ BOOLEAN Read
Definition: strmini.h:479
uint32_t ULONG
Definition: typedefs.h:59
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
@ Executive
Definition: ketypes.h:415

◆ StreamClassReenumerateStreams()

VOID NTAPI StreamClassReenumerateStreams ( IN PVOID  HwDeviceExtension,
IN ULONG  StreamDescriptorSize 
)

Definition at line 154 of file driver.c.

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 */
195 KeWaitForSingleObject(&RequestBlock.Event, Executive, KernelMode, FALSE, NULL);
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}
@ SynchronizationEvent
@ SRB_GET_STREAM_INFO
Definition: strmini.h:191
struct _HW_STREAM_REQUEST_BLOCK HW_STREAM_REQUEST_BLOCK
HW_STREAM_REQUEST_BLOCK Block
Definition: stream.h:54
PHW_STREAM_DESCRIPTOR StreamDescriptor
Definition: stream.h:44
ULONG StreamDescriptorSize
Definition: stream.h:43
PHW_RECEIVE_DEVICE_SRB HwReceivePacket
Definition: strmini.h:356
SRB_COMMAND Command
Definition: strmini.h:224
union _HW_STREAM_REQUEST_BLOCK::_CommandData CommandData
PHW_STREAM_DESCRIPTOR StreamBuffer
Definition: strmini.h:232

◆ StreamClassRegisterAdapter()

NTSTATUS STREAMAPI StreamClassRegisterAdapter ( IN PVOID  Argument1,
IN PVOID  Argument2,
IN PHW_INITIALIZATION_DATA  HwInitializationData 
)

Definition at line 106 of file driver.c.

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}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
KSDDKAPI NTSTATUS NTAPI KsSetMajorFunctionHandler(IN PDRIVER_OBJECT DriverObject, IN ULONG MajorFunction)
Definition: irp.c:2050
KSDDKAPI VOID NTAPI KsNullDriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: irp.c:1178
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 StreamClassPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pnp.c:456
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA * HwInitializationData
Definition: srb.h:906
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:696
struct _DRIVER_OBJECT * PDRIVER_OBJECT
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_FLUSH_BUFFERS
#define IRP_MJ_POWER
#define IRP_MJ_CLEANUP

◆ StreamClassRWCompletion()

NTSTATUS NTAPI StreamClassRWCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 304 of file driver.c.

308{
310
311 IoStatusBlock->Information = Irp->IoStatus.Information;
312 IoStatusBlock->Status = Irp->IoStatus.Status;
313
314 return STATUS_SUCCESS;
315}
struct _IO_STATUS_BLOCK * PIO_STATUS_BLOCK
Definition: change.c:34
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

Referenced by StreamClassReadWriteConfig().