Pull kmalloc into release branch
[pandora-kernel.git] / arch / powerpc / platforms / iseries / smp.c
1 /*
2  * SMP support for iSeries machines.
3  *
4  * Dave Engebretsen, Peter Bergner, and
5  * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
6  *
7  * Plus various changes from other IBM teams...
8  *
9  *      This program is free software; you can redistribute it and/or
10  *      modify it under the terms of the GNU General Public License
11  *      as published by the Free Software Foundation; either version
12  *      2 of the License, or (at your option) any later version.
13  */
14
15 #undef DEBUG
16
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/interrupt.h>
23 #include <linux/kernel_stat.h>
24 #include <linux/delay.h>
25 #include <linux/init.h>
26 #include <linux/spinlock.h>
27 #include <linux/cache.h>
28 #include <linux/err.h>
29 #include <linux/sysdev.h>
30 #include <linux/cpu.h>
31
32 #include <asm/ptrace.h>
33 #include <asm/atomic.h>
34 #include <asm/irq.h>
35 #include <asm/page.h>
36 #include <asm/pgtable.h>
37 #include <asm/io.h>
38 #include <asm/smp.h>
39 #include <asm/paca.h>
40 #include <asm/iseries/hv_call.h>
41 #include <asm/time.h>
42 #include <asm/machdep.h>
43 #include <asm/cputable.h>
44 #include <asm/system.h>
45
46 static unsigned long iSeries_smp_message[NR_CPUS];
47
48 void iSeries_smp_message_recv(struct pt_regs *regs)
49 {
50         int cpu = smp_processor_id();
51         int msg;
52
53         if (num_online_cpus() < 2)
54                 return;
55
56         for (msg = 0; msg < 4; msg++)
57                 if (test_and_clear_bit(msg, &iSeries_smp_message[cpu]))
58                         smp_message_recv(msg, regs);
59 }
60
61 static inline void smp_iSeries_do_message(int cpu, int msg)
62 {
63         set_bit(msg, &iSeries_smp_message[cpu]);
64         HvCall_sendIPI(&(paca[cpu]));
65 }
66
67 static void smp_iSeries_message_pass(int target, int msg)
68 {
69         int i;
70
71         if (target < NR_CPUS)
72                 smp_iSeries_do_message(target, msg);
73         else {
74                 for_each_online_cpu(i) {
75                         if ((target == MSG_ALL_BUT_SELF) &&
76                                         (i == smp_processor_id()))
77                                 continue;
78                         smp_iSeries_do_message(i, msg);
79                 }
80         }
81 }
82
83 static int smp_iSeries_probe(void)
84 {
85         return cpus_weight(cpu_possible_map);
86 }
87
88 static void smp_iSeries_kick_cpu(int nr)
89 {
90         BUG_ON((nr < 0) || (nr >= NR_CPUS));
91
92         /* Verify that our partition has a processor nr */
93         if (lppaca[nr].dyn_proc_status >= 2)
94                 return;
95
96         /* The processor is currently spinning, waiting
97          * for the cpu_start field to become non-zero
98          * After we set cpu_start, the processor will
99          * continue on to secondary_start in iSeries_head.S
100          */
101         paca[nr].cpu_start = 1;
102 }
103
104 static void __devinit smp_iSeries_setup_cpu(int nr)
105 {
106 }
107
108 static struct smp_ops_t iSeries_smp_ops = {
109         .message_pass = smp_iSeries_message_pass,
110         .probe        = smp_iSeries_probe,
111         .kick_cpu     = smp_iSeries_kick_cpu,
112         .setup_cpu    = smp_iSeries_setup_cpu,
113 };
114
115 /* This is called very early. */
116 void __init smp_init_iSeries(void)
117 {
118         smp_ops = &iSeries_smp_ops;
119 }