Acked-by: Michael D Kinney <michael.d.kin...@intel.com> > -----Original Message----- > From: Chao Li <lic...@loongson.cn> > Sent: Sunday, November 5, 2023 7:28 PM > To: devel@edk2.groups.io > Cc: Kinney, Michael D <michael.d.kin...@intel.com>; Gao, Liming > <gaolim...@byosoft.com.cn>; Liu, Zhiguang <zhiguang....@intel.com> > Subject: [PATCH v2 08/30] MdePkg: Add IOCSR operation for LoongArch > > 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 <michael.d.kin...@intel.com> > Cc: Liming Gao <gaolim...@byosoft.com.cn> > Cc: Zhiguang Liu <zhiguang....@intel.com> > Signed-off-by: Chao Li <lic...@loongson.cn> > --- > 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 234f3065c2..88ee6e9d51 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -338,6 +338,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 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/BaseLib/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.<BR> > +# > +# 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 (#110795): https://edk2.groups.io/g/devel/message/110795 Mute This Topic: https://groups.io/mt/102413858/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/9847357/21656/1706620634/xyzzy [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-