BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3902

TdProbeLib is used to probe if the working system is of Td guest. This
library is designed to run on SEC / PEI / DXE phases. A null instance
of the library returns Non-Td anyway. A platform specific TdProbeLib
will be implemented, for example, in OvmfPkg.

Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang....@intel.com>
Cc: James Bottomley <j...@linux.ibm.com>
Cc: Jiewen Yao <jiewen....@intel.com>
Cc: Gerd Hoffmann <kra...@redhat.com>
Signed-off-by: Min Xu <min.m...@intel.com>
---
 MdePkg/Include/Library/TdProbeLib.h           | 26 +++++++++++++++++++
 .../Library/TdProbeLibNull/TdProbeLibNull.c   | 25 ++++++++++++++++++
 .../Library/TdProbeLibNull/TdProbeLibNull.inf | 21 +++++++++++++++
 MdePkg/MdePkg.dec                             |  5 ++++
 MdePkg/MdePkg.dsc                             |  1 +
 5 files changed, 78 insertions(+)
 create mode 100644 MdePkg/Include/Library/TdProbeLib.h
 create mode 100644 MdePkg/Library/TdProbeLibNull/TdProbeLibNull.c
 create mode 100644 MdePkg/Library/TdProbeLibNull/TdProbeLibNull.inf

diff --git a/MdePkg/Include/Library/TdProbeLib.h 
b/MdePkg/Include/Library/TdProbeLib.h
new file mode 100644
index 000000000000..363a30fce649
--- /dev/null
+++ b/MdePkg/Include/Library/TdProbeLib.h
@@ -0,0 +1,26 @@
+/** @file
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef TD_PROBE_LIB_H_
+#define TD_PROBE_LIB_H_
+
+#define TD_PROBE_NON  0
+#define TD_PROBE_TDX  1
+
+/**
+  Probe if it is Tdx guest.
+
+  @return TD_PROBE_TDX if it is Tdx guest. Otherwise return TD_PROBE_NON.
+
+**/
+UINTN
+EFIAPI
+TdProbe (
+  VOID
+  );
+
+#endif
diff --git a/MdePkg/Library/TdProbeLibNull/TdProbeLibNull.c 
b/MdePkg/Library/TdProbeLibNull/TdProbeLibNull.c
new file mode 100644
index 000000000000..8aa2baf9053d
--- /dev/null
+++ b/MdePkg/Library/TdProbeLibNull/TdProbeLibNull.c
@@ -0,0 +1,25 @@
+/** @file
+
+  Null stub of TdProbeLib
+
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/TdProbeLib.h>
+
+/**
+  Probe if it is Tdx guest.
+
+  @return TD_PROBE_TDX if it is Tdx guest. Otherwise return TD_PROBE_NON.
+
+**/
+UINTN
+EFIAPI
+TdProbe (
+  VOID
+  )
+{
+  return TD_PROBE_NON;
+}
diff --git a/MdePkg/Library/TdProbeLibNull/TdProbeLibNull.inf 
b/MdePkg/Library/TdProbeLibNull/TdProbeLibNull.inf
new file mode 100644
index 000000000000..7db961e6ea2d
--- /dev/null
+++ b/MdePkg/Library/TdProbeLibNull/TdProbeLibNull.inf
@@ -0,0 +1,21 @@
+## @file
+# TdProbeLib null instance.
+#
+#  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = TdProbeLibNull
+  FILE_GUID                      = B15D67FE-0DAC-4316-8E26-8A6b85E43782
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TdProbeLib
+
+[Sources]
+  TdProbeLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 1934c9840423..9cc713e3d5af 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -267,6 +267,11 @@
   #
   RegisterFilterLib|Include/Library/RegisterFilterLib.h
 
+  ##  @libraryclass  This library provides interfances to probe Td guest.
+  #
+  #
+  TdProbeLib|Include/Library/TdProbeLib.h
+
 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
   ##  @libraryclass  Provides services to generate random number.
   #
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index d6a7af412be7..c2a68056f48a 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -130,6 +130,7 @@
   MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
 
   MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf
+  MdePkg/Library/TdProbeLibNull/TdProbeLibNull.inf
 
 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
   #
-- 
2.29.2.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88862): https://edk2.groups.io/g/devel/message/88862
Mute This Topic: https://groups.io/mt/90436750/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to