powerpc: consolidate feature fixup code
PATCH 1/5 powerpc: consolidate feature fixup code
There are currently two versions of the functions for applying the feature fixups, one for CPU features and one for firmware features. In addition, they are both in assembly and with separate implementations for 32 and 64 bits. identify_cpu() is also implemented in assembly and separately for 32 and 64 bits.
This patch replaces them with a pair of C functions. The call sites are slightly moved on ppc64 as well to be called from C instead of from assembly, though it's a very small change, and thus shouldn't cause any problem.
arch/powerpc/kernel/head_64.S +0 -19
@@ -1580,11 +1580,6 @@ _STATIC(__start_initialization_iSeries) li r0,0 stdu r0,-STACK_FRAME_OVERHEAD(r1) - LOAD_REG_IMMEDIATE(r3,cpu_specs) - LOAD_REG_IMMEDIATE(r4,cur_cpu_spec) - li r5,0 - bl .identify_cpu - LOAD_REG_IMMEDIATE(r2,__toc_start) addi r2,r2,0x4000 addi r2,r2,0x4000
@@ -1964,13 +1959,6 @@ _STATIC(start_here_multiplatform) addi r2,r2,0x4000 add r2,r2,r26 - LOAD_REG_IMMEDIATE(r3, cpu_specs) - add r3,r3,r26 - LOAD_REG_IMMEDIATE(r4,cur_cpu_spec) - add r4,r4,r26 - mr r5,r26 - bl .identify_cpu - /* Do very early kernel initializations, including initial hash table, * stab and slb setup before we turn on relocation. */
@@ -2000,13 +1988,6 @@ _STATIC(start_here_common) li r0,0 stdu r0,-STACK_FRAME_OVERHEAD(r1) - /* Apply the CPUs-specific fixups (nop out sections not relevant - * to this CPU - */ - li r3,0 - bl .do_cpu_ftr_fixups - bl .do_fw_ftr_fixups - /* ptr to current */ LOAD_REG_IMMEDIATE(r4, init_task) std r4,PACACURRENT(r13)
arch/powerpc/kernel/misc_64.S +0 -124
130 lines not on this page · raw message
arch/powerpc/kernel/setup-common.c +36 -0
@@ -520,3 +520,39 @@ void __init setup_panic(void) {atomic_notifier_chain_register (&panic_notifier_list, &ppc_panic_block); } + +void do_feature_fixups (unsigned long offset,unsigned long value, +void *fixup_start,void *fixup_end) +{ +struct fixup_entry { +unsigned long mask; +unsigned long value; +unsigned int *start; +unsigned int *end; + } *fcur, *fend; + + fcur = fixup_start; + fend = fixup_end; + +for (; fcur < fend; fcur++) { +unsigned int *pstart, *pend, *p; + +if ((value & fcur->mask) == fcur->value) +continue ; + +/* These PTRRELOCs will disappear once the new scheme for +* modules and vdso is implemented +*/ + pstart =PTRRELOC (fcur->start); + pend =PTRRELOC (fcur->end); + +for (p = pstart; p < pend; p++) { + *p =0x60000000u ; + asmvolatile ("dcbst 0, %0" : :"r" (p)); + } + asmvolatile ("sync" : : :"memory" ); +for (p = pstart; p < pend; p++) + asmvolatile ("icbi 0,%0" : :"r" (p)); + asmvolatile ("sync; isync" : : :"memory" ); + } +}
arch/powerpc/kernel/setup.h +6 -3
@@ -1,9 +1,12 @@#ifndef _POWERPC_KERNEL_SETUP_H#define _POWERPC_KERNEL_SETUP_H -void check_for_initrd (void ); -void do_init_bootmem (void ); -void setup_panic (void ); +extern void check_for_initrd (void ); +extern void do_init_bootmem (void ); +extern void setup_panic (void ); +extern void do_feature_fixups (unsigned long offset,unsigned long value, +void *fixup_start,void *fixup_end); +extern int do_early_xmon;#endif /* _POWERPC_KERNEL_SETUP_H */
arch/powerpc/kernel/setup_32.c +7 -2
@@ -90,7 +90,9 @@ int ucache_bsize;*/ unsigned long __init early_init (unsigned long dt_ptr) { +extern unsigned int __start___ftr_fixup, __stop___ftr_fixup;unsigned long offset =reloc_offset (); +struct cpu_spec *spec;/* First zero the BSS -- use memset_io, some platforms don't have * caches on yet */
@@ -100,8 +102,11 @@ unsigned long __init early_init(unsigned* Identify the CPU type and fix up code sections * that depend on which cpu we have. */ -identify_cpu (offset,0 ); -do_cpu_ftr_fixups (offset); + spec =identify_cpu (offset); + +do_feature_fixups (offset, spec->cpu_features, +PTRRELOC (&__start___ftr_fixup), +PTRRELOC (&__stop___ftr_fixup));return KERNELBASE + offset; }
arch/powerpc/kernel/setup_64.c +14 -0
@@ -170,6 +170,9 @@ void __init setup_paca(int cpu)void __init early_setup (unsigned long dt_ptr) { +/* Identify CPU type */ +identify_cpu (0 ); +/* Assume we're on cpu 0 for now. Don't write to the paca yet! */ setup_paca (0 );
@@ -346,8 +349,19 @@ static void __init initialize_cache_info*/ void __init setup_system (void ) { +extern unsigned int __start___ftr_fixup, __stop___ftr_fixup; +extern unsigned int __start___fw_ftr_fixup, __stop___fw_ftr_fixup; +DBG (" -> setup_system()\n" ); +/* Apply the CPUs-specific and firmware specific fixups to kernel +* text (nop out sections not relevant to this CPU or this firmware) +*/ +do_feature_fixups (0 , cur_cpu_spec->cpu_features, + &__start___ftr_fixup, &__stop___ftr_fixup); +do_feature_fixups (0 , powerpc_firmware_features, + &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup); +/* * Unflatten the device-tree passed by prom_init or kexec */
arch/powerpc/kernel/cputable.c +23 -1
@@ -73,7 +73,7 @@ extern void __restore_cpu_ppc970(void);#define PPC_FEATURE_SPE_COMP 0#endif -struct cpu_spec cpu_specs[] = { +static struct cpu_spec cpu_specs[] = { #ifdef CONFIG_PPC64 { /* Power3 */ .pvr_mask = 0xffff0000,
@@ -1152,3 +1152,25 @@ struct cpu_spec cpu_specs[] = {#endif /* !CLASSIC_PPC */ #endif /* CONFIG_PPC32 */ }; + +struct cpu_spec *identify_cpu (unsigned long offset) +{ +struct cpu_spec *s = cpu_specs; +struct cpu_spec **cur = &cur_cpu_spec; +unsigned int pvr =mfspr (SPRN_PVR ); +int i; + + s =PTRRELOC (s); + cur =PTRRELOC (cur); + +if (*cur !=NULL ) +return PTRRELOC (*cur); + +for (i =0 ; i <ARRAY_SIZE (cpu_specs); i++,s++) +if ((pvr & s->pvr_mask) == s->pvr_value) { + *cur = cpu_specs + i; +return s; + } +BUG (); +return NULL ; +}
arch/powerpc/kernel/misc_32.S +0 -74
80 lines not on this page · raw message
include/asm-powerpc/cputable.h +1 -2
@@ -89,8 +89,7 @@ struct cpu_spec {extern struct cpu_spec *cur_cpu_spec; -extern void identify_cpu (unsigned long offset,unsigned long cpu); -extern void do_cpu_ftr_fixups (unsigned long offset); +extern struct cpu_spec *identify_cpu (unsigned long offset);#endif /* __ASSEMBLY__ */
arch/powerpc/platforms/iseries/setup.c +5 -0
@@ -694,6 +694,11 @@ void * __init iSeries_early_setup(void) {unsigned long phys_mem_size; +/* Identify CPU type. This is done again by the common code later +* on but calling this function multiple times is fine. +*/ +identify_cpu (0 ); + powerpc_firmware_features |=FW_FEATURE_ISERIES ; powerpc_firmware_features |=FW_FEATURE_LPAR ;
Quoted 6 lines · On Fri, 20 Oct 2006 11:47:15 +1000 Benjamin Herrenschmidt…
There are currently two versions of the functions for applying the feature fixups, one for CPU features and one for firmware features. In addition, they are both in assembly and with separate implementations for 32 and 64 bits.
identify_cpu()is also implemented in assembly and separately for 32 and 64 bits.
Quoted 6 lines
This patch replaces them with a pair of C functions. The call sites are slightly moved on ppc64 as well to be called from C instead of from assembly, though it's a very small change, and thus shouldn't cause any problem.
Signed-off-by Benjamin Herrenschmidt <[email protected]>
Quoted 10 lines · Benjamin Herrenschmidt
There are currently two versions of the functions for applying the feature fixups, one for CPU features and one for firmware features. In addition, they are both in assembly and with separate implementations for 32 and 64 bits.
identify_cpu()is also implemented in assembly and separately for 32 and 64 bits.This patch replaces them with a pair of C functions. The call sites are slightly moved on ppc64 as well to be called from C instead of from assembly, though it's a very small change, and thus shouldn't cause any problem.
Unfortunately this:
include/asm-powerpc/cputable.h struct cpu_spec { · line 92
Quoted 11 lines
Index:
linux-cell/include/asm-powerpc/cputable.h
===================================================================include/asm-powerpc/cputable.h +1
-2@@ -89,8 +89,7 @@ struct cpu_spec {extern struct cpu_spec *cur_cpu_spec; -extern void identify_cpu (unsigned long offset,unsigned long cpu); -extern void do_cpu_ftr_fixups (unsigned long offset); +extern struct cpu_spec *identify_cpu (unsigned long offset);
... breaks the ARCH=ppc build.
Paul.
Quoted 7 lines
Quoted 7 lines
Index:
linux-cell/include/asm-powerpc/cputable.h
===================================================================include/asm-powerpc/cputable.h +0
-0@@ -89,8 +89,7 @@ struct cpu_spec {
Quoted 7 lines
include/asm-powerpc/cputable.h struct cpu_spec { · line 92
Quoted 5 lines
include/asm-powerpc/cputable.h +1
-2extern struct cpu_spec *cur_cpu_spec; -extern void identify_cpu (unsigned long offset,unsigned long cpu); -extern void do_cpu_ftr_fixups (unsigned long offset); +extern struct cpu_spec *identify_cpu (unsigned long offset);... breaks the ARCH=ppc build.
Gack... I though I tested, I must have screwed up. Should be easy enough to fix though. I'll have a look.
Ben.