1213379Shselasky/* $FreeBSD$ */ 2213379Shselasky 3213379Shselasky/*- 4213379Shselasky * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. 5213379Shselasky * 6213379Shselasky * Redistribution and use in source and binary forms, with or without 7213379Shselasky * modification, are permitted provided that the following conditions 8213379Shselasky * are met: 9213379Shselasky * 1. Redistributions of source code must retain the above copyright 10213379Shselasky * notice, this list of conditions and the following disclaimer. 11213379Shselasky * 2. Redistributions in binary form must reproduce the above copyright 12213379Shselasky * notice, this list of conditions and the following disclaimer in the 13213379Shselasky * documentation and/or other materials provided with the distribution. 14213379Shselasky * 15213379Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16213379Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17213379Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18213379Shselasky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19213379Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20213379Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21213379Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22213379Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23213379Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24213379Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25213379Shselasky * SUCH DAMAGE. 26213379Shselasky */ 27213379Shselasky 28213379Shselasky#ifndef _XHCIREG_H_ 29213379Shselasky#define _XHCIREG_H_ 30213379Shselasky 31213379Shselasky/* XHCI PCI config registers */ 32213379Shselasky#define PCI_XHCI_CBMEM 0x10 /* configuration base MEM */ 33213379Shselasky#define PCI_XHCI_USBREV 0x60 /* RO USB protocol revision */ 34213379Shselasky#define PCI_USB_REV_3_0 0x30 /* USB 3.0 */ 35213379Shselasky#define PCI_XHCI_FLADJ 0x61 /* RW frame length adjust */ 36213379Shselasky 37242774Shselasky#define PCI_XHCI_INTEL_XUSB2PR 0xD0 /* Intel USB2 Port Routing */ 38242774Shselasky#define PCI_XHCI_INTEL_USB3_PSSEN 0xD8 /* Intel USB3 Port SuperSpeed Enable */ 39242774Shselasky 40213379Shselasky/* XHCI capability registers */ 41213379Shselasky#define XHCI_CAPLENGTH 0x00 /* RO capability */ 42213379Shselasky#define XHCI_RESERVED 0x01 /* Reserved */ 43213379Shselasky#define XHCI_HCIVERSION 0x02 /* RO Interface version number */ 44213379Shselasky#define XHCI_HCIVERSION_0_9 0x0090 /* xHCI version 0.9 */ 45213379Shselasky#define XHCI_HCIVERSION_1_0 0x0100 /* xHCI version 1.0 */ 46213379Shselasky#define XHCI_HCSPARAMS1 0x04 /* RO structual parameters 1 */ 47213379Shselasky#define XHCI_HCS1_DEVSLOT_MAX(x)((x) & 0xFF) 48213379Shselasky#define XHCI_HCS1_IRQ_MAX(x) (((x) >> 8) & 0x3FF) 49213379Shselasky#define XHCI_HCS1_N_PORTS(x) (((x) >> 24) & 0xFF) 50213379Shselasky#define XHCI_HCSPARAMS2 0x08 /* RO structual parameters 2 */ 51213379Shselasky#define XHCI_HCS2_IST(x) ((x) & 0xF) 52213379Shselasky#define XHCI_HCS2_ERST_MAX(x) (((x) >> 4) & 0xF) 53213379Shselasky#define XHCI_HCS2_SPR(x) (((x) >> 24) & 0x1) 54213379Shselasky#define XHCI_HCS2_SPB_MAX(x) (((x) >> 27) & 0x7F) 55213379Shselasky#define XHCI_HCSPARAMS3 0x0C /* RO structual parameters 3 */ 56213379Shselasky#define XHCI_HCS3_U1_DEL(x) ((x) & 0xFF) 57213379Shselasky#define XHCI_HCS3_U2_DEL(x) (((x) >> 16) & 0xFFFF) 58213379Shselasky#define XHCI_HCSPARAMS0 0x10 /* RO capability parameters */ 59213379Shselasky#define XHCI_HCS0_AC64(x) ((x) & 0x1) /* 64-bit capable */ 60213379Shselasky#define XHCI_HCS0_BNC(x) (((x) >> 1) & 0x1) /* BW negotiation */ 61213379Shselasky#define XHCI_HCS0_CSZ(x) (((x) >> 2) & 0x1) /* context size */ 62213379Shselasky#define XHCI_HCS0_PPC(x) (((x) >> 3) & 0x1) /* port power control */ 63213379Shselasky#define XHCI_HCS0_PIND(x) (((x) >> 4) & 0x1) /* port indicators */ 64213379Shselasky#define XHCI_HCS0_LHRC(x) (((x) >> 5) & 0x1) /* light HC reset */ 65213379Shselasky#define XHCI_HCS0_LTC(x) (((x) >> 6) & 0x1) /* latency tolerance msg */ 66213379Shselasky#define XHCI_HCS0_NSS(x) (((x) >> 7) & 0x1) /* no secondary sid */ 67213379Shselasky#define XHCI_HCS0_PSA_SZ_MAX(x) (((x) >> 12) & 0xF) /* max pri. stream array size */ 68213379Shselasky#define XHCI_HCS0_XECP(x) (((x) >> 16) & 0xFFFF) /* extended capabilities pointer */ 69213379Shselasky#define XHCI_DBOFF 0x14 /* RO doorbell offset */ 70213379Shselasky#define XHCI_RTSOFF 0x18 /* RO runtime register space offset */ 71213379Shselasky 72213379Shselasky/* XHCI operational registers. Offset given by XHCI_CAPLENGTH register */ 73213379Shselasky#define XHCI_USBCMD 0x00 /* XHCI command */ 74213379Shselasky#define XHCI_CMD_RS 0x00000001 /* RW Run/Stop */ 75213379Shselasky#define XHCI_CMD_HCRST 0x00000002 /* RW Host Controller Reset */ 76213379Shselasky#define XHCI_CMD_INTE 0x00000004 /* RW Interrupter Enable */ 77213379Shselasky#define XHCI_CMD_HSEE 0x00000008 /* RW Host System Error Enable */ 78213379Shselasky#define XHCI_CMD_LHCRST 0x00000080 /* RO/RW Light Host Controller Reset */ 79213379Shselasky#define XHCI_CMD_CSS 0x00000100 /* RW Controller Save State */ 80213379Shselasky#define XHCI_CMD_CRS 0x00000200 /* RW Controller Restore State */ 81213379Shselasky#define XHCI_CMD_EWE 0x00000400 /* RW Enable Wrap Event */ 82213379Shselasky#define XHCI_CMD_EU3S 0x00000800 /* RW Enable U3 MFINDEX Stop */ 83213379Shselasky#define XHCI_USBSTS 0x04 /* XHCI status */ 84213379Shselasky#define XHCI_STS_HCH 0x00000001 /* RO - Host Controller Halted */ 85213379Shselasky#define XHCI_STS_HSE 0x00000004 /* RW - Host System Error */ 86213379Shselasky#define XHCI_STS_EINT 0x00000008 /* RW - Event Interrupt */ 87213379Shselasky#define XHCI_STS_PCD 0x00000010 /* RW - Port Change Detect */ 88213379Shselasky#define XHCI_STS_SSS 0x00000100 /* RO - Save State Status */ 89213379Shselasky#define XHCI_STS_RSS 0x00000200 /* RO - Restore State Status */ 90213379Shselasky#define XHCI_STS_SRE 0x00000400 /* RW - Save/Restore Error */ 91213379Shselasky#define XHCI_STS_CNR 0x00000800 /* RO - Controller Not Ready */ 92213379Shselasky#define XHCI_STS_HCE 0x00001000 /* RO - Host Controller Error */ 93213379Shselasky#define XHCI_PAGESIZE 0x08 /* XHCI page size mask */ 94213379Shselasky#define XHCI_PAGESIZE_4K 0x00000001 /* 4K Page Size */ 95213379Shselasky#define XHCI_PAGESIZE_8K 0x00000002 /* 8K Page Size */ 96213379Shselasky#define XHCI_PAGESIZE_16K 0x00000004 /* 16K Page Size */ 97213379Shselasky#define XHCI_PAGESIZE_32K 0x00000008 /* 32K Page Size */ 98213379Shselasky#define XHCI_PAGESIZE_64K 0x00000010 /* 64K Page Size */ 99213379Shselasky#define XHCI_DNCTRL 0x14 /* XHCI device notification control */ 100213379Shselasky#define XHCI_DNCTRL_MASK(n) (1U << (n)) 101213379Shselasky#define XHCI_CRCR_LO 0x18 /* XHCI command ring control */ 102213379Shselasky#define XHCI_CRCR_LO_RCS 0x00000001 /* RW - consumer cycle state */ 103213379Shselasky#define XHCI_CRCR_LO_CS 0x00000002 /* RW - command stop */ 104213379Shselasky#define XHCI_CRCR_LO_CA 0x00000004 /* RW - command abort */ 105213379Shselasky#define XHCI_CRCR_LO_CRR 0x00000008 /* RW - command ring running */ 106213379Shselasky#define XHCI_CRCR_LO_MASK 0x0000000F 107213379Shselasky#define XHCI_CRCR_HI 0x1C /* XHCI command ring control */ 108213379Shselasky#define XHCI_DCBAAP_LO 0x30 /* XHCI dev context BA pointer */ 109213379Shselasky#define XHCI_DCBAAP_HI 0x34 /* XHCI dev context BA pointer */ 110213379Shselasky#define XHCI_CONFIG 0x38 111213379Shselasky#define XHCI_CONFIG_SLOTS_MASK 0x000000FF /* RW - number of device slots enabled */ 112213379Shselasky 113213379Shselasky/* XHCI port status registers */ 114213379Shselasky#define XHCI_PORTSC(n) (0x3F0 + (0x10 * (n))) /* XHCI port status */ 115213379Shselasky#define XHCI_PS_CCS 0x00000001 /* RO - current connect status */ 116213379Shselasky#define XHCI_PS_PED 0x00000002 /* RW - port enabled / disabled */ 117213379Shselasky#define XHCI_PS_OCA 0x00000008 /* RO - over current active */ 118213379Shselasky#define XHCI_PS_PR 0x00000010 /* RW - port reset */ 119213379Shselasky#define XHCI_PS_PLS_GET(x) (((x) >> 5) & 0xF) /* RW - port link state */ 120213379Shselasky#define XHCI_PS_PLS_SET(x) (((x) & 0xF) << 5) /* RW - port link state */ 121229084Shselasky#define XHCI_PS_PP 0x00000200 /* RW - port power */ 122213379Shselasky#define XHCI_PS_SPEED_GET(x) (((x) >> 10) & 0xF) /* RO - port speed */ 123213379Shselasky#define XHCI_PS_PIC_GET(x) (((x) >> 14) & 0x3) /* RW - port indicator */ 124213379Shselasky#define XHCI_PS_PIC_SET(x) (((x) & 0x3) << 14) /* RW - port indicator */ 125213379Shselasky#define XHCI_PS_LWS 0x00010000 /* RW - port link state write strobe */ 126213379Shselasky#define XHCI_PS_CSC 0x00020000 /* RW - connect status change */ 127213379Shselasky#define XHCI_PS_PEC 0x00040000 /* RW - port enable/disable change */ 128213379Shselasky#define XHCI_PS_WRC 0x00080000 /* RW - warm port reset change */ 129213379Shselasky#define XHCI_PS_OCC 0x00100000 /* RW - over-current change */ 130213379Shselasky#define XHCI_PS_PRC 0x00200000 /* RW - port reset change */ 131213379Shselasky#define XHCI_PS_PLC 0x00400000 /* RW - port link state change */ 132213379Shselasky#define XHCI_PS_CEC 0x00800000 /* RW - config error change */ 133213379Shselasky#define XHCI_PS_CAS 0x01000000 /* RO - cold attach status */ 134213379Shselasky#define XHCI_PS_WCE 0x02000000 /* RW - wake on connect enable */ 135213379Shselasky#define XHCI_PS_WDE 0x04000000 /* RW - wake on disconnect enable */ 136213379Shselasky#define XHCI_PS_WOE 0x08000000 /* RW - wake on over-current enable */ 137213379Shselasky#define XHCI_PS_DR 0x40000000 /* RO - device removable */ 138213379Shselasky#define XHCI_PS_WPR 0x80000000U /* RW - warm port reset */ 139226904Shselasky#define XHCI_PS_CLEAR 0x80FF01FFU /* command bits */ 140213379Shselasky 141213379Shselasky#define XHCI_PORTPMSC(n) (0x3F4 + (0x10 * (n))) /* XHCI status and control */ 142213379Shselasky#define XHCI_PM3_U1TO_GET(x) (((x) >> 0) & 0xFF) /* RW - U1 timeout */ 143213379Shselasky#define XHCI_PM3_U1TO_SET(x) (((x) & 0xFF) << 0) /* RW - U1 timeout */ 144213379Shselasky#define XHCI_PM3_U2TO_GET(x) (((x) >> 8) & 0xFF) /* RW - U2 timeout */ 145213379Shselasky#define XHCI_PM3_U2TO_SET(x) (((x) & 0xFF) << 8) /* RW - U2 timeout */ 146213379Shselasky#define XHCI_PM3_FLA 0x00010000 /* RW - Force Link PM Accept */ 147213379Shselasky#define XHCI_PM2_L1S_GET(x) (((x) >> 0) & 0x7) /* RO - L1 status */ 148213379Shselasky#define XHCI_PM2_RWE 0x00000008 /* RW - remote wakup enable */ 149213379Shselasky#define XHCI_PM2_HIRD_GET(x) (((x) >> 4) & 0xF) /* RW - host initiated resume duration */ 150213379Shselasky#define XHCI_PM2_HIRD_SET(x) (((x) & 0xF) << 4) /* RW - host initiated resume duration */ 151213379Shselasky#define XHCI_PM2_L1SLOT_GET(x) (((x) >> 8) & 0xFF) /* RW - L1 device slot */ 152213379Shselasky#define XHCI_PM2_L1SLOT_SET(x) (((x) & 0xFF) << 8) /* RW - L1 device slot */ 153213379Shselasky#define XHCI_PM2_HLE 0x00010000 /* RW - hardware LPM enable */ 154213379Shselasky#define XHCI_PORTLI(n) (0x3F8 + (0x10 * (n))) /* XHCI port link info */ 155213379Shselasky#define XHCI_PLI3_ERR_GET(x) (((x) >> 0) & 0xFFFF) /* RO - port link errors */ 156213379Shselasky#define XHCI_PORTRSV(n) (0x3FC + (0x10 * (n))) /* XHCI port reserved */ 157213379Shselasky 158213379Shselasky/* XHCI runtime registers. Offset given by XHCI_CAPLENGTH + XHCI_RTSOFF registers */ 159213379Shselasky#define XHCI_MFINDEX 0x0000 /* RO - microframe index */ 160213379Shselasky#define XHCI_MFINDEX_GET(x) ((x) & 0x3FFF) 161213379Shselasky#define XHCI_IMAN(n) (0x0020 + (0x20 * (n))) /* XHCI interrupt management */ 162213379Shselasky#define XHCI_IMAN_INTR_PEND 0x00000001 /* RW - interrupt pending */ 163213379Shselasky#define XHCI_IMAN_INTR_ENA 0x00000002 /* RW - interrupt enable */ 164213379Shselasky#define XHCI_IMOD(n) (0x0024 + (0x20 * (n))) /* XHCI interrupt moderation */ 165213379Shselasky#define XHCI_IMOD_IVAL_GET(x) (((x) >> 0) & 0xFFFF) /* 250ns unit */ 166213379Shselasky#define XHCI_IMOD_IVAL_SET(x) (((x) & 0xFFFF) << 0) /* 250ns unit */ 167213379Shselasky#define XHCI_IMOD_ICNT_GET(x) (((x) >> 16) & 0xFFFF) /* 250ns unit */ 168213379Shselasky#define XHCI_IMOD_ICNT_SET(x) (((x) & 0xFFFF) << 16) /* 250ns unit */ 169265079Shselasky#define XHCI_IMOD_DEFAULT 0x000001F4U /* 8000 IRQs/second */ 170265079Shselasky#define XHCI_IMOD_DEFAULT_LP 0x000003F8U /* 4000 IRQs/second - LynxPoint */ 171213379Shselasky#define XHCI_ERSTSZ(n) (0x0028 + (0x20 * (n))) /* XHCI event ring segment table size */ 172213379Shselasky#define XHCI_ERSTS_GET(x) ((x) & 0xFFFF) 173213379Shselasky#define XHCI_ERSTS_SET(x) ((x) & 0xFFFF) 174213379Shselasky#define XHCI_ERSTBA_LO(n) (0x0030 + (0x20 * (n))) /* XHCI event ring segment table BA */ 175213379Shselasky#define XHCI_ERSTBA_HI(n) (0x0034 + (0x20 * (n))) /* XHCI event ring segment table BA */ 176213379Shselasky#define XHCI_ERDP_LO(n) (0x0038 + (0x20 * (n))) /* XHCI event ring dequeue pointer */ 177213379Shselasky#define XHCI_ERDP_LO_SINDEX(x) ((x) & 0x7) /* RO - dequeue segment index */ 178213379Shselasky#define XHCI_ERDP_LO_BUSY 0x00000008 /* RW - event handler busy */ 179213379Shselasky#define XHCI_ERDP_HI(n) (0x003C + (0x20 * (n))) /* XHCI event ring dequeue pointer */ 180213379Shselasky 181213379Shselasky/* XHCI doorbell registers. Offset given by XHCI_CAPLENGTH + XHCI_DBOFF registers */ 182213379Shselasky#define XHCI_DOORBELL(n) (0x0000 + (4 * (n))) 183213379Shselasky#define XHCI_DB_TARGET_GET(x) ((x) & 0xFF) /* RW - doorbell target */ 184213379Shselasky#define XHCI_DB_TARGET_SET(x) ((x) & 0xFF) /* RW - doorbell target */ 185213379Shselasky#define XHCI_DB_SID_GET(x) (((x) >> 16) & 0xFFFF) /* RW - doorbell stream ID */ 186213379Shselasky#define XHCI_DB_SID_SET(x) (((x) & 0xFFFF) << 16) /* RW - doorbell stream ID */ 187213379Shselasky 188213379Shselasky/* XHCI legacy support */ 189213379Shselasky#define XHCI_XECP_ID(x) ((x) & 0xFF) 190213379Shselasky#define XHCI_XECP_NEXT(x) (((x) >> 8) & 0xFF) 191213379Shselasky#define XHCI_XECP_BIOS_SEM 0x0002 192213379Shselasky#define XHCI_XECP_OS_SEM 0x0003 193213379Shselasky 194213379Shselasky/* XHCI capability ID's */ 195213379Shselasky#define XHCI_ID_USB_LEGACY 0x0001 196213379Shselasky#define XHCI_ID_PROTOCOLS 0x0002 197213379Shselasky#define XHCI_ID_POWER_MGMT 0x0003 198213379Shselasky#define XHCI_ID_VIRTUALIZATION 0x0004 199213379Shselasky#define XHCI_ID_MSG_IRQ 0x0005 200213379Shselasky#define XHCI_ID_USB_LOCAL_MEM 0x0006 201213379Shselasky 202213379Shselasky/* XHCI register R/W wrappers */ 203213379Shselasky#define XREAD1(sc, what, a) \ 204213379Shselasky bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 205213379Shselasky (a) + (sc)->sc_##what##_off) 206213379Shselasky#define XREAD2(sc, what, a) \ 207213379Shselasky bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 208213379Shselasky (a) + (sc)->sc_##what##_off) 209213379Shselasky#define XREAD4(sc, what, a) \ 210213379Shselasky bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 211213379Shselasky (a) + (sc)->sc_##what##_off) 212213379Shselasky#define XWRITE1(sc, what, a, x) \ 213213379Shselasky bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 214213379Shselasky (a) + (sc)->sc_##what##_off, (x)) 215213379Shselasky#define XWRITE2(sc, what, a, x) \ 216213379Shselasky bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 217213379Shselasky (a) + (sc)->sc_##what##_off, (x)) 218213379Shselasky#define XWRITE4(sc, what, a, x) \ 219213379Shselasky bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 220213379Shselasky (a) + (sc)->sc_##what##_off, (x)) 221213379Shselasky 222213379Shselasky#endif /* _XHCIREG_H_ */ 223