5 Copyright © 2010, The AROS Development Team. All rights reserved
9 #include <exec/types.h>
13 #define AHCI_VERSION_0_95 0x00000095
14 #define AHCI_VERSION_1_00 0x00010000
15 #define AHCI_VERSION_1_10 0x00010100
16 #define AHCI_VERSION_1_20 0x00010200
17 #define AHCI_VERSION_1_30 0x00010300
20 CAP_S64A
= (1 << 31), // Supports 64-bit Addressing
21 CAP_SNCQ
= (1 << 30), // Supports Native Command Queuing
22 CAP_SSNTF
= (1 << 29), // Supports SNotification Register
23 CAP_SMPS
= (1 << 28), // Supports Mechanical Presence Switch
24 CAP_SSS
= (1 << 27), // Supports Staggered Spin-up
25 CAP_SALP
= (1 << 26), // Supports Aggressive Link Power Management
26 CAP_SAL
= (1 << 25), // Supports Activity LED
27 CAP_SCLO
= (1 << 24), // Supports Command List Override
28 CAP_ISS_MASK
= 0xf, // Interface Speed Support
30 CAP_SNZO
= (1 << 19), // Supports Non-Zero DMA Offsets
31 CAP_SAM
= (1 << 18), // Supports AHCI mode only
32 CAP_SPM
= (1 << 17), // Supports Port Multiplier
33 CAP_FBSS
= (1 << 16), // FIS-based Switching Supported
34 CAP_PMD
= (1 << 15), // PIO Multiple DRQ Block
35 CAP_SSC
= (1 << 14), // Slumber State Capable
36 CAP_PSC
= (1 << 13), // Partial State Capable
37 CAP_NCS_MASK
= 0x1f, // Number of Command Slots (zero-based number)
39 CAP_CCCS
= (1 << 7), // Command Completion Coalescing Supported
40 CAP_EMS
= (1 << 6), // Enclosure Management Supported
41 CAP_SXS
= (1 << 5), // Supports External SATA
42 CAP_NP_MASK
= 0x1f, // Number of Ports (zero-based number)
47 CAP2_APST
= (1 << 2), // Automatic Partial to Slumber Transitions (APST)
48 CAP2_NVNP
= (1 << 1), // NVMHCI Present (NVMP)
49 CAP2_BOH
= (1 << 0), // BIOS/OS Handoff (BOH)
61 GHC_AE
= (1 << 31), // AHCI Enable
62 GHC_MRSM
= (1 << 2), // MSI Revert to Single Message
63 GHC_IE
= (1 << 1), // Interrupt Enable
64 GHC_HR
= (1 << 0), // HBA Reset **RW1**
68 PORT_CMD_ICC_ACTIVE
= (1 << 28), // Interface Communication control
69 PORT_CMD_ICC_SLUMBER
= (6 << 28), // Interface Communication control
70 PORT_CMD_ICC_MASK
= (0xf<<28), // Interface Communication control
71 PORT_CMD_ATAPI
= (1 << 24), // Device is ATAPI
72 PORT_CMD_CR
= (1 << 15), // Command List Running (DMA active)
73 PORT_CMD_FR
= (1 << 14), // FIS Receive Running
74 PORT_CMD_FRE
= (1 << 4), // FIS Receive Enable
75 PORT_CMD_CLO
= (1 << 3), // Command List Override
76 PORT_CMD_POD
= (1 << 2), // Power On Device
77 PORT_CMD_SUD
= (1 << 1), // Spin-up Device
78 PORT_CMD_ST
= (1 << 0), // Start DMA
82 PORT_INT_CPD
= (1 << 31), // Cold Presence Detect Status/Enable
83 PORT_INT_TFE
= (1 << 30), // Task File Error Status/Enable
84 PORT_INT_HBF
= (1 << 29), // Host Bus Fatal Error Status/Enable
85 PORT_INT_HBD
= (1 << 28), // Host Bus Data Error Status/Enable
86 PORT_INT_IF
= (1 << 27), // Interface Fatal Error Status/Enable
87 PORT_INT_INF
= (1 << 26), // Interface Non-fatal Error Status/Enable
88 PORT_INT_OF
= (1 << 24), // Overflow Status/Enable
89 PORT_INT_IPM
= (1 << 23), // Incorrect Port Multiplier Status/Enable
90 PORT_INT_PRC
= (1 << 22), // PhyRdy Change Status/Enable
91 PORT_INT_DI
= (1 << 7), // Device Interlock Status/Enable
92 PORT_INT_PC
= (1 << 6), // Port Change Status/Enable
93 PORT_INT_DP
= (1 << 5), // Descriptor Processed Interrupt
94 PORT_INT_UF
= (1 << 4), // Unknown FIS Interrupt
95 PORT_INT_SDB
= (1 << 3), // Set Device Bits FIS Interrupt
96 PORT_INT_DS
= (1 << 2), // DMA Setup FIS Interrupt
97 PORT_INT_PS
= (1 << 1), // PIO Setup FIS Interrupt
98 PORT_INT_DHR
= (1 << 0), // Device to Host Register FIS Interrupt
102 PORT_TFD_ERR_MASK
= 0xff, // Last error from task file
103 PORT_TFD_ERR_SHIFT
= 8,
104 PORT_TFD_STS_MASK
= 0xff, // Status of task file
105 PORT_TFD_STS_BSY
= (1 << 7), // Busy
106 PORT_TFD_STS_DRQ
= (1 << 3), // Data requested
107 PORT_TFD_STS_ERR
= (1 << 0), // Transfer error
111 PORT_SIG_LBA_HIGH_MASK
= 0xff, // LBA High Register
112 PORT_SIG_LBA_HIGH_SHIFT
= 24,
113 PORT_SIG_LBA_MED_MASK
= 0xff, // LBA Med Register
114 PORT_SIG_LBA_MED_SHIFT
= 16,
115 PORT_SIG_LBA_LOW_MASK
= 0xff, // LBA Low Register
116 PORT_SIG_LBA_LOW_SHIFT
= 8,
117 PORT_SIG_SECTORS_MASK
= 0xff, // Sector Count Register
121 PORT_SSTS_IPM_MASK
= (0xf << 8), // Interface state
122 PORT_SSTS_IPM_NODEV
= (0 << 8), // No device present
123 PORT_SSTS_IPM_ACTIVE
= (1 << 8), // Interface active
124 PORT_SSTS_IPM_PARTIAL
= (2 << 8), // Partial power save
125 PORT_SSTS_IPM_SLUMBER
= (6 << 8), // Slumber power save
127 PORT_SSTS_SPD_MASK
= (0xf << 4), // Interface speed
128 PORT_SSTS_SPD_NODEV
= (0 << 4), // Interface speed
129 PORT_SSTS_SPD_GEN1
= (1 << 4), // Interface speed
130 PORT_SSTS_SPD_GEN2
= (2 << 4), // Interface speed
131 PORT_SSTS_SPD_GEN3
= (3 << 4), // Interface speed
133 PORT_SSTS_DET_MASK
= 0xf, // Device Detect
134 PORT_SSTS_DET_NODEV
= (0 << 0), // No device, no phy
135 PORT_SSTS_DET_NOPHY
= (1 << 0), // Device, but no phy
136 PORT_SSTS_DET_ONLINE
= (3 << 0), // Online and ready
137 PORT_SSTS_DET_OFFLINE
= (4 << 0), // Offline (Device in BIST?)
141 PORT_SERR_ERR_MASK
= 0xffff, // Errors
144 /********** DMAable Data Structures **********/
154 UBYTE dsfis_pad
[0x20];
161 UBYTE psfis_pad
[0x20];
164 /* D2H register FIS */
168 UBYTE rfis_pad
[0x18];
175 UBYTE sdbfis_pad
[0x8];
184 /* Command List Header Entry */
186 ULONG cw0
; /* PRDTL, PMP, C, B, R, P, W, A, and CFL */
187 ULONG prdbc
; /* PRD byte count */
188 ULONG ctba
; /* Lower 32bits of the command table address. 128 byte aligned */
189 ULONG ctbu
; /* Uppoer 32bit of the command table address */
194 CW0_PRDTL_MASK
= 0xffff, /* Physical Region Descriptor Table Length */
195 CW0_PRDTL_SHIFT
= 16,
196 CW0_PMP_MASK
= 0x1f, /* Port Multiplier Port */
198 CW0_C
= (1 << 10), /* Clear Busy Upon R_OK */
199 CW0_B
= (1 << 9), /* BIST */
200 CW0_R
= (1 << 8), /* Reset */
201 CW0_P
= (1 << 7), /* Prefetchable */
202 CW0_W
= (1 << 6), /* Write to device */
203 CW0_A
= (1 << 5), /* ATAPI */
204 CW0_CFL_MASK
= 0x1f, /* Command FIS Length in ULONGs. Max 16 */
207 /* Command Table (pointed to by a command list header)
208 * Must be 128 byte aligned.
215 UBYTE pad_cfis
[0x40];
222 UBYTE pad_acmd
[0x10];
227 /* Physical Region Descriptor Table
228 * (the scatter-gather DMA list)
231 ULONG dba
; /* Data Base Address (USHORT aligned) */
232 ULONG dbau
; /* Data Base Upper 32 Address */
233 ULONG resv
; /* Reserved */
234 ULONG pw3
; /* I and DBC. See below. */
235 } prdt
[]; /* Up to 65535 entries allowed */
239 PW3_I
= (1 << 31), /* Interrupt on completion */
240 PW3_DBC_MASK
= 0x3fffff, /* N-1 bytes of transfer */
244 volatile ULONG clb
; // Port x Command List Base Address (alignment 1024 byte)
245 volatile ULONG clbu
; // Port x Command List Base Address Upper 32-Bits
246 volatile ULONG fb
; // Port x FIS Base Address (alignment 256 byte)
247 volatile ULONG fbu
; // Port x FIS Base Address Upper 32-Bits
248 volatile ULONG is
; // Port x Interrupt Status
249 volatile ULONG ie
; // Port x Interrupt Enable
250 volatile ULONG cmd
; // Port x Command and Status
251 volatile ULONG res1
; // Port x Reserved
252 volatile ULONG tfd
; // Port x Task File Data
253 volatile ULONG sig
; // Port x Signature
254 volatile ULONG ssts
; // Port x Serial ATA Status (SCR0: SStatus)
255 volatile ULONG sctl
; // Port x Serial ATA Control (SCR2: SControl)
256 volatile ULONG serr
; // Port x Serial ATA Error (SCR1: SError)
257 volatile ULONG sact
; // Port x Serial ATA Active (SCR3: SActive)
258 volatile ULONG ci
; // Port x Command Issue
259 volatile ULONG sntf
; // Port x Serial ATA Notification (SCR4: SNotification)
260 volatile ULONG res2
; // Port x FIS-based Switching Control
261 volatile ULONG res
[11]; // Port x Reserved
262 volatile ULONG vendor
[4]; // Port x Vendor Specific
266 volatile ULONG cap
; // 0x00 Host Capabilities
267 volatile ULONG ghc
; // 0x04 Global Host Control
268 volatile ULONG is
; // 0x08 Interrupt Status
269 volatile ULONG pi
; // 0x0c Ports Implemented
270 volatile ULONG vs
; // 0x10 Version
271 volatile ULONG ccc_ctl
; // 0x14 Command Completion Coalescing Control
272 volatile ULONG ccc_ports
; // 0x18 Command Completion Coalsecing Ports
273 volatile ULONG em_loc
; // 0x1c Enclosure Management Location
274 volatile ULONG em_ctl
; // 0x20 Enclosure Management Control
275 volatile ULONG cap2
; // 0x24 Host Capabilities Extended
276 volatile ULONG bohc
; // 0x28 BIOS/OS Handoff Control and Status
277 volatile ULONG res
[29]; // 0x2c-0x9f Reserved
278 volatile ULONG vendor
[24]; // 0xa0-0xff Vendor Specific registers
279 struct ahci_hwport port
[32]; // 0x100