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