TianoCore EDK2 master
Loading...
Searching...
No Matches
AhciMode.h
Go to the documentation of this file.
1
9#ifndef __ATA_HC_AHCI_MODE_H__
10#define __ATA_HC_AHCI_MODE_H__
11
12#define EFI_AHCI_BAR_INDEX 0x05
13
14#define EFI_AHCI_CAPABILITY_OFFSET 0x0000
15#define EFI_AHCI_CAP_SAM BIT18
16#define EFI_AHCI_CAP_SSS BIT27
17#define EFI_AHCI_CAP_S64A BIT31
18#define EFI_AHCI_GHC_OFFSET 0x0004
19#define EFI_AHCI_GHC_RESET BIT0
20#define EFI_AHCI_GHC_IE BIT1
21#define EFI_AHCI_GHC_ENABLE BIT31
22#define EFI_AHCI_IS_OFFSET 0x0008
23#define EFI_AHCI_PI_OFFSET 0x000C
24
25#define EFI_AHCI_MAX_PORTS 32
26
27#define AHCI_CAPABILITY2_OFFSET 0x0024
28#define AHCI_CAP2_SDS BIT3
29#define AHCI_CAP2_SADM BIT4
30
31typedef struct {
32 UINT32 Lower32;
33 UINT32 Upper32;
34} DATA_32;
35
36typedef union {
37 DATA_32 Uint32;
38 UINT64 Uint64;
39} DATA_64;
40
41//
42// Refer SATA1.0a spec section 5.2, the Phy detection time should be less than 10ms.
43// Add a bit of margin for robustness.
44//
45#define EFI_AHCI_BUS_PHY_DETECT_TIMEOUT 15
46//
47// Refer SATA1.0a spec, the FIS enable time should be less than 500ms.
48//
49#define EFI_AHCI_PORT_CMD_FR_CLEAR_TIMEOUT EFI_TIMER_PERIOD_MILLISECONDS(500)
50//
51// Refer SATA1.0a spec, the bus reset time should be less than 1s.
52//
53#define EFI_AHCI_BUS_RESET_TIMEOUT EFI_TIMER_PERIOD_SECONDS(1)
54
55#define EFI_AHCI_ATAPI_DEVICE_SIG 0xEB140000
56#define EFI_AHCI_ATA_DEVICE_SIG 0x00000000
57#define EFI_AHCI_PORT_MULTIPLIER_SIG 0x96690000
58#define EFI_AHCI_ATAPI_SIG_MASK 0xFFFF0000
59
60//
61// Each PRDT entry can point to a memory block up to 4M byte
62//
63#define EFI_AHCI_MAX_DATA_PER_PRDT 0x400000
64
65#define EFI_AHCI_FIS_REGISTER_H2D 0x27 // Register FIS - Host to Device
66#define EFI_AHCI_FIS_REGISTER_H2D_LENGTH 20
67#define EFI_AHCI_FIS_REGISTER_D2H 0x34 // Register FIS - Device to Host
68#define EFI_AHCI_FIS_REGISTER_D2H_LENGTH 20
69#define EFI_AHCI_FIS_DMA_ACTIVATE 0x39 // DMA Activate FIS - Device to Host
70#define EFI_AHCI_FIS_DMA_ACTIVATE_LENGTH 4
71#define EFI_AHCI_FIS_DMA_SETUP 0x41 // DMA Setup FIS - Bi-directional
72#define EFI_AHCI_FIS_DMA_SETUP_LENGTH 28
73#define EFI_AHCI_FIS_DATA 0x46 // Data FIS - Bi-directional
74#define EFI_AHCI_FIS_BIST 0x58 // BIST Activate FIS - Bi-directional
75#define EFI_AHCI_FIS_BIST_LENGTH 12
76#define EFI_AHCI_FIS_PIO_SETUP 0x5F // PIO Setup FIS - Device to Host
77#define EFI_AHCI_FIS_PIO_SETUP_LENGTH 20
78#define EFI_AHCI_FIS_SET_DEVICE 0xA1 // Set Device Bits FIS - Device to Host
79#define EFI_AHCI_FIS_SET_DEVICE_LENGTH 8
80
81#define EFI_AHCI_D2H_FIS_OFFSET 0x40
82#define EFI_AHCI_DMA_FIS_OFFSET 0x00
83#define EFI_AHCI_PIO_FIS_OFFSET 0x20
84#define EFI_AHCI_SDB_FIS_OFFSET 0x58
85#define EFI_AHCI_FIS_TYPE_MASK 0xFF
86#define EFI_AHCI_U_FIS_OFFSET 0x60
87
88//
89// Port register
90//
91#define EFI_AHCI_PORT_START 0x0100
92#define EFI_AHCI_PORT_REG_WIDTH 0x0080
93#define EFI_AHCI_PORT_CLB 0x0000
94#define EFI_AHCI_PORT_CLBU 0x0004
95#define EFI_AHCI_PORT_FB 0x0008
96#define EFI_AHCI_PORT_FBU 0x000C
97#define EFI_AHCI_PORT_IS 0x0010
98#define EFI_AHCI_PORT_IS_DHRS BIT0
99#define EFI_AHCI_PORT_IS_PSS BIT1
100#define EFI_AHCI_PORT_IS_DSS BIT2
101#define EFI_AHCI_PORT_IS_SDBS BIT3
102#define EFI_AHCI_PORT_IS_UFS BIT4
103#define EFI_AHCI_PORT_IS_DPS BIT5
104#define EFI_AHCI_PORT_IS_PCS BIT6
105#define EFI_AHCI_PORT_IS_DIS BIT7
106#define EFI_AHCI_PORT_IS_PRCS BIT22
107#define EFI_AHCI_PORT_IS_IPMS BIT23
108#define EFI_AHCI_PORT_IS_OFS BIT24
109#define EFI_AHCI_PORT_IS_INFS BIT26
110#define EFI_AHCI_PORT_IS_IFS BIT27
111#define EFI_AHCI_PORT_IS_HBDS BIT28
112#define EFI_AHCI_PORT_IS_HBFS BIT29
113#define EFI_AHCI_PORT_IS_TFES BIT30
114#define EFI_AHCI_PORT_IS_CPDS BIT31
115#define EFI_AHCI_PORT_IS_CLEAR 0xFFFFFFFF
116#define EFI_AHCI_PORT_IS_FIS_CLEAR 0x0000000F
117#define EFI_AHCI_PORT_IS_ERROR_MASK (EFI_AHCI_PORT_IS_INFS | EFI_AHCI_PORT_IS_IFS | EFI_AHCI_PORT_IS_HBDS | EFI_AHCI_PORT_IS_HBFS | EFI_AHCI_PORT_IS_TFES)
118#define EFI_AHCI_PORT_IS_FATAL_ERROR_MASK (EFI_AHCI_PORT_IS_IFS | EFI_AHCI_PORT_IS_HBDS | EFI_AHCI_PORT_IS_HBFS | EFI_AHCI_PORT_IS_TFES)
119
120#define EFI_AHCI_PORT_IE 0x0014
121#define EFI_AHCI_PORT_CMD 0x0018
122#define EFI_AHCI_PORT_CMD_ST_MASK 0xFFFFFFFE
123#define EFI_AHCI_PORT_CMD_ST BIT0
124#define EFI_AHCI_PORT_CMD_SUD BIT1
125#define EFI_AHCI_PORT_CMD_POD BIT2
126#define EFI_AHCI_PORT_CMD_CLO BIT3
127#define EFI_AHCI_PORT_CMD_FRE BIT4
128#define EFI_AHCI_PORT_CMD_CCS_MASK (BIT8 | BIT9 | BIT10 | BIT11 | BIT12)
129#define EFI_AHCI_PORT_CMD_CCS_SHIFT 8
130#define EFI_AHCI_PORT_CMD_FR BIT14
131#define EFI_AHCI_PORT_CMD_CR BIT15
132#define EFI_AHCI_PORT_CMD_MASK ~(EFI_AHCI_PORT_CMD_ST | EFI_AHCI_PORT_CMD_FRE | EFI_AHCI_PORT_CMD_COL)
133#define EFI_AHCI_PORT_CMD_PMA BIT17
134#define EFI_AHCI_PORT_CMD_HPCP BIT18
135#define EFI_AHCI_PORT_CMD_MPSP BIT19
136#define EFI_AHCI_PORT_CMD_CPD BIT20
137#define EFI_AHCI_PORT_CMD_ESP BIT21
138#define EFI_AHCI_PORT_CMD_ATAPI BIT24
139#define EFI_AHCI_PORT_CMD_DLAE BIT25
140#define EFI_AHCI_PORT_CMD_ALPE BIT26
141#define EFI_AHCI_PORT_CMD_ASP BIT27
142#define EFI_AHCI_PORT_CMD_ICC_MASK (BIT28 | BIT29 | BIT30 | BIT31)
143#define EFI_AHCI_PORT_CMD_ACTIVE (1 << 28 )
144#define EFI_AHCI_PORT_TFD 0x0020
145#define EFI_AHCI_PORT_TFD_MASK (BIT7 | BIT3 | BIT0)
146#define EFI_AHCI_PORT_TFD_BSY BIT7
147#define EFI_AHCI_PORT_TFD_DRQ BIT3
148#define EFI_AHCI_PORT_TFD_ERR BIT0
149#define EFI_AHCI_PORT_TFD_ERR_MASK 0x00FF00 // ERROR field is specified by ATA/ATAPI Command Set specification
150#define EFI_AHCI_PORT_TFD_ERR_INT_CRC BIT15
151#define EFI_AHCI_PORT_SIG 0x0024
152#define EFI_AHCI_PORT_SSTS 0x0028
153#define EFI_AHCI_PORT_SSTS_DET_MASK 0x000F
154#define EFI_AHCI_PORT_SSTS_DET 0x0001
155#define EFI_AHCI_PORT_SSTS_DET_PCE 0x0003
156#define EFI_AHCI_PORT_SSTS_SPD_MASK 0x00F0
157#define EFI_AHCI_PORT_SCTL 0x002C
158#define EFI_AHCI_PORT_SCTL_DET_MASK 0x000F
159#define EFI_AHCI_PORT_SCTL_MASK (~EFI_AHCI_PORT_SCTL_DET_MASK)
160#define EFI_AHCI_PORT_SCTL_DET_INIT 0x0001
161#define EFI_AHCI_PORT_SCTL_DET_PHYCOMM 0x0003
162#define EFI_AHCI_PORT_SCTL_SPD_MASK 0x00F0
163#define EFI_AHCI_PORT_SCTL_IPM_MASK 0x0F00
164#define EFI_AHCI_PORT_SCTL_IPM_INIT 0x0300
165#define EFI_AHCI_PORT_SCTL_IPM_PSD 0x0100
166#define EFI_AHCI_PORT_SCTL_IPM_SSD 0x0200
167#define EFI_AHCI_PORT_SERR 0x0030
168#define EFI_AHCI_PORT_SERR_RDIE BIT0
169#define EFI_AHCI_PORT_SERR_RCE BIT1
170#define EFI_AHCI_PORT_SERR_TDIE BIT8
171#define EFI_AHCI_PORT_SERR_PCDIE BIT9
172#define EFI_AHCI_PORT_SERR_PE BIT10
173#define EFI_AHCI_PORT_SERR_IE BIT11
174#define EFI_AHCI_PORT_SERR_PRC BIT16
175#define EFI_AHCI_PORT_SERR_PIE BIT17
176#define EFI_AHCI_PORT_SERR_CW BIT18
177#define EFI_AHCI_PORT_SERR_BDE BIT19
178#define EFI_AHCI_PORT_SERR_DE BIT20
179#define EFI_AHCI_PORT_SERR_CRCE BIT21
180#define EFI_AHCI_PORT_SERR_HE BIT22
181#define EFI_AHCI_PORT_SERR_LSE BIT23
182#define EFI_AHCI_PORT_SERR_TSTE BIT24
183#define EFI_AHCI_PORT_SERR_UFT BIT25
184#define EFI_AHCI_PORT_SERR_EX BIT26
185#define EFI_AHCI_PORT_ERR_CLEAR 0xFFFFFFFF
186#define EFI_AHCI_PORT_SACT 0x0034
187#define EFI_AHCI_PORT_CI 0x0038
188#define EFI_AHCI_PORT_SNTF 0x003C
189#define AHCI_PORT_DEVSLP 0x0044
190#define AHCI_PORT_DEVSLP_ADSE BIT0
191#define AHCI_PORT_DEVSLP_DSP BIT1
192#define AHCI_PORT_DEVSLP_DETO_MASK 0x000003FC
193#define AHCI_PORT_DEVSLP_MDAT_MASK 0x00007C00
194#define AHCI_PORT_DEVSLP_DITO_MASK 0x01FF8000
195#define AHCI_PORT_DEVSLP_DM_MASK 0x1E000000
196
197#define AHCI_COMMAND_RETRIES (PcdGet32 (PcdAhciCommandRetryCount))
198
199#pragma pack(1)
200//
201// Command List structure includes total 32 entries.
202// The entry data structure is listed at the following.
203//
204typedef struct {
205 UINT32 AhciCmdCfl : 5; // Command FIS Length
206 UINT32 AhciCmdA : 1; // ATAPI
207 UINT32 AhciCmdW : 1; // Write
208 UINT32 AhciCmdP : 1; // Prefetchable
209 UINT32 AhciCmdR : 1; // Reset
210 UINT32 AhciCmdB : 1; // BIST
211 UINT32 AhciCmdC : 1; // Clear Busy upon R_OK
212 UINT32 AhciCmdRsvd : 1;
213 UINT32 AhciCmdPmp : 4; // Port Multiplier Port
214 UINT32 AhciCmdPrdtl : 16; // Physical Region Descriptor Table Length
215 UINT32 AhciCmdPrdbc; // Physical Region Descriptor Byte Count
216 UINT32 AhciCmdCtba; // Command Table Descriptor Base Address
217 UINT32 AhciCmdCtbau; // Command Table Descriptor Base Address Upper 32-BITs
218 UINT32 AhciCmdRsvd1[4];
220
221//
222// This is a software constructed FIS.
223// For data transfer operations, this is the H2D Register FIS format as
224// specified in the Serial ATA Revision 2.6 specification.
225//
226typedef struct {
227 UINT8 AhciCFisType;
228 UINT8 AhciCFisPmNum : 4;
229 UINT8 AhciCFisRsvd : 1;
230 UINT8 AhciCFisRsvd1 : 1;
231 UINT8 AhciCFisRsvd2 : 1;
232 UINT8 AhciCFisCmdInd : 1;
233 UINT8 AhciCFisCmd;
234 UINT8 AhciCFisFeature;
235 UINT8 AhciCFisSecNum;
236 UINT8 AhciCFisClyLow;
237 UINT8 AhciCFisClyHigh;
238 UINT8 AhciCFisDevHead;
239 UINT8 AhciCFisSecNumExp;
240 UINT8 AhciCFisClyLowExp;
241 UINT8 AhciCFisClyHighExp;
242 UINT8 AhciCFisFeatureExp;
243 UINT8 AhciCFisSecCount;
244 UINT8 AhciCFisSecCountExp;
245 UINT8 AhciCFisRsvd3;
246 UINT8 AhciCFisControl;
247 UINT8 AhciCFisRsvd4[4];
248 UINT8 AhciCFisRsvd5[44];
250
251typedef enum {
252 SataFisD2H = 0,
253 SataFisPioSetup,
254 SataFisDmaSetup
255} SATA_FIS_TYPE;
256
257//
258// ACMD: ATAPI command (12 or 16 bytes)
259//
260typedef struct {
261 UINT8 AtapiCmd[0x10];
263
264//
265// Physical Region Descriptor Table includes up to 65535 entries
266// The entry data structure is listed at the following.
267// the actual entry number comes from the PRDTL field in the command
268// list entry for this command slot.
269//
270typedef struct {
271 UINT32 AhciPrdtDba; // Data Base Address
272 UINT32 AhciPrdtDbau; // Data Base Address Upper 32-BITs
273 UINT32 AhciPrdtRsvd;
274 UINT32 AhciPrdtDbc : 22; // Data Byte Count
275 UINT32 AhciPrdtRsvd1 : 9;
276 UINT32 AhciPrdtIoc : 1; // Interrupt on Completion
278
279//
280// Command table data structure which is pointed to by the entry in the command list
281//
282typedef struct {
283 EFI_AHCI_COMMAND_FIS CommandFis; // A software constructed FIS.
284 EFI_AHCI_ATAPI_COMMAND AtapiCmd; // 12 or 16 bytes ATAPI cmd.
285 UINT8 Reserved[0x30];
286 EFI_AHCI_COMMAND_PRDT PrdtTable[65535]; // The scatter/gather list for data transfer
288
289//
290// Received FIS structure
291//
292typedef struct {
293 UINT8 AhciDmaSetupFis[0x1C]; // Dma Setup Fis: offset 0x00
294 UINT8 AhciDmaSetupFisRsvd[0x04];
295 UINT8 AhciPioSetupFis[0x14]; // Pio Setup Fis: offset 0x20
296 UINT8 AhciPioSetupFisRsvd[0x0C];
297 UINT8 AhciD2HRegisterFis[0x14]; // D2H Register Fis: offset 0x40
298 UINT8 AhciD2HRegisterFisRsvd[0x04];
299 UINT64 AhciSetDeviceBitsFis; // Set Device Bits Fix: offset 0x58
300 UINT8 AhciUnknownFis[0x40]; // Unknown Fis: offset 0x60
301 UINT8 AhciUnknownFisRsvd[0x60];
303
304typedef struct {
305 UINT8 Madt : 5;
306 UINT8 Reserved_5 : 3;
307 UINT8 Deto;
308 UINT16 Reserved_16;
309 UINT32 Reserved_32 : 31;
310 UINT32 Supported : 1;
312
313#pragma pack()
314
315typedef struct {
316 EFI_AHCI_RECEIVED_FIS *AhciRFis;
317 EFI_AHCI_COMMAND_LIST *AhciCmdList;
318 EFI_AHCI_COMMAND_TABLE *AhciCommandTable;
319 EFI_AHCI_RECEIVED_FIS *AhciRFisPciAddr;
320 EFI_AHCI_COMMAND_LIST *AhciCmdListPciAddr;
321 EFI_AHCI_COMMAND_TABLE *AhciCommandTablePciAddr;
322 UINT64 MaxCommandListSize;
323 UINT64 MaxCommandTableSize;
324 UINT64 MaxReceiveFisSize;
325 VOID *MapRFis;
326 VOID *MapCmdList;
327 VOID *MapCommandTable;
329
346EFIAPI
348 IN EFI_PCI_IO_PROTOCOL *PciIo,
349 IN EFI_AHCI_REGISTERS *AhciRegisters,
350 IN UINT8 Port,
351 IN UINT8 PortMultiplier,
353 );
354
369EFIAPI
371 IN EFI_PCI_IO_PROTOCOL *PciIo,
372 IN UINT8 Port,
373 IN UINT8 CommandSlot,
374 IN UINT64 Timeout
375 );
376
390EFIAPI
392 IN EFI_PCI_IO_PROTOCOL *PciIo,
393 IN UINT8 Port,
394 IN UINT64 Timeout
395 );
396
397#endif
EFI_STATUS EFIAPI AhciPacketCommandExecute(IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_AHCI_REGISTERS *AhciRegisters, IN UINT8 Port, IN UINT8 PortMultiplier, IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet)
Definition: AhciMode.c:2126
EFI_STATUS EFIAPI AhciStopCommand(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Port, IN UINT64 Timeout)
Definition: AhciMode.c:1536
EFI_STATUS EFIAPI AhciStartCommand(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINT8 Port, IN UINT8 CommandSlot, IN UINT64 Timeout)
Definition: AhciMode.c:1580
#define IN
Definition: Base.h:279
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29