hcd-xhci.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * USB xHCI controller emulation
  3. *
  4. * Copyright (c) 2011 Securiforest
  5. * Date: 2011-05-11 ; Author: Hector Martin <hector@marcansoft.com>
  6. * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef HW_USB_HCD_XHCI_H
  22. #define HW_USB_HCD_XHCI_H
  23. #define TYPE_XHCI "base-xhci"
  24. #define TYPE_NEC_XHCI "nec-usb-xhci"
  25. #define TYPE_QEMU_XHCI "qemu-xhci"
  26. #define XHCI(obj) \
  27. OBJECT_CHECK(XHCIState, (obj), TYPE_XHCI)
  28. #define MAXPORTS_2 15
  29. #define MAXPORTS_3 15
  30. #define MAXPORTS (MAXPORTS_2 + MAXPORTS_3)
  31. #define MAXSLOTS 64
  32. #define MAXINTRS 16
  33. /* Very pessimistic, let's hope it's enough for all cases */
  34. #define EV_QUEUE (((3 * 24) + 16) * MAXSLOTS)
  35. typedef struct XHCIState XHCIState;
  36. typedef struct XHCIStreamContext XHCIStreamContext;
  37. typedef struct XHCIEPContext XHCIEPContext;
  38. enum xhci_flags {
  39. XHCI_FLAG_SS_FIRST = 1,
  40. XHCI_FLAG_FORCE_PCIE_ENDCAP,
  41. XHCI_FLAG_ENABLE_STREAMS,
  42. };
  43. typedef enum TRBType {
  44. TRB_RESERVED = 0,
  45. TR_NORMAL,
  46. TR_SETUP,
  47. TR_DATA,
  48. TR_STATUS,
  49. TR_ISOCH,
  50. TR_LINK,
  51. TR_EVDATA,
  52. TR_NOOP,
  53. CR_ENABLE_SLOT,
  54. CR_DISABLE_SLOT,
  55. CR_ADDRESS_DEVICE,
  56. CR_CONFIGURE_ENDPOINT,
  57. CR_EVALUATE_CONTEXT,
  58. CR_RESET_ENDPOINT,
  59. CR_STOP_ENDPOINT,
  60. CR_SET_TR_DEQUEUE,
  61. CR_RESET_DEVICE,
  62. CR_FORCE_EVENT,
  63. CR_NEGOTIATE_BW,
  64. CR_SET_LATENCY_TOLERANCE,
  65. CR_GET_PORT_BANDWIDTH,
  66. CR_FORCE_HEADER,
  67. CR_NOOP,
  68. ER_TRANSFER = 32,
  69. ER_COMMAND_COMPLETE,
  70. ER_PORT_STATUS_CHANGE,
  71. ER_BANDWIDTH_REQUEST,
  72. ER_DOORBELL,
  73. ER_HOST_CONTROLLER,
  74. ER_DEVICE_NOTIFICATION,
  75. ER_MFINDEX_WRAP,
  76. /* vendor specific bits */
  77. CR_VENDOR_NEC_FIRMWARE_REVISION = 49,
  78. CR_VENDOR_NEC_CHALLENGE_RESPONSE = 50,
  79. } TRBType;
  80. typedef enum TRBCCode {
  81. CC_INVALID = 0,
  82. CC_SUCCESS,
  83. CC_DATA_BUFFER_ERROR,
  84. CC_BABBLE_DETECTED,
  85. CC_USB_TRANSACTION_ERROR,
  86. CC_TRB_ERROR,
  87. CC_STALL_ERROR,
  88. CC_RESOURCE_ERROR,
  89. CC_BANDWIDTH_ERROR,
  90. CC_NO_SLOTS_ERROR,
  91. CC_INVALID_STREAM_TYPE_ERROR,
  92. CC_SLOT_NOT_ENABLED_ERROR,
  93. CC_EP_NOT_ENABLED_ERROR,
  94. CC_SHORT_PACKET,
  95. CC_RING_UNDERRUN,
  96. CC_RING_OVERRUN,
  97. CC_VF_ER_FULL,
  98. CC_PARAMETER_ERROR,
  99. CC_BANDWIDTH_OVERRUN,
  100. CC_CONTEXT_STATE_ERROR,
  101. CC_NO_PING_RESPONSE_ERROR,
  102. CC_EVENT_RING_FULL_ERROR,
  103. CC_INCOMPATIBLE_DEVICE_ERROR,
  104. CC_MISSED_SERVICE_ERROR,
  105. CC_COMMAND_RING_STOPPED,
  106. CC_COMMAND_ABORTED,
  107. CC_STOPPED,
  108. CC_STOPPED_LENGTH_INVALID,
  109. CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR = 29,
  110. CC_ISOCH_BUFFER_OVERRUN = 31,
  111. CC_EVENT_LOST_ERROR,
  112. CC_UNDEFINED_ERROR,
  113. CC_INVALID_STREAM_ID_ERROR,
  114. CC_SECONDARY_BANDWIDTH_ERROR,
  115. CC_SPLIT_TRANSACTION_ERROR
  116. } TRBCCode;
  117. typedef struct XHCIRing {
  118. dma_addr_t dequeue;
  119. bool ccs;
  120. } XHCIRing;
  121. typedef struct XHCIPort {
  122. XHCIState *xhci;
  123. uint32_t portsc;
  124. uint32_t portnr;
  125. USBPort *uport;
  126. uint32_t speedmask;
  127. char name[16];
  128. MemoryRegion mem;
  129. } XHCIPort;
  130. typedef struct XHCISlot {
  131. bool enabled;
  132. bool addressed;
  133. uint16_t intr;
  134. dma_addr_t ctx;
  135. USBPort *uport;
  136. XHCIEPContext *eps[31];
  137. } XHCISlot;
  138. typedef struct XHCIEvent {
  139. TRBType type;
  140. TRBCCode ccode;
  141. uint64_t ptr;
  142. uint32_t length;
  143. uint32_t flags;
  144. uint8_t slotid;
  145. uint8_t epid;
  146. } XHCIEvent;
  147. typedef struct XHCIInterrupter {
  148. uint32_t iman;
  149. uint32_t imod;
  150. uint32_t erstsz;
  151. uint32_t erstba_low;
  152. uint32_t erstba_high;
  153. uint32_t erdp_low;
  154. uint32_t erdp_high;
  155. bool msix_used, er_pcs;
  156. dma_addr_t er_start;
  157. uint32_t er_size;
  158. unsigned int er_ep_idx;
  159. /* kept for live migration compat only */
  160. bool er_full_unused;
  161. XHCIEvent ev_buffer[EV_QUEUE];
  162. unsigned int ev_buffer_put;
  163. unsigned int ev_buffer_get;
  164. } XHCIInterrupter;
  165. struct XHCIState {
  166. /*< private >*/
  167. PCIDevice parent_obj;
  168. /*< public >*/
  169. USBBus bus;
  170. MemoryRegion mem;
  171. MemoryRegion mem_cap;
  172. MemoryRegion mem_oper;
  173. MemoryRegion mem_runtime;
  174. MemoryRegion mem_doorbell;
  175. /* properties */
  176. uint32_t numports_2;
  177. uint32_t numports_3;
  178. uint32_t numintrs;
  179. uint32_t numslots;
  180. uint32_t flags;
  181. uint32_t max_pstreams_mask;
  182. OnOffAuto msi;
  183. OnOffAuto msix;
  184. /* Operational Registers */
  185. uint32_t usbcmd;
  186. uint32_t usbsts;
  187. uint32_t dnctrl;
  188. uint32_t crcr_low;
  189. uint32_t crcr_high;
  190. uint32_t dcbaap_low;
  191. uint32_t dcbaap_high;
  192. uint32_t config;
  193. USBPort uports[MAX(MAXPORTS_2, MAXPORTS_3)];
  194. XHCIPort ports[MAXPORTS];
  195. XHCISlot slots[MAXSLOTS];
  196. uint32_t numports;
  197. /* Runtime Registers */
  198. int64_t mfindex_start;
  199. QEMUTimer *mfwrap_timer;
  200. XHCIInterrupter intr[MAXINTRS];
  201. XHCIRing cmd_ring;
  202. bool nec_quirks;
  203. };
  204. #endif