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