2007-02-14 16:09:45 +03:00
|
|
|
/*
|
|
|
|
* pmi driver
|
|
|
|
*
|
|
|
|
* (C) Copyright IBM Deutschland Entwicklung GmbH 2005
|
|
|
|
*
|
|
|
|
* PMI (Platform Management Interrupt) is a way to communicate
|
|
|
|
* with the BMC (Baseboard Management Controller) via interrupts.
|
|
|
|
* Unlike IPMI it is bidirectional and has a low latency.
|
|
|
|
*
|
|
|
|
* Author: Christian Krafft <krafft@de.ibm.com>
|
|
|
|
*
|
|
|
|
* 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, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2007-02-14 16:09:45 +03:00
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/spinlock.h>
|
2011-05-27 21:23:32 +04:00
|
|
|
#include <linux/module.h>
|
2007-02-14 16:09:45 +03:00
|
|
|
#include <linux/workqueue.h>
|
2007-11-13 20:13:09 +03:00
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/of_platform.h>
|
2007-02-14 16:09:45 +03:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/pmi.h>
|
2007-04-23 23:35:45 +04:00
|
|
|
#include <asm/prom.h>
|
2007-02-14 16:09:45 +03:00
|
|
|
|
|
|
|
struct pmi_data {
|
|
|
|
struct list_head handler;
|
|
|
|
spinlock_t handler_spinlock;
|
|
|
|
spinlock_t pmi_spinlock;
|
|
|
|
struct mutex msg_mutex;
|
|
|
|
pmi_message_t msg;
|
|
|
|
struct completion *completion;
|
2010-07-23 01:52:34 +04:00
|
|
|
struct platform_device *dev;
|
2007-02-14 16:09:45 +03:00
|
|
|
int irq;
|
|
|
|
u8 __iomem *pmi_reg;
|
|
|
|
struct work_struct work;
|
|
|
|
};
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
static struct pmi_data *data;
|
2007-02-14 16:09:45 +03:00
|
|
|
|
2009-03-18 20:08:52 +03:00
|
|
|
static irqreturn_t pmi_irq_handler(int irq, void *dev_id)
|
2007-02-14 16:09:45 +03:00
|
|
|
{
|
|
|
|
u8 type;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spin_lock(&data->pmi_spinlock);
|
|
|
|
|
|
|
|
type = ioread8(data->pmi_reg + PMI_READ_TYPE);
|
|
|
|
pr_debug("pmi: got message of type %d\n", type);
|
|
|
|
|
|
|
|
if (type & PMI_ACK && !data->completion) {
|
|
|
|
printk(KERN_WARNING "pmi: got unexpected ACK message.\n");
|
|
|
|
rc = -EIO;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->completion && !(type & PMI_ACK)) {
|
|
|
|
printk(KERN_WARNING "pmi: expected ACK, but got %d\n", type);
|
|
|
|
rc = -EIO;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->msg.type = type;
|
|
|
|
data->msg.data0 = ioread8(data->pmi_reg + PMI_READ_DATA0);
|
|
|
|
data->msg.data1 = ioread8(data->pmi_reg + PMI_READ_DATA1);
|
|
|
|
data->msg.data2 = ioread8(data->pmi_reg + PMI_READ_DATA2);
|
|
|
|
rc = 0;
|
|
|
|
unlock:
|
|
|
|
spin_unlock(&data->pmi_spinlock);
|
|
|
|
|
|
|
|
if (rc == -EIO) {
|
|
|
|
rc = IRQ_HANDLED;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->msg.type & PMI_ACK) {
|
|
|
|
complete(data->completion);
|
|
|
|
rc = IRQ_HANDLED;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule_work(&data->work);
|
|
|
|
|
|
|
|
rc = IRQ_HANDLED;
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-10 23:56:38 +04:00
|
|
|
static const struct of_device_id pmi_match[] = {
|
2007-02-14 16:09:45 +03:00
|
|
|
{ .type = "ibm,pmi", .name = "ibm,pmi" },
|
2007-04-23 23:35:44 +04:00
|
|
|
{ .type = "ibm,pmi" },
|
2007-02-14 16:09:45 +03:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, pmi_match);
|
|
|
|
|
|
|
|
static void pmi_notify_handlers(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct pmi_handler *handler;
|
|
|
|
|
|
|
|
spin_lock(&data->handler_spinlock);
|
|
|
|
list_for_each_entry(handler, &data->handler, node) {
|
2010-09-11 23:10:53 +04:00
|
|
|
pr_debug("pmi: notifying handler %p\n", handler);
|
2007-02-14 16:09:45 +03:00
|
|
|
if (handler->type == data->msg.type)
|
2007-07-20 23:39:18 +04:00
|
|
|
handler->handle_pmi_message(data->msg);
|
2007-02-14 16:09:45 +03:00
|
|
|
}
|
|
|
|
spin_unlock(&data->handler_spinlock);
|
|
|
|
}
|
|
|
|
|
2011-02-23 05:59:54 +03:00
|
|
|
static int pmi_of_probe(struct platform_device *dev)
|
2007-02-14 16:09:45 +03:00
|
|
|
{
|
2010-04-14 03:12:29 +04:00
|
|
|
struct device_node *np = dev->dev.of_node;
|
2007-02-14 16:09:45 +03:00
|
|
|
int rc;
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
if (data) {
|
|
|
|
printk(KERN_ERR "pmi: driver has already been initialized.\n");
|
|
|
|
rc = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-02-14 16:09:45 +03:00
|
|
|
data = kzalloc(sizeof(struct pmi_data), GFP_KERNEL);
|
|
|
|
if (!data) {
|
|
|
|
printk(KERN_ERR "pmi: could not allocate memory.\n");
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-04-23 23:35:45 +04:00
|
|
|
data->pmi_reg = of_iomap(np, 0);
|
2007-02-14 16:09:45 +03:00
|
|
|
if (!data->pmi_reg) {
|
|
|
|
printk(KERN_ERR "pmi: invalid register address.\n");
|
|
|
|
rc = -EFAULT;
|
|
|
|
goto error_cleanup_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&data->handler);
|
|
|
|
|
|
|
|
mutex_init(&data->msg_mutex);
|
|
|
|
spin_lock_init(&data->pmi_spinlock);
|
|
|
|
spin_lock_init(&data->handler_spinlock);
|
|
|
|
|
|
|
|
INIT_WORK(&data->work, pmi_notify_handlers);
|
|
|
|
|
|
|
|
data->dev = dev;
|
|
|
|
|
|
|
|
data->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
if (data->irq == NO_IRQ) {
|
|
|
|
printk(KERN_ERR "pmi: invalid interrupt.\n");
|
|
|
|
rc = -EFAULT;
|
|
|
|
goto error_cleanup_iomap;
|
|
|
|
}
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
rc = request_irq(data->irq, pmi_irq_handler, 0, "pmi", NULL);
|
2007-02-14 16:09:45 +03:00
|
|
|
if (rc) {
|
|
|
|
printk(KERN_ERR "pmi: can't request IRQ %d: returned %d\n",
|
|
|
|
data->irq, rc);
|
|
|
|
goto error_cleanup_iomap;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO "pmi: found pmi device at addr %p.\n", data->pmi_reg);
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
error_cleanup_iomap:
|
|
|
|
iounmap(data->pmi_reg);
|
|
|
|
|
|
|
|
error_cleanup_data:
|
|
|
|
kfree(data);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-07-23 01:52:34 +04:00
|
|
|
static int pmi_of_remove(struct platform_device *dev)
|
2007-02-14 16:09:45 +03:00
|
|
|
{
|
|
|
|
struct pmi_handler *handler, *tmp;
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
free_irq(data->irq, NULL);
|
2007-02-14 16:09:45 +03:00
|
|
|
iounmap(data->pmi_reg);
|
|
|
|
|
|
|
|
spin_lock(&data->handler_spinlock);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(handler, tmp, &data->handler, node)
|
|
|
|
list_del(&handler->node);
|
|
|
|
|
|
|
|
spin_unlock(&data->handler_spinlock);
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
kfree(data);
|
|
|
|
data = NULL;
|
2007-02-14 16:09:45 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-23 05:59:54 +03:00
|
|
|
static struct platform_driver pmi_of_platform_driver = {
|
2007-02-14 16:09:45 +03:00
|
|
|
.probe = pmi_of_probe,
|
2007-10-11 09:19:03 +04:00
|
|
|
.remove = pmi_of_remove,
|
2010-04-14 03:13:02 +04:00
|
|
|
.driver = {
|
|
|
|
.name = "pmi",
|
|
|
|
.of_match_table = pmi_match,
|
2007-10-11 09:19:03 +04:00
|
|
|
},
|
2007-02-14 16:09:45 +03:00
|
|
|
};
|
2012-10-10 12:32:30 +04:00
|
|
|
module_platform_driver(pmi_of_platform_driver);
|
2007-02-14 16:09:45 +03:00
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
int pmi_send_message(pmi_message_t msg)
|
2007-02-14 16:09:45 +03:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
DECLARE_COMPLETION_ONSTACK(completion);
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
if (!data)
|
|
|
|
return -ENODEV;
|
2007-02-14 16:09:45 +03:00
|
|
|
|
|
|
|
mutex_lock(&data->msg_mutex);
|
|
|
|
|
|
|
|
data->msg = msg;
|
|
|
|
pr_debug("pmi_send_message: msg is %08x\n", *(u32*)&msg);
|
|
|
|
|
|
|
|
data->completion = &completion;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&data->pmi_spinlock, flags);
|
|
|
|
iowrite8(msg.data0, data->pmi_reg + PMI_WRITE_DATA0);
|
|
|
|
iowrite8(msg.data1, data->pmi_reg + PMI_WRITE_DATA1);
|
|
|
|
iowrite8(msg.data2, data->pmi_reg + PMI_WRITE_DATA2);
|
|
|
|
iowrite8(msg.type, data->pmi_reg + PMI_WRITE_TYPE);
|
|
|
|
spin_unlock_irqrestore(&data->pmi_spinlock, flags);
|
|
|
|
|
|
|
|
pr_debug("pmi_send_message: wait for completion\n");
|
|
|
|
|
|
|
|
wait_for_completion_interruptible_timeout(data->completion,
|
|
|
|
PMI_TIMEOUT);
|
|
|
|
|
|
|
|
data->completion = NULL;
|
|
|
|
|
|
|
|
mutex_unlock(&data->msg_mutex);
|
2007-07-20 23:39:18 +04:00
|
|
|
|
|
|
|
return 0;
|
2007-02-14 16:09:45 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pmi_send_message);
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
int pmi_register_handler(struct pmi_handler *handler)
|
2007-02-14 16:09:45 +03:00
|
|
|
{
|
2007-04-23 23:35:43 +04:00
|
|
|
if (!data)
|
2007-07-20 23:39:18 +04:00
|
|
|
return -ENODEV;
|
2007-04-23 23:35:43 +04:00
|
|
|
|
2007-02-14 16:09:45 +03:00
|
|
|
spin_lock(&data->handler_spinlock);
|
|
|
|
list_add_tail(&handler->node, &data->handler);
|
|
|
|
spin_unlock(&data->handler_spinlock);
|
2007-07-20 23:39:18 +04:00
|
|
|
|
|
|
|
return 0;
|
2007-02-14 16:09:45 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pmi_register_handler);
|
|
|
|
|
2007-07-20 23:39:18 +04:00
|
|
|
void pmi_unregister_handler(struct pmi_handler *handler)
|
2007-02-14 16:09:45 +03:00
|
|
|
{
|
2007-04-23 23:35:43 +04:00
|
|
|
if (!data)
|
|
|
|
return;
|
2007-02-14 16:09:45 +03:00
|
|
|
|
2007-04-23 23:35:43 +04:00
|
|
|
pr_debug("pmi: unregistering handler %p\n", handler);
|
2007-02-14 16:09:45 +03:00
|
|
|
|
|
|
|
spin_lock(&data->handler_spinlock);
|
|
|
|
list_del(&handler->node);
|
|
|
|
spin_unlock(&data->handler_spinlock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(pmi_unregister_handler);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
|
|
|
|
MODULE_DESCRIPTION("IBM Platform Management Interrupt driver");
|