38 if (!EFI_ERROR (Status)) {
43 &gPeiAtaControllerPpiGuid,
46 (VOID **)&AtaControllerPpi
51 if (AtapiBlkIoDev ==
NULL) {
52 return EFI_OUT_OF_RESOURCES;
55 AtapiBlkIoDev->Signature = ATAPI_BLK_IO_DEV_SIGNATURE;
56 AtapiBlkIoDev->AtaControllerPpi = AtaControllerPpi;
66 AtapiBlkIoDev->AtapiBlkIo2.
Revision = EFI_PEI_RECOVERY_BLOCK_IO2_PPI_REVISION;
71 AtapiBlkIoDev->PpiDescriptor.
Flags = EFI_PEI_PPI_DESCRIPTOR_PPI;
72 AtapiBlkIoDev->PpiDescriptor.
Guid = &gEfiPeiVirtualBlockIoPpiGuid;
73 AtapiBlkIoDev->PpiDescriptor.
Ppi = &AtapiBlkIoDev->AtapiBlkIo;
75 AtapiBlkIoDev->PpiDescriptor2.
Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
76 AtapiBlkIoDev->PpiDescriptor2.
Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
77 AtapiBlkIoDev->PpiDescriptor2.
Ppi = &AtapiBlkIoDev->AtapiBlkIo2;
79 DEBUG ((DEBUG_INFO,
"Atatpi Device Count is %d\n", AtapiBlkIoDev->DeviceCount));
80 if (AtapiBlkIoDev->DeviceCount != 0) {
82 if (EFI_ERROR (Status)) {
83 return EFI_OUT_OF_RESOURCES;
119 AtapiBlkIoDev =
NULL;
121 AtapiBlkIoDev = PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS (This);
123 *NumberBlockDevices = AtapiBlkIoDev->DeviceCount;
170 AtapiBlkIoDev =
NULL;
172 if ((This ==
NULL) || (MediaInfo ==
NULL)) {
173 return EFI_INVALID_PARAMETER;
176 AtapiBlkIoDev = PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS (This);
178 DeviceCount = AtapiBlkIoDev->DeviceCount;
183 if ((DeviceIndex < 1) || (DeviceIndex > DeviceCount) || (DeviceIndex > MAX_IDE_DEVICES)) {
184 return EFI_INVALID_PARAMETER;
187 Index = DeviceIndex - 1;
192 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo DevicePosition is %d\n", AtapiBlkIoDev->DeviceInfo[Index].DevicePosition));
193 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo DeviceType is %d\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
DeviceType));
194 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo MediaPresent is %d\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
MediaPresent));
195 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo BlockSize is 0x%x\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
BlockSize));
196 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo LastBlock is 0x%x\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
LastBlock));
200 AtapiBlkIoDev->DeviceInfo[Index].DevicePosition,
201 &AtapiBlkIoDev->DeviceInfo[Index].MediaInfo,
202 &AtapiBlkIoDev->DeviceInfo[Index].MediaInfo2
205 return EFI_DEVICE_ERROR;
208 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo DevicePosition is %d\n", AtapiBlkIoDev->DeviceInfo[Index].DevicePosition));
209 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo DeviceType is %d\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
DeviceType));
210 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo MediaPresent is %d\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
MediaPresent));
211 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo BlockSize is 0x%x\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
BlockSize));
212 DEBUG ((DEBUG_INFO,
"Atatpi GetInfo LastBlock is 0x%x\n", AtapiBlkIoDev->DeviceInfo[Index].MediaInfo.
LastBlock));
269 UINTN NumberOfBlocks;
273 AtapiBlkIoDev =
NULL;
276 return EFI_INVALID_PARAMETER;
279 AtapiBlkIoDev = PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS (This);
281 if (Buffer ==
NULL) {
282 return EFI_INVALID_PARAMETER;
285 if (BufferSize == 0) {
296 return EFI_DEVICE_ERROR;
305 if (BufferSize % BlockSize != 0) {
306 return EFI_BAD_BUFFER_SIZE;
309 NumberOfBlocks = BufferSize / BlockSize;
311 if ((StartLBA + NumberOfBlocks - 1) > AtapiBlkIoDev->DeviceInfo[DeviceIndex - 1].MediaInfo2.
LastBlock) {
312 return EFI_INVALID_PARAMETER;
317 AtapiBlkIoDev->DeviceInfo[DeviceIndex - 1].DevicePosition,
323 if (EFI_ERROR (Status)) {
324 return EFI_DEVICE_ERROR;
360 AtapiBlkIoDev = PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS (This);
364 &AtapiBlkIoDev->AtapiBlkIo,
412 AtapiBlkIoDev =
NULL;
414 if ((This ==
NULL) || (MediaInfo ==
NULL)) {
415 return EFI_INVALID_PARAMETER;
418 AtapiBlkIoDev = PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS (This);
422 &AtapiBlkIoDev->AtapiBlkIo,
426 if (EFI_ERROR (Status)) {
486 AtapiBlkIoDev =
NULL;
489 return EFI_INVALID_PARAMETER;
492 AtapiBlkIoDev = PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS (This);
496 &AtapiBlkIoDev->AtapiBlkIo,
521 UINTN DevicePosition;
526 UINT16 CommandBlockBaseAddr;
527 UINT16 ControlBlockBaseAddr;
528 UINT32 IdeEnabledNumber;
541 AtapiBlkIoDev->AtaControllerPpi->EnableAtaChannel (
543 AtapiBlkIoDev->AtaControllerPpi,
551 DEBUG ((DEBUG_INFO,
"Delay for %d seconds for SATA devices to spin-up\n",
PcdGet16 (PcdSataSpinUpDelayInSecForRecoveryPath)));
557 IdeEnabledNumber = AtapiBlkIoDev->AtaControllerPpi->GetIdeRegsBaseAddr (
559 AtapiBlkIoDev->AtaControllerPpi,
566 for (Index1 = 0; Index1 < IdeEnabledNumber; Index1++) {
568 AtapiBlkIoDev->IdeIoPortReg[Index1].Data = CommandBlockBaseAddr;
569 AtapiBlkIoDev->IdeIoPortReg[Index1].Reg1.Feature = (UINT16)(CommandBlockBaseAddr + 0x1);
570 AtapiBlkIoDev->IdeIoPortReg[Index1].SectorCount = (UINT16)(CommandBlockBaseAddr + 0x2);
571 AtapiBlkIoDev->IdeIoPortReg[Index1].SectorNumber = (UINT16)(CommandBlockBaseAddr + 0x3);
572 AtapiBlkIoDev->IdeIoPortReg[Index1].CylinderLsb = (UINT16)(CommandBlockBaseAddr + 0x4);
573 AtapiBlkIoDev->IdeIoPortReg[Index1].CylinderMsb = (UINT16)(CommandBlockBaseAddr + 0x5);
574 AtapiBlkIoDev->IdeIoPortReg[Index1].Head = (UINT16)(CommandBlockBaseAddr + 0x6);
575 AtapiBlkIoDev->IdeIoPortReg[Index1].Reg.Command = (UINT16)(CommandBlockBaseAddr + 0x7);
578 AtapiBlkIoDev->IdeIoPortReg[Index1].Alt.DeviceControl = ControlBlockBaseAddr;
579 AtapiBlkIoDev->IdeIoPortReg[Index1].DriveAddress = (UINT16)(ControlBlockBaseAddr + 0x1);
584 for (Index2 = IdeMaster; Index2 < IdeMaxDevice; Index2++) {
588 DevicePosition = Index1 * 2 + Index2;
594 AtapiBlkIoDev->DeviceInfo[DeviceCount].DevicePosition = DevicePosition;
598 Status =
DetectMedia (AtapiBlkIoDev, DevicePosition, &MediaInfo, &MediaInfo2);
599 CopyMem (&(AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo), &MediaInfo, sizeof (MediaInfo));
600 CopyMem (&(AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2), &MediaInfo2, sizeof (MediaInfo2));
602 DEBUG ((DEBUG_INFO,
"Atatpi Device Position is %d\n", DevicePosition));
603 DEBUG ((DEBUG_INFO,
"Atatpi DeviceType is %d\n", MediaInfo.
DeviceType));
605 DEBUG ((DEBUG_INFO,
"Atatpi BlockSize is 0x%x\n", MediaInfo.
BlockSize));
607 if (EFI_ERROR (Status)) {
608 AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo.MediaPresent =
FALSE;
609 AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo.LastBlock = 0;
610 AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2.MediaPresent =
FALSE;
611 AtapiBlkIoDev->DeviceInfo[DeviceCount].MediaInfo2.LastBlock = 0;
619 AtapiBlkIoDev->DeviceCount = DeviceCount;
652 Status =
Inquiry (AtapiBlkIoDev, DevicePosition, MediaInfo, MediaInfo2);
653 if (!EFI_ERROR (Status)) {
683 UINT16 StatusRegister;
685 UINT16 CommandRegister;
686 UINT16 ErrorRegister;
687 UINT16 SectorCountRegister;
691 UINT8 SectorCountValue;
693 Channel = (UINT8)(DevicePosition / 2);
694 Device = (UINT8)(DevicePosition % 2);
696 ASSERT (Channel < MAX_IDE_CHANNELS);
698 StatusRegister = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Status;
699 HeadRegister = AtapiBlkIoDev->IdeIoPortReg[Channel].Head;
700 CommandRegister = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Command;
701 ErrorRegister = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg1.Error;
702 SectorCountRegister = AtapiBlkIoDev->IdeIoPortReg[Channel].SectorCount;
707 IoWrite8 (HeadRegister, (UINT8)((Device << 4) | 0xe0));
712 SectorCountValue = 0x55;
713 IoWrite8 (SectorCountRegister, SectorCountValue);
718 IoWrite8 (HeadRegister, (UINT8)((Device << 4) | 0xe0));
720 Status =
DRDYReady (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 100);
725 IoWrite8 (HeadRegister, (UINT8)((Device << 4) | 0xe0));
729 IoWrite8 (CommandRegister, AtaCommand);
731 Status =
WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 3000);
732 if (EFI_ERROR (Status)) {
736 StatusValue =
IoRead8 (StatusRegister);
746 SectorCountValue =
IoRead8 (SectorCountRegister);
753 ErrorValue =
IoRead8 (ErrorRegister);
760 return EFI_NOT_FOUND;
764 if ((SectorCountValue == 0x00) || (SectorCountValue == 0x80) || (SectorCountValue == 0xff)) {
769 IoWrite8 (HeadRegister, (UINT8)((Device << 4) | 0xe0));
776 SectorCountValue = 0x55;
777 IoWrite8 (SectorCountRegister, SectorCountValue);
780 SectorCountValue =
IoRead8 (SectorCountRegister);
781 if (SectorCountValue != 0x55) {
782 return EFI_NOT_FOUND;
792 return EFI_NOT_FOUND;
815 Channel = (UINT8)(DevicePosition / 2);
817 ASSERT (Channel < MAX_IDE_CHANNELS);
821 Status =
WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000);
822 if (EFI_ERROR (Status)) {
830 Status =
CheckPowerMode (AtapiBlkIoDev, DevicePosition, AtaCommand);
831 if ((Status == EFI_ABORTED) || (Status ==
EFI_SUCCESS)) {
857 UINT16 StatusRegister;
862 StatusRegister = IdeIoRegisters->Reg.Status;
864 Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
866 StatusValue =
IoRead8 (StatusRegister);
874 }
while (Delay != 0);
902 UINT16 StatusRegister;
908 StatusRegister = IdeIoRegisters->Reg.Status;
910 Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
912 StatusValue =
IoRead8 (StatusRegister);
921 ErrValue =
IoRead8 (IdeIoRegisters->Reg1.Error);
930 }
while (Delay != 0);
958 UINT16 StatusRegister;
964 StatusRegister = IdeIoRegisters->Reg.Status;
966 Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
968 StatusValue =
IoRead8 (StatusRegister);
978 ErrValue =
IoRead8 (IdeIoRegisters->Reg1.Error);
987 }
while (Delay != 0);
1011 IN UINTN TimeoutInMilliSeconds
1015 UINT16 AltStatusRegister;
1016 UINT8 AltStatusValue;
1021 AltStatusRegister = IdeIoRegisters->Alt.AltStatus;
1023 Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
1025 AltStatusValue =
IoRead8 (AltStatusRegister);
1035 ErrValue =
IoRead8 (IdeIoRegisters->Reg1.Error);
1044 }
while (Delay != 0);
1069 IN UINTN TimeoutInMilliSeconds
1073 UINT16 StatusRegister;
1080 StatusRegister = IdeIoRegisters->Reg.Status;
1082 Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
1087 StatusValue =
IoRead8 (StatusRegister);
1097 ErrValue =
IoRead8 (IdeIoRegisters->Reg1.Error);
1106 }
while (Delay != 0);
1131 IN UINTN TimeoutInMilliSeconds
1135 UINT16 AltStatusRegister;
1136 UINT8 AltStatusValue;
1141 AltStatusRegister = IdeIoRegisters->Alt.AltStatus;
1143 Delay = ((TimeoutInMilliSeconds * STALL_1_MILLI_SECOND) / 250) + 1;
1145 AltStatusValue =
IoRead8 (AltStatusRegister);
1155 ErrValue =
IoRead8 (IdeIoRegisters->Reg1.Error);
1164 }
while (Delay != 0);
1191 StatusValue =
IoRead8 (StatusReg);
1197 return EFI_DEVICE_ERROR;
1223 UINT16 SectorCountReg;
1224 UINT16 SectorNumberReg;
1225 UINT16 CylinderLsbReg;
1226 UINT16 CylinderMsbReg;
1236 ByteCount =
sizeof (AtapiIdentifyData);
1237 Buffer16 = (UINT16 *)&AtapiIdentifyData;
1239 Channel = (UINT8)(DevicePosition / 2);
1240 Device = (UINT8)(DevicePosition % 2);
1242 ASSERT (Channel < MAX_IDE_CHANNELS);
1244 StatusReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Status;
1245 HeadReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Head;
1246 CommandReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Command;
1247 DataReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Data;
1248 SectorCountReg = AtapiBlkIoDev->IdeIoPortReg[Channel].SectorCount;
1249 SectorNumberReg = AtapiBlkIoDev->IdeIoPortReg[Channel].SectorNumber;
1250 CylinderLsbReg = AtapiBlkIoDev->IdeIoPortReg[Channel].CylinderLsb;
1251 CylinderMsbReg = AtapiBlkIoDev->IdeIoPortReg[Channel].CylinderMsb;
1258 &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
1262 return EFI_DEVICE_ERROR;
1269 if (
DRQClear2 (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), ATATIMEOUT) !=
EFI_SUCCESS) {
1270 return EFI_DEVICE_ERROR;
1277 IoWrite8 (HeadReg, (UINT8)((Device << 4) | 0xe0));
1285 &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
1289 return EFI_DEVICE_ERROR;
1322 while (WordCount < ByteCount / 2) {
1326 Status =
DRQReady2 (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), ATATIMEOUT);
1332 return EFI_DEVICE_ERROR;
1338 if ((WordCount + Increment) > ByteCount / 2) {
1339 Increment = ByteCount / 2 - WordCount;
1345 for (Index = 0; Index < Increment; Index++) {
1349 WordCount += Increment;
1357 &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
1420 IN UINT32 ByteCount,
1421 IN UINTN TimeoutInMilliSeconds
1430 UINT16 CylinderLsbReg;
1431 UINT16 CylinderMsbReg;
1432 UINT16 DeviceControlReg;
1436 UINT16 *CommandIndex;
1445 UINT32 RequiredWordCount;
1450 UINT32 ActualWordCount;
1452 Channel = (UINT8)(DevicePosition / 2);
1453 Device = (UINT8)(DevicePosition % 2);
1455 ASSERT (Channel < MAX_IDE_CHANNELS);
1457 StatusReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Status;
1458 HeadReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Head;
1459 CommandReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Command;
1460 FeatureReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg1.Feature;
1461 CylinderLsbReg = AtapiBlkIoDev->IdeIoPortReg[Channel].CylinderLsb;
1462 CylinderMsbReg = AtapiBlkIoDev->IdeIoPortReg[Channel].CylinderMsb;
1463 DeviceControlReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Alt.DeviceControl;
1464 DataReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Data;
1472 &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
1476 return EFI_DEVICE_ERROR;
1494 IoWrite8 (CylinderLsbReg, (UINT8)(ATAPI_MAX_BYTE_COUNT & 0x00ff));
1495 IoWrite8 (CylinderMsbReg, (UINT8)(ATAPI_MAX_BYTE_COUNT >> 8));
1509 Status =
DRQReady (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), TimeoutInMilliSeconds);
1517 CommandIndex = Packet->Data16;
1518 for (Count = 0; Count < 6; Count++, CommandIndex++) {
1523 StatusValue =
IoRead8 (StatusReg);
1530 return EFI_DEVICE_ERROR;
1533 if ((Buffer ==
NULL) || (ByteCount == 0)) {
1542 RequiredWordCount = ByteCount / 2;
1546 ActualWordCount = 0;
1549 while ((Status ==
EFI_SUCCESS) && (ActualWordCount < RequiredWordCount)) {
1556 &(AtapiBlkIoDev->IdeIoPortReg[Channel]),
1557 TimeoutInMilliSeconds
1566 StatusValue =
IoRead8 (StatusReg);
1571 WordCount =
IoRead8 (CylinderMsbReg) << 8;
1572 WordCount = WordCount |
IoRead8 (CylinderLsbReg);
1573 WordCount = WordCount & 0xffff;
1579 for (Index = 0; (Index < WordCount) && (ActualWordCount < RequiredWordCount); Index++, ActualWordCount++) {
1586 RequiredWordCount =
MIN (
1596 Status =
DRQClear2 (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), TimeoutInMilliSeconds);
1598 return EFI_DEVICE_ERROR;
1658 return EFI_DEVICE_ERROR;
1664 switch (Idata.peripheral_type & 0x1f) {
1670 MediaInfo->MediaPresent =
FALSE;
1671 MediaInfo->LastBlock = 0;
1672 MediaInfo->BlockSize = 0x200;
1674 MediaInfo2->RemovableMedia =
TRUE;
1675 MediaInfo2->MediaPresent =
FALSE;
1676 MediaInfo2->ReadOnly =
FALSE;
1677 MediaInfo2->BlockSize = 0x200;
1678 MediaInfo2->LastBlock = 0;
1686 MediaInfo->MediaPresent =
FALSE;
1687 MediaInfo->LastBlock = 0;
1688 MediaInfo->BlockSize = 0x800;
1690 MediaInfo2->RemovableMedia =
TRUE;
1691 MediaInfo2->MediaPresent =
FALSE;
1692 MediaInfo2->ReadOnly =
TRUE;
1693 MediaInfo2->BlockSize = 0x200;
1694 MediaInfo2->LastBlock = 0;
1698 return EFI_UNSUPPORTED;
1731 BOOLEAN NeedReadCapacity;
1737 if (SenseBuffers ==
NULL) {
1738 return EFI_OUT_OF_RESOURCES;
1745 for (Index = 0; Index < 2; Index++) {
1758 SenseCounts = MAX_SENSE_KEY_COUNT;
1760 NeedReadCapacity =
TRUE;
1762 for (Index = 0; Index < 5; Index++) {
1763 SenseCounts = MAX_SENSE_KEY_COUNT;
1770 DEBUG ((DEBUG_INFO,
"Atapi Request Sense Count is %d\n", SenseCounts));
1782 if (
IsNoMedia (SenseBuffers, SenseCounts)) {
1783 NeedReadCapacity =
FALSE;
1784 MediaInfo->MediaPresent =
FALSE;
1785 MediaInfo->LastBlock = 0;
1786 MediaInfo2->MediaPresent =
FALSE;
1787 MediaInfo2->LastBlock = 0;
1791 return EFI_DEVICE_ERROR;
1795 if (NeedReadCapacity) {
1804 for (Index = 0; (Index < RetryNum) && (Index < MaxRetryNum); Index++) {
1805 Status =
ReadCapacity (AtapiBlkIoDev, DevicePosition, MediaInfo, MediaInfo2);
1807 SenseCounts = MAX_SENSE_KEY_COUNT;
1810 Status =
RequestSense (AtapiBlkIoDev, DevicePosition, SenseBuffers, &SenseCounts);
1834 if (
IsNoMedia (SenseBuffers, SenseCounts)) {
1835 MediaInfo->MediaPresent =
FALSE;
1836 MediaInfo->LastBlock = 0;
1837 MediaInfo2->MediaPresent =
FALSE;
1838 MediaInfo2->LastBlock = 0;
1843 return EFI_DEVICE_ERROR;
1846 if (!
IsDriveReady (SenseBuffers, SenseCounts, &NeedRetry)) {
1855 return EFI_DEVICE_ERROR;
1885 IN BOOLEAN Extensive
1891 UINT16 DeviceControlReg;
1897 Channel = (UINT8)(DevicePosition / 2);
1898 Device = (UINT8)(DevicePosition % 2);
1900 ASSERT (Channel < MAX_IDE_CHANNELS);
1902 DeviceControlReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Alt.DeviceControl;
1903 CommandReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Reg.Command;
1904 HeadReg = AtapiBlkIoDev->IdeIoPortReg[Channel].Head;
1916 IoWrite8 (DeviceControlReg, DevControl);
1930 IoWrite8 (DeviceControlReg, DevControl);
1935 if (
WaitForBSYClear (AtapiBlkIoDev, &(AtapiBlkIoDev->IdeIoPortReg[Channel]), 31000) == EFI_TIMEOUT) {
1936 return EFI_DEVICE_ERROR;
1943 DeviceSelect = (UINT8)(((BIT7 | BIT5) | (Device << 4)));
1954 return EFI_DEVICE_ERROR;
1983 IN OUT UINT8 *SenseCounts
2000 Ptr = (UINT16 *)SenseBuffers;
2008 for (SenseReq =
TRUE; SenseReq;) {
2026 if (*SenseCounts == 0) {
2027 return EFI_DEVICE_ERROR;
2035 if (*SenseCounts > MAX_SENSE_KEY_COUNT) {
2045 if ((Sense->sense_key != ATA_SK_NO_SENSE) && ((*SenseCounts) < 20)) {
2092 ZeroMem (&Data,
sizeof (Data));
2093 ZeroMem (&FormatData,
sizeof (FormatData));
2095 if (MediaInfo->DeviceType ==
IdeCDROM) {
2112 Packet.ReadFormatCapacity.allocation_length_lo = 12;
2117 (UINT16 *)(&FormatData),
2124 if (MediaInfo->DeviceType ==
IdeCDROM) {
2125 MediaInfo->LastBlock = ((UINT32)Data.LastLba3 << 24) | (Data.LastLba2 << 16) | (Data.LastLba1 << 8) | Data.LastLba0;
2126 MediaInfo->MediaPresent =
TRUE;
2131 MediaInfo->BlockSize = 0x800;
2133 MediaInfo2->LastBlock = MediaInfo->LastBlock;
2134 MediaInfo2->MediaPresent = MediaInfo->MediaPresent;
2135 MediaInfo2->BlockSize = (UINT32)MediaInfo->BlockSize;
2138 if (MediaInfo->DeviceType ==
IdeLS120) {
2139 if (FormatData.DesCode == 3) {
2140 MediaInfo->MediaPresent =
FALSE;
2141 MediaInfo->LastBlock = 0;
2142 MediaInfo2->MediaPresent =
FALSE;
2143 MediaInfo2->LastBlock = 0;
2145 MediaInfo->LastBlock = ((UINT32)FormatData.LastLba3 << 24) |
2146 (FormatData.LastLba2 << 16) |
2147 (FormatData.LastLba1 << 8) |
2148 FormatData.LastLba0;
2149 MediaInfo->LastBlock--;
2151 MediaInfo->MediaPresent =
TRUE;
2153 MediaInfo->BlockSize = 0x200;
2155 MediaInfo2->LastBlock = MediaInfo->LastBlock;
2156 MediaInfo2->MediaPresent = MediaInfo->MediaPresent;
2157 MediaInfo2->BlockSize = (UINT32)MediaInfo->BlockSize;
2163 return EFI_DEVICE_ERROR;
2194 UINTN BlocksRemaining;
2205 Read10Packet = &Packet.Read10;
2206 Lba32 = (UINT32)StartLba;
2212 MaxBlock = (UINT16)(0x10000 / BlockSize);
2216 BlocksRemaining = NumberOfBlocks;
2219 while (BlocksRemaining > 0) {
2220 if (BlocksRemaining <= MaxBlock) {
2221 SectorCount = (UINT16)BlocksRemaining;
2223 SectorCount = MaxBlock;
2235 Read10Packet->Lba3 = (UINT8)(Lba32 & 0xff);
2236 Read10Packet->Lba2 = (UINT8)(Lba32 >> 8);
2237 Read10Packet->Lba1 = (UINT8)(Lba32 >> 16);
2238 Read10Packet->Lba0 = (UINT8)(Lba32 >> 24);
2244 Read10Packet->TranLen1 = (UINT8)(SectorCount & 0xff);
2245 Read10Packet->TranLen0 = (UINT8)(SectorCount >> 8);
2247 ByteCount = (UINT32)(SectorCount * BlockSize);
2253 (UINT16 *)PtrBuffer,
2261 Lba32 += SectorCount;
2262 PtrBuffer = (UINT8 *)PtrBuffer + SectorCount * BlockSize;
2263 BlocksRemaining -= SectorCount;
2291 SensePtr = SenseData;
2293 for (Index = 0; Index < SenseCounts; Index++) {
2294 if ((SensePtr->sense_key == ATA_SK_NOT_READY) && (SensePtr->
addnl_sense_code == ATA_ASC_NO_MEDIA)) {
2326 SensePtr = SenseData;
2328 for (Index = 0; Index < SenseCounts; Index++) {
2329 if (SensePtr->sense_key == 0x06) {
2366 SensePtr = SenseData;
2368 for (Index = 0; Index < SenseCounts; Index++) {
2369 switch (SensePtr->sense_key) {
2370 case ATA_SK_MEDIUM_ERROR:
2372 case ATA_ASC_MEDIA_ERR1:
2376 case ATA_ASC_MEDIA_ERR2:
2380 case ATA_ASC_MEDIA_ERR3:
2384 case ATA_ASC_MEDIA_ERR4:
2394 case ATA_SK_NOT_READY:
2396 case ATA_ASC_MEDIA_UPSIDE_DOWN:
2431 OUT BOOLEAN *NeedRetry
2441 SensePtr = SenseData;
2443 for (Index = 0; Index < SenseCounts; Index++) {
2444 switch (SensePtr->sense_key) {
2445 case ATA_SK_NOT_READY:
2447 case ATA_ASC_NOT_READY:
2449 case ATA_ASCQ_IN_PROGRESS:
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
#define PEI_ICH_IDE_SECONDARY
#define PEI_ICH_IDE_PRIMARY
#define ATA_CMD_TEST_UNIT_READY
defined from ATA-1
#define ATA_STSREG_BSY
Controller Busy defined from ATA-1.
#define ATA_ERRREG_ABRT
Aborted Command defined from ATA-1.
#define ATA_STSREG_DRQ
Data Request defined from ATA-1.
#define ATA_CMD_REQUEST_SENSE
defined from ATA-4
#define ATA_STSREG_DWF
Drive Write Fault defined from ATA-1, obsoleted from ATA-4.
#define ATA_CMD_READ_10
defined in ATAPI Removable Rewritable Media Devices
#define ATA_STSREG_ERR
Error defined from ATA-1.
#define ATA_CMD_READ_CAPACITY
defined in ATAPI Removable Rewritable Media Devices
#define ATA_CTLREG_SRST
Software Reset.
#define ATA_STSREG_CORR
Corrected Data defined from ATA-1, obsoleted from ATA-4.
#define ATA_STSREG_DRDY
Drive Ready defined from ATA-1.
#define ATA_CMD_READ_FORMAT_CAPACITY
defined in ATAPI Removable Rewritable Media Devices
#define ATA_CMD_IDENTIFY_DEVICE
defined from ATA-3
#define ATA_CMD_SOFT_RESET
defined from ATA-3
#define ATA_CMD_PACKET
defined from ATA-3
#define ATA_CMD_INQUIRY
defined in ATAPI Removable Rewritable Media Devices
EFI_STATUS EFIAPI AtapiReadBlocks(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI AtapiGetBlockDeviceMediaInfo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo)
EFI_STATUS ReadCapacity(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
EFI_STATUS EFIAPI AtapiPeimEntry(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS DRDYReady(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
EFI_STATUS DRQReady(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
EFI_STATUS TestUnitReady(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
VOID AtapiEnumerateDevices(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev)
EFI_STATUS CheckPowerMode(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN UINT8 AtaCommand)
BOOLEAN DiscoverAtapiDevice(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
EFI_STATUS EFIAPI AtapiGetNumberOfBlockDevices2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS AtapiPacketCommandIn(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN ATAPI_PACKET_COMMAND *Packet, IN UINT16 *Buffer, IN UINT32 ByteCount, IN UINTN TimeoutInMilliSeconds)
EFI_STATUS DRQClear(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
EFI_STATUS ReadSectors(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN VOID *Buffer, IN EFI_PEI_LBA StartLba, IN UINTN NumberOfBlocks, IN UINTN BlockSize)
BOOLEAN DetectIDEController(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
EFI_STATUS ATAPIIdentify(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
EFI_STATUS RequestSense(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN ATAPI_REQUEST_SENSE_DATA *SenseBuffers, IN OUT UINT8 *SenseCounts)
EFI_STATUS WaitForBSYClear(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
EFI_STATUS CheckErrorStatus(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINT16 StatusReg)
EFI_STATUS DetectMedia(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
BOOLEAN IsNoMedia(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
BOOLEAN IsDriveReady(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts, OUT BOOLEAN *NeedRetry)
EFI_STATUS DRQReady2(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
BOOLEAN IsMediaError(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
BOOLEAN IsDeviceStateUnclear(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
EFI_STATUS EFIAPI AtapiReadBlocks2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI AtapiGetBlockDeviceMediaInfo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo)
EFI_STATUS ResetDevice(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN BOOLEAN Extensive)
EFI_STATUS DRQClear2(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
EFI_STATUS Inquiry(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
EFI_STATUS EFIAPI AtapiGetNumberOfBlockDevices(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI PeiServicesRegisterForShadow(IN EFI_PEI_FILE_HANDLE FileHandle)
UINT8 EFIAPI IoWrite8(IN UINTN Port, IN UINT8 Value)
UINT8 EFIAPI IoRead8(IN UINTN Port)
UINT16 EFIAPI IoRead16(IN UINTN Port)
UINT16 EFIAPI IoWrite16(IN UINTN Port, IN UINT16 Value)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
@ IdeLS120
The recovery device is an IDE LS-120.
@ IdeCDROM
The recovery device is an IDE CD-ROM.
#define PcdGet16(TokenName)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_PEI_READ_BLOCKS2 ReadBlocks
EFI_PEI_GET_DEVICE_MEDIA_INFORMATION2 GetBlockDeviceMediaInfo
EFI_PEI_GET_NUMBER_BLOCK_DEVICES2 GetNumberOfBlockDevices
EFI_PEI_READ_BLOCKS ReadBlocks
EFI_PEI_GET_NUMBER_BLOCK_DEVICES GetNumberOfBlockDevices
EFI_PEI_GET_DEVICE_MEDIA_INFORMATION GetBlockDeviceMediaInfo
UINT8 page_code
defined in SFF8090i, V6
UINT8 addnl_sense_code
mandatory
UINT8 addnl_sense_code_qualifier
mandatory
EFI_PEI_BLOCK_DEVICE_TYPE DeviceType
UINT16 CommandBlockBaseAddr
UINT16 ControlBlockBaseAddr