Files
system76-edk2/MdePkg/Library/BaseLib/LoongArch64/Csr.c
Chao Li 0565a8e885 MdePkg: Add CSR operation for LoongArch
Add CsrRead, CsrWrite and CsrXChg functions for LoongArch, and use them
to operate the CSR register of LoongArch architecture.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Chao Li <lichao@loongson.cn>
Co-authored-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2024-02-06 23:51:47 +08:00

82 lines
1.6 KiB
C

/** @file
LoongArch CSR operation functions.
Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
UINTN
AsmCsrRead (
IN UINT16 Select
);
UINTN
AsmCsrWrite (
IN UINT16 Select,
IN UINTN Value
);
UINTN
AsmCsrXChg (
IN UINT16 Select,
IN UINTN Value,
IN UINTN Mask
);
/**
CSR read operation.
@param[in] Select CSR read instruction select values.
@return The return value of csrrd instruction, return -1 means Select is out of support.
**/
UINTN
EFIAPI
CsrRead (
IN UINT16 Select
)
{
return AsmCsrRead (Select);
}
/**
CSR write operation.
@param[in] Select CSR write instruction select values.
@param[in, out] Value The csrwr will write the value.
@return The return value of csrwr instruction, that is, store the old value of
the register, return -1 means Select is out of support.
**/
UINTN
EFIAPI
CsrWrite (
IN UINT16 Select,
IN OUT UINTN Value
)
{
return AsmCsrWrite (Select, Value);
}
/**
CSR exchange operation.
@param[in] Select CSR exchange instruction select values.
@param[in, out] Value The csrxchg will write the value.
@param[in] Mask The csrxchg mask value.
@return The return value of csrxchg instruction, that is, store the old value of
the register, return -1 means Select is out of support.
**/
UINTN
EFIAPI
CsrXChg (
IN UINT16 Select,
IN OUT UINTN Value,
IN UINTN Mask
)
{
return AsmCsrXChg (Select, Value, Mask);
}