X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=MdeModulePkg%2FBus%2FAta%2FAtaAtapiPassThru%2FIdeMode.c;h=ac055f00422f132d283755f338967f4161033628;hb=9d510e61fceee7b92955ef9a3c20343752d8ce3f;hp=79310fcb49a311033550d48d11180dbf5846a0b2;hpb=7538d53684792266c37e91f11a3ce2b7fb1e32d9;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c index 79310fcb49..ac055f0042 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c @@ -1,14 +1,8 @@ /** @file Header file for AHCI mode of ATA host controller. - - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -17,8 +11,8 @@ /** read a one-byte data from a IDE port. - @param PciIo The PCI IO protocol instance - @param Port The IDE Port number + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure + @param Port The IDE Port number @return the one-byte data read from IDE port **/ @@ -51,7 +45,7 @@ IdeReadPortB ( /** write a 1-byte data to a specific IDE port. - @param PciIo The PCI IO protocol instance + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure @param Port The IDE port to be writen @param Data The data to write to the port **/ @@ -81,7 +75,7 @@ IdeWritePortB ( /** write a 1-word data to a specific IDE port. - @param PciIo PCI IO protocol instance + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure @param Port The IDE port to be writen @param Data The data to write to the port **/ @@ -111,7 +105,7 @@ IdeWritePortW ( /** write a 2-word data to a specific IDE port. - @param PciIo PCI IO protocol instance + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure @param Port The IDE port to be writen @param Data The data to write to the port **/ @@ -143,7 +137,7 @@ IdeWritePortDW ( Call the IO abstraction once to do the complete read, not one word at a time - @param PciIo Pointer to the EFI_PCI_IO instance + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure @param Port IO port to read @param Count No. of UINT16's to read @param Buffer Pointer to the data buffer for read @@ -180,7 +174,7 @@ IdeWritePortWMultiple ( Call the IO abstraction once to do the complete read, not one word at a time - @param PciIo Pointer to the EFI_PCI_IO instance + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure @param Port IO port to read @param Count Number of UINT16's to read @param Buffer Pointer to the data buffer for read @@ -217,7 +211,7 @@ IdeReadPortWMultiple ( some debug information and if there is ERR bit set in the Status Register, the Error Register's value is also be parsed and print out. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. @param AtaStatusBlock A pointer to EFI_ATA_STATUS_BLOCK data structure. @@ -294,11 +288,10 @@ DumpAllIdeRegisters ( } /** - This function is used to analyze the Status Register and print out - some debug information and if there is ERR bit set in the Status - Register, the Error Register's value is also be parsed and print out. + This function is used to analyze the Status Register at the condition that BSY is zero. + if there is ERR bit set in the Status Register, then return error. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. @retval EFI_SUCCESS No err information in the Status Register. @@ -312,7 +305,6 @@ CheckStatusRegister ( IN EFI_IDE_REGISTERS *IdeRegisters ) { - EFI_STATUS Status; UINT8 StatusRegister; ASSERT (PciIo != NULL); @@ -320,13 +312,14 @@ CheckStatusRegister ( StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus); - if ((StatusRegister & (ATA_STSREG_ERR | ATA_STSREG_DWF | ATA_STSREG_CORR)) == 0) { - Status = EFI_SUCCESS; - } else { - Status = EFI_DEVICE_ERROR; + if ((StatusRegister & ATA_STSREG_BSY) == 0) { + if ((StatusRegister & (ATA_STSREG_ERR | ATA_STSREG_DWF | ATA_STSREG_CORR)) == 0) { + return EFI_SUCCESS; + } else { + return EFI_DEVICE_ERROR; + } } - - return Status; + return EFI_SUCCESS; } /** @@ -334,9 +327,9 @@ CheckStatusRegister ( Register. DRQ is cleared when the device is finished transferring data. So this function is called after data transfer is finished. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. + @param Timeout The time to complete the command, uses 100ns as a unit. @retval EFI_SUCCESS DRQ bit clear within the time out. @@ -354,46 +347,44 @@ DRQClear ( IN UINT64 Timeout ) { - UINT32 Delay; + UINT64 Delay; UINT8 StatusRegister; - UINT8 ErrorRegister; + BOOLEAN InfiniteWait; ASSERT (PciIo != NULL); ASSERT (IdeRegisters != NULL); - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); + if (Timeout == 0) { + InfiniteWait = TRUE; + } else { + InfiniteWait = FALSE; + } + + Delay = DivU64x32(Timeout, 1000) + 1; do { StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus); // - // wait for BSY == 0 and DRQ == 0 + // Wait for BSY == 0, then judge if DRQ is clear // - if ((StatusRegister & (ATA_STSREG_DRQ | ATA_STSREG_BSY)) == 0) { - break; - } - - if ((StatusRegister & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { - ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); - - if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { - return EFI_ABORTED; + if ((StatusRegister & ATA_STSREG_BSY) == 0) { + if ((StatusRegister & ATA_STSREG_DRQ) == ATA_STSREG_DRQ) { + return EFI_DEVICE_ERROR; + } else { + return EFI_SUCCESS; } } // - // Stall for 100 microseconds. + // Stall for 100 microseconds. // MicroSecondDelay (100); Delay--; - } while (Delay > 0); + } while (InfiniteWait || (Delay > 0)); - if (Delay == 0) { - return EFI_TIMEOUT; - } - - return EFI_SUCCESS; + return EFI_TIMEOUT; } /** This function is used to poll for the DRQ bit clear in the Alternate @@ -401,9 +392,9 @@ DRQClear ( transferring data. So this function is called after data transfer is finished. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. + @param Timeout The time to complete the command, uses 100ns as a unit. @retval EFI_SUCCESS DRQ bit clear within the time out. @@ -419,29 +410,31 @@ DRQClear2 ( IN UINT64 Timeout ) { - UINT32 Delay; + UINT64 Delay; UINT8 AltRegister; - UINT8 ErrorRegister; + BOOLEAN InfiniteWait; ASSERT (PciIo != NULL); ASSERT (IdeRegisters != NULL); - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); + if (Timeout == 0) { + InfiniteWait = TRUE; + } else { + InfiniteWait = FALSE; + } + + Delay = DivU64x32(Timeout, 1000) + 1; do { AltRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev); // - // wait for BSY == 0 and DRQ == 0 + // Wait for BSY == 0, then judge if DRQ is clear // - if ((AltRegister & (ATA_STSREG_DRQ | ATA_STSREG_BSY)) == 0) { - break; - } - - if ((AltRegister & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { - ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); - - if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { - return EFI_ABORTED; + if ((AltRegister & ATA_STSREG_BSY) == 0) { + if ((AltRegister & ATA_STSREG_DRQ) == ATA_STSREG_DRQ) { + return EFI_DEVICE_ERROR; + } else { + return EFI_SUCCESS; } } @@ -452,13 +445,9 @@ DRQClear2 ( Delay--; - } while (Delay > 0); + } while (InfiniteWait || (Delay > 0)); - if (Delay == 0) { - return EFI_TIMEOUT; - } - - return EFI_SUCCESS; + return EFI_TIMEOUT; } /** @@ -468,13 +457,22 @@ DRQClear2 ( is called after the command is sent to the device and before required data is transferred. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. + @param Timeout The time to complete the command, uses 100ns as a unit. + + @retval EFI_SUCCESS BSY bit cleared and DRQ bit set within the + timeout. - @retval EFI_SUCCESS DRQ bit set within the time out. - @retval EFI_TIMEOUT DRQ bit not set within the time out. - @retval EFI_ABORTED DRQ bit not set caused by the command abort. + @retval EFI_TIMEOUT BSY bit not cleared within the timeout. + + @retval EFI_ABORTED Polling abandoned due to command abort. + + @retval EFI_DEVICE_ERROR Polling abandoned due to a non-abort error. + + @retval EFI_NOT_READY BSY bit cleared within timeout, and device + reported "command complete" by clearing DRQ + bit. @note Read Status Register will clear interrupt status. @@ -487,32 +485,44 @@ DRQReady ( IN UINT64 Timeout ) { - UINT32 Delay; + UINT64 Delay; UINT8 StatusRegister; UINT8 ErrorRegister; + BOOLEAN InfiniteWait; ASSERT (PciIo != NULL); ASSERT (IdeRegisters != NULL); - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); + if (Timeout == 0) { + InfiniteWait = TRUE; + } else { + InfiniteWait = FALSE; + } + + Delay = DivU64x32(Timeout, 1000) + 1; do { // - // read Status Register will clear interrupt + // Read Status Register will clear interrupt // StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus); // - // BSY==0,DRQ==1 + // Wait for BSY == 0, then judge if DRQ is clear or ERR is set // - if ((StatusRegister & (ATA_STSREG_BSY | ATA_STSREG_DRQ)) == ATA_STSREG_DRQ) { - break; - } + if ((StatusRegister & ATA_STSREG_BSY) == 0) { + if ((StatusRegister & ATA_STSREG_ERR) == ATA_STSREG_ERR) { + ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); - if ((StatusRegister & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { - ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); + if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { + return EFI_ABORTED; + } + return EFI_DEVICE_ERROR; + } - if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { - return EFI_ABORTED; + if ((StatusRegister & ATA_STSREG_DRQ) == ATA_STSREG_DRQ) { + return EFI_SUCCESS; + } else { + return EFI_NOT_READY; } } @@ -522,26 +532,32 @@ DRQReady ( MicroSecondDelay (100); Delay--; - } while (Delay > 0); - - if (Delay == 0) { - return EFI_TIMEOUT; - } + } while (InfiniteWait || (Delay > 0)); - return EFI_SUCCESS; + return EFI_TIMEOUT; } /** This function is used to poll for the DRQ bit set in the Alternate Status Register. - DRQ is set when the device is ready to transfer data. So this function is called after + DRQ is set when the device is ready to transfer data. So this function is called after the command is sent to the device and before required data is transferred. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. + @param PciIo A pointer to EFI_PCI_IO_PROTOCOL data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. + @param Timeout The time to complete the command, uses 100ns as a unit. + + @retval EFI_SUCCESS BSY bit cleared and DRQ bit set within the + timeout. + + @retval EFI_TIMEOUT BSY bit not cleared within the timeout. + + @retval EFI_ABORTED Polling abandoned due to command abort. + + @retval EFI_DEVICE_ERROR Polling abandoned due to a non-abort error. + + @retval EFI_NOT_READY BSY bit cleared within timeout, and device + reported "command complete" by clearing DRQ + bit. - @retval EFI_SUCCESS DRQ bit set within the time out. - @retval EFI_TIMEOUT DRQ bit not set within the time out. - @retval EFI_ABORTED DRQ bit not set caused by the command abort. @note Read Alternate Status Register will not clear interrupt status. **/ @@ -553,94 +569,44 @@ DRQReady2 ( IN UINT64 Timeout ) { - UINT32 Delay; + UINT64 Delay; UINT8 AltRegister; UINT8 ErrorRegister; + BOOLEAN InfiniteWait; ASSERT (PciIo != NULL); ASSERT (IdeRegisters != NULL); - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); + if (Timeout == 0) { + InfiniteWait = TRUE; + } else { + InfiniteWait = FALSE; + } + + Delay = DivU64x32(Timeout, 1000) + 1; do { // - // Read Alternate Status Register will not clear interrupt status + // Read Alternate Status Register will not clear interrupt status // AltRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev); // - // BSY == 0 , DRQ == 1 + // Wait for BSY == 0, then judge if DRQ is clear or ERR is set // - if ((AltRegister & (ATA_STSREG_BSY | ATA_STSREG_DRQ)) == ATA_STSREG_DRQ) { - break; - } - - if ((AltRegister & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { - ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); + if ((AltRegister & ATA_STSREG_BSY) == 0) { + if ((AltRegister & ATA_STSREG_ERR) == ATA_STSREG_ERR) { + ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); - if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { - return EFI_ABORTED; + if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { + return EFI_ABORTED; + } + return EFI_DEVICE_ERROR; } - } - - // - // Stall for 100 microseconds. - // - MicroSecondDelay (100); - - Delay--; - } while (Delay > 0); - - if (Delay == 0) { - return EFI_TIMEOUT; - } - - return EFI_SUCCESS; -} - -/** - This function is used to poll for the DRDY bit set in the Status Register. DRDY - bit is set when the device is ready to accept command. Most ATA commands must be - sent after DRDY set except the ATAPI Packet Command. - - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. - @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. - - @retval EFI_SUCCESS DRDY bit set within the time out. - @retval EFI_TIMEOUT DRDY bit not set within the time out. - - @note Read Status Register will clear interrupt status. -**/ -EFI_STATUS -EFIAPI -DRDYReady ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN EFI_IDE_REGISTERS *IdeRegisters, - IN UINT64 Timeout - ) -{ - UINT32 Delay; - UINT8 StatusRegister; - UINT8 ErrorRegister; - - ASSERT (PciIo != NULL); - ASSERT (IdeRegisters != NULL); - - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); - do { - StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus); - // - // BSY == 0 , DRDY == 1 - // - if ((StatusRegister & (ATA_STSREG_DRDY | ATA_STSREG_BSY)) == ATA_STSREG_DRDY) { - break; - } - if ((StatusRegister & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { - ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); - - if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { - return EFI_ABORTED; + if ((AltRegister & ATA_STSREG_DRQ) == ATA_STSREG_DRQ) { + return EFI_SUCCESS; + } else { + return EFI_NOT_READY; } } @@ -650,77 +616,13 @@ DRDYReady ( MicroSecondDelay (100); Delay--; - } while (Delay > 0); - - if (Delay == 0) { - return EFI_TIMEOUT; - } + } while (InfiniteWait || (Delay > 0)); - return EFI_SUCCESS; + return EFI_TIMEOUT; } -/** - This function is used to poll for the DRDY bit set in the Alternate Status Register. - DRDY bit is set when the device is ready to accept command. Most ATA commands must - be sent after DRDY set except the ATAPI Packet Command. - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. - @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. - - @retval EFI_SUCCESS DRDY bit set within the time out. - @retval EFI_TIMEOUT DRDY bit not set within the time out. - @note Read Alternate Status Register will clear interrupt status. - -**/ -EFI_STATUS -EFIAPI -DRDYReady2 ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN EFI_IDE_REGISTERS *IdeRegisters, - IN UINT64 Timeout - ) -{ - UINT32 Delay; - UINT8 AltRegister; - UINT8 ErrorRegister; - - ASSERT (PciIo != NULL); - ASSERT (IdeRegisters != NULL); - - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); - do { - AltRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev); - // - // BSY == 0 , DRDY == 1 - // - if ((AltRegister & (ATA_STSREG_DRDY | ATA_STSREG_BSY)) == ATA_STSREG_DRDY) { - break; - } - - if ((AltRegister & (ATA_STSREG_BSY | ATA_STSREG_ERR)) == ATA_STSREG_ERR) { - ErrorRegister = IdeReadPortB (PciIo, IdeRegisters->ErrOrFeature); - - if ((ErrorRegister & ATA_ERRREG_ABRT) == ATA_ERRREG_ABRT) { - return EFI_ABORTED; - } - } - - // - // Stall for 100 microseconds. - // - MicroSecondDelay (100); - - Delay--; - } while (Delay > 0); - - if (Delay == 0) { - return EFI_TIMEOUT; - } - - return EFI_SUCCESS; -} /** This function is used to poll for the BSY bit clear in the Status Register. BSY @@ -728,7 +630,7 @@ DRDYReady2 ( @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. + @param Timeout The time to complete the command, uses 100ns as a unit. @retval EFI_SUCCESS BSY bit clear within the time out. @retval EFI_TIMEOUT BSY bit not clear within the time out. @@ -743,18 +645,25 @@ WaitForBSYClear ( IN UINT64 Timeout ) { - UINT32 Delay; + UINT64 Delay; UINT8 StatusRegister; + BOOLEAN InfiniteWait; ASSERT (PciIo != NULL); ASSERT (IdeRegisters != NULL); - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); + if (Timeout == 0) { + InfiniteWait = TRUE; + } else { + InfiniteWait = FALSE; + } + + Delay = DivU64x32(Timeout, 1000) + 1; do { StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus); if ((StatusRegister & ATA_STSREG_BSY) == 0x00) { - break; + return EFI_SUCCESS; } // @@ -764,68 +673,14 @@ WaitForBSYClear ( Delay--; - } while (Delay > 0); - - if (Delay == 0) { - return EFI_TIMEOUT; - } + } while (InfiniteWait || (Delay > 0)); - return EFI_SUCCESS; + return EFI_TIMEOUT; } -/** - This function is used to poll for the BSY bit clear in the Status Register. BSY - is clear when the device is not busy. Every command must be sent after device is not busy. - - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. - @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. - - @retval EFI_SUCCESS BSY bit clear within the time out. - @retval EFI_TIMEOUT BSY bit not clear within the time out. - - @note Read Status Register will clear interrupt status. -**/ -EFI_STATUS -EFIAPI -WaitForBSYClear2 ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN EFI_IDE_REGISTERS *IdeRegisters, - IN UINT64 Timeout - ) -{ - UINT32 Delay; - UINT8 AltStatusRegister; - - ASSERT (PciIo != NULL); - ASSERT (IdeRegisters != NULL); - - Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1); - do { - AltStatusRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev); - - if ((AltStatusRegister & ATA_STSREG_BSY) == 0x00) { - break; - } - - // - // Stall for 100 microseconds. - // - MicroSecondDelay (100); - - Delay--; - - } while (Delay > 0); - - if (Delay == 0) { - return EFI_TIMEOUT; - } - - return EFI_SUCCESS; -} /** - Get IDE i/o port registers' base addresses by mode. + Get IDE i/o port registers' base addresses by mode. In 'Compatibility' mode, use fixed addresses. In Native-PCI mode, get base addresses from BARs in the PCI IDE controller's @@ -848,7 +703,7 @@ WaitForBSYClear2 ( |___________|_______________|_______________| Table 1. Compatibility resource mappings - + b) In Native-PCI mode, IDE registers are mapped into IO space using the BARs in IDE controller's PCI Configuration Space, shown in the Table 2 below. ___________________________________________________ @@ -865,7 +720,7 @@ WaitForBSYClear2 ( @param[in] PciIo Pointer to the EFI_PCI_IO_PROTOCOL instance @param[in, out] IdeRegisters Pointer to EFI_IDE_REGISTERS which is used to store the IDE i/o port registers' base addresses - + @retval EFI_UNSUPPORTED Return this value when the BARs is not IO type @retval EFI_SUCCESS Get the Base address successfully @retval Other Read the pci configureation data error @@ -965,72 +820,6 @@ GetIdeRegisterIoAddr ( return EFI_SUCCESS; } -/** - This function is used to implement the Soft Reset on the specified device. But, - the ATA Soft Reset mechanism is so strong a reset method that it will force - resetting on both devices connected to the same cable. - - It is called by IdeBlkIoReset(), a interface function of Block - I/O protocol. - - This function can also be used by the ATAPI device to perform reset when - ATAPI Reset command is failed. - - @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. - @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. - @param Timeout The time to complete the command. - - @retval EFI_SUCCESS Soft reset completes successfully. - @retval EFI_DEVICE_ERROR Any step during the reset process is failed. - - @note The registers initial values after ATA soft reset are different - to the ATA device and ATAPI device. -**/ -EFI_STATUS -EFIAPI -AtaSoftReset ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN EFI_IDE_REGISTERS *IdeRegisters, - IN UINT64 Timeout - ) -{ - UINT8 DeviceControl; - - DeviceControl = 0; - // - // disable Interrupt and set SRST bit to initiate soft reset - // - DeviceControl = ATA_CTLREG_SRST | ATA_CTLREG_IEN_L; - - IdeWritePortB (PciIo, IdeRegisters->AltOrDev, DeviceControl); - - // - // SRST should assert for at least 5 us, we use 10 us for - // better compatibility - // - MicroSecondDelay (10); - - // - // Enable interrupt to support UDMA, and clear SRST bit - // - DeviceControl = 0; - IdeWritePortB (PciIo, IdeRegisters->AltOrDev, DeviceControl); - - // - // Wait for at least 10 ms to check BSY status, we use 10 ms - // for better compatibility - // - MicroSecondDelay (10000); - - // - // slave device needs at most 31ms to clear BSY - // - if (WaitForBSYClear (PciIo, IdeRegisters, Timeout) == EFI_TIMEOUT) { - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; -} /** Send ATA Ext command into device with NON_DATA protocol. @@ -1038,7 +827,7 @@ AtaSoftReset ( @param PciIo A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. @param IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. @param AtaCommandBlock A pointer to EFI_ATA_COMMAND_BLOCK data structure. - @param Timeout The time to complete the command. + @param Timeout The time to complete the command, uses 100ns as a unit. @retval EFI_SUCCESS Reading succeed @retval EFI_DEVICE_ERROR Error executing commands on this device. @@ -1134,17 +923,17 @@ AtaIssueCommand ( from host to device. @param[in] AtaCommandBlock A pointer to EFI_ATA_COMMAND_BLOCK data structure. @param[in, out] AtaStatusBlock A pointer to EFI_ATA_STATUS_BLOCK data structure. - @param[in] Timeout The time to complete the command. + @param[in] Timeout The time to complete the command, uses 100ns as a unit. @param[in] Task Optional. Pointer to the ATA_NONBLOCK_TASK used by non-blocking mode. - + @retval EFI_SUCCESS send out the ATA command and device send required data successfully. @retval EFI_DEVICE_ERROR command sent failed. **/ EFI_STATUS EFIAPI -AtaPioDataInOut ( +AtaPioDataInOut ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_IDE_REGISTERS *IdeRegisters, IN OUT VOID *Buffer, @@ -1203,7 +992,7 @@ AtaPioDataInOut ( // Poll DRQ bit set, data transfer can be performed only when DRQ is ready // Status = DRQReady2 (PciIo, IdeRegisters, Timeout); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto Exit; } @@ -1268,7 +1057,7 @@ Exit: @param[in] AtaCommandBlock A pointer to EFI_ATA_COMMAND_BLOCK data structure. @param[in, out] AtaStatusBlock A pointer to EFI_ATA_STATUS_BLOCK data structure. - @param[in] Timeout The time to complete the command. + @param[in] Timeout The time to complete the command, uses 100ns as a unit. @param[in] Task Optional. Pointer to the ATA_NONBLOCK_TASK used by non-blocking mode. @@ -1279,7 +1068,7 @@ Exit: **/ EFI_STATUS EFIAPI -AtaNonDataCommandIn ( +AtaNonDataCommandIn ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_IDE_REGISTERS *IdeRegisters, IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock, @@ -1311,7 +1100,7 @@ AtaNonDataCommandIn ( Status = EFI_DEVICE_ERROR; goto Exit; } - + Status = CheckStatusRegister (PciIo, IdeRegisters); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; @@ -1323,7 +1112,7 @@ Exit: // Dump All Ide registers to ATA_STATUS_BLOCK // DumpAllIdeRegisters (PciIo, IdeRegisters, AtaStatusBlock); - + // // Not support the Non-blocking now,just do the blocking process. // @@ -1332,9 +1121,10 @@ Exit: /** Wait for memory to be set. - + @param[in] PciIo The PCI IO protocol instance. - @param[in] PortNum The IDE Port number. + @param[in] IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. + @param[in] Timeout The time to complete the command, uses 100ns as a unit. @retval EFI_DEVICE_ERROR The memory is not set. @retval EFI_TIMEOUT The memory setting is time out. @@ -1343,19 +1133,34 @@ Exit: **/ EFI_STATUS AtaUdmStatusWait ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN UINT16 PortNum - ) + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN EFI_IDE_REGISTERS *IdeRegisters, + IN UINT64 Timeout + ) { UINT8 RegisterValue; EFI_STATUS Status; - UINT64 Timeout; + UINT16 IoPortForBmis; + UINT64 Delay; + BOOLEAN InfiniteWait; - Timeout = 2000; + if (Timeout == 0) { + InfiniteWait = TRUE; + } else { + InfiniteWait = FALSE; + } + + Delay = DivU64x32 (Timeout, 1000) + 1; - while (TRUE) { - RegisterValue = IdeReadPortB (PciIo, PortNum); + do { + Status = CheckStatusRegister (PciIo, IdeRegisters); + if (EFI_ERROR (Status)) { + Status = EFI_DEVICE_ERROR; + break; + } + IoPortForBmis = (UINT16) (IdeRegisters->BusMasterBaseAddr + BMIS_OFFSET); + RegisterValue = IdeReadPortB (PciIo, IoPortForBmis); if (((RegisterValue & BMIS_ERROR) != 0) || (Timeout == 0)) { DEBUG ((EFI_D_ERROR, "ATA UDMA operation fails\n")); Status = EFI_DEVICE_ERROR; @@ -1367,22 +1172,22 @@ AtaUdmStatusWait ( break; } // - // Stall for 1 milliseconds. + // Stall for 100 microseconds. // - MicroSecondDelay (1000); - Timeout--; - } + MicroSecondDelay (100); + Delay--; + } while (InfiniteWait || (Delay > 0)); return Status; } /** Check if the memory to be set. - + @param[in] PciIo The PCI IO protocol instance. @param[in] Task Optional. Pointer to the ATA_NONBLOCK_TASK used by non-blocking mode. - @param[in] PortForBit The bit to be checked. + @param[in] IdeRegisters A pointer to EFI_IDE_REGISTERS data structure. @retval EFI_DEVICE_ERROR The memory setting met a issue. @retval EFI_NOT_READY The memory is not set. @@ -1394,13 +1199,22 @@ EFI_STATUS AtaUdmStatusCheck ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN ATA_NONBLOCK_TASK *Task, - IN UINT16 PortForBit + IN EFI_IDE_REGISTERS *IdeRegisters ) { - UINT8 RegisterValue; + UINT8 RegisterValue; + UINT16 IoPortForBmis; + EFI_STATUS Status; Task->RetryTimes--; - RegisterValue = IdeReadPortB(PciIo, PortForBit); + + Status = CheckStatusRegister (PciIo, IdeRegisters); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + IoPortForBmis = (UINT16) (IdeRegisters->BusMasterBaseAddr + BMIS_OFFSET); + RegisterValue = IdeReadPortB (PciIo, IoPortForBmis); if ((RegisterValue & BMIS_ERROR) != 0) { DEBUG ((EFI_D_ERROR, "ATA UDMA operation fails\n")); @@ -1411,7 +1225,7 @@ AtaUdmStatusCheck ( return EFI_SUCCESS; } - if (Task->RetryTimes == 0) { + if (!Task->InfiniteWait && (Task->RetryTimes == 0)) { return EFI_TIMEOUT; } else { // @@ -1435,7 +1249,7 @@ AtaUdmStatusCheck ( @param[in] DataLength The length of the data. @param[in] AtaCommandBlock A pointer to EFI_ATA_COMMAND_BLOCK data structure. @param[in, out] AtaStatusBlock A pointer to EFI_ATA_STATUS_BLOCK data structure. - @param[in] Timeout The time to complete the command. + @param[in] Timeout The time to complete the command, uses 100ns as a unit. @param[in] Task Optional. Pointer to the ATA_NONBLOCK_TASK used by non-blocking mode. @@ -1467,7 +1281,7 @@ AtaUdmaInOut ( UINTN PrdTableSize; EFI_PHYSICAL_ADDRESS PrdTableMapAddr; VOID *PrdTableMap; - EFI_ATA_DMA_PRD *PrdBaseAddr; + EFI_PHYSICAL_ADDRESS PrdTableBaseAddr; EFI_ATA_DMA_PRD *TempPrdBaseAddr; UINTN PrdTableNum; @@ -1485,12 +1299,17 @@ AtaUdmaInOut ( EFI_PCI_IO_PROTOCOL *PciIo; EFI_TPL OldTpl; + UINTN AlignmentMask; + UINTN RealPageCount; + EFI_PHYSICAL_ADDRESS BaseAddr; + EFI_PHYSICAL_ADDRESS BaseMapAddr; Status = EFI_SUCCESS; - PrdBaseAddr = NULL; PrdTableMap = NULL; BufferMap = NULL; PageCount = 0; + RealPageCount = 0; + BaseAddr = 0; PciIo = Instance->PciIo; if ((PciIo == NULL) || (IdeRegisters == NULL) || (DataBuffer == NULL) || (AtaCommandBlock == NULL)) { @@ -1502,15 +1321,15 @@ AtaUdmaInOut ( // BlockIO tasks. // Delay 1ms to simulate the blocking time out checking. // + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); while ((Task == NULL) && (!IsListEmpty (&Instance->NonBlockingTaskList))) { - OldTpl = gBS->RaiseTPL (TPL_NOTIFY); AsyncNonBlockingTransferRoutine (NULL, Instance); - gBS->RestoreTPL (OldTpl); // // Stall for 1 milliseconds. // MicroSecondDelay (1000); - } + } + gBS->RestoreTPL (OldTpl); // // The data buffer should be even alignment @@ -1527,10 +1346,10 @@ AtaUdmaInOut ( IoPortForBmid = (UINT16) (IdeRegisters->BusMasterBaseAddr + BMID_OFFSET); // - // For Blocking mode, start the command. + // For Blocking mode, start the command. // For non-blocking mode, when the command is not started, start it, otherwise // go to check the status. - // + // if (((Task != NULL) && (!Task->IsStart)) || (Task == NULL)) { // // Calculate the number of PRD entry. @@ -1548,40 +1367,56 @@ AtaUdmaInOut ( // // Allocate buffer for PRD table initialization. + // Note Ide Bus Master spec said the descriptor table must be aligned on a 4 byte + // boundary and the table cannot cross a 64K boundary in memory. + // + PageCount = EFI_SIZE_TO_PAGES (PrdTableSize); + RealPageCount = PageCount + EFI_SIZE_TO_PAGES (SIZE_64KB); + + // + // Make sure that PageCount plus EFI_SIZE_TO_PAGES (SIZE_64KB) does not overflow. // - PageCount = EFI_SIZE_TO_PAGES (PrdTableSize); + ASSERT (RealPageCount > PageCount); + Status = PciIo->AllocateBuffer ( PciIo, AllocateAnyPages, EfiBootServicesData, - PageCount, - (VOID **)&PrdBaseAddr, + RealPageCount, + (VOID **)&BaseAddr, 0 ); if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } - ByteCount = EFI_PAGES_TO_SIZE (PageCount); + ByteCount = EFI_PAGES_TO_SIZE (RealPageCount); Status = PciIo->Map ( PciIo, EfiPciIoOperationBusMasterCommonBuffer, - PrdBaseAddr, + (VOID*)(UINTN)BaseAddr, &ByteCount, - &PrdTableMapAddr, + &BaseMapAddr, &PrdTableMap ); - if (EFI_ERROR (Status) || (ByteCount != EFI_PAGES_TO_SIZE (PageCount))) { + if (EFI_ERROR (Status) || (ByteCount != EFI_PAGES_TO_SIZE (RealPageCount))) { // // If the data length actually mapped is not equal to the requested amount, // it means the DMA operation may be broken into several discontinuous smaller chunks. // Can't handle this case. // - PciIo->FreeBuffer (PciIo, PageCount, PrdBaseAddr); + PciIo->FreeBuffer (PciIo, RealPageCount, (VOID*)(UINTN)BaseAddr); return EFI_OUT_OF_RESOURCES; } - ZeroMem ((VOID *) ((UINTN) PrdBaseAddr), ByteCount); + ZeroMem ((VOID *) ((UINTN) BaseAddr), ByteCount); + + // + // Calculate the 64K align address as PRD Table base address. + // + AlignmentMask = SIZE_64KB - 1; + PrdTableBaseAddr = ((UINTN) BaseAddr + AlignmentMask) & ~AlignmentMask; + PrdTableMapAddr = ((UINTN) BaseMapAddr + AlignmentMask) & ~AlignmentMask; // // Map the host address of DataBuffer to DMA master address. @@ -1603,7 +1438,7 @@ AtaUdmaInOut ( ); if (EFI_ERROR (Status) || (ByteCount != DataLength)) { PciIo->Unmap (PciIo, PrdTableMap); - PciIo->FreeBuffer (PciIo, PageCount, PrdBaseAddr); + PciIo->FreeBuffer (PciIo, RealPageCount, (VOID*)(UINTN)BaseAddr); return EFI_OUT_OF_RESOURCES; } @@ -1617,7 +1452,7 @@ AtaUdmaInOut ( // Fill the PRD table with appropriate bus master address of data buffer and data length. // ByteRemaining = ByteCount; - TempPrdBaseAddr = PrdBaseAddr; + TempPrdBaseAddr = (EFI_ATA_DMA_PRD*)(UINTN)PrdTableBaseAddr; while (ByteRemaining != 0) { if (ByteRemaining <= 0x10000) { TempPrdBaseAddr->RegionBaseAddr = (UINT32) ((UINTN) BufferMapAddress); @@ -1652,7 +1487,7 @@ AtaUdmaInOut ( // RegisterValue = IdeReadPortB(PciIo, IoPortForBmis); RegisterValue |= (BMIS_INTERRUPT | BMIS_ERROR); - IdeWritePortB(PciIo, IoPortForBmis, RegisterValue); + IdeWritePortB (PciIo, IoPortForBmis, RegisterValue); // // Set the base address to BMID register @@ -1670,6 +1505,14 @@ AtaUdmaInOut ( } IdeWritePortB (PciIo, IoPortForBmic, RegisterValue); + if (Task != NULL) { + Task->Map = BufferMap; + Task->TableMap = PrdTableMap; + Task->MapBaseAddress = (EFI_ATA_DMA_PRD*)(UINTN)BaseAddr; + Task->PageCount = RealPageCount; + Task->IsStart = TRUE; + } + // // Issue ATA command // @@ -1680,6 +1523,11 @@ AtaUdmaInOut ( goto Exit; } + Status = CheckStatusRegister (PciIo, IdeRegisters); + if (EFI_ERROR (Status)) { + Status = EFI_DEVICE_ERROR; + goto Exit; + } // // Set START bit of BMIC register // @@ -1687,31 +1535,15 @@ AtaUdmaInOut ( RegisterValue |= BMIC_START; IdeWritePortB(PciIo, IoPortForBmic, RegisterValue); - if (Task != NULL) { - // - // Max transfer number of sectors for one command is 65536(32Mbyte), - // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps). - // So set the variable Count to 2000, for about 2 second Timeout time. - // - Task->RetryTimes = 2000; - Task->Map = BufferMap; - Task->TableMap = PrdTableMap; - Task->MapBaseAddress = PrdBaseAddr; - Task->PageCount = PageCount; - Task->IsStart = TRUE; - } } // // Check the INTERRUPT and ERROR bit of BMIS - // Max transfer number of sectors for one command is 65536(32Mbyte), - // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps). - // So set the variable Count to 2000, for about 2 second Timeout time. // if (Task != NULL) { - Status = AtaUdmStatusCheck (PciIo, Task, IoPortForBmis); + Status = AtaUdmStatusCheck (PciIo, Task, IdeRegisters); } else { - Status = AtaUdmStatusWait (PciIo, IoPortForBmis); + Status = AtaUdmStatusWait (PciIo, IdeRegisters, Timeout); } // @@ -1764,7 +1596,7 @@ Exit: PciIo->Unmap (PciIo, Task->Map); } else { PciIo->Unmap (PciIo, PrdTableMap); - PciIo->FreeBuffer (PciIo, PageCount, PrdBaseAddr); + PciIo->FreeBuffer (PciIo, RealPageCount, (VOID*)(UINTN)BaseAddr); PciIo->Unmap (PciIo, BufferMap); } @@ -1773,7 +1605,7 @@ Exit: // DumpAllIdeRegisters (PciIo, IdeRegisters, AtaStatusBlock); } - + return Status; } @@ -1807,8 +1639,8 @@ AtaPacketReadPendingData ( while ((TempWordBuffer & (ATA_STSREG_BSY | ATA_STSREG_DRQ)) == ATA_STSREG_DRQ) { IdeReadPortWMultiple ( PciIo, - IdeRegisters->Data, - 1, + IdeRegisters->Data, + 1, &TempWordBuffer ); TempWordBuffer = IdeReadPortB (PciIo, IdeRegisters->AltOrDev); @@ -1818,7 +1650,7 @@ AtaPacketReadPendingData ( } /** - This function is called by AtaPacketCommandExecute(). + This function is called by AtaPacketCommandExecute(). It is used to transfer data between host and device. The data direction is specified by the fourth parameter. @@ -1829,7 +1661,8 @@ AtaPacketReadPendingData ( @param Read Flag used to determine the data transfer direction. Read equals 1, means data transferred from device to host; Read equals 0, means data transferred from host to device. - @param Timeout Timeout value for wait DRQ ready before each data stream's transfer. + @param Timeout Timeout value for wait DRQ ready before each data stream's transfer + , uses 100ns as a unit. @retval EFI_SUCCESS data is transferred successfully. @retval EFI_DEVICE_ERROR the device failed to transfer data. @@ -1840,7 +1673,7 @@ AtaPacketReadWrite ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_IDE_REGISTERS *IdeRegisters, IN OUT VOID *Buffer, - IN UINT64 ByteCount, + IN OUT UINT32 *ByteCount, IN BOOLEAN Read, IN UINT64 Timeout ) @@ -1851,17 +1684,18 @@ AtaPacketReadWrite ( EFI_STATUS Status; UINT16 *PtrBuffer; + PtrBuffer = Buffer; + RequiredWordCount = *ByteCount >> 1; + // // No data transfer is premitted. // - if (ByteCount == 0) { + if (RequiredWordCount == 0) { return EFI_SUCCESS; } - - PtrBuffer = Buffer; - RequiredWordCount = (UINT32)RShiftU64(ByteCount, 1); + // - // ActuralWordCount means the word count of data really transferred. + // ActualWordCount means the word count of data really transferred. // ActualWordCount = 0; @@ -1872,7 +1706,15 @@ AtaPacketReadWrite ( // Status = DRQReady2 (PciIo, IdeRegisters, Timeout); if (EFI_ERROR (Status)) { - return CheckStatusRegister (PciIo, IdeRegisters); + if (Status == EFI_NOT_READY) { + // + // Device provided less data than we intended to read, or wanted less + // data than we intended to write, but it may still be successful. + // + break; + } else { + return Status; + } } // @@ -1912,7 +1754,7 @@ AtaPacketReadWrite ( PtrBuffer += WordCount; ActualWordCount += WordCount; } - + if (Read) { // // In the case where the drive wants to send more data than we need to read, @@ -1933,66 +1775,17 @@ AtaPacketReadWrite ( // // After data transfer is completed, normally, DRQ bit should clear. // - Status = DRQClear2 (PciIo, IdeRegisters, Timeout); + Status = DRQClear (PciIo, IdeRegisters, Timeout); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } - - return Status; -} - -/** - Sumbit ATAPI request sense command. - - @param[in] PciIo Pointer to the EFI_PCI_IO_PROTOCOL instance - @param[in] IdeRegisters Pointer to EFI_IDE_REGISTERS which is used to - store the IDE i/o port registers' base addresses - @param[in] Channel The channel number of device. - @param[in] Device The device number of device. - @param[in] SenseData A pointer to store sense data. - @param[in] SenseDataLength The sense data length. - @param[in] Timeout The timeout value to execute this cmd. - - @retval EFI_SUCCESS Send out the ATAPI packet command successfully. - @retval EFI_DEVICE_ERROR The device failed to send data. - -**/ -EFI_STATUS -EFIAPI -AtaPacketRequestSense ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN EFI_IDE_REGISTERS *IdeRegisters, - IN UINT8 Channel, - IN UINT8 Device, - IN VOID *SenseData, - IN UINT8 SenseDataLength, - IN UINT64 Timeout - ) -{ - EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET Packet; - UINT8 Cdb[12]; - EFI_STATUS Status; - - ZeroMem (&Packet, sizeof (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET)); - ZeroMem (Cdb, 12); - - Cdb[0] = ATA_CMD_REQUEST_SENSE; - Cdb[4] = SenseDataLength; - - Packet.Timeout = Timeout; - Packet.Cdb = Cdb; - Packet.CdbLength = 12; - Packet.DataDirection = EFI_EXT_SCSI_DATA_DIRECTION_READ; - Packet.InDataBuffer = SenseData; - Packet.InTransferLength = SenseDataLength; - - Status = AtaPacketCommandExecute (PciIo, IdeRegisters, Channel, Device, &Packet); + *ByteCount = ActualWordCount << 1; return Status; } /** - This function is used to send out ATAPI commands conforms to the Packet Command + This function is used to send out ATAPI commands conforms to the Packet Command with PIO Data In Protocol. @param[in] PciIo Pointer to the EFI_PCI_IO_PROTOCOL instance @@ -2017,7 +1810,6 @@ AtaPacketCommandExecute ( IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet ) { - EFI_STATUS PacketCommandStatus; EFI_ATA_COMMAND_BLOCK AtaCommandBlock; EFI_STATUS Status; UINT8 Count; @@ -2072,7 +1864,7 @@ AtaPacketCommandExecute ( // Send out ATAPI command packet // for (Count = 0; Count < 6; Count++) { - IdeWritePortW (PciIo, IdeRegisters->Data, *((UINT16*)PacketCommand + Count)); + IdeWritePortW (PciIo, IdeRegisters->Data, *((UINT16*)PacketCommand + Count)); // // Stall for 10 microseconds. // @@ -2083,56 +1875,26 @@ AtaPacketCommandExecute ( // Read/Write the data of ATAPI Command // if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ) { - PacketCommandStatus = AtaPacketReadWrite ( - PciIo, - IdeRegisters, - Packet->InDataBuffer, - Packet->InTransferLength, - TRUE, - Packet->Timeout - ); + Status = AtaPacketReadWrite ( + PciIo, + IdeRegisters, + Packet->InDataBuffer, + &Packet->InTransferLength, + TRUE, + Packet->Timeout + ); } else { - PacketCommandStatus = AtaPacketReadWrite ( - PciIo, - IdeRegisters, - Packet->OutDataBuffer, - Packet->OutTransferLength, - FALSE, - Packet->Timeout - ); - } - - if (!EFI_ERROR (PacketCommandStatus)) { - return PacketCommandStatus; - } - - // - // Return SenseData if PacketCommandStatus matches - // the following return codes. - // - if ((PacketCommandStatus == EFI_BAD_BUFFER_SIZE) || - (PacketCommandStatus == EFI_DEVICE_ERROR) || - (PacketCommandStatus == EFI_TIMEOUT)) { - - // - // avoid submit request sense command continuously. - // - if ((Packet->SenseData == NULL) || (((UINT8 *)Packet->Cdb)[0] == ATA_CMD_REQUEST_SENSE)) { - return PacketCommandStatus; - } - - AtaPacketRequestSense ( - PciIo, - IdeRegisters, - Channel, - Device, - Packet->SenseData, - Packet->SenseDataLength, - Packet->Timeout - ); + Status = AtaPacketReadWrite ( + PciIo, + IdeRegisters, + Packet->OutDataBuffer, + &Packet->OutTransferLength, + FALSE, + Packet->Timeout + ); } - return PacketCommandStatus; + return Status; } @@ -2207,14 +1969,13 @@ SetDriveParameters ( IN UINT8 Device, IN EFI_ATA_DRIVE_PARMS *DriveParameters, IN OUT EFI_ATA_STATUS_BLOCK *AtaStatusBlock - ) { EFI_STATUS Status; EFI_ATA_COMMAND_BLOCK AtaCommandBlock; ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK)); - + AtaCommandBlock.AtaCommand = ATA_CMD_INIT_DRIVE_PARAM; AtaCommandBlock.AtaSectorCount = DriveParameters->Sector; AtaCommandBlock.AtaDeviceHead = (UINT8) ((Device << 0x4) + DriveParameters->Heads); @@ -2227,7 +1988,7 @@ SetDriveParameters ( &Instance->IdeRegisters[Channel], &AtaCommandBlock, AtaStatusBlock, - ATA_ATAPI_TIMEOUT, + ATA_ATAPI_TIMEOUT, NULL ); @@ -2243,7 +2004,7 @@ SetDriveParameters ( &Instance->IdeRegisters[Channel], &AtaCommandBlock, AtaStatusBlock, - ATA_ATAPI_TIMEOUT, + ATA_ATAPI_TIMEOUT, NULL ); @@ -2297,9 +2058,18 @@ IdeAtaSmartReturnStatusCheck ( ); if (EFI_ERROR (Status)) { + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLED) + ); return EFI_DEVICE_ERROR; } + REPORT_STATUS_CODE ( + EFI_PROGRESS_CODE, + (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_ENABLE) + ); + LBAMid = IdeReadPortB (Instance->PciIo, Instance->IdeRegisters[Channel].CylinderLsb); LBAHigh = IdeReadPortB (Instance->PciIo, Instance->IdeRegisters[Channel].CylinderMsb); @@ -2308,12 +2078,19 @@ IdeAtaSmartReturnStatusCheck ( // The threshold exceeded condition is not detected by the device // DEBUG ((EFI_D_INFO, "The S.M.A.R.T threshold exceeded condition is not detected\n")); - + REPORT_STATUS_CODE ( + EFI_PROGRESS_CODE, + (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_UNDERTHRESHOLD) + ); } else if ((LBAMid == 0xf4) && (LBAHigh == 0x2c)) { // // The threshold exceeded condition is detected by the device // DEBUG ((EFI_D_INFO, "The S.M.A.R.T threshold exceeded condition is detected\n")); + REPORT_STATUS_CODE ( + EFI_PROGRESS_CODE, + (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_OVERTHRESHOLD) + ); } return EFI_SUCCESS; @@ -2349,14 +2126,23 @@ IdeAtaSmartSupport ( // // S.M.A.R.T is not supported by the device // - DEBUG ((EFI_D_INFO, "S.M.A.R.T feature is not supported at [%a] channel [%a] device!\n", + DEBUG ((EFI_D_INFO, "S.M.A.R.T feature is not supported at [%a] channel [%a] device!\n", (Channel == 1) ? "secondary" : "primary", (Device == 1) ? "slave" : "master")); + REPORT_STATUS_CODE ( + EFI_ERROR_CODE | EFI_ERROR_MINOR, + (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED) + ); } else { // // Check if the feature is enabled. If not, then enable S.M.A.R.T. // if ((IdentifyData->AtaData.command_set_feature_enb_85 & 0x0001) != 0x0001) { + REPORT_STATUS_CODE ( + EFI_PROGRESS_CODE, + (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLE) + ); + ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK)); AtaCommandBlock.AtaCommand = ATA_CMD_SMART; @@ -2409,7 +2195,7 @@ IdeAtaSmartSupport ( } } - DEBUG ((EFI_D_INFO, "Enabled S.M.A.R.T feature at [%a] channel [%a] device!\n", + DEBUG ((EFI_D_INFO, "Enabled S.M.A.R.T feature at [%a] channel [%a] device!\n", (Channel == 1) ? "secondary" : "primary", (Device == 1) ? "slave" : "master")); } @@ -2480,19 +2266,19 @@ AtaIdentify ( to fill in the Media data structure of the Block I/O Protocol interface. There are 5 steps to reach such objective: - 1. Sends out the ATAPI Identify Command to the specified device. + 1. Sends out the ATAPI Identify Command to the specified device. Only ATAPI device responses to this command. If the command succeeds, - it returns the Identify data structure which filled with information - about the device. Since the ATAPI device contains removable media, + it returns the Identify data structure which filled with information + about the device. Since the ATAPI device contains removable media, the only meaningful information is the device module name. 2. Sends out ATAPI Inquiry Packet Command to the specified device. This command will return inquiry data of the device, which contains the device type information. 3. Allocate sense data space for future use. We don't detect the media - presence here to improvement boot performance, especially when CD + presence here to improvement boot performance, especially when CD media is present. The media detection will be performed just before each BLK_IO read/write - + @param Instance A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure. @param Channel The channel number of device. @param Device The device number of device. @@ -2519,7 +2305,7 @@ AtaIdentifyPacket ( EFI_ATA_COMMAND_BLOCK AtaCommandBlock; ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK)); - + AtaCommandBlock.AtaCommand = ATA_CMD_IDENTIFY_DEVICE; AtaCommandBlock.AtaDeviceHead = (UINT8)(Device << 0x4); @@ -2593,12 +2379,17 @@ DetectAndConfigIdeDevice ( PciIo = Instance->PciIo; for (IdeDevice = 0; IdeDevice < EfiIdeMaxDevice; IdeDevice++) { + // + // Select Master or Slave device to get the return signature for ATA DEVICE DIAGNOSTIC cmd. + // + IdeWritePortB (PciIo, IdeRegisters->Head, (UINT8)((IdeDevice << 4) | 0xe0)); + // // Send ATA Device Execut Diagnostic command. // This command should work no matter DRDY is ready or not // IdeWritePortB (PciIo, IdeRegisters->CmdOrStatus, ATA_CMD_EXEC_DRIVE_DIAG); - + Status = WaitForBSYClear (PciIo, IdeRegisters, 350000000); if (EFI_ERROR (Status)) { DEBUG((EFI_D_ERROR, "New detecting method: Send Execute Diagnostic Command: WaitForBSYClear: Status: %d\n", Status)); @@ -2662,13 +2453,13 @@ DetectAndConfigIdeDevice ( continue; } - DEBUG ((EFI_D_INFO, "[%a] channel [%a] [%a] device\n", + DEBUG ((EFI_D_INFO, "[%a] channel [%a] [%a] device\n", (IdeChannel == 1) ? "secondary" : "primary ", (IdeDevice == 1) ? "slave " : "master", DeviceType == EfiIdeCdrom ? "cdrom " : "harddisk")); // // If the device is a hard disk, then try to enable S.M.A.R.T feature // - if (DeviceType == EfiIdeHarddisk) { + if ((DeviceType == EfiIdeHarddisk) && PcdGetBool (PcdAtaSmartEnable)) { IdeAtaSmartSupport ( Instance, IdeChannel, @@ -2783,9 +2574,9 @@ DetectAndConfigIdeDevice ( /** Initialize ATA host controller at IDE mode. - - The function is designed to initialize ATA host controller. - + + The function is designed to initialize ATA host controller. + @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance. **/