1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#undef DEBUG
16
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/smp.h>
20#include <linux/interrupt.h>
21#include <linux/delay.h>
22#include <linux/init.h>
23#include <linux/spinlock.h>
24#include <linux/cache.h>
25#include <linux/err.h>
26#include <linux/device.h>
27#include <linux/cpu.h>
28
29#include <asm/ptrace.h>
30#include <linux/atomic.h>
31#include <asm/irq.h>
32#include <asm/page.h>
33#include <asm/pgtable.h>
34#include <asm/io.h>
35#include <asm/prom.h>
36#include <asm/smp.h>
37#include <asm/paca.h>
38#include <asm/machdep.h>
39#include <asm/cputable.h>
40#include <asm/firmware.h>
41#include <asm/rtas.h>
42#include <asm/cputhreads.h>
43#include <asm/code-patching.h>
44
45#include "interrupt.h"
46#include <asm/udbg.h>
47
48#ifdef DEBUG
49#define DBG(fmt...) udbg_printf(fmt)
50#else
51#define DBG(fmt...)
52#endif
53
54
55
56
57
58static cpumask_t of_spin_map;
59
60
61
62
63
64
65
66
67
68
69
70
71static inline int smp_startup_cpu(unsigned int lcpu)
72{
73 int status;
74 unsigned long start_here =
75 __pa(ppc_function_entry(generic_secondary_smp_init));
76 unsigned int pcpu;
77 int start_cpu;
78
79 if (cpumask_test_cpu(lcpu, &of_spin_map))
80
81 return 1;
82
83 pcpu = get_hard_smp_processor_id(lcpu);
84
85
86 task_thread_info(paca[lcpu].__current)->preempt_count = 0;
87
88
89
90
91
92 start_cpu = rtas_token("start-cpu");
93 if (start_cpu == RTAS_UNKNOWN_SERVICE)
94 return 1;
95
96 status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
97 if (status != 0) {
98 printk(KERN_ERR "start-cpu failed: %i\n", status);
99 return 0;
100 }
101
102 return 1;
103}
104
105static void smp_cell_setup_cpu(int cpu)
106{
107 if (cpu != boot_cpuid)
108 iic_setup_cpu();
109
110
111
112
113 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
114}
115
116static int smp_cell_kick_cpu(int nr)
117{
118 BUG_ON(nr < 0 || nr >= NR_CPUS);
119
120 if (!smp_startup_cpu(nr))
121 return -ENOENT;
122
123
124
125
126
127
128 paca[nr].cpu_start = 1;
129
130 return 0;
131}
132
133static struct smp_ops_t bpa_iic_smp_ops = {
134 .message_pass = iic_message_pass,
135 .probe = iic_request_IPIs,
136 .kick_cpu = smp_cell_kick_cpu,
137 .setup_cpu = smp_cell_setup_cpu,
138 .cpu_bootable = smp_generic_cpu_bootable,
139};
140
141
142void __init smp_init_cell(void)
143{
144 int i;
145
146 DBG(" -> smp_init_cell()\n");
147
148 smp_ops = &bpa_iic_smp_ops;
149
150
151 if (cpu_has_feature(CPU_FTR_SMT)) {
152 for_each_present_cpu(i) {
153 if (cpu_thread_in_core(i) == 0)
154 cpumask_set_cpu(i, &of_spin_map);
155 }
156 } else
157 cpumask_copy(&of_spin_map, cpu_present_mask);
158
159 cpumask_clear_cpu(boot_cpuid, &of_spin_map);
160
161
162 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
163 smp_ops->give_timebase = rtas_give_timebase;
164 smp_ops->take_timebase = rtas_take_timebase;
165 }
166
167 DBG(" <- smp_init_cell()\n");
168}
169