target/ppc: Drop PowerPCCPUClass::interrupts_big_endian()
cover target/ppc: Drop PowerPCCPUClass::interrupts_big_endian()
Class method is overkill and cause code duplication in CPU setup functions. Switch to a more lightweight solution with a unique inline helper.
Greg Kurz (2):
target/ppc: Introduce ppc_interrupts_little_endian() target/ppc: Drop PowerPCCPUClass::interrupts_big_endian()
target/ppc/cpu-qom.h | 1 - target/ppc/cpu.h | 15 +++++++++++++++ target/ppc/arch_dump.c | 8 +++----- target/ppc/cpu_init.c | 17 ----------------- target/ppc/excp_helper.c | 3 +-- 5 files changed, 19 insertions(+), 25 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 target/ppc: Introduce ppc_interrupts_little_endian()
PowerPC CPUs use big endian by default but starting with POWER7, server grade CPUs use the ILE bit of the LPCR special purpose register to decide on the endianness to use when handling interrupts. This gives a clue to QEMU on the endianness the guest kernel is running, which is needed when generating an ELF dump of the guest or when delivering an FWNMI machine check interrupt.
Commit 382d2db62bcb ("target-ppc: Introduce callback for interrupt endianness") added a class method to PowerPCCPUClass to modelize this : default implementation returns a fixed "big endian" value, while POWER7 and newer do the LPCR_ILE check. This is suboptimal as it forces to implement the method for every new CPU family, and it is very unlikely that this will ever be different than what we have today.
We basically only have three cases to consider:
a) CPU doesn't have an LPCR => big endian
b) CPU has an LPCR but doesn't support the ILE bit => big endian
c) CPU has an LPCR and supports the ILE bit => little or big endian
Instead of class methods, introduce an inline helper that checks the ILE bit in the LPCR_MASK to decide on the outcome. The new helper words little endian instead of big endian. This allows to drop a ! operator in ppc_cpu_do_fwnmi_machine_check().
--- target/ppc/cpu.h | 15 +++++++++++++++ target/ppc/arch_dump.c | 8 +++----- target/ppc/excp_helper.c | 3 +-- 3 files changed, 19 insertions(+), 7 deletions(-)
target/ppc/cpu.h +15 -0
@@ -2643,6 +2643,21 @@ static inline bool ppc_has_spr(PowerPCCPU *cpu, int spr)return cpu->env.spr_cb[spr].name !=NULL ; } +static inline bool ppc_interrupts_little_endian (PowerPCCPU *cpu) +{ +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); + +/* +* Only models that have an LPCR and know about LPCR_ILE can do little +* endian. +*/ +if (pcc->lpcr_mask &LPCR_ILE ) { +return !!(cpu->env.spr[SPR_LPCR ] &LPCR_ILE ); + } + +return false; +} +void dump_mmu (CPUPPCState *env);void ppc_maybe_bswap_register (CPUPPCState *env,uint8_t *mem_buf,int len);
target/ppc/arch_dump.c +3 -5
@@ -227,22 +227,20 @@ int cpu_get_dump_info(ArchDumpInfo *info, const struct GuestPhysBlockList *guest_phys_blocks) {PowerPCCPU *cpu; -PowerPCCPUClass *pcc;if (first_cpu ==NULL ) {return -1 ; } cpu =POWERPC_CPU (first_cpu); - pcc =POWERPC_CPU_GET_CLASS (cpu); info->d_machine =PPC_ELF_MACHINE ; info->d_class =ELFCLASS ; -if ((*pcc->interrupts_big_endian)(cpu)) { - info->d_endian =ELFDATA2MSB ; - }else { +if (ppc_interrupts_little_endian (cpu)) { info->d_endian =ELFDATA2LSB ; + }else { + info->d_endian =ELFDATA2MSB ; }/* 64KB is the max page size for pseries kernel */ if (strncmp(object_get_typename(qdev_get_machine()),
target/ppc/excp_helper.c +1 -2
@@ -1099,7 +1099,6 @@ void ppc_cpu_do_fwnmi_machine_check(CPUState *cs, target_ulong vector) {PowerPCCPU *cpu =POWERPC_CPU (cs);CPUPPCState *env = &cpu->env; -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);target_ulong msr =0 ;/*
@@ -1108,7 +1107,7 @@ void ppc_cpu_do_fwnmi_machine_check(CPUState *cs, target_ulong vector)*/ msr = (1ULL <<MSR_ME ); msr |= env->msr & (1ULL <<MSR_SF ); -if (!(*pcc->interrupts_big_endian)(cpu)) { +if (ppc_interrupts_little_endian (cpu)) { msr |= (1ULL <<MSR_LE ); }
Signature · 1 line
2.31.1
Re: [PATCH 1/2] target/ppc: Introduce ppc_interrupts_little_endian()
Quoted 21 lines · Greg Kurz
PowerPC CPUs use big endian by default but starting with POWER7, server grade CPUs use the ILE bit of the LPCR special purpose register to decide on the endianness to use when handling interrupts. This gives a clue to QEMU on the endianness the guest kernel is running, which is needed when generating an ELF dump of the guest or when delivering an FWNMI machine check interrupt.
Commit
382d2db62bcb("target-ppc: Introduce callback for interrupt endianness") added a class method to PowerPCCPUClass to modelize this : default implementation returns a fixed "big endian" value, while POWER7 and newer do theLPCR_ILEcheck. This is suboptimal as it forces to implement the method for every new CPU family, and it is very unlikely that this will ever be different than what we have today.We basically only have three cases to consider:
a) CPU doesn't have an LPCR => big endian
b) CPU has an LPCR but doesn't support the ILE bit => big endian
c) CPU has an LPCR and supports the ILE bit => little or big endian
Quoted 6 lines
Instead of class methods, introduce an inline helper that checks the ILE bit in the
LPCR_MASKto decide on the outcome. The new helper words little endian instead of big endian. This allows to drop a ! operator inppc_cpu_do_fwnmi_machine_check().Signed-off-by Greg Kurz <[email protected]>
Quoted 82 lines
--- target/ppc/cpu.h | 15 +++++++++++++++ target/ppc/arch_dump.c | 8 +++----- target/ppc/excp_helper.c | 3 +-- 3 files changed, 19 insertions(+), 7 deletions(-)target/ppc/cpu.h +15
-0@@ -2643,6 +2643,21 @@ static inline bool ppc_has_spr(PowerPCCPU *cpu, int spr)return cpu->env.spr_cb[spr].name !=NULL ; } +static inline bool ppc_interrupts_little_endian (PowerPCCPU *cpu) +{ +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); + +/* +* Only models that have an LPCR and know about LPCR_ILE can do little +* endian. +*/ +if (pcc->lpcr_mask &LPCR_ILE ) { +return !!(cpu->env.spr[SPR_LPCR ] &LPCR_ILE ); + } + +return false; +} +void dump_mmu (CPUPPCState *env);void ppc_maybe_bswap_register (CPUPPCState *env,uint8_t *mem_buf,int len);target/ppc/arch_dump.c +3
-5@@ -227,22 +227,20 @@ int cpu_get_dump_info(ArchDumpInfo *info, const struct GuestPhysBlockList *guest_phys_blocks) {PowerPCCPU *cpu; -PowerPCCPUClass *pcc;if (first_cpu ==NULL ) {return -1 ; } cpu =POWERPC_CPU (first_cpu); - pcc =POWERPC_CPU_GET_CLASS (cpu); info->d_machine =PPC_ELF_MACHINE ; info->d_class =ELFCLASS ; -if ((*pcc->interrupts_big_endian)(cpu)) { - info->d_endian =ELFDATA2MSB ; - }else { +if (ppc_interrupts_little_endian (cpu)) { info->d_endian =ELFDATA2LSB ; + }else { + info->d_endian =ELFDATA2MSB ; }/* 64KB is the max page size for pseries kernel */ if (strncmp(object_get_typename(qdev_get_machine()),target/ppc/excp_helper.c +1
-2@@ -1099,7 +1099,6 @@ void ppc_cpu_do_fwnmi_machine_check(CPUState *cs, target_ulong vector) {PowerPCCPU *cpu =POWERPC_CPU (cs);CPUPPCState *env = &cpu->env; -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);target_ulong msr =0 ;/* @@ -1108,7 +1107,7 @@ void ppc_cpu_do_fwnmi_machine_check(CPUState *cs, target_ulong vector)*/ msr = (1ULL <<MSR_ME ); msr |= env->msr & (1ULL <<MSR_SF ); -if (!(*pcc->interrupts_big_endian)(cpu)) { +if (ppc_interrupts_little_endian (cpu)) { msr |= (1ULL <<MSR_LE ); }
PATCH 2/2 target/ppc: Drop PowerPCCPUClass::interrupts_big_endian()
In reply to Greg KurzThis isn't used anymore.
--- target/ppc/cpu-qom.h | 1 - target/ppc/cpu_init.c | 17 ----------------- 2 files changed, 18 deletions(-)
target/ppc/cpu-qom.h +0 -1
@@ -199,7 +199,6 @@ struct PowerPCCPUClass {void (*init_proc)(CPUPPCState *env);int (*check_pow)(CPUPPCState *env);int (*handle_mmu_fault)(PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx); -bool (*interrupts_big_endian)(PowerPCCPU *cpu); };#ifndef CONFIG_USER_ONLY
target/ppc/cpu_init.c +0 -17
@@ -2666,18 +2666,6 @@ static int check_pow_hid0_74xx(CPUPPCState *env)return 0 ; } -static bool ppc_cpu_interrupts_big_endian_always (PowerPCCPU *cpu) -{ -return true; -} - -#ifdef TARGET_PPC64 -static bool ppc_cpu_interrupts_big_endian_lpcr (PowerPCCPU *cpu) -{ -return !(cpu->env.spr[SPR_LPCR ] &LPCR_ILE ); -} -#endif -/*****************************************************************************/ /* PowerPC implementations definitions */
@@ -7740,7 +7728,6 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }static void init_proc_POWER8 (CPUPPCState *env)
@@ -7918,7 +7905,6 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX |POWERPC_FLAG_TM ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }#ifdef CONFIG_SOFTMMU
@@ -8136,7 +8122,6 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX |POWERPC_FLAG_TM |POWERPC_FLAG_SCV ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }#ifdef CONFIG_SOFTMMU
@@ -8347,7 +8332,6 @@ POWERPC_FAMILY(POWER10)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX |POWERPC_FLAG_TM |POWERPC_FLAG_SCV ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }#if !defined(CONFIG_USER_ONLY )
@@ -9094,7 +9078,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)device_class_set_parent_unrealize (dc, ppc_cpu_unrealize, &pcc->parent_unrealize); pcc->pvr_match = ppc_pvr_match_default; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always;device_class_set_props (dc, ppc_cpu_properties);device_class_set_parent_reset (dc, ppc_cpu_reset, &pcc->parent_reset);
Signature · 1 line
2.31.1
Quoted 3 lines · Greg Kurz
This isn't used anymore.
Signed-off-by Greg Kurz <[email protected]>
Quoted 80 lines
--- target/ppc/cpu-qom.h | 1 - target/ppc/cpu_init.c | 17 ----------------- 2 files changed, 18 deletions(-)target/ppc/cpu-qom.h +0
-1@@ -199,7 +199,6 @@ struct PowerPCCPUClass {void (*init_proc)(CPUPPCState *env);int (*check_pow)(CPUPPCState *env);int (*handle_mmu_fault)(PowerPCCPU *cpu,vaddr eaddr,int rwx,int mmu_idx); -bool (*interrupts_big_endian)(PowerPCCPU *cpu); };#ifndef CONFIG_USER_ONLY target/ppc/cpu_init.c +0
-17@@ -2666,18 +2666,6 @@ static int check_pow_hid0_74xx(CPUPPCState *env)return 0 ; } -static bool ppc_cpu_interrupts_big_endian_always (PowerPCCPU *cpu) -{ -return true; -} - -#ifdef TARGET_PPC64 -static bool ppc_cpu_interrupts_big_endian_lpcr (PowerPCCPU *cpu) -{ -return !(cpu->env.spr[SPR_LPCR ] &LPCR_ILE ); -} -#endif -/*****************************************************************************/ /* PowerPC implementations definitions */ @@ -7740,7 +7728,6 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }static void init_proc_POWER8 (CPUPPCState *env)@@ -7918,7 +7905,6 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX |POWERPC_FLAG_TM ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }#ifdef CONFIG_SOFTMMU @@ -8136,7 +8122,6 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX |POWERPC_FLAG_TM |POWERPC_FLAG_SCV ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }#ifdef CONFIG_SOFTMMU @@ -8347,7 +8332,6 @@ POWERPC_FAMILY(POWER10)(ObjectClass *oc, void *data)POWERPC_FLAG_VSX |POWERPC_FLAG_TM |POWERPC_FLAG_SCV ; pcc->l1_dcache_size =0x8000 ; pcc->l1_icache_size =0x8000 ; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr; }#if !defined(CONFIG_USER_ONLY )@@ -9094,7 +9078,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)device_class_set_parent_unrealize (dc, ppc_cpu_unrealize, &pcc->parent_unrealize); pcc->pvr_match = ppc_pvr_match_default; - pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always;device_class_set_props (dc, ppc_cpu_properties);device_class_set_parent_reset (dc, ppc_cpu_reset, &pcc->parent_reset);
Quoted 2 lines · Greg Kurz
Class method is overkill and cause code duplication in CPU setup functions. Switch to a more lightweight solution with a unique inline helper.
LGTM, applied to ppc-for-6.1, thanks.
Quoted 12 lines
Greg Kurz (2):
target/ppc: Introduceppc_interrupts_little_endian()target/ppc: DropPowerPCCPUClass::interrupts_big_endian()target/ppc/cpu-qom.h | 1 - target/ppc/cpu.h | 15 +++++++++++++++ target/ppc/arch_dump.c | 8 +++----- target/ppc/cpu_init.c | 17 ----------------- target/ppc/excp_helper.c | 3 +-- 5 files changed, 19 insertions(+), 25 deletions(-)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson