public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf
@ 2023-11-09  2:49 duntan
  2023-11-09  2:49 ` [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c duntan
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: duntan @ 2023-11-09  2:49 UTC (permalink / raw)
  To: devel

Simplify IoRead/WriteFifo implement in BaseIoLibIntrinsic by repeatedly calling
IoRead/Write in C code. This can avoid calling assembly code to use string I/O instructions.
With this change, Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed. Also
source files for IA32 and X64 are the same.

Dun Tan (2):
  MdePkg: Change IoLibFifo.c to IoLibFifoCc.c
  MdePkg:simplify Fifo API in BaseIoLibIntrinsic

 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf    |  10 ++--------
 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |   2 +-
 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm          | 131 -----------------------------------------------------------------------------------------------------------------------------------
 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c               |  59 +++++++++++++++++++++++++++++++----------------------------
 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c             | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm           | 120 ------------------------------------------------------------------------------------------------------------------------
 6 files changed, 251 insertions(+), 288 deletions(-)
 delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
 create mode 100644 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
 delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm

-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110938): https://edk2.groups.io/g/devel/message/110938
Mute This Topic: https://groups.io/mt/102478994/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c
  2023-11-09  2:49 [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf duntan
@ 2023-11-09  2:49 ` duntan
  2023-11-09  2:49 ` [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic duntan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: duntan @ 2023-11-09  2:49 UTC (permalink / raw)
  To: devel; +Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Ray Ni

Change IoLibFifo.c to IoLibFifoCc.c since the
file is for Tdx and SEV in BaseIoLibIntrinsicSev.
It's also to distinguish with a new incoming
IoLibFifo.c for BaseIoLibIntrinsic.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf      | 2 +-
 MdePkg/Library/BaseIoLibIntrinsic/{IoLibFifo.c => IoLibFifoCc.c} | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
index e1b8298ac4..8b62bd4e2a 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
+++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
@@ -45,7 +45,7 @@
   IoLibMsc.c    | MSFT
   IoLib.c
   IoLibInternalTdx.c
-  IoLibFifo.c
+  IoLibFifoCc.c
   X64/IoFifoSev.nasm
 
 [Packages]
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
similarity index 94%
rename from MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
rename to MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
index 9a94bc6a05..0c85cf9426 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
@@ -1,7 +1,7 @@
 /** @file
   IoFifo read/write routines.
 
-  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2021 - 2023, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110939): https://edk2.groups.io/g/devel/message/110939
Mute This Topic: https://groups.io/mt/102478995/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic
  2023-11-09  2:49 [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf duntan
  2023-11-09  2:49 ` [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c duntan
@ 2023-11-09  2:49 ` duntan
  2023-11-09  5:56 ` [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf Ni, Ray
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: duntan @ 2023-11-09  2:49 UTC (permalink / raw)
  To: devel; +Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Ray Ni

Simplify IoRead/WriteFifo implement by repeatedly
calling IoRead/Write in the C code.
This can avoid calling assembly code to use string
I/O instructions. With this change Ia32/IoFifo.nasm
and X64/IoFifo.nasm can be removed. Then the source
files for IA32 and X64 are the same.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf |  10 ++--------
 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm       | 131 -----------------------------------------------------------------------------------------------------------------------------------
 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c            | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm        | 120 ------------------------------------------------------------------------------------------------------------------------
 4 files changed, 222 insertions(+), 259 deletions(-)

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
index aeb072ee95..b587e2cded 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
@@ -38,17 +38,11 @@
   IoLibInternalTdxNull.c
   IoLibTdx.h
 
-[Sources.IA32]
+[Sources.IA32, Sources.X64]
   IoLibGcc.c    | GCC
   IoLibMsc.c    | MSFT
   IoLib.c
-  Ia32/IoFifo.nasm
-
-[Sources.X64]
-  IoLibGcc.c    | GCC
-  IoLibMsc.c    | MSFT
-  IoLib.c
-  X64/IoFifo.nasm
+  IoLibFifo.c
 
 [Sources.EBC]
   IoLibEbc.c
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
deleted file mode 100644
index a4ae1a0053..0000000000
--- a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
+++ /dev/null
@@ -1,131 +0,0 @@
-;------------------------------------------------------------------------------
-;
-; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-; Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
-;
-; SPDX-License-Identifier: BSD-2-Clause-Patent
-;
-;------------------------------------------------------------------------------
-
-    SECTION .text
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo8 (
-;    IN  UINTN                 Port,
-;    IN  UINTN                 Size,
-;    OUT VOID                  *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo8)
-ASM_PFX(IoReadFifo8):
-    push    edi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     edi, [esp + 16]
-rep insb
-    pop     edi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo16 (
-;    IN  UINTN                 Port,
-;    IN  UINTN                 Size,
-;    OUT VOID                  *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo16)
-ASM_PFX(IoReadFifo16):
-    push    edi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     edi, [esp + 16]
-rep insw
-    pop     edi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo32 (
-;    IN  UINTN                 Port,
-;    IN  UINTN                 Size,
-;    OUT VOID                  *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo32)
-ASM_PFX(IoReadFifo32):
-    push    edi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     edi, [esp + 16]
-rep insd
-    pop     edi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo8 (
-;    IN UINTN                  Port,
-;    IN UINTN                  Size,
-;    IN VOID                   *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo8)
-ASM_PFX(IoWriteFifo8):
-    push    esi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     esi, [esp + 16]
-rep outsb
-    pop     esi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo16 (
-;    IN UINTN                  Port,
-;    IN UINTN                  Size,
-;    IN VOID                   *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo16)
-ASM_PFX(IoWriteFifo16):
-    push    esi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     esi, [esp + 16]
-rep outsw
-    pop     esi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo32 (
-;    IN UINTN                  Port,
-;    IN UINTN                  Size,
-;    IN VOID                   *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo32)
-ASM_PFX(IoWriteFifo32):
-    push    esi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     esi, [esp + 16]
-rep outsd
-    pop     esi
-    ret
-
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
new file mode 100644
index 0000000000..bd1d372d0f
--- /dev/null
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
@@ -0,0 +1,220 @@
+/** @file
+  IoFifo read/write routines.
+
+  Copyright (c) 2021 - 2023, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseIoLibIntrinsicInternal.h"
+#include <Uefi/UefiBaseType.h>
+
+/**
+  Reads an 8-bit I/O port fifo into a block of memory.
+
+  Reads the 8-bit I/O fifo port specified by Port.
+  The port is read Count times, and the read data is
+  stored in the provided Buffer.
+
+  This function must guarantee that all I/O read and write operations are
+  serialized.
+
+  If 8-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoRead8 is invoked to read the I/O port fifo.
+
+  @param  Port    The I/O port to read.
+  @param  Count   The number of times to read I/O port.
+  @param  Buffer  The buffer to store the read data into.
+
+**/
+VOID
+EFIAPI
+IoReadFifo8 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  OUT     VOID   *Buffer
+  )
+{
+  UINT8  *Buffer8;
+
+  Buffer8 = (UINT8 *)Buffer;
+  while (Count-- > 0) {
+    *Buffer8++ = IoRead8 (Port);
+  }
+}
+
+/**
+  Writes a block of memory into an 8-bit I/O port fifo.
+
+  Writes the 8-bit I/O fifo port specified by Port.
+  The port is written Count times, and the write data is
+  retrieved from the provided Buffer.
+
+  This function must guarantee that all I/O write and write operations are
+  serialized.
+
+  If 8-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoWrite8 is invoked to write data to the I/O port.
+
+  @param  Port    The I/O port to write.
+  @param  Count   The number of times to write I/O port.
+  @param  Buffer  The buffer to retrieve the write data from.
+
+**/
+VOID
+EFIAPI
+IoWriteFifo8 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  IN      VOID   *Buffer
+  )
+{
+  UINT8  *Buffer8;
+
+  Buffer8 = (UINT8 *)Buffer;
+  while (Count-- > 0) {
+    IoWrite8 (Port, *Buffer8++);
+  }
+}
+
+/**
+  Reads a 16-bit I/O port fifo into a block of memory.
+
+  Reads the 16-bit I/O fifo port specified by Port.
+  The port is read Count times, and the read data is
+  stored in the provided Buffer.
+
+  This function must guarantee that all I/O read and write operations are
+  serialized.
+
+  If 16-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoRead16 is invoked to read data from the I/O port.
+
+  @param  Port    The I/O port to read.
+  @param  Count   The number of times to read I/O port.
+  @param  Buffer  The buffer to store the read data into.
+
+**/
+VOID
+EFIAPI
+IoReadFifo16 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  OUT     VOID   *Buffer
+  )
+{
+  UINT16  *Buffer16;
+
+  Buffer16 = (UINT16 *)Buffer;
+  while (Count-- > 0) {
+    *Buffer16++ = IoRead16 (Port);
+  }
+}
+
+/**
+  Writes a block of memory into a 16-bit I/O port fifo.
+
+  Writes the 16-bit I/O fifo port specified by Port.
+  The port is written Count times, and the write data is
+  retrieved from the provided Buffer.
+
+  This function must guarantee that all I/O write and write operations are
+  serialized.
+
+  If 16-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoWrite16 is invoked to write data to the I/O port.
+
+  @param  Port    The I/O port to write.
+  @param  Count   The number of times to write I/O port.
+  @param  Buffer  The buffer to retrieve the write data from.
+
+**/
+VOID
+EFIAPI
+IoWriteFifo16 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  IN      VOID   *Buffer
+  )
+{
+  UINT16  *Buffer16;
+
+  Buffer16 = (UINT16 *)Buffer;
+  while (Count-- > 0) {
+    IoWrite16 (Port, *Buffer16++);
+  }
+}
+
+/**
+  Reads a 32-bit I/O port fifo into a block of memory.
+
+  Reads the 32-bit I/O fifo port specified by Port.
+  The port is read Count times, and the read data is
+  stored in the provided Buffer.
+
+  This function must guarantee that all I/O read and write operations are
+  serialized.
+
+  If 32-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoRead32 is invoked to read data from the I/O port.
+
+  @param  Port    The I/O port to read.
+  @param  Count   The number of times to read I/O port.
+  @param  Buffer  The buffer to store the read data into.
+
+**/
+VOID
+EFIAPI
+IoReadFifo32 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  OUT     VOID   *Buffer
+  )
+{
+  UINT32  *Buffer32;
+
+  Buffer32 = (UINT32 *)Buffer;
+  while (Count-- > 0) {
+    *Buffer32++ = IoRead32 (Port);
+  }
+}
+
+/**
+  Writes a block of memory into a 32-bit I/O port fifo.
+
+  Writes the 32-bit I/O fifo port specified by Port.
+  The port is written Count times, and the write data is
+  retrieved from the provided Buffer.
+
+  This function must guarantee that all I/O write and write operations are
+  serialized.
+
+  If 32-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoWrite32 is invoked to write data to the I/O port.
+
+  @param  Port    The I/O port to write.
+  @param  Count   The number of times to write I/O port.
+  @param  Buffer  The buffer to retrieve the write data from.
+
+**/
+VOID
+EFIAPI
+IoWriteFifo32 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  IN      VOID   *Buffer
+  )
+{
+  UINT32  *Buffer32;
+
+  Buffer32 = (UINT32 *)Buffer;
+  while (Count-- > 0) {
+    IoWrite32 (Port, *Buffer32++);
+  }
+}
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
deleted file mode 100644
index d459072f6e..0000000000
--- a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
+++ /dev/null
@@ -1,120 +0,0 @@
-;------------------------------------------------------------------------------
-;
-; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
-; Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
-;
-; SPDX-License-Identifier: BSD-2-Clause-Patent
-;
-;------------------------------------------------------------------------------
-
-    DEFAULT REL
-    SECTION .text
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo8 (
-;    IN  UINTN                 Port,              // rcx
-;    IN  UINTN                 Size,              // rdx
-;    OUT VOID                  *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo8)
-ASM_PFX(IoReadFifo8):
-    cld
-    xchg    rcx, rdx
-    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
-rep insb
-    mov     rdi, r8             ; restore rdi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo16 (
-;    IN  UINTN                 Port,              // rcx
-;    IN  UINTN                 Size,              // rdx
-;    OUT VOID                  *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo16)
-ASM_PFX(IoReadFifo16):
-    cld
-    xchg    rcx, rdx
-    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
-rep insw
-    mov     rdi, r8             ; restore rdi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo32 (
-;    IN  UINTN                 Port,              // rcx
-;    IN  UINTN                 Size,              // rdx
-;    OUT VOID                  *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo32)
-ASM_PFX(IoReadFifo32):
-    cld
-    xchg    rcx, rdx
-    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
-rep insd
-    mov     rdi, r8             ; restore rdi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo8 (
-;    IN UINTN                  Port,              // rcx
-;    IN UINTN                  Size,              // rdx
-;    IN VOID                   *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo8)
-ASM_PFX(IoWriteFifo8):
-    cld
-    xchg    rcx, rdx
-    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
-rep outsb
-    mov     rsi, r8             ; restore rsi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo16 (
-;    IN UINTN                  Port,              // rcx
-;    IN UINTN                  Size,              // rdx
-;    IN VOID                   *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo16)
-ASM_PFX(IoWriteFifo16):
-    cld
-    xchg    rcx, rdx
-    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
-rep outsw
-    mov     rsi, r8             ; restore rsi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo32 (
-;    IN UINTN                  Port,              // rcx
-;    IN UINTN                  Size,              // rdx
-;    IN VOID                   *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo32)
-ASM_PFX(IoWriteFifo32):
-    cld
-    xchg    rcx, rdx
-    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
-rep outsd
-    mov     rsi, r8             ; restore rsi
-    ret
-
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110940): https://edk2.groups.io/g/devel/message/110940
Mute This Topic: https://groups.io/mt/102478996/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf
  2023-11-09  2:49 [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf duntan
  2023-11-09  2:49 ` [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c duntan
  2023-11-09  2:49 ` [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic duntan
@ 2023-11-09  5:56 ` Ni, Ray
  2023-11-13 13:07   ` Laszlo Ersek
       [not found] ` <1795D4A7BE9E02F3.6123@groups.io>
       [not found] ` <1795D4A7D7819C64.15940@groups.io>
  4 siblings, 1 reply; 10+ messages in thread
From: Ni, Ray @ 2023-11-09  5:56 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun

[-- Attachment #1: Type: text/plain, Size: 2527 bytes --]

Reviewed-by: Ray Ni <ray.ni@intel.com>

Thanks for providing the alternative solution that avoids impacting OVMF boot performance.

Thanks,
Ray
________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of duntan <dun.tan@intel.com>
Sent: Thursday, November 9, 2023 10:49 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Subject: [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf

Simplify IoRead/WriteFifo implement in BaseIoLibIntrinsic by repeatedly calling
IoRead/Write in C code. This can avoid calling assembly code to use string I/O instructions.
With this change, Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed. Also
source files for IA32 and X64 are the same.

Dun Tan (2):
  MdePkg: Change IoLibFifo.c to IoLibFifoCc.c
  MdePkg:simplify Fifo API in BaseIoLibIntrinsic

 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf    |  10 ++--------
 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |   2 +-
 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm          | 131 -----------------------------------------------------------------------------------------------------------------------------------
 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c               |  59 +++++++++++++++++++++++++++++++----------------------------
 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c             | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm           | 120 ------------------------------------------------------------------------------------------------------------------------
 6 files changed, 251 insertions(+), 288 deletions(-)
 delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
 create mode 100644 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
 delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm

--
2.31.1.windows.1








-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110949): https://edk2.groups.io/g/devel/message/110949
Mute This Topic: https://groups.io/mt/102478994/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 5055 bytes --]

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

* Re: [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf
  2023-11-09  5:56 ` [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf Ni, Ray
@ 2023-11-13 13:07   ` Laszlo Ersek
  2023-11-27 10:14     ` duntan
  0 siblings, 1 reply; 10+ messages in thread
From: Laszlo Ersek @ 2023-11-13 13:07 UTC (permalink / raw)
  To: devel, ray.ni, Tan, Dun

On 11/9/23 06:56, Ni, Ray wrote:
> Reviewed-by: Ray Ni <ray.ni@intel.com>
> 
> Thanks for providing the alternative solution that avoids impacting OVMF
> boot performance.

This approach looks good to me.

The IA32 and X64 OVMF platforms use "BaseIoLibIntrinsicSev.inf", and
that library instance is left alone.

The RISC-V OVMF platform uses "BaseIoLibIntrinsic.inf", but RISC-V
already doesn't (can't) use the IA32/X64 NASM files.

So, surprisingly, the "IoFifo.nasm" files are actually unused,
pre-patch; IA32 and X64 OVMF only uses the "IoFifoSev.nasm" files.

Acked-by: Laszlo Ersek <lersek@redhat.com>

Thanks!
Laszlo




> 
> Thanks,
> Ray
> ------------------------------------------------------------------------
> *From:* devel@edk2.groups.io <devel@edk2.groups.io> on behalf of duntan
> <dun.tan@intel.com>
> *Sent:* Thursday, November 9, 2023 10:49 AM
> *To:* devel@edk2.groups.io <devel@edk2.groups.io>
> *Subject:* [edk2-devel] [PATCH 0/2] Remove string IO instruction in
> BaseIoLibIntrinsic.inf
>  
> Simplify IoRead/WriteFifo implement in BaseIoLibIntrinsic by repeatedly
> calling
> IoRead/Write in C code. This can avoid calling assembly code to use
> string I/O instructions.
> With this change, Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed. Also
> source files for IA32 and X64 are the same.
> 
> Dun Tan (2):
>   MdePkg: Change IoLibFifo.c to IoLibFifoCc.c
>   MdePkg:simplify Fifo API in BaseIoLibIntrinsic
> 
>  MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf    |  10
> ++--------
>  MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |   2 +-
>  MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm          | 131
> -----------------------------------------------------------------------------------------------------------------------------------
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c               |  59
> +++++++++++++++++++++++++++++++----------------------------
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c             | 217
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm           | 120
> ------------------------------------------------------------------------------------------------------------------------
>  6 files changed, 251 insertions(+), 288 deletions(-)
>  delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
>  create mode 100644 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
>  delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> 
> -- 
> 2.31.1.windows.1
> 
> 
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111152): https://edk2.groups.io/g/devel/message/111152
Mute This Topic: https://groups.io/mt/102478994/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf
  2023-11-13 13:07   ` Laszlo Ersek
@ 2023-11-27 10:14     ` duntan
  0 siblings, 0 replies; 10+ messages in thread
From: duntan @ 2023-11-27 10:14 UTC (permalink / raw)
  To: devel@edk2.groups.io, Kinney, Michael D, Gao, Liming; +Cc: Ni, Ray

Hi Mike and Liming,

Could you help to review this patch set? It's to remove string IO instruction in BaseIoLibIntrinsic and simplify BaseIoLibIntrinsic.

Thanks,
Dun

-----Original Message-----
From: Laszlo Ersek <lersek@redhat.com> 
Sent: Monday, November 13, 2023 9:08 PM
To: devel@edk2.groups.io; Ni, Ray <ray.ni@intel.com>; Tan, Dun <dun.tan@intel.com>
Subject: Re: [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf

On 11/9/23 06:56, Ni, Ray wrote:
> Reviewed-by: Ray Ni <ray.ni@intel.com>
> 
> Thanks for providing the alternative solution that avoids impacting 
> OVMF boot performance.

This approach looks good to me.

The IA32 and X64 OVMF platforms use "BaseIoLibIntrinsicSev.inf", and that library instance is left alone.

The RISC-V OVMF platform uses "BaseIoLibIntrinsic.inf", but RISC-V already doesn't (can't) use the IA32/X64 NASM files.

So, surprisingly, the "IoFifo.nasm" files are actually unused, pre-patch; IA32 and X64 OVMF only uses the "IoFifoSev.nasm" files.

Acked-by: Laszlo Ersek <lersek@redhat.com>

Thanks!
Laszlo




> 
> Thanks,
> Ray
> ----------------------------------------------------------------------
> --
> *From:* devel@edk2.groups.io <devel@edk2.groups.io> on behalf of 
> duntan <dun.tan@intel.com>
> *Sent:* Thursday, November 9, 2023 10:49 AM
> *To:* devel@edk2.groups.io <devel@edk2.groups.io>
> *Subject:* [edk2-devel] [PATCH 0/2] Remove string IO instruction in 
> BaseIoLibIntrinsic.inf
>  
> Simplify IoRead/WriteFifo implement in BaseIoLibIntrinsic by 
> repeatedly calling IoRead/Write in C code. This can avoid calling 
> assembly code to use string I/O instructions.
> With this change, Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed. 
> Also source files for IA32 and X64 are the same.
> 
> Dun Tan (2):
>   MdePkg: Change IoLibFifo.c to IoLibFifoCc.c
>   MdePkg:simplify Fifo API in BaseIoLibIntrinsic
> 
>  MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf    |  10
> ++--------
>  MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |   2 +-
>  MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm          | 131
> ----------------------------------------------------------------------
> -------------------------------------------------------------
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c               |  59
> +++++++++++++++++++++++++++++++----------------------------
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c             | 217
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm           | 120
> ----------------------------------------------------------------------
> --------------------------------------------------
>  6 files changed, 251 insertions(+), 288 deletions(-)
>  delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
>  create mode 100644 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
>  delete mode 100644 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> 
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111734): https://edk2.groups.io/g/devel/message/111734
Mute This Topic: https://groups.io/mt/102478994/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c
       [not found] ` <1795D4A7BE9E02F3.6123@groups.io>
@ 2023-12-06  9:25   ` duntan
  0 siblings, 0 replies; 10+ messages in thread
From: duntan @ 2023-12-06  9:25 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun
  Cc: Kinney, Michael D, Gao, Liming, Liu, Zhiguang, Ni, Ray

Hi Mike and Liming,

Could you please help to review this patch? 

Thanks.
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Thursday, November 9, 2023 10:50 AM
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c

Change IoLibFifo.c to IoLibFifoCc.c since the file is for Tdx and SEV in BaseIoLibIntrinsicSev.
It's also to distinguish with a new incoming IoLibFifo.c for BaseIoLibIntrinsic.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf      | 2 +-
 MdePkg/Library/BaseIoLibIntrinsic/{IoLibFifo.c => IoLibFifoCc.c} | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
index e1b8298ac4..8b62bd4e2a 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
+++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf
@@ -45,7 +45,7 @@
   IoLibMsc.c    | MSFT
   IoLib.c
   IoLibInternalTdx.c
-  IoLibFifo.c
+  IoLibFifoCc.c
   X64/IoFifoSev.nasm
 
 [Packages]
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
similarity index 94%
rename from MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
rename to MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
index 9a94bc6a05..0c85cf9426 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifoCc.c
@@ -1,7 +1,7 @@
 /** @file
   IoFifo read/write routines.
 
-  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2021 - 2023, Intel Corporation. All rights 
+ reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
--
2.31.1.windows.1








-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112103): https://edk2.groups.io/g/devel/message/112103
Mute This Topic: https://groups.io/mt/103009909/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic
       [not found] ` <1795D4A7D7819C64.15940@groups.io>
@ 2023-12-06  9:26   ` duntan
  2023-12-11 17:34     ` Michael D Kinney
  0 siblings, 1 reply; 10+ messages in thread
From: duntan @ 2023-12-06  9:26 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun
  Cc: Kinney, Michael D, Gao, Liming, Liu, Zhiguang, Ni, Ray

Hi Mike and Liming, 

Could you please help to review this patch?

Thanks,
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Thursday, November 9, 2023 10:50 AM
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic

Simplify IoRead/WriteFifo implement by repeatedly calling IoRead/Write in the C code.
This can avoid calling assembly code to use string I/O instructions. With this change Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed. Then the source files for IA32 and X64 are the same.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf |  10 ++--------
 MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm       | 131 -----------------------------------------------------------------------------------------------------------------------------------
 MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c            | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm        | 120 ------------------------------------------------------------------------------------------------------------------------
 4 files changed, 222 insertions(+), 259 deletions(-)

diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
index aeb072ee95..b587e2cded 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
@@ -38,17 +38,11 @@
   IoLibInternalTdxNull.c
   IoLibTdx.h
 
-[Sources.IA32]
+[Sources.IA32, Sources.X64]
   IoLibGcc.c    | GCC
   IoLibMsc.c    | MSFT
   IoLib.c
-  Ia32/IoFifo.nasm
-
-[Sources.X64]
-  IoLibGcc.c    | GCC
-  IoLibMsc.c    | MSFT
-  IoLib.c
-  X64/IoFifo.nasm
+  IoLibFifo.c
 
 [Sources.EBC]
   IoLibEbc.c
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
deleted file mode 100644
index a4ae1a0053..0000000000
--- a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
+++ /dev/null
@@ -1,131 +0,0 @@
-;------------------------------------------------------------------------------
-;
-; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> -; Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> -; -; SPDX-License-Identifier: BSD-2-Clause-Patent -;
-;------------------------------------------------------------------------------
-
-    SECTION .text
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo8 (
-;    IN  UINTN                 Port,
-;    IN  UINTN                 Size,
-;    OUT VOID                  *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo8)
-ASM_PFX(IoReadFifo8):
-    push    edi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     edi, [esp + 16]
-rep insb
-    pop     edi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo16 (
-;    IN  UINTN                 Port,
-;    IN  UINTN                 Size,
-;    OUT VOID                  *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo16)
-ASM_PFX(IoReadFifo16):
-    push    edi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     edi, [esp + 16]
-rep insw
-    pop     edi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo32 (
-;    IN  UINTN                 Port,
-;    IN  UINTN                 Size,
-;    OUT VOID                  *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo32)
-ASM_PFX(IoReadFifo32):
-    push    edi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     edi, [esp + 16]
-rep insd
-    pop     edi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo8 (
-;    IN UINTN                  Port,
-;    IN UINTN                  Size,
-;    IN VOID                   *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo8)
-ASM_PFX(IoWriteFifo8):
-    push    esi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     esi, [esp + 16]
-rep outsb
-    pop     esi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo16 (
-;    IN UINTN                  Port,
-;    IN UINTN                  Size,
-;    IN VOID                   *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo16)
-ASM_PFX(IoWriteFifo16):
-    push    esi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     esi, [esp + 16]
-rep outsw
-    pop     esi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo32 (
-;    IN UINTN                  Port,
-;    IN UINTN                  Size,
-;    IN VOID                   *Buffer
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo32)
-ASM_PFX(IoWriteFifo32):
-    push    esi
-    cld
-    mov     dx, [esp + 8]
-    mov     ecx, [esp + 12]
-    mov     esi, [esp + 16]
-rep outsd
-    pop     esi
-    ret
-
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
new file mode 100644
index 0000000000..bd1d372d0f
--- /dev/null
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
@@ -0,0 +1,220 @@
+/** @file
+  IoFifo read/write routines.
+
+  Copyright (c) 2021 - 2023, Intel Corporation. All rights 
+ reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseIoLibIntrinsicInternal.h"
+#include <Uefi/UefiBaseType.h>
+
+/**
+  Reads an 8-bit I/O port fifo into a block of memory.
+
+  Reads the 8-bit I/O fifo port specified by Port.
+  The port is read Count times, and the read data is  stored in the 
+ provided Buffer.
+
+  This function must guarantee that all I/O read and write operations 
+ are  serialized.
+
+  If 8-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoRead8 is invoked to read the I/O port fifo.
+
+  @param  Port    The I/O port to read.
+  @param  Count   The number of times to read I/O port.
+  @param  Buffer  The buffer to store the read data into.
+
+**/
+VOID
+EFIAPI
+IoReadFifo8 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  OUT     VOID   *Buffer
+  )
+{
+  UINT8  *Buffer8;
+
+  Buffer8 = (UINT8 *)Buffer;
+  while (Count-- > 0) {
+    *Buffer8++ = IoRead8 (Port);
+  }
+}
+
+/**
+  Writes a block of memory into an 8-bit I/O port fifo.
+
+  Writes the 8-bit I/O fifo port specified by Port.
+  The port is written Count times, and the write data is  retrieved 
+ from the provided Buffer.
+
+  This function must guarantee that all I/O write and write operations 
+ are  serialized.
+
+  If 8-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoWrite8 is invoked to write data to the I/O port.
+
+  @param  Port    The I/O port to write.
+  @param  Count   The number of times to write I/O port.
+  @param  Buffer  The buffer to retrieve the write data from.
+
+**/
+VOID
+EFIAPI
+IoWriteFifo8 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  IN      VOID   *Buffer
+  )
+{
+  UINT8  *Buffer8;
+
+  Buffer8 = (UINT8 *)Buffer;
+  while (Count-- > 0) {
+    IoWrite8 (Port, *Buffer8++);
+  }
+}
+
+/**
+  Reads a 16-bit I/O port fifo into a block of memory.
+
+  Reads the 16-bit I/O fifo port specified by Port.
+  The port is read Count times, and the read data is  stored in the 
+ provided Buffer.
+
+  This function must guarantee that all I/O read and write operations 
+ are  serialized.
+
+  If 16-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoRead16 is invoked to read data from the I/O port.
+
+  @param  Port    The I/O port to read.
+  @param  Count   The number of times to read I/O port.
+  @param  Buffer  The buffer to store the read data into.
+
+**/
+VOID
+EFIAPI
+IoReadFifo16 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  OUT     VOID   *Buffer
+  )
+{
+  UINT16  *Buffer16;
+
+  Buffer16 = (UINT16 *)Buffer;
+  while (Count-- > 0) {
+    *Buffer16++ = IoRead16 (Port);
+  }
+}
+
+/**
+  Writes a block of memory into a 16-bit I/O port fifo.
+
+  Writes the 16-bit I/O fifo port specified by Port.
+  The port is written Count times, and the write data is  retrieved 
+ from the provided Buffer.
+
+  This function must guarantee that all I/O write and write operations 
+ are  serialized.
+
+  If 16-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoWrite16 is invoked to write data to the I/O port.
+
+  @param  Port    The I/O port to write.
+  @param  Count   The number of times to write I/O port.
+  @param  Buffer  The buffer to retrieve the write data from.
+
+**/
+VOID
+EFIAPI
+IoWriteFifo16 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  IN      VOID   *Buffer
+  )
+{
+  UINT16  *Buffer16;
+
+  Buffer16 = (UINT16 *)Buffer;
+  while (Count-- > 0) {
+    IoWrite16 (Port, *Buffer16++);
+  }
+}
+
+/**
+  Reads a 32-bit I/O port fifo into a block of memory.
+
+  Reads the 32-bit I/O fifo port specified by Port.
+  The port is read Count times, and the read data is  stored in the 
+ provided Buffer.
+
+  This function must guarantee that all I/O read and write operations 
+ are  serialized.
+
+  If 32-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoRead32 is invoked to read data from the I/O port.
+
+  @param  Port    The I/O port to read.
+  @param  Count   The number of times to read I/O port.
+  @param  Buffer  The buffer to store the read data into.
+
+**/
+VOID
+EFIAPI
+IoReadFifo32 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  OUT     VOID   *Buffer
+  )
+{
+  UINT32  *Buffer32;
+
+  Buffer32 = (UINT32 *)Buffer;
+  while (Count-- > 0) {
+    *Buffer32++ = IoRead32 (Port);
+  }
+}
+
+/**
+  Writes a block of memory into a 32-bit I/O port fifo.
+
+  Writes the 32-bit I/O fifo port specified by Port.
+  The port is written Count times, and the write data is  retrieved 
+ from the provided Buffer.
+
+  This function must guarantee that all I/O write and write operations 
+ are  serialized.
+
+  If 32-bit I/O port operations are not supported, then ASSERT().
+
+  In TDX a serial of TdIoWrite32 is invoked to write data to the I/O port.
+
+  @param  Port    The I/O port to write.
+  @param  Count   The number of times to write I/O port.
+  @param  Buffer  The buffer to retrieve the write data from.
+
+**/
+VOID
+EFIAPI
+IoWriteFifo32 (
+  IN      UINTN  Port,
+  IN      UINTN  Count,
+  IN      VOID   *Buffer
+  )
+{
+  UINT32  *Buffer32;
+
+  Buffer32 = (UINT32 *)Buffer;
+  while (Count-- > 0) {
+    IoWrite32 (Port, *Buffer32++);
+  }
+}
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
deleted file mode 100644
index d459072f6e..0000000000
--- a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
+++ /dev/null
@@ -1,120 +0,0 @@
-;------------------------------------------------------------------------------
-;
-; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> -; Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> -; -; SPDX-License-Identifier: BSD-2-Clause-Patent -;
-;------------------------------------------------------------------------------
-
-    DEFAULT REL
-    SECTION .text
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo8 (
-;    IN  UINTN                 Port,              // rcx
-;    IN  UINTN                 Size,              // rdx
-;    OUT VOID                  *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo8)
-ASM_PFX(IoReadFifo8):
-    cld
-    xchg    rcx, rdx
-    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
-rep insb
-    mov     rdi, r8             ; restore rdi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo16 (
-;    IN  UINTN                 Port,              // rcx
-;    IN  UINTN                 Size,              // rdx
-;    OUT VOID                  *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo16)
-ASM_PFX(IoReadFifo16):
-    cld
-    xchg    rcx, rdx
-    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
-rep insw
-    mov     rdi, r8             ; restore rdi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoReadFifo32 (
-;    IN  UINTN                 Port,              // rcx
-;    IN  UINTN                 Size,              // rdx
-;    OUT VOID                  *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoReadFifo32)
-ASM_PFX(IoReadFifo32):
-    cld
-    xchg    rcx, rdx
-    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
-rep insd
-    mov     rdi, r8             ; restore rdi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo8 (
-;    IN UINTN                  Port,              // rcx
-;    IN UINTN                  Size,              // rdx
-;    IN VOID                   *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo8)
-ASM_PFX(IoWriteFifo8):
-    cld
-    xchg    rcx, rdx
-    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
-rep outsb
-    mov     rsi, r8             ; restore rsi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo16 (
-;    IN UINTN                  Port,              // rcx
-;    IN UINTN                  Size,              // rdx
-;    IN VOID                   *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo16)
-ASM_PFX(IoWriteFifo16):
-    cld
-    xchg    rcx, rdx
-    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
-rep outsw
-    mov     rsi, r8             ; restore rsi
-    ret
-
-;------------------------------------------------------------------------------
-;  VOID
-;  EFIAPI
-;  IoWriteFifo32 (
-;    IN UINTN                  Port,              // rcx
-;    IN UINTN                  Size,              // rdx
-;    IN VOID                   *Buffer            // r8
-;    );
-;------------------------------------------------------------------------------
-global ASM_PFX(IoWriteFifo32)
-ASM_PFX(IoWriteFifo32):
-    cld
-    xchg    rcx, rdx
-    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
-rep outsd
-    mov     rsi, r8             ; restore rsi
-    ret
-
--
2.31.1.windows.1








-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112104): https://edk2.groups.io/g/devel/message/112104
Mute This Topic: https://groups.io/mt/103009916/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic
  2023-12-06  9:26   ` [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic duntan
@ 2023-12-11 17:34     ` Michael D Kinney
  2023-12-11 21:12       ` Michael D Kinney
  0 siblings, 1 reply; 10+ messages in thread
From: Michael D Kinney @ 2023-12-11 17:34 UTC (permalink / raw)
  To: Tan, Dun, devel@edk2.groups.io
  Cc: Gao, Liming, Liu, Zhiguang, Ni, Ray, Kinney, Michael D

Acked-by: Michael D Kinney <michael.d.kinney@intel.com>

Mike

> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Wednesday, December 6, 2023 1:26 AM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Ni,
> Ray <ray.ni@intel.com>
> Subject: RE: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in
> BaseIoLibIntrinsic
> 
> Hi Mike and Liming,
> 
> Could you please help to review this patch?
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
> Sent: Thursday, November 9, 2023 10:50 AM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>; Ni,
> Ray <ray.ni@intel.com>
> Subject: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in
> BaseIoLibIntrinsic
> 
> Simplify IoRead/WriteFifo implement by repeatedly calling IoRead/Write
> in the C code.
> This can avoid calling assembly code to use string I/O instructions.
> With this change Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed.
> Then the source files for IA32 and X64 are the same.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> ---
>  MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf |  10 ++------
> --
>  MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm       | 131 --------
> ------------------------------------------------------------------------
> ---------------------------------------------------
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c            | 220
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++
>  MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm        | 120 --------
> ------------------------------------------------------------------------
> ----------------------------------------
>  4 files changed, 222 insertions(+), 259 deletions(-)
> 
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> index aeb072ee95..b587e2cded 100644
> --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> @@ -38,17 +38,11 @@
>    IoLibInternalTdxNull.c
>    IoLibTdx.h
> 
> -[Sources.IA32]
> +[Sources.IA32, Sources.X64]
>    IoLibGcc.c    | GCC
>    IoLibMsc.c    | MSFT
>    IoLib.c
> -  Ia32/IoFifo.nasm
> -
> -[Sources.X64]
> -  IoLibGcc.c    | GCC
> -  IoLibMsc.c    | MSFT
> -  IoLib.c
> -  X64/IoFifo.nasm
> +  IoLibFifo.c
> 
>  [Sources.EBC]
>    IoLibEbc.c
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
> b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
> deleted file mode 100644
> index a4ae1a0053..0000000000
> --- a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
> +++ /dev/null
> @@ -1,131 +0,0 @@
> -;----------------------------------------------------------------------
> --------
> -;
> -; Copyright (c) 2006 - 2012, Intel Corporation. All rights
> reserved.<BR> -; Copyright (c) 2017, AMD Incorporated. All rights
> reserved.<BR> -; -; SPDX-License-Identifier: BSD-2-Clause-Patent -;
> -;----------------------------------------------------------------------
> --------
> -
> -    SECTION .text
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoReadFifo8 (
> -;    IN  UINTN                 Port,
> -;    IN  UINTN                 Size,
> -;    OUT VOID                  *Buffer
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoReadFifo8)
> -ASM_PFX(IoReadFifo8):
> -    push    edi
> -    cld
> -    mov     dx, [esp + 8]
> -    mov     ecx, [esp + 12]
> -    mov     edi, [esp + 16]
> -rep insb
> -    pop     edi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoReadFifo16 (
> -;    IN  UINTN                 Port,
> -;    IN  UINTN                 Size,
> -;    OUT VOID                  *Buffer
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoReadFifo16)
> -ASM_PFX(IoReadFifo16):
> -    push    edi
> -    cld
> -    mov     dx, [esp + 8]
> -    mov     ecx, [esp + 12]
> -    mov     edi, [esp + 16]
> -rep insw
> -    pop     edi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoReadFifo32 (
> -;    IN  UINTN                 Port,
> -;    IN  UINTN                 Size,
> -;    OUT VOID                  *Buffer
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoReadFifo32)
> -ASM_PFX(IoReadFifo32):
> -    push    edi
> -    cld
> -    mov     dx, [esp + 8]
> -    mov     ecx, [esp + 12]
> -    mov     edi, [esp + 16]
> -rep insd
> -    pop     edi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoWriteFifo8 (
> -;    IN UINTN                  Port,
> -;    IN UINTN                  Size,
> -;    IN VOID                   *Buffer
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoWriteFifo8)
> -ASM_PFX(IoWriteFifo8):
> -    push    esi
> -    cld
> -    mov     dx, [esp + 8]
> -    mov     ecx, [esp + 12]
> -    mov     esi, [esp + 16]
> -rep outsb
> -    pop     esi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoWriteFifo16 (
> -;    IN UINTN                  Port,
> -;    IN UINTN                  Size,
> -;    IN VOID                   *Buffer
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoWriteFifo16)
> -ASM_PFX(IoWriteFifo16):
> -    push    esi
> -    cld
> -    mov     dx, [esp + 8]
> -    mov     ecx, [esp + 12]
> -    mov     esi, [esp + 16]
> -rep outsw
> -    pop     esi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoWriteFifo32 (
> -;    IN UINTN                  Port,
> -;    IN UINTN                  Size,
> -;    IN VOID                   *Buffer
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoWriteFifo32)
> -ASM_PFX(IoWriteFifo32):
> -    push    esi
> -    cld
> -    mov     dx, [esp + 8]
> -    mov     ecx, [esp + 12]
> -    mov     esi, [esp + 16]
> -rep outsd
> -    pop     esi
> -    ret
> -
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
> b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
> new file mode 100644
> index 0000000000..bd1d372d0f
> --- /dev/null
> +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
> @@ -0,0 +1,220 @@
> +/** @file
> +  IoFifo read/write routines.
> +
> +  Copyright (c) 2021 - 2023, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include "BaseIoLibIntrinsicInternal.h"
> +#include <Uefi/UefiBaseType.h>
> +
> +/**
> +  Reads an 8-bit I/O port fifo into a block of memory.
> +
> +  Reads the 8-bit I/O fifo port specified by Port.
> +  The port is read Count times, and the read data is  stored in the
> + provided Buffer.
> +
> +  This function must guarantee that all I/O read and write operations
> + are  serialized.
> +
> +  If 8-bit I/O port operations are not supported, then ASSERT().
> +
> +  In TDX a serial of TdIoRead8 is invoked to read the I/O port fifo.
> +
> +  @param  Port    The I/O port to read.
> +  @param  Count   The number of times to read I/O port.
> +  @param  Buffer  The buffer to store the read data into.
> +
> +**/
> +VOID
> +EFIAPI
> +IoReadFifo8 (
> +  IN      UINTN  Port,
> +  IN      UINTN  Count,
> +  OUT     VOID   *Buffer
> +  )
> +{
> +  UINT8  *Buffer8;
> +
> +  Buffer8 = (UINT8 *)Buffer;
> +  while (Count-- > 0) {
> +    *Buffer8++ = IoRead8 (Port);
> +  }
> +}
> +
> +/**
> +  Writes a block of memory into an 8-bit I/O port fifo.
> +
> +  Writes the 8-bit I/O fifo port specified by Port.
> +  The port is written Count times, and the write data is  retrieved
> + from the provided Buffer.
> +
> +  This function must guarantee that all I/O write and write operations
> + are  serialized.
> +
> +  If 8-bit I/O port operations are not supported, then ASSERT().
> +
> +  In TDX a serial of TdIoWrite8 is invoked to write data to the I/O
> port.
> +
> +  @param  Port    The I/O port to write.
> +  @param  Count   The number of times to write I/O port.
> +  @param  Buffer  The buffer to retrieve the write data from.
> +
> +**/
> +VOID
> +EFIAPI
> +IoWriteFifo8 (
> +  IN      UINTN  Port,
> +  IN      UINTN  Count,
> +  IN      VOID   *Buffer
> +  )
> +{
> +  UINT8  *Buffer8;
> +
> +  Buffer8 = (UINT8 *)Buffer;
> +  while (Count-- > 0) {
> +    IoWrite8 (Port, *Buffer8++);
> +  }
> +}
> +
> +/**
> +  Reads a 16-bit I/O port fifo into a block of memory.
> +
> +  Reads the 16-bit I/O fifo port specified by Port.
> +  The port is read Count times, and the read data is  stored in the
> + provided Buffer.
> +
> +  This function must guarantee that all I/O read and write operations
> + are  serialized.
> +
> +  If 16-bit I/O port operations are not supported, then ASSERT().
> +
> +  In TDX a serial of TdIoRead16 is invoked to read data from the I/O
> port.
> +
> +  @param  Port    The I/O port to read.
> +  @param  Count   The number of times to read I/O port.
> +  @param  Buffer  The buffer to store the read data into.
> +
> +**/
> +VOID
> +EFIAPI
> +IoReadFifo16 (
> +  IN      UINTN  Port,
> +  IN      UINTN  Count,
> +  OUT     VOID   *Buffer
> +  )
> +{
> +  UINT16  *Buffer16;
> +
> +  Buffer16 = (UINT16 *)Buffer;
> +  while (Count-- > 0) {
> +    *Buffer16++ = IoRead16 (Port);
> +  }
> +}
> +
> +/**
> +  Writes a block of memory into a 16-bit I/O port fifo.
> +
> +  Writes the 16-bit I/O fifo port specified by Port.
> +  The port is written Count times, and the write data is  retrieved
> + from the provided Buffer.
> +
> +  This function must guarantee that all I/O write and write operations
> + are  serialized.
> +
> +  If 16-bit I/O port operations are not supported, then ASSERT().
> +
> +  In TDX a serial of TdIoWrite16 is invoked to write data to the I/O
> port.
> +
> +  @param  Port    The I/O port to write.
> +  @param  Count   The number of times to write I/O port.
> +  @param  Buffer  The buffer to retrieve the write data from.
> +
> +**/
> +VOID
> +EFIAPI
> +IoWriteFifo16 (
> +  IN      UINTN  Port,
> +  IN      UINTN  Count,
> +  IN      VOID   *Buffer
> +  )
> +{
> +  UINT16  *Buffer16;
> +
> +  Buffer16 = (UINT16 *)Buffer;
> +  while (Count-- > 0) {
> +    IoWrite16 (Port, *Buffer16++);
> +  }
> +}
> +
> +/**
> +  Reads a 32-bit I/O port fifo into a block of memory.
> +
> +  Reads the 32-bit I/O fifo port specified by Port.
> +  The port is read Count times, and the read data is  stored in the
> + provided Buffer.
> +
> +  This function must guarantee that all I/O read and write operations
> + are  serialized.
> +
> +  If 32-bit I/O port operations are not supported, then ASSERT().
> +
> +  In TDX a serial of TdIoRead32 is invoked to read data from the I/O
> port.
> +
> +  @param  Port    The I/O port to read.
> +  @param  Count   The number of times to read I/O port.
> +  @param  Buffer  The buffer to store the read data into.
> +
> +**/
> +VOID
> +EFIAPI
> +IoReadFifo32 (
> +  IN      UINTN  Port,
> +  IN      UINTN  Count,
> +  OUT     VOID   *Buffer
> +  )
> +{
> +  UINT32  *Buffer32;
> +
> +  Buffer32 = (UINT32 *)Buffer;
> +  while (Count-- > 0) {
> +    *Buffer32++ = IoRead32 (Port);
> +  }
> +}
> +
> +/**
> +  Writes a block of memory into a 32-bit I/O port fifo.
> +
> +  Writes the 32-bit I/O fifo port specified by Port.
> +  The port is written Count times, and the write data is  retrieved
> + from the provided Buffer.
> +
> +  This function must guarantee that all I/O write and write operations
> + are  serialized.
> +
> +  If 32-bit I/O port operations are not supported, then ASSERT().
> +
> +  In TDX a serial of TdIoWrite32 is invoked to write data to the I/O
> port.
> +
> +  @param  Port    The I/O port to write.
> +  @param  Count   The number of times to write I/O port.
> +  @param  Buffer  The buffer to retrieve the write data from.
> +
> +**/
> +VOID
> +EFIAPI
> +IoWriteFifo32 (
> +  IN      UINTN  Port,
> +  IN      UINTN  Count,
> +  IN      VOID   *Buffer
> +  )
> +{
> +  UINT32  *Buffer32;
> +
> +  Buffer32 = (UINT32 *)Buffer;
> +  while (Count-- > 0) {
> +    IoWrite32 (Port, *Buffer32++);
> +  }
> +}
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> deleted file mode 100644
> index d459072f6e..0000000000
> --- a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> +++ /dev/null
> @@ -1,120 +0,0 @@
> -;----------------------------------------------------------------------
> --------
> -;
> -; Copyright (c) 2006 - 2012, Intel Corporation. All rights
> reserved.<BR> -; Copyright (c) 2017, AMD Incorporated. All rights
> reserved.<BR> -; -; SPDX-License-Identifier: BSD-2-Clause-Patent -;
> -;----------------------------------------------------------------------
> --------
> -
> -    DEFAULT REL
> -    SECTION .text
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoReadFifo8 (
> -;    IN  UINTN                 Port,              // rcx
> -;    IN  UINTN                 Size,              // rdx
> -;    OUT VOID                  *Buffer            // r8
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoReadFifo8)
> -ASM_PFX(IoReadFifo8):
> -    cld
> -    xchg    rcx, rdx
> -    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
> -rep insb
> -    mov     rdi, r8             ; restore rdi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoReadFifo16 (
> -;    IN  UINTN                 Port,              // rcx
> -;    IN  UINTN                 Size,              // rdx
> -;    OUT VOID                  *Buffer            // r8
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoReadFifo16)
> -ASM_PFX(IoReadFifo16):
> -    cld
> -    xchg    rcx, rdx
> -    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
> -rep insw
> -    mov     rdi, r8             ; restore rdi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoReadFifo32 (
> -;    IN  UINTN                 Port,              // rcx
> -;    IN  UINTN                 Size,              // rdx
> -;    OUT VOID                  *Buffer            // r8
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoReadFifo32)
> -ASM_PFX(IoReadFifo32):
> -    cld
> -    xchg    rcx, rdx
> -    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
> -rep insd
> -    mov     rdi, r8             ; restore rdi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoWriteFifo8 (
> -;    IN UINTN                  Port,              // rcx
> -;    IN UINTN                  Size,              // rdx
> -;    IN VOID                   *Buffer            // r8
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoWriteFifo8)
> -ASM_PFX(IoWriteFifo8):
> -    cld
> -    xchg    rcx, rdx
> -    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
> -rep outsb
> -    mov     rsi, r8             ; restore rsi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoWriteFifo16 (
> -;    IN UINTN                  Port,              // rcx
> -;    IN UINTN                  Size,              // rdx
> -;    IN VOID                   *Buffer            // r8
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoWriteFifo16)
> -ASM_PFX(IoWriteFifo16):
> -    cld
> -    xchg    rcx, rdx
> -    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
> -rep outsw
> -    mov     rsi, r8             ; restore rsi
> -    ret
> -
> -;----------------------------------------------------------------------
> --------
> -;  VOID
> -;  EFIAPI
> -;  IoWriteFifo32 (
> -;    IN UINTN                  Port,              // rcx
> -;    IN UINTN                  Size,              // rdx
> -;    IN VOID                   *Buffer            // r8
> -;    );
> -;----------------------------------------------------------------------
> --------
> -global ASM_PFX(IoWriteFifo32)
> -ASM_PFX(IoWriteFifo32):
> -    cld
> -    xchg    rcx, rdx
> -    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
> -rep outsd
> -    mov     rsi, r8             ; restore rsi
> -    ret
> -
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112324): https://edk2.groups.io/g/devel/message/112324
Mute This Topic: https://groups.io/mt/103009916/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

* Re: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic
  2023-12-11 17:34     ` Michael D Kinney
@ 2023-12-11 21:12       ` Michael D Kinney
  0 siblings, 0 replies; 10+ messages in thread
From: Michael D Kinney @ 2023-12-11 21:12 UTC (permalink / raw)
  To: Tan, Dun, devel@edk2.groups.io
  Cc: Gao, Liming, Liu, Zhiguang, Ni, Ray, Kinney, Michael D

Merged: https://github.com/tianocore/edk2/pull/5138

> -----Original Message-----
> From: Kinney, Michael D <michael.d.kinney@intel.com>
> Sent: Monday, December 11, 2023 9:34 AM
> To: Tan, Dun <dun.tan@intel.com>; devel@edk2.groups.io
> Cc: Gao, Liming <gaoliming@byosoft.com.cn>; Liu, Zhiguang
> <zhiguang.liu@intel.com>; Ni, Ray <ray.ni@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>
> Subject: RE: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in
> BaseIoLibIntrinsic
> 
> Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
> 
> Mike
> 
> > -----Original Message-----
> > From: Tan, Dun <dun.tan@intel.com>
> > Sent: Wednesday, December 6, 2023 1:26 AM
> > To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> Ni,
> > Ray <ray.ni@intel.com>
> > Subject: RE: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in
> > BaseIoLibIntrinsic
> >
> > Hi Mike and Liming,
> >
> > Could you please help to review this patch?
> >
> > Thanks,
> > Dun
> >
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
> > Sent: Thursday, November 9, 2023 10:50 AM
> > To: devel@edk2.groups.io
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> Ni,
> > Ray <ray.ni@intel.com>
> > Subject: [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in
> > BaseIoLibIntrinsic
> >
> > Simplify IoRead/WriteFifo implement by repeatedly calling IoRead/Write
> > in the C code.
> > This can avoid calling assembly code to use string I/O instructions.
> > With this change Ia32/IoFifo.nasm and X64/IoFifo.nasm can be removed.
> > Then the source files for IA32 and X64 are the same.
> >
> > Signed-off-by: Dun Tan <dun.tan@intel.com>
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > ---
> >  MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf |  10 ++----
> --
> > --
> >  MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm       | 131 ------
> --
> > ----------------------------------------------------------------------
> --
> > ---------------------------------------------------
> >  MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c            | 220
> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > ++++
> >  MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm        | 120 ------
> --
> > ----------------------------------------------------------------------
> --
> > ----------------------------------------
> >  4 files changed, 222 insertions(+), 259 deletions(-)
> >
> > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> > b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> > index aeb072ee95..b587e2cded 100644
> > --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> > +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> > @@ -38,17 +38,11 @@
> >    IoLibInternalTdxNull.c
> >    IoLibTdx.h
> >
> > -[Sources.IA32]
> > +[Sources.IA32, Sources.X64]
> >    IoLibGcc.c    | GCC
> >    IoLibMsc.c    | MSFT
> >    IoLib.c
> > -  Ia32/IoFifo.nasm
> > -
> > -[Sources.X64]
> > -  IoLibGcc.c    | GCC
> > -  IoLibMsc.c    | MSFT
> > -  IoLib.c
> > -  X64/IoFifo.nasm
> > +  IoLibFifo.c
> >
> >  [Sources.EBC]
> >    IoLibEbc.c
> > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
> > b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
> > deleted file mode 100644
> > index a4ae1a0053..0000000000
> > --- a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifo.nasm
> > +++ /dev/null
> > @@ -1,131 +0,0 @@
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;
> > -; Copyright (c) 2006 - 2012, Intel Corporation. All rights
> > reserved.<BR> -; Copyright (c) 2017, AMD Incorporated. All rights
> > reserved.<BR> -; -; SPDX-License-Identifier: BSD-2-Clause-Patent -;
> > -;--------------------------------------------------------------------
> --
> > --------
> > -
> > -    SECTION .text
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoReadFifo8 (
> > -;    IN  UINTN                 Port,
> > -;    IN  UINTN                 Size,
> > -;    OUT VOID                  *Buffer
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoReadFifo8)
> > -ASM_PFX(IoReadFifo8):
> > -    push    edi
> > -    cld
> > -    mov     dx, [esp + 8]
> > -    mov     ecx, [esp + 12]
> > -    mov     edi, [esp + 16]
> > -rep insb
> > -    pop     edi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoReadFifo16 (
> > -;    IN  UINTN                 Port,
> > -;    IN  UINTN                 Size,
> > -;    OUT VOID                  *Buffer
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoReadFifo16)
> > -ASM_PFX(IoReadFifo16):
> > -    push    edi
> > -    cld
> > -    mov     dx, [esp + 8]
> > -    mov     ecx, [esp + 12]
> > -    mov     edi, [esp + 16]
> > -rep insw
> > -    pop     edi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoReadFifo32 (
> > -;    IN  UINTN                 Port,
> > -;    IN  UINTN                 Size,
> > -;    OUT VOID                  *Buffer
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoReadFifo32)
> > -ASM_PFX(IoReadFifo32):
> > -    push    edi
> > -    cld
> > -    mov     dx, [esp + 8]
> > -    mov     ecx, [esp + 12]
> > -    mov     edi, [esp + 16]
> > -rep insd
> > -    pop     edi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoWriteFifo8 (
> > -;    IN UINTN                  Port,
> > -;    IN UINTN                  Size,
> > -;    IN VOID                   *Buffer
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoWriteFifo8)
> > -ASM_PFX(IoWriteFifo8):
> > -    push    esi
> > -    cld
> > -    mov     dx, [esp + 8]
> > -    mov     ecx, [esp + 12]
> > -    mov     esi, [esp + 16]
> > -rep outsb
> > -    pop     esi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoWriteFifo16 (
> > -;    IN UINTN                  Port,
> > -;    IN UINTN                  Size,
> > -;    IN VOID                   *Buffer
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoWriteFifo16)
> > -ASM_PFX(IoWriteFifo16):
> > -    push    esi
> > -    cld
> > -    mov     dx, [esp + 8]
> > -    mov     ecx, [esp + 12]
> > -    mov     esi, [esp + 16]
> > -rep outsw
> > -    pop     esi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoWriteFifo32 (
> > -;    IN UINTN                  Port,
> > -;    IN UINTN                  Size,
> > -;    IN VOID                   *Buffer
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoWriteFifo32)
> > -ASM_PFX(IoWriteFifo32):
> > -    push    esi
> > -    cld
> > -    mov     dx, [esp + 8]
> > -    mov     ecx, [esp + 12]
> > -    mov     esi, [esp + 16]
> > -rep outsd
> > -    pop     esi
> > -    ret
> > -
> > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
> > b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
> > new file mode 100644
> > index 0000000000..bd1d372d0f
> > --- /dev/null
> > +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibFifo.c
> > @@ -0,0 +1,220 @@
> > +/** @file
> > +  IoFifo read/write routines.
> > +
> > +  Copyright (c) 2021 - 2023, Intel Corporation. All rights
> > + reserved.<BR>
> > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#include "BaseIoLibIntrinsicInternal.h"
> > +#include <Uefi/UefiBaseType.h>
> > +
> > +/**
> > +  Reads an 8-bit I/O port fifo into a block of memory.
> > +
> > +  Reads the 8-bit I/O fifo port specified by Port.
> > +  The port is read Count times, and the read data is  stored in the
> > + provided Buffer.
> > +
> > +  This function must guarantee that all I/O read and write operations
> > + are  serialized.
> > +
> > +  If 8-bit I/O port operations are not supported, then ASSERT().
> > +
> > +  In TDX a serial of TdIoRead8 is invoked to read the I/O port fifo.
> > +
> > +  @param  Port    The I/O port to read.
> > +  @param  Count   The number of times to read I/O port.
> > +  @param  Buffer  The buffer to store the read data into.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +IoReadFifo8 (
> > +  IN      UINTN  Port,
> > +  IN      UINTN  Count,
> > +  OUT     VOID   *Buffer
> > +  )
> > +{
> > +  UINT8  *Buffer8;
> > +
> > +  Buffer8 = (UINT8 *)Buffer;
> > +  while (Count-- > 0) {
> > +    *Buffer8++ = IoRead8 (Port);
> > +  }
> > +}
> > +
> > +/**
> > +  Writes a block of memory into an 8-bit I/O port fifo.
> > +
> > +  Writes the 8-bit I/O fifo port specified by Port.
> > +  The port is written Count times, and the write data is  retrieved
> > + from the provided Buffer.
> > +
> > +  This function must guarantee that all I/O write and write
> operations
> > + are  serialized.
> > +
> > +  If 8-bit I/O port operations are not supported, then ASSERT().
> > +
> > +  In TDX a serial of TdIoWrite8 is invoked to write data to the I/O
> > port.
> > +
> > +  @param  Port    The I/O port to write.
> > +  @param  Count   The number of times to write I/O port.
> > +  @param  Buffer  The buffer to retrieve the write data from.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +IoWriteFifo8 (
> > +  IN      UINTN  Port,
> > +  IN      UINTN  Count,
> > +  IN      VOID   *Buffer
> > +  )
> > +{
> > +  UINT8  *Buffer8;
> > +
> > +  Buffer8 = (UINT8 *)Buffer;
> > +  while (Count-- > 0) {
> > +    IoWrite8 (Port, *Buffer8++);
> > +  }
> > +}
> > +
> > +/**
> > +  Reads a 16-bit I/O port fifo into a block of memory.
> > +
> > +  Reads the 16-bit I/O fifo port specified by Port.
> > +  The port is read Count times, and the read data is  stored in the
> > + provided Buffer.
> > +
> > +  This function must guarantee that all I/O read and write operations
> > + are  serialized.
> > +
> > +  If 16-bit I/O port operations are not supported, then ASSERT().
> > +
> > +  In TDX a serial of TdIoRead16 is invoked to read data from the I/O
> > port.
> > +
> > +  @param  Port    The I/O port to read.
> > +  @param  Count   The number of times to read I/O port.
> > +  @param  Buffer  The buffer to store the read data into.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +IoReadFifo16 (
> > +  IN      UINTN  Port,
> > +  IN      UINTN  Count,
> > +  OUT     VOID   *Buffer
> > +  )
> > +{
> > +  UINT16  *Buffer16;
> > +
> > +  Buffer16 = (UINT16 *)Buffer;
> > +  while (Count-- > 0) {
> > +    *Buffer16++ = IoRead16 (Port);
> > +  }
> > +}
> > +
> > +/**
> > +  Writes a block of memory into a 16-bit I/O port fifo.
> > +
> > +  Writes the 16-bit I/O fifo port specified by Port.
> > +  The port is written Count times, and the write data is  retrieved
> > + from the provided Buffer.
> > +
> > +  This function must guarantee that all I/O write and write
> operations
> > + are  serialized.
> > +
> > +  If 16-bit I/O port operations are not supported, then ASSERT().
> > +
> > +  In TDX a serial of TdIoWrite16 is invoked to write data to the I/O
> > port.
> > +
> > +  @param  Port    The I/O port to write.
> > +  @param  Count   The number of times to write I/O port.
> > +  @param  Buffer  The buffer to retrieve the write data from.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +IoWriteFifo16 (
> > +  IN      UINTN  Port,
> > +  IN      UINTN  Count,
> > +  IN      VOID   *Buffer
> > +  )
> > +{
> > +  UINT16  *Buffer16;
> > +
> > +  Buffer16 = (UINT16 *)Buffer;
> > +  while (Count-- > 0) {
> > +    IoWrite16 (Port, *Buffer16++);
> > +  }
> > +}
> > +
> > +/**
> > +  Reads a 32-bit I/O port fifo into a block of memory.
> > +
> > +  Reads the 32-bit I/O fifo port specified by Port.
> > +  The port is read Count times, and the read data is  stored in the
> > + provided Buffer.
> > +
> > +  This function must guarantee that all I/O read and write operations
> > + are  serialized.
> > +
> > +  If 32-bit I/O port operations are not supported, then ASSERT().
> > +
> > +  In TDX a serial of TdIoRead32 is invoked to read data from the I/O
> > port.
> > +
> > +  @param  Port    The I/O port to read.
> > +  @param  Count   The number of times to read I/O port.
> > +  @param  Buffer  The buffer to store the read data into.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +IoReadFifo32 (
> > +  IN      UINTN  Port,
> > +  IN      UINTN  Count,
> > +  OUT     VOID   *Buffer
> > +  )
> > +{
> > +  UINT32  *Buffer32;
> > +
> > +  Buffer32 = (UINT32 *)Buffer;
> > +  while (Count-- > 0) {
> > +    *Buffer32++ = IoRead32 (Port);
> > +  }
> > +}
> > +
> > +/**
> > +  Writes a block of memory into a 32-bit I/O port fifo.
> > +
> > +  Writes the 32-bit I/O fifo port specified by Port.
> > +  The port is written Count times, and the write data is  retrieved
> > + from the provided Buffer.
> > +
> > +  This function must guarantee that all I/O write and write
> operations
> > + are  serialized.
> > +
> > +  If 32-bit I/O port operations are not supported, then ASSERT().
> > +
> > +  In TDX a serial of TdIoWrite32 is invoked to write data to the I/O
> > port.
> > +
> > +  @param  Port    The I/O port to write.
> > +  @param  Count   The number of times to write I/O port.
> > +  @param  Buffer  The buffer to retrieve the write data from.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +IoWriteFifo32 (
> > +  IN      UINTN  Port,
> > +  IN      UINTN  Count,
> > +  IN      VOID   *Buffer
> > +  )
> > +{
> > +  UINT32  *Buffer32;
> > +
> > +  Buffer32 = (UINT32 *)Buffer;
> > +  while (Count-- > 0) {
> > +    IoWrite32 (Port, *Buffer32++);
> > +  }
> > +}
> > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> > b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> > deleted file mode 100644
> > index d459072f6e..0000000000
> > --- a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifo.nasm
> > +++ /dev/null
> > @@ -1,120 +0,0 @@
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;
> > -; Copyright (c) 2006 - 2012, Intel Corporation. All rights
> > reserved.<BR> -; Copyright (c) 2017, AMD Incorporated. All rights
> > reserved.<BR> -; -; SPDX-License-Identifier: BSD-2-Clause-Patent -;
> > -;--------------------------------------------------------------------
> --
> > --------
> > -
> > -    DEFAULT REL
> > -    SECTION .text
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoReadFifo8 (
> > -;    IN  UINTN                 Port,              // rcx
> > -;    IN  UINTN                 Size,              // rdx
> > -;    OUT VOID                  *Buffer            // r8
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoReadFifo8)
> > -ASM_PFX(IoReadFifo8):
> > -    cld
> > -    xchg    rcx, rdx
> > -    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
> > -rep insb
> > -    mov     rdi, r8             ; restore rdi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoReadFifo16 (
> > -;    IN  UINTN                 Port,              // rcx
> > -;    IN  UINTN                 Size,              // rdx
> > -;    OUT VOID                  *Buffer            // r8
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoReadFifo16)
> > -ASM_PFX(IoReadFifo16):
> > -    cld
> > -    xchg    rcx, rdx
> > -    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
> > -rep insw
> > -    mov     rdi, r8             ; restore rdi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoReadFifo32 (
> > -;    IN  UINTN                 Port,              // rcx
> > -;    IN  UINTN                 Size,              // rdx
> > -;    OUT VOID                  *Buffer            // r8
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoReadFifo32)
> > -ASM_PFX(IoReadFifo32):
> > -    cld
> > -    xchg    rcx, rdx
> > -    xchg    rdi, r8             ; rdi: buffer address; r8: save rdi
> > -rep insd
> > -    mov     rdi, r8             ; restore rdi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoWriteFifo8 (
> > -;    IN UINTN                  Port,              // rcx
> > -;    IN UINTN                  Size,              // rdx
> > -;    IN VOID                   *Buffer            // r8
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoWriteFifo8)
> > -ASM_PFX(IoWriteFifo8):
> > -    cld
> > -    xchg    rcx, rdx
> > -    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
> > -rep outsb
> > -    mov     rsi, r8             ; restore rsi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoWriteFifo16 (
> > -;    IN UINTN                  Port,              // rcx
> > -;    IN UINTN                  Size,              // rdx
> > -;    IN VOID                   *Buffer            // r8
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoWriteFifo16)
> > -ASM_PFX(IoWriteFifo16):
> > -    cld
> > -    xchg    rcx, rdx
> > -    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
> > -rep outsw
> > -    mov     rsi, r8             ; restore rsi
> > -    ret
> > -
> > -;--------------------------------------------------------------------
> --
> > --------
> > -;  VOID
> > -;  EFIAPI
> > -;  IoWriteFifo32 (
> > -;    IN UINTN                  Port,              // rcx
> > -;    IN UINTN                  Size,              // rdx
> > -;    IN VOID                   *Buffer            // r8
> > -;    );
> > -;--------------------------------------------------------------------
> --
> > --------
> > -global ASM_PFX(IoWriteFifo32)
> > -ASM_PFX(IoWriteFifo32):
> > -    cld
> > -    xchg    rcx, rdx
> > -    xchg    rsi, r8             ; rsi: buffer address; r8: save rsi
> > -rep outsd
> > -    mov     rsi, r8             ; restore rsi
> > -    ret
> > -
> > --
> > 2.31.1.windows.1
> >
> >
> >
> > 
> >



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112327): https://edk2.groups.io/g/devel/message/112327
Mute This Topic: https://groups.io/mt/103009916/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



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

end of thread, other threads:[~2023-12-11 21:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-09  2:49 [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf duntan
2023-11-09  2:49 ` [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c duntan
2023-11-09  2:49 ` [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic duntan
2023-11-09  5:56 ` [edk2-devel] [PATCH 0/2] Remove string IO instruction in BaseIoLibIntrinsic.inf Ni, Ray
2023-11-13 13:07   ` Laszlo Ersek
2023-11-27 10:14     ` duntan
     [not found] ` <1795D4A7BE9E02F3.6123@groups.io>
2023-12-06  9:25   ` [edk2-devel] [PATCH 1/2] MdePkg: Change IoLibFifo.c to IoLibFifoCc.c duntan
     [not found] ` <1795D4A7D7819C64.15940@groups.io>
2023-12-06  9:26   ` [edk2-devel] [PATCH 2/2] MdePkg:simplify Fifo API in BaseIoLibIntrinsic duntan
2023-12-11 17:34     ` Michael D Kinney
2023-12-11 21:12       ` Michael D Kinney

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