mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-09-08 01:08:03 -04:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
43
drivers/sh/intc/Kconfig
Normal file
43
drivers/sh/intc/Kconfig
Normal file
|
@ -0,0 +1,43 @@
|
|||
config SH_INTC
|
||||
bool
|
||||
select IRQ_DOMAIN
|
||||
|
||||
if SH_INTC
|
||||
|
||||
comment "Interrupt controller options"
|
||||
|
||||
config INTC_USERIMASK
|
||||
bool "Userspace interrupt masking support"
|
||||
depends on (SUPERH && CPU_SH4A) || COMPILE_TEST
|
||||
help
|
||||
This enables support for hardware-assisted userspace hardirq
|
||||
masking.
|
||||
|
||||
SH-4A and newer interrupt blocks all support a special shadowed
|
||||
page with all non-masking registers obscured when mapped in to
|
||||
userspace. This is primarily for use by userspace device
|
||||
drivers that are using special priority levels.
|
||||
|
||||
If in doubt, say N.
|
||||
|
||||
config INTC_BALANCING
|
||||
bool "Hardware IRQ balancing support"
|
||||
depends on SMP && SUPERH && CPU_SHX3
|
||||
help
|
||||
This enables support for IRQ auto-distribution mode on SH-X3
|
||||
SMP parts. All of the balancing and CPU wakeup decisions are
|
||||
taken care of automatically by hardware for distributed
|
||||
vectors.
|
||||
|
||||
If in doubt, say N.
|
||||
|
||||
config INTC_MAPPING_DEBUG
|
||||
bool "Expose IRQ to per-controller id mapping via debugfs"
|
||||
depends on DEBUG_FS
|
||||
help
|
||||
This will create a debugfs entry for showing the relationship
|
||||
between system IRQs and the per-controller id tables.
|
||||
|
||||
If in doubt, say N.
|
||||
|
||||
endif
|
5
drivers/sh/intc/Makefile
Normal file
5
drivers/sh/intc/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
obj-y := access.o chip.o core.o handle.o irqdomain.o virq.o
|
||||
|
||||
obj-$(CONFIG_INTC_BALANCING) += balancing.o
|
||||
obj-$(CONFIG_INTC_USERIMASK) += userimask.o
|
||||
obj-$(CONFIG_INTC_MAPPING_DEBUG) += virq-debugfs.o
|
246
drivers/sh/intc/access.c
Normal file
246
drivers/sh/intc/access.c
Normal file
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* Common INTC2 register accessors
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Magnus Damm
|
||||
* Copyright (C) 2009, 2010 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.
|
||||
*/
|
||||
#include <linux/io.h>
|
||||
#include "internals.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
unsigned int intc_set_field_from_handle(unsigned int value,
|
||||
unsigned int field_value,
|
||||
unsigned int handle)
|
||||
{
|
||||
unsigned int width = _INTC_WIDTH(handle);
|
||||
unsigned int shift = _INTC_SHIFT(handle);
|
||||
|
||||
value &= ~(((1 << width) - 1) << shift);
|
||||
value |= field_value << shift;
|
||||
return value;
|
||||
}
|
||||
|
||||
unsigned long intc_get_field_from_handle(unsigned int value, unsigned int handle)
|
||||
{
|
||||
unsigned int width = _INTC_WIDTH(handle);
|
||||
unsigned int shift = _INTC_SHIFT(handle);
|
||||
unsigned int mask = ((1 << width) - 1) << shift;
|
||||
|
||||
return (value & mask) >> shift;
|
||||
}
|
||||
|
||||
static unsigned long test_8(unsigned long addr, unsigned long h,
|
||||
unsigned long ignore)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
return intc_get_field_from_handle(__raw_readb(ptr), h);
|
||||
}
|
||||
|
||||
static unsigned long test_16(unsigned long addr, unsigned long h,
|
||||
unsigned long ignore)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
return intc_get_field_from_handle(__raw_readw(ptr), h);
|
||||
}
|
||||
|
||||
static unsigned long test_32(unsigned long addr, unsigned long h,
|
||||
unsigned long ignore)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
return intc_get_field_from_handle(__raw_readl(ptr), h);
|
||||
}
|
||||
|
||||
static unsigned long write_8(unsigned long addr, unsigned long h,
|
||||
unsigned long data)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
__raw_writeb(intc_set_field_from_handle(0, data, h), ptr);
|
||||
(void)__raw_readb(ptr); /* Defeat write posting */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long write_16(unsigned long addr, unsigned long h,
|
||||
unsigned long data)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
__raw_writew(intc_set_field_from_handle(0, data, h), ptr);
|
||||
(void)__raw_readw(ptr); /* Defeat write posting */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long write_32(unsigned long addr, unsigned long h,
|
||||
unsigned long data)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
__raw_writel(intc_set_field_from_handle(0, data, h), ptr);
|
||||
(void)__raw_readl(ptr); /* Defeat write posting */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long modify_8(unsigned long addr, unsigned long h,
|
||||
unsigned long data)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
unsigned long flags;
|
||||
unsigned int value;
|
||||
local_irq_save(flags);
|
||||
value = intc_set_field_from_handle(__raw_readb(ptr), data, h);
|
||||
__raw_writeb(value, ptr);
|
||||
(void)__raw_readb(ptr); /* Defeat write posting */
|
||||
local_irq_restore(flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long modify_16(unsigned long addr, unsigned long h,
|
||||
unsigned long data)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
unsigned long flags;
|
||||
unsigned int value;
|
||||
local_irq_save(flags);
|
||||
value = intc_set_field_from_handle(__raw_readw(ptr), data, h);
|
||||
__raw_writew(value, ptr);
|
||||
(void)__raw_readw(ptr); /* Defeat write posting */
|
||||
local_irq_restore(flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long modify_32(unsigned long addr, unsigned long h,
|
||||
unsigned long data)
|
||||
{
|
||||
void __iomem *ptr = (void __iomem *)addr;
|
||||
unsigned long flags;
|
||||
unsigned int value;
|
||||
local_irq_save(flags);
|
||||
value = intc_set_field_from_handle(__raw_readl(ptr), data, h);
|
||||
__raw_writel(value, ptr);
|
||||
(void)__raw_readl(ptr); /* Defeat write posting */
|
||||
local_irq_restore(flags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long intc_mode_field(unsigned long addr,
|
||||
unsigned long handle,
|
||||
unsigned long (*fn)(unsigned long,
|
||||
unsigned long,
|
||||
unsigned long),
|
||||
unsigned int irq)
|
||||
{
|
||||
return fn(addr, handle, ((1 << _INTC_WIDTH(handle)) - 1));
|
||||
}
|
||||
|
||||
static unsigned long intc_mode_zero(unsigned long addr,
|
||||
unsigned long handle,
|
||||
unsigned long (*fn)(unsigned long,
|
||||
unsigned long,
|
||||
unsigned long),
|
||||
unsigned int irq)
|
||||
{
|
||||
return fn(addr, handle, 0);
|
||||
}
|
||||
|
||||
static unsigned long intc_mode_prio(unsigned long addr,
|
||||
unsigned long handle,
|
||||
unsigned long (*fn)(unsigned long,
|
||||
unsigned long,
|
||||
unsigned long),
|
||||
unsigned int irq)
|
||||
{
|
||||
return fn(addr, handle, intc_get_prio_level(irq));
|
||||
}
|
||||
|
||||
unsigned long (*intc_reg_fns[])(unsigned long addr,
|
||||
unsigned long h,
|
||||
unsigned long data) = {
|
||||
[REG_FN_TEST_BASE + 0] = test_8,
|
||||
[REG_FN_TEST_BASE + 1] = test_16,
|
||||
[REG_FN_TEST_BASE + 3] = test_32,
|
||||
[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,
|
||||
};
|
||||
|
||||
unsigned long (*intc_enable_fns[])(unsigned long addr,
|
||||
unsigned long handle,
|
||||
unsigned long (*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,
|
||||
};
|
||||
|
||||
unsigned long (*intc_disable_fns[])(unsigned long addr,
|
||||
unsigned long handle,
|
||||
unsigned long (*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,
|
||||
};
|
||||
|
||||
unsigned long (*intc_enable_noprio_fns[])(unsigned long addr,
|
||||
unsigned long handle,
|
||||
unsigned long (*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,
|
||||
};
|
97
drivers/sh/intc/balancing.c
Normal file
97
drivers/sh/intc/balancing.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Support for hardware-managed IRQ auto-distribution.
|
||||
*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
#include "internals.h"
|
||||
|
||||
static unsigned long dist_handle[INTC_NR_IRQS];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
|
||||
struct intc_desc_int *d, intc_enum id)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
/*
|
||||
* Nothing to do for this IRQ.
|
||||
*/
|
||||
if (!desc->hw.mask_regs)
|
||||
return;
|
||||
|
||||
raw_spin_lock_irqsave(&intc_big_lock, flags);
|
||||
dist_handle[irq] = intc_dist_data(desc, d, id);
|
||||
raw_spin_unlock_irqrestore(&intc_big_lock, flags);
|
||||
}
|
211
drivers/sh/intc/chip.c
Normal file
211
drivers/sh/intc/chip.c
Normal file
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* IRQ chip definitions for INTC IRQs.
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Magnus Damm
|
||||
* Copyright (C) 2009 - 2012 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.
|
||||
*/
|
||||
#include <linux/cpumask.h>
|
||||
#include <linux/bsearch.h>
|
||||
#include <linux/io.h>
|
||||
#include "internals.h"
|
||||
|
||||
void _intc_enable(struct irq_data *data, unsigned long handle)
|
||||
{
|
||||
unsigned int irq = data->irq;
|
||||
struct intc_desc_int *d = get_intc_desc(irq);
|
||||
unsigned long addr;
|
||||
unsigned int cpu;
|
||||
|
||||
for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
|
||||
#ifdef CONFIG_SMP
|
||||
if (!cpumask_test_cpu(cpu, data->affinity))
|
||||
continue;
|
||||
#endif
|
||||
addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
|
||||
intc_enable_fns[_INTC_MODE(handle)](addr, handle, intc_reg_fns\
|
||||
[_INTC_FN(handle)], irq);
|
||||
}
|
||||
|
||||
intc_balancing_enable(irq);
|
||||
}
|
||||
|
||||
static void intc_enable(struct irq_data *data)
|
||||
{
|
||||
_intc_enable(data, (unsigned long)irq_data_get_irq_chip_data(data));
|
||||
}
|
||||
|
||||
static void intc_disable(struct irq_data *data)
|
||||
{
|
||||
unsigned int irq = data->irq;
|
||||
struct intc_desc_int *d = get_intc_desc(irq);
|
||||
unsigned long handle = (unsigned long)irq_data_get_irq_chip_data(data);
|
||||
unsigned long addr;
|
||||
unsigned int cpu;
|
||||
|
||||
intc_balancing_disable(irq);
|
||||
|
||||
for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
|
||||
#ifdef CONFIG_SMP
|
||||
if (!cpumask_test_cpu(cpu, data->affinity))
|
||||
continue;
|
||||
#endif
|
||||
addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
|
||||
intc_disable_fns[_INTC_MODE(handle)](addr, handle,intc_reg_fns\
|
||||
[_INTC_FN(handle)], irq);
|
||||
}
|
||||
}
|
||||
|
||||
#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(struct irq_data *data,
|
||||
const struct cpumask *cpumask,
|
||||
bool force)
|
||||
{
|
||||
if (!cpumask_intersects(cpumask, cpu_online_mask))
|
||||
return -1;
|
||||
|
||||
cpumask_copy(data->affinity, cpumask);
|
||||
|
||||
return IRQ_SET_MASK_OK_NOCOPY;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void intc_mask_ack(struct irq_data *data)
|
||||
{
|
||||
unsigned int irq = data->irq;
|
||||
struct intc_desc_int *d = get_intc_desc(irq);
|
||||
unsigned long handle = intc_get_ack_handle(irq);
|
||||
void __iomem *addr;
|
||||
|
||||
intc_disable(data);
|
||||
|
||||
/* read register and write zero only to the associated bit */
|
||||
if (handle) {
|
||||
unsigned int value;
|
||||
|
||||
addr = (void __iomem *)INTC_REG(d, _INTC_ADDR_D(handle), 0);
|
||||
value = intc_set_field_from_handle(0, 1, handle);
|
||||
|
||||
switch (_INTC_FN(handle)) {
|
||||
case REG_FN_MODIFY_BASE + 0: /* 8bit */
|
||||
__raw_readb(addr);
|
||||
__raw_writeb(0xff ^ value, addr);
|
||||
break;
|
||||
case REG_FN_MODIFY_BASE + 1: /* 16bit */
|
||||
__raw_readw(addr);
|
||||
__raw_writew(0xffff ^ value, addr);
|
||||
break;
|
||||
case REG_FN_MODIFY_BASE + 3: /* 32bit */
|
||||
__raw_readl(addr);
|
||||
__raw_writel(0xffffffff ^ value, addr);
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,
|
||||
unsigned int nr_hp,
|
||||
unsigned int irq)
|
||||
{
|
||||
struct intc_handle_int key;
|
||||
|
||||
key.irq = irq;
|
||||
key.handle = 0;
|
||||
|
||||
return bsearch(&key, hp, nr_hp, sizeof(*hp), intc_handle_int_cmp);
|
||||
}
|
||||
|
||||
int intc_set_priority(unsigned int irq, unsigned int prio)
|
||||
{
|
||||
struct intc_desc_int *d = get_intc_desc(irq);
|
||||
struct irq_data *data = irq_get_irq_data(irq);
|
||||
struct intc_handle_int *ihp;
|
||||
|
||||
if (!intc_get_prio_level(irq) || prio <= 1)
|
||||
return -EINVAL;
|
||||
|
||||
ihp = intc_find_irq(d->prio, d->nr_prio, irq);
|
||||
if (ihp) {
|
||||
if (prio >= (1 << _INTC_WIDTH(ihp->handle)))
|
||||
return -EINVAL;
|
||||
|
||||
intc_set_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()
|
||||
*/
|
||||
if (_INTC_FN(ihp->handle) != REG_FN_ERR)
|
||||
_intc_enable(data, ihp->handle);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SENSE_VALID_FLAG 0x80
|
||||
#define VALID(x) (x | SENSE_VALID_FLAG)
|
||||
|
||||
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),
|
||||
/* 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)
|
||||
[IRQ_TYPE_LEVEL_HIGH] = VALID(3),
|
||||
#endif
|
||||
#if defined(CONFIG_ARM) /* all recent SH-Mobile / R-Mobile ARM support this */
|
||||
[IRQ_TYPE_EDGE_BOTH] = VALID(4),
|
||||
#endif
|
||||
};
|
||||
|
||||
static int intc_set_type(struct irq_data *data, unsigned int type)
|
||||
{
|
||||
unsigned int irq = data->irq;
|
||||
struct intc_desc_int *d = get_intc_desc(irq);
|
||||
unsigned char value = intc_irq_sense_table[type & IRQ_TYPE_SENSE_MASK];
|
||||
struct intc_handle_int *ihp;
|
||||
unsigned long addr;
|
||||
|
||||
if (!value)
|
||||
return -EINVAL;
|
||||
|
||||
value &= ~SENSE_VALID_FLAG;
|
||||
|
||||
ihp = intc_find_irq(d->sense, d->nr_sense, irq);
|
||||
if (ihp) {
|
||||
/* PINT has 2-bit sense registers, should fail on EDGE_BOTH */
|
||||
if (value >= (1 << _INTC_WIDTH(ihp->handle)))
|
||||
return -EINVAL;
|
||||
|
||||
addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0);
|
||||
intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct irq_chip intc_irq_chip = {
|
||||
.irq_mask = intc_disable,
|
||||
.irq_unmask = intc_enable,
|
||||
.irq_mask_ack = intc_mask_ack,
|
||||
.irq_enable = intc_enable,
|
||||
.irq_disable = intc_disable,
|
||||
.irq_set_type = intc_set_type,
|
||||
#ifdef CONFIG_SMP
|
||||
.irq_set_affinity = intc_set_affinity,
|
||||
#endif
|
||||
.flags = IRQCHIP_SKIP_SET_WAKE,
|
||||
};
|
511
drivers/sh/intc/core.c
Normal file
511
drivers/sh/intc/core.c
Normal file
|
@ -0,0 +1,511 @@
|
|||
/*
|
||||
* Shared interrupt handling code for IPR and INTC2 types of IRQs.
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Magnus Damm
|
||||
* Copyright (C) 2009 - 2012 Paul Mundt
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#define pr_fmt(fmt) "intc: " fmt
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/sh_intc.h>
|
||||
#include <linux/irqdomain.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/syscore_ops.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/radix-tree.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/sort.h>
|
||||
#include "internals.h"
|
||||
|
||||
LIST_HEAD(intc_list);
|
||||
DEFINE_RAW_SPINLOCK(intc_big_lock);
|
||||
static unsigned int nr_intc_controllers;
|
||||
|
||||
/*
|
||||
* Default priority level
|
||||
* - this needs to be at least 2 for 5-bit priorities on 7780
|
||||
*/
|
||||
static unsigned int default_prio_level = 2; /* 2 - 16 */
|
||||
static unsigned int intc_prio_level[INTC_NR_IRQS]; /* for now */
|
||||
|
||||
unsigned int intc_get_dfl_prio_level(void)
|
||||
{
|
||||
return default_prio_level;
|
||||
}
|
||||
|
||||
unsigned int intc_get_prio_level(unsigned int irq)
|
||||
{
|
||||
return intc_prio_level[irq];
|
||||
}
|
||||
|
||||
void intc_set_prio_level(unsigned int irq, unsigned int level)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
raw_spin_lock_irqsave(&intc_big_lock, flags);
|
||||
intc_prio_level[irq] = level;
|
||||
raw_spin_unlock_irqrestore(&intc_big_lock, flags);
|
||||
}
|
||||
|
||||
static void intc_redirect_irq(unsigned int irq, struct irq_desc *desc)
|
||||
{
|
||||
generic_handle_irq((unsigned int)irq_get_handler_data(irq));
|
||||
}
|
||||
|
||||
static void __init intc_register_irq(struct intc_desc *desc,
|
||||
struct intc_desc_int *d,
|
||||
intc_enum enum_id,
|
||||
unsigned int irq)
|
||||
{
|
||||
struct intc_handle_int *hp;
|
||||
struct irq_data *irq_data;
|
||||
unsigned int data[2], primary;
|
||||
unsigned long flags;
|
||||
|
||||
raw_spin_lock_irqsave(&intc_big_lock, flags);
|
||||
radix_tree_insert(&d->tree, enum_id, intc_irq_xlate_get(irq));
|
||||
raw_spin_unlock_irqrestore(&intc_big_lock, flags);
|
||||
|
||||
/*
|
||||
* Prefer single interrupt source bitmap over other combinations:
|
||||
*
|
||||
* 1. bitmap, single interrupt source
|
||||
* 2. priority, single interrupt source
|
||||
* 3. bitmap, multiple interrupt sources (groups)
|
||||
* 4. priority, multiple interrupt sources (groups)
|
||||
*/
|
||||
data[0] = intc_get_mask_handle(desc, d, enum_id, 0);
|
||||
data[1] = intc_get_prio_handle(desc, d, enum_id, 0);
|
||||
|
||||
primary = 0;
|
||||
if (!data[0] && data[1])
|
||||
primary = 1;
|
||||
|
||||
if (!data[0] && !data[1])
|
||||
pr_warning("missing unique irq mask for irq %d (vect 0x%04x)\n",
|
||||
irq, irq2evt(irq));
|
||||
|
||||
data[0] = data[0] ? data[0] : intc_get_mask_handle(desc, d, enum_id, 1);
|
||||
data[1] = data[1] ? data[1] : intc_get_prio_handle(desc, d, enum_id, 1);
|
||||
|
||||
if (!data[primary])
|
||||
primary ^= 1;
|
||||
|
||||
BUG_ON(!data[primary]); /* must have primary masking method */
|
||||
|
||||
irq_data = irq_get_irq_data(irq);
|
||||
|
||||
disable_irq_nosync(irq);
|
||||
irq_set_chip_and_handler_name(irq, &d->chip, handle_level_irq,
|
||||
"level");
|
||||
irq_set_chip_data(irq, (void *)data[primary]);
|
||||
|
||||
/*
|
||||
* set priority level
|
||||
*/
|
||||
intc_set_prio_level(irq, intc_get_dfl_prio_level());
|
||||
|
||||
/* enable secondary masking method if present */
|
||||
if (data[!primary])
|
||||
_intc_enable(irq_data, data[!primary]);
|
||||
|
||||
/* add irq to d->prio list if priority is available */
|
||||
if (data[1]) {
|
||||
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);
|
||||
}
|
||||
d->nr_prio++;
|
||||
}
|
||||
|
||||
/* add irq to d->sense list if sense is available */
|
||||
data[0] = intc_get_sense_handle(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++;
|
||||
}
|
||||
|
||||
/* irq should be disabled by default */
|
||||
d->chip.irq_mask(irq_data);
|
||||
|
||||
intc_set_ack_handle(irq, desc, d, enum_id);
|
||||
intc_set_dist_handle(irq, desc, d, enum_id);
|
||||
|
||||
activate_irq(irq);
|
||||
}
|
||||
|
||||
static unsigned int __init save_reg(struct intc_desc_int *d,
|
||||
unsigned int cnt,
|
||||
unsigned long value,
|
||||
unsigned int smp)
|
||||
{
|
||||
if (value) {
|
||||
value = intc_phys_to_virt(d, value);
|
||||
|
||||
d->reg[cnt] = value;
|
||||
#ifdef CONFIG_SMP
|
||||
d->smp[cnt] = smp;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init register_intc_controller(struct intc_desc *desc)
|
||||
{
|
||||
unsigned int i, k, smp;
|
||||
struct intc_hw_desc *hw = &desc->hw;
|
||||
struct intc_desc_int *d;
|
||||
struct resource *res;
|
||||
|
||||
pr_info("Registered controller '%s' with %u IRQs\n",
|
||||
desc->name, hw->nr_vectors);
|
||||
|
||||
d = kzalloc(sizeof(*d), GFP_NOWAIT);
|
||||
if (!d)
|
||||
goto err0;
|
||||
|
||||
INIT_LIST_HEAD(&d->list);
|
||||
list_add_tail(&d->list, &intc_list);
|
||||
|
||||
raw_spin_lock_init(&d->lock);
|
||||
INIT_RADIX_TREE(&d->tree, GFP_ATOMIC);
|
||||
|
||||
d->index = nr_intc_controllers;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
d->nr_reg = hw->mask_regs ? hw->nr_mask_regs * 2 : 0;
|
||||
#ifdef CONFIG_INTC_BALANCING
|
||||
if (d->nr_reg)
|
||||
d->nr_reg += hw->nr_mask_regs;
|
||||
#endif
|
||||
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;
|
||||
d->nr_reg += hw->subgroups ? hw->nr_subgroups : 0;
|
||||
|
||||
d->reg = kzalloc(d->nr_reg * sizeof(*d->reg), GFP_NOWAIT);
|
||||
if (!d->reg)
|
||||
goto err2;
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
d->smp = kzalloc(d->nr_reg * sizeof(*d->smp), GFP_NOWAIT);
|
||||
if (!d->smp)
|
||||
goto err3;
|
||||
#endif
|
||||
k = 0;
|
||||
|
||||
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);
|
||||
#ifdef CONFIG_INTC_BALANCING
|
||||
k += save_reg(d, k, hw->mask_regs[i].dist_reg, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (hw->prio_regs) {
|
||||
d->prio = kzalloc(hw->nr_vectors * sizeof(*d->prio),
|
||||
GFP_NOWAIT);
|
||||
if (!d->prio)
|
||||
goto err4;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
sort(d->prio, hw->nr_prio_regs, sizeof(*d->prio),
|
||||
intc_handle_int_cmp, NULL);
|
||||
}
|
||||
|
||||
if (hw->sense_regs) {
|
||||
d->sense = kzalloc(hw->nr_vectors * sizeof(*d->sense),
|
||||
GFP_NOWAIT);
|
||||
if (!d->sense)
|
||||
goto err5;
|
||||
|
||||
for (i = 0; i < hw->nr_sense_regs; i++)
|
||||
k += save_reg(d, k, hw->sense_regs[i].reg, 0);
|
||||
|
||||
sort(d->sense, hw->nr_sense_regs, sizeof(*d->sense),
|
||||
intc_handle_int_cmp, NULL);
|
||||
}
|
||||
|
||||
if (hw->subgroups)
|
||||
for (i = 0; i < hw->nr_subgroups; i++)
|
||||
if (hw->subgroups[i].reg)
|
||||
k+= save_reg(d, k, hw->subgroups[i].reg, 0);
|
||||
|
||||
memcpy(&d->chip, &intc_irq_chip, sizeof(struct irq_chip));
|
||||
d->chip.name = desc->name;
|
||||
|
||||
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);
|
||||
else
|
||||
d->chip.irq_mask_ack = d->chip.irq_disable;
|
||||
|
||||
/* disable bits matching force_disable before registering irqs */
|
||||
if (desc->force_disable)
|
||||
intc_enable_disable_enum(desc, d, desc->force_disable, 0);
|
||||
|
||||
/* disable bits matching force_enable before registering irqs */
|
||||
if (desc->force_enable)
|
||||
intc_enable_disable_enum(desc, d, desc->force_enable, 0);
|
||||
|
||||
BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */
|
||||
|
||||
intc_irq_domain_init(d, hw);
|
||||
|
||||
/* register the vectors one by one */
|
||||
for (i = 0; i < hw->nr_vectors; i++) {
|
||||
struct intc_vect *vect = hw->vectors + i;
|
||||
unsigned int irq = evt2irq(vect->vect);
|
||||
int res;
|
||||
|
||||
if (!vect->enum_id)
|
||||
continue;
|
||||
|
||||
res = irq_create_identity_mapping(d->domain, irq);
|
||||
if (unlikely(res)) {
|
||||
if (res == -EEXIST) {
|
||||
res = irq_domain_associate(d->domain, irq, irq);
|
||||
if (unlikely(res)) {
|
||||
pr_err("domain association failure\n");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
pr_err("can't identity map IRQ %d\n", irq);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
intc_irq_xlate_set(irq, vect->enum_id, d);
|
||||
intc_register_irq(desc, d, vect->enum_id, irq);
|
||||
|
||||
for (k = i + 1; k < hw->nr_vectors; k++) {
|
||||
struct intc_vect *vect2 = hw->vectors + k;
|
||||
unsigned int irq2 = evt2irq(vect2->vect);
|
||||
|
||||
if (vect->enum_id != vect2->enum_id)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* In the case of multi-evt handling and sparse
|
||||
* IRQ support, each vector still needs to have
|
||||
* its own backing irq_desc.
|
||||
*/
|
||||
res = irq_create_identity_mapping(d->domain, irq2);
|
||||
if (unlikely(res)) {
|
||||
if (res == -EEXIST) {
|
||||
res = irq_domain_associate(d->domain,
|
||||
irq2, irq2);
|
||||
if (unlikely(res)) {
|
||||
pr_err("domain association "
|
||||
"failure\n");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
pr_err("can't identity map IRQ %d\n",
|
||||
irq);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
vect2->enum_id = 0;
|
||||
|
||||
/* redirect this interrupts to the first one */
|
||||
irq_set_chip(irq2, &dummy_irq_chip);
|
||||
irq_set_chained_handler(irq2, intc_redirect_irq);
|
||||
irq_set_handler_data(irq2, (void *)irq);
|
||||
}
|
||||
}
|
||||
|
||||
intc_subgroup_init(desc, d);
|
||||
|
||||
/* enable bits matching force_enable after registering irqs */
|
||||
if (desc->force_enable)
|
||||
intc_enable_disable_enum(desc, d, desc->force_enable, 1);
|
||||
|
||||
d->skip_suspend = desc->skip_syscore_suspend;
|
||||
|
||||
nr_intc_controllers++;
|
||||
|
||||
return 0;
|
||||
err5:
|
||||
kfree(d->prio);
|
||||
err4:
|
||||
#ifdef CONFIG_SMP
|
||||
kfree(d->smp);
|
||||
err3:
|
||||
#endif
|
||||
kfree(d->reg);
|
||||
err2:
|
||||
for (k = 0; k < d->nr_windows; k++)
|
||||
if (d->window[k].virt)
|
||||
iounmap(d->window[k].virt);
|
||||
|
||||
kfree(d->window);
|
||||
err1:
|
||||
kfree(d);
|
||||
err0:
|
||||
pr_err("unable to allocate INTC memory\n");
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static int intc_suspend(void)
|
||||
{
|
||||
struct intc_desc_int *d;
|
||||
|
||||
list_for_each_entry(d, &intc_list, list) {
|
||||
int irq;
|
||||
|
||||
if (d->skip_suspend)
|
||||
continue;
|
||||
|
||||
/* enable wakeup irqs belonging to this intc controller */
|
||||
for_each_active_irq(irq) {
|
||||
struct irq_data *data;
|
||||
struct irq_chip *chip;
|
||||
|
||||
data = irq_get_irq_data(irq);
|
||||
chip = irq_data_get_irq_chip(data);
|
||||
if (chip != &d->chip)
|
||||
continue;
|
||||
if (irqd_is_wakeup_set(data))
|
||||
chip->irq_enable(data);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void intc_resume(void)
|
||||
{
|
||||
struct intc_desc_int *d;
|
||||
|
||||
list_for_each_entry(d, &intc_list, list) {
|
||||
int irq;
|
||||
|
||||
if (d->skip_suspend)
|
||||
continue;
|
||||
|
||||
for_each_active_irq(irq) {
|
||||
struct irq_data *data;
|
||||
struct irq_chip *chip;
|
||||
|
||||
data = irq_get_irq_data(irq);
|
||||
chip = irq_data_get_irq_chip(data);
|
||||
/*
|
||||
* This will catch the redirect and VIRQ cases
|
||||
* due to the dummy_irq_chip being inserted.
|
||||
*/
|
||||
if (chip != &d->chip)
|
||||
continue;
|
||||
if (irqd_irq_disabled(data))
|
||||
chip->irq_disable(data);
|
||||
else
|
||||
chip->irq_enable(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct syscore_ops intc_syscore_ops = {
|
||||
.suspend = intc_suspend,
|
||||
.resume = intc_resume,
|
||||
};
|
||||
|
||||
struct bus_type intc_subsys = {
|
||||
.name = "intc",
|
||||
.dev_name = "intc",
|
||||
};
|
||||
|
||||
static ssize_t
|
||||
show_intc_name(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct intc_desc_int *d;
|
||||
|
||||
d = container_of(dev, struct intc_desc_int, dev);
|
||||
|
||||
return sprintf(buf, "%s\n", d->chip.name);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(name, S_IRUGO, show_intc_name, NULL);
|
||||
|
||||
static int __init register_intc_devs(void)
|
||||
{
|
||||
struct intc_desc_int *d;
|
||||
int error;
|
||||
|
||||
register_syscore_ops(&intc_syscore_ops);
|
||||
|
||||
error = subsys_system_register(&intc_subsys, NULL);
|
||||
if (!error) {
|
||||
list_for_each_entry(d, &intc_list, list) {
|
||||
d->dev.id = d->index;
|
||||
d->dev.bus = &intc_subsys;
|
||||
error = device_register(&d->dev);
|
||||
if (error == 0)
|
||||
error = device_create_file(&d->dev,
|
||||
&dev_attr_name);
|
||||
if (error)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
pr_err("device registration error\n");
|
||||
|
||||
return error;
|
||||
}
|
||||
device_initcall(register_intc_devs);
|
306
drivers/sh/intc/handle.c
Normal file
306
drivers/sh/intc/handle.c
Normal file
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* Shared interrupt handling code for IPR and INTC2 types of IRQs.
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Magnus Damm
|
||||
* Copyright (C) 2009, 2010 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.
|
||||
*/
|
||||
#include <linux/init.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include "internals.h"
|
||||
|
||||
static unsigned long ack_handle[INTC_NR_IRQS];
|
||||
|
||||
static intc_enum __init intc_grp_id(struct intc_desc *desc,
|
||||
intc_enum enum_id)
|
||||
{
|
||||
struct intc_group *g = desc->hw.groups;
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0; g && enum_id && i < desc->hw.nr_groups; i++) {
|
||||
g = desc->hw.groups + i;
|
||||
|
||||
for (j = 0; g->enum_ids[j]; j++) {
|
||||
if (g->enum_ids[j] != enum_id)
|
||||
continue;
|
||||
|
||||
return g->enum_id;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct intc_mask_reg *mr = desc->hw.mask_regs;
|
||||
unsigned int fn, mode;
|
||||
unsigned long reg_e, reg_d;
|
||||
|
||||
while (mr && enum_id && *reg_idx < desc->hw.nr_mask_regs) {
|
||||
mr = desc->hw.mask_regs + *reg_idx;
|
||||
|
||||
for (; *fld_idx < ARRAY_SIZE(mr->enum_ids); (*fld_idx)++) {
|
||||
if (mr->enum_ids[*fld_idx] != enum_id)
|
||||
continue;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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) - *fld_idx);
|
||||
}
|
||||
|
||||
*fld_idx = 0;
|
||||
(*reg_idx)++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int __init
|
||||
intc_get_mask_handle(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;
|
||||
|
||||
if (do_grps)
|
||||
return intc_get_mask_handle(desc, d, intc_grp_id(desc, enum_id), 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct intc_prio_reg *pr = desc->hw.prio_regs;
|
||||
unsigned int fn, n, mode, bit;
|
||||
unsigned long reg_e, reg_d;
|
||||
|
||||
while (pr && enum_id && *reg_idx < desc->hw.nr_prio_regs) {
|
||||
pr = desc->hw.prio_regs + *reg_idx;
|
||||
|
||||
for (; *fld_idx < ARRAY_SIZE(pr->enum_ids); (*fld_idx)++) {
|
||||
if (pr->enum_ids[*fld_idx] != enum_id)
|
||||
continue;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
fn += (pr->reg_width >> 3) - 1;
|
||||
n = *fld_idx + 1;
|
||||
|
||||
BUG_ON(n * pr->field_width > pr->reg_width);
|
||||
|
||||
bit = pr->reg_width - (n * pr->field_width);
|
||||
|
||||
return _INTC_MK(fn, mode,
|
||||
intc_get_reg(d, reg_e),
|
||||
intc_get_reg(d, reg_d),
|
||||
pr->field_width, bit);
|
||||
}
|
||||
|
||||
*fld_idx = 0;
|
||||
(*reg_idx)++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int __init
|
||||
intc_get_prio_handle(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;
|
||||
|
||||
if (do_grps)
|
||||
return intc_get_prio_handle(desc, d, intc_grp_id(desc, enum_id), 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int intc_ack_data(struct intc_desc *desc,
|
||||
struct intc_desc_int *d, intc_enum enum_id)
|
||||
{
|
||||
struct intc_mask_reg *mr = desc->hw.ack_regs;
|
||||
unsigned int i, j, fn, mode;
|
||||
unsigned long reg_e, reg_d;
|
||||
|
||||
for (i = 0; mr && enum_id && i < desc->hw.nr_ack_regs; i++) {
|
||||
mr = desc->hw.ack_regs + i;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void intc_enable_disable(struct intc_desc_int *d,
|
||||
unsigned long handle, int do_enable)
|
||||
{
|
||||
unsigned long addr;
|
||||
unsigned int cpu;
|
||||
unsigned long (*fn)(unsigned long, unsigned long,
|
||||
unsigned long (*)(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
unsigned int __init
|
||||
intc_get_sense_handle(struct intc_desc *desc, struct intc_desc_int *d,
|
||||
intc_enum enum_id)
|
||||
{
|
||||
struct intc_sense_reg *sr = desc->hw.sense_regs;
|
||||
unsigned int i, j, fn, bit;
|
||||
|
||||
for (i = 0; sr && enum_id && i < desc->hw.nr_sense_regs; i++) {
|
||||
sr = desc->hw.sense_regs + i;
|
||||
|
||||
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;
|
||||
|
||||
BUG_ON((j + 1) * sr->field_width > sr->reg_width);
|
||||
|
||||
bit = sr->reg_width - ((j + 1) * sr->field_width);
|
||||
|
||||
return _INTC_MK(fn, 0, intc_get_reg(d, sr->reg),
|
||||
0, sr->field_width, bit);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
|
||||
struct intc_desc_int *d, intc_enum id)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
/*
|
||||
* Nothing to do for this IRQ.
|
||||
*/
|
||||
if (!desc->hw.ack_regs)
|
||||
return;
|
||||
|
||||
raw_spin_lock_irqsave(&intc_big_lock, flags);
|
||||
ack_handle[irq] = intc_ack_data(desc, d, id);
|
||||
raw_spin_unlock_irqrestore(&intc_big_lock, flags);
|
||||
}
|
||||
|
||||
unsigned long intc_get_ack_handle(unsigned int irq)
|
||||
{
|
||||
return ack_handle[irq];
|
||||
}
|
198
drivers/sh/intc/internals.h
Normal file
198
drivers/sh/intc/internals.h
Normal file
|
@ -0,0 +1,198 @@
|
|||
#include <linux/sh_intc.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/irqdomain.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/radix-tree.h>
|
||||
#include <linux/device.h>
|
||||
|
||||
#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)
|
||||
|
||||
#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
|
||||
|
||||
struct intc_handle_int {
|
||||
unsigned int irq;
|
||||
unsigned long handle;
|
||||
};
|
||||
|
||||
struct intc_window {
|
||||
phys_addr_t phys;
|
||||
void __iomem *virt;
|
||||
unsigned long size;
|
||||
};
|
||||
|
||||
struct intc_map_entry {
|
||||
intc_enum enum_id;
|
||||
struct intc_desc_int *desc;
|
||||
};
|
||||
|
||||
struct intc_subgroup_entry {
|
||||
unsigned int pirq;
|
||||
intc_enum enum_id;
|
||||
unsigned long handle;
|
||||
};
|
||||
|
||||
struct intc_desc_int {
|
||||
struct list_head list;
|
||||
struct device dev;
|
||||
struct radix_tree_root tree;
|
||||
raw_spinlock_t lock;
|
||||
unsigned int index;
|
||||
unsigned long *reg;
|
||||
#ifdef CONFIG_SMP
|
||||
unsigned long *smp;
|
||||
#endif
|
||||
unsigned int nr_reg;
|
||||
struct intc_handle_int *prio;
|
||||
unsigned int nr_prio;
|
||||
struct intc_handle_int *sense;
|
||||
unsigned int nr_sense;
|
||||
struct intc_window *window;
|
||||
unsigned int nr_windows;
|
||||
struct irq_domain *domain;
|
||||
struct irq_chip chip;
|
||||
bool skip_suspend;
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
REG_FN_ERR = 0,
|
||||
REG_FN_TEST_BASE = 1,
|
||||
REG_FN_WRITE_BASE = 5,
|
||||
REG_FN_MODIFY_BASE = 9
|
||||
};
|
||||
|
||||
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 */
|
||||
};
|
||||
|
||||
static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
|
||||
{
|
||||
struct irq_chip *chip = irq_get_chip(irq);
|
||||
|
||||
return container_of(chip, struct intc_desc_int, chip);
|
||||
}
|
||||
|
||||
/*
|
||||
* Grumble.
|
||||
*/
|
||||
static inline void activate_irq(int irq)
|
||||
{
|
||||
#ifdef CONFIG_ARM
|
||||
/* ARM requires an extra step to clear IRQ_NOREQUEST, which it
|
||||
* sets on behalf of every irq_chip. Also sets IRQ_NOPROBE.
|
||||
*/
|
||||
set_irq_flags(irq, IRQF_VALID);
|
||||
#else
|
||||
/* same effect on other architectures */
|
||||
irq_set_noprobe(irq);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int intc_handle_int_cmp(const void *a, const void *b)
|
||||
{
|
||||
const struct intc_handle_int *_a = a;
|
||||
const struct intc_handle_int *_b = b;
|
||||
|
||||
return _a->irq - _b->irq;
|
||||
}
|
||||
|
||||
/* access.c */
|
||||
extern unsigned long
|
||||
(*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data);
|
||||
|
||||
extern unsigned long
|
||||
(*intc_enable_fns[])(unsigned long addr, unsigned long handle,
|
||||
unsigned long (*fn)(unsigned long,
|
||||
unsigned long, unsigned long),
|
||||
unsigned int irq);
|
||||
extern unsigned long
|
||||
(*intc_disable_fns[])(unsigned long addr, unsigned long handle,
|
||||
unsigned long (*fn)(unsigned long,
|
||||
unsigned long, unsigned long),
|
||||
unsigned int irq);
|
||||
extern unsigned long
|
||||
(*intc_enable_noprio_fns[])(unsigned long addr, unsigned long handle,
|
||||
unsigned long (*fn)(unsigned long,
|
||||
unsigned long, unsigned long),
|
||||
unsigned int irq);
|
||||
|
||||
unsigned long intc_phys_to_virt(struct intc_desc_int *d, unsigned long address);
|
||||
unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address);
|
||||
unsigned int intc_set_field_from_handle(unsigned int value,
|
||||
unsigned int field_value,
|
||||
unsigned int handle);
|
||||
unsigned long intc_get_field_from_handle(unsigned int value,
|
||||
unsigned int handle);
|
||||
|
||||
/* balancing.c */
|
||||
#ifdef CONFIG_INTC_BALANCING
|
||||
void intc_balancing_enable(unsigned int irq);
|
||||
void intc_balancing_disable(unsigned int irq);
|
||||
void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
|
||||
struct intc_desc_int *d, intc_enum id);
|
||||
#else
|
||||
static inline void intc_balancing_enable(unsigned int irq) { }
|
||||
static inline void intc_balancing_disable(unsigned int irq) { }
|
||||
static inline void
|
||||
intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
|
||||
struct intc_desc_int *d, intc_enum id) { }
|
||||
#endif
|
||||
|
||||
/* chip.c */
|
||||
extern struct irq_chip intc_irq_chip;
|
||||
void _intc_enable(struct irq_data *data, unsigned long handle);
|
||||
|
||||
/* core.c */
|
||||
extern struct list_head intc_list;
|
||||
extern raw_spinlock_t intc_big_lock;
|
||||
extern struct bus_type intc_subsys;
|
||||
|
||||
unsigned int intc_get_dfl_prio_level(void);
|
||||
unsigned int intc_get_prio_level(unsigned int irq);
|
||||
void intc_set_prio_level(unsigned int irq, unsigned int level);
|
||||
|
||||
/* handle.c */
|
||||
unsigned int intc_get_mask_handle(struct intc_desc *desc,
|
||||
struct intc_desc_int *d,
|
||||
intc_enum enum_id, int do_grps);
|
||||
unsigned int intc_get_prio_handle(struct intc_desc *desc,
|
||||
struct intc_desc_int *d,
|
||||
intc_enum enum_id, int do_grps);
|
||||
unsigned int intc_get_sense_handle(struct intc_desc *desc,
|
||||
struct intc_desc_int *d,
|
||||
intc_enum enum_id);
|
||||
void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
|
||||
struct intc_desc_int *d, intc_enum id);
|
||||
unsigned long intc_get_ack_handle(unsigned int irq);
|
||||
void intc_enable_disable_enum(struct intc_desc *desc, struct intc_desc_int *d,
|
||||
intc_enum enum_id, int enable);
|
||||
|
||||
/* irqdomain.c */
|
||||
void intc_irq_domain_init(struct intc_desc_int *d, struct intc_hw_desc *hw);
|
||||
|
||||
/* virq.c */
|
||||
void intc_subgroup_init(struct intc_desc *desc, struct intc_desc_int *d);
|
||||
void intc_irq_xlate_set(unsigned int irq, intc_enum id, struct intc_desc_int *d);
|
||||
struct intc_map_entry *intc_irq_xlate_get(unsigned int irq);
|
68
drivers/sh/intc/irqdomain.c
Normal file
68
drivers/sh/intc/irqdomain.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* IRQ domain support for SH INTC subsystem
|
||||
*
|
||||
* Copyright (C) 2012 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.
|
||||
*/
|
||||
#define pr_fmt(fmt) "intc: " fmt
|
||||
|
||||
#include <linux/irqdomain.h>
|
||||
#include <linux/sh_intc.h>
|
||||
#include <linux/export.h>
|
||||
#include "internals.h"
|
||||
|
||||
/**
|
||||
* intc_irq_domain_evt_xlate() - Generic xlate for vectored IRQs.
|
||||
*
|
||||
* This takes care of exception vector to hwirq translation through
|
||||
* by way of evt2irq() translation.
|
||||
*
|
||||
* Note: For platforms that use a flat vector space without INTEVT this
|
||||
* basically just mimics irq_domain_xlate_onecell() by way of a nopped
|
||||
* out evt2irq() implementation.
|
||||
*/
|
||||
static int intc_evt_xlate(struct irq_domain *d, struct device_node *ctrlr,
|
||||
const u32 *intspec, unsigned int intsize,
|
||||
unsigned long *out_hwirq, unsigned int *out_type)
|
||||
{
|
||||
if (WARN_ON(intsize < 1))
|
||||
return -EINVAL;
|
||||
|
||||
*out_hwirq = evt2irq(intspec[0]);
|
||||
*out_type = IRQ_TYPE_NONE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct irq_domain_ops intc_evt_ops = {
|
||||
.xlate = intc_evt_xlate,
|
||||
};
|
||||
|
||||
void __init intc_irq_domain_init(struct intc_desc_int *d,
|
||||
struct intc_hw_desc *hw)
|
||||
{
|
||||
unsigned int irq_base, irq_end;
|
||||
|
||||
/*
|
||||
* Quick linear revmap check
|
||||
*/
|
||||
irq_base = evt2irq(hw->vectors[0].vect);
|
||||
irq_end = evt2irq(hw->vectors[hw->nr_vectors - 1].vect);
|
||||
|
||||
/*
|
||||
* Linear domains have a hard-wired assertion that IRQs start at
|
||||
* 0 in order to make some performance optimizations. Lamely
|
||||
* restrict the linear case to these conditions here, taking the
|
||||
* tree penalty for linear cases with non-zero hwirq bases.
|
||||
*/
|
||||
if (irq_base == 0 && irq_end == (irq_base + hw->nr_vectors - 1))
|
||||
d->domain = irq_domain_add_linear(NULL, hw->nr_vectors,
|
||||
&intc_evt_ops, NULL);
|
||||
else
|
||||
d->domain = irq_domain_add_tree(NULL, &intc_evt_ops, NULL);
|
||||
|
||||
BUG_ON(!d->domain);
|
||||
}
|
84
drivers/sh/intc/userimask.c
Normal file
84
drivers/sh/intc/userimask.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Support for hardware-assisted userspace interrupt masking.
|
||||
*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
#define pr_fmt(fmt) "intc: " fmt
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/stat.h>
|
||||
#include <asm/sizes.h>
|
||||
#include "internals.h"
|
||||
|
||||
static void __iomem *uimask;
|
||||
|
||||
static ssize_t
|
||||
show_intc_userimask(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
store_intc_userimask(struct device *dev,
|
||||
struct device_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 the default priority level as a cut off so that only
|
||||
* special case opt-in IRQs can be mangled.
|
||||
*/
|
||||
if (level >= intc_get_dfl_prio_level())
|
||||
return -EINVAL;
|
||||
|
||||
__raw_writel(0xa5 << 24 | level << 4, uimask);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(userimask, S_IRUSR | S_IWUSR,
|
||||
show_intc_userimask, store_intc_userimask);
|
||||
|
||||
|
||||
static int __init userimask_sysdev_init(void)
|
||||
{
|
||||
if (unlikely(!uimask))
|
||||
return -ENXIO;
|
||||
|
||||
return device_create_file(intc_subsys.dev_root, &dev_attr_userimask);
|
||||
}
|
||||
late_initcall(userimask_sysdev_init);
|
||||
|
||||
int register_intc_userimask(unsigned long addr)
|
||||
{
|
||||
if (unlikely(uimask))
|
||||
return -EBUSY;
|
||||
|
||||
uimask = ioremap_nocache(addr, SZ_4K);
|
||||
if (unlikely(!uimask))
|
||||
return -ENOMEM;
|
||||
|
||||
pr_info("userimask support registered for levels 0 -> %d\n",
|
||||
intc_get_dfl_prio_level() - 1);
|
||||
|
||||
return 0;
|
||||
}
|
64
drivers/sh/intc/virq-debugfs.c
Normal file
64
drivers/sh/intc/virq-debugfs.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Support for virtual IRQ subgroups debugfs mapping.
|
||||
*
|
||||
* Copyright (C) 2010 Paul Mundt
|
||||
*
|
||||
* Modelled after arch/powerpc/kernel/irq.c.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include "internals.h"
|
||||
|
||||
static int intc_irq_xlate_debug(struct seq_file *m, void *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
seq_printf(m, "%-5s %-7s %-15s\n", "irq", "enum", "chip name");
|
||||
|
||||
for (i = 1; i < nr_irqs; i++) {
|
||||
struct intc_map_entry *entry = intc_irq_xlate_get(i);
|
||||
struct intc_desc_int *desc = entry->desc;
|
||||
|
||||
if (!desc)
|
||||
continue;
|
||||
|
||||
seq_printf(m, "%5d ", i);
|
||||
seq_printf(m, "0x%05x ", entry->enum_id);
|
||||
seq_printf(m, "%-15s\n", desc->chip.name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int intc_irq_xlate_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, intc_irq_xlate_debug, inode->i_private);
|
||||
}
|
||||
|
||||
static const struct file_operations intc_irq_xlate_fops = {
|
||||
.open = intc_irq_xlate_open,
|
||||
.read = seq_read,
|
||||
.llseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
|
||||
static int __init intc_irq_xlate_init(void)
|
||||
{
|
||||
/*
|
||||
* XXX.. use arch_debugfs_dir here when all of the intc users are
|
||||
* converted.
|
||||
*/
|
||||
if (debugfs_create_file("intc_irq_xlate", S_IRUGO, NULL, NULL,
|
||||
&intc_irq_xlate_fops) == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
fs_initcall(intc_irq_xlate_init);
|
265
drivers/sh/intc/virq.c
Normal file
265
drivers/sh/intc/virq.c
Normal file
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
* Support for virtual IRQ subgroups.
|
||||
*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
#define pr_fmt(fmt) "intc: " fmt
|
||||
|
||||
#include <linux/slab.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/radix-tree.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/export.h>
|
||||
#include "internals.h"
|
||||
|
||||
static struct intc_map_entry intc_irq_xlate[INTC_NR_IRQS];
|
||||
|
||||
struct intc_virq_list {
|
||||
unsigned int irq;
|
||||
struct intc_virq_list *next;
|
||||
};
|
||||
|
||||
#define for_each_virq(entry, head) \
|
||||
for (entry = head; entry; entry = entry->next)
|
||||
|
||||
/*
|
||||
* Tags for the radix tree
|
||||
*/
|
||||
#define INTC_TAG_VIRQ_NEEDS_ALLOC 0
|
||||
|
||||
void intc_irq_xlate_set(unsigned int irq, intc_enum id, struct intc_desc_int *d)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
raw_spin_lock_irqsave(&intc_big_lock, flags);
|
||||
intc_irq_xlate[irq].enum_id = id;
|
||||
intc_irq_xlate[irq].desc = d;
|
||||
raw_spin_unlock_irqrestore(&intc_big_lock, flags);
|
||||
}
|
||||
|
||||
struct intc_map_entry *intc_irq_xlate_get(unsigned int irq)
|
||||
{
|
||||
return intc_irq_xlate + irq;
|
||||
}
|
||||
|
||||
int intc_irq_lookup(const char *chipname, intc_enum enum_id)
|
||||
{
|
||||
struct intc_map_entry *ptr;
|
||||
struct intc_desc_int *d;
|
||||
int irq = -1;
|
||||
|
||||
list_for_each_entry(d, &intc_list, list) {
|
||||
int tagged;
|
||||
|
||||
if (strcmp(d->chip.name, chipname) != 0)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Catch early lookups for subgroup VIRQs that have not
|
||||
* yet been allocated an IRQ. This already includes a
|
||||
* fast-path out if the tree is untagged, so there is no
|
||||
* need to explicitly test the root tree.
|
||||
*/
|
||||
tagged = radix_tree_tag_get(&d->tree, enum_id,
|
||||
INTC_TAG_VIRQ_NEEDS_ALLOC);
|
||||
if (unlikely(tagged))
|
||||
break;
|
||||
|
||||
ptr = radix_tree_lookup(&d->tree, enum_id);
|
||||
if (ptr) {
|
||||
irq = ptr - intc_irq_xlate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return irq;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(intc_irq_lookup);
|
||||
|
||||
static int add_virq_to_pirq(unsigned int irq, unsigned int virq)
|
||||
{
|
||||
struct intc_virq_list **last, *entry;
|
||||
struct irq_data *data = irq_get_irq_data(irq);
|
||||
|
||||
/* scan for duplicates */
|
||||
last = (struct intc_virq_list **)&data->handler_data;
|
||||
for_each_virq(entry, data->handler_data) {
|
||||
if (entry->irq == virq)
|
||||
return 0;
|
||||
last = &entry->next;
|
||||
}
|
||||
|
||||
entry = kzalloc(sizeof(struct intc_virq_list), GFP_ATOMIC);
|
||||
if (!entry) {
|
||||
pr_err("can't allocate VIRQ mapping for %d\n", virq);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
entry->irq = virq;
|
||||
|
||||
*last = entry;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void intc_virq_handler(unsigned int irq, struct irq_desc *desc)
|
||||
{
|
||||
struct irq_data *data = irq_get_irq_data(irq);
|
||||
struct irq_chip *chip = irq_data_get_irq_chip(data);
|
||||
struct intc_virq_list *entry, *vlist = irq_data_get_irq_handler_data(data);
|
||||
struct intc_desc_int *d = get_intc_desc(irq);
|
||||
|
||||
chip->irq_mask_ack(data);
|
||||
|
||||
for_each_virq(entry, vlist) {
|
||||
unsigned long addr, handle;
|
||||
|
||||
handle = (unsigned long)irq_get_handler_data(entry->irq);
|
||||
addr = INTC_REG(d, _INTC_ADDR_E(handle), 0);
|
||||
|
||||
if (intc_reg_fns[_INTC_FN(handle)](addr, handle, 0))
|
||||
generic_handle_irq(entry->irq);
|
||||
}
|
||||
|
||||
chip->irq_unmask(data);
|
||||
}
|
||||
|
||||
static unsigned long __init intc_subgroup_data(struct intc_subgroup *subgroup,
|
||||
struct intc_desc_int *d,
|
||||
unsigned int index)
|
||||
{
|
||||
unsigned int fn = REG_FN_TEST_BASE + (subgroup->reg_width >> 3) - 1;
|
||||
|
||||
return _INTC_MK(fn, MODE_ENABLE_REG, intc_get_reg(d, subgroup->reg),
|
||||
0, 1, (subgroup->reg_width - 1) - index);
|
||||
}
|
||||
|
||||
static void __init intc_subgroup_init_one(struct intc_desc *desc,
|
||||
struct intc_desc_int *d,
|
||||
struct intc_subgroup *subgroup)
|
||||
{
|
||||
struct intc_map_entry *mapped;
|
||||
unsigned int pirq;
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
mapped = radix_tree_lookup(&d->tree, subgroup->parent_id);
|
||||
if (!mapped) {
|
||||
WARN_ON(1);
|
||||
return;
|
||||
}
|
||||
|
||||
pirq = mapped - intc_irq_xlate;
|
||||
|
||||
raw_spin_lock_irqsave(&d->lock, flags);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(subgroup->enum_ids); i++) {
|
||||
struct intc_subgroup_entry *entry;
|
||||
int err;
|
||||
|
||||
if (!subgroup->enum_ids[i])
|
||||
continue;
|
||||
|
||||
entry = kmalloc(sizeof(*entry), GFP_NOWAIT);
|
||||
if (!entry)
|
||||
break;
|
||||
|
||||
entry->pirq = pirq;
|
||||
entry->enum_id = subgroup->enum_ids[i];
|
||||
entry->handle = intc_subgroup_data(subgroup, d, i);
|
||||
|
||||
err = radix_tree_insert(&d->tree, entry->enum_id, entry);
|
||||
if (unlikely(err < 0))
|
||||
break;
|
||||
|
||||
radix_tree_tag_set(&d->tree, entry->enum_id,
|
||||
INTC_TAG_VIRQ_NEEDS_ALLOC);
|
||||
}
|
||||
|
||||
raw_spin_unlock_irqrestore(&d->lock, flags);
|
||||
}
|
||||
|
||||
void __init intc_subgroup_init(struct intc_desc *desc, struct intc_desc_int *d)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!desc->hw.subgroups)
|
||||
return;
|
||||
|
||||
for (i = 0; i < desc->hw.nr_subgroups; i++)
|
||||
intc_subgroup_init_one(desc, d, desc->hw.subgroups + i);
|
||||
}
|
||||
|
||||
static void __init intc_subgroup_map(struct intc_desc_int *d)
|
||||
{
|
||||
struct intc_subgroup_entry *entries[32];
|
||||
unsigned long flags;
|
||||
unsigned int nr_found;
|
||||
int i;
|
||||
|
||||
raw_spin_lock_irqsave(&d->lock, flags);
|
||||
|
||||
restart:
|
||||
nr_found = radix_tree_gang_lookup_tag_slot(&d->tree,
|
||||
(void ***)entries, 0, ARRAY_SIZE(entries),
|
||||
INTC_TAG_VIRQ_NEEDS_ALLOC);
|
||||
|
||||
for (i = 0; i < nr_found; i++) {
|
||||
struct intc_subgroup_entry *entry;
|
||||
int irq;
|
||||
|
||||
entry = radix_tree_deref_slot((void **)entries[i]);
|
||||
if (unlikely(!entry))
|
||||
continue;
|
||||
if (radix_tree_deref_retry(entry))
|
||||
goto restart;
|
||||
|
||||
irq = irq_alloc_desc(numa_node_id());
|
||||
if (unlikely(irq < 0)) {
|
||||
pr_err("no more free IRQs, bailing..\n");
|
||||
break;
|
||||
}
|
||||
|
||||
activate_irq(irq);
|
||||
|
||||
pr_info("Setting up a chained VIRQ from %d -> %d\n",
|
||||
irq, entry->pirq);
|
||||
|
||||
intc_irq_xlate_set(irq, entry->enum_id, d);
|
||||
|
||||
irq_set_chip_and_handler_name(irq, irq_get_chip(entry->pirq),
|
||||
handle_simple_irq, "virq");
|
||||
irq_set_chip_data(irq, irq_get_chip_data(entry->pirq));
|
||||
|
||||
irq_set_handler_data(irq, (void *)entry->handle);
|
||||
|
||||
/*
|
||||
* Set the virtual IRQ as non-threadable.
|
||||
*/
|
||||
irq_set_nothread(irq);
|
||||
|
||||
irq_set_chained_handler(entry->pirq, intc_virq_handler);
|
||||
add_virq_to_pirq(entry->pirq, irq);
|
||||
|
||||
radix_tree_tag_clear(&d->tree, entry->enum_id,
|
||||
INTC_TAG_VIRQ_NEEDS_ALLOC);
|
||||
radix_tree_replace_slot((void **)entries[i],
|
||||
&intc_irq_xlate[irq]);
|
||||
}
|
||||
|
||||
raw_spin_unlock_irqrestore(&d->lock, flags);
|
||||
}
|
||||
|
||||
void __init intc_finalize(void)
|
||||
{
|
||||
struct intc_desc_int *d;
|
||||
|
||||
list_for_each_entry(d, &intc_list, list)
|
||||
if (radix_tree_tagged(&d->tree, INTC_TAG_VIRQ_NEEDS_ALLOC))
|
||||
intc_subgroup_map(d);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue