ehcihw.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. ehcihw.h
  5. Abstract:
  6. This header contains EHCI hardware definitions.
  7. Author:
  8. Evan Green 18-Mar-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // Define PCI configuration register offsets.
  18. //
  19. #define EHCI_USB_REGISTER_BASE_REGISTER 0x10
  20. #define EHCI_USB_REGISTER_BASE_ADDRESS_MASK 0xFFFFFF00
  21. #define EHCI_EECP_LEGACY_SUPPORT_REGISTER 0x00
  22. #define EHCI_LEGACY_SUPPORT_OS_OWNED (1 << 24)
  23. #define EHCI_LEGACY_SUPPORT_BIOS_OWNED (1 << 16)
  24. #define EHCI_EECP_LEGACY_SUPPORT_REGISTER 0x00
  25. #define EHCI_EECP_LEGACY_CONTROL_REGISTER 0x04
  26. //
  27. // Define EHCI capability register offsets.
  28. //
  29. #define EHCI_CAPABILITY_LENGTH_REGISTER 0x00
  30. #define EHCI_CAPABILITY_VERSION_REGISTER 0x02
  31. #define EHCI_CAPABILITY_PARAMETERS_REGISTER 0x04
  32. #define EHCI_CAPABILITY_PARAMETERS_PORT_COUNT_MASK 0x0000000F
  33. #define EHCI_CAPABILITY_CAPABILITIES_REGISTER 0x08
  34. #define EHCI_CAPABILITY_CAPABILITIES_EXTENDED_CAPABILITIES_MASK 0x0000FF00
  35. #define EHCI_CAPABILITY_CAPABILITIES_EXTENDED_CAPABILITIES_SHIFT 8
  36. #define EHCI_CAPABILITY_PORT_ROUTING_REGISTER 0x0C
  37. //
  38. // Define the default number of frame list pointers in a schedule.
  39. //
  40. #define EHCI_DEFAULT_FRAME_LIST_ENTRY_COUNT 1024
  41. #define EHCI_FRAME_LIST_ALIGNMENT 4096
  42. #define EHCI_TRANSFER_POINTER_COUNT 5
  43. #define EHCI_PAGE_SIZE 4096
  44. #define EHCI_TRANSFER_MAX_PACKET_SIZE \
  45. (EHCI_TRANSFER_POINTER_COUNT * EHCI_PAGE_SIZE)
  46. //
  47. // EHCI USB Command bit definitions
  48. //
  49. #define EHCI_COMMAND_INTERRUPT_EVERY_1_UFRAME (0x1 << 16)
  50. #define EHCI_COMMAND_INTERRUPT_EVERY_2_UFRAMES (0x2 << 16)
  51. #define EHCI_COMMAND_INTERRUPT_EVERY_4_UFRAMES (0x4 << 16)
  52. #define EHCI_COMMAND_INTERRUPT_EVERY_8_UFRAMES (0x8 << 16)
  53. #define EHCI_COMMAND_INTERRUPT_EVERY_16_UFRAMES (0x10 << 16)
  54. #define EHCI_COMMAND_INTERRUPT_EVERY_32_UFRAMES (0x20 << 16)
  55. #define EHCI_COMMAND_INTERRUPT_EVERY_64_UFRAMES (0x40 << 16)
  56. #define ECHI_COMMAND_ASYNC_PARK_ENABLE (1 << 11)
  57. #define EHCI_COMMAND_PARK_COUNT_SHIFT 8
  58. #define EHCI_COMMAND_LIGHT_CONTROLLER_RESET (1 << 7)
  59. #define EHCI_COMMAND_INTERRUPT_ON_ASYNC_ADVANCE (1 << 6)
  60. #define EHCI_COMMAND_ENABLE_ASYNC_SCHEDULE (1 << 5)
  61. #define EHCI_COMMAND_ENABLE_PERIODIC_SCHEDULE (1 << 4)
  62. #define EHCI_COMMAND_1024_FRAME_LIST_ENTRIES (0 << 2)
  63. #define EHCI_COMMAND_512_FRAME_LIST_ENTRIES (1 << 2)
  64. #define EHCI_COMMAND_256_FRAME_LIST_ENTRIES (2 << 2)
  65. #define EHCI_COMMAND_CONTROLLER_RESET (1 << 1)
  66. #define EHCI_COMMAND_RUN (1 << 0)
  67. //
  68. // EHCI USB Status bit definitions
  69. //
  70. #define EHCI_STATUS_ASYNC_SCHEDULE_STATUS (1 << 15)
  71. #define EHCI_STATUS_PERIODIC_SCHEDULE_STATUS (1 << 14)
  72. #define EHCI_STATUS_RECLAMATION (1 << 13)
  73. #define EHCI_STATUS_HALTED (1 << 12)
  74. #define EHCI_STATUS_INTERRUPT_ON_ASYNC_ADVANCE (1 << 5)
  75. #define EHCI_STATUS_HOST_SYSTEM_ERROR (1 << 4)
  76. #define EHCI_STATUS_FRAME_LIST_ROLLOVER (1 << 3)
  77. #define EHCI_STATUS_PORT_CHANGE_DETECT (1 << 2)
  78. #define EHCI_STATUS_USB_ERROR_INTERRUPT (1 << 1)
  79. #define EHCI_STATUS_USB_INTERRUPT (1 << 0)
  80. #define EHCI_STATUS_INTERRUPT_MASK \
  81. (EHCI_STATUS_INTERRUPT_ON_ASYNC_ADVANCE | \
  82. EHCI_STATUS_HOST_SYSTEM_ERROR | \
  83. EHCI_STATUS_FRAME_LIST_ROLLOVER | \
  84. EHCI_STATUS_PORT_CHANGE_DETECT | \
  85. EHCI_STATUS_USB_ERROR_INTERRUPT | \
  86. EHCI_STATUS_USB_INTERRUPT)
  87. //
  88. // EHCI Interrupt Enable bit definitions
  89. //
  90. #define EHCI_INTERRUPT_ASYNC_ADVANCE (1 << 5)
  91. #define EHCI_INTERRUPT_HOST_SYSTEM_ERROR (1 << 4)
  92. #define EHCI_INTERRUPT_FRAME_LIST_ROLLOVER (1 << 3)
  93. #define EHCI_INTERRUPT_PORT_CHANGE (1 << 2)
  94. #define EHCI_INTERRUPT_USB_ERROR (1 << 1)
  95. #define EHCI_INTERRUPT_ENABLE (1 << 0)
  96. //
  97. // EHCI Port Status bit definitions
  98. // For the line state registers, K state is a low speed device, J state is a
  99. // full or high speed device.
  100. //
  101. #define EHCI_PORT_WAKE_ON_OVER_CURRENT (1 << 22)
  102. #define EHCI_PORT_WAKE_ON_DISCONNECT (1 << 21)
  103. #define EHCI_PORT_WAKE_ON_CONNECT (1 << 20)
  104. #define EHCI_PORT_TEST_MODE_DISABLED (0x0 << 16)
  105. #define EHCI_PORT_TEST_J_STATE (0x1 << 16)
  106. #define EHCI_PORT_TEST_K_STATE (0x2 << 16)
  107. #define EHCI_PORT_TEST_SE0_NAK (0x3 << 16)
  108. #define EHCI_PORT_TEST_PACKET (0x4 << 16)
  109. #define EHCI_PORT_TEST_FORCE_ENABLE (0x5 << 16)
  110. #define EHCI_PORT_INDICATOR_OFF (0x0 << 14)
  111. #define EHCI_PORT_INDICATOR_AMBER (0x1 << 14)
  112. #define EHCI_PORT_INDICATOR_GREEN (0x2 << 14)
  113. #define EHCI_PORT_INDICATOR_MASK (0x3 << 14)
  114. #define EHCI_PORT_OWNER (1 << 13)
  115. #define EHCI_PORT_POWER (1 << 12)
  116. #define EHCI_PORT_LINE_STATE_SE0 (0x0 << 10)
  117. #define EHCI_PORT_LINE_STATE_K (0x1 << 10)
  118. #define EHCI_PORT_LINE_STATE_J (0x2 << 10)
  119. #define EHCI_PORT_LINE_STATE_MASK (0x3 << 10)
  120. #define EHCI_PORT_RESET (1 << 8)
  121. #define EHCI_PORT_SUSPEND (1 << 7)
  122. #define EHCI_PORT_RESUME (1 << 6)
  123. #define EHCI_PORT_OVER_CURRENT_CHANGE (1 << 5)
  124. #define EHCI_PORT_OVER_CURRENT_ACTIVE (1 << 4)
  125. #define EHCI_PORT_ENABLE_CHANGE (1 << 3)
  126. #define EHCI_PORT_ENABLE (1 << 2)
  127. #define EHCI_PORT_CONNECT_STATUS_CHANGE (1 << 1)
  128. #define EHCI_PORT_CONNECT_STATUS (1 << 0)
  129. //
  130. // Define common bits across all link pointers.
  131. //
  132. #define EHCI_LINK_TYPE_ISOCHRONOUS_TRANSFER (0x0 << 1)
  133. #define EHCI_LINK_TYPE_QUEUE_HEAD (0x1 << 1)
  134. #define EHCI_LINK_TYPE_SPLIT_ISOCHRONOUS_TRANSFER (0x2 << 1)
  135. #define EHCI_LINK_TYPE_FRAME_SPAN_TRAVERSAL_NODE (0x3 << 1)
  136. #define EHCI_LINK_TERMINATE (1 << 0)
  137. #define EHCI_LINK_ADDRESS_MASK 0xFFFFFFE0
  138. #define EHCI_LINK_ALIGNMENT 32
  139. //
  140. // Define Transfer Descriptor Token and Page 0 bit definitions.
  141. //
  142. #define EHCI_TRANSFER_DATA_TOGGLE (1 << 31)
  143. #define EHCI_TRANSFER_TOTAL_BYTES_MASK 0x7FFF0000
  144. #define EHCI_TRANSFER_TOTAL_BYTES_SHIFT 16
  145. #define EHCI_TRANSFER_INTERRUPT_ON_COMPLETE (1 << 15)
  146. #define EHCI_TRANSFER_CURRENT_PAGE_SHIFT 12
  147. #define EHCI_TRANSFER_3_ERRORS_ALLOWED (0x3 << 10)
  148. #define EHCI_TRANSFER_2_ERRORS_ALLOWED (0x2 << 10)
  149. #define EHCI_TRANSFER_1_ERROR_ALLOWED (0x1 << 10)
  150. #define EHCI_TRANSFER_UNLIMITED_ERRORS (0x0 << 10)
  151. #define EHCI_TRANSFER_ERROR_COUNT_SHIFT 10
  152. #define EHCI_TRANSFER_PID_CODE_OUT (0x0 << 8)
  153. #define EHCI_TRANSFER_PID_CODE_IN (0x1 << 8)
  154. #define EHCI_TRANSFER_PID_CODE_SETUP (0x2 << 8)
  155. #define EHCI_TRANSFER_STATUS_ACTIVE (1 << 7)
  156. #define EHCI_TRANSFER_STATUS_HALTED (1 << 6)
  157. #define EHCI_TRANSFER_STATUS_DATA_BUFFER_ERROR (1 << 5)
  158. #define EHCI_TRANSFER_BABBLE_ERROR (1 << 4)
  159. #define EHCI_TRANSFER_TRANSACTION_ERROR (1 << 3)
  160. #define EHCI_TRANSFER_MISSED_MICRO_FRAME_ERROR (1 << 2)
  161. #define EHCI_TRANSFER_SPLIT_DO_COMPLETE (1 << 1)
  162. #define EHCI_TRANSFER_SPLIT_DO_PING (1 << 0)
  163. #define EHCI_TRANSFER_ERROR_MASK \
  164. (EHCI_TRANSFER_STATUS_HALTED | \
  165. EHCI_TRANSFER_STATUS_DATA_BUFFER_ERROR | \
  166. EHCI_TRANSFER_BABBLE_ERROR | \
  167. EHCI_TRANSFER_TRANSACTION_ERROR | \
  168. EHCI_TRANSFER_MISSED_MICRO_FRAME_ERROR)
  169. #define EHCI_TRANSFER_CURRENT_OFFSET_MASK 0x00000FFF
  170. #define EHCI_TRANSFER_BUFFER_POINTER_MASK 0xFFFFF000
  171. //
  172. // Define Queue Head endpoint capability bit definitions.
  173. //
  174. #define EHCI_QUEUE_DEFAULT_NAK_RELOAD_COUNT 1
  175. #define EHCI_QUEUE_MAX_NAK_RELOAD_COUNT 0xF
  176. #define EHCI_QUEUE_NAK_RELOAD_COUNT_SHIFT 28
  177. #define EHCI_QUEUE_CONTROL_ENDPOINT (1 << 27)
  178. #define EHCI_QUEUE_MAX_PACKET_LENGTH_SHIFT 16
  179. #define EHCI_QUEUE_MAX_PACKET_LENGTH_MASK 0x07FF0000
  180. #define EHCI_QUEUE_RECLAMATION_HEAD (1 << 15)
  181. #define EHCI_QUEUE_USE_TRANSFER_DESCRIPTOR_DATA_TOGGLE (1 << 14)
  182. #define EHCI_QUEUE_FULL_SPEED (0x0 << 12)
  183. #define EHCI_QUEUE_LOW_SPEED (0x1 << 12)
  184. #define EHCI_QUEUE_HIGH_SPEED (0x2 << 12)
  185. #define EHCI_QUEUE_ENDPOINT_SHIFT 8
  186. #define EHCI_QUEUE_INACTIVATE_ON_NEXT_TRANSACTION (1 << 7)
  187. #define EHCI_QUEUE_DEVICE_ADDRESS_MASK 0x7F
  188. #define EHCI_QUEUE_1_TRANSACTION_PER_MICRO_FRAME (0x1 << 30)
  189. #define EHCI_QUEUE_2_TRANSACTIONS_PER_MICRO_FRAME (0x2 << 30)
  190. #define EHCI_QUEUE_3_TRANSACTIONS_PER_MICRO_FRAME (0x3 << 30)
  191. #define EHCI_QUEUE_PORT_NUMBER_SHIFT 23
  192. #define EHCI_QUEUE_PORT_NUMBER_MASK 0x3F800000
  193. #define EHCI_QUEUE_HUB_ADDRESS_SHIFT 16
  194. #define EHCI_QUEUE_HUB_ADDRESS_MASK 0x007F0000
  195. #define EHCI_QUEUE_SPLIT_COMPLETION_MASK 0x0000FF00
  196. #define EHCI_QUEUE_SPLIT_COMPLETION_SHIFT 8
  197. #define EHCI_QUEUE_INTERRUPT_SCHEDULE_MASK 0x000000FF
  198. #define EHCI_QUEUE_SPLIT_START_MASK EHCI_QUEUE_INTERRUPT_SCHEDULE_MASK
  199. //
  200. // ------------------------------------------------------ Data Type Definitions
  201. //
  202. typedef enum _EHCI_REGISTER {
  203. EhciRegisterUsbCommand = 0x00, // USBCMD
  204. EhciRegisterUsbStatus = 0x04, // USBSTS
  205. EhciRegisterUsbInterruptEnable = 0x08, // USBINTR
  206. EhciRegisterFrameNumber = 0x0C, // FRINDEX
  207. EhciRegisterSegmentSelector = 0x10, // CTRLDSSEGMENT
  208. EhciRegisterPeriodicListBase = 0x14, // PERIODICLISTBASE
  209. EhciRegisterAsynchronousListAddress = 0x18, // ASYNCLISTADDR
  210. EhciRegisterConfigured = 0x40, // CONFIGFLAG
  211. EhciRegisterPortStatusBase = 0x44, // PORTSC[1-N_PORTS]
  212. } EHCI_REGISTER, *PEHCI_REGISTER;
  213. /*++
  214. Structure Description:
  215. This structure defines the hardware-mandated structure for EHCI transfer
  216. descriptors, which are the heart of moving data through USB on EHCI host
  217. controllers. Pointers to this structure must be 32-byte aligned as required
  218. by the EHCI specification.
  219. Members:
  220. NextTransfer - Stores a link pointer containing the physical address of the
  221. next transfer in the queue.
  222. AlternateNextTransfer - Stores a link pointer containing the physical
  223. address of the next transfer should this transfer be a short IN
  224. packet.
  225. Token - Stores the working control/status information of the transfer.
  226. BufferPointer - Stores an array of physical pointers to the data to
  227. transfer. This data must be virtually contiguous, essentially meaning
  228. that buffers that are not the first or last must be a full 4096 bytes
  229. large.
  230. BufferAddressHigh - Stores the high 32 bits of each of the addresses in the
  231. buffer pointers. This is only referenced by the hardware if 64 bit
  232. structures are supported.
  233. --*/
  234. typedef struct _EHCI_TRANSFER_DESCRIPTOR {
  235. ULONG NextTransfer;
  236. ULONG AlternateNextTransfer;
  237. ULONG Token;
  238. ULONG BufferPointer[EHCI_TRANSFER_POINTER_COUNT];
  239. ULONG BufferAddressHigh[EHCI_TRANSFER_POINTER_COUNT];
  240. } PACKED EHCI_TRANSFER_DESCRIPTOR, *PEHCI_TRANSFER_DESCRIPTOR;
  241. /*++
  242. Structure Description:
  243. This structure defines the hardware-mandated structure for EHCI transfer
  244. queues, which manage sets of transfer descriptors for all transfer types
  245. except isochronous. Pointers to this structure must be 32-byte aligned as
  246. required by the EHCI specification.
  247. Members:
  248. HorizontalLink - Stores a pointer to the next element after this queue,
  249. which if on the periodic list may be an Isochronous Transfer Descriptor,
  250. Queue Head, or Frame Span Traversal Node. On the asynchronous list, this
  251. would only be another Queue Head.
  252. Destination - Stores queue adressing information and transfer length.
  253. SplitInformation - Stores information relating largely to performing full/
  254. low speed split transactions.
  255. CurrentTransferDescriptorLink - Stores the link pointer to the transfer
  256. descriptor currently being processed.
  257. TransferOverlay - Stores the working space for the EHCI controller when
  258. processing transfer descriptors on this queue.
  259. --*/
  260. typedef struct _EHCI_QUEUE_HEAD {
  261. ULONG HorizontalLink;
  262. ULONG Destination;
  263. ULONG SplitInformation;
  264. ULONG CurrentTransferDescriptorLink;
  265. EHCI_TRANSFER_DESCRIPTOR TransferOverlay;
  266. } PACKED EHCI_QUEUE_HEAD, *PEHCI_QUEUE_HEAD;
  267. /*++
  268. Structure Description:
  269. This structure defines the hardware-mandated structure for EHCI Frame
  270. Span Traversal Nodes, which are used to ensure split transactions that
  271. occur across a frame boundary get the appropriate attention from the
  272. periodic schedule.
  273. Members:
  274. NormalPathLink - Stores the normal path to the next element in the periodic
  275. schedule, which is automatically traversed during micro-frames 2-7 and
  276. when not in restore path mode.
  277. BackPathLink - Store the link to the valid in-progress split transaction,
  278. in which case this is called a Save-Place node. If the T bit is set,
  279. then the back path link is invalid, and this node is considered a
  280. Restore node.
  281. --*/
  282. typedef struct _EHCI_FRAME_SPAN_TRAVERSAL_NODE {
  283. ULONG NormalPathLink;
  284. ULONG BackPathLink;
  285. } PACKED EHCI_FRAME_SPAN_TRAVERSAL_NODE, *PEHCI_FRAME_SPAN_TRAVERSAL_NODE;
  286. /*++
  287. Structure Description:
  288. This structure defines the hardware-mandated structure for an EHCI periodic
  289. schedule. It contains 1024 frame list pointers by default, which get
  290. executed 8 times for each frame.
  291. Members:
  292. Frame - Stores the array of frame list pointers, one for each frame in
  293. the schedule.
  294. --*/
  295. typedef struct _EHCI_PERIODIC_SCHEDULE {
  296. ULONG FrameLink[EHCI_DEFAULT_FRAME_LIST_ENTRY_COUNT];
  297. } PACKED EHCI_PERIODIC_SCHEDULE, *PEHCI_PERIODIC_SCHEDULE;
  298. //
  299. // -------------------------------------------------------------------- Globals
  300. //
  301. //
  302. // -------------------------------------------------------- Function Prototypes
  303. //