50#define AHCI_BUS_PHY_DETECT_TIMEOUT 15
55#define AHCI_PEI_RESET_TIMEOUT 10000000
59#define ATA_TIMEOUT 30000000
63#define AHCI_MAX_PRDT_NUMBER 8
65#define AHCI_CAPABILITY_OFFSET 0x0000
66#define AHCI_CAP_SAM BIT18
67#define AHCI_CAP_SSS BIT27
69#define AHCI_GHC_OFFSET 0x0004
70#define AHCI_GHC_RESET BIT0
71#define AHCI_GHC_ENABLE BIT31
73#define AHCI_IS_OFFSET 0x0008
74#define AHCI_PI_OFFSET 0x000C
76#define AHCI_MAX_PORTS 32
88#define AHCI_ATAPI_SIG_MASK 0xFFFF0000
89#define AHCI_ATA_DEVICE_SIG 0x00000000
94#define AHCI_MAX_DATA_PER_PRDT 0x400000
96#define AHCI_FIS_REGISTER_H2D 0x27
97#define AHCI_FIS_REGISTER_H2D_LENGTH 20
98#define AHCI_FIS_REGISTER_D2H 0x34
99#define AHCI_FIS_PIO_SETUP 0x5F
101#define AHCI_D2H_FIS_OFFSET 0x40
102#define AHCI_PIO_FIS_OFFSET 0x20
103#define AHCI_FIS_TYPE_MASK 0xFF
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)
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)
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
143#define AHCI_PORT_SCTL 0x002C
144#define AHCI_PORT_SCTL_IPM_INIT 0x0300
146#define AHCI_PORT_SERR 0x0030
147#define AHCI_PORT_CI 0x0038
149#define TIMER_PERIOD_SECONDS(Seconds) MultU64x32((UINT64)(Seconds), 10000000)
157 UINT8 AhciDmaSetupFis[0x1C];
158 UINT8 AhciDmaSetupFisRsvd[0x04];
159 UINT8 AhciPioSetupFis[0x14];
160 UINT8 AhciPioSetupFisRsvd[0x0C];
161 UINT8 AhciD2HRegisterFis[0x14];
162 UINT8 AhciD2HRegisterFisRsvd[0x04];
163 UINT64 AhciSetDeviceBitsFis;
164 UINT8 AhciUnknownFis[0x40];
165 UINT8 AhciUnknownFisRsvd[0x60];
173 UINT32 AhciCmdCfl : 5;
180 UINT32 AhciCmdRsvd : 1;
181 UINT32 AhciCmdPmp : 4;
182 UINT32 AhciCmdPrdtl : 16;
186 UINT32 AhciCmdRsvd1[4];
196 UINT8 AhciCFisPmNum : 4;
197 UINT8 AhciCFisRsvd : 1;
198 UINT8 AhciCFisRsvd1 : 1;
199 UINT8 AhciCFisRsvd2 : 1;
200 UINT8 AhciCFisCmdInd : 1;
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;
214 UINT8 AhciCFisControl;
215 UINT8 AhciCFisRsvd4[4];
216 UINT8 AhciCFisRsvd5[44];
223 UINT8 AtapiCmd[0x10];
236 UINT32 AhciPrdtDbc : 22;
237 UINT32 AhciPrdtRsvd1 : 9;
238 UINT32 AhciPrdtIoc : 1;
247 UINT8 Reserved[0x30];
261 UINTN MaxCmdListSize;
262 UINTN MaxCmdTableSize;
264 VOID *AhciCmdListMap;
265 VOID *AhciCmdTableMap;
271#define AHCI_PEI_ATA_DEVICE_DATA_SIGNATURE SIGNATURE_32 ('A', 'P', 'A', 'D')
281 UINT16 PortMultiplier;
287 BOOLEAN TrustComputing;
288 UINTN TrustComputingDeviceIndex;
294#define AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS(a) \
296 PEI_AHCI_ATA_DEVICE_DATA, \
298 AHCI_PEI_ATA_DEVICE_DATA_SIGNATURE \
304#define AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('A','P','C','P')
312 UINTN DevicePathLength;
329 UINT32 ActiveDevices;
330 UINT32 TrustComputingDevices;
334 UINT16 PreviousPortMultiplier;
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)
351extern UINT32 mMaxTransferBlockNumber[2];
418 OUT VOID **HostAddress,
438 IN VOID *HostAddress,
464 IN VOID *HostAddress,
542 IN UINT8 PortMultiplier,
547 IN OUT VOID *MemoryAddr,
574 IN UINT8 PortMultiplier,
622 IN UINT32 TransferLength,
666 IN UINT8 SecurityProtocolId,
667 IN UINT16 SecurityProtocolSpecificData,
669 IN BOOLEAN IsTrustSend,
691 OUT BOOLEAN *EntireDevicePathEnd
731 IN UINT16 PortMultiplierPort,
752 OUT UINT32 *PortBitMap
UINT8 AhciS3GetEumeratePorts(IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath, IN UINTN HcDevicePathLength, OUT UINT32 *PortBitMap)
UINT8 AhciGetNumberOfPortsFromMap(IN UINT32 PortBitMap)
EFI_STATUS AhciModeInitialization(IN OUT PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private)
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)
EFI_STATUS IoMmuUnmap(IN VOID *Mapping)
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)
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
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)
EFI_STATUS IoMmuMap(IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
EFI_STATUS EFIAPI AhciPeimEndOfPei(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS GetDevicePathInstanceSize(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINTN *InstanceSize, OUT BOOLEAN *EntireDevicePathEnd)
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)
EFI_STATUS EFIAPI AtaAhciPciDevicePpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI AtaAhciHostControllerPpiInstallationCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS IoMmuFreeBuffer(IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
EFI_STATUS AhciIsHcDevicePathValid(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN DevicePathLength)
EFI_STATUS TransferAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT VOID *Buffer, IN EFI_LBA StartLba, IN UINT32 TransferLength, IN BOOLEAN IsWrite)
UINT64 EFI_PHYSICAL_ADDRESS