xhci-dbc.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * xhci-dbc.h - xHCI debug capability early driver
  4. *
  5. * Copyright (C) 2016 Intel Corporation
  6. *
  7. * Author: Lu Baolu <[email protected]>
  8. */
  9. #ifndef __LINUX_XHCI_DBC_H
  10. #define __LINUX_XHCI_DBC_H
  11. #include <linux/types.h>
  12. #include <linux/usb/ch9.h>
  13. /*
  14. * xHCI Debug Capability Register interfaces:
  15. */
  16. struct xdbc_regs {
  17. __le32 capability;
  18. __le32 doorbell;
  19. __le32 ersts; /* Event Ring Segment Table Size*/
  20. __le32 __reserved_0; /* 0c~0f reserved bits */
  21. __le64 erstba; /* Event Ring Segment Table Base Address */
  22. __le64 erdp; /* Event Ring Dequeue Pointer */
  23. __le32 control;
  24. __le32 status;
  25. __le32 portsc; /* Port status and control */
  26. __le32 __reserved_1; /* 2b~28 reserved bits */
  27. __le64 dccp; /* Debug Capability Context Pointer */
  28. __le32 devinfo1; /* Device Descriptor Info Register 1 */
  29. __le32 devinfo2; /* Device Descriptor Info Register 2 */
  30. };
  31. #define DEBUG_MAX_BURST(p) (((p) >> 16) & 0xff)
  32. #define CTRL_DBC_RUN BIT(0)
  33. #define CTRL_PORT_ENABLE BIT(1)
  34. #define CTRL_HALT_OUT_TR BIT(2)
  35. #define CTRL_HALT_IN_TR BIT(3)
  36. #define CTRL_DBC_RUN_CHANGE BIT(4)
  37. #define CTRL_DBC_ENABLE BIT(31)
  38. #define DCST_DEBUG_PORT(p) (((p) >> 24) & 0xff)
  39. #define PORTSC_CONN_STATUS BIT(0)
  40. #define PORTSC_CONN_CHANGE BIT(17)
  41. #define PORTSC_RESET_CHANGE BIT(21)
  42. #define PORTSC_LINK_CHANGE BIT(22)
  43. #define PORTSC_CONFIG_CHANGE BIT(23)
  44. /*
  45. * xHCI Debug Capability data structures:
  46. */
  47. struct xdbc_trb {
  48. __le32 field[4];
  49. };
  50. struct xdbc_erst_entry {
  51. __le64 seg_addr;
  52. __le32 seg_size;
  53. __le32 __reserved_0;
  54. };
  55. struct xdbc_info_context {
  56. __le64 string0;
  57. __le64 manufacturer;
  58. __le64 product;
  59. __le64 serial;
  60. __le32 length;
  61. __le32 __reserved_0[7];
  62. };
  63. struct xdbc_ep_context {
  64. __le32 ep_info1;
  65. __le32 ep_info2;
  66. __le64 deq;
  67. __le32 tx_info;
  68. __le32 __reserved_0[11];
  69. };
  70. struct xdbc_context {
  71. struct xdbc_info_context info;
  72. struct xdbc_ep_context out;
  73. struct xdbc_ep_context in;
  74. };
  75. #define XDBC_INFO_CONTEXT_SIZE 48
  76. #define XDBC_MAX_STRING_LENGTH 64
  77. #define XDBC_STRING_MANUFACTURER "Linux Foundation"
  78. #define XDBC_STRING_PRODUCT "Linux USB GDB Target"
  79. #define XDBC_STRING_SERIAL "0001"
  80. struct xdbc_strings {
  81. char string0[XDBC_MAX_STRING_LENGTH];
  82. char manufacturer[XDBC_MAX_STRING_LENGTH];
  83. char product[XDBC_MAX_STRING_LENGTH];
  84. char serial[XDBC_MAX_STRING_LENGTH];
  85. };
  86. #define XDBC_PROTOCOL 1 /* GNU Remote Debug Command Set */
  87. #define XDBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
  88. #define XDBC_PRODUCT_ID 0x0011 /* __le16 idProduct; device 0011 */
  89. #define XDBC_DEVICE_REV 0x0010 /* 0.10 */
  90. /*
  91. * xHCI Debug Capability software state structures:
  92. */
  93. struct xdbc_segment {
  94. struct xdbc_trb *trbs;
  95. dma_addr_t dma;
  96. };
  97. #define XDBC_TRBS_PER_SEGMENT 256
  98. struct xdbc_ring {
  99. struct xdbc_segment *segment;
  100. struct xdbc_trb *enqueue;
  101. struct xdbc_trb *dequeue;
  102. u32 cycle_state;
  103. };
  104. /*
  105. * These are the "Endpoint ID" (also known as "Context Index") values for the
  106. * OUT Transfer Ring and the IN Transfer Ring of a Debug Capability Context data
  107. * structure.
  108. * According to the "eXtensible Host Controller Interface for Universal Serial
  109. * Bus (xHCI)" specification, section "7.6.3.2 Endpoint Contexts and Transfer
  110. * Rings", these should be 0 and 1, and those are the values AMD machines give
  111. * you; but Intel machines seem to use the formula from section "4.5.1 Device
  112. * Context Index", which is supposed to be used for the Device Context only.
  113. * Luckily the values from Intel don't overlap with those from AMD, so we can
  114. * just test for both.
  115. */
  116. #define XDBC_EPID_OUT 0
  117. #define XDBC_EPID_IN 1
  118. #define XDBC_EPID_OUT_INTEL 2
  119. #define XDBC_EPID_IN_INTEL 3
  120. struct xdbc_state {
  121. u16 vendor;
  122. u16 device;
  123. u32 bus;
  124. u32 dev;
  125. u32 func;
  126. void __iomem *xhci_base;
  127. u64 xhci_start;
  128. size_t xhci_length;
  129. int port_number;
  130. /* DbC register base */
  131. struct xdbc_regs __iomem *xdbc_reg;
  132. /* DbC table page */
  133. dma_addr_t table_dma;
  134. void *table_base;
  135. /* event ring segment table */
  136. dma_addr_t erst_dma;
  137. size_t erst_size;
  138. void *erst_base;
  139. /* event ring segments */
  140. struct xdbc_ring evt_ring;
  141. struct xdbc_segment evt_seg;
  142. /* debug capability contexts */
  143. dma_addr_t dbcc_dma;
  144. size_t dbcc_size;
  145. void *dbcc_base;
  146. /* descriptor strings */
  147. dma_addr_t string_dma;
  148. size_t string_size;
  149. void *string_base;
  150. /* bulk OUT endpoint */
  151. struct xdbc_ring out_ring;
  152. struct xdbc_segment out_seg;
  153. void *out_buf;
  154. dma_addr_t out_dma;
  155. /* bulk IN endpoint */
  156. struct xdbc_ring in_ring;
  157. struct xdbc_segment in_seg;
  158. void *in_buf;
  159. dma_addr_t in_dma;
  160. u32 flags;
  161. /* spinlock for early_xdbc_write() reentrancy */
  162. raw_spinlock_t lock;
  163. };
  164. #define XDBC_PCI_MAX_BUSES 256
  165. #define XDBC_PCI_MAX_DEVICES 32
  166. #define XDBC_PCI_MAX_FUNCTION 8
  167. #define XDBC_TABLE_ENTRY_SIZE 64
  168. #define XDBC_ERST_ENTRY_NUM 1
  169. #define XDBC_DBCC_ENTRY_NUM 3
  170. #define XDBC_STRING_ENTRY_NUM 4
  171. /* Bits definitions for xdbc_state.flags: */
  172. #define XDBC_FLAGS_INITIALIZED BIT(0)
  173. #define XDBC_FLAGS_IN_STALL BIT(1)
  174. #define XDBC_FLAGS_OUT_STALL BIT(2)
  175. #define XDBC_FLAGS_IN_PROCESS BIT(3)
  176. #define XDBC_FLAGS_OUT_PROCESS BIT(4)
  177. #define XDBC_FLAGS_CONFIGURED BIT(5)
  178. #define XDBC_MAX_PACKET 1024
  179. /* Door bell target: */
  180. #define OUT_EP_DOORBELL 0
  181. #define IN_EP_DOORBELL 1
  182. #define DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
  183. #define xdbc_read64(regs) xhci_read_64(NULL, (regs))
  184. #define xdbc_write64(val, regs) xhci_write_64(NULL, (val), (regs))
  185. #endif /* __LINUX_XHCI_DBC_H */