Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1367 lines
46 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. openhci.h
  5. Abstract:
  6. This module contains the PRIVATE definitions for the
  7. code that implements the OpenHCI Host Controller Driver for USB.
  8. Environment:
  9. Kernel & user mode
  10. Revision History:
  11. 12-28-95 : created jfuller
  12. --*/
  13. #include "stdarg.h"
  14. #include "wdm.h"
  15. #include "usbdi.h"
  16. #include "hcdi.h"
  17. #include "usbdlibi.h"
  18. #include "usbdlib.h"
  19. #include "dbg.h"
  20. #ifndef OPENHCI_H
  21. #define OPENHCI_H
  22. // #define COMPAQ
  23. // #define NEC
  24. // #define CMD
  25. // #define NSC //National Semiconductor
  26. #define NEC_XXX
  27. #define DISABLE_INT_DELAY_NO_INT 0
  28. #define PREALLOCATE_DESCRIPTOR_MEMORY 1
  29. #define PREALLOCATE_DESCRIPTOR_MEMORY_NUM_PAGES 2
  30. #define RESOURCES_NOT_ON_IRP_STACK 0
  31. #ifdef PNP_POWER
  32. #define PnPEnabled() TRUE
  33. #else
  34. #define PnPEnabled() FALSE
  35. #endif /* PNP_POWER */
  36. #define HCD_PENDING_STATUS_SUBMITTING 0x40404001
  37. #define HCD_PENDING_STATUS_SUBMITTED 0x40404002
  38. #define HCD_PENDING_STATUS_QUEUED 0x40404003
  39. //
  40. // OpenHCI PCI Identification values
  41. //
  42. #define OpenHCI_PCI_BASE_CLASS 0x0C // base class is serial bus
  43. #define OpenHCI_PCI_SUB_CLASS 0x03 // sub class is USB
  44. #define OpenHCI_PCI_PROG_IF 0x10 // programming interface is OpenHCI
  45. //
  46. // Tag for memory allocations: 'OHCI'
  47. //
  48. #define OpenHCI_TAG 0x4943484F
  49. //
  50. // Eventually CacheCommon should determine if the platform snoops i/o cycles;
  51. // for now, just cache memory allocated by HalAllocateCommonBuffer
  52. #define CacheCommon TRUE
  53. //
  54. // Maximum length of name strings used in initialization code
  55. //
  56. #define NAME_MAX 256
  57. #define NAME_STRING L"\\Device\\USB#"
  58. /* 0 1234567 89012345 */
  59. #define NAME_NO_POS 11
  60. //
  61. // highest physical address we can use
  62. //
  63. #define OpenHCI_HIGHEST_ADDRESS 0x000000FFFFFFFF;
  64. //
  65. // Maximum frame and packet overhead
  66. //
  67. #define MAXIMUM_OVERHEAD 210
  68. #define OHCI_PAGE_SIZE 0x1000
  69. // #define OHCI_PAGE_SIZE 0x20
  70. #define OHCI_PAGE_SIZE_MASK (OHCI_PAGE_SIZE - 1)
  71. #if DBG
  72. #if !defined(FAKEPORTCHANGE)
  73. #define FAKEPORTCHANGE 1
  74. #endif
  75. #else
  76. #if !defined(FAKEPORTCHANGE)
  77. #define FAKEPORTCHANGE 0
  78. #endif
  79. #endif
  80. #ifdef MAX_DEBUG
  81. #define OHCI_DEFAULT_DEBUG_OUTPUT_LEVEL 0xFFFFFFFF
  82. #else
  83. //#define OHCI_DEFAULT_DEBUG_OUTPUT_LEVEL 0xFEAAFFEE // 0xF8A8888E
  84. #define OHCI_DEFAULT_DEBUG_OUTPUT_LEVEL 0x00000000
  85. #endif
  86. #define MIN(_A_,_B_) (((_A_) < (_B_)) ? (_A_) : (_B_))
  87. #define IoDecrementStackLocation(IRP) \
  88. (IRP)->CurrentLocation++; \
  89. (IRP)->Tail.Overlay.CurrentStackLocation++;
  90. #define IoCopyStackToNextStack(IRP) \
  91. { \
  92. PIO_STACK_LOCATION now, later; \
  93. now = IoGetCurrentIrpStackLocation (IRP); \
  94. later = IoGetNextIrpStackLocation (IRP); \
  95. later->Parameters = now->Parameters; \
  96. later->MajorFunction = now->MajorFunction; \
  97. later->MinorFunction = now->MinorFunction; \
  98. later->Flags = now->Flags; \
  99. }
  100. //
  101. // 7.1.1 HcRevision Register
  102. // Definition of Host Controller Revision register
  103. //
  104. typedef union _HC_REVISION {
  105. ULONG ul;
  106. struct {
  107. ULONG Rev:8;
  108. ULONG :24;
  109. };
  110. } HC_REVISION, *PHC_REVISION;
  111. //
  112. // 7.1.2 HcControl Register
  113. // Definition of Host Controller Control register
  114. //
  115. typedef union _HC_CONTROL {
  116. ULONG ul;
  117. struct {
  118. ULONG ControlBulkServiceRatio:2;
  119. ULONG PeriodicListEnable:1;
  120. ULONG IsochronousEnable:1;
  121. ULONG ControlListEnable:1;
  122. ULONG BulkListEnable:1;
  123. ULONG HostControllerFunctionalState:2;
  124. ULONG InterruptRouting:1;
  125. ULONG RemoteWakeupConnected:1;
  126. ULONG RemoteWakeupEnable:1;
  127. ULONG :21;
  128. };
  129. } HC_CONTROL, *PHC_CONTROL;
  130. #define HcCtrl_CBSR_MASK 0x00000003L
  131. #define HcCtrl_CBSR_1_to_1 0x00000000L
  132. #define HcCtrl_CBSR_2_to_1 0x00000001L
  133. #define HcCtrl_CBSR_3_to_1 0x00000002L
  134. #define HcCtrl_CBSR_4_to_1 0x00000003L
  135. #define HcCtrl_PeriodicListEnable 0x00000004L
  136. #define HcCtrl_IsochronousEnable 0x00000008L
  137. #define HcCtrl_ControlListEnable 0x00000010L
  138. #define HcCtrl_BulkListEnable 0x00000020L
  139. #define HcCtrl_ListEnableMask 0x00000038L
  140. #define HcCtrl_HCFS_MASK 0x000000C0L
  141. #define HcCtrl_HCFS_USBReset 0x00000000L
  142. #define HcCtrl_HCFS_USBResume 0x00000040L
  143. #define HcCtrl_HCFS_USBOperational 0x00000080L
  144. #define HcCtrl_HCFS_USBSuspend 0x000000C0L
  145. #define HcCtrl_InterruptRouting 0x00000100L
  146. #define HcCtrl_RemoteWakeupConnected 0x00000200L
  147. #define HcCtrl_RemoteWakeupEnable 0x00000400L
  148. #define HcHCFS_USBReset 0x00000000
  149. #define HcHCFS_USBResume 0x00000001
  150. #define HcHCFS_USBOperational 0x00000002
  151. #define HcHCFS_USBSuspend 0x00000003
  152. //
  153. // 7.1.3 HcCommandStatus Register
  154. // Definition of Host Controller Command/Status register
  155. //
  156. typedef union _HC_COMMAND_STATUS {
  157. ULONG ul; // use HcCmd flags below
  158. struct {
  159. ULONG HostControllerReset:1;
  160. ULONG ControlListFilled:1;
  161. ULONG BulkListFilled:1;
  162. ULONG OwnershipChangeRequest:1;
  163. ULONG :12;
  164. ULONG SchedulingOverrunCount:2;
  165. ULONG :14;
  166. };
  167. } HC_COMMAND_STATUS, *PHC_COMMAND_STATUS;
  168. #define HcCmd_HostControllerReset 0x00000001
  169. #define HcCmd_ControlListFilled 0x00000002
  170. #define HcCmd_BulkListFilled 0x00000004
  171. #define HcCmd_OwnershipChangeRequest 0x00000008
  172. #define HcCmd_SOC_Mask 0x00030000
  173. #define HcCmd_SOC_Offset 16
  174. #define HcCmd_SOC_Mask_LowBits 0x00000003
  175. //
  176. // 7.3.1 HcFmInterval Register
  177. // Definition of Host Controller Frame Interval register
  178. //
  179. typedef union _HC_FM_INTERVAL {
  180. ULONG ul; // use HcFmI flags below
  181. struct {
  182. ULONG FrameInterval:14;
  183. ULONG :2;
  184. ULONG FSLargestDataPacket:15;
  185. ULONG FrameIntervalToggle:1;
  186. };
  187. } HC_FM_INTERVAL, *PHC_FM_INTERVAL;
  188. #define HcFmI_FRAME_INTERVAL_MASK 0x00003FFF
  189. #define HcFmI_FS_LARGEST_DATA_PACKET_MASK 0x7FFF0000
  190. #define HcFmI_FS_LARGEST_DATA_PACKET_SHIFT 16
  191. #define HcFmI_FRAME_INTERVAL_TOGGLE 0x80000000
  192. //
  193. // 7.3.2 HcFmRemaining Register
  194. // Definition of Host Controller Frame Remaining register
  195. //
  196. typedef union _HC_FM_REMAINING {
  197. ULONG ul;
  198. struct {
  199. ULONG FrameRemaining:14;
  200. ULONG :17;
  201. ULONG FrameRemainingToggle:1;
  202. };
  203. } HC_FM_REMAINING, *PHC_FM_REMAINING;
  204. //
  205. // 7.4.1 HcRhDescriptorA Register
  206. // Definition of Host Controller Root Hub DescriptorA register
  207. //
  208. typedef union _HC_RH_DESCRIPTOR_A {
  209. ULONG ul;
  210. struct {
  211. ULONG NumberDownstreamPorts:8;
  212. ULONG PowerSwitchingMode:1;
  213. ULONG NoPowerSwitching:1;
  214. ULONG :1;
  215. ULONG OverCurrentProtectionMode:1;
  216. ULONG NoOverCurrentProtection:1;
  217. ULONG :11;
  218. ULONG PowerOnToPowerGoodTime:8;
  219. };
  220. } HC_RH_DESCRIPTOR_A, *PHC_RH_DESCRIPTOR_A;
  221. //
  222. // 7.4.2 HcRhDescriptorB Register
  223. // Definition of Host Controller Root Hub DescritorB register
  224. //
  225. typedef union _HC_RH_DESCRIPTOR_B {
  226. ULONG ul;
  227. struct {
  228. USHORT DeviceRemovableMask;
  229. USHORT PortPowerControlMask;
  230. };
  231. } HC_RH_DESCRIPTOR_B, *PHC_RH_DESCRIPTOR_B;
  232. //
  233. // Host Controler Hardware Registers as accessed in memory
  234. //
  235. typedef struct _HC_OPERATIONAL_REGISTER {
  236. // 0 0x00 - 0,4,8,c
  237. HC_REVISION HcRevision;
  238. HC_CONTROL HcControl;
  239. HC_COMMAND_STATUS HcCommandStatus;
  240. ULONG HcInterruptStatus; // use HcInt flags below
  241. // 1 0x10
  242. ULONG HcInterruptEnable; // use HcInt flags below
  243. ULONG HcInterruptDisable; // use HcInt flags below
  244. ULONG HcHCCA; // physical pointer to Host Controller Communications Area
  245. ULONG HcPeriodCurrentED; // physical ptr to current periodic ED
  246. // 2 0x20
  247. ULONG HcControlHeadED; // physical ptr to head of control list
  248. ULONG HcControlCurrentED; // physical ptr to current control ED
  249. ULONG HcBulkHeadED; // physical ptr to head of bulk list
  250. ULONG HcBulkCurrentED; // physical ptr to current bulk ED
  251. // 3 0x30
  252. ULONG HcDoneHead; // physical ptr to internal done queue
  253. HC_FM_INTERVAL HcFmInterval;
  254. HC_FM_REMAINING HcFmRemaining;
  255. ULONG HcFmNumber;
  256. // 4 0x40
  257. ULONG HcPeriodicStart;
  258. ULONG HcLSThreshold;
  259. HC_RH_DESCRIPTOR_A HcRhDescriptorA;
  260. HC_RH_DESCRIPTOR_B HcRhDescriptorB;
  261. // 5 0x50
  262. ULONG HcRhStatus; // use HcRhS flags below
  263. ULONG HcRhPortStatus[15]; // use HcRhPS flags below
  264. } HC_OPERATIONAL_REGISTER, *PHC_OPERATIONAL_REGISTER;
  265. //
  266. // 7.1.4 HcInterrruptStatus Register
  267. // 7.1.5 HcInterruptEnable Register
  268. // 7.1.6 HcInterruptDisable Register
  269. //
  270. #define HcInt_SchedulingOverrun 0x00000001L
  271. #define HcInt_WritebackDoneHead 0x00000002L
  272. #define HcInt_StartOfFrame 0x00000004L
  273. #define HcInt_ResumeDetected 0x00000008L
  274. #define HcInt_UnrecoverableError 0x00000010L
  275. #define HcInt_FrameNumberOverflow 0x00000020L
  276. #define HcInt_RootHubStatusChange 0x00000040L
  277. #define HcInt_OwnershipChange 0x40000000L
  278. #define HcInt_MasterInterruptEnable 0x80000000L
  279. //
  280. // 7.4.3 HcRhStatus Register
  281. //
  282. #define HcRhS_LocalPowerStatus 0x00000001 // read only
  283. #define HcRhS_OverCurrentIndicator 0x00000002 // read only
  284. #define HcRhS_DeviceRemoteWakeupEnable 0x00008000 // read only
  285. #define HcRhS_LocalPowerStatusChange 0x00010000 // read only
  286. #define HcRhS_OverCurrentIndicatorChange 0x00020000 // read only
  287. #define HcRhS_ClearGlobalPower 0x00000001 // write only
  288. #define HcRhS_SetRemoteWakeupEnable 0x00008000 // write only
  289. #define HcRhS_SetGlobalPower 0x00010000 // write only
  290. #define HcRhS_ClearOverCurrentIndicatorChange 0x00020000 // write only
  291. #define HcRhS_ClearRemoteWakeupEnable 0x80000000 // write only
  292. //
  293. // 7.4.4 HcRhPortStatus Register
  294. //
  295. #define HcRhPS_CurrentConnectStatus 0x00000001 // read only
  296. #define HcRhPS_PortEnableStatus 0x00000002 // read only
  297. #define HcRhPS_PortSuspendStatus 0x00000004 // read only
  298. #define HcRhPS_PortOverCurrentIndicator 0x00000008 // read only
  299. #define HcRhPS_PortResetStatus 0x00000010 // read only
  300. #define HcRhPS_PortPowerStatus 0x00000100 // read only
  301. #define HcRhPS_LowSpeedDeviceAttached 0x00000200 // read only
  302. #define HcRhPS_ConnectStatusChange 0x00010000 // read only
  303. #define HcRhPS_PortEnableStatusChange 0x00020000 // read only
  304. #define HcRhPS_PortSuspendStatusChange 0x00040000 // read only
  305. #define HcRhPS_OverCurrentIndicatorChange 0x00080000 // read only
  306. #define HcRhPS_PortResetStatusChange 0x00100000 // read only
  307. #define HcRhPS_ClearPortEnable 0x00000001 // write only
  308. #define HcRhPS_SetPortEnable 0x00000002 // write only
  309. #define HcRhPS_SetPortSuspend 0x00000004 // write only
  310. #define HcRhPS_ClearPortSuspend 0x00000008 // write only
  311. #define HcRhPS_SetPortReset 0x00000010 // write only
  312. #define HcRhPS_SetPortPower 0x00000100 // write only
  313. #define HcRhPS_ClearPortPower 0x00000200 // write only
  314. #define HcRhPS_ClearConnectStatusChange 0x00010000 // write only
  315. #define HcRhPS_ClearPortEnableStatusChange 0x00020000 // write only
  316. #define HcRhPS_ClearPortSuspendStatusChange 0x00040000 // write only
  317. #define HcRhPS_ClearPortOverCurrentChange 0x00080000 // write only
  318. #define HcRhPS_ClearPortResetStatusChange 0x00100000 // write only
  319. #define HcRhPS_RESERVED (~(HcRhPS_CurrentConnectStatus | \
  320. HcRhPS_PortEnableStatus | \
  321. HcRhPS_PortSuspendStatus | \
  322. HcRhPS_PortOverCurrentIndicator | \
  323. HcRhPS_PortResetStatus | \
  324. HcRhPS_PortPowerStatus | \
  325. HcRhPS_LowSpeedDeviceAttached | \
  326. HcRhPS_ConnectStatusChange | \
  327. HcRhPS_PortEnableStatusChange | \
  328. HcRhPS_PortSuspendStatusChange | \
  329. HcRhPS_OverCurrentIndicatorChange | \
  330. HcRhPS_PortResetStatusChange \
  331. ))
  332. //
  333. // Host Controller Communications Area
  334. //
  335. typedef struct _HCCA_BLOCK {
  336. ULONG HccaInterruptTable[32]; // physical pointer to interrupt lists
  337. USHORT HccaFrameNumber; // 16-bit current frame number
  338. USHORT HccaPad1; // When the HC updates
  339. // HccaFrameNumber, it sets
  340. // this word to zero.
  341. ULONG HccaDoneHead; // pointer to done queue
  342. ULONG Reserved[30]; // pad to 256 bytes
  343. } HCCA_BLOCK, *PHCCA_BLOCK;
  344. C_ASSERT(sizeof(HCCA_BLOCK) == 256);
  345. #define HCCADoneHead_INT_FLAG 0x00000001 // bit set if other ints pending
  346. //
  347. // Host Controller Endpoint Descriptor Control DWORD
  348. //
  349. typedef union _HC_ENDPOINT_CONTROL {
  350. ULONG Control; // use HcEDControl flags below
  351. struct {
  352. ULONG FunctionAddress:7;
  353. ULONG EndpointNumber:4;
  354. ULONG Direction:2; // use HcEDDirection flags below
  355. ULONG LowSpeed:1;
  356. ULONG sKip:1;
  357. ULONG Isochronous:1;
  358. ULONG MaxPacket:11;
  359. ULONG Unused:5; //available for software use
  360. };
  361. } HC_ENDPOINT_CONTROL, *PHC_ENDPOINT_CONTROL;
  362. //
  363. // Definitions for HC_ENDPOINT_CONTROL.Control
  364. //
  365. #define HcEDControl_MPS_MASK 0x07FF0000 // Maximum Packet Size field
  366. #define HcEDControl_MPS_SHIFT 16 // Shift Count for MPS
  367. #define HcEDControl_ISOCH 0x00008000 // Bit set for isochronous endpoints
  368. #define HcEDControl_SKIP 0x00004000 // Bit tells hw to skip this endpoint
  369. #define HcEDControl_LOWSPEED 0x00002000 // Bit set if device is a low speed device
  370. #define HcEDControl_DIR_MASK 0x00001800 // Transfer direction field
  371. #define HcEDControl_DIR_DEFER 0x00000000 // Defer direction select to TD (Control Endpoints)
  372. #define HcEDControl_DIR_OUT 0x00000800 // Direction is from host to device
  373. #define HcEDControl_DIR_IN 0x00001000 // Direction is from device to host
  374. #define HcEDControl_EN_MASK 0x00000780 // Endpoint Number field
  375. #define HcEDControl_EN_SHIFT 7 // Shift Count for EN
  376. #define HcEDControl_FA_MASK 0x0000007F // Function Address field
  377. #define HcEDControl_FA_SHIFT 0 // Shift Count for FA
  378. //
  379. // Definitions for HC_ENDPOINT_CONTROL.Direction
  380. //
  381. #define HcEDDirection_Defer 0 // Defer direction to TD (Control Endpoints)
  382. #define HcEDDirection_Out 1 // Direction from host to device
  383. #define HcEDDirection_In 2 // Direction from device to host
  384. //
  385. // Host Controller Endpoint Descriptor, refer to Section 4.2, Endpoint Descriptor
  386. //
  387. typedef struct _HC_ENDPOINT_DESCRIPTOR {
  388. HC_ENDPOINT_CONTROL; // dword 0
  389. ULONG TailP; //physical pointer to HC_TRANSFER_DESCRIPTOR
  390. volatile ULONG HeadP; //flags + phys ptr to HC_TRANSFER_DESCRIPTOR
  391. ULONG NextED; //phys ptr to HC_ENDPOINT_DESCRIPTOR
  392. } HC_ENDPOINT_DESCRIPTOR, *PHC_ENDPOINT_DESCRIPTOR;
  393. C_ASSERT(sizeof(HC_ENDPOINT_DESCRIPTOR) == 16);
  394. //
  395. // Definitions for HC_ENDPOINT_DESCRIPTOR.HeadP
  396. //
  397. #define HcEDHeadP_FLAGS 0x0000000F //mask for flags in HeadP
  398. #define HcEDHeadP_HALT 0x00000001 //hardware stopped bit
  399. #define HcEDHeadP_CARRY 0x00000002 //hardware toggle carry bit
  400. //
  401. // HCD Isochronous offset/status words
  402. //
  403. typedef union _HC_OFFSET_PSW {
  404. struct {
  405. USHORT Offset:13; // Offset within two pages of packet buffer
  406. USHORT Ones:3; // should be 111b when in Offset format
  407. };
  408. struct {
  409. USHORT Size:11; // Size of packet received
  410. USHORT :1; // reserved
  411. USHORT ConditionCode:4; // use HcCC flags below
  412. };
  413. USHORT PSW; // use HcPSW flags below
  414. } HC_OFFSET_PSW, *PHC_OFFSET_PSW;
  415. //
  416. // Definitions for HC_OFFSET_PSW.PSW
  417. //
  418. #define HcPSW_OFFSET_MASK 0x0FFF // Packet buffer offset field
  419. #define HcPSW_SECOND_PAGE 0x1000 // Is this packet on 2nd page
  420. #define HcPSW_ONES 0xE000 // The ones for Offset form
  421. #define HcPSW_CONDITION_CODE_MASK 0xF000 // Packet ConditionCode field
  422. #define HcPSW_CONDITION_CODE_SHIFT 12 // shift count for Code
  423. #define HcPSW_RETURN_SIZE 0x07FF // The size field.
  424. //
  425. // HCD Transfer Descriptor Control DWord
  426. //
  427. typedef union _HC_TRANSFER_CONTROL {
  428. ULONG Control; // use HcTDControl flags below
  429. struct _HC_GENERAL_TD_CONTROL{
  430. ULONG :16; // available for s/w use in GTD
  431. ULONG IsochFlag:1; // should be 0 for GTD, s/w flag
  432. ULONG :1; // available for s/w use
  433. ULONG ShortXferOk:1; // if set don't report error on short transfer
  434. ULONG Direction:2; // use HcTDDirection flags below
  435. ULONG IntDelay:3; // use HcTDIntDelay flags below
  436. ULONG Toggle:2; // use HcTDToggle flags below
  437. ULONG ErrorCount:2;
  438. ULONG ConditionCode:4; // use HcCC flags below
  439. };
  440. struct _HC_ISOCHRONOUS_TD_CONTROL{
  441. ULONG StartingFrame:16;
  442. ULONG Isochronous:1; // should be 1 for ITD, s/w flag
  443. ULONG :1; // available for s/w use
  444. ULONG :3; // available for s/w use in ITD
  445. ULONG :3; // IntDelay
  446. ULONG FrameCount:3; // one less than number of frames described in ITD
  447. ULONG :1; // available for s/w use in ITD
  448. ULONG :4; // ConditionCode
  449. };
  450. } HC_TRANSFER_CONTROL, *PHC_TRANSFER_CONTROL;
  451. //
  452. // Definitions for HC_TRANSFER_CONTROL.Control
  453. //
  454. #define HcTDControl_STARTING_FRAME 0x0000FFFF // mask for starting frame (Isochronous)
  455. #define HcTDControl_ISOCHRONOUS 0x00010000 // 1 for Isoch TD, 0 for General TD
  456. #define HcTDControl_SHORT_XFER_OK 0x00040000 // 0 if short transfers are errors
  457. #define HcTDControl_DIR_MASK 0x00180000 // Transfer direction field
  458. #define HcTDControl_DIR_SETUP 0x00000000 // direction is setup packet from host to device
  459. #define HcTDControl_DIR_OUT 0x00080000 // direction is from host to device
  460. #define HcTDControl_DIR_IN 0x00100000 // direction is from device to host
  461. #define HcTDControl_INT_DELAY_MASK 0x00E00000 // Interrupt Delay field
  462. #define HcTDControl_INT_DELAY_0_MS 0x00000000 // Interrupt at end of frame TD is completed
  463. #define HcTDControl_INT_DELAY_1_MS 0x00200000 // Interrupt no later than end of 1st frame after TD is completed
  464. #define HcTDControl_INT_DELAY_2_MS 0x00400000 // Interrupt no later than end of 2nd frame after TD is completed
  465. #define HcTDControl_INT_DELAY_3_MS 0x00600000 // Interrupt no later than end of 3rd frame after TD is completed
  466. #define HcTDControl_INT_DELAY_4_MS 0x00800000 // Interrupt no later than end of 4th frame after TD is completed
  467. #define HcTDControl_INT_DELAY_5_MS 0x00A00000 // Interrupt no later than end of 5th frame after TD is completed
  468. #define HcTDControl_INT_DELAY_6_MS 0x00C00000 // Interrupt no later than end of 6th frame after TD is completed
  469. #ifdef NSC
  470. #define HcTDControl_INT_DELAY_NO_INT 0x00C00000 // Almost infinity but not yet quite.
  471. #elif DISABLE_INT_DELAY_NO_INT
  472. #define HcTDControl_INT_DELAY_NO_INT 0x00000000 // Interrupt at the completion of all packets.
  473. #else
  474. #define HcTDControl_INT_DELAY_NO_INT 0x00E00000 // Do not cause an interrupt for normal completion of this TD
  475. #endif
  476. #define HcTDControl_FRAME_COUNT_MASK 0x07000000 // mask for FrameCount field (Isochronous)
  477. #define HcTDControl_FRAME_COUNT_SHIFT 24 // shift count for FrameCount (Isochronous)
  478. #define HcTDControl_FRAME_COUNT_MAX 8 // Max number of for frame count per TD
  479. #define HcTDControl_TOGGLE_MASK 0x03000000 // mask for Toggle control field
  480. #define HcTDControl_TOGGLE_FROM_ED 0x00000000 // get data toggle from CARRY field of ED
  481. #define HcTDControl_TOGGLE_DATA0 0x02000000 // use DATA0 for data PID
  482. #define HcTDControl_TOGGLE_DATA1 0x03000000 // use DATA1 for data PID
  483. #define HcTDControl_ERROR_COUNT 0x0C000000 // mask for Error Count field
  484. #define HcTDControl_CONDITION_CODE_MASK 0xF0000000 // mask for ConditionCode field
  485. #define HcTDControl_CONDITION_CODE_SHIFT 28 // shift count for ConditionCode
  486. //
  487. // Definitions for HC_TRANSFER_CONTROL.Direction
  488. //
  489. #define HcTDDirection_Setup 0 // setup packet from host to device
  490. #define HcTDDirection_Out 1 // direction from host to device
  491. #define HcTDDirection_In 2 // direction from device to host
  492. //
  493. // Definitions for Hc_TRANSFER_CONTROL.IntDelay
  494. //
  495. #define HcTDIntDelay_0ms 0 // interrupt at end of frame TD is completed
  496. #define HcTDIntDelay_1ms 1 // Interrupt no later than end of 1st frame after TD is completed
  497. #define HcTDIntDelay_2ms 2 // Interrupt no later than end of 2nd frame after TD is completed
  498. #define HcTDIntDelay_3ms 3 // Interrupt no later than end of 3rd frame after TD is completed
  499. #define HcTDIntDelay_4ms 4 // Interrupt no later than end of 4th frame after TD is completed
  500. #define HcTDIntDelay_5ms 5 // Interrupt no later than end of 5th frame after TD is completed
  501. #define HcTDIntDelay_6ms 6 // Interrupt no later than end of 6th frame after TD is completed
  502. #define HcTDIntDelay_NoInterrupt 7 // do not generate interrupt for normal completion of this TD
  503. //
  504. // Definitions for HC_TRANSFER_CONTROL.Toggle
  505. //
  506. #define HcTDToggle_FromEd 0 // get toggle for Endpoint Descriptor toggle CARRY bit
  507. #define HcTDToggle_Data0 2 // use Data0 PID
  508. #define HcTDToggle_Data1 3 // use Data1 PID
  509. //
  510. // Definitions for HC_TRANSFER_CONTROL.ConditionCode and HC_OFFSET_PSW.ConditionCode
  511. //
  512. #define HcCC_NoError 0x0UL
  513. #define HcCC_CRC 0x1UL
  514. #define HcCC_BitStuffing 0x2UL
  515. #define HcCC_DataToggleMismatch 0x3UL
  516. #define HcCC_Stall 0x4UL
  517. #define HcCC_DeviceNotResponding 0x5UL
  518. #define HcCC_PIDCheckFailure 0x6UL
  519. #define HcCC_UnexpectedPID 0x7UL
  520. #define HcCC_DataOverrun 0x8UL
  521. #define HcCC_DataUnderrun 0x9UL
  522. // 0xA // reserved
  523. // 0xB // reserved
  524. #define HcCC_BufferOverrun 0xCUL
  525. #define HcCC_BufferUnderrun 0xDUL
  526. #define HcCC_NotAccessed 0xEUL
  527. // 0xF // this also means NotAccessed
  528. //
  529. // Host Controller Transfer Descriptor, refer to Section 4.3, Transfer Descriptors
  530. //
  531. typedef struct _HC_TRANSFER_DESCRIPTOR {
  532. HC_TRANSFER_CONTROL; // dword 0
  533. ULONG CBP; // phys ptr to start of buffer
  534. ULONG NextTD; // phys ptr to HC_TRANSFER_DESCRIPTOR
  535. ULONG BE; // phys ptr to end of buffer (last byte)
  536. HC_OFFSET_PSW Packet[8]; // isoch & Control packets
  537. } HC_TRANSFER_DESCRIPTOR, *PHC_TRANSFER_DESCRIPTOR;
  538. //
  539. // HCD Endpoint Descriptor
  540. //
  541. typedef struct _HCD_ENDPOINT_DESCRIPTOR {
  542. HC_ENDPOINT_DESCRIPTOR HcED;
  543. ULONG Pad[4]; // make Physical Address the same as in HCD_TRANSFER_DESCRIPTOR
  544. ULONG PhysicalAddress;
  545. UCHAR ListIndex;
  546. UCHAR PauseFlag;
  547. UCHAR Flags;
  548. UCHAR Reserved[1]; // fill out to 64 bytes
  549. LIST_ENTRY Link;
  550. struct _HCD_ENDPOINT *Endpoint;
  551. ULONG ReclamationFrame;
  552. LIST_ENTRY PausedLink;
  553. #ifdef _WIN64
  554. ULONG Pad24[9]; // file out to 128 bytes
  555. #endif
  556. } HCD_ENDPOINT_DESCRIPTOR, *PHCD_ENDPOINT_DESCRIPTOR;
  557. C_ASSERT((sizeof(HCD_ENDPOINT_DESCRIPTOR) == 64) ||
  558. (sizeof(HCD_ENDPOINT_DESCRIPTOR) == 128));
  559. // Values for HCD_ENDPOINT_DESCRIPTOR->PauseFlag
  560. //
  561. // Used by:
  562. //
  563. // OpenHCI_CancelTDsForED()
  564. // OpenHCI_PauseED()
  565. // OpenHCI_CloseEndpoint()
  566. //
  567. // Normal state. If the endpoint is in this state, OpenHCI_PauseED()
  568. // will set the endpoint sKip bit, else the sKip bit is already set.
  569. //
  570. #define HCD_ED_PAUSE_NOT_PAUSED 0
  571. // Set when OpenHCI_PauseED() is called, which is called either by
  572. // OpenHCI_CancelTransfer() or by OpenHCI_AbortEndpoint().
  573. //
  574. #define HCD_ED_PAUSE_NEEDED 1
  575. // Set when OpenHCI_CancelTDsForED() starts running. If the endpoint is
  576. // still in this state after OpenHCI_CancelTDsForED() has made a pass through
  577. // all of the requests queued on the endpoint, the pause is complete and
  578. // the state is set back to HCD_ED_PAUSE_NOT_PAUSED and the sKip is cleared.
  579. // Else the state is set back to HCD_ED_PAUSE_PROCESSING again and another
  580. // pass is made through all of the requests queued on the endpoints.
  581. //
  582. #define HCD_ED_PAUSE_PROCESSING 2
  583. //
  584. // HCD Transfer Descriptor
  585. //
  586. //
  587. // HCD_TRANSFER_DESCRIPTOR and HCD_ENDPOINT_DESCRIPTOR structures are
  588. // allocated from a common pool and share the Flags field.
  589. //
  590. #define TD_FLAG_INUSE 0x01 // Indicates that the structure is allocated
  591. #define TD_FLAG_IS_ED 0x80 // Indicates that the structure is an ED
  592. // This structure MUST be exactly 64 or 128 bytes long
  593. // we use 128 byte EDs for the 64 bit platform
  594. typedef struct _HCD_TRANSFER_DESCRIPTOR {
  595. HC_TRANSFER_DESCRIPTOR HcTD; /* first 16 bytes */
  596. ULONG PhysicalAddress;
  597. UCHAR BaseIsocURBOffset;
  598. BOOLEAN Canceled;
  599. UCHAR Flags;
  600. UCHAR Reserved[1]; // fill out to 64 bytes
  601. LIST_ENTRY RequestList; /* list of TDs for a req */
  602. struct _HCD_TRANSFER_DESCRIPTOR *NextHcdTD;
  603. PHCD_URB UsbdRequest;
  604. struct _HCD_ENDPOINT *Endpoint;
  605. ULONG TransferCount;
  606. #ifdef _WIN64
  607. ULONG64 _SortNext;
  608. ULONG Pad22[8]; // fill out to 128 bytes
  609. #endif
  610. } HCD_TRANSFER_DESCRIPTOR, *PHCD_TRANSFER_DESCRIPTOR;
  611. C_ASSERT((sizeof(HCD_TRANSFER_DESCRIPTOR) == 64) ||
  612. (sizeof(HCD_TRANSFER_DESCRIPTOR) == 128));
  613. C_ASSERT(sizeof(HCD_ENDPOINT_DESCRIPTOR) == sizeof(HCD_TRANSFER_DESCRIPTOR));
  614. C_ASSERT(FIELD_OFFSET(HCD_ENDPOINT_DESCRIPTOR, PhysicalAddress) ==
  615. FIELD_OFFSET(HCD_TRANSFER_DESCRIPTOR, PhysicalAddress));
  616. C_ASSERT(FIELD_OFFSET(HCD_ENDPOINT_DESCRIPTOR, Flags) ==
  617. FIELD_OFFSET(HCD_TRANSFER_DESCRIPTOR, Flags));
  618. #ifdef _WIN64
  619. #define SortNext _SortNext
  620. #else
  621. #define SortNext HcTD.NextTD
  622. #endif
  623. //
  624. // HCD Endpoint control structure
  625. //
  626. // set when ep is closed successfully
  627. #define EP_CLOSED 0x00000001
  628. // set to if the root hub code owns this ep
  629. #define EP_ROOT_HUB 0x00000002
  630. // need to abort all transfers for this endpoint
  631. #define EP_ABORT 0x00000004
  632. // endpoint needs to be freed
  633. #define EP_FREE 0x00000008
  634. // endpoint has had no transfers submitted,
  635. // restored on reset
  636. #define EP_VIRGIN 0x00000020
  637. // limit endpoint to one outstanding TD
  638. #define EP_ONE_TD 0x00000040
  639. // in active list
  640. #define EP_IN_ACTIVE_LIST 0x00000080
  641. #define SET_EPFLAG(ep, flag) ((ep)->EpFlags |= (flag))
  642. #define CLR_EPFLAG(ep, flag) ((ep)->EpFlags &= ~(flag))
  643. typedef struct _HCD_ENDPOINT {
  644. ULONG Sig;
  645. PHCD_ENDPOINT_DESCRIPTOR HcdED;
  646. PHCD_TRANSFER_DESCRIPTOR HcdHeadP;
  647. PHCD_TRANSFER_DESCRIPTOR HcdTailP;
  648. ULONG EpFlags;
  649. UCHAR Pad[3];
  650. UCHAR Rate;
  651. LIST_ENTRY RequestQueue; // Protected by QueueLock
  652. LIST_ENTRY EndpointListEntry;
  653. LONG EndpointStatus; // Requests currently on HW
  654. LONG MaxRequest; // Max requests allowed on HW
  655. UCHAR Type;
  656. UCHAR ListIndex;
  657. USHORT Bandwidth;
  658. struct _HCD_DEVICE_DATA *DeviceData;
  659. HC_ENDPOINT_CONTROL; // copy of control that is/will be in
  660. ULONG DescriptorsReserved;
  661. KSPIN_LOCK QueueLock; // QueueLock protects RequestQueue
  662. ULONG NextIsoFreeFrame;
  663. ULONG MaxTransfer;
  664. PVOID TrueTail;
  665. PIRP AbortIrp;
  666. } HCD_ENDPOINT, *PHCD_ENDPOINT;
  667. //
  668. // Each Host Controller Endpoint Descriptor is also doubly linked into a list tracked by HCD.
  669. // Each ED queue is managed via an HCD_ED_LIST
  670. //
  671. typedef struct _HCD_ED_LIST {
  672. LIST_ENTRY Head;
  673. PULONG PhysicalHead;
  674. USHORT Bandwidth;
  675. UCHAR Next;
  676. BOOLEAN HcRegister; // PhysicalHead is in a Host Controller register
  677. } HCD_ED_LIST, *PHCD_ED_LIST;
  678. //
  679. // The different ED lists are as follows.
  680. //
  681. #define ED_INTERRUPT_1ms 0
  682. #define ED_INTERRUPT_2ms 1
  683. #define ED_INTERRUPT_4ms 3
  684. #define ED_INTERRUPT_8ms 7
  685. #define ED_INTERRUPT_16ms 15
  686. #define ED_INTERRUPT_32ms 31
  687. #define ED_CONTROL 63
  688. #define ED_BULK 64
  689. #define ED_ISOCHRONOUS 0 // same as 1ms interrupt queue
  690. #define NO_ED_LISTS 65
  691. #define ED_EOF 0xff
  692. //
  693. // HCD Descriptor Page List Entry data structure.
  694. //
  695. // These entries are used to link together the common buffer pages that are
  696. // allocated to hold TD and ED data structures. In addition, the HCCA and the
  697. // static EDs for the interrupt endpoint polling interval tree are contained
  698. // in the first common buffer page that is allocated.
  699. //
  700. typedef struct _PAGE_LIST_ENTRY *PPAGE_LIST_ENTRY;
  701. typedef struct _PAGE_LIST_ENTRY {
  702. PPAGE_LIST_ENTRY NextPage; // NULL terminated list
  703. ULONG BufferSize; // Allocated buffer size
  704. PHYSICAL_ADDRESS PhysAddr; // Base phys address of page
  705. PHYSICAL_ADDRESS FirstTDPhys; // Phys addr of the first TD
  706. PHYSICAL_ADDRESS LastTDPhys; // Phys addr of the last TD
  707. PCHAR VirtAddr; // Base virt address of page
  708. PHCD_TRANSFER_DESCRIPTOR FirstTDVirt; // Virt addr of the first TD
  709. PHCD_TRANSFER_DESCRIPTOR LastTDVirt; // Virt Addr of the last TD
  710. } PAGE_LIST_ENTRY, *PPAGE_LIST_ENTRY;
  711. //values for HcFlags
  712. #define HC_FLAG_REMOTE_WAKEUP_CONNECTED 0x00000001
  713. #define HC_FLAG_LEGACY_BIOS_DETECTED 0x00000002
  714. #define HC_FLAG_SLOW_BULK_ENABLE 0x00000004
  715. #define HC_FLAG_SHUTDOWN 0x00000008 // not really used
  716. #define HC_FLAG_MAP_SX_TO_D3 0x00000010
  717. #define HC_FLAG_IDLE 0x00000020
  718. #define HC_FLAG_DISABLE_IDLE_CHECK 0x00000040
  719. #define HC_FLAG_DEVICE_STARTED 0x00000080
  720. #define HC_FLAG_LOST_POWER 0x00000100
  721. #define HC_FLAG_DISABLE_IDLE_MODE 0x00000200
  722. #define HC_FLAG_USE_HYDRA_HACK 0x00000400
  723. #define HC_FLAG_IN_DPC 0x00000800
  724. #define HC_FLAG_SUSPEND_NEXT_D3 0x00001000
  725. #define HC_FLAG_LIST_FIX_ENABLE 0x00002000
  726. #define HC_FLAG_HUNG_CHECK_ENABLE 0x00004000
  727. #define PENDING_TD_LIST_SIZE 1000
  728. //
  729. // HCD Device Data == Device Extention data
  730. //
  731. typedef struct _HCD_DEVICE_DATA {
  732. UCHAR UsbdWorkArea[sizeof(USBD_EXTENSION)];
  733. ULONG DebugLevel;
  734. ULONG DeviceNameHandle; // handle passed to USBD to generate device name
  735. ULONG HcFlags;
  736. KSPIN_LOCK InterruptSpin; // Spinlock for interrupt
  737. PDEVICE_OBJECT DeviceObject; // point back to device object
  738. PDMA_ADAPTER AdapterObject; // point to our adapter object
  739. ULONG NumberOfMapRegisters;// max number of map registers per transfer
  740. PKINTERRUPT InterruptObject; // Pointer to interrupt object.
  741. KDPC IsrDPC;
  742. PHC_OPERATIONAL_REGISTER HC; // pointer to hw registers
  743. ULONG HClength; // save length for MmUnmapIoSpace
  744. PHCCA_BLOCK HCCA; // pointer to shared memory
  745. KSPIN_LOCK EDListSpin;
  746. // our pool of descriptors
  747. SINGLE_LIST_ENTRY FreeDescriptorList;
  748. ULONG FreeDescriptorCount;
  749. PPAGE_LIST_ENTRY PageList; // pages aquired for descriptors
  750. LIST_ENTRY StalledEDReclamation;
  751. LIST_ENTRY RunningEDReclamation;
  752. LIST_ENTRY PausedEDRestart;
  753. LIST_ENTRY ActiveEndpointList; // list of
  754. // endpoints that
  755. // processing
  756. LONG HcDma;
  757. HCD_ED_LIST EDList[NO_ED_LISTS];
  758. HC_CONTROL CurrentHcControl;
  759. HC_CONTROL ListEnablesAtNextSOF;
  760. HC_FM_INTERVAL OriginalInterval;
  761. ULONG FrameHighPart;
  762. ULONG AvailableBandwidth;
  763. ULONG MaxBandwidthInUse;
  764. ULONG ControlSav;
  765. ULONG BulkSav;
  766. ULONG HcHCCASav;
  767. ULONG LostDoneHeadCount; // Diagnostic aid
  768. ULONG ResurrectHCCount; // Diagnostic aid
  769. ULONG FrozenHcDoneHead;
  770. ULONG LastHccaDoneHead;
  771. ULONGLONG LastDeadmanTime;
  772. KSPIN_LOCK DescriptorsSpin;
  773. KSPIN_LOCK ReclamationSpin;
  774. KSPIN_LOCK PausedSpin;
  775. KSPIN_LOCK HcFlagSpin;
  776. KSPIN_LOCK PageListSpin;
  777. KSPIN_LOCK HcDmaSpin;
  778. LARGE_INTEGER LastIdleTime;
  779. LONG IdleTime;
  780. struct
  781. { /* A context structure between Isr and Dpc */
  782. ULONG ContextInfo;
  783. ULONG Frame;
  784. } IsrDpc_Context;
  785. BOOLEAN InterruptShare;
  786. UCHAR Pad3[3];
  787. PHYSICAL_ADDRESS cardAddress;
  788. PHCD_ENDPOINT RootHubControl;
  789. PHCD_ENDPOINT RootHubInterrupt; // root hub interrupt endpoint (EP 1)
  790. UCHAR RootHubAddress; // device address of root hub (starts as 0)
  791. ULONG PortsSuspendedAtSuspend;
  792. ULONG PortsEnabledAtSuspend;
  793. DEVICE_POWER_STATE CurrentDevicePowerState;
  794. // When we suspend, the states of the ports are not kept by the host
  795. // controller through the resume. We have to find out what the states
  796. // are and put them back. These are bit masks of the ports that are
  797. // either set enabled or suspended.
  798. //
  799. UCHAR RootHubConfig;
  800. UCHAR NumberOfPorts;
  801. UCHAR Pad2[1];
  802. UCHAR ZeroLoadEndpoint_AddrHolder;
  803. USHORT VendorID;
  804. USHORT DeviceID;
  805. UCHAR RevisionID;
  806. UCHAR Pad[3];
  807. PDEVICE_OBJECT RealPhysicalDeviceObject;
  808. PDEVICE_OBJECT TopOfStackPhysicalDeviceObject;
  809. KTIMER DeadmanTimer;
  810. KDPC DeadmanTimerDPC;
  811. #define ZERO_LOAD_ENDPOINT(DeviceData) \
  812. ((PVOID) (&(DeviceData)->ZeroLoadEndpoint_AddrHolder))
  813. //
  814. // We need a memory location that will not be used by any other
  815. // pointer so that we can uniquely identify an endpoint on which there
  816. // is a max packet size of zero. AKA one with no load.
  817. //
  818. LONG OpenCloseSync; // Debugging tool to insure serial
  819. // _OpenEndpoint and _CloseEndpoint
  820. ULONG FakePortChange; // Per port bitmap
  821. ULONG FakePortDisconnect; // Per port bitmap
  822. } HCD_DEVICE_DATA, *PHCD_DEVICE_DATA;
  823. typedef struct _OHCI_RESOURCES {
  824. ULONG InterruptVector;
  825. KIRQL InterruptLevel;
  826. KAFFINITY Affinity;
  827. BOOLEAN ShareIRQ;
  828. KINTERRUPT_MODE InterruptMode;
  829. } OHCI_RESOURCES, *POHCI_RESOURCES;
  830. #define OHCI_MAP_INIT 0x01
  831. typedef struct _MAP_CONTEXT {
  832. BOOLEAN Mapped;
  833. UCHAR Flags;
  834. UCHAR Pad[2];
  835. PHYSICAL_ADDRESS PhysAddress;
  836. ULONG LengthMapped;
  837. PVOID CurrentVa;
  838. PVOID MapRegisterBase;
  839. ULONG TotalLength;
  840. } MAP_CONTEXT, *PMAP_CONTEXT;
  841. typedef struct _KeSync_HcControl
  842. {
  843. PHCD_DEVICE_DATA DeviceData;
  844. HC_CONTROL NewHcControl;
  845. } KeSynch_HcControl, *PKeSynch_HcControl;
  846. #ifdef DEBUG_LOG
  847. #ifdef IRP_LOG
  848. #define IRP_IN(i) OHCI_LogIrp((i), 1)
  849. #define IRP_OUT(i) OHCI_LogIrp((i), 0)
  850. #else
  851. #define IRP_IN(i)
  852. #define IRP_OUT(i)
  853. #endif
  854. #define LOGENTRY(m, sig, info1, info2, info3) \
  855. OHCI_Debug_LogEntry(m, sig, (ULONG_PTR)info1, \
  856. (ULONG_PTR)info2, \
  857. (ULONG_PTR)info3)
  858. #define LOGIRQL() LOGENTRY(G, 'IRQL', KeGetCurrentIrql(), 0, 0);
  859. VOID
  860. OHCI_Debug_LogEntry(
  861. IN ULONG Mask,
  862. IN ULONG Sig,
  863. IN ULONG_PTR Info1,
  864. IN ULONG_PTR Info2,
  865. IN ULONG_PTR Info3
  866. );
  867. VOID
  868. OHCI_LogInit(
  869. );
  870. VOID
  871. OHCI_LogFree(
  872. VOID
  873. );
  874. #else
  875. #define LOGENTRY(mask, sig, info1, info2, info3)
  876. #define OHCI_LogInit()
  877. #define OHCI_LogFree()
  878. #define LOGIRQL()
  879. #define IRP_IN(i)
  880. #define IRP_OUT(i)
  881. #endif
  882. #define ENABLE_LIST(hc, ep) \
  883. { \
  884. ULONG listFilled = 0;\
  885. ULONG temp;\
  886. ASSERT_ENDPOINT(ep);\
  887. \
  888. temp = READ_REGISTER_ULONG (&(hc)->HcControlHeadED);\
  889. if (temp) {\
  890. listFilled |= HcCmd_ControlListFilled;\
  891. }\
  892. temp = READ_REGISTER_ULONG (&(hc)->HcBulkHeadED);\
  893. if (temp) {\
  894. listFilled |= HcCmd_BulkListFilled;\
  895. }\
  896. if (USB_ENDPOINT_TYPE_BULK == (ep)->Type) {\
  897. listFilled |= HcCmd_BulkListFilled;\
  898. } else if (USB_ENDPOINT_TYPE_CONTROL == (ep)->Type) {\
  899. listFilled |= HcCmd_ControlListFilled;\
  900. }\
  901. WRITE_REGISTER_ULONG(&(hc)->HcCommandStatus.ul,\
  902. listFilled);\
  903. LOGENTRY(G, 'enaL', listFilled, ep, 0); \
  904. };
  905. //
  906. // Function Prototypes
  907. //
  908. BOOLEAN OpenHCI_InterruptService (IN PKINTERRUPT Interrupt,
  909. IN void * ServiceContext);
  910. NTSTATUS OpenHCI_URB_Dispatch (IN PDEVICE_OBJECT, IN PIRP);
  911. ULONG Get32BitFrameNumber (PHCD_DEVICE_DATA);
  912. PHCD_ENDPOINT_DESCRIPTOR InsertEDForEndpoint (IN PHCD_DEVICE_DATA, IN PHCD_ENDPOINT, IN UCHAR,
  913. IN PHCD_TRANSFER_DESCRIPTOR *);
  914. PHCD_TRANSFER_DESCRIPTOR
  915. OpenHCI_Alloc_HcdTD(
  916. PHCD_DEVICE_DATA DeviceData
  917. );
  918. VOID
  919. OpenHCI_Free_HcdTD(
  920. PHCD_DEVICE_DATA DeviceData,
  921. PHCD_TRANSFER_DESCRIPTOR Td
  922. );
  923. PHCD_ENDPOINT_DESCRIPTOR
  924. OpenHCI_Alloc_HcdED(
  925. PHCD_DEVICE_DATA DeviceData
  926. );
  927. VOID
  928. OpenHCI_Free_HcdED(
  929. PHCD_DEVICE_DATA DeviceData,
  930. PHCD_ENDPOINT_DESCRIPTOR Ed
  931. );
  932. PHCD_TRANSFER_DESCRIPTOR
  933. OpenHCI_LogDesc_to_PhyDesc (PHCD_DEVICE_DATA, ULONG);
  934. void OpenHCI_PauseED (PHCD_ENDPOINT);
  935. BOOLEAN OpenHCI_InterruptService (PKINTERRUPT, void *);
  936. void OpenHCI_IsrDPC (PKDPC, PVOID, PVOID, PVOID);
  937. void OpenHCI_CompleteIrp(PDEVICE_OBJECT, PIRP, NTSTATUS);
  938. BOOLEAN OpenHCI_StartController (PVOID context);
  939. void OpenHCI_StartEndpoint (PHCD_ENDPOINT);
  940. NTSTATUS OpenHCI_StartTransfer (PDEVICE_OBJECT, PIRP);
  941. NTSTATUS OpenHCI_RootHubStartXfer (PDEVICE_OBJECT, PHCD_DEVICE_DATA, PIRP, PHCD_URB, PHCD_ENDPOINT);
  942. BOOLEAN OpenHCI_HcControl_OR (PVOID);
  943. BOOLEAN OpenHCI_HcControl_AND (PVOID);
  944. BOOLEAN OpenHCI_HcControl_SetHCFS (PVOID);
  945. BOOLEAN OpenHCI_ListEnablesAtNextSOF (PVOID);
  946. void OpenHCI_CancelTransfer (PDEVICE_OBJECT, PIRP);
  947. NTSTATUS OpenHCI_AbortEndpoint(PDEVICE_OBJECT, PIRP, PHCD_DEVICE_DATA, PHCD_URB);
  948. void EmulateRootHubInterruptXfer(PHCD_DEVICE_DATA, PHC_OPERATIONAL_REGISTER);
  949. NTSTATUS CheckRootHub(PHCD_DEVICE_DATA , PHC_OPERATIONAL_REGISTER HC, PHCD_URB);
  950. //jd
  951. VOID
  952. RemoveEDForEndpoint(
  953. IN PHCD_ENDPOINT
  954. );
  955. NTSTATUS
  956. OpenHCI_SetDevicePowerState(
  957. IN PDEVICE_OBJECT,
  958. IN PIRP,
  959. IN DEVICE_POWER_STATE
  960. );
  961. NTSTATUS
  962. OpenHCI_DeferredStartDevice(
  963. IN PDEVICE_OBJECT,
  964. IN PIRP
  965. );
  966. NTSTATUS
  967. OpenHCI_DeferIrpCompletion(
  968. PDEVICE_OBJECT,
  969. PIRP,
  970. PVOID
  971. );
  972. NTSTATUS
  973. OpenHCI_StartDevice(
  974. IN PDEVICE_OBJECT,
  975. IN POHCI_RESOURCES
  976. );
  977. NTSTATUS
  978. OpenHCI_QueryCapabilities(
  979. PDEVICE_OBJECT,
  980. PDEVICE_CAPABILITIES
  981. );
  982. NTSTATUS
  983. OpenHCI_PnPAddDevice(
  984. IN PDRIVER_OBJECT DriverObject,
  985. IN PDEVICE_OBJECT PhysicalDeviceObject
  986. );
  987. NTSTATUS
  988. OpenHCI_SaveHCstate(
  989. PHCD_DEVICE_DATA
  990. );
  991. NTSTATUS
  992. OpenHCI_RestoreHCstate(
  993. PHCD_DEVICE_DATA,
  994. PBOOLEAN
  995. );
  996. NTSTATUS
  997. OpenHCI_DeferPoRequestCompletion(
  998. IN PDEVICE_OBJECT,
  999. IN UCHAR,
  1000. IN POWER_STATE,
  1001. IN PVOID,
  1002. IN PIO_STATUS_BLOCK
  1003. );
  1004. NTSTATUS
  1005. OpenHCI_RootHubPower(
  1006. IN PDEVICE_OBJECT,
  1007. IN PIRP
  1008. );
  1009. NTSTATUS
  1010. OpenHCI_ReserveDescriptors(
  1011. IN PHCD_DEVICE_DATA,
  1012. IN ULONG
  1013. );
  1014. NTSTATUS
  1015. OpenHCI_QueueTransfer(
  1016. PDEVICE_OBJECT ,
  1017. PIRP
  1018. );
  1019. NTSTATUS
  1020. OpenHCI_Dispatch(
  1021. IN PDEVICE_OBJECT ,
  1022. IN PIRP
  1023. );
  1024. VOID
  1025. OpenHCI_Unload(
  1026. IN PDRIVER_OBJECT
  1027. );
  1028. VOID
  1029. OpenHCI_SetTranferError(
  1030. PHCD_URB,
  1031. NTSTATUS
  1032. );
  1033. VOID
  1034. OpenHCI_EndpointWorker(
  1035. PHCD_ENDPOINT
  1036. );
  1037. NTSTATUS
  1038. OpenHCI_GrowDescriptorPool (
  1039. IN PHCD_DEVICE_DATA DeviceData,
  1040. IN ULONG ReserveLength,
  1041. OUT PCHAR *VirtAddr OPTIONAL,
  1042. OUT PHYSICAL_ADDRESS *PhysAddr OPTIONAL
  1043. );
  1044. VOID
  1045. OpenHCI_LockAndCheckEndpoint(
  1046. PHCD_ENDPOINT ,
  1047. PBOOLEAN ,
  1048. PBOOLEAN ,
  1049. PKIRQL
  1050. );
  1051. VOID
  1052. OpenHCI_UnlockEndpoint(
  1053. PHCD_ENDPOINT ,
  1054. KIRQL
  1055. );
  1056. BOOLEAN
  1057. OpenHCI_StopController(
  1058. IN PVOID
  1059. );
  1060. NTSTATUS
  1061. OpenHCI_StopDevice(
  1062. IN PDEVICE_OBJECT DeviceObject,
  1063. IN BOOLEAN TouchTheHardware
  1064. );
  1065. NTSTATUS
  1066. OpenHCI_Shutdown(
  1067. IN PDEVICE_OBJECT DeviceObject
  1068. );
  1069. NTSTATUS
  1070. OpenHCI_StartBIOS(
  1071. IN PDEVICE_OBJECT DeviceObject
  1072. );
  1073. NTSTATUS
  1074. OpenHCI_StopBIOS(
  1075. IN PDEVICE_OBJECT DeviceObject
  1076. );
  1077. NTSTATUS
  1078. OpenHCI_GetSOFRegModifyValue(
  1079. IN PDEVICE_OBJECT DeviceObject,
  1080. IN OUT PULONG SofModifyValue
  1081. );
  1082. NTSTATUS
  1083. OpenHCI_GetRegFlags(
  1084. IN PDEVICE_OBJECT DeviceObject,
  1085. IN OUT PULONG SofModifyValue
  1086. );
  1087. VOID
  1088. OpenHCI_DeadmanDPC(
  1089. PKDPC Dpc,
  1090. PVOID DeviceObject,
  1091. PVOID Context1,
  1092. PVOID Context2
  1093. );
  1094. NTSTATUS
  1095. OpenHCI_InsertMagicEDs(
  1096. IN PDEVICE_OBJECT DeviceObject
  1097. );
  1098. NTSTATUS
  1099. OpenHCI_ResurrectHC(
  1100. PHCD_DEVICE_DATA DeviceData
  1101. );
  1102. ULONG
  1103. FindLostDoneHead (
  1104. IN PHCD_DEVICE_DATA DeviceData
  1105. );
  1106. PHYSICAL_ADDRESS
  1107. OpenHCI_IoMapTransfer(
  1108. IN PMAP_CONTEXT MapContext,
  1109. IN PDMA_ADAPTER DmaAdapter,
  1110. IN PMDL Mdl,
  1111. IN PVOID MapRegisterBase,
  1112. IN PVOID CurrentVa,
  1113. IN OUT PULONG Length,
  1114. IN ULONG TotalLength,
  1115. IN BOOLEAN WriteToDevice
  1116. );
  1117. NTSTATUS
  1118. OpenHCI_ExternalGetCurrentFrame(
  1119. IN PDEVICE_OBJECT DeviceObject,
  1120. IN PULONG CurrentFrame
  1121. );
  1122. ULONG
  1123. OpenHCI_ExternalGetConsumedBW(
  1124. IN PDEVICE_OBJECT DeviceObject
  1125. );
  1126. BOOLEAN
  1127. OpenHCI_RhPortsIdle(
  1128. PHCD_DEVICE_DATA DeviceData
  1129. );
  1130. VOID
  1131. OpenHCI_ProcessEndpoint(
  1132. PHCD_DEVICE_DATA DeviceData,
  1133. PHCD_ENDPOINT Endpoint
  1134. );
  1135. NTSTATUS
  1136. OpenHCI_Resume(
  1137. PDEVICE_OBJECT DeviceObject,
  1138. BOOLEAN LostPower
  1139. );
  1140. ULONG
  1141. ReadPortStatusFix(
  1142. PHCD_DEVICE_DATA DeviceData,
  1143. ULONG PortIndex
  1144. );
  1145. #endif /* OPENHCI_H */