f9db2d7d6afcaa7846d32471eee92ee0aaddb0e2
[reactos.git] / drivers / usb / usbuhci_new / usbuhci.h
1 #ifndef USBUHCI_H__
2 #define USBUHCI_H__
3
4 #include <ntddk.h>
5 #include <windef.h>
6 #include <stdio.h>
7 #include <hubbusif.h>
8 #include <usbbusif.h>
9 #include <usbdlib.h>
10 #include <drivers/usbport/usbmport.h>
11 #include "hardware.h"
12
13 extern USBPORT_REGISTRATION_PACKET RegPacket;
14
15 #define UHCI_MAX_HC_SCHEDULE_ERRORS 16
16 #define UHCI_RH_STATUS_SUCCESS 1
17
18 #define UHCI_MAX_ISO_TRANSFER_SIZE 0x10000
19 #define UHCI_MAX_BULK_TRANSFER_SIZE 0x1000
20 //#define UHCI_MAX_BULK_TRANSFER_SIZE 0x10000 // Hack for testing w/o Split Transfers
21 #define UHCI_MAX_ISO_TD_COUNT 256
22 #define UHCI_MAX_INTERRUPT_TD_COUNT 8
23
24 /* Host Controller Driver Transfer Descriptor (HCD TD) */
25 #define UHCI_HCD_TD_FLAG_ALLOCATED 0x00000001
26 #define UHCI_HCD_TD_FLAG_PROCESSED 0x00000002
27 #define UHCI_HCD_TD_FLAG_DONE 0x00000008
28 #define UHCI_HCD_TD_FLAG_NOT_ACCESSED 0x00000010
29 #define UHCI_HCD_TD_FLAG_DATA_BUFFER 0x00000020
30 #define UHCI_HCD_TD_FLAG_GOOD_FRAME 0x00000040
31 #define UHCI_HCD_TD_FLAG_CONTROLL 0x00000400
32 #define UHCI_HCD_TD_FLAG_STALLED_SETUP 0x00000800
33
34 typedef struct _UHCI_ENDPOINT *PUHCI_ENDPOINT;
35 typedef struct _UHCI_TRANSFER *PUHCI_TRANSFER;
36
37 typedef struct _UHCI_HCD_TD {
38 /* Hardware */
39 UHCI_TD HwTD;
40 /* Software */
41 USB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
42 ULONG PhysicalAddress;
43 ULONG Flags;
44 struct _UHCI_HCD_TD * NextHcdTD;
45 _ANONYMOUS_UNION union {
46 PUHCI_TRANSFER UhciTransfer;
47 #if !defined(_M_X64)
48 ULONG Frame; // for SOF_HcdTDs only
49 #else
50 struct {
51 ULONG Frame;
52 ULONG Pad2;
53 };
54 #endif
55 } DUMMYUNIONNAME;
56 LIST_ENTRY TdLink;
57 #if !defined(_M_X64)
58 ULONG Padded[4];
59 #else
60 ULONG Padded[15];
61 #endif
62 } UHCI_HCD_TD, *PUHCI_HCD_TD;
63
64 #if !defined(_M_X64)
65 C_ASSERT(sizeof(UHCI_HCD_TD) == 0x40);
66 #else
67 C_ASSERT(sizeof(UHCI_HCD_TD) == 0x80);
68 #endif
69
70 /* Host Controller Driver Queue Header (HCD QH) */
71 #define UHCI_HCD_QH_FLAG_ACTIVE 0x00000001
72 #define UHCI_HCD_QH_FLAG_REMOVE 0x00000002
73
74 typedef struct _UHCI_HCD_QH {
75 /* Hardware */
76 UHCI_QH HwQH;
77 /* Software */
78 ULONG PhysicalAddress;
79 ULONG QhFlags;
80 struct _UHCI_HCD_QH * NextHcdQH;
81 #if !defined(_M_X64)
82 ULONG Pad1;
83 #endif
84 struct _UHCI_HCD_QH * PrevHcdQH;
85 #if !defined(_M_X64)
86 ULONG Pad2;
87 #endif
88 PUHCI_ENDPOINT UhciEndpoint;
89 #if !defined(_M_X64)
90 ULONG Pad3;
91 #endif
92 ULONG Padded[6];
93 } UHCI_HCD_QH, *PUHCI_HCD_QH;
94
95 C_ASSERT(sizeof(UHCI_HCD_QH) == 0x40);
96
97 #define UHCI_ENDPOINT_FLAG_HALTED 1
98 #define UHCI_ENDPOINT_FLAG_RESERVED 2
99 #define UHCI_ENDPOINT_FLAG_CONTROL_OR_ISO 4
100
101 /* UHCI Endpoint follows USBPORT Endpoint */
102 typedef struct _UHCI_ENDPOINT {
103 ULONG Flags;
104 LONG EndpointLock;
105 USBPORT_ENDPOINT_PROPERTIES EndpointProperties;
106 PUHCI_HCD_QH QH;
107 PUHCI_HCD_TD TailTD;
108 PUHCI_HCD_TD HeadTD;
109 PUHCI_HCD_TD FirstTD;
110 ULONG MaxTDs;
111 ULONG AllocatedTDs;
112 ULONG AllocTdCounter;
113 LIST_ENTRY ListTDs;
114 BOOL DataToggle;
115 } UHCI_ENDPOINT, *PUHCI_ENDPOINT;
116
117 /* UHCI Transfer follows USBPORT Transfer */
118 typedef struct _UHCI_TRANSFER {
119 PUSBPORT_TRANSFER_PARAMETERS TransferParameters;
120 PUHCI_ENDPOINT UhciEndpoint;
121 USBD_STATUS USBDStatus;
122 ULONG PendingTds;
123 SIZE_T TransferLen;
124 } UHCI_TRANSFER, *PUHCI_TRANSFER;
125
126 #define UHCI_FRAME_LIST_POINTER_VALID (0 << 0)
127 #define UHCI_FRAME_LIST_POINTER_TERMINATE (1 << 0)
128 #define UHCI_FRAME_LIST_POINTER_TD (0 << 1)
129 #define UHCI_FRAME_LIST_POINTER_QH (1 << 1)
130
131 #define UHCI_FRAME_LIST_INDEX_MASK 0x3FF
132 #define UHCI_MAX_STATIC_SOF_TDS 8
133
134 typedef struct _UHCI_HC_RESOURCES {
135 ULONG FrameList[UHCI_FRAME_LIST_MAX_ENTRIES]; // The 4-Kbyte Frame List Table is aligned on a 4-Kbyte boundary
136 UHCI_HCD_QH StaticIntHead[INTERRUPT_ENDPOINTs];
137 UHCI_HCD_QH StaticControlHead;
138 UHCI_HCD_QH StaticBulkHead;
139 UHCI_HCD_TD StaticBulkTD;
140 UHCI_HCD_TD StaticTD;
141 UHCI_HCD_TD StaticSofTD[UHCI_MAX_STATIC_SOF_TDS];
142 } UHCI_HC_RESOURCES, *PUHCI_HC_RESOURCES;
143
144 #define UHCI_EXTENSION_FLAG_SUSPENDED 0x00000002
145
146 /* UHCI Extension follows USBPORT Extension */
147 typedef struct _UHCI_EXTENSION {
148 PUHCI_HW_REGISTERS BaseRegister;
149 USB_CONTROLLER_FLAVOR HcFlavor;
150 PUHCI_HC_RESOURCES HcResourcesVA;
151 ULONG HcResourcesPA;
152 PUHCI_HCD_QH IntQH[INTERRUPT_ENDPOINTs];
153 PUHCI_HCD_QH ControlQH;
154 PUHCI_HCD_QH BulkQH;
155 PUHCI_HCD_QH BulkTailQH;
156 PUHCI_HCD_TD StaticTD;
157 PUHCI_HCD_TD SOF_HcdTDs; // pointer to array StaticSofTD[UHCI_MAX_STATIC_SOF_TDS]
158 ULONG FrameNumber;
159 ULONG FrameHighPart;
160 ULONG Flags;
161 LONG LockFrameList;
162 ULONG ResetPortMask;
163 ULONG ResetChangePortMask;
164 ULONG SuspendChangePortMask;
165 ULONG HcScheduleError;
166 LONG ExtensionLock;
167 UHCI_USB_STATUS StatusMask;
168 UHCI_USB_STATUS HcStatus;
169 UCHAR SOF_Modify;
170 UCHAR Padded2[3];
171 } UHCI_EXTENSION, *PUHCI_EXTENSION;
172
173 /* roothub.c */
174 VOID
175 NTAPI
176 UhciRHGetRootHubData(
177 IN PVOID uhciExtension,
178 IN PVOID rootHubData);
179
180 MPSTATUS
181 NTAPI
182 UhciRHGetStatus(
183 IN PVOID uhciExtension,
184 IN PUSHORT Status);
185
186 MPSTATUS
187 NTAPI
188 UhciRHGetPortStatus(
189 IN PVOID uhciExtension,
190 IN USHORT Port,
191 IN PUSB_PORT_STATUS_AND_CHANGE PortStatus);
192
193 MPSTATUS
194 NTAPI
195 UhciRHGetHubStatus(
196 IN PVOID uhciExtension,
197 IN PUSB_HUB_STATUS_AND_CHANGE HubStatus);
198
199 MPSTATUS
200 NTAPI
201 UhciRHSetFeaturePortReset(
202 IN PVOID uhciExtension,
203 IN USHORT Port);
204
205 MPSTATUS
206 NTAPI
207 UhciRHSetFeaturePortPower(
208 IN PVOID uhciExtension,
209 IN USHORT Port);
210
211 MPSTATUS
212 NTAPI
213 UhciRHSetFeaturePortEnable(
214 IN PVOID uhciExtension,
215 IN USHORT Port);
216
217 MPSTATUS
218 NTAPI
219 UhciRHSetFeaturePortSuspend(
220 IN PVOID uhciExtension,
221 IN USHORT Port);
222
223 MPSTATUS
224 NTAPI
225 UhciRHClearFeaturePortEnable(
226 IN PVOID uhciExtension,
227 IN USHORT Port);
228
229 MPSTATUS
230 NTAPI
231 UhciRHClearFeaturePortPower(
232 IN PVOID uhciExtension,
233 IN USHORT Port);
234
235 MPSTATUS
236 NTAPI
237 UhciRHClearFeaturePortSuspend(
238 IN PVOID uhciExtension,
239 IN USHORT Port);
240
241 MPSTATUS
242 NTAPI
243 UhciRHClearFeaturePortEnableChange(
244 IN PVOID uhciExtension,
245 IN USHORT Port);
246
247 MPSTATUS
248 NTAPI
249 UhciRHClearFeaturePortConnectChange(
250 IN PVOID uhciExtension,
251 IN USHORT Port);
252
253 MPSTATUS
254 NTAPI
255 UhciRHClearFeaturePortResetChange(
256 IN PVOID uhciExtension,
257 IN USHORT Port);
258
259 MPSTATUS
260 NTAPI
261 UhciRHClearFeaturePortSuspendChange(
262 IN PVOID uhciExtension,
263 IN USHORT Port);
264
265 MPSTATUS
266 NTAPI
267 UhciRHClearFeaturePortOvercurrentChange(
268 IN PVOID uhciExtension,
269 IN USHORT Port);
270
271 VOID
272 NTAPI
273 UhciRHDisableIrq(
274 IN PVOID uhciExtension);
275
276 VOID
277 NTAPI
278 UhciRHEnableIrq(
279 IN PVOID uhciExtension);
280
281 /* usbuhci.c */
282 VOID
283 NTAPI
284 UhciDisableInterrupts(
285 IN PVOID uhciExtension);
286
287 ULONG
288 NTAPI
289 UhciGet32BitFrameNumber(
290 IN PVOID uhciExtension);
291
292 BOOLEAN
293 NTAPI
294 UhciHardwarePresent(
295 IN PUHCI_EXTENSION UhciExtension);
296
297 #endif /* USBUHCI_H__ */