[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240926065422.226518-2-nick.hu@sifive.com>
Date: Thu, 26 Sep 2024 14:54:16 +0800
From: Nick Hu <nick.hu@...ive.com>
To: greentime.hu@...ive.com,
zong.li@...ive.com,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Pavel Machek <pavel@....cz>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Thomas Gleixner <tglx@...utronix.de>,
Anup Patel <anup@...infault.org>,
Andrew Jones <ajones@...tanamicro.com>,
Mayuresh Chitale <mchitale@...tanamicro.com>,
Conor Dooley <conor.dooley@...rochip.com>,
Atish Patra <atishp@...osinc.com>,
Samuel Ortiz <sameo@...osinc.com>,
Samuel Holland <samuel.holland@...ive.com>,
Nick Hu <nick.hu@...ive.com>,
Sunil V L <sunilvl@...tanamicro.com>,
linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org,
linux-pm@...r.kernel.org
Subject: [PATCH v2 1/3] riscv: Add csr_read/write_hi_lo support
In RV32, we may have the need to read both low 32 bit and high 32 bit of
the CSR. Therefore adding the csr_read_hi_lo() and csr_write_hi_lo() to
support such case.
Suggested-by: Andrew Jones <ajones@...tanamicro.com>
Suggested-by: Zong Li <zong.li@...ive.com>
Signed-off-by: Nick Hu <nick.hu@...ive.com>
---
arch/riscv/include/asm/csr.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 25966995da04..54198284eb22 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -501,6 +501,17 @@
__v; \
})
+#if __riscv_xlen < 64
+#define csr_read_hi_lo(csr) \
+({ \
+ u32 hi = csr_read(csr##H); \
+ u32 lo = csr_read(csr); \
+ lo | ((u64)hi << 32); \
+})
+#else
+#define csr_read_hi_lo csr_read
+#endif
+
#define csr_write(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
@@ -509,6 +520,17 @@
: "memory"); \
})
+#if __riscv_xlen < 64
+#define csr_write_hi_lo(csr, val) \
+({ \
+ u64 _v = (u64)(val); \
+ csr_write(csr##H, (_v) >> 32); \
+ csr_write(csr, (_v)); \
+})
+#else
+#define csr_write_hi_lo csr_write
+#endif
+
#define csr_read_set(csr, val) \
({ \
unsigned long __v = (unsigned long)(val); \
--
2.34.1
Powered by blists - more mailing lists