1c2c66affSColin Finck #pragma once 2c2c66affSColin Finck 3c2c66affSColin Finck #include <ntddk.h> 4c2c66affSColin Finck #include <initguid.h> 5c2c66affSColin Finck #include <hdaudio.h> 6c2c66affSColin Finck #include <stdio.h> 76ec38aa9SThomas Faber #include <ntstrsafe.h> 8c2c66affSColin Finck 931876ba8SSerge Gautherie // Include Haiku headers 10c2c66affSColin Finck #include "driver.h" 11c2c66affSColin Finck 12*2185848fSTimo Kreuzer #define NDEBUG 1331876ba8SSerge Gautherie #include <debug.h> 1431876ba8SSerge Gautherie 1531876ba8SSerge Gautherie #define TAG_HDA 'bADH' 1631876ba8SSerge Gautherie 17c2c66affSColin Finck #define MAKE_RATE(base, multiply, divide) \ 18c2c66affSColin Finck ((base == 44100 ? FORMAT_44_1_BASE_RATE : 0) \ 19c2c66affSColin Finck | ((multiply - 1) << FORMAT_MULTIPLY_RATE_SHIFT) \ 20c2c66affSColin Finck | ((divide - 1) << FORMAT_DIVIDE_RATE_SHIFT)) 21c2c66affSColin Finck 22c2c66affSColin Finck #define HDAC_INPUT_STREAM_OFFSET(index) \ 23c2c66affSColin Finck ((index) * HDAC_STREAM_SIZE) 24c2c66affSColin Finck #define HDAC_OUTPUT_STREAM_OFFSET(num_input_streams, index) \ 25c2c66affSColin Finck ((num_input_streams + (index)) * HDAC_STREAM_SIZE) 26c2c66affSColin Finck #define HDAC_BIDIR_STREAM_OFFSET(num_input_streams, num_output_streams, index) \ 27c2c66affSColin Finck ((num_input_streams + num_output_streams \ 28c2c66affSColin Finck + (index)) * HDAC_STREAM_SIZE) 29c2c66affSColin Finck 30c2c66affSColin Finck #define ALIGN(size, align) (((size) + align - 1) & ~(align - 1)) 31c2c66affSColin Finck 32c2c66affSColin Finck typedef struct { 33c2c66affSColin Finck ULONG response; 34c2c66affSColin Finck ULONG flags; 35c2c66affSColin Finck }RIRB_RESPONSE, *PRIRB_RESPONSE; 36c2c66affSColin Finck 37c2c66affSColin Finck typedef struct 38c2c66affSColin Finck { 39c2c66affSColin Finck PDEVICE_OBJECT ChildPDO; 40c2c66affSColin Finck ULONG FunctionGroup; 41c2c66affSColin Finck ULONG NodeId; 42c2c66affSColin Finck }HDA_CODEC_AUDIO_GROUP, *PHDA_CODEC_AUDIO_GROUP; 43c2c66affSColin Finck 44c2c66affSColin Finck typedef struct 45c2c66affSColin Finck { 46c2c66affSColin Finck USHORT VendorId; 47c2c66affSColin Finck USHORT ProductId; 48c2c66affSColin Finck UCHAR Major; 49c2c66affSColin Finck UCHAR Minor; 50c2c66affSColin Finck UCHAR Revision; 51c2c66affSColin Finck UCHAR Stepping; 52c2c66affSColin Finck UCHAR Addr; 53c2c66affSColin Finck 54c2c66affSColin Finck ULONG Responses[MAX_CODEC_RESPONSES]; 55c2c66affSColin Finck ULONG ResponseCount; 561001e608SThomas Faber KSEMAPHORE ResponseSemaphore; 57c2c66affSColin Finck 58c2c66affSColin Finck PHDA_CODEC_AUDIO_GROUP AudioGroups[HDA_MAX_AUDIO_GROUPS]; 59c2c66affSColin Finck ULONG AudioGroupCount; 60c2c66affSColin Finck 61c2c66affSColin Finck }HDA_CODEC_ENTRY, *PHDA_CODEC_ENTRY; 62c2c66affSColin Finck 63c2c66affSColin Finck typedef struct 64c2c66affSColin Finck { 65c2c66affSColin Finck BOOLEAN IsFDO; 66c2c66affSColin Finck PDEVICE_OBJECT LowerDevice; 67c2c66affSColin Finck 68c2c66affSColin Finck PUCHAR RegBase; 69c8c0fc8dSThomas Faber SIZE_T RegLength; 70c2c66affSColin Finck PKINTERRUPT Interrupt; 71c2c66affSColin Finck 72c2c66affSColin Finck ULONG CorbLength; 73c2c66affSColin Finck PULONG CorbBase; 74c2c66affSColin Finck ULONG RirbLength; 75c2c66affSColin Finck PRIRB_RESPONSE RirbBase; 76c2c66affSColin Finck ULONG RirbReadPos; 77c2c66affSColin Finck ULONG CorbWritePos; 78c2c66affSColin Finck PVOID StreamPositions; 79c2c66affSColin Finck 80c2c66affSColin Finck PHDA_CODEC_ENTRY Codecs[HDA_MAX_CODECS + 1]; 81c2c66affSColin Finck 82c2c66affSColin Finck }HDA_FDO_DEVICE_EXTENSION, *PHDA_FDO_DEVICE_EXTENSION; 83c2c66affSColin Finck 84c2c66affSColin Finck typedef struct 85c2c66affSColin Finck { 86c2c66affSColin Finck BOOLEAN IsFDO; 87584baf79SThomas Faber BOOLEAN ReportedMissing; 88c2c66affSColin Finck PHDA_CODEC_ENTRY Codec; 89c2c66affSColin Finck PHDA_CODEC_AUDIO_GROUP AudioGroup; 90c2c66affSColin Finck PDEVICE_OBJECT FDO; 91c2c66affSColin Finck }HDA_PDO_DEVICE_EXTENSION, *PHDA_PDO_DEVICE_EXTENSION; 92c2c66affSColin Finck 93c2c66affSColin Finck typedef struct { 94c2c66affSColin Finck ULONG device : 16; 95c2c66affSColin Finck ULONG vendor : 16; 96c2c66affSColin Finck ULONG stepping : 8; 97c2c66affSColin Finck ULONG revision : 8; 98c2c66affSColin Finck ULONG minor : 4; 99c2c66affSColin Finck ULONG major : 4; 100c2c66affSColin Finck ULONG _reserved0 : 8; 101c2c66affSColin Finck ULONG count : 8; 102c2c66affSColin Finck ULONG _reserved1 : 8; 103c2c66affSColin Finck ULONG start : 8; 104c2c66affSColin Finck ULONG _reserved2 : 8; 105c2c66affSColin Finck }CODEC_RESPONSE, *PCODEC_RESPONSE; 106c2c66affSColin Finck 107c2c66affSColin Finck PVOID 108c2c66affSColin Finck AllocateItem( 109c2c66affSColin Finck IN POOL_TYPE PoolType, 110c2c66affSColin Finck IN SIZE_T NumberOfBytes); 111c2c66affSColin Finck 112c2c66affSColin Finck VOID 113c2c66affSColin Finck FreeItem( 114c2c66affSColin Finck IN PVOID Item); 115c2c66affSColin Finck 116c2c66affSColin Finck /* fdo.cpp */ 11731876ba8SSerge Gautherie 1188530ae99SThomas Faber KSERVICE_ROUTINE HDA_InterruptService; 1198530ae99SThomas Faber IO_DPC_ROUTINE HDA_DpcForIsr; 120c2c66affSColin Finck 121c2c66affSColin Finck NTSTATUS 122c2c66affSColin Finck NTAPI 123c2c66affSColin Finck HDA_FDOStartDevice( 124c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject, 125c2c66affSColin Finck IN PIRP Irp); 126c2c66affSColin Finck 127c2c66affSColin Finck NTSTATUS 128c2c66affSColin Finck NTAPI 129c8c0fc8dSThomas Faber HDA_FDORemoveDevice( 130c8c0fc8dSThomas Faber _In_ PDEVICE_OBJECT DeviceObject, 131c8c0fc8dSThomas Faber _Inout_ PIRP Irp); 132c8c0fc8dSThomas Faber 133c8c0fc8dSThomas Faber NTSTATUS 134c8c0fc8dSThomas Faber NTAPI 135c2c66affSColin Finck HDA_FDOQueryBusRelations( 136c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject, 137c2c66affSColin Finck IN PIRP Irp); 138c2c66affSColin Finck 139af0f8581SVictor Perevertkin NTSTATUS 140c2c66affSColin Finck HDA_SendVerbs( 141c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject, 142c2c66affSColin Finck IN PHDA_CODEC_ENTRY Codec, 143c2c66affSColin Finck IN PULONG Verbs, 144c2c66affSColin Finck OUT PULONG Responses, 145c2c66affSColin Finck IN ULONG Count); 146c2c66affSColin Finck 147c2c66affSColin Finck /* pdo.cpp*/ 148c2c66affSColin Finck 149c2c66affSColin Finck NTSTATUS 150584baf79SThomas Faber HDA_PDORemoveDevice( 151584baf79SThomas Faber _In_ PDEVICE_OBJECT DeviceObject); 152584baf79SThomas Faber 153584baf79SThomas Faber NTSTATUS 154c2c66affSColin Finck HDA_PDOQueryBusInformation( 155c2c66affSColin Finck IN PIRP Irp); 156c2c66affSColin Finck 157c2c66affSColin Finck NTSTATUS 158c2c66affSColin Finck NTAPI 159c2c66affSColin Finck HDA_PDOQueryId( 160c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject, 161c2c66affSColin Finck IN PIRP Irp); 162c2c66affSColin Finck 163c2c66affSColin Finck NTSTATUS 164c2c66affSColin Finck HDA_PDOHandleQueryDeviceText( 165c2c66affSColin Finck IN PIRP Irp); 166c2c66affSColin Finck 167c2c66affSColin Finck NTSTATUS 168c2c66affSColin Finck HDA_PDOQueryBusDeviceCapabilities( 169c2c66affSColin Finck IN PIRP Irp); 170c2c66affSColin Finck 171c2c66affSColin Finck NTSTATUS 172c2c66affSColin Finck HDA_PDOQueryBusDevicePnpState( 173c2c66affSColin Finck IN PIRP Irp); 174c2c66affSColin Finck 175c2c66affSColin Finck /* businterface.cpp */ 176c2c66affSColin Finck 177c2c66affSColin Finck NTSTATUS 178c2c66affSColin Finck HDA_PDOHandleQueryInterface( 179c2c66affSColin Finck IN PDEVICE_OBJECT DeviceObject, 180c2c66affSColin Finck IN PIRP Irp); 181