aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/Kconfig5
-rw-r--r--arch/powerpc/boot/dts/canyonlands.dts4
-rw-r--r--arch/powerpc/boot/dts/glacier.dts4
-rw-r--r--arch/powerpc/include/asm/abs_addr.h2
-rw-r--r--arch/powerpc/include/asm/asm-compat.h2
-rw-r--r--arch/powerpc/include/asm/cputable.h4
-rw-r--r--arch/powerpc/include/asm/dbell.h8
-rw-r--r--arch/powerpc/include/asm/hvcall.h1
-rw-r--r--arch/powerpc/include/asm/hw_breakpoint.h74
-rw-r--r--arch/powerpc/include/asm/machdep.h5
-rw-r--r--arch/powerpc/include/asm/mmu-book3e.h4
-rw-r--r--arch/powerpc/include/asm/paca.h2
-rw-r--r--arch/powerpc/include/asm/percpu.h3
-rw-r--r--arch/powerpc/include/asm/ppc-opcode.h7
-rw-r--r--arch/powerpc/include/asm/processor.h8
-rw-r--r--arch/powerpc/include/asm/reg.h2
-rw-r--r--arch/powerpc/include/asm/reg_booke.h5
-rw-r--r--arch/powerpc/include/asm/rtas.h13
-rw-r--r--arch/powerpc/include/asm/time.h7
-rw-r--r--arch/powerpc/include/asm/topology.h3
-rw-r--r--arch/powerpc/include/asm/vdso_datapage.h2
-rw-r--r--arch/powerpc/kernel/Makefile4
-rw-r--r--arch/powerpc/kernel/asm-offsets.c2
-rw-r--r--arch/powerpc/kernel/cputable.c118
-rw-r--r--arch/powerpc/kernel/crash_dump.c4
-rw-r--r--arch/powerpc/kernel/dbell.c78
-rw-r--r--arch/powerpc/kernel/exceptions-64e.S50
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S1
-rw-r--r--arch/powerpc/kernel/hw_breakpoint.c364
-rw-r--r--arch/powerpc/kernel/idle_book3e.S86
-rw-r--r--arch/powerpc/kernel/irq.c16
-rw-r--r--arch/powerpc/kernel/machine_kexec.c22
-rw-r--r--arch/powerpc/kernel/machine_kexec_64.c78
-rw-r--r--arch/powerpc/kernel/paca.c10
-rw-r--r--arch/powerpc/kernel/process.c36
-rw-r--r--arch/powerpc/kernel/prom_init.c44
-rw-r--r--arch/powerpc/kernel/ptrace.c64
-rw-r--r--arch/powerpc/kernel/rtas.c105
-rw-r--r--arch/powerpc/kernel/setup-common.c13
-rw-r--r--arch/powerpc/kernel/setup_64.c19
-rw-r--r--arch/powerpc/kernel/signal.c3
-rw-r--r--arch/powerpc/kernel/smp.c10
-rw-r--r--arch/powerpc/kernel/time.c197
-rw-r--r--arch/powerpc/kernel/traps.c29
-rw-r--r--arch/powerpc/kernel/vdso32/gettimeofday.S184
-rw-r--r--arch/powerpc/kernel/vdso64/gettimeofday.S88
-rw-r--r--arch/powerpc/kvm/timing.c2
-rw-r--r--arch/powerpc/lib/Makefile5
-rw-r--r--arch/powerpc/lib/ldstfp.S375
-rw-r--r--arch/powerpc/lib/sstep.c1514
-rw-r--r--arch/powerpc/mm/fsl_booke_mmu.c7
-rw-r--r--arch/powerpc/mm/numa.c122
-rw-r--r--arch/powerpc/mm/pgtable.c1
-rw-r--r--arch/powerpc/mm/tlb_hash32.c15
-rw-r--r--arch/powerpc/mm/tlb_nohash.c129
-rw-r--r--arch/powerpc/oprofile/Makefile2
-rw-r--r--arch/powerpc/oprofile/common.c2
-rw-r--r--arch/powerpc/platforms/40x/Kconfig16
-rw-r--r--arch/powerpc/platforms/52xx/lite5200_pm.c3
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_pm.c3
-rw-r--r--arch/powerpc/platforms/85xx/smp.c4
-rw-r--r--arch/powerpc/platforms/iseries/vio.c3
-rw-r--r--arch/powerpc/platforms/powermac/cpufreq_32.c8
-rw-r--r--arch/powerpc/platforms/powermac/feature.c6
-rw-r--r--arch/powerpc/platforms/pseries/Makefile4
-rw-r--r--arch/powerpc/platforms/pseries/dlpar.c1
-rw-r--r--arch/powerpc/platforms/pseries/eeh_cache.c3
-rw-r--r--arch/powerpc/platforms/pseries/event_sources.c23
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-cpu.c7
-rw-r--r--arch/powerpc/platforms/pseries/ras.c5
-rw-r--r--arch/powerpc/platforms/pseries/reconfig.c4
-rw-r--r--arch/powerpc/platforms/pseries/suspend.c214
-rw-r--r--arch/powerpc/platforms/pseries/xics.c2
-rw-r--r--arch/powerpc/sysdev/mpic.c18
-rw-r--r--arch/powerpc/sysdev/mpic.h1
-rw-r--r--arch/powerpc/xmon/xmon.c152
76 files changed, 3738 insertions, 703 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2031a284686..ae29761469b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -141,6 +141,7 @@ config PPC
141 select GENERIC_ATOMIC64 if PPC32 141 select GENERIC_ATOMIC64 if PPC32
142 select HAVE_PERF_EVENTS 142 select HAVE_PERF_EVENTS
143 select HAVE_REGS_AND_STACK_ACCESS_API 143 select HAVE_REGS_AND_STACK_ACCESS_API
144 select HAVE_HW_BREAKPOINT if PERF_EVENTS && PPC_BOOK3S_64
144 145
145config EARLY_PRINTK 146config EARLY_PRINTK
146 bool 147 bool
@@ -218,7 +219,7 @@ config ARCH_HIBERNATION_POSSIBLE
218config ARCH_SUSPEND_POSSIBLE 219config ARCH_SUSPEND_POSSIBLE
219 def_bool y 220 def_bool y
220 depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \ 221 depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \
221 PPC_85xx || PPC_86xx 222 PPC_85xx || PPC_86xx || PPC_PSERIES
222 223
223config PPC_DCR_NATIVE 224config PPC_DCR_NATIVE
224 bool 225 bool
@@ -668,7 +669,7 @@ config NEED_SG_DMA_LENGTH
668 669
669config GENERIC_ISA_DMA 670config GENERIC_ISA_DMA
670 bool 671 bool
671 depends on PPC64 || POWER4 || 6xx && !CPM2 672 depends on ISA_DMA_API
672 default y 673 default y
673 674
674config PPC_INDIRECT_PCI 675config PPC_INDIRECT_PCI
diff --git a/arch/powerpc/boot/dts/canyonlands.dts b/arch/powerpc/boot/dts/canyonlands.dts
index cd56bb5b347..5806ef0b860 100644
--- a/arch/powerpc/boot/dts/canyonlands.dts
+++ b/arch/powerpc/boot/dts/canyonlands.dts
@@ -270,7 +270,7 @@
270 clock-frequency = <0>; /* Filled in by U-Boot */ 270 clock-frequency = <0>; /* Filled in by U-Boot */
271 current-speed = <0>; /* Filled in by U-Boot */ 271 current-speed = <0>; /* Filled in by U-Boot */
272 interrupt-parent = <&UIC1>; 272 interrupt-parent = <&UIC1>;
273 interrupts = <0x1d 0x4>; 273 interrupts = <28 0x4>;
274 }; 274 };
275 275
276 UART3: serial@ef600600 { 276 UART3: serial@ef600600 {
@@ -281,7 +281,7 @@
281 clock-frequency = <0>; /* Filled in by U-Boot */ 281 clock-frequency = <0>; /* Filled in by U-Boot */
282 current-speed = <0>; /* Filled in by U-Boot */ 282 current-speed = <0>; /* Filled in by U-Boot */
283 interrupt-parent = <&UIC1>; 283 interrupt-parent = <&UIC1>;
284 interrupts = <0x1e 0x4>; 284 interrupts = <29 0x4>;
285 }; 285 };
286 286
287 IIC0: i2c@ef600700 { 287 IIC0: i2c@ef600700 {
diff --git a/arch/powerpc/boot/dts/glacier.dts b/arch/powerpc/boot/dts/glacier.dts
index d62a4fb6f93..e618fc4cbc9 100644
--- a/arch/powerpc/boot/dts/glacier.dts
+++ b/arch/powerpc/boot/dts/glacier.dts
@@ -259,7 +259,7 @@
259 clock-frequency = <0>; /* Filled in by U-Boot */ 259 clock-frequency = <0>; /* Filled in by U-Boot */
260 current-speed = <0>; /* Filled in by U-Boot */ 260 current-speed = <0>; /* Filled in by U-Boot */
261 interrupt-parent = <&UIC1>; 261 interrupt-parent = <&UIC1>;
262 interrupts = <0x1d 0x4>; 262 interrupts = <28 0x4>;
263 }; 263 };
264 264
265 UART3: serial@ef600600 { 265 UART3: serial@ef600600 {
@@ -270,7 +270,7 @@
270 clock-frequency = <0>; /* Filled in by U-Boot */ 270 clock-frequency = <0>; /* Filled in by U-Boot */
271 current-speed = <0>; /* Filled in by U-Boot */ 271 current-speed = <0>; /* Filled in by U-Boot */
272 interrupt-parent = <&UIC1>; 272 interrupt-parent = <&UIC1>;
273 interrupts = <0x1e 0x4>; 273 interrupts = <29 0x4>;
274 }; 274 };
275 275
276 IIC0: i2c@ef600700 { 276 IIC0: i2c@ef600700 {
diff --git a/arch/powerpc/include/asm/abs_addr.h b/arch/powerpc/include/asm/abs_addr.h
index 9a846efe638..5ab0b71531b 100644
--- a/arch/powerpc/include/asm/abs_addr.h
+++ b/arch/powerpc/include/asm/abs_addr.h
@@ -69,7 +69,7 @@ static inline unsigned long phys_to_abs(unsigned long pa)
69 * Legacy iSeries Hypervisor calls 69 * Legacy iSeries Hypervisor calls
70 */ 70 */
71#define iseries_hv_addr(virtaddr) \ 71#define iseries_hv_addr(virtaddr) \
72 (0x8000000000000000 | virt_to_abs(virtaddr)) 72 (0x8000000000000000UL | virt_to_abs(virtaddr))
73 73
74#endif /* __KERNEL__ */ 74#endif /* __KERNEL__ */
75#endif /* _ASM_POWERPC_ABS_ADDR_H */ 75#endif /* _ASM_POWERPC_ABS_ADDR_H */
diff --git a/arch/powerpc/include/asm/asm-compat.h b/arch/powerpc/include/asm/asm-compat.h
index 2048a6aeea9..decad950f11 100644
--- a/arch/powerpc/include/asm/asm-compat.h
+++ b/arch/powerpc/include/asm/asm-compat.h
@@ -30,6 +30,7 @@
30#define PPC_STLCX stringify_in_c(stdcx.) 30#define PPC_STLCX stringify_in_c(stdcx.)
31#define PPC_CNTLZL stringify_in_c(cntlzd) 31#define PPC_CNTLZL stringify_in_c(cntlzd)
32#define PPC_LR_STKOFF 16 32#define PPC_LR_STKOFF 16
33#define PPC_MIN_STKFRM 112
33 34
34/* Move to CR, single-entry optimized version. Only available 35/* Move to CR, single-entry optimized version. Only available
35 * on POWER4 and later. 36 * on POWER4 and later.
@@ -55,6 +56,7 @@
55#define PPC_CNTLZL stringify_in_c(cntlzw) 56#define PPC_CNTLZL stringify_in_c(cntlzw)
56#define PPC_MTOCRF stringify_in_c(mtcrf) 57#define PPC_MTOCRF stringify_in_c(mtcrf)
57#define PPC_LR_STKOFF 4 58#define PPC_LR_STKOFF 4
59#define PPC_MIN_STKFRM 16
58 60
59#endif 61#endif
60 62
diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cputable.h
index b0b21134f61..5e2e2cfcc81 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -517,6 +517,10 @@ static inline int cpu_has_feature(unsigned long feature)
517 & feature); 517 & feature);
518} 518}
519 519
520#ifdef CONFIG_HAVE_HW_BREAKPOINT
521#define HBP_NUM 1
522#endif /* CONFIG_HAVE_HW_BREAKPOINT */
523
520#endif /* !__ASSEMBLY__ */ 524#endif /* !__ASSEMBLY__ */
521 525
522#endif /* __KERNEL__ */ 526#endif /* __KERNEL__ */
diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h
index 501189a543d..0893ab9343a 100644
--- a/arch/powerpc/include/asm/dbell.h
+++ b/arch/powerpc/include/asm/dbell.h
@@ -27,10 +27,10 @@ enum ppc_dbell {
27 PPC_G_DBELL_MC = 4, /* guest mcheck doorbell */ 27 PPC_G_DBELL_MC = 4, /* guest mcheck doorbell */
28}; 28};
29 29
30#ifdef CONFIG_SMP 30extern void doorbell_message_pass(int target, int msg);
31extern unsigned long dbell_smp_message[NR_CPUS]; 31extern void doorbell_exception(struct pt_regs *regs);
32extern void smp_dbell_message_pass(int target, int msg); 32extern void doorbell_check_self(void);
33#endif 33extern void doorbell_setup_this_cpu(void);
34 34
35static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag) 35static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag)
36{ 36{
diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
index 5119b7db314..de03ca58db5 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -74,6 +74,7 @@
74#define H_NOT_ENOUGH_RESOURCES -44 74#define H_NOT_ENOUGH_RESOURCES -44
75#define H_R_STATE -45 75#define H_R_STATE -45
76#define H_RESCINDEND -46 76#define H_RESCINDEND -46
77#define H_MULTI_THREADS_ACTIVE -9005
77 78
78 79
79/* Long Busy is a condition that can be returned by the firmware 80/* Long Busy is a condition that can be returned by the firmware
diff --git a/arch/powerpc/include/asm/hw_breakpoint.h b/arch/powerpc/include/asm/hw_breakpoint.h
new file mode 100644
index 00000000000..1c33ec17ca3
--- /dev/null
+++ b/arch/powerpc/include/asm/hw_breakpoint.h
@@ -0,0 +1,74 @@
1/*
2 * PowerPC BookIII S hardware breakpoint definitions
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright 2010, IBM Corporation.
19 * Author: K.Prasad <prasad@linux.vnet.ibm.com>
20 *
21 */
22
23#ifndef _PPC_BOOK3S_64_HW_BREAKPOINT_H
24#define _PPC_BOOK3S_64_HW_BREAKPOINT_H
25
26#ifdef __KERNEL__
27#ifdef CONFIG_HAVE_HW_BREAKPOINT
28
29struct arch_hw_breakpoint {
30 bool extraneous_interrupt;
31 u8 len; /* length of the target data symbol */
32 int type;
33 unsigned long address;
34};
35
36#include <linux/kdebug.h>
37#include <asm/reg.h>
38#include <asm/system.h>
39
40struct perf_event;
41struct pmu;
42struct perf_sample_data;
43
44#define HW_BREAKPOINT_ALIGN 0x7
45/* Maximum permissible length of any HW Breakpoint */
46#define HW_BREAKPOINT_LEN 0x8
47
48extern int hw_breakpoint_slots(int type);
49extern int arch_bp_generic_fields(int type, int *gen_bp_type);
50extern int arch_check_bp_in_kernelspace(struct perf_event *bp);
51extern int arch_validate_hwbkpt_settings(struct perf_event *bp);
52extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
53 unsigned long val, void *data);
54int arch_install_hw_breakpoint(struct perf_event *bp);
55void arch_uninstall_hw_breakpoint(struct perf_event *bp);
56void hw_breakpoint_pmu_read(struct perf_event *bp);
57extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
58
59extern struct pmu perf_ops_bp;
60extern void ptrace_triggered(struct perf_event *bp, int nmi,
61 struct perf_sample_data *data, struct pt_regs *regs);
62static inline void hw_breakpoint_disable(void)
63{
64 set_dabr(0);
65}
66extern void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs);
67
68#else /* CONFIG_HAVE_HW_BREAKPOINT */
69static inline void hw_breakpoint_disable(void) { }
70static inline void thread_change_pc(struct task_struct *tsk,
71 struct pt_regs *regs) { }
72#endif /* CONFIG_HAVE_HW_BREAKPOINT */
73#endif /* __KERNEL__ */
74#endif /* _PPC_BOOK3S_64_HW_BREAKPOINT_H */
diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h
index 9f0fc9e6ce0..adc8e6cdf33 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -266,6 +266,7 @@ struct machdep_calls {
266 void (*suspend_disable_irqs)(void); 266 void (*suspend_disable_irqs)(void);
267 void (*suspend_enable_irqs)(void); 267 void (*suspend_enable_irqs)(void);
268#endif 268#endif
269 int (*suspend_disable_cpu)(void);
269 270
270#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE 271#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
271 ssize_t (*cpu_probe)(const char *, size_t); 272 ssize_t (*cpu_probe)(const char *, size_t);
@@ -277,6 +278,7 @@ extern void e500_idle(void);
277extern void power4_idle(void); 278extern void power4_idle(void);
278extern void power4_cpu_offline_powersave(void); 279extern void power4_cpu_offline_powersave(void);
279extern void ppc6xx_idle(void); 280extern void ppc6xx_idle(void);
281extern void book3e_idle(void);
280 282
281/* 283/*
282 * ppc_md contains a copy of the machine description structure for the 284 * ppc_md contains a copy of the machine description structure for the
@@ -366,8 +368,5 @@ static inline void log_error(char *buf, unsigned int err_type, int fatal)
366#define machine_late_initcall(mach,fn) __define_machine_initcall(mach,"7",fn,7) 368#define machine_late_initcall(mach,fn) __define_machine_initcall(mach,"7",fn,7)
367#define machine_late_initcall_sync(mach,fn) __define_machine_initcall(mach,"7s",fn,7s) 369#define machine_late_initcall_sync(mach,fn) __define_machine_initcall(mach,"7s",fn,7s)
368 370
369void generic_suspend_disable_irqs(void);
370void generic_suspend_enable_irqs(void);
371
372#endif /* __KERNEL__ */ 371#endif /* __KERNEL__ */
373#endif /* _ASM_POWERPC_MACHDEP_H */ 372#endif /* _ASM_POWERPC_MACHDEP_H */
diff --git a/arch/powerpc/include/asm/mmu-book3e.h b/arch/powerpc/include/asm/mmu-book3e.h
index 74695816205..87a1d787c5b 100644
--- a/arch/powerpc/include/asm/mmu-book3e.h
+++ b/arch/powerpc/include/asm/mmu-book3e.h
@@ -193,6 +193,10 @@ struct mmu_psize_def
193{ 193{
194 unsigned int shift; /* number of bits */ 194 unsigned int shift; /* number of bits */
195 unsigned int enc; /* PTE encoding */ 195 unsigned int enc; /* PTE encoding */
196 unsigned int ind; /* Corresponding indirect page size shift */
197 unsigned int flags;
198#define MMU_PAGE_SIZE_DIRECT 0x1 /* Supported as a direct size */
199#define MMU_PAGE_SIZE_INDIRECT 0x2 /* Supported as an indirect size */
196}; 200};
197extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT]; 201extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
198 202
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 8ce7963ad41..1ff6662f7fa 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -146,7 +146,7 @@ struct paca_struct {
146extern struct paca_struct *paca; 146extern struct paca_struct *paca;
147extern __initdata struct paca_struct boot_paca; 147extern __initdata struct paca_struct boot_paca;
148extern void initialise_paca(struct paca_struct *new_paca, int cpu); 148extern void initialise_paca(struct paca_struct *new_paca, int cpu);
149 149extern void setup_paca(struct paca_struct *new_paca);
150extern void allocate_pacas(void); 150extern void allocate_pacas(void);
151extern void free_unused_pacas(void); 151extern void free_unused_pacas(void);
152 152
diff --git a/arch/powerpc/include/asm/percpu.h b/arch/powerpc/include/asm/percpu.h
index f879252b7ea..2cedefddba3 100644
--- a/arch/powerpc/include/asm/percpu.h
+++ b/arch/powerpc/include/asm/percpu.h
@@ -1,7 +1,6 @@
1#ifndef _ASM_POWERPC_PERCPU_H_ 1#ifndef _ASM_POWERPC_PERCPU_H_
2#define _ASM_POWERPC_PERCPU_H_ 2#define _ASM_POWERPC_PERCPU_H_
3#ifdef __powerpc64__ 3#ifdef __powerpc64__
4#include <linux/compiler.h>
5 4
6/* 5/*
7 * Same as asm-generic/percpu.h, except that we store the per cpu offset 6 * Same as asm-generic/percpu.h, except that we store the per cpu offset
@@ -12,9 +11,7 @@
12 11
13#include <asm/paca.h> 12#include <asm/paca.h>
14 13
15#define __per_cpu_offset(cpu) (paca[cpu].data_offset)
16#define __my_cpu_offset local_paca->data_offset 14#define __my_cpu_offset local_paca->data_offset
17#define per_cpu_offset(x) (__per_cpu_offset(x))
18 15
19#endif /* CONFIG_SMP */ 16#endif /* CONFIG_SMP */
20#endif /* __powerpc64__ */ 17#endif /* __powerpc64__ */
diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index d553bbeb726..43adc8b819e 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -52,13 +52,17 @@
52#define PPC_INST_WAIT 0x7c00007c 52#define PPC_INST_WAIT 0x7c00007c
53#define PPC_INST_TLBIVAX 0x7c000624 53#define PPC_INST_TLBIVAX 0x7c000624
54#define PPC_INST_TLBSRX_DOT 0x7c0006a5 54#define PPC_INST_TLBSRX_DOT 0x7c0006a5
55#define PPC_INST_XXLOR 0xf0000510
55 56
56/* macros to insert fields into opcodes */ 57/* macros to insert fields into opcodes */
57#define __PPC_RA(a) (((a) & 0x1f) << 16) 58#define __PPC_RA(a) (((a) & 0x1f) << 16)
58#define __PPC_RB(b) (((b) & 0x1f) << 11) 59#define __PPC_RB(b) (((b) & 0x1f) << 11)
59#define __PPC_RS(s) (((s) & 0x1f) << 21) 60#define __PPC_RS(s) (((s) & 0x1f) << 21)
60#define __PPC_RT(s) __PPC_RS(s) 61#define __PPC_RT(s) __PPC_RS(s)
62#define __PPC_XA(a) ((((a) & 0x1f) << 16) | (((a) & 0x20) >> 3))
63#define __PPC_XB(b) ((((b) & 0x1f) << 11) | (((b) & 0x20) >> 4))
61#define __PPC_XS(s) ((((s) & 0x1f) << 21) | (((s) & 0x20) >> 5)) 64#define __PPC_XS(s) ((((s) & 0x1f) << 21) | (((s) & 0x20) >> 5))
65#define __PPC_XT(s) __PPC_XS(s)
62#define __PPC_T_TLB(t) (((t) & 0x3) << 21) 66#define __PPC_T_TLB(t) (((t) & 0x3) << 21)
63#define __PPC_WC(w) (((w) & 0x3) << 21) 67#define __PPC_WC(w) (((w) & 0x3) << 21)
64/* 68/*
@@ -106,9 +110,12 @@
106 * the 128 bit load store instructions based on that. 110 * the 128 bit load store instructions based on that.
107 */ 111 */
108#define VSX_XX1(s, a, b) (__PPC_XS(s) | __PPC_RA(a) | __PPC_RB(b)) 112#define VSX_XX1(s, a, b) (__PPC_XS(s) | __PPC_RA(a) | __PPC_RB(b))
113#define VSX_XX3(t, a, b) (__PPC_XT(t) | __PPC_XA(a) | __PPC_XB(b))
109#define STXVD2X(s, a, b) stringify_in_c(.long PPC_INST_STXVD2X | \ 114#define STXVD2X(s, a, b) stringify_in_c(.long PPC_INST_STXVD2X | \
110 VSX_XX1((s), (a), (b))) 115 VSX_XX1((s), (a), (b)))
111#define LXVD2X(s, a, b) stringify_in_c(.long PPC_INST_LXVD2X | \ 116#define LXVD2X(s, a, b) stringify_in_c(.long PPC_INST_LXVD2X | \
112 VSX_XX1((s), (a), (b))) 117 VSX_XX1((s), (a), (b)))
118#define XXLOR(t, a, b) stringify_in_c(.long PPC_INST_XXLOR | \
119 VSX_XX3((t), (a), (b)))
113 120
114#endif /* _ASM_POWERPC_PPC_OPCODE_H */ 121#endif /* _ASM_POWERPC_PPC_OPCODE_H */
diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index 7492fe8ad6e..19c05b0f74b 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -209,6 +209,14 @@ struct thread_struct {
209#ifdef CONFIG_PPC64 209#ifdef CONFIG_PPC64
210 unsigned long start_tb; /* Start purr when proc switched in */ 210 unsigned long start_tb; /* Start purr when proc switched in */
211 unsigned long accum_tb; /* Total accumilated purr for process */ 211 unsigned long accum_tb; /* Total accumilated purr for process */
212#ifdef CONFIG_HAVE_HW_BREAKPOINT
213 struct perf_event *ptrace_bps[HBP_NUM];
214 /*
215 * Helps identify source of single-step exception and subsequent
216 * hw-breakpoint enablement
217 */
218 struct perf_event *last_hit_ubp;
219#endif /* CONFIG_HAVE_HW_BREAKPOINT */
212#endif 220#endif
213 unsigned long dabr; /* Data address breakpoint register */ 221 unsigned long dabr; /* Data address breakpoint register */
214#ifdef CONFIG_ALTIVEC 222#ifdef CONFIG_ALTIVEC
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index d62fdf4e504..d8be016d2ed 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -890,7 +890,7 @@
890#ifndef __ASSEMBLY__ 890#ifndef __ASSEMBLY__
891#define mfmsr() ({unsigned long rval; \ 891#define mfmsr() ({unsigned long rval; \
892 asm volatile("mfmsr %0" : "=r" (rval)); rval;}) 892 asm volatile("mfmsr %0" : "=r" (rval)); rval;})
893#ifdef CONFIG_PPC64 893#ifdef CONFIG_PPC_BOOK3S_64
894#define __mtmsrd(v, l) asm volatile("mtmsrd %0," __stringify(l) \ 894#define __mtmsrd(v, l) asm volatile("mtmsrd %0," __stringify(l) \
895 : : "r" (v) : "memory") 895 : : "r" (v) : "memory")
896#define mtmsrd(v) __mtmsrd((v), 0) 896#define mtmsrd(v) __mtmsrd((v), 0)
diff --git a/arch/powerpc/include/asm/reg_booke.h b/arch/powerpc/include/asm/reg_booke.h
index 2360317179a..667a498eaee 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -29,8 +29,8 @@
29#if defined(CONFIG_PPC_BOOK3E_64) 29#if defined(CONFIG_PPC_BOOK3E_64)
30#define MSR_ MSR_ME | MSR_CE 30#define MSR_ MSR_ME | MSR_CE
31#define MSR_KERNEL MSR_ | MSR_CM 31#define MSR_KERNEL MSR_ | MSR_CM
32#define MSR_USER32 MSR_ | MSR_PR | MSR_EE 32#define MSR_USER32 MSR_ | MSR_PR | MSR_EE | MSR_DE
33#define MSR_USER64 MSR_USER32 | MSR_CM 33#define MSR_USER64 MSR_USER32 | MSR_CM | MSR_DE
34#elif defined (CONFIG_40x) 34#elif defined (CONFIG_40x)
35#define MSR_KERNEL (MSR_ME|MSR_RI|MSR_IR|MSR_DR|MSR_CE) 35#define MSR_KERNEL (MSR_ME|MSR_RI|MSR_IR|MSR_DR|MSR_CE)
36#define MSR_USER (MSR_KERNEL|MSR_PR|MSR_EE) 36#define MSR_USER (MSR_KERNEL|MSR_PR|MSR_EE)
@@ -62,6 +62,7 @@
62#define SPRN_TLB0PS 0x158 /* TLB 0 Page Size Register */ 62#define SPRN_TLB0PS 0x158 /* TLB 0 Page Size Register */
63#define SPRN_MAS5_MAS6 0x15c /* MMU Assist Register 5 || 6 */ 63#define SPRN_MAS5_MAS6 0x15c /* MMU Assist Register 5 || 6 */
64#define SPRN_MAS8_MAS1 0x15d /* MMU Assist Register 8 || 1 */ 64#define SPRN_MAS8_MAS1 0x15d /* MMU Assist Register 8 || 1 */
65#define SPRN_EPTCFG 0x15e /* Embedded Page Table Config */
65#define SPRN_MAS7_MAS3 0x174 /* MMU Assist Register 7 || 3 */ 66#define SPRN_MAS7_MAS3 0x174 /* MMU Assist Register 7 || 3 */
66#define SPRN_MAS0_MAS1 0x175 /* MMU Assist Register 0 || 1 */ 67#define SPRN_MAS0_MAS1 0x175 /* MMU Assist Register 0 || 1 */
67#define SPRN_IVOR0 0x190 /* Interrupt Vector Offset Register 0 */ 68#define SPRN_IVOR0 0x190 /* Interrupt Vector Offset Register 0 */
diff --git a/arch/powerpc/include/asm/rtas.h b/arch/powerpc/include/asm/rtas.h
index 20de73c3668..3d35f8ae377 100644
--- a/arch/powerpc/include/asm/rtas.h
+++ b/arch/powerpc/include/asm/rtas.h
@@ -63,6 +63,14 @@ struct rtas_t {
63 struct device_node *dev; /* virtual address pointer */ 63 struct device_node *dev; /* virtual address pointer */
64}; 64};
65 65
66struct rtas_suspend_me_data {
67 atomic_t working; /* number of cpus accessing this struct */
68 atomic_t done;
69 int token; /* ibm,suspend-me */
70 atomic_t error;
71 struct completion *complete; /* wait on this until working == 0 */
72};
73
66/* RTAS event classes */ 74/* RTAS event classes */
67#define RTAS_INTERNAL_ERROR 0x80000000 /* set bit 0 */ 75#define RTAS_INTERNAL_ERROR 0x80000000 /* set bit 0 */
68#define RTAS_EPOW_WARNING 0x40000000 /* set bit 1 */ 76#define RTAS_EPOW_WARNING 0x40000000 /* set bit 1 */
@@ -137,6 +145,9 @@ struct rtas_t {
137#define RTAS_TYPE_PMGM_CONFIG_CHANGE 0x70 145#define RTAS_TYPE_PMGM_CONFIG_CHANGE 0x70
138#define RTAS_TYPE_PMGM_SERVICE_PROC 0x71 146#define RTAS_TYPE_PMGM_SERVICE_PROC 0x71
139 147
148/* RTAS check-exception vector offset */
149#define RTAS_VECTOR_EXTERNAL_INTERRUPT 0x500
150
140struct rtas_error_log { 151struct rtas_error_log {
141 unsigned long version:8; /* Architectural version */ 152 unsigned long version:8; /* Architectural version */
142 unsigned long severity:3; /* Severity level of error */ 153 unsigned long severity:3; /* Severity level of error */
@@ -174,6 +185,8 @@ extern int rtas_set_indicator(int indicator, int index, int new_value);
174extern int rtas_set_indicator_fast(int indicator, int index, int new_value); 185extern int rtas_set_indicator_fast(int indicator, int index, int new_value);
175extern void rtas_progress(char *s, unsigned short hex); 186extern void rtas_progress(char *s, unsigned short hex);
176extern void rtas_initialize(void); 187extern void rtas_initialize(void);
188extern int rtas_suspend_cpu(struct rtas_suspend_me_data *data);
189extern int rtas_suspend_last_cpu(struct rtas_suspend_me_data *data);
177 190
178struct rtc_time; 191struct rtc_time;
179extern unsigned long rtas_get_boot_time(void); 192extern unsigned long rtas_get_boot_time(void);
diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
index 27ccb764fda..dc779dfcf25 100644
--- a/arch/powerpc/include/asm/time.h
+++ b/arch/powerpc/include/asm/time.h
@@ -28,16 +28,12 @@
28extern unsigned long tb_ticks_per_jiffy; 28extern unsigned long tb_ticks_per_jiffy;
29extern unsigned long tb_ticks_per_usec; 29extern unsigned long tb_ticks_per_usec;
30extern unsigned long tb_ticks_per_sec; 30extern unsigned long tb_ticks_per_sec;
31extern u64 tb_to_xs;
32extern unsigned tb_to_us;
33 31
34struct rtc_time; 32struct rtc_time;
35extern void to_tm(int tim, struct rtc_time * tm); 33extern void to_tm(int tim, struct rtc_time * tm);
36extern void GregorianDay(struct rtc_time *tm); 34extern void GregorianDay(struct rtc_time *tm);
37extern time_t last_rtc_update;
38 35
39extern void generic_calibrate_decr(void); 36extern void generic_calibrate_decr(void);
40extern void wakeup_decrementer(void);
41extern void snapshot_timebase(void); 37extern void snapshot_timebase(void);
42 38
43extern void set_dec_cpu6(unsigned int val); 39extern void set_dec_cpu6(unsigned int val);
@@ -204,9 +200,6 @@ static inline unsigned long tb_ticks_since(unsigned long tstamp)
204extern u64 mulhdu(u64, u64); 200extern u64 mulhdu(u64, u64);
205#endif 201#endif
206 202
207extern void smp_space_timers(unsigned int);
208
209extern unsigned mulhwu_scale_factor(unsigned, unsigned);
210extern void div128_by_32(u64 dividend_high, u64 dividend_low, 203extern void div128_by_32(u64 dividend_high, u64 dividend_low,
211 unsigned divisor, struct div_result *dr); 204 unsigned divisor, struct div_result *dr);
212 205
diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 32adf728072..3033c1b3074 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -87,6 +87,9 @@ static inline int pcibus_to_node(struct pci_bus *bus)
87 .balance_interval = 1, \ 87 .balance_interval = 1, \
88} 88}
89 89
90extern int __node_distance(int, int);
91#define node_distance(a, b) __node_distance(a, b)
92
90extern void __init dump_numa_cpu_topology(void); 93extern void __init dump_numa_cpu_topology(void);
91 94
92extern int sysfs_add_device_to_node(struct sys_device *dev, int nid); 95extern int sysfs_add_device_to_node(struct sys_device *dev, int nid);
diff --git a/arch/powerpc/include/asm/vdso_datapage.h b/arch/powerpc/include/asm/vdso_datapage.h
index 13c2c283e17..08679c5319b 100644
--- a/arch/powerpc/include/asm/vdso_datapage.h
+++ b/arch/powerpc/include/asm/vdso_datapage.h
@@ -85,6 +85,7 @@ struct vdso_data {
85 __s32 wtom_clock_sec; /* Wall to monotonic clock */ 85 __s32 wtom_clock_sec; /* Wall to monotonic clock */
86 __s32 wtom_clock_nsec; 86 __s32 wtom_clock_nsec;
87 struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */ 87 struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */
88 __u32 stamp_sec_fraction; /* fractional seconds of stamp_xtime */
88 __u32 syscall_map_64[SYSCALL_MAP_SIZE]; /* map of syscalls */ 89 __u32 syscall_map_64[SYSCALL_MAP_SIZE]; /* map of syscalls */
89 __u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */ 90 __u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
90}; 91};
@@ -105,6 +106,7 @@ struct vdso_data {
105 __s32 wtom_clock_sec; /* Wall to monotonic clock */ 106 __s32 wtom_clock_sec; /* Wall to monotonic clock */
106 __s32 wtom_clock_nsec; 107 __s32 wtom_clock_nsec;
107 struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */ 108 struct timespec stamp_xtime; /* xtime as at tb_orig_stamp */
109 __u32 stamp_sec_fraction; /* fractional seconds of stamp_xtime */
108 __u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */ 110 __u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
109 __u32 dcache_block_size; /* L1 d-cache block size */ 111 __u32 dcache_block_size; /* L1 d-cache block size */
110 __u32 icache_block_size; /* L1 i-cache block size */ 112 __u32 icache_block_size; /* L1 i-cache block size */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 58d0572de6f..77d831a1cc3 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -34,9 +34,10 @@ obj-y += vdso32/
34obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \ 34obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \
35 signal_64.o ptrace32.o \ 35 signal_64.o ptrace32.o \
36 paca.o nvram_64.o firmware.o 36 paca.o nvram_64.o firmware.o
37obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
37obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o 38obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o
38obj64-$(CONFIG_RELOCATABLE) += reloc_64.o 39obj64-$(CONFIG_RELOCATABLE) += reloc_64.o
39obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o 40obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o
40obj-$(CONFIG_PPC64) += vdso64/ 41obj-$(CONFIG_PPC64) += vdso64/
41obj-$(CONFIG_ALTIVEC) += vecemu.o 42obj-$(CONFIG_ALTIVEC) += vecemu.o
42obj-$(CONFIG_PPC_970_NAP) += idle_power4.o 43obj-$(CONFIG_PPC_970_NAP) += idle_power4.o
@@ -67,6 +68,7 @@ obj64-$(CONFIG_HIBERNATION) += swsusp_asm64.o
67obj-$(CONFIG_MODULES) += module.o module_$(CONFIG_WORD_SIZE).o 68obj-$(CONFIG_MODULES) += module.o module_$(CONFIG_WORD_SIZE).o
68obj-$(CONFIG_44x) += cpu_setup_44x.o 69obj-$(CONFIG_44x) += cpu_setup_44x.o
69obj-$(CONFIG_FSL_BOOKE) += cpu_setup_fsl_booke.o dbell.o 70obj-$(CONFIG_FSL_BOOKE) += cpu_setup_fsl_booke.o dbell.o
71obj-$(CONFIG_PPC_BOOK3E_64) += dbell.o
70 72
71extra-y := head_$(CONFIG_WORD_SIZE).o 73extra-y := head_$(CONFIG_WORD_SIZE).o
72extra-$(CONFIG_PPC_BOOK3E_32) := head_new_booke.o 74extra-$(CONFIG_PPC_BOOK3E_32) := head_new_booke.o
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 496cc5b3984..1c0607ddccc 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -194,7 +194,6 @@ int main(void)
194 DEFINE(PACA_STARTSPURR, offsetof(struct paca_struct, startspurr)); 194 DEFINE(PACA_STARTSPURR, offsetof(struct paca_struct, startspurr));
195 DEFINE(PACA_USER_TIME, offsetof(struct paca_struct, user_time)); 195 DEFINE(PACA_USER_TIME, offsetof(struct paca_struct, user_time));
196 DEFINE(PACA_SYSTEM_TIME, offsetof(struct paca_struct, system_time)); 196 DEFINE(PACA_SYSTEM_TIME, offsetof(struct paca_struct, system_time));
197 DEFINE(PACA_DATA_OFFSET, offsetof(struct paca_struct, data_offset));
198 DEFINE(PACA_TRAP_SAVE, offsetof(struct paca_struct, trap_save)); 197 DEFINE(PACA_TRAP_SAVE, offsetof(struct paca_struct, trap_save));
199#ifdef CONFIG_KVM_BOOK3S_64_HANDLER 198#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
200 DEFINE(PACA_KVM_SVCPU, offsetof(struct paca_struct, shadow_vcpu)); 199 DEFINE(PACA_KVM_SVCPU, offsetof(struct paca_struct, shadow_vcpu));
@@ -342,6 +341,7 @@ int main(void)
342 DEFINE(WTOM_CLOCK_SEC, offsetof(struct vdso_data, wtom_clock_sec)); 341 DEFINE(WTOM_CLOCK_SEC, offsetof(struct vdso_data, wtom_clock_sec));
343 DEFINE(WTOM_CLOCK_NSEC, offsetof(struct vdso_data, wtom_clock_nsec)); 342 DEFINE(WTOM_CLOCK_NSEC, offsetof(struct vdso_data, wtom_clock_nsec));
344 DEFINE(STAMP_XTIME, offsetof(struct vdso_data, stamp_xtime)); 343 DEFINE(STAMP_XTIME, offsetof(struct vdso_data, stamp_xtime));
344 DEFINE(STAMP_SEC_FRAC, offsetof(struct vdso_data, stamp_sec_fraction));
345 DEFINE(CFG_ICACHE_BLOCKSZ, offsetof(struct vdso_data, icache_block_size)); 345 DEFINE(CFG_ICACHE_BLOCKSZ, offsetof(struct vdso_data, icache_block_size));
346 DEFINE(CFG_DCACHE_BLOCKSZ, offsetof(struct vdso_data, dcache_block_size)); 346 DEFINE(CFG_DCACHE_BLOCKSZ, offsetof(struct vdso_data, dcache_block_size));
347 DEFINE(CFG_ICACHE_LOGBLOCKSZ, offsetof(struct vdso_data, icache_log_block_size)); 347 DEFINE(CFG_ICACHE_LOGBLOCKSZ, offsetof(struct vdso_data, icache_log_block_size));
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 87aa0f3c604..65e2b4e10f9 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -1364,10 +1364,10 @@ static struct cpu_spec __initdata cpu_specs[] = {
1364 .machine_check = machine_check_4xx, 1364 .machine_check = machine_check_4xx,
1365 .platform = "ppc405", 1365 .platform = "ppc405",
1366 }, 1366 },
1367 { /* 405EX */ 1367 { /* 405EX Rev. A/B with Security */
1368 .pvr_mask = 0xffff0004, 1368 .pvr_mask = 0xffff000f,
1369 .pvr_value = 0x12910004, 1369 .pvr_value = 0x12910007,
1370 .cpu_name = "405EX", 1370 .cpu_name = "405EX Rev. A/B",
1371 .cpu_features = CPU_FTRS_40X, 1371 .cpu_features = CPU_FTRS_40X,
1372 .cpu_user_features = PPC_FEATURE_32 | 1372 .cpu_user_features = PPC_FEATURE_32 |
1373 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC, 1373 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
@@ -1377,10 +1377,114 @@ static struct cpu_spec __initdata cpu_specs[] = {
1377 .machine_check = machine_check_4xx, 1377 .machine_check = machine_check_4xx,
1378 .platform = "ppc405", 1378 .platform = "ppc405",
1379 }, 1379 },
1380 { /* 405EXr */ 1380 { /* 405EX Rev. C without Security */
1381 .pvr_mask = 0xffff0004, 1381 .pvr_mask = 0xffff000f,
1382 .pvr_value = 0x1291000d,
1383 .cpu_name = "405EX Rev. C",
1384 .cpu_features = CPU_FTRS_40X,
1385 .cpu_user_features = PPC_FEATURE_32 |
1386 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1387 .mmu_features = MMU_FTR_TYPE_40x,
1388 .icache_bsize = 32,
1389 .dcache_bsize = 32,
1390 .machine_check = machine_check_4xx,
1391 .platform = "ppc405",
1392 },
1393 { /* 405EX Rev. C with Security */
1394 .pvr_mask = 0xffff000f,
1395 .pvr_value = 0x1291000f,
1396 .cpu_name = "405EX Rev. C",
1397 .cpu_features = CPU_FTRS_40X,
1398 .cpu_user_features = PPC_FEATURE_32 |
1399 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1400 .mmu_features = MMU_FTR_TYPE_40x,
1401 .icache_bsize = 32,
1402 .dcache_bsize = 32,
1403 .machine_check = machine_check_4xx,
1404 .platform = "ppc405",
1405 },
1406 { /* 405EX Rev. D without Security */
1407 .pvr_mask = 0xffff000f,
1408 .pvr_value = 0x12910003,
1409 .cpu_name = "405EX Rev. D",
1410 .cpu_features = CPU_FTRS_40X,
1411 .cpu_user_features = PPC_FEATURE_32 |
1412 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1413 .mmu_features = MMU_FTR_TYPE_40x,
1414 .icache_bsize = 32,
1415 .dcache_bsize = 32,
1416 .machine_check = machine_check_4xx,
1417 .platform = "ppc405",
1418 },
1419 { /* 405EX Rev. D with Security */
1420 .pvr_mask = 0xffff000f,
1421 .pvr_value = 0x12910005,
1422 .cpu_name = "405EX Rev. D",
1423 .cpu_features = CPU_FTRS_40X,
1424 .cpu_user_features = PPC_FEATURE_32 |
1425 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1426 .mmu_features = MMU_FTR_TYPE_40x,
1427 .icache_bsize = 32,
1428 .dcache_bsize = 32,
1429 .machine_check = machine_check_4xx,
1430 .platform = "ppc405",
1431 },
1432 { /* 405EXr Rev. A/B without Security */
1433 .pvr_mask = 0xffff000f,
1434 .pvr_value = 0x12910001,
1435 .cpu_name = "405EXr Rev. A/B",
1436 .cpu_features = CPU_FTRS_40X,
1437 .cpu_user_features = PPC_FEATURE_32 |
1438 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1439 .mmu_features = MMU_FTR_TYPE_40x,
1440 .icache_bsize = 32,
1441 .dcache_bsize = 32,
1442 .machine_check = machine_check_4xx,
1443 .platform = "ppc405",
1444 },
1445 { /* 405EXr Rev. C without Security */
1446 .pvr_mask = 0xffff000f,
1447 .pvr_value = 0x12910009,
1448 .cpu_name = "405EXr Rev. C",
1449 .cpu_features = CPU_FTRS_40X,
1450 .cpu_user_features = PPC_FEATURE_32 |
1451 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1452 .mmu_features = MMU_FTR_TYPE_40x,
1453 .icache_bsize = 32,
1454 .dcache_bsize = 32,
1455 .machine_check = machine_check_4xx,
1456 .platform = "ppc405",
1457 },
1458 { /* 405EXr Rev. C with Security */
1459 .pvr_mask = 0xffff000f,
1460 .pvr_value = 0x1291000b,
1461 .cpu_name = "405EXr Rev. C",
1462 .cpu_features = CPU_FTRS_40X,
1463 .cpu_user_features = PPC_FEATURE_32 |
1464 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1465 .mmu_features = MMU_FTR_TYPE_40x,
1466 .icache_bsize = 32,
1467 .dcache_bsize = 32,
1468 .machine_check = machine_check_4xx,
1469 .platform = "ppc405",
1470 },
1471 { /* 405EXr Rev. D without Security */
1472 .pvr_mask = 0xffff000f,
1382 .pvr_value = 0x12910000, 1473 .pvr_value = 0x12910000,
1383 .cpu_name = "405EXr", 1474 .cpu_name = "405EXr Rev. D",
1475 .cpu_features = CPU_FTRS_40X,
1476 .cpu_user_features = PPC_FEATURE_32 |
1477 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
1478 .mmu_features = MMU_FTR_TYPE_40x,
1479 .icache_bsize = 32,
1480 .dcache_bsize = 32,
1481 .machine_check = machine_check_4xx,
1482 .platform = "ppc405",
1483 },
1484 { /* 405EXr Rev. D with Security */
1485 .pvr_mask = 0xffff000f,
1486 .pvr_value = 0x12910002,
1487 .cpu_name = "405EXr Rev. D",
1384 .cpu_features = CPU_FTRS_40X, 1488 .cpu_features = CPU_FTRS_40X,
1385 .cpu_user_features = PPC_FEATURE_32 | 1489 .cpu_user_features = PPC_FEATURE_32 |
1386 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC, 1490 PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_4xxMAC,
diff --git a/arch/powerpc/kernel/crash_dump.c b/arch/powerpc/kernel/crash_dump.c
index 40f524643ba..8e05c16344e 100644
--- a/arch/powerpc/kernel/crash_dump.c
+++ b/arch/powerpc/kernel/crash_dump.c
@@ -128,9 +128,9 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
128 if (!csize) 128 if (!csize)
129 return 0; 129 return 0;
130 130
131 csize = min(csize, PAGE_SIZE); 131 csize = min_t(size_t, csize, PAGE_SIZE);
132 132
133 if (pfn < max_pfn) { 133 if ((min_low_pfn < pfn) && (pfn < max_pfn)) {
134 vaddr = __va(pfn << PAGE_SHIFT); 134 vaddr = __va(pfn << PAGE_SHIFT);
135 csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf); 135 csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf);
136 } else { 136 } else {
diff --git a/arch/powerpc/kernel/dbell.c b/arch/powerpc/kernel/dbell.c
index 1493734cd87..3307a52d797 100644
--- a/arch/powerpc/kernel/dbell.c
+++ b/arch/powerpc/kernel/dbell.c
@@ -13,32 +13,88 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/smp.h> 14#include <linux/smp.h>
15#include <linux/threads.h> 15#include <linux/threads.h>
16#include <linux/percpu.h>
16 17
17#include <asm/dbell.h> 18#include <asm/dbell.h>
19#include <asm/irq_regs.h>
18 20
19#ifdef CONFIG_SMP 21#ifdef CONFIG_SMP
20unsigned long dbell_smp_message[NR_CPUS]; 22struct doorbell_cpu_info {
23 unsigned long messages; /* current messages bits */
24 unsigned int tag; /* tag value */
25};
21 26
22void smp_dbell_message_pass(int target, int msg) 27static DEFINE_PER_CPU(struct doorbell_cpu_info, doorbell_cpu_info);
28
29void doorbell_setup_this_cpu(void)
30{
31 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
32
33 info->messages = 0;
34 info->tag = mfspr(SPRN_PIR) & 0x3fff;
35}
36
37void doorbell_message_pass(int target, int msg)
23{ 38{
39 struct doorbell_cpu_info *info;
24 int i; 40 int i;
25 41
26 if(target < NR_CPUS) { 42 if (target < NR_CPUS) {
27 set_bit(msg, &dbell_smp_message[target]); 43 info = &per_cpu(doorbell_cpu_info, target);
28 ppc_msgsnd(PPC_DBELL, 0, target); 44 set_bit(msg, &info->messages);
45 ppc_msgsnd(PPC_DBELL, 0, info->tag);
29 } 46 }
30 else if(target == MSG_ALL_BUT_SELF) { 47 else if (target == MSG_ALL_BUT_SELF) {
31 for_each_online_cpu(i) { 48 for_each_online_cpu(i) {
32 if (i == smp_processor_id()) 49 if (i == smp_processor_id())
33 continue; 50 continue;
34 set_bit(msg, &dbell_smp_message[i]); 51 info = &per_cpu(doorbell_cpu_info, i);
35 ppc_msgsnd(PPC_DBELL, 0, i); 52 set_bit(msg, &info->messages);
53 ppc_msgsnd(PPC_DBELL, 0, info->tag);
36 } 54 }
37 } 55 }
38 else { /* target == MSG_ALL */ 56 else { /* target == MSG_ALL */
39 for_each_online_cpu(i) 57 for_each_online_cpu(i) {
40 set_bit(msg, &dbell_smp_message[i]); 58 info = &per_cpu(doorbell_cpu_info, i);
59 set_bit(msg, &info->messages);
60 }
41 ppc_msgsnd(PPC_DBELL, PPC_DBELL_MSG_BRDCAST, 0); 61 ppc_msgsnd(PPC_DBELL, PPC_DBELL_MSG_BRDCAST, 0);
42 } 62 }
43} 63}
44#endif 64
65void doorbell_exception(struct pt_regs *regs)
66{
67 struct pt_regs *old_regs = set_irq_regs(regs);
68 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
69 int msg;
70
71 /* Warning: regs can be NULL when called from irq enable */
72
73 if (!info->messages || (num_online_cpus() < 2))
74 goto out;
75
76 for (msg = 0; msg < 4; msg++)
77 if (test_and_clear_bit(msg, &info->messages))
78 smp_message_recv(msg);
79
80out:
81 set_irq_regs(old_regs);
82}
83
84void doorbell_check_self(void)
85{
86 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
87
88 if (!info->messages)
89 return;
90
91 ppc_msgsnd(PPC_DBELL, 0, info->tag);
92}
93
94#else /* CONFIG_SMP */
95void doorbell_exception(struct pt_regs *regs)
96{
97 printk(KERN_WARNING "Received doorbell on non-smp system\n");
98}
99#endif /* CONFIG_SMP */
100
diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
index 24dcc0ecf24..5c43063d250 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -191,6 +191,12 @@ exc_##n##_bad_stack: \
191 sth r1,PACA_TRAP_SAVE(r13); /* store trap */ \ 191 sth r1,PACA_TRAP_SAVE(r13); /* store trap */ \
192 b bad_stack_book3e; /* bad stack error */ 192 b bad_stack_book3e; /* bad stack error */
193 193
194/* WARNING: If you change the layout of this stub, make sure you chcek
195 * the debug exception handler which handles single stepping
196 * into exceptions from userspace, and the MM code in
197 * arch/powerpc/mm/tlb_nohash.c which patches the branch here
198 * and would need to be updated if that branch is moved
199 */
194#define EXCEPTION_STUB(loc, label) \ 200#define EXCEPTION_STUB(loc, label) \
195 . = interrupt_base_book3e + loc; \ 201 . = interrupt_base_book3e + loc; \
196 nop; /* To make debug interrupts happy */ \ 202 nop; /* To make debug interrupts happy */ \
@@ -204,11 +210,30 @@ exc_##n##_bad_stack: \
204 lis r,TSR_FIS@h; \ 210 lis r,TSR_FIS@h; \
205 mtspr SPRN_TSR,r 211 mtspr SPRN_TSR,r
206 212
213/* Used by asynchronous interrupt that may happen in the idle loop.
214 *
215 * This check if the thread was in the idle loop, and if yes, returns
216 * to the caller rather than the PC. This is to avoid a race if
217 * interrupts happen before the wait instruction.
218 */
219#define CHECK_NAPPING() \
220 clrrdi r11,r1,THREAD_SHIFT; \
221 ld r10,TI_LOCAL_FLAGS(r11); \
222 andi. r9,r10,_TLF_NAPPING; \
223 beq+ 1f; \
224 ld r8,_LINK(r1); \
225 rlwinm r7,r10,0,~_TLF_NAPPING; \
226 std r8,_NIP(r1); \
227 std r7,TI_LOCAL_FLAGS(r11); \
2281:
229
230
207#define MASKABLE_EXCEPTION(trapnum, label, hdlr, ack) \ 231#define MASKABLE_EXCEPTION(trapnum, label, hdlr, ack) \
208 START_EXCEPTION(label); \ 232 START_EXCEPTION(label); \
209 NORMAL_EXCEPTION_PROLOG(trapnum, PROLOG_ADDITION_MASKABLE) \ 233 NORMAL_EXCEPTION_PROLOG(trapnum, PROLOG_ADDITION_MASKABLE) \
210 EXCEPTION_COMMON(trapnum, PACA_EXGEN, INTS_DISABLE_ALL) \ 234 EXCEPTION_COMMON(trapnum, PACA_EXGEN, INTS_DISABLE_ALL) \
211 ack(r8); \ 235 ack(r8); \
236 CHECK_NAPPING(); \
212 addi r3,r1,STACK_FRAME_OVERHEAD; \ 237 addi r3,r1,STACK_FRAME_OVERHEAD; \
213 bl hdlr; \ 238 bl hdlr; \
214 b .ret_from_except_lite; 239 b .ret_from_except_lite;
@@ -246,11 +271,9 @@ interrupt_base_book3e: /* fake trap */
246 EXCEPTION_STUB(0x1a0, watchdog) /* 0x09f0 */ 271 EXCEPTION_STUB(0x1a0, watchdog) /* 0x09f0 */
247 EXCEPTION_STUB(0x1c0, data_tlb_miss) 272 EXCEPTION_STUB(0x1c0, data_tlb_miss)
248 EXCEPTION_STUB(0x1e0, instruction_tlb_miss) 273 EXCEPTION_STUB(0x1e0, instruction_tlb_miss)
274 EXCEPTION_STUB(0x280, doorbell)
275 EXCEPTION_STUB(0x2a0, doorbell_crit)
249 276
250#if 0
251 EXCEPTION_STUB(0x280, processor_doorbell)
252 EXCEPTION_STUB(0x220, processor_doorbell_crit)
253#endif
254 .globl interrupt_end_book3e 277 .globl interrupt_end_book3e
255interrupt_end_book3e: 278interrupt_end_book3e:
256 279
@@ -259,6 +282,7 @@ interrupt_end_book3e:
259 CRIT_EXCEPTION_PROLOG(0x100, PROLOG_ADDITION_NONE) 282 CRIT_EXCEPTION_PROLOG(0x100, PROLOG_ADDITION_NONE)
260// EXCEPTION_COMMON(0x100, PACA_EXCRIT, INTS_DISABLE_ALL) 283// EXCEPTION_COMMON(0x100, PACA_EXCRIT, INTS_DISABLE_ALL)
261// bl special_reg_save_crit 284// bl special_reg_save_crit
285// CHECK_NAPPING();
262// addi r3,r1,STACK_FRAME_OVERHEAD 286// addi r3,r1,STACK_FRAME_OVERHEAD
263// bl .critical_exception 287// bl .critical_exception
264// b ret_from_crit_except 288// b ret_from_crit_except
@@ -270,6 +294,7 @@ interrupt_end_book3e:
270// EXCEPTION_COMMON(0x200, PACA_EXMC, INTS_DISABLE_ALL) 294// EXCEPTION_COMMON(0x200, PACA_EXMC, INTS_DISABLE_ALL)
271// bl special_reg_save_mc 295// bl special_reg_save_mc
272// addi r3,r1,STACK_FRAME_OVERHEAD 296// addi r3,r1,STACK_FRAME_OVERHEAD
297// CHECK_NAPPING();
273// bl .machine_check_exception 298// bl .machine_check_exception
274// b ret_from_mc_except 299// b ret_from_mc_except
275 b . 300 b .
@@ -340,6 +365,7 @@ interrupt_end_book3e:
340 CRIT_EXCEPTION_PROLOG(0x9f0, PROLOG_ADDITION_NONE) 365 CRIT_EXCEPTION_PROLOG(0x9f0, PROLOG_ADDITION_NONE)
341// EXCEPTION_COMMON(0x9f0, PACA_EXCRIT, INTS_DISABLE_ALL) 366// EXCEPTION_COMMON(0x9f0, PACA_EXCRIT, INTS_DISABLE_ALL)
342// bl special_reg_save_crit 367// bl special_reg_save_crit
368// CHECK_NAPPING();
343// addi r3,r1,STACK_FRAME_OVERHEAD 369// addi r3,r1,STACK_FRAME_OVERHEAD
344// bl .unknown_exception 370// bl .unknown_exception
345// b ret_from_crit_except 371// b ret_from_crit_except
@@ -428,6 +454,20 @@ interrupt_end_book3e:
428kernel_dbg_exc: 454kernel_dbg_exc:
429 b . /* NYI */ 455 b . /* NYI */
430 456
457/* Doorbell interrupt */
458 MASKABLE_EXCEPTION(0x2070, doorbell, .doorbell_exception, ACK_NONE)
459
460/* Doorbell critical Interrupt */
461 START_EXCEPTION(doorbell_crit);
462 CRIT_EXCEPTION_PROLOG(0x2080, PROLOG_ADDITION_NONE)
463// EXCEPTION_COMMON(0x2080, PACA_EXCRIT, INTS_DISABLE_ALL)
464// bl special_reg_save_crit
465// CHECK_NAPPING();
466// addi r3,r1,STACK_FRAME_OVERHEAD
467// bl .doorbell_critical_exception
468// b ret_from_crit_except
469 b .
470
431 471
432/* 472/*
433 * An interrupt came in while soft-disabled; clear EE in SRR1, 473 * An interrupt came in while soft-disabled; clear EE in SRR1,
@@ -563,6 +603,8 @@ BAD_STACK_TRAMPOLINE(0xd00)
563BAD_STACK_TRAMPOLINE(0xe00) 603BAD_STACK_TRAMPOLINE(0xe00)
564BAD_STACK_TRAMPOLINE(0xf00) 604BAD_STACK_TRAMPOLINE(0xf00)
565BAD_STACK_TRAMPOLINE(0xf20) 605BAD_STACK_TRAMPOLINE(0xf20)
606BAD_STACK_TRAMPOLINE(0x2070)
607BAD_STACK_TRAMPOLINE(0x2080)
566 608
567 .globl bad_stack_book3e 609 .globl bad_stack_book3e
568bad_stack_book3e: 610bad_stack_book3e:
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 3e423fbad6b..f53029a0155 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -828,6 +828,7 @@ END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
828 828
829/* We have a data breakpoint exception - handle it */ 829/* We have a data breakpoint exception - handle it */
830handle_dabr_fault: 830handle_dabr_fault:
831 bl .save_nvgprs
831 ld r4,_DAR(r1) 832 ld r4,_DAR(r1)
832 ld r5,_DSISR(r1) 833 ld r5,_DSISR(r1)
833 addi r3,r1,STACK_FRAME_OVERHEAD 834 addi r3,r1,STACK_FRAME_OVERHEAD
diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc/kernel/hw_breakpoint.c
new file mode 100644
index 00000000000..5ecd0401cdb
--- /dev/null
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -0,0 +1,364 @@
1/*
2 * HW_breakpoint: a unified kernel/user-space hardware breakpoint facility,
3 * using the CPU's debug registers. Derived from
4 * "arch/x86/kernel/hw_breakpoint.c"
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 * Copyright 2010 IBM Corporation
21 * Author: K.Prasad <prasad@linux.vnet.ibm.com>
22 *
23 */
24
25#include <linux/hw_breakpoint.h>
26#include <linux/notifier.h>
27#include <linux/kprobes.h>
28#include <linux/percpu.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/sched.h>
32#include <linux/init.h>
33#include <linux/smp.h>
34
35#include <asm/hw_breakpoint.h>
36#include <asm/processor.h>
37#include <asm/sstep.h>
38#include <asm/uaccess.h>
39
40/*
41 * Stores the breakpoints currently in use on each breakpoint address
42 * register for every cpu
43 */
44static DEFINE_PER_CPU(struct perf_event *, bp_per_reg);
45
46/*
47 * Returns total number of data or instruction breakpoints available.
48 */
49int hw_breakpoint_slots(int type)
50{
51 if (type == TYPE_DATA)
52 return HBP_NUM;
53 return 0; /* no instruction breakpoints available */
54}
55
56/*
57 * Install a perf counter breakpoint.
58 *
59 * We seek a free debug address register and use it for this
60 * breakpoint.
61 *
62 * Atomic: we hold the counter->ctx->lock and we only handle variables
63 * and registers local to this cpu.
64 */
65int arch_install_hw_breakpoint(struct perf_event *bp)
66{
67 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
68 struct perf_event **slot = &__get_cpu_var(bp_per_reg);
69
70 *slot = bp;
71
72 /*
73 * Do not install DABR values if the instruction must be single-stepped.
74 * If so, DABR will be populated in single_step_dabr_instruction().
75 */
76 if (current->thread.last_hit_ubp != bp)
77 set_dabr(info->address | info->type | DABR_TRANSLATION);
78
79 return 0;
80}
81
82/*
83 * Uninstall the breakpoint contained in the given counter.
84 *
85 * First we search the debug address register it uses and then we disable
86 * it.
87 *
88 * Atomic: we hold the counter->ctx->lock and we only handle variables
89 * and registers local to this cpu.
90 */
91void arch_uninstall_hw_breakpoint(struct perf_event *bp)
92{
93 struct perf_event **slot = &__get_cpu_var(bp_per_reg);
94
95 if (*slot != bp) {
96 WARN_ONCE(1, "Can't find the breakpoint");
97 return;
98 }
99
100 *slot = NULL;
101 set_dabr(0);
102}
103
104/*
105 * Perform cleanup of arch-specific counters during unregistration
106 * of the perf-event
107 */
108void arch_unregister_hw_breakpoint(struct perf_event *bp)
109{
110 /*
111 * If the breakpoint is unregistered between a hw_breakpoint_handler()
112 * and the single_step_dabr_instruction(), then cleanup the breakpoint
113 * restoration variables to prevent dangling pointers.
114 */
115 if (bp->ctx->task)
116 bp->ctx->task->thread.last_hit_ubp = NULL;
117}
118
119/*
120 * Check for virtual address in kernel space.
121 */
122int arch_check_bp_in_kernelspace(struct perf_event *bp)
123{
124 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
125
126 return is_kernel_addr(info->address);
127}
128
129int arch_bp_generic_fields(int type, int *gen_bp_type)
130{
131 switch (type) {
132 case DABR_DATA_READ:
133 *gen_bp_type = HW_BREAKPOINT_R;
134 break;
135 case DABR_DATA_WRITE:
136 *gen_bp_type = HW_BREAKPOINT_W;
137 break;
138 case (DABR_DATA_WRITE | DABR_DATA_READ):
139 *gen_bp_type = (HW_BREAKPOINT_W | HW_BREAKPOINT_R);
140 break;
141 default:
142 return -EINVAL;
143 }
144 return 0;
145}
146
147/*
148 * Validate the arch-specific HW Breakpoint register settings
149 */
150int arch_validate_hwbkpt_settings(struct perf_event *bp)
151{
152 int ret = -EINVAL;
153 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
154
155 if (!bp)
156 return ret;
157
158 switch (bp->attr.bp_type) {
159 case HW_BREAKPOINT_R:
160 info->type = DABR_DATA_READ;
161 break;
162 case HW_BREAKPOINT_W:
163 info->type = DABR_DATA_WRITE;
164 break;
165 case HW_BREAKPOINT_R | HW_BREAKPOINT_W:
166 info->type = (DABR_DATA_READ | DABR_DATA_WRITE);
167 break;
168 default:
169 return ret;
170 }
171
172 info->address = bp->attr.bp_addr;
173 info->len = bp->attr.bp_len;
174
175 /*
176 * Since breakpoint length can be a maximum of HW_BREAKPOINT_LEN(8)
177 * and breakpoint addresses are aligned to nearest double-word
178 * HW_BREAKPOINT_ALIGN by rounding off to the lower address, the
179 * 'symbolsize' should satisfy the check below.
180 */
181 if (info->len >
182 (HW_BREAKPOINT_LEN - (info->address & HW_BREAKPOINT_ALIGN)))
183 return -EINVAL;
184 return 0;
185}
186
187/*
188 * Restores the breakpoint on the debug registers.
189 * Invoke this function if it is known that the execution context is
190 * about to change to cause loss of MSR_SE settings.
191 */
192void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs)
193{
194 struct arch_hw_breakpoint *info;
195
196 if (likely(!tsk->thread.last_hit_ubp))
197 return;
198
199 info = counter_arch_bp(tsk->thread.last_hit_ubp);
200 regs->msr &= ~MSR_SE;
201 set_dabr(info->address | info->type | DABR_TRANSLATION);
202 tsk->thread.last_hit_ubp = NULL;
203}
204
205/*
206 * Handle debug exception notifications.
207 */
208int __kprobes hw_breakpoint_handler(struct die_args *args)
209{
210 int rc = NOTIFY_STOP;
211 struct perf_event *bp;
212 struct pt_regs *regs = args->regs;
213 int stepped = 1;
214 struct arch_hw_breakpoint *info;
215 unsigned int instr;
216 unsigned long dar = regs->dar;
217
218 /* Disable breakpoints during exception handling */
219 set_dabr(0);
220
221 /*
222 * The counter may be concurrently released but that can only
223 * occur from a call_rcu() path. We can then safely fetch
224 * the breakpoint, use its callback, touch its counter
225 * while we are in an rcu_read_lock() path.
226 */
227 rcu_read_lock();
228
229 bp = __get_cpu_var(bp_per_reg);
230 if (!bp)
231 goto out;
232 info = counter_arch_bp(bp);
233
234 /*
235 * Return early after invoking user-callback function without restoring
236 * DABR if the breakpoint is from ptrace which always operates in
237 * one-shot mode. The ptrace-ed process will receive the SIGTRAP signal
238 * generated in do_dabr().
239 */
240 if (bp->overflow_handler == ptrace_triggered) {
241 perf_bp_event(bp, regs);
242 rc = NOTIFY_DONE;
243 goto out;
244 }
245
246 /*
247 * Verify if dar lies within the address range occupied by the symbol
248 * being watched to filter extraneous exceptions. If it doesn't,
249 * we still need to single-step the instruction, but we don't
250 * generate an event.
251 */
252 info->extraneous_interrupt = !((bp->attr.bp_addr <= dar) &&
253 (dar - bp->attr.bp_addr < bp->attr.bp_len));
254
255 /* Do not emulate user-space instructions, instead single-step them */
256 if (user_mode(regs)) {
257 bp->ctx->task->thread.last_hit_ubp = bp;
258 regs->msr |= MSR_SE;
259 goto out;
260 }
261
262 stepped = 0;
263 instr = 0;
264 if (!__get_user_inatomic(instr, (unsigned int *) regs->nip))
265 stepped = emulate_step(regs, instr);
266
267 /*
268 * emulate_step() could not execute it. We've failed in reliably
269 * handling the hw-breakpoint. Unregister it and throw a warning
270 * message to let the user know about it.
271 */
272 if (!stepped) {
273 WARN(1, "Unable to handle hardware breakpoint. Breakpoint at "
274 "0x%lx will be disabled.", info->address);
275 perf_event_disable(bp);
276 goto out;
277 }
278 /*
279 * As a policy, the callback is invoked in a 'trigger-after-execute'
280 * fashion
281 */
282 if (!info->extraneous_interrupt)
283 perf_bp_event(bp, regs);
284
285 set_dabr(info->address | info->type | DABR_TRANSLATION);
286out:
287 rcu_read_unlock();
288 return rc;
289}
290
291/*
292 * Handle single-step exceptions following a DABR hit.
293 */
294int __kprobes single_step_dabr_instruction(struct die_args *args)
295{
296 struct pt_regs *regs = args->regs;
297 struct perf_event *bp = NULL;
298 struct arch_hw_breakpoint *bp_info;
299
300 bp = current->thread.last_hit_ubp;
301 /*
302 * Check if we are single-stepping as a result of a
303 * previous HW Breakpoint exception
304 */
305 if (!bp)
306 return NOTIFY_DONE;
307
308 bp_info = counter_arch_bp(bp);
309
310 /*
311 * We shall invoke the user-defined callback function in the single
312 * stepping handler to confirm to 'trigger-after-execute' semantics
313 */
314 if (!bp_info->extraneous_interrupt)
315 perf_bp_event(bp, regs);
316
317 set_dabr(bp_info->address | bp_info->type | DABR_TRANSLATION);
318 current->thread.last_hit_ubp = NULL;
319
320 /*
321 * If the process was being single-stepped by ptrace, let the
322 * other single-step actions occur (e.g. generate SIGTRAP).
323 */
324 if (test_thread_flag(TIF_SINGLESTEP))
325 return NOTIFY_DONE;
326
327 return NOTIFY_STOP;
328}
329
330/*
331 * Handle debug exception notifications.
332 */
333int __kprobes hw_breakpoint_exceptions_notify(
334 struct notifier_block *unused, unsigned long val, void *data)
335{
336 int ret = NOTIFY_DONE;
337
338 switch (val) {
339 case DIE_DABR_MATCH:
340 ret = hw_breakpoint_handler(data);
341 break;
342 case DIE_SSTEP:
343 ret = single_step_dabr_instruction(data);
344 break;
345 }
346
347 return ret;
348}
349
350/*
351 * Release the user breakpoints used by ptrace
352 */
353void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
354{
355 struct thread_struct *t = &tsk->thread;
356
357 unregister_hw_breakpoint(t->ptrace_bps[0]);
358 t->ptrace_bps[0] = NULL;
359}
360
361void hw_breakpoint_pmu_read(struct perf_event *bp)
362{
363 /* TODO */
364}
diff --git a/arch/powerpc/kernel/idle_book3e.S b/arch/powerpc/kernel/idle_book3e.S
new file mode 100644
index 00000000000..16c002d6bdf
--- /dev/null
+++ b/arch/powerpc/kernel/idle_book3e.S
@@ -0,0 +1,86 @@
1/*
2 * Copyright 2010 IBM Corp, Benjamin Herrenschmidt <benh@kernel.crashing.org>
3 *
4 * Generic idle routine for Book3E processors
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/threads.h>
13#include <asm/reg.h>
14#include <asm/ppc_asm.h>
15#include <asm/asm-offsets.h>
16#include <asm/ppc-opcode.h>
17#include <asm/processor.h>
18#include <asm/thread_info.h>
19
20/* 64-bit version only for now */
21#ifdef CONFIG_PPC64
22
23_GLOBAL(book3e_idle)
24 /* Save LR for later */
25 mflr r0
26 std r0,16(r1)
27
28 /* Hard disable interrupts */
29 wrteei 0
30
31 /* Now check if an interrupt came in while we were soft disabled
32 * since we may otherwise lose it (doorbells etc...). We know
33 * that since PACAHARDIRQEN will have been cleared in that case.
34 */
35 lbz r3,PACAHARDIRQEN(r13)
36 cmpwi cr0,r3,0
37 beqlr
38
39 /* Now we are going to mark ourselves as soft and hard enables in
40 * order to be able to take interrupts while asleep. We inform lockdep
41 * of that. We don't actually turn interrupts on just yet tho.
42 */
43#ifdef CONFIG_TRACE_IRQFLAGS
44 stdu r1,-128(r1)
45 bl .trace_hardirqs_on
46#endif
47 li r0,1
48 stb r0,PACASOFTIRQEN(r13)
49 stb r0,PACAHARDIRQEN(r13)
50
51 /* Interrupts will make use return to LR, so get something we want
52 * in there
53 */
54 bl 1f
55
56 /* Hard disable interrupts again */
57 wrteei 0
58
59 /* Mark them off again in the PACA as well */
60 li r0,0
61 stb r0,PACASOFTIRQEN(r13)
62 stb r0,PACAHARDIRQEN(r13)
63
64 /* Tell lockdep about it */
65#ifdef CONFIG_TRACE_IRQFLAGS
66 bl .trace_hardirqs_off
67 addi r1,r1,128
68#endif
69 ld r0,16(r1)
70 mtlr r0
71 blr
72
731: /* Let's set the _TLF_NAPPING flag so interrupts make us return
74 * to the right spot
75 */
76 clrrdi r11,r1,THREAD_SHIFT
77 ld r10,TI_LOCAL_FLAGS(r11)
78 ori r10,r10,_TLF_NAPPING
79 std r10,TI_LOCAL_FLAGS(r11)
80
81 /* We can now re-enable hard interrupts and go to sleep */
82 wrteei 1
831: PPC_WAIT(0)
84 b 1b
85
86#endif /* CONFIG_PPC64 */
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 77be3d058a6..8f96d319890 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -64,6 +64,8 @@
64#include <asm/ptrace.h> 64#include <asm/ptrace.h>
65#include <asm/machdep.h> 65#include <asm/machdep.h>
66#include <asm/udbg.h> 66#include <asm/udbg.h>
67#include <asm/dbell.h>
68
67#ifdef CONFIG_PPC64 69#ifdef CONFIG_PPC64
68#include <asm/paca.h> 70#include <asm/paca.h>
69#include <asm/firmware.h> 71#include <asm/firmware.h>
@@ -153,14 +155,28 @@ notrace void raw_local_irq_restore(unsigned long en)
153 if (get_hard_enabled()) 155 if (get_hard_enabled())
154 return; 156 return;
155 157
158#if defined(CONFIG_BOOKE) && defined(CONFIG_SMP)
159 /* Check for pending doorbell interrupts and resend to ourself */
160 doorbell_check_self();
161#endif
162
156 /* 163 /*
157 * Need to hard-enable interrupts here. Since currently disabled, 164 * Need to hard-enable interrupts here. Since currently disabled,
158 * no need to take further asm precautions against preemption; but 165 * no need to take further asm precautions against preemption; but
159 * use local_paca instead of get_paca() to avoid preemption checking. 166 * use local_paca instead of get_paca() to avoid preemption checking.
160 */ 167 */
161 local_paca->hard_enabled = en; 168 local_paca->hard_enabled = en;
169
170#ifndef CONFIG_BOOKE
171 /* On server, re-trigger the decrementer if it went negative since
172 * some processors only trigger on edge transitions of the sign bit.
173 *
174 * BookE has a level sensitive decrementer (latches in TSR) so we
175 * don't need that
176 */
162 if ((int)mfspr(SPRN_DEC) < 0) 177 if ((int)mfspr(SPRN_DEC) < 0)
163 mtspr(SPRN_DEC, 1); 178 mtspr(SPRN_DEC, 1);
179#endif /* CONFIG_BOOKE */
164 180
165 /* 181 /*
166 * Force the delivery of pending soft-disabled interrupts on PS3. 182 * Force the delivery of pending soft-disabled interrupts on PS3.
diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c
index 89f005116aa..dd6c141f166 100644
--- a/arch/powerpc/kernel/machine_kexec.c
+++ b/arch/powerpc/kernel/machine_kexec.c
@@ -45,6 +45,18 @@ void machine_kexec_cleanup(struct kimage *image)
45 ppc_md.machine_kexec_cleanup(image); 45 ppc_md.machine_kexec_cleanup(image);
46} 46}
47 47
48void arch_crash_save_vmcoreinfo(void)
49{
50
51#ifdef CONFIG_NEED_MULTIPLE_NODES
52 VMCOREINFO_SYMBOL(node_data);
53 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
54#endif
55#ifndef CONFIG_NEED_MULTIPLE_NODES
56 VMCOREINFO_SYMBOL(contig_page_data);
57#endif
58}
59
48/* 60/*
49 * Do not allocate memory (or fail in any way) in machine_kexec(). 61 * Do not allocate memory (or fail in any way) in machine_kexec().
50 * We are past the point of no return, committed to rebooting now. 62 * We are past the point of no return, committed to rebooting now.
@@ -144,24 +156,24 @@ int overlaps_crashkernel(unsigned long start, unsigned long size)
144} 156}
145 157
146/* Values we need to export to the second kernel via the device tree. */ 158/* Values we need to export to the second kernel via the device tree. */
147static unsigned long kernel_end; 159static phys_addr_t kernel_end;
148static unsigned long crashk_size; 160static phys_addr_t crashk_size;
149 161
150static struct property kernel_end_prop = { 162static struct property kernel_end_prop = {
151 .name = "linux,kernel-end", 163 .name = "linux,kernel-end",
152 .length = sizeof(unsigned long), 164 .length = sizeof(phys_addr_t),
153 .value = &kernel_end, 165 .value = &kernel_end,
154}; 166};
155 167
156static struct property crashk_base_prop = { 168static struct property crashk_base_prop = {
157 .name = "linux,crashkernel-base", 169 .name = "linux,crashkernel-base",
158 .length = sizeof(unsigned long), 170 .length = sizeof(phys_addr_t),
159 .value = &crashk_res.start, 171 .value = &crashk_res.start,
160}; 172};
161 173
162static struct property crashk_size_prop = { 174static struct property crashk_size_prop = {
163 .name = "linux,crashkernel-size", 175 .name = "linux,crashkernel-size",
164 .length = sizeof(unsigned long), 176 .length = sizeof(phys_addr_t),
165 .value = &crashk_size, 177 .value = &crashk_size,
166}; 178};
167 179
diff --git a/arch/powerpc/kernel/machine_kexec_64.c b/arch/powerpc/kernel/machine_kexec_64.c
index ed31a29c4ff..583af70c4b1 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -15,6 +15,8 @@
15#include <linux/thread_info.h> 15#include <linux/thread_info.h>
16#include <linux/init_task.h> 16#include <linux/init_task.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/kernel.h>
19#include <linux/cpu.h>
18 20
19#include <asm/page.h> 21#include <asm/page.h>
20#include <asm/current.h> 22#include <asm/current.h>
@@ -25,6 +27,7 @@
25#include <asm/sections.h> /* _end */ 27#include <asm/sections.h> /* _end */
26#include <asm/prom.h> 28#include <asm/prom.h>
27#include <asm/smp.h> 29#include <asm/smp.h>
30#include <asm/hw_breakpoint.h>
28 31
29int default_machine_kexec_prepare(struct kimage *image) 32int default_machine_kexec_prepare(struct kimage *image)
30{ 33{
@@ -165,6 +168,7 @@ static void kexec_smp_down(void *arg)
165 while(kexec_all_irq_disabled == 0) 168 while(kexec_all_irq_disabled == 0)
166 cpu_relax(); 169 cpu_relax();
167 mb(); /* make sure all irqs are disabled before this */ 170 mb(); /* make sure all irqs are disabled before this */
171 hw_breakpoint_disable();
168 /* 172 /*
169 * Now every CPU has IRQs off, we can clear out any pending 173 * Now every CPU has IRQs off, we can clear out any pending
170 * IPIs and be sure that no more will come in after this. 174 * IPIs and be sure that no more will come in after this.
@@ -180,8 +184,22 @@ static void kexec_prepare_cpus_wait(int wait_state)
180{ 184{
181 int my_cpu, i, notified=-1; 185 int my_cpu, i, notified=-1;
182 186
187 hw_breakpoint_disable();
183 my_cpu = get_cpu(); 188 my_cpu = get_cpu();
184 /* Make sure each CPU has atleast made it to the state we need */ 189 /* Make sure each CPU has at least made it to the state we need.
190 *
191 * FIXME: There is a (slim) chance of a problem if not all of the CPUs
192 * are correctly onlined. If somehow we start a CPU on boot with RTAS
193 * start-cpu, but somehow that CPU doesn't write callin_cpu_map[] in
194 * time, the boot CPU will timeout. If it does eventually execute
195 * stuff, the secondary will start up (paca[].cpu_start was written) and
196 * get into a peculiar state. If the platform supports
197 * smp_ops->take_timebase(), the secondary CPU will probably be spinning
198 * in there. If not (i.e. pseries), the secondary will continue on and
199 * try to online itself/idle/etc. If it survives that, we need to find
200 * these possible-but-not-online-but-should-be CPUs and chaperone them
201 * into kexec_smp_wait().
202 */
185 for_each_online_cpu(i) { 203 for_each_online_cpu(i) {
186 if (i == my_cpu) 204 if (i == my_cpu)
187 continue; 205 continue;
@@ -189,9 +207,9 @@ static void kexec_prepare_cpus_wait(int wait_state)
189 while (paca[i].kexec_state < wait_state) { 207 while (paca[i].kexec_state < wait_state) {
190 barrier(); 208 barrier();
191 if (i != notified) { 209 if (i != notified) {
192 printk( "kexec: waiting for cpu %d (physical" 210 printk(KERN_INFO "kexec: waiting for cpu %d "
193 " %d) to enter %i state\n", 211 "(physical %d) to enter %i state\n",
194 i, paca[i].hw_cpu_id, wait_state); 212 i, paca[i].hw_cpu_id, wait_state);
195 notified = i; 213 notified = i;
196 } 214 }
197 } 215 }
@@ -199,9 +217,32 @@ static void kexec_prepare_cpus_wait(int wait_state)
199 mb(); 217 mb();
200} 218}
201 219
202static void kexec_prepare_cpus(void) 220/*
221 * We need to make sure each present CPU is online. The next kernel will scan
222 * the device tree and assume primary threads are online and query secondary
223 * threads via RTAS to online them if required. If we don't online primary
224 * threads, they will be stuck. However, we also online secondary threads as we
225 * may be using 'cede offline'. In this case RTAS doesn't see the secondary
226 * threads as offline -- and again, these CPUs will be stuck.
227 *
228 * So, we online all CPUs that should be running, including secondary threads.
229 */
230static void wake_offline_cpus(void)
203{ 231{
232 int cpu = 0;
204 233
234 for_each_present_cpu(cpu) {
235 if (!cpu_online(cpu)) {
236 printk(KERN_INFO "kexec: Waking offline cpu %d.\n",
237 cpu);
238 cpu_up(cpu);
239 }
240 }
241}
242
243static void kexec_prepare_cpus(void)
244{
245 wake_offline_cpus();
205 smp_call_function(kexec_smp_down, NULL, /* wait */0); 246 smp_call_function(kexec_smp_down, NULL, /* wait */0);
206 local_irq_disable(); 247 local_irq_disable();
207 mb(); /* make sure IRQs are disabled before we say they are */ 248 mb(); /* make sure IRQs are disabled before we say they are */
@@ -215,7 +256,10 @@ static void kexec_prepare_cpus(void)
215 if (ppc_md.kexec_cpu_down) 256 if (ppc_md.kexec_cpu_down)
216 ppc_md.kexec_cpu_down(0, 0); 257 ppc_md.kexec_cpu_down(0, 0);
217 258
218 /* Before removing MMU mapings make sure all CPUs have entered real mode */ 259 /*
260 * Before removing MMU mappings make sure all CPUs have entered real
261 * mode:
262 */
219 kexec_prepare_cpus_wait(KEXEC_STATE_REAL_MODE); 263 kexec_prepare_cpus_wait(KEXEC_STATE_REAL_MODE);
220 264
221 put_cpu(); 265 put_cpu();
@@ -257,6 +301,12 @@ static void kexec_prepare_cpus(void)
257static union thread_union kexec_stack __init_task_data = 301static union thread_union kexec_stack __init_task_data =
258 { }; 302 { };
259 303
304/*
305 * For similar reasons to the stack above, the kexecing CPU needs to be on a
306 * static PACA; we switch to kexec_paca.
307 */
308struct paca_struct kexec_paca;
309
260/* Our assembly helper, in kexec_stub.S */ 310/* Our assembly helper, in kexec_stub.S */
261extern NORET_TYPE void kexec_sequence(void *newstack, unsigned long start, 311extern NORET_TYPE void kexec_sequence(void *newstack, unsigned long start,
262 void *image, void *control, 312 void *image, void *control,
@@ -278,12 +328,28 @@ void default_machine_kexec(struct kimage *image)
278 if (crashing_cpu == -1) 328 if (crashing_cpu == -1)
279 kexec_prepare_cpus(); 329 kexec_prepare_cpus();
280 330
331 pr_debug("kexec: Starting switchover sequence.\n");
332
281 /* switch to a staticly allocated stack. Based on irq stack code. 333 /* switch to a staticly allocated stack. Based on irq stack code.
282 * XXX: the task struct will likely be invalid once we do the copy! 334 * XXX: the task struct will likely be invalid once we do the copy!
283 */ 335 */
284 kexec_stack.thread_info.task = current_thread_info()->task; 336 kexec_stack.thread_info.task = current_thread_info()->task;
285 kexec_stack.thread_info.flags = 0; 337 kexec_stack.thread_info.flags = 0;
286 338
339 /* We need a static PACA, too; copy this CPU's PACA over and switch to
340 * it. Also poison per_cpu_offset to catch anyone using non-static
341 * data.
342 */
343 memcpy(&kexec_paca, get_paca(), sizeof(struct paca_struct));
344 kexec_paca.data_offset = 0xedeaddeadeeeeeeeUL;
345 paca = (struct paca_struct *)RELOC_HIDE(&kexec_paca, 0) -
346 kexec_paca.paca_index;
347 setup_paca(&kexec_paca);
348
349 /* XXX: If anyone does 'dynamic lppacas' this will also need to be
350 * switched to a static version!
351 */
352
287 /* Some things are best done in assembly. Finding globals with 353 /* Some things are best done in assembly. Finding globals with
288 * a toc is easier in C, so pass in what we can. 354 * a toc is easier in C, so pass in what we can.
289 */ 355 */
diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c
index 139a773853f..d0a26f1770f 100644
--- a/arch/powerpc/kernel/paca.c
+++ b/arch/powerpc/kernel/paca.c
@@ -105,6 +105,16 @@ void __init initialise_paca(struct paca_struct *new_paca, int cpu)
105#endif /* CONFIG_PPC_STD_MMU_64 */ 105#endif /* CONFIG_PPC_STD_MMU_64 */
106} 106}
107 107
108/* Put the paca pointer into r13 and SPRG_PACA */
109void setup_paca(struct paca_struct *new_paca)
110{
111 local_paca = new_paca;
112 mtspr(SPRN_SPRG_PACA, local_paca);
113#ifdef CONFIG_PPC_BOOK3E
114 mtspr(SPRN_SPRG_TLB_EXFRAME, local_paca->extlb);
115#endif
116}
117
108static int __initdata paca_size; 118static int __initdata paca_size;
109 119
110void __init allocate_pacas(void) 120void __init allocate_pacas(void)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 773424df828..551f6713ff4 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -37,6 +37,7 @@
37#include <linux/kernel_stat.h> 37#include <linux/kernel_stat.h>
38#include <linux/personality.h> 38#include <linux/personality.h>
39#include <linux/random.h> 39#include <linux/random.h>
40#include <linux/hw_breakpoint.h>
40 41
41#include <asm/pgtable.h> 42#include <asm/pgtable.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
@@ -462,14 +463,42 @@ struct task_struct *__switch_to(struct task_struct *prev,
462#ifdef CONFIG_PPC_ADV_DEBUG_REGS 463#ifdef CONFIG_PPC_ADV_DEBUG_REGS
463 switch_booke_debug_regs(&new->thread); 464 switch_booke_debug_regs(&new->thread);
464#else 465#else
466/*
467 * For PPC_BOOK3S_64, we use the hw-breakpoint interfaces that would
468 * schedule DABR
469 */
470#ifndef CONFIG_HAVE_HW_BREAKPOINT
465 if (unlikely(__get_cpu_var(current_dabr) != new->thread.dabr)) 471 if (unlikely(__get_cpu_var(current_dabr) != new->thread.dabr))
466 set_dabr(new->thread.dabr); 472 set_dabr(new->thread.dabr);
473#endif /* CONFIG_HAVE_HW_BREAKPOINT */
467#endif 474#endif
468 475
469 476
470 new_thread = &new->thread; 477 new_thread = &new->thread;
471 old_thread = &current->thread; 478 old_thread = &current->thread;
472 479
480#if defined(CONFIG_PPC_BOOK3E_64)
481 /* XXX Current Book3E code doesn't deal with kernel side DBCR0,
482 * we always hold the user values, so we set it now.
483 *
484 * However, we ensure the kernel MSR:DE is appropriately cleared too
485 * to avoid spurrious single step exceptions in the kernel.
486 *
487 * This will have to change to merge with the ppc32 code at some point,
488 * but I don't like much what ppc32 is doing today so there's some
489 * thinking needed there
490 */
491 if ((new_thread->dbcr0 | old_thread->dbcr0) & DBCR0_IDM) {
492 u32 dbcr0;
493
494 mtmsr(mfmsr() & ~MSR_DE);
495 isync();
496 dbcr0 = mfspr(SPRN_DBCR0);
497 dbcr0 = (dbcr0 & DBCR0_EDM) | new_thread->dbcr0;
498 mtspr(SPRN_DBCR0, dbcr0);
499 }
500#endif /* CONFIG_PPC64_BOOK3E */
501
473#ifdef CONFIG_PPC64 502#ifdef CONFIG_PPC64
474 /* 503 /*
475 * Collect processor utilization data per process 504 * Collect processor utilization data per process
@@ -642,7 +671,11 @@ void flush_thread(void)
642{ 671{
643 discard_lazy_cpu_state(); 672 discard_lazy_cpu_state();
644 673
674#ifdef CONFIG_HAVE_HW_BREAKPOINTS
675 flush_ptrace_hw_breakpoint(current);
676#else /* CONFIG_HAVE_HW_BREAKPOINTS */
645 set_debug_reg_defaults(&current->thread); 677 set_debug_reg_defaults(&current->thread);
678#endif /* CONFIG_HAVE_HW_BREAKPOINTS */
646} 679}
647 680
648void 681void
@@ -660,6 +693,9 @@ void prepare_to_copy(struct task_struct *tsk)
660 flush_altivec_to_thread(current); 693 flush_altivec_to_thread(current);
661 flush_vsx_to_thread(current); 694 flush_vsx_to_thread(current);
662 flush_spe_to_thread(current); 695 flush_spe_to_thread(current);
696#ifdef CONFIG_HAVE_HW_BREAKPOINT
697 flush_ptrace_hw_breakpoint(tsk);
698#endif /* CONFIG_HAVE_HW_BREAKPOINT */
663} 699}
664 700
665/* 701/*
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 3b6f8ae9b8c..941ff4dbc56 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -311,6 +311,24 @@ static void __init prom_print_hex(unsigned long val)
311 call_prom("write", 3, 1, _prom->stdout, buf, nibbles); 311 call_prom("write", 3, 1, _prom->stdout, buf, nibbles);
312} 312}
313 313
314/* max number of decimal digits in an unsigned long */
315#define UL_DIGITS 21
316static void __init prom_print_dec(unsigned long val)
317{
318 int i, size;
319 char buf[UL_DIGITS+1];
320 struct prom_t *_prom = &RELOC(prom);
321
322 for (i = UL_DIGITS-1; i >= 0; i--) {
323 buf[i] = (val % 10) + '0';
324 val = val/10;
325 if (val == 0)
326 break;
327 }
328 /* shift stuff down */
329 size = UL_DIGITS - i;
330 call_prom("write", 3, 1, _prom->stdout, buf+i, size);
331}
314 332
315static void __init prom_printf(const char *format, ...) 333static void __init prom_printf(const char *format, ...)
316{ 334{
@@ -350,6 +368,14 @@ static void __init prom_printf(const char *format, ...)
350 v = va_arg(args, unsigned long); 368 v = va_arg(args, unsigned long);
351 prom_print_hex(v); 369 prom_print_hex(v);
352 break; 370 break;
371 case 'l':
372 ++q;
373 if (*q == 'u') { /* '%lu' */
374 ++q;
375 v = va_arg(args, unsigned long);
376 prom_print_dec(v);
377 }
378 break;
353 } 379 }
354 } 380 }
355} 381}
@@ -835,11 +861,11 @@ static int __init prom_count_smt_threads(void)
835 if (plen == PROM_ERROR) 861 if (plen == PROM_ERROR)
836 break; 862 break;
837 plen >>= 2; 863 plen >>= 2;
838 prom_debug("Found 0x%x smt threads per core\n", (unsigned long)plen); 864 prom_debug("Found %lu smt threads per core\n", (unsigned long)plen);
839 865
840 /* Sanity check */ 866 /* Sanity check */
841 if (plen < 1 || plen > 64) { 867 if (plen < 1 || plen > 64) {
842 prom_printf("Threads per core 0x%x out of bounds, assuming 1\n", 868 prom_printf("Threads per core %lu out of bounds, assuming 1\n",
843 (unsigned long)plen); 869 (unsigned long)plen);
844 return 1; 870 return 1;
845 } 871 }
@@ -869,12 +895,12 @@ static void __init prom_send_capabilities(void)
869 cores = (u32 *)PTRRELOC(&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]); 895 cores = (u32 *)PTRRELOC(&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]);
870 if (*cores != NR_CPUS) { 896 if (*cores != NR_CPUS) {
871 prom_printf("WARNING ! " 897 prom_printf("WARNING ! "
872 "ibm_architecture_vec structure inconsistent: 0x%x !\n", 898 "ibm_architecture_vec structure inconsistent: %lu!\n",
873 *cores); 899 *cores);
874 } else { 900 } else {
875 *cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads()); 901 *cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads());
876 prom_printf("Max number of cores passed to firmware: 0x%x\n", 902 prom_printf("Max number of cores passed to firmware: %lu (NR_CPUS = %lu)\n",
877 (unsigned long)*cores); 903 *cores, NR_CPUS);
878 } 904 }
879 905
880 /* try calling the ibm,client-architecture-support method */ 906 /* try calling the ibm,client-architecture-support method */
@@ -1482,7 +1508,7 @@ static void __init prom_hold_cpus(void)
1482 reg = -1; 1508 reg = -1;
1483 prom_getprop(node, "reg", &reg, sizeof(reg)); 1509 prom_getprop(node, "reg", &reg, sizeof(reg));
1484 1510
1485 prom_debug("cpu hw idx = 0x%x\n", reg); 1511 prom_debug("cpu hw idx = %lu\n", reg);
1486 1512
1487 /* Init the acknowledge var which will be reset by 1513 /* Init the acknowledge var which will be reset by
1488 * the secondary cpu when it awakens from its OF 1514 * the secondary cpu when it awakens from its OF
@@ -1492,7 +1518,7 @@ static void __init prom_hold_cpus(void)
1492 1518
1493 if (reg != _prom->cpu) { 1519 if (reg != _prom->cpu) {
1494 /* Primary Thread of non-boot cpu */ 1520 /* Primary Thread of non-boot cpu */
1495 prom_printf("starting cpu hw idx %x... ", reg); 1521 prom_printf("starting cpu hw idx %lu... ", reg);
1496 call_prom("start-cpu", 3, 0, node, 1522 call_prom("start-cpu", 3, 0, node,
1497 secondary_hold, reg); 1523 secondary_hold, reg);
1498 1524
@@ -1507,7 +1533,7 @@ static void __init prom_hold_cpus(void)
1507 } 1533 }
1508#ifdef CONFIG_SMP 1534#ifdef CONFIG_SMP
1509 else 1535 else
1510 prom_printf("boot cpu hw idx %x\n", reg); 1536 prom_printf("boot cpu hw idx %lu\n", reg);
1511#endif /* CONFIG_SMP */ 1537#endif /* CONFIG_SMP */
1512 } 1538 }
1513 1539
@@ -2420,7 +2446,7 @@ static void __init prom_find_boot_cpu(void)
2420 prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval)); 2446 prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval));
2421 _prom->cpu = getprop_rval; 2447 _prom->cpu = getprop_rval;
2422 2448
2423 prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu); 2449 prom_debug("Booting CPU hw index = %lu\n", _prom->cpu);
2424} 2450}
2425 2451
2426static void __init prom_check_initrd(unsigned long r3, unsigned long r4) 2452static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 7a0c0199ea2..11f3cd9c832 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -32,6 +32,8 @@
32#ifdef CONFIG_PPC32 32#ifdef CONFIG_PPC32
33#include <linux/module.h> 33#include <linux/module.h>
34#endif 34#endif
35#include <linux/hw_breakpoint.h>
36#include <linux/perf_event.h>
35 37
36#include <asm/uaccess.h> 38#include <asm/uaccess.h>
37#include <asm/page.h> 39#include <asm/page.h>
@@ -866,9 +868,34 @@ void user_disable_single_step(struct task_struct *task)
866 clear_tsk_thread_flag(task, TIF_SINGLESTEP); 868 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
867} 869}
868 870
871#ifdef CONFIG_HAVE_HW_BREAKPOINT
872void ptrace_triggered(struct perf_event *bp, int nmi,
873 struct perf_sample_data *data, struct pt_regs *regs)
874{
875 struct perf_event_attr attr;
876
877 /*
878 * Disable the breakpoint request here since ptrace has defined a
879 * one-shot behaviour for breakpoint exceptions in PPC64.
880 * The SIGTRAP signal is generated automatically for us in do_dabr().
881 * We don't have to do anything about that here
882 */
883 attr = bp->attr;
884 attr.disabled = true;
885 modify_user_hw_breakpoint(bp, &attr);
886}
887#endif /* CONFIG_HAVE_HW_BREAKPOINT */
888
869int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, 889int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
870 unsigned long data) 890 unsigned long data)
871{ 891{
892#ifdef CONFIG_HAVE_HW_BREAKPOINT
893 int ret;
894 struct thread_struct *thread = &(task->thread);
895 struct perf_event *bp;
896 struct perf_event_attr attr;
897#endif /* CONFIG_HAVE_HW_BREAKPOINT */
898
872 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). 899 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
873 * For embedded processors we support one DAC and no IAC's at the 900 * For embedded processors we support one DAC and no IAC's at the
874 * moment. 901 * moment.
@@ -896,6 +923,43 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
896 /* Ensure breakpoint translation bit is set */ 923 /* Ensure breakpoint translation bit is set */
897 if (data && !(data & DABR_TRANSLATION)) 924 if (data && !(data & DABR_TRANSLATION))
898 return -EIO; 925 return -EIO;
926#ifdef CONFIG_HAVE_HW_BREAKPOINT
927 bp = thread->ptrace_bps[0];
928 if ((!data) || !(data & (DABR_DATA_WRITE | DABR_DATA_READ))) {
929 if (bp) {
930 unregister_hw_breakpoint(bp);
931 thread->ptrace_bps[0] = NULL;
932 }
933 return 0;
934 }
935 if (bp) {
936 attr = bp->attr;
937 attr.bp_addr = data & ~HW_BREAKPOINT_ALIGN;
938 arch_bp_generic_fields(data &
939 (DABR_DATA_WRITE | DABR_DATA_READ),
940 &attr.bp_type);
941 ret = modify_user_hw_breakpoint(bp, &attr);
942 if (ret)
943 return ret;
944 thread->ptrace_bps[0] = bp;
945 thread->dabr = data;
946 return 0;
947 }
948
949 /* Create a new breakpoint request if one doesn't exist already */
950 hw_breakpoint_init(&attr);
951 attr.bp_addr = data & ~HW_BREAKPOINT_ALIGN;
952 arch_bp_generic_fields(data & (DABR_DATA_WRITE | DABR_DATA_READ),
953 &attr.bp_type);
954
955 thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
956 ptrace_triggered, task);
957 if (IS_ERR(bp)) {
958 thread->ptrace_bps[0] = NULL;
959 return PTR_ERR(bp);
960 }
961
962#endif /* CONFIG_HAVE_HW_BREAKPOINT */
899 963
900 /* Move contents to the DABR register */ 964 /* Move contents to the DABR register */
901 task->thread.dabr = data; 965 task->thread.dabr = data;
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index d0516dbee76..41048de3c6c 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -47,14 +47,6 @@ struct rtas_t rtas = {
47}; 47};
48EXPORT_SYMBOL(rtas); 48EXPORT_SYMBOL(rtas);
49 49
50struct rtas_suspend_me_data {
51 atomic_t working; /* number of cpus accessing this struct */
52 atomic_t done;
53 int token; /* ibm,suspend-me */
54 int error;
55 struct completion *complete; /* wait on this until working == 0 */
56};
57
58DEFINE_SPINLOCK(rtas_data_buf_lock); 50DEFINE_SPINLOCK(rtas_data_buf_lock);
59EXPORT_SYMBOL(rtas_data_buf_lock); 51EXPORT_SYMBOL(rtas_data_buf_lock);
60 52
@@ -714,14 +706,53 @@ void rtas_os_term(char *str)
714 706
715static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE; 707static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE;
716#ifdef CONFIG_PPC_PSERIES 708#ifdef CONFIG_PPC_PSERIES
717static void rtas_percpu_suspend_me(void *info) 709static int __rtas_suspend_last_cpu(struct rtas_suspend_me_data *data, int wake_when_done)
710{
711 u16 slb_size = mmu_slb_size;
712 int rc = H_MULTI_THREADS_ACTIVE;
713 int cpu;
714
715 slb_set_size(SLB_MIN_SIZE);
716 printk(KERN_DEBUG "calling ibm,suspend-me on cpu %i\n", smp_processor_id());
717
718 while (rc == H_MULTI_THREADS_ACTIVE && !atomic_read(&data->done) &&
719 !atomic_read(&data->error))
720 rc = rtas_call(data->token, 0, 1, NULL);
721
722 if (rc || atomic_read(&data->error)) {
723 printk(KERN_DEBUG "ibm,suspend-me returned %d\n", rc);
724 slb_set_size(slb_size);
725 }
726
727 if (atomic_read(&data->error))
728 rc = atomic_read(&data->error);
729
730 atomic_set(&data->error, rc);
731
732 if (wake_when_done) {
733 atomic_set(&data->done, 1);
734
735 for_each_online_cpu(cpu)
736 plpar_hcall_norets(H_PROD, get_hard_smp_processor_id(cpu));
737 }
738
739 if (atomic_dec_return(&data->working) == 0)
740 complete(data->complete);
741
742 return rc;
743}
744
745int rtas_suspend_last_cpu(struct rtas_suspend_me_data *data)
746{
747 atomic_inc(&data->working);
748 return __rtas_suspend_last_cpu(data, 0);
749}
750
751static int __rtas_suspend_cpu(struct rtas_suspend_me_data *data, int wake_when_done)
718{ 752{
719 long rc = H_SUCCESS; 753 long rc = H_SUCCESS;
720 unsigned long msr_save; 754 unsigned long msr_save;
721 u16 slb_size = mmu_slb_size;
722 int cpu; 755 int cpu;
723 struct rtas_suspend_me_data *data =
724 (struct rtas_suspend_me_data *)info;
725 756
726 atomic_inc(&data->working); 757 atomic_inc(&data->working);
727 758
@@ -729,7 +760,7 @@ static void rtas_percpu_suspend_me(void *info)
729 msr_save = mfmsr(); 760 msr_save = mfmsr();
730 mtmsr(msr_save & ~(MSR_EE)); 761 mtmsr(msr_save & ~(MSR_EE));
731 762
732 while (rc == H_SUCCESS && !atomic_read(&data->done)) 763 while (rc == H_SUCCESS && !atomic_read(&data->done) && !atomic_read(&data->error))
733 rc = plpar_hcall_norets(H_JOIN); 764 rc = plpar_hcall_norets(H_JOIN);
734 765
735 mtmsr(msr_save); 766 mtmsr(msr_save);
@@ -741,33 +772,37 @@ static void rtas_percpu_suspend_me(void *info)
741 /* All other cpus are in H_JOIN, this cpu does 772 /* All other cpus are in H_JOIN, this cpu does
742 * the suspend. 773 * the suspend.
743 */ 774 */
744 slb_set_size(SLB_MIN_SIZE); 775 return __rtas_suspend_last_cpu(data, wake_when_done);
745 printk(KERN_DEBUG "calling ibm,suspend-me on cpu %i\n",
746 smp_processor_id());
747 data->error = rtas_call(data->token, 0, 1, NULL);
748
749 if (data->error) {
750 printk(KERN_DEBUG "ibm,suspend-me returned %d\n",
751 data->error);
752 slb_set_size(slb_size);
753 }
754 } else { 776 } else {
755 printk(KERN_ERR "H_JOIN on cpu %i failed with rc = %ld\n", 777 printk(KERN_ERR "H_JOIN on cpu %i failed with rc = %ld\n",
756 smp_processor_id(), rc); 778 smp_processor_id(), rc);
757 data->error = rc; 779 atomic_set(&data->error, rc);
758 } 780 }
759 781
760 atomic_set(&data->done, 1); 782 if (wake_when_done) {
783 atomic_set(&data->done, 1);
761 784
762 /* This cpu did the suspend or got an error; in either case, 785 /* This cpu did the suspend or got an error; in either case,
763 * we need to prod all other other cpus out of join state. 786 * we need to prod all other other cpus out of join state.
764 * Extra prods are harmless. 787 * Extra prods are harmless.
765 */ 788 */
766 for_each_online_cpu(cpu) 789 for_each_online_cpu(cpu)
767 plpar_hcall_norets(H_PROD, get_hard_smp_processor_id(cpu)); 790 plpar_hcall_norets(H_PROD, get_hard_smp_processor_id(cpu));
791 }
768out: 792out:
769 if (atomic_dec_return(&data->working) == 0) 793 if (atomic_dec_return(&data->working) == 0)
770 complete(data->complete); 794 complete(data->complete);
795 return rc;
796}
797
798int rtas_suspend_cpu(struct rtas_suspend_me_data *data)
799{
800 return __rtas_suspend_cpu(data, 0);
801}
802
803static void rtas_percpu_suspend_me(void *info)
804{
805 __rtas_suspend_cpu((struct rtas_suspend_me_data *)info, 1);
771} 806}
772 807
773static int rtas_ibm_suspend_me(struct rtas_args *args) 808static int rtas_ibm_suspend_me(struct rtas_args *args)
@@ -802,22 +837,22 @@ static int rtas_ibm_suspend_me(struct rtas_args *args)
802 837
803 atomic_set(&data.working, 0); 838 atomic_set(&data.working, 0);
804 atomic_set(&data.done, 0); 839 atomic_set(&data.done, 0);
840 atomic_set(&data.error, 0);
805 data.token = rtas_token("ibm,suspend-me"); 841 data.token = rtas_token("ibm,suspend-me");
806 data.error = 0;
807 data.complete = &done; 842 data.complete = &done;
808 843
809 /* Call function on all CPUs. One of us will make the 844 /* Call function on all CPUs. One of us will make the
810 * rtas call 845 * rtas call
811 */ 846 */
812 if (on_each_cpu(rtas_percpu_suspend_me, &data, 0)) 847 if (on_each_cpu(rtas_percpu_suspend_me, &data, 0))
813 data.error = -EINVAL; 848 atomic_set(&data.error, -EINVAL);
814 849
815 wait_for_completion(&done); 850 wait_for_completion(&done);
816 851
817 if (data.error != 0) 852 if (atomic_read(&data.error) != 0)
818 printk(KERN_ERR "Error doing global join\n"); 853 printk(KERN_ERR "Error doing global join\n");
819 854
820 return data.error; 855 return atomic_read(&data.error);
821} 856}
822#else /* CONFIG_PPC_PSERIES */ 857#else /* CONFIG_PPC_PSERIES */
823static int rtas_ibm_suspend_me(struct rtas_args *args) 858static int rtas_ibm_suspend_me(struct rtas_args *args)
diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index b7e6c7e193a..70decd8068c 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -94,6 +94,10 @@ struct screen_info screen_info = {
94 .orig_video_points = 16 94 .orig_video_points = 16
95}; 95};
96 96
97/* Variables required to store legacy IO irq routing */
98int of_i8042_kbd_irq;
99int of_i8042_aux_irq;
100
97#ifdef __DO_IRQ_CANON 101#ifdef __DO_IRQ_CANON
98/* XXX should go elsewhere eventually */ 102/* XXX should go elsewhere eventually */
99int ppc_do_canonicalize_irqs; 103int ppc_do_canonicalize_irqs;
@@ -575,6 +579,15 @@ int check_legacy_ioport(unsigned long base_port)
575 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03"); 579 np = of_find_compatible_node(NULL, NULL, "pnpPNP,f03");
576 if (np) { 580 if (np) {
577 parent = of_get_parent(np); 581 parent = of_get_parent(np);
582
583 of_i8042_kbd_irq = irq_of_parse_and_map(parent, 0);
584 if (!of_i8042_kbd_irq)
585 of_i8042_kbd_irq = 1;
586
587 of_i8042_aux_irq = irq_of_parse_and_map(parent, 1);
588 if (!of_i8042_aux_irq)
589 of_i8042_aux_irq = 12;
590
578 of_node_put(np); 591 of_node_put(np);
579 np = parent; 592 np = parent;
580 break; 593 break;
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index d135f93cb0f..1bee4b68fa4 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -142,16 +142,6 @@ early_param("smt-enabled", early_smt_enabled);
142#define check_smt_enabled() 142#define check_smt_enabled()
143#endif /* CONFIG_SMP */ 143#endif /* CONFIG_SMP */
144 144
145/* Put the paca pointer into r13 and SPRG_PACA */
146static void __init setup_paca(struct paca_struct *new_paca)
147{
148 local_paca = new_paca;
149 mtspr(SPRN_SPRG_PACA, local_paca);
150#ifdef CONFIG_PPC_BOOK3E
151 mtspr(SPRN_SPRG_TLB_EXFRAME, local_paca->extlb);
152#endif
153}
154
155/* 145/*
156 * Early initialization entry point. This is called by head.S 146 * Early initialization entry point. This is called by head.S
157 * with MMU translation disabled. We rely on the "feature" of 147 * with MMU translation disabled. We rely on the "feature" of
@@ -600,6 +590,9 @@ static int pcpu_cpu_distance(unsigned int from, unsigned int to)
600 return REMOTE_DISTANCE; 590 return REMOTE_DISTANCE;
601} 591}
602 592
593unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
594EXPORT_SYMBOL(__per_cpu_offset);
595
603void __init setup_per_cpu_areas(void) 596void __init setup_per_cpu_areas(void)
604{ 597{
605 const size_t dyn_size = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE; 598 const size_t dyn_size = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE;
@@ -624,8 +617,10 @@ void __init setup_per_cpu_areas(void)
624 panic("cannot initialize percpu area (err=%d)", rc); 617 panic("cannot initialize percpu area (err=%d)", rc);
625 618
626 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start; 619 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
627 for_each_possible_cpu(cpu) 620 for_each_possible_cpu(cpu) {
628 paca[cpu].data_offset = delta + pcpu_unit_offsets[cpu]; 621 __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
622 paca[cpu].data_offset = __per_cpu_offset[cpu];
623 }
629} 624}
630#endif 625#endif
631 626
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index a0afb555a7c..7109f5b1baa 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/tracehook.h> 12#include <linux/tracehook.h>
13#include <linux/signal.h> 13#include <linux/signal.h>
14#include <asm/hw_breakpoint.h>
14#include <asm/uaccess.h> 15#include <asm/uaccess.h>
15#include <asm/unistd.h> 16#include <asm/unistd.h>
16 17
@@ -149,6 +150,8 @@ static int do_signal_pending(sigset_t *oldset, struct pt_regs *regs)
149 if (current->thread.dabr) 150 if (current->thread.dabr)
150 set_dabr(current->thread.dabr); 151 set_dabr(current->thread.dabr);
151#endif 152#endif
153 /* Re-enable the breakpoints for the signal stack */
154 thread_change_pc(current, regs);
152 155
153 if (is32) { 156 if (is32) {
154 if (ka.sa.sa_flags & SA_SIGINFO) 157 if (ka.sa.sa_flags & SA_SIGINFO)
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 5c196d1086d..a61b3ddd7bb 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -288,8 +288,6 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
288 max_cpus = NR_CPUS; 288 max_cpus = NR_CPUS;
289 else 289 else
290 max_cpus = 1; 290 max_cpus = 1;
291
292 smp_space_timers(max_cpus);
293 291
294 for_each_possible_cpu(cpu) 292 for_each_possible_cpu(cpu)
295 if (cpu != boot_cpuid) 293 if (cpu != boot_cpuid)
@@ -501,14 +499,6 @@ int __devinit start_secondary(void *unused)
501 current->active_mm = &init_mm; 499 current->active_mm = &init_mm;
502 500
503 smp_store_cpu_info(cpu); 501 smp_store_cpu_info(cpu);
504
505#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
506 /* Clear any pending timer interrupts */
507 mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
508
509 /* Enable decrementer interrupt */
510 mtspr(SPRN_TCR, TCR_DIE);
511#endif
512 set_dec(tb_ticks_per_jiffy); 502 set_dec(tb_ticks_per_jiffy);
513 preempt_disable(); 503 preempt_disable();
514 cpu_callin_map[cpu] = 1; 504 cpu_callin_map[cpu] = 1;
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 0441bbdadbd..ccb8759c853 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -149,16 +149,6 @@ unsigned long tb_ticks_per_usec = 100; /* sane default */
149EXPORT_SYMBOL(tb_ticks_per_usec); 149EXPORT_SYMBOL(tb_ticks_per_usec);
150unsigned long tb_ticks_per_sec; 150unsigned long tb_ticks_per_sec;
151EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */ 151EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */
152u64 tb_to_xs;
153unsigned tb_to_us;
154
155#define TICKLEN_SCALE NTP_SCALE_SHIFT
156static u64 last_tick_len; /* units are ns / 2^TICKLEN_SCALE */
157static u64 ticklen_to_xs; /* 0.64 fraction */
158
159/* If last_tick_len corresponds to about 1/HZ seconds, then
160 last_tick_len << TICKLEN_SHIFT will be about 2^63. */
161#define TICKLEN_SHIFT (63 - 30 - TICKLEN_SCALE + SHIFT_HZ)
162 152
163DEFINE_SPINLOCK(rtc_lock); 153DEFINE_SPINLOCK(rtc_lock);
164EXPORT_SYMBOL_GPL(rtc_lock); 154EXPORT_SYMBOL_GPL(rtc_lock);
@@ -174,7 +164,6 @@ unsigned long ppc_proc_freq;
174EXPORT_SYMBOL(ppc_proc_freq); 164EXPORT_SYMBOL(ppc_proc_freq);
175unsigned long ppc_tb_freq; 165unsigned long ppc_tb_freq;
176 166
177static u64 tb_last_jiffy __cacheline_aligned_in_smp;
178static DEFINE_PER_CPU(u64, last_jiffy); 167static DEFINE_PER_CPU(u64, last_jiffy);
179 168
180#ifdef CONFIG_VIRT_CPU_ACCOUNTING 169#ifdef CONFIG_VIRT_CPU_ACCOUNTING
@@ -423,30 +412,6 @@ void udelay(unsigned long usecs)
423} 412}
424EXPORT_SYMBOL(udelay); 413EXPORT_SYMBOL(udelay);
425 414
426static inline void update_gtod(u64 new_tb_stamp, u64 new_stamp_xsec,
427 u64 new_tb_to_xs)
428{
429 /*
430 * tb_update_count is used to allow the userspace gettimeofday code
431 * to assure itself that it sees a consistent view of the tb_to_xs and
432 * stamp_xsec variables. It reads the tb_update_count, then reads
433 * tb_to_xs and stamp_xsec and then reads tb_update_count again. If
434 * the two values of tb_update_count match and are even then the
435 * tb_to_xs and stamp_xsec values are consistent. If not, then it
436 * loops back and reads them again until this criteria is met.
437 * We expect the caller to have done the first increment of
438 * vdso_data->tb_update_count already.
439 */
440 vdso_data->tb_orig_stamp = new_tb_stamp;
441 vdso_data->stamp_xsec = new_stamp_xsec;
442 vdso_data->tb_to_xs = new_tb_to_xs;
443 vdso_data->wtom_clock_sec = wall_to_monotonic.tv_sec;
444 vdso_data->wtom_clock_nsec = wall_to_monotonic.tv_nsec;
445 vdso_data->stamp_xtime = xtime;
446 smp_wmb();
447 ++(vdso_data->tb_update_count);
448}
449
450#ifdef CONFIG_SMP 415#ifdef CONFIG_SMP
451unsigned long profile_pc(struct pt_regs *regs) 416unsigned long profile_pc(struct pt_regs *regs)
452{ 417{
@@ -470,7 +435,6 @@ EXPORT_SYMBOL(profile_pc);
470 435
471static int __init iSeries_tb_recal(void) 436static int __init iSeries_tb_recal(void)
472{ 437{
473 struct div_result divres;
474 unsigned long titan, tb; 438 unsigned long titan, tb;
475 439
476 /* Make sure we only run on iSeries */ 440 /* Make sure we only run on iSeries */
@@ -501,10 +465,7 @@ static int __init iSeries_tb_recal(void)
501 tb_ticks_per_jiffy = new_tb_ticks_per_jiffy; 465 tb_ticks_per_jiffy = new_tb_ticks_per_jiffy;
502 tb_ticks_per_sec = new_tb_ticks_per_sec; 466 tb_ticks_per_sec = new_tb_ticks_per_sec;
503 calc_cputime_factors(); 467 calc_cputime_factors();
504 div128_by_32( XSEC_PER_SEC, 0, tb_ticks_per_sec, &divres );
505 tb_to_xs = divres.result_low;
506 vdso_data->tb_ticks_per_sec = tb_ticks_per_sec; 468 vdso_data->tb_ticks_per_sec = tb_ticks_per_sec;
507 vdso_data->tb_to_xs = tb_to_xs;
508 setup_cputime_one_jiffy(); 469 setup_cputime_one_jiffy();
509 } 470 }
510 else { 471 else {
@@ -667,27 +628,9 @@ void timer_interrupt(struct pt_regs * regs)
667 trace_timer_interrupt_exit(regs); 628 trace_timer_interrupt_exit(regs);
668} 629}
669 630
670void wakeup_decrementer(void)
671{
672 unsigned long ticks;
673
674 /*
675 * The timebase gets saved on sleep and restored on wakeup,
676 * so all we need to do is to reset the decrementer.
677 */
678 ticks = tb_ticks_since(__get_cpu_var(last_jiffy));
679 if (ticks < tb_ticks_per_jiffy)
680 ticks = tb_ticks_per_jiffy - ticks;
681 else
682 ticks = 1;
683 set_dec(ticks);
684}
685
686#ifdef CONFIG_SUSPEND 631#ifdef CONFIG_SUSPEND
687void generic_suspend_disable_irqs(void) 632static void generic_suspend_disable_irqs(void)
688{ 633{
689 preempt_disable();
690
691 /* Disable the decrementer, so that it doesn't interfere 634 /* Disable the decrementer, so that it doesn't interfere
692 * with suspending. 635 * with suspending.
693 */ 636 */
@@ -697,12 +640,9 @@ void generic_suspend_disable_irqs(void)
697 set_dec(0x7fffffff); 640 set_dec(0x7fffffff);
698} 641}
699 642
700void generic_suspend_enable_irqs(void) 643static void generic_suspend_enable_irqs(void)
701{ 644{
702 wakeup_decrementer();
703
704 local_irq_enable(); 645 local_irq_enable();
705 preempt_enable();
706} 646}
707 647
708/* Overrides the weak version in kernel/power/main.c */ 648/* Overrides the weak version in kernel/power/main.c */
@@ -722,23 +662,6 @@ void arch_suspend_enable_irqs(void)
722} 662}
723#endif 663#endif
724 664
725#ifdef CONFIG_SMP
726void __init smp_space_timers(unsigned int max_cpus)
727{
728 int i;
729 u64 previous_tb = per_cpu(last_jiffy, boot_cpuid);
730
731 /* make sure tb > per_cpu(last_jiffy, cpu) for all cpus always */
732 previous_tb -= tb_ticks_per_jiffy;
733
734 for_each_possible_cpu(i) {
735 if (i == boot_cpuid)
736 continue;
737 per_cpu(last_jiffy, i) = previous_tb;
738 }
739}
740#endif
741
742/* 665/*
743 * Scheduler clock - returns current time in nanosec units. 666 * Scheduler clock - returns current time in nanosec units.
744 * 667 *
@@ -873,10 +796,37 @@ static cycle_t timebase_read(struct clocksource *cs)
873 return (cycle_t)get_tb(); 796 return (cycle_t)get_tb();
874} 797}
875 798
799static inline void update_gtod(u64 new_tb_stamp, u64 new_stamp_xsec,
800 u64 new_tb_to_xs, struct timespec *now,
801 u32 frac_sec)
802{
803 /*
804 * tb_update_count is used to allow the userspace gettimeofday code
805 * to assure itself that it sees a consistent view of the tb_to_xs and
806 * stamp_xsec variables. It reads the tb_update_count, then reads
807 * tb_to_xs and stamp_xsec and then reads tb_update_count again. If
808 * the two values of tb_update_count match and are even then the
809 * tb_to_xs and stamp_xsec values are consistent. If not, then it
810 * loops back and reads them again until this criteria is met.
811 * We expect the caller to have done the first increment of
812 * vdso_data->tb_update_count already.
813 */
814 vdso_data->tb_orig_stamp = new_tb_stamp;
815 vdso_data->stamp_xsec = new_stamp_xsec;
816 vdso_data->tb_to_xs = new_tb_to_xs;
817 vdso_data->wtom_clock_sec = wall_to_monotonic.tv_sec;
818 vdso_data->wtom_clock_nsec = wall_to_monotonic.tv_nsec;
819 vdso_data->stamp_xtime = *now;
820 vdso_data->stamp_sec_fraction = frac_sec;
821 smp_wmb();
822 ++(vdso_data->tb_update_count);
823}
824
876void update_vsyscall(struct timespec *wall_time, struct clocksource *clock, 825void update_vsyscall(struct timespec *wall_time, struct clocksource *clock,
877 u32 mult) 826 u32 mult)
878{ 827{
879 u64 t2x, stamp_xsec; 828 u64 t2x, stamp_xsec;
829 u32 frac_sec;
880 830
881 if (clock != &clocksource_timebase) 831 if (clock != &clocksource_timebase)
882 return; 832 return;
@@ -888,10 +838,14 @@ void update_vsyscall(struct timespec *wall_time, struct clocksource *clock,
888 /* XXX this assumes clock->shift == 22 */ 838 /* XXX this assumes clock->shift == 22 */
889 /* 4611686018 ~= 2^(20+64-22) / 1e9 */ 839 /* 4611686018 ~= 2^(20+64-22) / 1e9 */
890 t2x = (u64) mult * 4611686018ULL; 840 t2x = (u64) mult * 4611686018ULL;
891 stamp_xsec = (u64) xtime.tv_nsec * XSEC_PER_SEC; 841 stamp_xsec = (u64) wall_time->tv_nsec * XSEC_PER_SEC;
892 do_div(stamp_xsec, 1000000000); 842 do_div(stamp_xsec, 1000000000);
893 stamp_xsec += (u64) xtime.tv_sec * XSEC_PER_SEC; 843 stamp_xsec += (u64) wall_time->tv_sec * XSEC_PER_SEC;
894 update_gtod(clock->cycle_last, stamp_xsec, t2x); 844
845 BUG_ON(wall_time->tv_nsec >= NSEC_PER_SEC);
846 /* this is tv_nsec / 1e9 as a 0.32 fraction */
847 frac_sec = ((u64) wall_time->tv_nsec * 18446744073ULL) >> 32;
848 update_gtod(clock->cycle_last, stamp_xsec, t2x, wall_time, frac_sec);
895} 849}
896 850
897void update_vsyscall_tz(void) 851void update_vsyscall_tz(void)
@@ -1007,15 +961,13 @@ void secondary_cpu_time_init(void)
1007/* This function is only called on the boot processor */ 961/* This function is only called on the boot processor */
1008void __init time_init(void) 962void __init time_init(void)
1009{ 963{
1010 unsigned long flags;
1011 struct div_result res; 964 struct div_result res;
1012 u64 scale, x; 965 u64 scale;
1013 unsigned shift; 966 unsigned shift;
1014 967
1015 if (__USE_RTC()) { 968 if (__USE_RTC()) {
1016 /* 601 processor: dec counts down by 128 every 128ns */ 969 /* 601 processor: dec counts down by 128 every 128ns */
1017 ppc_tb_freq = 1000000000; 970 ppc_tb_freq = 1000000000;
1018 tb_last_jiffy = get_rtcl();
1019 } else { 971 } else {
1020 /* Normal PowerPC with timebase register */ 972 /* Normal PowerPC with timebase register */
1021 ppc_md.calibrate_decr(); 973 ppc_md.calibrate_decr();
@@ -1023,50 +975,15 @@ void __init time_init(void)
1023 ppc_tb_freq / 1000000, ppc_tb_freq % 1000000); 975 ppc_tb_freq / 1000000, ppc_tb_freq % 1000000);
1024 printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n", 976 printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n",
1025 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000); 977 ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
1026 tb_last_jiffy = get_tb();
1027 } 978 }
1028 979
1029 tb_ticks_per_jiffy = ppc_tb_freq / HZ; 980 tb_ticks_per_jiffy = ppc_tb_freq / HZ;
1030 tb_ticks_per_sec = ppc_tb_freq; 981 tb_ticks_per_sec = ppc_tb_freq;
1031 tb_ticks_per_usec = ppc_tb_freq / 1000000; 982 tb_ticks_per_usec = ppc_tb_freq / 1000000;
1032 tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
1033 calc_cputime_factors(); 983 calc_cputime_factors();
1034 setup_cputime_one_jiffy(); 984 setup_cputime_one_jiffy();
1035 985
1036 /* 986 /*
1037 * Calculate the length of each tick in ns. It will not be
1038 * exactly 1e9/HZ unless ppc_tb_freq is divisible by HZ.
1039 * We compute 1e9 * tb_ticks_per_jiffy / ppc_tb_freq,
1040 * rounded up.
1041 */
1042 x = (u64) NSEC_PER_SEC * tb_ticks_per_jiffy + ppc_tb_freq - 1;
1043 do_div(x, ppc_tb_freq);
1044 tick_nsec = x;
1045 last_tick_len = x << TICKLEN_SCALE;
1046
1047 /*
1048 * Compute ticklen_to_xs, which is a factor which gets multiplied
1049 * by (last_tick_len << TICKLEN_SHIFT) to get a tb_to_xs value.
1050 * It is computed as:
1051 * ticklen_to_xs = 2^N / (tb_ticks_per_jiffy * 1e9)
1052 * where N = 64 + 20 - TICKLEN_SCALE - TICKLEN_SHIFT
1053 * which turns out to be N = 51 - SHIFT_HZ.
1054 * This gives the result as a 0.64 fixed-point fraction.
1055 * That value is reduced by an offset amounting to 1 xsec per
1056 * 2^31 timebase ticks to avoid problems with time going backwards
1057 * by 1 xsec when we do timer_recalc_offset due to losing the
1058 * fractional xsec. That offset is equal to ppc_tb_freq/2^51
1059 * since there are 2^20 xsec in a second.
1060 */
1061 div128_by_32((1ULL << 51) - ppc_tb_freq, 0,
1062 tb_ticks_per_jiffy << SHIFT_HZ, &res);
1063 div128_by_32(res.result_high, res.result_low, NSEC_PER_SEC, &res);
1064 ticklen_to_xs = res.result_low;
1065
1066 /* Compute tb_to_xs from tick_nsec */
1067 tb_to_xs = mulhdu(last_tick_len << TICKLEN_SHIFT, ticklen_to_xs);
1068
1069 /*
1070 * Compute scale factor for sched_clock. 987 * Compute scale factor for sched_clock.
1071 * The calibrate_decr() function has set tb_ticks_per_sec, 988 * The calibrate_decr() function has set tb_ticks_per_sec,
1072 * which is the timebase frequency. 989 * which is the timebase frequency.
@@ -1087,21 +1004,14 @@ void __init time_init(void)
1087 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */ 1004 /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
1088 boot_tb = get_tb_or_rtc(); 1005 boot_tb = get_tb_or_rtc();
1089 1006
1090 write_seqlock_irqsave(&xtime_lock, flags);
1091
1092 /* If platform provided a timezone (pmac), we correct the time */ 1007 /* If platform provided a timezone (pmac), we correct the time */
1093 if (timezone_offset) { 1008 if (timezone_offset) {
1094 sys_tz.tz_minuteswest = -timezone_offset / 60; 1009 sys_tz.tz_minuteswest = -timezone_offset / 60;
1095 sys_tz.tz_dsttime = 0; 1010 sys_tz.tz_dsttime = 0;
1096 } 1011 }
1097 1012
1098 vdso_data->tb_orig_stamp = tb_last_jiffy;
1099 vdso_data->tb_update_count = 0; 1013 vdso_data->tb_update_count = 0;
1100 vdso_data->tb_ticks_per_sec = tb_ticks_per_sec; 1014 vdso_data->tb_ticks_per_sec = tb_ticks_per_sec;
1101 vdso_data->stamp_xsec = (u64) xtime.tv_sec * XSEC_PER_SEC;
1102 vdso_data->tb_to_xs = tb_to_xs;
1103
1104 write_sequnlock_irqrestore(&xtime_lock, flags);
1105 1015
1106 /* Start the decrementer on CPUs that have manual control 1016 /* Start the decrementer on CPUs that have manual control
1107 * such as BookE 1017 * such as BookE
@@ -1195,39 +1105,6 @@ void to_tm(int tim, struct rtc_time * tm)
1195 GregorianDay(tm); 1105 GregorianDay(tm);
1196} 1106}
1197 1107
1198/* Auxiliary function to compute scaling factors */
1199/* Actually the choice of a timebase running at 1/4 the of the bus
1200 * frequency giving resolution of a few tens of nanoseconds is quite nice.
1201 * It makes this computation very precise (27-28 bits typically) which
1202 * is optimistic considering the stability of most processor clock
1203 * oscillators and the precision with which the timebase frequency
1204 * is measured but does not harm.
1205 */
1206unsigned mulhwu_scale_factor(unsigned inscale, unsigned outscale)
1207{
1208 unsigned mlt=0, tmp, err;
1209 /* No concern for performance, it's done once: use a stupid
1210 * but safe and compact method to find the multiplier.
1211 */
1212
1213 for (tmp = 1U<<31; tmp != 0; tmp >>= 1) {
1214 if (mulhwu(inscale, mlt|tmp) < outscale)
1215 mlt |= tmp;
1216 }
1217
1218 /* We might still be off by 1 for the best approximation.
1219 * A side effect of this is that if outscale is too large
1220 * the returned value will be zero.
1221 * Many corner cases have been checked and seem to work,
1222 * some might have been forgotten in the test however.
1223 */
1224
1225 err = inscale * (mlt+1);
1226 if (err <= inscale/2)
1227 mlt++;
1228 return mlt;
1229}
1230
1231/* 1108/*
1232 * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit 1109 * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit
1233 * result. 1110 * result.
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 25fc33984c2..a45a63c3a0c 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -55,9 +55,6 @@
55#endif 55#endif
56#include <asm/kexec.h> 56#include <asm/kexec.h>
57#include <asm/ppc-opcode.h> 57#include <asm/ppc-opcode.h>
58#ifdef CONFIG_FSL_BOOKE
59#include <asm/dbell.h>
60#endif
61 58
62#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) 59#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
63int (*__debugger)(struct pt_regs *regs) __read_mostly; 60int (*__debugger)(struct pt_regs *regs) __read_mostly;
@@ -688,7 +685,7 @@ void RunModeException(struct pt_regs *regs)
688 685
689void __kprobes single_step_exception(struct pt_regs *regs) 686void __kprobes single_step_exception(struct pt_regs *regs)
690{ 687{
691 regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */ 688 clear_single_step(regs);
692 689
693 if (notify_die(DIE_SSTEP, "single_step", regs, 5, 690 if (notify_die(DIE_SSTEP, "single_step", regs, 5,
694 5, SIGTRAP) == NOTIFY_STOP) 691 5, SIGTRAP) == NOTIFY_STOP)
@@ -707,10 +704,8 @@ void __kprobes single_step_exception(struct pt_regs *regs)
707 */ 704 */
708static void emulate_single_step(struct pt_regs *regs) 705static void emulate_single_step(struct pt_regs *regs)
709{ 706{
710 if (single_stepping(regs)) { 707 if (single_stepping(regs))
711 clear_single_step(regs); 708 single_step_exception(regs);
712 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
713 }
714} 709}
715 710
716static inline int __parse_fpscr(unsigned long fpscr) 711static inline int __parse_fpscr(unsigned long fpscr)
@@ -1344,24 +1339,6 @@ void vsx_assist_exception(struct pt_regs *regs)
1344#endif /* CONFIG_VSX */ 1339#endif /* CONFIG_VSX */
1345 1340
1346#ifdef CONFIG_FSL_BOOKE 1341#ifdef CONFIG_FSL_BOOKE
1347
1348void doorbell_exception(struct pt_regs *regs)
1349{
1350#ifdef CONFIG_SMP
1351 int cpu = smp_processor_id();
1352 int msg;
1353
1354 if (num_online_cpus() < 2)
1355 return;
1356
1357 for (msg = 0; msg < 4; msg++)
1358 if (test_and_clear_bit(msg, &dbell_smp_message[cpu]))
1359 smp_message_recv(msg);
1360#else
1361 printk(KERN_WARNING "Received doorbell on non-smp system\n");
1362#endif
1363}
1364
1365void CacheLockingException(struct pt_regs *regs, unsigned long address, 1342void CacheLockingException(struct pt_regs *regs, unsigned long address,
1366 unsigned long error_code) 1343 unsigned long error_code)
1367{ 1344{
diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S b/arch/powerpc/kernel/vdso32/gettimeofday.S
index ee038d4bf25..4ee09ee2e83 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -19,8 +19,10 @@
19/* Offset for the low 32-bit part of a field of long type */ 19/* Offset for the low 32-bit part of a field of long type */
20#ifdef CONFIG_PPC64 20#ifdef CONFIG_PPC64
21#define LOPART 4 21#define LOPART 4
22#define TSPEC_TV_SEC TSPC64_TV_SEC+LOPART
22#else 23#else
23#define LOPART 0 24#define LOPART 0
25#define TSPEC_TV_SEC TSPC32_TV_SEC
24#endif 26#endif
25 27
26 .text 28 .text
@@ -41,23 +43,11 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday)
41 mr r9, r3 /* datapage ptr in r9 */ 43 mr r9, r3 /* datapage ptr in r9 */
42 cmplwi r10,0 /* check if tv is NULL */ 44 cmplwi r10,0 /* check if tv is NULL */
43 beq 3f 45 beq 3f
44 bl __do_get_xsec@local /* get xsec from tb & kernel */ 46 lis r7,1000000@ha /* load up USEC_PER_SEC */
45 bne- 2f /* out of line -> do syscall */ 47 addi r7,r7,1000000@l /* so we get microseconds in r4 */
46 48 bl __do_get_tspec@local /* get sec/usec from tb & kernel */
47 /* seconds are xsec >> 20 */ 49 stw r3,TVAL32_TV_SEC(r10)
48 rlwinm r5,r4,12,20,31 50 stw r4,TVAL32_TV_USEC(r10)
49 rlwimi r5,r3,12,0,19
50 stw r5,TVAL32_TV_SEC(r10)
51
52 /* get remaining xsec and convert to usec. we scale
53 * up remaining xsec by 12 bits and get the top 32 bits
54 * of the multiplication
55 */
56 rlwinm r5,r4,12,0,19
57 lis r6,1000000@h
58 ori r6,r6,1000000@l
59 mulhwu r5,r5,r6
60 stw r5,TVAL32_TV_USEC(r10)
61 51
623: cmplwi r11,0 /* check if tz is NULL */ 523: cmplwi r11,0 /* check if tz is NULL */
63 beq 1f 53 beq 1f
@@ -70,14 +60,6 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday)
70 crclr cr0*4+so 60 crclr cr0*4+so
71 li r3,0 61 li r3,0
72 blr 62 blr
73
742:
75 mtlr r12
76 mr r3,r10
77 mr r4,r11
78 li r0,__NR_gettimeofday
79 sc
80 blr
81 .cfi_endproc 63 .cfi_endproc
82V_FUNCTION_END(__kernel_gettimeofday) 64V_FUNCTION_END(__kernel_gettimeofday)
83 65
@@ -100,7 +82,8 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
100 mr r11,r4 /* r11 saves tp */ 82 mr r11,r4 /* r11 saves tp */
101 bl __get_datapage@local /* get data page */ 83 bl __get_datapage@local /* get data page */
102 mr r9,r3 /* datapage ptr in r9 */ 84 mr r9,r3 /* datapage ptr in r9 */
103 85 lis r7,NSEC_PER_SEC@h /* want nanoseconds */
86 ori r7,r7,NSEC_PER_SEC@l
10450: bl __do_get_tspec@local /* get sec/nsec from tb & kernel */ 8750: bl __do_get_tspec@local /* get sec/nsec from tb & kernel */
105 bne cr1,80f /* not monotonic -> all done */ 88 bne cr1,80f /* not monotonic -> all done */
106 89
@@ -198,83 +181,12 @@ V_FUNCTION_END(__kernel_clock_getres)
198 181
199 182
200/* 183/*
201 * This is the core of gettimeofday() & friends, it returns the xsec 184 * This is the core of clock_gettime() and gettimeofday(),
202 * value in r3 & r4 and expects the datapage ptr (non clobbered) 185 * it returns the current time in r3 (seconds) and r4.
203 * in r9. clobbers r0,r4,r5,r6,r7,r8. 186 * On entry, r7 gives the resolution of r4, either USEC_PER_SEC
204 * When returning, r8 contains the counter value that can be reused 187 * or NSEC_PER_SEC, giving r4 in microseconds or nanoseconds.
205 * by the monotonic clock implementation
206 */
207__do_get_xsec:
208 .cfi_startproc
209 /* Check for update count & load values. We use the low
210 * order 32 bits of the update count
211 */
2121: lwz r8,(CFG_TB_UPDATE_COUNT+LOPART)(r9)
213 andi. r0,r8,1 /* pending update ? loop */
214 bne- 1b
215 xor r0,r8,r8 /* create dependency */
216 add r9,r9,r0
217
218 /* Load orig stamp (offset to TB) */
219 lwz r5,CFG_TB_ORIG_STAMP(r9)
220 lwz r6,(CFG_TB_ORIG_STAMP+4)(r9)
221
222 /* Get a stable TB value */
2232: mftbu r3
224 mftbl r4
225 mftbu r0
226 cmpl cr0,r3,r0
227 bne- 2b
228
229 /* Substract tb orig stamp. If the high part is non-zero, we jump to
230 * the slow path which call the syscall.
231 * If it's ok, then we have our 32 bits tb_ticks value in r7
232 */
233 subfc r7,r6,r4
234 subfe. r0,r5,r3
235 bne- 3f
236
237 /* Load scale factor & do multiplication */
238 lwz r5,CFG_TB_TO_XS(r9) /* load values */
239 lwz r6,(CFG_TB_TO_XS+4)(r9)
240 mulhwu r4,r7,r5
241 mulhwu r6,r7,r6
242 mullw r0,r7,r5
243 addc r6,r6,r0
244
245 /* At this point, we have the scaled xsec value in r4 + XER:CA
246 * we load & add the stamp since epoch
247 */
248 lwz r5,CFG_STAMP_XSEC(r9)
249 lwz r6,(CFG_STAMP_XSEC+4)(r9)
250 adde r4,r4,r6
251 addze r3,r5
252
253 /* We now have our result in r3,r4. We create a fake dependency
254 * on that result and re-check the counter
255 */
256 or r6,r4,r3
257 xor r0,r6,r6
258 add r9,r9,r0
259 lwz r0,(CFG_TB_UPDATE_COUNT+LOPART)(r9)
260 cmpl cr0,r8,r0 /* check if updated */
261 bne- 1b
262
263 /* Warning ! The caller expects CR:EQ to be set to indicate a
264 * successful calculation (so it won't fallback to the syscall
265 * method). We have overriden that CR bit in the counter check,
266 * but fortunately, the loop exit condition _is_ CR:EQ set, so
267 * we can exit safely here. If you change this code, be careful
268 * of that side effect.
269 */
2703: blr
271 .cfi_endproc
272
273/*
274 * This is the core of clock_gettime(), it returns the current
275 * time in seconds and nanoseconds in r3 and r4.
276 * It expects the datapage ptr in r9 and doesn't clobber it. 188 * It expects the datapage ptr in r9 and doesn't clobber it.
277 * It clobbers r0, r5, r6, r10 and returns NSEC_PER_SEC in r7. 189 * It clobbers r0, r5 and r6.
278 * On return, r8 contains the counter value that can be reused. 190 * On return, r8 contains the counter value that can be reused.
279 * This clobbers cr0 but not any other cr field. 191 * This clobbers cr0 but not any other cr field.
280 */ 192 */
@@ -297,70 +209,58 @@ __do_get_tspec:
2972: mftbu r3 2092: mftbu r3
298 mftbl r4 210 mftbl r4
299 mftbu r0 211 mftbu r0
300 cmpl cr0,r3,r0 212 cmplw cr0,r3,r0
301 bne- 2b 213 bne- 2b
302 214
303 /* Subtract tb orig stamp and shift left 12 bits. 215 /* Subtract tb orig stamp and shift left 12 bits.
304 */ 216 */
305 subfc r7,r6,r4 217 subfc r4,r6,r4
306 subfe r0,r5,r3 218 subfe r0,r5,r3
307 slwi r0,r0,12 219 slwi r0,r0,12
308 rlwimi. r0,r7,12,20,31 220 rlwimi. r0,r4,12,20,31
309 slwi r7,r7,12 221 slwi r4,r4,12
310 222
311 /* Load scale factor & do multiplication */ 223 /*
224 * Load scale factor & do multiplication.
225 * We only use the high 32 bits of the tb_to_xs value.
226 * Even with a 1GHz timebase clock, the high 32 bits of
227 * tb_to_xs will be at least 4 million, so the error from
228 * ignoring the low 32 bits will be no more than 0.25ppm.
229 * The error will just make the clock run very very slightly
230 * slow until the next time the kernel updates the VDSO data,
231 * at which point the clock will catch up to the kernel's value,
232 * so there is no long-term error accumulation.
233 */
312 lwz r5,CFG_TB_TO_XS(r9) /* load values */ 234 lwz r5,CFG_TB_TO_XS(r9) /* load values */
313 lwz r6,(CFG_TB_TO_XS+4)(r9) 235 mulhwu r4,r4,r5
314 mulhwu r3,r7,r6
315 mullw r10,r7,r5
316 mulhwu r4,r7,r5
317 addc r10,r3,r10
318 li r3,0 236 li r3,0
319 237
320 beq+ 4f /* skip high part computation if 0 */ 238 beq+ 4f /* skip high part computation if 0 */
321 mulhwu r3,r0,r5 239 mulhwu r3,r0,r5
322 mullw r7,r0,r5 240 mullw r5,r0,r5
323 mulhwu r5,r0,r6
324 mullw r6,r0,r6
325 adde r4,r4,r7
326 addze r3,r3
327 addc r4,r4,r5 241 addc r4,r4,r5
328 addze r3,r3 242 addze r3,r3
329 addc r10,r10,r6 2434:
330 244 /* At this point, we have seconds since the xtime stamp
3314: addze r4,r4 /* add in carry */ 245 * as a 32.32 fixed-point number in r3 and r4.
332 lis r7,NSEC_PER_SEC@h 246 * Load & add the xtime stamp.
333 ori r7,r7,NSEC_PER_SEC@l
334 mulhwu r4,r4,r7 /* convert to nanoseconds */
335
336 /* At this point, we have seconds & nanoseconds since the xtime
337 * stamp in r3+CA and r4. Load & add the xtime stamp.
338 */ 247 */
339#ifdef CONFIG_PPC64 248 lwz r5,STAMP_XTIME+TSPEC_TV_SEC(r9)
340 lwz r5,STAMP_XTIME+TSPC64_TV_SEC+LOPART(r9) 249 lwz r6,STAMP_SEC_FRAC(r9)
341 lwz r6,STAMP_XTIME+TSPC64_TV_NSEC+LOPART(r9) 250 addc r4,r4,r6
342#else
343 lwz r5,STAMP_XTIME+TSPC32_TV_SEC(r9)
344 lwz r6,STAMP_XTIME+TSPC32_TV_NSEC(r9)
345#endif
346 add r4,r4,r6
347 adde r3,r3,r5 251 adde r3,r3,r5
348 252
349 /* We now have our result in r3,r4. We create a fake dependency 253 /* We create a fake dependency on the result in r3/r4
350 * on that result and re-check the counter 254 * and re-check the counter
351 */ 255 */
352 or r6,r4,r3 256 or r6,r4,r3
353 xor r0,r6,r6 257 xor r0,r6,r6
354 add r9,r9,r0 258 add r9,r9,r0
355 lwz r0,(CFG_TB_UPDATE_COUNT+LOPART)(r9) 259 lwz r0,(CFG_TB_UPDATE_COUNT+LOPART)(r9)
356 cmpl cr0,r8,r0 /* check if updated */ 260 cmplw cr0,r8,r0 /* check if updated */
357 bne- 1b 261 bne- 1b
358 262
359 /* check for nanosecond overflow and adjust if necessary */ 263 mulhwu r4,r4,r7 /* convert to micro or nanoseconds */
360 cmpw r4,r7
361 bltlr /* all done if no overflow */
362 subf r4,r7,r4 /* adjust if overflow */
363 addi r3,r3,1
364 264
365 blr 265 blr
366 .cfi_endproc 266 .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S
index 262cd5857a5..e97a9a0dc4a 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -33,18 +33,11 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday)
33 bl V_LOCAL_FUNC(__get_datapage) /* get data page */ 33 bl V_LOCAL_FUNC(__get_datapage) /* get data page */
34 cmpldi r11,0 /* check if tv is NULL */ 34 cmpldi r11,0 /* check if tv is NULL */
35 beq 2f 35 beq 2f
36 bl V_LOCAL_FUNC(__do_get_xsec) /* get xsec from tb & kernel */ 36 lis r7,1000000@ha /* load up USEC_PER_SEC */
37 lis r7,15 /* r7 = 1000000 = USEC_PER_SEC */ 37 addi r7,r7,1000000@l
38 ori r7,r7,16960 38 bl V_LOCAL_FUNC(__do_get_tspec) /* get sec/us from tb & kernel */
39 rldicl r5,r4,44,20 /* r5 = sec = xsec / XSEC_PER_SEC */ 39 std r4,TVAL64_TV_SEC(r11) /* store sec in tv */
40 rldicr r6,r5,20,43 /* r6 = sec * XSEC_PER_SEC */ 40 std r5,TVAL64_TV_USEC(r11) /* store usec in tv */
41 std r5,TVAL64_TV_SEC(r11) /* store sec in tv */
42 subf r0,r6,r4 /* r0 = xsec = (xsec - r6) */
43 mulld r0,r0,r7 /* usec = (xsec * USEC_PER_SEC) /
44 * XSEC_PER_SEC
45 */
46 rldicl r0,r0,44,20
47 std r0,TVAL64_TV_USEC(r11) /* store usec in tv */
482: cmpldi r10,0 /* check if tz is NULL */ 412: cmpldi r10,0 /* check if tz is NULL */
49 beq 1f 42 beq 1f
50 lwz r4,CFG_TZ_MINUTEWEST(r3)/* fill tz */ 43 lwz r4,CFG_TZ_MINUTEWEST(r3)/* fill tz */
@@ -77,6 +70,8 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
77 .cfi_register lr,r12 70 .cfi_register lr,r12
78 mr r11,r4 /* r11 saves tp */ 71 mr r11,r4 /* r11 saves tp */
79 bl V_LOCAL_FUNC(__get_datapage) /* get data page */ 72 bl V_LOCAL_FUNC(__get_datapage) /* get data page */
73 lis r7,NSEC_PER_SEC@h /* want nanoseconds */
74 ori r7,r7,NSEC_PER_SEC@l
8050: bl V_LOCAL_FUNC(__do_get_tspec) /* get time from tb & kernel */ 7550: bl V_LOCAL_FUNC(__do_get_tspec) /* get time from tb & kernel */
81 bne cr1,80f /* if not monotonic, all done */ 76 bne cr1,80f /* if not monotonic, all done */
82 77
@@ -171,49 +166,12 @@ V_FUNCTION_END(__kernel_clock_getres)
171 166
172 167
173/* 168/*
174 * This is the core of gettimeofday(), it returns the xsec 169 * This is the core of clock_gettime() and gettimeofday(),
175 * value in r4 and expects the datapage ptr (non clobbered) 170 * it returns the current time in r4 (seconds) and r5.
176 * in r3. clobbers r0,r4,r5,r6,r7,r8 171 * On entry, r7 gives the resolution of r5, either USEC_PER_SEC
177 * When returning, r8 contains the counter value that can be reused 172 * or NSEC_PER_SEC, giving r5 in microseconds or nanoseconds.
178 */
179V_FUNCTION_BEGIN(__do_get_xsec)
180 .cfi_startproc
181 /* check for update count & load values */
1821: ld r8,CFG_TB_UPDATE_COUNT(r3)
183 andi. r0,r8,1 /* pending update ? loop */
184 bne- 1b
185 xor r0,r8,r8 /* create dependency */
186 add r3,r3,r0
187
188 /* Get TB & offset it. We use the MFTB macro which will generate
189 * workaround code for Cell.
190 */
191 MFTB(r7)
192 ld r9,CFG_TB_ORIG_STAMP(r3)
193 subf r7,r9,r7
194
195 /* Scale result */
196 ld r5,CFG_TB_TO_XS(r3)
197 mulhdu r7,r7,r5
198
199 /* Add stamp since epoch */
200 ld r6,CFG_STAMP_XSEC(r3)
201 add r4,r6,r7
202
203 xor r0,r4,r4
204 add r3,r3,r0
205 ld r0,CFG_TB_UPDATE_COUNT(r3)
206 cmpld cr0,r0,r8 /* check if updated */
207 bne- 1b
208 blr
209 .cfi_endproc
210V_FUNCTION_END(__do_get_xsec)
211
212/*
213 * This is the core of clock_gettime(), it returns the current
214 * time in seconds and nanoseconds in r4 and r5.
215 * It expects the datapage ptr in r3 and doesn't clobber it. 173 * It expects the datapage ptr in r3 and doesn't clobber it.
216 * It clobbers r0 and r6 and returns NSEC_PER_SEC in r7. 174 * It clobbers r0, r6 and r9.
217 * On return, r8 contains the counter value that can be reused. 175 * On return, r8 contains the counter value that can be reused.
218 * This clobbers cr0 but not any other cr field. 176 * This clobbers cr0 but not any other cr field.
219 */ 177 */
@@ -229,18 +187,18 @@ V_FUNCTION_BEGIN(__do_get_tspec)
229 /* Get TB & offset it. We use the MFTB macro which will generate 187 /* Get TB & offset it. We use the MFTB macro which will generate
230 * workaround code for Cell. 188 * workaround code for Cell.
231 */ 189 */
232 MFTB(r7) 190 MFTB(r6)
233 ld r9,CFG_TB_ORIG_STAMP(r3) 191 ld r9,CFG_TB_ORIG_STAMP(r3)
234 subf r7,r9,r7 192 subf r6,r9,r6
235 193
236 /* Scale result */ 194 /* Scale result */
237 ld r5,CFG_TB_TO_XS(r3) 195 ld r5,CFG_TB_TO_XS(r3)
238 sldi r7,r7,12 /* compute time since stamp_xtime */ 196 sldi r6,r6,12 /* compute time since stamp_xtime */
239 mulhdu r6,r7,r5 /* in units of 2^-32 seconds */ 197 mulhdu r6,r6,r5 /* in units of 2^-32 seconds */
240 198
241 /* Add stamp since epoch */ 199 /* Add stamp since epoch */
242 ld r4,STAMP_XTIME+TSPC64_TV_SEC(r3) 200 ld r4,STAMP_XTIME+TSPC64_TV_SEC(r3)
243 ld r5,STAMP_XTIME+TSPC64_TV_NSEC(r3) 201 lwz r5,STAMP_SEC_FRAC(r3)
244 or r0,r4,r5 202 or r0,r4,r5
245 or r0,r0,r6 203 or r0,r0,r6
246 xor r0,r0,r0 204 xor r0,r0,r0
@@ -250,17 +208,11 @@ V_FUNCTION_BEGIN(__do_get_tspec)
250 bne- 1b /* reload if so */ 208 bne- 1b /* reload if so */
251 209
252 /* convert to seconds & nanoseconds and add to stamp */ 210 /* convert to seconds & nanoseconds and add to stamp */
253 lis r7,NSEC_PER_SEC@h 211 add r6,r6,r5 /* add on fractional seconds of xtime */
254 ori r7,r7,NSEC_PER_SEC@l 212 mulhwu r5,r6,r7 /* compute micro or nanoseconds and */
255 mulhwu r0,r6,r7 /* compute nanoseconds and */
256 srdi r6,r6,32 /* seconds since stamp_xtime */ 213 srdi r6,r6,32 /* seconds since stamp_xtime */
257 clrldi r0,r0,32 214 clrldi r5,r5,32
258 add r5,r5,r0 /* add nanoseconds together */
259 cmpd r5,r7 /* overflow? */
260 add r4,r4,r6 215 add r4,r4,r6
261 bltlr /* all done if no overflow */
262 subf r5,r7,r5 /* if overflow, adjust */
263 addi r4,r4,1
264 blr 216 blr
265 .cfi_endproc 217 .cfi_endproc
266V_FUNCTION_END(__do_get_tspec) 218V_FUNCTION_END(__do_get_tspec)
diff --git a/arch/powerpc/kvm/timing.c b/arch/powerpc/kvm/timing.c
index 70378551c0c..46fa04f12a9 100644
--- a/arch/powerpc/kvm/timing.c
+++ b/arch/powerpc/kvm/timing.c
@@ -182,7 +182,7 @@ static ssize_t kvmppc_exit_timing_write(struct file *file,
182 } 182 }
183 183
184 if (c == 'c') { 184 if (c == 'c') {
185 struct seq_file *seqf = (struct seq_file *)file->private_data; 185 struct seq_file *seqf = file->private_data;
186 struct kvm_vcpu *vcpu = seqf->private; 186 struct kvm_vcpu *vcpu = seqf->private;
187 /* Write does not affect our buffers previously generated with 187 /* Write does not affect our buffers previously generated with
188 * show. seq_file is locked here to prevent races of init with 188 * show. seq_file is locked here to prevent races of init with
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 111da1c03a1..5bb89c82807 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -18,8 +18,9 @@ obj-$(CONFIG_HAS_IOMEM) += devres.o
18 18
19obj-$(CONFIG_PPC64) += copypage_64.o copyuser_64.o \ 19obj-$(CONFIG_PPC64) += copypage_64.o copyuser_64.o \
20 memcpy_64.o usercopy_64.o mem_64.o string.o 20 memcpy_64.o usercopy_64.o mem_64.o string.o
21obj-$(CONFIG_XMON) += sstep.o 21obj-$(CONFIG_XMON) += sstep.o ldstfp.o
22obj-$(CONFIG_KPROBES) += sstep.o 22obj-$(CONFIG_KPROBES) += sstep.o ldstfp.o
23obj-$(CONFIG_HAVE_HW_BREAKPOINT) += sstep.o ldstfp.o
23 24
24ifeq ($(CONFIG_PPC64),y) 25ifeq ($(CONFIG_PPC64),y)
25obj-$(CONFIG_SMP) += locks.o 26obj-$(CONFIG_SMP) += locks.o
diff --git a/arch/powerpc/lib/ldstfp.S b/arch/powerpc/lib/ldstfp.S
new file mode 100644
index 00000000000..f6448636baf
--- /dev/null
+++ b/arch/powerpc/lib/ldstfp.S
@@ -0,0 +1,375 @@
1/*
2 * Floating-point, VMX/Altivec and VSX loads and stores
3 * for use in instruction emulation.
4 *
5 * Copyright 2010 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <asm/processor.h>
14#include <asm/ppc_asm.h>
15#include <asm/ppc-opcode.h>
16#include <asm/reg.h>
17#include <asm/asm-offsets.h>
18#include <linux/errno.h>
19
20#define STKFRM (PPC_MIN_STKFRM + 16)
21
22 .macro extab instr,handler
23 .section __ex_table,"a"
24 PPC_LONG \instr,\handler
25 .previous
26 .endm
27
28 .macro inst32 op
29reg = 0
30 .rept 32
3120: \op reg,0,r4
32 b 3f
33 extab 20b,99f
34reg = reg + 1
35 .endr
36 .endm
37
38/* Get the contents of frN into fr0; N is in r3. */
39_GLOBAL(get_fpr)
40 mflr r0
41 rlwinm r3,r3,3,0xf8
42 bcl 20,31,1f
43 blr /* fr0 is already in fr0 */
44 nop
45reg = 1
46 .rept 31
47 fmr fr0,reg
48 blr
49reg = reg + 1
50 .endr
511: mflr r5
52 add r5,r3,r5
53 mtctr r5
54 mtlr r0
55 bctr
56
57/* Put the contents of fr0 into frN; N is in r3. */
58_GLOBAL(put_fpr)
59 mflr r0
60 rlwinm r3,r3,3,0xf8
61 bcl 20,31,1f
62 blr /* fr0 is already in fr0 */
63 nop
64reg = 1
65 .rept 31
66 fmr reg,fr0
67 blr
68reg = reg + 1
69 .endr
701: mflr r5
71 add r5,r3,r5
72 mtctr r5
73 mtlr r0
74 bctr
75
76/* Load FP reg N from float at *p. N is in r3, p in r4. */
77_GLOBAL(do_lfs)
78 PPC_STLU r1,-STKFRM(r1)
79 mflr r0
80 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
81 mfmsr r6
82 ori r7,r6,MSR_FP
83 cmpwi cr7,r3,0
84 mtmsrd r7
85 isync
86 beq cr7,1f
87 stfd fr0,STKFRM-16(r1)
881: li r9,-EFAULT
892: lfs fr0,0(r4)
90 li r9,0
913: bl put_fpr
92 beq cr7,4f
93 lfd fr0,STKFRM-16(r1)
944: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
95 mtlr r0
96 mtmsrd r6
97 isync
98 mr r3,r9
99 addi r1,r1,STKFRM
100 blr
101 extab 2b,3b
102
103/* Load FP reg N from double at *p. N is in r3, p in r4. */
104_GLOBAL(do_lfd)
105 PPC_STLU r1,-STKFRM(r1)
106 mflr r0
107 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
108 mfmsr r6
109 ori r7,r6,MSR_FP
110 cmpwi cr7,r3,0
111 mtmsrd r7
112 isync
113 beq cr7,1f
114 stfd fr0,STKFRM-16(r1)
1151: li r9,-EFAULT
1162: lfd fr0,0(r4)
117 li r9,0
1183: beq cr7,4f
119 bl put_fpr
120 lfd fr0,STKFRM-16(r1)
1214: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
122 mtlr r0
123 mtmsrd r6
124 isync
125 mr r3,r9
126 addi r1,r1,STKFRM
127 blr
128 extab 2b,3b
129
130/* Store FP reg N to float at *p. N is in r3, p in r4. */
131_GLOBAL(do_stfs)
132 PPC_STLU r1,-STKFRM(r1)
133 mflr r0
134 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
135 mfmsr r6
136 ori r7,r6,MSR_FP
137 cmpwi cr7,r3,0
138 mtmsrd r7
139 isync
140 beq cr7,1f
141 stfd fr0,STKFRM-16(r1)
142 bl get_fpr
1431: li r9,-EFAULT
1442: stfs fr0,0(r4)
145 li r9,0
1463: beq cr7,4f
147 lfd fr0,STKFRM-16(r1)
1484: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
149 mtlr r0
150 mtmsrd r6
151 isync
152 mr r3,r9
153 addi r1,r1,STKFRM
154 blr
155 extab 2b,3b
156
157/* Store FP reg N to double at *p. N is in r3, p in r4. */
158_GLOBAL(do_stfd)
159 PPC_STLU r1,-STKFRM(r1)
160 mflr r0
161 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
162 mfmsr r6
163 ori r7,r6,MSR_FP
164 cmpwi cr7,r3,0
165 mtmsrd r7
166 isync
167 beq cr7,1f
168 stfd fr0,STKFRM-16(r1)
169 bl get_fpr
1701: li r9,-EFAULT
1712: stfd fr0,0(r4)
172 li r9,0
1733: beq cr7,4f
174 lfd fr0,STKFRM-16(r1)
1754: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
176 mtlr r0
177 mtmsrd r6
178 isync
179 mr r3,r9
180 addi r1,r1,STKFRM
181 blr
182 extab 2b,3b
183
184#ifdef CONFIG_ALTIVEC
185/* Get the contents of vrN into vr0; N is in r3. */
186_GLOBAL(get_vr)
187 mflr r0
188 rlwinm r3,r3,3,0xf8
189 bcl 20,31,1f
190 blr /* vr0 is already in vr0 */
191 nop
192reg = 1
193 .rept 31
194 vor vr0,reg,reg /* assembler doesn't know vmr? */
195 blr
196reg = reg + 1
197 .endr
1981: mflr r5
199 add r5,r3,r5
200 mtctr r5
201 mtlr r0
202 bctr
203
204/* Put the contents of vr0 into vrN; N is in r3. */
205_GLOBAL(put_vr)
206 mflr r0
207 rlwinm r3,r3,3,0xf8
208 bcl 20,31,1f
209 blr /* vr0 is already in vr0 */
210 nop
211reg = 1
212 .rept 31
213 vor reg,vr0,vr0
214 blr
215reg = reg + 1
216 .endr
2171: mflr r5
218 add r5,r3,r5
219 mtctr r5
220 mtlr r0
221 bctr
222
223/* Load vector reg N from *p. N is in r3, p in r4. */
224_GLOBAL(do_lvx)
225 PPC_STLU r1,-STKFRM(r1)
226 mflr r0
227 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
228 mfmsr r6
229 oris r7,r6,MSR_VEC@h
230 cmpwi cr7,r3,0
231 li r8,STKFRM-16
232 mtmsrd r7
233 isync
234 beq cr7,1f
235 stvx vr0,r1,r8
2361: li r9,-EFAULT
2372: lvx vr0,0,r4
238 li r9,0
2393: beq cr7,4f
240 bl put_vr
241 lvx vr0,r1,r8
2424: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
243 mtlr r0
244 mtmsrd r6
245 isync
246 mr r3,r9
247 addi r1,r1,STKFRM
248 blr
249 extab 2b,3b
250
251/* Store vector reg N to *p. N is in r3, p in r4. */
252_GLOBAL(do_stvx)
253 PPC_STLU r1,-STKFRM(r1)
254 mflr r0
255 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
256 mfmsr r6
257 oris r7,r6,MSR_VEC@h
258 cmpwi cr7,r3,0
259 li r8,STKFRM-16
260 mtmsrd r7
261 isync
262 beq cr7,1f
263 stvx vr0,r1,r8
264 bl get_vr
2651: li r9,-EFAULT
2662: stvx vr0,0,r4
267 li r9,0
2683: beq cr7,4f
269 lvx vr0,r1,r8
2704: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
271 mtlr r0
272 mtmsrd r6
273 isync
274 mr r3,r9
275 addi r1,r1,STKFRM
276 blr
277 extab 2b,3b
278#endif /* CONFIG_ALTIVEC */
279
280#ifdef CONFIG_VSX
281/* Get the contents of vsrN into vsr0; N is in r3. */
282_GLOBAL(get_vsr)
283 mflr r0
284 rlwinm r3,r3,3,0x1f8
285 bcl 20,31,1f
286 blr /* vsr0 is already in vsr0 */
287 nop
288reg = 1
289 .rept 63
290 XXLOR(0,reg,reg)
291 blr
292reg = reg + 1
293 .endr
2941: mflr r5
295 add r5,r3,r5
296 mtctr r5
297 mtlr r0
298 bctr
299
300/* Put the contents of vsr0 into vsrN; N is in r3. */
301_GLOBAL(put_vsr)
302 mflr r0
303 rlwinm r3,r3,3,0x1f8
304 bcl 20,31,1f
305 blr /* vr0 is already in vr0 */
306 nop
307reg = 1
308 .rept 63
309 XXLOR(reg,0,0)
310 blr
311reg = reg + 1
312 .endr
3131: mflr r5
314 add r5,r3,r5
315 mtctr r5
316 mtlr r0
317 bctr
318
319/* Load VSX reg N from vector doubleword *p. N is in r3, p in r4. */
320_GLOBAL(do_lxvd2x)
321 PPC_STLU r1,-STKFRM(r1)
322 mflr r0
323 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
324 mfmsr r6
325 oris r7,r6,MSR_VSX@h
326 cmpwi cr7,r3,0
327 li r8,STKFRM-16
328 mtmsrd r7
329 isync
330 beq cr7,1f
331 STXVD2X(0,r1,r8)
3321: li r9,-EFAULT
3332: LXVD2X(0,0,r4)
334 li r9,0
3353: beq cr7,4f
336 bl put_vsr
337 LXVD2X(0,r1,r8)
3384: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
339 mtlr r0
340 mtmsrd r6
341 isync
342 mr r3,r9
343 addi r1,r1,STKFRM
344 blr
345 extab 2b,3b
346
347/* Store VSX reg N to vector doubleword *p. N is in r3, p in r4. */
348_GLOBAL(do_stxvd2x)
349 PPC_STLU r1,-STKFRM(r1)
350 mflr r0
351 PPC_STL r0,STKFRM+PPC_LR_STKOFF(r1)
352 mfmsr r6
353 oris r7,r6,MSR_VSX@h
354 cmpwi cr7,r3,0
355 li r8,STKFRM-16
356 mtmsrd r7
357 isync
358 beq cr7,1f
359 STXVD2X(0,r1,r8)
360 bl get_vsr
3611: li r9,-EFAULT
3622: STXVD2X(0,0,r4)
363 li r9,0
3643: beq cr7,4f
365 LXVD2X(0,r1,r8)
3664: PPC_LL r0,STKFRM+PPC_LR_STKOFF(r1)
367 mtlr r0
368 mtmsrd r6
369 isync
370 mr r3,r9
371 addi r1,r1,STKFRM
372 blr
373 extab 2b,3b
374
375#endif /* CONFIG_VSX */
diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 13b7d54f185..e0a9858d537 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -13,6 +13,8 @@
13#include <linux/ptrace.h> 13#include <linux/ptrace.h>
14#include <asm/sstep.h> 14#include <asm/sstep.h>
15#include <asm/processor.h> 15#include <asm/processor.h>
16#include <asm/uaccess.h>
17#include <asm/cputable.h>
16 18
17extern char system_call_common[]; 19extern char system_call_common[];
18 20
@@ -23,6 +25,23 @@ extern char system_call_common[];
23#define MSR_MASK 0x87c0ffff 25#define MSR_MASK 0x87c0ffff
24#endif 26#endif
25 27
28/* Bits in XER */
29#define XER_SO 0x80000000U
30#define XER_OV 0x40000000U
31#define XER_CA 0x20000000U
32
33/*
34 * Functions in ldstfp.S
35 */
36extern int do_lfs(int rn, unsigned long ea);
37extern int do_lfd(int rn, unsigned long ea);
38extern int do_stfs(int rn, unsigned long ea);
39extern int do_stfd(int rn, unsigned long ea);
40extern int do_lvx(int rn, unsigned long ea);
41extern int do_stvx(int rn, unsigned long ea);
42extern int do_lxvd2x(int rn, unsigned long ea);
43extern int do_stxvd2x(int rn, unsigned long ea);
44
26/* 45/*
27 * Determine whether a conditional branch instruction would branch. 46 * Determine whether a conditional branch instruction would branch.
28 */ 47 */
@@ -46,16 +65,499 @@ static int __kprobes branch_taken(unsigned int instr, struct pt_regs *regs)
46 return 1; 65 return 1;
47} 66}
48 67
68
69static long __kprobes address_ok(struct pt_regs *regs, unsigned long ea, int nb)
70{
71 if (!user_mode(regs))
72 return 1;
73 return __access_ok(ea, nb, USER_DS);
74}
75
76/*
77 * Calculate effective address for a D-form instruction
78 */
79static unsigned long __kprobes dform_ea(unsigned int instr, struct pt_regs *regs)
80{
81 int ra;
82 unsigned long ea;
83
84 ra = (instr >> 16) & 0x1f;
85 ea = (signed short) instr; /* sign-extend */
86 if (ra) {
87 ea += regs->gpr[ra];
88 if (instr & 0x04000000) /* update forms */
89 regs->gpr[ra] = ea;
90 }
91#ifdef __powerpc64__
92 if (!(regs->msr & MSR_SF))
93 ea &= 0xffffffffUL;
94#endif
95 return ea;
96}
97
98#ifdef __powerpc64__
99/*
100 * Calculate effective address for a DS-form instruction
101 */
102static unsigned long __kprobes dsform_ea(unsigned int instr, struct pt_regs *regs)
103{
104 int ra;
105 unsigned long ea;
106
107 ra = (instr >> 16) & 0x1f;
108 ea = (signed short) (instr & ~3); /* sign-extend */
109 if (ra) {
110 ea += regs->gpr[ra];
111 if ((instr & 3) == 1) /* update forms */
112 regs->gpr[ra] = ea;
113 }
114 if (!(regs->msr & MSR_SF))
115 ea &= 0xffffffffUL;
116 return ea;
117}
118#endif /* __powerpc64 */
119
120/*
121 * Calculate effective address for an X-form instruction
122 */
123static unsigned long __kprobes xform_ea(unsigned int instr, struct pt_regs *regs,
124 int do_update)
125{
126 int ra, rb;
127 unsigned long ea;
128
129 ra = (instr >> 16) & 0x1f;
130 rb = (instr >> 11) & 0x1f;
131 ea = regs->gpr[rb];
132 if (ra) {
133 ea += regs->gpr[ra];
134 if (do_update) /* update forms */
135 regs->gpr[ra] = ea;
136 }
137#ifdef __powerpc64__
138 if (!(regs->msr & MSR_SF))
139 ea &= 0xffffffffUL;
140#endif
141 return ea;
142}
143
144/*
145 * Return the largest power of 2, not greater than sizeof(unsigned long),
146 * such that x is a multiple of it.
147 */
148static inline unsigned long max_align(unsigned long x)
149{
150 x |= sizeof(unsigned long);
151 return x & -x; /* isolates rightmost bit */
152}
153
154
155static inline unsigned long byterev_2(unsigned long x)
156{
157 return ((x >> 8) & 0xff) | ((x & 0xff) << 8);
158}
159
160static inline unsigned long byterev_4(unsigned long x)
161{
162 return ((x >> 24) & 0xff) | ((x >> 8) & 0xff00) |
163 ((x & 0xff00) << 8) | ((x & 0xff) << 24);
164}
165
166#ifdef __powerpc64__
167static inline unsigned long byterev_8(unsigned long x)
168{
169 return (byterev_4(x) << 32) | byterev_4(x >> 32);
170}
171#endif
172
173static int __kprobes read_mem_aligned(unsigned long *dest, unsigned long ea,
174 int nb)
175{
176 int err = 0;
177 unsigned long x = 0;
178
179 switch (nb) {
180 case 1:
181 err = __get_user(x, (unsigned char __user *) ea);
182 break;
183 case 2:
184 err = __get_user(x, (unsigned short __user *) ea);
185 break;
186 case 4:
187 err = __get_user(x, (unsigned int __user *) ea);
188 break;
189#ifdef __powerpc64__
190 case 8:
191 err = __get_user(x, (unsigned long __user *) ea);
192 break;
193#endif
194 }
195 if (!err)
196 *dest = x;
197 return err;
198}
199
200static int __kprobes read_mem_unaligned(unsigned long *dest, unsigned long ea,
201 int nb, struct pt_regs *regs)
202{
203 int err;
204 unsigned long x, b, c;
205
206 /* unaligned, do this in pieces */
207 x = 0;
208 for (; nb > 0; nb -= c) {
209 c = max_align(ea);
210 if (c > nb)
211 c = max_align(nb);
212 err = read_mem_aligned(&b, ea, c);
213 if (err)
214 return err;
215 x = (x << (8 * c)) + b;
216 ea += c;
217 }
218 *dest = x;
219 return 0;
220}
221
222/*
223 * Read memory at address ea for nb bytes, return 0 for success
224 * or -EFAULT if an error occurred.
225 */
226static int __kprobes read_mem(unsigned long *dest, unsigned long ea, int nb,
227 struct pt_regs *regs)
228{
229 if (!address_ok(regs, ea, nb))
230 return -EFAULT;
231 if ((ea & (nb - 1)) == 0)
232 return read_mem_aligned(dest, ea, nb);
233 return read_mem_unaligned(dest, ea, nb, regs);
234}
235
236static int __kprobes write_mem_aligned(unsigned long val, unsigned long ea,
237 int nb)
238{
239 int err = 0;
240
241 switch (nb) {
242 case 1:
243 err = __put_user(val, (unsigned char __user *) ea);
244 break;
245 case 2:
246 err = __put_user(val, (unsigned short __user *) ea);
247 break;
248 case 4:
249 err = __put_user(val, (unsigned int __user *) ea);
250 break;
251#ifdef __powerpc64__
252 case 8:
253 err = __put_user(val, (unsigned long __user *) ea);
254 break;
255#endif
256 }
257 return err;
258}
259
260static int __kprobes write_mem_unaligned(unsigned long val, unsigned long ea,
261 int nb, struct pt_regs *regs)
262{
263 int err;
264 unsigned long c;
265
266 /* unaligned or little-endian, do this in pieces */
267 for (; nb > 0; nb -= c) {
268 c = max_align(ea);
269 if (c > nb)
270 c = max_align(nb);
271 err = write_mem_aligned(val >> (nb - c) * 8, ea, c);
272 if (err)
273 return err;
274 ++ea;
275 }
276 return 0;
277}
278
279/*
280 * Write memory at address ea for nb bytes, return 0 for success
281 * or -EFAULT if an error occurred.
282 */
283static int __kprobes write_mem(unsigned long val, unsigned long ea, int nb,
284 struct pt_regs *regs)
285{
286 if (!address_ok(regs, ea, nb))
287 return -EFAULT;
288 if ((ea & (nb - 1)) == 0)
289 return write_mem_aligned(val, ea, nb);
290 return write_mem_unaligned(val, ea, nb, regs);
291}
292
49/* 293/*
50 * Emulate instructions that cause a transfer of control. 294 * Check the address and alignment, and call func to do the actual
295 * load or store.
296 */
297static int __kprobes do_fp_load(int rn, int (*func)(int, unsigned long),
298 unsigned long ea, int nb,
299 struct pt_regs *regs)
300{
301 int err;
302 unsigned long val[sizeof(double) / sizeof(long)];
303 unsigned long ptr;
304
305 if (!address_ok(regs, ea, nb))
306 return -EFAULT;
307 if ((ea & 3) == 0)
308 return (*func)(rn, ea);
309 ptr = (unsigned long) &val[0];
310 if (sizeof(unsigned long) == 8 || nb == 4) {
311 err = read_mem_unaligned(&val[0], ea, nb, regs);
312 ptr += sizeof(unsigned long) - nb;
313 } else {
314 /* reading a double on 32-bit */
315 err = read_mem_unaligned(&val[0], ea, 4, regs);
316 if (!err)
317 err = read_mem_unaligned(&val[1], ea + 4, 4, regs);
318 }
319 if (err)
320 return err;
321 return (*func)(rn, ptr);
322}
323
324static int __kprobes do_fp_store(int rn, int (*func)(int, unsigned long),
325 unsigned long ea, int nb,
326 struct pt_regs *regs)
327{
328 int err;
329 unsigned long val[sizeof(double) / sizeof(long)];
330 unsigned long ptr;
331
332 if (!address_ok(regs, ea, nb))
333 return -EFAULT;
334 if ((ea & 3) == 0)
335 return (*func)(rn, ea);
336 ptr = (unsigned long) &val[0];
337 if (sizeof(unsigned long) == 8 || nb == 4) {
338 ptr += sizeof(unsigned long) - nb;
339 err = (*func)(rn, ptr);
340 if (err)
341 return err;
342 err = write_mem_unaligned(val[0], ea, nb, regs);
343 } else {
344 /* writing a double on 32-bit */
345 err = (*func)(rn, ptr);
346 if (err)
347 return err;
348 err = write_mem_unaligned(val[0], ea, 4, regs);
349 if (!err)
350 err = write_mem_unaligned(val[1], ea + 4, 4, regs);
351 }
352 return err;
353}
354
355#ifdef CONFIG_ALTIVEC
356/* For Altivec/VMX, no need to worry about alignment */
357static int __kprobes do_vec_load(int rn, int (*func)(int, unsigned long),
358 unsigned long ea, struct pt_regs *regs)
359{
360 if (!address_ok(regs, ea & ~0xfUL, 16))
361 return -EFAULT;
362 return (*func)(rn, ea);
363}
364
365static int __kprobes do_vec_store(int rn, int (*func)(int, unsigned long),
366 unsigned long ea, struct pt_regs *regs)
367{
368 if (!address_ok(regs, ea & ~0xfUL, 16))
369 return -EFAULT;
370 return (*func)(rn, ea);
371}
372#endif /* CONFIG_ALTIVEC */
373
374#ifdef CONFIG_VSX
375static int __kprobes do_vsx_load(int rn, int (*func)(int, unsigned long),
376 unsigned long ea, struct pt_regs *regs)
377{
378 int err;
379 unsigned long val[2];
380
381 if (!address_ok(regs, ea, 16))
382 return -EFAULT;
383 if ((ea & 3) == 0)
384 return (*func)(rn, ea);
385 err = read_mem_unaligned(&val[0], ea, 8, regs);
386 if (!err)
387 err = read_mem_unaligned(&val[1], ea + 8, 8, regs);
388 if (!err)
389 err = (*func)(rn, (unsigned long) &val[0]);
390 return err;
391}
392
393static int __kprobes do_vsx_store(int rn, int (*func)(int, unsigned long),
394 unsigned long ea, struct pt_regs *regs)
395{
396 int err;
397 unsigned long val[2];
398
399 if (!address_ok(regs, ea, 16))
400 return -EFAULT;
401 if ((ea & 3) == 0)
402 return (*func)(rn, ea);
403 err = (*func)(rn, (unsigned long) &val[0]);
404 if (err)
405 return err;
406 err = write_mem_unaligned(val[0], ea, 8, regs);
407 if (!err)
408 err = write_mem_unaligned(val[1], ea + 8, 8, regs);
409 return err;
410}
411#endif /* CONFIG_VSX */
412
413#define __put_user_asmx(x, addr, err, op, cr) \
414 __asm__ __volatile__( \
415 "1: " op " %2,0,%3\n" \
416 " mfcr %1\n" \
417 "2:\n" \
418 ".section .fixup,\"ax\"\n" \
419 "3: li %0,%4\n" \
420 " b 2b\n" \
421 ".previous\n" \
422 ".section __ex_table,\"a\"\n" \
423 PPC_LONG_ALIGN "\n" \
424 PPC_LONG "1b,3b\n" \
425 ".previous" \
426 : "=r" (err), "=r" (cr) \
427 : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err))
428
429#define __get_user_asmx(x, addr, err, op) \
430 __asm__ __volatile__( \
431 "1: "op" %1,0,%2\n" \
432 "2:\n" \
433 ".section .fixup,\"ax\"\n" \
434 "3: li %0,%3\n" \
435 " b 2b\n" \
436 ".previous\n" \
437 ".section __ex_table,\"a\"\n" \
438 PPC_LONG_ALIGN "\n" \
439 PPC_LONG "1b,3b\n" \
440 ".previous" \
441 : "=r" (err), "=r" (x) \
442 : "r" (addr), "i" (-EFAULT), "0" (err))
443
444#define __cacheop_user_asmx(addr, err, op) \
445 __asm__ __volatile__( \
446 "1: "op" 0,%1\n" \
447 "2:\n" \
448 ".section .fixup,\"ax\"\n" \
449 "3: li %0,%3\n" \
450 " b 2b\n" \
451 ".previous\n" \
452 ".section __ex_table,\"a\"\n" \
453 PPC_LONG_ALIGN "\n" \
454 PPC_LONG "1b,3b\n" \
455 ".previous" \
456 : "=r" (err) \
457 : "r" (addr), "i" (-EFAULT), "0" (err))
458
459static void __kprobes set_cr0(struct pt_regs *regs, int rd)
460{
461 long val = regs->gpr[rd];
462
463 regs->ccr = (regs->ccr & 0x0fffffff) | ((regs->xer >> 3) & 0x10000000);
464#ifdef __powerpc64__
465 if (!(regs->msr & MSR_SF))
466 val = (int) val;
467#endif
468 if (val < 0)
469 regs->ccr |= 0x80000000;
470 else if (val > 0)
471 regs->ccr |= 0x40000000;
472 else
473 regs->ccr |= 0x20000000;
474}
475
476static void __kprobes add_with_carry(struct pt_regs *regs, int rd,
477 unsigned long val1, unsigned long val2,
478 unsigned long carry_in)
479{
480 unsigned long val = val1 + val2;
481
482 if (carry_in)
483 ++val;
484 regs->gpr[rd] = val;
485#ifdef __powerpc64__
486 if (!(regs->msr & MSR_SF)) {
487 val = (unsigned int) val;
488 val1 = (unsigned int) val1;
489 }
490#endif
491 if (val < val1 || (carry_in && val == val1))
492 regs->xer |= XER_CA;
493 else
494 regs->xer &= ~XER_CA;
495}
496
497static void __kprobes do_cmp_signed(struct pt_regs *regs, long v1, long v2,
498 int crfld)
499{
500 unsigned int crval, shift;
501
502 crval = (regs->xer >> 31) & 1; /* get SO bit */
503 if (v1 < v2)
504 crval |= 8;
505 else if (v1 > v2)
506 crval |= 4;
507 else
508 crval |= 2;
509 shift = (7 - crfld) * 4;
510 regs->ccr = (regs->ccr & ~(0xf << shift)) | (crval << shift);
511}
512
513static void __kprobes do_cmp_unsigned(struct pt_regs *regs, unsigned long v1,
514 unsigned long v2, int crfld)
515{
516 unsigned int crval, shift;
517
518 crval = (regs->xer >> 31) & 1; /* get SO bit */
519 if (v1 < v2)
520 crval |= 8;
521 else if (v1 > v2)
522 crval |= 4;
523 else
524 crval |= 2;
525 shift = (7 - crfld) * 4;
526 regs->ccr = (regs->ccr & ~(0xf << shift)) | (crval << shift);
527}
528
529/*
530 * Elements of 32-bit rotate and mask instructions.
531 */
532#define MASK32(mb, me) ((0xffffffffUL >> (mb)) + \
533 ((signed long)-0x80000000L >> (me)) + ((me) >= (mb)))
534#ifdef __powerpc64__
535#define MASK64_L(mb) (~0UL >> (mb))
536#define MASK64_R(me) ((signed long)-0x8000000000000000L >> (me))
537#define MASK64(mb, me) (MASK64_L(mb) + MASK64_R(me) + ((me) >= (mb)))
538#define DATA32(x) (((x) & 0xffffffffUL) | (((x) & 0xffffffffUL) << 32))
539#else
540#define DATA32(x) (x)
541#endif
542#define ROTATE(x, n) ((n) ? (((x) << (n)) | ((x) >> (8 * sizeof(long) - (n)))) : (x))
543
544/*
545 * Emulate instructions that cause a transfer of control,
546 * loads and stores, and a few other instructions.
51 * Returns 1 if the step was emulated, 0 if not, 547 * Returns 1 if the step was emulated, 0 if not,
52 * or -1 if the instruction is one that should not be stepped, 548 * or -1 if the instruction is one that should not be stepped,
53 * such as an rfid, or a mtmsrd that would clear MSR_RI. 549 * such as an rfid, or a mtmsrd that would clear MSR_RI.
54 */ 550 */
55int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr) 551int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
56{ 552{
57 unsigned int opcode, rs, rb, rd, spr; 553 unsigned int opcode, ra, rb, rd, spr, u;
58 unsigned long int imm; 554 unsigned long int imm;
555 unsigned long int val, val2;
556 unsigned long int ea;
557 unsigned int cr, mb, me, sh;
558 int err;
559 unsigned long old_ra;
560 long ival;
59 561
60 opcode = instr >> 26; 562 opcode = instr >> 26;
61 switch (opcode) { 563 switch (opcode) {
@@ -78,7 +580,13 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
78 * entry code works. If that is changed, this will 580 * entry code works. If that is changed, this will
79 * need to be changed also. 581 * need to be changed also.
80 */ 582 */
583 if (regs->gpr[0] == 0x1ebe &&
584 cpu_has_feature(CPU_FTR_REAL_LE)) {
585 regs->msr ^= MSR_LE;
586 goto instr_done;
587 }
81 regs->gpr[9] = regs->gpr[13]; 588 regs->gpr[9] = regs->gpr[13];
589 regs->gpr[10] = MSR_KERNEL;
82 regs->gpr[11] = regs->nip + 4; 590 regs->gpr[11] = regs->nip + 4;
83 regs->gpr[12] = regs->msr & MSR_MASK; 591 regs->gpr[12] = regs->msr & MSR_MASK;
84 regs->gpr[13] = (unsigned long) get_paca(); 592 regs->gpr[13] = (unsigned long) get_paca();
@@ -102,9 +610,9 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
102 regs->nip = imm; 610 regs->nip = imm;
103 return 1; 611 return 1;
104 case 19: 612 case 19:
105 switch (instr & 0x7fe) { 613 switch ((instr >> 1) & 0x3ff) {
106 case 0x20: /* bclr */ 614 case 16: /* bclr */
107 case 0x420: /* bcctr */ 615 case 528: /* bcctr */
108 imm = (instr & 0x400)? regs->ctr: regs->link; 616 imm = (instr & 0x400)? regs->ctr: regs->link;
109 regs->nip += 4; 617 regs->nip += 4;
110 if ((regs->msr & MSR_SF) == 0) { 618 if ((regs->msr & MSR_SF) == 0) {
@@ -116,30 +624,233 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
116 if (branch_taken(instr, regs)) 624 if (branch_taken(instr, regs))
117 regs->nip = imm; 625 regs->nip = imm;
118 return 1; 626 return 1;
119 case 0x24: /* rfid, scary */ 627
628 case 18: /* rfid, scary */
120 return -1; 629 return -1;
630
631 case 150: /* isync */
632 isync();
633 goto instr_done;
634
635 case 33: /* crnor */
636 case 129: /* crandc */
637 case 193: /* crxor */
638 case 225: /* crnand */
639 case 257: /* crand */
640 case 289: /* creqv */
641 case 417: /* crorc */
642 case 449: /* cror */
643 ra = (instr >> 16) & 0x1f;
644 rb = (instr >> 11) & 0x1f;
645 rd = (instr >> 21) & 0x1f;
646 ra = (regs->ccr >> (31 - ra)) & 1;
647 rb = (regs->ccr >> (31 - rb)) & 1;
648 val = (instr >> (6 + ra * 2 + rb)) & 1;
649 regs->ccr = (regs->ccr & ~(1UL << (31 - rd))) |
650 (val << (31 - rd));
651 goto instr_done;
652 }
653 break;
654 case 31:
655 switch ((instr >> 1) & 0x3ff) {
656 case 598: /* sync */
657#ifdef __powerpc64__
658 switch ((instr >> 21) & 3) {
659 case 1: /* lwsync */
660 asm volatile("lwsync" : : : "memory");
661 goto instr_done;
662 case 2: /* ptesync */
663 asm volatile("ptesync" : : : "memory");
664 goto instr_done;
665 }
666#endif
667 mb();
668 goto instr_done;
669
670 case 854: /* eieio */
671 eieio();
672 goto instr_done;
673 }
674 break;
675 }
676
677 /* Following cases refer to regs->gpr[], so we need all regs */
678 if (!FULL_REGS(regs))
679 return 0;
680
681 rd = (instr >> 21) & 0x1f;
682 ra = (instr >> 16) & 0x1f;
683 rb = (instr >> 11) & 0x1f;
684
685 switch (opcode) {
686 case 7: /* mulli */
687 regs->gpr[rd] = regs->gpr[ra] * (short) instr;
688 goto instr_done;
689
690 case 8: /* subfic */
691 imm = (short) instr;
692 add_with_carry(regs, rd, ~regs->gpr[ra], imm, 1);
693 goto instr_done;
694
695 case 10: /* cmpli */
696 imm = (unsigned short) instr;
697 val = regs->gpr[ra];
698#ifdef __powerpc64__
699 if ((rd & 1) == 0)
700 val = (unsigned int) val;
701#endif
702 do_cmp_unsigned(regs, val, imm, rd >> 2);
703 goto instr_done;
704
705 case 11: /* cmpi */
706 imm = (short) instr;
707 val = regs->gpr[ra];
708#ifdef __powerpc64__
709 if ((rd & 1) == 0)
710 val = (int) val;
711#endif
712 do_cmp_signed(regs, val, imm, rd >> 2);
713 goto instr_done;
714
715 case 12: /* addic */
716 imm = (short) instr;
717 add_with_carry(regs, rd, regs->gpr[ra], imm, 0);
718 goto instr_done;
719
720 case 13: /* addic. */
721 imm = (short) instr;
722 add_with_carry(regs, rd, regs->gpr[ra], imm, 0);
723 set_cr0(regs, rd);
724 goto instr_done;
725
726 case 14: /* addi */
727 imm = (short) instr;
728 if (ra)
729 imm += regs->gpr[ra];
730 regs->gpr[rd] = imm;
731 goto instr_done;
732
733 case 15: /* addis */
734 imm = ((short) instr) << 16;
735 if (ra)
736 imm += regs->gpr[ra];
737 regs->gpr[rd] = imm;
738 goto instr_done;
739
740 case 20: /* rlwimi */
741 mb = (instr >> 6) & 0x1f;
742 me = (instr >> 1) & 0x1f;
743 val = DATA32(regs->gpr[rd]);
744 imm = MASK32(mb, me);
745 regs->gpr[ra] = (regs->gpr[ra] & ~imm) | (ROTATE(val, rb) & imm);
746 goto logical_done;
747
748 case 21: /* rlwinm */
749 mb = (instr >> 6) & 0x1f;
750 me = (instr >> 1) & 0x1f;
751 val = DATA32(regs->gpr[rd]);
752 regs->gpr[ra] = ROTATE(val, rb) & MASK32(mb, me);
753 goto logical_done;
754
755 case 23: /* rlwnm */
756 mb = (instr >> 6) & 0x1f;
757 me = (instr >> 1) & 0x1f;
758 rb = regs->gpr[rb] & 0x1f;
759 val = DATA32(regs->gpr[rd]);
760 regs->gpr[ra] = ROTATE(val, rb) & MASK32(mb, me);
761 goto logical_done;
762
763 case 24: /* ori */
764 imm = (unsigned short) instr;
765 regs->gpr[ra] = regs->gpr[rd] | imm;
766 goto instr_done;
767
768 case 25: /* oris */
769 imm = (unsigned short) instr;
770 regs->gpr[ra] = regs->gpr[rd] | (imm << 16);
771 goto instr_done;
772
773 case 26: /* xori */
774 imm = (unsigned short) instr;
775 regs->gpr[ra] = regs->gpr[rd] ^ imm;
776 goto instr_done;
777
778 case 27: /* xoris */
779 imm = (unsigned short) instr;
780 regs->gpr[ra] = regs->gpr[rd] ^ (imm << 16);
781 goto instr_done;
782
783 case 28: /* andi. */
784 imm = (unsigned short) instr;
785 regs->gpr[ra] = regs->gpr[rd] & imm;
786 set_cr0(regs, ra);
787 goto instr_done;
788
789 case 29: /* andis. */
790 imm = (unsigned short) instr;
791 regs->gpr[ra] = regs->gpr[rd] & (imm << 16);
792 set_cr0(regs, ra);
793 goto instr_done;
794
795#ifdef __powerpc64__
796 case 30: /* rld* */
797 mb = ((instr >> 6) & 0x1f) | (instr & 0x20);
798 val = regs->gpr[rd];
799 if ((instr & 0x10) == 0) {
800 sh = rb | ((instr & 2) << 4);
801 val = ROTATE(val, sh);
802 switch ((instr >> 2) & 3) {
803 case 0: /* rldicl */
804 regs->gpr[ra] = val & MASK64_L(mb);
805 goto logical_done;
806 case 1: /* rldicr */
807 regs->gpr[ra] = val & MASK64_R(mb);
808 goto logical_done;
809 case 2: /* rldic */
810 regs->gpr[ra] = val & MASK64(mb, 63 - sh);
811 goto logical_done;
812 case 3: /* rldimi */
813 imm = MASK64(mb, 63 - sh);
814 regs->gpr[ra] = (regs->gpr[ra] & ~imm) |
815 (val & imm);
816 goto logical_done;
817 }
818 } else {
819 sh = regs->gpr[rb] & 0x3f;
820 val = ROTATE(val, sh);
821 switch ((instr >> 1) & 7) {
822 case 0: /* rldcl */
823 regs->gpr[ra] = val & MASK64_L(mb);
824 goto logical_done;
825 case 1: /* rldcr */
826 regs->gpr[ra] = val & MASK64_R(mb);
827 goto logical_done;
828 }
121 } 829 }
830#endif
831
122 case 31: 832 case 31:
123 rd = (instr >> 21) & 0x1f; 833 switch ((instr >> 1) & 0x3ff) {
124 switch (instr & 0x7fe) { 834 case 83: /* mfmsr */
125 case 0xa6: /* mfmsr */ 835 if (regs->msr & MSR_PR)
836 break;
126 regs->gpr[rd] = regs->msr & MSR_MASK; 837 regs->gpr[rd] = regs->msr & MSR_MASK;
127 regs->nip += 4; 838 goto instr_done;
128 if ((regs->msr & MSR_SF) == 0) 839 case 146: /* mtmsr */
129 regs->nip &= 0xffffffffUL; 840 if (regs->msr & MSR_PR)
130 return 1; 841 break;
131 case 0x124: /* mtmsr */
132 imm = regs->gpr[rd]; 842 imm = regs->gpr[rd];
133 if ((imm & MSR_RI) == 0) 843 if ((imm & MSR_RI) == 0)
134 /* can't step mtmsr that would clear MSR_RI */ 844 /* can't step mtmsr that would clear MSR_RI */
135 return -1; 845 return -1;
136 regs->msr = imm; 846 regs->msr = imm;
137 regs->nip += 4; 847 goto instr_done;
138 return 1;
139#ifdef CONFIG_PPC64 848#ifdef CONFIG_PPC64
140 case 0x164: /* mtmsrd */ 849 case 178: /* mtmsrd */
141 /* only MSR_EE and MSR_RI get changed if bit 15 set */ 850 /* only MSR_EE and MSR_RI get changed if bit 15 set */
142 /* mtmsrd doesn't change MSR_HV and MSR_ME */ 851 /* mtmsrd doesn't change MSR_HV and MSR_ME */
852 if (regs->msr & MSR_PR)
853 break;
143 imm = (instr & 0x10000)? 0x8002: 0xefffffffffffefffUL; 854 imm = (instr & 0x10000)? 0x8002: 0xefffffffffffefffUL;
144 imm = (regs->msr & MSR_MASK & ~imm) 855 imm = (regs->msr & MSR_MASK & ~imm)
145 | (regs->gpr[rd] & imm); 856 | (regs->gpr[rd] & imm);
@@ -147,57 +858,770 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
147 /* can't step mtmsrd that would clear MSR_RI */ 858 /* can't step mtmsrd that would clear MSR_RI */
148 return -1; 859 return -1;
149 regs->msr = imm; 860 regs->msr = imm;
150 regs->nip += 4; 861 goto instr_done;
151 if ((imm & MSR_SF) == 0)
152 regs->nip &= 0xffffffffUL;
153 return 1;
154#endif 862#endif
155 case 0x26: /* mfcr */ 863 case 19: /* mfcr */
156 regs->gpr[rd] = regs->ccr; 864 regs->gpr[rd] = regs->ccr;
157 regs->gpr[rd] &= 0xffffffffUL; 865 regs->gpr[rd] &= 0xffffffffUL;
158 goto mtspr_out; 866 goto instr_done;
159 case 0x2a6: /* mfspr */ 867
868 case 144: /* mtcrf */
869 imm = 0xf0000000UL;
870 val = regs->gpr[rd];
871 for (sh = 0; sh < 8; ++sh) {
872 if (instr & (0x80000 >> sh))
873 regs->ccr = (regs->ccr & ~imm) |
874 (val & imm);
875 imm >>= 4;
876 }
877 goto instr_done;
878
879 case 339: /* mfspr */
160 spr = (instr >> 11) & 0x3ff; 880 spr = (instr >> 11) & 0x3ff;
161 switch (spr) { 881 switch (spr) {
162 case 0x20: /* mfxer */ 882 case 0x20: /* mfxer */
163 regs->gpr[rd] = regs->xer; 883 regs->gpr[rd] = regs->xer;
164 regs->gpr[rd] &= 0xffffffffUL; 884 regs->gpr[rd] &= 0xffffffffUL;
165 goto mtspr_out; 885 goto instr_done;
166 case 0x100: /* mflr */ 886 case 0x100: /* mflr */
167 regs->gpr[rd] = regs->link; 887 regs->gpr[rd] = regs->link;
168 goto mtspr_out; 888 goto instr_done;
169 case 0x120: /* mfctr */ 889 case 0x120: /* mfctr */
170 regs->gpr[rd] = regs->ctr; 890 regs->gpr[rd] = regs->ctr;
171 goto mtspr_out; 891 goto instr_done;
172 }
173 break;
174 case 0x378: /* orx */
175 if (instr & 1)
176 break;
177 rs = (instr >> 21) & 0x1f;
178 rb = (instr >> 11) & 0x1f;
179 if (rs == rb) { /* mr */
180 rd = (instr >> 16) & 0x1f;
181 regs->gpr[rd] = regs->gpr[rs];
182 goto mtspr_out;
183 } 892 }
184 break; 893 break;
185 case 0x3a6: /* mtspr */ 894
895 case 467: /* mtspr */
186 spr = (instr >> 11) & 0x3ff; 896 spr = (instr >> 11) & 0x3ff;
187 switch (spr) { 897 switch (spr) {
188 case 0x20: /* mtxer */ 898 case 0x20: /* mtxer */
189 regs->xer = (regs->gpr[rd] & 0xffffffffUL); 899 regs->xer = (regs->gpr[rd] & 0xffffffffUL);
190 goto mtspr_out; 900 goto instr_done;
191 case 0x100: /* mtlr */ 901 case 0x100: /* mtlr */
192 regs->link = regs->gpr[rd]; 902 regs->link = regs->gpr[rd];
193 goto mtspr_out; 903 goto instr_done;
194 case 0x120: /* mtctr */ 904 case 0x120: /* mtctr */
195 regs->ctr = regs->gpr[rd]; 905 regs->ctr = regs->gpr[rd];
196mtspr_out: 906 goto instr_done;
197 regs->nip += 4;
198 return 1;
199 } 907 }
908 break;
909
910/*
911 * Compare instructions
912 */
913 case 0: /* cmp */
914 val = regs->gpr[ra];
915 val2 = regs->gpr[rb];
916#ifdef __powerpc64__
917 if ((rd & 1) == 0) {
918 /* word (32-bit) compare */
919 val = (int) val;
920 val2 = (int) val2;
921 }
922#endif
923 do_cmp_signed(regs, val, val2, rd >> 2);
924 goto instr_done;
925
926 case 32: /* cmpl */
927 val = regs->gpr[ra];
928 val2 = regs->gpr[rb];
929#ifdef __powerpc64__
930 if ((rd & 1) == 0) {
931 /* word (32-bit) compare */
932 val = (unsigned int) val;
933 val2 = (unsigned int) val2;
934 }
935#endif
936 do_cmp_unsigned(regs, val, val2, rd >> 2);
937 goto instr_done;
938
939/*
940 * Arithmetic instructions
941 */
942 case 8: /* subfc */
943 add_with_carry(regs, rd, ~regs->gpr[ra],
944 regs->gpr[rb], 1);
945 goto arith_done;
946#ifdef __powerpc64__
947 case 9: /* mulhdu */
948 asm("mulhdu %0,%1,%2" : "=r" (regs->gpr[rd]) :
949 "r" (regs->gpr[ra]), "r" (regs->gpr[rb]));
950 goto arith_done;
951#endif
952 case 10: /* addc */
953 add_with_carry(regs, rd, regs->gpr[ra],
954 regs->gpr[rb], 0);
955 goto arith_done;
956
957 case 11: /* mulhwu */
958 asm("mulhwu %0,%1,%2" : "=r" (regs->gpr[rd]) :
959 "r" (regs->gpr[ra]), "r" (regs->gpr[rb]));
960 goto arith_done;
961
962 case 40: /* subf */
963 regs->gpr[rd] = regs->gpr[rb] - regs->gpr[ra];
964 goto arith_done;
965#ifdef __powerpc64__
966 case 73: /* mulhd */
967 asm("mulhd %0,%1,%2" : "=r" (regs->gpr[rd]) :
968 "r" (regs->gpr[ra]), "r" (regs->gpr[rb]));
969 goto arith_done;
970#endif
971 case 75: /* mulhw */
972 asm("mulhw %0,%1,%2" : "=r" (regs->gpr[rd]) :
973 "r" (regs->gpr[ra]), "r" (regs->gpr[rb]));
974 goto arith_done;
975
976 case 104: /* neg */
977 regs->gpr[rd] = -regs->gpr[ra];
978 goto arith_done;
979
980 case 136: /* subfe */
981 add_with_carry(regs, rd, ~regs->gpr[ra], regs->gpr[rb],
982 regs->xer & XER_CA);
983 goto arith_done;
984
985 case 138: /* adde */
986 add_with_carry(regs, rd, regs->gpr[ra], regs->gpr[rb],
987 regs->xer & XER_CA);
988 goto arith_done;
989
990 case 200: /* subfze */
991 add_with_carry(regs, rd, ~regs->gpr[ra], 0L,
992 regs->xer & XER_CA);
993 goto arith_done;
994
995 case 202: /* addze */
996 add_with_carry(regs, rd, regs->gpr[ra], 0L,
997 regs->xer & XER_CA);
998 goto arith_done;
999
1000 case 232: /* subfme */
1001 add_with_carry(regs, rd, ~regs->gpr[ra], -1L,
1002 regs->xer & XER_CA);
1003 goto arith_done;
1004#ifdef __powerpc64__
1005 case 233: /* mulld */
1006 regs->gpr[rd] = regs->gpr[ra] * regs->gpr[rb];
1007 goto arith_done;
1008#endif
1009 case 234: /* addme */
1010 add_with_carry(regs, rd, regs->gpr[ra], -1L,
1011 regs->xer & XER_CA);
1012 goto arith_done;
1013
1014 case 235: /* mullw */
1015 regs->gpr[rd] = (unsigned int) regs->gpr[ra] *
1016 (unsigned int) regs->gpr[rb];
1017 goto arith_done;
1018
1019 case 266: /* add */
1020 regs->gpr[rd] = regs->gpr[ra] + regs->gpr[rb];
1021 goto arith_done;
1022#ifdef __powerpc64__
1023 case 457: /* divdu */
1024 regs->gpr[rd] = regs->gpr[ra] / regs->gpr[rb];
1025 goto arith_done;
1026#endif
1027 case 459: /* divwu */
1028 regs->gpr[rd] = (unsigned int) regs->gpr[ra] /
1029 (unsigned int) regs->gpr[rb];
1030 goto arith_done;
1031#ifdef __powerpc64__
1032 case 489: /* divd */
1033 regs->gpr[rd] = (long int) regs->gpr[ra] /
1034 (long int) regs->gpr[rb];
1035 goto arith_done;
1036#endif
1037 case 491: /* divw */
1038 regs->gpr[rd] = (int) regs->gpr[ra] /
1039 (int) regs->gpr[rb];
1040 goto arith_done;
1041
1042
1043/*
1044 * Logical instructions
1045 */
1046 case 26: /* cntlzw */
1047 asm("cntlzw %0,%1" : "=r" (regs->gpr[ra]) :
1048 "r" (regs->gpr[rd]));
1049 goto logical_done;
1050#ifdef __powerpc64__
1051 case 58: /* cntlzd */
1052 asm("cntlzd %0,%1" : "=r" (regs->gpr[ra]) :
1053 "r" (regs->gpr[rd]));
1054 goto logical_done;
1055#endif
1056 case 28: /* and */
1057 regs->gpr[ra] = regs->gpr[rd] & regs->gpr[rb];
1058 goto logical_done;
1059
1060 case 60: /* andc */
1061 regs->gpr[ra] = regs->gpr[rd] & ~regs->gpr[rb];
1062 goto logical_done;
1063
1064 case 124: /* nor */
1065 regs->gpr[ra] = ~(regs->gpr[rd] | regs->gpr[rb]);
1066 goto logical_done;
1067
1068 case 284: /* xor */
1069 regs->gpr[ra] = ~(regs->gpr[rd] ^ regs->gpr[rb]);
1070 goto logical_done;
1071
1072 case 316: /* xor */
1073 regs->gpr[ra] = regs->gpr[rd] ^ regs->gpr[rb];
1074 goto logical_done;
1075
1076 case 412: /* orc */
1077 regs->gpr[ra] = regs->gpr[rd] | ~regs->gpr[rb];
1078 goto logical_done;
1079
1080 case 444: /* or */
1081 regs->gpr[ra] = regs->gpr[rd] | regs->gpr[rb];
1082 goto logical_done;
1083
1084 case 476: /* nand */
1085 regs->gpr[ra] = ~(regs->gpr[rd] & regs->gpr[rb]);
1086 goto logical_done;
1087
1088 case 922: /* extsh */
1089 regs->gpr[ra] = (signed short) regs->gpr[rd];
1090 goto logical_done;
1091
1092 case 954: /* extsb */
1093 regs->gpr[ra] = (signed char) regs->gpr[rd];
1094 goto logical_done;
1095#ifdef __powerpc64__
1096 case 986: /* extsw */
1097 regs->gpr[ra] = (signed int) regs->gpr[rd];
1098 goto logical_done;
1099#endif
1100
1101/*
1102 * Shift instructions
1103 */
1104 case 24: /* slw */
1105 sh = regs->gpr[rb] & 0x3f;
1106 if (sh < 32)
1107 regs->gpr[ra] = (regs->gpr[rd] << sh) & 0xffffffffUL;
1108 else
1109 regs->gpr[ra] = 0;
1110 goto logical_done;
1111
1112 case 536: /* srw */
1113 sh = regs->gpr[rb] & 0x3f;
1114 if (sh < 32)
1115 regs->gpr[ra] = (regs->gpr[rd] & 0xffffffffUL) >> sh;
1116 else
1117 regs->gpr[ra] = 0;
1118 goto logical_done;
1119
1120 case 792: /* sraw */
1121 sh = regs->gpr[rb] & 0x3f;
1122 ival = (signed int) regs->gpr[rd];
1123 regs->gpr[ra] = ival >> (sh < 32 ? sh : 31);
1124 if (ival < 0 && (sh >= 32 || (ival & ((1 << sh) - 1)) != 0))
1125 regs->xer |= XER_CA;
1126 else
1127 regs->xer &= ~XER_CA;
1128 goto logical_done;
1129
1130 case 824: /* srawi */
1131 sh = rb;
1132 ival = (signed int) regs->gpr[rd];
1133 regs->gpr[ra] = ival >> sh;
1134 if (ival < 0 && (ival & ((1 << sh) - 1)) != 0)
1135 regs->xer |= XER_CA;
1136 else
1137 regs->xer &= ~XER_CA;
1138 goto logical_done;
1139
1140#ifdef __powerpc64__
1141 case 27: /* sld */
1142 sh = regs->gpr[rd] & 0x7f;
1143 if (sh < 64)
1144 regs->gpr[ra] = regs->gpr[rd] << sh;
1145 else
1146 regs->gpr[ra] = 0;
1147 goto logical_done;
1148
1149 case 539: /* srd */
1150 sh = regs->gpr[rb] & 0x7f;
1151 if (sh < 64)
1152 regs->gpr[ra] = regs->gpr[rd] >> sh;
1153 else
1154 regs->gpr[ra] = 0;
1155 goto logical_done;
1156
1157 case 794: /* srad */
1158 sh = regs->gpr[rb] & 0x7f;
1159 ival = (signed long int) regs->gpr[rd];
1160 regs->gpr[ra] = ival >> (sh < 64 ? sh : 63);
1161 if (ival < 0 && (sh >= 64 || (ival & ((1 << sh) - 1)) != 0))
1162 regs->xer |= XER_CA;
1163 else
1164 regs->xer &= ~XER_CA;
1165 goto logical_done;
1166
1167 case 826: /* sradi with sh_5 = 0 */
1168 case 827: /* sradi with sh_5 = 1 */
1169 sh = rb | ((instr & 2) << 4);
1170 ival = (signed long int) regs->gpr[rd];
1171 regs->gpr[ra] = ival >> sh;
1172 if (ival < 0 && (ival & ((1 << sh) - 1)) != 0)
1173 regs->xer |= XER_CA;
1174 else
1175 regs->xer &= ~XER_CA;
1176 goto logical_done;
1177#endif /* __powerpc64__ */
1178
1179/*
1180 * Cache instructions
1181 */
1182 case 54: /* dcbst */
1183 ea = xform_ea(instr, regs, 0);
1184 if (!address_ok(regs, ea, 8))
1185 return 0;
1186 err = 0;
1187 __cacheop_user_asmx(ea, err, "dcbst");
1188 if (err)
1189 return 0;
1190 goto instr_done;
1191
1192 case 86: /* dcbf */
1193 ea = xform_ea(instr, regs, 0);
1194 if (!address_ok(regs, ea, 8))
1195 return 0;
1196 err = 0;
1197 __cacheop_user_asmx(ea, err, "dcbf");
1198 if (err)
1199 return 0;
1200 goto instr_done;
1201
1202 case 246: /* dcbtst */
1203 if (rd == 0) {
1204 ea = xform_ea(instr, regs, 0);
1205 prefetchw((void *) ea);
1206 }
1207 goto instr_done;
1208
1209 case 278: /* dcbt */
1210 if (rd == 0) {
1211 ea = xform_ea(instr, regs, 0);
1212 prefetch((void *) ea);
1213 }
1214 goto instr_done;
1215
200 } 1216 }
1217 break;
201 } 1218 }
202 return 0; 1219
1220 /*
1221 * Following cases are for loads and stores, so bail out
1222 * if we're in little-endian mode.
1223 */
1224 if (regs->msr & MSR_LE)
1225 return 0;
1226
1227 /*
1228 * Save register RA in case it's an update form load or store
1229 * and the access faults.
1230 */
1231 old_ra = regs->gpr[ra];
1232
1233 switch (opcode) {
1234 case 31:
1235 u = instr & 0x40;
1236 switch ((instr >> 1) & 0x3ff) {
1237 case 20: /* lwarx */
1238 ea = xform_ea(instr, regs, 0);
1239 if (ea & 3)
1240 break; /* can't handle misaligned */
1241 err = -EFAULT;
1242 if (!address_ok(regs, ea, 4))
1243 goto ldst_done;
1244 err = 0;
1245 __get_user_asmx(val, ea, err, "lwarx");
1246 if (!err)
1247 regs->gpr[rd] = val;
1248 goto ldst_done;
1249
1250 case 150: /* stwcx. */
1251 ea = xform_ea(instr, regs, 0);
1252 if (ea & 3)
1253 break; /* can't handle misaligned */
1254 err = -EFAULT;
1255 if (!address_ok(regs, ea, 4))
1256 goto ldst_done;
1257 err = 0;
1258 __put_user_asmx(regs->gpr[rd], ea, err, "stwcx.", cr);
1259 if (!err)
1260 regs->ccr = (regs->ccr & 0x0fffffff) |
1261 (cr & 0xe0000000) |
1262 ((regs->xer >> 3) & 0x10000000);
1263 goto ldst_done;
1264
1265#ifdef __powerpc64__
1266 case 84: /* ldarx */
1267 ea = xform_ea(instr, regs, 0);
1268 if (ea & 7)
1269 break; /* can't handle misaligned */
1270 err = -EFAULT;
1271 if (!address_ok(regs, ea, 8))
1272 goto ldst_done;
1273 err = 0;
1274 __get_user_asmx(val, ea, err, "ldarx");
1275 if (!err)
1276 regs->gpr[rd] = val;
1277 goto ldst_done;
1278
1279 case 214: /* stdcx. */
1280 ea = xform_ea(instr, regs, 0);
1281 if (ea & 7)
1282 break; /* can't handle misaligned */
1283 err = -EFAULT;
1284 if (!address_ok(regs, ea, 8))
1285 goto ldst_done;
1286 err = 0;
1287 __put_user_asmx(regs->gpr[rd], ea, err, "stdcx.", cr);
1288 if (!err)
1289 regs->ccr = (regs->ccr & 0x0fffffff) |
1290 (cr & 0xe0000000) |
1291 ((regs->xer >> 3) & 0x10000000);
1292 goto ldst_done;
1293
1294 case 21: /* ldx */
1295 case 53: /* ldux */
1296 err = read_mem(&regs->gpr[rd], xform_ea(instr, regs, u),
1297 8, regs);
1298 goto ldst_done;
1299#endif
1300
1301 case 23: /* lwzx */
1302 case 55: /* lwzux */
1303 err = read_mem(&regs->gpr[rd], xform_ea(instr, regs, u),
1304 4, regs);
1305 goto ldst_done;
1306
1307 case 87: /* lbzx */
1308 case 119: /* lbzux */
1309 err = read_mem(&regs->gpr[rd], xform_ea(instr, regs, u),
1310 1, regs);
1311 goto ldst_done;
1312
1313#ifdef CONFIG_ALTIVEC
1314 case 103: /* lvx */
1315 case 359: /* lvxl */
1316 if (!(regs->msr & MSR_VEC))
1317 break;
1318 ea = xform_ea(instr, regs, 0);
1319 err = do_vec_load(rd, do_lvx, ea, regs);
1320 goto ldst_done;
1321
1322 case 231: /* stvx */
1323 case 487: /* stvxl */
1324 if (!(regs->msr & MSR_VEC))
1325 break;
1326 ea = xform_ea(instr, regs, 0);
1327 err = do_vec_store(rd, do_stvx, ea, regs);
1328 goto ldst_done;
1329#endif /* CONFIG_ALTIVEC */
1330
1331#ifdef __powerpc64__
1332 case 149: /* stdx */
1333 case 181: /* stdux */
1334 val = regs->gpr[rd];
1335 err = write_mem(val, xform_ea(instr, regs, u), 8, regs);
1336 goto ldst_done;
1337#endif
1338
1339 case 151: /* stwx */
1340 case 183: /* stwux */
1341 val = regs->gpr[rd];
1342 err = write_mem(val, xform_ea(instr, regs, u), 4, regs);
1343 goto ldst_done;
1344
1345 case 215: /* stbx */
1346 case 247: /* stbux */
1347 val = regs->gpr[rd];
1348 err = write_mem(val, xform_ea(instr, regs, u), 1, regs);
1349 goto ldst_done;
1350
1351 case 279: /* lhzx */
1352 case 311: /* lhzux */
1353 err = read_mem(&regs->gpr[rd], xform_ea(instr, regs, u),
1354 2, regs);
1355 goto ldst_done;
1356
1357#ifdef __powerpc64__
1358 case 341: /* lwax */
1359 case 373: /* lwaux */
1360 err = read_mem(&regs->gpr[rd], xform_ea(instr, regs, u),
1361 4, regs);
1362 if (!err)
1363 regs->gpr[rd] = (signed int) regs->gpr[rd];
1364 goto ldst_done;
1365#endif
1366
1367 case 343: /* lhax */
1368 case 375: /* lhaux */
1369 err = read_mem(&regs->gpr[rd], xform_ea(instr, regs, u),
1370 2, regs);
1371 if (!err)
1372 regs->gpr[rd] = (signed short) regs->gpr[rd];
1373 goto ldst_done;
1374
1375 case 407: /* sthx */
1376 case 439: /* sthux */
1377 val = regs->gpr[rd];
1378 err = write_mem(val, xform_ea(instr, regs, u), 2, regs);
1379 goto ldst_done;
1380
1381#ifdef __powerpc64__
1382 case 532: /* ldbrx */
1383 err = read_mem(&val, xform_ea(instr, regs, 0), 8, regs);
1384 if (!err)
1385 regs->gpr[rd] = byterev_8(val);
1386 goto ldst_done;
1387
1388#endif
1389
1390 case 534: /* lwbrx */
1391 err = read_mem(&val, xform_ea(instr, regs, 0), 4, regs);
1392 if (!err)
1393 regs->gpr[rd] = byterev_4(val);
1394 goto ldst_done;
1395
1396 case 535: /* lfsx */
1397 case 567: /* lfsux */
1398 if (!(regs->msr & MSR_FP))
1399 break;
1400 ea = xform_ea(instr, regs, u);
1401 err = do_fp_load(rd, do_lfs, ea, 4, regs);
1402 goto ldst_done;
1403
1404 case 599: /* lfdx */
1405 case 631: /* lfdux */
1406 if (!(regs->msr & MSR_FP))
1407 break;
1408 ea = xform_ea(instr, regs, u);
1409 err = do_fp_load(rd, do_lfd, ea, 8, regs);
1410 goto ldst_done;
1411
1412 case 663: /* stfsx */
1413 case 695: /* stfsux */
1414 if (!(regs->msr & MSR_FP))
1415 break;
1416 ea = xform_ea(instr, regs, u);
1417 err = do_fp_store(rd, do_stfs, ea, 4, regs);
1418 goto ldst_done;
1419
1420 case 727: /* stfdx */
1421 case 759: /* stfdux */
1422 if (!(regs->msr & MSR_FP))
1423 break;
1424 ea = xform_ea(instr, regs, u);
1425 err = do_fp_store(rd, do_stfd, ea, 8, regs);
1426 goto ldst_done;
1427
1428#ifdef __powerpc64__
1429 case 660: /* stdbrx */
1430 val = byterev_8(regs->gpr[rd]);
1431 err = write_mem(val, xform_ea(instr, regs, 0), 8, regs);
1432 goto ldst_done;
1433
1434#endif
1435 case 662: /* stwbrx */
1436 val = byterev_4(regs->gpr[rd]);
1437 err = write_mem(val, xform_ea(instr, regs, 0), 4, regs);
1438 goto ldst_done;
1439
1440 case 790: /* lhbrx */
1441 err = read_mem(&val, xform_ea(instr, regs, 0), 2, regs);
1442 if (!err)
1443 regs->gpr[rd] = byterev_2(val);
1444 goto ldst_done;
1445
1446 case 918: /* sthbrx */
1447 val = byterev_2(regs->gpr[rd]);
1448 err = write_mem(val, xform_ea(instr, regs, 0), 2, regs);
1449 goto ldst_done;
1450
1451#ifdef CONFIG_VSX
1452 case 844: /* lxvd2x */
1453 case 876: /* lxvd2ux */
1454 if (!(regs->msr & MSR_VSX))
1455 break;
1456 rd |= (instr & 1) << 5;
1457 ea = xform_ea(instr, regs, u);
1458 err = do_vsx_load(rd, do_lxvd2x, ea, regs);
1459 goto ldst_done;
1460
1461 case 972: /* stxvd2x */
1462 case 1004: /* stxvd2ux */
1463 if (!(regs->msr & MSR_VSX))
1464 break;
1465 rd |= (instr & 1) << 5;
1466 ea = xform_ea(instr, regs, u);
1467 err = do_vsx_store(rd, do_stxvd2x, ea, regs);
1468 goto ldst_done;
1469
1470#endif /* CONFIG_VSX */
1471 }
1472 break;
1473
1474 case 32: /* lwz */
1475 case 33: /* lwzu */
1476 err = read_mem(&regs->gpr[rd], dform_ea(instr, regs), 4, regs);
1477 goto ldst_done;
1478
1479 case 34: /* lbz */
1480 case 35: /* lbzu */
1481 err = read_mem(&regs->gpr[rd], dform_ea(instr, regs), 1, regs);
1482 goto ldst_done;
1483
1484 case 36: /* stw */
1485 case 37: /* stwu */
1486 val = regs->gpr[rd];
1487 err = write_mem(val, dform_ea(instr, regs), 4, regs);
1488 goto ldst_done;
1489
1490 case 38: /* stb */
1491 case 39: /* stbu */
1492 val = regs->gpr[rd];
1493 err = write_mem(val, dform_ea(instr, regs), 1, regs);
1494 goto ldst_done;
1495
1496 case 40: /* lhz */
1497 case 41: /* lhzu */
1498 err = read_mem(&regs->gpr[rd], dform_ea(instr, regs), 2, regs);
1499 goto ldst_done;
1500
1501 case 42: /* lha */
1502 case 43: /* lhau */
1503 err = read_mem(&regs->gpr[rd], dform_ea(instr, regs), 2, regs);
1504 if (!err)
1505 regs->gpr[rd] = (signed short) regs->gpr[rd];
1506 goto ldst_done;
1507
1508 case 44: /* sth */
1509 case 45: /* sthu */
1510 val = regs->gpr[rd];
1511 err = write_mem(val, dform_ea(instr, regs), 2, regs);
1512 goto ldst_done;
1513
1514 case 46: /* lmw */
1515 ra = (instr >> 16) & 0x1f;
1516 if (ra >= rd)
1517 break; /* invalid form, ra in range to load */
1518 ea = dform_ea(instr, regs);
1519 do {
1520 err = read_mem(&regs->gpr[rd], ea, 4, regs);
1521 if (err)
1522 return 0;
1523 ea += 4;
1524 } while (++rd < 32);
1525 goto instr_done;
1526
1527 case 47: /* stmw */
1528 ea = dform_ea(instr, regs);
1529 do {
1530 err = write_mem(regs->gpr[rd], ea, 4, regs);
1531 if (err)
1532 return 0;
1533 ea += 4;
1534 } while (++rd < 32);
1535 goto instr_done;
1536
1537 case 48: /* lfs */
1538 case 49: /* lfsu */
1539 if (!(regs->msr & MSR_FP))
1540 break;
1541 ea = dform_ea(instr, regs);
1542 err = do_fp_load(rd, do_lfs, ea, 4, regs);
1543 goto ldst_done;
1544
1545 case 50: /* lfd */
1546 case 51: /* lfdu */
1547 if (!(regs->msr & MSR_FP))
1548 break;
1549 ea = dform_ea(instr, regs);
1550 err = do_fp_load(rd, do_lfd, ea, 8, regs);
1551 goto ldst_done;
1552
1553 case 52: /* stfs */
1554 case 53: /* stfsu */
1555 if (!(regs->msr & MSR_FP))
1556 break;
1557 ea = dform_ea(instr, regs);
1558 err = do_fp_store(rd, do_stfs, ea, 4, regs);
1559 goto ldst_done;
1560
1561 case 54: /* stfd */
1562 case 55: /* stfdu */
1563 if (!(regs->msr & MSR_FP))
1564 break;
1565 ea = dform_ea(instr, regs);
1566 err = do_fp_store(rd, do_stfd, ea, 8, regs);
1567 goto ldst_done;
1568
1569#ifdef __powerpc64__
1570 case 58: /* ld[u], lwa */
1571 switch (instr & 3) {
1572 case 0: /* ld */
1573 err = read_mem(&regs->gpr[rd], dsform_ea(instr, regs),
1574 8, regs);
1575 goto ldst_done;
1576 case 1: /* ldu */
1577 err = read_mem(&regs->gpr[rd], dsform_ea(instr, regs),
1578 8, regs);
1579 goto ldst_done;
1580 case 2: /* lwa */
1581 err = read_mem(&regs->gpr[rd], dsform_ea(instr, regs),
1582 4, regs);
1583 if (!err)
1584 regs->gpr[rd] = (signed int) regs->gpr[rd];
1585 goto ldst_done;
1586 }
1587 break;
1588
1589 case 62: /* std[u] */
1590 val = regs->gpr[rd];
1591 switch (instr & 3) {
1592 case 0: /* std */
1593 err = write_mem(val, dsform_ea(instr, regs), 8, regs);
1594 goto ldst_done;
1595 case 1: /* stdu */
1596 err = write_mem(val, dsform_ea(instr, regs), 8, regs);
1597 goto ldst_done;
1598 }
1599 break;
1600#endif /* __powerpc64__ */
1601
1602 }
1603 err = -EINVAL;
1604
1605 ldst_done:
1606 if (err) {
1607 regs->gpr[ra] = old_ra;
1608 return 0; /* invoke DSI if -EFAULT? */
1609 }
1610 instr_done:
1611 regs->nip += 4;
1612#ifdef __powerpc64__
1613 if ((regs->msr & MSR_SF) == 0)
1614 regs->nip &= 0xffffffffUL;
1615#endif
1616 return 1;
1617
1618 logical_done:
1619 if (instr & 1)
1620 set_cr0(regs, ra);
1621 goto instr_done;
1622
1623 arith_done:
1624 if (instr & 1)
1625 set_cr0(regs, rd);
1626 goto instr_done;
203} 1627}
diff --git a/arch/powerpc/mm/fsl_booke_mmu.c b/arch/powerpc/mm/fsl_booke_mmu.c
index cdc7526e9c9..4b66a1ece6d 100644
--- a/arch/powerpc/mm/fsl_booke_mmu.c
+++ b/arch/powerpc/mm/fsl_booke_mmu.c
@@ -104,9 +104,10 @@ unsigned long p_mapped_by_tlbcam(phys_addr_t pa)
104} 104}
105 105
106/* 106/*
107 * Set up one of the I/D BAT (block address translation) register pairs. 107 * Set up a variable-size TLB entry (tlbcam). The parameters are not checked;
108 * The parameters are not checked; in particular size must be a power 108 * in particular size must be a power of 4 between 4k and 256M (or 1G, for cpus
109 * of 4 between 4k and 256M. 109 * that support extended page sizes). Note that while some cpus support a
110 * page size of 4G, we don't allow its use here.
110 */ 111 */
111static void settlbcam(int index, unsigned long virt, phys_addr_t phys, 112static void settlbcam(int index, unsigned long virt, phys_addr_t phys,
112 unsigned long size, unsigned long flags, unsigned int pid) 113 unsigned long size, unsigned long flags, unsigned int pid)
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index f47364585ec..338c6f39eab 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -42,6 +42,12 @@ EXPORT_SYMBOL(node_data);
42 42
43static int min_common_depth; 43static int min_common_depth;
44static int n_mem_addr_cells, n_mem_size_cells; 44static int n_mem_addr_cells, n_mem_size_cells;
45static int form1_affinity;
46
47#define MAX_DISTANCE_REF_POINTS 4
48static int distance_ref_points_depth;
49static const unsigned int *distance_ref_points;
50static int distance_lookup_table[MAX_NUMNODES][MAX_DISTANCE_REF_POINTS];
45 51
46/* 52/*
47 * Allocate node_to_cpumask_map based on number of available nodes 53 * Allocate node_to_cpumask_map based on number of available nodes
@@ -204,6 +210,39 @@ static const u32 *of_get_usable_memory(struct device_node *memory)
204 return prop; 210 return prop;
205} 211}
206 212
213int __node_distance(int a, int b)
214{
215 int i;
216 int distance = LOCAL_DISTANCE;
217
218 if (!form1_affinity)
219 return distance;
220
221 for (i = 0; i < distance_ref_points_depth; i++) {
222 if (distance_lookup_table[a][i] == distance_lookup_table[b][i])
223 break;
224
225 /* Double the distance for each NUMA level */
226 distance *= 2;
227 }
228
229 return distance;
230}
231
232static void initialize_distance_lookup_table(int nid,
233 const unsigned int *associativity)
234{
235 int i;
236
237 if (!form1_affinity)
238 return;
239
240 for (i = 0; i < distance_ref_points_depth; i++) {
241 distance_lookup_table[nid][i] =
242 associativity[distance_ref_points[i]];
243 }
244}
245
207/* Returns nid in the range [0..MAX_NUMNODES-1], or -1 if no useful numa 246/* Returns nid in the range [0..MAX_NUMNODES-1], or -1 if no useful numa
208 * info is found. 247 * info is found.
209 */ 248 */
@@ -225,6 +264,10 @@ static int of_node_to_nid_single(struct device_node *device)
225 /* POWER4 LPAR uses 0xffff as invalid node */ 264 /* POWER4 LPAR uses 0xffff as invalid node */
226 if (nid == 0xffff || nid >= MAX_NUMNODES) 265 if (nid == 0xffff || nid >= MAX_NUMNODES)
227 nid = -1; 266 nid = -1;
267
268 if (nid > 0 && tmp[0] >= distance_ref_points_depth)
269 initialize_distance_lookup_table(nid, tmp);
270
228out: 271out:
229 return nid; 272 return nid;
230} 273}
@@ -251,26 +294,10 @@ int of_node_to_nid(struct device_node *device)
251} 294}
252EXPORT_SYMBOL_GPL(of_node_to_nid); 295EXPORT_SYMBOL_GPL(of_node_to_nid);
253 296
254/*
255 * In theory, the "ibm,associativity" property may contain multiple
256 * associativity lists because a resource may be multiply connected
257 * into the machine. This resource then has different associativity
258 * characteristics relative to its multiple connections. We ignore
259 * this for now. We also assume that all cpu and memory sets have
260 * their distances represented at a common level. This won't be
261 * true for hierarchical NUMA.
262 *
263 * In any case the ibm,associativity-reference-points should give
264 * the correct depth for a normal NUMA system.
265 *
266 * - Dave Hansen <haveblue@us.ibm.com>
267 */
268static int __init find_min_common_depth(void) 297static int __init find_min_common_depth(void)
269{ 298{
270 int depth, index; 299 int depth;
271 const unsigned int *ref_points;
272 struct device_node *rtas_root; 300 struct device_node *rtas_root;
273 unsigned int len;
274 struct device_node *chosen; 301 struct device_node *chosen;
275 const char *vec5; 302 const char *vec5;
276 303
@@ -280,18 +307,28 @@ static int __init find_min_common_depth(void)
280 return -1; 307 return -1;
281 308
282 /* 309 /*
283 * this property is 2 32-bit integers, each representing a level of 310 * This property is a set of 32-bit integers, each representing
284 * depth in the associativity nodes. The first is for an SMP 311 * an index into the ibm,associativity nodes.
285 * configuration (should be all 0's) and the second is for a normal 312 *
286 * NUMA configuration. 313 * With form 0 affinity the first integer is for an SMP configuration
314 * (should be all 0's) and the second is for a normal NUMA
315 * configuration. We have only one level of NUMA.
316 *
317 * With form 1 affinity the first integer is the most significant
318 * NUMA boundary and the following are progressively less significant
319 * boundaries. There can be more than one level of NUMA.
287 */ 320 */
288 index = 1; 321 distance_ref_points = of_get_property(rtas_root,
289 ref_points = of_get_property(rtas_root, 322 "ibm,associativity-reference-points",
290 "ibm,associativity-reference-points", &len); 323 &distance_ref_points_depth);
324
325 if (!distance_ref_points) {
326 dbg("NUMA: ibm,associativity-reference-points not found.\n");
327 goto err;
328 }
329
330 distance_ref_points_depth /= sizeof(int);
291 331
292 /*
293 * For form 1 affinity information we want the first field
294 */
295#define VEC5_AFFINITY_BYTE 5 332#define VEC5_AFFINITY_BYTE 5
296#define VEC5_AFFINITY 0x80 333#define VEC5_AFFINITY 0x80
297 chosen = of_find_node_by_path("/chosen"); 334 chosen = of_find_node_by_path("/chosen");
@@ -299,19 +336,38 @@ static int __init find_min_common_depth(void)
299 vec5 = of_get_property(chosen, "ibm,architecture-vec-5", NULL); 336 vec5 = of_get_property(chosen, "ibm,architecture-vec-5", NULL);
300 if (vec5 && (vec5[VEC5_AFFINITY_BYTE] & VEC5_AFFINITY)) { 337 if (vec5 && (vec5[VEC5_AFFINITY_BYTE] & VEC5_AFFINITY)) {
301 dbg("Using form 1 affinity\n"); 338 dbg("Using form 1 affinity\n");
302 index = 0; 339 form1_affinity = 1;
303 } 340 }
304 } 341 }
305 342
306 if ((len >= 2 * sizeof(unsigned int)) && ref_points) { 343 if (form1_affinity) {
307 depth = ref_points[index]; 344 depth = distance_ref_points[0];
308 } else { 345 } else {
309 dbg("NUMA: ibm,associativity-reference-points not found.\n"); 346 if (distance_ref_points_depth < 2) {
310 depth = -1; 347 printk(KERN_WARNING "NUMA: "
348 "short ibm,associativity-reference-points\n");
349 goto err;
350 }
351
352 depth = distance_ref_points[1];
311 } 353 }
312 of_node_put(rtas_root);
313 354
355 /*
356 * Warn and cap if the hardware supports more than
357 * MAX_DISTANCE_REF_POINTS domains.
358 */
359 if (distance_ref_points_depth > MAX_DISTANCE_REF_POINTS) {
360 printk(KERN_WARNING "NUMA: distance array capped at "
361 "%d entries\n", MAX_DISTANCE_REF_POINTS);
362 distance_ref_points_depth = MAX_DISTANCE_REF_POINTS;
363 }
364
365 of_node_put(rtas_root);
314 return depth; 366 return depth;
367
368err:
369 of_node_put(rtas_root);
370 return -1;
315} 371}
316 372
317static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells) 373static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells)
diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
index ebc2f38eb38..2c7e801ab20 100644
--- a/arch/powerpc/mm/pgtable.c
+++ b/arch/powerpc/mm/pgtable.c
@@ -92,7 +92,6 @@ static void pte_free_rcu_callback(struct rcu_head *head)
92 92
93static void pte_free_submit(struct pte_freelist_batch *batch) 93static void pte_free_submit(struct pte_freelist_batch *batch)
94{ 94{
95 INIT_RCU_HEAD(&batch->rcu);
96 call_rcu(&batch->rcu, pte_free_rcu_callback); 95 call_rcu(&batch->rcu, pte_free_rcu_callback);
97} 96}
98 97
diff --git a/arch/powerpc/mm/tlb_hash32.c b/arch/powerpc/mm/tlb_hash32.c
index 8aaa8b7eb32..690566b66e8 100644
--- a/arch/powerpc/mm/tlb_hash32.c
+++ b/arch/powerpc/mm/tlb_hash32.c
@@ -89,17 +89,6 @@ void tlb_flush(struct mmu_gather *tlb)
89 * -- Cort 89 * -- Cort
90 */ 90 */
91 91
92/*
93 * 750 SMP is a Bad Idea because the 750 doesn't broadcast all
94 * the cache operations on the bus. Hence we need to use an IPI
95 * to get the other CPU(s) to invalidate their TLBs.
96 */
97#ifdef CONFIG_SMP_750
98#define FINISH_FLUSH smp_send_tlb_invalidate(0)
99#else
100#define FINISH_FLUSH do { } while (0)
101#endif
102
103static void flush_range(struct mm_struct *mm, unsigned long start, 92static void flush_range(struct mm_struct *mm, unsigned long start,
104 unsigned long end) 93 unsigned long end)
105{ 94{
@@ -138,7 +127,6 @@ static void flush_range(struct mm_struct *mm, unsigned long start,
138void flush_tlb_kernel_range(unsigned long start, unsigned long end) 127void flush_tlb_kernel_range(unsigned long start, unsigned long end)
139{ 128{
140 flush_range(&init_mm, start, end); 129 flush_range(&init_mm, start, end);
141 FINISH_FLUSH;
142} 130}
143EXPORT_SYMBOL(flush_tlb_kernel_range); 131EXPORT_SYMBOL(flush_tlb_kernel_range);
144 132
@@ -162,7 +150,6 @@ void flush_tlb_mm(struct mm_struct *mm)
162 */ 150 */
163 for (mp = mm->mmap; mp != NULL; mp = mp->vm_next) 151 for (mp = mm->mmap; mp != NULL; mp = mp->vm_next)
164 flush_range(mp->vm_mm, mp->vm_start, mp->vm_end); 152 flush_range(mp->vm_mm, mp->vm_start, mp->vm_end);
165 FINISH_FLUSH;
166} 153}
167EXPORT_SYMBOL(flush_tlb_mm); 154EXPORT_SYMBOL(flush_tlb_mm);
168 155
@@ -179,7 +166,6 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
179 pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr); 166 pmd = pmd_offset(pud_offset(pgd_offset(mm, vmaddr), vmaddr), vmaddr);
180 if (!pmd_none(*pmd)) 167 if (!pmd_none(*pmd))
181 flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1); 168 flush_hash_pages(mm->context.id, vmaddr, pmd_val(*pmd), 1);
182 FINISH_FLUSH;
183} 169}
184EXPORT_SYMBOL(flush_tlb_page); 170EXPORT_SYMBOL(flush_tlb_page);
185 171
@@ -192,6 +178,5 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
192 unsigned long end) 178 unsigned long end)
193{ 179{
194 flush_range(vma->vm_mm, start, end); 180 flush_range(vma->vm_mm, start, end);
195 FINISH_FLUSH;
196} 181}
197EXPORT_SYMBOL(flush_tlb_range); 182EXPORT_SYMBOL(flush_tlb_range);
diff --git a/arch/powerpc/mm/tlb_nohash.c b/arch/powerpc/mm/tlb_nohash.c
index d8695b02a96..fe391e94252 100644
--- a/arch/powerpc/mm/tlb_nohash.c
+++ b/arch/powerpc/mm/tlb_nohash.c
@@ -46,6 +46,7 @@
46struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = { 46struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = {
47 [MMU_PAGE_4K] = { 47 [MMU_PAGE_4K] = {
48 .shift = 12, 48 .shift = 12,
49 .ind = 20,
49 .enc = BOOK3E_PAGESZ_4K, 50 .enc = BOOK3E_PAGESZ_4K,
50 }, 51 },
51 [MMU_PAGE_16K] = { 52 [MMU_PAGE_16K] = {
@@ -54,6 +55,7 @@ struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = {
54 }, 55 },
55 [MMU_PAGE_64K] = { 56 [MMU_PAGE_64K] = {
56 .shift = 16, 57 .shift = 16,
58 .ind = 28,
57 .enc = BOOK3E_PAGESZ_64K, 59 .enc = BOOK3E_PAGESZ_64K,
58 }, 60 },
59 [MMU_PAGE_1M] = { 61 [MMU_PAGE_1M] = {
@@ -62,6 +64,7 @@ struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT] = {
62 }, 64 },
63 [MMU_PAGE_16M] = { 65 [MMU_PAGE_16M] = {
64 .shift = 24, 66 .shift = 24,
67 .ind = 36,
65 .enc = BOOK3E_PAGESZ_16M, 68 .enc = BOOK3E_PAGESZ_16M,
66 }, 69 },
67 [MMU_PAGE_256M] = { 70 [MMU_PAGE_256M] = {
@@ -344,16 +347,108 @@ void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address)
344 } 347 }
345} 348}
346 349
347/* 350static void setup_page_sizes(void)
348 * Early initialization of the MMU TLB code 351{
349 */ 352 unsigned int tlb0cfg = mfspr(SPRN_TLB0CFG);
350static void __early_init_mmu(int boot_cpu) 353 unsigned int tlb0ps = mfspr(SPRN_TLB0PS);
354 unsigned int eptcfg = mfspr(SPRN_EPTCFG);
355 int i, psize;
356
357 /* Look for supported direct sizes */
358 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
359 struct mmu_psize_def *def = &mmu_psize_defs[psize];
360
361 if (tlb0ps & (1U << (def->shift - 10)))
362 def->flags |= MMU_PAGE_SIZE_DIRECT;
363 }
364
365 /* Indirect page sizes supported ? */
366 if ((tlb0cfg & TLBnCFG_IND) == 0)
367 goto no_indirect;
368
369 /* Now, we only deal with one IND page size for each
370 * direct size. Hopefully all implementations today are
371 * unambiguous, but we might want to be careful in the
372 * future.
373 */
374 for (i = 0; i < 3; i++) {
375 unsigned int ps, sps;
376
377 sps = eptcfg & 0x1f;
378 eptcfg >>= 5;
379 ps = eptcfg & 0x1f;
380 eptcfg >>= 5;
381 if (!ps || !sps)
382 continue;
383 for (psize = 0; psize < MMU_PAGE_COUNT; psize++) {
384 struct mmu_psize_def *def = &mmu_psize_defs[psize];
385
386 if (ps == (def->shift - 10))
387 def->flags |= MMU_PAGE_SIZE_INDIRECT;
388 if (sps == (def->shift - 10))
389 def->ind = ps + 10;
390 }
391 }
392 no_indirect:
393
394 /* Cleanup array and print summary */
395 pr_info("MMU: Supported page sizes\n");
396 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
397 struct mmu_psize_def *def = &mmu_psize_defs[psize];
398 const char *__page_type_names[] = {
399 "unsupported",
400 "direct",
401 "indirect",
402 "direct & indirect"
403 };
404 if (def->flags == 0) {
405 def->shift = 0;
406 continue;
407 }
408 pr_info(" %8ld KB as %s\n", 1ul << (def->shift - 10),
409 __page_type_names[def->flags & 0x3]);
410 }
411}
412
413static void setup_mmu_htw(void)
351{ 414{
352 extern unsigned int interrupt_base_book3e; 415 extern unsigned int interrupt_base_book3e;
353 extern unsigned int exc_data_tlb_miss_htw_book3e; 416 extern unsigned int exc_data_tlb_miss_htw_book3e;
354 extern unsigned int exc_instruction_tlb_miss_htw_book3e; 417 extern unsigned int exc_instruction_tlb_miss_htw_book3e;
355 418
356 unsigned int *ibase = &interrupt_base_book3e; 419 unsigned int *ibase = &interrupt_base_book3e;
420
421 /* Check if HW tablewalk is present, and if yes, enable it by:
422 *
423 * - patching the TLB miss handlers to branch to the
424 * one dedicates to it
425 *
426 * - setting the global book3e_htw_enabled
427 */
428 unsigned int tlb0cfg = mfspr(SPRN_TLB0CFG);
429
430 if ((tlb0cfg & TLBnCFG_IND) &&
431 (tlb0cfg & TLBnCFG_PT)) {
432 /* Our exceptions vectors start with a NOP and -then- a branch
433 * to deal with single stepping from userspace which stops on
434 * the second instruction. Thus we need to patch the second
435 * instruction of the exception, not the first one
436 */
437 patch_branch(ibase + (0x1c0 / 4) + 1,
438 (unsigned long)&exc_data_tlb_miss_htw_book3e, 0);
439 patch_branch(ibase + (0x1e0 / 4) + 1,
440 (unsigned long)&exc_instruction_tlb_miss_htw_book3e, 0);
441 book3e_htw_enabled = 1;
442 }
443 pr_info("MMU: Book3E Page Tables %s\n",
444 book3e_htw_enabled ? "Enabled" : "Disabled");
445}
446
447/*
448 * Early initialization of the MMU TLB code
449 */
450static void __early_init_mmu(int boot_cpu)
451{
357 unsigned int mas4; 452 unsigned int mas4;
358 453
359 /* XXX This will have to be decided at runtime, but right 454 /* XXX This will have to be decided at runtime, but right
@@ -370,35 +465,17 @@ static void __early_init_mmu(int boot_cpu)
370 */ 465 */
371 mmu_vmemmap_psize = MMU_PAGE_16M; 466 mmu_vmemmap_psize = MMU_PAGE_16M;
372 467
373 /* Check if HW tablewalk is present, and if yes, enable it by:
374 *
375 * - patching the TLB miss handlers to branch to the
376 * one dedicates to it
377 *
378 * - setting the global book3e_htw_enabled
379 *
380 * - Set MAS4:INDD and default page size
381 */
382
383 /* XXX This code only checks for TLB 0 capabilities and doesn't 468 /* XXX This code only checks for TLB 0 capabilities and doesn't
384 * check what page size combos are supported by the HW. It 469 * check what page size combos are supported by the HW. It
385 * also doesn't handle the case where a separate array holds 470 * also doesn't handle the case where a separate array holds
386 * the IND entries from the array loaded by the PT. 471 * the IND entries from the array loaded by the PT.
387 */ 472 */
388 if (boot_cpu) { 473 if (boot_cpu) {
389 unsigned int tlb0cfg = mfspr(SPRN_TLB0CFG); 474 /* Look for supported page sizes */
475 setup_page_sizes();
390 476
391 /* Check if HW loader is supported */ 477 /* Look for HW tablewalk support */
392 if ((tlb0cfg & TLBnCFG_IND) && 478 setup_mmu_htw();
393 (tlb0cfg & TLBnCFG_PT)) {
394 patch_branch(ibase + (0x1c0 / 4),
395 (unsigned long)&exc_data_tlb_miss_htw_book3e, 0);
396 patch_branch(ibase + (0x1e0 / 4),
397 (unsigned long)&exc_instruction_tlb_miss_htw_book3e, 0);
398 book3e_htw_enabled = 1;
399 }
400 pr_info("MMU: Book3E Page Tables %s\n",
401 book3e_htw_enabled ? "Enabled" : "Disabled");
402 } 479 }
403 480
404 /* Set MAS4 based on page table setting */ 481 /* Set MAS4 based on page table setting */
diff --git a/arch/powerpc/oprofile/Makefile b/arch/powerpc/oprofile/Makefile
index 73e1c2ca055..e219ca43962 100644
--- a/arch/powerpc/oprofile/Makefile
+++ b/arch/powerpc/oprofile/Makefile
@@ -16,6 +16,6 @@ oprofile-y := $(DRIVER_OBJS) common.o backtrace.o
16oprofile-$(CONFIG_OPROFILE_CELL) += op_model_cell.o \ 16oprofile-$(CONFIG_OPROFILE_CELL) += op_model_cell.o \
17 cell/spu_profiler.o cell/vma_map.o \ 17 cell/spu_profiler.o cell/vma_map.o \
18 cell/spu_task_sync.o 18 cell/spu_task_sync.o
19oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o op_model_pa6t.o 19oprofile-$(CONFIG_PPC_BOOK3S_64) += op_model_rs64.o op_model_power4.o op_model_pa6t.o
20oprofile-$(CONFIG_FSL_EMB_PERFMON) += op_model_fsl_emb.o 20oprofile-$(CONFIG_FSL_EMB_PERFMON) += op_model_fsl_emb.o
21oprofile-$(CONFIG_6xx) += op_model_7450.o 21oprofile-$(CONFIG_6xx) += op_model_7450.o
diff --git a/arch/powerpc/oprofile/common.c b/arch/powerpc/oprofile/common.c
index 21f16edf6c8..d65e68f3cb2 100644
--- a/arch/powerpc/oprofile/common.c
+++ b/arch/powerpc/oprofile/common.c
@@ -199,7 +199,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
199 return -ENODEV; 199 return -ENODEV;
200 200
201 switch (cur_cpu_spec->oprofile_type) { 201 switch (cur_cpu_spec->oprofile_type) {
202#ifdef CONFIG_PPC64 202#ifdef CONFIG_PPC_BOOK3S_64
203#ifdef CONFIG_OPROFILE_CELL 203#ifdef CONFIG_OPROFILE_CELL
204 case PPC_OPROFILE_CELL: 204 case PPC_OPROFILE_CELL:
205 if (firmware_has_feature(FW_FEATURE_LPAR)) 205 if (firmware_has_feature(FW_FEATURE_LPAR))
diff --git a/arch/powerpc/platforms/40x/Kconfig b/arch/powerpc/platforms/40x/Kconfig
index ec64264f7a5..b72176434eb 100644
--- a/arch/powerpc/platforms/40x/Kconfig
+++ b/arch/powerpc/platforms/40x/Kconfig
@@ -71,22 +71,6 @@ config MAKALU
71 help 71 help
72 This option enables support for the AMCC PPC405EX board. 72 This option enables support for the AMCC PPC405EX board.
73 73
74#config REDWOOD_5
75# bool "Redwood-5"
76# depends on 40x
77# default n
78# select STB03xxx
79# help
80# This option enables support for the IBM STB04 evaluation board.
81
82#config REDWOOD_6
83# bool "Redwood-6"
84# depends on 40x
85# default n
86# select STB03xxx
87# help
88# This option enables support for the IBM STBx25xx evaluation board.
89
90#config SYCAMORE 74#config SYCAMORE
91# bool "Sycamore" 75# bool "Sycamore"
92# depends on 40x 76# depends on 40x
diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platforms/52xx/lite5200_pm.c
index b5c753db125..80234e5921f 100644
--- a/arch/powerpc/platforms/52xx/lite5200_pm.c
+++ b/arch/powerpc/platforms/52xx/lite5200_pm.c
@@ -216,9 +216,6 @@ static int lite5200_pm_enter(suspend_state_t state)
216 216
217 lite5200_restore_regs(); 217 lite5200_restore_regs();
218 218
219 /* restart jiffies */
220 wakeup_decrementer();
221
222 iounmap(mbar); 219 iounmap(mbar);
223 return 0; 220 return 0;
224} 221}
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pm.c b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
index 76722532bd9..568cef63627 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_pm.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
@@ -171,9 +171,6 @@ int mpc52xx_pm_enter(suspend_state_t state)
171 /* restore SRAM */ 171 /* restore SRAM */
172 memcpy(sram, saved_sram, sram_size); 172 memcpy(sram, saved_sram, sram_size);
173 173
174 /* restart jiffies */
175 wakeup_decrementer();
176
177 /* reenable interrupts in PIC */ 174 /* reenable interrupts in PIC */
178 out_be32(&intr->main_mask, intr_main_mask); 175 out_be32(&intr->main_mask, intr_main_mask);
179 176
diff --git a/arch/powerpc/platforms/85xx/smp.c b/arch/powerpc/platforms/85xx/smp.c
index a15f582300d..4c3cde911c7 100644
--- a/arch/powerpc/platforms/85xx/smp.c
+++ b/arch/powerpc/platforms/85xx/smp.c
@@ -99,6 +99,8 @@ static void __init
99smp_85xx_setup_cpu(int cpu_nr) 99smp_85xx_setup_cpu(int cpu_nr)
100{ 100{
101 mpic_setup_this_cpu(); 101 mpic_setup_this_cpu();
102 if (cpu_has_feature(CPU_FTR_DBELL))
103 doorbell_setup_this_cpu();
102} 104}
103 105
104struct smp_ops_t smp_85xx_ops = { 106struct smp_ops_t smp_85xx_ops = {
@@ -117,7 +119,7 @@ void __init mpc85xx_smp_init(void)
117 } 119 }
118 120
119 if (cpu_has_feature(CPU_FTR_DBELL)) 121 if (cpu_has_feature(CPU_FTR_DBELL))
120 smp_85xx_ops.message_pass = smp_dbell_message_pass; 122 smp_85xx_ops.message_pass = doorbell_message_pass;
121 123
122 BUG_ON(!smp_85xx_ops.message_pass); 124 BUG_ON(!smp_85xx_ops.message_pass);
123 125
diff --git a/arch/powerpc/platforms/iseries/vio.c b/arch/powerpc/platforms/iseries/vio.c
index 00b6730bc48..b6db7cef83b 100644
--- a/arch/powerpc/platforms/iseries/vio.c
+++ b/arch/powerpc/platforms/iseries/vio.c
@@ -87,12 +87,11 @@ static struct device_node *new_node(const char *path,
87 87
88 if (!np) 88 if (!np)
89 return NULL; 89 return NULL;
90 np->full_name = kmalloc(strlen(path) + 1, GFP_KERNEL); 90 np->full_name = kstrdup(path, GFP_KERNEL);
91 if (!np->full_name) { 91 if (!np->full_name) {
92 kfree(np); 92 kfree(np);
93 return NULL; 93 return NULL;
94 } 94 }
95 strcpy(np->full_name, path);
96 of_node_set_flag(np, OF_DYNAMIC); 95 of_node_set_flag(np, OF_DYNAMIC);
97 kref_init(&np->kref); 96 kref_init(&np->kref);
98 np->parent = of_node_get(parent); 97 np->parent = of_node_get(parent);
diff --git a/arch/powerpc/platforms/powermac/cpufreq_32.c b/arch/powerpc/platforms/powermac/cpufreq_32.c
index 1e9eba175ff..415ca6d6b27 100644
--- a/arch/powerpc/platforms/powermac/cpufreq_32.c
+++ b/arch/powerpc/platforms/powermac/cpufreq_32.c
@@ -310,8 +310,12 @@ static int pmu_set_cpu_speed(int low_speed)
310 /* Restore low level PMU operations */ 310 /* Restore low level PMU operations */
311 pmu_unlock(); 311 pmu_unlock();
312 312
313 /* Restore decrementer */ 313 /*
314 wakeup_decrementer(); 314 * Restore decrementer; we'll take a decrementer interrupt
315 * as soon as interrupts are re-enabled and the generic
316 * clockevents code will reprogram it with the right value.
317 */
318 set_dec(1);
315 319
316 /* Restore interrupts */ 320 /* Restore interrupts */
317 mpic_cpu_set_priority(pic_prio); 321 mpic_cpu_set_priority(pic_prio);
diff --git a/arch/powerpc/platforms/powermac/feature.c b/arch/powerpc/platforms/powermac/feature.c
index 9e1b9fd7520..79bd3e89dba 100644
--- a/arch/powerpc/platforms/powermac/feature.c
+++ b/arch/powerpc/platforms/powermac/feature.c
@@ -2191,7 +2191,11 @@ static struct pmac_mb_def pmac_mb_defs[] = {
2191 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features, 2191 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2192 PMAC_MB_MAY_SLEEP, 2192 PMAC_MB_MAY_SLEEP,
2193 }, 2193 },
2194 { "iMac,1", "iMac (first generation)", 2194 { "PowerMac10,2", "Mac mini (Late 2005)",
2195 PMAC_TYPE_UNKNOWN_INTREPID, intrepid_features,
2196 PMAC_MB_MAY_SLEEP,
2197 },
2198 { "iMac,1", "iMac (first generation)",
2195 PMAC_TYPE_ORIG_IMAC, paddington_features, 2199 PMAC_TYPE_ORIG_IMAC, paddington_features,
2196 0 2200 0
2197 }, 2201 },
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index 3dbef309bc8..046ace9c438 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -26,3 +26,7 @@ obj-$(CONFIG_HCALL_STATS) += hvCall_inst.o
26obj-$(CONFIG_PHYP_DUMP) += phyp_dump.o 26obj-$(CONFIG_PHYP_DUMP) += phyp_dump.o
27obj-$(CONFIG_CMM) += cmm.o 27obj-$(CONFIG_CMM) += cmm.o
28obj-$(CONFIG_DTL) += dtl.o 28obj-$(CONFIG_DTL) += dtl.o
29
30ifeq ($(CONFIG_PPC_PSERIES),y)
31obj-$(CONFIG_SUSPEND) += suspend.o
32endif
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index d71e5858408..227c1c3d585 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -463,6 +463,7 @@ static int dlpar_offline_cpu(struct device_node *dn)
463 break; 463 break;
464 464
465 if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) { 465 if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) {
466 set_preferred_offline_state(cpu, CPU_STATE_OFFLINE);
466 cpu_maps_update_done(); 467 cpu_maps_update_done();
467 rc = cpu_down(cpu); 468 rc = cpu_down(cpu);
468 if (rc) 469 if (rc)
diff --git a/arch/powerpc/platforms/pseries/eeh_cache.c b/arch/powerpc/platforms/pseries/eeh_cache.c
index 30b987b73c2..8ed0d2d0e1b 100644
--- a/arch/powerpc/platforms/pseries/eeh_cache.c
+++ b/arch/powerpc/platforms/pseries/eeh_cache.c
@@ -288,8 +288,7 @@ void __init pci_addr_cache_build(void)
288 288
289 spin_lock_init(&pci_io_addr_cache_root.piar_lock); 289 spin_lock_init(&pci_io_addr_cache_root.piar_lock);
290 290
291 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 291 for_each_pci_dev(dev) {
292
293 pci_addr_cache_insert_device(dev); 292 pci_addr_cache_insert_device(dev);
294 293
295 dn = pci_device_to_OF_node(dev); 294 dn = pci_device_to_OF_node(dev);
diff --git a/arch/powerpc/platforms/pseries/event_sources.c b/arch/powerpc/platforms/pseries/event_sources.c
index e889c9d9586..2605c310166 100644
--- a/arch/powerpc/platforms/pseries/event_sources.c
+++ b/arch/powerpc/platforms/pseries/event_sources.c
@@ -41,9 +41,12 @@ void request_event_sources_irqs(struct device_node *np,
41 if (count > 15) 41 if (count > 15)
42 break; 42 break;
43 virqs[count] = irq_create_mapping(NULL, *(opicprop++)); 43 virqs[count] = irq_create_mapping(NULL, *(opicprop++));
44 if (virqs[count] == NO_IRQ) 44 if (virqs[count] == NO_IRQ) {
45 printk(KERN_ERR "Unable to allocate interrupt " 45 pr_err("event-sources: Unable to allocate "
46 "number for %s\n", np->full_name); 46 "interrupt number for %s\n",
47 np->full_name);
48 WARN_ON(1);
49 }
47 else 50 else
48 count++; 51 count++;
49 52
@@ -59,9 +62,12 @@ void request_event_sources_irqs(struct device_node *np,
59 virqs[count] = irq_create_of_mapping(oirq.controller, 62 virqs[count] = irq_create_of_mapping(oirq.controller,
60 oirq.specifier, 63 oirq.specifier,
61 oirq.size); 64 oirq.size);
62 if (virqs[count] == NO_IRQ) 65 if (virqs[count] == NO_IRQ) {
63 printk(KERN_ERR "Unable to allocate interrupt " 66 pr_err("event-sources: Unable to allocate "
64 "number for %s\n", np->full_name); 67 "interrupt number for %s\n",
68 np->full_name);
69 WARN_ON(1);
70 }
65 else 71 else
66 count++; 72 count++;
67 } 73 }
@@ -70,8 +76,9 @@ void request_event_sources_irqs(struct device_node *np,
70 /* Now request them */ 76 /* Now request them */
71 for (i = 0; i < count; i++) { 77 for (i = 0; i < count; i++) {
72 if (request_irq(virqs[i], handler, 0, name, NULL)) { 78 if (request_irq(virqs[i], handler, 0, name, NULL)) {
73 printk(KERN_ERR "Unable to request interrupt %d for " 79 pr_err("event-sources: Unable to request interrupt "
74 "%s\n", virqs[i], np->full_name); 80 "%d for %s\n", virqs[i], np->full_name);
81 WARN_ON(1);
75 return; 82 return;
76 } 83 }
77 } 84 }
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 8f85f399ab9..fd50ccd4bac 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -116,6 +116,9 @@ static void pseries_mach_cpu_die(void)
116 116
117 if (get_preferred_offline_state(cpu) == CPU_STATE_INACTIVE) { 117 if (get_preferred_offline_state(cpu) == CPU_STATE_INACTIVE) {
118 set_cpu_current_state(cpu, CPU_STATE_INACTIVE); 118 set_cpu_current_state(cpu, CPU_STATE_INACTIVE);
119 if (ppc_md.suspend_disable_cpu)
120 ppc_md.suspend_disable_cpu();
121
119 cede_latency_hint = 2; 122 cede_latency_hint = 2;
120 123
121 get_lppaca()->idle = 1; 124 get_lppaca()->idle = 1;
@@ -190,12 +193,12 @@ static void pseries_cpu_die(unsigned int cpu)
190 193
191 if (get_preferred_offline_state(cpu) == CPU_STATE_INACTIVE) { 194 if (get_preferred_offline_state(cpu) == CPU_STATE_INACTIVE) {
192 cpu_status = 1; 195 cpu_status = 1;
193 for (tries = 0; tries < 1000; tries++) { 196 for (tries = 0; tries < 5000; tries++) {
194 if (get_cpu_current_state(cpu) == CPU_STATE_INACTIVE) { 197 if (get_cpu_current_state(cpu) == CPU_STATE_INACTIVE) {
195 cpu_status = 0; 198 cpu_status = 0;
196 break; 199 break;
197 } 200 }
198 cpu_relax(); 201 msleep(1);
199 } 202 }
200 } else if (get_preferred_offline_state(cpu) == CPU_STATE_OFFLINE) { 203 } else if (get_preferred_offline_state(cpu) == CPU_STATE_OFFLINE) {
201 204
diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index 41a3e9a039e..a4fc6da87c2 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -61,7 +61,6 @@ static int ras_check_exception_token;
61 61
62#define EPOW_SENSOR_TOKEN 9 62#define EPOW_SENSOR_TOKEN 9
63#define EPOW_SENSOR_INDEX 0 63#define EPOW_SENSOR_INDEX 0
64#define RAS_VECTOR_OFFSET 0x500
65 64
66static irqreturn_t ras_epow_interrupt(int irq, void *dev_id); 65static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
67static irqreturn_t ras_error_interrupt(int irq, void *dev_id); 66static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
@@ -121,7 +120,7 @@ static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
121 spin_lock(&ras_log_buf_lock); 120 spin_lock(&ras_log_buf_lock);
122 121
123 status = rtas_call(ras_check_exception_token, 6, 1, NULL, 122 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
124 RAS_VECTOR_OFFSET, 123 RTAS_VECTOR_EXTERNAL_INTERRUPT,
125 irq_map[irq].hwirq, 124 irq_map[irq].hwirq,
126 RTAS_EPOW_WARNING | RTAS_POWERMGM_EVENTS, 125 RTAS_EPOW_WARNING | RTAS_POWERMGM_EVENTS,
127 critical, __pa(&ras_log_buf), 126 critical, __pa(&ras_log_buf),
@@ -156,7 +155,7 @@ static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
156 spin_lock(&ras_log_buf_lock); 155 spin_lock(&ras_log_buf_lock);
157 156
158 status = rtas_call(ras_check_exception_token, 6, 1, NULL, 157 status = rtas_call(ras_check_exception_token, 6, 1, NULL,
159 RAS_VECTOR_OFFSET, 158 RTAS_VECTOR_EXTERNAL_INTERRUPT,
160 irq_map[irq].hwirq, 159 irq_map[irq].hwirq,
161 RTAS_INTERNAL_ERROR, 1 /*Time Critical */, 160 RTAS_INTERNAL_ERROR, 1 /*Time Critical */,
162 __pa(&ras_log_buf), 161 __pa(&ras_log_buf),
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index 1a58637bcea..57ddbb43b33 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -118,12 +118,10 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist
118 if (!np) 118 if (!np)
119 goto out_err; 119 goto out_err;
120 120
121 np->full_name = kmalloc(strlen(path) + 1, GFP_KERNEL); 121 np->full_name = kstrdup(path, GFP_KERNEL);
122 if (!np->full_name) 122 if (!np->full_name)
123 goto out_err; 123 goto out_err;
124 124
125 strcpy(np->full_name, path);
126
127 np->properties = proplist; 125 np->properties = proplist;
128 of_node_set_flag(np, OF_DYNAMIC); 126 of_node_set_flag(np, OF_DYNAMIC);
129 kref_init(&np->kref); 127 kref_init(&np->kref);
diff --git a/arch/powerpc/platforms/pseries/suspend.c b/arch/powerpc/platforms/pseries/suspend.c
new file mode 100644
index 00000000000..ed72098bb4e
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/suspend.c
@@ -0,0 +1,214 @@
1/*
2 * Copyright (C) 2010 Brian King IBM Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <linux/delay.h>
20#include <linux/suspend.h>
21#include <asm/firmware.h>
22#include <asm/hvcall.h>
23#include <asm/machdep.h>
24#include <asm/mmu.h>
25#include <asm/rtas.h>
26
27static u64 stream_id;
28static struct sys_device suspend_sysdev;
29static DECLARE_COMPLETION(suspend_work);
30static struct rtas_suspend_me_data suspend_data;
31static atomic_t suspending;
32
33/**
34 * pseries_suspend_begin - First phase of hibernation
35 *
36 * Check to ensure we are in a valid state to hibernate
37 *
38 * Return value:
39 * 0 on success / other on failure
40 **/
41static int pseries_suspend_begin(suspend_state_t state)
42{
43 long vasi_state, rc;
44 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
45
46 /* Make sure the state is valid */
47 rc = plpar_hcall(H_VASI_STATE, retbuf, stream_id);
48
49 vasi_state = retbuf[0];
50
51 if (rc) {
52 pr_err("pseries_suspend_begin: vasi_state returned %ld\n",rc);
53 return rc;
54 } else if (vasi_state == H_VASI_ENABLED) {
55 return -EAGAIN;
56 } else if (vasi_state != H_VASI_SUSPENDING) {
57 pr_err("pseries_suspend_begin: vasi_state returned state %ld\n",
58 vasi_state);
59 return -EIO;
60 }
61
62 return 0;
63}
64
65/**
66 * pseries_suspend_cpu - Suspend a single CPU
67 *
68 * Makes the H_JOIN call to suspend the CPU
69 *
70 **/
71static int pseries_suspend_cpu(void)
72{
73 if (atomic_read(&suspending))
74 return rtas_suspend_cpu(&suspend_data);
75 return 0;
76}
77
78/**
79 * pseries_suspend_enter - Final phase of hibernation
80 *
81 * Return value:
82 * 0 on success / other on failure
83 **/
84static int pseries_suspend_enter(suspend_state_t state)
85{
86 int rc = rtas_suspend_last_cpu(&suspend_data);
87
88 atomic_set(&suspending, 0);
89 atomic_set(&suspend_data.done, 1);
90 return rc;
91}
92
93/**
94 * pseries_prepare_late - Prepare to suspend all other CPUs
95 *
96 * Return value:
97 * 0 on success / other on failure
98 **/
99static int pseries_prepare_late(void)
100{
101 atomic_set(&suspending, 1);
102 atomic_set(&suspend_data.working, 0);
103 atomic_set(&suspend_data.done, 0);
104 atomic_set(&suspend_data.error, 0);
105 suspend_data.complete = &suspend_work;
106 INIT_COMPLETION(suspend_work);
107 return 0;
108}
109
110/**
111 * store_hibernate - Initiate partition hibernation
112 * @classdev: sysdev class struct
113 * @attr: class device attribute struct
114 * @buf: buffer
115 * @count: buffer size
116 *
117 * Write the stream ID received from the HMC to this file
118 * to trigger hibernating the partition
119 *
120 * Return value:
121 * number of bytes printed to buffer / other on failure
122 **/
123static ssize_t store_hibernate(struct sysdev_class *classdev,
124 struct sysdev_class_attribute *attr,
125 const char *buf, size_t count)
126{
127 int rc;
128
129 if (!capable(CAP_SYS_ADMIN))
130 return -EPERM;
131
132 stream_id = simple_strtoul(buf, NULL, 16);
133
134 do {
135 rc = pseries_suspend_begin(PM_SUSPEND_MEM);
136 if (rc == -EAGAIN)
137 ssleep(1);
138 } while (rc == -EAGAIN);
139
140 if (!rc)
141 rc = pm_suspend(PM_SUSPEND_MEM);
142
143 stream_id = 0;
144
145 if (!rc)
146 rc = count;
147 return rc;
148}
149
150static SYSDEV_CLASS_ATTR(hibernate, S_IWUSR, NULL, store_hibernate);
151
152static struct sysdev_class suspend_sysdev_class = {
153 .name = "power",
154};
155
156static struct platform_suspend_ops pseries_suspend_ops = {
157 .valid = suspend_valid_only_mem,
158 .begin = pseries_suspend_begin,
159 .prepare_late = pseries_prepare_late,
160 .enter = pseries_suspend_enter,
161};
162
163/**
164 * pseries_suspend_sysfs_register - Register with sysfs
165 *
166 * Return value:
167 * 0 on success / other on failure
168 **/
169static int pseries_suspend_sysfs_register(struct sys_device *sysdev)
170{
171 int rc;
172
173 if ((rc = sysdev_class_register(&suspend_sysdev_class)))
174 return rc;
175
176 sysdev->id = 0;
177 sysdev->cls = &suspend_sysdev_class;
178
179 if ((rc = sysdev_class_create_file(&suspend_sysdev_class, &attr_hibernate)))
180 goto class_unregister;
181
182 return 0;
183
184class_unregister:
185 sysdev_class_unregister(&suspend_sysdev_class);
186 return rc;
187}
188
189/**
190 * pseries_suspend_init - initcall for pSeries suspend
191 *
192 * Return value:
193 * 0 on success / other on failure
194 **/
195static int __init pseries_suspend_init(void)
196{
197 int rc;
198
199 if (!machine_is(pseries) || !firmware_has_feature(FW_FEATURE_LPAR))
200 return 0;
201
202 suspend_data.token = rtas_token("ibm,suspend-me");
203 if (suspend_data.token == RTAS_UNKNOWN_SERVICE)
204 return 0;
205
206 if ((rc = pseries_suspend_sysfs_register(&suspend_sysdev)))
207 return rc;
208
209 ppc_md.suspend_disable_cpu = pseries_suspend_cpu;
210 suspend_set_ops(&pseries_suspend_ops);
211 return 0;
212}
213
214__initcall(pseries_suspend_init);
diff --git a/arch/powerpc/platforms/pseries/xics.c b/arch/powerpc/platforms/pseries/xics.c
index f19d1946839..5b22b07c8f6 100644
--- a/arch/powerpc/platforms/pseries/xics.c
+++ b/arch/powerpc/platforms/pseries/xics.c
@@ -549,8 +549,6 @@ static irqreturn_t xics_ipi_dispatch(int cpu)
549{ 549{
550 unsigned long *tgt = &per_cpu(xics_ipi_message, cpu); 550 unsigned long *tgt = &per_cpu(xics_ipi_message, cpu);
551 551
552 WARN_ON(cpu_is_offline(cpu));
553
554 mb(); /* order mmio clearing qirr */ 552 mb(); /* order mmio clearing qirr */
555 while (*tgt) { 553 while (*tgt) {
556 if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION, tgt)) { 554 if (test_and_clear_bit(PPC_MSG_CALL_FUNCTION, tgt)) {
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 20b73c025a4..7c1342618a3 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1636,6 +1636,24 @@ void __devinit smp_mpic_setup_cpu(int cpu)
1636{ 1636{
1637 mpic_setup_this_cpu(); 1637 mpic_setup_this_cpu();
1638} 1638}
1639
1640void mpic_reset_core(int cpu)
1641{
1642 struct mpic *mpic = mpic_primary;
1643 u32 pir;
1644 int cpuid = get_hard_smp_processor_id(cpu);
1645
1646 /* Set target bit for core reset */
1647 pir = mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
1648 pir |= (1 << cpuid);
1649 mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
1650 mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
1651
1652 /* Restore target bit after reset complete */
1653 pir &= ~(1 << cpuid);
1654 mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
1655 mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
1656}
1639#endif /* CONFIG_SMP */ 1657#endif /* CONFIG_SMP */
1640 1658
1641#ifdef CONFIG_PM 1659#ifdef CONFIG_PM
diff --git a/arch/powerpc/sysdev/mpic.h b/arch/powerpc/sysdev/mpic.h
index eff433c322a..e4a6df77b8d 100644
--- a/arch/powerpc/sysdev/mpic.h
+++ b/arch/powerpc/sysdev/mpic.h
@@ -37,5 +37,6 @@ static inline int mpic_pasemi_msi_init(struct mpic *mpic)
37extern int mpic_set_irq_type(unsigned int virq, unsigned int flow_type); 37extern int mpic_set_irq_type(unsigned int virq, unsigned int flow_type);
38extern void mpic_set_vector(unsigned int virq, unsigned int vector); 38extern void mpic_set_vector(unsigned int virq, unsigned int vector);
39extern int mpic_set_affinity(unsigned int irq, const struct cpumask *cpumask); 39extern int mpic_set_affinity(unsigned int irq, const struct cpumask *cpumask);
40extern void mpic_reset_core(int cpu);
40 41
41#endif /* _POWERPC_SYSDEV_MPIC_H */ 42#endif /* _POWERPC_SYSDEV_MPIC_H */
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 8bad7d5f32a..0554445200b 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -155,6 +155,9 @@ static int do_spu_cmd(void);
155#ifdef CONFIG_44x 155#ifdef CONFIG_44x
156static void dump_tlb_44x(void); 156static void dump_tlb_44x(void);
157#endif 157#endif
158#ifdef CONFIG_PPC_BOOK3E
159static void dump_tlb_book3e(void);
160#endif
158 161
159static int xmon_no_auto_backtrace; 162static int xmon_no_auto_backtrace;
160 163
@@ -888,6 +891,11 @@ cmds(struct pt_regs *excp)
888 dump_tlb_44x(); 891 dump_tlb_44x();
889 break; 892 break;
890#endif 893#endif
894#ifdef CONFIG_PPC_BOOK3E
895 case 'u':
896 dump_tlb_book3e();
897 break;
898#endif
891 default: 899 default:
892 printf("Unrecognized command: "); 900 printf("Unrecognized command: ");
893 do { 901 do {
@@ -2701,6 +2709,150 @@ static void dump_tlb_44x(void)
2701} 2709}
2702#endif /* CONFIG_44x */ 2710#endif /* CONFIG_44x */
2703 2711
2712#ifdef CONFIG_PPC_BOOK3E
2713static void dump_tlb_book3e(void)
2714{
2715 u32 mmucfg, pidmask, lpidmask;
2716 u64 ramask;
2717 int i, tlb, ntlbs, pidsz, lpidsz, rasz, lrat = 0;
2718 int mmu_version;
2719 static const char *pgsz_names[] = {
2720 " 1K",
2721 " 2K",
2722 " 4K",
2723 " 8K",
2724 " 16K",
2725 " 32K",
2726 " 64K",
2727 "128K",
2728 "256K",
2729 "512K",
2730 " 1M",
2731 " 2M",
2732 " 4M",
2733 " 8M",
2734 " 16M",
2735 " 32M",
2736 " 64M",
2737 "128M",
2738 "256M",
2739 "512M",
2740 " 1G",
2741 " 2G",
2742 " 4G",
2743 " 8G",
2744 " 16G",
2745 " 32G",
2746 " 64G",
2747 "128G",
2748 "256G",
2749 "512G",
2750 " 1T",
2751 " 2T",
2752 };
2753
2754 /* Gather some infos about the MMU */
2755 mmucfg = mfspr(SPRN_MMUCFG);
2756 mmu_version = (mmucfg & 3) + 1;
2757 ntlbs = ((mmucfg >> 2) & 3) + 1;
2758 pidsz = ((mmucfg >> 6) & 0x1f) + 1;
2759 lpidsz = (mmucfg >> 24) & 0xf;
2760 rasz = (mmucfg >> 16) & 0x7f;
2761 if ((mmu_version > 1) && (mmucfg & 0x10000))
2762 lrat = 1;
2763 printf("Book3E MMU MAV=%d.0,%d TLBs,%d-bit PID,%d-bit LPID,%d-bit RA\n",
2764 mmu_version, ntlbs, pidsz, lpidsz, rasz);
2765 pidmask = (1ul << pidsz) - 1;
2766 lpidmask = (1ul << lpidsz) - 1;
2767 ramask = (1ull << rasz) - 1;
2768
2769 for (tlb = 0; tlb < ntlbs; tlb++) {
2770 u32 tlbcfg;
2771 int nent, assoc, new_cc = 1;
2772 printf("TLB %d:\n------\n", tlb);
2773 switch(tlb) {
2774 case 0:
2775 tlbcfg = mfspr(SPRN_TLB0CFG);
2776 break;
2777 case 1:
2778 tlbcfg = mfspr(SPRN_TLB1CFG);
2779 break;
2780 case 2:
2781 tlbcfg = mfspr(SPRN_TLB2CFG);
2782 break;
2783 case 3:
2784 tlbcfg = mfspr(SPRN_TLB3CFG);
2785 break;
2786 default:
2787 printf("Unsupported TLB number !\n");
2788 continue;
2789 }
2790 nent = tlbcfg & 0xfff;
2791 assoc = (tlbcfg >> 24) & 0xff;
2792 for (i = 0; i < nent; i++) {
2793 u32 mas0 = MAS0_TLBSEL(tlb);
2794 u32 mas1 = MAS1_TSIZE(BOOK3E_PAGESZ_4K);
2795 u64 mas2 = 0;
2796 u64 mas7_mas3;
2797 int esel = i, cc = i;
2798
2799 if (assoc != 0) {
2800 cc = i / assoc;
2801 esel = i % assoc;
2802 mas2 = cc * 0x1000;
2803 }
2804
2805 mas0 |= MAS0_ESEL(esel);
2806 mtspr(SPRN_MAS0, mas0);
2807 mtspr(SPRN_MAS1, mas1);
2808 mtspr(SPRN_MAS2, mas2);
2809 asm volatile("tlbre 0,0,0" : : : "memory");
2810 mas1 = mfspr(SPRN_MAS1);
2811 mas2 = mfspr(SPRN_MAS2);
2812 mas7_mas3 = mfspr(SPRN_MAS7_MAS3);
2813 if (assoc && (i % assoc) == 0)
2814 new_cc = 1;
2815 if (!(mas1 & MAS1_VALID))
2816 continue;
2817 if (assoc == 0)
2818 printf("%04x- ", i);
2819 else if (new_cc)
2820 printf("%04x-%c", cc, 'A' + esel);
2821 else
2822 printf(" |%c", 'A' + esel);
2823 new_cc = 0;
2824 printf(" %016llx %04x %s %c%c AS%c",
2825 mas2 & ~0x3ffull,
2826 (mas1 >> 16) & 0x3fff,
2827 pgsz_names[(mas1 >> 7) & 0x1f],
2828 mas1 & MAS1_IND ? 'I' : ' ',
2829 mas1 & MAS1_IPROT ? 'P' : ' ',
2830 mas1 & MAS1_TS ? '1' : '0');
2831 printf(" %c%c%c%c%c%c%c",
2832 mas2 & MAS2_X0 ? 'a' : ' ',
2833 mas2 & MAS2_X1 ? 'v' : ' ',
2834 mas2 & MAS2_W ? 'w' : ' ',
2835 mas2 & MAS2_I ? 'i' : ' ',
2836 mas2 & MAS2_M ? 'm' : ' ',
2837 mas2 & MAS2_G ? 'g' : ' ',
2838 mas2 & MAS2_E ? 'e' : ' ');
2839 printf(" %016llx", mas7_mas3 & ramask & ~0x7ffull);
2840 if (mas1 & MAS1_IND)
2841 printf(" %s\n",
2842 pgsz_names[(mas7_mas3 >> 1) & 0x1f]);
2843 else
2844 printf(" U%c%c%c S%c%c%c\n",
2845 mas7_mas3 & MAS3_UX ? 'x' : ' ',
2846 mas7_mas3 & MAS3_UW ? 'w' : ' ',
2847 mas7_mas3 & MAS3_UR ? 'r' : ' ',
2848 mas7_mas3 & MAS3_SX ? 'x' : ' ',
2849 mas7_mas3 & MAS3_SW ? 'w' : ' ',
2850 mas7_mas3 & MAS3_SR ? 'r' : ' ');
2851 }
2852 }
2853}
2854#endif /* CONFIG_PPC_BOOK3E */
2855
2704static void xmon_init(int enable) 2856static void xmon_init(int enable)
2705{ 2857{
2706#ifdef CONFIG_PPC_ISERIES 2858#ifdef CONFIG_PPC_ISERIES