From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 14FF3740038 for ; Fri, 26 Jan 2024 06:28:58 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=w+q0mBjNBuZaCrEa25OzJAKHCyIkcrXTRwX/tyEHAX8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706250537; v=1; b=vCgsIkqwQvGW0arCHluGll/TmrZ8HlcQB5J8+1RvkISTVF1KTgIzEzPhhiC+okMn4DkTYXT7 AIh7PR4n+CNUSDJTo9ASVQEsyKGm/NQwbPNfB9XE1iK0ValLr3SdJ5VOrow29iX2ZKWSKG4Fn33 WIlQR5TrWnPBSwQwJZeOyMao= X-Received: by 127.0.0.2 with SMTP id EKkeYY7687511xY8Z2gxsWf0; Thu, 25 Jan 2024 22:28:57 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.9990.1706250531502387173 for ; Thu, 25 Jan 2024 22:28:52 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8AxafAfUbNlyx0GAA--.22086S3; Fri, 26 Jan 2024 14:28:47 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxTs0dUbNlv3EbAA--.51205S2; Fri, 26 Jan 2024 14:28:45 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v8 08/37] MdePkg: Add IOCSR operation for LoongArch Date: Fri, 26 Jan 2024 14:28:44 +0800 Message-Id: <20240126062844.3101286-1-lichao@loongson.cn> In-Reply-To: <20240126062715.3099433-1-lichao@loongson.cn> References: <20240126062715.3099433-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxTs0dUbNlv3EbAA--.51205S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAICGWyG+ALOQBDsc X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: fkjSsnU9SV4HBM5za2nMfJQbx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vCgsIkqw; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Add IoCsrRead8, IoCsrRead16, IoCsrRead32, IoCsrRead64, IoCsrWrite8, IoCsrWrite16, IoCsrWrite32, IoCsrWrite64 to operate the IOCSR registers of LoongArch architecture. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney Reviewed-by: Liming Gao --- MdePkg/Include/Library/BaseLib.h | 112 +++++++++++++++++++ MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Library/BaseLib/LoongArch64/IoCsr.S | 120 +++++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 MdePkg/Library/BaseLib/LoongArch64/IoCsr.S diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 4e97368ae2..1fff0fb224 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -396,6 +396,118 @@ CsrXChg ( IN UINTN Mask ); +/** + IO CSR read byte operation. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.b instruction. + +**/ +UINT8 +IoCsrRead8 ( + IN UINTN Select + ); + +/** + IO CSR read half word operation. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.h instruction. + +**/ +UINT16 +IoCsrRead16 ( + IN UINTN Select + ); + +/** + IO CSR read word operation. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.w instruction. + +**/ +UINT32 +IoCsrRead32 ( + IN UINTN Select + ); + +/** + IO CSR read double word operation. Only for LoongArch64. + + @param[in] Select IO CSR read instruction select values. + + @return The return value of iocsrrd.d instruction. + +**/ +UINT64 +IoCsrRead64 ( + IN UINTN Select + ); + +/** + IO CSR write byte operation. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.b will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite8 ( + IN UINTN Select, + IN UINT8 Value + ); + +/** + IO CSR write half word operation. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.h will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite16 ( + IN UINTN Select, + IN UINT16 Value + ); + +/** + IO CSR write word operation. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.w will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite32 ( + IN UINTN Select, + IN UINT32 Value + ); + +/** + IO CSR write double word operation. Only for LoongArch64. + + @param[in] Select IO CSR write instruction select values. + @param[in] Value The iocsrwr.d will write the value. + + @return VOID. + +**/ +VOID +IoCsrWrite64 ( + IN UINTN Select, + IN UINT64 Value + ); + #endif // defined (MDE_CPU_LOONGARCH64) // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf index 7c46306883..4dbe94be71 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -413,6 +413,7 @@ LoongArch64/Csr.c LoongArch64/InternalSwitchStack.c LoongArch64/AsmCsr.S | GCC + LoongArch64/IoCsr.S | GCC LoongArch64/GetInterruptState.S | GCC LoongArch64/EnableInterrupts.S | GCC LoongArch64/DisableInterrupts.S | GCC diff --git a/MdePkg/Library/BaseLib/LoongArch64/IoCsr.S b/MdePkg/Library/BaseLib/LoongArch64/IoCsr.S new file mode 100644 index 0000000000..a659908bc4 --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/IoCsr.S @@ -0,0 +1,120 @@ +#------------------------------------------------------------------------------ +# +# LoongArch ASM IO CSR operation functions +# +# Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#------------------------------------------------------------------------------ + +ASM_GLOBAL ASM_PFX (IoCsrRead8) +ASM_GLOBAL ASM_PFX (IoCsrRead16) +ASM_GLOBAL ASM_PFX (IoCsrRead32) +ASM_GLOBAL ASM_PFX (IoCsrRead64) + +ASM_GLOBAL ASM_PFX (IoCsrWrite8) +ASM_GLOBAL ASM_PFX (IoCsrWrite16) +ASM_GLOBAL ASM_PFX (IoCsrWrite32) +ASM_GLOBAL ASM_PFX (IoCsrWrite64) + +#/** +# IO CSR read byte operation. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.b instruction. +# +#**/ +ASM_PFX (IoCsrRead8): + iocsrrd.b $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR read half word operation. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.h instruction. +# +#**/ +ASM_PFX (IoCsrRead16): + iocsrrd.h $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR read word operation. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.w instruction. +# +#**/ +ASM_PFX (IoCsrRead32): + iocsrrd.w $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR read double word operation. Only for LoongArch64. +# +# @param[in] Select IO CSR read instruction select values. +# +# @return The return value of iocsrrd.d instruction. +# +#**/ +ASM_PFX (IoCsrRead64): + iocsrrd.d $a0, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write byte operation. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.b will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite8): + iocsrwr.b $a1, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write half word operation. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.h will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite16): + iocsrwr.h $a1, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write word operation. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.w will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite32): + iocsrwr.w $a1, $a0 + jirl $zero, $ra, 0 + +#/** +# IO CSR write double word operation. Only for LoongArch64. +# +# @param[in] Select IO CSR write instruction select values. +# @param[in] Value The iocsrwr.d will write the value. +# +# @return VOID. +# +#**/ +ASM_PFX (IoCsrWrite64): + iocsrwr.d $a1, $a0 + jirl $zero, $ra, 0 + .end -- 2.27.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114534): https://edk2.groups.io/g/devel/message/114534 Mute This Topic: https://groups.io/mt/103971647/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-