Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PS3 SMP routines. |
| 3 | * |
| 4 | * Copyright (C) 2006 Sony Computer Entertainment Inc. |
| 5 | * Copyright 2006 Sony Corp. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/smp.h> |
| 23 | |
| 24 | #include <asm/machdep.h> |
| 25 | #include <asm/udbg.h> |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 26 | |
| 27 | #include "platform.h" |
| 28 | |
| 29 | #if defined(DEBUG) |
Geert Uytterhoeven | 83bb643 | 2007-06-16 07:19:23 +1000 | [diff] [blame] | 30 | #define DBG udbg_printf |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 31 | #else |
Geert Uytterhoeven | 83bb643 | 2007-06-16 07:19:23 +1000 | [diff] [blame] | 32 | #define DBG pr_debug |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | static irqreturn_t ipi_function_handler(int irq, void *msg) |
| 36 | { |
| 37 | smp_message_recv((int)(long)msg); |
| 38 | return IRQ_HANDLED; |
| 39 | } |
| 40 | |
| 41 | /** |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 42 | * ps3_ipi_virqs - a per cpu array of virqs for ipi use |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 43 | */ |
| 44 | |
| 45 | #define MSG_COUNT 4 |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 46 | static DEFINE_PER_CPU(unsigned int, ps3_ipi_virqs[MSG_COUNT]); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 47 | |
| 48 | static const char *names[MSG_COUNT] = { |
| 49 | "ipi call", |
| 50 | "ipi reschedule", |
| 51 | "ipi migrate", |
| 52 | "ipi debug brk" |
| 53 | }; |
| 54 | |
| 55 | static void do_message_pass(int target, int msg) |
| 56 | { |
| 57 | int result; |
| 58 | unsigned int virq; |
| 59 | |
| 60 | if (msg >= MSG_COUNT) { |
| 61 | DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg); |
| 62 | return; |
| 63 | } |
| 64 | |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 65 | virq = per_cpu(ps3_ipi_virqs, target)[msg]; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 66 | result = ps3_send_event_locally(virq); |
| 67 | |
| 68 | if (result) |
| 69 | DBG("%s:%d: ps3_send_event_locally(%d, %d) failed" |
| 70 | " (%d)\n", __func__, __LINE__, target, msg, result); |
| 71 | } |
| 72 | |
| 73 | static void ps3_smp_message_pass(int target, int msg) |
| 74 | { |
| 75 | int cpu; |
| 76 | |
| 77 | if (target < NR_CPUS) |
| 78 | do_message_pass(target, msg); |
| 79 | else if (target == MSG_ALL_BUT_SELF) { |
| 80 | for_each_online_cpu(cpu) |
| 81 | if (cpu != smp_processor_id()) |
| 82 | do_message_pass(cpu, msg); |
| 83 | } else { |
| 84 | for_each_online_cpu(cpu) |
| 85 | do_message_pass(cpu, msg); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | static int ps3_smp_probe(void) |
| 90 | { |
| 91 | return 2; |
| 92 | } |
| 93 | |
| 94 | static void __init ps3_smp_setup_cpu(int cpu) |
| 95 | { |
| 96 | int result; |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 97 | unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 98 | int i; |
| 99 | |
| 100 | DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); |
| 101 | |
| 102 | /* |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 103 | * Check assumptions on ps3_ipi_virqs[] indexing. If this |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 104 | * check fails, then a different mapping of PPC_MSG_ |
| 105 | * to index needs to be setup. |
| 106 | */ |
| 107 | |
Jens Axboe | b7d7a24 | 2008-06-26 11:22:13 +0200 | [diff] [blame] | 108 | BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0); |
| 109 | BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1); |
| 110 | BUILD_BUG_ON(PPC_MSG_CALL_FUNC_SINGLE != 2); |
| 111 | BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 112 | |
| 113 | for (i = 0; i < MSG_COUNT; i++) { |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 114 | result = ps3_event_receive_port_setup(cpu, &virqs[i]); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 115 | |
| 116 | if (result) |
| 117 | continue; |
| 118 | |
| 119 | DBG("%s:%d: (%d, %d) => virq %u\n", |
| 120 | __func__, __LINE__, cpu, i, virqs[i]); |
| 121 | |
Geoff Levand | 28820d9 | 2007-05-12 03:41:59 +1000 | [diff] [blame] | 122 | result = request_irq(virqs[i], ipi_function_handler, |
| 123 | IRQF_DISABLED, names[i], (void*)(long)i); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 124 | |
Geoff Levand | 28820d9 | 2007-05-12 03:41:59 +1000 | [diff] [blame] | 125 | if (result) |
| 126 | virqs[i] = NO_IRQ; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]); |
| 130 | |
| 131 | DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu); |
| 132 | } |
| 133 | |
| 134 | void ps3_smp_cleanup_cpu(int cpu) |
| 135 | { |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 136 | unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 137 | int i; |
| 138 | |
| 139 | DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 140 | |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 141 | for (i = 0; i < MSG_COUNT; i++) { |
Geoff Levand | 9263e85 | 2007-06-16 07:19:32 +1000 | [diff] [blame] | 142 | /* Can't call free_irq from interrupt context. */ |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 143 | ps3_event_receive_port_destroy(virqs[i]); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 144 | virqs[i] = NO_IRQ; |
| 145 | } |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 146 | |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 147 | DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu); |
| 148 | } |
| 149 | |
| 150 | static struct smp_ops_t ps3_smp_ops = { |
| 151 | .probe = ps3_smp_probe, |
| 152 | .message_pass = ps3_smp_message_pass, |
| 153 | .kick_cpu = smp_generic_kick_cpu, |
| 154 | .setup_cpu = ps3_smp_setup_cpu, |
| 155 | }; |
| 156 | |
| 157 | void smp_init_ps3(void) |
| 158 | { |
| 159 | DBG(" -> %s\n", __func__); |
| 160 | smp_ops = &ps3_smp_ops; |
| 161 | DBG(" <- %s\n", __func__); |
| 162 | } |