Home | History | Annotate | Line # | Download | only in ic
ahcisatareg.h revision 1.6
      1 /*	$NetBSD: ahcisatareg.h,v 1.6 2010/07/20 18:50:48 jakllsch Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2006 Manuel Bouyer.
      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 ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  *
     26  */
     27 
     28 /* SATA AHCI v1.0 register defines */
     29 
     30 /* misc defines */
     31 #define AHCI_MAX_PORTS 32
     32 #define AHCI_MAX_CMDS 32
     33 
     34 /* in-memory structures used by the controller */
     35 /* physical region descriptor: points to a region of data (max 4MB) */
     36 struct ahci_dma_prd {
     37 	uint32_t prd_dba; /* data base address (64 bits) */
     38 	uint32_t prd_dbau;
     39 	uint32_t prd_res; /* reserved */
     40 	uint32_t prd_dbc; /* data byte count */
     41 #define AHCI_PRD_DBC_MASK 0x003fffff
     42 #define AHCI_PRD_DBC_IPC  0x80000000 /* interrupt on completion */
     43 } __packed;
     44 
     45 #define AHCI_NPRD ((MAXPHYS/PAGE_SIZE) + 1)
     46 
     47 /* command table: describe a command to send to drive */
     48 struct ahci_cmd_tbl {
     49 	uint8_t cmdt_cfis[64]; /* command FIS */
     50 	uint8_t cmdt_acmd[16]; /* ATAPI command */
     51 	uint8_t cmdt_res[48]; /* reserved */
     52 	struct ahci_dma_prd cmdt_prd[1]; /* extended to AHCI_NPRD */
     53 } __packed;
     54 
     55 #define AHCI_CMDTBL_ALIGN 0x7f
     56 
     57 #define AHCI_CMDTBL_SIZE ((sizeof(struct ahci_cmd_tbl) + \
     58     (sizeof(struct ahci_dma_prd) * (AHCI_NPRD - 1)) + (AHCI_CMDTBL_ALIGN)) \
     59     & ~AHCI_CMDTBL_ALIGN)
     60 
     61 /*
     62  * command header: points to a command table. The command list is an array
     63  * of theses.
     64  */
     65 struct ahci_cmd_header {
     66 	uint16_t cmdh_flags;
     67 #define AHCI_CMDH_F_PMP_MASK	0xf000 /* port multiplier port */
     68 #define AHCI_CMDH_F_PMP_SHIFT	12
     69 #define AHCI_CMDH_F_CBSY	0x0400 /* clear BSY on R_OK */
     70 #define AHCI_CMDH_F_BIST	0x0200 /* BIST FIS */
     71 #define AHCI_CMDH_F_RST		0x0100 /* Reset FIS */
     72 #define AHCI_CMDH_F_PRF		0x0080 /* prefectchable */
     73 #define AHCI_CMDH_F_WR		0x0040 /* write */
     74 #define AHCI_CMDH_F_A		0x0020 /* ATAPI */
     75 #define AHCI_CMDH_F_CFL_MASK	0x001f /* command FIS length (in dw) */
     76 #define AHCI_CMDH_F_CFL_SHIFT	0
     77 	uint16_t cmdh_prdtl;	/* number of cmdt_prd */
     78 	uint32_t cmdh_prdbc;	/* physical region descriptor byte count */
     79 	uint32_t cmdh_cmdtba;	/* phys. addr. of cmd_tbl */
     80 	uint32_t cmdh_cmdtbau;	/* (64bits, 128bytes aligned) */
     81 	uint32_t cmdh_res[4];	/* reserved */
     82 } __packed;
     83 
     84 #define AHCI_CMDH_SIZE (sizeof(struct ahci_cmd_header) * AHCI_MAX_CMDS)
     85 
     86 /* received FIS: where the HBA stores various type of FIS it receives */
     87 struct ahci_r_fis {
     88 	uint8_t rfis_dsfis[32];	/* DMA setup FIS */
     89 	uint8_t rfis_psfis[32]; /* PIO setup FIS */
     90 	uint8_t rfis_rfis[24];  /* D2H register FIS */
     91 	uint8_t rfis_sdbfis[8]; /* set device bit FIS */
     92 	uint8_t rfis_ukfis[64]; /* unknown FIS */
     93 	uint8_t rfis_res[96];   /* reserved */
     94 } __packed;
     95 
     96 #define AHCI_RFIS_SIZE (sizeof(struct ahci_r_fis))
     97 
     98 /* PCI registers */
     99 /* class Mass storage, subclass SATA, interface AHCI */
    100 #define PCI_INTERFACE_SATA_AHCI	0x01
    101 
    102 #define AHCI_PCI_ABAR	0x24 /* native ACHI registers (memory mapped) */
    103 
    104 /*  ABAR registers */
    105 /* Global registers */
    106 #define AHCI_CAP	0x00 /* HBA capabilities */
    107 #define		AHCI_CAP_NPMASK	0x0000001f /* Number of ports */
    108 #define		AHCI_CAP_XS	0x00000020 /* External SATA */
    109 #define		AHCI_CAP_EM	0x00000040 /* Enclosure Management */
    110 #define		AHCI_CAP_CCC	0x00000080 /* command completion coalescing */
    111 #define		AHCI_CAP_NCS	0x00001f00 /* number of command slots */
    112 #define		AHCI_CAP_PS	0x00002000 /* Partial State */
    113 #define		AHCI_CAP_SS	0x00004000 /* Slumber State */
    114 #define		AHCI_CAP_PMD	0x00008000 /* PIO multiple DRQ blocks */
    115 #define		AHCI_CAP_FBS	0x00010000 /* FIS-Based switching */
    116 #define		AHCI_CAP_SPM	0x00020000 /* Port multipliers */
    117 #define		AHCI_CAP_SAM	0x00040000 /* AHCI-only */
    118 #define		AHCI_CAP_NZO	0x00080000 /* Non-zero DMA offset (reserved) */
    119 #define		AHCI_CAP_IS	0x00f00000 /* Interface speed */
    120 #define		AHCI_CAP_IS_GEN1	0x00100000 /* 1.5 GB/s */
    121 #define		AHCI_CAP_IS_GEN2	0x00200000 /* 1.5 and 3 GB/s */
    122 #define		AHCI_CAP_CLO	0x01000000 /* Command list override */
    123 #define		AHCI_CAP_AL	0x02000000 /* Single Activitly LED */
    124 #define		AHCI_CAP_ALP	0x04000000 /* Agressive link power management */
    125 #define		AHCI_CAP_SSU	0x08000000 /* Staggered spin-up */
    126 #define		AHCI_CAP_MPS	0x10000000 /* Mechanical swicth */
    127 #define		AHCI_CAP_NTF	0x20000000 /* Snotification */
    128 #define		AHCI_CAP_NCQ	0x40000000 /* Native command queuing */
    129 #define		AHCI_CAP_64BIT	0x80000000 /* 64bit addresses */
    130 
    131 #define AHCI_GHC	0x04 /* HBA control */
    132 #define 	AHCI_GHC_HR	 0x00000001 /* HBA reset */
    133 #define 	AHCI_GHC_IE	 0x00000002 /* Interrupt enable */
    134 #define 	AHCI_GHC_MRSM	 0x00000004 /* MSI revert to single message */
    135 #define 	AHCI_GHC_AE	 0x80000000 /* AHCI enable */
    136 
    137 #define AHCI_IS		0x08 /* Interrupt status register: one bit per port */
    138 
    139 #define AHCI_PI		0x0c /* Port implemented: one bit per port */
    140 
    141 #define AHCI_VS		0x10 /* AHCI version */
    142 #define 	AHCI_VS_10	0x00010000 /* AHCI spec 1.0 */
    143 #define 	AHCI_VS_11	0x00010100 /* AHCI spec 1.1 */
    144 #define 	AHCI_VS_12	0x00010200 /* AHCI spec 1.2 */
    145 
    146 #define AHCI_CC_CTL	0x14 /* command completion coalescing control */
    147 #define 	AHCI_CC_TV_MASK	0xffff0000 /* timeout value */
    148 #define 	AHCI_CC_TV_SHIFT 16
    149 #define 	AHCI_CC_CC_MASK	0x0000ff00 /* command completion */
    150 #define 	AHCI_CC_CC_SHIFT 8
    151 #define 	AHCI_CC_INT_MASK 0x000000f8 /* interrupt */
    152 #define 	AHCI_CC_INT_SHIFT 3
    153 #define 	AHCI_CC_EN	0x000000001 /* enable */
    154 
    155 #define AHCI_CC_PORTS	0x18 /* command completion coalescing ports (1b/port */
    156 
    157 #define AHCI_EM_LOC	0x1c /* enclosure managemement location */
    158 #define		AHCI_EML_OFF_MASK 0xffff0000 /* offset in ABAR */
    159 #define		AHCI_EML_OFF_SHIFT 16
    160 #define		AHCI_EML_SZ_MASK  0x0000ffff /* offset in ABAR */
    161 #define		AHCI_EML_SZ_SHIFT  0
    162 
    163 #define AHCI_EM_CTL	0x20 /* enclosure management control */
    164 #define		AHCI_EMC_PM	0x08000000 /* port multiplier support */
    165 #define		AHCI_EMC_ALHD	0x04000000 /* activity LED hardware driven */
    166 #define		AHCI_EMC_XMIT	0x02000000 /* tramsit messages only */
    167 #define		AHCI_EMC_SMB	0x01000000 /* single message buffer */
    168 #define		AHCI_EMC_SGPIO	0x00080000 /* enclosure management messages */
    169 #define		AHCI_EMC_SES2	0x00040000 /* SeS-2 messages */
    170 #define		AHCI_EMC_SAF	0x00020000 /* SAF_TE messages */
    171 #define		AHCI_EMC_LED	0x00010000 /* LED messages */
    172 #define		AHCI_EMC_RST	0x00000200 /* Reset */
    173 #define		AHCI_EMC_TM	0x00000100 /* Transmit message */
    174 #define		AHCI_EMC_MR	0x00000001 /* Message received */
    175 
    176 /* Per-port registers */
    177 #define AHCI_P_OFFSET(port) (0x80 * (port))
    178 
    179 #define AHCI_P_CLB(p)	(0x100 + AHCI_P_OFFSET(p)) /* command list addr */
    180 #define AHCI_P_CLBU(p)	(0x104 + AHCI_P_OFFSET(p)) /* command list addr */
    181 #define AHCI_P_FB(p)	(0x108 + AHCI_P_OFFSET(p)) /* FIS addr */
    182 #define AHCI_P_FBU(p)	(0x10c + AHCI_P_OFFSET(p)) /* FIS addr */
    183 #define AHCI_P_IS(p)	(0x110 + AHCI_P_OFFSET(p)) /* Interrupt status */
    184 #define AHCI_P_IE(p)	(0x114 + AHCI_P_OFFSET(p)) /* Interrupt enable */
    185 #define		AHCI_P_IX_CPDS	0x80000000 /* Cold port detect */
    186 #define		AHCI_P_IX_TFES	0x40000000 /* Task file error */
    187 #define		AHCI_P_IX_HBFS	0x20000000 /* Host bus fatal error */
    188 #define		AHCI_P_IX_HBDS	0x10000000 /* Host bus data error */
    189 #define		AHCI_P_IX_IFS	0x08000000 /* Interface fatal error */
    190 #define		AHCI_P_IX_INFS	0x04000000 /* Interface non-fatal error */
    191 #define		AHCI_P_IX_OFS	0x01000000 /* Overflow */
    192 #define		AHCI_P_IX_IPMS	0x00800000 /* Incorrect port multiplier */
    193 #define		AHCI_P_IX_PRCS	0x00400000 /* Phy Ready change */
    194 #define		AHCI_P_IX_DMPS	0x00000080 /* Device Mechanical Presence */
    195 #define		AHCI_P_IX_PCS	0x00000040 /* port Connect change */
    196 #define		AHCI_P_IX_DPS	0x00000020 /* dexcriptor processed */
    197 #define		AHCI_P_IX_UFS	0x00000010 /* Unknown FIS */
    198 #define		AHCI_P_IX_SDBS	0x00000008 /* Set device bit */
    199 #define		AHCI_P_IX_DSS	0x00000004 /* DMA setup FIS */
    200 #define		AHCI_P_IX_PSS	0x00000002 /* PIO setup FIS */
    201 #define		AHCI_P_IX_DHRS	0x00000001 /* Device to Host FIS */
    202 
    203 #define AHCI_P_CMD(p)	(0x118 + AHCI_P_OFFSET(p)) /* Port command/status */
    204 #define		AHCI_P_CMD_ICC_MASK 0xf0000000 /* Interface Comm. Control */
    205 #define		AHCI_P_CMD_ICC_SL   0x60000000 /* State slumber */
    206 #define		AHCI_P_CMD_ICC_PA   0x20000000 /* State partial */
    207 #define		AHCI_P_CMD_ICC_AC   0x10000000 /* State active */
    208 #define		AHCI_P_CMD_ICC_NO   0x00000000 /* State idle/NOP */
    209 #define		AHCI_P_CMD_ASP	0x08000000 /* Agressive Slumber/Partial */
    210 #define		AHCI_P_CMD_ALPE	0x04000000 /* Agressive link power management */
    211 #define		AHCI_P_CMD_DLAE	0x02000000 /* drive LED on ATAPI */
    212 #define		AHCI_P_CMD_ATAP	0x01000000 /* Device is ATAPI */
    213 #define		AHCI_P_CMD_ESP	0x00200000 /* external SATA port */
    214 #define		AHCI_P_CMD_CPD	0x00100000 /* Cold presence detection */
    215 #define		AHCI_P_CMD_MPSP	0x00080000 /* Mechanical switch attached */
    216 #define		AHCI_P_CMD_HPCP	0x00040000 /* hot-plug capable */
    217 #define		AHCI_P_CMD_PMA	0x00020000 /* port multiplier attached */
    218 #define		AHCI_P_CMD_CPS	0x00010000 /* cold presence state */
    219 #define		AHCI_P_CMD_CR	0x00008000 /* command list running */
    220 #define		AHCI_P_CMD_FR	0x00004000 /* FIS receive running */
    221 #define		AHCI_P_CMD_MPSS	0x00002000 /* mechanical switch state */
    222 #define		AHCI_P_CMD_CCS_MASK 0x00001f00 /* current command slot */
    223 #define		AHCI_P_CMD_CCS_SHIFT 12
    224 #define		AHCI_P_CMD_FRE	0x00000010 /* FIS receive enable */
    225 #define		AHCI_P_CMD_CLO	0x00000008 /* command list override */
    226 #define		AHCI_P_CMD_POD	0x00000004 /* power on device */
    227 #define		AHCI_P_CMD_SUD	0x00000002 /* spin up device */
    228 #define		AHCI_P_CMD_ST	0x00000001 /* start */
    229 
    230 #define AHCI_P_TFD(p)	(0x120 + AHCI_P_OFFSET(p)) /* Port task file data */
    231 #define		AHCI_P_TFD_ERR_MASK	0x0000ff00 /* error register */
    232 #define		AHCI_P_TFD_ERR_SHIFT	8
    233 #define		AHCI_P_TFD_ST		0x000000ff /* status register */
    234 #define		AHCI_P_TFD_ST_SHIFT	0
    235 
    236 #define AHCI_P_SIG(p)	(0x124 + AHCI_P_OFFSET(p)) /* device signature */
    237 #define		AHCI_P_SIG_LBAH_MASK	0xff000000
    238 #define		AHCI_P_SIG_LBAH_SHIFT	24
    239 #define		AHCI_P_SIG_LBAM_MASK	0x00ff0000
    240 #define		AHCI_P_SIG_LBAM_SHIFT	16
    241 #define		AHCI_P_SIG_LBAL_MASK	0x0000ff00
    242 #define		AHCI_P_SIG_LBAL_SHIFT	8
    243 #define		AHCI_P_SIG_SC_MASK	0x000000ff
    244 #define		AHCI_P_SIG_SC_SHIFT	8
    245 
    246 #define AHCI_P_SSTS(p)	(0x128 + AHCI_P_OFFSET(p)) /* Serial ATA status */
    247 
    248 #define AHCI_P_SCTL(p)	(0x12c + AHCI_P_OFFSET(p)) /* Serial ATA control */
    249 
    250 #define AHCI_P_SERR(p)	(0x130 + AHCI_P_OFFSET(p)) /* Serial ATA error */
    251 
    252 #define AHCI_P_SACT(p)	(0x134 + AHCI_P_OFFSET(p)) /* Serial ATA active */
    253 	/* one bit per tag/command slot */
    254 
    255 #define AHCI_P_CI(p)	(0x138 + AHCI_P_OFFSET(p)) /* Command issued */
    256 	/* one bit per tag/command slot */
    257 
    258 #define AHCI_P_FNTF(p)	(0x13c + AHCI_P_OFFSET(p)) /* SNotification */
    259 	/* one bit per port */
    260