2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-01-20 14:00:50 -07:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
|
2016-05-05 00:57:56 -07:00
|
|
|
* Copyright (C) 2013 John Crispin <john@phrozen.org>
|
2013-01-20 14:00:50 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/bitops.h>
|
2023-07-14 10:40:27 -07:00
|
|
|
#include <linux/of.h>
|
2013-01-20 14:00:50 -07:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
|
|
|
|
#include <asm/irq_cpu.h>
|
|
|
|
#include <asm/mipsregs.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#define INTC_INT_GLOBAL BIT(31)
|
|
|
|
|
|
|
|
#define RALINK_CPU_IRQ_INTC (MIPS_CPU_IRQ_BASE + 2)
|
2013-04-10 00:07:27 -07:00
|
|
|
#define RALINK_CPU_IRQ_PCI (MIPS_CPU_IRQ_BASE + 4)
|
2013-01-20 14:00:50 -07:00
|
|
|
#define RALINK_CPU_IRQ_FE (MIPS_CPU_IRQ_BASE + 5)
|
|
|
|
#define RALINK_CPU_IRQ_WIFI (MIPS_CPU_IRQ_BASE + 6)
|
|
|
|
#define RALINK_CPU_IRQ_COUNTER (MIPS_CPU_IRQ_BASE + 7)
|
|
|
|
|
|
|
|
/* we have a cascade of 8 irqs */
|
|
|
|
#define RALINK_INTC_IRQ_BASE 8
|
|
|
|
|
|
|
|
/* we have 32 SoC irqs */
|
|
|
|
#define RALINK_INTC_IRQ_COUNT 32
|
|
|
|
|
|
|
|
#define RALINK_INTC_IRQ_PERFC (RALINK_INTC_IRQ_BASE + 9)
|
|
|
|
|
2014-10-26 03:26:04 -07:00
|
|
|
enum rt_intc_regs_enum {
|
|
|
|
INTC_REG_STATUS0 = 0,
|
|
|
|
INTC_REG_STATUS1,
|
|
|
|
INTC_REG_TYPE,
|
|
|
|
INTC_REG_RAW_STATUS,
|
|
|
|
INTC_REG_ENABLE,
|
|
|
|
INTC_REG_DISABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static u32 rt_intc_regs[] = {
|
|
|
|
[INTC_REG_STATUS0] = 0x00,
|
|
|
|
[INTC_REG_STATUS1] = 0x04,
|
|
|
|
[INTC_REG_TYPE] = 0x20,
|
|
|
|
[INTC_REG_RAW_STATUS] = 0x30,
|
|
|
|
[INTC_REG_ENABLE] = 0x34,
|
|
|
|
[INTC_REG_DISABLE] = 0x38,
|
|
|
|
};
|
|
|
|
|
2013-01-20 14:00:50 -07:00
|
|
|
static void __iomem *rt_intc_membase;
|
2014-10-26 03:26:04 -07:00
|
|
|
|
2014-09-18 14:47:12 -07:00
|
|
|
static int rt_perfcount_irq;
|
2013-01-20 14:00:50 -07:00
|
|
|
|
|
|
|
static inline void rt_intc_w32(u32 val, unsigned reg)
|
|
|
|
{
|
2014-10-26 03:26:04 -07:00
|
|
|
__raw_writel(val, rt_intc_membase + rt_intc_regs[reg]);
|
2013-01-20 14:00:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 rt_intc_r32(unsigned reg)
|
|
|
|
{
|
2014-10-26 03:26:04 -07:00
|
|
|
return __raw_readl(rt_intc_membase + rt_intc_regs[reg]);
|
2013-01-20 14:00:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ralink_intc_irq_unmask(struct irq_data *d)
|
|
|
|
{
|
|
|
|
rt_intc_w32(BIT(d->hwirq), INTC_REG_ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ralink_intc_irq_mask(struct irq_data *d)
|
|
|
|
{
|
|
|
|
rt_intc_w32(BIT(d->hwirq), INTC_REG_DISABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_chip ralink_intc_irq_chip = {
|
|
|
|
.name = "INTC",
|
|
|
|
.irq_unmask = ralink_intc_irq_unmask,
|
|
|
|
.irq_mask = ralink_intc_irq_mask,
|
|
|
|
.irq_mask_ack = ralink_intc_irq_mask,
|
|
|
|
};
|
|
|
|
|
2014-09-18 14:47:12 -07:00
|
|
|
int get_c0_perfcount_int(void)
|
|
|
|
{
|
|
|
|
return rt_perfcount_irq;
|
|
|
|
}
|
2015-07-23 09:59:52 -07:00
|
|
|
EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
|
2014-09-18 14:47:12 -07:00
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 06:38:59 -07:00
|
|
|
unsigned int get_c0_compare_int(void)
|
2013-01-20 14:00:50 -07:00
|
|
|
{
|
|
|
|
return CP0_LEGACY_COMPARE_IRQ;
|
|
|
|
}
|
|
|
|
|
2015-09-14 01:42:37 -07:00
|
|
|
static void ralink_intc_irq_handler(struct irq_desc *desc)
|
2013-01-20 14:00:50 -07:00
|
|
|
{
|
|
|
|
u32 pending = rt_intc_r32(INTC_REG_STATUS0);
|
|
|
|
|
|
|
|
if (pending) {
|
2015-05-20 02:59:51 -07:00
|
|
|
struct irq_domain *domain = irq_desc_get_handler_data(desc);
|
2021-05-04 09:42:18 -07:00
|
|
|
generic_handle_domain_irq(domain, __ffs(pending));
|
2013-01-20 14:00:50 -07:00
|
|
|
} else {
|
|
|
|
spurious_interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void plat_irq_dispatch(void)
|
|
|
|
{
|
|
|
|
unsigned long pending;
|
|
|
|
|
|
|
|
pending = read_c0_status() & read_c0_cause() & ST0_IM;
|
|
|
|
|
|
|
|
if (pending & STATUSF_IP7)
|
|
|
|
do_IRQ(RALINK_CPU_IRQ_COUNTER);
|
|
|
|
|
|
|
|
else if (pending & STATUSF_IP5)
|
|
|
|
do_IRQ(RALINK_CPU_IRQ_FE);
|
|
|
|
|
|
|
|
else if (pending & STATUSF_IP6)
|
|
|
|
do_IRQ(RALINK_CPU_IRQ_WIFI);
|
|
|
|
|
2013-04-10 00:07:27 -07:00
|
|
|
else if (pending & STATUSF_IP4)
|
|
|
|
do_IRQ(RALINK_CPU_IRQ_PCI);
|
|
|
|
|
2013-01-20 14:00:50 -07:00
|
|
|
else if (pending & STATUSF_IP2)
|
|
|
|
do_IRQ(RALINK_CPU_IRQ_INTC);
|
|
|
|
|
|
|
|
else
|
|
|
|
spurious_interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int intc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
|
|
|
|
{
|
|
|
|
irq_set_chip_and_handler(irq, &ralink_intc_irq_chip, handle_level_irq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct irq_domain_ops irq_domain_ops = {
|
|
|
|
.xlate = irq_domain_xlate_onecell,
|
|
|
|
.map = intc_map,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init intc_of_init(struct device_node *node,
|
|
|
|
struct device_node *parent)
|
|
|
|
{
|
|
|
|
struct resource res;
|
|
|
|
struct irq_domain *domain;
|
2013-01-31 12:43:30 -07:00
|
|
|
int irq;
|
2013-01-20 14:00:50 -07:00
|
|
|
|
2014-10-26 03:26:04 -07:00
|
|
|
if (!of_property_read_u32_array(node, "ralink,intc-registers",
|
|
|
|
rt_intc_regs, 6))
|
|
|
|
pr_info("intc: using register map from devicetree\n");
|
|
|
|
|
2013-01-31 12:43:30 -07:00
|
|
|
irq = irq_of_parse_and_map(node, 0);
|
|
|
|
if (!irq)
|
|
|
|
panic("Failed to get INTC IRQ");
|
2013-01-20 14:00:50 -07:00
|
|
|
|
|
|
|
if (of_address_to_resource(node, 0, &res))
|
|
|
|
panic("Failed to get intc memory range");
|
|
|
|
|
2017-01-17 08:18:42 -07:00
|
|
|
if (!request_mem_region(res.start, resource_size(&res),
|
|
|
|
res.name))
|
2013-01-20 14:00:50 -07:00
|
|
|
pr_err("Failed to request intc memory");
|
|
|
|
|
2020-01-06 01:43:50 -07:00
|
|
|
rt_intc_membase = ioremap(res.start,
|
2013-01-20 14:00:50 -07:00
|
|
|
resource_size(&res));
|
|
|
|
if (!rt_intc_membase)
|
|
|
|
panic("Failed to remap intc memory");
|
|
|
|
|
|
|
|
/* disable all interrupts */
|
|
|
|
rt_intc_w32(~0, INTC_REG_DISABLE);
|
|
|
|
|
|
|
|
/* route all INTC interrupts to MIPS HW0 interrupt */
|
|
|
|
rt_intc_w32(0, INTC_REG_TYPE);
|
|
|
|
|
|
|
|
domain = irq_domain_add_legacy(node, RALINK_INTC_IRQ_COUNT,
|
|
|
|
RALINK_INTC_IRQ_BASE, 0, &irq_domain_ops, NULL);
|
|
|
|
if (!domain)
|
|
|
|
panic("Failed to add irqdomain");
|
|
|
|
|
|
|
|
rt_intc_w32(INTC_INT_GLOBAL, INTC_REG_ENABLE);
|
|
|
|
|
MIPS/ralink: Fix race in installing chained IRQ handler
Fix a race where a pending interrupt could be received and the handler
called before the handler's data has been setup, by converting to
irq_set_chained_handler_and_data().
Search and conversion was done with coccinelle:
@@
expression E1, E2, E3;
@@
(
-if (irq_set_chained_handler(E1, E3) != 0)
- BUG();
|
-irq_set_chained_handler(E1, E3);
)
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);
@@
expression E1, E2, E3;
@@
(
-if (irq_set_chained_handler(E1, E3) != 0)
- BUG();
...
|
-irq_set_chained_handler(E1, E3);
...
)
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);
Reported-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Qais Yousef <qais.yousef@imgtec.com>
Cc: Andrew Bresticker <abrestic@chromium.org>
Cc: John Crispin <blogic@openwrt.org>
Cc: linux-mips@linux-mips.org
2015-06-21 12:00:43 -07:00
|
|
|
irq_set_chained_handler_and_data(irq, ralink_intc_irq_handler, domain);
|
2013-01-20 14:00:50 -07:00
|
|
|
|
2013-03-16 08:28:54 -07:00
|
|
|
/* tell the kernel which irq is used for performance monitoring */
|
2014-09-18 14:47:12 -07:00
|
|
|
rt_perfcount_irq = irq_create_mapping(domain, 9);
|
2013-01-20 14:00:50 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct of_device_id __initdata of_irq_ids[] = {
|
2014-09-18 14:47:08 -07:00
|
|
|
{ .compatible = "mti,cpu-interrupt-controller", .data = mips_cpu_irq_of_init },
|
2013-01-20 14:00:50 -07:00
|
|
|
{ .compatible = "ralink,rt2880-intc", .data = intc_of_init },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
void __init arch_init_irq(void)
|
|
|
|
{
|
|
|
|
of_irq_init(of_irq_ids);
|
|
|
|
}
|
|
|
|
|