]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Support mmio for Tdx guest in BaseIoLibIntrinsic
authorMin Xu <min.m.xu@intel.com>
Fri, 22 Oct 2021 05:48:28 +0000 (13:48 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 2 Apr 2022 08:15:12 +0000 (08:15 +0000)
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429

TDVF access MMIO with TDG.VP.VMCALL to invoke VMM provided emulation
functions. If the access to MMIO fails, it fall backs to the direct
access.

BaseIoLibIntrinsic.inf is the IoLib used by other packages. It will
not support I/O in Td guest. But some files are shared between
BaseIoLibIntrinsic and BaseIoLibIntrinsicSev (IoLib.c is the example). So
IoLibInternalTdxNull.c (which holds the null stub of the Td I/O routines)
is included in BaseIoLibIntrinsic.inf. BaseIoLibIntrinsic.inf doesn't
import TdxLib so that the Pkgs which include BaseIoLibIntrinsic.inf
need not include TdxLib.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
MdePkg/Library/BaseIoLibIntrinsic/IoLib.c

index 97eeada0656e9a033f00c698d341459b50f3c6eb..27b15d9ae256fb3f092754b85963da9bfd024737 100644 (file)
@@ -34,6 +34,8 @@
   IoLibMmioBuffer.c\r
   BaseIoLibIntrinsicInternal.h\r
   IoHighLevel.c\r
+  IoLibInternalTdxNull.c\r
+  IoLibTdx.h\r
 \r
 [Sources.IA32]\r
   IoLibGcc.c    | GCC\r
index 336d79736d9a69d6ea12fa41ea84459f28339e1f..a74e54bee8b5fa4a6095c01d1681d80b262aeb3c 100644 (file)
   IoLibMmioBuffer.c\r
   BaseIoLibIntrinsicInternal.h\r
   IoHighLevel.c\r
+  IoLibTdx.h\r
 \r
 [Sources.IA32]\r
   IoLibGcc.c    | GCC\r
   IoLibMsc.c    | MSFT\r
   IoLib.c\r
+  IoLibInternalTdxNull.c\r
   Ia32/IoFifoSev.nasm\r
 \r
 [Sources.X64]\r
   IoLibGcc.c    | GCC\r
   IoLibMsc.c    | MSFT\r
   IoLib.c\r
+  IoLibInternalTdx.c\r
   X64/IoFifoSev.nasm\r
 \r
 [Packages]\r
index 9d42e21a691c6ee9719a6d1d2ab42d14ba07c8eb..5bd02b56a1faa39b4b4ab5161abfd2452aee035e 100644 (file)
@@ -7,6 +7,7 @@
 **/\r
 \r
 #include "BaseIoLibIntrinsicInternal.h"\r
+#include "IoLibTdx.h"\r
 \r
 /**\r
   Reads a 64-bit I/O port.\r
@@ -69,6 +70,8 @@ IoWrite64 (
 \r
   If 8-bit MMIO register operations are not supported, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to read MMIO registers.\r
+\r
   @param  Address The MMIO register to read.\r
 \r
   @return The value read.\r
@@ -86,7 +89,13 @@ MmioRead8 (
   Flag = FilterBeforeMmIoRead (FilterWidth8, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    Value = *(volatile UINT8 *)Address;\r
+\r
+    if (IsTdxGuest ()) {\r
+      Value = TdMmioRead8 (Address);\r
+    } else {\r
+      Value = *(volatile UINT8 *)Address;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -104,6 +113,8 @@ MmioRead8 (
 \r
   If 8-bit MMIO register operations are not supported, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to write MMIO registers.\r
+\r
   @param  Address The MMIO register to write.\r
   @param  Value   The value to write to the MMIO register.\r
 \r
@@ -122,7 +133,13 @@ MmioWrite8 (
   Flag = FilterBeforeMmIoWrite (FilterWidth8, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    *(volatile UINT8 *)Address = Value;\r
+\r
+    if (IsTdxGuest ()) {\r
+      TdMmioWrite8 (Address, Value);\r
+    } else {\r
+      *(volatile UINT8 *)Address = Value;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -141,6 +158,8 @@ MmioWrite8 (
   If 16-bit MMIO register operations are not supported, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to read MMIO registers.\r
+\r
   @param  Address The MMIO register to read.\r
 \r
   @return The value read.\r
@@ -159,7 +178,13 @@ MmioRead16 (
   Flag = FilterBeforeMmIoRead (FilterWidth16, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    Value = *(volatile UINT16 *)Address;\r
+\r
+    if (IsTdxGuest ()) {\r
+      Value = TdMmioRead16 (Address);\r
+    } else {\r
+      Value = *(volatile UINT16 *)Address;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -178,6 +203,8 @@ MmioRead16 (
   If 16-bit MMIO register operations are not supported, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to write MMIO registers.\r
+\r
   @param  Address The MMIO register to write.\r
   @param  Value   The value to write to the MMIO register.\r
 \r
@@ -198,7 +225,13 @@ MmioWrite16 (
   Flag = FilterBeforeMmIoWrite (FilterWidth16, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    *(volatile UINT16 *)Address = Value;\r
+\r
+    if (IsTdxGuest ()) {\r
+      TdMmioWrite16 (Address, Value);\r
+    } else {\r
+      *(volatile UINT16 *)Address = Value;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -217,6 +250,8 @@ MmioWrite16 (
   If 32-bit MMIO register operations are not supported, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to read MMIO registers.\r
+\r
   @param  Address The MMIO register to read.\r
 \r
   @return The value read.\r
@@ -236,7 +271,13 @@ MmioRead32 (
   Flag = FilterBeforeMmIoRead (FilterWidth32, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    Value = *(volatile UINT32 *)Address;\r
+\r
+    if (IsTdxGuest ()) {\r
+      Value = TdMmioRead32 (Address);\r
+    } else {\r
+      Value = *(volatile UINT32 *)Address;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -255,6 +296,8 @@ MmioRead32 (
   If 32-bit MMIO register operations are not supported, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to write MMIO registers.\r
+\r
   @param  Address The MMIO register to write.\r
   @param  Value   The value to write to the MMIO register.\r
 \r
@@ -275,7 +318,13 @@ MmioWrite32 (
   Flag = FilterBeforeMmIoWrite (FilterWidth32, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    *(volatile UINT32 *)Address = Value;\r
+\r
+    if (IsTdxGuest ()) {\r
+      TdMmioWrite32 (Address, Value);\r
+    } else {\r
+      *(volatile UINT32 *)Address = Value;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -294,6 +343,8 @@ MmioWrite32 (
   If 64-bit MMIO register operations are not supported, then ASSERT().\r
   If Address is not aligned on a 64-bit boundary, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to read MMIO registers.\r
+\r
   @param  Address The MMIO register to read.\r
 \r
   @return The value read.\r
@@ -313,7 +364,13 @@ MmioRead64 (
   Flag = FilterBeforeMmIoRead (FilterWidth64, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    Value = *(volatile UINT64 *)Address;\r
+\r
+    if (IsTdxGuest ()) {\r
+      Value = TdMmioRead64 (Address);\r
+    } else {\r
+      Value = *(volatile UINT64 *)Address;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r
@@ -332,6 +389,8 @@ MmioRead64 (
   If 64-bit MMIO register operations are not supported, then ASSERT().\r
   If Address is not aligned on a 64-bit boundary, then ASSERT().\r
 \r
+  For Td guest TDVMCALL_MMIO is invoked to write MMIO registers.\r
+\r
   @param  Address The MMIO register to write.\r
   @param  Value   The value to write to the MMIO register.\r
 \r
@@ -350,7 +409,13 @@ MmioWrite64 (
   Flag = FilterBeforeMmIoWrite (FilterWidth64, Address, &Value);\r
   if (Flag) {\r
     MemoryFence ();\r
-    *(volatile UINT64 *)Address = Value;\r
+\r
+    if (IsTdxGuest ()) {\r
+      TdMmioWrite64 (Address, Value);\r
+    } else {\r
+      *(volatile UINT64 *)Address = Value;\r
+    }\r
+\r
     MemoryFence ();\r
   }\r
 \r