From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by mx.groups.io with SMTP id smtpd.web10.3452.1587636559859879105 for ; Thu, 23 Apr 2020 03:09:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=QIg8iy25; spf=pass (domain: nuviainc.com, ip: 209.85.128.43, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f43.google.com with SMTP id 188so5792497wmc.2 for ; Thu, 23 Apr 2020 03:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bgzspWuj2opYtjLTNNxJ1OQZwl02siua31aaD3UkO/U=; b=QIg8iy25IxTSYb4MHMgFi2EMv8TMUxZFSlt22Ue3PSRmSl060t7e9zkEO5kvt5emUW Agk6gU0vooFCeo3afMZvMzpG6J9WTaHpnF25IqMTE0rMH3GW38I7fRsxa+AAxgxP78hP xKNo76WrZN97W8mM4dpLvKAixc26SJPS/MJ0oGfs3L5XF7HisHW08Zb0kXzeS7BDyMGG YknZFhCZoc4AJkq3OT8UlMAG8vctXz5JrGEeVCvhly43QnR8ycLRD+RqweDj0gvMN8Ki Axr1jF5EdX0tS/By4bboZxPrfm47T4JHhPAln+02R/mzs6Hrawf/uWbqhE7pNppPa5bU wmcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bgzspWuj2opYtjLTNNxJ1OQZwl02siua31aaD3UkO/U=; b=MqLuQBJjFXT4MvKNT/W+2pAqYlA9jUG5q7Esc82iHgvF2PXh+woAzTMGH/ZdkwmElK M8hpJQA36W7hZZQRq8VCRMETz0S9K2hB5Grzxg/1mWWiwgbEYrHw+jMqm9aVTNeweSuv HK2ML/4oDsToc9FUXcN3wYOlMx/hNhHMnrVnYBvd9YKqI+/T+ddJ/ZAgHyPO0ZaprDgZ LSIV7WwnM/Wu8QOQg3aj13C/iFtGk2TcCa6a5BKAmS8i3W2eDh3EXd1H02jxZNNvmuVM QIoNwSjA4/wx1t+yMGYXqyEHPydURZKBQtLWuuEAXZKdushD13XOvHxZNhAYsZ90WlT4 GQQQ== X-Gm-Message-State: AGi0PuYQdEeKb+cV0bjKklfxU2QCNK+YO+aFgIANmKc4eBDHLgdD8ITc uYpnAxbGAYSGlliB/nT8NNKMf9r+3lwiOKdcIZ1nqbjwTEgFG8IILp4NcwxwWrwdIfxs22/m89/ 6aqkKFGDakauil/i6ySYpIhOuBaSYT7B4xD6wNl0ZP1tdhQnwN39/MIuLe3fvtg4= X-Google-Smtp-Source: APiQypIa8OeWrGl+pMf0BcaGnFVIvSPAGmuijMSIMIlKA8MChpkp2gZrk+sO/IA5hbn0zGbOPa8Mcw== X-Received: by 2002:a1c:8049:: with SMTP id b70mr3351530wmd.162.1587636557909; Thu, 23 Apr 2020 03:09:17 -0700 (PDT) Return-Path: Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id a7sm2937450wmj.12.2020.04.23.03.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 03:09:17 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Meenakshi Aggarwal , Pankaj Bansal Subject: [PATCH edk2-platforms 1/1] Silicon/NXP: rework IoAccessLib to use single function pointer struct Date: Thu, 23 Apr 2020 11:09:16 +0100 Message-Id: <20200423100916.13064-1-leif@nuviainc.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For whatever reason, the function pointer structs (and their retrieval functions) were split up on data size boundary - separate for 16-bit, 32-bit, and 64-bit. This makes the already tedious boilerplate require to deal with these hardware quirks even worse, so unify them into a single function pointer struct and retrieval function. Cc: Meenakshi Aggarwal Cc: Pankaj Bansal Signed-off-by: Leif Lindholm --- Meenakshi, Pankaj - I have no hardware to verify that this patch works, but it builds cleanlyi and isn't exactly complex. I will need R-b from at least one of you, and ideally Tested-by as well. Silicon/NXP/Include/Library/IoAccessLib.h | 52 ++---------- Silicon/NXP/Library/IoAccessLib/IoAccessLib.c | 82 ++++--------------- 2 files changed, 22 insertions(+), 112 deletions(-) diff --git a/Silicon/NXP/Include/Library/IoAccessLib.h b/Silicon/NXP/Include/Library/IoAccessLib.h index 0b708d544fa7..0f5b19dcf149 100644 --- a/Silicon/NXP/Include/Library/IoAccessLib.h +++ b/Silicon/NXP/Include/Library/IoAccessLib.h @@ -15,40 +15,26 @@ /// Structure to have pointer to R/W /// Mmio operations for 16 bits. /// -typedef struct _MMIO_OPERATIONS_16 { +typedef struct _MMIO_OPERATIONS { 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; +} MMIO_OPERATIONS; /** - Function to return pointer to 16 bit Mmio operations. + Function to return pointer to Mmio operations. @param Swap Flag to tell if Swap is needed or not on Mmio Operations. @@ -56,36 +42,8 @@ typedef struct _MMIO_OPERATIONS_64 { @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 ( +MMIO_OPERATIONS * +GetMmioOperations ( IN BOOLEAN Swap ); diff --git a/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c b/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c index 6ed83d019a6e..33039afda40f 100644 --- a/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c +++ b/Silicon/NXP/Library/IoAccessLib/IoAccessLib.c @@ -301,39 +301,17 @@ SwapMmioAnd64 ( return MmioAnd64 (Address, SwapBytes64 (AndData)); } -STATIC MMIO_OPERATIONS_16 SwappingFunctions16 = { +STATIC MMIO_OPERATIONS SwappingFunctions = { 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, @@ -341,7 +319,17 @@ STATIC MMIO_OPERATIONS_64 SwappingFunctions64 = { SwapMmioAndThenOr64, }; -STATIC MMIO_OPERATIONS_64 NonSwappingFunctions64 = { +STATIC MMIO_OPERATIONS NonSwappingFunctions = { + MmioRead16, + MmioWrite16, + MmioOr16, + MmioAnd16, + MmioAndThenOr16, + MmioRead32, + MmioWrite32, + MmioOr32, + MmioAnd32, + MmioAndThenOr32, MmioRead64, MmioWrite64, MmioOr64, @@ -350,7 +338,7 @@ STATIC MMIO_OPERATIONS_64 NonSwappingFunctions64 = { }; /** - Function to return pointer to 16 bit Mmio operations. + Function to return pointer to Mmio operations. @param Swap Flag to tell if Swap is needed or not on Mmio Operations. @@ -358,47 +346,11 @@ STATIC MMIO_OPERATIONS_64 NonSwappingFunctions64 = { @return Pointer to Mmio Operations. **/ -MMIO_OPERATIONS_16 * -GetMmioOperations16 (BOOLEAN Swap) { +MMIO_OPERATIONS * +GetMmioOperations (BOOLEAN Swap) { if (Swap) { - return &SwappingFunctions16; + return &SwappingFunctions; } 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; + return &NonSwappingFunctions; } } -- 2.20.1