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 27*a9c94277SMarkus Armbruster #include "hw/sysbus.h" 285ea8b9c5SAlistair Francis 29465f1ab1SDaniel Verkamp #define AHCI_MEM_BAR_SIZE 0x1000 3003c7a6a8SSebastian Herbszt #define AHCI_MAX_PORTS 32 3103c7a6a8SSebastian Herbszt #define AHCI_MAX_SG 168 /* hardware max is 64K */ 3203c7a6a8SSebastian Herbszt #define AHCI_DMA_BOUNDARY 0xffffffff 3303c7a6a8SSebastian Herbszt #define AHCI_USE_CLUSTERING 0 3403c7a6a8SSebastian Herbszt #define AHCI_MAX_CMDS 32 3503c7a6a8SSebastian Herbszt #define AHCI_CMD_SZ 32 3603c7a6a8SSebastian Herbszt #define AHCI_CMD_SLOT_SZ (AHCI_MAX_CMDS * AHCI_CMD_SZ) 3703c7a6a8SSebastian Herbszt #define AHCI_RX_FIS_SZ 256 3803c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_CDB 0x40 3903c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_HDR_SZ 0x80 4003c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_SZ (AHCI_CMD_TBL_HDR_SZ + (AHCI_MAX_SG * 16)) 4103c7a6a8SSebastian Herbszt #define AHCI_CMD_TBL_AR_SZ (AHCI_CMD_TBL_SZ * AHCI_MAX_CMDS) 4203c7a6a8SSebastian Herbszt #define AHCI_PORT_PRIV_DMA_SZ (AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_AR_SZ + \ 4303c7a6a8SSebastian Herbszt AHCI_RX_FIS_SZ) 4403c7a6a8SSebastian Herbszt 452c02f887SPeter Maydell #define AHCI_IRQ_ON_SG (1U << 31) 4603c7a6a8SSebastian Herbszt #define AHCI_CMD_ATAPI (1 << 5) 4703c7a6a8SSebastian Herbszt #define AHCI_CMD_WRITE (1 << 6) 4803c7a6a8SSebastian Herbszt #define AHCI_CMD_PREFETCH (1 << 7) 4903c7a6a8SSebastian Herbszt #define AHCI_CMD_RESET (1 << 8) 5003c7a6a8SSebastian Herbszt #define AHCI_CMD_CLR_BUSY (1 << 10) 5103c7a6a8SSebastian Herbszt 5203c7a6a8SSebastian Herbszt #define RX_FIS_D2H_REG 0x40 /* offset of D2H Register FIS data */ 5303c7a6a8SSebastian Herbszt #define RX_FIS_SDB 0x58 /* offset of SDB FIS data */ 5403c7a6a8SSebastian Herbszt #define RX_FIS_UNK 0x60 /* offset of Unknown FIS data */ 5503c7a6a8SSebastian Herbszt 5603c7a6a8SSebastian Herbszt /* global controller registers */ 5703c7a6a8SSebastian Herbszt #define HOST_CAP 0x00 /* host capabilities */ 5803c7a6a8SSebastian Herbszt #define HOST_CTL 0x04 /* global host control */ 5903c7a6a8SSebastian Herbszt #define HOST_IRQ_STAT 0x08 /* interrupt status */ 6003c7a6a8SSebastian Herbszt #define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */ 6103c7a6a8SSebastian Herbszt #define HOST_VERSION 0x10 /* AHCI spec. version compliancy */ 6203c7a6a8SSebastian Herbszt 6303c7a6a8SSebastian Herbszt /* HOST_CTL bits */ 6403c7a6a8SSebastian Herbszt #define HOST_CTL_RESET (1 << 0) /* reset controller; self-clear */ 6503c7a6a8SSebastian Herbszt #define HOST_CTL_IRQ_EN (1 << 1) /* global IRQ enable */ 662c02f887SPeter Maydell #define HOST_CTL_AHCI_EN (1U << 31) /* AHCI enabled */ 6703c7a6a8SSebastian Herbszt 6803c7a6a8SSebastian Herbszt /* HOST_CAP bits */ 6903c7a6a8SSebastian Herbszt #define HOST_CAP_SSC (1 << 14) /* Slumber capable */ 7003c7a6a8SSebastian Herbszt #define HOST_CAP_AHCI (1 << 18) /* AHCI only */ 7103c7a6a8SSebastian Herbszt #define HOST_CAP_CLO (1 << 24) /* Command List Override support */ 7203c7a6a8SSebastian Herbszt #define HOST_CAP_SSS (1 << 27) /* Staggered Spin-up */ 7303c7a6a8SSebastian Herbszt #define HOST_CAP_NCQ (1 << 30) /* Native Command Queueing */ 742c02f887SPeter Maydell #define HOST_CAP_64 (1U << 31) /* PCI DAC (64-bit DMA) support */ 7503c7a6a8SSebastian Herbszt 7603c7a6a8SSebastian Herbszt /* registers for each SATA port */ 7703c7a6a8SSebastian Herbszt #define PORT_LST_ADDR 0x00 /* command list DMA addr */ 7803c7a6a8SSebastian Herbszt #define PORT_LST_ADDR_HI 0x04 /* command list DMA addr hi */ 7903c7a6a8SSebastian Herbszt #define PORT_FIS_ADDR 0x08 /* FIS rx buf addr */ 8003c7a6a8SSebastian Herbszt #define PORT_FIS_ADDR_HI 0x0c /* FIS rx buf addr hi */ 8103c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT 0x10 /* interrupt status */ 8203c7a6a8SSebastian Herbszt #define PORT_IRQ_MASK 0x14 /* interrupt enable/disable mask */ 8303c7a6a8SSebastian Herbszt #define PORT_CMD 0x18 /* port command */ 8403c7a6a8SSebastian Herbszt #define PORT_TFDATA 0x20 /* taskfile data */ 8503c7a6a8SSebastian Herbszt #define PORT_SIG 0x24 /* device TF signature */ 8603c7a6a8SSebastian Herbszt #define PORT_SCR_STAT 0x28 /* SATA phy register: SStatus */ 8703c7a6a8SSebastian Herbszt #define PORT_SCR_CTL 0x2c /* SATA phy register: SControl */ 8803c7a6a8SSebastian Herbszt #define PORT_SCR_ERR 0x30 /* SATA phy register: SError */ 8903c7a6a8SSebastian Herbszt #define PORT_SCR_ACT 0x34 /* SATA phy register: SActive */ 9003c7a6a8SSebastian Herbszt #define PORT_CMD_ISSUE 0x38 /* command issue */ 9103c7a6a8SSebastian Herbszt #define PORT_RESERVED 0x3c /* reserved */ 9203c7a6a8SSebastian Herbszt 9303c7a6a8SSebastian Herbszt /* PORT_IRQ_{STAT,MASK} bits */ 942c02f887SPeter Maydell #define PORT_IRQ_COLD_PRES (1U << 31) /* cold presence detect */ 9503c7a6a8SSebastian Herbszt #define PORT_IRQ_TF_ERR (1 << 30) /* task file error */ 9603c7a6a8SSebastian Herbszt #define PORT_IRQ_HBUS_ERR (1 << 29) /* host bus fatal error */ 9703c7a6a8SSebastian Herbszt #define PORT_IRQ_HBUS_DATA_ERR (1 << 28) /* host bus data error */ 9803c7a6a8SSebastian Herbszt #define PORT_IRQ_IF_ERR (1 << 27) /* interface fatal error */ 9903c7a6a8SSebastian Herbszt #define PORT_IRQ_IF_NONFATAL (1 << 26) /* interface non-fatal error */ 10003c7a6a8SSebastian Herbszt #define PORT_IRQ_OVERFLOW (1 << 24) /* xfer exhausted available S/G */ 10103c7a6a8SSebastian Herbszt #define PORT_IRQ_BAD_PMP (1 << 23) /* incorrect port multiplier */ 10203c7a6a8SSebastian Herbszt 10303c7a6a8SSebastian Herbszt #define PORT_IRQ_PHYRDY (1 << 22) /* PhyRdy changed */ 10403c7a6a8SSebastian Herbszt #define PORT_IRQ_DEV_ILCK (1 << 7) /* device interlock */ 10503c7a6a8SSebastian Herbszt #define PORT_IRQ_CONNECT (1 << 6) /* port connect change status */ 10603c7a6a8SSebastian Herbszt #define PORT_IRQ_SG_DONE (1 << 5) /* descriptor processed */ 10703c7a6a8SSebastian Herbszt #define PORT_IRQ_UNK_FIS (1 << 4) /* unknown FIS rx'd */ 10803c7a6a8SSebastian Herbszt #define PORT_IRQ_SDB_FIS (1 << 3) /* Set Device Bits FIS rx'd */ 10903c7a6a8SSebastian Herbszt #define PORT_IRQ_DMAS_FIS (1 << 2) /* DMA Setup FIS rx'd */ 11003c7a6a8SSebastian Herbszt #define PORT_IRQ_PIOS_FIS (1 << 1) /* PIO Setup FIS rx'd */ 11103c7a6a8SSebastian Herbszt #define PORT_IRQ_D2H_REG_FIS (1 << 0) /* D2H Register FIS rx'd */ 11203c7a6a8SSebastian Herbszt 11303c7a6a8SSebastian Herbszt #define PORT_IRQ_FREEZE (PORT_IRQ_HBUS_ERR | PORT_IRQ_IF_ERR | \ 11403c7a6a8SSebastian Herbszt PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY | \ 11503c7a6a8SSebastian Herbszt PORT_IRQ_UNK_FIS) 11603c7a6a8SSebastian Herbszt #define PORT_IRQ_ERROR (PORT_IRQ_FREEZE | PORT_IRQ_TF_ERR | \ 11703c7a6a8SSebastian Herbszt PORT_IRQ_HBUS_DATA_ERR) 11803c7a6a8SSebastian Herbszt #define DEF_PORT_IRQ (PORT_IRQ_ERROR | PORT_IRQ_SG_DONE | \ 11903c7a6a8SSebastian Herbszt PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS | \ 12003c7a6a8SSebastian Herbszt PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS) 12103c7a6a8SSebastian Herbszt 12203c7a6a8SSebastian Herbszt /* PORT_CMD bits */ 12303c7a6a8SSebastian Herbszt #define PORT_CMD_ATAPI (1 << 24) /* Device is ATAPI */ 12403c7a6a8SSebastian Herbszt #define PORT_CMD_LIST_ON (1 << 15) /* cmd list DMA engine running */ 12503c7a6a8SSebastian Herbszt #define PORT_CMD_FIS_ON (1 << 14) /* FIS DMA engine running */ 12603c7a6a8SSebastian Herbszt #define PORT_CMD_FIS_RX (1 << 4) /* Enable FIS receive DMA engine */ 12703c7a6a8SSebastian Herbszt #define PORT_CMD_CLO (1 << 3) /* Command list override */ 12803c7a6a8SSebastian Herbszt #define PORT_CMD_POWER_ON (1 << 2) /* Power up device */ 12903c7a6a8SSebastian Herbszt #define PORT_CMD_SPIN_UP (1 << 1) /* Spin up device */ 13003c7a6a8SSebastian Herbszt #define PORT_CMD_START (1 << 0) /* Enable port DMA engine */ 13103c7a6a8SSebastian Herbszt 13291ced514SJohn Snow #define PORT_CMD_ICC_MASK (0xfU << 28) /* i/f ICC state mask */ 13303c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_ACTIVE (0x1 << 28) /* Put i/f in active state */ 13403c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_PARTIAL (0x2 << 28) /* Put i/f in partial state */ 13503c7a6a8SSebastian Herbszt #define PORT_CMD_ICC_SLUMBER (0x6 << 28) /* Put i/f in slumber state */ 13603c7a6a8SSebastian Herbszt 137fc3d8e11SJohn Snow #define PORT_CMD_RO_MASK 0x007dffe0 /* Which CMD bits are read only? */ 138fc3d8e11SJohn Snow 13903c7a6a8SSebastian Herbszt /* ap->flags bits */ 14003c7a6a8SSebastian Herbszt #define AHCI_FLAG_NO_NCQ (1 << 24) 14103c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_IRQ_IF_ERR (1 << 25) /* ignore IRQ_IF_ERR */ 14203c7a6a8SSebastian Herbszt #define AHCI_FLAG_HONOR_PI (1 << 26) /* honor PORTS_IMPL */ 14303c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_SERR_INTERNAL (1 << 27) /* ignore SERR_INTERNAL */ 14403c7a6a8SSebastian Herbszt #define AHCI_FLAG_32BIT_ONLY (1 << 28) /* force 32bit */ 14503c7a6a8SSebastian Herbszt 14603c7a6a8SSebastian Herbszt #define ATA_SRST (1 << 2) /* software reset */ 14703c7a6a8SSebastian Herbszt 14803c7a6a8SSebastian Herbszt #define STATE_RUN 0 14903c7a6a8SSebastian Herbszt #define STATE_RESET 1 15003c7a6a8SSebastian Herbszt 15103c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_NODEV 0x0 15203c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP 0x3 15303c7a6a8SSebastian Herbszt 15403c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_NODEV 0x00 15503c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_GEN1 0x10 15603c7a6a8SSebastian Herbszt 15703c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_NODEV 0x000 15803c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_ACTIVE 0X100 15903c7a6a8SSebastian Herbszt 16003c7a6a8SSebastian Herbszt #define AHCI_SCR_SCTL_DET 0xf 16103c7a6a8SSebastian Herbszt 16203c7a6a8SSebastian Herbszt #define SATA_FIS_TYPE_REGISTER_H2D 0x27 16303c7a6a8SSebastian Herbszt #define SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER 0x80 16417fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_REGISTER_D2H 0x34 16517fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_PIO_SETUP 0x5f 16617fcb74aSStefan Hajnoczi #define SATA_FIS_TYPE_SDB 0xA1 16703c7a6a8SSebastian Herbszt 16803c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_CMD_FIS_LEN 0x1f 16903c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_PRDT_LEN 16 17003c7a6a8SSebastian Herbszt 171702c8c8bSHannes Reinecke #define SATA_SIGNATURE_CDROM 0xeb140101 17203c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_DISK 0x00000101 17303c7a6a8SSebastian Herbszt 17403c7a6a8SSebastian Herbszt #define AHCI_GENERIC_HOST_CONTROL_REGS_MAX_ADDR 0x20 17503c7a6a8SSebastian Herbszt /* Shouldn't this be 0x2c? */ 17603c7a6a8SSebastian Herbszt 17703c7a6a8SSebastian Herbszt #define AHCI_PORT_REGS_START_ADDR 0x100 17803c7a6a8SSebastian Herbszt #define AHCI_PORT_ADDR_OFFSET_MASK 0x7f 1792c4b9d0eSAlexander Graf #define AHCI_PORT_ADDR_OFFSET_LEN 0x80 18003c7a6a8SSebastian Herbszt 18103c7a6a8SSebastian Herbszt #define AHCI_NUM_COMMAND_SLOTS 31 18203c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED 20 18303c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED_GEN1 1 18403c7a6a8SSebastian Herbszt #define AHCI_VERSION_1_0 0x10000 18503c7a6a8SSebastian Herbszt 18603c7a6a8SSebastian Herbszt #define AHCI_PROGMODE_MAJOR_REV_1 1 18703c7a6a8SSebastian Herbszt 18803c7a6a8SSebastian Herbszt #define AHCI_COMMAND_TABLE_ACMD 0x40 18903c7a6a8SSebastian Herbszt 190d02f8adcSReza Jelveh #define AHCI_PRDT_SIZE_MASK 0x3fffff 191d02f8adcSReza Jelveh 19203c7a6a8SSebastian Herbszt #define IDE_FEATURE_DMA 1 19303c7a6a8SSebastian Herbszt 19403c7a6a8SSebastian Herbszt #define READ_FPDMA_QUEUED 0x60 19503c7a6a8SSebastian Herbszt #define WRITE_FPDMA_QUEUED 0x61 19672a065dbSJohn Snow #define NCQ_NON_DATA 0x63 19772a065dbSJohn Snow #define RECEIVE_FPDMA_QUEUED 0x65 19872a065dbSJohn Snow #define SEND_FPDMA_QUEUED 0x64 19903c7a6a8SSebastian Herbszt 2007763ed15SJohn Snow #define NCQ_FIS_FUA_MASK 0x80 2017763ed15SJohn Snow #define NCQ_FIS_RARC_MASK 0x01 2027763ed15SJohn Snow 20303c7a6a8SSebastian Herbszt #define RES_FIS_DSFIS 0x00 20403c7a6a8SSebastian Herbszt #define RES_FIS_PSFIS 0x20 20503c7a6a8SSebastian Herbszt #define RES_FIS_RFIS 0x40 20603c7a6a8SSebastian Herbszt #define RES_FIS_SDBFIS 0x58 20703c7a6a8SSebastian Herbszt #define RES_FIS_UFIS 0x60 20803c7a6a8SSebastian Herbszt 209465f1ab1SDaniel Verkamp #define SATA_CAP_SIZE 0x8 210465f1ab1SDaniel Verkamp #define SATA_CAP_REV 0x2 211465f1ab1SDaniel Verkamp #define SATA_CAP_BAR 0x4 212465f1ab1SDaniel Verkamp 21303c7a6a8SSebastian Herbszt typedef struct AHCIControlRegs { 21403c7a6a8SSebastian Herbszt uint32_t cap; 21503c7a6a8SSebastian Herbszt uint32_t ghc; 21603c7a6a8SSebastian Herbszt uint32_t irqstatus; 21703c7a6a8SSebastian Herbszt uint32_t impl; 21803c7a6a8SSebastian Herbszt uint32_t version; 21903c7a6a8SSebastian Herbszt } AHCIControlRegs; 22003c7a6a8SSebastian Herbszt 22103c7a6a8SSebastian Herbszt typedef struct AHCIPortRegs { 22203c7a6a8SSebastian Herbszt uint32_t lst_addr; 22303c7a6a8SSebastian Herbszt uint32_t lst_addr_hi; 22403c7a6a8SSebastian Herbszt uint32_t fis_addr; 22503c7a6a8SSebastian Herbszt uint32_t fis_addr_hi; 22603c7a6a8SSebastian Herbszt uint32_t irq_stat; 22703c7a6a8SSebastian Herbszt uint32_t irq_mask; 22803c7a6a8SSebastian Herbszt uint32_t cmd; 22903c7a6a8SSebastian Herbszt uint32_t unused0; 23003c7a6a8SSebastian Herbszt uint32_t tfdata; 23103c7a6a8SSebastian Herbszt uint32_t sig; 23203c7a6a8SSebastian Herbszt uint32_t scr_stat; 23303c7a6a8SSebastian Herbszt uint32_t scr_ctl; 23403c7a6a8SSebastian Herbszt uint32_t scr_err; 23503c7a6a8SSebastian Herbszt uint32_t scr_act; 23603c7a6a8SSebastian Herbszt uint32_t cmd_issue; 23703c7a6a8SSebastian Herbszt uint32_t reserved; 23803c7a6a8SSebastian Herbszt } AHCIPortRegs; 23903c7a6a8SSebastian Herbszt 24003c7a6a8SSebastian Herbszt typedef struct AHCICmdHdr { 241d56f4d69SJohn Snow uint16_t opts; 242d56f4d69SJohn Snow uint16_t prdtl; 24303c7a6a8SSebastian Herbszt uint32_t status; 24403c7a6a8SSebastian Herbszt uint64_t tbl_addr; 24503c7a6a8SSebastian Herbszt uint32_t reserved[4]; 246541dc0d4SStefan Weil } QEMU_PACKED AHCICmdHdr; 24703c7a6a8SSebastian Herbszt 24803c7a6a8SSebastian Herbszt typedef struct AHCI_SG { 24903c7a6a8SSebastian Herbszt uint64_t addr; 25003c7a6a8SSebastian Herbszt uint32_t reserved; 25103c7a6a8SSebastian Herbszt uint32_t flags_size; 252541dc0d4SStefan Weil } QEMU_PACKED AHCI_SG; 25303c7a6a8SSebastian Herbszt 25403c7a6a8SSebastian Herbszt typedef struct AHCIDevice AHCIDevice; 25503c7a6a8SSebastian Herbszt 25603c7a6a8SSebastian Herbszt typedef struct NCQTransferState { 25703c7a6a8SSebastian Herbszt AHCIDevice *drive; 2587c84b1b8SMarkus Armbruster BlockAIOCB *aiocb; 259c82bd3c8SJohn Snow AHCICmdHdr *cmdh; 26003c7a6a8SSebastian Herbszt QEMUSGList sglist; 261a597e79cSChristoph Hellwig BlockAcctCookie acct; 262e08a9835SJohn Snow uint32_t sector_count; 26303c7a6a8SSebastian Herbszt uint64_t lba; 26403c7a6a8SSebastian Herbszt uint8_t tag; 2654614619eSJohn Snow uint8_t cmd; 2669364384dSJohn Snow uint8_t slot; 2679364384dSJohn Snow bool used; 2687c03a691SJohn Snow bool halt; 26903c7a6a8SSebastian Herbszt } NCQTransferState; 27003c7a6a8SSebastian Herbszt 27103c7a6a8SSebastian Herbszt struct AHCIDevice { 27203c7a6a8SSebastian Herbszt IDEDMA dma; 27303c7a6a8SSebastian Herbszt IDEBus port; 27403c7a6a8SSebastian Herbszt int port_no; 27503c7a6a8SSebastian Herbszt uint32_t port_state; 27603c7a6a8SSebastian Herbszt uint32_t finished; 27703c7a6a8SSebastian Herbszt AHCIPortRegs port_regs; 27803c7a6a8SSebastian Herbszt struct AHCIState *hba; 27903c7a6a8SSebastian Herbszt QEMUBH *check_bh; 28003c7a6a8SSebastian Herbszt uint8_t *lst; 28103c7a6a8SSebastian Herbszt uint8_t *res_fis; 2824ac557c8SKevin Wolf bool done_atapi_packet; 2834ac557c8SKevin Wolf int32_t busy_slot; 2844ac557c8SKevin Wolf bool init_d2h_sent; 28503c7a6a8SSebastian Herbszt AHCICmdHdr *cur_cmd; 28603c7a6a8SSebastian Herbszt NCQTransferState ncq_tfs[AHCI_MAX_CMDS]; 28703c7a6a8SSebastian Herbszt }; 28803c7a6a8SSebastian Herbszt 28903c7a6a8SSebastian Herbszt typedef struct AHCIState { 290bb639f82SAlistair Francis DeviceState *container; 291bb639f82SAlistair Francis 2922c4b9d0eSAlexander Graf AHCIDevice *dev; 29303c7a6a8SSebastian Herbszt AHCIControlRegs control_regs; 29467e576c2SAvi Kivity MemoryRegion mem; 295465f1ab1SDaniel Verkamp MemoryRegion idp; /* Index-Data Pair I/O port space */ 296465f1ab1SDaniel Verkamp unsigned idp_offset; /* Offset of index in I/O port space */ 297465f1ab1SDaniel Verkamp uint32_t idp_index; /* Current IDP index */ 2984ac557c8SKevin Wolf int32_t ports; 29903c7a6a8SSebastian Herbszt qemu_irq irq; 300df32fd1cSPaolo Bonzini AddressSpace *as; 30103c7a6a8SSebastian Herbszt } AHCIState; 30203c7a6a8SSebastian Herbszt 30303c7a6a8SSebastian Herbszt typedef struct AHCIPCIState { 3040d3aea56SAndreas Färber /*< private >*/ 3050d3aea56SAndreas Färber PCIDevice parent_obj; 3060d3aea56SAndreas Färber /*< public >*/ 3070d3aea56SAndreas Färber 30803c7a6a8SSebastian Herbszt AHCIState ahci; 30903c7a6a8SSebastian Herbszt } AHCIPCIState; 31003c7a6a8SSebastian Herbszt 311fd58922cSPeter Crosthwaite #define TYPE_ICH9_AHCI "ich9-ahci" 312fd58922cSPeter Crosthwaite 313fd58922cSPeter Crosthwaite #define ICH_AHCI(obj) \ 314fd58922cSPeter Crosthwaite OBJECT_CHECK(AHCIPCIState, (obj), TYPE_ICH9_AHCI) 315fd58922cSPeter Crosthwaite 316a2623021SJason Baron extern const VMStateDescription vmstate_ahci; 317a2623021SJason Baron 318a2623021SJason Baron #define VMSTATE_AHCI(_field, _state) { \ 319a2623021SJason Baron .name = (stringify(_field)), \ 320a2623021SJason Baron .size = sizeof(AHCIState), \ 321a2623021SJason Baron .vmsd = &vmstate_ahci, \ 322a2623021SJason Baron .flags = VMS_STRUCT, \ 323a2623021SJason Baron .offset = vmstate_offset_value(_state, _field, AHCIState), \ 324a2623021SJason Baron } 325a2623021SJason Baron 3267763ed15SJohn Snow /** 3277763ed15SJohn Snow * NCQFrame is the same as a Register H2D FIS (described in SATA 3.2), 3287763ed15SJohn Snow * but some fields have been re-mapped and re-purposed, as seen in 3297763ed15SJohn Snow * SATA 3.2 section 13.6.4.1 ("READ FPDMA QUEUED") 3307763ed15SJohn Snow * 3317763ed15SJohn Snow * cmd_fis[3], feature 7:0, becomes sector count 7:0. 3327763ed15SJohn Snow * cmd_fis[7], device 7:0, uses bit 7 as the Force Unit Access bit. 3337763ed15SJohn Snow * cmd_fis[11], feature 15:8, becomes sector count 15:8. 3347763ed15SJohn Snow * cmd_fis[12], count 7:0, becomes the NCQ TAG (7:3) and RARC bit (0) 3357763ed15SJohn Snow * cmd_fis[13], count 15:8, becomes the priority value (7:6) 3367763ed15SJohn Snow * bytes 16-19 become an le32 "auxiliary" field. 3377763ed15SJohn Snow */ 33803c7a6a8SSebastian Herbszt typedef struct NCQFrame { 33903c7a6a8SSebastian Herbszt uint8_t fis_type; 34003c7a6a8SSebastian Herbszt uint8_t c; 34103c7a6a8SSebastian Herbszt uint8_t command; 3427763ed15SJohn Snow uint8_t sector_count_low; /* (feature 7:0) */ 34303c7a6a8SSebastian Herbszt uint8_t lba0; 34403c7a6a8SSebastian Herbszt uint8_t lba1; 34503c7a6a8SSebastian Herbszt uint8_t lba2; 3467763ed15SJohn Snow uint8_t fua; /* (device 7:0) */ 34703c7a6a8SSebastian Herbszt uint8_t lba3; 34803c7a6a8SSebastian Herbszt uint8_t lba4; 34903c7a6a8SSebastian Herbszt uint8_t lba5; 3507763ed15SJohn Snow uint8_t sector_count_high; /* (feature 15:8) */ 3517763ed15SJohn Snow uint8_t tag; /* (count 0:7) */ 3527763ed15SJohn Snow uint8_t prio; /* (count 15:8) */ 3537763ed15SJohn Snow uint8_t icc; 35403c7a6a8SSebastian Herbszt uint8_t control; 3557763ed15SJohn Snow uint8_t aux0; 3567763ed15SJohn Snow uint8_t aux1; 3577763ed15SJohn Snow uint8_t aux2; 3587763ed15SJohn Snow uint8_t aux3; 359541dc0d4SStefan Weil } QEMU_PACKED NCQFrame; 36003c7a6a8SSebastian Herbszt 36154a7f8f3SJohn Snow typedef struct SDBFIS { 36254a7f8f3SJohn Snow uint8_t type; 36354a7f8f3SJohn Snow uint8_t flags; 36454a7f8f3SJohn Snow uint8_t status; 36554a7f8f3SJohn Snow uint8_t error; 36654a7f8f3SJohn Snow uint32_t payload; 36754a7f8f3SJohn Snow } QEMU_PACKED SDBFIS; 36854a7f8f3SJohn Snow 3690487eea4SPeter Crosthwaite void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports); 3700487eea4SPeter Crosthwaite void ahci_init(AHCIState *s, DeviceState *qdev); 3712c4b9d0eSAlexander Graf void ahci_uninit(AHCIState *s); 37203c7a6a8SSebastian Herbszt 3738ab60a07SJan Kiszka void ahci_reset(AHCIState *s); 37403c7a6a8SSebastian Herbszt 375d93162e1SJohn Snow void ahci_ide_create_devs(PCIDevice *dev, DriveInfo **hd); 376d93162e1SJohn Snow 3775ea8b9c5SAlistair Francis #define TYPE_SYSBUS_AHCI "sysbus-ahci" 3785ea8b9c5SAlistair Francis #define SYSBUS_AHCI(obj) OBJECT_CHECK(SysbusAHCIState, (obj), TYPE_SYSBUS_AHCI) 3795ea8b9c5SAlistair Francis 3805ea8b9c5SAlistair Francis typedef struct SysbusAHCIState { 3815ea8b9c5SAlistair Francis /*< private >*/ 3825ea8b9c5SAlistair Francis SysBusDevice parent_obj; 3835ea8b9c5SAlistair Francis /*< public >*/ 3845ea8b9c5SAlistair Francis 3855ea8b9c5SAlistair Francis AHCIState ahci; 3865ea8b9c5SAlistair Francis uint32_t num_ports; 3875ea8b9c5SAlistair Francis } SysbusAHCIState; 3885ea8b9c5SAlistair Francis 389377e2145SPeter Crosthwaite #define TYPE_ALLWINNER_AHCI "allwinner-ahci" 390377e2145SPeter Crosthwaite #define ALLWINNER_AHCI(obj) OBJECT_CHECK(AllwinnerAHCIState, (obj), \ 391377e2145SPeter Crosthwaite TYPE_ALLWINNER_AHCI) 392377e2145SPeter Crosthwaite 393377e2145SPeter Crosthwaite #define ALLWINNER_AHCI_MMIO_OFF 0x80 394377e2145SPeter Crosthwaite #define ALLWINNER_AHCI_MMIO_SIZE 0x80 395377e2145SPeter Crosthwaite 396377e2145SPeter Crosthwaite struct AllwinnerAHCIState { 397377e2145SPeter Crosthwaite /*< private >*/ 398377e2145SPeter Crosthwaite SysbusAHCIState parent_obj; 399377e2145SPeter Crosthwaite /*< public >*/ 400377e2145SPeter Crosthwaite 401377e2145SPeter Crosthwaite MemoryRegion mmio; 402377e2145SPeter Crosthwaite uint32_t regs[ALLWINNER_AHCI_MMIO_SIZE/4]; 403377e2145SPeter Crosthwaite }; 404377e2145SPeter Crosthwaite 40503c7a6a8SSebastian Herbszt #endif /* HW_IDE_AHCI_H */ 406