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/switch_to.h>
14 #include <asm/tlbflush.h>
19 #define IRQ_IPI_SINGLE 12
20 #define IRQ_IPI_MASK 13
21 #define IRQ_IPI_RESCHED 14
22 #define IRQ_CROSS_CALL 15
24 static inline unsigned long
25 swap_ulong(volatile unsigned long *ptr
, unsigned long val
)
27 __asm__
__volatile__("swap [%1], %0\n\t" :
28 "=&r" (val
), "=&r" (ptr
) :
29 "0" (val
), "1" (ptr
));
33 static void smp4m_ipi_init(void);
34 static void smp_setup_percpu_timer(void);
36 void __cpuinit
smp4m_callin(void)
38 int cpuid
= hard_smp_processor_id();
40 local_flush_cache_all();
41 local_flush_tlb_all();
43 notify_cpu_starting(cpuid
);
45 /* Get our local ticker going. */
46 smp_setup_percpu_timer();
49 smp_store_cpu_info(cpuid
);
51 local_flush_cache_all();
52 local_flush_tlb_all();
55 * Unblock the master CPU _only_ when the scheduler state
56 * of all secondary CPUs will be up-to-date, so after
57 * the SMP initialization the master will be just allowed
58 * to call the scheduler code.
60 /* Allow master to continue. */
61 swap_ulong(&cpu_callin_map
[cpuid
], 1);
63 /* XXX: What's up with all the flushes? */
64 local_flush_cache_all();
65 local_flush_tlb_all();
67 /* Fix idle thread fields. */
68 __asm__
__volatile__("ld [%0], %%g6\n\t"
69 : : "r" (¤t_set
[cpuid
])
70 : "memory" /* paranoid */);
72 /* Attach to the address space of init_task. */
73 atomic_inc(&init_mm
.mm_count
);
74 current
->active_mm
= &init_mm
;
76 while (!cpumask_test_cpu(cpuid
, &smp_commenced_mask
))
81 set_cpu_online(cpuid
, true);
85 * Cycle through the processors asking the PROM to start each one.
87 void __init
smp4m_boot_cpus(void)
90 smp_setup_percpu_timer();
91 local_flush_cache_all();
94 int __cpuinit
smp4m_boot_one_cpu(int i
, struct task_struct
*idle
)
96 unsigned long *entry
= &sun4m_cpu_startup
;
100 cpu_find_by_mid(i
, &cpu_node
);
101 current_set
[i
] = task_thread_info(idle
);
103 /* See trampoline.S for details... */
104 entry
+= ((i
- 1) * 3);
107 * Initialize the contexts table
108 * Since the call to prom_startcpu() trashes the structure,
109 * we need to re-initialize it for each cpu
111 smp_penguin_ctable
.which_io
= 0;
112 smp_penguin_ctable
.phys_addr
= (unsigned int) srmmu_ctx_table_phys
;
113 smp_penguin_ctable
.reg_size
= 0;
115 /* whirrr, whirrr, whirrrrrrrrr... */
116 printk(KERN_INFO
"Starting CPU %d at %p\n", i
, entry
);
117 local_flush_cache_all();
118 prom_startcpu(cpu_node
, &smp_penguin_ctable
, 0, (char *)entry
);
120 /* wheee... it's going... */
121 for (timeout
= 0; timeout
< 10000; timeout
++) {
122 if (cpu_callin_map
[i
])
127 if (!(cpu_callin_map
[i
])) {
128 printk(KERN_ERR
"Processor %d is stuck.\n", i
);
132 local_flush_cache_all();
136 void __init
smp4m_smp_done(void)
141 /* setup cpu list for irq rotation */
144 for_each_online_cpu(i
) {
146 prev
= &cpu_data(i
).next
;
149 local_flush_cache_all();
151 /* Ok, they are spinning and ready to go. */
155 /* Initialize IPIs on the SUN4M SMP machine */
156 static void __init
smp4m_ipi_init(void)
160 static void smp4m_ipi_resched(int cpu
)
162 set_cpu_int(cpu
, IRQ_IPI_RESCHED
);
165 static void smp4m_ipi_single(int cpu
)
167 set_cpu_int(cpu
, IRQ_IPI_SINGLE
);
170 static void smp4m_ipi_mask_one(int cpu
)
172 set_cpu_int(cpu
, IRQ_IPI_MASK
);
175 static struct smp_funcall
{
182 unsigned long processors_in
[SUN4M_NCPUS
]; /* Set when ipi entered. */
183 unsigned long processors_out
[SUN4M_NCPUS
]; /* Set when ipi exited. */
186 static DEFINE_SPINLOCK(cross_call_lock
);
188 /* Cross calls must be serialized, at least currently. */
189 static void smp4m_cross_call(smpfunc_t func
, cpumask_t mask
, unsigned long arg1
,
190 unsigned long arg2
, unsigned long arg3
,
193 register int ncpus
= SUN4M_NCPUS
;
196 spin_lock_irqsave(&cross_call_lock
, flags
);
198 /* Init function glue. */
199 ccall_info
.func
= func
;
200 ccall_info
.arg1
= arg1
;
201 ccall_info
.arg2
= arg2
;
202 ccall_info
.arg3
= arg3
;
203 ccall_info
.arg4
= arg4
;
206 /* Init receive/complete mapping, plus fire the IPI's off. */
210 cpumask_clear_cpu(smp_processor_id(), &mask
);
211 cpumask_and(&mask
, cpu_online_mask
, &mask
);
212 for (i
= 0; i
< ncpus
; i
++) {
213 if (cpumask_test_cpu(i
, &mask
)) {
214 ccall_info
.processors_in
[i
] = 0;
215 ccall_info
.processors_out
[i
] = 0;
216 set_cpu_int(i
, IRQ_CROSS_CALL
);
218 ccall_info
.processors_in
[i
] = 1;
219 ccall_info
.processors_out
[i
] = 1;
229 if (!cpumask_test_cpu(i
, &mask
))
231 while (!ccall_info
.processors_in
[i
])
233 } while (++i
< ncpus
);
237 if (!cpumask_test_cpu(i
, &mask
))
239 while (!ccall_info
.processors_out
[i
])
241 } while (++i
< ncpus
);
243 spin_unlock_irqrestore(&cross_call_lock
, flags
);
246 /* Running cross calls. */
247 void smp4m_cross_call_irq(void)
249 int i
= smp_processor_id();
251 ccall_info
.processors_in
[i
] = 1;
252 ccall_info
.func(ccall_info
.arg1
, ccall_info
.arg2
, ccall_info
.arg3
,
253 ccall_info
.arg4
, ccall_info
.arg5
);
254 ccall_info
.processors_out
[i
] = 1;
257 void smp4m_percpu_timer_interrupt(struct pt_regs
*regs
)
259 struct pt_regs
*old_regs
;
260 int cpu
= smp_processor_id();
262 old_regs
= set_irq_regs(regs
);
264 sun4m_clear_profile_irq(cpu
);
266 profile_tick(CPU_PROFILING
);
268 if (!--prof_counter(cpu
)) {
269 int user
= user_mode(regs
);
272 update_process_times(user
);
275 prof_counter(cpu
) = prof_multiplier(cpu
);
277 set_irq_regs(old_regs
);
280 static void __cpuinit
smp_setup_percpu_timer(void)
282 int cpu
= smp_processor_id();
284 prof_counter(cpu
) = prof_multiplier(cpu
) = 1;
285 load_profile_irq(cpu
, lvl14_resolution
);
287 if (cpu
== boot_cpu_id
)
288 sun4m_unmask_profile_irq();
291 static void __init
smp4m_blackbox_id(unsigned *addr
)
293 int rd
= *addr
& 0x3e000000;
296 addr
[0] = 0x81580000 | rd
; /* rd %tbr, reg */
297 addr
[1] = 0x8130200c | rd
| rs1
; /* srl reg, 0xc, reg */
298 addr
[2] = 0x80082003 | rd
| rs1
; /* and reg, 3, reg */
301 static void __init
smp4m_blackbox_current(unsigned *addr
)
303 int rd
= *addr
& 0x3e000000;
306 addr
[0] = 0x81580000 | rd
; /* rd %tbr, reg */
307 addr
[2] = 0x8130200a | rd
| rs1
; /* srl reg, 0xa, reg */
308 addr
[4] = 0x8008200c | rd
| rs1
; /* and reg, 0xc, reg */
311 void __init
sun4m_init_smp(void)
313 BTFIXUPSET_BLACKBOX(hard_smp_processor_id
, smp4m_blackbox_id
);
314 BTFIXUPSET_BLACKBOX(load_current
, smp4m_blackbox_current
);
315 BTFIXUPSET_CALL(smp_cross_call
, smp4m_cross_call
, BTFIXUPCALL_NORM
);
316 BTFIXUPSET_CALL(__hard_smp_processor_id
, __smp4m_processor_id
, BTFIXUPCALL_NORM
);
317 BTFIXUPSET_CALL(smp_ipi_resched
, smp4m_ipi_resched
, BTFIXUPCALL_NORM
);
318 BTFIXUPSET_CALL(smp_ipi_single
, smp4m_ipi_single
, BTFIXUPCALL_NORM
);
319 BTFIXUPSET_CALL(smp_ipi_mask_one
, smp4m_ipi_mask_one
, BTFIXUPCALL_NORM
);
This page took 0.037477 seconds and 5 git commands to generate.