xref: /reactos/drivers/wdm/audio/hdaudbus/pdo.cpp (revision 5100859e)
1 /*
2 * COPYRIGHT:       See COPYING in the top level directory
3 * PROJECT:         ReactOS Kernel Streaming
4 * FILE:            drivers/wdm/audio/hdaudbus/pdo.cpp
5 * PURPOSE:         HDA Driver Entry
6 * PROGRAMMER:      Johannes Anderwald
7 */
8 #include "hdaudbus.h"
9 
10 NTSTATUS
11 HDA_PDOQueryBusInformation(
12     IN PIRP Irp)
13 {
14     PPNP_BUS_INFORMATION BusInformation;
15 
16     /* allocate bus information */
17     BusInformation = (PPNP_BUS_INFORMATION)AllocateItem(PagedPool, sizeof(PNP_BUS_INFORMATION));
18 
19     if (!BusInformation)
20     {
21         /* no memory */
22         return STATUS_INSUFFICIENT_RESOURCES;
23     }
24 
25     /* return info */
26     BusInformation->BusNumber = 0;
27     BusInformation->LegacyBusType = PCIBus;
28     RtlMoveMemory(&BusInformation->BusTypeGuid, &GUID_HDAUDIO_BUS_INTERFACE, sizeof(GUID));
29 
30     /* store result */
31     Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
32 
33     /* done */
34     return STATUS_SUCCESS;
35 }
36 
37 
38 NTSTATUS
39 NTAPI
40 HDA_PDOQueryId(
41     IN PDEVICE_OBJECT DeviceObject,
42     IN PIRP Irp)
43 {
44     PIO_STACK_LOCATION IoStack;
45     WCHAR DeviceName[200];
46     PHDA_PDO_DEVICE_EXTENSION DeviceExtension;
47     ULONG Length;
48     LPWSTR Device;
49 
50     /* get device extension */
51     DeviceExtension = (PHDA_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
52     ASSERT(DeviceExtension->IsFDO == FALSE);
53 
54     /* get current irp stack location */
55     IoStack = IoGetCurrentIrpStackLocation(Irp);
56 
57     if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
58     {
59         UNIMPLEMENTED;
60 
61         // FIXME
62         swprintf(DeviceName, L"%08x", 1);
63         Length = wcslen(DeviceName) + 20;
64 
65         /* allocate result buffer*/
66         Device = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
67         if (!Device)
68             return STATUS_INSUFFICIENT_RESOURCES;
69 
70         swprintf(Device, L"%08x", 1);
71 
72         DPRINT1("ID: %S\n", Device);
73         /* store result */
74         Irp->IoStatus.Information = (ULONG_PTR)Device;
75         return STATUS_SUCCESS;
76     }
77     else if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID ||
78         IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
79     {
80 
81         /* calculate size */
82         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);
83         Length = wcslen(DeviceName) + 20;
84 
85         /* allocate result buffer*/
86         Device = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
87         if (!Device)
88             return STATUS_INSUFFICIENT_RESOURCES;
89 
90         wcscpy(Device, DeviceName);
91 
92         DPRINT1("ID: %S\n", Device);
93         /* store result */
94         Irp->IoStatus.Information = (ULONG_PTR)Device;
95         return STATUS_SUCCESS;
96     }
97     else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
98     {
99         RtlZeroMemory(DeviceName, sizeof(DeviceName));
100         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;
101         Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId) + 1;
102         Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X&VEN_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId) + 1;
103         Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X", DeviceExtension->AudioGroup->FunctionGroup) + 2;
104 
105         /* allocate result buffer*/
106         Device = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
107         if (!Device)
108             return STATUS_INSUFFICIENT_RESOURCES;
109 
110         RtlCopyMemory(Device, DeviceName, Length * sizeof(WCHAR));
111 
112         DPRINT1("ID: %S\n", Device);
113         /* store result */
114         Irp->IoStatus.Information = (ULONG_PTR)Device;
115         return STATUS_SUCCESS;
116     }
117     else
118     {
119         DPRINT1("QueryID Type %x not implemented\n", IoStack->Parameters.QueryId.IdType);
120         return Irp->IoStatus.Status;
121     }
122     return STATUS_NOT_IMPLEMENTED;
123 }
124 
125 NTSTATUS
126 HDA_PDOHandleQueryDeviceText(
127     IN PIRP Irp)
128 {
129     PIO_STACK_LOCATION IoStack;
130     LPWSTR Buffer;
131     static WCHAR DeviceText[] = L"Audio Device on High Definition Audio Bus";
132 
133     IoStack = IoGetCurrentIrpStackLocation(Irp);
134     if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription)
135     {
136         DPRINT("HDA_PdoHandleQueryDeviceText DeviceTextDescription\n");
137 
138         Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
139         if (!Buffer)
140         {
141             Irp->IoStatus.Information = 0;
142             return STATUS_INSUFFICIENT_RESOURCES;
143         }
144 
145         wcscpy(Buffer, DeviceText);
146 
147         Irp->IoStatus.Information = (ULONG_PTR)Buffer;
148         return STATUS_SUCCESS;
149     }
150     else
151     {
152         DPRINT("HDA_PdoHandleQueryDeviceText DeviceTextLocationInformation\n");
153 
154         Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
155         if (!Buffer)
156         {
157             Irp->IoStatus.Information = 0;
158             return STATUS_INSUFFICIENT_RESOURCES;
159         }
160 
161         wcscpy(Buffer, DeviceText);
162 
163         /* save result */
164         Irp->IoStatus.Information = (ULONG_PTR)Buffer;
165         return STATUS_SUCCESS;
166     }
167 
168 }
169 
170 NTSTATUS
171 HDA_PDOQueryBusDeviceCapabilities(
172     IN PIRP Irp)
173 {
174     PDEVICE_CAPABILITIES Capabilities;
175     PIO_STACK_LOCATION IoStack;
176 
177     /* get stack location */
178     IoStack = IoGetCurrentIrpStackLocation(Irp);
179 
180     /* get capabilities */
181     Capabilities = IoStack->Parameters.DeviceCapabilities.Capabilities;
182 
183     RtlZeroMemory(Capabilities, sizeof(DEVICE_CAPABILITIES));
184 
185     /* setup capabilities */
186     Capabilities->UniqueID = TRUE;
187     Capabilities->SilentInstall = TRUE;
188     Capabilities->SurpriseRemovalOK = TRUE;
189     Capabilities->Address = 0;
190     Capabilities->UINumber = 0;
191     Capabilities->SystemWake = PowerSystemWorking; /* FIXME common device extension */
192     Capabilities->DeviceWake = PowerDeviceD0;
193 
194     /* done */
195     return STATUS_SUCCESS;
196 }
197 
198 NTSTATUS
199 HDA_PDOQueryBusDevicePnpState(
200     IN PIRP Irp)
201 {
202     /* set device flags */
203     Irp->IoStatus.Information = PNP_DEVICE_DONT_DISPLAY_IN_UI | PNP_DEVICE_NOT_DISABLEABLE;
204 
205     /* done */
206     return STATUS_SUCCESS;
207 }
208 
209