2 * Smp support for CHRP machines.
4 * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
5 * deal of code from the sparc and intel versions.
7 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/delay.h>
19 #include <linux/init.h>
20 #include <linux/spinlock.h>
22 #include <asm/ptrace.h>
23 #include <asm/atomic.h>
26 #include <asm/pgtable.h>
27 #include <asm/sections.h>
31 #include <asm/residual.h>
33 #include <asm/open_pic.h>
34 #include <asm/machdep.h>
38 extern unsigned long smp_chrp_cpu_nr;
40 static int __init smp_chrp_probe(void)
42 struct device_node *cpus = NULL;
49 /* Count CPUs in the device-tree */
50 cpuid = 1; /* the boot cpu is logical cpu 0 */
51 while ((cpus = of_find_node_by_type(cpus, "cpu")) != NULL) {
53 reg = (unsigned int *) get_property(cpus, "reg", ®len);
54 if (reg && reglen >= sizeof(unsigned int))
55 /* hmmm, not having a reg property would be bad */
57 if (phys != boot_cpuid_phys) {
58 set_hard_smp_processor_id(cpuid, phys);
64 printk(KERN_INFO "CHRP SMP probe found %d cpus\n", ncpus);
66 /* Nothing more to do if less than 2 of them */
75 static void __devinit smp_chrp_kick_cpu(int nr)
77 *(unsigned long *)KERNELBASE = nr;
78 asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
81 static void __devinit smp_chrp_setup_cpu(int cpu_nr)
83 mpic_setup_this_cpu();
86 static DEFINE_SPINLOCK(timebase_lock);
87 static unsigned int timebase_upper = 0, timebase_lower = 0;
89 void __devinit smp_chrp_give_timebase(void)
91 spin_lock(&timebase_lock);
92 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
93 timebase_upper = get_tbu();
94 timebase_lower = get_tbl();
95 spin_unlock(&timebase_lock);
97 while (timebase_upper || timebase_lower)
99 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
102 void __devinit smp_chrp_take_timebase(void)
104 while (!(timebase_upper || timebase_lower))
106 spin_lock(&timebase_lock);
107 set_tb(timebase_upper, timebase_lower);
110 spin_unlock(&timebase_lock);
111 printk("CPU %i taken timebase\n", smp_processor_id());
114 /* CHRP with openpic */
115 struct smp_ops_t chrp_smp_ops = {
116 .message_pass = smp_mpic_message_pass,
117 .probe = smp_chrp_probe,
118 .kick_cpu = smp_chrp_kick_cpu,
119 .setup_cpu = smp_chrp_setup_cpu,
120 .give_timebase = smp_chrp_give_timebase,
121 .take_timebase = smp_chrp_take_timebase,