On 2019-04-16 16:05:06 Tue, Hari Bathini wrote: > From: Hari Bathini <hbath...@linux.vnet.ibm.com> > > Firmware provides architected register state data at the time of crash. > Process this data and build CPU notes to append to ELF core. > > Signed-off-by: Hari Bathini <hbath...@linux.vnet.ibm.com> > Signed-off-by: Vasant Hegde <hegdevas...@linux.vnet.ibm.com> > --- > > Changes in v2: > * Updated reg type values according to recent OPAL changes > > > arch/powerpc/include/asm/opal-api.h | 23 +++ > arch/powerpc/kernel/fadump-common.h | 3 > arch/powerpc/platforms/powernv/opal-fadump.c | 187 > ++++++++++++++++++++++++-- > arch/powerpc/platforms/powernv/opal-fadump.h | 4 + > 4 files changed, 206 insertions(+), 11 deletions(-) > > diff --git a/arch/powerpc/include/asm/opal-api.h > b/arch/powerpc/include/asm/opal-api.h > index 75471c2..91f2735 100644 > --- a/arch/powerpc/include/asm/opal-api.h > +++ b/arch/powerpc/include/asm/opal-api.h > @@ -976,6 +976,29 @@ struct opal_sg_list { > * Firmware-Assisted Dump (FADump) > */ > > +/* FADump thread header for register entries */ > +struct opal_fadump_thread_hdr { > + __be32 pir; > + /* 0x00 - 0x0F - The corresponding stop state of the core */ > + u8 core_state; > + u8 reserved[3]; > + > + __be32 offset; /* Offset to Register Entries array */ > + __be32 ecnt; /* Number of entries */ > + __be32 esize; /* Alloc size of each array entry in bytes */ > + __be32 eactsz; /* Actual size of each array entry in bytes */ > +} __packed; > + > +#define OPAL_REG_TYPE_GPR 0x01 > +#define OPAL_REG_TYPE_SPR 0x02 > + > +/* FADump register entry. */ > +struct opal_fadump_reg_entry { > + __be32 reg_type; > + __be32 reg_num; > + __be64 reg_val; > +}; > + > /* The maximum number of dump sections supported by OPAL */ > #define OPAL_FADUMP_NR_SECTIONS 64 > > diff --git a/arch/powerpc/kernel/fadump-common.h > b/arch/powerpc/kernel/fadump-common.h > index ff764d4..8d47382 100644 > --- a/arch/powerpc/kernel/fadump-common.h > +++ b/arch/powerpc/kernel/fadump-common.h > @@ -117,6 +117,9 @@ struct fadump_memory_range { > > /* Firmware-assisted dump configuration details. */ > struct fw_dump { > + unsigned long cpu_state_destination_addr; > + unsigned long cpu_state_data_version; > + unsigned long cpu_state_entry_size; > unsigned long cpu_state_data_size; > unsigned long hpte_region_size; > unsigned long boot_memory_size; > diff --git a/arch/powerpc/platforms/powernv/opal-fadump.c > b/arch/powerpc/platforms/powernv/opal-fadump.c > index da8480d..853f663 100644 > --- a/arch/powerpc/platforms/powernv/opal-fadump.c > +++ b/arch/powerpc/platforms/powernv/opal-fadump.c > @@ -94,6 +94,12 @@ static void update_fadump_config(struct fw_dump > *fadump_conf, > > last_end = base + size; > j++; > + } else if (fdm->section[i].src_type == > + OPAL_FADUMP_CPU_STATE_DATA) { > + fadump_conf->cpu_state_destination_addr = > + be64_to_cpu(fdm->section[i].dest_addr); > + fadump_conf->cpu_state_data_size = > + be64_to_cpu(fdm->section[i].dest_size); > } > } > fadump_conf->rmr_regions_cnt = j; > @@ -199,6 +205,75 @@ static int opal_invalidate_fadump(struct fw_dump > *fadump_conf) > return 0; > } > > +static inline void fadump_set_regval_regnum(struct pt_regs *regs, u32 > reg_type, > + u32 reg_num, u64 reg_val) > +{ > + if (reg_type == OPAL_REG_TYPE_GPR) { > + if (reg_num < 32) > + regs->gpr[reg_num] = reg_val; > + return; > + } > + > + switch (reg_num) { > + case 2000: > + regs->nip = reg_val; > + break; > + case 2001: > + regs->msr = reg_val; > + break; > + case 9: > + regs->ctr = reg_val; > + break; > + case 8: > + regs->link = reg_val; > + break; > + case 1: > + regs->xer = reg_val; > + break; > + case 2002: > + regs->ccr = reg_val; > + break; > + case 19: > + regs->dar = reg_val; > + break; > + case 18: > + regs->dsisr = reg_val; > + break;
Can we use SPRN_* #defines which are already present in asm/reg.h instead of hard coding numbers for switch cases ? You may want to add new #defines for NIP, MSR and CCR. Thanks, -Mahesh.