From nobody Mon Feb 9 03:13:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+72756+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+72756+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1615780758; cv=none; d=zohomail.com; s=zohoarc; b=LkK0pwrcisaUbG7z4iRoONIgHRR/9U59SFNxEWcgS98g+/M58/+m2m+NbSdE5y7qdaeLaqUMQHUkc5R9Jqay+jnmVe/cZUeJ1fqnLeLql6myK4outymLo3e6sz2L2CLdHkr0D5jd6VdsJYJMbocercokWrEejhXdUvPW3WH3dys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615780758; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=mFJHW8LQ9Hc+nO3g+Ba4dU8LpKOA9dfFrpGIoDc5Gho=; b=d2dxr3RevOsTUenHv7bOJP5U7HGH40QrBKG7+FwlSpWvHapx+7W2UiE9zZTtOTJMWFbtrpva35yFZHGhwYhIsgS4+pn55Kl1nz6KOSjqP2vJvxFZVih/F7vNtjhQLpQ18ZG1xmzwnM2kp59dwNCAM7jushq9OiMtJ5ftiT88WLo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+72756+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1615780758827351.13661416691207; Sun, 14 Mar 2021 20:59:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id cf82YY1788612xV273C7jYds; Sun, 14 Mar 2021 20:59:18 -0700 X-Received: from mga17.intel.com (mga17.intel.com []) by mx.groups.io with SMTP id smtpd.web12.4285.1615780756988246010 for ; Sun, 14 Mar 2021 20:59:18 -0700 IronPort-SDR: TBo7QbCUVaG7unPrzPOIbbplKXCb1y5SuPQ4rXZH4FQZSCU8y+xT9rl4q3x45nIuxloJskRBoM S+Hd03owbAUw== X-IronPort-AV: E=McAfee;i="6000,8403,9923"; a="168946274" X-IronPort-AV: E=Sophos;i="5.81,249,1610438400"; d="scan'208";a="168946274" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2021 20:59:09 -0700 IronPort-SDR: JOZcXEnvBQXW1qiq8HL44BZGEWVNXVkBAEzjpyCIkZcqUzNLOTv+WC1d/t1AcO04N9iRZcxCrX N+qThkddHcpg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,249,1610438400"; d="scan'208";a="373297927" X-Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.154.141]) by orsmga006.jf.intel.com with ESMTP; 14 Mar 2021 20:59:07 -0700 From: "Dandan Bi" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [patch 01/28] MdePkg: Add RegisterFilterLib class and NULL instance Date: Mon, 15 Mar 2021 11:58:17 +0800 Message-Id: <20210315035844.32756-2-dandan.bi@intel.com> In-Reply-To: <20210315035844.32756-1-dandan.bi@intel.com> References: <20210315035844.32756-1-dandan.bi@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dandan.bi@intel.com X-Gm-Message-State: 5E2UnXXd4K9bsVeJwW6LiVqKx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1615780758; bh=rKQpiURkwgNRbFsAjKsCPhTep2raB7oKpRthOt82pdM=; h=Cc:Date:From:Reply-To:Subject:To; b=lUGqAXTqLomu27q8bPIxvHe0qWMCgztLLxGKUaa1aZX9vPrqniFH2krfcAG3q3gdLlU ELm35ADwc6zHoimzJhblADyavXqMOzz8/eFrj1PnaUAkQFXTn8FlLYl9x3CaGP7pC8sDp 8m0pvUPlNSyf5rDZi0W5Bf5Wq5TUjd5uUVU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3246 1. Add a new library class (RegisterFilterLib) to filter and trace port IO/MMIO/MSR access. 2. Add a NULL instance (RegisterFilterLibNull) can be used to keep current behavior. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Dandan Bi --- MdePkg/Include/Library/RegisterFilterLib.h | 225 ++++++++++++++++ .../RegisterFilterLibNull.c | 253 ++++++++++++++++++ .../RegisterFilterLibNull.inf | 23 ++ .../RegisterFilterLibNull.uni | 13 + MdePkg/MdePkg.dec | 7 +- MdePkg/MdePkg.dsc | 4 +- 6 files changed, 523 insertions(+), 2 deletions(-) create mode 100644 MdePkg/Include/Library/RegisterFilterLib.h create mode 100644 MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibN= ull.c create mode 100644 MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibN= ull.inf create mode 100644 MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibN= ull.uni diff --git a/MdePkg/Include/Library/RegisterFilterLib.h b/MdePkg/Include/Li= brary/RegisterFilterLib.h new file mode 100644 index 0000000000..df0adb3a42 --- /dev/null +++ b/MdePkg/Include/Library/RegisterFilterLib.h @@ -0,0 +1,225 @@ +/** @file + Public include file for the Port IO/MMIO/MSR RegisterFilterLib. + +Copyright (c) 2021, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef REGISTER_FILTER_LIB_H_ +#define REGISTER_FILTER_LIB_H_ + +typedef enum { + FilterWidth8, + FilterWidth16, + FilterWidth32, + FilterWidth64 +} FILTER_IO_WIDTH; + +/** + Filter IO read operation before read IO port. + It is used to filter IO read operation. + + It will return the flag to decide whether require read real IO port. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The destination buffer to store the results. + +**/ +BOOLEAN +EFIAPI +FilterBeforeIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN OUT VOID *Buffer + ); + +/** + Trace IO read operation after read IO port. + It is used to trace IO operation. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The destination buffer to store the results. + +**/ +VOID +EFIAPI +FilterAfterIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ); +/** + Filter IO Write operation before wirte IO port. + It is used to filter IO operation. + + It will return the flag to decide whether require read write IO port. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The source buffer from which to BeforeWrite da= ta. + +**/ +BOOLEAN +EFIAPI +FilterBeforeIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ); + + /** + Trace IO Write operation after wirte IO port. + It is used to trace IO operation. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The source buffer from which to BeforeWrite da= ta. + +**/ +VOID +EFIAPI +FilterAfterIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ); + +/** + Filter memory IO before Read operation. + + It will return the flag to decide whether require read real MMIO. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The destination buffer to store the results. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMmIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN OUT VOID *Buffer + ); + +/** + Tracer memory IO after read operation + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The destination buffer to store the results. + +**/ +VOID +EFIAPI +FilterAfterMmIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ); + +/** + Filter memory IO before write operation + + It will return the flag to decide whether require wirte real MMIO. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The source buffer from which to BeforeWrite da= ta. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMmIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ); + +/** + Tracer memory IO after write operation + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The source buffer from which to BeforeWrite da= ta. + +**/ +VOID +EFIAPI +FilterAfterMmIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ); + +/** + Filter MSR before read operation. + + It will return the flag to decide whether require read real MSR. + It can be used for emulation environment. + + @param Index The 8-bit Machine Specific Register in= dex to BeforeWrite. + @param Value The 64-bit value to BeforeRead from th= e Machine Specific Register. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMsrRead ( + IN UINT32 Index, + IN OUT UINT64 *Value + ); + +/** + Trace MSR after read operation + + @param Index The 8-bit Machine Specific Register in= dex to BeforeWrite. + @param Value The 64-bit value to BeforeRead from th= e Machine Specific Register. + +**/ +VOID +EFIAPI +FilterAfterMsrRead ( + IN UINT32 Index, + IN UINT64 *Value + ); + +/** + Filter MSR before write operation + + It will return the flag to decide whether require write real MSR. + It can be used for emulation environment. + + @param Index The 8-bit Machine Specific Register in= dex to BeforeWrite. + @param Value The 64-bit value to BeforeWrite to the= Machine Specific Register. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMsrWrite ( + IN UINT32 Index, + IN UINT64 *Value + ); + +/** + Trace MSR after write operation + + @param Index The 8-bit Machine Specific Register in= dex to BeforeWrite. + @param Value The 64-bit value to BeforeWrite to the= Machine Specific Register. + +**/ +VOID +EFIAPI +FilterAfterMsrWrite ( + IN UINT32 Index, + IN UINT64 *Value + ); + +#endif // REGISTER_FILTER_LIB_H_ diff --git a/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.c b= /MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.c new file mode 100644 index 0000000000..5c2bc2864a --- /dev/null +++ b/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.c @@ -0,0 +1,253 @@ +/** @file + Null instance of RegisterFilterLib. + + Copyright (c) 2021 Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +/** + Filter IO read operation before read IO port. + It is used to filter IO read operation. + + It will return the flag to decide whether require read real IO port. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in,out] Buffer The destination buffer to store the results. + +**/ +BOOLEAN +EFIAPI +FilterBeforeIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN OUT VOID *Buffer + ) +{ + return TRUE; +} + +/** + Trace IO read operation after read IO port. + It is used to trace IO operation. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The destination buffer to store the results. + +**/ +VOID +EFIAPI +FilterAfterIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ) +{ + return; +} + +/** + Filter IO Write operation before wirte IO port. + It is used to filter IO operation. + + It will return the flag to decide whether require read write IO port. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The source buffer from which to write data. + +**/ +BOOLEAN +EFIAPI +FilterBeforeIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ) +{ + return TRUE; +} + + /** + Trace IO Write operation after wirte IO port. + It is used to trace IO operation. + + @param[in] Width Signifies the width of the I/O operation. + @param[in] Address The base address of the I/O operation. + @param[in] Buffer The source buffer from which to Write data. + +**/ +VOID +EFIAPI +FilterAfterIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ) +{ + return; +} + +/** + Filter memory IO before Read operation. + + It will return the flag to decide whether require read real MMIO. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in,out] Buffer The destination buffer to store the results. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMmIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN OUT VOID *Buffer + ) +{ + return TRUE; +} + +/** + Tracer memory IO after read operation. + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The destination buffer to store the results. + +**/ +VOID +EFIAPI +FilterAfterMmIoRead ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ) +{ + return; +} + +/** + Filter memory IO before write operation. + + It will return the flag to decide whether require wirte real MMIO. + It can be used for emulation environment. + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The source buffer from which to write data. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMmIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ) +{ + return TRUE; +} + +/** + Tracer memory IO after write operation. + + @param[in] Width Signifies the width of the memory I/O operatio= n. + @param[in] Address The base address of the memory I/O operation. + @param[in] Buffer The source buffer from which to write data. + +**/ +VOID +EFIAPI +FilterAfterMmIoWrite ( + IN FILTER_IO_WIDTH Width, + IN UINTN Address, + IN VOID *Buffer + ) +{ + return; +} + +/** + Filter MSR before read operation. + + It will return the flag to decide whether require read real MSR. + It can be used for emulation environment. + + @param Index The Register index of the MSR. + @param Value Point to the data will be read from th= e MSR. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMsrRead ( + IN UINT32 Index, + IN OUT UINT64 *Value + ) +{ + return TRUE; +} + +/** + Trace MSR after read operation. + + @param Index The Register index of the MSR. + @param Value Point to the data has been be read fro= m the MSR. + +**/ +VOID +EFIAPI +FilterAfterMsrRead ( + IN UINT32 Index, + IN UINT64 *Value + ) +{ + return; +} + +/** + Filter MSR before write operation. + + It will return the flag to decide whether require write real MSR. + It can be used for emulation environment. + + @param Index The Register index of the MSR. + @param Value Point to the data want to be written t= o the MSR. + +**/ +BOOLEAN +EFIAPI +FilterBeforeMsrWrite ( + IN UINT32 Index, + IN UINT64 *Value + ) +{ + return TRUE; +} + +/** + Trace MSR after write operation. + + @param Index The Register index of the MSR. + @param Value Point to the data has been be written = to the MSR. + +**/ +VOID +EFIAPI +FilterAfterMsrWrite ( + IN UINT32 Index, + IN UINT64 *Value + ) +{ + return; +} + diff --git a/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf= b/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf new file mode 100644 index 0000000000..a7fc7497ed --- /dev/null +++ b/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf @@ -0,0 +1,23 @@ +## @file +# Null instance of RegisterFilterLib. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D FilterLibNull + MODULE_UNI_FILE =3D FilterLibNull.uni + FILE_GUID =3D 9F555194-A410-4AD6-B3FC-53F6E10FA793 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RegisterFilterLib + +[Sources] + RegisterFilterLibNull.c + +[Packages] + MdePkg/MdePkg.dec diff --git a/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.uni= b/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.uni new file mode 100644 index 0000000000..8a8f1c4a77 --- /dev/null +++ b/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.uni @@ -0,0 +1,13 @@ +// /** @file +// Null instance of RegisterFilterLib. +// +// Copyright (c) 2021, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of= RegisterFilterLib. +#string STR_MODULE_DESCRIPTION #language en-US "Null instance of= RegisterFilterLib." + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 1d2637acc2..c437e2a065 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -2,11 +2,11 @@ # This Package provides all definitions, library classes and libraries ins= tances. # # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of # EFI1.10/UEFI2.7/PI1.7 and some Industry Standards. # -# Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
# (C) Copyright 2016 - 2020 Hewlett Packard Enterprise Development LP
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -255,10 +255,15 @@ ## @libraryclass Extension to BaseLib for host based unit tests that all= ows a # subset of BaseLib services to be hooked for emulation. # UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h =20 + ## @libraryclass + # + # + RegisterFilterLib|Include/Library/RegisterFilterLib.h + ## @libraryclass This library provides an interface to request non-MMR= AM pages to be mapped # or unblocked from inside MM environment. # MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h =20 diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 79629e3f93..be89e28eef 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -1,9 +1,9 @@ ## @file # EFI/PI MdePkg Package # -# Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -125,10 +125,12 @@ MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.i= nf =20 MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint= .inf MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib= .inf =20 + MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf + [Components.IA32, Components.X64, Components.ARM, Components.AARCH64] # # Add UEFI Target Based Unit Tests # MdePkg/Test/UnitTest/Library/BaseLib/BaseLibUnitTestsUefi.inf --=20 2.18.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#72756): https://edk2.groups.io/g/devel/message/72756 Mute This Topic: https://groups.io/mt/81341923/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-