TianoCore EDK2 master
Loading...
Searching...
No Matches
AhciPei.h
Go to the documentation of this file.
1
11#ifndef _AHCI_PEI_H_
12#define _AHCI_PEI_H_
13
14#include <PiPei.h>
15
17
19#include <Ppi/IoMmu.h>
20#include <Ppi/EndOfPeiPhase.h>
21#include <Ppi/AtaPassThru.h>
22#include <Ppi/BlockIo.h>
23#include <Ppi/BlockIo2.h>
25
26#include <Library/DebugLib.h>
30#include <Library/IoLib.h>
31#include <Library/TimerLib.h>
33
34//
35// Structure forward declarations
36//
38
39#include "AhciPeiPassThru.h"
40#include "AhciPeiBlockIo.h"
42
43//
44// ATA AHCI driver implementation related definitions
45//
46//
47// Refer SATA1.0a spec section 5.2, the Phy detection time should be less than 10ms.
48// The value is in millisecond units. Add a bit of margin for robustness.
49//
50#define AHCI_BUS_PHY_DETECT_TIMEOUT 15
51//
52// Refer SATA1.0a spec, the bus reset time should be less than 1s.
53// The value is in 100ns units.
54//
55#define AHCI_PEI_RESET_TIMEOUT 10000000
56//
57// Time out Value for ATA pass through protocol, in 100ns units.
58//
59#define ATA_TIMEOUT 30000000
60//
61// Maximal number of Physical Region Descriptor Table entries supported.
62//
63#define AHCI_MAX_PRDT_NUMBER 8
64
65#define AHCI_CAPABILITY_OFFSET 0x0000
66#define AHCI_CAP_SAM BIT18
67#define AHCI_CAP_SSS BIT27
68
69#define AHCI_GHC_OFFSET 0x0004
70#define AHCI_GHC_RESET BIT0
71#define AHCI_GHC_ENABLE BIT31
72
73#define AHCI_IS_OFFSET 0x0008
74#define AHCI_PI_OFFSET 0x000C
75
76#define AHCI_MAX_PORTS 32
77
78typedef struct {
79 UINT32 Lower32;
80 UINT32 Upper32;
81} DATA_32;
82
83typedef union {
84 DATA_32 Uint32;
85 UINT64 Uint64;
86} DATA_64;
87
88#define AHCI_ATAPI_SIG_MASK 0xFFFF0000
89#define AHCI_ATA_DEVICE_SIG 0x00000000
90
91//
92// Each PRDT entry can point to a memory block up to 4M byte
93//
94#define AHCI_MAX_DATA_PER_PRDT 0x400000
95
96#define AHCI_FIS_REGISTER_H2D 0x27 // Register FIS - Host to Device
97#define AHCI_FIS_REGISTER_H2D_LENGTH 20
98#define AHCI_FIS_REGISTER_D2H 0x34 // Register FIS - Device to Host
99#define AHCI_FIS_PIO_SETUP 0x5F // PIO Setup FIS - Device to Host
100
101#define AHCI_D2H_FIS_OFFSET 0x40
102#define AHCI_PIO_FIS_OFFSET 0x20
103#define AHCI_FIS_TYPE_MASK 0xFF
104
105//
106// Port register
107//
108#define AHCI_PORT_START 0x0100
109#define AHCI_PORT_REG_WIDTH 0x0080
110#define AHCI_PORT_CLB 0x0000
111#define AHCI_PORT_CLBU 0x0004
112#define AHCI_PORT_FB 0x0008
113#define AHCI_PORT_FBU 0x000C
114#define AHCI_PORT_IS 0x0010
115#define AHCI_PORT_IE 0x0014
116#define AHCI_PORT_CMD 0x0018
117#define AHCI_PORT_CMD_ST BIT0
118#define AHCI_PORT_CMD_SUD BIT1
119#define AHCI_PORT_CMD_POD BIT2
120#define AHCI_PORT_CMD_CLO BIT3
121#define AHCI_PORT_CMD_FRE BIT4
122#define AHCI_PORT_CMD_FR BIT14
123#define AHCI_PORT_CMD_CR BIT15
124#define AHCI_PORT_CMD_CPD BIT20
125#define AHCI_PORT_CMD_ATAPI BIT24
126#define AHCI_PORT_CMD_DLAE BIT25
127#define AHCI_PORT_CMD_ALPE BIT26
128#define AHCI_PORT_CMD_ACTIVE (1 << 28)
129#define AHCI_PORT_CMD_ICC_MASK (BIT28 | BIT29 | BIT30 | BIT31)
130
131#define AHCI_PORT_TFD 0x0020
132#define AHCI_PORT_TFD_ERR BIT0
133#define AHCI_PORT_TFD_DRQ BIT3
134#define AHCI_PORT_TFD_BSY BIT7
135#define AHCI_PORT_TFD_MASK (BIT7 | BIT3 | BIT0)
136
137#define AHCI_PORT_SIG 0x0024
138#define AHCI_PORT_SSTS 0x0028
139#define AHCI_PORT_SSTS_DET_MASK 0x000F
140#define AHCI_PORT_SSTS_DET 0x0001
141#define AHCI_PORT_SSTS_DET_PCE 0x0003
142
143#define AHCI_PORT_SCTL 0x002C
144#define AHCI_PORT_SCTL_IPM_INIT 0x0300
145
146#define AHCI_PORT_SERR 0x0030
147#define AHCI_PORT_CI 0x0038
148
149#define TIMER_PERIOD_SECONDS(Seconds) MultU64x32((UINT64)(Seconds), 10000000)
150
151#pragma pack(1)
152
153//
154// Received FIS structure
155//
156typedef struct {
157 UINT8 AhciDmaSetupFis[0x1C]; // Dma Setup Fis: offset 0x00
158 UINT8 AhciDmaSetupFisRsvd[0x04];
159 UINT8 AhciPioSetupFis[0x14]; // Pio Setup Fis: offset 0x20
160 UINT8 AhciPioSetupFisRsvd[0x0C];
161 UINT8 AhciD2HRegisterFis[0x14]; // D2H Register Fis: offset 0x40
162 UINT8 AhciD2HRegisterFisRsvd[0x04];
163 UINT64 AhciSetDeviceBitsFis; // Set Device Bits Fix: offset 0x58
164 UINT8 AhciUnknownFis[0x40]; // Unknown Fis: offset 0x60
165 UINT8 AhciUnknownFisRsvd[0x60];
167
168//
169// Command List structure includes total 32 entries.
170// The entry Data structure is listed at the following.
171//
172typedef struct {
173 UINT32 AhciCmdCfl : 5; // Command FIS Length
174 UINT32 AhciCmdA : 1; // ATAPI
175 UINT32 AhciCmdW : 1; // Write
176 UINT32 AhciCmdP : 1; // Prefetchable
177 UINT32 AhciCmdR : 1; // Reset
178 UINT32 AhciCmdB : 1; // BIST
179 UINT32 AhciCmdC : 1; // Clear Busy upon R_OK
180 UINT32 AhciCmdRsvd : 1;
181 UINT32 AhciCmdPmp : 4; // Port Multiplier Port
182 UINT32 AhciCmdPrdtl : 16; // Physical Region Descriptor Table Length
183 UINT32 AhciCmdPrdbc; // Physical Region Descriptor Byte Count
184 UINT32 AhciCmdCtba; // Command Table Descriptor Base Address
185 UINT32 AhciCmdCtbau; // Command Table Descriptor Base Address Upper 32-BITs
186 UINT32 AhciCmdRsvd1[4];
188
189//
190// This is a software constructed FIS.
191// For Data transfer operations, this is the H2D Register FIS format as
192// specified in the Serial ATA Revision 2.6 specification.
193//
194typedef struct {
195 UINT8 AhciCFisType;
196 UINT8 AhciCFisPmNum : 4;
197 UINT8 AhciCFisRsvd : 1;
198 UINT8 AhciCFisRsvd1 : 1;
199 UINT8 AhciCFisRsvd2 : 1;
200 UINT8 AhciCFisCmdInd : 1;
201 UINT8 AhciCFisCmd;
202 UINT8 AhciCFisFeature;
203 UINT8 AhciCFisSecNum;
204 UINT8 AhciCFisClyLow;
205 UINT8 AhciCFisClyHigh;
206 UINT8 AhciCFisDevHead;
207 UINT8 AhciCFisSecNumExp;
208 UINT8 AhciCFisClyLowExp;
209 UINT8 AhciCFisClyHighExp;
210 UINT8 AhciCFisFeatureExp;
211 UINT8 AhciCFisSecCount;
212 UINT8 AhciCFisSecCountExp;
213 UINT8 AhciCFisRsvd3;
214 UINT8 AhciCFisControl;
215 UINT8 AhciCFisRsvd4[4];
216 UINT8 AhciCFisRsvd5[44];
218
219//
220// ACMD: ATAPI command (12 or 16 bytes)
221//
222typedef struct {
223 UINT8 AtapiCmd[0x10];
225
226//
227// Physical Region Descriptor Table includes up to 65535 entries
228// The entry data structure is listed at the following.
229// the actual entry number comes from the PRDTL field in the command
230// list entry for this command slot.
231//
232typedef struct {
233 UINT32 AhciPrdtDba; // Data Base Address
234 UINT32 AhciPrdtDbau; // Data Base Address Upper 32-BITs
235 UINT32 AhciPrdtRsvd;
236 UINT32 AhciPrdtDbc : 22; // Data Byte Count
237 UINT32 AhciPrdtRsvd1 : 9;
238 UINT32 AhciPrdtIoc : 1; // Interrupt on Completion
240
241//
242// Command table Data structure which is pointed to by the entry in the command list
243//
244typedef struct {
245 EFI_AHCI_COMMAND_FIS CommandFis; // A software constructed FIS.
246 EFI_AHCI_ATAPI_COMMAND AtapiCmd; // 12 or 16 bytes ATAPI cmd.
247 UINT8 Reserved[0x30];
248 //
249 // The scatter/gather list for Data transfer.
250 //
251 EFI_AHCI_COMMAND_PRDT PrdtTable[AHCI_MAX_PRDT_NUMBER];
253
254#pragma pack()
255
256typedef struct {
257 EFI_AHCI_RECEIVED_FIS *AhciRFis;
258 EFI_AHCI_COMMAND_LIST *AhciCmdList;
259 EFI_AHCI_COMMAND_TABLE *AhciCmdTable;
260 UINTN MaxRFisSize;
261 UINTN MaxCmdListSize;
262 UINTN MaxCmdTableSize;
263 VOID *AhciRFisMap;
264 VOID *AhciCmdListMap;
265 VOID *AhciCmdTableMap;
267
268//
269// Unique signature for AHCI ATA device information structure.
270//
271#define AHCI_PEI_ATA_DEVICE_DATA_SIGNATURE SIGNATURE_32 ('A', 'P', 'A', 'D')
272
273//
274// AHCI mode device information structure.
275//
276typedef struct {
277 UINT32 Signature;
278 LIST_ENTRY Link;
279
280 UINT16 Port;
281 UINT16 PortMultiplier;
282 UINT8 FisIndex;
283 UINTN DeviceIndex;
284 ATA_IDENTIFY_DATA *IdentifyData;
285
286 BOOLEAN Lba48Bit;
287 BOOLEAN TrustComputing;
288 UINTN TrustComputingDeviceIndex;
290
293
294#define AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS(a) \
295 CR (a, \
296 PEI_AHCI_ATA_DEVICE_DATA, \
297 Link, \
298 AHCI_PEI_ATA_DEVICE_DATA_SIGNATURE \
299 );
300
301//
302// Unique signature for private data structure.
303//
304#define AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('A','P','C','P')
305
306//
307// ATA AHCI controller private data structure.
308//
310 UINT32 Signature;
311 UINTN MmioBase;
312 UINTN DevicePathLength;
313 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
314
315 EFI_ATA_PASS_THRU_MODE AtaPassThruMode;
316 EDKII_PEI_ATA_PASS_THRU_PPI AtaPassThruPpi;
319 EDKII_PEI_STORAGE_SECURITY_CMD_PPI StorageSecurityPpi;
320 EFI_PEI_PPI_DESCRIPTOR AtaPassThruPpiList;
321 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;
322 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;
323 EFI_PEI_PPI_DESCRIPTOR StorageSecurityPpiList;
324 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;
325
326 EFI_AHCI_REGISTERS AhciRegisters;
327
328 UINT32 PortBitMap;
329 UINT32 ActiveDevices;
330 UINT32 TrustComputingDevices;
331 LIST_ENTRY DeviceList;
332
333 UINT16 PreviousPort;
334 UINT16 PreviousPortMultiplier;
335};
336
337#define GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_PASS_THRU(a) \
338 CR (a, PEI_AHCI_CONTROLLER_PRIVATE_DATA, AtaPassThruPpi, AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
339#define GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO(a) \
340 CR (a, PEI_AHCI_CONTROLLER_PRIVATE_DATA, BlkIoPpi, AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
341#define GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2(a) \
342 CR (a, PEI_AHCI_CONTROLLER_PRIVATE_DATA, BlkIo2Ppi, AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
343#define GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY(a) \
344 CR (a, PEI_AHCI_CONTROLLER_PRIVATE_DATA, StorageSecurityPpi, AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
345#define GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) \
346 CR (a, PEI_AHCI_CONTROLLER_PRIVATE_DATA, EndOfPeiNotifyList, AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE)
347
348//
349// Global variables
350//
351extern UINT32 mMaxTransferBlockNumber[2];
352
353//
354// Internal functions
355//
356
370EFIAPI
372 IN EFI_PEI_SERVICES **PeiServices,
373 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
374 IN VOID *Ppi
375 );
376
390EFIAPI
392 IN EFI_PEI_SERVICES **PeiServices,
393 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
394 IN VOID *Ppi
395 );
396
417 IN UINTN Pages,
418 OUT VOID **HostAddress,
419 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
420 OUT VOID **Mapping
421 );
422
437 IN UINTN Pages,
438 IN VOID *HostAddress,
439 IN VOID *Mapping
440 );
441
462IoMmuMap (
463 IN EDKII_IOMMU_OPERATION Operation,
464 IN VOID *HostAddress,
465 IN OUT UINTN *NumberOfBytes,
466 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
467 OUT VOID **Mapping
468 );
469
481 IN VOID *Mapping
482 );
483
496EFIAPI
498 IN EFI_PEI_SERVICES **PeiServices,
499 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
500 IN VOID *Ppi
501 );
502
511UINT8
513 IN UINT32 PortBitMap
514 );
515
541 IN UINT8 Port,
542 IN UINT8 PortMultiplier,
543 IN UINT8 FisIndex,
544 IN BOOLEAN Read,
545 IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock,
546 IN OUT EFI_ATA_STATUS_BLOCK *AtaStatusBlock,
547 IN OUT VOID *MemoryAddr,
548 IN UINT32 DataCount,
549 IN UINT64 Timeout
550 );
551
573 IN UINT8 Port,
574 IN UINT8 PortMultiplier,
575 IN UINT8 FisIndex,
576 IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock,
577 IN OUT EFI_ATA_STATUS_BLOCK *AtaStatusBlock,
578 IN UINT64 Timeout
579 );
580
598 );
599
619 IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData,
620 IN OUT VOID *Buffer,
621 IN EFI_LBA StartLba,
622 IN UINT32 TransferLength,
623 IN BOOLEAN IsWrite
624 );
625
664 IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData,
665 IN OUT VOID *Buffer,
666 IN UINT8 SecurityProtocolId,
667 IN UINT16 SecurityProtocolSpecificData,
668 IN UINTN TransferLength,
669 IN BOOLEAN IsTrustSend,
670 IN UINT64 Timeout,
671 OUT UINTN *TransferLengthOut
672 );
673
689 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
690 OUT UINTN *InstanceSize,
691 OUT BOOLEAN *EntireDevicePathEnd
692 );
693
707 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
708 IN UINTN DevicePathLength
709 );
710
730 IN UINT16 Port,
731 IN UINT16 PortMultiplierPort,
732 OUT UINTN *DevicePathLength,
733 OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
734 );
735
748UINT8
750 IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath,
751 IN UINTN HcDevicePathLength,
752 OUT UINT32 *PortBitMap
753 );
754
755#endif
UINT64 UINTN
UINT8 AhciS3GetEumeratePorts(IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath, IN UINTN HcDevicePathLength, OUT UINT32 *PortBitMap)
Definition: AhciPeiS3.c:30
UINT8 AhciGetNumberOfPortsFromMap(IN UINT32 PortBitMap)
Definition: AhciMode.c:1190
EFI_STATUS AhciModeInitialization(IN OUT PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private)
Definition: AhciMode.c:1664
EFI_STATUS AhciNonDataTransfer(IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private, IN UINT8 Port, IN UINT8 PortMultiplier, IN UINT8 FisIndex, IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock, IN OUT EFI_ATA_STATUS_BLOCK *AtaStatusBlock, IN UINT64 Timeout)
Definition: AhciMode.c:981
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
Definition: DmaMem.c:132
EFI_STATUS AhciBuildDevicePath(IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private, IN UINT16 Port, IN UINT16 PortMultiplierPort, OUT UINTN *DevicePathLength, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
Definition: DevicePath.c:177
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
Definition: DmaMem.c:170
EFI_STATUS TrustTransferAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT VOID *Buffer, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN TransferLength, IN BOOLEAN IsTrustSend, IN UINT64 Timeout, OUT UINTN *TransferLengthOut)
Definition: AhciMode.c:2063
EFI_STATUS IoMmuMap(IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
Definition: DmaMem.c:60
EFI_STATUS EFIAPI AhciPeimEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: AhciPei.c:114
EFI_STATUS GetDevicePathInstanceSize(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINTN *InstanceSize, OUT BOOLEAN *EntireDevicePathEnd)
Definition: DevicePath.c:55
EFI_STATUS AhciPioTransfer(IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private, IN UINT8 Port, IN UINT8 PortMultiplier, IN UINT8 FisIndex, IN BOOLEAN Read, IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock, IN OUT EFI_ATA_STATUS_BLOCK *AtaStatusBlock, IN OUT VOID *MemoryAddr, IN UINT32 DataCount, IN UINT64 Timeout)
Definition: AhciMode.c:717
EFI_STATUS EFIAPI AtaAhciPciDevicePpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: AhciPei.c:496
EFI_STATUS EFIAPI AtaAhciHostControllerPpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: AhciPei.c:376
EFI_STATUS IoMmuFreeBuffer(IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
Definition: DmaMem.c:251
EFI_STATUS AhciIsHcDevicePathValid(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN DevicePathLength)
Definition: DevicePath.c:106
EFI_STATUS TransferAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT VOID *Buffer, IN EFI_LBA StartLba, IN UINT32 TransferLength, IN BOOLEAN IsWrite)
Definition: AhciMode.c:1924
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EDKII_IOMMU_OPERATION
Definition: IoMmu.h:44
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29