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