1
/******************************************************************************
2
* Copyright (c) 2013 IBM Corporation
4
* This program and the accompanying materials
5
* are made available under the terms of the BSD License
6
* which accompanies this distribution, and is available at
7
* http://www.opensource.org/licenses/bsd-license.php
10
* IBM Corporation - initial implementation
11
*****************************************************************************/
13
* Definitions for XHCI Controller - Revision 1.0 (5/21/10)
23
#define BIT(x) (1 << x)
25
/* 5.3 Host Controller Capability Registers
28
struct xhci_cap_regs {
36
#define XHCI_HCCPARAMS_CSZ BIT(2)
37
#define XHCI_HCCPARAMS_XECP(x) ((x & 0xFFFF0000) >> 16)
40
} __attribute__ ((packed));
42
/* USB 3.0: Section 7 and 7.2 */
43
#define XHCI_XECP_CAP_ID(x) ((x & 0xF))
44
#define XHCI_XECP_CAP_SP 2
45
#define XHCI_XECP_CAP_SP_MN(x) ((x & 0xFF0000) >> 16)
46
#define XHCI_XECP_CAP_SP_MJ(x) ((x & 0xFF000000) >> 24)
47
#define XHCI_XECP_CAP_SP_PC(x) ((x & 0xFF00) >> 8)
48
#define XHCI_XECP_CAP_SP_PO(x) (x & 0xFF)
49
#define XHCI_XECP_NEXT_PTR(x) ((x & 0xFF00) >> 8)
51
/* Table 27: Host Controller USB Port Register Set */
52
struct xhci_port_regs {
54
#define PORTSC_CCS BIT(0)
55
#define PORTSC_PED BIT(1)
56
#define PORTSC_OCA BIT(3)
57
#define PORTSC_PR BIT(4)
58
#define PORTSC_PLS_MASK (0xF << 5)
59
#define PORTSC_PLS_U0 0
60
#define PORTSC_PLS_U1 1
61
#define PORTSC_PLS_U2 2
62
#define PORTSC_PLS_U3 3
63
#define PORTSC_PLS_DISABLED 4
64
#define PORTSC_PLS_RXDETECT 5
65
#define PORTSC_PLS_INACTIVE 6
66
#define PORTSC_PLS_POLLING 7
67
#define PORTSC_PLS_RECOVERY 8
68
#define PORTSC_PLS_HOTRESET 9
69
#define PORTSC_PLS_COMP_MODE 10
70
#define PORTSC_PLS_TEST_MODE 11
71
#define PORTSC_PLS_RESUME 15
72
#define PORTSC_PP BIT(9)
73
#define PORTSC_PS_MASK (0xF << 10)
74
#define PORTSC_PIC_MASK (0x3 << 14)
75
#define PORTSC_LWS BIT(16)
76
#define PORTSC_CSC BIT(17)
77
#define PORTSC_PEC BIT(18)
78
#define PORTSC_WRC BIT(19)
79
#define PORTSC_OCC BIT(20)
80
#define PORTSC_PRC BIT(21)
81
#define PORTSC_PLC BIT(22)
82
#define PORTSC_CEC BIT(23)
83
#define PORTSC_CAS BIT(24)
84
#define PORTSC_WCE BIT(25)
85
#define PORTSC_WDE BIT(26)
86
#define PORTSC_WOE BIT(27)
87
#define PORTSC_DR BIT(30)
88
#define PORTSC_WPR BIT(31)
93
} __attribute__ ((packed));
104
/* 5.4 Host Controller Operational Registers
107
struct xhci_op_regs {
109
#define XHCI_USBCMD_RS BIT(0)
110
#define XHCI_USBCMD_HCRST BIT(1)
113
#define XHCI_USBSTS_HCH BIT(0)
114
#define XHCI_USBSTS_CNR BIT(11)
117
uint8_t reserved[8]; /* 0C - 13 */
118
uint32_t dnctrl; /* Device notification control */
119
uint64_t crcr; /* Command ring control */
120
#define XHCI_CRCR_CRP_MASK 0xFFFFFFFFFFFFFFC0
121
#define XHCI_CRCR_CRR BIT(3)
122
#define XHCI_CRCR_CRP_SIZE 4096
124
uint8_t reserved1[16]; /* 20 - 2F */
125
uint64_t dcbaap; /* Device Context Base Address Array Pointer */
126
#define XHCI_DCBAAP_MAX_SIZE 2048
128
uint32_t config; /* Configure */
129
#define XHCI_CONFIG_MAX_SLOT 44
131
uint8_t reserved2[964]; /* 3C - 3FF */
132
/* USB Port register set */
133
#define XHCI_PORT_MAX 256
134
struct xhci_port_regs prs[XHCI_PORT_MAX];
135
} __attribute__ ((packed));
138
* 5.5.2 Interrupter Register Set
139
* Table 42: Interrupter Registers
141
struct xhci_int_regs {
145
#define XHCI_ERST_SIZE_MASK 0xFFFF
148
#define XHCI_ERST_ADDR_MASK (~(0x3FUL))
150
#define XHCI_ERDP_MASK (~(0xFUL))
151
} __attribute__ ((packed));
153
/* 5.5 Host Controller Runtime Registers */
154
struct xhci_run_regs {
155
uint32_t mfindex; /* microframe index */
156
uint8_t reserved[28];
157
#define XHCI_IRS_MAX 1024
158
struct xhci_int_regs irs[XHCI_IRS_MAX];
159
} __attribute__ ((packed));
161
/* 5.6 Doorbell Registers*/
162
struct xhci_db_regs {
164
} __attribute__ ((packed));
166
#define COMP_SUCCESS 1
168
#define TRB_SLOT_ID(x) (((x) & (0xFF << 24)) >> 24)
169
#define TRB_CMD_SLOT_ID(x) ((x & 0xFF) << 24)
170
#define TRB_TYPE(x) (((x) & (0x3F << 10)) >> 10)
171
#define TRB_CMD_TYPE(x) ((x & 0x3F) << 10)
172
#define TRB_STATUS(x) (((x) & (0xFF << 24)) >> 24)
173
#define TRB_ADDR_LOW(x) ((uint32_t)((uint64_t)(x)))
174
#define TRB_ADDR_HIGH(x) ((uint32_t)((uint64_t)(x) >> 32))
175
#define TRB_TRT(x) (((x) & 0x3) << 16 )
176
#define TRB_DIR_IN BIT(16)
177
#define TRB_IOC BIT(5)
178
#define TRB_IDT BIT(6)
180
#define TRB_CYCLE_STATE BIT(0)
182
struct xhci_transfer_trb {
186
} __attribute__ ((packed));
188
struct xhci_link_trb {
192
} __attribute__ ((packed));
195
struct xhci_event_trb {
199
} __attribute__ ((packed));
202
#define TRB_SETUP_STAGE 2
203
#define TRB_DATA_STAGE 3
204
#define TRB_STATUS_STAGE 4
207
#define TRB_EVENT_DATA 7
209
#define TRB_ENABLE_SLOT 9
210
#define TRB_DISABLE_SLOT 10
211
#define TRB_ADDRESS_DEV 11
212
#define TRB_CONFIG_EP 12
213
#define TRB_EVAL_CNTX 13
214
#define TRB_TRANSFER_EVENT 32
215
#define TRB_CMD_COMPLETION 33
216
#define TRB_PORT_STATUS 34
218
struct xhci_command_trb {
220
}__attribute__ ((packed));
223
struct xhci_event_trb event;
224
struct xhci_transfer_trb xfer;
225
struct xhci_command_trb cmd;
226
struct xhci_link_trb link;
237
union xhci_trb *trbs;
238
struct xhci_seg *next;
243
uint32_t cycle_state;
244
enum xhci_seg_type type;
247
#define XHCI_TRB_SIZE 16
248
#define XHCI_EVENT_TRBS_SIZE 4096
249
#define XHCI_CONTROL_TRBS_SIZE 4096
250
#define XHCI_DATA_TRBS_SIZE 4096
251
#define XHCI_INTR_TRBS_SIZE 4096
252
#define XHCI_ERST_NUM_SEGS 1
254
#define XHCI_POLL_NO_WAIT 1
256
#define XHCI_MAX_BULK_SIZE 0xF000
258
struct xhci_erst_entry {
262
} __attribute__ ((packed));
265
struct xhci_erst_entry *entries;
267
uint32_t num_segs; /* number of segments */
270
struct xhci_control_ctx {
273
uint32_t reserved[6];
274
} __attribute__ ((packed));
276
struct xhci_slot_ctx {
278
#define SLOT_SPEED_FS BIT(20)
279
#define SLOT_SPEED_LS BIT(21)
280
#define SLOT_SPEED_HS BIT(22)
281
#define SLOT_SPEED_SS BIT(23)
282
#define LAST_CONTEXT(x) (x << 27)
285
#define ROOT_HUB_PORT(x) ((x & 0xff) << 16)
289
#define USB_DEV_ADDRESS(x) (x & 0xFFU)
290
#define SLOT_STATE(x) ((x >> 27) & 0x1FU)
291
#define SLOT_STATE_DIS_ENA 0
292
#define SLOT_STATE_DEFAULT 1
293
#define SLOT_STATE_ADDRESSED 2
294
#define SLOT_STATE_CONFIGURED 3
297
uint32_t reserved[4];
298
} __attribute__ ((packed));
303
#define MAX_PACKET_SIZE(x) (((x) & 0xFFFF) << 16)
304
#define MAX_BURST(x) (((x) & 0xFF) << 8)
305
#define EP_TYPE(x) (((x) & 0x07) << 3)
306
#define EP_ISOC_OUT 1
307
#define EP_BULK_OUT 2
314
#define ERROR_COUNT(x) (((x) & 0x03) << 1)
318
uint32_t reserved[3];
319
} __attribute__ ((packed));
323
#define XHCI_CTX_TYPE_DEVICE 0x1
324
#define XHCI_CTX_TYPE_INPUT 0x2
327
#define XHCI_CTX_BUF_SIZE 4096
334
struct xhci_ctx in_ctx;
335
struct xhci_ctx out_ctx;
336
struct xhci_seg control;
337
struct xhci_seg intr;
338
struct xhci_seg bulk_in;
339
struct xhci_seg bulk_out;
344
struct xhci_cap_regs *cap_regs;
345
struct xhci_op_regs *op_regs;
346
struct xhci_run_regs *run_regs;
347
struct xhci_db_regs *db_regs;
348
struct usb_hcd_dev *hcidev;
349
struct xhci_dev xdevs[XHCI_CONFIG_MAX_SLOT + 1];
350
struct usb_pipe *freelist;
351
struct usb_pipe *end;
354
struct xhci_seg ering;
355
struct xhci_seg crseg;
356
struct xhci_erst erst;
362
#define XHCI_PIPE_POOL_SIZE 4096
368
struct usb_pipe pipe;
369
struct xhci_seg *seg;
375
extern bool usb3_dev_init(struct xhci_hcd *xhcd, struct usb_dev *hub,
376
uint32_t port, uint32_t slotspeed);
378
#endif /* USB_XHCI_H */