uhcihw.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. uhcihw.h
  5. Abstract:
  6. This header contains UHCI hardware definitions.
  7. Author:
  8. Evan Green 13-Jan-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // Define the number of frame list pointers in a schedule.
  18. //
  19. #define UHCI_FRAME_LIST_ENTRY_COUNT 1024
  20. #define UHCI_FRAME_LIST_ALIGNMENT 4096
  21. #define UHCI_PORT_COUNT 2
  22. //
  23. // USB Command register bit definitions.
  24. //
  25. #define UHCI_COMMAND_MAX_RECLAMATION_PACKET_64 (1 << 7)
  26. #define UHCI_COMMAND_MAX_RECLAMATION_PACKET_32 (0 << 7)
  27. #define UHCI_COMMAND_CONFIGURED (1 << 6)
  28. #define UHCI_COMMAND_SINGLE_STEP (1 << 5)
  29. #define UHCI_COMMAND_FORCE_GLOBAL_RESUME (1 << 4)
  30. #define UHCI_COMMAND_ENTER_GLOBAL_SUSPEND (1 << 3)
  31. #define UHCI_COMMAND_GLOBAL_RESET (1 << 2)
  32. #define UHCI_COMMAND_HOST_CONTROLLER_RESET (1 << 1)
  33. #define UHCI_COMMAND_RUN (1 << 0)
  34. //
  35. // USB Status register bit definitions
  36. //
  37. #define UHCI_STATUS_HALTED (1 << 5)
  38. #define UHCI_STATUS_PROCESS_ERROR (1 << 4)
  39. #define UHCI_STATUS_HOST_SYSTEM_ERROR (1 << 3)
  40. #define UHCI_STATUS_RESUME_DETECT (1 << 2)
  41. #define UHCI_STATUS_ERROR_INTERRUPT (1 << 1)
  42. #define UHCI_STATUS_INTERRUPT (1 << 0)
  43. //
  44. // USB Interrupt enable register bit definitions.
  45. //
  46. #define UHCI_INTERRUPT_SHORT_PACKET (1 << 3)
  47. #define UHCI_INTERRUPT_COMPLETION (1 << 2)
  48. #define UHCI_INTERRUPT_RESUME (1 << 1)
  49. #define UHCI_INTERRUPT_TIMEOUT_CRC_ERROR (1 << 0)
  50. //
  51. // USB Port Status/Control register definitions.
  52. //
  53. #define UHCI_PORT_SUSPEND (1 << 12)
  54. #define UHCI_PORT_RESET (1 << 9)
  55. #define UHCI_PORT_LOW_SPEED (1 << 8)
  56. #define UHCI_PORT_RESUME_DETECT (1 << 6)
  57. #define UHCI_PORT_DPLUS (1 << 5)
  58. #define UHCI_PORT_DMINUS (1 << 4)
  59. #define UHCI_PORT_ENABLE_STATUS_CHANGED (1 << 3)
  60. #define UHCI_PORT_ENABLED (1 << 2)
  61. #define UHCI_PORT_CONNECT_STATUS_CHANGED (1 << 1)
  62. #define UHCI_PORT_DEVICE_CONNECTED (1 << 0)
  63. //
  64. // Define the bit definitions for each of the 1024 frame list entries.
  65. //
  66. #define UHCI_FRAME_LIST_ENTRY_ADDRESS_MASK 0xFFFFFFF0
  67. #define UHCI_FRAME_LIST_ENTRY_QUEUE_HEAD 0x00000002
  68. #define UHCI_FRAME_LIST_ENTRY_TERMINATE 0x00000001
  69. //
  70. // Define register definitions for the UHCI link pointer used in transfer
  71. // descriptors.
  72. //
  73. #define UHCI_TRANSFER_DESCRIPTOR_LINK_ADDRESS_MASK 0xFFFFFFF0
  74. #define UHCI_TRANSFER_DESCRIPTOR_LINK_DEPTH_FIRST 0x00000004
  75. #define UHCI_TRANSFER_DESCRIPTOR_LINK_QUEUE_HEAD 0x00000002
  76. #define UHCI_TRANSFER_DESCRIPTOR_LINK_TERMINATE 0x00000001
  77. //
  78. // Define register bit definitions for the status field of the transfer
  79. // descriptor.
  80. //
  81. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_SHORT_PACKET (1 << 29)
  82. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_3_ERRORS (0x3 << 27)
  83. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_2_ERRORS (0x2 << 27)
  84. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_1_ERROR (0x1 << 27)
  85. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_NO_ERRORS (0x0 << 27)
  86. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_LOW_SPEED (1 << 26)
  87. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_ISOCHRONOUS (1 << 25)
  88. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_INTERRUPT (1 << 24)
  89. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_ACTIVE (1 << 23)
  90. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_STALLED (1 << 22)
  91. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_DATA_BUFFER_ERROR (1 << 21)
  92. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_BABBLE (1 << 20)
  93. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_NAK (1 << 19)
  94. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_CRC_OR_TIMEOUT (1 << 18)
  95. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_BITSTUFF_ERROR (1 << 17)
  96. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_ERROR_MASK \
  97. (UHCI_TRANSFER_DESCRIPTOR_STATUS_STALLED | \
  98. UHCI_TRANSFER_DESCRIPTOR_STATUS_DATA_BUFFER_ERROR | \
  99. UHCI_TRANSFER_DESCRIPTOR_STATUS_BABBLE | \
  100. UHCI_TRANSFER_DESCRIPTOR_STATUS_CRC_OR_TIMEOUT | \
  101. UHCI_TRANSFER_DESCRIPTOR_STATUS_BITSTUFF_ERROR)
  102. #define UHCI_TRANSFER_DESCRIPTOR_STATUS_ACTUAL_LENGTH_MASK (0x000003FF)
  103. //
  104. // Define register bit definitions for the token field of the transfer
  105. // descriptor.
  106. //
  107. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_MAX_LENGTH_SHIFT 21
  108. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_DATA_TOGGLE (1 << 19)
  109. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_ENDPOINT_SHIFT 15
  110. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_ENDPOINT_MASK 0x00078000
  111. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_ADDRESS_SHIFT 8
  112. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_ADDRESS_MASK 0x00007F00
  113. #define UHCI_TRANSFER_DESCRIPTOR_TOKEN_PID_MASK 0x000000FF
  114. //
  115. // Define register definitions for the UHCI link and element link pointers used
  116. // in queue heads.
  117. //
  118. #define UHCI_QUEUE_HEAD_LINK_ADDRESS_MASK 0xFFFFFFF0
  119. #define UHCI_QUEUE_HEAD_LINK_QUEUE_HEAD 0x00000002
  120. #define UHCI_QUEUE_HEAD_LINK_TERMINATE 0x00000001
  121. //
  122. // Define the offset within the device's PCI Configuration Space where the
  123. // legacy support register lives.
  124. //
  125. #define UHCI_LEGACY_SUPPORT_REGISTER_OFFSET 0xC0
  126. //
  127. // Define the value written into the legacy support register (off in PCI config
  128. // space) to enable UHCI interrupts and stop trapping into SMIs for legacy
  129. // keyboard support.
  130. //
  131. #define UHCI_LEGACY_SUPPORT_ENABLE_USB_INTERRUPTS 0x2000
  132. //
  133. //
  134. // ------------------------------------------------------ Data Type Definitions
  135. //
  136. typedef enum _UHCI_REGISTER {
  137. UhciRegisterUsbCommand = 0x00, // USBCMD
  138. UhciRegisterUsbStatus = 0x02, // USBSTS
  139. UhciRegisterUsbInterruptEnable = 0x04, // USBINTR
  140. UhciRegisterFrameNumber = 0x06, // FRNUM
  141. UhciRegisterFrameBaseAddress = 0x08, // FRBASEADD
  142. UhciRegisterStartOfFrameModify = 0x0C, // SOFMOD
  143. UhciRegisterPort1StatusControl = 0x10, // PORTSC1
  144. UhciRegisterPort2StatusControl = 0x12, // PORTSC2
  145. } UHCI_REGISTER, *PUHCI_REGISTER;
  146. /*++
  147. Structure Description:
  148. This structure defines the hardware-mandated structure for UHCI transfer
  149. descriptors, which are the heart of moving data through USB on UHCI.
  150. Members:
  151. LinkPointer - Stores the link pointer and flags to the next transfer
  152. descriptor or queue head.
  153. Status - Stores status information about how this transfer is going. The
  154. host controller hardware writes to this field.
  155. Token - Stores addressing and length information about the transfer.
  156. BufferPointer - Stores the physical address of the buffer to transfer, down
  157. to the byte granularity.
  158. --*/
  159. typedef struct _UHCI_TRANSFER_DESCRIPTOR {
  160. ULONG LinkPointer;
  161. ULONG Status;
  162. ULONG Token;
  163. ULONG BufferPointer;
  164. } PACKED UHCI_TRANSFER_DESCRIPTOR, *PUHCI_TRANSFER_DESCRIPTOR;
  165. /*++
  166. Structure Description:
  167. This structure defines the hardware-mandated structure for UHCI queue head,
  168. which point to a chain of transfer descriptors (or queue heads in rare
  169. cases).
  170. Members:
  171. LinkPointer - Stores a pointer to the next queue head or transfer
  172. descriptor. This is also known as the "horizontal" link.
  173. ElementLink - Stores a pointer to the next element in the queue. This is
  174. also known as the "vertical" link.
  175. --*/
  176. typedef struct _UHCI_QUEUE_HEAD {
  177. ULONG LinkPointer;
  178. ULONG ElementLink;
  179. } PACKED UHCI_QUEUE_HEAD, *PUHCI_QUEUE_HEAD;
  180. /*++
  181. Structure Description:
  182. This structure defines the hardware-mandated structure for a UHCI schedule.
  183. It contains 1024 frame list pointers, which get executed sequentially
  184. with each frame.
  185. Members:
  186. Frame - Stores the array of frame list pointers, one for each frame in
  187. the schedule.
  188. --*/
  189. typedef struct _UHCI_SCHEDULE {
  190. ULONG Frame[UHCI_FRAME_LIST_ENTRY_COUNT];
  191. } PACKED UHCI_SCHEDULE, *PUHCI_SCHEDULE;
  192. //
  193. // -------------------------------------------------------------------- Globals
  194. //
  195. //
  196. // -------------------------------------------------------- Function Prototypes
  197. //