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