From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0729.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe44::729]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6A02580293 for ; Fri, 10 Mar 2017 02:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HPEnterprise.onmicrosoft.com; s=selector1-hpe-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=1JOZvukueH92kDjFbrPke7TPnJTA7I/++7L8z2LQTys=; b=AhBGj1D9COrzyrg2uiCWUwnFn2M7WN2Gj3WWKZrq4Jds3A3dENQWTyhOhI+iPysD98ra52V4NvKgv+Loj8OpJ+2V0U7qiPgpCiGP6jOQ406xUBh2R7UUh2fB500TVXKQxIgJgSBA0peOp+Gqx7feAyRl8dyQ5B0HzdFqxMC8ENY= Received: from CS1PR84MB0295.NAMPRD84.PROD.OUTLOOK.COM (10.162.190.26) by CS1PR84MB0293.NAMPRD84.PROD.OUTLOOK.COM (10.162.190.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Fri, 10 Mar 2017 10:11:12 +0000 Received: from CS1PR84MB0295.NAMPRD84.PROD.OUTLOOK.COM ([10.162.190.26]) by CS1PR84MB0295.NAMPRD84.PROD.OUTLOOK.COM ([10.162.190.26]) with mapi id 15.01.0947.020; Fri, 10 Mar 2017 10:11:11 +0000 From: "Wang, Sunny (HPS SW)" To: Ruiyu Ni , "edk2-devel@lists.01.org" CC: Feng Tian , "Wang, Sunny (HPS SW)" , "Haskell, Darrell" Thread-Topic: [edk2] [PATCH] MdeModulePkg/UefiBootManagerLib: Generate boot description for NVME Thread-Index: AQHSmXQPOBciSHJjX0aVkV1k68xFnqGN1qzQ Date: Fri, 10 Mar 2017 10:11:11 +0000 Message-ID: References: <20170310075759.79780-1-ruiyu.ni@intel.com> In-Reply-To: <20170310075759.79780-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=hpe.com; x-originating-ip: [15.211.131.8] x-microsoft-exchange-diagnostics: 1; CS1PR84MB0293; 7:jt0ng38QitbAjctxWcPQqO+z+niA6T8GyIs6U5ht7km3AYQJ5MzBUkx5ML5GvK/7yEIRfc4u/32HhGxtQQHtE+8VfXbM7mMb9WOgGiC2Mx16wpVNFHdsKvrldBklagy0qQtpvycpyRxXvms6KIQtQ5+oVHFjQ0l5K4Uk7TIzlwPIcNPhIj5dG18alQgqNoacJGUP5JMz4MQBKTQnoV811PAKL8H04qGQgfTd1pponY4YOp/ycw6eZK9gDYan4xuV9TJVxHwwLpJQ7iAHm0iP0bLKbS9gaDeiNB//ibZdxit8llWcshmb00Ow/tgCQzUz7hFxPWILcPk3ttBtnHSl7Q== x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10019020)(6009001)(39860400002)(39410400002)(39850400002)(39840400002)(39450400003)(377454003)(13464003)(40224003)(74316002)(38730400002)(2501003)(81166006)(189998001)(3660700001)(53936002)(7736002)(305945005)(4326008)(76176999)(54356999)(2950100002)(6246003)(53546006)(8676002)(33656002)(86362001)(50986999)(575784001)(122556002)(8936002)(9686003)(2900100001)(55016002)(106116001)(6116002)(6306002)(2906002)(5660300001)(3846002)(6436002)(3280700002)(77096006)(102836003)(66066001)(54906002)(6506006)(7696004)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:CS1PR84MB0293; H:CS1PR84MB0295.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; x-ms-office365-filtering-correlation-id: b6c07e0d-b40c-4a5e-8a6c-08d4679dc75b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CS1PR84MB0293; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123558025)(20161123564025)(20161123555025)(20161123562025)(20161123560025)(6072148); SRVR:CS1PR84MB0293; BCL:0; PCL:0; RULEID:; SRVR:CS1PR84MB0293; x-forefront-prvs: 02426D11FE spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Mar 2017 10:11:11.5774 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0293 Subject: Re: [PATCH] MdeModulePkg/UefiBootManagerLib: Generate boot description for NVME X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Mar 2017 10:11:16 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Ray, Just a question out of curiosity. Why don't we use UefiNvmExpressLib's NvmE= xpressIdentify() for sending ADMIN_IDENTIFY command to NVME controller?=20 Others look good to me.=20 Regards, Sunny Wang -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiy= u Ni Sent: Friday, March 10, 2017 3:58 PM To: edk2-devel@lists.01.org Cc: Feng Tian Subject: [edk2] [PATCH] MdeModulePkg/UefiBootManagerLib: Generate boot desc= ription for NVME Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Feng Tian --- .../Library/UefiBootManagerLib/BmBootDescription.c | 104 +++++++++++++++++= +++- .../Library/UefiBootManagerLib/InternalBm.h | 4 +- .../UefiBootManagerLib/UefiBootManagerLib.inf | 1 + 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c b/= MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c index 050647d..501a0cc 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c @@ -1,7 +1,7 @@ /** @file Library functions which relate with boot option description. =20 -Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This pro= gram and the accompanying materials are licensed and made available under = the terms and conditions of the BSD License @@ -501,6 +501,107 @@ BmGetLoad= FileDescription ( } =20 /** + Return the boot description for NVME boot device. + + @param Handle Controller handle. + + @return The description string. +**/ +CHAR16 * +BmGetNvmeDescription ( + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *NvmePassthru; + EFI_DEV_PATH_PTR DevicePath; + EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET CommandPacket; + EFI_NVM_EXPRESS_COMMAND Command; + EFI_NVM_EXPRESS_COMPLETION Completion; + NVME_ADMIN_CONTROLLER_DATA ControllerData; + CHAR16 *Description; + CHAR16 *Char; + UINTN Index; + + Status =3D gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid,=20 + (VOID **) &DevicePath.DevPath); if (EFI_ERROR (Status)) { + return NULL; + } + + Status =3D gBS->LocateDevicePath (&gEfiNvmExpressPassThruProtocolGuid,=20 + &DevicePath.DevPath, &Handle); if (EFI_ERROR (Status) || + (DevicePathType (DevicePath.DevPath) !=3D MESSAGING_DEVICE_PATH) || + (DevicePathSubType (DevicePath.DevPath) !=3D MSG_NVME_NAMESPACE_DP))= { + // + // Do not return description when the Handle is not a child of NVME co= ntroller. + // + return NULL; + } + + // + // Send ADMIN_IDENTIFY command to NVME controller to get the model and s= erial number. + // + Status =3D gBS->HandleProtocol (Handle,=20 + &gEfiNvmExpressPassThruProtocolGuid, (VOID **) &NvmePassthru); =20 + ASSERT_EFI_ERROR (Status); + + ZeroMem (&CommandPacket,=20 + sizeof(EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET)); + ZeroMem (&Command, sizeof(EFI_NVM_EXPRESS_COMMAND)); ZeroMem=20 + (&Completion, sizeof(EFI_NVM_EXPRESS_COMPLETION)); + + Command.Cdw0.Opcode =3D NVME_ADMIN_IDENTIFY_CMD; // // According to=20 + Nvm Express 1.1 spec Figure 38, When not used, the field shall be cleared= to 0h. + // For the Identify command, the Namespace Identifier is only used for t= he Namespace data structure. + // + Command.Nsid =3D 0; + CommandPacket.NvmeCmd =3D &Command; + CommandPacket.NvmeCompletion =3D &Completion; =20 + CommandPacket.TransferBuffer =3D &ControllerData; =20 + CommandPacket.TransferLength =3D sizeof (ControllerData); =20 + CommandPacket.CommandTimeout =3D EFI_TIMER_PERIOD_SECONDS (5); + CommandPacket.QueueType =3D NVME_ADMIN_QUEUE; + // + // Set bit 0 (Cns bit) to 1 to identify a controller // + Command.Cdw10 =3D 1; + Command.Flags =3D CDW10_VALID; + + Status =3D NvmePassthru->PassThru ( + NvmePassthru, + 0, + &CommandPacket, + NULL + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + Description =3D AllocateZeroPool ( + (ARRAY_SIZE (ControllerData.Mn) + 1 + + ARRAY_SIZE (ControllerData.Sn) + 1 + + MAXIMUM_VALUE_CHARACTERS + 1 + ) * sizeof (CHAR16)); if (Description !=3D NULL) { + Char =3D Description; + for (Index =3D 0; Index < ARRAY_SIZE (ControllerData.Mn); Index++) { + *(Char++) =3D (CHAR16) ControllerData.Mn[Index]; + } + *(Char++) =3D L' '; + for (Index =3D 0; Index < ARRAY_SIZE (ControllerData.Sn); Index++) { + *(Char++) =3D (CHAR16) ControllerData.Sn[Index]; + } + *(Char++) =3D L' '; + UnicodeValueToStringS ( + Char, sizeof (CHAR16) * (MAXIMUM_VALUE_CHARACTERS + 1), + 0, DevicePath.NvmeNamespace->NamespaceId, 0 + ); + BmEliminateExtraSpaces (Description); } + + return Description; +} + +/** Return the boot description for the controller based on the type. =20 @param Handle Controller handle. @@ -606,6 +707,7 @@ BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = =3D { BmGetDescriptionFromDiskInfo, BmGetNetworkDescription, BmGetLoadFileDescription, + BmGetNvmeDescription, BmGetMiscDescription }; =20 diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModu= lePkg/Library/UefiBootManagerLib/InternalBm.h index 444d4a5..8d7215a 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -1,7 +1,7 @@ /** @file BDS library definition, include the file and data structure =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This pro= gram and the accompanying materials are licensed and made available under = the terms and conditions of the BSD License @@ -22,6 +22,7 @@ WITHOUT WARRA= NTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include =20 #include #include @@ -38,6 +39,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include #include +#include #include #include #= include diff --git a/MdeModulePkg/Library/UefiBoo= tManagerLib/UefiBootManagerLib.inf b/MdeModulePkg/Library/UefiBootManagerLi= b/UefiBootManagerLib.inf index 6442f22..264d726 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf +++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf @@ -109,6 +109,7 @@ [Protocols] gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES + gEfiNvmExpressPassThruProtocolGuid ## SOMETIMES_CONSUMES gEfiDiskInfoProtocolGuid ## SOMETIMES_CONSUMES gEfiDriverHealthProtocolGuid ## SOMETIMES_CONSUMES gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES -- 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel