]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Support IoFifo for Tdx guest in BaseIoLibIntrinsic
authorMin Xu <min.m.xu@intel.com>
Fri, 22 Oct 2021 06:01:36 +0000 (14:01 +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

Previously IoFifo functions are in X64/IoFifoSev.nasm which supports
both SEV guest and Legacy guest. IoLibFifo.c is introduced to support
SEV/TDX/Legacy guest in one binary. It checks the guest type in runtime
and call corresponding functions then.

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/BaseIoLibIntrinsicSev.inf
MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c [new file with mode: 0644]
MdePkg/Library/BaseIoLibIntrinsic/IoLibSev.h [new file with mode: 0644]
MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm

index a74e54bee8b5fa4a6095c01d1681d80b262aeb3c..7fe1c60f046e2740ed24283c9819d3346ed900ca 100644 (file)
@@ -31,6 +31,7 @@
   BaseIoLibIntrinsicInternal.h\r
   IoHighLevel.c\r
   IoLibTdx.h\r
+  IoLibSev.h\r
 \r
 [Sources.IA32]\r
   IoLibGcc.c    | GCC\r
@@ -44,6 +45,7 @@
   IoLibMsc.c    | MSFT\r
   IoLib.c\r
   IoLibInternalTdx.c\r
+  IoLibFifo.c\r
   X64/IoFifoSev.nasm\r
 \r
 [Packages]\r
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
new file mode 100644 (file)
index 0000000..9a94bc6
--- /dev/null
@@ -0,0 +1,217 @@
+/** @file\r
+  IoFifo read/write routines.\r
+\r
+  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "BaseIoLibIntrinsicInternal.h"\r
+#include "IoLibSev.h"\r
+#include "IoLibTdx.h"\r
+#include <Uefi/UefiBaseType.h>\r
+#include <Library/TdxLib.h>\r
+\r
+/**\r
+  Reads an 8-bit I/O port fifo into a block of memory.\r
+\r
+  Reads the 8-bit I/O fifo port specified by Port.\r
+  The port is read Count times, and the read data is\r
+  stored in the provided Buffer.\r
+\r
+  This function must guarantee that all I/O read and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  In TDX a serial of TdIoRead8 is invoked to read the I/O port fifo.\r
+\r
+  @param  Port    The I/O port to read.\r
+  @param  Count   The number of times to read I/O port.\r
+  @param  Buffer  The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoReadFifo8 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  OUT     VOID   *Buffer\r
+  )\r
+{\r
+  if (IsTdxGuest ()) {\r
+    TdIoReadFifo8 (Port, Count, Buffer);\r
+  } else {\r
+    SevIoReadFifo8 (Port, Count, Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+  Writes a block of memory into an 8-bit I/O port fifo.\r
+\r
+  Writes the 8-bit I/O fifo port specified by Port.\r
+  The port is written Count times, and the write data is\r
+  retrieved from the provided Buffer.\r
+\r
+  This function must guarantee that all I/O write and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  In TDX a serial of TdIoWrite8 is invoked to write data to the I/O port.\r
+\r
+  @param  Port    The I/O port to write.\r
+  @param  Count   The number of times to write I/O port.\r
+  @param  Buffer  The buffer to retrieve the write data from.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoWriteFifo8 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  IN      VOID   *Buffer\r
+  )\r
+{\r
+  if (IsTdxGuest ()) {\r
+    TdIoWriteFifo8 (Port, Count, Buffer);\r
+  } else {\r
+    SevIoWriteFifo8 (Port, Count, Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+  Reads a 16-bit I/O port fifo into a block of memory.\r
+\r
+  Reads the 16-bit I/O fifo port specified by Port.\r
+  The port is read Count times, and the read data is\r
+  stored in the provided Buffer.\r
+\r
+  This function must guarantee that all I/O read and write operations are\r
+  serialized.\r
+\r
+  If 16-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  In TDX a serial of TdIoRead16 is invoked to read data from the I/O port.\r
+\r
+  @param  Port    The I/O port to read.\r
+  @param  Count   The number of times to read I/O port.\r
+  @param  Buffer  The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoReadFifo16 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  OUT     VOID   *Buffer\r
+  )\r
+{\r
+  if (IsTdxGuest ()) {\r
+    TdIoReadFifo16 (Port, Count, Buffer);\r
+  } else {\r
+    SevIoReadFifo16 (Port, Count, Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+  Writes a block of memory into a 16-bit I/O port fifo.\r
+\r
+  Writes the 16-bit I/O fifo port specified by Port.\r
+  The port is written Count times, and the write data is\r
+  retrieved from the provided Buffer.\r
+\r
+  This function must guarantee that all I/O write and write operations are\r
+  serialized.\r
+\r
+  If 16-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  In TDX a serial of TdIoWrite16 is invoked to write data to the I/O port.\r
+\r
+  @param  Port    The I/O port to write.\r
+  @param  Count   The number of times to write I/O port.\r
+  @param  Buffer  The buffer to retrieve the write data from.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoWriteFifo16 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  IN      VOID   *Buffer\r
+  )\r
+{\r
+  if (IsTdxGuest ()) {\r
+    TdIoWriteFifo16 (Port, Count, Buffer);\r
+  } else {\r
+    SevIoWriteFifo16 (Port, Count, Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+  Reads a 32-bit I/O port fifo into a block of memory.\r
+\r
+  Reads the 32-bit I/O fifo port specified by Port.\r
+  The port is read Count times, and the read data is\r
+  stored in the provided Buffer.\r
+\r
+  This function must guarantee that all I/O read and write operations are\r
+  serialized.\r
+\r
+  If 32-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  In TDX a serial of TdIoRead32 is invoked to read data from the I/O port.\r
+\r
+  @param  Port    The I/O port to read.\r
+  @param  Count   The number of times to read I/O port.\r
+  @param  Buffer  The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoReadFifo32 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  OUT     VOID   *Buffer\r
+  )\r
+{\r
+  if (IsTdxGuest ()) {\r
+    TdIoReadFifo32 (Port, Count, Buffer);\r
+  } else {\r
+    SevIoReadFifo32 (Port, Count, Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+  Writes a block of memory into a 32-bit I/O port fifo.\r
+\r
+  Writes the 32-bit I/O fifo port specified by Port.\r
+  The port is written Count times, and the write data is\r
+  retrieved from the provided Buffer.\r
+\r
+  This function must guarantee that all I/O write and write operations are\r
+  serialized.\r
+\r
+  If 32-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  In TDX a serial of TdIoWrite32 is invoked to write data to the I/O port.\r
+\r
+  @param  Port    The I/O port to write.\r
+  @param  Count   The number of times to write I/O port.\r
+  @param  Buffer  The buffer to retrieve the write data from.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+IoWriteFifo32 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  IN      VOID   *Buffer\r
+  )\r
+{\r
+  if (IsTdxGuest ()) {\r
+    TdIoWriteFifo32 (Port, Count, Buffer);\r
+  } else {\r
+    SevIoWriteFifo32 (Port, Count, Buffer);\r
+  }\r
+}\r
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibSev.h b/MdePkg/Library/BaseIoLibIntrinsic/IoLibSev.h
new file mode 100644 (file)
index 0000000..6d7cafc
--- /dev/null
@@ -0,0 +1,166 @@
+/** @file\r
+  Header file for SEV IO library.\r
+\r
+  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>\r
+   SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#ifndef IOLIB_SEV_H_\r
+#define IOLIB_SEV_H_\r
+\r
+#include <Base.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+/**\r
+  Reads an 8-bit I/O port fifo into a block of memory.\r
+\r
+  Reads the 8-bit I/O fifo port specified by Port.\r
+  The port is read Count times, and the read data is\r
+  stored in the provided Buffer.\r
+\r
+  This function must guarantee that all I/O read and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  @param  Port    The I/O port to read.\r
+  @param  Count   The number of times to read I/O port.\r
+  @param  Buffer  The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SevIoReadFifo8 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  OUT     VOID   *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a block of memory into an 8-bit I/O port fifo.\r
+\r
+  Writes the 8-bit I/O fifo port specified by Port.\r
+  The port is written Count times, and the write data is\r
+  retrieved from the provided Buffer.\r
+\r
+  This function must guarantee that all I/O write and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  @param  Port    The I/O port to write.\r
+  @param  Count   The number of times to write I/O port.\r
+  @param  Buffer  The buffer to retrieve the write data from.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SevIoWriteFifo8 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  IN      VOID   *Buffer\r
+  );\r
+\r
+/**\r
+  Reads an 8-bit I/O port fifo into a block of memory.\r
+\r
+  Reads the 8-bit I/O fifo port specified by Port.\r
+  The port is read Count times, and the read data is\r
+  stored in the provided Buffer.\r
+\r
+  This function must guarantee that all I/O read and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  @param  Port    The I/O port to read.\r
+  @param  Count   The number of times to read I/O port.\r
+  @param  Buffer  The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SevIoReadFifo16 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  OUT     VOID   *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a block of memory into an 8-bit I/O port fifo.\r
+\r
+  Writes the 8-bit I/O fifo port specified by Port.\r
+  The port is written Count times, and the write data is\r
+  retrieved from the provided Buffer.\r
+\r
+  This function must guarantee that all I/O write and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  @param  Port    The I/O port to write.\r
+  @param  Count   The number of times to write I/O port.\r
+  @param  Buffer  The buffer to retrieve the write data from.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SevIoWriteFifo16 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  IN      VOID   *Buffer\r
+  );\r
+\r
+/**\r
+  Reads an 8-bit I/O port fifo into a block of memory.\r
+\r
+  Reads the 8-bit I/O fifo port specified by Port.\r
+  The port is read Count times, and the read data is\r
+  stored in the provided Buffer.\r
+\r
+  This function must guarantee that all I/O read and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  @param  Port    The I/O port to read.\r
+  @param  Count   The number of times to read I/O port.\r
+  @param  Buffer  The buffer to store the read data into.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SevIoReadFifo32 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  OUT     VOID   *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a block of memory into an 8-bit I/O port fifo.\r
+\r
+  Writes the 8-bit I/O fifo port specified by Port.\r
+  The port is written Count times, and the write data is\r
+  retrieved from the provided Buffer.\r
+\r
+  This function must guarantee that all I/O write and write operations are\r
+  serialized.\r
+\r
+  If 8-bit I/O port operations are not supported, then ASSERT().\r
+\r
+  @param  Port    The I/O port to write.\r
+  @param  Count   The number of times to write I/O port.\r
+  @param  Buffer  The buffer to retrieve the write data from.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SevIoWriteFifo32 (\r
+  IN      UINTN  Port,\r
+  IN      UINTN  Count,\r
+  IN      VOID   *Buffer\r
+  );\r
+\r
+#endif\r
index 106f8881c55c761c73261c34be79fa59423c47b9..d02286b4d518bea597b731bdcb5ffce2c9514707 100644 (file)
@@ -67,14 +67,14 @@ ASM_PFX(SevNoRepIo):
 ;------------------------------------------------------------------------------\r
 ;  VOID\r
 ;  EFIAPI\r
-;  IoReadFifo8 (\r
+;  SevIoReadFifo8 (\r
 ;    IN  UINTN                 Port,              // rcx\r
 ;    IN  UINTN                 Size,              // rdx\r
 ;    OUT VOID                  *Buffer            // r8\r
 ;    );\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(IoReadFifo8)\r
-ASM_PFX(IoReadFifo8):\r
+global ASM_PFX(SevIoReadFifo8)\r
+ASM_PFX(SevIoReadFifo8):\r
     xchg    rcx, rdx\r
     xchg    rdi, r8             ; rdi: buffer address; r8: save rdi\r
 \r
@@ -103,14 +103,14 @@ ASM_PFX(IoReadFifo8):
 ;------------------------------------------------------------------------------\r
 ;  VOID\r
 ;  EFIAPI\r
-;  IoReadFifo16 (\r
+;  SevIoReadFifo16 (\r
 ;    IN  UINTN                 Port,              // rcx\r
 ;    IN  UINTN                 Size,              // rdx\r
 ;    OUT VOID                  *Buffer            // r8\r
 ;    );\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(IoReadFifo16)\r
-ASM_PFX(IoReadFifo16):\r
+global ASM_PFX(SevIoReadFifo16)\r
+ASM_PFX(SevIoReadFifo16):\r
     xchg    rcx, rdx\r
     xchg    rdi, r8             ; rdi: buffer address; r8: save rdi\r
 \r
@@ -139,14 +139,14 @@ ASM_PFX(IoReadFifo16):
 ;------------------------------------------------------------------------------\r
 ;  VOID\r
 ;  EFIAPI\r
-;  IoReadFifo32 (\r
+;  SevIoReadFifo32 (\r
 ;    IN  UINTN                 Port,              // rcx\r
 ;    IN  UINTN                 Size,              // rdx\r
 ;    OUT VOID                  *Buffer            // r8\r
 ;    );\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(IoReadFifo32)\r
-ASM_PFX(IoReadFifo32):\r
+global ASM_PFX(SevIoReadFifo32)\r
+ASM_PFX(SevIoReadFifo32):\r
     xchg    rcx, rdx\r
     xchg    rdi, r8             ; rdi: buffer address; r8: save rdi\r
 \r
@@ -181,8 +181,8 @@ ASM_PFX(IoReadFifo32):
 ;    IN VOID                   *Buffer            // r8\r
 ;    );\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(IoWriteFifo8)\r
-ASM_PFX(IoWriteFifo8):\r
+global ASM_PFX(SevIoWriteFifo8)\r
+ASM_PFX(SevIoWriteFifo8):\r
     xchg    rcx, rdx\r
     xchg    rsi, r8             ; rsi: buffer address; r8: save rsi\r
 \r
@@ -211,14 +211,14 @@ ASM_PFX(IoWriteFifo8):
 ;------------------------------------------------------------------------------\r
 ;  VOID\r
 ;  EFIAPI\r
-;  IoWriteFifo16 (\r
+;  SevIoWriteFifo16 (\r
 ;    IN UINTN                  Port,              // rcx\r
 ;    IN UINTN                  Size,              // rdx\r
 ;    IN VOID                   *Buffer            // r8\r
 ;    );\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(IoWriteFifo16)\r
-ASM_PFX(IoWriteFifo16):\r
+global ASM_PFX(SevIoWriteFifo16)\r
+ASM_PFX(SevIoWriteFifo16):\r
     xchg    rcx, rdx\r
     xchg    rsi, r8             ; rsi: buffer address; r8: save rsi\r
 \r
@@ -247,14 +247,14 @@ ASM_PFX(IoWriteFifo16):
 ;------------------------------------------------------------------------------\r
 ;  VOID\r
 ;  EFIAPI\r
-;  IoWriteFifo32 (\r
+;  SevIoWriteFifo32 (\r
 ;    IN UINTN                  Port,              // rcx\r
 ;    IN UINTN                  Size,              // rdx\r
 ;    IN VOID                   *Buffer            // r8\r
 ;    );\r
 ;------------------------------------------------------------------------------\r
-global ASM_PFX(IoWriteFifo32)\r
-ASM_PFX(IoWriteFifo32):\r
+global ASM_PFX(SevIoWriteFifo32)\r
+ASM_PFX(SevIoWriteFifo32):\r
     xchg    rcx, rdx\r
     xchg    rsi, r8             ; rsi: buffer address; r8: save rsi\r
 \r