4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 #include <linux/interrupt.h>
8 #include <linux/profile.h>
9 #include <linux/delay.h>
10 #include <linux/cpu.h>
12 #include <asm/cacheflush.h>
13 #include <asm/tlbflush.h>
18 #define IRQ_CROSS_CALL 15
20 static inline unsigned long
21 swap_ulong(volatile unsigned long *ptr
, unsigned long val
)
23 __asm__
__volatile__("swap [%1], %0\n\t" :
24 "=&r" (val
), "=&r" (ptr
) :
25 "0" (val
), "1" (ptr
));
29 static void smp_setup_percpu_timer(void);
31 void __cpuinit
smp4m_callin(void)
33 int cpuid
= hard_smp_processor_id();
35 local_flush_cache_all();
36 local_flush_tlb_all();
38 notify_cpu_starting(cpuid
);
40 /* Get our local ticker going. */
41 smp_setup_percpu_timer();
44 smp_store_cpu_info(cpuid
);
46 local_flush_cache_all();
47 local_flush_tlb_all();
50 * Unblock the master CPU _only_ when the scheduler state
51 * of all secondary CPUs will be up-to-date, so after
52 * the SMP initialization the master will be just allowed
53 * to call the scheduler code.
55 /* Allow master to continue. */
56 swap_ulong(&cpu_callin_map
[cpuid
], 1);
58 /* XXX: What's up with all the flushes? */
59 local_flush_cache_all();
60 local_flush_tlb_all();
64 /* Fix idle thread fields. */
65 __asm__
__volatile__("ld [%0], %%g6\n\t"
66 : : "r" (¤t_set
[cpuid
])
67 : "memory" /* paranoid */);
69 /* Attach to the address space of init_task. */
70 atomic_inc(&init_mm
.mm_count
);
71 current
->active_mm
= &init_mm
;
73 while (!cpu_isset(cpuid
, smp_commenced_mask
))
78 set_cpu_online(cpuid
, true);
82 * Cycle through the processors asking the PROM to start each one.
84 void __init
smp4m_boot_cpus(void)
86 smp_setup_percpu_timer();
87 local_flush_cache_all();
90 int __cpuinit
smp4m_boot_one_cpu(int i
)
92 unsigned long *entry
= &sun4m_cpu_startup
;
93 struct task_struct
*p
;
97 cpu_find_by_mid(i
, &cpu_node
);
99 /* Cook up an idler for this guy. */
101 current_set
[i
] = task_thread_info(p
);
102 /* See trampoline.S for details... */
103 entry
+= ((i
- 1) * 3);
106 * Initialize the contexts table
107 * Since the call to prom_startcpu() trashes the structure,
108 * we need to re-initialize it for each cpu
110 smp_penguin_ctable
.which_io
= 0;
111 smp_penguin_ctable
.phys_addr
= (unsigned int) srmmu_ctx_table_phys
;
112 smp_penguin_ctable
.reg_size
= 0;
114 /* whirrr, whirrr, whirrrrrrrrr... */
115 printk(KERN_INFO
"Starting CPU %d at %p\n", i
, entry
);
116 local_flush_cache_all();
117 prom_startcpu(cpu_node
, &smp_penguin_ctable
, 0, (char *)entry
);
119 /* wheee... it's going... */
120 for (timeout
= 0; timeout
< 10000; timeout
++) {
121 if (cpu_callin_map
[i
])
126 if (!(cpu_callin_map
[i
])) {
127 printk(KERN_ERR
"Processor %d is stuck.\n", i
);
131 local_flush_cache_all();
135 void __init
smp4m_smp_done(void)
140 /* setup cpu list for irq rotation */
143 for_each_online_cpu(i
) {
145 prev
= &cpu_data(i
).next
;
148 local_flush_cache_all();
150 /* Ok, they are spinning and ready to go. */
153 static struct smp_funcall
{
160 unsigned long processors_in
[SUN4M_NCPUS
]; /* Set when ipi entered. */
161 unsigned long processors_out
[SUN4M_NCPUS
]; /* Set when ipi exited. */
164 static DEFINE_SPINLOCK(cross_call_lock
);
166 /* Cross calls must be serialized, at least currently. */
167 static void smp4m_cross_call(smpfunc_t func
, cpumask_t mask
, unsigned long arg1
,
168 unsigned long arg2
, unsigned long arg3
,
171 register int ncpus
= SUN4M_NCPUS
;
174 spin_lock_irqsave(&cross_call_lock
, flags
);
176 /* Init function glue. */
177 ccall_info
.func
= func
;
178 ccall_info
.arg1
= arg1
;
179 ccall_info
.arg2
= arg2
;
180 ccall_info
.arg3
= arg3
;
181 ccall_info
.arg4
= arg4
;
184 /* Init receive/complete mapping, plus fire the IPI's off. */
188 cpu_clear(smp_processor_id(), mask
);
189 cpus_and(mask
, cpu_online_map
, mask
);
190 for (i
= 0; i
< ncpus
; i
++) {
191 if (cpu_isset(i
, mask
)) {
192 ccall_info
.processors_in
[i
] = 0;
193 ccall_info
.processors_out
[i
] = 0;
194 set_cpu_int(i
, IRQ_CROSS_CALL
);
196 ccall_info
.processors_in
[i
] = 1;
197 ccall_info
.processors_out
[i
] = 1;
207 if (!cpu_isset(i
, mask
))
209 while (!ccall_info
.processors_in
[i
])
211 } while (++i
< ncpus
);
215 if (!cpu_isset(i
, mask
))
217 while (!ccall_info
.processors_out
[i
])
219 } while (++i
< ncpus
);
221 spin_unlock_irqrestore(&cross_call_lock
, flags
);
224 /* Running cross calls. */
225 void smp4m_cross_call_irq(void)
227 int i
= smp_processor_id();
229 ccall_info
.processors_in
[i
] = 1;
230 ccall_info
.func(ccall_info
.arg1
, ccall_info
.arg2
, ccall_info
.arg3
,
231 ccall_info
.arg4
, ccall_info
.arg5
);
232 ccall_info
.processors_out
[i
] = 1;
235 void smp4m_percpu_timer_interrupt(struct pt_regs
*regs
)
237 struct pt_regs
*old_regs
;
238 int cpu
= smp_processor_id();
240 old_regs
= set_irq_regs(regs
);
242 sun4m_clear_profile_irq(cpu
);
244 profile_tick(CPU_PROFILING
);
246 if (!--prof_counter(cpu
)) {
247 int user
= user_mode(regs
);
250 update_process_times(user
);
253 prof_counter(cpu
) = prof_multiplier(cpu
);
255 set_irq_regs(old_regs
);
258 static void __cpuinit
smp_setup_percpu_timer(void)
260 int cpu
= smp_processor_id();
262 prof_counter(cpu
) = prof_multiplier(cpu
) = 1;
263 load_profile_irq(cpu
, lvl14_resolution
);
265 if (cpu
== boot_cpu_id
)
266 sun4m_unmask_profile_irq();
269 static void __init
smp4m_blackbox_id(unsigned *addr
)
271 int rd
= *addr
& 0x3e000000;
274 addr
[0] = 0x81580000 | rd
; /* rd %tbr, reg */
275 addr
[1] = 0x8130200c | rd
| rs1
; /* srl reg, 0xc, reg */
276 addr
[2] = 0x80082003 | rd
| rs1
; /* and reg, 3, reg */
279 static void __init
smp4m_blackbox_current(unsigned *addr
)
281 int rd
= *addr
& 0x3e000000;
284 addr
[0] = 0x81580000 | rd
; /* rd %tbr, reg */
285 addr
[2] = 0x8130200a | rd
| rs1
; /* srl reg, 0xa, reg */
286 addr
[4] = 0x8008200c | rd
| rs1
; /* and reg, 0xc, reg */
289 void __init
sun4m_init_smp(void)
291 BTFIXUPSET_BLACKBOX(hard_smp_processor_id
, smp4m_blackbox_id
);
292 BTFIXUPSET_BLACKBOX(load_current
, smp4m_blackbox_current
);
293 BTFIXUPSET_CALL(smp_cross_call
, smp4m_cross_call
, BTFIXUPCALL_NORM
);
294 BTFIXUPSET_CALL(__hard_smp_processor_id
, __smp4m_processor_id
, BTFIXUPCALL_NORM
);
This page took 0.041798 seconds and 5 git commands to generate.