MIPS: Loongson: new features and improvements
Subsystems (7)
cover MIPS: Loongson: new features and improvements
This patchset is is prepared for the next 4.14 release for Linux/MIPS. It enable Loongson-3's SFB at runtime, adds "model name" and "CPU MHz" knobs in /proc/cpuinfo which is needed by some userspace tools, adds Loongson-3 kexec/kdump and CPUFreq support, fixes pmd_present() and indexed scache flushing for Loongson-3, and introduces WAR_LLSC_MB to improve stability.
Huacai Chen(8):
MIPS: Loongson-3: Enable Store Fill Buffer at runtime.
MIPS: c-r4k: Add r4k_blast_scache_node for Loongson-3.
MIPS: Ensure pmd_present() returns false after pmd_mknotpresent().
MIPS: Add __cpu_full_name[] to make CPU names more human-readable.
MIPS: Align kernel load address to 64KB.
MIPS: Loongson: Add kexec/kdump support.
MIPS: Loongson: Make CPUFreq usable for Loongson-3.
MIPS: Loongson: Introduce and use WAR_LLSC_MB.
--- arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | 5 +- arch/mips/include/asm/atomic.h | 18 +- arch/mips/include/asm/barrier.h | 6 + arch/mips/include/asm/bitops.h | 15 ++ arch/mips/include/asm/cmpxchg.h | 9 +- arch/mips/include/asm/cpu-info.h | 2 + arch/mips/include/asm/edac.h | 5 +- arch/mips/include/asm/futex.h | 18 +- arch/mips/include/asm/io.h | 2 +- arch/mips/include/asm/local.h | 10 +- arch/mips/include/asm/mach-loongson64/boot_param.h | 1 + .../asm/mach-loongson64/kernel-entry-init.h | 38 ++-- arch/mips/include/asm/mach-loongson64/loongson.h | 1 + arch/mips/include/asm/mipsregs.h | 2 + arch/mips/include/asm/pgtable-64.h | 5 + arch/mips/include/asm/pgtable.h | 5 +- arch/mips/include/asm/r4kcache.h | 34 +++ arch/mips/include/asm/time.h | 2 + arch/mips/kernel/cpu-probe.c | 25 ++- arch/mips/kernel/proc.c | 6 + arch/mips/kernel/relocate_kernel.S | 30 +++ arch/mips/kernel/smp.c | 3 +- arch/mips/kernel/syscall.c | 2 + arch/mips/kernel/time.c | 2 + arch/mips/loongson64/Kconfig | 1 + arch/mips/loongson64/Platform | 3 + arch/mips/loongson64/common/env.c | 21 ++ arch/mips/loongson64/common/platform.c | 13 +- arch/mips/loongson64/common/reset.c | 119 +++++++++++ arch/mips/loongson64/loongson-3/Makefile | 2 +- arch/mips/loongson64/loongson-3/clock.c | 191 +++++++++++++++++ arch/mips/loongson64/loongson-3/smp.c | 5 + arch/mips/loongson64/loongson-3/smp.h | 1 + arch/mips/mm/c-r4k.c | 42 +++- arch/mips/mm/tlbex.c | 11 + drivers/cpufreq/Kconfig | 15 ++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/loongson3_cpufreq.c | 236 +++++++++++++++++++++ 38 files changed, 855 insertions(+), 52 deletions(-) create mode 100644 arch/mips/loongson64/loongson-3/clock.c create mode 100644 drivers/cpufreq/loongson3_cpufreq.c
--
2.7.0
PATCH 1/8 MIPS: Loongson-3: Enable Store Fill Buffer at runtime
New Loongson-3 (Loongson-3A R2, Loongson-3A R3, and newer) has SFB (Store Fill Buffer) which can improve the performance of memory access. Now, SFB enablement is controlled by CONFIG_LOONGSON3_ENHANCEMENT, and the generic kernel has no benefit from SFB (even it is running on a new Loongson-3 machine). With this patch, we can enable SFB at runtime by detecting the CPU type (the expense is war_io_reorder_wmb() will always be a 'sync', which will hurt the performance of old Loongson-3).
--- arch/mips/include/asm/io.h | 2 +- .../asm/mach-loongson64/kernel-entry-init.h | 38 +++++++++++++--------- arch/mips/include/asm/mipsregs.h | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-)
arch/mips/include/asm/io.h +1 -1
@@ -304,7 +304,7 @@ static inline void iounmap(const volatile void __iomem *addr)#undef __IS_KSEG1 } -#if defined(CONFIG_CPU_CAVIUM_OCTEON ) || defined(CONFIG_LOONGSON3_ENHANCEMENT ) +#if defined(CONFIG_CPU_CAVIUM_OCTEON ) || defined(CONFIG_CPU_LOONGSON3 )#define war_io_reorder_wmb () wmb()#else #define war_io_reorder_wmb () do { } while (0)
arch/mips/include/asm/mach-loongson64/kernel-entry-init.h +22 -16
@@ -19,19 +19,22 @@ .set push .set mips64/* Set LPA on LOONGSON3 config3 */ - mfc0 t0, $16, 3 + mfc0 t0, CP0_CONFIG3 or t0, (0x1 << 7) - mtc0 t0, $16, 3 + mtc0 t0, CP0_CONFIG3/* Set ELPA on LOONGSON3 pagegrain */ - mfc0 t0, $5, 1 + mfc0 t0, CP0_PAGEGRAIN or t0, (0x1 << 29) - mtc0 t0, $5, 1 -#ifdef CONFIG_LOONGSON3_ENHANCEMENT + mtc0 t0, CP0_PAGEGRAIN/* Enable STFill Buffer */ - mfc0 t0, $16, 6 + mfc0 t0, CP0_PRID + andi t0, 0xffff + slti t0, 0x6308 + bnez t0, 1f + mfc0 t0, CP0_CONFIG6 or t0, 0x100 - mtc0 t0, $16, 6 -#endif + mtc0 t0, CP0_CONFIG6 +1: _ehb .set pop #endif
@@ -45,19 +48,22 @@ .set push .set mips64/* Set LPA on LOONGSON3 config3 */ - mfc0 t0, $16, 3 + mfc0 t0, CP0_CONFIG3 or t0, (0x1 << 7) - mtc0 t0, $16, 3 + mtc0 t0, CP0_CONFIG3/* Set ELPA on LOONGSON3 pagegrain */ - mfc0 t0, $5, 1 + mfc0 t0, CP0_PAGEGRAIN or t0, (0x1 << 29) - mtc0 t0, $5, 1 -#ifdef CONFIG_LOONGSON3_ENHANCEMENT + mtc0 t0, CP0_PAGEGRAIN/* Enable STFill Buffer */ - mfc0 t0, $16, 6 + mfc0 t0, CP0_PRID + andi t0, 0xffff + slti t0, 0x6308 + bnez t0, 1f + mfc0 t0, CP0_CONFIG6 or t0, 0x100 - mtc0 t0, $16, 6 -#endif + mtc0 t0, CP0_CONFIG6 +1: _ehb .set pop #endif
arch/mips/include/asm/mipsregs.h +2 -0
@@ -50,6 +50,7 @@#define CP0_CONF $3#define CP0_CONTEXT $4#define CP0_PAGEMASK $5 +#define CP0_PAGEGRAIN $5, 1#define CP0_SEGCTL0 $5, 2#define CP0_SEGCTL1 $5, 3#define CP0_SEGCTL2 $5, 4
@@ -76,6 +77,7 @@#define CP0_CONFIG $16#define CP0_CONFIG3 $16, 3#define CP0_CONFIG5 $16, 5 +#define CP0_CONFIG6 $16, 6#define CP0_LLADDR $17#define CP0_WATCHLO $18#define CP0_WATCHHI $19
Signature · 1 line
2.7.0
Re: [PATCH 1/8] MIPS: Loongson-3: Enable Store Fill Buffer at runtime
Quoted 34 lines · Huacai Chen
New Loongson-3 (Loongson-3A R2, Loongson-3A R3, and newer) has SFB (Store Fill Buffer) which can improve the performance of memory access. Now, SFB enablement is controlled by
CONFIG_LOONGSON3_ENHANCEMENT, and the generic kernel has no benefit from SFB (even it is running on a new Loongson-3 machine). With this patch, we can enable SFB at runtime by detecting the CPU type (the expense iswar_io_reorder_wmb()will always be a 'sync', which will hurt the performance of old Loongson-3).Signed-off-by Huacai Chen <[email protected]>--- arch/mips/include/asm/io.h | 2 +- .../asm/mach-loongson64/kernel-entry-init.h | 38 +++++++++++++--------- arch/mips/include/asm/mipsregs.h | 2 ++ 3 files changed, 25 insertions(+), 17 deletions(-)arch/mips/include/asm/io.h +1
-1@@ -304,7 +304,7 @@ static inline void iounmap(const volatile void __iomem *addr)#undef __IS_KSEG1 } -#if defined(CONFIG_CPU_CAVIUM_OCTEON ) || defined(CONFIG_LOONGSON3_ENHANCEMENT ) +#if defined(CONFIG_CPU_CAVIUM_OCTEON ) || defined(CONFIG_CPU_LOONGSON3 )#define war_io_reorder_wmb () wmb()#else #define war_io_reorder_wmb () do { } while (0)arch/mips/include/asm/mach-loongson64/kernel-entry-init.h +0
-0@@ -19,19 +19,22 @@ .set push
arch/mips/include/asm/mach-loongson64/kernel-entry-init.h line 26
Quoted 10 lines
arch/mips/include/asm/mach-loongson64/kernel-entry-init.h +3
-3.set mips64 /* Set LPA on LOONGSON3 config3 */ - mfc0 t0, $16, 3 +mfc0 t0,CP0_CONFIG3 or t0, (0x1 << 7) - mtc0 t0, $16, 3 + mtc0 t0, CP0_CONFIG3/* Set ELPA on LOONGSON3 pagegrain */ - mfc0 t0, $5, 1 + mfc0 t0, CP0_PAGEGRAIN
Please don't mix cleanups with functional changes.
Separately, both the cleanup and the main change look good to me.
Cheers
James
Quoted 76 lines
arch/mips/include/asm/mach-loongson64/kernel-entry-init.h +19
-13or t0, (0x1 << 29) - mtc0 t0, $5, 1 -#ifdef CONFIG_LOONGSON3_ENHANCEMENT + mtc0 t0, CP0_PAGEGRAIN /* Enable STFill Buffer */ - mfc0 t0, $16, 6 + mfc0 t0, CP0_PRID + andi t0, 0xffff + slti t0, 0x6308 + bnez t0, 1f + mfc0 t0, CP0_CONFIG6 or t0, 0x100 - mtc0 t0, $16, 6 -#endif + mtc0 t0, CP0_CONFIG6 +1: _ehb .set pop#endif @@ -45,19 +48,22 @@ .set push .set mips64/* Set LPA on LOONGSON3 config3 */ - mfc0 t0, $16, 3 + mfc0 t0, CP0_CONFIG3 or t0, (0x1 << 7) - mtc0 t0, $16, 3 + mtc0 t0, CP0_CONFIG3/* Set ELPA on LOONGSON3 pagegrain */ - mfc0 t0, $5, 1 + mfc0 t0, CP0_PAGEGRAIN or t0, (0x1 << 29) - mtc0 t0, $5, 1 -#ifdef CONFIG_LOONGSON3_ENHANCEMENT + mtc0 t0, CP0_PAGEGRAIN/* Enable STFill Buffer */ - mfc0 t0, $16, 6 + mfc0 t0, CP0_PRID + andi t0, 0xffff + slti t0, 0x6308 + bnez t0, 1f + mfc0 t0, CP0_CONFIG6 or t0, 0x100 - mtc0 t0, $16, 6 -#endif + mtc0 t0, CP0_CONFIG6 +1: _ehb .set pop #endifarch/mips/include/asm/mipsregs.h +2
-0@@ -50,6 +50,7 @@#define CP0_CONF $3#define CP0_CONTEXT $4#define CP0_PAGEMASK $5 +#define CP0_PAGEGRAIN $5, 1#define CP0_SEGCTL0 $5, 2#define CP0_SEGCTL1 $5, 3#define CP0_SEGCTL2 $5, 4@@ -76,6 +77,7 @@#define CP0_CONFIG $16#define CP0_CONFIG3 $16, 3#define CP0_CONFIG5 $16, 5 +#define CP0_CONFIG6 $16, 6#define CP0_LLADDR $17#define CP0_WATCHLO $18#define CP0_WATCHHI $19Signature · 1 line
2.7.0
PATCH 2/8 MIPS: c-r4k: Add r4k_blast_scache_node for Loongson-3
In reply to Huacai ChenFor multi-node Loongson-3 (NUMA configuration), r4k_blast_scache() can only flush Node-0's scache. So we add r4k_blast_scache_node() by using (CAC_BASE | (node_id << NODE_ADDRSPACE_SHIFT)) instead of CKSEG0 as the start address.
--- arch/mips/include/asm/r4kcache.h | 34 ++++++++++++++++++++++++++++++++ arch/mips/mm/c-r4k.c | 42 +++++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 7 deletions(-)
arch/mips/include/asm/r4kcache.h +34 -0
@@ -747,4 +747,38 @@ __BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, , ) __BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, , ) __BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, , ) +#ifndef pa_to_nid +#define pa_to_nid(addr) 0 +#endif + +#ifndef NODE_ADDRSPACE_SHIFT +#define nid_to_addrbase(nid) 0 +#else +#define nid_to_addrbase(nid) (nid << NODE_ADDRSPACE_SHIFT) +#endif + +#define __BUILD_BLAST_CACHE_NODE(pfx, desc, indexop, hitop, lsize) \ +static inline void blast_##pfx##cache##lsize##_node(long node) \ +{ \ + unsigned long start = CAC_BASE | nid_to_addrbase(node); \ + unsigned long end = start + current_cpu_data.desc.waysize; \ + unsigned long ws_inc = 1UL << current_cpu_data.desc.waybit; \ + unsigned long ws_end = current_cpu_data.desc.ways << \ + current_cpu_data.desc.waybit; \ + unsigned long ws, addr; \ + \ + __##pfx##flush_prologue \ + \ + for (ws = 0; ws < ws_end; ws += ws_inc) \ + for (addr = start; addr < end; addr += lsize * 32) \ + cache##lsize##_unroll32(addr|ws, indexop); \ + \ + __##pfx##flush_epilogue \ +} + +__BUILD_BLAST_CACHE_NODE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 16) +__BUILD_BLAST_CACHE_NODE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 32) +__BUILD_BLAST_CACHE_NODE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 64) +__BUILD_BLAST_CACHE_NODE(s, scache, Index_Writeback_Inv_SD, Hit_Writeback_Inv_SD, 128) +#endif /* _ASM_R4KCACHE_H */
arch/mips/mm/c-r4k.c +35 -7
76 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH 3/8 MIPS: Ensure pmd_present() returns false after pmd_mknotpresent()
This patch is borrowed from ARM64 to ensure pmd_present() returns false after pmd_mknotpresent(). This is needed for THP.
--- arch/mips/include/asm/pgtable-64.h | 5 +++++ 1 file changed, 5 insertions(+)
arch/mips/include/asm/pgtable-64.h +5 -0
@@ -271,6 +271,11 @@ static inline int pmd_bad(pmd_t pmd)static inline int pmd_present (pmd_t pmd) { +#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT +if (unlikely (pmd_val (pmd) & _PAGE_HUGE)) +return pmd_val (pmd) & _PAGE_PRESENT; +#endif +return pmd_val (pmd) != (unsigned long ) invalid_pte_table; }
Signature · 1 line
2.7.0
Re: [PATCH 3/8] MIPS: Ensure pmd_present() returns false after pmd_mknotpresent()
Quoted 1 line · Huacai Chen
This patch is borrowed from ARM64 to ensure
pmd_present()returns false
I presume you're referring to commit 5bb1cc0ff9a6 ("arm64: Ensure pmd_present() returns false after pmd_mknotpresent()"). I think it would be worth mentioning that specifically.
Quoted 3 lines
after
pmd_mknotpresent(). This is needed for THP.
Back to what version? 3.8 when THP was added?
Otherwise it looks reasonable:
Cheers
James
Quoted 27 lines
Signed-off-by Huacai Chen <[email protected]>--- arch/mips/include/asm/pgtable-64.h | 5 +++++ 1 file changed, 5 insertions(+)arch/mips/include/asm/pgtable-64.h +5
-0@@ -271,6 +271,11 @@ static inline int pmd_bad(pmd_t pmd)static inline int pmd_present (pmd_t pmd) { +#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT +if (unlikely (pmd_val (pmd) & _PAGE_HUGE)) +return pmd_val (pmd) & _PAGE_PRESENT; +#endif +return pmd_val (pmd) != (unsigned long ) invalid_pte_table; }Signature · 1 line
2.7.0
PATCH 4/8 MIPS: Add __cpu_full_name[] to make CPU names more human-readable
In reply to Huacai ChenIn /proc/cpuinfo, we keep "cpu model" as is, since GCC should use it for -march=native. Besides, we add __cpu_full_name[] to describe the processor in a more human-readable manner. The full name is displayed as "model name" in cpuinfo, which is needed by some userspace tools such as gnome-system-monitor.
The CPU frequency in "model name" is the default value (highest), and there is also a "CPU MHz" whose value can be changed by cpufreq.
This is only used by Loongson now (ICT is dropped in cpu name, and cpu name can be overwritten by BIOS).
--- arch/mips/include/asm/cpu-info.h | 2 ++ arch/mips/include/asm/mach-loongson64/boot_param.h | 1 + arch/mips/include/asm/time.h | 2 ++ arch/mips/kernel/cpu-probe.c | 25 ++++++++++++++++------ arch/mips/kernel/proc.c | 6 ++++++ arch/mips/kernel/time.c | 2 ++ arch/mips/loongson64/common/env.c | 13 +++++++++++ arch/mips/loongson64/loongson-3/smp.c | 1 + arch/mips/loongson64/loongson-3/smp.h | 1 + 9 files changed, 47 insertions(+), 6 deletions(-)
arch/mips/include/asm/cpu-info.h +2 -0
@@ -121,7 +121,9 @@ extern void cpu_probe(void);extern void cpu_report (void );extern const char *__cpu_name[]; +extern const char *__cpu_full_name[];#define cpu_name_string () __cpu_name[raw_smp_processor_id()] +#define cpu_full_name_string () __cpu_full_name[raw_smp_processor_id()]struct seq_file ;struct notifier_block ;
arch/mips/include/asm/mach-loongson64/boot_param.h +1 -0
@@ -57,6 +57,7 @@ struct efi_cpuinfo_loongson {u16 reserved_cores_mask;u32 cpu_clock_freq;/* cpu_clock */ u32 nr_cpus; +char cpuname[64 ]; } __packed;#define MAX_UARTS 64
arch/mips/include/asm/time.h +2 -0
@@ -35,6 +35,8 @@ extern int rtc_mips_set_mmss(unsigned long);*/ extern void plat_time_init (void ); +extern unsigned int mips_cpu_frequency; +/* * mips_hpt_frequency - must be set if you intend to use an R4k-compatible * counter as a timer interrupt source.
arch/mips/kernel/cpu-probe.c +19 -6
@@ -1476,30 +1476,40 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)switch (c->processor_id &PRID_REV_MASK ) {case PRID_REV_LOONGSON2E : c->cputype =CPU_LOONGSON2 ; - __cpu_name[cpu] ="ICT Loongson-2" ; + __cpu_name[cpu] ="Loongson-2" ;set_elf_platform (cpu,"loongson2e" );set_isa (c,MIPS_CPU_ISA_III ); c->fpu_msk31 |=FPU_CSR_CONDX ; + __cpu_full_name[cpu] ="Loongson-2E" ;break ;case PRID_REV_LOONGSON2F : c->cputype =CPU_LOONGSON2 ; - __cpu_name[cpu] ="ICT Loongson-2" ; + __cpu_name[cpu] ="Loongson-2" ;set_elf_platform (cpu,"loongson2f" );set_isa (c,MIPS_CPU_ISA_III ); c->fpu_msk31 |=FPU_CSR_CONDX ; + __cpu_full_name[cpu] ="Loongson-2F" ;break ;case PRID_REV_LOONGSON3A_R1 : c->cputype =CPU_LOONGSON3 ; - __cpu_name[cpu] ="ICT Loongson-3" ; + __cpu_name[cpu] ="Loongson-3" ;set_elf_platform (cpu,"loongson3a" );set_isa (c,MIPS_CPU_ISA_M64R1 ); + __cpu_full_name[cpu] ="Loongson-3A R1 (Loongson-3A1000)" ;break ;case PRID_REV_LOONGSON3B_R1 : + c->cputype =CPU_LOONGSON3 ; + __cpu_name[cpu] ="Loongson-3" ; +set_elf_platform (cpu,"loongson3b" ); +set_isa (c,MIPS_CPU_ISA_M64R1 ); + __cpu_full_name[cpu] ="Loongson-3B R1 (Loongson-3B1000)" ; +break ;case PRID_REV_LOONGSON3B_R2 : c->cputype =CPU_LOONGSON3 ; - __cpu_name[cpu] ="ICT Loongson-3" ; + __cpu_name[cpu] ="Loongson-3" ;set_elf_platform (cpu,"loongson3b" );set_isa (c,MIPS_CPU_ISA_M64R1 ); + __cpu_full_name[cpu] ="Loongson-3B R2 (Loongson-3B1500)" ;break ; }
@@ -1845,15 +1855,17 @@ static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)switch (c->processor_id &PRID_REV_MASK ) {case PRID_REV_LOONGSON3A_R2 : c->cputype =CPU_LOONGSON3 ; - __cpu_name[cpu] ="ICT Loongson-3" ; + __cpu_name[cpu] ="Loongson-3" ;set_elf_platform (cpu,"loongson3a" );set_isa (c,MIPS_CPU_ISA_M64R2 ); + __cpu_full_name[cpu] ="Loongson-3A R2 (Loongson-3A2000)" ;break ;case PRID_REV_LOONGSON3A_R3 : c->cputype =CPU_LOONGSON3 ; - __cpu_name[cpu] ="ICT Loongson-3" ; + __cpu_name[cpu] ="Loongson-3" ;set_elf_platform (cpu,"loongson3a" );set_isa (c,MIPS_CPU_ISA_M64R2 ); + __cpu_full_name[cpu] ="Loongson-3A R3 (Loongson-3A3000)" ;break ; }
@@ -1973,6 +1985,7 @@ EXPORT_SYMBOL(__ua_limit);#endif const char *__cpu_name[NR_CPUS ]; +const char *__cpu_full_name[NR_CPUS ];const char *__elf_platform;void cpu_probe (void )
arch/mips/kernel/proc.c +6 -0
@@ -14,6 +14,7 @@#include <asm/mipsregs.h> #include <asm/processor.h> #include <asm/prom.h> +#include <asm/time.h> unsigned int vced_count, vcei_count;
@@ -62,6 +63,11 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_printf (m, fmt, __cpu_name[n], (version >>4 ) &0x0f , version &0x0f , (fp_vers >>4 ) &0x0f , fp_vers &0x0f ); +if (__cpu_full_name[n]) +seq_printf (m,"model name\t\t: %s\n" , __cpu_full_name[n]); +if (mips_cpu_frequency) +seq_printf (m,"CPU MHz\t\t\t: %u.%02u\n" , + mips_cpu_frequency /1000000 , (mips_cpu_frequency /10000 ) %100 );seq_printf (m,"BogoMIPS\t\t: %u.%02u\n" , cpu_data[n].udelay_val / (500000 /HZ ), (cpu_data[n].udelay_val / (5000 /HZ )) %100 );
arch/mips/kernel/time.c +2 -0
@@ -69,6 +69,8 @@ EXPORT_SYMBOL(perf_irq);* 2) calculate a couple of cached variables for later usage */ +unsigned int mips_cpu_frequency; +EXPORT_SYMBOL_GPL (mips_cpu_frequency);unsigned int mips_hpt_frequency;EXPORT_SYMBOL_GPL (mips_hpt_frequency);
arch/mips/loongson64/common/env.c +13 -0
@@ -18,6 +18,7 @@* option) any later version. */ #include <linux/export.h> +#include <asm/time.h> #include <asm/bootinfo.h> #include <loongson.h> #include <boot_param.h>
@@ -25,6 +26,7 @@u32 cpu_clock_freq;EXPORT_SYMBOL (cpu_clock_freq); +char cpu_full_name[64 ];struct efi_memory_map_loongson *loongson_memmap;struct loongson_system_configuration loongson_sysconf;
@@ -45,6 +47,7 @@ do { \void __init prom_init_env (void ) {/* pmon passes arguments in 32bit pointers */ +char freq[12 ];unsigned int processor_id;#ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
@@ -151,6 +154,10 @@ void __init prom_init_env(void) loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus + loongson_sysconf.cores_per_node -1 ) / loongson_sysconf.cores_per_node; +if (!strncmp (ecpu->cpuname,"Loongson" ,8 )) +strncpy (cpu_full_name, ecpu->cpuname,sizeof (cpu_full_name)); +if (cpu_full_name[0 ] ==0 ) +strncpy (cpu_full_name, __cpu_full_name[0 ],sizeof (cpu_full_name)); loongson_sysconf.pci_mem_start_addr = eirq_source->pci_mem_start_addr; loongson_sysconf.pci_mem_end_addr = eirq_source->pci_mem_end_addr;
@@ -210,5 +217,11 @@ void __init prom_init_env(void)break ; } } + mips_cpu_frequency = cpu_clock_freq;pr_info ("CpuClock = %u\n" , cpu_clock_freq); + +/* Append default cpu frequency with round-off */ +sprintf (freq," @ %uMHz" , (cpu_clock_freq +500000 ) /1000000 ); +strncat (cpu_full_name, freq,sizeof (cpu_full_name)); + __cpu_full_name[0 ] = cpu_full_name; }
arch/mips/loongson64/loongson-3/smp.c +1 -0
@@ -340,6 +340,7 @@ static void loongson3_init_secondary(void) initcount = core0_c0count[cpu] + i/2 ;write_c0_count (initcount); + __cpu_full_name[cpu] = cpu_full_name; }static void loongson3_smp_finish (void )
arch/mips/loongson64/loongson-3/smp.h +1 -0
@@ -2,6 +2,7 @@#define __LOONGSON_SMP_H_/* for Loongson-3 smp support */ +extern char cpu_full_name[64 ];extern unsigned long long smp_group[4 ];/* 4 groups(nodes) in maximum in numa case */
Signature · 1 line
2.7.0
Re: [PATCH 4/8] MIPS: Add __cpu_full_name[] to make CPU names more human-readable
Quoted 20 lines · Huacai Chen
In
/proc/cpuinfo, we keep "cpu model" as is, since GCC should use it for -march=native. Besides, we add __cpu_full_name[] to describe the processor in a more human-readable manner. The full name is displayed as "model name" in cpuinfo, which is needed by some userspace tools such as gnome-system-monitor.The CPU frequency in "model name" is the default value (highest), and there is also a "CPU MHz" whose value can be changed by cpufreq.
This is only used by Loongson now (ICT is dropped in cpu name, and cpu name can be overwritten by BIOS).
Signed-off-by Huacai Chen <[email protected]>arch/mips/kernel/proc.c +0
-0
arch/mips/kernel/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 70
Quoted 8 lines
arch/mips/kernel/proc.c +5
-0@@ -62,6 +63,11 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_printf (m, fmt, __cpu_name[n], (version >>4 ) &0x0f , version &0x0f , (fp_vers >>4 ) &0x0f , fp_vers &0x0f ); +if (__cpu_full_name[n]) +seq_printf (m,"model name\t\t: %s\n" , __cpu_full_name[n]); +if (mips_cpu_frequency) +seq_printf (m,"CPU MHz\t\t\t: %u.%02u\n" , + mips_cpu_frequency /1000000 , (mips_cpu_frequency /10000 ) %100 );
long line
arch/mips/loongson64/common/env.c void __init prom_init_env(void) · line 160
Quoted 13 lines
arch/mips/loongson64/common/env.c +4
-0@@ -151,6 +154,10 @@ void __init prom_init_env(void) loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus + loongson_sysconf.cores_per_node -1 ) / loongson_sysconf.cores_per_node; +if (!strncmp (ecpu->cpuname,"Loongson" ,8 )) +strncpy (cpu_full_name, ecpu->cpuname,sizeof (cpu_full_name)); +if (cpu_full_name[0 ] ==0 ) +strncpy (cpu_full_name, __cpu_full_name[0 ],sizeof (cpu_full_name));
long line
Otherwise this looks reasonable I think:
Cheers
James
PATCH 5/8 MIPS: Align kernel load address to 64KB
In reply to Huacai ChenKEXEC assume kernel align to PAGE_SIZE, and 64KB is the largest PAGE_SIZE.
--- arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/mips/boot/compressed/calc_vmlinuz_load_addr.c +2 -3
@@ -45,11 +45,10 @@ int main(int argc, char *argv[]) vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size;/* -* Align with 16 bytes: "greater than that used for any standard data -* types by a MIPS compiler." -- See MIPS Run Linux (Second Edition). +* Align with 64KB: KEXEC assume kernel align to PAGE_SIZE */ - vmlinuz_load_addr += (16 - vmlinux_size %16 ); + vmlinuz_load_addr += (65536 - vmlinux_size %65536 );printf ("0x%llx\n" , vmlinuz_load_addr);
Signature · 5 lines
2.7.0
PATCH 6/8 MIPS: Loongson: Add kexec/kdump support
In reply to Huacai Chen--- arch/mips/kernel/relocate_kernel.S | 30 +++++++++ arch/mips/loongson64/common/env.c | 8 +++ arch/mips/loongson64/common/reset.c | 119 ++++++++++++++++++++++++++++++++++ arch/mips/loongson64/loongson-3/smp.c | 4 ++ 4 files changed, 161 insertions(+)
arch/mips/kernel/relocate_kernel.S +30 -0
@@ -135,6 +135,36 @@ LEAF(kexec_smp_wait) #else sync #endif + +#ifdef CONFIG_CPU_LOONGSON3 + /* s0:prid s1:initfn */ + /* t0:base t1:cpuid t2:node t3:core t9:count */ + mfc0 t1, $15, 1 + andi t1, 0x3ff + dli t0, 0x900000003ff01000 + andi t3, t1, 0x3 + sll t3, 8 /* get core id */ + or t0, t0, t3 + andi t2, t1, 0xc + dsll t2, 42 /* get node id */ + or t0, t0, t2 + mfc0 s0, $15, 0 + andi s0, s0, 0xf + blt s0, 0x6, 1f /* Loongson-3A1000 */ + bgt s0, 0x7, 1f /* Loongson-3A2000/3A3000 */ + dsrl t2, 30 /* Loongson-3B1000/3B1500 need bit15:14 */ + or t0, t0, t2 +1: li t9, 0x100 /* wait for init loop */ +2: addiu t9, -1 /* limit mailbox access */ + bnez t9, 2b + ld s1, 0x20(t0) /* get PC via mailbox */ + beqz s1, 1b + ld sp, 0x28(t0) /* get SP via mailbox */ + ld gp, 0x30(t0) /* get GP via mailbox */ + ld a1, 0x38(t0) + jr s1 /* jump to initial PC */ +#endif + j s1 END(kexec_smp_wait) #endif
arch/mips/loongson64/common/env.c +8 -0
@@ -72,6 +72,7 @@ void __init prom_init_env(void)pr_info ("memsize=%u, highmemsize=%u\n" , memsize, highmemsize);#else +int i;struct boot_params *boot_p;struct loongson_params *loongson_p;struct system_loongson *esys;
@@ -149,6 +150,13 @@ void __init prom_init_env(void) loongson_sysconf.nr_cpus = ecpu->nr_cpus; loongson_sysconf.boot_cpu_id = ecpu->cpu_startup_core_id; loongson_sysconf.reserved_cpus_mask = ecpu->reserved_cores_mask; +#ifdef CONFIG_KEXEC + loongson_sysconf.boot_cpu_id =get_ebase_cpunum (); +for (i =0 ; i < loongson_sysconf.boot_cpu_id; i++) + loongson_sysconf.reserved_cpus_mask |= (1 <<i); +pr_info ("Boot CPU ID is being fixed from %d to %d\n" , + ecpu->cpu_startup_core_id, loongson_sysconf.boot_cpu_id); +#endif if (ecpu->nr_cpus >NR_CPUS || ecpu->nr_cpus ==0 ) loongson_sysconf.nr_cpus =NR_CPUS ; loongson_sysconf.nr_nodes = (loongson_sysconf.nr_cpus +
arch/mips/loongson64/common/reset.c +119 -0
140 lines not on this page · raw message
arch/mips/loongson64/loongson-3/smp.c +4 -0
@@ -387,6 +387,10 @@ static void __init loongson3_smp_setup(void)ipi_status0_regs_init ();ipi_en0_regs_init ();ipi_mailbox_buf_init (); + +for (i =0 ; i < loongson_sysconf.nr_cpus; i++) +loongson3_ipi_write64 (0 , (void *)(ipi_mailbox_buf[i]+0x0 )); + cpu_data[0 ].core =cpu_logical_map (0 ) % loongson_sysconf.cores_per_package; cpu_data[0 ].package =cpu_logical_map (0 ) / loongson_sysconf.cores_per_package; }
Signature · 1 line
2.7.0
Re: [PATCH 2/8] MIPS: c-r4k: Add r4k_blast_scache_node for Loongson-3
In reply to Huacai ChenQuoted 6 lines · Huacai Chen
For multi-node Loongson-3 (NUMA configuration),
r4k_blast_scache()can only flush Node-0's scache. So we addr4k_blast_scache_node()by using (CAC_BASE| (node_id<<NODE_ADDRSPACE_SHIFT)) instead of CKSEG0 as the start address.
I believe Loongson 3 support was added in 3.15, so the following is probably slightly better:
arch/mips/mm/c-r4k.c static void r4k_blast_scache_setup(void) · line 462
Quoted 9 lines
arch/mips/mm/c-r4k.c +1
-0@@ -459,11 +459,28 @@ static void r4k_blast_scache_setup(void) r4k_blast_scache = blast_scache128; } +static void (* r4k_blast_scache_node)(long node);
Checkpatch objects to the space after '*'.
Other than those minor things this patch looks reasonable I think
Cheers
James
PATCH 7/8 MIPS: Loongson: Make CPUFreq usable for Loongson-3
In reply to Huacai ChenLoongson-3A/3B support frequency scaling. But due to hardware limitation, Loongson-3A's frequency scaling is not independent for each core, we suggest enable Loongson-3A's CPUFreq only when there is one core online. Loongson-3B can adjust frequency independently for each core, so it can be always enabled.
Each package has only one register (ChipConfig or FreqCtrl) to control frequency, so we need spinlocks to protect register access for multi- cores. However, we cannot use spinlock when a core becomes into "wait" status (frequency = 0), so we only enable "wait" when there is one core in a package online.
arch/mips/kernel/smp.c is modified to guarantee udelay_val has the correct value while both CPU hotplug and CPUFreq are enabled.
--- arch/mips/include/asm/mach-loongson64/loongson.h | 1 + arch/mips/kernel/smp.c | 3 +- arch/mips/loongson64/Kconfig | 1 + arch/mips/loongson64/common/platform.c | 13 +- arch/mips/loongson64/loongson-3/Makefile | 2 +- arch/mips/loongson64/loongson-3/clock.c | 191 ++++++++++++++++++ drivers/cpufreq/Kconfig | 15 ++ drivers/cpufreq/Makefile | 1 + drivers/cpufreq/loongson3_cpufreq.c | 236 +++++++++++++++++++++++ 9 files changed, 458 insertions(+), 5 deletions(-) create mode 100644 arch/mips/loongson64/loongson-3/clock.c create mode 100644 drivers/cpufreq/loongson3_cpufreq.c
arch/mips/include/asm/mach-loongson64/loongson.h +1 -0
@@ -277,6 +277,7 @@ extern u64 loongson_freqctrl[MAX_PACKAGES];#ifdef CONFIG_CPU_SUPPORTS_CPUFREQ #include <linux/cpufreq.h> extern struct cpufreq_frequency_table loongson2_clockmod_table[]; +extern struct cpufreq_frequency_table loongson3_clockmod_table[];#endif /*
arch/mips/kernel/smp.c +2 -1
@@ -371,7 +371,8 @@ asmlinkage void start_secondary(void)calibrate_delay ();preempt_disable (); cpu =smp_processor_id (); - cpu_data[cpu].udelay_val = loops_per_jiffy; +if (!cpu_data[cpu].udelay_val) + cpu_data[cpu].udelay_val = loops_per_jiffy;cpumask_set_cpu (cpu, &cpu_coherent_mask);notify_cpu_starting (cpu);
arch/mips/loongson64/Kconfig +1 -0
@@ -69,6 +69,7 @@ config LOONGSON_MACH3X select CSRC_R4K select CEVT_R4K select CPU_HAS_WB + select HAVE_CLK select HW_HAS_PCI select ISA select HT_PCI
arch/mips/loongson64/common/platform.c +10 -3
@@ -17,15 +17,22 @@ static struct platform_device loongson2_cpufreq_device = { .id = -1, }; -static int __init loongson2_cpufreq_init (void ) +static struct platform_device loongson3_cpufreq_device = { + .name ="loongson3_cpufreq" , + .id =-1 , +}; + +static int __init loongson_cpufreq_init (void ) {struct cpuinfo_mips *c = ¤t_cpu_data;/* Only 2F revision and it's successors support CPUFreq */ -if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_LOONGSON2F ) +if ((c->processor_id &PRID_REV_MASK ) ==PRID_REV_LOONGSON2F )return platform_device_register (&loongson2_cpufreq_device); +if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_LOONGSON3A_R1 ) +return platform_device_register (&loongson3_cpufreq_device);return -ENODEV ; } -arch_initcall (loongson2_cpufreq_init); +arch_initcall (loongson_cpufreq_init);
arch/mips/loongson64/loongson-3/Makefile +1 -1
@@ -1,7 +1,7 @@ # # Makefile for Loongson-3 family machines # -obj-y += irq.o cop2-ex.o platform.o acpi_init.o +obj-y += irq.o cop2-ex.o platform.o acpi_init.o clock.o obj-$(CONFIG_SMP) += smp.o
arch/mips/loongson64/loongson-3/clock.c new file +191 -0
191 lines not on this page · raw message
drivers/cpufreq/Kconfig +15 -0
@@ -275,6 +275,7 @@ config BMIPS_CPUFREQ config LOONGSON2_CPUFREQ tristate "Loongson2 CPUFreq Driver" + depends on CPU_LOONGSON2 help This option adds a CPUFreq driver for loongson processors which support software configurable cpu frequency.
@@ -285,8 +286,22 @@ config LOONGSON2_CPUFREQ If in doubt, say N. +config LOONGSON3_CPUFREQ + tristate "Loongson3 CPUFreq Driver" + depends on CPU_LOONGSON3 + help + This option adds a CPUFreq driver for loongson processors which + support software configurable cpu frequency. + + Loongson-3A and it's successors support this feature. + + For details, take a look at <file:Documentation/cpu-freq/>. + + If in doubt, say N. + config LOONGSON1_CPUFREQ tristate "Loongson1 CPUFreq Driver" + depends on CPU_LOONGSON1 help This option adds a CPUFreq driver for loongson1 processors which support software configurable cpu frequency.
drivers/cpufreq/Makefile +1 -0
@@ -105,6 +105,7 @@ obj-$(CONFIG_CRIS_MACH_ARTPEC3) += cris-artpec3-cpufreq.o obj-$(CONFIG_ETRAXFS) += cris-etraxfs-cpufreq.o obj-$(CONFIG_IA64_ACPI_CPUFREQ) += ia64-acpi-cpufreq.o obj-$(CONFIG_LOONGSON2_CPUFREQ) += loongson2_cpufreq.o +obj-$(CONFIG_LOONGSON3_CPUFREQ) += loongson3_cpufreq.o obj-$(CONFIG_LOONGSON1_CPUFREQ) += loongson1-cpufreq.o obj-$(CONFIG_SH_CPU_FREQ) += sh-cpufreq.o obj-$(CONFIG_SPARC_US2E_CPUFREQ) += sparc-us2e-cpufreq.o
drivers/cpufreq/loongson3_cpufreq.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH 8/8 MIPS: Loongson: Introduce and use WAR_LLSC_MB
On the Loongson-2G/2H/3A/3B there is a hardware flaw that ll/sc and lld/scd is very weak ordering. We should add sync instructions before each ll/lld and after the last sc/scd to workaround. Otherwise, this flaw will cause deadlock occationally (e.g. when doing heavy load test with LTP).
--- arch/mips/include/asm/atomic.h | 18 ++++++++++++++++-- arch/mips/include/asm/barrier.h | 6 ++++++ arch/mips/include/asm/bitops.h | 15 +++++++++++++++ arch/mips/include/asm/cmpxchg.h | 9 +++++++-- arch/mips/include/asm/edac.h | 5 ++++- arch/mips/include/asm/futex.h | 18 ++++++++++++------ arch/mips/include/asm/local.h | 10 ++++++++-- arch/mips/include/asm/pgtable.h | 5 ++++- arch/mips/kernel/syscall.c | 2 ++ arch/mips/loongson64/Platform | 3 +++ arch/mips/mm/tlbex.c | 11 +++++++++++ 11 files changed, 88 insertions(+), 14 deletions(-)
arch/mips/include/asm/atomic.h +16 -2
@@ -62,6 +62,7 @@ static __inline__ void atomic_##op(int i, atomic_t * v) \ do { \ __asm__ __volatile__( \ " .set "MIPS_ISA_LEVEL" \n" \ + __WAR_LLSC_MB \ " ll %0, %1 # atomic_" #op "\n" \ " " #asm_op " %0, %2 \n" \ " sc %0, %1 \n" \
@@ -69,6 +70,7 @@ static __inline__ void atomic_##op(int i, atomic_t * v) \ : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ : "Ir" (i)); \ }while (unlikely (!temp)); \ + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); \ }else { \unsigned long flags; \ \
@@ -103,6 +105,7 @@ static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ do { \ __asm__ __volatile__( \ " .set "MIPS_ISA_LEVEL" \n" \ + __WAR_LLSC_MB \ " ll %1, %2 # atomic_" #op "_return \n" \ " " #asm_op " %0, %1, %3 \n" \ " sc %0, %2 \n" \
@@ -151,6 +154,7 @@ static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ do { \ __asm__ __volatile__( \ " .set "MIPS_ISA_LEVEL" \n" \ + __WAR_LLSC_MB \ " ll %1, %2 # atomic_fetch_" #op " \n" \ " " #asm_op " %0, %1, %3 \n" \ " sc %0, %2 \n" \
@@ -159,6 +163,7 @@ static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ "+" GCC_OFF_SMALL_ASM() (v->counter) \ : "Ir" (i)); \} while (unlikely(!result)); \ +__asm__ __volatile__(__WAR_LLSC_MB : : :" memory"); \ \ result = temp; \ } else { \
@@ -242,7 +247,9 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) __asm__ __volatile__(" .set " MIPS_ISA_LEVEL " \n" -"1: ll %1, %2 # atomic_sub_if_positive\n" +"1: # atomic_sub_if_positive \n" + __WAR_LLSC_MB +" ll %1, %2 \n" " subu %0, %1, %3 \n" " bltz %0, 1f \n" " sc %0, %2 \n"
@@ -404,6 +411,7 @@ static __inline__ void atomic64_##op(long i, atomic64_t * v) \ do { \ __asm__ __volatile__( \ " .set "MIPS_ISA_LEVEL" \n" \ + __WAR_LLSC_MB \ " lld %0, %1 # atomic64_" #op "\n" \ " " #asm_op " %0, %2 \n" \ " scd %0, %1 \n" \
@@ -411,6 +419,7 @@ static __inline__ void atomic64_##op(long i, atomic64_t * v) \ : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ : "Ir" (i)); \ }while (unlikely (!temp)); \ + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); \ }else { \unsigned long flags; \ \
@@ -445,6 +454,7 @@ static __inline__ long atomic64_##op##_return_relaxed(long i, atomic64_t * v) \ do { \ __asm__ __volatile__( \ " .set "MIPS_ISA_LEVEL" \n" \ + __WAR_LLSC_MB \ " lld %1, %2 # atomic64_" #op "_return\n" \ " " #asm_op " %0, %1, %3 \n" \ " scd %0, %2 \n" \
@@ -494,6 +504,7 @@ static __inline__ long atomic64_fetch_##op##_relaxed(long i, atomic64_t * v) \ do { \ __asm__ __volatile__( \ " .set "MIPS_ISA_LEVEL" \n" \ + __WAR_LLSC_MB \ " lld %1, %2 # atomic64_fetch_" #op "\n" \ " " #asm_op " %0, %1, %3 \n" \ " scd %0, %2 \n" \
@@ -503,6 +514,7 @@ static __inline__ long atomic64_fetch_##op##_relaxed(long i, atomic64_t * v) \ : "Ir" (i), GCC_OFF_SMALL_ASM() (v->counter) \ : "memory"); \ }while (unlikely (!result)); \ + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); \ \ result = temp; \ }else { \
@@ -587,7 +599,9 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v) __asm__ __volatile__(" .set " MIPS_ISA_LEVEL " \n" -"1: lld %1, %2 # atomic64_sub_if_positive\n" +"1: # atomic64_sub_if_positive \n" + __WAR_LLSC_MB +" lld %1, %2 \n" " dsubu %0, %1, %3 \n" " bltz %0, 1f \n" " scd %0, %2 \n"
arch/mips/include/asm/barrier.h +6 -0
@@ -203,6 +203,12 @@#define __WEAK_LLSC_MB " \n"#endif +#if defined(CONFIG_LOONGSON3 ) && defined(CONFIG_SMP )/* Loongson-3's LLSC workaround */ +#define __WAR_LLSC_MB " sync \n" +#else +#define __WAR_LLSC_MB " \n" +#endif +#define smp_llsc_mb () __asm__ __volatile__(__WEAK_LLSC_MB : : :"memory")#ifdef CONFIG_CPU_CAVIUM_OCTEON
arch/mips/include/asm/bitops.h +15 -0
@@ -70,17 +70,20 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) } else if (kernel_uses_llsc && __builtin_constant_p(bit)) {do { __asm__ __volatile__( + __WAR_LLSC_MB" " __LL"%0, %1 # set_bit \n" " " __INS"%0, %3, %2, 1 \n" " " __SC"%0, %1 \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) :"ir" (bit),"r" (~0 )); }while (unlikely (!temp)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory");#endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ }else if (kernel_uses_llsc) { do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # set_bit \n" " or %0, %2 \n" " " __SC "%0, %1 \n"
@@ -88,6 +91,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *addr) : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) : "ir" (1UL << bit)); }while (unlikely (!temp)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }else __mips_set_bit (nr, addr); }
@@ -122,17 +126,20 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) } else if (kernel_uses_llsc && __builtin_constant_p(bit)) {do { __asm__ __volatile__( + __WAR_LLSC_MB" " __LL"%0, %1 # clear_bit \n" " " __INS"%0, $0, %2, 1 \n" " " __SC"%0, %1 \n" : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) :"ir" (bit)); }while (unlikely (!temp)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory");#endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ }else if (kernel_uses_llsc) { do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # clear_bit \n" " and %0, %2 \n" " " __SC "%0, %1 \n"
@@ -140,6 +147,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *addr) : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) : "ir" (~(1UL << bit))); }while (unlikely (!temp)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }else __mips_clear_bit (nr, addr); }
@@ -191,6 +199,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # change_bit \n" " xor %0, %2 \n" " " __SC "%0, %1 \n"
@@ -198,6 +207,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *addr) : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (*m) : "ir" (1UL << bit)); }while (unlikely (!temp)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }else __mips_change_bit (nr, addr); }
@@ -240,6 +250,7 @@ static inline int test_and_set_bit(unsigned long nr, do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # test_and_set_bit \n" " or %2, %0, %3 \n" " " __SC "%2, %1 \n"
@@ -294,6 +305,7 @@ static inline int test_and_set_bit_lock(unsigned long nr, do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # test_and_set_bit \n" " or %2, %0, %3 \n" " " __SC "%2, %1 \n"
@@ -350,6 +362,7 @@ static inline int test_and_clear_bit(unsigned long nr, do { __asm__ __volatile__( + __WAR_LLSC_MB " " __LL "%0, %1 # test_and_clear_bit \n" " " __EXT "%2, %0, %3, 1 \n" " " __INS "%0, $0, %3, 1 \n"
@@ -366,6 +379,7 @@ static inline int test_and_clear_bit(unsigned long nr, do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # test_and_clear_bit \n" " or %2, %0, %3 \n" " xor %2, %3 \n"
@@ -423,6 +437,7 @@ static inline int test_and_change_bit(unsigned long nr, do { __asm__ __volatile__( " .set "MIPS_ISA_ARCH_LEVEL" \n" + __WAR_LLSC_MB " " __LL "%0, %1 # test_and_change_bit \n" " xor %2, %0, %3 \n" " " __SC "\t%2, %1 \n"
arch/mips/include/asm/cmpxchg.h +7 -2
@@ -48,7 +48,9 @@ extern unsigned long __xchg_called_with_bad_pointer(void)" .set push \n" \" .set noat \n" \" .set " MIPS_ISA_ARCH_LEVEL " \n" \ -"1: " ld" %0, %2 # __xchg_asm \n" \ +"1: # __xchg_asm \n" \ + __WAR_LLSC_MB \ +" " ld" %0, %2 \n" \" .set mips0 \n" \" move $1, %z3 \n" \" .set " MIPS_ISA_ARCH_LEVEL " \n" \
@@ -118,7 +120,9 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x," .set push \n" \" .set noat \n" \" .set " MIPS_ISA_ARCH_LEVEL " \n" \ -"1: " ld" %0, %2 # __cmpxchg_asm \n" \ +"1: # __cmpxchg_asm \n" \ + __WAR_LLSC_MB \ +" " ld" %0, %2 \n" \" bne %0, %z3, 2f \n" \" .set mips0 \n" \" move $1, %z4 \n" \
@@ -127,6 +131,7 @@ static inline unsigned long __xchg(volatile void *ptr, unsigned long x,"\t" __scbeqz" $1, 1b \n" \" .set pop \n" \"2: \n" \ + __WAR_LLSC_MB \ : "=&r" (__ret), "=" GCC_OFF_SMALL_ASM() (*m) \: GCC_OFF_SMALL_ASM() (*m), " Jr" (old), " Jr" (new) \ : "memory"); \
arch/mips/include/asm/edac.h +4 -1
@@ -21,13 +21,16 @@ static inline void edac_atomic_scrub(void *va, u32 size) __asm__ __volatile__ (" .set mips2 \n" -"1: ll %0, %1 # edac_atomic_scrub \n" +"1: # edac_atomic_scrub \n" + __WAR_LLSC_MB +" ll %0, %1 \n" " addu %0, $0 \n" " sc %0, %1 \n" " beqz %0, 1b \n" " .set mips0 \n" : "=&r" (temp), "=" GCC_OFF_SMALL_ASM() (*virt_addr) : GCC_OFF_SMALL_ASM() (*virt_addr)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); virt_addr++; }
arch/mips/include/asm/futex.h +12 -6
@@ -54,7 +54,9 @@" .set push \n" \" .set noat \n" \" .set " MIPS_ISA_ARCH_LEVEL " \n" \ - "1: "user_ll("%1", "%4")" # __futex_atomic_op\n" \ +"1: # __futex_atomic_op\n" \ + __WAR_LLSC_MB \ + " "user_ll("%1", "%4")" \n" \" .set mips0 \n" \" " insn" \n" \" .set " MIPS_ISA_ARCH_LEVEL " \n" \
@@ -70,8 +72,9 @@" j 3b \n" \" .previous \n" \" .section __ex_table,\"a\" \n" \ -" " __UA_ADDR"\t1b, 4b \n" \ -" " __UA_ADDR"\t2b, 4b \n" \ +" " __UA_ADDR"\t(1b + 0), 4b \n" \ +" " __UA_ADDR"\t(1b + 4), 4b \n" \ +" " __UA_ADDR"\t(2b + 0), 4b \n" \" .previous \n" \ : "=r" (ret), "=&r" (oldval), \"=" GCC_OFF_SMALL_ASM () (*uaddr) \
@@ -184,7 +187,9 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr," .set push \n" " .set noat \n" " .set " MIPS_ISA_ARCH_LEVEL " \n" - "1: "user_ll("%1", "%3")" \n" +"1: \n" + __WAR_LLSC_MB + " "user_ll("%1", "%3")" \n"" bne %1, %z4, 3f \n" " .set mips0 \n" " move $1, %z5 \n"
@@ -200,8 +205,9 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr," j 3b \n" " .previous \n" " .section __ex_table,\"a\" \n" -" " __UA_ADDR"\t1b, 4b \n" -" " __UA_ADDR"\t2b, 4b \n" +" " __UA_ADDR"\t(1b + 0), 4b \n" +" " __UA_ADDR"\t(1b + 4), 4b \n" +" " __UA_ADDR"\t(2b + 0), 4b \n" " .previous \n" : "+r" (ret), "=&r" (val), "=" GCC_OFF_SMALL_ASM() (*uaddr) : GCC_OFF_SMALL_ASM() (*uaddr), "Jr" (oldval), "Jr" (newval),
arch/mips/include/asm/local.h +8 -2
@@ -49,7 +49,9 @@ static __inline__ long local_add_return(long i, local_t * l) __asm__ __volatile__(" .set " MIPS_ISA_ARCH_LEVEL " \n" -"1:" __LL"%1, %2 # local_add_return \n" +"1: # local_add_return \n" + __WAR_LLSC_MB + __LL"%1, %2 \n" " addu %0, %1, %3 \n" __SC"%0, %2 \n" " beqz %0, 1b \n"
@@ -58,6 +60,7 @@ static __inline__ long local_add_return(long i, local_t * l) : "=&r" (result), "=&r" (temp), "=m" (l->a.counter) : "Ir" (i), "m" (l->a.counter) : "memory"); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }else {unsigned long flags;
@@ -94,7 +97,9 @@ static __inline__ long local_sub_return(long i, local_t * l) __asm__ __volatile__(" .set " MIPS_ISA_ARCH_LEVEL " \n" -"1:" __LL"%1, %2 # local_sub_return \n" +"1: # local_sub_return \n" + __WAR_LLSC_MB + __LL"%1, %2 \n" " subu %0, %1, %3 \n" __SC"%0, %2 \n" " beqz %0, 1b \n"
@@ -103,6 +108,7 @@ static __inline__ long local_sub_return(long i, local_t * l) : "=&r" (result), "=&r" (temp), "=m" (l->a.counter) : "Ir" (i), "m" (l->a.counter) : "memory"); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }else {unsigned long flags;
arch/mips/include/asm/pgtable.h +4 -1
@@ -233,7 +233,9 @@ static inline void set_pte(pte_t *ptep, pte_t pteval)" .set " MIPS_ISA_ARCH_LEVEL " \n" " .set push \n" " .set noreorder \n" -"1:" __LL"%[tmp], %[buddy] \n" +"1: \n" + __WAR_LLSC_MB + __LL"%[tmp], %[buddy] \n" " bnez %[tmp], 2f \n" " or %[tmp], %[tmp], %[global] \n" __SC"%[tmp], %[buddy] \n"
@@ -244,6 +246,7 @@ static inline void set_pte(pte_t *ptep, pte_t pteval)" .set mips0 \n" : [buddy] "+m" (buddy->pte), [tmp] "=&r" (tmp) : [global] "r" (page_global)); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }#else /* !CONFIG_SMP */ if (pte_none (*buddy))
arch/mips/kernel/syscall.c +2 -0
@@ -133,6 +133,7 @@ static inline int mips_atomic_set(unsigned long addr, unsigned long new)" .set " MIPS_ISA_ARCH_LEVEL " \n" " li %[err], 0 \n" "1: \n" + __WAR_LLSC_MB user_ll("%[old]", "(%[addr])")" move %[tmp], %[new] \n" "2: \n"
@@ -156,6 +157,7 @@ static inline int mips_atomic_set(unsigned long addr, unsigned long new) [new] "r" (new), [efault] "i" (-EFAULT) : "memory"); + __asm__ __volatile__(__WAR_LLSC_MB : : :"memory"); }else { do { preempt_disable();
arch/mips/loongson64/Platform +3 -0
@@ -23,6 +23,9 @@ ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS endif cflags-$(CONFIG_CPU_LOONGSON3) += -Wa,--trap +ifneq ($(call as-option,-Wa$(comma)-mfix-loongson3-llsc,),) + cflags-$(CONFIG_CPU_LOONGSON3) += -Wa$(comma)-mno-fix-loongson3-llsc +endif # # binutils from v2.25 on and gcc starting from v4.9.0 treat -march=loongson3a # as MIPS64 R2; older versions as just R1. This leaves the possibility open
arch/mips/mm/tlbex.c +11 -0
@@ -935,6 +935,8 @@ build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,* to mimic that here by taking a load/istream page * fault. */ +if (current_cpu_type () ==CPU_LOONGSON3 ) +uasm_i_sync (p,0 );UASM_i_LA (p, ptr, (unsigned long )tlb_do_page_fault_0);uasm_i_jr (p, ptr);
@@ -1560,6 +1562,7 @@ static void build_loongson3_tlb_refill_handler(void)if (check_for_high_segbits) {uasm_l_large_segbits_fault (&l, p); +uasm_i_sync (&p,0 );UASM_i_LA (&p,K1 , (unsigned long )tlb_do_page_fault_0);uasm_i_jr (&p,K1 );uasm_i_nop (&p);
@@ -1660,6 +1663,8 @@ static void iPTE_LW(u32 **p, unsigned int pte, unsigned int ptr) {#ifdef CONFIG_SMP +if (current_cpu_type () ==CPU_LOONGSON3 ) +uasm_i_sync (p,0 );# ifdef CONFIG_PHYS_ADDR_T_64BIT if (cpu_has_64bits)uasm_i_lld (p, pte,0 , ptr);
@@ -2277,6 +2282,8 @@ static void build_r4000_tlb_load_handler(void)#endif uasm_l_nopage_tlbl (&l, p); +if (current_cpu_type () ==CPU_LOONGSON3 ) +uasm_i_sync (&p,0 );build_restore_work_registers (&p);#ifdef CONFIG_CPU_MICROMIPS if ((unsigned long )tlb_do_page_fault_0 &1 ) {
@@ -2332,6 +2339,8 @@ static void build_r4000_tlb_store_handler(void)#endif uasm_l_nopage_tlbs (&l, p); +if (current_cpu_type () ==CPU_LOONGSON3 ) +uasm_i_sync (&p,0 );build_restore_work_registers (&p);#ifdef CONFIG_CPU_MICROMIPS if ((unsigned long )tlb_do_page_fault_1 &1 ) {
@@ -2388,6 +2397,8 @@ static void build_r4000_tlb_modify_handler(void)#endif uasm_l_nopage_tlbm (&l, p); +if (current_cpu_type () ==CPU_LOONGSON3 ) +uasm_i_sync (&p,0 );build_restore_work_registers (&p);#ifdef CONFIG_CPU_MICROMIPS if ((unsigned long )tlb_do_page_fault_1 &1 ) {
Signature · 1 line
2.7.0