- Implement ProtocolResetComplete
[reactos.git] / drivers / wdm / audio / drivers / mpu401 / adapter.cpp
1 /*
2 ReactOS Operating System
3 MPU401 Example KS Driver
4
5 AUTHORS:
6 Andrew Greenwood
7
8 NOTES:
9 This is an example MPU401 driver. You can use DirectMusic instead with
10 this, by changing the CLSIDs accordingly.
11 */
12
13 #define MAX_MINIPORTS 1
14
15 #define PUT_GUIDS_HERE
16
17 #define INITGUID
18 #include <ntddk.h>
19 #include <debug.h>
20
21 #include <portcls.h>
22
23 extern "C"
24 NTSTATUS
25 StartDevice(
26 IN PDEVICE_OBJECT pDeviceObject,
27 IN PIRP pIrp,
28 IN PRESOURCELIST ResourceList)
29 {
30 DPRINT1("MPU401_KS StartDevice called\n");
31
32 if ( ! ResourceList )
33 return STATUS_INVALID_PARAMETER;
34
35 if ( ResourceList->NumberOfEntries() == 0 )
36 {
37 return STATUS_INSUFFICIENT_RESOURCES;
38 }
39
40 DPRINT1("Sufficient resources available :)\n");
41
42 PPORT port;
43 PMINIPORT miniport;
44
45 NTSTATUS status;
46
47 DPRINT1("Calling PcNewPort with CLSID_PortMidi\n");
48 status = PcNewPort(&port, CLSID_PortMidi);
49
50 if ( ! NT_SUCCESS(status) )
51 {
52 DPRINT("PcNewPort FAILED with status 0x%08x\n", status);
53 return status;
54 }
55
56 DPRINT1("Calling PcNewMiniport with CLSID_MiniportDriverUart\n");
57 status = PcNewMiniport(&miniport, CLSID_MiniportDriverUart);
58
59 if ( ! NT_SUCCESS(status) )
60 {
61 DPRINT1("PcNewMiniport FAILED with status 0x%08x\n", status);
62 return status;
63 }
64
65 DPRINT1("Calling Init of port object\n");
66 status = port->Init(pDeviceObject, pIrp, miniport, NULL, ResourceList);
67
68 if ( ! NT_SUCCESS(status) )
69 {
70 DPRINT1("Init FAILED with status 0x%08x\n", status);
71 return status;
72 }
73
74 DPRINT1("Registering subdevice via PcRegisterSubdevice\n");
75 status = PcRegisterSubdevice(pDeviceObject, L"Uart", port);
76
77 if ( ! NT_SUCCESS(status) )
78 {
79 /* just print an error here */
80 DPRINT1("PcRegisterSubdevice FAILED with status 0x%08x\n", status);
81 }
82
83 miniport->Release();
84 port->Release();
85
86 DPRINT1("Device started\n");
87
88 return status;
89 }
90
91
92 extern "C"
93 NTSTATUS
94 AddDevice(
95 IN PVOID Context1,
96 IN PVOID Context2)
97 {
98 DPRINT1("MPU401_KS AddDevice called, redirecting to PcAddAdapterDevice\n");
99 return PcAddAdapterDevice((PDRIVER_OBJECT) Context1,
100 (PDEVICE_OBJECT) Context2,
101 StartDevice,
102 MAX_MINIPORTS,
103 0);
104 }
105
106 extern "C"
107 {
108
109 NTSTATUS NTAPI
110 DriverEntry(
111 IN PDRIVER_OBJECT Context1,
112 IN PUNICODE_STRING Context2)
113 {
114 PDEVICE_OBJECT DeviceObject;
115 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\MPU401Static");
116
117 // KeBugCheck(0x0000007F);
118 DPRINT1("MPU401_KS DriverEntry called, redirecting to PcInitializeAdapterDriver\n");
119
120 NTSTATUS status = PcInitializeAdapterDriver((PDRIVER_OBJECT) Context1,
121 (PUNICODE_STRING) Context2,
122 (PDRIVER_ADD_DEVICE) AddDevice);
123 DPRINT1("Result was 0x%08x\n", status);
124
125 /* Create a device (this will be handled by PnP manager really but we fake for now */
126
127 /*
128 DPRINT1("Creating device\n");
129 status = IoCreateDevice(Context1,
130 0,
131 &DeviceName,
132 FILE_DEVICE_SOUND,
133 0,
134 FALSE,
135 &DeviceObject);
136
137 DPRINT1("Result was 0x%08x\n", status);
138 */
139
140 return status;
141 };
142
143 }