aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2013-01-29 04:48:30 -0500
committerJiri Kosina <jkosina@suse.cz>2013-01-29 04:48:30 -0500
commit617677295b53a40d0e54aac4cbbc216ffbc755dd (patch)
tree51b9e87213243ed5efff252c8e8d8fec4eebc588 /arch/powerpc
parent5c8d1b68e01a144813e38795fe6dbe7ebb506131 (diff)
parent6abb7c25775b7fb2225ad0508236d63ca710e65f (diff)
Merge branch 'master' into for-next
Conflicts: drivers/devfreq/exynos4_bus.c Sync with Linus' tree to be able to apply patches that are against newer code (mvneta).
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/Kconfig2
-rw-r--r--arch/powerpc/Makefile2
-rw-r--r--arch/powerpc/boot/dts/a3m071.dts144
-rw-r--r--arch/powerpc/boot/dts/fsl/p5020si-post.dtsi1
-rw-r--r--arch/powerpc/boot/dts/fsl/p5020si-pre.dtsi6
-rw-r--r--arch/powerpc/boot/dts/fsl/qoriq-raid1.0-0.dtsi85
-rw-r--r--arch/powerpc/boot/dts/mpc5200b.dtsi6
-rw-r--r--arch/powerpc/boot/dts/o2d.dtsi6
-rw-r--r--arch/powerpc/boot/dts/pcm030.dts7
-rw-r--r--arch/powerpc/configs/pseries_defconfig2
-rw-r--r--arch/powerpc/include/asm/Kbuild2
-rw-r--r--arch/powerpc/include/asm/bitops.h75
-rw-r--r--arch/powerpc/include/asm/cputable.h12
-rw-r--r--arch/powerpc/include/asm/cputime.h2
-rw-r--r--arch/powerpc/include/asm/dbell.h2
-rw-r--r--arch/powerpc/include/asm/dma-mapping.h1
-rw-r--r--arch/powerpc/include/asm/eeh.h6
-rw-r--r--arch/powerpc/include/asm/epapr_hcalls.h83
-rw-r--r--arch/powerpc/include/asm/exception-64s.h97
-rw-r--r--arch/powerpc/include/asm/firmware.h4
-rw-r--r--arch/powerpc/include/asm/fsl_gtm.h2
-rw-r--r--arch/powerpc/include/asm/fsl_guts.h4
-rw-r--r--arch/powerpc/include/asm/fsl_hcalls.h36
-rw-r--r--arch/powerpc/include/asm/hvcall.h23
-rw-r--r--arch/powerpc/include/asm/immap_qe.h2
-rw-r--r--arch/powerpc/include/asm/io-workarounds.h4
-rw-r--r--arch/powerpc/include/asm/kvm_asm.h1
-rw-r--r--arch/powerpc/include/asm/kvm_book3s.h12
-rw-r--r--arch/powerpc/include/asm/kvm_book3s_64.h33
-rw-r--r--arch/powerpc/include/asm/kvm_booke_hv_asm.h29
-rw-r--r--arch/powerpc/include/asm/kvm_host.h68
-rw-r--r--arch/powerpc/include/asm/kvm_para.h15
-rw-r--r--arch/powerpc/include/asm/kvm_ppc.h87
-rw-r--r--arch/powerpc/include/asm/machdep.h39
-rw-r--r--arch/powerpc/include/asm/mmu-book3e.h2
-rw-r--r--arch/powerpc/include/asm/mmu-hash64.h10
-rw-r--r--arch/powerpc/include/asm/mmu.h1
-rw-r--r--arch/powerpc/include/asm/pSeries_reconfig.h47
-rw-r--r--arch/powerpc/include/asm/parport.h2
-rw-r--r--arch/powerpc/include/asm/ppc-opcode.h9
-rw-r--r--arch/powerpc/include/asm/prom.h16
-rw-r--r--arch/powerpc/include/asm/qe.h2
-rw-r--r--arch/powerpc/include/asm/qe_ic.h2
-rw-r--r--arch/powerpc/include/asm/reg.h4
-rw-r--r--arch/powerpc/include/asm/reg_booke.h7
-rw-r--r--arch/powerpc/include/asm/rtas.h5
-rw-r--r--arch/powerpc/include/asm/setup.h29
-rw-r--r--arch/powerpc/include/asm/signal.h2
-rw-r--r--arch/powerpc/include/asm/smp.h12
-rw-r--r--arch/powerpc/include/asm/syscalls.h9
-rw-r--r--arch/powerpc/include/asm/systbl.h3
-rw-r--r--arch/powerpc/include/asm/ucc.h2
-rw-r--r--arch/powerpc/include/asm/ucc_fast.h2
-rw-r--r--arch/powerpc/include/asm/ucc_slow.h2
-rw-r--r--arch/powerpc/include/asm/udbg.h1
-rw-r--r--arch/powerpc/include/asm/unistd.h8
-rw-r--r--arch/powerpc/include/asm/vio.h2
-rw-r--r--arch/powerpc/include/uapi/asm/Kbuild1
-rw-r--r--arch/powerpc/include/uapi/asm/epapr_hcalls.h98
-rw-r--r--arch/powerpc/include/uapi/asm/ioctls.h3
-rw-r--r--arch/powerpc/include/uapi/asm/kvm.h86
-rw-r--r--arch/powerpc/include/uapi/asm/kvm_para.h7
-rw-r--r--arch/powerpc/include/uapi/asm/setup.h31
-rw-r--r--arch/powerpc/include/uapi/asm/signal.h6
-rw-r--r--arch/powerpc/include/uapi/asm/socket.h1
-rw-r--r--arch/powerpc/include/uapi/asm/unistd.h1
-rw-r--r--arch/powerpc/kernel/Makefile2
-rw-r--r--arch/powerpc/kernel/asm-offsets.c4
-rw-r--r--arch/powerpc/kernel/cpu_setup_power.S (renamed from arch/powerpc/kernel/cpu_setup_power7.S)32
-rw-r--r--arch/powerpc/kernel/cputable.c38
-rw-r--r--arch/powerpc/kernel/entry_32.S7
-rw-r--r--arch/powerpc/kernel/entry_64.S23
-rw-r--r--arch/powerpc/kernel/epapr_hcalls.S28
-rw-r--r--arch/powerpc/kernel/epapr_paravirt.c11
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S308
-rw-r--r--arch/powerpc/kernel/head_64.S6
-rw-r--r--arch/powerpc/kernel/idle.c3
-rw-r--r--arch/powerpc/kernel/io-workarounds.c9
-rw-r--r--arch/powerpc/kernel/iommu.c16
-rw-r--r--arch/powerpc/kernel/isa-bridge.c12
-rw-r--r--arch/powerpc/kernel/kgdb.c5
-rw-r--r--arch/powerpc/kernel/kvm.c2
-rw-r--r--arch/powerpc/kernel/machine_kexec.c14
-rw-r--r--arch/powerpc/kernel/machine_kexec_64.c8
-rw-r--r--arch/powerpc/kernel/of_platform.c2
-rw-r--r--arch/powerpc/kernel/pci-common.c32
-rw-r--r--arch/powerpc/kernel/pci_32.c4
-rw-r--r--arch/powerpc/kernel/pci_64.c10
-rw-r--r--arch/powerpc/kernel/pci_dn.c4
-rw-r--r--arch/powerpc/kernel/pci_of_scan.c12
-rw-r--r--arch/powerpc/kernel/ppc_ksyms.c5
-rw-r--r--arch/powerpc/kernel/process.c64
-rw-r--r--arch/powerpc/kernel/prom.c7
-rw-r--r--arch/powerpc/kernel/prom_init.c11
-rw-r--r--arch/powerpc/kernel/ptrace.c90
-rw-r--r--arch/powerpc/kernel/rtas.c1
-rw-r--r--arch/powerpc/kernel/rtas_flash.c4
-rw-r--r--arch/powerpc/kernel/rtas_pci.c4
-rw-r--r--arch/powerpc/kernel/setup_64.c5
-rw-r--r--arch/powerpc/kernel/signal.c4
-rw-r--r--arch/powerpc/kernel/smp-tbsync.c8
-rw-r--r--arch/powerpc/kernel/smp.c54
-rw-r--r--arch/powerpc/kernel/sys_ppc32.c17
-rw-r--r--arch/powerpc/kernel/sysfs.c4
-rw-r--r--arch/powerpc/kernel/time.c34
-rw-r--r--arch/powerpc/kernel/udbg.c23
-rw-r--r--arch/powerpc/kernel/uprobes.c6
-rw-r--r--arch/powerpc/kernel/vio.c4
-rw-r--r--arch/powerpc/kvm/44x.c1
-rw-r--r--arch/powerpc/kvm/44x_emulate.c112
-rw-r--r--arch/powerpc/kvm/Kconfig4
-rw-r--r--arch/powerpc/kvm/Makefile5
-rw-r--r--arch/powerpc/kvm/book3s.c125
-rw-r--r--arch/powerpc/kvm/book3s_32_mmu_host.c3
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_host.c3
-rw-r--r--arch/powerpc/kvm/book3s_64_mmu_hv.c474
-rw-r--r--arch/powerpc/kvm/book3s_emulate.c16
-rw-r--r--arch/powerpc/kvm/book3s_exports.c3
-rw-r--r--arch/powerpc/kvm/book3s_hv.c655
-rw-r--r--arch/powerpc/kvm/book3s_hv_builtin.c4
-rw-r--r--arch/powerpc/kvm/book3s_hv_ras.c148
-rw-r--r--arch/powerpc/kvm/book3s_hv_rm_mmu.c143
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S142
-rw-r--r--arch/powerpc/kvm/book3s_mmu_hpte.c5
-rw-r--r--arch/powerpc/kvm/book3s_pr.c294
-rw-r--r--arch/powerpc/kvm/book3s_rmhandlers.S18
-rw-r--r--arch/powerpc/kvm/booke.c346
-rw-r--r--arch/powerpc/kvm/booke.h1
-rw-r--r--arch/powerpc/kvm/booke_emulate.c36
-rw-r--r--arch/powerpc/kvm/bookehv_interrupts.S145
-rw-r--r--arch/powerpc/kvm/e500.h11
-rw-r--r--arch/powerpc/kvm/e500_emulate.c14
-rw-r--r--arch/powerpc/kvm/e500_tlb.c132
-rw-r--r--arch/powerpc/kvm/emulate.c223
-rw-r--r--arch/powerpc/kvm/powerpc.c187
-rw-r--r--arch/powerpc/kvm/trace.h200
-rw-r--r--arch/powerpc/mm/fault.c27
-rw-r--r--arch/powerpc/mm/numa.c12
-rw-r--r--arch/powerpc/mm/tlb_hash64.c4
-rw-r--r--arch/powerpc/mm/tlb_nohash_low.S15
-rw-r--r--arch/powerpc/net/bpf_jit.h6
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c25
-rw-r--r--arch/powerpc/oprofile/op_model_power4.c2
-rw-r--r--arch/powerpc/perf/power7-pmu.c17
-rw-r--r--arch/powerpc/platforms/40x/ppc40x_simple.c3
-rw-r--r--arch/powerpc/platforms/44x/currituck.c2
-rw-r--r--arch/powerpc/platforms/44x/virtex_ml510.c2
-rw-r--r--arch/powerpc/platforms/512x/Kconfig1
-rw-r--r--arch/powerpc/platforms/512x/mpc5121_ads.c3
-rw-r--r--arch/powerpc/platforms/512x/mpc512x.h11
-rw-r--r--arch/powerpc/platforms/512x/mpc512x_shared.c25
-rw-r--r--arch/powerpc/platforms/52xx/lite5200.c2
-rw-r--r--arch/powerpc/platforms/52xx/mpc5200_simple.c1
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_gpt.c6
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c24
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_pic.c9
-rw-r--r--arch/powerpc/platforms/82xx/ep8248e.c2
-rw-r--r--arch/powerpc/platforms/82xx/pq2ads-pci-pic.c8
-rw-r--r--arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c9
-rw-r--r--arch/powerpc/platforms/83xx/mpc832x_mds.c2
-rw-r--r--arch/powerpc/platforms/83xx/mpc836x_mds.c2
-rw-r--r--arch/powerpc/platforms/83xx/mpc836x_rdk.c2
-rw-r--r--arch/powerpc/platforms/83xx/mpc837x_rdb.c2
-rw-r--r--arch/powerpc/platforms/85xx/corenet_ds.c2
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_cds.c2
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_mds.c2
-rw-r--r--arch/powerpc/platforms/85xx/p1022_ds.c8
-rw-r--r--arch/powerpc/platforms/85xx/smp.c49
-rw-r--r--arch/powerpc/platforms/85xx/tqm85xx.c2
-rw-r--r--arch/powerpc/platforms/86xx/gef_ppc9a.c2
-rw-r--r--arch/powerpc/platforms/86xx/gef_sbc310.c2
-rw-r--r--arch/powerpc/platforms/86xx/gef_sbc610.c2
-rw-r--r--arch/powerpc/platforms/86xx/mpc8610_hpcd.c2
-rw-r--r--arch/powerpc/platforms/Kconfig1
-rw-r--r--arch/powerpc/platforms/cell/celleb_pci.c4
-rw-r--r--arch/powerpc/platforms/cell/setup.c2
-rw-r--r--arch/powerpc/platforms/cell/smp.c6
-rw-r--r--arch/powerpc/platforms/cell/spufs/sched.c2
-rw-r--r--arch/powerpc/platforms/cell/spufs/syscalls.c2
-rw-r--r--arch/powerpc/platforms/chrp/pci.c2
-rw-r--r--arch/powerpc/platforms/chrp/smp.c4
-rw-r--r--arch/powerpc/platforms/fsl_uli1575.c20
-rw-r--r--arch/powerpc/platforms/maple/pci.c4
-rw-r--r--arch/powerpc/platforms/pasemi/cpufreq.c7
-rw-r--r--arch/powerpc/platforms/pasemi/gpio_mdio.c2
-rw-r--r--arch/powerpc/platforms/pasemi/pasemi.h4
-rw-r--r--arch/powerpc/platforms/pasemi/setup.c4
-rw-r--r--arch/powerpc/platforms/powermac/cpufreq_32.c5
-rw-r--r--arch/powerpc/platforms/powermac/pci.c6
-rw-r--r--arch/powerpc/platforms/powermac/pfunc_core.c2
-rw-r--r--arch/powerpc/platforms/powermac/smp.c8
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c73
-rw-r--r--arch/powerpc/platforms/powernv/pci-p5ioc2.c4
-rw-r--r--arch/powerpc/platforms/powernv/pci.c11
-rw-r--r--arch/powerpc/platforms/powernv/smp.c2
-rw-r--r--arch/powerpc/platforms/ps3/os-area.c6
-rw-r--r--arch/powerpc/platforms/ps3/repository.c2
-rw-r--r--arch/powerpc/platforms/pseries/dlpar.c34
-rw-r--r--arch/powerpc/platforms/pseries/eeh_dev.c4
-rw-r--r--arch/powerpc/platforms/pseries/eeh_pe.c4
-rw-r--r--arch/powerpc/platforms/pseries/firmware.c1
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-cpu.c8
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-memory.c60
-rw-r--r--arch/powerpc/platforms/pseries/iommu.c10
-rw-r--r--arch/powerpc/platforms/pseries/mobility.c4
-rw-r--r--arch/powerpc/platforms/pseries/msi.c3
-rw-r--r--arch/powerpc/platforms/pseries/pci_dlpar.c2
-rw-r--r--arch/powerpc/platforms/pseries/plpar_wrappers.h31
-rw-r--r--arch/powerpc/platforms/pseries/processor_idle.c4
-rw-r--r--arch/powerpc/platforms/pseries/reconfig.c122
-rw-r--r--arch/powerpc/platforms/pseries/setup.c77
-rw-r--r--arch/powerpc/platforms/pseries/smp.c7
-rw-r--r--arch/powerpc/platforms/wsp/scom_smp.c3
-rw-r--r--arch/powerpc/platforms/wsp/smp.c4
-rw-r--r--arch/powerpc/platforms/wsp/wsp.h2
-rw-r--r--arch/powerpc/platforms/wsp/wsp_pci.c2
-rw-r--r--arch/powerpc/sysdev/bestcomm/bestcomm.c7
-rw-r--r--arch/powerpc/sysdev/fsl_85xx_l2ctlr.c6
-rw-r--r--arch/powerpc/sysdev/fsl_gtm.c2
-rw-r--r--arch/powerpc/sysdev/fsl_ifc.c4
-rw-r--r--arch/powerpc/sysdev/fsl_lbc.c6
-rw-r--r--arch/powerpc/sysdev/fsl_msi.c16
-rw-r--r--arch/powerpc/sysdev/fsl_pci.c43
-rw-r--r--arch/powerpc/sysdev/fsl_rio.c2
-rw-r--r--arch/powerpc/sysdev/fsl_soc.c2
-rw-r--r--arch/powerpc/sysdev/mpic.c2
-rw-r--r--arch/powerpc/sysdev/mpic_msgr.c2
-rw-r--r--arch/powerpc/sysdev/mv64x60_pci.c2
-rw-r--r--arch/powerpc/sysdev/pmi.c13
-rw-r--r--arch/powerpc/sysdev/ppc4xx_msi.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe_ic.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe_ic.h2
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe_io.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/ucc.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/ucc_fast.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/ucc_slow.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/usb.c2
-rw-r--r--arch/powerpc/sysdev/scom.c2
-rw-r--r--arch/powerpc/xmon/Makefile2
-rw-r--r--arch/powerpc/xmon/nonstdio.c53
-rw-r--r--arch/powerpc/xmon/nonstdio.h6
-rw-r--r--arch/powerpc/xmon/start.c34
-rw-r--r--arch/powerpc/xmon/xmon.c26
244 files changed, 4892 insertions, 1918 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index a902a5c1c76a..17903f1f356b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -141,9 +141,9 @@ config PPC
141 select GENERIC_CLOCKEVENTS 141 select GENERIC_CLOCKEVENTS
142 select GENERIC_STRNCPY_FROM_USER 142 select GENERIC_STRNCPY_FROM_USER
143 select GENERIC_STRNLEN_USER 143 select GENERIC_STRNLEN_USER
144 select GENERIC_KERNEL_THREAD
145 select HAVE_MOD_ARCH_SPECIFIC 144 select HAVE_MOD_ARCH_SPECIFIC
146 select MODULES_USE_ELF_RELA 145 select MODULES_USE_ELF_RELA
146 select CLONE_BACKWARDS
147 147
148config EARLY_PRINTK 148config EARLY_PRINTK
149 bool 149 bool
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 159e94f4b22a..b639852116fa 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -181,7 +181,7 @@ $(BOOT_TARGETS2): vmlinux
181bootwrapper_install: 181bootwrapper_install:
182 $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) 182 $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
183 183
184%.dtb: 184%.dtb: scripts
185 $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) 185 $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
186 186
187define archhelp 187define archhelp
diff --git a/arch/powerpc/boot/dts/a3m071.dts b/arch/powerpc/boot/dts/a3m071.dts
new file mode 100644
index 000000000000..877a28cb77e4
--- /dev/null
+++ b/arch/powerpc/boot/dts/a3m071.dts
@@ -0,0 +1,144 @@
1/*
2 * a3m071 board Device Tree Source
3 *
4 * Copyright 2012 Stefan Roese <sr@denx.de>
5 *
6 * Copyright (C) 2011 DENX Software Engineering GmbH
7 * Heiko Schocher <hs@denx.de>
8 *
9 * Copyright (C) 2007 Semihalf
10 * Marian Balakowicz <m8@semihalf.com>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
18/include/ "mpc5200b.dtsi"
19
20/ {
21 model = "anonymous,a3m071";
22 compatible = "anonymous,a3m071";
23
24 soc5200@f0000000 {
25 #address-cells = <1>;
26 #size-cells = <1>;
27 compatible = "fsl,mpc5200b-immr";
28 ranges = <0 0xf0000000 0x0000c000>;
29 reg = <0xf0000000 0x00000100>;
30 bus-frequency = <0>; /* From boot loader */
31 system-frequency = <0>; /* From boot loader */
32
33 timer@600 {
34 fsl,has-wdt;
35 };
36
37 spi@f00 {
38 status = "disabled";
39 };
40
41 usb: usb@1000 {
42 status = "disabled";
43 };
44
45 psc@2000 {
46 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
47 reg = <0x2000 0x100>;
48 interrupts = <2 1 0>;
49 };
50
51 psc@2200 {
52 status = "disabled";
53 };
54
55 psc@2400 {
56 status = "disabled";
57 };
58
59 psc@2600 {
60 status = "disabled";
61 };
62
63 psc@2800 {
64 status = "disabled";
65 };
66
67 psc@2c00 { // PSC6
68 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
69 reg = <0x2c00 0x100>;
70 interrupts = <2 4 0>;
71 };
72
73 ethernet@3000 {
74 phy-handle = <&phy0>;
75 };
76
77 mdio@3000 {
78 phy0: ethernet-phy@3 {
79 reg = <0x03>;
80 };
81 };
82
83 ata@3a00 {
84 status = "disabled";
85 };
86
87 i2c@3d00 {
88 status = "disabled";
89 };
90
91 i2c@3d40 {
92 status = "disabled";
93 };
94 };
95
96 localbus {
97 compatible = "fsl,mpc5200b-lpb","simple-bus";
98 #address-cells = <2>;
99 #size-cells = <1>;
100 ranges = <0 0 0xfc000000 0x02000000
101 3 0 0xe9000000 0x00080000
102 5 0 0xe8000000 0x00010000>;
103
104 flash@0,0 {
105 #address-cells = <1>;
106 #size-cells = <1>;
107 reg = <0 0x0 0x02000000>;
108 compatible = "cfi-flash";
109 bank-width = <2>;
110 partition@0x0 {
111 label = "u-boot";
112 reg = <0x00000000 0x00040000>;
113 read-only;
114 };
115 partition@0x00040000 {
116 label = "env";
117 reg = <0x00040000 0x00020000>;
118 };
119 partition@0x00060000 {
120 label = "dtb";
121 reg = <0x00060000 0x00020000>;
122 };
123 partition@0x00080000 {
124 label = "kernel";
125 reg = <0x00080000 0x00500000>;
126 };
127 partition@0x00580000 {
128 label = "root";
129 reg = <0x00580000 0x00A80000>;
130 };
131 };
132
133 fpga@3,0 {
134 compatible = "anonymous,a3m071-fpga";
135 reg = <3 0x0 0x00080000
136 5 0x0 0x00010000>;
137 interrupts = <0 0 3>; /* level low */
138 };
139 };
140
141 pci@f0000d00 {
142 status = "disabled";
143 };
144};
diff --git a/arch/powerpc/boot/dts/fsl/p5020si-post.dtsi b/arch/powerpc/boot/dts/fsl/p5020si-post.dtsi
index 64b6abea8464..5d7205b7bb05 100644
--- a/arch/powerpc/boot/dts/fsl/p5020si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p5020si-post.dtsi
@@ -354,4 +354,5 @@
354/include/ "qoriq-sata2-0.dtsi" 354/include/ "qoriq-sata2-0.dtsi"
355/include/ "qoriq-sata2-1.dtsi" 355/include/ "qoriq-sata2-1.dtsi"
356/include/ "qoriq-sec4.2-0.dtsi" 356/include/ "qoriq-sec4.2-0.dtsi"
357/include/ "qoriq-raid1.0-0.dtsi"
357}; 358};
diff --git a/arch/powerpc/boot/dts/fsl/p5020si-pre.dtsi b/arch/powerpc/boot/dts/fsl/p5020si-pre.dtsi
index 0a198b0a77e5..8df47fc45ab5 100644
--- a/arch/powerpc/boot/dts/fsl/p5020si-pre.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p5020si-pre.dtsi
@@ -73,6 +73,12 @@
73 rtic_c = &rtic_c; 73 rtic_c = &rtic_c;
74 rtic_d = &rtic_d; 74 rtic_d = &rtic_d;
75 sec_mon = &sec_mon; 75 sec_mon = &sec_mon;
76
77 raideng = &raideng;
78 raideng_jr0 = &raideng_jr0;
79 raideng_jr1 = &raideng_jr1;
80 raideng_jr2 = &raideng_jr2;
81 raideng_jr3 = &raideng_jr3;
76 }; 82 };
77 83
78 cpus { 84 cpus {
diff --git a/arch/powerpc/boot/dts/fsl/qoriq-raid1.0-0.dtsi b/arch/powerpc/boot/dts/fsl/qoriq-raid1.0-0.dtsi
new file mode 100644
index 000000000000..8d2e8aa6cf8a
--- /dev/null
+++ b/arch/powerpc/boot/dts/fsl/qoriq-raid1.0-0.dtsi
@@ -0,0 +1,85 @@
1/*
2 * QorIQ RAID 1.0 device tree stub [ controller @ offset 0x320000 ]
3 *
4 * Copyright 2012 Freescale Semiconductor Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Freescale Semiconductor nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 *
18 * ALTERNATIVELY, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") as published by the Free Software
20 * Foundation, either version 2 of that License or (at your option) any
21 * later version.
22 *
23 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35raideng: raideng@320000 {
36 compatible = "fsl,raideng-v1.0";
37 #address-cells = <1>;
38 #size-cells = <1>;
39 reg = <0x320000 0x10000>;
40 ranges = <0 0x320000 0x10000>;
41
42 raideng_jq0@1000 {
43 compatible = "fsl,raideng-v1.0-job-queue";
44 #address-cells = <1>;
45 #size-cells = <1>;
46 reg = <0x1000 0x1000>;
47 ranges = <0x0 0x1000 0x1000>;
48
49 raideng_jr0: jr@0 {
50 compatible = "fsl,raideng-v1.0-job-ring", "fsl,raideng-v1.0-hp-ring";
51 reg = <0x0 0x400>;
52 interrupts = <139 2 0 0>;
53 interrupt-parent = <&mpic>;
54 };
55
56 raideng_jr1: jr@400 {
57 compatible = "fsl,raideng-v1.0-job-ring", "fsl,raideng-v1.0-lp-ring";
58 reg = <0x400 0x400>;
59 interrupts = <140 2 0 0>;
60 interrupt-parent = <&mpic>;
61 };
62 };
63
64 raideng_jq1@2000 {
65 compatible = "fsl,raideng-v1.0-job-queue";
66 #address-cells = <1>;
67 #size-cells = <1>;
68 reg = <0x2000 0x1000>;
69 ranges = <0x0 0x2000 0x1000>;
70
71 raideng_jr2: jr@0 {
72 compatible = "fsl,raideng-v1.0-job-ring", "fsl,raideng-v1.0-hp-ring";
73 reg = <0x0 0x400>;
74 interrupts = <141 2 0 0>;
75 interrupt-parent = <&mpic>;
76 };
77
78 raideng_jr3: jr@400 {
79 compatible = "fsl,raideng-v1.0-job-ring", "fsl,raideng-v1.0-lp-ring";
80 reg = <0x400 0x400>;
81 interrupts = <142 2 0 0>;
82 interrupt-parent = <&mpic>;
83 };
84 };
85};
diff --git a/arch/powerpc/boot/dts/mpc5200b.dtsi b/arch/powerpc/boot/dts/mpc5200b.dtsi
index 7ab286ab5300..39ed65a44c5f 100644
--- a/arch/powerpc/boot/dts/mpc5200b.dtsi
+++ b/arch/powerpc/boot/dts/mpc5200b.dtsi
@@ -231,6 +231,12 @@
231 interrupts = <2 7 0>; 231 interrupts = <2 7 0>;
232 }; 232 };
233 233
234 sclpc@3c00 {
235 compatible = "fsl,mpc5200-lpbfifo";
236 reg = <0x3c00 0x60>;
237 interrupts = <2 23 0>;
238 };
239
234 i2c@3d00 { 240 i2c@3d00 {
235 #address-cells = <1>; 241 #address-cells = <1>;
236 #size-cells = <0>; 242 #size-cells = <0>;
diff --git a/arch/powerpc/boot/dts/o2d.dtsi b/arch/powerpc/boot/dts/o2d.dtsi
index 3444eb8f0ade..24f668039295 100644
--- a/arch/powerpc/boot/dts/o2d.dtsi
+++ b/arch/powerpc/boot/dts/o2d.dtsi
@@ -86,12 +86,6 @@
86 reg = <0>; 86 reg = <0>;
87 }; 87 };
88 }; 88 };
89
90 sclpc@3c00 {
91 compatible = "fsl,mpc5200-lpbfifo";
92 reg = <0x3c00 0x60>;
93 interrupts = <3 23 0>;
94 };
95 }; 89 };
96 90
97 localbus { 91 localbus {
diff --git a/arch/powerpc/boot/dts/pcm030.dts b/arch/powerpc/boot/dts/pcm030.dts
index 9e354997eb7e..96512c058033 100644
--- a/arch/powerpc/boot/dts/pcm030.dts
+++ b/arch/powerpc/boot/dts/pcm030.dts
@@ -59,7 +59,7 @@
59 #gpio-cells = <2>; 59 #gpio-cells = <2>;
60 }; 60 };
61 61
62 psc@2000 { /* PSC1 in ac97 mode */ 62 audioplatform: psc@2000 { /* PSC1 in ac97 mode */
63 compatible = "mpc5200b-psc-ac97","fsl,mpc5200b-psc-ac97"; 63 compatible = "mpc5200b-psc-ac97","fsl,mpc5200b-psc-ac97";
64 cell-index = <0>; 64 cell-index = <0>;
65 }; 65 };
@@ -134,4 +134,9 @@
134 localbus { 134 localbus {
135 status = "disabled"; 135 status = "disabled";
136 }; 136 };
137
138 sound {
139 compatible = "phytec,pcm030-audio-fabric";
140 asoc-platform = <&audioplatform>;
141 };
137}; 142};
diff --git a/arch/powerpc/configs/pseries_defconfig b/arch/powerpc/configs/pseries_defconfig
index 1f710a32ffae..5b8e1e508270 100644
--- a/arch/powerpc/configs/pseries_defconfig
+++ b/arch/powerpc/configs/pseries_defconfig
@@ -2,7 +2,7 @@ CONFIG_PPC64=y
2CONFIG_ALTIVEC=y 2CONFIG_ALTIVEC=y
3CONFIG_VSX=y 3CONFIG_VSX=y
4CONFIG_SMP=y 4CONFIG_SMP=y
5CONFIG_NR_CPUS=1024 5CONFIG_NR_CPUS=2048
6CONFIG_EXPERIMENTAL=y 6CONFIG_EXPERIMENTAL=y
7CONFIG_SYSVIPC=y 7CONFIG_SYSVIPC=y
8CONFIG_POSIX_MQUEUE=y 8CONFIG_POSIX_MQUEUE=y
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index a4fe15e33c6f..650757c300db 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -1,4 +1,4 @@
1 1
2
3generic-y += clkdev.h 2generic-y += clkdev.h
4generic-y += rwsem.h 3generic-y += rwsem.h
4generic-y += trace_clock.h
diff --git a/arch/powerpc/include/asm/bitops.h b/arch/powerpc/include/asm/bitops.h
index dc2cf9c6d9e6..ef918a2328bb 100644
--- a/arch/powerpc/include/asm/bitops.h
+++ b/arch/powerpc/include/asm/bitops.h
@@ -52,8 +52,6 @@
52#define smp_mb__before_clear_bit() smp_mb() 52#define smp_mb__before_clear_bit() smp_mb()
53#define smp_mb__after_clear_bit() smp_mb() 53#define smp_mb__after_clear_bit() smp_mb()
54 54
55#define BITOP_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
56#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
57#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7) 55#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
58 56
59/* Macro for generating the ***_bits() functions */ 57/* Macro for generating the ***_bits() functions */
@@ -83,22 +81,22 @@ DEFINE_BITOP(change_bits, xor, "", "")
83 81
84static __inline__ void set_bit(int nr, volatile unsigned long *addr) 82static __inline__ void set_bit(int nr, volatile unsigned long *addr)
85{ 83{
86 set_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)); 84 set_bits(BIT_MASK(nr), addr + BIT_WORD(nr));
87} 85}
88 86
89static __inline__ void clear_bit(int nr, volatile unsigned long *addr) 87static __inline__ void clear_bit(int nr, volatile unsigned long *addr)
90{ 88{
91 clear_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)); 89 clear_bits(BIT_MASK(nr), addr + BIT_WORD(nr));
92} 90}
93 91
94static __inline__ void clear_bit_unlock(int nr, volatile unsigned long *addr) 92static __inline__ void clear_bit_unlock(int nr, volatile unsigned long *addr)
95{ 93{
96 clear_bits_unlock(BITOP_MASK(nr), addr + BITOP_WORD(nr)); 94 clear_bits_unlock(BIT_MASK(nr), addr + BIT_WORD(nr));
97} 95}
98 96
99static __inline__ void change_bit(int nr, volatile unsigned long *addr) 97static __inline__ void change_bit(int nr, volatile unsigned long *addr)
100{ 98{
101 change_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)); 99 change_bits(BIT_MASK(nr), addr + BIT_WORD(nr));
102} 100}
103 101
104/* Like DEFINE_BITOP(), with changes to the arguments to 'op' and the output 102/* Like DEFINE_BITOP(), with changes to the arguments to 'op' and the output
@@ -136,26 +134,26 @@ DEFINE_TESTOP(test_and_change_bits, xor, PPC_ATOMIC_ENTRY_BARRIER,
136static __inline__ int test_and_set_bit(unsigned long nr, 134static __inline__ int test_and_set_bit(unsigned long nr,
137 volatile unsigned long *addr) 135 volatile unsigned long *addr)
138{ 136{
139 return test_and_set_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)) != 0; 137 return test_and_set_bits(BIT_MASK(nr), addr + BIT_WORD(nr)) != 0;
140} 138}
141 139
142static __inline__ int test_and_set_bit_lock(unsigned long nr, 140static __inline__ int test_and_set_bit_lock(unsigned long nr,
143 volatile unsigned long *addr) 141 volatile unsigned long *addr)
144{ 142{
145 return test_and_set_bits_lock(BITOP_MASK(nr), 143 return test_and_set_bits_lock(BIT_MASK(nr),
146 addr + BITOP_WORD(nr)) != 0; 144 addr + BIT_WORD(nr)) != 0;
147} 145}
148 146
149static __inline__ int test_and_clear_bit(unsigned long nr, 147static __inline__ int test_and_clear_bit(unsigned long nr,
150 volatile unsigned long *addr) 148 volatile unsigned long *addr)
151{ 149{
152 return test_and_clear_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)) != 0; 150 return test_and_clear_bits(BIT_MASK(nr), addr + BIT_WORD(nr)) != 0;
153} 151}
154 152
155static __inline__ int test_and_change_bit(unsigned long nr, 153static __inline__ int test_and_change_bit(unsigned long nr,
156 volatile unsigned long *addr) 154 volatile unsigned long *addr)
157{ 155{
158 return test_and_change_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)) != 0; 156 return test_and_change_bits(BIT_MASK(nr), addr + BIT_WORD(nr)) != 0;
159} 157}
160 158
161#include <asm-generic/bitops/non-atomic.h> 159#include <asm-generic/bitops/non-atomic.h>
@@ -280,61 +278,8 @@ unsigned long __arch_hweight64(__u64 w);
280#include <asm-generic/bitops/find.h> 278#include <asm-generic/bitops/find.h>
281 279
282/* Little-endian versions */ 280/* Little-endian versions */
281#include <asm-generic/bitops/le.h>
283 282
284static __inline__ int test_bit_le(unsigned long nr,
285 __const__ void *addr)
286{
287 __const__ unsigned char *tmp = (__const__ unsigned char *) addr;
288 return (tmp[nr >> 3] >> (nr & 7)) & 1;
289}
290
291static inline void set_bit_le(int nr, void *addr)
292{
293 set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
294}
295
296static inline void clear_bit_le(int nr, void *addr)
297{
298 clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
299}
300
301static inline void __set_bit_le(int nr, void *addr)
302{
303 __set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
304}
305
306static inline void __clear_bit_le(int nr, void *addr)
307{
308 __clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
309}
310
311static inline int test_and_set_bit_le(int nr, void *addr)
312{
313 return test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
314}
315
316static inline int test_and_clear_bit_le(int nr, void *addr)
317{
318 return test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
319}
320
321static inline int __test_and_set_bit_le(int nr, void *addr)
322{
323 return __test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
324}
325
326static inline int __test_and_clear_bit_le(int nr, void *addr)
327{
328 return __test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
329}
330
331#define find_first_zero_bit_le(addr, size) \
332 find_next_zero_bit_le((addr), (size), 0)
333unsigned long find_next_zero_bit_le(const void *addr,
334 unsigned long size, unsigned long offset);
335
336unsigned long find_next_bit_le(const void *addr,
337 unsigned long size, unsigned long offset);
338/* Bitmap functions for the ext2 filesystem */ 283/* Bitmap functions for the ext2 filesystem */
339 284
340#include <asm-generic/bitops/ext2-atomic-setbit.h> 285#include <asm-generic/bitops/ext2-atomic-setbit.h>
diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cputable.h
index 21a0687b8c4d..76f81bd64f1d 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -401,6 +401,14 @@ extern const char *powerpc_base_platform;
401 CPU_FTR_DSCR | CPU_FTR_SAO | CPU_FTR_ASYM_SMT | \ 401 CPU_FTR_DSCR | CPU_FTR_SAO | CPU_FTR_ASYM_SMT | \
402 CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \ 402 CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
403 CPU_FTR_ICSWX | CPU_FTR_CFAR | CPU_FTR_HVMODE | CPU_FTR_VMX_COPY) 403 CPU_FTR_ICSWX | CPU_FTR_CFAR | CPU_FTR_HVMODE | CPU_FTR_VMX_COPY)
404#define CPU_FTRS_POWER8 (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \
405 CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | CPU_FTR_ARCH_206 |\
406 CPU_FTR_MMCRA | CPU_FTR_SMT | \
407 CPU_FTR_COHERENT_ICACHE | \
408 CPU_FTR_PURR | CPU_FTR_SPURR | CPU_FTR_REAL_LE | \
409 CPU_FTR_DSCR | CPU_FTR_SAO | \
410 CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
411 CPU_FTR_ICSWX | CPU_FTR_CFAR | CPU_FTR_HVMODE | CPU_FTR_VMX_COPY)
404#define CPU_FTRS_CELL (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ 412#define CPU_FTRS_CELL (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \
405 CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ 413 CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \
406 CPU_FTR_ALTIVEC_COMP | CPU_FTR_MMCRA | CPU_FTR_SMT | \ 414 CPU_FTR_ALTIVEC_COMP | CPU_FTR_MMCRA | CPU_FTR_SMT | \
@@ -421,8 +429,8 @@ extern const char *powerpc_base_platform;
421#define CPU_FTRS_POSSIBLE \ 429#define CPU_FTRS_POSSIBLE \
422 (CPU_FTRS_POWER3 | CPU_FTRS_RS64 | CPU_FTRS_POWER4 | \ 430 (CPU_FTRS_POWER3 | CPU_FTRS_RS64 | CPU_FTRS_POWER4 | \
423 CPU_FTRS_PPC970 | CPU_FTRS_POWER5 | CPU_FTRS_POWER6 | \ 431 CPU_FTRS_PPC970 | CPU_FTRS_POWER5 | CPU_FTRS_POWER6 | \
424 CPU_FTRS_POWER7 | CPU_FTRS_CELL | CPU_FTRS_PA6T | \ 432 CPU_FTRS_POWER7 | CPU_FTRS_POWER8 | CPU_FTRS_CELL | \
425 CPU_FTR_VSX) 433 CPU_FTRS_PA6T | CPU_FTR_VSX)
426#endif 434#endif
427#else 435#else
428enum { 436enum {
diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 487d46ff68a1..483733bd06d4 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -228,6 +228,8 @@ static inline cputime_t clock_t_to_cputime(const unsigned long clk)
228 228
229#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct)) 229#define cputime64_to_clock_t(ct) cputime_to_clock_t((cputime_t)(ct))
230 230
231static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
232
231#endif /* __KERNEL__ */ 233#endif /* __KERNEL__ */
232#endif /* CONFIG_VIRT_CPU_ACCOUNTING */ 234#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
233#endif /* __POWERPC_CPUTIME_H */ 235#endif /* __POWERPC_CPUTIME_H */
diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h
index 154c067761b1..607e4eeeb694 100644
--- a/arch/powerpc/include/asm/dbell.h
+++ b/arch/powerpc/include/asm/dbell.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2009 Freescale Semicondutor, Inc. 2 * Copyright 2009 Freescale Semiconductor, Inc.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License 5 * modify it under the terms of the GNU General Public License
diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
index 78160874809a..e27e9ad6818e 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -172,6 +172,7 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
172{ 172{
173 struct dma_map_ops *dma_ops = get_dma_ops(dev); 173 struct dma_map_ops *dma_ops = get_dma_ops(dev);
174 174
175 debug_dma_mapping_error(dev, dma_addr);
175 if (dma_ops->mapping_error) 176 if (dma_ops->mapping_error)
176 return dma_ops->mapping_error(dev, dma_addr); 177 return dma_ops->mapping_error(dev, dma_addr);
177 178
diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index b0ef73882b38..a8fb03e22770 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -183,7 +183,7 @@ static inline void eeh_unlock(void)
183#define EEH_MAX_ALLOWED_FREEZES 5 183#define EEH_MAX_ALLOWED_FREEZES 5
184 184
185typedef void *(*eeh_traverse_func)(void *data, void *flag); 185typedef void *(*eeh_traverse_func)(void *data, void *flag);
186int __devinit eeh_phb_pe_create(struct pci_controller *phb); 186int eeh_phb_pe_create(struct pci_controller *phb);
187int eeh_add_to_parent_pe(struct eeh_dev *edev); 187int eeh_add_to_parent_pe(struct eeh_dev *edev);
188int eeh_rmv_from_parent_pe(struct eeh_dev *edev, int purge_pe); 188int eeh_rmv_from_parent_pe(struct eeh_dev *edev, int purge_pe);
189void *eeh_pe_dev_traverse(struct eeh_pe *root, 189void *eeh_pe_dev_traverse(struct eeh_pe *root,
@@ -191,8 +191,8 @@ void *eeh_pe_dev_traverse(struct eeh_pe *root,
191void eeh_pe_restore_bars(struct eeh_pe *pe); 191void eeh_pe_restore_bars(struct eeh_pe *pe);
192struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe); 192struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
193 193
194void * __devinit eeh_dev_init(struct device_node *dn, void *data); 194void *eeh_dev_init(struct device_node *dn, void *data);
195void __devinit eeh_dev_phb_init_dynamic(struct pci_controller *phb); 195void eeh_dev_phb_init_dynamic(struct pci_controller *phb);
196int __init eeh_ops_register(struct eeh_ops *ops); 196int __init eeh_ops_register(struct eeh_ops *ops);
197int __exit eeh_ops_unregister(const char *name); 197int __exit eeh_ops_unregister(const char *name);
198unsigned long eeh_check_failure(const volatile void __iomem *token, 198unsigned long eeh_check_failure(const volatile void __iomem *token,
diff --git a/arch/powerpc/include/asm/epapr_hcalls.h b/arch/powerpc/include/asm/epapr_hcalls.h
index bf2c06c33871..d3d634274d2c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,64 +50,13 @@
50#ifndef _EPAPR_HCALLS_H 50#ifndef _EPAPR_HCALLS_H
51#define _EPAPR_HCALLS_H 51#define _EPAPR_HCALLS_H
52 52
53#include <uapi/asm/epapr_hcalls.h>
54
55#ifndef __ASSEMBLY__
53#include <linux/types.h> 56#include <linux/types.h>
54#include <linux/errno.h> 57#include <linux/errno.h>
55#include <asm/byteorder.h> 58#include <asm/byteorder.h>
56 59
57#define EV_BYTE_CHANNEL_SEND 1
58#define EV_BYTE_CHANNEL_RECEIVE 2
59#define EV_BYTE_CHANNEL_POLL 3
60#define EV_INT_SET_CONFIG 4
61#define EV_INT_GET_CONFIG 5
62#define EV_INT_SET_MASK 6
63#define EV_INT_GET_MASK 7
64#define EV_INT_IACK 9
65#define EV_INT_EOI 10
66#define EV_INT_SEND_IPI 11
67#define EV_INT_SET_TASK_PRIORITY 12
68#define EV_INT_GET_TASK_PRIORITY 13
69#define EV_DOORBELL_SEND 14
70#define EV_MSGSND 15
71#define EV_IDLE 16
72
73/* vendor ID: epapr */
74#define EV_LOCAL_VENDOR_ID 0 /* for private use */
75#define EV_EPAPR_VENDOR_ID 1
76#define EV_FSL_VENDOR_ID 2 /* Freescale Semiconductor */
77#define EV_IBM_VENDOR_ID 3 /* IBM */
78#define EV_GHS_VENDOR_ID 4 /* Green Hills Software */
79#define EV_ENEA_VENDOR_ID 5 /* Enea */
80#define EV_WR_VENDOR_ID 6 /* Wind River Systems */
81#define EV_AMCC_VENDOR_ID 7 /* Applied Micro Circuits */
82#define EV_KVM_VENDOR_ID 42 /* KVM */
83
84/* The max number of bytes that a byte channel can send or receive per call */
85#define EV_BYTE_CHANNEL_MAX_BYTES 16
86
87
88#define _EV_HCALL_TOKEN(id, num) (((id) << 16) | (num))
89#define EV_HCALL_TOKEN(hcall_num) _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, hcall_num)
90
91/* epapr error codes */
92#define EV_EPERM 1 /* Operation not permitted */
93#define EV_ENOENT 2 /* Entry Not Found */
94#define EV_EIO 3 /* I/O error occured */
95#define EV_EAGAIN 4 /* The operation had insufficient
96 * resources to complete and should be
97 * retried
98 */
99#define EV_ENOMEM 5 /* There was insufficient memory to
100 * complete the operation */
101#define EV_EFAULT 6 /* Bad guest address */
102#define EV_ENODEV 7 /* No such device */
103#define EV_EINVAL 8 /* An argument supplied to the hcall
104 was out of range or invalid */
105#define EV_INTERNAL 9 /* An internal error occured */
106#define EV_CONFIG 10 /* A configuration error was detected */
107#define EV_INVALID_STATE 11 /* The object is in an invalid state */
108#define EV_UNIMPLEMENTED 12 /* Unimplemented hypercall */
109#define EV_BUFFER_OVERFLOW 13 /* Caller-supplied buffer too small */
110
111/* 60/*
112 * Hypercall register clobber list 61 * Hypercall register clobber list
113 * 62 *
@@ -193,7 +142,7 @@ static inline unsigned int ev_int_set_config(unsigned int interrupt,
193 r5 = priority; 142 r5 = priority;
194 r6 = destination; 143 r6 = destination;
195 144
196 __asm__ __volatile__ ("sc 1" 145 asm volatile("bl epapr_hypercall_start"
197 : "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6) 146 : "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6)
198 : : EV_HCALL_CLOBBERS4 147 : : EV_HCALL_CLOBBERS4
199 ); 148 );
@@ -222,7 +171,7 @@ static inline unsigned int ev_int_get_config(unsigned int interrupt,
222 r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG); 171 r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
223 r3 = interrupt; 172 r3 = interrupt;
224 173
225 __asm__ __volatile__ ("sc 1" 174 asm volatile("bl epapr_hypercall_start"
226 : "+r" (r11), "+r" (r3), "=r" (r4), "=r" (r5), "=r" (r6) 175 : "+r" (r11), "+r" (r3), "=r" (r4), "=r" (r5), "=r" (r6)
227 : : EV_HCALL_CLOBBERS4 176 : : EV_HCALL_CLOBBERS4
228 ); 177 );
@@ -252,7 +201,7 @@ static inline unsigned int ev_int_set_mask(unsigned int interrupt,
252 r3 = interrupt; 201 r3 = interrupt;
253 r4 = mask; 202 r4 = mask;
254 203
255 __asm__ __volatile__ ("sc 1" 204 asm volatile("bl epapr_hypercall_start"
256 : "+r" (r11), "+r" (r3), "+r" (r4) 205 : "+r" (r11), "+r" (r3), "+r" (r4)
257 : : EV_HCALL_CLOBBERS2 206 : : EV_HCALL_CLOBBERS2
258 ); 207 );
@@ -277,7 +226,7 @@ static inline unsigned int ev_int_get_mask(unsigned int interrupt,
277 r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK); 226 r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
278 r3 = interrupt; 227 r3 = interrupt;
279 228
280 __asm__ __volatile__ ("sc 1" 229 asm volatile("bl epapr_hypercall_start"
281 : "+r" (r11), "+r" (r3), "=r" (r4) 230 : "+r" (r11), "+r" (r3), "=r" (r4)
282 : : EV_HCALL_CLOBBERS2 231 : : EV_HCALL_CLOBBERS2
283 ); 232 );
@@ -305,7 +254,7 @@ static inline unsigned int ev_int_eoi(unsigned int interrupt)
305 r11 = EV_HCALL_TOKEN(EV_INT_EOI); 254 r11 = EV_HCALL_TOKEN(EV_INT_EOI);
306 r3 = interrupt; 255 r3 = interrupt;
307 256
308 __asm__ __volatile__ ("sc 1" 257 asm volatile("bl epapr_hypercall_start"
309 : "+r" (r11), "+r" (r3) 258 : "+r" (r11), "+r" (r3)
310 : : EV_HCALL_CLOBBERS1 259 : : EV_HCALL_CLOBBERS1
311 ); 260 );
@@ -344,7 +293,7 @@ static inline unsigned int ev_byte_channel_send(unsigned int handle,
344 r7 = be32_to_cpu(p[2]); 293 r7 = be32_to_cpu(p[2]);
345 r8 = be32_to_cpu(p[3]); 294 r8 = be32_to_cpu(p[3]);
346 295
347 __asm__ __volatile__ ("sc 1" 296 asm volatile("bl epapr_hypercall_start"
348 : "+r" (r11), "+r" (r3), 297 : "+r" (r11), "+r" (r3),
349 "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), "+r" (r8) 298 "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), "+r" (r8)
350 : : EV_HCALL_CLOBBERS6 299 : : EV_HCALL_CLOBBERS6
@@ -383,7 +332,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned int handle,
383 r3 = handle; 332 r3 = handle;
384 r4 = *count; 333 r4 = *count;
385 334
386 __asm__ __volatile__ ("sc 1" 335 asm volatile("bl epapr_hypercall_start"
387 : "+r" (r11), "+r" (r3), "+r" (r4), 336 : "+r" (r11), "+r" (r3), "+r" (r4),
388 "=r" (r5), "=r" (r6), "=r" (r7), "=r" (r8) 337 "=r" (r5), "=r" (r6), "=r" (r7), "=r" (r8)
389 : : EV_HCALL_CLOBBERS6 338 : : EV_HCALL_CLOBBERS6
@@ -421,7 +370,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned int handle,
421 r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL); 370 r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
422 r3 = handle; 371 r3 = handle;
423 372
424 __asm__ __volatile__ ("sc 1" 373 asm volatile("bl epapr_hypercall_start"
425 : "+r" (r11), "+r" (r3), "=r" (r4), "=r" (r5) 374 : "+r" (r11), "+r" (r3), "=r" (r4), "=r" (r5)
426 : : EV_HCALL_CLOBBERS3 375 : : EV_HCALL_CLOBBERS3
427 ); 376 );
@@ -454,7 +403,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
454 r11 = EV_HCALL_TOKEN(EV_INT_IACK); 403 r11 = EV_HCALL_TOKEN(EV_INT_IACK);
455 r3 = handle; 404 r3 = handle;
456 405
457 __asm__ __volatile__ ("sc 1" 406 asm volatile("bl epapr_hypercall_start"
458 : "+r" (r11), "+r" (r3), "=r" (r4) 407 : "+r" (r11), "+r" (r3), "=r" (r4)
459 : : EV_HCALL_CLOBBERS2 408 : : EV_HCALL_CLOBBERS2
460 ); 409 );
@@ -478,7 +427,7 @@ static inline unsigned int ev_doorbell_send(unsigned int handle)
478 r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND); 427 r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
479 r3 = handle; 428 r3 = handle;
480 429
481 __asm__ __volatile__ ("sc 1" 430 asm volatile("bl epapr_hypercall_start"
482 : "+r" (r11), "+r" (r3) 431 : "+r" (r11), "+r" (r3)
483 : : EV_HCALL_CLOBBERS1 432 : : EV_HCALL_CLOBBERS1
484 ); 433 );
@@ -498,12 +447,12 @@ static inline unsigned int ev_idle(void)
498 447
499 r11 = EV_HCALL_TOKEN(EV_IDLE); 448 r11 = EV_HCALL_TOKEN(EV_IDLE);
500 449
501 __asm__ __volatile__ ("sc 1" 450 asm volatile("bl epapr_hypercall_start"
502 : "+r" (r11), "=r" (r3) 451 : "+r" (r11), "=r" (r3)
503 : : EV_HCALL_CLOBBERS1 452 : : EV_HCALL_CLOBBERS1
504 ); 453 );
505 454
506 return r3; 455 return r3;
507} 456}
508 457#endif /* !__ASSEMBLY__ */
509#endif 458#endif /* _EPAPR_HCALLS_H */
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index a43c1473915f..ad708dda3ba3 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -48,6 +48,35 @@
48#define EX_LR 72 48#define EX_LR 72
49#define EX_CFAR 80 49#define EX_CFAR 80
50 50
51#ifdef CONFIG_RELOCATABLE
52#define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
53 ld r12,PACAKBASE(r13); /* get high part of &label */ \
54 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
55 LOAD_HANDLER(r12,label); \
56 mtlr r12; \
57 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
58 li r10,MSR_RI; \
59 mtmsrd r10,1; /* Set RI (EE=0) */ \
60 blr;
61#else
62/* If not relocatable, we can jump directly -- and save messing with LR */
63#define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
64 mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
65 mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
66 li r10,MSR_RI; \
67 mtmsrd r10,1; /* Set RI (EE=0) */ \
68 b label;
69#endif
70
71/*
72 * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on
73 * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which
74 * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr.
75 */
76#define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \
77 EXCEPTION_PROLOG_1(area, extra, vec); \
78 EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
79
51/* 80/*
52 * We're short on space and time in the exception prolog, so we can't 81 * We're short on space and time in the exception prolog, so we can't
53 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the 82 * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
@@ -55,12 +84,29 @@
55 * word. 84 * word.
56 */ 85 */
57#define LOAD_HANDLER(reg, label) \ 86#define LOAD_HANDLER(reg, label) \
58 addi reg,reg,(label)-_stext; /* virt addr of handler ... */ 87 /* Handlers must be within 64K of kbase, which must be 64k aligned */ \
88 ori reg,reg,(label)-_stext; /* virt addr of handler ... */
59 89
60/* Exception register prefixes */ 90/* Exception register prefixes */
61#define EXC_HV H 91#define EXC_HV H
62#define EXC_STD 92#define EXC_STD
63 93
94#if defined(CONFIG_RELOCATABLE)
95/*
96 * If we support interrupts with relocation on AND we're a relocatable
97 * kernel, we need to use LR to get to the 2nd level handler. So, save/restore
98 * it when required.
99 */
100#define SAVE_LR(reg, area) mflr reg ; std reg,area+EX_LR(r13)
101#define GET_LR(reg, area) ld reg,area+EX_LR(r13)
102#define RESTORE_LR(reg, area) ld reg,area+EX_LR(r13) ; mtlr reg
103#else
104/* ...else LR is unused and in register. */
105#define SAVE_LR(reg, area)
106#define GET_LR(reg, area) mflr reg
107#define RESTORE_LR(reg, area)
108#endif
109
64#define __EXCEPTION_PROLOG_1(area, extra, vec) \ 110#define __EXCEPTION_PROLOG_1(area, extra, vec) \
65 GET_PACA(r13); \ 111 GET_PACA(r13); \
66 std r9,area+EX_R9(r13); /* save r9 - r12 */ \ 112 std r9,area+EX_R9(r13); /* save r9 - r12 */ \
@@ -69,6 +115,7 @@
69 mfspr r10,SPRN_CFAR; \ 115 mfspr r10,SPRN_CFAR; \
70 std r10,area+EX_CFAR(r13); \ 116 std r10,area+EX_CFAR(r13); \
71 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 117 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
118 SAVE_LR(r10, area); \
72 mfcr r9; \ 119 mfcr r9; \
73 extra(vec); \ 120 extra(vec); \
74 std r11,area+EX_R11(r13); \ 121 std r11,area+EX_R11(r13); \
@@ -169,6 +216,7 @@ do_kvm_##n: \
169 sth r1,PACA_TRAP_SAVE(r13); \ 216 sth r1,PACA_TRAP_SAVE(r13); \
170 std r3,area+EX_R3(r13); \ 217 std r3,area+EX_R3(r13); \
171 addi r3,r13,area; /* r3 -> where regs are saved*/ \ 218 addi r3,r13,area; /* r3 -> where regs are saved*/ \
219 RESTORE_LR(r1, area); \
172 b bad_stack; \ 220 b bad_stack; \
1733: std r9,_CCR(r1); /* save CR in stackframe */ \ 2213: std r9,_CCR(r1); /* save CR in stackframe */ \
174 std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 222 std r11,_NIP(r1); /* save SRR0 in stackframe */ \
@@ -194,8 +242,8 @@ do_kvm_##n: \
194 ld r10,area+EX_CFAR(r13); \ 242 ld r10,area+EX_CFAR(r13); \
195 std r10,ORIG_GPR3(r1); \ 243 std r10,ORIG_GPR3(r1); \
196 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ 244 END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
245 GET_LR(r9,area); /* Get LR, later save to stack */ \
197 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 246 ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
198 mflr r9; /* save LR in stackframe */ \
199 std r9,_LINK(r1); \ 247 std r9,_LINK(r1); \
200 mfctr r10; /* save CTR in stackframe */ \ 248 mfctr r10; /* save CTR in stackframe */ \
201 std r10,_CTR(r1); \ 249 std r10,_CTR(r1); \
@@ -232,6 +280,26 @@ label##_hv: \
232 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ 280 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
233 EXC_HV, KVMTEST, vec) 281 EXC_HV, KVMTEST, vec)
234 282
283#define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \
284 . = loc; \
285 .globl label##_relon_pSeries; \
286label##_relon_pSeries: \
287 HMT_MEDIUM; \
288 /* No guest interrupts come through here */ \
289 SET_SCRATCH0(r13); /* save r13 */ \
290 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
291 EXC_STD, KVMTEST_PR, vec)
292
293#define STD_RELON_EXCEPTION_HV(loc, vec, label) \
294 . = loc; \
295 .globl label##_relon_hv; \
296label##_relon_hv: \
297 HMT_MEDIUM; \
298 /* No guest interrupts come through here */ \
299 SET_SCRATCH0(r13); /* save r13 */ \
300 EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
301 EXC_HV, KVMTEST, vec)
302
235/* This associate vector numbers with bits in paca->irq_happened */ 303/* This associate vector numbers with bits in paca->irq_happened */
236#define SOFTEN_VALUE_0x500 PACA_IRQ_EE 304#define SOFTEN_VALUE_0x500 PACA_IRQ_EE
237#define SOFTEN_VALUE_0x502 PACA_IRQ_EE 305#define SOFTEN_VALUE_0x502 PACA_IRQ_EE
@@ -257,6 +325,9 @@ label##_hv: \
257 KVMTEST(vec); \ 325 KVMTEST(vec); \
258 _SOFTEN_TEST(EXC_STD, vec) 326 _SOFTEN_TEST(EXC_STD, vec)
259 327
328#define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec)
329#define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec)
330
260#define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \ 331#define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
261 HMT_MEDIUM; \ 332 HMT_MEDIUM; \
262 SET_SCRATCH0(r13); /* save r13 */ \ 333 SET_SCRATCH0(r13); /* save r13 */ \
@@ -279,6 +350,28 @@ label##_hv: \
279 _MASKABLE_EXCEPTION_PSERIES(vec, label, \ 350 _MASKABLE_EXCEPTION_PSERIES(vec, label, \
280 EXC_HV, SOFTEN_TEST_HV) 351 EXC_HV, SOFTEN_TEST_HV)
281 352
353#define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
354 HMT_MEDIUM; \
355 SET_SCRATCH0(r13); /* save r13 */ \
356 __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
357 EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, h);
358#define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
359 __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
360
361#define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \
362 . = loc; \
363 .globl label##_relon_pSeries; \
364label##_relon_pSeries: \
365 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
366 EXC_STD, SOFTEN_NOTEST_PR)
367
368#define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \
369 . = loc; \
370 .globl label##_relon_hv; \
371label##_relon_hv: \
372 _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
373 EXC_HV, SOFTEN_NOTEST_HV)
374
282/* 375/*
283 * Our exception common code can be passed various "additions" 376 * Our exception common code can be passed various "additions"
284 * to specify the behaviour of interrupts, whether to kick the 377 * to specify the behaviour of interrupts, whether to kick the
diff --git a/arch/powerpc/include/asm/firmware.h b/arch/powerpc/include/asm/firmware.h
index ad0b751b0d78..973cc3be011b 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -49,6 +49,7 @@
49#define FW_FEATURE_XCMO ASM_CONST(0x0000000008000000) 49#define FW_FEATURE_XCMO ASM_CONST(0x0000000008000000)
50#define FW_FEATURE_OPAL ASM_CONST(0x0000000010000000) 50#define FW_FEATURE_OPAL ASM_CONST(0x0000000010000000)
51#define FW_FEATURE_OPALv2 ASM_CONST(0x0000000020000000) 51#define FW_FEATURE_OPALv2 ASM_CONST(0x0000000020000000)
52#define FW_FEATURE_SET_MODE ASM_CONST(0x0000000040000000)
52 53
53#ifndef __ASSEMBLY__ 54#ifndef __ASSEMBLY__
54 55
@@ -62,7 +63,8 @@ enum {
62 FW_FEATURE_VIO | FW_FEATURE_RDMA | FW_FEATURE_LLAN | 63 FW_FEATURE_VIO | FW_FEATURE_RDMA | FW_FEATURE_LLAN |
63 FW_FEATURE_BULK_REMOVE | FW_FEATURE_XDABR | 64 FW_FEATURE_BULK_REMOVE | FW_FEATURE_XDABR |
64 FW_FEATURE_MULTITCE | FW_FEATURE_SPLPAR | FW_FEATURE_LPAR | 65 FW_FEATURE_MULTITCE | FW_FEATURE_SPLPAR | FW_FEATURE_LPAR |
65 FW_FEATURE_CMO | FW_FEATURE_VPHN | FW_FEATURE_XCMO, 66 FW_FEATURE_CMO | FW_FEATURE_VPHN | FW_FEATURE_XCMO |
67 FW_FEATURE_SET_MODE,
66 FW_FEATURE_PSERIES_ALWAYS = 0, 68 FW_FEATURE_PSERIES_ALWAYS = 0,
67 FW_FEATURE_POWERNV_POSSIBLE = FW_FEATURE_OPAL | FW_FEATURE_OPALv2, 69 FW_FEATURE_POWERNV_POSSIBLE = FW_FEATURE_OPAL | FW_FEATURE_OPALv2,
68 FW_FEATURE_POWERNV_ALWAYS = 0, 70 FW_FEATURE_POWERNV_ALWAYS = 0,
diff --git a/arch/powerpc/include/asm/fsl_gtm.h b/arch/powerpc/include/asm/fsl_gtm.h
index 8e8c9b5032d3..3b05808f9caa 100644
--- a/arch/powerpc/include/asm/fsl_gtm.h
+++ b/arch/powerpc/include/asm/fsl_gtm.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Freescale General-purpose Timers Module 2 * Freescale General-purpose Timers Module
3 * 3 *
4 * Copyright (c) Freescale Semicondutor, Inc. 2006. 4 * Copyright 2006 Freescale Semiconductor, Inc.
5 * Shlomi Gridish <gridish@freescale.com> 5 * Shlomi Gridish <gridish@freescale.com>
6 * Jerry Huang <Chang-Ming.Huang@freescale.com> 6 * Jerry Huang <Chang-Ming.Huang@freescale.com>
7 * Copyright (c) MontaVista Software, Inc. 2008. 7 * Copyright (c) MontaVista Software, Inc. 2008.
diff --git a/arch/powerpc/include/asm/fsl_guts.h b/arch/powerpc/include/asm/fsl_guts.h
index dd5ba2c22771..77ced0b3d81d 100644
--- a/arch/powerpc/include/asm/fsl_guts.h
+++ b/arch/powerpc/include/asm/fsl_guts.h
@@ -71,7 +71,9 @@ struct ccsr_guts {
71 u8 res0c4[0x224 - 0xc4]; 71 u8 res0c4[0x224 - 0xc4];
72 __be32 iodelay1; /* 0x.0224 - IO delay control register 1 */ 72 __be32 iodelay1; /* 0x.0224 - IO delay control register 1 */
73 __be32 iodelay2; /* 0x.0228 - IO delay control register 2 */ 73 __be32 iodelay2; /* 0x.0228 - IO delay control register 2 */
74 u8 res22c[0x800 - 0x22c]; 74 u8 res22c[0x604 - 0x22c];
75 __be32 pamubypenr; /* 0x.604 - PAMU bypass enable register */
76 u8 res608[0x800 - 0x608];
75 __be32 clkdvdr; /* 0x.0800 - Clock Divide Register */ 77 __be32 clkdvdr; /* 0x.0800 - Clock Divide Register */
76 u8 res804[0x900 - 0x804]; 78 u8 res804[0x900 - 0x804];
77 __be32 ircr; /* 0x.0900 - Infrared Control Register */ 79 __be32 ircr; /* 0x.0900 - Infrared Control Register */
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5fe3d5..3abb58394da4 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
96 r11 = FH_HCALL_TOKEN(FH_SEND_NMI); 96 r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
97 r3 = vcpu_mask; 97 r3 = vcpu_mask;
98 98
99 __asm__ __volatile__ ("sc 1" 99 asm volatile("bl epapr_hypercall_start"
100 : "+r" (r11), "+r" (r3) 100 : "+r" (r11), "+r" (r3)
101 : : EV_HCALL_CLOBBERS1 101 : : EV_HCALL_CLOBBERS1
102 ); 102 );
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int handle,
151 r9 = (uint32_t)propvalue_addr; 151 r9 = (uint32_t)propvalue_addr;
152 r10 = *propvalue_len; 152 r10 = *propvalue_len;
153 153
154 __asm__ __volatile__ ("sc 1" 154 asm volatile("bl epapr_hypercall_start"
155 : "+r" (r11), 155 : "+r" (r11),
156 "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), 156 "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7),
157 "+r" (r8), "+r" (r9), "+r" (r10) 157 "+r" (r8), "+r" (r9), "+r" (r10)
@@ -205,7 +205,7 @@ static inline unsigned int fh_partition_set_dtprop(int handle,
205 r9 = (uint32_t)propvalue_addr; 205 r9 = (uint32_t)propvalue_addr;
206 r10 = propvalue_len; 206 r10 = propvalue_len;
207 207
208 __asm__ __volatile__ ("sc 1" 208 asm volatile("bl epapr_hypercall_start"
209 : "+r" (r11), 209 : "+r" (r11),
210 "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), 210 "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7),
211 "+r" (r8), "+r" (r9), "+r" (r10) 211 "+r" (r8), "+r" (r9), "+r" (r10)
@@ -229,7 +229,7 @@ static inline unsigned int fh_partition_restart(unsigned int partition)
229 r11 = FH_HCALL_TOKEN(FH_PARTITION_RESTART); 229 r11 = FH_HCALL_TOKEN(FH_PARTITION_RESTART);
230 r3 = partition; 230 r3 = partition;
231 231
232 __asm__ __volatile__ ("sc 1" 232 asm volatile("bl epapr_hypercall_start"
233 : "+r" (r11), "+r" (r3) 233 : "+r" (r11), "+r" (r3)
234 : : EV_HCALL_CLOBBERS1 234 : : EV_HCALL_CLOBBERS1
235 ); 235 );
@@ -262,7 +262,7 @@ static inline unsigned int fh_partition_get_status(unsigned int partition,
262 r11 = FH_HCALL_TOKEN(FH_PARTITION_GET_STATUS); 262 r11 = FH_HCALL_TOKEN(FH_PARTITION_GET_STATUS);
263 r3 = partition; 263 r3 = partition;
264 264
265 __asm__ __volatile__ ("sc 1" 265 asm volatile("bl epapr_hypercall_start"
266 : "+r" (r11), "+r" (r3), "=r" (r4) 266 : "+r" (r11), "+r" (r3), "=r" (r4)
267 : : EV_HCALL_CLOBBERS2 267 : : EV_HCALL_CLOBBERS2
268 ); 268 );
@@ -295,7 +295,7 @@ static inline unsigned int fh_partition_start(unsigned int partition,
295 r4 = entry_point; 295 r4 = entry_point;
296 r5 = load; 296 r5 = load;
297 297
298 __asm__ __volatile__ ("sc 1" 298 asm volatile("bl epapr_hypercall_start"
299 : "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5) 299 : "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5)
300 : : EV_HCALL_CLOBBERS3 300 : : EV_HCALL_CLOBBERS3
301 ); 301 );
@@ -317,7 +317,7 @@ static inline unsigned int fh_partition_stop(unsigned int partition)
317 r11 = FH_HCALL_TOKEN(FH_PARTITION_STOP); 317 r11 = FH_HCALL_TOKEN(FH_PARTITION_STOP);
318 r3 = partition; 318 r3 = partition;
319 319
320 __asm__ __volatile__ ("sc 1" 320 asm volatile("bl epapr_hypercall_start"
321 : "+r" (r11), "+r" (r3) 321 : "+r" (r11), "+r" (r3)
322 : : EV_HCALL_CLOBBERS1 322 : : EV_HCALL_CLOBBERS1
323 ); 323 );
@@ -376,7 +376,7 @@ static inline unsigned int fh_partition_memcpy(unsigned int source,
376#endif 376#endif
377 r7 = count; 377 r7 = count;
378 378
379 __asm__ __volatile__ ("sc 1" 379 asm volatile("bl epapr_hypercall_start"
380 : "+r" (r11), 380 : "+r" (r11),
381 "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7) 381 "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7)
382 : : EV_HCALL_CLOBBERS5 382 : : EV_HCALL_CLOBBERS5
@@ -399,7 +399,7 @@ static inline unsigned int fh_dma_enable(unsigned int liodn)
399 r11 = FH_HCALL_TOKEN(FH_DMA_ENABLE); 399 r11 = FH_HCALL_TOKEN(FH_DMA_ENABLE);
400 r3 = liodn; 400 r3 = liodn;
401 401
402 __asm__ __volatile__ ("sc 1" 402 asm volatile("bl epapr_hypercall_start"
403 : "+r" (r11), "+r" (r3) 403 : "+r" (r11), "+r" (r3)
404 : : EV_HCALL_CLOBBERS1 404 : : EV_HCALL_CLOBBERS1
405 ); 405 );
@@ -421,7 +421,7 @@ static inline unsigned int fh_dma_disable(unsigned int liodn)
421 r11 = FH_HCALL_TOKEN(FH_DMA_DISABLE); 421 r11 = FH_HCALL_TOKEN(FH_DMA_DISABLE);
422 r3 = liodn; 422 r3 = liodn;
423 423
424 __asm__ __volatile__ ("sc 1" 424 asm volatile("bl epapr_hypercall_start"
425 : "+r" (r11), "+r" (r3) 425 : "+r" (r11), "+r" (r3)
426 : : EV_HCALL_CLOBBERS1 426 : : EV_HCALL_CLOBBERS1
427 ); 427 );
@@ -447,7 +447,7 @@ static inline unsigned int fh_vmpic_get_msir(unsigned int interrupt,
447 r11 = FH_HCALL_TOKEN(FH_VMPIC_GET_MSIR); 447 r11 = FH_HCALL_TOKEN(FH_VMPIC_GET_MSIR);
448 r3 = interrupt; 448 r3 = interrupt;
449 449
450 __asm__ __volatile__ ("sc 1" 450 asm volatile("bl epapr_hypercall_start"
451 : "+r" (r11), "+r" (r3), "=r" (r4) 451 : "+r" (r11), "+r" (r3), "=r" (r4)
452 : : EV_HCALL_CLOBBERS2 452 : : EV_HCALL_CLOBBERS2
453 ); 453 );
@@ -469,7 +469,7 @@ static inline unsigned int fh_system_reset(void)
469 469
470 r11 = FH_HCALL_TOKEN(FH_SYSTEM_RESET); 470 r11 = FH_HCALL_TOKEN(FH_SYSTEM_RESET);
471 471
472 __asm__ __volatile__ ("sc 1" 472 asm volatile("bl epapr_hypercall_start"
473 : "+r" (r11), "=r" (r3) 473 : "+r" (r11), "=r" (r3)
474 : : EV_HCALL_CLOBBERS1 474 : : EV_HCALL_CLOBBERS1
475 ); 475 );
@@ -506,7 +506,7 @@ static inline unsigned int fh_err_get_info(int queue, uint32_t *bufsize,
506 r6 = addr_lo; 506 r6 = addr_lo;
507 r7 = peek; 507 r7 = peek;
508 508
509 __asm__ __volatile__ ("sc 1" 509 asm volatile("bl epapr_hypercall_start"
510 : "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), 510 : "+r" (r11), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6),
511 "+r" (r7) 511 "+r" (r7)
512 : : EV_HCALL_CLOBBERS5 512 : : EV_HCALL_CLOBBERS5
@@ -542,7 +542,7 @@ static inline unsigned int fh_get_core_state(unsigned int handle,
542 r3 = handle; 542 r3 = handle;
543 r4 = vcpu; 543 r4 = vcpu;
544 544
545 __asm__ __volatile__ ("sc 1" 545 asm volatile("bl epapr_hypercall_start"
546 : "+r" (r11), "+r" (r3), "+r" (r4) 546 : "+r" (r11), "+r" (r3), "+r" (r4)
547 : : EV_HCALL_CLOBBERS2 547 : : EV_HCALL_CLOBBERS2
548 ); 548 );
@@ -572,7 +572,7 @@ static inline unsigned int fh_enter_nap(unsigned int handle, unsigned int vcpu)
572 r3 = handle; 572 r3 = handle;
573 r4 = vcpu; 573 r4 = vcpu;
574 574
575 __asm__ __volatile__ ("sc 1" 575 asm volatile("bl epapr_hypercall_start"
576 : "+r" (r11), "+r" (r3), "+r" (r4) 576 : "+r" (r11), "+r" (r3), "+r" (r4)
577 : : EV_HCALL_CLOBBERS2 577 : : EV_HCALL_CLOBBERS2
578 ); 578 );
@@ -597,7 +597,7 @@ static inline unsigned int fh_exit_nap(unsigned int handle, unsigned int vcpu)
597 r3 = handle; 597 r3 = handle;
598 r4 = vcpu; 598 r4 = vcpu;
599 599
600 __asm__ __volatile__ ("sc 1" 600 asm volatile("bl epapr_hypercall_start"
601 : "+r" (r11), "+r" (r3), "+r" (r4) 601 : "+r" (r11), "+r" (r3), "+r" (r4)
602 : : EV_HCALL_CLOBBERS2 602 : : EV_HCALL_CLOBBERS2
603 ); 603 );
@@ -618,7 +618,7 @@ static inline unsigned int fh_claim_device(unsigned int handle)
618 r11 = FH_HCALL_TOKEN(FH_CLAIM_DEVICE); 618 r11 = FH_HCALL_TOKEN(FH_CLAIM_DEVICE);
619 r3 = handle; 619 r3 = handle;
620 620
621 __asm__ __volatile__ ("sc 1" 621 asm volatile("bl epapr_hypercall_start"
622 : "+r" (r11), "+r" (r3) 622 : "+r" (r11), "+r" (r3)
623 : : EV_HCALL_CLOBBERS1 623 : : EV_HCALL_CLOBBERS1
624 ); 624 );
@@ -645,7 +645,7 @@ static inline unsigned int fh_partition_stop_dma(unsigned int handle)
645 r11 = FH_HCALL_TOKEN(FH_PARTITION_STOP_DMA); 645 r11 = FH_HCALL_TOKEN(FH_PARTITION_STOP_DMA);
646 r3 = handle; 646 r3 = handle;
647 647
648 __asm__ __volatile__ ("sc 1" 648 asm volatile("bl epapr_hypercall_start"
649 : "+r" (r11), "+r" (r3) 649 : "+r" (r11), "+r" (r3)
650 : : EV_HCALL_CLOBBERS1 650 : : EV_HCALL_CLOBBERS1
651 ); 651 );
diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
index 7a867065db79..0975e5c0bb19 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -267,7 +267,8 @@
267#define H_RANDOM 0x300 267#define H_RANDOM 0x300
268#define H_COP 0x304 268#define H_COP 0x304
269#define H_GET_MPP_X 0x314 269#define H_GET_MPP_X 0x314
270#define MAX_HCALL_OPCODE H_GET_MPP_X 270#define H_SET_MODE 0x31C
271#define MAX_HCALL_OPCODE H_SET_MODE
271 272
272#ifndef __ASSEMBLY__ 273#ifndef __ASSEMBLY__
273 274
@@ -355,6 +356,26 @@ struct hvcall_mpp_x_data {
355 356
356int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data); 357int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data);
357 358
359static inline unsigned int get_longbusy_msecs(int longbusy_rc)
360{
361 switch (longbusy_rc) {
362 case H_LONG_BUSY_ORDER_1_MSEC:
363 return 1;
364 case H_LONG_BUSY_ORDER_10_MSEC:
365 return 10;
366 case H_LONG_BUSY_ORDER_100_MSEC:
367 return 100;
368 case H_LONG_BUSY_ORDER_1_SEC:
369 return 1000;
370 case H_LONG_BUSY_ORDER_10_SEC:
371 return 10000;
372 case H_LONG_BUSY_ORDER_100_SEC:
373 return 100000;
374 default:
375 return 1;
376 }
377}
378
358#ifdef CONFIG_PPC_PSERIES 379#ifdef CONFIG_PPC_PSERIES
359extern int CMO_PrPSP; 380extern int CMO_PrPSP;
360extern int CMO_SecPSP; 381extern int CMO_SecPSP;
diff --git a/arch/powerpc/include/asm/immap_qe.h b/arch/powerpc/include/asm/immap_qe.h
index 61e8490786b8..bedbff891423 100644
--- a/arch/powerpc/include/asm/immap_qe.h
+++ b/arch/powerpc/include/asm/immap_qe.h
@@ -3,7 +3,7 @@
3 * The Internal Memory Map for devices with QE on them. This 3 * The Internal Memory Map for devices with QE on them. This
4 * is the superset of all QE devices (8360, etc.). 4 * is the superset of all QE devices (8360, etc.).
5 5
6 * Copyright (C) 2006. Freescale Semicondutor, Inc. All rights reserved. 6 * Copyright (C) 2006. Freescale Semiconductor, Inc. All rights reserved.
7 * 7 *
8 * Authors: Shlomi Gridish <gridish@freescale.com> 8 * Authors: Shlomi Gridish <gridish@freescale.com>
9 * Li Yang <leoli@freescale.com> 9 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/include/asm/io-workarounds.h b/arch/powerpc/include/asm/io-workarounds.h
index fbae49286926..f96dd096ff4e 100644
--- a/arch/powerpc/include/asm/io-workarounds.h
+++ b/arch/powerpc/include/asm/io-workarounds.h
@@ -31,8 +31,8 @@ struct iowa_bus {
31 void *private; 31 void *private;
32}; 32};
33 33
34void __devinit iowa_register_bus(struct pci_controller *, struct ppc_pci_io *, 34void iowa_register_bus(struct pci_controller *, struct ppc_pci_io *,
35 int (*)(struct iowa_bus *, void *), void *); 35 int (*)(struct iowa_bus *, void *), void *);
36struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR); 36struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR);
37struct iowa_bus *iowa_pio_find_bus(unsigned long); 37struct iowa_bus *iowa_pio_find_bus(unsigned long);
38 38
diff --git a/arch/powerpc/include/asm/kvm_asm.h b/arch/powerpc/include/asm/kvm_asm.h
index 76fdcfef0889..aabcdba8f6b0 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -118,6 +118,7 @@
118 118
119#define RESUME_FLAG_NV (1<<0) /* Reload guest nonvolatile state? */ 119#define RESUME_FLAG_NV (1<<0) /* Reload guest nonvolatile state? */
120#define RESUME_FLAG_HOST (1<<1) /* Resume host? */ 120#define RESUME_FLAG_HOST (1<<1) /* Resume host? */
121#define RESUME_FLAG_ARCH1 (1<<2)
121 122
122#define RESUME_GUEST 0 123#define RESUME_GUEST 0
123#define RESUME_GUEST_NV RESUME_FLAG_NV 124#define RESUME_GUEST_NV RESUME_FLAG_NV
diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index 7aefdb3e1ce4..5a56e1c5f851 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -81,6 +81,8 @@ struct kvmppc_vcpu_book3s {
81 u64 sdr1; 81 u64 sdr1;
82 u64 hior; 82 u64 hior;
83 u64 msr_mask; 83 u64 msr_mask;
84 u64 purr_offset;
85 u64 spurr_offset;
84#ifdef CONFIG_PPC_BOOK3S_32 86#ifdef CONFIG_PPC_BOOK3S_32
85 u32 vsid_pool[VSID_POOL_SIZE]; 87 u32 vsid_pool[VSID_POOL_SIZE];
86 u32 vsid_next; 88 u32 vsid_next;
@@ -157,10 +159,14 @@ extern void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long addr,
157extern void kvmppc_unpin_guest_page(struct kvm *kvm, void *addr); 159extern void kvmppc_unpin_guest_page(struct kvm *kvm, void *addr);
158extern long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, 160extern long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
159 long pte_index, unsigned long pteh, unsigned long ptel); 161 long pte_index, unsigned long pteh, unsigned long ptel);
160extern long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, 162extern long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
161 long pte_index, unsigned long pteh, unsigned long ptel); 163 long pte_index, unsigned long pteh, unsigned long ptel,
164 pgd_t *pgdir, bool realmode, unsigned long *idx_ret);
165extern long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
166 unsigned long pte_index, unsigned long avpn,
167 unsigned long *hpret);
162extern long kvmppc_hv_get_dirty_log(struct kvm *kvm, 168extern long kvmppc_hv_get_dirty_log(struct kvm *kvm,
163 struct kvm_memory_slot *memslot); 169 struct kvm_memory_slot *memslot, unsigned long *map);
164 170
165extern void kvmppc_entry_trampoline(void); 171extern void kvmppc_entry_trampoline(void);
166extern void kvmppc_hv_entry_trampoline(void); 172extern void kvmppc_hv_entry_trampoline(void);
diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h b/arch/powerpc/include/asm/kvm_book3s_64.h
index 0dd1d86d3e31..38bec1dc9928 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -50,6 +50,15 @@ extern int kvm_hpt_order; /* order of preallocated HPTs */
50#define HPTE_V_HVLOCK 0x40UL 50#define HPTE_V_HVLOCK 0x40UL
51#define HPTE_V_ABSENT 0x20UL 51#define HPTE_V_ABSENT 0x20UL
52 52
53/*
54 * We use this bit in the guest_rpte field of the revmap entry
55 * to indicate a modified HPTE.
56 */
57#define HPTE_GR_MODIFIED (1ul << 62)
58
59/* These bits are reserved in the guest view of the HPTE */
60#define HPTE_GR_RESERVED HPTE_GR_MODIFIED
61
53static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits) 62static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits)
54{ 63{
55 unsigned long tmp, old; 64 unsigned long tmp, old;
@@ -60,7 +69,7 @@ static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits)
60 " ori %0,%0,%4\n" 69 " ori %0,%0,%4\n"
61 " stdcx. %0,0,%2\n" 70 " stdcx. %0,0,%2\n"
62 " beq+ 2f\n" 71 " beq+ 2f\n"
63 " li %1,%3\n" 72 " mr %1,%3\n"
64 "2: isync" 73 "2: isync"
65 : "=&r" (tmp), "=&r" (old) 74 : "=&r" (tmp), "=&r" (old)
66 : "r" (hpte), "r" (bits), "i" (HPTE_V_HVLOCK) 75 : "r" (hpte), "r" (bits), "i" (HPTE_V_HVLOCK)
@@ -237,4 +246,26 @@ static inline bool slot_is_aligned(struct kvm_memory_slot *memslot,
237 return !(memslot->base_gfn & mask) && !(memslot->npages & mask); 246 return !(memslot->base_gfn & mask) && !(memslot->npages & mask);
238} 247}
239 248
249/*
250 * This works for 4k, 64k and 16M pages on POWER7,
251 * and 4k and 16M pages on PPC970.
252 */
253static inline unsigned long slb_pgsize_encoding(unsigned long psize)
254{
255 unsigned long senc = 0;
256
257 if (psize > 0x1000) {
258 senc = SLB_VSID_L;
259 if (psize == 0x10000)
260 senc |= SLB_VSID_LP_01;
261 }
262 return senc;
263}
264
265static inline int is_vrma_hpte(unsigned long hpte_v)
266{
267 return (hpte_v & ~0xffffffUL) ==
268 (HPTE_V_1TB_SEG | (VRMA_VSID << (40 - 16)));
269}
270
240#endif /* __ASM_KVM_BOOK3S_64_H__ */ 271#endif /* __ASM_KVM_BOOK3S_64_H__ */
diff --git a/arch/powerpc/include/asm/kvm_booke_hv_asm.h b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
index 30a600fa1b6a..3a79f5325712 100644
--- a/arch/powerpc/include/asm/kvm_booke_hv_asm.h
+++ b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
@@ -17,6 +17,7 @@
17 * there are no exceptions for which we fall through directly to 17 * there are no exceptions for which we fall through directly to
18 * the normal host handler. 18 * the normal host handler.
19 * 19 *
20 * 32-bit host
20 * Expected inputs (normal exceptions): 21 * Expected inputs (normal exceptions):
21 * SCRATCH0 = saved r10 22 * SCRATCH0 = saved r10
22 * r10 = thread struct 23 * r10 = thread struct
@@ -33,14 +34,38 @@
33 * *(r8 + GPR9) = saved r9 34 * *(r8 + GPR9) = saved r9
34 * *(r8 + GPR10) = saved r10 (r10 not yet clobbered) 35 * *(r8 + GPR10) = saved r10 (r10 not yet clobbered)
35 * *(r8 + GPR11) = saved r11 36 * *(r8 + GPR11) = saved r11
37 *
38 * 64-bit host
39 * Expected inputs (GEN/GDBELL/DBG/MC exception types):
40 * r10 = saved CR
41 * r13 = PACA_POINTER
42 * *(r13 + PACA_EX##type + EX_R10) = saved r10
43 * *(r13 + PACA_EX##type + EX_R11) = saved r11
44 * SPRN_SPRG_##type##_SCRATCH = saved r13
45 *
46 * Expected inputs (CRIT exception type):
47 * r10 = saved CR
48 * r13 = PACA_POINTER
49 * *(r13 + PACA_EX##type + EX_R10) = saved r10
50 * *(r13 + PACA_EX##type + EX_R11) = saved r11
51 * *(r13 + PACA_EX##type + EX_R13) = saved r13
52 *
53 * Expected inputs (TLB exception type):
54 * r10 = saved CR
55 * r13 = PACA_POINTER
56 * *(r13 + PACA_EX##type + EX_TLB_R10) = saved r10
57 * *(r13 + PACA_EX##type + EX_TLB_R11) = saved r11
58 * SPRN_SPRG_GEN_SCRATCH = saved r13
59 *
60 * Only the bolted version of TLB miss exception handlers is supported now.
36 */ 61 */
37.macro DO_KVM intno srr1 62.macro DO_KVM intno srr1
38#ifdef CONFIG_KVM_BOOKE_HV 63#ifdef CONFIG_KVM_BOOKE_HV
39BEGIN_FTR_SECTION 64BEGIN_FTR_SECTION
40 mtocrf 0x80, r11 /* check MSR[GS] without clobbering reg */ 65 mtocrf 0x80, r11 /* check MSR[GS] without clobbering reg */
41 bf 3, kvmppc_resume_\intno\()_\srr1 66 bf 3, 1975f
42 b kvmppc_handler_\intno\()_\srr1 67 b kvmppc_handler_\intno\()_\srr1
43kvmppc_resume_\intno\()_\srr1: 681975:
44END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) 69END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
45#endif 70#endif
46.endm 71.endm
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 28e8f5e5c63e..ca9bf459db6a 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -46,7 +46,7 @@
46#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 46#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
47#endif 47#endif
48 48
49#ifdef CONFIG_KVM_BOOK3S_64_HV 49#if !defined(CONFIG_KVM_440)
50#include <linux/mmu_notifier.h> 50#include <linux/mmu_notifier.h>
51 51
52#define KVM_ARCH_WANT_MMU_NOTIFIER 52#define KVM_ARCH_WANT_MMU_NOTIFIER
@@ -204,7 +204,7 @@ struct revmap_entry {
204}; 204};
205 205
206/* 206/*
207 * We use the top bit of each memslot->rmap entry as a lock bit, 207 * We use the top bit of each memslot->arch.rmap entry as a lock bit,
208 * and bit 32 as a present flag. The bottom 32 bits are the 208 * and bit 32 as a present flag. The bottom 32 bits are the
209 * index in the guest HPT of a HPTE that points to the page. 209 * index in the guest HPT of a HPTE that points to the page.
210 */ 210 */
@@ -215,14 +215,17 @@ struct revmap_entry {
215#define KVMPPC_RMAP_PRESENT 0x100000000ul 215#define KVMPPC_RMAP_PRESENT 0x100000000ul
216#define KVMPPC_RMAP_INDEX 0xfffffffful 216#define KVMPPC_RMAP_INDEX 0xfffffffful
217 217
218/* Low-order bits in kvm->arch.slot_phys[][] */ 218/* Low-order bits in memslot->arch.slot_phys[] */
219#define KVMPPC_PAGE_ORDER_MASK 0x1f 219#define KVMPPC_PAGE_ORDER_MASK 0x1f
220#define KVMPPC_PAGE_NO_CACHE HPTE_R_I /* 0x20 */ 220#define KVMPPC_PAGE_NO_CACHE HPTE_R_I /* 0x20 */
221#define KVMPPC_PAGE_WRITETHRU HPTE_R_W /* 0x40 */ 221#define KVMPPC_PAGE_WRITETHRU HPTE_R_W /* 0x40 */
222#define KVMPPC_GOT_PAGE 0x80 222#define KVMPPC_GOT_PAGE 0x80
223 223
224struct kvm_arch_memory_slot { 224struct kvm_arch_memory_slot {
225#ifdef CONFIG_KVM_BOOK3S_64_HV
225 unsigned long *rmap; 226 unsigned long *rmap;
227 unsigned long *slot_phys;
228#endif /* CONFIG_KVM_BOOK3S_64_HV */
226}; 229};
227 230
228struct kvm_arch { 231struct kvm_arch {
@@ -243,12 +246,12 @@ struct kvm_arch {
243 int using_mmu_notifiers; 246 int using_mmu_notifiers;
244 u32 hpt_order; 247 u32 hpt_order;
245 atomic_t vcpus_running; 248 atomic_t vcpus_running;
249 u32 online_vcores;
246 unsigned long hpt_npte; 250 unsigned long hpt_npte;
247 unsigned long hpt_mask; 251 unsigned long hpt_mask;
252 atomic_t hpte_mod_interest;
248 spinlock_t slot_phys_lock; 253 spinlock_t slot_phys_lock;
249 unsigned long *slot_phys[KVM_MEM_SLOTS_NUM]; 254 cpumask_t need_tlb_flush;
250 int slot_npages[KVM_MEM_SLOTS_NUM];
251 unsigned short last_vcpu[NR_CPUS];
252 struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; 255 struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
253 struct kvmppc_linear_info *hpt_li; 256 struct kvmppc_linear_info *hpt_li;
254#endif /* CONFIG_KVM_BOOK3S_64_HV */ 257#endif /* CONFIG_KVM_BOOK3S_64_HV */
@@ -273,6 +276,7 @@ struct kvmppc_vcore {
273 int nap_count; 276 int nap_count;
274 int napping_threads; 277 int napping_threads;
275 u16 pcpu; 278 u16 pcpu;
279 u16 last_cpu;
276 u8 vcore_state; 280 u8 vcore_state;
277 u8 in_guest; 281 u8 in_guest;
278 struct list_head runnable_threads; 282 struct list_head runnable_threads;
@@ -288,9 +292,10 @@ struct kvmppc_vcore {
288 292
289/* Values for vcore_state */ 293/* Values for vcore_state */
290#define VCORE_INACTIVE 0 294#define VCORE_INACTIVE 0
291#define VCORE_RUNNING 1 295#define VCORE_SLEEPING 1
292#define VCORE_EXITING 2 296#define VCORE_STARTING 2
293#define VCORE_SLEEPING 3 297#define VCORE_RUNNING 3
298#define VCORE_EXITING 4
294 299
295/* 300/*
296 * Struct used to manage memory for a virtual processor area 301 * Struct used to manage memory for a virtual processor area
@@ -346,6 +351,27 @@ struct kvmppc_slb {
346 bool class : 1; 351 bool class : 1;
347}; 352};
348 353
354# ifdef CONFIG_PPC_FSL_BOOK3E
355#define KVMPPC_BOOKE_IAC_NUM 2
356#define KVMPPC_BOOKE_DAC_NUM 2
357# else
358#define KVMPPC_BOOKE_IAC_NUM 4
359#define KVMPPC_BOOKE_DAC_NUM 2
360# endif
361#define KVMPPC_BOOKE_MAX_IAC 4
362#define KVMPPC_BOOKE_MAX_DAC 2
363
364struct kvmppc_booke_debug_reg {
365 u32 dbcr0;
366 u32 dbcr1;
367 u32 dbcr2;
368#ifdef CONFIG_KVM_E500MC
369 u32 dbcr4;
370#endif
371 u64 iac[KVMPPC_BOOKE_MAX_IAC];
372 u64 dac[KVMPPC_BOOKE_MAX_DAC];
373};
374
349struct kvm_vcpu_arch { 375struct kvm_vcpu_arch {
350 ulong host_stack; 376 ulong host_stack;
351 u32 host_pid; 377 u32 host_pid;
@@ -380,13 +406,18 @@ struct kvm_vcpu_arch {
380 u32 host_mas4; 406 u32 host_mas4;
381 u32 host_mas6; 407 u32 host_mas6;
382 u32 shadow_epcr; 408 u32 shadow_epcr;
383 u32 epcr;
384 u32 shadow_msrp; 409 u32 shadow_msrp;
385 u32 eplc; 410 u32 eplc;
386 u32 epsc; 411 u32 epsc;
387 u32 oldpir; 412 u32 oldpir;
388#endif 413#endif
389 414
415#if defined(CONFIG_BOOKE)
416#if defined(CONFIG_KVM_BOOKE_HV) || defined(CONFIG_64BIT)
417 u32 epcr;
418#endif
419#endif
420
390#ifdef CONFIG_PPC_BOOK3S 421#ifdef CONFIG_PPC_BOOK3S
391 /* For Gekko paired singles */ 422 /* For Gekko paired singles */
392 u32 qpr[32]; 423 u32 qpr[32];
@@ -440,8 +471,6 @@ struct kvm_vcpu_arch {
440 471
441 u32 ccr0; 472 u32 ccr0;
442 u32 ccr1; 473 u32 ccr1;
443 u32 dbcr0;
444 u32 dbcr1;
445 u32 dbsr; 474 u32 dbsr;
446 475
447 u64 mmcr[3]; 476 u64 mmcr[3];
@@ -471,9 +500,12 @@ struct kvm_vcpu_arch {
471 ulong fault_esr; 500 ulong fault_esr;
472 ulong queued_dear; 501 ulong queued_dear;
473 ulong queued_esr; 502 ulong queued_esr;
503 spinlock_t wdt_lock;
504 struct timer_list wdt_timer;
474 u32 tlbcfg[4]; 505 u32 tlbcfg[4];
475 u32 mmucfg; 506 u32 mmucfg;
476 u32 epr; 507 u32 epr;
508 struct kvmppc_booke_debug_reg dbg_reg;
477#endif 509#endif
478 gpa_t paddr_accessed; 510 gpa_t paddr_accessed;
479 gva_t vaddr_accessed; 511 gva_t vaddr_accessed;
@@ -486,6 +518,7 @@ struct kvm_vcpu_arch {
486 u8 osi_needed; 518 u8 osi_needed;
487 u8 osi_enabled; 519 u8 osi_enabled;
488 u8 papr_enabled; 520 u8 papr_enabled;
521 u8 watchdog_enabled;
489 u8 sane; 522 u8 sane;
490 u8 cpu_type; 523 u8 cpu_type;
491 u8 hcall_needed; 524 u8 hcall_needed;
@@ -497,7 +530,6 @@ struct kvm_vcpu_arch {
497 u64 dec_jiffies; 530 u64 dec_jiffies;
498 u64 dec_expires; 531 u64 dec_expires;
499 unsigned long pending_exceptions; 532 unsigned long pending_exceptions;
500 u16 last_cpu;
501 u8 ceded; 533 u8 ceded;
502 u8 prodded; 534 u8 prodded;
503 u32 last_inst; 535 u32 last_inst;
@@ -534,13 +566,17 @@ struct kvm_vcpu_arch {
534 unsigned long dtl_index; 566 unsigned long dtl_index;
535 u64 stolen_logged; 567 u64 stolen_logged;
536 struct kvmppc_vpa slb_shadow; 568 struct kvmppc_vpa slb_shadow;
569
570 spinlock_t tbacct_lock;
571 u64 busy_stolen;
572 u64 busy_preempt;
537#endif 573#endif
538}; 574};
539 575
540/* Values for vcpu->arch.state */ 576/* Values for vcpu->arch.state */
541#define KVMPPC_VCPU_STOPPED 0 577#define KVMPPC_VCPU_NOTREADY 0
542#define KVMPPC_VCPU_BUSY_IN_HOST 1 578#define KVMPPC_VCPU_RUNNABLE 1
543#define KVMPPC_VCPU_RUNNABLE 2 579#define KVMPPC_VCPU_BUSY_IN_HOST 2
544 580
545/* Values for vcpu->arch.io_gpr */ 581/* Values for vcpu->arch.io_gpr */
546#define KVM_MMIO_REG_MASK 0x001f 582#define KVM_MMIO_REG_MASK 0x001f
diff --git a/arch/powerpc/include/asm/kvm_para.h b/arch/powerpc/include/asm/kvm_para.h
index 9365860fb7f6..2b119654b4c1 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -21,7 +21,6 @@
21 21
22#include <uapi/asm/kvm_para.h> 22#include <uapi/asm/kvm_para.h>
23 23
24
25#ifdef CONFIG_KVM_GUEST 24#ifdef CONFIG_KVM_GUEST
26 25
27#include <linux/of.h> 26#include <linux/of.h>
@@ -55,7 +54,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
55 unsigned long *out, 54 unsigned long *out,
56 unsigned long nr) 55 unsigned long nr)
57{ 56{
58 return HC_EV_UNIMPLEMENTED; 57 return EV_UNIMPLEMENTED;
59} 58}
60 59
61#endif 60#endif
@@ -66,7 +65,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
66 unsigned long out[8]; 65 unsigned long out[8];
67 unsigned long r; 66 unsigned long r;
68 67
69 r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM); 68 r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
70 *r2 = out[0]; 69 *r2 = out[0];
71 70
72 return r; 71 return r;
@@ -77,7 +76,7 @@ static inline long kvm_hypercall0(unsigned int nr)
77 unsigned long in[8]; 76 unsigned long in[8];
78 unsigned long out[8]; 77 unsigned long out[8];
79 78
80 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM); 79 return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
81} 80}
82 81
83static inline long kvm_hypercall1(unsigned int nr, unsigned long p1) 82static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -86,7 +85,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
86 unsigned long out[8]; 85 unsigned long out[8];
87 86
88 in[0] = p1; 87 in[0] = p1;
89 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM); 88 return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
90} 89}
91 90
92static inline long kvm_hypercall2(unsigned int nr, unsigned long p1, 91static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -97,7 +96,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
97 96
98 in[0] = p1; 97 in[0] = p1;
99 in[1] = p2; 98 in[1] = p2;
100 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM); 99 return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
101} 100}
102 101
103static inline long kvm_hypercall3(unsigned int nr, unsigned long p1, 102static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -109,7 +108,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
109 in[0] = p1; 108 in[0] = p1;
110 in[1] = p2; 109 in[1] = p2;
111 in[2] = p3; 110 in[2] = p3;
112 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM); 111 return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
113} 112}
114 113
115static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, 114static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -123,7 +122,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
123 in[1] = p2; 122 in[1] = p2;
124 in[2] = p3; 123 in[2] = p3;
125 in[3] = p4; 124 in[3] = p4;
126 return kvm_hypercall(in, out, nr | HC_VENDOR_KVM); 125 return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
127} 126}
128 127
129 128
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index e006f0bdea95..572aa7530619 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -28,6 +28,7 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/kvm_types.h> 29#include <linux/kvm_types.h>
30#include <linux/kvm_host.h> 30#include <linux/kvm_host.h>
31#include <linux/bug.h>
31#ifdef CONFIG_PPC_BOOK3S 32#ifdef CONFIG_PPC_BOOK3S
32#include <asm/kvm_book3s.h> 33#include <asm/kvm_book3s.h>
33#else 34#else
@@ -68,6 +69,8 @@ extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
68extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); 69extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
69extern void kvmppc_decrementer_func(unsigned long data); 70extern void kvmppc_decrementer_func(unsigned long data);
70extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu); 71extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
72extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu);
73extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu);
71 74
72/* Core-specific hooks */ 75/* Core-specific hooks */
73 76
@@ -104,6 +107,7 @@ extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
104 struct kvm_interrupt *irq); 107 struct kvm_interrupt *irq);
105extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, 108extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
106 struct kvm_interrupt *irq); 109 struct kvm_interrupt *irq);
110extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu);
107 111
108extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 112extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
109 unsigned int op, int *advance); 113 unsigned int op, int *advance);
@@ -111,6 +115,7 @@ extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn,
111 ulong val); 115 ulong val);
112extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, 116extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn,
113 ulong *val); 117 ulong *val);
118extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
114 119
115extern int kvmppc_booke_init(void); 120extern int kvmppc_booke_init(void);
116extern void kvmppc_booke_exit(void); 121extern void kvmppc_booke_exit(void);
@@ -139,16 +144,28 @@ extern struct kvmppc_linear_info *kvm_alloc_hpt(void);
139extern void kvm_release_hpt(struct kvmppc_linear_info *li); 144extern void kvm_release_hpt(struct kvmppc_linear_info *li);
140extern int kvmppc_core_init_vm(struct kvm *kvm); 145extern int kvmppc_core_init_vm(struct kvm *kvm);
141extern void kvmppc_core_destroy_vm(struct kvm *kvm); 146extern void kvmppc_core_destroy_vm(struct kvm *kvm);
147extern void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
148 struct kvm_memory_slot *dont);
149extern int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
150 unsigned long npages);
142extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, 151extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
152 struct kvm_memory_slot *memslot,
143 struct kvm_userspace_memory_region *mem); 153 struct kvm_userspace_memory_region *mem);
144extern void kvmppc_core_commit_memory_region(struct kvm *kvm, 154extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
145 struct kvm_userspace_memory_region *mem); 155 struct kvm_userspace_memory_region *mem,
156 struct kvm_memory_slot old);
146extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, 157extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
147 struct kvm_ppc_smmu_info *info); 158 struct kvm_ppc_smmu_info *info);
159extern void kvmppc_core_flush_memslot(struct kvm *kvm,
160 struct kvm_memory_slot *memslot);
148 161
149extern int kvmppc_bookehv_init(void); 162extern int kvmppc_bookehv_init(void);
150extern void kvmppc_bookehv_exit(void); 163extern void kvmppc_bookehv_exit(void);
151 164
165extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu);
166
167extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *);
168
152/* 169/*
153 * Cuts out inst bits with ordering according to spec. 170 * Cuts out inst bits with ordering according to spec.
154 * That means the leftmost bit is zero. All given bits are included. 171 * That means the leftmost bit is zero. All given bits are included.
@@ -182,6 +199,41 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
182 return r; 199 return r;
183} 200}
184 201
202union kvmppc_one_reg {
203 u32 wval;
204 u64 dval;
205 vector128 vval;
206 u64 vsxval[2];
207 struct {
208 u64 addr;
209 u64 length;
210 } vpaval;
211};
212
213#define one_reg_size(id) \
214 (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
215
216#define get_reg_val(id, reg) ({ \
217 union kvmppc_one_reg __u; \
218 switch (one_reg_size(id)) { \
219 case 4: __u.wval = (reg); break; \
220 case 8: __u.dval = (reg); break; \
221 default: BUG(); \
222 } \
223 __u; \
224})
225
226
227#define set_reg_val(id, val) ({ \
228 u64 __v; \
229 switch (one_reg_size(id)) { \
230 case 4: __v = (val).wval; break; \
231 case 8: __v = (val).dval; break; \
232 default: BUG(); \
233 } \
234 __v; \
235})
236
185void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); 237void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
186int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); 238int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
187 239
@@ -190,6 +242,8 @@ int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
190 242
191int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); 243int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
192int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); 244int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
245int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
246int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
193 247
194void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid); 248void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
195 249
@@ -230,5 +284,36 @@ static inline void kvmppc_mmu_flush_icache(pfn_t pfn)
230 } 284 }
231} 285}
232 286
287/* Please call after prepare_to_enter. This function puts the lazy ee state
288 back to normal mode, without actually enabling interrupts. */
289static inline void kvmppc_lazy_ee_enable(void)
290{
291#ifdef CONFIG_PPC64
292 /* Only need to enable IRQs by hard enabling them after this */
293 local_paca->irq_happened = 0;
294 local_paca->soft_enabled = 1;
295#endif
296}
297
298static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)
299{
300 ulong ea;
301 ulong msr_64bit = 0;
302
303 ea = kvmppc_get_gpr(vcpu, rb);
304 if (ra)
305 ea += kvmppc_get_gpr(vcpu, ra);
306
307#if defined(CONFIG_PPC_BOOK3E_64)
308 msr_64bit = MSR_CM;
309#elif defined(CONFIG_PPC_BOOK3S_64)
310 msr_64bit = MSR_SF;
311#endif
312
313 if (!(vcpu->arch.shared->msr & msr_64bit))
314 ea = (uint32_t)ea;
315
316 return ea;
317}
233 318
234#endif /* __POWERPC_KVM_PPC_H__ */ 319#endif /* __POWERPC_KVM_PPC_H__ */
diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h
index c4231973edd3..19d9d96eb8d3 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -166,9 +166,6 @@ struct machdep_calls {
166 unsigned long size, 166 unsigned long size,
167 pgprot_t vma_prot); 167 pgprot_t vma_prot);
168 168
169 /* Idle loop for this platform, leave empty for default idle loop */
170 void (*idle_loop)(void);
171
172 /* 169 /*
173 * Function for waiting for work with reduced power in idle loop; 170 * Function for waiting for work with reduced power in idle loop;
174 * called with interrupts disabled. 171 * called with interrupts disabled.
@@ -320,28 +317,28 @@ static inline void log_error(char *buf, unsigned int err_type, int fatal)
320 ppc_md.log_error(buf, err_type, fatal); 317 ppc_md.log_error(buf, err_type, fatal);
321} 318}
322 319
323#define __define_machine_initcall(mach,level,fn,id) \ 320#define __define_machine_initcall(mach, fn, id) \
324 static int __init __machine_initcall_##mach##_##fn(void) { \ 321 static int __init __machine_initcall_##mach##_##fn(void) { \
325 if (machine_is(mach)) return fn(); \ 322 if (machine_is(mach)) return fn(); \
326 return 0; \ 323 return 0; \
327 } \ 324 } \
328 __define_initcall(level,__machine_initcall_##mach##_##fn,id); 325 __define_initcall(__machine_initcall_##mach##_##fn, id);
329 326
330#define machine_core_initcall(mach,fn) __define_machine_initcall(mach,"1",fn,1) 327#define machine_core_initcall(mach, fn) __define_machine_initcall(mach, fn, 1)
331#define machine_core_initcall_sync(mach,fn) __define_machine_initcall(mach,"1s",fn,1s) 328#define machine_core_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 1s)
332#define machine_postcore_initcall(mach,fn) __define_machine_initcall(mach,"2",fn,2) 329#define machine_postcore_initcall(mach, fn) __define_machine_initcall(mach, fn, 2)
333#define machine_postcore_initcall_sync(mach,fn) __define_machine_initcall(mach,"2s",fn,2s) 330#define machine_postcore_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 2s)
334#define machine_arch_initcall(mach,fn) __define_machine_initcall(mach,"3",fn,3) 331#define machine_arch_initcall(mach, fn) __define_machine_initcall(mach, fn, 3)
335#define machine_arch_initcall_sync(mach,fn) __define_machine_initcall(mach,"3s",fn,3s) 332#define machine_arch_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 3s)
336#define machine_subsys_initcall(mach,fn) __define_machine_initcall(mach,"4",fn,4) 333#define machine_subsys_initcall(mach, fn) __define_machine_initcall(mach, fn, 4)
337#define machine_subsys_initcall_sync(mach,fn) __define_machine_initcall(mach,"4s",fn,4s) 334#define machine_subsys_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 4s)
338#define machine_fs_initcall(mach,fn) __define_machine_initcall(mach,"5",fn,5) 335#define machine_fs_initcall(mach, fn) __define_machine_initcall(mach, fn, 5)
339#define machine_fs_initcall_sync(mach,fn) __define_machine_initcall(mach,"5s",fn,5s) 336#define machine_fs_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 5s)
340#define machine_rootfs_initcall(mach,fn) __define_machine_initcall(mach,"rootfs",fn,rootfs) 337#define machine_rootfs_initcall(mach, fn) __define_machine_initcall(mach, fn, rootfs)
341#define machine_device_initcall(mach,fn) __define_machine_initcall(mach,"6",fn,6) 338#define machine_device_initcall(mach, fn) __define_machine_initcall(mach, fn, 6)
342#define machine_device_initcall_sync(mach,fn) __define_machine_initcall(mach,"6s",fn,6s) 339#define machine_device_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 6s)
343#define machine_late_initcall(mach,fn) __define_machine_initcall(mach,"7",fn,7) 340#define machine_late_initcall(mach, fn) __define_machine_initcall(mach, fn, 7)
344#define machine_late_initcall_sync(mach,fn) __define_machine_initcall(mach,"7s",fn,7s) 341#define machine_late_initcall_sync(mach, fn) __define_machine_initcall(mach, fn, 7s)
345 342
346#endif /* __KERNEL__ */ 343#endif /* __KERNEL__ */
347#endif /* _ASM_POWERPC_MACHDEP_H */ 344#endif /* _ASM_POWERPC_MACHDEP_H */
diff --git a/arch/powerpc/include/asm/mmu-book3e.h b/arch/powerpc/include/asm/mmu-book3e.h
index eeabcdbc30f7..99d43e0c1e4a 100644
--- a/arch/powerpc/include/asm/mmu-book3e.h
+++ b/arch/powerpc/include/asm/mmu-book3e.h
@@ -59,7 +59,7 @@
59#define MAS1_TSIZE_SHIFT 7 59#define MAS1_TSIZE_SHIFT 7
60#define MAS1_TSIZE(x) (((x) << MAS1_TSIZE_SHIFT) & MAS1_TSIZE_MASK) 60#define MAS1_TSIZE(x) (((x) << MAS1_TSIZE_SHIFT) & MAS1_TSIZE_MASK)
61 61
62#define MAS2_EPN 0xFFFFF000 62#define MAS2_EPN (~0xFFFUL)
63#define MAS2_X0 0x00000040 63#define MAS2_X0 0x00000040
64#define MAS2_X1 0x00000020 64#define MAS2_X1 0x00000020
65#define MAS2_W 0x00000010 65#define MAS2_W 0x00000010
diff --git a/arch/powerpc/include/asm/mmu-hash64.h b/arch/powerpc/include/asm/mmu-hash64.h
index 9673f73eb8db..2fdb47a19efd 100644
--- a/arch/powerpc/include/asm/mmu-hash64.h
+++ b/arch/powerpc/include/asm/mmu-hash64.h
@@ -121,6 +121,16 @@ extern char initial_stab[];
121#define PP_RXRX 3 /* Supervisor read, User read */ 121#define PP_RXRX 3 /* Supervisor read, User read */
122#define PP_RXXX (HPTE_R_PP0 | 2) /* Supervisor read, user none */ 122#define PP_RXXX (HPTE_R_PP0 | 2) /* Supervisor read, user none */
123 123
124/* Fields for tlbiel instruction in architecture 2.06 */
125#define TLBIEL_INVAL_SEL_MASK 0xc00 /* invalidation selector */
126#define TLBIEL_INVAL_PAGE 0x000 /* invalidate a single page */
127#define TLBIEL_INVAL_SET_LPID 0x800 /* invalidate a set for current LPID */
128#define TLBIEL_INVAL_SET 0xc00 /* invalidate a set for all LPIDs */
129#define TLBIEL_INVAL_SET_MASK 0xfff000 /* set number to inval. */
130#define TLBIEL_INVAL_SET_SHIFT 12
131
132#define POWER7_TLB_SETS 128 /* # sets in POWER7 TLB */
133
124#ifndef __ASSEMBLY__ 134#ifndef __ASSEMBLY__
125 135
126struct hash_pte { 136struct hash_pte {
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 5e38eedea218..691fd8aca939 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -101,6 +101,7 @@
101#define MMU_FTRS_POWER5 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE 101#define MMU_FTRS_POWER5 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE
102#define MMU_FTRS_POWER6 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE 102#define MMU_FTRS_POWER6 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE
103#define MMU_FTRS_POWER7 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE 103#define MMU_FTRS_POWER7 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE
104#define MMU_FTRS_POWER8 MMU_FTRS_POWER4 | MMU_FTR_LOCKLESS_TLBIE
104#define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \ 105#define MMU_FTRS_CELL MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
105 MMU_FTR_CI_LARGE_PAGE 106 MMU_FTR_CI_LARGE_PAGE
106#define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \ 107#define MMU_FTRS_PA6T MMU_FTRS_DEFAULT_HPTE_ARCH_V2 | \
diff --git a/arch/powerpc/include/asm/pSeries_reconfig.h b/arch/powerpc/include/asm/pSeries_reconfig.h
deleted file mode 100644
index c07edfe98b98..000000000000
--- a/arch/powerpc/include/asm/pSeries_reconfig.h
+++ /dev/null
@@ -1,47 +0,0 @@
1#ifndef _PPC64_PSERIES_RECONFIG_H
2#define _PPC64_PSERIES_RECONFIG_H
3#ifdef __KERNEL__
4
5#include <linux/notifier.h>
6
7/*
8 * Use this API if your code needs to know about OF device nodes being
9 * added or removed on pSeries systems.
10 */
11
12#define PSERIES_RECONFIG_ADD 0x0001
13#define PSERIES_RECONFIG_REMOVE 0x0002
14#define PSERIES_DRCONF_MEM_ADD 0x0003
15#define PSERIES_DRCONF_MEM_REMOVE 0x0004
16#define PSERIES_UPDATE_PROPERTY 0x0005
17
18/**
19 * pSeries_reconfig_notify - Notifier value structure for OFDT property updates
20 *
21 * @node: Device tree node which owns the property being updated
22 * @property: Updated property
23 */
24struct pSeries_reconfig_prop_update {
25 struct device_node *node;
26 struct property *property;
27};
28
29#ifdef CONFIG_PPC_PSERIES
30extern int pSeries_reconfig_notifier_register(struct notifier_block *);
31extern void pSeries_reconfig_notifier_unregister(struct notifier_block *);
32extern int pSeries_reconfig_notify(unsigned long action, void *p);
33/* Not the best place to put this, will be fixed when we move some
34 * of the rtas suspend-me stuff to pseries */
35extern void pSeries_coalesce_init(void);
36#else /* !CONFIG_PPC_PSERIES */
37static inline int pSeries_reconfig_notifier_register(struct notifier_block *nb)
38{
39 return 0;
40}
41static inline void pSeries_reconfig_notifier_unregister(struct notifier_block *nb) { }
42static inline void pSeries_coalesce_init(void) { }
43#endif /* CONFIG_PPC_PSERIES */
44
45
46#endif /* __KERNEL__ */
47#endif /* _PPC64_PSERIES_RECONFIG_H */
diff --git a/arch/powerpc/include/asm/parport.h b/arch/powerpc/include/asm/parport.h
index 1ca1102b4a2f..6dc2577932b1 100644
--- a/arch/powerpc/include/asm/parport.h
+++ b/arch/powerpc/include/asm/parport.h
@@ -12,7 +12,7 @@
12 12
13#include <asm/prom.h> 13#include <asm/prom.h>
14 14
15static int __devinit parport_pc_find_nonpci_ports (int autoirq, int autodma) 15static int parport_pc_find_nonpci_ports (int autoirq, int autodma)
16{ 16{
17 struct device_node *np; 17 struct device_node *np;
18 const u32 *prop; 18 const u32 *prop;
diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index 5f73ce63fcae..51fb00a20d7e 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2009 Freescale Semicondutor, Inc. 2 * Copyright 2009 Freescale Semiconductor, Inc.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License 5 * modify it under the terms of the GNU General Public License
@@ -86,6 +86,7 @@
86#define PPC_INST_DCBA_MASK 0xfc0007fe 86#define PPC_INST_DCBA_MASK 0xfc0007fe
87#define PPC_INST_DCBAL 0x7c2005ec 87#define PPC_INST_DCBAL 0x7c2005ec
88#define PPC_INST_DCBZL 0x7c2007ec 88#define PPC_INST_DCBZL 0x7c2007ec
89#define PPC_INST_ICBT 0x7c00002c
89#define PPC_INST_ISEL 0x7c00001e 90#define PPC_INST_ISEL 0x7c00001e
90#define PPC_INST_ISEL_MASK 0xfc00003e 91#define PPC_INST_ISEL_MASK 0xfc00003e
91#define PPC_INST_LDARX 0x7c0000a8 92#define PPC_INST_LDARX 0x7c0000a8
@@ -168,9 +169,12 @@
168#define PPC_INST_AND 0x7c000038 169#define PPC_INST_AND 0x7c000038
169#define PPC_INST_ANDDOT 0x7c000039 170#define PPC_INST_ANDDOT 0x7c000039
170#define PPC_INST_OR 0x7c000378 171#define PPC_INST_OR 0x7c000378
172#define PPC_INST_XOR 0x7c000278
171#define PPC_INST_ANDI 0x70000000 173#define PPC_INST_ANDI 0x70000000
172#define PPC_INST_ORI 0x60000000 174#define PPC_INST_ORI 0x60000000
173#define PPC_INST_ORIS 0x64000000 175#define PPC_INST_ORIS 0x64000000
176#define PPC_INST_XORI 0x68000000
177#define PPC_INST_XORIS 0x6c000000
174#define PPC_INST_NEG 0x7c0000d0 178#define PPC_INST_NEG 0x7c0000d0
175#define PPC_INST_BRANCH 0x48000000 179#define PPC_INST_BRANCH 0x48000000
176#define PPC_INST_BRANCH_COND 0x40800000 180#define PPC_INST_BRANCH_COND 0x40800000
@@ -198,6 +202,7 @@
198#define __PPC_MB(s) (((s) & 0x1f) << 6) 202#define __PPC_MB(s) (((s) & 0x1f) << 6)
199#define __PPC_ME(s) (((s) & 0x1f) << 1) 203#define __PPC_ME(s) (((s) & 0x1f) << 1)
200#define __PPC_BI(s) (((s) & 0x1f) << 16) 204#define __PPC_BI(s) (((s) & 0x1f) << 16)
205#define __PPC_CT(t) (((t) & 0x0f) << 21)
201 206
202/* 207/*
203 * Only use the larx hint bit on 64bit CPUs. e500v1/v2 based CPUs will treat a 208 * Only use the larx hint bit on 64bit CPUs. e500v1/v2 based CPUs will treat a
@@ -260,6 +265,8 @@
260 __PPC_RS(t) | __PPC_RA0(a) | __PPC_RB(b)) 265 __PPC_RS(t) | __PPC_RA0(a) | __PPC_RB(b))
261#define PPC_SLBFEE_DOT(t, b) stringify_in_c(.long PPC_INST_SLBFEE | \ 266#define PPC_SLBFEE_DOT(t, b) stringify_in_c(.long PPC_INST_SLBFEE | \
262 __PPC_RT(t) | __PPC_RB(b)) 267 __PPC_RT(t) | __PPC_RB(b))
268#define PPC_ICBT(c,a,b) stringify_in_c(.long PPC_INST_ICBT | \
269 __PPC_CT(c) | __PPC_RA0(a) | __PPC_RB(b))
263/* PASemi instructions */ 270/* PASemi instructions */
264#define LBZCIX(t,a,b) stringify_in_c(.long PPC_INST_LBZCIX | \ 271#define LBZCIX(t,a,b) stringify_in_c(.long PPC_INST_LBZCIX | \
265 __PPC_RT(t) | __PPC_RA(a) | __PPC_RB(b)) 272 __PPC_RT(t) | __PPC_RA(a) | __PPC_RB(b))
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index b5c91901e384..99c92d5363e4 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -58,6 +58,22 @@ static inline int of_node_to_nid(struct device_node *device) { return 0; }
58 58
59extern void of_instantiate_rtc(void); 59extern void of_instantiate_rtc(void);
60 60
61/* The of_drconf_cell struct defines the layout of the LMB array
62 * specified in the device tree property
63 * ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory
64 */
65struct of_drconf_cell {
66 u64 base_addr;
67 u32 drc_index;
68 u32 reserved;
69 u32 aa_index;
70 u32 flags;
71};
72
73#define DRCONF_MEM_ASSIGNED 0x00000008
74#define DRCONF_MEM_AI_INVALID 0x00000040
75#define DRCONF_MEM_RESERVED 0x00000080
76
61/* These includes are put at the bottom because they may contain things 77/* These includes are put at the bottom because they may contain things
62 * that are overridden by this file. Ideally they shouldn't be included 78 * that are overridden by this file. Ideally they shouldn't be included
63 * by this file, but there are a bunch of .c files that currently depend 79 * by this file, but there are a bunch of .c files that currently depend
diff --git a/arch/powerpc/include/asm/qe.h b/arch/powerpc/include/asm/qe.h
index 229571a49391..32b9bfa0c9bd 100644
--- a/arch/powerpc/include/asm/qe.h
+++ b/arch/powerpc/include/asm/qe.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/include/asm/qe_ic.h b/arch/powerpc/include/asm/qe_ic.h
index f706164b0bd0..25784cc959a0 100644
--- a/arch/powerpc/include/asm/qe_ic.h
+++ b/arch/powerpc/include/asm/qe_ic.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index d24c14163966..3d5c9dc8917a 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -249,6 +249,8 @@
249#define LPCR_RMLS 0x1C000000 /* impl dependent rmo limit sel */ 249#define LPCR_RMLS 0x1C000000 /* impl dependent rmo limit sel */
250#define LPCR_RMLS_SH (63-37) 250#define LPCR_RMLS_SH (63-37)
251#define LPCR_ILE 0x02000000 /* !HV irqs set MSR:LE */ 251#define LPCR_ILE 0x02000000 /* !HV irqs set MSR:LE */
252#define LPCR_AIL_0 0x00000000 /* MMU off exception offset 0x0 */
253#define LPCR_AIL_3 0x01800000 /* MMU on exception offset 0xc00...4xxx */
252#define LPCR_PECE 0x00007000 /* powersave exit cause enable */ 254#define LPCR_PECE 0x00007000 /* powersave exit cause enable */
253#define LPCR_PECE0 0x00004000 /* ext. exceptions can cause exit */ 255#define LPCR_PECE0 0x00004000 /* ext. exceptions can cause exit */
254#define LPCR_PECE1 0x00002000 /* decrementer can cause exit */ 256#define LPCR_PECE1 0x00002000 /* decrementer can cause exit */
@@ -518,6 +520,7 @@
518#define SRR1_WS_DEEPER 0x00020000 /* Some resources not maintained */ 520#define SRR1_WS_DEEPER 0x00020000 /* Some resources not maintained */
519#define SRR1_WS_DEEP 0x00010000 /* All resources maintained */ 521#define SRR1_WS_DEEP 0x00010000 /* All resources maintained */
520#define SRR1_PROGFPE 0x00100000 /* Floating Point Enabled */ 522#define SRR1_PROGFPE 0x00100000 /* Floating Point Enabled */
523#define SRR1_PROGILL 0x00080000 /* Illegal instruction */
521#define SRR1_PROGPRIV 0x00040000 /* Privileged instruction */ 524#define SRR1_PROGPRIV 0x00040000 /* Privileged instruction */
522#define SRR1_PROGTRAP 0x00020000 /* Trap */ 525#define SRR1_PROGTRAP 0x00020000 /* Trap */
523#define SRR1_PROGADDR 0x00010000 /* SRR0 contains subsequent addr */ 526#define SRR1_PROGADDR 0x00010000 /* SRR0 contains subsequent addr */
@@ -1029,6 +1032,7 @@
1029#define PVR_970MP 0x0044 1032#define PVR_970MP 0x0044
1030#define PVR_970GX 0x0045 1033#define PVR_970GX 0x0045
1031#define PVR_POWER7p 0x004A 1034#define PVR_POWER7p 0x004A
1035#define PVR_POWER8 0x004B
1032#define PVR_BE 0x0070 1036#define PVR_BE 0x0070
1033#define PVR_PA6T 0x0090 1037#define PVR_PA6T 0x0090
1034 1038
diff --git a/arch/powerpc/include/asm/reg_booke.h b/arch/powerpc/include/asm/reg_booke.h
index 2d916c4982c5..e07e6af5e1ff 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -539,6 +539,13 @@
539#define TCR_FIE 0x00800000 /* FIT Interrupt Enable */ 539#define TCR_FIE 0x00800000 /* FIT Interrupt Enable */
540#define TCR_ARE 0x00400000 /* Auto Reload Enable */ 540#define TCR_ARE 0x00400000 /* Auto Reload Enable */
541 541
542#ifdef CONFIG_E500
543#define TCR_GET_WP(tcr) ((((tcr) & 0xC0000000) >> 30) | \
544 (((tcr) & 0x1E0000) >> 15))
545#else
546#define TCR_GET_WP(tcr) (((tcr) & 0xC0000000) >> 30)
547#endif
548
542/* Bit definitions for the TSR. */ 549/* Bit definitions for the TSR. */
543#define TSR_ENW 0x80000000 /* Enable Next Watchdog */ 550#define TSR_ENW 0x80000000 /* Enable Next Watchdog */
544#define TSR_WIS 0x40000000 /* WDT Interrupt Status */ 551#define TSR_WIS 0x40000000 /* WDT Interrupt Status */
diff --git a/arch/powerpc/include/asm/rtas.h b/arch/powerpc/include/asm/rtas.h
index 557cff845dee..aef00c675905 100644
--- a/arch/powerpc/include/asm/rtas.h
+++ b/arch/powerpc/include/asm/rtas.h
@@ -353,8 +353,13 @@ static inline int page_is_rtas_user_buf(unsigned long pfn)
353 return 1; 353 return 1;
354 return 0; 354 return 0;
355} 355}
356
357/* Not the best place to put pSeries_coalesce_init, will be fixed when we
358 * move some of the rtas suspend-me stuff to pseries */
359extern void pSeries_coalesce_init(void);
356#else 360#else
357static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;} 361static inline int page_is_rtas_user_buf(unsigned long pfn) { return 0;}
362static inline void pSeries_coalesce_init(void) { }
358#endif 363#endif
359 364
360extern int call_rtas(const char *, int, int, unsigned long *, ...); 365extern int call_rtas(const char *, int, int, unsigned long *, ...);
diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
new file mode 100644
index 000000000000..d3ca85529b8b
--- /dev/null
+++ b/arch/powerpc/include/asm/setup.h
@@ -0,0 +1,29 @@
1#ifndef _ASM_POWERPC_SETUP_H
2#define _ASM_POWERPC_SETUP_H
3
4#include <uapi/asm/setup.h>
5
6#ifndef __ASSEMBLY__
7extern void ppc_printk_progress(char *s, unsigned short hex);
8
9extern unsigned int rtas_data;
10extern int mem_init_done; /* set on boot once kmalloc can be called */
11extern int init_bootmem_done; /* set once bootmem is available */
12extern unsigned long long memory_limit;
13extern unsigned long klimit;
14extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
15
16struct device_node;
17extern void note_scsi_host(struct device_node *, void *);
18
19/* Used in very early kernel initialization. */
20extern unsigned long reloc_offset(void);
21extern unsigned long add_reloc_offset(unsigned long);
22extern void reloc_got2(unsigned long);
23
24#define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
25
26#endif /* !__ASSEMBLY__ */
27
28#endif /* _ASM_POWERPC_SETUP_H */
29
diff --git a/arch/powerpc/include/asm/signal.h b/arch/powerpc/include/asm/signal.h
index 189998bb61c4..a101637725a2 100644
--- a/arch/powerpc/include/asm/signal.h
+++ b/arch/powerpc/include/asm/signal.h
@@ -3,6 +3,4 @@
3 3
4#include <uapi/asm/signal.h> 4#include <uapi/asm/signal.h>
5 5
6struct pt_regs;
7#define ptrace_signal_deliver(regs, cookie) do { } while (0)
8#endif /* _ASM_POWERPC_SIGNAL_H */ 6#endif /* _ASM_POWERPC_SIGNAL_H */
diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
index e807e9d8e3f7..195ce2ac5691 100644
--- a/arch/powerpc/include/asm/smp.h
+++ b/arch/powerpc/include/asm/smp.h
@@ -54,8 +54,8 @@ struct smp_ops_t {
54 54
55extern void smp_send_debugger_break(void); 55extern void smp_send_debugger_break(void);
56extern void start_secondary_resume(void); 56extern void start_secondary_resume(void);
57extern void __devinit smp_generic_give_timebase(void); 57extern void smp_generic_give_timebase(void);
58extern void __devinit smp_generic_take_timebase(void); 58extern void smp_generic_take_timebase(void);
59 59
60DECLARE_PER_CPU(unsigned int, cpu_pvr); 60DECLARE_PER_CPU(unsigned int, cpu_pvr);
61 61
@@ -67,6 +67,14 @@ void generic_mach_cpu_die(void);
67void generic_set_cpu_dead(unsigned int cpu); 67void generic_set_cpu_dead(unsigned int cpu);
68void generic_set_cpu_up(unsigned int cpu); 68void generic_set_cpu_up(unsigned int cpu);
69int generic_check_cpu_restart(unsigned int cpu); 69int generic_check_cpu_restart(unsigned int cpu);
70
71extern void inhibit_secondary_onlining(void);
72extern void uninhibit_secondary_onlining(void);
73
74#else /* HOTPLUG_CPU */
75static inline void inhibit_secondary_onlining(void) {}
76static inline void uninhibit_secondary_onlining(void) {}
77
70#endif 78#endif
71 79
72#ifdef CONFIG_PPC64 80#ifdef CONFIG_PPC64
diff --git a/arch/powerpc/include/asm/syscalls.h b/arch/powerpc/include/asm/syscalls.h
index 329db4ec12ca..b5308d3e6d39 100644
--- a/arch/powerpc/include/asm/syscalls.h
+++ b/arch/powerpc/include/asm/syscalls.h
@@ -17,15 +17,6 @@ asmlinkage unsigned long sys_mmap(unsigned long addr, size_t len,
17asmlinkage unsigned long sys_mmap2(unsigned long addr, size_t len, 17asmlinkage unsigned long sys_mmap2(unsigned long addr, size_t len,
18 unsigned long prot, unsigned long flags, 18 unsigned long prot, unsigned long flags,
19 unsigned long fd, unsigned long pgoff); 19 unsigned long fd, unsigned long pgoff);
20asmlinkage int sys_clone(unsigned long clone_flags, unsigned long usp,
21 int __user *parent_tidp, void __user *child_threadptr,
22 int __user *child_tidp, int p6, struct pt_regs *regs);
23asmlinkage int sys_fork(unsigned long p1, unsigned long p2,
24 unsigned long p3, unsigned long p4, unsigned long p5,
25 unsigned long p6, struct pt_regs *regs);
26asmlinkage int sys_vfork(unsigned long p1, unsigned long p2,
27 unsigned long p3, unsigned long p4, unsigned long p5,
28 unsigned long p6, struct pt_regs *regs);
29asmlinkage long sys_pipe(int __user *fildes); 20asmlinkage long sys_pipe(int __user *fildes);
30asmlinkage long sys_pipe2(int __user *fildes, int flags); 21asmlinkage long sys_pipe2(int __user *fildes, int flags);
31asmlinkage long sys_rt_sigaction(int sig, 22asmlinkage long sys_rt_sigaction(int sig,
diff --git a/arch/powerpc/include/asm/systbl.h b/arch/powerpc/include/asm/systbl.h
index 840838769853..97909d3b1d7b 100644
--- a/arch/powerpc/include/asm/systbl.h
+++ b/arch/powerpc/include/asm/systbl.h
@@ -164,7 +164,7 @@ COMPAT_SYS_SPU(sched_getscheduler)
164SYSCALL_SPU(sched_yield) 164SYSCALL_SPU(sched_yield)
165COMPAT_SYS_SPU(sched_get_priority_max) 165COMPAT_SYS_SPU(sched_get_priority_max)
166COMPAT_SYS_SPU(sched_get_priority_min) 166COMPAT_SYS_SPU(sched_get_priority_min)
167COMPAT_SYS_SPU(sched_rr_get_interval) 167SYSX_SPU(sys_sched_rr_get_interval,compat_sys_sched_rr_get_interval_wrapper,sys_sched_rr_get_interval)
168COMPAT_SYS_SPU(nanosleep) 168COMPAT_SYS_SPU(nanosleep)
169SYSCALL_SPU(mremap) 169SYSCALL_SPU(mremap)
170SYSCALL_SPU(setresuid) 170SYSCALL_SPU(setresuid)
@@ -356,3 +356,4 @@ COMPAT_SYS_SPU(sendmmsg)
356SYSCALL_SPU(setns) 356SYSCALL_SPU(setns)
357COMPAT_SYS(process_vm_readv) 357COMPAT_SYS(process_vm_readv)
358COMPAT_SYS(process_vm_writev) 358COMPAT_SYS(process_vm_writev)
359SYSCALL(finit_module)
diff --git a/arch/powerpc/include/asm/ucc.h b/arch/powerpc/include/asm/ucc.h
index 46b09ba6bead..6927ac26516e 100644
--- a/arch/powerpc/include/asm/ucc.h
+++ b/arch/powerpc/include/asm/ucc.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/include/asm/ucc_fast.h b/arch/powerpc/include/asm/ucc_fast.h
index 4644c840e2fa..72ea9bab07df 100644
--- a/arch/powerpc/include/asm/ucc_fast.h
+++ b/arch/powerpc/include/asm/ucc_fast.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Internal header file for UCC FAST unit routines. 2 * Internal header file for UCC FAST unit routines.
3 * 3 *
4 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 4 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
5 * 5 *
6 * Authors: Shlomi Gridish <gridish@freescale.com> 6 * Authors: Shlomi Gridish <gridish@freescale.com>
7 * Li Yang <leoli@freescale.com> 7 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/include/asm/ucc_slow.h b/arch/powerpc/include/asm/ucc_slow.h
index cf131ffdb8d1..c44131e68e11 100644
--- a/arch/powerpc/include/asm/ucc_slow.h
+++ b/arch/powerpc/include/asm/ucc_slow.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/include/asm/udbg.h b/arch/powerpc/include/asm/udbg.h
index b3038817b8dc..5a7510e9d09d 100644
--- a/arch/powerpc/include/asm/udbg.h
+++ b/arch/powerpc/include/asm/udbg.h
@@ -21,7 +21,6 @@ extern int (*udbg_getc_poll)(void);
21 21
22extern void udbg_puts(const char *s); 22extern void udbg_puts(const char *s);
23extern int udbg_write(const char *s, int n); 23extern int udbg_write(const char *s, int n);
24extern int udbg_read(char *buf, int buflen);
25 24
26extern void register_early_udbg_console(void); 25extern void register_early_udbg_console(void);
27extern void udbg_printf(const char *fmt, ...) 26extern void udbg_printf(const char *fmt, ...)
diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h
index 921dce6d8445..1d4864a40e35 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ b/arch/powerpc/include/asm/unistd.h
@@ -12,7 +12,7 @@
12#include <uapi/asm/unistd.h> 12#include <uapi/asm/unistd.h>
13 13
14 14
15#define __NR_syscalls 353 15#define __NR_syscalls 354
16 16
17#define __NR__exit __NR_exit 17#define __NR__exit __NR_exit
18#define NR_syscalls __NR_syscalls 18#define NR_syscalls __NR_syscalls
@@ -54,9 +54,11 @@
54#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND 54#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
55#define __ARCH_WANT_SYS_NEWFSTATAT 55#define __ARCH_WANT_SYS_NEWFSTATAT
56#define __ARCH_WANT_COMPAT_SYS_SENDFILE 56#define __ARCH_WANT_COMPAT_SYS_SENDFILE
57#define __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL
57#endif 58#endif
58#define __ARCH_WANT_SYS_EXECVE 59#define __ARCH_WANT_SYS_FORK
59#define __ARCH_WANT_KERNEL_EXECVE 60#define __ARCH_WANT_SYS_VFORK
61#define __ARCH_WANT_SYS_CLONE
60 62
61/* 63/*
62 * "Conditional" syscalls 64 * "Conditional" syscalls
diff --git a/arch/powerpc/include/asm/vio.h b/arch/powerpc/include/asm/vio.h
index df81cb72d1e0..68d0cc998b1b 100644
--- a/arch/powerpc/include/asm/vio.h
+++ b/arch/powerpc/include/asm/vio.h
@@ -139,7 +139,7 @@ extern void vio_unregister_driver(struct vio_driver *drv);
139extern int vio_cmo_entitlement_update(size_t); 139extern int vio_cmo_entitlement_update(size_t);
140extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired); 140extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
141 141
142extern void __devinit vio_unregister_device(struct vio_dev *dev); 142extern void vio_unregister_device(struct vio_dev *dev);
143 143
144extern int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op); 144extern int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op);
145 145
diff --git a/arch/powerpc/include/uapi/asm/Kbuild b/arch/powerpc/include/uapi/asm/Kbuild
index a33c3c03bb2e..f7bca6370745 100644
--- a/arch/powerpc/include/uapi/asm/Kbuild
+++ b/arch/powerpc/include/uapi/asm/Kbuild
@@ -7,6 +7,7 @@ header-y += bootx.h
7header-y += byteorder.h 7header-y += byteorder.h
8header-y += cputable.h 8header-y += cputable.h
9header-y += elf.h 9header-y += elf.h
10header-y += epapr_hcalls.h
10header-y += errno.h 11header-y += errno.h
11header-y += fcntl.h 12header-y += fcntl.h
12header-y += ioctl.h 13header-y += ioctl.h
diff --git a/arch/powerpc/include/uapi/asm/epapr_hcalls.h b/arch/powerpc/include/uapi/asm/epapr_hcalls.h
new file mode 100644
index 000000000000..7f9c74b46704
--- /dev/null
+++ b/arch/powerpc/include/uapi/asm/epapr_hcalls.h
@@ -0,0 +1,98 @@
1/*
2 * ePAPR hcall interface
3 *
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 *
6 * Author: Timur Tabi <timur@freescale.com>
7 *
8 * This file is provided under a dual BSD/GPL license. When using or
9 * redistributing this file, you may do so under either license.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * * Neither the name of Freescale Semiconductor nor the
19 * names of its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 *
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
26 * later version.
27 *
28 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
29 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifndef _UAPI_ASM_POWERPC_EPAPR_HCALLS_H
41#define _UAPI_ASM_POWERPC_EPAPR_HCALLS_H
42
43#define EV_BYTE_CHANNEL_SEND 1
44#define EV_BYTE_CHANNEL_RECEIVE 2
45#define EV_BYTE_CHANNEL_POLL 3
46#define EV_INT_SET_CONFIG 4
47#define EV_INT_GET_CONFIG 5
48#define EV_INT_SET_MASK 6
49#define EV_INT_GET_MASK 7
50#define EV_INT_IACK 9
51#define EV_INT_EOI 10
52#define EV_INT_SEND_IPI 11
53#define EV_INT_SET_TASK_PRIORITY 12
54#define EV_INT_GET_TASK_PRIORITY 13
55#define EV_DOORBELL_SEND 14
56#define EV_MSGSND 15
57#define EV_IDLE 16
58
59/* vendor ID: epapr */
60#define EV_LOCAL_VENDOR_ID 0 /* for private use */
61#define EV_EPAPR_VENDOR_ID 1
62#define EV_FSL_VENDOR_ID 2 /* Freescale Semiconductor */
63#define EV_IBM_VENDOR_ID 3 /* IBM */
64#define EV_GHS_VENDOR_ID 4 /* Green Hills Software */
65#define EV_ENEA_VENDOR_ID 5 /* Enea */
66#define EV_WR_VENDOR_ID 6 /* Wind River Systems */
67#define EV_AMCC_VENDOR_ID 7 /* Applied Micro Circuits */
68#define EV_KVM_VENDOR_ID 42 /* KVM */
69
70/* The max number of bytes that a byte channel can send or receive per call */
71#define EV_BYTE_CHANNEL_MAX_BYTES 16
72
73
74#define _EV_HCALL_TOKEN(id, num) (((id) << 16) | (num))
75#define EV_HCALL_TOKEN(hcall_num) _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, hcall_num)
76
77/* epapr return codes */
78#define EV_SUCCESS 0
79#define EV_EPERM 1 /* Operation not permitted */
80#define EV_ENOENT 2 /* Entry Not Found */
81#define EV_EIO 3 /* I/O error occured */
82#define EV_EAGAIN 4 /* The operation had insufficient
83 * resources to complete and should be
84 * retried
85 */
86#define EV_ENOMEM 5 /* There was insufficient memory to
87 * complete the operation */
88#define EV_EFAULT 6 /* Bad guest address */
89#define EV_ENODEV 7 /* No such device */
90#define EV_EINVAL 8 /* An argument supplied to the hcall
91 was out of range or invalid */
92#define EV_INTERNAL 9 /* An internal error occured */
93#define EV_CONFIG 10 /* A configuration error was detected */
94#define EV_INVALID_STATE 11 /* The object is in an invalid state */
95#define EV_UNIMPLEMENTED 12 /* Unimplemented hypercall */
96#define EV_BUFFER_OVERFLOW 13 /* Caller-supplied buffer too small */
97
98#endif /* _UAPI_ASM_POWERPC_EPAPR_HCALLS_H */
diff --git a/arch/powerpc/include/uapi/asm/ioctls.h b/arch/powerpc/include/uapi/asm/ioctls.h
index e9b78870aaab..49a25796a61a 100644
--- a/arch/powerpc/include/uapi/asm/ioctls.h
+++ b/arch/powerpc/include/uapi/asm/ioctls.h
@@ -97,6 +97,9 @@
97#define TIOCGDEV _IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */ 97#define TIOCGDEV _IOR('T',0x32, unsigned int) /* Get primary device node of /dev/console */
98#define TIOCSIG _IOW('T',0x36, int) /* Generate signal on Pty slave */ 98#define TIOCSIG _IOW('T',0x36, int) /* Generate signal on Pty slave */
99#define TIOCVHANGUP 0x5437 99#define TIOCVHANGUP 0x5437
100#define TIOCGPKT _IOR('T', 0x38, int) /* Get packet mode state */
101#define TIOCGPTLCK _IOR('T', 0x39, int) /* Get Pty lock state */
102#define TIOCGEXCL _IOR('T', 0x40, int) /* Get exclusive mode state */
100 103
101#define TIOCSERCONFIG 0x5453 104#define TIOCSERCONFIG 0x5453
102#define TIOCSERGWILD 0x5454 105#define TIOCSERGWILD 0x5454
diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h
index 1bea4d8ea6f4..2fba8a66fb10 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -221,6 +221,12 @@ struct kvm_sregs {
221 221
222 __u32 dbsr; /* KVM_SREGS_E_UPDATE_DBSR */ 222 __u32 dbsr; /* KVM_SREGS_E_UPDATE_DBSR */
223 __u32 dbcr[3]; 223 __u32 dbcr[3];
224 /*
225 * iac/dac registers are 64bit wide, while this API
226 * interface provides only lower 32 bits on 64 bit
227 * processors. ONE_REG interface is added for 64bit
228 * iac/dac registers.
229 */
224 __u32 iac[4]; 230 __u32 iac[4];
225 __u32 dac[2]; 231 __u32 dac[2];
226 __u32 dvc[2]; 232 __u32 dvc[2];
@@ -325,6 +331,86 @@ struct kvm_book3e_206_tlb_params {
325 __u32 reserved[8]; 331 __u32 reserved[8];
326}; 332};
327 333
334/* For KVM_PPC_GET_HTAB_FD */
335struct kvm_get_htab_fd {
336 __u64 flags;
337 __u64 start_index;
338 __u64 reserved[2];
339};
340
341/* Values for kvm_get_htab_fd.flags */
342#define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
343#define KVM_GET_HTAB_WRITE ((__u64)0x2)
344
345/*
346 * Data read on the file descriptor is formatted as a series of
347 * records, each consisting of a header followed by a series of
348 * `n_valid' HPTEs (16 bytes each), which are all valid. Following
349 * those valid HPTEs there are `n_invalid' invalid HPTEs, which
350 * are not represented explicitly in the stream. The same format
351 * is used for writing.
352 */
353struct kvm_get_htab_header {
354 __u32 index;
355 __u16 n_valid;
356 __u16 n_invalid;
357};
358
328#define KVM_REG_PPC_HIOR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x1) 359#define KVM_REG_PPC_HIOR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x1)
360#define KVM_REG_PPC_IAC1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x2)
361#define KVM_REG_PPC_IAC2 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x3)
362#define KVM_REG_PPC_IAC3 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x4)
363#define KVM_REG_PPC_IAC4 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x5)
364#define KVM_REG_PPC_DAC1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x6)
365#define KVM_REG_PPC_DAC2 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x7)
366#define KVM_REG_PPC_DABR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8)
367#define KVM_REG_PPC_DSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9)
368#define KVM_REG_PPC_PURR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa)
369#define KVM_REG_PPC_SPURR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb)
370#define KVM_REG_PPC_DAR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc)
371#define KVM_REG_PPC_DSISR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xd)
372#define KVM_REG_PPC_AMR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xe)
373#define KVM_REG_PPC_UAMOR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xf)
374
375#define KVM_REG_PPC_MMCR0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
376#define KVM_REG_PPC_MMCR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
377#define KVM_REG_PPC_MMCRA (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
378
379#define KVM_REG_PPC_PMC1 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
380#define KVM_REG_PPC_PMC2 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
381#define KVM_REG_PPC_PMC3 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1a)
382#define KVM_REG_PPC_PMC4 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1b)
383#define KVM_REG_PPC_PMC5 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1c)
384#define KVM_REG_PPC_PMC6 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1d)
385#define KVM_REG_PPC_PMC7 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
386#define KVM_REG_PPC_PMC8 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
387
388/* 32 floating-point registers */
389#define KVM_REG_PPC_FPR0 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x20)
390#define KVM_REG_PPC_FPR(n) (KVM_REG_PPC_FPR0 + (n))
391#define KVM_REG_PPC_FPR31 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x3f)
392
393/* 32 VMX/Altivec vector registers */
394#define KVM_REG_PPC_VR0 (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x40)
395#define KVM_REG_PPC_VR(n) (KVM_REG_PPC_VR0 + (n))
396#define KVM_REG_PPC_VR31 (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x5f)
397
398/* 32 double-width FP registers for VSX */
399/* High-order halves overlap with FP regs */
400#define KVM_REG_PPC_VSR0 (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x60)
401#define KVM_REG_PPC_VSR(n) (KVM_REG_PPC_VSR0 + (n))
402#define KVM_REG_PPC_VSR31 (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x7f)
403
404/* FP and vector status/control registers */
405#define KVM_REG_PPC_FPSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
406#define KVM_REG_PPC_VSCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
407
408/* Virtual processor areas */
409/* For SLB & DTL, address in high (first) half, length in low half */
410#define KVM_REG_PPC_VPA_ADDR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x82)
411#define KVM_REG_PPC_VPA_SLB (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x83)
412#define KVM_REG_PPC_VPA_DTL (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x84)
413
414#define KVM_REG_PPC_EPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x85)
329 415
330#endif /* __LINUX_KVM_POWERPC_H */ 416#endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/uapi/asm/kvm_para.h b/arch/powerpc/include/uapi/asm/kvm_para.h
index 5e04383a1db5..e3af3286a068 100644
--- a/arch/powerpc/include/uapi/asm/kvm_para.h
+++ b/arch/powerpc/include/uapi/asm/kvm_para.h
@@ -75,9 +75,10 @@ struct kvm_vcpu_arch_shared {
75}; 75};
76 76
77#define KVM_SC_MAGIC_R0 0x4b564d21 /* "KVM!" */ 77#define KVM_SC_MAGIC_R0 0x4b564d21 /* "KVM!" */
78#define HC_VENDOR_KVM (42 << 16) 78
79#define HC_EV_SUCCESS 0 79#define KVM_HCALL_TOKEN(num) _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
80#define HC_EV_UNIMPLEMENTED 12 80
81#include <asm/epapr_hcalls.h>
81 82
82#define KVM_FEATURE_MAGIC_PAGE 1 83#define KVM_FEATURE_MAGIC_PAGE 1
83 84
diff --git a/arch/powerpc/include/uapi/asm/setup.h b/arch/powerpc/include/uapi/asm/setup.h
index 8b9a306260b2..552df83f1a49 100644
--- a/arch/powerpc/include/uapi/asm/setup.h
+++ b/arch/powerpc/include/uapi/asm/setup.h
@@ -1,32 +1 @@
1#ifndef _ASM_POWERPC_SETUP_H
2#define _ASM_POWERPC_SETUP_H
3
4#include <asm-generic/setup.h> #include <asm-generic/setup.h>
5
6#ifndef __ASSEMBLY__
7extern void ppc_printk_progress(char *s, unsigned short hex);
8
9extern unsigned int rtas_data;
10extern int mem_init_done; /* set on boot once kmalloc can be called */
11extern int init_bootmem_done; /* set once bootmem is available */
12extern unsigned long long memory_limit;
13extern unsigned long klimit;
14extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
15
16extern void via_cuda_init(void);
17extern void read_rtc_time(void);
18extern void pmac_find_display(void);
19
20struct device_node;
21extern void note_scsi_host(struct device_node *, void *);
22
23/* Used in very early kernel initialization. */
24extern unsigned long reloc_offset(void);
25extern unsigned long add_reloc_offset(unsigned long);
26extern void reloc_got2(unsigned long);
27
28#define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
29
30#endif /* !__ASSEMBLY__ */
31
32#endif /* _ASM_POWERPC_SETUP_H */
diff --git a/arch/powerpc/include/uapi/asm/signal.h b/arch/powerpc/include/uapi/asm/signal.h
index 48fa8d3f2f9a..e079fb39d5bc 100644
--- a/arch/powerpc/include/uapi/asm/signal.h
+++ b/arch/powerpc/include/uapi/asm/signal.h
@@ -85,12 +85,6 @@ typedef struct {
85 85
86#define SA_RESTORER 0x04000000U 86#define SA_RESTORER 0x04000000U
87 87
88/*
89 * sigaltstack controls
90 */
91#define SS_ONSTACK 1
92#define SS_DISABLE 2
93
94#define MINSIGSTKSZ 2048 88#define MINSIGSTKSZ 2048
95#define SIGSTKSZ 8192 89#define SIGSTKSZ 8192
96 90
diff --git a/arch/powerpc/include/uapi/asm/socket.h b/arch/powerpc/include/uapi/asm/socket.h
index 3d5179bb122f..eb0b1864d400 100644
--- a/arch/powerpc/include/uapi/asm/socket.h
+++ b/arch/powerpc/include/uapi/asm/socket.h
@@ -47,6 +47,7 @@
47/* Socket filtering */ 47/* Socket filtering */
48#define SO_ATTACH_FILTER 26 48#define SO_ATTACH_FILTER 26
49#define SO_DETACH_FILTER 27 49#define SO_DETACH_FILTER 27
50#define SO_GET_FILTER SO_ATTACH_FILTER
50 51
51#define SO_PEERNAME 28 52#define SO_PEERNAME 28
52#define SO_TIMESTAMP 29 53#define SO_TIMESTAMP 29
diff --git a/arch/powerpc/include/uapi/asm/unistd.h b/arch/powerpc/include/uapi/asm/unistd.h
index 380b5d37a904..8c478c6c6b1e 100644
--- a/arch/powerpc/include/uapi/asm/unistd.h
+++ b/arch/powerpc/include/uapi/asm/unistd.h
@@ -375,6 +375,7 @@
375#define __NR_setns 350 375#define __NR_setns 350
376#define __NR_process_vm_readv 351 376#define __NR_process_vm_readv 351
377#define __NR_process_vm_writev 352 377#define __NR_process_vm_writev 352
378#define __NR_finit_module 353
378 379
379 380
380#endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */ 381#endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index cde12f8a4ebc..8f619342f14c 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -38,7 +38,7 @@ obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \
38 paca.o nvram_64.o firmware.o 38 paca.o nvram_64.o firmware.o
39obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o 39obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
40obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o 40obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o
41obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power7.o 41obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power.o
42obj64-$(CONFIG_RELOCATABLE) += reloc_64.o 42obj64-$(CONFIG_RELOCATABLE) += reloc_64.o
43obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o 43obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o
44obj-$(CONFIG_PPC_A2) += cpu_setup_a2.o 44obj-$(CONFIG_PPC_A2) += cpu_setup_a2.o
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 7523539cfe9f..4e23ba2f3ca7 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -441,8 +441,7 @@ int main(void)
441 DEFINE(KVM_HOST_LPCR, offsetof(struct kvm, arch.host_lpcr)); 441 DEFINE(KVM_HOST_LPCR, offsetof(struct kvm, arch.host_lpcr));
442 DEFINE(KVM_HOST_SDR1, offsetof(struct kvm, arch.host_sdr1)); 442 DEFINE(KVM_HOST_SDR1, offsetof(struct kvm, arch.host_sdr1));
443 DEFINE(KVM_TLBIE_LOCK, offsetof(struct kvm, arch.tlbie_lock)); 443 DEFINE(KVM_TLBIE_LOCK, offsetof(struct kvm, arch.tlbie_lock));
444 DEFINE(KVM_ONLINE_CPUS, offsetof(struct kvm, online_vcpus.counter)); 444 DEFINE(KVM_NEED_FLUSH, offsetof(struct kvm, arch.need_tlb_flush.bits));
445 DEFINE(KVM_LAST_VCPU, offsetof(struct kvm, arch.last_vcpu));
446 DEFINE(KVM_LPCR, offsetof(struct kvm, arch.lpcr)); 445 DEFINE(KVM_LPCR, offsetof(struct kvm, arch.lpcr));
447 DEFINE(KVM_RMOR, offsetof(struct kvm, arch.rmor)); 446 DEFINE(KVM_RMOR, offsetof(struct kvm, arch.rmor));
448 DEFINE(KVM_VRMA_SLB_V, offsetof(struct kvm, arch.vrma_slb_v)); 447 DEFINE(KVM_VRMA_SLB_V, offsetof(struct kvm, arch.vrma_slb_v));
@@ -470,7 +469,6 @@ int main(void)
470 DEFINE(VCPU_SLB, offsetof(struct kvm_vcpu, arch.slb)); 469 DEFINE(VCPU_SLB, offsetof(struct kvm_vcpu, arch.slb));
471 DEFINE(VCPU_SLB_MAX, offsetof(struct kvm_vcpu, arch.slb_max)); 470 DEFINE(VCPU_SLB_MAX, offsetof(struct kvm_vcpu, arch.slb_max));
472 DEFINE(VCPU_SLB_NR, offsetof(struct kvm_vcpu, arch.slb_nr)); 471 DEFINE(VCPU_SLB_NR, offsetof(struct kvm_vcpu, arch.slb_nr));
473 DEFINE(VCPU_LAST_CPU, offsetof(struct kvm_vcpu, arch.last_cpu));
474 DEFINE(VCPU_FAULT_DSISR, offsetof(struct kvm_vcpu, arch.fault_dsisr)); 472 DEFINE(VCPU_FAULT_DSISR, offsetof(struct kvm_vcpu, arch.fault_dsisr));
475 DEFINE(VCPU_FAULT_DAR, offsetof(struct kvm_vcpu, arch.fault_dar)); 473 DEFINE(VCPU_FAULT_DAR, offsetof(struct kvm_vcpu, arch.fault_dar));
476 DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); 474 DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
diff --git a/arch/powerpc/kernel/cpu_setup_power7.S b/arch/powerpc/kernel/cpu_setup_power.S
index 76797c5105d6..57cf14065aec 100644
--- a/arch/powerpc/kernel/cpu_setup_power7.S
+++ b/arch/powerpc/kernel/cpu_setup_power.S
@@ -27,6 +27,7 @@ _GLOBAL(__setup_cpu_power7)
27 beqlr 27 beqlr
28 li r0,0 28 li r0,0
29 mtspr SPRN_LPID,r0 29 mtspr SPRN_LPID,r0
30 mfspr r3,SPRN_LPCR
30 bl __init_LPCR 31 bl __init_LPCR
31 bl __init_TLB 32 bl __init_TLB
32 mtlr r11 33 mtlr r11
@@ -39,6 +40,35 @@ _GLOBAL(__restore_cpu_power7)
39 beqlr 40 beqlr
40 li r0,0 41 li r0,0
41 mtspr SPRN_LPID,r0 42 mtspr SPRN_LPID,r0
43 mfspr r3,SPRN_LPCR
44 bl __init_LPCR
45 bl __init_TLB
46 mtlr r11
47 blr
48
49_GLOBAL(__setup_cpu_power8)
50 mflr r11
51 bl __init_hvmode_206
52 mtlr r11
53 beqlr
54 li r0,0
55 mtspr SPRN_LPID,r0
56 mfspr r3,SPRN_LPCR
57 oris r3, r3, LPCR_AIL_3@h
58 bl __init_LPCR
59 bl __init_TLB
60 mtlr r11
61 blr
62
63_GLOBAL(__restore_cpu_power8)
64 mflr r11
65 mfmsr r3
66 rldicl. r0,r3,4,63
67 beqlr
68 li r0,0
69 mtspr SPRN_LPID,r0
70 mfspr r3,SPRN_LPCR
71 oris r3, r3, LPCR_AIL_3@h
42 bl __init_LPCR 72 bl __init_LPCR
43 bl __init_TLB 73 bl __init_TLB
44 mtlr r11 74 mtlr r11
@@ -57,6 +87,7 @@ __init_hvmode_206:
57 87
58__init_LPCR: 88__init_LPCR:
59 /* Setup a sane LPCR: 89 /* Setup a sane LPCR:
90 * Called with initial LPCR in R3
60 * 91 *
61 * LPES = 0b01 (HSRR0/1 used for 0x500) 92 * LPES = 0b01 (HSRR0/1 used for 0x500)
62 * PECE = 0b111 93 * PECE = 0b111
@@ -67,7 +98,6 @@ __init_LPCR:
67 * 98 *
68 * Other bits untouched for now 99 * Other bits untouched for now
69 */ 100 */
70 mfspr r3,SPRN_LPCR
71 li r5,1 101 li r5,1
72 rldimi r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2 102 rldimi r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
73 ori r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2) 103 ori r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 0514c21f138b..75a3d71b895d 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -68,6 +68,8 @@ extern void __restore_cpu_pa6t(void);
68extern void __restore_cpu_ppc970(void); 68extern void __restore_cpu_ppc970(void);
69extern void __setup_cpu_power7(unsigned long offset, struct cpu_spec* spec); 69extern void __setup_cpu_power7(unsigned long offset, struct cpu_spec* spec);
70extern void __restore_cpu_power7(void); 70extern void __restore_cpu_power7(void);
71extern void __setup_cpu_power8(unsigned long offset, struct cpu_spec* spec);
72extern void __restore_cpu_power8(void);
71extern void __restore_cpu_a2(void); 73extern void __restore_cpu_a2(void);
72#endif /* CONFIG_PPC64 */ 74#endif /* CONFIG_PPC64 */
73#if defined(CONFIG_E500) 75#if defined(CONFIG_E500)
@@ -94,6 +96,10 @@ extern void __restore_cpu_e5500(void);
94 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | \ 96 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | \
95 PPC_FEATURE_TRUE_LE | \ 97 PPC_FEATURE_TRUE_LE | \
96 PPC_FEATURE_PSERIES_PERFMON_COMPAT) 98 PPC_FEATURE_PSERIES_PERFMON_COMPAT)
99#define COMMON_USER_POWER8 (COMMON_USER_PPC64 | PPC_FEATURE_ARCH_2_06 |\
100 PPC_FEATURE_SMT | PPC_FEATURE_ICACHE_SNOOP | \
101 PPC_FEATURE_TRUE_LE | \
102 PPC_FEATURE_PSERIES_PERFMON_COMPAT)
97#define COMMON_USER_PA6T (COMMON_USER_PPC64 | PPC_FEATURE_PA6T |\ 103#define COMMON_USER_PA6T (COMMON_USER_PPC64 | PPC_FEATURE_PA6T |\
98 PPC_FEATURE_TRUE_LE | \ 104 PPC_FEATURE_TRUE_LE | \
99 PPC_FEATURE_HAS_ALTIVEC_COMP) 105 PPC_FEATURE_HAS_ALTIVEC_COMP)
@@ -429,6 +435,21 @@ static struct cpu_spec __initdata cpu_specs[] = {
429 .cpu_restore = __restore_cpu_power7, 435 .cpu_restore = __restore_cpu_power7,
430 .platform = "power7", 436 .platform = "power7",
431 }, 437 },
438 { /* 2.07-compliant processor, i.e. Power8 "architected" mode */
439 .pvr_mask = 0xffffffff,
440 .pvr_value = 0x0f000004,
441 .cpu_name = "POWER8 (architected)",
442 .cpu_features = CPU_FTRS_POWER8,
443 .cpu_user_features = COMMON_USER_POWER8,
444 .mmu_features = MMU_FTRS_POWER8,
445 .icache_bsize = 128,
446 .dcache_bsize = 128,
447 .oprofile_type = PPC_OPROFILE_POWER4,
448 .oprofile_cpu_type = "ppc64/ibm-compat-v1",
449 .cpu_setup = __setup_cpu_power8,
450 .cpu_restore = __restore_cpu_power8,
451 .platform = "power8",
452 },
432 { /* Power7 */ 453 { /* Power7 */
433 .pvr_mask = 0xffff0000, 454 .pvr_mask = 0xffff0000,
434 .pvr_value = 0x003f0000, 455 .pvr_value = 0x003f0000,
@@ -463,6 +484,23 @@ static struct cpu_spec __initdata cpu_specs[] = {
463 .cpu_restore = __restore_cpu_power7, 484 .cpu_restore = __restore_cpu_power7,
464 .platform = "power7+", 485 .platform = "power7+",
465 }, 486 },
487 { /* Power8 */
488 .pvr_mask = 0xffff0000,
489 .pvr_value = 0x004b0000,
490 .cpu_name = "POWER8 (raw)",
491 .cpu_features = CPU_FTRS_POWER8,
492 .cpu_user_features = COMMON_USER_POWER8,
493 .mmu_features = MMU_FTRS_POWER8,
494 .icache_bsize = 128,
495 .dcache_bsize = 128,
496 .num_pmcs = 6,
497 .pmc_type = PPC_PMC_IBM,
498 .oprofile_cpu_type = "ppc64/power8",
499 .oprofile_type = PPC_OPROFILE_POWER4,
500 .cpu_setup = __setup_cpu_power8,
501 .cpu_restore = __restore_cpu_power8,
502 .platform = "power8",
503 },
466 { /* Cell Broadband Engine */ 504 { /* Cell Broadband Engine */
467 .pvr_mask = 0xffff0000, 505 .pvr_mask = 0xffff0000,
468 .pvr_value = 0x00700000, 506 .pvr_value = 0x00700000,
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 9499385676e7..e514de57a125 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -439,16 +439,13 @@ ret_from_fork:
439ret_from_kernel_thread: 439ret_from_kernel_thread:
440 REST_NVGPRS(r1) 440 REST_NVGPRS(r1)
441 bl schedule_tail 441 bl schedule_tail
442 li r3,0
443 stw r3,0(r1)
442 mtlr r14 444 mtlr r14
443 mr r3,r15 445 mr r3,r15
444 PPC440EP_ERR42 446 PPC440EP_ERR42
445 blrl 447 blrl
446 li r3,0 448 li r3,0
447 b do_exit # no return
448
449 .globl __ret_from_kernel_execve
450__ret_from_kernel_execve:
451 addi r1,r3,-STACK_FRAME_OVERHEAD
452 b ret_from_syscall 449 b ret_from_syscall
453 450
454/* Traced system call support */ 451/* Traced system call support */
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 56e0ff0878b5..3d990d3bd8ba 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -373,17 +373,13 @@ _GLOBAL(ret_from_fork)
373_GLOBAL(ret_from_kernel_thread) 373_GLOBAL(ret_from_kernel_thread)
374 bl .schedule_tail 374 bl .schedule_tail
375 REST_NVGPRS(r1) 375 REST_NVGPRS(r1)
376 REST_GPR(2,r1) 376 li r3,0
377 std r3,0(r1)
378 ld r14, 0(r14)
377 mtlr r14 379 mtlr r14
378 mr r3,r15 380 mr r3,r15
379 blrl 381 blrl
380 li r3,0 382 li r3,0
381 b .do_exit # no return
382
383_GLOBAL(__ret_from_kernel_execve)
384 addi r1,r3,-STACK_FRAME_OVERHEAD
385 li r10,1
386 std r10,SOFTE(r1)
387 b syscall_exit 383 b syscall_exit
388 384
389 .section ".toc","aw" 385 .section ".toc","aw"
@@ -668,6 +664,19 @@ resume_kernel:
668 ld r4,TI_FLAGS(r9) 664 ld r4,TI_FLAGS(r9)
669 andi. r0,r4,_TIF_NEED_RESCHED 665 andi. r0,r4,_TIF_NEED_RESCHED
670 bne 1b 666 bne 1b
667
668 /*
669 * arch_local_irq_restore() from preempt_schedule_irq above may
670 * enable hard interrupt but we really should disable interrupts
671 * when we return from the interrupt, and so that we don't get
672 * interrupted after loading SRR0/1.
673 */
674#ifdef CONFIG_PPC_BOOK3E
675 wrteei 0
676#else
677 ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
678 mtmsrd r10,1 /* Update machine state */
679#endif /* CONFIG_PPC_BOOK3E */
671#endif /* CONFIG_PREEMPT */ 680#endif /* CONFIG_PREEMPT */
672 681
673 .globl fast_exc_return_irq 682 .globl fast_exc_return_irq
diff --git a/arch/powerpc/kernel/epapr_hcalls.S b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390ebfd8..62c0dc237826 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
8 */ 8 */
9 9
10#include <linux/threads.h> 10#include <linux/threads.h>
11#include <asm/epapr_hcalls.h>
11#include <asm/reg.h> 12#include <asm/reg.h>
12#include <asm/page.h> 13#include <asm/page.h>
13#include <asm/cputable.h> 14#include <asm/cputable.h>
14#include <asm/thread_info.h> 15#include <asm/thread_info.h>
15#include <asm/ppc_asm.h> 16#include <asm/ppc_asm.h>
17#include <asm/asm-compat.h>
16#include <asm/asm-offsets.h> 18#include <asm/asm-offsets.h>
17 19
20/* epapr_ev_idle() was derived from e500_idle() */
21_GLOBAL(epapr_ev_idle)
22 CURRENT_THREAD_INFO(r3, r1)
23 PPC_LL r4, TI_LOCAL_FLAGS(r3) /* set napping bit */
24 ori r4, r4,_TLF_NAPPING /* so when we take an exception */
25 PPC_STL r4, TI_LOCAL_FLAGS(r3) /* it will return to our caller */
26
27 wrteei 1
28
29idle_loop:
30 LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
31
32.global epapr_ev_idle_start
33epapr_ev_idle_start:
34 li r3, -1
35 nop
36 nop
37 nop
38
39 /*
40 * Guard against spurious wakeups from a hypervisor --
41 * only interrupt will cause us to return to LR due to
42 * _TLF_NAPPING.
43 */
44 b idle_loop
45
18/* Hypercall entry point. Will be patched with device tree instructions. */ 46/* Hypercall entry point. Will be patched with device tree instructions. */
19.global epapr_hypercall_start 47.global epapr_hypercall_start
20epapr_hypercall_start: 48epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae370b6..f3eab8594d9f 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
21#include <asm/epapr_hcalls.h> 21#include <asm/epapr_hcalls.h>
22#include <asm/cacheflush.h> 22#include <asm/cacheflush.h>
23#include <asm/code-patching.h> 23#include <asm/code-patching.h>
24#include <asm/machdep.h>
25
26extern void epapr_ev_idle(void);
27extern u32 epapr_ev_idle_start[];
24 28
25bool epapr_paravirt_enabled; 29bool epapr_paravirt_enabled;
26 30
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
41 if (len % 4 || len > (4 * 4)) 45 if (len % 4 || len > (4 * 4))
42 return -ENODEV; 46 return -ENODEV;
43 47
44 for (i = 0; i < (len / 4); i++) 48 for (i = 0; i < (len / 4); i++) {
45 patch_instruction(epapr_hypercall_start + i, insts[i]); 49 patch_instruction(epapr_hypercall_start + i, insts[i]);
50 patch_instruction(epapr_ev_idle_start + i, insts[i]);
51 }
52
53 if (of_get_property(hyper_node, "has-idle", NULL))
54 ppc_md.power_save = epapr_ev_idle;
46 55
47 epapr_paravirt_enabled = true; 56 epapr_paravirt_enabled = true;
48 57
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 10b658ad65e1..4665e82fa377 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -19,12 +19,76 @@
19/* 19/*
20 * We layout physical memory as follows: 20 * We layout physical memory as follows:
21 * 0x0000 - 0x00ff : Secondary processor spin code 21 * 0x0000 - 0x00ff : Secondary processor spin code
22 * 0x0100 - 0x2fff : pSeries Interrupt prologs 22 * 0x0100 - 0x17ff : pSeries Interrupt prologs
23 * 0x3000 - 0x5fff : interrupt support common interrupt prologs 23 * 0x1800 - 0x4000 : interrupt support common interrupt prologs
24 * 0x6000 - 0x6fff : Initial (CPU0) segment table 24 * 0x4000 - 0x5fff : pSeries interrupts with IR=1,DR=1
25 * 0x6000 - 0x6fff : more interrupt support including for IR=1,DR=1
25 * 0x7000 - 0x7fff : FWNMI data area 26 * 0x7000 - 0x7fff : FWNMI data area
26 * 0x8000 - : Early init and support code 27 * 0x8000 - 0x8fff : Initial (CPU0) segment table
28 * 0x9000 - : Early init and support code
27 */ 29 */
30 /* Syscall routine is used twice, in reloc-off and reloc-on paths */
31#define SYSCALL_PSERIES_1 \
32BEGIN_FTR_SECTION \
33 cmpdi r0,0x1ebe ; \
34 beq- 1f ; \
35END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
36 mr r9,r13 ; \
37 GET_PACA(r13) ; \
38 mfspr r11,SPRN_SRR0 ; \
390:
40
41#define SYSCALL_PSERIES_2_RFID \
42 mfspr r12,SPRN_SRR1 ; \
43 ld r10,PACAKBASE(r13) ; \
44 LOAD_HANDLER(r10, system_call_entry) ; \
45 mtspr SPRN_SRR0,r10 ; \
46 ld r10,PACAKMSR(r13) ; \
47 mtspr SPRN_SRR1,r10 ; \
48 rfid ; \
49 b . ; /* prevent speculative execution */
50
51#define SYSCALL_PSERIES_3 \
52 /* Fast LE/BE switch system call */ \
531: mfspr r12,SPRN_SRR1 ; \
54 xori r12,r12,MSR_LE ; \
55 mtspr SPRN_SRR1,r12 ; \
56 rfid ; /* return to userspace */ \
57 b . ; \
582: mfspr r12,SPRN_SRR1 ; \
59 andi. r12,r12,MSR_PR ; \
60 bne 0b ; \
61 mtspr SPRN_SRR0,r3 ; \
62 mtspr SPRN_SRR1,r4 ; \
63 mtspr SPRN_SDR1,r5 ; \
64 rfid ; \
65 b . ; /* prevent speculative execution */
66
67#if defined(CONFIG_RELOCATABLE)
68 /*
69 * We can't branch directly; in the direct case we use LR
70 * and system_call_entry restores LR. (We thus need to move
71 * LR to r10 in the RFID case too.)
72 */
73#define SYSCALL_PSERIES_2_DIRECT \
74 mflr r10 ; \
75 ld r12,PACAKBASE(r13) ; \
76 LOAD_HANDLER(r12, system_call_entry_direct) ; \
77 mtlr r12 ; \
78 mfspr r12,SPRN_SRR1 ; \
79 /* Re-use of r13... No spare regs to do this */ \
80 li r13,MSR_RI ; \
81 mtmsrd r13,1 ; \
82 GET_PACA(r13) ; /* get r13 back */ \
83 blr ;
84#else
85 /* We can branch directly */
86#define SYSCALL_PSERIES_2_DIRECT \
87 mfspr r12,SPRN_SRR1 ; \
88 li r10,MSR_RI ; \
89 mtmsrd r10,1 ; /* Set RI (EE=0) */ \
90 b system_call_entry_direct ;
91#endif
28 92
29/* 93/*
30 * This is the start of the interrupt handlers for pSeries 94 * This is the start of the interrupt handlers for pSeries
@@ -207,31 +271,11 @@ system_call_pSeries:
207 KVMTEST(0xc00) 271 KVMTEST(0xc00)
208 GET_SCRATCH0(r13) 272 GET_SCRATCH0(r13)
209#endif 273#endif
210BEGIN_FTR_SECTION 274 SYSCALL_PSERIES_1
211 cmpdi r0,0x1ebe 275 SYSCALL_PSERIES_2_RFID
212 beq- 1f 276 SYSCALL_PSERIES_3
213END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
214 mr r9,r13
215 GET_PACA(r13)
216 mfspr r11,SPRN_SRR0
217 mfspr r12,SPRN_SRR1
218 ld r10,PACAKBASE(r13)
219 LOAD_HANDLER(r10, system_call_entry)
220 mtspr SPRN_SRR0,r10
221 ld r10,PACAKMSR(r13)
222 mtspr SPRN_SRR1,r10
223 rfid
224 b . /* prevent speculative execution */
225
226 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00) 277 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
227 278
228/* Fast LE/BE switch system call */
2291: mfspr r12,SPRN_SRR1
230 xori r12,r12,MSR_LE
231 mtspr SPRN_SRR1,r12
232 rfid /* return to userspace */
233 b .
234
235 STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step) 279 STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
236 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00) 280 KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
237 281
@@ -276,7 +320,7 @@ vsx_unavailable_pSeries_1:
276 KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300) 320 KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
277 321
278 . = 0x1500 322 . = 0x1500
279 .global denorm_Hypervisor 323 .global denorm_exception_hv
280denorm_exception_hv: 324denorm_exception_hv:
281 HMT_MEDIUM 325 HMT_MEDIUM
282 mtspr SPRN_SPRG_HSCRATCH0,r13 326 mtspr SPRN_SPRG_HSCRATCH0,r13
@@ -311,12 +355,14 @@ denorm_exception_hv:
311#ifdef CONFIG_CBE_RAS 355#ifdef CONFIG_CBE_RAS
312 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal) 356 STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
313 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802) 357 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
358#else
359 . = 0x1800
314#endif /* CONFIG_CBE_RAS */ 360#endif /* CONFIG_CBE_RAS */
315 361
316 . = 0x3000
317 362
318/*** Out of line interrupts support ***/ 363/*** Out of line interrupts support ***/
319 364
365 .align 7
320 /* moved from 0x200 */ 366 /* moved from 0x200 */
321machine_check_pSeries: 367machine_check_pSeries:
322 .globl machine_check_fwnmi 368 .globl machine_check_fwnmi
@@ -575,16 +621,12 @@ slb_miss_user_pseries:
575 b . /* prevent spec. execution */ 621 b . /* prevent spec. execution */
576#endif /* __DISABLED__ */ 622#endif /* __DISABLED__ */
577 623
578 .align 7
579 .globl __end_interrupts
580__end_interrupts:
581
582/* 624/*
583 * Code from here down to __end_handlers is invoked from the 625 * Code from here down to __end_handlers is invoked from the
584 * exception prologs above. Because the prologs assemble the 626 * exception prologs above. Because the prologs assemble the
585 * addresses of these handlers using the LOAD_HANDLER macro, 627 * addresses of these handlers using the LOAD_HANDLER macro,
586 * which uses an addi instruction, these handlers must be in 628 * which uses an ori instruction, these handlers must be in
587 * the first 32k of the kernel image. 629 * the first 64k of the kernel image.
588 */ 630 */
589 631
590/*** Common interrupt handlers ***/ 632/*** Common interrupt handlers ***/
@@ -613,8 +655,8 @@ machine_check_common:
613 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception) 655 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
614 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception) 656 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
615 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception) 657 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
616 STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception) 658 STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
617 STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception) 659 STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
618 STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception) 660 STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
619 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception) 661 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
620 STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception) 662 STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception)
@@ -629,7 +671,158 @@ machine_check_common:
629 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception) 671 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
630#endif /* CONFIG_CBE_RAS */ 672#endif /* CONFIG_CBE_RAS */
631 673
674 /*
675 * Relocation-on interrupts: A subset of the interrupts can be delivered
676 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
677 * it. Addresses are the same as the original interrupt addresses, but
678 * offset by 0xc000000000004000.
679 * It's impossible to receive interrupts below 0x300 via this mechanism.
680 * KVM: None of these traps are from the guest ; anything that escalated
681 * to HV=1 from HV=0 is delivered via real mode handlers.
682 */
683
684 /*
685 * This uses the standard macro, since the original 0x300 vector
686 * only has extra guff for STAB-based processors -- which never
687 * come here.
688 */
689 STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
690 . = 0x4380
691 .globl data_access_slb_relon_pSeries
692data_access_slb_relon_pSeries:
693 HMT_MEDIUM
694 SET_SCRATCH0(r13)
695 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
696 std r3,PACA_EXSLB+EX_R3(r13)
697 mfspr r3,SPRN_DAR
698 mfspr r12,SPRN_SRR1
699#ifndef CONFIG_RELOCATABLE
700 b .slb_miss_realmode
701#else
702 /*
703 * We can't just use a direct branch to .slb_miss_realmode
704 * because the distance from here to there depends on where
705 * the kernel ends up being put.
706 */
707 mfctr r11
708 ld r10,PACAKBASE(r13)
709 LOAD_HANDLER(r10, .slb_miss_realmode)
710 mtctr r10
711 bctr
712#endif
713
714 STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
715 . = 0x4480
716 .globl instruction_access_slb_relon_pSeries
717instruction_access_slb_relon_pSeries:
718 HMT_MEDIUM
719 SET_SCRATCH0(r13)
720 EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
721 std r3,PACA_EXSLB+EX_R3(r13)
722 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
723 mfspr r12,SPRN_SRR1
724#ifndef CONFIG_RELOCATABLE
725 b .slb_miss_realmode
726#else
727 mfctr r11
728 ld r10,PACAKBASE(r13)
729 LOAD_HANDLER(r10, .slb_miss_realmode)
730 mtctr r10
731 bctr
732#endif
733
734 . = 0x4500
735 .globl hardware_interrupt_relon_pSeries;
736 .globl hardware_interrupt_relon_hv;
737hardware_interrupt_relon_pSeries:
738hardware_interrupt_relon_hv:
739 BEGIN_FTR_SECTION
740 _MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
741 FTR_SECTION_ELSE
742 _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
743 ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_206)
744 STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
745 STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
746 STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
747 MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
748 STD_RELON_EXCEPTION_HV(0x4980, 0x982, hdecrementer)
749 STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
750
751 . = 0x4c00
752 .globl system_call_relon_pSeries
753system_call_relon_pSeries:
754 HMT_MEDIUM
755 SYSCALL_PSERIES_1
756 SYSCALL_PSERIES_2_DIRECT
757 SYSCALL_PSERIES_3
758
759 STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
760
761 . = 0x4e00
762 b h_data_storage_relon_hv
763
764 . = 0x4e20
765 b h_instr_storage_relon_hv
766
767 . = 0x4e40
768 b emulation_assist_relon_hv
769
770 . = 0x4e50
771 b hmi_exception_relon_hv
772
773 . = 0x4e60
774 b hmi_exception_relon_hv
775
776 /* For when we support the doorbell interrupt:
777 STD_RELON_EXCEPTION_HYPERVISOR(0x4e80, 0xe80, doorbell_hyper)
778 */
779
780performance_monitor_relon_pSeries_1:
781 . = 0x4f00
782 b performance_monitor_relon_pSeries
783
784altivec_unavailable_relon_pSeries_1:
785 . = 0x4f20
786 b altivec_unavailable_relon_pSeries
787
788vsx_unavailable_relon_pSeries_1:
789 . = 0x4f40
790 b vsx_unavailable_relon_pSeries
791
792#ifdef CONFIG_CBE_RAS
793 STD_RELON_EXCEPTION_HV(0x5200, 0x1202, cbe_system_error)
794#endif /* CONFIG_CBE_RAS */
795 STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
796#ifdef CONFIG_PPC_DENORMALISATION
797 . = 0x5500
798 b denorm_exception_hv
799#endif
800#ifdef CONFIG_CBE_RAS
801 STD_RELON_EXCEPTION_HV(0x5600, 0x1602, cbe_maintenance)
802#else
803#ifdef CONFIG_HVC_SCOM
804 STD_RELON_EXCEPTION_HV(0x5600, 0x1600, maintence_interrupt)
805 KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1600)
806#endif /* CONFIG_HVC_SCOM */
807#endif /* CONFIG_CBE_RAS */
808 STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
809#ifdef CONFIG_CBE_RAS
810 STD_RELON_EXCEPTION_HV(0x5800, 0x1802, cbe_thermal)
811#endif /* CONFIG_CBE_RAS */
812
813 /* Other future vectors */
632 .align 7 814 .align 7
815 .globl __end_interrupts
816__end_interrupts:
817
818 .align 7
819system_call_entry_direct:
820#if defined(CONFIG_RELOCATABLE)
821 /* The first level prologue may have used LR to get here, saving
822 * orig in r10. To save hacking/ifdeffing common code, restore here.
823 */
824 mtlr r10
825#endif
633system_call_entry: 826system_call_entry:
634 b system_call_common 827 b system_call_common
635 828
@@ -714,21 +907,21 @@ data_access_common:
714 ld r3,PACA_EXGEN+EX_DAR(r13) 907 ld r3,PACA_EXGEN+EX_DAR(r13)
715 lwz r4,PACA_EXGEN+EX_DSISR(r13) 908 lwz r4,PACA_EXGEN+EX_DSISR(r13)
716 li r5,0x300 909 li r5,0x300
717 b .do_hash_page /* Try to handle as hpte fault */ 910 b .do_hash_page /* Try to handle as hpte fault */
718 911
719 .align 7 912 .align 7
720 .globl h_data_storage_common 913 .globl h_data_storage_common
721h_data_storage_common: 914h_data_storage_common:
722 mfspr r10,SPRN_HDAR 915 mfspr r10,SPRN_HDAR
723 std r10,PACA_EXGEN+EX_DAR(r13) 916 std r10,PACA_EXGEN+EX_DAR(r13)
724 mfspr r10,SPRN_HDSISR 917 mfspr r10,SPRN_HDSISR
725 stw r10,PACA_EXGEN+EX_DSISR(r13) 918 stw r10,PACA_EXGEN+EX_DSISR(r13)
726 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN) 919 EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
727 bl .save_nvgprs 920 bl .save_nvgprs
728 DISABLE_INTS 921 DISABLE_INTS
729 addi r3,r1,STACK_FRAME_OVERHEAD 922 addi r3,r1,STACK_FRAME_OVERHEAD
730 bl .unknown_exception 923 bl .unknown_exception
731 b .ret_from_except 924 b .ret_from_except
732 925
733 .align 7 926 .align 7
734 .globl instruction_access_common 927 .globl instruction_access_common
@@ -741,7 +934,7 @@ instruction_access_common:
741 li r5,0x400 934 li r5,0x400
742 b .do_hash_page /* Try to handle as hpte fault */ 935 b .do_hash_page /* Try to handle as hpte fault */
743 936
744 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception) 937 STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
745 938
746/* 939/*
747 * Here is the common SLB miss user that is used when going to virtual 940 * Here is the common SLB miss user that is used when going to virtual
@@ -1152,6 +1345,21 @@ _GLOBAL(do_stab_bolted)
1152 rfid 1345 rfid
1153 b . /* prevent speculative execution */ 1346 b . /* prevent speculative execution */
1154 1347
1348
1349 /* Equivalents to the above handlers for relocation-on interrupt vectors */
1350 STD_RELON_EXCEPTION_HV(., 0xe00, h_data_storage)
1351 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe00)
1352 STD_RELON_EXCEPTION_HV(., 0xe20, h_instr_storage)
1353 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe20)
1354 STD_RELON_EXCEPTION_HV(., 0xe40, emulation_assist)
1355 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe40)
1356 STD_RELON_EXCEPTION_HV(., 0xe60, hmi_exception)
1357 KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe60)
1358
1359 STD_RELON_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
1360 STD_RELON_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
1361 STD_RELON_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
1362
1155#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) 1363#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
1156/* 1364/*
1157 * Data area reserved for FWNMI option. 1365 * Data area reserved for FWNMI option.
@@ -1164,7 +1372,7 @@ fwnmi_data_area:
1164 /* pseries and powernv need to keep the whole page from 1372 /* pseries and powernv need to keep the whole page from
1165 * 0x7000 to 0x8000 free for use by the firmware 1373 * 0x7000 to 0x8000 free for use by the firmware
1166 */ 1374 */
1167 . = 0x8000 1375 . = 0x8000
1168#endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */ 1376#endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
1169 1377
1170/* Space for CPU0's segment table */ 1378/* Space for CPU0's segment table */
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index 58bddee8e1e8..116f0868695b 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -422,7 +422,7 @@ _STATIC(__after_prom_start)
422 tovirt(r6,r6) /* on booke, we already run at PAGE_OFFSET */ 422 tovirt(r6,r6) /* on booke, we already run at PAGE_OFFSET */
423#endif 423#endif
424 424
425#ifdef CONFIG_CRASH_DUMP 425#ifdef CONFIG_RELOCATABLE
426/* 426/*
427 * Check if the kernel has to be running as relocatable kernel based on the 427 * Check if the kernel has to be running as relocatable kernel based on the
428 * variable __run_at_load, if it is set the kernel is treated as relocatable 428 * variable __run_at_load, if it is set the kernel is treated as relocatable
@@ -432,7 +432,8 @@ _STATIC(__after_prom_start)
432 cmplwi cr0,r7,1 432 cmplwi cr0,r7,1
433 bne 3f 433 bne 3f
434 434
435 li r5,__end_interrupts - _stext /* just copy interrupts */ 435 /* just copy interrupts */
436 LOAD_REG_IMMEDIATE(r5, __end_interrupts - _stext)
436 b 5f 437 b 5f
4373: 4383:
438#endif 439#endif
@@ -703,6 +704,7 @@ _INIT_STATIC(start_here_multiplatform)
703 704
704#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 705#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
705 /* Setup OPAL entry */ 706 /* Setup OPAL entry */
707 LOAD_REG_ADDR(r11, opal)
706 std r28,0(r11); 708 std r28,0(r11);
707 std r29,8(r11); 709 std r29,8(r11);
708#endif 710#endif
diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index 2099d9a879e8..ea78761aa169 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -55,9 +55,6 @@ __setup("powersave=off", powersave_off);
55 */ 55 */
56void cpu_idle(void) 56void cpu_idle(void)
57{ 57{
58 if (ppc_md.idle_loop)
59 ppc_md.idle_loop(); /* doesn't return */
60
61 set_thread_flag(TIF_POLLING_NRFLAG); 58 set_thread_flag(TIF_POLLING_NRFLAG);
62 while (1) { 59 while (1) {
63 tick_nohz_idle_enter(); 60 tick_nohz_idle_enter();
diff --git a/arch/powerpc/kernel/io-workarounds.c b/arch/powerpc/kernel/io-workarounds.c
index 12d329bcbb98..50e90b7e7139 100644
--- a/arch/powerpc/kernel/io-workarounds.c
+++ b/arch/powerpc/kernel/io-workarounds.c
@@ -118,7 +118,7 @@ static void iowa_##name at \
118#undef DEF_PCI_AC_RET 118#undef DEF_PCI_AC_RET
119#undef DEF_PCI_AC_NORET 119#undef DEF_PCI_AC_NORET
120 120
121static const struct ppc_pci_io __devinitconst iowa_pci_io = { 121static const struct ppc_pci_io iowa_pci_io = {
122 122
123#define DEF_PCI_AC_RET(name, ret, at, al, space, aa) .name = iowa_##name, 123#define DEF_PCI_AC_RET(name, ret, at, al, space, aa) .name = iowa_##name,
124#define DEF_PCI_AC_NORET(name, at, al, space, aa) .name = iowa_##name, 124#define DEF_PCI_AC_NORET(name, at, al, space, aa) .name = iowa_##name,
@@ -146,7 +146,7 @@ static void __iomem *iowa_ioremap(phys_addr_t addr, unsigned long size,
146} 146}
147 147
148/* Enable IO workaround */ 148/* Enable IO workaround */
149static void __devinit io_workaround_init(void) 149static void io_workaround_init(void)
150{ 150{
151 static int io_workaround_inited; 151 static int io_workaround_inited;
152 152
@@ -158,9 +158,8 @@ static void __devinit io_workaround_init(void)
158} 158}
159 159
160/* Register new bus to support workaround */ 160/* Register new bus to support workaround */
161void __devinit iowa_register_bus(struct pci_controller *phb, 161void iowa_register_bus(struct pci_controller *phb, struct ppc_pci_io *ops,
162 struct ppc_pci_io *ops, 162 int (*initfunc)(struct iowa_bus *, void *), void *data)
163 int (*initfunc)(struct iowa_bus *, void *), void *data)
164{ 163{
165 struct iowa_bus *bus; 164 struct iowa_bus *bus;
166 struct device_node *np = phb->dn; 165 struct device_node *np = phb->dn;
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 8226c6cb348a..c862fd716fe3 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -656,7 +656,7 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
656 struct iommu_pool *p; 656 struct iommu_pool *p;
657 657
658 /* number of bytes needed for the bitmap */ 658 /* number of bytes needed for the bitmap */
659 sz = (tbl->it_size + 7) >> 3; 659 sz = BITS_TO_LONGS(tbl->it_size) * sizeof(unsigned long);
660 660
661 page = alloc_pages_node(nid, GFP_ATOMIC, get_order(sz)); 661 page = alloc_pages_node(nid, GFP_ATOMIC, get_order(sz));
662 if (!page) 662 if (!page)
@@ -708,7 +708,7 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
708 708
709void iommu_free_table(struct iommu_table *tbl, const char *node_name) 709void iommu_free_table(struct iommu_table *tbl, const char *node_name)
710{ 710{
711 unsigned long bitmap_sz, i; 711 unsigned long bitmap_sz;
712 unsigned int order; 712 unsigned int order;
713 713
714 if (!tbl || !tbl->it_map) { 714 if (!tbl || !tbl->it_map) {
@@ -718,17 +718,11 @@ void iommu_free_table(struct iommu_table *tbl, const char *node_name)
718 } 718 }
719 719
720 /* verify that table contains no entries */ 720 /* verify that table contains no entries */
721 /* it_size is in entries, and we're examining 64 at a time */ 721 if (!bitmap_empty(tbl->it_map, tbl->it_size))
722 for (i = 0; i < (tbl->it_size/64); i++) { 722 pr_warn("%s: Unexpected TCEs for %s\n", __func__, node_name);
723 if (tbl->it_map[i] != 0) {
724 printk(KERN_WARNING "%s: Unexpected TCEs for %s\n",
725 __func__, node_name);
726 break;
727 }
728 }
729 723
730 /* calculate bitmap size in bytes */ 724 /* calculate bitmap size in bytes */
731 bitmap_sz = (tbl->it_size + 7) / 8; 725 bitmap_sz = BITS_TO_LONGS(tbl->it_size) * sizeof(unsigned long);
732 726
733 /* free bitmap */ 727 /* free bitmap */
734 order = get_order(bitmap_sz); 728 order = get_order(bitmap_sz);
diff --git a/arch/powerpc/kernel/isa-bridge.c b/arch/powerpc/kernel/isa-bridge.c
index d45ec58703ce..0f1997097960 100644
--- a/arch/powerpc/kernel/isa-bridge.c
+++ b/arch/powerpc/kernel/isa-bridge.c
@@ -41,8 +41,8 @@ EXPORT_SYMBOL_GPL(isa_bridge_pcidev);
41#define ISA_SPACE_MASK 0x1 41#define ISA_SPACE_MASK 0x1
42#define ISA_SPACE_IO 0x1 42#define ISA_SPACE_IO 0x1
43 43
44static void __devinit pci_process_ISA_OF_ranges(struct device_node *isa_node, 44static void pci_process_ISA_OF_ranges(struct device_node *isa_node,
45 unsigned long phb_io_base_phys) 45 unsigned long phb_io_base_phys)
46{ 46{
47 /* We should get some saner parsing here and remove these structs */ 47 /* We should get some saner parsing here and remove these structs */
48 struct pci_address { 48 struct pci_address {
@@ -170,8 +170,8 @@ void __init isa_bridge_find_early(struct pci_controller *hose)
170 * isa_bridge_find_late - Find and map the ISA IO space upon discovery of 170 * isa_bridge_find_late - Find and map the ISA IO space upon discovery of
171 * a new ISA bridge 171 * a new ISA bridge
172 */ 172 */
173static void __devinit isa_bridge_find_late(struct pci_dev *pdev, 173static void isa_bridge_find_late(struct pci_dev *pdev,
174 struct device_node *devnode) 174 struct device_node *devnode)
175{ 175{
176 struct pci_controller *hose = pci_bus_to_host(pdev->bus); 176 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
177 177
@@ -215,8 +215,8 @@ static void isa_bridge_remove(void)
215/** 215/**
216 * isa_bridge_notify - Get notified of PCI devices addition/removal 216 * isa_bridge_notify - Get notified of PCI devices addition/removal
217 */ 217 */
218static int __devinit isa_bridge_notify(struct notifier_block *nb, 218static int isa_bridge_notify(struct notifier_block *nb, unsigned long action,
219 unsigned long action, void *data) 219 void *data)
220{ 220{
221 struct device *dev = data; 221 struct device *dev = data;
222 struct pci_dev *pdev = to_pci_dev(dev); 222 struct pci_dev *pdev = to_pci_dev(dev);
diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
index c470a40b29f5..a7bc7521c064 100644
--- a/arch/powerpc/kernel/kgdb.c
+++ b/arch/powerpc/kernel/kgdb.c
@@ -154,12 +154,12 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)
154static int kgdb_singlestep(struct pt_regs *regs) 154static int kgdb_singlestep(struct pt_regs *regs)
155{ 155{
156 struct thread_info *thread_info, *exception_thread_info; 156 struct thread_info *thread_info, *exception_thread_info;
157 struct thread_info *backup_current_thread_info = \ 157 struct thread_info *backup_current_thread_info;
158 (struct thread_info *)kmalloc(sizeof(struct thread_info), GFP_KERNEL);
159 158
160 if (user_mode(regs)) 159 if (user_mode(regs))
161 return 0; 160 return 0;
162 161
162 backup_current_thread_info = (struct thread_info *)kmalloc(sizeof(struct thread_info), GFP_KERNEL);
163 /* 163 /*
164 * On Book E and perhaps other processors, singlestep is handled on 164 * On Book E and perhaps other processors, singlestep is handled on
165 * the critical exception stack. This causes current_thread_info() 165 * the critical exception stack. This causes current_thread_info()
@@ -185,6 +185,7 @@ static int kgdb_singlestep(struct pt_regs *regs)
185 /* Restore current_thread_info lastly. */ 185 /* Restore current_thread_info lastly. */
186 memcpy(exception_thread_info, backup_current_thread_info, sizeof *thread_info); 186 memcpy(exception_thread_info, backup_current_thread_info, sizeof *thread_info);
187 187
188 kfree(backup_current_thread_info);
188 return 1; 189 return 1;
189} 190}
190 191
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 867db1de8949..a61b133c4f99 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
419 in[0] = KVM_MAGIC_PAGE; 419 in[0] = KVM_MAGIC_PAGE;
420 in[1] = KVM_MAGIC_PAGE; 420 in[1] = KVM_MAGIC_PAGE;
421 421
422 kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE); 422 kvm_hypercall(in, out, KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE));
423 423
424 *features = out[0]; 424 *features = out[0];
425} 425}
diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c
index fa9f6c72f557..e1ec57e87b3b 100644
--- a/arch/powerpc/kernel/machine_kexec.c
+++ b/arch/powerpc/kernel/machine_kexec.c
@@ -218,23 +218,23 @@ static void __init export_crashk_values(struct device_node *node)
218 * be sure what's in them, so remove them. */ 218 * be sure what's in them, so remove them. */
219 prop = of_find_property(node, "linux,crashkernel-base", NULL); 219 prop = of_find_property(node, "linux,crashkernel-base", NULL);
220 if (prop) 220 if (prop)
221 prom_remove_property(node, prop); 221 of_remove_property(node, prop);
222 222
223 prop = of_find_property(node, "linux,crashkernel-size", NULL); 223 prop = of_find_property(node, "linux,crashkernel-size", NULL);
224 if (prop) 224 if (prop)
225 prom_remove_property(node, prop); 225 of_remove_property(node, prop);
226 226
227 if (crashk_res.start != 0) { 227 if (crashk_res.start != 0) {
228 prom_add_property(node, &crashk_base_prop); 228 of_add_property(node, &crashk_base_prop);
229 crashk_size = resource_size(&crashk_res); 229 crashk_size = resource_size(&crashk_res);
230 prom_add_property(node, &crashk_size_prop); 230 of_add_property(node, &crashk_size_prop);
231 } 231 }
232 232
233 /* 233 /*
234 * memory_limit is required by the kexec-tools to limit the 234 * memory_limit is required by the kexec-tools to limit the
235 * crash regions to the actual memory used. 235 * crash regions to the actual memory used.
236 */ 236 */
237 prom_update_property(node, &memory_limit_prop); 237 of_update_property(node, &memory_limit_prop);
238} 238}
239 239
240static int __init kexec_setup(void) 240static int __init kexec_setup(void)
@@ -249,11 +249,11 @@ static int __init kexec_setup(void)
249 /* remove any stale properties so ours can be found */ 249 /* remove any stale properties so ours can be found */
250 prop = of_find_property(node, kernel_end_prop.name, NULL); 250 prop = of_find_property(node, kernel_end_prop.name, NULL);
251 if (prop) 251 if (prop)
252 prom_remove_property(node, prop); 252 of_remove_property(node, prop);
253 253
254 /* information needed by userspace when using default_machine_kexec */ 254 /* information needed by userspace when using default_machine_kexec */
255 kernel_end = __pa(_end); 255 kernel_end = __pa(_end);
256 prom_add_property(node, &kernel_end_prop); 256 of_add_property(node, &kernel_end_prop);
257 257
258 export_crashk_values(node); 258 export_crashk_values(node);
259 259
diff --git a/arch/powerpc/kernel/machine_kexec_64.c b/arch/powerpc/kernel/machine_kexec_64.c
index d7f609086a99..7206701b1ff1 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -389,14 +389,14 @@ static int __init export_htab_values(void)
389 /* remove any stale propertys so ours can be found */ 389 /* remove any stale propertys so ours can be found */
390 prop = of_find_property(node, htab_base_prop.name, NULL); 390 prop = of_find_property(node, htab_base_prop.name, NULL);
391 if (prop) 391 if (prop)
392 prom_remove_property(node, prop); 392 of_remove_property(node, prop);
393 prop = of_find_property(node, htab_size_prop.name, NULL); 393 prop = of_find_property(node, htab_size_prop.name, NULL);
394 if (prop) 394 if (prop)
395 prom_remove_property(node, prop); 395 of_remove_property(node, prop);
396 396
397 htab_base = __pa(htab_address); 397 htab_base = __pa(htab_address);
398 prom_add_property(node, &htab_base_prop); 398 of_add_property(node, &htab_base_prop);
399 prom_add_property(node, &htab_size_prop); 399 of_add_property(node, &htab_size_prop);
400 400
401 of_node_put(node); 401 of_node_put(node);
402 return 0; 402 return 0;
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index 9db8ec07ec94..07c12697d708 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -37,7 +37,7 @@
37 * lacking some bits needed here. 37 * lacking some bits needed here.
38 */ 38 */
39 39
40static int __devinit of_pci_phb_probe(struct platform_device *dev) 40static int of_pci_phb_probe(struct platform_device *dev)
41{ 41{
42 struct pci_controller *phb; 42 struct pci_controller *phb;
43 43
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 7f94f760dd0c..7c37379ea9b1 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -673,9 +673,8 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar,
673 * - Some 32 bits platforms such as 4xx can have physical space larger than 673 * - Some 32 bits platforms such as 4xx can have physical space larger than
674 * 32 bits so we need to use 64 bits values for the parsing 674 * 32 bits so we need to use 64 bits values for the parsing
675 */ 675 */
676void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose, 676void pci_process_bridge_OF_ranges(struct pci_controller *hose,
677 struct device_node *dev, 677 struct device_node *dev, int primary)
678 int primary)
679{ 678{
680 const u32 *ranges; 679 const u32 *ranges;
681 int rlen; 680 int rlen;
@@ -848,7 +847,7 @@ int pci_proc_domain(struct pci_bus *bus)
848/* This header fixup will do the resource fixup for all devices as they are 847/* This header fixup will do the resource fixup for all devices as they are
849 * probed, but not for bridge ranges 848 * probed, but not for bridge ranges
850 */ 849 */
851static void __devinit pcibios_fixup_resources(struct pci_dev *dev) 850static void pcibios_fixup_resources(struct pci_dev *dev)
852{ 851{
853 struct pci_controller *hose = pci_bus_to_host(dev->bus); 852 struct pci_controller *hose = pci_bus_to_host(dev->bus);
854 int i; 853 int i;
@@ -902,8 +901,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources);
902 * things go more smoothly when it gets it right. It should covers cases such 901 * things go more smoothly when it gets it right. It should covers cases such
903 * as Apple "closed" bridge resources and bare-metal pSeries unassigned bridges 902 * as Apple "closed" bridge resources and bare-metal pSeries unassigned bridges
904 */ 903 */
905static int __devinit pcibios_uninitialized_bridge_resource(struct pci_bus *bus, 904static int pcibios_uninitialized_bridge_resource(struct pci_bus *bus,
906 struct resource *res) 905 struct resource *res)
907{ 906{
908 struct pci_controller *hose = pci_bus_to_host(bus); 907 struct pci_controller *hose = pci_bus_to_host(bus);
909 struct pci_dev *dev = bus->self; 908 struct pci_dev *dev = bus->self;
@@ -967,7 +966,7 @@ static int __devinit pcibios_uninitialized_bridge_resource(struct pci_bus *bus,
967} 966}
968 967
969/* Fixup resources of a PCI<->PCI bridge */ 968/* Fixup resources of a PCI<->PCI bridge */
970static void __devinit pcibios_fixup_bridge(struct pci_bus *bus) 969static void pcibios_fixup_bridge(struct pci_bus *bus)
971{ 970{
972 struct resource *res; 971 struct resource *res;
973 int i; 972 int i;
@@ -1007,7 +1006,7 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus)
1007 } 1006 }
1008} 1007}
1009 1008
1010void __devinit pcibios_setup_bus_self(struct pci_bus *bus) 1009void pcibios_setup_bus_self(struct pci_bus *bus)
1011{ 1010{
1012 /* Fix up the bus resources for P2P bridges */ 1011 /* Fix up the bus resources for P2P bridges */
1013 if (bus->self != NULL) 1012 if (bus->self != NULL)
@@ -1024,7 +1023,7 @@ void __devinit pcibios_setup_bus_self(struct pci_bus *bus)
1024 ppc_md.pci_dma_bus_setup(bus); 1023 ppc_md.pci_dma_bus_setup(bus);
1025} 1024}
1026 1025
1027void __devinit pcibios_setup_bus_devices(struct pci_bus *bus) 1026void pcibios_setup_bus_devices(struct pci_bus *bus)
1028{ 1027{
1029 struct pci_dev *dev; 1028 struct pci_dev *dev;
1030 1029
@@ -1063,7 +1062,7 @@ void pcibios_set_master(struct pci_dev *dev)
1063 /* No special bus mastering setup handling */ 1062 /* No special bus mastering setup handling */
1064} 1063}
1065 1064
1066void __devinit pcibios_fixup_bus(struct pci_bus *bus) 1065void pcibios_fixup_bus(struct pci_bus *bus)
1067{ 1066{
1068 /* When called from the generic PCI probe, read PCI<->PCI bridge 1067 /* When called from the generic PCI probe, read PCI<->PCI bridge
1069 * bases. This is -not- called when generating the PCI tree from 1068 * bases. This is -not- called when generating the PCI tree from
@@ -1080,7 +1079,7 @@ void __devinit pcibios_fixup_bus(struct pci_bus *bus)
1080} 1079}
1081EXPORT_SYMBOL(pcibios_fixup_bus); 1080EXPORT_SYMBOL(pcibios_fixup_bus);
1082 1081
1083void __devinit pci_fixup_cardbus(struct pci_bus *bus) 1082void pci_fixup_cardbus(struct pci_bus *bus)
1084{ 1083{
1085 /* Now fixup devices on that bus */ 1084 /* Now fixup devices on that bus */
1086 pcibios_setup_bus_devices(bus); 1085 pcibios_setup_bus_devices(bus);
@@ -1264,7 +1263,7 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)
1264 pcibios_allocate_bus_resources(b); 1263 pcibios_allocate_bus_resources(b);
1265} 1264}
1266 1265
1267static inline void __devinit alloc_resource(struct pci_dev *dev, int idx) 1266static inline void alloc_resource(struct pci_dev *dev, int idx)
1268{ 1267{
1269 struct resource *pr, *r = &dev->resource[idx]; 1268 struct resource *pr, *r = &dev->resource[idx];
1270 1269
@@ -1428,8 +1427,6 @@ void __init pcibios_resource_survey(void)
1428 ppc_md.pcibios_fixup(); 1427 ppc_md.pcibios_fixup();
1429} 1428}
1430 1429
1431#ifdef CONFIG_HOTPLUG
1432
1433/* This is used by the PCI hotplug driver to allocate resource 1430/* This is used by the PCI hotplug driver to allocate resource
1434 * of newly plugged busses. We can try to consolidate with the 1431 * of newly plugged busses. We can try to consolidate with the
1435 * rest of the code later, for now, keep it as-is as our main 1432 * rest of the code later, for now, keep it as-is as our main
@@ -1488,8 +1485,6 @@ void pcibios_finish_adding_to_bus(struct pci_bus *bus)
1488} 1485}
1489EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus); 1486EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus);
1490 1487
1491#endif /* CONFIG_HOTPLUG */
1492
1493int pcibios_enable_device(struct pci_dev *dev, int mask) 1488int pcibios_enable_device(struct pci_dev *dev, int mask)
1494{ 1489{
1495 if (ppc_md.pcibios_enable_device_hook) 1490 if (ppc_md.pcibios_enable_device_hook)
@@ -1504,7 +1499,8 @@ resource_size_t pcibios_io_space_offset(struct pci_controller *hose)
1504 return (unsigned long) hose->io_base_virt - _IO_BASE; 1499 return (unsigned long) hose->io_base_virt - _IO_BASE;
1505} 1500}
1506 1501
1507static void __devinit pcibios_setup_phb_resources(struct pci_controller *hose, struct list_head *resources) 1502static void pcibios_setup_phb_resources(struct pci_controller *hose,
1503 struct list_head *resources)
1508{ 1504{
1509 struct resource *res; 1505 struct resource *res;
1510 int i; 1506 int i;
@@ -1643,7 +1639,7 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
1643 * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus 1639 * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus
1644 * @hose: Pointer to the PCI host controller instance structure 1640 * @hose: Pointer to the PCI host controller instance structure
1645 */ 1641 */
1646void __devinit pcibios_scan_phb(struct pci_controller *hose) 1642void pcibios_scan_phb(struct pci_controller *hose)
1647{ 1643{
1648 LIST_HEAD(resources); 1644 LIST_HEAD(resources);
1649 struct pci_bus *bus; 1645 struct pci_bus *bus;
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c
index 4b06ec5a502e..e37c2152acf4 100644
--- a/arch/powerpc/kernel/pci_32.c
+++ b/arch/powerpc/kernel/pci_32.c
@@ -208,12 +208,12 @@ pci_create_OF_bus_map(void)
208 of_prop->name = "pci-OF-bus-map"; 208 of_prop->name = "pci-OF-bus-map";
209 of_prop->length = 256; 209 of_prop->length = 256;
210 of_prop->value = &of_prop[1]; 210 of_prop->value = &of_prop[1];
211 prom_add_property(dn, of_prop); 211 of_add_property(dn, of_prop);
212 of_node_put(dn); 212 of_node_put(dn);
213 } 213 }
214} 214}
215 215
216void __devinit pcibios_setup_phb_io_space(struct pci_controller *hose) 216void pcibios_setup_phb_io_space(struct pci_controller *hose)
217{ 217{
218 unsigned long io_offset; 218 unsigned long io_offset;
219 struct resource *res = &hose->io_resource; 219 struct resource *res = &hose->io_resource;
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 4ff190ff24a0..51a133a78a09 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -74,8 +74,6 @@ static int __init pcibios_init(void)
74 74
75subsys_initcall(pcibios_init); 75subsys_initcall(pcibios_init);
76 76
77#ifdef CONFIG_HOTPLUG
78
79int pcibios_unmap_io_space(struct pci_bus *bus) 77int pcibios_unmap_io_space(struct pci_bus *bus)
80{ 78{
81 struct pci_controller *hose; 79 struct pci_controller *hose;
@@ -124,9 +122,7 @@ int pcibios_unmap_io_space(struct pci_bus *bus)
124} 122}
125EXPORT_SYMBOL_GPL(pcibios_unmap_io_space); 123EXPORT_SYMBOL_GPL(pcibios_unmap_io_space);
126 124
127#endif /* CONFIG_HOTPLUG */ 125static int pcibios_map_phb_io_space(struct pci_controller *hose)
128
129static int __devinit pcibios_map_phb_io_space(struct pci_controller *hose)
130{ 126{
131 struct vm_struct *area; 127 struct vm_struct *area;
132 unsigned long phys_page; 128 unsigned long phys_page;
@@ -177,7 +173,7 @@ static int __devinit pcibios_map_phb_io_space(struct pci_controller *hose)
177 return 0; 173 return 0;
178} 174}
179 175
180int __devinit pcibios_map_io_space(struct pci_bus *bus) 176int pcibios_map_io_space(struct pci_bus *bus)
181{ 177{
182 WARN_ON(bus == NULL); 178 WARN_ON(bus == NULL);
183 179
@@ -197,7 +193,7 @@ int __devinit pcibios_map_io_space(struct pci_bus *bus)
197} 193}
198EXPORT_SYMBOL_GPL(pcibios_map_io_space); 194EXPORT_SYMBOL_GPL(pcibios_map_io_space);
199 195
200void __devinit pcibios_setup_phb_io_space(struct pci_controller *hose) 196void pcibios_setup_phb_io_space(struct pci_controller *hose)
201{ 197{
202 pcibios_map_phb_io_space(hose); 198 pcibios_map_phb_io_space(hose);
203} 199}
diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index dd9e4a04bf79..e7af165f8b9d 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -36,7 +36,7 @@
36 * Traverse_func that inits the PCI fields of the device node. 36 * Traverse_func that inits the PCI fields of the device node.
37 * NOTE: this *must* be done before read/write config to the device. 37 * NOTE: this *must* be done before read/write config to the device.
38 */ 38 */
39void * __devinit update_dn_pci_info(struct device_node *dn, void *data) 39void *update_dn_pci_info(struct device_node *dn, void *data)
40{ 40{
41 struct pci_controller *phb = data; 41 struct pci_controller *phb = data;
42 const int *type = 42 const int *type =
@@ -129,7 +129,7 @@ void *traverse_pci_devices(struct device_node *start, traverse_func pre,
129 * subsystem is set up, before kmalloc is valid) and during the 129 * subsystem is set up, before kmalloc is valid) and during the
130 * dynamic lpar operation of adding a PHB to a running system. 130 * dynamic lpar operation of adding a PHB to a running system.
131 */ 131 */
132void __devinit pci_devs_phb_init_dynamic(struct pci_controller *phb) 132void pci_devs_phb_init_dynamic(struct pci_controller *phb)
133{ 133{
134 struct device_node *dn = phb->dn; 134 struct device_node *dn = phb->dn;
135 struct pci_dn *pdn; 135 struct pci_dn *pdn;
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index 30378a19f65d..2a67e9baa59f 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -204,7 +204,7 @@ EXPORT_SYMBOL(of_create_pci_dev);
204 * this routine in turn call of_scan_bus() recusively to scan for more child 204 * this routine in turn call of_scan_bus() recusively to scan for more child
205 * devices. 205 * devices.
206 */ 206 */
207void __devinit of_scan_pci_bridge(struct pci_dev *dev) 207void of_scan_pci_bridge(struct pci_dev *dev)
208{ 208{
209 struct device_node *node = dev->dev.of_node; 209 struct device_node *node = dev->dev.of_node;
210 struct pci_bus *bus; 210 struct pci_bus *bus;
@@ -299,8 +299,8 @@ EXPORT_SYMBOL(of_scan_pci_bridge);
299 * @bus: pci_bus structure for the PCI bus 299 * @bus: pci_bus structure for the PCI bus
300 * @rescan_existing: Flag indicating bus has already been set up 300 * @rescan_existing: Flag indicating bus has already been set up
301 */ 301 */
302static void __devinit __of_scan_bus(struct device_node *node, 302static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,
303 struct pci_bus *bus, int rescan_existing) 303 int rescan_existing)
304{ 304{
305 struct device_node *child; 305 struct device_node *child;
306 const u32 *reg; 306 const u32 *reg;
@@ -348,8 +348,7 @@ static void __devinit __of_scan_bus(struct device_node *node,
348 * @node: device tree node for the PCI bus 348 * @node: device tree node for the PCI bus
349 * @bus: pci_bus structure for the PCI bus 349 * @bus: pci_bus structure for the PCI bus
350 */ 350 */
351void __devinit of_scan_bus(struct device_node *node, 351void of_scan_bus(struct device_node *node, struct pci_bus *bus)
352 struct pci_bus *bus)
353{ 352{
354 __of_scan_bus(node, bus, 0); 353 __of_scan_bus(node, bus, 0);
355} 354}
@@ -363,8 +362,7 @@ EXPORT_SYMBOL_GPL(of_scan_bus);
363 * Same as of_scan_bus, but for a pci_bus structure that has already been 362 * Same as of_scan_bus, but for a pci_bus structure that has already been
364 * setup. 363 * setup.
365 */ 364 */
366void __devinit of_rescan_bus(struct device_node *node, 365void of_rescan_bus(struct device_node *node, struct pci_bus *bus)
367 struct pci_bus *bus)
368{ 366{
369 __of_scan_bus(node, bus, 1); 367 __of_scan_bus(node, bus, 1);
370} 368}
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 19e4288d8486..78b8766fd79e 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -43,6 +43,7 @@
43#include <asm/dcr.h> 43#include <asm/dcr.h>
44#include <asm/ftrace.h> 44#include <asm/ftrace.h>
45#include <asm/switch_to.h> 45#include <asm/switch_to.h>
46#include <asm/epapr_hcalls.h>
46 47
47#ifdef CONFIG_PPC32 48#ifdef CONFIG_PPC32
48extern void transfer_to_handler(void); 49extern void transfer_to_handler(void);
@@ -191,3 +192,7 @@ EXPORT_SYMBOL(__arch_hweight64);
191#ifdef CONFIG_PPC_BOOK3S_64 192#ifdef CONFIG_PPC_BOOK3S_64
192EXPORT_SYMBOL_GPL(mmu_psize_defs); 193EXPORT_SYMBOL_GPL(mmu_psize_defs);
193#endif 194#endif
195
196#ifdef CONFIG_EPAPR_PARAVIRT
197EXPORT_SYMBOL(epapr_hypercall_start);
198#endif
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index ba48233500f6..81430674e71c 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -733,8 +733,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
733extern unsigned long dscr_default; /* defined in arch/powerpc/kernel/sysfs.c */ 733extern unsigned long dscr_default; /* defined in arch/powerpc/kernel/sysfs.c */
734 734
735int copy_thread(unsigned long clone_flags, unsigned long usp, 735int copy_thread(unsigned long clone_flags, unsigned long usp,
736 unsigned long arg, struct task_struct *p, 736 unsigned long arg, struct task_struct *p)
737 struct pt_regs *regs)
738{ 737{
739 struct pt_regs *childregs, *kregs; 738 struct pt_regs *childregs, *kregs;
740 extern void ret_from_fork(void); 739 extern void ret_from_fork(void);
@@ -745,25 +744,25 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
745 /* Copy registers */ 744 /* Copy registers */
746 sp -= sizeof(struct pt_regs); 745 sp -= sizeof(struct pt_regs);
747 childregs = (struct pt_regs *) sp; 746 childregs = (struct pt_regs *) sp;
748 if (!regs) { 747 if (unlikely(p->flags & PF_KTHREAD)) {
749 /* for kernel thread, set `current' and stackptr in new task */ 748 struct thread_info *ti = (void *)task_stack_page(p);
750 memset(childregs, 0, sizeof(struct pt_regs)); 749 memset(childregs, 0, sizeof(struct pt_regs));
751 childregs->gpr[1] = sp + sizeof(struct pt_regs); 750 childregs->gpr[1] = sp + sizeof(struct pt_regs);
751 childregs->gpr[14] = usp; /* function */
752#ifdef CONFIG_PPC64 752#ifdef CONFIG_PPC64
753 childregs->gpr[14] = *(unsigned long *)usp;
754 childregs->gpr[2] = ((unsigned long *)usp)[1],
755 clear_tsk_thread_flag(p, TIF_32BIT); 753 clear_tsk_thread_flag(p, TIF_32BIT);
756#else 754 childregs->softe = 1;
757 childregs->gpr[14] = usp; /* function */
758 childregs->gpr[2] = (unsigned long) p;
759#endif 755#endif
760 childregs->gpr[15] = arg; 756 childregs->gpr[15] = arg;
761 p->thread.regs = NULL; /* no user register state */ 757 p->thread.regs = NULL; /* no user register state */
758 ti->flags |= _TIF_RESTOREALL;
762 f = ret_from_kernel_thread; 759 f = ret_from_kernel_thread;
763 } else { 760 } else {
761 struct pt_regs *regs = current_pt_regs();
764 CHECK_FULL_REGS(regs); 762 CHECK_FULL_REGS(regs);
765 *childregs = *regs; 763 *childregs = *regs;
766 childregs->gpr[1] = usp; 764 if (usp)
765 childregs->gpr[1] = usp;
767 p->thread.regs = childregs; 766 p->thread.regs = childregs;
768 childregs->gpr[3] = 0; /* Result from fork() */ 767 childregs->gpr[3] = 0; /* Result from fork() */
769 if (clone_flags & CLONE_SETTLS) { 768 if (clone_flags & CLONE_SETTLS) {
@@ -1027,51 +1026,6 @@ int get_unalign_ctl(struct task_struct *tsk, unsigned long adr)
1027 return put_user(tsk->thread.align_ctl, (unsigned int __user *)adr); 1026 return put_user(tsk->thread.align_ctl, (unsigned int __user *)adr);
1028} 1027}
1029 1028
1030#define TRUNC_PTR(x) ((typeof(x))(((unsigned long)(x)) & 0xffffffff))
1031
1032int sys_clone(unsigned long clone_flags, unsigned long usp,
1033 int __user *parent_tidp, void __user *child_threadptr,
1034 int __user *child_tidp, int p6,
1035 struct pt_regs *regs)
1036{
1037 CHECK_FULL_REGS(regs);
1038 if (usp == 0)
1039 usp = regs->gpr[1]; /* stack pointer for child */
1040#ifdef CONFIG_PPC64
1041 if (is_32bit_task()) {
1042 parent_tidp = TRUNC_PTR(parent_tidp);
1043 child_tidp = TRUNC_PTR(child_tidp);
1044 }
1045#endif
1046 return do_fork(clone_flags, usp, regs, 0, parent_tidp, child_tidp);
1047}
1048
1049int sys_fork(unsigned long p1, unsigned long p2, unsigned long p3,
1050 unsigned long p4, unsigned long p5, unsigned long p6,
1051 struct pt_regs *regs)
1052{
1053 CHECK_FULL_REGS(regs);
1054 return do_fork(SIGCHLD, regs->gpr[1], regs, 0, NULL, NULL);
1055}
1056
1057int sys_vfork(unsigned long p1, unsigned long p2, unsigned long p3,
1058 unsigned long p4, unsigned long p5, unsigned long p6,
1059 struct pt_regs *regs)
1060{
1061 CHECK_FULL_REGS(regs);
1062 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gpr[1],
1063 regs, 0, NULL, NULL);
1064}
1065
1066void __ret_from_kernel_execve(struct pt_regs *normal)
1067__noreturn;
1068
1069void ret_from_kernel_execve(struct pt_regs *normal)
1070{
1071 set_thread_flag(TIF_RESTOREALL);
1072 __ret_from_kernel_execve(normal);
1073}
1074
1075static inline int valid_irq_stack(unsigned long sp, struct task_struct *p, 1029static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,
1076 unsigned long nbytes) 1030 unsigned long nbytes)
1077{ 1031{
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 37725e86651e..8b6f7a99cce2 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -32,6 +32,7 @@
32#include <linux/debugfs.h> 32#include <linux/debugfs.h>
33#include <linux/irq.h> 33#include <linux/irq.h>
34#include <linux/memblock.h> 34#include <linux/memblock.h>
35#include <linux/of.h>
35 36
36#include <asm/prom.h> 37#include <asm/prom.h>
37#include <asm/rtas.h> 38#include <asm/rtas.h>
@@ -49,11 +50,11 @@
49#include <asm/btext.h> 50#include <asm/btext.h>
50#include <asm/sections.h> 51#include <asm/sections.h>
51#include <asm/machdep.h> 52#include <asm/machdep.h>
52#include <asm/pSeries_reconfig.h>
53#include <asm/pci-bridge.h> 53#include <asm/pci-bridge.h>
54#include <asm/kexec.h> 54#include <asm/kexec.h>
55#include <asm/opal.h> 55#include <asm/opal.h>
56#include <asm/fadump.h> 56#include <asm/fadump.h>
57#include <asm/debug.h>
57 58
58#include <mm/mmu_decl.h> 59#include <mm/mmu_decl.h>
59 60
@@ -802,7 +803,7 @@ static int prom_reconfig_notifier(struct notifier_block *nb,
802 int err; 803 int err;
803 804
804 switch (action) { 805 switch (action) {
805 case PSERIES_RECONFIG_ADD: 806 case OF_RECONFIG_ATTACH_NODE:
806 err = of_finish_dynamic_node(node); 807 err = of_finish_dynamic_node(node);
807 if (err < 0) 808 if (err < 0)
808 printk(KERN_ERR "finish_node returned %d\n", err); 809 printk(KERN_ERR "finish_node returned %d\n", err);
@@ -821,7 +822,7 @@ static struct notifier_block prom_reconfig_nb = {
821 822
822static int __init prom_reconfig_setup(void) 823static int __init prom_reconfig_setup(void)
823{ 824{
824 return pSeries_reconfig_notifier_register(&prom_reconfig_nb); 825 return of_reconfig_notifier_register(&prom_reconfig_nb);
825} 826}
826__initcall(prom_reconfig_setup); 827__initcall(prom_reconfig_setup);
827#endif 828#endif
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index cb6c123722a2..779f34049a56 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -671,6 +671,7 @@ static void __init early_cmdline_parse(void)
671#define OV1_PPC_2_04 0x08 /* set if we support PowerPC 2.04 */ 671#define OV1_PPC_2_04 0x08 /* set if we support PowerPC 2.04 */
672#define OV1_PPC_2_05 0x04 /* set if we support PowerPC 2.05 */ 672#define OV1_PPC_2_05 0x04 /* set if we support PowerPC 2.05 */
673#define OV1_PPC_2_06 0x02 /* set if we support PowerPC 2.06 */ 673#define OV1_PPC_2_06 0x02 /* set if we support PowerPC 2.06 */
674#define OV1_PPC_2_07 0x01 /* set if we support PowerPC 2.07 */
674 675
675/* Option vector 2: Open Firmware options supported */ 676/* Option vector 2: Open Firmware options supported */
676#define OV2_REAL_MODE 0x20 /* set if we want OF in real mode */ 677#define OV2_REAL_MODE 0x20 /* set if we want OF in real mode */
@@ -707,6 +708,7 @@ static void __init early_cmdline_parse(void)
707#define OV5_PFO_HW_RNG 0x80 /* PFO Random Number Generator */ 708#define OV5_PFO_HW_RNG 0x80 /* PFO Random Number Generator */
708#define OV5_PFO_HW_842 0x40 /* PFO Compression Accelerator */ 709#define OV5_PFO_HW_842 0x40 /* PFO Compression Accelerator */
709#define OV5_PFO_HW_ENCR 0x20 /* PFO Encryption Accelerator */ 710#define OV5_PFO_HW_ENCR 0x20 /* PFO Encryption Accelerator */
711#define OV5_SUB_PROCESSORS 0x01 /* 1,2,or 4 Sub-Processors supported */
710 712
711/* Option Vector 6: IBM PAPR hints */ 713/* Option Vector 6: IBM PAPR hints */
712#define OV6_LINUX 0x02 /* Linux is our OS */ 714#define OV6_LINUX 0x02 /* Linux is our OS */
@@ -719,6 +721,8 @@ static unsigned char ibm_architecture_vec[] = {
719 W(0xfffe0000), W(0x003a0000), /* POWER5/POWER5+ */ 721 W(0xfffe0000), W(0x003a0000), /* POWER5/POWER5+ */
720 W(0xffff0000), W(0x003e0000), /* POWER6 */ 722 W(0xffff0000), W(0x003e0000), /* POWER6 */
721 W(0xffff0000), W(0x003f0000), /* POWER7 */ 723 W(0xffff0000), W(0x003f0000), /* POWER7 */
724 W(0xffff0000), W(0x004b0000), /* POWER8 */
725 W(0xffffffff), W(0x0f000004), /* all 2.07-compliant */
722 W(0xffffffff), W(0x0f000003), /* all 2.06-compliant */ 726 W(0xffffffff), W(0x0f000003), /* all 2.06-compliant */
723 W(0xffffffff), W(0x0f000002), /* all 2.05-compliant */ 727 W(0xffffffff), W(0x0f000002), /* all 2.05-compliant */
724 W(0xfffffffe), W(0x0f000001), /* all 2.04-compliant and earlier */ 728 W(0xfffffffe), W(0x0f000001), /* all 2.04-compliant and earlier */
@@ -728,7 +732,7 @@ static unsigned char ibm_architecture_vec[] = {
728 3 - 2, /* length */ 732 3 - 2, /* length */
729 0, /* don't ignore, don't halt */ 733 0, /* don't ignore, don't halt */
730 OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 | 734 OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 |
731 OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06, 735 OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06 | OV1_PPC_2_07,
732 736
733 /* option vector 2: Open Firmware options supported */ 737 /* option vector 2: Open Firmware options supported */
734 34 - 2, /* length */ 738 34 - 2, /* length */
@@ -755,7 +759,7 @@ static unsigned char ibm_architecture_vec[] = {
755 OV4_MIN_ENT_CAP, /* minimum VP entitled capacity */ 759 OV4_MIN_ENT_CAP, /* minimum VP entitled capacity */
756 760
757 /* option vector 5: PAPR/OF options */ 761 /* option vector 5: PAPR/OF options */
758 18 - 2, /* length */ 762 19 - 2, /* length */
759 0, /* don't ignore, don't halt */ 763 0, /* don't ignore, don't halt */
760 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY | 764 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY |
761 OV5_DONATE_DEDICATE_CPU | OV5_MSI, 765 OV5_DONATE_DEDICATE_CPU | OV5_MSI,
@@ -769,13 +773,14 @@ static unsigned char ibm_architecture_vec[] = {
769 * must match by the macro below. Update the definition if 773 * must match by the macro below. Update the definition if
770 * the structure layout changes. 774 * the structure layout changes.
771 */ 775 */
772#define IBM_ARCH_VEC_NRCORES_OFFSET 101 776#define IBM_ARCH_VEC_NRCORES_OFFSET 117
773 W(NR_CPUS), /* number of cores supported */ 777 W(NR_CPUS), /* number of cores supported */
774 0, 778 0,
775 0, 779 0,
776 0, 780 0,
777 0, 781 0,
778 OV5_PFO_HW_RNG | OV5_PFO_HW_ENCR | OV5_PFO_HW_842, 782 OV5_PFO_HW_RNG | OV5_PFO_HW_ENCR | OV5_PFO_HW_842,
783 OV5_SUB_PROCESSORS,
779 /* option vector 6: IBM PAPR hints */ 784 /* option vector 6: IBM PAPR hints */
780 4 - 2, /* length */ 785 4 - 2, /* length */
781 0, 786 0,
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 79d8e56470df..c4970004d44d 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -952,6 +952,10 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
952 arch_bp_generic_fields(data & 952 arch_bp_generic_fields(data &
953 (DABR_DATA_WRITE | DABR_DATA_READ), 953 (DABR_DATA_WRITE | DABR_DATA_READ),
954 &attr.bp_type); 954 &attr.bp_type);
955
956 /* Enable breakpoint */
957 attr.disabled = false;
958
955 ret = modify_user_hw_breakpoint(bp, &attr); 959 ret = modify_user_hw_breakpoint(bp, &attr);
956 if (ret) { 960 if (ret) {
957 ptrace_put_breakpoints(task); 961 ptrace_put_breakpoints(task);
@@ -1037,7 +1041,7 @@ void ptrace_disable(struct task_struct *child)
1037} 1041}
1038 1042
1039#ifdef CONFIG_PPC_ADV_DEBUG_REGS 1043#ifdef CONFIG_PPC_ADV_DEBUG_REGS
1040static long set_intruction_bp(struct task_struct *child, 1044static long set_instruction_bp(struct task_struct *child,
1041 struct ppc_hw_breakpoint *bp_info) 1045 struct ppc_hw_breakpoint *bp_info)
1042{ 1046{
1043 int slot; 1047 int slot;
@@ -1338,6 +1342,12 @@ static int set_dac_range(struct task_struct *child,
1338static long ppc_set_hwdebug(struct task_struct *child, 1342static long ppc_set_hwdebug(struct task_struct *child,
1339 struct ppc_hw_breakpoint *bp_info) 1343 struct ppc_hw_breakpoint *bp_info)
1340{ 1344{
1345#ifdef CONFIG_HAVE_HW_BREAKPOINT
1346 int len = 0;
1347 struct thread_struct *thread = &(child->thread);
1348 struct perf_event *bp;
1349 struct perf_event_attr attr;
1350#endif /* CONFIG_HAVE_HW_BREAKPOINT */
1341#ifndef CONFIG_PPC_ADV_DEBUG_REGS 1351#ifndef CONFIG_PPC_ADV_DEBUG_REGS
1342 unsigned long dabr; 1352 unsigned long dabr;
1343#endif 1353#endif
@@ -1365,7 +1375,7 @@ static long ppc_set_hwdebug(struct task_struct *child,
1365 if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) || 1375 if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) ||
1366 (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)) 1376 (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE))
1367 return -EINVAL; 1377 return -EINVAL;
1368 return set_intruction_bp(child, bp_info); 1378 return set_instruction_bp(child, bp_info);
1369 } 1379 }
1370 if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) 1380 if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
1371 return set_dac(child, bp_info); 1381 return set_dac(child, bp_info);
@@ -1381,13 +1391,9 @@ static long ppc_set_hwdebug(struct task_struct *child,
1381 */ 1391 */
1382 if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 || 1392 if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 ||
1383 (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 || 1393 (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 ||
1384 bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT ||
1385 bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) 1394 bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
1386 return -EINVAL; 1395 return -EINVAL;
1387 1396
1388 if (child->thread.dabr)
1389 return -ENOSPC;
1390
1391 if ((unsigned long)bp_info->addr >= TASK_SIZE) 1397 if ((unsigned long)bp_info->addr >= TASK_SIZE)
1392 return -EIO; 1398 return -EIO;
1393 1399
@@ -1397,6 +1403,50 @@ static long ppc_set_hwdebug(struct task_struct *child,
1397 dabr |= DABR_DATA_READ; 1403 dabr |= DABR_DATA_READ;
1398 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) 1404 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
1399 dabr |= DABR_DATA_WRITE; 1405 dabr |= DABR_DATA_WRITE;
1406#ifdef CONFIG_HAVE_HW_BREAKPOINT
1407 if (ptrace_get_breakpoints(child) < 0)
1408 return -ESRCH;
1409
1410 /*
1411 * Check if the request is for 'range' breakpoints. We can
1412 * support it if range < 8 bytes.
1413 */
1414 if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) {
1415 len = bp_info->addr2 - bp_info->addr;
1416 } else if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) {
1417 ptrace_put_breakpoints(child);
1418 return -EINVAL;
1419 }
1420 bp = thread->ptrace_bps[0];
1421 if (bp) {
1422 ptrace_put_breakpoints(child);
1423 return -ENOSPC;
1424 }
1425
1426 /* Create a new breakpoint request if one doesn't exist already */
1427 hw_breakpoint_init(&attr);
1428 attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN;
1429 attr.bp_len = len;
1430 arch_bp_generic_fields(dabr & (DABR_DATA_WRITE | DABR_DATA_READ),
1431 &attr.bp_type);
1432
1433 thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
1434 ptrace_triggered, NULL, child);
1435 if (IS_ERR(bp)) {
1436 thread->ptrace_bps[0] = NULL;
1437 ptrace_put_breakpoints(child);
1438 return PTR_ERR(bp);
1439 }
1440
1441 ptrace_put_breakpoints(child);
1442 return 1;
1443#endif /* CONFIG_HAVE_HW_BREAKPOINT */
1444
1445 if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT)
1446 return -EINVAL;
1447
1448 if (child->thread.dabr)
1449 return -ENOSPC;
1400 1450
1401 child->thread.dabr = dabr; 1451 child->thread.dabr = dabr;
1402 child->thread.dabrx = DABRX_ALL; 1452 child->thread.dabrx = DABRX_ALL;
@@ -1405,8 +1455,13 @@ static long ppc_set_hwdebug(struct task_struct *child,
1405#endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */ 1455#endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
1406} 1456}
1407 1457
1408static long ppc_del_hwdebug(struct task_struct *child, long addr, long data) 1458static long ppc_del_hwdebug(struct task_struct *child, long data)
1409{ 1459{
1460#ifdef CONFIG_HAVE_HW_BREAKPOINT
1461 int ret = 0;
1462 struct thread_struct *thread = &(child->thread);
1463 struct perf_event *bp;
1464#endif /* CONFIG_HAVE_HW_BREAKPOINT */
1410#ifdef CONFIG_PPC_ADV_DEBUG_REGS 1465#ifdef CONFIG_PPC_ADV_DEBUG_REGS
1411 int rc; 1466 int rc;
1412 1467
@@ -1426,10 +1481,25 @@ static long ppc_del_hwdebug(struct task_struct *child, long addr, long data)
1426#else 1481#else
1427 if (data != 1) 1482 if (data != 1)
1428 return -EINVAL; 1483 return -EINVAL;
1484
1485#ifdef CONFIG_HAVE_HW_BREAKPOINT
1486 if (ptrace_get_breakpoints(child) < 0)
1487 return -ESRCH;
1488
1489 bp = thread->ptrace_bps[0];
1490 if (bp) {
1491 unregister_hw_breakpoint(bp);
1492 thread->ptrace_bps[0] = NULL;
1493 } else
1494 ret = -ENOENT;
1495 ptrace_put_breakpoints(child);
1496 return ret;
1497#else /* CONFIG_HAVE_HW_BREAKPOINT */
1429 if (child->thread.dabr == 0) 1498 if (child->thread.dabr == 0)
1430 return -ENOENT; 1499 return -ENOENT;
1431 1500
1432 child->thread.dabr = 0; 1501 child->thread.dabr = 0;
1502#endif /* CONFIG_HAVE_HW_BREAKPOINT */
1433 1503
1434 return 0; 1504 return 0;
1435#endif 1505#endif
@@ -1536,7 +1606,11 @@ long arch_ptrace(struct task_struct *child, long request,
1536 dbginfo.data_bp_alignment = 4; 1606 dbginfo.data_bp_alignment = 4;
1537#endif 1607#endif
1538 dbginfo.sizeof_condition = 0; 1608 dbginfo.sizeof_condition = 0;
1609#ifdef CONFIG_HAVE_HW_BREAKPOINT
1610 dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE;
1611#else
1539 dbginfo.features = 0; 1612 dbginfo.features = 0;
1613#endif /* CONFIG_HAVE_HW_BREAKPOINT */
1540#endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 1614#endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1541 1615
1542 if (!access_ok(VERIFY_WRITE, datavp, 1616 if (!access_ok(VERIFY_WRITE, datavp,
@@ -1563,7 +1637,7 @@ long arch_ptrace(struct task_struct *child, long request,
1563 } 1637 }
1564 1638
1565 case PPC_PTRACE_DELHWDEBUG: { 1639 case PPC_PTRACE_DELHWDEBUG: {
1566 ret = ppc_del_hwdebug(child, addr, data); 1640 ret = ppc_del_hwdebug(child, data);
1567 break; 1641 break;
1568 } 1642 }
1569 1643
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index fcec38241f79..1fd6e7b2f390 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -42,7 +42,6 @@
42#include <asm/time.h> 42#include <asm/time.h>
43#include <asm/mmu.h> 43#include <asm/mmu.h>
44#include <asm/topology.h> 44#include <asm/topology.h>
45#include <asm/pSeries_reconfig.h>
46 45
47struct rtas_t rtas = { 46struct rtas_t rtas = {
48 .lock = __ARCH_SPIN_LOCK_UNLOCKED 47 .lock = __ARCH_SPIN_LOCK_UNLOCKED
diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index 20b0120db0c3..8329190312c1 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -650,10 +650,8 @@ static int initialize_flash_pde_data(const char *rtas_call_name,
650 int token; 650 int token;
651 651
652 dp->data = kzalloc(buf_size, GFP_KERNEL); 652 dp->data = kzalloc(buf_size, GFP_KERNEL);
653 if (dp->data == NULL) { 653 if (dp->data == NULL)
654 remove_flash_pde(dp);
655 return -ENOMEM; 654 return -ENOMEM;
656 }
657 655
658 /* 656 /*
659 * This code assumes that the status int is the first member of the 657 * This code assumes that the status int is the first member of the
diff --git a/arch/powerpc/kernel/rtas_pci.c b/arch/powerpc/kernel/rtas_pci.c
index 6de63e3250bb..71cb20d6ec61 100644
--- a/arch/powerpc/kernel/rtas_pci.c
+++ b/arch/powerpc/kernel/rtas_pci.c
@@ -209,7 +209,7 @@ void __init init_pci_config_tokens (void)
209 ibm_write_pci_config = rtas_token("ibm,write-pci-config"); 209 ibm_write_pci_config = rtas_token("ibm,write-pci-config");
210} 210}
211 211
212unsigned long __devinit get_phb_buid (struct device_node *phb) 212unsigned long get_phb_buid (struct device_node *phb)
213{ 213{
214 struct resource r; 214 struct resource r;
215 215
@@ -237,7 +237,7 @@ static int phb_set_bus_ranges(struct device_node *dev,
237 return 0; 237 return 0;
238} 238}
239 239
240int __devinit rtas_setup_phb(struct pci_controller *phb) 240int rtas_setup_phb(struct pci_controller *phb)
241{ 241{
242 struct device_node *dev = phb->dn; 242 struct device_node *dev = phb->dn;
243 243
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index efb6a41b3131..6da881b35dac 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -601,6 +601,11 @@ void __init setup_arch(char **cmdline_p)
601 601
602 kvm_linear_init(); 602 kvm_linear_init();
603 603
604 /* Interrupt code needs to be 64K-aligned */
605 if ((unsigned long)_stext & 0xffff)
606 panic("Kernelbase not 64K-aligned (0x%lx)!\n",
607 (unsigned long)_stext);
608
604 ppc64_boot_msg(0x15, "Setup Done"); 609 ppc64_boot_msg(0x15, "Setup Done");
605} 610}
606 611
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index a2dc75793bd5..3b997118df50 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -158,10 +158,8 @@ static int do_signal(struct pt_regs *regs)
158 158
159void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) 159void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
160{ 160{
161 if (thread_info_flags & _TIF_UPROBE) { 161 if (thread_info_flags & _TIF_UPROBE)
162 clear_thread_flag(TIF_UPROBE);
163 uprobe_notify_resume(regs); 162 uprobe_notify_resume(regs);
164 }
165 163
166 if (thread_info_flags & _TIF_SIGPENDING) 164 if (thread_info_flags & _TIF_SIGPENDING)
167 do_signal(regs); 165 do_signal(regs);
diff --git a/arch/powerpc/kernel/smp-tbsync.c b/arch/powerpc/kernel/smp-tbsync.c
index 640de836e466..e68fd1ae727a 100644
--- a/arch/powerpc/kernel/smp-tbsync.c
+++ b/arch/powerpc/kernel/smp-tbsync.c
@@ -36,13 +36,13 @@ static struct {
36 36
37static volatile int running; 37static volatile int running;
38 38
39static void __devinit enter_contest(u64 mark, long add) 39static void enter_contest(u64 mark, long add)
40{ 40{
41 while (get_tb() < mark) 41 while (get_tb() < mark)
42 tbsync->race_result = add; 42 tbsync->race_result = add;
43} 43}
44 44
45void __devinit smp_generic_take_timebase(void) 45void smp_generic_take_timebase(void)
46{ 46{
47 int cmd; 47 int cmd;
48 u64 tb; 48 u64 tb;
@@ -75,7 +75,7 @@ void __devinit smp_generic_take_timebase(void)
75 local_irq_restore(flags); 75 local_irq_restore(flags);
76} 76}
77 77
78static int __devinit start_contest(int cmd, long offset, int num) 78static int start_contest(int cmd, long offset, int num)
79{ 79{
80 int i, score=0; 80 int i, score=0;
81 u64 tb; 81 u64 tb;
@@ -110,7 +110,7 @@ static int __devinit start_contest(int cmd, long offset, int num)
110 return score; 110 return score;
111} 111}
112 112
113void __devinit smp_generic_give_timebase(void) 113void smp_generic_give_timebase(void)
114{ 114{
115 int i, score, score2, old, min=0, max=5000, offset=1000; 115 int i, score, score2, old, min=0, max=5000, offset=1000;
116 116
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 2b952b5386fd..793401e65088 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -82,7 +82,7 @@ int smt_enabled_at_boot = 1;
82static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL; 82static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL;
83 83
84#ifdef CONFIG_PPC64 84#ifdef CONFIG_PPC64
85int __devinit smp_generic_kick_cpu(int nr) 85int smp_generic_kick_cpu(int nr)
86{ 86{
87 BUG_ON(nr < 0 || nr >= NR_CPUS); 87 BUG_ON(nr < 0 || nr >= NR_CPUS);
88 88
@@ -311,7 +311,7 @@ void smp_send_stop(void)
311 311
312struct thread_info *current_set[NR_CPUS]; 312struct thread_info *current_set[NR_CPUS];
313 313
314static void __devinit smp_store_cpu_info(int id) 314static void smp_store_cpu_info(int id)
315{ 315{
316 per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR); 316 per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
317#ifdef CONFIG_PPC_FSL_BOOK3E 317#ifdef CONFIG_PPC_FSL_BOOK3E
@@ -355,7 +355,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
355 max_cpus = 1; 355 max_cpus = 1;
356} 356}
357 357
358void __devinit smp_prepare_boot_cpu(void) 358void smp_prepare_boot_cpu(void)
359{ 359{
360 BUG_ON(smp_processor_id() != boot_cpuid); 360 BUG_ON(smp_processor_id() != boot_cpuid);
361#ifdef CONFIG_PPC64 361#ifdef CONFIG_PPC64
@@ -427,6 +427,45 @@ int generic_check_cpu_restart(unsigned int cpu)
427{ 427{
428 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE; 428 return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
429} 429}
430
431static atomic_t secondary_inhibit_count;
432
433/*
434 * Don't allow secondary CPU threads to come online
435 */
436void inhibit_secondary_onlining(void)
437{
438 /*
439 * This makes secondary_inhibit_count stable during cpu
440 * online/offline operations.
441 */
442 get_online_cpus();
443
444 atomic_inc(&secondary_inhibit_count);
445 put_online_cpus();
446}
447EXPORT_SYMBOL_GPL(inhibit_secondary_onlining);
448
449/*
450 * Allow secondary CPU threads to come online again
451 */
452void uninhibit_secondary_onlining(void)
453{
454 get_online_cpus();
455 atomic_dec(&secondary_inhibit_count);
456 put_online_cpus();
457}
458EXPORT_SYMBOL_GPL(uninhibit_secondary_onlining);
459
460static int secondaries_inhibited(void)
461{
462 return atomic_read(&secondary_inhibit_count);
463}
464
465#else /* HOTPLUG_CPU */
466
467#define secondaries_inhibited() 0
468
430#endif 469#endif
431 470
432static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle) 471static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
@@ -445,6 +484,13 @@ int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle)
445{ 484{
446 int rc, c; 485 int rc, c;
447 486
487 /*
488 * Don't allow secondary threads to come online if inhibited
489 */
490 if (threads_per_core > 1 && secondaries_inhibited() &&
491 cpu % threads_per_core != 0)
492 return -EBUSY;
493
448 if (smp_ops == NULL || 494 if (smp_ops == NULL ||
449 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu))) 495 (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
450 return -EINVAL; 496 return -EINVAL;
@@ -564,7 +610,7 @@ static struct device_node *cpu_to_l2cache(int cpu)
564} 610}
565 611
566/* Activate a secondary processor. */ 612/* Activate a secondary processor. */
567void __devinit start_secondary(void *unused) 613void start_secondary(void *unused)
568{ 614{
569 unsigned int cpu = smp_processor_id(); 615 unsigned int cpu = smp_processor_id();
570 struct device_node *l2_cache; 616 struct device_node *l2_cache;
diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
index 9c2ed90ece8f..8a93778ed9f5 100644
--- a/arch/powerpc/kernel/sys_ppc32.c
+++ b/arch/powerpc/kernel/sys_ppc32.c
@@ -175,19 +175,10 @@ asmlinkage long compat_sys_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 a
175 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 175 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
176 * and the register representation of a signed int (msr in 64-bit mode) is performed. 176 * and the register representation of a signed int (msr in 64-bit mode) is performed.
177 */ 177 */
178asmlinkage long compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval) 178asmlinkage long compat_sys_sched_rr_get_interval_wrapper(u32 pid,
179{ 179 struct compat_timespec __user *interval)
180 struct timespec t; 180{
181 int ret; 181 return compat_sys_sched_rr_get_interval((int)pid, interval);
182 mm_segment_t old_fs = get_fs ();
183
184 /* The __user pointer cast is valid because of the set_fs() */
185 set_fs (KERNEL_DS);
186 ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
187 set_fs (old_fs);
188 if (put_compat_timespec(&t, interval))
189 return -EFAULT;
190 return ret;
191} 182}
192 183
193/* Note: it is necessary to treat mode as an unsigned int, 184/* Note: it is necessary to treat mode as an unsigned int,
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index cf357a059ddb..3ce1f864c2d3 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -607,7 +607,7 @@ static void register_nodes(void)
607 607
608int sysfs_add_device_to_node(struct device *dev, int nid) 608int sysfs_add_device_to_node(struct device *dev, int nid)
609{ 609{
610 struct node *node = &node_devices[nid]; 610 struct node *node = node_devices[nid];
611 return sysfs_create_link(&node->dev.kobj, &dev->kobj, 611 return sysfs_create_link(&node->dev.kobj, &dev->kobj,
612 kobject_name(&dev->kobj)); 612 kobject_name(&dev->kobj));
613} 613}
@@ -615,7 +615,7 @@ EXPORT_SYMBOL_GPL(sysfs_add_device_to_node);
615 615
616void sysfs_remove_device_from_node(struct device *dev, int nid) 616void sysfs_remove_device_from_node(struct device *dev, int nid)
617{ 617{
618 struct node *node = &node_devices[nid]; 618 struct node *node = node_devices[nid];
619 sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj)); 619 sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj));
620} 620}
621EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node); 621EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index ce4cb772dc78..127361e093f4 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -297,6 +297,8 @@ static u64 vtime_delta(struct task_struct *tsk,
297 u64 now, nowscaled, deltascaled; 297 u64 now, nowscaled, deltascaled;
298 u64 udelta, delta, user_scaled; 298 u64 udelta, delta, user_scaled;
299 299
300 WARN_ON_ONCE(!irqs_disabled());
301
300 now = mftb(); 302 now = mftb();
301 nowscaled = read_spurr(now); 303 nowscaled = read_spurr(now);
302 get_paca()->system_time += now - get_paca()->starttime; 304 get_paca()->system_time += now - get_paca()->starttime;
@@ -355,15 +357,15 @@ void vtime_account_idle(struct task_struct *tsk)
355} 357}
356 358
357/* 359/*
358 * Transfer the user and system times accumulated in the paca 360 * Transfer the user time accumulated in the paca
359 * by the exception entry and exit code to the generic process 361 * by the exception entry and exit code to the generic
360 * user and system time records. 362 * process user time records.
361 * Must be called with interrupts disabled. 363 * Must be called with interrupts disabled.
362 * Assumes that vtime_account() has been called recently 364 * Assumes that vtime_account_system/idle() has been called
363 * (i.e. since the last entry from usermode) so that 365 * recently (i.e. since the last entry from usermode) so that
364 * get_paca()->user_time_scaled is up to date. 366 * get_paca()->user_time_scaled is up to date.
365 */ 367 */
366void account_process_tick(struct task_struct *tsk, int user_tick) 368void vtime_account_user(struct task_struct *tsk)
367{ 369{
368 cputime_t utime, utimescaled; 370 cputime_t utime, utimescaled;
369 371
@@ -375,12 +377,6 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
375 account_user_time(tsk, utime, utimescaled); 377 account_user_time(tsk, utime, utimescaled);
376} 378}
377 379
378void vtime_task_switch(struct task_struct *prev)
379{
380 vtime_account(prev);
381 account_process_tick(prev, 0);
382}
383
384#else /* ! CONFIG_VIRT_CPU_ACCOUNTING */ 380#else /* ! CONFIG_VIRT_CPU_ACCOUNTING */
385#define calc_cputime_factors() 381#define calc_cputime_factors()
386#endif 382#endif
@@ -498,10 +494,15 @@ void timer_interrupt(struct pt_regs * regs)
498 set_dec(DECREMENTER_MAX); 494 set_dec(DECREMENTER_MAX);
499 495
500 /* Some implementations of hotplug will get timer interrupts while 496 /* Some implementations of hotplug will get timer interrupts while
501 * offline, just ignore these 497 * offline, just ignore these and we also need to set
498 * decrementers_next_tb as MAX to make sure __check_irq_replay
499 * don't replay timer interrupt when return, otherwise we'll trap
500 * here infinitely :(
502 */ 501 */
503 if (!cpu_online(smp_processor_id())) 502 if (!cpu_online(smp_processor_id())) {
503 *next_tb = ~(u64)0;
504 return; 504 return;
505 }
505 506
506 /* Conditionally hard-enable interrupts now that the DEC has been 507 /* Conditionally hard-enable interrupts now that the DEC has been
507 * bumped to its maximum value 508 * bumped to its maximum value
@@ -774,13 +775,8 @@ void update_vsyscall_old(struct timespec *wall_time, struct timespec *wtm,
774 775
775void update_vsyscall_tz(void) 776void update_vsyscall_tz(void)
776{ 777{
777 /* Make userspace gettimeofday spin until we're done. */
778 ++vdso_data->tb_update_count;
779 smp_mb();
780 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; 778 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
781 vdso_data->tz_dsttime = sys_tz.tz_dsttime; 779 vdso_data->tz_dsttime = sys_tz.tz_dsttime;
782 smp_mb();
783 ++vdso_data->tb_update_count;
784} 780}
785 781
786static void __init clocksource_init(void) 782static void __init clocksource_init(void)
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index c39c1ca77f46..f9748498fe58 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -122,29 +122,6 @@ int udbg_write(const char *s, int n)
122 return n - remain; 122 return n - remain;
123} 123}
124 124
125int udbg_read(char *buf, int buflen)
126{
127 char *p = buf;
128 int i, c;
129
130 if (!udbg_getc)
131 return 0;
132
133 for (i = 0; i < buflen; ++i) {
134 do {
135 c = udbg_getc();
136 if (c == -1 && i == 0)
137 return -1;
138
139 } while (c == 0x11 || c == 0x13);
140 if (c == 0 || c == -1)
141 break;
142 *p++ = c;
143 }
144
145 return i;
146}
147
148#define UDBG_BUFSIZE 256 125#define UDBG_BUFSIZE 256
149void udbg_printf(const char *fmt, ...) 126void udbg_printf(const char *fmt, ...)
150{ 127{
diff --git a/arch/powerpc/kernel/uprobes.c b/arch/powerpc/kernel/uprobes.c
index d2d46d1014f8..bc77834dbf43 100644
--- a/arch/powerpc/kernel/uprobes.c
+++ b/arch/powerpc/kernel/uprobes.c
@@ -64,6 +64,8 @@ int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
64 autask->saved_trap_nr = current->thread.trap_nr; 64 autask->saved_trap_nr = current->thread.trap_nr;
65 current->thread.trap_nr = UPROBE_TRAP_NR; 65 current->thread.trap_nr = UPROBE_TRAP_NR;
66 regs->nip = current->utask->xol_vaddr; 66 regs->nip = current->utask->xol_vaddr;
67
68 user_enable_single_step(current);
67 return 0; 69 return 0;
68} 70}
69 71
@@ -119,6 +121,8 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
119 * to be executed. 121 * to be executed.
120 */ 122 */
121 regs->nip = utask->vaddr + MAX_UINSN_BYTES; 123 regs->nip = utask->vaddr + MAX_UINSN_BYTES;
124
125 user_disable_single_step(current);
122 return 0; 126 return 0;
123} 127}
124 128
@@ -162,6 +166,8 @@ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
162 166
163 current->thread.trap_nr = utask->autask.saved_trap_nr; 167 current->thread.trap_nr = utask->autask.saved_trap_nr;
164 instruction_pointer_set(regs, utask->vaddr); 168 instruction_pointer_set(regs, utask->vaddr);
169
170 user_disable_single_step(current);
165} 171}
166 172
167/* 173/*
diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 201ba59738be..536016d792ba 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -1289,7 +1289,7 @@ void vio_unregister_driver(struct vio_driver *viodrv)
1289EXPORT_SYMBOL(vio_unregister_driver); 1289EXPORT_SYMBOL(vio_unregister_driver);
1290 1290
1291/* vio_dev refcount hit 0 */ 1291/* vio_dev refcount hit 0 */
1292static void __devinit vio_dev_release(struct device *dev) 1292static void vio_dev_release(struct device *dev)
1293{ 1293{
1294 struct iommu_table *tbl = get_iommu_table_base(dev); 1294 struct iommu_table *tbl = get_iommu_table_base(dev);
1295 1295
@@ -1545,7 +1545,7 @@ static struct device_attribute vio_dev_attrs[] = {
1545 __ATTR_NULL 1545 __ATTR_NULL
1546}; 1546};
1547 1547
1548void __devinit vio_unregister_device(struct vio_dev *viodev) 1548void vio_unregister_device(struct vio_dev *viodev)
1549{ 1549{
1550 device_unregister(&viodev->dev); 1550 device_unregister(&viodev->dev);
1551} 1551}
diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 50e7dbc7356c..3d7fd21c65f9 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -83,6 +83,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
83 vcpu_44x->shadow_refs[i].gtlb_index = -1; 83 vcpu_44x->shadow_refs[i].gtlb_index = -1;
84 84
85 vcpu->arch.cpu_type = KVM_CPU_440; 85 vcpu->arch.cpu_type = KVM_CPU_440;
86 vcpu->arch.pvr = mfspr(SPRN_PVR);
86 87
87 return 0; 88 return 0;
88} 89}
diff --git a/arch/powerpc/kvm/44x_emulate.c b/arch/powerpc/kvm/44x_emulate.c
index c8c61578fdfc..35ec0a8547da 100644
--- a/arch/powerpc/kvm/44x_emulate.c
+++ b/arch/powerpc/kvm/44x_emulate.c
@@ -27,12 +27,70 @@
27#include "booke.h" 27#include "booke.h"
28#include "44x_tlb.h" 28#include "44x_tlb.h"
29 29
30#define XOP_MFDCRX 259
30#define XOP_MFDCR 323 31#define XOP_MFDCR 323
32#define XOP_MTDCRX 387
31#define XOP_MTDCR 451 33#define XOP_MTDCR 451
32#define XOP_TLBSX 914 34#define XOP_TLBSX 914
33#define XOP_ICCCI 966 35#define XOP_ICCCI 966
34#define XOP_TLBWE 978 36#define XOP_TLBWE 978
35 37
38static int emulate_mtdcr(struct kvm_vcpu *vcpu, int rs, int dcrn)
39{
40 /* emulate some access in kernel */
41 switch (dcrn) {
42 case DCRN_CPR0_CONFIG_ADDR:
43 vcpu->arch.cpr0_cfgaddr = kvmppc_get_gpr(vcpu, rs);
44 return EMULATE_DONE;
45 default:
46 vcpu->run->dcr.dcrn = dcrn;
47 vcpu->run->dcr.data = kvmppc_get_gpr(vcpu, rs);
48 vcpu->run->dcr.is_write = 1;
49 vcpu->arch.dcr_is_write = 1;
50 vcpu->arch.dcr_needed = 1;
51 kvmppc_account_exit(vcpu, DCR_EXITS);
52 return EMULATE_DO_DCR;
53 }
54}
55
56static int emulate_mfdcr(struct kvm_vcpu *vcpu, int rt, int dcrn)
57{
58 /* The guest may access CPR0 registers to determine the timebase
59 * frequency, and it must know the real host frequency because it
60 * can directly access the timebase registers.
61 *
62 * It would be possible to emulate those accesses in userspace,
63 * but userspace can really only figure out the end frequency.
64 * We could decompose that into the factors that compute it, but
65 * that's tricky math, and it's easier to just report the real
66 * CPR0 values.
67 */
68 switch (dcrn) {
69 case DCRN_CPR0_CONFIG_ADDR:
70 kvmppc_set_gpr(vcpu, rt, vcpu->arch.cpr0_cfgaddr);
71 break;
72 case DCRN_CPR0_CONFIG_DATA:
73 local_irq_disable();
74 mtdcr(DCRN_CPR0_CONFIG_ADDR,
75 vcpu->arch.cpr0_cfgaddr);
76 kvmppc_set_gpr(vcpu, rt,
77 mfdcr(DCRN_CPR0_CONFIG_DATA));
78 local_irq_enable();
79 break;
80 default:
81 vcpu->run->dcr.dcrn = dcrn;
82 vcpu->run->dcr.data = 0;
83 vcpu->run->dcr.is_write = 0;
84 vcpu->arch.dcr_is_write = 0;
85 vcpu->arch.io_gpr = rt;
86 vcpu->arch.dcr_needed = 1;
87 kvmppc_account_exit(vcpu, DCR_EXITS);
88 return EMULATE_DO_DCR;
89 }
90
91 return EMULATE_DONE;
92}
93
36int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 94int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
37 unsigned int inst, int *advance) 95 unsigned int inst, int *advance)
38{ 96{
@@ -50,55 +108,21 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
50 switch (get_xop(inst)) { 108 switch (get_xop(inst)) {
51 109
52 case XOP_MFDCR: 110 case XOP_MFDCR:
53 /* The guest may access CPR0 registers to determine the timebase 111 emulated = emulate_mfdcr(vcpu, rt, dcrn);
54 * frequency, and it must know the real host frequency because it 112 break;
55 * can directly access the timebase registers.
56 *
57 * It would be possible to emulate those accesses in userspace,
58 * but userspace can really only figure out the end frequency.
59 * We could decompose that into the factors that compute it, but
60 * that's tricky math, and it's easier to just report the real
61 * CPR0 values.
62 */
63 switch (dcrn) {
64 case DCRN_CPR0_CONFIG_ADDR:
65 kvmppc_set_gpr(vcpu, rt, vcpu->arch.cpr0_cfgaddr);
66 break;
67 case DCRN_CPR0_CONFIG_DATA:
68 local_irq_disable();
69 mtdcr(DCRN_CPR0_CONFIG_ADDR,
70 vcpu->arch.cpr0_cfgaddr);
71 kvmppc_set_gpr(vcpu, rt,
72 mfdcr(DCRN_CPR0_CONFIG_DATA));
73 local_irq_enable();
74 break;
75 default:
76 run->dcr.dcrn = dcrn;
77 run->dcr.data = 0;
78 run->dcr.is_write = 0;
79 vcpu->arch.io_gpr = rt;
80 vcpu->arch.dcr_needed = 1;
81 kvmppc_account_exit(vcpu, DCR_EXITS);
82 emulated = EMULATE_DO_DCR;
83 }
84 113
114 case XOP_MFDCRX:
115 emulated = emulate_mfdcr(vcpu, rt,
116 kvmppc_get_gpr(vcpu, ra));
85 break; 117 break;
86 118
87 case XOP_MTDCR: 119 case XOP_MTDCR:
88 /* emulate some access in kernel */ 120 emulated = emulate_mtdcr(vcpu, rs, dcrn);
89 switch (dcrn) { 121 break;
90 case DCRN_CPR0_CONFIG_ADDR:
91 vcpu->arch.cpr0_cfgaddr = kvmppc_get_gpr(vcpu, rs);
92 break;
93 default:
94 run->dcr.dcrn = dcrn;
95 run->dcr.data = kvmppc_get_gpr(vcpu, rs);
96 run->dcr.is_write = 1;
97 vcpu->arch.dcr_needed = 1;
98 kvmppc_account_exit(vcpu, DCR_EXITS);
99 emulated = EMULATE_DO_DCR;
100 }
101 122
123 case XOP_MTDCRX:
124 emulated = emulate_mtdcr(vcpu, rs,
125 kvmppc_get_gpr(vcpu, ra));
102 break; 126 break;
103 127
104 case XOP_TLBWE: 128 case XOP_TLBWE:
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index f4dacb9c57fa..4730c953f435 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -20,6 +20,7 @@ config KVM
20 bool 20 bool
21 select PREEMPT_NOTIFIERS 21 select PREEMPT_NOTIFIERS
22 select ANON_INODES 22 select ANON_INODES
23 select HAVE_KVM_EVENTFD
23 24
24config KVM_BOOK3S_HANDLER 25config KVM_BOOK3S_HANDLER
25 bool 26 bool
@@ -36,6 +37,7 @@ config KVM_BOOK3S_64_HANDLER
36config KVM_BOOK3S_PR 37config KVM_BOOK3S_PR
37 bool 38 bool
38 select KVM_MMIO 39 select KVM_MMIO
40 select MMU_NOTIFIER
39 41
40config KVM_BOOK3S_32 42config KVM_BOOK3S_32
41 tristate "KVM support for PowerPC book3s_32 processors" 43 tristate "KVM support for PowerPC book3s_32 processors"
@@ -123,6 +125,7 @@ config KVM_E500V2
123 depends on EXPERIMENTAL && E500 && !PPC_E500MC 125 depends on EXPERIMENTAL && E500 && !PPC_E500MC
124 select KVM 126 select KVM
125 select KVM_MMIO 127 select KVM_MMIO
128 select MMU_NOTIFIER
126 ---help--- 129 ---help---
127 Support running unmodified E500 guest kernels in virtual machines on 130 Support running unmodified E500 guest kernels in virtual machines on
128 E500v2 host processors. 131 E500v2 host processors.
@@ -138,6 +141,7 @@ config KVM_E500MC
138 select KVM 141 select KVM
139 select KVM_MMIO 142 select KVM_MMIO
140 select KVM_BOOKE_HV 143 select KVM_BOOKE_HV
144 select MMU_NOTIFIER
141 ---help--- 145 ---help---
142 Support running unmodified E500MC/E5500 (32-bit) guest kernels in 146 Support running unmodified E500MC/E5500 (32-bit) guest kernels in
143 virtual machines on E500MC/E5500 host processors. 147 virtual machines on E500MC/E5500 host processors.
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index c2a08636e6d4..1e473d46322c 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -6,7 +6,8 @@ subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror
6 6
7ccflags-y := -Ivirt/kvm -Iarch/powerpc/kvm 7ccflags-y := -Ivirt/kvm -Iarch/powerpc/kvm
8 8
9common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o) 9common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o \
10 eventfd.o)
10 11
11CFLAGS_44x_tlb.o := -I. 12CFLAGS_44x_tlb.o := -I.
12CFLAGS_e500_tlb.o := -I. 13CFLAGS_e500_tlb.o := -I.
@@ -72,10 +73,12 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \
72 book3s_hv_rmhandlers.o \ 73 book3s_hv_rmhandlers.o \
73 book3s_hv_rm_mmu.o \ 74 book3s_hv_rm_mmu.o \
74 book3s_64_vio_hv.o \ 75 book3s_64_vio_hv.o \
76 book3s_hv_ras.o \
75 book3s_hv_builtin.o 77 book3s_hv_builtin.o
76 78
77kvm-book3s_64-module-objs := \ 79kvm-book3s_64-module-objs := \
78 ../../../virt/kvm/kvm_main.o \ 80 ../../../virt/kvm/kvm_main.o \
81 ../../../virt/kvm/eventfd.o \
79 powerpc.o \ 82 powerpc.o \
80 emulate.o \ 83 emulate.o \
81 book3s.o \ 84 book3s.o \
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 3f2a8360c857..a4b645285240 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -411,6 +411,15 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
411 return 0; 411 return 0;
412} 412}
413 413
414int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu)
415{
416 return 0;
417}
418
419void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu)
420{
421}
422
414int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 423int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
415{ 424{
416 int i; 425 int i;
@@ -476,6 +485,122 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
476 return -ENOTSUPP; 485 return -ENOTSUPP;
477} 486}
478 487
488int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
489{
490 int r;
491 union kvmppc_one_reg val;
492 int size;
493 long int i;
494
495 size = one_reg_size(reg->id);
496 if (size > sizeof(val))
497 return -EINVAL;
498
499 r = kvmppc_get_one_reg(vcpu, reg->id, &val);
500
501 if (r == -EINVAL) {
502 r = 0;
503 switch (reg->id) {
504 case KVM_REG_PPC_DAR:
505 val = get_reg_val(reg->id, vcpu->arch.shared->dar);
506 break;
507 case KVM_REG_PPC_DSISR:
508 val = get_reg_val(reg->id, vcpu->arch.shared->dsisr);
509 break;
510 case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
511 i = reg->id - KVM_REG_PPC_FPR0;
512 val = get_reg_val(reg->id, vcpu->arch.fpr[i]);
513 break;
514 case KVM_REG_PPC_FPSCR:
515 val = get_reg_val(reg->id, vcpu->arch.fpscr);
516 break;
517#ifdef CONFIG_ALTIVEC
518 case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
519 if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
520 r = -ENXIO;
521 break;
522 }
523 val.vval = vcpu->arch.vr[reg->id - KVM_REG_PPC_VR0];
524 break;
525 case KVM_REG_PPC_VSCR:
526 if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
527 r = -ENXIO;
528 break;
529 }
530 val = get_reg_val(reg->id, vcpu->arch.vscr.u[3]);
531 break;
532#endif /* CONFIG_ALTIVEC */
533 default:
534 r = -EINVAL;
535 break;
536 }
537 }
538 if (r)
539 return r;
540
541 if (copy_to_user((char __user *)(unsigned long)reg->addr, &val, size))
542 r = -EFAULT;
543
544 return r;
545}
546
547int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
548{
549 int r;
550 union kvmppc_one_reg val;
551 int size;
552 long int i;
553
554 size = one_reg_size(reg->id);
555 if (size > sizeof(val))
556 return -EINVAL;
557
558 if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size))
559 return -EFAULT;
560
561 r = kvmppc_set_one_reg(vcpu, reg->id, &val);
562
563 if (r == -EINVAL) {
564 r = 0;
565 switch (reg->id) {
566 case KVM_REG_PPC_DAR:
567 vcpu->arch.shared->dar = set_reg_val(reg->id, val);
568 break;
569 case KVM_REG_PPC_DSISR:
570 vcpu->arch.shared->dsisr = set_reg_val(reg->id, val);
571 break;
572 case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
573 i = reg->id - KVM_REG_PPC_FPR0;
574 vcpu->arch.fpr[i] = set_reg_val(reg->id, val);
575 break;
576 case KVM_REG_PPC_FPSCR:
577 vcpu->arch.fpscr = set_reg_val(reg->id, val);
578 break;
579#ifdef CONFIG_ALTIVEC
580 case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
581 if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
582 r = -ENXIO;
583 break;
584 }
585 vcpu->arch.vr[reg->id - KVM_REG_PPC_VR0] = val.vval;
586 break;
587 case KVM_REG_PPC_VSCR:
588 if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
589 r = -ENXIO;
590 break;
591 }
592 vcpu->arch.vscr.u[3] = set_reg_val(reg->id, val);
593 break;
594#endif /* CONFIG_ALTIVEC */
595 default:
596 r = -EINVAL;
597 break;
598 }
599 }
600
601 return r;
602}
603
479int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, 604int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
480 struct kvm_translation *tr) 605 struct kvm_translation *tr)
481{ 606{
diff --git a/arch/powerpc/kvm/book3s_32_mmu_host.c b/arch/powerpc/kvm/book3s_32_mmu_host.c
index b0f625a33345..00e619bf608e 100644
--- a/arch/powerpc/kvm/book3s_32_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_32_mmu_host.c
@@ -155,7 +155,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)
155 155
156 /* Get host physical address for gpa */ 156 /* Get host physical address for gpa */
157 hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT); 157 hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT);
158 if (is_error_pfn(hpaddr)) { 158 if (is_error_noslot_pfn(hpaddr)) {
159 printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n", 159 printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n",
160 orig_pte->eaddr); 160 orig_pte->eaddr);
161 r = -EINVAL; 161 r = -EINVAL;
@@ -254,6 +254,7 @@ next_pteg:
254 254
255 kvmppc_mmu_hpte_cache_map(vcpu, pte); 255 kvmppc_mmu_hpte_cache_map(vcpu, pte);
256 256
257 kvm_release_pfn_clean(hpaddr >> PAGE_SHIFT);
257out: 258out:
258 return r; 259 return r;
259} 260}
diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c b/arch/powerpc/kvm/book3s_64_mmu_host.c
index 4d72f9ebc554..ead58e317294 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_host.c
@@ -93,7 +93,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)
93 93
94 /* Get host physical address for gpa */ 94 /* Get host physical address for gpa */
95 hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT); 95 hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT);
96 if (is_error_pfn(hpaddr)) { 96 if (is_error_noslot_pfn(hpaddr)) {
97 printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n", orig_pte->eaddr); 97 printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n", orig_pte->eaddr);
98 r = -EINVAL; 98 r = -EINVAL;
99 goto out; 99 goto out;
@@ -171,6 +171,7 @@ map_again:
171 171
172 kvmppc_mmu_hpte_cache_map(vcpu, pte); 172 kvmppc_mmu_hpte_cache_map(vcpu, pte);
173 } 173 }
174 kvm_release_pfn_clean(hpaddr >> PAGE_SHIFT);
174 175
175out: 176out:
176 return r; 177 return r;
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index d95d11322a15..8cc18abd6dde 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -24,6 +24,9 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/hugetlb.h> 25#include <linux/hugetlb.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/srcu.h>
28#include <linux/anon_inodes.h>
29#include <linux/file.h>
27 30
28#include <asm/tlbflush.h> 31#include <asm/tlbflush.h>
29#include <asm/kvm_ppc.h> 32#include <asm/kvm_ppc.h>
@@ -40,6 +43,11 @@
40/* Power architecture requires HPT is at least 256kB */ 43/* Power architecture requires HPT is at least 256kB */
41#define PPC_MIN_HPT_ORDER 18 44#define PPC_MIN_HPT_ORDER 18
42 45
46static long kvmppc_virtmode_do_h_enter(struct kvm *kvm, unsigned long flags,
47 long pte_index, unsigned long pteh,
48 unsigned long ptel, unsigned long *pte_idx_ret);
49static void kvmppc_rmap_reset(struct kvm *kvm);
50
43long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp) 51long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
44{ 52{
45 unsigned long hpt; 53 unsigned long hpt;
@@ -137,10 +145,11 @@ long kvmppc_alloc_reset_hpt(struct kvm *kvm, u32 *htab_orderp)
137 /* Set the entire HPT to 0, i.e. invalid HPTEs */ 145 /* Set the entire HPT to 0, i.e. invalid HPTEs */
138 memset((void *)kvm->arch.hpt_virt, 0, 1ul << order); 146 memset((void *)kvm->arch.hpt_virt, 0, 1ul << order);
139 /* 147 /*
140 * Set the whole last_vcpu array to an invalid vcpu number. 148 * Reset all the reverse-mapping chains for all memslots
141 * This ensures that each vcpu will flush its TLB on next entry.
142 */ 149 */
143 memset(kvm->arch.last_vcpu, 0xff, sizeof(kvm->arch.last_vcpu)); 150 kvmppc_rmap_reset(kvm);
151 /* Ensure that each vcpu will flush its TLB on next entry. */
152 cpumask_setall(&kvm->arch.need_tlb_flush);
144 *htab_orderp = order; 153 *htab_orderp = order;
145 err = 0; 154 err = 0;
146 } else { 155 } else {
@@ -184,6 +193,7 @@ void kvmppc_map_vrma(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
184 unsigned long addr, hash; 193 unsigned long addr, hash;
185 unsigned long psize; 194 unsigned long psize;
186 unsigned long hp0, hp1; 195 unsigned long hp0, hp1;
196 unsigned long idx_ret;
187 long ret; 197 long ret;
188 struct kvm *kvm = vcpu->kvm; 198 struct kvm *kvm = vcpu->kvm;
189 199
@@ -215,7 +225,8 @@ void kvmppc_map_vrma(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
215 hash = (hash << 3) + 7; 225 hash = (hash << 3) + 7;
216 hp_v = hp0 | ((addr >> 16) & ~0x7fUL); 226 hp_v = hp0 | ((addr >> 16) & ~0x7fUL);
217 hp_r = hp1 | addr; 227 hp_r = hp1 | addr;
218 ret = kvmppc_virtmode_h_enter(vcpu, H_EXACT, hash, hp_v, hp_r); 228 ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, hash, hp_v, hp_r,
229 &idx_ret);
219 if (ret != H_SUCCESS) { 230 if (ret != H_SUCCESS) {
220 pr_err("KVM: map_vrma at %lx failed, ret=%ld\n", 231 pr_err("KVM: map_vrma at %lx failed, ret=%ld\n",
221 addr, ret); 232 addr, ret);
@@ -260,7 +271,7 @@ static void kvmppc_mmu_book3s_64_hv_reset_msr(struct kvm_vcpu *vcpu)
260 271
261/* 272/*
262 * This is called to get a reference to a guest page if there isn't 273 * This is called to get a reference to a guest page if there isn't
263 * one already in the kvm->arch.slot_phys[][] arrays. 274 * one already in the memslot->arch.slot_phys[] array.
264 */ 275 */
265static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn, 276static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn,
266 struct kvm_memory_slot *memslot, 277 struct kvm_memory_slot *memslot,
@@ -275,7 +286,7 @@ static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn,
275 struct vm_area_struct *vma; 286 struct vm_area_struct *vma;
276 unsigned long pfn, i, npages; 287 unsigned long pfn, i, npages;
277 288
278 physp = kvm->arch.slot_phys[memslot->id]; 289 physp = memslot->arch.slot_phys;
279 if (!physp) 290 if (!physp)
280 return -EINVAL; 291 return -EINVAL;
281 if (physp[gfn - memslot->base_gfn]) 292 if (physp[gfn - memslot->base_gfn])
@@ -353,15 +364,10 @@ static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn,
353 return err; 364 return err;
354} 365}
355 366
356/* 367long kvmppc_virtmode_do_h_enter(struct kvm *kvm, unsigned long flags,
357 * We come here on a H_ENTER call from the guest when we are not 368 long pte_index, unsigned long pteh,
358 * using mmu notifiers and we don't have the requested page pinned 369 unsigned long ptel, unsigned long *pte_idx_ret)
359 * already.
360 */
361long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
362 long pte_index, unsigned long pteh, unsigned long ptel)
363{ 370{
364 struct kvm *kvm = vcpu->kvm;
365 unsigned long psize, gpa, gfn; 371 unsigned long psize, gpa, gfn;
366 struct kvm_memory_slot *memslot; 372 struct kvm_memory_slot *memslot;
367 long ret; 373 long ret;
@@ -389,8 +395,8 @@ long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
389 do_insert: 395 do_insert:
390 /* Protect linux PTE lookup from page table destruction */ 396 /* Protect linux PTE lookup from page table destruction */
391 rcu_read_lock_sched(); /* this disables preemption too */ 397 rcu_read_lock_sched(); /* this disables preemption too */
392 vcpu->arch.pgdir = current->mm->pgd; 398 ret = kvmppc_do_h_enter(kvm, flags, pte_index, pteh, ptel,
393 ret = kvmppc_h_enter(vcpu, flags, pte_index, pteh, ptel); 399 current->mm->pgd, false, pte_idx_ret);
394 rcu_read_unlock_sched(); 400 rcu_read_unlock_sched();
395 if (ret == H_TOO_HARD) { 401 if (ret == H_TOO_HARD) {
396 /* this can't happen */ 402 /* this can't happen */
@@ -401,6 +407,19 @@ long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
401 407
402} 408}
403 409
410/*
411 * We come here on a H_ENTER call from the guest when we are not
412 * using mmu notifiers and we don't have the requested page pinned
413 * already.
414 */
415long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
416 long pte_index, unsigned long pteh,
417 unsigned long ptel)
418{
419 return kvmppc_virtmode_do_h_enter(vcpu->kvm, flags, pte_index,
420 pteh, ptel, &vcpu->arch.gpr[4]);
421}
422
404static struct kvmppc_slb *kvmppc_mmu_book3s_hv_find_slbe(struct kvm_vcpu *vcpu, 423static struct kvmppc_slb *kvmppc_mmu_book3s_hv_find_slbe(struct kvm_vcpu *vcpu,
405 gva_t eaddr) 424 gva_t eaddr)
406{ 425{
@@ -570,7 +589,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
570 struct kvm *kvm = vcpu->kvm; 589 struct kvm *kvm = vcpu->kvm;
571 unsigned long *hptep, hpte[3], r; 590 unsigned long *hptep, hpte[3], r;
572 unsigned long mmu_seq, psize, pte_size; 591 unsigned long mmu_seq, psize, pte_size;
573 unsigned long gfn, hva, pfn; 592 unsigned long gpa, gfn, hva, pfn;
574 struct kvm_memory_slot *memslot; 593 struct kvm_memory_slot *memslot;
575 unsigned long *rmap; 594 unsigned long *rmap;
576 struct revmap_entry *rev; 595 struct revmap_entry *rev;
@@ -608,15 +627,14 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
608 627
609 /* Translate the logical address and get the page */ 628 /* Translate the logical address and get the page */
610 psize = hpte_page_size(hpte[0], r); 629 psize = hpte_page_size(hpte[0], r);
611 gfn = hpte_rpn(r, psize); 630 gpa = (r & HPTE_R_RPN & ~(psize - 1)) | (ea & (psize - 1));
631 gfn = gpa >> PAGE_SHIFT;
612 memslot = gfn_to_memslot(kvm, gfn); 632 memslot = gfn_to_memslot(kvm, gfn);
613 633
614 /* No memslot means it's an emulated MMIO region */ 634 /* No memslot means it's an emulated MMIO region */
615 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) { 635 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
616 unsigned long gpa = (gfn << PAGE_SHIFT) | (ea & (psize - 1));
617 return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea, 636 return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea,
618 dsisr & DSISR_ISSTORE); 637 dsisr & DSISR_ISSTORE);
619 }
620 638
621 if (!kvm->arch.using_mmu_notifiers) 639 if (!kvm->arch.using_mmu_notifiers)
622 return -EFAULT; /* should never get here */ 640 return -EFAULT; /* should never get here */
@@ -710,7 +728,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
710 728
711 /* Check if we might have been invalidated; let the guest retry if so */ 729 /* Check if we might have been invalidated; let the guest retry if so */
712 ret = RESUME_GUEST; 730 ret = RESUME_GUEST;
713 if (mmu_notifier_retry(vcpu, mmu_seq)) { 731 if (mmu_notifier_retry(vcpu->kvm, mmu_seq)) {
714 unlock_rmap(rmap); 732 unlock_rmap(rmap);
715 goto out_unlock; 733 goto out_unlock;
716 } 734 }
@@ -756,6 +774,25 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
756 goto out_put; 774 goto out_put;
757} 775}
758 776
777static void kvmppc_rmap_reset(struct kvm *kvm)
778{
779 struct kvm_memslots *slots;
780 struct kvm_memory_slot *memslot;
781 int srcu_idx;
782
783 srcu_idx = srcu_read_lock(&kvm->srcu);
784 slots = kvm->memslots;
785 kvm_for_each_memslot(memslot, slots) {
786 /*
787 * This assumes it is acceptable to lose reference and
788 * change bits across a reset.
789 */
790 memset(memslot->arch.rmap, 0,
791 memslot->npages * sizeof(*memslot->arch.rmap));
792 }
793 srcu_read_unlock(&kvm->srcu, srcu_idx);
794}
795
759static int kvm_handle_hva_range(struct kvm *kvm, 796static int kvm_handle_hva_range(struct kvm *kvm,
760 unsigned long start, 797 unsigned long start,
761 unsigned long end, 798 unsigned long end,
@@ -850,7 +887,8 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,
850 psize = hpte_page_size(hptep[0], ptel); 887 psize = hpte_page_size(hptep[0], ptel);
851 if ((hptep[0] & HPTE_V_VALID) && 888 if ((hptep[0] & HPTE_V_VALID) &&
852 hpte_rpn(ptel, psize) == gfn) { 889 hpte_rpn(ptel, psize) == gfn) {
853 hptep[0] |= HPTE_V_ABSENT; 890 if (kvm->arch.using_mmu_notifiers)
891 hptep[0] |= HPTE_V_ABSENT;
854 kvmppc_invalidate_hpte(kvm, hptep, i); 892 kvmppc_invalidate_hpte(kvm, hptep, i);
855 /* Harvest R and C */ 893 /* Harvest R and C */
856 rcbits = hptep[1] & (HPTE_R_R | HPTE_R_C); 894 rcbits = hptep[1] & (HPTE_R_R | HPTE_R_C);
@@ -877,6 +915,28 @@ int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
877 return 0; 915 return 0;
878} 916}
879 917
918void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
919{
920 unsigned long *rmapp;
921 unsigned long gfn;
922 unsigned long n;
923
924 rmapp = memslot->arch.rmap;
925 gfn = memslot->base_gfn;
926 for (n = memslot->npages; n; --n) {
927 /*
928 * Testing the present bit without locking is OK because
929 * the memslot has been marked invalid already, and hence
930 * no new HPTEs referencing this page can be created,
931 * thus the present bit can't go from 0 to 1.
932 */
933 if (*rmapp & KVMPPC_RMAP_PRESENT)
934 kvm_unmap_rmapp(kvm, rmapp, gfn);
935 ++rmapp;
936 ++gfn;
937 }
938}
939
880static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp, 940static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp,
881 unsigned long gfn) 941 unsigned long gfn)
882{ 942{
@@ -1030,16 +1090,16 @@ static int kvm_test_clear_dirty(struct kvm *kvm, unsigned long *rmapp)
1030 return ret; 1090 return ret;
1031} 1091}
1032 1092
1033long kvmppc_hv_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot) 1093long kvmppc_hv_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot,
1094 unsigned long *map)
1034{ 1095{
1035 unsigned long i; 1096 unsigned long i;
1036 unsigned long *rmapp, *map; 1097 unsigned long *rmapp;
1037 1098
1038 preempt_disable(); 1099 preempt_disable();
1039 rmapp = memslot->arch.rmap; 1100 rmapp = memslot->arch.rmap;
1040 map = memslot->dirty_bitmap;
1041 for (i = 0; i < memslot->npages; ++i) { 1101 for (i = 0; i < memslot->npages; ++i) {
1042 if (kvm_test_clear_dirty(kvm, rmapp)) 1102 if (kvm_test_clear_dirty(kvm, rmapp) && map)
1043 __set_bit_le(i, map); 1103 __set_bit_le(i, map);
1044 ++rmapp; 1104 ++rmapp;
1045 } 1105 }
@@ -1057,20 +1117,22 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa,
1057 unsigned long hva, psize, offset; 1117 unsigned long hva, psize, offset;
1058 unsigned long pa; 1118 unsigned long pa;
1059 unsigned long *physp; 1119 unsigned long *physp;
1120 int srcu_idx;
1060 1121
1122 srcu_idx = srcu_read_lock(&kvm->srcu);
1061 memslot = gfn_to_memslot(kvm, gfn); 1123 memslot = gfn_to_memslot(kvm, gfn);
1062 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) 1124 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
1063 return NULL; 1125 goto err;
1064 if (!kvm->arch.using_mmu_notifiers) { 1126 if (!kvm->arch.using_mmu_notifiers) {
1065 physp = kvm->arch.slot_phys[memslot->id]; 1127 physp = memslot->arch.slot_phys;
1066 if (!physp) 1128 if (!physp)
1067 return NULL; 1129 goto err;
1068 physp += gfn - memslot->base_gfn; 1130 physp += gfn - memslot->base_gfn;
1069 pa = *physp; 1131 pa = *physp;
1070 if (!pa) { 1132 if (!pa) {
1071 if (kvmppc_get_guest_page(kvm, gfn, memslot, 1133 if (kvmppc_get_guest_page(kvm, gfn, memslot,
1072 PAGE_SIZE) < 0) 1134 PAGE_SIZE) < 0)
1073 return NULL; 1135 goto err;
1074 pa = *physp; 1136 pa = *physp;
1075 } 1137 }
1076 page = pfn_to_page(pa >> PAGE_SHIFT); 1138 page = pfn_to_page(pa >> PAGE_SHIFT);
@@ -1079,9 +1141,11 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa,
1079 hva = gfn_to_hva_memslot(memslot, gfn); 1141 hva = gfn_to_hva_memslot(memslot, gfn);
1080 npages = get_user_pages_fast(hva, 1, 1, pages); 1142 npages = get_user_pages_fast(hva, 1, 1, pages);
1081 if (npages < 1) 1143 if (npages < 1)
1082 return NULL; 1144 goto err;
1083 page = pages[0]; 1145 page = pages[0];
1084 } 1146 }
1147 srcu_read_unlock(&kvm->srcu, srcu_idx);
1148
1085 psize = PAGE_SIZE; 1149 psize = PAGE_SIZE;
1086 if (PageHuge(page)) { 1150 if (PageHuge(page)) {
1087 page = compound_head(page); 1151 page = compound_head(page);
@@ -1091,6 +1155,10 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long gpa,
1091 if (nb_ret) 1155 if (nb_ret)
1092 *nb_ret = psize - offset; 1156 *nb_ret = psize - offset;
1093 return page_address(page) + offset; 1157 return page_address(page) + offset;
1158
1159 err:
1160 srcu_read_unlock(&kvm->srcu, srcu_idx);
1161 return NULL;
1094} 1162}
1095 1163
1096void kvmppc_unpin_guest_page(struct kvm *kvm, void *va) 1164void kvmppc_unpin_guest_page(struct kvm *kvm, void *va)
@@ -1100,6 +1168,348 @@ void kvmppc_unpin_guest_page(struct kvm *kvm, void *va)
1100 put_page(page); 1168 put_page(page);
1101} 1169}
1102 1170
1171/*
1172 * Functions for reading and writing the hash table via reads and
1173 * writes on a file descriptor.
1174 *
1175 * Reads return the guest view of the hash table, which has to be
1176 * pieced together from the real hash table and the guest_rpte
1177 * values in the revmap array.
1178 *
1179 * On writes, each HPTE written is considered in turn, and if it
1180 * is valid, it is written to the HPT as if an H_ENTER with the
1181 * exact flag set was done. When the invalid count is non-zero
1182 * in the header written to the stream, the kernel will make
1183 * sure that that many HPTEs are invalid, and invalidate them
1184 * if not.
1185 */
1186
1187struct kvm_htab_ctx {
1188 unsigned long index;
1189 unsigned long flags;
1190 struct kvm *kvm;
1191 int first_pass;
1192};
1193
1194#define HPTE_SIZE (2 * sizeof(unsigned long))
1195
1196static long record_hpte(unsigned long flags, unsigned long *hptp,
1197 unsigned long *hpte, struct revmap_entry *revp,
1198 int want_valid, int first_pass)
1199{
1200 unsigned long v, r;
1201 int ok = 1;
1202 int valid, dirty;
1203
1204 /* Unmodified entries are uninteresting except on the first pass */
1205 dirty = !!(revp->guest_rpte & HPTE_GR_MODIFIED);
1206 if (!first_pass && !dirty)
1207 return 0;
1208
1209 valid = 0;
1210 if (hptp[0] & (HPTE_V_VALID | HPTE_V_ABSENT)) {
1211 valid = 1;
1212 if ((flags & KVM_GET_HTAB_BOLTED_ONLY) &&
1213 !(hptp[0] & HPTE_V_BOLTED))
1214 valid = 0;
1215 }
1216 if (valid != want_valid)
1217 return 0;
1218
1219 v = r = 0;
1220 if (valid || dirty) {
1221 /* lock the HPTE so it's stable and read it */
1222 preempt_disable();
1223 while (!try_lock_hpte(hptp, HPTE_V_HVLOCK))
1224 cpu_relax();
1225 v = hptp[0];
1226 if (v & HPTE_V_ABSENT) {
1227 v &= ~HPTE_V_ABSENT;
1228 v |= HPTE_V_VALID;
1229 }
1230 /* re-evaluate valid and dirty from synchronized HPTE value */
1231 valid = !!(v & HPTE_V_VALID);
1232 if ((flags & KVM_GET_HTAB_BOLTED_ONLY) && !(v & HPTE_V_BOLTED))
1233 valid = 0;
1234 r = revp->guest_rpte | (hptp[1] & (HPTE_R_R | HPTE_R_C));
1235 dirty = !!(revp->guest_rpte & HPTE_GR_MODIFIED);
1236 /* only clear modified if this is the right sort of entry */
1237 if (valid == want_valid && dirty) {
1238 r &= ~HPTE_GR_MODIFIED;
1239 revp->guest_rpte = r;
1240 }
1241 asm volatile(PPC_RELEASE_BARRIER "" : : : "memory");
1242 hptp[0] &= ~HPTE_V_HVLOCK;
1243 preempt_enable();
1244 if (!(valid == want_valid && (first_pass || dirty)))
1245 ok = 0;
1246 }
1247 hpte[0] = v;
1248 hpte[1] = r;
1249 return ok;
1250}
1251
1252static ssize_t kvm_htab_read(struct file *file, char __user *buf,
1253 size_t count, loff_t *ppos)
1254{
1255 struct kvm_htab_ctx *ctx = file->private_data;
1256 struct kvm *kvm = ctx->kvm;
1257 struct kvm_get_htab_header hdr;
1258 unsigned long *hptp;
1259 struct revmap_entry *revp;
1260 unsigned long i, nb, nw;
1261 unsigned long __user *lbuf;
1262 struct kvm_get_htab_header __user *hptr;
1263 unsigned long flags;
1264 int first_pass;
1265 unsigned long hpte[2];
1266
1267 if (!access_ok(VERIFY_WRITE, buf, count))
1268 return -EFAULT;
1269
1270 first_pass = ctx->first_pass;
1271 flags = ctx->flags;
1272
1273 i = ctx->index;
1274 hptp = (unsigned long *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
1275 revp = kvm->arch.revmap + i;
1276 lbuf = (unsigned long __user *)buf;
1277
1278 nb = 0;
1279 while (nb + sizeof(hdr) + HPTE_SIZE < count) {
1280 /* Initialize header */
1281 hptr = (struct kvm_get_htab_header __user *)buf;
1282 hdr.n_valid = 0;
1283 hdr.n_invalid = 0;
1284 nw = nb;
1285 nb += sizeof(hdr);
1286 lbuf = (unsigned long __user *)(buf + sizeof(hdr));
1287
1288 /* Skip uninteresting entries, i.e. clean on not-first pass */
1289 if (!first_pass) {
1290 while (i < kvm->arch.hpt_npte &&
1291 !(revp->guest_rpte & HPTE_GR_MODIFIED)) {
1292 ++i;
1293 hptp += 2;
1294 ++revp;
1295 }
1296 }
1297 hdr.index = i;
1298
1299 /* Grab a series of valid entries */
1300 while (i < kvm->arch.hpt_npte &&
1301 hdr.n_valid < 0xffff &&
1302 nb + HPTE_SIZE < count &&
1303 record_hpte(flags, hptp, hpte, revp, 1, first_pass)) {
1304 /* valid entry, write it out */
1305 ++hdr.n_valid;
1306 if (__put_user(hpte[0], lbuf) ||
1307 __put_user(hpte[1], lbuf + 1))
1308 return -EFAULT;
1309 nb += HPTE_SIZE;
1310 lbuf += 2;
1311 ++i;
1312 hptp += 2;
1313 ++revp;
1314 }
1315 /* Now skip invalid entries while we can */
1316 while (i < kvm->arch.hpt_npte &&
1317 hdr.n_invalid < 0xffff &&
1318 record_hpte(flags, hptp, hpte, revp, 0, first_pass)) {
1319 /* found an invalid entry */
1320 ++hdr.n_invalid;
1321 ++i;
1322 hptp += 2;
1323 ++revp;
1324 }
1325
1326 if (hdr.n_valid || hdr.n_invalid) {
1327 /* write back the header */
1328 if (__copy_to_user(hptr, &hdr, sizeof(hdr)))
1329 return -EFAULT;
1330 nw = nb;
1331 buf = (char __user *)lbuf;
1332 } else {
1333 nb = nw;
1334 }
1335
1336 /* Check if we've wrapped around the hash table */
1337 if (i >= kvm->arch.hpt_npte) {
1338 i = 0;
1339 ctx->first_pass = 0;
1340 break;
1341 }
1342 }
1343
1344 ctx->index = i;
1345
1346 return nb;
1347}
1348
1349static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
1350 size_t count, loff_t *ppos)
1351{
1352 struct kvm_htab_ctx *ctx = file->private_data;
1353 struct kvm *kvm = ctx->kvm;
1354 struct kvm_get_htab_header hdr;
1355 unsigned long i, j;
1356 unsigned long v, r;
1357 unsigned long __user *lbuf;
1358 unsigned long *hptp;
1359 unsigned long tmp[2];
1360 ssize_t nb;
1361 long int err, ret;
1362 int rma_setup;
1363
1364 if (!access_ok(VERIFY_READ, buf, count))
1365 return -EFAULT;
1366
1367 /* lock out vcpus from running while we're doing this */
1368 mutex_lock(&kvm->lock);
1369 rma_setup = kvm->arch.rma_setup_done;
1370 if (rma_setup) {
1371 kvm->arch.rma_setup_done = 0; /* temporarily */
1372 /* order rma_setup_done vs. vcpus_running */
1373 smp_mb();
1374 if (atomic_read(&kvm->arch.vcpus_running)) {
1375 kvm->arch.rma_setup_done = 1;
1376 mutex_unlock(&kvm->lock);
1377 return -EBUSY;
1378 }
1379 }
1380
1381 err = 0;
1382 for (nb = 0; nb + sizeof(hdr) <= count; ) {
1383 err = -EFAULT;
1384 if (__copy_from_user(&hdr, buf, sizeof(hdr)))
1385 break;
1386
1387 err = 0;
1388 if (nb + hdr.n_valid * HPTE_SIZE > count)
1389 break;
1390
1391 nb += sizeof(hdr);
1392 buf += sizeof(hdr);
1393
1394 err = -EINVAL;
1395 i = hdr.index;
1396 if (i >= kvm->arch.hpt_npte ||
1397 i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
1398 break;
1399
1400 hptp = (unsigned long *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
1401 lbuf = (unsigned long __user *)buf;
1402 for (j = 0; j < hdr.n_valid; ++j) {
1403 err = -EFAULT;
1404 if (__get_user(v, lbuf) || __get_user(r, lbuf + 1))
1405 goto out;
1406 err = -EINVAL;
1407 if (!(v & HPTE_V_VALID))
1408 goto out;
1409 lbuf += 2;
1410 nb += HPTE_SIZE;
1411
1412 if (hptp[0] & (HPTE_V_VALID | HPTE_V_ABSENT))
1413 kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
1414 err = -EIO;
1415 ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
1416 tmp);
1417 if (ret != H_SUCCESS) {
1418 pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
1419 "r=%lx\n", ret, i, v, r);
1420 goto out;
1421 }
1422 if (!rma_setup && is_vrma_hpte(v)) {
1423 unsigned long psize = hpte_page_size(v, r);
1424 unsigned long senc = slb_pgsize_encoding(psize);
1425 unsigned long lpcr;
1426
1427 kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
1428 (VRMA_VSID << SLB_VSID_SHIFT_1T);
1429 lpcr = kvm->arch.lpcr & ~LPCR_VRMASD;
1430 lpcr |= senc << (LPCR_VRMASD_SH - 4);
1431 kvm->arch.lpcr = lpcr;
1432 rma_setup = 1;
1433 }
1434 ++i;
1435 hptp += 2;
1436 }
1437
1438 for (j = 0; j < hdr.n_invalid; ++j) {
1439 if (hptp[0] & (HPTE_V_VALID | HPTE_V_ABSENT))
1440 kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
1441 ++i;
1442 hptp += 2;
1443 }
1444 err = 0;
1445 }
1446
1447 out:
1448 /* Order HPTE updates vs. rma_setup_done */
1449 smp_wmb();
1450 kvm->arch.rma_setup_done = rma_setup;
1451 mutex_unlock(&kvm->lock);
1452
1453 if (err)
1454 return err;
1455 return nb;
1456}
1457
1458static int kvm_htab_release(struct inode *inode, struct file *filp)
1459{
1460 struct kvm_htab_ctx *ctx = filp->private_data;
1461
1462 filp->private_data = NULL;
1463 if (!(ctx->flags & KVM_GET_HTAB_WRITE))
1464 atomic_dec(&ctx->kvm->arch.hpte_mod_interest);
1465 kvm_put_kvm(ctx->kvm);
1466 kfree(ctx);
1467 return 0;
1468}
1469
1470static struct file_operations kvm_htab_fops = {
1471 .read = kvm_htab_read,
1472 .write = kvm_htab_write,
1473 .llseek = default_llseek,
1474 .release = kvm_htab_release,
1475};
1476
1477int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *ghf)
1478{
1479 int ret;
1480 struct kvm_htab_ctx *ctx;
1481 int rwflag;
1482
1483 /* reject flags we don't recognize */
1484 if (ghf->flags & ~(KVM_GET_HTAB_BOLTED_ONLY | KVM_GET_HTAB_WRITE))
1485 return -EINVAL;
1486 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
1487 if (!ctx)
1488 return -ENOMEM;
1489 kvm_get_kvm(kvm);
1490 ctx->kvm = kvm;
1491 ctx->index = ghf->start_index;
1492 ctx->flags = ghf->flags;
1493 ctx->first_pass = 1;
1494
1495 rwflag = (ghf->flags & KVM_GET_HTAB_WRITE) ? O_WRONLY : O_RDONLY;
1496 ret = anon_inode_getfd("kvm-htab", &kvm_htab_fops, ctx, rwflag);
1497 if (ret < 0) {
1498 kvm_put_kvm(kvm);
1499 return ret;
1500 }
1501
1502 if (rwflag == O_RDONLY) {
1503 mutex_lock(&kvm->slots_lock);
1504 atomic_inc(&kvm->arch.hpte_mod_interest);
1505 /* make sure kvmppc_do_h_enter etc. see the increment */
1506 synchronize_srcu_expedited(&kvm->srcu);
1507 mutex_unlock(&kvm->slots_lock);
1508 }
1509
1510 return ret;
1511}
1512
1103void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu) 1513void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu)
1104{ 1514{
1105 struct kvmppc_mmu *mmu = &vcpu->arch.mmu; 1515 struct kvmppc_mmu *mmu = &vcpu->arch.mmu;
diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
index b9a989dc76cc..d31a716f7f2b 100644
--- a/arch/powerpc/kvm/book3s_emulate.c
+++ b/arch/powerpc/kvm/book3s_emulate.c
@@ -22,6 +22,7 @@
22#include <asm/kvm_book3s.h> 22#include <asm/kvm_book3s.h>
23#include <asm/reg.h> 23#include <asm/reg.h>
24#include <asm/switch_to.h> 24#include <asm/switch_to.h>
25#include <asm/time.h>
25 26
26#define OP_19_XOP_RFID 18 27#define OP_19_XOP_RFID 18
27#define OP_19_XOP_RFI 50 28#define OP_19_XOP_RFI 50
@@ -395,6 +396,12 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
395 (mfmsr() & MSR_HV)) 396 (mfmsr() & MSR_HV))
396 vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; 397 vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32;
397 break; 398 break;
399 case SPRN_PURR:
400 to_book3s(vcpu)->purr_offset = spr_val - get_tb();
401 break;
402 case SPRN_SPURR:
403 to_book3s(vcpu)->spurr_offset = spr_val - get_tb();
404 break;
398 case SPRN_GQR0: 405 case SPRN_GQR0:
399 case SPRN_GQR1: 406 case SPRN_GQR1:
400 case SPRN_GQR2: 407 case SPRN_GQR2:
@@ -412,6 +419,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
412 case SPRN_CTRLF: 419 case SPRN_CTRLF:
413 case SPRN_CTRLT: 420 case SPRN_CTRLT:
414 case SPRN_L2CR: 421 case SPRN_L2CR:
422 case SPRN_DSCR:
415 case SPRN_MMCR0_GEKKO: 423 case SPRN_MMCR0_GEKKO:
416 case SPRN_MMCR1_GEKKO: 424 case SPRN_MMCR1_GEKKO:
417 case SPRN_PMC1_GEKKO: 425 case SPRN_PMC1_GEKKO:
@@ -483,9 +491,15 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
483 *spr_val = to_book3s(vcpu)->hid[5]; 491 *spr_val = to_book3s(vcpu)->hid[5];
484 break; 492 break;
485 case SPRN_CFAR: 493 case SPRN_CFAR:
486 case SPRN_PURR: 494 case SPRN_DSCR:
487 *spr_val = 0; 495 *spr_val = 0;
488 break; 496 break;
497 case SPRN_PURR:
498 *spr_val = get_tb() + to_book3s(vcpu)->purr_offset;
499 break;
500 case SPRN_SPURR:
501 *spr_val = get_tb() + to_book3s(vcpu)->purr_offset;
502 break;
489 case SPRN_GQR0: 503 case SPRN_GQR0:
490 case SPRN_GQR1: 504 case SPRN_GQR1:
491 case SPRN_GQR2: 505 case SPRN_GQR2:
diff --git a/arch/powerpc/kvm/book3s_exports.c b/arch/powerpc/kvm/book3s_exports.c
index a150817d6d4c..7057a02f0906 100644
--- a/arch/powerpc/kvm/book3s_exports.c
+++ b/arch/powerpc/kvm/book3s_exports.c
@@ -28,8 +28,5 @@ EXPORT_SYMBOL_GPL(kvmppc_load_up_fpu);
28#ifdef CONFIG_ALTIVEC 28#ifdef CONFIG_ALTIVEC
29EXPORT_SYMBOL_GPL(kvmppc_load_up_altivec); 29EXPORT_SYMBOL_GPL(kvmppc_load_up_altivec);
30#endif 30#endif
31#ifdef CONFIG_VSX
32EXPORT_SYMBOL_GPL(kvmppc_load_up_vsx);
33#endif
34#endif 31#endif
35 32
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 721d4603a235..71d0c90b62bf 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -30,6 +30,7 @@
30#include <linux/cpumask.h> 30#include <linux/cpumask.h>
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/page-flags.h> 32#include <linux/page-flags.h>
33#include <linux/srcu.h>
33 34
34#include <asm/reg.h> 35#include <asm/reg.h>
35#include <asm/cputable.h> 36#include <asm/cputable.h>
@@ -46,6 +47,7 @@
46#include <asm/page.h> 47#include <asm/page.h>
47#include <asm/hvcall.h> 48#include <asm/hvcall.h>
48#include <asm/switch_to.h> 49#include <asm/switch_to.h>
50#include <asm/smp.h>
49#include <linux/gfp.h> 51#include <linux/gfp.h>
50#include <linux/vmalloc.h> 52#include <linux/vmalloc.h>
51#include <linux/highmem.h> 53#include <linux/highmem.h>
@@ -55,25 +57,77 @@
55/* #define EXIT_DEBUG_SIMPLE */ 57/* #define EXIT_DEBUG_SIMPLE */
56/* #define EXIT_DEBUG_INT */ 58/* #define EXIT_DEBUG_INT */
57 59
60/* Used to indicate that a guest page fault needs to be handled */
61#define RESUME_PAGE_FAULT (RESUME_GUEST | RESUME_FLAG_ARCH1)
62
63/* Used as a "null" value for timebase values */
64#define TB_NIL (~(u64)0)
65
58static void kvmppc_end_cede(struct kvm_vcpu *vcpu); 66static void kvmppc_end_cede(struct kvm_vcpu *vcpu);
59static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); 67static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu);
60 68
69/*
70 * We use the vcpu_load/put functions to measure stolen time.
71 * Stolen time is counted as time when either the vcpu is able to
72 * run as part of a virtual core, but the task running the vcore
73 * is preempted or sleeping, or when the vcpu needs something done
74 * in the kernel by the task running the vcpu, but that task is
75 * preempted or sleeping. Those two things have to be counted
76 * separately, since one of the vcpu tasks will take on the job
77 * of running the core, and the other vcpu tasks in the vcore will
78 * sleep waiting for it to do that, but that sleep shouldn't count
79 * as stolen time.
80 *
81 * Hence we accumulate stolen time when the vcpu can run as part of
82 * a vcore using vc->stolen_tb, and the stolen time when the vcpu
83 * needs its task to do other things in the kernel (for example,
84 * service a page fault) in busy_stolen. We don't accumulate
85 * stolen time for a vcore when it is inactive, or for a vcpu
86 * when it is in state RUNNING or NOTREADY. NOTREADY is a bit of
87 * a misnomer; it means that the vcpu task is not executing in
88 * the KVM_VCPU_RUN ioctl, i.e. it is in userspace or elsewhere in
89 * the kernel. We don't have any way of dividing up that time
90 * between time that the vcpu is genuinely stopped, time that
91 * the task is actively working on behalf of the vcpu, and time
92 * that the task is preempted, so we don't count any of it as
93 * stolen.
94 *
95 * Updates to busy_stolen are protected by arch.tbacct_lock;
96 * updates to vc->stolen_tb are protected by the arch.tbacct_lock
97 * of the vcpu that has taken responsibility for running the vcore
98 * (i.e. vc->runner). The stolen times are measured in units of
99 * timebase ticks. (Note that the != TB_NIL checks below are
100 * purely defensive; they should never fail.)
101 */
102
61void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 103void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
62{ 104{
63 struct kvmppc_vcore *vc = vcpu->arch.vcore; 105 struct kvmppc_vcore *vc = vcpu->arch.vcore;
64 106
65 local_paca->kvm_hstate.kvm_vcpu = vcpu; 107 spin_lock(&vcpu->arch.tbacct_lock);
66 local_paca->kvm_hstate.kvm_vcore = vc; 108 if (vc->runner == vcpu && vc->vcore_state != VCORE_INACTIVE &&
67 if (vc->runner == vcpu && vc->vcore_state != VCORE_INACTIVE) 109 vc->preempt_tb != TB_NIL) {
68 vc->stolen_tb += mftb() - vc->preempt_tb; 110 vc->stolen_tb += mftb() - vc->preempt_tb;
111 vc->preempt_tb = TB_NIL;
112 }
113 if (vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST &&
114 vcpu->arch.busy_preempt != TB_NIL) {
115 vcpu->arch.busy_stolen += mftb() - vcpu->arch.busy_preempt;
116 vcpu->arch.busy_preempt = TB_NIL;
117 }
118 spin_unlock(&vcpu->arch.tbacct_lock);
69} 119}
70 120
71void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu) 121void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
72{ 122{
73 struct kvmppc_vcore *vc = vcpu->arch.vcore; 123 struct kvmppc_vcore *vc = vcpu->arch.vcore;
74 124
125 spin_lock(&vcpu->arch.tbacct_lock);
75 if (vc->runner == vcpu && vc->vcore_state != VCORE_INACTIVE) 126 if (vc->runner == vcpu && vc->vcore_state != VCORE_INACTIVE)
76 vc->preempt_tb = mftb(); 127 vc->preempt_tb = mftb();
128 if (vcpu->arch.state == KVMPPC_VCPU_BUSY_IN_HOST)
129 vcpu->arch.busy_preempt = mftb();
130 spin_unlock(&vcpu->arch.tbacct_lock);
77} 131}
78 132
79void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) 133void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr)
@@ -142,6 +196,22 @@ static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa)
142 vpa->yield_count = 1; 196 vpa->yield_count = 1;
143} 197}
144 198
199static int set_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *v,
200 unsigned long addr, unsigned long len)
201{
202 /* check address is cacheline aligned */
203 if (addr & (L1_CACHE_BYTES - 1))
204 return -EINVAL;
205 spin_lock(&vcpu->arch.vpa_update_lock);
206 if (v->next_gpa != addr || v->len != len) {
207 v->next_gpa = addr;
208 v->len = addr ? len : 0;
209 v->update_pending = 1;
210 }
211 spin_unlock(&vcpu->arch.vpa_update_lock);
212 return 0;
213}
214
145/* Length for a per-processor buffer is passed in at offset 4 in the buffer */ 215/* Length for a per-processor buffer is passed in at offset 4 in the buffer */
146struct reg_vpa { 216struct reg_vpa {
147 u32 dummy; 217 u32 dummy;
@@ -317,10 +387,16 @@ static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap)
317 387
318static void kvmppc_update_vpas(struct kvm_vcpu *vcpu) 388static void kvmppc_update_vpas(struct kvm_vcpu *vcpu)
319{ 389{
390 if (!(vcpu->arch.vpa.update_pending ||
391 vcpu->arch.slb_shadow.update_pending ||
392 vcpu->arch.dtl.update_pending))
393 return;
394
320 spin_lock(&vcpu->arch.vpa_update_lock); 395 spin_lock(&vcpu->arch.vpa_update_lock);
321 if (vcpu->arch.vpa.update_pending) { 396 if (vcpu->arch.vpa.update_pending) {
322 kvmppc_update_vpa(vcpu, &vcpu->arch.vpa); 397 kvmppc_update_vpa(vcpu, &vcpu->arch.vpa);
323 init_vpa(vcpu, vcpu->arch.vpa.pinned_addr); 398 if (vcpu->arch.vpa.pinned_addr)
399 init_vpa(vcpu, vcpu->arch.vpa.pinned_addr);
324 } 400 }
325 if (vcpu->arch.dtl.update_pending) { 401 if (vcpu->arch.dtl.update_pending) {
326 kvmppc_update_vpa(vcpu, &vcpu->arch.dtl); 402 kvmppc_update_vpa(vcpu, &vcpu->arch.dtl);
@@ -332,24 +408,61 @@ static void kvmppc_update_vpas(struct kvm_vcpu *vcpu)
332 spin_unlock(&vcpu->arch.vpa_update_lock); 408 spin_unlock(&vcpu->arch.vpa_update_lock);
333} 409}
334 410
411/*
412 * Return the accumulated stolen time for the vcore up until `now'.
413 * The caller should hold the vcore lock.
414 */
415static u64 vcore_stolen_time(struct kvmppc_vcore *vc, u64 now)
416{
417 u64 p;
418
419 /*
420 * If we are the task running the vcore, then since we hold
421 * the vcore lock, we can't be preempted, so stolen_tb/preempt_tb
422 * can't be updated, so we don't need the tbacct_lock.
423 * If the vcore is inactive, it can't become active (since we
424 * hold the vcore lock), so the vcpu load/put functions won't
425 * update stolen_tb/preempt_tb, and we don't need tbacct_lock.
426 */
427 if (vc->vcore_state != VCORE_INACTIVE &&
428 vc->runner->arch.run_task != current) {
429 spin_lock(&vc->runner->arch.tbacct_lock);
430 p = vc->stolen_tb;
431 if (vc->preempt_tb != TB_NIL)
432 p += now - vc->preempt_tb;
433 spin_unlock(&vc->runner->arch.tbacct_lock);
434 } else {
435 p = vc->stolen_tb;
436 }
437 return p;
438}
439
335static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, 440static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu,
336 struct kvmppc_vcore *vc) 441 struct kvmppc_vcore *vc)
337{ 442{
338 struct dtl_entry *dt; 443 struct dtl_entry *dt;
339 struct lppaca *vpa; 444 struct lppaca *vpa;
340 unsigned long old_stolen; 445 unsigned long stolen;
446 unsigned long core_stolen;
447 u64 now;
341 448
342 dt = vcpu->arch.dtl_ptr; 449 dt = vcpu->arch.dtl_ptr;
343 vpa = vcpu->arch.vpa.pinned_addr; 450 vpa = vcpu->arch.vpa.pinned_addr;
344 old_stolen = vcpu->arch.stolen_logged; 451 now = mftb();
345 vcpu->arch.stolen_logged = vc->stolen_tb; 452 core_stolen = vcore_stolen_time(vc, now);
453 stolen = core_stolen - vcpu->arch.stolen_logged;
454 vcpu->arch.stolen_logged = core_stolen;
455 spin_lock(&vcpu->arch.tbacct_lock);
456 stolen += vcpu->arch.busy_stolen;
457 vcpu->arch.busy_stolen = 0;
458 spin_unlock(&vcpu->arch.tbacct_lock);
346 if (!dt || !vpa) 459 if (!dt || !vpa)
347 return; 460 return;
348 memset(dt, 0, sizeof(struct dtl_entry)); 461 memset(dt, 0, sizeof(struct dtl_entry));
349 dt->dispatch_reason = 7; 462 dt->dispatch_reason = 7;
350 dt->processor_id = vc->pcpu + vcpu->arch.ptid; 463 dt->processor_id = vc->pcpu + vcpu->arch.ptid;
351 dt->timebase = mftb(); 464 dt->timebase = now;
352 dt->enqueue_to_dispatch_time = vc->stolen_tb - old_stolen; 465 dt->enqueue_to_dispatch_time = stolen;
353 dt->srr0 = kvmppc_get_pc(vcpu); 466 dt->srr0 = kvmppc_get_pc(vcpu);
354 dt->srr1 = vcpu->arch.shregs.msr; 467 dt->srr1 = vcpu->arch.shregs.msr;
355 ++dt; 468 ++dt;
@@ -366,13 +479,16 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
366 unsigned long req = kvmppc_get_gpr(vcpu, 3); 479 unsigned long req = kvmppc_get_gpr(vcpu, 3);
367 unsigned long target, ret = H_SUCCESS; 480 unsigned long target, ret = H_SUCCESS;
368 struct kvm_vcpu *tvcpu; 481 struct kvm_vcpu *tvcpu;
482 int idx;
369 483
370 switch (req) { 484 switch (req) {
371 case H_ENTER: 485 case H_ENTER:
486 idx = srcu_read_lock(&vcpu->kvm->srcu);
372 ret = kvmppc_virtmode_h_enter(vcpu, kvmppc_get_gpr(vcpu, 4), 487 ret = kvmppc_virtmode_h_enter(vcpu, kvmppc_get_gpr(vcpu, 4),
373 kvmppc_get_gpr(vcpu, 5), 488 kvmppc_get_gpr(vcpu, 5),
374 kvmppc_get_gpr(vcpu, 6), 489 kvmppc_get_gpr(vcpu, 6),
375 kvmppc_get_gpr(vcpu, 7)); 490 kvmppc_get_gpr(vcpu, 7));
491 srcu_read_unlock(&vcpu->kvm->srcu, idx);
376 break; 492 break;
377 case H_CEDE: 493 case H_CEDE:
378 break; 494 break;
@@ -429,6 +545,17 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
429 case BOOK3S_INTERRUPT_PERFMON: 545 case BOOK3S_INTERRUPT_PERFMON:
430 r = RESUME_GUEST; 546 r = RESUME_GUEST;
431 break; 547 break;
548 case BOOK3S_INTERRUPT_MACHINE_CHECK:
549 /*
550 * Deliver a machine check interrupt to the guest.
551 * We have to do this, even if the host has handled the
552 * machine check, because machine checks use SRR0/1 and
553 * the interrupt might have trashed guest state in them.
554 */
555 kvmppc_book3s_queue_irqprio(vcpu,
556 BOOK3S_INTERRUPT_MACHINE_CHECK);
557 r = RESUME_GUEST;
558 break;
432 case BOOK3S_INTERRUPT_PROGRAM: 559 case BOOK3S_INTERRUPT_PROGRAM:
433 { 560 {
434 ulong flags; 561 ulong flags;
@@ -470,12 +597,12 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
470 * have been handled already. 597 * have been handled already.
471 */ 598 */
472 case BOOK3S_INTERRUPT_H_DATA_STORAGE: 599 case BOOK3S_INTERRUPT_H_DATA_STORAGE:
473 r = kvmppc_book3s_hv_page_fault(run, vcpu, 600 r = RESUME_PAGE_FAULT;
474 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr);
475 break; 601 break;
476 case BOOK3S_INTERRUPT_H_INST_STORAGE: 602 case BOOK3S_INTERRUPT_H_INST_STORAGE:
477 r = kvmppc_book3s_hv_page_fault(run, vcpu, 603 vcpu->arch.fault_dar = kvmppc_get_pc(vcpu);
478 kvmppc_get_pc(vcpu), 0); 604 vcpu->arch.fault_dsisr = 0;
605 r = RESUME_PAGE_FAULT;
479 break; 606 break;
480 /* 607 /*
481 * This occurs if the guest executes an illegal instruction. 608 * This occurs if the guest executes an illegal instruction.
@@ -535,36 +662,174 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
535 return 0; 662 return 0;
536} 663}
537 664
538int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 665int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
539{ 666{
540 int r = -EINVAL; 667 int r = 0;
668 long int i;
541 669
542 switch (reg->id) { 670 switch (id) {
543 case KVM_REG_PPC_HIOR: 671 case KVM_REG_PPC_HIOR:
544 r = put_user(0, (u64 __user *)reg->addr); 672 *val = get_reg_val(id, 0);
673 break;
674 case KVM_REG_PPC_DABR:
675 *val = get_reg_val(id, vcpu->arch.dabr);
676 break;
677 case KVM_REG_PPC_DSCR:
678 *val = get_reg_val(id, vcpu->arch.dscr);
679 break;
680 case KVM_REG_PPC_PURR:
681 *val = get_reg_val(id, vcpu->arch.purr);
682 break;
683 case KVM_REG_PPC_SPURR:
684 *val = get_reg_val(id, vcpu->arch.spurr);
685 break;
686 case KVM_REG_PPC_AMR:
687 *val = get_reg_val(id, vcpu->arch.amr);
688 break;
689 case KVM_REG_PPC_UAMOR:
690 *val = get_reg_val(id, vcpu->arch.uamor);
691 break;
692 case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRA:
693 i = id - KVM_REG_PPC_MMCR0;
694 *val = get_reg_val(id, vcpu->arch.mmcr[i]);
695 break;
696 case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
697 i = id - KVM_REG_PPC_PMC1;
698 *val = get_reg_val(id, vcpu->arch.pmc[i]);
699 break;
700#ifdef CONFIG_VSX
701 case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
702 if (cpu_has_feature(CPU_FTR_VSX)) {
703 /* VSX => FP reg i is stored in arch.vsr[2*i] */
704 long int i = id - KVM_REG_PPC_FPR0;
705 *val = get_reg_val(id, vcpu->arch.vsr[2 * i]);
706 } else {
707 /* let generic code handle it */
708 r = -EINVAL;
709 }
710 break;
711 case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
712 if (cpu_has_feature(CPU_FTR_VSX)) {
713 long int i = id - KVM_REG_PPC_VSR0;
714 val->vsxval[0] = vcpu->arch.vsr[2 * i];
715 val->vsxval[1] = vcpu->arch.vsr[2 * i + 1];
716 } else {
717 r = -ENXIO;
718 }
719 break;
720#endif /* CONFIG_VSX */
721 case KVM_REG_PPC_VPA_ADDR:
722 spin_lock(&vcpu->arch.vpa_update_lock);
723 *val = get_reg_val(id, vcpu->arch.vpa.next_gpa);
724 spin_unlock(&vcpu->arch.vpa_update_lock);
725 break;
726 case KVM_REG_PPC_VPA_SLB:
727 spin_lock(&vcpu->arch.vpa_update_lock);
728 val->vpaval.addr = vcpu->arch.slb_shadow.next_gpa;
729 val->vpaval.length = vcpu->arch.slb_shadow.len;
730 spin_unlock(&vcpu->arch.vpa_update_lock);
731 break;
732 case KVM_REG_PPC_VPA_DTL:
733 spin_lock(&vcpu->arch.vpa_update_lock);
734 val->vpaval.addr = vcpu->arch.dtl.next_gpa;
735 val->vpaval.length = vcpu->arch.dtl.len;
736 spin_unlock(&vcpu->arch.vpa_update_lock);
545 break; 737 break;
546 default: 738 default:
739 r = -EINVAL;
547 break; 740 break;
548 } 741 }
549 742
550 return r; 743 return r;
551} 744}
552 745
553int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 746int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
554{ 747{
555 int r = -EINVAL; 748 int r = 0;
749 long int i;
750 unsigned long addr, len;
556 751
557 switch (reg->id) { 752 switch (id) {
558 case KVM_REG_PPC_HIOR: 753 case KVM_REG_PPC_HIOR:
559 {
560 u64 hior;
561 /* Only allow this to be set to zero */ 754 /* Only allow this to be set to zero */
562 r = get_user(hior, (u64 __user *)reg->addr); 755 if (set_reg_val(id, *val))
563 if (!r && (hior != 0))
564 r = -EINVAL; 756 r = -EINVAL;
565 break; 757 break;
566 } 758 case KVM_REG_PPC_DABR:
759 vcpu->arch.dabr = set_reg_val(id, *val);
760 break;
761 case KVM_REG_PPC_DSCR:
762 vcpu->arch.dscr = set_reg_val(id, *val);
763 break;
764 case KVM_REG_PPC_PURR:
765 vcpu->arch.purr = set_reg_val(id, *val);
766 break;
767 case KVM_REG_PPC_SPURR:
768 vcpu->arch.spurr = set_reg_val(id, *val);
769 break;
770 case KVM_REG_PPC_AMR:
771 vcpu->arch.amr = set_reg_val(id, *val);
772 break;
773 case KVM_REG_PPC_UAMOR:
774 vcpu->arch.uamor = set_reg_val(id, *val);
775 break;
776 case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRA:
777 i = id - KVM_REG_PPC_MMCR0;
778 vcpu->arch.mmcr[i] = set_reg_val(id, *val);
779 break;
780 case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
781 i = id - KVM_REG_PPC_PMC1;
782 vcpu->arch.pmc[i] = set_reg_val(id, *val);
783 break;
784#ifdef CONFIG_VSX
785 case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
786 if (cpu_has_feature(CPU_FTR_VSX)) {
787 /* VSX => FP reg i is stored in arch.vsr[2*i] */
788 long int i = id - KVM_REG_PPC_FPR0;
789 vcpu->arch.vsr[2 * i] = set_reg_val(id, *val);
790 } else {
791 /* let generic code handle it */
792 r = -EINVAL;
793 }
794 break;
795 case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
796 if (cpu_has_feature(CPU_FTR_VSX)) {
797 long int i = id - KVM_REG_PPC_VSR0;
798 vcpu->arch.vsr[2 * i] = val->vsxval[0];
799 vcpu->arch.vsr[2 * i + 1] = val->vsxval[1];
800 } else {
801 r = -ENXIO;
802 }
803 break;
804#endif /* CONFIG_VSX */
805 case KVM_REG_PPC_VPA_ADDR:
806 addr = set_reg_val(id, *val);
807 r = -EINVAL;
808 if (!addr && (vcpu->arch.slb_shadow.next_gpa ||
809 vcpu->arch.dtl.next_gpa))
810 break;
811 r = set_vpa(vcpu, &vcpu->arch.vpa, addr, sizeof(struct lppaca));
812 break;
813 case KVM_REG_PPC_VPA_SLB:
814 addr = val->vpaval.addr;
815 len = val->vpaval.length;
816 r = -EINVAL;
817 if (addr && !vcpu->arch.vpa.next_gpa)
818 break;
819 r = set_vpa(vcpu, &vcpu->arch.slb_shadow, addr, len);
820 break;
821 case KVM_REG_PPC_VPA_DTL:
822 addr = val->vpaval.addr;
823 len = val->vpaval.length;
824 r = -EINVAL;
825 if (addr && (len < sizeof(struct dtl_entry) ||
826 !vcpu->arch.vpa.next_gpa))
827 break;
828 len -= len % sizeof(struct dtl_entry);
829 r = set_vpa(vcpu, &vcpu->arch.dtl, addr, len);
830 break;
567 default: 831 default:
832 r = -EINVAL;
568 break; 833 break;
569 } 834 }
570 835
@@ -599,20 +864,18 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
599 goto free_vcpu; 864 goto free_vcpu;
600 865
601 vcpu->arch.shared = &vcpu->arch.shregs; 866 vcpu->arch.shared = &vcpu->arch.shregs;
602 vcpu->arch.last_cpu = -1;
603 vcpu->arch.mmcr[0] = MMCR0_FC; 867 vcpu->arch.mmcr[0] = MMCR0_FC;
604 vcpu->arch.ctrl = CTRL_RUNLATCH; 868 vcpu->arch.ctrl = CTRL_RUNLATCH;
605 /* default to host PVR, since we can't spoof it */ 869 /* default to host PVR, since we can't spoof it */
606 vcpu->arch.pvr = mfspr(SPRN_PVR); 870 vcpu->arch.pvr = mfspr(SPRN_PVR);
607 kvmppc_set_pvr(vcpu, vcpu->arch.pvr); 871 kvmppc_set_pvr(vcpu, vcpu->arch.pvr);
608 spin_lock_init(&vcpu->arch.vpa_update_lock); 872 spin_lock_init(&vcpu->arch.vpa_update_lock);
873 spin_lock_init(&vcpu->arch.tbacct_lock);
874 vcpu->arch.busy_preempt = TB_NIL;
609 875
610 kvmppc_mmu_book3s_hv_init(vcpu); 876 kvmppc_mmu_book3s_hv_init(vcpu);
611 877
612 /* 878 vcpu->arch.state = KVMPPC_VCPU_NOTREADY;
613 * We consider the vcpu stopped until we see the first run ioctl for it.
614 */
615 vcpu->arch.state = KVMPPC_VCPU_STOPPED;
616 879
617 init_waitqueue_head(&vcpu->arch.cpu_run); 880 init_waitqueue_head(&vcpu->arch.cpu_run);
618 881
@@ -624,9 +887,10 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
624 INIT_LIST_HEAD(&vcore->runnable_threads); 887 INIT_LIST_HEAD(&vcore->runnable_threads);
625 spin_lock_init(&vcore->lock); 888 spin_lock_init(&vcore->lock);
626 init_waitqueue_head(&vcore->wq); 889 init_waitqueue_head(&vcore->wq);
627 vcore->preempt_tb = mftb(); 890 vcore->preempt_tb = TB_NIL;
628 } 891 }
629 kvm->arch.vcores[core] = vcore; 892 kvm->arch.vcores[core] = vcore;
893 kvm->arch.online_vcores++;
630 } 894 }
631 mutex_unlock(&kvm->lock); 895 mutex_unlock(&kvm->lock);
632 896
@@ -637,7 +901,6 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
637 ++vcore->num_threads; 901 ++vcore->num_threads;
638 spin_unlock(&vcore->lock); 902 spin_unlock(&vcore->lock);
639 vcpu->arch.vcore = vcore; 903 vcpu->arch.vcore = vcore;
640 vcpu->arch.stolen_logged = vcore->stolen_tb;
641 904
642 vcpu->arch.cpu_type = KVM_CPU_3S_64; 905 vcpu->arch.cpu_type = KVM_CPU_3S_64;
643 kvmppc_sanity_check(vcpu); 906 kvmppc_sanity_check(vcpu);
@@ -697,17 +960,18 @@ extern void xics_wake_cpu(int cpu);
697static void kvmppc_remove_runnable(struct kvmppc_vcore *vc, 960static void kvmppc_remove_runnable(struct kvmppc_vcore *vc,
698 struct kvm_vcpu *vcpu) 961 struct kvm_vcpu *vcpu)
699{ 962{
700 struct kvm_vcpu *v; 963 u64 now;
701 964
702 if (vcpu->arch.state != KVMPPC_VCPU_RUNNABLE) 965 if (vcpu->arch.state != KVMPPC_VCPU_RUNNABLE)
703 return; 966 return;
967 spin_lock(&vcpu->arch.tbacct_lock);
968 now = mftb();
969 vcpu->arch.busy_stolen += vcore_stolen_time(vc, now) -
970 vcpu->arch.stolen_logged;
971 vcpu->arch.busy_preempt = now;
704 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST; 972 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST;
973 spin_unlock(&vcpu->arch.tbacct_lock);
705 --vc->n_runnable; 974 --vc->n_runnable;
706 ++vc->n_busy;
707 /* decrement the physical thread id of each following vcpu */
708 v = vcpu;
709 list_for_each_entry_continue(v, &vc->runnable_threads, arch.run_list)
710 --v->arch.ptid;
711 list_del(&vcpu->arch.run_list); 975 list_del(&vcpu->arch.run_list);
712} 976}
713 977
@@ -720,6 +984,7 @@ static int kvmppc_grab_hwthread(int cpu)
720 984
721 /* Ensure the thread won't go into the kernel if it wakes */ 985 /* Ensure the thread won't go into the kernel if it wakes */
722 tpaca->kvm_hstate.hwthread_req = 1; 986 tpaca->kvm_hstate.hwthread_req = 1;
987 tpaca->kvm_hstate.kvm_vcpu = NULL;
723 988
724 /* 989 /*
725 * If the thread is already executing in the kernel (e.g. handling 990 * If the thread is already executing in the kernel (e.g. handling
@@ -769,7 +1034,6 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu)
769 smp_wmb(); 1034 smp_wmb();
770#if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP) 1035#if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
771 if (vcpu->arch.ptid) { 1036 if (vcpu->arch.ptid) {
772 kvmppc_grab_hwthread(cpu);
773 xics_wake_cpu(cpu); 1037 xics_wake_cpu(cpu);
774 ++vc->n_woken; 1038 ++vc->n_woken;
775 } 1039 }
@@ -795,7 +1059,8 @@ static void kvmppc_wait_for_nap(struct kvmppc_vcore *vc)
795 1059
796/* 1060/*
797 * Check that we are on thread 0 and that any other threads in 1061 * Check that we are on thread 0 and that any other threads in
798 * this core are off-line. 1062 * this core are off-line. Then grab the threads so they can't
1063 * enter the kernel.
799 */ 1064 */
800static int on_primary_thread(void) 1065static int on_primary_thread(void)
801{ 1066{
@@ -807,6 +1072,17 @@ static int on_primary_thread(void)
807 while (++thr < threads_per_core) 1072 while (++thr < threads_per_core)
808 if (cpu_online(cpu + thr)) 1073 if (cpu_online(cpu + thr))
809 return 0; 1074 return 0;
1075
1076 /* Grab all hw threads so they can't go into the kernel */
1077 for (thr = 1; thr < threads_per_core; ++thr) {
1078 if (kvmppc_grab_hwthread(cpu + thr)) {
1079 /* Couldn't grab one; let the others go */
1080 do {
1081 kvmppc_release_hwthread(cpu + thr);
1082 } while (--thr > 0);
1083 return 0;
1084 }
1085 }
810 return 1; 1086 return 1;
811} 1087}
812 1088
@@ -814,21 +1090,24 @@ static int on_primary_thread(void)
814 * Run a set of guest threads on a physical core. 1090 * Run a set of guest threads on a physical core.
815 * Called with vc->lock held. 1091 * Called with vc->lock held.
816 */ 1092 */
817static int kvmppc_run_core(struct kvmppc_vcore *vc) 1093static void kvmppc_run_core(struct kvmppc_vcore *vc)
818{ 1094{
819 struct kvm_vcpu *vcpu, *vcpu0, *vnext; 1095 struct kvm_vcpu *vcpu, *vcpu0, *vnext;
820 long ret; 1096 long ret;
821 u64 now; 1097 u64 now;
822 int ptid, i, need_vpa_update; 1098 int ptid, i, need_vpa_update;
1099 int srcu_idx;
1100 struct kvm_vcpu *vcpus_to_update[threads_per_core];
823 1101
824 /* don't start if any threads have a signal pending */ 1102 /* don't start if any threads have a signal pending */
825 need_vpa_update = 0; 1103 need_vpa_update = 0;
826 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { 1104 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
827 if (signal_pending(vcpu->arch.run_task)) 1105 if (signal_pending(vcpu->arch.run_task))
828 return 0; 1106 return;
829 need_vpa_update |= vcpu->arch.vpa.update_pending | 1107 if (vcpu->arch.vpa.update_pending ||
830 vcpu->arch.slb_shadow.update_pending | 1108 vcpu->arch.slb_shadow.update_pending ||
831 vcpu->arch.dtl.update_pending; 1109 vcpu->arch.dtl.update_pending)
1110 vcpus_to_update[need_vpa_update++] = vcpu;
832 } 1111 }
833 1112
834 /* 1113 /*
@@ -838,7 +1117,7 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
838 vc->n_woken = 0; 1117 vc->n_woken = 0;
839 vc->nap_count = 0; 1118 vc->nap_count = 0;
840 vc->entry_exit_count = 0; 1119 vc->entry_exit_count = 0;
841 vc->vcore_state = VCORE_RUNNING; 1120 vc->vcore_state = VCORE_STARTING;
842 vc->in_guest = 0; 1121 vc->in_guest = 0;
843 vc->napping_threads = 0; 1122 vc->napping_threads = 0;
844 1123
@@ -848,24 +1127,12 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
848 */ 1127 */
849 if (need_vpa_update) { 1128 if (need_vpa_update) {
850 spin_unlock(&vc->lock); 1129 spin_unlock(&vc->lock);
851 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) 1130 for (i = 0; i < need_vpa_update; ++i)
852 kvmppc_update_vpas(vcpu); 1131 kvmppc_update_vpas(vcpus_to_update[i]);
853 spin_lock(&vc->lock); 1132 spin_lock(&vc->lock);
854 } 1133 }
855 1134
856 /* 1135 /*
857 * Make sure we are running on thread 0, and that
858 * secondary threads are offline.
859 * XXX we should also block attempts to bring any
860 * secondary threads online.
861 */
862 if (threads_per_core > 1 && !on_primary_thread()) {
863 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
864 vcpu->arch.ret = -EBUSY;
865 goto out;
866 }
867
868 /*
869 * Assign physical thread IDs, first to non-ceded vcpus 1136 * Assign physical thread IDs, first to non-ceded vcpus
870 * and then to ceded ones. 1137 * and then to ceded ones.
871 */ 1138 */
@@ -879,28 +1146,36 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
879 } 1146 }
880 } 1147 }
881 if (!vcpu0) 1148 if (!vcpu0)
882 return 0; /* nothing to run */ 1149 goto out; /* nothing to run; should never happen */
883 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) 1150 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
884 if (vcpu->arch.ceded) 1151 if (vcpu->arch.ceded)
885 vcpu->arch.ptid = ptid++; 1152 vcpu->arch.ptid = ptid++;
886 1153
887 vc->stolen_tb += mftb() - vc->preempt_tb; 1154 /*
1155 * Make sure we are running on thread 0, and that
1156 * secondary threads are offline.
1157 */
1158 if (threads_per_core > 1 && !on_primary_thread()) {
1159 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
1160 vcpu->arch.ret = -EBUSY;
1161 goto out;
1162 }
1163
888 vc->pcpu = smp_processor_id(); 1164 vc->pcpu = smp_processor_id();
889 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { 1165 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
890 kvmppc_start_thread(vcpu); 1166 kvmppc_start_thread(vcpu);
891 kvmppc_create_dtl_entry(vcpu, vc); 1167 kvmppc_create_dtl_entry(vcpu, vc);
892 } 1168 }
893 /* Grab any remaining hw threads so they can't go into the kernel */
894 for (i = ptid; i < threads_per_core; ++i)
895 kvmppc_grab_hwthread(vc->pcpu + i);
896 1169
1170 vc->vcore_state = VCORE_RUNNING;
897 preempt_disable(); 1171 preempt_disable();
898 spin_unlock(&vc->lock); 1172 spin_unlock(&vc->lock);
899 1173
900 kvm_guest_enter(); 1174 kvm_guest_enter();
1175
1176 srcu_idx = srcu_read_lock(&vcpu0->kvm->srcu);
1177
901 __kvmppc_vcore_entry(NULL, vcpu0); 1178 __kvmppc_vcore_entry(NULL, vcpu0);
902 for (i = 0; i < threads_per_core; ++i)
903 kvmppc_release_hwthread(vc->pcpu + i);
904 1179
905 spin_lock(&vc->lock); 1180 spin_lock(&vc->lock);
906 /* disable sending of IPIs on virtual external irqs */ 1181 /* disable sending of IPIs on virtual external irqs */
@@ -909,10 +1184,14 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
909 /* wait for secondary threads to finish writing their state to memory */ 1184 /* wait for secondary threads to finish writing their state to memory */
910 if (vc->nap_count < vc->n_woken) 1185 if (vc->nap_count < vc->n_woken)
911 kvmppc_wait_for_nap(vc); 1186 kvmppc_wait_for_nap(vc);
1187 for (i = 0; i < threads_per_core; ++i)
1188 kvmppc_release_hwthread(vc->pcpu + i);
912 /* prevent other vcpu threads from doing kvmppc_start_thread() now */ 1189 /* prevent other vcpu threads from doing kvmppc_start_thread() now */
913 vc->vcore_state = VCORE_EXITING; 1190 vc->vcore_state = VCORE_EXITING;
914 spin_unlock(&vc->lock); 1191 spin_unlock(&vc->lock);
915 1192
1193 srcu_read_unlock(&vcpu0->kvm->srcu, srcu_idx);
1194
916 /* make sure updates to secondary vcpu structs are visible now */ 1195 /* make sure updates to secondary vcpu structs are visible now */
917 smp_mb(); 1196 smp_mb();
918 kvm_guest_exit(); 1197 kvm_guest_exit();
@@ -920,6 +1199,7 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
920 preempt_enable(); 1199 preempt_enable();
921 kvm_resched(vcpu); 1200 kvm_resched(vcpu);
922 1201
1202 spin_lock(&vc->lock);
923 now = get_tb(); 1203 now = get_tb();
924 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) { 1204 list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
925 /* cancel pending dec exception if dec is positive */ 1205 /* cancel pending dec exception if dec is positive */
@@ -943,10 +1223,8 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
943 } 1223 }
944 } 1224 }
945 1225
946 spin_lock(&vc->lock);
947 out: 1226 out:
948 vc->vcore_state = VCORE_INACTIVE; 1227 vc->vcore_state = VCORE_INACTIVE;
949 vc->preempt_tb = mftb();
950 list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads, 1228 list_for_each_entry_safe(vcpu, vnext, &vc->runnable_threads,
951 arch.run_list) { 1229 arch.run_list) {
952 if (vcpu->arch.ret != RESUME_GUEST) { 1230 if (vcpu->arch.ret != RESUME_GUEST) {
@@ -954,8 +1232,6 @@ static int kvmppc_run_core(struct kvmppc_vcore *vc)
954 wake_up(&vcpu->arch.cpu_run); 1232 wake_up(&vcpu->arch.cpu_run);
955 } 1233 }
956 } 1234 }
957
958 return 1;
959} 1235}
960 1236
961/* 1237/*
@@ -979,20 +1255,11 @@ static void kvmppc_wait_for_exec(struct kvm_vcpu *vcpu, int wait_state)
979static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc) 1255static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
980{ 1256{
981 DEFINE_WAIT(wait); 1257 DEFINE_WAIT(wait);
982 struct kvm_vcpu *v;
983 int all_idle = 1;
984 1258
985 prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE); 1259 prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
986 vc->vcore_state = VCORE_SLEEPING; 1260 vc->vcore_state = VCORE_SLEEPING;
987 spin_unlock(&vc->lock); 1261 spin_unlock(&vc->lock);
988 list_for_each_entry(v, &vc->runnable_threads, arch.run_list) { 1262 schedule();
989 if (!v->arch.ceded || v->arch.pending_exceptions) {
990 all_idle = 0;
991 break;
992 }
993 }
994 if (all_idle)
995 schedule();
996 finish_wait(&vc->wq, &wait); 1263 finish_wait(&vc->wq, &wait);
997 spin_lock(&vc->lock); 1264 spin_lock(&vc->lock);
998 vc->vcore_state = VCORE_INACTIVE; 1265 vc->vcore_state = VCORE_INACTIVE;
@@ -1001,13 +1268,13 @@ static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
1001static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 1268static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1002{ 1269{
1003 int n_ceded; 1270 int n_ceded;
1004 int prev_state;
1005 struct kvmppc_vcore *vc; 1271 struct kvmppc_vcore *vc;
1006 struct kvm_vcpu *v, *vn; 1272 struct kvm_vcpu *v, *vn;
1007 1273
1008 kvm_run->exit_reason = 0; 1274 kvm_run->exit_reason = 0;
1009 vcpu->arch.ret = RESUME_GUEST; 1275 vcpu->arch.ret = RESUME_GUEST;
1010 vcpu->arch.trap = 0; 1276 vcpu->arch.trap = 0;
1277 kvmppc_update_vpas(vcpu);
1011 1278
1012 /* 1279 /*
1013 * Synchronize with other threads in this virtual core 1280 * Synchronize with other threads in this virtual core
@@ -1017,8 +1284,9 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1017 vcpu->arch.ceded = 0; 1284 vcpu->arch.ceded = 0;
1018 vcpu->arch.run_task = current; 1285 vcpu->arch.run_task = current;
1019 vcpu->arch.kvm_run = kvm_run; 1286 vcpu->arch.kvm_run = kvm_run;
1020 prev_state = vcpu->arch.state; 1287 vcpu->arch.stolen_logged = vcore_stolen_time(vc, mftb());
1021 vcpu->arch.state = KVMPPC_VCPU_RUNNABLE; 1288 vcpu->arch.state = KVMPPC_VCPU_RUNNABLE;
1289 vcpu->arch.busy_preempt = TB_NIL;
1022 list_add_tail(&vcpu->arch.run_list, &vc->runnable_threads); 1290 list_add_tail(&vcpu->arch.run_list, &vc->runnable_threads);
1023 ++vc->n_runnable; 1291 ++vc->n_runnable;
1024 1292
@@ -1027,33 +1295,26 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1027 * If the vcore is already running, we may be able to start 1295 * If the vcore is already running, we may be able to start
1028 * this thread straight away and have it join in. 1296 * this thread straight away and have it join in.
1029 */ 1297 */
1030 if (prev_state == KVMPPC_VCPU_STOPPED) { 1298 if (!signal_pending(current)) {
1031 if (vc->vcore_state == VCORE_RUNNING && 1299 if (vc->vcore_state == VCORE_RUNNING &&
1032 VCORE_EXIT_COUNT(vc) == 0) { 1300 VCORE_EXIT_COUNT(vc) == 0) {
1033 vcpu->arch.ptid = vc->n_runnable - 1; 1301 vcpu->arch.ptid = vc->n_runnable - 1;
1302 kvmppc_create_dtl_entry(vcpu, vc);
1034 kvmppc_start_thread(vcpu); 1303 kvmppc_start_thread(vcpu);
1304 } else if (vc->vcore_state == VCORE_SLEEPING) {
1305 wake_up(&vc->wq);
1035 } 1306 }
1036 1307
1037 } else if (prev_state == KVMPPC_VCPU_BUSY_IN_HOST) 1308 }
1038 --vc->n_busy;
1039 1309
1040 while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE && 1310 while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE &&
1041 !signal_pending(current)) { 1311 !signal_pending(current)) {
1042 if (vc->n_busy || vc->vcore_state != VCORE_INACTIVE) { 1312 if (vc->vcore_state != VCORE_INACTIVE) {
1043 spin_unlock(&vc->lock); 1313 spin_unlock(&vc->lock);
1044 kvmppc_wait_for_exec(vcpu, TASK_INTERRUPTIBLE); 1314 kvmppc_wait_for_exec(vcpu, TASK_INTERRUPTIBLE);
1045 spin_lock(&vc->lock); 1315 spin_lock(&vc->lock);
1046 continue; 1316 continue;
1047 } 1317 }
1048 vc->runner = vcpu;
1049 n_ceded = 0;
1050 list_for_each_entry(v, &vc->runnable_threads, arch.run_list)
1051 n_ceded += v->arch.ceded;
1052 if (n_ceded == vc->n_runnable)
1053 kvmppc_vcore_blocked(vc);
1054 else
1055 kvmppc_run_core(vc);
1056
1057 list_for_each_entry_safe(v, vn, &vc->runnable_threads, 1318 list_for_each_entry_safe(v, vn, &vc->runnable_threads,
1058 arch.run_list) { 1319 arch.run_list) {
1059 kvmppc_core_prepare_to_enter(v); 1320 kvmppc_core_prepare_to_enter(v);
@@ -1065,22 +1326,40 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1065 wake_up(&v->arch.cpu_run); 1326 wake_up(&v->arch.cpu_run);
1066 } 1327 }
1067 } 1328 }
1329 if (!vc->n_runnable || vcpu->arch.state != KVMPPC_VCPU_RUNNABLE)
1330 break;
1331 vc->runner = vcpu;
1332 n_ceded = 0;
1333 list_for_each_entry(v, &vc->runnable_threads, arch.run_list)
1334 if (!v->arch.pending_exceptions)
1335 n_ceded += v->arch.ceded;
1336 if (n_ceded == vc->n_runnable)
1337 kvmppc_vcore_blocked(vc);
1338 else
1339 kvmppc_run_core(vc);
1068 vc->runner = NULL; 1340 vc->runner = NULL;
1069 } 1341 }
1070 1342
1071 if (signal_pending(current)) { 1343 while (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE &&
1072 if (vc->vcore_state == VCORE_RUNNING || 1344 (vc->vcore_state == VCORE_RUNNING ||
1073 vc->vcore_state == VCORE_EXITING) { 1345 vc->vcore_state == VCORE_EXITING)) {
1074 spin_unlock(&vc->lock); 1346 spin_unlock(&vc->lock);
1075 kvmppc_wait_for_exec(vcpu, TASK_UNINTERRUPTIBLE); 1347 kvmppc_wait_for_exec(vcpu, TASK_UNINTERRUPTIBLE);
1076 spin_lock(&vc->lock); 1348 spin_lock(&vc->lock);
1077 } 1349 }
1078 if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) { 1350
1079 kvmppc_remove_runnable(vc, vcpu); 1351 if (vcpu->arch.state == KVMPPC_VCPU_RUNNABLE) {
1080 vcpu->stat.signal_exits++; 1352 kvmppc_remove_runnable(vc, vcpu);
1081 kvm_run->exit_reason = KVM_EXIT_INTR; 1353 vcpu->stat.signal_exits++;
1082 vcpu->arch.ret = -EINTR; 1354 kvm_run->exit_reason = KVM_EXIT_INTR;
1083 } 1355 vcpu->arch.ret = -EINTR;
1356 }
1357
1358 if (vc->n_runnable && vc->vcore_state == VCORE_INACTIVE) {
1359 /* Wake up some vcpu to run the core */
1360 v = list_first_entry(&vc->runnable_threads,
1361 struct kvm_vcpu, arch.run_list);
1362 wake_up(&v->arch.cpu_run);
1084 } 1363 }
1085 1364
1086 spin_unlock(&vc->lock); 1365 spin_unlock(&vc->lock);
@@ -1090,6 +1369,7 @@ static int kvmppc_run_vcpu(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1090int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu) 1369int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)
1091{ 1370{
1092 int r; 1371 int r;
1372 int srcu_idx;
1093 1373
1094 if (!vcpu->arch.sane) { 1374 if (!vcpu->arch.sane) {
1095 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1375 run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
@@ -1120,6 +1400,7 @@ int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)
1120 flush_vsx_to_thread(current); 1400 flush_vsx_to_thread(current);
1121 vcpu->arch.wqp = &vcpu->arch.vcore->wq; 1401 vcpu->arch.wqp = &vcpu->arch.vcore->wq;
1122 vcpu->arch.pgdir = current->mm->pgd; 1402 vcpu->arch.pgdir = current->mm->pgd;
1403 vcpu->arch.state = KVMPPC_VCPU_BUSY_IN_HOST;
1123 1404
1124 do { 1405 do {
1125 r = kvmppc_run_vcpu(run, vcpu); 1406 r = kvmppc_run_vcpu(run, vcpu);
@@ -1128,10 +1409,16 @@ int kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu)
1128 !(vcpu->arch.shregs.msr & MSR_PR)) { 1409 !(vcpu->arch.shregs.msr & MSR_PR)) {
1129 r = kvmppc_pseries_do_hcall(vcpu); 1410 r = kvmppc_pseries_do_hcall(vcpu);
1130 kvmppc_core_prepare_to_enter(vcpu); 1411 kvmppc_core_prepare_to_enter(vcpu);
1412 } else if (r == RESUME_PAGE_FAULT) {
1413 srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
1414 r = kvmppc_book3s_hv_page_fault(run, vcpu,
1415 vcpu->arch.fault_dar, vcpu->arch.fault_dsisr);
1416 srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx);
1131 } 1417 }
1132 } while (r == RESUME_GUEST); 1418 } while (r == RESUME_GUEST);
1133 1419
1134 out: 1420 out:
1421 vcpu->arch.state = KVMPPC_VCPU_NOTREADY;
1135 atomic_dec(&vcpu->kvm->arch.vcpus_running); 1422 atomic_dec(&vcpu->kvm->arch.vcpus_running);
1136 return r; 1423 return r;
1137} 1424}
@@ -1273,7 +1560,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
1273 n = kvm_dirty_bitmap_bytes(memslot); 1560 n = kvm_dirty_bitmap_bytes(memslot);
1274 memset(memslot->dirty_bitmap, 0, n); 1561 memset(memslot->dirty_bitmap, 0, n);
1275 1562
1276 r = kvmppc_hv_get_dirty_log(kvm, memslot); 1563 r = kvmppc_hv_get_dirty_log(kvm, memslot, memslot->dirty_bitmap);
1277 if (r) 1564 if (r)
1278 goto out; 1565 goto out;
1279 1566
@@ -1287,67 +1574,88 @@ out:
1287 return r; 1574 return r;
1288} 1575}
1289 1576
1290static unsigned long slb_pgsize_encoding(unsigned long psize) 1577static void unpin_slot(struct kvm_memory_slot *memslot)
1291{ 1578{
1292 unsigned long senc = 0; 1579 unsigned long *physp;
1580 unsigned long j, npages, pfn;
1581 struct page *page;
1293 1582
1294 if (psize > 0x1000) { 1583 physp = memslot->arch.slot_phys;
1295 senc = SLB_VSID_L; 1584 npages = memslot->npages;
1296 if (psize == 0x10000) 1585 if (!physp)
1297 senc |= SLB_VSID_LP_01; 1586 return;
1587 for (j = 0; j < npages; j++) {
1588 if (!(physp[j] & KVMPPC_GOT_PAGE))
1589 continue;
1590 pfn = physp[j] >> PAGE_SHIFT;
1591 page = pfn_to_page(pfn);
1592 SetPageDirty(page);
1593 put_page(page);
1594 }
1595}
1596
1597void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
1598 struct kvm_memory_slot *dont)
1599{
1600 if (!dont || free->arch.rmap != dont->arch.rmap) {
1601 vfree(free->arch.rmap);
1602 free->arch.rmap = NULL;
1603 }
1604 if (!dont || free->arch.slot_phys != dont->arch.slot_phys) {
1605 unpin_slot(free);
1606 vfree(free->arch.slot_phys);
1607 free->arch.slot_phys = NULL;
1298 } 1608 }
1299 return senc; 1609}
1610
1611int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
1612 unsigned long npages)
1613{
1614 slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap));
1615 if (!slot->arch.rmap)
1616 return -ENOMEM;
1617 slot->arch.slot_phys = NULL;
1618
1619 return 0;
1300} 1620}
1301 1621
1302int kvmppc_core_prepare_memory_region(struct kvm *kvm, 1622int kvmppc_core_prepare_memory_region(struct kvm *kvm,
1303 struct kvm_userspace_memory_region *mem) 1623 struct kvm_memory_slot *memslot,
1624 struct kvm_userspace_memory_region *mem)
1304{ 1625{
1305 unsigned long npages;
1306 unsigned long *phys; 1626 unsigned long *phys;
1307 1627
1308 /* Allocate a slot_phys array */ 1628 /* Allocate a slot_phys array if needed */
1309 phys = kvm->arch.slot_phys[mem->slot]; 1629 phys = memslot->arch.slot_phys;
1310 if (!kvm->arch.using_mmu_notifiers && !phys) { 1630 if (!kvm->arch.using_mmu_notifiers && !phys && memslot->npages) {
1311 npages = mem->memory_size >> PAGE_SHIFT; 1631 phys = vzalloc(memslot->npages * sizeof(unsigned long));
1312 phys = vzalloc(npages * sizeof(unsigned long));
1313 if (!phys) 1632 if (!phys)
1314 return -ENOMEM; 1633 return -ENOMEM;
1315 kvm->arch.slot_phys[mem->slot] = phys; 1634 memslot->arch.slot_phys = phys;
1316 kvm->arch.slot_npages[mem->slot] = npages;
1317 } 1635 }
1318 1636
1319 return 0; 1637 return 0;
1320} 1638}
1321 1639
1322static void unpin_slot(struct kvm *kvm, int slot_id) 1640void kvmppc_core_commit_memory_region(struct kvm *kvm,
1641 struct kvm_userspace_memory_region *mem,
1642 struct kvm_memory_slot old)
1323{ 1643{
1324 unsigned long *physp; 1644 unsigned long npages = mem->memory_size >> PAGE_SHIFT;
1325 unsigned long j, npages, pfn; 1645 struct kvm_memory_slot *memslot;
1326 struct page *page;
1327 1646
1328 physp = kvm->arch.slot_phys[slot_id]; 1647 if (npages && old.npages) {
1329 npages = kvm->arch.slot_npages[slot_id]; 1648 /*
1330 if (physp) { 1649 * If modifying a memslot, reset all the rmap dirty bits.
1331 spin_lock(&kvm->arch.slot_phys_lock); 1650 * If this is a new memslot, we don't need to do anything
1332 for (j = 0; j < npages; j++) { 1651 * since the rmap array starts out as all zeroes,
1333 if (!(physp[j] & KVMPPC_GOT_PAGE)) 1652 * i.e. no pages are dirty.
1334 continue; 1653 */
1335 pfn = physp[j] >> PAGE_SHIFT; 1654 memslot = id_to_memslot(kvm->memslots, mem->slot);
1336 page = pfn_to_page(pfn); 1655 kvmppc_hv_get_dirty_log(kvm, memslot, NULL);
1337 SetPageDirty(page);
1338 put_page(page);
1339 }
1340 kvm->arch.slot_phys[slot_id] = NULL;
1341 spin_unlock(&kvm->arch.slot_phys_lock);
1342 vfree(physp);
1343 } 1656 }
1344} 1657}
1345 1658
1346void kvmppc_core_commit_memory_region(struct kvm *kvm,
1347 struct kvm_userspace_memory_region *mem)
1348{
1349}
1350
1351static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu) 1659static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1352{ 1660{
1353 int err = 0; 1661 int err = 0;
@@ -1362,6 +1670,7 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1362 unsigned long rmls; 1670 unsigned long rmls;
1363 unsigned long *physp; 1671 unsigned long *physp;
1364 unsigned long i, npages; 1672 unsigned long i, npages;
1673 int srcu_idx;
1365 1674
1366 mutex_lock(&kvm->lock); 1675 mutex_lock(&kvm->lock);
1367 if (kvm->arch.rma_setup_done) 1676 if (kvm->arch.rma_setup_done)
@@ -1377,12 +1686,13 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1377 } 1686 }
1378 1687
1379 /* Look up the memslot for guest physical address 0 */ 1688 /* Look up the memslot for guest physical address 0 */
1689 srcu_idx = srcu_read_lock(&kvm->srcu);
1380 memslot = gfn_to_memslot(kvm, 0); 1690 memslot = gfn_to_memslot(kvm, 0);
1381 1691
1382 /* We must have some memory at 0 by now */ 1692 /* We must have some memory at 0 by now */
1383 err = -EINVAL; 1693 err = -EINVAL;
1384 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) 1694 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
1385 goto out; 1695 goto out_srcu;
1386 1696
1387 /* Look up the VMA for the start of this memory slot */ 1697 /* Look up the VMA for the start of this memory slot */
1388 hva = memslot->userspace_addr; 1698 hva = memslot->userspace_addr;
@@ -1406,14 +1716,14 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1406 err = -EPERM; 1716 err = -EPERM;
1407 if (cpu_has_feature(CPU_FTR_ARCH_201)) { 1717 if (cpu_has_feature(CPU_FTR_ARCH_201)) {
1408 pr_err("KVM: CPU requires an RMO\n"); 1718 pr_err("KVM: CPU requires an RMO\n");
1409 goto out; 1719 goto out_srcu;
1410 } 1720 }
1411 1721
1412 /* We can handle 4k, 64k or 16M pages in the VRMA */ 1722 /* We can handle 4k, 64k or 16M pages in the VRMA */
1413 err = -EINVAL; 1723 err = -EINVAL;
1414 if (!(psize == 0x1000 || psize == 0x10000 || 1724 if (!(psize == 0x1000 || psize == 0x10000 ||
1415 psize == 0x1000000)) 1725 psize == 0x1000000))
1416 goto out; 1726 goto out_srcu;
1417 1727
1418 /* Update VRMASD field in the LPCR */ 1728 /* Update VRMASD field in the LPCR */
1419 senc = slb_pgsize_encoding(psize); 1729 senc = slb_pgsize_encoding(psize);
@@ -1436,7 +1746,7 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1436 err = -EINVAL; 1746 err = -EINVAL;
1437 if (rmls < 0) { 1747 if (rmls < 0) {
1438 pr_err("KVM: Can't use RMA of 0x%lx bytes\n", rma_size); 1748 pr_err("KVM: Can't use RMA of 0x%lx bytes\n", rma_size);
1439 goto out; 1749 goto out_srcu;
1440 } 1750 }
1441 atomic_inc(&ri->use_count); 1751 atomic_inc(&ri->use_count);
1442 kvm->arch.rma = ri; 1752 kvm->arch.rma = ri;
@@ -1465,17 +1775,24 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
1465 /* Initialize phys addrs of pages in RMO */ 1775 /* Initialize phys addrs of pages in RMO */
1466 npages = ri->npages; 1776 npages = ri->npages;
1467 porder = __ilog2(npages); 1777 porder = __ilog2(npages);
1468 physp = kvm->arch.slot_phys[memslot->id]; 1778 physp = memslot->arch.slot_phys;
1469 spin_lock(&kvm->arch.slot_phys_lock); 1779 if (physp) {
1470 for (i = 0; i < npages; ++i) 1780 if (npages > memslot->npages)
1471 physp[i] = ((ri->base_pfn + i) << PAGE_SHIFT) + porder; 1781 npages = memslot->npages;
1472 spin_unlock(&kvm->arch.slot_phys_lock); 1782 spin_lock(&kvm->arch.slot_phys_lock);
1783 for (i = 0; i < npages; ++i)
1784 physp[i] = ((ri->base_pfn + i) << PAGE_SHIFT) +
1785 porder;
1786 spin_unlock(&kvm->arch.slot_phys_lock);
1787 }
1473 } 1788 }
1474 1789
1475 /* Order updates to kvm->arch.lpcr etc. vs. rma_setup_done */ 1790 /* Order updates to kvm->arch.lpcr etc. vs. rma_setup_done */
1476 smp_wmb(); 1791 smp_wmb();
1477 kvm->arch.rma_setup_done = 1; 1792 kvm->arch.rma_setup_done = 1;
1478 err = 0; 1793 err = 0;
1794 out_srcu:
1795 srcu_read_unlock(&kvm->srcu, srcu_idx);
1479 out: 1796 out:
1480 mutex_unlock(&kvm->lock); 1797 mutex_unlock(&kvm->lock);
1481 return err; 1798 return err;
@@ -1496,6 +1813,13 @@ int kvmppc_core_init_vm(struct kvm *kvm)
1496 return -ENOMEM; 1813 return -ENOMEM;
1497 kvm->arch.lpid = lpid; 1814 kvm->arch.lpid = lpid;
1498 1815
1816 /*
1817 * Since we don't flush the TLB when tearing down a VM,
1818 * and this lpid might have previously been used,
1819 * make sure we flush on each core before running the new VM.
1820 */
1821 cpumask_setall(&kvm->arch.need_tlb_flush);
1822
1499 INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables); 1823 INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables);
1500 1824
1501 kvm->arch.rma = NULL; 1825 kvm->arch.rma = NULL;
@@ -1523,16 +1847,19 @@ int kvmppc_core_init_vm(struct kvm *kvm)
1523 1847
1524 kvm->arch.using_mmu_notifiers = !!cpu_has_feature(CPU_FTR_ARCH_206); 1848 kvm->arch.using_mmu_notifiers = !!cpu_has_feature(CPU_FTR_ARCH_206);
1525 spin_lock_init(&kvm->arch.slot_phys_lock); 1849 spin_lock_init(&kvm->arch.slot_phys_lock);
1850
1851 /*
1852 * Don't allow secondary CPU threads to come online
1853 * while any KVM VMs exist.
1854 */
1855 inhibit_secondary_onlining();
1856
1526 return 0; 1857 return 0;
1527} 1858}
1528 1859
1529void kvmppc_core_destroy_vm(struct kvm *kvm) 1860void kvmppc_core_destroy_vm(struct kvm *kvm)
1530{ 1861{
1531 unsigned long i; 1862 uninhibit_secondary_onlining();
1532
1533 if (!kvm->arch.using_mmu_notifiers)
1534 for (i = 0; i < KVM_MEM_SLOTS_NUM; i++)
1535 unpin_slot(kvm, i);
1536 1863
1537 if (kvm->arch.rma) { 1864 if (kvm->arch.rma) {
1538 kvm_release_rma(kvm->arch.rma); 1865 kvm_release_rma(kvm->arch.rma);
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
index fb4eac290fef..ec0a9e5de100 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -157,8 +157,8 @@ static void __init kvm_linear_init_one(ulong size, int count, int type)
157 linear_info = alloc_bootmem(count * sizeof(struct kvmppc_linear_info)); 157 linear_info = alloc_bootmem(count * sizeof(struct kvmppc_linear_info));
158 for (i = 0; i < count; ++i) { 158 for (i = 0; i < count; ++i) {
159 linear = alloc_bootmem_align(size, size); 159 linear = alloc_bootmem_align(size, size);
160 pr_info("Allocated KVM %s at %p (%ld MB)\n", typestr, linear, 160 pr_debug("Allocated KVM %s at %p (%ld MB)\n", typestr, linear,
161 size >> 20); 161 size >> 20);
162 linear_info[i].base_virt = linear; 162 linear_info[i].base_virt = linear;
163 linear_info[i].base_pfn = __pa(linear) >> PAGE_SHIFT; 163 linear_info[i].base_pfn = __pa(linear) >> PAGE_SHIFT;
164 linear_info[i].npages = npages; 164 linear_info[i].npages = npages;
diff --git a/arch/powerpc/kvm/book3s_hv_ras.c b/arch/powerpc/kvm/book3s_hv_ras.c
new file mode 100644
index 000000000000..a353c485808c
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_hv_ras.c
@@ -0,0 +1,148 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
5 *
6 * Copyright 2012 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
7 */
8
9#include <linux/types.h>
10#include <linux/string.h>
11#include <linux/kvm.h>
12#include <linux/kvm_host.h>
13#include <linux/kernel.h>
14#include <asm/opal.h>
15
16/* SRR1 bits for machine check on POWER7 */
17#define SRR1_MC_LDSTERR (1ul << (63-42))
18#define SRR1_MC_IFETCH_SH (63-45)
19#define SRR1_MC_IFETCH_MASK 0x7
20#define SRR1_MC_IFETCH_SLBPAR 2 /* SLB parity error */
21#define SRR1_MC_IFETCH_SLBMULTI 3 /* SLB multi-hit */
22#define SRR1_MC_IFETCH_SLBPARMULTI 4 /* SLB parity + multi-hit */
23#define SRR1_MC_IFETCH_TLBMULTI 5 /* I-TLB multi-hit */
24
25/* DSISR bits for machine check on POWER7 */
26#define DSISR_MC_DERAT_MULTI 0x800 /* D-ERAT multi-hit */
27#define DSISR_MC_TLB_MULTI 0x400 /* D-TLB multi-hit */
28#define DSISR_MC_SLB_PARITY 0x100 /* SLB parity error */
29#define DSISR_MC_SLB_MULTI 0x080 /* SLB multi-hit */
30#define DSISR_MC_SLB_PARMULTI 0x040 /* SLB parity + multi-hit */
31
32/* POWER7 SLB flush and reload */
33static void reload_slb(struct kvm_vcpu *vcpu)
34{
35 struct slb_shadow *slb;
36 unsigned long i, n;
37
38 /* First clear out SLB */
39 asm volatile("slbmte %0,%0; slbia" : : "r" (0));
40
41 /* Do they have an SLB shadow buffer registered? */
42 slb = vcpu->arch.slb_shadow.pinned_addr;
43 if (!slb)
44 return;
45
46 /* Sanity check */
47 n = min_t(u32, slb->persistent, SLB_MIN_SIZE);
48 if ((void *) &slb->save_area[n] > vcpu->arch.slb_shadow.pinned_end)
49 return;
50
51 /* Load up the SLB from that */
52 for (i = 0; i < n; ++i) {
53 unsigned long rb = slb->save_area[i].esid;
54 unsigned long rs = slb->save_area[i].vsid;
55
56 rb = (rb & ~0xFFFul) | i; /* insert entry number */
57 asm volatile("slbmte %0,%1" : : "r" (rs), "r" (rb));
58 }
59}
60
61/* POWER7 TLB flush */
62static void flush_tlb_power7(struct kvm_vcpu *vcpu)
63{
64 unsigned long i, rb;
65
66 rb = TLBIEL_INVAL_SET_LPID;
67 for (i = 0; i < POWER7_TLB_SETS; ++i) {
68 asm volatile("tlbiel %0" : : "r" (rb));
69 rb += 1 << TLBIEL_INVAL_SET_SHIFT;
70 }
71}
72
73/*
74 * On POWER7, see if we can handle a machine check that occurred inside
75 * the guest in real mode, without switching to the host partition.
76 *
77 * Returns: 0 => exit guest, 1 => deliver machine check to guest
78 */
79static long kvmppc_realmode_mc_power7(struct kvm_vcpu *vcpu)
80{
81 unsigned long srr1 = vcpu->arch.shregs.msr;
82#ifdef CONFIG_PPC_POWERNV
83 struct opal_machine_check_event *opal_evt;
84#endif
85 long handled = 1;
86
87 if (srr1 & SRR1_MC_LDSTERR) {
88 /* error on load/store */
89 unsigned long dsisr = vcpu->arch.shregs.dsisr;
90
91 if (dsisr & (DSISR_MC_SLB_PARMULTI | DSISR_MC_SLB_MULTI |
92 DSISR_MC_SLB_PARITY | DSISR_MC_DERAT_MULTI)) {
93 /* flush and reload SLB; flushes D-ERAT too */
94 reload_slb(vcpu);
95 dsisr &= ~(DSISR_MC_SLB_PARMULTI | DSISR_MC_SLB_MULTI |
96 DSISR_MC_SLB_PARITY | DSISR_MC_DERAT_MULTI);
97 }
98 if (dsisr & DSISR_MC_TLB_MULTI) {
99 flush_tlb_power7(vcpu);
100 dsisr &= ~DSISR_MC_TLB_MULTI;
101 }
102 /* Any other errors we don't understand? */
103 if (dsisr & 0xffffffffUL)
104 handled = 0;
105 }
106
107 switch ((srr1 >> SRR1_MC_IFETCH_SH) & SRR1_MC_IFETCH_MASK) {
108 case 0:
109 break;
110 case SRR1_MC_IFETCH_SLBPAR:
111 case SRR1_MC_IFETCH_SLBMULTI:
112 case SRR1_MC_IFETCH_SLBPARMULTI:
113 reload_slb(vcpu);
114 break;
115 case SRR1_MC_IFETCH_TLBMULTI:
116 flush_tlb_power7(vcpu);
117 break;
118 default:
119 handled = 0;
120 }
121
122#ifdef CONFIG_PPC_POWERNV
123 /*
124 * See if OPAL has already handled the condition.
125 * We assume that if the condition is recovered then OPAL
126 * will have generated an error log event that we will pick
127 * up and log later.
128 */
129 opal_evt = local_paca->opal_mc_evt;
130 if (opal_evt->version == OpalMCE_V1 &&
131 (opal_evt->severity == OpalMCE_SEV_NO_ERROR ||
132 opal_evt->disposition == OpalMCE_DISPOSITION_RECOVERED))
133 handled = 1;
134
135 if (handled)
136 opal_evt->in_use = 0;
137#endif
138
139 return handled;
140}
141
142long kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu)
143{
144 if (cpu_has_feature(CPU_FTR_ARCH_206))
145 return kvmppc_realmode_mc_power7(vcpu);
146
147 return 0;
148}
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index fb0e821622d4..19c93bae1aea 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -35,6 +35,37 @@ static void *real_vmalloc_addr(void *x)
35 return __va(addr); 35 return __va(addr);
36} 36}
37 37
38/* Return 1 if we need to do a global tlbie, 0 if we can use tlbiel */
39static int global_invalidates(struct kvm *kvm, unsigned long flags)
40{
41 int global;
42
43 /*
44 * If there is only one vcore, and it's currently running,
45 * we can use tlbiel as long as we mark all other physical
46 * cores as potentially having stale TLB entries for this lpid.
47 * If we're not using MMU notifiers, we never take pages away
48 * from the guest, so we can use tlbiel if requested.
49 * Otherwise, don't use tlbiel.
50 */
51 if (kvm->arch.online_vcores == 1 && local_paca->kvm_hstate.kvm_vcore)
52 global = 0;
53 else if (kvm->arch.using_mmu_notifiers)
54 global = 1;
55 else
56 global = !(flags & H_LOCAL);
57
58 if (!global) {
59 /* any other core might now have stale TLB entries... */
60 smp_wmb();
61 cpumask_setall(&kvm->arch.need_tlb_flush);
62 cpumask_clear_cpu(local_paca->kvm_hstate.kvm_vcore->pcpu,
63 &kvm->arch.need_tlb_flush);
64 }
65
66 return global;
67}
68
38/* 69/*
39 * Add this HPTE into the chain for the real page. 70 * Add this HPTE into the chain for the real page.
40 * Must be called with the chain locked; it unlocks the chain. 71 * Must be called with the chain locked; it unlocks the chain.
@@ -59,13 +90,24 @@ void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev,
59 head->back = pte_index; 90 head->back = pte_index;
60 } else { 91 } else {
61 rev->forw = rev->back = pte_index; 92 rev->forw = rev->back = pte_index;
62 i = pte_index; 93 *rmap = (*rmap & ~KVMPPC_RMAP_INDEX) |
94 pte_index | KVMPPC_RMAP_PRESENT;
63 } 95 }
64 smp_wmb(); 96 unlock_rmap(rmap);
65 *rmap = i | KVMPPC_RMAP_REFERENCED | KVMPPC_RMAP_PRESENT; /* unlock */
66} 97}
67EXPORT_SYMBOL_GPL(kvmppc_add_revmap_chain); 98EXPORT_SYMBOL_GPL(kvmppc_add_revmap_chain);
68 99
100/*
101 * Note modification of an HPTE; set the HPTE modified bit
102 * if anyone is interested.
103 */
104static inline void note_hpte_modification(struct kvm *kvm,
105 struct revmap_entry *rev)
106{
107 if (atomic_read(&kvm->arch.hpte_mod_interest))
108 rev->guest_rpte |= HPTE_GR_MODIFIED;
109}
110
69/* Remove this HPTE from the chain for a real page */ 111/* Remove this HPTE from the chain for a real page */
70static void remove_revmap_chain(struct kvm *kvm, long pte_index, 112static void remove_revmap_chain(struct kvm *kvm, long pte_index,
71 struct revmap_entry *rev, 113 struct revmap_entry *rev,
@@ -81,7 +123,7 @@ static void remove_revmap_chain(struct kvm *kvm, long pte_index,
81 ptel = rev->guest_rpte |= rcbits; 123 ptel = rev->guest_rpte |= rcbits;
82 gfn = hpte_rpn(ptel, hpte_page_size(hpte_v, ptel)); 124 gfn = hpte_rpn(ptel, hpte_page_size(hpte_v, ptel));
83 memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn); 125 memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn);
84 if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) 126 if (!memslot)
85 return; 127 return;
86 128
87 rmap = real_vmalloc_addr(&memslot->arch.rmap[gfn - memslot->base_gfn]); 129 rmap = real_vmalloc_addr(&memslot->arch.rmap[gfn - memslot->base_gfn]);
@@ -103,14 +145,14 @@ static void remove_revmap_chain(struct kvm *kvm, long pte_index,
103 unlock_rmap(rmap); 145 unlock_rmap(rmap);
104} 146}
105 147
106static pte_t lookup_linux_pte(struct kvm_vcpu *vcpu, unsigned long hva, 148static pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva,
107 int writing, unsigned long *pte_sizep) 149 int writing, unsigned long *pte_sizep)
108{ 150{
109 pte_t *ptep; 151 pte_t *ptep;
110 unsigned long ps = *pte_sizep; 152 unsigned long ps = *pte_sizep;
111 unsigned int shift; 153 unsigned int shift;
112 154
113 ptep = find_linux_pte_or_hugepte(vcpu->arch.pgdir, hva, &shift); 155 ptep = find_linux_pte_or_hugepte(pgdir, hva, &shift);
114 if (!ptep) 156 if (!ptep)
115 return __pte(0); 157 return __pte(0);
116 if (shift) 158 if (shift)
@@ -130,15 +172,15 @@ static inline void unlock_hpte(unsigned long *hpte, unsigned long hpte_v)
130 hpte[0] = hpte_v; 172 hpte[0] = hpte_v;
131} 173}
132 174
133long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, 175long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
134 long pte_index, unsigned long pteh, unsigned long ptel) 176 long pte_index, unsigned long pteh, unsigned long ptel,
177 pgd_t *pgdir, bool realmode, unsigned long *pte_idx_ret)
135{ 178{
136 struct kvm *kvm = vcpu->kvm;
137 unsigned long i, pa, gpa, gfn, psize; 179 unsigned long i, pa, gpa, gfn, psize;
138 unsigned long slot_fn, hva; 180 unsigned long slot_fn, hva;
139 unsigned long *hpte; 181 unsigned long *hpte;
140 struct revmap_entry *rev; 182 struct revmap_entry *rev;
141 unsigned long g_ptel = ptel; 183 unsigned long g_ptel;
142 struct kvm_memory_slot *memslot; 184 struct kvm_memory_slot *memslot;
143 unsigned long *physp, pte_size; 185 unsigned long *physp, pte_size;
144 unsigned long is_io; 186 unsigned long is_io;
@@ -147,13 +189,14 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
147 unsigned int writing; 189 unsigned int writing;
148 unsigned long mmu_seq; 190 unsigned long mmu_seq;
149 unsigned long rcbits; 191 unsigned long rcbits;
150 bool realmode = vcpu->arch.vcore->vcore_state == VCORE_RUNNING;
151 192
152 psize = hpte_page_size(pteh, ptel); 193 psize = hpte_page_size(pteh, ptel);
153 if (!psize) 194 if (!psize)
154 return H_PARAMETER; 195 return H_PARAMETER;
155 writing = hpte_is_writable(ptel); 196 writing = hpte_is_writable(ptel);
156 pteh &= ~(HPTE_V_HVLOCK | HPTE_V_ABSENT | HPTE_V_VALID); 197 pteh &= ~(HPTE_V_HVLOCK | HPTE_V_ABSENT | HPTE_V_VALID);
198 ptel &= ~HPTE_GR_RESERVED;
199 g_ptel = ptel;
157 200
158 /* used later to detect if we might have been invalidated */ 201 /* used later to detect if we might have been invalidated */
159 mmu_seq = kvm->mmu_notifier_seq; 202 mmu_seq = kvm->mmu_notifier_seq;
@@ -183,7 +226,7 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
183 rmap = &memslot->arch.rmap[slot_fn]; 226 rmap = &memslot->arch.rmap[slot_fn];
184 227
185 if (!kvm->arch.using_mmu_notifiers) { 228 if (!kvm->arch.using_mmu_notifiers) {
186 physp = kvm->arch.slot_phys[memslot->id]; 229 physp = memslot->arch.slot_phys;
187 if (!physp) 230 if (!physp)
188 return H_PARAMETER; 231 return H_PARAMETER;
189 physp += slot_fn; 232 physp += slot_fn;
@@ -201,7 +244,7 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
201 244
202 /* Look up the Linux PTE for the backing page */ 245 /* Look up the Linux PTE for the backing page */
203 pte_size = psize; 246 pte_size = psize;
204 pte = lookup_linux_pte(vcpu, hva, writing, &pte_size); 247 pte = lookup_linux_pte(pgdir, hva, writing, &pte_size);
205 if (pte_present(pte)) { 248 if (pte_present(pte)) {
206 if (writing && !pte_write(pte)) 249 if (writing && !pte_write(pte))
207 /* make the actual HPTE be read-only */ 250 /* make the actual HPTE be read-only */
@@ -210,6 +253,7 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
210 pa = pte_pfn(pte) << PAGE_SHIFT; 253 pa = pte_pfn(pte) << PAGE_SHIFT;
211 } 254 }
212 } 255 }
256
213 if (pte_size < psize) 257 if (pte_size < psize)
214 return H_PARAMETER; 258 return H_PARAMETER;
215 if (pa && pte_size > psize) 259 if (pa && pte_size > psize)
@@ -287,8 +331,10 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
287 rev = &kvm->arch.revmap[pte_index]; 331 rev = &kvm->arch.revmap[pte_index];
288 if (realmode) 332 if (realmode)
289 rev = real_vmalloc_addr(rev); 333 rev = real_vmalloc_addr(rev);
290 if (rev) 334 if (rev) {
291 rev->guest_rpte = g_ptel; 335 rev->guest_rpte = g_ptel;
336 note_hpte_modification(kvm, rev);
337 }
292 338
293 /* Link HPTE into reverse-map chain */ 339 /* Link HPTE into reverse-map chain */
294 if (pteh & HPTE_V_VALID) { 340 if (pteh & HPTE_V_VALID) {
@@ -297,7 +343,7 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
297 lock_rmap(rmap); 343 lock_rmap(rmap);
298 /* Check for pending invalidations under the rmap chain lock */ 344 /* Check for pending invalidations under the rmap chain lock */
299 if (kvm->arch.using_mmu_notifiers && 345 if (kvm->arch.using_mmu_notifiers &&
300 mmu_notifier_retry(vcpu, mmu_seq)) { 346 mmu_notifier_retry(kvm, mmu_seq)) {
301 /* inval in progress, write a non-present HPTE */ 347 /* inval in progress, write a non-present HPTE */
302 pteh |= HPTE_V_ABSENT; 348 pteh |= HPTE_V_ABSENT;
303 pteh &= ~HPTE_V_VALID; 349 pteh &= ~HPTE_V_VALID;
@@ -318,10 +364,17 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
318 hpte[0] = pteh; 364 hpte[0] = pteh;
319 asm volatile("ptesync" : : : "memory"); 365 asm volatile("ptesync" : : : "memory");
320 366
321 vcpu->arch.gpr[4] = pte_index; 367 *pte_idx_ret = pte_index;
322 return H_SUCCESS; 368 return H_SUCCESS;
323} 369}
324EXPORT_SYMBOL_GPL(kvmppc_h_enter); 370EXPORT_SYMBOL_GPL(kvmppc_do_h_enter);
371
372long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
373 long pte_index, unsigned long pteh, unsigned long ptel)
374{
375 return kvmppc_do_h_enter(vcpu->kvm, flags, pte_index, pteh, ptel,
376 vcpu->arch.pgdir, true, &vcpu->arch.gpr[4]);
377}
325 378
326#define LOCK_TOKEN (*(u32 *)(&get_paca()->lock_token)) 379#define LOCK_TOKEN (*(u32 *)(&get_paca()->lock_token))
327 380
@@ -343,11 +396,10 @@ static inline int try_lock_tlbie(unsigned int *lock)
343 return old == 0; 396 return old == 0;
344} 397}
345 398
346long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags, 399long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
347 unsigned long pte_index, unsigned long avpn, 400 unsigned long pte_index, unsigned long avpn,
348 unsigned long va) 401 unsigned long *hpret)
349{ 402{
350 struct kvm *kvm = vcpu->kvm;
351 unsigned long *hpte; 403 unsigned long *hpte;
352 unsigned long v, r, rb; 404 unsigned long v, r, rb;
353 struct revmap_entry *rev; 405 struct revmap_entry *rev;
@@ -369,7 +421,7 @@ long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,
369 if (v & HPTE_V_VALID) { 421 if (v & HPTE_V_VALID) {
370 hpte[0] &= ~HPTE_V_VALID; 422 hpte[0] &= ~HPTE_V_VALID;
371 rb = compute_tlbie_rb(v, hpte[1], pte_index); 423 rb = compute_tlbie_rb(v, hpte[1], pte_index);
372 if (!(flags & H_LOCAL) && atomic_read(&kvm->online_vcpus) > 1) { 424 if (global_invalidates(kvm, flags)) {
373 while (!try_lock_tlbie(&kvm->arch.tlbie_lock)) 425 while (!try_lock_tlbie(&kvm->arch.tlbie_lock))
374 cpu_relax(); 426 cpu_relax();
375 asm volatile("ptesync" : : : "memory"); 427 asm volatile("ptesync" : : : "memory");
@@ -385,13 +437,22 @@ long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,
385 /* Read PTE low word after tlbie to get final R/C values */ 437 /* Read PTE low word after tlbie to get final R/C values */
386 remove_revmap_chain(kvm, pte_index, rev, v, hpte[1]); 438 remove_revmap_chain(kvm, pte_index, rev, v, hpte[1]);
387 } 439 }
388 r = rev->guest_rpte; 440 r = rev->guest_rpte & ~HPTE_GR_RESERVED;
441 note_hpte_modification(kvm, rev);
389 unlock_hpte(hpte, 0); 442 unlock_hpte(hpte, 0);
390 443
391 vcpu->arch.gpr[4] = v; 444 hpret[0] = v;
392 vcpu->arch.gpr[5] = r; 445 hpret[1] = r;
393 return H_SUCCESS; 446 return H_SUCCESS;
394} 447}
448EXPORT_SYMBOL_GPL(kvmppc_do_h_remove);
449
450long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,
451 unsigned long pte_index, unsigned long avpn)
452{
453 return kvmppc_do_h_remove(vcpu->kvm, flags, pte_index, avpn,
454 &vcpu->arch.gpr[4]);
455}
395 456
396long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu) 457long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu)
397{ 458{
@@ -459,6 +520,7 @@ long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu)
459 520
460 args[j] = ((0x80 | flags) << 56) + pte_index; 521 args[j] = ((0x80 | flags) << 56) + pte_index;
461 rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]); 522 rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]);
523 note_hpte_modification(kvm, rev);
462 524
463 if (!(hp[0] & HPTE_V_VALID)) { 525 if (!(hp[0] & HPTE_V_VALID)) {
464 /* insert R and C bits from PTE */ 526 /* insert R and C bits from PTE */
@@ -534,8 +596,6 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
534 return H_NOT_FOUND; 596 return H_NOT_FOUND;
535 } 597 }
536 598
537 if (atomic_read(&kvm->online_vcpus) == 1)
538 flags |= H_LOCAL;
539 v = hpte[0]; 599 v = hpte[0];
540 bits = (flags << 55) & HPTE_R_PP0; 600 bits = (flags << 55) & HPTE_R_PP0;
541 bits |= (flags << 48) & HPTE_R_KEY_HI; 601 bits |= (flags << 48) & HPTE_R_KEY_HI;
@@ -548,6 +608,7 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
548 if (rev) { 608 if (rev) {
549 r = (rev->guest_rpte & ~mask) | bits; 609 r = (rev->guest_rpte & ~mask) | bits;
550 rev->guest_rpte = r; 610 rev->guest_rpte = r;
611 note_hpte_modification(kvm, rev);
551 } 612 }
552 r = (hpte[1] & ~mask) | bits; 613 r = (hpte[1] & ~mask) | bits;
553 614
@@ -555,7 +616,7 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
555 if (v & HPTE_V_VALID) { 616 if (v & HPTE_V_VALID) {
556 rb = compute_tlbie_rb(v, r, pte_index); 617 rb = compute_tlbie_rb(v, r, pte_index);
557 hpte[0] = v & ~HPTE_V_VALID; 618 hpte[0] = v & ~HPTE_V_VALID;
558 if (!(flags & H_LOCAL)) { 619 if (global_invalidates(kvm, flags)) {
559 while(!try_lock_tlbie(&kvm->arch.tlbie_lock)) 620 while(!try_lock_tlbie(&kvm->arch.tlbie_lock))
560 cpu_relax(); 621 cpu_relax();
561 asm volatile("ptesync" : : : "memory"); 622 asm volatile("ptesync" : : : "memory");
@@ -568,6 +629,28 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
568 asm volatile("tlbiel %0" : : "r" (rb)); 629 asm volatile("tlbiel %0" : : "r" (rb));
569 asm volatile("ptesync" : : : "memory"); 630 asm volatile("ptesync" : : : "memory");
570 } 631 }
632 /*
633 * If the host has this page as readonly but the guest
634 * wants to make it read/write, reduce the permissions.
635 * Checking the host permissions involves finding the
636 * memslot and then the Linux PTE for the page.
637 */
638 if (hpte_is_writable(r) && kvm->arch.using_mmu_notifiers) {
639 unsigned long psize, gfn, hva;
640 struct kvm_memory_slot *memslot;
641 pgd_t *pgdir = vcpu->arch.pgdir;
642 pte_t pte;
643
644 psize = hpte_page_size(v, r);
645 gfn = ((r & HPTE_R_RPN) & ~(psize - 1)) >> PAGE_SHIFT;
646 memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn);
647 if (memslot) {
648 hva = __gfn_to_hva_memslot(memslot, gfn);
649 pte = lookup_linux_pte(pgdir, hva, 1, &psize);
650 if (pte_present(pte) && !pte_write(pte))
651 r = hpte_make_readonly(r);
652 }
653 }
571 } 654 }
572 hpte[1] = r; 655 hpte[1] = r;
573 eieio(); 656 eieio();
@@ -599,8 +682,10 @@ long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags,
599 v &= ~HPTE_V_ABSENT; 682 v &= ~HPTE_V_ABSENT;
600 v |= HPTE_V_VALID; 683 v |= HPTE_V_VALID;
601 } 684 }
602 if (v & HPTE_V_VALID) 685 if (v & HPTE_V_VALID) {
603 r = rev[i].guest_rpte | (r & (HPTE_R_R | HPTE_R_C)); 686 r = rev[i].guest_rpte | (r & (HPTE_R_R | HPTE_R_C));
687 r &= ~HPTE_GR_RESERVED;
688 }
604 vcpu->arch.gpr[4 + i * 2] = v; 689 vcpu->arch.gpr[4 + i * 2] = v;
605 vcpu->arch.gpr[5 + i * 2] = r; 690 vcpu->arch.gpr[5 + i * 2] = r;
606 } 691 }
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 74a24bbb9637..10b6c358dd77 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -27,6 +27,7 @@
27#include <asm/asm-offsets.h> 27#include <asm/asm-offsets.h>
28#include <asm/exception-64s.h> 28#include <asm/exception-64s.h>
29#include <asm/kvm_book3s_asm.h> 29#include <asm/kvm_book3s_asm.h>
30#include <asm/mmu-hash64.h>
30 31
31/***************************************************************************** 32/*****************************************************************************
32 * * 33 * *
@@ -134,8 +135,11 @@ kvm_start_guest:
134 135
13527: /* XXX should handle hypervisor maintenance interrupts etc. here */ 13627: /* XXX should handle hypervisor maintenance interrupts etc. here */
136 137
138 /* reload vcpu pointer after clearing the IPI */
139 ld r4,HSTATE_KVM_VCPU(r13)
140 cmpdi r4,0
137 /* if we have no vcpu to run, go back to sleep */ 141 /* if we have no vcpu to run, go back to sleep */
138 beq cr1,kvm_no_guest 142 beq kvm_no_guest
139 143
140 /* were we napping due to cede? */ 144 /* were we napping due to cede? */
141 lbz r0,HSTATE_NAPPING(r13) 145 lbz r0,HSTATE_NAPPING(r13)
@@ -310,7 +314,33 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
310 mtspr SPRN_SDR1,r6 /* switch to partition page table */ 314 mtspr SPRN_SDR1,r6 /* switch to partition page table */
311 mtspr SPRN_LPID,r7 315 mtspr SPRN_LPID,r7
312 isync 316 isync
317
318 /* See if we need to flush the TLB */
319 lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */
320 clrldi r7,r6,64-6 /* extract bit number (6 bits) */
321 srdi r6,r6,6 /* doubleword number */
322 sldi r6,r6,3 /* address offset */
323 add r6,r6,r9
324 addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */
313 li r0,1 325 li r0,1
326 sld r0,r0,r7
327 ld r7,0(r6)
328 and. r7,r7,r0
329 beq 22f
33023: ldarx r7,0,r6 /* if set, clear the bit */
331 andc r7,r7,r0
332 stdcx. r7,0,r6
333 bne 23b
334 li r6,128 /* and flush the TLB */
335 mtctr r6
336 li r7,0x800 /* IS field = 0b10 */
337 ptesync
33828: tlbiel r7
339 addi r7,r7,0x1000
340 bdnz 28b
341 ptesync
342
34322: li r0,1
314 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */ 344 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */
315 b 10f 345 b 10f
316 346
@@ -333,36 +363,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
333 mr r9,r4 363 mr r9,r4
334 blt hdec_soon 364 blt hdec_soon
335 365
336 /*
337 * Invalidate the TLB if we could possibly have stale TLB
338 * entries for this partition on this core due to the use
339 * of tlbiel.
340 * XXX maybe only need this on primary thread?
341 */
342 ld r9,VCPU_KVM(r4) /* pointer to struct kvm */
343 lwz r5,VCPU_VCPUID(r4)
344 lhz r6,PACAPACAINDEX(r13)
345 rldimi r6,r5,0,62 /* XXX map as if threads 1:1 p:v */
346 lhz r8,VCPU_LAST_CPU(r4)
347 sldi r7,r6,1 /* see if this is the same vcpu */
348 add r7,r7,r9 /* as last ran on this pcpu */
349 lhz r0,KVM_LAST_VCPU(r7)
350 cmpw r6,r8 /* on the same cpu core as last time? */
351 bne 3f
352 cmpw r0,r5 /* same vcpu as this core last ran? */
353 beq 1f
3543: sth r6,VCPU_LAST_CPU(r4) /* if not, invalidate partition TLB */
355 sth r5,KVM_LAST_VCPU(r7)
356 li r6,128
357 mtctr r6
358 li r7,0x800 /* IS field = 0b10 */
359 ptesync
3602: tlbiel r7
361 addi r7,r7,0x1000
362 bdnz 2b
363 ptesync
3641:
365
366 /* Save purr/spurr */ 366 /* Save purr/spurr */
367 mfspr r5,SPRN_PURR 367 mfspr r5,SPRN_PURR
368 mfspr r6,SPRN_SPURR 368 mfspr r6,SPRN_SPURR
@@ -679,8 +679,7 @@ BEGIN_FTR_SECTION
6791: 6791:
680END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) 680END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
681 681
682nohpte_cont: 682guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */
683hcall_real_cont: /* r9 = vcpu, r12 = trap, r13 = paca */
684 /* Save DEC */ 683 /* Save DEC */
685 mfspr r5,SPRN_DEC 684 mfspr r5,SPRN_DEC
686 mftb r6 685 mftb r6
@@ -701,6 +700,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
701 std r6, VCPU_FAULT_DAR(r9) 700 std r6, VCPU_FAULT_DAR(r9)
702 stw r7, VCPU_FAULT_DSISR(r9) 701 stw r7, VCPU_FAULT_DSISR(r9)
703 702
703 /* See if it is a machine check */
704 cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK
705 beq machine_check_realmode
706mc_cont:
707
704 /* Save guest CTRL register, set runlatch to 1 */ 708 /* Save guest CTRL register, set runlatch to 1 */
7056: mfspr r6,SPRN_CTRLF 7096: mfspr r6,SPRN_CTRLF
706 stw r6,VCPU_CTRL(r9) 710 stw r6,VCPU_CTRL(r9)
@@ -1113,38 +1117,41 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1113 /* 1117 /*
1114 * For external and machine check interrupts, we need 1118 * For external and machine check interrupts, we need
1115 * to call the Linux handler to process the interrupt. 1119 * to call the Linux handler to process the interrupt.
1116 * We do that by jumping to the interrupt vector address 1120 * We do that by jumping to absolute address 0x500 for
1117 * which we have in r12. The [h]rfid at the end of the 1121 * external interrupts, or the machine_check_fwnmi label
1122 * for machine checks (since firmware might have patched
1123 * the vector area at 0x200). The [h]rfid at the end of the
1118 * handler will return to the book3s_hv_interrupts.S code. 1124 * handler will return to the book3s_hv_interrupts.S code.
1119 * For other interrupts we do the rfid to get back 1125 * For other interrupts we do the rfid to get back
1120 * to the book3s_interrupts.S code here. 1126 * to the book3s_hv_interrupts.S code here.
1121 */ 1127 */
1122 ld r8, HSTATE_VMHANDLER(r13) 1128 ld r8, HSTATE_VMHANDLER(r13)
1123 ld r7, HSTATE_HOST_MSR(r13) 1129 ld r7, HSTATE_HOST_MSR(r13)
1124 1130
1131 cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK
1125 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL 1132 cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL
1133BEGIN_FTR_SECTION
1126 beq 11f 1134 beq 11f
1127 cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK 1135END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
1128 1136
1129 /* RFI into the highmem handler, or branch to interrupt handler */ 1137 /* RFI into the highmem handler, or branch to interrupt handler */
113012: mfmsr r6 1138 mfmsr r6
1131 mtctr r12
1132 li r0, MSR_RI 1139 li r0, MSR_RI
1133 andc r6, r6, r0 1140 andc r6, r6, r0
1134 mtmsrd r6, 1 /* Clear RI in MSR */ 1141 mtmsrd r6, 1 /* Clear RI in MSR */
1135 mtsrr0 r8 1142 mtsrr0 r8
1136 mtsrr1 r7 1143 mtsrr1 r7
1137 beqctr 1144 beqa 0x500 /* external interrupt (PPC970) */
1145 beq cr1, 13f /* machine check */
1138 RFI 1146 RFI
1139 1147
114011: 1148 /* On POWER7, we have external interrupts set to use HSRR0/1 */
1141BEGIN_FTR_SECTION 114911: mtspr SPRN_HSRR0, r8
1142 b 12b
1143END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
1144 mtspr SPRN_HSRR0, r8
1145 mtspr SPRN_HSRR1, r7 1150 mtspr SPRN_HSRR1, r7
1146 ba 0x500 1151 ba 0x500
1147 1152
115313: b machine_check_fwnmi
1154
1148/* 1155/*
1149 * Check whether an HDSI is an HPTE not found fault or something else. 1156 * Check whether an HDSI is an HPTE not found fault or something else.
1150 * If it is an HPTE not found fault that is due to the guest accessing 1157 * If it is an HPTE not found fault that is due to the guest accessing
@@ -1177,7 +1184,7 @@ kvmppc_hdsi:
1177 cmpdi r3, 0 /* retry the instruction */ 1184 cmpdi r3, 0 /* retry the instruction */
1178 beq 6f 1185 beq 6f
1179 cmpdi r3, -1 /* handle in kernel mode */ 1186 cmpdi r3, -1 /* handle in kernel mode */
1180 beq nohpte_cont 1187 beq guest_exit_cont
1181 cmpdi r3, -2 /* MMIO emulation; need instr word */ 1188 cmpdi r3, -2 /* MMIO emulation; need instr word */
1182 beq 2f 1189 beq 2f
1183 1190
@@ -1191,6 +1198,7 @@ kvmppc_hdsi:
1191 li r10, BOOK3S_INTERRUPT_DATA_STORAGE 1198 li r10, BOOK3S_INTERRUPT_DATA_STORAGE
1192 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ 1199 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1193 rotldi r11, r11, 63 1200 rotldi r11, r11, 63
1201fast_interrupt_c_return:
11946: ld r7, VCPU_CTR(r9) 12026: ld r7, VCPU_CTR(r9)
1195 lwz r8, VCPU_XER(r9) 1203 lwz r8, VCPU_XER(r9)
1196 mtctr r7 1204 mtctr r7
@@ -1223,7 +1231,7 @@ kvmppc_hdsi:
1223 /* Unset guest mode. */ 1231 /* Unset guest mode. */
1224 li r0, KVM_GUEST_MODE_NONE 1232 li r0, KVM_GUEST_MODE_NONE
1225 stb r0, HSTATE_IN_GUEST(r13) 1233 stb r0, HSTATE_IN_GUEST(r13)
1226 b nohpte_cont 1234 b guest_exit_cont
1227 1235
1228/* 1236/*
1229 * Similarly for an HISI, reflect it to the guest as an ISI unless 1237 * Similarly for an HISI, reflect it to the guest as an ISI unless
@@ -1249,9 +1257,9 @@ kvmppc_hisi:
1249 ld r11, VCPU_MSR(r9) 1257 ld r11, VCPU_MSR(r9)
1250 li r12, BOOK3S_INTERRUPT_H_INST_STORAGE 1258 li r12, BOOK3S_INTERRUPT_H_INST_STORAGE
1251 cmpdi r3, 0 /* retry the instruction */ 1259 cmpdi r3, 0 /* retry the instruction */
1252 beq 6f 1260 beq fast_interrupt_c_return
1253 cmpdi r3, -1 /* handle in kernel mode */ 1261 cmpdi r3, -1 /* handle in kernel mode */
1254 beq nohpte_cont 1262 beq guest_exit_cont
1255 1263
1256 /* Synthesize an ISI for the guest */ 1264 /* Synthesize an ISI for the guest */
1257 mr r11, r3 1265 mr r11, r3
@@ -1260,12 +1268,7 @@ kvmppc_hisi:
1260 li r10, BOOK3S_INTERRUPT_INST_STORAGE 1268 li r10, BOOK3S_INTERRUPT_INST_STORAGE
1261 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ 1269 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1262 rotldi r11, r11, 63 1270 rotldi r11, r11, 63
12636: ld r7, VCPU_CTR(r9) 1271 b fast_interrupt_c_return
1264 lwz r8, VCPU_XER(r9)
1265 mtctr r7
1266 mtxer r8
1267 mr r4, r9
1268 b fast_guest_return
1269 1272
12703: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */ 12733: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */
1271 ld r5, KVM_VRMA_SLB_V(r6) 1274 ld r5, KVM_VRMA_SLB_V(r6)
@@ -1281,14 +1284,14 @@ kvmppc_hisi:
1281hcall_try_real_mode: 1284hcall_try_real_mode:
1282 ld r3,VCPU_GPR(R3)(r9) 1285 ld r3,VCPU_GPR(R3)(r9)
1283 andi. r0,r11,MSR_PR 1286 andi. r0,r11,MSR_PR
1284 bne hcall_real_cont 1287 bne guest_exit_cont
1285 clrrdi r3,r3,2 1288 clrrdi r3,r3,2
1286 cmpldi r3,hcall_real_table_end - hcall_real_table 1289 cmpldi r3,hcall_real_table_end - hcall_real_table
1287 bge hcall_real_cont 1290 bge guest_exit_cont
1288 LOAD_REG_ADDR(r4, hcall_real_table) 1291 LOAD_REG_ADDR(r4, hcall_real_table)
1289 lwzx r3,r3,r4 1292 lwzx r3,r3,r4
1290 cmpwi r3,0 1293 cmpwi r3,0
1291 beq hcall_real_cont 1294 beq guest_exit_cont
1292 add r3,r3,r4 1295 add r3,r3,r4
1293 mtctr r3 1296 mtctr r3
1294 mr r3,r9 /* get vcpu pointer */ 1297 mr r3,r9 /* get vcpu pointer */
@@ -1309,7 +1312,7 @@ hcall_real_fallback:
1309 li r12,BOOK3S_INTERRUPT_SYSCALL 1312 li r12,BOOK3S_INTERRUPT_SYSCALL
1310 ld r9, HSTATE_KVM_VCPU(r13) 1313 ld r9, HSTATE_KVM_VCPU(r13)
1311 1314
1312 b hcall_real_cont 1315 b guest_exit_cont
1313 1316
1314 .globl hcall_real_table 1317 .globl hcall_real_table
1315hcall_real_table: 1318hcall_real_table:
@@ -1568,6 +1571,21 @@ kvm_cede_exit:
1568 li r3,H_TOO_HARD 1571 li r3,H_TOO_HARD
1569 blr 1572 blr
1570 1573
1574 /* Try to handle a machine check in real mode */
1575machine_check_realmode:
1576 mr r3, r9 /* get vcpu pointer */
1577 bl .kvmppc_realmode_machine_check
1578 nop
1579 cmpdi r3, 0 /* continue exiting from guest? */
1580 ld r9, HSTATE_KVM_VCPU(r13)
1581 li r12, BOOK3S_INTERRUPT_MACHINE_CHECK
1582 beq mc_cont
1583 /* If not, deliver a machine check. SRR0/1 are already set */
1584 li r10, BOOK3S_INTERRUPT_MACHINE_CHECK
1585 li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */
1586 rotldi r11, r11, 63
1587 b fast_interrupt_c_return
1588
1571secondary_too_late: 1589secondary_too_late:
1572 ld r5,HSTATE_KVM_VCORE(r13) 1590 ld r5,HSTATE_KVM_VCORE(r13)
1573 HMT_LOW 1591 HMT_LOW
@@ -1587,6 +1605,10 @@ secondary_too_late:
1587 .endr 1605 .endr
1588 1606
1589secondary_nap: 1607secondary_nap:
1608 /* Clear our vcpu pointer so we don't come back in early */
1609 li r0, 0
1610 std r0, HSTATE_KVM_VCPU(r13)
1611 lwsync
1590 /* Clear any pending IPI - assume we're a secondary thread */ 1612 /* Clear any pending IPI - assume we're a secondary thread */
1591 ld r5, HSTATE_XICS_PHYS(r13) 1613 ld r5, HSTATE_XICS_PHYS(r13)
1592 li r7, XICS_XIRR 1614 li r7, XICS_XIRR
@@ -1612,8 +1634,6 @@ secondary_nap:
1612kvm_no_guest: 1634kvm_no_guest:
1613 li r0, KVM_HWTHREAD_IN_NAP 1635 li r0, KVM_HWTHREAD_IN_NAP
1614 stb r0, HSTATE_HWTHREAD_STATE(r13) 1636 stb r0, HSTATE_HWTHREAD_STATE(r13)
1615 li r0, 0
1616 std r0, HSTATE_KVM_VCPU(r13)
1617 1637
1618 li r3, LPCR_PECE0 1638 li r3, LPCR_PECE0
1619 mfspr r4, SPRN_LPCR 1639 mfspr r4, SPRN_LPCR
diff --git a/arch/powerpc/kvm/book3s_mmu_hpte.c b/arch/powerpc/kvm/book3s_mmu_hpte.c
index 41cb0017e757..2c86b0d63714 100644
--- a/arch/powerpc/kvm/book3s_mmu_hpte.c
+++ b/arch/powerpc/kvm/book3s_mmu_hpte.c
@@ -114,11 +114,6 @@ static void invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
114 hlist_del_init_rcu(&pte->list_vpte); 114 hlist_del_init_rcu(&pte->list_vpte);
115 hlist_del_init_rcu(&pte->list_vpte_long); 115 hlist_del_init_rcu(&pte->list_vpte_long);
116 116
117 if (pte->pte.may_write)
118 kvm_release_pfn_dirty(pte->pfn);
119 else
120 kvm_release_pfn_clean(pte->pfn);
121
122 spin_unlock(&vcpu3s->mmu_lock); 117 spin_unlock(&vcpu3s->mmu_lock);
123 118
124 vcpu3s->hpte_cache_count--; 119 vcpu3s->hpte_cache_count--;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 05c28f59f77f..28d38adeca73 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -52,8 +52,6 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,
52#define MSR_USER32 MSR_USER 52#define MSR_USER32 MSR_USER
53#define MSR_USER64 MSR_USER 53#define MSR_USER64 MSR_USER
54#define HW_PAGE_SIZE PAGE_SIZE 54#define HW_PAGE_SIZE PAGE_SIZE
55#define __hard_irq_disable local_irq_disable
56#define __hard_irq_enable local_irq_enable
57#endif 55#endif
58 56
59void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 57void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
@@ -66,7 +64,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
66 svcpu->slb_max = to_book3s(vcpu)->slb_shadow_max; 64 svcpu->slb_max = to_book3s(vcpu)->slb_shadow_max;
67 svcpu_put(svcpu); 65 svcpu_put(svcpu);
68#endif 66#endif
69 67 vcpu->cpu = smp_processor_id();
70#ifdef CONFIG_PPC_BOOK3S_32 68#ifdef CONFIG_PPC_BOOK3S_32
71 current->thread.kvm_shadow_vcpu = to_book3s(vcpu)->shadow_vcpu; 69 current->thread.kvm_shadow_vcpu = to_book3s(vcpu)->shadow_vcpu;
72#endif 70#endif
@@ -83,17 +81,71 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
83 svcpu_put(svcpu); 81 svcpu_put(svcpu);
84#endif 82#endif
85 83
86 kvmppc_giveup_ext(vcpu, MSR_FP); 84 kvmppc_giveup_ext(vcpu, MSR_FP | MSR_VEC | MSR_VSX);
87 kvmppc_giveup_ext(vcpu, MSR_VEC); 85 vcpu->cpu = -1;
88 kvmppc_giveup_ext(vcpu, MSR_VSX); 86}
87
88int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
89{
90 int r = 1; /* Indicate we want to get back into the guest */
91
92 /* We misuse TLB_FLUSH to indicate that we want to clear
93 all shadow cache entries */
94 if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
95 kvmppc_mmu_pte_flush(vcpu, 0, 0);
96
97 return r;
98}
99
100/************* MMU Notifiers *************/
101
102int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
103{
104 trace_kvm_unmap_hva(hva);
105
106 /*
107 * Flush all shadow tlb entries everywhere. This is slow, but
108 * we are 100% sure that we catch the to be unmapped page
109 */
110 kvm_flush_remote_tlbs(kvm);
111
112 return 0;
113}
114
115int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
116{
117 /* kvm_unmap_hva flushes everything anyways */
118 kvm_unmap_hva(kvm, start);
119
120 return 0;
121}
122
123int kvm_age_hva(struct kvm *kvm, unsigned long hva)
124{
125 /* XXX could be more clever ;) */
126 return 0;
127}
128
129int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
130{
131 /* XXX could be more clever ;) */
132 return 0;
89} 133}
90 134
135void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)
136{
137 /* The page will get remapped properly on its next fault */
138 kvm_unmap_hva(kvm, hva);
139}
140
141/*****************************************/
142
91static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu) 143static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)
92{ 144{
93 ulong smsr = vcpu->arch.shared->msr; 145 ulong smsr = vcpu->arch.shared->msr;
94 146
95 /* Guest MSR values */ 147 /* Guest MSR values */
96 smsr &= MSR_FE0 | MSR_FE1 | MSR_SF | MSR_SE | MSR_BE | MSR_DE; 148 smsr &= MSR_FE0 | MSR_FE1 | MSR_SF | MSR_SE | MSR_BE;
97 /* Process MSR values */ 149 /* Process MSR values */
98 smsr |= MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_PR | MSR_EE; 150 smsr |= MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_PR | MSR_EE;
99 /* External providers the guest reserved */ 151 /* External providers the guest reserved */
@@ -379,10 +431,7 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu,
379 431
380static inline int get_fpr_index(int i) 432static inline int get_fpr_index(int i)
381{ 433{
382#ifdef CONFIG_VSX 434 return i * TS_FPRWIDTH;
383 i *= 2;
384#endif
385 return i;
386} 435}
387 436
388/* Give up external provider (FPU, Altivec, VSX) */ 437/* Give up external provider (FPU, Altivec, VSX) */
@@ -396,41 +445,49 @@ void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr)
396 u64 *thread_fpr = (u64*)t->fpr; 445 u64 *thread_fpr = (u64*)t->fpr;
397 int i; 446 int i;
398 447
399 if (!(vcpu->arch.guest_owned_ext & msr)) 448 /*
449 * VSX instructions can access FP and vector registers, so if
450 * we are giving up VSX, make sure we give up FP and VMX as well.
451 */
452 if (msr & MSR_VSX)
453 msr |= MSR_FP | MSR_VEC;
454
455 msr &= vcpu->arch.guest_owned_ext;
456 if (!msr)
400 return; 457 return;
401 458
402#ifdef DEBUG_EXT 459#ifdef DEBUG_EXT
403 printk(KERN_INFO "Giving up ext 0x%lx\n", msr); 460 printk(KERN_INFO "Giving up ext 0x%lx\n", msr);
404#endif 461#endif
405 462
406 switch (msr) { 463 if (msr & MSR_FP) {
407 case MSR_FP: 464 /*
465 * Note that on CPUs with VSX, giveup_fpu stores
466 * both the traditional FP registers and the added VSX
467 * registers into thread.fpr[].
468 */
408 giveup_fpu(current); 469 giveup_fpu(current);
409 for (i = 0; i < ARRAY_SIZE(vcpu->arch.fpr); i++) 470 for (i = 0; i < ARRAY_SIZE(vcpu->arch.fpr); i++)
410 vcpu_fpr[i] = thread_fpr[get_fpr_index(i)]; 471 vcpu_fpr[i] = thread_fpr[get_fpr_index(i)];
411 472
412 vcpu->arch.fpscr = t->fpscr.val; 473 vcpu->arch.fpscr = t->fpscr.val;
413 break; 474
414 case MSR_VEC: 475#ifdef CONFIG_VSX
476 if (cpu_has_feature(CPU_FTR_VSX))
477 for (i = 0; i < ARRAY_SIZE(vcpu->arch.vsr) / 2; i++)
478 vcpu_vsx[i] = thread_fpr[get_fpr_index(i) + 1];
479#endif
480 }
481
415#ifdef CONFIG_ALTIVEC 482#ifdef CONFIG_ALTIVEC
483 if (msr & MSR_VEC) {
416 giveup_altivec(current); 484 giveup_altivec(current);
417 memcpy(vcpu->arch.vr, t->vr, sizeof(vcpu->arch.vr)); 485 memcpy(vcpu->arch.vr, t->vr, sizeof(vcpu->arch.vr));
418 vcpu->arch.vscr = t->vscr; 486 vcpu->arch.vscr = t->vscr;
419#endif
420 break;
421 case MSR_VSX:
422#ifdef CONFIG_VSX
423 __giveup_vsx(current);
424 for (i = 0; i < ARRAY_SIZE(vcpu->arch.vsr); i++)
425 vcpu_vsx[i] = thread_fpr[get_fpr_index(i) + 1];
426#endif
427 break;
428 default:
429 BUG();
430 } 487 }
488#endif
431 489
432 vcpu->arch.guest_owned_ext &= ~msr; 490 vcpu->arch.guest_owned_ext &= ~(msr | MSR_VSX);
433 current->thread.regs->msr &= ~msr;
434 kvmppc_recalc_shadow_msr(vcpu); 491 kvmppc_recalc_shadow_msr(vcpu);
435} 492}
436 493
@@ -490,47 +547,56 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,
490 return RESUME_GUEST; 547 return RESUME_GUEST;
491 } 548 }
492 549
493 /* We already own the ext */ 550 if (msr == MSR_VSX) {
494 if (vcpu->arch.guest_owned_ext & msr) { 551 /* No VSX? Give an illegal instruction interrupt */
495 return RESUME_GUEST; 552#ifdef CONFIG_VSX
553 if (!cpu_has_feature(CPU_FTR_VSX))
554#endif
555 {
556 kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
557 return RESUME_GUEST;
558 }
559
560 /*
561 * We have to load up all the FP and VMX registers before
562 * we can let the guest use VSX instructions.
563 */
564 msr = MSR_FP | MSR_VEC | MSR_VSX;
496 } 565 }
497 566
567 /* See if we already own all the ext(s) needed */
568 msr &= ~vcpu->arch.guest_owned_ext;
569 if (!msr)
570 return RESUME_GUEST;
571
498#ifdef DEBUG_EXT 572#ifdef DEBUG_EXT
499 printk(KERN_INFO "Loading up ext 0x%lx\n", msr); 573 printk(KERN_INFO "Loading up ext 0x%lx\n", msr);
500#endif 574#endif
501 575
502 current->thread.regs->msr |= msr; 576 current->thread.regs->msr |= msr;
503 577
504 switch (msr) { 578 if (msr & MSR_FP) {
505 case MSR_FP:
506 for (i = 0; i < ARRAY_SIZE(vcpu->arch.fpr); i++) 579 for (i = 0; i < ARRAY_SIZE(vcpu->arch.fpr); i++)
507 thread_fpr[get_fpr_index(i)] = vcpu_fpr[i]; 580 thread_fpr[get_fpr_index(i)] = vcpu_fpr[i];
508 581#ifdef CONFIG_VSX
582 for (i = 0; i < ARRAY_SIZE(vcpu->arch.vsr) / 2; i++)
583 thread_fpr[get_fpr_index(i) + 1] = vcpu_vsx[i];
584#endif
509 t->fpscr.val = vcpu->arch.fpscr; 585 t->fpscr.val = vcpu->arch.fpscr;
510 t->fpexc_mode = 0; 586 t->fpexc_mode = 0;
511 kvmppc_load_up_fpu(); 587 kvmppc_load_up_fpu();
512 break; 588 }
513 case MSR_VEC: 589
590 if (msr & MSR_VEC) {
514#ifdef CONFIG_ALTIVEC 591#ifdef CONFIG_ALTIVEC
515 memcpy(t->vr, vcpu->arch.vr, sizeof(vcpu->arch.vr)); 592 memcpy(t->vr, vcpu->arch.vr, sizeof(vcpu->arch.vr));
516 t->vscr = vcpu->arch.vscr; 593 t->vscr = vcpu->arch.vscr;
517 t->vrsave = -1; 594 t->vrsave = -1;
518 kvmppc_load_up_altivec(); 595 kvmppc_load_up_altivec();
519#endif 596#endif
520 break;
521 case MSR_VSX:
522#ifdef CONFIG_VSX
523 for (i = 0; i < ARRAY_SIZE(vcpu->arch.vsr); i++)
524 thread_fpr[get_fpr_index(i) + 1] = vcpu_vsx[i];
525 kvmppc_load_up_vsx();
526#endif
527 break;
528 default:
529 BUG();
530 } 597 }
531 598
532 vcpu->arch.guest_owned_ext |= msr; 599 vcpu->arch.guest_owned_ext |= msr;
533
534 kvmppc_recalc_shadow_msr(vcpu); 600 kvmppc_recalc_shadow_msr(vcpu);
535 601
536 return RESUME_GUEST; 602 return RESUME_GUEST;
@@ -540,18 +606,18 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
540 unsigned int exit_nr) 606 unsigned int exit_nr)
541{ 607{
542 int r = RESUME_HOST; 608 int r = RESUME_HOST;
609 int s;
543 610
544 vcpu->stat.sum_exits++; 611 vcpu->stat.sum_exits++;
545 612
546 run->exit_reason = KVM_EXIT_UNKNOWN; 613 run->exit_reason = KVM_EXIT_UNKNOWN;
547 run->ready_for_interrupt_injection = 1; 614 run->ready_for_interrupt_injection = 1;
548 615
549 /* We get here with MSR.EE=0, so enable it to be a nice citizen */ 616 /* We get here with MSR.EE=1 */
550 __hard_irq_enable(); 617
618 trace_kvm_exit(exit_nr, vcpu);
619 kvm_guest_exit();
551 620
552 trace_kvm_book3s_exit(exit_nr, vcpu);
553 preempt_enable();
554 kvm_resched(vcpu);
555 switch (exit_nr) { 621 switch (exit_nr) {
556 case BOOK3S_INTERRUPT_INST_STORAGE: 622 case BOOK3S_INTERRUPT_INST_STORAGE:
557 { 623 {
@@ -802,7 +868,6 @@ program_interrupt:
802 } 868 }
803 } 869 }
804 870
805 preempt_disable();
806 if (!(r & RESUME_HOST)) { 871 if (!(r & RESUME_HOST)) {
807 /* To avoid clobbering exit_reason, only check for signals if 872 /* To avoid clobbering exit_reason, only check for signals if
808 * we aren't already exiting to userspace for some other 873 * we aren't already exiting to userspace for some other
@@ -814,20 +879,13 @@ program_interrupt:
814 * and if we really did time things so badly, then we just exit 879 * and if we really did time things so badly, then we just exit
815 * again due to a host external interrupt. 880 * again due to a host external interrupt.
816 */ 881 */
817 __hard_irq_disable(); 882 local_irq_disable();
818 if (signal_pending(current)) { 883 s = kvmppc_prepare_to_enter(vcpu);
819 __hard_irq_enable(); 884 if (s <= 0) {
820#ifdef EXIT_DEBUG 885 local_irq_enable();
821 printk(KERN_EMERG "KVM: Going back to host\n"); 886 r = s;
822#endif
823 vcpu->stat.signal_exits++;
824 run->exit_reason = KVM_EXIT_INTR;
825 r = -EINTR;
826 } else { 887 } else {
827 /* In case an interrupt came in that was triggered 888 kvmppc_lazy_ee_enable();
828 * from userspace (like DEC), we need to check what
829 * to inject now! */
830 kvmppc_core_prepare_to_enter(vcpu);
831 } 889 }
832 } 890 }
833 891
@@ -899,34 +957,59 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
899 return 0; 957 return 0;
900} 958}
901 959
902int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 960int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
903{ 961{
904 int r = -EINVAL; 962 int r = 0;
905 963
906 switch (reg->id) { 964 switch (id) {
907 case KVM_REG_PPC_HIOR: 965 case KVM_REG_PPC_HIOR:
908 r = copy_to_user((u64 __user *)(long)reg->addr, 966 *val = get_reg_val(id, to_book3s(vcpu)->hior);
909 &to_book3s(vcpu)->hior, sizeof(u64));
910 break; 967 break;
968#ifdef CONFIG_VSX
969 case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: {
970 long int i = id - KVM_REG_PPC_VSR0;
971
972 if (!cpu_has_feature(CPU_FTR_VSX)) {
973 r = -ENXIO;
974 break;
975 }
976 val->vsxval[0] = vcpu->arch.fpr[i];
977 val->vsxval[1] = vcpu->arch.vsr[i];
978 break;
979 }
980#endif /* CONFIG_VSX */
911 default: 981 default:
982 r = -EINVAL;
912 break; 983 break;
913 } 984 }
914 985
915 return r; 986 return r;
916} 987}
917 988
918int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 989int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)
919{ 990{
920 int r = -EINVAL; 991 int r = 0;
921 992
922 switch (reg->id) { 993 switch (id) {
923 case KVM_REG_PPC_HIOR: 994 case KVM_REG_PPC_HIOR:
924 r = copy_from_user(&to_book3s(vcpu)->hior, 995 to_book3s(vcpu)->hior = set_reg_val(id, *val);
925 (u64 __user *)(long)reg->addr, sizeof(u64)); 996 to_book3s(vcpu)->hior_explicit = true;
926 if (!r) 997 break;
927 to_book3s(vcpu)->hior_explicit = true; 998#ifdef CONFIG_VSX
999 case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: {
1000 long int i = id - KVM_REG_PPC_VSR0;
1001
1002 if (!cpu_has_feature(CPU_FTR_VSX)) {
1003 r = -ENXIO;
1004 break;
1005 }
1006 vcpu->arch.fpr[i] = val->vsxval[0];
1007 vcpu->arch.vsr[i] = val->vsxval[1];
928 break; 1008 break;
1009 }
1010#endif /* CONFIG_VSX */
929 default: 1011 default:
1012 r = -EINVAL;
930 break; 1013 break;
931 } 1014 }
932 1015
@@ -1020,8 +1103,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1020#endif 1103#endif
1021 ulong ext_msr; 1104 ulong ext_msr;
1022 1105
1023 preempt_disable();
1024
1025 /* Check if we can run the vcpu at all */ 1106 /* Check if we can run the vcpu at all */
1026 if (!vcpu->arch.sane) { 1107 if (!vcpu->arch.sane) {
1027 kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1108 kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
@@ -1029,21 +1110,16 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1029 goto out; 1110 goto out;
1030 } 1111 }
1031 1112
1032 kvmppc_core_prepare_to_enter(vcpu);
1033
1034 /* 1113 /*
1035 * Interrupts could be timers for the guest which we have to inject 1114 * Interrupts could be timers for the guest which we have to inject
1036 * again, so let's postpone them until we're in the guest and if we 1115 * again, so let's postpone them until we're in the guest and if we
1037 * really did time things so badly, then we just exit again due to 1116 * really did time things so badly, then we just exit again due to
1038 * a host external interrupt. 1117 * a host external interrupt.
1039 */ 1118 */
1040 __hard_irq_disable(); 1119 local_irq_disable();
1041 1120 ret = kvmppc_prepare_to_enter(vcpu);
1042 /* No need to go into the guest when all we do is going out */ 1121 if (ret <= 0) {
1043 if (signal_pending(current)) { 1122 local_irq_enable();
1044 __hard_irq_enable();
1045 kvm_run->exit_reason = KVM_EXIT_INTR;
1046 ret = -EINTR;
1047 goto out; 1123 goto out;
1048 } 1124 }
1049 1125
@@ -1070,7 +1146,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1070 /* Save VSX state in stack */ 1146 /* Save VSX state in stack */
1071 used_vsr = current->thread.used_vsr; 1147 used_vsr = current->thread.used_vsr;
1072 if (used_vsr && (current->thread.regs->msr & MSR_VSX)) 1148 if (used_vsr && (current->thread.regs->msr & MSR_VSX))
1073 __giveup_vsx(current); 1149 __giveup_vsx(current);
1074#endif 1150#endif
1075 1151
1076 /* Remember the MSR with disabled extensions */ 1152 /* Remember the MSR with disabled extensions */
@@ -1080,20 +1156,19 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1080 if (vcpu->arch.shared->msr & MSR_FP) 1156 if (vcpu->arch.shared->msr & MSR_FP)
1081 kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP); 1157 kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP);
1082 1158
1083 kvm_guest_enter(); 1159 kvmppc_lazy_ee_enable();
1084 1160
1085 ret = __kvmppc_vcpu_run(kvm_run, vcpu); 1161 ret = __kvmppc_vcpu_run(kvm_run, vcpu);
1086 1162
1087 kvm_guest_exit(); 1163 /* No need for kvm_guest_exit. It's done in handle_exit.
1088 1164 We also get here with interrupts enabled. */
1089 current->thread.regs->msr = ext_msr;
1090 1165
1091 /* Make sure we save the guest FPU/Altivec/VSX state */ 1166 /* Make sure we save the guest FPU/Altivec/VSX state */
1092 kvmppc_giveup_ext(vcpu, MSR_FP); 1167 kvmppc_giveup_ext(vcpu, MSR_FP | MSR_VEC | MSR_VSX);
1093 kvmppc_giveup_ext(vcpu, MSR_VEC); 1168
1094 kvmppc_giveup_ext(vcpu, MSR_VSX); 1169 current->thread.regs->msr = ext_msr;
1095 1170
1096 /* Restore FPU state from stack */ 1171 /* Restore FPU/VSX state from stack */
1097 memcpy(current->thread.fpr, fpr, sizeof(current->thread.fpr)); 1172 memcpy(current->thread.fpr, fpr, sizeof(current->thread.fpr));
1098 current->thread.fpscr.val = fpscr; 1173 current->thread.fpscr.val = fpscr;
1099 current->thread.fpexc_mode = fpexc_mode; 1174 current->thread.fpexc_mode = fpexc_mode;
@@ -1113,7 +1188,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1113#endif 1188#endif
1114 1189
1115out: 1190out:
1116 preempt_enable(); 1191 vcpu->mode = OUTSIDE_GUEST_MODE;
1117 return ret; 1192 return ret;
1118} 1193}
1119 1194
@@ -1181,14 +1256,31 @@ int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, struct kvm_ppc_smmu_info *info)
1181} 1256}
1182#endif /* CONFIG_PPC64 */ 1257#endif /* CONFIG_PPC64 */
1183 1258
1259void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
1260 struct kvm_memory_slot *dont)
1261{
1262}
1263
1264int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
1265 unsigned long npages)
1266{
1267 return 0;
1268}
1269
1184int kvmppc_core_prepare_memory_region(struct kvm *kvm, 1270int kvmppc_core_prepare_memory_region(struct kvm *kvm,
1271 struct kvm_memory_slot *memslot,
1185 struct kvm_userspace_memory_region *mem) 1272 struct kvm_userspace_memory_region *mem)
1186{ 1273{
1187 return 0; 1274 return 0;
1188} 1275}
1189 1276
1190void kvmppc_core_commit_memory_region(struct kvm *kvm, 1277void kvmppc_core_commit_memory_region(struct kvm *kvm,
1191 struct kvm_userspace_memory_region *mem) 1278 struct kvm_userspace_memory_region *mem,
1279 struct kvm_memory_slot old)
1280{
1281}
1282
1283void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
1192{ 1284{
1193} 1285}
1194 1286
diff --git a/arch/powerpc/kvm/book3s_rmhandlers.S b/arch/powerpc/kvm/book3s_rmhandlers.S
index 9ecf6e35cd8d..8f7633e3afb8 100644
--- a/arch/powerpc/kvm/book3s_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_rmhandlers.S
@@ -170,20 +170,21 @@ kvmppc_handler_skip_ins:
170 * Call kvmppc_handler_trampoline_enter in real mode 170 * Call kvmppc_handler_trampoline_enter in real mode
171 * 171 *
172 * On entry, r4 contains the guest shadow MSR 172 * On entry, r4 contains the guest shadow MSR
173 * MSR.EE has to be 0 when calling this function
173 */ 174 */
174_GLOBAL(kvmppc_entry_trampoline) 175_GLOBAL(kvmppc_entry_trampoline)
175 mfmsr r5 176 mfmsr r5
176 LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter) 177 LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
177 toreal(r7) 178 toreal(r7)
178 179
179 li r9, MSR_RI
180 ori r9, r9, MSR_EE
181 andc r9, r5, r9 /* Clear EE and RI in MSR value */
182 li r6, MSR_IR | MSR_DR 180 li r6, MSR_IR | MSR_DR
183 ori r6, r6, MSR_EE 181 andc r6, r5, r6 /* Clear DR and IR in MSR value */
184 andc r6, r5, r6 /* Clear EE, DR and IR in MSR value */ 182 /*
185 MTMSR_EERI(r9) /* Clear EE and RI in MSR */ 183 * Set EE in HOST_MSR so that it's enabled when we get into our
186 mtsrr0 r7 /* before we set srr0/1 */ 184 * C exit handler function
185 */
186 ori r5, r5, MSR_EE
187 mtsrr0 r7
187 mtsrr1 r6 188 mtsrr1 r6
188 RFI 189 RFI
189 190
@@ -233,8 +234,5 @@ define_load_up(fpu)
233#ifdef CONFIG_ALTIVEC 234#ifdef CONFIG_ALTIVEC
234define_load_up(altivec) 235define_load_up(altivec)
235#endif 236#endif
236#ifdef CONFIG_VSX
237define_load_up(vsx)
238#endif
239 237
240#include "book3s_segment.S" 238#include "book3s_segment.S"
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index d25a097c852b..69f114015780 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -36,9 +36,11 @@
36#include <asm/dbell.h> 36#include <asm/dbell.h>
37#include <asm/hw_irq.h> 37#include <asm/hw_irq.h>
38#include <asm/irq.h> 38#include <asm/irq.h>
39#include <asm/time.h>
39 40
40#include "timing.h" 41#include "timing.h"
41#include "booke.h" 42#include "booke.h"
43#include "trace.h"
42 44
43unsigned long kvmppc_booke_handlers; 45unsigned long kvmppc_booke_handlers;
44 46
@@ -62,6 +64,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
62 { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 64 { "halt_wakeup", VCPU_STAT(halt_wakeup) },
63 { "doorbell", VCPU_STAT(dbell_exits) }, 65 { "doorbell", VCPU_STAT(dbell_exits) },
64 { "guest doorbell", VCPU_STAT(gdbell_exits) }, 66 { "guest doorbell", VCPU_STAT(gdbell_exits) },
67 { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
65 { NULL } 68 { NULL }
66}; 69};
67 70
@@ -120,6 +123,16 @@ static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu)
120} 123}
121#endif 124#endif
122 125
126static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
127{
128#if defined(CONFIG_PPC_FPU) && !defined(CONFIG_KVM_BOOKE_HV)
129 /* We always treat the FP bit as enabled from the host
130 perspective, so only need to adjust the shadow MSR */
131 vcpu->arch.shadow_msr &= ~MSR_FP;
132 vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_FP;
133#endif
134}
135
123/* 136/*
124 * Helper function for "full" MSR writes. No need to call this if only 137 * Helper function for "full" MSR writes. No need to call this if only
125 * EE/CE/ME/DE/RI are changing. 138 * EE/CE/ME/DE/RI are changing.
@@ -136,11 +149,13 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
136 149
137 kvmppc_mmu_msr_notify(vcpu, old_msr); 150 kvmppc_mmu_msr_notify(vcpu, old_msr);
138 kvmppc_vcpu_sync_spe(vcpu); 151 kvmppc_vcpu_sync_spe(vcpu);
152 kvmppc_vcpu_sync_fpu(vcpu);
139} 153}
140 154
141static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, 155static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
142 unsigned int priority) 156 unsigned int priority)
143{ 157{
158 trace_kvm_booke_queue_irqprio(vcpu, priority);
144 set_bit(priority, &vcpu->arch.pending_exceptions); 159 set_bit(priority, &vcpu->arch.pending_exceptions);
145} 160}
146 161
@@ -206,6 +221,16 @@ void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
206 clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions); 221 clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, &vcpu->arch.pending_exceptions);
207} 222}
208 223
224static void kvmppc_core_queue_watchdog(struct kvm_vcpu *vcpu)
225{
226 kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_WATCHDOG);
227}
228
229static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu *vcpu)
230{
231 clear_bit(BOOKE_IRQPRIO_WATCHDOG, &vcpu->arch.pending_exceptions);
232}
233
209static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1) 234static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
210{ 235{
211#ifdef CONFIG_KVM_BOOKE_HV 236#ifdef CONFIG_KVM_BOOKE_HV
@@ -287,6 +312,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
287 bool crit; 312 bool crit;
288 bool keep_irq = false; 313 bool keep_irq = false;
289 enum int_class int_class; 314 enum int_class int_class;
315 ulong new_msr = vcpu->arch.shared->msr;
290 316
291 /* Truncate crit indicators in 32 bit mode */ 317 /* Truncate crit indicators in 32 bit mode */
292 if (!(vcpu->arch.shared->msr & MSR_SF)) { 318 if (!(vcpu->arch.shared->msr & MSR_SF)) {
@@ -325,6 +351,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
325 msr_mask = MSR_CE | MSR_ME | MSR_DE; 351 msr_mask = MSR_CE | MSR_ME | MSR_DE;
326 int_class = INT_CLASS_NONCRIT; 352 int_class = INT_CLASS_NONCRIT;
327 break; 353 break;
354 case BOOKE_IRQPRIO_WATCHDOG:
328 case BOOKE_IRQPRIO_CRITICAL: 355 case BOOKE_IRQPRIO_CRITICAL:
329 case BOOKE_IRQPRIO_DBELL_CRIT: 356 case BOOKE_IRQPRIO_DBELL_CRIT:
330 allowed = vcpu->arch.shared->msr & MSR_CE; 357 allowed = vcpu->arch.shared->msr & MSR_CE;
@@ -381,7 +408,13 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
381 set_guest_esr(vcpu, vcpu->arch.queued_esr); 408 set_guest_esr(vcpu, vcpu->arch.queued_esr);
382 if (update_dear == true) 409 if (update_dear == true)
383 set_guest_dear(vcpu, vcpu->arch.queued_dear); 410 set_guest_dear(vcpu, vcpu->arch.queued_dear);
384 kvmppc_set_msr(vcpu, vcpu->arch.shared->msr & msr_mask); 411
412 new_msr &= msr_mask;
413#if defined(CONFIG_64BIT)
414 if (vcpu->arch.epcr & SPRN_EPCR_ICM)
415 new_msr |= MSR_CM;
416#endif
417 kvmppc_set_msr(vcpu, new_msr);
385 418
386 if (!keep_irq) 419 if (!keep_irq)
387 clear_bit(priority, &vcpu->arch.pending_exceptions); 420 clear_bit(priority, &vcpu->arch.pending_exceptions);
@@ -404,12 +437,121 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
404 return allowed; 437 return allowed;
405} 438}
406 439
440/*
441 * Return the number of jiffies until the next timeout. If the timeout is
442 * longer than the NEXT_TIMER_MAX_DELTA, then return NEXT_TIMER_MAX_DELTA
443 * because the larger value can break the timer APIs.
444 */
445static unsigned long watchdog_next_timeout(struct kvm_vcpu *vcpu)
446{
447 u64 tb, wdt_tb, wdt_ticks = 0;
448 u64 nr_jiffies = 0;
449 u32 period = TCR_GET_WP(vcpu->arch.tcr);
450
451 wdt_tb = 1ULL << (63 - period);
452 tb = get_tb();
453 /*
454 * The watchdog timeout will hapeen when TB bit corresponding
455 * to watchdog will toggle from 0 to 1.
456 */
457 if (tb & wdt_tb)
458 wdt_ticks = wdt_tb;
459
460 wdt_ticks += wdt_tb - (tb & (wdt_tb - 1));
461
462 /* Convert timebase ticks to jiffies */
463 nr_jiffies = wdt_ticks;
464
465 if (do_div(nr_jiffies, tb_ticks_per_jiffy))
466 nr_jiffies++;
467
468 return min_t(unsigned long long, nr_jiffies, NEXT_TIMER_MAX_DELTA);
469}
470
471static void arm_next_watchdog(struct kvm_vcpu *vcpu)
472{
473 unsigned long nr_jiffies;
474 unsigned long flags;
475
476 /*
477 * If TSR_ENW and TSR_WIS are not set then no need to exit to
478 * userspace, so clear the KVM_REQ_WATCHDOG request.
479 */
480 if ((vcpu->arch.tsr & (TSR_ENW | TSR_WIS)) != (TSR_ENW | TSR_WIS))
481 clear_bit(KVM_REQ_WATCHDOG, &vcpu->requests);
482
483 spin_lock_irqsave(&vcpu->arch.wdt_lock, flags);
484 nr_jiffies = watchdog_next_timeout(vcpu);
485 /*
486 * If the number of jiffies of watchdog timer >= NEXT_TIMER_MAX_DELTA
487 * then do not run the watchdog timer as this can break timer APIs.
488 */
489 if (nr_jiffies < NEXT_TIMER_MAX_DELTA)
490 mod_timer(&vcpu->arch.wdt_timer, jiffies + nr_jiffies);
491 else
492 del_timer(&vcpu->arch.wdt_timer);
493 spin_unlock_irqrestore(&vcpu->arch.wdt_lock, flags);
494}
495
496void kvmppc_watchdog_func(unsigned long data)
497{
498 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
499 u32 tsr, new_tsr;
500 int final;
501
502 do {
503 new_tsr = tsr = vcpu->arch.tsr;
504 final = 0;
505
506 /* Time out event */
507 if (tsr & TSR_ENW) {
508 if (tsr & TSR_WIS)
509 final = 1;
510 else
511 new_tsr = tsr | TSR_WIS;
512 } else {
513 new_tsr = tsr | TSR_ENW;
514 }
515 } while (cmpxchg(&vcpu->arch.tsr, tsr, new_tsr) != tsr);
516
517 if (new_tsr & TSR_WIS) {
518 smp_wmb();
519 kvm_make_request(KVM_REQ_PENDING_TIMER, vcpu);
520 kvm_vcpu_kick(vcpu);
521 }
522
523 /*
524 * If this is final watchdog expiry and some action is required
525 * then exit to userspace.
526 */
527 if (final && (vcpu->arch.tcr & TCR_WRC_MASK) &&
528 vcpu->arch.watchdog_enabled) {
529 smp_wmb();
530 kvm_make_request(KVM_REQ_WATCHDOG, vcpu);
531 kvm_vcpu_kick(vcpu);
532 }
533
534 /*
535 * Stop running the watchdog timer after final expiration to
536 * prevent the host from being flooded with timers if the
537 * guest sets a short period.
538 * Timers will resume when TSR/TCR is updated next time.
539 */
540 if (!final)
541 arm_next_watchdog(vcpu);
542}
543
407static void update_timer_ints(struct kvm_vcpu *vcpu) 544static void update_timer_ints(struct kvm_vcpu *vcpu)
408{ 545{
409 if ((vcpu->arch.tcr & TCR_DIE) && (vcpu->arch.tsr & TSR_DIS)) 546 if ((vcpu->arch.tcr & TCR_DIE) && (vcpu->arch.tsr & TSR_DIS))
410 kvmppc_core_queue_dec(vcpu); 547 kvmppc_core_queue_dec(vcpu);
411 else 548 else
412 kvmppc_core_dequeue_dec(vcpu); 549 kvmppc_core_dequeue_dec(vcpu);
550
551 if ((vcpu->arch.tcr & TCR_WIE) && (vcpu->arch.tsr & TSR_WIS))
552 kvmppc_core_queue_watchdog(vcpu);
553 else
554 kvmppc_core_dequeue_watchdog(vcpu);
413} 555}
414 556
415static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) 557static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu)
@@ -417,13 +559,6 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu)
417 unsigned long *pending = &vcpu->arch.pending_exceptions; 559 unsigned long *pending = &vcpu->arch.pending_exceptions;
418 unsigned int priority; 560 unsigned int priority;
419 561
420 if (vcpu->requests) {
421 if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
422 smp_mb();
423 update_timer_ints(vcpu);
424 }
425 }
426
427 priority = __ffs(*pending); 562 priority = __ffs(*pending);
428 while (priority < BOOKE_IRQPRIO_MAX) { 563 while (priority < BOOKE_IRQPRIO_MAX) {
429 if (kvmppc_booke_irqprio_deliver(vcpu, priority)) 564 if (kvmppc_booke_irqprio_deliver(vcpu, priority))
@@ -459,37 +594,20 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
459 return r; 594 return r;
460} 595}
461 596
462/* 597int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
463 * Common checks before entering the guest world. Call with interrupts
464 * disabled.
465 *
466 * returns !0 if a signal is pending and check_signal is true
467 */
468static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
469{ 598{
470 int r = 0; 599 int r = 1; /* Indicate we want to get back into the guest */
471 600
472 WARN_ON_ONCE(!irqs_disabled()); 601 if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
473 while (true) { 602 update_timer_ints(vcpu);
474 if (need_resched()) { 603#if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
475 local_irq_enable(); 604 if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
476 cond_resched(); 605 kvmppc_core_flush_tlb(vcpu);
477 local_irq_disable(); 606#endif
478 continue;
479 }
480
481 if (signal_pending(current)) {
482 r = 1;
483 break;
484 }
485
486 if (kvmppc_core_prepare_to_enter(vcpu)) {
487 /* interrupts got enabled in between, so we
488 are back at square 1 */
489 continue;
490 }
491 607
492 break; 608 if (kvm_check_request(KVM_REQ_WATCHDOG, vcpu)) {
609 vcpu->run->exit_reason = KVM_EXIT_WATCHDOG;
610 r = 0;
493 } 611 }
494 612
495 return r; 613 return r;
@@ -497,7 +615,7 @@ static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
497 615
498int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 616int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
499{ 617{
500 int ret; 618 int ret, s;
501#ifdef CONFIG_PPC_FPU 619#ifdef CONFIG_PPC_FPU
502 unsigned int fpscr; 620 unsigned int fpscr;
503 int fpexc_mode; 621 int fpexc_mode;
@@ -510,11 +628,13 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
510 } 628 }
511 629
512 local_irq_disable(); 630 local_irq_disable();
513 if (kvmppc_prepare_to_enter(vcpu)) { 631 s = kvmppc_prepare_to_enter(vcpu);
514 kvm_run->exit_reason = KVM_EXIT_INTR; 632 if (s <= 0) {
515 ret = -EINTR; 633 local_irq_enable();
634 ret = s;
516 goto out; 635 goto out;
517 } 636 }
637 kvmppc_lazy_ee_enable();
518 638
519 kvm_guest_enter(); 639 kvm_guest_enter();
520 640
@@ -542,6 +662,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
542 662
543 ret = __kvmppc_vcpu_run(kvm_run, vcpu); 663 ret = __kvmppc_vcpu_run(kvm_run, vcpu);
544 664
665 /* No need for kvm_guest_exit. It's done in handle_exit.
666 We also get here with interrupts enabled. */
667
545#ifdef CONFIG_PPC_FPU 668#ifdef CONFIG_PPC_FPU
546 kvmppc_save_guest_fp(vcpu); 669 kvmppc_save_guest_fp(vcpu);
547 670
@@ -557,10 +680,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
557 current->thread.fpexc_mode = fpexc_mode; 680 current->thread.fpexc_mode = fpexc_mode;
558#endif 681#endif
559 682
560 kvm_guest_exit();
561
562out: 683out:
563 local_irq_enable(); 684 vcpu->mode = OUTSIDE_GUEST_MODE;
564 return ret; 685 return ret;
565} 686}
566 687
@@ -668,6 +789,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
668 unsigned int exit_nr) 789 unsigned int exit_nr)
669{ 790{
670 int r = RESUME_HOST; 791 int r = RESUME_HOST;
792 int s;
671 793
672 /* update before a new last_exit_type is rewritten */ 794 /* update before a new last_exit_type is rewritten */
673 kvmppc_update_timing_stats(vcpu); 795 kvmppc_update_timing_stats(vcpu);
@@ -677,6 +799,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
677 799
678 local_irq_enable(); 800 local_irq_enable();
679 801
802 trace_kvm_exit(exit_nr, vcpu);
803 kvm_guest_exit();
804
680 run->exit_reason = KVM_EXIT_UNKNOWN; 805 run->exit_reason = KVM_EXIT_UNKNOWN;
681 run->ready_for_interrupt_injection = 1; 806 run->ready_for_interrupt_injection = 1;
682 807
@@ -971,10 +1096,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
971 */ 1096 */
972 if (!(r & RESUME_HOST)) { 1097 if (!(r & RESUME_HOST)) {
973 local_irq_disable(); 1098 local_irq_disable();
974 if (kvmppc_prepare_to_enter(vcpu)) { 1099 s = kvmppc_prepare_to_enter(vcpu);
975 run->exit_reason = KVM_EXIT_INTR; 1100 if (s <= 0) {
976 r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); 1101 local_irq_enable();
977 kvmppc_account_exit(vcpu, SIGNAL_EXITS); 1102 r = (s << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
1103 } else {
1104 kvmppc_lazy_ee_enable();
978 } 1105 }
979 } 1106 }
980 1107
@@ -1011,6 +1138,21 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
1011 return r; 1138 return r;
1012} 1139}
1013 1140
1141int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu)
1142{
1143 /* setup watchdog timer once */
1144 spin_lock_init(&vcpu->arch.wdt_lock);
1145 setup_timer(&vcpu->arch.wdt_timer, kvmppc_watchdog_func,
1146 (unsigned long)vcpu);
1147
1148 return 0;
1149}
1150
1151void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu)
1152{
1153 del_timer_sync(&vcpu->arch.wdt_timer);
1154}
1155
1014int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 1156int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
1015{ 1157{
1016 int i; 1158 int i;
@@ -1106,7 +1248,13 @@ static int set_sregs_base(struct kvm_vcpu *vcpu,
1106 } 1248 }
1107 1249
1108 if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) { 1250 if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_TSR) {
1251 u32 old_tsr = vcpu->arch.tsr;
1252
1109 vcpu->arch.tsr = sregs->u.e.tsr; 1253 vcpu->arch.tsr = sregs->u.e.tsr;
1254
1255 if ((old_tsr ^ vcpu->arch.tsr) & (TSR_ENW | TSR_WIS))
1256 arm_next_watchdog(vcpu);
1257
1110 update_timer_ints(vcpu); 1258 update_timer_ints(vcpu);
1111 } 1259 }
1112 1260
@@ -1221,12 +1369,70 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
1221 1369
1222int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 1370int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
1223{ 1371{
1224 return -EINVAL; 1372 int r = -EINVAL;
1373
1374 switch (reg->id) {
1375 case KVM_REG_PPC_IAC1:
1376 case KVM_REG_PPC_IAC2:
1377 case KVM_REG_PPC_IAC3:
1378 case KVM_REG_PPC_IAC4: {
1379 int iac = reg->id - KVM_REG_PPC_IAC1;
1380 r = copy_to_user((u64 __user *)(long)reg->addr,
1381 &vcpu->arch.dbg_reg.iac[iac], sizeof(u64));
1382 break;
1383 }
1384 case KVM_REG_PPC_DAC1:
1385 case KVM_REG_PPC_DAC2: {
1386 int dac = reg->id - KVM_REG_PPC_DAC1;
1387 r = copy_to_user((u64 __user *)(long)reg->addr,
1388 &vcpu->arch.dbg_reg.dac[dac], sizeof(u64));
1389 break;
1390 }
1391#if defined(CONFIG_64BIT)
1392 case KVM_REG_PPC_EPCR:
1393 r = put_user(vcpu->arch.epcr, (u32 __user *)(long)reg->addr);
1394 break;
1395#endif
1396 default:
1397 break;
1398 }
1399 return r;
1225} 1400}
1226 1401
1227int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) 1402int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
1228{ 1403{
1229 return -EINVAL; 1404 int r = -EINVAL;
1405
1406 switch (reg->id) {
1407 case KVM_REG_PPC_IAC1:
1408 case KVM_REG_PPC_IAC2:
1409 case KVM_REG_PPC_IAC3:
1410 case KVM_REG_PPC_IAC4: {
1411 int iac = reg->id - KVM_REG_PPC_IAC1;
1412 r = copy_from_user(&vcpu->arch.dbg_reg.iac[iac],
1413 (u64 __user *)(long)reg->addr, sizeof(u64));
1414 break;
1415 }
1416 case KVM_REG_PPC_DAC1:
1417 case KVM_REG_PPC_DAC2: {
1418 int dac = reg->id - KVM_REG_PPC_DAC1;
1419 r = copy_from_user(&vcpu->arch.dbg_reg.dac[dac],
1420 (u64 __user *)(long)reg->addr, sizeof(u64));
1421 break;
1422 }
1423#if defined(CONFIG_64BIT)
1424 case KVM_REG_PPC_EPCR: {
1425 u32 new_epcr;
1426 r = get_user(new_epcr, (u32 __user *)(long)reg->addr);
1427 if (r == 0)
1428 kvmppc_set_epcr(vcpu, new_epcr);
1429 break;
1430 }
1431#endif
1432 default:
1433 break;
1434 }
1435 return r;
1230} 1436}
1231 1437
1232int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 1438int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
@@ -1253,20 +1459,50 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
1253 return -ENOTSUPP; 1459 return -ENOTSUPP;
1254} 1460}
1255 1461
1462void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
1463 struct kvm_memory_slot *dont)
1464{
1465}
1466
1467int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
1468 unsigned long npages)
1469{
1470 return 0;
1471}
1472
1256int kvmppc_core_prepare_memory_region(struct kvm *kvm, 1473int kvmppc_core_prepare_memory_region(struct kvm *kvm,
1474 struct kvm_memory_slot *memslot,
1257 struct kvm_userspace_memory_region *mem) 1475 struct kvm_userspace_memory_region *mem)
1258{ 1476{
1259 return 0; 1477 return 0;
1260} 1478}
1261 1479
1262void kvmppc_core_commit_memory_region(struct kvm *kvm, 1480void kvmppc_core_commit_memory_region(struct kvm *kvm,
1263 struct kvm_userspace_memory_region *mem) 1481 struct kvm_userspace_memory_region *mem,
1482 struct kvm_memory_slot old)
1483{
1484}
1485
1486void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
1487{
1488}
1489
1490void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr)
1264{ 1491{
1492#if defined(CONFIG_64BIT)
1493 vcpu->arch.epcr = new_epcr;
1494#ifdef CONFIG_KVM_BOOKE_HV
1495 vcpu->arch.shadow_epcr &= ~SPRN_EPCR_GICM;
1496 if (vcpu->arch.epcr & SPRN_EPCR_ICM)
1497 vcpu->arch.shadow_epcr |= SPRN_EPCR_GICM;
1498#endif
1499#endif
1265} 1500}
1266 1501
1267void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr) 1502void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr)
1268{ 1503{
1269 vcpu->arch.tcr = new_tcr; 1504 vcpu->arch.tcr = new_tcr;
1505 arm_next_watchdog(vcpu);
1270 update_timer_ints(vcpu); 1506 update_timer_ints(vcpu);
1271} 1507}
1272 1508
@@ -1281,6 +1517,14 @@ void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits)
1281void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits) 1517void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits)
1282{ 1518{
1283 clear_bits(tsr_bits, &vcpu->arch.tsr); 1519 clear_bits(tsr_bits, &vcpu->arch.tsr);
1520
1521 /*
1522 * We may have stopped the watchdog due to
1523 * being stuck on final expiration.
1524 */
1525 if (tsr_bits & (TSR_ENW | TSR_WIS))
1526 arm_next_watchdog(vcpu);
1527
1284 update_timer_ints(vcpu); 1528 update_timer_ints(vcpu);
1285} 1529}
1286 1530
@@ -1298,12 +1542,14 @@ void kvmppc_decrementer_func(unsigned long data)
1298 1542
1299void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 1543void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
1300{ 1544{
1545 vcpu->cpu = smp_processor_id();
1301 current->thread.kvm_vcpu = vcpu; 1546 current->thread.kvm_vcpu = vcpu;
1302} 1547}
1303 1548
1304void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu) 1549void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)
1305{ 1550{
1306 current->thread.kvm_vcpu = NULL; 1551 current->thread.kvm_vcpu = NULL;
1552 vcpu->cpu = -1;
1307} 1553}
1308 1554
1309int __init kvmppc_booke_init(void) 1555int __init kvmppc_booke_init(void)
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index ba61974c1e20..e9b88e433f64 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -69,6 +69,7 @@ extern unsigned long kvmppc_booke_handlers;
69void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr); 69void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
70void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr); 70void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr);
71 71
72void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr);
72void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr); 73void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr);
73void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); 74void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
74void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); 75void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
diff --git a/arch/powerpc/kvm/booke_emulate.c b/arch/powerpc/kvm/booke_emulate.c
index 12834bb608ab..4685b8cf2249 100644
--- a/arch/powerpc/kvm/booke_emulate.c
+++ b/arch/powerpc/kvm/booke_emulate.c
@@ -133,10 +133,10 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
133 vcpu->arch.csrr1 = spr_val; 133 vcpu->arch.csrr1 = spr_val;
134 break; 134 break;
135 case SPRN_DBCR0: 135 case SPRN_DBCR0:
136 vcpu->arch.dbcr0 = spr_val; 136 vcpu->arch.dbg_reg.dbcr0 = spr_val;
137 break; 137 break;
138 case SPRN_DBCR1: 138 case SPRN_DBCR1:
139 vcpu->arch.dbcr1 = spr_val; 139 vcpu->arch.dbg_reg.dbcr1 = spr_val;
140 break; 140 break;
141 case SPRN_DBSR: 141 case SPRN_DBSR:
142 vcpu->arch.dbsr &= ~spr_val; 142 vcpu->arch.dbsr &= ~spr_val;
@@ -145,6 +145,14 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
145 kvmppc_clr_tsr_bits(vcpu, spr_val); 145 kvmppc_clr_tsr_bits(vcpu, spr_val);
146 break; 146 break;
147 case SPRN_TCR: 147 case SPRN_TCR:
148 /*
149 * WRC is a 2-bit field that is supposed to preserve its
150 * value once written to non-zero.
151 */
152 if (vcpu->arch.tcr & TCR_WRC_MASK) {
153 spr_val &= ~TCR_WRC_MASK;
154 spr_val |= vcpu->arch.tcr & TCR_WRC_MASK;
155 }
148 kvmppc_set_tcr(vcpu, spr_val); 156 kvmppc_set_tcr(vcpu, spr_val);
149 break; 157 break;
150 158
@@ -229,7 +237,17 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
229 case SPRN_IVOR15: 237 case SPRN_IVOR15:
230 vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = spr_val; 238 vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG] = spr_val;
231 break; 239 break;
232 240 case SPRN_MCSR:
241 vcpu->arch.mcsr &= ~spr_val;
242 break;
243#if defined(CONFIG_64BIT)
244 case SPRN_EPCR:
245 kvmppc_set_epcr(vcpu, spr_val);
246#ifdef CONFIG_KVM_BOOKE_HV
247 mtspr(SPRN_EPCR, vcpu->arch.shadow_epcr);
248#endif
249 break;
250#endif
233 default: 251 default:
234 emulated = EMULATE_FAIL; 252 emulated = EMULATE_FAIL;
235 } 253 }
@@ -258,10 +276,10 @@ int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
258 *spr_val = vcpu->arch.csrr1; 276 *spr_val = vcpu->arch.csrr1;
259 break; 277 break;
260 case SPRN_DBCR0: 278 case SPRN_DBCR0:
261 *spr_val = vcpu->arch.dbcr0; 279 *spr_val = vcpu->arch.dbg_reg.dbcr0;
262 break; 280 break;
263 case SPRN_DBCR1: 281 case SPRN_DBCR1:
264 *spr_val = vcpu->arch.dbcr1; 282 *spr_val = vcpu->arch.dbg_reg.dbcr1;
265 break; 283 break;
266 case SPRN_DBSR: 284 case SPRN_DBSR:
267 *spr_val = vcpu->arch.dbsr; 285 *spr_val = vcpu->arch.dbsr;
@@ -321,6 +339,14 @@ int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
321 case SPRN_IVOR15: 339 case SPRN_IVOR15:
322 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]; 340 *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG];
323 break; 341 break;
342 case SPRN_MCSR:
343 *spr_val = vcpu->arch.mcsr;
344 break;
345#if defined(CONFIG_64BIT)
346 case SPRN_EPCR:
347 *spr_val = vcpu->arch.epcr;
348 break;
349#endif
324 350
325 default: 351 default:
326 emulated = EMULATE_FAIL; 352 emulated = EMULATE_FAIL;
diff --git a/arch/powerpc/kvm/bookehv_interrupts.S b/arch/powerpc/kvm/bookehv_interrupts.S
index 099fe8272b57..e8ed7d659c55 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -16,6 +16,7 @@
16 * 16 *
17 * Author: Varun Sethi <varun.sethi@freescale.com> 17 * Author: Varun Sethi <varun.sethi@freescale.com>
18 * Author: Scott Wood <scotwood@freescale.com> 18 * Author: Scott Wood <scotwood@freescale.com>
19 * Author: Mihai Caraman <mihai.caraman@freescale.com>
19 * 20 *
20 * This file is derived from arch/powerpc/kvm/booke_interrupts.S 21 * This file is derived from arch/powerpc/kvm/booke_interrupts.S
21 */ 22 */
@@ -30,31 +31,33 @@
30#include <asm/bitsperlong.h> 31#include <asm/bitsperlong.h>
31#include <asm/thread_info.h> 32#include <asm/thread_info.h>
32 33
34#ifdef CONFIG_64BIT
35#include <asm/exception-64e.h>
36#else
33#include "../kernel/head_booke.h" /* for THREAD_NORMSAVE() */ 37#include "../kernel/head_booke.h" /* for THREAD_NORMSAVE() */
34 38#endif
35#define GET_VCPU(vcpu, thread) \
36 PPC_LL vcpu, THREAD_KVM_VCPU(thread)
37 39
38#define LONGBYTES (BITS_PER_LONG / 8) 40#define LONGBYTES (BITS_PER_LONG / 8)
39 41
40#define VCPU_GUEST_SPRG(n) (VCPU_GUEST_SPRGS + (n * LONGBYTES)) 42#define VCPU_GUEST_SPRG(n) (VCPU_GUEST_SPRGS + (n * LONGBYTES))
41 43
42/* The host stack layout: */ 44/* The host stack layout: */
43#define HOST_R1 (0 * LONGBYTES) /* Implied by stwu. */ 45#define HOST_R1 0 /* Implied by stwu. */
44#define HOST_CALLEE_LR (1 * LONGBYTES) 46#define HOST_CALLEE_LR PPC_LR_STKOFF
45#define HOST_RUN (2 * LONGBYTES) /* struct kvm_run */ 47#define HOST_RUN (HOST_CALLEE_LR + LONGBYTES)
46/* 48/*
47 * r2 is special: it holds 'current', and it made nonvolatile in the 49 * r2 is special: it holds 'current', and it made nonvolatile in the
48 * kernel with the -ffixed-r2 gcc option. 50 * kernel with the -ffixed-r2 gcc option.
49 */ 51 */
50#define HOST_R2 (3 * LONGBYTES) 52#define HOST_R2 (HOST_RUN + LONGBYTES)
51#define HOST_CR (4 * LONGBYTES) 53#define HOST_CR (HOST_R2 + LONGBYTES)
52#define HOST_NV_GPRS (5 * LONGBYTES) 54#define HOST_NV_GPRS (HOST_CR + LONGBYTES)
53#define __HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * LONGBYTES)) 55#define __HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * LONGBYTES))
54#define HOST_NV_GPR(n) __HOST_NV_GPR(__REG_##n) 56#define HOST_NV_GPR(n) __HOST_NV_GPR(__REG_##n)
55#define HOST_MIN_STACK_SIZE (HOST_NV_GPR(R31) + LONGBYTES) 57#define HOST_MIN_STACK_SIZE (HOST_NV_GPR(R31) + LONGBYTES)
56#define HOST_STACK_SIZE ((HOST_MIN_STACK_SIZE + 15) & ~15) /* Align. */ 58#define HOST_STACK_SIZE ((HOST_MIN_STACK_SIZE + 15) & ~15) /* Align. */
57#define HOST_STACK_LR (HOST_STACK_SIZE + LONGBYTES) /* In caller stack frame. */ 59/* LR in caller stack frame. */
60#define HOST_STACK_LR (HOST_STACK_SIZE + PPC_LR_STKOFF)
58 61
59#define NEED_EMU 0x00000001 /* emulation -- save nv regs */ 62#define NEED_EMU 0x00000001 /* emulation -- save nv regs */
60#define NEED_DEAR 0x00000002 /* save faulting DEAR */ 63#define NEED_DEAR 0x00000002 /* save faulting DEAR */
@@ -201,12 +204,128 @@
201 b kvmppc_resume_host 204 b kvmppc_resume_host
202.endm 205.endm
203 206
207#ifdef CONFIG_64BIT
208/* Exception types */
209#define EX_GEN 1
210#define EX_GDBELL 2
211#define EX_DBG 3
212#define EX_MC 4
213#define EX_CRIT 5
214#define EX_TLB 6
215
216/*
217 * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h
218 */
219.macro kvm_handler intno type scratch, paca_ex, ex_r10, ex_r11, srr0, srr1, flags
220 _GLOBAL(kvmppc_handler_\intno\()_\srr1)
221 mr r11, r4
222 /*
223 * Get vcpu from Paca: paca->__current.thread->kvm_vcpu
224 */
225 PPC_LL r4, PACACURRENT(r13)
226 PPC_LL r4, (THREAD + THREAD_KVM_VCPU)(r4)
227 stw r10, VCPU_CR(r4)
228 PPC_STL r11, VCPU_GPR(R4)(r4)
229 PPC_STL r5, VCPU_GPR(R5)(r4)
230 .if \type == EX_CRIT
231 PPC_LL r5, (\paca_ex + EX_R13)(r13)
232 .else
233 mfspr r5, \scratch
234 .endif
235 PPC_STL r6, VCPU_GPR(R6)(r4)
236 PPC_STL r8, VCPU_GPR(R8)(r4)
237 PPC_STL r9, VCPU_GPR(R9)(r4)
238 PPC_STL r5, VCPU_GPR(R13)(r4)
239 PPC_LL r6, (\paca_ex + \ex_r10)(r13)
240 PPC_LL r8, (\paca_ex + \ex_r11)(r13)
241 PPC_STL r3, VCPU_GPR(R3)(r4)
242 PPC_STL r7, VCPU_GPR(R7)(r4)
243 PPC_STL r12, VCPU_GPR(R12)(r4)
244 PPC_STL r6, VCPU_GPR(R10)(r4)
245 PPC_STL r8, VCPU_GPR(R11)(r4)
246 mfctr r5
247 PPC_STL r5, VCPU_CTR(r4)
248 mfspr r5, \srr0
249 mfspr r6, \srr1
250 kvm_handler_common \intno, \srr0, \flags
251.endm
252
253#define EX_PARAMS(type) \
254 EX_##type, \
255 SPRN_SPRG_##type##_SCRATCH, \
256 PACA_EX##type, \
257 EX_R10, \
258 EX_R11
259
260#define EX_PARAMS_TLB \
261 EX_TLB, \
262 SPRN_SPRG_GEN_SCRATCH, \
263 PACA_EXTLB, \
264 EX_TLB_R10, \
265 EX_TLB_R11
266
267kvm_handler BOOKE_INTERRUPT_CRITICAL, EX_PARAMS(CRIT), \
268 SPRN_CSRR0, SPRN_CSRR1, 0
269kvm_handler BOOKE_INTERRUPT_MACHINE_CHECK, EX_PARAMS(MC), \
270 SPRN_MCSRR0, SPRN_MCSRR1, 0
271kvm_handler BOOKE_INTERRUPT_DATA_STORAGE, EX_PARAMS(GEN), \
272 SPRN_SRR0, SPRN_SRR1,(NEED_EMU | NEED_DEAR | NEED_ESR)
273kvm_handler BOOKE_INTERRUPT_INST_STORAGE, EX_PARAMS(GEN), \
274 SPRN_SRR0, SPRN_SRR1, NEED_ESR
275kvm_handler BOOKE_INTERRUPT_EXTERNAL, EX_PARAMS(GEN), \
276 SPRN_SRR0, SPRN_SRR1, 0
277kvm_handler BOOKE_INTERRUPT_ALIGNMENT, EX_PARAMS(GEN), \
278 SPRN_SRR0, SPRN_SRR1,(NEED_DEAR | NEED_ESR)
279kvm_handler BOOKE_INTERRUPT_PROGRAM, EX_PARAMS(GEN), \
280 SPRN_SRR0, SPRN_SRR1,NEED_ESR
281kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, EX_PARAMS(GEN), \
282 SPRN_SRR0, SPRN_SRR1, 0
283kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, EX_PARAMS(GEN), \
284 SPRN_SRR0, SPRN_SRR1, 0
285kvm_handler BOOKE_INTERRUPT_DECREMENTER, EX_PARAMS(GEN), \
286 SPRN_SRR0, SPRN_SRR1, 0
287kvm_handler BOOKE_INTERRUPT_FIT, EX_PARAMS(GEN), \
288 SPRN_SRR0, SPRN_SRR1, 0
289kvm_handler BOOKE_INTERRUPT_WATCHDOG, EX_PARAMS(CRIT),\
290 SPRN_CSRR0, SPRN_CSRR1, 0
291/*
292 * Only bolted TLB miss exception handlers are supported for now
293 */
294kvm_handler BOOKE_INTERRUPT_DTLB_MISS, EX_PARAMS_TLB, \
295 SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR | NEED_ESR)
296kvm_handler BOOKE_INTERRUPT_ITLB_MISS, EX_PARAMS_TLB, \
297 SPRN_SRR0, SPRN_SRR1, 0
298kvm_handler BOOKE_INTERRUPT_SPE_UNAVAIL, EX_PARAMS(GEN), \
299 SPRN_SRR0, SPRN_SRR1, 0
300kvm_handler BOOKE_INTERRUPT_SPE_FP_DATA, EX_PARAMS(GEN), \
301 SPRN_SRR0, SPRN_SRR1, 0
302kvm_handler BOOKE_INTERRUPT_SPE_FP_ROUND, EX_PARAMS(GEN), \
303 SPRN_SRR0, SPRN_SRR1, 0
304kvm_handler BOOKE_INTERRUPT_PERFORMANCE_MONITOR, EX_PARAMS(GEN), \
305 SPRN_SRR0, SPRN_SRR1, 0
306kvm_handler BOOKE_INTERRUPT_DOORBELL, EX_PARAMS(GEN), \
307 SPRN_SRR0, SPRN_SRR1, 0
308kvm_handler BOOKE_INTERRUPT_DOORBELL_CRITICAL, EX_PARAMS(CRIT), \
309 SPRN_CSRR0, SPRN_CSRR1, 0
310kvm_handler BOOKE_INTERRUPT_HV_PRIV, EX_PARAMS(GEN), \
311 SPRN_SRR0, SPRN_SRR1, NEED_EMU
312kvm_handler BOOKE_INTERRUPT_HV_SYSCALL, EX_PARAMS(GEN), \
313 SPRN_SRR0, SPRN_SRR1, 0
314kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, EX_PARAMS(GDBELL), \
315 SPRN_GSRR0, SPRN_GSRR1, 0
316kvm_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, EX_PARAMS(CRIT), \
317 SPRN_CSRR0, SPRN_CSRR1, 0
318kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(DBG), \
319 SPRN_DSRR0, SPRN_DSRR1, 0
320kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(CRIT), \
321 SPRN_CSRR0, SPRN_CSRR1, 0
322#else
204/* 323/*
205 * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h 324 * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h
206 */ 325 */
207.macro kvm_handler intno srr0, srr1, flags 326.macro kvm_handler intno srr0, srr1, flags
208_GLOBAL(kvmppc_handler_\intno\()_\srr1) 327_GLOBAL(kvmppc_handler_\intno\()_\srr1)
209 GET_VCPU(r11, r10) 328 PPC_LL r11, THREAD_KVM_VCPU(r10)
210 PPC_STL r3, VCPU_GPR(R3)(r11) 329 PPC_STL r3, VCPU_GPR(R3)(r11)
211 mfspr r3, SPRN_SPRG_RSCRATCH0 330 mfspr r3, SPRN_SPRG_RSCRATCH0
212 PPC_STL r4, VCPU_GPR(R4)(r11) 331 PPC_STL r4, VCPU_GPR(R4)(r11)
@@ -233,7 +352,7 @@ _GLOBAL(kvmppc_handler_\intno\()_\srr1)
233.macro kvm_lvl_handler intno scratch srr0, srr1, flags 352.macro kvm_lvl_handler intno scratch srr0, srr1, flags
234_GLOBAL(kvmppc_handler_\intno\()_\srr1) 353_GLOBAL(kvmppc_handler_\intno\()_\srr1)
235 mfspr r10, SPRN_SPRG_THREAD 354 mfspr r10, SPRN_SPRG_THREAD
236 GET_VCPU(r11, r10) 355 PPC_LL r11, THREAD_KVM_VCPU(r10)
237 PPC_STL r3, VCPU_GPR(R3)(r11) 356 PPC_STL r3, VCPU_GPR(R3)(r11)
238 mfspr r3, \scratch 357 mfspr r3, \scratch
239 PPC_STL r4, VCPU_GPR(R4)(r11) 358 PPC_STL r4, VCPU_GPR(R4)(r11)
@@ -295,7 +414,7 @@ kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
295 SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 414 SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
296kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ 415kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
297 SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0 416 SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0
298 417#endif
299 418
300/* Registers: 419/* Registers:
301 * SPRG_SCRATCH0: guest r10 420 * SPRG_SCRATCH0: guest r10
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index aa8b81428bf4..c70d37ed770a 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -27,8 +27,7 @@
27#define E500_TLB_NUM 2 27#define E500_TLB_NUM 2
28 28
29#define E500_TLB_VALID 1 29#define E500_TLB_VALID 1
30#define E500_TLB_DIRTY 2 30#define E500_TLB_BITMAP 2
31#define E500_TLB_BITMAP 4
32 31
33struct tlbe_ref { 32struct tlbe_ref {
34 pfn_t pfn; 33 pfn_t pfn;
@@ -130,9 +129,9 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500,
130 ulong value); 129 ulong value);
131int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu); 130int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu);
132int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu); 131int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu);
133int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb); 132int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, gva_t ea);
134int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int rt, int ra, int rb); 133int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int type, gva_t ea);
135int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb); 134int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, gva_t ea);
136int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500); 135int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500);
137void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500); 136void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500);
138 137
@@ -155,7 +154,7 @@ get_tlb_size(const struct kvm_book3e_206_tlb_entry *tlbe)
155 154
156static inline gva_t get_tlb_eaddr(const struct kvm_book3e_206_tlb_entry *tlbe) 155static inline gva_t get_tlb_eaddr(const struct kvm_book3e_206_tlb_entry *tlbe)
157{ 156{
158 return tlbe->mas2 & 0xfffff000; 157 return tlbe->mas2 & MAS2_EPN;
159} 158}
160 159
161static inline u64 get_tlb_bytes(const struct kvm_book3e_206_tlb_entry *tlbe) 160static inline u64 get_tlb_bytes(const struct kvm_book3e_206_tlb_entry *tlbe)
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index e04b0ef55ce0..e78f353a836a 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -89,6 +89,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
89 int ra = get_ra(inst); 89 int ra = get_ra(inst);
90 int rb = get_rb(inst); 90 int rb = get_rb(inst);
91 int rt = get_rt(inst); 91 int rt = get_rt(inst);
92 gva_t ea;
92 93
93 switch (get_op(inst)) { 94 switch (get_op(inst)) {
94 case 31: 95 case 31:
@@ -113,15 +114,20 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
113 break; 114 break;
114 115
115 case XOP_TLBSX: 116 case XOP_TLBSX:
116 emulated = kvmppc_e500_emul_tlbsx(vcpu,rb); 117 ea = kvmppc_get_ea_indexed(vcpu, ra, rb);
118 emulated = kvmppc_e500_emul_tlbsx(vcpu, ea);
117 break; 119 break;
118 120
119 case XOP_TLBILX: 121 case XOP_TLBILX: {
120 emulated = kvmppc_e500_emul_tlbilx(vcpu, rt, ra, rb); 122 int type = rt & 0x3;
123 ea = kvmppc_get_ea_indexed(vcpu, ra, rb);
124 emulated = kvmppc_e500_emul_tlbilx(vcpu, type, ea);
121 break; 125 break;
126 }
122 127
123 case XOP_TLBIVAX: 128 case XOP_TLBIVAX:
124 emulated = kvmppc_e500_emul_tlbivax(vcpu, ra, rb); 129 ea = kvmppc_get_ea_indexed(vcpu, ra, rb);
130 emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
125 break; 131 break;
126 132
127 default: 133 default:
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index ff38b664195d..cf3f18012371 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -304,17 +304,13 @@ static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref,
304 ref->flags = E500_TLB_VALID; 304 ref->flags = E500_TLB_VALID;
305 305
306 if (tlbe_is_writable(gtlbe)) 306 if (tlbe_is_writable(gtlbe))
307 ref->flags |= E500_TLB_DIRTY; 307 kvm_set_pfn_dirty(pfn);
308} 308}
309 309
310static inline void kvmppc_e500_ref_release(struct tlbe_ref *ref) 310static inline void kvmppc_e500_ref_release(struct tlbe_ref *ref)
311{ 311{
312 if (ref->flags & E500_TLB_VALID) { 312 if (ref->flags & E500_TLB_VALID) {
313 if (ref->flags & E500_TLB_DIRTY) 313 trace_kvm_booke206_ref_release(ref->pfn, ref->flags);
314 kvm_release_pfn_dirty(ref->pfn);
315 else
316 kvm_release_pfn_clean(ref->pfn);
317
318 ref->flags = 0; 314 ref->flags = 0;
319 } 315 }
320} 316}
@@ -357,6 +353,13 @@ static void clear_tlb_refs(struct kvmppc_vcpu_e500 *vcpu_e500)
357 clear_tlb_privs(vcpu_e500); 353 clear_tlb_privs(vcpu_e500);
358} 354}
359 355
356void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu)
357{
358 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
359 clear_tlb_refs(vcpu_e500);
360 clear_tlb1_bitmap(vcpu_e500);
361}
362
360static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu, 363static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu,
361 unsigned int eaddr, int as) 364 unsigned int eaddr, int as)
362{ 365{
@@ -412,7 +415,8 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
412 struct tlbe_ref *ref) 415 struct tlbe_ref *ref)
413{ 416{
414 struct kvm_memory_slot *slot; 417 struct kvm_memory_slot *slot;
415 unsigned long pfn, hva; 418 unsigned long pfn = 0; /* silence GCC warning */
419 unsigned long hva;
416 int pfnmap = 0; 420 int pfnmap = 0;
417 int tsize = BOOK3E_PAGESZ_4K; 421 int tsize = BOOK3E_PAGESZ_4K;
418 422
@@ -521,7 +525,7 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
521 if (likely(!pfnmap)) { 525 if (likely(!pfnmap)) {
522 unsigned long tsize_pages = 1 << (tsize + 10 - PAGE_SHIFT); 526 unsigned long tsize_pages = 1 << (tsize + 10 - PAGE_SHIFT);
523 pfn = gfn_to_pfn_memslot(slot, gfn); 527 pfn = gfn_to_pfn_memslot(slot, gfn);
524 if (is_error_pfn(pfn)) { 528 if (is_error_noslot_pfn(pfn)) {
525 printk(KERN_ERR "Couldn't get real page for gfn %lx!\n", 529 printk(KERN_ERR "Couldn't get real page for gfn %lx!\n",
526 (long)gfn); 530 (long)gfn);
527 return; 531 return;
@@ -541,6 +545,9 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
541 545
542 /* Clear i-cache for new pages */ 546 /* Clear i-cache for new pages */
543 kvmppc_mmu_flush_icache(pfn); 547 kvmppc_mmu_flush_icache(pfn);
548
549 /* Drop refcount on page, so that mmu notifiers can clear it */
550 kvm_release_pfn_clean(pfn);
544} 551}
545 552
546/* XXX only map the one-one case, for now use TLB0 */ 553/* XXX only map the one-one case, for now use TLB0 */
@@ -682,14 +689,11 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500, ulong value)
682 return EMULATE_DONE; 689 return EMULATE_DONE;
683} 690}
684 691
685int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb) 692int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, gva_t ea)
686{ 693{
687 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 694 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
688 unsigned int ia; 695 unsigned int ia;
689 int esel, tlbsel; 696 int esel, tlbsel;
690 gva_t ea;
691
692 ea = ((ra) ? kvmppc_get_gpr(vcpu, ra) : 0) + kvmppc_get_gpr(vcpu, rb);
693 697
694 ia = (ea >> 2) & 0x1; 698 ia = (ea >> 2) & 0x1;
695 699
@@ -716,7 +720,7 @@ int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb)
716} 720}
717 721
718static void tlbilx_all(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel, 722static void tlbilx_all(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,
719 int pid, int rt) 723 int pid, int type)
720{ 724{
721 struct kvm_book3e_206_tlb_entry *tlbe; 725 struct kvm_book3e_206_tlb_entry *tlbe;
722 int tid, esel; 726 int tid, esel;
@@ -725,7 +729,7 @@ static void tlbilx_all(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,
725 for (esel = 0; esel < vcpu_e500->gtlb_params[tlbsel].entries; esel++) { 729 for (esel = 0; esel < vcpu_e500->gtlb_params[tlbsel].entries; esel++) {
726 tlbe = get_entry(vcpu_e500, tlbsel, esel); 730 tlbe = get_entry(vcpu_e500, tlbsel, esel);
727 tid = get_tlb_tid(tlbe); 731 tid = get_tlb_tid(tlbe);
728 if (rt == 0 || tid == pid) { 732 if (type == 0 || tid == pid) {
729 inval_gtlbe_on_host(vcpu_e500, tlbsel, esel); 733 inval_gtlbe_on_host(vcpu_e500, tlbsel, esel);
730 kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel); 734 kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
731 } 735 }
@@ -733,14 +737,9 @@ static void tlbilx_all(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,
733} 737}
734 738
735static void tlbilx_one(struct kvmppc_vcpu_e500 *vcpu_e500, int pid, 739static void tlbilx_one(struct kvmppc_vcpu_e500 *vcpu_e500, int pid,
736 int ra, int rb) 740 gva_t ea)
737{ 741{
738 int tlbsel, esel; 742 int tlbsel, esel;
739 gva_t ea;
740
741 ea = kvmppc_get_gpr(&vcpu_e500->vcpu, rb);
742 if (ra)
743 ea += kvmppc_get_gpr(&vcpu_e500->vcpu, ra);
744 743
745 for (tlbsel = 0; tlbsel < 2; tlbsel++) { 744 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
746 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, -1); 745 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, -1);
@@ -752,16 +751,16 @@ static void tlbilx_one(struct kvmppc_vcpu_e500 *vcpu_e500, int pid,
752 } 751 }
753} 752}
754 753
755int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int rt, int ra, int rb) 754int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int type, gva_t ea)
756{ 755{
757 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 756 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
758 int pid = get_cur_spid(vcpu); 757 int pid = get_cur_spid(vcpu);
759 758
760 if (rt == 0 || rt == 1) { 759 if (type == 0 || type == 1) {
761 tlbilx_all(vcpu_e500, 0, pid, rt); 760 tlbilx_all(vcpu_e500, 0, pid, type);
762 tlbilx_all(vcpu_e500, 1, pid, rt); 761 tlbilx_all(vcpu_e500, 1, pid, type);
763 } else if (rt == 3) { 762 } else if (type == 3) {
764 tlbilx_one(vcpu_e500, pid, ra, rb); 763 tlbilx_one(vcpu_e500, pid, ea);
765 } 764 }
766 765
767 return EMULATE_DONE; 766 return EMULATE_DONE;
@@ -786,16 +785,13 @@ int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu)
786 return EMULATE_DONE; 785 return EMULATE_DONE;
787} 786}
788 787
789int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb) 788int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, gva_t ea)
790{ 789{
791 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); 790 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
792 int as = !!get_cur_sas(vcpu); 791 int as = !!get_cur_sas(vcpu);
793 unsigned int pid = get_cur_spid(vcpu); 792 unsigned int pid = get_cur_spid(vcpu);
794 int esel, tlbsel; 793 int esel, tlbsel;
795 struct kvm_book3e_206_tlb_entry *gtlbe = NULL; 794 struct kvm_book3e_206_tlb_entry *gtlbe = NULL;
796 gva_t ea;
797
798 ea = kvmppc_get_gpr(vcpu, rb);
799 795
800 for (tlbsel = 0; tlbsel < 2; tlbsel++) { 796 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
801 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, as); 797 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, as);
@@ -875,6 +871,8 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
875 871
876 gtlbe->mas1 = vcpu->arch.shared->mas1; 872 gtlbe->mas1 = vcpu->arch.shared->mas1;
877 gtlbe->mas2 = vcpu->arch.shared->mas2; 873 gtlbe->mas2 = vcpu->arch.shared->mas2;
874 if (!(vcpu->arch.shared->msr & MSR_CM))
875 gtlbe->mas2 &= 0xffffffffUL;
878 gtlbe->mas7_3 = vcpu->arch.shared->mas7_3; 876 gtlbe->mas7_3 = vcpu->arch.shared->mas7_3;
879 877
880 trace_kvm_booke206_gtlb_write(vcpu->arch.shared->mas0, gtlbe->mas1, 878 trace_kvm_booke206_gtlb_write(vcpu->arch.shared->mas0, gtlbe->mas1,
@@ -1039,8 +1037,12 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
1039 sesel = 0; /* unused */ 1037 sesel = 0; /* unused */
1040 priv = &vcpu_e500->gtlb_priv[tlbsel][esel]; 1038 priv = &vcpu_e500->gtlb_priv[tlbsel][esel];
1041 1039
1042 kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K, 1040 /* Only triggers after clear_tlb_refs */
1043 &priv->ref, eaddr, &stlbe); 1041 if (unlikely(!(priv->ref.flags & E500_TLB_VALID)))
1042 kvmppc_e500_tlb0_map(vcpu_e500, esel, &stlbe);
1043 else
1044 kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K,
1045 &priv->ref, eaddr, &stlbe);
1044 break; 1046 break;
1045 1047
1046 case 1: { 1048 case 1: {
@@ -1060,6 +1062,49 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
1060 write_stlbe(vcpu_e500, gtlbe, &stlbe, stlbsel, sesel); 1062 write_stlbe(vcpu_e500, gtlbe, &stlbe, stlbsel, sesel);
1061} 1063}
1062 1064
1065/************* MMU Notifiers *************/
1066
1067int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
1068{
1069 trace_kvm_unmap_hva(hva);
1070
1071 /*
1072 * Flush all shadow tlb entries everywhere. This is slow, but
1073 * we are 100% sure that we catch the to be unmapped page
1074 */
1075 kvm_flush_remote_tlbs(kvm);
1076
1077 return 0;
1078}
1079
1080int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
1081{
1082 /* kvm_unmap_hva flushes everything anyways */
1083 kvm_unmap_hva(kvm, start);
1084
1085 return 0;
1086}
1087
1088int kvm_age_hva(struct kvm *kvm, unsigned long hva)
1089{
1090 /* XXX could be more clever ;) */
1091 return 0;
1092}
1093
1094int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
1095{
1096 /* XXX could be more clever ;) */
1097 return 0;
1098}
1099
1100void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)
1101{
1102 /* The page will get remapped properly on its next fault */
1103 kvm_unmap_hva(kvm, hva);
1104}
1105
1106/*****************************************/
1107
1063static void free_gtlb(struct kvmppc_vcpu_e500 *vcpu_e500) 1108static void free_gtlb(struct kvmppc_vcpu_e500 *vcpu_e500)
1064{ 1109{
1065 int i; 1110 int i;
@@ -1081,6 +1126,8 @@ static void free_gtlb(struct kvmppc_vcpu_e500 *vcpu_e500)
1081 } 1126 }
1082 1127
1083 vcpu_e500->num_shared_tlb_pages = 0; 1128 vcpu_e500->num_shared_tlb_pages = 0;
1129
1130 kfree(vcpu_e500->shared_tlb_pages);
1084 vcpu_e500->shared_tlb_pages = NULL; 1131 vcpu_e500->shared_tlb_pages = NULL;
1085 } else { 1132 } else {
1086 kfree(vcpu_e500->gtlb_arch); 1133 kfree(vcpu_e500->gtlb_arch);
@@ -1178,21 +1225,27 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
1178 } 1225 }
1179 1226
1180 virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL); 1227 virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL);
1181 if (!virt) 1228 if (!virt) {
1229 ret = -ENOMEM;
1182 goto err_put_page; 1230 goto err_put_page;
1231 }
1183 1232
1184 privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0], 1233 privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
1185 GFP_KERNEL); 1234 GFP_KERNEL);
1186 privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1], 1235 privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
1187 GFP_KERNEL); 1236 GFP_KERNEL);
1188 1237
1189 if (!privs[0] || !privs[1]) 1238 if (!privs[0] || !privs[1]) {
1190 goto err_put_page; 1239 ret = -ENOMEM;
1240 goto err_privs;
1241 }
1191 1242
1192 g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1], 1243 g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
1193 GFP_KERNEL); 1244 GFP_KERNEL);
1194 if (!g2h_bitmap) 1245 if (!g2h_bitmap) {
1195 goto err_put_page; 1246 ret = -ENOMEM;
1247 goto err_privs;
1248 }
1196 1249
1197 free_gtlb(vcpu_e500); 1250 free_gtlb(vcpu_e500);
1198 1251
@@ -1232,10 +1285,11 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
1232 kvmppc_recalc_tlb1map_range(vcpu_e500); 1285 kvmppc_recalc_tlb1map_range(vcpu_e500);
1233 return 0; 1286 return 0;
1234 1287
1235err_put_page: 1288err_privs:
1236 kfree(privs[0]); 1289 kfree(privs[0]);
1237 kfree(privs[1]); 1290 kfree(privs[1]);
1238 1291
1292err_put_page:
1239 for (i = 0; i < num_pages; i++) 1293 for (i = 0; i < num_pages; i++)
1240 put_page(pages[i]); 1294 put_page(pages[i]);
1241 1295
@@ -1332,7 +1386,7 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
1332 if (!vcpu_e500->gtlb_priv[1]) 1386 if (!vcpu_e500->gtlb_priv[1])
1333 goto err; 1387 goto err;
1334 1388
1335 vcpu_e500->g2h_tlb1_map = kzalloc(sizeof(unsigned int) * 1389 vcpu_e500->g2h_tlb1_map = kzalloc(sizeof(u64) *
1336 vcpu_e500->gtlb_params[1].entries, 1390 vcpu_e500->gtlb_params[1].entries,
1337 GFP_KERNEL); 1391 GFP_KERNEL);
1338 if (!vcpu_e500->g2h_tlb1_map) 1392 if (!vcpu_e500->g2h_tlb1_map)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index ee04abaefe23..9d9cddc5b346 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -39,6 +39,7 @@
39#define OP_31_XOP_TRAP 4 39#define OP_31_XOP_TRAP 4
40#define OP_31_XOP_LWZX 23 40#define OP_31_XOP_LWZX 23
41#define OP_31_XOP_TRAP_64 68 41#define OP_31_XOP_TRAP_64 68
42#define OP_31_XOP_DCBF 86
42#define OP_31_XOP_LBZX 87 43#define OP_31_XOP_LBZX 87
43#define OP_31_XOP_STWX 151 44#define OP_31_XOP_STWX 151
44#define OP_31_XOP_STBX 215 45#define OP_31_XOP_STBX 215
@@ -131,6 +132,125 @@ u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb)
131 return vcpu->arch.dec - jd; 132 return vcpu->arch.dec - jd;
132} 133}
133 134
135static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
136{
137 enum emulation_result emulated = EMULATE_DONE;
138 ulong spr_val = kvmppc_get_gpr(vcpu, rs);
139
140 switch (sprn) {
141 case SPRN_SRR0:
142 vcpu->arch.shared->srr0 = spr_val;
143 break;
144 case SPRN_SRR1:
145 vcpu->arch.shared->srr1 = spr_val;
146 break;
147
148 /* XXX We need to context-switch the timebase for
149 * watchdog and FIT. */
150 case SPRN_TBWL: break;
151 case SPRN_TBWU: break;
152
153 case SPRN_MSSSR0: break;
154
155 case SPRN_DEC:
156 vcpu->arch.dec = spr_val;
157 kvmppc_emulate_dec(vcpu);
158 break;
159
160 case SPRN_SPRG0:
161 vcpu->arch.shared->sprg0 = spr_val;
162 break;
163 case SPRN_SPRG1:
164 vcpu->arch.shared->sprg1 = spr_val;
165 break;
166 case SPRN_SPRG2:
167 vcpu->arch.shared->sprg2 = spr_val;
168 break;
169 case SPRN_SPRG3:
170 vcpu->arch.shared->sprg3 = spr_val;
171 break;
172
173 default:
174 emulated = kvmppc_core_emulate_mtspr(vcpu, sprn,
175 spr_val);
176 if (emulated == EMULATE_FAIL)
177 printk(KERN_INFO "mtspr: unknown spr "
178 "0x%x\n", sprn);
179 break;
180 }
181
182 kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS);
183
184 return emulated;
185}
186
187static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
188{
189 enum emulation_result emulated = EMULATE_DONE;
190 ulong spr_val = 0;
191
192 switch (sprn) {
193 case SPRN_SRR0:
194 spr_val = vcpu->arch.shared->srr0;
195 break;
196 case SPRN_SRR1:
197 spr_val = vcpu->arch.shared->srr1;
198 break;
199 case SPRN_PVR:
200 spr_val = vcpu->arch.pvr;
201 break;
202 case SPRN_PIR:
203 spr_val = vcpu->vcpu_id;
204 break;
205 case SPRN_MSSSR0:
206 spr_val = 0;
207 break;
208
209 /* Note: mftb and TBRL/TBWL are user-accessible, so
210 * the guest can always access the real TB anyways.
211 * In fact, we probably will never see these traps. */
212 case SPRN_TBWL:
213 spr_val = get_tb() >> 32;
214 break;
215 case SPRN_TBWU:
216 spr_val = get_tb();
217 break;
218
219 case SPRN_SPRG0:
220 spr_val = vcpu->arch.shared->sprg0;
221 break;
222 case SPRN_SPRG1:
223 spr_val = vcpu->arch.shared->sprg1;
224 break;
225 case SPRN_SPRG2:
226 spr_val = vcpu->arch.shared->sprg2;
227 break;
228 case SPRN_SPRG3:
229 spr_val = vcpu->arch.shared->sprg3;
230 break;
231 /* Note: SPRG4-7 are user-readable, so we don't get
232 * a trap. */
233
234 case SPRN_DEC:
235 spr_val = kvmppc_get_dec(vcpu, get_tb());
236 break;
237 default:
238 emulated = kvmppc_core_emulate_mfspr(vcpu, sprn,
239 &spr_val);
240 if (unlikely(emulated == EMULATE_FAIL)) {
241 printk(KERN_INFO "mfspr: unknown spr "
242 "0x%x\n", sprn);
243 }
244 break;
245 }
246
247 if (emulated == EMULATE_DONE)
248 kvmppc_set_gpr(vcpu, rt, spr_val);
249 kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS);
250
251 return emulated;
252}
253
134/* XXX to do: 254/* XXX to do:
135 * lhax 255 * lhax
136 * lhaux 256 * lhaux
@@ -156,7 +276,6 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
156 int sprn = get_sprn(inst); 276 int sprn = get_sprn(inst);
157 enum emulation_result emulated = EMULATE_DONE; 277 enum emulation_result emulated = EMULATE_DONE;
158 int advance = 1; 278 int advance = 1;
159 ulong spr_val = 0;
160 279
161 /* this default type might be overwritten by subcategories */ 280 /* this default type might be overwritten by subcategories */
162 kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS); 281 kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
@@ -236,62 +355,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
236 break; 355 break;
237 356
238 case OP_31_XOP_MFSPR: 357 case OP_31_XOP_MFSPR:
239 switch (sprn) { 358 emulated = kvmppc_emulate_mfspr(vcpu, sprn, rt);
240 case SPRN_SRR0:
241 spr_val = vcpu->arch.shared->srr0;
242 break;
243 case SPRN_SRR1:
244 spr_val = vcpu->arch.shared->srr1;
245 break;
246 case SPRN_PVR:
247 spr_val = vcpu->arch.pvr;
248 break;
249 case SPRN_PIR:
250 spr_val = vcpu->vcpu_id;
251 break;
252 case SPRN_MSSSR0:
253 spr_val = 0;
254 break;
255
256 /* Note: mftb and TBRL/TBWL are user-accessible, so
257 * the guest can always access the real TB anyways.
258 * In fact, we probably will never see these traps. */
259 case SPRN_TBWL:
260 spr_val = get_tb() >> 32;
261 break;
262 case SPRN_TBWU:
263 spr_val = get_tb();
264 break;
265
266 case SPRN_SPRG0:
267 spr_val = vcpu->arch.shared->sprg0;
268 break;
269 case SPRN_SPRG1:
270 spr_val = vcpu->arch.shared->sprg1;
271 break;
272 case SPRN_SPRG2:
273 spr_val = vcpu->arch.shared->sprg2;
274 break;
275 case SPRN_SPRG3:
276 spr_val = vcpu->arch.shared->sprg3;
277 break;
278 /* Note: SPRG4-7 are user-readable, so we don't get
279 * a trap. */
280
281 case SPRN_DEC:
282 spr_val = kvmppc_get_dec(vcpu, get_tb());
283 break;
284 default:
285 emulated = kvmppc_core_emulate_mfspr(vcpu, sprn,
286 &spr_val);
287 if (unlikely(emulated == EMULATE_FAIL)) {
288 printk(KERN_INFO "mfspr: unknown spr "
289 "0x%x\n", sprn);
290 }
291 break;
292 }
293 kvmppc_set_gpr(vcpu, rt, spr_val);
294 kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS);
295 break; 359 break;
296 360
297 case OP_31_XOP_STHX: 361 case OP_31_XOP_STHX:
@@ -308,51 +372,10 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
308 break; 372 break;
309 373
310 case OP_31_XOP_MTSPR: 374 case OP_31_XOP_MTSPR:
311 spr_val = kvmppc_get_gpr(vcpu, rs); 375 emulated = kvmppc_emulate_mtspr(vcpu, sprn, rs);
312 switch (sprn) {
313 case SPRN_SRR0:
314 vcpu->arch.shared->srr0 = spr_val;
315 break;
316 case SPRN_SRR1:
317 vcpu->arch.shared->srr1 = spr_val;
318 break;
319
320 /* XXX We need to context-switch the timebase for
321 * watchdog and FIT. */
322 case SPRN_TBWL: break;
323 case SPRN_TBWU: break;
324
325 case SPRN_MSSSR0: break;
326
327 case SPRN_DEC:
328 vcpu->arch.dec = spr_val;
329 kvmppc_emulate_dec(vcpu);
330 break;
331
332 case SPRN_SPRG0:
333 vcpu->arch.shared->sprg0 = spr_val;
334 break;
335 case SPRN_SPRG1:
336 vcpu->arch.shared->sprg1 = spr_val;
337 break;
338 case SPRN_SPRG2:
339 vcpu->arch.shared->sprg2 = spr_val;
340 break;
341 case SPRN_SPRG3:
342 vcpu->arch.shared->sprg3 = spr_val;
343 break;
344
345 default:
346 emulated = kvmppc_core_emulate_mtspr(vcpu, sprn,
347 spr_val);
348 if (emulated == EMULATE_FAIL)
349 printk(KERN_INFO "mtspr: unknown spr "
350 "0x%x\n", sprn);
351 break;
352 }
353 kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS);
354 break; 376 break;
355 377
378 case OP_31_XOP_DCBF:
356 case OP_31_XOP_DCBI: 379 case OP_31_XOP_DCBI:
357 /* Do nothing. The guest is performing dcbi because 380 /* Do nothing. The guest is performing dcbi because
358 * hardware DMA is not snooped by the dcache, but 381 * hardware DMA is not snooped by the dcache, but
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 4d213b8b0fb5..70739a089560 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -30,6 +30,7 @@
30#include <asm/kvm_ppc.h> 30#include <asm/kvm_ppc.h>
31#include <asm/tlbflush.h> 31#include <asm/tlbflush.h>
32#include <asm/cputhreads.h> 32#include <asm/cputhreads.h>
33#include <asm/irqflags.h>
33#include "timing.h" 34#include "timing.h"
34#include "../mm/mmu_decl.h" 35#include "../mm/mmu_decl.h"
35 36
@@ -38,8 +39,7 @@
38 39
39int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) 40int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
40{ 41{
41 return !(v->arch.shared->msr & MSR_WE) || 42 return !!(v->arch.pending_exceptions) ||
42 !!(v->arch.pending_exceptions) ||
43 v->requests; 43 v->requests;
44} 44}
45 45
@@ -48,6 +48,85 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
48 return 1; 48 return 1;
49} 49}
50 50
51#ifndef CONFIG_KVM_BOOK3S_64_HV
52/*
53 * Common checks before entering the guest world. Call with interrupts
54 * disabled.
55 *
56 * returns:
57 *
58 * == 1 if we're ready to go into guest state
59 * <= 0 if we need to go back to the host with return value
60 */
61int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
62{
63 int r = 1;
64
65 WARN_ON_ONCE(!irqs_disabled());
66 while (true) {
67 if (need_resched()) {
68 local_irq_enable();
69 cond_resched();
70 local_irq_disable();
71 continue;
72 }
73
74 if (signal_pending(current)) {
75 kvmppc_account_exit(vcpu, SIGNAL_EXITS);
76 vcpu->run->exit_reason = KVM_EXIT_INTR;
77 r = -EINTR;
78 break;
79 }
80
81 vcpu->mode = IN_GUEST_MODE;
82
83 /*
84 * Reading vcpu->requests must happen after setting vcpu->mode,
85 * so we don't miss a request because the requester sees
86 * OUTSIDE_GUEST_MODE and assumes we'll be checking requests
87 * before next entering the guest (and thus doesn't IPI).
88 */
89 smp_mb();
90
91 if (vcpu->requests) {
92 /* Make sure we process requests preemptable */
93 local_irq_enable();
94 trace_kvm_check_requests(vcpu);
95 r = kvmppc_core_check_requests(vcpu);
96 local_irq_disable();
97 if (r > 0)
98 continue;
99 break;
100 }
101
102 if (kvmppc_core_prepare_to_enter(vcpu)) {
103 /* interrupts got enabled in between, so we
104 are back at square 1 */
105 continue;
106 }
107
108#ifdef CONFIG_PPC64
109 /* lazy EE magic */
110 hard_irq_disable();
111 if (lazy_irq_pending()) {
112 /* Got an interrupt in between, try again */
113 local_irq_enable();
114 local_irq_disable();
115 kvm_guest_exit();
116 continue;
117 }
118
119 trace_hardirqs_on();
120#endif
121
122 kvm_guest_enter();
123 break;
124 }
125
126 return r;
127}
128#endif /* CONFIG_KVM_BOOK3S_64_HV */
129
51int kvmppc_kvm_pv(struct kvm_vcpu *vcpu) 130int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
52{ 131{
53 int nr = kvmppc_get_gpr(vcpu, 11); 132 int nr = kvmppc_get_gpr(vcpu, 11);
@@ -67,18 +146,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
67 } 146 }
68 147
69 switch (nr) { 148 switch (nr) {
70 case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE: 149 case KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE):
71 { 150 {
72 vcpu->arch.magic_page_pa = param1; 151 vcpu->arch.magic_page_pa = param1;
73 vcpu->arch.magic_page_ea = param2; 152 vcpu->arch.magic_page_ea = param2;
74 153
75 r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7; 154 r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
76 155
77 r = HC_EV_SUCCESS; 156 r = EV_SUCCESS;
78 break; 157 break;
79 } 158 }
80 case HC_VENDOR_KVM | KVM_HC_FEATURES: 159 case KVM_HCALL_TOKEN(KVM_HC_FEATURES):
81 r = HC_EV_SUCCESS; 160 r = EV_SUCCESS;
82#if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2) 161#if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
83 /* XXX Missing magic page on 44x */ 162 /* XXX Missing magic page on 44x */
84 r2 |= (1 << KVM_FEATURE_MAGIC_PAGE); 163 r2 |= (1 << KVM_FEATURE_MAGIC_PAGE);
@@ -86,8 +165,13 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
86 165
87 /* Second return value is in r4 */ 166 /* Second return value is in r4 */
88 break; 167 break;
168 case EV_HCALL_TOKEN(EV_IDLE):
169 r = EV_SUCCESS;
170 kvm_vcpu_block(vcpu);
171 clear_bit(KVM_REQ_UNHALT, &vcpu->requests);
172 break;
89 default: 173 default:
90 r = HC_EV_UNIMPLEMENTED; 174 r = EV_UNIMPLEMENTED;
91 break; 175 break;
92 } 176 }
93 177
@@ -220,6 +304,7 @@ int kvm_dev_ioctl_check_extension(long ext)
220 switch (ext) { 304 switch (ext) {
221#ifdef CONFIG_BOOKE 305#ifdef CONFIG_BOOKE
222 case KVM_CAP_PPC_BOOKE_SREGS: 306 case KVM_CAP_PPC_BOOKE_SREGS:
307 case KVM_CAP_PPC_BOOKE_WATCHDOG:
223#else 308#else
224 case KVM_CAP_PPC_SEGSTATE: 309 case KVM_CAP_PPC_SEGSTATE:
225 case KVM_CAP_PPC_HIOR: 310 case KVM_CAP_PPC_HIOR:
@@ -229,6 +314,7 @@ int kvm_dev_ioctl_check_extension(long ext)
229 case KVM_CAP_PPC_IRQ_LEVEL: 314 case KVM_CAP_PPC_IRQ_LEVEL:
230 case KVM_CAP_ENABLE_CAP: 315 case KVM_CAP_ENABLE_CAP:
231 case KVM_CAP_ONE_REG: 316 case KVM_CAP_ONE_REG:
317 case KVM_CAP_IOEVENTFD:
232 r = 1; 318 r = 1;
233 break; 319 break;
234#ifndef CONFIG_KVM_BOOK3S_64_HV 320#ifndef CONFIG_KVM_BOOK3S_64_HV
@@ -260,10 +346,22 @@ int kvm_dev_ioctl_check_extension(long ext)
260 if (cpu_has_feature(CPU_FTR_ARCH_201)) 346 if (cpu_has_feature(CPU_FTR_ARCH_201))
261 r = 2; 347 r = 2;
262 break; 348 break;
349#endif
263 case KVM_CAP_SYNC_MMU: 350 case KVM_CAP_SYNC_MMU:
351#ifdef CONFIG_KVM_BOOK3S_64_HV
264 r = cpu_has_feature(CPU_FTR_ARCH_206) ? 1 : 0; 352 r = cpu_has_feature(CPU_FTR_ARCH_206) ? 1 : 0;
353#elif defined(KVM_ARCH_WANT_MMU_NOTIFIER)
354 r = 1;
355#else
356 r = 0;
357 break;
358#endif
359#ifdef CONFIG_KVM_BOOK3S_64_HV
360 case KVM_CAP_PPC_HTAB_FD:
361 r = 1;
265 break; 362 break;
266#endif 363#endif
364 break;
267 case KVM_CAP_NR_VCPUS: 365 case KVM_CAP_NR_VCPUS:
268 /* 366 /*
269 * Recommending a number of CPUs is somewhat arbitrary; we 367 * Recommending a number of CPUs is somewhat arbitrary; we
@@ -302,19 +400,12 @@ long kvm_arch_dev_ioctl(struct file *filp,
302void kvm_arch_free_memslot(struct kvm_memory_slot *free, 400void kvm_arch_free_memslot(struct kvm_memory_slot *free,
303 struct kvm_memory_slot *dont) 401 struct kvm_memory_slot *dont)
304{ 402{
305 if (!dont || free->arch.rmap != dont->arch.rmap) { 403 kvmppc_core_free_memslot(free, dont);
306 vfree(free->arch.rmap);
307 free->arch.rmap = NULL;
308 }
309} 404}
310 405
311int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) 406int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages)
312{ 407{
313 slot->arch.rmap = vzalloc(npages * sizeof(*slot->arch.rmap)); 408 return kvmppc_core_create_memslot(slot, npages);
314 if (!slot->arch.rmap)
315 return -ENOMEM;
316
317 return 0;
318} 409}
319 410
320int kvm_arch_prepare_memory_region(struct kvm *kvm, 411int kvm_arch_prepare_memory_region(struct kvm *kvm,
@@ -323,7 +414,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
323 struct kvm_userspace_memory_region *mem, 414 struct kvm_userspace_memory_region *mem,
324 int user_alloc) 415 int user_alloc)
325{ 416{
326 return kvmppc_core_prepare_memory_region(kvm, mem); 417 return kvmppc_core_prepare_memory_region(kvm, memslot, mem);
327} 418}
328 419
329void kvm_arch_commit_memory_region(struct kvm *kvm, 420void kvm_arch_commit_memory_region(struct kvm *kvm,
@@ -331,7 +422,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
331 struct kvm_memory_slot old, 422 struct kvm_memory_slot old,
332 int user_alloc) 423 int user_alloc)
333{ 424{
334 kvmppc_core_commit_memory_region(kvm, mem); 425 kvmppc_core_commit_memory_region(kvm, mem, old);
335} 426}
336 427
337void kvm_arch_flush_shadow_all(struct kvm *kvm) 428void kvm_arch_flush_shadow_all(struct kvm *kvm)
@@ -341,6 +432,7 @@ void kvm_arch_flush_shadow_all(struct kvm *kvm)
341void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 432void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
342 struct kvm_memory_slot *slot) 433 struct kvm_memory_slot *slot)
343{ 434{
435 kvmppc_core_flush_memslot(kvm, slot);
344} 436}
345 437
346struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) 438struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
@@ -354,6 +446,11 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
354 return vcpu; 446 return vcpu;
355} 447}
356 448
449int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
450{
451 return 0;
452}
453
357void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) 454void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
358{ 455{
359 /* Make sure we're not using the vcpu anymore */ 456 /* Make sure we're not using the vcpu anymore */
@@ -390,6 +487,8 @@ enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer)
390 487
391int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) 488int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
392{ 489{
490 int ret;
491
393 hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 492 hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
394 tasklet_init(&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu); 493 tasklet_init(&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu);
395 vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup; 494 vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup;
@@ -398,13 +497,14 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
398#ifdef CONFIG_KVM_EXIT_TIMING 497#ifdef CONFIG_KVM_EXIT_TIMING
399 mutex_init(&vcpu->arch.exit_timing_lock); 498 mutex_init(&vcpu->arch.exit_timing_lock);
400#endif 499#endif
401 500 ret = kvmppc_subarch_vcpu_init(vcpu);
402 return 0; 501 return ret;
403} 502}
404 503
405void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) 504void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
406{ 505{
407 kvmppc_mmu_destroy(vcpu); 506 kvmppc_mmu_destroy(vcpu);
507 kvmppc_subarch_vcpu_uninit(vcpu);
408} 508}
409 509
410void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 510void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
@@ -420,7 +520,6 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
420 mtspr(SPRN_VRSAVE, vcpu->arch.vrsave); 520 mtspr(SPRN_VRSAVE, vcpu->arch.vrsave);
421#endif 521#endif
422 kvmppc_core_vcpu_load(vcpu, cpu); 522 kvmppc_core_vcpu_load(vcpu, cpu);
423 vcpu->cpu = smp_processor_id();
424} 523}
425 524
426void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) 525void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
@@ -429,7 +528,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
429#ifdef CONFIG_BOOKE 528#ifdef CONFIG_BOOKE
430 vcpu->arch.vrsave = mfspr(SPRN_VRSAVE); 529 vcpu->arch.vrsave = mfspr(SPRN_VRSAVE);
431#endif 530#endif
432 vcpu->cpu = -1;
433} 531}
434 532
435int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 533int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
@@ -527,6 +625,13 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
527 vcpu->mmio_is_write = 0; 625 vcpu->mmio_is_write = 0;
528 vcpu->arch.mmio_sign_extend = 0; 626 vcpu->arch.mmio_sign_extend = 0;
529 627
628 if (!kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr,
629 bytes, &run->mmio.data)) {
630 kvmppc_complete_mmio_load(vcpu, run);
631 vcpu->mmio_needed = 0;
632 return EMULATE_DONE;
633 }
634
530 return EMULATE_DO_MMIO; 635 return EMULATE_DO_MMIO;
531} 636}
532 637
@@ -536,8 +641,8 @@ int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
536{ 641{
537 int r; 642 int r;
538 643
539 r = kvmppc_handle_load(run, vcpu, rt, bytes, is_bigendian);
540 vcpu->arch.mmio_sign_extend = 1; 644 vcpu->arch.mmio_sign_extend = 1;
645 r = kvmppc_handle_load(run, vcpu, rt, bytes, is_bigendian);
541 646
542 return r; 647 return r;
543} 648}
@@ -575,6 +680,13 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
575 } 680 }
576 } 681 }
577 682
683 if (!kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr,
684 bytes, &run->mmio.data)) {
685 kvmppc_complete_mmio_load(vcpu, run);
686 vcpu->mmio_needed = 0;
687 return EMULATE_DONE;
688 }
689
578 return EMULATE_DO_MMIO; 690 return EMULATE_DO_MMIO;
579} 691}
580 692
@@ -649,6 +761,12 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
649 r = 0; 761 r = 0;
650 vcpu->arch.papr_enabled = true; 762 vcpu->arch.papr_enabled = true;
651 break; 763 break;
764#ifdef CONFIG_BOOKE
765 case KVM_CAP_PPC_BOOKE_WATCHDOG:
766 r = 0;
767 vcpu->arch.watchdog_enabled = true;
768 break;
769#endif
652#if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC) 770#if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
653 case KVM_CAP_SW_TLB: { 771 case KVM_CAP_SW_TLB: {
654 struct kvm_config_tlb cfg; 772 struct kvm_config_tlb cfg;
@@ -751,9 +869,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
751 869
752static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo) 870static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
753{ 871{
872 u32 inst_nop = 0x60000000;
873#ifdef CONFIG_KVM_BOOKE_HV
874 u32 inst_sc1 = 0x44000022;
875 pvinfo->hcall[0] = inst_sc1;
876 pvinfo->hcall[1] = inst_nop;
877 pvinfo->hcall[2] = inst_nop;
878 pvinfo->hcall[3] = inst_nop;
879#else
754 u32 inst_lis = 0x3c000000; 880 u32 inst_lis = 0x3c000000;
755 u32 inst_ori = 0x60000000; 881 u32 inst_ori = 0x60000000;
756 u32 inst_nop = 0x60000000;
757 u32 inst_sc = 0x44000002; 882 u32 inst_sc = 0x44000002;
758 u32 inst_imm_mask = 0xffff; 883 u32 inst_imm_mask = 0xffff;
759 884
@@ -770,6 +895,9 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
770 pvinfo->hcall[1] = inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask); 895 pvinfo->hcall[1] = inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask);
771 pvinfo->hcall[2] = inst_sc; 896 pvinfo->hcall[2] = inst_sc;
772 pvinfo->hcall[3] = inst_nop; 897 pvinfo->hcall[3] = inst_nop;
898#endif
899
900 pvinfo->flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
773 901
774 return 0; 902 return 0;
775} 903}
@@ -832,6 +960,17 @@ long kvm_arch_vm_ioctl(struct file *filp,
832 r = 0; 960 r = 0;
833 break; 961 break;
834 } 962 }
963
964 case KVM_PPC_GET_HTAB_FD: {
965 struct kvm *kvm = filp->private_data;
966 struct kvm_get_htab_fd ghf;
967
968 r = -EFAULT;
969 if (copy_from_user(&ghf, argp, sizeof(ghf)))
970 break;
971 r = kvm_vm_ioctl_get_htab_fd(kvm, &ghf);
972 break;
973 }
835#endif /* CONFIG_KVM_BOOK3S_64_HV */ 974#endif /* CONFIG_KVM_BOOK3S_64_HV */
836 975
837#ifdef CONFIG_PPC_BOOK3S_64 976#ifdef CONFIG_PPC_BOOK3S_64
diff --git a/arch/powerpc/kvm/trace.h b/arch/powerpc/kvm/trace.h
index ddb6a2149d44..e326489a5420 100644
--- a/arch/powerpc/kvm/trace.h
+++ b/arch/powerpc/kvm/trace.h
@@ -31,6 +31,126 @@ TRACE_EVENT(kvm_ppc_instr,
31 __entry->inst, __entry->pc, __entry->emulate) 31 __entry->inst, __entry->pc, __entry->emulate)
32); 32);
33 33
34#ifdef CONFIG_PPC_BOOK3S
35#define kvm_trace_symbol_exit \
36 {0x100, "SYSTEM_RESET"}, \
37 {0x200, "MACHINE_CHECK"}, \
38 {0x300, "DATA_STORAGE"}, \
39 {0x380, "DATA_SEGMENT"}, \
40 {0x400, "INST_STORAGE"}, \
41 {0x480, "INST_SEGMENT"}, \
42 {0x500, "EXTERNAL"}, \
43 {0x501, "EXTERNAL_LEVEL"}, \
44 {0x502, "EXTERNAL_HV"}, \
45 {0x600, "ALIGNMENT"}, \
46 {0x700, "PROGRAM"}, \
47 {0x800, "FP_UNAVAIL"}, \
48 {0x900, "DECREMENTER"}, \
49 {0x980, "HV_DECREMENTER"}, \
50 {0xc00, "SYSCALL"}, \
51 {0xd00, "TRACE"}, \
52 {0xe00, "H_DATA_STORAGE"}, \
53 {0xe20, "H_INST_STORAGE"}, \
54 {0xe40, "H_EMUL_ASSIST"}, \
55 {0xf00, "PERFMON"}, \
56 {0xf20, "ALTIVEC"}, \
57 {0xf40, "VSX"}
58#else
59#define kvm_trace_symbol_exit \
60 {0, "CRITICAL"}, \
61 {1, "MACHINE_CHECK"}, \
62 {2, "DATA_STORAGE"}, \
63 {3, "INST_STORAGE"}, \
64 {4, "EXTERNAL"}, \
65 {5, "ALIGNMENT"}, \
66 {6, "PROGRAM"}, \
67 {7, "FP_UNAVAIL"}, \
68 {8, "SYSCALL"}, \
69 {9, "AP_UNAVAIL"}, \
70 {10, "DECREMENTER"}, \
71 {11, "FIT"}, \
72 {12, "WATCHDOG"}, \
73 {13, "DTLB_MISS"}, \
74 {14, "ITLB_MISS"}, \
75 {15, "DEBUG"}, \
76 {32, "SPE_UNAVAIL"}, \
77 {33, "SPE_FP_DATA"}, \
78 {34, "SPE_FP_ROUND"}, \
79 {35, "PERFORMANCE_MONITOR"}, \
80 {36, "DOORBELL"}, \
81 {37, "DOORBELL_CRITICAL"}, \
82 {38, "GUEST_DBELL"}, \
83 {39, "GUEST_DBELL_CRIT"}, \
84 {40, "HV_SYSCALL"}, \
85 {41, "HV_PRIV"}
86#endif
87
88TRACE_EVENT(kvm_exit,
89 TP_PROTO(unsigned int exit_nr, struct kvm_vcpu *vcpu),
90 TP_ARGS(exit_nr, vcpu),
91
92 TP_STRUCT__entry(
93 __field( unsigned int, exit_nr )
94 __field( unsigned long, pc )
95 __field( unsigned long, msr )
96 __field( unsigned long, dar )
97#ifdef CONFIG_KVM_BOOK3S_PR
98 __field( unsigned long, srr1 )
99#endif
100 __field( unsigned long, last_inst )
101 ),
102
103 TP_fast_assign(
104#ifdef CONFIG_KVM_BOOK3S_PR
105 struct kvmppc_book3s_shadow_vcpu *svcpu;
106#endif
107 __entry->exit_nr = exit_nr;
108 __entry->pc = kvmppc_get_pc(vcpu);
109 __entry->dar = kvmppc_get_fault_dar(vcpu);
110 __entry->msr = vcpu->arch.shared->msr;
111#ifdef CONFIG_KVM_BOOK3S_PR
112 svcpu = svcpu_get(vcpu);
113 __entry->srr1 = svcpu->shadow_srr1;
114 svcpu_put(svcpu);
115#endif
116 __entry->last_inst = vcpu->arch.last_inst;
117 ),
118
119 TP_printk("exit=%s"
120 " | pc=0x%lx"
121 " | msr=0x%lx"
122 " | dar=0x%lx"
123#ifdef CONFIG_KVM_BOOK3S_PR
124 " | srr1=0x%lx"
125#endif
126 " | last_inst=0x%lx"
127 ,
128 __print_symbolic(__entry->exit_nr, kvm_trace_symbol_exit),
129 __entry->pc,
130 __entry->msr,
131 __entry->dar,
132#ifdef CONFIG_KVM_BOOK3S_PR
133 __entry->srr1,
134#endif
135 __entry->last_inst
136 )
137);
138
139TRACE_EVENT(kvm_unmap_hva,
140 TP_PROTO(unsigned long hva),
141 TP_ARGS(hva),
142
143 TP_STRUCT__entry(
144 __field( unsigned long, hva )
145 ),
146
147 TP_fast_assign(
148 __entry->hva = hva;
149 ),
150
151 TP_printk("unmap hva 0x%lx\n", __entry->hva)
152);
153
34TRACE_EVENT(kvm_stlb_inval, 154TRACE_EVENT(kvm_stlb_inval,
35 TP_PROTO(unsigned int stlb_index), 155 TP_PROTO(unsigned int stlb_index),
36 TP_ARGS(stlb_index), 156 TP_ARGS(stlb_index),
@@ -98,41 +218,31 @@ TRACE_EVENT(kvm_gtlb_write,
98 __entry->word1, __entry->word2) 218 __entry->word1, __entry->word2)
99); 219);
100 220
101 221TRACE_EVENT(kvm_check_requests,
102/************************************************************************* 222 TP_PROTO(struct kvm_vcpu *vcpu),
103 * Book3S trace points * 223 TP_ARGS(vcpu),
104 *************************************************************************/
105
106#ifdef CONFIG_KVM_BOOK3S_PR
107
108TRACE_EVENT(kvm_book3s_exit,
109 TP_PROTO(unsigned int exit_nr, struct kvm_vcpu *vcpu),
110 TP_ARGS(exit_nr, vcpu),
111 224
112 TP_STRUCT__entry( 225 TP_STRUCT__entry(
113 __field( unsigned int, exit_nr ) 226 __field( __u32, cpu_nr )
114 __field( unsigned long, pc ) 227 __field( __u32, requests )
115 __field( unsigned long, msr )
116 __field( unsigned long, dar )
117 __field( unsigned long, srr1 )
118 ), 228 ),
119 229
120 TP_fast_assign( 230 TP_fast_assign(
121 struct kvmppc_book3s_shadow_vcpu *svcpu; 231 __entry->cpu_nr = vcpu->vcpu_id;
122 __entry->exit_nr = exit_nr; 232 __entry->requests = vcpu->requests;
123 __entry->pc = kvmppc_get_pc(vcpu);
124 __entry->dar = kvmppc_get_fault_dar(vcpu);
125 __entry->msr = vcpu->arch.shared->msr;
126 svcpu = svcpu_get(vcpu);
127 __entry->srr1 = svcpu->shadow_srr1;
128 svcpu_put(svcpu);
129 ), 233 ),
130 234
131 TP_printk("exit=0x%x | pc=0x%lx | msr=0x%lx | dar=0x%lx | srr1=0x%lx", 235 TP_printk("vcpu=%x requests=%x",
132 __entry->exit_nr, __entry->pc, __entry->msr, __entry->dar, 236 __entry->cpu_nr, __entry->requests)
133 __entry->srr1)
134); 237);
135 238
239
240/*************************************************************************
241 * Book3S trace points *
242 *************************************************************************/
243
244#ifdef CONFIG_KVM_BOOK3S_PR
245
136TRACE_EVENT(kvm_book3s_reenter, 246TRACE_EVENT(kvm_book3s_reenter,
137 TP_PROTO(int r, struct kvm_vcpu *vcpu), 247 TP_PROTO(int r, struct kvm_vcpu *vcpu),
138 TP_ARGS(r, vcpu), 248 TP_ARGS(r, vcpu),
@@ -395,6 +505,44 @@ TRACE_EVENT(kvm_booke206_gtlb_write,
395 __entry->mas2, __entry->mas7_3) 505 __entry->mas2, __entry->mas7_3)
396); 506);
397 507
508TRACE_EVENT(kvm_booke206_ref_release,
509 TP_PROTO(__u64 pfn, __u32 flags),
510 TP_ARGS(pfn, flags),
511
512 TP_STRUCT__entry(
513 __field( __u64, pfn )
514 __field( __u32, flags )
515 ),
516
517 TP_fast_assign(
518 __entry->pfn = pfn;
519 __entry->flags = flags;
520 ),
521
522 TP_printk("pfn=%llx flags=%x",
523 __entry->pfn, __entry->flags)
524);
525
526TRACE_EVENT(kvm_booke_queue_irqprio,
527 TP_PROTO(struct kvm_vcpu *vcpu, unsigned int priority),
528 TP_ARGS(vcpu, priority),
529
530 TP_STRUCT__entry(
531 __field( __u32, cpu_nr )
532 __field( __u32, priority )
533 __field( unsigned long, pending )
534 ),
535
536 TP_fast_assign(
537 __entry->cpu_nr = vcpu->vcpu_id;
538 __entry->priority = priority;
539 __entry->pending = vcpu->arch.pending_exceptions;
540 ),
541
542 TP_printk("vcpu=%x prio=%x pending=%lx",
543 __entry->cpu_nr, __entry->priority, __entry->pending)
544);
545
398#endif 546#endif
399 547
400#endif /* _TRACE_KVM_H */ 548#endif /* _TRACE_KVM_H */
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 0a6b28336eb0..3a8489a354e9 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -113,19 +113,6 @@ static int store_updates_sp(struct pt_regs *regs)
113#define MM_FAULT_CONTINUE -1 113#define MM_FAULT_CONTINUE -1
114#define MM_FAULT_ERR(sig) (sig) 114#define MM_FAULT_ERR(sig) (sig)
115 115
116static int out_of_memory(struct pt_regs *regs)
117{
118 /*
119 * We ran out of memory, or some other thing happened to us that made
120 * us unable to handle the page fault gracefully.
121 */
122 up_read(&current->mm->mmap_sem);
123 if (!user_mode(regs))
124 return MM_FAULT_ERR(SIGKILL);
125 pagefault_out_of_memory();
126 return MM_FAULT_RETURN;
127}
128
129static int do_sigbus(struct pt_regs *regs, unsigned long address) 116static int do_sigbus(struct pt_regs *regs, unsigned long address)
130{ 117{
131 siginfo_t info; 118 siginfo_t info;
@@ -169,8 +156,18 @@ static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
169 return MM_FAULT_CONTINUE; 156 return MM_FAULT_CONTINUE;
170 157
171 /* Out of memory */ 158 /* Out of memory */
172 if (fault & VM_FAULT_OOM) 159 if (fault & VM_FAULT_OOM) {
173 return out_of_memory(regs); 160 up_read(&current->mm->mmap_sem);
161
162 /*
163 * We ran out of memory, or some other thing happened to us that
164 * made us unable to handle the page fault gracefully.
165 */
166 if (!user_mode(regs))
167 return MM_FAULT_ERR(SIGKILL);
168 pagefault_out_of_memory();
169 return MM_FAULT_RETURN;
170 }
174 171
175 /* Bus error. x86 handles HWPOISON here, we'll add this if/when 172 /* Bus error. x86 handles HWPOISON here, we'll add this if/when
176 * we support the feature in HW 173 * we support the feature in HW
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 59213cfaeca9..bba87ca2b4d7 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -399,18 +399,6 @@ static unsigned long read_n_cells(int n, const unsigned int **buf)
399 return result; 399 return result;
400} 400}
401 401
402struct of_drconf_cell {
403 u64 base_addr;
404 u32 drc_index;
405 u32 reserved;
406 u32 aa_index;
407 u32 flags;
408};
409
410#define DRCONF_MEM_ASSIGNED 0x00000008
411#define DRCONF_MEM_AI_INVALID 0x00000040
412#define DRCONF_MEM_RESERVED 0x00000080
413
414/* 402/*
415 * Read the next memblock list entry from the ibm,dynamic-memory property 403 * Read the next memblock list entry from the ibm,dynamic-memory property
416 * and return the information in the provided of_drconf_cell structure. 404 * and return the information in the provided of_drconf_cell structure.
diff --git a/arch/powerpc/mm/tlb_hash64.c b/arch/powerpc/mm/tlb_hash64.c
index ae758b3ff72c..0d82ef50dc3f 100644
--- a/arch/powerpc/mm/tlb_hash64.c
+++ b/arch/powerpc/mm/tlb_hash64.c
@@ -186,8 +186,6 @@ void tlb_flush(struct mmu_gather *tlb)
186 * Because of that usage pattern, it's only available with CONFIG_HOTPLUG 186 * Because of that usage pattern, it's only available with CONFIG_HOTPLUG
187 * and is implemented for small size rather than speed. 187 * and is implemented for small size rather than speed.
188 */ 188 */
189#ifdef CONFIG_HOTPLUG
190
191void __flush_hash_table_range(struct mm_struct *mm, unsigned long start, 189void __flush_hash_table_range(struct mm_struct *mm, unsigned long start,
192 unsigned long end) 190 unsigned long end)
193{ 191{
@@ -221,5 +219,3 @@ void __flush_hash_table_range(struct mm_struct *mm, unsigned long start,
221 arch_leave_lazy_mmu_mode(); 219 arch_leave_lazy_mmu_mode();
222 local_irq_restore(flags); 220 local_irq_restore(flags);
223} 221}
224
225#endif /* CONFIG_HOTPLUG */
diff --git a/arch/powerpc/mm/tlb_nohash_low.S b/arch/powerpc/mm/tlb_nohash_low.S
index fab919fd1384..626ad081639f 100644
--- a/arch/powerpc/mm/tlb_nohash_low.S
+++ b/arch/powerpc/mm/tlb_nohash_low.S
@@ -191,12 +191,6 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
191#ifdef CONFIG_PPC_47x 191#ifdef CONFIG_PPC_47x
192 192
193/* 193/*
194 * 47x variant of icbt
195 */
196# define ICBT(CT,RA,RB) \
197 .long 0x7c00002c | ((CT) << 21) | ((RA) << 16) | ((RB) << 11)
198
199/*
200 * _tlbivax_bcast is only on 47x. We don't bother doing a runtime 194 * _tlbivax_bcast is only on 47x. We don't bother doing a runtime
201 * check though, it will blow up soon enough if we mistakenly try 195 * check though, it will blow up soon enough if we mistakenly try
202 * to use it on a 440. 196 * to use it on a 440.
@@ -208,8 +202,7 @@ _GLOBAL(_tlbivax_bcast)
208 wrteei 0 202 wrteei 0
209 mtspr SPRN_MMUCR,r5 203 mtspr SPRN_MMUCR,r5
210 isync 204 isync
211/* tlbivax 0,r3 - use .long to avoid binutils deps */ 205 PPC_TLBIVAX(0, R3)
212 .long 0x7c000624 | (r3 << 11)
213 isync 206 isync
214 eieio 207 eieio
215 tlbsync 208 tlbsync
@@ -227,11 +220,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_476_DD2)
227 bl 2f 220 bl 2f
2282: mflr r6 2212: mflr r6
229 li r7,32 222 li r7,32
230 ICBT(0,r6,r7) /* touch next cache line */ 223 PPC_ICBT(0,R6,R7) /* touch next cache line */
231 add r6,r6,r7 224 add r6,r6,r7
232 ICBT(0,r6,r7) /* touch next cache line */ 225 PPC_ICBT(0,R6,R7) /* touch next cache line */
233 add r6,r6,r7 226 add r6,r6,r7
234 ICBT(0,r6,r7) /* touch next cache line */ 227 PPC_ICBT(0,R6,R7) /* touch next cache line */
235 sync 228 sync
236 nop 229 nop
237 nop 230 nop
diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
index 1fc8109bf2f9..8a5dfaf5c6b7 100644
--- a/arch/powerpc/net/bpf_jit.h
+++ b/arch/powerpc/net/bpf_jit.h
@@ -134,6 +134,12 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
134 ___PPC_RS(a) | IMM_L(i)) 134 ___PPC_RS(a) | IMM_L(i))
135#define PPC_ORIS(d, a, i) EMIT(PPC_INST_ORIS | ___PPC_RA(d) | \ 135#define PPC_ORIS(d, a, i) EMIT(PPC_INST_ORIS | ___PPC_RA(d) | \
136 ___PPC_RS(a) | IMM_L(i)) 136 ___PPC_RS(a) | IMM_L(i))
137#define PPC_XOR(d, a, b) EMIT(PPC_INST_XOR | ___PPC_RA(d) | \
138 ___PPC_RS(a) | ___PPC_RB(b))
139#define PPC_XORI(d, a, i) EMIT(PPC_INST_XORI | ___PPC_RA(d) | \
140 ___PPC_RS(a) | IMM_L(i))
141#define PPC_XORIS(d, a, i) EMIT(PPC_INST_XORIS | ___PPC_RA(d) | \
142 ___PPC_RS(a) | IMM_L(i))
137#define PPC_SLW(d, a, s) EMIT(PPC_INST_SLW | ___PPC_RA(d) | \ 143#define PPC_SLW(d, a, s) EMIT(PPC_INST_SLW | ___PPC_RA(d) | \
138 ___PPC_RS(a) | ___PPC_RB(s)) 144 ___PPC_RS(a) | ___PPC_RB(s))
139#define PPC_SRW(d, a, s) EMIT(PPC_INST_SRW | ___PPC_RA(d) | \ 145#define PPC_SRW(d, a, s) EMIT(PPC_INST_SRW | ___PPC_RA(d) | \
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index dd1130642d07..e834f1ec23c8 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -13,6 +13,8 @@
13#include <asm/cacheflush.h> 13#include <asm/cacheflush.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/filter.h> 15#include <linux/filter.h>
16#include <linux/if_vlan.h>
17
16#include "bpf_jit.h" 18#include "bpf_jit.h"
17 19
18#ifndef __BIG_ENDIAN 20#ifndef __BIG_ENDIAN
@@ -89,6 +91,8 @@ static void bpf_jit_build_prologue(struct sk_filter *fp, u32 *image,
89 case BPF_S_ANC_IFINDEX: 91 case BPF_S_ANC_IFINDEX:
90 case BPF_S_ANC_MARK: 92 case BPF_S_ANC_MARK:
91 case BPF_S_ANC_RXHASH: 93 case BPF_S_ANC_RXHASH:
94 case BPF_S_ANC_VLAN_TAG:
95 case BPF_S_ANC_VLAN_TAG_PRESENT:
92 case BPF_S_ANC_CPU: 96 case BPF_S_ANC_CPU:
93 case BPF_S_ANC_QUEUE: 97 case BPF_S_ANC_QUEUE:
94 case BPF_S_LD_W_ABS: 98 case BPF_S_LD_W_ABS:
@@ -232,6 +236,17 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
232 if (K >= 65536) 236 if (K >= 65536)
233 PPC_ORIS(r_A, r_A, IMM_H(K)); 237 PPC_ORIS(r_A, r_A, IMM_H(K));
234 break; 238 break;
239 case BPF_S_ANC_ALU_XOR_X:
240 case BPF_S_ALU_XOR_X: /* A ^= X */
241 ctx->seen |= SEEN_XREG;
242 PPC_XOR(r_A, r_A, r_X);
243 break;
244 case BPF_S_ALU_XOR_K: /* A ^= K */
245 if (IMM_L(K))
246 PPC_XORI(r_A, r_A, IMM_L(K));
247 if (K >= 65536)
248 PPC_XORIS(r_A, r_A, IMM_H(K));
249 break;
235 case BPF_S_ALU_LSH_X: /* A <<= X; */ 250 case BPF_S_ALU_LSH_X: /* A <<= X; */
236 ctx->seen |= SEEN_XREG; 251 ctx->seen |= SEEN_XREG;
237 PPC_SLW(r_A, r_A, r_X); 252 PPC_SLW(r_A, r_A, r_X);
@@ -371,6 +386,16 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
371 PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, 386 PPC_LWZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
372 rxhash)); 387 rxhash));
373 break; 388 break;
389 case BPF_S_ANC_VLAN_TAG:
390 case BPF_S_ANC_VLAN_TAG_PRESENT:
391 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
392 PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
393 vlan_tci));
394 if (filter[i].code == BPF_S_ANC_VLAN_TAG)
395 PPC_ANDI(r_A, r_A, VLAN_VID_MASK);
396 else
397 PPC_ANDI(r_A, r_A, VLAN_TAG_PRESENT);
398 break;
374 case BPF_S_ANC_QUEUE: 399 case BPF_S_ANC_QUEUE:
375 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, 400 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
376 queue_mapping) != 2); 401 queue_mapping) != 2);
diff --git a/arch/powerpc/oprofile/op_model_power4.c b/arch/powerpc/oprofile/op_model_power4.c
index 315f9495e9b2..f444b94935f5 100644
--- a/arch/powerpc/oprofile/op_model_power4.c
+++ b/arch/powerpc/oprofile/op_model_power4.c
@@ -52,7 +52,7 @@ static int power7_marked_instr_event(u64 mmcr1)
52 for (pmc = 0; pmc < 4; pmc++) { 52 for (pmc = 0; pmc < 4; pmc++) {
53 psel = mmcr1 & (OPROFILE_PM_PMCSEL_MSK 53 psel = mmcr1 & (OPROFILE_PM_PMCSEL_MSK
54 << (OPROFILE_MAX_PMC_NUM - pmc) 54 << (OPROFILE_MAX_PMC_NUM - pmc)
55 * OPROFILE_MAX_PMC_NUM); 55 * OPROFILE_PMSEL_FIELD_WIDTH);
56 psel = (psel >> ((OPROFILE_MAX_PMC_NUM - pmc) 56 psel = (psel >> ((OPROFILE_MAX_PMC_NUM - pmc)
57 * OPROFILE_PMSEL_FIELD_WIDTH)) & ~1ULL; 57 * OPROFILE_PMSEL_FIELD_WIDTH)) & ~1ULL;
58 unit = mmcr1 & (OPROFILE_PM_UNIT_MSK 58 unit = mmcr1 & (OPROFILE_PM_UNIT_MSK
diff --git a/arch/powerpc/perf/power7-pmu.c b/arch/powerpc/perf/power7-pmu.c
index 441af08edf43..2ee01e38d5e2 100644
--- a/arch/powerpc/perf/power7-pmu.c
+++ b/arch/powerpc/perf/power7-pmu.c
@@ -54,8 +54,10 @@
54 * Layout of constraint bits: 54 * Layout of constraint bits:
55 * 6666555555555544444444443333333333222222222211111111110000000000 55 * 6666555555555544444444443333333333222222222211111111110000000000
56 * 3210987654321098765432109876543210987654321098765432109876543210 56 * 3210987654321098765432109876543210987654321098765432109876543210
57 * [ ><><><><><><> 57 * < >< ><><><><><><>
58 * NC P6P5P4P3P2P1 58 * L2 NC P6P5P4P3P2P1
59 *
60 * L2 - 16-18 - Required L2SEL value (select field)
59 * 61 *
60 * NC - number of counters 62 * NC - number of counters
61 * 15: NC error 0x8000 63 * 15: NC error 0x8000
@@ -72,7 +74,7 @@
72static int power7_get_constraint(u64 event, unsigned long *maskp, 74static int power7_get_constraint(u64 event, unsigned long *maskp,
73 unsigned long *valp) 75 unsigned long *valp)
74{ 76{
75 int pmc, sh; 77 int pmc, sh, unit;
76 unsigned long mask = 0, value = 0; 78 unsigned long mask = 0, value = 0;
77 79
78 pmc = (event >> PM_PMC_SH) & PM_PMC_MSK; 80 pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
@@ -90,6 +92,15 @@ static int power7_get_constraint(u64 event, unsigned long *maskp,
90 mask |= 0x8000; 92 mask |= 0x8000;
91 value |= 0x1000; 93 value |= 0x1000;
92 } 94 }
95
96 unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
97 if (unit == 6) {
98 /* L2SEL must be identical across events */
99 int l2sel = (event >> PM_L2SEL_SH) & PM_L2SEL_MSK;
100 mask |= 0x7 << 16;
101 value |= l2sel << 16;
102 }
103
93 *maskp = mask; 104 *maskp = mask;
94 *valp = value; 105 *valp = value;
95 return 0; 106 return 0;
diff --git a/arch/powerpc/platforms/40x/ppc40x_simple.c b/arch/powerpc/platforms/40x/ppc40x_simple.c
index 969dddcf3320..8f3920e5a046 100644
--- a/arch/powerpc/platforms/40x/ppc40x_simple.c
+++ b/arch/powerpc/platforms/40x/ppc40x_simple.c
@@ -57,7 +57,8 @@ static const char * const board[] __initconst = {
57 "amcc,makalu", 57 "amcc,makalu",
58 "apm,klondike", 58 "apm,klondike",
59 "est,hotfoot", 59 "est,hotfoot",
60 "plathome,obs600" 60 "plathome,obs600",
61 NULL
61}; 62};
62 63
63static int __init ppc40x_probe(void) 64static int __init ppc40x_probe(void)
diff --git a/arch/powerpc/platforms/44x/currituck.c b/arch/powerpc/platforms/44x/currituck.c
index 6bd89a0e0dea..ecd3890c40d7 100644
--- a/arch/powerpc/platforms/44x/currituck.c
+++ b/arch/powerpc/platforms/44x/currituck.c
@@ -46,7 +46,7 @@ static __initdata struct of_device_id ppc47x_of_bus[] = {
46 46
47/* The EEPROM is missing and the default values are bogus. This forces USB in 47/* The EEPROM is missing and the default values are bogus. This forces USB in
48 * to EHCI mode */ 48 * to EHCI mode */
49static void __devinit quirk_ppc_currituck_usb_fixup(struct pci_dev *dev) 49static void quirk_ppc_currituck_usb_fixup(struct pci_dev *dev)
50{ 50{
51 if (of_machine_is_compatible("ibm,currituck")) { 51 if (of_machine_is_compatible("ibm,currituck")) {
52 pci_write_config_dword(dev, 0xe0, 0x0114231f); 52 pci_write_config_dword(dev, 0xe0, 0x0114231f);
diff --git a/arch/powerpc/platforms/44x/virtex_ml510.c b/arch/powerpc/platforms/44x/virtex_ml510.c
index ba4a6e388a46..1fdb8748638d 100644
--- a/arch/powerpc/platforms/44x/virtex_ml510.c
+++ b/arch/powerpc/platforms/44x/virtex_ml510.c
@@ -5,7 +5,7 @@
5/** 5/**
6 * ml510_ail_quirk 6 * ml510_ail_quirk
7 */ 7 */
8static void __devinit ml510_ali_quirk(struct pci_dev *dev) 8static void ml510_ali_quirk(struct pci_dev *dev)
9{ 9{
10 /* Enable the IDE controller */ 10 /* Enable the IDE controller */
11 pci_write_config_byte(dev, 0x58, 0x4c); 11 pci_write_config_byte(dev, 0x58, 0x4c);
diff --git a/arch/powerpc/platforms/512x/Kconfig b/arch/powerpc/platforms/512x/Kconfig
index b62508b113db..c16999802ecf 100644
--- a/arch/powerpc/platforms/512x/Kconfig
+++ b/arch/powerpc/platforms/512x/Kconfig
@@ -2,7 +2,6 @@ config PPC_MPC512x
2 bool "512x-based boards" 2 bool "512x-based boards"
3 depends on 6xx 3 depends on 6xx
4 select FSL_SOC 4 select FSL_SOC
5 select FB_FSL_DIU
6 select IPIC 5 select IPIC
7 select PPC_CLOCK 6 select PPC_CLOCK
8 select PPC_PCI_CHOICE 7 select PPC_PCI_CHOICE
diff --git a/arch/powerpc/platforms/512x/mpc5121_ads.c b/arch/powerpc/platforms/512x/mpc5121_ads.c
index dcef6ade48e1..0a134e0469ef 100644
--- a/arch/powerpc/platforms/512x/mpc5121_ads.c
+++ b/arch/powerpc/platforms/512x/mpc5121_ads.c
@@ -42,7 +42,10 @@ static void __init mpc5121_ads_setup_arch(void)
42 for_each_compatible_node(np, "pci", "fsl,mpc5121-pci") 42 for_each_compatible_node(np, "pci", "fsl,mpc5121-pci")
43 mpc83xx_add_bridge(np); 43 mpc83xx_add_bridge(np);
44#endif 44#endif
45
46#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
45 mpc512x_setup_diu(); 47 mpc512x_setup_diu();
48#endif
46} 49}
47 50
48static void __init mpc5121_ads_init_IRQ(void) 51static void __init mpc5121_ads_init_IRQ(void)
diff --git a/arch/powerpc/platforms/512x/mpc512x.h b/arch/powerpc/platforms/512x/mpc512x.h
index 1ab6d11d0b19..c32b399eb952 100644
--- a/arch/powerpc/platforms/512x/mpc512x.h
+++ b/arch/powerpc/platforms/512x/mpc512x.h
@@ -16,6 +16,13 @@ extern void __init mpc512x_init(void);
16extern int __init mpc5121_clk_init(void); 16extern int __init mpc5121_clk_init(void);
17void __init mpc512x_declare_of_platform_devices(void); 17void __init mpc512x_declare_of_platform_devices(void);
18extern void mpc512x_restart(char *cmd); 18extern void mpc512x_restart(char *cmd);
19extern void mpc512x_init_diu(void); 19
20extern void mpc512x_setup_diu(void); 20#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
21void mpc512x_init_diu(void);
22void mpc512x_setup_diu(void);
23#else
24#define mpc512x_init_diu NULL
25#define mpc512x_setup_diu NULL
26#endif
27
21#endif /* __MPC512X_H__ */ 28#endif /* __MPC512X_H__ */
diff --git a/arch/powerpc/platforms/512x/mpc512x_shared.c b/arch/powerpc/platforms/512x/mpc512x_shared.c
index 1650e090ef3a..35f14fda108a 100644
--- a/arch/powerpc/platforms/512x/mpc512x_shared.c
+++ b/arch/powerpc/platforms/512x/mpc512x_shared.c
@@ -58,6 +58,8 @@ void mpc512x_restart(char *cmd)
58 ; 58 ;
59} 59}
60 60
61#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
62
61struct fsl_diu_shared_fb { 63struct fsl_diu_shared_fb {
62 u8 gamma[0x300]; /* 32-bit aligned! */ 64 u8 gamma[0x300]; /* 32-bit aligned! */
63 struct diu_ad ad0; /* 32-bit aligned! */ 65 struct diu_ad ad0; /* 32-bit aligned! */
@@ -66,25 +68,6 @@ struct fsl_diu_shared_fb {
66 bool in_use; 68 bool in_use;
67}; 69};
68 70
69u32 mpc512x_get_pixel_format(enum fsl_diu_monitor_port port,
70 unsigned int bits_per_pixel)
71{
72 switch (bits_per_pixel) {
73 case 32:
74 return 0x88883316;
75 case 24:
76 return 0x88082219;
77 case 16:
78 return 0x65053118;
79 }
80 return 0x00000400;
81}
82
83void mpc512x_set_gamma_table(enum fsl_diu_monitor_port port,
84 char *gamma_table_base)
85{
86}
87
88void mpc512x_set_monitor_port(enum fsl_diu_monitor_port port) 71void mpc512x_set_monitor_port(enum fsl_diu_monitor_port port)
89{ 72{
90} 73}
@@ -320,14 +303,14 @@ void __init mpc512x_setup_diu(void)
320 } 303 }
321 } 304 }
322 305
323 diu_ops.get_pixel_format = mpc512x_get_pixel_format;
324 diu_ops.set_gamma_table = mpc512x_set_gamma_table;
325 diu_ops.set_monitor_port = mpc512x_set_monitor_port; 306 diu_ops.set_monitor_port = mpc512x_set_monitor_port;
326 diu_ops.set_pixel_clock = mpc512x_set_pixel_clock; 307 diu_ops.set_pixel_clock = mpc512x_set_pixel_clock;
327 diu_ops.valid_monitor_port = mpc512x_valid_monitor_port; 308 diu_ops.valid_monitor_port = mpc512x_valid_monitor_port;
328 diu_ops.release_bootmem = mpc512x_release_bootmem; 309 diu_ops.release_bootmem = mpc512x_release_bootmem;
329} 310}
330 311
312#endif
313
331void __init mpc512x_init_IRQ(void) 314void __init mpc512x_init_IRQ(void)
332{ 315{
333 struct device_node *np; 316 struct device_node *np;
diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c
index 448d862bcf3d..1843bc932011 100644
--- a/arch/powerpc/platforms/52xx/lite5200.c
+++ b/arch/powerpc/platforms/52xx/lite5200.c
@@ -4,7 +4,7 @@
4 * Written by: Grant Likely <grant.likely@secretlab.ca> 4 * Written by: Grant Likely <grant.likely@secretlab.ca>
5 * 5 *
6 * Copyright (C) Secret Lab Technologies Ltd. 2006. All rights reserved. 6 * Copyright (C) Secret Lab Technologies Ltd. 2006. All rights reserved.
7 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved. 7 * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
8 * 8 *
9 * Description: 9 * Description:
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
diff --git a/arch/powerpc/platforms/52xx/mpc5200_simple.c b/arch/powerpc/platforms/52xx/mpc5200_simple.c
index 9cf36020cf0d..792a301a0bf0 100644
--- a/arch/powerpc/platforms/52xx/mpc5200_simple.c
+++ b/arch/powerpc/platforms/52xx/mpc5200_simple.c
@@ -50,6 +50,7 @@ static void __init mpc5200_simple_setup_arch(void)
50 50
51/* list of the supported boards */ 51/* list of the supported boards */
52static const char *board[] __initdata = { 52static const char *board[] __initdata = {
53 "anonymous,a3m071",
53 "anonymous,a4m072", 54 "anonymous,a4m072",
54 "anon,charon", 55 "anon,charon",
55 "ifm,o2d", 56 "ifm,o2d",
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
index a51cb07bd663..692998244d2c 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
@@ -669,7 +669,7 @@ static struct miscdevice mpc52xx_wdt_miscdev = {
669 .fops = &mpc52xx_wdt_fops, 669 .fops = &mpc52xx_wdt_fops,
670}; 670};
671 671
672static int __devinit mpc52xx_gpt_wdt_init(void) 672static int mpc52xx_gpt_wdt_init(void)
673{ 673{
674 int err; 674 int err;
675 675
@@ -704,7 +704,7 @@ static int mpc52xx_gpt_wdt_setup(struct mpc52xx_gpt_priv *gpt,
704 704
705#else 705#else
706 706
707static int __devinit mpc52xx_gpt_wdt_init(void) 707static int mpc52xx_gpt_wdt_init(void)
708{ 708{
709 return 0; 709 return 0;
710} 710}
@@ -720,7 +720,7 @@ static inline int mpc52xx_gpt_wdt_setup(struct mpc52xx_gpt_priv *gpt,
720/* --------------------------------------------------------------------- 720/* ---------------------------------------------------------------------
721 * of_platform bus binding code 721 * of_platform bus binding code
722 */ 722 */
723static int __devinit mpc52xx_gpt_probe(struct platform_device *ofdev) 723static int mpc52xx_gpt_probe(struct platform_device *ofdev)
724{ 724{
725 struct mpc52xx_gpt_priv *gpt; 725 struct mpc52xx_gpt_priv *gpt;
726 726
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c b/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
index 2351f9e0fb6f..f9f4537f546d 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
@@ -470,7 +470,7 @@ void mpc52xx_lpbfifo_abort(struct mpc52xx_lpbfifo_request *req)
470} 470}
471EXPORT_SYMBOL(mpc52xx_lpbfifo_abort); 471EXPORT_SYMBOL(mpc52xx_lpbfifo_abort);
472 472
473static int __devinit mpc52xx_lpbfifo_probe(struct platform_device *op) 473static int mpc52xx_lpbfifo_probe(struct platform_device *op)
474{ 474{
475 struct resource res; 475 struct resource res;
476 int rc = -ENOMEM; 476 int rc = -ENOMEM;
@@ -540,7 +540,7 @@ static int __devinit mpc52xx_lpbfifo_probe(struct platform_device *op)
540} 540}
541 541
542 542
543static int __devexit mpc52xx_lpbfifo_remove(struct platform_device *op) 543static int mpc52xx_lpbfifo_remove(struct platform_device *op)
544{ 544{
545 if (lpbfifo.dev != &op->dev) 545 if (lpbfifo.dev != &op->dev)
546 return 0; 546 return 0;
@@ -564,7 +564,7 @@ static int __devexit mpc52xx_lpbfifo_remove(struct platform_device *op)
564 return 0; 564 return 0;
565} 565}
566 566
567static struct of_device_id mpc52xx_lpbfifo_match[] __devinitconst = { 567static struct of_device_id mpc52xx_lpbfifo_match[] = {
568 { .compatible = "fsl,mpc5200-lpbfifo", }, 568 { .compatible = "fsl,mpc5200-lpbfifo", },
569 {}, 569 {},
570}; 570};
@@ -576,20 +576,6 @@ static struct platform_driver mpc52xx_lpbfifo_driver = {
576 .of_match_table = mpc52xx_lpbfifo_match, 576 .of_match_table = mpc52xx_lpbfifo_match,
577 }, 577 },
578 .probe = mpc52xx_lpbfifo_probe, 578 .probe = mpc52xx_lpbfifo_probe,
579 .remove = __devexit_p(mpc52xx_lpbfifo_remove), 579 .remove = mpc52xx_lpbfifo_remove,
580}; 580};
581 581module_platform_driver(mpc52xx_lpbfifo_driver);
582/***********************************************************************
583 * Module init/exit
584 */
585static int __init mpc52xx_lpbfifo_init(void)
586{
587 return platform_driver_register(&mpc52xx_lpbfifo_driver);
588}
589module_init(mpc52xx_lpbfifo_init);
590
591static void __exit mpc52xx_lpbfifo_exit(void)
592{
593 platform_driver_unregister(&mpc52xx_lpbfifo_driver);
594}
595module_exit(mpc52xx_lpbfifo_exit);
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pic.c b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
index 8520b58a5e9a..b89ef65392dc 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_pic.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
@@ -372,10 +372,11 @@ static int mpc52xx_irqhost_map(struct irq_domain *h, unsigned int virq,
372 case MPC52xx_IRQ_L1_MAIN: irqchip = &mpc52xx_main_irqchip; break; 372 case MPC52xx_IRQ_L1_MAIN: irqchip = &mpc52xx_main_irqchip; break;
373 case MPC52xx_IRQ_L1_PERP: irqchip = &mpc52xx_periph_irqchip; break; 373 case MPC52xx_IRQ_L1_PERP: irqchip = &mpc52xx_periph_irqchip; break;
374 case MPC52xx_IRQ_L1_SDMA: irqchip = &mpc52xx_sdma_irqchip; break; 374 case MPC52xx_IRQ_L1_SDMA: irqchip = &mpc52xx_sdma_irqchip; break;
375 default: 375 case MPC52xx_IRQ_L1_CRIT:
376 pr_err("%s: invalid irq: virq=%i, l1=%i, l2=%i\n", 376 pr_warn("%s: Critical IRQ #%d is unsupported! Nopping it.\n",
377 __func__, virq, l1irq, l2irq); 377 __func__, l2irq);
378 return -EINVAL; 378 irq_set_chip(virq, &no_irq_chip);
379 return 0;
379 } 380 }
380 381
381 irq_set_chip_and_handler(virq, irqchip, handle_level_irq); 382 irq_set_chip_and_handler(virq, irqchip, handle_level_irq);
diff --git a/arch/powerpc/platforms/82xx/ep8248e.c b/arch/powerpc/platforms/82xx/ep8248e.c
index 10ff526cd046..79799b29ffe2 100644
--- a/arch/powerpc/platforms/82xx/ep8248e.c
+++ b/arch/powerpc/platforms/82xx/ep8248e.c
@@ -111,7 +111,7 @@ static struct mdiobb_ctrl ep8248e_mdio_ctrl = {
111 .ops = &ep8248e_mdio_ops, 111 .ops = &ep8248e_mdio_ops,
112}; 112};
113 113
114static int __devinit ep8248e_mdio_probe(struct platform_device *ofdev) 114static int ep8248e_mdio_probe(struct platform_device *ofdev)
115{ 115{
116 struct mii_bus *bus; 116 struct mii_bus *bus;
117 struct resource res; 117 struct resource res;
diff --git a/arch/powerpc/platforms/82xx/pq2ads-pci-pic.c b/arch/powerpc/platforms/82xx/pq2ads-pci-pic.c
index 328d221fd1c0..74861a7fb807 100644
--- a/arch/powerpc/platforms/82xx/pq2ads-pci-pic.c
+++ b/arch/powerpc/platforms/82xx/pq2ads-pci-pic.c
@@ -16,7 +16,6 @@
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/irq.h> 17#include <linux/irq.h>
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/bootmem.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21 20
22#include <asm/io.h> 21#include <asm/io.h>
@@ -149,7 +148,7 @@ int __init pq2ads_pci_init_irq(void)
149 priv->regs = of_iomap(np, 0); 148 priv->regs = of_iomap(np, 0);
150 if (!priv->regs) { 149 if (!priv->regs) {
151 printk(KERN_ERR "Cannot map PCI PIC registers.\n"); 150 printk(KERN_ERR "Cannot map PCI PIC registers.\n");
152 goto out_free_bootmem; 151 goto out_free_kmalloc;
153 } 152 }
154 153
155 /* mask all PCI interrupts */ 154 /* mask all PCI interrupts */
@@ -171,9 +170,8 @@ int __init pq2ads_pci_init_irq(void)
171 170
172out_unmap_regs: 171out_unmap_regs:
173 iounmap(priv->regs); 172 iounmap(priv->regs);
174out_free_bootmem: 173out_free_kmalloc:
175 free_bootmem((unsigned long)priv, 174 kfree(priv);
176 sizeof(struct pq2ads_pci_pic));
177 of_node_put(np); 175 of_node_put(np);
178out_unmap_irq: 176out_unmap_irq:
179 irq_dispose_mapping(irq); 177 irq_dispose_mapping(irq);
diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index ef6537b8ed33..624cb51d19c9 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -145,8 +145,7 @@ static int mcu_gpiochip_remove(struct mcu *mcu)
145 return gpiochip_remove(&mcu->gc); 145 return gpiochip_remove(&mcu->gc);
146} 146}
147 147
148static int __devinit mcu_probe(struct i2c_client *client, 148static int mcu_probe(struct i2c_client *client, const struct i2c_device_id *id)
149 const struct i2c_device_id *id)
150{ 149{
151 struct mcu *mcu; 150 struct mcu *mcu;
152 int ret; 151 int ret;
@@ -188,7 +187,7 @@ err:
188 return ret; 187 return ret;
189} 188}
190 189
191static int __devexit mcu_remove(struct i2c_client *client) 190static int mcu_remove(struct i2c_client *client)
192{ 191{
193 struct mcu *mcu = i2c_get_clientdata(client); 192 struct mcu *mcu = i2c_get_clientdata(client);
194 int ret; 193 int ret;
@@ -216,7 +215,7 @@ static const struct i2c_device_id mcu_ids[] = {
216}; 215};
217MODULE_DEVICE_TABLE(i2c, mcu_ids); 216MODULE_DEVICE_TABLE(i2c, mcu_ids);
218 217
219static struct of_device_id mcu_of_match_table[] __devinitdata = { 218static struct of_device_id mcu_of_match_table[] = {
220 { .compatible = "fsl,mcu-mpc8349emitx", }, 219 { .compatible = "fsl,mcu-mpc8349emitx", },
221 { }, 220 { },
222}; 221};
@@ -228,7 +227,7 @@ static struct i2c_driver mcu_driver = {
228 .of_match_table = mcu_of_match_table, 227 .of_match_table = mcu_of_match_table,
229 }, 228 },
230 .probe = mcu_probe, 229 .probe = mcu_probe,
231 .remove = __devexit_p(mcu_remove), 230 .remove = mcu_remove,
232 .id_table = mcu_ids, 231 .id_table = mcu_ids,
233}; 232};
234 233
diff --git a/arch/powerpc/platforms/83xx/mpc832x_mds.c b/arch/powerpc/platforms/83xx/mpc832x_mds.c
index d440435e055c..8d762203eeff 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_mds.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved. 2 * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Description: 4 * Description:
5 * MPC832xE MDS board specific routines. 5 * MPC832xE MDS board specific routines.
diff --git a/arch/powerpc/platforms/83xx/mpc836x_mds.c b/arch/powerpc/platforms/83xx/mpc836x_mds.c
index 1b1f6c8a1a12..1a26d2f83401 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_mds.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved. 2 * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Author: Li Yang <LeoLi@freescale.com> 4 * Author: Li Yang <LeoLi@freescale.com>
5 * Yin Olivia <Hong-hua.Yin@freescale.com> 5 * Yin Olivia <Hong-hua.Yin@freescale.com>
diff --git a/arch/powerpc/platforms/83xx/mpc836x_rdk.c b/arch/powerpc/platforms/83xx/mpc836x_rdk.c
index f8769d713d61..b63b42d11d6c 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_rdk.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_rdk.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * MPC8360E-RDK board file. 2 * MPC8360E-RDK board file.
3 * 3 *
4 * Copyright (c) 2006 Freescale Semicondutor, Inc. 4 * Copyright (c) 2006 Freescale Semiconductor, Inc.
5 * Copyright (c) 2007-2008 MontaVista Software, Inc. 5 * Copyright (c) 2007-2008 MontaVista Software, Inc.
6 * 6 *
7 * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 7 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
diff --git a/arch/powerpc/platforms/83xx/mpc837x_rdb.c b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
index eca1f0960fff..9813c81e8e5b 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/powerpc/platforms/83xx/mpc837x_rdb.c 2 * arch/powerpc/platforms/83xx/mpc837x_rdb.c
3 * 3 *
4 * Copyright (C) 2007 Freescale Semicondutor, Inc. All rights reserved. 4 * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved.
5 * 5 *
6 * MPC837x RDB board specific routines 6 * MPC837x RDB board specific routines
7 * 7 *
diff --git a/arch/powerpc/platforms/85xx/corenet_ds.c b/arch/powerpc/platforms/85xx/corenet_ds.c
index ed69c9250717..6f355d8c92f6 100644
--- a/arch/powerpc/platforms/85xx/corenet_ds.c
+++ b/arch/powerpc/platforms/85xx/corenet_ds.c
@@ -64,7 +64,7 @@ void __init corenet_ds_setup_arch(void)
64 pr_info("%s board from Freescale Semiconductor\n", ppc_md.name); 64 pr_info("%s board from Freescale Semiconductor\n", ppc_md.name);
65} 65}
66 66
67static const struct of_device_id of_device_ids[] __devinitconst = { 67static const struct of_device_id of_device_ids[] = {
68 { 68 {
69 .compatible = "simple-bus" 69 .compatible = "simple-bus"
70 }, 70 },
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_cds.c b/arch/powerpc/platforms/85xx/mpc85xx_cds.c
index c474505ad0d0..7a31a0e1df29 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_cds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_cds.c
@@ -154,7 +154,7 @@ static void __init mpc85xx_cds_pci_irq_fixup(struct pci_dev *dev)
154 } 154 }
155} 155}
156 156
157static void __devinit skip_fake_bridge(struct pci_dev *dev) 157static void skip_fake_bridge(struct pci_dev *dev)
158{ 158{
159 /* Make it an error to skip the fake bridge 159 /* Make it an error to skip the fake bridge
160 * in pci_setup_device() in probe.c */ 160 * in pci_setup_device() in probe.c */
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index 8498f7323470..bd12588fa252 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006-2010, 2012 Freescale Semicondutor, Inc. 2 * Copyright (C) 2006-2010, 2012 Freescale Semiconductor, Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Author: Andy Fleming <afleming@freescale.com> 5 * Author: Andy Fleming <afleming@freescale.com>
diff --git a/arch/powerpc/platforms/85xx/p1022_ds.c b/arch/powerpc/platforms/85xx/p1022_ds.c
index 8b0e05f4f60c..e346edf7f157 100644
--- a/arch/powerpc/platforms/85xx/p1022_ds.c
+++ b/arch/powerpc/platforms/85xx/p1022_ds.c
@@ -249,7 +249,7 @@ static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port)
249 goto exit; 249 goto exit;
250 } 250 }
251 251
252 iprop = of_get_property(law_node, "fsl,num-laws", 0); 252 iprop = of_get_property(law_node, "fsl,num-laws", NULL);
253 if (!iprop) { 253 if (!iprop) {
254 pr_err("p1022ds: LAW node is missing fsl,num-laws property\n"); 254 pr_err("p1022ds: LAW node is missing fsl,num-laws property\n");
255 goto exit; 255 goto exit;
@@ -539,7 +539,7 @@ static void __init p1022_ds_setup_arch(void)
539 }; 539 };
540 540
541 /* 541 /*
542 * prom_update_property() is called before 542 * of_update_property() is called before
543 * kmalloc() is available, so the 'new' object 543 * kmalloc() is available, so the 'new' object
544 * should be allocated in the global area. 544 * should be allocated in the global area.
545 * The easiest way is to do that is to 545 * The easiest way is to do that is to
@@ -548,7 +548,7 @@ static void __init p1022_ds_setup_arch(void)
548 */ 548 */
549 pr_info("p1022ds: disabling %s node", 549 pr_info("p1022ds: disabling %s node",
550 np2->full_name); 550 np2->full_name);
551 prom_update_property(np2, &nor_status); 551 of_update_property(np2, &nor_status);
552 of_node_put(np2); 552 of_node_put(np2);
553 } 553 }
554 554
@@ -564,7 +564,7 @@ static void __init p1022_ds_setup_arch(void)
564 564
565 pr_info("p1022ds: disabling %s node", 565 pr_info("p1022ds: disabling %s node",
566 np2->full_name); 566 np2->full_name);
567 prom_update_property(np2, &nand_status); 567 of_update_property(np2, &nand_status);
568 of_node_put(np2); 568 of_node_put(np2);
569 } 569 }
570 570
diff --git a/arch/powerpc/platforms/85xx/smp.c b/arch/powerpc/platforms/85xx/smp.c
index 6fcfa12e5c56..148c2f2d9780 100644
--- a/arch/powerpc/platforms/85xx/smp.c
+++ b/arch/powerpc/platforms/85xx/smp.c
@@ -128,6 +128,19 @@ static void __cpuinit smp_85xx_mach_cpu_die(void)
128} 128}
129#endif 129#endif
130 130
131static inline void flush_spin_table(void *spin_table)
132{
133 flush_dcache_range((ulong)spin_table,
134 (ulong)spin_table + sizeof(struct epapr_spin_table));
135}
136
137static inline u32 read_spin_table_addr_l(void *spin_table)
138{
139 flush_dcache_range((ulong)spin_table,
140 (ulong)spin_table + sizeof(struct epapr_spin_table));
141 return in_be32(&((struct epapr_spin_table *)spin_table)->addr_l);
142}
143
131static int __cpuinit smp_85xx_kick_cpu(int nr) 144static int __cpuinit smp_85xx_kick_cpu(int nr)
132{ 145{
133 unsigned long flags; 146 unsigned long flags;
@@ -161,8 +174,8 @@ static int __cpuinit smp_85xx_kick_cpu(int nr)
161 174
162 /* Map the spin table */ 175 /* Map the spin table */
163 if (ioremappable) 176 if (ioremappable)
164 spin_table = ioremap(*cpu_rel_addr, 177 spin_table = ioremap_prot(*cpu_rel_addr,
165 sizeof(struct epapr_spin_table)); 178 sizeof(struct epapr_spin_table), _PAGE_COHERENT);
166 else 179 else
167 spin_table = phys_to_virt(*cpu_rel_addr); 180 spin_table = phys_to_virt(*cpu_rel_addr);
168 181
@@ -173,7 +186,16 @@ static int __cpuinit smp_85xx_kick_cpu(int nr)
173 generic_set_cpu_up(nr); 186 generic_set_cpu_up(nr);
174 187
175 if (system_state == SYSTEM_RUNNING) { 188 if (system_state == SYSTEM_RUNNING) {
189 /*
190 * To keep it compatible with old boot program which uses
191 * cache-inhibit spin table, we need to flush the cache
192 * before accessing spin table to invalidate any staled data.
193 * We also need to flush the cache after writing to spin
194 * table to push data out.
195 */
196 flush_spin_table(spin_table);
176 out_be32(&spin_table->addr_l, 0); 197 out_be32(&spin_table->addr_l, 0);
198 flush_spin_table(spin_table);
177 199
178 /* 200 /*
179 * We don't set the BPTR register here since it already points 201 * We don't set the BPTR register here since it already points
@@ -181,9 +203,14 @@ static int __cpuinit smp_85xx_kick_cpu(int nr)
181 */ 203 */
182 mpic_reset_core(hw_cpu); 204 mpic_reset_core(hw_cpu);
183 205
184 /* wait until core is ready... */ 206 /*
185 if (!spin_event_timeout(in_be32(&spin_table->addr_l) == 1, 207 * wait until core is ready...
186 10000, 100)) { 208 * We need to invalidate the stale data, in case the boot
209 * loader uses a cache-inhibited spin table.
210 */
211 if (!spin_event_timeout(
212 read_spin_table_addr_l(spin_table) == 1,
213 10000, 100)) {
187 pr_err("%s: timeout waiting for core %d to reset\n", 214 pr_err("%s: timeout waiting for core %d to reset\n",
188 __func__, hw_cpu); 215 __func__, hw_cpu);
189 ret = -ENOENT; 216 ret = -ENOENT;
@@ -194,12 +221,10 @@ static int __cpuinit smp_85xx_kick_cpu(int nr)
194 __secondary_hold_acknowledge = -1; 221 __secondary_hold_acknowledge = -1;
195 } 222 }
196#endif 223#endif
224 flush_spin_table(spin_table);
197 out_be32(&spin_table->pir, hw_cpu); 225 out_be32(&spin_table->pir, hw_cpu);
198 out_be32(&spin_table->addr_l, __pa(__early_start)); 226 out_be32(&spin_table->addr_l, __pa(__early_start));
199 227 flush_spin_table(spin_table);
200 if (!ioremappable)
201 flush_dcache_range((ulong)spin_table,
202 (ulong)spin_table + sizeof(struct epapr_spin_table));
203 228
204 /* Wait a bit for the CPU to ack. */ 229 /* Wait a bit for the CPU to ack. */
205 if (!spin_event_timeout(__secondary_hold_acknowledge == hw_cpu, 230 if (!spin_event_timeout(__secondary_hold_acknowledge == hw_cpu,
@@ -213,13 +238,11 @@ out:
213#else 238#else
214 smp_generic_kick_cpu(nr); 239 smp_generic_kick_cpu(nr);
215 240
241 flush_spin_table(spin_table);
216 out_be32(&spin_table->pir, hw_cpu); 242 out_be32(&spin_table->pir, hw_cpu);
217 out_be64((u64 *)(&spin_table->addr_h), 243 out_be64((u64 *)(&spin_table->addr_h),
218 __pa((u64)*((unsigned long long *)generic_secondary_smp_init))); 244 __pa((u64)*((unsigned long long *)generic_secondary_smp_init)));
219 245 flush_spin_table(spin_table);
220 if (!ioremappable)
221 flush_dcache_range((ulong)spin_table,
222 (ulong)spin_table + sizeof(struct epapr_spin_table));
223#endif 246#endif
224 247
225 local_irq_restore(flags); 248 local_irq_restore(flags);
diff --git a/arch/powerpc/platforms/85xx/tqm85xx.c b/arch/powerpc/platforms/85xx/tqm85xx.c
index b4e58cdc09a5..ec0b7272fae2 100644
--- a/arch/powerpc/platforms/85xx/tqm85xx.c
+++ b/arch/powerpc/platforms/85xx/tqm85xx.c
@@ -85,7 +85,7 @@ static void tqm85xx_show_cpuinfo(struct seq_file *m)
85 seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f)); 85 seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
86} 86}
87 87
88static void __devinit tqm85xx_ti1520_fixup(struct pci_dev *pdev) 88static void tqm85xx_ti1520_fixup(struct pci_dev *pdev)
89{ 89{
90 unsigned int val; 90 unsigned int val;
91 91
diff --git a/arch/powerpc/platforms/86xx/gef_ppc9a.c b/arch/powerpc/platforms/86xx/gef_ppc9a.c
index bf5338754c5a..c23f3443880a 100644
--- a/arch/powerpc/platforms/86xx/gef_ppc9a.c
+++ b/arch/powerpc/platforms/86xx/gef_ppc9a.c
@@ -159,7 +159,7 @@ static void gef_ppc9a_show_cpuinfo(struct seq_file *m)
159 gef_ppc9a_get_vme_is_syscon() ? "yes" : "no"); 159 gef_ppc9a_get_vme_is_syscon() ? "yes" : "no");
160} 160}
161 161
162static void __devinit gef_ppc9a_nec_fixup(struct pci_dev *pdev) 162static void gef_ppc9a_nec_fixup(struct pci_dev *pdev)
163{ 163{
164 unsigned int val; 164 unsigned int val;
165 165
diff --git a/arch/powerpc/platforms/86xx/gef_sbc310.c b/arch/powerpc/platforms/86xx/gef_sbc310.c
index 0b7851330a07..8a6ac20686ea 100644
--- a/arch/powerpc/platforms/86xx/gef_sbc310.c
+++ b/arch/powerpc/platforms/86xx/gef_sbc310.c
@@ -146,7 +146,7 @@ static void gef_sbc310_show_cpuinfo(struct seq_file *m)
146 146
147} 147}
148 148
149static void __devinit gef_sbc310_nec_fixup(struct pci_dev *pdev) 149static void gef_sbc310_nec_fixup(struct pci_dev *pdev)
150{ 150{
151 unsigned int val; 151 unsigned int val;
152 152
diff --git a/arch/powerpc/platforms/86xx/gef_sbc610.c b/arch/powerpc/platforms/86xx/gef_sbc610.c
index b9eb174897b1..06c72636f299 100644
--- a/arch/powerpc/platforms/86xx/gef_sbc610.c
+++ b/arch/powerpc/platforms/86xx/gef_sbc610.c
@@ -136,7 +136,7 @@ static void gef_sbc610_show_cpuinfo(struct seq_file *m)
136 seq_printf(m, "SVR\t\t: 0x%x\n", svid); 136 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
137} 137}
138 138
139static void __devinit gef_sbc610_nec_fixup(struct pci_dev *pdev) 139static void gef_sbc610_nec_fixup(struct pci_dev *pdev)
140{ 140{
141 unsigned int val; 141 unsigned int val;
142 142
diff --git a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
index 7076006f972e..d479d68fbb2b 100644
--- a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
+++ b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
@@ -353,5 +353,7 @@ define_machine(mpc86xx_hpcd) {
353 .time_init = mpc86xx_time_init, 353 .time_init = mpc86xx_time_init,
354 .calibrate_decr = generic_calibrate_decr, 354 .calibrate_decr = generic_calibrate_decr,
355 .progress = udbg_progress, 355 .progress = udbg_progress,
356#ifdef CONFIG_PCI
356 .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 357 .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
358#endif
357}; 359};
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e7a896acd982..48a920d51489 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -90,6 +90,7 @@ config MPIC
90config PPC_EPAPR_HV_PIC 90config PPC_EPAPR_HV_PIC
91 bool 91 bool
92 default n 92 default n
93 select EPAPR_PARAVIRT
93 94
94config MPIC_WEIRD 95config MPIC_WEIRD
95 bool 96 bool
diff --git a/arch/powerpc/platforms/cell/celleb_pci.c b/arch/powerpc/platforms/cell/celleb_pci.c
index abc8af43ea7c..173568140a32 100644
--- a/arch/powerpc/platforms/cell/celleb_pci.c
+++ b/arch/powerpc/platforms/cell/celleb_pci.c
@@ -401,11 +401,11 @@ error:
401 } else { 401 } else {
402 if (config && *config) { 402 if (config && *config) {
403 size = 256; 403 size = 256;
404 free_bootmem((unsigned long)(*config), size); 404 free_bootmem(__pa(*config), size);
405 } 405 }
406 if (res && *res) { 406 if (res && *res) {
407 size = sizeof(struct celleb_pci_resource); 407 size = sizeof(struct celleb_pci_resource);
408 free_bootmem((unsigned long)(*res), size); 408 free_bootmem(__pa(*res), size);
409 } 409 }
410 } 410 }
411 411
diff --git a/arch/powerpc/platforms/cell/setup.c b/arch/powerpc/platforms/cell/setup.c
index 4ab087671185..6ae25fb62015 100644
--- a/arch/powerpc/platforms/cell/setup.c
+++ b/arch/powerpc/platforms/cell/setup.c
@@ -117,7 +117,7 @@ static void cell_fixup_pcie_rootcomplex(struct pci_dev *dev)
117} 117}
118DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, cell_fixup_pcie_rootcomplex); 118DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, cell_fixup_pcie_rootcomplex);
119 119
120static int __devinit cell_setup_phb(struct pci_controller *phb) 120static int cell_setup_phb(struct pci_controller *phb)
121{ 121{
122 const char *model; 122 const char *model;
123 struct device_node *np; 123 struct device_node *np;
diff --git a/arch/powerpc/platforms/cell/smp.c b/arch/powerpc/platforms/cell/smp.c
index 49a65e2dfc71..d35dbbc8ec79 100644
--- a/arch/powerpc/platforms/cell/smp.c
+++ b/arch/powerpc/platforms/cell/smp.c
@@ -67,7 +67,7 @@ static cpumask_t of_spin_map;
67 * 0 - failure 67 * 0 - failure
68 * 1 - success 68 * 1 - success
69 */ 69 */
70static inline int __devinit smp_startup_cpu(unsigned int lcpu) 70static inline int smp_startup_cpu(unsigned int lcpu)
71{ 71{
72 int status; 72 int status;
73 unsigned long start_here = __pa((u32)*((unsigned long *) 73 unsigned long start_here = __pa((u32)*((unsigned long *)
@@ -108,7 +108,7 @@ static int __init smp_iic_probe(void)
108 return cpumask_weight(cpu_possible_mask); 108 return cpumask_weight(cpu_possible_mask);
109} 109}
110 110
111static void __devinit smp_cell_setup_cpu(int cpu) 111static void smp_cell_setup_cpu(int cpu)
112{ 112{
113 if (cpu != boot_cpuid) 113 if (cpu != boot_cpuid)
114 iic_setup_cpu(); 114 iic_setup_cpu();
@@ -119,7 +119,7 @@ static void __devinit smp_cell_setup_cpu(int cpu)
119 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER); 119 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
120} 120}
121 121
122static int __devinit smp_cell_kick_cpu(int nr) 122static int smp_cell_kick_cpu(int nr)
123{ 123{
124 BUG_ON(nr < 0 || nr >= NR_CPUS); 124 BUG_ON(nr < 0 || nr >= NR_CPUS);
125 125
diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 965d381abd75..25db92a8e1cf 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -1094,7 +1094,7 @@ static int show_spu_loadavg(struct seq_file *s, void *private)
1094 LOAD_INT(c), LOAD_FRAC(c), 1094 LOAD_INT(c), LOAD_FRAC(c),
1095 count_active_contexts(), 1095 count_active_contexts(),
1096 atomic_read(&nr_spu_contexts), 1096 atomic_read(&nr_spu_contexts),
1097 current->nsproxy->pid_ns->last_pid); 1097 task_active_pid_ns(current)->last_pid);
1098 return 0; 1098 return 0;
1099} 1099}
1100 1100
diff --git a/arch/powerpc/platforms/cell/spufs/syscalls.c b/arch/powerpc/platforms/cell/spufs/syscalls.c
index 5b7d8ffbf890..baee994fe810 100644
--- a/arch/powerpc/platforms/cell/spufs/syscalls.c
+++ b/arch/powerpc/platforms/cell/spufs/syscalls.c
@@ -66,7 +66,7 @@ static long do_spu_create(const char __user *pathname, unsigned int flags,
66 struct dentry *dentry; 66 struct dentry *dentry;
67 int ret; 67 int ret;
68 68
69 dentry = user_path_create(AT_FDCWD, pathname, &path, 1); 69 dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
70 ret = PTR_ERR(dentry); 70 ret = PTR_ERR(dentry);
71 if (!IS_ERR(dentry)) { 71 if (!IS_ERR(dentry)) {
72 ret = spufs_create(&path, dentry, flags, mode, neighbor); 72 ret = spufs_create(&path, dentry, flags, mode, neighbor);
diff --git a/arch/powerpc/platforms/chrp/pci.c b/arch/powerpc/platforms/chrp/pci.c
index 83285c5a2049..1b87e198faa7 100644
--- a/arch/powerpc/platforms/chrp/pci.c
+++ b/arch/powerpc/platforms/chrp/pci.c
@@ -323,7 +323,7 @@ chrp_find_bridges(void)
323 * ATA controller to be set to fully native mode or bad things 323 * ATA controller to be set to fully native mode or bad things
324 * will happen. 324 * will happen.
325 */ 325 */
326static void __devinit chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105) 326static void chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105)
327{ 327{
328 u8 progif; 328 u8 progif;
329 329
diff --git a/arch/powerpc/platforms/chrp/smp.c b/arch/powerpc/platforms/chrp/smp.c
index feab30bbae23..dead91b177b9 100644
--- a/arch/powerpc/platforms/chrp/smp.c
+++ b/arch/powerpc/platforms/chrp/smp.c
@@ -30,7 +30,7 @@
30#include <asm/mpic.h> 30#include <asm/mpic.h>
31#include <asm/rtas.h> 31#include <asm/rtas.h>
32 32
33static int __devinit smp_chrp_kick_cpu(int nr) 33static int smp_chrp_kick_cpu(int nr)
34{ 34{
35 *(unsigned long *)KERNELBASE = nr; 35 *(unsigned long *)KERNELBASE = nr;
36 asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory"); 36 asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
@@ -38,7 +38,7 @@ static int __devinit smp_chrp_kick_cpu(int nr)
38 return 0; 38 return 0;
39} 39}
40 40
41static void __devinit smp_chrp_setup_cpu(int cpu_nr) 41static void smp_chrp_setup_cpu(int cpu_nr)
42{ 42{
43 mpic_setup_this_cpu(); 43 mpic_setup_this_cpu();
44} 44}
diff --git a/arch/powerpc/platforms/fsl_uli1575.c b/arch/powerpc/platforms/fsl_uli1575.c
index 64fde058e545..92ac9b52b32d 100644
--- a/arch/powerpc/platforms/fsl_uli1575.c
+++ b/arch/powerpc/platforms/fsl_uli1575.c
@@ -59,7 +59,7 @@ static inline bool is_quirk_valid(void)
59} 59}
60 60
61/* Bridge */ 61/* Bridge */
62static void __devinit early_uli5249(struct pci_dev *dev) 62static void early_uli5249(struct pci_dev *dev)
63{ 63{
64 unsigned char temp; 64 unsigned char temp;
65 65
@@ -82,7 +82,7 @@ static void __devinit early_uli5249(struct pci_dev *dev)
82} 82}
83 83
84 84
85static void __devinit quirk_uli1575(struct pci_dev *dev) 85static void quirk_uli1575(struct pci_dev *dev)
86{ 86{
87 int i; 87 int i;
88 88
@@ -139,7 +139,7 @@ static void __devinit quirk_uli1575(struct pci_dev *dev)
139 pci_write_config_byte(dev, 0x75, ULI_8259_IRQ15); 139 pci_write_config_byte(dev, 0x75, ULI_8259_IRQ15);
140} 140}
141 141
142static void __devinit quirk_final_uli1575(struct pci_dev *dev) 142static void quirk_final_uli1575(struct pci_dev *dev)
143{ 143{
144 /* Set i8259 interrupt trigger 144 /* Set i8259 interrupt trigger
145 * IRQ 3: Level 145 * IRQ 3: Level
@@ -175,7 +175,7 @@ static void __devinit quirk_final_uli1575(struct pci_dev *dev)
175} 175}
176 176
177/* SATA */ 177/* SATA */
178static void __devinit quirk_uli5288(struct pci_dev *dev) 178static void quirk_uli5288(struct pci_dev *dev)
179{ 179{
180 unsigned char c; 180 unsigned char c;
181 unsigned int d; 181 unsigned int d;
@@ -200,7 +200,7 @@ static void __devinit quirk_uli5288(struct pci_dev *dev)
200} 200}
201 201
202/* PATA */ 202/* PATA */
203static void __devinit quirk_uli5229(struct pci_dev *dev) 203static void quirk_uli5229(struct pci_dev *dev)
204{ 204{
205 unsigned short temp; 205 unsigned short temp;
206 206
@@ -216,7 +216,7 @@ static void __devinit quirk_uli5229(struct pci_dev *dev)
216} 216}
217 217
218/* We have to do a dummy read on the P2P for the RTC to work, WTF */ 218/* We have to do a dummy read on the P2P for the RTC to work, WTF */
219static void __devinit quirk_final_uli5249(struct pci_dev *dev) 219static void quirk_final_uli5249(struct pci_dev *dev)
220{ 220{
221 int i; 221 int i;
222 u8 *dummy; 222 u8 *dummy;
@@ -253,7 +253,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5249, quirk_final_uli5249);
253DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x1575, quirk_final_uli1575); 253DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x1575, quirk_final_uli1575);
254DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229); 254DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
255 255
256static void __devinit hpcd_quirk_uli1575(struct pci_dev *dev) 256static void hpcd_quirk_uli1575(struct pci_dev *dev)
257{ 257{
258 u32 temp32; 258 u32 temp32;
259 259
@@ -269,7 +269,7 @@ static void __devinit hpcd_quirk_uli1575(struct pci_dev *dev)
269 pci_write_config_dword(dev, 0x90, (temp32 | 1<<22)); 269 pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
270} 270}
271 271
272static void __devinit hpcd_quirk_uli5288(struct pci_dev *dev) 272static void hpcd_quirk_uli5288(struct pci_dev *dev)
273{ 273{
274 unsigned char c; 274 unsigned char c;
275 275
@@ -295,7 +295,7 @@ static void __devinit hpcd_quirk_uli5288(struct pci_dev *dev)
295 * IRQ14 is a sideband interrupt from IDE device to CPU and we use this 295 * IRQ14 is a sideband interrupt from IDE device to CPU and we use this
296 * as the interrupt for IDE device. 296 * as the interrupt for IDE device.
297 */ 297 */
298static void __devinit hpcd_quirk_uli5229(struct pci_dev *dev) 298static void hpcd_quirk_uli5229(struct pci_dev *dev)
299{ 299{
300 unsigned char c; 300 unsigned char c;
301 301
@@ -317,7 +317,7 @@ static void __devinit hpcd_quirk_uli5229(struct pci_dev *dev)
317 * bug by re-assigning a correct irq to 5288. 317 * bug by re-assigning a correct irq to 5288.
318 * 318 *
319 */ 319 */
320static void __devinit hpcd_final_uli5288(struct pci_dev *dev) 320static void hpcd_final_uli5288(struct pci_dev *dev)
321{ 321{
322 struct pci_controller *hose = pci_bus_to_host(dev->bus); 322 struct pci_controller *hose = pci_bus_to_host(dev->bus);
323 struct device_node *hosenode = hose ? hose->dn : NULL; 323 struct device_node *hosenode = hose ? hose->dn : NULL;
diff --git a/arch/powerpc/platforms/maple/pci.c b/arch/powerpc/platforms/maple/pci.c
index 465ee8f5c086..f7136aae8bbf 100644
--- a/arch/powerpc/platforms/maple/pci.c
+++ b/arch/powerpc/platforms/maple/pci.c
@@ -543,7 +543,7 @@ static int __init maple_add_bridge(struct device_node *dev)
543} 543}
544 544
545 545
546void __devinit maple_pci_irq_fixup(struct pci_dev *dev) 546void maple_pci_irq_fixup(struct pci_dev *dev)
547{ 547{
548 DBG(" -> maple_pci_irq_fixup\n"); 548 DBG(" -> maple_pci_irq_fixup\n");
549 549
@@ -648,7 +648,7 @@ int maple_pci_get_legacy_ide_irq(struct pci_dev *pdev, int channel)
648 return irq; 648 return irq;
649} 649}
650 650
651static void __devinit quirk_ipr_msi(struct pci_dev *dev) 651static void quirk_ipr_msi(struct pci_dev *dev)
652{ 652{
653 /* Something prevents MSIs from the IPR from working on Bimini, 653 /* Something prevents MSIs from the IPR from working on Bimini,
654 * and the driver has no smarts to recover. So disable MSI 654 * and the driver has no smarts to recover. So disable MSI
diff --git a/arch/powerpc/platforms/pasemi/cpufreq.c b/arch/powerpc/platforms/pasemi/cpufreq.c
index 95d00173029f..890f30e70f98 100644
--- a/arch/powerpc/platforms/pasemi/cpufreq.c
+++ b/arch/powerpc/platforms/pasemi/cpufreq.c
@@ -236,6 +236,13 @@ out:
236 236
237static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy) 237static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)
238{ 238{
239 /*
240 * We don't support CPU hotplug. Don't unmap after the system
241 * has already made it to a running state.
242 */
243 if (system_state != SYSTEM_BOOTING)
244 return 0;
245
239 if (sdcasr_mapbase) 246 if (sdcasr_mapbase)
240 iounmap(sdcasr_mapbase); 247 iounmap(sdcasr_mapbase);
241 if (sdcpwr_mapbase) 248 if (sdcpwr_mapbase)
diff --git a/arch/powerpc/platforms/pasemi/gpio_mdio.c b/arch/powerpc/platforms/pasemi/gpio_mdio.c
index 9886296e08da..0237ab782fb8 100644
--- a/arch/powerpc/platforms/pasemi/gpio_mdio.c
+++ b/arch/powerpc/platforms/pasemi/gpio_mdio.c
@@ -216,7 +216,7 @@ static int gpio_mdio_reset(struct mii_bus *bus)
216} 216}
217 217
218 218
219static int __devinit gpio_mdio_probe(struct platform_device *ofdev) 219static int gpio_mdio_probe(struct platform_device *ofdev)
220{ 220{
221 struct device *dev = &ofdev->dev; 221 struct device *dev = &ofdev->dev;
222 struct device_node *np = ofdev->dev.of_node; 222 struct device_node *np = ofdev->dev.of_node;
diff --git a/arch/powerpc/platforms/pasemi/pasemi.h b/arch/powerpc/platforms/pasemi/pasemi.h
index b1e524f7489d..ea65bf0eb897 100644
--- a/arch/powerpc/platforms/pasemi/pasemi.h
+++ b/arch/powerpc/platforms/pasemi/pasemi.h
@@ -3,8 +3,8 @@
3 3
4extern unsigned long pas_get_boot_time(void); 4extern unsigned long pas_get_boot_time(void);
5extern void pas_pci_init(void); 5extern void pas_pci_init(void);
6extern void __devinit pas_pci_irq_fixup(struct pci_dev *dev); 6extern void pas_pci_irq_fixup(struct pci_dev *dev);
7extern void __devinit pas_pci_dma_dev_setup(struct pci_dev *dev); 7extern void pas_pci_dma_dev_setup(struct pci_dev *dev);
8 8
9extern void __iomem *pasemi_pci_getcfgaddr(struct pci_dev *dev, int offset); 9extern void __iomem *pasemi_pci_getcfgaddr(struct pci_dev *dev, int offset);
10 10
diff --git a/arch/powerpc/platforms/pasemi/setup.c b/arch/powerpc/platforms/pasemi/setup.c
index 2ed9212d7d59..8c54de6d8ec4 100644
--- a/arch/powerpc/platforms/pasemi/setup.c
+++ b/arch/powerpc/platforms/pasemi/setup.c
@@ -76,7 +76,7 @@ static void pas_restart(char *cmd)
76static arch_spinlock_t timebase_lock; 76static arch_spinlock_t timebase_lock;
77static unsigned long timebase; 77static unsigned long timebase;
78 78
79static void __devinit pas_give_timebase(void) 79static void pas_give_timebase(void)
80{ 80{
81 unsigned long flags; 81 unsigned long flags;
82 82
@@ -94,7 +94,7 @@ static void __devinit pas_give_timebase(void)
94 local_irq_restore(flags); 94 local_irq_restore(flags);
95} 95}
96 96
97static void __devinit pas_take_timebase(void) 97static void pas_take_timebase(void)
98{ 98{
99 while (!timebase) 99 while (!timebase)
100 smp_rmb(); 100 smp_rmb();
diff --git a/arch/powerpc/platforms/powermac/cpufreq_32.c b/arch/powerpc/platforms/powermac/cpufreq_32.c
index 64171198535c..311b804353b1 100644
--- a/arch/powerpc/platforms/powermac/cpufreq_32.c
+++ b/arch/powerpc/platforms/powermac/cpufreq_32.c
@@ -55,6 +55,7 @@ static unsigned int low_freq;
55static unsigned int hi_freq; 55static unsigned int hi_freq;
56static unsigned int cur_freq; 56static unsigned int cur_freq;
57static unsigned int sleep_freq; 57static unsigned int sleep_freq;
58static unsigned long transition_latency;
58 59
59/* 60/*
60 * Different models uses different mechanisms to switch the frequency 61 * Different models uses different mechanisms to switch the frequency
@@ -403,7 +404,7 @@ static int pmac_cpufreq_cpu_init(struct cpufreq_policy *policy)
403 if (policy->cpu != 0) 404 if (policy->cpu != 0)
404 return -ENODEV; 405 return -ENODEV;
405 406
406 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 407 policy->cpuinfo.transition_latency = transition_latency;
407 policy->cur = cur_freq; 408 policy->cur = cur_freq;
408 409
409 cpufreq_frequency_table_get_attr(pmac_cpu_freqs, policy->cpu); 410 cpufreq_frequency_table_get_attr(pmac_cpu_freqs, policy->cpu);
@@ -658,12 +659,14 @@ static int __init pmac_cpufreq_setup(void)
658 if (!value) 659 if (!value)
659 goto out; 660 goto out;
660 cur_freq = (*value) / 1000; 661 cur_freq = (*value) / 1000;
662 transition_latency = CPUFREQ_ETERNAL;
661 663
662 /* Check for 7447A based MacRISC3 */ 664 /* Check for 7447A based MacRISC3 */
663 if (of_machine_is_compatible("MacRISC3") && 665 if (of_machine_is_compatible("MacRISC3") &&
664 of_get_property(cpunode, "dynamic-power-step", NULL) && 666 of_get_property(cpunode, "dynamic-power-step", NULL) &&
665 PVR_VER(mfspr(SPRN_PVR)) == 0x8003) { 667 PVR_VER(mfspr(SPRN_PVR)) == 0x8003) {
666 pmac_cpufreq_init_7447A(cpunode); 668 pmac_cpufreq_init_7447A(cpunode);
669 transition_latency = 8000000;
667 /* Check for other MacRISC3 machines */ 670 /* Check for other MacRISC3 machines */
668 } else if (of_machine_is_compatible("PowerBook3,4") || 671 } else if (of_machine_is_compatible("PowerBook3,4") ||
669 of_machine_is_compatible("PowerBook3,5") || 672 of_machine_is_compatible("PowerBook3,5") ||
diff --git a/arch/powerpc/platforms/powermac/pci.c b/arch/powerpc/platforms/powermac/pci.c
index 43bbe1bda939..2b8af75abc23 100644
--- a/arch/powerpc/platforms/powermac/pci.c
+++ b/arch/powerpc/platforms/powermac/pci.c
@@ -561,7 +561,7 @@ static struct pci_ops u4_pcie_pci_ops =
561 .write = u4_pcie_write_config, 561 .write = u4_pcie_write_config,
562}; 562};
563 563
564static void __devinit pmac_pci_fixup_u4_of_node(struct pci_dev *dev) 564static void pmac_pci_fixup_u4_of_node(struct pci_dev *dev)
565{ 565{
566 /* Apple's device-tree "hides" the root complex virtual P2P bridge 566 /* Apple's device-tree "hides" the root complex virtual P2P bridge
567 * on U4. However, Linux sees it, causing the PCI <-> OF matching 567 * on U4. However, Linux sees it, causing the PCI <-> OF matching
@@ -988,7 +988,7 @@ static int __init pmac_add_bridge(struct device_node *dev)
988 return 0; 988 return 0;
989} 989}
990 990
991void __devinit pmac_pci_irq_fixup(struct pci_dev *dev) 991void pmac_pci_irq_fixup(struct pci_dev *dev)
992{ 992{
993#ifdef CONFIG_PPC32 993#ifdef CONFIG_PPC32
994 /* Fixup interrupt for the modem/ethernet combo controller. 994 /* Fixup interrupt for the modem/ethernet combo controller.
@@ -1138,7 +1138,7 @@ int pmac_pci_enable_device_hook(struct pci_dev *dev)
1138 return 0; 1138 return 0;
1139} 1139}
1140 1140
1141void __devinit pmac_pci_fixup_ohci(struct pci_dev *dev) 1141void pmac_pci_fixup_ohci(struct pci_dev *dev)
1142{ 1142{
1143 struct device_node *node = pci_device_to_OF_node(dev); 1143 struct device_node *node = pci_device_to_OF_node(dev);
1144 1144
diff --git a/arch/powerpc/platforms/powermac/pfunc_core.c b/arch/powerpc/platforms/powermac/pfunc_core.c
index b0c3777528a1..d588e48dff74 100644
--- a/arch/powerpc/platforms/powermac/pfunc_core.c
+++ b/arch/powerpc/platforms/powermac/pfunc_core.c
@@ -686,7 +686,7 @@ static int pmf_add_functions(struct pmf_device *dev, void *driverdata)
686 int count = 0; 686 int count = 0;
687 687
688 for (pp = dev->node->properties; pp != 0; pp = pp->next) { 688 for (pp = dev->node->properties; pp != 0; pp = pp->next) {
689 char *name; 689 const char *name;
690 if (strncmp(pp->name, PP_PREFIX, plen) != 0) 690 if (strncmp(pp->name, PP_PREFIX, plen) != 0)
691 continue; 691 continue;
692 name = pp->name + plen; 692 name = pp->name + plen;
diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
index b4ddaa3fbb29..bdb738a69e41 100644
--- a/arch/powerpc/platforms/powermac/smp.c
+++ b/arch/powerpc/platforms/powermac/smp.c
@@ -484,7 +484,7 @@ static void smp_core99_give_timebase(void)
484} 484}
485 485
486 486
487static void __devinit smp_core99_take_timebase(void) 487static void smp_core99_take_timebase(void)
488{ 488{
489 unsigned long flags; 489 unsigned long flags;
490 490
@@ -669,7 +669,7 @@ static void smp_core99_gpio_tb_freeze(int freeze)
669volatile static long int core99_l2_cache; 669volatile static long int core99_l2_cache;
670volatile static long int core99_l3_cache; 670volatile static long int core99_l3_cache;
671 671
672static void __devinit core99_init_caches(int cpu) 672static void core99_init_caches(int cpu)
673{ 673{
674#ifndef CONFIG_PPC64 674#ifndef CONFIG_PPC64
675 if (!cpu_has_feature(CPU_FTR_L2CR)) 675 if (!cpu_has_feature(CPU_FTR_L2CR))
@@ -801,7 +801,7 @@ static int __init smp_core99_probe(void)
801 return ncpus; 801 return ncpus;
802} 802}
803 803
804static int __devinit smp_core99_kick_cpu(int nr) 804static int smp_core99_kick_cpu(int nr)
805{ 805{
806 unsigned int save_vector; 806 unsigned int save_vector;
807 unsigned long target, flags; 807 unsigned long target, flags;
@@ -844,7 +844,7 @@ static int __devinit smp_core99_kick_cpu(int nr)
844 return 0; 844 return 0;
845} 845}
846 846
847static void __devinit smp_core99_setup_cpu(int cpu_nr) 847static void smp_core99_setup_cpu(int cpu_nr)
848{ 848{
849 /* Setup L2/L3 */ 849 /* Setup L2/L3 */
850 if (cpu_nr != 0) 850 if (cpu_nr != 0)
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 471aa3ccd9fd..8e90e8906df3 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -34,24 +34,12 @@
34#include "powernv.h" 34#include "powernv.h"
35#include "pci.h" 35#include "pci.h"
36 36
37static int __pe_printk(const char *level, const struct pnv_ioda_pe *pe,
38 struct va_format *vaf)
39{
40 char pfix[32];
41
42 if (pe->pdev)
43 strlcpy(pfix, dev_name(&pe->pdev->dev), sizeof(pfix));
44 else
45 sprintf(pfix, "%04x:%02x ",
46 pci_domain_nr(pe->pbus), pe->pbus->number);
47 return printk("pci %s%s: [PE# %.3d] %pV", level, pfix, pe->pe_number, vaf);
48}
49
50#define define_pe_printk_level(func, kern_level) \ 37#define define_pe_printk_level(func, kern_level) \
51static int func(const struct pnv_ioda_pe *pe, const char *fmt, ...) \ 38static int func(const struct pnv_ioda_pe *pe, const char *fmt, ...) \
52{ \ 39{ \
53 struct va_format vaf; \ 40 struct va_format vaf; \
54 va_list args; \ 41 va_list args; \
42 char pfix[32]; \
55 int r; \ 43 int r; \
56 \ 44 \
57 va_start(args, fmt); \ 45 va_start(args, fmt); \
@@ -59,7 +47,16 @@ static int func(const struct pnv_ioda_pe *pe, const char *fmt, ...) \
59 vaf.fmt = fmt; \ 47 vaf.fmt = fmt; \
60 vaf.va = &args; \ 48 vaf.va = &args; \
61 \ 49 \
62 r = __pe_printk(kern_level, pe, &vaf); \ 50 if (pe->pdev) \
51 strlcpy(pfix, dev_name(&pe->pdev->dev), \
52 sizeof(pfix)); \
53 else \
54 sprintf(pfix, "%04x:%02x ", \
55 pci_domain_nr(pe->pbus), \
56 pe->pbus->number); \
57 r = printk(kern_level "pci %s: [PE# %.3d] %pV", \
58 pfix, pe->pe_number, &vaf); \
59 \
63 va_end(args); \ 60 va_end(args); \
64 \ 61 \
65 return r; \ 62 return r; \
@@ -79,7 +76,7 @@ static struct pci_dn *pnv_ioda_get_pdn(struct pci_dev *dev)
79 return PCI_DN(np); 76 return PCI_DN(np);
80} 77}
81 78
82static int __devinit pnv_ioda_alloc_pe(struct pnv_phb *phb) 79static int pnv_ioda_alloc_pe(struct pnv_phb *phb)
83{ 80{
84 unsigned long pe; 81 unsigned long pe;
85 82
@@ -94,7 +91,7 @@ static int __devinit pnv_ioda_alloc_pe(struct pnv_phb *phb)
94 return pe; 91 return pe;
95} 92}
96 93
97static void __devinit pnv_ioda_free_pe(struct pnv_phb *phb, int pe) 94static void pnv_ioda_free_pe(struct pnv_phb *phb, int pe)
98{ 95{
99 WARN_ON(phb->ioda.pe_array[pe].pdev); 96 WARN_ON(phb->ioda.pe_array[pe].pdev);
100 97
@@ -106,7 +103,7 @@ static void __devinit pnv_ioda_free_pe(struct pnv_phb *phb, int pe)
106 * but in the meantime, we need to protect them to avoid warnings 103 * but in the meantime, we need to protect them to avoid warnings
107 */ 104 */
108#ifdef CONFIG_PCI_MSI 105#ifdef CONFIG_PCI_MSI
109static struct pnv_ioda_pe * __devinit pnv_ioda_get_pe(struct pci_dev *dev) 106static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
110{ 107{
111 struct pci_controller *hose = pci_bus_to_host(dev->bus); 108 struct pci_controller *hose = pci_bus_to_host(dev->bus);
112 struct pnv_phb *phb = hose->private_data; 109 struct pnv_phb *phb = hose->private_data;
@@ -120,8 +117,7 @@ static struct pnv_ioda_pe * __devinit pnv_ioda_get_pe(struct pci_dev *dev)
120} 117}
121#endif /* CONFIG_PCI_MSI */ 118#endif /* CONFIG_PCI_MSI */
122 119
123static int __devinit pnv_ioda_configure_pe(struct pnv_phb *phb, 120static int pnv_ioda_configure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe)
124 struct pnv_ioda_pe *pe)
125{ 121{
126 struct pci_dev *parent; 122 struct pci_dev *parent;
127 uint8_t bcomp, dcomp, fcomp; 123 uint8_t bcomp, dcomp, fcomp;
@@ -210,8 +206,8 @@ static int __devinit pnv_ioda_configure_pe(struct pnv_phb *phb,
210 return 0; 206 return 0;
211} 207}
212 208
213static void __devinit pnv_ioda_link_pe_by_weight(struct pnv_phb *phb, 209static void pnv_ioda_link_pe_by_weight(struct pnv_phb *phb,
214 struct pnv_ioda_pe *pe) 210 struct pnv_ioda_pe *pe)
215{ 211{
216 struct pnv_ioda_pe *lpe; 212 struct pnv_ioda_pe *lpe;
217 213
@@ -249,7 +245,7 @@ static unsigned int pnv_ioda_dma_weight(struct pci_dev *dev)
249} 245}
250 246
251#if 0 247#if 0
252static struct pnv_ioda_pe * __devinit pnv_ioda_setup_dev_PE(struct pci_dev *dev) 248static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)
253{ 249{
254 struct pci_controller *hose = pci_bus_to_host(dev->bus); 250 struct pci_controller *hose = pci_bus_to_host(dev->bus);
255 struct pnv_phb *phb = hose->private_data; 251 struct pnv_phb *phb = hose->private_data;
@@ -346,7 +342,7 @@ static void pnv_ioda_setup_same_PE(struct pci_bus *bus, struct pnv_ioda_pe *pe)
346 * subordinate PCI devices and buses. The second type of PE is normally 342 * subordinate PCI devices and buses. The second type of PE is normally
347 * orgiriated by PCIe-to-PCI bridge or PLX switch downstream ports. 343 * orgiriated by PCIe-to-PCI bridge or PLX switch downstream ports.
348 */ 344 */
349static void __devinit pnv_ioda_setup_bus_PE(struct pci_bus *bus, int all) 345static void pnv_ioda_setup_bus_PE(struct pci_bus *bus, int all)
350{ 346{
351 struct pci_controller *hose = pci_bus_to_host(bus); 347 struct pci_controller *hose = pci_bus_to_host(bus);
352 struct pnv_phb *phb = hose->private_data; 348 struct pnv_phb *phb = hose->private_data;
@@ -402,7 +398,7 @@ static void __devinit pnv_ioda_setup_bus_PE(struct pci_bus *bus, int all)
402 pnv_ioda_link_pe_by_weight(phb, pe); 398 pnv_ioda_link_pe_by_weight(phb, pe);
403} 399}
404 400
405static void __devinit pnv_ioda_setup_PEs(struct pci_bus *bus) 401static void pnv_ioda_setup_PEs(struct pci_bus *bus)
406{ 402{
407 struct pci_dev *dev; 403 struct pci_dev *dev;
408 404
@@ -426,7 +422,7 @@ static void __devinit pnv_ioda_setup_PEs(struct pci_bus *bus)
426 * port to PE# here. The game rule here is expected to be changed 422 * port to PE# here. The game rule here is expected to be changed
427 * as soon as we can detected PLX bridge correctly. 423 * as soon as we can detected PLX bridge correctly.
428 */ 424 */
429static void __devinit pnv_pci_ioda_setup_PEs(void) 425static void pnv_pci_ioda_setup_PEs(void)
430{ 426{
431 struct pci_controller *hose, *tmp; 427 struct pci_controller *hose, *tmp;
432 428
@@ -435,14 +431,12 @@ static void __devinit pnv_pci_ioda_setup_PEs(void)
435 } 431 }
436} 432}
437 433
438static void __devinit pnv_pci_ioda_dma_dev_setup(struct pnv_phb *phb, 434static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb *phb, struct pci_dev *dev)
439 struct pci_dev *dev)
440{ 435{
441 /* We delay DMA setup after we have assigned all PE# */ 436 /* We delay DMA setup after we have assigned all PE# */
442} 437}
443 438
444static void __devinit pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, 439static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)
445 struct pci_bus *bus)
446{ 440{
447 struct pci_dev *dev; 441 struct pci_dev *dev;
448 442
@@ -453,10 +447,9 @@ static void __devinit pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe,
453 } 447 }
454} 448}
455 449
456static void __devinit pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb, 450static void pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb,
457 struct pnv_ioda_pe *pe, 451 struct pnv_ioda_pe *pe, unsigned int base,
458 unsigned int base, 452 unsigned int segs)
459 unsigned int segs)
460{ 453{
461 454
462 struct page *tce_mem = NULL; 455 struct page *tce_mem = NULL;
@@ -544,7 +537,7 @@ static void __devinit pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb,
544 __free_pages(tce_mem, get_order(TCE32_TABLE_SIZE * segs)); 537 __free_pages(tce_mem, get_order(TCE32_TABLE_SIZE * segs));
545} 538}
546 539
547static void __devinit pnv_ioda_setup_dma(struct pnv_phb *phb) 540static void pnv_ioda_setup_dma(struct pnv_phb *phb)
548{ 541{
549 struct pci_controller *hose = phb->hose; 542 struct pci_controller *hose = phb->hose;
550 unsigned int residual, remaining, segs, tw, base; 543 unsigned int residual, remaining, segs, tw, base;
@@ -687,8 +680,8 @@ static void pnv_pci_init_ioda_msis(struct pnv_phb *phb) { }
687 * to bottom style. So the the I/O or MMIO segment assigned to 680 * to bottom style. So the the I/O or MMIO segment assigned to
688 * parent PE could be overrided by its child PEs if necessary. 681 * parent PE could be overrided by its child PEs if necessary.
689 */ 682 */
690static void __devinit pnv_ioda_setup_pe_seg(struct pci_controller *hose, 683static void pnv_ioda_setup_pe_seg(struct pci_controller *hose,
691 struct pnv_ioda_pe *pe) 684 struct pnv_ioda_pe *pe)
692{ 685{
693 struct pnv_phb *phb = hose->private_data; 686 struct pnv_phb *phb = hose->private_data;
694 struct pci_bus_region region; 687 struct pci_bus_region region;
@@ -756,7 +749,7 @@ static void __devinit pnv_ioda_setup_pe_seg(struct pci_controller *hose,
756 } 749 }
757} 750}
758 751
759static void __devinit pnv_pci_ioda_setup_seg(void) 752static void pnv_pci_ioda_setup_seg(void)
760{ 753{
761 struct pci_controller *tmp, *hose; 754 struct pci_controller *tmp, *hose;
762 struct pnv_phb *phb; 755 struct pnv_phb *phb;
@@ -770,7 +763,7 @@ static void __devinit pnv_pci_ioda_setup_seg(void)
770 } 763 }
771} 764}
772 765
773static void __devinit pnv_pci_ioda_setup_DMA(void) 766static void pnv_pci_ioda_setup_DMA(void)
774{ 767{
775 struct pci_controller *hose, *tmp; 768 struct pci_controller *hose, *tmp;
776 struct pnv_phb *phb; 769 struct pnv_phb *phb;
@@ -784,7 +777,7 @@ static void __devinit pnv_pci_ioda_setup_DMA(void)
784 } 777 }
785} 778}
786 779
787static void __devinit pnv_pci_ioda_fixup(void) 780static void pnv_pci_ioda_fixup(void)
788{ 781{
789 pnv_pci_ioda_setup_PEs(); 782 pnv_pci_ioda_setup_PEs();
790 pnv_pci_ioda_setup_seg(); 783 pnv_pci_ioda_setup_seg();
@@ -832,7 +825,7 @@ static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
832/* Prevent enabling devices for which we couldn't properly 825/* Prevent enabling devices for which we couldn't properly
833 * assign a PE 826 * assign a PE
834 */ 827 */
835static int __devinit pnv_pci_enable_device_hook(struct pci_dev *dev) 828static int pnv_pci_enable_device_hook(struct pci_dev *dev)
836{ 829{
837 struct pci_controller *hose = pci_bus_to_host(dev->bus); 830 struct pci_controller *hose = pci_bus_to_host(dev->bus);
838 struct pnv_phb *phb = hose->private_data; 831 struct pnv_phb *phb = hose->private_data;
diff --git a/arch/powerpc/platforms/powernv/pci-p5ioc2.c b/arch/powerpc/platforms/powernv/pci-p5ioc2.c
index 6b4bef4e9d82..7db8771a40f5 100644
--- a/arch/powerpc/platforms/powernv/pci-p5ioc2.c
+++ b/arch/powerpc/platforms/powernv/pci-p5ioc2.c
@@ -84,8 +84,8 @@ static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb)
84static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) { } 84static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) { }
85#endif /* CONFIG_PCI_MSI */ 85#endif /* CONFIG_PCI_MSI */
86 86
87static void __devinit pnv_pci_p5ioc2_dma_dev_setup(struct pnv_phb *phb, 87static void pnv_pci_p5ioc2_dma_dev_setup(struct pnv_phb *phb,
88 struct pci_dev *pdev) 88 struct pci_dev *pdev)
89{ 89{
90 if (phb->p5ioc2.iommu_table.it_map == NULL) 90 if (phb->p5ioc2.iommu_table.it_map == NULL)
91 iommu_init_table(&phb->p5ioc2.iommu_table, phb->hose->node); 91 iommu_init_table(&phb->p5ioc2.iommu_table, phb->hose->node);
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index c01688a1a741..b8b8e0bd9897 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -464,8 +464,7 @@ void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
464 tbl->it_type = TCE_PCI; 464 tbl->it_type = TCE_PCI;
465} 465}
466 466
467static struct iommu_table * __devinit 467static struct iommu_table *pnv_pci_setup_bml_iommu(struct pci_controller *hose)
468pnv_pci_setup_bml_iommu(struct pci_controller *hose)
469{ 468{
470 struct iommu_table *tbl; 469 struct iommu_table *tbl;
471 const __be64 *basep, *swinvp; 470 const __be64 *basep, *swinvp;
@@ -496,8 +495,8 @@ pnv_pci_setup_bml_iommu(struct pci_controller *hose)
496 return tbl; 495 return tbl;
497} 496}
498 497
499static void __devinit pnv_pci_dma_fallback_setup(struct pci_controller *hose, 498static void pnv_pci_dma_fallback_setup(struct pci_controller *hose,
500 struct pci_dev *pdev) 499 struct pci_dev *pdev)
501{ 500{
502 struct device_node *np = pci_bus_to_OF_node(hose->bus); 501 struct device_node *np = pci_bus_to_OF_node(hose->bus);
503 struct pci_dn *pdn; 502 struct pci_dn *pdn;
@@ -512,7 +511,7 @@ static void __devinit pnv_pci_dma_fallback_setup(struct pci_controller *hose,
512 set_iommu_table_base(&pdev->dev, pdn->iommu_table); 511 set_iommu_table_base(&pdev->dev, pdn->iommu_table);
513} 512}
514 513
515static void __devinit pnv_pci_dma_dev_setup(struct pci_dev *pdev) 514static void pnv_pci_dma_dev_setup(struct pci_dev *pdev)
516{ 515{
517 struct pci_controller *hose = pci_bus_to_host(pdev->bus); 516 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
518 struct pnv_phb *phb = hose->private_data; 517 struct pnv_phb *phb = hose->private_data;
@@ -527,7 +526,7 @@ static void __devinit pnv_pci_dma_dev_setup(struct pci_dev *pdev)
527} 526}
528 527
529/* Fixup wrong class code in p7ioc root complex */ 528/* Fixup wrong class code in p7ioc root complex */
530static void __devinit pnv_p7ioc_rc_quirk(struct pci_dev *dev) 529static void pnv_p7ioc_rc_quirk(struct pci_dev *dev)
531{ 530{
532 dev->class = PCI_CLASS_BRIDGE_PCI << 8; 531 dev->class = PCI_CLASS_BRIDGE_PCI << 8;
533} 532}
diff --git a/arch/powerpc/platforms/powernv/smp.c b/arch/powerpc/platforms/powernv/smp.c
index 7698b6e13c57..0bdc735db16f 100644
--- a/arch/powerpc/platforms/powernv/smp.c
+++ b/arch/powerpc/platforms/powernv/smp.c
@@ -62,7 +62,7 @@ static int pnv_smp_cpu_bootable(unsigned int nr)
62 return 1; 62 return 1;
63} 63}
64 64
65int __devinit pnv_smp_kick_cpu(int nr) 65int pnv_smp_kick_cpu(int nr)
66{ 66{
67 unsigned int pcpu = get_hard_smp_processor_id(nr); 67 unsigned int pcpu = get_hard_smp_processor_id(nr);
68 unsigned long start_here = __pa(*((unsigned long *) 68 unsigned long start_here = __pa(*((unsigned long *)
diff --git a/arch/powerpc/platforms/ps3/os-area.c b/arch/powerpc/platforms/ps3/os-area.c
index 56d26bc4fd41..09787139834d 100644
--- a/arch/powerpc/platforms/ps3/os-area.c
+++ b/arch/powerpc/platforms/ps3/os-area.c
@@ -280,13 +280,13 @@ static void os_area_set_property(struct device_node *node,
280 280
281 if (tmp) { 281 if (tmp) {
282 pr_debug("%s:%d found %s\n", __func__, __LINE__, prop->name); 282 pr_debug("%s:%d found %s\n", __func__, __LINE__, prop->name);
283 prom_remove_property(node, tmp); 283 of_remove_property(node, tmp);
284 } 284 }
285 285
286 result = prom_add_property(node, prop); 286 result = of_add_property(node, prop);
287 287
288 if (result) 288 if (result)
289 pr_debug("%s:%d prom_set_property failed\n", __func__, 289 pr_debug("%s:%d of_set_property failed\n", __func__,
290 __LINE__); 290 __LINE__);
291} 291}
292 292
diff --git a/arch/powerpc/platforms/ps3/repository.c b/arch/powerpc/platforms/ps3/repository.c
index 9b47ba7a5de7..bfccdc7cb85f 100644
--- a/arch/powerpc/platforms/ps3/repository.c
+++ b/arch/powerpc/platforms/ps3/repository.c
@@ -437,7 +437,7 @@ found_dev:
437 return 0; 437 return 0;
438} 438}
439 439
440int __devinit ps3_repository_find_devices(enum ps3_bus_type bus_type, 440int ps3_repository_find_devices(enum ps3_bus_type bus_type,
441 int (*callback)(const struct ps3_repository_device *repo)) 441 int (*callback)(const struct ps3_repository_device *repo))
442{ 442{
443 int result = 0; 443 int result = 0;
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index 0f1b706506ed..a1a7b9a67ffd 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -13,17 +13,16 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/kref.h> 14#include <linux/kref.h>
15#include <linux/notifier.h> 15#include <linux/notifier.h>
16#include <linux/proc_fs.h>
17#include <linux/spinlock.h> 16#include <linux/spinlock.h>
18#include <linux/cpu.h> 17#include <linux/cpu.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/of.h>
20#include "offline_states.h" 20#include "offline_states.h"
21 21
22#include <asm/prom.h> 22#include <asm/prom.h>
23#include <asm/machdep.h> 23#include <asm/machdep.h>
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <asm/rtas.h> 25#include <asm/rtas.h>
26#include <asm/pSeries_reconfig.h>
27 26
28struct cc_workarea { 27struct cc_workarea {
29 u32 drc_index; 28 u32 drc_index;
@@ -255,9 +254,6 @@ static struct device_node *derive_parent(const char *path)
255 254
256int dlpar_attach_node(struct device_node *dn) 255int dlpar_attach_node(struct device_node *dn)
257{ 256{
258#ifdef CONFIG_PROC_DEVICETREE
259 struct proc_dir_entry *ent;
260#endif
261 int rc; 257 int rc;
262 258
263 of_node_set_flag(dn, OF_DYNAMIC); 259 of_node_set_flag(dn, OF_DYNAMIC);
@@ -266,44 +262,26 @@ int dlpar_attach_node(struct device_node *dn)
266 if (!dn->parent) 262 if (!dn->parent)
267 return -ENOMEM; 263 return -ENOMEM;
268 264
269 rc = pSeries_reconfig_notify(PSERIES_RECONFIG_ADD, dn); 265 rc = of_attach_node(dn);
270 if (rc) { 266 if (rc) {
271 printk(KERN_ERR "Failed to add device node %s\n", 267 printk(KERN_ERR "Failed to add device node %s\n",
272 dn->full_name); 268 dn->full_name);
273 return rc; 269 return rc;
274 } 270 }
275 271
276 of_attach_node(dn);
277
278#ifdef CONFIG_PROC_DEVICETREE
279 ent = proc_mkdir(strrchr(dn->full_name, '/') + 1, dn->parent->pde);
280 if (ent)
281 proc_device_tree_add_node(dn, ent);
282#endif
283
284 of_node_put(dn->parent); 272 of_node_put(dn->parent);
285 return 0; 273 return 0;
286} 274}
287 275
288int dlpar_detach_node(struct device_node *dn) 276int dlpar_detach_node(struct device_node *dn)
289{ 277{
290#ifdef CONFIG_PROC_DEVICETREE 278 int rc;
291 struct device_node *parent = dn->parent;
292 struct property *prop = dn->properties;
293
294 while (prop) {
295 remove_proc_entry(prop->name, dn->pde);
296 prop = prop->next;
297 }
298 279
299 if (dn->pde) 280 rc = of_detach_node(dn);
300 remove_proc_entry(dn->pde->name, parent->pde); 281 if (rc)
301#endif 282 return rc;
302 283
303 pSeries_reconfig_notify(PSERIES_RECONFIG_REMOVE, dn);
304 of_detach_node(dn);
305 of_node_put(dn); /* Must decrement the refcount */ 284 of_node_put(dn); /* Must decrement the refcount */
306
307 return 0; 285 return 0;
308} 286}
309 287
diff --git a/arch/powerpc/platforms/pseries/eeh_dev.c b/arch/powerpc/platforms/pseries/eeh_dev.c
index 66442341d3a6..1efa28f5fc54 100644
--- a/arch/powerpc/platforms/pseries/eeh_dev.c
+++ b/arch/powerpc/platforms/pseries/eeh_dev.c
@@ -49,7 +49,7 @@
49 * It will create EEH device according to the given OF node. The function 49 * It will create EEH device according to the given OF node. The function
50 * might be called by PCI emunation, DR, PHB hotplug. 50 * might be called by PCI emunation, DR, PHB hotplug.
51 */ 51 */
52void * __devinit eeh_dev_init(struct device_node *dn, void *data) 52void *eeh_dev_init(struct device_node *dn, void *data)
53{ 53{
54 struct pci_controller *phb = data; 54 struct pci_controller *phb = data;
55 struct eeh_dev *edev; 55 struct eeh_dev *edev;
@@ -77,7 +77,7 @@ void * __devinit eeh_dev_init(struct device_node *dn, void *data)
77 * Scan the PHB OF node and its child association, then create the 77 * Scan the PHB OF node and its child association, then create the
78 * EEH devices accordingly 78 * EEH devices accordingly
79 */ 79 */
80void __devinit eeh_dev_phb_init_dynamic(struct pci_controller *phb) 80void eeh_dev_phb_init_dynamic(struct pci_controller *phb)
81{ 81{
82 struct device_node *dn = phb->dn; 82 struct device_node *dn = phb->dn;
83 83
diff --git a/arch/powerpc/platforms/pseries/eeh_pe.c b/arch/powerpc/platforms/pseries/eeh_pe.c
index 797cd181dc3f..fe43d1aa2cf1 100644
--- a/arch/powerpc/platforms/pseries/eeh_pe.c
+++ b/arch/powerpc/platforms/pseries/eeh_pe.c
@@ -66,7 +66,7 @@ static struct eeh_pe *eeh_pe_alloc(struct pci_controller *phb, int type)
66 * The function should be called while the PHB is detected during 66 * The function should be called while the PHB is detected during
67 * system boot or PCI hotplug in order to create PHB PE. 67 * system boot or PCI hotplug in order to create PHB PE.
68 */ 68 */
69int __devinit eeh_phb_pe_create(struct pci_controller *phb) 69int eeh_phb_pe_create(struct pci_controller *phb)
70{ 70{
71 struct eeh_pe *pe; 71 struct eeh_pe *pe;
72 72
@@ -449,7 +449,7 @@ int eeh_rmv_from_parent_pe(struct eeh_dev *edev, int purge_pe)
449 if (list_empty(&pe->edevs)) { 449 if (list_empty(&pe->edevs)) {
450 cnt = 0; 450 cnt = 0;
451 list_for_each_entry(child, &pe->child_list, child) { 451 list_for_each_entry(child, &pe->child_list, child) {
452 if (!(pe->type & EEH_PE_INVALID)) { 452 if (!(child->type & EEH_PE_INVALID)) {
453 cnt++; 453 cnt++;
454 break; 454 break;
455 } 455 }
diff --git a/arch/powerpc/platforms/pseries/firmware.c b/arch/powerpc/platforms/pseries/firmware.c
index 0b0eff0cce35..7b56118f531c 100644
--- a/arch/powerpc/platforms/pseries/firmware.c
+++ b/arch/powerpc/platforms/pseries/firmware.c
@@ -56,6 +56,7 @@ firmware_features_table[FIRMWARE_MAX_FEATURES] = {
56 {FW_FEATURE_MULTITCE, "hcall-multi-tce"}, 56 {FW_FEATURE_MULTITCE, "hcall-multi-tce"},
57 {FW_FEATURE_SPLPAR, "hcall-splpar"}, 57 {FW_FEATURE_SPLPAR, "hcall-splpar"},
58 {FW_FEATURE_VPHN, "hcall-vphn"}, 58 {FW_FEATURE_VPHN, "hcall-vphn"},
59 {FW_FEATURE_SET_MODE, "hcall-set-mode"},
59}; 60};
60 61
61/* Build up the firmware features bitmask using the contents of 62/* Build up the firmware features bitmask using the contents of
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 64c97d8ac0c5..a38956269fbf 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -23,12 +23,12 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/sched.h> /* for idle_task_exit */ 24#include <linux/sched.h> /* for idle_task_exit */
25#include <linux/cpu.h> 25#include <linux/cpu.h>
26#include <linux/of.h>
26#include <asm/prom.h> 27#include <asm/prom.h>
27#include <asm/rtas.h> 28#include <asm/rtas.h>
28#include <asm/firmware.h> 29#include <asm/firmware.h>
29#include <asm/machdep.h> 30#include <asm/machdep.h>
30#include <asm/vdso_datapage.h> 31#include <asm/vdso_datapage.h>
31#include <asm/pSeries_reconfig.h>
32#include <asm/xics.h> 32#include <asm/xics.h>
33#include "plpar_wrappers.h" 33#include "plpar_wrappers.h"
34#include "offline_states.h" 34#include "offline_states.h"
@@ -333,10 +333,10 @@ static int pseries_smp_notifier(struct notifier_block *nb,
333 int err = 0; 333 int err = 0;
334 334
335 switch (action) { 335 switch (action) {
336 case PSERIES_RECONFIG_ADD: 336 case OF_RECONFIG_ATTACH_NODE:
337 err = pseries_add_processor(node); 337 err = pseries_add_processor(node);
338 break; 338 break;
339 case PSERIES_RECONFIG_REMOVE: 339 case OF_RECONFIG_DETACH_NODE:
340 pseries_remove_processor(node); 340 pseries_remove_processor(node);
341 break; 341 break;
342 } 342 }
@@ -399,7 +399,7 @@ static int __init pseries_cpu_hotplug_init(void)
399 399
400 /* Processors can be added/removed only on LPAR */ 400 /* Processors can be added/removed only on LPAR */
401 if (firmware_has_feature(FW_FEATURE_LPAR)) { 401 if (firmware_has_feature(FW_FEATURE_LPAR)) {
402 pSeries_reconfig_notifier_register(&pseries_smp_nb); 402 of_reconfig_notifier_register(&pseries_smp_nb);
403 cpu_maps_update_begin(); 403 cpu_maps_update_begin();
404 if (cede_offline_enabled && parse_cede_parameters() == 0) { 404 if (cede_offline_enabled && parse_cede_parameters() == 0) {
405 default_offline_state = CPU_STATE_INACTIVE; 405 default_offline_state = CPU_STATE_INACTIVE;
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index ecdb0a6b3171..2372c609fa2b 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -16,7 +16,6 @@
16 16
17#include <asm/firmware.h> 17#include <asm/firmware.h>
18#include <asm/machdep.h> 18#include <asm/machdep.h>
19#include <asm/pSeries_reconfig.h>
20#include <asm/sparsemem.h> 19#include <asm/sparsemem.h>
21 20
22static unsigned long get_memblock_size(void) 21static unsigned long get_memblock_size(void)
@@ -187,42 +186,69 @@ static int pseries_add_memory(struct device_node *np)
187 return (ret < 0) ? -EINVAL : 0; 186 return (ret < 0) ? -EINVAL : 0;
188} 187}
189 188
190static int pseries_drconf_memory(unsigned long *base, unsigned int action) 189static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
191{ 190{
191 struct of_drconf_cell *new_drmem, *old_drmem;
192 unsigned long memblock_size; 192 unsigned long memblock_size;
193 int rc; 193 u32 entries;
194 u32 *p;
195 int i, rc = -EINVAL;
194 196
195 memblock_size = get_memblock_size(); 197 memblock_size = get_memblock_size();
196 if (!memblock_size) 198 if (!memblock_size)
197 return -EINVAL; 199 return -EINVAL;
198 200
199 if (action == PSERIES_DRCONF_MEM_ADD) { 201 p = (u32 *)of_get_property(pr->dn, "ibm,dynamic-memory", NULL);
200 rc = memblock_add(*base, memblock_size); 202 if (!p)
201 rc = (rc < 0) ? -EINVAL : 0; 203 return -EINVAL;
202 } else if (action == PSERIES_DRCONF_MEM_REMOVE) { 204
203 rc = pseries_remove_memblock(*base, memblock_size); 205 /* The first int of the property is the number of lmb's described
204 } else { 206 * by the property. This is followed by an array of of_drconf_cell
205 rc = -EINVAL; 207 * entries. Get the niumber of entries and skip to the array of
208 * of_drconf_cell's.
209 */
210 entries = *p++;
211 old_drmem = (struct of_drconf_cell *)p;
212
213 p = (u32 *)pr->prop->value;
214 p++;
215 new_drmem = (struct of_drconf_cell *)p;
216
217 for (i = 0; i < entries; i++) {
218 if ((old_drmem[i].flags & DRCONF_MEM_ASSIGNED) &&
219 (!(new_drmem[i].flags & DRCONF_MEM_ASSIGNED))) {
220 rc = pseries_remove_memblock(old_drmem[i].base_addr,
221 memblock_size);
222 break;
223 } else if ((!(old_drmem[i].flags & DRCONF_MEM_ASSIGNED)) &&
224 (new_drmem[i].flags & DRCONF_MEM_ASSIGNED)) {
225 rc = memblock_add(old_drmem[i].base_addr,
226 memblock_size);
227 rc = (rc < 0) ? -EINVAL : 0;
228 break;
229 }
206 } 230 }
207 231
208 return rc; 232 return rc;
209} 233}
210 234
211static int pseries_memory_notifier(struct notifier_block *nb, 235static int pseries_memory_notifier(struct notifier_block *nb,
212 unsigned long action, void *node) 236 unsigned long action, void *node)
213{ 237{
238 struct of_prop_reconfig *pr;
214 int err = 0; 239 int err = 0;
215 240
216 switch (action) { 241 switch (action) {
217 case PSERIES_RECONFIG_ADD: 242 case OF_RECONFIG_ATTACH_NODE:
218 err = pseries_add_memory(node); 243 err = pseries_add_memory(node);
219 break; 244 break;
220 case PSERIES_RECONFIG_REMOVE: 245 case OF_RECONFIG_DETACH_NODE:
221 err = pseries_remove_memory(node); 246 err = pseries_remove_memory(node);
222 break; 247 break;
223 case PSERIES_DRCONF_MEM_ADD: 248 case OF_RECONFIG_UPDATE_PROPERTY:
224 case PSERIES_DRCONF_MEM_REMOVE: 249 pr = (struct of_prop_reconfig *)node;
225 err = pseries_drconf_memory(node, action); 250 if (!strcmp(pr->prop->name, "ibm,dynamic-memory"))
251 err = pseries_update_drconf_memory(pr);
226 break; 252 break;
227 } 253 }
228 return notifier_from_errno(err); 254 return notifier_from_errno(err);
@@ -235,7 +261,7 @@ static struct notifier_block pseries_mem_nb = {
235static int __init pseries_memory_hotplug_init(void) 261static int __init pseries_memory_hotplug_init(void)
236{ 262{
237 if (firmware_has_feature(FW_FEATURE_LPAR)) 263 if (firmware_has_feature(FW_FEATURE_LPAR))
238 pSeries_reconfig_notifier_register(&pseries_mem_nb); 264 of_reconfig_notifier_register(&pseries_mem_nb);
239 265
240 return 0; 266 return 0;
241} 267}
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index 6153eea27ce7..e2685badb5db 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -36,13 +36,13 @@
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/crash_dump.h> 37#include <linux/crash_dump.h>
38#include <linux/memory.h> 38#include <linux/memory.h>
39#include <linux/of.h>
39#include <asm/io.h> 40#include <asm/io.h>
40#include <asm/prom.h> 41#include <asm/prom.h>
41#include <asm/rtas.h> 42#include <asm/rtas.h>
42#include <asm/iommu.h> 43#include <asm/iommu.h>
43#include <asm/pci-bridge.h> 44#include <asm/pci-bridge.h>
44#include <asm/machdep.h> 45#include <asm/machdep.h>
45#include <asm/pSeries_reconfig.h>
46#include <asm/firmware.h> 46#include <asm/firmware.h>
47#include <asm/tce.h> 47#include <asm/tce.h>
48#include <asm/ppc-pci.h> 48#include <asm/ppc-pci.h>
@@ -760,7 +760,7 @@ static void remove_ddw(struct device_node *np)
760 __remove_ddw(np, ddw_avail, liobn); 760 __remove_ddw(np, ddw_avail, liobn);
761 761
762delprop: 762delprop:
763 ret = prom_remove_property(np, win64); 763 ret = of_remove_property(np, win64);
764 if (ret) 764 if (ret)
765 pr_warning("%s: failed to remove direct window property: %d\n", 765 pr_warning("%s: failed to remove direct window property: %d\n",
766 np->full_name, ret); 766 np->full_name, ret);
@@ -1070,7 +1070,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
1070 goto out_free_window; 1070 goto out_free_window;
1071 } 1071 }
1072 1072
1073 ret = prom_add_property(pdn, win64); 1073 ret = of_add_property(pdn, win64);
1074 if (ret) { 1074 if (ret) {
1075 dev_err(&dev->dev, "unable to add dma window property for %s: %d", 1075 dev_err(&dev->dev, "unable to add dma window property for %s: %d",
1076 pdn->full_name, ret); 1076 pdn->full_name, ret);
@@ -1294,7 +1294,7 @@ static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long acti
1294 struct direct_window *window; 1294 struct direct_window *window;
1295 1295
1296 switch (action) { 1296 switch (action) {
1297 case PSERIES_RECONFIG_REMOVE: 1297 case OF_RECONFIG_DETACH_NODE:
1298 if (pci && pci->iommu_table) 1298 if (pci && pci->iommu_table)
1299 iommu_free_table(pci->iommu_table, np->full_name); 1299 iommu_free_table(pci->iommu_table, np->full_name);
1300 1300
@@ -1357,7 +1357,7 @@ void iommu_init_early_pSeries(void)
1357 } 1357 }
1358 1358
1359 1359
1360 pSeries_reconfig_notifier_register(&iommu_reconfig_nb); 1360 of_reconfig_notifier_register(&iommu_reconfig_nb);
1361 register_memory_notifier(&iommu_mem_nb); 1361 register_memory_notifier(&iommu_mem_nb);
1362 1362
1363 set_pci_dma_ops(&dma_iommu_ops); 1363 set_pci_dma_ops(&dma_iommu_ops);
diff --git a/arch/powerpc/platforms/pseries/mobility.c b/arch/powerpc/platforms/pseries/mobility.c
index dd30b12edfe4..6573808cc5f3 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -116,7 +116,7 @@ static int update_dt_property(struct device_node *dn, struct property **prop,
116 } 116 }
117 117
118 if (!more) { 118 if (!more) {
119 prom_update_property(dn, new_prop); 119 of_update_property(dn, new_prop);
120 new_prop = NULL; 120 new_prop = NULL;
121 } 121 }
122 122
@@ -172,7 +172,7 @@ static int update_dt_node(u32 phandle)
172 172
173 case 0x80000000: 173 case 0x80000000:
174 prop = of_find_property(dn, prop_name, NULL); 174 prop = of_find_property(dn, prop_name, NULL);
175 prom_remove_property(dn, prop); 175 of_remove_property(dn, prop);
176 prop = NULL; 176 prop = NULL;
177 break; 177 break;
178 178
diff --git a/arch/powerpc/platforms/pseries/msi.c b/arch/powerpc/platforms/pseries/msi.c
index d19f4977c834..e5b084723131 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -220,7 +220,8 @@ static struct device_node *find_pe_dn(struct pci_dev *dev, int *total)
220 220
221 /* Get the top level device in the PE */ 221 /* Get the top level device in the PE */
222 edev = of_node_to_eeh_dev(dn); 222 edev = of_node_to_eeh_dev(dn);
223 edev = list_first_entry(&edev->pe->edevs, struct eeh_dev, list); 223 if (edev->pe)
224 edev = list_first_entry(&edev->pe->edevs, struct eeh_dev, list);
224 dn = eeh_dev_to_of_node(edev); 225 dn = eeh_dev_to_of_node(edev);
225 if (!dn) 226 if (!dn)
226 return NULL; 227 return NULL;
diff --git a/arch/powerpc/platforms/pseries/pci_dlpar.c b/arch/powerpc/platforms/pseries/pci_dlpar.c
index 261a577a3dd2..c91b22be9288 100644
--- a/arch/powerpc/platforms/pseries/pci_dlpar.c
+++ b/arch/powerpc/platforms/pseries/pci_dlpar.c
@@ -149,7 +149,7 @@ void pcibios_add_pci_devices(struct pci_bus * bus)
149} 149}
150EXPORT_SYMBOL_GPL(pcibios_add_pci_devices); 150EXPORT_SYMBOL_GPL(pcibios_add_pci_devices);
151 151
152struct pci_controller * __devinit init_phb_dynamic(struct device_node *dn) 152struct pci_controller *init_phb_dynamic(struct device_node *dn)
153{ 153{
154 struct pci_controller *phb; 154 struct pci_controller *phb;
155 155
diff --git a/arch/powerpc/platforms/pseries/plpar_wrappers.h b/arch/powerpc/platforms/pseries/plpar_wrappers.h
index 13e8cc43adf7..e6cc34a67053 100644
--- a/arch/powerpc/platforms/pseries/plpar_wrappers.h
+++ b/arch/powerpc/platforms/pseries/plpar_wrappers.h
@@ -273,4 +273,35 @@ static inline long plpar_put_term_char(unsigned long termno, unsigned long len,
273 lbuf[1]); 273 lbuf[1]);
274} 274}
275 275
276/* Set various resource mode parameters */
277static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
278 unsigned long value1, unsigned long value2)
279{
280 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
281}
282
283/*
284 * Enable relocation on exceptions on this partition
285 *
286 * Note: this call has a partition wide scope and can take a while to complete.
287 * If it returns H_LONG_BUSY_* it should be retried periodically until it
288 * returns H_SUCCESS.
289 */
290static inline long enable_reloc_on_exceptions(void)
291{
292 /* mflags = 3: Exceptions at 0xC000000000004000 */
293 return plpar_set_mode(3, 3, 0, 0);
294}
295
296/*
297 * Disable relocation on exceptions on this partition
298 *
299 * Note: this call has a partition wide scope and can take a while to complete.
300 * If it returns H_LONG_BUSY_* it should be retried periodically until it
301 * returns H_SUCCESS.
302 */
303static inline long disable_reloc_on_exceptions(void) {
304 return plpar_set_mode(0, 3, 0, 0);
305}
306
276#endif /* _PSERIES_PLPAR_WRAPPERS_H */ 307#endif /* _PSERIES_PLPAR_WRAPPERS_H */
diff --git a/arch/powerpc/platforms/pseries/processor_idle.c b/arch/powerpc/platforms/pseries/processor_idle.c
index 45d00e5fe14d..4d806b419606 100644
--- a/arch/powerpc/platforms/pseries/processor_idle.c
+++ b/arch/powerpc/platforms/pseries/processor_idle.c
@@ -36,7 +36,7 @@ static struct cpuidle_state *cpuidle_state_table;
36static inline void idle_loop_prolog(unsigned long *in_purr, ktime_t *kt_before) 36static inline void idle_loop_prolog(unsigned long *in_purr, ktime_t *kt_before)
37{ 37{
38 38
39 *kt_before = ktime_get_real(); 39 *kt_before = ktime_get();
40 *in_purr = mfspr(SPRN_PURR); 40 *in_purr = mfspr(SPRN_PURR);
41 /* 41 /*
42 * Indicate to the HV that we are idle. Now would be 42 * Indicate to the HV that we are idle. Now would be
@@ -50,7 +50,7 @@ static inline s64 idle_loop_epilog(unsigned long in_purr, ktime_t kt_before)
50 get_lppaca()->wait_state_cycles += mfspr(SPRN_PURR) - in_purr; 50 get_lppaca()->wait_state_cycles += mfspr(SPRN_PURR) - in_purr;
51 get_lppaca()->idle = 0; 51 get_lppaca()->idle = 0;
52 52
53 return ktime_to_us(ktime_sub(ktime_get_real(), kt_before)); 53 return ktime_to_us(ktime_sub(ktime_get(), kt_before));
54} 54}
55 55
56static int snooze_loop(struct cpuidle_device *dev, 56static int snooze_loop(struct cpuidle_device *dev,
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index 39f71fba9b38..d6491bd481d0 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -16,55 +16,13 @@
16#include <linux/notifier.h> 16#include <linux/notifier.h>
17#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/of.h>
19 20
20#include <asm/prom.h> 21#include <asm/prom.h>
21#include <asm/machdep.h> 22#include <asm/machdep.h>
22#include <asm/uaccess.h> 23#include <asm/uaccess.h>
23#include <asm/pSeries_reconfig.h>
24#include <asm/mmu.h> 24#include <asm/mmu.h>
25 25
26
27
28/*
29 * Routines for "runtime" addition and removal of device tree nodes.
30 */
31#ifdef CONFIG_PROC_DEVICETREE
32/*
33 * Add a node to /proc/device-tree.
34 */
35static void add_node_proc_entries(struct device_node *np)
36{
37 struct proc_dir_entry *ent;
38
39 ent = proc_mkdir(strrchr(np->full_name, '/') + 1, np->parent->pde);
40 if (ent)
41 proc_device_tree_add_node(np, ent);
42}
43
44static void remove_node_proc_entries(struct device_node *np)
45{
46 struct property *pp = np->properties;
47 struct device_node *parent = np->parent;
48
49 while (pp) {
50 remove_proc_entry(pp->name, np->pde);
51 pp = pp->next;
52 }
53 if (np->pde)
54 remove_proc_entry(np->pde->name, parent->pde);
55}
56#else /* !CONFIG_PROC_DEVICETREE */
57static void add_node_proc_entries(struct device_node *np)
58{
59 return;
60}
61
62static void remove_node_proc_entries(struct device_node *np)
63{
64 return;
65}
66#endif /* CONFIG_PROC_DEVICETREE */
67
68/** 26/**
69 * derive_parent - basically like dirname(1) 27 * derive_parent - basically like dirname(1)
70 * @path: the full_name of a node to be added to the tree 28 * @path: the full_name of a node to be added to the tree
@@ -97,28 +55,6 @@ static struct device_node *derive_parent(const char *path)
97 return parent; 55 return parent;
98} 56}
99 57
100static BLOCKING_NOTIFIER_HEAD(pSeries_reconfig_chain);
101
102int pSeries_reconfig_notifier_register(struct notifier_block *nb)
103{
104 return blocking_notifier_chain_register(&pSeries_reconfig_chain, nb);
105}
106EXPORT_SYMBOL_GPL(pSeries_reconfig_notifier_register);
107
108void pSeries_reconfig_notifier_unregister(struct notifier_block *nb)
109{
110 blocking_notifier_chain_unregister(&pSeries_reconfig_chain, nb);
111}
112EXPORT_SYMBOL_GPL(pSeries_reconfig_notifier_unregister);
113
114int pSeries_reconfig_notify(unsigned long action, void *p)
115{
116 int err = blocking_notifier_call_chain(&pSeries_reconfig_chain,
117 action, p);
118
119 return notifier_to_errno(err);
120}
121
122static int pSeries_reconfig_add_node(const char *path, struct property *proplist) 58static int pSeries_reconfig_add_node(const char *path, struct property *proplist)
123{ 59{
124 struct device_node *np; 60 struct device_node *np;
@@ -142,16 +78,12 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist
142 goto out_err; 78 goto out_err;
143 } 79 }
144 80
145 err = pSeries_reconfig_notify(PSERIES_RECONFIG_ADD, np); 81 err = of_attach_node(np);
146 if (err) { 82 if (err) {
147 printk(KERN_ERR "Failed to add device node %s\n", path); 83 printk(KERN_ERR "Failed to add device node %s\n", path);
148 goto out_err; 84 goto out_err;
149 } 85 }
150 86
151 of_attach_node(np);
152
153 add_node_proc_entries(np);
154
155 of_node_put(np->parent); 87 of_node_put(np->parent);
156 88
157 return 0; 89 return 0;
@@ -179,11 +111,7 @@ static int pSeries_reconfig_remove_node(struct device_node *np)
179 return -EBUSY; 111 return -EBUSY;
180 } 112 }
181 113
182 remove_node_proc_entries(np);
183
184 pSeries_reconfig_notify(PSERIES_RECONFIG_REMOVE, np);
185 of_detach_node(np); 114 of_detach_node(np);
186
187 of_node_put(parent); 115 of_node_put(parent);
188 of_node_put(np); /* Must decrement the refcount */ 116 of_node_put(np); /* Must decrement the refcount */
189 return 0; 117 return 0;
@@ -281,12 +209,11 @@ static struct property *new_property(const char *name, const int length,
281 if (!new) 209 if (!new)
282 return NULL; 210 return NULL;
283 211
284 if (!(new->name = kmalloc(strlen(name) + 1, GFP_KERNEL))) 212 if (!(new->name = kstrdup(name, GFP_KERNEL)))
285 goto cleanup; 213 goto cleanup;
286 if (!(new->value = kmalloc(length + 1, GFP_KERNEL))) 214 if (!(new->value = kmalloc(length + 1, GFP_KERNEL)))
287 goto cleanup; 215 goto cleanup;
288 216
289 strcpy(new->name, name);
290 memcpy(new->value, value, length); 217 memcpy(new->value, value, length);
291 *(((char *)new->value) + length) = 0; 218 *(((char *)new->value) + length) = 0;
292 new->length = length; 219 new->length = length;
@@ -398,7 +325,7 @@ static int do_add_property(char *buf, size_t bufsize)
398 if (!prop) 325 if (!prop)
399 return -ENOMEM; 326 return -ENOMEM;
400 327
401 prom_add_property(np, prop); 328 of_add_property(np, prop);
402 329
403 return 0; 330 return 0;
404} 331}
@@ -422,16 +349,15 @@ static int do_remove_property(char *buf, size_t bufsize)
422 349
423 prop = of_find_property(np, buf, NULL); 350 prop = of_find_property(np, buf, NULL);
424 351
425 return prom_remove_property(np, prop); 352 return of_remove_property(np, prop);
426} 353}
427 354
428static int do_update_property(char *buf, size_t bufsize) 355static int do_update_property(char *buf, size_t bufsize)
429{ 356{
430 struct device_node *np; 357 struct device_node *np;
431 struct pSeries_reconfig_prop_update upd_value;
432 unsigned char *value; 358 unsigned char *value;
433 char *name, *end, *next_prop; 359 char *name, *end, *next_prop;
434 int rc, length; 360 int length;
435 struct property *newprop; 361 struct property *newprop;
436 buf = parse_node(buf, bufsize, &np); 362 buf = parse_node(buf, bufsize, &np);
437 end = buf + bufsize; 363 end = buf + bufsize;
@@ -453,41 +379,7 @@ static int do_update_property(char *buf, size_t bufsize)
453 if (!strcmp(name, "slb-size") || !strcmp(name, "ibm,slb-size")) 379 if (!strcmp(name, "slb-size") || !strcmp(name, "ibm,slb-size"))
454 slb_set_size(*(int *)value); 380 slb_set_size(*(int *)value);
455 381
456 upd_value.node = np; 382 return of_update_property(np, newprop);
457 upd_value.property = newprop;
458 pSeries_reconfig_notify(PSERIES_UPDATE_PROPERTY, &upd_value);
459
460 rc = prom_update_property(np, newprop);
461 if (rc)
462 return rc;
463
464 /* For memory under the ibm,dynamic-reconfiguration-memory node
465 * of the device tree, adding and removing memory is just an update
466 * to the ibm,dynamic-memory property instead of adding/removing a
467 * memory node in the device tree. For these cases we still need to
468 * involve the notifier chain.
469 */
470 if (!strcmp(name, "ibm,dynamic-memory")) {
471 int action;
472
473 next_prop = parse_next_property(next_prop, end, &name,
474 &length, &value);
475 if (!next_prop)
476 return -EINVAL;
477
478 if (!strcmp(name, "add"))
479 action = PSERIES_DRCONF_MEM_ADD;
480 else
481 action = PSERIES_DRCONF_MEM_REMOVE;
482
483 rc = pSeries_reconfig_notify(action, value);
484 if (rc) {
485 prom_update_property(np, newprop);
486 return rc;
487 }
488 }
489
490 return 0;
491} 383}
492 384
493/** 385/**
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index e3cb7ae61658..ca55882465d6 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -40,6 +40,8 @@
40#include <linux/seq_file.h> 40#include <linux/seq_file.h>
41#include <linux/root_dev.h> 41#include <linux/root_dev.h>
42#include <linux/cpuidle.h> 42#include <linux/cpuidle.h>
43#include <linux/of.h>
44#include <linux/kexec.h>
43 45
44#include <asm/mmu.h> 46#include <asm/mmu.h>
45#include <asm/processor.h> 47#include <asm/processor.h>
@@ -63,7 +65,6 @@
63#include <asm/smp.h> 65#include <asm/smp.h>
64#include <asm/firmware.h> 66#include <asm/firmware.h>
65#include <asm/eeh.h> 67#include <asm/eeh.h>
66#include <asm/pSeries_reconfig.h>
67 68
68#include "plpar_wrappers.h" 69#include "plpar_wrappers.h"
69#include "pseries.h" 70#include "pseries.h"
@@ -258,7 +259,7 @@ static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long act
258 int err = NOTIFY_OK; 259 int err = NOTIFY_OK;
259 260
260 switch (action) { 261 switch (action) {
261 case PSERIES_RECONFIG_ADD: 262 case OF_RECONFIG_ATTACH_NODE:
262 pci = np->parent->data; 263 pci = np->parent->data;
263 if (pci) { 264 if (pci) {
264 update_dn_pci_info(np, pci->phb); 265 update_dn_pci_info(np, pci->phb);
@@ -367,6 +368,65 @@ static void pSeries_idle(void)
367 } 368 }
368} 369}
369 370
371/*
372 * Enable relocation on during exceptions. This has partition wide scope and
373 * may take a while to complete, if it takes longer than one second we will
374 * just give up rather than wasting any more time on this - if that turns out
375 * to ever be a problem in practice we can move this into a kernel thread to
376 * finish off the process later in boot.
377 */
378static int __init pSeries_enable_reloc_on_exc(void)
379{
380 long rc;
381 unsigned int delay, total_delay = 0;
382
383 while (1) {
384 rc = enable_reloc_on_exceptions();
385 if (!H_IS_LONG_BUSY(rc))
386 return rc;
387
388 delay = get_longbusy_msecs(rc);
389 total_delay += delay;
390 if (total_delay > 1000) {
391 pr_warn("Warning: Giving up waiting to enable "
392 "relocation on exceptions (%u msec)!\n",
393 total_delay);
394 return rc;
395 }
396
397 mdelay(delay);
398 }
399}
400
401#ifdef CONFIG_KEXEC
402static long pSeries_disable_reloc_on_exc(void)
403{
404 long rc;
405
406 while (1) {
407 rc = disable_reloc_on_exceptions();
408 if (!H_IS_LONG_BUSY(rc))
409 return rc;
410 mdelay(get_longbusy_msecs(rc));
411 }
412}
413
414static void pSeries_machine_kexec(struct kimage *image)
415{
416 long rc;
417
418 if (firmware_has_feature(FW_FEATURE_SET_MODE) &&
419 (image->type != KEXEC_TYPE_CRASH)) {
420 rc = pSeries_disable_reloc_on_exc();
421 if (rc != H_SUCCESS)
422 pr_warning("Warning: Failed to disable relocation on "
423 "exceptions: %ld\n", rc);
424 }
425
426 default_machine_kexec(image);
427}
428#endif
429
370static void __init pSeries_setup_arch(void) 430static void __init pSeries_setup_arch(void)
371{ 431{
372 panic_timeout = 10; 432 panic_timeout = 10;
@@ -389,7 +449,7 @@ static void __init pSeries_setup_arch(void)
389 /* Find and initialize PCI host bridges */ 449 /* Find and initialize PCI host bridges */
390 init_pci_config_tokens(); 450 init_pci_config_tokens();
391 find_and_init_phbs(); 451 find_and_init_phbs();
392 pSeries_reconfig_notifier_register(&pci_dn_reconfig_nb); 452 of_reconfig_notifier_register(&pci_dn_reconfig_nb);
393 453
394 pSeries_nvram_init(); 454 pSeries_nvram_init();
395 455
@@ -402,6 +462,14 @@ static void __init pSeries_setup_arch(void)
402 ppc_md.enable_pmcs = pseries_lpar_enable_pmcs; 462 ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
403 else 463 else
404 ppc_md.enable_pmcs = power4_enable_pmcs; 464 ppc_md.enable_pmcs = power4_enable_pmcs;
465
466 if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
467 long rc;
468 if ((rc = pSeries_enable_reloc_on_exc()) != H_SUCCESS) {
469 pr_warn("Unable to enable relocation on exceptions: "
470 "%ld\n", rc);
471 }
472 }
405} 473}
406 474
407static int __init pSeries_init_panel(void) 475static int __init pSeries_init_panel(void)
@@ -659,4 +727,7 @@ define_machine(pseries) {
659 .progress = rtas_progress, 727 .progress = rtas_progress,
660 .system_reset_exception = pSeries_system_reset_exception, 728 .system_reset_exception = pSeries_system_reset_exception,
661 .machine_check_exception = pSeries_machine_check_exception, 729 .machine_check_exception = pSeries_machine_check_exception,
730#ifdef CONFIG_KEXEC
731 .machine_kexec = pSeries_machine_kexec,
732#endif
662}; 733};
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index 71706bc34a0d..80cd0be71e06 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -38,7 +38,6 @@
38#include <asm/cputable.h> 38#include <asm/cputable.h>
39#include <asm/firmware.h> 39#include <asm/firmware.h>
40#include <asm/rtas.h> 40#include <asm/rtas.h>
41#include <asm/pSeries_reconfig.h>
42#include <asm/mpic.h> 41#include <asm/mpic.h>
43#include <asm/vdso_datapage.h> 42#include <asm/vdso_datapage.h>
44#include <asm/cputhreads.h> 43#include <asm/cputhreads.h>
@@ -88,7 +87,7 @@ int smp_query_cpu_stopped(unsigned int pcpu)
88 * 0 - failure 87 * 0 - failure
89 * 1 - success 88 * 1 - success
90 */ 89 */
91static inline int __devinit smp_startup_cpu(unsigned int lcpu) 90static inline int smp_startup_cpu(unsigned int lcpu)
92{ 91{
93 int status; 92 int status;
94 unsigned long start_here = __pa((u32)*((unsigned long *) 93 unsigned long start_here = __pa((u32)*((unsigned long *)
@@ -134,7 +133,7 @@ out:
134 return 1; 133 return 1;
135} 134}
136 135
137static void __devinit smp_xics_setup_cpu(int cpu) 136static void smp_xics_setup_cpu(int cpu)
138{ 137{
139 if (cpu != boot_cpuid) 138 if (cpu != boot_cpuid)
140 xics_setup_cpu(); 139 xics_setup_cpu();
@@ -149,7 +148,7 @@ static void __devinit smp_xics_setup_cpu(int cpu)
149#endif 148#endif
150} 149}
151 150
152static int __devinit smp_pSeries_kick_cpu(int nr) 151static int smp_pSeries_kick_cpu(int nr)
153{ 152{
154 BUG_ON(nr < 0 || nr >= NR_CPUS); 153 BUG_ON(nr < 0 || nr >= NR_CPUS);
155 154
diff --git a/arch/powerpc/platforms/wsp/scom_smp.c b/arch/powerpc/platforms/wsp/scom_smp.c
index 141e78032097..b56b70aeb497 100644
--- a/arch/powerpc/platforms/wsp/scom_smp.c
+++ b/arch/powerpc/platforms/wsp/scom_smp.c
@@ -337,8 +337,7 @@ scom_fail:
337 return rc; 337 return rc;
338} 338}
339 339
340int __devinit a2_scom_startup_cpu(unsigned int lcpu, int thr_idx, 340int a2_scom_startup_cpu(unsigned int lcpu, int thr_idx, struct device_node *np)
341 struct device_node *np)
342{ 341{
343 u64 init_iar, init_msr, init_ccr2; 342 u64 init_iar, init_msr, init_ccr2;
344 unsigned long start_here; 343 unsigned long start_here;
diff --git a/arch/powerpc/platforms/wsp/smp.c b/arch/powerpc/platforms/wsp/smp.c
index 0ba103ae83a5..332a18b81403 100644
--- a/arch/powerpc/platforms/wsp/smp.c
+++ b/arch/powerpc/platforms/wsp/smp.c
@@ -23,7 +23,7 @@
23#include "ics.h" 23#include "ics.h"
24#include "wsp.h" 24#include "wsp.h"
25 25
26static void __devinit smp_a2_setup_cpu(int cpu) 26static void smp_a2_setup_cpu(int cpu)
27{ 27{
28 doorbell_setup_this_cpu(); 28 doorbell_setup_this_cpu();
29 29
@@ -31,7 +31,7 @@ static void __devinit smp_a2_setup_cpu(int cpu)
31 xics_setup_cpu(); 31 xics_setup_cpu();
32} 32}
33 33
34int __devinit smp_a2_kick_cpu(int nr) 34int smp_a2_kick_cpu(int nr)
35{ 35{
36 const char *enable_method; 36 const char *enable_method;
37 struct device_node *np; 37 struct device_node *np;
diff --git a/arch/powerpc/platforms/wsp/wsp.h b/arch/powerpc/platforms/wsp/wsp.h
index 10c1d1fff362..62ef21afb89a 100644
--- a/arch/powerpc/platforms/wsp/wsp.h
+++ b/arch/powerpc/platforms/wsp/wsp.h
@@ -18,7 +18,7 @@ extern void a2_setup_smp(void);
18extern int a2_scom_startup_cpu(unsigned int lcpu, int thr_idx, 18extern int a2_scom_startup_cpu(unsigned int lcpu, int thr_idx,
19 struct device_node *np); 19 struct device_node *np);
20extern int smp_a2_cpu_bootable(unsigned int nr); 20extern int smp_a2_cpu_bootable(unsigned int nr);
21extern int __devinit smp_a2_kick_cpu(int nr); 21extern int smp_a2_kick_cpu(int nr);
22 22
23extern void opb_pic_init(void); 23extern void opb_pic_init(void);
24 24
diff --git a/arch/powerpc/platforms/wsp/wsp_pci.c b/arch/powerpc/platforms/wsp/wsp_pci.c
index 1526551f9fe6..8e22f561d171 100644
--- a/arch/powerpc/platforms/wsp/wsp_pci.c
+++ b/arch/powerpc/platforms/wsp/wsp_pci.c
@@ -402,7 +402,7 @@ static struct wsp_dma_table *wsp_pci_create_dma32_table(struct wsp_phb *phb,
402 return ERR_PTR(-ENOMEM); 402 return ERR_PTR(-ENOMEM);
403} 403}
404 404
405static void __devinit wsp_pci_dma_dev_setup(struct pci_dev *pdev) 405static void wsp_pci_dma_dev_setup(struct pci_dev *pdev)
406{ 406{
407 struct dev_archdata *archdata = &pdev->dev.archdata; 407 struct dev_archdata *archdata = &pdev->dev.archdata;
408 struct pci_controller *hose = pci_bus_to_host(pdev->bus); 408 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
diff --git a/arch/powerpc/sysdev/bestcomm/bestcomm.c b/arch/powerpc/sysdev/bestcomm/bestcomm.c
index b3fbb271be87..d9130630f7ef 100644
--- a/arch/powerpc/sysdev/bestcomm/bestcomm.c
+++ b/arch/powerpc/sysdev/bestcomm/bestcomm.c
@@ -30,7 +30,7 @@
30#define DRIVER_NAME "bestcomm-core" 30#define DRIVER_NAME "bestcomm-core"
31 31
32/* MPC5200 device tree match tables */ 32/* MPC5200 device tree match tables */
33static struct of_device_id mpc52xx_sram_ids[] __devinitdata = { 33static struct of_device_id mpc52xx_sram_ids[] = {
34 { .compatible = "fsl,mpc5200-sram", }, 34 { .compatible = "fsl,mpc5200-sram", },
35 { .compatible = "mpc5200-sram", }, 35 { .compatible = "mpc5200-sram", },
36 {} 36 {}
@@ -273,8 +273,7 @@ static u32 fdt_ops[] = {
273}; 273};
274 274
275 275
276static int __devinit 276static int bcom_engine_init(void)
277bcom_engine_init(void)
278{ 277{
279 int task; 278 int task;
280 phys_addr_t tdt_pa, ctx_pa, var_pa, fdt_pa; 279 phys_addr_t tdt_pa, ctx_pa, var_pa, fdt_pa;
@@ -365,7 +364,7 @@ bcom_engine_cleanup(void)
365/* OF platform driver */ 364/* OF platform driver */
366/* ======================================================================== */ 365/* ======================================================================== */
367 366
368static int __devinit mpc52xx_bcom_probe(struct platform_device *op) 367static int mpc52xx_bcom_probe(struct platform_device *op)
369{ 368{
370 struct device_node *ofn_sram; 369 struct device_node *ofn_sram;
371 struct resource res_bcom; 370 struct resource res_bcom;
diff --git a/arch/powerpc/sysdev/fsl_85xx_l2ctlr.c b/arch/powerpc/sysdev/fsl_85xx_l2ctlr.c
index d131c8a1cb15..8cf93f029e17 100644
--- a/arch/powerpc/sysdev/fsl_85xx_l2ctlr.c
+++ b/arch/powerpc/sysdev/fsl_85xx_l2ctlr.c
@@ -69,7 +69,7 @@ static int __init get_offset_from_cmdline(char *str)
69__setup("cache-sram-size=", get_size_from_cmdline); 69__setup("cache-sram-size=", get_size_from_cmdline);
70__setup("cache-sram-offset=", get_offset_from_cmdline); 70__setup("cache-sram-offset=", get_offset_from_cmdline);
71 71
72static int __devinit mpc85xx_l2ctlr_of_probe(struct platform_device *dev) 72static int mpc85xx_l2ctlr_of_probe(struct platform_device *dev)
73{ 73{
74 long rval; 74 long rval;
75 unsigned int rem; 75 unsigned int rem;
@@ -160,7 +160,7 @@ static int __devinit mpc85xx_l2ctlr_of_probe(struct platform_device *dev)
160 return 0; 160 return 0;
161} 161}
162 162
163static int __devexit mpc85xx_l2ctlr_of_remove(struct platform_device *dev) 163static int mpc85xx_l2ctlr_of_remove(struct platform_device *dev)
164{ 164{
165 BUG_ON(!l2ctlr); 165 BUG_ON(!l2ctlr);
166 166
@@ -213,7 +213,7 @@ static struct platform_driver mpc85xx_l2ctlr_of_platform_driver = {
213 .of_match_table = mpc85xx_l2ctlr_of_match, 213 .of_match_table = mpc85xx_l2ctlr_of_match,
214 }, 214 },
215 .probe = mpc85xx_l2ctlr_of_probe, 215 .probe = mpc85xx_l2ctlr_of_probe,
216 .remove = __devexit_p(mpc85xx_l2ctlr_of_remove), 216 .remove = mpc85xx_l2ctlr_of_remove,
217}; 217};
218 218
219static __init int mpc85xx_l2ctlr_of_init(void) 219static __init int mpc85xx_l2ctlr_of_init(void)
diff --git a/arch/powerpc/sysdev/fsl_gtm.c b/arch/powerpc/sysdev/fsl_gtm.c
index 02cf1e7e77fc..0eb871cc3437 100644
--- a/arch/powerpc/sysdev/fsl_gtm.c
+++ b/arch/powerpc/sysdev/fsl_gtm.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Freescale General-purpose Timers Module 2 * Freescale General-purpose Timers Module
3 * 3 *
4 * Copyright (c) Freescale Semicondutor, Inc. 2006. 4 * Copyright (c) Freescale Semiconductor, Inc. 2006.
5 * Shlomi Gridish <gridish@freescale.com> 5 * Shlomi Gridish <gridish@freescale.com>
6 * Jerry Huang <Chang-Ming.Huang@freescale.com> 6 * Jerry Huang <Chang-Ming.Huang@freescale.com>
7 * Copyright (c) MontaVista Software, Inc. 2008. 7 * Copyright (c) MontaVista Software, Inc. 2008.
diff --git a/arch/powerpc/sysdev/fsl_ifc.c b/arch/powerpc/sysdev/fsl_ifc.c
index 097cc9d2585b..2a36fd6a9583 100644
--- a/arch/powerpc/sysdev/fsl_ifc.c
+++ b/arch/powerpc/sysdev/fsl_ifc.c
@@ -73,7 +73,7 @@ int fsl_ifc_find(phys_addr_t addr_base)
73} 73}
74EXPORT_SYMBOL(fsl_ifc_find); 74EXPORT_SYMBOL(fsl_ifc_find);
75 75
76static int __devinit fsl_ifc_ctrl_init(struct fsl_ifc_ctrl *ctrl) 76static int fsl_ifc_ctrl_init(struct fsl_ifc_ctrl *ctrl)
77{ 77{
78 struct fsl_ifc_regs __iomem *ifc = ctrl->regs; 78 struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
79 79
@@ -211,7 +211,7 @@ static irqreturn_t fsl_ifc_ctrl_irq(int irqno, void *data)
211 * resources for the NAND banks themselves are allocated 211 * resources for the NAND banks themselves are allocated
212 * in the chip probe function. 212 * in the chip probe function.
213*/ 213*/
214static int __devinit fsl_ifc_ctrl_probe(struct platform_device *dev) 214static int fsl_ifc_ctrl_probe(struct platform_device *dev)
215{ 215{
216 int ret = 0; 216 int ret = 0;
217 217
diff --git a/arch/powerpc/sysdev/fsl_lbc.c b/arch/powerpc/sysdev/fsl_lbc.c
index 483126d7b3c0..300be2d06a26 100644
--- a/arch/powerpc/sysdev/fsl_lbc.c
+++ b/arch/powerpc/sysdev/fsl_lbc.c
@@ -185,8 +185,8 @@ int fsl_upm_run_pattern(struct fsl_upm *upm, void __iomem *io_base, u32 mar)
185} 185}
186EXPORT_SYMBOL(fsl_upm_run_pattern); 186EXPORT_SYMBOL(fsl_upm_run_pattern);
187 187
188static int __devinit fsl_lbc_ctrl_init(struct fsl_lbc_ctrl *ctrl, 188static int fsl_lbc_ctrl_init(struct fsl_lbc_ctrl *ctrl,
189 struct device_node *node) 189 struct device_node *node)
190{ 190{
191 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 191 struct fsl_lbc_regs __iomem *lbc = ctrl->regs;
192 192
@@ -273,7 +273,7 @@ static irqreturn_t fsl_lbc_ctrl_irq(int irqno, void *data)
273 * in the chip probe function. 273 * in the chip probe function.
274*/ 274*/
275 275
276static int __devinit fsl_lbc_ctrl_probe(struct platform_device *dev) 276static int fsl_lbc_ctrl_probe(struct platform_device *dev)
277{ 277{
278 int ret; 278 int ret;
279 279
diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 51ffafae561e..6e53d97abd3f 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -236,7 +236,6 @@ static void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
236 u32 intr_index; 236 u32 intr_index;
237 u32 have_shift = 0; 237 u32 have_shift = 0;
238 struct fsl_msi_cascade_data *cascade_data; 238 struct fsl_msi_cascade_data *cascade_data;
239 unsigned int ret;
240 239
241 cascade_data = irq_get_handler_data(irq); 240 cascade_data = irq_get_handler_data(irq);
242 msi_data = cascade_data->msi_data; 241 msi_data = cascade_data->msi_data;
@@ -268,7 +267,9 @@ static void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
268 case FSL_PIC_IP_IPIC: 267 case FSL_PIC_IP_IPIC:
269 msir_value = fsl_msi_read(msi_data->msi_regs, msir_index * 0x4); 268 msir_value = fsl_msi_read(msi_data->msi_regs, msir_index * 0x4);
270 break; 269 break;
271 case FSL_PIC_IP_VMPIC: 270#ifdef CONFIG_EPAPR_PARAVIRT
271 case FSL_PIC_IP_VMPIC: {
272 unsigned int ret;
272 ret = fh_vmpic_get_msir(virq_to_hw(irq), &msir_value); 273 ret = fh_vmpic_get_msir(virq_to_hw(irq), &msir_value);
273 if (ret) { 274 if (ret) {
274 pr_err("fsl-msi: fh_vmpic_get_msir() failed for " 275 pr_err("fsl-msi: fh_vmpic_get_msir() failed for "
@@ -277,6 +278,8 @@ static void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
277 } 278 }
278 break; 279 break;
279 } 280 }
281#endif
282 }
280 283
281 while (msir_value) { 284 while (msir_value) {
282 intr_index = ffs(msir_value) - 1; 285 intr_index = ffs(msir_value) - 1;
@@ -330,9 +333,8 @@ static int fsl_of_msi_remove(struct platform_device *ofdev)
330 return 0; 333 return 0;
331} 334}
332 335
333static int __devinit fsl_msi_setup_hwirq(struct fsl_msi *msi, 336static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
334 struct platform_device *dev, 337 int offset, int irq_index)
335 int offset, int irq_index)
336{ 338{
337 struct fsl_msi_cascade_data *cascade_data = NULL; 339 struct fsl_msi_cascade_data *cascade_data = NULL;
338 int virt_msir; 340 int virt_msir;
@@ -360,7 +362,7 @@ static int __devinit fsl_msi_setup_hwirq(struct fsl_msi *msi,
360} 362}
361 363
362static const struct of_device_id fsl_of_msi_ids[]; 364static const struct of_device_id fsl_of_msi_ids[];
363static int __devinit fsl_of_msi_probe(struct platform_device *dev) 365static int fsl_of_msi_probe(struct platform_device *dev)
364{ 366{
365 const struct of_device_id *match; 367 const struct of_device_id *match;
366 struct fsl_msi *msi; 368 struct fsl_msi *msi;
@@ -508,10 +510,12 @@ static const struct of_device_id fsl_of_msi_ids[] = {
508 .compatible = "fsl,ipic-msi", 510 .compatible = "fsl,ipic-msi",
509 .data = &ipic_msi_feature, 511 .data = &ipic_msi_feature,
510 }, 512 },
513#ifdef CONFIG_EPAPR_PARAVIRT
511 { 514 {
512 .compatible = "fsl,vmpic-msi", 515 .compatible = "fsl,vmpic-msi",
513 .data = &vmpic_msi_feature, 516 .data = &vmpic_msi_feature,
514 }, 517 },
518#endif
515 {} 519 {}
516}; 520};
517 521
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index ffb93ae9379b..92a5915b1827 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -36,7 +36,7 @@
36 36
37static int fsl_pcie_bus_fixup, is_mpc83xx_pci; 37static int fsl_pcie_bus_fixup, is_mpc83xx_pci;
38 38
39static void __devinit quirk_fsl_pcie_header(struct pci_dev *dev) 39static void quirk_fsl_pcie_header(struct pci_dev *dev)
40{ 40{
41 u8 hdr_type; 41 u8 hdr_type;
42 42
@@ -89,7 +89,7 @@ static int fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask)
89 return 0; 89 return 0;
90} 90}
91 91
92static int __init setup_one_atmu(struct ccsr_pci __iomem *pci, 92static int setup_one_atmu(struct ccsr_pci __iomem *pci,
93 unsigned int index, const struct resource *res, 93 unsigned int index, const struct resource *res,
94 resource_size_t offset) 94 resource_size_t offset)
95{ 95{
@@ -126,7 +126,7 @@ static int __init setup_one_atmu(struct ccsr_pci __iomem *pci,
126} 126}
127 127
128/* atmu setup for fsl pci/pcie controller */ 128/* atmu setup for fsl pci/pcie controller */
129static void __init setup_pci_atmu(struct pci_controller *hose, 129static void setup_pci_atmu(struct pci_controller *hose,
130 struct resource *rsrc) 130 struct resource *rsrc)
131{ 131{
132 struct ccsr_pci __iomem *pci; 132 struct ccsr_pci __iomem *pci;
@@ -136,7 +136,7 @@ static void __init setup_pci_atmu(struct pci_controller *hose,
136 u32 pcicsrbar = 0, pcicsrbar_sz; 136 u32 pcicsrbar = 0, pcicsrbar_sz;
137 u32 piwar = PIWAR_EN | PIWAR_PF | PIWAR_TGI_LOCAL | 137 u32 piwar = PIWAR_EN | PIWAR_PF | PIWAR_TGI_LOCAL |
138 PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP; 138 PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
139 char *name = hose->dn->full_name; 139 const char *name = hose->dn->full_name;
140 const u64 *reg; 140 const u64 *reg;
141 int len; 141 int len;
142 142
@@ -871,7 +871,7 @@ void fsl_pci_assign_primary(void)
871 } 871 }
872} 872}
873 873
874static int __devinit fsl_pci_probe(struct platform_device *pdev) 874static int fsl_pci_probe(struct platform_device *pdev)
875{ 875{
876 int ret; 876 int ret;
877 struct device_node *node; 877 struct device_node *node;
@@ -902,9 +902,42 @@ static int __devinit fsl_pci_probe(struct platform_device *pdev)
902 return 0; 902 return 0;
903} 903}
904 904
905#ifdef CONFIG_PM
906static int fsl_pci_resume(struct device *dev)
907{
908 struct pci_controller *hose;
909 struct resource pci_rsrc;
910
911 hose = pci_find_hose_for_OF_device(dev->of_node);
912 if (!hose)
913 return -ENODEV;
914
915 if (of_address_to_resource(dev->of_node, 0, &pci_rsrc)) {
916 dev_err(dev, "Get pci register base failed.");
917 return -ENODEV;
918 }
919
920 setup_pci_atmu(hose, &pci_rsrc);
921
922 return 0;
923}
924
925static const struct dev_pm_ops pci_pm_ops = {
926 .resume = fsl_pci_resume,
927};
928
929#define PCI_PM_OPS (&pci_pm_ops)
930
931#else
932
933#define PCI_PM_OPS NULL
934
935#endif
936
905static struct platform_driver fsl_pci_driver = { 937static struct platform_driver fsl_pci_driver = {
906 .driver = { 938 .driver = {
907 .name = "fsl-pci", 939 .name = "fsl-pci",
940 .pm = PCI_PM_OPS,
908 .of_match_table = pci_ids, 941 .of_match_table = pci_ids,
909 }, 942 },
910 .probe = fsl_pci_probe, 943 .probe = fsl_pci_probe,
diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c
index 5b6f556094dd..e2fb3171f41b 100644
--- a/arch/powerpc/sysdev/fsl_rio.c
+++ b/arch/powerpc/sysdev/fsl_rio.c
@@ -644,7 +644,7 @@ err_rio_regs:
644 644
645/* The probe function for RapidIO peer-to-peer network. 645/* The probe function for RapidIO peer-to-peer network.
646 */ 646 */
647static int __devinit fsl_of_rio_rpn_probe(struct platform_device *dev) 647static int fsl_of_rio_rpn_probe(struct platform_device *dev)
648{ 648{
649 printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n", 649 printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
650 dev->dev.of_node->full_name); 650 dev->dev.of_node->full_name);
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index c449dbd1c938..97118dc3d285 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -253,6 +253,7 @@ struct platform_diu_data_ops diu_ops;
253EXPORT_SYMBOL(diu_ops); 253EXPORT_SYMBOL(diu_ops);
254#endif 254#endif
255 255
256#ifdef CONFIG_EPAPR_PARAVIRT
256/* 257/*
257 * Restart the current partition 258 * Restart the current partition
258 * 259 *
@@ -278,3 +279,4 @@ void fsl_hv_halt(void)
278 pr_info("hv exit\n"); 279 pr_info("hv exit\n");
279 fh_partition_stop(-1); 280 fh_partition_stop(-1);
280} 281}
282#endif
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 9c6e535daad2..3b2efd41abf2 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1864,7 +1864,7 @@ int __init smp_mpic_probe(void)
1864 return nr_cpus; 1864 return nr_cpus;
1865} 1865}
1866 1866
1867void __devinit smp_mpic_setup_cpu(int cpu) 1867void smp_mpic_setup_cpu(int cpu)
1868{ 1868{
1869 mpic_setup_this_cpu(); 1869 mpic_setup_this_cpu();
1870} 1870}
diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c
index e961f8c4a8f0..c75325865a85 100644
--- a/arch/powerpc/sysdev/mpic_msgr.c
+++ b/arch/powerpc/sysdev/mpic_msgr.c
@@ -160,7 +160,7 @@ static int mpic_msgr_block_number(struct device_node *node)
160 160
161/* The probe function for a single message register block. 161/* The probe function for a single message register block.
162 */ 162 */
163static __devinit int mpic_msgr_probe(struct platform_device *dev) 163static int mpic_msgr_probe(struct platform_device *dev)
164{ 164{
165 void __iomem *msgr_block_addr; 165 void __iomem *msgr_block_addr;
166 int block_number; 166 int block_number;
diff --git a/arch/powerpc/sysdev/mv64x60_pci.c b/arch/powerpc/sysdev/mv64x60_pci.c
index 364b14d4754b..330d56613c5a 100644
--- a/arch/powerpc/sysdev/mv64x60_pci.c
+++ b/arch/powerpc/sysdev/mv64x60_pci.c
@@ -104,7 +104,7 @@ subsys_initcall(mv64x60_sysfs_init);
104 104
105#endif /* CONFIG_SYSFS */ 105#endif /* CONFIG_SYSFS */
106 106
107static void __devinit mv64x60_pci_fixup_early(struct pci_dev *dev) 107static void mv64x60_pci_fixup_early(struct pci_dev *dev)
108{ 108{
109 /* 109 /*
110 * Set the host bridge hdr_type to an invalid value so that 110 * Set the host bridge hdr_type to an invalid value so that
diff --git a/arch/powerpc/sysdev/pmi.c b/arch/powerpc/sysdev/pmi.c
index 8f0465422b1e..5aaf86c03893 100644
--- a/arch/powerpc/sysdev/pmi.c
+++ b/arch/powerpc/sysdev/pmi.c
@@ -214,18 +214,7 @@ static struct platform_driver pmi_of_platform_driver = {
214 .of_match_table = pmi_match, 214 .of_match_table = pmi_match,
215 }, 215 },
216}; 216};
217 217module_platform_driver(pmi_of_platform_driver);
218static int __init pmi_module_init(void)
219{
220 return platform_driver_register(&pmi_of_platform_driver);
221}
222module_init(pmi_module_init);
223
224static void __exit pmi_module_exit(void)
225{
226 platform_driver_unregister(&pmi_of_platform_driver);
227}
228module_exit(pmi_module_exit);
229 218
230int pmi_send_message(pmi_message_t msg) 219int pmi_send_message(pmi_message_t msg)
231{ 220{
diff --git a/arch/powerpc/sysdev/ppc4xx_msi.c b/arch/powerpc/sysdev/ppc4xx_msi.c
index 82c6702dcbab..43948da837a7 100644
--- a/arch/powerpc/sysdev/ppc4xx_msi.c
+++ b/arch/powerpc/sysdev/ppc4xx_msi.c
@@ -220,7 +220,7 @@ static int ppc4xx_of_msi_remove(struct platform_device *dev)
220 return 0; 220 return 0;
221} 221}
222 222
223static int __devinit ppc4xx_msi_probe(struct platform_device *dev) 223static int ppc4xx_msi_probe(struct platform_device *dev)
224{ 224{
225 struct ppc4xx_msi *msi; 225 struct ppc4xx_msi *msi;
226 struct resource res; 226 struct resource res;
diff --git a/arch/powerpc/sysdev/qe_lib/qe.c b/arch/powerpc/sysdev/qe_lib/qe.c
index b04367529729..238a07b97f2c 100644
--- a/arch/powerpc/sysdev/qe_lib/qe.c
+++ b/arch/powerpc/sysdev/qe_lib/qe.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006-2010 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006-2010 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/qe_ic.c b/arch/powerpc/sysdev/qe_lib/qe_ic.c
index 2fba6ef2f95e..b2b87c30e266 100644
--- a/arch/powerpc/sysdev/qe_lib/qe_ic.c
+++ b/arch/powerpc/sysdev/qe_lib/qe_ic.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/powerpc/sysdev/qe_lib/qe_ic.c 2 * arch/powerpc/sysdev/qe_lib/qe_ic.c
3 * 3 *
4 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 4 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
5 * 5 *
6 * Author: Li Yang <leoli@freescale.com> 6 * Author: Li Yang <leoli@freescale.com>
7 * Based on code from Shlomi Gridish <gridish@freescale.com> 7 * Based on code from Shlomi Gridish <gridish@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/qe_ic.h b/arch/powerpc/sysdev/qe_lib/qe_ic.h
index c327872ed35c..efef7ab9b753 100644
--- a/arch/powerpc/sysdev/qe_lib/qe_ic.h
+++ b/arch/powerpc/sysdev/qe_lib/qe_ic.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * QUICC ENGINE Interrupt Controller Header 4 * QUICC ENGINE Interrupt Controller Header
5 * 5 *
6 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 6 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
7 * 7 *
8 * Author: Li Yang <leoli@freescale.com> 8 * Author: Li Yang <leoli@freescale.com>
9 * Based on code from Shlomi Gridish <gridish@freescale.com> 9 * Based on code from Shlomi Gridish <gridish@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/qe_io.c b/arch/powerpc/sysdev/qe_lib/qe_io.c
index fd1a6c3b1721..a88807b3dd57 100644
--- a/arch/powerpc/sysdev/qe_lib/qe_io.c
+++ b/arch/powerpc/sysdev/qe_lib/qe_io.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * QE Parallel I/O ports configuration routines 4 * QE Parallel I/O ports configuration routines
5 * 5 *
6 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved. 6 * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
7 * 7 *
8 * Author: Li Yang <LeoLi@freescale.com> 8 * Author: Li Yang <LeoLi@freescale.com>
9 * Based on code from Shlomi Gridish <gridish@freescale.com> 9 * Based on code from Shlomi Gridish <gridish@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/ucc.c b/arch/powerpc/sysdev/qe_lib/ucc.c
index 04677505f20f..134b07d29435 100644
--- a/arch/powerpc/sysdev/qe_lib/ucc.c
+++ b/arch/powerpc/sysdev/qe_lib/ucc.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * QE UCC API Set - UCC specific routines implementations. 4 * QE UCC API Set - UCC specific routines implementations.
5 * 5 *
6 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 6 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
7 * 7 *
8 * Authors: Shlomi Gridish <gridish@freescale.com> 8 * Authors: Shlomi Gridish <gridish@freescale.com>
9 * Li Yang <leoli@freescale.com> 9 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/ucc_fast.c b/arch/powerpc/sysdev/qe_lib/ucc_fast.c
index fba02440d122..cceb2e366738 100644
--- a/arch/powerpc/sysdev/qe_lib/ucc_fast.c
+++ b/arch/powerpc/sysdev/qe_lib/ucc_fast.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/ucc_slow.c b/arch/powerpc/sysdev/qe_lib/ucc_slow.c
index 524c0ead941d..1c062f48f1ac 100644
--- a/arch/powerpc/sysdev/qe_lib/ucc_slow.c
+++ b/arch/powerpc/sysdev/qe_lib/ucc_slow.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved. 2 * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
3 * 3 *
4 * Authors: Shlomi Gridish <gridish@freescale.com> 4 * Authors: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
diff --git a/arch/powerpc/sysdev/qe_lib/usb.c b/arch/powerpc/sysdev/qe_lib/usb.c
index 9162828f5da7..27f23bd15eb6 100644
--- a/arch/powerpc/sysdev/qe_lib/usb.c
+++ b/arch/powerpc/sysdev/qe_lib/usb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * QE USB routines 2 * QE USB routines
3 * 3 *
4 * Copyright (c) Freescale Semicondutor, Inc. 2006. 4 * Copyright 2006 Freescale Semiconductor, Inc.
5 * Shlomi Gridish <gridish@freescale.com> 5 * Shlomi Gridish <gridish@freescale.com>
6 * Jerry Huang <Chang-Ming.Huang@freescale.com> 6 * Jerry Huang <Chang-Ming.Huang@freescale.com>
7 * Copyright (c) MontaVista Software, Inc. 2008. 7 * Copyright (c) MontaVista Software, Inc. 2008.
diff --git a/arch/powerpc/sysdev/scom.c b/arch/powerpc/sysdev/scom.c
index 702256a1ca11..9193e12df695 100644
--- a/arch/powerpc/sysdev/scom.c
+++ b/arch/powerpc/sysdev/scom.c
@@ -157,7 +157,7 @@ static int scom_debug_init_one(struct dentry *root, struct device_node *dn,
157 ent->map = SCOM_MAP_INVALID; 157 ent->map = SCOM_MAP_INVALID;
158 spin_lock_init(&ent->lock); 158 spin_lock_init(&ent->lock);
159 snprintf(ent->name, 8, "scom%d", i); 159 snprintf(ent->name, 8, "scom%d", i);
160 ent->blob.data = dn->full_name; 160 ent->blob.data = (void*) dn->full_name;
161 ent->blob.size = strlen(dn->full_name); 161 ent->blob.size = strlen(dn->full_name);
162 162
163 dir = debugfs_create_dir(ent->name, root); 163 dir = debugfs_create_dir(ent->name, root);
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index c168c54e3c40..b49fdbd15808 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -6,7 +6,7 @@ GCOV_PROFILE := n
6 6
7ccflags-$(CONFIG_PPC64) := -mno-minimal-toc 7ccflags-$(CONFIG_PPC64) := -mno-minimal-toc
8 8
9obj-y += xmon.o start.o nonstdio.o 9obj-y += xmon.o nonstdio.o
10 10
11ifdef CONFIG_XMON_DISASSEMBLY 11ifdef CONFIG_XMON_DISASSEMBLY
12obj-y += ppc-dis.o ppc-opc.o 12obj-y += ppc-dis.o ppc-opc.o
diff --git a/arch/powerpc/xmon/nonstdio.c b/arch/powerpc/xmon/nonstdio.c
index bfac84fbe780..bce3dcfe5058 100644
--- a/arch/powerpc/xmon/nonstdio.c
+++ b/arch/powerpc/xmon/nonstdio.c
@@ -7,9 +7,23 @@
7 * 2 of the License, or (at your option) any later version. 7 * 2 of the License, or (at your option) any later version.
8 */ 8 */
9#include <linux/string.h> 9#include <linux/string.h>
10#include <asm/udbg.h>
10#include <asm/time.h> 11#include <asm/time.h>
11#include "nonstdio.h" 12#include "nonstdio.h"
12 13
14
15static int xmon_write(const void *ptr, int nb)
16{
17 return udbg_write(ptr, nb);
18}
19
20static int xmon_readchar(void)
21{
22 if (udbg_getc)
23 return udbg_getc();
24 return -1;
25}
26
13int xmon_putchar(int c) 27int xmon_putchar(int c)
14{ 28{
15 char ch = c; 29 char ch = c;
@@ -23,34 +37,7 @@ static char line[256];
23static char *lineptr; 37static char *lineptr;
24static int lineleft; 38static int lineleft;
25 39
26int xmon_expect(const char *str, unsigned long timeout) 40static int xmon_getchar(void)
27{
28 int c;
29 unsigned long t0;
30
31 /* assume 25MHz default timebase if tb_ticks_per_sec not set yet */
32 timeout *= tb_ticks_per_sec? tb_ticks_per_sec: 25000000;
33 t0 = get_tbl();
34 do {
35 lineptr = line;
36 for (;;) {
37 c = xmon_read_poll();
38 if (c == -1) {
39 if (get_tbl() - t0 > timeout)
40 return 0;
41 continue;
42 }
43 if (c == '\n')
44 break;
45 if (c != '\r' && lineptr < &line[sizeof(line) - 1])
46 *lineptr++ = c;
47 }
48 *lineptr = 0;
49 } while (strstr(line, str) == NULL);
50 return 1;
51}
52
53int xmon_getchar(void)
54{ 41{
55 int c; 42 int c;
56 43
@@ -124,13 +111,19 @@ char *xmon_gets(char *str, int nb)
124void xmon_printf(const char *format, ...) 111void xmon_printf(const char *format, ...)
125{ 112{
126 va_list args; 113 va_list args;
127 int n;
128 static char xmon_outbuf[1024]; 114 static char xmon_outbuf[1024];
115 int rc, n;
129 116
130 va_start(args, format); 117 va_start(args, format);
131 n = vsnprintf(xmon_outbuf, sizeof(xmon_outbuf), format, args); 118 n = vsnprintf(xmon_outbuf, sizeof(xmon_outbuf), format, args);
132 va_end(args); 119 va_end(args);
133 xmon_write(xmon_outbuf, n); 120
121 rc = xmon_write(xmon_outbuf, n);
122
123 if (n && rc == 0) {
124 /* No udbg hooks, fallback to printk() - dangerous */
125 printk(xmon_outbuf);
126 }
134} 127}
135 128
136void xmon_puts(const char *str) 129void xmon_puts(const char *str)
diff --git a/arch/powerpc/xmon/nonstdio.h b/arch/powerpc/xmon/nonstdio.h
index 23dd95f4599c..18a51ded4ffd 100644
--- a/arch/powerpc/xmon/nonstdio.h
+++ b/arch/powerpc/xmon/nonstdio.h
@@ -4,12 +4,6 @@
4#define putchar xmon_putchar 4#define putchar xmon_putchar
5 5
6extern int xmon_putchar(int c); 6extern int xmon_putchar(int c);
7extern int xmon_getchar(void);
8extern void xmon_puts(const char *); 7extern void xmon_puts(const char *);
9extern char *xmon_gets(char *, int); 8extern char *xmon_gets(char *, int);
10extern void xmon_printf(const char *, ...); 9extern void xmon_printf(const char *, ...);
11extern void xmon_map_scc(void);
12extern int xmon_expect(const char *str, unsigned long timeout);
13extern int xmon_write(const void *ptr, int nb);
14extern int xmon_readchar(void);
15extern int xmon_read_poll(void);
diff --git a/arch/powerpc/xmon/start.c b/arch/powerpc/xmon/start.c
deleted file mode 100644
index 8864de2af382..000000000000
--- a/arch/powerpc/xmon/start.c
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * Copyright (C) 1996 Paul Mackerras.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9#include <asm/machdep.h>
10#include <asm/udbg.h>
11#include "nonstdio.h"
12
13void xmon_map_scc(void)
14{
15}
16
17int xmon_write(const void *ptr, int nb)
18{
19 return udbg_write(ptr, nb);
20}
21
22int xmon_readchar(void)
23{
24 if (udbg_getc)
25 return udbg_getc();
26 return -1;
27}
28
29int xmon_read_poll(void)
30{
31 if (udbg_getc_poll)
32 return udbg_getc_poll();
33 return -1;
34}
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 3a56a639a92e..1f8d2f10a432 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -52,9 +52,6 @@
52#include "nonstdio.h" 52#include "nonstdio.h"
53#include "dis-asm.h" 53#include "dis-asm.h"
54 54
55#define scanhex xmon_scanhex
56#define skipbl xmon_skipbl
57
58#ifdef CONFIG_SMP 55#ifdef CONFIG_SMP
59static cpumask_t cpus_in_xmon = CPU_MASK_NONE; 56static cpumask_t cpus_in_xmon = CPU_MASK_NONE;
60static unsigned long xmon_taken = 1; 57static unsigned long xmon_taken = 1;
@@ -169,12 +166,8 @@ extern void xmon_leave(void);
169 166
170#ifdef CONFIG_PPC64 167#ifdef CONFIG_PPC64
171#define REG "%.16lx" 168#define REG "%.16lx"
172#define REGS_PER_LINE 4
173#define LAST_VOLATILE 13
174#else 169#else
175#define REG "%.8lx" 170#define REG "%.8lx"
176#define REGS_PER_LINE 8
177#define LAST_VOLATILE 12
178#endif 171#endif
179 172
180#define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3]) 173#define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
@@ -1288,27 +1281,19 @@ static void get_function_bounds(unsigned long pc, unsigned long *startp,
1288 catch_memory_errors = 0; 1281 catch_memory_errors = 0;
1289} 1282}
1290 1283
1291static int xmon_depth_to_print = 64;
1292
1293#define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long)) 1284#define LRSAVE_OFFSET (STACK_FRAME_LR_SAVE * sizeof(unsigned long))
1294#define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long)) 1285#define MARKER_OFFSET (STACK_FRAME_MARKER * sizeof(unsigned long))
1295 1286
1296#ifdef __powerpc64__
1297#define REGS_OFFSET 0x70
1298#else
1299#define REGS_OFFSET 16
1300#endif
1301
1302static void xmon_show_stack(unsigned long sp, unsigned long lr, 1287static void xmon_show_stack(unsigned long sp, unsigned long lr,
1303 unsigned long pc) 1288 unsigned long pc)
1304{ 1289{
1290 int max_to_print = 64;
1305 unsigned long ip; 1291 unsigned long ip;
1306 unsigned long newsp; 1292 unsigned long newsp;
1307 unsigned long marker; 1293 unsigned long marker;
1308 int count = 0;
1309 struct pt_regs regs; 1294 struct pt_regs regs;
1310 1295
1311 do { 1296 while (max_to_print--) {
1312 if (sp < PAGE_OFFSET) { 1297 if (sp < PAGE_OFFSET) {
1313 if (sp != 0) 1298 if (sp != 0)
1314 printf("SP (%lx) is in userspace\n", sp); 1299 printf("SP (%lx) is in userspace\n", sp);
@@ -1362,10 +1347,10 @@ static void xmon_show_stack(unsigned long sp, unsigned long lr,
1362 an exception frame. */ 1347 an exception frame. */
1363 if (mread(sp + MARKER_OFFSET, &marker, sizeof(unsigned long)) 1348 if (mread(sp + MARKER_OFFSET, &marker, sizeof(unsigned long))
1364 && marker == STACK_FRAME_REGS_MARKER) { 1349 && marker == STACK_FRAME_REGS_MARKER) {
1365 if (mread(sp + REGS_OFFSET, &regs, sizeof(regs)) 1350 if (mread(sp + STACK_FRAME_OVERHEAD, &regs, sizeof(regs))
1366 != sizeof(regs)) { 1351 != sizeof(regs)) {
1367 printf("Couldn't read registers at %lx\n", 1352 printf("Couldn't read registers at %lx\n",
1368 sp + REGS_OFFSET); 1353 sp + STACK_FRAME_OVERHEAD);
1369 break; 1354 break;
1370 } 1355 }
1371 printf("--- Exception: %lx %s at ", regs.trap, 1356 printf("--- Exception: %lx %s at ", regs.trap,
@@ -1379,7 +1364,7 @@ static void xmon_show_stack(unsigned long sp, unsigned long lr,
1379 break; 1364 break;
1380 1365
1381 sp = newsp; 1366 sp = newsp;
1382 } while (count++ < xmon_depth_to_print); 1367 }
1383} 1368}
1384 1369
1385static void backtrace(struct pt_regs *excp) 1370static void backtrace(struct pt_regs *excp)
@@ -2943,7 +2928,6 @@ static void xmon_init(int enable)
2943 __debugger_dabr_match = NULL; 2928 __debugger_dabr_match = NULL;
2944 __debugger_fault_handler = NULL; 2929 __debugger_fault_handler = NULL;
2945 } 2930 }
2946 xmon_map_scc();
2947} 2931}
2948 2932
2949#ifdef CONFIG_MAGIC_SYSRQ 2933#ifdef CONFIG_MAGIC_SYSRQ