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 13503c7a6a8SSebastian Herbszt /* ap->flags bits */ 13603c7a6a8SSebastian Herbszt #define AHCI_FLAG_NO_NCQ (1 << 24) 13703c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_IRQ_IF_ERR (1 << 25) /* ignore IRQ_IF_ERR */ 13803c7a6a8SSebastian Herbszt #define AHCI_FLAG_HONOR_PI (1 << 26) /* honor PORTS_IMPL */ 13903c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_SERR_INTERNAL (1 << 27) /* ignore SERR_INTERNAL */ 14003c7a6a8SSebastian Herbszt #define AHCI_FLAG_32BIT_ONLY (1 << 28) /* force 32bit */ 14103c7a6a8SSebastian Herbszt 14203c7a6a8SSebastian Herbszt #define ATA_SRST (1 << 2) /* software reset */ 14303c7a6a8SSebastian Herbszt 14403c7a6a8SSebastian Herbszt #define STATE_RUN 0 14503c7a6a8SSebastian Herbszt #define STATE_RESET 1 14603c7a6a8SSebastian Herbszt 14703c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_NODEV 0x0 14803c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP 0x3 14903c7a6a8SSebastian Herbszt 15003c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_NODEV 0x00 15103c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_GEN1 0x10 15203c7a6a8SSebastian Herbszt 15303c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_NODEV 0x000 15403c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_ACTIVE 0X100 15503c7a6a8SSebastian Herbszt 15603c7a6a8SSebastian Herbszt #define AHCI_SCR_SCTL_DET 0xf 15703c7a6a8SSebastian Herbszt 15803c7a6a8SSebastian Herbszt #define SATA_FIS_TYPE_REGISTER_H2D 0x27 15903c7a6a8SSebastian Herbszt #define SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER 0x80 160*17fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_REGISTER_D2H 0x34 161*17fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_PIO_SETUP 0x5f 162*17fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_SDB 0xA1 16303c7a6a8SSebastian Herbszt 16403c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_CMD_FIS_LEN 0x1f 16503c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_PRDT_LEN 16 16603c7a6a8SSebastian Herbszt 16703c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_CDROM 0xeb140000 16803c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_DISK 0x00000101 16903c7a6a8SSebastian Herbszt 17003c7a6a8SSebastian Herbszt #define AHCI_GENERIC_HOST_CONTROL_REGS_MAX_ADDR 0x20 17103c7a6a8SSebastian Herbszt /* Shouldn't this be 0x2c? */ 17203c7a6a8SSebastian Herbszt 17303c7a6a8SSebastian Herbszt #define AHCI_PORT_REGS_START_ADDR 0x100 17403c7a6a8SSebastian Herbszt #define AHCI_PORT_ADDR_OFFSET_MASK 0x7f 1752c4b9d0eSAlexander Graf #define AHCI_PORT_ADDR_OFFSET_LEN 0x80 17603c7a6a8SSebastian Herbszt 17703c7a6a8SSebastian Herbszt #define AHCI_NUM_COMMAND_SLOTS 31 17803c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED 20 17903c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED_GEN1 1 18003c7a6a8SSebastian Herbszt #define AHCI_VERSION_1_0 0x10000 18103c7a6a8SSebastian Herbszt 18203c7a6a8SSebastian Herbszt #define AHCI_PROGMODE_MAJOR_REV_1 1 18303c7a6a8SSebastian Herbszt 18403c7a6a8SSebastian Herbszt #define AHCI_COMMAND_TABLE_ACMD 0x40 18503c7a6a8SSebastian Herbszt 186d02f8adcSReza Jelveh #define AHCI_PRDT_SIZE_MASK 0x3fffff 187d02f8adcSReza Jelveh 18803c7a6a8SSebastian Herbszt #define IDE_FEATURE_DMA 1 18903c7a6a8SSebastian Herbszt 19003c7a6a8SSebastian Herbszt #define READ_FPDMA_QUEUED 0x60 19103c7a6a8SSebastian Herbszt #define WRITE_FPDMA_QUEUED 0x61 19272a065dbSJohn Snow #define NCQ_NON_DATA 0x63 19372a065dbSJohn Snow #define RECEIVE_FPDMA_QUEUED 0x65 19472a065dbSJohn Snow #define SEND_FPDMA_QUEUED 0x64 19503c7a6a8SSebastian Herbszt 19603c7a6a8SSebastian Herbszt #define RES_FIS_DSFIS 0x00 19703c7a6a8SSebastian Herbszt #define RES_FIS_PSFIS 0x20 19803c7a6a8SSebastian Herbszt #define RES_FIS_RFIS 0x40 19903c7a6a8SSebastian Herbszt #define RES_FIS_SDBFIS 0x58 20003c7a6a8SSebastian Herbszt #define RES_FIS_UFIS 0x60 20103c7a6a8SSebastian Herbszt 202465f1ab1SDaniel Verkamp #define SATA_CAP_SIZE 0x8 203465f1ab1SDaniel Verkamp #define SATA_CAP_REV 0x2 204465f1ab1SDaniel Verkamp #define SATA_CAP_BAR 0x4 205465f1ab1SDaniel Verkamp 20603c7a6a8SSebastian Herbszt typedef struct AHCIControlRegs { 20703c7a6a8SSebastian Herbszt uint32_t cap; 20803c7a6a8SSebastian Herbszt uint32_t ghc; 20903c7a6a8SSebastian Herbszt uint32_t irqstatus; 21003c7a6a8SSebastian Herbszt uint32_t impl; 21103c7a6a8SSebastian Herbszt uint32_t version; 21203c7a6a8SSebastian Herbszt } AHCIControlRegs; 21303c7a6a8SSebastian Herbszt 21403c7a6a8SSebastian Herbszt typedef struct AHCIPortRegs { 21503c7a6a8SSebastian Herbszt uint32_t lst_addr; 21603c7a6a8SSebastian Herbszt uint32_t lst_addr_hi; 21703c7a6a8SSebastian Herbszt uint32_t fis_addr; 21803c7a6a8SSebastian Herbszt uint32_t fis_addr_hi; 21903c7a6a8SSebastian Herbszt uint32_t irq_stat; 22003c7a6a8SSebastian Herbszt uint32_t irq_mask; 22103c7a6a8SSebastian Herbszt uint32_t cmd; 22203c7a6a8SSebastian Herbszt uint32_t unused0; 22303c7a6a8SSebastian Herbszt uint32_t tfdata; 22403c7a6a8SSebastian Herbszt uint32_t sig; 22503c7a6a8SSebastian Herbszt uint32_t scr_stat; 22603c7a6a8SSebastian Herbszt uint32_t scr_ctl; 22703c7a6a8SSebastian Herbszt uint32_t scr_err; 22803c7a6a8SSebastian Herbszt uint32_t scr_act; 22903c7a6a8SSebastian Herbszt uint32_t cmd_issue; 23003c7a6a8SSebastian Herbszt uint32_t reserved; 23103c7a6a8SSebastian Herbszt } AHCIPortRegs; 23203c7a6a8SSebastian Herbszt 23303c7a6a8SSebastian Herbszt typedef struct AHCICmdHdr { 23403c7a6a8SSebastian Herbszt uint32_t opts; 23503c7a6a8SSebastian Herbszt uint32_t status; 23603c7a6a8SSebastian Herbszt uint64_t tbl_addr; 23703c7a6a8SSebastian Herbszt uint32_t reserved[4]; 238541dc0d4SStefan Weil } QEMU_PACKED AHCICmdHdr; 23903c7a6a8SSebastian Herbszt 24003c7a6a8SSebastian Herbszt typedef struct AHCI_SG { 24103c7a6a8SSebastian Herbszt uint64_t addr; 24203c7a6a8SSebastian Herbszt uint32_t reserved; 24303c7a6a8SSebastian Herbszt uint32_t flags_size; 244541dc0d4SStefan Weil } QEMU_PACKED AHCI_SG; 24503c7a6a8SSebastian Herbszt 24603c7a6a8SSebastian Herbszt typedef struct AHCIDevice AHCIDevice; 24703c7a6a8SSebastian Herbszt 24803c7a6a8SSebastian Herbszt typedef struct NCQTransferState { 24903c7a6a8SSebastian Herbszt AHCIDevice *drive; 2507c84b1b8SMarkus Armbruster BlockAIOCB *aiocb; 25103c7a6a8SSebastian Herbszt QEMUSGList sglist; 252a597e79cSChristoph Hellwig BlockAcctCookie acct; 25303c7a6a8SSebastian Herbszt uint16_t sector_count; 25403c7a6a8SSebastian Herbszt uint64_t lba; 25503c7a6a8SSebastian Herbszt uint8_t tag; 25603c7a6a8SSebastian Herbszt int slot; 25703c7a6a8SSebastian Herbszt int used; 25803c7a6a8SSebastian Herbszt } NCQTransferState; 25903c7a6a8SSebastian Herbszt 26003c7a6a8SSebastian Herbszt struct AHCIDevice { 26103c7a6a8SSebastian Herbszt IDEDMA dma; 26203c7a6a8SSebastian Herbszt IDEBus port; 26303c7a6a8SSebastian Herbszt int port_no; 26403c7a6a8SSebastian Herbszt uint32_t port_state; 26503c7a6a8SSebastian Herbszt uint32_t finished; 26603c7a6a8SSebastian Herbszt AHCIPortRegs port_regs; 26703c7a6a8SSebastian Herbszt struct AHCIState *hba; 26803c7a6a8SSebastian Herbszt QEMUBH *check_bh; 26903c7a6a8SSebastian Herbszt uint8_t *lst; 27003c7a6a8SSebastian Herbszt uint8_t *res_fis; 2714ac557c8SKevin Wolf bool done_atapi_packet; 2724ac557c8SKevin Wolf int32_t busy_slot; 2734ac557c8SKevin Wolf bool init_d2h_sent; 27403c7a6a8SSebastian Herbszt AHCICmdHdr *cur_cmd; 27503c7a6a8SSebastian Herbszt NCQTransferState ncq_tfs[AHCI_MAX_CMDS]; 27603c7a6a8SSebastian Herbszt }; 27703c7a6a8SSebastian Herbszt 27803c7a6a8SSebastian Herbszt typedef struct AHCIState { 2792c4b9d0eSAlexander Graf AHCIDevice *dev; 28003c7a6a8SSebastian Herbszt AHCIControlRegs control_regs; 28167e576c2SAvi Kivity MemoryRegion mem; 282465f1ab1SDaniel Verkamp MemoryRegion idp; /* Index-Data Pair I/O port space */ 283465f1ab1SDaniel Verkamp unsigned idp_offset; /* Offset of index in I/O port space */ 284465f1ab1SDaniel Verkamp uint32_t idp_index; /* Current IDP index */ 2854ac557c8SKevin Wolf int32_t ports; 28603c7a6a8SSebastian Herbszt qemu_irq irq; 287df32fd1cSPaolo Bonzini AddressSpace *as; 28803c7a6a8SSebastian Herbszt } AHCIState; 28903c7a6a8SSebastian Herbszt 29003c7a6a8SSebastian Herbszt typedef struct AHCIPCIState { 2910d3aea56SAndreas Färber /*< private >*/ 2920d3aea56SAndreas Färber PCIDevice parent_obj; 2930d3aea56SAndreas Färber /*< public >*/ 2940d3aea56SAndreas Färber 29503c7a6a8SSebastian Herbszt AHCIState ahci; 29603c7a6a8SSebastian Herbszt } AHCIPCIState; 29703c7a6a8SSebastian Herbszt 298fd58922cSPeter Crosthwaite #define TYPE_ICH9_AHCI "ich9-ahci" 299fd58922cSPeter Crosthwaite 300fd58922cSPeter Crosthwaite #define ICH_AHCI(obj) \ 301fd58922cSPeter Crosthwaite OBJECT_CHECK(AHCIPCIState, (obj), TYPE_ICH9_AHCI) 302fd58922cSPeter Crosthwaite 303a2623021SJason Baron extern const VMStateDescription vmstate_ahci; 304a2623021SJason Baron 305a2623021SJason Baron #define VMSTATE_AHCI(_field, _state) { \ 306a2623021SJason Baron .name = (stringify(_field)), \ 307a2623021SJason Baron .size = sizeof(AHCIState), \ 308a2623021SJason Baron .vmsd = &vmstate_ahci, \ 309a2623021SJason Baron .flags = VMS_STRUCT, \ 310a2623021SJason Baron .offset = vmstate_offset_value(_state, _field, AHCIState), \ 311a2623021SJason Baron } 312a2623021SJason Baron 31303c7a6a8SSebastian Herbszt typedef struct NCQFrame { 31403c7a6a8SSebastian Herbszt uint8_t fis_type; 31503c7a6a8SSebastian Herbszt uint8_t c; 31603c7a6a8SSebastian Herbszt uint8_t command; 31703c7a6a8SSebastian Herbszt uint8_t sector_count_low; 31803c7a6a8SSebastian Herbszt uint8_t lba0; 31903c7a6a8SSebastian Herbszt uint8_t lba1; 32003c7a6a8SSebastian Herbszt uint8_t lba2; 32103c7a6a8SSebastian Herbszt uint8_t fua; 32203c7a6a8SSebastian Herbszt uint8_t lba3; 32303c7a6a8SSebastian Herbszt uint8_t lba4; 32403c7a6a8SSebastian Herbszt uint8_t lba5; 32503c7a6a8SSebastian Herbszt uint8_t sector_count_high; 32603c7a6a8SSebastian Herbszt uint8_t tag; 32703c7a6a8SSebastian Herbszt uint8_t reserved5; 32803c7a6a8SSebastian Herbszt uint8_t reserved6; 32903c7a6a8SSebastian Herbszt uint8_t control; 33003c7a6a8SSebastian Herbszt uint8_t reserved7; 33103c7a6a8SSebastian Herbszt uint8_t reserved8; 33203c7a6a8SSebastian Herbszt uint8_t reserved9; 33303c7a6a8SSebastian Herbszt uint8_t reserved10; 334541dc0d4SStefan Weil } QEMU_PACKED NCQFrame; 33503c7a6a8SSebastian Herbszt 33654a7f8f3SJohn Snow typedef struct SDBFIS { 33754a7f8f3SJohn Snow uint8_t type; 33854a7f8f3SJohn Snow uint8_t flags; 33954a7f8f3SJohn Snow uint8_t status; 34054a7f8f3SJohn Snow uint8_t error; 34154a7f8f3SJohn Snow uint32_t payload; 34254a7f8f3SJohn Snow } QEMU_PACKED SDBFIS; 34354a7f8f3SJohn Snow 344df32fd1cSPaolo Bonzini void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports); 3452c4b9d0eSAlexander Graf void ahci_uninit(AHCIState *s); 34603c7a6a8SSebastian Herbszt 3478ab60a07SJan Kiszka void ahci_reset(AHCIState *s); 34803c7a6a8SSebastian Herbszt 349d93162e1SJohn Snow void ahci_ide_create_devs(PCIDevice *dev, DriveInfo **hd); 350d93162e1SJohn Snow 35103c7a6a8SSebastian Herbszt #endif /* HW_IDE_AHCI_H */ 352