-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadapter.cpp
More file actions
333 lines (252 loc) · 7.87 KB
/
adapter.cpp
File metadata and controls
333 lines (252 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*++
Copyright (c) 1997-2000 Microsoft Corporation All Rights Reserved
Module Name:
adapter.cpp
Abstract:
Setup and miniport installation. No resources are used by msvad.
--*/
#pragma warning (disable : 4127)
//
// All the GUIDS for all the miniports end up in this object.
//
#define PUT_GUIDS_HERE
#include <msvad.h>
#include "common.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// BUGBUG set this to number of miniports
#define MAX_MINIPORTS 3 // Number of maximum miniports.
//-----------------------------------------------------------------------------
// Referenced forward.
//-----------------------------------------------------------------------------
DRIVER_ADD_DEVICE AddDevice;
NTSTATUS
StartDevice
(
IN PDEVICE_OBJECT,
IN PIRP,
IN PRESOURCELIST
);
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
//=============================================================================
#pragma code_seg("PAGE")
NTSTATUS PnpHandler
(
_In_ DEVICE_OBJECT *_DeviceObject,
_In_ IRP *_Irp
)
/*++
Routine Description:
Handles PnP IRPs
Arguments:
_Fdo - Functional Device object pointer.
_Irp - The Irp being passed
Return Value:
NT status code.
--*/
{
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
IO_STACK_LOCATION *stack;
PortClassDeviceContext *ext;
PAGED_CODE();
ASSERT(_DeviceObject);
ASSERT(_Irp);
// Check for the REMOVE_DEVICE irp. If we're being unloaded,
// uninstantiate our devices and release the adapter common
// object.
//
stack = IoGetCurrentIrpStackLocation(_Irp);
if ((IRP_MN_REMOVE_DEVICE == stack->MinorFunction) ||
(IRP_MN_SURPRISE_REMOVAL == stack->MinorFunction) ||
(IRP_MN_STOP_DEVICE == stack->MinorFunction))
{
ext= static_cast<PortClassDeviceContext*>(_DeviceObject->DeviceExtension);
ext->m_pCommon->UninstantiateDevices();
ext->m_pCommon->Release();
ext->m_pCommon = NULL;
}
ntStatus = PcDispatchIrp(_DeviceObject, _Irp);
return ntStatus;
}
//=============================================================================
#pragma code_seg("INIT")
extern "C" DRIVER_INITIALIZE DriverEntry;
extern "C" NTSTATUS
DriverEntry
(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPathName
)
{
/*++
Routine Description:
Installable driver initialization entry point.
This entry point is called directly by the I/O system.
All audio adapter drivers can use this code without change.
Arguments:
DriverObject - pointer to the driver object
RegistryPath - pointer to a unicode string representing the path,
to driver-specific key in the registry.
Return Value:
STATUS_SUCCESS if successful,
STATUS_UNSUCCESSFUL otherwise.
--*/
NTSTATUS ntStatus;
DPF(D_TERSE, ("[DriverEntry]"));
// Tell the class driver to initialize the driver.
//
ntStatus =
PcInitializeAdapterDriver
(
DriverObject,
RegistryPathName,
(PDRIVER_ADD_DEVICE)AddDevice
);
if (NT_SUCCESS(ntStatus))
{
#pragma warning (push)
#pragma warning( disable:28169 )
#pragma warning( disable:28023 )
DriverObject->MajorFunction[IRP_MJ_PNP] = PnpHandler;
#pragma warning (pop)
}
return ntStatus;
} // DriverEntry
#pragma code_seg()
// disable prefast warning 28152 because
// DO_DEVICE_INITIALIZING is cleared in PcAddAdapterDevice
#pragma warning(disable:28152)
#pragma code_seg("PAGE")
//=============================================================================
NTSTATUS AddDevice
(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
/*++
Routine Description:
The Plug & Play subsystem is handing us a brand new PDO, for which we
(by means of INF registration) have been asked to provide a driver.
We need to determine if we need to be in the driver stack for the device.
Create a function device object to attach to the stack
Initialize that device object
Return status success.
All audio adapter drivers can use this code without change.
Set MAX_MINIPORTS depending on the number of miniports that the driver
uses.
Arguments:
DriverObject - pointer to a driver object
PhysicalDeviceObject - pointer to a device object created by the
underlying bus driver.
Return Value:
NT status code.
--*/
{
PAGED_CODE();
NTSTATUS ntStatus;
DPF(D_TERSE, ("[AddDevice]"));
// Tell the class driver to add the device.
//
ntStatus =
PcAddAdapterDevice
(
DriverObject,
PhysicalDeviceObject,
PCPFNSTARTDEVICE(StartDevice),
MAX_MINIPORTS,
0
);
return ntStatus;
} // AddDevice
//=============================================================================
NTSTATUS
StartDevice
(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PRESOURCELIST ResourceList
)
{
/*++
Routine Description:
This function is called by the operating system when the device is
started.
It is responsible for starting the miniports. This code is specific to
the adapter because it calls out miniports for functions that are specific
to the adapter.
Arguments:
DeviceObject - pointer to the driver object
Irp - pointer to the irp
ResourceList - pointer to the resource list assigned by PnP manager
Return Value:
NT status code.
--*/
UNREFERENCED_PARAMETER(ResourceList);
UNREFERENCED_PARAMETER(Irp);
PAGED_CODE();
ASSERT(DeviceObject);
ASSERT(Irp);
ASSERT(ResourceList);
NTSTATUS ntStatus = STATUS_SUCCESS;
PADAPTERCOMMON pAdapterCommon = NULL;
PUNKNOWN pUnknownCommon = NULL;
PortClassDeviceContext* pExtenstion = static_cast<PortClassDeviceContext*>(DeviceObject->DeviceExtension);
DPF_ENTER(("[StartDevice]"));
// create a new adapter common object
//
ntStatus =
NewAdapterCommon
(
&pUnknownCommon,
IID_IAdapterCommon,
NULL,
NonPagedPool
);
if (NT_SUCCESS(ntStatus))
{
ntStatus =
pUnknownCommon->QueryInterface
(
IID_IAdapterCommon,
(PVOID *) &pAdapterCommon
);
if (NT_SUCCESS(ntStatus))
{
ntStatus =
pAdapterCommon->Init(DeviceObject);
if (NT_SUCCESS(ntStatus))
{
// register with PortCls for power-management services
//
ntStatus =
PcRegisterAdapterPowerManagement
(
PUNKNOWN(pAdapterCommon),
DeviceObject
);
}
}
}
// Tell the adapter common object to instantiate the subdevices.
//
if (NT_SUCCESS(ntStatus))
{
ntStatus = pAdapterCommon->InstantiateDevices();
}
// Stash the adapter common object in the device extension so
// we can access it for cleanup on stop/removal.
//
if (pAdapterCommon)
{
pExtenstion->m_pCommon = pAdapterCommon;
}
if (pUnknownCommon)
{
pUnknownCommon->Release();
}
return ntStatus;
} // StartDevice
#pragma code_seg()