611697bcacb5c0a4b2eaecbda012b15c04483509
[reactos.git] / drivers / wdm / audio / filters / kmixer / kmixer.c
1 /*
2 * PROJECT: ReactOS Kernel Streaming Mixer
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/wdm/audio/filters/kmixer/kmixer.c
5 * PURPOSE: main entry point
6 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
7 */
8
9 #include "kmixer.h"
10
11 NTSTATUS
12 NTAPI
13 KMix_Pnp(
14 IN PDEVICE_OBJECT DeviceObject,
15 IN PIRP Irp)
16 {
17 PIO_STACK_LOCATION IrpStack;
18
19 IrpStack = IoGetCurrentIrpStackLocation(Irp);
20
21 DPRINT("KMix_Pnp called for func %x\n", IrpStack->MinorFunction);
22
23 if (IrpStack->MinorFunction == IRP_MN_QUERY_PNP_DEVICE_STATE)
24 {
25 Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
26 }
27
28 return KsDefaultDispatchPnp(DeviceObject, Irp);
29 }
30
31 VOID
32 NTAPI
33 KMix_Unload(IN PDRIVER_OBJECT DriverObject)
34 {
35 DPRINT1("SysAudio_Unload called\n");
36 }
37
38 NTSTATUS
39 NTAPI
40 KMix_InstallDevice(
41 IN PDRIVER_OBJECT DriverObject)
42 {
43 NTSTATUS Status;
44 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\kmixer");
45 PDEVICE_OBJECT DeviceObject;
46 PKMIXER_DEVICE_EXT DeviceExtension;
47
48 DPRINT1("KMix_InstallDevice called\n");
49
50 /* create the device */
51 Status = IoCreateDevice(DriverObject,
52 sizeof(KMIXER_DEVICE_EXT),
53 &DeviceName,
54 FILE_DEVICE_KS,
55 0,
56 FALSE,
57 &DeviceObject);
58
59 /* check for success */
60 if (!NT_SUCCESS(Status))
61 {
62 DPRINT("Failed to create \\Device\\kmixer !\n");
63 return Status;
64 }
65
66 DeviceExtension = (PKMIXER_DEVICE_EXT)DeviceObject->DeviceExtension;
67 /* initialize device extension */
68 RtlZeroMemory(DeviceExtension, sizeof(KMIXER_DEVICE_EXT));
69
70
71 Status = KMixAllocateDeviceHeader(DeviceExtension);
72 if (!NT_SUCCESS(Status))
73 {
74 DPRINT1("KMixAllocateDeviceHeader failed with %x\n", Status);
75 goto cleanup;
76 }
77
78 /* set io flags */
79 DeviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE;
80 /* clear initializing flag */
81 DeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING;
82
83 DPRINT("KMix_InstallDevice result %x\n", Status);
84 return STATUS_SUCCESS;
85
86 cleanup:
87
88 IoDeleteDevice(DeviceObject);
89 return Status;
90 }
91
92
93 NTSTATUS
94 NTAPI
95 DriverEntry(
96 PDRIVER_OBJECT DriverObject,
97 PUNICODE_STRING RegistryPathName)
98 {
99 DPRINT1("KMixer.sys loaded\n");
100
101 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CREATE);
102 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_CLOSE);
103 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_WRITE);
104 KsSetMajorFunctionHandler(DriverObject, IRP_MJ_DEVICE_CONTROL);
105
106 DriverObject->MajorFunction[IRP_MJ_POWER] = KsDefaultDispatchPower;
107 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = KsDefaultForwardIrp;
108 DriverObject->MajorFunction[IRP_MJ_PNP] = KMix_Pnp;
109 DriverObject->DriverUnload = KMix_Unload;
110
111 return KMix_InstallDevice(DriverObject);
112 }