blob: e49b24c8413342e35063e3b060749960678009c7 [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
Milton Millerf1072932011-05-10 19:29:10 +000037void doorbell_message_pass(int cpu, int msg)
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100038{
39 struct doorbell_cpu_info *info;
Kumar Gala620165f2009-02-12 13:54:53 +000040
Milton Millerf1072932011-05-10 19:29:10 +000041 info = &per_cpu(doorbell_cpu_info, cpu);
42 set_bit(msg, &info->messages);
43 ppc_msgsnd(PPC_DBELL, 0, info->tag);
Kumar Gala620165f2009-02-12 13:54:53 +000044}
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100045
46void doorbell_exception(struct pt_regs *regs)
47{
David Gibson0e37d252010-07-09 15:32:30 +100048 struct pt_regs *old_regs = set_irq_regs(regs);
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100049 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100050 int msg;
51
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100052 /* Warning: regs can be NULL when called from irq enable */
53
54 if (!info->messages || (num_online_cpus() < 2))
David Gibson0e37d252010-07-09 15:32:30 +100055 goto out;
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100056
57 for (msg = 0; msg < 4; msg++)
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100058 if (test_and_clear_bit(msg, &info->messages))
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100059 smp_message_recv(msg);
David Gibson0e37d252010-07-09 15:32:30 +100060
61out:
62 set_irq_regs(old_regs);
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100063}
64
Michael Ellerman850f22d2010-07-09 15:34:00 +100065void doorbell_check_self(void)
66{
67 struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
68
69 if (!info->messages)
70 return;
71
72 ppc_msgsnd(PPC_DBELL, 0, info->tag);
73}
74
Benjamin Herrenschmidte3145b32010-07-09 15:25:18 +100075#else /* CONFIG_SMP */
76void doorbell_exception(struct pt_regs *regs)
77{
78 printk(KERN_WARNING "Received doorbell on non-smp system\n");
79}
80#endif /* CONFIG_SMP */
81