ReactOS  0.4.14-dev-1007-g90d795b
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 #include "hdaudbus.h"
9 
13 DRIVER_ADD_DEVICE HDA_AddDevice;
14 DRIVER_UNLOAD HDA_Unload;
15 extern "C" DRIVER_INITIALIZE DriverEntry;
16 
17 PVOID
21 {
23  if (!Item)
24  return Item;
25 
27  return Item;
28 }
29 
30 VOID
32  __drv_freesMem(Mem) PVOID Item)
33 {
34  ExFreePool(Item);
35 }
36 
41 {
43  PIO_STACK_LOCATION IoStack;
44  PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
45  ULONG CodecIndex, AFGIndex;
46  PHDA_CODEC_ENTRY CodecEntry;
47  PHDA_PDO_DEVICE_EXTENSION ChildDeviceExtension;
48 
49  FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
51 
52  switch (IoStack->MinorFunction)
53  {
56  Irp->IoStatus.Status = Status;
58  return Status;
62  for (CodecIndex = 0; CodecIndex < HDA_MAX_CODECS; CodecIndex++)
63  {
64  CodecEntry = FDODeviceExtension->Codecs[CodecIndex];
65 
67  for (AFGIndex = 0; AFGIndex < CodecEntry->AudioGroupCount; AFGIndex++)
68  {
69  ChildDeviceExtension = static_cast<PHDA_PDO_DEVICE_EXTENSION>(CodecEntry->AudioGroups[AFGIndex]->ChildPDO->DeviceExtension);
70  ChildDeviceExtension->ReportedMissing = TRUE;
71  }
72  }
73  Irp->IoStatus.Status = STATUS_SUCCESS;
74  break;
77  Irp->IoStatus.Status = STATUS_SUCCESS;
78  break;
80  /* handle bus device relations */
81  if (IoStack->Parameters.QueryDeviceRelations.Type == BusRelations)
82  {
84  Irp->IoStatus.Status = Status;
85  if (!NT_SUCCESS(Status))
86  {
88  return Status;
89  }
90  }
91  break;
92  }
93 
95  return IoCallDriver(FDODeviceExtension->LowerDevice, Irp);
96 }
97 
101  _Inout_ PIRP Irp)
102 {
104  PIO_STACK_LOCATION IoStack;
105  PDEVICE_RELATIONS DeviceRelation;
106 
108 
109  switch (IoStack->MinorFunction)
110  {
111  case IRP_MN_START_DEVICE:
112  /* no op for pdo */
114  break;
117  break;
121  break;
123  /* query bus information */
125  break;
127  /* query pnp state */
129  break;
131  if (IoStack->Parameters.QueryDeviceRelations.Type == TargetDeviceRelation)
132  {
133  /* handle target device relations */
134  ASSERT(IoStack->Parameters.QueryDeviceRelations.Type == TargetDeviceRelation);
135  ASSERT(Irp->IoStatus.Information == 0);
136 
137  /* allocate device relation */
138  DeviceRelation = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS));
139  if (DeviceRelation)
140  {
141  DeviceRelation->Count = 1;
142  DeviceRelation->Objects[0] = DeviceObject;
143 
144  /* reference self */
146 
147  /* store result */
148  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelation;
149 
150  /* done */
152  }
153  else
154  {
155  /* no memory */
157  }
158  }
159  break;
161  /* query capabilities */
163  break;
165  /* no op */
167  break;
169  /* no op */
171  break;
172  case IRP_MN_QUERY_ID:
174  break;
177  break;
180  break;
181  default:
182  /* get default status */
183  Status = Irp->IoStatus.Status;
184  break;
185  }
186 
187  Irp->IoStatus.Status = Status;
189 
190  return Status;
191 }
192 
193 NTSTATUS
194 NTAPI
197  _Inout_ PIRP Irp)
198 {
199  PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
200 
201  FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
202 
203  if (FDODeviceExtension->IsFDO)
204  {
205  return HDA_FdoPnp(DeviceObject, Irp);
206  }
207  else
208  {
209  return HDA_PdoPnp(DeviceObject, Irp);
210  }
211 }
212 
213 NTSTATUS
214 NTAPI
217  _Inout_ PIRP Irp)
218 {
220  PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
221 
222  FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
223 
224  if (FDODeviceExtension->IsFDO)
225  {
227  return IoCallDriver(FDODeviceExtension->LowerDevice, Irp);
228  }
229  else
230  {
231  Status = Irp->IoStatus.Status;
233  return Status;
234  }
235 }
236 
237 NTSTATUS
238 NTAPI
241  _Inout_ PIRP Irp)
242 {
244  PHDA_FDO_DEVICE_EXTENSION FDODeviceExtension;
245 
246  FDODeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
247 
248  if (FDODeviceExtension->IsFDO)
249  {
252  return PoCallDriver(FDODeviceExtension->LowerDevice, Irp);
253  }
254  else
255  {
256  Status = Irp->IoStatus.Status;
259  return Status;
260  }
261 }
262 
263 NTSTATUS
264 NTAPI
268 {
270  PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
272 
273  /* create device object */
275  if (!NT_SUCCESS(Status))
276  {
277  /* failed */
278  return Status;
279  }
280 
281  /* get device extension*/
283 
284  /* init device extension*/
285  DeviceExtension->IsFDO = TRUE;
288  RtlZeroMemory(DeviceExtension->Codecs, sizeof(PHDA_CODEC_ENTRY) * (HDA_MAX_CODECS + 1));
289 
290  /* set device flags */
292 
293  return Status;
294 }
295 
296 VOID
297 NTAPI
300 {
301 }
302 
303 extern "C"
304 {
305 NTSTATUS
306 NTAPI
309  _In_ PUNICODE_STRING RegistryPathName)
310 {
316 
317  return STATUS_SUCCESS;
318 }
319 
320 }
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2792
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define DO_POWER_PAGABLE
#define TRUE
Definition: types.h:120
#define HDA_MAX_AUDIO_GROUPS
Definition: driver.h:40
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_REMOVE_DEVICE
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_ID
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
IO_DPC_ROUTINE HDA_DpcForIsr
Definition: hdaudbus.h:122
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
NTSTATUS HDA_FdoPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: hdaudbus.cpp:38
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
struct HDA_FDO_DEVICE_EXTENSION * PHDA_FDO_DEVICE_EXTENSION
LONG NTSTATUS
Definition: precomp.h:26
DRIVER_DISPATCH HDA_Power
Definition: hdaudbus.cpp:12
PVOID AllocateItem(_In_ POOL_TYPE PoolType, _In_ SIZE_T NumberOfBytes)
Definition: hdaudbus.cpp:18
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
DRIVER_DISPATCH HDA_Pnp
Definition: hdaudbus.cpp:10
NTSTATUS HDA_PDOQueryBusDevicePnpState(IN PIRP Irp)
Definition: pdo.cpp:227
NTSTATUS NTAPI HDA_FDOStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.cpp:558
NTSTATUS NTAPI HDA_FDOQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.cpp:740
PHDA_CODEC_ENTRY Codecs[HDA_MAX_CODECS+1]
Definition: hdaudbus.h:82
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define IRP_MN_QUERY_REMOVE_DEVICE
ULONG AudioGroupCount
Definition: hdaudbus.h:60
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
PHDA_CODEC_AUDIO_GROUP AudioGroups[HDA_MAX_AUDIO_GROUPS]
Definition: hdaudbus.h:59
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
#define TAG_HDA
Definition: hdaudbus.h:11
NTSTATUS HDA_PDOQueryBusInformation(IN PIRP Irp)
Definition: pdo.cpp:33
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
NTSTATUS HDA_PDORemoveDevice(_In_ PDEVICE_OBJECT DeviceObject)
Definition: pdo.cpp:11
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:77
NTSTATUS HDA_PDOQueryBusDeviceCapabilities(IN PIRP Irp)
Definition: pdo.cpp:199
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_INTERFACE
#define _Inout_
Definition: no_sal2.h:244
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IRP_MN_QUERY_BUS_INFORMATION
#define IRP_MJ_POWER
DRIVER_INITIALIZE DriverEntry
Definition: hdaudbus.cpp:15
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
PDEVICE_OBJECT LowerDevice
Definition: hdaudbus.h:68
Definition: hdaudbus.h:45
DRIVER_DISPATCH(nfs41_FsdDispatch)
#define IRP_MJ_SYSTEM_CONTROL
NTSTATUS HDA_PDOHandleQueryInterface(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Status
Definition: gdiplustypes.h:24
DRIVER_ADD_DEVICE HDA_AddDevice
Definition: hdaudbus.cpp:13
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ULONG_PTR SIZE_T
Definition: typedefs.h:79
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
#define HDA_MAX_CODECS
Definition: driver.h:41
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define __drv_freesMem(kind)
Definition: driverspecs.h:254
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
DRIVER_UNLOAD HDA_Unload
Definition: hdaudbus.cpp:14
VOID FreeItem(__drv_freesMem(Mem) PVOID Item)
Definition: hdaudbus.cpp:31
#define ObReferenceObject
Definition: obfuncs.h:204
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
PDEVICE_OBJECT ChildPDO
Definition: hdaudbus.h:40
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS NTAPI HDA_FDORemoveDevice(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: fdo.cpp:672
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147
NTSTATUS HDA_PdoPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: hdaudbus.cpp:99
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS HDA_PDOHandleQueryDeviceText(IN PIRP Irp)
Definition: pdo.cpp:154
DRIVER_DISPATCH HDA_SystemControl
Definition: hdaudbus.cpp:11
#define IRP_MN_QUERY_CAPABILITIES
NTSTATUS NTAPI HDA_PDOQueryId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.cpp:62