xref: /reactos/drivers/wdm/audio/hdaudbus/pdo.cpp (revision 6ec38aa9)
1c2c66affSColin Finck /*
2c2c66affSColin Finck * COPYRIGHT:       See COPYING in the top level directory
3c2c66affSColin Finck * PROJECT:         ReactOS Kernel Streaming
4c2c66affSColin Finck * FILE:            drivers/wdm/audio/hdaudbus/pdo.cpp
5c2c66affSColin Finck * PURPOSE:         HDA Driver Entry
6c2c66affSColin Finck * PROGRAMMER:      Johannes Anderwald
7c2c66affSColin Finck */
8c2c66affSColin Finck #include "hdaudbus.h"
9c2c66affSColin Finck 
10c2c66affSColin Finck NTSTATUS
HDA_PDORemoveDevice(_In_ PDEVICE_OBJECT DeviceObject)11584baf79SThomas Faber HDA_PDORemoveDevice(
12584baf79SThomas Faber     _In_ PDEVICE_OBJECT DeviceObject)
13584baf79SThomas Faber {
14584baf79SThomas Faber     PHDA_PDO_DEVICE_EXTENSION DeviceExtension;
15584baf79SThomas Faber 
16584baf79SThomas Faber     /* get device extension */
17584baf79SThomas Faber     DeviceExtension = static_cast<PHDA_PDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
18584baf79SThomas Faber     ASSERT(DeviceExtension->IsFDO == FALSE);
19584baf79SThomas Faber 
20584baf79SThomas Faber     if (DeviceExtension->ReportedMissing)
21584baf79SThomas Faber     {
22584baf79SThomas Faber         if (DeviceExtension->AudioGroup != NULL)
23584baf79SThomas Faber         {
24584baf79SThomas Faber             DeviceExtension->AudioGroup->ChildPDO = NULL;
25584baf79SThomas Faber         }
26584baf79SThomas Faber         IoDeleteDevice(DeviceObject);
27584baf79SThomas Faber     }
28584baf79SThomas Faber 
29584baf79SThomas Faber     return STATUS_SUCCESS;
30584baf79SThomas Faber }
31584baf79SThomas Faber 
32584baf79SThomas Faber NTSTATUS
HDA_PDOQueryBusInformation(IN PIRP Irp)33c2c66affSColin Finck HDA_PDOQueryBusInformation(
34c2c66affSColin Finck     IN PIRP Irp)
35c2c66affSColin Finck {
36c2c66affSColin Finck     PPNP_BUS_INFORMATION BusInformation;
37c2c66affSColin Finck 
38c2c66affSColin Finck     /* allocate bus information */
39c2c66affSColin Finck     BusInformation = (PPNP_BUS_INFORMATION)AllocateItem(PagedPool, sizeof(PNP_BUS_INFORMATION));
40c2c66affSColin Finck 
41c2c66affSColin Finck     if (!BusInformation)
42c2c66affSColin Finck     {
43c2c66affSColin Finck         /* no memory */
44c2c66affSColin Finck         return STATUS_INSUFFICIENT_RESOURCES;
45c2c66affSColin Finck     }
46c2c66affSColin Finck 
47c2c66affSColin Finck     /* return info */
48c2c66affSColin Finck     BusInformation->BusNumber = 0;
49c2c66affSColin Finck     BusInformation->LegacyBusType = PCIBus;
50c2c66affSColin Finck     RtlMoveMemory(&BusInformation->BusTypeGuid, &GUID_HDAUDIO_BUS_INTERFACE, sizeof(GUID));
51c2c66affSColin Finck 
52c2c66affSColin Finck     /* store result */
53c2c66affSColin Finck     Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
54c2c66affSColin Finck 
55c2c66affSColin Finck     /* done */
56c2c66affSColin Finck     return STATUS_SUCCESS;
57c2c66affSColin Finck }
58c2c66affSColin Finck 
59c2c66affSColin Finck 
60c2c66affSColin Finck NTSTATUS
61c2c66affSColin Finck NTAPI
HDA_PDOQueryId(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)62c2c66affSColin Finck HDA_PDOQueryId(
63c2c66affSColin Finck     IN PDEVICE_OBJECT DeviceObject,
64c2c66affSColin Finck     IN PIRP Irp)
65c2c66affSColin Finck {
66c2c66affSColin Finck     PIO_STACK_LOCATION IoStack;
67c2c66affSColin Finck     WCHAR DeviceName[200];
68c2c66affSColin Finck     PHDA_PDO_DEVICE_EXTENSION DeviceExtension;
69c2c66affSColin Finck     ULONG Length;
70c2c66affSColin Finck     LPWSTR Device;
71*6ec38aa9SThomas Faber     NTSTATUS Status;
72c2c66affSColin Finck 
73c2c66affSColin Finck     /* get device extension */
74c2c66affSColin Finck     DeviceExtension = (PHDA_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
75c2c66affSColin Finck     ASSERT(DeviceExtension->IsFDO == FALSE);
76c2c66affSColin Finck 
77c2c66affSColin Finck     /* get current irp stack location */
78c2c66affSColin Finck     IoStack = IoGetCurrentIrpStackLocation(Irp);
79c2c66affSColin Finck 
80c2c66affSColin Finck     if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
81c2c66affSColin Finck     {
82*6ec38aa9SThomas Faber         Status = RtlStringCbPrintfW(DeviceName,
83*6ec38aa9SThomas Faber                                     sizeof(DeviceName),
84*6ec38aa9SThomas Faber                                     L"%02x%02x",
85*6ec38aa9SThomas Faber                                     DeviceExtension->Codec->Addr,
86*6ec38aa9SThomas Faber                                     DeviceExtension->AudioGroup->NodeId);
87*6ec38aa9SThomas Faber         NT_ASSERT(NT_SUCCESS(Status));
88*6ec38aa9SThomas Faber         Length = wcslen(DeviceName) + 1;
89c2c66affSColin Finck 
90c2c66affSColin Finck         /* allocate result buffer*/
91c2c66affSColin Finck         Device = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
92c2c66affSColin Finck         if (!Device)
93c2c66affSColin Finck             return STATUS_INSUFFICIENT_RESOURCES;
94c2c66affSColin Finck 
95*6ec38aa9SThomas Faber         Status = RtlStringCbCopyW(Device,
96*6ec38aa9SThomas Faber                                   Length * sizeof(WCHAR),
97*6ec38aa9SThomas Faber                                   DeviceName);
98*6ec38aa9SThomas Faber         NT_ASSERT(NT_SUCCESS(Status));
99c2c66affSColin Finck 
100c2c66affSColin Finck         DPRINT1("ID: %S\n", Device);
101c2c66affSColin Finck         /* store result */
102c2c66affSColin Finck         Irp->IoStatus.Information = (ULONG_PTR)Device;
103c2c66affSColin Finck         return STATUS_SUCCESS;
104c2c66affSColin Finck     }
105c2c66affSColin Finck     else if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID ||
106c2c66affSColin Finck         IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
107c2c66affSColin Finck     {
108c2c66affSColin Finck 
109c2c66affSColin Finck         /* calculate size */
110c2c66affSColin Finck         swprintf(DeviceName, L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X&SUBSYS_%08X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId, DeviceExtension->Codec->VendorId << 16 | DeviceExtension->Codec->ProductId);
111c2c66affSColin Finck         Length = wcslen(DeviceName) + 20;
112c2c66affSColin Finck 
113c2c66affSColin Finck         /* allocate result buffer*/
114c2c66affSColin Finck         Device = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
115c2c66affSColin Finck         if (!Device)
116c2c66affSColin Finck             return STATUS_INSUFFICIENT_RESOURCES;
117c2c66affSColin Finck 
118c2c66affSColin Finck         wcscpy(Device, DeviceName);
119c2c66affSColin Finck 
120c2c66affSColin Finck         DPRINT1("ID: %S\n", Device);
121c2c66affSColin Finck         /* store result */
122c2c66affSColin Finck         Irp->IoStatus.Information = (ULONG_PTR)Device;
123c2c66affSColin Finck         return STATUS_SUCCESS;
124c2c66affSColin Finck     }
125c2c66affSColin Finck     else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
126c2c66affSColin Finck     {
127c2c66affSColin Finck         RtlZeroMemory(DeviceName, sizeof(DeviceName));
128c2c66affSColin Finck         Length = swprintf(DeviceName, L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X&REV_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId, DeviceExtension->Codec->Major << 12 | DeviceExtension->Codec->Minor << 8 | DeviceExtension->Codec->Revision) + 1;
129c2c66affSColin Finck         Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId) + 1;
130c2c66affSColin Finck         Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X&VEN_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId) + 1;
131c2c66affSColin Finck         Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X", DeviceExtension->AudioGroup->FunctionGroup) + 2;
132c2c66affSColin Finck 
133c2c66affSColin Finck         /* allocate result buffer*/
134c2c66affSColin Finck         Device = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
135c2c66affSColin Finck         if (!Device)
136c2c66affSColin Finck             return STATUS_INSUFFICIENT_RESOURCES;
137c2c66affSColin Finck 
138c2c66affSColin Finck         RtlCopyMemory(Device, DeviceName, Length * sizeof(WCHAR));
139c2c66affSColin Finck 
140c2c66affSColin Finck         DPRINT1("ID: %S\n", Device);
141c2c66affSColin Finck         /* store result */
142c2c66affSColin Finck         Irp->IoStatus.Information = (ULONG_PTR)Device;
143c2c66affSColin Finck         return STATUS_SUCCESS;
144c2c66affSColin Finck     }
145c2c66affSColin Finck     else
146c2c66affSColin Finck     {
147c2c66affSColin Finck         DPRINT1("QueryID Type %x not implemented\n", IoStack->Parameters.QueryId.IdType);
148c2c66affSColin Finck         return Irp->IoStatus.Status;
149c2c66affSColin Finck     }
150c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
151c2c66affSColin Finck }
152c2c66affSColin Finck 
153c2c66affSColin Finck NTSTATUS
HDA_PDOHandleQueryDeviceText(IN PIRP Irp)154c2c66affSColin Finck HDA_PDOHandleQueryDeviceText(
155c2c66affSColin Finck     IN PIRP Irp)
156c2c66affSColin Finck {
157c2c66affSColin Finck     PIO_STACK_LOCATION IoStack;
158c2c66affSColin Finck     LPWSTR Buffer;
159c2c66affSColin Finck     static WCHAR DeviceText[] = L"Audio Device on High Definition Audio Bus";
160c2c66affSColin Finck 
161c2c66affSColin Finck     IoStack = IoGetCurrentIrpStackLocation(Irp);
162c2c66affSColin Finck     if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription)
163c2c66affSColin Finck     {
164c2c66affSColin Finck         DPRINT("HDA_PdoHandleQueryDeviceText DeviceTextDescription\n");
165c2c66affSColin Finck 
166c2c66affSColin Finck         Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
167c2c66affSColin Finck         if (!Buffer)
168c2c66affSColin Finck         {
169c2c66affSColin Finck             Irp->IoStatus.Information = 0;
170c2c66affSColin Finck             return STATUS_INSUFFICIENT_RESOURCES;
171c2c66affSColin Finck         }
172c2c66affSColin Finck 
173c2c66affSColin Finck         wcscpy(Buffer, DeviceText);
174c2c66affSColin Finck 
175c2c66affSColin Finck         Irp->IoStatus.Information = (ULONG_PTR)Buffer;
176c2c66affSColin Finck         return STATUS_SUCCESS;
177c2c66affSColin Finck     }
178c2c66affSColin Finck     else
179c2c66affSColin Finck     {
180c2c66affSColin Finck         DPRINT("HDA_PdoHandleQueryDeviceText DeviceTextLocationInformation\n");
181c2c66affSColin Finck 
182c2c66affSColin Finck         Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
183c2c66affSColin Finck         if (!Buffer)
184c2c66affSColin Finck         {
185c2c66affSColin Finck             Irp->IoStatus.Information = 0;
186c2c66affSColin Finck             return STATUS_INSUFFICIENT_RESOURCES;
187c2c66affSColin Finck         }
188c2c66affSColin Finck 
189c2c66affSColin Finck         wcscpy(Buffer, DeviceText);
190c2c66affSColin Finck 
191c2c66affSColin Finck         /* save result */
192c2c66affSColin Finck         Irp->IoStatus.Information = (ULONG_PTR)Buffer;
193c2c66affSColin Finck         return STATUS_SUCCESS;
194c2c66affSColin Finck     }
195c2c66affSColin Finck 
196c2c66affSColin Finck }
197c2c66affSColin Finck 
198c2c66affSColin Finck NTSTATUS
HDA_PDOQueryBusDeviceCapabilities(IN PIRP Irp)199c2c66affSColin Finck HDA_PDOQueryBusDeviceCapabilities(
200c2c66affSColin Finck     IN PIRP Irp)
201c2c66affSColin Finck {
202c2c66affSColin Finck     PDEVICE_CAPABILITIES Capabilities;
203c2c66affSColin Finck     PIO_STACK_LOCATION IoStack;
204c2c66affSColin Finck 
205c2c66affSColin Finck     /* get stack location */
206c2c66affSColin Finck     IoStack = IoGetCurrentIrpStackLocation(Irp);
207c2c66affSColin Finck 
208c2c66affSColin Finck     /* get capabilities */
209c2c66affSColin Finck     Capabilities = IoStack->Parameters.DeviceCapabilities.Capabilities;
210c2c66affSColin Finck 
211c2c66affSColin Finck     RtlZeroMemory(Capabilities, sizeof(DEVICE_CAPABILITIES));
212c2c66affSColin Finck 
213c2c66affSColin Finck     /* setup capabilities */
214c2c66affSColin Finck     Capabilities->UniqueID = TRUE;
215c2c66affSColin Finck     Capabilities->SilentInstall = TRUE;
216c2c66affSColin Finck     Capabilities->SurpriseRemovalOK = TRUE;
217c2c66affSColin Finck     Capabilities->Address = 0;
218c2c66affSColin Finck     Capabilities->UINumber = 0;
219c2c66affSColin Finck     Capabilities->SystemWake = PowerSystemWorking; /* FIXME common device extension */
220c2c66affSColin Finck     Capabilities->DeviceWake = PowerDeviceD0;
221c2c66affSColin Finck 
222c2c66affSColin Finck     /* done */
223c2c66affSColin Finck     return STATUS_SUCCESS;
224c2c66affSColin Finck }
225c2c66affSColin Finck 
226c2c66affSColin Finck NTSTATUS
HDA_PDOQueryBusDevicePnpState(IN PIRP Irp)227c2c66affSColin Finck HDA_PDOQueryBusDevicePnpState(
228c2c66affSColin Finck     IN PIRP Irp)
229c2c66affSColin Finck {
230c2c66affSColin Finck     /* set device flags */
231c2c66affSColin Finck     Irp->IoStatus.Information = PNP_DEVICE_DONT_DISPLAY_IN_UI | PNP_DEVICE_NOT_DISABLEABLE;
232c2c66affSColin Finck 
233c2c66affSColin Finck     /* done */
234c2c66affSColin Finck     return STATUS_SUCCESS;
235c2c66affSColin Finck }
236c2c66affSColin Finck 
237