xref: /qemu/include/hw/ide/ahci.h (revision 4ac557c89b04d506c876a0a378e815d822261c8a)
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 
4303c7a6a8SSebastian Herbszt #define AHCI_IRQ_ON_SG            (1 << 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 */
6403c7a6a8SSebastian Herbszt #define HOST_CTL_AHCI_EN          (1 << 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 */
7203c7a6a8SSebastian Herbszt #define HOST_CAP_64               (1 << 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 */
9203c7a6a8SSebastian Herbszt #define PORT_IRQ_COLD_PRES        (1 << 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 #define PORT_IRQ_STAT_DHRS        (1 << 0) /* Device to Host Register FIS */
13603c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_PSS         (1 << 1) /* PIO Setup FIS */
13703c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_DSS         (1 << 2) /* DMA Setup FIS */
13803c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_SDBS        (1 << 3) /* Set Device Bits */
13903c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_UFS         (1 << 4) /* Unknown FIS */
14003c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_DPS         (1 << 5) /* Descriptor Processed */
14103c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_PCS         (1 << 6) /* Port Connect Change Status */
14203c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_DMPS        (1 << 7) /* Device Mechanical Presence
14303c7a6a8SSebastian Herbszt                                               Status */
14403c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_PRCS        (1 << 22) /* File Ready Status */
14503c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_IPMS        (1 << 23) /* Incorrect Port Multiplier
14603c7a6a8SSebastian Herbszt                                                Status */
14703c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_OFS         (1 << 24) /* Overflow Status */
14803c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_INFS        (1 << 26) /* Interface Non-Fatal Error
14903c7a6a8SSebastian Herbszt                                                Status */
15003c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_IFS         (1 << 27) /* Interface Fatal Error */
15103c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_HBDS        (1 << 28) /* Host Bus Data Error Status */
15203c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_HBFS        (1 << 29) /* Host Bus Fatal Error Status */
15303c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_TFES        (1 << 30) /* Task File Error Status */
15403c7a6a8SSebastian Herbszt #define PORT_IRQ_STAT_CPDS        (1 << 31) /* Code Port Detect Status */
15503c7a6a8SSebastian Herbszt 
15603c7a6a8SSebastian Herbszt /* ap->flags bits */
15703c7a6a8SSebastian Herbszt #define AHCI_FLAG_NO_NCQ                  (1 << 24)
15803c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_IRQ_IF_ERR          (1 << 25) /* ignore IRQ_IF_ERR */
15903c7a6a8SSebastian Herbszt #define AHCI_FLAG_HONOR_PI                (1 << 26) /* honor PORTS_IMPL */
16003c7a6a8SSebastian Herbszt #define AHCI_FLAG_IGN_SERR_INTERNAL       (1 << 27) /* ignore SERR_INTERNAL */
16103c7a6a8SSebastian Herbszt #define AHCI_FLAG_32BIT_ONLY              (1 << 28) /* force 32bit */
16203c7a6a8SSebastian Herbszt 
16303c7a6a8SSebastian Herbszt #define ATA_SRST                          (1 << 2)  /* software reset */
16403c7a6a8SSebastian Herbszt 
16503c7a6a8SSebastian Herbszt #define STATE_RUN                         0
16603c7a6a8SSebastian Herbszt #define STATE_RESET                       1
16703c7a6a8SSebastian Herbszt 
16803c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_NODEV        0x0
16903c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP 0x3
17003c7a6a8SSebastian Herbszt 
17103c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_NODEV        0x00
17203c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_SPD_GEN1         0x10
17303c7a6a8SSebastian Herbszt 
17403c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_NODEV        0x000
17503c7a6a8SSebastian Herbszt #define SATA_SCR_SSTATUS_IPM_ACTIVE       0X100
17603c7a6a8SSebastian Herbszt 
17703c7a6a8SSebastian Herbszt #define AHCI_SCR_SCTL_DET                 0xf
17803c7a6a8SSebastian Herbszt 
17903c7a6a8SSebastian Herbszt #define SATA_FIS_TYPE_REGISTER_H2D        0x27
18003c7a6a8SSebastian Herbszt #define SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER 0x80
18103c7a6a8SSebastian Herbszt 
18203c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_CMD_FIS_LEN           0x1f
18303c7a6a8SSebastian Herbszt #define AHCI_CMD_HDR_PRDT_LEN              16
18403c7a6a8SSebastian Herbszt 
18503c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_CDROM               0xeb140000
18603c7a6a8SSebastian Herbszt #define SATA_SIGNATURE_DISK                0x00000101
18703c7a6a8SSebastian Herbszt 
18803c7a6a8SSebastian Herbszt #define AHCI_GENERIC_HOST_CONTROL_REGS_MAX_ADDR 0x20
18903c7a6a8SSebastian Herbszt                                             /* Shouldn't this be 0x2c? */
19003c7a6a8SSebastian Herbszt 
19103c7a6a8SSebastian Herbszt #define AHCI_PORT_REGS_START_ADDR          0x100
19203c7a6a8SSebastian Herbszt #define AHCI_PORT_ADDR_OFFSET_MASK         0x7f
1932c4b9d0eSAlexander Graf #define AHCI_PORT_ADDR_OFFSET_LEN          0x80
19403c7a6a8SSebastian Herbszt 
19503c7a6a8SSebastian Herbszt #define AHCI_NUM_COMMAND_SLOTS             31
19603c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED               20
19703c7a6a8SSebastian Herbszt #define AHCI_SUPPORTED_SPEED_GEN1          1
19803c7a6a8SSebastian Herbszt #define AHCI_VERSION_1_0                   0x10000
19903c7a6a8SSebastian Herbszt 
20003c7a6a8SSebastian Herbszt #define AHCI_PROGMODE_MAJOR_REV_1          1
20103c7a6a8SSebastian Herbszt 
20203c7a6a8SSebastian Herbszt #define AHCI_COMMAND_TABLE_ACMD            0x40
20303c7a6a8SSebastian Herbszt 
20403c7a6a8SSebastian Herbszt #define IDE_FEATURE_DMA                    1
20503c7a6a8SSebastian Herbszt 
20603c7a6a8SSebastian Herbszt #define READ_FPDMA_QUEUED                  0x60
20703c7a6a8SSebastian Herbszt #define WRITE_FPDMA_QUEUED                 0x61
20803c7a6a8SSebastian Herbszt 
20903c7a6a8SSebastian Herbszt #define RES_FIS_DSFIS                      0x00
21003c7a6a8SSebastian Herbszt #define RES_FIS_PSFIS                      0x20
21103c7a6a8SSebastian Herbszt #define RES_FIS_RFIS                       0x40
21203c7a6a8SSebastian Herbszt #define RES_FIS_SDBFIS                     0x58
21303c7a6a8SSebastian Herbszt #define RES_FIS_UFIS                       0x60
21403c7a6a8SSebastian Herbszt 
215465f1ab1SDaniel Verkamp #define SATA_CAP_SIZE           0x8
216465f1ab1SDaniel Verkamp #define SATA_CAP_REV            0x2
217465f1ab1SDaniel Verkamp #define SATA_CAP_BAR            0x4
218465f1ab1SDaniel Verkamp 
21903c7a6a8SSebastian Herbszt typedef struct AHCIControlRegs {
22003c7a6a8SSebastian Herbszt     uint32_t    cap;
22103c7a6a8SSebastian Herbszt     uint32_t    ghc;
22203c7a6a8SSebastian Herbszt     uint32_t    irqstatus;
22303c7a6a8SSebastian Herbszt     uint32_t    impl;
22403c7a6a8SSebastian Herbszt     uint32_t    version;
22503c7a6a8SSebastian Herbszt } AHCIControlRegs;
22603c7a6a8SSebastian Herbszt 
22703c7a6a8SSebastian Herbszt typedef struct AHCIPortRegs {
22803c7a6a8SSebastian Herbszt     uint32_t    lst_addr;
22903c7a6a8SSebastian Herbszt     uint32_t    lst_addr_hi;
23003c7a6a8SSebastian Herbszt     uint32_t    fis_addr;
23103c7a6a8SSebastian Herbszt     uint32_t    fis_addr_hi;
23203c7a6a8SSebastian Herbszt     uint32_t    irq_stat;
23303c7a6a8SSebastian Herbszt     uint32_t    irq_mask;
23403c7a6a8SSebastian Herbszt     uint32_t    cmd;
23503c7a6a8SSebastian Herbszt     uint32_t    unused0;
23603c7a6a8SSebastian Herbszt     uint32_t    tfdata;
23703c7a6a8SSebastian Herbszt     uint32_t    sig;
23803c7a6a8SSebastian Herbszt     uint32_t    scr_stat;
23903c7a6a8SSebastian Herbszt     uint32_t    scr_ctl;
24003c7a6a8SSebastian Herbszt     uint32_t    scr_err;
24103c7a6a8SSebastian Herbszt     uint32_t    scr_act;
24203c7a6a8SSebastian Herbszt     uint32_t    cmd_issue;
24303c7a6a8SSebastian Herbszt     uint32_t    reserved;
24403c7a6a8SSebastian Herbszt } AHCIPortRegs;
24503c7a6a8SSebastian Herbszt 
24603c7a6a8SSebastian Herbszt typedef struct AHCICmdHdr {
24703c7a6a8SSebastian Herbszt     uint32_t    opts;
24803c7a6a8SSebastian Herbszt     uint32_t    status;
24903c7a6a8SSebastian Herbszt     uint64_t    tbl_addr;
25003c7a6a8SSebastian Herbszt     uint32_t    reserved[4];
251541dc0d4SStefan Weil } QEMU_PACKED AHCICmdHdr;
25203c7a6a8SSebastian Herbszt 
25303c7a6a8SSebastian Herbszt typedef struct AHCI_SG {
25403c7a6a8SSebastian Herbszt     uint64_t    addr;
25503c7a6a8SSebastian Herbszt     uint32_t    reserved;
25603c7a6a8SSebastian Herbszt     uint32_t    flags_size;
257541dc0d4SStefan Weil } QEMU_PACKED AHCI_SG;
25803c7a6a8SSebastian Herbszt 
25903c7a6a8SSebastian Herbszt typedef struct AHCIDevice AHCIDevice;
26003c7a6a8SSebastian Herbszt 
26103c7a6a8SSebastian Herbszt typedef struct NCQTransferState {
26203c7a6a8SSebastian Herbszt     AHCIDevice *drive;
26303c7a6a8SSebastian Herbszt     BlockDriverAIOCB *aiocb;
26403c7a6a8SSebastian Herbszt     QEMUSGList sglist;
265a597e79cSChristoph Hellwig     BlockAcctCookie acct;
26603c7a6a8SSebastian Herbszt     uint16_t sector_count;
26703c7a6a8SSebastian Herbszt     uint64_t lba;
26803c7a6a8SSebastian Herbszt     uint8_t tag;
26903c7a6a8SSebastian Herbszt     int slot;
27003c7a6a8SSebastian Herbszt     int used;
27103c7a6a8SSebastian Herbszt } NCQTransferState;
27203c7a6a8SSebastian Herbszt 
27303c7a6a8SSebastian Herbszt struct AHCIDevice {
27403c7a6a8SSebastian Herbszt     IDEDMA dma;
27503c7a6a8SSebastian Herbszt     IDEBus port;
27603c7a6a8SSebastian Herbszt     int port_no;
27703c7a6a8SSebastian Herbszt     uint32_t port_state;
27803c7a6a8SSebastian Herbszt     uint32_t finished;
27903c7a6a8SSebastian Herbszt     AHCIPortRegs port_regs;
28003c7a6a8SSebastian Herbszt     struct AHCIState *hba;
28103c7a6a8SSebastian Herbszt     QEMUBH *check_bh;
28203c7a6a8SSebastian Herbszt     uint8_t *lst;
28303c7a6a8SSebastian Herbszt     uint8_t *res_fis;
284*4ac557c8SKevin Wolf     bool done_atapi_packet;
285*4ac557c8SKevin Wolf     int32_t busy_slot;
286*4ac557c8SKevin Wolf     bool init_d2h_sent;
28703c7a6a8SSebastian Herbszt     AHCICmdHdr *cur_cmd;
28803c7a6a8SSebastian Herbszt     NCQTransferState ncq_tfs[AHCI_MAX_CMDS];
28903c7a6a8SSebastian Herbszt };
29003c7a6a8SSebastian Herbszt 
29103c7a6a8SSebastian Herbszt typedef struct AHCIState {
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 */
298*4ac557c8SKevin Wolf     int32_t ports;
29903c7a6a8SSebastian Herbszt     qemu_irq irq;
30010ca2943SDavid Gibson     DMAContext *dma;
30103c7a6a8SSebastian Herbszt } AHCIState;
30203c7a6a8SSebastian Herbszt 
30303c7a6a8SSebastian Herbszt typedef struct AHCIPCIState {
30403c7a6a8SSebastian Herbszt     PCIDevice card;
30503c7a6a8SSebastian Herbszt     AHCIState ahci;
30603c7a6a8SSebastian Herbszt } AHCIPCIState;
30703c7a6a8SSebastian Herbszt 
30803c7a6a8SSebastian Herbszt typedef struct NCQFrame {
30903c7a6a8SSebastian Herbszt     uint8_t fis_type;
31003c7a6a8SSebastian Herbszt     uint8_t c;
31103c7a6a8SSebastian Herbszt     uint8_t command;
31203c7a6a8SSebastian Herbszt     uint8_t sector_count_low;
31303c7a6a8SSebastian Herbszt     uint8_t lba0;
31403c7a6a8SSebastian Herbszt     uint8_t lba1;
31503c7a6a8SSebastian Herbszt     uint8_t lba2;
31603c7a6a8SSebastian Herbszt     uint8_t fua;
31703c7a6a8SSebastian Herbszt     uint8_t lba3;
31803c7a6a8SSebastian Herbszt     uint8_t lba4;
31903c7a6a8SSebastian Herbszt     uint8_t lba5;
32003c7a6a8SSebastian Herbszt     uint8_t sector_count_high;
32103c7a6a8SSebastian Herbszt     uint8_t tag;
32203c7a6a8SSebastian Herbszt     uint8_t reserved5;
32303c7a6a8SSebastian Herbszt     uint8_t reserved6;
32403c7a6a8SSebastian Herbszt     uint8_t control;
32503c7a6a8SSebastian Herbszt     uint8_t reserved7;
32603c7a6a8SSebastian Herbszt     uint8_t reserved8;
32703c7a6a8SSebastian Herbszt     uint8_t reserved9;
32803c7a6a8SSebastian Herbszt     uint8_t reserved10;
329541dc0d4SStefan Weil } QEMU_PACKED NCQFrame;
33003c7a6a8SSebastian Herbszt 
33110ca2943SDavid Gibson void ahci_init(AHCIState *s, DeviceState *qdev, DMAContext *dma, int ports);
3322c4b9d0eSAlexander Graf void ahci_uninit(AHCIState *s);
33303c7a6a8SSebastian Herbszt 
3348ab60a07SJan Kiszka void ahci_reset(AHCIState *s);
33503c7a6a8SSebastian Herbszt 
33603c7a6a8SSebastian Herbszt #endif /* HW_IDE_AHCI_H */
337