public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
@ 2016-10-14  9:33 Bhupesh Sharma
  2016-10-14 12:06 ` Laszlo Ersek
  2016-10-17  3:10 ` Gao, Liming
  0 siblings, 2 replies; 25+ messages in thread
From: Bhupesh Sharma @ 2016-10-14  9:33 UTC (permalink / raw)
  To: edk2-devel

Various IPs on NXP/FSL SoCs having ARM64 cores have big-endian
MMIO interfaces.

This implies that a byte-swap operation is needed to read/write
such BE MMIO registers from the LE ARM64 cores.

This patch adds the support for the same.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
Signed-off-by: Bhupesh Sharma <bhupesh.sharma@nxp.com>
---
 MdePkg/Include/Library/IoLib.h               | 364 ++++++++++++++++++++
 MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c | 479 +++++++++++++++++++++++++++
 2 files changed, 843 insertions(+)

diff --git a/MdePkg/Include/Library/IoLib.h b/MdePkg/Include/Library/IoLib.h
index a0dd16b..f5842e6 100644
--- a/MdePkg/Include/Library/IoLib.h
+++ b/MdePkg/Include/Library/IoLib.h
@@ -2658,6 +2658,370 @@ MmioWriteBuffer64 (
   IN  CONST UINT64 *Buffer
   );
 
+/**
+  Reads a 16-bit MMIO register in Big Endian format.
+
+  Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
+  returned. This function must guarantee that all MMIO read and write
+  operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to read.
+
+  @return The value read.
+
+**/
+UINT16
+EFIAPI
+MmioReadBe16 (
+  IN      UINTN                     Address
+  );
+
+/**
+  Writes a 16-bit MMIO register in Big Endian format.
+
+  Writes the 16-bit MMIO register specified by Address with the value specified
+  by Value and returns Value. This function must guarantee that all MMIO read
+  and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioWriteBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Value
+  );
+
+/**
+  Reads a 32-bit MMIO register in Big Endian format.
+
+  Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
+  returned. This function must guarantee that all MMIO read and write
+  operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to read.
+
+  @return The value read.
+
+**/
+UINT32
+EFIAPI
+MmioReadBe32 (
+  IN      UINTN                     Address
+  );
+
+/**
+  Writes a 32-bit MMIO register in Big Endian format.
+
+  Writes the 32-bit MMIO register specified by Address with the value specified
+  by Value and returns Value. This function must guarantee that all MMIO read
+  and write operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioWriteBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Value
+  );
+
+
+/**
+  Reads a 64-bit MMIO register in Big Endian format.
+
+  Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
+  returned. This function must guarantee that all MMIO read and write
+  operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to read.
+
+  @return The value read.
+
+**/
+UINT64
+EFIAPI
+MmioReadBe64 (
+  IN      UINTN                     Address
+  );
+
+
+/**
+  Writes a 64-bit MMIO register in Big Endian format.
+
+  Writes the 64-bit MMIO register specified by Address with the value specified
+  by Value and returns Value. This function must guarantee that all MMIO read
+  and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioWriteBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Value
+  );
+
+/**
+  Clear and set a 8-bit MMIO register.
+
+  Mask the 8-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 8-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT8
+EFIAPI
+MmioClearSet8 (
+  IN      UINTN                    Address,
+  IN      UINT8                    Mask,
+  IN      UINT8                    Value
+  );
+
+/**
+  Clear and set a 16-bit MMIO register in Big Endian format.
+
+  Mask the 16-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 16-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioClearSetBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Mask,
+  IN      UINT16                    Value
+  );
+
+/**
+  Clear and set a 32-bit MMIO register in Big Endian format.
+
+  Mask the 32-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 32-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioClearSetBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Mask,
+  IN      UINT32                    Value
+  );
+
+/**
+  Clear and set a 64-bit MMIO register in Big Endian format.
+
+  Mask the 64-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 64-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioClearSetBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Mask,
+  IN      UINT64                    Value
+  );
+
+/**
+  Set a 8-bit MMIO register in Big Endian format.
+
+  Set bits of the 8-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 8-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT8
+EFIAPI
+MmioSetBits8 (
+  IN      UINTN                     Address,
+  IN      UINT8                     Bits
+  );
+
+/**
+  Set a 16-bit MMIO register in Big Endian format.
+
+  Set bits of the 16-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioSetBitsBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Bits
+  );
+
+/**
+  Set a 32-bit MMIO register in Big Endian format.
+
+  Set bits of the 32-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioSetBitsBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Bits
+  );
+
+/**
+  Set a 64-bit MMIO register in Big Endian format.
+
+  Set bits of the 64-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioSetBitsBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Bits
+  );
+
+/**
+  Clear bits of the 8-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 8-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT8
+EFIAPI
+MmioClearBits8 (
+  IN      UINTN                     Address,
+  IN      UINT8                     Mask
+  );
+
+/**
+  Clear bits of the 16-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioClearBitsBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Mask
+  );
+
+/**
+  Clear bits of the 32-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioClearBitsBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Mask
+  );
+
+/**
+  Clear bits of the 64-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioClearBitsBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Mask
+  );
 
 #endif
 
diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
index b9f4c5e..f2179d1 100644
--- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
+++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
@@ -19,6 +19,26 @@
 //
 #include "BaseIoLibIntrinsicInternal.h"
 
+
+#define Uswap16(X) \
+       ((((X) & 0xff00) >> 8) | \
+        (((X) & 0x00ff) << 8))
+#define Uswap32(X) \
+       ((((X) & 0xff000000) >> 24) | \
+        (((X) & 0x00ff0000) >>  8) | \
+        (((X) & 0x0000ff00) <<  8) | \
+        (((X) & 0x000000ff) << 24))
+#define Uswap64(X) \
+       ((((X) & 0xff00000000000000) >> 56) | \
+        (((X) & 0x00ff000000000000) >> 40) | \
+        (((X) & 0x0000ff0000000000) >> 24) | \
+        (((X) & 0x000000ff00000000) >>  8) | \
+        (((X) & 0x00000000ff000000) <<  8) | \
+        (((X) & 0x0000000000ff0000) << 24) | \
+        (((X) & 0x000000000000ff00) << 40) | \
+        (((X) & 0x00000000000000ff) << 56))
+
+
 /**
   Reads an 8-bit I/O port.
 
@@ -428,3 +448,462 @@ MmioWrite64 (
   return Value;
 }
 
+
+/**
+  Reads a 16-bit MMIO register in Big Endian format.
+
+  Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
+  returned. This function must guarantee that all MMIO read and write
+  operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to read.
+
+  @return The value read.
+
+**/
+UINT16
+EFIAPI
+MmioReadBe16 (
+  IN      UINTN                     Address
+  )
+{
+  UINT16                            Value;
+
+  ASSERT ((Address & 1) == 0);
+  Value = *(volatile UINT16*)Address;
+  return Uswap16(Value);
+}
+
+/**
+  Writes a 16-bit MMIO register in Big Endian format.
+
+  Writes the 16-bit MMIO register specified by Address with the value specified
+  by Value and returns Value. This function must guarantee that all MMIO read
+  and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioWriteBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Value
+  )
+{
+  ASSERT ((Address & 1) == 0);
+  *(volatile UINT16*)Address = Uswap16(Value);
+  return Value;
+}
+
+/**
+  Reads a 32-bit MMIO register in Big Endian format.
+
+  Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
+  returned. This function must guarantee that all MMIO read and write
+  operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to read.
+
+  @return The value read.
+
+**/
+UINT32
+EFIAPI
+MmioReadBe32 (
+  IN      UINTN                     Address
+  )
+{
+  UINT32                            Value;
+
+  ASSERT ((Address & 3) == 0);
+  Value = *(volatile UINT32*)Address;
+  return Uswap32(Value);
+}
+
+/**
+  Writes a 32-bit MMIO register in Big Endian format.
+
+  Writes the 32-bit MMIO register specified by Address with the value specified
+  by Value and returns Value. This function must guarantee that all MMIO read
+  and write operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioWriteBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Value
+  )
+{
+  ASSERT ((Address & 3) == 0);
+  *(volatile UINT32*)Address = Uswap32(Value);
+  return Value;
+}
+
+/**
+  Reads a 64-bit MMIO register in Big Endian format.
+
+  Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
+  returned. This function must guarantee that all MMIO read and write
+  operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to read.
+
+  @return The value read.
+
+**/
+UINT64
+EFIAPI
+MmioReadBe64 (
+  IN      UINTN                     Address
+  )
+{
+  UINT64                            Value;
+
+  ASSERT ((Address & 7) == 0);
+  Value = *(volatile UINT64*)Address;
+  return Uswap64(Value);
+}
+
+/**
+  Writes a 64-bit MMIO register in Big Endian format.
+
+  Writes the 64-bit MMIO register specified by Address with the value specified
+  by Value and returns Value. This function must guarantee that all MMIO read
+  and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioWriteBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Value
+  )
+{
+  ASSERT ((Address & 7) == 0);
+  *(volatile UINT64*)Address = Uswap64(Value);
+  return Value;
+}
+
+/**
+  Clear and set a 8-bit MMIO register.
+
+  Mask the 8-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 8-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT8
+EFIAPI
+MmioClearSet8 (
+  IN      UINTN                    Address,
+  IN      UINT8                    Mask,
+  IN      UINT8                    Value
+  )
+{
+  *(volatile UINT8*)Address = (*(volatile UINT8*)Address & ~Mask) | Value;
+  return *(volatile UINT8*)Address;
+}
+
+/**
+  Clear and set a 16-bit MMIO register in Big Endian format.
+
+  Mask the 16-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 16-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioClearSetBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Mask,
+  IN      UINT16                    Value
+  )
+{
+  ASSERT ((Address & 1) == 0);
+  *(volatile UINT16*)Address = (*(volatile UINT16*)Address & Uswap16(~Mask))
+								 | Uswap16(Value);
+  return *(volatile UINT16*)Address;
+}
+
+/**
+  Clear and set a 32-bit MMIO register in Big Endian format.
+
+  Mask the 32-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 32-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioClearSetBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Mask,
+  IN      UINT32                    Value
+  )
+{
+  ASSERT ((Address & 3) == 0);
+  *(volatile UINT32*)Address = (*(volatile UINT32*)Address & Uswap32(~Mask))
+								 | Uswap32(Value);
+  return *(volatile UINT32*)Address;
+}
+
+/**
+  Clear and set a 64-bit MMIO register in Big Endian format.
+
+  Mask the 64-bit MMIO register specified by Address with the mask specified
+  by Mask and then Writes the 64-bit MMIO register specified by Address with
+  the value specified by Value and returns current value on register. This
+  function must guarantee that all MMIO read and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Mask to clear the MMIO register.
+  @param  Value   The value to write to the MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioClearSetBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Mask,
+  IN      UINT64                    Value
+  )
+{
+  ASSERT ((Address & 7) == 0);
+  *(volatile UINT64*)Address = (*(volatile UINT64*)Address & Uswap64(~Mask))
+								| Uswap64(Value);
+  return *(volatile UINT64*)Address;
+}
+
+/**
+  Set a 8-bit MMIO register in Big Endian format.
+
+  Set bits of the 8-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 8-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT8
+EFIAPI
+MmioSetBits8 (
+  IN      UINTN                     Address,
+  IN      UINT8                     Bits
+  )
+{
+  *(volatile UINT8*)Address = *(volatile UINT8*)Address | Bits;
+  return *(volatile UINT8*)Address;
+}
+
+/**
+  Set a 16-bit MMIO register in Big Endian format.
+
+  Set bits of the 16-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioSetBitsBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Bits
+  )
+{
+  ASSERT ((Address & 1) == 0);
+  *(volatile UINT16*)Address = *(volatile UINT16*)Address | Uswap16(Bits);
+  return *(volatile UINT16*)Address;
+}
+
+/**
+  Set a 32-bit MMIO register in Big Endian format.
+
+  Set bits of the 32-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioSetBitsBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Bits
+  )
+{
+  ASSERT ((Address & 3) == 0);
+  *(volatile UINT32*)Address = *(volatile UINT32*)Address | Uswap32(Bits);
+  return *(volatile UINT32*)Address;
+}
+
+/**
+  Set a 64-bit MMIO register in Big Endian format.
+
+  Set bits of the 64-bit MMIO register specified by Address with the Bits
+  specified by Bits and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Bits    The Bits to set in MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioSetBitsBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Bits
+  )
+{
+  ASSERT ((Address & 7) == 0);
+  *(volatile UINT64*)Address = *(volatile UINT64*)Address | Uswap64(Bits);
+  return *(volatile UINT64*)Address;
+}
+
+/**
+  Clear bits of the 8-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 8-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT8
+EFIAPI
+MmioClearBits8 (
+  IN      UINTN                     Address,
+  IN      UINT8                     Mask
+  )
+{
+  *(volatile UINT8*)Address = *(volatile UINT8*)Address & (~Mask);
+  return *(volatile UINT8*)Address;
+}
+
+/**
+  Clear bits of the 16-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 16-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT16
+EFIAPI
+MmioClearBitsBe16 (
+  IN      UINTN                     Address,
+  IN      UINT16                    Mask
+  )
+{
+  ASSERT ((Address & 1) == 0);
+  *(volatile UINT16*)Address = *(volatile UINT16*)Address & Uswap16(~Mask);
+  return *(volatile UINT16*)Address;
+}
+
+/**
+  Clear bits of the 32-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 32-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT32
+EFIAPI
+MmioClearBitsBe32 (
+  IN      UINTN                     Address,
+  IN      UINT32                    Mask
+  )
+{
+  ASSERT ((Address & 3) == 0);
+  *(volatile UINT32*)Address = *(volatile UINT32*)Address & Uswap32(~Mask);
+  return *(volatile UINT32*)Address;
+}
+
+/**
+  Clear bits of the 64-bit MMIO register specified by Address with the Mask
+  specified by Mask and returns register content. This function must
+  guarantee that all MMIO read and write operations are serialized.
+
+  If 64-bit MMIO register operations are not supported, then ASSERT().
+
+  @param  Address The MMIO register to write.
+  @param  Mask    The Bits to clear in MMIO register.
+
+**/
+UINT64
+EFIAPI
+MmioClearBitsBe64 (
+  IN      UINTN                     Address,
+  IN      UINT64                    Mask
+  )
+{
+  ASSERT ((Address & 7) == 0);
+  *(volatile UINT64*)Address = *(volatile UINT64*)Address & Uswap64(~Mask);
+  return *(volatile UINT64*)Address;
+}
-- 
1.9.1




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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-14  9:33 [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO Bhupesh Sharma
@ 2016-10-14 12:06 ` Laszlo Ersek
  2016-10-14 13:17   ` Bhupesh Sharma
  2016-10-17  3:10 ` Gao, Liming
  1 sibling, 1 reply; 25+ messages in thread
From: Laszlo Ersek @ 2016-10-14 12:06 UTC (permalink / raw)
  To: Bhupesh Sharma; +Cc: edk2-devel

On 10/14/16 11:33, Bhupesh Sharma wrote:
> Various IPs on NXP/FSL SoCs having ARM64 cores have big-endian
> MMIO interfaces.
> 
> This implies that a byte-swap operation is needed to read/write
> such BE MMIO registers from the LE ARM64 cores.
> 
> This patch adds the support for the same.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> Signed-off-by: Bhupesh Sharma <bhupesh.sharma@nxp.com>
> ---
>  MdePkg/Include/Library/IoLib.h               | 364 ++++++++++++++++++++
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c | 479 +++++++++++++++++++++++++++
>  2 files changed, 843 insertions(+)

I think this is both overkill and incomplete, at the same time :)

- Incomplete because only one IoLib instance gets the implementation.

- Overkill because you can easily use the SwapBytes16, SwapBytes32,
SwapBytes64 functions -- also from BaseLib --, for transforming
MmioWrite arguments and MmioRead results.

Thanks
Laszlo


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-14 12:06 ` Laszlo Ersek
@ 2016-10-14 13:17   ` Bhupesh Sharma
  2016-10-14 13:32     ` Laszlo Ersek
  0 siblings, 1 reply; 25+ messages in thread
From: Bhupesh Sharma @ 2016-10-14 13:17 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: edk2-devel@ml01.01.org

Hi Laszlo,

> From: Laszlo Ersek [mailto:lersek@redhat.com]
> Sent: Friday, October 14, 2016 5:37 PM
> 
> On 10/14/16 11:33, Bhupesh Sharma wrote:
> > Various IPs on NXP/FSL SoCs having ARM64 cores have big-endian MMIO
> > interfaces.
> >
> > This implies that a byte-swap operation is needed to read/write such
> > BE MMIO registers from the LE ARM64 cores.
> >
> > This patch adds the support for the same.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > Signed-off-by: Bhupesh Sharma <bhupesh.sharma@nxp.com>
> > ---
> >  MdePkg/Include/Library/IoLib.h               | 364
> ++++++++++++++++++++
> >  MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c | 479
> > +++++++++++++++++++++++++++
> >  2 files changed, 843 insertions(+)
> 
> I think this is both overkill and incomplete, at the same time :)
> 
> - Incomplete because only one IoLib instance gets the implementation.

Agree, but do we have an example of similar BE MMIO IPs on other
Architectures/soc? I was only aware of NXP/FSL having such MMIO
interfaces as the IPs have been reused from PPC SoC, which used
to have a BE core and hence did not require a SwapByte.
 
> - Overkill because you can easily use the SwapBytes16, SwapBytes32,
> SwapBytes64 functions -- also from BaseLib --, for transforming
> MmioWrite arguments and MmioRead results.
> 

Yes, but that means at every IP driver needs to especially carry such
arguments and transform the results. That might be an overkill.

We already have similar implementations MMIO implementations in Linux for e.g.
http://lxr.free-electrons.com/source/include/asm-generic/io.h#L642

Regards,
Bhupesh


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-14 13:17   ` Bhupesh Sharma
@ 2016-10-14 13:32     ` Laszlo Ersek
  0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2016-10-14 13:32 UTC (permalink / raw)
  To: Bhupesh Sharma; +Cc: edk2-devel@ml01.01.org

On 10/14/16 15:17, Bhupesh Sharma wrote:
> Hi Laszlo,
> 
>> From: Laszlo Ersek [mailto:lersek@redhat.com]
>> Sent: Friday, October 14, 2016 5:37 PM
>>
>> On 10/14/16 11:33, Bhupesh Sharma wrote:
>>> Various IPs on NXP/FSL SoCs having ARM64 cores have big-endian MMIO
>>> interfaces.
>>>
>>> This implies that a byte-swap operation is needed to read/write such
>>> BE MMIO registers from the LE ARM64 cores.
>>>
>>> This patch adds the support for the same.
>>>
>>> Contributed-under: TianoCore Contribution Agreement 1.0
>>> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
>>> Signed-off-by: Bhupesh Sharma <bhupesh.sharma@nxp.com>
>>> ---
>>>  MdePkg/Include/Library/IoLib.h               | 364
>> ++++++++++++++++++++
>>>  MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c | 479
>>> +++++++++++++++++++++++++++
>>>  2 files changed, 843 insertions(+)
>>
>> I think this is both overkill and incomplete, at the same time :)
>>
>> - Incomplete because only one IoLib instance gets the implementation.
> 
> Agree, but do we have an example of similar BE MMIO IPs on other
> Architectures/soc? I was only aware of NXP/FSL having such MMIO
> interfaces as the IPs have been reused from PPC SoC, which used
> to have a BE core and hence did not require a SwapByte.

For example, the fw_cfg device of QEMU is big endian. OvmfPkg and
ArmVirtPkg call SwapBytesXX as necessary, in combination with MmioWriteXX.

In general, I think it's expected that a library declared under MdePkg
will not cause build failures (unresolved symbols) in any platform code,
once the library is resolved correctly in the platform DSC.

>  
>> - Overkill because you can easily use the SwapBytes16, SwapBytes32,
>> SwapBytes64 functions -- also from BaseLib --, for transforming
>> MmioWrite arguments and MmioRead results.
>>
> 
> Yes, but that means at every IP driver needs to especially carry such
> arguments and transform the results.

Indeed.

> That might be an overkill.

I think it should be possible to factor out these functions to a
separate library, or non-standard protocol, that is central enough for
the platform or device in question, but not core enough for putting into
MdePkg.

> We already have similar implementations MMIO implementations in Linux for e.g.
> http://lxr.free-electrons.com/source/include/asm-generic/io.h#L642

Hmmm. That does detract from the value of my "overkill" argument. So I
guess I'll have to defer to the MdePkg maintainers on that.

Regarding my "incomplete" argument, it still stands. I think it's
logically impossible to introduce a library class that is simultaneously
- central enough to merit a place under MdePkg, but
- not central enough to receive implementations (library instances) for
all the platforms supported by edk2 at the moment.

Thanks
Laszlo


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-14  9:33 [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO Bhupesh Sharma
  2016-10-14 12:06 ` Laszlo Ersek
@ 2016-10-17  3:10 ` Gao, Liming
  2016-10-17  4:10   ` Kinney, Michael D
  1 sibling, 1 reply; 25+ messages in thread
From: Gao, Liming @ 2016-10-17  3:10 UTC (permalink / raw)
  To: Bhupesh Sharma, edk2-devel@ml01.01.org

Bhupesh:
  In this patch, five class APIs are new added. They are MmioReadBe16(),MmioWriteBe16(),MmioClearSetBe16(),MmioSetBitsBe16(),MmioClearBitsBe16(). In fact, they can map to the existing MMIO APIs. Below is their mapping. And, I understand some hardware uses little-endian MMIO interfaces, other hardware use big-endian MMIO interfaces. But, there are no hardware to require little-endian and big-endian at the same time. If so, we don't need to expose MmioRead16() and MmioReadBe16() API both in the same library instances. For your case, I suggest to add new IoLib library instance that implement the existing MMIO APIs with the big-endian way. This library instance can be placed into ARM device package. 

MmioReadBe16()  --> MmioRead16()
MmioWriteBe16() --> MmioWrite16()
MmioClearSetBe16() -->  MmioAndThenOr16()
MmioSetBitsBe16() -->     MmioOr16()
MmioClearBitsBe16() -->  MmioAnd16()

Thanks
Liming
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Bhupesh Sharma
> Sent: Friday, October 14, 2016 5:34 PM
> To: edk2-devel@ml01.01.org
> Subject: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> Various IPs on NXP/FSL SoCs having ARM64 cores have big-endian
> MMIO interfaces.
> 
> This implies that a byte-swap operation is needed to read/write
> such BE MMIO registers from the LE ARM64 cores.
> 
> This patch adds the support for the same.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> Signed-off-by: Bhupesh Sharma <bhupesh.sharma@nxp.com>
> ---
>  MdePkg/Include/Library/IoLib.h               | 364 ++++++++++++++++++++
>  MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c | 479
> +++++++++++++++++++++++++++
>  2 files changed, 843 insertions(+)
> 
> diff --git a/MdePkg/Include/Library/IoLib.h
> b/MdePkg/Include/Library/IoLib.h
> index a0dd16b..f5842e6 100644
> --- a/MdePkg/Include/Library/IoLib.h
> +++ b/MdePkg/Include/Library/IoLib.h
> @@ -2658,6 +2658,370 @@ MmioWriteBuffer64 (
>    IN  CONST UINT64 *Buffer
>    );
> 
> +/**
> +  Reads a 16-bit MMIO register in Big Endian format.
> +
> +  Reads the 16-bit MMIO register specified by Address. The 16-bit read value
> is
> +  returned. This function must guarantee that all MMIO read and write
> +  operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to read.
> +
> +  @return The value read.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioReadBe16 (
> +  IN      UINTN                     Address
> +  );
> +
> +/**
> +  Writes a 16-bit MMIO register in Big Endian format.
> +
> +  Writes the 16-bit MMIO register specified by Address with the value
> specified
> +  by Value and returns Value. This function must guarantee that all MMIO
> read
> +  and write operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioWriteBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Value
> +  );
> +
> +/**
> +  Reads a 32-bit MMIO register in Big Endian format.
> +
> +  Reads the 32-bit MMIO register specified by Address. The 32-bit read value
> is
> +  returned. This function must guarantee that all MMIO read and write
> +  operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to read.
> +
> +  @return The value read.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioReadBe32 (
> +  IN      UINTN                     Address
> +  );
> +
> +/**
> +  Writes a 32-bit MMIO register in Big Endian format.
> +
> +  Writes the 32-bit MMIO register specified by Address with the value
> specified
> +  by Value and returns Value. This function must guarantee that all MMIO
> read
> +  and write operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioWriteBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Value
> +  );
> +
> +
> +/**
> +  Reads a 64-bit MMIO register in Big Endian format.
> +
> +  Reads the 64-bit MMIO register specified by Address. The 64-bit read value
> is
> +  returned. This function must guarantee that all MMIO read and write
> +  operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to read.
> +
> +  @return The value read.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioReadBe64 (
> +  IN      UINTN                     Address
> +  );
> +
> +
> +/**
> +  Writes a 64-bit MMIO register in Big Endian format.
> +
> +  Writes the 64-bit MMIO register specified by Address with the value
> specified
> +  by Value and returns Value. This function must guarantee that all MMIO
> read
> +  and write operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioWriteBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Value
> +  );
> +
> +/**
> +  Clear and set a 8-bit MMIO register.
> +
> +  Mask the 8-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 8-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT8
> +EFIAPI
> +MmioClearSet8 (
> +  IN      UINTN                    Address,
> +  IN      UINT8                    Mask,
> +  IN      UINT8                    Value
> +  );
> +
> +/**
> +  Clear and set a 16-bit MMIO register in Big Endian format.
> +
> +  Mask the 16-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 16-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioClearSetBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Mask,
> +  IN      UINT16                    Value
> +  );
> +
> +/**
> +  Clear and set a 32-bit MMIO register in Big Endian format.
> +
> +  Mask the 32-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 32-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioClearSetBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Mask,
> +  IN      UINT32                    Value
> +  );
> +
> +/**
> +  Clear and set a 64-bit MMIO register in Big Endian format.
> +
> +  Mask the 64-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 64-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioClearSetBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Mask,
> +  IN      UINT64                    Value
> +  );
> +
> +/**
> +  Set a 8-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 8-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 8-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT8
> +EFIAPI
> +MmioSetBits8 (
> +  IN      UINTN                     Address,
> +  IN      UINT8                     Bits
> +  );
> +
> +/**
> +  Set a 16-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 16-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioSetBitsBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Bits
> +  );
> +
> +/**
> +  Set a 32-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 32-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioSetBitsBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Bits
> +  );
> +
> +/**
> +  Set a 64-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 64-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioSetBitsBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Bits
> +  );
> +
> +/**
> +  Clear bits of the 8-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 8-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT8
> +EFIAPI
> +MmioClearBits8 (
> +  IN      UINTN                     Address,
> +  IN      UINT8                     Mask
> +  );
> +
> +/**
> +  Clear bits of the 16-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioClearBitsBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Mask
> +  );
> +
> +/**
> +  Clear bits of the 32-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioClearBitsBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Mask
> +  );
> +
> +/**
> +  Clear bits of the 64-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioClearBitsBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Mask
> +  );
> 
>  #endif
> 
> diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> b/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> index b9f4c5e..f2179d1 100644
> --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> @@ -19,6 +19,26 @@
>  //
>  #include "BaseIoLibIntrinsicInternal.h"
> 
> +
> +#define Uswap16(X) \
> +       ((((X) & 0xff00) >> 8) | \
> +        (((X) & 0x00ff) << 8))
> +#define Uswap32(X) \
> +       ((((X) & 0xff000000) >> 24) | \
> +        (((X) & 0x00ff0000) >>  8) | \
> +        (((X) & 0x0000ff00) <<  8) | \
> +        (((X) & 0x000000ff) << 24))
> +#define Uswap64(X) \
> +       ((((X) & 0xff00000000000000) >> 56) | \
> +        (((X) & 0x00ff000000000000) >> 40) | \
> +        (((X) & 0x0000ff0000000000) >> 24) | \
> +        (((X) & 0x000000ff00000000) >>  8) | \
> +        (((X) & 0x00000000ff000000) <<  8) | \
> +        (((X) & 0x0000000000ff0000) << 24) | \
> +        (((X) & 0x000000000000ff00) << 40) | \
> +        (((X) & 0x00000000000000ff) << 56))
> +
> +
>  /**
>    Reads an 8-bit I/O port.
> 
> @@ -428,3 +448,462 @@ MmioWrite64 (
>    return Value;
>  }
> 
> +
> +/**
> +  Reads a 16-bit MMIO register in Big Endian format.
> +
> +  Reads the 16-bit MMIO register specified by Address. The 16-bit read value
> is
> +  returned. This function must guarantee that all MMIO read and write
> +  operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to read.
> +
> +  @return The value read.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioReadBe16 (
> +  IN      UINTN                     Address
> +  )
> +{
> +  UINT16                            Value;
> +
> +  ASSERT ((Address & 1) == 0);
> +  Value = *(volatile UINT16*)Address;
> +  return Uswap16(Value);
> +}
> +
> +/**
> +  Writes a 16-bit MMIO register in Big Endian format.
> +
> +  Writes the 16-bit MMIO register specified by Address with the value
> specified
> +  by Value and returns Value. This function must guarantee that all MMIO
> read
> +  and write operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioWriteBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Value
> +  )
> +{
> +  ASSERT ((Address & 1) == 0);
> +  *(volatile UINT16*)Address = Uswap16(Value);
> +  return Value;
> +}
> +
> +/**
> +  Reads a 32-bit MMIO register in Big Endian format.
> +
> +  Reads the 32-bit MMIO register specified by Address. The 32-bit read value
> is
> +  returned. This function must guarantee that all MMIO read and write
> +  operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to read.
> +
> +  @return The value read.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioReadBe32 (
> +  IN      UINTN                     Address
> +  )
> +{
> +  UINT32                            Value;
> +
> +  ASSERT ((Address & 3) == 0);
> +  Value = *(volatile UINT32*)Address;
> +  return Uswap32(Value);
> +}
> +
> +/**
> +  Writes a 32-bit MMIO register in Big Endian format.
> +
> +  Writes the 32-bit MMIO register specified by Address with the value
> specified
> +  by Value and returns Value. This function must guarantee that all MMIO
> read
> +  and write operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioWriteBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Value
> +  )
> +{
> +  ASSERT ((Address & 3) == 0);
> +  *(volatile UINT32*)Address = Uswap32(Value);
> +  return Value;
> +}
> +
> +/**
> +  Reads a 64-bit MMIO register in Big Endian format.
> +
> +  Reads the 64-bit MMIO register specified by Address. The 64-bit read value
> is
> +  returned. This function must guarantee that all MMIO read and write
> +  operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to read.
> +
> +  @return The value read.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioReadBe64 (
> +  IN      UINTN                     Address
> +  )
> +{
> +  UINT64                            Value;
> +
> +  ASSERT ((Address & 7) == 0);
> +  Value = *(volatile UINT64*)Address;
> +  return Uswap64(Value);
> +}
> +
> +/**
> +  Writes a 64-bit MMIO register in Big Endian format.
> +
> +  Writes the 64-bit MMIO register specified by Address with the value
> specified
> +  by Value and returns Value. This function must guarantee that all MMIO
> read
> +  and write operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioWriteBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Value
> +  )
> +{
> +  ASSERT ((Address & 7) == 0);
> +  *(volatile UINT64*)Address = Uswap64(Value);
> +  return Value;
> +}
> +
> +/**
> +  Clear and set a 8-bit MMIO register.
> +
> +  Mask the 8-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 8-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT8
> +EFIAPI
> +MmioClearSet8 (
> +  IN      UINTN                    Address,
> +  IN      UINT8                    Mask,
> +  IN      UINT8                    Value
> +  )
> +{
> +  *(volatile UINT8*)Address = (*(volatile UINT8*)Address & ~Mask) | Value;
> +  return *(volatile UINT8*)Address;
> +}
> +
> +/**
> +  Clear and set a 16-bit MMIO register in Big Endian format.
> +
> +  Mask the 16-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 16-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioClearSetBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Mask,
> +  IN      UINT16                    Value
> +  )
> +{
> +  ASSERT ((Address & 1) == 0);
> +  *(volatile UINT16*)Address = (*(volatile UINT16*)Address &
> Uswap16(~Mask))
> +								 |
> Uswap16(Value);
> +  return *(volatile UINT16*)Address;
> +}
> +
> +/**
> +  Clear and set a 32-bit MMIO register in Big Endian format.
> +
> +  Mask the 32-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 32-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioClearSetBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Mask,
> +  IN      UINT32                    Value
> +  )
> +{
> +  ASSERT ((Address & 3) == 0);
> +  *(volatile UINT32*)Address = (*(volatile UINT32*)Address &
> Uswap32(~Mask))
> +								 |
> Uswap32(Value);
> +  return *(volatile UINT32*)Address;
> +}
> +
> +/**
> +  Clear and set a 64-bit MMIO register in Big Endian format.
> +
> +  Mask the 64-bit MMIO register specified by Address with the mask
> specified
> +  by Mask and then Writes the 64-bit MMIO register specified by Address
> with
> +  the value specified by Value and returns current value on register. This
> +  function must guarantee that all MMIO read and write operations are
> serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Mask to clear the MMIO register.
> +  @param  Value   The value to write to the MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioClearSetBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Mask,
> +  IN      UINT64                    Value
> +  )
> +{
> +  ASSERT ((Address & 7) == 0);
> +  *(volatile UINT64*)Address = (*(volatile UINT64*)Address &
> Uswap64(~Mask))
> +								|
> Uswap64(Value);
> +  return *(volatile UINT64*)Address;
> +}
> +
> +/**
> +  Set a 8-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 8-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 8-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT8
> +EFIAPI
> +MmioSetBits8 (
> +  IN      UINTN                     Address,
> +  IN      UINT8                     Bits
> +  )
> +{
> +  *(volatile UINT8*)Address = *(volatile UINT8*)Address | Bits;
> +  return *(volatile UINT8*)Address;
> +}
> +
> +/**
> +  Set a 16-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 16-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioSetBitsBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Bits
> +  )
> +{
> +  ASSERT ((Address & 1) == 0);
> +  *(volatile UINT16*)Address = *(volatile UINT16*)Address | Uswap16(Bits);
> +  return *(volatile UINT16*)Address;
> +}
> +
> +/**
> +  Set a 32-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 32-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioSetBitsBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Bits
> +  )
> +{
> +  ASSERT ((Address & 3) == 0);
> +  *(volatile UINT32*)Address = *(volatile UINT32*)Address | Uswap32(Bits);
> +  return *(volatile UINT32*)Address;
> +}
> +
> +/**
> +  Set a 64-bit MMIO register in Big Endian format.
> +
> +  Set bits of the 64-bit MMIO register specified by Address with the Bits
> +  specified by Bits and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Bits    The Bits to set in MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioSetBitsBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Bits
> +  )
> +{
> +  ASSERT ((Address & 7) == 0);
> +  *(volatile UINT64*)Address = *(volatile UINT64*)Address | Uswap64(Bits);
> +  return *(volatile UINT64*)Address;
> +}
> +
> +/**
> +  Clear bits of the 8-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 8-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT8
> +EFIAPI
> +MmioClearBits8 (
> +  IN      UINTN                     Address,
> +  IN      UINT8                     Mask
> +  )
> +{
> +  *(volatile UINT8*)Address = *(volatile UINT8*)Address & (~Mask);
> +  return *(volatile UINT8*)Address;
> +}
> +
> +/**
> +  Clear bits of the 16-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 16-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT16
> +EFIAPI
> +MmioClearBitsBe16 (
> +  IN      UINTN                     Address,
> +  IN      UINT16                    Mask
> +  )
> +{
> +  ASSERT ((Address & 1) == 0);
> +  *(volatile UINT16*)Address = *(volatile UINT16*)Address &
> Uswap16(~Mask);
> +  return *(volatile UINT16*)Address;
> +}
> +
> +/**
> +  Clear bits of the 32-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 32-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT32
> +EFIAPI
> +MmioClearBitsBe32 (
> +  IN      UINTN                     Address,
> +  IN      UINT32                    Mask
> +  )
> +{
> +  ASSERT ((Address & 3) == 0);
> +  *(volatile UINT32*)Address = *(volatile UINT32*)Address &
> Uswap32(~Mask);
> +  return *(volatile UINT32*)Address;
> +}
> +
> +/**
> +  Clear bits of the 64-bit MMIO register specified by Address with the Mask
> +  specified by Mask and returns register content. This function must
> +  guarantee that all MMIO read and write operations are serialized.
> +
> +  If 64-bit MMIO register operations are not supported, then ASSERT().
> +
> +  @param  Address The MMIO register to write.
> +  @param  Mask    The Bits to clear in MMIO register.
> +
> +**/
> +UINT64
> +EFIAPI
> +MmioClearBitsBe64 (
> +  IN      UINTN                     Address,
> +  IN      UINT64                    Mask
> +  )
> +{
> +  ASSERT ((Address & 7) == 0);
> +  *(volatile UINT64*)Address = *(volatile UINT64*)Address &
> Uswap64(~Mask);
> +  return *(volatile UINT64*)Address;
> +}
> --
> 1.9.1
> 
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-17  3:10 ` Gao, Liming
@ 2016-10-17  4:10   ` Kinney, Michael D
  2016-10-17  7:42     ` Ard Biesheuvel
  0 siblings, 1 reply; 25+ messages in thread
From: Kinney, Michael D @ 2016-10-17  4:10 UTC (permalink / raw)
  To: Gao, Liming, Bhupesh Sharma, edk2-devel@ml01.01.org,
	Kinney, Michael D

Bhupesh,

It is also possible to add an ARM specific PCD to select endianness and update
MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that PCD in MmioRead/Write() 
APIs in that file to support both endian types.  You can use the SwapBytesxx()
functions from BaseLib(as Laszlo suggested) based on the setting of this ARM 
specific PCD.

Modules that link against this lib can select endianness by setting PCD in the 
scope of that module.

The IPF version of IoLib uses an IPF specific PCD to translate I/O port accesses
to MMIO accesses.  So there is already an example of an arch specific PCD in this
lib instance.

Mike

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Gao, Liming
> Sent: Monday, October 17, 2016 11:10 AM
> To: Bhupesh Sharma <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
> 
> Bhupesh:
>   In this patch, five class APIs are new added. They are
> MmioReadBe16(),MmioWriteBe16(),MmioClearSetBe16(),MmioSetBitsBe16(),MmioClearBitsBe16
> (). In fact, they can map to the existing MMIO APIs. Below is their mapping. And, I
> understand some hardware uses little-endian MMIO interfaces, other hardware use big-
> endian MMIO interfaces. But, there are no hardware to require little-endian and big-
> endian at the same time. If so, we don't need to expose MmioRead16() and
> MmioReadBe16() API both in the same library instances. For your case, I suggest to
> add new IoLib library instance that implement the existing MMIO APIs with the big-
> endian way. This library instance can be placed into ARM device package.
> 
> MmioReadBe16()  --> MmioRead16()
> MmioWriteBe16() --> MmioWrite16()
> MmioClearSetBe16() -->  MmioAndThenOr16()
> MmioSetBitsBe16() -->     MmioOr16()
> MmioClearBitsBe16() -->  MmioAnd16()
> 
> Thanks
> Liming
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> > Bhupesh Sharma
> > Sent: Friday, October 14, 2016 5:34 PM
> > To: edk2-devel@ml01.01.org
> > Subject: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> > MMIO
> >
> > Various IPs on NXP/FSL SoCs having ARM64 cores have big-endian
> > MMIO interfaces.
> >
> > This implies that a byte-swap operation is needed to read/write
> > such BE MMIO registers from the LE ARM64 cores.
> >
> > This patch adds the support for the same.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > Signed-off-by: Bhupesh Sharma <bhupesh.sharma@nxp.com>
> > ---
> >  MdePkg/Include/Library/IoLib.h               | 364 ++++++++++++++++++++
> >  MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c | 479
> > +++++++++++++++++++++++++++
> >  2 files changed, 843 insertions(+)
> >
> > diff --git a/MdePkg/Include/Library/IoLib.h
> > b/MdePkg/Include/Library/IoLib.h
> > index a0dd16b..f5842e6 100644
> > --- a/MdePkg/Include/Library/IoLib.h
> > +++ b/MdePkg/Include/Library/IoLib.h
> > @@ -2658,6 +2658,370 @@ MmioWriteBuffer64 (
> >    IN  CONST UINT64 *Buffer
> >    );
> >
> > +/**
> > +  Reads a 16-bit MMIO register in Big Endian format.
> > +
> > +  Reads the 16-bit MMIO register specified by Address. The 16-bit read value
> > is
> > +  returned. This function must guarantee that all MMIO read and write
> > +  operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to read.
> > +
> > +  @return The value read.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioReadBe16 (
> > +  IN      UINTN                     Address
> > +  );
> > +
> > +/**
> > +  Writes a 16-bit MMIO register in Big Endian format.
> > +
> > +  Writes the 16-bit MMIO register specified by Address with the value
> > specified
> > +  by Value and returns Value. This function must guarantee that all MMIO
> > read
> > +  and write operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioWriteBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Value
> > +  );
> > +
> > +/**
> > +  Reads a 32-bit MMIO register in Big Endian format.
> > +
> > +  Reads the 32-bit MMIO register specified by Address. The 32-bit read value
> > is
> > +  returned. This function must guarantee that all MMIO read and write
> > +  operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to read.
> > +
> > +  @return The value read.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioReadBe32 (
> > +  IN      UINTN                     Address
> > +  );
> > +
> > +/**
> > +  Writes a 32-bit MMIO register in Big Endian format.
> > +
> > +  Writes the 32-bit MMIO register specified by Address with the value
> > specified
> > +  by Value and returns Value. This function must guarantee that all MMIO
> > read
> > +  and write operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioWriteBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Value
> > +  );
> > +
> > +
> > +/**
> > +  Reads a 64-bit MMIO register in Big Endian format.
> > +
> > +  Reads the 64-bit MMIO register specified by Address. The 64-bit read value
> > is
> > +  returned. This function must guarantee that all MMIO read and write
> > +  operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to read.
> > +
> > +  @return The value read.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioReadBe64 (
> > +  IN      UINTN                     Address
> > +  );
> > +
> > +
> > +/**
> > +  Writes a 64-bit MMIO register in Big Endian format.
> > +
> > +  Writes the 64-bit MMIO register specified by Address with the value
> > specified
> > +  by Value and returns Value. This function must guarantee that all MMIO
> > read
> > +  and write operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioWriteBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Value
> > +  );
> > +
> > +/**
> > +  Clear and set a 8-bit MMIO register.
> > +
> > +  Mask the 8-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 8-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT8
> > +EFIAPI
> > +MmioClearSet8 (
> > +  IN      UINTN                    Address,
> > +  IN      UINT8                    Mask,
> > +  IN      UINT8                    Value
> > +  );
> > +
> > +/**
> > +  Clear and set a 16-bit MMIO register in Big Endian format.
> > +
> > +  Mask the 16-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 16-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioClearSetBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Mask,
> > +  IN      UINT16                    Value
> > +  );
> > +
> > +/**
> > +  Clear and set a 32-bit MMIO register in Big Endian format.
> > +
> > +  Mask the 32-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 32-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioClearSetBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Mask,
> > +  IN      UINT32                    Value
> > +  );
> > +
> > +/**
> > +  Clear and set a 64-bit MMIO register in Big Endian format.
> > +
> > +  Mask the 64-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 64-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioClearSetBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Mask,
> > +  IN      UINT64                    Value
> > +  );
> > +
> > +/**
> > +  Set a 8-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 8-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 8-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT8
> > +EFIAPI
> > +MmioSetBits8 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT8                     Bits
> > +  );
> > +
> > +/**
> > +  Set a 16-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 16-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioSetBitsBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Bits
> > +  );
> > +
> > +/**
> > +  Set a 32-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 32-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioSetBitsBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Bits
> > +  );
> > +
> > +/**
> > +  Set a 64-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 64-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioSetBitsBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Bits
> > +  );
> > +
> > +/**
> > +  Clear bits of the 8-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 8-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT8
> > +EFIAPI
> > +MmioClearBits8 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT8                     Mask
> > +  );
> > +
> > +/**
> > +  Clear bits of the 16-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioClearBitsBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Mask
> > +  );
> > +
> > +/**
> > +  Clear bits of the 32-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioClearBitsBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Mask
> > +  );
> > +
> > +/**
> > +  Clear bits of the 64-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioClearBitsBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Mask
> > +  );
> >
> >  #endif
> >
> > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> > b/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> > index b9f4c5e..f2179d1 100644
> > --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> > +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c
> > @@ -19,6 +19,26 @@
> >  //
> >  #include "BaseIoLibIntrinsicInternal.h"
> >
> > +
> > +#define Uswap16(X) \
> > +       ((((X) & 0xff00) >> 8) | \
> > +        (((X) & 0x00ff) << 8))
> > +#define Uswap32(X) \
> > +       ((((X) & 0xff000000) >> 24) | \
> > +        (((X) & 0x00ff0000) >>  8) | \
> > +        (((X) & 0x0000ff00) <<  8) | \
> > +        (((X) & 0x000000ff) << 24))
> > +#define Uswap64(X) \
> > +       ((((X) & 0xff00000000000000) >> 56) | \
> > +        (((X) & 0x00ff000000000000) >> 40) | \
> > +        (((X) & 0x0000ff0000000000) >> 24) | \
> > +        (((X) & 0x000000ff00000000) >>  8) | \
> > +        (((X) & 0x00000000ff000000) <<  8) | \
> > +        (((X) & 0x0000000000ff0000) << 24) | \
> > +        (((X) & 0x000000000000ff00) << 40) | \
> > +        (((X) & 0x00000000000000ff) << 56))
> > +
> > +
> >  /**
> >    Reads an 8-bit I/O port.
> >
> > @@ -428,3 +448,462 @@ MmioWrite64 (
> >    return Value;
> >  }
> >
> > +
> > +/**
> > +  Reads a 16-bit MMIO register in Big Endian format.
> > +
> > +  Reads the 16-bit MMIO register specified by Address. The 16-bit read value
> > is
> > +  returned. This function must guarantee that all MMIO read and write
> > +  operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to read.
> > +
> > +  @return The value read.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioReadBe16 (
> > +  IN      UINTN                     Address
> > +  )
> > +{
> > +  UINT16                            Value;
> > +
> > +  ASSERT ((Address & 1) == 0);
> > +  Value = *(volatile UINT16*)Address;
> > +  return Uswap16(Value);
> > +}
> > +
> > +/**
> > +  Writes a 16-bit MMIO register in Big Endian format.
> > +
> > +  Writes the 16-bit MMIO register specified by Address with the value
> > specified
> > +  by Value and returns Value. This function must guarantee that all MMIO
> > read
> > +  and write operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioWriteBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Value
> > +  )
> > +{
> > +  ASSERT ((Address & 1) == 0);
> > +  *(volatile UINT16*)Address = Uswap16(Value);
> > +  return Value;
> > +}
> > +
> > +/**
> > +  Reads a 32-bit MMIO register in Big Endian format.
> > +
> > +  Reads the 32-bit MMIO register specified by Address. The 32-bit read value
> > is
> > +  returned. This function must guarantee that all MMIO read and write
> > +  operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to read.
> > +
> > +  @return The value read.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioReadBe32 (
> > +  IN      UINTN                     Address
> > +  )
> > +{
> > +  UINT32                            Value;
> > +
> > +  ASSERT ((Address & 3) == 0);
> > +  Value = *(volatile UINT32*)Address;
> > +  return Uswap32(Value);
> > +}
> > +
> > +/**
> > +  Writes a 32-bit MMIO register in Big Endian format.
> > +
> > +  Writes the 32-bit MMIO register specified by Address with the value
> > specified
> > +  by Value and returns Value. This function must guarantee that all MMIO
> > read
> > +  and write operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioWriteBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Value
> > +  )
> > +{
> > +  ASSERT ((Address & 3) == 0);
> > +  *(volatile UINT32*)Address = Uswap32(Value);
> > +  return Value;
> > +}
> > +
> > +/**
> > +  Reads a 64-bit MMIO register in Big Endian format.
> > +
> > +  Reads the 64-bit MMIO register specified by Address. The 64-bit read value
> > is
> > +  returned. This function must guarantee that all MMIO read and write
> > +  operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to read.
> > +
> > +  @return The value read.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioReadBe64 (
> > +  IN      UINTN                     Address
> > +  )
> > +{
> > +  UINT64                            Value;
> > +
> > +  ASSERT ((Address & 7) == 0);
> > +  Value = *(volatile UINT64*)Address;
> > +  return Uswap64(Value);
> > +}
> > +
> > +/**
> > +  Writes a 64-bit MMIO register in Big Endian format.
> > +
> > +  Writes the 64-bit MMIO register specified by Address with the value
> > specified
> > +  by Value and returns Value. This function must guarantee that all MMIO
> > read
> > +  and write operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioWriteBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Value
> > +  )
> > +{
> > +  ASSERT ((Address & 7) == 0);
> > +  *(volatile UINT64*)Address = Uswap64(Value);
> > +  return Value;
> > +}
> > +
> > +/**
> > +  Clear and set a 8-bit MMIO register.
> > +
> > +  Mask the 8-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 8-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT8
> > +EFIAPI
> > +MmioClearSet8 (
> > +  IN      UINTN                    Address,
> > +  IN      UINT8                    Mask,
> > +  IN      UINT8                    Value
> > +  )
> > +{
> > +  *(volatile UINT8*)Address = (*(volatile UINT8*)Address & ~Mask) | Value;
> > +  return *(volatile UINT8*)Address;
> > +}
> > +
> > +/**
> > +  Clear and set a 16-bit MMIO register in Big Endian format.
> > +
> > +  Mask the 16-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 16-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioClearSetBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Mask,
> > +  IN      UINT16                    Value
> > +  )
> > +{
> > +  ASSERT ((Address & 1) == 0);
> > +  *(volatile UINT16*)Address = (*(volatile UINT16*)Address &
> > Uswap16(~Mask))
> > +								 |
> > Uswap16(Value);
> > +  return *(volatile UINT16*)Address;
> > +}
> > +
> > +/**
> > +  Clear and set a 32-bit MMIO register in Big Endian format.
> > +
> > +  Mask the 32-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 32-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioClearSetBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Mask,
> > +  IN      UINT32                    Value
> > +  )
> > +{
> > +  ASSERT ((Address & 3) == 0);
> > +  *(volatile UINT32*)Address = (*(volatile UINT32*)Address &
> > Uswap32(~Mask))
> > +								 |
> > Uswap32(Value);
> > +  return *(volatile UINT32*)Address;
> > +}
> > +
> > +/**
> > +  Clear and set a 64-bit MMIO register in Big Endian format.
> > +
> > +  Mask the 64-bit MMIO register specified by Address with the mask
> > specified
> > +  by Mask and then Writes the 64-bit MMIO register specified by Address
> > with
> > +  the value specified by Value and returns current value on register. This
> > +  function must guarantee that all MMIO read and write operations are
> > serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Mask to clear the MMIO register.
> > +  @param  Value   The value to write to the MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioClearSetBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Mask,
> > +  IN      UINT64                    Value
> > +  )
> > +{
> > +  ASSERT ((Address & 7) == 0);
> > +  *(volatile UINT64*)Address = (*(volatile UINT64*)Address &
> > Uswap64(~Mask))
> > +								|
> > Uswap64(Value);
> > +  return *(volatile UINT64*)Address;
> > +}
> > +
> > +/**
> > +  Set a 8-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 8-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 8-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT8
> > +EFIAPI
> > +MmioSetBits8 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT8                     Bits
> > +  )
> > +{
> > +  *(volatile UINT8*)Address = *(volatile UINT8*)Address | Bits;
> > +  return *(volatile UINT8*)Address;
> > +}
> > +
> > +/**
> > +  Set a 16-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 16-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioSetBitsBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Bits
> > +  )
> > +{
> > +  ASSERT ((Address & 1) == 0);
> > +  *(volatile UINT16*)Address = *(volatile UINT16*)Address | Uswap16(Bits);
> > +  return *(volatile UINT16*)Address;
> > +}
> > +
> > +/**
> > +  Set a 32-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 32-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioSetBitsBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Bits
> > +  )
> > +{
> > +  ASSERT ((Address & 3) == 0);
> > +  *(volatile UINT32*)Address = *(volatile UINT32*)Address | Uswap32(Bits);
> > +  return *(volatile UINT32*)Address;
> > +}
> > +
> > +/**
> > +  Set a 64-bit MMIO register in Big Endian format.
> > +
> > +  Set bits of the 64-bit MMIO register specified by Address with the Bits
> > +  specified by Bits and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Bits    The Bits to set in MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioSetBitsBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Bits
> > +  )
> > +{
> > +  ASSERT ((Address & 7) == 0);
> > +  *(volatile UINT64*)Address = *(volatile UINT64*)Address | Uswap64(Bits);
> > +  return *(volatile UINT64*)Address;
> > +}
> > +
> > +/**
> > +  Clear bits of the 8-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 8-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT8
> > +EFIAPI
> > +MmioClearBits8 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT8                     Mask
> > +  )
> > +{
> > +  *(volatile UINT8*)Address = *(volatile UINT8*)Address & (~Mask);
> > +  return *(volatile UINT8*)Address;
> > +}
> > +
> > +/**
> > +  Clear bits of the 16-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 16-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT16
> > +EFIAPI
> > +MmioClearBitsBe16 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT16                    Mask
> > +  )
> > +{
> > +  ASSERT ((Address & 1) == 0);
> > +  *(volatile UINT16*)Address = *(volatile UINT16*)Address &
> > Uswap16(~Mask);
> > +  return *(volatile UINT16*)Address;
> > +}
> > +
> > +/**
> > +  Clear bits of the 32-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 32-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT32
> > +EFIAPI
> > +MmioClearBitsBe32 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT32                    Mask
> > +  )
> > +{
> > +  ASSERT ((Address & 3) == 0);
> > +  *(volatile UINT32*)Address = *(volatile UINT32*)Address &
> > Uswap32(~Mask);
> > +  return *(volatile UINT32*)Address;
> > +}
> > +
> > +/**
> > +  Clear bits of the 64-bit MMIO register specified by Address with the Mask
> > +  specified by Mask and returns register content. This function must
> > +  guarantee that all MMIO read and write operations are serialized.
> > +
> > +  If 64-bit MMIO register operations are not supported, then ASSERT().
> > +
> > +  @param  Address The MMIO register to write.
> > +  @param  Mask    The Bits to clear in MMIO register.
> > +
> > +**/
> > +UINT64
> > +EFIAPI
> > +MmioClearBitsBe64 (
> > +  IN      UINTN                     Address,
> > +  IN      UINT64                    Mask
> > +  )
> > +{
> > +  ASSERT ((Address & 7) == 0);
> > +  *(volatile UINT64*)Address = *(volatile UINT64*)Address &
> > Uswap64(~Mask);
> > +  return *(volatile UINT64*)Address;
> > +}
> > --
> > 1.9.1
> >
> >
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-17  4:10   ` Kinney, Michael D
@ 2016-10-17  7:42     ` Ard Biesheuvel
  2016-10-17  9:57       ` Bhupesh Sharma
  0 siblings, 1 reply; 25+ messages in thread
From: Ard Biesheuvel @ 2016-10-17  7:42 UTC (permalink / raw)
  To: Kinney, Michael D; +Cc: Gao, Liming, Bhupesh Sharma, edk2-devel@ml01.01.org

On 17 October 2016 at 05:10, Kinney, Michael D
<michael.d.kinney@intel.com> wrote:
> Bhupesh,
>
> It is also possible to add an ARM specific PCD to select endianness and update
> MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that PCD in MmioRead/Write()
> APIs in that file to support both endian types.  You can use the SwapBytesxx()
> functions from BaseLib(as Laszlo suggested) based on the setting of this ARM
> specific PCD.
>
> Modules that link against this lib can select endianness by setting PCD in the
> scope of that module.
>
> The IPF version of IoLib uses an IPF specific PCD to translate I/O port accesses
> to MMIO accesses.  So there is already an example of an arch specific PCD in this
> lib instance.
>

This is not a platform wide thing, it is a per-device property whether
the MMIO occurs in big endian or little endian manner.

So I think Liming's suggestion makes sense: create an IoLib
implementation that performs the byte swapping, and selectively
incorporate it into drivers that require it using

BeMmioDeviceDxe.inf {
  <LibraryClasses>
    IoLib|SomePkg/Library/BigEndianIoLib.inf
}


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-17  7:42     ` Ard Biesheuvel
@ 2016-10-17  9:57       ` Bhupesh Sharma
  2017-10-13  6:07         ` Meenakshi Aggarwal
  0 siblings, 1 reply; 25+ messages in thread
From: Bhupesh Sharma @ 2016-10-17  9:57 UTC (permalink / raw)
  To: Ard Biesheuvel, Kinney, Michael D
  Cc: Gao, Liming, edk2-devel@ml01.01.org, Meenakshi Aggarwal

Hi Ard,

> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Monday, October 17, 2016 1:12 PM
> To: Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Gao, Liming <liming.gao@intel.com>; Bhupesh Sharma
> <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-
> endian MMIO
> 
> On 17 October 2016 at 05:10, Kinney, Michael D
> <michael.d.kinney@intel.com> wrote:
> > Bhupesh,
> >
> > It is also possible to add an ARM specific PCD to select endianness
> > and update MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that
> > PCD in MmioRead/Write() APIs in that file to support both endian
> > types.  You can use the SwapBytesxx() functions from BaseLib(as
> Laszlo
> > suggested) based on the setting of this ARM specific PCD.
> >
> > Modules that link against this lib can select endianness by setting
> > PCD in the scope of that module.
> >
> > The IPF version of IoLib uses an IPF specific PCD to translate I/O
> > port accesses to MMIO accesses.  So there is already an example of an
> > arch specific PCD in this lib instance.
> >
> 
> This is not a platform wide thing, it is a per-device property whether
> the MMIO occurs in big endian or little endian manner.
> 
> So I think Liming's suggestion makes sense: create an IoLib
> implementation that performs the byte swapping, and selectively
> incorporate it into drivers that require it using
> 
> BeMmioDeviceDxe.inf {
>   <LibraryClasses>
>     IoLib|SomePkg/Library/BigEndianIoLib.inf
> }

That's correct. I think creating a separate IoLib for byte-swapping makes sense.

We will rework the patch accordingly.

Regards,
Bhupesh

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2016-10-17  9:57       ` Bhupesh Sharma
@ 2017-10-13  6:07         ` Meenakshi Aggarwal
  2017-10-16  3:17           ` Gao, Liming
  0 siblings, 1 reply; 25+ messages in thread
From: Meenakshi Aggarwal @ 2017-10-13  6:07 UTC (permalink / raw)
  To: Ard Biesheuvel, Kinney, Michael D, edk2-devel@lists.01.org,
	Gao, Liming

Hi All,


It’s a pretty old discussion, we have left the upstreaming of NXP package in between because of some other work, but have started it again now.


Issue  : Few NXP modules support Big Endian MMIOs as these are ported from PowerPC.

Solution suggested : Create a separate library for BE MMIO APIs.


So what I have done is, I have created a separate library to support BE MMIO APIs and currently keeping it to my package.
This library is basically a wrapper over existing MMIO APIs.

UINT32
EFIAPI
BeMmioRead32 (
  IN  UINTN     Address
  )
{
  UINT32  Value;

  Value = MmioRead32(Address);

  return SwapBytes32(Value);
}


Need your opinion on below optinos:

1. Will this be a good idea to make this library a part of MdePkg? OR

2. Add a new file e.g. IoBeMmio.c like IoHighLevel.c in MdePkg/Library/BaseIoLibIntrinsic/
 And made these APIs a part of IoLib itself. OR

3. Keep this library internal to NXP package.


Please provide your inputs.


Thanks & Regards,
Meenakshi

> -----Original Message-----
> From: Bhupesh Sharma
> Sent: Monday, October 17, 2016 3:28 PM
> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> <michael.d.kinney@intel.com>
> Cc: Gao, Liming <liming.gao@intel.com>; edk2-devel@ml01.01.org;
> Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> Hi Ard,
> 
> > -----Original Message-----
> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> > Sent: Monday, October 17, 2016 1:12 PM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > Cc: Gao, Liming <liming.gao@intel.com>; Bhupesh Sharma
> > <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-
> > endian MMIO
> >
> > On 17 October 2016 at 05:10, Kinney, Michael D
> > <michael.d.kinney@intel.com> wrote:
> > > Bhupesh,
> > >
> > > It is also possible to add an ARM specific PCD to select endianness
> > > and update MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that
> > > PCD in MmioRead/Write() APIs in that file to support both endian
> > > types.  You can use the SwapBytesxx() functions from BaseLib(as
> > Laszlo
> > > suggested) based on the setting of this ARM specific PCD.
> > >
> > > Modules that link against this lib can select endianness by setting
> > > PCD in the scope of that module.
> > >
> > > The IPF version of IoLib uses an IPF specific PCD to translate I/O
> > > port accesses to MMIO accesses.  So there is already an example of
> > > an arch specific PCD in this lib instance.
> > >
> >
> > This is not a platform wide thing, it is a per-device property whether
> > the MMIO occurs in big endian or little endian manner.
> >
> > So I think Liming's suggestion makes sense: create an IoLib
> > implementation that performs the byte swapping, and selectively
> > incorporate it into drivers that require it using
> >
> > BeMmioDeviceDxe.inf {
> >   <LibraryClasses>
> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > }
> 
> That's correct. I think creating a separate IoLib for byte-swapping makes
> sense.
> 
> We will rework the patch accordingly.
> 
> Regards,
> Bhupesh

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-10-13  6:07         ` Meenakshi Aggarwal
@ 2017-10-16  3:17           ` Gao, Liming
  2017-10-23  7:07             ` Udit Kumar
  0 siblings, 1 reply; 25+ messages in thread
From: Gao, Liming @ 2017-10-16  3:17 UTC (permalink / raw)
  To: Meenakshi Aggarwal, Ard Biesheuvel, Kinney, Michael D,
	edk2-devel@lists.01.org

Meenakshi:
  I suggest to introduce new IoLib library instance, not to add new IoLib APIs. New IoLib library instance will perform IO operation as the big endian. You can update MdePkg/Library/BaseIoLibIntrinsic instance, add new source file and new INF for it. 

UINT32
EFIAPI
MmioRead32 (
  IN  UINTN     Address
  )
{
  UINT32                            Value;

  ASSERT ((Address & 3) == 0);
  Value = *(volatile UINT32*)Address;
  return SwapBytes32(Value);
}

Thanks
Liming
>-----Original Message-----
>From: Meenakshi Aggarwal [mailto:meenakshi.aggarwal@nxp.com]
>Sent: Friday, October 13, 2017 2:07 PM
>To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
><michael.d.kinney@intel.com>; edk2-devel@lists.01.org; Gao, Liming
><liming.gao@intel.com>
>Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
>MMIO
>
>Hi All,
>
>
>It’s a pretty old discussion, we have left the upstreaming of NXP package in
>between because of some other work, but have started it again now.
>
>
>Issue  : Few NXP modules support Big Endian MMIOs as these are ported from
>PowerPC.
>
>Solution suggested : Create a separate library for BE MMIO APIs.
>
>
>So what I have done is, I have created a separate library to support BE MMIO
>APIs and currently keeping it to my package.
>This library is basically a wrapper over existing MMIO APIs.
>
>UINT32
>EFIAPI
>BeMmioRead32 (
>  IN  UINTN     Address
>  )
>{
>  UINT32  Value;
>
>  Value = MmioRead32(Address);
>
>  return SwapBytes32(Value);
>}
>
>
>Need your opinion on below optinos:
>
>1. Will this be a good idea to make this library a part of MdePkg? OR
>
>2. Add a new file e.g. IoBeMmio.c like IoHighLevel.c in
>MdePkg/Library/BaseIoLibIntrinsic/
> And made these APIs a part of IoLib itself. OR
>
>3. Keep this library internal to NXP package.
>
>
>Please provide your inputs.
>
>
>Thanks & Regards,
>Meenakshi
>
>> -----Original Message-----
>> From: Bhupesh Sharma
>> Sent: Monday, October 17, 2016 3:28 PM
>> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
>> <michael.d.kinney@intel.com>
>> Cc: Gao, Liming <liming.gao@intel.com>; edk2-devel@ml01.01.org;
>> Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
>> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
>> MMIO
>>
>> Hi Ard,
>>
>> > -----Original Message-----
>> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
>> > Sent: Monday, October 17, 2016 1:12 PM
>> > To: Kinney, Michael D <michael.d.kinney@intel.com>
>> > Cc: Gao, Liming <liming.gao@intel.com>; Bhupesh Sharma
>> > <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
>> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-
>> > endian MMIO
>> >
>> > On 17 October 2016 at 05:10, Kinney, Michael D
>> > <michael.d.kinney@intel.com> wrote:
>> > > Bhupesh,
>> > >
>> > > It is also possible to add an ARM specific PCD to select endianness
>> > > and update MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that
>> > > PCD in MmioRead/Write() APIs in that file to support both endian
>> > > types.  You can use the SwapBytesxx() functions from BaseLib(as
>> > Laszlo
>> > > suggested) based on the setting of this ARM specific PCD.
>> > >
>> > > Modules that link against this lib can select endianness by setting
>> > > PCD in the scope of that module.
>> > >
>> > > The IPF version of IoLib uses an IPF specific PCD to translate I/O
>> > > port accesses to MMIO accesses.  So there is already an example of
>> > > an arch specific PCD in this lib instance.
>> > >
>> >
>> > This is not a platform wide thing, it is a per-device property whether
>> > the MMIO occurs in big endian or little endian manner.
>> >
>> > So I think Liming's suggestion makes sense: create an IoLib
>> > implementation that performs the byte swapping, and selectively
>> > incorporate it into drivers that require it using
>> >
>> > BeMmioDeviceDxe.inf {
>> >   <LibraryClasses>
>> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
>> > }
>>
>> That's correct. I think creating a separate IoLib for byte-swapping makes
>> sense.
>>
>> We will rework the patch accordingly.
>>
>> Regards,
>> Bhupesh

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-10-16  3:17           ` Gao, Liming
@ 2017-10-23  7:07             ` Udit Kumar
  2017-11-27  6:06               ` Meenakshi Aggarwal
  0 siblings, 1 reply; 25+ messages in thread
From: Udit Kumar @ 2017-10-23  7:07 UTC (permalink / raw)
  To: Gao, Liming, Meenakshi Aggarwal, Ard Biesheuvel,
	Kinney, Michael D, edk2-devel@lists.01.org

Hi Meenakshi/Liming, 
My 2 cents, around this. 

1)
Having a new lib for BE read might not be helpful for us, 
e.g. a IP which is in BE mode access the UART for print or system registers which are in LE, 
then with new Lib, we will get all read/write in BE mode 

2)
Especially for our IPs, which are changing from BE to LE depending on platform. 
As said before, having BE read lib with API name of MmioRead32 etc, will not help (I guess Meenakshi already seen some problems around this)
Adding a new lib with MmioRead32BE API name could help, but IP driver we need to take care of IP mode either by Pcd or #define, to select MmioRead32 or MmioRead32BE. 
This conditional compile needs to be done for all IPs (which works in BE/LE mode on different platforms). 

My preferred way of implementation to use one function in IP driver, 
And based on IP mode, do the switch. 

New Lib could have function like below 
MmioRead32Generic(IN  UINTN     Address, BOOL IsIPBE) {
   UINT32                            Value;
 
   ASSERT ((Address & 3) == 0);
   Value = *(volatile UINT32*)Address;
   If(IsIPBE)
     Value = SwapBytes32(Value);
 return  Value;
}

And IP driver can use it 
MmioRead32Generic(ADDR, FixedPcdGet(This_IP_Mode_For_This_platform)

Comments are welcome. 

Regards
Udit

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Gao,
> Liming
> Sent: Monday, October 16, 2017 8:48 AM
> To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>; Kinney, Michael D <michael.d.kinney@intel.com>;
> edk2-devel@lists.01.org
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> Meenakshi:
>   I suggest to introduce new IoLib library instance, not to add new IoLib APIs.
> New IoLib library instance will perform IO operation as the big endian. You can
> update MdePkg/Library/BaseIoLibIntrinsic instance, add new source file and
> new INF for it.
> 
> UINT32
> EFIAPI
> MmioRead32 (
>   IN  UINTN     Address
>   )
> {
>   UINT32                            Value;
> 
>   ASSERT ((Address & 3) == 0);
>   Value = *(volatile UINT32*)Address;
>   return SwapBytes32(Value);
> }
> 
> Thanks
> Liming
> >-----Original Message-----
> >From: Meenakshi Aggarwal [mailto:meenakshi.aggarwal@nxp.com]
> >Sent: Friday, October 13, 2017 2:07 PM
> >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> ><michael.d.kinney@intel.com>; edk2-devel@lists.01.org; Gao, Liming
> ><liming.gao@intel.com>
> >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> >big-endian MMIO
> >
> >Hi All,
> >
> >
> >It’s a pretty old discussion, we have left the upstreaming of NXP
> >package in between because of some other work, but have started it again
> now.
> >
> >
> >Issue  : Few NXP modules support Big Endian MMIOs as these are ported
> >from PowerPC.
> >
> >Solution suggested : Create a separate library for BE MMIO APIs.
> >
> >
> >So what I have done is, I have created a separate library to support BE
> >MMIO APIs and currently keeping it to my package.
> >This library is basically a wrapper over existing MMIO APIs.
> >
> >UINT32
> >EFIAPI
> >BeMmioRead32 (
> >  IN  UINTN     Address
> >  )
> >{
> >  UINT32  Value;
> >
> >  Value = MmioRead32(Address);
> >
> >  return SwapBytes32(Value);
> >}
> >
> >
> >Need your opinion on below optinos:
> >
> >1. Will this be a good idea to make this library a part of MdePkg? OR
> >
> >2. Add a new file e.g. IoBeMmio.c like IoHighLevel.c in
> >MdePkg/Library/BaseIoLibIntrinsic/
> > And made these APIs a part of IoLib itself. OR
> >
> >3. Keep this library internal to NXP package.
> >
> >
> >Please provide your inputs.
> >
> >
> >Thanks & Regards,
> >Meenakshi
> >
> >> -----Original Message-----
> >> From: Bhupesh Sharma
> >> Sent: Monday, October 17, 2016 3:28 PM
> >> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> >> <michael.d.kinney@intel.com>
> >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-devel@ml01.01.org;
> >> Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> >> big-endian MMIO
> >>
> >> Hi Ard,
> >>
> >> > -----Original Message-----
> >> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> >> > Sent: Monday, October 17, 2016 1:12 PM
> >> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> >> > Cc: Gao, Liming <liming.gao@intel.com>; Bhupesh Sharma
> >> > <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
> >> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-
> >> > endian MMIO
> >> >
> >> > On 17 October 2016 at 05:10, Kinney, Michael D
> >> > <michael.d.kinney@intel.com> wrote:
> >> > > Bhupesh,
> >> > >
> >> > > It is also possible to add an ARM specific PCD to select
> >> > > endianness and update
> >> > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that PCD in
> >> > > MmioRead/Write() APIs in that file to support both endian types.
> >> > > You can use the SwapBytesxx() functions from BaseLib(as
> >> > Laszlo
> >> > > suggested) based on the setting of this ARM specific PCD.
> >> > >
> >> > > Modules that link against this lib can select endianness by
> >> > > setting PCD in the scope of that module.
> >> > >
> >> > > The IPF version of IoLib uses an IPF specific PCD to translate
> >> > > I/O port accesses to MMIO accesses.  So there is already an
> >> > > example of an arch specific PCD in this lib instance.
> >> > >
> >> >
> >> > This is not a platform wide thing, it is a per-device property
> >> > whether the MMIO occurs in big endian or little endian manner.
> >> >
> >> > So I think Liming's suggestion makes sense: create an IoLib
> >> > implementation that performs the byte swapping, and selectively
> >> > incorporate it into drivers that require it using
> >> >
> >> > BeMmioDeviceDxe.inf {
> >> >   <LibraryClasses>
> >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> >> > }
> >>
> >> That's correct. I think creating a separate IoLib for byte-swapping
> >> makes sense.
> >>
> >> We will rework the patch accordingly.
> >>
> >> Regards,
> >> Bhupesh
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-10-23  7:07             ` Udit Kumar
@ 2017-11-27  6:06               ` Meenakshi Aggarwal
  2017-11-27 11:07                 ` Leif Lindholm
  2017-11-29 12:51                 ` Leif Lindholm
  0 siblings, 2 replies; 25+ messages in thread
From: Meenakshi Aggarwal @ 2017-11-27  6:06 UTC (permalink / raw)
  To: edk2-devel@lists.01.org, Leif Lindholm
  Cc: Udit Kumar, Gao, Liming, Ard Biesheuvel, Kinney, Michael D

Hi Leif,

This is regarding Big-Endian Library patch ([PATCH v2 1/9] Platform/NXP: Add support for Big Endian Mmio APIs)

We have started this discussion before and the suggestion was to create a separate .inf file keeping APIs name same e.g. MmioRead/MmioWrite in MdePkg.

But we can't go with this approach (reason mentioned by Udit).


So please suggest if we should keep this library under Platform/NXP or I send a new patch moving this library in MdePkg.

But we have to keep a different name for Big Endian MMIO APIs.


Thanks,
Meenakshi


> -----Original Message-----
> From: Udit Kumar
> Sent: Monday, October 23, 2017 12:38 PM
> To: Gao, Liming <liming.gao@intel.com>; Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>; Kinney, Michael D
> <michael.d.kinney@intel.com>; edk2-devel@lists.01.org
> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> Hi Meenakshi/Liming,
> My 2 cents, around this.
> 
> 1)
> Having a new lib for BE read might not be helpful for us, e.g. a IP which is in
> BE mode access the UART for print or system registers which are in LE, then
> with new Lib, we will get all read/write in BE mode
> 
> 2)
> Especially for our IPs, which are changing from BE to LE depending on
> platform.
> As said before, having BE read lib with API name of MmioRead32 etc, will not
> help (I guess Meenakshi already seen some problems around this) Adding a
> new lib with MmioRead32BE API name could help, but IP driver we need to
> take care of IP mode either by Pcd or #define, to select MmioRead32 or
> MmioRead32BE.
> This conditional compile needs to be done for all IPs (which works in BE/LE
> mode on different platforms).
> 
> My preferred way of implementation to use one function in IP driver, And
> based on IP mode, do the switch.
> 
> New Lib could have function like below
> MmioRead32Generic(IN  UINTN     Address, BOOL IsIPBE) {
>    UINT32                            Value;
> 
>    ASSERT ((Address & 3) == 0);
>    Value = *(volatile UINT32*)Address;
>    If(IsIPBE)
>      Value = SwapBytes32(Value);
>  return  Value;
> }
> 
> And IP driver can use it
> MmioRead32Generic(ADDR,
> FixedPcdGet(This_IP_Mode_For_This_platform)
> 
> Comments are welcome.
> 
> Regards
> Udit
> 
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> > Gao, Liming
> > Sent: Monday, October 16, 2017 8:48 AM
> > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > <michael.d.kinney@intel.com>; edk2-devel@lists.01.org
> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > big-endian MMIO
> >
> > Meenakshi:
> >   I suggest to introduce new IoLib library instance, not to add new IoLib
> APIs.
> > New IoLib library instance will perform IO operation as the big
> > endian. You can update MdePkg/Library/BaseIoLibIntrinsic instance, add
> > new source file and new INF for it.
> >
> > UINT32
> > EFIAPI
> > MmioRead32 (
> >   IN  UINTN     Address
> >   )
> > {
> >   UINT32                            Value;
> >
> >   ASSERT ((Address & 3) == 0);
> >   Value = *(volatile UINT32*)Address;
> >   return SwapBytes32(Value);
> > }
> >
> > Thanks
> > Liming
> > >-----Original Message-----
> > >From: Meenakshi Aggarwal [mailto:meenakshi.aggarwal@nxp.com]
> > >Sent: Friday, October 13, 2017 2:07 PM
> > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > ><michael.d.kinney@intel.com>; edk2-devel@lists.01.org; Gao, Liming
> > ><liming.gao@intel.com>
> > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > >big-endian MMIO
> > >
> > >Hi All,
> > >
> > >
> > >It’s a pretty old discussion, we have left the upstreaming of NXP
> > >package in between because of some other work, but have started it
> > >again
> > now.
> > >
> > >
> > >Issue  : Few NXP modules support Big Endian MMIOs as these are ported
> > >from PowerPC.
> > >
> > >Solution suggested : Create a separate library for BE MMIO APIs.
> > >
> > >
> > >So what I have done is, I have created a separate library to support
> > >BE MMIO APIs and currently keeping it to my package.
> > >This library is basically a wrapper over existing MMIO APIs.
> > >
> > >UINT32
> > >EFIAPI
> > >BeMmioRead32 (
> > >  IN  UINTN     Address
> > >  )
> > >{
> > >  UINT32  Value;
> > >
> > >  Value = MmioRead32(Address);
> > >
> > >  return SwapBytes32(Value);
> > >}
> > >
> > >
> > >Need your opinion on below optinos:
> > >
> > >1. Will this be a good idea to make this library a part of MdePkg? OR
> > >
> > >2. Add a new file e.g. IoBeMmio.c like IoHighLevel.c in
> > >MdePkg/Library/BaseIoLibIntrinsic/
> > > And made these APIs a part of IoLib itself. OR
> > >
> > >3. Keep this library internal to NXP package.
> > >
> > >
> > >Please provide your inputs.
> > >
> > >
> > >Thanks & Regards,
> > >Meenakshi
> > >
> > >> -----Original Message-----
> > >> From: Bhupesh Sharma
> > >> Sent: Monday, October 17, 2016 3:28 PM
> > >> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > >> <michael.d.kinney@intel.com>
> > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-devel@ml01.01.org;
> > >> Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > >> big-endian MMIO
> > >>
> > >> Hi Ard,
> > >>
> > >> > -----Original Message-----
> > >> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> > >> > Sent: Monday, October 17, 2016 1:12 PM
> > >> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > >> > Cc: Gao, Liming <liming.gao@intel.com>; Bhupesh Sharma
> > >> > <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
> > >> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > >> > big- endian MMIO
> > >> >
> > >> > On 17 October 2016 at 05:10, Kinney, Michael D
> > >> > <michael.d.kinney@intel.com> wrote:
> > >> > > Bhupesh,
> > >> > >
> > >> > > It is also possible to add an ARM specific PCD to select
> > >> > > endianness and update
> > >> > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that PCD in
> > >> > > MmioRead/Write() APIs in that file to support both endian types.
> > >> > > You can use the SwapBytesxx() functions from BaseLib(as
> > >> > Laszlo
> > >> > > suggested) based on the setting of this ARM specific PCD.
> > >> > >
> > >> > > Modules that link against this lib can select endianness by
> > >> > > setting PCD in the scope of that module.
> > >> > >
> > >> > > The IPF version of IoLib uses an IPF specific PCD to translate
> > >> > > I/O port accesses to MMIO accesses.  So there is already an
> > >> > > example of an arch specific PCD in this lib instance.
> > >> > >
> > >> >
> > >> > This is not a platform wide thing, it is a per-device property
> > >> > whether the MMIO occurs in big endian or little endian manner.
> > >> >
> > >> > So I think Liming's suggestion makes sense: create an IoLib
> > >> > implementation that performs the byte swapping, and selectively
> > >> > incorporate it into drivers that require it using
> > >> >
> > >> > BeMmioDeviceDxe.inf {
> > >> >   <LibraryClasses>
> > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > >> > }
> > >>
> > >> That's correct. I think creating a separate IoLib for byte-swapping
> > >> makes sense.
> > >>
> > >> We will rework the patch accordingly.
> > >>
> > >> Regards,
> > >> Bhupesh
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-11-27  6:06               ` Meenakshi Aggarwal
@ 2017-11-27 11:07                 ` Leif Lindholm
  2017-11-29 12:51                 ` Leif Lindholm
  1 sibling, 0 replies; 25+ messages in thread
From: Leif Lindholm @ 2017-11-27 11:07 UTC (permalink / raw)
  To: Meenakshi Aggarwal
  Cc: edk2-devel@lists.01.org, Udit Kumar, Gao, Liming, Ard Biesheuvel,
	Kinney, Michael D

On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi Aggarwal wrote:
> Hi Leif,
> 
> This is regarding Big-Endian Library patch ([PATCH v2 1/9]
> Platform/NXP: Add support for Big Endian Mmio APIs)
> 
> We have started this discussion before and the suggestion was to
> create a separate .inf file keeping APIs name same
> e.g. MmioRead/MmioWrite in MdePkg.
> 
> But we can't go with this approach (reason mentioned by Udit).
> 
> 
> So please suggest if we should keep this library under Platform/NXP
> or I send a new patch moving this library in MdePkg.

For now, absolutely keep it under Platform/NXP.

I do believe this will naturally make its way into edk2 at some point
in the future. Perhaps then as an alternative IoLib implementation to
override specific drivers (as suggested in the original thread).

> But we have to keep a different name for Big Endian MMIO APIs.

Sure.

Regards,

Leif


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-11-27  6:06               ` Meenakshi Aggarwal
  2017-11-27 11:07                 ` Leif Lindholm
@ 2017-11-29 12:51                 ` Leif Lindholm
  2017-11-29 19:25                   ` Kinney, Michael D
  1 sibling, 1 reply; 25+ messages in thread
From: Leif Lindholm @ 2017-11-29 12:51 UTC (permalink / raw)
  To: Meenakshi Aggarwal, Gao, Liming
  Cc: edk2-devel@lists.01.org, Udit Kumar, Ard Biesheuvel,
	Kinney, Michael D

Hi Meenakshi,

I finally got around to looking at the watchdog code (that uses this
library), and that has convinced me the best solution is to do what
Liming proposed.

Looking at this snippet:

> +STATIC
> +UINT16
> +EFIAPI
> +WdogRead (
> +  IN  UINTN     Address
> +  )
> +{
> +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> +    return BeMmioRead16 (Address);
> +  } else {
> +    return MmioRead16(Address);
> +  }

This is actually a pretty good demonstration of the arguments that
were made with regards to how the BeIoLib could be just another
implementation of IoLib.

You would then just do (in your .dsc):
  Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
    IoLib|<path to BeIoLib .inf>
  }

This causes the big-endian version of the library to be used for this
component. This makes these Wdog<access> functions and the Pcd
redundant, and the rest of the code can use MmioRead16()/MmioWrite16()
directly.

But then, it is not really a big-endian or litte-endian version of the
library we need. We always know which endianness we are building for.
What we need is a byteswapping flavour of IoLib.

So Liming, what if we do something like adding a
MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwap.inf
---
[Defines]
  INF_VERSION                    = 0x0001001A
  BASE_NAME                      = BaseIoLibIntrinsicSwap
  MODULE_UNI_FILE                = BaseIoLibIntrinsic.uni
  FILE_GUID                      = d4a60d44-3688-4a50-b2d0-5c6fc2422523
  MODULE_TYPE                    = BASE
  VERSION_STRING                 = 1.0
  LIBRARY_CLASS                  = IoLib


#
#  VALID_ARCHITECTURES           = IA32 X64 EBC IPF ARM AARCH64
#

[Sources]
  BaseIoLibIntrinsicInternal.h
  IoHighLevel.c
  IoLib.c
  IoLibEbc.c         # Asserts on all i/o port accesses
  IoLibMmioBuffer.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  DebugLib
  BaseLib

[BuildOptions]
  GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
---

And then add

#ifdef SWAP_BYTES
  return SwapBytesXX (Value);
#else
  return Value;
#fi

for the read operations and

#ifdef SWAP_BYTES
  *(type)Address = SwapBytesXX (Value);
#else
  *(type)Address = Value;
#fi

for the write operations in IoLib.c?

/
    Leif

On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi Aggarwal wrote:
> Hi Leif,
> 
> This is regarding Big-Endian Library patch ([PATCH v2 1/9]
> Platform/NXP: Add support for Big Endian Mmio APIs)
> 
> We have started this discussion before and the suggestion was to
> create a separate .inf file keeping APIs name same
> e.g. MmioRead/MmioWrite in MdePkg.
> 
> But we can't go with this approach (reason mentioned by Udit).
> 
> So please suggest if we should keep this library under Platform/NXP
> or I send a new patch moving this library in MdePkg.
> 
> But we have to keep a different name for Big Endian MMIO APIs.
> 
> 
> Thanks,
> Meenakshi
> 
> 
> > -----Original Message-----
> > From: Udit Kumar
> > Sent: Monday, October 23, 2017 12:38 PM
> > To: Gao, Liming <liming.gao@intel.com>; Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > <michael.d.kinney@intel.com>; edk2-devel@lists.01.org
> > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> > MMIO
> > 
> > Hi Meenakshi/Liming,
> > My 2 cents, around this.
> > 
> > 1)
> > Having a new lib for BE read might not be helpful for us, e.g. a IP which is in
> > BE mode access the UART for print or system registers which are in LE, then
> > with new Lib, we will get all read/write in BE mode
> > 
> > 2)
> > Especially for our IPs, which are changing from BE to LE depending on
> > platform.
> > As said before, having BE read lib with API name of MmioRead32 etc, will not
> > help (I guess Meenakshi already seen some problems around this) Adding a
> > new lib with MmioRead32BE API name could help, but IP driver we need to
> > take care of IP mode either by Pcd or #define, to select MmioRead32 or
> > MmioRead32BE.
> > This conditional compile needs to be done for all IPs (which works in BE/LE
> > mode on different platforms).
> > 
> > My preferred way of implementation to use one function in IP driver, And
> > based on IP mode, do the switch.
> > 
> > New Lib could have function like below
> > MmioRead32Generic(IN  UINTN     Address, BOOL IsIPBE) {
> >    UINT32                            Value;
> > 
> >    ASSERT ((Address & 3) == 0);
> >    Value = *(volatile UINT32*)Address;
> >    If(IsIPBE)
> >      Value = SwapBytes32(Value);
> >  return  Value;
> > }
> > 
> > And IP driver can use it
> > MmioRead32Generic(ADDR,
> > FixedPcdGet(This_IP_Mode_For_This_platform)
> > 
> > Comments are welcome.
> > 
> > Regards
> > Udit
> > 
> > > -----Original Message-----
> > > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> > > Gao, Liming
> > > Sent: Monday, October 16, 2017 8:48 AM
> > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > <michael.d.kinney@intel.com>; edk2-devel@lists.01.org
> > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > > big-endian MMIO
> > >
> > > Meenakshi:
> > >   I suggest to introduce new IoLib library instance, not to add new IoLib
> > APIs.
> > > New IoLib library instance will perform IO operation as the big
> > > endian. You can update MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > new source file and new INF for it.
> > >
> > > UINT32
> > > EFIAPI
> > > MmioRead32 (
> > >   IN  UINTN     Address
> > >   )
> > > {
> > >   UINT32                            Value;
> > >
> > >   ASSERT ((Address & 3) == 0);
> > >   Value = *(volatile UINT32*)Address;
> > >   return SwapBytes32(Value);
> > > }
> > >
> > > Thanks
> > > Liming
> > > >-----Original Message-----
> > > >From: Meenakshi Aggarwal [mailto:meenakshi.aggarwal@nxp.com]
> > > >Sent: Friday, October 13, 2017 2:07 PM
> > > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > ><michael.d.kinney@intel.com>; edk2-devel@lists.01.org; Gao, Liming
> > > ><liming.gao@intel.com>
> > > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > > >big-endian MMIO
> > > >
> > > >Hi All,
> > > >
> > > >
> > > >It’s a pretty old discussion, we have left the upstreaming of NXP
> > > >package in between because of some other work, but have started it
> > > >again
> > > now.
> > > >
> > > >
> > > >Issue  : Few NXP modules support Big Endian MMIOs as these are ported
> > > >from PowerPC.
> > > >
> > > >Solution suggested : Create a separate library for BE MMIO APIs.
> > > >
> > > >
> > > >So what I have done is, I have created a separate library to support
> > > >BE MMIO APIs and currently keeping it to my package.
> > > >This library is basically a wrapper over existing MMIO APIs.
> > > >
> > > >UINT32
> > > >EFIAPI
> > > >BeMmioRead32 (
> > > >  IN  UINTN     Address
> > > >  )
> > > >{
> > > >  UINT32  Value;
> > > >
> > > >  Value = MmioRead32(Address);
> > > >
> > > >  return SwapBytes32(Value);
> > > >}
> > > >
> > > >
> > > >Need your opinion on below optinos:
> > > >
> > > >1. Will this be a good idea to make this library a part of MdePkg? OR
> > > >
> > > >2. Add a new file e.g. IoBeMmio.c like IoHighLevel.c in
> > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > And made these APIs a part of IoLib itself. OR
> > > >
> > > >3. Keep this library internal to NXP package.
> > > >
> > > >
> > > >Please provide your inputs.
> > > >
> > > >
> > > >Thanks & Regards,
> > > >Meenakshi
> > > >
> > > >> -----Original Message-----
> > > >> From: Bhupesh Sharma
> > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > >> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > >> <michael.d.kinney@intel.com>
> > > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-devel@ml01.01.org;
> > > >> Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > > >> big-endian MMIO
> > > >>
> > > >> Hi Ard,
> > > >>
> > > >> > -----Original Message-----
> > > >> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> > > >> > Sent: Monday, October 17, 2016 1:12 PM
> > > >> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > > >> > Cc: Gao, Liming <liming.gao@intel.com>; Bhupesh Sharma
> > > >> > <bhupesh.sharma@nxp.com>; edk2-devel@ml01.01.org
> > > >> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > > >> > big- endian MMIO
> > > >> >
> > > >> > On 17 October 2016 at 05:10, Kinney, Michael D
> > > >> > <michael.d.kinney@intel.com> wrote:
> > > >> > > Bhupesh,
> > > >> > >
> > > >> > > It is also possible to add an ARM specific PCD to select
> > > >> > > endianness and update
> > > >> > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that PCD in
> > > >> > > MmioRead/Write() APIs in that file to support both endian types.
> > > >> > > You can use the SwapBytesxx() functions from BaseLib(as
> > > >> > Laszlo
> > > >> > > suggested) based on the setting of this ARM specific PCD.
> > > >> > >
> > > >> > > Modules that link against this lib can select endianness by
> > > >> > > setting PCD in the scope of that module.
> > > >> > >
> > > >> > > The IPF version of IoLib uses an IPF specific PCD to translate
> > > >> > > I/O port accesses to MMIO accesses.  So there is already an
> > > >> > > example of an arch specific PCD in this lib instance.
> > > >> > >
> > > >> >
> > > >> > This is not a platform wide thing, it is a per-device property
> > > >> > whether the MMIO occurs in big endian or little endian manner.
> > > >> >
> > > >> > So I think Liming's suggestion makes sense: create an IoLib
> > > >> > implementation that performs the byte swapping, and selectively
> > > >> > incorporate it into drivers that require it using
> > > >> >
> > > >> > BeMmioDeviceDxe.inf {
> > > >> >   <LibraryClasses>
> > > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > >> > }
> > > >>
> > > >> That's correct. I think creating a separate IoLib for byte-swapping
> > > >> makes sense.
> > > >>
> > > >> We will rework the patch accordingly.
> > > >>
> > > >> Regards,
> > > >> Bhupesh
> > > _______________________________________________
> > > edk2-devel mailing list
> > > edk2-devel@lists.01.org
> > > https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-11-29 12:51                 ` Leif Lindholm
@ 2017-11-29 19:25                   ` Kinney, Michael D
  2017-11-29 19:48                     ` Leif Lindholm
  0 siblings, 1 reply; 25+ messages in thread
From: Kinney, Michael D @ 2017-11-29 19:25 UTC (permalink / raw)
  To: Leif Lindholm, Meenakshi Aggarwal, Gao, Liming, Kinney, Michael D
  Cc: edk2-devel@lists.01.org, Ard Biesheuvel

Leif,

I agree that this should be described as byte swapping.

What about a module that needs to access HW with and
without the bytes swapped?  It gets more complex if a
module is linked against several libs and some libs
access HW with bytes swapped and some do not.

Thanks,

Mike

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-
> bounces@lists.01.org] On Behalf Of Leif Lindholm
> Sent: Wednesday, November 29, 2017 4:51 AM
> To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>;
> Gao, Liming <liming.gao@intel.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> edk2-devel@lists.01.org; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support for big-endian MMIO
> 
> Hi Meenakshi,
> 
> I finally got around to looking at the watchdog code
> (that uses this
> library), and that has convinced me the best solution
> is to do what
> Liming proposed.
> 
> Looking at this snippet:
> 
> > +STATIC
> > +UINT16
> > +EFIAPI
> > +WdogRead (
> > +  IN  UINTN     Address
> > +  )
> > +{
> > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > +    return BeMmioRead16 (Address);
> > +  } else {
> > +    return MmioRead16(Address);
> > +  }
> 
> This is actually a pretty good demonstration of the
> arguments that
> were made with regards to how the BeIoLib could be just
> another
> implementation of IoLib.
> 
> You would then just do (in your .dsc):
>   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
>     IoLib|<path to BeIoLib .inf>
>   }
> 
> This causes the big-endian version of the library to be
> used for this
> component. This makes these Wdog<access> functions and
> the Pcd
> redundant, and the rest of the code can use
> MmioRead16()/MmioWrite16()
> directly.
> 
> But then, it is not really a big-endian or litte-endian
> version of the
> library we need. We always know which endianness we are
> building for.
> What we need is a byteswapping flavour of IoLib.
> 
> So Liming, what if we do something like adding a
> MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> p.inf
> ---
> [Defines]
>   INF_VERSION                    = 0x0001001A
>   BASE_NAME                      =
> BaseIoLibIntrinsicSwap
>   MODULE_UNI_FILE                =
> BaseIoLibIntrinsic.uni
>   FILE_GUID                      = d4a60d44-3688-4a50-
> b2d0-5c6fc2422523
>   MODULE_TYPE                    = BASE
>   VERSION_STRING                 = 1.0
>   LIBRARY_CLASS                  = IoLib
> 
> 
> #
> #  VALID_ARCHITECTURES           = IA32 X64 EBC IPF ARM
> AARCH64
> #
> 
> [Sources]
>   BaseIoLibIntrinsicInternal.h
>   IoHighLevel.c
>   IoLib.c
>   IoLibEbc.c         # Asserts on all i/o port accesses
>   IoLibMmioBuffer.c
> 
> [Packages]
>   MdePkg/MdePkg.dec
> 
> [LibraryClasses]
>   DebugLib
>   BaseLib
> 
> [BuildOptions]
>   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> ---
> 
> And then add
> 
> #ifdef SWAP_BYTES
>   return SwapBytesXX (Value);
> #else
>   return Value;
> #fi
> 
> for the read operations and
> 
> #ifdef SWAP_BYTES
>   *(type)Address = SwapBytesXX (Value);
> #else
>   *(type)Address = Value;
> #fi
> 
> for the write operations in IoLib.c?
> 
> /
>     Leif
> 
> On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi
> Aggarwal wrote:
> > Hi Leif,
> >
> > This is regarding Big-Endian Library patch ([PATCH v2
> 1/9]
> > Platform/NXP: Add support for Big Endian Mmio APIs)
> >
> > We have started this discussion before and the
> suggestion was to
> > create a separate .inf file keeping APIs name same
> > e.g. MmioRead/MmioWrite in MdePkg.
> >
> > But we can't go with this approach (reason mentioned
> by Udit).
> >
> > So please suggest if we should keep this library
> under Platform/NXP
> > or I send a new patch moving this library in MdePkg.
> >
> > But we have to keep a different name for Big Endian
> MMIO APIs.
> >
> >
> > Thanks,
> > Meenakshi
> >
> >
> > > -----Original Message-----
> > > From: Udit Kumar
> > > Sent: Monday, October 23, 2017 12:38 PM
> > > To: Gao, Liming <liming.gao@intel.com>; Meenakshi
> Aggarwal
> > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > <michael.d.kinney@intel.com>; edk2-
> devel@lists.01.org
> > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support for big-endian
> > > MMIO
> > >
> > > Hi Meenakshi/Liming,
> > > My 2 cents, around this.
> > >
> > > 1)
> > > Having a new lib for BE read might not be helpful
> for us, e.g. a IP which is in
> > > BE mode access the UART for print or system
> registers which are in LE, then
> > > with new Lib, we will get all read/write in BE mode
> > >
> > > 2)
> > > Especially for our IPs, which are changing from BE
> to LE depending on
> > > platform.
> > > As said before, having BE read lib with API name of
> MmioRead32 etc, will not
> > > help (I guess Meenakshi already seen some problems
> around this) Adding a
> > > new lib with MmioRead32BE API name could help, but
> IP driver we need to
> > > take care of IP mode either by Pcd or #define, to
> select MmioRead32 or
> > > MmioRead32BE.
> > > This conditional compile needs to be done for all
> IPs (which works in BE/LE
> > > mode on different platforms).
> > >
> > > My preferred way of implementation to use one
> function in IP driver, And
> > > based on IP mode, do the switch.
> > >
> > > New Lib could have function like below
> > > MmioRead32Generic(IN  UINTN     Address, BOOL
> IsIPBE) {
> > >    UINT32                            Value;
> > >
> > >    ASSERT ((Address & 3) == 0);
> > >    Value = *(volatile UINT32*)Address;
> > >    If(IsIPBE)
> > >      Value = SwapBytes32(Value);
> > >  return  Value;
> > > }
> > >
> > > And IP driver can use it
> > > MmioRead32Generic(ADDR,
> > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > >
> > > Comments are welcome.
> > >
> > > Regards
> > > Udit
> > >
> > > > -----Original Message-----
> > > > From: edk2-devel [mailto:edk2-devel-
> bounces@lists.01.org] On Behalf Of
> > > > Gao, Liming
> > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > To: Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > <michael.d.kinney@intel.com>; edk2-
> devel@lists.01.org
> > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support for
> > > > big-endian MMIO
> > > >
> > > > Meenakshi:
> > > >   I suggest to introduce new IoLib library
> instance, not to add new IoLib
> > > APIs.
> > > > New IoLib library instance will perform IO
> operation as the big
> > > > endian. You can update
> MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > new source file and new INF for it.
> > > >
> > > > UINT32
> > > > EFIAPI
> > > > MmioRead32 (
> > > >   IN  UINTN     Address
> > > >   )
> > > > {
> > > >   UINT32                            Value;
> > > >
> > > >   ASSERT ((Address & 3) == 0);
> > > >   Value = *(volatile UINT32*)Address;
> > > >   return SwapBytes32(Value);
> > > > }
> > > >
> > > > Thanks
> > > > Liming
> > > > >-----Original Message-----
> > > > >From: Meenakshi Aggarwal
> [mailto:meenakshi.aggarwal@nxp.com]
> > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> Kinney, Michael D
> > > > ><michael.d.kinney@intel.com>; edk2-
> devel@lists.01.org; Gao, Liming
> > > > ><liming.gao@intel.com>
> > > > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> Add support for
> > > > >big-endian MMIO
> > > > >
> > > > >Hi All,
> > > > >
> > > > >
> > > > >It’s a pretty old discussion, we have left the
> upstreaming of NXP
> > > > >package in between because of some other work,
> but have started it
> > > > >again
> > > > now.
> > > > >
> > > > >
> > > > >Issue  : Few NXP modules support Big Endian
> MMIOs as these are ported
> > > > >from PowerPC.
> > > > >
> > > > >Solution suggested : Create a separate library
> for BE MMIO APIs.
> > > > >
> > > > >
> > > > >So what I have done is, I have created a
> separate library to support
> > > > >BE MMIO APIs and currently keeping it to my
> package.
> > > > >This library is basically a wrapper over
> existing MMIO APIs.
> > > > >
> > > > >UINT32
> > > > >EFIAPI
> > > > >BeMmioRead32 (
> > > > >  IN  UINTN     Address
> > > > >  )
> > > > >{
> > > > >  UINT32  Value;
> > > > >
> > > > >  Value = MmioRead32(Address);
> > > > >
> > > > >  return SwapBytes32(Value);
> > > > >}
> > > > >
> > > > >
> > > > >Need your opinion on below optinos:
> > > > >
> > > > >1. Will this be a good idea to make this library
> a part of MdePkg? OR
> > > > >
> > > > >2. Add a new file e.g. IoBeMmio.c like
> IoHighLevel.c in
> > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > And made these APIs a part of IoLib itself. OR
> > > > >
> > > > >3. Keep this library internal to NXP package.
> > > > >
> > > > >
> > > > >Please provide your inputs.
> > > > >
> > > > >
> > > > >Thanks & Regards,
> > > > >Meenakshi
> > > > >
> > > > >> -----Original Message-----
> > > > >> From: Bhupesh Sharma
> > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > >> To: Ard Biesheuvel
> <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > >> <michael.d.kinney@intel.com>
> > > > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-
> devel@ml01.01.org;
> > > > >> Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>
> > > > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> Add support for
> > > > >> big-endian MMIO
> > > > >>
> > > > >> Hi Ard,
> > > > >>
> > > > >> > -----Original Message-----
> > > > >> > From: Ard Biesheuvel
> [mailto:ard.biesheuvel@linaro.org]
> > > > >> > Sent: Monday, October 17, 2016 1:12 PM
> > > > >> > To: Kinney, Michael D
> <michael.d.kinney@intel.com>
> > > > >> > Cc: Gao, Liming <liming.gao@intel.com>;
> Bhupesh Sharma
> > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> devel@ml01.01.org
> > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> MdePkg/IoLib: Add support for
> > > > >> > big- endian MMIO
> > > > >> >
> > > > >> > On 17 October 2016 at 05:10, Kinney, Michael
> D
> > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > >> > > Bhupesh,
> > > > >> > >
> > > > >> > > It is also possible to add an ARM specific
> PCD to select
> > > > >> > > endianness and update
> > > > >> > >
> MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use
> that PCD in
> > > > >> > > MmioRead/Write() APIs in that file to
> support both endian types.
> > > > >> > > You can use the SwapBytesxx() functions
> from BaseLib(as
> > > > >> > Laszlo
> > > > >> > > suggested) based on the setting of this
> ARM specific PCD.
> > > > >> > >
> > > > >> > > Modules that link against this lib can
> select endianness by
> > > > >> > > setting PCD in the scope of that module.
> > > > >> > >
> > > > >> > > The IPF version of IoLib uses an IPF
> specific PCD to translate
> > > > >> > > I/O port accesses to MMIO accesses.  So
> there is already an
> > > > >> > > example of an arch specific PCD in this
> lib instance.
> > > > >> > >
> > > > >> >
> > > > >> > This is not a platform wide thing, it is a
> per-device property
> > > > >> > whether the MMIO occurs in big endian or
> little endian manner.
> > > > >> >
> > > > >> > So I think Liming's suggestion makes sense:
> create an IoLib
> > > > >> > implementation that performs the byte
> swapping, and selectively
> > > > >> > incorporate it into drivers that require it
> using
> > > > >> >
> > > > >> > BeMmioDeviceDxe.inf {
> > > > >> >   <LibraryClasses>
> > > > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > >> > }
> > > > >>
> > > > >> That's correct. I think creating a separate
> IoLib for byte-swapping
> > > > >> makes sense.
> > > > >>
> > > > >> We will rework the patch accordingly.
> > > > >>
> > > > >> Regards,
> > > > >> Bhupesh
> > > > _______________________________________________
> > > > edk2-devel mailing list
> > > > edk2-devel@lists.01.org
> > > > https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-11-29 19:25                   ` Kinney, Michael D
@ 2017-11-29 19:48                     ` Leif Lindholm
  2017-11-30  4:15                       ` Meenakshi Aggarwal
  0 siblings, 1 reply; 25+ messages in thread
From: Leif Lindholm @ 2017-11-29 19:48 UTC (permalink / raw)
  To: Kinney, Michael D
  Cc: Meenakshi Aggarwal, Gao, Liming, edk2-devel@lists.01.org,
	Ard Biesheuvel

I guess there is no strict rule about a driver only directly accessing
one piece of HW?

Still, that would be one possible solution: breaking accesses to a
separate HW in need of byteswapping out into its own module and
letting it override IoLib version there.

Regards,

Leif

On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney, Michael D wrote:
> Leif,
> 
> I agree that this should be described as byte swapping.
> 
> What about a module that needs to access HW with and
> without the bytes swapped?  It gets more complex if a
> module is linked against several libs and some libs
> access HW with bytes swapped and some do not.
> 
> Thanks,
> 
> Mike
> 
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-
> > bounces@lists.01.org] On Behalf Of Leif Lindholm
> > Sent: Wednesday, November 29, 2017 4:51 AM
> > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>;
> > Gao, Liming <liming.gao@intel.com>
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > edk2-devel@lists.01.org; Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>
> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for big-endian MMIO
> > 
> > Hi Meenakshi,
> > 
> > I finally got around to looking at the watchdog code
> > (that uses this
> > library), and that has convinced me the best solution
> > is to do what
> > Liming proposed.
> > 
> > Looking at this snippet:
> > 
> > > +STATIC
> > > +UINT16
> > > +EFIAPI
> > > +WdogRead (
> > > +  IN  UINTN     Address
> > > +  )
> > > +{
> > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > +    return BeMmioRead16 (Address);
> > > +  } else {
> > > +    return MmioRead16(Address);
> > > +  }
> > 
> > This is actually a pretty good demonstration of the
> > arguments that
> > were made with regards to how the BeIoLib could be just
> > another
> > implementation of IoLib.
> > 
> > You would then just do (in your .dsc):
> >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> >     IoLib|<path to BeIoLib .inf>
> >   }
> > 
> > This causes the big-endian version of the library to be
> > used for this
> > component. This makes these Wdog<access> functions and
> > the Pcd
> > redundant, and the rest of the code can use
> > MmioRead16()/MmioWrite16()
> > directly.
> > 
> > But then, it is not really a big-endian or litte-endian
> > version of the
> > library we need. We always know which endianness we are
> > building for.
> > What we need is a byteswapping flavour of IoLib.
> > 
> > So Liming, what if we do something like adding a
> > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > p.inf
> > ---
> > [Defines]
> >   INF_VERSION                    = 0x0001001A
> >   BASE_NAME                      =
> > BaseIoLibIntrinsicSwap
> >   MODULE_UNI_FILE                =
> > BaseIoLibIntrinsic.uni
> >   FILE_GUID                      = d4a60d44-3688-4a50-
> > b2d0-5c6fc2422523
> >   MODULE_TYPE                    = BASE
> >   VERSION_STRING                 = 1.0
> >   LIBRARY_CLASS                  = IoLib
> > 
> > 
> > #
> > #  VALID_ARCHITECTURES           = IA32 X64 EBC IPF ARM
> > AARCH64
> > #
> > 
> > [Sources]
> >   BaseIoLibIntrinsicInternal.h
> >   IoHighLevel.c
> >   IoLib.c
> >   IoLibEbc.c         # Asserts on all i/o port accesses
> >   IoLibMmioBuffer.c
> > 
> > [Packages]
> >   MdePkg/MdePkg.dec
> > 
> > [LibraryClasses]
> >   DebugLib
> >   BaseLib
> > 
> > [BuildOptions]
> >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > ---
> > 
> > And then add
> > 
> > #ifdef SWAP_BYTES
> >   return SwapBytesXX (Value);
> > #else
> >   return Value;
> > #fi
> > 
> > for the read operations and
> > 
> > #ifdef SWAP_BYTES
> >   *(type)Address = SwapBytesXX (Value);
> > #else
> >   *(type)Address = Value;
> > #fi
> > 
> > for the write operations in IoLib.c?
> > 
> > /
> >     Leif
> > 
> > On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi
> > Aggarwal wrote:
> > > Hi Leif,
> > >
> > > This is regarding Big-Endian Library patch ([PATCH v2
> > 1/9]
> > > Platform/NXP: Add support for Big Endian Mmio APIs)
> > >
> > > We have started this discussion before and the
> > suggestion was to
> > > create a separate .inf file keeping APIs name same
> > > e.g. MmioRead/MmioWrite in MdePkg.
> > >
> > > But we can't go with this approach (reason mentioned
> > by Udit).
> > >
> > > So please suggest if we should keep this library
> > under Platform/NXP
> > > or I send a new patch moving this library in MdePkg.
> > >
> > > But we have to keep a different name for Big Endian
> > MMIO APIs.
> > >
> > >
> > > Thanks,
> > > Meenakshi
> > >
> > >
> > > > -----Original Message-----
> > > > From: Udit Kumar
> > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > To: Gao, Liming <liming.gao@intel.com>; Meenakshi
> > Aggarwal
> > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > <michael.d.kinney@intel.com>; edk2-
> > devel@lists.01.org
> > > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for big-endian
> > > > MMIO
> > > >
> > > > Hi Meenakshi/Liming,
> > > > My 2 cents, around this.
> > > >
> > > > 1)
> > > > Having a new lib for BE read might not be helpful
> > for us, e.g. a IP which is in
> > > > BE mode access the UART for print or system
> > registers which are in LE, then
> > > > with new Lib, we will get all read/write in BE mode
> > > >
> > > > 2)
> > > > Especially for our IPs, which are changing from BE
> > to LE depending on
> > > > platform.
> > > > As said before, having BE read lib with API name of
> > MmioRead32 etc, will not
> > > > help (I guess Meenakshi already seen some problems
> > around this) Adding a
> > > > new lib with MmioRead32BE API name could help, but
> > IP driver we need to
> > > > take care of IP mode either by Pcd or #define, to
> > select MmioRead32 or
> > > > MmioRead32BE.
> > > > This conditional compile needs to be done for all
> > IPs (which works in BE/LE
> > > > mode on different platforms).
> > > >
> > > > My preferred way of implementation to use one
> > function in IP driver, And
> > > > based on IP mode, do the switch.
> > > >
> > > > New Lib could have function like below
> > > > MmioRead32Generic(IN  UINTN     Address, BOOL
> > IsIPBE) {
> > > >    UINT32                            Value;
> > > >
> > > >    ASSERT ((Address & 3) == 0);
> > > >    Value = *(volatile UINT32*)Address;
> > > >    If(IsIPBE)
> > > >      Value = SwapBytes32(Value);
> > > >  return  Value;
> > > > }
> > > >
> > > > And IP driver can use it
> > > > MmioRead32Generic(ADDR,
> > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > >
> > > > Comments are welcome.
> > > >
> > > > Regards
> > > > Udit
> > > >
> > > > > -----Original Message-----
> > > > > From: edk2-devel [mailto:edk2-devel-
> > bounces@lists.01.org] On Behalf Of
> > > > > Gao, Liming
> > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > To: Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > <michael.d.kinney@intel.com>; edk2-
> > devel@lists.01.org
> > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for
> > > > > big-endian MMIO
> > > > >
> > > > > Meenakshi:
> > > > >   I suggest to introduce new IoLib library
> > instance, not to add new IoLib
> > > > APIs.
> > > > > New IoLib library instance will perform IO
> > operation as the big
> > > > > endian. You can update
> > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > new source file and new INF for it.
> > > > >
> > > > > UINT32
> > > > > EFIAPI
> > > > > MmioRead32 (
> > > > >   IN  UINTN     Address
> > > > >   )
> > > > > {
> > > > >   UINT32                            Value;
> > > > >
> > > > >   ASSERT ((Address & 3) == 0);
> > > > >   Value = *(volatile UINT32*)Address;
> > > > >   return SwapBytes32(Value);
> > > > > }
> > > > >
> > > > > Thanks
> > > > > Liming
> > > > > >-----Original Message-----
> > > > > >From: Meenakshi Aggarwal
> > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> > Kinney, Michael D
> > > > > ><michael.d.kinney@intel.com>; edk2-
> > devel@lists.01.org; Gao, Liming
> > > > > ><liming.gao@intel.com>
> > > > > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > Add support for
> > > > > >big-endian MMIO
> > > > > >
> > > > > >Hi All,
> > > > > >
> > > > > >
> > > > > >It’s a pretty old discussion, we have left the
> > upstreaming of NXP
> > > > > >package in between because of some other work,
> > but have started it
> > > > > >again
> > > > > now.
> > > > > >
> > > > > >
> > > > > >Issue  : Few NXP modules support Big Endian
> > MMIOs as these are ported
> > > > > >from PowerPC.
> > > > > >
> > > > > >Solution suggested : Create a separate library
> > for BE MMIO APIs.
> > > > > >
> > > > > >
> > > > > >So what I have done is, I have created a
> > separate library to support
> > > > > >BE MMIO APIs and currently keeping it to my
> > package.
> > > > > >This library is basically a wrapper over
> > existing MMIO APIs.
> > > > > >
> > > > > >UINT32
> > > > > >EFIAPI
> > > > > >BeMmioRead32 (
> > > > > >  IN  UINTN     Address
> > > > > >  )
> > > > > >{
> > > > > >  UINT32  Value;
> > > > > >
> > > > > >  Value = MmioRead32(Address);
> > > > > >
> > > > > >  return SwapBytes32(Value);
> > > > > >}
> > > > > >
> > > > > >
> > > > > >Need your opinion on below optinos:
> > > > > >
> > > > > >1. Will this be a good idea to make this library
> > a part of MdePkg? OR
> > > > > >
> > > > > >2. Add a new file e.g. IoBeMmio.c like
> > IoHighLevel.c in
> > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > And made these APIs a part of IoLib itself. OR
> > > > > >
> > > > > >3. Keep this library internal to NXP package.
> > > > > >
> > > > > >
> > > > > >Please provide your inputs.
> > > > > >
> > > > > >
> > > > > >Thanks & Regards,
> > > > > >Meenakshi
> > > > > >
> > > > > >> -----Original Message-----
> > > > > >> From: Bhupesh Sharma
> > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > >> To: Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > >> <michael.d.kinney@intel.com>
> > > > > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-
> > devel@ml01.01.org;
> > > > > >> Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>
> > > > > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > Add support for
> > > > > >> big-endian MMIO
> > > > > >>
> > > > > >> Hi Ard,
> > > > > >>
> > > > > >> > -----Original Message-----
> > > > > >> > From: Ard Biesheuvel
> > [mailto:ard.biesheuvel@linaro.org]
> > > > > >> > Sent: Monday, October 17, 2016 1:12 PM
> > > > > >> > To: Kinney, Michael D
> > <michael.d.kinney@intel.com>
> > > > > >> > Cc: Gao, Liming <liming.gao@intel.com>;
> > Bhupesh Sharma
> > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > devel@ml01.01.org
> > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > MdePkg/IoLib: Add support for
> > > > > >> > big- endian MMIO
> > > > > >> >
> > > > > >> > On 17 October 2016 at 05:10, Kinney, Michael
> > D
> > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > >> > > Bhupesh,
> > > > > >> > >
> > > > > >> > > It is also possible to add an ARM specific
> > PCD to select
> > > > > >> > > endianness and update
> > > > > >> > >
> > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use
> > that PCD in
> > > > > >> > > MmioRead/Write() APIs in that file to
> > support both endian types.
> > > > > >> > > You can use the SwapBytesxx() functions
> > from BaseLib(as
> > > > > >> > Laszlo
> > > > > >> > > suggested) based on the setting of this
> > ARM specific PCD.
> > > > > >> > >
> > > > > >> > > Modules that link against this lib can
> > select endianness by
> > > > > >> > > setting PCD in the scope of that module.
> > > > > >> > >
> > > > > >> > > The IPF version of IoLib uses an IPF
> > specific PCD to translate
> > > > > >> > > I/O port accesses to MMIO accesses.  So
> > there is already an
> > > > > >> > > example of an arch specific PCD in this
> > lib instance.
> > > > > >> > >
> > > > > >> >
> > > > > >> > This is not a platform wide thing, it is a
> > per-device property
> > > > > >> > whether the MMIO occurs in big endian or
> > little endian manner.
> > > > > >> >
> > > > > >> > So I think Liming's suggestion makes sense:
> > create an IoLib
> > > > > >> > implementation that performs the byte
> > swapping, and selectively
> > > > > >> > incorporate it into drivers that require it
> > using
> > > > > >> >
> > > > > >> > BeMmioDeviceDxe.inf {
> > > > > >> >   <LibraryClasses>
> > > > > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > >> > }
> > > > > >>
> > > > > >> That's correct. I think creating a separate
> > IoLib for byte-swapping
> > > > > >> makes sense.
> > > > > >>
> > > > > >> We will rework the patch accordingly.
> > > > > >>
> > > > > >> Regards,
> > > > > >> Bhupesh
> > > > > _______________________________________________
> > > > > edk2-devel mailing list
> > > > > edk2-devel@lists.01.org
> > > > > https://lists.01.org/mailman/listinfo/edk2-devel
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-11-29 19:48                     ` Leif Lindholm
@ 2017-11-30  4:15                       ` Meenakshi Aggarwal
  2017-12-01 10:57                         ` Leif Lindholm
  0 siblings, 1 reply; 25+ messages in thread
From: Meenakshi Aggarwal @ 2017-11-30  4:15 UTC (permalink / raw)
  To: Leif Lindholm, Kinney, Michael D
  Cc: Gao, Liming, edk2-devel@lists.01.org, Ard Biesheuvel

Hi Leif, Mike,


NXP boards, at present, have few controllers with big endian and other with little endian memory access.

Maximum controllers depend on SocLib library for clock information and endianness for SocLib and
controllers is different.

So this option will not work for us,
  You would then just do (in your .dsc):
  Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
      IoLib|<path to BeIoLib .inf>
  }

Because all libraries included by WatchDog will then access BE mode Mmio APIs.


And breaking code into separate modules with different access will be very difficult.
Watchdog is not the only module which need BE Mmio APIs, we have MMC and other controllers also with same requirement.

We need BE Mmio APIs with a different name.

Please see the possibility.


Thanks & Regards,
Meenakshi

> -----Original Message-----
> From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> Sent: Thursday, November 30, 2017 1:19 AM
> To: Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Gao, Liming
> <liming.gao@intel.com>; edk2-devel@lists.01.org; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> I guess there is no strict rule about a driver only directly accessing
> one piece of HW?
> 
> Still, that would be one possible solution: breaking accesses to a
> separate HW in need of byteswapping out into its own module and
> letting it override IoLib version there.
> 
> Regards,
> 
> Leif
> 
> On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney, Michael D wrote:
> > Leif,
> >
> > I agree that this should be described as byte swapping.
> >
> > What about a module that needs to access HW with and
> > without the bytes swapped?  It gets more complex if a
> > module is linked against several libs and some libs
> > access HW with bytes swapped and some do not.
> >
> > Thanks,
> >
> > Mike
> >
> > > -----Original Message-----
> > > From: edk2-devel [mailto:edk2-devel-
> > > bounces@lists.01.org] On Behalf Of Leif Lindholm
> > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>;
> > > Gao, Liming <liming.gao@intel.com>
> > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>
> > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > support for big-endian MMIO
> > >
> > > Hi Meenakshi,
> > >
> > > I finally got around to looking at the watchdog code
> > > (that uses this
> > > library), and that has convinced me the best solution
> > > is to do what
> > > Liming proposed.
> > >
> > > Looking at this snippet:
> > >
> > > > +STATIC
> > > > +UINT16
> > > > +EFIAPI
> > > > +WdogRead (
> > > > +  IN  UINTN     Address
> > > > +  )
> > > > +{
> > > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > > +    return BeMmioRead16 (Address);
> > > > +  } else {
> > > > +    return MmioRead16(Address);
> > > > +  }
> > >
> > > This is actually a pretty good demonstration of the
> > > arguments that
> > > were made with regards to how the BeIoLib could be just
> > > another
> > > implementation of IoLib.
> > >
> > > You would then just do (in your .dsc):
> > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > >     IoLib|<path to BeIoLib .inf>
> > >   }
> > >
> > > This causes the big-endian version of the library to be
> > > used for this
> > > component. This makes these Wdog<access> functions and
> > > the Pcd
> > > redundant, and the rest of the code can use
> > > MmioRead16()/MmioWrite16()
> > > directly.
> > >
> > > But then, it is not really a big-endian or litte-endian
> > > version of the
> > > library we need. We always know which endianness we are
> > > building for.
> > > What we need is a byteswapping flavour of IoLib.
> > >
> > > So Liming, what if we do something like adding a
> > > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > p.inf
> > > ---
> > > [Defines]
> > >   INF_VERSION                    = 0x0001001A
> > >   BASE_NAME                      =
> > > BaseIoLibIntrinsicSwap
> > >   MODULE_UNI_FILE                =
> > > BaseIoLibIntrinsic.uni
> > >   FILE_GUID                      = d4a60d44-3688-4a50-
> > > b2d0-5c6fc2422523
> > >   MODULE_TYPE                    = BASE
> > >   VERSION_STRING                 = 1.0
> > >   LIBRARY_CLASS                  = IoLib
> > >
> > >
> > > #
> > > #  VALID_ARCHITECTURES           = IA32 X64 EBC IPF ARM
> > > AARCH64
> > > #
> > >
> > > [Sources]
> > >   BaseIoLibIntrinsicInternal.h
> > >   IoHighLevel.c
> > >   IoLib.c
> > >   IoLibEbc.c         # Asserts on all i/o port accesses
> > >   IoLibMmioBuffer.c
> > >
> > > [Packages]
> > >   MdePkg/MdePkg.dec
> > >
> > > [LibraryClasses]
> > >   DebugLib
> > >   BaseLib
> > >
> > > [BuildOptions]
> > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > ---
> > >
> > > And then add
> > >
> > > #ifdef SWAP_BYTES
> > >   return SwapBytesXX (Value);
> > > #else
> > >   return Value;
> > > #fi
> > >
> > > for the read operations and
> > >
> > > #ifdef SWAP_BYTES
> > >   *(type)Address = SwapBytesXX (Value);
> > > #else
> > >   *(type)Address = Value;
> > > #fi
> > >
> > > for the write operations in IoLib.c?
> > >
> > > /
> > >     Leif
> > >
> > > On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi
> > > Aggarwal wrote:
> > > > Hi Leif,
> > > >
> > > > This is regarding Big-Endian Library patch ([PATCH v2
> > > 1/9]
> > > > Platform/NXP: Add support for Big Endian Mmio APIs)
> > > >
> > > > We have started this discussion before and the
> > > suggestion was to
> > > > create a separate .inf file keeping APIs name same
> > > > e.g. MmioRead/MmioWrite in MdePkg.
> > > >
> > > > But we can't go with this approach (reason mentioned
> > > by Udit).
> > > >
> > > > So please suggest if we should keep this library
> > > under Platform/NXP
> > > > or I send a new patch moving this library in MdePkg.
> > > >
> > > > But we have to keep a different name for Big Endian
> > > MMIO APIs.
> > > >
> > > >
> > > > Thanks,
> > > > Meenakshi
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Udit Kumar
> > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > To: Gao, Liming <liming.gao@intel.com>; Meenakshi
> > > Aggarwal
> > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > <michael.d.kinney@intel.com>; edk2-
> > > devel@lists.01.org
> > > > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > support for big-endian
> > > > > MMIO
> > > > >
> > > > > Hi Meenakshi/Liming,
> > > > > My 2 cents, around this.
> > > > >
> > > > > 1)
> > > > > Having a new lib for BE read might not be helpful
> > > for us, e.g. a IP which is in
> > > > > BE mode access the UART for print or system
> > > registers which are in LE, then
> > > > > with new Lib, we will get all read/write in BE mode
> > > > >
> > > > > 2)
> > > > > Especially for our IPs, which are changing from BE
> > > to LE depending on
> > > > > platform.
> > > > > As said before, having BE read lib with API name of
> > > MmioRead32 etc, will not
> > > > > help (I guess Meenakshi already seen some problems
> > > around this) Adding a
> > > > > new lib with MmioRead32BE API name could help, but
> > > IP driver we need to
> > > > > take care of IP mode either by Pcd or #define, to
> > > select MmioRead32 or
> > > > > MmioRead32BE.
> > > > > This conditional compile needs to be done for all
> > > IPs (which works in BE/LE
> > > > > mode on different platforms).
> > > > >
> > > > > My preferred way of implementation to use one
> > > function in IP driver, And
> > > > > based on IP mode, do the switch.
> > > > >
> > > > > New Lib could have function like below
> > > > > MmioRead32Generic(IN  UINTN     Address, BOOL
> > > IsIPBE) {
> > > > >    UINT32                            Value;
> > > > >
> > > > >    ASSERT ((Address & 3) == 0);
> > > > >    Value = *(volatile UINT32*)Address;
> > > > >    If(IsIPBE)
> > > > >      Value = SwapBytes32(Value);
> > > > >  return  Value;
> > > > > }
> > > > >
> > > > > And IP driver can use it
> > > > > MmioRead32Generic(ADDR,
> > > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > >
> > > > > Comments are welcome.
> > > > >
> > > > > Regards
> > > > > Udit
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: edk2-devel [mailto:edk2-devel-
> > > bounces@lists.01.org] On Behalf Of
> > > > > > Gao, Liming
> > > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > > To: Meenakshi Aggarwal
> > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > <michael.d.kinney@intel.com>; edk2-
> > > devel@lists.01.org
> > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > support for
> > > > > > big-endian MMIO
> > > > > >
> > > > > > Meenakshi:
> > > > > >   I suggest to introduce new IoLib library
> > > instance, not to add new IoLib
> > > > > APIs.
> > > > > > New IoLib library instance will perform IO
> > > operation as the big
> > > > > > endian. You can update
> > > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > > new source file and new INF for it.
> > > > > >
> > > > > > UINT32
> > > > > > EFIAPI
> > > > > > MmioRead32 (
> > > > > >   IN  UINTN     Address
> > > > > >   )
> > > > > > {
> > > > > >   UINT32                            Value;
> > > > > >
> > > > > >   ASSERT ((Address & 3) == 0);
> > > > > >   Value = *(volatile UINT32*)Address;
> > > > > >   return SwapBytes32(Value);
> > > > > > }
> > > > > >
> > > > > > Thanks
> > > > > > Liming
> > > > > > >-----Original Message-----
> > > > > > >From: Meenakshi Aggarwal
> > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> > > Kinney, Michael D
> > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > devel@lists.01.org; Gao, Liming
> > > > > > ><liming.gao@intel.com>
> > > > > > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > > Add support for
> > > > > > >big-endian MMIO
> > > > > > >
> > > > > > >Hi All,
> > > > > > >
> > > > > > >
> > > > > > >It’s a pretty old discussion, we have left the
> > > upstreaming of NXP
> > > > > > >package in between because of some other work,
> > > but have started it
> > > > > > >again
> > > > > > now.
> > > > > > >
> > > > > > >
> > > > > > >Issue  : Few NXP modules support Big Endian
> > > MMIOs as these are ported
> > > > > > >from PowerPC.
> > > > > > >
> > > > > > >Solution suggested : Create a separate library
> > > for BE MMIO APIs.
> > > > > > >
> > > > > > >
> > > > > > >So what I have done is, I have created a
> > > separate library to support
> > > > > > >BE MMIO APIs and currently keeping it to my
> > > package.
> > > > > > >This library is basically a wrapper over
> > > existing MMIO APIs.
> > > > > > >
> > > > > > >UINT32
> > > > > > >EFIAPI
> > > > > > >BeMmioRead32 (
> > > > > > >  IN  UINTN     Address
> > > > > > >  )
> > > > > > >{
> > > > > > >  UINT32  Value;
> > > > > > >
> > > > > > >  Value = MmioRead32(Address);
> > > > > > >
> > > > > > >  return SwapBytes32(Value);
> > > > > > >}
> > > > > > >
> > > > > > >
> > > > > > >Need your opinion on below optinos:
> > > > > > >
> > > > > > >1. Will this be a good idea to make this library
> > > a part of MdePkg? OR
> > > > > > >
> > > > > > >2. Add a new file e.g. IoBeMmio.c like
> > > IoHighLevel.c in
> > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > And made these APIs a part of IoLib itself. OR
> > > > > > >
> > > > > > >3. Keep this library internal to NXP package.
> > > > > > >
> > > > > > >
> > > > > > >Please provide your inputs.
> > > > > > >
> > > > > > >
> > > > > > >Thanks & Regards,
> > > > > > >Meenakshi
> > > > > > >
> > > > > > >> -----Original Message-----
> > > > > > >> From: Bhupesh Sharma
> > > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > > >> To: Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > >> <michael.d.kinney@intel.com>
> > > > > > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-
> > > devel@ml01.01.org;
> > > > > > >> Meenakshi Aggarwal
> > > <meenakshi.aggarwal@nxp.com>
> > > > > > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > > Add support for
> > > > > > >> big-endian MMIO
> > > > > > >>
> > > > > > >> Hi Ard,
> > > > > > >>
> > > > > > >> > -----Original Message-----
> > > > > > >> > From: Ard Biesheuvel
> > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > >> > Sent: Monday, October 17, 2016 1:12 PM
> > > > > > >> > To: Kinney, Michael D
> > > <michael.d.kinney@intel.com>
> > > > > > >> > Cc: Gao, Liming <liming.gao@intel.com>;
> > > Bhupesh Sharma
> > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > devel@ml01.01.org
> > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > MdePkg/IoLib: Add support for
> > > > > > >> > big- endian MMIO
> > > > > > >> >
> > > > > > >> > On 17 October 2016 at 05:10, Kinney, Michael
> > > D
> > > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > > >> > > Bhupesh,
> > > > > > >> > >
> > > > > > >> > > It is also possible to add an ARM specific
> > > PCD to select
> > > > > > >> > > endianness and update
> > > > > > >> > >
> > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use
> > > that PCD in
> > > > > > >> > > MmioRead/Write() APIs in that file to
> > > support both endian types.
> > > > > > >> > > You can use the SwapBytesxx() functions
> > > from BaseLib(as
> > > > > > >> > Laszlo
> > > > > > >> > > suggested) based on the setting of this
> > > ARM specific PCD.
> > > > > > >> > >
> > > > > > >> > > Modules that link against this lib can
> > > select endianness by
> > > > > > >> > > setting PCD in the scope of that module.
> > > > > > >> > >
> > > > > > >> > > The IPF version of IoLib uses an IPF
> > > specific PCD to translate
> > > > > > >> > > I/O port accesses to MMIO accesses.  So
> > > there is already an
> > > > > > >> > > example of an arch specific PCD in this
> > > lib instance.
> > > > > > >> > >
> > > > > > >> >
> > > > > > >> > This is not a platform wide thing, it is a
> > > per-device property
> > > > > > >> > whether the MMIO occurs in big endian or
> > > little endian manner.
> > > > > > >> >
> > > > > > >> > So I think Liming's suggestion makes sense:
> > > create an IoLib
> > > > > > >> > implementation that performs the byte
> > > swapping, and selectively
> > > > > > >> > incorporate it into drivers that require it
> > > using
> > > > > > >> >
> > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > >> >   <LibraryClasses>
> > > > > > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > >> > }
> > > > > > >>
> > > > > > >> That's correct. I think creating a separate
> > > IoLib for byte-swapping
> > > > > > >> makes sense.
> > > > > > >>
> > > > > > >> We will rework the patch accordingly.
> > > > > > >>
> > > > > > >> Regards,
> > > > > > >> Bhupesh
> > > > > > _______________________________________________
> > > > > > edk2-devel mailing list
> > > > > > edk2-devel@lists.01.org
> > > > > >
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e43cbb51
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEkdEQ
> %2Bu97606L%2FHEfg%3D&reserved=0
> > > _______________________________________________
> > > edk2-devel mailing list
> > > edk2-devel@lists.01.org
> > >
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e43cbb51
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEkdEQ
> %2Bu97606L%2FHEfg%3D&reserved=0

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-11-30  4:15                       ` Meenakshi Aggarwal
@ 2017-12-01 10:57                         ` Leif Lindholm
  2017-12-01 17:57                           ` Udit Kumar
  0 siblings, 1 reply; 25+ messages in thread
From: Leif Lindholm @ 2017-12-01 10:57 UTC (permalink / raw)
  To: Meenakshi Aggarwal
  Cc: Kinney, Michael D, Gao, Liming, edk2-devel@lists.01.org,
	Ard Biesheuvel

On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi Aggarwal wrote:
> Hi Leif, Mike,
> 
> 
> NXP boards, at present, have few controllers with big endian and
> other with little endian memory access.

Sure, this is not a problem.

> Maximum controllers depend on SocLib library for clock information
> and endianness for SocLib and controllers is different.

OK, I see in SocLib you have something called a Gur that is read once
(and again does a special per-device Pcd dance for runtime selection
between byteswapping Mmio and plain Mmio).

> So this option will not work for us,
>   You would then just do (in your .dsc):
>   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
>       IoLib|<path to BeIoLib .inf>
>   }
> 
> Because all libraries included by WatchDog will then access BE mode Mmio APIs.

Which libraries performing Mmio accesses are you intending to include
in your watchdog driver? You have submitted none as part of this series.

> And breaking code into separate modules with different access will
> be very difficult.

It may require a little bit more of up-front work, but the end result
will be a platform port that works with the intended edk2 design
principles rather than against them. And that will reduce the overall
effort (not to mention code duplication).

>From the patches you have sent, the only required change I see (if a
byteswapping IoLib was added to edk2) would be to create a tiny driver
for this "Gur" device that installs a protocol containing a single
function for reading from that device's register space. That driver
can be built against the swapping or non-swapping IoLib as
appropriate.

> Watchdog is not the only module which need BE Mmio APIs, we have MMC
> and other controllers also with same requirement.

And the same solutions are possible everywhere.

Best Regards,

Leif

> We need BE Mmio APIs with a different name.
> 
> Please see the possibility.
>
> Thanks & Regards,
> Meenakshi
> 
> > -----Original Message-----
> > From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> > Sent: Thursday, November 30, 2017 1:19 AM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > <liming.gao@intel.com>; edk2-devel@lists.01.org; Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>
> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> > MMIO
> > 
> > I guess there is no strict rule about a driver only directly accessing
> > one piece of HW?
> > 
> > Still, that would be one possible solution: breaking accesses to a
> > separate HW in need of byteswapping out into its own module and
> > letting it override IoLib version there.
> > 
> > Regards,
> > 
> > Leif
> > 
> > On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney, Michael D wrote:
> > > Leif,
> > >
> > > I agree that this should be described as byte swapping.
> > >
> > > What about a module that needs to access HW with and
> > > without the bytes swapped?  It gets more complex if a
> > > module is linked against several libs and some libs
> > > access HW with bytes swapped and some do not.
> > >
> > > Thanks,
> > >
> > > Mike
> > >
> > > > -----Original Message-----
> > > > From: edk2-devel [mailto:edk2-devel-
> > > > bounces@lists.01.org] On Behalf Of Leif Lindholm
> > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>;
> > > > Gao, Liming <liming.gao@intel.com>
> > > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>
> > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > > support for big-endian MMIO
> > > >
> > > > Hi Meenakshi,
> > > >
> > > > I finally got around to looking at the watchdog code
> > > > (that uses this
> > > > library), and that has convinced me the best solution
> > > > is to do what
> > > > Liming proposed.
> > > >
> > > > Looking at this snippet:
> > > >
> > > > > +STATIC
> > > > > +UINT16
> > > > > +EFIAPI
> > > > > +WdogRead (
> > > > > +  IN  UINTN     Address
> > > > > +  )
> > > > > +{
> > > > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > > > +    return BeMmioRead16 (Address);
> > > > > +  } else {
> > > > > +    return MmioRead16(Address);
> > > > > +  }
> > > >
> > > > This is actually a pretty good demonstration of the
> > > > arguments that
> > > > were made with regards to how the BeIoLib could be just
> > > > another
> > > > implementation of IoLib.
> > > >
> > > > You would then just do (in your .dsc):
> > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > >     IoLib|<path to BeIoLib .inf>
> > > >   }
> > > >
> > > > This causes the big-endian version of the library to be
> > > > used for this
> > > > component. This makes these Wdog<access> functions and
> > > > the Pcd
> > > > redundant, and the rest of the code can use
> > > > MmioRead16()/MmioWrite16()
> > > > directly.
> > > >
> > > > But then, it is not really a big-endian or litte-endian
> > > > version of the
> > > > library we need. We always know which endianness we are
> > > > building for.
> > > > What we need is a byteswapping flavour of IoLib.
> > > >
> > > > So Liming, what if we do something like adding a
> > > > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > p.inf
> > > > ---
> > > > [Defines]
> > > >   INF_VERSION                    = 0x0001001A
> > > >   BASE_NAME                      =
> > > > BaseIoLibIntrinsicSwap
> > > >   MODULE_UNI_FILE                =
> > > > BaseIoLibIntrinsic.uni
> > > >   FILE_GUID                      = d4a60d44-3688-4a50-
> > > > b2d0-5c6fc2422523
> > > >   MODULE_TYPE                    = BASE
> > > >   VERSION_STRING                 = 1.0
> > > >   LIBRARY_CLASS                  = IoLib
> > > >
> > > >
> > > > #
> > > > #  VALID_ARCHITECTURES           = IA32 X64 EBC IPF ARM
> > > > AARCH64
> > > > #
> > > >
> > > > [Sources]
> > > >   BaseIoLibIntrinsicInternal.h
> > > >   IoHighLevel.c
> > > >   IoLib.c
> > > >   IoLibEbc.c         # Asserts on all i/o port accesses
> > > >   IoLibMmioBuffer.c
> > > >
> > > > [Packages]
> > > >   MdePkg/MdePkg.dec
> > > >
> > > > [LibraryClasses]
> > > >   DebugLib
> > > >   BaseLib
> > > >
> > > > [BuildOptions]
> > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > ---
> > > >
> > > > And then add
> > > >
> > > > #ifdef SWAP_BYTES
> > > >   return SwapBytesXX (Value);
> > > > #else
> > > >   return Value;
> > > > #fi
> > > >
> > > > for the read operations and
> > > >
> > > > #ifdef SWAP_BYTES
> > > >   *(type)Address = SwapBytesXX (Value);
> > > > #else
> > > >   *(type)Address = Value;
> > > > #fi
> > > >
> > > > for the write operations in IoLib.c?
> > > >
> > > > /
> > > >     Leif
> > > >
> > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi
> > > > Aggarwal wrote:
> > > > > Hi Leif,
> > > > >
> > > > > This is regarding Big-Endian Library patch ([PATCH v2
> > > > 1/9]
> > > > > Platform/NXP: Add support for Big Endian Mmio APIs)
> > > > >
> > > > > We have started this discussion before and the
> > > > suggestion was to
> > > > > create a separate .inf file keeping APIs name same
> > > > > e.g. MmioRead/MmioWrite in MdePkg.
> > > > >
> > > > > But we can't go with this approach (reason mentioned
> > > > by Udit).
> > > > >
> > > > > So please suggest if we should keep this library
> > > > under Platform/NXP
> > > > > or I send a new patch moving this library in MdePkg.
> > > > >
> > > > > But we have to keep a different name for Big Endian
> > > > MMIO APIs.
> > > > >
> > > > >
> > > > > Thanks,
> > > > > Meenakshi
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Udit Kumar
> > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > To: Gao, Liming <liming.gao@intel.com>; Meenakshi
> > > > Aggarwal
> > > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > devel@lists.01.org
> > > > > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > > support for big-endian
> > > > > > MMIO
> > > > > >
> > > > > > Hi Meenakshi/Liming,
> > > > > > My 2 cents, around this.
> > > > > >
> > > > > > 1)
> > > > > > Having a new lib for BE read might not be helpful
> > > > for us, e.g. a IP which is in
> > > > > > BE mode access the UART for print or system
> > > > registers which are in LE, then
> > > > > > with new Lib, we will get all read/write in BE mode
> > > > > >
> > > > > > 2)
> > > > > > Especially for our IPs, which are changing from BE
> > > > to LE depending on
> > > > > > platform.
> > > > > > As said before, having BE read lib with API name of
> > > > MmioRead32 etc, will not
> > > > > > help (I guess Meenakshi already seen some problems
> > > > around this) Adding a
> > > > > > new lib with MmioRead32BE API name could help, but
> > > > IP driver we need to
> > > > > > take care of IP mode either by Pcd or #define, to
> > > > select MmioRead32 or
> > > > > > MmioRead32BE.
> > > > > > This conditional compile needs to be done for all
> > > > IPs (which works in BE/LE
> > > > > > mode on different platforms).
> > > > > >
> > > > > > My preferred way of implementation to use one
> > > > function in IP driver, And
> > > > > > based on IP mode, do the switch.
> > > > > >
> > > > > > New Lib could have function like below
> > > > > > MmioRead32Generic(IN  UINTN     Address, BOOL
> > > > IsIPBE) {
> > > > > >    UINT32                            Value;
> > > > > >
> > > > > >    ASSERT ((Address & 3) == 0);
> > > > > >    Value = *(volatile UINT32*)Address;
> > > > > >    If(IsIPBE)
> > > > > >      Value = SwapBytes32(Value);
> > > > > >  return  Value;
> > > > > > }
> > > > > >
> > > > > > And IP driver can use it
> > > > > > MmioRead32Generic(ADDR,
> > > > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > >
> > > > > > Comments are welcome.
> > > > > >
> > > > > > Regards
> > > > > > Udit
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > bounces@lists.01.org] On Behalf Of
> > > > > > > Gao, Liming
> > > > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > > > To: Meenakshi Aggarwal
> > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > devel@lists.01.org
> > > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > > support for
> > > > > > > big-endian MMIO
> > > > > > >
> > > > > > > Meenakshi:
> > > > > > >   I suggest to introduce new IoLib library
> > > > instance, not to add new IoLib
> > > > > > APIs.
> > > > > > > New IoLib library instance will perform IO
> > > > operation as the big
> > > > > > > endian. You can update
> > > > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > > > new source file and new INF for it.
> > > > > > >
> > > > > > > UINT32
> > > > > > > EFIAPI
> > > > > > > MmioRead32 (
> > > > > > >   IN  UINTN     Address
> > > > > > >   )
> > > > > > > {
> > > > > > >   UINT32                            Value;
> > > > > > >
> > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > >   return SwapBytes32(Value);
> > > > > > > }
> > > > > > >
> > > > > > > Thanks
> > > > > > > Liming
> > > > > > > >-----Original Message-----
> > > > > > > >From: Meenakshi Aggarwal
> > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > > > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> > > > Kinney, Michael D
> > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > devel@lists.01.org; Gao, Liming
> > > > > > > ><liming.gao@intel.com>
> > > > > > > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > > > Add support for
> > > > > > > >big-endian MMIO
> > > > > > > >
> > > > > > > >Hi All,
> > > > > > > >
> > > > > > > >
> > > > > > > >It’s a pretty old discussion, we have left the
> > > > upstreaming of NXP
> > > > > > > >package in between because of some other work,
> > > > but have started it
> > > > > > > >again
> > > > > > > now.
> > > > > > > >
> > > > > > > >
> > > > > > > >Issue  : Few NXP modules support Big Endian
> > > > MMIOs as these are ported
> > > > > > > >from PowerPC.
> > > > > > > >
> > > > > > > >Solution suggested : Create a separate library
> > > > for BE MMIO APIs.
> > > > > > > >
> > > > > > > >
> > > > > > > >So what I have done is, I have created a
> > > > separate library to support
> > > > > > > >BE MMIO APIs and currently keeping it to my
> > > > package.
> > > > > > > >This library is basically a wrapper over
> > > > existing MMIO APIs.
> > > > > > > >
> > > > > > > >UINT32
> > > > > > > >EFIAPI
> > > > > > > >BeMmioRead32 (
> > > > > > > >  IN  UINTN     Address
> > > > > > > >  )
> > > > > > > >{
> > > > > > > >  UINT32  Value;
> > > > > > > >
> > > > > > > >  Value = MmioRead32(Address);
> > > > > > > >
> > > > > > > >  return SwapBytes32(Value);
> > > > > > > >}
> > > > > > > >
> > > > > > > >
> > > > > > > >Need your opinion on below optinos:
> > > > > > > >
> > > > > > > >1. Will this be a good idea to make this library
> > > > a part of MdePkg? OR
> > > > > > > >
> > > > > > > >2. Add a new file e.g. IoBeMmio.c like
> > > > IoHighLevel.c in
> > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > And made these APIs a part of IoLib itself. OR
> > > > > > > >
> > > > > > > >3. Keep this library internal to NXP package.
> > > > > > > >
> > > > > > > >
> > > > > > > >Please provide your inputs.
> > > > > > > >
> > > > > > > >
> > > > > > > >Thanks & Regards,
> > > > > > > >Meenakshi
> > > > > > > >
> > > > > > > >> -----Original Message-----
> > > > > > > >> From: Bhupesh Sharma
> > > > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > > > >> To: Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-
> > > > devel@ml01.01.org;
> > > > > > > >> Meenakshi Aggarwal
> > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > > > Add support for
> > > > > > > >> big-endian MMIO
> > > > > > > >>
> > > > > > > >> Hi Ard,
> > > > > > > >>
> > > > > > > >> > -----Original Message-----
> > > > > > > >> > From: Ard Biesheuvel
> > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > >> > Sent: Monday, October 17, 2016 1:12 PM
> > > > > > > >> > To: Kinney, Michael D
> > > > <michael.d.kinney@intel.com>
> > > > > > > >> > Cc: Gao, Liming <liming.gao@intel.com>;
> > > > Bhupesh Sharma
> > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > devel@ml01.01.org
> > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > MdePkg/IoLib: Add support for
> > > > > > > >> > big- endian MMIO
> > > > > > > >> >
> > > > > > > >> > On 17 October 2016 at 05:10, Kinney, Michael
> > > > D
> > > > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > > > >> > > Bhupesh,
> > > > > > > >> > >
> > > > > > > >> > > It is also possible to add an ARM specific
> > > > PCD to select
> > > > > > > >> > > endianness and update
> > > > > > > >> > >
> > > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use
> > > > that PCD in
> > > > > > > >> > > MmioRead/Write() APIs in that file to
> > > > support both endian types.
> > > > > > > >> > > You can use the SwapBytesxx() functions
> > > > from BaseLib(as
> > > > > > > >> > Laszlo
> > > > > > > >> > > suggested) based on the setting of this
> > > > ARM specific PCD.
> > > > > > > >> > >
> > > > > > > >> > > Modules that link against this lib can
> > > > select endianness by
> > > > > > > >> > > setting PCD in the scope of that module.
> > > > > > > >> > >
> > > > > > > >> > > The IPF version of IoLib uses an IPF
> > > > specific PCD to translate
> > > > > > > >> > > I/O port accesses to MMIO accesses.  So
> > > > there is already an
> > > > > > > >> > > example of an arch specific PCD in this
> > > > lib instance.
> > > > > > > >> > >
> > > > > > > >> >
> > > > > > > >> > This is not a platform wide thing, it is a
> > > > per-device property
> > > > > > > >> > whether the MMIO occurs in big endian or
> > > > little endian manner.
> > > > > > > >> >
> > > > > > > >> > So I think Liming's suggestion makes sense:
> > > > create an IoLib
> > > > > > > >> > implementation that performs the byte
> > > > swapping, and selectively
> > > > > > > >> > incorporate it into drivers that require it
> > > > using
> > > > > > > >> >
> > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > >> >   <LibraryClasses>
> > > > > > > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > >> > }
> > > > > > > >>
> > > > > > > >> That's correct. I think creating a separate
> > > > IoLib for byte-swapping
> > > > > > > >> makes sense.
> > > > > > > >>
> > > > > > > >> We will rework the patch accordingly.
> > > > > > > >>
> > > > > > > >> Regards,
> > > > > > > >> Bhupesh
> > > > > > > _______________________________________________
> > > > > > > edk2-devel mailing list
> > > > > > > edk2-devel@lists.01.org
> > > > > > >
> > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e43cbb51
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEkdEQ
> > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > _______________________________________________
> > > > edk2-devel mailing list
> > > > edk2-devel@lists.01.org
> > > >
> > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
> > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e43cbb51
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEkdEQ
> > %2Bu97606L%2FHEfg%3D&reserved=0


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-01 10:57                         ` Leif Lindholm
@ 2017-12-01 17:57                           ` Udit Kumar
  2017-12-01 22:41                             ` Kinney, Michael D
  0 siblings, 1 reply; 25+ messages in thread
From: Udit Kumar @ 2017-12-01 17:57 UTC (permalink / raw)
  To: Leif Lindholm, Meenakshi Aggarwal, Varun Sethi
  Cc: Kinney, Michael D, edk2-devel@lists.01.org, Gao, Liming,
	Ard Biesheuvel

Thanks Leif, 

> It may require a little bit more of up-front work, but the end result will be a
> platform port that works with the intended edk2 design principles rather than

Yes, this will be re-design/code for us, breaking all software pieces into
smaller blocks and exposing protocol from the same. 
This could be managed.

But how do you see,  if there is such dependency oN lib. 
Say a driver which is in BE mode, and is using DebugLib (BaseDebugLibSerialPort)
And DebugLib uses SerialPortLib, which is in LE mode 

Thanks 
Udit

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Leif
> Lindholm
> Sent: Friday, December 01, 2017 4:28 PM
> To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; edk2-devel@lists.01.org;
> Gao, Liming <liming.gao@intel.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi Aggarwal wrote:
> > Hi Leif, Mike,
> >
> >
> > NXP boards, at present, have few controllers with big endian and other
> > with little endian memory access.
> 
> Sure, this is not a problem.
> 
> > Maximum controllers depend on SocLib library for clock information and
> > endianness for SocLib and controllers is different.
> 
> OK, I see in SocLib you have something called a Gur that is read once (and again
> does a special per-device Pcd dance for runtime selection between
> byteswapping Mmio and plain Mmio).
> 
> > So this option will not work for us,
> >   You would then just do (in your .dsc):
> >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> >       IoLib|<path to BeIoLib .inf>
> >   }
> >
> > Because all libraries included by WatchDog will then access BE mode Mmio
> APIs.
> 
> Which libraries performing Mmio accesses are you intending to include in your
> watchdog driver? You have submitted none as part of this series.
> 
> > And breaking code into separate modules with different access will be
> > very difficult.
> 
> It may require a little bit more of up-front work, but the end result will be a
> platform port that works with the intended edk2 design principles rather than
> against them. And that will reduce the overall effort (not to mention code
> duplication).
> 
> From the patches you have sent, the only required change I see (if a
> byteswapping IoLib was added to edk2) would be to create a tiny driver for this
> "Gur" device that installs a protocol containing a single function for reading
> from that device's register space. That driver can be built against the swapping
> or non-swapping IoLib as appropriate.
> 
> > Watchdog is not the only module which need BE Mmio APIs, we have MMC
> > and other controllers also with same requirement.
> 
> And the same solutions are possible everywhere.
> 
> Best Regards,
> 
> Leif
> 
> > We need BE Mmio APIs with a different name.
> >
> > Please see the possibility.
> >
> > Thanks & Regards,
> > Meenakshi
> >
> > > -----Original Message-----
> > > From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> > > Sent: Thursday, November 30, 2017 1:19 AM
> > > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > > Cc: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > <liming.gao@intel.com>; edk2-devel@lists.01.org; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>
> > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > > big-endian MMIO
> > >
> > > I guess there is no strict rule about a driver only directly
> > > accessing one piece of HW?
> > >
> > > Still, that would be one possible solution: breaking accesses to a
> > > separate HW in need of byteswapping out into its own module and
> > > letting it override IoLib version there.
> > >
> > > Regards,
> > >
> > > Leif
> > >
> > > On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney, Michael D wrote:
> > > > Leif,
> > > >
> > > > I agree that this should be described as byte swapping.
> > > >
> > > > What about a module that needs to access HW with and without the
> > > > bytes swapped?  It gets more complex if a module is linked against
> > > > several libs and some libs access HW with bytes swapped and some
> > > > do not.
> > > >
> > > > Thanks,
> > > >
> > > > Mike
> > > >
> > > > > -----Original Message-----
> > > > > From: edk2-devel [mailto:edk2-devel- bounces@lists.01.org] On
> > > > > Behalf Of Leif Lindholm
> > > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > <liming.gao@intel.com>
> > > > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>
> > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for
> > > > > big-endian MMIO
> > > > >
> > > > > Hi Meenakshi,
> > > > >
> > > > > I finally got around to looking at the watchdog code (that uses
> > > > > this library), and that has convinced me the best solution is to
> > > > > do what Liming proposed.
> > > > >
> > > > > Looking at this snippet:
> > > > >
> > > > > > +STATIC
> > > > > > +UINT16
> > > > > > +EFIAPI
> > > > > > +WdogRead (
> > > > > > +  IN  UINTN     Address
> > > > > > +  )
> > > > > > +{
> > > > > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > > > > +    return BeMmioRead16 (Address);
> > > > > > +  } else {
> > > > > > +    return MmioRead16(Address);
> > > > > > +  }
> > > > >
> > > > > This is actually a pretty good demonstration of the arguments
> > > > > that were made with regards to how the BeIoLib could be just
> > > > > another implementation of IoLib.
> > > > >
> > > > > You would then just do (in your .dsc):
> > > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > > >     IoLib|<path to BeIoLib .inf>
> > > > >   }
> > > > >
> > > > > This causes the big-endian version of the library to be used for
> > > > > this component. This makes these Wdog<access> functions and the
> > > > > Pcd redundant, and the rest of the code can use
> > > > > MmioRead16()/MmioWrite16()
> > > > > directly.
> > > > >
> > > > > But then, it is not really a big-endian or litte-endian version
> > > > > of the library we need. We always know which endianness we are
> > > > > building for.
> > > > > What we need is a byteswapping flavour of IoLib.
> > > > >
> > > > > So Liming, what if we do something like adding a
> > > > > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > p.inf
> > > > > ---
> > > > > [Defines]
> > > > >   INF_VERSION                    = 0x0001001A
> > > > >   BASE_NAME                      =
> > > > > BaseIoLibIntrinsicSwap
> > > > >   MODULE_UNI_FILE                =
> > > > > BaseIoLibIntrinsic.uni
> > > > >   FILE_GUID                      = d4a60d44-3688-4a50-
> > > > > b2d0-5c6fc2422523
> > > > >   MODULE_TYPE                    = BASE
> > > > >   VERSION_STRING                 = 1.0
> > > > >   LIBRARY_CLASS                  = IoLib
> > > > >
> > > > >
> > > > > #
> > > > > #  VALID_ARCHITECTURES           = IA32 X64 EBC IPF ARM
> > > > > AARCH64
> > > > > #
> > > > >
> > > > > [Sources]
> > > > >   BaseIoLibIntrinsicInternal.h
> > > > >   IoHighLevel.c
> > > > >   IoLib.c
> > > > >   IoLibEbc.c         # Asserts on all i/o port accesses
> > > > >   IoLibMmioBuffer.c
> > > > >
> > > > > [Packages]
> > > > >   MdePkg/MdePkg.dec
> > > > >
> > > > > [LibraryClasses]
> > > > >   DebugLib
> > > > >   BaseLib
> > > > >
> > > > > [BuildOptions]
> > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > ---
> > > > >
> > > > > And then add
> > > > >
> > > > > #ifdef SWAP_BYTES
> > > > >   return SwapBytesXX (Value);
> > > > > #else
> > > > >   return Value;
> > > > > #fi
> > > > >
> > > > > for the read operations and
> > > > >
> > > > > #ifdef SWAP_BYTES
> > > > >   *(type)Address = SwapBytesXX (Value); #else
> > > > >   *(type)Address = Value;
> > > > > #fi
> > > > >
> > > > > for the write operations in IoLib.c?
> > > > >
> > > > > /
> > > > >     Leif
> > > > >
> > > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000, Meenakshi Aggarwal
> > > > > wrote:
> > > > > > Hi Leif,
> > > > > >
> > > > > > This is regarding Big-Endian Library patch ([PATCH v2
> > > > > 1/9]
> > > > > > Platform/NXP: Add support for Big Endian Mmio APIs)
> > > > > >
> > > > > > We have started this discussion before and the
> > > > > suggestion was to
> > > > > > create a separate .inf file keeping APIs name same e.g.
> > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > >
> > > > > > But we can't go with this approach (reason mentioned
> > > > > by Udit).
> > > > > >
> > > > > > So please suggest if we should keep this library
> > > > > under Platform/NXP
> > > > > > or I send a new patch moving this library in MdePkg.
> > > > > >
> > > > > > But we have to keep a different name for Big Endian
> > > > > MMIO APIs.
> > > > > >
> > > > > >
> > > > > > Thanks,
> > > > > > Meenakshi
> > > > > >
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Udit Kumar
> > > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > > To: Gao, Liming <liming.gao@intel.com>; Meenakshi
> > > > > Aggarwal
> > > > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > devel@lists.01.org
> > > > > > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > > > support for big-endian
> > > > > > > MMIO
> > > > > > >
> > > > > > > Hi Meenakshi/Liming,
> > > > > > > My 2 cents, around this.
> > > > > > >
> > > > > > > 1)
> > > > > > > Having a new lib for BE read might not be helpful
> > > > > for us, e.g. a IP which is in
> > > > > > > BE mode access the UART for print or system
> > > > > registers which are in LE, then
> > > > > > > with new Lib, we will get all read/write in BE mode
> > > > > > >
> > > > > > > 2)
> > > > > > > Especially for our IPs, which are changing from BE
> > > > > to LE depending on
> > > > > > > platform.
> > > > > > > As said before, having BE read lib with API name of
> > > > > MmioRead32 etc, will not
> > > > > > > help (I guess Meenakshi already seen some problems
> > > > > around this) Adding a
> > > > > > > new lib with MmioRead32BE API name could help, but
> > > > > IP driver we need to
> > > > > > > take care of IP mode either by Pcd or #define, to
> > > > > select MmioRead32 or
> > > > > > > MmioRead32BE.
> > > > > > > This conditional compile needs to be done for all
> > > > > IPs (which works in BE/LE
> > > > > > > mode on different platforms).
> > > > > > >
> > > > > > > My preferred way of implementation to use one
> > > > > function in IP driver, And
> > > > > > > based on IP mode, do the switch.
> > > > > > >
> > > > > > > New Lib could have function like below
> > > > > > > MmioRead32Generic(IN  UINTN     Address, BOOL
> > > > > IsIPBE) {
> > > > > > >    UINT32                            Value;
> > > > > > >
> > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > >    Value = *(volatile UINT32*)Address;
> > > > > > >    If(IsIPBE)
> > > > > > >      Value = SwapBytes32(Value);  return  Value; }
> > > > > > >
> > > > > > > And IP driver can use it
> > > > > > > MmioRead32Generic(ADDR,
> > > > > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > >
> > > > > > > Comments are welcome.
> > > > > > >
> > > > > > > Regards
> > > > > > > Udit
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > Gao, Liming
> > > > > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > > > > To: Meenakshi Aggarwal
> > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > devel@lists.01.org
> > > > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > > > support for
> > > > > > > > big-endian MMIO
> > > > > > > >
> > > > > > > > Meenakshi:
> > > > > > > >   I suggest to introduce new IoLib library
> > > > > instance, not to add new IoLib
> > > > > > > APIs.
> > > > > > > > New IoLib library instance will perform IO
> > > > > operation as the big
> > > > > > > > endian. You can update
> > > > > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > > > > new source file and new INF for it.
> > > > > > > >
> > > > > > > > UINT32
> > > > > > > > EFIAPI
> > > > > > > > MmioRead32 (
> > > > > > > >   IN  UINTN     Address
> > > > > > > >   )
> > > > > > > > {
> > > > > > > >   UINT32                            Value;
> > > > > > > >
> > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > > >   return SwapBytes32(Value); }
> > > > > > > >
> > > > > > > > Thanks
> > > > > > > > Liming
> > > > > > > > >-----Original Message-----
> > > > > > > > >From: Meenakshi Aggarwal
> > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > > > > >To: Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> > > > > Kinney, Michael D
> > > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > ><liming.gao@intel.com>
> > > > > > > > >Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > > > > Add support for
> > > > > > > > >big-endian MMIO
> > > > > > > > >
> > > > > > > > >Hi All,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >It’s a pretty old discussion, we have left the
> > > > > upstreaming of NXP
> > > > > > > > >package in between because of some other work,
> > > > > but have started it
> > > > > > > > >again
> > > > > > > > now.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >Issue  : Few NXP modules support Big Endian
> > > > > MMIOs as these are ported
> > > > > > > > >from PowerPC.
> > > > > > > > >
> > > > > > > > >Solution suggested : Create a separate library
> > > > > for BE MMIO APIs.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >So what I have done is, I have created a
> > > > > separate library to support
> > > > > > > > >BE MMIO APIs and currently keeping it to my
> > > > > package.
> > > > > > > > >This library is basically a wrapper over
> > > > > existing MMIO APIs.
> > > > > > > > >
> > > > > > > > >UINT32
> > > > > > > > >EFIAPI
> > > > > > > > >BeMmioRead32 (
> > > > > > > > >  IN  UINTN     Address
> > > > > > > > >  )
> > > > > > > > >{
> > > > > > > > >  UINT32  Value;
> > > > > > > > >
> > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > >
> > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >Need your opinion on below optinos:
> > > > > > > > >
> > > > > > > > >1. Will this be a good idea to make this library
> > > > > a part of MdePkg? OR
> > > > > > > > >
> > > > > > > > >2. Add a new file e.g. IoBeMmio.c like
> > > > > IoHighLevel.c in
> > > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > And made these APIs a part of IoLib itself. OR
> > > > > > > > >
> > > > > > > > >3. Keep this library internal to NXP package.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >Please provide your inputs.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >Thanks & Regards,
> > > > > > > > >Meenakshi
> > > > > > > > >
> > > > > > > > >> -----Original Message-----
> > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > > > > >> To: Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > >> Cc: Gao, Liming <liming.gao@intel.com>; edk2-
> > > > > devel@ml01.01.org;
> > > > > > > > >> Meenakshi Aggarwal
> > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > >> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > > > > Add support for
> > > > > > > > >> big-endian MMIO
> > > > > > > > >>
> > > > > > > > >> Hi Ard,
> > > > > > > > >>
> > > > > > > > >> > -----Original Message-----
> > > > > > > > >> > From: Ard Biesheuvel
> > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > >> > Sent: Monday, October 17, 2016 1:12 PM
> > > > > > > > >> > To: Kinney, Michael D
> > > > > <michael.d.kinney@intel.com>
> > > > > > > > >> > Cc: Gao, Liming <liming.gao@intel.com>;
> > > > > Bhupesh Sharma
> > > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > > devel@ml01.01.org
> > > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > > MdePkg/IoLib: Add support for
> > > > > > > > >> > big- endian MMIO
> > > > > > > > >> >
> > > > > > > > >> > On 17 October 2016 at 05:10, Kinney, Michael
> > > > > D
> > > > > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > > > > >> > > Bhupesh,
> > > > > > > > >> > >
> > > > > > > > >> > > It is also possible to add an ARM specific
> > > > > PCD to select
> > > > > > > > >> > > endianness and update
> > > > > > > > >> > >
> > > > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to use that PCD in
> > > > > > > > >> > > MmioRead/Write() APIs in that file to
> > > > > support both endian types.
> > > > > > > > >> > > You can use the SwapBytesxx() functions
> > > > > from BaseLib(as
> > > > > > > > >> > Laszlo
> > > > > > > > >> > > suggested) based on the setting of this
> > > > > ARM specific PCD.
> > > > > > > > >> > >
> > > > > > > > >> > > Modules that link against this lib can
> > > > > select endianness by
> > > > > > > > >> > > setting PCD in the scope of that module.
> > > > > > > > >> > >
> > > > > > > > >> > > The IPF version of IoLib uses an IPF
> > > > > specific PCD to translate
> > > > > > > > >> > > I/O port accesses to MMIO accesses.  So
> > > > > there is already an
> > > > > > > > >> > > example of an arch specific PCD in this
> > > > > lib instance.
> > > > > > > > >> > >
> > > > > > > > >> >
> > > > > > > > >> > This is not a platform wide thing, it is a
> > > > > per-device property
> > > > > > > > >> > whether the MMIO occurs in big endian or
> > > > > little endian manner.
> > > > > > > > >> >
> > > > > > > > >> > So I think Liming's suggestion makes sense:
> > > > > create an IoLib
> > > > > > > > >> > implementation that performs the byte
> > > > > swapping, and selectively
> > > > > > > > >> > incorporate it into drivers that require it
> > > > > using
> > > > > > > > >> >
> > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > >> >   <LibraryClasses>
> > > > > > > > >> >     IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > >> > }
> > > > > > > > >>
> > > > > > > > >> That's correct. I think creating a separate
> > > > > IoLib for byte-swapping
> > > > > > > > >> makes sense.
> > > > > > > > >>
> > > > > > > > >> We will rework the patch accordingly.
> > > > > > > > >>
> > > > > > > > >> Regards,
> > > > > > > > >> Bhupesh
> > > > > > > > _______________________________________________
> > > > > > > > edk2-devel mailing list
> > > > > > > > edk2-devel@lists.01.org
> > > > > > > >
> > > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fl
> > > ist
> > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e43cbb51
> > >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> > > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEkdEQ
> > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > _______________________________________________
> > > > > edk2-devel mailing list
> > > > > edk2-devel@lists.01.org
> > > > >
> > > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fl
> > > ist
> > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e43cbb51
> > >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> > > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEkdEQ
> > > %2Bu97606L%2FHEfg%3D&reserved=0
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.01
> .org%2Fmailman%2Flistinfo%2Fedk2-
> devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a0648fa8e440
> 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6364772
> 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alHY4ptAX
> MU%3D&reserved=0

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-01 17:57                           ` Udit Kumar
@ 2017-12-01 22:41                             ` Kinney, Michael D
  2017-12-04  6:18                               ` Meenakshi Aggarwal
  2017-12-04 12:36                               ` Leif Lindholm
  0 siblings, 2 replies; 25+ messages in thread
From: Kinney, Michael D @ 2017-12-01 22:41 UTC (permalink / raw)
  To: Udit Kumar, Leif Lindholm, Meenakshi Aggarwal, Varun Sethi,
	Kinney, Michael D
  Cc: edk2-devel@lists.01.org, Gao, Liming, Ard Biesheuvel

Udit,

I agree with your concern.

I am in favor of adding new APIs that perform the
byte swap operations.

Mike

> -----Original Message-----
> From: Udit Kumar [mailto:udit.kumar@nxp.com]
> Sent: Friday, December 1, 2017 9:58 AM
> To: Leif Lindholm <leif.lindholm@linaro.org>; Meenakshi
> Aggarwal <meenakshi.aggarwal@nxp.com>; Varun Sethi
> <V.Sethi@nxp.com>
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; edk2-
> devel@lists.01.org; Gao, Liming <liming.gao@intel.com>;
> Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support
> for big-endian MMIO
> 
> Thanks Leif,
> 
> > It may require a little bit more of up-front work, but
> the end result will be a
> > platform port that works with the intended edk2 design
> principles rather than
> 
> Yes, this will be re-design/code for us, breaking all
> software pieces into
> smaller blocks and exposing protocol from the same.
> This could be managed.
> 
> But how do you see,  if there is such dependency oN lib.
> Say a driver which is in BE mode, and is using DebugLib
> (BaseDebugLibSerialPort)
> And DebugLib uses SerialPortLib, which is in LE mode
> 
> Thanks
> Udit
> 
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-
> bounces@lists.01.org] On Behalf Of Leif
> > Lindholm
> > Sent: Friday, December 01, 2017 4:28 PM
> > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> edk2-devel@lists.01.org;
> > Gao, Liming <liming.gao@intel.com>; Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>
> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support for big-endian
> > MMIO
> >
> > On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi
> Aggarwal wrote:
> > > Hi Leif, Mike,
> > >
> > >
> > > NXP boards, at present, have few controllers with big
> endian and other
> > > with little endian memory access.
> >
> > Sure, this is not a problem.
> >
> > > Maximum controllers depend on SocLib library for
> clock information and
> > > endianness for SocLib and controllers is different.
> >
> > OK, I see in SocLib you have something called a Gur
> that is read once (and again
> > does a special per-device Pcd dance for runtime
> selection between
> > byteswapping Mmio and plain Mmio).
> >
> > > So this option will not work for us,
> > >   You would then just do (in your .dsc):
> > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > >       IoLib|<path to BeIoLib .inf>
> > >   }
> > >
> > > Because all libraries included by WatchDog will then
> access BE mode Mmio
> > APIs.
> >
> > Which libraries performing Mmio accesses are you
> intending to include in your
> > watchdog driver? You have submitted none as part of
> this series.
> >
> > > And breaking code into separate modules with
> different access will be
> > > very difficult.
> >
> > It may require a little bit more of up-front work, but
> the end result will be a
> > platform port that works with the intended edk2 design
> principles rather than
> > against them. And that will reduce the overall effort
> (not to mention code
> > duplication).
> >
> > From the patches you have sent, the only required
> change I see (if a
> > byteswapping IoLib was added to edk2) would be to
> create a tiny driver for this
> > "Gur" device that installs a protocol containing a
> single function for reading
> > from that device's register space. That driver can be
> built against the swapping
> > or non-swapping IoLib as appropriate.
> >
> > > Watchdog is not the only module which need BE Mmio
> APIs, we have MMC
> > > and other controllers also with same requirement.
> >
> > And the same solutions are possible everywhere.
> >
> > Best Regards,
> >
> > Leif
> >
> > > We need BE Mmio APIs with a different name.
> > >
> > > Please see the possibility.
> > >
> > > Thanks & Regards,
> > > Meenakshi
> > >
> > > > -----Original Message-----
> > > > From: Leif Lindholm
> [mailto:leif.lindholm@linaro.org]
> > > > Sent: Thursday, November 30, 2017 1:19 AM
> > > > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > Cc: Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > <liming.gao@intel.com>; edk2-devel@lists.01.org;
> Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>
> > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support for
> > > > big-endian MMIO
> > > >
> > > > I guess there is no strict rule about a driver only
> directly
> > > > accessing one piece of HW?
> > > >
> > > > Still, that would be one possible solution:
> breaking accesses to a
> > > > separate HW in need of byteswapping out into its
> own module and
> > > > letting it override IoLib version there.
> > > >
> > > > Regards,
> > > >
> > > > Leif
> > > >
> > > > On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney,
> Michael D wrote:
> > > > > Leif,
> > > > >
> > > > > I agree that this should be described as byte
> swapping.
> > > > >
> > > > > What about a module that needs to access HW with
> and without the
> > > > > bytes swapped?  It gets more complex if a module
> is linked against
> > > > > several libs and some libs access HW with bytes
> swapped and some
> > > > > do not.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Mike
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: edk2-devel [mailto:edk2-devel-
> bounces@lists.01.org] On
> > > > > > Behalf Of Leif Lindholm
> > > > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > > > To: Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > <liming.gao@intel.com>
> > > > > > Cc: Kinney, Michael D
> <michael.d.kinney@intel.com>;
> > > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > > <ard.biesheuvel@linaro.org>
> > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib:
> Add support for
> > > > > > big-endian MMIO
> > > > > >
> > > > > > Hi Meenakshi,
> > > > > >
> > > > > > I finally got around to looking at the watchdog
> code (that uses
> > > > > > this library), and that has convinced me the
> best solution is to
> > > > > > do what Liming proposed.
> > > > > >
> > > > > > Looking at this snippet:
> > > > > >
> > > > > > > +STATIC
> > > > > > > +UINT16
> > > > > > > +EFIAPI
> > > > > > > +WdogRead (
> > > > > > > +  IN  UINTN     Address
> > > > > > > +  )
> > > > > > > +{
> > > > > > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > > > > > +    return BeMmioRead16 (Address);
> > > > > > > +  } else {
> > > > > > > +    return MmioRead16(Address);
> > > > > > > +  }
> > > > > >
> > > > > > This is actually a pretty good demonstration of
> the arguments
> > > > > > that were made with regards to how the BeIoLib
> could be just
> > > > > > another implementation of IoLib.
> > > > > >
> > > > > > You would then just do (in your .dsc):
> > > > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf
> {
> > > > > >     IoLib|<path to BeIoLib .inf>
> > > > > >   }
> > > > > >
> > > > > > This causes the big-endian version of the
> library to be used for
> > > > > > this component. This makes these Wdog<access>
> functions and the
> > > > > > Pcd redundant, and the rest of the code can use
> > > > > > MmioRead16()/MmioWrite16()
> > > > > > directly.
> > > > > >
> > > > > > But then, it is not really a big-endian or
> litte-endian version
> > > > > > of the library we need. We always know which
> endianness we are
> > > > > > building for.
> > > > > > What we need is a byteswapping flavour of
> IoLib.
> > > > > >
> > > > > > So Liming, what if we do something like adding
> a
> > > > > >
> MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > > p.inf
> > > > > > ---
> > > > > > [Defines]
> > > > > >   INF_VERSION                    = 0x0001001A
> > > > > >   BASE_NAME                      =
> > > > > > BaseIoLibIntrinsicSwap
> > > > > >   MODULE_UNI_FILE                =
> > > > > > BaseIoLibIntrinsic.uni
> > > > > >   FILE_GUID                      = d4a60d44-
> 3688-4a50-
> > > > > > b2d0-5c6fc2422523
> > > > > >   MODULE_TYPE                    = BASE
> > > > > >   VERSION_STRING                 = 1.0
> > > > > >   LIBRARY_CLASS                  = IoLib
> > > > > >
> > > > > >
> > > > > > #
> > > > > > #  VALID_ARCHITECTURES           = IA32 X64 EBC
> IPF ARM
> > > > > > AARCH64
> > > > > > #
> > > > > >
> > > > > > [Sources]
> > > > > >   BaseIoLibIntrinsicInternal.h
> > > > > >   IoHighLevel.c
> > > > > >   IoLib.c
> > > > > >   IoLibEbc.c         # Asserts on all i/o port
> accesses
> > > > > >   IoLibMmioBuffer.c
> > > > > >
> > > > > > [Packages]
> > > > > >   MdePkg/MdePkg.dec
> > > > > >
> > > > > > [LibraryClasses]
> > > > > >   DebugLib
> > > > > >   BaseLib
> > > > > >
> > > > > > [BuildOptions]
> > > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > > ---
> > > > > >
> > > > > > And then add
> > > > > >
> > > > > > #ifdef SWAP_BYTES
> > > > > >   return SwapBytesXX (Value);
> > > > > > #else
> > > > > >   return Value;
> > > > > > #fi
> > > > > >
> > > > > > for the read operations and
> > > > > >
> > > > > > #ifdef SWAP_BYTES
> > > > > >   *(type)Address = SwapBytesXX (Value); #else
> > > > > >   *(type)Address = Value;
> > > > > > #fi
> > > > > >
> > > > > > for the write operations in IoLib.c?
> > > > > >
> > > > > > /
> > > > > >     Leif
> > > > > >
> > > > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000,
> Meenakshi Aggarwal
> > > > > > wrote:
> > > > > > > Hi Leif,
> > > > > > >
> > > > > > > This is regarding Big-Endian Library patch
> ([PATCH v2
> > > > > > 1/9]
> > > > > > > Platform/NXP: Add support for Big Endian Mmio
> APIs)
> > > > > > >
> > > > > > > We have started this discussion before and
> the
> > > > > > suggestion was to
> > > > > > > create a separate .inf file keeping APIs name
> same e.g.
> > > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > > >
> > > > > > > But we can't go with this approach (reason
> mentioned
> > > > > > by Udit).
> > > > > > >
> > > > > > > So please suggest if we should keep this
> library
> > > > > > under Platform/NXP
> > > > > > > or I send a new patch moving this library in
> MdePkg.
> > > > > > >
> > > > > > > But we have to keep a different name for Big
> Endian
> > > > > > MMIO APIs.
> > > > > > >
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Meenakshi
> > > > > > >
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: Udit Kumar
> > > > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > > > To: Gao, Liming <liming.gao@intel.com>;
> Meenakshi
> > > > > > Aggarwal
> > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> Biesheuvel
> > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> Michael D
> > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > devel@lists.01.org
> > > > > > > > Subject: RE: [edk2] [PATCH 1/1]
> MdePkg/IoLib: Add
> > > > > > support for big-endian
> > > > > > > > MMIO
> > > > > > > >
> > > > > > > > Hi Meenakshi/Liming,
> > > > > > > > My 2 cents, around this.
> > > > > > > >
> > > > > > > > 1)
> > > > > > > > Having a new lib for BE read might not be
> helpful
> > > > > > for us, e.g. a IP which is in
> > > > > > > > BE mode access the UART for print or system
> > > > > > registers which are in LE, then
> > > > > > > > with new Lib, we will get all read/write in
> BE mode
> > > > > > > >
> > > > > > > > 2)
> > > > > > > > Especially for our IPs, which are changing
> from BE
> > > > > > to LE depending on
> > > > > > > > platform.
> > > > > > > > As said before, having BE read lib with API
> name of
> > > > > > MmioRead32 etc, will not
> > > > > > > > help (I guess Meenakshi already seen some
> problems
> > > > > > around this) Adding a
> > > > > > > > new lib with MmioRead32BE API name could
> help, but
> > > > > > IP driver we need to
> > > > > > > > take care of IP mode either by Pcd or
> #define, to
> > > > > > select MmioRead32 or
> > > > > > > > MmioRead32BE.
> > > > > > > > This conditional compile needs to be done
> for all
> > > > > > IPs (which works in BE/LE
> > > > > > > > mode on different platforms).
> > > > > > > >
> > > > > > > > My preferred way of implementation to use
> one
> > > > > > function in IP driver, And
> > > > > > > > based on IP mode, do the switch.
> > > > > > > >
> > > > > > > > New Lib could have function like below
> > > > > > > > MmioRead32Generic(IN  UINTN     Address,
> BOOL
> > > > > > IsIPBE) {
> > > > > > > >    UINT32                            Value;
> > > > > > > >
> > > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > > >    Value = *(volatile UINT32*)Address;
> > > > > > > >    If(IsIPBE)
> > > > > > > >      Value = SwapBytes32(Value);  return
> Value; }
> > > > > > > >
> > > > > > > > And IP driver can use it
> > > > > > > > MmioRead32Generic(ADDR,
> > > > > > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > > >
> > > > > > > > Comments are welcome.
> > > > > > > >
> > > > > > > > Regards
> > > > > > > > Udit
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > > Gao, Liming
> > > > > > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > > > > > To: Meenakshi Aggarwal
> > > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> Michael D
> > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > devel@lists.01.org
> > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> MdePkg/IoLib: Add
> > > > > > support for
> > > > > > > > > big-endian MMIO
> > > > > > > > >
> > > > > > > > > Meenakshi:
> > > > > > > > >   I suggest to introduce new IoLib
> library
> > > > > > instance, not to add new IoLib
> > > > > > > > APIs.
> > > > > > > > > New IoLib library instance will perform
> IO
> > > > > > operation as the big
> > > > > > > > > endian. You can update
> > > > > > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > > > > > new source file and new INF for it.
> > > > > > > > >
> > > > > > > > > UINT32
> > > > > > > > > EFIAPI
> > > > > > > > > MmioRead32 (
> > > > > > > > >   IN  UINTN     Address
> > > > > > > > >   )
> > > > > > > > > {
> > > > > > > > >   UINT32
> Value;
> > > > > > > > >
> > > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > > > >   return SwapBytes32(Value); }
> > > > > > > > >
> > > > > > > > > Thanks
> > > > > > > > > Liming
> > > > > > > > > >-----Original Message-----
> > > > > > > > > >From: Meenakshi Aggarwal
> > > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > > > > > >To: Ard Biesheuvel
> <ard.biesheuvel@linaro.org>;
> > > > > > Kinney, Michael D
> > > > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > > ><liming.gao@intel.com>
> > > > > > > > > >Subject: RE: [edk2] [PATCH 1/1]
> MdePkg/IoLib:
> > > > > > Add support for
> > > > > > > > > >big-endian MMIO
> > > > > > > > > >
> > > > > > > > > >Hi All,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >It’s a pretty old discussion, we have
> left the
> > > > > > upstreaming of NXP
> > > > > > > > > >package in between because of some other
> work,
> > > > > > but have started it
> > > > > > > > > >again
> > > > > > > > > now.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >Issue  : Few NXP modules support Big
> Endian
> > > > > > MMIOs as these are ported
> > > > > > > > > >from PowerPC.
> > > > > > > > > >
> > > > > > > > > >Solution suggested : Create a separate
> library
> > > > > > for BE MMIO APIs.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >So what I have done is, I have created a
> > > > > > separate library to support
> > > > > > > > > >BE MMIO APIs and currently keeping it to
> my
> > > > > > package.
> > > > > > > > > >This library is basically a wrapper over
> > > > > > existing MMIO APIs.
> > > > > > > > > >
> > > > > > > > > >UINT32
> > > > > > > > > >EFIAPI
> > > > > > > > > >BeMmioRead32 (
> > > > > > > > > >  IN  UINTN     Address
> > > > > > > > > >  )
> > > > > > > > > >{
> > > > > > > > > >  UINT32  Value;
> > > > > > > > > >
> > > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > > >
> > > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >Need your opinion on below optinos:
> > > > > > > > > >
> > > > > > > > > >1. Will this be a good idea to make this
> library
> > > > > > a part of MdePkg? OR
> > > > > > > > > >
> > > > > > > > > >2. Add a new file e.g. IoBeMmio.c like
> > > > > > IoHighLevel.c in
> > > > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > > And made these APIs a part of IoLib
> itself. OR
> > > > > > > > > >
> > > > > > > > > >3. Keep this library internal to NXP
> package.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >Please provide your inputs.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >Thanks & Regards,
> > > > > > > > > >Meenakshi
> > > > > > > > > >
> > > > > > > > > >> -----Original Message-----
> > > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > > > > > >> To: Ard Biesheuvel
> > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > > >> Cc: Gao, Liming
> <liming.gao@intel.com>; edk2-
> > > > > > devel@ml01.01.org;
> > > > > > > > > >> Meenakshi Aggarwal
> > > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > > >> Subject: RE: [edk2] [PATCH 1/1]
> MdePkg/IoLib:
> > > > > > Add support for
> > > > > > > > > >> big-endian MMIO
> > > > > > > > > >>
> > > > > > > > > >> Hi Ard,
> > > > > > > > > >>
> > > > > > > > > >> > -----Original Message-----
> > > > > > > > > >> > From: Ard Biesheuvel
> > > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > > >> > Sent: Monday, October 17, 2016 1:12
> PM
> > > > > > > > > >> > To: Kinney, Michael D
> > > > > > <michael.d.kinney@intel.com>
> > > > > > > > > >> > Cc: Gao, Liming
> <liming.gao@intel.com>;
> > > > > > Bhupesh Sharma
> > > > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > > > devel@ml01.01.org
> > > > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > > > MdePkg/IoLib: Add support for
> > > > > > > > > >> > big- endian MMIO
> > > > > > > > > >> >
> > > > > > > > > >> > On 17 October 2016 at 05:10, Kinney,
> Michael
> > > > > > D
> > > > > > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > > > > > >> > > Bhupesh,
> > > > > > > > > >> > >
> > > > > > > > > >> > > It is also possible to add an ARM
> specific
> > > > > > PCD to select
> > > > > > > > > >> > > endianness and update
> > > > > > > > > >> > >
> > > > > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to
> use that PCD in
> > > > > > > > > >> > > MmioRead/Write() APIs in that file
> to
> > > > > > support both endian types.
> > > > > > > > > >> > > You can use the SwapBytesxx()
> functions
> > > > > > from BaseLib(as
> > > > > > > > > >> > Laszlo
> > > > > > > > > >> > > suggested) based on the setting of
> this
> > > > > > ARM specific PCD.
> > > > > > > > > >> > >
> > > > > > > > > >> > > Modules that link against this lib
> can
> > > > > > select endianness by
> > > > > > > > > >> > > setting PCD in the scope of that
> module.
> > > > > > > > > >> > >
> > > > > > > > > >> > > The IPF version of IoLib uses an
> IPF
> > > > > > specific PCD to translate
> > > > > > > > > >> > > I/O port accesses to MMIO
> accesses.  So
> > > > > > there is already an
> > > > > > > > > >> > > example of an arch specific PCD in
> this
> > > > > > lib instance.
> > > > > > > > > >> > >
> > > > > > > > > >> >
> > > > > > > > > >> > This is not a platform wide thing,
> it is a
> > > > > > per-device property
> > > > > > > > > >> > whether the MMIO occurs in big
> endian or
> > > > > > little endian manner.
> > > > > > > > > >> >
> > > > > > > > > >> > So I think Liming's suggestion makes
> sense:
> > > > > > create an IoLib
> > > > > > > > > >> > implementation that performs the
> byte
> > > > > > swapping, and selectively
> > > > > > > > > >> > incorporate it into drivers that
> require it
> > > > > > using
> > > > > > > > > >> >
> > > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > > >> >   <LibraryClasses>
> > > > > > > > > >> >
> IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > > >> > }
> > > > > > > > > >>
> > > > > > > > > >> That's correct. I think creating a
> separate
> > > > > > IoLib for byte-swapping
> > > > > > > > > >> makes sense.
> > > > > > > > > >>
> > > > > > > > > >> We will rework the patch accordingly.
> > > > > > > > > >>
> > > > > > > > > >> Regards,
> > > > > > > > > >> Bhupesh
> > > > > > > > >
> _______________________________________________
> > > > > > > > > edk2-devel mailing list
> > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > >
> > > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> s%3A%2F%2Fl
> > > > ist
> > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > >
> >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> 3cbb51
> > > >
> >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> 7C0%7C0
> > > >
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> dEQ
> > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > _______________________________________________
> > > > > > edk2-devel mailing list
> > > > > > edk2-devel@lists.01.org
> > > > > >
> > > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> s%3A%2F%2Fl
> > > > ist
> > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > >
> >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> 3cbb51
> > > >
> >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> 7C0%7C0
> > > >
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> dEQ
> > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> >
> https://emea01.safelinks.protection.outlook.com/?url=http
> s%3A%2F%2Flists.01
> > .org%2Fmailman%2Flistinfo%2Fedk2-
> >
> devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a064
> 8fa8e440
> >
> 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> 6364772
> >
> 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alH
> Y4ptAX
> > MU%3D&reserved=0

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-01 22:41                             ` Kinney, Michael D
@ 2017-12-04  6:18                               ` Meenakshi Aggarwal
  2017-12-04 12:36                               ` Leif Lindholm
  1 sibling, 0 replies; 25+ messages in thread
From: Meenakshi Aggarwal @ 2017-12-04  6:18 UTC (permalink / raw)
  To: Kinney, Michael D, Leif Lindholm
  Cc: edk2-devel@lists.01.org, Gao, Liming, Ard Biesheuvel, Varun Sethi,
	Udit Kumar

Hi Leif,


Michael is in favor of adding separate APIs for byte swap operation and 
We also prefer keeping it as a separate library because of following use case:

Driver which is in BE mode, and is using DebugLib which uses SerialPortLib, which is in LE mode.
This is the main issue because of which we cannot use same APIs for byte swapping.


Please give your views.


Thanks,
Meenakshi

> -----Original Message-----
> From: Kinney, Michael D [mailto:michael.d.kinney@intel.com]
> Sent: Saturday, December 02, 2017 4:11 AM
> To: Udit Kumar <udit.kumar@nxp.com>; Leif Lindholm
> <leif.lindholm@linaro.org>; Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> Cc: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>; Ard
> Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support for big-endian
> MMIO
> 
> Udit,
> 
> I agree with your concern.
> 
> I am in favor of adding new APIs that perform the
> byte swap operations.
> 
> Mike
> 
> > -----Original Message-----
> > From: Udit Kumar [mailto:udit.kumar@nxp.com]
> > Sent: Friday, December 1, 2017 9:58 AM
> > To: Leif Lindholm <leif.lindholm@linaro.org>; Meenakshi
> > Aggarwal <meenakshi.aggarwal@nxp.com>; Varun Sethi
> > <V.Sethi@nxp.com>
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>; edk2-
> > devel@lists.01.org; Gao, Liming <liming.gao@intel.com>;
> > Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support
> > for big-endian MMIO
> >
> > Thanks Leif,
> >
> > > It may require a little bit more of up-front work, but
> > the end result will be a
> > > platform port that works with the intended edk2 design
> > principles rather than
> >
> > Yes, this will be re-design/code for us, breaking all
> > software pieces into
> > smaller blocks and exposing protocol from the same.
> > This could be managed.
> >
> > But how do you see,  if there is such dependency oN lib.
> > Say a driver which is in BE mode, and is using DebugLib
> > (BaseDebugLibSerialPort)
> > And DebugLib uses SerialPortLib, which is in LE mode
> >
> > Thanks
> > Udit
> >
> > > -----Original Message-----
> > > From: edk2-devel [mailto:edk2-devel-
> > bounces@lists.01.org] On Behalf Of Leif
> > > Lindholm
> > > Sent: Friday, December 01, 2017 4:28 PM
> > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > edk2-devel@lists.01.org;
> > > Gao, Liming <liming.gao@intel.com>; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>
> > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for big-endian
> > > MMIO
> > >
> > > On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi
> > Aggarwal wrote:
> > > > Hi Leif, Mike,
> > > >
> > > >
> > > > NXP boards, at present, have few controllers with big
> > endian and other
> > > > with little endian memory access.
> > >
> > > Sure, this is not a problem.
> > >
> > > > Maximum controllers depend on SocLib library for
> > clock information and
> > > > endianness for SocLib and controllers is different.
> > >
> > > OK, I see in SocLib you have something called a Gur
> > that is read once (and again
> > > does a special per-device Pcd dance for runtime
> > selection between
> > > byteswapping Mmio and plain Mmio).
> > >
> > > > So this option will not work for us,
> > > >   You would then just do (in your .dsc):
> > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > >       IoLib|<path to BeIoLib .inf>
> > > >   }
> > > >
> > > > Because all libraries included by WatchDog will then
> > access BE mode Mmio
> > > APIs.
> > >
> > > Which libraries performing Mmio accesses are you
> > intending to include in your
> > > watchdog driver? You have submitted none as part of
> > this series.
> > >
> > > > And breaking code into separate modules with
> > different access will be
> > > > very difficult.
> > >
> > > It may require a little bit more of up-front work, but
> > the end result will be a
> > > platform port that works with the intended edk2 design
> > principles rather than
> > > against them. And that will reduce the overall effort
> > (not to mention code
> > > duplication).
> > >
> > > From the patches you have sent, the only required
> > change I see (if a
> > > byteswapping IoLib was added to edk2) would be to
> > create a tiny driver for this
> > > "Gur" device that installs a protocol containing a
> > single function for reading
> > > from that device's register space. That driver can be
> > built against the swapping
> > > or non-swapping IoLib as appropriate.
> > >
> > > > Watchdog is not the only module which need BE Mmio
> > APIs, we have MMC
> > > > and other controllers also with same requirement.
> > >
> > > And the same solutions are possible everywhere.
> > >
> > > Best Regards,
> > >
> > > Leif
> > >
> > > > We need BE Mmio APIs with a different name.
> > > >
> > > > Please see the possibility.
> > > >
> > > > Thanks & Regards,
> > > > Meenakshi
> > > >
> > > > > -----Original Message-----
> > > > > From: Leif Lindholm
> > [mailto:leif.lindholm@linaro.org]
> > > > > Sent: Thursday, November 30, 2017 1:19 AM
> > > > > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > > Cc: Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > <liming.gao@intel.com>; edk2-devel@lists.01.org;
> > Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>
> > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for
> > > > > big-endian MMIO
> > > > >
> > > > > I guess there is no strict rule about a driver only
> > directly
> > > > > accessing one piece of HW?
> > > > >
> > > > > Still, that would be one possible solution:
> > breaking accesses to a
> > > > > separate HW in need of byteswapping out into its
> > own module and
> > > > > letting it override IoLib version there.
> > > > >
> > > > > Regards,
> > > > >
> > > > > Leif
> > > > >
> > > > > On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney,
> > Michael D wrote:
> > > > > > Leif,
> > > > > >
> > > > > > I agree that this should be described as byte
> > swapping.
> > > > > >
> > > > > > What about a module that needs to access HW with
> > and without the
> > > > > > bytes swapped?  It gets more complex if a module
> > is linked against
> > > > > > several libs and some libs access HW with bytes
> > swapped and some
> > > > > > do not.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Mike
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: edk2-devel [mailto:edk2-devel-
> > bounces@lists.01.org] On
> > > > > > > Behalf Of Leif Lindholm
> > > > > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > > > > To: Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > <liming.gao@intel.com>
> > > > > > > Cc: Kinney, Michael D
> > <michael.d.kinney@intel.com>;
> > > > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > Add support for
> > > > > > > big-endian MMIO
> > > > > > >
> > > > > > > Hi Meenakshi,
> > > > > > >
> > > > > > > I finally got around to looking at the watchdog
> > code (that uses
> > > > > > > this library), and that has convinced me the
> > best solution is to
> > > > > > > do what Liming proposed.
> > > > > > >
> > > > > > > Looking at this snippet:
> > > > > > >
> > > > > > > > +STATIC
> > > > > > > > +UINT16
> > > > > > > > +EFIAPI
> > > > > > > > +WdogRead (
> > > > > > > > +  IN  UINTN     Address
> > > > > > > > +  )
> > > > > > > > +{
> > > > > > > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > > > > > > +    return BeMmioRead16 (Address);
> > > > > > > > +  } else {
> > > > > > > > +    return MmioRead16(Address);
> > > > > > > > +  }
> > > > > > >
> > > > > > > This is actually a pretty good demonstration of
> > the arguments
> > > > > > > that were made with regards to how the BeIoLib
> > could be just
> > > > > > > another implementation of IoLib.
> > > > > > >
> > > > > > > You would then just do (in your .dsc):
> > > > > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf
> > {
> > > > > > >     IoLib|<path to BeIoLib .inf>
> > > > > > >   }
> > > > > > >
> > > > > > > This causes the big-endian version of the
> > library to be used for
> > > > > > > this component. This makes these Wdog<access>
> > functions and the
> > > > > > > Pcd redundant, and the rest of the code can use
> > > > > > > MmioRead16()/MmioWrite16()
> > > > > > > directly.
> > > > > > >
> > > > > > > But then, it is not really a big-endian or
> > litte-endian version
> > > > > > > of the library we need. We always know which
> > endianness we are
> > > > > > > building for.
> > > > > > > What we need is a byteswapping flavour of
> > IoLib.
> > > > > > >
> > > > > > > So Liming, what if we do something like adding
> > a
> > > > > > >
> > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > > > p.inf
> > > > > > > ---
> > > > > > > [Defines]
> > > > > > >   INF_VERSION                    = 0x0001001A
> > > > > > >   BASE_NAME                      =
> > > > > > > BaseIoLibIntrinsicSwap
> > > > > > >   MODULE_UNI_FILE                =
> > > > > > > BaseIoLibIntrinsic.uni
> > > > > > >   FILE_GUID                      = d4a60d44-
> > 3688-4a50-
> > > > > > > b2d0-5c6fc2422523
> > > > > > >   MODULE_TYPE                    = BASE
> > > > > > >   VERSION_STRING                 = 1.0
> > > > > > >   LIBRARY_CLASS                  = IoLib
> > > > > > >
> > > > > > >
> > > > > > > #
> > > > > > > #  VALID_ARCHITECTURES           = IA32 X64 EBC
> > IPF ARM
> > > > > > > AARCH64
> > > > > > > #
> > > > > > >
> > > > > > > [Sources]
> > > > > > >   BaseIoLibIntrinsicInternal.h
> > > > > > >   IoHighLevel.c
> > > > > > >   IoLib.c
> > > > > > >   IoLibEbc.c         # Asserts on all i/o port
> > accesses
> > > > > > >   IoLibMmioBuffer.c
> > > > > > >
> > > > > > > [Packages]
> > > > > > >   MdePkg/MdePkg.dec
> > > > > > >
> > > > > > > [LibraryClasses]
> > > > > > >   DebugLib
> > > > > > >   BaseLib
> > > > > > >
> > > > > > > [BuildOptions]
> > > > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > > > ---
> > > > > > >
> > > > > > > And then add
> > > > > > >
> > > > > > > #ifdef SWAP_BYTES
> > > > > > >   return SwapBytesXX (Value);
> > > > > > > #else
> > > > > > >   return Value;
> > > > > > > #fi
> > > > > > >
> > > > > > > for the read operations and
> > > > > > >
> > > > > > > #ifdef SWAP_BYTES
> > > > > > >   *(type)Address = SwapBytesXX (Value); #else
> > > > > > >   *(type)Address = Value;
> > > > > > > #fi
> > > > > > >
> > > > > > > for the write operations in IoLib.c?
> > > > > > >
> > > > > > > /
> > > > > > >     Leif
> > > > > > >
> > > > > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000,
> > Meenakshi Aggarwal
> > > > > > > wrote:
> > > > > > > > Hi Leif,
> > > > > > > >
> > > > > > > > This is regarding Big-Endian Library patch
> > ([PATCH v2
> > > > > > > 1/9]
> > > > > > > > Platform/NXP: Add support for Big Endian Mmio
> > APIs)
> > > > > > > >
> > > > > > > > We have started this discussion before and
> > the
> > > > > > > suggestion was to
> > > > > > > > create a separate .inf file keeping APIs name
> > same e.g.
> > > > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > > > >
> > > > > > > > But we can't go with this approach (reason
> > mentioned
> > > > > > > by Udit).
> > > > > > > >
> > > > > > > > So please suggest if we should keep this
> > library
> > > > > > > under Platform/NXP
> > > > > > > > or I send a new patch moving this library in
> > MdePkg.
> > > > > > > >
> > > > > > > > But we have to keep a different name for Big
> > Endian
> > > > > > > MMIO APIs.
> > > > > > > >
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Meenakshi
> > > > > > > >
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: Udit Kumar
> > > > > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > > > > To: Gao, Liming <liming.gao@intel.com>;
> > Meenakshi
> > > > > > > Aggarwal
> > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > Biesheuvel
> > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > Michael D
> > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > devel@lists.01.org
> > > > > > > > > Subject: RE: [edk2] [PATCH 1/1]
> > MdePkg/IoLib: Add
> > > > > > > support for big-endian
> > > > > > > > > MMIO
> > > > > > > > >
> > > > > > > > > Hi Meenakshi/Liming,
> > > > > > > > > My 2 cents, around this.
> > > > > > > > >
> > > > > > > > > 1)
> > > > > > > > > Having a new lib for BE read might not be
> > helpful
> > > > > > > for us, e.g. a IP which is in
> > > > > > > > > BE mode access the UART for print or system
> > > > > > > registers which are in LE, then
> > > > > > > > > with new Lib, we will get all read/write in
> > BE mode
> > > > > > > > >
> > > > > > > > > 2)
> > > > > > > > > Especially for our IPs, which are changing
> > from BE
> > > > > > > to LE depending on
> > > > > > > > > platform.
> > > > > > > > > As said before, having BE read lib with API
> > name of
> > > > > > > MmioRead32 etc, will not
> > > > > > > > > help (I guess Meenakshi already seen some
> > problems
> > > > > > > around this) Adding a
> > > > > > > > > new lib with MmioRead32BE API name could
> > help, but
> > > > > > > IP driver we need to
> > > > > > > > > take care of IP mode either by Pcd or
> > #define, to
> > > > > > > select MmioRead32 or
> > > > > > > > > MmioRead32BE.
> > > > > > > > > This conditional compile needs to be done
> > for all
> > > > > > > IPs (which works in BE/LE
> > > > > > > > > mode on different platforms).
> > > > > > > > >
> > > > > > > > > My preferred way of implementation to use
> > one
> > > > > > > function in IP driver, And
> > > > > > > > > based on IP mode, do the switch.
> > > > > > > > >
> > > > > > > > > New Lib could have function like below
> > > > > > > > > MmioRead32Generic(IN  UINTN     Address,
> > BOOL
> > > > > > > IsIPBE) {
> > > > > > > > >    UINT32                            Value;
> > > > > > > > >
> > > > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > > > >    Value = *(volatile UINT32*)Address;
> > > > > > > > >    If(IsIPBE)
> > > > > > > > >      Value = SwapBytes32(Value);  return
> > Value; }
> > > > > > > > >
> > > > > > > > > And IP driver can use it
> > > > > > > > > MmioRead32Generic(ADDR,
> > > > > > > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > > > >
> > > > > > > > > Comments are welcome.
> > > > > > > > >
> > > > > > > > > Regards
> > > > > > > > > Udit
> > > > > > > > >
> > > > > > > > > > -----Original Message-----
> > > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > > > Gao, Liming
> > > > > > > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > > > > > > To: Meenakshi Aggarwal
> > > > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > Michael D
> > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > devel@lists.01.org
> > > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > MdePkg/IoLib: Add
> > > > > > > support for
> > > > > > > > > > big-endian MMIO
> > > > > > > > > >
> > > > > > > > > > Meenakshi:
> > > > > > > > > >   I suggest to introduce new IoLib
> > library
> > > > > > > instance, not to add new IoLib
> > > > > > > > > APIs.
> > > > > > > > > > New IoLib library instance will perform
> > IO
> > > > > > > operation as the big
> > > > > > > > > > endian. You can update
> > > > > > > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > > > > > > new source file and new INF for it.
> > > > > > > > > >
> > > > > > > > > > UINT32
> > > > > > > > > > EFIAPI
> > > > > > > > > > MmioRead32 (
> > > > > > > > > >   IN  UINTN     Address
> > > > > > > > > >   )
> > > > > > > > > > {
> > > > > > > > > >   UINT32
> > Value;
> > > > > > > > > >
> > > > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > > > > >   return SwapBytes32(Value); }
> > > > > > > > > >
> > > > > > > > > > Thanks
> > > > > > > > > > Liming
> > > > > > > > > > >-----Original Message-----
> > > > > > > > > > >From: Meenakshi Aggarwal
> > > > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > > > > > > >To: Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>;
> > > > > > > Kinney, Michael D
> > > > > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > > > ><liming.gao@intel.com>
> > > > > > > > > > >Subject: RE: [edk2] [PATCH 1/1]
> > MdePkg/IoLib:
> > > > > > > Add support for
> > > > > > > > > > >big-endian MMIO
> > > > > > > > > > >
> > > > > > > > > > >Hi All,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >It’s a pretty old discussion, we have
> > left the
> > > > > > > upstreaming of NXP
> > > > > > > > > > >package in between because of some other
> > work,
> > > > > > > but have started it
> > > > > > > > > > >again
> > > > > > > > > > now.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Issue  : Few NXP modules support Big
> > Endian
> > > > > > > MMIOs as these are ported
> > > > > > > > > > >from PowerPC.
> > > > > > > > > > >
> > > > > > > > > > >Solution suggested : Create a separate
> > library
> > > > > > > for BE MMIO APIs.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >So what I have done is, I have created a
> > > > > > > separate library to support
> > > > > > > > > > >BE MMIO APIs and currently keeping it to
> > my
> > > > > > > package.
> > > > > > > > > > >This library is basically a wrapper over
> > > > > > > existing MMIO APIs.
> > > > > > > > > > >
> > > > > > > > > > >UINT32
> > > > > > > > > > >EFIAPI
> > > > > > > > > > >BeMmioRead32 (
> > > > > > > > > > >  IN  UINTN     Address
> > > > > > > > > > >  )
> > > > > > > > > > >{
> > > > > > > > > > >  UINT32  Value;
> > > > > > > > > > >
> > > > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > > > >
> > > > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Need your opinion on below optinos:
> > > > > > > > > > >
> > > > > > > > > > >1. Will this be a good idea to make this
> > library
> > > > > > > a part of MdePkg? OR
> > > > > > > > > > >
> > > > > > > > > > >2. Add a new file e.g. IoBeMmio.c like
> > > > > > > IoHighLevel.c in
> > > > > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > > > And made these APIs a part of IoLib
> > itself. OR
> > > > > > > > > > >
> > > > > > > > > > >3. Keep this library internal to NXP
> > package.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Please provide your inputs.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Thanks & Regards,
> > > > > > > > > > >Meenakshi
> > > > > > > > > > >
> > > > > > > > > > >> -----Original Message-----
> > > > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > > > > > > >> To: Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > > > >> Cc: Gao, Liming
> > <liming.gao@intel.com>; edk2-
> > > > > > > devel@ml01.01.org;
> > > > > > > > > > >> Meenakshi Aggarwal
> > > > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > > > >> Subject: RE: [edk2] [PATCH 1/1]
> > MdePkg/IoLib:
> > > > > > > Add support for
> > > > > > > > > > >> big-endian MMIO
> > > > > > > > > > >>
> > > > > > > > > > >> Hi Ard,
> > > > > > > > > > >>
> > > > > > > > > > >> > -----Original Message-----
> > > > > > > > > > >> > From: Ard Biesheuvel
> > > > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > > > >> > Sent: Monday, October 17, 2016 1:12
> > PM
> > > > > > > > > > >> > To: Kinney, Michael D
> > > > > > > <michael.d.kinney@intel.com>
> > > > > > > > > > >> > Cc: Gao, Liming
> > <liming.gao@intel.com>;
> > > > > > > Bhupesh Sharma
> > > > > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > > > > devel@ml01.01.org
> > > > > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > > > > MdePkg/IoLib: Add support for
> > > > > > > > > > >> > big- endian MMIO
> > > > > > > > > > >> >
> > > > > > > > > > >> > On 17 October 2016 at 05:10, Kinney,
> > Michael
> > > > > > > D
> > > > > > > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > > > > > > >> > > Bhupesh,
> > > > > > > > > > >> > >
> > > > > > > > > > >> > > It is also possible to add an ARM
> > specific
> > > > > > > PCD to select
> > > > > > > > > > >> > > endianness and update
> > > > > > > > > > >> > >
> > > > > > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to
> > use that PCD in
> > > > > > > > > > >> > > MmioRead/Write() APIs in that file
> > to
> > > > > > > support both endian types.
> > > > > > > > > > >> > > You can use the SwapBytesxx()
> > functions
> > > > > > > from BaseLib(as
> > > > > > > > > > >> > Laszlo
> > > > > > > > > > >> > > suggested) based on the setting of
> > this
> > > > > > > ARM specific PCD.
> > > > > > > > > > >> > >
> > > > > > > > > > >> > > Modules that link against this lib
> > can
> > > > > > > select endianness by
> > > > > > > > > > >> > > setting PCD in the scope of that
> > module.
> > > > > > > > > > >> > >
> > > > > > > > > > >> > > The IPF version of IoLib uses an
> > IPF
> > > > > > > specific PCD to translate
> > > > > > > > > > >> > > I/O port accesses to MMIO
> > accesses.  So
> > > > > > > there is already an
> > > > > > > > > > >> > > example of an arch specific PCD in
> > this
> > > > > > > lib instance.
> > > > > > > > > > >> > >
> > > > > > > > > > >> >
> > > > > > > > > > >> > This is not a platform wide thing,
> > it is a
> > > > > > > per-device property
> > > > > > > > > > >> > whether the MMIO occurs in big
> > endian or
> > > > > > > little endian manner.
> > > > > > > > > > >> >
> > > > > > > > > > >> > So I think Liming's suggestion makes
> > sense:
> > > > > > > create an IoLib
> > > > > > > > > > >> > implementation that performs the
> > byte
> > > > > > > swapping, and selectively
> > > > > > > > > > >> > incorporate it into drivers that
> > require it
> > > > > > > using
> > > > > > > > > > >> >
> > > > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > > > >> >   <LibraryClasses>
> > > > > > > > > > >> >
> > IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > > > >> > }
> > > > > > > > > > >>
> > > > > > > > > > >> That's correct. I think creating a
> > separate
> > > > > > > IoLib for byte-swapping
> > > > > > > > > > >> makes sense.
> > > > > > > > > > >>
> > > > > > > > > > >> We will rework the patch accordingly.
> > > > > > > > > > >>
> > > > > > > > > > >> Regards,
> > > > > > > > > > >> Bhupesh
> > > > > > > > > >
> > _______________________________________________
> > > > > > > > > > edk2-devel mailing list
> > > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > > >
> > > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > s%3A%2F%2Fl
> > > > > ist
> > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > >
> > >
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > 3cbb51
> > > > >
> > >
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > 7C0%7C0
> > > > >
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > dEQ
> > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > > _______________________________________________
> > > > > > > edk2-devel mailing list
> > > > > > > edk2-devel@lists.01.org
> > > > > > >
> > > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > s%3A%2F%2Fl
> > > > > ist
> > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > >
> > >
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > 3cbb51
> > > > >
> > >
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > 7C0%7C0
> > > > >
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > dEQ
> > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > _______________________________________________
> > > edk2-devel mailing list
> > > edk2-devel@lists.01.org
> > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > s%3A%2F%2Flists.01
> > > .org%2Fmailman%2Flistinfo%2Fedk2-
> > >
> > devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a064
> > 8fa8e440
> > >
> > 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> > 6364772
> > >
> > 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alH
> > Y4ptAX
> > > MU%3D&reserved=0

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-01 22:41                             ` Kinney, Michael D
  2017-12-04  6:18                               ` Meenakshi Aggarwal
@ 2017-12-04 12:36                               ` Leif Lindholm
  2017-12-04 15:31                                 ` Kinney, Michael D
  1 sibling, 1 reply; 25+ messages in thread
From: Leif Lindholm @ 2017-12-04 12:36 UTC (permalink / raw)
  To: Kinney, Michael D
  Cc: Udit Kumar, Meenakshi Aggarwal, Varun Sethi,
	edk2-devel@lists.01.org, Gao, Liming, Ard Biesheuvel

Mike,

In that case - do you think it should be added to MdeModulePkg?

Should it be implemented simply as a wrapper on IoLib (depending on
it)?

/
    Leif

On Fri, Dec 01, 2017 at 10:41:26PM +0000, Kinney, Michael D wrote:
> Udit,
> 
> I agree with your concern.
> 
> I am in favor of adding new APIs that perform the
> byte swap operations.
> 
> Mike
> 
> > -----Original Message-----
> > From: Udit Kumar [mailto:udit.kumar@nxp.com]
> > Sent: Friday, December 1, 2017 9:58 AM
> > To: Leif Lindholm <leif.lindholm@linaro.org>; Meenakshi
> > Aggarwal <meenakshi.aggarwal@nxp.com>; Varun Sethi
> > <V.Sethi@nxp.com>
> > Cc: Kinney, Michael D <michael.d.kinney@intel.com>; edk2-
> > devel@lists.01.org; Gao, Liming <liming.gao@intel.com>;
> > Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support
> > for big-endian MMIO
> > 
> > Thanks Leif,
> > 
> > > It may require a little bit more of up-front work, but
> > the end result will be a
> > > platform port that works with the intended edk2 design
> > principles rather than
> > 
> > Yes, this will be re-design/code for us, breaking all
> > software pieces into
> > smaller blocks and exposing protocol from the same.
> > This could be managed.
> > 
> > But how do you see,  if there is such dependency oN lib.
> > Say a driver which is in BE mode, and is using DebugLib
> > (BaseDebugLibSerialPort)
> > And DebugLib uses SerialPortLib, which is in LE mode
> > 
> > Thanks
> > Udit
> > 
> > > -----Original Message-----
> > > From: edk2-devel [mailto:edk2-devel-
> > bounces@lists.01.org] On Behalf Of Leif
> > > Lindholm
> > > Sent: Friday, December 01, 2017 4:28 PM
> > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > edk2-devel@lists.01.org;
> > > Gao, Liming <liming.gao@intel.com>; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>
> > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for big-endian
> > > MMIO
> > >
> > > On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi
> > Aggarwal wrote:
> > > > Hi Leif, Mike,
> > > >
> > > >
> > > > NXP boards, at present, have few controllers with big
> > endian and other
> > > > with little endian memory access.
> > >
> > > Sure, this is not a problem.
> > >
> > > > Maximum controllers depend on SocLib library for
> > clock information and
> > > > endianness for SocLib and controllers is different.
> > >
> > > OK, I see in SocLib you have something called a Gur
> > that is read once (and again
> > > does a special per-device Pcd dance for runtime
> > selection between
> > > byteswapping Mmio and plain Mmio).
> > >
> > > > So this option will not work for us,
> > > >   You would then just do (in your .dsc):
> > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > >       IoLib|<path to BeIoLib .inf>
> > > >   }
> > > >
> > > > Because all libraries included by WatchDog will then
> > access BE mode Mmio
> > > APIs.
> > >
> > > Which libraries performing Mmio accesses are you
> > intending to include in your
> > > watchdog driver? You have submitted none as part of
> > this series.
> > >
> > > > And breaking code into separate modules with
> > different access will be
> > > > very difficult.
> > >
> > > It may require a little bit more of up-front work, but
> > the end result will be a
> > > platform port that works with the intended edk2 design
> > principles rather than
> > > against them. And that will reduce the overall effort
> > (not to mention code
> > > duplication).
> > >
> > > From the patches you have sent, the only required
> > change I see (if a
> > > byteswapping IoLib was added to edk2) would be to
> > create a tiny driver for this
> > > "Gur" device that installs a protocol containing a
> > single function for reading
> > > from that device's register space. That driver can be
> > built against the swapping
> > > or non-swapping IoLib as appropriate.
> > >
> > > > Watchdog is not the only module which need BE Mmio
> > APIs, we have MMC
> > > > and other controllers also with same requirement.
> > >
> > > And the same solutions are possible everywhere.
> > >
> > > Best Regards,
> > >
> > > Leif
> > >
> > > > We need BE Mmio APIs with a different name.
> > > >
> > > > Please see the possibility.
> > > >
> > > > Thanks & Regards,
> > > > Meenakshi
> > > >
> > > > > -----Original Message-----
> > > > > From: Leif Lindholm
> > [mailto:leif.lindholm@linaro.org]
> > > > > Sent: Thursday, November 30, 2017 1:19 AM
> > > > > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > > > > Cc: Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > <liming.gao@intel.com>; edk2-devel@lists.01.org;
> > Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>
> > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support for
> > > > > big-endian MMIO
> > > > >
> > > > > I guess there is no strict rule about a driver only
> > directly
> > > > > accessing one piece of HW?
> > > > >
> > > > > Still, that would be one possible solution:
> > breaking accesses to a
> > > > > separate HW in need of byteswapping out into its
> > own module and
> > > > > letting it override IoLib version there.
> > > > >
> > > > > Regards,
> > > > >
> > > > > Leif
> > > > >
> > > > > On Wed, Nov 29, 2017 at 07:25:05PM +0000, Kinney,
> > Michael D wrote:
> > > > > > Leif,
> > > > > >
> > > > > > I agree that this should be described as byte
> > swapping.
> > > > > >
> > > > > > What about a module that needs to access HW with
> > and without the
> > > > > > bytes swapped?  It gets more complex if a module
> > is linked against
> > > > > > several libs and some libs access HW with bytes
> > swapped and some
> > > > > > do not.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Mike
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: edk2-devel [mailto:edk2-devel-
> > bounces@lists.01.org] On
> > > > > > > Behalf Of Leif Lindholm
> > > > > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > > > > To: Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > <liming.gao@intel.com>
> > > > > > > Cc: Kinney, Michael D
> > <michael.d.kinney@intel.com>;
> > > > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > Add support for
> > > > > > > big-endian MMIO
> > > > > > >
> > > > > > > Hi Meenakshi,
> > > > > > >
> > > > > > > I finally got around to looking at the watchdog
> > code (that uses
> > > > > > > this library), and that has convinced me the
> > best solution is to
> > > > > > > do what Liming proposed.
> > > > > > >
> > > > > > > Looking at this snippet:
> > > > > > >
> > > > > > > > +STATIC
> > > > > > > > +UINT16
> > > > > > > > +EFIAPI
> > > > > > > > +WdogRead (
> > > > > > > > +  IN  UINTN     Address
> > > > > > > > +  )
> > > > > > > > +{
> > > > > > > > +  if (FixedPcdGetBool (PcdWdogBigEndian)) {
> > > > > > > > +    return BeMmioRead16 (Address);
> > > > > > > > +  } else {
> > > > > > > > +    return MmioRead16(Address);
> > > > > > > > +  }
> > > > > > >
> > > > > > > This is actually a pretty good demonstration of
> > the arguments
> > > > > > > that were made with regards to how the BeIoLib
> > could be just
> > > > > > > another implementation of IoLib.
> > > > > > >
> > > > > > > You would then just do (in your .dsc):
> > > > > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf
> > {
> > > > > > >     IoLib|<path to BeIoLib .inf>
> > > > > > >   }
> > > > > > >
> > > > > > > This causes the big-endian version of the
> > library to be used for
> > > > > > > this component. This makes these Wdog<access>
> > functions and the
> > > > > > > Pcd redundant, and the rest of the code can use
> > > > > > > MmioRead16()/MmioWrite16()
> > > > > > > directly.
> > > > > > >
> > > > > > > But then, it is not really a big-endian or
> > litte-endian version
> > > > > > > of the library we need. We always know which
> > endianness we are
> > > > > > > building for.
> > > > > > > What we need is a byteswapping flavour of
> > IoLib.
> > > > > > >
> > > > > > > So Liming, what if we do something like adding
> > a
> > > > > > >
> > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > > > p.inf
> > > > > > > ---
> > > > > > > [Defines]
> > > > > > >   INF_VERSION                    = 0x0001001A
> > > > > > >   BASE_NAME                      =
> > > > > > > BaseIoLibIntrinsicSwap
> > > > > > >   MODULE_UNI_FILE                =
> > > > > > > BaseIoLibIntrinsic.uni
> > > > > > >   FILE_GUID                      = d4a60d44-
> > 3688-4a50-
> > > > > > > b2d0-5c6fc2422523
> > > > > > >   MODULE_TYPE                    = BASE
> > > > > > >   VERSION_STRING                 = 1.0
> > > > > > >   LIBRARY_CLASS                  = IoLib
> > > > > > >
> > > > > > >
> > > > > > > #
> > > > > > > #  VALID_ARCHITECTURES           = IA32 X64 EBC
> > IPF ARM
> > > > > > > AARCH64
> > > > > > > #
> > > > > > >
> > > > > > > [Sources]
> > > > > > >   BaseIoLibIntrinsicInternal.h
> > > > > > >   IoHighLevel.c
> > > > > > >   IoLib.c
> > > > > > >   IoLibEbc.c         # Asserts on all i/o port
> > accesses
> > > > > > >   IoLibMmioBuffer.c
> > > > > > >
> > > > > > > [Packages]
> > > > > > >   MdePkg/MdePkg.dec
> > > > > > >
> > > > > > > [LibraryClasses]
> > > > > > >   DebugLib
> > > > > > >   BaseLib
> > > > > > >
> > > > > > > [BuildOptions]
> > > > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > > > ---
> > > > > > >
> > > > > > > And then add
> > > > > > >
> > > > > > > #ifdef SWAP_BYTES
> > > > > > >   return SwapBytesXX (Value);
> > > > > > > #else
> > > > > > >   return Value;
> > > > > > > #fi
> > > > > > >
> > > > > > > for the read operations and
> > > > > > >
> > > > > > > #ifdef SWAP_BYTES
> > > > > > >   *(type)Address = SwapBytesXX (Value); #else
> > > > > > >   *(type)Address = Value;
> > > > > > > #fi
> > > > > > >
> > > > > > > for the write operations in IoLib.c?
> > > > > > >
> > > > > > > /
> > > > > > >     Leif
> > > > > > >
> > > > > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000,
> > Meenakshi Aggarwal
> > > > > > > wrote:
> > > > > > > > Hi Leif,
> > > > > > > >
> > > > > > > > This is regarding Big-Endian Library patch
> > ([PATCH v2
> > > > > > > 1/9]
> > > > > > > > Platform/NXP: Add support for Big Endian Mmio
> > APIs)
> > > > > > > >
> > > > > > > > We have started this discussion before and
> > the
> > > > > > > suggestion was to
> > > > > > > > create a separate .inf file keeping APIs name
> > same e.g.
> > > > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > > > >
> > > > > > > > But we can't go with this approach (reason
> > mentioned
> > > > > > > by Udit).
> > > > > > > >
> > > > > > > > So please suggest if we should keep this
> > library
> > > > > > > under Platform/NXP
> > > > > > > > or I send a new patch moving this library in
> > MdePkg.
> > > > > > > >
> > > > > > > > But we have to keep a different name for Big
> > Endian
> > > > > > > MMIO APIs.
> > > > > > > >
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Meenakshi
> > > > > > > >
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: Udit Kumar
> > > > > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > > > > To: Gao, Liming <liming.gao@intel.com>;
> > Meenakshi
> > > > > > > Aggarwal
> > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > Biesheuvel
> > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > Michael D
> > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > devel@lists.01.org
> > > > > > > > > Subject: RE: [edk2] [PATCH 1/1]
> > MdePkg/IoLib: Add
> > > > > > > support for big-endian
> > > > > > > > > MMIO
> > > > > > > > >
> > > > > > > > > Hi Meenakshi/Liming,
> > > > > > > > > My 2 cents, around this.
> > > > > > > > >
> > > > > > > > > 1)
> > > > > > > > > Having a new lib for BE read might not be
> > helpful
> > > > > > > for us, e.g. a IP which is in
> > > > > > > > > BE mode access the UART for print or system
> > > > > > > registers which are in LE, then
> > > > > > > > > with new Lib, we will get all read/write in
> > BE mode
> > > > > > > > >
> > > > > > > > > 2)
> > > > > > > > > Especially for our IPs, which are changing
> > from BE
> > > > > > > to LE depending on
> > > > > > > > > platform.
> > > > > > > > > As said before, having BE read lib with API
> > name of
> > > > > > > MmioRead32 etc, will not
> > > > > > > > > help (I guess Meenakshi already seen some
> > problems
> > > > > > > around this) Adding a
> > > > > > > > > new lib with MmioRead32BE API name could
> > help, but
> > > > > > > IP driver we need to
> > > > > > > > > take care of IP mode either by Pcd or
> > #define, to
> > > > > > > select MmioRead32 or
> > > > > > > > > MmioRead32BE.
> > > > > > > > > This conditional compile needs to be done
> > for all
> > > > > > > IPs (which works in BE/LE
> > > > > > > > > mode on different platforms).
> > > > > > > > >
> > > > > > > > > My preferred way of implementation to use
> > one
> > > > > > > function in IP driver, And
> > > > > > > > > based on IP mode, do the switch.
> > > > > > > > >
> > > > > > > > > New Lib could have function like below
> > > > > > > > > MmioRead32Generic(IN  UINTN     Address,
> > BOOL
> > > > > > > IsIPBE) {
> > > > > > > > >    UINT32                            Value;
> > > > > > > > >
> > > > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > > > >    Value = *(volatile UINT32*)Address;
> > > > > > > > >    If(IsIPBE)
> > > > > > > > >      Value = SwapBytes32(Value);  return
> > Value; }
> > > > > > > > >
> > > > > > > > > And IP driver can use it
> > > > > > > > > MmioRead32Generic(ADDR,
> > > > > > > > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > > > >
> > > > > > > > > Comments are welcome.
> > > > > > > > >
> > > > > > > > > Regards
> > > > > > > > > Udit
> > > > > > > > >
> > > > > > > > > > -----Original Message-----
> > > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > > > Gao, Liming
> > > > > > > > > > Sent: Monday, October 16, 2017 8:48 AM
> > > > > > > > > > To: Meenakshi Aggarwal
> > > > > > > <meenakshi.aggarwal@nxp.com>; Ard Biesheuvel
> > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > Michael D
> > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > devel@lists.01.org
> > > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > MdePkg/IoLib: Add
> > > > > > > support for
> > > > > > > > > > big-endian MMIO
> > > > > > > > > >
> > > > > > > > > > Meenakshi:
> > > > > > > > > >   I suggest to introduce new IoLib
> > library
> > > > > > > instance, not to add new IoLib
> > > > > > > > > APIs.
> > > > > > > > > > New IoLib library instance will perform
> > IO
> > > > > > > operation as the big
> > > > > > > > > > endian. You can update
> > > > > > > MdePkg/Library/BaseIoLibIntrinsic instance, add
> > > > > > > > > > new source file and new INF for it.
> > > > > > > > > >
> > > > > > > > > > UINT32
> > > > > > > > > > EFIAPI
> > > > > > > > > > MmioRead32 (
> > > > > > > > > >   IN  UINTN     Address
> > > > > > > > > >   )
> > > > > > > > > > {
> > > > > > > > > >   UINT32
> > Value;
> > > > > > > > > >
> > > > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > > > > >   return SwapBytes32(Value); }
> > > > > > > > > >
> > > > > > > > > > Thanks
> > > > > > > > > > Liming
> > > > > > > > > > >-----Original Message-----
> > > > > > > > > > >From: Meenakshi Aggarwal
> > > > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > > > >Sent: Friday, October 13, 2017 2:07 PM
> > > > > > > > > > >To: Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>;
> > > > > > > Kinney, Michael D
> > > > > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > > > ><liming.gao@intel.com>
> > > > > > > > > > >Subject: RE: [edk2] [PATCH 1/1]
> > MdePkg/IoLib:
> > > > > > > Add support for
> > > > > > > > > > >big-endian MMIO
> > > > > > > > > > >
> > > > > > > > > > >Hi All,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >It’s a pretty old discussion, we have
> > left the
> > > > > > > upstreaming of NXP
> > > > > > > > > > >package in between because of some other
> > work,
> > > > > > > but have started it
> > > > > > > > > > >again
> > > > > > > > > > now.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Issue  : Few NXP modules support Big
> > Endian
> > > > > > > MMIOs as these are ported
> > > > > > > > > > >from PowerPC.
> > > > > > > > > > >
> > > > > > > > > > >Solution suggested : Create a separate
> > library
> > > > > > > for BE MMIO APIs.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >So what I have done is, I have created a
> > > > > > > separate library to support
> > > > > > > > > > >BE MMIO APIs and currently keeping it to
> > my
> > > > > > > package.
> > > > > > > > > > >This library is basically a wrapper over
> > > > > > > existing MMIO APIs.
> > > > > > > > > > >
> > > > > > > > > > >UINT32
> > > > > > > > > > >EFIAPI
> > > > > > > > > > >BeMmioRead32 (
> > > > > > > > > > >  IN  UINTN     Address
> > > > > > > > > > >  )
> > > > > > > > > > >{
> > > > > > > > > > >  UINT32  Value;
> > > > > > > > > > >
> > > > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > > > >
> > > > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Need your opinion on below optinos:
> > > > > > > > > > >
> > > > > > > > > > >1. Will this be a good idea to make this
> > library
> > > > > > > a part of MdePkg? OR
> > > > > > > > > > >
> > > > > > > > > > >2. Add a new file e.g. IoBeMmio.c like
> > > > > > > IoHighLevel.c in
> > > > > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > > > And made these APIs a part of IoLib
> > itself. OR
> > > > > > > > > > >
> > > > > > > > > > >3. Keep this library internal to NXP
> > package.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Please provide your inputs.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >Thanks & Regards,
> > > > > > > > > > >Meenakshi
> > > > > > > > > > >
> > > > > > > > > > >> -----Original Message-----
> > > > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > > > >> Sent: Monday, October 17, 2016 3:28 PM
> > > > > > > > > > >> To: Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>; Kinney, Michael D
> > > > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > > > >> Cc: Gao, Liming
> > <liming.gao@intel.com>; edk2-
> > > > > > > devel@ml01.01.org;
> > > > > > > > > > >> Meenakshi Aggarwal
> > > > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > > > >> Subject: RE: [edk2] [PATCH 1/1]
> > MdePkg/IoLib:
> > > > > > > Add support for
> > > > > > > > > > >> big-endian MMIO
> > > > > > > > > > >>
> > > > > > > > > > >> Hi Ard,
> > > > > > > > > > >>
> > > > > > > > > > >> > -----Original Message-----
> > > > > > > > > > >> > From: Ard Biesheuvel
> > > > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > > > >> > Sent: Monday, October 17, 2016 1:12
> > PM
> > > > > > > > > > >> > To: Kinney, Michael D
> > > > > > > <michael.d.kinney@intel.com>
> > > > > > > > > > >> > Cc: Gao, Liming
> > <liming.gao@intel.com>;
> > > > > > > Bhupesh Sharma
> > > > > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > > > > devel@ml01.01.org
> > > > > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > > > > MdePkg/IoLib: Add support for
> > > > > > > > > > >> > big- endian MMIO
> > > > > > > > > > >> >
> > > > > > > > > > >> > On 17 October 2016 at 05:10, Kinney,
> > Michael
> > > > > > > D
> > > > > > > > > > >> > <michael.d.kinney@intel.com> wrote:
> > > > > > > > > > >> > > Bhupesh,
> > > > > > > > > > >> > >
> > > > > > > > > > >> > > It is also possible to add an ARM
> > specific
> > > > > > > PCD to select
> > > > > > > > > > >> > > endianness and update
> > > > > > > > > > >> > >
> > > > > > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to
> > use that PCD in
> > > > > > > > > > >> > > MmioRead/Write() APIs in that file
> > to
> > > > > > > support both endian types.
> > > > > > > > > > >> > > You can use the SwapBytesxx()
> > functions
> > > > > > > from BaseLib(as
> > > > > > > > > > >> > Laszlo
> > > > > > > > > > >> > > suggested) based on the setting of
> > this
> > > > > > > ARM specific PCD.
> > > > > > > > > > >> > >
> > > > > > > > > > >> > > Modules that link against this lib
> > can
> > > > > > > select endianness by
> > > > > > > > > > >> > > setting PCD in the scope of that
> > module.
> > > > > > > > > > >> > >
> > > > > > > > > > >> > > The IPF version of IoLib uses an
> > IPF
> > > > > > > specific PCD to translate
> > > > > > > > > > >> > > I/O port accesses to MMIO
> > accesses.  So
> > > > > > > there is already an
> > > > > > > > > > >> > > example of an arch specific PCD in
> > this
> > > > > > > lib instance.
> > > > > > > > > > >> > >
> > > > > > > > > > >> >
> > > > > > > > > > >> > This is not a platform wide thing,
> > it is a
> > > > > > > per-device property
> > > > > > > > > > >> > whether the MMIO occurs in big
> > endian or
> > > > > > > little endian manner.
> > > > > > > > > > >> >
> > > > > > > > > > >> > So I think Liming's suggestion makes
> > sense:
> > > > > > > create an IoLib
> > > > > > > > > > >> > implementation that performs the
> > byte
> > > > > > > swapping, and selectively
> > > > > > > > > > >> > incorporate it into drivers that
> > require it
> > > > > > > using
> > > > > > > > > > >> >
> > > > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > > > >> >   <LibraryClasses>
> > > > > > > > > > >> >
> > IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > > > >> > }
> > > > > > > > > > >>
> > > > > > > > > > >> That's correct. I think creating a
> > separate
> > > > > > > IoLib for byte-swapping
> > > > > > > > > > >> makes sense.
> > > > > > > > > > >>
> > > > > > > > > > >> We will rework the patch accordingly.
> > > > > > > > > > >>
> > > > > > > > > > >> Regards,
> > > > > > > > > > >> Bhupesh
> > > > > > > > > >
> > _______________________________________________
> > > > > > > > > > edk2-devel mailing list
> > > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > > >
> > > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > s%3A%2F%2Fl
> > > > > ist
> > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > >
> > >
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > 3cbb51
> > > > >
> > >
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > 7C0%7C0
> > > > >
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > dEQ
> > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > > _______________________________________________
> > > > > > > edk2-devel mailing list
> > > > > > > edk2-devel@lists.01.org
> > > > > > >
> > > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > s%3A%2F%2Fl
> > > > > ist
> > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > >
> > >
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > 3cbb51
> > > > >
> > >
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > 7C0%7C0
> > > > >
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > dEQ
> > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > _______________________________________________
> > > edk2-devel mailing list
> > > edk2-devel@lists.01.org
> > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > s%3A%2F%2Flists.01
> > > .org%2Fmailman%2Flistinfo%2Fedk2-
> > >
> > devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a064
> > 8fa8e440
> > >
> > 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> > 6364772
> > >
> > 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alH
> > Y4ptAX
> > > MU%3D&reserved=0


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-04 12:36                               ` Leif Lindholm
@ 2017-12-04 15:31                                 ` Kinney, Michael D
  2017-12-04 15:54                                   ` Leif Lindholm
  0 siblings, 1 reply; 25+ messages in thread
From: Kinney, Michael D @ 2017-12-04 15:31 UTC (permalink / raw)
  To: Leif Lindholm, Kinney, Michael D
  Cc: Udit Kumar, Meenakshi Aggarwal, Varun Sethi,
	edk2-devel@lists.01.org, Gao, Liming, Ard Biesheuvel

Leif,

I may make more sense to add to MdePkg as a peer to IoLib.
This minimizes the package dependencies for Si modules.

I am ok as a wrapper on top of IoLib.  Whatever reduces 
code duplication and reduces maintenance.

Best regards,

Mike

> -----Original Message-----
> From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> Sent: Monday, December 4, 2017 4:36 AM
> To: Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Udit Kumar <udit.kumar@nxp.com>; Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Varun Sethi
> <V.Sethi@nxp.com>; edk2-devel@lists.01.org; Gao, Liming
> <liming.gao@intel.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support
> for big-endian MMIO
> 
> Mike,
> 
> In that case - do you think it should be added to
> MdeModulePkg?
> 
> Should it be implemented simply as a wrapper on IoLib
> (depending on
> it)?
> 
> /
>     Leif
> 
> On Fri, Dec 01, 2017 at 10:41:26PM +0000, Kinney, Michael
> D wrote:
> > Udit,
> >
> > I agree with your concern.
> >
> > I am in favor of adding new APIs that perform the
> > byte swap operations.
> >
> > Mike
> >
> > > -----Original Message-----
> > > From: Udit Kumar [mailto:udit.kumar@nxp.com]
> > > Sent: Friday, December 1, 2017 9:58 AM
> > > To: Leif Lindholm <leif.lindholm@linaro.org>;
> Meenakshi
> > > Aggarwal <meenakshi.aggarwal@nxp.com>; Varun Sethi
> > > <V.Sethi@nxp.com>
> > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> edk2-
> > > devel@lists.01.org; Gao, Liming
> <liming.gao@intel.com>;
> > > Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support
> > > for big-endian MMIO
> > >
> > > Thanks Leif,
> > >
> > > > It may require a little bit more of up-front work,
> but
> > > the end result will be a
> > > > platform port that works with the intended edk2
> design
> > > principles rather than
> > >
> > > Yes, this will be re-design/code for us, breaking all
> > > software pieces into
> > > smaller blocks and exposing protocol from the same.
> > > This could be managed.
> > >
> > > But how do you see,  if there is such dependency oN
> lib.
> > > Say a driver which is in BE mode, and is using
> DebugLib
> > > (BaseDebugLibSerialPort)
> > > And DebugLib uses SerialPortLib, which is in LE mode
> > >
> > > Thanks
> > > Udit
> > >
> > > > -----Original Message-----
> > > > From: edk2-devel [mailto:edk2-devel-
> > > bounces@lists.01.org] On Behalf Of Leif
> > > > Lindholm
> > > > Sent: Friday, December 01, 2017 4:28 PM
> > > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > edk2-devel@lists.01.org;
> > > > Gao, Liming <liming.gao@intel.com>; Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>
> > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > support for big-endian
> > > > MMIO
> > > >
> > > > On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi
> > > Aggarwal wrote:
> > > > > Hi Leif, Mike,
> > > > >
> > > > >
> > > > > NXP boards, at present, have few controllers with
> big
> > > endian and other
> > > > > with little endian memory access.
> > > >
> > > > Sure, this is not a problem.
> > > >
> > > > > Maximum controllers depend on SocLib library for
> > > clock information and
> > > > > endianness for SocLib and controllers is
> different.
> > > >
> > > > OK, I see in SocLib you have something called a Gur
> > > that is read once (and again
> > > > does a special per-device Pcd dance for runtime
> > > selection between
> > > > byteswapping Mmio and plain Mmio).
> > > >
> > > > > So this option will not work for us,
> > > > >   You would then just do (in your .dsc):
> > > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > > >       IoLib|<path to BeIoLib .inf>
> > > > >   }
> > > > >
> > > > > Because all libraries included by WatchDog will
> then
> > > access BE mode Mmio
> > > > APIs.
> > > >
> > > > Which libraries performing Mmio accesses are you
> > > intending to include in your
> > > > watchdog driver? You have submitted none as part of
> > > this series.
> > > >
> > > > > And breaking code into separate modules with
> > > different access will be
> > > > > very difficult.
> > > >
> > > > It may require a little bit more of up-front work,
> but
> > > the end result will be a
> > > > platform port that works with the intended edk2
> design
> > > principles rather than
> > > > against them. And that will reduce the overall
> effort
> > > (not to mention code
> > > > duplication).
> > > >
> > > > From the patches you have sent, the only required
> > > change I see (if a
> > > > byteswapping IoLib was added to edk2) would be to
> > > create a tiny driver for this
> > > > "Gur" device that installs a protocol containing a
> > > single function for reading
> > > > from that device's register space. That driver can
> be
> > > built against the swapping
> > > > or non-swapping IoLib as appropriate.
> > > >
> > > > > Watchdog is not the only module which need BE
> Mmio
> > > APIs, we have MMC
> > > > > and other controllers also with same requirement.
> > > >
> > > > And the same solutions are possible everywhere.
> > > >
> > > > Best Regards,
> > > >
> > > > Leif
> > > >
> > > > > We need BE Mmio APIs with a different name.
> > > > >
> > > > > Please see the possibility.
> > > > >
> > > > > Thanks & Regards,
> > > > > Meenakshi
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Leif Lindholm
> > > [mailto:leif.lindholm@linaro.org]
> > > > > > Sent: Thursday, November 30, 2017 1:19 AM
> > > > > > To: Kinney, Michael D
> <michael.d.kinney@intel.com>
> > > > > > Cc: Meenakshi Aggarwal
> > > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > <liming.gao@intel.com>; edk2-
> devel@lists.01.org;
> > > Ard Biesheuvel
> > > > > > <ard.biesheuvel@linaro.org>
> > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib:
> Add
> > > support for
> > > > > > big-endian MMIO
> > > > > >
> > > > > > I guess there is no strict rule about a driver
> only
> > > directly
> > > > > > accessing one piece of HW?
> > > > > >
> > > > > > Still, that would be one possible solution:
> > > breaking accesses to a
> > > > > > separate HW in need of byteswapping out into
> its
> > > own module and
> > > > > > letting it override IoLib version there.
> > > > > >
> > > > > > Regards,
> > > > > >
> > > > > > Leif
> > > > > >
> > > > > > On Wed, Nov 29, 2017 at 07:25:05PM +0000,
> Kinney,
> > > Michael D wrote:
> > > > > > > Leif,
> > > > > > >
> > > > > > > I agree that this should be described as byte
> > > swapping.
> > > > > > >
> > > > > > > What about a module that needs to access HW
> with
> > > and without the
> > > > > > > bytes swapped?  It gets more complex if a
> module
> > > is linked against
> > > > > > > several libs and some libs access HW with
> bytes
> > > swapped and some
> > > > > > > do not.
> > > > > > >
> > > > > > > Thanks,
> > > > > > >
> > > > > > > Mike
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > bounces@lists.01.org] On
> > > > > > > > Behalf Of Leif Lindholm
> > > > > > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > > > > > To: Meenakshi Aggarwal
> > > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > > <liming.gao@intel.com>
> > > > > > > > Cc: Kinney, Michael D
> > > <michael.d.kinney@intel.com>;
> > > > > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> MdePkg/IoLib:
> > > Add support for
> > > > > > > > big-endian MMIO
> > > > > > > >
> > > > > > > > Hi Meenakshi,
> > > > > > > >
> > > > > > > > I finally got around to looking at the
> watchdog
> > > code (that uses
> > > > > > > > this library), and that has convinced me
> the
> > > best solution is to
> > > > > > > > do what Liming proposed.
> > > > > > > >
> > > > > > > > Looking at this snippet:
> > > > > > > >
> > > > > > > > > +STATIC
> > > > > > > > > +UINT16
> > > > > > > > > +EFIAPI
> > > > > > > > > +WdogRead (
> > > > > > > > > +  IN  UINTN     Address
> > > > > > > > > +  )
> > > > > > > > > +{
> > > > > > > > > +  if (FixedPcdGetBool
> (PcdWdogBigEndian)) {
> > > > > > > > > +    return BeMmioRead16 (Address);
> > > > > > > > > +  } else {
> > > > > > > > > +    return MmioRead16(Address);
> > > > > > > > > +  }
> > > > > > > >
> > > > > > > > This is actually a pretty good
> demonstration of
> > > the arguments
> > > > > > > > that were made with regards to how the
> BeIoLib
> > > could be just
> > > > > > > > another implementation of IoLib.
> > > > > > > >
> > > > > > > > You would then just do (in your .dsc):
> > > > > > >
> >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf
> > > {
> > > > > > > >     IoLib|<path to BeIoLib .inf>
> > > > > > > >   }
> > > > > > > >
> > > > > > > > This causes the big-endian version of the
> > > library to be used for
> > > > > > > > this component. This makes these
> Wdog<access>
> > > functions and the
> > > > > > > > Pcd redundant, and the rest of the code can
> use
> > > > > > > > MmioRead16()/MmioWrite16()
> > > > > > > > directly.
> > > > > > > >
> > > > > > > > But then, it is not really a big-endian or
> > > litte-endian version
> > > > > > > > of the library we need. We always know
> which
> > > endianness we are
> > > > > > > > building for.
> > > > > > > > What we need is a byteswapping flavour of
> > > IoLib.
> > > > > > > >
> > > > > > > > So Liming, what if we do something like
> adding
> > > a
> > > > > > > >
> > >
> MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > > > > p.inf
> > > > > > > > ---
> > > > > > > > [Defines]
> > > > > > > >   INF_VERSION                    =
> 0x0001001A
> > > > > > > >   BASE_NAME                      =
> > > > > > > > BaseIoLibIntrinsicSwap
> > > > > > > >   MODULE_UNI_FILE                =
> > > > > > > > BaseIoLibIntrinsic.uni
> > > > > > > >   FILE_GUID                      =
> d4a60d44-
> > > 3688-4a50-
> > > > > > > > b2d0-5c6fc2422523
> > > > > > > >   MODULE_TYPE                    = BASE
> > > > > > > >   VERSION_STRING                 = 1.0
> > > > > > > >   LIBRARY_CLASS                  = IoLib
> > > > > > > >
> > > > > > > >
> > > > > > > > #
> > > > > > > > #  VALID_ARCHITECTURES           = IA32 X64
> EBC
> > > IPF ARM
> > > > > > > > AARCH64
> > > > > > > > #
> > > > > > > >
> > > > > > > > [Sources]
> > > > > > > >   BaseIoLibIntrinsicInternal.h
> > > > > > > >   IoHighLevel.c
> > > > > > > >   IoLib.c
> > > > > > > >   IoLibEbc.c         # Asserts on all i/o
> port
> > > accesses
> > > > > > > >   IoLibMmioBuffer.c
> > > > > > > >
> > > > > > > > [Packages]
> > > > > > > >   MdePkg/MdePkg.dec
> > > > > > > >
> > > > > > > > [LibraryClasses]
> > > > > > > >   DebugLib
> > > > > > > >   BaseLib
> > > > > > > >
> > > > > > > > [BuildOptions]
> > > > > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > > > > ---
> > > > > > > >
> > > > > > > > And then add
> > > > > > > >
> > > > > > > > #ifdef SWAP_BYTES
> > > > > > > >   return SwapBytesXX (Value);
> > > > > > > > #else
> > > > > > > >   return Value;
> > > > > > > > #fi
> > > > > > > >
> > > > > > > > for the read operations and
> > > > > > > >
> > > > > > > > #ifdef SWAP_BYTES
> > > > > > > >   *(type)Address = SwapBytesXX (Value);
> #else
> > > > > > > >   *(type)Address = Value;
> > > > > > > > #fi
> > > > > > > >
> > > > > > > > for the write operations in IoLib.c?
> > > > > > > >
> > > > > > > > /
> > > > > > > >     Leif
> > > > > > > >
> > > > > > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000,
> > > Meenakshi Aggarwal
> > > > > > > > wrote:
> > > > > > > > > Hi Leif,
> > > > > > > > >
> > > > > > > > > This is regarding Big-Endian Library
> patch
> > > ([PATCH v2
> > > > > > > > 1/9]
> > > > > > > > > Platform/NXP: Add support for Big Endian
> Mmio
> > > APIs)
> > > > > > > > >
> > > > > > > > > We have started this discussion before
> and
> > > the
> > > > > > > > suggestion was to
> > > > > > > > > create a separate .inf file keeping APIs
> name
> > > same e.g.
> > > > > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > > > > >
> > > > > > > > > But we can't go with this approach
> (reason
> > > mentioned
> > > > > > > > by Udit).
> > > > > > > > >
> > > > > > > > > So please suggest if we should keep this
> > > library
> > > > > > > > under Platform/NXP
> > > > > > > > > or I send a new patch moving this library
> in
> > > MdePkg.
> > > > > > > > >
> > > > > > > > > But we have to keep a different name for
> Big
> > > Endian
> > > > > > > > MMIO APIs.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > > Meenakshi
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > > -----Original Message-----
> > > > > > > > > > From: Udit Kumar
> > > > > > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > > > > > To: Gao, Liming <liming.gao@intel.com>;
> > > Meenakshi
> > > > > > > > Aggarwal
> > > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > > Biesheuvel
> > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > > Michael D
> > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > > devel@lists.01.org
> > > > > > > > > > Subject: RE: [edk2] [PATCH 1/1]
> > > MdePkg/IoLib: Add
> > > > > > > > support for big-endian
> > > > > > > > > > MMIO
> > > > > > > > > >
> > > > > > > > > > Hi Meenakshi/Liming,
> > > > > > > > > > My 2 cents, around this.
> > > > > > > > > >
> > > > > > > > > > 1)
> > > > > > > > > > Having a new lib for BE read might not
> be
> > > helpful
> > > > > > > > for us, e.g. a IP which is in
> > > > > > > > > > BE mode access the UART for print or
> system
> > > > > > > > registers which are in LE, then
> > > > > > > > > > with new Lib, we will get all
> read/write in
> > > BE mode
> > > > > > > > > >
> > > > > > > > > > 2)
> > > > > > > > > > Especially for our IPs, which are
> changing
> > > from BE
> > > > > > > > to LE depending on
> > > > > > > > > > platform.
> > > > > > > > > > As said before, having BE read lib with
> API
> > > name of
> > > > > > > > MmioRead32 etc, will not
> > > > > > > > > > help (I guess Meenakshi already seen
> some
> > > problems
> > > > > > > > around this) Adding a
> > > > > > > > > > new lib with MmioRead32BE API name
> could
> > > help, but
> > > > > > > > IP driver we need to
> > > > > > > > > > take care of IP mode either by Pcd or
> > > #define, to
> > > > > > > > select MmioRead32 or
> > > > > > > > > > MmioRead32BE.
> > > > > > > > > > This conditional compile needs to be
> done
> > > for all
> > > > > > > > IPs (which works in BE/LE
> > > > > > > > > > mode on different platforms).
> > > > > > > > > >
> > > > > > > > > > My preferred way of implementation to
> use
> > > one
> > > > > > > > function in IP driver, And
> > > > > > > > > > based on IP mode, do the switch.
> > > > > > > > > >
> > > > > > > > > > New Lib could have function like below
> > > > > > > > > > MmioRead32Generic(IN  UINTN
> Address,
> > > BOOL
> > > > > > > > IsIPBE) {
> > > > > > > > > >    UINT32
> Value;
> > > > > > > > > >
> > > > > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > > > > >    Value = *(volatile UINT32*)Address;
> > > > > > > > > >    If(IsIPBE)
> > > > > > > > > >      Value = SwapBytes32(Value);
> return
> > > Value; }
> > > > > > > > > >
> > > > > > > > > > And IP driver can use it
> > > > > > > > > > MmioRead32Generic(ADDR,
> > > > > > > > > >
> FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > > > > >
> > > > > > > > > > Comments are welcome.
> > > > > > > > > >
> > > > > > > > > > Regards
> > > > > > > > > > Udit
> > > > > > > > > >
> > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > > > > Gao, Liming
> > > > > > > > > > > Sent: Monday, October 16, 2017 8:48
> AM
> > > > > > > > > > > To: Meenakshi Aggarwal
> > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> Biesheuvel
> > > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > > Michael D
> > > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > > devel@lists.01.org
> > > > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > > MdePkg/IoLib: Add
> > > > > > > > support for
> > > > > > > > > > > big-endian MMIO
> > > > > > > > > > >
> > > > > > > > > > > Meenakshi:
> > > > > > > > > > >   I suggest to introduce new IoLib
> > > library
> > > > > > > > instance, not to add new IoLib
> > > > > > > > > > APIs.
> > > > > > > > > > > New IoLib library instance will
> perform
> > > IO
> > > > > > > > operation as the big
> > > > > > > > > > > endian. You can update
> > > > > > > > MdePkg/Library/BaseIoLibIntrinsic instance,
> add
> > > > > > > > > > > new source file and new INF for it.
> > > > > > > > > > >
> > > > > > > > > > > UINT32
> > > > > > > > > > > EFIAPI
> > > > > > > > > > > MmioRead32 (
> > > > > > > > > > >   IN  UINTN     Address
> > > > > > > > > > >   )
> > > > > > > > > > > {
> > > > > > > > > > >   UINT32
> > > Value;
> > > > > > > > > > >
> > > > > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > > > > > >   return SwapBytes32(Value); }
> > > > > > > > > > >
> > > > > > > > > > > Thanks
> > > > > > > > > > > Liming
> > > > > > > > > > > >-----Original Message-----
> > > > > > > > > > > >From: Meenakshi Aggarwal
> > > > > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > > > > >Sent: Friday, October 13, 2017 2:07
> PM
> > > > > > > > > > > >To: Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>;
> > > > > > > > Kinney, Michael D
> > > > > > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > > > > ><liming.gao@intel.com>
> > > > > > > > > > > >Subject: RE: [edk2] [PATCH 1/1]
> > > MdePkg/IoLib:
> > > > > > > > Add support for
> > > > > > > > > > > >big-endian MMIO
> > > > > > > > > > > >
> > > > > > > > > > > >Hi All,
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >It’s a pretty old discussion, we
> have
> > > left the
> > > > > > > > upstreaming of NXP
> > > > > > > > > > > >package in between because of some
> other
> > > work,
> > > > > > > > but have started it
> > > > > > > > > > > >again
> > > > > > > > > > > now.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >Issue  : Few NXP modules support Big
> > > Endian
> > > > > > > > MMIOs as these are ported
> > > > > > > > > > > >from PowerPC.
> > > > > > > > > > > >
> > > > > > > > > > > >Solution suggested : Create a
> separate
> > > library
> > > > > > > > for BE MMIO APIs.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >So what I have done is, I have
> created a
> > > > > > > > separate library to support
> > > > > > > > > > > >BE MMIO APIs and currently keeping
> it to
> > > my
> > > > > > > > package.
> > > > > > > > > > > >This library is basically a wrapper
> over
> > > > > > > > existing MMIO APIs.
> > > > > > > > > > > >
> > > > > > > > > > > >UINT32
> > > > > > > > > > > >EFIAPI
> > > > > > > > > > > >BeMmioRead32 (
> > > > > > > > > > > >  IN  UINTN     Address
> > > > > > > > > > > >  )
> > > > > > > > > > > >{
> > > > > > > > > > > >  UINT32  Value;
> > > > > > > > > > > >
> > > > > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > > > > >
> > > > > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >Need your opinion on below optinos:
> > > > > > > > > > > >
> > > > > > > > > > > >1. Will this be a good idea to make
> this
> > > library
> > > > > > > > a part of MdePkg? OR
> > > > > > > > > > > >
> > > > > > > > > > > >2. Add a new file e.g. IoBeMmio.c
> like
> > > > > > > > IoHighLevel.c in
> > > > > > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > > > > And made these APIs a part of IoLib
> > > itself. OR
> > > > > > > > > > > >
> > > > > > > > > > > >3. Keep this library internal to NXP
> > > package.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >Please provide your inputs.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >Thanks & Regards,
> > > > > > > > > > > >Meenakshi
> > > > > > > > > > > >
> > > > > > > > > > > >> -----Original Message-----
> > > > > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > > > > >> Sent: Monday, October 17, 2016
> 3:28 PM
> > > > > > > > > > > >> To: Ard Biesheuvel
> > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> Michael D
> > > > > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > > > > >> Cc: Gao, Liming
> > > <liming.gao@intel.com>; edk2-
> > > > > > > > devel@ml01.01.org;
> > > > > > > > > > > >> Meenakshi Aggarwal
> > > > > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > > > > >> Subject: RE: [edk2] [PATCH 1/1]
> > > MdePkg/IoLib:
> > > > > > > > Add support for
> > > > > > > > > > > >> big-endian MMIO
> > > > > > > > > > > >>
> > > > > > > > > > > >> Hi Ard,
> > > > > > > > > > > >>
> > > > > > > > > > > >> > -----Original Message-----
> > > > > > > > > > > >> > From: Ard Biesheuvel
> > > > > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > > > > >> > Sent: Monday, October 17, 2016
> 1:12
> > > PM
> > > > > > > > > > > >> > To: Kinney, Michael D
> > > > > > > > <michael.d.kinney@intel.com>
> > > > > > > > > > > >> > Cc: Gao, Liming
> > > <liming.gao@intel.com>;
> > > > > > > > Bhupesh Sharma
> > > > > > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > > > > > devel@ml01.01.org
> > > > > > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > > > > > MdePkg/IoLib: Add support for
> > > > > > > > > > > >> > big- endian MMIO
> > > > > > > > > > > >> >
> > > > > > > > > > > >> > On 17 October 2016 at 05:10,
> Kinney,
> > > Michael
> > > > > > > > D
> > > > > > > > > > > >> > <michael.d.kinney@intel.com>
> wrote:
> > > > > > > > > > > >> > > Bhupesh,
> > > > > > > > > > > >> > >
> > > > > > > > > > > >> > > It is also possible to add an
> ARM
> > > specific
> > > > > > > > PCD to select
> > > > > > > > > > > >> > > endianness and update
> > > > > > > > > > > >> > >
> > > > > > > >
> MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to
> > > use that PCD in
> > > > > > > > > > > >> > > MmioRead/Write() APIs in that
> file
> > > to
> > > > > > > > support both endian types.
> > > > > > > > > > > >> > > You can use the SwapBytesxx()
> > > functions
> > > > > > > > from BaseLib(as
> > > > > > > > > > > >> > Laszlo
> > > > > > > > > > > >> > > suggested) based on the
> setting of
> > > this
> > > > > > > > ARM specific PCD.
> > > > > > > > > > > >> > >
> > > > > > > > > > > >> > > Modules that link against this
> lib
> > > can
> > > > > > > > select endianness by
> > > > > > > > > > > >> > > setting PCD in the scope of
> that
> > > module.
> > > > > > > > > > > >> > >
> > > > > > > > > > > >> > > The IPF version of IoLib uses
> an
> > > IPF
> > > > > > > > specific PCD to translate
> > > > > > > > > > > >> > > I/O port accesses to MMIO
> > > accesses.  So
> > > > > > > > there is already an
> > > > > > > > > > > >> > > example of an arch specific
> PCD in
> > > this
> > > > > > > > lib instance.
> > > > > > > > > > > >> > >
> > > > > > > > > > > >> >
> > > > > > > > > > > >> > This is not a platform wide
> thing,
> > > it is a
> > > > > > > > per-device property
> > > > > > > > > > > >> > whether the MMIO occurs in big
> > > endian or
> > > > > > > > little endian manner.
> > > > > > > > > > > >> >
> > > > > > > > > > > >> > So I think Liming's suggestion
> makes
> > > sense:
> > > > > > > > create an IoLib
> > > > > > > > > > > >> > implementation that performs the
> > > byte
> > > > > > > > swapping, and selectively
> > > > > > > > > > > >> > incorporate it into drivers that
> > > require it
> > > > > > > > using
> > > > > > > > > > > >> >
> > > > > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > > > > >> >   <LibraryClasses>
> > > > > > > > > > > >> >
> > > IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > > > > >> > }
> > > > > > > > > > > >>
> > > > > > > > > > > >> That's correct. I think creating a
> > > separate
> > > > > > > > IoLib for byte-swapping
> > > > > > > > > > > >> makes sense.
> > > > > > > > > > > >>
> > > > > > > > > > > >> We will rework the patch
> accordingly.
> > > > > > > > > > > >>
> > > > > > > > > > > >> Regards,
> > > > > > > > > > > >> Bhupesh
> > > > > > > > > > >
> > > _______________________________________________
> > > > > > > > > > > edk2-devel mailing list
> > > > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > > > >
> > > > > >
> > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> > > s%3A%2F%2Fl
> > > > > > ist
> > > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > >
> > > >
> > >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > > 3cbb51
> > > > > >
> > > >
> > >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > > 7C0%7C0
> > > > > >
> > >
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > > dEQ
> > > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > > >
> _______________________________________________
> > > > > > > > edk2-devel mailing list
> > > > > > > > edk2-devel@lists.01.org
> > > > > > > >
> > > > > >
> > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> > > s%3A%2F%2Fl
> > > > > > ist
> > > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > >
> > > >
> > >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > > 3cbb51
> > > > > >
> > > >
> > >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > > 7C0%7C0
> > > > > >
> > >
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > > dEQ
> > > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > _______________________________________________
> > > > edk2-devel mailing list
> > > > edk2-devel@lists.01.org
> > > >
> > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> > > s%3A%2F%2Flists.01
> > > > .org%2Fmailman%2Flistinfo%2Fedk2-
> > > >
> > >
> devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a064
> > > 8fa8e440
> > > >
> > >
> 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> > > 6364772
> > > >
> > >
> 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alH
> > > Y4ptAX
> > > > MU%3D&reserved=0

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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-04 15:31                                 ` Kinney, Michael D
@ 2017-12-04 15:54                                   ` Leif Lindholm
  2017-12-04 16:19                                     ` Kinney, Michael D
  0 siblings, 1 reply; 25+ messages in thread
From: Leif Lindholm @ 2017-12-04 15:54 UTC (permalink / raw)
  To: Kinney, Michael D
  Cc: Udit Kumar, Meenakshi Aggarwal, Varun Sethi,
	edk2-devel@lists.01.org, Gao, Liming, Ard Biesheuvel

Hi Mike,

This separate library would only be necessary specifically because
an additional library to the default platform IoLib was needed.
So while it's another dependency, it would likely reduce image size.

Which is why I was leaning towards a wrapper.

This also means the actual hw-dependent bit gets abstracted away from
the portable and predictable byteswapping. Which always makes me
slightly more comfortable.

If you're OK with the concept, I can throw an RFC together.

Best Regards,

Leif

On Mon, Dec 04, 2017 at 03:31:10PM +0000, Kinney, Michael D wrote:
> Leif,
> 
> I may make more sense to add to MdePkg as a peer to IoLib.
> This minimizes the package dependencies for Si modules.
> 
> I am ok as a wrapper on top of IoLib.  Whatever reduces 
> code duplication and reduces maintenance.
> 
> Best regards,
> 
> Mike
> 
> > -----Original Message-----
> > From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> > Sent: Monday, December 4, 2017 4:36 AM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > Cc: Udit Kumar <udit.kumar@nxp.com>; Meenakshi Aggarwal
> > <meenakshi.aggarwal@nxp.com>; Varun Sethi
> > <V.Sethi@nxp.com>; edk2-devel@lists.01.org; Gao, Liming
> > <liming.gao@intel.com>; Ard Biesheuvel
> > <ard.biesheuvel@linaro.org>
> > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support
> > for big-endian MMIO
> > 
> > Mike,
> > 
> > In that case - do you think it should be added to
> > MdeModulePkg?
> > 
> > Should it be implemented simply as a wrapper on IoLib
> > (depending on
> > it)?
> > 
> > /
> >     Leif
> > 
> > On Fri, Dec 01, 2017 at 10:41:26PM +0000, Kinney, Michael
> > D wrote:
> > > Udit,
> > >
> > > I agree with your concern.
> > >
> > > I am in favor of adding new APIs that perform the
> > > byte swap operations.
> > >
> > > Mike
> > >
> > > > -----Original Message-----
> > > > From: Udit Kumar [mailto:udit.kumar@nxp.com]
> > > > Sent: Friday, December 1, 2017 9:58 AM
> > > > To: Leif Lindholm <leif.lindholm@linaro.org>;
> > Meenakshi
> > > > Aggarwal <meenakshi.aggarwal@nxp.com>; Varun Sethi
> > > > <V.Sethi@nxp.com>
> > > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > edk2-
> > > > devel@lists.01.org; Gao, Liming
> > <liming.gao@intel.com>;
> > > > Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > support
> > > > for big-endian MMIO
> > > >
> > > > Thanks Leif,
> > > >
> > > > > It may require a little bit more of up-front work,
> > but
> > > > the end result will be a
> > > > > platform port that works with the intended edk2
> > design
> > > > principles rather than
> > > >
> > > > Yes, this will be re-design/code for us, breaking all
> > > > software pieces into
> > > > smaller blocks and exposing protocol from the same.
> > > > This could be managed.
> > > >
> > > > But how do you see,  if there is such dependency oN
> > lib.
> > > > Say a driver which is in BE mode, and is using
> > DebugLib
> > > > (BaseDebugLibSerialPort)
> > > > And DebugLib uses SerialPortLib, which is in LE mode
> > > >
> > > > Thanks
> > > > Udit
> > > >
> > > > > -----Original Message-----
> > > > > From: edk2-devel [mailto:edk2-devel-
> > > > bounces@lists.01.org] On Behalf Of Leif
> > > > > Lindholm
> > > > > Sent: Friday, December 01, 2017 4:28 PM
> > > > > To: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
> > > > > Cc: Kinney, Michael D <michael.d.kinney@intel.com>;
> > > > edk2-devel@lists.01.org;
> > > > > Gao, Liming <liming.gao@intel.com>; Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>
> > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > > support for big-endian
> > > > > MMIO
> > > > >
> > > > > On Thu, Nov 30, 2017 at 04:15:38AM +0000, Meenakshi
> > > > Aggarwal wrote:
> > > > > > Hi Leif, Mike,
> > > > > >
> > > > > >
> > > > > > NXP boards, at present, have few controllers with
> > big
> > > > endian and other
> > > > > > with little endian memory access.
> > > > >
> > > > > Sure, this is not a problem.
> > > > >
> > > > > > Maximum controllers depend on SocLib library for
> > > > clock information and
> > > > > > endianness for SocLib and controllers is
> > different.
> > > > >
> > > > > OK, I see in SocLib you have something called a Gur
> > > > that is read once (and again
> > > > > does a special per-device Pcd dance for runtime
> > > > selection between
> > > > > byteswapping Mmio and plain Mmio).
> > > > >
> > > > > > So this option will not work for us,
> > > > > >   You would then just do (in your .dsc):
> > > > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > > > >       IoLib|<path to BeIoLib .inf>
> > > > > >   }
> > > > > >
> > > > > > Because all libraries included by WatchDog will
> > then
> > > > access BE mode Mmio
> > > > > APIs.
> > > > >
> > > > > Which libraries performing Mmio accesses are you
> > > > intending to include in your
> > > > > watchdog driver? You have submitted none as part of
> > > > this series.
> > > > >
> > > > > > And breaking code into separate modules with
> > > > different access will be
> > > > > > very difficult.
> > > > >
> > > > > It may require a little bit more of up-front work,
> > but
> > > > the end result will be a
> > > > > platform port that works with the intended edk2
> > design
> > > > principles rather than
> > > > > against them. And that will reduce the overall
> > effort
> > > > (not to mention code
> > > > > duplication).
> > > > >
> > > > > From the patches you have sent, the only required
> > > > change I see (if a
> > > > > byteswapping IoLib was added to edk2) would be to
> > > > create a tiny driver for this
> > > > > "Gur" device that installs a protocol containing a
> > > > single function for reading
> > > > > from that device's register space. That driver can
> > be
> > > > built against the swapping
> > > > > or non-swapping IoLib as appropriate.
> > > > >
> > > > > > Watchdog is not the only module which need BE
> > Mmio
> > > > APIs, we have MMC
> > > > > > and other controllers also with same requirement.
> > > > >
> > > > > And the same solutions are possible everywhere.
> > > > >
> > > > > Best Regards,
> > > > >
> > > > > Leif
> > > > >
> > > > > > We need BE Mmio APIs with a different name.
> > > > > >
> > > > > > Please see the possibility.
> > > > > >
> > > > > > Thanks & Regards,
> > > > > > Meenakshi
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Leif Lindholm
> > > > [mailto:leif.lindholm@linaro.org]
> > > > > > > Sent: Thursday, November 30, 2017 1:19 AM
> > > > > > > To: Kinney, Michael D
> > <michael.d.kinney@intel.com>
> > > > > > > Cc: Meenakshi Aggarwal
> > > > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > <liming.gao@intel.com>; edk2-
> > devel@lists.01.org;
> > > > Ard Biesheuvel
> > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib:
> > Add
> > > > support for
> > > > > > > big-endian MMIO
> > > > > > >
> > > > > > > I guess there is no strict rule about a driver
> > only
> > > > directly
> > > > > > > accessing one piece of HW?
> > > > > > >
> > > > > > > Still, that would be one possible solution:
> > > > breaking accesses to a
> > > > > > > separate HW in need of byteswapping out into
> > its
> > > > own module and
> > > > > > > letting it override IoLib version there.
> > > > > > >
> > > > > > > Regards,
> > > > > > >
> > > > > > > Leif
> > > > > > >
> > > > > > > On Wed, Nov 29, 2017 at 07:25:05PM +0000,
> > Kinney,
> > > > Michael D wrote:
> > > > > > > > Leif,
> > > > > > > >
> > > > > > > > I agree that this should be described as byte
> > > > swapping.
> > > > > > > >
> > > > > > > > What about a module that needs to access HW
> > with
> > > > and without the
> > > > > > > > bytes swapped?  It gets more complex if a
> > module
> > > > is linked against
> > > > > > > > several libs and some libs access HW with
> > bytes
> > > > swapped and some
> > > > > > > > do not.
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > >
> > > > > > > > Mike
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > bounces@lists.01.org] On
> > > > > > > > > Behalf Of Leif Lindholm
> > > > > > > > > Sent: Wednesday, November 29, 2017 4:51 AM
> > > > > > > > > To: Meenakshi Aggarwal
> > > > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > > > <liming.gao@intel.com>
> > > > > > > > > Cc: Kinney, Michael D
> > > > <michael.d.kinney@intel.com>;
> > > > > > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > MdePkg/IoLib:
> > > > Add support for
> > > > > > > > > big-endian MMIO
> > > > > > > > >
> > > > > > > > > Hi Meenakshi,
> > > > > > > > >
> > > > > > > > > I finally got around to looking at the
> > watchdog
> > > > code (that uses
> > > > > > > > > this library), and that has convinced me
> > the
> > > > best solution is to
> > > > > > > > > do what Liming proposed.
> > > > > > > > >
> > > > > > > > > Looking at this snippet:
> > > > > > > > >
> > > > > > > > > > +STATIC
> > > > > > > > > > +UINT16
> > > > > > > > > > +EFIAPI
> > > > > > > > > > +WdogRead (
> > > > > > > > > > +  IN  UINTN     Address
> > > > > > > > > > +  )
> > > > > > > > > > +{
> > > > > > > > > > +  if (FixedPcdGetBool
> > (PcdWdogBigEndian)) {
> > > > > > > > > > +    return BeMmioRead16 (Address);
> > > > > > > > > > +  } else {
> > > > > > > > > > +    return MmioRead16(Address);
> > > > > > > > > > +  }
> > > > > > > > >
> > > > > > > > > This is actually a pretty good
> > demonstration of
> > > > the arguments
> > > > > > > > > that were made with regards to how the
> > BeIoLib
> > > > could be just
> > > > > > > > > another implementation of IoLib.
> > > > > > > > >
> > > > > > > > > You would then just do (in your .dsc):
> > > > > > > >
> > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf
> > > > {
> > > > > > > > >     IoLib|<path to BeIoLib .inf>
> > > > > > > > >   }
> > > > > > > > >
> > > > > > > > > This causes the big-endian version of the
> > > > library to be used for
> > > > > > > > > this component. This makes these
> > Wdog<access>
> > > > functions and the
> > > > > > > > > Pcd redundant, and the rest of the code can
> > use
> > > > > > > > > MmioRead16()/MmioWrite16()
> > > > > > > > > directly.
> > > > > > > > >
> > > > > > > > > But then, it is not really a big-endian or
> > > > litte-endian version
> > > > > > > > > of the library we need. We always know
> > which
> > > > endianness we are
> > > > > > > > > building for.
> > > > > > > > > What we need is a byteswapping flavour of
> > > > IoLib.
> > > > > > > > >
> > > > > > > > > So Liming, what if we do something like
> > adding
> > > > a
> > > > > > > > >
> > > >
> > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > > > > > p.inf
> > > > > > > > > ---
> > > > > > > > > [Defines]
> > > > > > > > >   INF_VERSION                    =
> > 0x0001001A
> > > > > > > > >   BASE_NAME                      =
> > > > > > > > > BaseIoLibIntrinsicSwap
> > > > > > > > >   MODULE_UNI_FILE                =
> > > > > > > > > BaseIoLibIntrinsic.uni
> > > > > > > > >   FILE_GUID                      =
> > d4a60d44-
> > > > 3688-4a50-
> > > > > > > > > b2d0-5c6fc2422523
> > > > > > > > >   MODULE_TYPE                    = BASE
> > > > > > > > >   VERSION_STRING                 = 1.0
> > > > > > > > >   LIBRARY_CLASS                  = IoLib
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > #
> > > > > > > > > #  VALID_ARCHITECTURES           = IA32 X64
> > EBC
> > > > IPF ARM
> > > > > > > > > AARCH64
> > > > > > > > > #
> > > > > > > > >
> > > > > > > > > [Sources]
> > > > > > > > >   BaseIoLibIntrinsicInternal.h
> > > > > > > > >   IoHighLevel.c
> > > > > > > > >   IoLib.c
> > > > > > > > >   IoLibEbc.c         # Asserts on all i/o
> > port
> > > > accesses
> > > > > > > > >   IoLibMmioBuffer.c
> > > > > > > > >
> > > > > > > > > [Packages]
> > > > > > > > >   MdePkg/MdePkg.dec
> > > > > > > > >
> > > > > > > > > [LibraryClasses]
> > > > > > > > >   DebugLib
> > > > > > > > >   BaseLib
> > > > > > > > >
> > > > > > > > > [BuildOptions]
> > > > > > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > > > > > ---
> > > > > > > > >
> > > > > > > > > And then add
> > > > > > > > >
> > > > > > > > > #ifdef SWAP_BYTES
> > > > > > > > >   return SwapBytesXX (Value);
> > > > > > > > > #else
> > > > > > > > >   return Value;
> > > > > > > > > #fi
> > > > > > > > >
> > > > > > > > > for the read operations and
> > > > > > > > >
> > > > > > > > > #ifdef SWAP_BYTES
> > > > > > > > >   *(type)Address = SwapBytesXX (Value);
> > #else
> > > > > > > > >   *(type)Address = Value;
> > > > > > > > > #fi
> > > > > > > > >
> > > > > > > > > for the write operations in IoLib.c?
> > > > > > > > >
> > > > > > > > > /
> > > > > > > > >     Leif
> > > > > > > > >
> > > > > > > > > On Mon, Nov 27, 2017 at 06:06:33AM +0000,
> > > > Meenakshi Aggarwal
> > > > > > > > > wrote:
> > > > > > > > > > Hi Leif,
> > > > > > > > > >
> > > > > > > > > > This is regarding Big-Endian Library
> > patch
> > > > ([PATCH v2
> > > > > > > > > 1/9]
> > > > > > > > > > Platform/NXP: Add support for Big Endian
> > Mmio
> > > > APIs)
> > > > > > > > > >
> > > > > > > > > > We have started this discussion before
> > and
> > > > the
> > > > > > > > > suggestion was to
> > > > > > > > > > create a separate .inf file keeping APIs
> > name
> > > > same e.g.
> > > > > > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > > > > > >
> > > > > > > > > > But we can't go with this approach
> > (reason
> > > > mentioned
> > > > > > > > > by Udit).
> > > > > > > > > >
> > > > > > > > > > So please suggest if we should keep this
> > > > library
> > > > > > > > > under Platform/NXP
> > > > > > > > > > or I send a new patch moving this library
> > in
> > > > MdePkg.
> > > > > > > > > >
> > > > > > > > > > But we have to keep a different name for
> > Big
> > > > Endian
> > > > > > > > > MMIO APIs.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > > Meenakshi
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > From: Udit Kumar
> > > > > > > > > > > Sent: Monday, October 23, 2017 12:38 PM
> > > > > > > > > > > To: Gao, Liming <liming.gao@intel.com>;
> > > > Meenakshi
> > > > > > > > > Aggarwal
> > > > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > > > Biesheuvel
> > > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > > > Michael D
> > > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > > > devel@lists.01.org
> > > > > > > > > > > Subject: RE: [edk2] [PATCH 1/1]
> > > > MdePkg/IoLib: Add
> > > > > > > > > support for big-endian
> > > > > > > > > > > MMIO
> > > > > > > > > > >
> > > > > > > > > > > Hi Meenakshi/Liming,
> > > > > > > > > > > My 2 cents, around this.
> > > > > > > > > > >
> > > > > > > > > > > 1)
> > > > > > > > > > > Having a new lib for BE read might not
> > be
> > > > helpful
> > > > > > > > > for us, e.g. a IP which is in
> > > > > > > > > > > BE mode access the UART for print or
> > system
> > > > > > > > > registers which are in LE, then
> > > > > > > > > > > with new Lib, we will get all
> > read/write in
> > > > BE mode
> > > > > > > > > > >
> > > > > > > > > > > 2)
> > > > > > > > > > > Especially for our IPs, which are
> > changing
> > > > from BE
> > > > > > > > > to LE depending on
> > > > > > > > > > > platform.
> > > > > > > > > > > As said before, having BE read lib with
> > API
> > > > name of
> > > > > > > > > MmioRead32 etc, will not
> > > > > > > > > > > help (I guess Meenakshi already seen
> > some
> > > > problems
> > > > > > > > > around this) Adding a
> > > > > > > > > > > new lib with MmioRead32BE API name
> > could
> > > > help, but
> > > > > > > > > IP driver we need to
> > > > > > > > > > > take care of IP mode either by Pcd or
> > > > #define, to
> > > > > > > > > select MmioRead32 or
> > > > > > > > > > > MmioRead32BE.
> > > > > > > > > > > This conditional compile needs to be
> > done
> > > > for all
> > > > > > > > > IPs (which works in BE/LE
> > > > > > > > > > > mode on different platforms).
> > > > > > > > > > >
> > > > > > > > > > > My preferred way of implementation to
> > use
> > > > one
> > > > > > > > > function in IP driver, And
> > > > > > > > > > > based on IP mode, do the switch.
> > > > > > > > > > >
> > > > > > > > > > > New Lib could have function like below
> > > > > > > > > > > MmioRead32Generic(IN  UINTN
> > Address,
> > > > BOOL
> > > > > > > > > IsIPBE) {
> > > > > > > > > > >    UINT32
> > Value;
> > > > > > > > > > >
> > > > > > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > > > > > >    Value = *(volatile UINT32*)Address;
> > > > > > > > > > >    If(IsIPBE)
> > > > > > > > > > >      Value = SwapBytes32(Value);
> > return
> > > > Value; }
> > > > > > > > > > >
> > > > > > > > > > > And IP driver can use it
> > > > > > > > > > > MmioRead32Generic(ADDR,
> > > > > > > > > > >
> > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > > > > > >
> > > > > > > > > > > Comments are welcome.
> > > > > > > > > > >
> > > > > > > > > > > Regards
> > > > > > > > > > > Udit
> > > > > > > > > > >
> > > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > > > > > Gao, Liming
> > > > > > > > > > > > Sent: Monday, October 16, 2017 8:48
> > AM
> > > > > > > > > > > > To: Meenakshi Aggarwal
> > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > Biesheuvel
> > > > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > > > Michael D
> > > > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > > > devel@lists.01.org
> > > > > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > > > MdePkg/IoLib: Add
> > > > > > > > > support for
> > > > > > > > > > > > big-endian MMIO
> > > > > > > > > > > >
> > > > > > > > > > > > Meenakshi:
> > > > > > > > > > > >   I suggest to introduce new IoLib
> > > > library
> > > > > > > > > instance, not to add new IoLib
> > > > > > > > > > > APIs.
> > > > > > > > > > > > New IoLib library instance will
> > perform
> > > > IO
> > > > > > > > > operation as the big
> > > > > > > > > > > > endian. You can update
> > > > > > > > > MdePkg/Library/BaseIoLibIntrinsic instance,
> > add
> > > > > > > > > > > > new source file and new INF for it.
> > > > > > > > > > > >
> > > > > > > > > > > > UINT32
> > > > > > > > > > > > EFIAPI
> > > > > > > > > > > > MmioRead32 (
> > > > > > > > > > > >   IN  UINTN     Address
> > > > > > > > > > > >   )
> > > > > > > > > > > > {
> > > > > > > > > > > >   UINT32
> > > > Value;
> > > > > > > > > > > >
> > > > > > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > > > > > >   Value = *(volatile UINT32*)Address;
> > > > > > > > > > > >   return SwapBytes32(Value); }
> > > > > > > > > > > >
> > > > > > > > > > > > Thanks
> > > > > > > > > > > > Liming
> > > > > > > > > > > > >-----Original Message-----
> > > > > > > > > > > > >From: Meenakshi Aggarwal
> > > > > > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > > > > > >Sent: Friday, October 13, 2017 2:07
> > PM
> > > > > > > > > > > > >To: Ard Biesheuvel
> > > > <ard.biesheuvel@linaro.org>;
> > > > > > > > > Kinney, Michael D
> > > > > > > > > > > > ><michael.d.kinney@intel.com>; edk2-
> > > > > > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > > > > > ><liming.gao@intel.com>
> > > > > > > > > > > > >Subject: RE: [edk2] [PATCH 1/1]
> > > > MdePkg/IoLib:
> > > > > > > > > Add support for
> > > > > > > > > > > > >big-endian MMIO
> > > > > > > > > > > > >
> > > > > > > > > > > > >Hi All,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >It’s a pretty old discussion, we
> > have
> > > > left the
> > > > > > > > > upstreaming of NXP
> > > > > > > > > > > > >package in between because of some
> > other
> > > > work,
> > > > > > > > > but have started it
> > > > > > > > > > > > >again
> > > > > > > > > > > > now.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >Issue  : Few NXP modules support Big
> > > > Endian
> > > > > > > > > MMIOs as these are ported
> > > > > > > > > > > > >from PowerPC.
> > > > > > > > > > > > >
> > > > > > > > > > > > >Solution suggested : Create a
> > separate
> > > > library
> > > > > > > > > for BE MMIO APIs.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >So what I have done is, I have
> > created a
> > > > > > > > > separate library to support
> > > > > > > > > > > > >BE MMIO APIs and currently keeping
> > it to
> > > > my
> > > > > > > > > package.
> > > > > > > > > > > > >This library is basically a wrapper
> > over
> > > > > > > > > existing MMIO APIs.
> > > > > > > > > > > > >
> > > > > > > > > > > > >UINT32
> > > > > > > > > > > > >EFIAPI
> > > > > > > > > > > > >BeMmioRead32 (
> > > > > > > > > > > > >  IN  UINTN     Address
> > > > > > > > > > > > >  )
> > > > > > > > > > > > >{
> > > > > > > > > > > > >  UINT32  Value;
> > > > > > > > > > > > >
> > > > > > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > > > > > >
> > > > > > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >Need your opinion on below optinos:
> > > > > > > > > > > > >
> > > > > > > > > > > > >1. Will this be a good idea to make
> > this
> > > > library
> > > > > > > > > a part of MdePkg? OR
> > > > > > > > > > > > >
> > > > > > > > > > > > >2. Add a new file e.g. IoBeMmio.c
> > like
> > > > > > > > > IoHighLevel.c in
> > > > > > > > > > > > >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > > > > > And made these APIs a part of IoLib
> > > > itself. OR
> > > > > > > > > > > > >
> > > > > > > > > > > > >3. Keep this library internal to NXP
> > > > package.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >Please provide your inputs.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >Thanks & Regards,
> > > > > > > > > > > > >Meenakshi
> > > > > > > > > > > > >
> > > > > > > > > > > > >> -----Original Message-----
> > > > > > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > > > > > >> Sent: Monday, October 17, 2016
> > 3:28 PM
> > > > > > > > > > > > >> To: Ard Biesheuvel
> > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > Michael D
> > > > > > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > > > > > >> Cc: Gao, Liming
> > > > <liming.gao@intel.com>; edk2-
> > > > > > > > > devel@ml01.01.org;
> > > > > > > > > > > > >> Meenakshi Aggarwal
> > > > > > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > > > > > >> Subject: RE: [edk2] [PATCH 1/1]
> > > > MdePkg/IoLib:
> > > > > > > > > Add support for
> > > > > > > > > > > > >> big-endian MMIO
> > > > > > > > > > > > >>
> > > > > > > > > > > > >> Hi Ard,
> > > > > > > > > > > > >>
> > > > > > > > > > > > >> > -----Original Message-----
> > > > > > > > > > > > >> > From: Ard Biesheuvel
> > > > > > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > > > > > >> > Sent: Monday, October 17, 2016
> > 1:12
> > > > PM
> > > > > > > > > > > > >> > To: Kinney, Michael D
> > > > > > > > > <michael.d.kinney@intel.com>
> > > > > > > > > > > > >> > Cc: Gao, Liming
> > > > <liming.gao@intel.com>;
> > > > > > > > > Bhupesh Sharma
> > > > > > > > > > > > >> > <bhupesh.sharma@nxp.com>; edk2-
> > > > > > > > > devel@ml01.01.org
> > > > > > > > > > > > >> > Subject: Re: [edk2] [PATCH 1/1]
> > > > > > > > > MdePkg/IoLib: Add support for
> > > > > > > > > > > > >> > big- endian MMIO
> > > > > > > > > > > > >> >
> > > > > > > > > > > > >> > On 17 October 2016 at 05:10,
> > Kinney,
> > > > Michael
> > > > > > > > > D
> > > > > > > > > > > > >> > <michael.d.kinney@intel.com>
> > wrote:
> > > > > > > > > > > > >> > > Bhupesh,
> > > > > > > > > > > > >> > >
> > > > > > > > > > > > >> > > It is also possible to add an
> > ARM
> > > > specific
> > > > > > > > > PCD to select
> > > > > > > > > > > > >> > > endianness and update
> > > > > > > > > > > > >> > >
> > > > > > > > >
> > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to
> > > > use that PCD in
> > > > > > > > > > > > >> > > MmioRead/Write() APIs in that
> > file
> > > > to
> > > > > > > > > support both endian types.
> > > > > > > > > > > > >> > > You can use the SwapBytesxx()
> > > > functions
> > > > > > > > > from BaseLib(as
> > > > > > > > > > > > >> > Laszlo
> > > > > > > > > > > > >> > > suggested) based on the
> > setting of
> > > > this
> > > > > > > > > ARM specific PCD.
> > > > > > > > > > > > >> > >
> > > > > > > > > > > > >> > > Modules that link against this
> > lib
> > > > can
> > > > > > > > > select endianness by
> > > > > > > > > > > > >> > > setting PCD in the scope of
> > that
> > > > module.
> > > > > > > > > > > > >> > >
> > > > > > > > > > > > >> > > The IPF version of IoLib uses
> > an
> > > > IPF
> > > > > > > > > specific PCD to translate
> > > > > > > > > > > > >> > > I/O port accesses to MMIO
> > > > accesses.  So
> > > > > > > > > there is already an
> > > > > > > > > > > > >> > > example of an arch specific
> > PCD in
> > > > this
> > > > > > > > > lib instance.
> > > > > > > > > > > > >> > >
> > > > > > > > > > > > >> >
> > > > > > > > > > > > >> > This is not a platform wide
> > thing,
> > > > it is a
> > > > > > > > > per-device property
> > > > > > > > > > > > >> > whether the MMIO occurs in big
> > > > endian or
> > > > > > > > > little endian manner.
> > > > > > > > > > > > >> >
> > > > > > > > > > > > >> > So I think Liming's suggestion
> > makes
> > > > sense:
> > > > > > > > > create an IoLib
> > > > > > > > > > > > >> > implementation that performs the
> > > > byte
> > > > > > > > > swapping, and selectively
> > > > > > > > > > > > >> > incorporate it into drivers that
> > > > require it
> > > > > > > > > using
> > > > > > > > > > > > >> >
> > > > > > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > > > > > >> >   <LibraryClasses>
> > > > > > > > > > > > >> >
> > > > IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > > > > > >> > }
> > > > > > > > > > > > >>
> > > > > > > > > > > > >> That's correct. I think creating a
> > > > separate
> > > > > > > > > IoLib for byte-swapping
> > > > > > > > > > > > >> makes sense.
> > > > > > > > > > > > >>
> > > > > > > > > > > > >> We will rework the patch
> > accordingly.
> > > > > > > > > > > > >>
> > > > > > > > > > > > >> Regards,
> > > > > > > > > > > > >> Bhupesh
> > > > > > > > > > > >
> > > > _______________________________________________
> > > > > > > > > > > > edk2-devel mailing list
> > > > > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > > > > >
> > > > > > >
> > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > > > s%3A%2F%2Fl
> > > > > > > ist
> > > > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > > >
> > > > >
> > > >
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > > > 3cbb51
> > > > > > >
> > > > >
> > > >
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > > > 7C0%7C0
> > > > > > >
> > > >
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > > > dEQ
> > > > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > > > >
> > _______________________________________________
> > > > > > > > > edk2-devel mailing list
> > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > >
> > > > > > >
> > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > > > s%3A%2F%2Fl
> > > > > > > ist
> > > > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > > >
> > > > >
> > > >
> > devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > > > 3cbb51
> > > > > > >
> > > > >
> > > >
> > a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > > > 7C0%7C0
> > > > > > >
> > > >
> > %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > > > dEQ
> > > > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > _______________________________________________
> > > > > edk2-devel mailing list
> > > > > edk2-devel@lists.01.org
> > > > >
> > > >
> > https://emea01.safelinks.protection.outlook.com/?url=http
> > > > s%3A%2F%2Flists.01
> > > > > .org%2Fmailman%2Flistinfo%2Fedk2-
> > > > >
> > > >
> > devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a064
> > > > 8fa8e440
> > > > >
> > > >
> > 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> > > > 6364772
> > > > >
> > > >
> > 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alH
> > > > Y4ptAX
> > > > > MU%3D&reserved=0


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

* Re: [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO
  2017-12-04 15:54                                   ` Leif Lindholm
@ 2017-12-04 16:19                                     ` Kinney, Michael D
  0 siblings, 0 replies; 25+ messages in thread
From: Kinney, Michael D @ 2017-12-04 16:19 UTC (permalink / raw)
  To: Leif Lindholm, Kinney, Michael D
  Cc: Udit Kumar, Meenakshi Aggarwal, Varun Sethi,
	edk2-devel@lists.01.org, Gao, Liming, Ard Biesheuvel

Sounds good.

Mike

> -----Original Message-----
> From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> Sent: Monday, December 4, 2017 7:54 AM
> To: Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Udit Kumar <udit.kumar@nxp.com>; Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>; Varun Sethi
> <V.Sethi@nxp.com>; edk2-devel@lists.01.org; Gao, Liming
> <liming.gao@intel.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add support
> for big-endian MMIO
> 
> Hi Mike,
> 
> This separate library would only be necessary
> specifically because
> an additional library to the default platform IoLib was
> needed.
> So while it's another dependency, it would likely reduce
> image size.
> 
> Which is why I was leaning towards a wrapper.
> 
> This also means the actual hw-dependent bit gets
> abstracted away from
> the portable and predictable byteswapping. Which always
> makes me
> slightly more comfortable.
> 
> If you're OK with the concept, I can throw an RFC
> together.
> 
> Best Regards,
> 
> Leif
> 
> On Mon, Dec 04, 2017 at 03:31:10PM +0000, Kinney, Michael
> D wrote:
> > Leif,
> >
> > I may make more sense to add to MdePkg as a peer to
> IoLib.
> > This minimizes the package dependencies for Si modules.
> >
> > I am ok as a wrapper on top of IoLib.  Whatever reduces
> > code duplication and reduces maintenance.
> >
> > Best regards,
> >
> > Mike
> >
> > > -----Original Message-----
> > > From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> > > Sent: Monday, December 4, 2017 4:36 AM
> > > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > > Cc: Udit Kumar <udit.kumar@nxp.com>; Meenakshi
> Aggarwal
> > > <meenakshi.aggarwal@nxp.com>; Varun Sethi
> > > <V.Sethi@nxp.com>; edk2-devel@lists.01.org; Gao,
> Liming
> > > <liming.gao@intel.com>; Ard Biesheuvel
> > > <ard.biesheuvel@linaro.org>
> > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> support
> > > for big-endian MMIO
> > >
> > > Mike,
> > >
> > > In that case - do you think it should be added to
> > > MdeModulePkg?
> > >
> > > Should it be implemented simply as a wrapper on IoLib
> > > (depending on
> > > it)?
> > >
> > > /
> > >     Leif
> > >
> > > On Fri, Dec 01, 2017 at 10:41:26PM +0000, Kinney,
> Michael
> > > D wrote:
> > > > Udit,
> > > >
> > > > I agree with your concern.
> > > >
> > > > I am in favor of adding new APIs that perform the
> > > > byte swap operations.
> > > >
> > > > Mike
> > > >
> > > > > -----Original Message-----
> > > > > From: Udit Kumar [mailto:udit.kumar@nxp.com]
> > > > > Sent: Friday, December 1, 2017 9:58 AM
> > > > > To: Leif Lindholm <leif.lindholm@linaro.org>;
> > > Meenakshi
> > > > > Aggarwal <meenakshi.aggarwal@nxp.com>; Varun
> Sethi
> > > > > <V.Sethi@nxp.com>
> > > > > Cc: Kinney, Michael D
> <michael.d.kinney@intel.com>;
> > > edk2-
> > > > > devel@lists.01.org; Gao, Liming
> > > <liming.gao@intel.com>;
> > > > > Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > > > > Subject: RE: [edk2] [PATCH 1/1] MdePkg/IoLib: Add
> > > support
> > > > > for big-endian MMIO
> > > > >
> > > > > Thanks Leif,
> > > > >
> > > > > > It may require a little bit more of up-front
> work,
> > > but
> > > > > the end result will be a
> > > > > > platform port that works with the intended edk2
> > > design
> > > > > principles rather than
> > > > >
> > > > > Yes, this will be re-design/code for us, breaking
> all
> > > > > software pieces into
> > > > > smaller blocks and exposing protocol from the
> same.
> > > > > This could be managed.
> > > > >
> > > > > But how do you see,  if there is such dependency
> oN
> > > lib.
> > > > > Say a driver which is in BE mode, and is using
> > > DebugLib
> > > > > (BaseDebugLibSerialPort)
> > > > > And DebugLib uses SerialPortLib, which is in LE
> mode
> > > > >
> > > > > Thanks
> > > > > Udit
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > bounces@lists.01.org] On Behalf Of Leif
> > > > > > Lindholm
> > > > > > Sent: Friday, December 01, 2017 4:28 PM
> > > > > > To: Meenakshi Aggarwal
> <meenakshi.aggarwal@nxp.com>
> > > > > > Cc: Kinney, Michael D
> <michael.d.kinney@intel.com>;
> > > > > edk2-devel@lists.01.org;
> > > > > > Gao, Liming <liming.gao@intel.com>; Ard
> Biesheuvel
> > > > > > <ard.biesheuvel@linaro.org>
> > > > > > Subject: Re: [edk2] [PATCH 1/1] MdePkg/IoLib:
> Add
> > > > > support for big-endian
> > > > > > MMIO
> > > > > >
> > > > > > On Thu, Nov 30, 2017 at 04:15:38AM +0000,
> Meenakshi
> > > > > Aggarwal wrote:
> > > > > > > Hi Leif, Mike,
> > > > > > >
> > > > > > >
> > > > > > > NXP boards, at present, have few controllers
> with
> > > big
> > > > > endian and other
> > > > > > > with little endian memory access.
> > > > > >
> > > > > > Sure, this is not a problem.
> > > > > >
> > > > > > > Maximum controllers depend on SocLib library
> for
> > > > > clock information and
> > > > > > > endianness for SocLib and controllers is
> > > different.
> > > > > >
> > > > > > OK, I see in SocLib you have something called a
> Gur
> > > > > that is read once (and again
> > > > > > does a special per-device Pcd dance for runtime
> > > > > selection between
> > > > > > byteswapping Mmio and plain Mmio).
> > > > > >
> > > > > > > So this option will not work for us,
> > > > > > >   You would then just do (in your .dsc):
> > > > > > >
> Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf {
> > > > > > >       IoLib|<path to BeIoLib .inf>
> > > > > > >   }
> > > > > > >
> > > > > > > Because all libraries included by WatchDog
> will
> > > then
> > > > > access BE mode Mmio
> > > > > > APIs.
> > > > > >
> > > > > > Which libraries performing Mmio accesses are
> you
> > > > > intending to include in your
> > > > > > watchdog driver? You have submitted none as
> part of
> > > > > this series.
> > > > > >
> > > > > > > And breaking code into separate modules with
> > > > > different access will be
> > > > > > > very difficult.
> > > > > >
> > > > > > It may require a little bit more of up-front
> work,
> > > but
> > > > > the end result will be a
> > > > > > platform port that works with the intended edk2
> > > design
> > > > > principles rather than
> > > > > > against them. And that will reduce the overall
> > > effort
> > > > > (not to mention code
> > > > > > duplication).
> > > > > >
> > > > > > From the patches you have sent, the only
> required
> > > > > change I see (if a
> > > > > > byteswapping IoLib was added to edk2) would be
> to
> > > > > create a tiny driver for this
> > > > > > "Gur" device that installs a protocol
> containing a
> > > > > single function for reading
> > > > > > from that device's register space. That driver
> can
> > > be
> > > > > built against the swapping
> > > > > > or non-swapping IoLib as appropriate.
> > > > > >
> > > > > > > Watchdog is not the only module which need BE
> > > Mmio
> > > > > APIs, we have MMC
> > > > > > > and other controllers also with same
> requirement.
> > > > > >
> > > > > > And the same solutions are possible everywhere.
> > > > > >
> > > > > > Best Regards,
> > > > > >
> > > > > > Leif
> > > > > >
> > > > > > > We need BE Mmio APIs with a different name.
> > > > > > >
> > > > > > > Please see the possibility.
> > > > > > >
> > > > > > > Thanks & Regards,
> > > > > > > Meenakshi
> > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: Leif Lindholm
> > > > > [mailto:leif.lindholm@linaro.org]
> > > > > > > > Sent: Thursday, November 30, 2017 1:19 AM
> > > > > > > > To: Kinney, Michael D
> > > <michael.d.kinney@intel.com>
> > > > > > > > Cc: Meenakshi Aggarwal
> > > > > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > > <liming.gao@intel.com>; edk2-
> > > devel@lists.01.org;
> > > > > Ard Biesheuvel
> > > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> MdePkg/IoLib:
> > > Add
> > > > > support for
> > > > > > > > big-endian MMIO
> > > > > > > >
> > > > > > > > I guess there is no strict rule about a
> driver
> > > only
> > > > > directly
> > > > > > > > accessing one piece of HW?
> > > > > > > >
> > > > > > > > Still, that would be one possible solution:
> > > > > breaking accesses to a
> > > > > > > > separate HW in need of byteswapping out
> into
> > > its
> > > > > own module and
> > > > > > > > letting it override IoLib version there.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > >
> > > > > > > > Leif
> > > > > > > >
> > > > > > > > On Wed, Nov 29, 2017 at 07:25:05PM +0000,
> > > Kinney,
> > > > > Michael D wrote:
> > > > > > > > > Leif,
> > > > > > > > >
> > > > > > > > > I agree that this should be described as
> byte
> > > > > swapping.
> > > > > > > > >
> > > > > > > > > What about a module that needs to access
> HW
> > > with
> > > > > and without the
> > > > > > > > > bytes swapped?  It gets more complex if a
> > > module
> > > > > is linked against
> > > > > > > > > several libs and some libs access HW with
> > > bytes
> > > > > swapped and some
> > > > > > > > > do not.
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > >
> > > > > > > > > Mike
> > > > > > > > >
> > > > > > > > > > -----Original Message-----
> > > > > > > > > > From: edk2-devel [mailto:edk2-devel-
> > > > > bounces@lists.01.org] On
> > > > > > > > > > Behalf Of Leif Lindholm
> > > > > > > > > > Sent: Wednesday, November 29, 2017 4:51
> AM
> > > > > > > > > > To: Meenakshi Aggarwal
> > > > > <meenakshi.aggarwal@nxp.com>; Gao, Liming
> > > > > > > > > > <liming.gao@intel.com>
> > > > > > > > > > Cc: Kinney, Michael D
> > > > > <michael.d.kinney@intel.com>;
> > > > > > > > > > edk2-devel@lists.01.org; Ard Biesheuvel
> > > > > > > > > > <ard.biesheuvel@linaro.org>
> > > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > > MdePkg/IoLib:
> > > > > Add support for
> > > > > > > > > > big-endian MMIO
> > > > > > > > > >
> > > > > > > > > > Hi Meenakshi,
> > > > > > > > > >
> > > > > > > > > > I finally got around to looking at the
> > > watchdog
> > > > > code (that uses
> > > > > > > > > > this library), and that has convinced
> me
> > > the
> > > > > best solution is to
> > > > > > > > > > do what Liming proposed.
> > > > > > > > > >
> > > > > > > > > > Looking at this snippet:
> > > > > > > > > >
> > > > > > > > > > > +STATIC
> > > > > > > > > > > +UINT16
> > > > > > > > > > > +EFIAPI
> > > > > > > > > > > +WdogRead (
> > > > > > > > > > > +  IN  UINTN     Address
> > > > > > > > > > > +  )
> > > > > > > > > > > +{
> > > > > > > > > > > +  if (FixedPcdGetBool
> > > (PcdWdogBigEndian)) {
> > > > > > > > > > > +    return BeMmioRead16 (Address);
> > > > > > > > > > > +  } else {
> > > > > > > > > > > +    return MmioRead16(Address);
> > > > > > > > > > > +  }
> > > > > > > > > >
> > > > > > > > > > This is actually a pretty good
> > > demonstration of
> > > > > the arguments
> > > > > > > > > > that were made with regards to how the
> > > BeIoLib
> > > > > could be just
> > > > > > > > > > another implementation of IoLib.
> > > > > > > > > >
> > > > > > > > > > You would then just do (in your .dsc):
> > > > > > > > >
> > > >   Platform/NXP/Drivers/WatchDog/WatchDogDxe.inf
> > > > > {
> > > > > > > > > >     IoLib|<path to BeIoLib .inf>
> > > > > > > > > >   }
> > > > > > > > > >
> > > > > > > > > > This causes the big-endian version of
> the
> > > > > library to be used for
> > > > > > > > > > this component. This makes these
> > > Wdog<access>
> > > > > functions and the
> > > > > > > > > > Pcd redundant, and the rest of the code
> can
> > > use
> > > > > > > > > > MmioRead16()/MmioWrite16()
> > > > > > > > > > directly.
> > > > > > > > > >
> > > > > > > > > > But then, it is not really a big-endian
> or
> > > > > litte-endian version
> > > > > > > > > > of the library we need. We always know
> > > which
> > > > > endianness we are
> > > > > > > > > > building for.
> > > > > > > > > > What we need is a byteswapping flavour
> of
> > > > > IoLib.
> > > > > > > > > >
> > > > > > > > > > So Liming, what if we do something like
> > > adding
> > > > > a
> > > > > > > > > >
> > > > >
> > >
> MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSwa
> > > > > > > > > > p.inf
> > > > > > > > > > ---
> > > > > > > > > > [Defines]
> > > > > > > > > >   INF_VERSION                    =
> > > 0x0001001A
> > > > > > > > > >   BASE_NAME                      =
> > > > > > > > > > BaseIoLibIntrinsicSwap
> > > > > > > > > >   MODULE_UNI_FILE                =
> > > > > > > > > > BaseIoLibIntrinsic.uni
> > > > > > > > > >   FILE_GUID                      =
> > > d4a60d44-
> > > > > 3688-4a50-
> > > > > > > > > > b2d0-5c6fc2422523
> > > > > > > > > >   MODULE_TYPE                    = BASE
> > > > > > > > > >   VERSION_STRING                 = 1.0
> > > > > > > > > >   LIBRARY_CLASS                  =
> IoLib
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > #
> > > > > > > > > > #  VALID_ARCHITECTURES           = IA32
> X64
> > > EBC
> > > > > IPF ARM
> > > > > > > > > > AARCH64
> > > > > > > > > > #
> > > > > > > > > >
> > > > > > > > > > [Sources]
> > > > > > > > > >   BaseIoLibIntrinsicInternal.h
> > > > > > > > > >   IoHighLevel.c
> > > > > > > > > >   IoLib.c
> > > > > > > > > >   IoLibEbc.c         # Asserts on all
> i/o
> > > port
> > > > > accesses
> > > > > > > > > >   IoLibMmioBuffer.c
> > > > > > > > > >
> > > > > > > > > > [Packages]
> > > > > > > > > >   MdePkg/MdePkg.dec
> > > > > > > > > >
> > > > > > > > > > [LibraryClasses]
> > > > > > > > > >   DebugLib
> > > > > > > > > >   BaseLib
> > > > > > > > > >
> > > > > > > > > > [BuildOptions]
> > > > > > > > > >   GCC:*_*_*_CC_FLAGS  = -DSWAP_BYTES
> > > > > > > > > > ---
> > > > > > > > > >
> > > > > > > > > > And then add
> > > > > > > > > >
> > > > > > > > > > #ifdef SWAP_BYTES
> > > > > > > > > >   return SwapBytesXX (Value);
> > > > > > > > > > #else
> > > > > > > > > >   return Value;
> > > > > > > > > > #fi
> > > > > > > > > >
> > > > > > > > > > for the read operations and
> > > > > > > > > >
> > > > > > > > > > #ifdef SWAP_BYTES
> > > > > > > > > >   *(type)Address = SwapBytesXX (Value);
> > > #else
> > > > > > > > > >   *(type)Address = Value;
> > > > > > > > > > #fi
> > > > > > > > > >
> > > > > > > > > > for the write operations in IoLib.c?
> > > > > > > > > >
> > > > > > > > > > /
> > > > > > > > > >     Leif
> > > > > > > > > >
> > > > > > > > > > On Mon, Nov 27, 2017 at 06:06:33AM
> +0000,
> > > > > Meenakshi Aggarwal
> > > > > > > > > > wrote:
> > > > > > > > > > > Hi Leif,
> > > > > > > > > > >
> > > > > > > > > > > This is regarding Big-Endian Library
> > > patch
> > > > > ([PATCH v2
> > > > > > > > > > 1/9]
> > > > > > > > > > > Platform/NXP: Add support for Big
> Endian
> > > Mmio
> > > > > APIs)
> > > > > > > > > > >
> > > > > > > > > > > We have started this discussion
> before
> > > and
> > > > > the
> > > > > > > > > > suggestion was to
> > > > > > > > > > > create a separate .inf file keeping
> APIs
> > > name
> > > > > same e.g.
> > > > > > > > > > > MmioRead/MmioWrite in MdePkg.
> > > > > > > > > > >
> > > > > > > > > > > But we can't go with this approach
> > > (reason
> > > > > mentioned
> > > > > > > > > > by Udit).
> > > > > > > > > > >
> > > > > > > > > > > So please suggest if we should keep
> this
> > > > > library
> > > > > > > > > > under Platform/NXP
> > > > > > > > > > > or I send a new patch moving this
> library
> > > in
> > > > > MdePkg.
> > > > > > > > > > >
> > > > > > > > > > > But we have to keep a different name
> for
> > > Big
> > > > > Endian
> > > > > > > > > > MMIO APIs.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Thanks,
> > > > > > > > > > > Meenakshi
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > > From: Udit Kumar
> > > > > > > > > > > > Sent: Monday, October 23, 2017
> 12:38 PM
> > > > > > > > > > > > To: Gao, Liming
> <liming.gao@intel.com>;
> > > > > Meenakshi
> > > > > > > > > > Aggarwal
> > > > > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > > > > Biesheuvel
> > > > > > > > > > > > <ard.biesheuvel@linaro.org>;
> Kinney,
> > > > > Michael D
> > > > > > > > > > > > <michael.d.kinney@intel.com>; edk2-
> > > > > > > > > > devel@lists.01.org
> > > > > > > > > > > > Subject: RE: [edk2] [PATCH 1/1]
> > > > > MdePkg/IoLib: Add
> > > > > > > > > > support for big-endian
> > > > > > > > > > > > MMIO
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Meenakshi/Liming,
> > > > > > > > > > > > My 2 cents, around this.
> > > > > > > > > > > >
> > > > > > > > > > > > 1)
> > > > > > > > > > > > Having a new lib for BE read might
> not
> > > be
> > > > > helpful
> > > > > > > > > > for us, e.g. a IP which is in
> > > > > > > > > > > > BE mode access the UART for print
> or
> > > system
> > > > > > > > > > registers which are in LE, then
> > > > > > > > > > > > with new Lib, we will get all
> > > read/write in
> > > > > BE mode
> > > > > > > > > > > >
> > > > > > > > > > > > 2)
> > > > > > > > > > > > Especially for our IPs, which are
> > > changing
> > > > > from BE
> > > > > > > > > > to LE depending on
> > > > > > > > > > > > platform.
> > > > > > > > > > > > As said before, having BE read lib
> with
> > > API
> > > > > name of
> > > > > > > > > > MmioRead32 etc, will not
> > > > > > > > > > > > help (I guess Meenakshi already
> seen
> > > some
> > > > > problems
> > > > > > > > > > around this) Adding a
> > > > > > > > > > > > new lib with MmioRead32BE API name
> > > could
> > > > > help, but
> > > > > > > > > > IP driver we need to
> > > > > > > > > > > > take care of IP mode either by Pcd
> or
> > > > > #define, to
> > > > > > > > > > select MmioRead32 or
> > > > > > > > > > > > MmioRead32BE.
> > > > > > > > > > > > This conditional compile needs to
> be
> > > done
> > > > > for all
> > > > > > > > > > IPs (which works in BE/LE
> > > > > > > > > > > > mode on different platforms).
> > > > > > > > > > > >
> > > > > > > > > > > > My preferred way of implementation
> to
> > > use
> > > > > one
> > > > > > > > > > function in IP driver, And
> > > > > > > > > > > > based on IP mode, do the switch.
> > > > > > > > > > > >
> > > > > > > > > > > > New Lib could have function like
> below
> > > > > > > > > > > > MmioRead32Generic(IN  UINTN
> > > Address,
> > > > > BOOL
> > > > > > > > > > IsIPBE) {
> > > > > > > > > > > >    UINT32
> > > Value;
> > > > > > > > > > > >
> > > > > > > > > > > >    ASSERT ((Address & 3) == 0);
> > > > > > > > > > > >    Value = *(volatile
> UINT32*)Address;
> > > > > > > > > > > >    If(IsIPBE)
> > > > > > > > > > > >      Value = SwapBytes32(Value);
> > > return
> > > > > Value; }
> > > > > > > > > > > >
> > > > > > > > > > > > And IP driver can use it
> > > > > > > > > > > > MmioRead32Generic(ADDR,
> > > > > > > > > > > >
> > > FixedPcdGet(This_IP_Mode_For_This_platform)
> > > > > > > > > > > >
> > > > > > > > > > > > Comments are welcome.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards
> > > > > > > > > > > > Udit
> > > > > > > > > > > >
> > > > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > > > From: edk2-devel [mailto:edk2-
> devel-
> > > > > > > > > > bounces@lists.01.org] On Behalf Of
> > > > > > > > > > > > > Gao, Liming
> > > > > > > > > > > > > Sent: Monday, October 16, 2017
> 8:48
> > > AM
> > > > > > > > > > > > > To: Meenakshi Aggarwal
> > > > > > > > > > <meenakshi.aggarwal@nxp.com>; Ard
> > > Biesheuvel
> > > > > > > > > > > > > <ard.biesheuvel@linaro.org>;
> Kinney,
> > > > > Michael D
> > > > > > > > > > > > > <michael.d.kinney@intel.com>;
> edk2-
> > > > > > > > > > devel@lists.01.org
> > > > > > > > > > > > > Subject: Re: [edk2] [PATCH 1/1]
> > > > > MdePkg/IoLib: Add
> > > > > > > > > > support for
> > > > > > > > > > > > > big-endian MMIO
> > > > > > > > > > > > >
> > > > > > > > > > > > > Meenakshi:
> > > > > > > > > > > > >   I suggest to introduce new
> IoLib
> > > > > library
> > > > > > > > > > instance, not to add new IoLib
> > > > > > > > > > > > APIs.
> > > > > > > > > > > > > New IoLib library instance will
> > > perform
> > > > > IO
> > > > > > > > > > operation as the big
> > > > > > > > > > > > > endian. You can update
> > > > > > > > > > MdePkg/Library/BaseIoLibIntrinsic
> instance,
> > > add
> > > > > > > > > > > > > new source file and new INF for
> it.
> > > > > > > > > > > > >
> > > > > > > > > > > > > UINT32
> > > > > > > > > > > > > EFIAPI
> > > > > > > > > > > > > MmioRead32 (
> > > > > > > > > > > > >   IN  UINTN     Address
> > > > > > > > > > > > >   )
> > > > > > > > > > > > > {
> > > > > > > > > > > > >   UINT32
> > > > > Value;
> > > > > > > > > > > > >
> > > > > > > > > > > > >   ASSERT ((Address & 3) == 0);
> > > > > > > > > > > > >   Value = *(volatile
> UINT32*)Address;
> > > > > > > > > > > > >   return SwapBytes32(Value); }
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > Liming
> > > > > > > > > > > > > >-----Original Message-----
> > > > > > > > > > > > > >From: Meenakshi Aggarwal
> > > > > > > > > > [mailto:meenakshi.aggarwal@nxp.com]
> > > > > > > > > > > > > >Sent: Friday, October 13, 2017
> 2:07
> > > PM
> > > > > > > > > > > > > >To: Ard Biesheuvel
> > > > > <ard.biesheuvel@linaro.org>;
> > > > > > > > > > Kinney, Michael D
> > > > > > > > > > > > > ><michael.d.kinney@intel.com>;
> edk2-
> > > > > > > > > > devel@lists.01.org; Gao, Liming
> > > > > > > > > > > > > ><liming.gao@intel.com>
> > > > > > > > > > > > > >Subject: RE: [edk2] [PATCH 1/1]
> > > > > MdePkg/IoLib:
> > > > > > > > > > Add support for
> > > > > > > > > > > > > >big-endian MMIO
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >Hi All,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >It’s a pretty old discussion, we
> > > have
> > > > > left the
> > > > > > > > > > upstreaming of NXP
> > > > > > > > > > > > > >package in between because of
> some
> > > other
> > > > > work,
> > > > > > > > > > but have started it
> > > > > > > > > > > > > >again
> > > > > > > > > > > > > now.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >Issue  : Few NXP modules support
> Big
> > > > > Endian
> > > > > > > > > > MMIOs as these are ported
> > > > > > > > > > > > > >from PowerPC.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >Solution suggested : Create a
> > > separate
> > > > > library
> > > > > > > > > > for BE MMIO APIs.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >So what I have done is, I have
> > > created a
> > > > > > > > > > separate library to support
> > > > > > > > > > > > > >BE MMIO APIs and currently
> keeping
> > > it to
> > > > > my
> > > > > > > > > > package.
> > > > > > > > > > > > > >This library is basically a
> wrapper
> > > over
> > > > > > > > > > existing MMIO APIs.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >UINT32
> > > > > > > > > > > > > >EFIAPI
> > > > > > > > > > > > > >BeMmioRead32 (
> > > > > > > > > > > > > >  IN  UINTN     Address
> > > > > > > > > > > > > >  )
> > > > > > > > > > > > > >{
> > > > > > > > > > > > > >  UINT32  Value;
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >  Value = MmioRead32(Address);
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >  return SwapBytes32(Value); }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >Need your opinion on below
> optinos:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >1. Will this be a good idea to
> make
> > > this
> > > > > library
> > > > > > > > > > a part of MdePkg? OR
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >2. Add a new file e.g.
> IoBeMmio.c
> > > like
> > > > > > > > > > IoHighLevel.c in
> > > > > > > > > > > > >
> >MdePkg/Library/BaseIoLibIntrinsic/
> > > > > > > > > > > > > > And made these APIs a part of
> IoLib
> > > > > itself. OR
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >3. Keep this library internal to
> NXP
> > > > > package.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >Please provide your inputs.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >Thanks & Regards,
> > > > > > > > > > > > > >Meenakshi
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >> -----Original Message-----
> > > > > > > > > > > > > >> From: Bhupesh Sharma
> > > > > > > > > > > > > >> Sent: Monday, October 17, 2016
> > > 3:28 PM
> > > > > > > > > > > > > >> To: Ard Biesheuvel
> > > > > > > > > > <ard.biesheuvel@linaro.org>; Kinney,
> > > Michael D
> > > > > > > > > > > > > >> <michael.d.kinney@intel.com>
> > > > > > > > > > > > > >> Cc: Gao, Liming
> > > > > <liming.gao@intel.com>; edk2-
> > > > > > > > > > devel@ml01.01.org;
> > > > > > > > > > > > > >> Meenakshi Aggarwal
> > > > > > > > > > <meenakshi.aggarwal@nxp.com>
> > > > > > > > > > > > > >> Subject: RE: [edk2] [PATCH
> 1/1]
> > > > > MdePkg/IoLib:
> > > > > > > > > > Add support for
> > > > > > > > > > > > > >> big-endian MMIO
> > > > > > > > > > > > > >>
> > > > > > > > > > > > > >> Hi Ard,
> > > > > > > > > > > > > >>
> > > > > > > > > > > > > >> > -----Original Message-----
> > > > > > > > > > > > > >> > From: Ard Biesheuvel
> > > > > > > > > > [mailto:ard.biesheuvel@linaro.org]
> > > > > > > > > > > > > >> > Sent: Monday, October 17,
> 2016
> > > 1:12
> > > > > PM
> > > > > > > > > > > > > >> > To: Kinney, Michael D
> > > > > > > > > > <michael.d.kinney@intel.com>
> > > > > > > > > > > > > >> > Cc: Gao, Liming
> > > > > <liming.gao@intel.com>;
> > > > > > > > > > Bhupesh Sharma
> > > > > > > > > > > > > >> > <bhupesh.sharma@nxp.com>;
> edk2-
> > > > > > > > > > devel@ml01.01.org
> > > > > > > > > > > > > >> > Subject: Re: [edk2] [PATCH
> 1/1]
> > > > > > > > > > MdePkg/IoLib: Add support for
> > > > > > > > > > > > > >> > big- endian MMIO
> > > > > > > > > > > > > >> >
> > > > > > > > > > > > > >> > On 17 October 2016 at 05:10,
> > > Kinney,
> > > > > Michael
> > > > > > > > > > D
> > > > > > > > > > > > > >> > <michael.d.kinney@intel.com>
> > > wrote:
> > > > > > > > > > > > > >> > > Bhupesh,
> > > > > > > > > > > > > >> > >
> > > > > > > > > > > > > >> > > It is also possible to add
> an
> > > ARM
> > > > > specific
> > > > > > > > > > PCD to select
> > > > > > > > > > > > > >> > > endianness and update
> > > > > > > > > > > > > >> > >
> > > > > > > > > >
> > > MdePkg/Library/BaseIoLibIntrinsic/IoLibArm.c to
> > > > > use that PCD in
> > > > > > > > > > > > > >> > > MmioRead/Write() APIs in
> that
> > > file
> > > > > to
> > > > > > > > > > support both endian types.
> > > > > > > > > > > > > >> > > You can use the
> SwapBytesxx()
> > > > > functions
> > > > > > > > > > from BaseLib(as
> > > > > > > > > > > > > >> > Laszlo
> > > > > > > > > > > > > >> > > suggested) based on the
> > > setting of
> > > > > this
> > > > > > > > > > ARM specific PCD.
> > > > > > > > > > > > > >> > >
> > > > > > > > > > > > > >> > > Modules that link against
> this
> > > lib
> > > > > can
> > > > > > > > > > select endianness by
> > > > > > > > > > > > > >> > > setting PCD in the scope
> of
> > > that
> > > > > module.
> > > > > > > > > > > > > >> > >
> > > > > > > > > > > > > >> > > The IPF version of IoLib
> uses
> > > an
> > > > > IPF
> > > > > > > > > > specific PCD to translate
> > > > > > > > > > > > > >> > > I/O port accesses to MMIO
> > > > > accesses.  So
> > > > > > > > > > there is already an
> > > > > > > > > > > > > >> > > example of an arch
> specific
> > > PCD in
> > > > > this
> > > > > > > > > > lib instance.
> > > > > > > > > > > > > >> > >
> > > > > > > > > > > > > >> >
> > > > > > > > > > > > > >> > This is not a platform wide
> > > thing,
> > > > > it is a
> > > > > > > > > > per-device property
> > > > > > > > > > > > > >> > whether the MMIO occurs in
> big
> > > > > endian or
> > > > > > > > > > little endian manner.
> > > > > > > > > > > > > >> >
> > > > > > > > > > > > > >> > So I think Liming's
> suggestion
> > > makes
> > > > > sense:
> > > > > > > > > > create an IoLib
> > > > > > > > > > > > > >> > implementation that performs
> the
> > > > > byte
> > > > > > > > > > swapping, and selectively
> > > > > > > > > > > > > >> > incorporate it into drivers
> that
> > > > > require it
> > > > > > > > > > using
> > > > > > > > > > > > > >> >
> > > > > > > > > > > > > >> > BeMmioDeviceDxe.inf {
> > > > > > > > > > > > > >> >   <LibraryClasses>
> > > > > > > > > > > > > >> >
> > > > > IoLib|SomePkg/Library/BigEndianIoLib.inf
> > > > > > > > > > > > > >> > }
> > > > > > > > > > > > > >>
> > > > > > > > > > > > > >> That's correct. I think
> creating a
> > > > > separate
> > > > > > > > > > IoLib for byte-swapping
> > > > > > > > > > > > > >> makes sense.
> > > > > > > > > > > > > >>
> > > > > > > > > > > > > >> We will rework the patch
> > > accordingly.
> > > > > > > > > > > > > >>
> > > > > > > > > > > > > >> Regards,
> > > > > > > > > > > > > >> Bhupesh
> > > > > > > > > > > > >
> > > > > _______________________________________________
> > > > > > > > > > > > > edk2-devel mailing list
> > > > > > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > > > > > >
> > > > > > > >
> > > > >
> > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> > > > > s%3A%2F%2Fl
> > > > > > > > ist
> > > > > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > > > >
> > > > > >
> > > > >
> > >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > > > > 3cbb51
> > > > > > > >
> > > > > >
> > > > >
> > >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > > > > 7C0%7C0
> > > > > > > >
> > > > >
> > >
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > > > > dEQ
> > > > > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > > > > >
> > > _______________________________________________
> > > > > > > > > > edk2-devel mailing list
> > > > > > > > > > edk2-devel@lists.01.org
> > > > > > > > > >
> > > > > > > >
> > > > >
> > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> > > > > s%3A%2F%2Fl
> > > > > > > > ist
> > > > > > > > s.01.org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > > > >
> > > > > >
> > > > >
> > >
> devel&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7C695e4
> > > > > 3cbb51
> > > > > > > >
> > > > > >
> > > > >
> > >
> a471cd44608d5376230b0%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> > > > > 7C0%7C0
> > > > > > > >
> > > > >
> > >
> %7C636475817220663612&sdata=hwQh8dfUkVGzm7uQB9%2FirexmYEk
> > > > > dEQ
> > > > > > > > %2Bu97606L%2FHEfg%3D&reserved=0
> > > > > > _______________________________________________
> > > > > > edk2-devel mailing list
> > > > > > edk2-devel@lists.01.org
> > > > > >
> > > > >
> > >
> https://emea01.safelinks.protection.outlook.com/?url=http
> > > > > s%3A%2F%2Flists.01
> > > > > > .org%2Fmailman%2Flistinfo%2Fedk2-
> > > > > >
> > > > >
> > >
> devel&data=02%7C01%7Cudit.kumar%40nxp.com%7Cd06018336a064
> > > > > 8fa8e440
> > > > > >
> > > > >
> > >
> 8d538aa5f19%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C
> > > > > 6364772
> > > > > >
> > > > >
> > >
> 26761253124&sdata=bAU%2BOidbzbKw76OOq5%2FUplwQbo8iMnE3alH
> > > > > Y4ptAX
> > > > > > MU%3D&reserved=0

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

end of thread, other threads:[~2017-12-04 16:14 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-14  9:33 [PATCH 1/1] MdePkg/IoLib: Add support for big-endian MMIO Bhupesh Sharma
2016-10-14 12:06 ` Laszlo Ersek
2016-10-14 13:17   ` Bhupesh Sharma
2016-10-14 13:32     ` Laszlo Ersek
2016-10-17  3:10 ` Gao, Liming
2016-10-17  4:10   ` Kinney, Michael D
2016-10-17  7:42     ` Ard Biesheuvel
2016-10-17  9:57       ` Bhupesh Sharma
2017-10-13  6:07         ` Meenakshi Aggarwal
2017-10-16  3:17           ` Gao, Liming
2017-10-23  7:07             ` Udit Kumar
2017-11-27  6:06               ` Meenakshi Aggarwal
2017-11-27 11:07                 ` Leif Lindholm
2017-11-29 12:51                 ` Leif Lindholm
2017-11-29 19:25                   ` Kinney, Michael D
2017-11-29 19:48                     ` Leif Lindholm
2017-11-30  4:15                       ` Meenakshi Aggarwal
2017-12-01 10:57                         ` Leif Lindholm
2017-12-01 17:57                           ` Udit Kumar
2017-12-01 22:41                             ` Kinney, Michael D
2017-12-04  6:18                               ` Meenakshi Aggarwal
2017-12-04 12:36                               ` Leif Lindholm
2017-12-04 15:31                                 ` Kinney, Michael D
2017-12-04 15:54                                   ` Leif Lindholm
2017-12-04 16:19                                     ` Kinney, Michael D

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