]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/AtaAtapiPassThru: enable/disable PUIS per policy
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 29 May 2018 05:08:21 +0000 (13:08 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 8 Jun 2018 09:46:45 +0000 (17:46 +0800)
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf

index 14578c0f948a6a0da44ce5c6a159fdd3b8012411..841b6a0e60634ab11dc3634088b39f1ad02532fc 100644 (file)
@@ -2316,6 +2316,38 @@ AhciSpinUpDisk (
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Enable/disable/skip PUIS of the disk according to policy.\r
+\r
+  @param  PciIo               The PCI IO protocol instance.\r
+  @param  AhciRegisters       The pointer to the EFI_AHCI_REGISTERS.\r
+  @param  Port                The number of port.\r
+  @param  PortMultiplier      The multiplier of port.\r
+\r
+**/\r
+EFI_STATUS\r
+AhciPuisEnable (\r
+  IN EFI_PCI_IO_PROTOCOL           *PciIo,\r
+  IN EFI_AHCI_REGISTERS            *AhciRegisters,\r
+  IN UINT8                         Port,\r
+  IN UINT8                         PortMultiplier\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+  if (mAtaAtapiPolicy->PuisEnable == 0) {\r
+    Status = AhciDeviceSetFeature (PciIo, AhciRegisters, Port, PortMultiplier, ATA_SUB_CMD_DISABLE_PUIS, 0x00, ATA_ATAPI_TIMEOUT);\r
+  } else if (mAtaAtapiPolicy->PuisEnable == 1) {\r
+    Status = AhciDeviceSetFeature (PciIo, AhciRegisters, Port, PortMultiplier, ATA_SUB_CMD_ENABLE_PUIS, 0x00, ATA_ATAPI_TIMEOUT);\r
+  }\r
+  DEBUG ((DEBUG_INFO, "%a PUIS feature at port [%d] PortMultiplier [%d] - %r!\n",\r
+    (mAtaAtapiPolicy->PuisEnable == 0) ? "Disable" : (\r
+    (mAtaAtapiPolicy->PuisEnable == 1) ? "Enable" : "Skip"\r
+      ), Port, PortMultiplier, Status));\r
+  return Status;\r
+}\r
+\r
 /**\r
   Initialize ATA host controller at AHCI mode.\r
 \r
 /**\r
   Initialize ATA host controller at AHCI mode.\r
 \r
@@ -2658,6 +2690,22 @@ AhciModeInitialization (
       if (DeviceType == EfiIdeHarddisk) {\r
         REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_PC_ENABLE));\r
       }\r
       if (DeviceType == EfiIdeHarddisk) {\r
         REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_PERIPHERAL_FIXED_MEDIA | EFI_P_PC_ENABLE));\r
       }\r
+\r
+      //\r
+      // Enable/disable PUIS according to policy setting if PUIS is capable (Word[83].BIT5 is set).\r
+      //\r
+      if ((Buffer.AtaData.command_set_supported_83 & BIT5) != 0) {\r
+        Status = AhciPuisEnable (\r
+                   PciIo,\r
+                   AhciRegisters,\r
+                   Port,\r
+                   0\r
+                   );\r
+        if (EFI_ERROR (Status)) {\r
+          DEBUG ((DEBUG_ERROR, "PUIS enable/disable failed, Status = %r\n", Status));\r
+          continue;\r
+        }\r
+      }\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
index a48b295d26aad4182641887eac68d5f74ebb1d3b..aab704bcd3796cff4ec9fb3069863ac205fe3dcd 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
   This file implements ATA_PASSTHRU_PROCTOCOL and EXT_SCSI_PASSTHRU_PROTOCOL interfaces\r
   for managed ATA controllers.\r
 \r
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2018, 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
   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
@@ -142,6 +142,15 @@ UINT8 mScsiId[TARGET_MAX_BYTES] = {
   0xFF, 0xFF, 0xFF, 0xFF\r
 };\r
 \r
   0xFF, 0xFF, 0xFF, 0xFF\r
 };\r
 \r
+EDKII_ATA_ATAPI_POLICY_PROTOCOL *mAtaAtapiPolicy;\r
+EDKII_ATA_ATAPI_POLICY_PROTOCOL mDefaultAtaAtapiPolicy = {\r
+  EDKII_ATA_ATAPI_POLICY_VERSION,\r
+  2,  // PuisEnable\r
+  0,  // DeviceSleepEnable\r
+  0,  // AggressiveDeviceSleepEnable\r
+  0   // Reserved\r
+};\r
+\r
 /**\r
   Sends an ATA command to an ATA device that is attached to the ATA controller. This function\r
   supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,\r
 /**\r
   Sends an ATA command to an ATA device that is attached to the ATA controller. This function\r
   supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,\r
@@ -739,6 +748,14 @@ AtaAtapiPassThruStart (
     goto ErrorExit;\r
   }\r
 \r
     goto ErrorExit;\r
   }\r
 \r
+  Status = gBS->LocateProtocol (&gEdkiiAtaAtapiPolicyProtocolGuid, NULL, (VOID **)&mAtaAtapiPolicy);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If there is no AtaAtapiPolicy exposed, use the default policy.\r
+    //\r
+    mAtaAtapiPolicy = &mDefaultAtaAtapiPolicy;\r
+  }\r
+\r
   //\r
   // Allocate a buffer to store the ATA_ATAPI_PASS_THRU_INSTANCE data structure\r
   //\r
   //\r
   // Allocate a buffer to store the ATA_ATAPI_PASS_THRU_INSTANCE data structure\r
   //\r
index 31b005f2f6abf69347a77565783dbc0bd21d4514..b07bcbbb3ec88b7c912376037ce27308b29ebfd6 100644 (file)
@@ -24,6 +24,7 @@
 #include <Protocol/IdeControllerInit.h>\r
 #include <Protocol/AtaPassThru.h>\r
 #include <Protocol/ScsiPassThruExt.h>\r
 #include <Protocol/IdeControllerInit.h>\r
 #include <Protocol/AtaPassThru.h>\r
 #include <Protocol/ScsiPassThruExt.h>\r
+#include <Protocol/AtaAtapiPolicy.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
 \r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
@@ -45,6 +46,8 @@ extern EFI_DRIVER_BINDING_PROTOCOL  gAtaAtapiPassThruDriverBinding;
 extern EFI_COMPONENT_NAME_PROTOCOL  gAtaAtapiPassThruComponentName;\r
 extern EFI_COMPONENT_NAME2_PROTOCOL gAtaAtapiPassThruComponentName2;\r
 \r
 extern EFI_COMPONENT_NAME_PROTOCOL  gAtaAtapiPassThruComponentName;\r
 extern EFI_COMPONENT_NAME2_PROTOCOL gAtaAtapiPassThruComponentName2;\r
 \r
+extern EDKII_ATA_ATAPI_POLICY_PROTOCOL *mAtaAtapiPolicy;\r
+\r
 #define ATA_ATAPI_PASS_THRU_SIGNATURE  SIGNATURE_32 ('a', 'a', 'p', 't')\r
 #define ATA_ATAPI_DEVICE_SIGNATURE     SIGNATURE_32 ('a', 'd', 'e', 'v')\r
 #define ATA_NONBLOCKING_TASK_SIGNATURE  SIGNATURE_32 ('a', 't', 's', 'k')\r
 #define ATA_ATAPI_PASS_THRU_SIGNATURE  SIGNATURE_32 ('a', 'a', 'p', 't')\r
 #define ATA_ATAPI_DEVICE_SIGNATURE     SIGNATURE_32 ('a', 'd', 'e', 'v')\r
 #define ATA_NONBLOCKING_TASK_SIGNATURE  SIGNATURE_32 ('a', 't', 's', 'k')\r
index 82d5f7a46ce8662345e40fdc536df782b3ffe698..d1ce859091018df9c8876f662be50f2bda8b8e25 100644 (file)
@@ -4,7 +4,7 @@
 #  This driver installs AtaPassThru and ExtScsiPassThru protocol in each ide/sata controller\r
 #  to access to all attached Ata/Atapi devices.\r
 #\r
 #  This driver installs AtaPassThru and ExtScsiPassThru protocol in each ide/sata controller\r
 #  to access to all attached Ata/Atapi devices.\r
 #\r
-#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -67,6 +67,7 @@
   gEfiIdeControllerInitProtocolGuid             ## TO_START\r
   gEfiDevicePathProtocolGuid                    ## TO_START\r
   gEfiPciIoProtocolGuid                         ## TO_START\r
   gEfiIdeControllerInitProtocolGuid             ## TO_START\r
   gEfiDevicePathProtocolGuid                    ## TO_START\r
   gEfiPciIoProtocolGuid                         ## TO_START\r
+  gEdkiiAtaAtapiPolicyProtocolGuid              ## CONSUMES\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdAtaSmartEnable   ## SOMETIMES_CONSUMES\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdAtaSmartEnable   ## SOMETIMES_CONSUMES\r