From nobody Sat Nov 2 12:19:48 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489132685910287.3193221715741; Thu, 9 Mar 2017 23:58:05 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 490E8803A6; Thu, 9 Mar 2017 23:58:04 -0800 (PST) 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 277F2803A5 for ; Thu, 9 Mar 2017 23:58:03 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 23:58:02 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga004.jf.intel.com with ESMTP; 09 Mar 2017 23:58:01 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,139,1486454400"; d="scan'208";a="66087553" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Fri, 10 Mar 2017 15:57:59 +0800 Message-Id: <20170310075759.79780-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [edk2] [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: , Cc: Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Feng Tian Reviewed-by: Feng Tian Reviewed-by: Sunny Wang --- .../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 program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License @@ -501,6 +501,107 @@ BmGetLoadFileDescription ( } =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, (VO= ID **) &DevicePath.DevPath); + if (EFI_ERROR (Status)) { + return NULL; + } + + Status =3D gBS->LocateDevicePath (&gEfiNvmExpressPassThruProtocolGuid, &= 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, &gEfiNvmExpressPassThruProtocolG= uid, (VOID **) &NvmePassthru); + ASSERT_EFI_ERROR (Status); + + ZeroMem (&CommandPacket, sizeof(EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET= )); + ZeroMem (&Command, sizeof(EFI_NVM_EXPRESS_COMMAND)); + ZeroMem (&Completion, sizeof(EFI_NVM_EXPRESS_COMPLETION)); + + Command.Cdw0.Opcode =3D NVME_ADMIN_IDENTIFY_CMD; + // + // According to 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; + CommandPacket.TransferBuffer =3D &ControllerData; + CommandPacket.TransferLength =3D sizeof (ControllerData); + 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 program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License @@ -22,6 +22,7 @@ WITHOUT WARRANTIES 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/UefiBootManagerLib/UefiBootManagerLib.inf= b/MdeModulePkg/Library/UefiBootManagerLib/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 --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel