From nobody Tue Feb 10 23:13:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110712+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110712+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1699241281; cv=none; d=zohomail.com; s=zohoarc; b=WFjIromfmLPiB7KcsQqhOLNMIP5merWcfHD3lZyf5n7RTJg+HC9DRJxrA4jFVwyeT2qLLxxqLhQJKZo7jzFwmm04wQbslHJlbej6m+wv0LfqFpLoDbjSZgEiTZ7rXw+rFJKvsFb3LUV8e7ofSoDoNF4T1Gs43uGP6THupokKgKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699241281; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=9wq/QHuugfpfODG8V/2/+wy7l2uddEX7RUL4rioDpaM=; b=O8nQij1AFkM9uZGk6IItmdE5rbKYBXynFUY2kNH0l0fvLD58UWrUKp4jSxyt1RxsATy66S9oVZfw5z+jMIRFCarWqAiQo+befkjlnZ5zAoDEoFeqwfstA79ZtQZepBQPHbGG29ULBXFkKFZL7A0WwiGtHeewOX5PHKxJXPnTZZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110712+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1699241281911605.5628772679262; Sun, 5 Nov 2023 19:28:01 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=G9bKTlP0XR6pNT8QNHlYHFRWD6uje+k9giHkv/yQ4Lw=; 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=1699241281; v=1; b=FXPrl3DMUjES//uiL2aIVCePRcCaW/Xq17xu9eU4hcvIslBMI2yy0+jNF0L6mkpkLwrneLGE 4A0tvmgm8u/4fzSHwzFf/W/2cK7FKFE3UtLMYYZyBT4hN1bizgtBxXuXfd1pSGPS9uehjSL5Zd7 HTsKnXAYGuXx3i2/tzk759dM= X-Received: by 127.0.0.2 with SMTP id CemAYY1788612xusWP1pA4He; Sun, 05 Nov 2023 19:28:01 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.47055.1699241280414045965 for ; Sun, 05 Nov 2023 19:28:01 -0800 X-Received: from loongson.cn (unknown [10.2.9.245]) by gateway (Coremail) with SMTP id _____8CxNvE9XUhlEjc3AA--.42423S3; Mon, 06 Nov 2023 11:27:57 +0800 (CST) X-Received: from code-server.gen (unknown [10.2.9.245]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxbNw8XUhlHxI6AA--.60845S2; Mon, 06 Nov 2023 11:27:56 +0800 (CST) From: "Chao Li" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH v2 08/30] MdePkg: Add IOCSR operation for LoongArch Date: Mon, 6 Nov 2023 11:27:55 +0800 Message-Id: <20231106032755.2282083-1-lichao@loongson.cn> In-Reply-To: <20231106032521.2251143-1-lichao@loongson.cn> References: <20231106032521.2251143-1-lichao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxbNw8XUhlHxI6AA--.60845S2 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAGCGVFqihSvgA1s0 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: twMbfaElhJjlHxXBaop6jOJ1x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1699241282855100001 Content-Type: text/plain; charset="utf-8" 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=3D4584 Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Chao Li Acked-by: Michael D Kinney --- 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/Base= Lib.h index 234f3065c2..88ee6e9d51 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -338,6 +338,118 @@ CsrXChg ( IN UINTN Mask ); =20 +/** + 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) =20 // diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 74a323c798..e72724c1c1 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -412,6 +412,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/Ba= seLib/LoongArch64/IoCsr.S new file mode 100644 index 0000000000..4c0009b93a --- /dev/null +++ b/MdePkg/Library/BaseLib/LoongArch64/IoCsr.S @@ -0,0 +1,120 @@ +#-------------------------------------------------------------------------= ----- +# +# LoongArch ASM IO CSR operation functions +# +# Copyright (c) 2023, 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 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110712): https://edk2.groups.io/g/devel/message/110712 Mute This Topic: https://groups.io/mt/102413858/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-