2007-07-18 02:25:09 -06:00
|
|
|
/*
|
|
|
|
* Shared interrupt handling code for IPR and INTC2 types of IRQs.
|
|
|
|
*
|
2008-04-24 06:36:34 -06:00
|
|
|
* Copyright (C) 2007, 2008 Magnus Damm
|
2010-03-07 21:33:17 -07:00
|
|
|
* Copyright (C) 2009, 2010 Paul Mundt
|
2007-07-18 02:25:09 -06:00
|
|
|
*
|
|
|
|
* Based on intc2.c and ipr.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi
|
|
|
|
* Copyright (C) 2000 Kazumoto Kojima
|
|
|
|
* Copyright (C) 2001 David J. Mckay (david.mckay@st.com)
|
|
|
|
* Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
|
|
|
|
* Copyright (C) 2005, 2006 Paul Mundt
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
2010-06-02 03:10:00 -06:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-07-18 02:25:09 -06:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/io.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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2007-07-18 02:25:09 -06:00
|
|
|
#include <linux/interrupt.h>
|
2008-10-01 01:13:54 -06:00
|
|
|
#include <linux/sh_intc.h>
|
2009-04-01 08:30:59 -06:00
|
|
|
#include <linux/sysdev.h>
|
|
|
|
#include <linux/list.h>
|
2009-06-11 01:33:09 -06:00
|
|
|
#include <linux/topology.h>
|
2009-11-01 18:30:26 -07:00
|
|
|
#include <linux/bitmap.h>
|
2010-03-07 21:33:17 -07:00
|
|
|
#include <linux/cpumask.h>
|
2010-04-12 23:43:03 -06:00
|
|
|
#include <asm/sizes.h>
|
2007-08-12 00:26:12 -06:00
|
|
|
|
|
|
|
#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
|
|
|
|
((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
|
|
|
|
((addr_e) << 16) | ((addr_d << 24)))
|
|
|
|
|
|
|
|
#define _INTC_SHIFT(h) (h & 0x1f)
|
|
|
|
#define _INTC_WIDTH(h) ((h >> 5) & 0xf)
|
|
|
|
#define _INTC_FN(h) ((h >> 9) & 0xf)
|
|
|
|
#define _INTC_MODE(h) ((h >> 13) & 0x7)
|
|
|
|
#define _INTC_ADDR_E(h) ((h >> 16) & 0xff)
|
|
|
|
#define _INTC_ADDR_D(h) ((h >> 24) & 0xff)
|
|
|
|
|
|
|
|
struct intc_handle_int {
|
|
|
|
unsigned int irq;
|
|
|
|
unsigned long handle;
|
|
|
|
};
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-03-19 01:48:01 -06:00
|
|
|
struct intc_window {
|
|
|
|
phys_addr_t phys;
|
|
|
|
void __iomem *virt;
|
|
|
|
unsigned long size;
|
|
|
|
};
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
struct intc_desc_int {
|
2009-04-01 08:30:59 -06:00
|
|
|
struct list_head list;
|
|
|
|
struct sys_device sysdev;
|
2009-04-06 01:17:04 -06:00
|
|
|
pm_message_t state;
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned long *reg;
|
2007-09-21 03:16:42 -06:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
unsigned long *smp;
|
|
|
|
#endif
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned int nr_reg;
|
|
|
|
struct intc_handle_int *prio;
|
|
|
|
unsigned int nr_prio;
|
|
|
|
struct intc_handle_int *sense;
|
|
|
|
unsigned int nr_sense;
|
2010-03-19 01:48:01 -06:00
|
|
|
struct intc_window *window;
|
|
|
|
unsigned int nr_windows;
|
2007-08-12 00:26:12 -06:00
|
|
|
struct irq_chip chip;
|
|
|
|
};
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2009-04-01 08:30:59 -06:00
|
|
|
static LIST_HEAD(intc_list);
|
|
|
|
|
2009-11-01 18:30:26 -07:00
|
|
|
/*
|
|
|
|
* The intc_irq_map provides a global map of bound IRQ vectors for a
|
|
|
|
* given platform. Allocation of IRQs are either static through the CPU
|
|
|
|
* vector map, or dynamic in the case of board mux vectors or MSI.
|
|
|
|
*
|
|
|
|
* As this is a central point for all IRQ controllers on the system,
|
|
|
|
* each of the available sources are mapped out here. This combined with
|
|
|
|
* sparseirq makes it quite trivial to keep the vector map tightly packed
|
|
|
|
* when dynamically creating IRQs, as well as tying in to otherwise
|
|
|
|
* unused irq_desc positions in the sparse array.
|
|
|
|
*/
|
|
|
|
static DECLARE_BITMAP(intc_irq_map, NR_IRQS);
|
|
|
|
static DEFINE_SPINLOCK(vector_lock);
|
|
|
|
|
2007-09-21 03:16:42 -06:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#define IS_SMP(x) x.smp
|
|
|
|
#define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
|
|
|
|
#define SMP_NR(d, x) ((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)
|
|
|
|
#else
|
|
|
|
#define IS_SMP(x) 0
|
|
|
|
#define INTC_REG(d, x, c) (d->reg[(x)])
|
|
|
|
#define SMP_NR(d, x) 1
|
|
|
|
#endif
|
|
|
|
|
2010-04-12 23:43:03 -06:00
|
|
|
static unsigned int intc_prio_level[NR_IRQS]; /* for now */
|
|
|
|
static unsigned int default_prio_level = 2; /* 2 - 16 */
|
2008-04-24 06:36:34 -06:00
|
|
|
static unsigned long ack_handle[NR_IRQS];
|
2010-04-14 22:13:52 -06:00
|
|
|
#ifdef CONFIG_INTC_BALANCING
|
|
|
|
static unsigned long dist_handle[NR_IRQS];
|
|
|
|
#endif
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
|
|
|
struct irq_chip *chip = get_irq_chip(irq);
|
2009-08-24 03:27:33 -06:00
|
|
|
return container_of(chip, struct intc_desc_int, chip);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
static unsigned long intc_phys_to_virt(struct intc_desc_int *d,
|
|
|
|
unsigned long address)
|
|
|
|
{
|
|
|
|
struct intc_window *window;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
/* scan through physical windows and convert address */
|
|
|
|
for (k = 0; k < d->nr_windows; k++) {
|
|
|
|
window = d->window + k;
|
|
|
|
|
|
|
|
if (address < window->phys)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (address >= (window->phys + window->size))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
address -= window->phys;
|
|
|
|
address += (unsigned long)window->virt;
|
|
|
|
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no windows defined, register must be 1:1 mapped virt:phys */
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address)
|
|
|
|
{
|
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
address = intc_phys_to_virt(d, address);
|
|
|
|
|
|
|
|
for (k = 0; k < d->nr_reg; k++) {
|
|
|
|
if (d->reg[k] == address)
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-18 02:25:09 -06:00
|
|
|
static inline unsigned int set_field(unsigned int value,
|
|
|
|
unsigned int field_value,
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned int handle)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned int width = _INTC_WIDTH(handle);
|
|
|
|
unsigned int shift = _INTC_SHIFT(handle);
|
|
|
|
|
2007-07-18 02:25:09 -06:00
|
|
|
value &= ~(((1 << width) - 1) << shift);
|
|
|
|
value |= field_value << shift;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void write_8(unsigned long addr, unsigned long h, unsigned long data)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_writeb(set_field(0, data, h), addr);
|
2009-08-24 03:27:33 -06:00
|
|
|
(void)__raw_readb(addr); /* Defeat write posting */
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void write_16(unsigned long addr, unsigned long h, unsigned long data)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_writew(set_field(0, data, h), addr);
|
2009-08-24 03:27:33 -06:00
|
|
|
(void)__raw_readw(addr); /* Defeat write posting */
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void write_32(unsigned long addr, unsigned long h, unsigned long data)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_writel(set_field(0, data, h), addr);
|
2009-08-24 03:27:33 -06:00
|
|
|
(void)__raw_readl(addr); /* Defeat write posting */
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void modify_8(unsigned long addr, unsigned long h, unsigned long data)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2008-04-24 06:53:07 -06:00
|
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_writeb(set_field(__raw_readb(addr), data, h), addr);
|
2009-08-24 03:27:33 -06:00
|
|
|
(void)__raw_readb(addr); /* Defeat write posting */
|
2008-04-24 06:53:07 -06:00
|
|
|
local_irq_restore(flags);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void modify_16(unsigned long addr, unsigned long h, unsigned long data)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2008-04-24 06:53:07 -06:00
|
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_writew(set_field(__raw_readw(addr), data, h), addr);
|
2009-08-24 03:27:33 -06:00
|
|
|
(void)__raw_readw(addr); /* Defeat write posting */
|
2008-04-24 06:53:07 -06:00
|
|
|
local_irq_restore(flags);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void modify_32(unsigned long addr, unsigned long h, unsigned long data)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2008-04-24 06:53:07 -06:00
|
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_writel(set_field(__raw_readl(addr), data, h), addr);
|
2009-08-24 03:27:33 -06:00
|
|
|
(void)__raw_readl(addr); /* Defeat write posting */
|
2008-04-24 06:53:07 -06:00
|
|
|
local_irq_restore(flags);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
enum { REG_FN_ERR = 0, REG_FN_WRITE_BASE = 1, REG_FN_MODIFY_BASE = 5 };
|
|
|
|
|
|
|
|
static void (*intc_reg_fns[])(unsigned long addr,
|
|
|
|
unsigned long h,
|
|
|
|
unsigned long data) = {
|
|
|
|
[REG_FN_WRITE_BASE + 0] = write_8,
|
|
|
|
[REG_FN_WRITE_BASE + 1] = write_16,
|
|
|
|
[REG_FN_WRITE_BASE + 3] = write_32,
|
|
|
|
[REG_FN_MODIFY_BASE + 0] = modify_8,
|
|
|
|
[REG_FN_MODIFY_BASE + 1] = modify_16,
|
|
|
|
[REG_FN_MODIFY_BASE + 3] = modify_32,
|
|
|
|
};
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
enum { MODE_ENABLE_REG = 0, /* Bit(s) set -> interrupt enabled */
|
|
|
|
MODE_MASK_REG, /* Bit(s) set -> interrupt disabled */
|
|
|
|
MODE_DUAL_REG, /* Two registers, set bit to enable / disable */
|
|
|
|
MODE_PRIO_REG, /* Priority value written to enable interrupt */
|
|
|
|
MODE_PCLR_REG, /* Above plus all bits set to disable interrupt */
|
|
|
|
};
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void intc_mode_field(unsigned long addr,
|
|
|
|
unsigned long handle,
|
|
|
|
void (*fn)(unsigned long,
|
|
|
|
unsigned long,
|
|
|
|
unsigned long),
|
|
|
|
unsigned int irq)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
fn(addr, handle, ((1 << _INTC_WIDTH(handle)) - 1));
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void intc_mode_zero(unsigned long addr,
|
|
|
|
unsigned long handle,
|
|
|
|
void (*fn)(unsigned long,
|
|
|
|
unsigned long,
|
|
|
|
unsigned long),
|
|
|
|
unsigned int irq)
|
2007-08-02 23:25:32 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
fn(addr, handle, 0);
|
2007-08-02 23:25:32 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void intc_mode_prio(unsigned long addr,
|
|
|
|
unsigned long handle,
|
|
|
|
void (*fn)(unsigned long,
|
|
|
|
unsigned long,
|
|
|
|
unsigned long),
|
|
|
|
unsigned int irq)
|
2007-08-02 23:25:32 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
fn(addr, handle, intc_prio_level[irq]);
|
2007-08-02 23:25:32 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void (*intc_enable_fns[])(unsigned long addr,
|
|
|
|
unsigned long handle,
|
|
|
|
void (*fn)(unsigned long,
|
|
|
|
unsigned long,
|
|
|
|
unsigned long),
|
|
|
|
unsigned int irq) = {
|
|
|
|
[MODE_ENABLE_REG] = intc_mode_field,
|
|
|
|
[MODE_MASK_REG] = intc_mode_zero,
|
|
|
|
[MODE_DUAL_REG] = intc_mode_field,
|
|
|
|
[MODE_PRIO_REG] = intc_mode_prio,
|
|
|
|
[MODE_PCLR_REG] = intc_mode_prio,
|
|
|
|
};
|
2007-08-02 23:25:32 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void (*intc_disable_fns[])(unsigned long addr,
|
|
|
|
unsigned long handle,
|
|
|
|
void (*fn)(unsigned long,
|
|
|
|
unsigned long,
|
|
|
|
unsigned long),
|
|
|
|
unsigned int irq) = {
|
|
|
|
[MODE_ENABLE_REG] = intc_mode_zero,
|
|
|
|
[MODE_MASK_REG] = intc_mode_field,
|
|
|
|
[MODE_DUAL_REG] = intc_mode_field,
|
|
|
|
[MODE_PRIO_REG] = intc_mode_zero,
|
|
|
|
[MODE_PCLR_REG] = intc_mode_field,
|
|
|
|
};
|
2007-08-02 23:25:32 -06:00
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
#ifdef CONFIG_INTC_BALANCING
|
|
|
|
static inline void intc_balancing_enable(unsigned int irq)
|
|
|
|
{
|
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
|
|
|
unsigned long handle = dist_handle[irq];
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
if (irq_balancing_disabled(irq) || !handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
|
|
|
|
intc_reg_fns[_INTC_FN(handle)](addr, handle, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void intc_balancing_disable(unsigned int irq)
|
|
|
|
{
|
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
|
|
|
unsigned long handle = dist_handle[irq];
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
if (irq_balancing_disabled(irq) || !handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
|
|
|
|
intc_reg_fns[_INTC_FN(handle)](addr, handle, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int intc_dist_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id)
|
|
|
|
{
|
|
|
|
struct intc_mask_reg *mr = desc->hw.mask_regs;
|
|
|
|
unsigned int i, j, fn, mode;
|
|
|
|
unsigned long reg_e, reg_d;
|
|
|
|
|
|
|
|
for (i = 0; mr && enum_id && i < desc->hw.nr_mask_regs; i++) {
|
|
|
|
mr = desc->hw.mask_regs + i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip this entry if there's no auto-distribution
|
|
|
|
* register associated with it.
|
|
|
|
*/
|
|
|
|
if (!mr->dist_reg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) {
|
|
|
|
if (mr->enum_ids[j] != enum_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fn = REG_FN_MODIFY_BASE;
|
|
|
|
mode = MODE_ENABLE_REG;
|
|
|
|
reg_e = mr->dist_reg;
|
|
|
|
reg_d = mr->dist_reg;
|
|
|
|
|
|
|
|
fn += (mr->reg_width >> 3) - 1;
|
|
|
|
return _INTC_MK(fn, mode,
|
|
|
|
intc_get_reg(d, reg_e),
|
|
|
|
intc_get_reg(d, reg_d),
|
|
|
|
1,
|
|
|
|
(mr->reg_width - 1) - j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's possible we've gotten here with no distribution options
|
|
|
|
* available for the IRQ in question, so we just skip over those.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void intc_balancing_enable(unsigned int irq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void intc_balancing_disable(unsigned int irq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static inline void _intc_enable(unsigned int irq, unsigned long handle)
|
2007-08-02 23:25:32 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
2007-09-21 03:16:42 -06:00
|
|
|
unsigned long addr;
|
|
|
|
unsigned int cpu;
|
2007-08-02 23:25:32 -06:00
|
|
|
|
2007-09-21 03:16:42 -06:00
|
|
|
for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
|
2010-03-07 21:33:17 -07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (!cpumask_test_cpu(cpu, irq_to_desc(irq)->affinity))
|
|
|
|
continue;
|
|
|
|
#endif
|
2007-09-21 03:16:42 -06:00
|
|
|
addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
|
|
|
|
intc_enable_fns[_INTC_MODE(handle)](addr, handle, intc_reg_fns\
|
|
|
|
[_INTC_FN(handle)], irq);
|
|
|
|
}
|
2010-04-14 22:13:52 -06:00
|
|
|
|
|
|
|
intc_balancing_enable(irq);
|
2007-08-02 23:25:32 -06:00
|
|
|
}
|
|
|
|
|
2007-07-18 02:25:09 -06:00
|
|
|
static void intc_enable(unsigned int irq)
|
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
_intc_enable(irq, (unsigned long)get_irq_chip_data(irq));
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void intc_disable(unsigned int irq)
|
|
|
|
{
|
2007-09-21 03:16:42 -06:00
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
2010-04-14 22:13:52 -06:00
|
|
|
unsigned long handle = (unsigned long)get_irq_chip_data(irq);
|
2007-09-21 03:16:42 -06:00
|
|
|
unsigned long addr;
|
|
|
|
unsigned int cpu;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
intc_balancing_disable(irq);
|
|
|
|
|
2007-09-21 03:16:42 -06:00
|
|
|
for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
|
2010-03-07 21:33:17 -07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (!cpumask_test_cpu(cpu, irq_to_desc(irq)->affinity))
|
|
|
|
continue;
|
|
|
|
#endif
|
2007-09-21 03:16:42 -06:00
|
|
|
addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
|
|
|
|
intc_disable_fns[_INTC_MODE(handle)](addr, handle,intc_reg_fns\
|
|
|
|
[_INTC_FN(handle)], irq);
|
|
|
|
}
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
static void (*intc_enable_noprio_fns[])(unsigned long addr,
|
|
|
|
unsigned long handle,
|
|
|
|
void (*fn)(unsigned long,
|
|
|
|
unsigned long,
|
|
|
|
unsigned long),
|
|
|
|
unsigned int irq) = {
|
|
|
|
[MODE_ENABLE_REG] = intc_mode_field,
|
|
|
|
[MODE_MASK_REG] = intc_mode_zero,
|
|
|
|
[MODE_DUAL_REG] = intc_mode_field,
|
|
|
|
[MODE_PRIO_REG] = intc_mode_field,
|
|
|
|
[MODE_PCLR_REG] = intc_mode_field,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void intc_enable_disable(struct intc_desc_int *d,
|
|
|
|
unsigned long handle, int do_enable)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
unsigned int cpu;
|
|
|
|
void (*fn)(unsigned long, unsigned long,
|
|
|
|
void (*)(unsigned long, unsigned long, unsigned long),
|
|
|
|
unsigned int);
|
|
|
|
|
|
|
|
if (do_enable) {
|
|
|
|
for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
|
|
|
|
addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
|
|
|
|
fn = intc_enable_noprio_fns[_INTC_MODE(handle)];
|
|
|
|
fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
|
|
|
|
addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
|
|
|
|
fn = intc_disable_fns[_INTC_MODE(handle)];
|
|
|
|
fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-01 08:30:59 -06:00
|
|
|
static int intc_set_wake(unsigned int irq, unsigned int on)
|
|
|
|
{
|
|
|
|
return 0; /* allow wakeup, but setup hardware in intc_suspend() */
|
|
|
|
}
|
|
|
|
|
2010-03-07 21:33:17 -07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/*
|
|
|
|
* This is held with the irq desc lock held, so we don't require any
|
|
|
|
* additional locking here at the intc desc level. The affinity mask is
|
|
|
|
* later tested in the enable/disable paths.
|
|
|
|
*/
|
|
|
|
static int intc_set_affinity(unsigned int irq, const struct cpumask *cpumask)
|
|
|
|
{
|
|
|
|
if (!cpumask_intersects(cpumask, cpu_online_mask))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
cpumask_copy(irq_to_desc(irq)->affinity, cpumask);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-24 06:36:34 -06:00
|
|
|
static void intc_mask_ack(unsigned int irq)
|
|
|
|
{
|
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
|
|
|
unsigned long handle = ack_handle[irq];
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
intc_disable(irq);
|
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
/* read register and write zero only to the associated bit */
|
2008-04-24 06:36:34 -06:00
|
|
|
if (handle) {
|
|
|
|
addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
|
2008-07-03 21:37:12 -06:00
|
|
|
switch (_INTC_FN(handle)) {
|
|
|
|
case REG_FN_MODIFY_BASE + 0: /* 8bit */
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_readb(addr);
|
|
|
|
__raw_writeb(0xff ^ set_field(0, 1, handle), addr);
|
2008-07-03 21:37:12 -06:00
|
|
|
break;
|
|
|
|
case REG_FN_MODIFY_BASE + 1: /* 16bit */
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_readw(addr);
|
|
|
|
__raw_writew(0xffff ^ set_field(0, 1, handle), addr);
|
2008-07-03 21:37:12 -06:00
|
|
|
break;
|
|
|
|
case REG_FN_MODIFY_BASE + 3: /* 32bit */
|
2008-10-01 00:19:10 -06:00
|
|
|
__raw_readl(addr);
|
|
|
|
__raw_writel(0xffffffff ^ set_field(0, 1, handle), addr);
|
2008-07-03 21:37:12 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
break;
|
|
|
|
}
|
2008-04-24 06:36:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,
|
|
|
|
unsigned int nr_hp,
|
|
|
|
unsigned int irq)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
int i;
|
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
/*
|
|
|
|
* this doesn't scale well, but...
|
2007-08-16 09:50:44 -06:00
|
|
|
*
|
|
|
|
* this function should only be used for cerain uncommon
|
|
|
|
* operations such as intc_set_priority() and intc_set_sense()
|
|
|
|
* and in those rare cases performance doesn't matter that much.
|
|
|
|
* keeping the memory footprint low is more important.
|
|
|
|
*
|
|
|
|
* one rather simple way to speed this up and still keep the
|
|
|
|
* memory footprint down is to make sure the array is sorted
|
|
|
|
* and then perform a bisect to lookup the irq.
|
|
|
|
*/
|
2007-08-12 00:26:12 -06:00
|
|
|
for (i = 0; i < nr_hp; i++) {
|
|
|
|
if ((hp + i)->irq != irq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return hp + i;
|
|
|
|
}
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
return NULL;
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
int intc_set_priority(unsigned int irq, unsigned int prio)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
|
|
|
struct intc_handle_int *ihp;
|
|
|
|
|
|
|
|
if (!intc_prio_level[irq] || prio <= 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ihp = intc_find_irq(d->prio, d->nr_prio, irq);
|
|
|
|
if (ihp) {
|
2007-08-16 09:50:44 -06:00
|
|
|
if (prio >= (1 << _INTC_WIDTH(ihp->handle)))
|
2007-08-12 00:26:12 -06:00
|
|
|
return -EINVAL;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
intc_prio_level[irq] = prio;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only set secondary masking method directly
|
|
|
|
* primary masking method is using intc_prio_level[irq]
|
|
|
|
* priority level will be set during next enable()
|
|
|
|
*/
|
2007-08-16 09:50:44 -06:00
|
|
|
if (_INTC_FN(ihp->handle) != REG_FN_ERR)
|
2007-08-12 00:26:12 -06:00
|
|
|
_intc_enable(irq, ihp->handle);
|
|
|
|
}
|
|
|
|
return 0;
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#define VALID(x) (x | 0x80)
|
|
|
|
|
|
|
|
static unsigned char intc_irq_sense_table[IRQ_TYPE_SENSE_MASK + 1] = {
|
|
|
|
[IRQ_TYPE_EDGE_FALLING] = VALID(0),
|
|
|
|
[IRQ_TYPE_EDGE_RISING] = VALID(1),
|
|
|
|
[IRQ_TYPE_LEVEL_LOW] = VALID(2),
|
2008-04-24 06:47:15 -06:00
|
|
|
/* SH7706, SH7707 and SH7709 do not support high level triggered */
|
|
|
|
#if !defined(CONFIG_CPU_SUBTYPE_SH7706) && \
|
|
|
|
!defined(CONFIG_CPU_SUBTYPE_SH7707) && \
|
|
|
|
!defined(CONFIG_CPU_SUBTYPE_SH7709)
|
2007-07-18 02:25:09 -06:00
|
|
|
[IRQ_TYPE_LEVEL_HIGH] = VALID(3),
|
2008-04-24 06:47:15 -06:00
|
|
|
#endif
|
2007-07-18 02:25:09 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static int intc_set_sense(unsigned int irq, unsigned int type)
|
|
|
|
{
|
2007-08-12 00:26:12 -06:00
|
|
|
struct intc_desc_int *d = get_intc_desc(irq);
|
2007-07-18 02:25:09 -06:00
|
|
|
unsigned char value = intc_irq_sense_table[type & IRQ_TYPE_SENSE_MASK];
|
2007-08-12 00:26:12 -06:00
|
|
|
struct intc_handle_int *ihp;
|
|
|
|
unsigned long addr;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
if (!value)
|
2007-07-18 02:25:09 -06:00
|
|
|
return -EINVAL;
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
ihp = intc_find_irq(d->sense, d->nr_sense, irq);
|
|
|
|
if (ihp) {
|
2007-09-21 03:16:42 -06:00
|
|
|
addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0);
|
2007-08-12 00:26:12 -06:00
|
|
|
intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, value);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
2007-08-12 00:26:12 -06:00
|
|
|
return 0;
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static intc_enum __init intc_grp_id(struct intc_desc *desc,
|
|
|
|
intc_enum enum_id)
|
2007-07-19 21:09:29 -06:00
|
|
|
{
|
2010-02-08 21:24:46 -07:00
|
|
|
struct intc_group *g = desc->hw.groups;
|
2007-07-19 21:09:29 -06:00
|
|
|
unsigned int i, j;
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
for (i = 0; g && enum_id && i < desc->hw.nr_groups; i++) {
|
|
|
|
g = desc->hw.groups + i;
|
2007-07-19 21:09:29 -06:00
|
|
|
|
|
|
|
for (j = 0; g->enum_ids[j]; j++) {
|
|
|
|
if (g->enum_ids[j] != enum_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return g->enum_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
static unsigned int __init _intc_mask_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id,
|
|
|
|
unsigned int *reg_idx,
|
|
|
|
unsigned int *fld_idx)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2010-02-08 21:24:46 -07:00
|
|
|
struct intc_mask_reg *mr = desc->hw.mask_regs;
|
2010-02-08 21:29:22 -07:00
|
|
|
unsigned int fn, mode;
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned long reg_e, reg_d;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
while (mr && enum_id && *reg_idx < desc->hw.nr_mask_regs) {
|
|
|
|
mr = desc->hw.mask_regs + *reg_idx;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
for (; *fld_idx < ARRAY_SIZE(mr->enum_ids); (*fld_idx)++) {
|
|
|
|
if (mr->enum_ids[*fld_idx] != enum_id)
|
2007-07-18 02:25:09 -06:00
|
|
|
continue;
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
if (mr->set_reg && mr->clr_reg) {
|
|
|
|
fn = REG_FN_WRITE_BASE;
|
|
|
|
mode = MODE_DUAL_REG;
|
|
|
|
reg_e = mr->clr_reg;
|
|
|
|
reg_d = mr->set_reg;
|
|
|
|
} else {
|
|
|
|
fn = REG_FN_MODIFY_BASE;
|
|
|
|
if (mr->set_reg) {
|
|
|
|
mode = MODE_ENABLE_REG;
|
|
|
|
reg_e = mr->set_reg;
|
|
|
|
reg_d = mr->set_reg;
|
|
|
|
} else {
|
|
|
|
mode = MODE_MASK_REG;
|
|
|
|
reg_e = mr->clr_reg;
|
|
|
|
reg_d = mr->clr_reg;
|
|
|
|
}
|
2007-08-02 23:25:32 -06:00
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
fn += (mr->reg_width >> 3) - 1;
|
|
|
|
return _INTC_MK(fn, mode,
|
|
|
|
intc_get_reg(d, reg_e),
|
|
|
|
intc_get_reg(d, reg_d),
|
|
|
|
1,
|
2010-02-08 21:29:22 -07:00
|
|
|
(mr->reg_width - 1) - *fld_idx);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
2010-02-08 21:29:22 -07:00
|
|
|
|
|
|
|
*fld_idx = 0;
|
|
|
|
(*reg_idx)++;
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int __init intc_mask_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id, int do_grps)
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int j = 0;
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
ret = _intc_mask_data(desc, d, enum_id, &i, &j);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2007-07-19 21:09:29 -06:00
|
|
|
if (do_grps)
|
2007-08-12 00:26:12 -06:00
|
|
|
return intc_mask_data(desc, d, intc_grp_id(desc, enum_id), 0);
|
2007-07-19 21:09:29 -06:00
|
|
|
|
2007-07-18 02:25:09 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
static unsigned int __init _intc_prio_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id,
|
|
|
|
unsigned int *reg_idx,
|
|
|
|
unsigned int *fld_idx)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2010-02-08 21:24:46 -07:00
|
|
|
struct intc_prio_reg *pr = desc->hw.prio_regs;
|
2010-02-08 21:29:22 -07:00
|
|
|
unsigned int fn, n, mode, bit;
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned long reg_e, reg_d;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
while (pr && enum_id && *reg_idx < desc->hw.nr_prio_regs) {
|
|
|
|
pr = desc->hw.prio_regs + *reg_idx;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
for (; *fld_idx < ARRAY_SIZE(pr->enum_ids); (*fld_idx)++) {
|
|
|
|
if (pr->enum_ids[*fld_idx] != enum_id)
|
2007-07-18 02:25:09 -06:00
|
|
|
continue;
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
if (pr->set_reg && pr->clr_reg) {
|
|
|
|
fn = REG_FN_WRITE_BASE;
|
|
|
|
mode = MODE_PCLR_REG;
|
|
|
|
reg_e = pr->set_reg;
|
|
|
|
reg_d = pr->clr_reg;
|
|
|
|
} else {
|
|
|
|
fn = REG_FN_MODIFY_BASE;
|
|
|
|
mode = MODE_PRIO_REG;
|
|
|
|
if (!pr->set_reg)
|
|
|
|
BUG();
|
|
|
|
reg_e = pr->set_reg;
|
|
|
|
reg_d = pr->set_reg;
|
|
|
|
}
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
fn += (pr->reg_width >> 3) - 1;
|
2010-02-08 21:29:22 -07:00
|
|
|
n = *fld_idx + 1;
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
BUG_ON(n * pr->field_width > pr->reg_width);
|
2008-09-09 15:02:43 -06:00
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
bit = pr->reg_width - (n * pr->field_width);
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
return _INTC_MK(fn, mode,
|
|
|
|
intc_get_reg(d, reg_e),
|
|
|
|
intc_get_reg(d, reg_d),
|
|
|
|
pr->field_width, bit);
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
2010-02-08 21:29:22 -07:00
|
|
|
|
|
|
|
*fld_idx = 0;
|
|
|
|
(*reg_idx)++;
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int __init intc_prio_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id, int do_grps)
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int j = 0;
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
ret = _intc_prio_data(desc, d, enum_id, &i, &j);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2007-07-19 21:09:29 -06:00
|
|
|
if (do_grps)
|
2007-08-12 00:26:12 -06:00
|
|
|
return intc_prio_data(desc, d, intc_grp_id(desc, enum_id), 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:29:22 -07:00
|
|
|
static void __init intc_enable_disable_enum(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id, int enable)
|
|
|
|
{
|
|
|
|
unsigned int i, j, data;
|
|
|
|
|
|
|
|
/* go through and enable/disable all mask bits */
|
|
|
|
i = j = 0;
|
|
|
|
do {
|
|
|
|
data = _intc_mask_data(desc, d, enum_id, &i, &j);
|
|
|
|
if (data)
|
|
|
|
intc_enable_disable(d, data, enable);
|
|
|
|
j++;
|
|
|
|
} while (data);
|
|
|
|
|
|
|
|
/* go through and enable/disable all priority fields */
|
|
|
|
i = j = 0;
|
|
|
|
do {
|
|
|
|
data = _intc_prio_data(desc, d, enum_id, &i, &j);
|
|
|
|
if (data)
|
|
|
|
intc_enable_disable(d, data, enable);
|
|
|
|
|
|
|
|
j++;
|
|
|
|
} while (data);
|
|
|
|
}
|
|
|
|
|
2008-04-24 06:36:34 -06:00
|
|
|
static unsigned int __init intc_ack_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id)
|
|
|
|
{
|
2010-02-08 21:24:46 -07:00
|
|
|
struct intc_mask_reg *mr = desc->hw.ack_regs;
|
2008-04-24 06:36:34 -06:00
|
|
|
unsigned int i, j, fn, mode;
|
|
|
|
unsigned long reg_e, reg_d;
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
for (i = 0; mr && enum_id && i < desc->hw.nr_ack_regs; i++) {
|
|
|
|
mr = desc->hw.ack_regs + i;
|
2008-04-24 06:36:34 -06:00
|
|
|
|
|
|
|
for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) {
|
|
|
|
if (mr->enum_ids[j] != enum_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fn = REG_FN_MODIFY_BASE;
|
|
|
|
mode = MODE_ENABLE_REG;
|
|
|
|
reg_e = mr->set_reg;
|
|
|
|
reg_d = mr->set_reg;
|
|
|
|
|
|
|
|
fn += (mr->reg_width >> 3) - 1;
|
|
|
|
return _INTC_MK(fn, mode,
|
|
|
|
intc_get_reg(d, reg_e),
|
|
|
|
intc_get_reg(d, reg_d),
|
|
|
|
1,
|
|
|
|
(mr->reg_width - 1) - j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static unsigned int __init intc_sense_data(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id)
|
|
|
|
{
|
2010-02-08 21:24:46 -07:00
|
|
|
struct intc_sense_reg *sr = desc->hw.sense_regs;
|
2007-08-12 00:26:12 -06:00
|
|
|
unsigned int i, j, fn, bit;
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
for (i = 0; sr && enum_id && i < desc->hw.nr_sense_regs; i++) {
|
|
|
|
sr = desc->hw.sense_regs + i;
|
2007-08-12 00:26:12 -06:00
|
|
|
|
|
|
|
for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) {
|
|
|
|
if (sr->enum_ids[j] != enum_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fn = REG_FN_MODIFY_BASE;
|
|
|
|
fn += (sr->reg_width >> 3) - 1;
|
|
|
|
|
2008-09-09 15:02:43 -06:00
|
|
|
BUG_ON((j + 1) * sr->field_width > sr->reg_width);
|
|
|
|
|
|
|
|
bit = sr->reg_width - ((j + 1) * sr->field_width);
|
2007-08-12 00:26:12 -06:00
|
|
|
|
|
|
|
return _INTC_MK(fn, 0, intc_get_reg(d, sr->reg),
|
|
|
|
0, sr->field_width, bit);
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 21:09:29 -06:00
|
|
|
|
2007-07-18 02:25:09 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
static void __init intc_register_irq(struct intc_desc *desc,
|
|
|
|
struct intc_desc_int *d,
|
|
|
|
intc_enum enum_id,
|
2007-07-18 02:25:09 -06:00
|
|
|
unsigned int irq)
|
|
|
|
{
|
2007-08-16 09:50:44 -06:00
|
|
|
struct intc_handle_int *hp;
|
2007-07-19 21:09:29 -06:00
|
|
|
unsigned int data[2], primary;
|
|
|
|
|
2009-11-01 18:30:26 -07:00
|
|
|
/*
|
|
|
|
* Register the IRQ position with the global IRQ map
|
|
|
|
*/
|
|
|
|
set_bit(irq, intc_irq_map);
|
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
/*
|
|
|
|
* Prefer single interrupt source bitmap over other combinations:
|
|
|
|
*
|
2007-07-19 21:09:29 -06:00
|
|
|
* 1. bitmap, single interrupt source
|
|
|
|
* 2. priority, single interrupt source
|
|
|
|
* 3. bitmap, multiple interrupt sources (groups)
|
|
|
|
* 4. priority, multiple interrupt sources (groups)
|
|
|
|
*/
|
2007-08-12 00:26:12 -06:00
|
|
|
data[0] = intc_mask_data(desc, d, enum_id, 0);
|
|
|
|
data[1] = intc_prio_data(desc, d, enum_id, 0);
|
2007-07-19 21:09:29 -06:00
|
|
|
|
|
|
|
primary = 0;
|
|
|
|
if (!data[0] && data[1])
|
|
|
|
primary = 1;
|
|
|
|
|
2009-02-24 06:58:57 -07:00
|
|
|
if (!data[0] && !data[1])
|
2010-06-02 03:10:00 -06:00
|
|
|
pr_warning("missing unique irq mask for irq %d (vect 0x%04x)\n",
|
|
|
|
irq, irq2evt(irq));
|
2009-02-24 06:58:57 -07:00
|
|
|
|
2007-08-12 00:26:12 -06:00
|
|
|
data[0] = data[0] ? data[0] : intc_mask_data(desc, d, enum_id, 1);
|
|
|
|
data[1] = data[1] ? data[1] : intc_prio_data(desc, d, enum_id, 1);
|
2007-07-19 21:09:29 -06:00
|
|
|
|
|
|
|
if (!data[primary])
|
|
|
|
primary ^= 1;
|
|
|
|
|
|
|
|
BUG_ON(!data[primary]); /* must have primary masking method */
|
2007-07-18 02:25:09 -06:00
|
|
|
|
|
|
|
disable_irq_nosync(irq);
|
2007-08-12 00:26:12 -06:00
|
|
|
set_irq_chip_and_handler_name(irq, &d->chip,
|
2007-07-18 02:25:09 -06:00
|
|
|
handle_level_irq, "level");
|
2007-07-19 21:09:29 -06:00
|
|
|
set_irq_chip_data(irq, (void *)data[primary]);
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
/*
|
|
|
|
* set priority level
|
2008-01-09 22:08:55 -07:00
|
|
|
* - this needs to be at least 2 for 5-bit priorities on 7780
|
|
|
|
*/
|
2010-04-12 23:43:03 -06:00
|
|
|
intc_prio_level[irq] = default_prio_level;
|
2007-08-12 00:26:12 -06:00
|
|
|
|
2007-07-19 21:09:29 -06:00
|
|
|
/* enable secondary masking method if present */
|
|
|
|
if (data[!primary])
|
2007-08-12 00:26:12 -06:00
|
|
|
_intc_enable(irq, data[!primary]);
|
|
|
|
|
|
|
|
/* add irq to d->prio list if priority is available */
|
|
|
|
if (data[1]) {
|
2007-08-16 09:50:44 -06:00
|
|
|
hp = d->prio + d->nr_prio;
|
|
|
|
hp->irq = irq;
|
|
|
|
hp->handle = data[1];
|
|
|
|
|
|
|
|
if (primary) {
|
|
|
|
/*
|
|
|
|
* only secondary priority should access registers, so
|
|
|
|
* set _INTC_FN(h) = REG_FN_ERR for intc_set_priority()
|
|
|
|
*/
|
|
|
|
hp->handle &= ~_INTC_MK(0x0f, 0, 0, 0, 0, 0);
|
|
|
|
hp->handle |= _INTC_MK(REG_FN_ERR, 0, 0, 0, 0, 0);
|
|
|
|
}
|
2007-08-12 00:26:12 -06:00
|
|
|
d->nr_prio++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add irq to d->sense list if sense is available */
|
|
|
|
data[0] = intc_sense_data(desc, d, enum_id);
|
|
|
|
if (data[0]) {
|
|
|
|
(d->sense + d->nr_sense)->irq = irq;
|
|
|
|
(d->sense + d->nr_sense)->handle = data[0];
|
|
|
|
d->nr_sense++;
|
|
|
|
}
|
2007-07-18 02:25:09 -06:00
|
|
|
|
|
|
|
/* irq should be disabled by default */
|
2007-08-12 00:26:12 -06:00
|
|
|
d->chip.mask(irq);
|
2008-04-24 06:36:34 -06:00
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
if (desc->hw.ack_regs)
|
2008-04-24 06:36:34 -06:00
|
|
|
ack_handle[irq] = intc_ack_data(desc, d, enum_id);
|
2010-02-05 04:15:25 -07:00
|
|
|
|
2010-04-14 22:13:52 -06:00
|
|
|
#ifdef CONFIG_INTC_BALANCING
|
|
|
|
if (desc->hw.mask_regs)
|
|
|
|
dist_handle[irq] = intc_dist_data(desc, d, enum_id);
|
|
|
|
#endif
|
|
|
|
|
2010-02-05 04:15:25 -07:00
|
|
|
#ifdef CONFIG_ARM
|
|
|
|
set_irq_flags(irq, IRQF_VALID); /* Enable IRQ on ARM systems */
|
|
|
|
#endif
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
|
|
|
|
2007-09-21 03:16:42 -06:00
|
|
|
static unsigned int __init save_reg(struct intc_desc_int *d,
|
|
|
|
unsigned int cnt,
|
|
|
|
unsigned long value,
|
|
|
|
unsigned int smp)
|
|
|
|
{
|
|
|
|
if (value) {
|
2010-03-19 01:48:01 -06:00
|
|
|
value = intc_phys_to_virt(d, value);
|
|
|
|
|
2007-09-21 03:16:42 -06:00
|
|
|
d->reg[cnt] = value;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
d->smp[cnt] = smp;
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-24 04:52:38 -06:00
|
|
|
static void intc_redirect_irq(unsigned int irq, struct irq_desc *desc)
|
2009-02-24 06:58:57 -07:00
|
|
|
{
|
2009-08-24 04:52:38 -06:00
|
|
|
generic_handle_irq((unsigned int)get_irq_data(irq));
|
2009-02-24 06:58:57 -07:00
|
|
|
}
|
2007-09-21 03:16:42 -06:00
|
|
|
|
2010-03-10 02:31:01 -07:00
|
|
|
int __init register_intc_controller(struct intc_desc *desc)
|
2007-07-18 02:25:09 -06:00
|
|
|
{
|
2009-06-11 01:33:09 -06:00
|
|
|
unsigned int i, k, smp;
|
2010-02-08 21:24:46 -07:00
|
|
|
struct intc_hw_desc *hw = &desc->hw;
|
2007-08-12 00:26:12 -06:00
|
|
|
struct intc_desc_int *d;
|
2010-03-19 01:48:01 -06:00
|
|
|
struct resource *res;
|
2007-08-12 00:26:12 -06:00
|
|
|
|
2010-06-02 03:10:00 -06:00
|
|
|
pr_info("Registered controller '%s' with %u IRQs\n",
|
2010-04-12 22:49:54 -06:00
|
|
|
desc->name, hw->nr_vectors);
|
|
|
|
|
2009-06-11 16:34:12 -06:00
|
|
|
d = kzalloc(sizeof(*d), GFP_NOWAIT);
|
2010-03-10 02:31:01 -07:00
|
|
|
if (!d)
|
|
|
|
goto err0;
|
2007-08-12 00:26:12 -06:00
|
|
|
|
2009-04-01 08:30:59 -06:00
|
|
|
INIT_LIST_HEAD(&d->list);
|
|
|
|
list_add(&d->list, &intc_list);
|
|
|
|
|
2010-03-19 01:48:01 -06:00
|
|
|
if (desc->num_resources) {
|
|
|
|
d->nr_windows = desc->num_resources;
|
|
|
|
d->window = kzalloc(d->nr_windows * sizeof(*d->window),
|
|
|
|
GFP_NOWAIT);
|
|
|
|
if (!d->window)
|
|
|
|
goto err1;
|
|
|
|
|
|
|
|
for (k = 0; k < d->nr_windows; k++) {
|
|
|
|
res = desc->resource + k;
|
|
|
|
WARN_ON(resource_type(res) != IORESOURCE_MEM);
|
|
|
|
d->window[k].phys = res->start;
|
|
|
|
d->window[k].size = resource_size(res);
|
|
|
|
d->window[k].virt = ioremap_nocache(res->start,
|
|
|
|
resource_size(res));
|
|
|
|
if (!d->window[k].virt)
|
|
|
|
goto err2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
d->nr_reg = hw->mask_regs ? hw->nr_mask_regs * 2 : 0;
|
2010-04-14 22:13:52 -06:00
|
|
|
#ifdef CONFIG_INTC_BALANCING
|
|
|
|
if (d->nr_reg)
|
|
|
|
d->nr_reg += hw->nr_mask_regs;
|
|
|
|
#endif
|
2010-02-08 21:24:46 -07:00
|
|
|
d->nr_reg += hw->prio_regs ? hw->nr_prio_regs * 2 : 0;
|
|
|
|
d->nr_reg += hw->sense_regs ? hw->nr_sense_regs : 0;
|
|
|
|
d->nr_reg += hw->ack_regs ? hw->nr_ack_regs : 0;
|
2009-10-26 20:36:43 -06:00
|
|
|
|
2009-06-11 16:34:12 -06:00
|
|
|
d->reg = kzalloc(d->nr_reg * sizeof(*d->reg), GFP_NOWAIT);
|
2010-03-10 02:31:01 -07:00
|
|
|
if (!d->reg)
|
2010-03-19 01:48:01 -06:00
|
|
|
goto err2;
|
2010-03-10 02:31:01 -07:00
|
|
|
|
2007-09-21 03:16:42 -06:00
|
|
|
#ifdef CONFIG_SMP
|
2009-06-11 16:34:12 -06:00
|
|
|
d->smp = kzalloc(d->nr_reg * sizeof(*d->smp), GFP_NOWAIT);
|
2010-03-10 02:31:01 -07:00
|
|
|
if (!d->smp)
|
2010-03-19 01:48:01 -06:00
|
|
|
goto err3;
|
2007-09-21 03:16:42 -06:00
|
|
|
#endif
|
2007-08-12 00:26:12 -06:00
|
|
|
k = 0;
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
if (hw->mask_regs) {
|
|
|
|
for (i = 0; i < hw->nr_mask_regs; i++) {
|
|
|
|
smp = IS_SMP(hw->mask_regs[i]);
|
|
|
|
k += save_reg(d, k, hw->mask_regs[i].set_reg, smp);
|
|
|
|
k += save_reg(d, k, hw->mask_regs[i].clr_reg, smp);
|
2010-04-14 22:13:52 -06:00
|
|
|
#ifdef CONFIG_INTC_BALANCING
|
|
|
|
k += save_reg(d, k, hw->mask_regs[i].dist_reg, 0);
|
|
|
|
#endif
|
2007-08-12 00:26:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
if (hw->prio_regs) {
|
|
|
|
d->prio = kzalloc(hw->nr_vectors * sizeof(*d->prio),
|
|
|
|
GFP_NOWAIT);
|
2010-03-10 02:31:01 -07:00
|
|
|
if (!d->prio)
|
2010-03-19 01:48:01 -06:00
|
|
|
goto err4;
|
2007-08-12 00:26:12 -06:00
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
for (i = 0; i < hw->nr_prio_regs; i++) {
|
|
|
|
smp = IS_SMP(hw->prio_regs[i]);
|
|
|
|
k += save_reg(d, k, hw->prio_regs[i].set_reg, smp);
|
|
|
|
k += save_reg(d, k, hw->prio_regs[i].clr_reg, smp);
|
2007-08-12 00:26:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
if (hw->sense_regs) {
|
|
|
|
d->sense = kzalloc(hw->nr_vectors * sizeof(*d->sense),
|
|
|
|
GFP_NOWAIT);
|
2010-03-10 02:31:01 -07:00
|
|
|
if (!d->sense)
|
2010-03-19 01:48:01 -06:00
|
|
|
goto err5;
|
2007-08-12 00:26:12 -06:00
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
for (i = 0; i < hw->nr_sense_regs; i++)
|
|
|
|
k += save_reg(d, k, hw->sense_regs[i].reg, 0);
|
2007-08-12 00:26:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
d->chip.name = desc->name;
|
|
|
|
d->chip.mask = intc_disable;
|
|
|
|
d->chip.unmask = intc_enable;
|
|
|
|
d->chip.mask_ack = intc_disable;
|
2009-04-01 08:20:58 -06:00
|
|
|
d->chip.enable = intc_enable;
|
|
|
|
d->chip.disable = intc_disable;
|
|
|
|
d->chip.shutdown = intc_disable;
|
2007-08-12 00:26:12 -06:00
|
|
|
d->chip.set_type = intc_set_sense;
|
2009-04-01 08:30:59 -06:00
|
|
|
d->chip.set_wake = intc_set_wake;
|
2010-03-07 21:33:17 -07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
d->chip.set_affinity = intc_set_affinity;
|
|
|
|
#endif
|
2007-07-18 02:25:09 -06:00
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
if (hw->ack_regs) {
|
|
|
|
for (i = 0; i < hw->nr_ack_regs; i++)
|
|
|
|
k += save_reg(d, k, hw->ack_regs[i].set_reg, 0);
|
2008-04-24 06:36:34 -06:00
|
|
|
|
|
|
|
d->chip.mask_ack = intc_mask_ack;
|
|
|
|
}
|
|
|
|
|
2010-02-15 04:40:25 -07:00
|
|
|
/* disable bits matching force_disable before registering irqs */
|
|
|
|
if (desc->force_disable)
|
|
|
|
intc_enable_disable_enum(desc, d, desc->force_disable, 0);
|
2010-02-08 21:29:22 -07:00
|
|
|
|
|
|
|
/* disable bits matching force_enable before registering irqs */
|
|
|
|
if (desc->force_enable)
|
|
|
|
intc_enable_disable_enum(desc, d, desc->force_enable, 0);
|
|
|
|
|
2008-04-24 06:36:34 -06:00
|
|
|
BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */
|
|
|
|
|
2009-02-24 06:58:57 -07:00
|
|
|
/* register the vectors one by one */
|
2010-02-08 21:24:46 -07:00
|
|
|
for (i = 0; i < hw->nr_vectors; i++) {
|
|
|
|
struct intc_vect *vect = hw->vectors + i;
|
2009-05-21 10:28:33 -06:00
|
|
|
unsigned int irq = evt2irq(vect->vect);
|
|
|
|
struct irq_desc *irq_desc;
|
2009-06-11 01:33:09 -06:00
|
|
|
|
2009-02-24 06:58:57 -07:00
|
|
|
if (!vect->enum_id)
|
|
|
|
continue;
|
|
|
|
|
2009-06-11 01:33:09 -06:00
|
|
|
irq_desc = irq_to_desc_alloc_node(irq, numa_node_id());
|
2009-05-21 10:28:33 -06:00
|
|
|
if (unlikely(!irq_desc)) {
|
2010-04-12 22:49:54 -06:00
|
|
|
pr_err("can't get irq_desc for %d\n", irq);
|
2009-05-21 10:28:33 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
intc_register_irq(desc, d, vect->enum_id, irq);
|
2009-08-24 04:52:38 -06:00
|
|
|
|
2010-02-08 21:24:46 -07:00
|
|
|
for (k = i + 1; k < hw->nr_vectors; k++) {
|
|
|
|
struct intc_vect *vect2 = hw->vectors + k;
|
2009-08-24 04:52:38 -06:00
|
|
|
unsigned int irq2 = evt2irq(vect2->vect);
|
|
|
|
|
|
|
|
if (vect->enum_id != vect2->enum_id)
|
|
|
|
continue;
|
|
|
|
|
2009-08-31 00:15:33 -06:00
|
|
|
/*
|
|
|
|
* In the case of multi-evt handling and sparse
|
|
|
|
* IRQ support, each vector still needs to have
|
|
|
|
* its own backing irq_desc.
|
|
|
|
*/
|
|
|
|
irq_desc = irq_to_desc_alloc_node(irq2, numa_node_id());
|
|
|
|
if (unlikely(!irq_desc)) {
|
2010-04-12 22:49:54 -06:00
|
|
|
pr_err("can't get irq_desc for %d\n", irq2);
|
2009-08-31 00:15:33 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-24 04:52:38 -06:00
|
|
|
vect2->enum_id = 0;
|
|
|
|
|
|
|
|
/* redirect this interrupts to the first one */
|
2010-02-16 20:37:42 -07:00
|
|
|
set_irq_chip(irq2, &dummy_irq_chip);
|
2010-02-09 00:17:20 -07:00
|
|
|
set_irq_chained_handler(irq2, intc_redirect_irq);
|
2009-08-24 04:52:38 -06:00
|
|
|
set_irq_data(irq2, (void *)irq);
|
|
|
|
}
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
2010-02-08 21:29:22 -07:00
|
|
|
|
|
|
|
/* enable bits matching force_enable after registering irqs */
|
|
|
|
if (desc->force_enable)
|
|
|
|
intc_enable_disable_enum(desc, d, desc->force_enable, 1);
|
2010-03-10 02:31:01 -07:00
|
|
|
|
|
|
|
return 0;
|
2010-03-19 01:48:01 -06:00
|
|
|
err5:
|
2010-03-10 02:31:01 -07:00
|
|
|
kfree(d->prio);
|
2010-03-19 01:48:01 -06:00
|
|
|
err4:
|
2010-03-10 02:31:01 -07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
kfree(d->smp);
|
2010-03-19 01:48:01 -06:00
|
|
|
err3:
|
2010-03-10 02:31:01 -07:00
|
|
|
#endif
|
|
|
|
kfree(d->reg);
|
2010-03-19 01:48:01 -06:00
|
|
|
err2:
|
|
|
|
for (k = 0; k < d->nr_windows; k++)
|
|
|
|
if (d->window[k].virt)
|
|
|
|
iounmap(d->window[k].virt);
|
|
|
|
|
|
|
|
kfree(d->window);
|
|
|
|
err1:
|
2010-03-10 02:31:01 -07:00
|
|
|
kfree(d);
|
2010-03-19 01:48:01 -06:00
|
|
|
err0:
|
2010-03-10 02:31:01 -07:00
|
|
|
pr_err("unable to allocate INTC memory\n");
|
|
|
|
|
|
|
|
return -ENOMEM;
|
2007-07-18 02:25:09 -06:00
|
|
|
}
|
2009-04-01 08:30:59 -06:00
|
|
|
|
2010-04-12 23:43:03 -06:00
|
|
|
#ifdef CONFIG_INTC_USERIMASK
|
|
|
|
static void __iomem *uimask;
|
|
|
|
|
|
|
|
int register_intc_userimask(unsigned long addr)
|
|
|
|
{
|
|
|
|
if (unlikely(uimask))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
uimask = ioremap_nocache(addr, SZ_4K);
|
|
|
|
if (unlikely(!uimask))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-06-02 03:10:00 -06:00
|
|
|
pr_info("userimask support registered for levels 0 -> %d\n",
|
2010-04-12 23:43:03 -06:00
|
|
|
default_prio_level - 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
show_intc_userimask(struct sysdev_class *cls,
|
|
|
|
struct sysdev_class_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
store_intc_userimask(struct sysdev_class *cls,
|
|
|
|
struct sysdev_class_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
unsigned long level;
|
|
|
|
|
|
|
|
level = simple_strtoul(buf, NULL, 10);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimal acceptable IRQ levels are in the 2 - 16 range, but
|
|
|
|
* these are chomped so as to not interfere with normal IRQs.
|
|
|
|
*
|
|
|
|
* Level 1 is a special case on some CPUs in that it's not
|
|
|
|
* directly settable, but given that USERIMASK cuts off below a
|
|
|
|
* certain level, we don't care about this limitation here.
|
|
|
|
* Level 0 on the other hand equates to user masking disabled.
|
|
|
|
*
|
|
|
|
* We use default_prio_level as a cut off so that only special
|
|
|
|
* case opt-in IRQs can be mangled.
|
|
|
|
*/
|
|
|
|
if (level >= default_prio_level)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
__raw_writel(0xa5 << 24 | level << 4, uimask);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SYSDEV_CLASS_ATTR(userimask, S_IRUSR | S_IWUSR,
|
|
|
|
show_intc_userimask, store_intc_userimask);
|
|
|
|
#endif
|
|
|
|
|
2010-04-12 19:16:34 -06:00
|
|
|
static ssize_t
|
|
|
|
show_intc_name(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct intc_desc_int *d;
|
|
|
|
|
|
|
|
d = container_of(dev, struct intc_desc_int, sysdev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", d->chip.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SYSDEV_ATTR(name, S_IRUGO, show_intc_name, NULL);
|
|
|
|
|
2009-04-01 08:30:59 -06:00
|
|
|
static int intc_suspend(struct sys_device *dev, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct intc_desc_int *d;
|
|
|
|
struct irq_desc *desc;
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
/* get intc controller associated with this sysdev */
|
|
|
|
d = container_of(dev, struct intc_desc_int, sysdev);
|
|
|
|
|
2009-04-06 01:17:04 -06:00
|
|
|
switch (state.event) {
|
|
|
|
case PM_EVENT_ON:
|
|
|
|
if (d->state.event != PM_EVENT_FREEZE)
|
|
|
|
break;
|
|
|
|
for_each_irq_desc(irq, desc) {
|
2009-12-04 01:57:58 -07:00
|
|
|
if (desc->handle_irq == intc_redirect_irq)
|
2009-12-08 22:36:16 -07:00
|
|
|
continue;
|
2009-04-06 01:17:04 -06:00
|
|
|
if (desc->chip != &d->chip)
|
|
|
|
continue;
|
|
|
|
if (desc->status & IRQ_DISABLED)
|
|
|
|
intc_disable(irq);
|
|
|
|
else
|
|
|
|
intc_enable(irq);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PM_EVENT_FREEZE:
|
|
|
|
/* nothing has to be done */
|
|
|
|
break;
|
|
|
|
case PM_EVENT_SUSPEND:
|
|
|
|
/* enable wakeup irqs belonging to this intc controller */
|
|
|
|
for_each_irq_desc(irq, desc) {
|
|
|
|
if ((desc->status & IRQ_WAKEUP) && (desc->chip == &d->chip))
|
|
|
|
intc_enable(irq);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-01 08:30:59 -06:00
|
|
|
}
|
2009-04-06 01:17:04 -06:00
|
|
|
d->state = state;
|
2009-04-01 08:30:59 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-06 01:17:04 -06:00
|
|
|
static int intc_resume(struct sys_device *dev)
|
|
|
|
{
|
|
|
|
return intc_suspend(dev, PMSG_ON);
|
|
|
|
}
|
|
|
|
|
2009-04-01 08:30:59 -06:00
|
|
|
static struct sysdev_class intc_sysdev_class = {
|
|
|
|
.name = "intc",
|
|
|
|
.suspend = intc_suspend,
|
2009-04-06 01:17:04 -06:00
|
|
|
.resume = intc_resume,
|
2009-04-01 08:30:59 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* register this intc as sysdev to allow suspend/resume */
|
|
|
|
static int __init register_intc_sysdevs(void)
|
|
|
|
{
|
|
|
|
struct intc_desc_int *d;
|
|
|
|
int error;
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
error = sysdev_class_register(&intc_sysdev_class);
|
2010-04-12 23:43:03 -06:00
|
|
|
#ifdef CONFIG_INTC_USERIMASK
|
|
|
|
if (!error && uimask)
|
|
|
|
error = sysdev_class_create_file(&intc_sysdev_class,
|
|
|
|
&attr_userimask);
|
|
|
|
#endif
|
2009-04-01 08:30:59 -06:00
|
|
|
if (!error) {
|
|
|
|
list_for_each_entry(d, &intc_list, list) {
|
|
|
|
d->sysdev.id = id;
|
|
|
|
d->sysdev.cls = &intc_sysdev_class;
|
|
|
|
error = sysdev_register(&d->sysdev);
|
2010-04-12 19:16:34 -06:00
|
|
|
if (error == 0)
|
|
|
|
error = sysdev_create_file(&d->sysdev,
|
|
|
|
&attr_name);
|
2009-04-01 08:30:59 -06:00
|
|
|
if (error)
|
|
|
|
break;
|
2010-04-12 19:16:34 -06:00
|
|
|
|
2009-04-01 08:30:59 -06:00
|
|
|
id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
2010-06-02 03:10:00 -06:00
|
|
|
pr_err("sysdev registration error\n");
|
2009-04-01 08:30:59 -06:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
device_initcall(register_intc_sysdevs);
|
2009-11-01 18:30:26 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dynamic IRQ allocation and deallocation
|
|
|
|
*/
|
2010-02-02 01:35:13 -07:00
|
|
|
unsigned int create_irq_nr(unsigned int irq_want, int node)
|
2009-11-01 18:30:26 -07:00
|
|
|
{
|
|
|
|
unsigned int irq = 0, new;
|
|
|
|
unsigned long flags;
|
|
|
|
struct irq_desc *desc;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vector_lock, flags);
|
|
|
|
|
|
|
|
/*
|
2010-02-02 01:35:13 -07:00
|
|
|
* First try the wanted IRQ
|
2009-11-01 18:30:26 -07:00
|
|
|
*/
|
2010-02-02 01:35:13 -07:00
|
|
|
if (test_and_set_bit(irq_want, intc_irq_map) == 0) {
|
|
|
|
new = irq_want;
|
|
|
|
} else {
|
|
|
|
/* .. then fall back to scanning. */
|
2009-11-01 18:30:26 -07:00
|
|
|
new = find_first_zero_bit(intc_irq_map, nr_irqs);
|
|
|
|
if (unlikely(new == nr_irqs))
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
__set_bit(new, intc_irq_map);
|
|
|
|
}
|
|
|
|
|
2010-02-02 01:35:13 -07:00
|
|
|
desc = irq_to_desc_alloc_node(new, node);
|
|
|
|
if (unlikely(!desc)) {
|
2010-04-12 22:49:54 -06:00
|
|
|
pr_err("can't get irq_desc for %d\n", new);
|
2010-02-02 01:35:13 -07:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = move_irq_desc(desc, node);
|
|
|
|
irq = new;
|
|
|
|
|
2009-11-01 18:30:26 -07:00
|
|
|
out_unlock:
|
|
|
|
spin_unlock_irqrestore(&vector_lock, flags);
|
|
|
|
|
2010-02-05 04:15:25 -07:00
|
|
|
if (irq > 0) {
|
2009-11-01 18:30:26 -07:00
|
|
|
dynamic_irq_init(irq);
|
2010-02-05 04:15:25 -07:00
|
|
|
#ifdef CONFIG_ARM
|
|
|
|
set_irq_flags(irq, IRQF_VALID); /* Enable IRQ on ARM systems */
|
|
|
|
#endif
|
|
|
|
}
|
2009-11-01 18:30:26 -07:00
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
int create_irq(void)
|
|
|
|
{
|
|
|
|
int nid = cpu_to_node(smp_processor_id());
|
|
|
|
int irq;
|
|
|
|
|
2010-02-02 01:35:13 -07:00
|
|
|
irq = create_irq_nr(NR_IRQS_LEGACY, nid);
|
2009-11-01 18:30:26 -07:00
|
|
|
if (irq == 0)
|
|
|
|
irq = -1;
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_irq(unsigned int irq)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
dynamic_irq_cleanup(irq);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vector_lock, flags);
|
|
|
|
__clear_bit(irq, intc_irq_map);
|
|
|
|
spin_unlock_irqrestore(&vector_lock, flags);
|
|
|
|
}
|
2009-11-01 23:43:20 -07:00
|
|
|
|
|
|
|
int reserve_irq_vector(unsigned int irq)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vector_lock, flags);
|
|
|
|
if (test_and_set_bit(irq, intc_irq_map))
|
|
|
|
ret = -EBUSY;
|
|
|
|
spin_unlock_irqrestore(&vector_lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reserve_irq_legacy(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vector_lock, flags);
|
|
|
|
j = find_first_bit(intc_irq_map, nr_irqs);
|
|
|
|
for (i = 0; i < j; i++)
|
|
|
|
__set_bit(i, intc_irq_map);
|
|
|
|
spin_unlock_irqrestore(&vector_lock, flags);
|
|
|
|
}
|