blob: bb2315997d4560363b2d9bf0a7f8340afb3bd328 [file] [log] [blame]
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +10001/*
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/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>
21
22#include <asm/ptrace.h>
23#include <asm/atomic.h>
24#include <asm/irq.h>
25#include <asm/page.h>
26#include <asm/pgtable.h>
27#include <asm/sections.h>
28#include <asm/io.h>
29#include <asm/prom.h>
30#include <asm/smp.h>
31#include <asm/residual.h>
32#include <asm/time.h>
33#include <asm/open_pic.h>
34#include <asm/machdep.h>
Paul Mackerras80579e12005-10-27 22:42:04 +100035#include <asm/smp.h>
36#include <asm/mpic.h>
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100037
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100038static 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
44static void __devinit smp_chrp_setup_cpu(int cpu_nr)
45{
Paul Mackerras80579e12005-10-27 22:42:04 +100046 mpic_setup_this_cpu();
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100047}
48
49static DEFINE_SPINLOCK(timebase_lock);
50static unsigned int timebase_upper = 0, timebase_lower = 0;
51
52void __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
65void __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 */
78struct smp_ops_t chrp_smp_ops = {
Paul Mackerras80579e12005-10-27 22:42:04 +100079 .message_pass = smp_mpic_message_pass,
Paul Mackerras5ad57072005-11-05 10:33:55 +110080 .probe = smp_mpic_probe,
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100081 .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};