Remove obsolete #include <linux/config.h>
[linux-3.10.git] / arch / powerpc / platforms / chrp / smp.c
1 /*
2  * Smp support for CHRP machines.
3  *
4  * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
5  * deal of code from the sparc and intel versions.
6  *
7  * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
8  *
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/spinlock.h>
20
21 #include <asm/ptrace.h>
22 #include <asm/atomic.h>
23 #include <asm/irq.h>
24 #include <asm/page.h>
25 #include <asm/pgtable.h>
26 #include <asm/sections.h>
27 #include <asm/io.h>
28 #include <asm/prom.h>
29 #include <asm/smp.h>
30 #include <asm/residual.h>
31 #include <asm/time.h>
32 #include <asm/open_pic.h>
33 #include <asm/machdep.h>
34 #include <asm/smp.h>
35 #include <asm/mpic.h>
36 #include <asm/rtas.h>
37
38 static void __devinit smp_chrp_kick_cpu(int nr)
39 {
40         *(unsigned long *)KERNELBASE = nr;
41         asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
42 }
43
44 static void __devinit smp_chrp_setup_cpu(int cpu_nr)
45 {
46         mpic_setup_this_cpu();
47 }
48
49 static DEFINE_SPINLOCK(timebase_lock);
50 static unsigned int timebase_upper = 0, timebase_lower = 0;
51
52 void __devinit smp_chrp_give_timebase(void)
53 {
54         spin_lock(&timebase_lock);
55         rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
56         timebase_upper = get_tbu();
57         timebase_lower = get_tbl();
58         spin_unlock(&timebase_lock);
59
60         while (timebase_upper || timebase_lower)
61                 barrier();
62         rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
63 }
64
65 void __devinit smp_chrp_take_timebase(void)
66 {
67         while (!(timebase_upper || timebase_lower))
68                 barrier();
69         spin_lock(&timebase_lock);
70         set_tb(timebase_upper, timebase_lower);
71         timebase_upper = 0;
72         timebase_lower = 0;
73         spin_unlock(&timebase_lock);
74         printk("CPU %i taken timebase\n", smp_processor_id());
75 }
76
77 /* CHRP with openpic */
78 struct smp_ops_t chrp_smp_ops = {
79         .message_pass = smp_mpic_message_pass,
80         .probe = smp_mpic_probe,
81         .kick_cpu = smp_chrp_kick_cpu,
82         .setup_cpu = smp_chrp_setup_cpu,
83         .give_timebase = smp_chrp_give_timebase,
84         .take_timebase = smp_chrp_take_timebase,
85 };