2006-11-23 02:46:51 +03:00
|
|
|
/*
|
|
|
|
* PS3 SMP routines.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Sony Computer Entertainment Inc.
|
|
|
|
* Copyright 2006 Sony Corp.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/udbg.h>
|
|
|
|
|
|
|
|
#include "platform.h"
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2007-06-16 01:19:23 +04:00
|
|
|
#define DBG udbg_printf
|
2006-11-23 02:46:51 +03:00
|
|
|
#else
|
2007-06-16 01:19:23 +04:00
|
|
|
#define DBG pr_debug
|
2006-11-23 02:46:51 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static irqreturn_t ipi_function_handler(int irq, void *msg)
|
|
|
|
{
|
|
|
|
smp_message_recv((int)(long)msg);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-16 01:17:42 +04:00
|
|
|
* ps3_ipi_virqs - a per cpu array of virqs for ipi use
|
2006-11-23 02:46:51 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define MSG_COUNT 4
|
2007-06-16 01:17:42 +04:00
|
|
|
static DEFINE_PER_CPU(unsigned int, ps3_ipi_virqs[MSG_COUNT]);
|
2006-11-23 02:46:51 +03:00
|
|
|
|
|
|
|
static const char *names[MSG_COUNT] = {
|
|
|
|
"ipi call",
|
|
|
|
"ipi reschedule",
|
|
|
|
"ipi migrate",
|
|
|
|
"ipi debug brk"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void do_message_pass(int target, int msg)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
unsigned int virq;
|
|
|
|
|
|
|
|
if (msg >= MSG_COUNT) {
|
|
|
|
DBG("%s:%d: bad msg: %d\n", __func__, __LINE__, msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-16 01:17:42 +04:00
|
|
|
virq = per_cpu(ps3_ipi_virqs, target)[msg];
|
2006-11-23 02:46:51 +03:00
|
|
|
result = ps3_send_event_locally(virq);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
DBG("%s:%d: ps3_send_event_locally(%d, %d) failed"
|
|
|
|
" (%d)\n", __func__, __LINE__, target, msg, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ps3_smp_message_pass(int target, int msg)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
if (target < NR_CPUS)
|
|
|
|
do_message_pass(target, msg);
|
|
|
|
else if (target == MSG_ALL_BUT_SELF) {
|
|
|
|
for_each_online_cpu(cpu)
|
|
|
|
if (cpu != smp_processor_id())
|
|
|
|
do_message_pass(cpu, msg);
|
|
|
|
} else {
|
|
|
|
for_each_online_cpu(cpu)
|
|
|
|
do_message_pass(cpu, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ps3_smp_probe(void)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init ps3_smp_setup_cpu(int cpu)
|
|
|
|
{
|
|
|
|
int result;
|
2007-06-16 01:17:42 +04:00
|
|
|
unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
|
2006-11-23 02:46:51 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
|
|
|
|
|
|
|
|
/*
|
2007-06-16 01:17:42 +04:00
|
|
|
* Check assumptions on ps3_ipi_virqs[] indexing. If this
|
2006-11-23 02:46:51 +03:00
|
|
|
* check fails, then a different mapping of PPC_MSG_
|
|
|
|
* to index needs to be setup.
|
|
|
|
*/
|
|
|
|
|
2008-06-26 13:22:13 +04:00
|
|
|
BUILD_BUG_ON(PPC_MSG_CALL_FUNCTION != 0);
|
|
|
|
BUILD_BUG_ON(PPC_MSG_RESCHEDULE != 1);
|
|
|
|
BUILD_BUG_ON(PPC_MSG_CALL_FUNC_SINGLE != 2);
|
|
|
|
BUILD_BUG_ON(PPC_MSG_DEBUGGER_BREAK != 3);
|
2006-11-23 02:46:51 +03:00
|
|
|
|
|
|
|
for (i = 0; i < MSG_COUNT; i++) {
|
2007-05-01 01:01:01 +04:00
|
|
|
result = ps3_event_receive_port_setup(cpu, &virqs[i]);
|
2006-11-23 02:46:51 +03:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DBG("%s:%d: (%d, %d) => virq %u\n",
|
|
|
|
__func__, __LINE__, cpu, i, virqs[i]);
|
|
|
|
|
2007-05-11 21:41:59 +04:00
|
|
|
result = request_irq(virqs[i], ipi_function_handler,
|
|
|
|
IRQF_DISABLED, names[i], (void*)(long)i);
|
2006-11-23 02:46:51 +03:00
|
|
|
|
2007-05-11 21:41:59 +04:00
|
|
|
if (result)
|
|
|
|
virqs[i] = NO_IRQ;
|
2006-11-23 02:46:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ps3_register_ipi_debug_brk(cpu, virqs[PPC_MSG_DEBUGGER_BREAK]);
|
|
|
|
|
|
|
|
DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ps3_smp_cleanup_cpu(int cpu)
|
|
|
|
{
|
2007-06-16 01:17:42 +04:00
|
|
|
unsigned int *virqs = per_cpu(ps3_ipi_virqs, cpu);
|
2006-11-23 02:46:51 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
|
2007-05-01 01:01:01 +04:00
|
|
|
|
2006-11-23 02:46:51 +03:00
|
|
|
for (i = 0; i < MSG_COUNT; i++) {
|
2007-06-16 01:19:32 +04:00
|
|
|
/* Can't call free_irq from interrupt context. */
|
2007-05-01 01:01:01 +04:00
|
|
|
ps3_event_receive_port_destroy(virqs[i]);
|
2006-11-23 02:46:51 +03:00
|
|
|
virqs[i] = NO_IRQ;
|
|
|
|
}
|
2007-05-01 01:01:01 +04:00
|
|
|
|
2006-11-23 02:46:51 +03:00
|
|
|
DBG(" <- %s:%d: (%d)\n", __func__, __LINE__, cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct smp_ops_t ps3_smp_ops = {
|
|
|
|
.probe = ps3_smp_probe,
|
|
|
|
.message_pass = ps3_smp_message_pass,
|
|
|
|
.kick_cpu = smp_generic_kick_cpu,
|
|
|
|
.setup_cpu = ps3_smp_setup_cpu,
|
|
|
|
};
|
|
|
|
|
|
|
|
void smp_init_ps3(void)
|
|
|
|
{
|
|
|
|
DBG(" -> %s\n", __func__);
|
|
|
|
smp_ops = &ps3_smp_ops;
|
|
|
|
DBG(" <- %s\n", __func__);
|
|
|
|
}
|