xhci-dbc.h 4.8 KB

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