1 /* 2 * PROJECT: ReactOS USB OHCI Miniport Driver 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: USBOHCI declarations 5 * COPYRIGHT: Copyright 2017-2018 Vadim Galyant <vgal@rambler.ru> 6 */ 7 8 #ifndef USBOHCI_H__ 9 #define USBOHCI_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 OHCI_HCD_ED_FLAG_CONTROL 0x00000001 23 #define OHCI_HCD_ED_FLAG_RESET_ON_HALT 0x00000008 24 #define OHCI_HCD_ED_FLAG_NOT_ACCESSED 0x00000010 25 26 #define OHCI_HCD_TD_FLAG_ALLOCATED 0x00000001 27 #define OHCI_HCD_TD_FLAG_PROCESSED 0x00000002 28 #define OHCI_HCD_TD_FLAG_CONTROL_STATUS 0x00000004 29 #define OHCI_HCD_TD_FLAG_DONE 0x00000008 30 #define OHCI_HCD_TD_FLAG_NOT_ACCESSED 0x00000010 31 32 #define OHCI_MAX_ISO_TRANSFER_SIZE 0x10000 33 #define OHCI_MAX_CONTROL_TRANSFER_SIZE 0x10000 34 #define OHCI_MAX_BULK_TRANSFER_SIZE 0x40000 35 #define OHCI_MAX_INTERRUPT_TRANSFER_SIZE 0x1000 36 37 #define OHCI_MAX_ISO_TD_COUNT 64 38 #define OHCI_MAX_CONTROL_TD_COUNT 38 39 #define OHCI_MAX_BULK_TD_COUNT 68 40 #define OHCI_MAX_INTERRUPT_TD_COUNT 4 41 42 #define OHCI_NON_DATA_CONTROL_TDS 2 43 44 #define OHCI_TRANSFER_FLAGS_SHORT_TRANSFER_OK 1 45 46 typedef struct _OHCI_TRANSFER *POHCI_TRANSFER; 47 48 typedef union DECLSPEC_ALIGN(32) _OHCI_HW_TRANSFER_DESCRIPTOR { 49 struct { 50 OHCI_TRANSFER_DESCRIPTOR gTD; // must be aligned to a 16-byte boundary 51 USB_DEFAULT_PIPE_SETUP_PACKET SetupPacket; 52 ULONG Padded[2]; 53 }; 54 struct { 55 OHCI_ISO_TRANSFER_DESCRIPTOR iTD; // must be aligned to a 32-byte boundary 56 }; 57 } OHCI_HW_TRANSFER_DESCRIPTOR, *POHCI_HW_TRANSFER_DESCRIPTOR; 58 59 C_ASSERT(sizeof(OHCI_HW_TRANSFER_DESCRIPTOR) == 32); 60 C_ASSERT(__alignof(OHCI_HW_TRANSFER_DESCRIPTOR) == 32); 61 62 typedef struct _OHCI_HCD_TD { 63 /* Hardware part */ 64 OHCI_HW_TRANSFER_DESCRIPTOR HwTD; // must be aligned to a 32-byte boundary 65 /* Software part */ 66 ULONG PhysicalAddress; 67 ULONG Flags; 68 POHCI_TRANSFER OhciTransfer; 69 struct _OHCI_HCD_TD *NextTDVa; 70 ULONG TransferLen; 71 LIST_ENTRY DoneLink; 72 ULONG Pad[1]; 73 } OHCI_HCD_TD, *POHCI_HCD_TD; 74 75 #ifdef _WIN64 76 C_ASSERT(sizeof(OHCI_HCD_TD) == 96); 77 #else 78 C_ASSERT(sizeof(OHCI_HCD_TD) == 64); 79 #endif 80 81 typedef struct _OHCI_HCD_ED { 82 /* Hardware part */ 83 OHCI_ENDPOINT_DESCRIPTOR HwED; // must be aligned to a 16-byte boundary 84 /* Software part */ 85 ULONG PhysicalAddress; 86 ULONG Flags; 87 LIST_ENTRY HcdEDLink; 88 #ifdef _WIN64 89 ULONG Pad[6]; 90 #else 91 ULONG Pad[8]; 92 #endif 93 } OHCI_HCD_ED, *POHCI_HCD_ED; 94 95 C_ASSERT(sizeof(OHCI_HCD_ED) == 64); 96 97 #define OHCI_STATIC_ED_TYPE_INTERRUPT 0 98 #define OHCI_STATIC_ED_TYPE_CONTROL 1 99 #define OHCI_STATIC_ED_TYPE_BULK 2 100 101 typedef struct _OHCI_STATIC_ED { 102 /* Software only */ 103 POHCI_ENDPOINT_DESCRIPTOR HwED; 104 ULONG PhysicalAddress; 105 UCHAR HeadIndex; 106 UCHAR Reserved[3]; 107 LIST_ENTRY Link; 108 ULONG Type; 109 PULONG pNextED; 110 ULONG HccaIndex; 111 } OHCI_STATIC_ED, *POHCI_STATIC_ED; 112 113 typedef struct _OHCI_HC_RESOURCES { 114 OHCI_HCCA HcHCCA; // (256 byte align) 115 OHCI_ENDPOINT_DESCRIPTOR InterrruptHeadED[63]; // (16 byte align) 116 OHCI_ENDPOINT_DESCRIPTOR ControlHeadED; // (16 byte align) 117 OHCI_ENDPOINT_DESCRIPTOR BulkHeadED; // (16 byte align) 118 } OHCI_HC_RESOURCES, *POHCI_HC_RESOURCES; 119 120 /* OHCI Endpoint follows USBPORT Endpoint */ 121 typedef struct _OHCI_ENDPOINT { 122 ULONG Reserved; 123 USBPORT_ENDPOINT_PROPERTIES EndpointProperties; 124 POHCI_STATIC_ED HeadED; 125 POHCI_HCD_TD FirstTD; 126 POHCI_HCD_ED HcdED; 127 ULONG MaxTransferDescriptors; 128 POHCI_HCD_TD HcdHeadP; 129 POHCI_HCD_TD HcdTailP; 130 LIST_ENTRY TDList; 131 } OHCI_ENDPOINT, *POHCI_ENDPOINT; 132 133 /* OHCI Transfer follows USBPORT Transfer */ 134 typedef struct _OHCI_TRANSFER { 135 ULONG Reserved; 136 ULONG TransferLen; 137 PUSBPORT_TRANSFER_PARAMETERS TransferParameters; 138 ULONG PendingTDs; 139 ULONG Flags; 140 USBD_STATUS USBDStatus; 141 POHCI_ENDPOINT OhciEndpoint; 142 POHCI_HCD_TD NextTD; 143 POHCI_HCD_TD ControlStatusTD; 144 } OHCI_TRANSFER, *POHCI_TRANSFER; 145 146 /* OHCI Extension follows USBPORT Extension */ 147 typedef struct _OHCI_EXTENSION { 148 ULONG Reserved; 149 POHCI_OPERATIONAL_REGISTERS OperationalRegs; 150 OHCI_REG_FRAME_INTERVAL FrameInterval; 151 ULONG FrameHighPart; 152 ULONG HcdFmNumber; 153 POHCI_HC_RESOURCES HcResourcesVA; 154 ULONG HcResourcesPA; 155 OHCI_STATIC_ED IntStaticED[63]; 156 OHCI_STATIC_ED ControlStaticED; 157 OHCI_STATIC_ED BulkStaticED; 158 } OHCI_EXTENSION, *POHCI_EXTENSION; 159 160 /* roothub.c */ 161 VOID 162 NTAPI 163 OHCI_RH_GetRootHubData( 164 IN PVOID ohciExtension, 165 IN PVOID rootHubData); 166 167 MPSTATUS 168 NTAPI 169 OHCI_RH_GetStatus( 170 IN PVOID ohciExtension, 171 IN PUSHORT Status); 172 173 MPSTATUS 174 NTAPI 175 OHCI_RH_GetPortStatus( 176 IN PVOID ohciExtension, 177 IN USHORT Port, 178 IN PUSB_PORT_STATUS_AND_CHANGE PortStatus); 179 180 MPSTATUS 181 NTAPI 182 OHCI_RH_GetHubStatus( 183 IN PVOID ohciExtension, 184 IN PUSB_HUB_STATUS_AND_CHANGE HubStatus); 185 186 MPSTATUS 187 NTAPI 188 OHCI_RH_SetFeaturePortReset( 189 IN PVOID ohciExtension, 190 IN USHORT Port); 191 192 MPSTATUS 193 NTAPI 194 OHCI_RH_SetFeaturePortPower( 195 IN PVOID ohciExtension, 196 IN USHORT Port); 197 198 MPSTATUS 199 NTAPI 200 OHCI_RH_SetFeaturePortEnable( 201 IN PVOID ohciExtension, 202 IN USHORT Port); 203 204 MPSTATUS 205 NTAPI 206 OHCI_RH_SetFeaturePortSuspend( 207 IN PVOID ohciExtension, 208 IN USHORT Port); 209 210 MPSTATUS 211 NTAPI 212 OHCI_RH_ClearFeaturePortEnable( 213 IN PVOID ohciExtension, 214 IN USHORT Port); 215 216 MPSTATUS 217 NTAPI 218 OHCI_RH_ClearFeaturePortPower( 219 IN PVOID ohciExtension, 220 IN USHORT Port); 221 222 MPSTATUS 223 NTAPI 224 OHCI_RH_ClearFeaturePortSuspend( 225 IN PVOID ohciExtension, 226 IN USHORT Port); 227 228 MPSTATUS 229 NTAPI 230 OHCI_RH_ClearFeaturePortEnableChange( 231 IN PVOID ohciExtension, 232 IN USHORT Port); 233 234 MPSTATUS 235 NTAPI 236 OHCI_RH_ClearFeaturePortConnectChange( 237 IN PVOID ohciExtension, 238 IN USHORT Port); 239 240 MPSTATUS 241 NTAPI 242 OHCI_RH_ClearFeaturePortResetChange( 243 IN PVOID ohciExtension, 244 IN USHORT Port); 245 246 MPSTATUS 247 NTAPI 248 OHCI_RH_ClearFeaturePortSuspendChange( 249 IN PVOID ohciExtension, 250 IN USHORT Port); 251 252 MPSTATUS 253 NTAPI 254 OHCI_RH_ClearFeaturePortOvercurrentChange( 255 IN PVOID ohciExtension, 256 IN USHORT Port); 257 258 VOID 259 NTAPI 260 OHCI_RH_DisableIrq( 261 IN PVOID ohciExtension); 262 263 VOID 264 NTAPI 265 OHCI_RH_EnableIrq( 266 IN PVOID ohciExtension); 267 268 OHCI_REG_RH_DESCRIPTORA 269 NTAPI 270 OHCI_ReadRhDescriptorA( 271 IN POHCI_EXTENSION OhciExtension); 272 273 #endif /* USBOHCI_H__ */ 274