1*1cf4323eSThomas Huth #ifndef LIBQOS_AHCI_H 2*1cf4323eSThomas Huth #define LIBQOS_AHCI_H 3*1cf4323eSThomas Huth 4*1cf4323eSThomas Huth /* 5*1cf4323eSThomas Huth * AHCI qtest library functions and definitions 6*1cf4323eSThomas Huth * 7*1cf4323eSThomas Huth * Copyright (c) 2014 John Snow <jsnow@redhat.com> 8*1cf4323eSThomas Huth * 9*1cf4323eSThomas Huth * Permission is hereby granted, free of charge, to any person obtaining a copy 10*1cf4323eSThomas Huth * of this software and associated documentation files (the "Software"), to deal 11*1cf4323eSThomas Huth * in the Software without restriction, including without limitation the rights 12*1cf4323eSThomas Huth * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13*1cf4323eSThomas Huth * copies of the Software, and to permit persons to whom the Software is 14*1cf4323eSThomas Huth * furnished to do so, subject to the following conditions: 15*1cf4323eSThomas Huth * 16*1cf4323eSThomas Huth * The above copyright notice and this permission notice shall be included in 17*1cf4323eSThomas Huth * all copies or substantial portions of the Software. 18*1cf4323eSThomas Huth * 19*1cf4323eSThomas Huth * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20*1cf4323eSThomas Huth * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21*1cf4323eSThomas Huth * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22*1cf4323eSThomas Huth * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23*1cf4323eSThomas Huth * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24*1cf4323eSThomas Huth * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25*1cf4323eSThomas Huth * THE SOFTWARE. 26*1cf4323eSThomas Huth */ 27*1cf4323eSThomas Huth 28*1cf4323eSThomas Huth #include "libqos/libqos.h" 29*1cf4323eSThomas Huth #include "libqos/pci.h" 30*1cf4323eSThomas Huth #include "libqos/malloc-pc.h" 31*1cf4323eSThomas Huth 32*1cf4323eSThomas Huth /*** Supplementary PCI Config Space IDs & Masks ***/ 33*1cf4323eSThomas Huth #define PCI_DEVICE_ID_INTEL_Q35_AHCI (0x2922) 34*1cf4323eSThomas Huth #define PCI_MSI_FLAGS_RESERVED (0xFF00) 35*1cf4323eSThomas Huth #define PCI_PM_CTRL_RESERVED (0xFC) 36*1cf4323eSThomas Huth #define PCI_BCC(REG32) ((REG32) >> 24) 37*1cf4323eSThomas Huth #define PCI_PI(REG32) (((REG32) >> 8) & 0xFF) 38*1cf4323eSThomas Huth #define PCI_SCC(REG32) (((REG32) >> 16) & 0xFF) 39*1cf4323eSThomas Huth 40*1cf4323eSThomas Huth /*** Recognized AHCI Device Types ***/ 41*1cf4323eSThomas Huth #define AHCI_INTEL_ICH9 (PCI_DEVICE_ID_INTEL_Q35_AHCI << 16 | \ 42*1cf4323eSThomas Huth PCI_VENDOR_ID_INTEL) 43*1cf4323eSThomas Huth 44*1cf4323eSThomas Huth /*** AHCI/HBA Register Offsets and Bitmasks ***/ 45*1cf4323eSThomas Huth #define AHCI_CAP (0) 46*1cf4323eSThomas Huth #define AHCI_CAP_NP (0x1F) 47*1cf4323eSThomas Huth #define AHCI_CAP_SXS (0x20) 48*1cf4323eSThomas Huth #define AHCI_CAP_EMS (0x40) 49*1cf4323eSThomas Huth #define AHCI_CAP_CCCS (0x80) 50*1cf4323eSThomas Huth #define AHCI_CAP_NCS (0x1F00) 51*1cf4323eSThomas Huth #define AHCI_CAP_PSC (0x2000) 52*1cf4323eSThomas Huth #define AHCI_CAP_SSC (0x4000) 53*1cf4323eSThomas Huth #define AHCI_CAP_PMD (0x8000) 54*1cf4323eSThomas Huth #define AHCI_CAP_FBSS (0x10000) 55*1cf4323eSThomas Huth #define AHCI_CAP_SPM (0x20000) 56*1cf4323eSThomas Huth #define AHCI_CAP_SAM (0x40000) 57*1cf4323eSThomas Huth #define AHCI_CAP_RESERVED (0x80000) 58*1cf4323eSThomas Huth #define AHCI_CAP_ISS (0xF00000) 59*1cf4323eSThomas Huth #define AHCI_CAP_SCLO (0x1000000) 60*1cf4323eSThomas Huth #define AHCI_CAP_SAL (0x2000000) 61*1cf4323eSThomas Huth #define AHCI_CAP_SALP (0x4000000) 62*1cf4323eSThomas Huth #define AHCI_CAP_SSS (0x8000000) 63*1cf4323eSThomas Huth #define AHCI_CAP_SMPS (0x10000000) 64*1cf4323eSThomas Huth #define AHCI_CAP_SSNTF (0x20000000) 65*1cf4323eSThomas Huth #define AHCI_CAP_SNCQ (0x40000000) 66*1cf4323eSThomas Huth #define AHCI_CAP_S64A (0x80000000) 67*1cf4323eSThomas Huth 68*1cf4323eSThomas Huth #define AHCI_GHC (1) 69*1cf4323eSThomas Huth #define AHCI_GHC_HR (0x01) 70*1cf4323eSThomas Huth #define AHCI_GHC_IE (0x02) 71*1cf4323eSThomas Huth #define AHCI_GHC_MRSM (0x04) 72*1cf4323eSThomas Huth #define AHCI_GHC_RESERVED (0x7FFFFFF8) 73*1cf4323eSThomas Huth #define AHCI_GHC_AE (0x80000000) 74*1cf4323eSThomas Huth 75*1cf4323eSThomas Huth #define AHCI_IS (2) 76*1cf4323eSThomas Huth #define AHCI_PI (3) 77*1cf4323eSThomas Huth #define AHCI_VS (4) 78*1cf4323eSThomas Huth 79*1cf4323eSThomas Huth #define AHCI_CCCCTL (5) 80*1cf4323eSThomas Huth #define AHCI_CCCCTL_EN (0x01) 81*1cf4323eSThomas Huth #define AHCI_CCCCTL_RESERVED (0x06) 82*1cf4323eSThomas Huth #define AHCI_CCCCTL_CC (0xFF00) 83*1cf4323eSThomas Huth #define AHCI_CCCCTL_TV (0xFFFF0000) 84*1cf4323eSThomas Huth 85*1cf4323eSThomas Huth #define AHCI_CCCPORTS (6) 86*1cf4323eSThomas Huth #define AHCI_EMLOC (7) 87*1cf4323eSThomas Huth 88*1cf4323eSThomas Huth #define AHCI_EMCTL (8) 89*1cf4323eSThomas Huth #define AHCI_EMCTL_STSMR (0x01) 90*1cf4323eSThomas Huth #define AHCI_EMCTL_CTLTM (0x100) 91*1cf4323eSThomas Huth #define AHCI_EMCTL_CTLRST (0x200) 92*1cf4323eSThomas Huth #define AHCI_EMCTL_RESERVED (0xF0F0FCFE) 93*1cf4323eSThomas Huth 94*1cf4323eSThomas Huth #define AHCI_CAP2 (9) 95*1cf4323eSThomas Huth #define AHCI_CAP2_BOH (0x01) 96*1cf4323eSThomas Huth #define AHCI_CAP2_NVMP (0x02) 97*1cf4323eSThomas Huth #define AHCI_CAP2_APST (0x04) 98*1cf4323eSThomas Huth #define AHCI_CAP2_RESERVED (0xFFFFFFF8) 99*1cf4323eSThomas Huth 100*1cf4323eSThomas Huth #define AHCI_BOHC (10) 101*1cf4323eSThomas Huth #define AHCI_RESERVED (11) 102*1cf4323eSThomas Huth #define AHCI_NVMHCI (24) 103*1cf4323eSThomas Huth #define AHCI_VENDOR (40) 104*1cf4323eSThomas Huth #define AHCI_PORTS (64) 105*1cf4323eSThomas Huth 106*1cf4323eSThomas Huth /*** Port Memory Offsets & Bitmasks ***/ 107*1cf4323eSThomas Huth #define AHCI_PX_CLB (0) 108*1cf4323eSThomas Huth #define AHCI_PX_CLB_RESERVED (0x1FF) 109*1cf4323eSThomas Huth 110*1cf4323eSThomas Huth #define AHCI_PX_CLBU (1) 111*1cf4323eSThomas Huth 112*1cf4323eSThomas Huth #define AHCI_PX_FB (2) 113*1cf4323eSThomas Huth #define AHCI_PX_FB_RESERVED (0xFF) 114*1cf4323eSThomas Huth 115*1cf4323eSThomas Huth #define AHCI_PX_FBU (3) 116*1cf4323eSThomas Huth 117*1cf4323eSThomas Huth #define AHCI_PX_IS (4) 118*1cf4323eSThomas Huth #define AHCI_PX_IS_DHRS (0x1) 119*1cf4323eSThomas Huth #define AHCI_PX_IS_PSS (0x2) 120*1cf4323eSThomas Huth #define AHCI_PX_IS_DSS (0x4) 121*1cf4323eSThomas Huth #define AHCI_PX_IS_SDBS (0x8) 122*1cf4323eSThomas Huth #define AHCI_PX_IS_UFS (0x10) 123*1cf4323eSThomas Huth #define AHCI_PX_IS_DPS (0x20) 124*1cf4323eSThomas Huth #define AHCI_PX_IS_PCS (0x40) 125*1cf4323eSThomas Huth #define AHCI_PX_IS_DMPS (0x80) 126*1cf4323eSThomas Huth #define AHCI_PX_IS_RESERVED (0x23FFF00) 127*1cf4323eSThomas Huth #define AHCI_PX_IS_PRCS (0x400000) 128*1cf4323eSThomas Huth #define AHCI_PX_IS_IPMS (0x800000) 129*1cf4323eSThomas Huth #define AHCI_PX_IS_OFS (0x1000000) 130*1cf4323eSThomas Huth #define AHCI_PX_IS_INFS (0x4000000) 131*1cf4323eSThomas Huth #define AHCI_PX_IS_IFS (0x8000000) 132*1cf4323eSThomas Huth #define AHCI_PX_IS_HBDS (0x10000000) 133*1cf4323eSThomas Huth #define AHCI_PX_IS_HBFS (0x20000000) 134*1cf4323eSThomas Huth #define AHCI_PX_IS_TFES (0x40000000) 135*1cf4323eSThomas Huth #define AHCI_PX_IS_CPDS (0x80000000) 136*1cf4323eSThomas Huth 137*1cf4323eSThomas Huth #define AHCI_PX_IE (5) 138*1cf4323eSThomas Huth #define AHCI_PX_IE_DHRE (0x1) 139*1cf4323eSThomas Huth #define AHCI_PX_IE_PSE (0x2) 140*1cf4323eSThomas Huth #define AHCI_PX_IE_DSE (0x4) 141*1cf4323eSThomas Huth #define AHCI_PX_IE_SDBE (0x8) 142*1cf4323eSThomas Huth #define AHCI_PX_IE_UFE (0x10) 143*1cf4323eSThomas Huth #define AHCI_PX_IE_DPE (0x20) 144*1cf4323eSThomas Huth #define AHCI_PX_IE_PCE (0x40) 145*1cf4323eSThomas Huth #define AHCI_PX_IE_DMPE (0x80) 146*1cf4323eSThomas Huth #define AHCI_PX_IE_RESERVED (0x23FFF00) 147*1cf4323eSThomas Huth #define AHCI_PX_IE_PRCE (0x400000) 148*1cf4323eSThomas Huth #define AHCI_PX_IE_IPME (0x800000) 149*1cf4323eSThomas Huth #define AHCI_PX_IE_OFE (0x1000000) 150*1cf4323eSThomas Huth #define AHCI_PX_IE_INFE (0x4000000) 151*1cf4323eSThomas Huth #define AHCI_PX_IE_IFE (0x8000000) 152*1cf4323eSThomas Huth #define AHCI_PX_IE_HBDE (0x10000000) 153*1cf4323eSThomas Huth #define AHCI_PX_IE_HBFE (0x20000000) 154*1cf4323eSThomas Huth #define AHCI_PX_IE_TFEE (0x40000000) 155*1cf4323eSThomas Huth #define AHCI_PX_IE_CPDE (0x80000000) 156*1cf4323eSThomas Huth 157*1cf4323eSThomas Huth #define AHCI_PX_CMD (6) 158*1cf4323eSThomas Huth #define AHCI_PX_CMD_ST (0x1) 159*1cf4323eSThomas Huth #define AHCI_PX_CMD_SUD (0x2) 160*1cf4323eSThomas Huth #define AHCI_PX_CMD_POD (0x4) 161*1cf4323eSThomas Huth #define AHCI_PX_CMD_CLO (0x8) 162*1cf4323eSThomas Huth #define AHCI_PX_CMD_FRE (0x10) 163*1cf4323eSThomas Huth #define AHCI_PX_CMD_RESERVED (0xE0) 164*1cf4323eSThomas Huth #define AHCI_PX_CMD_CCS (0x1F00) 165*1cf4323eSThomas Huth #define AHCI_PX_CMD_MPSS (0x2000) 166*1cf4323eSThomas Huth #define AHCI_PX_CMD_FR (0x4000) 167*1cf4323eSThomas Huth #define AHCI_PX_CMD_CR (0x8000) 168*1cf4323eSThomas Huth #define AHCI_PX_CMD_CPS (0x10000) 169*1cf4323eSThomas Huth #define AHCI_PX_CMD_PMA (0x20000) 170*1cf4323eSThomas Huth #define AHCI_PX_CMD_HPCP (0x40000) 171*1cf4323eSThomas Huth #define AHCI_PX_CMD_MPSP (0x80000) 172*1cf4323eSThomas Huth #define AHCI_PX_CMD_CPD (0x100000) 173*1cf4323eSThomas Huth #define AHCI_PX_CMD_ESP (0x200000) 174*1cf4323eSThomas Huth #define AHCI_PX_CMD_FBSCP (0x400000) 175*1cf4323eSThomas Huth #define AHCI_PX_CMD_APSTE (0x800000) 176*1cf4323eSThomas Huth #define AHCI_PX_CMD_ATAPI (0x1000000) 177*1cf4323eSThomas Huth #define AHCI_PX_CMD_DLAE (0x2000000) 178*1cf4323eSThomas Huth #define AHCI_PX_CMD_ALPE (0x4000000) 179*1cf4323eSThomas Huth #define AHCI_PX_CMD_ASP (0x8000000) 180*1cf4323eSThomas Huth #define AHCI_PX_CMD_ICC (0xF0000000) 181*1cf4323eSThomas Huth 182*1cf4323eSThomas Huth #define AHCI_PX_RES1 (7) 183*1cf4323eSThomas Huth 184*1cf4323eSThomas Huth #define AHCI_PX_TFD (8) 185*1cf4323eSThomas Huth #define AHCI_PX_TFD_STS (0xFF) 186*1cf4323eSThomas Huth #define AHCI_PX_TFD_STS_ERR (0x01) 187*1cf4323eSThomas Huth #define AHCI_PX_TFD_STS_CS1 (0x06) 188*1cf4323eSThomas Huth #define AHCI_PX_TFD_STS_DRQ (0x08) 189*1cf4323eSThomas Huth #define AHCI_PX_TFD_STS_CS2 (0x70) 190*1cf4323eSThomas Huth #define AHCI_PX_TFD_STS_BSY (0x80) 191*1cf4323eSThomas Huth #define AHCI_PX_TFD_ERR (0xFF00) 192*1cf4323eSThomas Huth #define AHCI_PX_TFD_RESERVED (0xFFFF0000) 193*1cf4323eSThomas Huth 194*1cf4323eSThomas Huth #define AHCI_PX_SIG (9) 195*1cf4323eSThomas Huth #define AHCI_PX_SIG_SECTOR_COUNT (0xFF) 196*1cf4323eSThomas Huth #define AHCI_PX_SIG_LBA_LOW (0xFF00) 197*1cf4323eSThomas Huth #define AHCI_PX_SIG_LBA_MID (0xFF0000) 198*1cf4323eSThomas Huth #define AHCI_PX_SIG_LBA_HIGH (0xFF000000) 199*1cf4323eSThomas Huth 200*1cf4323eSThomas Huth #define AHCI_PX_SSTS (10) 201*1cf4323eSThomas Huth #define AHCI_PX_SSTS_DET (0x0F) 202*1cf4323eSThomas Huth #define AHCI_PX_SSTS_SPD (0xF0) 203*1cf4323eSThomas Huth #define AHCI_PX_SSTS_IPM (0xF00) 204*1cf4323eSThomas Huth #define AHCI_PX_SSTS_RESERVED (0xFFFFF000) 205*1cf4323eSThomas Huth #define SSTS_DET_NO_DEVICE (0x00) 206*1cf4323eSThomas Huth #define SSTS_DET_PRESENT (0x01) 207*1cf4323eSThomas Huth #define SSTS_DET_ESTABLISHED (0x03) 208*1cf4323eSThomas Huth #define SSTS_DET_OFFLINE (0x04) 209*1cf4323eSThomas Huth 210*1cf4323eSThomas Huth #define AHCI_PX_SCTL (11) 211*1cf4323eSThomas Huth 212*1cf4323eSThomas Huth #define AHCI_PX_SERR (12) 213*1cf4323eSThomas Huth #define AHCI_PX_SERR_ERR (0xFFFF) 214*1cf4323eSThomas Huth #define AHCI_PX_SERR_DIAG (0xFFFF0000) 215*1cf4323eSThomas Huth #define AHCI_PX_SERR_DIAG_X (0x04000000) 216*1cf4323eSThomas Huth 217*1cf4323eSThomas Huth #define AHCI_PX_SACT (13) 218*1cf4323eSThomas Huth #define AHCI_PX_CI (14) 219*1cf4323eSThomas Huth #define AHCI_PX_SNTF (15) 220*1cf4323eSThomas Huth 221*1cf4323eSThomas Huth #define AHCI_PX_FBS (16) 222*1cf4323eSThomas Huth #define AHCI_PX_FBS_EN (0x1) 223*1cf4323eSThomas Huth #define AHCI_PX_FBS_DEC (0x2) 224*1cf4323eSThomas Huth #define AHCI_PX_FBS_SDE (0x4) 225*1cf4323eSThomas Huth #define AHCI_PX_FBS_DEV (0xF00) 226*1cf4323eSThomas Huth #define AHCI_PX_FBS_ADO (0xF000) 227*1cf4323eSThomas Huth #define AHCI_PX_FBS_DWE (0xF0000) 228*1cf4323eSThomas Huth #define AHCI_PX_FBS_RESERVED (0xFFF000F8) 229*1cf4323eSThomas Huth 230*1cf4323eSThomas Huth #define AHCI_PX_RES2 (17) 231*1cf4323eSThomas Huth #define AHCI_PX_VS (28) 232*1cf4323eSThomas Huth 233*1cf4323eSThomas Huth #define HBA_DATA_REGION_SIZE (256) 234*1cf4323eSThomas Huth #define HBA_PORT_DATA_SIZE (128) 235*1cf4323eSThomas Huth #define HBA_PORT_NUM_REG (HBA_PORT_DATA_SIZE/4) 236*1cf4323eSThomas Huth 237*1cf4323eSThomas Huth #define AHCI_VERSION_0_95 (0x00000905) 238*1cf4323eSThomas Huth #define AHCI_VERSION_1_0 (0x00010000) 239*1cf4323eSThomas Huth #define AHCI_VERSION_1_1 (0x00010100) 240*1cf4323eSThomas Huth #define AHCI_VERSION_1_2 (0x00010200) 241*1cf4323eSThomas Huth #define AHCI_VERSION_1_3 (0x00010300) 242*1cf4323eSThomas Huth 243*1cf4323eSThomas Huth #define AHCI_SECTOR_SIZE (512) 244*1cf4323eSThomas Huth #define ATAPI_SECTOR_SIZE (2048) 245*1cf4323eSThomas Huth 246*1cf4323eSThomas Huth #define AHCI_SIGNATURE_CDROM (0xeb140101) 247*1cf4323eSThomas Huth #define AHCI_SIGNATURE_DISK (0x00000101) 248*1cf4323eSThomas Huth 249*1cf4323eSThomas Huth /* FIS types */ 250*1cf4323eSThomas Huth enum { 251*1cf4323eSThomas Huth REG_H2D_FIS = 0x27, 252*1cf4323eSThomas Huth REG_D2H_FIS = 0x34, 253*1cf4323eSThomas Huth DMA_ACTIVATE_FIS = 0x39, 254*1cf4323eSThomas Huth DMA_SETUP_FIS = 0x41, 255*1cf4323eSThomas Huth DATA_FIS = 0x46, 256*1cf4323eSThomas Huth BIST_ACTIVATE_FIS = 0x58, 257*1cf4323eSThomas Huth PIO_SETUP_FIS = 0x5F, 258*1cf4323eSThomas Huth SDB_FIS = 0xA1 259*1cf4323eSThomas Huth }; 260*1cf4323eSThomas Huth 261*1cf4323eSThomas Huth /* FIS flags */ 262*1cf4323eSThomas Huth #define REG_H2D_FIS_CMD 0x80 263*1cf4323eSThomas Huth 264*1cf4323eSThomas Huth /* ATA Commands */ 265*1cf4323eSThomas Huth enum { 266*1cf4323eSThomas Huth /* DMA */ 267*1cf4323eSThomas Huth CMD_READ_DMA = 0xC8, 268*1cf4323eSThomas Huth CMD_READ_DMA_EXT = 0x25, 269*1cf4323eSThomas Huth CMD_WRITE_DMA = 0xCA, 270*1cf4323eSThomas Huth CMD_WRITE_DMA_EXT = 0x35, 271*1cf4323eSThomas Huth /* PIO */ 272*1cf4323eSThomas Huth CMD_READ_PIO = 0x20, 273*1cf4323eSThomas Huth CMD_READ_PIO_EXT = 0x24, 274*1cf4323eSThomas Huth CMD_WRITE_PIO = 0x30, 275*1cf4323eSThomas Huth CMD_WRITE_PIO_EXT = 0x34, 276*1cf4323eSThomas Huth /* Misc */ 277*1cf4323eSThomas Huth CMD_READ_MAX = 0xF8, 278*1cf4323eSThomas Huth CMD_READ_MAX_EXT = 0x27, 279*1cf4323eSThomas Huth CMD_FLUSH_CACHE = 0xE7, 280*1cf4323eSThomas Huth CMD_IDENTIFY = 0xEC, 281*1cf4323eSThomas Huth CMD_PACKET = 0xA0, 282*1cf4323eSThomas Huth CMD_PACKET_ID = 0xA1, 283*1cf4323eSThomas Huth /* NCQ */ 284*1cf4323eSThomas Huth READ_FPDMA_QUEUED = 0x60, 285*1cf4323eSThomas Huth WRITE_FPDMA_QUEUED = 0x61, 286*1cf4323eSThomas Huth }; 287*1cf4323eSThomas Huth 288*1cf4323eSThomas Huth /* ATAPI Commands */ 289*1cf4323eSThomas Huth enum { 290*1cf4323eSThomas Huth CMD_ATAPI_TEST_UNIT_READY = 0x00, 291*1cf4323eSThomas Huth CMD_ATAPI_REQUEST_SENSE = 0x03, 292*1cf4323eSThomas Huth CMD_ATAPI_START_STOP_UNIT = 0x1b, 293*1cf4323eSThomas Huth CMD_ATAPI_READ_10 = 0x28, 294*1cf4323eSThomas Huth CMD_ATAPI_READ_CD = 0xbe, 295*1cf4323eSThomas Huth }; 296*1cf4323eSThomas Huth 297*1cf4323eSThomas Huth enum { 298*1cf4323eSThomas Huth SENSE_NO_SENSE = 0x00, 299*1cf4323eSThomas Huth SENSE_NOT_READY = 0x02, 300*1cf4323eSThomas Huth SENSE_UNIT_ATTENTION = 0x06, 301*1cf4323eSThomas Huth }; 302*1cf4323eSThomas Huth 303*1cf4323eSThomas Huth enum { 304*1cf4323eSThomas Huth ASC_MEDIUM_MAY_HAVE_CHANGED = 0x28, 305*1cf4323eSThomas Huth ASC_MEDIUM_NOT_PRESENT = 0x3a, 306*1cf4323eSThomas Huth }; 307*1cf4323eSThomas Huth 308*1cf4323eSThomas Huth /* AHCI Command Header Flags & Masks*/ 309*1cf4323eSThomas Huth #define CMDH_CFL (0x1F) 310*1cf4323eSThomas Huth #define CMDH_ATAPI (0x20) 311*1cf4323eSThomas Huth #define CMDH_WRITE (0x40) 312*1cf4323eSThomas Huth #define CMDH_PREFETCH (0x80) 313*1cf4323eSThomas Huth #define CMDH_RESET (0x100) 314*1cf4323eSThomas Huth #define CMDH_BIST (0x200) 315*1cf4323eSThomas Huth #define CMDH_CLR_BSY (0x400) 316*1cf4323eSThomas Huth #define CMDH_RES (0x800) 317*1cf4323eSThomas Huth #define CMDH_PMP (0xF000) 318*1cf4323eSThomas Huth 319*1cf4323eSThomas Huth /* ATA device register masks */ 320*1cf4323eSThomas Huth #define ATA_DEVICE_MAGIC 0xA0 /* used in ata1-3 */ 321*1cf4323eSThomas Huth #define ATA_DEVICE_LBA 0x40 322*1cf4323eSThomas Huth #define NCQ_DEVICE_MAGIC 0x40 /* for ncq device registers */ 323*1cf4323eSThomas Huth #define ATA_DEVICE_DRIVE 0x10 324*1cf4323eSThomas Huth #define ATA_DEVICE_HEAD 0x0F 325*1cf4323eSThomas Huth 326*1cf4323eSThomas Huth /*** Structures ***/ 327*1cf4323eSThomas Huth 328*1cf4323eSThomas Huth typedef struct AHCIPortQState { 329*1cf4323eSThomas Huth uint64_t fb; 330*1cf4323eSThomas Huth uint64_t clb; 331*1cf4323eSThomas Huth uint64_t ctba[32]; 332*1cf4323eSThomas Huth uint16_t prdtl[32]; 333*1cf4323eSThomas Huth uint8_t next; /** Next Command Slot to Use **/ 334*1cf4323eSThomas Huth } AHCIPortQState; 335*1cf4323eSThomas Huth 336*1cf4323eSThomas Huth typedef struct AHCIQState { 337*1cf4323eSThomas Huth QOSState *parent; 338*1cf4323eSThomas Huth QPCIDevice *dev; 339*1cf4323eSThomas Huth QPCIBar hba_bar; 340*1cf4323eSThomas Huth uint64_t barsize; 341*1cf4323eSThomas Huth uint32_t fingerprint; 342*1cf4323eSThomas Huth uint32_t cap; 343*1cf4323eSThomas Huth uint32_t cap2; 344*1cf4323eSThomas Huth AHCIPortQState port[32]; 345*1cf4323eSThomas Huth bool enabled; 346*1cf4323eSThomas Huth } AHCIQState; 347*1cf4323eSThomas Huth 348*1cf4323eSThomas Huth /** 349*1cf4323eSThomas Huth * Generic FIS structure. 350*1cf4323eSThomas Huth */ 351*1cf4323eSThomas Huth typedef struct FIS { 352*1cf4323eSThomas Huth uint8_t fis_type; 353*1cf4323eSThomas Huth uint8_t flags; 354*1cf4323eSThomas Huth char data[0]; 355*1cf4323eSThomas Huth } __attribute__((__packed__)) FIS; 356*1cf4323eSThomas Huth 357*1cf4323eSThomas Huth /** 358*1cf4323eSThomas Huth * Register device-to-host FIS structure. 359*1cf4323eSThomas Huth */ 360*1cf4323eSThomas Huth typedef struct RegD2HFIS { 361*1cf4323eSThomas Huth /* DW0 */ 362*1cf4323eSThomas Huth uint8_t fis_type; 363*1cf4323eSThomas Huth uint8_t flags; 364*1cf4323eSThomas Huth uint8_t status; 365*1cf4323eSThomas Huth uint8_t error; 366*1cf4323eSThomas Huth /* DW1 */ 367*1cf4323eSThomas Huth uint8_t lba_lo[3]; 368*1cf4323eSThomas Huth uint8_t device; 369*1cf4323eSThomas Huth /* DW2 */ 370*1cf4323eSThomas Huth uint8_t lba_hi[3]; 371*1cf4323eSThomas Huth uint8_t res0; 372*1cf4323eSThomas Huth /* DW3 */ 373*1cf4323eSThomas Huth uint16_t count; 374*1cf4323eSThomas Huth uint16_t res1; 375*1cf4323eSThomas Huth /* DW4 */ 376*1cf4323eSThomas Huth uint32_t res2; 377*1cf4323eSThomas Huth } __attribute__((__packed__)) RegD2HFIS; 378*1cf4323eSThomas Huth 379*1cf4323eSThomas Huth /** 380*1cf4323eSThomas Huth * Register device-to-host FIS structure; 381*1cf4323eSThomas Huth * PIO Setup variety. 382*1cf4323eSThomas Huth */ 383*1cf4323eSThomas Huth typedef struct PIOSetupFIS { 384*1cf4323eSThomas Huth /* DW0 */ 385*1cf4323eSThomas Huth uint8_t fis_type; 386*1cf4323eSThomas Huth uint8_t flags; 387*1cf4323eSThomas Huth uint8_t status; 388*1cf4323eSThomas Huth uint8_t error; 389*1cf4323eSThomas Huth /* DW1 */ 390*1cf4323eSThomas Huth uint8_t lba_lo[3]; 391*1cf4323eSThomas Huth uint8_t device; 392*1cf4323eSThomas Huth /* DW2 */ 393*1cf4323eSThomas Huth uint8_t lba_hi[3]; 394*1cf4323eSThomas Huth uint8_t res0; 395*1cf4323eSThomas Huth /* DW3 */ 396*1cf4323eSThomas Huth uint16_t count; 397*1cf4323eSThomas Huth uint8_t res1; 398*1cf4323eSThomas Huth uint8_t e_status; 399*1cf4323eSThomas Huth /* DW4 */ 400*1cf4323eSThomas Huth uint16_t tx_count; 401*1cf4323eSThomas Huth uint16_t res2; 402*1cf4323eSThomas Huth } __attribute__((__packed__)) PIOSetupFIS; 403*1cf4323eSThomas Huth 404*1cf4323eSThomas Huth /** 405*1cf4323eSThomas Huth * Register host-to-device FIS structure. 406*1cf4323eSThomas Huth */ 407*1cf4323eSThomas Huth typedef struct RegH2DFIS { 408*1cf4323eSThomas Huth /* DW0 */ 409*1cf4323eSThomas Huth uint8_t fis_type; 410*1cf4323eSThomas Huth uint8_t flags; 411*1cf4323eSThomas Huth uint8_t command; 412*1cf4323eSThomas Huth uint8_t feature_low; 413*1cf4323eSThomas Huth /* DW1 */ 414*1cf4323eSThomas Huth uint8_t lba_lo[3]; 415*1cf4323eSThomas Huth uint8_t device; 416*1cf4323eSThomas Huth /* DW2 */ 417*1cf4323eSThomas Huth uint8_t lba_hi[3]; 418*1cf4323eSThomas Huth uint8_t feature_high; 419*1cf4323eSThomas Huth /* DW3 */ 420*1cf4323eSThomas Huth uint16_t count; 421*1cf4323eSThomas Huth uint8_t icc; 422*1cf4323eSThomas Huth uint8_t control; 423*1cf4323eSThomas Huth /* DW4 */ 424*1cf4323eSThomas Huth uint8_t aux[4]; 425*1cf4323eSThomas Huth } __attribute__((__packed__)) RegH2DFIS; 426*1cf4323eSThomas Huth 427*1cf4323eSThomas Huth /** 428*1cf4323eSThomas Huth * Register host-to-device FIS structure, for NCQ commands. 429*1cf4323eSThomas Huth * Actually just a RegH2DFIS, but with fields repurposed. 430*1cf4323eSThomas Huth * Repurposed fields are annotated below. 431*1cf4323eSThomas Huth */ 432*1cf4323eSThomas Huth typedef struct NCQFIS { 433*1cf4323eSThomas Huth /* DW0 */ 434*1cf4323eSThomas Huth uint8_t fis_type; 435*1cf4323eSThomas Huth uint8_t flags; 436*1cf4323eSThomas Huth uint8_t command; 437*1cf4323eSThomas Huth uint8_t sector_low; /* H2D: Feature 7:0 */ 438*1cf4323eSThomas Huth /* DW1 */ 439*1cf4323eSThomas Huth uint8_t lba_lo[3]; 440*1cf4323eSThomas Huth uint8_t device; 441*1cf4323eSThomas Huth /* DW2 */ 442*1cf4323eSThomas Huth uint8_t lba_hi[3]; 443*1cf4323eSThomas Huth uint8_t sector_hi; /* H2D: Feature 15:8 */ 444*1cf4323eSThomas Huth /* DW3 */ 445*1cf4323eSThomas Huth uint8_t tag; /* H2D: Count 0:7 */ 446*1cf4323eSThomas Huth uint8_t prio; /* H2D: Count 15:8 */ 447*1cf4323eSThomas Huth uint8_t icc; 448*1cf4323eSThomas Huth uint8_t control; 449*1cf4323eSThomas Huth /* DW4 */ 450*1cf4323eSThomas Huth uint8_t aux[4]; 451*1cf4323eSThomas Huth } __attribute__((__packed__)) NCQFIS; 452*1cf4323eSThomas Huth 453*1cf4323eSThomas Huth /** 454*1cf4323eSThomas Huth * Command List entry structure. 455*1cf4323eSThomas Huth * The command list contains between 1-32 of these structures. 456*1cf4323eSThomas Huth */ 457*1cf4323eSThomas Huth typedef struct AHCICommandHeader { 458*1cf4323eSThomas Huth uint16_t flags; /* Cmd-Fis-Len, PMP#, and flags. */ 459*1cf4323eSThomas Huth uint16_t prdtl; /* Phys Region Desc. Table Length */ 460*1cf4323eSThomas Huth uint32_t prdbc; /* Phys Region Desc. Byte Count */ 461*1cf4323eSThomas Huth uint64_t ctba; /* Command Table Descriptor Base Address */ 462*1cf4323eSThomas Huth uint32_t res[4]; 463*1cf4323eSThomas Huth } __attribute__((__packed__)) AHCICommandHeader; 464*1cf4323eSThomas Huth 465*1cf4323eSThomas Huth /** 466*1cf4323eSThomas Huth * Physical Region Descriptor; pointed to by the Command List Header, 467*1cf4323eSThomas Huth * struct ahci_command. 468*1cf4323eSThomas Huth */ 469*1cf4323eSThomas Huth typedef struct PRD { 470*1cf4323eSThomas Huth uint64_t dba; /* Data Base Address */ 471*1cf4323eSThomas Huth uint32_t res; /* Reserved */ 472*1cf4323eSThomas Huth uint32_t dbc; /* Data Byte Count (0-indexed) & Interrupt Flag (bit 2^31) */ 473*1cf4323eSThomas Huth } __attribute__((__packed__)) PRD; 474*1cf4323eSThomas Huth 475*1cf4323eSThomas Huth /* Opaque, defined within ahci.c */ 476*1cf4323eSThomas Huth typedef struct AHCICommand AHCICommand; 477*1cf4323eSThomas Huth 478*1cf4323eSThomas Huth /* Options to ahci_exec */ 479*1cf4323eSThomas Huth typedef struct AHCIOpts { 480*1cf4323eSThomas Huth size_t size; /* Size of transfer */ 481*1cf4323eSThomas Huth unsigned prd_size; /* Size per-each PRD */ 482*1cf4323eSThomas Huth bool set_bcl; /* Override the default BCL of ATAPI_SECTOR_SIZE */ 483*1cf4323eSThomas Huth unsigned bcl; /* Byte Count Limit, for ATAPI PIO */ 484*1cf4323eSThomas Huth uint64_t lba; /* Starting LBA offset */ 485*1cf4323eSThomas Huth uint64_t buffer; /* Pointer to source or destination guest buffer */ 486*1cf4323eSThomas Huth bool atapi; /* ATAPI command? */ 487*1cf4323eSThomas Huth bool atapi_dma; /* Use DMA for ATAPI? */ 488*1cf4323eSThomas Huth bool error; 489*1cf4323eSThomas Huth int (*pre_cb)(AHCIQState*, AHCICommand*, const struct AHCIOpts *); 490*1cf4323eSThomas Huth int (*mid_cb)(AHCIQState*, AHCICommand*, const struct AHCIOpts *); 491*1cf4323eSThomas Huth int (*post_cb)(AHCIQState*, AHCICommand*, const struct AHCIOpts *); 492*1cf4323eSThomas Huth void *opaque; 493*1cf4323eSThomas Huth } AHCIOpts; 494*1cf4323eSThomas Huth 495*1cf4323eSThomas Huth /*** Macro Utilities ***/ 496*1cf4323eSThomas Huth #define BITANY(data, mask) (((data) & (mask)) != 0) 497*1cf4323eSThomas Huth #define BITSET(data, mask) (((data) & (mask)) == (mask)) 498*1cf4323eSThomas Huth #define BITCLR(data, mask) (((data) & (mask)) == 0) 499*1cf4323eSThomas Huth #define ASSERT_BIT_SET(data, mask) g_assert_cmphex((data) & (mask), ==, (mask)) 500*1cf4323eSThomas Huth #define ASSERT_BIT_CLEAR(data, mask) g_assert_cmphex((data) & (mask), ==, 0) 501*1cf4323eSThomas Huth 502*1cf4323eSThomas Huth /* For calculating how big the PRD table needs to be: */ 503*1cf4323eSThomas Huth #define CMD_TBL_SIZ(n) ((0x80 + ((n) * sizeof(PRD)) + 0x7F) & ~0x7F) 504*1cf4323eSThomas Huth 505*1cf4323eSThomas Huth /* Helpers for reading/writing AHCI HBA register values */ 506*1cf4323eSThomas Huth 507*1cf4323eSThomas Huth static inline uint32_t ahci_mread(AHCIQState *ahci, size_t offset) 508*1cf4323eSThomas Huth { 509*1cf4323eSThomas Huth return qpci_io_readl(ahci->dev, ahci->hba_bar, offset); 510*1cf4323eSThomas Huth } 511*1cf4323eSThomas Huth 512*1cf4323eSThomas Huth static inline void ahci_mwrite(AHCIQState *ahci, size_t offset, uint32_t value) 513*1cf4323eSThomas Huth { 514*1cf4323eSThomas Huth qpci_io_writel(ahci->dev, ahci->hba_bar, offset, value); 515*1cf4323eSThomas Huth } 516*1cf4323eSThomas Huth 517*1cf4323eSThomas Huth static inline uint32_t ahci_rreg(AHCIQState *ahci, uint32_t reg_num) 518*1cf4323eSThomas Huth { 519*1cf4323eSThomas Huth return ahci_mread(ahci, 4 * reg_num); 520*1cf4323eSThomas Huth } 521*1cf4323eSThomas Huth 522*1cf4323eSThomas Huth static inline void ahci_wreg(AHCIQState *ahci, uint32_t reg_num, uint32_t value) 523*1cf4323eSThomas Huth { 524*1cf4323eSThomas Huth ahci_mwrite(ahci, 4 * reg_num, value); 525*1cf4323eSThomas Huth } 526*1cf4323eSThomas Huth 527*1cf4323eSThomas Huth static inline void ahci_set(AHCIQState *ahci, uint32_t reg_num, uint32_t mask) 528*1cf4323eSThomas Huth { 529*1cf4323eSThomas Huth ahci_wreg(ahci, reg_num, ahci_rreg(ahci, reg_num) | mask); 530*1cf4323eSThomas Huth } 531*1cf4323eSThomas Huth 532*1cf4323eSThomas Huth static inline void ahci_clr(AHCIQState *ahci, uint32_t reg_num, uint32_t mask) 533*1cf4323eSThomas Huth { 534*1cf4323eSThomas Huth ahci_wreg(ahci, reg_num, ahci_rreg(ahci, reg_num) & ~mask); 535*1cf4323eSThomas Huth } 536*1cf4323eSThomas Huth 537*1cf4323eSThomas Huth static inline size_t ahci_px_offset(uint8_t port, uint32_t reg_num) 538*1cf4323eSThomas Huth { 539*1cf4323eSThomas Huth return AHCI_PORTS + (HBA_PORT_NUM_REG * port) + reg_num; 540*1cf4323eSThomas Huth } 541*1cf4323eSThomas Huth 542*1cf4323eSThomas Huth static inline uint32_t ahci_px_rreg(AHCIQState *ahci, uint8_t port, 543*1cf4323eSThomas Huth uint32_t reg_num) 544*1cf4323eSThomas Huth { 545*1cf4323eSThomas Huth return ahci_rreg(ahci, ahci_px_offset(port, reg_num)); 546*1cf4323eSThomas Huth } 547*1cf4323eSThomas Huth 548*1cf4323eSThomas Huth static inline void ahci_px_wreg(AHCIQState *ahci, uint8_t port, 549*1cf4323eSThomas Huth uint32_t reg_num, uint32_t value) 550*1cf4323eSThomas Huth { 551*1cf4323eSThomas Huth ahci_wreg(ahci, ahci_px_offset(port, reg_num), value); 552*1cf4323eSThomas Huth } 553*1cf4323eSThomas Huth 554*1cf4323eSThomas Huth static inline void ahci_px_set(AHCIQState *ahci, uint8_t port, 555*1cf4323eSThomas Huth uint32_t reg_num, uint32_t mask) 556*1cf4323eSThomas Huth { 557*1cf4323eSThomas Huth ahci_px_wreg(ahci, port, reg_num, 558*1cf4323eSThomas Huth ahci_px_rreg(ahci, port, reg_num) | mask); 559*1cf4323eSThomas Huth } 560*1cf4323eSThomas Huth 561*1cf4323eSThomas Huth static inline void ahci_px_clr(AHCIQState *ahci, uint8_t port, 562*1cf4323eSThomas Huth uint32_t reg_num, uint32_t mask) 563*1cf4323eSThomas Huth { 564*1cf4323eSThomas Huth ahci_px_wreg(ahci, port, reg_num, 565*1cf4323eSThomas Huth ahci_px_rreg(ahci, port, reg_num) & ~mask); 566*1cf4323eSThomas Huth } 567*1cf4323eSThomas Huth 568*1cf4323eSThomas Huth /*** Prototypes ***/ 569*1cf4323eSThomas Huth uint64_t ahci_alloc(AHCIQState *ahci, size_t bytes); 570*1cf4323eSThomas Huth void ahci_free(AHCIQState *ahci, uint64_t addr); 571*1cf4323eSThomas Huth void ahci_clean_mem(AHCIQState *ahci); 572*1cf4323eSThomas Huth 573*1cf4323eSThomas Huth /* Device management */ 574*1cf4323eSThomas Huth QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint); 575*1cf4323eSThomas Huth void free_ahci_device(QPCIDevice *dev); 576*1cf4323eSThomas Huth void ahci_pci_enable(AHCIQState *ahci); 577*1cf4323eSThomas Huth void start_ahci_device(AHCIQState *ahci); 578*1cf4323eSThomas Huth void ahci_hba_enable(AHCIQState *ahci); 579*1cf4323eSThomas Huth 580*1cf4323eSThomas Huth /* Port Management */ 581*1cf4323eSThomas Huth unsigned ahci_port_select(AHCIQState *ahci); 582*1cf4323eSThomas Huth void ahci_port_clear(AHCIQState *ahci, uint8_t port); 583*1cf4323eSThomas Huth 584*1cf4323eSThomas Huth /* Command header / table management */ 585*1cf4323eSThomas Huth unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port); 586*1cf4323eSThomas Huth void ahci_get_command_header(AHCIQState *ahci, uint8_t port, 587*1cf4323eSThomas Huth uint8_t slot, AHCICommandHeader *cmd); 588*1cf4323eSThomas Huth void ahci_set_command_header(AHCIQState *ahci, uint8_t port, 589*1cf4323eSThomas Huth uint8_t slot, AHCICommandHeader *cmd); 590*1cf4323eSThomas Huth void ahci_destroy_command(AHCIQState *ahci, uint8_t port, uint8_t slot); 591*1cf4323eSThomas Huth 592*1cf4323eSThomas Huth /* AHCI sanity check routines */ 593*1cf4323eSThomas Huth void ahci_port_check_error(AHCIQState *ahci, uint8_t port, 594*1cf4323eSThomas Huth uint32_t imask, uint8_t emask); 595*1cf4323eSThomas Huth void ahci_port_check_interrupts(AHCIQState *ahci, uint8_t port, 596*1cf4323eSThomas Huth uint32_t intr_mask); 597*1cf4323eSThomas Huth void ahci_port_check_nonbusy(AHCIQState *ahci, uint8_t port, uint8_t slot); 598*1cf4323eSThomas Huth void ahci_port_check_d2h_sanity(AHCIQState *ahci, uint8_t port, uint8_t slot); 599*1cf4323eSThomas Huth void ahci_port_check_pio_sanity(AHCIQState *ahci, AHCICommand *cmd); 600*1cf4323eSThomas Huth void ahci_port_check_cmd_sanity(AHCIQState *ahci, AHCICommand *cmd); 601*1cf4323eSThomas Huth 602*1cf4323eSThomas Huth /* Misc */ 603*1cf4323eSThomas Huth bool is_atapi(AHCIQState *ahci, uint8_t port); 604*1cf4323eSThomas Huth unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd); 605*1cf4323eSThomas Huth 606*1cf4323eSThomas Huth /* Command: Macro level execution */ 607*1cf4323eSThomas Huth void ahci_guest_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd, 608*1cf4323eSThomas Huth uint64_t gbuffer, size_t size, uint64_t sector); 609*1cf4323eSThomas Huth AHCICommand *ahci_guest_io_halt(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd, 610*1cf4323eSThomas Huth uint64_t gbuffer, size_t size, uint64_t sector); 611*1cf4323eSThomas Huth void ahci_guest_io_resume(AHCIQState *ahci, AHCICommand *cmd); 612*1cf4323eSThomas Huth void ahci_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd, 613*1cf4323eSThomas Huth void *buffer, size_t bufsize, uint64_t sector); 614*1cf4323eSThomas Huth void ahci_exec(AHCIQState *ahci, uint8_t port, 615*1cf4323eSThomas Huth uint8_t op, const AHCIOpts *opts); 616*1cf4323eSThomas Huth void ahci_atapi_test_ready(AHCIQState *ahci, uint8_t port, bool ready, 617*1cf4323eSThomas Huth uint8_t expected_sense); 618*1cf4323eSThomas Huth void ahci_atapi_get_sense(AHCIQState *ahci, uint8_t port, 619*1cf4323eSThomas Huth uint8_t *sense, uint8_t *asc); 620*1cf4323eSThomas Huth void ahci_atapi_eject(AHCIQState *ahci, uint8_t port); 621*1cf4323eSThomas Huth void ahci_atapi_load(AHCIQState *ahci, uint8_t port); 622*1cf4323eSThomas Huth 623*1cf4323eSThomas Huth /* Command: Fine-grained lifecycle */ 624*1cf4323eSThomas Huth AHCICommand *ahci_command_create(uint8_t command_name); 625*1cf4323eSThomas Huth AHCICommand *ahci_atapi_command_create(uint8_t scsi_cmd, uint16_t bcl, bool dma); 626*1cf4323eSThomas Huth void ahci_command_commit(AHCIQState *ahci, AHCICommand *cmd, uint8_t port); 627*1cf4323eSThomas Huth void ahci_command_issue(AHCIQState *ahci, AHCICommand *cmd); 628*1cf4323eSThomas Huth void ahci_command_issue_async(AHCIQState *ahci, AHCICommand *cmd); 629*1cf4323eSThomas Huth void ahci_command_wait(AHCIQState *ahci, AHCICommand *cmd); 630*1cf4323eSThomas Huth void ahci_command_verify(AHCIQState *ahci, AHCICommand *cmd); 631*1cf4323eSThomas Huth void ahci_command_free(AHCICommand *cmd); 632*1cf4323eSThomas Huth 633*1cf4323eSThomas Huth /* Command: adjustments */ 634*1cf4323eSThomas Huth void ahci_command_set_flags(AHCICommand *cmd, uint16_t cmdh_flags); 635*1cf4323eSThomas Huth void ahci_command_clr_flags(AHCICommand *cmd, uint16_t cmdh_flags); 636*1cf4323eSThomas Huth void ahci_command_set_offset(AHCICommand *cmd, uint64_t lba_sect); 637*1cf4323eSThomas Huth void ahci_command_set_buffer(AHCICommand *cmd, uint64_t buffer); 638*1cf4323eSThomas Huth void ahci_command_set_size(AHCICommand *cmd, uint64_t xbytes); 639*1cf4323eSThomas Huth void ahci_command_set_prd_size(AHCICommand *cmd, unsigned prd_size); 640*1cf4323eSThomas Huth void ahci_command_set_sizes(AHCICommand *cmd, uint64_t xbytes, 641*1cf4323eSThomas Huth unsigned prd_size); 642*1cf4323eSThomas Huth void ahci_command_set_acmd(AHCICommand *cmd, void *acmd); 643*1cf4323eSThomas Huth void ahci_command_enable_atapi_dma(AHCICommand *cmd); 644*1cf4323eSThomas Huth void ahci_command_adjust(AHCICommand *cmd, uint64_t lba_sect, uint64_t gbuffer, 645*1cf4323eSThomas Huth uint64_t xbytes, unsigned prd_size); 646*1cf4323eSThomas Huth 647*1cf4323eSThomas Huth /* Command: Misc */ 648*1cf4323eSThomas Huth uint8_t ahci_command_slot(AHCICommand *cmd); 649*1cf4323eSThomas Huth void ahci_write_fis(AHCIQState *ahci, AHCICommand *cmd); 650*1cf4323eSThomas Huth 651*1cf4323eSThomas Huth #endif 652