UDI/bus_pci - Apply erratum E20010702.1, handle status from preprocessed interrupts
[tpg/acess2.git] / KernelLand / Modules / Storage / AHCI / ahci_hw.h
1 /*
2  * Acess2 Kernel - AHCI Driver
3  * - By John Hodge (thePowersGang)
4  *
5  * ahci_hw.h
6  * - Hardware Definitions
7  */
8 #ifndef _AHCI__AHCI_HW_H_
9 #define _AHCI__AHCI_HW_H_
10
11 #include "sata.h"
12
13 #define AHCI_CAP_S64A   (1 << 31)       // Supports 64-bit addressing
14 #define AHCI_CAP_SNCQ   (1 << 30)       // Supports Native Command Queuing
15 #define AHCI_CAP_SXS    (1 << 5)        // Support External SATA
16 #define AHCI_CAP_NCS    (31 << 8)       // Number of command slots (mask)
17 #define AHCI_CAP_NCS_ofs        8       //                         (offset)
18
19 #define AHCI_GHC_AE     (1 << 31)       // AHCI Enable
20 #define AHCI_GHC_MRSM   (1 << 2)        // MSI Revert to Single Message
21 #define AHCI_GHC_IE     (1 << 1)        // Interrupt Enable
22 #define ACHI_GHC_HR     (1 << 0)        // HBA Reset (Clears once complete)
23
24 #define AHCI_PxIS_CPDS  (1 << 31)       // Cold Port Detect Status
25 #define AHCI_PxIS_TFES  (1 << 30)       // Task File Error Status
26 #define AHCI_PxIS_HBFS  (1 << 29)       // Host Bus Fatal error Status
27 #define AHCI_PxIS_HBDS  (1 << 28)       // Host Bus Data error Status
28 #define AHCI_PxIS_IFS   (1 << 27)       // Interface Fatal error Status
29 #define AHCI_PxIS_INFS  (1 << 26)       // Interface Non-Fatal error status
30 #define AHCI_PxIS_OFS   (1 << 24)       // OverFlow Status
31 #define AHCI_PxIS_IPMS  (1 << 23)       // Incorrect Port Multipier Status
32 #define AHCI_PxIS_PRCS  (1 << 22)       // PhyRdy Change Status
33 #define AHCI_PxIS_DMPS  (1 << 7)        // Device Mechanical Presence Status
34 #define AHCI_PxIS_PCS   (1 << 6)        // Port Connect change Status
35 #define AHCI_PxIS_DPS   (1 << 5)        // Descriptor Processed
36 #define AHCI_PxIS_UFI   (1 << 4)        // Unknown FIX Interrupt
37 #define AHCI_PxIS_SDBS  (1 << 3)        // Set Device Bits Interrupt
38 #define AHCI_PxIS_DSS   (1 << 2)        // DMA Setup FIS Interrupt
39 #define AHCI_PxIS_PSS   (1 << 1)        // PIO Setup FIX Interrupt
40 #define AHCI_PxIS_DHRS  (1 << 0)        // Device to Host Register FIS Interrupt
41
42 #define AHCI_PxCMD_ICC  (15 << 28)      // Interface Communication Control (mask)
43 #define AHCI_PxCMD_ASP  (1 << 27)       // Agressive Slumber / Partial
44 #define AHCI_PxCMD_ALPE (1 << 26)       // Agressive Link Power Management Enable
45 #define AHCI_PxCMD_DLAE (1 << 25)       // Drive LED on ATAPI Enable
46 #define AHCI_PxCMD_ATAPI        (1 << 24)       // Device is ATAPI
47 #define AHCI_PxCMD_APSTE        (1 << 23)       // Automatic Partial to Slumber Transitions Enabled
48 #define AHCI_PxCMD_FBSCP        (1 << 22)       // FIS-based Switching Capable Port
49 #define AHCI_PxCMD_ESP  (1 << 21)       // External SATA Port
50 #define AHCI_PxCMD_CPD  (1 << 20)       // Cold Presence Detection
51 #define AHCI_PxCMD_MPSP (1 << 19)       // Mechanical Presence Switch attached to Port
52 #define AHCI_PxCMD_HPCP (1 << 18)       // Hot Plut Capable Port
53 #define AHCI_PxCMD_PMA  (1 << 17)       // Port Multiplier Attached
54 #define AHCI_PxCMD_CPS  (1 << 16)       // Cold Presence State
55 #define AHCI_PxCMD_CR   (1 << 15)       // Command List Running
56 #define AHCI_PxCMD_FR   (1 << 14)       // FIS Receive Running
57 #define AHCI_PxCMD_MPSS (1 << 13)       // Mechanical Presence Switch State
58 #define AHCI_PxCMD_CCS  (31 << 8)       // Current Command Slot (mask)
59 #define AHCI_PxCMD_FRE  (1 << 4)        // FIS Receive Enable
60 #define AHCI_PxCMD_CLO  (1 << 3)        // Command List Override
61 #define AHCI_PxCMD_POD  (1 << 2)        // Power On Device
62 #define AHCI_PxCMD_SUD  (1 << 1)        // Spin-Up Device
63 #define AHCI_PxCMD_ST   (1 << 0)        // Start
64
65 #define AHCI_PxTFD_ERR  (255 << 8)
66 #define AHCI_PxTFD_STS  (255 << 0)      // Status (latest copy of task file status register)
67 #define AHCI_PxTFD_STS_BSY      (1 << 7)        // Interface is busy
68 #define AHCI_PxTFD_STS_DRQ      (1 << 3)        // Data transfer requested
69 #define AHCI_PxTFD_STS_ERR      (1 << 0)        // Error during transfer
70
71 #define AHCI_PxSSTS_IPM (15 << 8)       // Interface Power Management (0=NP,1=Active,2=Partial,6=Slumber)
72 #define AHCI_PxSSTS_IPM_ofs     8
73 #define AHCI_PxSSTS_SPD (15 << 4)       // Current Interface Speed (0=NP,Generation n)
74 #define AHCI_PxSSTS_SPD_ofs     4
75 #define AHCI_PxSSTS_DET (15 << 0)       // Device Detection (0: None, 1: Present but no PHY yet, 3: Present and PHY, 4: offline)
76 #define AHCI_PxSSTS_DET_ofs     0
77
78 typedef volatile struct sAHCI_MemSpace  tAHCI_MemSpace;
79
80 struct sAHCI_MemSpace
81 {
82         Uint32  CAP;    // Host Capabilities
83         Uint32  GHC;    // Global Host Control;
84         Uint32  IS;     // Interrupt Status
85         Uint32  PI;     // Ports Implemented
86         Uint32  VS;     // Version
87         Uint32  CCC_CTL;        // Command Completion Coalsecing Control
88         Uint32  CCC_PORTS;      // Command Completion Coalsecing Ports
89         Uint32  EM_LOC; // Enclosure Management Location
90         Uint32  EM_CTL; // Enclosure management control
91         Uint32  CAP2;   // Host Capabilities Extended
92         Uint32  BOHC;   // BIOS/OS Handoff Control and Status
93         
94         Uint16  _padding[(0x100-0x2C)/2];
95
96         struct s_port
97         {
98                 Uint32  PxCLB;  // Command List Base Address
99                 Uint32  PxCLBU; // (High of above)
100                 Uint32  PxFB;   // FIS Base Address
101                 Uint32  PxFBU;  // (high of above)
102                 Uint32  PxIS;   // Interrupt Status
103                 Uint32  PxIE;   // Interrupt Enable
104                 Uint32  PxCMD;  // Command and Status
105                 Uint32  _resvd;
106                 Uint32  PxTFD;  // Task File Data
107                 Uint32  PxSIG;  // Signature
108                 Uint32  PxSSTS; // Serial ATA Status
109                 Uint32  PxSCTL; // Serial ATA Control
110                 Uint32  PxSERR; // Serial ATA Error
111                 Uint32  PxSACT; // Serial ATA Active
112                 Uint32  PxCI;   // Command Issue
113                 Uint32  PxSNTF; // Serial ATA Notification
114                 Uint32  PxFBS;  // FIS-based Switching Control
115                 Uint32  _resvd2[(0x70-0x44)/4];
116                 Uint32  PxVS[4];
117         }       Ports[32];
118 } PACKED;
119
120 struct sAHCI_RcvdFIS
121 {
122         struct sSATA_FIS_DMASetup       DSFIS;
123         Uint32  _pad1[1];
124         struct sSATA_FIS_PIOSetup       PSFIS;
125         Uint32  _pad2[3];
126         struct sSATA_FIS_D2HRegister    RFIS;
127         Uint32  _pad3[1];
128         struct sSATA_FIS_SDB    SDBFIS;
129         Uint32  UFIS[64/4];
130         Uint32  _redvd[(0x100 - 0xA0) / 4];
131 } PACKED;
132
133 struct sAHCI_CmdHdr
134 {
135         Uint16  Flags;
136         Uint16  PRDTL;
137         Uint32  PRDBC;
138         Uint32  CTBA;   // 128-byte alignment
139         Uint32  CTBAU;
140         union {
141                 struct {
142                         struct sThread  *Thread;
143                         struct sAHCI_CmdTable   *TablePtr;
144                 } PACKED Ptrs;
145                 Uint32  resdv[4];
146         } Resvd;
147 } PACKED;
148
149 struct sAHCI_CmdEnt
150 {
151         Uint32  DBA;    // Data base address
152         Uint32  DBAU;   // (upper)
153         Uint32  resvd;
154         Uint32  DBC;    // Data byte count (31: IOC, 21:0 count) 0=1, 1=2, ...
155 } PACKED;
156
157 struct sAHCI_CmdTable
158 {
159         Uint32  CFIS[64/4];
160         Uint32  ACMD[16/4];
161         Uint32  _resvd[0x30/4];
162         struct sAHCI_CmdEnt     PRDT[0x80/16];
163 } PACKED;
164
165 #endif
166

UCC git Repository :: git.ucc.asn.au