2007-07-21 03:39:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2007, Michael Ellerman, IBM Corporation.
|
|
|
|
*
|
|
|
|
* 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/interrupt.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/msi.h>
|
2008-01-25 13:59:14 +08:00
|
|
|
#include <linux/of_platform.h>
|
2008-05-23 12:21:30 +08:00
|
|
|
#include <linux/debugfs.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2007-07-21 03:39:28 +08:00
|
|
|
|
|
|
|
#include <asm/dcr.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MSIC registers, specified as offsets from dcr_base
|
|
|
|
*/
|
|
|
|
#define MSIC_CTRL_REG 0x0
|
|
|
|
|
|
|
|
/* Base Address registers specify FIFO location in BE memory */
|
|
|
|
#define MSIC_BASE_ADDR_HI_REG 0x3
|
|
|
|
#define MSIC_BASE_ADDR_LO_REG 0x4
|
|
|
|
|
|
|
|
/* Hold the read/write offsets into the FIFO */
|
|
|
|
#define MSIC_READ_OFFSET_REG 0x5
|
|
|
|
#define MSIC_WRITE_OFFSET_REG 0x6
|
|
|
|
|
|
|
|
|
|
|
|
/* MSIC control register flags */
|
|
|
|
#define MSIC_CTRL_ENABLE 0x0001
|
|
|
|
#define MSIC_CTRL_FIFO_FULL_ENABLE 0x0002
|
|
|
|
#define MSIC_CTRL_IRQ_ENABLE 0x0008
|
|
|
|
#define MSIC_CTRL_FULL_STOP_ENABLE 0x0010
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The MSIC can be configured to use a FIFO of 32KB, 64KB, 128KB or 256KB.
|
|
|
|
* Currently we're using a 64KB FIFO size.
|
|
|
|
*/
|
|
|
|
#define MSIC_FIFO_SIZE_SHIFT 16
|
|
|
|
#define MSIC_FIFO_SIZE_BYTES (1 << MSIC_FIFO_SIZE_SHIFT)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To configure the FIFO size as (1 << n) bytes, we write (n - 15) into bits
|
|
|
|
* 8-9 of the MSIC control reg.
|
|
|
|
*/
|
|
|
|
#define MSIC_CTRL_FIFO_SIZE (((MSIC_FIFO_SIZE_SHIFT - 15) << 8) & 0x300)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to mask the read/write offsets to make sure they stay within
|
|
|
|
* the bounds of the FIFO. Also they should always be 16-byte aligned.
|
|
|
|
*/
|
|
|
|
#define MSIC_FIFO_SIZE_MASK ((MSIC_FIFO_SIZE_BYTES - 1) & ~0xFu)
|
|
|
|
|
|
|
|
/* Each entry in the FIFO is 16 bytes, the first 4 bytes hold the irq # */
|
|
|
|
#define MSIC_FIFO_ENTRY_SIZE 0x10
|
|
|
|
|
|
|
|
|
|
|
|
struct axon_msic {
|
|
|
|
struct irq_host *irq_host;
|
2008-01-25 13:59:14 +08:00
|
|
|
__le32 *fifo_virt;
|
|
|
|
dma_addr_t fifo_phys;
|
2007-07-21 03:39:28 +08:00
|
|
|
dcr_host_t dcr_host;
|
|
|
|
u32 read_offset;
|
2008-05-23 12:21:30 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
u32 __iomem *trigger;
|
|
|
|
#endif
|
2007-07-21 03:39:28 +08:00
|
|
|
};
|
|
|
|
|
2008-05-23 12:21:30 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic);
|
|
|
|
#else
|
|
|
|
static inline void axon_msi_debug_setup(struct device_node *dn,
|
|
|
|
struct axon_msic *msic) { }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-07-21 03:39:28 +08:00
|
|
|
static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
|
|
|
|
{
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2007-10-15 17:34:36 +08:00
|
|
|
dcr_write(msic->dcr_host, dcr_n, val);
|
2007-07-21 03:39:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
|
|
|
|
{
|
2011-03-25 23:45:20 +08:00
|
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
|
|
struct axon_msic *msic = irq_get_handler_data(irq);
|
2007-07-21 03:39:28 +08:00
|
|
|
u32 write_offset, msi;
|
|
|
|
int idx;
|
2008-11-28 17:51:22 +08:00
|
|
|
int retry = 0;
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2007-10-15 17:34:38 +08:00
|
|
|
write_offset = dcr_read(msic->dcr_host, MSIC_WRITE_OFFSET_REG);
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: original write_offset 0x%x\n", write_offset);
|
2007-07-21 03:39:28 +08:00
|
|
|
|
|
|
|
/* write_offset doesn't wrap properly, so we have to mask it */
|
|
|
|
write_offset &= MSIC_FIFO_SIZE_MASK;
|
|
|
|
|
2008-11-28 17:51:22 +08:00
|
|
|
while (msic->read_offset != write_offset && retry < 100) {
|
2007-07-21 03:39:28 +08:00
|
|
|
idx = msic->read_offset / sizeof(__le32);
|
2008-01-25 13:59:14 +08:00
|
|
|
msi = le32_to_cpu(msic->fifo_virt[idx]);
|
2007-07-21 03:39:28 +08:00
|
|
|
msi &= 0xFFFF;
|
|
|
|
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: woff %x roff %x msi %x\n",
|
2007-07-21 03:39:28 +08:00
|
|
|
write_offset, msic->read_offset, msi);
|
|
|
|
|
2008-11-28 17:51:22 +08:00
|
|
|
if (msi < NR_IRQS && irq_map[msi].host == msic->irq_host) {
|
|
|
|
generic_handle_irq(msi);
|
|
|
|
msic->fifo_virt[idx] = cpu_to_le32(0xffffffff);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Reading the MSIC_WRITE_OFFSET_REG does not
|
|
|
|
* reliably flush the outstanding DMA to the
|
|
|
|
* FIFO buffer. Here we were reading stale
|
|
|
|
* data, so we need to retry.
|
|
|
|
*/
|
|
|
|
udelay(1);
|
|
|
|
retry++;
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: invalid irq 0x%x!\n", msi);
|
2008-11-28 17:51:22 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retry) {
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: late irq 0x%x, retry %d\n",
|
2008-11-28 17:51:22 +08:00
|
|
|
msi, retry);
|
|
|
|
retry = 0;
|
|
|
|
}
|
|
|
|
|
2007-07-21 03:39:28 +08:00
|
|
|
msic->read_offset += MSIC_FIFO_ENTRY_SIZE;
|
|
|
|
msic->read_offset &= MSIC_FIFO_SIZE_MASK;
|
2008-11-28 17:51:22 +08:00
|
|
|
}
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2008-11-28 17:51:22 +08:00
|
|
|
if (retry) {
|
|
|
|
printk(KERN_WARNING "axon_msi: irq timed out\n");
|
|
|
|
|
|
|
|
msic->read_offset += MSIC_FIFO_ENTRY_SIZE;
|
|
|
|
msic->read_offset &= MSIC_FIFO_SIZE_MASK;
|
2007-07-21 03:39:28 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 21:59:28 +08:00
|
|
|
chip->irq_eoi(&desc->irq_data);
|
2007-07-21 03:39:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct axon_msic *find_msi_translator(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct irq_host *irq_host;
|
|
|
|
struct device_node *dn, *tmp;
|
|
|
|
const phandle *ph;
|
|
|
|
struct axon_msic *msic = NULL;
|
|
|
|
|
2007-09-17 14:03:45 +08:00
|
|
|
dn = of_node_get(pci_device_to_OF_node(dev));
|
2007-07-21 03:39:28 +08:00
|
|
|
if (!dn) {
|
|
|
|
dev_dbg(&dev->dev, "axon_msi: no pci_dn found\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-24 10:08:54 +08:00
|
|
|
for (; dn; dn = of_get_next_parent(dn)) {
|
2007-07-21 03:39:28 +08:00
|
|
|
ph = of_get_property(dn, "msi-translator", NULL);
|
|
|
|
if (ph)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ph) {
|
|
|
|
dev_dbg(&dev->dev,
|
|
|
|
"axon_msi: no msi-translator property found\n");
|
|
|
|
goto out_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = dn;
|
|
|
|
dn = of_find_node_by_phandle(*ph);
|
2008-02-05 10:13:15 +08:00
|
|
|
of_node_put(tmp);
|
2007-07-21 03:39:28 +08:00
|
|
|
if (!dn) {
|
|
|
|
dev_dbg(&dev->dev,
|
|
|
|
"axon_msi: msi-translator doesn't point to a node\n");
|
|
|
|
goto out_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
irq_host = irq_find_host(dn);
|
|
|
|
if (!irq_host) {
|
|
|
|
dev_dbg(&dev->dev, "axon_msi: no irq_host found for node %s\n",
|
|
|
|
dn->full_name);
|
|
|
|
goto out_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
msic = irq_host->host_data;
|
|
|
|
|
|
|
|
out_error:
|
|
|
|
of_node_put(dn);
|
|
|
|
|
|
|
|
return msic;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int axon_msi_check_device(struct pci_dev *dev, int nvec, int type)
|
|
|
|
{
|
|
|
|
if (!find_msi_translator(dev))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int setup_msi_msg_address(struct pci_dev *dev, struct msi_msg *msg)
|
|
|
|
{
|
2008-04-24 10:08:54 +08:00
|
|
|
struct device_node *dn;
|
2007-07-21 03:39:28 +08:00
|
|
|
struct msi_desc *entry;
|
|
|
|
int len;
|
|
|
|
const u32 *prop;
|
|
|
|
|
2007-09-17 14:03:45 +08:00
|
|
|
dn = of_node_get(pci_device_to_OF_node(dev));
|
2007-07-21 03:39:28 +08:00
|
|
|
if (!dn) {
|
|
|
|
dev_dbg(&dev->dev, "axon_msi: no pci_dn found\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
|
|
|
|
|
2008-04-24 10:08:54 +08:00
|
|
|
for (; dn; dn = of_get_next_parent(dn)) {
|
2007-07-21 03:39:28 +08:00
|
|
|
if (entry->msi_attrib.is_64) {
|
|
|
|
prop = of_get_property(dn, "msi-address-64", &len);
|
|
|
|
if (prop)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = of_get_property(dn, "msi-address-32", &len);
|
|
|
|
if (prop)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
dev_dbg(&dev->dev,
|
|
|
|
"axon_msi: no msi-address-(32|64) properties found\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (len) {
|
|
|
|
case 8:
|
|
|
|
msg->address_hi = prop[0];
|
|
|
|
msg->address_lo = prop[1];
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
msg->address_hi = 0;
|
|
|
|
msg->address_lo = prop[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_dbg(&dev->dev,
|
|
|
|
"axon_msi: malformed msi-address-(32|64) property\n");
|
|
|
|
of_node_put(dn);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(dn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int axon_msi_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
|
|
|
{
|
|
|
|
unsigned int virq, rc;
|
|
|
|
struct msi_desc *entry;
|
|
|
|
struct msi_msg msg;
|
|
|
|
struct axon_msic *msic;
|
|
|
|
|
|
|
|
msic = find_msi_translator(dev);
|
|
|
|
if (!msic)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
rc = setup_msi_msg_address(dev, &msg);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* We rely on being able to stash a virq in a u16 */
|
|
|
|
BUILD_BUG_ON(NR_IRQS > 65536);
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &dev->msi_list, list) {
|
|
|
|
virq = irq_create_direct_mapping(msic->irq_host);
|
|
|
|
if (virq == NO_IRQ) {
|
|
|
|
dev_warn(&dev->dev,
|
|
|
|
"axon_msi: virq allocation failed!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dev_dbg(&dev->dev, "axon_msi: allocated virq 0x%x\n", virq);
|
|
|
|
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_msi_desc(virq, entry);
|
2007-07-21 03:39:28 +08:00
|
|
|
msg.data = virq;
|
|
|
|
write_msi_msg(virq, &msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void axon_msi_teardown_msi_irqs(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct msi_desc *entry;
|
|
|
|
|
|
|
|
dev_dbg(&dev->dev, "axon_msi: tearing down msi irqs\n");
|
|
|
|
|
|
|
|
list_for_each_entry(entry, &dev->msi_list, list) {
|
|
|
|
if (entry->irq == NO_IRQ)
|
|
|
|
continue;
|
|
|
|
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_msi_desc(entry->irq, NULL);
|
2007-07-21 03:39:28 +08:00
|
|
|
irq_dispose_mapping(entry->irq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_chip msic_irq_chip = {
|
2010-09-28 22:46:51 +08:00
|
|
|
.irq_mask = mask_msi_irq,
|
|
|
|
.irq_unmask = unmask_msi_irq,
|
|
|
|
.irq_shutdown = mask_msi_irq,
|
2009-11-19 07:44:21 +08:00
|
|
|
.name = "AXON-MSI",
|
2007-07-21 03:39:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int msic_host_map(struct irq_host *h, unsigned int virq,
|
|
|
|
irq_hw_number_t hw)
|
|
|
|
{
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_chip_and_handler(virq, &msic_irq_chip, handle_simple_irq);
|
2007-07-21 03:39:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_host_ops msic_host_ops = {
|
|
|
|
.map = msic_host_map,
|
|
|
|
};
|
|
|
|
|
2011-02-23 10:59:54 +08:00
|
|
|
static void axon_msi_shutdown(struct platform_device *device)
|
2007-07-21 03:39:28 +08:00
|
|
|
{
|
2009-06-11 03:06:34 +08:00
|
|
|
struct axon_msic *msic = dev_get_drvdata(&device->dev);
|
2007-07-21 03:39:28 +08:00
|
|
|
u32 tmp;
|
|
|
|
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: disabling %s\n",
|
2008-01-25 13:59:14 +08:00
|
|
|
msic->irq_host->of_node->full_name);
|
|
|
|
tmp = dcr_read(msic->dcr_host, MSIC_CTRL_REG);
|
|
|
|
tmp &= ~MSIC_CTRL_ENABLE & ~MSIC_CTRL_IRQ_ENABLE;
|
|
|
|
msic_dcr_write(msic, MSIC_CTRL_REG, tmp);
|
2007-07-21 03:39:28 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 10:59:54 +08:00
|
|
|
static int axon_msi_probe(struct platform_device *device)
|
2007-07-21 03:39:28 +08:00
|
|
|
{
|
2010-04-14 07:12:29 +08:00
|
|
|
struct device_node *dn = device->dev.of_node;
|
2007-07-21 03:39:28 +08:00
|
|
|
struct axon_msic *msic;
|
|
|
|
unsigned int virq;
|
2007-09-17 14:05:02 +08:00
|
|
|
int dcr_base, dcr_len;
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: setting up dn %s\n", dn->full_name);
|
2007-07-21 03:39:28 +08:00
|
|
|
|
|
|
|
msic = kzalloc(sizeof(struct axon_msic), GFP_KERNEL);
|
|
|
|
if (!msic) {
|
|
|
|
printk(KERN_ERR "axon_msi: couldn't allocate msic for %s\n",
|
|
|
|
dn->full_name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-09-17 14:05:02 +08:00
|
|
|
dcr_base = dcr_resource_start(dn, 0);
|
2007-07-21 03:39:28 +08:00
|
|
|
dcr_len = dcr_resource_len(dn, 0);
|
|
|
|
|
2007-09-17 14:05:02 +08:00
|
|
|
if (dcr_base == 0 || dcr_len == 0) {
|
2007-07-21 03:39:28 +08:00
|
|
|
printk(KERN_ERR
|
|
|
|
"axon_msi: couldn't parse dcr properties on %s\n",
|
|
|
|
dn->full_name);
|
2009-10-12 22:29:40 +08:00
|
|
|
goto out_free_msic;
|
2007-07-21 03:39:28 +08:00
|
|
|
}
|
|
|
|
|
2007-09-17 14:05:02 +08:00
|
|
|
msic->dcr_host = dcr_map(dn, dcr_base, dcr_len);
|
2007-07-21 03:39:28 +08:00
|
|
|
if (!DCR_MAP_OK(msic->dcr_host)) {
|
|
|
|
printk(KERN_ERR "axon_msi: dcr_map failed for %s\n",
|
|
|
|
dn->full_name);
|
|
|
|
goto out_free_msic;
|
|
|
|
}
|
|
|
|
|
2008-01-25 13:59:14 +08:00
|
|
|
msic->fifo_virt = dma_alloc_coherent(&device->dev, MSIC_FIFO_SIZE_BYTES,
|
|
|
|
&msic->fifo_phys, GFP_KERNEL);
|
|
|
|
if (!msic->fifo_virt) {
|
2007-07-21 03:39:28 +08:00
|
|
|
printk(KERN_ERR "axon_msi: couldn't allocate fifo for %s\n",
|
|
|
|
dn->full_name);
|
|
|
|
goto out_free_msic;
|
|
|
|
}
|
|
|
|
|
2008-05-26 10:12:30 +08:00
|
|
|
virq = irq_of_parse_and_map(dn, 0);
|
|
|
|
if (virq == NO_IRQ) {
|
|
|
|
printk(KERN_ERR "axon_msi: irq parse and map failed for %s\n",
|
|
|
|
dn->full_name);
|
|
|
|
goto out_free_fifo;
|
|
|
|
}
|
2008-11-28 17:51:22 +08:00
|
|
|
memset(msic->fifo_virt, 0xff, MSIC_FIFO_SIZE_BYTES);
|
2008-05-26 10:12:30 +08:00
|
|
|
|
2008-05-26 10:12:32 +08:00
|
|
|
msic->irq_host = irq_alloc_host(dn, IRQ_HOST_MAP_NOMAP,
|
2007-08-28 16:47:54 +08:00
|
|
|
NR_IRQS, &msic_host_ops, 0);
|
2007-07-21 03:39:28 +08:00
|
|
|
if (!msic->irq_host) {
|
|
|
|
printk(KERN_ERR "axon_msi: couldn't allocate irq_host for %s\n",
|
|
|
|
dn->full_name);
|
|
|
|
goto out_free_fifo;
|
|
|
|
}
|
|
|
|
|
|
|
|
msic->irq_host->host_data = msic;
|
|
|
|
|
2011-03-25 23:45:20 +08:00
|
|
|
irq_set_handler_data(virq, msic);
|
|
|
|
irq_set_chained_handler(virq, axon_msi_cascade);
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: irq 0x%x setup for axon_msi\n", virq);
|
2007-07-21 03:39:28 +08:00
|
|
|
|
|
|
|
/* Enable the MSIC hardware */
|
2008-01-25 13:59:14 +08:00
|
|
|
msic_dcr_write(msic, MSIC_BASE_ADDR_HI_REG, msic->fifo_phys >> 32);
|
2007-07-21 03:39:28 +08:00
|
|
|
msic_dcr_write(msic, MSIC_BASE_ADDR_LO_REG,
|
2008-01-25 13:59:14 +08:00
|
|
|
msic->fifo_phys & 0xFFFFFFFF);
|
2007-07-21 03:39:28 +08:00
|
|
|
msic_dcr_write(msic, MSIC_CTRL_REG,
|
|
|
|
MSIC_CTRL_IRQ_ENABLE | MSIC_CTRL_ENABLE |
|
|
|
|
MSIC_CTRL_FIFO_SIZE);
|
|
|
|
|
powerpc/cell/axon-msi: Fix MSI after kexec
Commit d015fe995 'powerpc/cell/axon-msi: Retry on missing interrupt'
has turned a rare failure to kexec on QS22 into a reproducible
error, which we have now analysed.
The problem is that after a kexec, the MSIC hardware still points
into the middle of the old ring buffer. We set up the ring buffer
during reboot, but not the offset into it. On older kernels, this
would cause a storm of thousands of spurious interrupts after a
kexec, which would most of the time get dropped silently.
With the new code, we time out on each interrupt, waiting for
it to become valid. If more interrupts come in that we time
out on, this goes on indefinitely, which eventually leads to
a hard crash.
The solution in this commit is to read the current offset from
the MSIC when reinitializing it. This now works correctly, as
expected.
Reported-by: Dirk Herrendoerfer <d.herrendoerfer@de.ibm.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2008-12-12 17:19:50 +08:00
|
|
|
msic->read_offset = dcr_read(msic->dcr_host, MSIC_WRITE_OFFSET_REG)
|
|
|
|
& MSIC_FIFO_SIZE_MASK;
|
|
|
|
|
2009-06-11 03:06:34 +08:00
|
|
|
dev_set_drvdata(&device->dev, msic);
|
2008-01-25 13:59:14 +08:00
|
|
|
|
|
|
|
ppc_md.setup_msi_irqs = axon_msi_setup_msi_irqs;
|
|
|
|
ppc_md.teardown_msi_irqs = axon_msi_teardown_msi_irqs;
|
|
|
|
ppc_md.msi_check_device = axon_msi_check_device;
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2008-05-23 12:21:30 +08:00
|
|
|
axon_msi_debug_setup(dn, msic);
|
|
|
|
|
2007-07-21 03:39:28 +08:00
|
|
|
printk(KERN_DEBUG "axon_msi: setup MSIC on %s\n", dn->full_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free_fifo:
|
2008-01-25 13:59:14 +08:00
|
|
|
dma_free_coherent(&device->dev, MSIC_FIFO_SIZE_BYTES, msic->fifo_virt,
|
|
|
|
msic->fifo_phys);
|
2007-07-21 03:39:28 +08:00
|
|
|
out_free_msic:
|
|
|
|
kfree(msic);
|
|
|
|
out:
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-01-25 13:59:14 +08:00
|
|
|
static const struct of_device_id axon_msi_device_id[] = {
|
|
|
|
{
|
|
|
|
.compatible = "ibm,axon-msic"
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
};
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2011-02-23 10:59:54 +08:00
|
|
|
static struct platform_driver axon_msi_driver = {
|
2008-01-25 13:59:14 +08:00
|
|
|
.probe = axon_msi_probe,
|
|
|
|
.shutdown = axon_msi_shutdown,
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "axon-msi",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = axon_msi_device_id,
|
2008-01-25 13:59:14 +08:00
|
|
|
},
|
|
|
|
};
|
2007-07-21 03:39:28 +08:00
|
|
|
|
2008-01-25 13:59:14 +08:00
|
|
|
static int __init axon_msi_init(void)
|
|
|
|
{
|
2011-02-23 10:59:54 +08:00
|
|
|
return platform_driver_register(&axon_msi_driver);
|
2007-07-21 03:39:28 +08:00
|
|
|
}
|
2008-01-25 13:59:14 +08:00
|
|
|
subsys_initcall(axon_msi_init);
|
2008-05-23 12:21:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static int msic_set(void *data, u64 val)
|
|
|
|
{
|
|
|
|
struct axon_msic *msic = data;
|
|
|
|
out_le32(msic->trigger, val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msic_get(void *data, u64 *val)
|
|
|
|
{
|
|
|
|
*val = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_SIMPLE_ATTRIBUTE(fops_msic, msic_get, msic_set, "%llu\n");
|
|
|
|
|
|
|
|
void axon_msi_debug_setup(struct device_node *dn, struct axon_msic *msic)
|
|
|
|
{
|
|
|
|
char name[8];
|
|
|
|
u64 addr;
|
|
|
|
|
|
|
|
addr = of_translate_address(dn, of_get_property(dn, "reg", NULL));
|
|
|
|
if (addr == OF_BAD_ADDR) {
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: couldn't translate reg property\n");
|
2008-05-23 12:21:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msic->trigger = ioremap(addr, 0x4);
|
|
|
|
if (!msic->trigger) {
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: ioremap failed\n");
|
2008-05-23 12:21:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "msic_%d", of_node_to_nid(dn));
|
|
|
|
|
|
|
|
if (!debugfs_create_file(name, 0600, powerpc_debugfs_root,
|
|
|
|
msic, &fops_msic)) {
|
2009-06-18 02:13:53 +08:00
|
|
|
pr_devel("axon_msi: debugfs_create_file failed!\n");
|
2008-05-23 12:21:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|