]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
MdeModulePkg/.../IdeMode: actualize DRQReady*() comment blocks
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaAtapiPassThru / IdeMode.c
index 0604a9d4c3cbd60774a25615cb2925b9ce90091a..b06f9889ed03abe60a7af0f8b43feeab60c3ad7e 100644 (file)
@@ -1,14 +1,14 @@
 /** @file\r
   Header file for AHCI mode of ATA host controller.\r
-  \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -18,7 +18,7 @@
   read a one-byte data from a IDE port.\r
 \r
   @param  PciIo  A pointer to EFI_PCI_IO_PROTOCOL data structure\r
-  @param  Port   The IDE Port number \r
+  @param  Port   The IDE Port number\r
 \r
   @return  the one-byte data read from IDE port\r
 **/\r
@@ -353,13 +353,20 @@ DRQClear (
   IN  UINT64                    Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   StatusRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus);\r
 \r
@@ -381,7 +388,7 @@ DRQClear (
 \r
     Delay--;\r
 \r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
@@ -409,13 +416,20 @@ DRQClear2 (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   AltRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     AltRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev);\r
 \r
@@ -437,7 +451,7 @@ DRQClear2 (
 \r
     Delay--;\r
 \r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
@@ -453,9 +467,18 @@ DRQClear2 (
   @param IdeRegisters     A pointer to EFI_IDE_REGISTERS data structure.\r
   @param Timeout          The time to complete the command, uses 100ns as a unit.\r
 \r
-  @retval EFI_SUCCESS          DRQ bit set within the time out.\r
-  @retval EFI_TIMEOUT          DRQ bit not set within the time out.\r
-  @retval EFI_ABORTED          DRQ bit not set caused by the command abort.\r
+  @retval EFI_SUCCESS           BSY bit cleared and DRQ bit set within the\r
+                                timeout.\r
+\r
+  @retval EFI_TIMEOUT           BSY bit not cleared within the timeout.\r
+\r
+  @retval EFI_ABORTED           Polling abandoned due to command abort.\r
+\r
+  @retval EFI_DEVICE_ERROR      Polling abandoned due to a non-abort error.\r
+\r
+  @retval EFI_NOT_READY         BSY bit cleared within timeout, and device\r
+                                reported "command complete" by clearing DRQ\r
+                                bit.\r
 \r
   @note  Read Status Register will clear interrupt status.\r
 \r
@@ -468,14 +491,21 @@ DRQReady (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   StatusRegister;\r
   UINT8   ErrorRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     //\r
     // Read Status Register will clear interrupt\r
@@ -508,22 +538,32 @@ DRQReady (
     MicroSecondDelay (100);\r
 \r
     Delay--;\r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
 /**\r
   This function is used to poll for the DRQ bit set in the Alternate Status Register.\r
-  DRQ is set when the device is ready to transfer data. So this function is called after \r
+  DRQ is set when the device is ready to transfer data. So this function is called after\r
   the command is sent to the device and before required data is transferred.\r
 \r
   @param PciIo            A pointer to EFI_PCI_IO_PROTOCOL data structure.\r
   @param IdeRegisters     A pointer to EFI_IDE_REGISTERS data structure.\r
   @param Timeout          The time to complete the command, uses 100ns as a unit.\r
 \r
-  @retval EFI_SUCCESS           DRQ bit set within the time out.\r
-  @retval EFI_TIMEOUT           DRQ bit not set within the time out.\r
-  @retval EFI_ABORTED           DRQ bit not set caused by the command abort.\r
+  @retval EFI_SUCCESS           BSY bit cleared and DRQ bit set within the\r
+                                timeout.\r
+\r
+  @retval EFI_TIMEOUT           BSY bit not cleared within the timeout.\r
+\r
+  @retval EFI_ABORTED           Polling abandoned due to command abort.\r
+\r
+  @retval EFI_DEVICE_ERROR      Polling abandoned due to a non-abort error.\r
+\r
+  @retval EFI_NOT_READY         BSY bit cleared within timeout, and device\r
+                                reported "command complete" by clearing DRQ\r
+                                bit.\r
+\r
   @note  Read Alternate Status Register will not clear interrupt status.\r
 \r
 **/\r
@@ -535,14 +575,21 @@ DRQReady2 (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   AltRegister;\r
   UINT8   ErrorRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
 \r
   do {\r
     //\r
@@ -575,14 +622,14 @@ DRQReady2 (
     MicroSecondDelay (100);\r
 \r
     Delay--;\r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
 \r
 /**\r
   This function is used to poll for the DRDY bit set in the Status Register. DRDY\r
-  bit is set when the device is ready to accept command. Most ATA commands must be \r
+  bit is set when the device is ready to accept command. Most ATA commands must be\r
   sent after DRDY set except the ATAPI Packet Command.\r
 \r
   @param PciIo            A pointer to EFI_PCI_IO_PROTOCOL data structure.\r
@@ -602,14 +649,21 @@ DRDYReady (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   StatusRegister;\r
   UINT8   ErrorRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus);\r
     //\r
@@ -638,14 +692,14 @@ DRDYReady (
     MicroSecondDelay (100);\r
 \r
     Delay--;\r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
 \r
 /**\r
-  This function is used to poll for the DRDY bit set in the Alternate Status Register. \r
-  DRDY bit is set when the device is ready to accept command. Most ATA commands must \r
+  This function is used to poll for the DRDY bit set in the Alternate Status Register.\r
+  DRDY bit is set when the device is ready to accept command. Most ATA commands must\r
   be sent after DRDY set except the ATAPI Packet Command.\r
 \r
   @param PciIo            A pointer to EFI_PCI_IO_PROTOCOL data structure.\r
@@ -666,14 +720,21 @@ DRDYReady2 (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   AltRegister;\r
   UINT8   ErrorRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     AltRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev);\r
     //\r
@@ -702,7 +763,7 @@ DRDYReady2 (
     MicroSecondDelay (100);\r
 \r
     Delay--;\r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
@@ -728,13 +789,20 @@ WaitForBSYClear (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   StatusRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     StatusRegister = IdeReadPortB (PciIo, IdeRegisters->CmdOrStatus);\r
 \r
@@ -749,7 +817,7 @@ WaitForBSYClear (
 \r
     Delay--;\r
 \r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
@@ -775,13 +843,20 @@ WaitForBSYClear2 (
   IN  UINT64               Timeout\r
   )\r
 {\r
-  UINT32  Delay;\r
+  UINT64  Delay;\r
   UINT8   AltStatusRegister;\r
+  BOOLEAN InfiniteWait;\r
 \r
   ASSERT (PciIo != NULL);\r
   ASSERT (IdeRegisters != NULL);\r
 \r
-  Delay = (UINT32) (DivU64x32(Timeout, 1000) + 1);\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
+\r
+  Delay = DivU64x32(Timeout, 1000) + 1;\r
   do {\r
     AltStatusRegister = IdeReadPortB (PciIo, IdeRegisters->AltOrDev);\r
 \r
@@ -796,13 +871,13 @@ WaitForBSYClear2 (
 \r
     Delay--;\r
 \r
-  } while (Delay > 0);\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return EFI_TIMEOUT;\r
 }\r
 \r
 /**\r
-  Get IDE i/o port registers' base addresses by mode. \r
+  Get IDE i/o port registers' base addresses by mode.\r
 \r
   In 'Compatibility' mode, use fixed addresses.\r
   In Native-PCI mode, get base addresses from BARs in the PCI IDE controller's\r
@@ -825,7 +900,7 @@ WaitForBSYClear2 (
   |___________|_______________|_______________|\r
 \r
   Table 1. Compatibility resource mappings\r
-  \r
+\r
   b) In Native-PCI mode, IDE registers are mapped into IO space using the BARs\r
   in IDE controller's PCI Configuration Space, shown in the Table 2 below.\r
    ___________________________________________________\r
@@ -842,7 +917,7 @@ WaitForBSYClear2 (
   @param[in]      PciIo          Pointer to the EFI_PCI_IO_PROTOCOL instance\r
   @param[in, out] IdeRegisters    Pointer to EFI_IDE_REGISTERS which is used to\r
                                  store the IDE i/o port registers' base addresses\r
-           \r
+\r
   @retval EFI_UNSUPPORTED        Return this value when the BARs is not IO type\r
   @retval EFI_SUCCESS            Get the Base address successfully\r
   @retval Other                  Read the pci configureation data error\r
@@ -944,7 +1019,7 @@ GetIdeRegisterIoAddr (
 \r
 /**\r
   This function is used to implement the Soft Reset on the specified device. But,\r
-  the ATA Soft Reset mechanism is so strong a reset method that it will force \r
+  the ATA Soft Reset mechanism is so strong a reset method that it will force\r
   resetting on both devices connected to the same cable.\r
 \r
   It is called by IdeBlkIoReset(), a interface function of Block\r
@@ -996,7 +1071,7 @@ AtaSoftReset (
   //\r
   // Wait for at least 10 ms to check BSY status, we use 10 ms\r
   // for better compatibility\r
-  //  \r
+  //\r
   MicroSecondDelay (10000);\r
 \r
   //\r
@@ -1114,14 +1189,14 @@ AtaIssueCommand (
   @param[in]      Timeout          The time to complete the command, uses 100ns as a unit.\r
   @param[in]      Task             Optional. Pointer to the ATA_NONBLOCK_TASK\r
                                    used by non-blocking mode.\r
-  \r
+\r
   @retval EFI_SUCCESS      send out the ATA command and device send required data successfully.\r
   @retval EFI_DEVICE_ERROR command sent failed.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-AtaPioDataInOut (  \r
+AtaPioDataInOut (\r
   IN     EFI_PCI_IO_PROTOCOL       *PciIo,\r
   IN     EFI_IDE_REGISTERS         *IdeRegisters,\r
   IN OUT VOID                      *Buffer,\r
@@ -1180,7 +1255,7 @@ AtaPioDataInOut (
     // Poll DRQ bit set, data transfer can be performed only when DRQ is ready\r
     //\r
     Status = DRQReady2 (PciIo, IdeRegisters, Timeout);\r
-    if (EFI_ERROR (Status)) {      \r
+    if (EFI_ERROR (Status)) {\r
       Status = EFI_DEVICE_ERROR;\r
       goto Exit;\r
     }\r
@@ -1256,7 +1331,7 @@ Exit:
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-AtaNonDataCommandIn (  \r
+AtaNonDataCommandIn (\r
   IN     EFI_PCI_IO_PROTOCOL       *PciIo,\r
   IN     EFI_IDE_REGISTERS         *IdeRegisters,\r
   IN     EFI_ATA_COMMAND_BLOCK     *AtaCommandBlock,\r
@@ -1288,7 +1363,7 @@ AtaNonDataCommandIn (
     Status = EFI_DEVICE_ERROR;\r
     goto Exit;\r
   }\r
-  \r
+\r
   Status = CheckStatusRegister (PciIo, IdeRegisters);\r
   if (EFI_ERROR (Status)) {\r
     Status = EFI_DEVICE_ERROR;\r
@@ -1300,7 +1375,7 @@ Exit:
   // Dump All Ide registers to ATA_STATUS_BLOCK\r
   //\r
   DumpAllIdeRegisters (PciIo, IdeRegisters, AtaStatusBlock);\r
-  \r
+\r
   //\r
   // Not support the Non-blocking now,just do the blocking process.\r
   //\r
@@ -1309,9 +1384,10 @@ Exit:
 \r
 /**\r
   Wait for memory to be set.\r
-    \r
+\r
   @param[in]  PciIo           The PCI IO protocol instance.\r
   @param[in]  IdeRegisters    A pointer to EFI_IDE_REGISTERS data structure.\r
+  @param[in]  Timeout         The time to complete the command, uses 100ns as a unit.\r
 \r
   @retval EFI_DEVICE_ERROR  The memory is not set.\r
   @retval EFI_TIMEOUT       The memory setting is time out.\r
@@ -1320,18 +1396,26 @@ Exit:
 **/\r
 EFI_STATUS\r
 AtaUdmStatusWait (\r
-  IN     EFI_PCI_IO_PROTOCOL       *PciIo,\r
-  IN     EFI_IDE_REGISTERS         *IdeRegisters\r
- ) \r
+  IN  EFI_PCI_IO_PROTOCOL       *PciIo,\r
+  IN  EFI_IDE_REGISTERS         *IdeRegisters,\r
+  IN  UINT64                    Timeout\r
+ )\r
 {\r
   UINT8                         RegisterValue;\r
   EFI_STATUS                    Status;\r
   UINT16                        IoPortForBmis;\r
-  UINT64                        Timeout;\r
+  UINT64                        Delay;\r
+  BOOLEAN                       InfiniteWait;\r
 \r
-  Timeout = 2000;\r
+  if (Timeout == 0) {\r
+    InfiniteWait = TRUE;\r
+  } else {\r
+    InfiniteWait = FALSE;\r
+  }\r
 \r
-  while (TRUE) {\r
+  Delay = DivU64x32 (Timeout, 1000) + 1;\r
+\r
+  do {\r
     Status = CheckStatusRegister (PciIo, IdeRegisters);\r
     if (EFI_ERROR (Status)) {\r
       Status = EFI_DEVICE_ERROR;\r
@@ -1351,18 +1435,18 @@ AtaUdmStatusWait (
       break;\r
     }\r
     //\r
-    // Stall for 1 milliseconds.\r
+    // Stall for 100 microseconds.\r
     //\r
-    MicroSecondDelay (1000);\r
-    Timeout--;\r
-  }\r
+    MicroSecondDelay (100);\r
+    Delay--;\r
+  } while (InfiniteWait || (Delay > 0));\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
   Check if the memory to be set.\r
-    \r
+\r
   @param[in]  PciIo           The PCI IO protocol instance.\r
   @param[in]  Task            Optional. Pointer to the ATA_NONBLOCK_TASK\r
                               used by non-blocking mode.\r
@@ -1404,7 +1488,7 @@ AtaUdmStatusCheck (
     return EFI_SUCCESS;\r
   }\r
 \r
-  if (Task->RetryTimes == 0) {\r
+  if (!Task->InfiniteWait && (Task->RetryTimes == 0)) {\r
     return EFI_TIMEOUT;\r
   } else {\r
     //\r
@@ -1460,7 +1544,7 @@ AtaUdmaInOut (
   UINTN                         PrdTableSize;\r
   EFI_PHYSICAL_ADDRESS          PrdTableMapAddr;\r
   VOID                          *PrdTableMap;\r
-  EFI_ATA_DMA_PRD               *PrdBaseAddr;\r
+  EFI_PHYSICAL_ADDRESS          PrdTableBaseAddr;\r
   EFI_ATA_DMA_PRD               *TempPrdBaseAddr;\r
   UINTN                         PrdTableNum;\r
 \r
@@ -1478,12 +1562,17 @@ AtaUdmaInOut (
   EFI_PCI_IO_PROTOCOL           *PciIo;\r
   EFI_TPL                       OldTpl;\r
 \r
+  UINTN                         AlignmentMask;\r
+  UINTN                         RealPageCount;\r
+  EFI_PHYSICAL_ADDRESS          BaseAddr;\r
+  EFI_PHYSICAL_ADDRESS          BaseMapAddr;\r
 \r
   Status        = EFI_SUCCESS;\r
-  PrdBaseAddr   = NULL;\r
   PrdTableMap   = NULL;\r
   BufferMap     = NULL;\r
   PageCount     = 0;\r
+  RealPageCount = 0;\r
+  BaseAddr      = 0;\r
   PciIo         = Instance->PciIo;\r
 \r
   if ((PciIo == NULL) || (IdeRegisters == NULL) || (DataBuffer == NULL) || (AtaCommandBlock == NULL)) {\r
@@ -1495,15 +1584,15 @@ AtaUdmaInOut (
   // BlockIO tasks.\r
   // Delay 1ms to simulate the blocking time out checking.\r
   //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   while ((Task == NULL) && (!IsListEmpty (&Instance->NonBlockingTaskList))) {\r
-    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
     AsyncNonBlockingTransferRoutine (NULL, Instance);\r
-    gBS->RestoreTPL (OldTpl);\r
     //\r
     // Stall for 1 milliseconds.\r
     //\r
     MicroSecondDelay (1000);\r
-  } \r
+  }\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
   //\r
   // The data buffer should be even alignment\r
@@ -1520,10 +1609,10 @@ AtaUdmaInOut (
   IoPortForBmid = (UINT16) (IdeRegisters->BusMasterBaseAddr + BMID_OFFSET);\r
 \r
   //\r
-  // For Blocking mode, start the command. \r
+  // For Blocking mode, start the command.\r
   // For non-blocking mode, when the command is not started, start it, otherwise\r
   // go to check the status.\r
-  //  \r
+  //\r
   if (((Task != NULL) && (!Task->IsStart)) || (Task == NULL)) {\r
     //\r
     // Calculate the number of PRD entry.\r
@@ -1541,40 +1630,56 @@ AtaUdmaInOut (
 \r
     //\r
     // Allocate buffer for PRD table initialization.\r
+    // Note Ide Bus Master spec said the descriptor table must be aligned on a 4 byte\r
+    // boundary and the table cannot cross a 64K boundary in memory.\r
+    //\r
+    PageCount     = EFI_SIZE_TO_PAGES (PrdTableSize);\r
+    RealPageCount = PageCount + EFI_SIZE_TO_PAGES (SIZE_64KB);\r
+\r
+    //\r
+    // Make sure that PageCount plus EFI_SIZE_TO_PAGES (SIZE_64KB) does not overflow.\r
     //\r
-    PageCount = EFI_SIZE_TO_PAGES (PrdTableSize);\r
+    ASSERT (RealPageCount > PageCount);\r
+\r
     Status    = PciIo->AllocateBuffer (\r
                          PciIo,\r
                          AllocateAnyPages,\r
                          EfiBootServicesData,\r
-                         PageCount,\r
-                         (VOID **)&PrdBaseAddr,\r
+                         RealPageCount,\r
+                         (VOID **)&BaseAddr,\r
                          0\r
                          );\r
     if (EFI_ERROR (Status)) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    ByteCount = EFI_PAGES_TO_SIZE (PageCount);\r
+    ByteCount = EFI_PAGES_TO_SIZE (RealPageCount);\r
     Status    = PciIo->Map (\r
                          PciIo,\r
                          EfiPciIoOperationBusMasterCommonBuffer,\r
-                         PrdBaseAddr,\r
+                         (VOID*)(UINTN)BaseAddr,\r
                          &ByteCount,\r
-                         &PrdTableMapAddr,\r
+                         &BaseMapAddr,\r
                          &PrdTableMap\r
                          );\r
-    if (EFI_ERROR (Status) || (ByteCount != EFI_PAGES_TO_SIZE (PageCount))) {\r
+    if (EFI_ERROR (Status) || (ByteCount != EFI_PAGES_TO_SIZE (RealPageCount))) {\r
       //\r
       // If the data length actually mapped is not equal to the requested amount,\r
       // it means the DMA operation may be broken into several discontinuous smaller chunks.\r
       // Can't handle this case.\r
       //\r
-      PciIo->FreeBuffer (PciIo, PageCount, PrdBaseAddr);\r
+      PciIo->FreeBuffer (PciIo, RealPageCount, (VOID*)(UINTN)BaseAddr);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    ZeroMem ((VOID *) ((UINTN) PrdBaseAddr), ByteCount);\r
+    ZeroMem ((VOID *) ((UINTN) BaseAddr), ByteCount);\r
+\r
+    //\r
+    // Calculate the 64K align address as PRD Table base address.\r
+    //\r
+    AlignmentMask    = SIZE_64KB - 1;\r
+    PrdTableBaseAddr = ((UINTN) BaseAddr + AlignmentMask) & ~AlignmentMask;\r
+    PrdTableMapAddr  = ((UINTN) BaseMapAddr + AlignmentMask) & ~AlignmentMask;\r
 \r
     //\r
     // Map the host address of DataBuffer to DMA master address.\r
@@ -1596,7 +1701,7 @@ AtaUdmaInOut (
                          );\r
     if (EFI_ERROR (Status) || (ByteCount != DataLength)) {\r
       PciIo->Unmap (PciIo, PrdTableMap);\r
-      PciIo->FreeBuffer (PciIo, PageCount, PrdBaseAddr);\r
+      PciIo->FreeBuffer (PciIo, RealPageCount, (VOID*)(UINTN)BaseAddr);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -1610,7 +1715,7 @@ AtaUdmaInOut (
     // Fill the PRD table with appropriate bus master address of data buffer and data length.\r
     //\r
     ByteRemaining   = ByteCount;\r
-    TempPrdBaseAddr = PrdBaseAddr;\r
+    TempPrdBaseAddr = (EFI_ATA_DMA_PRD*)(UINTN)PrdTableBaseAddr;\r
     while (ByteRemaining != 0) {\r
       if (ByteRemaining <= 0x10000) {\r
         TempPrdBaseAddr->RegionBaseAddr = (UINT32) ((UINTN) BufferMapAddress);\r
@@ -1663,6 +1768,14 @@ AtaUdmaInOut (
     }\r
     IdeWritePortB (PciIo, IoPortForBmic, RegisterValue);\r
 \r
+    if (Task != NULL) {\r
+      Task->Map            = BufferMap;\r
+      Task->TableMap       = PrdTableMap;\r
+      Task->MapBaseAddress = (EFI_ATA_DMA_PRD*)(UINTN)BaseAddr;\r
+      Task->PageCount      = RealPageCount;\r
+      Task->IsStart        = TRUE;\r
+    }\r
+\r
     //\r
     // Issue ATA command\r
     //\r
@@ -1685,31 +1798,15 @@ AtaUdmaInOut (
     RegisterValue |= BMIC_START;\r
     IdeWritePortB(PciIo, IoPortForBmic, RegisterValue);\r
 \r
-    if (Task != NULL) {\r
-      //\r
-      // Max transfer number of sectors for one command is 65536(32Mbyte),\r
-      // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps).\r
-      // So set the variable Count to 2000, for about 2 second Timeout time.\r
-      //\r
-      Task->RetryTimes     = 2000;\r
-      Task->Map            = BufferMap;\r
-      Task->TableMap       = PrdTableMap;\r
-      Task->MapBaseAddress = PrdBaseAddr;\r
-      Task->PageCount      = PageCount;\r
-      Task->IsStart        = TRUE;\r
-    }\r
   }\r
 \r
   //\r
   // Check the INTERRUPT and ERROR bit of BMIS\r
-  // Max transfer number of sectors for one command is 65536(32Mbyte),\r
-  // it will cost 1 second to transfer these data in UDMA mode 2(33.3MBps).\r
-  // So set the variable Count to 2000, for about 2 second Timeout time.\r
   //\r
   if (Task != NULL) {\r
     Status = AtaUdmStatusCheck (PciIo, Task, IdeRegisters);\r
   } else {\r
-    Status = AtaUdmStatusWait (PciIo, IdeRegisters);\r
+    Status = AtaUdmStatusWait (PciIo, IdeRegisters, Timeout);\r
   }\r
 \r
   //\r
@@ -1762,7 +1859,7 @@ Exit:
       PciIo->Unmap (PciIo, Task->Map);\r
     } else {\r
       PciIo->Unmap (PciIo, PrdTableMap);\r
-      PciIo->FreeBuffer (PciIo, PageCount, PrdBaseAddr);\r
+      PciIo->FreeBuffer (PciIo, RealPageCount, (VOID*)(UINTN)BaseAddr);\r
       PciIo->Unmap (PciIo, BufferMap);\r
     }\r
 \r
@@ -1771,7 +1868,7 @@ Exit:
     //\r
     DumpAllIdeRegisters (PciIo, IdeRegisters, AtaStatusBlock);\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -1805,8 +1902,8 @@ AtaPacketReadPendingData (
     while ((TempWordBuffer & (ATA_STSREG_BSY | ATA_STSREG_DRQ)) == ATA_STSREG_DRQ) {\r
       IdeReadPortWMultiple (\r
         PciIo,\r
-        IdeRegisters->Data, \r
-        1, \r
+        IdeRegisters->Data,\r
+        1,\r
         &TempWordBuffer\r
         );\r
       TempWordBuffer = IdeReadPortB (PciIo, IdeRegisters->AltOrDev);\r
@@ -1816,7 +1913,7 @@ AtaPacketReadPendingData (
 }\r
 \r
 /**\r
-  This function is called by AtaPacketCommandExecute(). \r
+  This function is called by AtaPacketCommandExecute().\r
   It is used to transfer data between host and device. The data direction is specified\r
   by the fourth parameter.\r
 \r
@@ -1856,7 +1953,7 @@ AtaPacketReadWrite (
   if (ByteCount == 0) {\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   PtrBuffer         = Buffer;\r
   RequiredWordCount = (UINT32)RShiftU64(ByteCount, 1);\r
   //\r
@@ -1871,7 +1968,7 @@ AtaPacketReadWrite (
     //\r
     Status = DRQReady2 (PciIo, IdeRegisters, Timeout);\r
     if (EFI_ERROR (Status)) {\r
-      return CheckStatusRegister (PciIo, IdeRegisters);\r
+      return Status;\r
     }\r
 \r
     //\r
@@ -1911,7 +2008,7 @@ AtaPacketReadWrite (
     PtrBuffer       += WordCount;\r
     ActualWordCount += WordCount;\r
   }\r
-  \r
+\r
   if (Read) {\r
     //\r
     // In the case where the drive wants to send more data than we need to read,\r
@@ -1936,62 +2033,12 @@ AtaPacketReadWrite (
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
-  \r
-  return Status;\r
-}\r
-\r
-/**\r
-  Sumbit ATAPI request sense command.\r
-\r
-  @param[in] PciIo           Pointer to the EFI_PCI_IO_PROTOCOL instance\r
-  @param[in] IdeRegisters    Pointer to EFI_IDE_REGISTERS which is used to\r
-                             store the IDE i/o port registers' base addresses\r
-  @param[in] Channel         The channel number of device.\r
-  @param[in] Device          The device number of device.\r
-  @param[in] SenseData       A pointer to store sense data.\r
-  @param[in] SenseDataLength The sense data length.\r
-  @param[in] Timeout         The timeout value to execute this cmd, uses 100ns as a unit.\r
-\r
-  @retval EFI_SUCCESS        Send out the ATAPI packet command successfully.\r
-  @retval EFI_DEVICE_ERROR   The device failed to send data.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtaPacketRequestSense (\r
-  IN  EFI_PCI_IO_PROTOCOL               *PciIo,\r
-  IN  EFI_IDE_REGISTERS                 *IdeRegisters,\r
-  IN  UINT8                             Channel,\r
-  IN  UINT8                             Device,\r
-  IN  VOID                              *SenseData,\r
-  IN  UINT8                             SenseDataLength,\r
-  IN  UINT64                            Timeout\r
-  )\r
-{\r
-  EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  Packet;\r
-  UINT8                                       Cdb[12];\r
-  EFI_STATUS                                  Status;\r
-\r
-  ZeroMem (&Packet, sizeof (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 12);\r
-\r
-  Cdb[0] = ATA_CMD_REQUEST_SENSE;\r
-  Cdb[4] = SenseDataLength;\r
-\r
-  Packet.Timeout          = Timeout;\r
-  Packet.Cdb              = Cdb;\r
-  Packet.CdbLength        = 12;\r
-  Packet.DataDirection    = EFI_EXT_SCSI_DATA_DIRECTION_READ;\r
-  Packet.InDataBuffer     = SenseData;\r
-  Packet.InTransferLength = SenseDataLength;\r
-\r
-  Status = AtaPacketCommandExecute (PciIo, IdeRegisters, Channel, Device, &Packet);\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
-  This function is used to send out ATAPI commands conforms to the Packet Command \r
+  This function is used to send out ATAPI commands conforms to the Packet Command\r
   with PIO Data In Protocol.\r
 \r
   @param[in] PciIo          Pointer to the EFI_PCI_IO_PROTOCOL instance\r
@@ -2016,7 +2063,6 @@ AtaPacketCommandExecute (
   IN  EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET    *Packet\r
   )\r
 {\r
-  EFI_STATUS                  PacketCommandStatus;\r
   EFI_ATA_COMMAND_BLOCK       AtaCommandBlock;\r
   EFI_STATUS                  Status;\r
   UINT8                       Count;\r
@@ -2071,7 +2117,7 @@ AtaPacketCommandExecute (
   // Send out ATAPI command packet\r
   //\r
   for (Count = 0; Count < 6; Count++) {\r
-    IdeWritePortW (PciIo, IdeRegisters->Data, *((UINT16*)PacketCommand + Count)); \r
+    IdeWritePortW (PciIo, IdeRegisters->Data, *((UINT16*)PacketCommand + Count));\r
     //\r
     // Stall for 10 microseconds.\r
     //\r
@@ -2082,56 +2128,26 @@ AtaPacketCommandExecute (
   // Read/Write the data of ATAPI Command\r
   //\r
   if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ) {\r
-    PacketCommandStatus = AtaPacketReadWrite (\r
-                            PciIo,\r
-                            IdeRegisters,\r
-                            Packet->InDataBuffer,\r
-                            Packet->InTransferLength,\r
-                            TRUE,\r
-                            Packet->Timeout\r
-                            );\r
+    Status = AtaPacketReadWrite (\r
+               PciIo,\r
+               IdeRegisters,\r
+               Packet->InDataBuffer,\r
+               Packet->InTransferLength,\r
+               TRUE,\r
+               Packet->Timeout\r
+               );\r
   } else {\r
-    PacketCommandStatus = AtaPacketReadWrite (\r
-                            PciIo,\r
-                            IdeRegisters,\r
-                            Packet->OutDataBuffer,\r
-                            Packet->OutTransferLength,\r
-                            FALSE,\r
-                            Packet->Timeout\r
-                            );\r
+    Status = AtaPacketReadWrite (\r
+               PciIo,\r
+               IdeRegisters,\r
+               Packet->OutDataBuffer,\r
+               Packet->OutTransferLength,\r
+               FALSE,\r
+               Packet->Timeout\r
+               );\r
   }\r
 \r
-  if (!EFI_ERROR (PacketCommandStatus)) {\r
-    return PacketCommandStatus;\r
-  }\r
-\r
-  //\r
-  // Return SenseData if PacketCommandStatus matches\r
-  // the following return codes.\r
-  //\r
-  if ((PacketCommandStatus == EFI_BAD_BUFFER_SIZE) ||\r
-      (PacketCommandStatus == EFI_DEVICE_ERROR) ||\r
-      (PacketCommandStatus == EFI_TIMEOUT)) {\r
-\r
-    //\r
-    // avoid submit request sense command continuously.\r
-    //\r
-    if ((Packet->SenseData == NULL) || (((UINT8 *)Packet->Cdb)[0] == ATA_CMD_REQUEST_SENSE)) {\r
-      return PacketCommandStatus;\r
-    }\r
-\r
-    AtaPacketRequestSense (\r
-      PciIo,\r
-      IdeRegisters,\r
-      Channel,\r
-      Device,\r
-      Packet->SenseData,\r
-      Packet->SenseDataLength,\r
-      Packet->Timeout\r
-      );\r
-  }\r
-\r
-  return PacketCommandStatus;\r
+  return Status;\r
 }\r
 \r
 \r
@@ -2212,7 +2228,7 @@ SetDriveParameters (
   EFI_ATA_COMMAND_BLOCK   AtaCommandBlock;\r
 \r
   ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK));\r
\r
+\r
   AtaCommandBlock.AtaCommand     = ATA_CMD_INIT_DRIVE_PARAM;\r
   AtaCommandBlock.AtaSectorCount = DriveParameters->Sector;\r
   AtaCommandBlock.AtaDeviceHead  = (UINT8) ((Device << 0x4) + DriveParameters->Heads);\r
@@ -2225,7 +2241,7 @@ SetDriveParameters (
              &Instance->IdeRegisters[Channel],\r
              &AtaCommandBlock,\r
              AtaStatusBlock,\r
-             ATA_ATAPI_TIMEOUT, \r
+             ATA_ATAPI_TIMEOUT,\r
              NULL\r
              );\r
 \r
@@ -2241,7 +2257,7 @@ SetDriveParameters (
              &Instance->IdeRegisters[Channel],\r
              &AtaCommandBlock,\r
              AtaStatusBlock,\r
-             ATA_ATAPI_TIMEOUT, \r
+             ATA_ATAPI_TIMEOUT,\r
              NULL\r
              );\r
 \r
@@ -2295,9 +2311,18 @@ IdeAtaSmartReturnStatusCheck (
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLED)\r
+      );\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_ENABLE)\r
+    );\r
+\r
   LBAMid  = IdeReadPortB (Instance->PciIo, Instance->IdeRegisters[Channel].CylinderLsb);\r
   LBAHigh = IdeReadPortB (Instance->PciIo, Instance->IdeRegisters[Channel].CylinderMsb);\r
 \r
@@ -2306,12 +2331,19 @@ IdeAtaSmartReturnStatusCheck (
     // The threshold exceeded condition is not detected by the device\r
     //\r
     DEBUG ((EFI_D_INFO, "The S.M.A.R.T threshold exceeded condition is not detected\n"));\r
-\r
+    REPORT_STATUS_CODE (\r
+          EFI_PROGRESS_CODE,\r
+          (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_UNDERTHRESHOLD)\r
+          );\r
   } else if ((LBAMid == 0xf4) && (LBAHigh == 0x2c)) {\r
     //\r
     // The threshold exceeded condition is detected by the device\r
     //\r
     DEBUG ((EFI_D_INFO, "The S.M.A.R.T threshold exceeded condition is detected\n"));\r
+    REPORT_STATUS_CODE (\r
+         EFI_PROGRESS_CODE,\r
+         (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_OVERTHRESHOLD)\r
+         );\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2347,14 +2379,23 @@ IdeAtaSmartSupport (
     //\r
     // S.M.A.R.T is not supported by the device\r
     //\r
-    DEBUG ((EFI_D_INFO, "S.M.A.R.T feature is not supported at [%a] channel [%a] device!\n", \r
+    DEBUG ((EFI_D_INFO, "S.M.A.R.T feature is not supported at [%a] channel [%a] device!\n",\r
             (Channel == 1) ? "secondary" : "primary", (Device == 1) ? "slave" : "master"));\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_NOTSUPPORTED)\r
+      );\r
   } else {\r
     //\r
     // Check if the feature is enabled. If not, then enable S.M.A.R.T.\r
     //\r
     if ((IdentifyData->AtaData.command_set_feature_enb_85 & 0x0001) != 0x0001) {\r
 \r
+      REPORT_STATUS_CODE (\r
+        EFI_PROGRESS_CODE,\r
+        (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_ATA_BUS_SMART_DISABLE)\r
+        );\r
+\r
       ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK));\r
 \r
       AtaCommandBlock.AtaCommand      = ATA_CMD_SMART;\r
@@ -2407,7 +2448,7 @@ IdeAtaSmartSupport (
       }\r
     }\r
 \r
-    DEBUG ((EFI_D_INFO, "Enabled S.M.A.R.T feature at [%a] channel [%a] device!\n", \r
+    DEBUG ((EFI_D_INFO, "Enabled S.M.A.R.T feature at [%a] channel [%a] device!\n",\r
            (Channel == 1) ? "secondary" : "primary", (Device == 1) ? "slave" : "master"));\r
 \r
   }\r
@@ -2478,19 +2519,19 @@ AtaIdentify (
   to fill in the Media data structure of the Block I/O Protocol interface.\r
 \r
   There are 5 steps to reach such objective:\r
-  1. Sends out the ATAPI Identify Command to the specified device. \r
+  1. Sends out the ATAPI Identify Command to the specified device.\r
   Only ATAPI device responses to this command. If the command succeeds,\r
-  it returns the Identify data structure which filled with information \r
-  about the device. Since the ATAPI device contains removable media, \r
+  it returns the Identify data structure which filled with information\r
+  about the device. Since the ATAPI device contains removable media,\r
   the only meaningful information is the device module name.\r
   2. Sends out ATAPI Inquiry Packet Command to the specified device.\r
   This command will return inquiry data of the device, which contains\r
   the device type information.\r
   3. Allocate sense data space for future use. We don't detect the media\r
-  presence here to improvement boot performance, especially when CD \r
+  presence here to improvement boot performance, especially when CD\r
   media is present. The media detection will be performed just before\r
   each BLK_IO read/write\r
-  \r
+\r
   @param Instance         A pointer to ATA_ATAPI_PASS_THRU_INSTANCE data structure.\r
   @param Channel          The channel number of device.\r
   @param Device           The device number of device.\r
@@ -2517,7 +2558,7 @@ AtaIdentifyPacket (
   EFI_ATA_COMMAND_BLOCK  AtaCommandBlock;\r
 \r
   ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK));\r
-  \r
+\r
   AtaCommandBlock.AtaCommand    = ATA_CMD_IDENTIFY_DEVICE;\r
   AtaCommandBlock.AtaDeviceHead = (UINT8)(Device << 0x4);\r
 \r
@@ -2591,12 +2632,17 @@ DetectAndConfigIdeDevice (
   PciIo        = Instance->PciIo;\r
 \r
   for (IdeDevice = 0; IdeDevice < EfiIdeMaxDevice; IdeDevice++) {\r
+    //\r
+    // Select Master or Slave device to get the return signature for ATA DEVICE DIAGNOSTIC cmd.\r
+    //\r
+    IdeWritePortB (PciIo, IdeRegisters->Head, (UINT8)((IdeDevice << 4) | 0xe0));\r
+\r
     //\r
     // Send ATA Device Execut Diagnostic command.\r
     // This command should work no matter DRDY is ready or not\r
     //\r
     IdeWritePortB (PciIo, IdeRegisters->CmdOrStatus, ATA_CMD_EXEC_DRIVE_DIAG);\r
-  \r
+\r
     Status = WaitForBSYClear (PciIo, IdeRegisters, 350000000);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG((EFI_D_ERROR, "New detecting method: Send Execute Diagnostic Command: WaitForBSYClear: Status: %d\n", Status));\r
@@ -2660,13 +2706,13 @@ DetectAndConfigIdeDevice (
       continue;\r
     }\r
 \r
-    DEBUG ((EFI_D_INFO, "[%a] channel [%a] [%a] device\n", \r
+    DEBUG ((EFI_D_INFO, "[%a] channel [%a] [%a] device\n",\r
             (IdeChannel == 1) ? "secondary" : "primary  ", (IdeDevice == 1) ? "slave " : "master",\r
             DeviceType == EfiIdeCdrom ? "cdrom   " : "harddisk"));\r
     //\r
     // If the device is a hard disk, then try to enable S.M.A.R.T feature\r
     //\r
-    if (DeviceType == EfiIdeHarddisk) {\r
+    if ((DeviceType == EfiIdeHarddisk) && PcdGetBool (PcdAtaSmartEnable)) {\r
       IdeAtaSmartSupport (\r
         Instance,\r
         IdeChannel,\r
@@ -2781,9 +2827,9 @@ DetectAndConfigIdeDevice (
 \r
 /**\r
   Initialize ATA host controller at IDE mode.\r
-  \r
-  The function is designed to initialize ATA host controller. \r
-  \r
+\r
+  The function is designed to initialize ATA host controller.\r
+\r
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
 \r
 **/\r