Skip to contentSkip to conversation

LoongArch: CSR: Complete KSave registers definition

PATCH Applied Yanteng Si 4 participants 4 messages Jul 25, 2025 – Aug 1, 2025 LoongArch

lore
Share & tools
lore

Yanteng Si

author
#0 lore raw

PATCH 1/1 LoongArch: CSR: Complete KSave registers definition

According to the "LoongArch Reference Manual Volume 1: Basic Architecture", the KSave registers (SAVE0-SAVE15) are defined in section 7.4.16 "Data Save (SAVE)" and listed in Table 7-1 "Control and Status Registers Overview". These registers occupy CSR addresses 0x30 to 0x3F, with 16 registers in total.

This patch complete the definitions of KS9 to KS15 to match the architecture specification.

---
 arch/loongarch/include/asm/loongarch.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/loongarch/include/asm/loongarch.h +7 -0
index a0994d226eff..09dfd7eb406e 100644
@@ -451,6 +451,13 @@
 #define LOONGARCH_CSR_KS6		0x36
 #define LOONGARCH_CSR_KS7		0x37
 #define LOONGARCH_CSR_KS8		0x38
+#define LOONGARCH_CSR_KS9		0x39
+#define LOONGARCH_CSR_KS10		0x3a
+#define LOONGARCH_CSR_KS11		0x3b
+#define LOONGARCH_CSR_KS12		0x3c
+#define LOONGARCH_CSR_KS13		0x3d
+#define LOONGARCH_CSR_KS14		0x3e
+#define LOONGARCH_CSR_KS15		0x3f
 
 /* Exception allocated KS0, KS1 and KS2 statically */
 #define EXCEPTION_KS0			LOONGARCH_CSR_KS0
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw

Hello Yanteng:

As the manual say below,
"The minimum number of data save registers is 1, and the maximum number is 16." I search the prefix pattern "LOONGARCH_CSR_KS" in v6.16 kernel source, the KS0-KS7 has been used, if hardware support it, add it look ok.
<By the way, the KS8 defined is strange, it defined but not used, i don`t know why.>

Note that as manual v1.10 v4.2.1 say:
"When a CSR access instruction accesses a CSR that
is not defined in the architecture or not implemented in hardware, the read operation returns an all 0 values and
the write operation does not modify any software-visible state of the processor."

BRs
Wentao Guan

#2 lore raw
Quoted 8 lines · Wentao Guan

Hello Yanteng:

As the manual say below,
"The minimum number of data save registers is 1, and the maximum number is 16." I search the prefix pattern "LOONGARCH_CSR_KS" in v6.16 kernel source, the KS0-KS7 has been used, if hardware support it, add it look ok.
<By the way, the KS8 defined is strange, it defined but not used, i don`t know why.>

Quoted 5 lines

Note that as manual v1.10 v4.2.1 say:
"When a CSR access instruction accesses a CSR that
is not defined in the architecture or not implemented in hardware, the read operation returns an all 0 values and
the write operation does not modify any software-visible state of the processor."

I understand your concern. Actually, we can obtain it from CSR.PRCFG1.SAVENum, which is clearly stated in the manual.

Quoted 1 line

Thanks for your review!

Thanks,
Yanteng

Quoted 3 lines

BRs
Wentao Guan

maintainer Applied
#3 lore raw
In reply to Yanteng Si

Applied, thanks.

Huacai

Quoted 37 lines · Yanteng Si

According to the "LoongArch Reference Manual Volume 1: Basic Architecture", the KSave registers (SAVE0-SAVE15) are defined in section 7.4.16 "Data Save (SAVE)" and listed in Table 7-1 "Control and Status Registers Overview". These registers occupy CSR addresses 0x30 to 0x3F, with 16 registers in total.

This patch complete the definitions of KS9 to KS15 to match the architecture specification.

---
 arch/loongarch/include/asm/loongarch.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/loongarch/include/asm/loongarch.h +7 -1
index a0994d226eff..09dfd7eb406e 100644
@@ -451,6 +451,13 @@
 #define LOONGARCH_CSR_KS6              0x36
 #define LOONGARCH_CSR_KS7              0x37
 #define LOONGARCH_CSR_KS8              0x38
+#define LOONGARCH_CSR_KS9              0x39
+#define LOONGARCH_CSR_KS10             0x3a
+#define LOONGARCH_CSR_KS11             0x3b
+#define LOONGARCH_CSR_KS12             0x3c
+#define LOONGARCH_CSR_KS13             0x3d
+#define LOONGARCH_CSR_KS14             0x3e
+#define LOONGARCH_CSR_KS15             0x3f
 
 /* Exception allocated KS0, KS1 and KS2 statically */
 #define EXCEPTION_KS0                  LOONGARCH_CSR_KS0
--

2.50.1