1f83a40dcSAlexander Graf /* 2f83a40dcSAlexander Graf * QEMU AHCI Emulation 3f83a40dcSAlexander Graf * 4f83a40dcSAlexander Graf * Copyright (c) 2010 qiaochong@loongson.cn 5f83a40dcSAlexander Graf * Copyright (c) 2010 Roland Elek <elek.roland@gmail.com> 6f83a40dcSAlexander Graf * Copyright (c) 2010 Sebastian Herbszt <herbszt@gmx.de> 7f83a40dcSAlexander Graf * Copyright (c) 2010 Alexander Graf <agraf@suse.de> 8f83a40dcSAlexander Graf * 9f83a40dcSAlexander Graf * This library is free software; you can redistribute it and/or 10f83a40dcSAlexander Graf * modify it under the terms of the GNU Lesser General Public 11f83a40dcSAlexander Graf * License as published by the Free Software Foundation; either 12f83a40dcSAlexander Graf * version 2 of the License, or (at your option) any later version. 13f83a40dcSAlexander Graf * 14f83a40dcSAlexander Graf * This library is distributed in the hope that it will be useful, 15f83a40dcSAlexander Graf * but WITHOUT ANY WARRANTY; without even the implied warranty of 16f83a40dcSAlexander Graf * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17f83a40dcSAlexander Graf * Lesser General Public License for more details. 18f83a40dcSAlexander Graf * 19f83a40dcSAlexander Graf * You should have received a copy of the GNU Lesser General Public 20f83a40dcSAlexander Graf * License along with this library; if not, see <http://www.gnu.org/licenses/>. 21f83a40dcSAlexander Graf * 22f83a40dcSAlexander Graf */ 23f83a40dcSAlexander Graf 2403c7a6a8SSebastian Herbszt #ifndef HW_IDE_AHCI_H 2503c7a6a8SSebastian Herbszt #define HW_IDE_AHCI_H 2603c7a6a8SSebastian Herbszt 27465f1ab1SDaniel Verkamp #define AHCI_MEM_BAR_SIZE 0x1000 2803c7a6a8SSebastian Herbszt #define AHCI_MAX_PORTS 32 2903c7a6a8SSebastian Herbszt #define AHCI_MAX_SG 168 /* hardware max is 64K */ 3003c7a6a8SSebastian Herbszt #define AHCI_DMA_BOUNDARY 0xffffffff 3103c7a6a8SSebastian Herbszt #define AHCI_USE_CLUSTERING 0 3203c7a6a8SSebastian Herbszt #define AHCI_MAX_CMDS 32 3303c7a6a8SSebastian Herbszt #define AHCI_CMD_SZ 32 3403c7a6a8SSebastian Herbszt #define AHCI_CMD_SLOT_SZ (AHCI_MAX_CMDS * AHCI_CMD_SZ) 3503c7a6a8SSebastian Herbszt #define AHCI_RX_FIS_SZ 256 3603c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_CDB 0x40 3703c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_HDR_SZ 0x80 3803c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_SZ (AHCI_CMD_TBL_HDR_SZ + (AHCI_MAX_SG * 16)) 3903c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_AR_SZ (AHCI_CMD_TBL_SZ * AHCI_MAX_CMDS) 4003c7a6a8SSebastian Herbszt #define AHCI_PORT_PRIV_DMA_SZ (AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_AR_SZ + \ 4103c7a6a8SSebastian Herbszt AHCI_RX_FIS_SZ) 4203c7a6a8SSebastian Herbszt 432c02f887SPeter Maydell #define AHCI_IRQ_ON_SG (1U << 31) 4403c7a6a8SSebastian Herbszt #define AHCI_CMD_ATAPI (1 << 5) 4503c7a6a8SSebastian Herbszt #define AHCI_CMD_WRITE (1 << 6) 4603c7a6a8SSebastian Herbszt #define AHCI_CMD_PREFETCH (1 << 7) 4703c7a6a8SSebastian Herbszt #define AHCI_CMD_RESET (1 << 8) 4803c7a6a8SSebastian Herbszt #define AHCI_CMD_CLR_BUSY (1 << 10) 4903c7a6a8SSebastian Herbszt 5003c7a6a8SSebastian Herbszt #define RX_FIS_D2H_REG 0x40 /* offset of D2H Register FIS data */ 5103c7a6a8SSebastian Herbszt #define RX_FIS_SDB 0x58 /* offset of SDB FIS data */ 5203c7a6a8SSebastian Herbszt #define RX_FIS_UNK 0x60 /* offset of Unknown FIS data */ 5303c7a6a8SSebastian Herbszt 5403c7a6a8SSebastian Herbszt /* global controller registers */ 5503c7a6a8SSebastian Herbszt #define HOST_CAP 0x00 /* host capabilities */ 5603c7a6a8SSebastian Herbszt #define HOST_CTL 0x04 /* global host control */ 5703c7a6a8SSebastian Herbszt #define HOST_IRQ_STAT 0x08 /* interrupt status */ 5803c7a6a8SSebastian Herbszt #define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */ 5903c7a6a8SSebastian Herbszt #define HOST_VERSION 0x10 /* AHCI spec. version compliancy */ 6003c7a6a8SSebastian Herbszt 6103c7a6a8SSebastian Herbszt /* HOST_CTL bits */ 6203c7a6a8SSebastian Herbszt #define HOST_CTL_RESET (1 << 0) /* reset controller; self-clear */ 6303c7a6a8SSebastian Herbszt #define HOST_CTL_IRQ_EN (1 << 1) /* global IRQ enable */ 642c02f887SPeter Maydell #define HOST_CTL_AHCI_EN (1U << 31) /* AHCI enabled */ 6503c7a6a8SSebastian Herbszt 6603c7a6a8SSebastian Herbszt /* HOST_CAP bits */ 6703c7a6a8SSebastian Herbszt #define HOST_CAP_SSC (1 << 14) /* Slumber capable */ 6803c7a6a8SSebastian Herbszt #define HOST_CAP_AHCI (1 << 18) /* AHCI only */ 6903c7a6a8SSebastian Herbszt #define HOST_CAP_CLO (1 << 24) /* Command List Override support */ 7003c7a6a8SSebastian Herbszt #define HOST_CAP_SSS (1 << 27) /* Staggered Spin-up */ 7103c7a6a8SSebastian Herbszt #define HOST_CAP_NCQ (1 << 30) /* Native Command Queueing */ 722c02f887SPeter Maydell #define HOST_CAP_64 (1U << 31) /* PCI DAC (64-bit DMA) support */ 7303c7a6a8SSebastian Herbszt 7403c7a6a8SSebastian Herbszt /* registers for each SATA port */ 7503c7a6a8SSebastian Herbszt #define PORT_LST_ADDR 0x00 /* command list DMA addr */ 7603c7a6a8SSebastian Herbszt #define PORT_LST_ADDR_HI 0x04 /* command list DMA addr hi */ 7703c7a6a8SSebastian Herbszt #define PORT_FIS_ADDR 0x08 /* FIS rx buf addr */ 7803c7a6a8SSebastian Herbszt #define PORT_FIS_ADDR_HI 0x0c /* FIS rx buf addr hi */ 7903c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT 0x10 /* interrupt status */ 8003c7a6a8SSebastian Herbszt #define PORT_IRQ_MASK 0x14 /* interrupt enable/disable mask */ 8103c7a6a8SSebastian Herbszt #define PORT_CMD 0x18 /* port command */ 8203c7a6a8SSebastian Herbszt #define PORT_TFDATA 0x20 /* taskfile data */ 8303c7a6a8SSebastian Herbszt #define PORT_SIG 0x24 /* device TF signature */ 8403c7a6a8SSebastian Herbszt #define PORT_SCR_STAT 0x28 /* SATA phy register: SStatus */ 8503c7a6a8SSebastian Herbszt #define PORT_SCR_CTL 0x2c /* SATA phy register: SControl */ 8603c7a6a8SSebastian Herbszt #define PORT_SCR_ERR 0x30 /* SATA phy register: SError */ 8703c7a6a8SSebastian Herbszt #define PORT_SCR_ACT 0x34 /* SATA phy register: SActive */ 8803c7a6a8SSebastian Herbszt #define PORT_CMD_ISSUE 0x38 /* command issue */ 8903c7a6a8SSebastian Herbszt #define PORT_RESERVED 0x3c /* reserved */ 9003c7a6a8SSebastian Herbszt 9103c7a6a8SSebastian Herbszt /* PORT_IRQ_{STAT,MASK} bits */ 922c02f887SPeter Maydell #define PORT_IRQ_COLD_PRES (1U << 31) /* cold presence detect */ 9303c7a6a8SSebastian Herbszt #define PORT_IRQ_TF_ERR (1 << 30) /* task file error */ 9403c7a6a8SSebastian Herbszt #define PORT_IRQ_HBUS_ERR (1 << 29) /* host bus fatal error */ 9503c7a6a8SSebastian Herbszt #define PORT_IRQ_HBUS_DATA_ERR (1 << 28) /* host bus data error */ 9603c7a6a8SSebastian Herbszt #define PORT_IRQ_IF_ERR (1 << 27) /* interface fatal error */ 9703c7a6a8SSebastian Herbszt #define PORT_IRQ_IF_NONFATAL (1 << 26) /* interface non-fatal error */ 9803c7a6a8SSebastian Herbszt #define PORT_IRQ_OVERFLOW (1 << 24) /* xfer exhausted available S/G */ 9903c7a6a8SSebastian Herbszt #define PORT_IRQ_BAD_PMP (1 << 23) /* incorrect port multiplier */ 10003c7a6a8SSebastian Herbszt 10103c7a6a8SSebastian Herbszt #define PORT_IRQ_PHYRDY (1 << 22) /* PhyRdy changed */ 10203c7a6a8SSebastian Herbszt #define PORT_IRQ_DEV_ILCK (1 << 7) /* device interlock */ 10303c7a6a8SSebastian Herbszt #define PORT_IRQ_CONNECT (1 << 6) /* port connect change status */ 10403c7a6a8SSebastian Herbszt #define PORT_IRQ_SG_DONE (1 << 5) /* descriptor processed */ 10503c7a6a8SSebastian Herbszt #define PORT_IRQ_UNK_FIS (1 << 4) /* unknown FIS rx'd */ 10603c7a6a8SSebastian Herbszt #define PORT_IRQ_SDB_FIS (1 << 3) /* Set Device Bits FIS rx'd */ 10703c7a6a8SSebastian Herbszt #define PORT_IRQ_DMAS_FIS (1 << 2) /* DMA Setup FIS rx'd */ 10803c7a6a8SSebastian Herbszt #define PORT_IRQ_PIOS_FIS (1 << 1) /* PIO Setup FIS rx'd */ 10903c7a6a8SSebastian Herbszt #define PORT_IRQ_D2H_REG_FIS (1 << 0) /* D2H Register FIS rx'd */ 11003c7a6a8SSebastian Herbszt 11103c7a6a8SSebastian Herbszt #define PORT_IRQ_FREEZE (PORT_IRQ_HBUS_ERR | PORT_IRQ_IF_ERR | \ 11203c7a6a8SSebastian Herbszt PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY | \ 11303c7a6a8SSebastian Herbszt PORT_IRQ_UNK_FIS) 11403c7a6a8SSebastian Herbszt #define PORT_IRQ_ERROR (PORT_IRQ_FREEZE | PORT_IRQ_TF_ERR | \ 11503c7a6a8SSebastian Herbszt PORT_IRQ_HBUS_DATA_ERR) 11603c7a6a8SSebastian Herbszt #define DEF_PORT_IRQ (PORT_IRQ_ERROR | PORT_IRQ_SG_DONE | \ 11703c7a6a8SSebastian Herbszt PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS | \ 11803c7a6a8SSebastian Herbszt PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS) 11903c7a6a8SSebastian Herbszt 12003c7a6a8SSebastian Herbszt /* PORT_CMD bits */ 12103c7a6a8SSebastian Herbszt #define PORT_CMD_ATAPI (1 << 24) /* Device is ATAPI */ 12203c7a6a8SSebastian Herbszt #define PORT_CMD_LIST_ON (1 << 15) /* cmd list DMA engine running */ 12303c7a6a8SSebastian Herbszt #define PORT_CMD_FIS_ON (1 << 14) /* FIS DMA engine running */ 12403c7a6a8SSebastian Herbszt #define PORT_CMD_FIS_RX (1 << 4) /* Enable FIS receive DMA engine */ 12503c7a6a8SSebastian Herbszt #define PORT_CMD_CLO (1 << 3) /* Command list override */ 12603c7a6a8SSebastian Herbszt #define PORT_CMD_POWER_ON (1 << 2) /* Power up device */ 12703c7a6a8SSebastian Herbszt #define PORT_CMD_SPIN_UP (1 << 1) /* Spin up device */ 12803c7a6a8SSebastian Herbszt #define PORT_CMD_START (1 << 0) /* Enable port DMA engine */ 12903c7a6a8SSebastian Herbszt 13003c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_MASK (0xf << 28) /* i/f ICC state mask */ 13103c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_ACTIVE (0x1 << 28) /* Put i/f in active state */ 13203c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_PARTIAL (0x2 << 28) /* Put i/f in partial state */ 13303c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_SLUMBER (0x6 << 28) /* Put i/f in slumber state */ 13403c7a6a8SSebastian Herbszt 135fc3d8e11SJohn Snow #define PORT_CMD_RO_MASK 0x007dffe0 /* Which CMD bits are read only? */ 136fc3d8e11SJohn Snow 13703c7a6a8SSebastian Herbszt /* ap->flags bits */ 13803c7a6a8SSebastian Herbszt #define AHCI_FLAG_NO_NCQ (1 << 24) 13903c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_IRQ_IF_ERR (1 << 25) /* ignore IRQ_IF_ERR */ 14003c7a6a8SSebastian Herbszt #define AHCI_FLAG_HONOR_PI (1 << 26) /* honor PORTS_IMPL */ 14103c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_SERR_INTERNAL (1 << 27) /* ignore SERR_INTERNAL */ 14203c7a6a8SSebastian Herbszt #define AHCI_FLAG_32BIT_ONLY (1 << 28) /* force 32bit */ 14303c7a6a8SSebastian Herbszt 14403c7a6a8SSebastian Herbszt #define ATA_SRST (1 << 2) /* software reset */ 14503c7a6a8SSebastian Herbszt 14603c7a6a8SSebastian Herbszt #define STATE_RUN 0 14703c7a6a8SSebastian Herbszt #define STATE_RESET 1 14803c7a6a8SSebastian Herbszt 14903c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_NODEV 0x0 15003c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP 0x3 15103c7a6a8SSebastian Herbszt 15203c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_NODEV 0x00 15303c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_GEN1 0x10 15403c7a6a8SSebastian Herbszt 15503c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_NODEV 0x000 15603c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_ACTIVE 0X100 15703c7a6a8SSebastian Herbszt 15803c7a6a8SSebastian Herbszt #define AHCI_SCR_SCTL_DET 0xf 15903c7a6a8SSebastian Herbszt 16003c7a6a8SSebastian Herbszt #define SATA_FIS_TYPE_REGISTER_H2D 0x27 16103c7a6a8SSebastian Herbszt #define SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER 0x80 16217fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_REGISTER_D2H 0x34 16317fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_PIO_SETUP 0x5f 16417fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_SDB 0xA1 16503c7a6a8SSebastian Herbszt 16603c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_CMD_FIS_LEN 0x1f 16703c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_PRDT_LEN 16 16803c7a6a8SSebastian Herbszt 16903c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_CDROM 0xeb140000 17003c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_DISK 0x00000101 17103c7a6a8SSebastian Herbszt 17203c7a6a8SSebastian Herbszt #define AHCI_GENERIC_HOST_CONTROL_REGS_MAX_ADDR 0x20 17303c7a6a8SSebastian Herbszt /* Shouldn't this be 0x2c? */ 17403c7a6a8SSebastian Herbszt 17503c7a6a8SSebastian Herbszt #define AHCI_PORT_REGS_START_ADDR 0x100 17603c7a6a8SSebastian Herbszt #define AHCI_PORT_ADDR_OFFSET_MASK 0x7f 1772c4b9d0eSAlexander Graf #define AHCI_PORT_ADDR_OFFSET_LEN 0x80 17803c7a6a8SSebastian Herbszt 17903c7a6a8SSebastian Herbszt #define AHCI_NUM_COMMAND_SLOTS 31 18003c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED 20 18103c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED_GEN1 1 18203c7a6a8SSebastian Herbszt #define AHCI_VERSION_1_0 0x10000 18303c7a6a8SSebastian Herbszt 18403c7a6a8SSebastian Herbszt #define AHCI_PROGMODE_MAJOR_REV_1 1 18503c7a6a8SSebastian Herbszt 18603c7a6a8SSebastian Herbszt #define AHCI_COMMAND_TABLE_ACMD 0x40 18703c7a6a8SSebastian Herbszt 188d02f8adcSReza Jelveh #define AHCI_PRDT_SIZE_MASK 0x3fffff 189d02f8adcSReza Jelveh 19003c7a6a8SSebastian Herbszt #define IDE_FEATURE_DMA 1 19103c7a6a8SSebastian Herbszt 19203c7a6a8SSebastian Herbszt #define READ_FPDMA_QUEUED 0x60 19303c7a6a8SSebastian Herbszt #define WRITE_FPDMA_QUEUED 0x61 19472a065dbSJohn Snow #define NCQ_NON_DATA 0x63 19572a065dbSJohn Snow #define RECEIVE_FPDMA_QUEUED 0x65 19672a065dbSJohn Snow #define SEND_FPDMA_QUEUED 0x64 19703c7a6a8SSebastian Herbszt 1987763ed15SJohn Snow #define NCQ_FIS_FUA_MASK 0x80 1997763ed15SJohn Snow #define NCQ_FIS_RARC_MASK 0x01 2007763ed15SJohn Snow 20103c7a6a8SSebastian Herbszt #define RES_FIS_DSFIS 0x00 20203c7a6a8SSebastian Herbszt #define RES_FIS_PSFIS 0x20 20303c7a6a8SSebastian Herbszt #define RES_FIS_RFIS 0x40 20403c7a6a8SSebastian Herbszt #define RES_FIS_SDBFIS 0x58 20503c7a6a8SSebastian Herbszt #define RES_FIS_UFIS 0x60 20603c7a6a8SSebastian Herbszt 207465f1ab1SDaniel Verkamp #define SATA_CAP_SIZE 0x8 208465f1ab1SDaniel Verkamp #define SATA_CAP_REV 0x2 209465f1ab1SDaniel Verkamp #define SATA_CAP_BAR 0x4 210465f1ab1SDaniel Verkamp 21103c7a6a8SSebastian Herbszt typedef struct AHCIControlRegs { 21203c7a6a8SSebastian Herbszt uint32_t cap; 21303c7a6a8SSebastian Herbszt uint32_t ghc; 21403c7a6a8SSebastian Herbszt uint32_t irqstatus; 21503c7a6a8SSebastian Herbszt uint32_t impl; 21603c7a6a8SSebastian Herbszt uint32_t version; 21703c7a6a8SSebastian Herbszt } AHCIControlRegs; 21803c7a6a8SSebastian Herbszt 21903c7a6a8SSebastian Herbszt typedef struct AHCIPortRegs { 22003c7a6a8SSebastian Herbszt uint32_t lst_addr; 22103c7a6a8SSebastian Herbszt uint32_t lst_addr_hi; 22203c7a6a8SSebastian Herbszt uint32_t fis_addr; 22303c7a6a8SSebastian Herbszt uint32_t fis_addr_hi; 22403c7a6a8SSebastian Herbszt uint32_t irq_stat; 22503c7a6a8SSebastian Herbszt uint32_t irq_mask; 22603c7a6a8SSebastian Herbszt uint32_t cmd; 22703c7a6a8SSebastian Herbszt uint32_t unused0; 22803c7a6a8SSebastian Herbszt uint32_t tfdata; 22903c7a6a8SSebastian Herbszt uint32_t sig; 23003c7a6a8SSebastian Herbszt uint32_t scr_stat; 23103c7a6a8SSebastian Herbszt uint32_t scr_ctl; 23203c7a6a8SSebastian Herbszt uint32_t scr_err; 23303c7a6a8SSebastian Herbszt uint32_t scr_act; 23403c7a6a8SSebastian Herbszt uint32_t cmd_issue; 23503c7a6a8SSebastian Herbszt uint32_t reserved; 23603c7a6a8SSebastian Herbszt } AHCIPortRegs; 23703c7a6a8SSebastian Herbszt 23803c7a6a8SSebastian Herbszt typedef struct AHCICmdHdr { 239d56f4d69SJohn Snow uint16_t opts; 240d56f4d69SJohn Snow uint16_t prdtl; 24103c7a6a8SSebastian Herbszt uint32_t status; 24203c7a6a8SSebastian Herbszt uint64_t tbl_addr; 24303c7a6a8SSebastian Herbszt uint32_t reserved[4]; 244541dc0d4SStefan Weil } QEMU_PACKED AHCICmdHdr; 24503c7a6a8SSebastian Herbszt 24603c7a6a8SSebastian Herbszt typedef struct AHCI_SG { 24703c7a6a8SSebastian Herbszt uint64_t addr; 24803c7a6a8SSebastian Herbszt uint32_t reserved; 24903c7a6a8SSebastian Herbszt uint32_t flags_size; 250541dc0d4SStefan Weil } QEMU_PACKED AHCI_SG; 25103c7a6a8SSebastian Herbszt 25203c7a6a8SSebastian Herbszt typedef struct AHCIDevice AHCIDevice; 25303c7a6a8SSebastian Herbszt 25403c7a6a8SSebastian Herbszt typedef struct NCQTransferState { 25503c7a6a8SSebastian Herbszt AHCIDevice *drive; 2567c84b1b8SMarkus Armbruster BlockAIOCB *aiocb; 25703c7a6a8SSebastian Herbszt QEMUSGList sglist; 258a597e79cSChristoph Hellwig BlockAcctCookie acct; 25903c7a6a8SSebastian Herbszt uint16_t sector_count; 26003c7a6a8SSebastian Herbszt uint64_t lba; 26103c7a6a8SSebastian Herbszt uint8_t tag; 262*4614619eSJohn Snow uint8_t cmd; 26303c7a6a8SSebastian Herbszt int slot; 26403c7a6a8SSebastian Herbszt int used; 26503c7a6a8SSebastian Herbszt } NCQTransferState; 26603c7a6a8SSebastian Herbszt 26703c7a6a8SSebastian Herbszt struct AHCIDevice { 26803c7a6a8SSebastian Herbszt IDEDMA dma; 26903c7a6a8SSebastian Herbszt IDEBus port; 27003c7a6a8SSebastian Herbszt int port_no; 27103c7a6a8SSebastian Herbszt uint32_t port_state; 27203c7a6a8SSebastian Herbszt uint32_t finished; 27303c7a6a8SSebastian Herbszt AHCIPortRegs port_regs; 27403c7a6a8SSebastian Herbszt struct AHCIState *hba; 27503c7a6a8SSebastian Herbszt QEMUBH *check_bh; 27603c7a6a8SSebastian Herbszt uint8_t *lst; 27703c7a6a8SSebastian Herbszt uint8_t *res_fis; 2784ac557c8SKevin Wolf bool done_atapi_packet; 2794ac557c8SKevin Wolf int32_t busy_slot; 2804ac557c8SKevin Wolf bool init_d2h_sent; 28103c7a6a8SSebastian Herbszt AHCICmdHdr *cur_cmd; 28203c7a6a8SSebastian Herbszt NCQTransferState ncq_tfs[AHCI_MAX_CMDS]; 28303c7a6a8SSebastian Herbszt }; 28403c7a6a8SSebastian Herbszt 28503c7a6a8SSebastian Herbszt typedef struct AHCIState { 2862c4b9d0eSAlexander Graf AHCIDevice *dev; 28703c7a6a8SSebastian Herbszt AHCIControlRegs control_regs; 28867e576c2SAvi Kivity MemoryRegion mem; 289465f1ab1SDaniel Verkamp MemoryRegion idp; /* Index-Data Pair I/O port space */ 290465f1ab1SDaniel Verkamp unsigned idp_offset; /* Offset of index in I/O port space */ 291465f1ab1SDaniel Verkamp uint32_t idp_index; /* Current IDP index */ 2924ac557c8SKevin Wolf int32_t ports; 29303c7a6a8SSebastian Herbszt qemu_irq irq; 294df32fd1cSPaolo Bonzini AddressSpace *as; 29503c7a6a8SSebastian Herbszt } AHCIState; 29603c7a6a8SSebastian Herbszt 29703c7a6a8SSebastian Herbszt typedef struct AHCIPCIState { 2980d3aea56SAndreas Färber /*< private >*/ 2990d3aea56SAndreas Färber PCIDevice parent_obj; 3000d3aea56SAndreas Färber /*< public >*/ 3010d3aea56SAndreas Färber 30203c7a6a8SSebastian Herbszt AHCIState ahci; 30303c7a6a8SSebastian Herbszt } AHCIPCIState; 30403c7a6a8SSebastian Herbszt 305fd58922cSPeter Crosthwaite #define TYPE_ICH9_AHCI "ich9-ahci" 306fd58922cSPeter Crosthwaite 307fd58922cSPeter Crosthwaite #define ICH_AHCI(obj) \ 308fd58922cSPeter Crosthwaite OBJECT_CHECK(AHCIPCIState, (obj), TYPE_ICH9_AHCI) 309fd58922cSPeter Crosthwaite 310a2623021SJason Baron extern const VMStateDescription vmstate_ahci; 311a2623021SJason Baron 312a2623021SJason Baron #define VMSTATE_AHCI(_field, _state) { \ 313a2623021SJason Baron .name = (stringify(_field)), \ 314a2623021SJason Baron .size = sizeof(AHCIState), \ 315a2623021SJason Baron .vmsd = &vmstate_ahci, \ 316a2623021SJason Baron .flags = VMS_STRUCT, \ 317a2623021SJason Baron .offset = vmstate_offset_value(_state, _field, AHCIState), \ 318a2623021SJason Baron } 319a2623021SJason Baron 3207763ed15SJohn Snow /** 3217763ed15SJohn Snow * NCQFrame is the same as a Register H2D FIS (described in SATA 3.2), 3227763ed15SJohn Snow * but some fields have been re-mapped and re-purposed, as seen in 3237763ed15SJohn Snow * SATA 3.2 section 13.6.4.1 ("READ FPDMA QUEUED") 3247763ed15SJohn Snow * 3257763ed15SJohn Snow * cmd_fis[3], feature 7:0, becomes sector count 7:0. 3267763ed15SJohn Snow * cmd_fis[7], device 7:0, uses bit 7 as the Force Unit Access bit. 3277763ed15SJohn Snow * cmd_fis[11], feature 15:8, becomes sector count 15:8. 3287763ed15SJohn Snow * cmd_fis[12], count 7:0, becomes the NCQ TAG (7:3) and RARC bit (0) 3297763ed15SJohn Snow * cmd_fis[13], count 15:8, becomes the priority value (7:6) 3307763ed15SJohn Snow * bytes 16-19 become an le32 "auxiliary" field. 3317763ed15SJohn Snow */ 33203c7a6a8SSebastian Herbszt typedef struct NCQFrame { 33303c7a6a8SSebastian Herbszt uint8_t fis_type; 33403c7a6a8SSebastian Herbszt uint8_t c; 33503c7a6a8SSebastian Herbszt uint8_t command; 3367763ed15SJohn Snow uint8_t sector_count_low; /* (feature 7:0) */ 33703c7a6a8SSebastian Herbszt uint8_t lba0; 33803c7a6a8SSebastian Herbszt uint8_t lba1; 33903c7a6a8SSebastian Herbszt uint8_t lba2; 3407763ed15SJohn Snow uint8_t fua; /* (device 7:0) */ 34103c7a6a8SSebastian Herbszt uint8_t lba3; 34203c7a6a8SSebastian Herbszt uint8_t lba4; 34303c7a6a8SSebastian Herbszt uint8_t lba5; 3447763ed15SJohn Snow uint8_t sector_count_high; /* (feature 15:8) */ 3457763ed15SJohn Snow uint8_t tag; /* (count 0:7) */ 3467763ed15SJohn Snow uint8_t prio; /* (count 15:8) */ 3477763ed15SJohn Snow uint8_t icc; 34803c7a6a8SSebastian Herbszt uint8_t control; 3497763ed15SJohn Snow uint8_t aux0; 3507763ed15SJohn Snow uint8_t aux1; 3517763ed15SJohn Snow uint8_t aux2; 3527763ed15SJohn Snow uint8_t aux3; 353541dc0d4SStefan Weil } QEMU_PACKED NCQFrame; 35403c7a6a8SSebastian Herbszt 35554a7f8f3SJohn Snow typedef struct SDBFIS { 35654a7f8f3SJohn Snow uint8_t type; 35754a7f8f3SJohn Snow uint8_t flags; 35854a7f8f3SJohn Snow uint8_t status; 35954a7f8f3SJohn Snow uint8_t error; 36054a7f8f3SJohn Snow uint32_t payload; 36154a7f8f3SJohn Snow } QEMU_PACKED SDBFIS; 36254a7f8f3SJohn Snow 363df32fd1cSPaolo Bonzini void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports); 3642c4b9d0eSAlexander Graf void ahci_uninit(AHCIState *s); 36503c7a6a8SSebastian Herbszt 3668ab60a07SJan Kiszka void ahci_reset(AHCIState *s); 36703c7a6a8SSebastian Herbszt 368d93162e1SJohn Snow void ahci_ide_create_devs(PCIDevice *dev, DriveInfo **hd); 369d93162e1SJohn Snow 37003c7a6a8SSebastian Herbszt #endif /* HW_IDE_AHCI_H */ 371