2009-02-12 21:54:53 +08:00
|
|
|
/*
|
|
|
|
* Author: Kumar Gala <galak@kernel.crashing.org>
|
|
|
|
*
|
|
|
|
* Copyright 2009 Freescale Semiconductor Inc.
|
|
|
|
*
|
|
|
|
* 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; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/threads.h>
|
2010-07-09 13:29:53 +08:00
|
|
|
#include <linux/percpu.h>
|
2009-02-12 21:54:53 +08:00
|
|
|
|
|
|
|
#include <asm/dbell.h>
|
2010-07-09 13:32:30 +08:00
|
|
|
#include <asm/irq_regs.h>
|
2009-02-12 21:54:53 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2010-07-09 13:29:53 +08:00
|
|
|
struct doorbell_cpu_info {
|
|
|
|
unsigned long messages; /* current messages bits */
|
|
|
|
unsigned int tag; /* tag value */
|
|
|
|
};
|
2009-02-12 21:54:53 +08:00
|
|
|
|
2010-07-09 13:29:53 +08:00
|
|
|
static DEFINE_PER_CPU(struct doorbell_cpu_info, doorbell_cpu_info);
|
|
|
|
|
|
|
|
void doorbell_setup_this_cpu(void)
|
|
|
|
{
|
|
|
|
struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
|
|
|
|
|
|
|
|
info->messages = 0;
|
|
|
|
info->tag = mfspr(SPRN_PIR) & 0x3fff;
|
|
|
|
}
|
|
|
|
|
2011-05-11 03:29:10 +08:00
|
|
|
void doorbell_message_pass(int cpu, int msg)
|
2009-02-12 21:54:53 +08:00
|
|
|
{
|
2010-07-09 13:29:53 +08:00
|
|
|
struct doorbell_cpu_info *info;
|
2011-05-11 03:29:10 +08:00
|
|
|
|
|
|
|
info = &per_cpu(doorbell_cpu_info, cpu);
|
|
|
|
set_bit(msg, &info->messages);
|
|
|
|
ppc_msgsnd(PPC_DBELL, 0, info->tag);
|
2009-02-12 21:54:53 +08:00
|
|
|
}
|
2010-07-09 13:25:18 +08:00
|
|
|
|
|
|
|
void doorbell_exception(struct pt_regs *regs)
|
|
|
|
{
|
2010-07-09 13:32:30 +08:00
|
|
|
struct pt_regs *old_regs = set_irq_regs(regs);
|
2010-07-09 13:29:53 +08:00
|
|
|
struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
|
2010-07-09 13:25:18 +08:00
|
|
|
int msg;
|
|
|
|
|
2010-07-09 13:29:53 +08:00
|
|
|
/* Warning: regs can be NULL when called from irq enable */
|
|
|
|
|
|
|
|
if (!info->messages || (num_online_cpus() < 2))
|
2010-07-09 13:32:30 +08:00
|
|
|
goto out;
|
2010-07-09 13:25:18 +08:00
|
|
|
|
|
|
|
for (msg = 0; msg < 4; msg++)
|
2010-07-09 13:29:53 +08:00
|
|
|
if (test_and_clear_bit(msg, &info->messages))
|
2010-07-09 13:25:18 +08:00
|
|
|
smp_message_recv(msg);
|
2010-07-09 13:32:30 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
set_irq_regs(old_regs);
|
2010-07-09 13:25:18 +08:00
|
|
|
}
|
|
|
|
|
2010-07-09 13:34:00 +08:00
|
|
|
void doorbell_check_self(void)
|
|
|
|
{
|
|
|
|
struct doorbell_cpu_info *info = &__get_cpu_var(doorbell_cpu_info);
|
|
|
|
|
|
|
|
if (!info->messages)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ppc_msgsnd(PPC_DBELL, 0, info->tag);
|
|
|
|
}
|
|
|
|
|
2010-07-09 13:25:18 +08:00
|
|
|
#else /* CONFIG_SMP */
|
|
|
|
void doorbell_exception(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
printk(KERN_WARNING "Received doorbell on non-smp system\n");
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|