From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=chasel.chiu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 01D9C207DF2AD for ; Sun, 3 Jun 2018 20:51:43 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jun 2018 20:51:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,475,1520924400"; d="scan'208";a="47036066" Received: from pgsmsx104.gar.corp.intel.com ([10.221.44.91]) by orsmga006.jf.intel.com with ESMTP; 03 Jun 2018 20:51:42 -0700 Received: from pgsmsx111.gar.corp.intel.com ([169.254.2.7]) by PGSMSX104.gar.corp.intel.com ([169.254.3.168]) with mapi id 14.03.0319.002; Mon, 4 Jun 2018 11:51:41 +0800 From: "Chiu, Chasel" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Wu, Hao A" Thread-Topic: [PATCH 1/4] MdeModulePkg/AtaAtapiPassThru: Spin up Power up in Standby devices Thread-Index: AQHT+Wry/hs+MxSpxEuaPBBcF0Xm6qRPe9Hg Date: Mon, 4 Jun 2018 03:51:41 +0000 Message-ID: <3C3EFB470A303B4AB093197B6777CCEC500DEB98@PGSMSX111.gar.corp.intel.com> References: <20180601053921.34724-1-ruiyu.ni@intel.com> <20180601053921.34724-2-ruiyu.ni@intel.com> In-Reply-To: <20180601053921.34724-2-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiY2YzZjI3MjgtNzA4Yy00N2UwLTg4NTItZTc5OTQ0NzQ3OTZhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiU3JnQldTRUhqaDNvaFwvTUpOZnBzM0pVUzBOdWtsSG9GdTgzNXJFd3dpdTF2U1hZMWxJb0pLMG9CTlNQYjUxSkcifQ== x-ctpclassification: CTP_NT x-originating-ip: [172.30.20.205] MIME-Version: 1.0 Subject: Re: [PATCH 1/4] MdeModulePkg/AtaAtapiPassThru: Spin up Power up in Standby devices X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jun 2018 03:51:44 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Chasel Chiu -----Original Message----- From: Ni, Ruiyu=20 Sent: Friday, June 1, 2018 1:39 PM To: edk2-devel@lists.01.org Cc: Chiu, Chasel ; Wu, Hao A Subject: [PATCH 1/4] MdeModulePkg/AtaAtapiPassThru: Spin up Power up in Sta= ndby devices The patch adds support to certain devices that support PUIS (Power up in St= andby). For those devices that supports SET_FEATURE spin up, SW needs to send SET_F= EATURE subcommand to spin up the devices. For those devices that doesn't support SET_FEATURE spin up, SW needs to sen= d read sectors command to spin up the devices. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Chasel Chiu Cc: Hao A Wu --- MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c | 129 +++++++++++++++++= +++- .../Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h | 3 +- 2 files changed, 127 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePk= g/Bus/Ata/AtaAtapiPassThru/AhciMode.c index e6de5d65bc..6ab7870570 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c @@ -1,7 +1,7 @@ /** @file The file for AHCI mode of ATA host controller. =20 - Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights=20 + reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -1841,7 +1841,8 @@ AhciDeviceSetFeature ( IN UINT8 Port, IN UINT8 PortMultiplier, IN UINT16 Feature, - IN UINT32 FeatureSpecificData + IN UINT32 FeatureSpecificData, + IN UINT64 Timeout ) { EFI_STATUS Status; @@ -1868,7 +1869,7 @@ AhciDeviceSetFeature ( 0, &AtaCommandBlock, &AtaStatusBlock, - ATA_ATAPI_TIMEOUT, + Timeout, NULL ); =20 @@ -2216,6 +2217,104 @@ Error6: return Status; } =20 + +/** + Spin-up disk if IDD was incomplete or PUIS feature is enabled + + @param PciIo The PCI IO protocol instance. + @param AhciRegisters The pointer to the EFI_AHCI_REGISTERS. + @param Port The number of port. + @param PortMultiplier The multiplier of port. + @param IdentifyData A pointer to data buffer which is used to co= ntain IDENTIFY data. + +**/ +EFI_STATUS +AhciSpinUpDisk ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN EFI_AHCI_REGISTERS *AhciRegisters, + IN UINT8 Port, + IN UINT8 PortMultiplier, + IN OUT EFI_IDENTIFY_DATA *IdentifyData + ) +{ + EFI_STATUS Status; + EFI_ATA_COMMAND_BLOCK AtaCommandBlock; + EFI_ATA_STATUS_BLOCK AtaStatusBlock; + UINT8 Buffer[512]; + + if (IdentifyData->AtaData.specific_config =3D=3D ATA_SPINUP_CFG_REQUIRED= _IDD_INCOMPLETE) { + // + // Use SET_FEATURE subcommand to spin up the device. + // + Status =3D AhciDeviceSetFeature ( + PciIo, AhciRegisters, Port, PortMultiplier, + ATA_SUB_CMD_PUIS_SET_DEVICE_SPINUP, 0x00, ATA_SPINUP_TIMEOU= T + ); + DEBUG ((DEBUG_INFO, "CMD_PUIS_SET_DEVICE_SPINUP for device at port [%d= ] PortMultiplier [%d] - %r!\n", + Port, PortMultiplier, Status)); + if (EFI_ERROR (Status)) { + return Status; + } + } else { + ASSERT (IdentifyData->AtaData.specific_config =3D=3D=20 + ATA_SPINUP_CFG_NOT_REQUIRED_IDD_INCOMPLETE); + + // + // Use READ_SECTORS to spin up the device if SpinUp SET FEATURE subcom= mand is not supported + // + ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK)); + ZeroMem (&AtaStatusBlock, sizeof (EFI_ATA_STATUS_BLOCK)); + // + // Perform READ SECTORS PIO Data-In command to Read LBA 0 + // + AtaCommandBlock.AtaCommand =3D ATA_CMD_READ_SECTORS; + AtaCommandBlock.AtaSectorCount =3D 0x1; + + Status =3D AhciPioTransfer ( + PciIo, + AhciRegisters, + Port, + PortMultiplier, + NULL, + 0, + TRUE, + &AtaCommandBlock, + &AtaStatusBlock, + &Buffer, + sizeof (Buffer), + ATA_SPINUP_TIMEOUT, + NULL + ); + DEBUG ((DEBUG_INFO, "Read LBA 0 for device at port [%d] PortMultiplier= [%d] - %r!\n", + Port, PortMultiplier, Status)); + if (EFI_ERROR (Status)) { + return Status; + } + } + + // + // Read the complete IDENTIFY DEVICE data. + // + ZeroMem (IdentifyData, sizeof (*IdentifyData)); Status =3D=20 + AhciIdentify (PciIo, AhciRegisters, Port, PortMultiplier,=20 + IdentifyData); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Read IDD failed for device at port [%d] PortMult= iplier [%d] - %r!\n", + Port, PortMultiplier, Status)); + return Status; + } + + DEBUG ((DEBUG_INFO, "IDENTIFY DEVICE: [0] =3D %016x, [2] =3D %016x, [83]= =3D %016x, [86] =3D %016x\n", + IdentifyData->AtaData.config, IdentifyData->AtaData.specific_con= fig, + IdentifyData->AtaData.command_set_supported_83,=20 + IdentifyData->AtaData.command_set_feature_enb_86)); + // + // Check if IDD is incomplete + // + if ((IdentifyData->AtaData.config & BIT2) !=3D 0) { + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + /** Initialize ATA host controller at AHCI mode. =20 @@ -2458,6 +2557,28 @@ AhciModeInitialization ( continue; } =20 + DEBUG (( + DEBUG_INFO, "IDENTIFY DEVICE: [0] =3D %016x, [2] =3D %016x, [83]= =3D %016x, [86] =3D %016x\n", + Buffer.AtaData.config, Buffer.AtaData.specific_config, + Buffer.AtaData.command_set_supported_83, Buffer.AtaData.command_= set_feature_enb_86 + )); + if ((Buffer.AtaData.config & BIT2) !=3D 0) { + // + // SpinUp disk if device reported incomplete IDENTIFY DEVICE. + // + Status =3D AhciSpinUpDisk ( + PciIo, + AhciRegisters, + Port, + 0, + &Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Spin up standby device failed - %r\n", S= tatus)); + continue; + } + } + DeviceType =3D EfiIdeHarddisk; } else { continue; @@ -2523,7 +2644,7 @@ AhciModeInitialization ( TransferMode.ModeNumber =3D (UINT8) SupportedModes->MultiWordDmaMo= de.Mode; } =20 - Status =3D AhciDeviceSetFeature (PciIo, AhciRegisters, Port, 0, 0x03= , (UINT32)(*(UINT8 *)&TransferMode)); + Status =3D AhciDeviceSetFeature (PciIo, AhciRegisters, Port, 0,=20 + 0x03, (UINT32)(*(UINT8 *)&TransferMode), ATA_ATAPI_TIMEOUT); //=20 + RPPO-SKL-TBD if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Set transfer Mode Fail, Status =3D %r\n", St= atus)); continue; diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h b/Mde= ModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h index 85e5a55539..31b005f2f6 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h @@ -1,7 +1,7 @@ /** @file Header file for ATA/ATAPI PASS THRU driver. =20 - Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights=20 + reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -148,6 +148,7 @@ struct _ATA_NONBLOCK_TASK { // It means 3 s= econd span. // #define ATA_ATAPI_TIMEOUT EFI_TIMER_PERIOD_SECONDS(3) +#define ATA_SPINUP_TIMEOUT EFI_TIMER_PERIOD_SECONDS(10) =20 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) =3D=3D = 0) =20 -- 2.16.1.windows.1