blob: 2eb095edb472c213f0cf8a2589a5424913572952 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#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>
Kelly Daly1da44032005-11-01 16:59:20 +110040#include <asm/iseries/hv_call.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/machdep.h>
43#include <asm/cputable.h>
44#include <asm/system.h>
45
46static unsigned long iSeries_smp_message[NR_CPUS];
47
Stephen Rothwellb6b86812005-09-28 03:07:14 +100048void iSeries_smp_message_recv(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 int cpu = smp_processor_id();
51 int msg;
52
Stephen Rothwellb6b86812005-09-28 03:07:14 +100053 if (num_online_cpus() < 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 return;
55
Stephen Rothwellb6b86812005-09-28 03:07:14 +100056 for (msg = 0; msg < 4; msg++)
57 if (test_and_clear_bit(msg, &iSeries_smp_message[cpu]))
58 smp_message_recv(msg, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61static 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
67static 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) {
Stephen Rothwellb6b86812005-09-28 03:07:14 +100075 if ((target == MSG_ALL_BUT_SELF) &&
76 (i == smp_processor_id()))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 continue;
78 smp_iSeries_do_message(i, msg);
79 }
80 }
81}
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static int smp_iSeries_probe(void)
84{
Michael Ellerman95b29382005-09-23 15:03:10 +100085 return cpus_weight(cpu_possible_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
88static void smp_iSeries_kick_cpu(int nr)
89{
Stephen Rothwellb6b86812005-09-28 03:07:14 +100090 BUG_ON((nr < 0) || (nr >= NR_CPUS));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* Verify that our partition has a processor nr */
David Gibson3356bb9f72006-01-13 10:26:42 +110093 if (lppaca[nr].dyn_proc_status >= 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 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
104static void __devinit smp_iSeries_setup_cpu(int nr)
105{
106}
107
108static 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. */
116void __init smp_init_iSeries(void)
117{
118 smp_ops = &iSeries_smp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}