Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 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> |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 16 | #include <linux/percpu.h> |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 17 | |
| 18 | #include <asm/dbell.h> |
David Gibson | 0e37d25 | 2010-07-09 15:32:30 +1000 | [diff] [blame] | 19 | #include <asm/irq_regs.h> |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 20 | |
| 21 | #ifdef CONFIG_SMP |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 22 | struct doorbell_cpu_info { |
| 23 | unsigned long messages; /* current messages bits */ |
| 24 | unsigned int tag; /* tag value */ |
| 25 | }; |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 26 | |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 27 | static DEFINE_PER_CPU(struct doorbell_cpu_info, doorbell_cpu_info); |
| 28 | |
| 29 | void doorbell_setup_this_cpu(void) |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 30 | { |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 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 | |
Milton Miller | f107293 | 2011-05-10 19:29:10 +0000 | [diff] [blame] | 37 | void doorbell_message_pass(int cpu, int msg) |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 38 | { |
| 39 | struct doorbell_cpu_info *info; |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 40 | |
Milton Miller | f107293 | 2011-05-10 19:29:10 +0000 | [diff] [blame] | 41 | info = &per_cpu(doorbell_cpu_info, cpu); |
| 42 | set_bit(msg, &info->messages); |
| 43 | ppc_msgsnd(PPC_DBELL, 0, info->tag); |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 44 | } |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 45 | |
| 46 | void doorbell_exception(struct pt_regs *regs) |
| 47 | { |
David Gibson | 0e37d25 | 2010-07-09 15:32:30 +1000 | [diff] [blame] | 48 | struct pt_regs *old_regs = set_irq_regs(regs); |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 49 | struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info); |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 50 | int msg; |
| 51 | |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 52 | /* Warning: regs can be NULL when called from irq enable */ |
| 53 | |
| 54 | if (!info->messages || (num_online_cpus() < 2)) |
David Gibson | 0e37d25 | 2010-07-09 15:32:30 +1000 | [diff] [blame] | 55 | goto out; |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 56 | |
| 57 | for (msg = 0; msg < 4; msg++) |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 58 | if (test_and_clear_bit(msg, &info->messages)) |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 59 | smp_message_recv(msg); |
David Gibson | 0e37d25 | 2010-07-09 15:32:30 +1000 | [diff] [blame] | 60 | |
| 61 | out: |
| 62 | set_irq_regs(old_regs); |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 63 | } |
| 64 | |
Michael Ellerman | 850f22d | 2010-07-09 15:34:00 +1000 | [diff] [blame] | 65 | void 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 Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 75 | #else /* CONFIG_SMP */ |
| 76 | void doorbell_exception(struct pt_regs *regs) |
| 77 | { |
| 78 | printk(KERN_WARNING "Received doorbell on non-smp system\n"); |
| 79 | } |
| 80 | #endif /* CONFIG_SMP */ |
| 81 | |