public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platforms][PATCH V2 0/3] Add FW Boot Media Device Indicator
@ 2019-10-04 17:29 Kubacki, Michael A
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library Kubacki, Michael A
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Kubacki, Michael A @ 2019-10-04 17:29 UTC (permalink / raw)
  To: devel; +Cc: Sai Chaganty, Eric Dong, Liming Gao, Ray Ni

V2 Changes:
 1. Add the new libraries in BoardModulePkg and IntelSiliconPkg to the
    package DSC files so they are included in the package build.

This patch series introduces a mechanism for determining the firmware
boot media device. This allows the firmware boot media to be discovered
through a standardized API.

Traditionally, most systems have only supported firmware storage on SPI
flash. Presently, several other storage technologies are being used to
store boot system firmware such as eMMC, UFS, and NVMe.

The API for all board, platform, and silicon code to consume the
firmware boot media device is provided by the FirmwareBootMediaLib
in IntelSiliconPkg.

A driver (FirmwareBootMediaInfoPei) is added to BoardModulePkg to
serve as a consistent location for reporting the firmware boot device
information. In order to abstract the potentially hardware-specific
details to determine the boot media (for platforms that support
multiple firmware boot media devices), the driver retrieves the
boot media information using a new library class introduced called
FirmwareBootMediaInfoLib. A default instance of this library class
is provided in BoardModulePkg that always returns SPI flash. This
is intended to serve as a default implementation of the library for
the most common scenario and to easily allow a board package to
substitute the logic required to determine the boot media in more
complex scenarios. Ultimately, FirmwareBootMediaInfoPei produces a
HOB containing the firmware boot media device information so it can
be used in the HOB consumer phase.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>

Michael Kubacki (3):
  IntelSiliconPkg/FirmwareBootMediaLib: Add library
  BoardModulePkg/FirmwareBootMediaInfoLib: Add library
  BoardModulePkg/FirmwareBootMediaInfoPei: Add module

 Platform/Intel/BoardModulePkg/BoardModulePkg.dec                                                  |   3 +
 Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                                 |   8 +-
 Platform/Intel/BoardModulePkg/BoardModulePkg.dsc                                                  |   6 ++
 Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                                 |   4 +-
 Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf                  |  46 +++++++++
 Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf |  35 +++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf        |  43 ++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf           |  38 +++++++
 Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h                          |  26 +++++
 Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h                              | 106 +++++++++++++++++++
 Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.c                    |  76 ++++++++++++++
 Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.c   |  24 +++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c          | 107 +++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c                | 109 ++++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c             |  82 +++++++++++++++
 15 files changed, 711 insertions(+), 2 deletions(-)
 create mode 100644 Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf
 create mode 100644 Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf
 create mode 100644 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf
 create mode 100644 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
 create mode 100644 Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h
 create mode 100644 Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
 create mode 100644 Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.c
 create mode 100644 Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.c
 create mode 100644 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c
 create mode 100644 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c
 create mode 100644 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c

-- 
2.16.2.windows.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-04 17:29 [edk2-platforms][PATCH V2 0/3] Add FW Boot Media Device Indicator Kubacki, Michael A
@ 2019-10-04 17:29 ` Kubacki, Michael A
  2019-10-07  1:45   ` Chaganty, Rangasai V
  2019-10-09  9:35   ` Ni, Ray
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 2/3] BoardModulePkg/FirmwareBootMediaInfoLib: " Kubacki, Michael A
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 3/3] BoardModulePkg/FirmwareBootMediaInfoPei: Add module Kubacki, Michael A
  2 siblings, 2 replies; 12+ messages in thread
From: Kubacki, Michael A @ 2019-10-04 17:29 UTC (permalink / raw)
  To: devel; +Cc: Sai Chaganty, Ray Ni

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229

Adds a new library that is used to make system initialization
decisions in the boot flow dependent upon firmware boot media.
Note that the firmware boot media is the storage media that
the boot firmware is stored on. It is not the OS storage media
which may be stored upon a different non-volatile storage device.

Any Intel board, platform, or silicon code that must take action
conditionally based on the firmware boot media must use this
library API.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
 Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |   8 +-
 Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |   4 +-
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf |  43 ++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf    |  38 +++++++
 Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h                       | 106 +++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c   | 107 +++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c         | 109 ++++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c      |  82 +++++++++++++++
 8 files changed, 495 insertions(+), 2 deletions(-)

diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
index fe5bfa0dc6..f70e3b977d 100644
--- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
+++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
@@ -3,7 +3,7 @@
 #
 # This package provides common open source Intel silicon modules.
 #
-# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -22,6 +22,10 @@
   #
   MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
 
+  ## @libraryclass  Provides services to identify the firmware boot media device.
+  #
+  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
+
 [Guids]
   ## GUID for Package token space
   # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
@@ -35,6 +39,8 @@
   ## Include/Guid/MicrocodeFmp.h
   gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
 
+  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06, {0xa4, 0x78, 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
+
 [Ppis]
   gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97, 0x67, 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
 
diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
index 58b5b656ef..3fb8a08b50 100644
--- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
+++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 # This package provides common open source Intel silicon modules.
 #
-# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 #
 #    SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -80,6 +80,8 @@
   IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSamplePei.inf
   IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf
   IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
+  IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
+  IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf
 
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf
new file mode 100644
index 0000000000..83ed5f04af
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf
@@ -0,0 +1,43 @@
+## @file
+# Firmware Boot Media Library
+#
+# The firmware boot media device is used to make system initialization decisions in the boot flow dependent
+# upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+# It is not the OS storage media which may be stored upon a different non-volatile storage device.
+#
+# This library contains an implementation for the DXE and SMM boot phases.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
+  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  PI_SPECIFICATION_VERSION       = 0x0001000A
+  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
+  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  FirmwareBootMediaLib.c
+  DxeSmmFirmwareBootMediaLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelSiliconPkg/IntelSiliconPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  HobLib
+
+[Guids]
+  gFirmwareBootMediaHobGuid       ## CONSUMES
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
new file mode 100644
index 0000000000..063c4027d3
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
@@ -0,0 +1,38 @@
+## @file
+# Firmware Boot Media Library
+#
+# The firmware boot media device is used to make system initialization decisions in the boot flow dependent
+# upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+# It is not the OS storage media which may be stored upon a different non-volatile storage device.
+#
+# This library contains an implementation for the PEI boot phase.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION          = 0x00010005
+  BASE_NAME            = PeiFirmwareBootMediaLib
+  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
+  MODULE_TYPE          = PEIM
+  VERSION_STRING       = 1.0
+  LIBRARY_CLASS        = FirmwareBootMediaLib
+
+[Sources]
+  FirmwareBootMediaLib.c
+  PeiFirmwareBootMediaLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelSiliconPkg/IntelSiliconPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  HobLib
+
+[Guids]
+  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
diff --git a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
new file mode 100644
index 0000000000..aca9593a84
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
@@ -0,0 +1,106 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization decisions in the boot flow dependent
+  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_
+#define _FIRMWARE_BOOT_MEDIA_LIB_H_
+
+#include <Uefi.h>
+
+typedef enum {
+  FwBootMediaSpi,
+  FwBootMediaUfs,
+  FwBootMediaEmmc,
+  FwBootMediaNvme,
+  FwBootMediaMax
+} FW_BOOT_MEDIA_TYPE;
+
+typedef struct {
+  FW_BOOT_MEDIA_TYPE BootMedia;
+} FW_BOOT_MEDIA_HOB_DATA;
+
+/**
+  Determines the current platform firmware boot media device.
+
+  @param[out] FwBootMediaType The current platform Boot Media type.
+
+  @retval     EFI_SUCCESS     The operation completed successfully.
+  @retval     EFI_NOT_FOUND   The boot media type could not be found.
+**/
+EFI_STATUS
+EFIAPI
+GetFirmwareBootMediaType (
+  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
+  );
+
+/**
+  Indicates whether the boot media is presently known.
+
+  Note: Very early in boot this data may not be available.
+
+  @retval TRUE        Boot media is known
+  @retval FALSE       Boot media is not known
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsKnown (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from SPI.
+
+  @retval TRUE        Platform firmware is booting from SPI
+  @retval FALSE       Platform firmware is booting from a non-SPI device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsSpi (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from UFS.
+
+  @retval TRUE        Platform firmware is booting from UFS
+  @retval FALSE       Platform firmware is booting from a non-UFS device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsUfs (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from eMMC.
+
+  @retval TRUE        Platform firmware is booting from eMMC
+  @retval FALSE       Platform firmware is booting from a non-eMMC device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsEmmc (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from NVMe.
+
+  @retval TRUE        Platform firmware is booting from NVMe.
+  @retval FALSE       Platform firmware is booting from a non-NVMe device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsNvme (
+  VOID
+  );
+
+#endif
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c
new file mode 100644
index 0000000000..1e3876afb3
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c
@@ -0,0 +1,107 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization decisions in the boot flow dependent
+  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+  This file contains implementation specific to the DXE and SMM boot phases.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h>
+#include <Library/HobLib.h>
+
+STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia = FwBootMediaMax;
+
+/**
+  Determines the current platform firmware boot media device.
+
+  @param[out] FwBootMediaType The current platform Boot Media type.
+
+  @retval     EFI_SUCCESS     The operation completed successfully.
+  @retval     EFI_NOT_FOUND   The boot media type could not be found.
+**/
+EFI_STATUS
+EFIAPI
+GetFirmwareBootMediaType (
+  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
+  )
+{
+  if (mFwBootMedia == FwBootMediaMax) {
+    return EFI_NOT_FOUND;
+  }
+
+  *FwBootMediaType = mFwBootMedia;
+  return EFI_SUCCESS;
+}
+
+/**
+  Determines if the boot media is presently known.
+
+  Note: Very early in boot this data may not be available.
+
+  @retval TRUE        Boot media is known
+  @retval FALSE       Boot media is not known
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsKnown (
+  VOID
+  )
+{
+  return mFwBootMedia != FwBootMediaMax;
+}
+
+/**
+  The library constructor.
+
+  This constructor depends upon gFirmwareBootMediaHobGuid.
+  It should be produced by the platform in the HOB producer phase.
+
+  @param[in]  ImageHandle           The firmware allocated handle for the UEFI image.
+  @param[in]  SystemTable           A pointer to the EFI system table.
+
+  @retval     EFI_SUCCESS           The constructor executed successfully.
+  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid HOB could not be located
+                                    or the boot media type is invalid.
+**/
+EFI_STATUS
+EFIAPI
+DxeSmmFirmwareBootMediaLibInit (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
+  FW_BOOT_MEDIA_TYPE        BootMediaType;
+  EFI_HOB_GUID_TYPE         *GuidHobPtr;
+
+  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);
+  if (GuidHobPtr == NULL) {
+    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not exist!\n"));
+    ASSERT (GuidHobPtr != NULL);
+    return EFI_NOT_FOUND;
+  }
+
+  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *) GET_GUID_HOB_DATA (GuidHobPtr);
+  if (BootMediaHobData == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  BootMediaType = BootMediaHobData->BootMedia;
+
+  if (BootMediaType >= FwBootMediaMax) {
+    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an invalid media type.\n"));
+    return EFI_NOT_FOUND;
+  }
+
+  mFwBootMedia = BootMediaType;
+
+  return EFI_SUCCESS;
+}
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c
new file mode 100644
index 0000000000..11a14d172d
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c
@@ -0,0 +1,109 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization decisions in the boot flow dependent
+  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+  This file contains library implementation common to all boot phases.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h>
+
+/**
+  Determines if the platform firmware is booting from SPI.
+
+  @retval TRUE        Platform firmware is booting from SPI
+  @retval FALSE       Platform firmware is booting from a non-SPI device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsSpi (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
+
+/**
+  Determines if the platform firmware is booting from UFS.
+
+  @retval TRUE        Platform firmware is booting from UFS
+  @retval FALSE       Platform firmware is booting from a non-UFS device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsUfs (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
+
+/**
+  Determines if the platform firmware is booting from eMMC.
+
+  @retval TRUE        Platform firmware is booting from eMMC
+  @retval FALSE       Platform firmware is booting from a non-eMMC device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsEmmc (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
+
+/**
+  Determines if the platform firmware is booting from NVMe.
+
+  @retval TRUE        Platform firmware is booting from NVMe.
+  @retval FALSE       Platform firmware is booting from a non-NVMe device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsNvme (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c
new file mode 100644
index 0000000000..14478e0dbe
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c
@@ -0,0 +1,82 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization decisions in the boot flow dependent
+  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+  This file contains implementation specific to the PEI boot phase.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h>
+#include <Library/HobLib.h>
+
+/**
+  Determines the current platform firmware boot media device.
+
+  @param[out] FwBootMediaType The current platform Boot Media type.
+
+  @retval     EFI_SUCCESS     The operation completed successfully.
+  @retval     EFI_NOT_FOUND   The boot media type could not be found.
+**/
+EFI_STATUS
+EFIAPI
+GetFirmwareBootMediaType (
+  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
+  )
+{
+  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
+  EFI_HOB_GUID_TYPE         *GuidHobPtr;
+
+  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);
+  if (GuidHobPtr == NULL) {
+      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not exist!\n"));
+      ASSERT (GuidHobPtr != NULL);
+      return EFI_NOT_FOUND;
+  }
+
+  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *) GET_GUID_HOB_DATA (GuidHobPtr);
+  if (BootMediaHobData == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
+    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an invalid media type.\n"));
+    return EFI_NOT_FOUND;
+  }
+  *FwBootMediaType = BootMediaHobData->BootMedia;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Determines if the boot media is presently known.
+
+  Note: Very early in boot this data may not be available.
+
+  @retval TRUE        Boot media is known
+  @retval FALSE       Boot media is not known
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsKnown (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  BootMedia = FwBootMediaMax;
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [edk2-platforms][PATCH V2 2/3] BoardModulePkg/FirmwareBootMediaInfoLib: Add library
  2019-10-04 17:29 [edk2-platforms][PATCH V2 0/3] Add FW Boot Media Device Indicator Kubacki, Michael A
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library Kubacki, Michael A
@ 2019-10-04 17:29 ` Kubacki, Michael A
  2019-10-08  7:01   ` Dong, Eric
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 3/3] BoardModulePkg/FirmwareBootMediaInfoPei: Add module Kubacki, Michael A
  2 siblings, 1 reply; 12+ messages in thread
From: Kubacki, Michael A @ 2019-10-04 17:29 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Liming Gao

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229

Introduces a new library class FirmwareBootMediaInfoLib that is
used to report the firmware boot media device. A default library
instance is provided that always returns the firmware boot media
is SPI flash. For platforms with other firmware boot media
options, a board-specific instance of this library should be
used instead to provide the correct firmware boot media device
information.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
 Platform/Intel/BoardModulePkg/BoardModulePkg.dec                                                  |  3 ++
 Platform/Intel/BoardModulePkg/BoardModulePkg.dsc                                                  |  3 ++
 Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf | 35 ++++++++++++++++++++
 Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h                          | 26 +++++++++++++++
 Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.c   | 24 ++++++++++++++
 5 files changed, 91 insertions(+)

diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dec b/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
index 6f13945ca8..f96fb09aa1 100644
--- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
+++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
@@ -33,6 +33,9 @@
   ##  @libraryclass    Provide services to get BIOS ID information.
   BiosIdLib|Include/Library/BiosIdLib.h
 
+  ## @libraryclass     Provides a service to determine the firmware boot media device.
+  FirmwareBootMediaInfoLib|Include/Library/FirmwareBootMediaInfoLib.h
+
 [Guids]
   ## Include Include/Guid/BiosId.h
   gBiosIdGuid = { 0xC3E36D09, 0x8294, 0x4b97, { 0xA8, 0x57, 0xD5, 0x28, 0x8F, 0xE3, 0x3E, 0x28 } }
diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
index 734ead9be8..3d605cf876 100644
--- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
+++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
@@ -33,6 +33,7 @@
   DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
 
 [LibraryClasses.common.PEIM]
+  FirmwareBootMediaLib|IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
 
@@ -40,6 +41,7 @@
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf
 
 [LibraryClasses.common.DXE_DRIVER]
+  FirmwareBootMediaLib|IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
 
@@ -77,3 +79,4 @@
   BoardModulePkg/Library/BiosIdLib/DxeBiosIdLib.inf
   BoardModulePkg/Library/BiosIdLib/PeiBiosIdLib.inf
 
+  BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf
diff --git a/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf
new file mode 100644
index 0000000000..637aeca2af
--- /dev/null
+++ b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf
@@ -0,0 +1,35 @@
+## @file
+# Firmware Boot Media Info Library
+#
+# This library identifies firmware boot media device information used in the boot flow for system initialization
+# decisions dependent upon the firmware boot media.
+#
+# This library instance provides a default implementation of the FirmwareBootMediaInfoLib library class that always
+# returns SPI flash as the boot media device. For any system firmware in which this is not the case, an instance
+# of this library class should be provided that returns the correct boot media for the platform.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION          = 0x00010005
+  BASE_NAME            = PeiFirmwareBootMediaInfoLib
+  FILE_GUID            = 91CC29F5-AEAD-4108-9E91-C8DECDC1C654
+  MODULE_TYPE          = PEIM
+  VERSION_STRING       = 1.0
+  LIBRARY_CLASS        = FirmwareBootMediaInfoLib
+
+[Sources]
+  PeiFirmwareBootMediaInfoLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelSiliconPkg/IntelSiliconPkg.dec
+  BoardModulePkg/BoardModulePkg.dec
+
+[LibraryClasses]
+  BaseLib
+  FirmwareBootMediaLib
diff --git a/Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h b/Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h
new file mode 100644
index 0000000000..b08f21ac74
--- /dev/null
+++ b/Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h
@@ -0,0 +1,26 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _FIRMWARE_BOOT_MEDIA_INFO_LIB_H_
+#define _FIRMWARE_BOOT_MEDIA_INFO_LIB_H_
+
+#include <Uefi.h>
+#include <Library/FirmwareBootMediaLib.h>
+
+/**
+  Identifies the firmware boot media type for the current boot.
+
+  @retval BOOT_MEDIA_TYPE   The boot media type. A value of FwBootMediaTypeMax indicates the firmware boot media
+                            information is unavailable.
+**/
+FW_BOOT_MEDIA_TYPE
+IdentifyFirmwareBootMediaType (
+  VOID
+  );
+
+#endif
diff --git a/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.c b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.c
new file mode 100644
index 0000000000..0c29d96033
--- /dev/null
+++ b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.c
@@ -0,0 +1,24 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/FirmwareBootMediaInfoLib.h>
+
+/**
+  Identifies the firmware boot media type for the current boot.
+
+  @retval BOOT_MEDIA_TYPE   The boot media type. A value of FwBootMediaTypeMax indicates the firmware boot media
+                            information is unavailable.
+**/
+FW_BOOT_MEDIA_TYPE
+IdentifyFirmwareBootMediaType (
+  VOID
+  )
+{
+  return FwBootMediaSpi;
+}
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [edk2-platforms][PATCH V2 3/3] BoardModulePkg/FirmwareBootMediaInfoPei: Add module
  2019-10-04 17:29 [edk2-platforms][PATCH V2 0/3] Add FW Boot Media Device Indicator Kubacki, Michael A
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library Kubacki, Michael A
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 2/3] BoardModulePkg/FirmwareBootMediaInfoLib: " Kubacki, Michael A
@ 2019-10-04 17:29 ` Kubacki, Michael A
  2019-10-08  7:02   ` Dong, Eric
  2 siblings, 1 reply; 12+ messages in thread
From: Kubacki, Michael A @ 2019-10-04 17:29 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Liming Gao

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229

Adds a new module that is responsible for publishing the boot
media device information that will be used in the boot flow for
system initialization decisions dependent upon firmware boot
media.

The module depends on a library class to implement the board-
specific details to get the firmware boot media device. This
allows the module to remain consistent in its responsibility
across implementations and the details to be easily substituted.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
 Platform/Intel/BoardModulePkg/BoardModulePkg.dsc                                 |  3 +
 Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf | 46 ++++++++++++
 Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.c   | 76 ++++++++++++++++++++
 3 files changed, 125 insertions(+)

diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
index 3d605cf876..5ec68ceebf 100644
--- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
+++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
@@ -31,9 +31,11 @@
   DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
 
 [LibraryClasses.common.PEIM]
   FirmwareBootMediaLib|IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
+  FirmwareBootMediaInfoLib|BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMediaInfoLib.inf
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
 
@@ -73,6 +75,7 @@
 ###################################################################################################
 
 [Components]
+  BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf
   BoardModulePkg/Library/CmosAccessLib/CmosAccessLib.inf
   BoardModulePkg/Library/PlatformCmosAccessLibNull/PlatformCmosAccessLibNull.inf
 
diff --git a/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf
new file mode 100644
index 0000000000..a81932f2a1
--- /dev/null
+++ b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf
@@ -0,0 +1,46 @@
+## @file
+# Firmware Boot Media Info Module
+#
+# This module publishes firmware boot media device information used in the boot flow for system initialization
+# decisions dependent upon the firmware boot media.
+#
+# This module depends upon a library instance to actually perform firmware boot media device detection since the
+# detection mechanism will vary across systems. In many cases, the media type may simply be set to a single firmware
+# boot media device with no run-time logic required. In any case, this module should dispatch as early as possible in
+# the system boot flow so the firmware boot media information is available for other modules. If any dependencies are
+# required to dynamically determine the firmware boot media device, those should be in the DEPEX section of the active
+# FirmwareBootMediaInfoLib such that this module will dispatch once those dependencies are satisfied.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION       = 0x00010017
+  BASE_NAME         = FirmwareBootMediaInfoPei
+  FILE_GUID         = A8F14FA9-FC88-45F4-A622-F06E6C56E632
+  VERSION_STRING    = 1.0
+  MODULE_TYPE       = PEIM
+  ENTRY_POINT       = FirmwareBootMediaInfoPeiEntry
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  FirmwareBootMediaLib
+  FirmwareBootMediaInfoLib
+  HobLib
+  PeimEntryPoint
+  PeiServicesLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelSiliconPkg/IntelSiliconPkg.dec
+  BoardModulePkg/BoardModulePkg.dec
+
+[Sources]
+  FirmwareBootMediaInfoPei.c
+
+[Depex]
+  TRUE
diff --git a/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.c b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.c
new file mode 100644
index 0000000000..7a71071053
--- /dev/null
+++ b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.c
@@ -0,0 +1,76 @@
+/** @file
+  Firmware Boot Media Info Module
+
+  This module publishes firmware boot media device information used in the boot flow for system initialization
+  decisions dependent upon the firmware boot media.
+
+  This module depends upon a library instance to actually perform firmware boot media device detection since the
+  detection mechanism will vary across systems. In many cases, the media type may simply be set to a single firmware
+  boot media device with no run-time logic required. In any case, this module should dispatch as early as possible in
+  the system boot flow so the firmware boot media information is available for other modules. If any dependencies are
+  required to dynamically determine the firmware boot media device, those should be in the DEPEX section of the active
+  FirmwareBootMediaInfoLib such that this module will dispatch once those dependencies are satisfied.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h>
+#include <Library/FirmwareBootMediaInfoLib.h>
+#include <Library/HobLib.h>
+
+/**
+  Produces a gFirmwareBootMediaHobGuid HOB instance.
+
+  @retval     EFI_SUCCESS     The firmware boot media HOB was produced successfully.
+  @retval     EFI_NOT_FOUND   The firmware boot media device information could not be found to produce the
+                              the firmware boot media HOB.
+**/
+EFI_STATUS
+EFIAPI
+ProduceFirmwareBootMediaHob (
+  VOID
+  )
+{
+  FW_BOOT_MEDIA_HOB_DATA FwBootMediaHobData;
+
+  FwBootMediaHobData.BootMedia = IdentifyFirmwareBootMediaType ();
+  if (FwBootMediaHobData.BootMedia == FwBootMediaMax) {
+    return EFI_NOT_FOUND;
+  }
+
+  BuildGuidDataHob (
+    &gFirmwareBootMediaHobGuid,
+    &FwBootMediaHobData,
+    sizeof (FW_BOOT_MEDIA_HOB_DATA)
+    );
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Attempts to publish the firmware boot media HOB.
+
+  @param  FileHandle  Handle of the file being invoked.
+  @param  PeiServices Describes the list of possible PEI Services.
+
+  @retval EFI_SUCCESS   Produce the BootMedia Hob successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+FirmwareBootMediaInfoPeiEntry (
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = ProduceFirmwareBootMediaHob ();
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library Kubacki, Michael A
@ 2019-10-07  1:45   ` Chaganty, Rangasai V
  2019-10-09  9:35   ` Ni, Ray
  1 sibling, 0 replies; 12+ messages in thread
From: Chaganty, Rangasai V @ 2019-10-07  1:45 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Ni, Ray

Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com>

-----Original Message-----
From: Kubacki, Michael A 
Sent: Friday, October 04, 2019 10:29 AM
To: devel@edk2.groups.io
Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229

Adds a new library that is used to make system initialization decisions in the boot flow dependent upon firmware boot media.
Note that the firmware boot media is the storage media that the boot firmware is stored on. It is not the OS storage media which may be stored upon a different non-volatile storage device.

Any Intel board, platform, or silicon code that must take action conditionally based on the firmware boot media must use this library API.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
 Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |   8 +-
 Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |   4 +-
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf |  43 ++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf    |  38 +++++++
 Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h                       | 106 +++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c   | 107 +++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c         | 109 ++++++++++++++++++++
 Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c      |  82 +++++++++++++++
 8 files changed, 495 insertions(+), 2 deletions(-)

diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
index fe5bfa0dc6..f70e3b977d 100644
--- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
+++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
@@ -3,7 +3,7 @@
 #
 # This package provides common open source Intel silicon modules.
 #
-# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2016 - 2019, Intel Corporation. All rights 
+reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -22,6 +22,10 @@
   #
   MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
 
+  ## @libraryclass  Provides services to identify the firmware boot media device.
+  #
+  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
+
 [Guids]
   ## GUID for Package token space
   # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
@@ -35,6 +39,8 @@
   ## Include/Guid/MicrocodeFmp.h
   gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
 
+  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06, {0xa4, 
+ 0x78, 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
+
 [Ppis]
   gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97, 0x67, 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
 
diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
index 58b5b656ef..3fb8a08b50 100644
--- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
+++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 # This package provides common open source Intel silicon modules.
 #
-# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2019, Intel Corporation. All rights 
+reserved.<BR>
 #
 #    SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -80,6 +80,8 @@
   IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSamplePei.inf
   IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDxe.inf
   IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/MicrocodeFlashAccessLibNull.inf
+  
+ IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.
+ inf  
+ IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaL
+ ib.inf
 
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.inf
new file mode 100644
index 0000000000..83ed5f04af
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmm
+++ FirmwareBootMediaLib.inf
@@ -0,0 +1,43 @@
+## @file
+# Firmware Boot Media Library
+#
+# The firmware boot media device is used to make system initialization 
+decisions in the boot flow dependent # upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+# It is not the OS storage media which may be stored upon a different non-volatile storage device.
+#
+# This library contains an implementation for the DXE and SMM boot phases.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> # #  
+SPDX-License-Identifier: BSD-2-Clause-Patent # ##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
+  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  PI_SPECIFICATION_VERSION       = 0x0001000A
+  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
+  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  FirmwareBootMediaLib.c
+  DxeSmmFirmwareBootMediaLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelSiliconPkg/IntelSiliconPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  HobLib
+
+[Guids]
+  gFirmwareBootMediaHobGuid       ## CONSUMES
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.inf
new file mode 100644
index 0000000000..063c4027d3
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
+++ mwareBootMediaLib.inf
@@ -0,0 +1,38 @@
+## @file
+# Firmware Boot Media Library
+#
+# The firmware boot media device is used to make system initialization 
+decisions in the boot flow dependent # upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+# It is not the OS storage media which may be stored upon a different non-volatile storage device.
+#
+# This library contains an implementation for the PEI boot phase.
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> # #  
+SPDX-License-Identifier: BSD-2-Clause-Patent # ##
+
+[Defines]
+  INF_VERSION          = 0x00010005
+  BASE_NAME            = PeiFirmwareBootMediaLib
+  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
+  MODULE_TYPE          = PEIM
+  VERSION_STRING       = 1.0
+  LIBRARY_CLASS        = FirmwareBootMediaLib
+
+[Sources]
+  FirmwareBootMediaLib.c
+  PeiFirmwareBootMediaLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  IntelSiliconPkg/IntelSiliconPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  HobLib
+
+[Guids]
+  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
diff --git a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
new file mode 100644
index 0000000000..aca9593a84
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib
+++ .h
@@ -0,0 +1,106 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization 
+ decisions in the boot flow dependent  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_
+#define _FIRMWARE_BOOT_MEDIA_LIB_H_
+
+#include <Uefi.h>
+
+typedef enum {
+  FwBootMediaSpi,
+  FwBootMediaUfs,
+  FwBootMediaEmmc,
+  FwBootMediaNvme,
+  FwBootMediaMax
+} FW_BOOT_MEDIA_TYPE;
+
+typedef struct {
+  FW_BOOT_MEDIA_TYPE BootMedia;
+} FW_BOOT_MEDIA_HOB_DATA;
+
+/**
+  Determines the current platform firmware boot media device.
+
+  @param[out] FwBootMediaType The current platform Boot Media type.
+
+  @retval     EFI_SUCCESS     The operation completed successfully.
+  @retval     EFI_NOT_FOUND   The boot media type could not be found.
+**/
+EFI_STATUS
+EFIAPI
+GetFirmwareBootMediaType (
+  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
+  );
+
+/**
+  Indicates whether the boot media is presently known.
+
+  Note: Very early in boot this data may not be available.
+
+  @retval TRUE        Boot media is known
+  @retval FALSE       Boot media is not known
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsKnown (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from SPI.
+
+  @retval TRUE        Platform firmware is booting from SPI
+  @retval FALSE       Platform firmware is booting from a non-SPI device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsSpi (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from UFS.
+
+  @retval TRUE        Platform firmware is booting from UFS
+  @retval FALSE       Platform firmware is booting from a non-UFS device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsUfs (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from eMMC.
+
+  @retval TRUE        Platform firmware is booting from eMMC
+  @retval FALSE       Platform firmware is booting from a non-eMMC device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsEmmc (
+  VOID
+  );
+
+/**
+  Determines if the platform firmware is booting from NVMe.
+
+  @retval TRUE        Platform firmware is booting from NVMe.
+  @retval FALSE       Platform firmware is booting from a non-NVMe device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsNvme (
+  VOID
+  );
+
+#endif
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMediaLib.c
new file mode 100644
index 0000000000..1e3876afb3
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmm
+++ FirmwareBootMediaLib.c
@@ -0,0 +1,107 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization 
+ decisions in the boot flow dependent  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+  This file contains implementation specific to the DXE and SMM boot phases.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h> #include <Library/HobLib.h>
+
+STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia = FwBootMediaMax;
+
+/**
+  Determines the current platform firmware boot media device.
+
+  @param[out] FwBootMediaType The current platform Boot Media type.
+
+  @retval     EFI_SUCCESS     The operation completed successfully.
+  @retval     EFI_NOT_FOUND   The boot media type could not be found.
+**/
+EFI_STATUS
+EFIAPI
+GetFirmwareBootMediaType (
+  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
+  )
+{
+  if (mFwBootMedia == FwBootMediaMax) {
+    return EFI_NOT_FOUND;
+  }
+
+  *FwBootMediaType = mFwBootMedia;
+  return EFI_SUCCESS;
+}
+
+/**
+  Determines if the boot media is presently known.
+
+  Note: Very early in boot this data may not be available.
+
+  @retval TRUE        Boot media is known
+  @retval FALSE       Boot media is not known
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsKnown (
+  VOID
+  )
+{
+  return mFwBootMedia != FwBootMediaMax; }
+
+/**
+  The library constructor.
+
+  This constructor depends upon gFirmwareBootMediaHobGuid.
+  It should be produced by the platform in the HOB producer phase.
+
+  @param[in]  ImageHandle           The firmware allocated handle for the UEFI image.
+  @param[in]  SystemTable           A pointer to the EFI system table.
+
+  @retval     EFI_SUCCESS           The constructor executed successfully.
+  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid HOB could not be located
+                                    or the boot media type is invalid.
+**/
+EFI_STATUS
+EFIAPI
+DxeSmmFirmwareBootMediaLibInit (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
+  FW_BOOT_MEDIA_TYPE        BootMediaType;
+  EFI_HOB_GUID_TYPE         *GuidHobPtr;
+
+  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if 
+ (GuidHobPtr == NULL) {
+    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not exist!\n"));
+    ASSERT (GuidHobPtr != NULL);
+    return EFI_NOT_FOUND;
+  }
+
+  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *) GET_GUID_HOB_DATA 
+ (GuidHobPtr);  if (BootMediaHobData == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  BootMediaType = BootMediaHobData->BootMedia;
+
+  if (BootMediaType >= FwBootMediaMax) {
+    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an invalid media type.\n"));
+    return EFI_NOT_FOUND;
+  }
+
+  mFwBootMedia = BootMediaType;
+
+  return EFI_SUCCESS;
+}
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBootMediaLib.c
new file mode 100644
index 0000000000..11a14d172d
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmwa
+++ reBootMediaLib.c
@@ -0,0 +1,109 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization 
+ decisions in the boot flow dependent  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+  This file contains library implementation common to all boot phases.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h>
+
+/**
+  Determines if the platform firmware is booting from SPI.
+
+  @retval TRUE        Platform firmware is booting from SPI
+  @retval FALSE       Platform firmware is booting from a non-SPI device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsSpi (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
+
+/**
+  Determines if the platform firmware is booting from UFS.
+
+  @retval TRUE        Platform firmware is booting from UFS
+  @retval FALSE       Platform firmware is booting from a non-UFS device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsUfs (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
+
+/**
+  Determines if the platform firmware is booting from eMMC.
+
+  @retval TRUE        Platform firmware is booting from eMMC
+  @retval FALSE       Platform firmware is booting from a non-eMMC device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsEmmc (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
+
+/**
+  Determines if the platform firmware is booting from NVMe.
+
+  @retval TRUE        Platform firmware is booting from NVMe.
+  @retval FALSE       Platform firmware is booting from a non-NVMe device or the boot media is unknown
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsNvme (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
diff --git a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib.c
new file mode 100644
index 0000000000..14478e0dbe
--- /dev/null
+++ b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
+++ mwareBootMediaLib.c
@@ -0,0 +1,82 @@
+/** @file
+  This library identifies the firmware boot media device.
+
+  The firmware boot media device is used to make system initialization 
+ decisions in the boot flow dependent  upon firmware boot media. Note that the firmware boot media is the storage media that the boot firmware is stored on.
+  It is not the OS storage media which may be stored upon a different non-volatile storage device.
+
+  This file contains implementation specific to the PEI boot phase.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FirmwareBootMediaLib.h> #include <Library/HobLib.h>
+
+/**
+  Determines the current platform firmware boot media device.
+
+  @param[out] FwBootMediaType The current platform Boot Media type.
+
+  @retval     EFI_SUCCESS     The operation completed successfully.
+  @retval     EFI_NOT_FOUND   The boot media type could not be found.
+**/
+EFI_STATUS
+EFIAPI
+GetFirmwareBootMediaType (
+  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
+  )
+{
+  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
+  EFI_HOB_GUID_TYPE         *GuidHobPtr;
+
+  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if 
+ (GuidHobPtr == NULL) {
+      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not exist!\n"));
+      ASSERT (GuidHobPtr != NULL);
+      return EFI_NOT_FOUND;
+  }
+
+  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *) GET_GUID_HOB_DATA 
+ (GuidHobPtr);  if (BootMediaHobData == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
+    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an invalid media type.\n"));
+    return EFI_NOT_FOUND;
+  }
+  *FwBootMediaType = BootMediaHobData->BootMedia;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Determines if the boot media is presently known.
+
+  Note: Very early in boot this data may not be available.
+
+  @retval TRUE        Boot media is known
+  @retval FALSE       Boot media is not known
+**/
+BOOLEAN
+EFIAPI
+FirmwareBootMediaIsKnown (
+  VOID
+  )
+{
+  EFI_STATUS          Status;
+  FW_BOOT_MEDIA_TYPE  BootMedia;
+
+  BootMedia = FwBootMediaMax;
+  Status = GetFirmwareBootMediaType (&BootMedia);
+  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
+    return FALSE;
+  } else {
+    return TRUE;
+  }
+}
--
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 2/3] BoardModulePkg/FirmwareBootMediaInfoLib: Add library
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 2/3] BoardModulePkg/FirmwareBootMediaInfoLib: " Kubacki, Michael A
@ 2019-10-08  7:01   ` Dong, Eric
  0 siblings, 0 replies; 12+ messages in thread
From: Dong, Eric @ 2019-10-08  7:01 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Gao, Liming

Reviewed-by: Eric Dong <eric .dong@intel.com>

> -----Original Message-----
> From: Kubacki, Michael A
> Sent: Saturday, October 5, 2019 1:29 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2-platforms][PATCH V2 2/3]
> BoardModulePkg/FirmwareBootMediaInfoLib: Add library
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> 
> Introduces a new library class FirmwareBootMediaInfoLib that is
> used to report the firmware boot media device. A default library
> instance is provided that always returns the firmware boot media
> is SPI flash. For platforms with other firmware boot media
> options, a board-specific instance of this library should be
> used instead to provide the correct firmware boot media device
> information.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> ---
>  Platform/Intel/BoardModulePkg/BoardModulePkg.dec
> |  3 ++
>  Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> |  3 ++
> 
> Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFir
> mwareBootMediaInfoLib.inf | 35 ++++++++++++++++++++
>  Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib.h
> | 26 +++++++++++++++
> 
> Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFir
> mwareBootMediaInfoLib.c   | 24 ++++++++++++++
>  5 files changed, 91 insertions(+)
> 
> diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
> b/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
> index 6f13945ca8..f96fb09aa1 100644
> --- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
> +++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dec
> @@ -33,6 +33,9 @@
>    ##  @libraryclass    Provide services to get BIOS ID information.
>    BiosIdLib|Include/Library/BiosIdLib.h
> 
> +  ## @libraryclass     Provides a service to determine the firmware boot media
> device.
> +  FirmwareBootMediaInfoLib|Include/Library/FirmwareBootMediaInfoLib.h
> +
>  [Guids]
>    ## Include Include/Guid/BiosId.h
>    gBiosIdGuid = { 0xC3E36D09, 0x8294, 0x4b97, { 0xA8, 0x57, 0xD5, 0x28, 0x8F,
> 0xE3, 0x3E, 0x28 } }
> diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> index 734ead9be8..3d605cf876 100644
> --- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> +++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> @@ -33,6 +33,7 @@
>    DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
> 
>  [LibraryClasses.common.PEIM]
> +
> FirmwareBootMediaLib|IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFi
> rmwareBootMediaLib.inf
>    HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
> 
> MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAll
> ocationLib.inf
> 
> @@ -40,6 +41,7 @@
> 
> PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/Pei
> ServicesTablePointerLibIdt.inf
> 
>  [LibraryClasses.common.DXE_DRIVER]
> +
> FirmwareBootMediaLib|IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Dxe
> SmmFirmwareBootMediaLib.inf
>    HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
> 
> MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory
> AllocationLib.inf
> 
> @@ -77,3 +79,4 @@
>    BoardModulePkg/Library/BiosIdLib/DxeBiosIdLib.inf
>    BoardModulePkg/Library/BiosIdLib/PeiBiosIdLib.inf
> 
> +
> BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFirmwareBootMe
> diaInfoLib.inf
> diff --git
> a/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFi
> rmwareBootMediaInfoLib.inf
> b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFi
> rmwareBootMediaInfoLib.inf
> new file mode 100644
> index 0000000000..637aeca2af
> --- /dev/null
> +++
> b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFi
> rmwareBootMediaInfoLib.inf
> @@ -0,0 +1,35 @@
> +## @file
> +# Firmware Boot Media Info Library
> +#
> +# This library identifies firmware boot media device information used in the
> boot flow for system initialization
> +# decisions dependent upon the firmware boot media.
> +#
> +# This library instance provides a default implementation of the
> FirmwareBootMediaInfoLib library class that always
> +# returns SPI flash as the boot media device. For any system firmware in
> which this is not the case, an instance
> +# of this library class should be provided that returns the correct boot media
> for the platform.
> +#
> +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION          = 0x00010005
> +  BASE_NAME            = PeiFirmwareBootMediaInfoLib
> +  FILE_GUID            = 91CC29F5-AEAD-4108-9E91-C8DECDC1C654
> +  MODULE_TYPE          = PEIM
> +  VERSION_STRING       = 1.0
> +  LIBRARY_CLASS        = FirmwareBootMediaInfoLib
> +
> +[Sources]
> +  PeiFirmwareBootMediaInfoLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  IntelSiliconPkg/IntelSiliconPkg.dec
> +  BoardModulePkg/BoardModulePkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  FirmwareBootMediaLib
> diff --git
> a/Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib
> .h
> b/Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib
> .h
> new file mode 100644
> index 0000000000..b08f21ac74
> --- /dev/null
> +++
> b/Platform/Intel/BoardModulePkg/Include/Library/FirmwareBootMediaInfoLib
> .h
> @@ -0,0 +1,26 @@
> +/** @file
> +  This library identifies the firmware boot media device.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _FIRMWARE_BOOT_MEDIA_INFO_LIB_H_
> +#define _FIRMWARE_BOOT_MEDIA_INFO_LIB_H_
> +
> +#include <Uefi.h>
> +#include <Library/FirmwareBootMediaLib.h>
> +
> +/**
> +  Identifies the firmware boot media type for the current boot.
> +
> +  @retval BOOT_MEDIA_TYPE   The boot media type. A value of
> FwBootMediaTypeMax indicates the firmware boot media
> +                            information is unavailable.
> +**/
> +FW_BOOT_MEDIA_TYPE
> +IdentifyFirmwareBootMediaType (
> +  VOID
> +  );
> +
> +#endif
> diff --git
> a/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFi
> rmwareBootMediaInfoLib.c
> b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFi
> rmwareBootMediaInfoLib.c
> new file mode 100644
> index 0000000000..0c29d96033
> --- /dev/null
> +++
> b/Platform/Intel/BoardModulePkg/Library/PeiFirmwareBootMediaInfoLib/PeiFi
> rmwareBootMediaInfoLib.c
> @@ -0,0 +1,24 @@
> +/** @file
> +  This library identifies the firmware boot media device.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/FirmwareBootMediaInfoLib.h>
> +
> +/**
> +  Identifies the firmware boot media type for the current boot.
> +
> +  @retval BOOT_MEDIA_TYPE   The boot media type. A value of
> FwBootMediaTypeMax indicates the firmware boot media
> +                            information is unavailable.
> +**/
> +FW_BOOT_MEDIA_TYPE
> +IdentifyFirmwareBootMediaType (
> +  VOID
> +  )
> +{
> +  return FwBootMediaSpi;
> +}
> --
> 2.16.2.windows.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 3/3] BoardModulePkg/FirmwareBootMediaInfoPei: Add module
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 3/3] BoardModulePkg/FirmwareBootMediaInfoPei: Add module Kubacki, Michael A
@ 2019-10-08  7:02   ` Dong, Eric
  0 siblings, 0 replies; 12+ messages in thread
From: Dong, Eric @ 2019-10-08  7:02 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Gao, Liming

Reviewed-by: Eric Dong <eric.dong@intel.com>

> -----Original Message-----
> From: Kubacki, Michael A
> Sent: Saturday, October 5, 2019 1:29 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2-platforms][PATCH V2 3/3]
> BoardModulePkg/FirmwareBootMediaInfoPei: Add module
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> 
> Adds a new module that is responsible for publishing the boot
> media device information that will be used in the boot flow for
> system initialization decisions dependent upon firmware boot
> media.
> 
> The module depends on a library class to implement the board-
> specific details to get the firmware boot media device. This
> allows the module to remain consistent in its responsibility
> across implementations and the details to be easily substituted.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> ---
>  Platform/Intel/BoardModulePkg/BoardModulePkg.dsc                                 |  3 +
> 
> Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMedi
> aInfoPei.inf | 46 ++++++++++++
> 
> Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMedi
> aInfoPei.c   | 76 ++++++++++++++++++++
>  3 files changed, 125 insertions(+)
> 
> diff --git a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> index 3d605cf876..5ec68ceebf 100644
> --- a/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> +++ b/Platform/Intel/BoardModulePkg/BoardModulePkg.dsc
> @@ -31,9 +31,11 @@
>    DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
>    PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
>    DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
> +  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
> 
>  [LibraryClasses.common.PEIM]
> 
> FirmwareBootMediaLib|IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFi
> rmwareBootMediaLib.inf
> +
> FirmwareBootMediaInfoLib|BoardModulePkg/Library/PeiFirmwareBootMediaI
> nfoLib/PeiFirmwareBootMediaInfoLib.inf
>    HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
> 
> MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAll
> ocationLib.inf
> 
> @@ -73,6 +75,7 @@
> 
> ###############################################################
> ####################################
> 
>  [Components]
> +  BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMediaInfoPei.inf
>    BoardModulePkg/Library/CmosAccessLib/CmosAccessLib.inf
> 
> BoardModulePkg/Library/PlatformCmosAccessLibNull/PlatformCmosAccessLib
> Null.inf
> 
> diff --git
> a/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMe
> diaInfoPei.inf
> b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMe
> diaInfoPei.inf
> new file mode 100644
> index 0000000000..a81932f2a1
> --- /dev/null
> +++
> b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMe
> diaInfoPei.inf
> @@ -0,0 +1,46 @@
> +## @file
> +# Firmware Boot Media Info Module
> +#
> +# This module publishes firmware boot media device information used in the
> boot flow for system initialization
> +# decisions dependent upon the firmware boot media.
> +#
> +# This module depends upon a library instance to actually perform firmware
> boot media device detection since the
> +# detection mechanism will vary across systems. In many cases, the media
> type may simply be set to a single firmware
> +# boot media device with no run-time logic required. In any case, this module
> should dispatch as early as possible in
> +# the system boot flow so the firmware boot media information is available
> for other modules. If any dependencies are
> +# required to dynamically determine the firmware boot media device, those
> should be in the DEPEX section of the active
> +# FirmwareBootMediaInfoLib such that this module will dispatch once those
> dependencies are satisfied.
> +#
> +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION       = 0x00010017
> +  BASE_NAME         = FirmwareBootMediaInfoPei
> +  FILE_GUID         = A8F14FA9-FC88-45F4-A622-F06E6C56E632
> +  VERSION_STRING    = 1.0
> +  MODULE_TYPE       = PEIM
> +  ENTRY_POINT       = FirmwareBootMediaInfoPeiEntry
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  FirmwareBootMediaLib
> +  FirmwareBootMediaInfoLib
> +  HobLib
> +  PeimEntryPoint
> +  PeiServicesLib
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  IntelSiliconPkg/IntelSiliconPkg.dec
> +  BoardModulePkg/BoardModulePkg.dec
> +
> +[Sources]
> +  FirmwareBootMediaInfoPei.c
> +
> +[Depex]
> +  TRUE
> diff --git
> a/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMe
> diaInfoPei.c
> b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMe
> diaInfoPei.c
> new file mode 100644
> index 0000000000..7a71071053
> --- /dev/null
> +++
> b/Platform/Intel/BoardModulePkg/FirmwareBootMediaInfo/FirmwareBootMe
> diaInfoPei.c
> @@ -0,0 +1,76 @@
> +/** @file
> +  Firmware Boot Media Info Module
> +
> +  This module publishes firmware boot media device information used in the
> boot flow for system initialization
> +  decisions dependent upon the firmware boot media.
> +
> +  This module depends upon a library instance to actually perform firmware
> boot media device detection since the
> +  detection mechanism will vary across systems. In many cases, the media
> type may simply be set to a single firmware
> +  boot media device with no run-time logic required. In any case, this module
> should dispatch as early as possible in
> +  the system boot flow so the firmware boot media information is available for
> other modules. If any dependencies are
> +  required to dynamically determine the firmware boot media device, those
> should be in the DEPEX section of the active
> +  FirmwareBootMediaInfoLib such that this module will dispatch once those
> dependencies are satisfied.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/FirmwareBootMediaLib.h>
> +#include <Library/FirmwareBootMediaInfoLib.h>
> +#include <Library/HobLib.h>
> +
> +/**
> +  Produces a gFirmwareBootMediaHobGuid HOB instance.
> +
> +  @retval     EFI_SUCCESS     The firmware boot media HOB was produced
> successfully.
> +  @retval     EFI_NOT_FOUND   The firmware boot media device information
> could not be found to produce the
> +                              the firmware boot media HOB.
> +**/
> +EFI_STATUS
> +EFIAPI
> +ProduceFirmwareBootMediaHob (
> +  VOID
> +  )
> +{
> +  FW_BOOT_MEDIA_HOB_DATA FwBootMediaHobData;
> +
> +  FwBootMediaHobData.BootMedia = IdentifyFirmwareBootMediaType ();
> +  if (FwBootMediaHobData.BootMedia == FwBootMediaMax) {
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  BuildGuidDataHob (
> +    &gFirmwareBootMediaHobGuid,
> +    &FwBootMediaHobData,
> +    sizeof (FW_BOOT_MEDIA_HOB_DATA)
> +    );
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Attempts to publish the firmware boot media HOB.
> +
> +  @param  FileHandle  Handle of the file being invoked.
> +  @param  PeiServices Describes the list of possible PEI Services.
> +
> +  @retval EFI_SUCCESS   Produce the BootMedia Hob successfully.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwareBootMediaInfoPeiEntry (
> +  IN       EFI_PEI_FILE_HANDLE  FileHandle,
> +  IN CONST EFI_PEI_SERVICES     **PeiServices
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  Status = ProduceFirmwareBootMediaHob ();
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return Status;
> +}
> --
> 2.16.2.windows.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-04 17:29 ` [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library Kubacki, Michael A
  2019-10-07  1:45   ` Chaganty, Rangasai V
@ 2019-10-09  9:35   ` Ni, Ray
  2019-10-09 16:33     ` Kubacki, Michael A
  1 sibling, 1 reply; 12+ messages in thread
From: Ni, Ray @ 2019-10-09  9:35 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Chaganty, Rangasai V

Michael,
Two comments:
1. The difference between PEI and DXE instances is DXE instance has a global variable caching the boot media type. Both get the type from HOB. So I am thinking how about simplifying the library to have only one instance which equals to PEI instance. That can also be used in DXE phase.
2. With the definition of enum type FW_BOOT_MEDIA_TYPE and GetType() API, I feel the other several FirmwareBootMediaIsXXX() APIs are not very necessary.

Thanks,
Ray

> -----Original Message-----
> From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> Sent: Saturday, October 5, 2019 1:29 AM
> To: devel@edk2.groups.io
> Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Ni, Ray
> <ray.ni@intel.com>
> Subject: [edk2-platforms][PATCH V2 1/3]
> IntelSiliconPkg/FirmwareBootMediaLib: Add library
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> 
> Adds a new library that is used to make system initialization
> decisions in the boot flow dependent upon firmware boot media.
> Note that the firmware boot media is the storage media that
> the boot firmware is stored on. It is not the OS storage media
> which may be stored upon a different non-volatile storage device.
> 
> Any Intel board, platform, or silicon code that must take action
> conditionally based on the firmware boot media must use this
> library API.
> 
> Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> ---
>  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |   8 +-
>  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |   4 +-
> 
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> wareBootMediaLib.inf |  43 ++++++++
> 
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareB
> ootMediaLib.inf    |  38 +++++++
>  Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> | 106 +++++++++++++++++++
> 
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> wareBootMediaLib.c   | 107 +++++++++++++++++++
> 
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBoo
> tMediaLib.c         | 109 ++++++++++++++++++++
> 
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareB
> ootMediaLib.c      |  82 +++++++++++++++
>  8 files changed, 495 insertions(+), 2 deletions(-)
> 
> diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> index fe5bfa0dc6..f70e3b977d 100644
> --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> @@ -3,7 +3,7 @@
>  #
>  # This package provides common open source Intel silicon modules.
>  #
> -# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> @@ -22,6 +22,10 @@
>    #
>    MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
> 
> +  ## @libraryclass  Provides services to identify the firmware boot media
> device.
> +  #
> +  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
> +
>  [Guids]
>    ## GUID for Package token space
>    # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
> @@ -35,6 +39,8 @@
>    ## Include/Guid/MicrocodeFmp.h
>    gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, { 0x9d,
> 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
> 
> +  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06, {0xa4, 0x78,
> 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
> +
>  [Ppis]
>    gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97, 0x67, 0x67,
> 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
> 
> diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> index 58b5b656ef..3fb8a08b50 100644
> --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> @@ -1,7 +1,7 @@
>  ## @file
>  # This package provides common open source Intel silicon modules.
>  #
> -# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
>  #
>  #    SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> @@ -80,6 +80,8 @@
> 
> IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSa
> mplePei.inf
> 
> IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDx
> e.inf
> 
> IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/Micro
> codeFlashAccessLibNull.inf
> +
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib
> .inf
> +
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMe
> diaLib.inf
> 
>  [BuildOptions]
>    *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
> diff --git
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFir
> mwareBootMediaLib.inf
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFir
> mwareBootMediaLib.inf
> new file mode 100644
> index 0000000000..83ed5f04af
> --- /dev/null
> +++
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFir
> mwareBootMediaLib.inf
> @@ -0,0 +1,43 @@
> +## @file
> +# Firmware Boot Media Library
> +#
> +# The firmware boot media device is used to make system initialization
> decisions in the boot flow dependent
> +# upon firmware boot media. Note that the firmware boot media is the
> storage media that the boot firmware is stored on.
> +# It is not the OS storage media which may be stored upon a different non-
> volatile storage device.
> +#
> +# This library contains an implementation for the DXE and SMM boot phases.
> +#
> +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
> +  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  PI_SPECIFICATION_VERSION       = 0x0001000A
> +  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER
> DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
> UEFI_DRIVER
> +  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
> +#
> +
> +[Sources]
> +  FirmwareBootMediaLib.c
> +  DxeSmmFirmwareBootMediaLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  IntelSiliconPkg/IntelSiliconPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  HobLib
> +
> +[Guids]
> +  gFirmwareBootMediaHobGuid       ## CONSUMES
> diff --git
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> eBootMediaLib.inf
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> eBootMediaLib.inf
> new file mode 100644
> index 0000000000..063c4027d3
> --- /dev/null
> +++
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> eBootMediaLib.inf
> @@ -0,0 +1,38 @@
> +## @file
> +# Firmware Boot Media Library
> +#
> +# The firmware boot media device is used to make system initialization
> decisions in the boot flow dependent
> +# upon firmware boot media. Note that the firmware boot media is the
> storage media that the boot firmware is stored on.
> +# It is not the OS storage media which may be stored upon a different non-
> volatile storage device.
> +#
> +# This library contains an implementation for the PEI boot phase.
> +#
> +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION          = 0x00010005
> +  BASE_NAME            = PeiFirmwareBootMediaLib
> +  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
> +  MODULE_TYPE          = PEIM
> +  VERSION_STRING       = 1.0
> +  LIBRARY_CLASS        = FirmwareBootMediaLib
> +
> +[Sources]
> +  FirmwareBootMediaLib.c
> +  PeiFirmwareBootMediaLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  IntelSiliconPkg/IntelSiliconPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  HobLib
> +
> +[Guids]
> +  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
> diff --git
> a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> new file mode 100644
> index 0000000000..aca9593a84
> --- /dev/null
> +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> @@ -0,0 +1,106 @@
> +/** @file
> +  This library identifies the firmware boot media device.
> +
> +  The firmware boot media device is used to make system initialization
> decisions in the boot flow dependent
> +  upon firmware boot media. Note that the firmware boot media is the
> storage media that the boot firmware is stored on.
> +  It is not the OS storage media which may be stored upon a different non-
> volatile storage device.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_
> +#define _FIRMWARE_BOOT_MEDIA_LIB_H_
> +
> +#include <Uefi.h>
> +
> +typedef enum {
> +  FwBootMediaSpi,
> +  FwBootMediaUfs,
> +  FwBootMediaEmmc,
> +  FwBootMediaNvme,
> +  FwBootMediaMax
> +} FW_BOOT_MEDIA_TYPE;
> +
> +typedef struct {
> +  FW_BOOT_MEDIA_TYPE BootMedia;
> +} FW_BOOT_MEDIA_HOB_DATA;
> +
> +/**
> +  Determines the current platform firmware boot media device.
> +
> +  @param[out] FwBootMediaType The current platform Boot Media type.
> +
> +  @retval     EFI_SUCCESS     The operation completed successfully.
> +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetFirmwareBootMediaType (
> +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> +  );
> +
> +/**
> +  Indicates whether the boot media is presently known.
> +
> +  Note: Very early in boot this data may not be available.
> +
> +  @retval TRUE        Boot media is known
> +  @retval FALSE       Boot media is not known
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsKnown (
> +  VOID
> +  );
> +
> +/**
> +  Determines if the platform firmware is booting from SPI.
> +
> +  @retval TRUE        Platform firmware is booting from SPI
> +  @retval FALSE       Platform firmware is booting from a non-SPI device or
> the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsSpi (
> +  VOID
> +  );
> +
> +/**
> +  Determines if the platform firmware is booting from UFS.
> +
> +  @retval TRUE        Platform firmware is booting from UFS
> +  @retval FALSE       Platform firmware is booting from a non-UFS device or
> the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsUfs (
> +  VOID
> +  );
> +
> +/**
> +  Determines if the platform firmware is booting from eMMC.
> +
> +  @retval TRUE        Platform firmware is booting from eMMC
> +  @retval FALSE       Platform firmware is booting from a non-eMMC device
> or the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsEmmc (
> +  VOID
> +  );
> +
> +/**
> +  Determines if the platform firmware is booting from NVMe.
> +
> +  @retval TRUE        Platform firmware is booting from NVMe.
> +  @retval FALSE       Platform firmware is booting from a non-NVMe device or
> the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsNvme (
> +  VOID
> +  );
> +
> +#endif
> diff --git
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFir
> mwareBootMediaLib.c
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFir
> mwareBootMediaLib.c
> new file mode 100644
> index 0000000000..1e3876afb3
> --- /dev/null
> +++
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFir
> mwareBootMediaLib.c
> @@ -0,0 +1,107 @@
> +/** @file
> +  This library identifies the firmware boot media device.
> +
> +  The firmware boot media device is used to make system initialization
> decisions in the boot flow dependent
> +  upon firmware boot media. Note that the firmware boot media is the
> storage media that the boot firmware is stored on.
> +  It is not the OS storage media which may be stored upon a different non-
> volatile storage device.
> +
> +  This file contains implementation specific to the DXE and SMM boot phases.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/FirmwareBootMediaLib.h>
> +#include <Library/HobLib.h>
> +
> +STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia = FwBootMediaMax;
> +
> +/**
> +  Determines the current platform firmware boot media device.
> +
> +  @param[out] FwBootMediaType The current platform Boot Media type.
> +
> +  @retval     EFI_SUCCESS     The operation completed successfully.
> +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetFirmwareBootMediaType (
> +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> +  )
> +{
> +  if (mFwBootMedia == FwBootMediaMax) {
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  *FwBootMediaType = mFwBootMedia;
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Determines if the boot media is presently known.
> +
> +  Note: Very early in boot this data may not be available.
> +
> +  @retval TRUE        Boot media is known
> +  @retval FALSE       Boot media is not known
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsKnown (
> +  VOID
> +  )
> +{
> +  return mFwBootMedia != FwBootMediaMax;
> +}
> +
> +/**
> +  The library constructor.
> +
> +  This constructor depends upon gFirmwareBootMediaHobGuid.
> +  It should be produced by the platform in the HOB producer phase.
> +
> +  @param[in]  ImageHandle           The firmware allocated handle for the UEFI
> image.
> +  @param[in]  SystemTable           A pointer to the EFI system table.
> +
> +  @retval     EFI_SUCCESS           The constructor executed successfully.
> +  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid HOB
> could not be located
> +                                    or the boot media type is invalid.
> +**/
> +EFI_STATUS
> +EFIAPI
> +DxeSmmFirmwareBootMediaLibInit (
> +  IN EFI_HANDLE         ImageHandle,
> +  IN EFI_SYSTEM_TABLE   *SystemTable
> +  )
> +{
> +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> +  FW_BOOT_MEDIA_TYPE        BootMediaType;
> +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> +
> +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);
> +  if (GuidHobPtr == NULL) {
> +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> exist!\n"));
> +    ASSERT (GuidHobPtr != NULL);
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> GET_GUID_HOB_DATA (GuidHobPtr);
> +  if (BootMediaHobData == NULL) {
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  BootMediaType = BootMediaHobData->BootMedia;
> +
> +  if (BootMediaType >= FwBootMediaMax) {
> +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an
> invalid media type.\n"));
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  mFwBootMedia = BootMediaType;
> +
> +  return EFI_SUCCESS;
> +}
> diff --git
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareB
> ootMediaLib.c
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareB
> ootMediaLib.c
> new file mode 100644
> index 0000000000..11a14d172d
> --- /dev/null
> +++
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareB
> ootMediaLib.c
> @@ -0,0 +1,109 @@
> +/** @file
> +  This library identifies the firmware boot media device.
> +
> +  The firmware boot media device is used to make system initialization
> decisions in the boot flow dependent
> +  upon firmware boot media. Note that the firmware boot media is the
> storage media that the boot firmware is stored on.
> +  It is not the OS storage media which may be stored upon a different non-
> volatile storage device.
> +
> +  This file contains library implementation common to all boot phases.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/FirmwareBootMediaLib.h>
> +
> +/**
> +  Determines if the platform firmware is booting from SPI.
> +
> +  @retval TRUE        Platform firmware is booting from SPI
> +  @retval FALSE       Platform firmware is booting from a non-SPI device or
> the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsSpi (
> +  VOID
> +  )
> +{
> +  EFI_STATUS          Status;
> +  FW_BOOT_MEDIA_TYPE  BootMedia;
> +
> +  Status = GetFirmwareBootMediaType (&BootMedia);
> +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
> +    return FALSE;
> +  } else {
> +    return TRUE;
> +  }
> +}
> +
> +/**
> +  Determines if the platform firmware is booting from UFS.
> +
> +  @retval TRUE        Platform firmware is booting from UFS
> +  @retval FALSE       Platform firmware is booting from a non-UFS device or
> the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsUfs (
> +  VOID
> +  )
> +{
> +  EFI_STATUS          Status;
> +  FW_BOOT_MEDIA_TYPE  BootMedia;
> +
> +  Status = GetFirmwareBootMediaType (&BootMedia);
> +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
> +    return FALSE;
> +  } else {
> +    return TRUE;
> +  }
> +}
> +
> +/**
> +  Determines if the platform firmware is booting from eMMC.
> +
> +  @retval TRUE        Platform firmware is booting from eMMC
> +  @retval FALSE       Platform firmware is booting from a non-eMMC device
> or the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsEmmc (
> +  VOID
> +  )
> +{
> +  EFI_STATUS          Status;
> +  FW_BOOT_MEDIA_TYPE  BootMedia;
> +
> +  Status = GetFirmwareBootMediaType (&BootMedia);
> +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
> +    return FALSE;
> +  } else {
> +    return TRUE;
> +  }
> +}
> +
> +/**
> +  Determines if the platform firmware is booting from NVMe.
> +
> +  @retval TRUE        Platform firmware is booting from NVMe.
> +  @retval FALSE       Platform firmware is booting from a non-NVMe device or
> the boot media is unknown
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsNvme (
> +  VOID
> +  )
> +{
> +  EFI_STATUS          Status;
> +  FW_BOOT_MEDIA_TYPE  BootMedia;
> +
> +  Status = GetFirmwareBootMediaType (&BootMedia);
> +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
> +    return FALSE;
> +  } else {
> +    return TRUE;
> +  }
> +}
> diff --git
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> eBootMediaLib.c
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> eBootMediaLib.c
> new file mode 100644
> index 0000000000..14478e0dbe
> --- /dev/null
> +++
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> eBootMediaLib.c
> @@ -0,0 +1,82 @@
> +/** @file
> +  This library identifies the firmware boot media device.
> +
> +  The firmware boot media device is used to make system initialization
> decisions in the boot flow dependent
> +  upon firmware boot media. Note that the firmware boot media is the
> storage media that the boot firmware is stored on.
> +  It is not the OS storage media which may be stored upon a different non-
> volatile storage device.
> +
> +  This file contains implementation specific to the PEI boot phase.
> +
> +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/FirmwareBootMediaLib.h>
> +#include <Library/HobLib.h>
> +
> +/**
> +  Determines the current platform firmware boot media device.
> +
> +  @param[out] FwBootMediaType The current platform Boot Media type.
> +
> +  @retval     EFI_SUCCESS     The operation completed successfully.
> +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> +**/
> +EFI_STATUS
> +EFIAPI
> +GetFirmwareBootMediaType (
> +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> +  )
> +{
> +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> +
> +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);
> +  if (GuidHobPtr == NULL) {
> +      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> exist!\n"));
> +      ASSERT (GuidHobPtr != NULL);
> +      return EFI_NOT_FOUND;
> +  }
> +
> +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> GET_GUID_HOB_DATA (GuidHobPtr);
> +  if (BootMediaHobData == NULL) {
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
> +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an
> invalid media type.\n"));
> +    return EFI_NOT_FOUND;
> +  }
> +  *FwBootMediaType = BootMediaHobData->BootMedia;
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Determines if the boot media is presently known.
> +
> +  Note: Very early in boot this data may not be available.
> +
> +  @retval TRUE        Boot media is known
> +  @retval FALSE       Boot media is not known
> +**/
> +BOOLEAN
> +EFIAPI
> +FirmwareBootMediaIsKnown (
> +  VOID
> +  )
> +{
> +  EFI_STATUS          Status;
> +  FW_BOOT_MEDIA_TYPE  BootMedia;
> +
> +  BootMedia = FwBootMediaMax;
> +  Status = GetFirmwareBootMediaType (&BootMedia);
> +  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
> +    return FALSE;
> +  } else {
> +    return TRUE;
> +  }
> +}
> --
> 2.16.2.windows.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-09  9:35   ` Ni, Ray
@ 2019-10-09 16:33     ` Kubacki, Michael A
  2019-10-10  2:21       ` Ni, Ray
  0 siblings, 1 reply; 12+ messages in thread
From: Kubacki, Michael A @ 2019-10-09 16:33 UTC (permalink / raw)
  To: Ni, Ray, devel@edk2.groups.io; +Cc: Chaganty, Rangasai V

1. DxeSmmFirmwareBootMediaLib could get the HOB like PEI for every access. I considered this but it seems
unnecessary since we have the flexibility for  phase-specific drivers that can have trivial optimizations
like this. Checking the HOB on every access would also constrain usage in DXE_SMM_DRIVER and 
DXE_RUNTIME_DRIVER modules.

2. They are certainly not required, but in practice we've found code usage tends to read better and be more
concise with these APIs for simple firmware boot media checks. The enum is provided for relatively rarer
scenarios where many possibilities need to be considered such as usage in a switch statement. I can see a
case made in either direction. Let me know if you and Sai feel strongly about this.

Thanks,
Michael

> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Wednesday, October 9, 2019 2:36 AM
> To: Kubacki, Michael A <michael.a.kubacki@intel.com>;
> devel@edk2.groups.io
> Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> Subject: RE: [edk2-platforms][PATCH V2 1/3]
> IntelSiliconPkg/FirmwareBootMediaLib: Add library
> 
> Michael,
> Two comments:
> 1. The difference between PEI and DXE instances is DXE instance has a global
> variable caching the boot media type. Both get the type from HOB. So I am
> thinking how about simplifying the library to have only one instance which
> equals to PEI instance. That can also be used in DXE phase.
> 2. With the definition of enum type FW_BOOT_MEDIA_TYPE and GetType()
> API, I feel the other several FirmwareBootMediaIsXXX() APIs are not very
> necessary.
> 
> Thanks,
> Ray
> 
> > -----Original Message-----
> > From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> > Sent: Saturday, October 5, 2019 1:29 AM
> > To: devel@edk2.groups.io
> > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Ni, Ray
> > <ray.ni@intel.com>
> > Subject: [edk2-platforms][PATCH V2 1/3]
> > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> >
> > Adds a new library that is used to make system initialization
> > decisions in the boot flow dependent upon firmware boot media.
> > Note that the firmware boot media is the storage media that the boot
> > firmware is stored on. It is not the OS storage media which may be
> > stored upon a different non-volatile storage device.
> >
> > Any Intel board, platform, or silicon code that must take action
> > conditionally based on the firmware boot media must use this library
> > API.
> >
> > Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> > ---
> >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |   8 +-
> >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |   4 +-
> >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > wareBootMediaLib.inf |  43 ++++++++
> >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareB
> > ootMediaLib.inf    |  38 +++++++
> >  Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> > | 106 +++++++++++++++++++
> >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > wareBootMediaLib.c   | 107 +++++++++++++++++++
> >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBoo
> > tMediaLib.c         | 109 ++++++++++++++++++++
> >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareB
> > ootMediaLib.c      |  82 +++++++++++++++
> >  8 files changed, 495 insertions(+), 2 deletions(-)
> >
> > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > index fe5bfa0dc6..f70e3b977d 100644
> > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > @@ -3,7 +3,7 @@
> >  #
> >  # This package provides common open source Intel silicon modules.
> >  #
> > -# Copyright (c) 2016 - 2018, Intel Corporation. All rights
> > reserved.<BR>
> > +# Copyright (c) 2016 - 2019, Intel Corporation. All rights
> > +reserved.<BR>
> >  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -22,6 +22,10
> > @@
> >    #
> >    MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
> >
> > +  ## @libraryclass  Provides services to identify the firmware boot
> > + media
> > device.
> > +  #
> > +  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
> > +
> >  [Guids]
> >    ## GUID for Package token space
> >    # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
> > @@ -35,6 +39,8 @@
> >    ## Include/Guid/MicrocodeFmp.h
> >    gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, {
> 0x9d,
> > 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
> >
> > +  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06, {0xa4,
> > + 0x78,
> > 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
> > +
> >  [Ppis]
> >    gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97, 0x67,
> > 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
> >
> > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > index 58b5b656ef..3fb8a08b50 100644
> > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > @@ -1,7 +1,7 @@
> >  ## @file
> >  # This package provides common open source Intel silicon modules.
> >  #
> > -# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> > +# Copyright (c) 2017 - 2019, Intel Corporation. All rights
> > +reserved.<BR>
> >  #
> >  #    SPDX-License-Identifier: BSD-2-Clause-Patent
> >  #
> > @@ -80,6 +80,8 @@
> >
> >
> IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSa
> > mplePei.inf
> >
> >
> IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDx
> > e.inf
> >
> > IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/Mi
> > cro
> > codeFlashAccessLibNull.inf
> > +
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib
> > .inf
> > +
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMe
> > diaLib.inf
> >
> >  [BuildOptions]
> >    *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES diff --
> git
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > r
> > mwareBootMediaLib.inf
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > r
> > mwareBootMediaLib.inf
> > new file mode 100644
> > index 0000000000..83ed5f04af
> > --- /dev/null
> > +++
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > r
> > mwareBootMediaLib.inf
> > @@ -0,0 +1,43 @@
> > +## @file
> > +# Firmware Boot Media Library
> > +#
> > +# The firmware boot media device is used to make system
> > +initialization
> > decisions in the boot flow dependent
> > +# upon firmware boot media. Note that the firmware boot media is the
> > storage media that the boot firmware is stored on.
> > +# It is not the OS storage media which may be stored upon a different
> > +non-
> > volatile storage device.
> > +#
> > +# This library contains an implementation for the DXE and SMM boot
> phases.
> > +#
> > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> # #
> > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > +
> > +[Defines]
> > +  INF_VERSION                    = 0x00010005
> > +  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
> > +  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
> > +  MODULE_TYPE                    = DXE_DRIVER
> > +  VERSION_STRING                 = 1.0
> > +  PI_SPECIFICATION_VERSION       = 0x0001000A
> > +  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER
> > DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
> UEFI_DRIVER
> > +  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
> > +#
> > +#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
> > +#
> > +
> > +[Sources]
> > +  FirmwareBootMediaLib.c
> > +  DxeSmmFirmwareBootMediaLib.c
> > +
> > +[Packages]
> > +  MdePkg/MdePkg.dec
> > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > +
> > +[LibraryClasses]
> > +  BaseLib
> > +  DebugLib
> > +  HobLib
> > +
> > +[Guids]
> > +  gFirmwareBootMediaHobGuid       ## CONSUMES
> > diff --git
> > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > ar
> > eBootMediaLib.inf
> > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > ar
> > eBootMediaLib.inf
> > new file mode 100644
> > index 0000000000..063c4027d3
> > --- /dev/null
> > +++
> > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > ar
> > eBootMediaLib.inf
> > @@ -0,0 +1,38 @@
> > +## @file
> > +# Firmware Boot Media Library
> > +#
> > +# The firmware boot media device is used to make system
> > +initialization
> > decisions in the boot flow dependent
> > +# upon firmware boot media. Note that the firmware boot media is the
> > storage media that the boot firmware is stored on.
> > +# It is not the OS storage media which may be stored upon a different
> > +non-
> > volatile storage device.
> > +#
> > +# This library contains an implementation for the PEI boot phase.
> > +#
> > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> # #
> > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > +
> > +[Defines]
> > +  INF_VERSION          = 0x00010005
> > +  BASE_NAME            = PeiFirmwareBootMediaLib
> > +  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
> > +  MODULE_TYPE          = PEIM
> > +  VERSION_STRING       = 1.0
> > +  LIBRARY_CLASS        = FirmwareBootMediaLib
> > +
> > +[Sources]
> > +  FirmwareBootMediaLib.c
> > +  PeiFirmwareBootMediaLib.c
> > +
> > +[Packages]
> > +  MdePkg/MdePkg.dec
> > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > +
> > +[LibraryClasses]
> > +  BaseLib
> > +  DebugLib
> > +  HobLib
> > +
> > +[Guids]
> > +  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
> > diff --git
> > a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> > b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> > new file mode 100644
> > index 0000000000..aca9593a84
> > --- /dev/null
> > +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaL
> > +++ ib.h
> > @@ -0,0 +1,106 @@
> > +/** @file
> > +  This library identifies the firmware boot media device.
> > +
> > +  The firmware boot media device is used to make system
> > + initialization
> > decisions in the boot flow dependent
> > +  upon firmware boot media. Note that the firmware boot media is the
> > storage media that the boot firmware is stored on.
> > +  It is not the OS storage media which may be stored upon a different
> > + non-
> > volatile storage device.
> > +
> > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_
> > +#define _FIRMWARE_BOOT_MEDIA_LIB_H_
> > +
> > +#include <Uefi.h>
> > +
> > +typedef enum {
> > +  FwBootMediaSpi,
> > +  FwBootMediaUfs,
> > +  FwBootMediaEmmc,
> > +  FwBootMediaNvme,
> > +  FwBootMediaMax
> > +} FW_BOOT_MEDIA_TYPE;
> > +
> > +typedef struct {
> > +  FW_BOOT_MEDIA_TYPE BootMedia;
> > +} FW_BOOT_MEDIA_HOB_DATA;
> > +
> > +/**
> > +  Determines the current platform firmware boot media device.
> > +
> > +  @param[out] FwBootMediaType The current platform Boot Media type.
> > +
> > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +GetFirmwareBootMediaType (
> > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > +  );
> > +
> > +/**
> > +  Indicates whether the boot media is presently known.
> > +
> > +  Note: Very early in boot this data may not be available.
> > +
> > +  @retval TRUE        Boot media is known
> > +  @retval FALSE       Boot media is not known
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsKnown (
> > +  VOID
> > +  );
> > +
> > +/**
> > +  Determines if the platform firmware is booting from SPI.
> > +
> > +  @retval TRUE        Platform firmware is booting from SPI
> > +  @retval FALSE       Platform firmware is booting from a non-SPI device or
> > the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsSpi (
> > +  VOID
> > +  );
> > +
> > +/**
> > +  Determines if the platform firmware is booting from UFS.
> > +
> > +  @retval TRUE        Platform firmware is booting from UFS
> > +  @retval FALSE       Platform firmware is booting from a non-UFS device or
> > the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsUfs (
> > +  VOID
> > +  );
> > +
> > +/**
> > +  Determines if the platform firmware is booting from eMMC.
> > +
> > +  @retval TRUE        Platform firmware is booting from eMMC
> > +  @retval FALSE       Platform firmware is booting from a non-eMMC device
> > or the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsEmmc (
> > +  VOID
> > +  );
> > +
> > +/**
> > +  Determines if the platform firmware is booting from NVMe.
> > +
> > +  @retval TRUE        Platform firmware is booting from NVMe.
> > +  @retval FALSE       Platform firmware is booting from a non-NVMe device
> or
> > the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsNvme (
> > +  VOID
> > +  );
> > +
> > +#endif
> > diff --git
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > r
> > mwareBootMediaLib.c
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > r
> > mwareBootMediaLib.c
> > new file mode 100644
> > index 0000000000..1e3876afb3
> > --- /dev/null
> > +++
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > r
> > mwareBootMediaLib.c
> > @@ -0,0 +1,107 @@
> > +/** @file
> > +  This library identifies the firmware boot media device.
> > +
> > +  The firmware boot media device is used to make system
> > + initialization
> > decisions in the boot flow dependent
> > +  upon firmware boot media. Note that the firmware boot media is the
> > storage media that the boot firmware is stored on.
> > +  It is not the OS storage media which may be stored upon a different
> > + non-
> > volatile storage device.
> > +
> > +  This file contains implementation specific to the DXE and SMM boot
> phases.
> > +
> > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include <Library/BaseLib.h>
> > +#include <Library/DebugLib.h>
> > +#include <Library/FirmwareBootMediaLib.h> #include <Library/HobLib.h>
> > +
> > +STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia = FwBootMediaMax;
> > +
> > +/**
> > +  Determines the current platform firmware boot media device.
> > +
> > +  @param[out] FwBootMediaType The current platform Boot Media type.
> > +
> > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +GetFirmwareBootMediaType (
> > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > +  )
> > +{
> > +  if (mFwBootMedia == FwBootMediaMax) {
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> > +  *FwBootMediaType = mFwBootMedia;
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +  Determines if the boot media is presently known.
> > +
> > +  Note: Very early in boot this data may not be available.
> > +
> > +  @retval TRUE        Boot media is known
> > +  @retval FALSE       Boot media is not known
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsKnown (
> > +  VOID
> > +  )
> > +{
> > +  return mFwBootMedia != FwBootMediaMax; }
> > +
> > +/**
> > +  The library constructor.
> > +
> > +  This constructor depends upon gFirmwareBootMediaHobGuid.
> > +  It should be produced by the platform in the HOB producer phase.
> > +
> > +  @param[in]  ImageHandle           The firmware allocated handle for the
> UEFI
> > image.
> > +  @param[in]  SystemTable           A pointer to the EFI system table.
> > +
> > +  @retval     EFI_SUCCESS           The constructor executed successfully.
> > +  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid HOB
> > could not be located
> > +                                    or the boot media type is invalid.
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +DxeSmmFirmwareBootMediaLibInit (
> > +  IN EFI_HANDLE         ImageHandle,
> > +  IN EFI_SYSTEM_TABLE   *SystemTable
> > +  )
> > +{
> > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > +  FW_BOOT_MEDIA_TYPE        BootMediaType;
> > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > +
> > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if
> > + (GuidHobPtr == NULL) {
> > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > exist!\n"));
> > +    ASSERT (GuidHobPtr != NULL);
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > GET_GUID_HOB_DATA (GuidHobPtr);
> > +  if (BootMediaHobData == NULL) {
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> > +  BootMediaType = BootMediaHobData->BootMedia;
> > +
> > +  if (BootMediaType >= FwBootMediaMax) {
> > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an
> > invalid media type.\n"));
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> > +  mFwBootMedia = BootMediaType;
> > +
> > +  return EFI_SUCCESS;
> > +}
> > diff --git
> > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmware
> > B
> > ootMediaLib.c
> > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmware
> > B
> > ootMediaLib.c
> > new file mode 100644
> > index 0000000000..11a14d172d
> > --- /dev/null
> > +++
> > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmware
> > B
> > ootMediaLib.c
> > @@ -0,0 +1,109 @@
> > +/** @file
> > +  This library identifies the firmware boot media device.
> > +
> > +  The firmware boot media device is used to make system
> > + initialization
> > decisions in the boot flow dependent
> > +  upon firmware boot media. Note that the firmware boot media is the
> > storage media that the boot firmware is stored on.
> > +  It is not the OS storage media which may be stored upon a different
> > + non-
> > volatile storage device.
> > +
> > +  This file contains library implementation common to all boot phases.
> > +
> > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include <Library/BaseLib.h>
> > +#include <Library/DebugLib.h>
> > +#include <Library/FirmwareBootMediaLib.h>
> > +
> > +/**
> > +  Determines if the platform firmware is booting from SPI.
> > +
> > +  @retval TRUE        Platform firmware is booting from SPI
> > +  @retval FALSE       Platform firmware is booting from a non-SPI device or
> > the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsSpi (
> > +  VOID
> > +  )
> > +{
> > +  EFI_STATUS          Status;
> > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > +
> > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
> > +    return FALSE;
> > +  } else {
> > +    return TRUE;
> > +  }
> > +}
> > +
> > +/**
> > +  Determines if the platform firmware is booting from UFS.
> > +
> > +  @retval TRUE        Platform firmware is booting from UFS
> > +  @retval FALSE       Platform firmware is booting from a non-UFS device or
> > the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsUfs (
> > +  VOID
> > +  )
> > +{
> > +  EFI_STATUS          Status;
> > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > +
> > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
> > +    return FALSE;
> > +  } else {
> > +    return TRUE;
> > +  }
> > +}
> > +
> > +/**
> > +  Determines if the platform firmware is booting from eMMC.
> > +
> > +  @retval TRUE        Platform firmware is booting from eMMC
> > +  @retval FALSE       Platform firmware is booting from a non-eMMC device
> > or the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsEmmc (
> > +  VOID
> > +  )
> > +{
> > +  EFI_STATUS          Status;
> > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > +
> > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
> > +    return FALSE;
> > +  } else {
> > +    return TRUE;
> > +  }
> > +}
> > +
> > +/**
> > +  Determines if the platform firmware is booting from NVMe.
> > +
> > +  @retval TRUE        Platform firmware is booting from NVMe.
> > +  @retval FALSE       Platform firmware is booting from a non-NVMe device
> or
> > the boot media is unknown
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsNvme (
> > +  VOID
> > +  )
> > +{
> > +  EFI_STATUS          Status;
> > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > +
> > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
> > +    return FALSE;
> > +  } else {
> > +    return TRUE;
> > +  }
> > +}
> > diff --git
> > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > ar
> > eBootMediaLib.c
> > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > ar
> > eBootMediaLib.c
> > new file mode 100644
> > index 0000000000..14478e0dbe
> > --- /dev/null
> > +++
> > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > ar
> > eBootMediaLib.c
> > @@ -0,0 +1,82 @@
> > +/** @file
> > +  This library identifies the firmware boot media device.
> > +
> > +  The firmware boot media device is used to make system
> > + initialization
> > decisions in the boot flow dependent
> > +  upon firmware boot media. Note that the firmware boot media is the
> > storage media that the boot firmware is stored on.
> > +  It is not the OS storage media which may be stored upon a different
> > + non-
> > volatile storage device.
> > +
> > +  This file contains implementation specific to the PEI boot phase.
> > +
> > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include <Library/BaseLib.h>
> > +#include <Library/DebugLib.h>
> > +#include <Library/FirmwareBootMediaLib.h> #include <Library/HobLib.h>
> > +
> > +/**
> > +  Determines the current platform firmware boot media device.
> > +
> > +  @param[out] FwBootMediaType The current platform Boot Media type.
> > +
> > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +GetFirmwareBootMediaType (
> > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > +  )
> > +{
> > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > +
> > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if
> > + (GuidHobPtr == NULL) {
> > +      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > exist!\n"));
> > +      ASSERT (GuidHobPtr != NULL);
> > +      return EFI_NOT_FOUND;
> > +  }
> > +
> > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > GET_GUID_HOB_DATA (GuidHobPtr);
> > +  if (BootMediaHobData == NULL) {
> > +    return EFI_NOT_FOUND;
> > +  }
> > +
> > +  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
> > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an
> > invalid media type.\n"));
> > +    return EFI_NOT_FOUND;
> > +  }
> > +  *FwBootMediaType = BootMediaHobData->BootMedia;
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +  Determines if the boot media is presently known.
> > +
> > +  Note: Very early in boot this data may not be available.
> > +
> > +  @retval TRUE        Boot media is known
> > +  @retval FALSE       Boot media is not known
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +FirmwareBootMediaIsKnown (
> > +  VOID
> > +  )
> > +{
> > +  EFI_STATUS          Status;
> > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > +
> > +  BootMedia = FwBootMediaMax;
> > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > +  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
> > +    return FALSE;
> > +  } else {
> > +    return TRUE;
> > +  }
> > +}
> > --
> > 2.16.2.windows.1
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-09 16:33     ` Kubacki, Michael A
@ 2019-10-10  2:21       ` Ni, Ray
  2019-10-10  4:42         ` Kubacki, Michael A
  0 siblings, 1 reply; 12+ messages in thread
From: Ni, Ray @ 2019-10-10  2:21 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Chaganty, Rangasai V

Comments below.

> -----Original Message-----
> From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> Sent: Thursday, October 10, 2019 12:34 AM
> To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
> Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> Subject: RE: [edk2-platforms][PATCH V2 1/3]
> IntelSiliconPkg/FirmwareBootMediaLib: Add library
> 
> 1. DxeSmmFirmwareBootMediaLib could get the HOB like PEI for every
> access. I considered this but it seems unnecessary since we have the
> flexibility for  phase-specific drivers that can have trivial optimizations like this.
> Checking the HOB on every access would also constrain usage in
> DXE_SMM_DRIVER and DXE_RUNTIME_DRIVER modules.

Having single library instance can make platform DSC simpler.
Because SMM and Runtime drivers are dispatched in BS phase, they can cache the
boot media type if the usage lasts to post-EndOfDxe or OS runtime.

> 
> 2. They are certainly not required, but in practice we've found code usage
> tends to read better and be more concise with these APIs for simple
> firmware boot media checks. The enum is provided for relatively rarer
> scenarios where many possibilities need to be considered such as usage in a
> switch statement. I can see a case made in either direction. Let me know if
> you and Sai feel strongly about this.

I prefer to use enum and GetType() API. Because if there is more boot media type,
there is no need to add a new library API like IsXXX().
Not sure if it's over design, I prefer to use GUID against enum. No strong preference
of using GUID in this case.

Thanks,
Ray

> 
> Thanks,
> Michael
> 
> > -----Original Message-----
> > From: Ni, Ray <ray.ni@intel.com>
> > Sent: Wednesday, October 9, 2019 2:36 AM
> > To: Kubacki, Michael A <michael.a.kubacki@intel.com>;
> > devel@edk2.groups.io
> > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> > Subject: RE: [edk2-platforms][PATCH V2 1/3]
> > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> >
> > Michael,
> > Two comments:
> > 1. The difference between PEI and DXE instances is DXE instance has a
> > global variable caching the boot media type. Both get the type from
> > HOB. So I am thinking how about simplifying the library to have only
> > one instance which equals to PEI instance. That can also be used in DXE
> phase.
> > 2. With the definition of enum type FW_BOOT_MEDIA_TYPE and GetType()
> > API, I feel the other several FirmwareBootMediaIsXXX() APIs are not
> > very necessary.
> >
> > Thanks,
> > Ray
> >
> > > -----Original Message-----
> > > From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> > > Sent: Saturday, October 5, 2019 1:29 AM
> > > To: devel@edk2.groups.io
> > > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Ni, Ray
> > > <ray.ni@intel.com>
> > > Subject: [edk2-platforms][PATCH V2 1/3]
> > > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> > >
> > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> > >
> > > Adds a new library that is used to make system initialization
> > > decisions in the boot flow dependent upon firmware boot media.
> > > Note that the firmware boot media is the storage media that the boot
> > > firmware is stored on. It is not the OS storage media which may be
> > > stored upon a different non-volatile storage device.
> > >
> > > Any Intel board, platform, or silicon code that must take action
> > > conditionally based on the firmware boot media must use this library
> > > API.
> > >
> > > Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> > > Cc: Ray Ni <ray.ni@intel.com>
> > > Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> > > ---
> > >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |   8
> +-
> > >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |   4
> +-
> > >
> > >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > > wareBootMediaLib.inf |  43 ++++++++
> > >
> > >
> > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> > eB
> > > ootMediaLib.inf    |  38 +++++++
> > >
> > > Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib.h
> > > | 106 +++++++++++++++++++
> > >
> > >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > > wareBootMediaLib.c   | 107 +++++++++++++++++++
> > >
> > >
> > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/FirmwareBo
> > o
> > > tMediaLib.c         | 109 ++++++++++++++++++++
> > >
> > >
> > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwar
> > eB
> > > ootMediaLib.c      |  82 +++++++++++++++
> > >  8 files changed, 495 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > index fe5bfa0dc6..f70e3b977d 100644
> > > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > @@ -3,7 +3,7 @@
> > >  #
> > >  # This package provides common open source Intel silicon modules.
> > >  #
> > > -# Copyright (c) 2016 - 2018, Intel Corporation. All rights
> > > reserved.<BR>
> > > +# Copyright (c) 2016 - 2019, Intel Corporation. All rights
> > > +reserved.<BR>
> > >  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -22,6
> > > +22,10 @@
> > >    #
> > >    MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
> > >
> > > +  ## @libraryclass  Provides services to identify the firmware boot
> > > + media
> > > device.
> > > +  #
> > > +  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
> > > +
> > >  [Guids]
> > >    ## GUID for Package token space
> > >    # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
> > > @@ -35,6 +39,8 @@
> > >    ## Include/Guid/MicrocodeFmp.h
> > >    gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, {
> > 0x9d,
> > > 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
> > >
> > > +  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06, {0xa4,
> > > + 0x78,
> > > 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
> > > +
> > >  [Ppis]
> > >    gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97,
> > > 0x67, 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
> > >
> > > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > index 58b5b656ef..3fb8a08b50 100644
> > > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > @@ -1,7 +1,7 @@
> > >  ## @file
> > >  # This package provides common open source Intel silicon modules.
> > >  #
> > > -# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> > > +# Copyright (c) 2017 - 2019, Intel Corporation. All rights
> > > +reserved.<BR>
> > >  #
> > >  #    SPDX-License-Identifier: BSD-2-Clause-Patent
> > >  #
> > > @@ -80,6 +80,8 @@
> > >
> > >
> >
> IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSa
> > > mplePei.inf
> > >
> > >
> >
> IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDx
> > > e.inf
> > >
> > > IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNull/
> > > Mi
> > > cro
> > > codeFlashAccessLibNull.inf
> > > +
> > >
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib
> > > .inf
> > > +
> > >
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMe
> > > diaLib.inf
> > >
> > >  [BuildOptions]
> > >    *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES diff --
> > git
> > >
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > r
> > > mwareBootMediaLib.inf
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > r
> > > mwareBootMediaLib.inf
> > > new file mode 100644
> > > index 0000000000..83ed5f04af
> > > --- /dev/null
> > > +++
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > r
> > > mwareBootMediaLib.inf
> > > @@ -0,0 +1,43 @@
> > > +## @file
> > > +# Firmware Boot Media Library
> > > +#
> > > +# The firmware boot media device is used to make system
> > > +initialization
> > > decisions in the boot flow dependent
> > > +# upon firmware boot media. Note that the firmware boot media is
> > > +the
> > > storage media that the boot firmware is stored on.
> > > +# It is not the OS storage media which may be stored upon a
> > > +different
> > > +non-
> > > volatile storage device.
> > > +#
> > > +# This library contains an implementation for the DXE and SMM boot
> > phases.
> > > +#
> > > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> #
> > > +#
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > +
> > > +[Defines]
> > > +  INF_VERSION                    = 0x00010005
> > > +  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
> > > +  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
> > > +  MODULE_TYPE                    = DXE_DRIVER
> > > +  VERSION_STRING                 = 1.0
> > > +  PI_SPECIFICATION_VERSION       = 0x0001000A
> > > +  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER
> > > DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
> > UEFI_DRIVER
> > > +  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
> > > +#
> > > +#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
> > > +#
> > > +
> > > +[Sources]
> > > +  FirmwareBootMediaLib.c
> > > +  DxeSmmFirmwareBootMediaLib.c
> > > +
> > > +[Packages]
> > > +  MdePkg/MdePkg.dec
> > > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > > +
> > > +[LibraryClasses]
> > > +  BaseLib
> > > +  DebugLib
> > > +  HobLib
> > > +
> > > +[Guids]
> > > +  gFirmwareBootMediaHobGuid       ## CONSUMES
> > > diff --git
> > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > mw
> > > ar
> > > eBootMediaLib.inf
> > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > mw
> > > ar
> > > eBootMediaLib.inf
> > > new file mode 100644
> > > index 0000000000..063c4027d3
> > > --- /dev/null
> > > +++
> > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > mw
> > > ar
> > > eBootMediaLib.inf
> > > @@ -0,0 +1,38 @@
> > > +## @file
> > > +# Firmware Boot Media Library
> > > +#
> > > +# The firmware boot media device is used to make system
> > > +initialization
> > > decisions in the boot flow dependent
> > > +# upon firmware boot media. Note that the firmware boot media is
> > > +the
> > > storage media that the boot firmware is stored on.
> > > +# It is not the OS storage media which may be stored upon a
> > > +different
> > > +non-
> > > volatile storage device.
> > > +#
> > > +# This library contains an implementation for the PEI boot phase.
> > > +#
> > > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> #
> > > +#
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > +
> > > +[Defines]
> > > +  INF_VERSION          = 0x00010005
> > > +  BASE_NAME            = PeiFirmwareBootMediaLib
> > > +  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
> > > +  MODULE_TYPE          = PEIM
> > > +  VERSION_STRING       = 1.0
> > > +  LIBRARY_CLASS        = FirmwareBootMediaLib
> > > +
> > > +[Sources]
> > > +  FirmwareBootMediaLib.c
> > > +  PeiFirmwareBootMediaLib.c
> > > +
> > > +[Packages]
> > > +  MdePkg/MdePkg.dec
> > > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > > +
> > > +[LibraryClasses]
> > > +  BaseLib
> > > +  DebugLib
> > > +  HobLib
> > > +
> > > +[Guids]
> > > +  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
> > > diff --git
> > > a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib
> > > .h
> > > b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib
> > > .h
> > > new file mode 100644
> > > index 0000000000..aca9593a84
> > > --- /dev/null
> > > +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMedi
> > > +++ aL
> > > +++ ib.h
> > > @@ -0,0 +1,106 @@
> > > +/** @file
> > > +  This library identifies the firmware boot media device.
> > > +
> > > +  The firmware boot media device is used to make system
> > > + initialization
> > > decisions in the boot flow dependent
> > > +  upon firmware boot media. Note that the firmware boot media is
> > > + the
> > > storage media that the boot firmware is stored on.
> > > +  It is not the OS storage media which may be stored upon a
> > > + different
> > > + non-
> > > volatile storage device.
> > > +
> > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > > +
> > > +#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_ #define
> > > +_FIRMWARE_BOOT_MEDIA_LIB_H_
> > > +
> > > +#include <Uefi.h>
> > > +
> > > +typedef enum {
> > > +  FwBootMediaSpi,
> > > +  FwBootMediaUfs,
> > > +  FwBootMediaEmmc,
> > > +  FwBootMediaNvme,
> > > +  FwBootMediaMax
> > > +} FW_BOOT_MEDIA_TYPE;
> > > +
> > > +typedef struct {
> > > +  FW_BOOT_MEDIA_TYPE BootMedia;
> > > +} FW_BOOT_MEDIA_HOB_DATA;
> > > +
> > > +/**
> > > +  Determines the current platform firmware boot media device.
> > > +
> > > +  @param[out] FwBootMediaType The current platform Boot Media
> type.
> > > +
> > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +GetFirmwareBootMediaType (
> > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > +  );
> > > +
> > > +/**
> > > +  Indicates whether the boot media is presently known.
> > > +
> > > +  Note: Very early in boot this data may not be available.
> > > +
> > > +  @retval TRUE        Boot media is known
> > > +  @retval FALSE       Boot media is not known
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsKnown (
> > > +  VOID
> > > +  );
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from SPI.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from SPI
> > > +  @retval FALSE       Platform firmware is booting from a non-SPI device
> or
> > > the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsSpi (
> > > +  VOID
> > > +  );
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from UFS.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from UFS
> > > +  @retval FALSE       Platform firmware is booting from a non-UFS device
> or
> > > the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsUfs (
> > > +  VOID
> > > +  );
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from eMMC.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from eMMC
> > > +  @retval FALSE       Platform firmware is booting from a non-eMMC
> device
> > > or the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsEmmc (
> > > +  VOID
> > > +  );
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from NVMe.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from NVMe.
> > > +  @retval FALSE       Platform firmware is booting from a non-NVMe
> device
> > or
> > > the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsNvme (
> > > +  VOID
> > > +  );
> > > +
> > > +#endif
> > > diff --git
> > >
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > r
> > > mwareBootMediaLib.c
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > r
> > > mwareBootMediaLib.c
> > > new file mode 100644
> > > index 0000000000..1e3876afb3
> > > --- /dev/null
> > > +++
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > r
> > > mwareBootMediaLib.c
> > > @@ -0,0 +1,107 @@
> > > +/** @file
> > > +  This library identifies the firmware boot media device.
> > > +
> > > +  The firmware boot media device is used to make system
> > > + initialization
> > > decisions in the boot flow dependent
> > > +  upon firmware boot media. Note that the firmware boot media is
> > > + the
> > > storage media that the boot firmware is stored on.
> > > +  It is not the OS storage media which may be stored upon a
> > > + different
> > > + non-
> > > volatile storage device.
> > > +
> > > +  This file contains implementation specific to the DXE and SMM
> > > + boot
> > phases.
> > > +
> > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > > +
> > > +#include <Library/BaseLib.h>
> > > +#include <Library/DebugLib.h>
> > > +#include <Library/FirmwareBootMediaLib.h> #include
> > > +<Library/HobLib.h>
> > > +
> > > +STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia = FwBootMediaMax;
> > > +
> > > +/**
> > > +  Determines the current platform firmware boot media device.
> > > +
> > > +  @param[out] FwBootMediaType The current platform Boot Media
> type.
> > > +
> > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +GetFirmwareBootMediaType (
> > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > +  )
> > > +{
> > > +  if (mFwBootMedia == FwBootMediaMax) {
> > > +    return EFI_NOT_FOUND;
> > > +  }
> > > +
> > > +  *FwBootMediaType = mFwBootMedia;
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +/**
> > > +  Determines if the boot media is presently known.
> > > +
> > > +  Note: Very early in boot this data may not be available.
> > > +
> > > +  @retval TRUE        Boot media is known
> > > +  @retval FALSE       Boot media is not known
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsKnown (
> > > +  VOID
> > > +  )
> > > +{
> > > +  return mFwBootMedia != FwBootMediaMax; }
> > > +
> > > +/**
> > > +  The library constructor.
> > > +
> > > +  This constructor depends upon gFirmwareBootMediaHobGuid.
> > > +  It should be produced by the platform in the HOB producer phase.
> > > +
> > > +  @param[in]  ImageHandle           The firmware allocated handle for the
> > UEFI
> > > image.
> > > +  @param[in]  SystemTable           A pointer to the EFI system table.
> > > +
> > > +  @retval     EFI_SUCCESS           The constructor executed successfully.
> > > +  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid
> HOB
> > > could not be located
> > > +                                    or the boot media type is invalid.
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +DxeSmmFirmwareBootMediaLibInit (
> > > +  IN EFI_HANDLE         ImageHandle,
> > > +  IN EFI_SYSTEM_TABLE   *SystemTable
> > > +  )
> > > +{
> > > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > > +  FW_BOOT_MEDIA_TYPE        BootMediaType;
> > > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > > +
> > > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if
> > > + (GuidHobPtr == NULL) {
> > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > > exist!\n"));
> > > +    ASSERT (GuidHobPtr != NULL);
> > > +    return EFI_NOT_FOUND;
> > > +  }
> > > +
> > > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > > GET_GUID_HOB_DATA (GuidHobPtr);
> > > +  if (BootMediaHobData == NULL) {
> > > +    return EFI_NOT_FOUND;
> > > +  }
> > > +
> > > +  BootMediaType = BootMediaHobData->BootMedia;
> > > +
> > > +  if (BootMediaType >= FwBootMediaMax) {
> > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an
> > > invalid media type.\n"));
> > > +    return EFI_NOT_FOUND;
> > > +  }
> > > +
> > > +  mFwBootMedia = BootMediaType;
> > > +
> > > +  return EFI_SUCCESS;
> > > +}
> > > diff --git
> > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmwa
> > > re
> > > B
> > > ootMediaLib.c
> > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmwa
> > > re
> > > B
> > > ootMediaLib.c
> > > new file mode 100644
> > > index 0000000000..11a14d172d
> > > --- /dev/null
> > > +++
> > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmwa
> > > re
> > > B
> > > ootMediaLib.c
> > > @@ -0,0 +1,109 @@
> > > +/** @file
> > > +  This library identifies the firmware boot media device.
> > > +
> > > +  The firmware boot media device is used to make system
> > > + initialization
> > > decisions in the boot flow dependent
> > > +  upon firmware boot media. Note that the firmware boot media is
> > > + the
> > > storage media that the boot firmware is stored on.
> > > +  It is not the OS storage media which may be stored upon a
> > > + different
> > > + non-
> > > volatile storage device.
> > > +
> > > +  This file contains library implementation common to all boot phases.
> > > +
> > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > > +
> > > +#include <Library/BaseLib.h>
> > > +#include <Library/DebugLib.h>
> > > +#include <Library/FirmwareBootMediaLib.h>
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from SPI.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from SPI
> > > +  @retval FALSE       Platform firmware is booting from a non-SPI device
> or
> > > the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsSpi (
> > > +  VOID
> > > +  )
> > > +{
> > > +  EFI_STATUS          Status;
> > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > +
> > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
> > > +    return FALSE;
> > > +  } else {
> > > +    return TRUE;
> > > +  }
> > > +}
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from UFS.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from UFS
> > > +  @retval FALSE       Platform firmware is booting from a non-UFS device
> or
> > > the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsUfs (
> > > +  VOID
> > > +  )
> > > +{
> > > +  EFI_STATUS          Status;
> > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > +
> > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
> > > +    return FALSE;
> > > +  } else {
> > > +    return TRUE;
> > > +  }
> > > +}
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from eMMC.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from eMMC
> > > +  @retval FALSE       Platform firmware is booting from a non-eMMC
> device
> > > or the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsEmmc (
> > > +  VOID
> > > +  )
> > > +{
> > > +  EFI_STATUS          Status;
> > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > +
> > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
> > > +    return FALSE;
> > > +  } else {
> > > +    return TRUE;
> > > +  }
> > > +}
> > > +
> > > +/**
> > > +  Determines if the platform firmware is booting from NVMe.
> > > +
> > > +  @retval TRUE        Platform firmware is booting from NVMe.
> > > +  @retval FALSE       Platform firmware is booting from a non-NVMe
> device
> > or
> > > the boot media is unknown
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsNvme (
> > > +  VOID
> > > +  )
> > > +{
> > > +  EFI_STATUS          Status;
> > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > +
> > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
> > > +    return FALSE;
> > > +  } else {
> > > +    return TRUE;
> > > +  }
> > > +}
> > > diff --git
> > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > mw
> > > ar
> > > eBootMediaLib.c
> > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > mw
> > > ar
> > > eBootMediaLib.c
> > > new file mode 100644
> > > index 0000000000..14478e0dbe
> > > --- /dev/null
> > > +++
> > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > mw
> > > ar
> > > eBootMediaLib.c
> > > @@ -0,0 +1,82 @@
> > > +/** @file
> > > +  This library identifies the firmware boot media device.
> > > +
> > > +  The firmware boot media device is used to make system
> > > + initialization
> > > decisions in the boot flow dependent
> > > +  upon firmware boot media. Note that the firmware boot media is
> > > + the
> > > storage media that the boot firmware is stored on.
> > > +  It is not the OS storage media which may be stored upon a
> > > + different
> > > + non-
> > > volatile storage device.
> > > +
> > > +  This file contains implementation specific to the PEI boot phase.
> > > +
> > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > > +
> > > +#include <Library/BaseLib.h>
> > > +#include <Library/DebugLib.h>
> > > +#include <Library/FirmwareBootMediaLib.h> #include
> > > +<Library/HobLib.h>
> > > +
> > > +/**
> > > +  Determines the current platform firmware boot media device.
> > > +
> > > +  @param[out] FwBootMediaType The current platform Boot Media
> type.
> > > +
> > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > +  @retval     EFI_NOT_FOUND   The boot media type could not be found.
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +GetFirmwareBootMediaType (
> > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > +  )
> > > +{
> > > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > > +
> > > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if
> > > + (GuidHobPtr == NULL) {
> > > +      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > > exist!\n"));
> > > +      ASSERT (GuidHobPtr != NULL);
> > > +      return EFI_NOT_FOUND;
> > > +  }
> > > +
> > > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > > GET_GUID_HOB_DATA (GuidHobPtr);
> > > +  if (BootMediaHobData == NULL) {
> > > +    return EFI_NOT_FOUND;
> > > +  }
> > > +
> > > +  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
> > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies an
> > > invalid media type.\n"));
> > > +    return EFI_NOT_FOUND;
> > > +  }
> > > +  *FwBootMediaType = BootMediaHobData->BootMedia;
> > > +
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +/**
> > > +  Determines if the boot media is presently known.
> > > +
> > > +  Note: Very early in boot this data may not be available.
> > > +
> > > +  @retval TRUE        Boot media is known
> > > +  @retval FALSE       Boot media is not known
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +FirmwareBootMediaIsKnown (
> > > +  VOID
> > > +  )
> > > +{
> > > +  EFI_STATUS          Status;
> > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > +
> > > +  BootMedia = FwBootMediaMax;
> > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > +  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
> > > +    return FALSE;
> > > +  } else {
> > > +    return TRUE;
> > > +  }
> > > +}
> > > --
> > > 2.16.2.windows.1
> >
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-10  2:21       ` Ni, Ray
@ 2019-10-10  4:42         ` Kubacki, Michael A
  2019-10-10  5:44           ` Ni, Ray
  0 siblings, 1 reply; 12+ messages in thread
From: Kubacki, Michael A @ 2019-10-10  4:42 UTC (permalink / raw)
  To: Ni, Ray, devel@edk2.groups.io; +Cc: Chaganty, Rangasai V

Replies below.

> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Wednesday, October 9, 2019 7:21 PM
> To: Kubacki, Michael A <michael.a.kubacki@intel.com>;
> devel@edk2.groups.io
> Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> Subject: RE: [edk2-platforms][PATCH V2 1/3]
> IntelSiliconPkg/FirmwareBootMediaLib: Add library
> 
> Comments below.
> 
> > -----Original Message-----
> > From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> > Sent: Thursday, October 10, 2019 12:34 AM
> > To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
> > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> > Subject: RE: [edk2-platforms][PATCH V2 1/3]
> > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> >
> > 1. DxeSmmFirmwareBootMediaLib could get the HOB like PEI for every
> > access. I considered this but it seems unnecessary since we have the
> > flexibility for  phase-specific drivers that can have trivial optimizations like
> this.
> > Checking the HOB on every access would also constrain usage in
> > DXE_SMM_DRIVER and DXE_RUNTIME_DRIVER modules.
> 
> Having single library instance can make platform DSC simpler.
> Because SMM and Runtime drivers are dispatched in BS phase, they can
> cache the boot media type if the usage lasts to post-EndOfDxe or OS
> runtime.
> 

I don't see an issue with phase-specific instances that cleanly comply with
phase restrictions.

In general, PEI drivers cannot write to global variables. This change does
cache the value in BS phase so it is available in OS runtime.

 * PEI: Do not write to a global variable. Use the heap to store the value via
the HOB list. Always get the value from the HOB.
 * DXE: Get the value from the HOB and store the value in a global variable
during the library constructor in the BS phase so the value is available during
later phase transition.

What exactly are you proposing to change?

> >
> > 2. They are certainly not required, but in practice we've found code
> > usage tends to read better and be more concise with these APIs for
> > simple firmware boot media checks. The enum is provided for relatively
> > rarer scenarios where many possibilities need to be considered such as
> > usage in a switch statement. I can see a case made in either
> > direction. Let me know if you and Sai feel strongly about this.
> 
> I prefer to use enum and GetType() API. Because if there is more boot media
> type, there is no need to add a new library API like IsXXX().
> Not sure if it's over design, I prefer to use GUID against enum. No strong
> preference of using GUID in this case.
> 

My preference is that the API is well-defined and stable. In this case, my primary
thought  on the matter is not having two ways to do the same thing. And again,
I have no strong preference for either case but we do have Intel code that favors
the IsXXX () usage. I don't think adding new devices (extending the API) is so much an
issue as ensuring the existing ones are not modified. Which would be the case for
the enum members and the functions. In conclusion, I will send a patch to remove
the IsXXX () functions.

Before adding GUIDs, the problem statement needs to be clearly articulated
that justifies introducing GUID management.

> Thanks,
> Ray
> 
> >
> > Thanks,
> > Michael
> >
> > > -----Original Message-----
> > > From: Ni, Ray <ray.ni@intel.com>
> > > Sent: Wednesday, October 9, 2019 2:36 AM
> > > To: Kubacki, Michael A <michael.a.kubacki@intel.com>;
> > > devel@edk2.groups.io
> > > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> > > Subject: RE: [edk2-platforms][PATCH V2 1/3]
> > > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> > >
> > > Michael,
> > > Two comments:
> > > 1. The difference between PEI and DXE instances is DXE instance has
> > > a global variable caching the boot media type. Both get the type
> > > from HOB. So I am thinking how about simplifying the library to have
> > > only one instance which equals to PEI instance. That can also be
> > > used in DXE
> > phase.
> > > 2. With the definition of enum type FW_BOOT_MEDIA_TYPE and
> GetType()
> > > API, I feel the other several FirmwareBootMediaIsXXX() APIs are not
> > > very necessary.
> > >
> > > Thanks,
> > > Ray
> > >
> > > > -----Original Message-----
> > > > From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> > > > Sent: Saturday, October 5, 2019 1:29 AM
> > > > To: devel@edk2.groups.io
> > > > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Ni, Ray
> > > > <ray.ni@intel.com>
> > > > Subject: [edk2-platforms][PATCH V2 1/3]
> > > > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> > > >
> > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> > > >
> > > > Adds a new library that is used to make system initialization
> > > > decisions in the boot flow dependent upon firmware boot media.
> > > > Note that the firmware boot media is the storage media that the
> > > > boot firmware is stored on. It is not the OS storage media which
> > > > may be stored upon a different non-volatile storage device.
> > > >
> > > > Any Intel board, platform, or silicon code that must take action
> > > > conditionally based on the firmware boot media must use this
> > > > library API.
> > > >
> > > > Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> > > > Cc: Ray Ni <ray.ni@intel.com>
> > > > Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> > > > ---
> > > >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |
> 8
> > +-
> > > >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |   4
> > +-
> > > >
> > > >
> > >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > > > wareBootMediaLib.inf |  43 ++++++++
> > > >
> > > >
> > > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > > ar
> > > eB
> > > > ootMediaLib.inf    |  38 +++++++
> > > >
> > > > Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaLib
> > > > .h
> > > > | 106 +++++++++++++++++++
> > > >
> > > >
> > >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > > > wareBootMediaLib.c   | 107 +++++++++++++++++++
> > > >
> > > >
> > > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmware
> > > Bo
> > > o
> > > > tMediaLib.c         | 109 ++++++++++++++++++++
> > > >
> > > >
> > > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmw
> > > ar
> > > eB
> > > > ootMediaLib.c      |  82 +++++++++++++++
> > > >  8 files changed, 495 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > index fe5bfa0dc6..f70e3b977d 100644
> > > > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > @@ -3,7 +3,7 @@
> > > >  #
> > > >  # This package provides common open source Intel silicon modules.
> > > >  #
> > > > -# Copyright (c) 2016 - 2018, Intel Corporation. All rights
> > > > reserved.<BR>
> > > > +# Copyright (c) 2016 - 2019, Intel Corporation. All rights
> > > > +reserved.<BR>
> > > >  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -22,6
> > > > +22,10 @@
> > > >    #
> > > >
> > > > MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.h
> > > >
> > > > +  ## @libraryclass  Provides services to identify the firmware
> > > > + boot media
> > > > device.
> > > > +  #
> > > > +  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
> > > > +
> > > >  [Guids]
> > > >    ## GUID for Package token space
> > > >    # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
> > > > @@ -35,6 +39,8 @@
> > > >    ## Include/Guid/MicrocodeFmp.h
> > > >    gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d, {
> > > 0x9d,
> > > > 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
> > > >
> > > > +  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06,
> > > > + {0xa4, 0x78,
> > > > 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
> > > > +
> > > >  [Ppis]
> > > >    gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97,
> > > > 0x67, 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
> > > >
> > > > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > index 58b5b656ef..3fb8a08b50 100644
> > > > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > @@ -1,7 +1,7 @@
> > > >  ## @file
> > > >  # This package provides common open source Intel silicon modules.
> > > >  #
> > > > -# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> > > > +# Copyright (c) 2017 - 2019, Intel Corporation. All rights
> > > > +reserved.<BR>
> > > >  #
> > > >  #    SPDX-License-Identifier: BSD-2-Clause-Patent
> > > >  #
> > > > @@ -80,6 +80,8 @@
> > > >
> > > >
> > >
> >
> IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSa
> > > > mplePei.inf
> > > >
> > > >
> > >
> >
> IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDx
> > > > e.inf
> > > >
> > > > IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibNul
> > > > l/
> > > > Mi
> > > > cro
> > > > codeFlashAccessLibNull.inf
> > > > +
> > > >
> > >
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib
> > > > .inf
> > > > +
> > > >
> > >
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMe
> > > > diaLib.inf
> > > >
> > > >  [BuildOptions]
> > > >    *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES diff
> --
> > > git
> > > >
> > >
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > r
> > > > mwareBootMediaLib.inf
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > r
> > > > mwareBootMediaLib.inf
> > > > new file mode 100644
> > > > index 0000000000..83ed5f04af
> > > > --- /dev/null
> > > > +++
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > r
> > > > mwareBootMediaLib.inf
> > > > @@ -0,0 +1,43 @@
> > > > +## @file
> > > > +# Firmware Boot Media Library
> > > > +#
> > > > +# The firmware boot media device is used to make system
> > > > +initialization
> > > > decisions in the boot flow dependent
> > > > +# upon firmware boot media. Note that the firmware boot media is
> > > > +the
> > > > storage media that the boot firmware is stored on.
> > > > +# It is not the OS storage media which may be stored upon a
> > > > +different
> > > > +non-
> > > > volatile storage device.
> > > > +#
> > > > +# This library contains an implementation for the DXE and SMM
> > > > +boot
> > > phases.
> > > > +#
> > > > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > +# #
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > > +
> > > > +[Defines]
> > > > +  INF_VERSION                    = 0x00010005
> > > > +  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
> > > > +  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
> > > > +  MODULE_TYPE                    = DXE_DRIVER
> > > > +  VERSION_STRING                 = 1.0
> > > > +  PI_SPECIFICATION_VERSION       = 0x0001000A
> > > > +  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER
> > > > DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
> > > UEFI_DRIVER
> > > > +  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
> > > > +#
> > > > +#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
> > > > +#
> > > > +
> > > > +[Sources]
> > > > +  FirmwareBootMediaLib.c
> > > > +  DxeSmmFirmwareBootMediaLib.c
> > > > +
> > > > +[Packages]
> > > > +  MdePkg/MdePkg.dec
> > > > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > > > +
> > > > +[LibraryClasses]
> > > > +  BaseLib
> > > > +  DebugLib
> > > > +  HobLib
> > > > +
> > > > +[Guids]
> > > > +  gFirmwareBootMediaHobGuid       ## CONSUMES
> > > > diff --git
> > > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiF
> > > > ir
> > > > mw
> > > > ar
> > > > eBootMediaLib.inf
> > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiF
> > > > ir
> > > > mw
> > > > ar
> > > > eBootMediaLib.inf
> > > > new file mode 100644
> > > > index 0000000000..063c4027d3
> > > > --- /dev/null
> > > > +++
> > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiF
> > > > ir
> > > > mw
> > > > ar
> > > > eBootMediaLib.inf
> > > > @@ -0,0 +1,38 @@
> > > > +## @file
> > > > +# Firmware Boot Media Library
> > > > +#
> > > > +# The firmware boot media device is used to make system
> > > > +initialization
> > > > decisions in the boot flow dependent
> > > > +# upon firmware boot media. Note that the firmware boot media is
> > > > +the
> > > > storage media that the boot firmware is stored on.
> > > > +# It is not the OS storage media which may be stored upon a
> > > > +different
> > > > +non-
> > > > volatile storage device.
> > > > +#
> > > > +# This library contains an implementation for the PEI boot phase.
> > > > +#
> > > > +# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > +# #
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > > +
> > > > +[Defines]
> > > > +  INF_VERSION          = 0x00010005
> > > > +  BASE_NAME            = PeiFirmwareBootMediaLib
> > > > +  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
> > > > +  MODULE_TYPE          = PEIM
> > > > +  VERSION_STRING       = 1.0
> > > > +  LIBRARY_CLASS        = FirmwareBootMediaLib
> > > > +
> > > > +[Sources]
> > > > +  FirmwareBootMediaLib.c
> > > > +  PeiFirmwareBootMediaLib.c
> > > > +
> > > > +[Packages]
> > > > +  MdePkg/MdePkg.dec
> > > > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > > > +
> > > > +[LibraryClasses]
> > > > +  BaseLib
> > > > +  DebugLib
> > > > +  HobLib
> > > > +
> > > > +[Guids]
> > > > +  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
> > > > diff --git
> > > > a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaL
> > > > ib
> > > > .h
> > > > b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaL
> > > > ib
> > > > .h
> > > > new file mode 100644
> > > > index 0000000000..aca9593a84
> > > > --- /dev/null
> > > > +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMe
> > > > +++ di
> > > > +++ aL
> > > > +++ ib.h
> > > > @@ -0,0 +1,106 @@
> > > > +/** @file
> > > > +  This library identifies the firmware boot media device.
> > > > +
> > > > +  The firmware boot media device is used to make system
> > > > + initialization
> > > > decisions in the boot flow dependent
> > > > +  upon firmware boot media. Note that the firmware boot media is
> > > > + the
> > > > storage media that the boot firmware is stored on.
> > > > +  It is not the OS storage media which may be stored upon a
> > > > + different
> > > > + non-
> > > > volatile storage device.
> > > > +
> > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > +
> > > > +**/
> > > > +
> > > > +#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_ #define
> > > > +_FIRMWARE_BOOT_MEDIA_LIB_H_
> > > > +
> > > > +#include <Uefi.h>
> > > > +
> > > > +typedef enum {
> > > > +  FwBootMediaSpi,
> > > > +  FwBootMediaUfs,
> > > > +  FwBootMediaEmmc,
> > > > +  FwBootMediaNvme,
> > > > +  FwBootMediaMax
> > > > +} FW_BOOT_MEDIA_TYPE;
> > > > +
> > > > +typedef struct {
> > > > +  FW_BOOT_MEDIA_TYPE BootMedia;
> > > > +} FW_BOOT_MEDIA_HOB_DATA;
> > > > +
> > > > +/**
> > > > +  Determines the current platform firmware boot media device.
> > > > +
> > > > +  @param[out] FwBootMediaType The current platform Boot Media
> > type.
> > > > +
> > > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > > +  @retval     EFI_NOT_FOUND   The boot media type could not be
> found.
> > > > +**/
> > > > +EFI_STATUS
> > > > +EFIAPI
> > > > +GetFirmwareBootMediaType (
> > > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > > +  );
> > > > +
> > > > +/**
> > > > +  Indicates whether the boot media is presently known.
> > > > +
> > > > +  Note: Very early in boot this data may not be available.
> > > > +
> > > > +  @retval TRUE        Boot media is known
> > > > +  @retval FALSE       Boot media is not known
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsKnown (
> > > > +  VOID
> > > > +  );
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from SPI.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from SPI
> > > > +  @retval FALSE       Platform firmware is booting from a non-SPI device
> > or
> > > > the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsSpi (
> > > > +  VOID
> > > > +  );
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from UFS.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from UFS
> > > > +  @retval FALSE       Platform firmware is booting from a non-UFS
> device
> > or
> > > > the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsUfs (
> > > > +  VOID
> > > > +  );
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from eMMC.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from eMMC
> > > > +  @retval FALSE       Platform firmware is booting from a non-eMMC
> > device
> > > > or the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsEmmc (
> > > > +  VOID
> > > > +  );
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from NVMe.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from NVMe.
> > > > +  @retval FALSE       Platform firmware is booting from a non-NVMe
> > device
> > > or
> > > > the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsNvme (
> > > > +  VOID
> > > > +  );
> > > > +
> > > > +#endif
> > > > diff --git
> > > >
> > >
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > r
> > > > mwareBootMediaLib.c
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > r
> > > > mwareBootMediaLib.c
> > > > new file mode 100644
> > > > index 0000000000..1e3876afb3
> > > > --- /dev/null
> > > > +++
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > r
> > > > mwareBootMediaLib.c
> > > > @@ -0,0 +1,107 @@
> > > > +/** @file
> > > > +  This library identifies the firmware boot media device.
> > > > +
> > > > +  The firmware boot media device is used to make system
> > > > + initialization
> > > > decisions in the boot flow dependent
> > > > +  upon firmware boot media. Note that the firmware boot media is
> > > > + the
> > > > storage media that the boot firmware is stored on.
> > > > +  It is not the OS storage media which may be stored upon a
> > > > + different
> > > > + non-
> > > > volatile storage device.
> > > > +
> > > > +  This file contains implementation specific to the DXE and SMM
> > > > + boot
> > > phases.
> > > > +
> > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > +
> > > > +**/
> > > > +
> > > > +#include <Library/BaseLib.h>
> > > > +#include <Library/DebugLib.h>
> > > > +#include <Library/FirmwareBootMediaLib.h> #include
> > > > +<Library/HobLib.h>
> > > > +
> > > > +STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia = FwBootMediaMax;
> > > > +
> > > > +/**
> > > > +  Determines the current platform firmware boot media device.
> > > > +
> > > > +  @param[out] FwBootMediaType The current platform Boot Media
> > type.
> > > > +
> > > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > > +  @retval     EFI_NOT_FOUND   The boot media type could not be
> found.
> > > > +**/
> > > > +EFI_STATUS
> > > > +EFIAPI
> > > > +GetFirmwareBootMediaType (
> > > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > > +  )
> > > > +{
> > > > +  if (mFwBootMedia == FwBootMediaMax) {
> > > > +    return EFI_NOT_FOUND;
> > > > +  }
> > > > +
> > > > +  *FwBootMediaType = mFwBootMedia;
> > > > +  return EFI_SUCCESS;
> > > > +}
> > > > +
> > > > +/**
> > > > +  Determines if the boot media is presently known.
> > > > +
> > > > +  Note: Very early in boot this data may not be available.
> > > > +
> > > > +  @retval TRUE        Boot media is known
> > > > +  @retval FALSE       Boot media is not known
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsKnown (
> > > > +  VOID
> > > > +  )
> > > > +{
> > > > +  return mFwBootMedia != FwBootMediaMax; }
> > > > +
> > > > +/**
> > > > +  The library constructor.
> > > > +
> > > > +  This constructor depends upon gFirmwareBootMediaHobGuid.
> > > > +  It should be produced by the platform in the HOB producer phase.
> > > > +
> > > > +  @param[in]  ImageHandle           The firmware allocated handle for the
> > > UEFI
> > > > image.
> > > > +  @param[in]  SystemTable           A pointer to the EFI system table.
> > > > +
> > > > +  @retval     EFI_SUCCESS           The constructor executed successfully.
> > > > +  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid
> > HOB
> > > > could not be located
> > > > +                                    or the boot media type is invalid.
> > > > +**/
> > > > +EFI_STATUS
> > > > +EFIAPI
> > > > +DxeSmmFirmwareBootMediaLibInit (
> > > > +  IN EFI_HANDLE         ImageHandle,
> > > > +  IN EFI_SYSTEM_TABLE   *SystemTable
> > > > +  )
> > > > +{
> > > > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > > > +  FW_BOOT_MEDIA_TYPE        BootMediaType;
> > > > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > > > +
> > > > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if
> > > > + (GuidHobPtr == NULL) {
> > > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > > > exist!\n"));
> > > > +    ASSERT (GuidHobPtr != NULL);
> > > > +    return EFI_NOT_FOUND;
> > > > +  }
> > > > +
> > > > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > > > GET_GUID_HOB_DATA (GuidHobPtr);
> > > > +  if (BootMediaHobData == NULL) {
> > > > +    return EFI_NOT_FOUND;
> > > > +  }
> > > > +
> > > > +  BootMediaType = BootMediaHobData->BootMedia;
> > > > +
> > > > +  if (BootMediaType >= FwBootMediaMax) {
> > > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies
> > > > + an
> > > > invalid media type.\n"));
> > > > +    return EFI_NOT_FOUND;
> > > > +  }
> > > > +
> > > > +  mFwBootMedia = BootMediaType;
> > > > +
> > > > +  return EFI_SUCCESS;
> > > > +}
> > > > diff --git
> > > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firm
> > > > wa
> > > > re
> > > > B
> > > > ootMediaLib.c
> > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firm
> > > > wa
> > > > re
> > > > B
> > > > ootMediaLib.c
> > > > new file mode 100644
> > > > index 0000000000..11a14d172d
> > > > --- /dev/null
> > > > +++
> > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firm
> > > > wa
> > > > re
> > > > B
> > > > ootMediaLib.c
> > > > @@ -0,0 +1,109 @@
> > > > +/** @file
> > > > +  This library identifies the firmware boot media device.
> > > > +
> > > > +  The firmware boot media device is used to make system
> > > > + initialization
> > > > decisions in the boot flow dependent
> > > > +  upon firmware boot media. Note that the firmware boot media is
> > > > + the
> > > > storage media that the boot firmware is stored on.
> > > > +  It is not the OS storage media which may be stored upon a
> > > > + different
> > > > + non-
> > > > volatile storage device.
> > > > +
> > > > +  This file contains library implementation common to all boot phases.
> > > > +
> > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > +
> > > > +**/
> > > > +
> > > > +#include <Library/BaseLib.h>
> > > > +#include <Library/DebugLib.h>
> > > > +#include <Library/FirmwareBootMediaLib.h>
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from SPI.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from SPI
> > > > +  @retval FALSE       Platform firmware is booting from a non-SPI device
> > or
> > > > the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsSpi (
> > > > +  VOID
> > > > +  )
> > > > +{
> > > > +  EFI_STATUS          Status;
> > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > +
> > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
> > > > +    return FALSE;
> > > > +  } else {
> > > > +    return TRUE;
> > > > +  }
> > > > +}
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from UFS.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from UFS
> > > > +  @retval FALSE       Platform firmware is booting from a non-UFS
> device
> > or
> > > > the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsUfs (
> > > > +  VOID
> > > > +  )
> > > > +{
> > > > +  EFI_STATUS          Status;
> > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > +
> > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
> > > > +    return FALSE;
> > > > +  } else {
> > > > +    return TRUE;
> > > > +  }
> > > > +}
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from eMMC.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from eMMC
> > > > +  @retval FALSE       Platform firmware is booting from a non-eMMC
> > device
> > > > or the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsEmmc (
> > > > +  VOID
> > > > +  )
> > > > +{
> > > > +  EFI_STATUS          Status;
> > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > +
> > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
> > > > +    return FALSE;
> > > > +  } else {
> > > > +    return TRUE;
> > > > +  }
> > > > +}
> > > > +
> > > > +/**
> > > > +  Determines if the platform firmware is booting from NVMe.
> > > > +
> > > > +  @retval TRUE        Platform firmware is booting from NVMe.
> > > > +  @retval FALSE       Platform firmware is booting from a non-NVMe
> > device
> > > or
> > > > the boot media is unknown
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsNvme (
> > > > +  VOID
> > > > +  )
> > > > +{
> > > > +  EFI_STATUS          Status;
> > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > +
> > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
> > > > +    return FALSE;
> > > > +  } else {
> > > > +    return TRUE;
> > > > +  }
> > > > +}
> > > > diff --git
> > > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiF
> > > > ir
> > > > mw
> > > > ar
> > > > eBootMediaLib.c
> > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiF
> > > > ir
> > > > mw
> > > > ar
> > > > eBootMediaLib.c
> > > > new file mode 100644
> > > > index 0000000000..14478e0dbe
> > > > --- /dev/null
> > > > +++
> > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiF
> > > > ir
> > > > mw
> > > > ar
> > > > eBootMediaLib.c
> > > > @@ -0,0 +1,82 @@
> > > > +/** @file
> > > > +  This library identifies the firmware boot media device.
> > > > +
> > > > +  The firmware boot media device is used to make system
> > > > + initialization
> > > > decisions in the boot flow dependent
> > > > +  upon firmware boot media. Note that the firmware boot media is
> > > > + the
> > > > storage media that the boot firmware is stored on.
> > > > +  It is not the OS storage media which may be stored upon a
> > > > + different
> > > > + non-
> > > > volatile storage device.
> > > > +
> > > > +  This file contains implementation specific to the PEI boot phase.
> > > > +
> > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > +
> > > > +**/
> > > > +
> > > > +#include <Library/BaseLib.h>
> > > > +#include <Library/DebugLib.h>
> > > > +#include <Library/FirmwareBootMediaLib.h> #include
> > > > +<Library/HobLib.h>
> > > > +
> > > > +/**
> > > > +  Determines the current platform firmware boot media device.
> > > > +
> > > > +  @param[out] FwBootMediaType The current platform Boot Media
> > type.
> > > > +
> > > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > > +  @retval     EFI_NOT_FOUND   The boot media type could not be
> found.
> > > > +**/
> > > > +EFI_STATUS
> > > > +EFIAPI
> > > > +GetFirmwareBootMediaType (
> > > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > > +  )
> > > > +{
> > > > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > > > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > > > +
> > > > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);  if
> > > > + (GuidHobPtr == NULL) {
> > > > +      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > > > exist!\n"));
> > > > +      ASSERT (GuidHobPtr != NULL);
> > > > +      return EFI_NOT_FOUND;
> > > > +  }
> > > > +
> > > > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > > > GET_GUID_HOB_DATA (GuidHobPtr);
> > > > +  if (BootMediaHobData == NULL) {
> > > > +    return EFI_NOT_FOUND;
> > > > +  }
> > > > +
> > > > +  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
> > > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies
> > > > + an
> > > > invalid media type.\n"));
> > > > +    return EFI_NOT_FOUND;
> > > > +  }
> > > > +  *FwBootMediaType = BootMediaHobData->BootMedia;
> > > > +
> > > > +  return EFI_SUCCESS;
> > > > +}
> > > > +
> > > > +/**
> > > > +  Determines if the boot media is presently known.
> > > > +
> > > > +  Note: Very early in boot this data may not be available.
> > > > +
> > > > +  @retval TRUE        Boot media is known
> > > > +  @retval FALSE       Boot media is not known
> > > > +**/
> > > > +BOOLEAN
> > > > +EFIAPI
> > > > +FirmwareBootMediaIsKnown (
> > > > +  VOID
> > > > +  )
> > > > +{
> > > > +  EFI_STATUS          Status;
> > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > +
> > > > +  BootMedia = FwBootMediaMax;
> > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > +  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
> > > > +    return FALSE;
> > > > +  } else {
> > > > +    return TRUE;
> > > > +  }
> > > > +}
> > > > --
> > > > 2.16.2.windows.1
> > >
> >
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library
  2019-10-10  4:42         ` Kubacki, Michael A
@ 2019-10-10  5:44           ` Ni, Ray
  0 siblings, 0 replies; 12+ messages in thread
From: Ni, Ray @ 2019-10-10  5:44 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Chaganty, Rangasai V



> -----Original Message-----
> From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> Sent: Thursday, October 10, 2019 12:43 PM
> To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
> Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> Subject: RE: [edk2-platforms][PATCH V2 1/3]
> IntelSiliconPkg/FirmwareBootMediaLib: Add library
> 
> Replies below.
> 
> > -----Original Message-----
> > From: Ni, Ray <ray.ni@intel.com>
> > Sent: Wednesday, October 9, 2019 7:21 PM
> > To: Kubacki, Michael A <michael.a.kubacki@intel.com>;
> > devel@edk2.groups.io
> > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> > Subject: RE: [edk2-platforms][PATCH V2 1/3]
> > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> >
> > Comments below.
> >
> > > -----Original Message-----
> > > From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> > > Sent: Thursday, October 10, 2019 12:34 AM
> > > To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
> > > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> > > Subject: RE: [edk2-platforms][PATCH V2 1/3]
> > > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> > >
> > > 1. DxeSmmFirmwareBootMediaLib could get the HOB like PEI for every
> > > access. I considered this but it seems unnecessary since we have the
> > > flexibility for  phase-specific drivers that can have trivial
> > > optimizations like
> > this.
> > > Checking the HOB on every access would also constrain usage in
> > > DXE_SMM_DRIVER and DXE_RUNTIME_DRIVER modules.
> >
> > Having single library instance can make platform DSC simpler.
> > Because SMM and Runtime drivers are dispatched in BS phase, they can
> > cache the boot media type if the usage lasts to post-EndOfDxe or OS
> > runtime.
> >
> 
> I don't see an issue with phase-specific instances that cleanly comply with
> phase restrictions.
> 
> In general, PEI drivers cannot write to global variables. This change does
> cache the value in BS phase so it is available in OS runtime.
> 
>  * PEI: Do not write to a global variable. Use the heap to store the value via
> the HOB list. Always get the value from the HOB.
>  * DXE: Get the value from the HOB and store the value in a global variable
> during the library constructor in the BS phase so the value is available during
> later phase transition.
> 
> What exactly are you proposing to change?
> 

I would like to see one library instance that can be used in both PEI and DXE.
The library implementation doesn't need to care when it's called. Caller is responsible to call the API
properly in boot time phase.

> > >
> > > 2. They are certainly not required, but in practice we've found code
> > > usage tends to read better and be more concise with these APIs for
> > > simple firmware boot media checks. The enum is provided for
> > > relatively rarer scenarios where many possibilities need to be
> > > considered such as usage in a switch statement. I can see a case
> > > made in either direction. Let me know if you and Sai feel strongly about
> this.
> >
> > I prefer to use enum and GetType() API. Because if there is more boot
> > media type, there is no need to add a new library API like IsXXX().
> > Not sure if it's over design, I prefer to use GUID against enum. No
> > strong preference of using GUID in this case.
> >
> 
> My preference is that the API is well-defined and stable. In this case, my
> primary thought  on the matter is not having two ways to do the same thing.
> And again, I have no strong preference for either case but we do have Intel
> code that favors the IsXXX () usage. I don't think adding new devices
> (extending the API) is so much an issue as ensuring the existing ones are not
> modified. Which would be the case for the enum members and the functions.
> In conclusion, I will send a patch to remove the IsXXX () functions.

Thanks.

> 
> Before adding GUIDs, the problem statement needs to be clearly articulated
> that justifies introducing GUID management.

I am ok with enum.

> 
> > Thanks,
> > Ray
> >
> > >
> > > Thanks,
> > > Michael
> > >
> > > > -----Original Message-----
> > > > From: Ni, Ray <ray.ni@intel.com>
> > > > Sent: Wednesday, October 9, 2019 2:36 AM
> > > > To: Kubacki, Michael A <michael.a.kubacki@intel.com>;
> > > > devel@edk2.groups.io
> > > > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> > > > Subject: RE: [edk2-platforms][PATCH V2 1/3]
> > > > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> > > >
> > > > Michael,
> > > > Two comments:
> > > > 1. The difference between PEI and DXE instances is DXE instance
> > > > has a global variable caching the boot media type. Both get the
> > > > type from HOB. So I am thinking how about simplifying the library
> > > > to have only one instance which equals to PEI instance. That can
> > > > also be used in DXE
> > > phase.
> > > > 2. With the definition of enum type FW_BOOT_MEDIA_TYPE and
> > GetType()
> > > > API, I feel the other several FirmwareBootMediaIsXXX() APIs are
> > > > not very necessary.
> > > >
> > > > Thanks,
> > > > Ray
> > > >
> > > > > -----Original Message-----
> > > > > From: Kubacki, Michael A <michael.a.kubacki@intel.com>
> > > > > Sent: Saturday, October 5, 2019 1:29 AM
> > > > > To: devel@edk2.groups.io
> > > > > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Ni,
> > > > > Ray <ray.ni@intel.com>
> > > > > Subject: [edk2-platforms][PATCH V2 1/3]
> > > > > IntelSiliconPkg/FirmwareBootMediaLib: Add library
> > > > >
> > > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2229
> > > > >
> > > > > Adds a new library that is used to make system initialization
> > > > > decisions in the boot flow dependent upon firmware boot media.
> > > > > Note that the firmware boot media is the storage media that the
> > > > > boot firmware is stored on. It is not the OS storage media which
> > > > > may be stored upon a different non-volatile storage device.
> > > > >
> > > > > Any Intel board, platform, or silicon code that must take action
> > > > > conditionally based on the firmware boot media must use this
> > > > > library API.
> > > > >
> > > > > Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> > > > > Cc: Ray Ni <ray.ni@intel.com>
> > > > > Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> > > > > ---
> > > > >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec                                          |
> > 8
> > > +-
> > > > >  Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc                                          |
> 4
> > > +-
> > > > >
> > > > >
> > > >
> > >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > > > > wareBootMediaLib.inf |  43 ++++++++
> > > > >
> > > > >
> > > > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > > mw
> > > > ar
> > > > eB
> > > > > ootMediaLib.inf    |  38 +++++++
> > > > >
> > > > > Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMediaL
> > > > > ib
> > > > > .h
> > > > > | 106 +++++++++++++++++++
> > > > >
> > > > >
> > > >
> > >
> >
> Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirm
> > > > > wareBootMediaLib.c   | 107 +++++++++++++++++++
> > > > >
> > > > >
> > > > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Firmwa
> > > > re
> > > > Bo
> > > > o
> > > > > tMediaLib.c         | 109 ++++++++++++++++++++
> > > > >
> > > > >
> > > > Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFir
> > > > mw
> > > > ar
> > > > eB
> > > > > ootMediaLib.c      |  82 +++++++++++++++
> > > > >  8 files changed, 495 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > > index fe5bfa0dc6..f70e3b977d 100644
> > > > > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
> > > > > @@ -3,7 +3,7 @@
> > > > >  #
> > > > >  # This package provides common open source Intel silicon modules.
> > > > >  #
> > > > > -# Copyright (c) 2016 - 2018, Intel Corporation. All rights
> > > > > reserved.<BR>
> > > > > +# Copyright (c) 2016 - 2019, Intel Corporation. All rights
> > > > > +reserved.<BR>
> > > > >  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -22,6
> > > > > +22,10 @@
> > > > >    #
> > > > >
> > > > > MicrocodeFlashAccessLib|Include/Library/MicrocodeFlashAccessLib.
> > > > > MicrocodeFlashAccessLib|h
> > > > >
> > > > > +  ## @libraryclass  Provides services to identify the firmware
> > > > > + boot media
> > > > > device.
> > > > > +  #
> > > > > +  FirmwareBootMediaLib|Include/Library/FirmwareBootMediaLib.h
> > > > > +
> > > > >  [Guids]
> > > > >    ## GUID for Package token space
> > > > >    # {A9F8D54E-1107-4F0A-ADD0-4587E7A4A735}
> > > > > @@ -35,6 +39,8 @@
> > > > >    ## Include/Guid/MicrocodeFmp.h
> > > > >    gMicrocodeFmpImageTypeIdGuid      = { 0x96d4fdcd, 0x1502, 0x424d,
> {
> > > > 0x9d,
> > > > > 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } }
> > > > >
> > > > > +  gFirmwareBootMediaHobGuid = { 0x8c7340ea, 0xde8b, 0x4e06,
> > > > > + {0xa4, 0x78,
> > > > > 0xec, 0x8b, 0x62, 0xd7, 0xa, 0x8b } }
> > > > > +
> > > > >  [Ppis]
> > > > >    gEdkiiVTdInfoPpiGuid = { 0x8a59fcb3, 0xf191, 0x400c, { 0x97,
> > > > > 0x67, 0x67, 0xaf, 0x2b, 0x25, 0x68, 0x4a } }
> > > > >
> > > > > diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > > b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > > index 58b5b656ef..3fb8a08b50 100644
> > > > > --- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > > +++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dsc
> > > > > @@ -1,7 +1,7 @@
> > > > >  ## @file
> > > > >  # This package provides common open source Intel silicon modules.
> > > > >  #
> > > > > -# Copyright (c) 2017, Intel Corporation. All rights
> > > > > reserved.<BR>
> > > > > +# Copyright (c) 2017 - 2019, Intel Corporation. All rights
> > > > > +reserved.<BR>
> > > > >  #
> > > > >  #    SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > >  #
> > > > > @@ -80,6 +80,8 @@
> > > > >
> > > > >
> > > >
> > >
> >
> IntelSiliconPkg/Feature/VTd/PlatformVTdInfoSamplePei/PlatformVTdInfoSa
> > > > > mplePei.inf
> > > > >
> > > > >
> > > >
> > >
> >
> IntelSiliconPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdateDx
> > > > > e.inf
> > > > >
> > > > > IntelSiliconPkg/Feature/Capsule/Library/MicrocodeFlashAccessLibN
> > > > > ul
> > > > > l/
> > > > > Mi
> > > > > cro
> > > > > codeFlashAccessLibNull.inf
> > > > > +
> > > > >
> > > >
> > >
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/PeiFirmwareBootMediaLib
> > > > > .inf
> > > > > +
> > > > >
> > > >
> > >
> >
> IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFirmwareBootMe
> > > > > diaLib.inf
> > > > >
> > > > >  [BuildOptions]
> > > > >    *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
> diff
> > --
> > > > git
> > > > >
> > > >
> > >
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > > r
> > > > > mwareBootMediaLib.inf
> > > > >
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > > r
> > > > > mwareBootMediaLib.inf
> > > > > new file mode 100644
> > > > > index 0000000000..83ed5f04af
> > > > > --- /dev/null
> > > > > +++
> > > > >
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > > r
> > > > > mwareBootMediaLib.inf
> > > > > @@ -0,0 +1,43 @@
> > > > > +## @file
> > > > > +# Firmware Boot Media Library
> > > > > +#
> > > > > +# The firmware boot media device is used to make system
> > > > > +initialization
> > > > > decisions in the boot flow dependent
> > > > > +# upon firmware boot media. Note that the firmware boot media
> > > > > +is the
> > > > > storage media that the boot firmware is stored on.
> > > > > +# It is not the OS storage media which may be stored upon a
> > > > > +different
> > > > > +non-
> > > > > volatile storage device.
> > > > > +#
> > > > > +# This library contains an implementation for the DXE and SMM
> > > > > +boot
> > > > phases.
> > > > > +#
> > > > > +# Copyright (c) 2019, Intel Corporation. All rights
> > > > > +reserved.<BR> # #
> > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > > > +
> > > > > +[Defines]
> > > > > +  INF_VERSION                    = 0x00010005
> > > > > +  BASE_NAME                      = DxeSmmFirmwareBootMediaLib
> > > > > +  FILE_GUID                      = 72F07B0B-54F5-47FD-9EDB-D796BE2B87E9
> > > > > +  MODULE_TYPE                    = DXE_DRIVER
> > > > > +  VERSION_STRING                 = 1.0
> > > > > +  PI_SPECIFICATION_VERSION       = 0x0001000A
> > > > > +  LIBRARY_CLASS                  = FirmwareBootMediaLib|DXE_DRIVER
> > > > > DXE_SMM_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
> > > > UEFI_DRIVER
> > > > > +  CONSTRUCTOR                    = DxeSmmFirmwareBootMediaLibInit
> > > > > +#
> > > > > +#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
> > > > > +#
> > > > > +
> > > > > +[Sources]
> > > > > +  FirmwareBootMediaLib.c
> > > > > +  DxeSmmFirmwareBootMediaLib.c
> > > > > +
> > > > > +[Packages]
> > > > > +  MdePkg/MdePkg.dec
> > > > > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > > > > +
> > > > > +[LibraryClasses]
> > > > > +  BaseLib
> > > > > +  DebugLib
> > > > > +  HobLib
> > > > > +
> > > > > +[Guids]
> > > > > +  gFirmwareBootMediaHobGuid       ## CONSUMES
> > > > > diff --git
> > > > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Pe
> > > > > iF
> > > > > ir
> > > > > mw
> > > > > ar
> > > > > eBootMediaLib.inf
> > > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Pe
> > > > > iF
> > > > > ir
> > > > > mw
> > > > > ar
> > > > > eBootMediaLib.inf
> > > > > new file mode 100644
> > > > > index 0000000000..063c4027d3
> > > > > --- /dev/null
> > > > > +++
> > > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Pe
> > > > > iF
> > > > > ir
> > > > > mw
> > > > > ar
> > > > > eBootMediaLib.inf
> > > > > @@ -0,0 +1,38 @@
> > > > > +## @file
> > > > > +# Firmware Boot Media Library
> > > > > +#
> > > > > +# The firmware boot media device is used to make system
> > > > > +initialization
> > > > > decisions in the boot flow dependent
> > > > > +# upon firmware boot media. Note that the firmware boot media
> > > > > +is the
> > > > > storage media that the boot firmware is stored on.
> > > > > +# It is not the OS storage media which may be stored upon a
> > > > > +different
> > > > > +non-
> > > > > volatile storage device.
> > > > > +#
> > > > > +# This library contains an implementation for the PEI boot phase.
> > > > > +#
> > > > > +# Copyright (c) 2019, Intel Corporation. All rights
> > > > > +reserved.<BR> # #
> > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> > > > > +
> > > > > +[Defines]
> > > > > +  INF_VERSION          = 0x00010005
> > > > > +  BASE_NAME            = PeiFirmwareBootMediaLib
> > > > > +  FILE_GUID            = D3F7BD0B-3539-4F2D-AF98-EE32DBE7971F
> > > > > +  MODULE_TYPE          = PEIM
> > > > > +  VERSION_STRING       = 1.0
> > > > > +  LIBRARY_CLASS        = FirmwareBootMediaLib
> > > > > +
> > > > > +[Sources]
> > > > > +  FirmwareBootMediaLib.c
> > > > > +  PeiFirmwareBootMediaLib.c
> > > > > +
> > > > > +[Packages]
> > > > > +  MdePkg/MdePkg.dec
> > > > > +  IntelSiliconPkg/IntelSiliconPkg.dec
> > > > > +
> > > > > +[LibraryClasses]
> > > > > +  BaseLib
> > > > > +  DebugLib
> > > > > +  HobLib
> > > > > +
> > > > > +[Guids]
> > > > > +  gFirmwareBootMediaHobGuid       ## PRODUCES CONSUMES
> > > > > diff --git
> > > > > a/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMedi
> > > > > aL
> > > > > ib
> > > > > .h
> > > > > b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBootMedi
> > > > > aL
> > > > > ib
> > > > > .h
> > > > > new file mode 100644
> > > > > index 0000000000..aca9593a84
> > > > > --- /dev/null
> > > > > +++ b/Silicon/Intel/IntelSiliconPkg/Include/Library/FirmwareBoot
> > > > > +++ Me
> > > > > +++ di
> > > > > +++ aL
> > > > > +++ ib.h
> > > > > @@ -0,0 +1,106 @@
> > > > > +/** @file
> > > > > +  This library identifies the firmware boot media device.
> > > > > +
> > > > > +  The firmware boot media device is used to make system
> > > > > + initialization
> > > > > decisions in the boot flow dependent
> > > > > +  upon firmware boot media. Note that the firmware boot media
> > > > > + is the
> > > > > storage media that the boot firmware is stored on.
> > > > > +  It is not the OS storage media which may be stored upon a
> > > > > + different
> > > > > + non-
> > > > > volatile storage device.
> > > > > +
> > > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > +
> > > > > +**/
> > > > > +
> > > > > +#ifndef _FIRMWARE_BOOT_MEDIA_LIB_H_ #define
> > > > > +_FIRMWARE_BOOT_MEDIA_LIB_H_
> > > > > +
> > > > > +#include <Uefi.h>
> > > > > +
> > > > > +typedef enum {
> > > > > +  FwBootMediaSpi,
> > > > > +  FwBootMediaUfs,
> > > > > +  FwBootMediaEmmc,
> > > > > +  FwBootMediaNvme,
> > > > > +  FwBootMediaMax
> > > > > +} FW_BOOT_MEDIA_TYPE;
> > > > > +
> > > > > +typedef struct {
> > > > > +  FW_BOOT_MEDIA_TYPE BootMedia; }
> FW_BOOT_MEDIA_HOB_DATA;
> > > > > +
> > > > > +/**
> > > > > +  Determines the current platform firmware boot media device.
> > > > > +
> > > > > +  @param[out] FwBootMediaType The current platform Boot Media
> > > type.
> > > > > +
> > > > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > > > +  @retval     EFI_NOT_FOUND   The boot media type could not be
> > found.
> > > > > +**/
> > > > > +EFI_STATUS
> > > > > +EFIAPI
> > > > > +GetFirmwareBootMediaType (
> > > > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > > > +  );
> > > > > +
> > > > > +/**
> > > > > +  Indicates whether the boot media is presently known.
> > > > > +
> > > > > +  Note: Very early in boot this data may not be available.
> > > > > +
> > > > > +  @retval TRUE        Boot media is known
> > > > > +  @retval FALSE       Boot media is not known
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsKnown (
> > > > > +  VOID
> > > > > +  );
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from SPI.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from SPI
> > > > > +  @retval FALSE       Platform firmware is booting from a non-SPI
> device
> > > or
> > > > > the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsSpi (
> > > > > +  VOID
> > > > > +  );
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from UFS.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from UFS
> > > > > +  @retval FALSE       Platform firmware is booting from a non-UFS
> > device
> > > or
> > > > > the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsUfs (
> > > > > +  VOID
> > > > > +  );
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from eMMC.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from eMMC
> > > > > +  @retval FALSE       Platform firmware is booting from a non-eMMC
> > > device
> > > > > or the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsEmmc (
> > > > > +  VOID
> > > > > +  );
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from NVMe.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from NVMe.
> > > > > +  @retval FALSE       Platform firmware is booting from a non-NVMe
> > > device
> > > > or
> > > > > the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsNvme (
> > > > > +  VOID
> > > > > +  );
> > > > > +
> > > > > +#endif
> > > > > diff --git
> > > > >
> > > >
> > >
> >
> a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > > r
> > > > > mwareBootMediaLib.c
> > > > >
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > > r
> > > > > mwareBootMediaLib.c
> > > > > new file mode 100644
> > > > > index 0000000000..1e3876afb3
> > > > > --- /dev/null
> > > > > +++
> > > > >
> > > >
> > >
> >
> b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/DxeSmmFi
> > > > > r
> > > > > mwareBootMediaLib.c
> > > > > @@ -0,0 +1,107 @@
> > > > > +/** @file
> > > > > +  This library identifies the firmware boot media device.
> > > > > +
> > > > > +  The firmware boot media device is used to make system
> > > > > + initialization
> > > > > decisions in the boot flow dependent
> > > > > +  upon firmware boot media. Note that the firmware boot media
> > > > > + is the
> > > > > storage media that the boot firmware is stored on.
> > > > > +  It is not the OS storage media which may be stored upon a
> > > > > + different
> > > > > + non-
> > > > > volatile storage device.
> > > > > +
> > > > > +  This file contains implementation specific to the DXE and SMM
> > > > > + boot
> > > > phases.
> > > > > +
> > > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > +
> > > > > +**/
> > > > > +
> > > > > +#include <Library/BaseLib.h>
> > > > > +#include <Library/DebugLib.h>
> > > > > +#include <Library/FirmwareBootMediaLib.h> #include
> > > > > +<Library/HobLib.h>
> > > > > +
> > > > > +STATIC FW_BOOT_MEDIA_TYPE mFwBootMedia =
> FwBootMediaMax;
> > > > > +
> > > > > +/**
> > > > > +  Determines the current platform firmware boot media device.
> > > > > +
> > > > > +  @param[out] FwBootMediaType The current platform Boot Media
> > > type.
> > > > > +
> > > > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > > > +  @retval     EFI_NOT_FOUND   The boot media type could not be
> > found.
> > > > > +**/
> > > > > +EFI_STATUS
> > > > > +EFIAPI
> > > > > +GetFirmwareBootMediaType (
> > > > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > > > +  )
> > > > > +{
> > > > > +  if (mFwBootMedia == FwBootMediaMax) {
> > > > > +    return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +
> > > > > +  *FwBootMediaType = mFwBootMedia;
> > > > > +  return EFI_SUCCESS;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > +  Determines if the boot media is presently known.
> > > > > +
> > > > > +  Note: Very early in boot this data may not be available.
> > > > > +
> > > > > +  @retval TRUE        Boot media is known
> > > > > +  @retval FALSE       Boot media is not known
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsKnown (
> > > > > +  VOID
> > > > > +  )
> > > > > +{
> > > > > +  return mFwBootMedia != FwBootMediaMax; }
> > > > > +
> > > > > +/**
> > > > > +  The library constructor.
> > > > > +
> > > > > +  This constructor depends upon gFirmwareBootMediaHobGuid.
> > > > > +  It should be produced by the platform in the HOB producer phase.
> > > > > +
> > > > > +  @param[in]  ImageHandle           The firmware allocated handle for
> the
> > > > UEFI
> > > > > image.
> > > > > +  @param[in]  SystemTable           A pointer to the EFI system table.
> > > > > +
> > > > > +  @retval     EFI_SUCCESS           The constructor executed successfully.
> > > > > +  @retval     EFI_NOT_FOUND         The gFirmwareBootMediaHobGuid
> > > HOB
> > > > > could not be located
> > > > > +                                    or the boot media type is invalid.
> > > > > +**/
> > > > > +EFI_STATUS
> > > > > +EFIAPI
> > > > > +DxeSmmFirmwareBootMediaLibInit (
> > > > > +  IN EFI_HANDLE         ImageHandle,
> > > > > +  IN EFI_SYSTEM_TABLE   *SystemTable
> > > > > +  )
> > > > > +{
> > > > > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > > > > +  FW_BOOT_MEDIA_TYPE        BootMediaType;
> > > > > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > > > > +
> > > > > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);
> > > > > + if (GuidHobPtr == NULL) {
> > > > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does not
> > > > > exist!\n"));
> > > > > +    ASSERT (GuidHobPtr != NULL);
> > > > > +    return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +
> > > > > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > > > > GET_GUID_HOB_DATA (GuidHobPtr);
> > > > > +  if (BootMediaHobData == NULL) {
> > > > > +    return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +
> > > > > +  BootMediaType = BootMediaHobData->BootMedia;
> > > > > +
> > > > > +  if (BootMediaType >= FwBootMediaMax) {
> > > > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies
> > > > > + an
> > > > > invalid media type.\n"));
> > > > > +    return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +
> > > > > +  mFwBootMedia = BootMediaType;
> > > > > +
> > > > > +  return EFI_SUCCESS;
> > > > > +}
> > > > > diff --git
> > > > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Fi
> > > > > rm
> > > > > wa
> > > > > re
> > > > > B
> > > > > ootMediaLib.c
> > > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Fi
> > > > > rm
> > > > > wa
> > > > > re
> > > > > B
> > > > > ootMediaLib.c
> > > > > new file mode 100644
> > > > > index 0000000000..11a14d172d
> > > > > --- /dev/null
> > > > > +++
> > > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Fi
> > > > > rm
> > > > > wa
> > > > > re
> > > > > B
> > > > > ootMediaLib.c
> > > > > @@ -0,0 +1,109 @@
> > > > > +/** @file
> > > > > +  This library identifies the firmware boot media device.
> > > > > +
> > > > > +  The firmware boot media device is used to make system
> > > > > + initialization
> > > > > decisions in the boot flow dependent
> > > > > +  upon firmware boot media. Note that the firmware boot media
> > > > > + is the
> > > > > storage media that the boot firmware is stored on.
> > > > > +  It is not the OS storage media which may be stored upon a
> > > > > + different
> > > > > + non-
> > > > > volatile storage device.
> > > > > +
> > > > > +  This file contains library implementation common to all boot phases.
> > > > > +
> > > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > +
> > > > > +**/
> > > > > +
> > > > > +#include <Library/BaseLib.h>
> > > > > +#include <Library/DebugLib.h>
> > > > > +#include <Library/FirmwareBootMediaLib.h>
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from SPI.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from SPI
> > > > > +  @retval FALSE       Platform firmware is booting from a non-SPI
> device
> > > or
> > > > > the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsSpi (
> > > > > +  VOID
> > > > > +  )
> > > > > +{
> > > > > +  EFI_STATUS          Status;
> > > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > > +
> > > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaSpi) {
> > > > > +    return FALSE;
> > > > > +  } else {
> > > > > +    return TRUE;
> > > > > +  }
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from UFS.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from UFS
> > > > > +  @retval FALSE       Platform firmware is booting from a non-UFS
> > device
> > > or
> > > > > the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsUfs (
> > > > > +  VOID
> > > > > +  )
> > > > > +{
> > > > > +  EFI_STATUS          Status;
> > > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > > +
> > > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaUfs) {
> > > > > +    return FALSE;
> > > > > +  } else {
> > > > > +    return TRUE;
> > > > > +  }
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from eMMC.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from eMMC
> > > > > +  @retval FALSE       Platform firmware is booting from a non-eMMC
> > > device
> > > > > or the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsEmmc (
> > > > > +  VOID
> > > > > +  )
> > > > > +{
> > > > > +  EFI_STATUS          Status;
> > > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > > +
> > > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaEmmc) {
> > > > > +    return FALSE;
> > > > > +  } else {
> > > > > +    return TRUE;
> > > > > +  }
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > +  Determines if the platform firmware is booting from NVMe.
> > > > > +
> > > > > +  @retval TRUE        Platform firmware is booting from NVMe.
> > > > > +  @retval FALSE       Platform firmware is booting from a non-NVMe
> > > device
> > > > or
> > > > > the boot media is unknown
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsNvme (
> > > > > +  VOID
> > > > > +  )
> > > > > +{
> > > > > +  EFI_STATUS          Status;
> > > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > > +
> > > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > > +  if (EFI_ERROR (Status) || BootMedia != FwBootMediaNvme) {
> > > > > +    return FALSE;
> > > > > +  } else {
> > > > > +    return TRUE;
> > > > > +  }
> > > > > +}
> > > > > diff --git
> > > > > a/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Pe
> > > > > iF
> > > > > ir
> > > > > mw
> > > > > ar
> > > > > eBootMediaLib.c
> > > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Pe
> > > > > iF
> > > > > ir
> > > > > mw
> > > > > ar
> > > > > eBootMediaLib.c
> > > > > new file mode 100644
> > > > > index 0000000000..14478e0dbe
> > > > > --- /dev/null
> > > > > +++
> > > > > b/Silicon/Intel/IntelSiliconPkg/Library/PeiDxeSmmBootMediaLib/Pe
> > > > > iF
> > > > > ir
> > > > > mw
> > > > > ar
> > > > > eBootMediaLib.c
> > > > > @@ -0,0 +1,82 @@
> > > > > +/** @file
> > > > > +  This library identifies the firmware boot media device.
> > > > > +
> > > > > +  The firmware boot media device is used to make system
> > > > > + initialization
> > > > > decisions in the boot flow dependent
> > > > > +  upon firmware boot media. Note that the firmware boot media
> > > > > + is the
> > > > > storage media that the boot firmware is stored on.
> > > > > +  It is not the OS storage media which may be stored upon a
> > > > > + different
> > > > > + non-
> > > > > volatile storage device.
> > > > > +
> > > > > +  This file contains implementation specific to the PEI boot phase.
> > > > > +
> > > > > +Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> > > > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > > > +
> > > > > +**/
> > > > > +
> > > > > +#include <Library/BaseLib.h>
> > > > > +#include <Library/DebugLib.h>
> > > > > +#include <Library/FirmwareBootMediaLib.h> #include
> > > > > +<Library/HobLib.h>
> > > > > +
> > > > > +/**
> > > > > +  Determines the current platform firmware boot media device.
> > > > > +
> > > > > +  @param[out] FwBootMediaType The current platform Boot Media
> > > type.
> > > > > +
> > > > > +  @retval     EFI_SUCCESS     The operation completed successfully.
> > > > > +  @retval     EFI_NOT_FOUND   The boot media type could not be
> > found.
> > > > > +**/
> > > > > +EFI_STATUS
> > > > > +EFIAPI
> > > > > +GetFirmwareBootMediaType (
> > > > > +  OUT FW_BOOT_MEDIA_TYPE   *FwBootMediaType
> > > > > +  )
> > > > > +{
> > > > > +  FW_BOOT_MEDIA_HOB_DATA    *BootMediaHobData;
> > > > > +  EFI_HOB_GUID_TYPE         *GuidHobPtr;
> > > > > +
> > > > > +  GuidHobPtr  = GetFirstGuidHob (&gFirmwareBootMediaHobGuid);
> > > > > + if (GuidHobPtr == NULL) {
> > > > > +      DEBUG ((DEBUG_ERROR, "The firmware boot media HOB does
> > > > > + not
> > > > > exist!\n"));
> > > > > +      ASSERT (GuidHobPtr != NULL);
> > > > > +      return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +
> > > > > +  BootMediaHobData = (FW_BOOT_MEDIA_HOB_DATA *)
> > > > > GET_GUID_HOB_DATA (GuidHobPtr);
> > > > > +  if (BootMediaHobData == NULL) {
> > > > > +    return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +
> > > > > +  if (BootMediaHobData->BootMedia >= FwBootMediaMax) {
> > > > > +    DEBUG ((DEBUG_ERROR, "The firmware boot media HOB specifies
> > > > > + an
> > > > > invalid media type.\n"));
> > > > > +    return EFI_NOT_FOUND;
> > > > > +  }
> > > > > +  *FwBootMediaType = BootMediaHobData->BootMedia;
> > > > > +
> > > > > +  return EFI_SUCCESS;
> > > > > +}
> > > > > +
> > > > > +/**
> > > > > +  Determines if the boot media is presently known.
> > > > > +
> > > > > +  Note: Very early in boot this data may not be available.
> > > > > +
> > > > > +  @retval TRUE        Boot media is known
> > > > > +  @retval FALSE       Boot media is not known
> > > > > +**/
> > > > > +BOOLEAN
> > > > > +EFIAPI
> > > > > +FirmwareBootMediaIsKnown (
> > > > > +  VOID
> > > > > +  )
> > > > > +{
> > > > > +  EFI_STATUS          Status;
> > > > > +  FW_BOOT_MEDIA_TYPE  BootMedia;
> > > > > +
> > > > > +  BootMedia = FwBootMediaMax;
> > > > > +  Status = GetFirmwareBootMediaType (&BootMedia);
> > > > > +  if (EFI_ERROR (Status) || BootMedia == FwBootMediaMax) {
> > > > > +    return FALSE;
> > > > > +  } else {
> > > > > +    return TRUE;
> > > > > +  }
> > > > > +}
> > > > > --
> > > > > 2.16.2.windows.1
> > > >
> > >
> >
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-10-10  5:44 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-04 17:29 [edk2-platforms][PATCH V2 0/3] Add FW Boot Media Device Indicator Kubacki, Michael A
2019-10-04 17:29 ` [edk2-platforms][PATCH V2 1/3] IntelSiliconPkg/FirmwareBootMediaLib: Add library Kubacki, Michael A
2019-10-07  1:45   ` Chaganty, Rangasai V
2019-10-09  9:35   ` Ni, Ray
2019-10-09 16:33     ` Kubacki, Michael A
2019-10-10  2:21       ` Ni, Ray
2019-10-10  4:42         ` Kubacki, Michael A
2019-10-10  5:44           ` Ni, Ray
2019-10-04 17:29 ` [edk2-platforms][PATCH V2 2/3] BoardModulePkg/FirmwareBootMediaInfoLib: " Kubacki, Michael A
2019-10-08  7:01   ` Dong, Eric
2019-10-04 17:29 ` [edk2-platforms][PATCH V2 3/3] BoardModulePkg/FirmwareBootMediaInfoPei: Add module Kubacki, Michael A
2019-10-08  7:02   ` Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox