MdeModulePkg/UefiBootManagerLib: Generate boot description for NVME

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Sunny Wang <sunnywang@hpe.com>
This commit is contained in:
Ruiyu Ni 2017-03-10 15:41:21 +08:00
parent dd4eaf1573
commit 54127af53d
3 changed files with 107 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
Library functions which relate with boot option description. Library functions which relate with boot option description.
Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR> Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -500,6 +500,107 @@ BmGetLoadFileDescription (
return NULL; return NULL;
} }
/**
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 = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath.DevPath);
if (EFI_ERROR (Status)) {
return NULL;
}
Status = gBS->LocateDevicePath (&gEfiNvmExpressPassThruProtocolGuid, &DevicePath.DevPath, &Handle);
if (EFI_ERROR (Status) ||
(DevicePathType (DevicePath.DevPath) != MESSAGING_DEVICE_PATH) ||
(DevicePathSubType (DevicePath.DevPath) != MSG_NVME_NAMESPACE_DP)) {
//
// Do not return description when the Handle is not a child of NVME controller.
//
return NULL;
}
//
// Send ADMIN_IDENTIFY command to NVME controller to get the model and serial number.
//
Status = gBS->HandleProtocol (Handle, &gEfiNvmExpressPassThruProtocolGuid, (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 = 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 the Namespace data structure.
//
Command.Nsid = 0;
CommandPacket.NvmeCmd = &Command;
CommandPacket.NvmeCompletion = &Completion;
CommandPacket.TransferBuffer = &ControllerData;
CommandPacket.TransferLength = sizeof (ControllerData);
CommandPacket.CommandTimeout = EFI_TIMER_PERIOD_SECONDS (5);
CommandPacket.QueueType = NVME_ADMIN_QUEUE;
//
// Set bit 0 (Cns bit) to 1 to identify a controller
//
Command.Cdw10 = 1;
Command.Flags = CDW10_VALID;
Status = NvmePassthru->PassThru (
NvmePassthru,
0,
&CommandPacket,
NULL
);
if (EFI_ERROR (Status)) {
return NULL;
}
Description = AllocateZeroPool (
(ARRAY_SIZE (ControllerData.Mn) + 1
+ ARRAY_SIZE (ControllerData.Sn) + 1
+ MAXIMUM_VALUE_CHARACTERS + 1
) * sizeof (CHAR16));
if (Description != NULL) {
Char = Description;
for (Index = 0; Index < ARRAY_SIZE (ControllerData.Mn); Index++) {
*(Char++) = (CHAR16) ControllerData.Mn[Index];
}
*(Char++) = L' ';
for (Index = 0; Index < ARRAY_SIZE (ControllerData.Sn); Index++) {
*(Char++) = (CHAR16) ControllerData.Sn[Index];
}
*(Char++) = 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. Return the boot description for the controller based on the type.
@ -606,6 +707,7 @@ BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = {
BmGetDescriptionFromDiskInfo, BmGetDescriptionFromDiskInfo,
BmGetNetworkDescription, BmGetNetworkDescription,
BmGetLoadFileDescription, BmGetLoadFileDescription,
BmGetNvmeDescription,
BmGetMiscDescription BmGetMiscDescription
}; };

View File

@ -1,7 +1,7 @@
/** @file /** @file
BDS library definition, include the file and data structure BDS library definition, include the file and data structure
Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR> Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 <IndustryStandard/PeImage.h> #include <IndustryStandard/PeImage.h>
#include <IndustryStandard/Atapi.h> #include <IndustryStandard/Atapi.h>
#include <IndustryStandard/Scsi.h> #include <IndustryStandard/Scsi.h>
#include <IndustryStandard/Nvme.h>
#include <Protocol/PciRootBridgeIo.h> #include <Protocol/PciRootBridgeIo.h>
#include <Protocol/BlockIo.h> #include <Protocol/BlockIo.h>
@ -38,6 +39,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/GraphicsOutput.h> #include <Protocol/GraphicsOutput.h>
#include <Protocol/UsbIo.h> #include <Protocol/UsbIo.h>
#include <Protocol/DiskInfo.h> #include <Protocol/DiskInfo.h>
#include <Protocol/NvmExpressPassthru.h>
#include <Protocol/IdeControllerInit.h> #include <Protocol/IdeControllerInit.h>
#include <Protocol/BootLogo.h> #include <Protocol/BootLogo.h>
#include <Protocol/DriverHealth.h> #include <Protocol/DriverHealth.h>

View File

@ -109,6 +109,7 @@
gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES
gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES
gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES
gEfiNvmExpressPassThruProtocolGuid ## SOMETIMES_CONSUMES
gEfiDiskInfoProtocolGuid ## SOMETIMES_CONSUMES gEfiDiskInfoProtocolGuid ## SOMETIMES_CONSUMES
gEfiDriverHealthProtocolGuid ## SOMETIMES_CONSUMES gEfiDriverHealthProtocolGuid ## SOMETIMES_CONSUMES
gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES