Skip to content

Commit efada2a

Browse files
xen0nchenhuacai
authored andcommitted
LoongArch: Humanize the CRMD line when showing registers
Example output looks like: [ xx.xxxxxx] CRMD: 000000b0 (PLV0 -IE -DA +PG DACF=CC DACM=CC -WE) Some initial machinery for this pretty-printing format has been included in this patch as well. Signed-off-by: WANG Xuerui <git@xen0n.name> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 05fa8d4 commit efada2a

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

arch/loongarch/kernel/traps.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Author: Huacai Chen <chenhuacai@loongson.cn>
44
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
55
*/
6+
#include <linux/bitfield.h>
67
#include <linux/bitops.h>
78
#include <linux/bug.h>
89
#include <linux/compiler.h>
@@ -153,6 +154,54 @@ static void show_code(unsigned int *pc, bool user)
153154
pr_cont("\n");
154155
}
155156

157+
static void print_bool_fragment(const char *key, unsigned long val, bool first)
158+
{
159+
/* e.g. "+PG", "-DA" */
160+
pr_cont("%s%c%s", first ? "" : " ", val ? '+' : '-', key);
161+
}
162+
163+
static void print_plv_fragment(const char *key, int val)
164+
{
165+
/* e.g. "PLV0", "PPLV3" */
166+
pr_cont("%s%d", key, val);
167+
}
168+
169+
static void print_memory_type_fragment(const char *key, unsigned long val)
170+
{
171+
const char *humanized_type;
172+
173+
switch (val) {
174+
case 0:
175+
humanized_type = "SUC";
176+
break;
177+
case 1:
178+
humanized_type = "CC";
179+
break;
180+
case 2:
181+
humanized_type = "WUC";
182+
break;
183+
default:
184+
pr_cont(" %s=Reserved(%lu)", key, val);
185+
return;
186+
}
187+
188+
/* e.g. " DATM=WUC" */
189+
pr_cont(" %s=%s", key, humanized_type);
190+
}
191+
192+
static void print_crmd(unsigned long x)
193+
{
194+
printk(" CRMD: %08lx (", x);
195+
print_plv_fragment("PLV", (int) FIELD_GET(CSR_CRMD_PLV, x));
196+
print_bool_fragment("IE", FIELD_GET(CSR_CRMD_IE, x), false);
197+
print_bool_fragment("DA", FIELD_GET(CSR_CRMD_DA, x), false);
198+
print_bool_fragment("PG", FIELD_GET(CSR_CRMD_PG, x), false);
199+
print_memory_type_fragment("DACF", FIELD_GET(CSR_CRMD_DACF, x));
200+
print_memory_type_fragment("DACM", FIELD_GET(CSR_CRMD_DACM, x));
201+
print_bool_fragment("WE", FIELD_GET(CSR_CRMD_WE, x), false);
202+
pr_cont(")\n");
203+
}
204+
156205
static void __show_regs(const struct pt_regs *regs)
157206
{
158207
const int field = 2 * sizeof(unsigned long);
@@ -194,7 +243,7 @@ static void __show_regs(const struct pt_regs *regs)
194243
#undef GPR_FIELD
195244

196245
/* Print saved important CSRs */
197-
printk(" CRMD: %08lx\n", regs->csr_crmd);
246+
print_crmd(regs->csr_crmd);
198247
printk(" PRMD: %08lx\n", regs->csr_prmd);
199248
printk(" EUEN: %08lx\n", regs->csr_euen);
200249
printk(" ECFG: %08lx\n", regs->csr_ecfg);

0 commit comments

Comments
 (0)