]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
MdeModulePkg Ata: Use the new (incompatible) PortMultiplierPort semantics
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaAtapiPassThru / AtaAtapiPassThru.c
index 870900f1060db9310d4008e4bf1e1efae89dd341..2389d54926e7b8a9244d8b2796967abf0c6fc53b 100644 (file)
@@ -2,7 +2,7 @@
   This file implements ATA_PASSTHRU_PROCTOCOL and EXT_SCSI_PASSTHRU_PROTOCOL interfaces\r
   for managed ATA controllers.\r
 \r
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2016, 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
@@ -148,7 +148,7 @@ UINT8 mScsiId[TARGET_MAX_BYTES] = {
 \r
   @param[in]      Port               The port number of the ATA device to send the command.\r
   @param[in]      PortMultiplierPort The port multiplier port number of the ATA device to send the command.\r
-                                     If there is no port multiplier, then specify 0.\r
+                                     If there is no port multiplier, then specify 0xFFFF.\r
   @param[in, out] Packet             A pointer to the ATA command to send to the ATA device specified by Port\r
                                      and PortMultiplierPort.\r
   @param[in]      Instance           Pointer to the ATA_ATAPI_PASS_THRU_INSTANCE.\r
@@ -272,6 +272,14 @@ AtaPassThruPassThruExecute (
       }\r
       break;\r
     case EfiAtaAhciMode :\r
+      if (PortMultiplierPort == 0xFFFF) {\r
+        //\r
+        // If there is no port multiplier, PortMultiplierPort will be 0xFFFF\r
+        // according to UEFI spec. Here, we convert its value to 0 to follow\r
+        // AHCI spec.\r
+        //\r
+        PortMultiplierPort = 0;\r
+      }\r
       switch (Protocol) {\r
         case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:\r
           Status = AhciNonDataTransfer (\r
@@ -982,7 +990,7 @@ AtaAtapiPassThruStop (
   @param[in]  Instance            A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
   @param[in]  Port                The port number of the ATA device to send the command.\r
   @param[in]  PortMultiplierPort  The port multiplier port number of the ATA device to send the command.\r
-                                  If there is no port multiplier, then specify 0.\r
+                                  If there is no port multiplier, then specify 0xFFFF.\r
   @param[in]  DeviceType          The device type of the ATA device.\r
 \r
   @retval     The pointer to the data structure of the device info to access.\r
@@ -1004,6 +1012,18 @@ SearchDeviceInfoList (
   while (!IsNull (&Instance->DeviceList, Node)) {\r
     DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
 \r
+    //\r
+    // For CD-ROM working in the AHCI mode, only 8 bits are used to record\r
+    // the PortMultiplier information. If the CD-ROM is directly attached\r
+    // on a SATA port, the PortMultiplier should be translated from 0xFF\r
+    // to 0xFFFF according to the UEFI spec.\r
+    //\r
+    if ((Instance->Mode == EfiAtaAhciMode) &&\r
+        (DeviceInfo->Type == EfiIdeCdrom) &&\r
+        (PortMultiplier == 0xFF)) {\r
+        PortMultiplier = 0xFFFF;\r
+    }\r
+\r
     if ((DeviceInfo->Type == DeviceType) &&\r
         (Port == DeviceInfo->Port) &&\r
         (PortMultiplier == DeviceInfo->PortMultiplier)) {\r
@@ -1023,7 +1043,7 @@ SearchDeviceInfoList (
   @param[in]  Instance            A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
   @param[in]  Port                The port number of the ATA device to send the command.\r
   @param[in]  PortMultiplierPort  The port multiplier port number of the ATA device to send the command.\r
-                                  If there is no port multiplier, then specify 0.\r
+                                  If there is no port multiplier, then specify 0xFFFF.\r
   @param[in]  DeviceType          The device type of the ATA device.\r
   @param[in]  IdentifyData        The data buffer to store the output of the IDENTIFY cmd.\r
 \r
@@ -1216,7 +1236,7 @@ Done:
   @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.\r
   @param[in]      Port               The port number of the ATA device to send the command.\r
   @param[in]      PortMultiplierPort The port multiplier port number of the ATA device to send the command.\r
-                                     If there is no port multiplier, then specify 0.\r
+                                     If there is no port multiplier, then specify 0xFFFF.\r
   @param[in, out] Packet             A pointer to the ATA command to send to the ATA device specified by Port\r
                                      and PortMultiplierPort.\r
   @param[in]      Event               If non-blocking I/O is not supported then Event is ignored, and blocking\r
@@ -1531,17 +1551,25 @@ AtaPassThruGetNextDevice (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (*PortMultiplierPort == 0xFFFF) {\r
+  if (Instance->PreviousPortMultiplier == 0xFFFF) {\r
     //\r
-    // If the PortMultiplierPort is all 0xFF's, start to traverse the device list from the beginning\r
+    // If a device is directly attached on a port, previous call to this\r
+    // function will return the value 0xFFFF for PortMultiplierPort. In\r
+    // this case, there should be no more device on the port multiplier.\r
     //\r
+    Instance->PreviousPortMultiplier = 0;\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  if (*PortMultiplierPort == Instance->PreviousPortMultiplier) {\r
     Node = GetFirstNode (&Instance->DeviceList);\r
 \r
     while (!IsNull (&Instance->DeviceList, Node)) {\r
       DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
 \r
       if ((DeviceInfo->Type == EfiIdeHarddisk) &&\r
-           (DeviceInfo->Port == Port)){\r
+           (DeviceInfo->Port == Port) &&\r
+           (DeviceInfo->PortMultiplier > *PortMultiplierPort)){\r
         *PortMultiplierPort = DeviceInfo->PortMultiplier;\r
         goto Exit;\r
       }\r
@@ -1550,15 +1578,17 @@ AtaPassThruGetNextDevice (
     }\r
 \r
     return EFI_NOT_FOUND;\r
-  } else if (*PortMultiplierPort == Instance->PreviousPortMultiplier) {\r
+  } else if (*PortMultiplierPort == 0xFFFF) {\r
+    //\r
+    // If the PortMultiplierPort is all 0xFF's, start to traverse the device list from the beginning\r
+    //\r
     Node = GetFirstNode (&Instance->DeviceList);\r
 \r
     while (!IsNull (&Instance->DeviceList, Node)) {\r
       DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
 \r
       if ((DeviceInfo->Type == EfiIdeHarddisk) &&\r
-           (DeviceInfo->Port == Port) &&\r
-           (DeviceInfo->PortMultiplier > *PortMultiplierPort)){\r
+           (DeviceInfo->Port == Port)){\r
         *PortMultiplierPort = DeviceInfo->PortMultiplier;\r
         goto Exit;\r
       }\r
@@ -1601,7 +1631,7 @@ Exit:
                                      device path node is to be allocated and built.\r
   @param[in]      PortMultiplierPort The port multiplier port number of the ATA device for which a\r
                                      device path node is to be allocated and built. If there is no\r
-                                     port multiplier, then specify 0.\r
+                                     port multiplier, then specify 0xFFFF.\r
   @param[in, out] DevicePath         A pointer to a single device path node that describes the ATA\r
                                      device specified by Port and PortMultiplierPort. This function\r
                                      is responsible for allocating the buffer DevicePath with the\r
@@ -1812,7 +1842,7 @@ AtaPassThruResetPort (
   @param[in] This                A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.\r
   @param[in] Port                Port represents the port number of the ATA device to be reset.\r
   @param[in] PortMultiplierPort  The port multiplier port number of the ATA device to reset.\r
-                                 If there is no port multiplier, then specify 0.\r
+                                 If there is no port multiplier, then specify 0xFFFF.\r
   @retval EFI_SUCCESS            The ATA device specified by Port and PortMultiplierPort was reset.\r
   @retval EFI_UNSUPPORTED        The ATA controller does not support a device reset operation.\r
   @retval EFI_INVALID_PARAMETER  Port or PortMultiplierPort are invalid.\r
@@ -2049,6 +2079,13 @@ ExtScsiPassThruPassThru (
       Status = AtaPacketCommandExecute (Instance->PciIo, &Instance->IdeRegisters[Port], Port, PortMultiplier, Packet);\r
       break;\r
     case EfiAtaAhciMode:\r
+      if (PortMultiplier == 0xFF) {\r
+        //\r
+        // If there is no port multiplier, the PortMultiplier will be 0xFF\r
+        // Here, we convert its value to 0 to follow the AHCI spec.\r
+        //\r
+        PortMultiplier = 0;\r
+      }\r
       Status = AhciPacketCommandExecute (Instance->PciIo, &Instance->AhciRegisters, Port, PortMultiplier, Packet);\r
       break;\r
     default :\r
@@ -2186,7 +2223,7 @@ ExtScsiPassThruGetNextTargetLun (
       if ((DeviceInfo->Type == EfiIdeCdrom) &&\r
          ((Target8[0] < DeviceInfo->Port) ||\r
           ((Target8[0] == DeviceInfo->Port) &&\r
-           (Target8[1] < DeviceInfo->PortMultiplier)))) {\r
+           (Target8[1] < (UINT8)DeviceInfo->PortMultiplier)))) {\r
         Target8[0] = (UINT8)DeviceInfo->Port;\r
         Target8[1] = (UINT8)DeviceInfo->PortMultiplier;\r
         goto Exit;\r
@@ -2308,7 +2345,13 @@ ExtScsiPassThruBuildDevicePath (
     }\r
 \r
     DevicePathNode->Sata.HBAPortNumber            = Port;\r
-    DevicePathNode->Sata.PortMultiplierPortNumber = PortMultiplier;\r
+    //\r
+    // For CD-ROM working in the AHCI mode, only 8 bits are used to record\r
+    // the PortMultiplier information. If the CD-ROM is directly attached\r
+    // on a SATA port, the PortMultiplier should be translated from 0xFF\r
+    // to 0xFFFF according to the UEFI spec.\r
+    //\r
+    DevicePathNode->Sata.PortMultiplierPortNumber = PortMultiplier == 0xFF ? 0xFFFF : PortMultiplier;\r
     DevicePathNode->Sata.Lun                      = (UINT16) Lun;\r
   }\r
 \r
@@ -2562,7 +2605,7 @@ ExtScsiPassThruGetNextTarget (
       if ((DeviceInfo->Type == EfiIdeCdrom) &&\r
          ((Target8[0] < DeviceInfo->Port) ||\r
           ((Target8[0] == DeviceInfo->Port) &&\r
-           (Target8[1] < DeviceInfo->PortMultiplier)))) {\r
+           (Target8[1] < (UINT8)DeviceInfo->PortMultiplier)))) {\r
         Target8[0] = (UINT8)DeviceInfo->Port;\r
         Target8[1] = (UINT8)DeviceInfo->PortMultiplier;\r
         goto Exit;\r