aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms')
-rw-r--r--arch/powerpc/platforms/52xx/Makefile2
-rw-r--r--arch/powerpc/platforms/52xx/efika-pci.c119
-rw-r--r--arch/powerpc/platforms/52xx/efika-setup.c150
-rw-r--r--arch/powerpc/platforms/52xx/efika.c243
-rw-r--r--arch/powerpc/platforms/52xx/efika.h19
-rw-r--r--arch/powerpc/platforms/52xx/lite5200.c29
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_common.c4
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_pic.c10
-rw-r--r--arch/powerpc/platforms/83xx/Kconfig24
-rw-r--r--arch/powerpc/platforms/83xx/Makefile3
-rw-r--r--arch/powerpc/platforms/83xx/mpc8313_rdb.c99
-rw-r--r--arch/powerpc/platforms/83xx/mpc834x_itx.c2
-rw-r--r--arch/powerpc/platforms/83xx/mpc834x_mds.c (renamed from arch/powerpc/platforms/83xx/mpc834x_sys.c)95
-rw-r--r--arch/powerpc/platforms/83xx/mpc834x_sys.h23
-rw-r--r--arch/powerpc/platforms/83xx/mpc83xx.h18
-rw-r--r--arch/powerpc/platforms/85xx/Kconfig13
-rw-r--r--arch/powerpc/platforms/85xx/Makefile1
-rw-r--r--arch/powerpc/platforms/85xx/mpc8568_mds.c246
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_ads.c7
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_cds.c17
-rw-r--r--arch/powerpc/platforms/Makefile2
-rw-r--r--arch/powerpc/platforms/cell/pmu.c14
-rw-r--r--arch/powerpc/platforms/cell/spu_manage.c102
-rw-r--r--arch/powerpc/platforms/cell/spufs/context.c137
-rw-r--r--arch/powerpc/platforms/cell/spufs/file.c144
-rw-r--r--arch/powerpc/platforms/cell/spufs/run.c16
-rw-r--r--arch/powerpc/platforms/cell/spufs/sched.c386
-rw-r--r--arch/powerpc/platforms/cell/spufs/spufs.h50
-rw-r--r--arch/powerpc/platforms/celleb/htab.c19
-rw-r--r--arch/powerpc/platforms/embedded6xx/linkstation.c12
-rw-r--r--arch/powerpc/platforms/ps3/spu.c42
-rw-r--r--arch/powerpc/platforms/pseries/Makefile1
-rw-r--r--arch/powerpc/platforms/pseries/firmware.h17
-rw-r--r--arch/powerpc/platforms/pseries/kexec.c72
-rw-r--r--arch/powerpc/platforms/pseries/pci.c4
-rw-r--r--arch/powerpc/platforms/pseries/pseries.h36
-rw-r--r--arch/powerpc/platforms/pseries/ras.c2
-rw-r--r--arch/powerpc/platforms/pseries/ras.h9
-rw-r--r--arch/powerpc/platforms/pseries/setup.c60
-rw-r--r--arch/powerpc/platforms/pseries/smp.c1
40 files changed, 1365 insertions, 885 deletions
diff --git a/arch/powerpc/platforms/52xx/Makefile b/arch/powerpc/platforms/52xx/Makefile
index 795b713ec9ee..07cdbcacf156 100644
--- a/arch/powerpc/platforms/52xx/Makefile
+++ b/arch/powerpc/platforms/52xx/Makefile
@@ -6,5 +6,5 @@ obj-y += mpc52xx_pic.o mpc52xx_common.o
6obj-$(CONFIG_PCI) += mpc52xx_pci.o 6obj-$(CONFIG_PCI) += mpc52xx_pci.o
7endif 7endif
8 8
9obj-$(CONFIG_PPC_EFIKA) += efika-setup.o efika-pci.o 9obj-$(CONFIG_PPC_EFIKA) += efika.o
10obj-$(CONFIG_PPC_LITE5200) += lite5200.o 10obj-$(CONFIG_PPC_LITE5200) += lite5200.o
diff --git a/arch/powerpc/platforms/52xx/efika-pci.c b/arch/powerpc/platforms/52xx/efika-pci.c
deleted file mode 100644
index 62e05b2a9227..000000000000
--- a/arch/powerpc/platforms/52xx/efika-pci.c
+++ /dev/null
@@ -1,119 +0,0 @@
1
2#include <linux/kernel.h>
3#include <linux/pci.h>
4#include <linux/string.h>
5#include <linux/init.h>
6
7#include <asm/io.h>
8#include <asm/irq.h>
9#include <asm/prom.h>
10#include <asm/machdep.h>
11#include <asm/sections.h>
12#include <asm/pci-bridge.h>
13#include <asm/rtas.h>
14
15#include "efika.h"
16
17#ifdef CONFIG_PCI
18/*
19 * Access functions for PCI config space using RTAS calls.
20 */
21static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
22 int len, u32 * val)
23{
24 struct pci_controller *hose = bus->sysdata;
25 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
26 | (((bus->number - hose->first_busno) & 0xff) << 16)
27 | (hose->index << 24);
28 int ret = -1;
29 int rval;
30
31 rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
32 *val = ret;
33 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
34}
35
36static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,
37 int offset, int len, u32 val)
38{
39 struct pci_controller *hose = bus->sysdata;
40 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
41 | (((bus->number - hose->first_busno) & 0xff) << 16)
42 | (hose->index << 24);
43 int rval;
44
45 rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
46 addr, len, val);
47 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
48}
49
50static struct pci_ops rtas_pci_ops = {
51 rtas_read_config,
52 rtas_write_config
53};
54
55void __init efika_pcisetup(void)
56{
57 const int *bus_range;
58 int len;
59 struct pci_controller *hose;
60 struct device_node *root;
61 struct device_node *pcictrl;
62
63 root = of_find_node_by_path("/");
64 if (root == NULL) {
65 printk(KERN_WARNING EFIKA_PLATFORM_NAME
66 ": Unable to find the root node\n");
67 return;
68 }
69
70 for (pcictrl = NULL;;) {
71 pcictrl = of_get_next_child(root, pcictrl);
72 if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))
73 break;
74 }
75
76 of_node_put(root);
77
78 if (pcictrl == NULL) {
79 printk(KERN_WARNING EFIKA_PLATFORM_NAME
80 ": Unable to find the PCI bridge node\n");
81 return;
82 }
83
84 bus_range = get_property(pcictrl, "bus-range", &len);
85 if (bus_range == NULL || len < 2 * sizeof(int)) {
86 printk(KERN_WARNING EFIKA_PLATFORM_NAME
87 ": Can't get bus-range for %s\n", pcictrl->full_name);
88 return;
89 }
90
91 if (bus_range[1] == bus_range[0])
92 printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
93 bus_range[0]);
94 else
95 printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
96 bus_range[0], bus_range[1]);
97 printk(" controlled by %s\n", pcictrl->full_name);
98 printk("\n");
99
100 hose = pcibios_alloc_controller();
101 if (!hose) {
102 printk(KERN_WARNING EFIKA_PLATFORM_NAME
103 ": Can't allocate PCI controller structure for %s\n",
104 pcictrl->full_name);
105 return;
106 }
107
108 hose->arch_data = of_node_get(pcictrl);
109 hose->first_busno = bus_range[0];
110 hose->last_busno = bus_range[1];
111 hose->ops = &rtas_pci_ops;
112
113 pci_process_bridge_OF_ranges(hose, pcictrl, 0);
114}
115
116#else
117void __init efika_pcisetup(void)
118{}
119#endif
diff --git a/arch/powerpc/platforms/52xx/efika-setup.c b/arch/powerpc/platforms/52xx/efika-setup.c
deleted file mode 100644
index 110c980ed1e0..000000000000
--- a/arch/powerpc/platforms/52xx/efika-setup.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/*
2 *
3 * Efika 5K2 platform setup
4 * Some code really inspired from the lite5200b platform.
5 *
6 * Copyright (C) 2006 bplan GmbH
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 *
12 */
13
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/reboot.h>
18#include <linux/init.h>
19#include <linux/utsrelease.h>
20#include <linux/seq_file.h>
21#include <linux/root_dev.h>
22#include <linux/initrd.h>
23#include <linux/timer.h>
24#include <linux/pci.h>
25
26#include <asm/pgtable.h>
27#include <asm/prom.h>
28#include <asm/time.h>
29#include <asm/machdep.h>
30#include <asm/rtas.h>
31#include <asm/of_device.h>
32#include <asm/of_platform.h>
33#include <asm/mpc52xx.h>
34
35#include "efika.h"
36
37static void efika_show_cpuinfo(struct seq_file *m)
38{
39 struct device_node *root;
40 const char *revision = NULL;
41 const char *codegendescription = NULL;
42 const char *codegenvendor = NULL;
43
44 root = of_find_node_by_path("/");
45 if (root) {
46 revision = get_property(root, "revision", NULL);
47 codegendescription =
48 get_property(root, "CODEGEN,description", NULL);
49 codegenvendor = get_property(root, "CODEGEN,vendor", NULL);
50
51 of_node_put(root);
52 }
53
54 if (codegendescription)
55 seq_printf(m, "machine\t\t: %s\n", codegendescription);
56 else
57 seq_printf(m, "machine\t\t: Efika\n");
58
59 if (revision)
60 seq_printf(m, "revision\t: %s\n", revision);
61
62 if (codegenvendor)
63 seq_printf(m, "vendor\t\t: %s\n", codegenvendor);
64
65 of_node_put(root);
66}
67
68static void __init efika_setup_arch(void)
69{
70 rtas_initialize();
71
72#ifdef CONFIG_BLK_DEV_INITRD
73 initrd_below_start_ok = 1;
74
75 if (initrd_start)
76 ROOT_DEV = Root_RAM0;
77 else
78#endif
79 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
80
81 efika_pcisetup();
82
83 if (ppc_md.progress)
84 ppc_md.progress("Linux/PPC " UTS_RELEASE " runnung on Efika ;-)\n", 0x0);
85}
86
87static void __init efika_init(void)
88{
89 struct device_node *np;
90 struct device_node *cnp = NULL;
91 const u32 *base;
92
93 /* Find every child of the SOC node and add it to of_platform */
94 np = of_find_node_by_name(NULL, "builtin");
95 if (np) {
96 char name[BUS_ID_SIZE];
97 while ((cnp = of_get_next_child(np, cnp))) {
98 strcpy(name, cnp->name);
99
100 base = get_property(cnp, "reg", NULL);
101 if (base == NULL)
102 continue;
103
104 snprintf(name+strlen(name), BUS_ID_SIZE, "@%x", *base);
105 of_platform_device_create(cnp, name, NULL);
106
107 printk(KERN_INFO EFIKA_PLATFORM_NAME" : Added %s (type '%s' at '%s') to the known devices\n", name, cnp->type, cnp->full_name);
108 }
109 }
110
111 if (ppc_md.progress)
112 ppc_md.progress(" Have fun with your Efika! ", 0x7777);
113}
114
115static int __init efika_probe(void)
116{
117 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
118 "model", NULL);
119
120 if (model == NULL)
121 return 0;
122 if (strcmp(model, "EFIKA5K2"))
123 return 0;
124
125 ISA_DMA_THRESHOLD = ~0L;
126 DMA_MODE_READ = 0x44;
127 DMA_MODE_WRITE = 0x48;
128
129 return 1;
130}
131
132define_machine(efika)
133{
134 .name = EFIKA_PLATFORM_NAME,
135 .probe = efika_probe,
136 .setup_arch = efika_setup_arch,
137 .init = efika_init,
138 .show_cpuinfo = efika_show_cpuinfo,
139 .init_IRQ = mpc52xx_init_irq,
140 .get_irq = mpc52xx_get_irq,
141 .restart = rtas_restart,
142 .power_off = rtas_power_off,
143 .halt = rtas_halt,
144 .set_rtc_time = rtas_set_rtc_time,
145 .get_rtc_time = rtas_get_rtc_time,
146 .progress = rtas_progress,
147 .get_boot_time = rtas_get_boot_time,
148 .calibrate_decr = generic_calibrate_decr,
149 .phys_mem_access_prot = pci_phys_mem_access_prot,
150};
diff --git a/arch/powerpc/platforms/52xx/efika.c b/arch/powerpc/platforms/52xx/efika.c
new file mode 100644
index 000000000000..8de034116681
--- /dev/null
+++ b/arch/powerpc/platforms/52xx/efika.c
@@ -0,0 +1,243 @@
1/*
2 * Efika 5K2 platform code
3 * Some code really inspired from the lite5200b platform.
4 *
5 * Copyright (C) 2006 bplan GmbH
6 *
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.
10 */
11
12#include <linux/errno.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/reboot.h>
16#include <linux/init.h>
17#include <linux/utsrelease.h>
18#include <linux/seq_file.h>
19#include <linux/string.h>
20#include <linux/root_dev.h>
21#include <linux/initrd.h>
22#include <linux/timer.h>
23#include <linux/pci.h>
24
25#include <asm/io.h>
26#include <asm/irq.h>
27#include <asm/sections.h>
28#include <asm/pci-bridge.h>
29#include <asm/pgtable.h>
30#include <asm/prom.h>
31#include <asm/time.h>
32#include <asm/machdep.h>
33#include <asm/rtas.h>
34#include <asm/of_device.h>
35#include <asm/of_platform.h>
36#include <asm/mpc52xx.h>
37
38
39#define EFIKA_PLATFORM_NAME "Efika"
40
41
42/* ------------------------------------------------------------------------ */
43/* PCI accesses thru RTAS */
44/* ------------------------------------------------------------------------ */
45
46#ifdef CONFIG_PCI
47
48/*
49 * Access functions for PCI config space using RTAS calls.
50 */
51static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
52 int len, u32 * val)
53{
54 struct pci_controller *hose = bus->sysdata;
55 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
56 | (((bus->number - hose->first_busno) & 0xff) << 16)
57 | (hose->index << 24);
58 int ret = -1;
59 int rval;
60
61 rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
62 *val = ret;
63 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
64}
65
66static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,
67 int offset, int len, u32 val)
68{
69 struct pci_controller *hose = bus->sysdata;
70 unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
71 | (((bus->number - hose->first_busno) & 0xff) << 16)
72 | (hose->index << 24);
73 int rval;
74
75 rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
76 addr, len, val);
77 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
78}
79
80static struct pci_ops rtas_pci_ops = {
81 rtas_read_config,
82 rtas_write_config
83};
84
85
86void __init efika_pcisetup(void)
87{
88 const int *bus_range;
89 int len;
90 struct pci_controller *hose;
91 struct device_node *root;
92 struct device_node *pcictrl;
93
94 root = of_find_node_by_path("/");
95 if (root == NULL) {
96 printk(KERN_WARNING EFIKA_PLATFORM_NAME
97 ": Unable to find the root node\n");
98 return;
99 }
100
101 for (pcictrl = NULL;;) {
102 pcictrl = of_get_next_child(root, pcictrl);
103 if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))
104 break;
105 }
106
107 of_node_put(root);
108
109 if (pcictrl == NULL) {
110 printk(KERN_WARNING EFIKA_PLATFORM_NAME
111 ": Unable to find the PCI bridge node\n");
112 return;
113 }
114
115 bus_range = get_property(pcictrl, "bus-range", &len);
116 if (bus_range == NULL || len < 2 * sizeof(int)) {
117 printk(KERN_WARNING EFIKA_PLATFORM_NAME
118 ": Can't get bus-range for %s\n", pcictrl->full_name);
119 return;
120 }
121
122 if (bus_range[1] == bus_range[0])
123 printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
124 bus_range[0]);
125 else
126 printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
127 bus_range[0], bus_range[1]);
128 printk(" controlled by %s\n", pcictrl->full_name);
129 printk("\n");
130
131 hose = pcibios_alloc_controller();
132 if (!hose) {
133 printk(KERN_WARNING EFIKA_PLATFORM_NAME
134 ": Can't allocate PCI controller structure for %s\n",
135 pcictrl->full_name);
136 return;
137 }
138
139 hose->arch_data = of_node_get(pcictrl);
140 hose->first_busno = bus_range[0];
141 hose->last_busno = bus_range[1];
142 hose->ops = &rtas_pci_ops;
143
144 pci_process_bridge_OF_ranges(hose, pcictrl, 0);
145}
146
147#else
148void __init efika_pcisetup(void)
149{}
150#endif
151
152
153
154/* ------------------------------------------------------------------------ */
155/* Platform setup */
156/* ------------------------------------------------------------------------ */
157
158static void efika_show_cpuinfo(struct seq_file *m)
159{
160 struct device_node *root;
161 const char *revision = NULL;
162 const char *codegendescription = NULL;
163 const char *codegenvendor = NULL;
164
165 root = of_find_node_by_path("/");
166 if (!root)
167 return;
168
169 revision = get_property(root, "revision", NULL);
170 codegendescription =
171 get_property(root, "CODEGEN,description", NULL);
172 codegenvendor = get_property(root, "CODEGEN,vendor", NULL);
173
174 if (codegendescription)
175 seq_printf(m, "machine\t\t: %s\n", codegendescription);
176 else
177 seq_printf(m, "machine\t\t: Efika\n");
178
179 if (revision)
180 seq_printf(m, "revision\t: %s\n", revision);
181
182 if (codegenvendor)
183 seq_printf(m, "vendor\t\t: %s\n", codegenvendor);
184
185 of_node_put(root);
186}
187
188static void __init efika_setup_arch(void)
189{
190 rtas_initialize();
191
192#ifdef CONFIG_BLK_DEV_INITRD
193 initrd_below_start_ok = 1;
194
195 if (initrd_start)
196 ROOT_DEV = Root_RAM0;
197 else
198#endif
199 ROOT_DEV = Root_SDA2; /* sda2 (sda1 is for the kernel) */
200
201 efika_pcisetup();
202
203 if (ppc_md.progress)
204 ppc_md.progress("Linux/PPC " UTS_RELEASE " running on Efika ;-)\n", 0x0);
205}
206
207static int __init efika_probe(void)
208{
209 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
210 "model", NULL);
211
212 if (model == NULL)
213 return 0;
214 if (strcmp(model, "EFIKA5K2"))
215 return 0;
216
217 ISA_DMA_THRESHOLD = ~0L;
218 DMA_MODE_READ = 0x44;
219 DMA_MODE_WRITE = 0x48;
220
221 return 1;
222}
223
224define_machine(efika)
225{
226 .name = EFIKA_PLATFORM_NAME,
227 .probe = efika_probe,
228 .setup_arch = efika_setup_arch,
229 .init = mpc52xx_declare_of_platform_devices,
230 .show_cpuinfo = efika_show_cpuinfo,
231 .init_IRQ = mpc52xx_init_irq,
232 .get_irq = mpc52xx_get_irq,
233 .restart = rtas_restart,
234 .power_off = rtas_power_off,
235 .halt = rtas_halt,
236 .set_rtc_time = rtas_set_rtc_time,
237 .get_rtc_time = rtas_get_rtc_time,
238 .progress = rtas_progress,
239 .get_boot_time = rtas_get_boot_time,
240 .calibrate_decr = generic_calibrate_decr,
241 .phys_mem_access_prot = pci_phys_mem_access_prot,
242};
243
diff --git a/arch/powerpc/platforms/52xx/efika.h b/arch/powerpc/platforms/52xx/efika.h
deleted file mode 100644
index 2f060fd097d7..000000000000
--- a/arch/powerpc/platforms/52xx/efika.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Efika 5K2 platform setup - Header file
3 *
4 * Copyright (C) 2006 bplan GmbH
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 *
10 */
11
12#ifndef __ARCH_POWERPC_EFIKA__
13#define __ARCH_POWERPC_EFIKA__
14
15#define EFIKA_PLATFORM_NAME "Efika"
16
17extern void __init efika_pcisetup(void);
18
19#endif
diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c
index cdb16bfa6ca6..cc3b40de21dd 100644
--- a/arch/powerpc/platforms/52xx/lite5200.c
+++ b/arch/powerpc/platforms/52xx/lite5200.c
@@ -51,13 +51,13 @@
51 */ 51 */
52 52
53static void __init 53static void __init
54lite52xx_setup_cpu(void) 54lite5200_setup_cpu(void)
55{ 55{
56 struct mpc52xx_gpio __iomem *gpio; 56 struct mpc52xx_gpio __iomem *gpio;
57 u32 port_config; 57 u32 port_config;
58 58
59 /* Map zones */ 59 /* Map zones */
60 gpio = mpc52xx_find_and_map("mpc52xx-gpio"); 60 gpio = mpc52xx_find_and_map("mpc5200-gpio");
61 if (!gpio) { 61 if (!gpio) {
62 printk(KERN_ERR __FILE__ ": " 62 printk(KERN_ERR __FILE__ ": "
63 "Error while mapping GPIO register for port config. " 63 "Error while mapping GPIO register for port config. "
@@ -85,12 +85,12 @@ error:
85 iounmap(gpio); 85 iounmap(gpio);
86} 86}
87 87
88static void __init lite52xx_setup_arch(void) 88static void __init lite5200_setup_arch(void)
89{ 89{
90 struct device_node *np; 90 struct device_node *np;
91 91
92 if (ppc_md.progress) 92 if (ppc_md.progress)
93 ppc_md.progress("lite52xx_setup_arch()", 0); 93 ppc_md.progress("lite5200_setup_arch()", 0);
94 94
95 np = of_find_node_by_type(NULL, "cpu"); 95 np = of_find_node_by_type(NULL, "cpu");
96 if (np) { 96 if (np) {
@@ -105,7 +105,7 @@ static void __init lite52xx_setup_arch(void)
105 105
106 /* CPU & Port mux setup */ 106 /* CPU & Port mux setup */
107 mpc52xx_setup_cpu(); /* Generic */ 107 mpc52xx_setup_cpu(); /* Generic */
108 lite52xx_setup_cpu(); /* Platorm specific */ 108 lite5200_setup_cpu(); /* Platorm specific */
109 109
110#ifdef CONFIG_PCI 110#ifdef CONFIG_PCI
111 np = of_find_node_by_type(np, "pci"); 111 np = of_find_node_by_type(np, "pci");
@@ -126,7 +126,7 @@ static void __init lite52xx_setup_arch(void)
126 126
127} 127}
128 128
129void lite52xx_show_cpuinfo(struct seq_file *m) 129void lite5200_show_cpuinfo(struct seq_file *m)
130{ 130{
131 struct device_node* np = of_find_all_nodes(NULL); 131 struct device_node* np = of_find_all_nodes(NULL);
132 const char *model = NULL; 132 const char *model = NULL;
@@ -143,25 +143,26 @@ void lite52xx_show_cpuinfo(struct seq_file *m)
143/* 143/*
144 * Called very early, MMU is off, device-tree isn't unflattened 144 * Called very early, MMU is off, device-tree isn't unflattened
145 */ 145 */
146static int __init lite52xx_probe(void) 146static int __init lite5200_probe(void)
147{ 147{
148 unsigned long node = of_get_flat_dt_root(); 148 unsigned long node = of_get_flat_dt_root();
149 const char *model = of_get_flat_dt_prop(node, "model", NULL); 149 const char *model = of_get_flat_dt_prop(node, "model", NULL);
150 150
151 if (!of_flat_dt_is_compatible(node, "lite52xx")) 151 if (!of_flat_dt_is_compatible(node, "fsl,lite5200") &&
152 !of_flat_dt_is_compatible(node, "fsl,lite5200b"))
152 return 0; 153 return 0;
153 pr_debug("%s board w/ mpc52xx found\n", model ? model : "unknown"); 154 pr_debug("%s board found\n", model ? model : "unknown");
154 155
155 return 1; 156 return 1;
156} 157}
157 158
158define_machine(lite52xx) { 159define_machine(lite5200) {
159 .name = "lite52xx", 160 .name = "lite5200",
160 .probe = lite52xx_probe, 161 .probe = lite5200_probe,
161 .setup_arch = lite52xx_setup_arch, 162 .setup_arch = lite5200_setup_arch,
162 .init = mpc52xx_declare_of_platform_devices, 163 .init = mpc52xx_declare_of_platform_devices,
163 .init_IRQ = mpc52xx_init_irq, 164 .init_IRQ = mpc52xx_init_irq,
164 .get_irq = mpc52xx_get_irq, 165 .get_irq = mpc52xx_get_irq,
165 .show_cpuinfo = lite52xx_show_cpuinfo, 166 .show_cpuinfo = lite5200_show_cpuinfo,
166 .calibrate_decr = generic_calibrate_decr, 167 .calibrate_decr = generic_calibrate_decr,
167}; 168};
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_common.c b/arch/powerpc/platforms/52xx/mpc52xx_common.c
index cc40889074bd..ed0cb694aea8 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_common.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_common.c
@@ -83,8 +83,8 @@ mpc52xx_setup_cpu(void)
83 struct mpc52xx_xlb __iomem *xlb; 83 struct mpc52xx_xlb __iomem *xlb;
84 84
85 /* Map zones */ 85 /* Map zones */
86 cdm = mpc52xx_find_and_map("mpc52xx-cdm"); 86 cdm = mpc52xx_find_and_map("mpc5200-cdm");
87 xlb = mpc52xx_find_and_map("mpc52xx-xlb"); 87 xlb = mpc52xx_find_and_map("mpc5200-xlb");
88 88
89 if (!cdm || !xlb) { 89 if (!cdm || !xlb) {
90 printk(KERN_ERR __FILE__ ": " 90 printk(KERN_ERR __FILE__ ": "
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pic.c b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
index cd91a6c3aafa..c75192567e55 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_pic.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
@@ -383,16 +383,16 @@ void __init mpc52xx_init_irq(void)
383 struct device_node *picnode; 383 struct device_node *picnode;
384 384
385 /* Remap the necessary zones */ 385 /* Remap the necessary zones */
386 picnode = of_find_compatible_node(NULL, NULL, "mpc52xx-pic"); 386 picnode = of_find_compatible_node(NULL, NULL, "mpc5200-pic");
387 387
388 intr = mpc52xx_find_and_map("mpc52xx-pic"); 388 intr = mpc52xx_find_and_map("mpc5200-pic");
389 if (!intr) 389 if (!intr)
390 panic(__FILE__ ": find_and_map failed on 'mpc52xx-pic'. " 390 panic(__FILE__ ": find_and_map failed on 'mpc5200-pic'. "
391 "Check node !"); 391 "Check node !");
392 392
393 sdma = mpc52xx_find_and_map("mpc52xx-bestcomm"); 393 sdma = mpc52xx_find_and_map("mpc5200-bestcomm");
394 if (!sdma) 394 if (!sdma)
395 panic(__FILE__ ": find_and_map failed on 'mpc52xx-bestcomm'. " 395 panic(__FILE__ ": find_and_map failed on 'mpc5200-bestcomm'. "
396 "Check node !"); 396 "Check node !");
397 397
398 /* Disable all interrupt sources. */ 398 /* Disable all interrupt sources. */
diff --git a/arch/powerpc/platforms/83xx/Kconfig b/arch/powerpc/platforms/83xx/Kconfig
index edcd5b875b66..1aea1e69ff31 100644
--- a/arch/powerpc/platforms/83xx/Kconfig
+++ b/arch/powerpc/platforms/83xx/Kconfig
@@ -3,7 +3,13 @@ menu "Platform support"
3 3
4choice 4choice
5 prompt "Machine Type" 5 prompt "Machine Type"
6 default MPC834x_SYS 6 default MPC834x_MDS
7
8config MPC8313_RDB
9 bool "Freescale MPC8313 RDB"
10 select DEFAULT_UIMAGE
11 help
12 This option enables support for the MPC8313 RDB board.
7 13
8config MPC832x_MDS 14config MPC832x_MDS
9 bool "Freescale MPC832x MDS" 15 bool "Freescale MPC832x MDS"
@@ -12,13 +18,13 @@ config MPC832x_MDS
12 help 18 help
13 This option enables support for the MPC832x MDS evaluation board. 19 This option enables support for the MPC832x MDS evaluation board.
14 20
15config MPC834x_SYS 21config MPC834x_MDS
16 bool "Freescale MPC834x SYS" 22 bool "Freescale MPC834x MDS"
17 select DEFAULT_UIMAGE 23 select DEFAULT_UIMAGE
18 help 24 help
19 This option enables support for the MPC 834x SYS evaluation board. 25 This option enables support for the MPC 834x MDS evaluation board.
20 26
21 Be aware that PCI buses can only function when SYS board is plugged 27 Be aware that PCI buses can only function when MDS board is plugged
22 into the PIB (Platform IO Board) board from Freescale which provide 28 into the PIB (Platform IO Board) board from Freescale which provide
23 3 PCI slots. The PIBs PCI initialization is the bootloader's 29 3 PCI slots. The PIBs PCI initialization is the bootloader's
24 responsibility. 30 responsibility.
@@ -41,6 +47,12 @@ config MPC8360E_PB
41 47
42endchoice 48endchoice
43 49
50config PPC_MPC831x
51 bool
52 select PPC_UDBG_16550
53 select PPC_INDIRECT_PCI
54 default y if MPC8313_RDB
55
44config PPC_MPC832x 56config PPC_MPC832x
45 bool 57 bool
46 select PPC_UDBG_16550 58 select PPC_UDBG_16550
@@ -51,7 +63,7 @@ config MPC834x
51 bool 63 bool
52 select PPC_UDBG_16550 64 select PPC_UDBG_16550
53 select PPC_INDIRECT_PCI 65 select PPC_INDIRECT_PCI
54 default y if MPC834x_SYS || MPC834x_ITX 66 default y if MPC834x_MDS || MPC834x_ITX
55 67
56config PPC_MPC836x 68config PPC_MPC836x
57 bool 69 bool
diff --git a/arch/powerpc/platforms/83xx/Makefile b/arch/powerpc/platforms/83xx/Makefile
index f1aa7e24a938..6c8199c4c382 100644
--- a/arch/powerpc/platforms/83xx/Makefile
+++ b/arch/powerpc/platforms/83xx/Makefile
@@ -3,7 +3,8 @@
3# 3#
4obj-y := misc.o 4obj-y := misc.o
5obj-$(CONFIG_PCI) += pci.o 5obj-$(CONFIG_PCI) += pci.o
6obj-$(CONFIG_MPC834x_SYS) += mpc834x_sys.o 6obj-$(CONFIG_MPC8313_RDB) += mpc8313_rdb.o
7obj-$(CONFIG_MPC834x_MDS) += mpc834x_mds.o
7obj-$(CONFIG_MPC834x_ITX) += mpc834x_itx.o 8obj-$(CONFIG_MPC834x_ITX) += mpc834x_itx.o
8obj-$(CONFIG_MPC8360E_PB) += mpc8360e_pb.o 9obj-$(CONFIG_MPC8360E_PB) += mpc8360e_pb.o
9obj-$(CONFIG_MPC832x_MDS) += mpc832x_mds.o 10obj-$(CONFIG_MPC832x_MDS) += mpc832x_mds.o
diff --git a/arch/powerpc/platforms/83xx/mpc8313_rdb.c b/arch/powerpc/platforms/83xx/mpc8313_rdb.c
new file mode 100644
index 000000000000..c3b98c34eb6b
--- /dev/null
+++ b/arch/powerpc/platforms/83xx/mpc8313_rdb.c
@@ -0,0 +1,99 @@
1/*
2 * arch/powerpc/platforms/83xx/mpc8313_rdb.c
3 *
4 * Description: MPC8313x RDB board specific routines.
5 * This file is based on mpc834x_sys.c
6 * Author: Lo Wlison <r43300@freescale.com>
7 *
8 * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16#include <linux/pci.h>
17
18#include <asm/time.h>
19#include <asm/ipic.h>
20#include <asm/udbg.h>
21
22#include "mpc83xx.h"
23
24#undef DEBUG
25#ifdef DEBUG
26#define DBG(fmt...) udbg_printf(fmt)
27#else
28#define DBG(fmt...)
29#endif
30
31#ifndef CONFIG_PCI
32unsigned long isa_io_base = 0;
33unsigned long isa_mem_base = 0;
34#endif
35
36/* ************************************************************************
37 *
38 * Setup the architecture
39 *
40 */
41static void __init mpc8313_rdb_setup_arch(void)
42{
43 struct device_node *np;
44
45 if (ppc_md.progress)
46 ppc_md.progress("mpc8313_rdb_setup_arch()", 0);
47
48#ifdef CONFIG_PCI
49 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
50 add_bridge(np);
51
52 ppc_md.pci_exclude_device = mpc83xx_exclude_device;
53#endif
54}
55
56void __init mpc8313_rdb_init_IRQ(void)
57{
58 struct device_node *np;
59
60 np = of_find_node_by_type(NULL, "ipic");
61 if (!np)
62 return;
63
64 ipic_init(np, 0);
65
66 /* Initialize the default interrupt mapping priorities,
67 * in case the boot rom changed something on us.
68 */
69 ipic_set_default_priority();
70}
71
72/*
73 * Called very early, MMU is off, device-tree isn't unflattened
74 */
75static int __init mpc8313_rdb_probe(void)
76{
77 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
78 "model", NULL);
79 if (model == NULL)
80 return 0;
81 if (strcmp(model, "MPC8313ERDB"))
82 return 0;
83
84 DBG("MPC8313 RDB found\n");
85
86 return 1;
87}
88
89define_machine(mpc8313_rdb) {
90 .name = "MPC8313 RDB",
91 .probe = mpc8313_rdb_probe,
92 .setup_arch = mpc8313_rdb_setup_arch,
93 .init_IRQ = mpc8313_rdb_init_IRQ,
94 .get_irq = ipic_get_irq,
95 .restart = mpc83xx_restart,
96 .time_init = mpc83xx_time_init,
97 .calibrate_decr = generic_calibrate_decr,
98 .progress = udbg_progress,
99};
diff --git a/arch/powerpc/platforms/83xx/mpc834x_itx.c b/arch/powerpc/platforms/83xx/mpc834x_itx.c
index 2446dea9407e..443a3172f370 100644
--- a/arch/powerpc/platforms/83xx/mpc834x_itx.c
+++ b/arch/powerpc/platforms/83xx/mpc834x_itx.c
@@ -38,8 +38,6 @@
38 38
39#include "mpc83xx.h" 39#include "mpc83xx.h"
40 40
41#include <platforms/83xx/mpc834x_sys.h>
42
43#ifndef CONFIG_PCI 41#ifndef CONFIG_PCI
44unsigned long isa_io_base = 0; 42unsigned long isa_io_base = 0;
45unsigned long isa_mem_base = 0; 43unsigned long isa_mem_base = 0;
diff --git a/arch/powerpc/platforms/83xx/mpc834x_sys.c b/arch/powerpc/platforms/83xx/mpc834x_mds.c
index f30393f0b832..d2736da76c46 100644
--- a/arch/powerpc/platforms/83xx/mpc834x_sys.c
+++ b/arch/powerpc/platforms/83xx/mpc834x_mds.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/powerpc/platforms/83xx/mpc834x_sys.c 2 * arch/powerpc/platforms/83xx/mpc834x_mds.c
3 * 3 *
4 * MPC834x SYS board specific routines 4 * MPC834x MDS board specific routines
5 * 5 *
6 * Maintainer: Kumar Gala <galak@kernel.crashing.org> 6 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
7 * 7 *
@@ -43,17 +43,87 @@ unsigned long isa_io_base = 0;
43unsigned long isa_mem_base = 0; 43unsigned long isa_mem_base = 0;
44#endif 44#endif
45 45
46#define BCSR5_INT_USB 0x02
47/* Note: This is only for PB, not for PB+PIB
48 * On PB only port0 is connected using ULPI */
49static int mpc834x_usb_cfg(void)
50{
51 unsigned long sccr, sicrl;
52 void __iomem *immap;
53 void __iomem *bcsr_regs = NULL;
54 u8 bcsr5;
55 struct device_node *np = NULL;
56 int port0_is_dr = 0;
57
58 if ((np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL)
59 port0_is_dr = 1;
60 if ((np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL){
61 if (port0_is_dr) {
62 printk(KERN_WARNING
63 "There is only one USB port on PB board! \n");
64 return -1;
65 } else if (!port0_is_dr)
66 /* No usb port enabled */
67 return -1;
68 }
69
70 immap = ioremap(get_immrbase(), 0x1000);
71 if (!immap)
72 return -1;
73
74 /* Configure clock */
75 sccr = in_be32(immap + MPC83XX_SCCR_OFFS);
76 if (port0_is_dr)
77 sccr |= MPC83XX_SCCR_USB_DRCM_11; /* 1:3 */
78 else
79 sccr |= MPC83XX_SCCR_USB_MPHCM_11; /* 1:3 */
80 out_be32(immap + MPC83XX_SCCR_OFFS, sccr);
81
82 /* Configure Pin */
83 sicrl = in_be32(immap + MPC83XX_SICRL_OFFS);
84 /* set port0 only */
85 if (port0_is_dr)
86 sicrl |= MPC83XX_SICRL_USB0;
87 else
88 sicrl &= ~(MPC83XX_SICRL_USB0);
89 out_be32(immap + MPC83XX_SICRL_OFFS, sicrl);
90
91 iounmap(immap);
92
93 /* Map BCSR area */
94 np = of_find_node_by_name(NULL, "bcsr");
95 if (np != 0) {
96 struct resource res;
97
98 of_address_to_resource(np, 0, &res);
99 bcsr_regs = ioremap(res.start, res.end - res.start + 1);
100 of_node_put(np);
101 }
102 if (!bcsr_regs)
103 return -1;
104
105 /*
106 * if MDS board is plug into PIB board,
107 * force to use the PHY on MDS board
108 */
109 bcsr5 = in_8(bcsr_regs + 5);
110 if (!(bcsr5 & BCSR5_INT_USB))
111 out_8(bcsr_regs + 5, (bcsr5 | BCSR5_INT_USB));
112 iounmap(bcsr_regs);
113 return 0;
114}
115
46/* ************************************************************************ 116/* ************************************************************************
47 * 117 *
48 * Setup the architecture 118 * Setup the architecture
49 * 119 *
50 */ 120 */
51static void __init mpc834x_sys_setup_arch(void) 121static void __init mpc834x_mds_setup_arch(void)
52{ 122{
53 struct device_node *np; 123 struct device_node *np;
54 124
55 if (ppc_md.progress) 125 if (ppc_md.progress)
56 ppc_md.progress("mpc834x_sys_setup_arch()", 0); 126 ppc_md.progress("mpc834x_mds_setup_arch()", 0);
57 127
58 np = of_find_node_by_type(NULL, "cpu"); 128 np = of_find_node_by_type(NULL, "cpu");
59 if (np != 0) { 129 if (np != 0) {
@@ -65,6 +135,7 @@ static void __init mpc834x_sys_setup_arch(void)
65 loops_per_jiffy = 50000000 / HZ; 135 loops_per_jiffy = 50000000 / HZ;
66 of_node_put(np); 136 of_node_put(np);
67 } 137 }
138
68#ifdef CONFIG_PCI 139#ifdef CONFIG_PCI
69 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;) 140 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
70 add_bridge(np); 141 add_bridge(np);
@@ -72,6 +143,8 @@ static void __init mpc834x_sys_setup_arch(void)
72 ppc_md.pci_exclude_device = mpc83xx_exclude_device; 143 ppc_md.pci_exclude_device = mpc83xx_exclude_device;
73#endif 144#endif
74 145
146 mpc834x_usb_cfg();
147
75#ifdef CONFIG_ROOT_NFS 148#ifdef CONFIG_ROOT_NFS
76 ROOT_DEV = Root_NFS; 149 ROOT_DEV = Root_NFS;
77#else 150#else
@@ -79,7 +152,7 @@ static void __init mpc834x_sys_setup_arch(void)
79#endif 152#endif
80} 153}
81 154
82static void __init mpc834x_sys_init_IRQ(void) 155static void __init mpc834x_mds_init_IRQ(void)
83{ 156{
84 struct device_node *np; 157 struct device_node *np;
85 158
@@ -119,7 +192,7 @@ late_initcall(mpc834x_rtc_hookup);
119/* 192/*
120 * Called very early, MMU is off, device-tree isn't unflattened 193 * Called very early, MMU is off, device-tree isn't unflattened
121 */ 194 */
122static int __init mpc834x_sys_probe(void) 195static int __init mpc834x_mds_probe(void)
123{ 196{
124 /* We always match for now, eventually we should look at the flat 197 /* We always match for now, eventually we should look at the flat
125 dev tree to ensure this is the board we are suppose to run on 198 dev tree to ensure this is the board we are suppose to run on
@@ -127,11 +200,11 @@ static int __init mpc834x_sys_probe(void)
127 return 1; 200 return 1;
128} 201}
129 202
130define_machine(mpc834x_sys) { 203define_machine(mpc834x_mds) {
131 .name = "MPC834x SYS", 204 .name = "MPC834x MDS",
132 .probe = mpc834x_sys_probe, 205 .probe = mpc834x_mds_probe,
133 .setup_arch = mpc834x_sys_setup_arch, 206 .setup_arch = mpc834x_mds_setup_arch,
134 .init_IRQ = mpc834x_sys_init_IRQ, 207 .init_IRQ = mpc834x_mds_init_IRQ,
135 .get_irq = ipic_get_irq, 208 .get_irq = ipic_get_irq,
136 .restart = mpc83xx_restart, 209 .restart = mpc83xx_restart,
137 .time_init = mpc83xx_time_init, 210 .time_init = mpc83xx_time_init,
diff --git a/arch/powerpc/platforms/83xx/mpc834x_sys.h b/arch/powerpc/platforms/83xx/mpc834x_sys.h
deleted file mode 100644
index 7d5bbef084e7..000000000000
--- a/arch/powerpc/platforms/83xx/mpc834x_sys.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/*
2 * arch/powerpc/platforms/83xx/mpc834x_sys.h
3 *
4 * MPC834X SYS common board definitions
5 *
6 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#ifndef __MACH_MPC83XX_SYS_H__
16#define __MACH_MPC83XX_SYS_H__
17
18#define PIRQA MPC83xx_IRQ_EXT4
19#define PIRQB MPC83xx_IRQ_EXT5
20#define PIRQC MPC83xx_IRQ_EXT6
21#define PIRQD MPC83xx_IRQ_EXT7
22
23#endif /* __MACH_MPC83XX_SYS_H__ */
diff --git a/arch/powerpc/platforms/83xx/mpc83xx.h b/arch/powerpc/platforms/83xx/mpc83xx.h
index 01cae106912b..9cd03b59c8f4 100644
--- a/arch/powerpc/platforms/83xx/mpc83xx.h
+++ b/arch/powerpc/platforms/83xx/mpc83xx.h
@@ -4,6 +4,24 @@
4#include <linux/init.h> 4#include <linux/init.h>
5#include <linux/device.h> 5#include <linux/device.h>
6 6
7/* System Clock Control Register */
8#define MPC83XX_SCCR_OFFS 0xA08
9#define MPC83XX_SCCR_USB_MPHCM_11 0x00c00000
10#define MPC83XX_SCCR_USB_MPHCM_01 0x00400000
11#define MPC83XX_SCCR_USB_MPHCM_10 0x00800000
12#define MPC83XX_SCCR_USB_DRCM_11 0x00300000
13#define MPC83XX_SCCR_USB_DRCM_01 0x00100000
14#define MPC83XX_SCCR_USB_DRCM_10 0x00200000
15
16/* system i/o configuration register low */
17#define MPC83XX_SICRL_OFFS 0x114
18#define MPC83XX_SICRL_USB0 0x40000000
19#define MPC83XX_SICRL_USB1 0x20000000
20
21/* system i/o configuration register high */
22#define MPC83XX_SICRH_OFFS 0x118
23#define MPC83XX_SICRH_USB_UTMI 0x00020000
24
7/* 25/*
8 * Declaration for the various functions exported by the 26 * Declaration for the various functions exported by the
9 * mpc83xx_* files. Mostly for use by mpc83xx_setup 27 * mpc83xx_* files. Mostly for use by mpc83xx_setup
diff --git a/arch/powerpc/platforms/85xx/Kconfig b/arch/powerpc/platforms/85xx/Kconfig
index 0584f3c7e884..0efdd2f1babe 100644
--- a/arch/powerpc/platforms/85xx/Kconfig
+++ b/arch/powerpc/platforms/85xx/Kconfig
@@ -23,6 +23,13 @@ config MPC85xx_CDS
23 help 23 help
24 This option enables support for the MPC85xx CDS board 24 This option enables support for the MPC85xx CDS board
25 25
26config MPC8568_MDS
27 bool "Freescale MPC8568 MDS"
28 select DEFAULT_UIMAGE
29# select QUICC_ENGINE
30 help
31 This option enables support for the MPC8568 MDS board
32
26endchoice 33endchoice
27 34
28config MPC8540 35config MPC8540
@@ -36,6 +43,12 @@ config MPC8560
36 select PPC_INDIRECT_PCI 43 select PPC_INDIRECT_PCI
37 default y if MPC8560_ADS 44 default y if MPC8560_ADS
38 45
46config MPC85xx
47 bool
48 select PPC_UDBG_16550
49 select PPC_INDIRECT_PCI
50 default y if MPC8540_ADS || MPC85xx_CDS || MPC8560_ADS || MPC8568_MDS
51
39config PPC_INDIRECT_PCI_BE 52config PPC_INDIRECT_PCI_BE
40 bool 53 bool
41 depends on PPC_85xx 54 depends on PPC_85xx
diff --git a/arch/powerpc/platforms/85xx/Makefile b/arch/powerpc/platforms/85xx/Makefile
index 282f5d0d0152..e40e521816b8 100644
--- a/arch/powerpc/platforms/85xx/Makefile
+++ b/arch/powerpc/platforms/85xx/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_PPC_85xx) += misc.o pci.o
5obj-$(CONFIG_MPC8540_ADS) += mpc85xx_ads.o 5obj-$(CONFIG_MPC8540_ADS) += mpc85xx_ads.o
6obj-$(CONFIG_MPC8560_ADS) += mpc85xx_ads.o 6obj-$(CONFIG_MPC8560_ADS) += mpc85xx_ads.o
7obj-$(CONFIG_MPC85xx_CDS) += mpc85xx_cds.o 7obj-$(CONFIG_MPC85xx_CDS) += mpc85xx_cds.o
8obj-$(CONFIG_MPC8568_MDS) += mpc8568_mds.o
diff --git a/arch/powerpc/platforms/85xx/mpc8568_mds.c b/arch/powerpc/platforms/85xx/mpc8568_mds.c
new file mode 100644
index 000000000000..0861d1107bc8
--- /dev/null
+++ b/arch/powerpc/platforms/85xx/mpc8568_mds.c
@@ -0,0 +1,246 @@
1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006-2007. All rights reserved.
3 *
4 * Author: Andy Fleming <afleming@freescale.com>
5 *
6 * Based on 83xx/mpc8360e_pb.c by:
7 * Li Yang <LeoLi@freescale.com>
8 * Yin Olivia <Hong-hua.Yin@freescale.com>
9 *
10 * Description:
11 * MPC8568E MDS PB board specific routines.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
19#include <linux/stddef.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/errno.h>
23#include <linux/reboot.h>
24#include <linux/pci.h>
25#include <linux/kdev_t.h>
26#include <linux/major.h>
27#include <linux/console.h>
28#include <linux/delay.h>
29#include <linux/seq_file.h>
30#include <linux/root_dev.h>
31#include <linux/initrd.h>
32#include <linux/module.h>
33#include <linux/fsl_devices.h>
34
35#include <asm/of_device.h>
36#include <asm/of_platform.h>
37#include <asm/system.h>
38#include <asm/atomic.h>
39#include <asm/time.h>
40#include <asm/io.h>
41#include <asm/machdep.h>
42#include <asm/bootinfo.h>
43#include <asm/pci-bridge.h>
44#include <asm/mpc85xx.h>
45#include <asm/irq.h>
46#include <mm/mmu_decl.h>
47#include <asm/prom.h>
48#include <asm/udbg.h>
49#include <sysdev/fsl_soc.h>
50#include <asm/qe.h>
51#include <asm/qe_ic.h>
52#include <asm/mpic.h>
53
54#include "mpc85xx.h"
55
56#undef DEBUG
57#ifdef DEBUG
58#define DBG(fmt...) udbg_printf(fmt)
59#else
60#define DBG(fmt...)
61#endif
62
63#ifndef CONFIG_PCI
64unsigned long isa_io_base = 0;
65unsigned long isa_mem_base = 0;
66#endif
67
68/* ************************************************************************
69 *
70 * Setup the architecture
71 *
72 */
73static void __init mpc8568_mds_setup_arch(void)
74{
75 struct device_node *np;
76 static u8 *bcsr_regs = NULL;
77
78
79 if (ppc_md.progress)
80 ppc_md.progress("mpc8568_mds_setup_arch()", 0);
81
82 np = of_find_node_by_type(NULL, "cpu");
83 if (np != NULL) {
84 const unsigned int *fp =
85 get_property(np, "clock-frequency", NULL);
86 if (fp != NULL)
87 loops_per_jiffy = *fp / HZ;
88 else
89 loops_per_jiffy = 50000000 / HZ;
90 of_node_put(np);
91 }
92
93 /* Map BCSR area */
94 np = of_find_node_by_name(NULL, "bcsr");
95 if (np != NULL) {
96 struct resource res;
97
98 of_address_to_resource(np, 0, &res);
99 bcsr_regs = ioremap(res.start, res.end - res.start +1);
100 of_node_put(np);
101 }
102
103#ifdef CONFIG_PCI
104 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;) {
105 add_bridge(np);
106 }
107 of_node_put(np);
108#endif
109
110#ifdef CONFIG_QUICC_ENGINE
111 if ((np = of_find_node_by_name(NULL, "qe")) != NULL) {
112 qe_reset();
113 of_node_put(np);
114 }
115
116 if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {
117 struct device_node *ucc = NULL;
118
119 par_io_init(np);
120 of_node_put(np);
121
122 for ( ;(ucc = of_find_node_by_name(ucc, "ucc")) != NULL;)
123 par_io_of_config(ucc);
124
125 of_node_put(ucc);
126 }
127
128 if (bcsr_regs) {
129 u8 bcsr_phy;
130
131 /* Reset the Ethernet PHY */
132 bcsr_phy = in_be8(&bcsr_regs[9]);
133 bcsr_phy &= ~0x20;
134 out_be8(&bcsr_regs[9], bcsr_phy);
135
136 udelay(1000);
137
138 bcsr_phy = in_be8(&bcsr_regs[9]);
139 bcsr_phy |= 0x20;
140 out_be8(&bcsr_regs[9], bcsr_phy);
141
142 iounmap(bcsr_regs);
143 }
144
145#endif /* CONFIG_QUICC_ENGINE */
146}
147
148static struct of_device_id mpc8568_ids[] = {
149 { .type = "soc", },
150 { .compatible = "soc", },
151 { .type = "qe", },
152 {},
153};
154
155static int __init mpc8568_publish_devices(void)
156{
157 if (!machine_is(mpc8568_mds))
158 return 0;
159
160 /* Publish the QE devices */
161 of_platform_bus_probe(NULL,mpc8568_ids,NULL);
162
163 return 0;
164}
165device_initcall(mpc8568_publish_devices);
166
167static void __init mpc8568_mds_pic_init(void)
168{
169 struct mpic *mpic;
170 struct resource r;
171 struct device_node *np = NULL;
172
173 np = of_find_node_by_type(NULL, "open-pic");
174 if (!np)
175 return;
176
177 if (of_address_to_resource(np, 0, &r)) {
178 printk(KERN_ERR "Failed to map mpic register space\n");
179 of_node_put(np);
180 return;
181 }
182
183 mpic = mpic_alloc(np, r.start,
184 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
185 4, 0, " OpenPIC ");
186 BUG_ON(mpic == NULL);
187 of_node_put(np);
188
189 /* Internal Interrupts */
190 mpic_assign_isu(mpic, 0, r.start + 0x10200);
191 mpic_assign_isu(mpic, 1, r.start + 0x10280);
192 mpic_assign_isu(mpic, 2, r.start + 0x10300);
193 mpic_assign_isu(mpic, 3, r.start + 0x10380);
194 mpic_assign_isu(mpic, 4, r.start + 0x10400);
195 mpic_assign_isu(mpic, 5, r.start + 0x10480);
196 mpic_assign_isu(mpic, 6, r.start + 0x10500);
197 mpic_assign_isu(mpic, 7, r.start + 0x10580);
198 mpic_assign_isu(mpic, 8, r.start + 0x10600);
199 mpic_assign_isu(mpic, 9, r.start + 0x10680);
200 mpic_assign_isu(mpic, 10, r.start + 0x10700);
201 mpic_assign_isu(mpic, 11, r.start + 0x10780);
202
203 /* External Interrupts */
204 mpic_assign_isu(mpic, 12, r.start + 0x10000);
205 mpic_assign_isu(mpic, 13, r.start + 0x10080);
206 mpic_assign_isu(mpic, 14, r.start + 0x10100);
207
208 mpic_init(mpic);
209
210
211#ifdef CONFIG_QUICC_ENGINE
212 np = of_find_node_by_type(NULL, "qeic");
213 if (!np)
214 return;
215
216 qe_ic_init(np, 0);
217 of_node_put(np);
218#endif /* CONFIG_QUICC_ENGINE */
219}
220
221
222static int __init mpc8568_mds_probe(void)
223{
224 char *model = of_get_flat_dt_prop(of_get_flat_dt_root(),
225 "model", NULL);
226 if (model == NULL)
227 return 0;
228 if (strcmp(model, "MPC8568EMDS"))
229 return 0;
230
231 DBG("MPC8568EMDS found\n");
232
233 return 1;
234}
235
236
237define_machine(mpc8568_mds) {
238 .name = "MPC8568E MDS",
239 .probe = mpc8568_mds_probe,
240 .setup_arch = mpc8568_mds_setup_arch,
241 .init_IRQ = mpc8568_mds_pic_init,
242 .get_irq = mpic_get_irq,
243 .restart = mpc85xx_restart,
244 .calibrate_decr = generic_calibrate_decr,
245 .progress = udbg_progress,
246};
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_ads.c b/arch/powerpc/platforms/85xx/mpc85xx_ads.c
index bda2e55e6c4c..c56fce57621c 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_ads.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_ads.c
@@ -45,8 +45,7 @@ unsigned long isa_mem_base = 0;
45#endif 45#endif
46 46
47#ifdef CONFIG_PCI 47#ifdef CONFIG_PCI
48int 48static int mpc85xx_exclude_device(u_char bus, u_char devfn)
49mpc85xx_exclude_device(u_char bus, u_char devfn)
50{ 49{
51 if (bus == 0 && PCI_SLOT(devfn) == 0) 50 if (bus == 0 && PCI_SLOT(devfn) == 0)
52 return PCIBIOS_DEVICE_NOT_FOUND; 51 return PCIBIOS_DEVICE_NOT_FOUND;
@@ -69,7 +68,7 @@ static void cpm2_cascade(unsigned int irq, struct irq_desc *desc)
69 68
70#endif /* CONFIG_CPM2 */ 69#endif /* CONFIG_CPM2 */
71 70
72void __init mpc85xx_ads_pic_init(void) 71static void __init mpc85xx_ads_pic_init(void)
73{ 72{
74 struct mpic *mpic; 73 struct mpic *mpic;
75 struct resource r; 74 struct resource r;
@@ -254,7 +253,7 @@ static void __init mpc85xx_ads_setup_arch(void)
254#endif 253#endif
255} 254}
256 255
257void mpc85xx_ads_show_cpuinfo(struct seq_file *m) 256static void mpc85xx_ads_show_cpuinfo(struct seq_file *m)
258{ 257{
259 uint pvid, svid, phid1; 258 uint pvid, svid, phid1;
260 uint memsize = total_memory; 259 uint memsize = total_memory;
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_cds.c b/arch/powerpc/platforms/85xx/mpc85xx_cds.c
index 953cd5dd3f54..abc0aca6de40 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_cds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_cds.c
@@ -56,7 +56,6 @@ unsigned long isa_mem_base = 0;
56static int cds_pci_slot = 2; 56static int cds_pci_slot = 2;
57static volatile u8 *cadmus; 57static volatile u8 *cadmus;
58 58
59
60#ifdef CONFIG_PCI 59#ifdef CONFIG_PCI
61 60
62#define ARCADIA_HOST_BRIDGE_IDSEL 17 61#define ARCADIA_HOST_BRIDGE_IDSEL 17
@@ -64,8 +63,7 @@ static volatile u8 *cadmus;
64 63
65extern int mpc85xx_pci2_busno; 64extern int mpc85xx_pci2_busno;
66 65
67int 66static int mpc85xx_exclude_device(u_char bus, u_char devfn)
68mpc85xx_exclude_device(u_char bus, u_char devfn)
69{ 67{
70 if (bus == 0 && PCI_SLOT(devfn) == 0) 68 if (bus == 0 && PCI_SLOT(devfn) == 0)
71 return PCIBIOS_DEVICE_NOT_FOUND; 69 return PCIBIOS_DEVICE_NOT_FOUND;
@@ -81,8 +79,7 @@ mpc85xx_exclude_device(u_char bus, u_char devfn)
81 return PCIBIOS_SUCCESSFUL; 79 return PCIBIOS_SUCCESSFUL;
82} 80}
83 81
84void __init 82static void __init mpc85xx_cds_pcibios_fixup(void)
85mpc85xx_cds_pcibios_fixup(void)
86{ 83{
87 struct pci_dev *dev; 84 struct pci_dev *dev;
88 u_char c; 85 u_char c;
@@ -144,7 +141,7 @@ static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
144#endif /* PPC_I8259 */ 141#endif /* PPC_I8259 */
145#endif /* CONFIG_PCI */ 142#endif /* CONFIG_PCI */
146 143
147void __init mpc85xx_cds_pic_init(void) 144static void __init mpc85xx_cds_pic_init(void)
148{ 145{
149 struct mpic *mpic; 146 struct mpic *mpic;
150 struct resource r; 147 struct resource r;
@@ -224,12 +221,10 @@ void __init mpc85xx_cds_pic_init(void)
224#endif /* CONFIG_PPC_I8259 */ 221#endif /* CONFIG_PPC_I8259 */
225} 222}
226 223
227
228/* 224/*
229 * Setup the architecture 225 * Setup the architecture
230 */ 226 */
231static void __init 227static void __init mpc85xx_cds_setup_arch(void)
232mpc85xx_cds_setup_arch(void)
233{ 228{
234 struct device_node *cpu; 229 struct device_node *cpu;
235#ifdef CONFIG_PCI 230#ifdef CONFIG_PCI
@@ -276,9 +271,7 @@ mpc85xx_cds_setup_arch(void)
276#endif 271#endif
277} 272}
278 273
279 274static void mpc85xx_cds_show_cpuinfo(struct seq_file *m)
280void
281mpc85xx_cds_show_cpuinfo(struct seq_file *m)
282{ 275{
283 uint pvid, svid, phid1; 276 uint pvid, svid, phid1;
284 uint memsize = total_memory; 277 uint memsize = total_memory;
diff --git a/arch/powerpc/platforms/Makefile b/arch/powerpc/platforms/Makefile
index 65e612315b9b..452004283f17 100644
--- a/arch/powerpc/platforms/Makefile
+++ b/arch/powerpc/platforms/Makefile
@@ -5,9 +5,9 @@ ifeq ($(CONFIG_PPC64),y)
5obj-$(CONFIG_PPC_PMAC) += powermac/ 5obj-$(CONFIG_PPC_PMAC) += powermac/
6endif 6endif
7endif 7endif
8obj-$(CONFIG_PPC_MPC52xx) += 52xx/
9obj-$(CONFIG_PPC_CHRP) += chrp/ 8obj-$(CONFIG_PPC_CHRP) += chrp/
10obj-$(CONFIG_4xx) += 4xx/ 9obj-$(CONFIG_4xx) += 4xx/
10obj-$(CONFIG_PPC_MPC52xx) += 52xx/
11obj-$(CONFIG_PPC_8xx) += 8xx/ 11obj-$(CONFIG_PPC_8xx) += 8xx/
12obj-$(CONFIG_PPC_82xx) += 82xx/ 12obj-$(CONFIG_PPC_82xx) += 82xx/
13obj-$(CONFIG_PPC_83xx) += 83xx/ 13obj-$(CONFIG_PPC_83xx) += 83xx/
diff --git a/arch/powerpc/platforms/cell/pmu.c b/arch/powerpc/platforms/cell/pmu.c
index d04ae1671e6c..66ca4b5a1dbc 100644
--- a/arch/powerpc/platforms/cell/pmu.c
+++ b/arch/powerpc/platforms/cell/pmu.c
@@ -345,18 +345,12 @@ EXPORT_SYMBOL_GPL(cbe_read_trace_buffer);
345 * Enabling/disabling interrupts for the entire performance monitoring unit. 345 * Enabling/disabling interrupts for the entire performance monitoring unit.
346 */ 346 */
347 347
348u32 cbe_query_pm_interrupts(u32 cpu) 348u32 cbe_get_and_clear_pm_interrupts(u32 cpu)
349{
350 return cbe_read_pm(cpu, pm_status);
351}
352EXPORT_SYMBOL_GPL(cbe_query_pm_interrupts);
353
354u32 cbe_clear_pm_interrupts(u32 cpu)
355{ 349{
356 /* Reading pm_status clears the interrupt bits. */ 350 /* Reading pm_status clears the interrupt bits. */
357 return cbe_query_pm_interrupts(cpu); 351 return cbe_read_pm(cpu, pm_status);
358} 352}
359EXPORT_SYMBOL_GPL(cbe_clear_pm_interrupts); 353EXPORT_SYMBOL_GPL(cbe_get_and_clear_pm_interrupts);
360 354
361void cbe_enable_pm_interrupts(u32 cpu, u32 thread, u32 mask) 355void cbe_enable_pm_interrupts(u32 cpu, u32 thread, u32 mask)
362{ 356{
@@ -371,7 +365,7 @@ EXPORT_SYMBOL_GPL(cbe_enable_pm_interrupts);
371 365
372void cbe_disable_pm_interrupts(u32 cpu) 366void cbe_disable_pm_interrupts(u32 cpu)
373{ 367{
374 cbe_clear_pm_interrupts(cpu); 368 cbe_get_and_clear_pm_interrupts(cpu);
375 cbe_write_pm(cpu, pm_status, 0); 369 cbe_write_pm(cpu, pm_status, 0);
376} 370}
377EXPORT_SYMBOL_GPL(cbe_disable_pm_interrupts); 371EXPORT_SYMBOL_GPL(cbe_disable_pm_interrupts);
diff --git a/arch/powerpc/platforms/cell/spu_manage.c b/arch/powerpc/platforms/cell/spu_manage.c
index d8b39fe39cdd..e34599f53d28 100644
--- a/arch/powerpc/platforms/cell/spu_manage.c
+++ b/arch/powerpc/platforms/cell/spu_manage.c
@@ -59,63 +59,6 @@ static u64 __init find_spu_unit_number(struct device_node *spe)
59 return 0; 59 return 0;
60} 60}
61 61
62static int __init cell_spuprop_present(struct spu *spu, struct device_node *spe,
63 const char *prop)
64{
65 const struct address_prop {
66 unsigned long address;
67 unsigned int len;
68 } __attribute__((packed)) *p;
69 int proplen;
70
71 unsigned long start_pfn, nr_pages;
72 struct pglist_data *pgdata;
73 struct zone *zone;
74 int ret;
75
76 p = get_property(spe, prop, &proplen);
77 WARN_ON(proplen != sizeof (*p));
78
79 start_pfn = p->address >> PAGE_SHIFT;
80 nr_pages = ((unsigned long)p->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
81
82 pgdata = NODE_DATA(spu->node);
83 zone = pgdata->node_zones;
84
85 ret = __add_pages(zone, start_pfn, nr_pages);
86
87 return ret;
88}
89
90static void __iomem * __init map_spe_prop(struct spu *spu,
91 struct device_node *n, const char *name)
92{
93 const struct address_prop {
94 unsigned long address;
95 unsigned int len;
96 } __attribute__((packed)) *prop;
97
98 const void *p;
99 int proplen;
100 void __iomem *ret = NULL;
101 int err = 0;
102
103 p = get_property(n, name, &proplen);
104 if (proplen != sizeof (struct address_prop))
105 return NULL;
106
107 prop = p;
108
109 err = cell_spuprop_present(spu, n, name);
110 if (err && (err != -EEXIST))
111 goto out;
112
113 ret = ioremap(prop->address, prop->len);
114
115 out:
116 return ret;
117}
118
119static void spu_unmap(struct spu *spu) 62static void spu_unmap(struct spu *spu)
120{ 63{
121 if (!firmware_has_feature(FW_FEATURE_LPAR)) 64 if (!firmware_has_feature(FW_FEATURE_LPAR))
@@ -157,6 +100,23 @@ static int __init spu_map_interrupts_old(struct spu *spu,
157 return spu->irqs[2] == NO_IRQ ? -EINVAL : 0; 100 return spu->irqs[2] == NO_IRQ ? -EINVAL : 0;
158} 101}
159 102
103static void __iomem * __init spu_map_prop_old(struct spu *spu,
104 struct device_node *n,
105 const char *name)
106{
107 const struct address_prop {
108 unsigned long address;
109 unsigned int len;
110 } __attribute__((packed)) *prop;
111 int proplen;
112
113 prop = get_property(n, name, &proplen);
114 if (prop == NULL || proplen != sizeof (struct address_prop))
115 return NULL;
116
117 return ioremap(prop->address, prop->len);
118}
119
160static int __init spu_map_device_old(struct spu *spu) 120static int __init spu_map_device_old(struct spu *spu)
161{ 121{
162 struct device_node *node = spu->devnode; 122 struct device_node *node = spu->devnode;
@@ -175,7 +135,7 @@ static int __init spu_map_device_old(struct spu *spu)
175 135
176 /* we use local store as ram, not io memory */ 136 /* we use local store as ram, not io memory */
177 spu->local_store = (void __force *) 137 spu->local_store = (void __force *)
178 map_spe_prop(spu, node, "local-store"); 138 spu_map_prop_old(spu, node, "local-store");
179 if (!spu->local_store) 139 if (!spu->local_store)
180 goto out; 140 goto out;
181 141
@@ -184,16 +144,16 @@ static int __init spu_map_device_old(struct spu *spu)
184 goto out_unmap; 144 goto out_unmap;
185 spu->problem_phys = *(unsigned long *)prop; 145 spu->problem_phys = *(unsigned long *)prop;
186 146
187 spu->problem = map_spe_prop(spu, node, "problem"); 147 spu->problem = spu_map_prop_old(spu, node, "problem");
188 if (!spu->problem) 148 if (!spu->problem)
189 goto out_unmap; 149 goto out_unmap;
190 150
191 spu->priv2 = map_spe_prop(spu, node, "priv2"); 151 spu->priv2 = spu_map_prop_old(spu, node, "priv2");
192 if (!spu->priv2) 152 if (!spu->priv2)
193 goto out_unmap; 153 goto out_unmap;
194 154
195 if (!firmware_has_feature(FW_FEATURE_LPAR)) { 155 if (!firmware_has_feature(FW_FEATURE_LPAR)) {
196 spu->priv1 = map_spe_prop(spu, node, "priv1"); 156 spu->priv1 = spu_map_prop_old(spu, node, "priv1");
197 if (!spu->priv1) 157 if (!spu->priv1)
198 goto out_unmap; 158 goto out_unmap;
199 } 159 }
@@ -245,34 +205,20 @@ static int spu_map_resource(struct spu *spu, int nr,
245 void __iomem** virt, unsigned long *phys) 205 void __iomem** virt, unsigned long *phys)
246{ 206{
247 struct device_node *np = spu->devnode; 207 struct device_node *np = spu->devnode;
248 unsigned long start_pfn, nr_pages;
249 struct pglist_data *pgdata;
250 struct zone *zone;
251 struct resource resource = { }; 208 struct resource resource = { };
252 unsigned long len; 209 unsigned long len;
253 int ret; 210 int ret;
254 211
255 ret = of_address_to_resource(np, nr, &resource); 212 ret = of_address_to_resource(np, nr, &resource);
256 if (ret) 213 if (ret)
257 goto out; 214 return ret;
258
259 if (phys) 215 if (phys)
260 *phys = resource.start; 216 *phys = resource.start;
261 len = resource.end - resource.start + 1; 217 len = resource.end - resource.start + 1;
262 *virt = ioremap(resource.start, len); 218 *virt = ioremap(resource.start, len);
263 if (!*virt) 219 if (!*virt)
264 ret = -EINVAL; 220 return -EINVAL;
265 221 return 0;
266 start_pfn = resource.start >> PAGE_SHIFT;
267 nr_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
268
269 pgdata = NODE_DATA(spu->node);
270 zone = pgdata->node_zones;
271
272 ret = __add_pages(zone, start_pfn, nr_pages);
273
274out:
275 return ret;
276} 222}
277 223
278static int __init spu_map_device(struct spu *spu) 224static int __init spu_map_device(struct spu *spu)
diff --git a/arch/powerpc/platforms/cell/spufs/context.c b/arch/powerpc/platforms/cell/spufs/context.c
index 0870009f56db..04ad2e364e97 100644
--- a/arch/powerpc/platforms/cell/spufs/context.c
+++ b/arch/powerpc/platforms/cell/spufs/context.c
@@ -42,7 +42,7 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang)
42 } 42 }
43 spin_lock_init(&ctx->mmio_lock); 43 spin_lock_init(&ctx->mmio_lock);
44 kref_init(&ctx->kref); 44 kref_init(&ctx->kref);
45 init_rwsem(&ctx->state_sema); 45 mutex_init(&ctx->state_mutex);
46 init_MUTEX(&ctx->run_sema); 46 init_MUTEX(&ctx->run_sema);
47 init_waitqueue_head(&ctx->ibox_wq); 47 init_waitqueue_head(&ctx->ibox_wq);
48 init_waitqueue_head(&ctx->wbox_wq); 48 init_waitqueue_head(&ctx->wbox_wq);
@@ -53,6 +53,10 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang)
53 ctx->owner = get_task_mm(current); 53 ctx->owner = get_task_mm(current);
54 if (gang) 54 if (gang)
55 spu_gang_add_ctx(gang, ctx); 55 spu_gang_add_ctx(gang, ctx);
56 ctx->rt_priority = current->rt_priority;
57 ctx->policy = current->policy;
58 ctx->prio = current->prio;
59 INIT_DELAYED_WORK(&ctx->sched_work, spu_sched_tick);
56 goto out; 60 goto out;
57out_free: 61out_free:
58 kfree(ctx); 62 kfree(ctx);
@@ -65,9 +69,9 @@ void destroy_spu_context(struct kref *kref)
65{ 69{
66 struct spu_context *ctx; 70 struct spu_context *ctx;
67 ctx = container_of(kref, struct spu_context, kref); 71 ctx = container_of(kref, struct spu_context, kref);
68 down_write(&ctx->state_sema); 72 mutex_lock(&ctx->state_mutex);
69 spu_deactivate(ctx); 73 spu_deactivate(ctx);
70 up_write(&ctx->state_sema); 74 mutex_unlock(&ctx->state_mutex);
71 spu_fini_csa(&ctx->csa); 75 spu_fini_csa(&ctx->csa);
72 if (ctx->gang) 76 if (ctx->gang)
73 spu_gang_remove_ctx(ctx->gang, ctx); 77 spu_gang_remove_ctx(ctx->gang, ctx);
@@ -96,107 +100,102 @@ void spu_forget(struct spu_context *ctx)
96 spu_release(ctx); 100 spu_release(ctx);
97} 101}
98 102
99void spu_acquire(struct spu_context *ctx)
100{
101 down_read(&ctx->state_sema);
102}
103
104void spu_release(struct spu_context *ctx)
105{
106 up_read(&ctx->state_sema);
107}
108
109void spu_unmap_mappings(struct spu_context *ctx) 103void spu_unmap_mappings(struct spu_context *ctx)
110{ 104{
111 if (ctx->local_store) 105 if (ctx->local_store)
112 unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1); 106 unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1);
113 if (ctx->mfc) 107 if (ctx->mfc)
114 unmap_mapping_range(ctx->mfc, 0, 0x4000, 1); 108 unmap_mapping_range(ctx->mfc, 0, 0x1000, 1);
115 if (ctx->cntl) 109 if (ctx->cntl)
116 unmap_mapping_range(ctx->cntl, 0, 0x4000, 1); 110 unmap_mapping_range(ctx->cntl, 0, 0x1000, 1);
117 if (ctx->signal1) 111 if (ctx->signal1)
118 unmap_mapping_range(ctx->signal1, 0, 0x4000, 1); 112 unmap_mapping_range(ctx->signal1, 0, PAGE_SIZE, 1);
119 if (ctx->signal2) 113 if (ctx->signal2)
120 unmap_mapping_range(ctx->signal2, 0, 0x4000, 1); 114 unmap_mapping_range(ctx->signal2, 0, PAGE_SIZE, 1);
115 if (ctx->mss)
116 unmap_mapping_range(ctx->mss, 0, 0x1000, 1);
117 if (ctx->psmap)
118 unmap_mapping_range(ctx->psmap, 0, 0x20000, 1);
121} 119}
122 120
121/**
122 * spu_acquire_exclusive - lock spu contex and protect against userspace access
123 * @ctx: spu contex to lock
124 *
125 * Note:
126 * Returns 0 and with the context locked on success
127 * Returns negative error and with the context _unlocked_ on failure.
128 */
123int spu_acquire_exclusive(struct spu_context *ctx) 129int spu_acquire_exclusive(struct spu_context *ctx)
124{ 130{
125 int ret = 0; 131 int ret = -EINVAL;
126 132
127 down_write(&ctx->state_sema); 133 spu_acquire(ctx);
128 /* ctx is about to be freed, can't acquire any more */ 134 /*
129 if (!ctx->owner) { 135 * Context is about to be freed, so we can't acquire it anymore.
130 ret = -EINVAL; 136 */
131 goto out; 137 if (!ctx->owner)
132 } 138 goto out_unlock;
133 139
134 if (ctx->state == SPU_STATE_SAVED) { 140 if (ctx->state == SPU_STATE_SAVED) {
135 ret = spu_activate(ctx, 0); 141 ret = spu_activate(ctx, 0);
136 if (ret) 142 if (ret)
137 goto out; 143 goto out_unlock;
138 ctx->state = SPU_STATE_RUNNABLE;
139 } else { 144 } else {
140 /* We need to exclude userspace access to the context. */ 145 /*
146 * We need to exclude userspace access to the context.
147 *
148 * To protect against memory access we invalidate all ptes
149 * and make sure the pagefault handlers block on the mutex.
150 */
141 spu_unmap_mappings(ctx); 151 spu_unmap_mappings(ctx);
142 } 152 }
143 153
144out: 154 return 0;
145 if (ret) 155
146 up_write(&ctx->state_sema); 156 out_unlock:
157 spu_release(ctx);
147 return ret; 158 return ret;
148} 159}
149 160
150int spu_acquire_runnable(struct spu_context *ctx) 161/**
162 * spu_acquire_runnable - lock spu contex and make sure it is in runnable state
163 * @ctx: spu contex to lock
164 *
165 * Note:
166 * Returns 0 and with the context locked on success
167 * Returns negative error and with the context _unlocked_ on failure.
168 */
169int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags)
151{ 170{
152 int ret = 0; 171 int ret = -EINVAL;
153
154 down_read(&ctx->state_sema);
155 if (ctx->state == SPU_STATE_RUNNABLE) {
156 ctx->spu->prio = current->prio;
157 return 0;
158 }
159 up_read(&ctx->state_sema);
160
161 down_write(&ctx->state_sema);
162 /* ctx is about to be freed, can't acquire any more */
163 if (!ctx->owner) {
164 ret = -EINVAL;
165 goto out;
166 }
167 172
173 spu_acquire(ctx);
168 if (ctx->state == SPU_STATE_SAVED) { 174 if (ctx->state == SPU_STATE_SAVED) {
169 ret = spu_activate(ctx, 0); 175 /*
176 * Context is about to be freed, so we can't acquire it anymore.
177 */
178 if (!ctx->owner)
179 goto out_unlock;
180 ret = spu_activate(ctx, flags);
170 if (ret) 181 if (ret)
171 goto out; 182 goto out_unlock;
172 ctx->state = SPU_STATE_RUNNABLE;
173 } 183 }
174 184
175 downgrade_write(&ctx->state_sema); 185 return 0;
176 /* On success, we return holding the lock */
177
178 return ret;
179out:
180 /* Release here, to simplify calling code. */
181 up_write(&ctx->state_sema);
182 186
187 out_unlock:
188 spu_release(ctx);
183 return ret; 189 return ret;
184} 190}
185 191
192/**
193 * spu_acquire_saved - lock spu contex and make sure it is in saved state
194 * @ctx: spu contex to lock
195 */
186void spu_acquire_saved(struct spu_context *ctx) 196void spu_acquire_saved(struct spu_context *ctx)
187{ 197{
188 down_read(&ctx->state_sema); 198 spu_acquire(ctx);
189 199 if (ctx->state != SPU_STATE_SAVED)
190 if (ctx->state == SPU_STATE_SAVED)
191 return;
192
193 up_read(&ctx->state_sema);
194 down_write(&ctx->state_sema);
195
196 if (ctx->state == SPU_STATE_RUNNABLE) {
197 spu_deactivate(ctx); 200 spu_deactivate(ctx);
198 ctx->state = SPU_STATE_SAVED;
199 }
200
201 downgrade_write(&ctx->state_sema);
202} 201}
diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
index af9e9455a706..b00653d69c01 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -45,8 +45,8 @@ spufs_mem_open(struct inode *inode, struct file *file)
45 struct spufs_inode_info *i = SPUFS_I(inode); 45 struct spufs_inode_info *i = SPUFS_I(inode);
46 struct spu_context *ctx = i->i_ctx; 46 struct spu_context *ctx = i->i_ctx;
47 file->private_data = ctx; 47 file->private_data = ctx;
48 file->f_mapping = inode->i_mapping;
49 ctx->local_store = inode->i_mapping; 48 ctx->local_store = inode->i_mapping;
49 smp_wmb();
50 return 0; 50 return 0;
51} 51}
52 52
@@ -95,39 +95,38 @@ spufs_mem_write(struct file *file, const char __user *buffer,
95 return ret; 95 return ret;
96} 96}
97 97
98static struct page * 98static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
99spufs_mem_mmap_nopage(struct vm_area_struct *vma, 99 unsigned long address)
100 unsigned long address, int *type)
101{ 100{
102 struct page *page = NOPAGE_SIGBUS;
103
104 struct spu_context *ctx = vma->vm_file->private_data; 101 struct spu_context *ctx = vma->vm_file->private_data;
105 unsigned long offset = address - vma->vm_start; 102 unsigned long pfn, offset = address - vma->vm_start;
103
106 offset += vma->vm_pgoff << PAGE_SHIFT; 104 offset += vma->vm_pgoff << PAGE_SHIFT;
107 105
106 if (offset >= LS_SIZE)
107 return NOPFN_SIGBUS;
108
108 spu_acquire(ctx); 109 spu_acquire(ctx);
109 110
110 if (ctx->state == SPU_STATE_SAVED) { 111 if (ctx->state == SPU_STATE_SAVED) {
111 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 112 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
112 & ~_PAGE_NO_CACHE); 113 & ~_PAGE_NO_CACHE);
113 page = vmalloc_to_page(ctx->csa.lscsa->ls + offset); 114 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
114 } else { 115 } else {
115 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 116 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
116 | _PAGE_NO_CACHE); 117 | _PAGE_NO_CACHE);
117 page = pfn_to_page((ctx->spu->local_store_phys + offset) 118 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
118 >> PAGE_SHIFT);
119 } 119 }
120 spu_release(ctx); 120 vm_insert_pfn(vma, address, pfn);
121 121
122 if (type) 122 spu_release(ctx);
123 *type = VM_FAULT_MINOR;
124 123
125 page_cache_get(page); 124 return NOPFN_REFAULT;
126 return page;
127} 125}
128 126
127
129static struct vm_operations_struct spufs_mem_mmap_vmops = { 128static struct vm_operations_struct spufs_mem_mmap_vmops = {
130 .nopage = spufs_mem_mmap_nopage, 129 .nopfn = spufs_mem_mmap_nopfn,
131}; 130};
132 131
133static int 132static int
@@ -136,7 +135,7 @@ spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
136 if (!(vma->vm_flags & VM_SHARED)) 135 if (!(vma->vm_flags & VM_SHARED))
137 return -EINVAL; 136 return -EINVAL;
138 137
139 vma->vm_flags |= VM_IO; 138 vma->vm_flags |= VM_IO | VM_PFNMAP;
140 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 139 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
141 | _PAGE_NO_CACHE); 140 | _PAGE_NO_CACHE);
142 141
@@ -152,49 +151,42 @@ static const struct file_operations spufs_mem_fops = {
152 .mmap = spufs_mem_mmap, 151 .mmap = spufs_mem_mmap,
153}; 152};
154 153
155static struct page *spufs_ps_nopage(struct vm_area_struct *vma, 154static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
156 unsigned long address, 155 unsigned long address,
157 int *type, unsigned long ps_offs, 156 unsigned long ps_offs,
158 unsigned long ps_size) 157 unsigned long ps_size)
159{ 158{
160 struct page *page = NOPAGE_SIGBUS;
161 int fault_type = VM_FAULT_SIGBUS;
162 struct spu_context *ctx = vma->vm_file->private_data; 159 struct spu_context *ctx = vma->vm_file->private_data;
163 unsigned long offset = address - vma->vm_start; 160 unsigned long area, offset = address - vma->vm_start;
164 unsigned long area;
165 int ret; 161 int ret;
166 162
167 offset += vma->vm_pgoff << PAGE_SHIFT; 163 offset += vma->vm_pgoff << PAGE_SHIFT;
168 if (offset >= ps_size) 164 if (offset >= ps_size)
169 goto out; 165 return NOPFN_SIGBUS;
170 166
171 ret = spu_acquire_runnable(ctx); 167 /* error here usually means a signal.. we might want to test
168 * the error code more precisely though
169 */
170 ret = spu_acquire_runnable(ctx, 0);
172 if (ret) 171 if (ret)
173 goto out; 172 return NOPFN_REFAULT;
174 173
175 area = ctx->spu->problem_phys + ps_offs; 174 area = ctx->spu->problem_phys + ps_offs;
176 page = pfn_to_page((area + offset) >> PAGE_SHIFT); 175 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
177 fault_type = VM_FAULT_MINOR;
178 page_cache_get(page);
179
180 spu_release(ctx); 176 spu_release(ctx);
181 177
182 out: 178 return NOPFN_REFAULT;
183 if (type)
184 *type = fault_type;
185
186 return page;
187} 179}
188 180
189#if SPUFS_MMAP_4K 181#if SPUFS_MMAP_4K
190static struct page *spufs_cntl_mmap_nopage(struct vm_area_struct *vma, 182static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
191 unsigned long address, int *type) 183 unsigned long address)
192{ 184{
193 return spufs_ps_nopage(vma, address, type, 0x4000, 0x1000); 185 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
194} 186}
195 187
196static struct vm_operations_struct spufs_cntl_mmap_vmops = { 188static struct vm_operations_struct spufs_cntl_mmap_vmops = {
197 .nopage = spufs_cntl_mmap_nopage, 189 .nopfn = spufs_cntl_mmap_nopfn,
198}; 190};
199 191
200/* 192/*
@@ -205,7 +197,7 @@ static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
205 if (!(vma->vm_flags & VM_SHARED)) 197 if (!(vma->vm_flags & VM_SHARED))
206 return -EINVAL; 198 return -EINVAL;
207 199
208 vma->vm_flags |= VM_IO; 200 vma->vm_flags |= VM_IO | VM_PFNMAP;
209 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 201 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
210 | _PAGE_NO_CACHE | _PAGE_GUARDED); 202 | _PAGE_NO_CACHE | _PAGE_GUARDED);
211 203
@@ -243,8 +235,8 @@ static int spufs_cntl_open(struct inode *inode, struct file *file)
243 struct spu_context *ctx = i->i_ctx; 235 struct spu_context *ctx = i->i_ctx;
244 236
245 file->private_data = ctx; 237 file->private_data = ctx;
246 file->f_mapping = inode->i_mapping;
247 ctx->cntl = inode->i_mapping; 238 ctx->cntl = inode->i_mapping;
239 smp_wmb();
248 return simple_attr_open(inode, file, spufs_cntl_get, 240 return simple_attr_open(inode, file, spufs_cntl_get,
249 spufs_cntl_set, "0x%08lx"); 241 spufs_cntl_set, "0x%08lx");
250} 242}
@@ -728,8 +720,8 @@ static int spufs_signal1_open(struct inode *inode, struct file *file)
728 struct spufs_inode_info *i = SPUFS_I(inode); 720 struct spufs_inode_info *i = SPUFS_I(inode);
729 struct spu_context *ctx = i->i_ctx; 721 struct spu_context *ctx = i->i_ctx;
730 file->private_data = ctx; 722 file->private_data = ctx;
731 file->f_mapping = inode->i_mapping;
732 ctx->signal1 = inode->i_mapping; 723 ctx->signal1 = inode->i_mapping;
724 smp_wmb();
733 return nonseekable_open(inode, file); 725 return nonseekable_open(inode, file);
734} 726}
735 727
@@ -791,23 +783,23 @@ static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
791 return 4; 783 return 4;
792} 784}
793 785
794static struct page *spufs_signal1_mmap_nopage(struct vm_area_struct *vma, 786static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
795 unsigned long address, int *type) 787 unsigned long address)
796{ 788{
797#if PAGE_SIZE == 0x1000 789#if PAGE_SIZE == 0x1000
798 return spufs_ps_nopage(vma, address, type, 0x14000, 0x1000); 790 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
799#elif PAGE_SIZE == 0x10000 791#elif PAGE_SIZE == 0x10000
800 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole 792 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
801 * signal 1 and 2 area 793 * signal 1 and 2 area
802 */ 794 */
803 return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000); 795 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
804#else 796#else
805#error unsupported page size 797#error unsupported page size
806#endif 798#endif
807} 799}
808 800
809static struct vm_operations_struct spufs_signal1_mmap_vmops = { 801static struct vm_operations_struct spufs_signal1_mmap_vmops = {
810 .nopage = spufs_signal1_mmap_nopage, 802 .nopfn = spufs_signal1_mmap_nopfn,
811}; 803};
812 804
813static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma) 805static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
@@ -815,7 +807,7 @@ static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
815 if (!(vma->vm_flags & VM_SHARED)) 807 if (!(vma->vm_flags & VM_SHARED))
816 return -EINVAL; 808 return -EINVAL;
817 809
818 vma->vm_flags |= VM_IO; 810 vma->vm_flags |= VM_IO | VM_PFNMAP;
819 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 811 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
820 | _PAGE_NO_CACHE | _PAGE_GUARDED); 812 | _PAGE_NO_CACHE | _PAGE_GUARDED);
821 813
@@ -835,8 +827,8 @@ static int spufs_signal2_open(struct inode *inode, struct file *file)
835 struct spufs_inode_info *i = SPUFS_I(inode); 827 struct spufs_inode_info *i = SPUFS_I(inode);
836 struct spu_context *ctx = i->i_ctx; 828 struct spu_context *ctx = i->i_ctx;
837 file->private_data = ctx; 829 file->private_data = ctx;
838 file->f_mapping = inode->i_mapping;
839 ctx->signal2 = inode->i_mapping; 830 ctx->signal2 = inode->i_mapping;
831 smp_wmb();
840 return nonseekable_open(inode, file); 832 return nonseekable_open(inode, file);
841} 833}
842 834
@@ -899,23 +891,23 @@ static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
899} 891}
900 892
901#if SPUFS_MMAP_4K 893#if SPUFS_MMAP_4K
902static struct page *spufs_signal2_mmap_nopage(struct vm_area_struct *vma, 894static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
903 unsigned long address, int *type) 895 unsigned long address)
904{ 896{
905#if PAGE_SIZE == 0x1000 897#if PAGE_SIZE == 0x1000
906 return spufs_ps_nopage(vma, address, type, 0x1c000, 0x1000); 898 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
907#elif PAGE_SIZE == 0x10000 899#elif PAGE_SIZE == 0x10000
908 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole 900 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
909 * signal 1 and 2 area 901 * signal 1 and 2 area
910 */ 902 */
911 return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000); 903 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
912#else 904#else
913#error unsupported page size 905#error unsupported page size
914#endif 906#endif
915} 907}
916 908
917static struct vm_operations_struct spufs_signal2_mmap_vmops = { 909static struct vm_operations_struct spufs_signal2_mmap_vmops = {
918 .nopage = spufs_signal2_mmap_nopage, 910 .nopfn = spufs_signal2_mmap_nopfn,
919}; 911};
920 912
921static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma) 913static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
@@ -923,7 +915,7 @@ static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
923 if (!(vma->vm_flags & VM_SHARED)) 915 if (!(vma->vm_flags & VM_SHARED))
924 return -EINVAL; 916 return -EINVAL;
925 917
926 vma->vm_flags |= VM_IO; 918 vma->vm_flags |= VM_IO | VM_PFNMAP;
927 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 919 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
928 | _PAGE_NO_CACHE | _PAGE_GUARDED); 920 | _PAGE_NO_CACHE | _PAGE_GUARDED);
929 921
@@ -1000,14 +992,14 @@ DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1000 spufs_signal2_type_set, "%llu"); 992 spufs_signal2_type_set, "%llu");
1001 993
1002#if SPUFS_MMAP_4K 994#if SPUFS_MMAP_4K
1003static struct page *spufs_mss_mmap_nopage(struct vm_area_struct *vma, 995static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1004 unsigned long address, int *type) 996 unsigned long address)
1005{ 997{
1006 return spufs_ps_nopage(vma, address, type, 0x0000, 0x1000); 998 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
1007} 999}
1008 1000
1009static struct vm_operations_struct spufs_mss_mmap_vmops = { 1001static struct vm_operations_struct spufs_mss_mmap_vmops = {
1010 .nopage = spufs_mss_mmap_nopage, 1002 .nopfn = spufs_mss_mmap_nopfn,
1011}; 1003};
1012 1004
1013/* 1005/*
@@ -1018,7 +1010,7 @@ static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1018 if (!(vma->vm_flags & VM_SHARED)) 1010 if (!(vma->vm_flags & VM_SHARED))
1019 return -EINVAL; 1011 return -EINVAL;
1020 1012
1021 vma->vm_flags |= VM_IO; 1013 vma->vm_flags |= VM_IO | VM_PFNMAP;
1022 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 1014 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1023 | _PAGE_NO_CACHE | _PAGE_GUARDED); 1015 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1024 1016
@@ -1032,8 +1024,11 @@ static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1032static int spufs_mss_open(struct inode *inode, struct file *file) 1024static int spufs_mss_open(struct inode *inode, struct file *file)
1033{ 1025{
1034 struct spufs_inode_info *i = SPUFS_I(inode); 1026 struct spufs_inode_info *i = SPUFS_I(inode);
1027 struct spu_context *ctx = i->i_ctx;
1035 1028
1036 file->private_data = i->i_ctx; 1029 file->private_data = i->i_ctx;
1030 ctx->mss = inode->i_mapping;
1031 smp_wmb();
1037 return nonseekable_open(inode, file); 1032 return nonseekable_open(inode, file);
1038} 1033}
1039 1034
@@ -1042,14 +1037,14 @@ static const struct file_operations spufs_mss_fops = {
1042 .mmap = spufs_mss_mmap, 1037 .mmap = spufs_mss_mmap,
1043}; 1038};
1044 1039
1045static struct page *spufs_psmap_mmap_nopage(struct vm_area_struct *vma, 1040static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1046 unsigned long address, int *type) 1041 unsigned long address)
1047{ 1042{
1048 return spufs_ps_nopage(vma, address, type, 0x0000, 0x20000); 1043 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
1049} 1044}
1050 1045
1051static struct vm_operations_struct spufs_psmap_mmap_vmops = { 1046static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1052 .nopage = spufs_psmap_mmap_nopage, 1047 .nopfn = spufs_psmap_mmap_nopfn,
1053}; 1048};
1054 1049
1055/* 1050/*
@@ -1060,7 +1055,7 @@ static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1060 if (!(vma->vm_flags & VM_SHARED)) 1055 if (!(vma->vm_flags & VM_SHARED))
1061 return -EINVAL; 1056 return -EINVAL;
1062 1057
1063 vma->vm_flags |= VM_IO; 1058 vma->vm_flags |= VM_IO | VM_PFNMAP;
1064 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 1059 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1065 | _PAGE_NO_CACHE | _PAGE_GUARDED); 1060 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1066 1061
@@ -1071,8 +1066,11 @@ static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1071static int spufs_psmap_open(struct inode *inode, struct file *file) 1066static int spufs_psmap_open(struct inode *inode, struct file *file)
1072{ 1067{
1073 struct spufs_inode_info *i = SPUFS_I(inode); 1068 struct spufs_inode_info *i = SPUFS_I(inode);
1069 struct spu_context *ctx = i->i_ctx;
1074 1070
1075 file->private_data = i->i_ctx; 1071 file->private_data = i->i_ctx;
1072 ctx->psmap = inode->i_mapping;
1073 smp_wmb();
1076 return nonseekable_open(inode, file); 1074 return nonseekable_open(inode, file);
1077} 1075}
1078 1076
@@ -1083,14 +1081,14 @@ static const struct file_operations spufs_psmap_fops = {
1083 1081
1084 1082
1085#if SPUFS_MMAP_4K 1083#if SPUFS_MMAP_4K
1086static struct page *spufs_mfc_mmap_nopage(struct vm_area_struct *vma, 1084static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1087 unsigned long address, int *type) 1085 unsigned long address)
1088{ 1086{
1089 return spufs_ps_nopage(vma, address, type, 0x3000, 0x1000); 1087 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
1090} 1088}
1091 1089
1092static struct vm_operations_struct spufs_mfc_mmap_vmops = { 1090static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1093 .nopage = spufs_mfc_mmap_nopage, 1091 .nopfn = spufs_mfc_mmap_nopfn,
1094}; 1092};
1095 1093
1096/* 1094/*
@@ -1101,7 +1099,7 @@ static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1101 if (!(vma->vm_flags & VM_SHARED)) 1099 if (!(vma->vm_flags & VM_SHARED))
1102 return -EINVAL; 1100 return -EINVAL;
1103 1101
1104 vma->vm_flags |= VM_IO; 1102 vma->vm_flags |= VM_IO | VM_PFNMAP;
1105 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 1103 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1106 | _PAGE_NO_CACHE | _PAGE_GUARDED); 1104 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1107 1105
@@ -1125,6 +1123,8 @@ static int spufs_mfc_open(struct inode *inode, struct file *file)
1125 return -EBUSY; 1123 return -EBUSY;
1126 1124
1127 file->private_data = ctx; 1125 file->private_data = ctx;
1126 ctx->mfc = inode->i_mapping;
1127 smp_wmb();
1128 return nonseekable_open(inode, file); 1128 return nonseekable_open(inode, file);
1129} 1129}
1130 1130
@@ -1309,7 +1309,7 @@ static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1309 if (ret) 1309 if (ret)
1310 goto out; 1310 goto out;
1311 1311
1312 spu_acquire_runnable(ctx); 1312 spu_acquire_runnable(ctx, 0);
1313 if (file->f_flags & O_NONBLOCK) { 1313 if (file->f_flags & O_NONBLOCK) {
1314 ret = ctx->ops->send_mfc_command(ctx, &cmd); 1314 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1315 } else { 1315 } else {
diff --git a/arch/powerpc/platforms/cell/spufs/run.c b/arch/powerpc/platforms/cell/spufs/run.c
index 1acc2ffef8c8..353a8fa07ab8 100644
--- a/arch/powerpc/platforms/cell/spufs/run.c
+++ b/arch/powerpc/platforms/cell/spufs/run.c
@@ -133,7 +133,7 @@ out_drop_priv:
133 spu_mfc_sr1_set(ctx->spu, sr1); 133 spu_mfc_sr1_set(ctx->spu, sr1);
134 134
135out_unlock: 135out_unlock:
136 spu_release_exclusive(ctx); 136 spu_release(ctx);
137out: 137out:
138 return ret; 138 return ret;
139} 139}
@@ -143,7 +143,7 @@ static inline int spu_run_init(struct spu_context *ctx, u32 * npc)
143 int ret; 143 int ret;
144 unsigned long runcntl = SPU_RUNCNTL_RUNNABLE; 144 unsigned long runcntl = SPU_RUNCNTL_RUNNABLE;
145 145
146 ret = spu_acquire_runnable(ctx); 146 ret = spu_acquire_runnable(ctx, SPU_ACTIVATE_NOWAKE);
147 if (ret) 147 if (ret)
148 return ret; 148 return ret;
149 149
@@ -155,7 +155,7 @@ static inline int spu_run_init(struct spu_context *ctx, u32 * npc)
155 spu_release(ctx); 155 spu_release(ctx);
156 ret = spu_setup_isolated(ctx); 156 ret = spu_setup_isolated(ctx);
157 if (!ret) 157 if (!ret)
158 ret = spu_acquire_runnable(ctx); 158 ret = spu_acquire_runnable(ctx, SPU_ACTIVATE_NOWAKE);
159 } 159 }
160 160
161 /* if userspace has set the runcntrl register (eg, to issue an 161 /* if userspace has set the runcntrl register (eg, to issue an
@@ -164,8 +164,10 @@ static inline int spu_run_init(struct spu_context *ctx, u32 * npc)
164 (SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE); 164 (SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
165 if (runcntl == 0) 165 if (runcntl == 0)
166 runcntl = SPU_RUNCNTL_RUNNABLE; 166 runcntl = SPU_RUNCNTL_RUNNABLE;
167 } else 167 } else {
168 spu_start_tick(ctx);
168 ctx->ops->npc_write(ctx, *npc); 169 ctx->ops->npc_write(ctx, *npc);
170 }
169 171
170 ctx->ops->runcntl_write(ctx, runcntl); 172 ctx->ops->runcntl_write(ctx, runcntl);
171 return ret; 173 return ret;
@@ -176,6 +178,7 @@ static inline int spu_run_fini(struct spu_context *ctx, u32 * npc,
176{ 178{
177 int ret = 0; 179 int ret = 0;
178 180
181 spu_stop_tick(ctx);
179 *status = ctx->ops->status_read(ctx); 182 *status = ctx->ops->status_read(ctx);
180 *npc = ctx->ops->npc_read(ctx); 183 *npc = ctx->ops->npc_read(ctx);
181 spu_release(ctx); 184 spu_release(ctx);
@@ -329,8 +332,10 @@ long spufs_run_spu(struct file *file, struct spu_context *ctx,
329 } 332 }
330 if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) { 333 if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) {
331 ret = spu_reacquire_runnable(ctx, npc, &status); 334 ret = spu_reacquire_runnable(ctx, npc, &status);
332 if (ret) 335 if (ret) {
336 spu_stop_tick(ctx);
333 goto out2; 337 goto out2;
338 }
334 continue; 339 continue;
335 } 340 }
336 ret = spu_process_events(ctx); 341 ret = spu_process_events(ctx);
@@ -361,4 +366,3 @@ out:
361 up(&ctx->run_sema); 366 up(&ctx->run_sema);
362 return ret; 367 return ret;
363} 368}
364
diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index bd6fe4b7a84b..2f25e68b4bac 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -44,17 +44,18 @@
44#include <asm/spu_priv1.h> 44#include <asm/spu_priv1.h>
45#include "spufs.h" 45#include "spufs.h"
46 46
47#define SPU_MIN_TIMESLICE (100 * HZ / 1000) 47#define SPU_TIMESLICE (HZ)
48 48
49#define SPU_BITMAP_SIZE (((MAX_PRIO+BITS_PER_LONG)/BITS_PER_LONG)+1)
50struct spu_prio_array { 49struct spu_prio_array {
51 unsigned long bitmap[SPU_BITMAP_SIZE]; 50 DECLARE_BITMAP(bitmap, MAX_PRIO);
52 wait_queue_head_t waitq[MAX_PRIO]; 51 struct list_head runq[MAX_PRIO];
52 spinlock_t runq_lock;
53 struct list_head active_list[MAX_NUMNODES]; 53 struct list_head active_list[MAX_NUMNODES];
54 struct mutex active_mutex[MAX_NUMNODES]; 54 struct mutex active_mutex[MAX_NUMNODES];
55}; 55};
56 56
57static struct spu_prio_array *spu_prio; 57static struct spu_prio_array *spu_prio;
58static struct workqueue_struct *spu_sched_wq;
58 59
59static inline int node_allowed(int node) 60static inline int node_allowed(int node)
60{ 61{
@@ -68,6 +69,64 @@ static inline int node_allowed(int node)
68 return 1; 69 return 1;
69} 70}
70 71
72void spu_start_tick(struct spu_context *ctx)
73{
74 if (ctx->policy == SCHED_RR)
75 queue_delayed_work(spu_sched_wq, &ctx->sched_work, SPU_TIMESLICE);
76}
77
78void spu_stop_tick(struct spu_context *ctx)
79{
80 if (ctx->policy == SCHED_RR)
81 cancel_delayed_work(&ctx->sched_work);
82}
83
84void spu_sched_tick(struct work_struct *work)
85{
86 struct spu_context *ctx =
87 container_of(work, struct spu_context, sched_work.work);
88 struct spu *spu;
89 int rearm = 1;
90
91 mutex_lock(&ctx->state_mutex);
92 spu = ctx->spu;
93 if (spu) {
94 int best = sched_find_first_bit(spu_prio->bitmap);
95 if (best <= ctx->prio) {
96 spu_deactivate(ctx);
97 rearm = 0;
98 }
99 }
100 mutex_unlock(&ctx->state_mutex);
101
102 if (rearm)
103 spu_start_tick(ctx);
104}
105
106/**
107 * spu_add_to_active_list - add spu to active list
108 * @spu: spu to add to the active list
109 */
110static void spu_add_to_active_list(struct spu *spu)
111{
112 mutex_lock(&spu_prio->active_mutex[spu->node]);
113 list_add_tail(&spu->list, &spu_prio->active_list[spu->node]);
114 mutex_unlock(&spu_prio->active_mutex[spu->node]);
115}
116
117/**
118 * spu_remove_from_active_list - remove spu from active list
119 * @spu: spu to remove from the active list
120 */
121static void spu_remove_from_active_list(struct spu *spu)
122{
123 int node = spu->node;
124
125 mutex_lock(&spu_prio->active_mutex[node]);
126 list_del_init(&spu->list);
127 mutex_unlock(&spu_prio->active_mutex[node]);
128}
129
71static inline void mm_needs_global_tlbie(struct mm_struct *mm) 130static inline void mm_needs_global_tlbie(struct mm_struct *mm)
72{ 131{
73 int nr = (NR_CPUS > 1) ? NR_CPUS : NR_CPUS + 1; 132 int nr = (NR_CPUS > 1) ? NR_CPUS : NR_CPUS + 1;
@@ -94,8 +153,12 @@ int spu_switch_event_unregister(struct notifier_block * n)
94 return blocking_notifier_chain_unregister(&spu_switch_notifier, n); 153 return blocking_notifier_chain_unregister(&spu_switch_notifier, n);
95} 154}
96 155
97 156/**
98static inline void bind_context(struct spu *spu, struct spu_context *ctx) 157 * spu_bind_context - bind spu context to physical spu
158 * @spu: physical spu to bind to
159 * @ctx: context to bind
160 */
161static void spu_bind_context(struct spu *spu, struct spu_context *ctx)
99{ 162{
100 pr_debug("%s: pid=%d SPU=%d NODE=%d\n", __FUNCTION__, current->pid, 163 pr_debug("%s: pid=%d SPU=%d NODE=%d\n", __FUNCTION__, current->pid,
101 spu->number, spu->node); 164 spu->number, spu->node);
@@ -104,7 +167,6 @@ static inline void bind_context(struct spu *spu, struct spu_context *ctx)
104 ctx->spu = spu; 167 ctx->spu = spu;
105 ctx->ops = &spu_hw_ops; 168 ctx->ops = &spu_hw_ops;
106 spu->pid = current->pid; 169 spu->pid = current->pid;
107 spu->prio = current->prio;
108 spu->mm = ctx->owner; 170 spu->mm = ctx->owner;
109 mm_needs_global_tlbie(spu->mm); 171 mm_needs_global_tlbie(spu->mm);
110 spu->ibox_callback = spufs_ibox_callback; 172 spu->ibox_callback = spufs_ibox_callback;
@@ -118,12 +180,21 @@ static inline void bind_context(struct spu *spu, struct spu_context *ctx)
118 spu->timestamp = jiffies; 180 spu->timestamp = jiffies;
119 spu_cpu_affinity_set(spu, raw_smp_processor_id()); 181 spu_cpu_affinity_set(spu, raw_smp_processor_id());
120 spu_switch_notify(spu, ctx); 182 spu_switch_notify(spu, ctx);
183 spu_add_to_active_list(spu);
184 ctx->state = SPU_STATE_RUNNABLE;
121} 185}
122 186
123static inline void unbind_context(struct spu *spu, struct spu_context *ctx) 187/**
188 * spu_unbind_context - unbind spu context from physical spu
189 * @spu: physical spu to unbind from
190 * @ctx: context to unbind
191 */
192static void spu_unbind_context(struct spu *spu, struct spu_context *ctx)
124{ 193{
125 pr_debug("%s: unbind pid=%d SPU=%d NODE=%d\n", __FUNCTION__, 194 pr_debug("%s: unbind pid=%d SPU=%d NODE=%d\n", __FUNCTION__,
126 spu->pid, spu->number, spu->node); 195 spu->pid, spu->number, spu->node);
196
197 spu_remove_from_active_list(spu);
127 spu_switch_notify(spu, NULL); 198 spu_switch_notify(spu, NULL);
128 spu_unmap_mappings(ctx); 199 spu_unmap_mappings(ctx);
129 spu_save(&ctx->csa, spu); 200 spu_save(&ctx->csa, spu);
@@ -136,95 +207,98 @@ static inline void unbind_context(struct spu *spu, struct spu_context *ctx)
136 spu->dma_callback = NULL; 207 spu->dma_callback = NULL;
137 spu->mm = NULL; 208 spu->mm = NULL;
138 spu->pid = 0; 209 spu->pid = 0;
139 spu->prio = MAX_PRIO;
140 ctx->ops = &spu_backing_ops; 210 ctx->ops = &spu_backing_ops;
141 ctx->spu = NULL; 211 ctx->spu = NULL;
142 spu->flags = 0; 212 spu->flags = 0;
143 spu->ctx = NULL; 213 spu->ctx = NULL;
144} 214}
145 215
146static inline void spu_add_wq(wait_queue_head_t * wq, wait_queue_t * wait, 216/**
147 int prio) 217 * spu_add_to_rq - add a context to the runqueue
218 * @ctx: context to add
219 */
220static void spu_add_to_rq(struct spu_context *ctx)
148{ 221{
149 prepare_to_wait_exclusive(wq, wait, TASK_INTERRUPTIBLE); 222 spin_lock(&spu_prio->runq_lock);
150 set_bit(prio, spu_prio->bitmap); 223 list_add_tail(&ctx->rq, &spu_prio->runq[ctx->prio]);
224 set_bit(ctx->prio, spu_prio->bitmap);
225 spin_unlock(&spu_prio->runq_lock);
151} 226}
152 227
153static inline void spu_del_wq(wait_queue_head_t * wq, wait_queue_t * wait, 228/**
154 int prio) 229 * spu_del_from_rq - remove a context from the runqueue
230 * @ctx: context to remove
231 */
232static void spu_del_from_rq(struct spu_context *ctx)
155{ 233{
156 u64 flags; 234 spin_lock(&spu_prio->runq_lock);
157 235 list_del_init(&ctx->rq);
158 __set_current_state(TASK_RUNNING); 236 if (list_empty(&spu_prio->runq[ctx->prio]))
159 237 clear_bit(ctx->prio, spu_prio->bitmap);
160 spin_lock_irqsave(&wq->lock, flags); 238 spin_unlock(&spu_prio->runq_lock);
239}
161 240
162 remove_wait_queue_locked(wq, wait); 241/**
163 if (list_empty(&wq->task_list)) 242 * spu_grab_context - remove one context from the runqueue
164 clear_bit(prio, spu_prio->bitmap); 243 * @prio: priority of the context to be removed
244 *
245 * This function removes one context from the runqueue for priority @prio.
246 * If there is more than one context with the given priority the first
247 * task on the runqueue will be taken.
248 *
249 * Returns the spu_context it just removed.
250 *
251 * Must be called with spu_prio->runq_lock held.
252 */
253static struct spu_context *spu_grab_context(int prio)
254{
255 struct list_head *rq = &spu_prio->runq[prio];
165 256
166 spin_unlock_irqrestore(&wq->lock, flags); 257 if (list_empty(rq))
258 return NULL;
259 return list_entry(rq->next, struct spu_context, rq);
167} 260}
168 261
169static void spu_prio_wait(struct spu_context *ctx, u64 flags) 262static void spu_prio_wait(struct spu_context *ctx)
170{ 263{
171 int prio = current->prio;
172 wait_queue_head_t *wq = &spu_prio->waitq[prio];
173 DEFINE_WAIT(wait); 264 DEFINE_WAIT(wait);
174 265
175 if (ctx->spu) 266 set_bit(SPU_SCHED_WAKE, &ctx->sched_flags);
176 return; 267 prepare_to_wait_exclusive(&ctx->stop_wq, &wait, TASK_INTERRUPTIBLE);
177
178 spu_add_wq(wq, &wait, prio);
179
180 if (!signal_pending(current)) { 268 if (!signal_pending(current)) {
181 up_write(&ctx->state_sema); 269 mutex_unlock(&ctx->state_mutex);
182 pr_debug("%s: pid=%d prio=%d\n", __FUNCTION__,
183 current->pid, current->prio);
184 schedule(); 270 schedule();
185 down_write(&ctx->state_sema); 271 mutex_lock(&ctx->state_mutex);
186 } 272 }
187 273 __set_current_state(TASK_RUNNING);
188 spu_del_wq(wq, &wait, prio); 274 remove_wait_queue(&ctx->stop_wq, &wait);
275 clear_bit(SPU_SCHED_WAKE, &ctx->sched_flags);
189} 276}
190 277
191static void spu_prio_wakeup(void) 278/**
279 * spu_reschedule - try to find a runnable context for a spu
280 * @spu: spu available
281 *
282 * This function is called whenever a spu becomes idle. It looks for the
283 * most suitable runnable spu context and schedules it for execution.
284 */
285static void spu_reschedule(struct spu *spu)
192{ 286{
193 int best = sched_find_first_bit(spu_prio->bitmap); 287 int best;
194 if (best < MAX_PRIO) {
195 wait_queue_head_t *wq = &spu_prio->waitq[best];
196 wake_up_interruptible_nr(wq, 1);
197 }
198}
199 288
200static int get_active_spu(struct spu *spu) 289 spu_free(spu);
201{
202 int node = spu->node;
203 struct spu *tmp;
204 int rc = 0;
205 290
206 mutex_lock(&spu_prio->active_mutex[node]); 291 spin_lock(&spu_prio->runq_lock);
207 list_for_each_entry(tmp, &spu_prio->active_list[node], list) { 292 best = sched_find_first_bit(spu_prio->bitmap);
208 if (tmp == spu) { 293 if (best < MAX_PRIO) {
209 list_del_init(&spu->list); 294 struct spu_context *ctx = spu_grab_context(best);
210 rc = 1; 295 if (ctx && test_bit(SPU_SCHED_WAKE, &ctx->sched_flags))
211 break; 296 wake_up(&ctx->stop_wq);
212 }
213 } 297 }
214 mutex_unlock(&spu_prio->active_mutex[node]); 298 spin_unlock(&spu_prio->runq_lock);
215 return rc;
216}
217
218static void put_active_spu(struct spu *spu)
219{
220 int node = spu->node;
221
222 mutex_lock(&spu_prio->active_mutex[node]);
223 list_add_tail(&spu->list, &spu_prio->active_list[node]);
224 mutex_unlock(&spu_prio->active_mutex[node]);
225} 299}
226 300
227static struct spu *spu_get_idle(struct spu_context *ctx, u64 flags) 301static struct spu *spu_get_idle(struct spu_context *ctx)
228{ 302{
229 struct spu *spu = NULL; 303 struct spu *spu = NULL;
230 int node = cpu_to_node(raw_smp_processor_id()); 304 int node = cpu_to_node(raw_smp_processor_id());
@@ -241,87 +315,154 @@ static struct spu *spu_get_idle(struct spu_context *ctx, u64 flags)
241 return spu; 315 return spu;
242} 316}
243 317
244static inline struct spu *spu_get(struct spu_context *ctx, u64 flags) 318/**
319 * find_victim - find a lower priority context to preempt
320 * @ctx: canidate context for running
321 *
322 * Returns the freed physical spu to run the new context on.
323 */
324static struct spu *find_victim(struct spu_context *ctx)
245{ 325{
246 /* Future: spu_get_idle() if possible, 326 struct spu_context *victim = NULL;
247 * otherwise try to preempt an active 327 struct spu *spu;
248 * context. 328 int node, n;
329
330 /*
331 * Look for a possible preemption candidate on the local node first.
332 * If there is no candidate look at the other nodes. This isn't
333 * exactly fair, but so far the whole spu schedule tries to keep
334 * a strong node affinity. We might want to fine-tune this in
335 * the future.
249 */ 336 */
250 return spu_get_idle(ctx, flags); 337 restart:
338 node = cpu_to_node(raw_smp_processor_id());
339 for (n = 0; n < MAX_NUMNODES; n++, node++) {
340 node = (node < MAX_NUMNODES) ? node : 0;
341 if (!node_allowed(node))
342 continue;
343
344 mutex_lock(&spu_prio->active_mutex[node]);
345 list_for_each_entry(spu, &spu_prio->active_list[node], list) {
346 struct spu_context *tmp = spu->ctx;
347
348 if (tmp->rt_priority < ctx->rt_priority &&
349 (!victim || tmp->rt_priority < victim->rt_priority))
350 victim = spu->ctx;
351 }
352 mutex_unlock(&spu_prio->active_mutex[node]);
353
354 if (victim) {
355 /*
356 * This nests ctx->state_mutex, but we always lock
357 * higher priority contexts before lower priority
358 * ones, so this is safe until we introduce
359 * priority inheritance schemes.
360 */
361 if (!mutex_trylock(&victim->state_mutex)) {
362 victim = NULL;
363 goto restart;
364 }
365
366 spu = victim->spu;
367 if (!spu) {
368 /*
369 * This race can happen because we've dropped
370 * the active list mutex. No a problem, just
371 * restart the search.
372 */
373 mutex_unlock(&victim->state_mutex);
374 victim = NULL;
375 goto restart;
376 }
377 spu_unbind_context(spu, victim);
378 mutex_unlock(&victim->state_mutex);
379 return spu;
380 }
381 }
382
383 return NULL;
251} 384}
252 385
253/* The three externally callable interfaces 386/**
254 * for the scheduler begin here. 387 * spu_activate - find a free spu for a context and execute it
388 * @ctx: spu context to schedule
389 * @flags: flags (currently ignored)
255 * 390 *
256 * spu_activate - bind a context to SPU, waiting as needed. 391 * Tries to find a free spu to run @ctx. If no free spu is availble
257 * spu_deactivate - unbind a context from its SPU. 392 * add the context to the runqueue so it gets woken up once an spu
258 * spu_yield - yield an SPU if others are waiting. 393 * is available.
259 */ 394 */
260 395int spu_activate(struct spu_context *ctx, unsigned long flags)
261int spu_activate(struct spu_context *ctx, u64 flags)
262{ 396{
263 struct spu *spu;
264 int ret = 0;
265 397
266 for (;;) { 398 if (ctx->spu)
267 if (ctx->spu) 399 return 0;
400
401 do {
402 struct spu *spu;
403
404 spu = spu_get_idle(ctx);
405 /*
406 * If this is a realtime thread we try to get it running by
407 * preempting a lower priority thread.
408 */
409 if (!spu && ctx->rt_priority)
410 spu = find_victim(ctx);
411 if (spu) {
412 spu_bind_context(spu, ctx);
268 return 0; 413 return 0;
269 spu = spu_get(ctx, flags);
270 if (spu != NULL) {
271 if (ctx->spu != NULL) {
272 spu_free(spu);
273 spu_prio_wakeup();
274 break;
275 }
276 bind_context(spu, ctx);
277 put_active_spu(spu);
278 break;
279 } 414 }
280 spu_prio_wait(ctx, flags); 415
281 if (signal_pending(current)) { 416 spu_add_to_rq(ctx);
282 ret = -ERESTARTSYS; 417 if (!(flags & SPU_ACTIVATE_NOWAKE))
283 spu_prio_wakeup(); 418 spu_prio_wait(ctx);
284 break; 419 spu_del_from_rq(ctx);
285 } 420 } while (!signal_pending(current));
286 } 421
287 return ret; 422 return -ERESTARTSYS;
288} 423}
289 424
425/**
426 * spu_deactivate - unbind a context from it's physical spu
427 * @ctx: spu context to unbind
428 *
429 * Unbind @ctx from the physical spu it is running on and schedule
430 * the highest priority context to run on the freed physical spu.
431 */
290void spu_deactivate(struct spu_context *ctx) 432void spu_deactivate(struct spu_context *ctx)
291{ 433{
292 struct spu *spu; 434 struct spu *spu = ctx->spu;
293 int needs_idle;
294 435
295 spu = ctx->spu; 436 if (spu) {
296 if (!spu) 437 spu_unbind_context(spu, ctx);
297 return; 438 spu_reschedule(spu);
298 needs_idle = get_active_spu(spu);
299 unbind_context(spu, ctx);
300 if (needs_idle) {
301 spu_free(spu);
302 spu_prio_wakeup();
303 } 439 }
304} 440}
305 441
442/**
443 * spu_yield - yield a physical spu if others are waiting
444 * @ctx: spu context to yield
445 *
446 * Check if there is a higher priority context waiting and if yes
447 * unbind @ctx from the physical spu and schedule the highest
448 * priority context to run on the freed physical spu instead.
449 */
306void spu_yield(struct spu_context *ctx) 450void spu_yield(struct spu_context *ctx)
307{ 451{
308 struct spu *spu; 452 struct spu *spu;
309 int need_yield = 0; 453 int need_yield = 0;
310 454
311 if (down_write_trylock(&ctx->state_sema)) { 455 if (mutex_trylock(&ctx->state_mutex)) {
312 if ((spu = ctx->spu) != NULL) { 456 if ((spu = ctx->spu) != NULL) {
313 int best = sched_find_first_bit(spu_prio->bitmap); 457 int best = sched_find_first_bit(spu_prio->bitmap);
314 if (best < MAX_PRIO) { 458 if (best < MAX_PRIO) {
315 pr_debug("%s: yielding SPU %d NODE %d\n", 459 pr_debug("%s: yielding SPU %d NODE %d\n",
316 __FUNCTION__, spu->number, spu->node); 460 __FUNCTION__, spu->number, spu->node);
317 spu_deactivate(ctx); 461 spu_deactivate(ctx);
318 ctx->state = SPU_STATE_SAVED;
319 need_yield = 1; 462 need_yield = 1;
320 } else {
321 spu->prio = MAX_PRIO;
322 } 463 }
323 } 464 }
324 up_write(&ctx->state_sema); 465 mutex_unlock(&ctx->state_mutex);
325 } 466 }
326 if (unlikely(need_yield)) 467 if (unlikely(need_yield))
327 yield(); 468 yield();
@@ -331,14 +472,19 @@ int __init spu_sched_init(void)
331{ 472{
332 int i; 473 int i;
333 474
475 spu_sched_wq = create_singlethread_workqueue("spusched");
476 if (!spu_sched_wq)
477 return 1;
478
334 spu_prio = kzalloc(sizeof(struct spu_prio_array), GFP_KERNEL); 479 spu_prio = kzalloc(sizeof(struct spu_prio_array), GFP_KERNEL);
335 if (!spu_prio) { 480 if (!spu_prio) {
336 printk(KERN_WARNING "%s: Unable to allocate priority queue.\n", 481 printk(KERN_WARNING "%s: Unable to allocate priority queue.\n",
337 __FUNCTION__); 482 __FUNCTION__);
483 destroy_workqueue(spu_sched_wq);
338 return 1; 484 return 1;
339 } 485 }
340 for (i = 0; i < MAX_PRIO; i++) { 486 for (i = 0; i < MAX_PRIO; i++) {
341 init_waitqueue_head(&spu_prio->waitq[i]); 487 INIT_LIST_HEAD(&spu_prio->runq[i]);
342 __clear_bit(i, spu_prio->bitmap); 488 __clear_bit(i, spu_prio->bitmap);
343 } 489 }
344 __set_bit(MAX_PRIO, spu_prio->bitmap); 490 __set_bit(MAX_PRIO, spu_prio->bitmap);
@@ -346,6 +492,7 @@ int __init spu_sched_init(void)
346 mutex_init(&spu_prio->active_mutex[i]); 492 mutex_init(&spu_prio->active_mutex[i]);
347 INIT_LIST_HEAD(&spu_prio->active_list[i]); 493 INIT_LIST_HEAD(&spu_prio->active_list[i]);
348 } 494 }
495 spin_lock_init(&spu_prio->runq_lock);
349 return 0; 496 return 0;
350} 497}
351 498
@@ -364,4 +511,5 @@ void __exit spu_sched_exit(void)
364 mutex_unlock(&spu_prio->active_mutex[node]); 511 mutex_unlock(&spu_prio->active_mutex[node]);
365 } 512 }
366 kfree(spu_prio); 513 kfree(spu_prio);
514 destroy_workqueue(spu_sched_wq);
367} 515}
diff --git a/arch/powerpc/platforms/cell/spufs/spufs.h b/arch/powerpc/platforms/cell/spufs/spufs.h
index 56864469215e..0c437891dfd5 100644
--- a/arch/powerpc/platforms/cell/spufs/spufs.h
+++ b/arch/powerpc/platforms/cell/spufs/spufs.h
@@ -23,7 +23,7 @@
23#define SPUFS_H 23#define SPUFS_H
24 24
25#include <linux/kref.h> 25#include <linux/kref.h>
26#include <linux/rwsem.h> 26#include <linux/mutex.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/fs.h> 28#include <linux/fs.h>
29 29
@@ -37,11 +37,13 @@ enum {
37}; 37};
38 38
39struct spu_context_ops; 39struct spu_context_ops;
40
41#define SPU_CONTEXT_PREEMPT 0UL
42
43struct spu_gang; 40struct spu_gang;
44 41
42/* ctx->sched_flags */
43enum {
44 SPU_SCHED_WAKE = 0,
45};
46
45struct spu_context { 47struct spu_context {
46 struct spu *spu; /* pointer to a physical SPU */ 48 struct spu *spu; /* pointer to a physical SPU */
47 struct spu_state csa; /* SPU context save area. */ 49 struct spu_state csa; /* SPU context save area. */
@@ -51,10 +53,12 @@ struct spu_context {
51 struct address_space *cntl; /* 'control' area mappings. */ 53 struct address_space *cntl; /* 'control' area mappings. */
52 struct address_space *signal1; /* 'signal1' area mappings. */ 54 struct address_space *signal1; /* 'signal1' area mappings. */
53 struct address_space *signal2; /* 'signal2' area mappings. */ 55 struct address_space *signal2; /* 'signal2' area mappings. */
56 struct address_space *mss; /* 'mss' area mappings. */
57 struct address_space *psmap; /* 'psmap' area mappings. */
54 u64 object_id; /* user space pointer for oprofile */ 58 u64 object_id; /* user space pointer for oprofile */
55 59
56 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state; 60 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
57 struct rw_semaphore state_sema; 61 struct mutex state_mutex;
58 struct semaphore run_sema; 62 struct semaphore run_sema;
59 63
60 struct mm_struct *owner; 64 struct mm_struct *owner;
@@ -75,6 +79,14 @@ struct spu_context {
75 79
76 struct list_head gang_list; 80 struct list_head gang_list;
77 struct spu_gang *gang; 81 struct spu_gang *gang;
82
83 /* scheduler fields */
84 struct list_head rq;
85 struct delayed_work sched_work;
86 unsigned long sched_flags;
87 unsigned long rt_priority;
88 int policy;
89 int prio;
78}; 90};
79 91
80struct spu_gang { 92struct spu_gang {
@@ -159,6 +171,16 @@ void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
159void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx); 171void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
160 172
161/* context management */ 173/* context management */
174static inline void spu_acquire(struct spu_context *ctx)
175{
176 mutex_lock(&ctx->state_mutex);
177}
178
179static inline void spu_release(struct spu_context *ctx)
180{
181 mutex_unlock(&ctx->state_mutex);
182}
183
162struct spu_context * alloc_spu_context(struct spu_gang *gang); 184struct spu_context * alloc_spu_context(struct spu_gang *gang);
163void destroy_spu_context(struct kref *kref); 185void destroy_spu_context(struct kref *kref);
164struct spu_context * get_spu_context(struct spu_context *ctx); 186struct spu_context * get_spu_context(struct spu_context *ctx);
@@ -166,20 +188,18 @@ int put_spu_context(struct spu_context *ctx);
166void spu_unmap_mappings(struct spu_context *ctx); 188void spu_unmap_mappings(struct spu_context *ctx);
167 189
168void spu_forget(struct spu_context *ctx); 190void spu_forget(struct spu_context *ctx);
169void spu_acquire(struct spu_context *ctx); 191int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags);
170void spu_release(struct spu_context *ctx);
171int spu_acquire_runnable(struct spu_context *ctx);
172void spu_acquire_saved(struct spu_context *ctx); 192void spu_acquire_saved(struct spu_context *ctx);
173int spu_acquire_exclusive(struct spu_context *ctx); 193int spu_acquire_exclusive(struct spu_context *ctx);
174 194enum {
175static inline void spu_release_exclusive(struct spu_context *ctx) 195 SPU_ACTIVATE_NOWAKE = 1,
176{ 196};
177 up_write(&ctx->state_sema); 197int spu_activate(struct spu_context *ctx, unsigned long flags);
178}
179
180int spu_activate(struct spu_context *ctx, u64 flags);
181void spu_deactivate(struct spu_context *ctx); 198void spu_deactivate(struct spu_context *ctx);
182void spu_yield(struct spu_context *ctx); 199void spu_yield(struct spu_context *ctx);
200void spu_start_tick(struct spu_context *ctx);
201void spu_stop_tick(struct spu_context *ctx);
202void spu_sched_tick(struct work_struct *work);
183int __init spu_sched_init(void); 203int __init spu_sched_init(void);
184void __exit spu_sched_exit(void); 204void __exit spu_sched_exit(void);
185 205
diff --git a/arch/powerpc/platforms/celleb/htab.c b/arch/powerpc/platforms/celleb/htab.c
index ffa7c2c2030d..279d7339e170 100644
--- a/arch/powerpc/platforms/celleb/htab.c
+++ b/arch/powerpc/platforms/celleb/htab.c
@@ -95,7 +95,6 @@ static long beat_lpar_hpte_insert(unsigned long hpte_group,
95 unsigned long lpar_rc; 95 unsigned long lpar_rc;
96 unsigned long slot; 96 unsigned long slot;
97 unsigned long hpte_v, hpte_r; 97 unsigned long hpte_v, hpte_r;
98 unsigned long flags;
99 98
100 /* same as iseries */ 99 /* same as iseries */
101 if (vflags & HPTE_V_SECONDARY) 100 if (vflags & HPTE_V_SECONDARY)
@@ -115,17 +114,17 @@ static long beat_lpar_hpte_insert(unsigned long hpte_group,
115 if (rflags & (_PAGE_GUARDED|_PAGE_NO_CACHE)) 114 if (rflags & (_PAGE_GUARDED|_PAGE_NO_CACHE))
116 hpte_r &= ~_PAGE_COHERENT; 115 hpte_r &= ~_PAGE_COHERENT;
117 116
118 spin_lock_irqsave(&beat_htab_lock, flags); 117 spin_lock(&beat_htab_lock);
119 if ((lpar_rc = beat_read_mask(hpte_group)) == 0) { 118 if ((lpar_rc = beat_read_mask(hpte_group)) == 0) {
120 if (!(vflags & HPTE_V_BOLTED)) 119 if (!(vflags & HPTE_V_BOLTED))
121 DBG_LOW(" full\n"); 120 DBG_LOW(" full\n");
122 spin_unlock_irqrestore(&beat_htab_lock, flags); 121 spin_unlock(&beat_htab_lock);
123 return -1; 122 return -1;
124 } 123 }
125 124
126 lpar_rc = beat_insert_htab_entry(0, hpte_group, lpar_rc << 48, 125 lpar_rc = beat_insert_htab_entry(0, hpte_group, lpar_rc << 48,
127 hpte_v, hpte_r, &slot); 126 hpte_v, hpte_r, &slot);
128 spin_unlock_irqrestore(&beat_htab_lock, flags); 127 spin_unlock(&beat_htab_lock);
129 128
130 /* 129 /*
131 * Since we try and ioremap PHBs we don't own, the pte insert 130 * Since we try and ioremap PHBs we don't own, the pte insert
@@ -189,7 +188,6 @@ static long beat_lpar_hpte_updatepp(unsigned long slot,
189{ 188{
190 unsigned long lpar_rc; 189 unsigned long lpar_rc;
191 unsigned long dummy0, dummy1, want_v; 190 unsigned long dummy0, dummy1, want_v;
192 unsigned long flags;
193 191
194 want_v = hpte_encode_v(va, psize); 192 want_v = hpte_encode_v(va, psize);
195 193
@@ -197,17 +195,17 @@ static long beat_lpar_hpte_updatepp(unsigned long slot,
197 "avpnv=%016lx, slot=%016lx, psize: %d, newpp %016lx ... ", 195 "avpnv=%016lx, slot=%016lx, psize: %d, newpp %016lx ... ",
198 want_v & HPTE_V_AVPN, slot, psize, newpp); 196 want_v & HPTE_V_AVPN, slot, psize, newpp);
199 197
200 spin_lock_irqsave(&beat_htab_lock, flags); 198 spin_lock(&beat_htab_lock);
201 dummy0 = beat_lpar_hpte_getword0(slot); 199 dummy0 = beat_lpar_hpte_getword0(slot);
202 if ((dummy0 & ~0x7FUL) != (want_v & ~0x7FUL)) { 200 if ((dummy0 & ~0x7FUL) != (want_v & ~0x7FUL)) {
203 DBG_LOW("not found !\n"); 201 DBG_LOW("not found !\n");
204 spin_unlock_irqrestore(&beat_htab_lock, flags); 202 spin_unlock(&beat_htab_lock);
205 return -1; 203 return -1;
206 } 204 }
207 205
208 lpar_rc = beat_write_htab_entry(0, slot, 0, newpp, 0, 7, &dummy0, 206 lpar_rc = beat_write_htab_entry(0, slot, 0, newpp, 0, 7, &dummy0,
209 &dummy1); 207 &dummy1);
210 spin_unlock_irqrestore(&beat_htab_lock, flags); 208 spin_unlock(&beat_htab_lock);
211 if (lpar_rc != 0 || dummy0 == 0) { 209 if (lpar_rc != 0 || dummy0 == 0) {
212 DBG_LOW("not found !\n"); 210 DBG_LOW("not found !\n");
213 return -1; 211 return -1;
@@ -256,18 +254,17 @@ static void beat_lpar_hpte_updateboltedpp(unsigned long newpp,
256 int psize) 254 int psize)
257{ 255{
258 unsigned long lpar_rc, slot, vsid, va, dummy0, dummy1; 256 unsigned long lpar_rc, slot, vsid, va, dummy0, dummy1;
259 unsigned long flags;
260 257
261 vsid = get_kernel_vsid(ea); 258 vsid = get_kernel_vsid(ea);
262 va = (vsid << 28) | (ea & 0x0fffffff); 259 va = (vsid << 28) | (ea & 0x0fffffff);
263 260
264 spin_lock_irqsave(&beat_htab_lock, flags); 261 spin_lock(&beat_htab_lock);
265 slot = beat_lpar_hpte_find(va, psize); 262 slot = beat_lpar_hpte_find(va, psize);
266 BUG_ON(slot == -1); 263 BUG_ON(slot == -1);
267 264
268 lpar_rc = beat_write_htab_entry(0, slot, 0, newpp, 0, 7, 265 lpar_rc = beat_write_htab_entry(0, slot, 0, newpp, 0, 7,
269 &dummy0, &dummy1); 266 &dummy0, &dummy1);
270 spin_unlock_irqrestore(&beat_htab_lock, flags); 267 spin_unlock(&beat_htab_lock);
271 268
272 BUG_ON(lpar_rc != 0); 269 BUG_ON(lpar_rc != 0);
273} 270}
diff --git a/arch/powerpc/platforms/embedded6xx/linkstation.c b/arch/powerpc/platforms/embedded6xx/linkstation.c
index 61599d919ea8..3f6c4114f908 100644
--- a/arch/powerpc/platforms/embedded6xx/linkstation.c
+++ b/arch/powerpc/platforms/embedded6xx/linkstation.c
@@ -13,7 +13,6 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/pci.h> 14#include <linux/pci.h>
15#include <linux/initrd.h> 15#include <linux/initrd.h>
16#include <linux/root_dev.h>
17#include <linux/mtd/physmap.h> 16#include <linux/mtd/physmap.h>
18 17
19#include <asm/time.h> 18#include <asm/time.h>
@@ -91,17 +90,6 @@ static void __init linkstation_setup_arch(void)
91 ARRAY_SIZE(linkstation_physmap_partitions)); 90 ARRAY_SIZE(linkstation_physmap_partitions));
92#endif 91#endif
93 92
94#ifdef CONFIG_BLK_DEV_INITRD
95 if (initrd_start)
96 ROOT_DEV = Root_RAM0;
97 else
98#endif
99#ifdef CONFIG_ROOT_NFS
100 ROOT_DEV = Root_NFS;
101#else
102 ROOT_DEV = Root_HDA1;
103#endif
104
105 /* Lookup PCI host bridges */ 93 /* Lookup PCI host bridges */
106 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;) 94 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
107 add_bridge(np); 95 add_bridge(np);
diff --git a/arch/powerpc/platforms/ps3/spu.c b/arch/powerpc/platforms/ps3/spu.c
index d1929721b0e4..a397e4e17c13 100644
--- a/arch/powerpc/platforms/ps3/spu.c
+++ b/arch/powerpc/platforms/ps3/spu.c
@@ -170,31 +170,6 @@ static int __init construct_spu(struct spu *spu)
170 return result; 170 return result;
171} 171}
172 172
173static int __init add_spu_pages(unsigned long start_addr, unsigned long size)
174{
175 int result;
176 unsigned long start_pfn;
177 unsigned long nr_pages;
178 struct pglist_data *pgdata;
179 struct zone *zone;
180
181 BUG_ON(!mem_init_done);
182
183 start_pfn = start_addr >> PAGE_SHIFT;
184 nr_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
185
186 pgdata = NODE_DATA(0);
187 zone = pgdata->node_zones;
188
189 result = __add_pages(zone, start_pfn, nr_pages);
190
191 if (result)
192 pr_debug("%s:%d: __add_pages failed: (%d)\n",
193 __func__, __LINE__, result);
194
195 return result;
196}
197
198static void spu_unmap(struct spu *spu) 173static void spu_unmap(struct spu *spu)
199{ 174{
200 iounmap(spu->priv2); 175 iounmap(spu->priv2);
@@ -206,19 +181,6 @@ static void spu_unmap(struct spu *spu)
206static int __init setup_areas(struct spu *spu) 181static int __init setup_areas(struct spu *spu)
207{ 182{
208 struct table {char* name; unsigned long addr; unsigned long size;}; 183 struct table {char* name; unsigned long addr; unsigned long size;};
209 int result;
210
211 /* setup pages */
212
213 result = add_spu_pages(spu->local_store_phys, LS_SIZE);
214 if (result)
215 goto fail_add;
216
217 result = add_spu_pages(spu->problem_phys, sizeof(struct spu_problem));
218 if (result)
219 goto fail_add;
220
221 /* ioremap */
222 184
223 spu_pdata(spu)->shadow = __ioremap( 185 spu_pdata(spu)->shadow = __ioremap(
224 spu_pdata(spu)->shadow_addr, sizeof(struct spe_shadow), 186 spu_pdata(spu)->shadow_addr, sizeof(struct spe_shadow),
@@ -260,8 +222,8 @@ static int __init setup_areas(struct spu *spu)
260 222
261fail_ioremap: 223fail_ioremap:
262 spu_unmap(spu); 224 spu_unmap(spu);
263fail_add: 225
264 return result; 226 return -ENOMEM;
265} 227}
266 228
267static int __init setup_interrupts(struct spu *spu) 229static int __init setup_interrupts(struct spu *spu)
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index 69590fbf83da..dc0583bdbc63 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_SMP) += smp.o
9obj-$(CONFIG_XICS) += xics.o 9obj-$(CONFIG_XICS) += xics.o
10obj-$(CONFIG_SCANLOG) += scanlog.o 10obj-$(CONFIG_SCANLOG) += scanlog.o
11obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o 11obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o
12obj-$(CONFIG_KEXEC) += kexec.o
12 13
13obj-$(CONFIG_HOTPLUG_CPU) += hotplug-cpu.o 14obj-$(CONFIG_HOTPLUG_CPU) += hotplug-cpu.o
14 15
diff --git a/arch/powerpc/platforms/pseries/firmware.h b/arch/powerpc/platforms/pseries/firmware.h
deleted file mode 100644
index 714f56f55362..000000000000
--- a/arch/powerpc/platforms/pseries/firmware.h
+++ /dev/null
@@ -1,17 +0,0 @@
1/*
2 * Copyright 2006 IBM Corporation.
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
10#ifndef _PSERIES_FIRMWARE_H
11#define _PSERIES_FIRMWARE_H
12
13#include <asm/firmware.h>
14
15extern void __init fw_feature_init(void);
16
17#endif /* _PSERIES_FIRMWARE_H */
diff --git a/arch/powerpc/platforms/pseries/kexec.c b/arch/powerpc/platforms/pseries/kexec.c
new file mode 100644
index 000000000000..af2685607458
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/kexec.c
@@ -0,0 +1,72 @@
1/*
2 * Copyright 2006 Michael Ellerman, IBM Corporation
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
10#include <asm/machdep.h>
11#include <asm/page.h>
12#include <asm/firmware.h>
13#include <asm/kexec.h>
14#include <asm/mpic.h>
15
16#include "pseries.h"
17#include "xics.h"
18#include "plpar_wrappers.h"
19
20static void pseries_kexec_cpu_down(int crash_shutdown, int secondary)
21{
22 /* Don't risk a hypervisor call if we're crashing */
23 if (firmware_has_feature(FW_FEATURE_SPLPAR) && !crash_shutdown) {
24 unsigned long addr;
25
26 addr = __pa(get_slb_shadow());
27 if (unregister_slb_shadow(hard_smp_processor_id(), addr))
28 printk("SLB shadow buffer deregistration of "
29 "cpu %u (hw_cpu_id %d) failed\n",
30 smp_processor_id(),
31 hard_smp_processor_id());
32
33 addr = __pa(get_lppaca());
34 if (unregister_vpa(hard_smp_processor_id(), addr)) {
35 printk("VPA deregistration of cpu %u (hw_cpu_id %d) "
36 "failed\n", smp_processor_id(),
37 hard_smp_processor_id());
38 }
39 }
40}
41
42static void pseries_kexec_cpu_down_mpic(int crash_shutdown, int secondary)
43{
44 pseries_kexec_cpu_down(crash_shutdown, secondary);
45 mpic_teardown_this_cpu(secondary);
46}
47
48void __init setup_kexec_cpu_down_mpic(void)
49{
50 ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_mpic;
51}
52
53static void pseries_kexec_cpu_down_xics(int crash_shutdown, int secondary)
54{
55 pseries_kexec_cpu_down(crash_shutdown, secondary);
56 xics_teardown_cpu(secondary);
57}
58
59void __init setup_kexec_cpu_down_xics(void)
60{
61 ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_xics;
62}
63
64static int __init pseries_kexec_setup(void)
65{
66 ppc_md.machine_kexec = default_machine_kexec;
67 ppc_md.machine_kexec_prepare = default_machine_kexec_prepare;
68 ppc_md.machine_crash_shutdown = default_machine_crash_shutdown;
69
70 return 0;
71}
72__initcall(pseries_kexec_setup);
diff --git a/arch/powerpc/platforms/pseries/pci.c b/arch/powerpc/platforms/pseries/pci.c
index c69bd15ced9c..fa59124ce3fe 100644
--- a/arch/powerpc/platforms/pseries/pci.c
+++ b/arch/powerpc/platforms/pseries/pci.c
@@ -98,6 +98,10 @@ static void fixup_winbond_82c105(struct pci_dev* dev)
98 if (dev->resource[i].flags & IORESOURCE_IO 98 if (dev->resource[i].flags & IORESOURCE_IO
99 && dev->bus->number == 0 && dev->devfn == 0x81) 99 && dev->bus->number == 0 && dev->devfn == 0x81)
100 dev->resource[i].flags &= ~IORESOURCE_IO; 100 dev->resource[i].flags &= ~IORESOURCE_IO;
101 if (dev->resource[i].start == 0 && dev->resource[i].end) {
102 dev->resource[i].flags = 0;
103 dev->resource[i].end = 0;
104 }
101 } 105 }
102} 106}
103DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105, 107DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,
diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h
new file mode 100644
index 000000000000..b43f1397a5b6
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/pseries.h
@@ -0,0 +1,36 @@
1/*
2 * Copyright 2006 IBM Corporation.
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
10#ifndef _PSERIES_PSERIES_H
11#define _PSERIES_PSERIES_H
12
13extern void __init fw_feature_init(void);
14
15struct pt_regs;
16
17extern int pSeries_system_reset_exception(struct pt_regs *regs);
18extern int pSeries_machine_check_exception(struct pt_regs *regs);
19
20#ifdef CONFIG_SMP
21extern void smp_init_pseries_mpic(void);
22extern void smp_init_pseries_xics(void);
23#else
24static inline smp_init_pseries_mpic(void) { };
25static inline smp_init_pseries_xics(void) { };
26#endif
27
28#ifdef CONFIG_KEXEC
29extern void setup_kexec_cpu_down_xics(void);
30extern void setup_kexec_cpu_down_mpic(void);
31#else
32static inline setup_kexec_cpu_down_xics(void) { };
33static inline setup_kexec_cpu_down_mpic(void) { };
34#endif
35
36#endif /* _PSERIES_PSERIES_H */
diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index b1d3d161249e..edc038873113 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -51,7 +51,7 @@
51#include <asm/udbg.h> 51#include <asm/udbg.h>
52#include <asm/firmware.h> 52#include <asm/firmware.h>
53 53
54#include "ras.h" 54#include "pseries.h"
55 55
56static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX]; 56static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
57static DEFINE_SPINLOCK(ras_log_buf_lock); 57static DEFINE_SPINLOCK(ras_log_buf_lock);
diff --git a/arch/powerpc/platforms/pseries/ras.h b/arch/powerpc/platforms/pseries/ras.h
deleted file mode 100644
index 0e66b0da55e2..000000000000
--- a/arch/powerpc/platforms/pseries/ras.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef _PSERIES_RAS_H
2#define _PSERIES_RAS_H
3
4struct pt_regs;
5
6extern int pSeries_system_reset_exception(struct pt_regs *regs);
7extern int pSeries_machine_check_exception(struct pt_regs *regs);
8
9#endif /* _PSERIES_RAS_H */
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 042ecae107ac..435a04596526 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -55,7 +55,6 @@
55#include <asm/dma.h> 55#include <asm/dma.h>
56#include <asm/machdep.h> 56#include <asm/machdep.h>
57#include <asm/irq.h> 57#include <asm/irq.h>
58#include <asm/kexec.h>
59#include <asm/time.h> 58#include <asm/time.h>
60#include <asm/nvram.h> 59#include <asm/nvram.h>
61#include "xics.h" 60#include "xics.h"
@@ -65,10 +64,10 @@
65#include <asm/i8259.h> 64#include <asm/i8259.h>
66#include <asm/udbg.h> 65#include <asm/udbg.h>
67#include <asm/smp.h> 66#include <asm/smp.h>
67#include <asm/firmware.h>
68 68
69#include "plpar_wrappers.h" 69#include "plpar_wrappers.h"
70#include "ras.h" 70#include "pseries.h"
71#include "firmware.h"
72 71
73#ifdef DEBUG 72#ifdef DEBUG
74#define DBG(fmt...) udbg_printf(fmt) 73#define DBG(fmt...) udbg_printf(fmt)
@@ -77,8 +76,6 @@
77#endif 76#endif
78 77
79/* move those away to a .h */ 78/* move those away to a .h */
80extern void smp_init_pseries_mpic(void);
81extern void smp_init_pseries_xics(void);
82extern void find_udbg_vterm(void); 79extern void find_udbg_vterm(void);
83 80
84int fwnmi_active; /* TRUE if an FWNMI handler is present */ 81int fwnmi_active; /* TRUE if an FWNMI handler is present */
@@ -221,42 +218,6 @@ static void pseries_lpar_enable_pmcs(void)
221 get_lppaca()->pmcregs_in_use = 1; 218 get_lppaca()->pmcregs_in_use = 1;
222} 219}
223 220
224#ifdef CONFIG_KEXEC
225static void pseries_kexec_cpu_down(int crash_shutdown, int secondary)
226{
227 /* Don't risk a hypervisor call if we're crashing */
228 if (firmware_has_feature(FW_FEATURE_SPLPAR) && !crash_shutdown) {
229 unsigned long addr;
230
231 addr = __pa(get_slb_shadow());
232 if (unregister_slb_shadow(hard_smp_processor_id(), addr))
233 printk("SLB shadow buffer deregistration of "
234 "cpu %u (hw_cpu_id %d) failed\n",
235 smp_processor_id(),
236 hard_smp_processor_id());
237
238 addr = __pa(get_lppaca());
239 if (unregister_vpa(hard_smp_processor_id(), addr)) {
240 printk("VPA deregistration of cpu %u (hw_cpu_id %d) "
241 "failed\n", smp_processor_id(),
242 hard_smp_processor_id());
243 }
244 }
245}
246
247static void pseries_kexec_cpu_down_mpic(int crash_shutdown, int secondary)
248{
249 pseries_kexec_cpu_down(crash_shutdown, secondary);
250 mpic_teardown_this_cpu(secondary);
251}
252
253static void pseries_kexec_cpu_down_xics(int crash_shutdown, int secondary)
254{
255 pseries_kexec_cpu_down(crash_shutdown, secondary);
256 xics_teardown_cpu(secondary);
257}
258#endif /* CONFIG_KEXEC */
259
260static void __init pseries_discover_pic(void) 221static void __init pseries_discover_pic(void)
261{ 222{
262 struct device_node *np; 223 struct device_node *np;
@@ -269,21 +230,13 @@ static void __init pseries_discover_pic(void)
269 pSeries_mpic_node = of_node_get(np); 230 pSeries_mpic_node = of_node_get(np);
270 ppc_md.init_IRQ = pseries_mpic_init_IRQ; 231 ppc_md.init_IRQ = pseries_mpic_init_IRQ;
271 ppc_md.get_irq = mpic_get_irq; 232 ppc_md.get_irq = mpic_get_irq;
272#ifdef CONFIG_KEXEC 233 setup_kexec_cpu_down_mpic();
273 ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_mpic;
274#endif
275#ifdef CONFIG_SMP
276 smp_init_pseries_mpic(); 234 smp_init_pseries_mpic();
277#endif
278 return; 235 return;
279 } else if (strstr(typep, "ppc-xicp")) { 236 } else if (strstr(typep, "ppc-xicp")) {
280 ppc_md.init_IRQ = xics_init_IRQ; 237 ppc_md.init_IRQ = xics_init_IRQ;
281#ifdef CONFIG_KEXEC 238 setup_kexec_cpu_down_xics();
282 ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_xics;
283#endif
284#ifdef CONFIG_SMP
285 smp_init_pseries_xics(); 239 smp_init_pseries_xics();
286#endif
287 return; 240 return;
288 } 241 }
289 } 242 }
@@ -554,9 +507,4 @@ define_machine(pseries) {
554 .check_legacy_ioport = pSeries_check_legacy_ioport, 507 .check_legacy_ioport = pSeries_check_legacy_ioport,
555 .system_reset_exception = pSeries_system_reset_exception, 508 .system_reset_exception = pSeries_system_reset_exception,
556 .machine_check_exception = pSeries_machine_check_exception, 509 .machine_check_exception = pSeries_machine_check_exception,
557#ifdef CONFIG_KEXEC
558 .machine_kexec = default_machine_kexec,
559 .machine_kexec_prepare = default_machine_kexec_prepare,
560 .machine_crash_shutdown = default_machine_crash_shutdown,
561#endif
562}; 510};
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index 4408518eaebe..116305b22a2b 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -48,6 +48,7 @@
48#include <asm/vdso_datapage.h> 48#include <asm/vdso_datapage.h>
49 49
50#include "plpar_wrappers.h" 50#include "plpar_wrappers.h"
51#include "pseries.h"
51 52
52#ifdef DEBUG 53#ifdef DEBUG
53#include <asm/udbg.h> 54#include <asm/udbg.h>