Skip to content

Commit

Permalink
LoongArch: Humanize the CRMD line when showing registers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
  • Loading branch information
xen0n authored and chenhuacai committed May 1, 2023
1 parent 05fa8d4 commit efada2a
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion arch/loongarch/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Author: Huacai Chen <[email protected]>
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/compiler.h>
Expand Down Expand Up @@ -153,6 +154,54 @@ static void show_code(unsigned int *pc, bool user)
pr_cont("\n");
}

static void print_bool_fragment(const char *key, unsigned long val, bool first)
{
/* e.g. "+PG", "-DA" */
pr_cont("%s%c%s", first ? "" : " ", val ? '+' : '-', key);
}

static void print_plv_fragment(const char *key, int val)
{
/* e.g. "PLV0", "PPLV3" */
pr_cont("%s%d", key, val);
}

static void print_memory_type_fragment(const char *key, unsigned long val)
{
const char *humanized_type;

switch (val) {
case 0:
humanized_type = "SUC";
break;
case 1:
humanized_type = "CC";
break;
case 2:
humanized_type = "WUC";
break;
default:
pr_cont(" %s=Reserved(%lu)", key, val);
return;
}

/* e.g. " DATM=WUC" */
pr_cont(" %s=%s", key, humanized_type);
}

static void print_crmd(unsigned long x)
{
printk(" CRMD: %08lx (", x);
print_plv_fragment("PLV", (int) FIELD_GET(CSR_CRMD_PLV, x));
print_bool_fragment("IE", FIELD_GET(CSR_CRMD_IE, x), false);
print_bool_fragment("DA", FIELD_GET(CSR_CRMD_DA, x), false);
print_bool_fragment("PG", FIELD_GET(CSR_CRMD_PG, x), false);
print_memory_type_fragment("DACF", FIELD_GET(CSR_CRMD_DACF, x));
print_memory_type_fragment("DACM", FIELD_GET(CSR_CRMD_DACM, x));
print_bool_fragment("WE", FIELD_GET(CSR_CRMD_WE, x), false);
pr_cont(")\n");
}

static void __show_regs(const struct pt_regs *regs)
{
const int field = 2 * sizeof(unsigned long);
Expand Down Expand Up @@ -194,7 +243,7 @@ static void __show_regs(const struct pt_regs *regs)
#undef GPR_FIELD

/* Print saved important CSRs */
printk(" CRMD: %08lx\n", regs->csr_crmd);
print_crmd(regs->csr_crmd);
printk(" PRMD: %08lx\n", regs->csr_prmd);
printk(" EUEN: %08lx\n", regs->csr_euen);
printk(" ECFG: %08lx\n", regs->csr_ecfg);
Expand Down

0 comments on commit efada2a

Please sign in to comment.