1 /* $FreeBSD$ */ 2 3 /*- 4 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef _XHCIREG_H_ 29 #define _XHCIREG_H_ 30 31 /* XHCI PCI config registers */ 32 #define PCI_XHCI_CBMEM 0x10 /* configuration base MEM */ 33 #define PCI_XHCI_USBREV 0x60 /* RO USB protocol revision */ 34 #define PCI_USB_REV_3_0 0x30 /* USB 3.0 */ 35 #define PCI_XHCI_FLADJ 0x61 /* RW frame length adjust */ 36 37 #define PCI_XHCI_INTEL_XUSB2PR 0xD0 /* Intel USB2 Port Routing */ 38 #define PCI_XHCI_INTEL_USB2PRM 0xD4 /* Intel USB2 Port Routing Mask */ 39 #define PCI_XHCI_INTEL_USB3_PSSEN 0xD8 /* Intel USB3 Port SuperSpeed Enable */ 40 #define PCI_XHCI_INTEL_USB3PRM 0xDC /* Intel USB3 Port Routing Mask */ 41 42 /* XHCI capability registers */ 43 #define XHCI_CAPLENGTH 0x00 /* RO capability */ 44 #define XHCI_RESERVED 0x01 /* Reserved */ 45 #define XHCI_HCIVERSION 0x02 /* RO Interface version number */ 46 #define XHCI_HCIVERSION_0_9 0x0090 /* xHCI version 0.9 */ 47 #define XHCI_HCIVERSION_1_0 0x0100 /* xHCI version 1.0 */ 48 #define XHCI_HCSPARAMS1 0x04 /* RO structural parameters 1 */ 49 #define XHCI_HCS1_DEVSLOT_MAX(x)((x) & 0xFF) 50 #define XHCI_HCS1_IRQ_MAX(x) (((x) >> 8) & 0x3FF) 51 #define XHCI_HCS1_N_PORTS(x) (((x) >> 24) & 0xFF) 52 #define XHCI_HCSPARAMS2 0x08 /* RO structural parameters 2 */ 53 #define XHCI_HCS2_IST(x) ((x) & 0xF) 54 #define XHCI_HCS2_ERST_MAX(x) (((x) >> 4) & 0xF) 55 #define XHCI_HCS2_SPR(x) (((x) >> 26) & 0x1) 56 #define XHCI_HCS2_SPB_MAX(x) ((((x) >> 16) & 0x3E0) | (((x) >> 27) & 0x1F)) 57 #define XHCI_HCSPARAMS3 0x0C /* RO structural parameters 3 */ 58 #define XHCI_HCS3_U1_DEL(x) ((x) & 0xFF) 59 #define XHCI_HCS3_U2_DEL(x) (((x) >> 16) & 0xFFFF) 60 #define XHCI_HCSPARAMS0 0x10 /* RO capability parameters */ 61 #define XHCI_HCS0_AC64(x) ((x) & 0x1) /* 64-bit capable */ 62 #define XHCI_HCS0_BNC(x) (((x) >> 1) & 0x1) /* BW negotiation */ 63 #define XHCI_HCS0_CSZ(x) (((x) >> 2) & 0x1) /* context size */ 64 #define XHCI_HCS0_PPC(x) (((x) >> 3) & 0x1) /* port power control */ 65 #define XHCI_HCS0_PIND(x) (((x) >> 4) & 0x1) /* port indicators */ 66 #define XHCI_HCS0_LHRC(x) (((x) >> 5) & 0x1) /* light HC reset */ 67 #define XHCI_HCS0_LTC(x) (((x) >> 6) & 0x1) /* latency tolerance msg */ 68 #define XHCI_HCS0_NSS(x) (((x) >> 7) & 0x1) /* no secondary sid */ 69 /* max pri. stream array size */ 70 #define XHCI_HCS0_PSA_SZ_MAX(x) (((x) >> 12) & 0xF) 71 /* extended capabilities pointer */ 72 #define XHCI_HCS0_XECP(x) (((x) >> 16) & 0xFFFF) 73 #define XHCI_DBOFF 0x14 /* RO doorbell offset */ 74 #define XHCI_RTSOFF 0x18 /* RO runtime register space offset */ 75 76 /* XHCI operational registers. Offset given by XHCI_CAPLENGTH register */ 77 #define XHCI_USBCMD 0x00 /* XHCI command */ 78 #define XHCI_CMD_RS 0x00000001 /* RW Run/Stop */ 79 #define XHCI_CMD_HCRST 0x00000002 /* RW Host Controller Reset */ 80 #define XHCI_CMD_INTE 0x00000004 /* RW Interrupter Enable */ 81 #define XHCI_CMD_HSEE 0x00000008 /* RW Host System Error Enable */ 82 /* RO/RW Light Host Controller Reset */ 83 #define XHCI_CMD_LHCRST 0x00000080 84 #define XHCI_CMD_CSS 0x00000100 /* RW Controller Save State */ 85 #define XHCI_CMD_CRS 0x00000200 /* RW Controller Restore State */ 86 #define XHCI_CMD_EWE 0x00000400 /* RW Enable Wrap Event */ 87 #define XHCI_CMD_EU3S 0x00000800 /* RW Enable U3 MFINDEX Stop */ 88 #define XHCI_USBSTS 0x04 /* XHCI status */ 89 #define XHCI_STS_HCH 0x00000001 /* RO - Host Controller Halted */ 90 #define XHCI_STS_HSE 0x00000004 /* RW - Host System Error */ 91 #define XHCI_STS_EINT 0x00000008 /* RW - Event Interrupt */ 92 #define XHCI_STS_PCD 0x00000010 /* RW - Port Change Detect */ 93 #define XHCI_STS_SSS 0x00000100 /* RO - Save State Status */ 94 #define XHCI_STS_RSS 0x00000200 /* RO - Restore State Status */ 95 #define XHCI_STS_SRE 0x00000400 /* RW - Save/Restore Error */ 96 #define XHCI_STS_CNR 0x00000800 /* RO - Controller Not Ready */ 97 #define XHCI_STS_HCE 0x00001000 /* RO - Host Controller Error */ 98 #define XHCI_PAGESIZE 0x08 /* XHCI page size mask */ 99 #define XHCI_PAGESIZE_4K 0x00000001 /* 4K Page Size */ 100 #define XHCI_PAGESIZE_8K 0x00000002 /* 8K Page Size */ 101 #define XHCI_PAGESIZE_16K 0x00000004 /* 16K Page Size */ 102 #define XHCI_PAGESIZE_32K 0x00000008 /* 32K Page Size */ 103 #define XHCI_PAGESIZE_64K 0x00000010 /* 64K Page Size */ 104 #define XHCI_DNCTRL 0x14 /* XHCI device notification control */ 105 #define XHCI_DNCTRL_MASK(n) (1U << (n)) 106 #define XHCI_CRCR_LO 0x18 /* XHCI command ring control */ 107 #define XHCI_CRCR_LO_RCS 0x00000001 /* RW - consumer cycle state */ 108 #define XHCI_CRCR_LO_CS 0x00000002 /* RW - command stop */ 109 #define XHCI_CRCR_LO_CA 0x00000004 /* RW - command abort */ 110 #define XHCI_CRCR_LO_CRR 0x00000008 /* RW - command ring running */ 111 #define XHCI_CRCR_LO_MASK 0x0000000F 112 #define XHCI_CRCR_HI 0x1C /* XHCI command ring control */ 113 #define XHCI_DCBAAP_LO 0x30 /* XHCI dev context BA pointer */ 114 #define XHCI_DCBAAP_HI 0x34 /* XHCI dev context BA pointer */ 115 #define XHCI_CONFIG 0x38 116 /* RW - number of device slots enabled */ 117 #define XHCI_CONFIG_SLOTS_MASK 0x000000FF 118 119 /* XHCI port status registers */ 120 #define XHCI_PORTSC(n) (0x3F0 + (0x10 * (n))) /* XHCI port status */ 121 #define XHCI_PS_CCS 0x00000001 /* RO - current connect status */ 122 #define XHCI_PS_PED 0x00000002 /* RW - port enabled / disabled */ 123 #define XHCI_PS_OCA 0x00000008 /* RO - over current active */ 124 #define XHCI_PS_PR 0x00000010 /* RW - port reset */ 125 /* RW - port link state */ 126 #define XHCI_PS_PLS_GET(x) (((x) >> 5) & 0xF) 127 /* RW - port link state */ 128 #define XHCI_PS_PLS_SET(x) (((x) & 0xF) << 5) 129 #define XHCI_PS_PP 0x00000200 /* RW - port power */ 130 #define XHCI_PS_SPEED_GET(x) (((x) >> 10) & 0xF) /* RO - port speed */ 131 /* RW - port indicator */ 132 #define XHCI_PS_PIC_GET(x) (((x) >> 14) & 0x3) 133 /* RW - port indicator */ 134 #define XHCI_PS_PIC_SET(x) (((x) & 0x3) << 14) 135 #define XHCI_PS_LWS 0x00010000 /* RW - port link state write strobe */ 136 #define XHCI_PS_CSC 0x00020000 /* RW - connect status change */ 137 #define XHCI_PS_PEC 0x00040000 /* RW - port enable/disable change */ 138 #define XHCI_PS_WRC 0x00080000 /* RW - warm port reset change */ 139 #define XHCI_PS_OCC 0x00100000 /* RW - over-current change */ 140 #define XHCI_PS_PRC 0x00200000 /* RW - port reset change */ 141 #define XHCI_PS_PLC 0x00400000 /* RW - port link state change */ 142 #define XHCI_PS_CEC 0x00800000 /* RW - config error change */ 143 #define XHCI_PS_CAS 0x01000000 /* RO - cold attach status */ 144 #define XHCI_PS_WCE 0x02000000 /* RW - wake on connect enable */ 145 #define XHCI_PS_WDE 0x04000000 /* RW - wake on disconnect enable */ 146 #define XHCI_PS_WOE 0x08000000 /* RW - wake on over-current enable */ 147 #define XHCI_PS_DR 0x40000000 /* RO - device removable */ 148 #define XHCI_PS_WPR 0x80000000U /* RW - warm port reset */ 149 #define XHCI_PS_CLEAR 0x80FF01FFU /* command bits */ 150 151 /* XHCI status and control */ 152 #define XHCI_PORTPMSC(n) (0x3F4 + (0x10 * (n))) 153 #define XHCI_PM3_U1TO_GET(x) (((x) >> 0) & 0xFF) /* RW - U1 timeout */ 154 #define XHCI_PM3_U1TO_SET(x) (((x) & 0xFF) << 0) /* RW - U1 timeout */ 155 #define XHCI_PM3_U2TO_GET(x) (((x) >> 8) & 0xFF) /* RW - U2 timeout */ 156 #define XHCI_PM3_U2TO_SET(x) (((x) & 0xFF) << 8) /* RW - U2 timeout */ 157 #define XHCI_PM3_FLA 0x00010000 /* RW - Force Link PM Accept */ 158 #define XHCI_PM2_L1S_GET(x) (((x) >> 0) & 0x7) /* RO - L1 status */ 159 #define XHCI_PM2_RWE 0x00000008 /* RW - remote wakup enable */ 160 /* RW - host initiated resume duration */ 161 #define XHCI_PM2_HIRD_GET(x) (((x) >> 4) & 0xF) 162 /* RW - host initiated resume duration */ 163 #define XHCI_PM2_HIRD_SET(x) (((x) & 0xF) << 4) 164 #define XHCI_PM2_L1SLOT_GET(x) (((x) >> 8) & 0xFF) /* RW - L1 device slot */ 165 #define XHCI_PM2_L1SLOT_SET(x) (((x) & 0xFF) << 8) /* RW - L1 device slot */ 166 #define XHCI_PM2_HLE 0x00010000 /* RW - hardware LPM enable */ 167 #define XHCI_PORTLI(n) (0x3F8 + (0x10 * (n))) /* XHCI port link info */ 168 /* RO - port link errors */ 169 #define XHCI_PLI3_ERR_GET(x) (((x) >> 0) & 0xFFFF) 170 /* XHCI port reserved */ 171 #define XHCI_PORTRSV(n) (0x3FC + (0x10 * (n))) 172 173 /* XHCI runtime registers. Offset given by 174 * XHCI_CAPLENGTH + XHCI_RTSOFF registers 175 */ 176 #define XHCI_MFINDEX 0x0000 /* RO - microframe index */ 177 #define XHCI_MFINDEX_GET(x) ((x) & 0x3FFF) 178 /* XHCI interrupt management */ 179 #define XHCI_IMAN(n) (0x0020 + (0x20 * (n))) 180 #define XHCI_IMAN_INTR_PEND 0x00000001 /* RW - interrupt pending */ 181 #define XHCI_IMAN_INTR_ENA 0x00000002 /* RW - interrupt enable */ 182 /* XHCI interrupt moderation */ 183 #define XHCI_IMOD(n) (0x0024 + (0x20 * (n))) 184 #define XHCI_IMOD_IVAL_GET(x) (((x) >> 0) & 0xFFFF) /* 250ns unit */ 185 #define XHCI_IMOD_IVAL_SET(x) (((x) & 0xFFFF) << 0) /* 250ns unit */ 186 #define XHCI_IMOD_ICNT_GET(x) (((x) >> 16) & 0xFFFF) /* 250ns unit */ 187 #define XHCI_IMOD_ICNT_SET(x) (((x) & 0xFFFF) << 16) /* 250ns unit */ 188 #define XHCI_IMOD_DEFAULT 0x000001F4U /* 8000 IRQs/second */ 189 /* 4000 IRQs/second - LynxPoint */ 190 #define XHCI_IMOD_DEFAULT_LP 0x000003F8U 191 /* XHCI event ring segment table size */ 192 #define XHCI_ERSTSZ(n) (0x0028 + (0x20 * (n))) 193 #define XHCI_ERSTS_GET(x) ((x) & 0xFFFF) 194 #define XHCI_ERSTS_SET(x) ((x) & 0xFFFF) 195 /* XHCI event ring segment table BA */ 196 #define XHCI_ERSTBA_LO(n) (0x0030 + (0x20 * (n))) 197 /* XHCI event ring segment table BA */ 198 #define XHCI_ERSTBA_HI(n) (0x0034 + (0x20 * (n))) 199 /* XHCI event ring dequeue pointer */ 200 #define XHCI_ERDP_LO(n) (0x0038 + (0x20 * (n))) 201 #define XHCI_ERDP_LO_SINDEX(x) ((x) & 0x7) /* RO - dequeue segment index */ 202 #define XHCI_ERDP_LO_BUSY 0x00000008 /* RW - event handler busy */ 203 /* XHCI event ring dequeue pointer */ 204 #define XHCI_ERDP_HI(n) (0x003C + (0x20 * (n))) 205 206 /* XHCI doorbell registers 207 * Offset given by XHCI_CAPLENGTH + XHCI_DBOFF registers 208 */ 209 #define XHCI_DOORBELL(n) (0x0000 + (4 * (n))) 210 #define XHCI_DB_TARGET_GET(x) ((x) & 0xFF) /* RW - doorbell target */ 211 #define XHCI_DB_TARGET_SET(x) ((x) & 0xFF) /* RW - doorbell target */ 212 /* RW - doorbell stream ID */ 213 #define XHCI_DB_SID_GET(x) (((x) >> 16) & 0xFFFF) 214 /* RW - doorbell stream ID */ 215 #define XHCI_DB_SID_SET(x) (((x) & 0xFFFF) << 16) 216 217 /* XHCI runtime register IR base */ 218 #define XHCI_RT_IR_BASE 0x20 219 220 /* XHCI legacy support */ 221 #define XHCI_XECP_ID(x) ((x) & 0xFF) 222 #define XHCI_XECP_NEXT(x) (((x) >> 8) & 0xFF) 223 #define XHCI_XECP_OFF_SHIFT(x) ((x) >> 2) 224 #define XHCI_XECP_BIOS_SEM 0x0002 225 #define XHCI_XECP_OS_SEM 0x0003 226 227 /* XHCI capability ID's */ 228 #define XHCI_ID_USB_LEGACY 0x0001 229 #define XHCI_ID_PROTOCOLS 0x0002 230 #define XHCI_ID_POWER_MGMT 0x0003 231 #define XHCI_ID_VIRTUALIZATION 0x0004 232 #define XHCI_ID_MSG_IRQ 0x0005 233 #define XHCI_ID_USB_LOCAL_MEM 0x0006 234 #define XHCI_ID_DRD_INTEL 0x00C0 235 236 /* ACRN xHCI excapability offset */ 237 #define ACRN_XHCI_EXCAP1 0x20 238 #define ACRN_XHCI_EXCAP2 0x30 239 240 /* 241 * xHCI extended capability pointer in HCCPARAMS1. 242 * The excap offset is calculated by left shift 2 243 * bits which equals 0x8000 244 */ 245 #define XHCI_EXCAP_PTR 0x2000 246 247 /* xHCI extended capability group end marker */ 248 #define EXCAP_GROUP_END 0xFFFF 249 #define EXCAP_GROUP_NULL NULL 250 251 /* Intel xHCI IDs */ 252 #define PCI_INTEL_APL_XHCI_VID 0x8086 253 #define PCI_INTEL_APL_XHCI_PID 0x5aa8 254 255 /* ACRN xHCI iDs */ 256 #define PCI_ACRN_XHCI_VID 0x1234 257 #define PCI_ACRN_XHCI_PID 0x1234 258 259 /* Intel APL xHCI DRD Configuration registers */ 260 #define XHCI_DRD_MUX_CFG0 0x0000 261 #define XHCI_DRD_MUX_CFG1 0x0004 262 #define XHCI_DRD_CFG0_IDPIN (1 << 20) 263 #define XHCI_DRD_CFG0_IDPIN_EN (1 << 21) 264 #define XHCI_DRD_CFG0_VBUS_VALID (1 << 24) 265 #define XHCI_DRD_CFG1_HOST_MODE (1 << 29) 266 267 /* Intel APL xHCI DRD register related bases */ 268 #define XHCI_APL_DRDCAP_BASE 0x8070 269 #define XHCI_APL_DRDREGS_BASE 0x80D8 270 271 /* setting drd for host mode */ 272 #define XHCI_NATIVE_DRD_DEV_MODE "device" 273 274 /* setting drd for device mode */ 275 #define XHCI_NATIVE_DRD_HOST_MODE "host" 276 #define XHCI_NATIVE_DRD_SWITCH_PATH \ 277 "/sys/class/usb_role/intel_xhci_usb_sw-role-switch/role" 278 279 /* return value after setting drd device node */ 280 #define XHCI_NATIVE_DRD_WRITE_DEV_SZ (sizeof(XHCI_NATIVE_DRD_DEV_MODE) - 1) 281 #define XHCI_NATIVE_DRD_WRITE_HOST_SZ (sizeof(XHCI_NATIVE_DRD_HOST_MODE) - 1) 282 283 /* XHCI register R/W wrappers */ 284 #define XREAD1(sc, what, a) \ 285 bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 286 (a) + (sc)->sc_##what##_off) 287 #define XREAD2(sc, what, a) \ 288 bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 289 (a) + (sc)->sc_##what##_off) 290 #define XREAD4(sc, what, a) \ 291 bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 292 (a) + (sc)->sc_##what##_off) 293 #define XWRITE1(sc, what, a, x) \ 294 bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 295 (a) + (sc)->sc_##what##_off, (x)) 296 #define XWRITE2(sc, what, a, x) \ 297 bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 298 (a) + (sc)->sc_##what##_off, (x)) 299 #define XWRITE4(sc, what, a, x) \ 300 bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 301 (a) + (sc)->sc_##what##_off, (x)) 302 303 #endif /* _XHCIREG_H_ */ 304