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> |
Milton Miller | 23d72bf | 2011-05-10 19:29:39 +0000 | [diff] [blame] | 16 | #include <linux/hardirq.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> |
Paul Mackerras | 755563b | 2015-03-19 19:29:01 +1100 | [diff] [blame] | 20 | #include <asm/kvm_ppc.h> |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 21 | |
| 22 | #ifdef CONFIG_SMP |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 23 | |
Nicholas Piggin | b866cc2 | 2017-04-13 20:16:21 +1000 | [diff] [blame] | 24 | /* |
| 25 | * Doorbells must only be used if CPU_FTR_DBELL is available. |
| 26 | * msgsnd is used in HV, and msgsndp is used in !HV. |
| 27 | * |
| 28 | * These should be used by platform code that is aware of restrictions. |
| 29 | * Other arch code should use ->cause_ipi. |
| 30 | * |
| 31 | * doorbell_global_ipi() sends a dbell to any target CPU. |
| 32 | * Must be used only by architectures that address msgsnd target |
| 33 | * by PIR/get_hard_smp_processor_id. |
| 34 | */ |
| 35 | void doorbell_global_ipi(int cpu) |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 36 | { |
Nicholas Piggin | b866cc2 | 2017-04-13 20:16:21 +1000 | [diff] [blame] | 37 | u32 tag = get_hard_smp_processor_id(cpu); |
| 38 | |
| 39 | kvmppc_set_host_ipi(cpu, 1); |
Paul Mackerras | 9fb1b36 | 2012-09-04 18:33:08 +0000 | [diff] [blame] | 40 | /* Order previous accesses vs. msgsnd, which is treated as a store */ |
Nicholas Piggin | b87ac02 | 2017-04-13 20:16:22 +1000 | [diff] [blame^] | 41 | ppc_msgsnd_sync(); |
Nicholas Piggin | b866cc2 | 2017-04-13 20:16:21 +1000 | [diff] [blame] | 42 | ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag); |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * doorbell_core_ipi() sends a dbell to a target CPU in the same core. |
| 47 | * Must be used only by architectures that address msgsnd target |
| 48 | * by TIR/cpu_thread_in_core. |
| 49 | */ |
| 50 | void doorbell_core_ipi(int cpu) |
| 51 | { |
| 52 | u32 tag = cpu_thread_in_core(cpu); |
| 53 | |
| 54 | kvmppc_set_host_ipi(cpu, 1); |
| 55 | /* Order previous accesses vs. msgsnd, which is treated as a store */ |
Nicholas Piggin | b87ac02 | 2017-04-13 20:16:22 +1000 | [diff] [blame^] | 56 | ppc_msgsnd_sync(); |
Nicholas Piggin | b866cc2 | 2017-04-13 20:16:21 +1000 | [diff] [blame] | 57 | ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag); |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Attempt to cause a core doorbell if destination is on the same core. |
| 62 | * Returns 1 on success, 0 on failure. |
| 63 | */ |
| 64 | int doorbell_try_core_ipi(int cpu) |
| 65 | { |
| 66 | int this_cpu = get_cpu(); |
| 67 | int ret = 0; |
| 68 | |
| 69 | if (cpumask_test_cpu(cpu, cpu_sibling_mask(this_cpu))) { |
| 70 | doorbell_core_ipi(cpu); |
| 71 | ret = 1; |
| 72 | } |
| 73 | |
| 74 | put_cpu(); |
| 75 | |
| 76 | return ret; |
Kumar Gala | 620165f | 2009-02-12 13:54:53 +0000 | [diff] [blame] | 77 | } |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 78 | |
| 79 | void doorbell_exception(struct pt_regs *regs) |
| 80 | { |
David Gibson | 0e37d25 | 2010-07-09 15:32:30 +1000 | [diff] [blame] | 81 | struct pt_regs *old_regs = set_irq_regs(regs); |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 82 | |
Milton Miller | 23d72bf | 2011-05-10 19:29:39 +0000 | [diff] [blame] | 83 | irq_enter(); |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 84 | |
Nicholas Piggin | b87ac02 | 2017-04-13 20:16:22 +1000 | [diff] [blame^] | 85 | ppc_msgsync(); |
| 86 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 87 | may_hard_irq_enable(); |
| 88 | |
Paul Mackerras | 755563b | 2015-03-19 19:29:01 +1100 | [diff] [blame] | 89 | kvmppc_set_host_ipi(smp_processor_id(), 0); |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 90 | __this_cpu_inc(irq_stat.doorbell_irqs); |
Ian Munsie | a6a058e | 2013-03-21 19:22:52 +0000 | [diff] [blame] | 91 | |
Nicholas Piggin | b87ac02 | 2017-04-13 20:16:22 +1000 | [diff] [blame^] | 92 | smp_ipi_demux_relaxed(); /* already performed the barrier */ |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 93 | |
Milton Miller | 23d72bf | 2011-05-10 19:29:39 +0000 | [diff] [blame] | 94 | irq_exit(); |
David Gibson | 0e37d25 | 2010-07-09 15:32:30 +1000 | [diff] [blame] | 95 | set_irq_regs(old_regs); |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 96 | } |
Benjamin Herrenschmidt | e3145b3 | 2010-07-09 15:25:18 +1000 | [diff] [blame] | 97 | #else /* CONFIG_SMP */ |
| 98 | void doorbell_exception(struct pt_regs *regs) |
| 99 | { |
| 100 | printk(KERN_WARNING "Received doorbell on non-smp system\n"); |
| 101 | } |
| 102 | #endif /* CONFIG_SMP */ |
| 103 | |