blob: b616053bc33119d5a3b6e3523824483f7fe3aea1 [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 Mackerras44aedfe2005-11-18 15:54:12 +110037#include <asm/rtas.h>
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100038
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100039static void __devinit smp_chrp_kick_cpu(int nr)
40{
41 *(unsigned long *)KERNELBASE = nr;
42 asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
43}
44
45static void __devinit smp_chrp_setup_cpu(int cpu_nr)
46{
Paul Mackerras80579e12005-10-27 22:42:04 +100047 mpic_setup_this_cpu();
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100048}
49
50static DEFINE_SPINLOCK(timebase_lock);
51static unsigned int timebase_upper = 0, timebase_lower = 0;
52
53void __devinit smp_chrp_give_timebase(void)
54{
55 spin_lock(&timebase_lock);
56 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
57 timebase_upper = get_tbu();
58 timebase_lower = get_tbl();
59 spin_unlock(&timebase_lock);
60
61 while (timebase_upper || timebase_lower)
62 barrier();
63 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
64}
65
66void __devinit smp_chrp_take_timebase(void)
67{
68 while (!(timebase_upper || timebase_lower))
69 barrier();
70 spin_lock(&timebase_lock);
71 set_tb(timebase_upper, timebase_lower);
72 timebase_upper = 0;
73 timebase_lower = 0;
74 spin_unlock(&timebase_lock);
75 printk("CPU %i taken timebase\n", smp_processor_id());
76}
77
78/* CHRP with openpic */
79struct smp_ops_t chrp_smp_ops = {
Paul Mackerras80579e12005-10-27 22:42:04 +100080 .message_pass = smp_mpic_message_pass,
Paul Mackerras5ad57072005-11-05 10:33:55 +110081 .probe = smp_mpic_probe,
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100082 .kick_cpu = smp_chrp_kick_cpu,
83 .setup_cpu = smp_chrp_setup_cpu,
84 .give_timebase = smp_chrp_give_timebase,
85 .take_timebase = smp_chrp_take_timebase,
86};