ReactOS 0.4.15-dev-8127-g6338913
hdaudbus.cpp
Go to the documentation of this file.
1/*
2* COPYRIGHT: See COPYING in the top level directory
3* PROJECT: ReactOS Kernel Streaming
4* FILE: drivers/wdm/audio/hdaudbus/hdaudbus.cpp
5* PURPOSE: HDA Driver Entry
6* PROGRAMMER: Johannes Anderwald
7*/
8
9#include "hdaudbus.h"
10
14DRIVER_ADD_DEVICE HDA_AddDevice;
15DRIVER_UNLOAD HDA_Unload;
16extern "C" DRIVER_INITIALIZE DriverEntry;
17
22{
23 return ExAllocatePoolZero(PoolType, NumberOfBytes, TAG_HDA);
24}
25
26VOID
29{
31}
32
37{
39 PIO_STACK_LOCATION IoStack;
40 PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
41 ULONG CodecIndex, AFGIndex;
42 PHDA_CODEC_ENTRY CodecEntry;
43 PHDA_PDO_DEVICE_EXTENSION ChildDeviceExtension;
44
45 FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
47
48 switch (IoStack->MinorFunction)
49 {
52 Irp->IoStatus.Status = Status;
54 return Status;
58 for (CodecIndex = 0; CodecIndex < HDA_MAX_CODECS; CodecIndex++)
59 {
60 CodecEntry = FDODeviceExtension->Codecs[CodecIndex];
61
63 for (AFGIndex = 0; AFGIndex < CodecEntry->AudioGroupCount; AFGIndex++)
64 {
65 ChildDeviceExtension = static_cast<PHDA_PDO_DEVICE_EXTENSION>(CodecEntry->AudioGroups[AFGIndex]->ChildPDO->DeviceExtension);
66 ChildDeviceExtension->ReportedMissing = TRUE;
67 }
68 }
69 Irp->IoStatus.Status = STATUS_SUCCESS;
70 break;
73 Irp->IoStatus.Status = STATUS_SUCCESS;
74 break;
76 /* handle bus device relations */
77 if (IoStack->Parameters.QueryDeviceRelations.Type == BusRelations)
78 {
80 Irp->IoStatus.Status = Status;
81 if (!NT_SUCCESS(Status))
82 {
84 return Status;
85 }
86 }
87 break;
88 }
89
91 return IoCallDriver(FDODeviceExtension->LowerDevice, Irp);
92}
93
98{
100 PIO_STACK_LOCATION IoStack;
101 PDEVICE_RELATIONS DeviceRelation;
102
104
105 switch (IoStack->MinorFunction)
106 {
108 /* no op for pdo */
110 break;
113 break;
117 break;
119 /* query bus information */
121 break;
123 /* query pnp state */
125 break;
128 {
129 /* handle target device relations */
130 ASSERT(Irp->IoStatus.Information == 0);
131
132 /* allocate device relation */
133 DeviceRelation = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS));
134 if (DeviceRelation)
135 {
136 DeviceRelation->Count = 1;
137 DeviceRelation->Objects[0] = DeviceObject;
138
139 /* reference self */
141
142 /* store result */
143 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelation;
144
145 /* done */
147 }
148 else
149 {
150 /* no memory */
152 }
153 }
154 else
155 {
156 Status = Irp->IoStatus.Status;
157 }
158 break;
160 /* query capabilities */
162 break;
164 /* no op */
166 break;
168 /* no op */
170 break;
171 case IRP_MN_QUERY_ID:
173 break;
176 break;
179 break;
180 default:
181 /* get default status */
182 Status = Irp->IoStatus.Status;
183 break;
184 }
185
186 Irp->IoStatus.Status = Status;
188
189 return Status;
190}
191
193NTAPI
197{
198 PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
199
200 FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
201
202 if (FDODeviceExtension->IsFDO)
203 {
204 return HDA_FdoPnp(DeviceObject, Irp);
205 }
206 else
207 {
208 return HDA_PdoPnp(DeviceObject, Irp);
209 }
210}
211
213NTAPI
217{
219 PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
220
221 FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
222
223 if (FDODeviceExtension->IsFDO)
224 {
226 return IoCallDriver(FDODeviceExtension->LowerDevice, Irp);
227 }
228 else
229 {
230 Status = Irp->IoStatus.Status;
232 return Status;
233 }
234}
235
237NTAPI
241{
243 PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
244
245 FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
246
247 if (FDODeviceExtension->IsFDO)
248 {
251 return PoCallDriver(FDODeviceExtension->LowerDevice, Irp);
252 }
253 else
254 {
255 Status = Irp->IoStatus.Status;
258 return Status;
259 }
260}
261
263NTAPI
267{
269 PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
271
272 /* create device object */
274 if (!NT_SUCCESS(Status))
275 {
276 /* failed */
277 return Status;
278 }
279
280 /* get device extension*/
281 DeviceExtension = (PHDA_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
282
283 /* init device extension*/
284 DeviceExtension->IsFDO = TRUE;
287 RtlZeroMemory(DeviceExtension->Codecs, sizeof(PHDA_CODEC_ENTRY) * (HDA_MAX_CODECS + 1));
288
289 /* set device flags */
291
292 return Status;
293}
294
295VOID
296NTAPI
299{
300}
301
302extern "C"
303{
304
306NTAPI
309 _In_ PUNICODE_STRING RegistryPathName)
310{
311 DriverObject->DriverUnload = HDA_Unload;
312 DriverObject->DriverExtension->AddDevice = HDA_AddDevice;
313 DriverObject->MajorFunction[IRP_MJ_POWER] = HDA_Power;
315 DriverObject->MajorFunction[IRP_MJ_PNP] = HDA_Pnp;
316
317 return STATUS_SUCCESS;
318}
319
320} // extern "C"
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
NTSTATUS HDA_PDOHandleQueryInterface(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ULONG_PTR
Definition: config.h:101
#define HDA_MAX_AUDIO_GROUPS
Definition: driver.h:40
#define HDA_MAX_CODECS
Definition: driver.h:41
#define __drv_freesMem(kind)
Definition: driverspecs.h:272
#define PagedPool
Definition: env_spec_w32.h:308
NTSTATUS NTAPI HDA_FDOStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.cpp:579
NTSTATUS NTAPI HDA_FDORemoveDevice(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: fdo.cpp:693
NTSTATUS NTAPI HDA_FDOQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.cpp:761
Status
Definition: gdiplustypes.h:25
DRIVER_DISPATCH HDA_Pnp
Definition: hdaudbus.cpp:11
DRIVER_DISPATCH HDA_SystemControl
Definition: hdaudbus.cpp:12
DRIVER_ADD_DEVICE HDA_AddDevice
Definition: hdaudbus.cpp:14
DRIVER_INITIALIZE DriverEntry
Definition: hdaudbus.cpp:16
DRIVER_DISPATCH HDA_Power
Definition: hdaudbus.cpp:13
VOID FreeItem(__drv_freesMem(Mem) PVOID Item)
Definition: hdaudbus.cpp:27
NTSTATUS HDA_FdoPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: hdaudbus.cpp:34
PVOID AllocateItem(_In_ POOL_TYPE PoolType, _In_ SIZE_T NumberOfBytes)
Definition: hdaudbus.cpp:19
NTSTATUS HDA_PdoPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: hdaudbus.cpp:95
DRIVER_UNLOAD HDA_Unload
Definition: hdaudbus.cpp:15
IO_DPC_ROUTINE HDA_DpcForIsr
Definition: hdaudbus.h:119
NTSTATUS HDA_PDOHandleQueryDeviceText(IN PIRP Irp)
Definition: pdo.cpp:154
#define TAG_HDA
Definition: hdaudbus.h:15
NTSTATUS HDA_PDORemoveDevice(_In_ PDEVICE_OBJECT DeviceObject)
Definition: pdo.cpp:11
struct HDA_FDO_DEVICE_EXTENSION * PHDA_FDO_DEVICE_EXTENSION
NTSTATUS HDA_PDOQueryBusDeviceCapabilities(IN PIRP Irp)
Definition: pdo.cpp:199
NTSTATUS HDA_PDOQueryBusDevicePnpState(IN PIRP Irp)
Definition: pdo.cpp:227
NTSTATUS HDA_PDOQueryBusInformation(IN PIRP Irp)
Definition: pdo.cpp:33
NTSTATUS NTAPI HDA_PDOQueryId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.cpp:62
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
DRIVER_DISPATCH(nfs41_FsdDispatch)
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
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
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT ChildPDO
Definition: hdaudbus.h:39
Definition: hdaudbus.h:45
PHDA_CODEC_AUDIO_GROUP AudioGroups[HDA_MAX_AUDIO_GROUPS]
Definition: hdaudbus.h:58
ULONG AudioGroupCount
Definition: hdaudbus.h:59
PDEVICE_OBJECT LowerDevice
Definition: hdaudbus.h:66
PHDA_CODEC_ENTRY Codecs[HDA_MAX_CODECS+1]
Definition: hdaudbus.h:80
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
struct _IO_STACK_LOCATION::@3983::@4008 QueryDeviceRelations
union _IO_STACK_LOCATION::@1568 Parameters
INT POOL_TYPE
Definition: typedefs.h:78
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2840
@ BusRelations
Definition: iotypes.h:2152
@ TargetDeviceRelation
Definition: iotypes.h:2156
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DO_POWER_PAGABLE
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MJ_POWER
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036
#define IRP_MN_QUERY_BUS_INFORMATION
#define IRP_MN_QUERY_REMOVE_DEVICE
#define ObReferenceObject
Definition: obfuncs.h:204