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 | |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 35 | /** |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 36 | * ps3_ipi_virqs - a per cpu array of virqs for ipi use |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | #define MSG_COUNT 4 |
Tejun Heo | 204fba4 | 2009-06-24 15:13:45 +0900 | [diff] [blame] | 40 | static DEFINE_PER_CPU(unsigned int [MSG_COUNT], ps3_ipi_virqs); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 41 | |
Milton Miller | f107293 | 2011-05-10 19:29:10 +0000 | [diff] [blame] | 42 | static void ps3_smp_message_pass(int cpu, int msg) |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 43 | { |
| 44 | int result; |
| 45 | unsigned int virq; |
| 46 | |
| 47 | if (msg >= MSG_COUNT) { |
| 48 | DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg); |
| 49 | return; |
| 50 | } |
| 51 | |
Milton Miller | f107293 | 2011-05-10 19:29:10 +0000 | [diff] [blame] | 52 | virq = per_cpu(ps3_ipi_virqs, cpu)[msg]; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 53 | result = ps3_send_event_locally(virq); |
| 54 | |
| 55 | if (result) |
| 56 | DBG("%s:%d: ps3_send_event_locally(%d, %d) failed" |
Milton Miller | f107293 | 2011-05-10 19:29:10 +0000 | [diff] [blame] | 57 | " (%d)\n", __func__, __LINE__, cpu, msg, result); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Geoff Levand | b9ec60d | 2011-11-29 15:38:50 +0000 | [diff] [blame] | 60 | static int __init ps3_smp_probe(void) |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 61 | { |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 62 | int cpu; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 63 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 64 | for (cpu = 0; cpu < 2; cpu++) { |
| 65 | int result; |
| 66 | unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu); |
| 67 | int i; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 68 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 69 | DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 70 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 71 | /* |
| 72 | * Check assumptions on ps3_ipi_virqs[] indexing. If this |
| 73 | * check fails, then a different mapping of PPC_MSG_ |
| 74 | * to index needs to be setup. |
| 75 | */ |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 76 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 77 | BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0); |
| 78 | BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1); |
| 79 | BUILD_BUG_ON(PPC_MSG_CALL_FUNC_SINGLE != 2); |
| 80 | BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 81 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 82 | for (i = 0; i < MSG_COUNT; i++) { |
| 83 | result = ps3_event_receive_port_setup(cpu, &virqs[i]); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 84 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 85 | if (result) |
| 86 | continue; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 87 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 88 | DBG("%s:%d: (%d, %d) => virq %u\n", |
| 89 | __func__, __LINE__, cpu, i, virqs[i]); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 90 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 91 | result = smp_request_message_ipi(virqs[i], i); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 92 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 93 | if (result) |
| 94 | virqs[i] = NO_IRQ; |
| 95 | else |
| 96 | ps3_register_ipi_irq(cpu, virqs[i]); |
| 97 | } |
| 98 | |
| 99 | ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]); |
| 100 | |
| 101 | DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Geoff Levand | 7eaf09e | 2011-11-08 12:38:21 +0000 | [diff] [blame] | 104 | return 2; |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void ps3_smp_cleanup_cpu(int cpu) |
| 108 | { |
Geoff Levand | 7961f20 | 2007-06-16 07:17:42 +1000 | [diff] [blame] | 109 | unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 110 | int i; |
| 111 | |
| 112 | DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu); |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 113 | |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 114 | for (i = 0; i < MSG_COUNT; i++) { |
Geoff Levand | 9263e85 | 2007-06-16 07:19:32 +1000 | [diff] [blame] | 115 | /* Can't call free_irq from interrupt context. */ |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 116 | ps3_event_receive_port_destroy(virqs[i]); |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 117 | virqs[i] = NO_IRQ; |
| 118 | } |
Geoff Levand | dc4f60c | 2007-05-01 07:01:01 +1000 | [diff] [blame] | 119 | |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 120 | DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu); |
| 121 | } |
| 122 | |
| 123 | static struct smp_ops_t ps3_smp_ops = { |
| 124 | .probe = ps3_smp_probe, |
| 125 | .message_pass = ps3_smp_message_pass, |
| 126 | .kick_cpu = smp_generic_kick_cpu, |
Geoff Levand | f58a9d1 | 2006-11-23 00:46:51 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | void smp_init_ps3(void) |
| 130 | { |
| 131 | DBG(" -> %s\n", __func__); |
| 132 | smp_ops = &ps3_smp_ops; |
| 133 | DBG(" <- %s\n", __func__); |
| 134 | } |