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.115; helo=mga14.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 C5FF4208AE379 for ; Sun, 31 Mar 2019 23:53:24 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Mar 2019 23:53:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,295,1549958400"; d="scan'208";a="145492891" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by FMSMGA003.fm.intel.com with ESMTP; 31 Mar 2019 23:53:24 -0700 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 31 Mar 2019 23:53:24 -0700 Received: from shsmsx154.ccr.corp.intel.com (10.239.6.54) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 31 Mar 2019 23:53:23 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.92]) by SHSMSX154.ccr.corp.intel.com ([169.254.7.149]) with mapi id 14.03.0415.000; Mon, 1 Apr 2019 14:53:21 +0800 From: "Wu, Hao A" To: "Albecki, Mateusz" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH 3/3] MdeModulePkg/UfsPassThruDxe: Add UFS info protocol Thread-Index: AQHU5W4RTm/r+LRx+EqLhxrOxnMTvaYiS15g Date: Mon, 1 Apr 2019 06:53:20 +0000 Message-ID: References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 3/3] MdeModulePkg/UfsPassThruDxe: Add UFS info protocol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Apr 2019 06:53:25 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello Mateusz, A couple of general comments: A. I suggest to break this commit into 2 patches: The first one will just introduce the new protocol. The second one will update the UfsPassThruDxe driver to consume this new protocol. B. There has been a Bugzilla tracker for the feature you add in this patch: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1343 Could you help to add this information in the commit log message? Thanks. C. I prefer the new protocol to have platform level singleton instance: I do not see much value for a platform to produce multiple instances of this protocol, I think the additional UIC commands needed during the UFS HC initialization for a specific platform is deterministic. Also, the selection of protocol instance implemented in function GetUfsHcInfoProtocol() is by: 1) LocateHandleBuffer() to get all protocol instances; 2) Choose the 1st instance if the 'Supported' service returns without error. I think this will bring some kind of confusion to the protocol producers, since they do not know which one will be selected when there are multiple instances of the protocol. > -----Original Message----- > From: Albecki, Mateusz > Sent: Thursday, March 28, 2019 9:56 PM > To: edk2-devel@lists.01.org > Cc: Albecki, Mateusz; Wu, Hao A > Subject: [PATCH 3/3] MdeModulePkg/UfsPassThruDxe: Add UFS info protocol >=20 > UFS host controller specification allows for implementation specific > UIC programming to take place just after host controller enable and befor= e > device detection. Since there is no way for generic driver to anticipate > implementation specific programming we add a UFS info protocol > which allows the implementation specific code to pass this information > to generic driver. UFS info protocol is located by the driver at the > BindingStart call and the supported instance is retained throught entire throught -> through > driver lifetime. Presence of the protocol is optional. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Cc: Hao Wu > Signed-off-by: Albecki Mateusz > --- > MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c | 62 > ++++++++++++++++++ > MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h | 2 + > .../Bus/Ufs/UfsPassThruDxe/UfsPassThruDxe.inf | 1 + > .../Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 60 ++++++++++++++++= + > .../Include/Protocol/UfsHostControllerInfo.h | 75 > ++++++++++++++++++++++ > MdeModulePkg/MdeModulePkg.dec | 3 + > 6 files changed, 203 insertions(+) > create mode 100644 MdeModulePkg/Include/Protocol/UfsHostControllerInfo.h >=20 > diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > index ea329618dc..a41079e311 100644 > --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > @@ -40,6 +40,7 @@ UFS_PASS_THRU_PRIVATE_DATA gUfsPassThruTemplate > =3D { > UfsRwUfsAttribute > }, > 0, // UfsHostController > + NULL, // UfsInfo > 0, // UfsHcBase > 0, // Capabilities > 0, // TaskTag > @@ -776,6 +777,66 @@ UfsFinishDeviceInitialization ( > return EFI_SUCCESS; > } >=20 > +/** > + Locates UFS HC infor protocol suitable for this controller. infor -> info > + > + @param[in] DriverBinding Pointer to driver binding protocol > + @param[in] Private Pointer to host controller private data > + @param[in] ControllerHandle Controller to which driver is bound > +**/ > +VOID > +GetUfsHcInfoProtocol ( > + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, > + IN UFS_PASS_THRU_PRIVATE_DATA *Private, > + IN EFI_HANDLE ControllerHandle > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE *ProtocolHandleArray; > + UINTN NoHandles; > + UINTN HandleIndex; > + UFS_HC_INFO_PROTOCOL *UfsHcInfo; > + > + Status =3D gBS->LocateHandleBuffer ( > + ByProtocol, > + &gUfsHcInfoProtocolGuid, > + NULL, > + &NoHandles, > + &ProtocolHandleArray > + ); > + if (EFI_ERROR (Status)) { > + return; > + } > + > + for (HandleIndex =3D 0; HandleIndex < NoHandles; HandleIndex++) { > + Status =3D gBS->OpenProtocol ( > + ProtocolHandleArray[HandleIndex], > + &gUfsHcInfoProtocolGuid, > + &UfsHcInfo, > + DriverBinding->DriverBindingHandle, > + ControllerHandle, > + EFI_OPEN_PROTOCOL_BY_DRIVER > + ); > + if (EFI_ERROR (Status)) { > + continue; > + } > + if (!EFI_ERROR(UfsHcInfo->Supported (UfsHcInfo, ControllerHandle))) = { > + Private->UfsHcInfo =3D UfsHcInfo; > + break; > + } else { > + Status =3D gBS->CloseProtocol ( > + ProtocolHandleArray[HandleIndex], > + &gUfsHcInfoProtocolGuid, > + DriverBinding->DriverBindingHandle, > + ControllerHandle > + ); > + ASSERT_EFI_ERROR (Status); > + } > + } > + > + FreePool (ProtocolHandleArray); > +} > + > /** > Starts a device controller or a bus controller. >=20 > @@ -871,6 +932,7 @@ UfsPassThruDriverBindingStart ( > Private->UfsHostController =3D UfsHc; > Private->UfsHcBase =3D UfsHcBase; > InitializeListHead (&Private->Queue); > + GetUfsHcInfoProtocol (This, Private, Controller); >=20 > // > // Initialize UFS Host Controller H/W. > diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h > b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h > index e591e78661..55a8ed9bdf 100644 > --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h > +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h > @@ -29,6 +29,7 @@ > #include > #include > #include > +#include A minor comment here: You can put the above '#include' together with other protocol header files rather than appending it after the libraries includes. >=20 > #include "UfsPassThruHci.h" >=20 > @@ -66,6 +67,7 @@ typedef struct _UFS_PASS_THRU_PRIVATE_DATA { > EFI_EXT_SCSI_PASS_THRU_PROTOCOL ExtScsiPassThru; > EFI_UFS_DEVICE_CONFIG_PROTOCOL UfsDevConfig; > EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHostController; > + UFS_HC_INFO_PROTOCOL *UfsHcInfo; > UINTN UfsHcBase; > UINT32 Capabilities; >=20 > diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruDxe.inf > b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruDxe.inf > index e550cd02b4..12b01771ff 100644 > --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruDxe.inf > +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruDxe.inf > @@ -59,6 +59,7 @@ > gEfiExtScsiPassThruProtocolGuid ## BY_START > gEfiUfsDeviceConfigProtocolGuid ## BY_START > gEdkiiUfsHostControllerProtocolGuid ## TO_START > + gUfsHcInfoProtocolGuid gUfsHcInfoProtocolGuid -> gUfsHcInfoProtocolGuid ## SOMETIMES_CONSUMES >=20 > [UserExtensions.TianoCore."ExtraFiles"] > UfsPassThruExtra.uni > diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > index c37161c4ae..125f2f2516 100644 > --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > @@ -2068,6 +2068,61 @@ UfsInitTransferRequestList ( > return EFI_SUCCESS; > } >=20 > +/** > + Performs additional UIC programming if it has been specified by platfo= rm in > UFS info protocol. > + > + @param[in] Private Pointer to host controller private data > + > + @retval EFI_SUCCESS Programming finished successfully or not requeste= d > + @retval others Programming failed > +**/ > +EFI_STATUS > +UfsProgramAdditionalUicAttributes ( > + IN UFS_PASS_THRU_PRIVATE_DATA *Private > + ) > +{ > + EFI_STATUS Status; > + UIC_ATTRIBUTE *UicAttrArray; > + UINTN NoAttributes; > + UINTN AttributeIndex; > + > + // > + // No info protocol means that no additional programming should be > performed > + // > + if (Private->UfsHcInfo =3D=3D NULL) { > + return EFI_SUCCESS; > + } > + > + // > + // If we failed to get the programming table we assume that platform > doesn't want to do any additional programming > + // > + Status =3D Private->UfsHcInfo->GetUicProgrammingTable (Private->UfsHcI= nfo, > &UicAttrArray, &NoAttributes); > + if (EFI_ERROR (Status)) { > + return EFI_SUCCESS; > + } Please help to free the content pointed by 'UicAttrArray'. > + > + for (AttributeIndex =3D 0; AttributeIndex < NoAttributes; AttributeInd= ex++) { > + DEBUG ((DEBUG_ERROR, "Programing UIC attribute =3D %d, selector inde= x DEBUG_INFO should be enough. > =3D %d, set type =3D %d, value =3D %d\n", > + UicAttrArray[AttributeIndex].MibAttribute, > UicAttrArray[AttributeIndex].GenSelectorIndex, > + UicAttrArray[AttributeIndex].AttrSetType, > UicAttrArray[AttributeIndex].AttributeValue)); > + Status =3D UfsExecUicCommands ( > + Private, > + UfsUicDmeSet, > + (UicAttrArray[AttributeIndex].MibAttribute << 16) | > (UicAttrArray[AttributeIndex].GenSelectorIndex), > + UicAttrArray[AttributeIndex].AttrSetType << 16, > + UicAttrArray[AttributeIndex].AttributeValue > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to program UIC attribute =3D %d, sele= ctor > index =3D %d, set type =3D %d, value =3D %d\n", > + UicAttrArray[AttributeIndex].MibAttribute, > UicAttrArray[AttributeIndex].GenSelectorIndex, > + UicAttrArray[AttributeIndex].AttrSetType, > UicAttrArray[AttributeIndex].AttributeValue)); > + return Status; > + } > + } > + > + return EFI_SUCCESS; > +} > + > /** > Initialize the UFS host controller. >=20 > @@ -2090,6 +2145,11 @@ UfsControllerInit ( > return Status; > } >=20 > + Status =3D UfsProgramAdditionalUicAttributes (Private); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "UfsControllerInit: Failed to perform additiona= l > UIC programming\n")); > + } > + > Status =3D UfsDeviceDetection (Private); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "UfsControllerInit: Device Detection Fails, Sta= tus > =3D %r\n", Status)); > diff --git a/MdeModulePkg/Include/Protocol/UfsHostControllerInfo.h > b/MdeModulePkg/Include/Protocol/UfsHostControllerInfo.h > new file mode 100644 > index 0000000000..c730127482 > --- /dev/null > +++ b/MdeModulePkg/Include/Protocol/UfsHostControllerInfo.h > @@ -0,0 +1,75 @@ > +/** @file > + > + Universal Flash Storage Host Controller info Protocol. > + > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> +This program and the accompanying materials are licensed and made > available under > +the terms and conditions of the BSD License that accompanies this distri= bution. > +The full text of the license may be found at > +http://opensource.org/licenses/bsd-license.php. > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS > OR IMPLIED. > + > +**/ > + > +#ifndef __UFS_HC_INFO_PROTOCOL_H__ > +#define __UFS_HC_INFO_PROTOCOL_H__ > + > +#define UFS_HC_INFO_PROTOCOL_VERSION 1 > + > +extern EFI_GUID gUfsHcInfoProtocolGuid; I suggest to rename gUfsHcInfoProtocolGuid to: gEdkiiUfsHcInfoProtocolGuid which I think is a common naming convention for non UEFI spec protocols within MdeModulePkg. > + > +typedef struct _UFS_HC_INFO_PROTOCOL UFS_HC_INFO_PROTOCOL; > + > +typedef struct { > + UINT16 MibAttribute; > + UINT16 GenSelectorIndex; > + UINT8 AttrSetType; > + UINT32 AttributeValue; > +} UIC_ATTRIBUTE; > + > +/** > + Checks if this instance of the info protocol supports > + given host controller. > + > + @param[in] This Pointer to this instance of > UFS_HC_INFO_PROTOCOL > + @param[in] ControllerHandle Controller to check > + > + @retval EFI_SUCCESS This instance of info protocol supports given con= troller > + @retval others This instance of info protocol doesn't support gi= ven > controller > +**/ > +typedef > +EFI_STATUS > +(*UFS_INFO_CONTROLLER_SUPPORTED) ( > + IN UFS_HC_INFO_PROTOCOL *This, > + IN EFI_HANDLE ControllerHandle > + ); > + > +/** > + Get the UIC programming table to be used just after host controller > + enabling and before device detection. > + > + @param[in] This Pointer to this instance of > UFS_HC_INFO_PROTOCOL > + @param[in] UicAttributeArray Out variable for address of the table > + @param[in] NoAttributes Out variable for number of attributes in= the > array '@param[out]' for UicAttributeArray & NoAttributes. Also, for 'UicAttributeArray', I think the content pointed by this pointer is allocated by the protocol producer and should be freed by the consumer after being used, right? If so, please help to refine the description comments for 'UicAttributeArray'. > + > + @retval EFI_SUCCESS Table successfully found and returned > + @retval others Table wasn't located successfully UIC programming > shouldn't be performed. > +**/ > +typedef > +EFI_STATUS > +(*UFS_INFO_GET_UIC_PROGRAMMING_TABLE) ( > + IN UFS_HC_INFO_PROTOCOL *This, > + OUT UIC_ATTRIBUTE **UicAttributeArray, > + OUT UINTN *NoAttributes > + ); Judging from the usage of this service in function UfsProgramAdditionalUicAttributes(), I think there is an assumption that platforms will only require additional 'DME_SET' UIC commands. I am not sure if we need to make this service a bit more general. So how about changing the 'UIC_ATTRIBUTE' structure to: typedef struct { UINT8 UicOpcode; UINT32 Arg1; UINT32 Arg2; UINT32 Arg3; } UIC_COMMAND; and update the service to: typedef EFI_STATUS (*UFS_INFO_GET_UIC_PROGRAMMING_TABLE) ( IN UFS_HC_INFO_PROTOCOL *This, OUT UIC_COMMAND **UicCommandArray, OUT UINTN *NoCommand ); > + > +struct _UFS_HC_INFO_PROTOCOL { > + UINT32 Version; > + UFS_INFO_CONTROLLER_SUPPORTED Supported; If there will be only one protocol instance within system, do you think we can drop the above 'Supported' service? Best Regards, Hao Wu > + UFS_INFO_GET_UIC_PROGRAMMING_TABLE GetUicProgrammingTable; > +}; > + > +#endif > + > diff --git a/MdeModulePkg/MdeModulePkg.dec > b/MdeModulePkg/MdeModulePkg.dec > index a2130bc439..c6be8f12a4 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -581,6 +581,9 @@ > ## Include/Protocol/UfsHostController.h > gEdkiiUfsHostControllerProtocolGuid =3D { 0xebc01af5, 0x7a9, 0x489e, {= 0xb7, > 0xce, 0xdc, 0x8, 0x9e, 0x45, 0x9b, 0x2f } } >=20 > + ## Include/Protocol/UfsHostControllerInfo.h > + gUfsHcInfoProtocolGuid =3D { 0x3d18ba13, 0xd9b1, 0x4dd4, {0xb9, 0x16, = 0xd3, > 0x07, 0x96, 0x53, 0x9e, 0xd8}} > + > ## Include/Protocol/EsrtManagement.h > gEsrtManagementProtocolGuid =3D { 0xa340c064, 0x723c, 0x4a9c, = { 0xa4, > 0xdd, 0xd5, 0xb4, 0x7a, 0x26, 0xfb, 0xb0 }} >=20 > -- > 2.14.1.windows.1