From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by mx.groups.io with SMTP id smtpd.web09.22248.1574332902254223416 for ; Thu, 21 Nov 2019 02:41:42 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: nxp.com, ip: 92.121.34.13, mailfrom: meenakshi.aggarwal@nxp.com) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 937401A05EE; Thu, 21 Nov 2019 11:41:40 +0100 (CET) Received: from inv0113.in-blr01.nxp.com (inv0113.in-blr01.nxp.com [165.114.116.118]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 404191A0009; Thu, 21 Nov 2019 11:41:40 +0100 (CET) Received: from uefi-OptiPlex-790.ap.freescale.net (uefi-OptiPlex-790.ap.freescale.net [10.232.132.78]) by inv0113.in-blr01.nxp.com (Postfix) with ESMTP id 40706364; Thu, 21 Nov 2019 16:11:39 +0530 (IST) From: "Meenakshi Aggarwal" To: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, michael.d.kinney@intel.com, devel@edk2.groups.io Cc: v.sethi@nxp.com, Meenakshi Aggarwal Subject: [edk2-platforms] [PATCH v2 02/11] Silicon/NXP: Add function to return swapped Mmio APIs pointer Date: Thu, 21 Nov 2019 21:55:05 +0530 Message-Id: <1574353514-23986-3-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1574353514-23986-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1570639758-30355-1-git-send-email-meenakshi.aggarwal@nxp.com> <1574353514-23986-1-git-send-email-meenakshi.aggarwal@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Leif Lindholm --- 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 +/// +/// 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