blob: 3307a52d797fb682269723b240d05402aad26fe1 [file] [log] [blame]
Kumar Gala620165f2009-02-12 13:54:53 +00001/*
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>
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100016#include <linux/percpu.h>
Kumar Gala620165f2009-02-12 13:54:53 +000017
18#include <asm/dbell.h>
David Gibson0e37d252010-07-09 15:32:30 +100019#include <asm/irq_regs.h>
Kumar Gala620165f2009-02-12 13:54:53 +000020
21#ifdef CONFIG_SMP
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100022struct doorbell_cpu_info {
23 unsigned long messages; /* current messages bits */
24 unsigned int tag; /* tag value */
25};
Kumar Gala620165f2009-02-12 13:54:53 +000026
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100027static DEFINE_PER_CPU(struct doorbell_cpu_info, doorbell_cpu_info);
28
29void doorbell_setup_this_cpu(void)
Kumar Gala620165f2009-02-12 13:54:53 +000030{
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100031 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)
38{
39 struct doorbell_cpu_info *info;
Kumar Gala620165f2009-02-12 13:54:53 +000040 int i;
41
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100042 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);
Kumar Gala620165f2009-02-12 13:54:53 +000046 }
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100047 else if (target == MSG_ALL_BUT_SELF) {
Kumar Gala620165f2009-02-12 13:54:53 +000048 for_each_online_cpu(i) {
49 if (i == smp_processor_id())
50 continue;
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100051 info = &per_cpu(doorbell_cpu_info, i);
52 set_bit(msg, &info->messages);
53 ppc_msgsnd(PPC_DBELL, 0, info->tag);
Kumar Gala620165f2009-02-12 13:54:53 +000054 }
55 }
56 else { /* target == MSG_ALL */
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100057 for_each_online_cpu(i) {
58 info = &per_cpu(doorbell_cpu_info, i);
59 set_bit(msg, &info->messages);
60 }
Kumar Gala620165f2009-02-12 13:54:53 +000061 ppc_msgsnd(PPC_DBELL, PPC_DBELL_MSG_BRDCAST, 0);
62 }
63}
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100064
65void doorbell_exception(struct pt_regs *regs)
66{
David Gibson0e37d252010-07-09 15:32:30 +100067 struct pt_regs *old_regs = set_irq_regs(regs);
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100068 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100069 int msg;
70
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100071 /* Warning: regs can be NULL when called from irq enable */
72
73 if (!info->messages || (num_online_cpus() < 2))
David Gibson0e37d252010-07-09 15:32:30 +100074 goto out;
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100075
76 for (msg = 0; msg < 4; msg++)
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100077 if (test_and_clear_bit(msg, &info->messages))
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100078 smp_message_recv(msg);
David Gibson0e37d252010-07-09 15:32:30 +100079
80out:
81 set_irq_regs(old_regs);
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100082}
83
Michael Ellerman850f22d2010-07-09 15:34:00 +100084void 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
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100094#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