]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
Change BlockIo drivers to return EFI_NO_MEDIA or EFI_MEDIA_CHANGED even the Buffer...
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaBusDxe / AtaPassThruExecute.c
index d2a918271262b53e27699b320c5c837646c9e71e..acfbd743943ae9829b6d3d2f132d41ecba99ff8e 100644 (file)
@@ -5,8 +5,8 @@
   It transforms the high level identity, read/write, reset command to ATA pass\r
   through command and protocol. \r
     \r
-  Copyright (c) 2009 Intel Corporation. <BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2009 - 2010, 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
@@ -164,7 +164,7 @@ PrintAtaModelName (
   CHAR8   *Source;\r
   CHAR16  *Destination;\r
 \r
-  Source = AtaDevice->IdentifyData->AtaData.ModelName;\r
+  Source = AtaDevice->IdentifyData->ModelName;\r
   Destination = AtaDevice->ModelName;\r
 \r
   //\r
@@ -198,10 +198,10 @@ GetAtapi6Capacity (
   EFI_LBA                       Capacity;\r
   EFI_LBA                       TmpLba;\r
   UINTN                         Index;\r
-  ATAPI_IDENTIFY_DATA           *IdentifyData;\r
+  ATA_IDENTIFY_DATA             *IdentifyData;\r
 \r
-  IdentifyData = (ATAPI_IDENTIFY_DATA *) AtaDevice->IdentifyData;\r
-  if ((IdentifyData->cmd_set_support_83 & BIT10) == 0) {\r
+  IdentifyData = AtaDevice->IdentifyData;\r
+  if ((IdentifyData->command_set_supported_83 & BIT10) == 0) {\r
     //\r
     // The device doesn't support 48 bit addressing\r
     //\r
@@ -216,7 +216,7 @@ GetAtapi6Capacity (
     //\r
     // Lower byte goes first: word[100] is the lowest word, word[103] is highest\r
     //\r
-    TmpLba = IdentifyData->max_user_lba_for_48bit_addr[Index];\r
+    TmpLba = IdentifyData->maximum_lba_for_48bit_addressing[Index];\r
     Capacity |= LShiftU64 (TmpLba, 16 * Index);\r
   }\r
 \r
@@ -242,13 +242,13 @@ IdentifyAtaDevice (
   IN OUT ATA_DEVICE                 *AtaDevice\r
   )\r
 {\r
-  EFI_ATA_IDENTIFY_DATA             *IdentifyData;\r
+  ATA_IDENTIFY_DATA                 *IdentifyData;\r
   EFI_BLOCK_IO_MEDIA                *BlockMedia;\r
   EFI_LBA                           Capacity;\r
   UINT16                            PhyLogicSectorSupport;\r
   UINT16                            UdmaMode;\r
 \r
-  IdentifyData = &AtaDevice->IdentifyData->AtaData;\r
+  IdentifyData = AtaDevice->IdentifyData;\r
 \r
   if ((IdentifyData->config & BIT15) != 0) {\r
     //\r
@@ -289,6 +289,7 @@ IdentifyAtaDevice (
   //\r
   BlockMedia = &AtaDevice->BlockMedia;\r
   BlockMedia->LastBlock = Capacity - 1;\r
+  BlockMedia->IoAlign = AtaDevice->AtaBusDriverData->AtaPassThru->Mode->IoAlign;\r
   //\r
   // Check whether Long Physical Sector Feature is supported\r
   //\r
@@ -303,7 +304,8 @@ IdentifyAtaDevice (
       // Check lowest alignment of logical blocks within physical block\r
       //\r
       if ((IdentifyData->alignment_logic_in_phy_blocks & (BIT14 | BIT15)) == BIT14) {\r
-        BlockMedia->LowestAlignedLba = (EFI_LBA) (IdentifyData->alignment_logic_in_phy_blocks & 0x3fff);\r
+        BlockMedia->LowestAlignedLba = (EFI_LBA) ((BlockMedia->LogicalBlocksPerPhysicalBlock - ((UINT32)IdentifyData->alignment_logic_in_phy_blocks & 0x3fff)) %\r
+          BlockMedia->LogicalBlocksPerPhysicalBlock);\r
       }\r
     }\r
     //\r
@@ -352,6 +354,7 @@ DiscoverAtaDevice (
   //\r
   Acb = ZeroMem (&AtaDevice->Acb, sizeof (*Acb));\r
   Acb->AtaCommand = ATA_CMD_IDENTIFY_DRIVE;\r
+  Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4)); \r
 \r
   //\r
   // Prepare for ATA pass through packet.\r
@@ -408,6 +411,12 @@ TransferAtaDevice (
   EFI_ATA_COMMAND_BLOCK             *Acb;\r
   EFI_ATA_PASS_THRU_COMMAND_PACKET  *Packet;\r
 \r
+  //\r
+  // Ensure AtaDevice->UdmaValid, AtaDevice->Lba48Bit and IsWrite are valid boolean values \r
+  //\r
+  ASSERT ((UINTN) AtaDevice->UdmaValid < 2);\r
+  ASSERT ((UINTN) AtaDevice->Lba48Bit < 2);\r
+  ASSERT ((UINTN) IsWrite < 2);\r
   //\r
   // Prepare for ATA command block.\r
   //\r
@@ -417,15 +426,15 @@ TransferAtaDevice (
   Acb->AtaCylinderLow = (UINT8) RShiftU64 (StartLba, 8);\r
   Acb->AtaCylinderHigh = (UINT8) RShiftU64 (StartLba, 16);\r
   Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4)); \r
+  Acb->AtaSectorCount = (UINT8) TransferLength;\r
   if (AtaDevice->Lba48Bit) {\r
     Acb->AtaSectorNumberExp = (UINT8) RShiftU64 (StartLba, 24);\r
+    Acb->AtaCylinderLowExp = (UINT8) RShiftU64 (StartLba, 32);\r
+    Acb->AtaCylinderHighExp = (UINT8) RShiftU64 (StartLba, 40);\r
+    Acb->AtaSectorCountExp = (UINT8) (TransferLength >> 8);\r
   } else {\r
     Acb->AtaDeviceHead = (UINT8) (Acb->AtaDeviceHead | RShiftU64 (StartLba, 24));\r
   }\r
-  Acb->AtaCylinderLowExp = (UINT8) RShiftU64 (StartLba, 32);\r
-  Acb->AtaCylinderHighExp = (UINT8) RShiftU64 (StartLba, 40);\r
-  Acb->AtaSectorCount = (UINT8) TransferLength;\r
-  Acb->AtaSectorCountExp = (UINT8) (TransferLength >> 8);\r
 \r
   //\r
   // Prepare for ATA pass through packet.\r
@@ -475,6 +484,10 @@ AccessAtaDevice(
   UINTN                             TransferBlockNumber;\r
   UINTN                             BlockSize;\r
  \r
+  //\r
+  // Ensure AtaDevice->Lba48Bit is a valid boolean value \r
+  //\r
+  ASSERT ((UINTN) AtaDevice->Lba48Bit < 2);\r
   MaxTransferBlockNumber = mMaxTransferBlockNumber[AtaDevice->Lba48Bit];\r
   BlockSize = AtaDevice->BlockMedia.BlockSize;\r
   do {\r