Add support to return pointer to MMIO APIs on basis of Swap flag.
If Flag is True then MMIO APIs returned in which data
swapped after reading from MMIO and before write using MMIO.

Signed-off-by: Meenakshi Aggarwal <meenakshi.aggar...@nxp.com>
Reviewed-by: Leif Lindholm <leif.lindh...@linaro.org>
---
 Silicon/NXP/Include/Library/IoAccessLib.h     |  78 +++++++++++++++
 Silicon/NXP/Library/IoAccessLib/IoAccessLib.c | 102 ++++++++++++++++++++
 2 files changed, 180 insertions(+)

diff --git a/Silicon/NXP/Include/Library/IoAccessLib.h 
b/Silicon/NXP/Include/Library/IoAccessLib.h
index b72e65c83091..0b708d544fa7 100644
--- a/Silicon/NXP/Include/Library/IoAccessLib.h
+++ b/Silicon/NXP/Include/Library/IoAccessLib.h
@@ -11,6 +11,84 @@
 
 #include <Base.h>
 
+///
+///  Structure to have pointer to R/W
+///  Mmio operations for 16 bits.
+///
+typedef struct _MMIO_OPERATIONS_16 {
+  UINT16 (*Read16) (UINTN Address);
+  UINT16 (*Write16) (UINTN Address, UINT16 Value);
+  UINT16 (*Or16) (UINTN Address, UINT16 OrData);
+  UINT16 (*And16) (UINTN Address, UINT16 AndData);
+  UINT16 (*AndThenOr16) (UINTN Address, UINT16 AndData, UINT16 OrData);
+} MMIO_OPERATIONS_16;
+
+///
+///  Structure to have pointer to R/W
+///  Mmio operations for 32 bits.
+///
+typedef struct _MMIO_OPERATIONS_32 {
+  UINT32 (*Read32) (UINTN Address);
+  UINT32 (*Write32) (UINTN Address, UINT32 Value);
+  UINT32 (*Or32) (UINTN Address, UINT32 OrData);
+  UINT32 (*And32) (UINTN Address, UINT32 AndData);
+  UINT32 (*AndThenOr32) (UINTN Address, UINT32 AndData, UINT32 OrData);
+} MMIO_OPERATIONS_32;
+
+///
+///  Structure to have pointer to R/W
+///  Mmio operations for 64 bits.
+///
+typedef struct _MMIO_OPERATIONS_64 {
+  UINT64 (*Read64) (UINTN Address);
+  UINT64 (*Write64) (UINTN Address, UINT64 Value);
+  UINT64 (*Or64) (UINTN Address, UINT64 OrData);
+  UINT64 (*And64) (UINTN Address, UINT64 AndData);
+  UINT64 (*AndThenOr64) (UINTN Address, UINT64 AndData, UINT64 OrData);
+} MMIO_OPERATIONS_64;
+
+/**
+  Function to return pointer to 16 bit Mmio operations.
+
+  @param  Swap  Flag to tell if Swap is needed or not
+                on Mmio Operations.
+
+  @return       Pointer to Mmio Operations.
+
+**/
+MMIO_OPERATIONS_16 *
+GetMmioOperations16  (
+  IN  BOOLEAN  Swap
+  );
+
+/**
+  Function to return pointer to 32 bit Mmio operations.
+
+  @param  Swap  Flag to tell if Swap is needed or not
+                on Mmio Operations.
+
+  @return       Pointer to Mmio Operations.
+
+**/
+MMIO_OPERATIONS_32 *
+GetMmioOperations32  (
+  IN  BOOLEAN  Swap
+  );
+
+/**
+  Function to return pointer to 64 bit Mmio operations.
+
+  @param  Swap  Flag to tell if Swap is needed or not
+                on Mmio Operations.
+
+  @return       Pointer to Mmio Operations.
+
+**/
+MMIO_OPERATIONS_64 *
+GetMmioOperations64  (
+  IN  BOOLEAN  Swap
+  );
+
 /**
   MmioRead16 for Big-Endian modules.
 
diff --git a/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c 
b/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
index e9e535fc2f85..6ed83d019a6e 100644
--- a/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
+++ b/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c
@@ -300,3 +300,105 @@ SwapMmioAnd64 (
 {
   return MmioAnd64 (Address, SwapBytes64 (AndData));
 }
+
+STATIC MMIO_OPERATIONS_16 SwappingFunctions16 = {
+  SwapMmioRead16,
+  SwapMmioWrite16,
+  SwapMmioOr16,
+  SwapMmioAnd16,
+  SwapMmioAndThenOr16,
+};
+
+STATIC MMIO_OPERATIONS_16 NonSwappingFunctions16 = {
+  MmioRead16,
+  MmioWrite16,
+  MmioOr16,
+  MmioAnd16,
+  MmioAndThenOr16,
+};
+
+STATIC MMIO_OPERATIONS_32 SwappingFunctions32 = {
+  SwapMmioRead32,
+  SwapMmioWrite32,
+  SwapMmioOr32,
+  SwapMmioAnd32,
+  SwapMmioAndThenOr32,
+};
+
+STATIC MMIO_OPERATIONS_32 NonSwappingFunctions32 = {
+  MmioRead32,
+  MmioWrite32,
+  MmioOr32,
+  MmioAnd32,
+  MmioAndThenOr32,
+};
+
+STATIC MMIO_OPERATIONS_64 SwappingFunctions64 = {
+  SwapMmioRead64,
+  SwapMmioWrite64,
+  SwapMmioOr64,
+  SwapMmioAnd64,
+  SwapMmioAndThenOr64,
+};
+
+STATIC MMIO_OPERATIONS_64 NonSwappingFunctions64 = {
+  MmioRead64,
+  MmioWrite64,
+  MmioOr64,
+  MmioAnd64,
+  MmioAndThenOr64,
+};
+
+/**
+  Function to return pointer to 16 bit Mmio operations.
+
+  @param  Swap  Flag to tell if Swap is needed or not
+                on Mmio Operations.
+
+  @return       Pointer to Mmio Operations.
+
+**/
+MMIO_OPERATIONS_16 *
+GetMmioOperations16 (BOOLEAN Swap) {
+  if (Swap) {
+    return &SwappingFunctions16;
+  } else {
+    return &NonSwappingFunctions16;
+  }
+}
+
+/**
+  Function to return pointer to 32 bit Mmio operations.
+
+  @param  Swap  Flag to tell if Swap is needed or not
+                on Mmio Operations.
+
+  @return       Pointer to Mmio Operations.
+
+**/
+MMIO_OPERATIONS_32 *
+GetMmioOperations32 (BOOLEAN Swap) {
+  if (Swap) {
+    return &SwappingFunctions32;
+  } else {
+    return &NonSwappingFunctions32;
+  }
+}
+
+/**
+  Function to return pointer to 64 bit Mmio operations.
+
+  @param  Swap  Flag to tell if Swap is needed or not
+                on Mmio Operations.
+
+  @return       Pointer to Mmio Operations.
+
+**/
+MMIO_OPERATIONS_64 *
+GetMmioOperations64 (BOOLEAN Swap) {
+  if (Swap) {
+    return &SwappingFunctions64;
+  } else {
+    return &NonSwappingFunctions64;
+  }
+}
-- 
1.9.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51036): https://edk2.groups.io/g/devel/message/51036
Mute This Topic: https://groups.io/mt/61076174/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to