1 /* SPDX-License-Identifier: GPL-2.0 */
3 * xhci-dbc.h - xHCI debug capability early driver
5 * Copyright (C) 2016 Intel Corporation
7 * Author: Lu Baolu <baolu.lu@linux.intel.com>
10 #ifndef __LINUX_XHCI_DBC_H
11 #define __LINUX_XHCI_DBC_H
13 #include <linux/types.h>
14 #include <linux/usb/ch9.h>
17 * xHCI Debug Capability Register interfaces:
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 */
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 */
35 #define DEBUG_MAX_BURST(p) (((p) >> 16) & 0xff)
37 #define CTRL_DBC_RUN BIT(0)
38 #define CTRL_PORT_ENABLE BIT(1)
39 #define CTRL_HALT_OUT_TR BIT(2)
40 #define CTRL_HALT_IN_TR BIT(3)
41 #define CTRL_DBC_RUN_CHANGE BIT(4)
42 #define CTRL_DBC_ENABLE BIT(31)
44 #define DCST_DEBUG_PORT(p) (((p) >> 24) & 0xff)
46 #define PORTSC_CONN_STATUS BIT(0)
47 #define PORTSC_CONN_CHANGE BIT(17)
48 #define PORTSC_RESET_CHANGE BIT(21)
49 #define PORTSC_LINK_CHANGE BIT(22)
50 #define PORTSC_CONFIG_CHANGE BIT(23)
53 * xHCI Debug Capability data structures:
59 struct xdbc_erst_entry
{
65 struct xdbc_info_context
{
71 __le32 __reserved_0
[7];
74 struct xdbc_ep_context
{
79 __le32 __reserved_0
[11];
83 struct xdbc_info_context info
;
84 struct xdbc_ep_context out
;
85 struct xdbc_ep_context in
;
88 #define XDBC_INFO_CONTEXT_SIZE 48
89 #define XDBC_MAX_STRING_LENGTH 64
90 #define XDBC_STRING_MANUFACTURER "Linux Foundation"
91 #define XDBC_STRING_PRODUCT "Linux USB GDB Target"
92 #define XDBC_STRING_SERIAL "0001"
95 char string0
[XDBC_MAX_STRING_LENGTH
];
96 char manufacturer
[XDBC_MAX_STRING_LENGTH
];
97 char product
[XDBC_MAX_STRING_LENGTH
];
98 char serial
[XDBC_MAX_STRING_LENGTH
];
101 #define XDBC_PROTOCOL 1 /* GNU Remote Debug Command Set */
102 #define XDBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
103 #define XDBC_PRODUCT_ID 0x0011 /* __le16 idProduct; device 0011 */
104 #define XDBC_DEVICE_REV 0x0010 /* 0.10 */
107 * xHCI Debug Capability software state structures:
109 struct xdbc_segment
{
110 struct xdbc_trb
*trbs
;
114 #define XDBC_TRBS_PER_SEGMENT 256
117 struct xdbc_segment
*segment
;
118 struct xdbc_trb
*enqueue
;
119 struct xdbc_trb
*dequeue
;
124 * These are the "Endpoint ID" (also known as "Context Index") values for the
125 * OUT Transfer Ring and the IN Transfer Ring of a Debug Capability Context data
127 * According to the "eXtensible Host Controller Interface for Universal Serial
128 * Bus (xHCI)" specification, section "7.6.3.2 Endpoint Contexts and Transfer
129 * Rings", these should be 0 and 1, and those are the values AMD machines give
130 * you; but Intel machines seem to use the formula from section "4.5.1 Device
131 * Context Index", which is supposed to be used for the Device Context only.
132 * Luckily the values from Intel don't overlap with those from AMD, so we can
133 * just test for both.
135 #define XDBC_EPID_OUT 0
136 #define XDBC_EPID_IN 1
137 #define XDBC_EPID_OUT_INTEL 2
138 #define XDBC_EPID_IN_INTEL 3
146 void __iomem
*xhci_base
;
151 /* DbC register base */
152 struct xdbc_regs __iomem
*xdbc_reg
;
155 dma_addr_t table_dma
;
158 /* event ring segment table */
163 /* event ring segments */
164 struct xdbc_ring evt_ring
;
165 struct xdbc_segment evt_seg
;
167 /* debug capability contexts */
172 /* descriptor strings */
173 dma_addr_t string_dma
;
177 /* bulk OUT endpoint */
178 struct xdbc_ring out_ring
;
179 struct xdbc_segment out_seg
;
183 /* bulk IN endpoint */
184 struct xdbc_ring in_ring
;
185 struct xdbc_segment in_seg
;
191 /* spinlock for early_xdbc_write() reentrancy */
195 #define XDBC_PCI_MAX_BUSES 256
196 #define XDBC_PCI_MAX_DEVICES 32
197 #define XDBC_PCI_MAX_FUNCTION 8
199 #define XDBC_TABLE_ENTRY_SIZE 64
200 #define XDBC_ERST_ENTRY_NUM 1
201 #define XDBC_DBCC_ENTRY_NUM 3
202 #define XDBC_STRING_ENTRY_NUM 4
204 /* Bits definitions for xdbc_state.flags: */
205 #define XDBC_FLAGS_INITIALIZED BIT(0)
206 #define XDBC_FLAGS_IN_STALL BIT(1)
207 #define XDBC_FLAGS_OUT_STALL BIT(2)
208 #define XDBC_FLAGS_IN_PROCESS BIT(3)
209 #define XDBC_FLAGS_OUT_PROCESS BIT(4)
210 #define XDBC_FLAGS_CONFIGURED BIT(5)
212 #define XDBC_MAX_PACKET 1024
214 /* Door bell target: */
215 #define OUT_EP_DOORBELL 0
216 #define IN_EP_DOORBELL 1
217 #define DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
219 #define xdbc_read64(regs) xhci_read_64(NULL, (regs))
220 #define xdbc_write64(val, regs) xhci_write_64(NULL, (val), (regs))
222 #endif /* __LINUX_XHCI_DBC_H */