Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / powerpc / kernel / dbell.c
CommitLineData
620165f9
KG
1/*
2 * Author: Kumar Gala <galak@kernel.crashing.org>
3 *
4 * Copyright 2009 Freescale Semiconductor Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/smp.h>
15#include <linux/threads.h>
b9f1cd71 16#include <linux/percpu.h>
620165f9
KG
17
18#include <asm/dbell.h>
0e37d259 19#include <asm/irq_regs.h>
620165f9
KG
20
21#ifdef CONFIG_SMP
b9f1cd71
BH
22struct doorbell_cpu_info {
23 unsigned long messages; /* current messages bits */
24 unsigned int tag; /* tag value */
25};
620165f9 26
b9f1cd71
BH
27static DEFINE_PER_CPU(struct doorbell_cpu_info, doorbell_cpu_info);
28
29void doorbell_setup_this_cpu(void)
30{
31 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
32
33 info->messages = 0;
34 info->tag = mfspr(SPRN_PIR) & 0x3fff;
35}
36
37void doorbell_message_pass(int target, int msg)
620165f9 38{
b9f1cd71 39 struct doorbell_cpu_info *info;
620165f9
KG
40 int i;
41
b9f1cd71
BH
42 if (target < NR_CPUS) {
43 info = &per_cpu(doorbell_cpu_info, target);
44 set_bit(msg, &info->messages);
45 ppc_msgsnd(PPC_DBELL, 0, info->tag);
620165f9 46 }
b9f1cd71 47 else if (target == MSG_ALL_BUT_SELF) {
620165f9
KG
48 for_each_online_cpu(i) {
49 if (i == smp_processor_id())
50 continue;
b9f1cd71
BH
51 info = &per_cpu(doorbell_cpu_info, i);
52 set_bit(msg, &info->messages);
53 ppc_msgsnd(PPC_DBELL, 0, info->tag);
620165f9
KG
54 }
55 }
56 else { /* target == MSG_ALL */
b9f1cd71
BH
57 for_each_online_cpu(i) {
58 info = &per_cpu(doorbell_cpu_info, i);
59 set_bit(msg, &info->messages);
60 }
620165f9
KG
61 ppc_msgsnd(PPC_DBELL, PPC_DBELL_MSG_BRDCAST, 0);
62 }
63}
e3145b38
BH
64
65void doorbell_exception(struct pt_regs *regs)
66{
0e37d259 67 struct pt_regs *old_regs = set_irq_regs(regs);
b9f1cd71 68 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
e3145b38
BH
69 int msg;
70
b9f1cd71
BH
71 /* Warning: regs can be NULL when called from irq enable */
72
73 if (!info->messages || (num_online_cpus() < 2))
0e37d259 74 goto out;
e3145b38
BH
75
76 for (msg = 0; msg < 4; msg++)
b9f1cd71 77 if (test_and_clear_bit(msg, &info->messages))
e3145b38 78 smp_message_recv(msg);
0e37d259
DG
79
80out:
81 set_irq_regs(old_regs);
e3145b38
BH
82}
83
850f22d5
ME
84void doorbell_check_self(void)
85{
86 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
87
88 if (!info->messages)
89 return;
90
91 ppc_msgsnd(PPC_DBELL, 0, info->tag);
92}
93
e3145b38
BH
94#else /* CONFIG_SMP */
95void doorbell_exception(struct pt_regs *regs)
96{
97 printk(KERN_WARNING "Received doorbell on non-smp system\n");
98}
99#endif /* CONFIG_SMP */
100