blob: 10a4a4d063b6411b04db150f4bd00980aa67a6ee [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
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100011#include <linux/kernel.h>
12#include <linux/sched.h>
13#include <linux/smp.h>
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100014#include <linux/interrupt.h>
15#include <linux/kernel_stat.h>
16#include <linux/delay.h>
17#include <linux/init.h>
18#include <linux/spinlock.h>
19
20#include <asm/ptrace.h>
21#include <asm/atomic.h>
22#include <asm/irq.h>
23#include <asm/page.h>
24#include <asm/pgtable.h>
25#include <asm/sections.h>
26#include <asm/io.h>
27#include <asm/prom.h>
28#include <asm/smp.h>
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100029#include <asm/time.h>
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100030#include <asm/machdep.h>
Paul Mackerras80579e12005-10-27 22:42:04 +100031#include <asm/mpic.h>
Paul Mackerras44aedfe2005-11-18 15:54:12 +110032#include <asm/rtas.h>
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100033
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100034static void __devinit smp_chrp_kick_cpu(int nr)
35{
36 *(unsigned long *)KERNELBASE = nr;
37 asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
38}
39
40static void __devinit smp_chrp_setup_cpu(int cpu_nr)
41{
Paul Mackerras80579e12005-10-27 22:42:04 +100042 mpic_setup_this_cpu();
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100043}
44
45static DEFINE_SPINLOCK(timebase_lock);
46static unsigned int timebase_upper = 0, timebase_lower = 0;
47
48void __devinit smp_chrp_give_timebase(void)
49{
50 spin_lock(&timebase_lock);
51 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
52 timebase_upper = get_tbu();
53 timebase_lower = get_tbl();
54 spin_unlock(&timebase_lock);
55
56 while (timebase_upper || timebase_lower)
57 barrier();
58 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
59}
60
61void __devinit smp_chrp_take_timebase(void)
62{
63 while (!(timebase_upper || timebase_lower))
64 barrier();
65 spin_lock(&timebase_lock);
66 set_tb(timebase_upper, timebase_lower);
67 timebase_upper = 0;
68 timebase_lower = 0;
69 spin_unlock(&timebase_lock);
70 printk("CPU %i taken timebase\n", smp_processor_id());
71}
72
73/* CHRP with openpic */
74struct smp_ops_t chrp_smp_ops = {
Paul Mackerras80579e12005-10-27 22:42:04 +100075 .message_pass = smp_mpic_message_pass,
Paul Mackerras5ad57072005-11-05 10:33:55 +110076 .probe = smp_mpic_probe,
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100077 .kick_cpu = smp_chrp_kick_cpu,
78 .setup_cpu = smp_chrp_setup_cpu,
79 .give_timebase = smp_chrp_give_timebase,
80 .take_timebase = smp_chrp_take_timebase,
81};