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