ReactOS 0.4.15-dev-7889-g76290a6
device.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for device.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI IKsDevice_fnQueryInterface (IN IKsDevice *iface, REFIID refiid, PVOID *Output)
 
ULONG NTAPI IKsDevice_fnAddRef (IN IKsDevice *iface)
 
ULONG NTAPI IKsDevice_fnRelease (IN IKsDevice *iface)
 
PKSDEVICE NTAPI IKsDevice_fnGetStruct (IN IKsDevice *iface)
 
NTSTATUS NTAPI IKsDevice_fnInitializeObjectBag (IN IKsDevice *iface, IN PKSIOBJECT_BAG Bag, IN PRKMUTEX Mutex)
 
NTSTATUS NTAPI IKsDevice_fnAcquireDevice (IN IKsDevice *iface)
 
NTSTATUS NTAPI IKsDevice_fnReleaseDevice (IN IKsDevice *iface)
 
NTSTATUS NTAPI IKsDevice_fnGetAdapterObject (IN IKsDevice *iface, IN PADAPTER_OBJECT *Object, IN PULONG MaxMappingsByteCount, IN PULONG MappingTableStride)
 
NTSTATUS NTAPI IKsDevice_fnAddPowerEntry (IN IKsDevice *iface, IN struct KSPOWER_ENTRY *Entry, IN IKsPowerNotify *Notify)
 
NTSTATUS NTAPI IKsDevice_fnRemovePowerEntry (IN IKsDevice *iface, IN struct KSPOWER_ENTRY *Entry)
 
NTSTATUS NTAPI IKsDevice_fnPinStateChange (IN IKsDevice *iface, IN KSPIN Pin, IN PIRP Irp, IN KSSTATE OldState, IN KSSTATE NewState)
 
NTSTATUS NTAPI IKsDevice_fnArbitrateAdapterChannel (IN IKsDevice *iface, IN ULONG NumberOfMapRegisters, IN PDRIVER_CONTROL ExecutionRoutine, IN PVOID Context)
 
NTSTATUS NTAPI IKsDevice_fnCheckIoCapability (IN IKsDevice *iface, IN ULONG Unknown)
 
VOID NTAPI IKsDevice_PnpPostStart (IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
 
NTSTATUS NTAPI IKsDevice_PnpStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI IKsDevice_Pnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI IKsDevice_Power (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI IKsDevice_Create (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KSDDKAPI NTSTATUS NTAPI KsInitializeDevice (IN PDEVICE_OBJECT FunctionalDeviceObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_OBJECT NextDeviceObject, IN const KSDEVICE_DESCRIPTOR *Descriptor OPTIONAL)
 
KSDDKAPI NTSTATUS NTAPI KsReferenceSoftwareBusObject (IN KSDEVICE_HEADER Header)
 
KSDDKAPI NTSTATUS NTAPI KsReferenceBusObject (IN KSDEVICE_HEADER Header)
 
KSDDKAPI VOID NTAPI KsDereferenceBusObject (IN KSDEVICE_HEADER Header)
 
KSDDKAPI VOID NTAPI KsDereferenceSoftwareBusObject (IN KSDEVICE_HEADER Header)
 

Variables

static IKsDeviceVtbl vt_IKsDevice
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file device.c.

Function Documentation

◆ IKsDevice_Create()

NTSTATUS NTAPI IKsDevice_Create ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 566 of file device.c.

569{
570 PCREATE_ITEM_ENTRY CreateItemEntry;
571 PIO_STACK_LOCATION IoStack;
572 PDEVICE_EXTENSION DeviceExtension;
573 PKSIDEVICE_HEADER DeviceHeader;
574 PKSIOBJECT_HEADER ObjectHeader;
576
577 DPRINT("IKsDevice_Create\n");
578 /* get current stack location */
580 /* get device extension */
581 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
582 /* get device header */
583 DeviceHeader = DeviceExtension->DeviceHeader;
584
585 if (IoStack->FileObject->FileName.Buffer == NULL)
586 {
587 // ReactOS PnPMgr still sucks
588 ASSERT(IoStack->FileObject->FileName.Length == 0);
589 Irp->IoStatus.Status = STATUS_SUCCESS;
591 DPRINT1("ReactOS PnP hack\n");
592 return STATUS_SUCCESS;
593 }
594
595 /* acquire list lock */
596 IKsDevice_fnAcquireDevice((IKsDevice*)&DeviceHeader->BasicHeader.OuterUnknown);
597
598 /* sanity check */
599 ASSERT(IoStack->FileObject);
600
601 /* check if the request is relative */
602 if (IoStack->FileObject->RelatedFileObject != NULL)
603 {
604 /* request is to instantiate a pin / node / clock / allocator */
605 ObjectHeader = (PKSIOBJECT_HEADER)IoStack->FileObject->RelatedFileObject->FsContext2;
606
607 /* sanity check */
608 ASSERT(ObjectHeader);
609
610 /* find a matching a create item */
611 Status = FindMatchingCreateItem(&ObjectHeader->ItemList,
612 &IoStack->FileObject->FileName,
613 &CreateItemEntry);
614 }
615 else
616 {
617 /* request to create a filter */
618 Status = FindMatchingCreateItem(&DeviceHeader->ItemList,
619 &IoStack->FileObject->FileName,
620 &CreateItemEntry);
621 }
622
623 if (NT_SUCCESS(Status))
624 {
625 /* set object create item */
626 KSCREATE_ITEM_IRP_STORAGE(Irp) = CreateItemEntry->CreateItem;
627
628 /* call create function */
629 Status = CreateItemEntry->CreateItem->Create(DeviceObject, Irp);
630
631 if (NT_SUCCESS(Status))
632 {
633 /* increment create item reference count */
634 InterlockedIncrement(&CreateItemEntry->ReferenceCount);
635 }
636 }
637
638 /* release list lock */
639 IKsDevice_fnReleaseDevice((IKsDevice*)&DeviceHeader->BasicHeader.OuterUnknown);
640
641 /* done */
642 return Status;
643
644
645}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
NTSTATUS NTAPI IKsDevice_fnReleaseDevice(IN IKsDevice *iface)
Definition: device.c:119
NTSTATUS NTAPI IKsDevice_fnAcquireDevice(IN IKsDevice *iface)
Definition: device.c:109
NTSTATUS FindMatchingCreateItem(PLIST_ENTRY ListHead, PUNICODE_STRING String, OUT PCREATE_ITEM_ENTRY *OutCreateItem)
Definition: irp.c:1783
Status
Definition: gdiplustypes.h:25
struct KSIOBJECT_HEADER * PKSIOBJECT_HEADER
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
Definition: kstypes.h:46
PKSOBJECT_CREATE_ITEM CreateItem
Definition: kstypes.h:48
LONG ReferenceCount
Definition: kstypes.h:50
PUNKNOWN OuterUnknown
Definition: kstypes.h:62
KSBASIC_HEADER BasicHeader
Definition: kstypes.h:87
LIST_ENTRY ItemList
Definition: kstypes.h:94
LIST_ENTRY ItemList
Definition: kstypes.h:26
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by KsDispatchIrp(), and KsInitializeDriver().

◆ IKsDevice_fnAcquireDevice()

NTSTATUS NTAPI IKsDevice_fnAcquireDevice ( IN IKsDevice *  iface)

Definition at line 109 of file device.c.

111{
113
114 return KeWaitForSingleObject(&This->DeviceMutex, Executive, KernelMode, FALSE, NULL);
115}
#define FALSE
Definition: types.h:117
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
struct KSIDEVICE_HEADER * PKSIDEVICE_HEADER
#define KernelMode
Definition: asm.h:34
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
@ Executive
Definition: ketypes.h:415

Referenced by IKsDevice_Create().

◆ IKsDevice_fnAddPowerEntry()

NTSTATUS NTAPI IKsDevice_fnAddPowerEntry ( IN IKsDevice *  iface,
IN struct KSPOWER_ENTRY *  Entry,
IN IKsPowerNotify *  Notify 
)

Definition at line 147 of file device.c.

151{
152 //PKSIDEVICE_HEADER This = (PKSIDEVICE_HEADER)CONTAINING_RECORD(iface, KSIDEVICE_HEADER, BasicHeader.OuterUnknown);
153
156}
#define UNIMPLEMENTED
Definition: debug.h:115
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

◆ IKsDevice_fnAddRef()

ULONG NTAPI IKsDevice_fnAddRef ( IN IKsDevice *  iface)

Definition at line 49 of file device.c.

51{
53
54 return InterlockedIncrement(&This->ref);
55}

◆ IKsDevice_fnArbitrateAdapterChannel()

NTSTATUS NTAPI IKsDevice_fnArbitrateAdapterChannel ( IN IKsDevice *  iface,
IN ULONG  NumberOfMapRegisters,
IN PDRIVER_CONTROL  ExecutionRoutine,
IN PVOID  Context 
)

Definition at line 189 of file device.c.

194{
197
198 DPRINT("IKsDevice_fnArbitrateAdapterChannel NumberOfMapRegisters %lu ExecutionRoutine %p Context %p Irql %lu\n", NumberOfMapRegisters, ExecutionRoutine, Context, KeGetCurrentIrql());
199
200 /* sanity check */
202 ASSERT(This->AdapterObject);
203
204 /* allocate adapter channel */
205 Status = IoAllocateAdapterChannel(This->AdapterObject, This->KsDevice.FunctionalDeviceObject, NumberOfMapRegisters, ExecutionRoutine, Context);
206
207 /* done */
208 return Status;
209}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
NTSTATUS NTAPI IoAllocateAdapterChannel(IN PADAPTER_OBJECT AdapterObject, IN PDEVICE_OBJECT DeviceObject, IN ULONG NumberOfMapRegisters, IN PDRIVER_CONTROL ExecutionRoutine, IN PVOID Context)
Definition: adapter.c:30
_Out_ PULONG NumberOfMapRegisters
Definition: halfuncs.h:209
_In_ PDEVICE_OBJECT _In_ ULONG _In_ PDRIVER_CONTROL ExecutionRoutine
Definition: iofuncs.h:1399

◆ IKsDevice_fnCheckIoCapability()

NTSTATUS NTAPI IKsDevice_fnCheckIoCapability ( IN IKsDevice *  iface,
IN ULONG  Unknown 
)

Definition at line 213 of file device.c.

216{
217 //PKSIDEVICE_HEADER This = (PKSIDEVICE_HEADER)CONTAINING_RECORD(iface, KSIDEVICE_HEADER, BasicHeader.OuterUnknown);
218
221}

◆ IKsDevice_fnGetAdapterObject()

NTSTATUS NTAPI IKsDevice_fnGetAdapterObject ( IN IKsDevice *  iface,
IN PADAPTER_OBJECT Object,
IN PULONG  MaxMappingsByteCount,
IN PULONG  MappingTableStride 
)

Definition at line 129 of file device.c.

134{
136
137 *Object = This->AdapterObject;
138 *MaxMappingsByteCount = This->MaxMappingsByteCount;
139 *MappingTableStride = This->MappingTableStride;
140
141 return STATUS_SUCCESS;
142
143}
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

◆ IKsDevice_fnGetStruct()

PKSDEVICE NTAPI IKsDevice_fnGetStruct ( IN IKsDevice *  iface)

Definition at line 73 of file device.c.

75{
77
78 return &This->KsDevice;
79}

◆ IKsDevice_fnInitializeObjectBag()

NTSTATUS NTAPI IKsDevice_fnInitializeObjectBag ( IN IKsDevice *  iface,
IN PKSIOBJECT_BAG  Bag,
IN PRKMUTEX  Mutex 
)

Definition at line 83 of file device.c.

87{
89
90 if (!Mutex)
91 {
92 /* use device mutex */
93 Mutex = &This->BagMutex;
94 }
95
96 /* initialize object bag */
97 Bag->BagMutex = Mutex;
98 Bag->DeviceHeader = (PKSIDEVICE_HEADER)This;
99 InitializeListHead(&Bag->ObjectList);
100
101 /* insert bag into device list */
102 InsertTailList(&This->ObjectBags, &Bag->Entry);
103
104 return STATUS_SUCCESS;
105}
Definition: Mutex.h:16
#define InsertTailList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

◆ IKsDevice_fnPinStateChange()

NTSTATUS NTAPI IKsDevice_fnPinStateChange ( IN IKsDevice *  iface,
IN KSPIN  Pin,
IN PIRP  Irp,
IN KSSTATE  OldState,
IN KSSTATE  NewState 
)

Definition at line 173 of file device.c.

179{
180 //PKSIDEVICE_HEADER This = (PKSIDEVICE_HEADER)CONTAINING_RECORD(iface, KSIDEVICE_HEADER, BasicHeader.OuterUnknown);
181
184
185}

◆ IKsDevice_fnQueryInterface()

NTSTATUS NTAPI IKsDevice_fnQueryInterface ( IN IKsDevice *  iface,
REFIID  refiid,
PVOID Output 
)

Definition at line 16 of file device.c.

20{
23
24 if (IsEqualGUIDAligned(refiid, &IID_IUnknown))
25 {
26 *Output = &This->BasicHeader.OuterUnknown;
28 return STATUS_SUCCESS;
29 }
30
31 if (This->BasicHeader.ClientAggregate)
32 {
33 /* using client aggregate */
34 Status = This->BasicHeader.ClientAggregate->lpVtbl->QueryInterface(This->BasicHeader.ClientAggregate, refiid, Output);
35
36 if (NT_SUCCESS(Status))
37 {
38 /* client aggregate supports interface */
39 return Status;
40 }
41 }
42
43 DPRINT("IKsDevice_fnQueryInterface no interface\n");
45}
const GUID IID_IUnknown
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
@ Output
Definition: arc.h:85
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235

◆ IKsDevice_fnRelease()

ULONG NTAPI IKsDevice_fnRelease ( IN IKsDevice *  iface)

Definition at line 59 of file device.c.

61{
63
65
66 return This->ref;
67}
#define InterlockedDecrement
Definition: armddk.h:52

◆ IKsDevice_fnReleaseDevice()

NTSTATUS NTAPI IKsDevice_fnReleaseDevice ( IN IKsDevice *  iface)

Definition at line 119 of file device.c.

121{
123
124 return KeReleaseMutex(&This->DeviceMutex, FALSE);
125}
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189

Referenced by IKsDevice_Create().

◆ IKsDevice_fnRemovePowerEntry()

NTSTATUS NTAPI IKsDevice_fnRemovePowerEntry ( IN IKsDevice *  iface,
IN struct KSPOWER_ENTRY *  Entry 
)

Definition at line 160 of file device.c.

163{
164 //PKSIDEVICE_HEADER This = (PKSIDEVICE_HEADER)CONTAINING_RECORD(iface, KSIDEVICE_HEADER, BasicHeader.OuterUnknown);
165
168
169}

◆ IKsDevice_Pnp()

NTSTATUS NTAPI IKsDevice_Pnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 409 of file device.c.

412{
413 PIO_STACK_LOCATION IoStack;
414 PDEVICE_EXTENSION DeviceExtension;
415 PKSIDEVICE_HEADER DeviceHeader;
416 PKSDEVICE_DISPATCH Dispatch = NULL;
418
419 /* get current stack location */
421
422 /* get device extension */
423 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
424 /* get device header */
425 DeviceHeader = DeviceExtension->DeviceHeader;
426
427 /* do we have a device descriptor */
428 if (DeviceHeader->KsDevice.Descriptor && DeviceHeader->KsDevice.Descriptor->Dispatch)
429 {
430 /* does the device want pnp notifications */
431 Dispatch = (PKSDEVICE_DISPATCH)DeviceHeader->KsDevice.Descriptor->Dispatch;
432 }
433
434 switch (IoStack->MinorFunction)
435 {
437 {
439 }
440
442 {
444 /* check for pnp notification support */
445 if (Dispatch)
446 {
447 /* check for query stop support */
448 if (Dispatch->QueryStop)
449 {
450 /* call driver's query stop */
451 Status = Dispatch->QueryStop(&DeviceHeader->KsDevice, Irp);
453 }
454 }
455
456 if (!NT_SUCCESS(Status))
457 {
458 DPRINT1("Driver: query stop failed %x\n", Status);
459 Irp->IoStatus.Status = Status;
461 return Status;
462 }
463
464 /* pass the irp down the driver stack */
466 return IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
467 }
468
470 {
471 /* Clean up */
472 if (Dispatch)
473 {
474 /* check for remove support */
475 if (Dispatch->Remove)
476 {
477 /* call driver's stop routine */
478 Dispatch->Remove(&DeviceHeader->KsDevice, Irp);
479 }
480 }
481
482 /* pass the irp down the driver stack */
484 Status = IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
485 /* FIXME delete device resources */
486 return Status;
487 }
489 {
491 /* check for pnp notification support */
492 if (Dispatch)
493 {
494 /* check for query interface support */
495 if (Dispatch->QueryInterface)
496 {
497 /* call driver's query interface */
498 Status = Dispatch->QueryInterface(&DeviceHeader->KsDevice, Irp);
500 }
501 }
502
503 if (NT_SUCCESS(Status))
504 {
505 /* driver supports a private interface */
506 DPRINT1("IRP_MN_QUERY_INTERFACE Device supports interface\n");
507 Irp->IoStatus.Status = Status;
509 return Status;
510 }
511
512 /* pass the irp down the driver stack */
514 return IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
515 }
517 {
518 /* pass the irp down the driver stack */
520 return IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
521 }
523 {
524 /* pass the irp down the driver stack */
525 //Status = KspForwardIrpSynchronous(DeviceObject, Irp);
526 Status = Irp->IoStatus.Status;
527 DPRINT("IRP_MN_FILTER_RESOURCE_REQUIREMENTS Next Device: Status %x\n", Status);
528
529 //Irp->IoStatus.Status = Status;
531 return Status;
532 }
534 {
535 /* pass the irp down the driver stack */
537 return IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
538 }
539 default:
540 DPRINT1("unhandled function %u\n", IoStack->MinorFunction);
541 /* pass the irp down the driver stack */
543 return IoCallDriver(DeviceHeader->KsDevice.NextDeviceObject, Irp);
544 }
545}
NTSTATUS NTAPI CompleteRequest(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: dispatch.c:19
NTSTATUS NTAPI IKsDevice_PnpStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: device.c:276
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
KSDEVICE KsDevice
Definition: kstypes.h:88
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH * Dispatch
Definition: wsk.h:188
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE

Referenced by KsDispatchIrp(), and KsInitializeDriver().

◆ IKsDevice_PnpPostStart()

VOID NTAPI IKsDevice_PnpPostStart ( IN PDEVICE_OBJECT  DeviceObject,
IN PVOID  Context 
)

Definition at line 243 of file device.c.

246{
249
250 /* call driver pnp post routine */
251 Status = Ctx->DeviceHeader->KsDevice.Descriptor->Dispatch->PostStart(&Ctx->DeviceHeader->KsDevice);
252
253 if (!NT_SUCCESS(Status))
254 {
255 /* set state to disabled */
257 }
258 else
259 {
260 /* set state to enabled */
263 }
264
265 /* free work item */
267
268 /* free work context */
269 FreeItem(Ctx);
270
271 DPRINT("IKsDevice_PnpPostStart: PostStart Routine returned %x\n", Status);
272}
NTSTATUS KspSetFilterFactoriesState(IN PKSIDEVICE_HEADER DeviceHeader, IN BOOLEAN NewState)
#define TRUE
Definition: types.h:120
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
@ KSTARGET_STATE_ENABLED
Definition: ks.h:1223
@ KSTARGET_STATE_DISABLED
Definition: ks.h:1222
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
struct PNP_POSTSTART_CONTEXT * PPNP_POSTSTART_CONTEXT
KSTARGET_STATE TargetState
Definition: kstypes.h:100
PKSIDEVICE_HEADER DeviceHeader
Definition: kstypes.h:130
PIO_WORKITEM WorkItem
Definition: kstypes.h:131

Referenced by IKsDevice_PnpStartDevice().

◆ IKsDevice_PnpStartDevice()

NTSTATUS NTAPI IKsDevice_PnpStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 276 of file device.c.

279{
280 PIO_STACK_LOCATION IoStack;
281 PDEVICE_EXTENSION DeviceExtension;
282 PKSIDEVICE_HEADER DeviceHeader;
285 PCM_RESOURCE_LIST TranslatedResourceList;
286 PCM_RESOURCE_LIST UntranslatedResourceList;
287
288 /* get current stack location */
290 /* get device extension */
291 DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
292 /* get device header */
293 DeviceHeader = DeviceExtension->DeviceHeader;
294
295 DPRINT("IKsDevice_PnpStartDevice DeviceHeader %p\n", DeviceHeader);
296
297 /* first forward irp to lower device object */
298 if (!IoForwardIrpSynchronously(DeviceHeader->KsDevice.NextDeviceObject, Irp))
299 {
300 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
301 }
302 Status = Irp->IoStatus.Status;
303
304 /* check for success */
305 if (!NT_SUCCESS(Status))
306 {
307 DPRINT1("NextDevice object failed to start with %x\n", Status);
309 return Status;
310 }
311
312 TranslatedResourceList = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
313 UntranslatedResourceList = IoStack->Parameters.StartDevice.AllocatedResources;
314
315 ASSERT(DeviceHeader->KsDevice.Descriptor);
316
317 /* do we have a device descriptor */
318 if (DeviceHeader->KsDevice.Descriptor)
319 {
320 /* does the device want pnp notifications */
321 if (DeviceHeader->KsDevice.Descriptor->Dispatch)
322 {
323 /* does the driver care about IRP_MN_START_DEVICE */
324 if (DeviceHeader->KsDevice.Descriptor->Dispatch->Start)
325 {
326 /* call driver start device routine */
327 Status = DeviceHeader->KsDevice.Descriptor->Dispatch->Start(&DeviceHeader->KsDevice, Irp,
328 TranslatedResourceList,
329 UntranslatedResourceList);
330
331
332 DPRINT("IKsDevice_PnpStartDevice Start %p, Context %p\n", DeviceHeader->KsDevice.Descriptor->Dispatch->Start, DeviceHeader->KsDevice.Context);
334
335 if (!NT_SUCCESS(Status))
336 {
337 DPRINT1("Driver: failed to start %x\n", Status);
338 Irp->IoStatus.Status = Status;
340 return Status;
341 }
342
343 /* set state to run */
344 DeviceHeader->KsDevice.Started = TRUE;
345
346 }
347
348 /* does the driver need post start routine */
349 if (DeviceHeader->KsDevice.Descriptor->Dispatch->PostStart)
350 {
351 /* allocate pnp post workitem context */
353 if (!Ctx)
354 {
355 /* no memory */
357 }
358 else
359 {
360 /* allocate a work item */
362
363 if (!Ctx->WorkItem)
364 {
365 /* no memory */
366 FreeItem(Ctx);
367 Ctx = NULL;
369 }
370 else
371 {
372 /* store device header for post-start pnp processing */
373 Ctx->DeviceHeader = DeviceHeader;
374 }
375 }
376 }
377 else
378 {
379 /* set state to enabled, IRP_MJ_CREATE request may now succeed */
380 DeviceHeader->TargetState = KSTARGET_STATE_ENABLED;
381 Status = KspSetFilterFactoriesState(DeviceHeader, TRUE);
382 }
383 }
384 else
385 {
386 /* set state to run */
387 DeviceHeader->KsDevice.Started = TRUE;
388 }
389 }
390
391 /* store result */
392 Irp->IoStatus.Status = Status;
393 /* complete request */
395
396 if (Ctx)
397 {
398 /* queue a work item for driver post start routine */
400 }
401
402 /* return result */
403 DPRINT("IKsDevice_PnpStartDevice Status %x PostStartRoutine %p\n", Status, Ctx);
404 return Status;
405}
VOID NTAPI IKsDevice_PnpPostStart(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
Definition: device.c:243
#define NonPagedPool
Definition: env_spec_w32.h:307
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
struct _IO_STACK_LOCATION::@3978::@4015 StartDevice
union _IO_STACK_LOCATION::@1564 Parameters
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
@ DelayedWorkQueue
Definition: extypes.h:190

Referenced by IKsDevice_Pnp().

◆ IKsDevice_Power()

NTSTATUS NTAPI IKsDevice_Power ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 549 of file device.c.

552{
554
555 /* TODO */
556
557 Irp->IoStatus.Status = STATUS_SUCCESS;
558 Irp->IoStatus.Information = 0;
560
561 return STATUS_SUCCESS;
562}

Referenced by KsDispatchIrp(), and KsInitializeDriver().

◆ KsDereferenceBusObject()

KSDDKAPI VOID NTAPI KsDereferenceBusObject ( IN KSDEVICE_HEADER  Header)

Definition at line 829 of file device.c.

831{
832 IKsDevice * Device;
834
835 /* get device interface */
836 Device = (IKsDevice*)DeviceHeader->BasicHeader.OuterUnknown;
837
838 if (Device)
839 {
840 /* release device interface */
841 Device->lpVtbl->Release(Device);
842 }
843}
Definition: Header.h:9
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474

Referenced by KopDispatchClose().

◆ KsDereferenceSoftwareBusObject()

KSDDKAPI VOID NTAPI KsDereferenceSoftwareBusObject ( IN KSDEVICE_HEADER  Header)

Definition at line 851 of file device.c.

853{
854 IKsDevice * Device;
856
857 DPRINT("KsDereferenceSoftwareBusObject DeviceHeader %p\n", Header);
858
859 /* get device interface */
860 Device = (IKsDevice*)DeviceHeader->BasicHeader.OuterUnknown;
861
862 if (Device)
863 {
864 /* release device interface */
865 Device->lpVtbl->Release(Device);
866 }
867}

Referenced by DispatchCreateKMix(), and WdmAudClose().

◆ KsInitializeDevice()

KSDDKAPI NTSTATUS NTAPI KsInitializeDevice ( IN PDEVICE_OBJECT  FunctionalDeviceObject,
IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN PDEVICE_OBJECT  NextDeviceObject,
IN const KSDEVICE_DESCRIPTOR *Descriptor  OPTIONAL 
)

Definition at line 653 of file device.c.

658{
659 PDEVICE_EXTENSION DeviceExtension;
661 ULONG Index;
662 PKSIOBJECT_BAG Bag;
664
665 DPRINT1("KsInitializeDevice Descriptor %p\n", Descriptor);
666
667 /* get device extension */
669
670 /* first allocate device header */
671 Status = KsAllocateDeviceHeader((KSDEVICE_HEADER*)&DeviceExtension->DeviceHeader, 0, NULL);
672
673 /* point to allocated header */
674 Header = DeviceExtension->DeviceHeader;
675
676 DPRINT1("DeviceHeader %p\n", DeviceExtension->DeviceHeader);
677
678 if (Descriptor && Descriptor->Dispatch)
679 {
680 DPRINT("Descriptor Add %p\n", Descriptor->Dispatch->Add);
681 DPRINT("Descriptor Start %p\n", Descriptor->Dispatch->Start);
682 DPRINT("Descriptor PostStart %p\n", Descriptor->Dispatch->PostStart);
683 DPRINT("Descriptor QueryStop %p\n", Descriptor->Dispatch->QueryStop);
684 DPRINT("Descriptor CancelStop %p\n", Descriptor->Dispatch->CancelStop);
685 DPRINT("Descriptor Stop %p\n", Descriptor->Dispatch->Stop);
686 DPRINT("Descriptor QueryRemove %p\n", Descriptor->Dispatch->QueryRemove);
687 DPRINT("Descriptor CancelRemove %p\n", Descriptor->Dispatch->CancelRemove);
688 DPRINT("Descriptor Remove %p\n", Descriptor->Dispatch->Remove);
689 DPRINT("Descriptor QueryCapabilities %p\n", Descriptor->Dispatch->QueryCapabilities);
690 DPRINT("Descriptor SurpriseRemoval %p\n", Descriptor->Dispatch->SurpriseRemoval);
691 DPRINT("Descriptor QueryPower %p\n", Descriptor->Dispatch->QueryPower);
692 DPRINT("Descriptor SetPower %p\n", Descriptor->Dispatch->SetPower);
693 DPRINT("Descriptor QueryInterface %p\n", Descriptor->Dispatch->QueryInterface);
694 }
695
696 /* check for success */
697 if (!NT_SUCCESS(Status))
698 {
699 DPRINT1("KsInitializeDevice Failed to allocate device header with %x\n", Status);
700 return Status;
701 }
702
703 /* initialize IKsDevice interface */
704 Header->BasicHeader.OuterUnknown = (PUNKNOWN)&vt_IKsDevice;
705 Header->ref = 1;
706
707 /* allocate object bag */
708 Header->KsDevice.Bag = AllocateItem(NonPagedPool, sizeof(KSIOBJECT_BAG));
709 if (!Header->KsDevice.Bag)
710 {
711 /* no memory */
712 KsFreeDeviceHeader((KSDEVICE_HEADER*)&DeviceExtension->DeviceHeader);
714 }
715
716 /* initialize object bag */
717 KeInitializeMutex(&Header->BagMutex, 0);
718 KeInitializeMutex(&Header->DeviceMutex, 0);
719
720 Bag = (PKSIOBJECT_BAG)Header->KsDevice.Bag;
721 Bag->BagMutex = &Header->BagMutex;
722 InitializeListHead(&Header->ObjectBags);
724 Bag->DeviceHeader = (PVOID)Header;
725
726 /* insert bag into device list */
727 InsertTailList(&Header->ObjectBags, &Bag->Entry);
728
729 /* initialize device header */
730 Header->KsDevice.FunctionalDeviceObject = FunctionalDeviceObject;
731 Header->KsDevice.PhysicalDeviceObject = PhysicalDeviceObject;
732 Header->KsDevice.NextDeviceObject = NextDeviceObject;
733 Header->KsDevice.Descriptor = Descriptor;
734 Header->KsDevice.SystemPowerState = PowerSystemWorking;
735 Header->KsDevice.DevicePowerState = PowerDeviceD0;
736 Header->KsDevice.Started = FALSE;
737 Header->KsDevice.Context = NULL;
739
740
741
742 if (Descriptor)
743 {
744 /* create a filter factory for each filter descriptor */
745 DPRINT("KsInitializeDevice FilterDescriptorCount %lu\n", Descriptor->FilterDescriptorsCount);
746 for(Index = 0; Index < Descriptor->FilterDescriptorsCount; Index++)
747 {
749
750 DPRINT("KsInitializeDevice Index %lu KspCreateFilterFactory Status %lx\n", Index, Status);
751 /* check for success */
752 if (!NT_SUCCESS(Status))
753 {
754 DPRINT1("KspCreateFilterFactory failed with %x\n", Status);
755 /* FIXME memory leak */
756 return Status;
757 }
758 }
759
760 /* does the driver care about the add device */
761 if (Descriptor->Dispatch && Descriptor->Dispatch->Add)
762 {
763 Status = Descriptor->Dispatch->Add(&Header->KsDevice);
764 DPRINT("Driver: AddHandler Status %x\n", Status);
765 }
766
767 Header->KsDevice.Descriptor = Descriptor;
768 }
769
770
771 return Status;
772}
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
KSDDKAPI VOID NTAPI KsSetDevicePnpAndBaseObject(IN KSDEVICE_HEADER Header, IN PDEVICE_OBJECT PnpDeviceObject, IN PDEVICE_OBJECT BaseDevice)
Definition: api.c:257
KSDDKAPI NTSTATUS NTAPI KsAllocateDeviceHeader(OUT KSDEVICE_HEADER *OutHeader, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL)
Definition: api.c:522
KSDDKAPI VOID NTAPI KsFreeDeviceHeader(IN KSDEVICE_HEADER DevHeader)
Definition: api.c:590
static IKsDeviceVtbl vt_IKsDevice
Definition: device.c:223
NTSTATUS NTAPI KspCreateFilterFactory(IN PDEVICE_OBJECT DeviceObject, IN const KSFILTER_DESCRIPTOR *Descriptor, IN PWSTR RefString OPTIONAL, IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL, IN ULONG CreateItemFlags, IN PFNKSFILTERFACTORYPOWER SleepCallback OPTIONAL, IN PFNKSFILTERFACTORYPOWER WakeCallback OPTIONAL, OUT PKSFILTERFACTORY *FilterFactory OPTIONAL)
struct KSIOBJECT_BAG * PKSIOBJECT_BAG
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4641
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * NextDeviceObject
Definition: ndis.h:4642
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
PVOID DeviceHeader
Definition: ksiface.h:18
LIST_ENTRY ObjectList
Definition: ksiface.h:16
LIST_ENTRY Entry
Definition: ksiface.h:15
PRKMUTEX BagMutex
Definition: ksiface.h:17
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by KsCreateDevice().

◆ KsReferenceBusObject()

KSDDKAPI NTSTATUS NTAPI KsReferenceBusObject ( IN KSDEVICE_HEADER  Header)

Definition at line 804 of file device.c.

806{
807 IKsDevice * Device;
809
810 /* get device interface */
811 Device = (IKsDevice*)DeviceHeader->BasicHeader.OuterUnknown;
812
813 if (Device)
814 {
815 /* reference device interface */
816 Device->lpVtbl->AddRef(Device);
817 }
818
819 return STATUS_SUCCESS;
820
821}

◆ KsReferenceSoftwareBusObject()

KSDDKAPI NTSTATUS NTAPI KsReferenceSoftwareBusObject ( IN KSDEVICE_HEADER  Header)

Definition at line 780 of file device.c.

782{
783 IKsDevice * Device;
785
786 /* get device interface */
787 Device = (IKsDevice*)DeviceHeader->BasicHeader.OuterUnknown;
788
789 if (Device)
790 {
791 /* reference device interface */
792 Device->lpVtbl->AddRef(Device);
793 }
794
795 return STATUS_SUCCESS;
796}

Referenced by DispatchCreateKMix(), PcCreateItemDispatch(), PcCreatePinDispatch(), and WdmAudCreate().

Variable Documentation

◆ vt_IKsDevice

IKsDeviceVtbl vt_IKsDevice
static
Initial value:
=
{
}
NTSTATUS NTAPI IKsDevice_fnPinStateChange(IN IKsDevice *iface, IN KSPIN Pin, IN PIRP Irp, IN KSSTATE OldState, IN KSSTATE NewState)
Definition: device.c:173
NTSTATUS NTAPI IKsDevice_fnAddPowerEntry(IN IKsDevice *iface, IN struct KSPOWER_ENTRY *Entry, IN IKsPowerNotify *Notify)
Definition: device.c:147
PKSDEVICE NTAPI IKsDevice_fnGetStruct(IN IKsDevice *iface)
Definition: device.c:73
ULONG NTAPI IKsDevice_fnAddRef(IN IKsDevice *iface)
Definition: device.c:49
ULONG NTAPI IKsDevice_fnRelease(IN IKsDevice *iface)
Definition: device.c:59
NTSTATUS NTAPI IKsDevice_fnQueryInterface(IN IKsDevice *iface, REFIID refiid, PVOID *Output)
Definition: device.c:16
NTSTATUS NTAPI IKsDevice_fnInitializeObjectBag(IN IKsDevice *iface, IN PKSIOBJECT_BAG Bag, IN PRKMUTEX Mutex)
Definition: device.c:83
NTSTATUS NTAPI IKsDevice_fnCheckIoCapability(IN IKsDevice *iface, IN ULONG Unknown)
Definition: device.c:213
NTSTATUS NTAPI IKsDevice_fnArbitrateAdapterChannel(IN IKsDevice *iface, IN ULONG NumberOfMapRegisters, IN PDRIVER_CONTROL ExecutionRoutine, IN PVOID Context)
Definition: device.c:189
NTSTATUS NTAPI IKsDevice_fnRemovePowerEntry(IN IKsDevice *iface, IN struct KSPOWER_ENTRY *Entry)
Definition: device.c:160
NTSTATUS NTAPI IKsDevice_fnGetAdapterObject(IN IKsDevice *iface, IN PADAPTER_OBJECT *Object, IN PULONG MaxMappingsByteCount, IN PULONG MappingTableStride)
Definition: device.c:129

Definition at line 223 of file device.c.

Referenced by KsInitializeDevice().