public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 00/12] Add SmiHandlerProfile feature
@ 2017-02-08 16:30 Jiewen Yao
  2017-02-08 16:30 ` [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h Jiewen Yao
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel
  Cc: Michael D Kinney, Liming Gao, Feng Tian, Star Zeng, Laszlo Ersek

This series patch add SMI handler profile.

The purpose of SMI handler profile is to add the capability to
dump all SMI handlers produced by the firmware in a given boot.
The SMI handlers here include
1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
3) Hardware SMI handlers registered with SMM_XXX_DISPATCH_PROTOCOL->Register
by SmmChildDispatcher module.

The final log is an XML format log, including all SMM image name, all SMI
handlers name, type, location (source file and line number), and the caller
who registeres the handler.

We enabled Quark platform to show how to add support in SmmChildDispatcher.

NOTE: This SMI handler profile is a *DEBUG* feature only, to help platform
developer or test engineer to audit the SMI handlers. Please do not include
it in the final *RELEASE* image.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>

Jiewen Yao (12):
  MdePkg/Include: Add SmiHandlerProfileLib.h
  MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
  MdePkg/dsc: add SmiHandlerProfileLib to dsc.
  MdeModulePkg/include: Add SmiHandlerProfile header file.
  MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
  MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
  MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
  MdeModulePkg/App: Add SmiHandlerProfile dump app.
  MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
  BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
  QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
  QuarkPlatformPkg: enable SmiHandlerProfile.

 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
 MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
 MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
 MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
 MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
 MdePkg/MdePkg.dec                                                              |    5 +-
 MdePkg/MdePkg.dsc                                                              |    3 +-
 QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
 QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
 QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
 QuarkPlatformPkg/Readme.md                                                     |   29 +-
 QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
 QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
 28 files changed, 3159 insertions(+), 56 deletions(-)
 create mode 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni
 create mode 100644 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
 create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
 create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
 create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
 create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni
 create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
 create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
 create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
 create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni

-- 
2.7.4.windows.1



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

* [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-10  3:28   ` Gao, Liming
  2017-02-08 16:30 ` [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance Jiewen Yao
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Liming Gao, Laszlo Ersek

This library should be linked by SmmChildDispatch to
report the hardware SMI handler maintained by SmmChildDispatch.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdePkg/Include/Library/SmiHandlerProfileLib.h | 81 ++++++++++++++++++++
 MdePkg/MdePkg.dec                             |  5 +-
 2 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Library/SmiHandlerProfileLib.h b/MdePkg/Include/Library/SmiHandlerProfileLib.h
new file mode 100644
index 0000000..10b7323
--- /dev/null
+++ b/MdePkg/Include/Library/SmiHandlerProfileLib.h
@@ -0,0 +1,81 @@
+/** @file
+  Provides services to log the SMI handler registration.
+
+  This API provides services for the SMM Child Dispatch Protocols provider,
+  to register SMI handler information to SmmCore.
+
+  NOTE:
+  There is no need to update the consumers of SMST->SmiHandlerRegister() or
+  the consumers of SMM Child Dispatch Protocols.
+  The SmmCore (who produces SMST) should have ability to register such
+  information directly.
+  The SmmChildDispatcher (who produces SMM Child Dispatch Protocols) should
+  be responsible to call the services to register information to SMM Core.
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __SMI_HANDLER_PROFILE_LIB_H__
+#define __SMI_HANDLER_PROFILE_LIB_H__
+
+#include <PiSmm.h>
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  a new SMI handler is registered, to SmmCore.
+
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param CallerAddress   The address of the module who registers the SMI handler.
+  @param Context         The context of the SMI handler.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+  @param ContextSize     The size of the context in bytes.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+
+  @retval EFI_SUCCESS           The information is recorded.
+  @retval EFI_UNSUPPORTED       The feature is unsupported.
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileRegisterHandler (
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN PHYSICAL_ADDRESS               CallerAddress,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
+  );
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  an existing SMI handler is unregistered, to SmmCore.
+
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+
+  @retval EFI_SUCCESS           The original record is removed.
+  @retval EFI_UNSUPPORTED       The feature is unsupported.
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileUnregisterHandler (
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  );
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index f2bdb30..3310029 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -4,7 +4,7 @@
 # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of
 # EFI1.10/UEFI2.6/PI1.4 and some Industry Standards.
 #
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 #
@@ -254,6 +254,9 @@
   #
   RngLib|Include/Library/RngLib.h
 
+  ##  @libraryclass  Provides services to log the SMI handler registration.
+  SmiHandlerProfileLib|Include/Library/SmiHandlerProfileLib.h
+
 [LibraryClasses.IPF]
   ##  @libraryclass  The SAL Library provides a service to make a SAL CALL.
   SalLib|Include/Library/SalLib.h
-- 
2.7.4.windows.1



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

* [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
  2017-02-08 16:30 ` [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-10  3:29   ` Gao, Liming
  2017-02-08 16:30 ` [PATCH 03/12] MdePkg/dsc: add SmiHandlerProfileLib to dsc Jiewen Yao
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Liming Gao, Laszlo Ersek

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c   | 72 ++++++++++++++++++++
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf | 36 ++++++++++
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni | 21 ++++++
 3 files changed, 129 insertions(+)

diff --git a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
new file mode 100644
index 0000000..207482a
--- /dev/null
+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
@@ -0,0 +1,72 @@
+/** @file
+  NULL instance of SmiHandlerProfile Library.
+
+  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Library/SmiHandlerProfileLib.h>
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  a new SMI handler is registered, to SmmCore.
+
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param CallerAddress   The address of the module who registers the SMI handler.
+  @param Context         The context of the SMI handler.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+  @param ContextSize     The size of the context in bytes.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+
+  @retval EFI_SUCCESS           The information is recorded.
+  @retval EFI_UNSUPPORTED       The feature is unsupported.
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileRegisterHandler (
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN PHYSICAL_ADDRESS               CallerAddress,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  an existing SMI handler is unregistered, to SmmCore.
+
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+
+  @retval EFI_SUCCESS           The original record is removed.
+  @retval EFI_UNSUPPORTED       The feature is unsupported.
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileUnregisterHandler (
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  )
+{
+  return EFI_UNSUPPORTED;
+}
diff --git a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
new file mode 100644
index 0000000..8220834
--- /dev/null
+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
@@ -0,0 +1,36 @@
+## @file
+# NULL instance of SmiHandlerProfile Library.
+#
+#  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php.
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = SmiHandlerProfileLibNull
+  MODULE_UNI_FILE                = SmiHandlerProfileLibNull.uni
+  FILE_GUID                      = B43D1B52-6251-4E6F-82EC-A599A5EE94C1
+  MODULE_TYPE                    = DXE_SMM_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = SmiHandlerProfileLib|DXE_SMM_DRIVER SMM_CORE
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  SmiHandlerProfileLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
diff --git a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
new file mode 100644
index 0000000..fa3ba63
--- /dev/null
+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
@@ -0,0 +1,21 @@
+// /** @file
+// NULL instance of SmiHandlerProfile Library.
+//
+// NULL instance of SmiHandlerProfile Library.
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php.
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT             #language en-US "NULL instance of SmiHandlerProfile Library"
+
+#string STR_MODULE_DESCRIPTION          #language en-US "NULL instance of SmiHandlerProfile Library."
+
-- 
2.7.4.windows.1



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

* [PATCH 03/12] MdePkg/dsc: add SmiHandlerProfileLib to dsc.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
  2017-02-08 16:30 ` [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h Jiewen Yao
  2017-02-08 16:30 ` [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 16:30 ` [PATCH 04/12] MdeModulePkg/include: Add SmiHandlerProfile header file Jiewen Yao
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Michael D Kinney, Liming Gao, Laszlo Ersek

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdePkg/MdePkg.dsc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index b4575cd..2144979 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 # EFI/PI MdePkg Package
 #
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
 #
 #    This program and the accompanying materials
@@ -155,6 +155,7 @@
   MdePkg/Library/SmmMemLib/SmmMemLib.inf
   MdePkg/Library/BaseRngLib/BaseRngLib.inf
   MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf
+  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
 
 [Components.IPF]
   MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
-- 
2.7.4.windows.1



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

* [PATCH 04/12] MdeModulePkg/include: Add SmiHandlerProfile header file.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (2 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 03/12] MdePkg/dsc: add SmiHandlerProfileLib to dsc Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 16:30 ` [PATCH 05/12] MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask Jiewen Yao
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Star Zeng, Michael D Kinney, Laszlo Ersek

This header file defines:
1) An SMI handler profile protocol. So that SmmChildDispatch
module can register the hardware SMI handler information.
2) The SMI handler profile communication buffer. So that
a shell application can use SMM communication to get the
SMI handler profile info.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h | 177 ++++++++++++++++++++
 MdeModulePkg/MdeModulePkg.dec                 |   5 +-
 2 files changed, 181 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Include/Guid/SmiHandlerProfile.h b/MdeModulePkg/Include/Guid/SmiHandlerProfile.h
new file mode 100644
index 0000000..b81631d
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/SmiHandlerProfile.h
@@ -0,0 +1,177 @@
+/** @file
+  Header file for SMI handler profile definition.
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef  _SMI_HANDLER_PROFILE_H_
+#define  _SMI_HANDLER_PROFILE_H_
+
+#include <PiSmm.h>
+#include <Protocol/SmmGpiDispatch2.h>
+#include <Protocol/SmmIoTrapDispatch2.h>
+#include <Protocol/SmmPeriodicTimerDispatch2.h>
+#include <Protocol/SmmPowerButtonDispatch2.h>
+#include <Protocol/SmmStandbyButtonDispatch2.h>
+#include <Protocol/SmmSwDispatch2.h>
+#include <Protocol/SmmSxDispatch2.h>
+#include <Protocol/SmmUsbDispatch2.h>
+
+#pragma pack(1)
+
+typedef struct {
+  UINT32                       Signature;
+  UINT32                       Length;
+  UINT32                       Revision;
+} SMM_CORE_DATABASE_COMMON_HEADER;
+
+#define SMM_CORE_IMAGE_DATABASE_SIGNATURE SIGNATURE_32 ('S','C','I','D')
+#define SMM_CORE_IMAGE_DATABASE_REVISION  0x0001
+
+typedef struct {
+  SMM_CORE_DATABASE_COMMON_HEADER     Header;
+  EFI_GUID                            FileGuid;
+  UINTN                               ImageRef;
+  UINTN                               EntryPoint;
+  UINTN                               ImageBase;
+  UINTN                               ImageSize;
+  UINT16                              PdbStringOffset;
+  UINT8                               Reserved2[6];
+//CHAR8                               PdbString[];
+} SMM_CORE_IMAGE_DATABASE_STRUCTURE;
+
+#define SMM_CORE_SMI_DATABASE_SIGNATURE SIGNATURE_32 ('S','C','S','D')
+#define SMM_CORE_SMI_DATABASE_REVISION  0x0001
+
+typedef enum {
+  SmmCoreSmiHandlerCategoryRootHandler,
+  SmmCoreSmiHandlerCategoryGuidHandler,
+  SmmCoreSmiHandlerCategoryHardwareHandler,
+} SMM_CORE_SMI_HANDLER_CATEGORY;
+
+//
+// Context for SmmCoreSmiHandlerCategoryRootHandler:
+//   NULL
+// Context for SmmCoreSmiHandlerCategoryGuidHandler:
+//   NULL
+// Context for SmmCoreSmiHandlerCategoryHardwareHandler:
+//   (NOTE: The context field should NOT include any data pointer.)
+//   gEfiSmmSwDispatch2ProtocolGuid:            EFI_SMM_SW_REGISTER_CONTEXT
+//   gEfiSmmSxDispatch2ProtocolGuid:            EFI_SMM_SX_REGISTER_CONTEXT
+//   gEfiSmmPowerButtonDispatch2ProtocolGuid:   EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT
+//   gEfiSmmStandbyButtonDispatch2ProtocolGuid: EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT
+//   gEfiSmmPeriodicTimerDispatch2ProtocolGuid: EFI_SMM_PERIODIC_TIMER_CONTEXT
+//   gEfiSmmGpiDispatch2ProtocolGuid:           EFI_SMM_GPI_REGISTER_CONTEXT
+//   gEfiSmmIoTrapDispatch2ProtocolGuid:        EFI_SMM_IO_TRAP_REGISTER_CONTEXT
+//   gEfiSmmUsbDispatch2ProtocolGuid:           (EFI_SMM_USB_REGISTER_CONTEXT => SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT)
+//   Other:                                     GUID specific
+
+typedef struct {
+  EFI_USB_SMI_TYPE          Type;
+  UINT32                    DevicePathSize;
+//UINT8                     DevicePath[DevicePathSize];
+} SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT;
+
+typedef struct {
+  UINT32     Length;
+  UINTN      CallerAddr;
+  UINTN      Handler;
+  UINTN      ImageRef;
+  UINT16     ContextBufferOffset;
+  UINT8      Reserved2[2];
+  UINT32     ContextBufferSize;
+//UINT8      ContextBuffer[];
+} SMM_CORE_SMI_HANDLER_STRUCTURE;
+
+typedef struct {
+  SMM_CORE_DATABASE_COMMON_HEADER     Header;
+  UINT32                              HandlerCategory;
+  EFI_GUID                            HandlerType;
+  UINTN                               HandlerCount;
+//SMM_CORE_SMI_HANDLER_STRUCTURE      Handler[HandlerCount];
+} SMM_CORE_SMI_DATABASE_STRUCTURE;
+
+//
+// Layout:
+// +-------------------------------------+
+// | SMM_CORE_IMAGE_DATABASE_STRUCTURE   |
+// +-------------------------------------+
+// | SMM_CORE_SMI_DATABASE_STRUCTURE     |
+// +-------------------------------------+
+//
+
+
+
+//
+// SMM_CORE dump command
+//
+#define SMI_HANDLER_PROFILE_COMMAND_GET_INFO           0x1
+#define SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET 0x2
+
+typedef struct {
+  UINT32                            Command;
+  UINT32                            DataLength;
+  UINT64                            ReturnStatus;
+} SMI_HANDLER_PROFILE_PARAMETER_HEADER;
+
+typedef struct {
+  SMI_HANDLER_PROFILE_PARAMETER_HEADER    Header;
+  UINT64                                  DataSize;
+} SMI_HANDLER_PROFILE_PARAMETER_GET_INFO;
+
+typedef struct {
+  SMI_HANDLER_PROFILE_PARAMETER_HEADER    Header;
+  //
+  // On input, data buffer size.
+  // On output, actual data buffer size copied.
+  //
+  UINT64                                  DataSize;
+  PHYSICAL_ADDRESS                        DataBuffer;
+  //
+  // On input, data buffer offset to copy.
+  // On output, next time data buffer offset to copy.
+  //
+  UINT64                                  DataOffset;
+} SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET;
+
+#define SMI_HANDLER_PROFILE_GUID {0x49174342, 0x7108, 0x409b, {0x8b, 0xbe, 0x65, 0xfd, 0xa8, 0x53, 0x89, 0xf5}}
+
+#pragma pack()
+
+extern EFI_GUID gSmiHandlerProfileGuid;
+
+typedef struct _SMI_HANDLER_PROFILE_PROTOCOL  SMI_HANDLER_PROFILE_PROTOCOL;
+
+typedef
+EFI_STATUS
+(EFIAPI  *SMI_HANDLER_PROFILE_REGISTER_HANDLER) (
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN PHYSICAL_ADDRESS               CallerAddress,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
+  );
+
+typedef
+EFI_STATUS
+(EFIAPI  *SMI_HANDLER_PROFILE_UNREGISTER_HANDLER) (
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  );
+
+struct _SMI_HANDLER_PROFILE_PROTOCOL {
+  SMI_HANDLER_PROFILE_REGISTER_HANDLER     RegisterHandler;
+  SMI_HANDLER_PROFILE_UNREGISTER_HANDLER   UnregisterHandler;
+};
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 7307191..393b4a7 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -3,7 +3,7 @@
 # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs and library classes)
 # and libraries instances, which are used for those modules.
 #
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 # This program and the accompanying materials are licensed and made available under
@@ -366,6 +366,9 @@
   ## Include/Guid/PiSmmMemoryAttributesTable.h
   gEdkiiPiSmmMemoryAttributesTableGuid = { 0x6b9fd3f7, 0x16df, 0x45e8, {0xbd, 0x39, 0xb9, 0x4a, 0x66, 0x54, 0x1a, 0x5d}}
 
+  ## Include/Guid/SmiHandlerProfile.h
+  gSmiHandlerProfileGuid = {0x49174342, 0x7108, 0x409b, {0x8b, 0xbe, 0x65, 0xfd, 0xa8, 0x53, 0x89, 0xf5}}
+
   ## Include/Guid/NonDiscoverableDevice.h
   gEdkiiNonDiscoverableAhciDeviceGuid = { 0xC7D35798, 0xE4D2, 0x4A93, {0xB1, 0x45, 0x54, 0x88, 0x9F, 0x02, 0x58, 0x4B } }
   gEdkiiNonDiscoverableAmbaDeviceGuid = { 0x94440339, 0xCC93, 0x4506, {0xB4, 0xC6, 0xEE, 0x8D, 0x0F, 0x4C, 0xA1, 0x91 } }
-- 
2.7.4.windows.1



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

* [PATCH 05/12] MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (3 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 04/12] MdeModulePkg/include: Add SmiHandlerProfile header file Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 16:30 ` [PATCH 06/12] MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance Jiewen Yao
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Star Zeng, Michael D Kinney, Laszlo Ersek

This PCD is linked by PiSmmCore to control if it enables
SMI handler profile feature.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/MdeModulePkg.dec | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 393b4a7..a1f2a4f 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1049,6 +1049,12 @@
   # @Expression  0x80000002 | (gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask & 0x7C) == 0
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask|0x0|UINT8|0x30001041
 
+  ## The mask is used to control SmiHandlerProfile behavior.<BR><BR>
+  #  BIT0 - Enable SmiHandlerProfile.<BR>
+  # @Prompt SmiHandlerProfile Property.
+  # @Expression  0x80000002 | (gEfiMdeModulePkgTokenSpaceGuid.PcdSmiHandlerProfilePropertyMask & 0xFE) == 0
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmiHandlerProfilePropertyMask|0|UINT8|0x00000108
+
   ## This flag is to control which memory types of alloc info will be recorded by DxeCore & SmmCore.<BR><BR>
   # For SmmCore, only EfiRuntimeServicesCode and EfiRuntimeServicesData are valid.<BR>
   #
-- 
2.7.4.windows.1



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

* [PATCH 06/12] MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (4 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 05/12] MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 16:30 ` [PATCH 07/12] MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support Jiewen Yao
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Star Zeng, Michael D Kinney, Laszlo Ersek

This instance should be linked by SmmChildDispatcher
if SMI handler profile feature is enabled.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c   | 106 ++++++++++++++++++++
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf |  46 +++++++++
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni |  21 ++++
 3 files changed, 173 insertions(+)

diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
new file mode 100644
index 0000000..d7ed31e
--- /dev/null
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
@@ -0,0 +1,106 @@
+/** @file
+  SMM driver instance of SmiHandlerProfile Library.
+
+  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Base.h>
+#include <Library/SmiHandlerProfileLib.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Guid/SmiHandlerProfile.h>
+
+SMI_HANDLER_PROFILE_PROTOCOL  *mSmiHandlerProfile;
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  a new SMI handler is registered, to SmmCore.
+
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param CallerAddress   The address of the module who registers the SMI handler.
+  @param Context         The context of the SMI handler.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+  @param ContextSize     The size of the context in bytes.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+
+  @retval EFI_SUCCESS           The information is recorded.
+  @retval EFI_UNSUPPORTED       The feature is unsupported.
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileRegisterHandler (
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN PHYSICAL_ADDRESS               CallerAddress,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
+  )
+{
+  if (mSmiHandlerProfile != NULL) {
+    return mSmiHandlerProfile->RegisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, CallerAddress, Context, ContextSize);
+  }
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  an existing SMI handler is unregistered, to SmmCore.
+
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+
+  @retval EFI_SUCCESS           The original record is removed.
+  @retval EFI_UNSUPPORTED       The feature is unsupported.
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileUnregisterHandler (
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  )
+{
+  if (mSmiHandlerProfile != NULL) {
+    return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler);
+  }
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  The constructor function for SMI handler profile.
+
+  @param  ImageHandle   The firmware allocated handle for the EFI image.
+  @param  SystemTable   A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.
+**/
+EFI_STATUS
+EFIAPI
+SmmSmiHandlerProfileLibConstructor (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  gSmst->SmmLocateProtocol (
+           &gSmiHandlerProfileGuid,
+           NULL,
+           &mSmiHandlerProfile
+           );
+  return EFI_SUCCESS;
+}
+
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
new file mode 100644
index 0000000..0c1ad7e
--- /dev/null
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
@@ -0,0 +1,46 @@
+## @file
+# SMM driver instance of SmiHandlerProfile Library.
+#
+# This library instance provides real functionality for SmmChildDispatcher module.
+#
+#  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php.
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = SmmSmiHandlerProfileLib
+  MODULE_UNI_FILE                = SmmSmiHandlerProfileLib.uni
+  FILE_GUID                      = B43D1B52-6251-4E6F-82EC-A599A5EE94C1
+  MODULE_TYPE                    = DXE_SMM_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = SmiHandlerProfileLib|DXE_SMM_DRIVER
+  CONSTRUCTOR                    = SmmSmiHandlerProfileLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64
+#
+
+[Sources]
+  SmmSmiHandlerProfileLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  SmmServicesTableLib
+
+[Guids]
+  gSmiHandlerProfileGuid  ## CONSUMES   ## GUID # Locate protocol
+
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni
new file mode 100644
index 0000000..f65827d
--- /dev/null
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni
@@ -0,0 +1,21 @@
+// /** @file
+// SMM driver instance of SmiHandlerProfile Library.
+//
+// This library instance provides real functionality for SmmChildDispatcher module.
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php.
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT             #language en-US "SMM driver instance of SmiHandlerProfile Library"
+
+#string STR_MODULE_DESCRIPTION          #language en-US "This library instance provides real functionality for SmmChildDispatcher module."
+
-- 
2.7.4.windows.1



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

* [PATCH 07/12] MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (5 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 06/12] MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 16:30 ` [PATCH 08/12] MdeModulePkg/App: Add SmiHandlerProfile dump app Jiewen Yao
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Star Zeng, Michael D Kinney, Laszlo Ersek

1) SmmCore maintains the root SMI handler and NULL SMI handler
database.
2) SmmCore consumes PcdSmiHandlerProfilePropertyMask to decide
if SmmCore need support SMI handler profile.
If SMI handler profile is supported, the SmmCore installs
SMI handler profile protocol and SMI handler profile
communication handler.
3) SMI handler profile protocol will record the hardware SMI
handler profile registered by SmmChildDispatcher.
4) SMI handler profile communication handler will return all
SMI handler profile info (NULL SMI handler, GUID SMI handler,
and hardware SMI handler)

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c         |    4 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h         |   89 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf       |   17 +-
 MdeModulePkg/Core/PiSmmCore/Smi.c               |   46 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c | 1261 ++++++++++++++++++++
 5 files changed, 1381 insertions(+), 36 deletions(-)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
index de8db65..9e4390e 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c
@@ -1,7 +1,7 @@
 /** @file
   SMM Core Main Entry Point
 
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials are licensed and made available 
   under the terms and conditions of the BSD License which accompanies this 
   distribution.  The full text of the license may be found at        
@@ -680,5 +680,7 @@ SmmMain (
 
   SmmCoreInitializeMemoryAttributesTable ();
 
+  SmmCoreInitializeSmiHandlerProfile ();
+
   return EFI_SUCCESS;
 }
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index 58590d5..bdef026 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines
   internal structure and functions used by SmmCore module.
 
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials are licensed and made available 
   under the terms and conditions of the BSD License which accompanies this 
   distribution.  The full text of the license may be found at        
@@ -38,6 +38,7 @@
 #include <Guid/EventLegacyBios.h>
 #include <Guid/MemoryProfile.h>
 #include <Guid/LoadModuleAtFixedAddress.h>
+#include <Guid/SmiHandlerProfile.h>
 
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
@@ -70,6 +71,32 @@ typedef struct {
 } SMM_CORE_SMI_HANDLERS;
 
 //
+// SMM_HANDLER - used for each SMM handler
+//
+
+#define SMI_ENTRY_SIGNATURE  SIGNATURE_32('s','m','i','e')
+
+ typedef struct {
+  UINTN       Signature;
+  LIST_ENTRY  AllEntries;  // All entries
+
+  EFI_GUID    HandlerType; // Type of interrupt
+  LIST_ENTRY  SmiHandlers; // All handlers
+} SMI_ENTRY;
+
+#define SMI_HANDLER_SIGNATURE  SIGNATURE_32('s','m','i','h')
+
+ typedef struct {
+  UINTN                         Signature;
+  LIST_ENTRY                    Link;        // Link on SMI_ENTRY.SmiHandlers
+  EFI_SMM_HANDLER_ENTRY_POINT2  Handler;     // The smm handler's entry point
+  UINTN                         CallerAddr;  // The address of caller who register the SMI handler.
+  SMI_ENTRY                     *SmiEntry;
+  VOID                          *Context;    // for profile
+  UINTN                         ContextSize; // for profile
+} SMI_HANDLER;
+
+//
 // Structure for recording the state of an SMM Driver
 //
 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
@@ -1064,6 +1091,66 @@ SmmCoreGetMemoryMap (
   OUT UINT32                    *DescriptorVersion
   );
 
+/**
+  Initialize SmiHandler profile feature.
+**/
+VOID
+SmmCoreInitializeSmiHandlerProfile (
+  VOID
+  );
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  a new SMI handler is registered, to SmmCore.
+
+  @param This            The protocol instance
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param CallerAddress   The address of the module who registers the SMI handler.
+  @param Context         The context of the SMI handler.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+  @param ContextSize     The size of the context in bytes.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+
+  @retval EFI_SUCCESS           The information is recorded.
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileRegisterHandler (
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN PHYSICAL_ADDRESS               CallerAddress,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
+  );
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  an existing SMI handler is unregistered, to SmmCore.
+
+  @param This            The protocol instance
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+
+  @retval EFI_SUCCESS           The original record is removed.
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileUnregisterHandler (
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  );
+
 ///
 /// For generic EFI machines make the default allocations 4K aligned
 ///
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
index f380fc5..95e34bd 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
@@ -1,7 +1,7 @@
 ## @file
 # This module provide an SMM CIS compliant implementation of SMM Core.
 #
-# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 #
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD License
@@ -39,6 +39,7 @@
   InstallConfigurationTable.c
   SmramProfileRecord.c
   MemoryAttributesTable.c
+  SmiHandlerProfile.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -63,6 +64,7 @@
   TimerLib
   HobLib
   SmmMemLib
+  DxeServicesLib
 
 [Protocols]
   gEfiDxeSmmReadyToLockProtocolGuid             ## UNDEFINED # SmiHandlerRegister
@@ -78,12 +80,22 @@
   gEdkiiSmmLegacyBootProtocolGuid               ## SOMETIMES_PRODUCES
   gEdkiiSmmReadyToBootProtocolGuid              ## PRODUCES
 
+  gEfiSmmSwDispatch2ProtocolGuid                ## SOMETIMES_CONSUMES
+  gEfiSmmSxDispatch2ProtocolGuid                ## SOMETIMES_CONSUMES
+  gEfiSmmPowerButtonDispatch2ProtocolGuid       ## SOMETIMES_CONSUMES
+  gEfiSmmStandbyButtonDispatch2ProtocolGuid     ## SOMETIMES_CONSUMES
+  gEfiSmmPeriodicTimerDispatch2ProtocolGuid     ## SOMETIMES_CONSUMES
+  gEfiSmmGpiDispatch2ProtocolGuid               ## SOMETIMES_CONSUMES
+  gEfiSmmIoTrapDispatch2ProtocolGuid            ## SOMETIMES_CONSUMES
+  gEfiSmmUsbDispatch2ProtocolGuid               ## SOMETIMES_CONSUMES
+
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressSmmCodePageNumber     ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable        ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileMemoryType             ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask           ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileDriverPath             ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmiHandlerProfilePropertyMask       ## CONSUMES
 
 [Guids]
   gAprioriGuid                                  ## SOMETIMES_CONSUMES   ## File
@@ -100,6 +112,9 @@
   gEdkiiPiSmmMemoryAttributesTableGuid          ## SOMETIMES_PRODUCES   ## SystemTable
   ## SOMETIMES_CONSUMES   ## SystemTable
   gLoadFixedAddressConfigurationTableGuid
+  ## SOMETIMES_PRODUCES   ## GUID # Install protocol
+  ## SOMETIMES_PRODUCES   ## GUID # SmiHandlerRegister
+  gSmiHandlerProfileGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   PiSmmCoreExtra.uni
diff --git a/MdeModulePkg/Core/PiSmmCore/Smi.c b/MdeModulePkg/Core/PiSmmCore/Smi.c
index 816d0f5..ad483a1 100644
--- a/MdeModulePkg/Core/PiSmmCore/Smi.c
+++ b/MdeModulePkg/Core/PiSmmCore/Smi.c
@@ -1,7 +1,7 @@
 /** @file
   SMI management.
 
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials are licensed and made available 
   under the terms and conditions of the BSD License which accompanies this 
   distribution.  The full text of the license may be found at        
@@ -14,32 +14,15 @@
 
 #include "PiSmmCore.h"
 
-//
-// SMM_HANDLER - used for each SMM handler
-//
-
-#define SMI_ENTRY_SIGNATURE  SIGNATURE_32('s','m','i','e')
-
- typedef struct {
-  UINTN       Signature;
-  LIST_ENTRY  AllEntries;  // All entries
-
-  EFI_GUID    HandlerType; // Type of interrupt
-  LIST_ENTRY  SmiHandlers; // All handlers
-} SMI_ENTRY;
-
-#define SMI_HANDLER_SIGNATURE  SIGNATURE_32('s','m','i','h')
-
- typedef struct {
-  UINTN                         Signature;
-  LIST_ENTRY                    Link;        // Link on SMI_ENTRY.SmiHandlers
-  EFI_SMM_HANDLER_ENTRY_POINT2  Handler;     // The smm handler's entry point
-  SMI_ENTRY                     *SmiEntry;
-} SMI_HANDLER;
-
-LIST_ENTRY  mRootSmiHandlerList = INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiHandlerList);
 LIST_ENTRY  mSmiEntryList       = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList);
 
+SMI_ENTRY   mRootSmiEntry = {
+  SMI_ENTRY_SIGNATURE,
+  INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.AllEntries),
+  {0},
+  INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.SmiHandlers),
+};
+
 /**
   Finds the SMI entry for the requested handler type.
 
@@ -137,8 +120,7 @@ SmiManage (
     //
     // Root SMI handler
     //
-
-    Head = &mRootSmiHandlerList;
+    SmiEntry = &mRootSmiEntry;
   } else {
     //
     // Non-root SMI handler
@@ -150,9 +132,8 @@ SmiManage (
       //
       return Status;
     }
-
-    Head = &SmiEntry->SmiHandlers;
   }
+  Head = &SmiEntry->SmiHandlers;
 
   for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
     SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
@@ -252,13 +233,13 @@ SmiHandlerRegister (
 
   SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
   SmiHandler->Handler = Handler;
+  SmiHandler->CallerAddr = (UINTN)RETURN_ADDRESS (0);
 
   if (HandlerType == NULL) {
     //
     // This is root SMI handler
     //
-    SmiEntry = NULL;
-    List = &mRootSmiHandlerList;
+    SmiEntry = &mRootSmiEntry;
   } else {
     //
     // None root SMI handler
@@ -267,9 +248,8 @@ SmiHandlerRegister (
     if (SmiEntry == NULL) {
       return EFI_OUT_OF_RESOURCES;
     }
-
-    List = &SmiEntry->SmiHandlers;
   }
+  List = &SmiEntry->SmiHandlers;
 
   SmiHandler->SmiEntry = SmiEntry;
   InsertTailList (List, &SmiHandler->Link);
diff --git a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
new file mode 100644
index 0000000..f85c0f0
--- /dev/null
+++ b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
@@ -0,0 +1,1261 @@
+/** @file
+  SMI handler profile support.
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiSmm.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/DxeServicesLib.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/SmmAccess2.h>
+#include <Protocol/SmmReadyToLock.h>
+#include <Protocol/SmmEndOfDxe.h>
+
+#include <Guid/SmiHandlerProfile.h>
+
+#include "PiSmmCore.h"
+
+typedef struct {
+  EFI_GUID FileGuid;
+  UINTN    ImageRef;
+  UINTN    EntryPoint;
+  UINTN    ImageBase;
+  UINTN    ImageSize;
+  UINTN    PdbStringSize;
+  CHAR8    *PdbString;
+} IMAGE_STRUCT;
+
+/**
+  Register SMI handler profile handler.
+**/
+VOID
+RegisterSmiHandlerProfileHandler(
+  VOID
+  );
+
+/**
+  Retrieves and returns a pointer to the entry point to a PE/COFF image that has been loaded
+  into system memory with the PE/COFF Loader Library functions.
+
+  Retrieves the entry point to the PE/COFF image specified by Pe32Data and returns this entry
+  point in EntryPoint.  If the entry point could not be retrieved from the PE/COFF image, then
+  return RETURN_INVALID_PARAMETER.  Otherwise return RETURN_SUCCESS.
+  If Pe32Data is NULL, then ASSERT().
+  If EntryPoint is NULL, then ASSERT().
+
+  @param  Pe32Data                  The pointer to the PE/COFF image that is loaded in system memory.
+  @param  EntryPoint                The pointer to entry point to the PE/COFF image to return.
+
+  @retval RETURN_SUCCESS            EntryPoint was returned.
+  @retval RETURN_INVALID_PARAMETER  The entry point could not be found in the PE/COFF image.
+
+**/
+RETURN_STATUS
+InternalPeCoffGetEntryPoint (
+  IN  VOID  *Pe32Data,
+  OUT VOID  **EntryPoint
+  );
+
+extern LIST_ENTRY  mSmiEntryList;
+extern LIST_ENTRY  mHardwareSmiEntryList;
+extern SMI_ENTRY   mRootSmiEntry;
+
+extern SMI_HANDLER_PROFILE_PROTOCOL  mSmiHandlerProfile;
+
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY      mHardwareSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mHardwareSmiEntryList);
+
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY      mRootSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntryList);
+
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY      *mSmmCoreRootSmiEntryList = &mRootSmiEntryList;
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY      *mSmmCoreSmiEntryList = &mSmiEntryList;
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY      *mSmmCoreHardwareSmiEntryList = &mHardwareSmiEntryList;
+
+GLOBAL_REMOVE_IF_UNREFERENCED IMAGE_STRUCT  *mImageStruct;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN         mImageStructCountMax;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN         mImageStructCount;
+
+GLOBAL_REMOVE_IF_UNREFERENCED VOID   *mSmiHandlerProfileDatabase;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN  mSmiHandlerProfileDatabaseSize;
+
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN  mSmmImageDatabaseSize;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN  mSmmRootSmiDatabaseSize;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN  mSmmSmiDatabaseSize;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN  mSmmHardwareSmiDatabaseSize;
+
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN  mSmiHandlerProfileRecordingStatus;
+
+GLOBAL_REMOVE_IF_UNREFERENCED SMI_HANDLER_PROFILE_PROTOCOL  mSmiHandlerProfile = {
+  SmiHandlerProfileRegisterHandler,
+  SmiHandlerProfileUnregisterHandler,
+};
+
+/**
+  This function dump raw data.
+
+  @param  Data  raw data
+  @param  Size  raw data size
+**/
+VOID
+InternalDumpData (
+  IN UINT8  *Data,
+  IN UINTN  Size
+  )
+{
+  UINTN  Index;
+  for (Index = 0; Index < Size; Index++) {
+    DEBUG ((DEBUG_INFO, "%02x ", (UINTN)Data[Index]));
+  }
+}
+
+/**
+  Get GUID name for an image.
+
+  @param[in]  LoadedImage LoadedImage protocol.
+  @param[out] Guid        Guid of the FFS
+**/
+VOID
+GetDriverGuid (
+  IN  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage,
+  OUT EFI_GUID                   *Guid
+  )
+{
+  EFI_GUID                    *FileName;
+
+  FileName = NULL;
+  if ((DevicePathType(LoadedImage->FilePath) == MEDIA_DEVICE_PATH) &&
+      (DevicePathSubType(LoadedImage->FilePath) == MEDIA_PIWG_FW_FILE_DP)) {
+    FileName = &((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LoadedImage->FilePath)->FvFileName;
+  }
+  if (FileName != NULL) {
+    CopyGuid(Guid, FileName);
+  } else {
+    ZeroMem(Guid, sizeof(EFI_GUID));
+  }
+}
+
+/**
+  Add image structure.
+
+  @param  ImageBase         image base
+  @param  ImageSize         image size
+  @param  EntryPoint        image entry point
+  @param  Guid              FFS GUID of the image
+  @param  PdbString         image PDB string
+**/
+VOID
+AddImageStruct(
+  IN UINTN     ImageBase,
+  IN UINTN     ImageSize,
+  IN UINTN     EntryPoint,
+  IN EFI_GUID  *Guid,
+  IN CHAR8     *PdbString
+  )
+{
+  UINTN  PdbStringSize;
+
+  if (mImageStructCount >= mImageStructCountMax) {
+    ASSERT(FALSE);
+    return;
+  }
+
+  CopyGuid(&mImageStruct[mImageStructCount].FileGuid, Guid);
+  mImageStruct[mImageStructCount].ImageRef = mImageStructCount;
+  mImageStruct[mImageStructCount].ImageBase = ImageBase;
+  mImageStruct[mImageStructCount].ImageSize = ImageSize;
+  mImageStruct[mImageStructCount].EntryPoint = EntryPoint;
+  if (PdbString != NULL) {
+    PdbStringSize = AsciiStrSize(PdbString);
+    mImageStruct[mImageStructCount].PdbString = AllocateCopyPool (PdbStringSize, PdbString);
+    if (mImageStruct[mImageStructCount].PdbString != NULL) {
+      mImageStruct[mImageStructCount].PdbStringSize = PdbStringSize;
+    }
+  }
+
+  mImageStructCount++;
+}
+
+/**
+  return an image structure based upon image address.
+
+  @param  Address  image address
+
+  @return image structure
+**/
+IMAGE_STRUCT *
+AddressToImageStruct(
+  IN UINTN  Address
+  )
+{
+  UINTN  Index;
+
+  for (Index = 0; Index < mImageStructCount; Index++) {
+    if ((Address >= mImageStruct[Index].ImageBase) &&
+        (Address < mImageStruct[Index].ImageBase + mImageStruct[Index].ImageSize)) {
+      return &mImageStruct[Index];
+    }
+  }
+  return NULL;
+}
+
+/**
+  return an image reference index based upon image address.
+
+  @param  Address  image address
+
+  @return image reference index
+**/
+UINTN
+AddressToImageRef(
+  IN UINTN  Address
+  )
+{
+  IMAGE_STRUCT *ImageStruct;
+
+  ImageStruct = AddressToImageStruct(Address);
+  if (ImageStruct != NULL) {
+    return ImageStruct->ImageRef;
+  }
+  return (UINTN)-1;
+}
+
+/**
+  Collect SMM image information based upon loaded image protocol.
+**/
+VOID
+GetSmmLoadedImage(
+  VOID
+  )
+{
+  EFI_STATUS                 Status;
+  UINTN                      NoHandles;
+  UINTN                      HandleBufferSize;
+  EFI_HANDLE                 *HandleBuffer;
+  UINTN                      Index;
+  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;
+  CHAR16                     *PathStr;
+  EFI_SMM_DRIVER_ENTRY       *LoadedImagePrivate;
+  UINTN                      EntryPoint;
+  VOID                       *EntryPointInImage;
+  EFI_GUID                   Guid;
+  CHAR8                      *PdbString;
+  UINTN                      RealImageBase;
+
+  HandleBufferSize = 0;
+  HandleBuffer = NULL;
+  Status = gSmst->SmmLocateHandle(
+                    ByProtocol,
+                    &gEfiLoadedImageProtocolGuid,
+                    NULL,
+                    &HandleBufferSize,
+                    HandleBuffer
+                    );
+  if (Status != EFI_BUFFER_TOO_SMALL) {
+    return;
+  }
+  HandleBuffer = AllocateZeroPool (HandleBufferSize);
+  if (HandleBuffer == NULL) {
+    return;
+  }
+  Status = gSmst->SmmLocateHandle(
+                    ByProtocol,
+                    &gEfiLoadedImageProtocolGuid,
+                    NULL,
+                    &HandleBufferSize,
+                    HandleBuffer
+                    );
+  if (EFI_ERROR(Status)) {
+    return;
+  }
+
+  NoHandles = HandleBufferSize/sizeof(EFI_HANDLE);
+  mImageStructCountMax = NoHandles;
+  mImageStruct = AllocateZeroPool(mImageStructCountMax * sizeof(IMAGE_STRUCT));
+  if (mImageStruct == NULL) {
+    goto Done;
+  }
+
+  for (Index = 0; Index < NoHandles; Index++) {
+    Status = gSmst->SmmHandleProtocol(
+                      HandleBuffer[Index],
+                      &gEfiLoadedImageProtocolGuid,
+                      (VOID **)&LoadedImage
+                      );
+    if (EFI_ERROR(Status)) {
+      continue;
+    }
+    PathStr = ConvertDevicePathToText(LoadedImage->FilePath, TRUE, TRUE);
+    GetDriverGuid(LoadedImage, &Guid);
+    DEBUG ((DEBUG_INFO, "Image: %g ", &Guid));
+
+    EntryPoint = 0;
+    LoadedImagePrivate = BASE_CR(LoadedImage, EFI_SMM_DRIVER_ENTRY, SmmLoadedImage);
+    RealImageBase = (UINTN)LoadedImage->ImageBase;
+    if (LoadedImagePrivate->Signature == EFI_SMM_DRIVER_ENTRY_SIGNATURE) {
+      EntryPoint = (UINTN)LoadedImagePrivate->ImageEntryPoint;
+      if ((EntryPoint != 0) && ((EntryPoint < (UINTN)LoadedImage->ImageBase) || (EntryPoint >= ((UINTN)LoadedImage->ImageBase + (UINTN)LoadedImage->ImageSize)))) {
+        //
+        // If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
+        // So patch ImageBuffer here to align the EntryPoint.
+        //
+        Status = InternalPeCoffGetEntryPoint(LoadedImage->ImageBase, &EntryPointInImage);
+        ASSERT_EFI_ERROR(Status);
+        RealImageBase = (UINTN)LoadedImage->ImageBase + EntryPoint - (UINTN)EntryPointInImage;
+      }
+    }
+    DEBUG ((DEBUG_INFO, "(0x%x - 0x%x", RealImageBase, (UINTN)LoadedImage->ImageSize));
+    if (EntryPoint != 0) {
+      DEBUG ((DEBUG_INFO, ", EntryPoint:0x%x", EntryPoint));
+    }
+    DEBUG ((DEBUG_INFO, ")\n"));
+
+    if (RealImageBase != 0) {
+      PdbString = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) RealImageBase);
+      DEBUG ((DEBUG_INFO, "       pdb - %a\n", PdbString));
+    } else {
+      PdbString = NULL;
+    }
+    DEBUG ((DEBUG_INFO, "       (%s)\n", PathStr));
+
+    AddImageStruct((UINTN)RealImageBase, (UINTN)LoadedImage->ImageSize, EntryPoint, &Guid, PdbString);
+  }
+
+Done:
+  FreePool(HandleBuffer);
+  return;
+}
+
+/**
+  Dump SMI child context.
+
+  @param HandlerType  the handler type
+  @param Context      the handler context
+  @param ContextSize  the handler context size
+**/
+VOID
+DumpSmiChildContext (
+  IN EFI_GUID   *HandlerType,
+  IN VOID       *Context,
+  IN UINTN      ContextSize
+  )
+{
+  if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  SwSmi - 0x%x\n", ((EFI_SMM_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue));
+  } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  SxType - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type));
+    DEBUG ((DEBUG_INFO, "  SxPhase - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase));
+  } else if (CompareGuid (HandlerType, &gEfiSmmPowerButtonDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  PowerButtonPhase - 0x%x\n", ((EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT *)Context)->Phase));
+  } else if (CompareGuid (HandlerType, &gEfiSmmStandbyButtonDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  StandbyButtonPhase - 0x%x\n", ((EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT *)Context)->Phase));
+  } else if (CompareGuid (HandlerType, &gEfiSmmPeriodicTimerDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  PeriodicTimerPeriod - %ld\n", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->Period));
+    DEBUG ((DEBUG_INFO, "  PeriodicTimerSmiTickInterval - %ld\n", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->SmiTickInterval));
+  } else if (CompareGuid (HandlerType, &gEfiSmmGpiDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  GpiNum - 0x%lx\n", ((EFI_SMM_GPI_REGISTER_CONTEXT *)Context)->GpiNum));
+  } else if (CompareGuid (HandlerType, &gEfiSmmIoTrapDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  IoTrapAddress - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Address));
+    DEBUG ((DEBUG_INFO, "  IoTrapLength - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Length));
+    DEBUG ((DEBUG_INFO, "  IoTrapType - 0x%x\n", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Type));
+  } else if (CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) {
+    DEBUG ((DEBUG_INFO, "  UsbType - 0x%x\n", ((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context)->Type));
+    DEBUG ((DEBUG_INFO, "  UsbDevicePath - %s\n", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL *)(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context) + 1), TRUE, TRUE)));
+  } else {
+    DEBUG ((DEBUG_INFO, "  Context - "));
+    InternalDumpData (Context, ContextSize);
+    DEBUG ((DEBUG_INFO, "\n"));
+  }
+}
+
+/**
+  Dump all SMI handlers associated with SmiEntry.
+
+  @param SmiEntry  SMI entry.
+**/
+VOID
+DumpSmiHandlerOnSmiEntry(
+  IN SMI_ENTRY       *SmiEntry
+  )
+{
+  LIST_ENTRY      *ListEntry;
+  SMI_HANDLER     *SmiHandler;
+  IMAGE_STRUCT    *ImageStruct;
+
+  ListEntry = &SmiEntry->SmiHandlers;
+  for (ListEntry = ListEntry->ForwardLink;
+       ListEntry != &SmiEntry->SmiHandlers;
+       ListEntry = ListEntry->ForwardLink) {
+    SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+    ImageStruct = AddressToImageStruct((UINTN)SmiHandler->Handler);
+    if (ImageStruct != NULL) {
+      DEBUG ((DEBUG_INFO, " Module - %g", &ImageStruct->FileGuid));
+    }
+    if ((ImageStruct != NULL) && (ImageStruct->PdbString[0] != 0)) {
+      DEBUG ((DEBUG_INFO, " (Pdb - %a)", ImageStruct->PdbString));
+    }
+    DEBUG ((DEBUG_INFO, "\n"));
+    if (SmiHandler->ContextSize != 0) {
+      DumpSmiChildContext (&SmiEntry->HandlerType, SmiHandler->Context, SmiHandler->ContextSize);
+    }
+    DEBUG ((DEBUG_INFO, "  Handler - 0x%x", SmiHandler->Handler));
+    if (ImageStruct != NULL) {
+      DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", (UINTN)SmiHandler->Handler - ImageStruct->ImageBase));
+    }
+    DEBUG ((DEBUG_INFO, "\n"));
+    DEBUG ((DEBUG_INFO, "  CallerAddr - 0x%x", SmiHandler->CallerAddr));
+    if (ImageStruct != NULL) {
+      DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", SmiHandler->CallerAddr - ImageStruct->ImageBase));
+    }
+    DEBUG ((DEBUG_INFO, "\n"));
+  }
+
+  return;
+}
+
+/**
+  Dump all SMI entry on the list.
+
+  @param SmiEntryList a list of SMI entry.
+**/
+VOID
+DumpSmiEntryList(
+  IN LIST_ENTRY      *SmiEntryList
+  )
+{
+  LIST_ENTRY      *ListEntry;
+  SMI_ENTRY       *SmiEntry;
+
+  ListEntry = SmiEntryList;
+  for (ListEntry = ListEntry->ForwardLink;
+       ListEntry != SmiEntryList;
+       ListEntry = ListEntry->ForwardLink) {
+    SmiEntry = CR(ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+    DEBUG ((DEBUG_INFO, "SmiEntry - %g\n", &SmiEntry->HandlerType));
+    DumpSmiHandlerOnSmiEntry(SmiEntry);
+  }
+
+  return;
+}
+
+/**
+  SMM Ready To Lock event notification handler.
+
+  This function collects all SMM image information and build SmiHandleProfile database,
+  and register SmiHandlerProfile SMI handler.
+
+  @param[in] Protocol   Points to the protocol's unique identifier.
+  @param[in] Interface  Points to the interface instance.
+  @param[in] Handle     The handle on which the interface was installed.
+
+  @retval EFI_SUCCESS   Notification handler runs successfully.
+**/
+EFI_STATUS
+EFIAPI
+SmmReadyToLockInSmiHandlerProfile (
+  IN CONST EFI_GUID  *Protocol,
+  IN VOID            *Interface,
+  IN EFI_HANDLE      Handle
+  )
+{
+  //
+  // Dump all image
+  //
+  DEBUG ((DEBUG_INFO, "##################\n"));
+  DEBUG ((DEBUG_INFO, "# IMAGE DATABASE #\n"));
+  DEBUG ((DEBUG_INFO, "##################\n"));
+  GetSmmLoadedImage ();
+  DEBUG ((DEBUG_INFO, "\n"));
+
+  //
+  // Dump SMI Handler
+  //
+  DEBUG ((DEBUG_INFO, "########################\n"));
+  DEBUG ((DEBUG_INFO, "# SMI Handler DATABASE #\n"));
+  DEBUG ((DEBUG_INFO, "########################\n"));
+
+  DEBUG ((DEBUG_INFO, "# 1. ROOT SMI Handler #\n"));
+  DEBUG_CODE (
+    DumpSmiEntryList(mSmmCoreRootSmiEntryList);
+  );
+
+  DEBUG ((DEBUG_INFO, "# 2. GUID SMI Handler #\n"));
+  DEBUG_CODE (
+    DumpSmiEntryList(mSmmCoreSmiEntryList);
+  );
+
+  DEBUG ((DEBUG_INFO, "# 3. Hardware SMI Handler #\n"));
+  DEBUG_CODE (
+    DumpSmiEntryList(mSmmCoreHardwareSmiEntryList);
+  );
+
+  DEBUG ((DEBUG_INFO, "\n"));
+
+  RegisterSmiHandlerProfileHandler();
+
+  if (mImageStruct != NULL) {
+    FreePool(mImageStruct);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  returns SMM image data base size.
+
+  @return SMM image data base size.
+**/
+UINTN
+GetSmmImageDatabaseSize(
+  VOID
+  )
+{
+  UINTN  Size;
+  UINTN  Index;
+
+  Size = (sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE)) * mImageStructCount;
+  for (Index = 0; Index < mImageStructCount; Index++) {
+    Size += mImageStruct[Index].PdbStringSize;
+  }
+  return Size;
+}
+
+/**
+  returns all SMI handlers' size associated with SmiEntry.
+
+  @param SmiEntry  SMI entry.
+
+  @return all SMI handlers' size associated with SmiEntry.
+**/
+UINTN
+GetSmmSmiHandlerSizeOnSmiEntry(
+  IN SMI_ENTRY       *SmiEntry
+  )
+{
+  LIST_ENTRY      *ListEntry;
+  SMI_HANDLER     *SmiHandler;
+  UINTN           Size;
+
+  Size = 0;
+  ListEntry = &SmiEntry->SmiHandlers;
+  for (ListEntry = ListEntry->ForwardLink;
+       ListEntry != &SmiEntry->SmiHandlers;
+       ListEntry = ListEntry->ForwardLink) {
+    SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+    Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize;
+  }
+
+  return Size;
+}
+
+/**
+  return all SMI handler database size on the SMI entry list.
+
+  @param SmiEntryList a list of SMI entry.
+
+  @return all SMI handler database size on the SMI entry list.
+**/
+UINTN
+GetSmmSmiDatabaseSize(
+  IN LIST_ENTRY      *SmiEntryList
+  )
+{
+  LIST_ENTRY      *ListEntry;
+  SMI_ENTRY       *SmiEntry;
+  UINTN           Size;
+
+  Size = 0;
+  ListEntry = SmiEntryList;
+  for (ListEntry = ListEntry->ForwardLink;
+       ListEntry != SmiEntryList;
+       ListEntry = ListEntry->ForwardLink) {
+    SmiEntry = CR(ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+    Size += sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE);
+    Size += GetSmmSmiHandlerSizeOnSmiEntry(SmiEntry);
+  }
+  return Size;
+}
+
+/**
+  return SMI handler profile database size.
+
+  @return SMI handler profile database size.
+**/
+UINTN
+GetSmiHandlerProfileDatabaseSize (
+  VOID
+  )
+{
+  mSmmImageDatabaseSize = GetSmmImageDatabaseSize();
+  mSmmRootSmiDatabaseSize = GetSmmSmiDatabaseSize(mSmmCoreRootSmiEntryList);
+  mSmmSmiDatabaseSize = GetSmmSmiDatabaseSize(mSmmCoreSmiEntryList);
+  mSmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseSize(mSmmCoreHardwareSmiEntryList);
+
+  return mSmmImageDatabaseSize + mSmmSmiDatabaseSize + mSmmRootSmiDatabaseSize + mSmmHardwareSmiDatabaseSize;
+}
+
+/**
+  get SMM image database.
+
+  @param Data           The buffer to hold SMM image database
+  @param ExpectedSize   The expected size of the SMM image database
+
+  @return SMM image data base size.
+**/
+UINTN
+GetSmmImageDatabaseData (
+  IN OUT VOID  *Data,
+  IN     UINTN ExpectedSize
+  )
+{
+  SMM_CORE_IMAGE_DATABASE_STRUCTURE   *ImageStruct;
+  UINTN                               Size;
+  UINTN                               Index;
+
+  ImageStruct = Data;
+  Size = 0;
+  for (Index = 0; Index < mImageStructCount; Index++) {
+    if (Size >= ExpectedSize) {
+      return 0;
+    }
+    if (sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + mImageStruct[Index].PdbStringSize > ExpectedSize - Size) {
+      return 0;
+    }
+    ImageStruct->Header.Signature = SMM_CORE_IMAGE_DATABASE_SIGNATURE;
+    ImageStruct->Header.Length = (UINT32)(sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + mImageStruct[Index].PdbStringSize);
+    ImageStruct->Header.Revision = SMM_CORE_IMAGE_DATABASE_REVISION;
+    CopyGuid(&ImageStruct->FileGuid, &mImageStruct[Index].FileGuid);
+    ImageStruct->ImageRef = mImageStruct[Index].ImageRef;
+    ImageStruct->EntryPoint = mImageStruct[Index].EntryPoint;
+    ImageStruct->ImageBase = mImageStruct[Index].ImageBase;
+    ImageStruct->ImageSize = mImageStruct[Index].ImageSize;
+    ImageStruct->PdbStringOffset = sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE);
+    CopyMem ((VOID *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset), mImageStruct[Index].PdbString, mImageStruct[Index].PdbStringSize);
+    ImageStruct = (SMM_CORE_IMAGE_DATABASE_STRUCTURE *)((UINTN)ImageStruct + ImageStruct->Header.Length);
+    Size += sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + mImageStruct[Index].PdbStringSize;
+  }
+
+  if (ExpectedSize != Size) {
+    return 0;
+  }
+  return Size;
+}
+
+/**
+  get all SMI handler data associated with SmiEntry.
+
+  @param SmiEntry       SMI entry.
+  @param Data           The buffer to hold all SMI handler data
+  @param MaxSize        The max size of the SMM image database
+  @param Count          The count of the SMI handler.
+
+  @return SMM image data base size.
+**/
+UINTN
+GetSmmSmiHandlerDataOnSmiEntry(
+  IN     SMI_ENTRY       *SmiEntry,
+  IN OUT VOID            *Data,
+  IN     UINTN           MaxSize,
+     OUT UINTN           *Count
+  )
+{
+  SMM_CORE_SMI_HANDLER_STRUCTURE   *SmiHandlerStruct;
+  LIST_ENTRY                       *ListEntry;
+  SMI_HANDLER                      *SmiHandler;
+  UINTN                            Size;
+
+  SmiHandlerStruct = Data;
+  Size = 0;
+  *Count = 0;
+  ListEntry = &SmiEntry->SmiHandlers;
+  for (ListEntry = ListEntry->ForwardLink;
+       ListEntry != &SmiEntry->SmiHandlers;
+       ListEntry = ListEntry->ForwardLink) {
+    SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+    if (Size >= MaxSize) {
+      *Count = 0;
+      return 0;
+    }
+    if (sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize > MaxSize - Size) {
+      *Count = 0;
+      return 0;
+    }
+    SmiHandlerStruct->Length = (UINT32)(sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize);
+    SmiHandlerStruct->CallerAddr = (UINTN)SmiHandler->CallerAddr;
+    SmiHandlerStruct->Handler = (UINTN)SmiHandler->Handler;
+    SmiHandlerStruct->ImageRef = AddressToImageRef((UINTN)SmiHandler->Handler);
+    SmiHandlerStruct->ContextBufferSize = (UINT32)SmiHandler->ContextSize;
+    if (SmiHandler->ContextSize != 0) {
+      SmiHandlerStruct->ContextBufferOffset = sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE);
+      CopyMem ((UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandler->Context, SmiHandler->ContextSize);
+    } else {
+      SmiHandlerStruct->ContextBufferOffset = 0;
+    }
+    Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize;
+    SmiHandlerStruct = (SMM_CORE_SMI_HANDLER_STRUCTURE *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
+    *Count = *Count + 1;
+  }
+
+  return Size;
+}
+
+/**
+  get all SMI handler database on the SMI entry list.
+
+  @param SmiEntryList     a list of SMI entry.
+  @param HandlerCategory  The handler category
+  @param Data             The buffer to hold all SMI handler database
+  @param ExpectedSize     The expected size of the SMM image database
+
+  @return all SMI database size on the SMI entry list.
+**/
+UINTN
+GetSmmSmiDatabaseData(
+  IN     LIST_ENTRY      *SmiEntryList,
+  IN     UINT32          HandlerCategory,
+  IN OUT VOID            *Data,
+  IN     UINTN           ExpectedSize
+  )
+{
+  SMM_CORE_SMI_DATABASE_STRUCTURE   *SmiStruct;
+  LIST_ENTRY                        *ListEntry;
+  SMI_ENTRY                         *SmiEntry;
+  UINTN                             Size;
+  UINTN                             SmiHandlerSize;
+  UINTN                             SmiHandlerCount;
+
+  SmiStruct = Data;
+  Size = 0;
+  ListEntry = SmiEntryList;
+  for (ListEntry = ListEntry->ForwardLink;
+       ListEntry != SmiEntryList;
+       ListEntry = ListEntry->ForwardLink) {
+    SmiEntry = CR(ListEntry, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+    if (Size >= ExpectedSize) {
+      return 0;
+    }
+    if (sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE) > ExpectedSize - Size) {
+      return 0;
+    }
+
+    SmiStruct->Header.Signature = SMM_CORE_SMI_DATABASE_SIGNATURE;
+    SmiStruct->Header.Length = sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE);
+    SmiStruct->Header.Revision = SMM_CORE_SMI_DATABASE_REVISION;
+    SmiStruct->HandlerCategory = HandlerCategory;
+    CopyGuid(&SmiStruct->HandlerType, &SmiEntry->HandlerType);
+    Size += sizeof(SMM_CORE_SMI_DATABASE_STRUCTURE);
+    SmiHandlerSize = GetSmmSmiHandlerDataOnSmiEntry(SmiEntry, (UINT8 *)SmiStruct + SmiStruct->Header.Length, ExpectedSize - Size, &SmiHandlerCount);
+    SmiStruct->HandlerCount = SmiHandlerCount;
+    Size += SmiHandlerSize;
+    SmiStruct->Header.Length += (UINT32)SmiHandlerSize;
+    SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);
+  }
+  if (ExpectedSize != Size) {
+    return 0;
+  }
+  return Size;
+}
+
+/**
+  Get SMI handler profile database.
+
+  @param Data the buffer to hold SMI handler profile database
+
+  @retval EFI_SUCCESS            the database is got.
+  @retval EFI_INVALID_PARAMETER  the database size mismatch.
+**/
+EFI_STATUS
+GetSmiHandlerProfileDatabaseData(
+  IN OUT VOID *Data
+  )
+{
+  UINTN  SmmImageDatabaseSize;
+  UINTN  SmmSmiDatabaseSize;
+  UINTN  SmmRootSmiDatabaseSize;
+  UINTN  SmmHardwareSmiDatabaseSize;
+
+  DEBUG((DEBUG_VERBOSE, "GetSmiHandlerProfileDatabaseData\n"));
+  SmmImageDatabaseSize = GetSmmImageDatabaseData(Data, mSmmImageDatabaseSize);
+  if (SmmImageDatabaseSize != mSmmImageDatabaseSize) {
+    DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmImageDatabaseSize mismatch!\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+  SmmRootSmiDatabaseSize = GetSmmSmiDatabaseData(mSmmCoreRootSmiEntryList, SmmCoreSmiHandlerCategoryRootHandler, (UINT8 *)Data + SmmImageDatabaseSize, mSmmRootSmiDatabaseSize);
+  if (SmmRootSmiDatabaseSize != mSmmRootSmiDatabaseSize) {
+    DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmRootSmiDatabaseSize mismatch!\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+  SmmSmiDatabaseSize = GetSmmSmiDatabaseData(mSmmCoreSmiEntryList, SmmCoreSmiHandlerCategoryGuidHandler, (UINT8 *)Data + SmmImageDatabaseSize + mSmmRootSmiDatabaseSize, mSmmSmiDatabaseSize);
+  if (SmmSmiDatabaseSize != mSmmSmiDatabaseSize) {
+    DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmSmiDatabaseSize mismatch!\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+  SmmHardwareSmiDatabaseSize = GetSmmSmiDatabaseData(mSmmCoreHardwareSmiEntryList, SmmCoreSmiHandlerCategoryHardwareHandler, (UINT8 *)Data + SmmImageDatabaseSize + SmmRootSmiDatabaseSize + SmmSmiDatabaseSize, mSmmHardwareSmiDatabaseSize);
+  if (SmmHardwareSmiDatabaseSize != mSmmHardwareSmiDatabaseSize) {
+    DEBUG((DEBUG_ERROR, "GetSmiHandlerProfileDatabaseData - SmmHardwareSmiDatabaseSize mismatch!\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  build SMI handler profile database.
+**/
+VOID
+BuildSmiHandlerProfileDatabase(
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  mSmiHandlerProfileDatabaseSize = GetSmiHandlerProfileDatabaseSize();
+  mSmiHandlerProfileDatabase = AllocatePool(mSmiHandlerProfileDatabaseSize);
+  if (mSmiHandlerProfileDatabase == NULL) {
+    return;
+  }
+  Status = GetSmiHandlerProfileDatabaseData(mSmiHandlerProfileDatabase);
+  if (EFI_ERROR(Status)) {
+    FreePool(mSmiHandlerProfileDatabase);
+    mSmiHandlerProfileDatabase = NULL;
+  }
+}
+
+/**
+  Copy SMI handler profile data.
+
+  @param DataBuffer  The buffer to hold SMI handler profile data.
+  @param DataSize    On input, data buffer size.
+                     On output, actual data buffer size copied.
+  @param DataOffset  On input, data buffer offset to copy.
+                     On output, next time data buffer offset to copy.
+
+**/
+VOID
+SmiHandlerProfileCopyData(
+  OUT VOID      *DataBuffer,
+  IN OUT UINT64 *DataSize,
+  IN OUT UINT64 *DataOffset
+  )
+{
+  if (*DataOffset >= mSmiHandlerProfileDatabaseSize) {
+    *DataOffset = mSmiHandlerProfileDatabaseSize;
+    return;
+  }
+  if (mSmiHandlerProfileDatabaseSize - *DataOffset < *DataSize) {
+    *DataSize = mSmiHandlerProfileDatabaseSize - *DataOffset;
+  }
+
+  CopyMem(
+    DataBuffer,
+    (UINT8 *)mSmiHandlerProfileDatabase + *DataOffset,
+    (UINTN)*DataSize
+    );
+  *DataOffset = *DataOffset + *DataSize;
+}
+
+/**
+  SMI handler profile handler to get info.
+
+  @param SmiHandlerProfileParameterGetInfo The parameter of SMI handler profile get info.
+
+**/
+VOID
+SmiHandlerProfileHandlerGetInfo(
+  IN SMI_HANDLER_PROFILE_PARAMETER_GET_INFO   *SmiHandlerProfileParameterGetInfo
+  )
+{
+  BOOLEAN                       SmiHandlerProfileRecordingStatus;
+
+  SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
+  mSmiHandlerProfileRecordingStatus = FALSE;
+
+  SmiHandlerProfileParameterGetInfo->DataSize = mSmiHandlerProfileDatabaseSize;
+  SmiHandlerProfileParameterGetInfo->Header.ReturnStatus = 0;
+
+  mSmiHandlerProfileRecordingStatus = SmiHandlerProfileRecordingStatus;
+}
+
+/**
+  SMI handler profile handler to get data by offset.
+
+  @param SmiHandlerProfileParameterGetDataByOffset   The parameter of SMI handler profile get data by offset.
+
+**/
+VOID
+SmiHandlerProfileHandlerGetDataByOffset(
+  IN SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET     *SmiHandlerProfileParameterGetDataByOffset
+  )
+{
+  SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET    SmiHandlerProfileGetDataByOffset;
+  BOOLEAN                                             SmiHandlerProfileRecordingStatus;
+
+  SmiHandlerProfileRecordingStatus = mSmiHandlerProfileRecordingStatus;
+  mSmiHandlerProfileRecordingStatus = FALSE;
+
+  CopyMem(&SmiHandlerProfileGetDataByOffset, SmiHandlerProfileParameterGetDataByOffset, sizeof(SmiHandlerProfileGetDataByOffset));
+
+  //
+  // Sanity check
+  //
+  if (!SmmIsBufferOutsideSmmValid((UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, (UINTN)SmiHandlerProfileGetDataByOffset.DataSize)) {
+    DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset: SMI handler profile get data in SMRAM or overflow!\n"));
+    SmiHandlerProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED;
+    goto Done;
+  }
+
+  SmiHandlerProfileCopyData((VOID *)(UINTN)SmiHandlerProfileGetDataByOffset.DataBuffer, &SmiHandlerProfileGetDataByOffset.DataSize, &SmiHandlerProfileGetDataByOffset.DataOffset);
+  CopyMem(SmiHandlerProfileParameterGetDataByOffset, &SmiHandlerProfileGetDataByOffset, sizeof(SmiHandlerProfileGetDataByOffset));
+  SmiHandlerProfileParameterGetDataByOffset->Header.ReturnStatus = 0;
+
+Done:
+  mSmiHandlerProfileRecordingStatus = SmiHandlerProfileRecordingStatus;
+}
+
+/**
+  Dispatch function for a Software SMI handler.
+
+  Caution: This function may receive untrusted input.
+  Communicate buffer and buffer size are external input, so this function will do basic validation.
+
+  @param DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().
+  @param Context         Points to an optional handler context which was specified when the
+                         handler was registered.
+  @param CommBuffer      A pointer to a collection of data in memory that will
+                         be conveyed from a non-SMM environment into an SMM environment.
+  @param CommBufferSize  The size of the CommBuffer.
+
+  @retval EFI_SUCCESS Command is handled successfully.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileHandler(
+  IN EFI_HANDLE  DispatchHandle,
+  IN CONST VOID  *Context         OPTIONAL,
+  IN OUT VOID    *CommBuffer      OPTIONAL,
+  IN OUT UINTN   *CommBufferSize  OPTIONAL
+  )
+{
+  SMI_HANDLER_PROFILE_PARAMETER_HEADER           *SmiHandlerProfileParameterHeader;
+  UINTN                                    TempCommBufferSize;
+
+  DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler Enter\n"));
+
+  if (mSmiHandlerProfileDatabase == NULL) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // If input is invalid, stop processing this SMI
+  //
+  if (CommBuffer == NULL || CommBufferSize == NULL) {
+    return EFI_SUCCESS;
+  }
+
+  TempCommBufferSize = *CommBufferSize;
+
+  if (TempCommBufferSize < sizeof(SMI_HANDLER_PROFILE_PARAMETER_HEADER)) {
+    DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
+    return EFI_SUCCESS;
+  }
+
+  if (!SmmIsBufferOutsideSmmValid((UINTN)CommBuffer, TempCommBufferSize)) {
+    DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));
+    return EFI_SUCCESS;
+  }
+
+  SmiHandlerProfileParameterHeader = (SMI_HANDLER_PROFILE_PARAMETER_HEADER *)((UINTN)CommBuffer);
+  SmiHandlerProfileParameterHeader->ReturnStatus = (UINT64)-1;
+
+  switch (SmiHandlerProfileParameterHeader->Command) {
+  case SMI_HANDLER_PROFILE_COMMAND_GET_INFO:
+    DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandlerGetInfo\n"));
+    if (TempCommBufferSize != sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_INFO)) {
+      DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
+      return EFI_SUCCESS;
+    }
+    SmiHandlerProfileHandlerGetInfo((SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *)(UINTN)CommBuffer);
+    break;
+  case SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET:
+    DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandlerGetDataByOffset\n"));
+    if (TempCommBufferSize != sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET)) {
+      DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler: SMM communication buffer size invalid!\n"));
+      return EFI_SUCCESS;
+    }
+    SmiHandlerProfileHandlerGetDataByOffset((SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *)(UINTN)CommBuffer);
+    break;
+  default:
+    break;
+  }
+
+  DEBUG((DEBUG_ERROR, "SmiHandlerProfileHandler Exit\n"));
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Register SMI handler profile handler.
+**/
+VOID
+RegisterSmiHandlerProfileHandler (
+  VOID
+  )
+{
+  EFI_STATUS    Status;
+  EFI_HANDLE    DispatchHandle;
+
+  Status = gSmst->SmiHandlerRegister (
+                    SmiHandlerProfileHandler,
+                    &gSmiHandlerProfileGuid,
+                    &DispatchHandle
+                    );
+  ASSERT_EFI_ERROR (Status);
+
+  BuildSmiHandlerProfileDatabase();
+}
+
+/**
+  Finds the SMI entry for the requested handler type.
+
+  @param  HandlerType            The type of the interrupt
+  @param  Create                 Create a new entry if not found
+
+  @return SMI entry
+**/
+SMI_ENTRY  *
+SmmCoreFindHardwareSmiEntry (
+  IN EFI_GUID  *HandlerType,
+  IN BOOLEAN   Create
+  )
+{
+  LIST_ENTRY  *Link;
+  SMI_ENTRY   *Item;
+  SMI_ENTRY   *SmiEntry;
+
+  //
+  // Search the SMI entry list for the matching GUID
+  //
+  SmiEntry = NULL;
+  for (Link = mHardwareSmiEntryList.ForwardLink;
+       Link != &mHardwareSmiEntryList;
+       Link = Link->ForwardLink) {
+
+    Item = CR (Link, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
+    if (CompareGuid (&Item->HandlerType, HandlerType)) {
+      //
+      // This is the SMI entry
+      //
+      SmiEntry = Item;
+      break;
+    }
+  }
+
+  //
+  // If the protocol entry was not found and Create is TRUE, then
+  // allocate a new entry
+  //
+  if ((SmiEntry == NULL) && Create) {
+    SmiEntry = AllocatePool (sizeof(SMI_ENTRY));
+    if (SmiEntry != NULL) {
+      //
+      // Initialize new SMI entry structure
+      //
+      SmiEntry->Signature = SMI_ENTRY_SIGNATURE;
+      CopyGuid ((VOID *)&SmiEntry->HandlerType, HandlerType);
+      InitializeListHead (&SmiEntry->SmiHandlers);
+
+      //
+      // Add it to SMI entry list
+      //
+      InsertTailList (&mHardwareSmiEntryList, &SmiEntry->AllEntries);
+    }
+  }
+  return SmiEntry;
+}
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  a new SMI handler is registered, to SmmCore.
+
+  @param This            The protocol instance
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+  @param CallerAddress   The address of the module who registers the SMI handler.
+  @param Context         The context of the SMI handler.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+  @param ContextSize     The size of the context in bytes.
+                         For the SmmChildDispatch protocol, the Context
+                         must match the one defined for SmmChildDispatch protocol.
+
+  @retval EFI_SUCCESS           The information is recorded.
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileRegisterHandler (
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
+  IN PHYSICAL_ADDRESS               CallerAddress,
+  IN VOID                           *Context, OPTIONAL
+  IN UINTN                          ContextSize OPTIONAL
+  )
+{
+  SMI_HANDLER  *SmiHandler;
+  SMI_ENTRY    *SmiEntry;
+  LIST_ENTRY   *List;
+
+  SmiHandler = AllocateZeroPool (sizeof (SMI_HANDLER));
+  if (SmiHandler == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
+  SmiHandler->Handler = Handler;
+  SmiHandler->CallerAddr = (UINTN)CallerAddress;
+  if (ContextSize != 0 && Context != NULL) {
+    if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
+      EFI_SMM_USB_REGISTER_CONTEXT              *UsbContext;
+      UINTN                                     DevicePathSize;
+      SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT  *SmiHandlerUsbContext;
+
+      ASSERT (ContextSize == sizeof(EFI_SMM_USB_REGISTER_CONTEXT));
+
+      UsbContext = (EFI_SMM_USB_REGISTER_CONTEXT *)Context;
+      DevicePathSize = GetDevicePathSize (UsbContext->Device);
+      SmiHandlerUsbContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT) + DevicePathSize);
+      if (SmiHandlerUsbContext != NULL) {
+        SmiHandlerUsbContext->Type = UsbContext->Type;
+        SmiHandlerUsbContext->DevicePathSize = (UINT32)DevicePathSize;
+        CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathSize);
+        SmiHandler->Context = SmiHandlerUsbContext;
+      }
+    } else {
+      SmiHandler->Context = AllocateCopyPool (ContextSize, Context);
+    }
+  }
+  if (SmiHandler->Context != NULL) {
+    SmiHandler->ContextSize = ContextSize;
+  }
+
+  SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, TRUE);
+  if (SmiEntry == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  List = &SmiEntry->SmiHandlers;
+
+  SmiHandler->SmiEntry = SmiEntry;
+  InsertTailList (List, &SmiHandler->Link);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  This function is called by SmmChildDispatcher module to report
+  an existing SMI handler is unregistered, to SmmCore.
+
+  @param This            The protocol instance
+  @param HandlerGuid     The GUID to identify the type of the handler.
+                         For the SmmChildDispatch protocol, the HandlerGuid
+                         must be the GUID of SmmChildDispatch protocol.
+  @param Handler         The SMI handler.
+
+  @retval EFI_SUCCESS           The original record is removed.
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileUnregisterHandler (
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,
+  IN EFI_GUID                       *HandlerGuid,
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
+  )
+{
+  LIST_ENTRY   *Link;
+  LIST_ENTRY   *Head;
+  SMI_HANDLER  *SmiHandler;
+  SMI_ENTRY    *SmiEntry;
+  SMI_HANDLER  *TargetSmiHandler;
+
+  SmiEntry = SmmCoreFindHardwareSmiEntry (HandlerGuid, FALSE);
+  if (SmiEntry == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  TargetSmiHandler = NULL;
+  Head = &SmiEntry->SmiHandlers;
+  for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
+    SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
+    if (SmiHandler->Handler == Handler) {
+      TargetSmiHandler = SmiHandler;
+      break;
+    }
+  }
+  if (TargetSmiHandler == NULL) {
+    return EFI_NOT_FOUND;
+  }
+  SmiHandler = TargetSmiHandler;
+
+  RemoveEntryList (&SmiHandler->Link);
+  FreePool (SmiHandler);
+
+  if (IsListEmpty (&SmiEntry->SmiHandlers)) {
+    RemoveEntryList (&SmiEntry->AllEntries);
+    FreePool (SmiEntry);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Initialize SmiHandler profile feature.
+**/
+VOID
+SmmCoreInitializeSmiHandlerProfile (
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  VOID        *Registration;
+  EFI_HANDLE  Handle;
+
+  if ((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
+    InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);
+
+    Status = gSmst->SmmRegisterProtocolNotify (
+                      &gEfiSmmReadyToLockProtocolGuid,
+                      SmmReadyToLockInSmiHandlerProfile,
+                      &Registration
+                      );
+    ASSERT_EFI_ERROR (Status);
+
+    Handle = NULL;
+    Status = gSmst->SmmInstallProtocolInterface (
+                      &Handle,
+                      &gSmiHandlerProfileGuid,
+                      EFI_NATIVE_INTERFACE,
+                      &mSmiHandlerProfile
+                      );
+    ASSERT_EFI_ERROR (Status);
+  }
+}
+
-- 
2.7.4.windows.1



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

* [PATCH 08/12] MdeModulePkg/App: Add SmiHandlerProfile dump app.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (6 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 07/12] MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 16:30 ` [PATCH 09/12] MdeModulePkg/dsc: add SmiHandlerProfile to dsc Jiewen Yao
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Star Zeng, Michael D Kinney, Laszlo Ersek

This app uses SMM communication to get SMI handler profile
from SMM core.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c        | 685 ++++++++++++++++++++
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf      |  65 ++
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni      |  22 +
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni |  19 +
 4 files changed, 791 insertions(+)

diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
new file mode 100644
index 0000000..00cab0c
--- /dev/null
+++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
@@ -0,0 +1,685 @@
+/** @file
+  Shell application to dump SMI handler profile information.
+
+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiDxe.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/DxeServicesLib.h>
+#include <Protocol/SmmCommunication.h>
+#include <Guid/PiSmmCommunicationRegionTable.h>
+
+#include <Guid/SmiHandlerProfile.h>
+
+#define PROFILE_NAME_STRING_LENGTH  64
+CHAR8 mNameString[PROFILE_NAME_STRING_LENGTH + 1];
+
+VOID   *mSmiHandlerProfileDatabase;
+UINTN  mSmiHandlerProfileDatabaseSize;
+
+/**
+  This function dump raw data.
+
+  @param  Data  raw data
+  @param  Size  raw data size
+**/
+VOID
+InternalDumpData (
+  IN UINT8  *Data,
+  IN UINTN  Size
+  )
+{
+  UINTN  Index;
+  for (Index = 0; Index < Size; Index++) {
+    Print (L"%02x", (UINTN)Data[Index]);
+    if ((Index + 1) != Size) {
+      Print (L" ");
+    }
+  }
+}
+
+/**
+  Get SMI handler profile database.
+**/
+VOID
+GetSmiHandlerProfileDatabase(
+  VOID
+  )
+{
+  EFI_STATUS                                          Status;
+  UINTN                                               CommSize;
+  UINT8                                               *CommBuffer;
+  EFI_SMM_COMMUNICATE_HEADER                          *CommHeader;
+  SMI_HANDLER_PROFILE_PARAMETER_GET_INFO              *CommGetInfo;
+  SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET    *CommGetData;
+  EFI_SMM_COMMUNICATION_PROTOCOL                      *SmmCommunication;
+  UINTN                                               MinimalSizeNeeded;
+  EDKII_PI_SMM_COMMUNICATION_REGION_TABLE             *PiSmmCommunicationRegionTable;
+  UINT32                                              Index;
+  EFI_MEMORY_DESCRIPTOR                               *Entry;
+  VOID                                                *Buffer;
+  UINTN                                               Size;
+  UINTN                                               Offset;
+
+  Status = gBS->LocateProtocol(&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **)&SmmCommunication);
+  if (EFI_ERROR(Status)) {
+    Print(L"SmiHandlerProfile: Locate SmmCommunication protocol - %r\n", Status);
+    return ;
+  }
+
+  MinimalSizeNeeded = EFI_PAGE_SIZE;
+
+  Status = EfiGetSystemConfigurationTable(
+             &gEdkiiPiSmmCommunicationRegionTableGuid,
+             (VOID **)&PiSmmCommunicationRegionTable
+             );
+  if (EFI_ERROR(Status)) {
+    Print(L"SmiHandlerProfile: Get PiSmmCommunicationRegionTable - %r\n", Status);
+    return ;
+  }
+  ASSERT(PiSmmCommunicationRegionTable != NULL);
+  Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
+  Size = 0;
+  for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
+    if (Entry->Type == EfiConventionalMemory) {
+      Size = EFI_PAGES_TO_SIZE((UINTN)Entry->NumberOfPages);
+      if (Size >= MinimalSizeNeeded) {
+        break;
+      }
+    }
+    Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);
+  }
+  ASSERT(Index < PiSmmCommunicationRegionTable->NumberOfEntries);
+  CommBuffer = (UINT8 *)(UINTN)Entry->PhysicalStart;
+
+  //
+  // Get Size
+  //
+  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
+  CopyMem(&CommHeader->HeaderGuid, &gSmiHandlerProfileGuid, sizeof(gSmiHandlerProfileGuid));
+  CommHeader->MessageLength = sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_INFO);
+
+  CommGetInfo = (SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *)&CommBuffer[OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data)];
+  CommGetInfo->Header.Command = SMI_HANDLER_PROFILE_COMMAND_GET_INFO;
+  CommGetInfo->Header.DataLength = sizeof(*CommGetInfo);
+  CommGetInfo->Header.ReturnStatus = (UINT64)-1;
+  CommGetInfo->DataSize = 0;
+
+  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength;
+  Status = SmmCommunication->Communicate(SmmCommunication, CommBuffer, &CommSize);
+  if (EFI_ERROR(Status)) {
+    Print(L"SmiHandlerProfile: SmmCommunication - %r\n", Status);
+    return ;
+  }
+
+  if (CommGetInfo->Header.ReturnStatus != 0) {
+    Print(L"SmiHandlerProfile: GetInfo - 0x%0x\n", CommGetInfo->Header.ReturnStatus);
+    return ;
+  }
+
+  mSmiHandlerProfileDatabaseSize = (UINTN)CommGetInfo->DataSize;
+
+  //
+  // Get Data
+  //
+  mSmiHandlerProfileDatabase = AllocateZeroPool(mSmiHandlerProfileDatabaseSize);
+  if (mSmiHandlerProfileDatabase == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    Print(L"SmiHandlerProfile: AllocateZeroPool (0x%x) for dump buffer - %r\n", mSmiHandlerProfileDatabaseSize, Status);
+    return ;
+  }
+
+  CommHeader = (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0];
+  CopyMem(&CommHeader->HeaderGuid, &gSmiHandlerProfileGuid, sizeof(gSmiHandlerProfileGuid));
+  CommHeader->MessageLength = sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET);
+
+  CommGetData = (SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *)&CommBuffer[OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data)];
+  CommGetData->Header.Command = SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_OFFSET;
+  CommGetData->Header.DataLength = sizeof(*CommGetData);
+  CommGetData->Header.ReturnStatus = (UINT64)-1;
+
+  CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength;
+  Buffer = (UINT8 *)CommHeader + CommSize;
+  Size -= CommSize;
+
+  CommGetData->DataBuffer = (PHYSICAL_ADDRESS)(UINTN)Buffer;
+  CommGetData->DataOffset = 0;
+  while (CommGetData->DataOffset < mSmiHandlerProfileDatabaseSize) {
+    Offset = (UINTN)CommGetData->DataOffset;
+    if (Size <= (mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset)) {
+      CommGetData->DataSize = (UINT64)Size;
+    } else {
+      CommGetData->DataSize = (UINT64)(mSmiHandlerProfileDatabaseSize - CommGetData->DataOffset);
+    }
+    Status = SmmCommunication->Communicate(SmmCommunication, CommBuffer, &CommSize);
+    ASSERT_EFI_ERROR(Status);
+
+    if (CommGetData->Header.ReturnStatus != 0) {
+      FreePool(mSmiHandlerProfileDatabase);
+      mSmiHandlerProfileDatabase = NULL;
+      Print(L"SmiHandlerProfile: GetData - 0x%x\n", CommGetData->Header.ReturnStatus);
+      return ;
+    }
+    CopyMem((UINT8 *)mSmiHandlerProfileDatabase + Offset, (VOID *)(UINTN)CommGetData->DataBuffer, (UINTN)CommGetData->DataSize);
+  }
+
+  DEBUG ((DEBUG_INFO, "SmiHandlerProfileSize - 0x%x\n", mSmiHandlerProfileDatabaseSize));
+
+  return ;
+}
+
+/**
+  Get the file name portion of the Pdb File Name.
+
+  The portion of the Pdb File Name between the last backslash and
+  either a following period or the end of the string is copied into
+  AsciiBuffer.  The name is truncated, if necessary, to ensure that
+  AsciiBuffer is not overrun.
+
+  @param[in]  PdbFileName     Pdb file name.
+  @param[out] AsciiBuffer     The resultant Ascii File Name.
+
+**/
+VOID
+GetShortPdbFileName (
+  IN  CHAR8     *PdbFileName,
+  OUT CHAR8     *AsciiBuffer
+  )
+{
+  UINTN IndexPdb;     // Current work location within a Pdb string.
+  UINTN IndexBuffer;  // Current work location within a Buffer string.
+  UINTN StartIndex;
+  UINTN EndIndex;
+
+  ZeroMem (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1);
+
+  if (PdbFileName == NULL) {
+    AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1);
+  } else {
+    StartIndex = 0;
+    for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++);
+    for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) {
+      if ((PdbFileName[IndexPdb] == '\\') || (PdbFileName[IndexPdb] == '/')) {
+        StartIndex = IndexPdb + 1;
+      }
+
+      if (PdbFileName[IndexPdb] == '.') {
+        EndIndex = IndexPdb;
+      }
+    }
+
+    IndexBuffer = 0;
+    for (IndexPdb = StartIndex; IndexPdb < EndIndex; IndexPdb++) {
+      AsciiBuffer[IndexBuffer] = PdbFileName[IndexPdb];
+      IndexBuffer++;
+      if (IndexBuffer >= PROFILE_NAME_STRING_LENGTH) {
+        AsciiBuffer[PROFILE_NAME_STRING_LENGTH] = 0;
+        break;
+      }
+    }
+  }
+}
+
+/**
+  Get a human readable name for an image.
+  The following methods will be tried orderly:
+    1. Image PDB
+    2. FFS UI section
+    3. Image GUID
+
+  @param[in] DriverInfo Pointer to memory profile driver info.
+
+  @return The resulting Ascii name string is stored in the mNameString global array.
+
+**/
+CHAR8 *
+GetDriverNameString (
+  IN SMM_CORE_IMAGE_DATABASE_STRUCTURE  *ImageStruct
+  )
+{
+  EFI_STATUS                  Status;
+  CHAR16                      *NameString;
+  UINTN                       StringSize;
+
+  if (ImageStruct == NULL) {
+    return "???";
+  }
+
+  //
+  // Method 1: Get the name string from image PDB
+  //
+  if (ImageStruct->Header.Length > sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTURE)) {
+    GetShortPdbFileName ((CHAR8 *) (ImageStruct + 1), mNameString);
+    return mNameString;
+  }
+
+  if (!IsZeroGuid (&ImageStruct->FileGuid)) {
+    //
+    // Try to get the image's FFS UI section by image GUID
+    //
+    NameString = NULL;
+    StringSize = 0;
+    Status = GetSectionFromAnyFv (
+              &ImageStruct->FileGuid,
+              EFI_SECTION_USER_INTERFACE,
+              0,
+              (VOID **) &NameString,
+              &StringSize
+              );
+    if (!EFI_ERROR (Status)) {
+      //
+      // Method 2: Get the name string from FFS UI section
+      //
+      if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) {
+        NameString[PROFILE_NAME_STRING_LENGTH] = 0;
+      }
+      UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString));
+      FreePool (NameString);
+      return mNameString;
+    }
+  }
+
+  //
+  // Method 3: Get the name string from image GUID
+  //
+  AsciiSPrint (mNameString, sizeof (mNameString), "%g", &ImageStruct->FileGuid);
+  return mNameString;
+}
+
+/**
+  Get image structure from reference index.
+
+  @param ImageRef   the image reference index
+
+  @return image structure
+**/
+SMM_CORE_IMAGE_DATABASE_STRUCTURE *
+GetImageFromRef (
+  IN UINTN ImageRef
+  )
+{
+  SMM_CORE_IMAGE_DATABASE_STRUCTURE  *ImageStruct;
+
+  ImageStruct = (VOID *)mSmiHandlerProfileDatabase;
+  while ((UINTN)ImageStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {
+    if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {
+      if (ImageStruct->ImageRef == ImageRef) {
+        return ImageStruct;
+      }
+    }
+    ImageStruct = (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Length);
+  }
+
+  return NULL;
+}
+
+/**
+  Dump SMM loaded image information.
+**/
+VOID
+DumpSmmLoadedImage(
+  VOID
+  )
+{
+  SMM_CORE_IMAGE_DATABASE_STRUCTURE  *ImageStruct;
+  CHAR8                              *PdbString;
+  CHAR8                              *NameString;
+
+  ImageStruct = (VOID *)mSmiHandlerProfileDatabase;
+  while ((UINTN)ImageStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {
+    if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {
+      NameString = GetDriverNameString (ImageStruct);
+      Print(L"  <Image Name=\"%a\"", NameString);
+      Print(L" Base=\"0x%x\" Size=\"0x%x\"", ImageStruct->ImageBase, ImageStruct->ImageSize);
+      if (ImageStruct->EntryPoint != 0) {
+        Print(L" EntryPoint=\"0x%x\"", ImageStruct->EntryPoint);
+      }
+      Print(L" FvFile=\"%g\"", &ImageStruct->FileGuid);
+      Print(L" RefId=\"0x%x\"", ImageStruct->ImageRef);
+      Print(L">\n");
+      PdbString = (CHAR8 *)((UINTN)ImageStruct + ImageStruct->PdbStringOffset);
+      Print(L"    <Pdb>%a</Pdb>\n", PdbString);
+      Print(L"  </Image>\n");
+    }
+
+    ImageStruct = (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Length);
+  }
+
+  return;
+}
+
+CHAR8 *mSxTypeString[] = {
+  "SxS0",
+  "SxS1",
+  "SxS2",
+  "SxS3",
+  "SxS4",
+  "SxS5",
+};
+
+/**
+  Convert SxType to a string.
+
+  @param Type SxType
+
+  @return SxType string
+**/
+CHAR8 *
+SxTypeToString (
+  IN EFI_SLEEP_TYPE  Type
+  )
+{
+  if (Type >= 0 && Type <= ARRAY_SIZE(mSxTypeString)) {
+    return mSxTypeString[Type];
+  } else {
+    AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Type);
+    return mNameString;
+  }
+}
+
+CHAR8 *mSxPhaseString[] = {
+  "SxEntry",
+  "SxExit",
+};
+
+/**
+  Convert SxPhase to a string.
+
+  @param Phase SxPhase
+
+  @return SxPhase string
+**/
+CHAR8 *
+SxPhaseToString (
+  IN EFI_SLEEP_PHASE Phase
+  )
+{
+  if (Phase >= 0 && Phase <= ARRAY_SIZE(mSxPhaseString)) {
+    return mSxPhaseString[Phase];
+  } else {
+    AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Phase);
+    return mNameString;
+  }
+}
+
+CHAR8 *mPowerButtonPhaseString[] = {
+  "PowerButtonEntry",
+  "PowerButtonExit",
+};
+
+/**
+  Convert PowerButtonPhase to a string.
+
+  @param Phase PowerButtonPhase
+
+  @return PowerButtonPhase string
+**/
+CHAR8 *
+PowerButtonPhaseToString (
+  IN EFI_POWER_BUTTON_PHASE  Phase
+  )
+{
+  if (Phase >= 0 && Phase <= ARRAY_SIZE(mPowerButtonPhaseString)) {
+    return mPowerButtonPhaseString[Phase];
+  } else {
+    AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Phase);
+    return mNameString;
+  }
+}
+
+CHAR8 *mStandbyButtonPhaseString[] = {
+  "StandbyButtonEntry",
+  "StandbyButtonExit",
+};
+
+/**
+  Convert StandbyButtonPhase to a string.
+
+  @param Phase StandbyButtonPhase
+
+  @return StandbyButtonPhase string
+**/
+CHAR8 *
+StandbyButtonPhaseToString (
+  IN EFI_STANDBY_BUTTON_PHASE  Phase
+  )
+{
+  if (Phase >= 0 && Phase <= ARRAY_SIZE(mStandbyButtonPhaseString)) {
+    return mStandbyButtonPhaseString[Phase];
+  } else {
+    AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Phase);
+    return mNameString;
+  }
+}
+
+CHAR8 *mIoTrapTypeString[] = {
+  "WriteTrap",
+  "ReadTrap",
+  "ReadWriteTrap",
+};
+
+/**
+  Convert IoTrapType to a string.
+
+  @param Type IoTrapType
+
+  @return IoTrapType string
+**/
+CHAR8 *
+IoTrapTypeToString (
+  IN EFI_SMM_IO_TRAP_DISPATCH_TYPE  Type
+  )
+{
+  if (Type >= 0 && Type <= ARRAY_SIZE(mIoTrapTypeString)) {
+    return mIoTrapTypeString[Type];
+  } else {
+    AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Type);
+    return mNameString;
+  }
+}
+
+CHAR8 *mUsbTypeString[] = {
+  "UsbLegacy",
+  "UsbWake",
+};
+
+/**
+  Convert UsbType to a string.
+
+  @param Type UsbType
+
+  @return UsbType string
+**/
+CHAR8 *
+UsbTypeToString (
+  IN EFI_USB_SMI_TYPE          Type
+  )
+{
+  if (Type >= 0 && Type <= ARRAY_SIZE(mUsbTypeString)) {
+    return mUsbTypeString[Type];
+  } else {
+    AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Type);
+    return mNameString;
+  }
+}
+
+/**
+  Dump SMI child context.
+
+  @param HandlerType  the handler type
+  @param Context      the handler context
+  @param ContextSize  the handler context size
+**/
+VOID
+DumpSmiChildContext (
+  IN EFI_GUID   *HandlerType,
+  IN VOID       *Context,
+  IN UINTN      ContextSize
+  )
+{
+  if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
+    Print(L" SwSmi=\"0x%x\"", ((EFI_SMM_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue);
+  } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {
+    Print(L" SxType=\"%a\"", SxTypeToString(((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type));
+    Print(L" SxPhase=\"%a\"", SxPhaseToString(((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase));
+  } else if (CompareGuid (HandlerType, &gEfiSmmPowerButtonDispatch2ProtocolGuid)) {
+    Print(L" PowerButtonPhase=\"%a\"", PowerButtonPhaseToString(((EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT *)Context)->Phase));
+  } else if (CompareGuid (HandlerType, &gEfiSmmStandbyButtonDispatch2ProtocolGuid)) {
+    Print(L" StandbyButtonPhase=\"%a\"", StandbyButtonPhaseToString(((EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT *)Context)->Phase));
+  } else if (CompareGuid (HandlerType, &gEfiSmmPeriodicTimerDispatch2ProtocolGuid)) {
+    Print(L" PeriodicTimerPeriod=\"%ld\"", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->Period);
+    Print(L" PeriodicTimerSmiTickInterval=\"%ld\"", ((EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT *)Context)->SmiTickInterval);
+  } else if (CompareGuid (HandlerType, &gEfiSmmGpiDispatch2ProtocolGuid)) {
+    Print(L" GpiNum=\"0x%lx\"", ((EFI_SMM_GPI_REGISTER_CONTEXT *)Context)->GpiNum);
+  } else if (CompareGuid (HandlerType, &gEfiSmmIoTrapDispatch2ProtocolGuid)) {
+    Print(L" IoTrapAddress=\"0x%x\"", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Address);
+    Print(L" IoTrapLength=\"0x%x\"", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Length);
+    Print(L" IoTrapType=\"%a\"", IoTrapTypeToString(((EFI_SMM_IO_TRAP_REGISTER_CONTEXT *)Context)->Type));
+  } else if (CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) {
+    Print(L" UsbType=\"0x%x\"", UsbTypeToString(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context)->Type));
+    Print(L" UsbDevicePath=\"%s\"", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL *)(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context) + 1), TRUE, TRUE));
+  } else {
+    Print(L" Context=\"");
+    InternalDumpData (Context, ContextSize);
+    Print(L"\"");
+  }
+}
+
+/**
+  Dump SMI handler in HandlerCategory.
+
+  @param HandlerCategory  SMI handler category
+**/
+VOID
+DumpSmiHandler(
+  IN UINT32 HandlerCategory
+  )
+{
+  SMM_CORE_SMI_DATABASE_STRUCTURE    *SmiStruct;
+  SMM_CORE_SMI_HANDLER_STRUCTURE     *SmiHandlerStruct;
+  UINTN                              Index;
+  SMM_CORE_IMAGE_DATABASE_STRUCTURE  *ImageStruct;
+  CHAR8                              *NameString;
+
+  SmiStruct = (VOID *)mSmiHandlerProfileDatabase;
+  while ((UINTN)SmiStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandlerProfileDatabaseSize) {
+    if ((SmiStruct->Header.Signature == SMM_CORE_SMI_DATABASE_SIGNATURE) && (SmiStruct->HandlerCategory == HandlerCategory)) {
+      SmiHandlerStruct = (VOID *)(SmiStruct + 1);
+      Print(L"  <SmiEntry");
+      if (!IsZeroGuid (&SmiStruct->HandlerType)) {
+        Print(L" HandlerType=\"%g\"", &SmiStruct->HandlerType);
+      }
+      Print(L">\n");
+      for (Index = 0; Index < SmiStruct->HandlerCount; Index++) {
+        Print(L"    <SmiHandler");
+        if (SmiHandlerStruct->ContextBufferSize != 0) {
+          DumpSmiChildContext (&SmiStruct->HandlerType, (UINT8 *)SmiHandlerStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandlerStruct->ContextBufferSize);
+        }
+        Print(L">\n");
+        ImageStruct = GetImageFromRef((UINTN)SmiHandlerStruct->ImageRef);
+        NameString = GetDriverNameString (ImageStruct);
+        Print(L"      <Module RefId=\"0x%x\" Name=\"%a\">\n", SmiHandlerStruct->ImageRef, NameString);
+        if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) {
+          Print(L"      <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset);
+        }
+        Print(L"      </Module>\n");
+        Print(L"      <Handler Address=\"0x%x\">\n", SmiHandlerStruct->Handler);
+        if (ImageStruct != NULL) {
+          Print(L"         <RVA>0x%x</RVA>\n", SmiHandlerStruct->Handler - ImageStruct->ImageBase);
+        }
+        Print(L"      </Handler>\n", SmiHandlerStruct->Handler);
+        Print(L"      <Caller Address=\"0x%x\">\n", SmiHandlerStruct->CallerAddr);
+        if (ImageStruct != NULL) {
+          Print(L"         <RVA>0x%x</RVA>\n", SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase);
+        }
+        Print(L"      </Caller>\n", SmiHandlerStruct->Handler);
+        SmiHandlerStruct = (VOID *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
+        Print(L"    </SmiHandler>\n");
+      }
+      Print(L"  </SmiEntry>\n");
+    }
+    SmiStruct = (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length);
+  }
+
+  return;
+}
+
+/**
+  The Entry Point for SMI handler profile info application.
+
+  @param  ImageHandle    The firmware allocated handle for the EFI image.
+  @param  SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS    The entry point is executed successfully.
+  @retval Other          Some error occurred when executing this entry point.
+**/
+EFI_STATUS
+EFIAPI
+SmiHandlerProfileInfoEntrypoint (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_SYSTEM_TABLE     *SystemTable
+  )
+{
+  GetSmiHandlerProfileDatabase();
+
+  if (mSmiHandlerProfileDatabase == NULL) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Dump all image
+  //
+  Print(L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
+  Print(L"<SmiHandlerProfile>\n");
+  Print(L"<ImageDatabase>\n");
+  Print(L"  <!-- SMM image loaded -->\n");
+  DumpSmmLoadedImage();
+  Print(L"</ImageDatabase>\n\n");
+
+  //
+  // Dump SMI Handler
+  //
+  Print(L"<SmiHandlerDatabase>\n");
+  Print(L"  <!-- SMI Handler registered -->\n\n");
+  Print(L"  <SmiHandlerCategory Name=\"RootSmi\">\n");
+  Print(L"  <!-- The root SMI Handler registered by SmmCore -->\n");
+  DumpSmiHandler(SmmCoreSmiHandlerCategoryRootHandler);
+  Print(L"  </SmiHandlerCategory>\n\n");
+
+  Print(L"  <SmiHandlerCategory Name=\"GuidSmi\">\n");
+  Print(L"  <!-- The GUID SMI Handler registered by SmmCore -->\n");
+  DumpSmiHandler(SmmCoreSmiHandlerCategoryGuidHandler);
+  Print(L"  </SmiHandlerCategory>\n\n");
+
+  Print(L"  <SmiHandlerCategory Name=\"HardwareSmi\">\n");
+  Print(L"  <!-- The hardware SMI Handler registered by SmmChildDispatcher -->\n");
+  DumpSmiHandler(SmmCoreSmiHandlerCategoryHardwareHandler);
+  Print(L"  </SmiHandlerCategory>\n\n");
+
+  Print(L"</SmiHandlerDatabase>\n");
+  Print(L"</SmiHandlerProfile>\n");
+
+  if (mSmiHandlerProfileDatabase != NULL) {
+    FreePool(mSmiHandlerProfileDatabase);
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf
new file mode 100644
index 0000000..73cc052
--- /dev/null
+++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf
@@ -0,0 +1,65 @@
+## @file
+#  Shell application to dump SMI handler profile information.
+#
+# Note that if the feature is not enabled by setting PcdSmiHandlerProfilePropertyMask,
+# the application will not display SMI handler profile information.
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials are licensed and made available under
+# the terms and conditions of the BSD License that accompanies this distribution.
+# The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = SmiHandlerProfileInfo
+  MODULE_UNI_FILE                = SmiHandlerProfileInfo.uni
+  FILE_GUID                      = 611EA796-8DF8-4BB6-91FE-6540ED70DC66
+  MODULE_TYPE                    = UEFI_APPLICATION
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = SmiHandlerProfileInfoEntrypoint
+
+[Sources]
+  SmiHandlerProfileInfo.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  UefiApplicationEntryPoint
+  BaseLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  DebugLib
+  UefiBootServicesTableLib
+  UefiRuntimeServicesTableLib
+  UefiLib
+  PrintLib
+  DevicePathLib
+  PeCoffGetEntryPointLib
+  DxeServicesLib
+
+[Protocols]
+  gEfiSmmCommunicationProtocolGuid             ## CONSUMES
+  gEfiSmmSwDispatch2ProtocolGuid               ## SOMETIMES_CONSUMES
+  gEfiSmmSxDispatch2ProtocolGuid               ## SOMETIMES_CONSUMES
+  gEfiSmmPowerButtonDispatch2ProtocolGuid      ## SOMETIMES_CONSUMES
+  gEfiSmmStandbyButtonDispatch2ProtocolGuid    ## SOMETIMES_CONSUMES
+  gEfiSmmPeriodicTimerDispatch2ProtocolGuid    ## SOMETIMES_CONSUMES
+  gEfiSmmGpiDispatch2ProtocolGuid              ## SOMETIMES_CONSUMES
+  gEfiSmmIoTrapDispatch2ProtocolGuid           ## SOMETIMES_CONSUMES
+  gEfiSmmUsbDispatch2ProtocolGuid              ## SOMETIMES_CONSUMES
+
+[Guids]
+  gEdkiiPiSmmCommunicationRegionTableGuid  ## CONSUMES  ## SystemTable
+  gSmiHandlerProfileGuid                   ## SOMETIMES_CONSUMES   ## GUID # SmiHandlerRegister
+
+[UserExtensions.TianoCore."ExtraFiles"]
+  SmiHandlerProfileInfoExtra.uni
+
diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni
new file mode 100644
index 0000000..d73a1a0
--- /dev/null
+++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni
@@ -0,0 +1,22 @@
+// /** @file
+// Shell application to dump SMI handler profile information.
+//
+// Note that if the feature is not enabled by setting PcdSmiHandlerProfilePropertyMask,
+// the application will not display SMI handler profile information.
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT             #language en-US "Shell application to dump SMI handler profile information."
+
+#string STR_MODULE_DESCRIPTION          #language en-US "Note that if the feature is not enabled by setting PcdSmiHandlerProfilePropertyMask, the application will not display SMI handler profile information."
+
diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni
new file mode 100644
index 0000000..b10c71a
--- /dev/null
+++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni
@@ -0,0 +1,19 @@
+// /** @file
+// SmiHandlerProfileInfo Localized Strings and Content
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"SMI Handler Profile Information Application"
+
+
-- 
2.7.4.windows.1



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

* [PATCH 09/12] MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (7 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 08/12] MdeModulePkg/App: Add SmiHandlerProfile dump app Jiewen Yao
@ 2017-02-08 16:30 ` Jiewen Yao
  2017-02-08 17:34 ` [PATCH 00/12] Add SmiHandlerProfile feature Laszlo Ersek
  2017-02-22  6:48 ` Zeng, Star
  10 siblings, 0 replies; 20+ messages in thread
From: Jiewen Yao @ 2017-02-08 16:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Feng Tian, Star Zeng, Michael D Kinney, Laszlo Ersek

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
 MdeModulePkg/MdeModulePkg.dsc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 5996fe5..1bb361a 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -447,6 +447,7 @@
   MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
   
 [Components.IA32, Components.X64]
+  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf
   MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
   MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf {
@@ -470,6 +471,7 @@
   MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
   MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
   MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf
+  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
   MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
-- 
2.7.4.windows.1



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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (8 preceding siblings ...)
  2017-02-08 16:30 ` [PATCH 09/12] MdeModulePkg/dsc: add SmiHandlerProfile to dsc Jiewen Yao
@ 2017-02-08 17:34 ` Laszlo Ersek
       [not found]   ` <BF2CCE9263284D428840004653A28B6E53F5E3BC@SHSMSX103.ccr.corp.intel.com>
  2017-02-22  6:48 ` Zeng, Star
  10 siblings, 1 reply; 20+ messages in thread
From: Laszlo Ersek @ 2017-02-08 17:34 UTC (permalink / raw)
  To: Jiewen Yao, edk2-devel
  Cc: Michael D Kinney, Liming Gao, Feng Tian, Star Zeng,
	Jordan Justen (Intel address)

CC Jordan

On 02/08/17 17:30, Jiewen Yao wrote:
> This series patch add SMI handler profile.
> 
> The purpose of SMI handler profile is to add the capability to
> dump all SMI handlers produced by the firmware in a given boot.
> The SMI handlers here include
> 1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
> 2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
> 3) Hardware SMI handlers registered with SMM_XXX_DISPATCH_PROTOCOL->Register
> by SmmChildDispatcher module.
> 
> The final log is an XML format log, including all SMM image name, all SMI
> handlers name, type, location (source file and line number), and the caller
> who registeres the handler.
> 
> We enabled Quark platform to show how to add support in SmmChildDispatcher.

Thanks for the CC.

This module seems quite large, and OVMF (to my knowledge) doesn't
include any special handlers. (Nothing from category (3), and I couldn't
say if anything from category (2)).

Do you think this module would be useful to enable in OVMF,
conditionally, with -D SMI_HANDLER_PROFILE_ENABLE?

Beyond the question of its utility to OVMF developers and users,
requiring a separate UEFI app to dump the profile, presumably from the
UEFI shell, is not really flexible for OVMF. We can't / don't build
applications into the firmware image (beyond the shell and UiApp), so
users would have to build a virtual disk image with this app, or we'd
have to provide scripts for the same.

For now, I believe we don't wish to enable this in OVMF.

If you CC'd me for regression-testing PiSmmCore, as it is built into
OVMF, with the default PcdSmiHandlerProfilePropertyMask=0 value, then I
respectfully point you to the following article:

https://github.com/tianocore/tianocore.github.io/wiki/Testing-SMM-with-QEMU,-KVM-and-libvirt

Please set up a KVM environment as documented there, and adopt it for
regular SMM testing :) My strong hope is that, by adopting KVM as a
regular test platform, Intel developers won't only catch OVMF
regressions before they post patches, but they should also see their own
productivity increase.

I assume it must be much easier to click "Play" in the Virt-Manager GUI
and to boot to an OS, on top of the new firmware, in seconds, than to
flash firmware to a physical board. It does not replace physical board
testing, but should catch a number of errors more gracefully.

The test cases I wrote up include UEFI variable testing and ACPI S3. The
guest OSes covered are Fedora 25 and Windows 10. Please give it a look.

Thanks!
Laszlo

> 
> NOTE: This SMI handler profile is a *DEBUG* feature only, to help platform
> developer or test engineer to audit the SMI handlers. Please do not include
> it in the final *RELEASE* image.
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Feng Tian <feng.tian@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
> 
> Jiewen Yao (12):
>   MdePkg/Include: Add SmiHandlerProfileLib.h
>   MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
>   MdePkg/dsc: add SmiHandlerProfileLib to dsc.
>   MdeModulePkg/include: Add SmiHandlerProfile header file.
>   MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
>   MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
>   MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
>   MdeModulePkg/App: Add SmiHandlerProfile dump app.
>   MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
>   BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
>   QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
>   QuarkPlatformPkg: enable SmiHandlerProfile.
> 
>  BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
>  MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
>  MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
>  MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
>  MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
>  MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
>  MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
>  MdePkg/MdePkg.dec                                                              |    5 +-
>  MdePkg/MdePkg.dsc                                                              |    3 +-
>  QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
>  QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
>  QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
>  QuarkPlatformPkg/Readme.md                                                     |   29 +-
>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
>  28 files changed, 3159 insertions(+), 56 deletions(-)
>  create mode 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
>  create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
>  create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf
>  create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni
>  create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni
>  create mode 100644 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
>  create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
>  create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
>  create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
>  create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni
>  create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
>  create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>  create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>  create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
> 



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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
       [not found]   ` <BF2CCE9263284D428840004653A28B6E53F5E3BC@SHSMSX103.ccr.corp.intel.com>
@ 2017-02-08 17:57     ` Yao, Jiewen
  2017-02-08 18:28       ` Laszlo Ersek
  2017-02-21  7:06       ` Yao, Jiewen
  0 siblings, 2 replies; 20+ messages in thread
From: Yao, Jiewen @ 2017-02-08 17:57 UTC (permalink / raw)
  To: Yao, Jiewen, edk2-devel@ml01.01.org
  Cc: Kinney, Michael D, Justen, Jordan L, Tian, Feng, Zeng, Star,
	Gao, Liming, Laszlo Ersek (lersek@redhat.com)

Hi Laszlo
Thanks for the comment.

To clarify something:


1)       I did not enable SMI handler profile for OVMF because I notice the OVMF just use very few SMI handlers, and it does not have SmmChildDispatcher. Just like what you mentioned.


2)       I forget to mention: I did regression test for OVMF IA32 and IA32X64 with default SmiHandlerProfile is DISABLED.
I boot to UEFI SHELL only, and I do not enter OS.
I think the risk is very low, because if SMI handler profile is disabled, there is no code logic change.

VOID
SmmCoreInitializeSmiHandlerProfile (
  VOID
  )
{
  EFI_STATUS  Status;
  VOID        *Registration;
  EFI_HANDLE  Handle;

  if ((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
    InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);

    Status = gSmst->SmmRegisterProtocolNotify (
                      &gEfiSmmReadyToLockProtocolGuid,
                      SmmReadyToLockInSmiHandlerProfile,
                      &Registration
                      );
    ASSERT_EFI_ERROR (Status);

    Handle = NULL;
    Status = gSmst->SmmInstallProtocolInterface (
                      &Handle,
                      &gSmiHandlerProfileGuid,
                      EFI_NATIVE_INTERFACE,
                      &mSmiHandlerProfile
                      );
    ASSERT_EFI_ERROR (Status);
  }
}

I do understand your concern, because OVMF has some special feature which might be different with real hardware.

At same time, I have to mention that, it is very hard to setup KVM in Linux. I did try to follow your description before on NX.
I spent one week, but still fail to launch the final image on my side, I have no idea on what is wrong. That was a horrible experience.

I will have a try to follow your new document.
If it can be setup successfully, easily and fortunately, I do want to run it.

Thank you
Yao Jiewen

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
Sent: Wednesday, February 8, 2017 9:34 AM
To: Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>; edk2-devel@ml01.01.org<mailto:edk2-devel@ml01.01.org>
Cc: Kinney, Michael D <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Justen, Jordan L <jordan.l.justen@intel.com<mailto:jordan.l.justen@intel.com>>; Tian, Feng <feng.tian@intel.com<mailto:feng.tian@intel.com>>; Zeng, Star <star.zeng@intel.com<mailto:star.zeng@intel.com>>; Gao, Liming <liming.gao@intel.com<mailto:liming.gao@intel.com>>
Subject: Re: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature

CC Jordan

On 02/08/17 17:30, Jiewen Yao wrote:
> This series patch add SMI handler profile.
>
> The purpose of SMI handler profile is to add the capability to dump
> all SMI handlers produced by the firmware in a given boot.
> The SMI handlers here include
> 1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
> 2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
> 3) Hardware SMI handlers registered with
> SMM_XXX_DISPATCH_PROTOCOL->Register
> by SmmChildDispatcher module.
>
> The final log is an XML format log, including all SMM image name, all
> SMI handlers name, type, location (source file and line number), and
> the caller who registeres the handler.
>
> We enabled Quark platform to show how to add support in SmmChildDispatcher.

Thanks for the CC.

This module seems quite large, and OVMF (to my knowledge) doesn't include any special handlers. (Nothing from category (3), and I couldn't say if anything from category (2)).

Do you think this module would be useful to enable in OVMF, conditionally, with -D SMI_HANDLER_PROFILE_ENABLE?

Beyond the question of its utility to OVMF developers and users, requiring a separate UEFI app to dump the profile, presumably from the UEFI shell, is not really flexible for OVMF. We can't / don't build applications into the firmware image (beyond the shell and UiApp), so users would have to build a virtual disk image with this app, or we'd have to provide scripts for the same.

For now, I believe we don't wish to enable this in OVMF.

If you CC'd me for regression-testing PiSmmCore, as it is built into OVMF, with the default PcdSmiHandlerProfilePropertyMask=0 value, then I respectfully point you to the following article:

https://github.com/tianocore/tianocore.github.io/wiki/Testing-SMM-with-QEMU,-KVM-and-libvirt

Please set up a KVM environment as documented there, and adopt it for regular SMM testing :) My strong hope is that, by adopting KVM as a regular test platform, Intel developers won't only catch OVMF regressions before they post patches, but they should also see their own productivity increase.

I assume it must be much easier to click "Play" in the Virt-Manager GUI and to boot to an OS, on top of the new firmware, in seconds, than to flash firmware to a physical board. It does not replace physical board testing, but should catch a number of errors more gracefully.

The test cases I wrote up include UEFI variable testing and ACPI S3. The guest OSes covered are Fedora 25 and Windows 10. Please give it a look.

Thanks!
Laszlo

>
> NOTE: This SMI handler profile is a *DEBUG* feature only, to help
> platform developer or test engineer to audit the SMI handlers. Please
> do not include it in the final *RELEASE* image.
>
> Cc: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>
> Cc: Liming Gao <liming.gao@intel.com<mailto:liming.gao@intel.com>>
> Cc: Feng Tian <feng.tian@intel.com<mailto:feng.tian@intel.com>>
> Cc: Star Zeng <star.zeng@intel.com<mailto:star.zeng@intel.com>>
> Cc: Laszlo Ersek <lersek@redhat.com<mailto:lersek@redhat.com>>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
>
> Jiewen Yao (12):
>   MdePkg/Include: Add SmiHandlerProfileLib.h
>   MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
>   MdePkg/dsc: add SmiHandlerProfileLib to dsc.
>   MdeModulePkg/include: Add SmiHandlerProfile header file.
>   MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
>   MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
>   MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
>   MdeModulePkg/App: Add SmiHandlerProfile dump app.
>   MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
>   BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
>   QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
>   QuarkPlatformPkg: enable SmiHandlerProfile.
>
>  BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
>  MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
>  MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
>  MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
>  MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
>  MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
>  MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
>  MdePkg/MdePkg.dec                                                              |    5 +-
>  MdePkg/MdePkg.dsc                                                              |    3 +-
>  QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
>  QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
>  QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
>  QuarkPlatformPkg/Readme.md                                                     |   29 +-
>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
>  28 files changed, 3159 insertions(+), 56 deletions(-)  create mode
> 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
>  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
>  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.i
> nf  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.u
> ni  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoEx
> tra.uni  create mode 100644
> MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
>  create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
>  create mode 100644
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
>  create mode 100644
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.i
> nf  create mode 100644
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.u
> ni  create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
>  create mode 100644
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>  create mode 100644
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>  create mode 100644
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
  2017-02-08 17:57     ` Yao, Jiewen
@ 2017-02-08 18:28       ` Laszlo Ersek
  2017-02-08 18:37         ` Yao, Jiewen
  2017-02-21  7:06       ` Yao, Jiewen
  1 sibling, 1 reply; 20+ messages in thread
From: Laszlo Ersek @ 2017-02-08 18:28 UTC (permalink / raw)
  To: Yao, Jiewen, edk2-devel@ml01.01.org
  Cc: Kinney, Michael D, Justen, Jordan L, Tian, Feng, Zeng, Star,
	Gao, Liming

On 02/08/17 18:57, Yao, Jiewen wrote:
> Hi Laszlo
> 
> Thanks for the comment.
> 
>  
> 
> To clarify something:
> 
>  
> 
> 1)       I did not enable SMI handler profile for OVMF because I notice
> the OVMF just use very few SMI handlers, and it does not have
> SmmChildDispatcher. Just like what you mentioned.

Sounds great, thank you!

> 
>  
> 
> 2)       I forget to mention: I did regression test for OVMF IA32 and
> IA32X64 with default SmiHandlerProfile is DISABLED.
> 
> I boot to UEFI SHELL only, and I do not enter OS.
> 
> I think the risk is very low, because if SMI handler profile is
> disabled, there is no code logic change.
> 
>  
> 
> VOID
> 
> SmmCoreInitializeSmiHandlerProfile (
> 
>   VOID
> 
>   )
> 
> {
> 
>   EFI_STATUS  Status;
> 
>   VOID        *Registration;
> 
>   EFI_HANDLE  Handle;
> 
>  
> 
>   if((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
> 
>     InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);
> 
>  
> 
>     Status = gSmst->SmmRegisterProtocolNotify (
> 
>                       &gEfiSmmReadyToLockProtocolGuid,
> 
>                       SmmReadyToLockInSmiHandlerProfile,
> 
>                       &Registration
> 
>                       );
> 
>     ASSERT_EFI_ERROR (Status);
> 
>  
> 
>     Handle = NULL;
> 
>     Status = gSmst->SmmInstallProtocolInterface (
> 
>                       &Handle,
> 
>                       &gSmiHandlerProfileGuid,
> 
>                       EFI_NATIVE_INTERFACE,
> 
>                       &mSmiHandlerProfile
> 
>                       );
> 
>     ASSERT_EFI_ERROR (Status);
> 
>   }
> 
> }

Perfect. Thank you for confirming!

> 
>  
> 
> I do understand your concern, because OVMF has some special feature
> which might be different with real hardware.
> 
>  
> 
> At same time, I have to mention that, it is very hard to setup KVM in
> Linux. I did try to follow your description before on NX.
> 
> I spent one week, but still fail to launch the final image on my side, I
> have no idea on what is wrong. That was a horrible experience.

I'm very sorry to hear that, and I can't deny that using QEMU from the
command line is extremely hard. It's hard even for the people who work
on QEMU / use it on a daily basis.

The fact to keep in mind is that the QEMU command line is actually no
longer a human interface; it is a machine interface. The libvirt system
service sits on top of QEMU/KVM (and a few other hypervisors), and
manages the configuration and lifecycle of virtual machines.

In turn, there are both command line utilities and graphical tools that
connect to the libvirt service, and allow for much-much easier handling
of guests than the raw QEMU command line. So ultimately, it looks like this:

  helpful friendly GUI client  ------ libvirt service ---- QEMU --- KVM
  utility called "virt-manager"

The closer you sit to the right side, as a human / interactive user, the
more bumpy your ride will be.

In my own development environment, I *insist* on sitting at the leftmost
side.

In fact, for Windows desktop users, there's one more layer:

      [ WINDOWS DESKTOP ]
               |
               |
+-------[ LINUX SERVER ]-----------------------------------------------+
|                                                                      |
| helpful friendly GUI client  ----- libvirt service ---- QEMU --- KVM |
| utility called "virt-manager"                                        |
|                                                                      |
+----------------------------------------------------------------------+

In this scenario, you'd be using the "helpful friendly GUI client
utility called 'virt-manager'" that runs on the Linux server, getting
the GUI on your Windows desktop.

Last time around, I provided you with a QEMU command line, which is very
hard to adjust (for whatever reason). This time, I documented a setup so
that we can sit at the left side of the diagram.

> I will have a try to follow your new document.
> 
> If it can be setup successfully, easily and fortunately, I do want to
> run it.

The setup is likely not *quick*, but it should be reasonably
*straightforward*, and the end result is *extremely* convenient to use.

I *really* want it to work out for you. If you hit *any* roadblocks,
please email me, on-list or off-list, as you prefer (or we can discuss
on the #edk2 IRC channel), and I'll make it my first priority to assist you.

I can log in every day around 09:30 in the UTC+01:00 time zone.

Thanks,
Laszlo

> 
>  
> 
> Thank you
> 
> Yao Jiewen
> 
>  
> 
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
> Sent: Wednesday, February 8, 2017 9:34 AM
> To: Yao, Jiewen <jiewen.yao@intel.com
> <mailto:jiewen.yao@intel.com>>; edk2-devel@ml01.01.org
> <mailto:edk2-devel@ml01.01.org>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com
> <mailto:michael.d.kinney@intel.com>>; Justen, Jordan L <jordan.l.justen@intel.com
> <mailto:jordan.l.justen@intel.com>>; Tian, Feng <feng.tian@intel.com
> <mailto:feng.tian@intel.com>>; Zeng, Star <star.zeng@intel.com
> <mailto:star.zeng@intel.com>>; Gao, Liming <liming.gao@intel.com
> <mailto:liming.gao@intel.com>>
> Subject: Re: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature
> 
> CC Jordan
> 
> On 02/08/17 17:30, Jiewen Yao wrote:
>> This series patch add SMI handler profile.
>> 
>> The purpose of SMI handler profile is to add the capability to dump 
>> all SMI handlers produced by the firmware in a given boot.
>> The SMI handlers here include
>> 1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
>> 2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
>> 3) Hardware SMI handlers registered with 
>> SMM_XXX_DISPATCH_PROTOCOL->Register
>> by SmmChildDispatcher module.
>> 
>> The final log is an XML format log, including all SMM image name, all 
>> SMI handlers name, type, location (source file and line number), and 
>> the caller who registeres the handler.
>> 
>> We enabled Quark platform to show how to add support in SmmChildDispatcher.
> 
> Thanks for the CC.
> 
> This module seems quite large, and OVMF (to my knowledge) doesn't include any special handlers. (Nothing from category (3), and I couldn't say if anything from category (2)).
> 
> Do you think this module would be useful to enable in OVMF, conditionally, with -D SMI_HANDLER_PROFILE_ENABLE?
> 
> Beyond the question of its utility to OVMF developers and users, requiring a separate UEFI app to dump the profile, presumably from the UEFI shell, is not really flexible for OVMF. We can't / don't build applications into the firmware image (beyond the shell and UiApp), so users would have to build a virtual disk image with this app, or we'd have to provide scripts for the same.
> 
> For now, I believe we don't wish to enable this in OVMF.
> 
> If you CC'd me for regression-testing PiSmmCore, as it is built into OVMF, with the default PcdSmiHandlerProfilePropertyMask=0 value, then I respectfully point you to the following article:
> 
> https://github.com/tianocore/tianocore.github.io/wiki/Testing-SMM-with-QEMU,-KVM-and-libvirt
> 
> Please set up a KVM environment as documented there, and adopt it for regular SMM testing :) My strong hope is that, by adopting KVM as a regular test platform, Intel developers won't only catch OVMF regressions before they post patches, but they should also see their own productivity increase.
> 
> I assume it must be much easier to click "Play" in the Virt-Manager GUI and to boot to an OS, on top of the new firmware, in seconds, than to flash firmware to a physical board. It does not replace physical board testing, but should catch a number of errors more gracefully.
> 
> The test cases I wrote up include UEFI variable testing and ACPI S3. The guest OSes covered are Fedora 25 and Windows 10. Please give it a look.
> 
> Thanks!
> Laszlo
> 
>> 
>> NOTE: This SMI handler profile is a *DEBUG* feature only, to help 
>> platform developer or test engineer to audit the SMI handlers. Please 
>> do not include it in the final *RELEASE* image.
>> 
>> Cc: Michael D Kinney <michael.d.kinney@intel.com <mailto:michael.d.kinney@intel.com>>
>> Cc: Liming Gao <liming.gao@intel.com <mailto:liming.gao@intel.com>>
>> Cc: Feng Tian <feng.tian@intel.com <mailto:feng.tian@intel.com>>
>> Cc: Star Zeng <star.zeng@intel.com <mailto:star.zeng@intel.com>>
>> Cc: Laszlo Ersek <lersek@redhat.com <mailto:lersek@redhat.com>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Jiewen Yao <jiewen.yao@intel.com <mailto:jiewen.yao@intel.com>>
>> 
>> Jiewen Yao (12):
>>   MdePkg/Include: Add SmiHandlerProfileLib.h
>>   MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
>>   MdePkg/dsc: add SmiHandlerProfileLib to dsc.
>>   MdeModulePkg/include: Add SmiHandlerProfile header file.
>>   MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
>>   MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
>>   MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
>>   MdeModulePkg/App: Add SmiHandlerProfile dump app.
>>   MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
>>   BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
>>   QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
>>   QuarkPlatformPkg: enable SmiHandlerProfile.
>> 
>>  BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
>>  MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
>>  MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
>>  MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
>>  MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
>>  MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
>>  MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
>>  MdePkg/MdePkg.dec                                                              |    5 +-
>>  MdePkg/MdePkg.dsc                                                              |    3 +-
>>  QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
>>  QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
>>  QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
>>  QuarkPlatformPkg/Readme.md                                                     |   29 +-
>>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
>>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
>>  28 files changed, 3159 insertions(+), 56 deletions(-)  create mode 
>> 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
>>  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
>>  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.i
>> nf  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.u
>> ni  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoEx
>> tra.uni  create mode 100644 
>> MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
>>  create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
>>  create mode 100644 
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
>>  create mode 100644 
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.i
>> nf  create mode 100644 
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.u
>> ni  create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
>>  create mode 100644 
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>>  create mode 100644 
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>>  create mode 100644 
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>> 
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> https://lists.01.org/mailman/listinfo/edk2-devel
> 



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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
  2017-02-08 18:28       ` Laszlo Ersek
@ 2017-02-08 18:37         ` Yao, Jiewen
  0 siblings, 0 replies; 20+ messages in thread
From: Yao, Jiewen @ 2017-02-08 18:37 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel@ml01.01.org
  Cc: Kinney, Michael D, Justen, Jordan L, Tian, Feng, Zeng, Star,
	Gao, Liming

Sounds great.
I appreciate your help. :)

Thank you
Yao Jiewen


From: Laszlo Ersek [mailto:lersek@redhat.com]
Sent: Wednesday, February 8, 2017 10:28 AM
To: Yao, Jiewen <jiewen.yao@intel.com>; edk2-devel@ml01.01.org
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; Tian, Feng <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: Re: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature

On 02/08/17 18:57, Yao, Jiewen wrote:
> Hi Laszlo
>
> Thanks for the comment.
>
>
>
> To clarify something:
>
>
>
> 1)       I did not enable SMI handler profile for OVMF because I notice
> the OVMF just use very few SMI handlers, and it does not have
> SmmChildDispatcher. Just like what you mentioned.

Sounds great, thank you!

>
>
>
> 2)       I forget to mention: I did regression test for OVMF IA32 and
> IA32X64 with default SmiHandlerProfile is DISABLED.
>
> I boot to UEFI SHELL only, and I do not enter OS.
>
> I think the risk is very low, because if SMI handler profile is
> disabled, there is no code logic change.
>
>
>
> VOID
>
> SmmCoreInitializeSmiHandlerProfile (
>
>   VOID
>
>   )
>
> {
>
>   EFI_STATUS  Status;
>
>   VOID        *Registration;
>
>   EFI_HANDLE  Handle;
>
>
>
>   if((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
>
>     InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);
>
>
>
>     Status = gSmst->SmmRegisterProtocolNotify (
>
>                       &gEfiSmmReadyToLockProtocolGuid,
>
>                       SmmReadyToLockInSmiHandlerProfile,
>
>                       &Registration
>
>                       );
>
>     ASSERT_EFI_ERROR (Status);
>
>
>
>     Handle = NULL;
>
>     Status = gSmst->SmmInstallProtocolInterface (
>
>                       &Handle,
>
>                       &gSmiHandlerProfileGuid,
>
>                       EFI_NATIVE_INTERFACE,
>
>                       &mSmiHandlerProfile
>
>                       );
>
>     ASSERT_EFI_ERROR (Status);
>
>   }
>
> }

Perfect. Thank you for confirming!

>
>
>
> I do understand your concern, because OVMF has some special feature
> which might be different with real hardware.
>
>
>
> At same time, I have to mention that, it is very hard to setup KVM in
> Linux. I did try to follow your description before on NX.
>
> I spent one week, but still fail to launch the final image on my side, I
> have no idea on what is wrong. That was a horrible experience.

I'm very sorry to hear that, and I can't deny that using QEMU from the
command line is extremely hard. It's hard even for the people who work
on QEMU / use it on a daily basis.

The fact to keep in mind is that the QEMU command line is actually no
longer a human interface; it is a machine interface. The libvirt system
service sits on top of QEMU/KVM (and a few other hypervisors), and
manages the configuration and lifecycle of virtual machines.

In turn, there are both command line utilities and graphical tools that
connect to the libvirt service, and allow for much-much easier handling
of guests than the raw QEMU command line. So ultimately, it looks like this:

  helpful friendly GUI client  ------ libvirt service ---- QEMU --- KVM
  utility called "virt-manager"

The closer you sit to the right side, as a human / interactive user, the
more bumpy your ride will be.

In my own development environment, I *insist* on sitting at the leftmost
side.

In fact, for Windows desktop users, there's one more layer:

      [ WINDOWS DESKTOP ]
               |
               |
+-------[ LINUX SERVER ]-----------------------------------------------+
|                                                                      |
| helpful friendly GUI client  ----- libvirt service ---- QEMU --- KVM |
| utility called "virt-manager"                                        |
|                                                                      |
+----------------------------------------------------------------------+

In this scenario, you'd be using the "helpful friendly GUI client
utility called 'virt-manager'" that runs on the Linux server, getting
the GUI on your Windows desktop.

Last time around, I provided you with a QEMU command line, which is very
hard to adjust (for whatever reason). This time, I documented a setup so
that we can sit at the left side of the diagram.

> I will have a try to follow your new document.
>
> If it can be setup successfully, easily and fortunately, I do want to
> run it.

The setup is likely not *quick*, but it should be reasonably
*straightforward*, and the end result is *extremely* convenient to use.

I *really* want it to work out for you. If you hit *any* roadblocks,
please email me, on-list or off-list, as you prefer (or we can discuss
on the #edk2 IRC channel), and I'll make it my first priority to assist you.

I can log in every day around 09:30 in the UTC+01:00 time zone.

Thanks,
Laszlo

>
>
>
> Thank you
>
> Yao Jiewen
>
>
>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
> Sent: Wednesday, February 8, 2017 9:34 AM
> To: Yao, Jiewen <jiewen.yao@intel.com
<mailto:jiewen.yao@intel.com%0b>> <mailto:jiewen.yao@intel.com>>; edk2-devel@ml01.01.org<mailto:edk2-devel@ml01.01.org>
> <mailto:edk2-devel@ml01.01.org>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com
<mailto:michael.d.kinney@intel.com%0b>> <mailto:michael.d.kinney@intel.com>>; Justen, Jordan L <jordan.l.justen@intel.com
<mailto:jordan.l.justen@intel.com%0b>> <mailto:jordan.l.justen@intel.com>>; Tian, Feng <feng.tian@intel.com
<mailto:feng.tian@intel.com%0b>> <mailto:feng.tian@intel.com>>; Zeng, Star <star.zeng@intel.com
<mailto:star.zeng@intel.com%0b>> <mailto:star.zeng@intel.com>>; Gao, Liming <liming.gao@intel.com
<mailto:liming.gao@intel.com%0b>> <mailto:liming.gao@intel.com>>
> Subject: Re: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature
>
> CC Jordan
>
> On 02/08/17 17:30, Jiewen Yao wrote:
>> This series patch add SMI handler profile.
>>
>> The purpose of SMI handler profile is to add the capability to dump
>> all SMI handlers produced by the firmware in a given boot.
>> The SMI handlers here include
>> 1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
>> 2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
>> 3) Hardware SMI handlers registered with
>> SMM_XXX_DISPATCH_PROTOCOL->Register
>> by SmmChildDispatcher module.
>>
>> The final log is an XML format log, including all SMM image name, all
>> SMI handlers name, type, location (source file and line number), and
>> the caller who registeres the handler.
>>
>> We enabled Quark platform to show how to add support in SmmChildDispatcher.
>
> Thanks for the CC.
>
> This module seems quite large, and OVMF (to my knowledge) doesn't include any special handlers. (Nothing from category (3), and I couldn't say if anything from category (2)).
>
> Do you think this module would be useful to enable in OVMF, conditionally, with -D SMI_HANDLER_PROFILE_ENABLE?
>
> Beyond the question of its utility to OVMF developers and users, requiring a separate UEFI app to dump the profile, presumably from the UEFI shell, is not really flexible for OVMF. We can't / don't build applications into the firmware image (beyond the shell and UiApp), so users would have to build a virtual disk image with this app, or we'd have to provide scripts for the same.
>
> For now, I believe we don't wish to enable this in OVMF.
>
> If you CC'd me for regression-testing PiSmmCore, as it is built into OVMF, with the default PcdSmiHandlerProfilePropertyMask=0 value, then I respectfully point you to the following article:
>
> https://github.com/tianocore/tianocore.github.io/wiki/Testing-SMM-with-QEMU,-KVM-and-libvirt
>
> Please set up a KVM environment as documented there, and adopt it for regular SMM testing :) My strong hope is that, by adopting KVM as a regular test platform, Intel developers won't only catch OVMF regressions before they post patches, but they should also see their own productivity increase.
>
> I assume it must be much easier to click "Play" in the Virt-Manager GUI and to boot to an OS, on top of the new firmware, in seconds, than to flash firmware to a physical board. It does not replace physical board testing, but should catch a number of errors more gracefully.
>
> The test cases I wrote up include UEFI variable testing and ACPI S3. The guest OSes covered are Fedora 25 and Windows 10. Please give it a look.
>
> Thanks!
> Laszlo
>
>>
>> NOTE: This SMI handler profile is a *DEBUG* feature only, to help
>> platform developer or test engineer to audit the SMI handlers. Please
>> do not include it in the final *RELEASE* image.
>>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com <mailto:michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com %3cmailto:michael.d.kinney@intel.com>>>
>> Cc: Liming Gao <liming.gao@intel.com <mailto:liming.gao@intel.com<mailto:liming.gao@intel.com %3cmailto:liming.gao@intel.com>>>
>> Cc: Feng Tian <feng.tian@intel.com <mailto:feng.tian@intel.com<mailto:feng.tian@intel.com %3cmailto:feng.tian@intel.com>>>
>> Cc: Star Zeng <star.zeng@intel.com <mailto:star.zeng@intel.com<mailto:star.zeng@intel.com %3cmailto:star.zeng@intel.com>>>
>> Cc: Laszlo Ersek <lersek@redhat.com <mailto:lersek@redhat.com<mailto:lersek@redhat.com %3cmailto:lersek@redhat.com>>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Jiewen Yao <jiewen.yao@intel.com <mailto:jiewen.yao@intel.com<mailto:jiewen.yao@intel.com %3cmailto:jiewen.yao@intel.com>>>
>>
>> Jiewen Yao (12):
>>   MdePkg/Include: Add SmiHandlerProfileLib.h
>>   MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
>>   MdePkg/dsc: add SmiHandlerProfileLib to dsc.
>>   MdeModulePkg/include: Add SmiHandlerProfile header file.
>>   MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
>>   MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
>>   MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
>>   MdeModulePkg/App: Add SmiHandlerProfile dump app.
>>   MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
>>   BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
>>   QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
>>   QuarkPlatformPkg: enable SmiHandlerProfile.
>>
>>  BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
>>  MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
>>  MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
>>  MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
>>  MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
>>  MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
>>  MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
>>  MdePkg/MdePkg.dec                                                              |    5 +-
>>  MdePkg/MdePkg.dsc                                                              |    3 +-
>>  QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
>>  QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
>>  QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
>>  QuarkPlatformPkg/Readme.md                                                     |   29 +-
>>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
>>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
>>  28 files changed, 3159 insertions(+), 56 deletions(-)  create mode
>> 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
>>  create mode 100644
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
>>  create mode 100644
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.i
>> nf  create mode 100644
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.u
>> ni  create mode 100644
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoEx
>> tra.uni  create mode 100644
>> MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
>>  create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
>>  create mode 100644
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
>>  create mode 100644
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.i
>> nf  create mode 100644
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.u
>> ni  create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
>>  create mode 100644
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>>  create mode 100644
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>>  create mode 100644
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>>
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org> <mailto:edk2-devel@lists.01.org>
> https://lists.01.org/mailman/listinfo/edk2-devel
>


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

* Re: [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h
  2017-02-08 16:30 ` [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h Jiewen Yao
@ 2017-02-10  3:28   ` Gao, Liming
  0 siblings, 0 replies; 20+ messages in thread
From: Gao, Liming @ 2017-02-10  3:28 UTC (permalink / raw)
  To: Yao, Jiewen, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Laszlo Ersek

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: Yao, Jiewen
>Sent: Thursday, February 09, 2017 12:30 AM
>To: edk2-devel@lists.01.org
>Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
><liming.gao@intel.com>; Laszlo Ersek <lersek@redhat.com>
>Subject: [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h
>
>This library should be linked by SmmChildDispatch to
>report the hardware SMI handler maintained by SmmChildDispatch.
>
>Cc: Michael D Kinney <michael.d.kinney@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>Cc: Laszlo Ersek <lersek@redhat.com>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
>---
> MdePkg/Include/Library/SmiHandlerProfileLib.h | 81
>++++++++++++++++++++
> MdePkg/MdePkg.dec                             |  5 +-
> 2 files changed, 85 insertions(+), 1 deletion(-)
>
>diff --git a/MdePkg/Include/Library/SmiHandlerProfileLib.h
>b/MdePkg/Include/Library/SmiHandlerProfileLib.h
>new file mode 100644
>index 0000000..10b7323
>--- /dev/null
>+++ b/MdePkg/Include/Library/SmiHandlerProfileLib.h
>@@ -0,0 +1,81 @@
>+/** @file
>+  Provides services to log the SMI handler registration.
>+
>+  This API provides services for the SMM Child Dispatch Protocols provider,
>+  to register SMI handler information to SmmCore.
>+
>+  NOTE:
>+  There is no need to update the consumers of SMST->SmiHandlerRegister()
>or
>+  the consumers of SMM Child Dispatch Protocols.
>+  The SmmCore (who produces SMST) should have ability to register such
>+  information directly.
>+  The SmmChildDispatcher (who produces SMM Child Dispatch Protocols)
>should
>+  be responsible to call the services to register information to SMM Core.
>+
>+Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+This program and the accompanying materials
>+are licensed and made available under the terms and conditions of the BSD
>License
>+which accompanies this distribution.  The full text of the license may be
>found at
>+http://opensource.org/licenses/bsd-license.php
>+
>+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+
>+**/
>+
>+#ifndef __SMI_HANDLER_PROFILE_LIB_H__
>+#define __SMI_HANDLER_PROFILE_LIB_H__
>+
>+#include <PiSmm.h>
>+
>+/**
>+  This function is called by SmmChildDispatcher module to report
>+  a new SMI handler is registered, to SmmCore.
>+
>+  @param HandlerGuid     The GUID to identify the type of the handler.
>+                         For the SmmChildDispatch protocol, the HandlerGuid
>+                         must be the GUID of SmmChildDispatch protocol.
>+  @param Handler         The SMI handler.
>+  @param CallerAddress   The address of the module who registers the SMI
>handler.
>+  @param Context         The context of the SMI handler.
>+                         For the SmmChildDispatch protocol, the Context
>+                         must match the one defined for SmmChildDispatch protocol.
>+  @param ContextSize     The size of the context in bytes.
>+                         For the SmmChildDispatch protocol, the Context
>+                         must match the one defined for SmmChildDispatch protocol.
>+
>+  @retval EFI_SUCCESS           The information is recorded.
>+  @retval EFI_UNSUPPORTED       The feature is unsupported.
>+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record
>the information.
>+**/
>+EFI_STATUS
>+EFIAPI
>+SmiHandlerProfileRegisterHandler (
>+  IN EFI_GUID                       *HandlerGuid,
>+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
>+  IN PHYSICAL_ADDRESS               CallerAddress,
>+  IN VOID                           *Context, OPTIONAL
>+  IN UINTN                          ContextSize OPTIONAL
>+  );
>+
>+/**
>+  This function is called by SmmChildDispatcher module to report
>+  an existing SMI handler is unregistered, to SmmCore.
>+
>+  @param HandlerGuid     The GUID to identify the type of the handler.
>+                         For the SmmChildDispatch protocol, the HandlerGuid
>+                         must be the GUID of SmmChildDispatch protocol.
>+  @param Handler         The SMI handler.
>+
>+  @retval EFI_SUCCESS           The original record is removed.
>+  @retval EFI_UNSUPPORTED       The feature is unsupported.
>+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and
>handler.
>+**/
>+EFI_STATUS
>+EFIAPI
>+SmiHandlerProfileUnregisterHandler (
>+  IN EFI_GUID                       *HandlerGuid,
>+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
>+  );
>+
>+#endif
>diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
>index f2bdb30..3310029 100644
>--- a/MdePkg/MdePkg.dec
>+++ b/MdePkg/MdePkg.dec
>@@ -4,7 +4,7 @@
> # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of
> # EFI1.10/UEFI2.6/PI1.4 and some Industry Standards.
> #
>-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
>+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
> # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
> #
>@@ -254,6 +254,9 @@
>   #
>   RngLib|Include/Library/RngLib.h
>
>+  ##  @libraryclass  Provides services to log the SMI handler registration.
>+  SmiHandlerProfileLib|Include/Library/SmiHandlerProfileLib.h
>+
> [LibraryClasses.IPF]
>   ##  @libraryclass  The SAL Library provides a service to make a SAL CALL.
>   SalLib|Include/Library/SalLib.h
>--
>2.7.4.windows.1



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

* Re: [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
  2017-02-08 16:30 ` [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance Jiewen Yao
@ 2017-02-10  3:29   ` Gao, Liming
  2017-02-10  4:38     ` Yao, Jiewen
  0 siblings, 1 reply; 20+ messages in thread
From: Gao, Liming @ 2017-02-10  3:29 UTC (permalink / raw)
  To: Yao, Jiewen, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Laszlo Ersek

One minor comment. This library type is DXE_SMM_DRIVER. It should include <PiSmm.h>, not <Base.h> 

With this change, Reviewed-by: Liming Gao <liming.gao@intel.com>.

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Jiewen Yao
>Sent: Thursday, February 09, 2017 12:30 AM
>To: edk2-devel@lists.01.org
>Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Laszlo Ersek
><lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>
>Subject: [edk2] [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL
>instance.
>
>Cc: Michael D Kinney <michael.d.kinney@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>Cc: Laszlo Ersek <lersek@redhat.com>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
>---
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c   | 72
>++++++++++++++++++++
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf | 36
>++++++++++
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni | 21
>++++++
> 3 files changed, 129 insertions(+)
>
>diff --git
>a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>new file mode 100644
>index 0000000..207482a
>--- /dev/null
>+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>@@ -0,0 +1,72 @@
>+/** @file
>+  NULL instance of SmiHandlerProfile Library.
>+
>+  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+  This program and the accompanying materials
>+  are licensed and made available under the terms and conditions of the BSD
>License
>+  which accompanies this distribution.  The full text of the license may be
>found at
>+  http://opensource.org/licenses/bsd-license.php.
>+
>+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+
>+**/
>+
>+#include <Base.h>
>+#include <Library/SmiHandlerProfileLib.h>
>+
>+/**
>+  This function is called by SmmChildDispatcher module to report
>+  a new SMI handler is registered, to SmmCore.
>+
>+  @param HandlerGuid     The GUID to identify the type of the handler.
>+                         For the SmmChildDispatch protocol, the HandlerGuid
>+                         must be the GUID of SmmChildDispatch protocol.
>+  @param Handler         The SMI handler.
>+  @param CallerAddress   The address of the module who registers the SMI
>handler.
>+  @param Context         The context of the SMI handler.
>+                         For the SmmChildDispatch protocol, the Context
>+                         must match the one defined for SmmChildDispatch protocol.
>+  @param ContextSize     The size of the context in bytes.
>+                         For the SmmChildDispatch protocol, the Context
>+                         must match the one defined for SmmChildDispatch protocol.
>+
>+  @retval EFI_SUCCESS           The information is recorded.
>+  @retval EFI_UNSUPPORTED       The feature is unsupported.
>+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record
>the information.
>+**/
>+EFI_STATUS
>+EFIAPI
>+SmiHandlerProfileRegisterHandler (
>+  IN EFI_GUID                       *HandlerGuid,
>+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
>+  IN PHYSICAL_ADDRESS               CallerAddress,
>+  IN VOID                           *Context, OPTIONAL
>+  IN UINTN                          ContextSize OPTIONAL
>+  )
>+{
>+  return EFI_UNSUPPORTED;
>+}
>+
>+/**
>+  This function is called by SmmChildDispatcher module to report
>+  an existing SMI handler is unregistered, to SmmCore.
>+
>+  @param HandlerGuid     The GUID to identify the type of the handler.
>+                         For the SmmChildDispatch protocol, the HandlerGuid
>+                         must be the GUID of SmmChildDispatch protocol.
>+  @param Handler         The SMI handler.
>+
>+  @retval EFI_SUCCESS           The original record is removed.
>+  @retval EFI_UNSUPPORTED       The feature is unsupported.
>+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and
>handler.
>+**/
>+EFI_STATUS
>+EFIAPI
>+SmiHandlerProfileUnregisterHandler (
>+  IN EFI_GUID                       *HandlerGuid,
>+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
>+  )
>+{
>+  return EFI_UNSUPPORTED;
>+}
>diff --git
>a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>new file mode 100644
>index 0000000..8220834
>--- /dev/null
>+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>@@ -0,0 +1,36 @@
>+## @file
>+# NULL instance of SmiHandlerProfile Library.
>+#
>+#  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+#
>+#  This program and the accompanying materials
>+#  are licensed and made available under the terms and conditions of the
>BSD License
>+#  which accompanies this distribution. The full text of the license may be
>found at
>+#  http://opensource.org/licenses/bsd-license.php.
>+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+#
>+#
>+##
>+
>+[Defines]
>+  INF_VERSION                    = 0x00010005
>+  BASE_NAME                      = SmiHandlerProfileLibNull
>+  MODULE_UNI_FILE                = SmiHandlerProfileLibNull.uni
>+  FILE_GUID                      = B43D1B52-6251-4E6F-82EC-A599A5EE94C1
>+  MODULE_TYPE                    = DXE_SMM_DRIVER
>+  VERSION_STRING                 = 1.0
>+  LIBRARY_CLASS                  = SmiHandlerProfileLib|DXE_SMM_DRIVER
>SMM_CORE
>+
>+#
>+# The following information is for reference only and not required by the
>build tools.
>+#
>+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
>+#
>+
>+[Sources]
>+  SmiHandlerProfileLibNull.c
>+
>+[Packages]
>+  MdePkg/MdePkg.dec
>+
>diff --git
>a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>new file mode 100644
>index 0000000..fa3ba63
>--- /dev/null
>+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>@@ -0,0 +1,21 @@
>+// /** @file
>+// NULL instance of SmiHandlerProfile Library.
>+//
>+// NULL instance of SmiHandlerProfile Library.
>+//
>+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+//
>+// This program and the accompanying materials
>+// are licensed and made available under the terms and conditions of the
>BSD License
>+// which accompanies this distribution. The full text of the license may be
>found at
>+// http://opensource.org/licenses/bsd-license.php.
>+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+//
>+// **/
>+
>+
>+#string STR_MODULE_ABSTRACT             #language en-US "NULL instance of
>SmiHandlerProfile Library"
>+
>+#string STR_MODULE_DESCRIPTION          #language en-US "NULL instance of
>SmiHandlerProfile Library."
>+
>--
>2.7.4.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
  2017-02-10  3:29   ` Gao, Liming
@ 2017-02-10  4:38     ` Yao, Jiewen
  0 siblings, 0 replies; 20+ messages in thread
From: Yao, Jiewen @ 2017-02-10  4:38 UTC (permalink / raw)
  To: Gao, Liming, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Laszlo Ersek

Got it. Thanks!

From: Gao, Liming
Sent: Thursday, February 9, 2017 7:30 PM
To: Yao, Jiewen <jiewen.yao@intel.com>; edk2-devel@lists.01.org
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Laszlo Ersek <lersek@redhat.com>
Subject: RE: [edk2] [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance.

One minor comment. This library type is DXE_SMM_DRIVER. It should include <PiSmm.h>, not <Base.h>

With this change, Reviewed-by: Liming Gao <liming.gao@intel.com<mailto:liming.gao@intel.com>>.

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Jiewen Yao
>Sent: Thursday, February 09, 2017 12:30 AM
>To: edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
>Cc: Kinney, Michael D <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Laszlo Ersek
><lersek@redhat.com<mailto:lersek@redhat.com>>; Gao, Liming <liming.gao@intel.com<mailto:liming.gao@intel.com>>
>Subject: [edk2] [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL
>instance.
>
>Cc: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>
>Cc: Liming Gao <liming.gao@intel.com<mailto:liming.gao@intel.com>>
>Cc: Laszlo Ersek <lersek@redhat.com<mailto:lersek@redhat.com>>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
>---
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c   | 72
>++++++++++++++++++++
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf | 36
>++++++++++
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni | 21
>++++++
> 3 files changed, 129 insertions(+)
>
>diff --git
>a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>new file mode 100644
>index 0000000..207482a
>--- /dev/null
>+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>@@ -0,0 +1,72 @@
>+/** @file
>+  NULL instance of SmiHandlerProfile Library.
>+
>+  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+  This program and the accompanying materials
>+  are licensed and made available under the terms and conditions of the BSD
>License
>+  which accompanies this distribution.  The full text of the license may be
>found at
>+  http://opensource.org/licenses/bsd-license.php.
>+
>+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+
>+**/
>+
>+#include <Base.h>
>+#include <Library/SmiHandlerProfileLib.h>
>+
>+/**
>+  This function is called by SmmChildDispatcher module to report
>+  a new SMI handler is registered, to SmmCore.
>+
>+  @param HandlerGuid     The GUID to identify the type of the handler.
>+                         For the SmmChildDispatch protocol, the HandlerGuid
>+                         must be the GUID of SmmChildDispatch protocol.
>+  @param Handler         The SMI handler.
>+  @param CallerAddress   The address of the module who registers the SMI
>handler.
>+  @param Context         The context of the SMI handler.
>+                         For the SmmChildDispatch protocol, the Context
>+                         must match the one defined for SmmChildDispatch protocol.
>+  @param ContextSize     The size of the context in bytes.
>+                         For the SmmChildDispatch protocol, the Context
>+                         must match the one defined for SmmChildDispatch protocol.
>+
>+  @retval EFI_SUCCESS           The information is recorded.
>+  @retval EFI_UNSUPPORTED       The feature is unsupported.
>+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record
>the information.
>+**/
>+EFI_STATUS
>+EFIAPI
>+SmiHandlerProfileRegisterHandler (
>+  IN EFI_GUID                       *HandlerGuid,
>+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,
>+  IN PHYSICAL_ADDRESS               CallerAddress,
>+  IN VOID                           *Context, OPTIONAL
>+  IN UINTN                          ContextSize OPTIONAL
>+  )
>+{
>+  return EFI_UNSUPPORTED;
>+}
>+
>+/**
>+  This function is called by SmmChildDispatcher module to report
>+  an existing SMI handler is unregistered, to SmmCore.
>+
>+  @param HandlerGuid     The GUID to identify the type of the handler.
>+                         For the SmmChildDispatch protocol, the HandlerGuid
>+                         must be the GUID of SmmChildDispatch protocol.
>+  @param Handler         The SMI handler.
>+
>+  @retval EFI_SUCCESS           The original record is removed.
>+  @retval EFI_UNSUPPORTED       The feature is unsupported.
>+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and
>handler.
>+**/
>+EFI_STATUS
>+EFIAPI
>+SmiHandlerProfileUnregisterHandler (
>+  IN EFI_GUID                       *HandlerGuid,
>+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler
>+  )
>+{
>+  return EFI_UNSUPPORTED;
>+}
>diff --git
>a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>new file mode 100644
>index 0000000..8220834
>--- /dev/null
>+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>@@ -0,0 +1,36 @@
>+## @file
>+# NULL instance of SmiHandlerProfile Library.
>+#
>+#  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+#
>+#  This program and the accompanying materials
>+#  are licensed and made available under the terms and conditions of the
>BSD License
>+#  which accompanies this distribution. The full text of the license may be
>found at
>+#  http://opensource.org/licenses/bsd-license.php.
>+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+#
>+#
>+##
>+
>+[Defines]
>+  INF_VERSION                    = 0x00010005
>+  BASE_NAME                      = SmiHandlerProfileLibNull
>+  MODULE_UNI_FILE                = SmiHandlerProfileLibNull.uni
>+  FILE_GUID                      = B43D1B52-6251-4E6F-82EC-A599A5EE94C1
>+  MODULE_TYPE                    = DXE_SMM_DRIVER
>+  VERSION_STRING                 = 1.0
>+  LIBRARY_CLASS                  = SmiHandlerProfileLib|DXE_SMM_DRIVER
>SMM_CORE
>+
>+#
>+# The following information is for reference only and not required by the
>build tools.
>+#
>+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
>+#
>+
>+[Sources]
>+  SmiHandlerProfileLibNull.c
>+
>+[Packages]
>+  MdePkg/MdePkg.dec
>+
>diff --git
>a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>new file mode 100644
>index 0000000..fa3ba63
>--- /dev/null
>+++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>@@ -0,0 +1,21 @@
>+// /** @file
>+// NULL instance of SmiHandlerProfile Library.
>+//
>+// NULL instance of SmiHandlerProfile Library.
>+//
>+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
>+//
>+// This program and the accompanying materials
>+// are licensed and made available under the terms and conditions of the
>BSD License
>+// which accompanies this distribution. The full text of the license may be
>found at
>+// http://opensource.org/licenses/bsd-license.php.
>+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+//
>+// **/
>+
>+
>+#string STR_MODULE_ABSTRACT             #language en-US "NULL instance of
>SmiHandlerProfile Library"
>+
>+#string STR_MODULE_DESCRIPTION          #language en-US "NULL instance of
>SmiHandlerProfile Library."
>+
>--
>2.7.4.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
>https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
  2017-02-08 17:57     ` Yao, Jiewen
  2017-02-08 18:28       ` Laszlo Ersek
@ 2017-02-21  7:06       ` Yao, Jiewen
  2017-02-21  8:47         ` Laszlo Ersek
  1 sibling, 1 reply; 20+ messages in thread
From: Yao, Jiewen @ 2017-02-21  7:06 UTC (permalink / raw)
  To: 'edk2-devel@ml01.01.org'
  Cc: Kinney, Michael D, Justen, Jordan L, Tian, Feng, Zeng, Star,
	Gao, Liming, Laszlo Ersek (lersek@redhat.com)

HI Laszlo
We have enabled OVMF KVM, and validated this patch.

There is no impact to OVMF. Fedora Guest boot and S3 passes.

Thank you
Yao Jiewen


From: Yao, Jiewen
Sent: Thursday, February 9, 2017 1:58 AM
To: Yao, Jiewen <jiewen.yao@intel.com>; edk2-devel@ml01.01.org
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; Tian, Feng <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao, Liming <liming.gao@intel.com>; Laszlo Ersek (lersek@redhat.com) <lersek@redhat.com>
Subject: RE: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature

Hi Laszlo
Thanks for the comment.

To clarify something:


1)       I did not enable SMI handler profile for OVMF because I notice the OVMF just use very few SMI handlers, and it does not have SmmChildDispatcher. Just like what you mentioned.


2)       I forget to mention: I did regression test for OVMF IA32 and IA32X64 with default SmiHandlerProfile is DISABLED.
I boot to UEFI SHELL only, and I do not enter OS.
I think the risk is very low, because if SMI handler profile is disabled, there is no code logic change.

VOID
SmmCoreInitializeSmiHandlerProfile (
  VOID
  )
{
  EFI_STATUS  Status;
  VOID        *Registration;
  EFI_HANDLE  Handle;

  if ((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
    InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);

    Status = gSmst->SmmRegisterProtocolNotify (
                      &gEfiSmmReadyToLockProtocolGuid,
                      SmmReadyToLockInSmiHandlerProfile,
                      &Registration
                      );
    ASSERT_EFI_ERROR (Status);

    Handle = NULL;
    Status = gSmst->SmmInstallProtocolInterface (
                      &Handle,
                      &gSmiHandlerProfileGuid,
                      EFI_NATIVE_INTERFACE,
                      &mSmiHandlerProfile
                      );
    ASSERT_EFI_ERROR (Status);
  }
}

I do understand your concern, because OVMF has some special feature which might be different with real hardware.

At same time, I have to mention that, it is very hard to setup KVM in Linux. I did try to follow your description before on NX.
I spent one week, but still fail to launch the final image on my side, I have no idea on what is wrong. That was a horrible experience.

I will have a try to follow your new document.
If it can be setup successfully, easily and fortunately, I do want to run it.

Thank you
Yao Jiewen

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
Sent: Wednesday, February 8, 2017 9:34 AM
To: Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>; edk2-devel@ml01.01.org<mailto:edk2-devel@ml01.01.org>
Cc: Kinney, Michael D <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Justen, Jordan L <jordan.l.justen@intel.com<mailto:jordan.l.justen@intel.com>>; Tian, Feng <feng.tian@intel.com<mailto:feng.tian@intel.com>>; Zeng, Star <star.zeng@intel.com<mailto:star.zeng@intel.com>>; Gao, Liming <liming.gao@intel.com<mailto:liming.gao@intel.com>>
Subject: Re: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature

CC Jordan

On 02/08/17 17:30, Jiewen Yao wrote:
> This series patch add SMI handler profile.
>
> The purpose of SMI handler profile is to add the capability to dump
> all SMI handlers produced by the firmware in a given boot.
> The SMI handlers here include
> 1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
> 2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
> 3) Hardware SMI handlers registered with
> SMM_XXX_DISPATCH_PROTOCOL->Register
> by SmmChildDispatcher module.
>
> The final log is an XML format log, including all SMM image name, all
> SMI handlers name, type, location (source file and line number), and
> the caller who registeres the handler.
>
> We enabled Quark platform to show how to add support in SmmChildDispatcher.

Thanks for the CC.

This module seems quite large, and OVMF (to my knowledge) doesn't include any special handlers. (Nothing from category (3), and I couldn't say if anything from category (2)).

Do you think this module would be useful to enable in OVMF, conditionally, with -D SMI_HANDLER_PROFILE_ENABLE?

Beyond the question of its utility to OVMF developers and users, requiring a separate UEFI app to dump the profile, presumably from the UEFI shell, is not really flexible for OVMF. We can't / don't build applications into the firmware image (beyond the shell and UiApp), so users would have to build a virtual disk image with this app, or we'd have to provide scripts for the same.

For now, I believe we don't wish to enable this in OVMF.

If you CC'd me for regression-testing PiSmmCore, as it is built into OVMF, with the default PcdSmiHandlerProfilePropertyMask=0 value, then I respectfully point you to the following article:

https://github.com/tianocore/tianocore.github.io/wiki/Testing-SMM-with-QEMU,-KVM-and-libvirt

Please set up a KVM environment as documented there, and adopt it for regular SMM testing :) My strong hope is that, by adopting KVM as a regular test platform, Intel developers won't only catch OVMF regressions before they post patches, but they should also see their own productivity increase.

I assume it must be much easier to click "Play" in the Virt-Manager GUI and to boot to an OS, on top of the new firmware, in seconds, than to flash firmware to a physical board. It does not replace physical board testing, but should catch a number of errors more gracefully.

The test cases I wrote up include UEFI variable testing and ACPI S3. The guest OSes covered are Fedora 25 and Windows 10. Please give it a look.

Thanks!
Laszlo

>
> NOTE: This SMI handler profile is a *DEBUG* feature only, to help
> platform developer or test engineer to audit the SMI handlers. Please
> do not include it in the final *RELEASE* image.
>
> Cc: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>
> Cc: Liming Gao <liming.gao@intel.com<mailto:liming.gao@intel.com>>
> Cc: Feng Tian <feng.tian@intel.com<mailto:feng.tian@intel.com>>
> Cc: Star Zeng <star.zeng@intel.com<mailto:star.zeng@intel.com>>
> Cc: Laszlo Ersek <lersek@redhat.com<mailto:lersek@redhat.com>>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
>
> Jiewen Yao (12):
>   MdePkg/Include: Add SmiHandlerProfileLib.h
>   MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
>   MdePkg/dsc: add SmiHandlerProfileLib to dsc.
>   MdeModulePkg/include: Add SmiHandlerProfile header file.
>   MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
>   MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
>   MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
>   MdeModulePkg/App: Add SmiHandlerProfile dump app.
>   MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
>   BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
>   QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
>   QuarkPlatformPkg: enable SmiHandlerProfile.
>
>  BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
>  MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
>  MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
>  MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
>  MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
>  MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
>  MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
>  MdePkg/MdePkg.dec                                                              |    5 +-
>  MdePkg/MdePkg.dsc                                                              |    3 +-
>  QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
>  QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
>  QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
>  QuarkPlatformPkg/Readme.md                                                     |   29 +-
>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
>  28 files changed, 3159 insertions(+), 56 deletions(-)  create mode
> 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
>  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
>  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.i
> nf  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.u
> ni  create mode 100644
> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoEx
> tra.uni  create mode 100644
> MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
>  create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
>  create mode 100644
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
>  create mode 100644
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.i
> nf  create mode 100644
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.u
> ni  create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
>  create mode 100644
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>  create mode 100644
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>  create mode 100644
> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
  2017-02-21  7:06       ` Yao, Jiewen
@ 2017-02-21  8:47         ` Laszlo Ersek
  0 siblings, 0 replies; 20+ messages in thread
From: Laszlo Ersek @ 2017-02-21  8:47 UTC (permalink / raw)
  To: Yao, Jiewen, 'edk2-devel@ml01.01.org'
  Cc: Kinney, Michael D, Justen, Jordan L, Tian, Feng, Zeng, Star,
	Gao, Liming

On 02/21/17 08:06, Yao, Jiewen wrote:
> HI Laszlo
> 
> We have enabled OVMF KVM, and validated this patch.

Fantastic!!! Thank you for making the effort!

> There is no impact to OVMF. Fedora Guest boot and S3 passes.

Hooray! :)

Thanks!
Laszlo

> 
>  
> 
> Thank you
> 
> Yao Jiewen
> 
>  
> 
>  
> 
> *From:*Yao, Jiewen
> *Sent:* Thursday, February 9, 2017 1:58 AM
> *To:* Yao, Jiewen <jiewen.yao@intel.com>; edk2-devel@ml01.01.org
> *Cc:* Kinney, Michael D <michael.d.kinney@intel.com>; Justen, Jordan L
> <jordan.l.justen@intel.com>; Tian, Feng <feng.tian@intel.com>; Zeng,
> Star <star.zeng@intel.com>; Gao, Liming <liming.gao@intel.com>; Laszlo
> Ersek (lersek@redhat.com) <lersek@redhat.com>
> *Subject:* RE: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature
> 
>  
> 
> Hi Laszlo
> 
> Thanks for the comment.
> 
>  
> 
> To clarify something:
> 
>  
> 
> 1)       I did not enable SMI handler profile for OVMF because I notice
> the OVMF just use very few SMI handlers, and it does not have
> SmmChildDispatcher. Just like what you mentioned.
> 
>  
> 
> 2)       I forget to mention: I did regression test for OVMF IA32 and
> IA32X64 with default SmiHandlerProfile is DISABLED.
> 
> I boot to UEFI SHELL only, and I do not enter OS.
> 
> I think the risk is very low, because if SMI handler profile is
> disabled, there is no code logic change.
> 
>  
> 
> VOID
> 
> SmmCoreInitializeSmiHandlerProfile (
> 
>   VOID
> 
>   )
> 
> {
> 
>   EFI_STATUS  Status;
> 
>   VOID        *Registration;
> 
>   EFI_HANDLE  Handle;
> 
>  
> 
>   if((PcdGet8 (PcdSmiHandlerProfilePropertyMask) & 0x1) != 0) {
> 
>     InsertTailList (&mRootSmiEntryList, &mRootSmiEntry.AllEntries);
> 
>  
> 
>     Status = gSmst->SmmRegisterProtocolNotify (
> 
>                       &gEfiSmmReadyToLockProtocolGuid,
> 
>                       SmmReadyToLockInSmiHandlerProfile,
> 
>                       &Registration
> 
>                       );
> 
>     ASSERT_EFI_ERROR (Status);
> 
>  
> 
>     Handle = NULL;
> 
>     Status = gSmst->SmmInstallProtocolInterface (
> 
>                       &Handle,
> 
>                       &gSmiHandlerProfileGuid,
> 
>                       EFI_NATIVE_INTERFACE,
> 
>                       &mSmiHandlerProfile
> 
>                       );
> 
>     ASSERT_EFI_ERROR (Status);
> 
>   }
> 
> }
> 
>  
> 
> I do understand your concern, because OVMF has some special feature
> which might be different with real hardware.
> 
>  
> 
> At same time, I have to mention that, it is very hard to setup KVM in
> Linux. I did try to follow your description before on NX.
> 
> I spent one week, but still fail to launch the final image on my side, I
> have no idea on what is wrong. That was a horrible experience.
> 
>  
> 
> I will have a try to follow your new document.
> 
> If it can be setup successfully, easily and fortunately, I do want to
> run it.
> 
>  
> 
> Thank you
> 
> Yao Jiewen
> 
>  
> 
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
> Sent: Wednesday, February 8, 2017 9:34 AM
> To: Yao, Jiewen <jiewen.yao@intel.com
> <mailto:jiewen.yao@intel.com>>; edk2-devel@ml01.01.org
> <mailto:edk2-devel@ml01.01.org>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com
> <mailto:michael.d.kinney@intel.com>>; Justen, Jordan L <jordan.l.justen@intel.com
> <mailto:jordan.l.justen@intel.com>>; Tian, Feng <feng.tian@intel.com
> <mailto:feng.tian@intel.com>>; Zeng, Star <star.zeng@intel.com
> <mailto:star.zeng@intel.com>>; Gao, Liming <liming.gao@intel.com
> <mailto:liming.gao@intel.com>>
> Subject: Re: [edk2] [PATCH 00/12] Add SmiHandlerProfile feature
> 
> CC Jordan
> 
> On 02/08/17 17:30, Jiewen Yao wrote:
>> This series patch add SMI handler profile.
>> 
>> The purpose of SMI handler profile is to add the capability to dump 
>> all SMI handlers produced by the firmware in a given boot.
>> The SMI handlers here include
>> 1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
>> 2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
>> 3) Hardware SMI handlers registered with 
>> SMM_XXX_DISPATCH_PROTOCOL->Register
>> by SmmChildDispatcher module.
>> 
>> The final log is an XML format log, including all SMM image name, all 
>> SMI handlers name, type, location (source file and line number), and 
>> the caller who registeres the handler.
>> 
>> We enabled Quark platform to show how to add support in SmmChildDispatcher.
> 
> Thanks for the CC.
> 
> This module seems quite large, and OVMF (to my knowledge) doesn't include any special handlers. (Nothing from category (3), and I couldn't say if anything from category (2)).
> 
> Do you think this module would be useful to enable in OVMF, conditionally, with -D SMI_HANDLER_PROFILE_ENABLE?
> 
> Beyond the question of its utility to OVMF developers and users, requiring a separate UEFI app to dump the profile, presumably from the UEFI shell, is not really flexible for OVMF. We can't / don't build applications into the firmware image (beyond the shell and UiApp), so users would have to build a virtual disk image with this app, or we'd have to provide scripts for the same.
> 
> For now, I believe we don't wish to enable this in OVMF.
> 
> If you CC'd me for regression-testing PiSmmCore, as it is built into OVMF, with the default PcdSmiHandlerProfilePropertyMask=0 value, then I respectfully point you to the following article:
> 
> https://github.com/tianocore/tianocore.github.io/wiki/Testing-SMM-with-QEMU,-KVM-and-libvirt
> 
> Please set up a KVM environment as documented there, and adopt it for regular SMM testing :) My strong hope is that, by adopting KVM as a regular test platform, Intel developers won't only catch OVMF regressions before they post patches, but they should also see their own productivity increase.
> 
> I assume it must be much easier to click "Play" in the Virt-Manager GUI and to boot to an OS, on top of the new firmware, in seconds, than to flash firmware to a physical board. It does not replace physical board testing, but should catch a number of errors more gracefully.
> 
> The test cases I wrote up include UEFI variable testing and ACPI S3. The guest OSes covered are Fedora 25 and Windows 10. Please give it a look.
> 
> Thanks!
> Laszlo
> 
>> 
>> NOTE: This SMI handler profile is a *DEBUG* feature only, to help 
>> platform developer or test engineer to audit the SMI handlers. Please 
>> do not include it in the final *RELEASE* image.
>> 
>> Cc: Michael D Kinney <michael.d.kinney@intel.com <mailto:michael.d.kinney@intel.com>>
>> Cc: Liming Gao <liming.gao@intel.com <mailto:liming.gao@intel.com>>
>> Cc: Feng Tian <feng.tian@intel.com <mailto:feng.tian@intel.com>>
>> Cc: Star Zeng <star.zeng@intel.com <mailto:star.zeng@intel.com>>
>> Cc: Laszlo Ersek <lersek@redhat.com <mailto:lersek@redhat.com>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Jiewen Yao <jiewen.yao@intel.com <mailto:jiewen.yao@intel.com>>
>> 
>> Jiewen Yao (12):
>>   MdePkg/Include: Add SmiHandlerProfileLib.h
>>   MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
>>   MdePkg/dsc: add SmiHandlerProfileLib to dsc.
>>   MdeModulePkg/include: Add SmiHandlerProfile header file.
>>   MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
>>   MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
>>   MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
>>   MdeModulePkg/App: Add SmiHandlerProfile dump app.
>>   MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
>>   BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
>>   QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
>>   QuarkPlatformPkg: enable SmiHandlerProfile.
>> 
>>  BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
>>  MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
>>  MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
>>  MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
>>  MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
>>  MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
>>  MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
>>  MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
>>  MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
>>  MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
>>  MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
>>  MdePkg/MdePkg.dec                                                              |    5 +-
>>  MdePkg/MdePkg.dsc                                                              |    3 +-
>>  QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
>>  QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
>>  QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
>>  QuarkPlatformPkg/Readme.md                                                     |   29 +-
>>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
>>  QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
>>  28 files changed, 3159 insertions(+), 56 deletions(-)  create mode 
>> 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
>>  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
>>  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.i
>> nf  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.u
>> ni  create mode 100644 
>> MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoEx
>> tra.uni  create mode 100644 
>> MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
>>  create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
>>  create mode 100644 
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
>>  create mode 100644 
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.i
>> nf  create mode 100644 
>> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.u
>> ni  create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
>>  create mode 100644 
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
>>  create mode 100644 
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
>>  create mode 100644 
>> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni
>> 
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> https://lists.01.org/mailman/listinfo/edk2-devel
> 



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

* Re: [PATCH 00/12] Add SmiHandlerProfile feature
  2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
                   ` (9 preceding siblings ...)
  2017-02-08 17:34 ` [PATCH 00/12] Add SmiHandlerProfile feature Laszlo Ersek
@ 2017-02-22  6:48 ` Zeng, Star
  10 siblings, 0 replies; 20+ messages in thread
From: Zeng, Star @ 2017-02-22  6:48 UTC (permalink / raw)
  To: Yao, Jiewen, edk2-devel@lists.01.org
  Cc: Kinney, Michael D, Gao, Liming, Tian, Feng, Laszlo Ersek,
	Zeng, Star

Reviewed-by: Star Zeng <star.zeng@intel.com> to MdeModulePkg changes.

Thanks,
Star
-----Original Message-----
From: Yao, Jiewen 
Sent: Thursday, February 9, 2017 12:30 AM
To: edk2-devel@lists.01.org
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>; Tian, Feng <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>; Laszlo Ersek <lersek@redhat.com>
Subject: [PATCH 00/12] Add SmiHandlerProfile feature

This series patch add SMI handler profile.

The purpose of SMI handler profile is to add the capability to dump all SMI handlers produced by the firmware in a given boot.
The SMI handlers here include
1) Root SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
2) GUID SMI handlers registered with SMST->SmiHandlerRegister by SmmCore.
3) Hardware SMI handlers registered with SMM_XXX_DISPATCH_PROTOCOL->Register
by SmmChildDispatcher module.

The final log is an XML format log, including all SMM image name, all SMI handlers name, type, location (source file and line number), and the caller who registeres the handler.

We enabled Quark platform to show how to add support in SmmChildDispatcher.

NOTE: This SMI handler profile is a *DEBUG* feature only, to help platform developer or test engineer to audit the SMI handlers. Please do not include it in the final *RELEASE* image.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>

Jiewen Yao (12):
  MdePkg/Include: Add SmiHandlerProfileLib.h
  MdePkg/SmiHandlerProfileLibNull: Add NULL instance.
  MdePkg/dsc: add SmiHandlerProfileLib to dsc.
  MdeModulePkg/include: Add SmiHandlerProfile header file.
  MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask.
  MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance.
  MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support.
  MdeModulePkg/App: Add SmiHandlerProfile dump app.
  MdeModulePkg/dsc: add SmiHandlerProfile to dsc.
  BaseTool/Script: Add SmiHandleProfile OS tool to get symbol.
  QuarkSocPkg/SmmChildDispatch: Add SmiHandlerProfile support.
  QuarkPlatformPkg: enable SmiHandlerProfile.

 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py                                |  351 ++++++
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c         |  685 +++++++++++
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf       |   65 +
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni       |   22 +
 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni  |   19 +
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.c                                        |    4 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.h                                        |   89 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf                                      |   17 +-
 MdeModulePkg/Core/PiSmmCore/Smi.c                                              |   46 +-
 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c                                | 1261 ++++++++++++++++++++
 MdeModulePkg/Include/Guid/SmiHandlerProfile.h                                  |  177 +++
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c         |  106 ++
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf       |   46 +
 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni       |   21 +
 MdeModulePkg/MdeModulePkg.dec                                                  |   11 +-
 MdeModulePkg/MdeModulePkg.dsc                                                  |    2 +
 MdePkg/Include/Library/SmiHandlerProfileLib.h                                  |   81 ++
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c             |   72 ++
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf           |   36 +
 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni           |   21 +
 MdePkg/MdePkg.dec                                                              |    5 +-
 MdePkg/MdePkg.dsc                                                              |    3 +-
 QuarkPlatformPkg/Quark.dsc                                                     |   16 +-
 QuarkPlatformPkg/Quark.fdf                                                     |    3 +-
 QuarkPlatformPkg/QuarkMin.dsc                                                  |    5 +-
 QuarkPlatformPkg/Readme.md                                                     |   29 +-
 QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmCore.c         |   19 +-
 QuarkSocPkg/QuarkNorthCluster/Smm/DxeSmm/QncSmmDispatcher/QNCSmmDispatcher.inf |    3 +-
 28 files changed, 3159 insertions(+), 56 deletions(-)  create mode 100644 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni
 create mode 100644 MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.uni
 create mode 100644 MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c
 create mode 100644 MdeModulePkg/Include/Guid/SmiHandlerProfile.h
 create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
 create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
 create mode 100644 MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.uni
 create mode 100644 MdePkg/Include/Library/SmiHandlerProfileLib.h
 create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c
 create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf
 create mode 100644 MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.uni

--
2.7.4.windows.1



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

end of thread, other threads:[~2017-02-22  6:48 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-08 16:30 [PATCH 00/12] Add SmiHandlerProfile feature Jiewen Yao
2017-02-08 16:30 ` [PATCH 01/12] MdePkg/Include: Add SmiHandlerProfileLib.h Jiewen Yao
2017-02-10  3:28   ` Gao, Liming
2017-02-08 16:30 ` [PATCH 02/12] MdePkg/SmiHandlerProfileLibNull: Add NULL instance Jiewen Yao
2017-02-10  3:29   ` Gao, Liming
2017-02-10  4:38     ` Yao, Jiewen
2017-02-08 16:30 ` [PATCH 03/12] MdePkg/dsc: add SmiHandlerProfileLib to dsc Jiewen Yao
2017-02-08 16:30 ` [PATCH 04/12] MdeModulePkg/include: Add SmiHandlerProfile header file Jiewen Yao
2017-02-08 16:30 ` [PATCH 05/12] MdeModulePkg/dec: Add PcdSmiHandlerProfilePropertyMask Jiewen Yao
2017-02-08 16:30 ` [PATCH 06/12] MdeModulePkg/SmmSmiHandlerProfileLib: Add SMM instance Jiewen Yao
2017-02-08 16:30 ` [PATCH 07/12] MdeModulePkg/PiSmmCore: Add SmiHandlerProfile support Jiewen Yao
2017-02-08 16:30 ` [PATCH 08/12] MdeModulePkg/App: Add SmiHandlerProfile dump app Jiewen Yao
2017-02-08 16:30 ` [PATCH 09/12] MdeModulePkg/dsc: add SmiHandlerProfile to dsc Jiewen Yao
2017-02-08 17:34 ` [PATCH 00/12] Add SmiHandlerProfile feature Laszlo Ersek
     [not found]   ` <BF2CCE9263284D428840004653A28B6E53F5E3BC@SHSMSX103.ccr.corp.intel.com>
2017-02-08 17:57     ` Yao, Jiewen
2017-02-08 18:28       ` Laszlo Ersek
2017-02-08 18:37         ` Yao, Jiewen
2017-02-21  7:06       ` Yao, Jiewen
2017-02-21  8:47         ` Laszlo Ersek
2017-02-22  6:48 ` Zeng, Star

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