[edk2-devel] [PATCH edk2-platforms 02/12] Silicon/NXP: Add function to return swapped Mmio APIs pointer

Leif Lindholm leif.lindholm at linaro.org
Thu Oct 10 10:23:15 UTC 2019


On Wed, Oct 09, 2019 at 10:19:08PM +0530, Meenakshi Aggarwal wrote:
> 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.aggarwal at nxp.com>
> ---
>  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 b72e65c..1e7c028 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 Or);
> +  UINT16 (*And16) (UINTN Address, UINT16 AND);
> +  UINT16 (*AndThenOr16) (UINTN Address, UINT16 And, UINT16 Or);

The idea of having variables called "Or" and "And" makes my head hurt.
Thankfully, they are not called that in the actual implementations.

If you change all the "AND" to "AndData" and all the "Or" to "OrData"
in this file:

Reviewed-by: Leif Lindholm <leif.lindholm at linaro.org>

> +} 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 Or);
> +  UINT32 (*And32) (UINTN Address, UINT32 AND);
> +  UINT32 (*AndThenOr32) (UINTN Address, UINT32 And, UINT32 Or);
> +} 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 Or);
> +  UINT64 (*And64) (UINTN Address, UINT64 AND);
> +  UINT64 (*AndThenOr64) (UINTN Address, UINT64 And, UINT64 Or);
> +} 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 e9e535f..6ed83d0 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 (#48719): https://edk2.groups.io/g/devel/message/48719
Mute This Topic: https://groups.io/mt/34473278/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list