2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-06-26 15:18:48 +08:00
|
|
|
/*
|
|
|
|
* drivers/irq/irq-nvic.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 ARM Limited, All Rights Reserved.
|
|
|
|
* Copyright (C) 2013 Pengutronix
|
|
|
|
*
|
|
|
|
* Support for the Nested Vectored Interrupt Controller found on the
|
|
|
|
* ARMv7-M CPUs (Cortex-M3/M4)
|
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/irq.h>
|
2015-07-08 05:11:46 +08:00
|
|
|
#include <linux/irqchip.h>
|
2013-06-26 15:18:48 +08:00
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
|
|
|
|
#include <asm/v7m.h>
|
|
|
|
#include <asm/exception.h>
|
|
|
|
|
|
|
|
#define NVIC_ISER 0x000
|
|
|
|
#define NVIC_ICER 0x080
|
2021-12-01 19:02:58 +08:00
|
|
|
#define NVIC_IPR 0x400
|
2013-06-26 15:18:48 +08:00
|
|
|
|
|
|
|
#define NVIC_MAX_BANKS 16
|
|
|
|
/*
|
|
|
|
* Each bank handles 32 irqs. Only the 16th (= last) bank handles only
|
|
|
|
* 16 irqs.
|
|
|
|
*/
|
|
|
|
#define NVIC_MAX_IRQ ((NVIC_MAX_BANKS - 1) * 32 + 16)
|
|
|
|
|
|
|
|
static struct irq_domain *nvic_irq_domain;
|
|
|
|
|
2021-10-21 03:23:09 +08:00
|
|
|
static void __nvic_handle_irq(irq_hw_number_t hwirq)
|
irq: arm: perform irqentry in entry code
In preparation for removing HANDLE_DOMAIN_IRQ_IRQENTRY, have arch/arm
perform all the irqentry accounting in its entry code.
For configurations with CONFIG_GENERIC_IRQ_MULTI_HANDLER, we can use
generic_handle_arch_irq(). Other than asm_do_IRQ(), all C calls to
handle_IRQ() are from irqchip handlers which will be called from
generic_handle_arch_irq(), so to avoid double accounting IRQ entry, the
entry logic is moved from handle_IRQ() into asm_do_IRQ().
For ARMv7M the entry assembly is tightly coupled with the NVIC irqchip, and
while the entry code should logically live under arch/arm/, moving the
entry logic there makes things more convoluted. So for now, place the
entry logic in the NVIC irqchip, but separated into a separate
function to make the split of responsibility clear.
For all other configurations without CONFIG_GENERIC_IRQ_MULTI_HANDLER,
IRQ entry is already handled in arch code, and requires no changes.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
2021-10-20 01:17:17 +08:00
|
|
|
{
|
2021-10-21 03:23:09 +08:00
|
|
|
generic_handle_domain_irq(nvic_irq_domain, hwirq);
|
irq: arm: perform irqentry in entry code
In preparation for removing HANDLE_DOMAIN_IRQ_IRQENTRY, have arch/arm
perform all the irqentry accounting in its entry code.
For configurations with CONFIG_GENERIC_IRQ_MULTI_HANDLER, we can use
generic_handle_arch_irq(). Other than asm_do_IRQ(), all C calls to
handle_IRQ() are from irqchip handlers which will be called from
generic_handle_arch_irq(), so to avoid double accounting IRQ entry, the
entry logic is moved from handle_IRQ() into asm_do_IRQ().
For ARMv7M the entry assembly is tightly coupled with the NVIC irqchip, and
while the entry code should logically live under arch/arm/, moving the
entry logic there makes things more convoluted. So for now, place the
entry logic in the NVIC irqchip, but separated into a separate
function to make the split of responsibility clear.
For all other configurations without CONFIG_GENERIC_IRQ_MULTI_HANDLER,
IRQ entry is already handled in arch code, and requires no changes.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
2021-10-20 01:17:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: restructure the ARMv7M entry logic so that this entry logic can live
|
|
|
|
* in arch code.
|
|
|
|
*/
|
2013-06-26 15:18:48 +08:00
|
|
|
asmlinkage void __exception_irq_entry
|
|
|
|
nvic_handle_irq(irq_hw_number_t hwirq, struct pt_regs *regs)
|
|
|
|
{
|
irq: arm: perform irqentry in entry code
In preparation for removing HANDLE_DOMAIN_IRQ_IRQENTRY, have arch/arm
perform all the irqentry accounting in its entry code.
For configurations with CONFIG_GENERIC_IRQ_MULTI_HANDLER, we can use
generic_handle_arch_irq(). Other than asm_do_IRQ(), all C calls to
handle_IRQ() are from irqchip handlers which will be called from
generic_handle_arch_irq(), so to avoid double accounting IRQ entry, the
entry logic is moved from handle_IRQ() into asm_do_IRQ().
For ARMv7M the entry assembly is tightly coupled with the NVIC irqchip, and
while the entry code should logically live under arch/arm/, moving the
entry logic there makes things more convoluted. So for now, place the
entry logic in the NVIC irqchip, but separated into a separate
function to make the split of responsibility clear.
For all other configurations without CONFIG_GENERIC_IRQ_MULTI_HANDLER,
IRQ entry is already handled in arch code, and requires no changes.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
2021-10-20 01:17:17 +08:00
|
|
|
struct pt_regs *old_regs;
|
|
|
|
|
|
|
|
irq_enter();
|
|
|
|
old_regs = set_irq_regs(regs);
|
2021-10-21 03:23:09 +08:00
|
|
|
__nvic_handle_irq(hwirq);
|
irq: arm: perform irqentry in entry code
In preparation for removing HANDLE_DOMAIN_IRQ_IRQENTRY, have arch/arm
perform all the irqentry accounting in its entry code.
For configurations with CONFIG_GENERIC_IRQ_MULTI_HANDLER, we can use
generic_handle_arch_irq(). Other than asm_do_IRQ(), all C calls to
handle_IRQ() are from irqchip handlers which will be called from
generic_handle_arch_irq(), so to avoid double accounting IRQ entry, the
entry logic is moved from handle_IRQ() into asm_do_IRQ().
For ARMv7M the entry assembly is tightly coupled with the NVIC irqchip, and
while the entry code should logically live under arch/arm/, moving the
entry logic there makes things more convoluted. So for now, place the
entry logic in the NVIC irqchip, but separated into a separate
function to make the split of responsibility clear.
For all other configurations without CONFIG_GENERIC_IRQ_MULTI_HANDLER,
IRQ entry is already handled in arch code, and requires no changes.
There should be no functional change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
2021-10-20 01:17:17 +08:00
|
|
|
set_irq_regs(old_regs);
|
|
|
|
irq_exit();
|
2013-06-26 15:18:48 +08:00
|
|
|
}
|
|
|
|
|
2015-05-16 17:44:16 +08:00
|
|
|
static int nvic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
|
|
|
|
unsigned int nr_irqs, void *arg)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
irq_hw_number_t hwirq;
|
|
|
|
unsigned int type = IRQ_TYPE_NONE;
|
2015-10-13 19:51:33 +08:00
|
|
|
struct irq_fwspec *fwspec = arg;
|
2015-05-16 17:44:16 +08:00
|
|
|
|
2019-12-10 19:11:10 +08:00
|
|
|
ret = irq_domain_translate_onecell(domain, fwspec, &hwirq, &type);
|
2015-05-16 17:44:16 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_irqs; i++)
|
|
|
|
irq_map_generic_chip(domain, virq + i, hwirq + i);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct irq_domain_ops nvic_irq_domain_ops = {
|
2019-12-10 19:11:10 +08:00
|
|
|
.translate = irq_domain_translate_onecell,
|
2015-05-16 17:44:16 +08:00
|
|
|
.alloc = nvic_irq_domain_alloc,
|
|
|
|
.free = irq_domain_free_irqs_top,
|
|
|
|
};
|
|
|
|
|
2013-06-26 15:18:48 +08:00
|
|
|
static int __init nvic_of_init(struct device_node *node,
|
|
|
|
struct device_node *parent)
|
|
|
|
{
|
|
|
|
unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
|
|
|
|
unsigned int irqs, i, ret, numbanks;
|
|
|
|
void __iomem *nvic_base;
|
|
|
|
|
|
|
|
numbanks = (readl_relaxed(V7M_SCS_ICTR) &
|
|
|
|
V7M_SCS_ICTR_INTLINESNUM_MASK) + 1;
|
|
|
|
|
|
|
|
nvic_base = of_iomap(node, 0);
|
|
|
|
if (!nvic_base) {
|
|
|
|
pr_warn("unable to map nvic registers\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
irqs = numbanks * 32;
|
|
|
|
if (irqs > NVIC_MAX_IRQ)
|
|
|
|
irqs = NVIC_MAX_IRQ;
|
|
|
|
|
|
|
|
nvic_irq_domain =
|
2015-05-16 17:44:16 +08:00
|
|
|
irq_domain_add_linear(node, irqs, &nvic_irq_domain_ops, NULL);
|
|
|
|
|
2013-06-26 15:18:48 +08:00
|
|
|
if (!nvic_irq_domain) {
|
|
|
|
pr_warn("Failed to allocate irq domain\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-07-05 15:39:11 +08:00
|
|
|
ret = irq_alloc_domain_generic_chips(nvic_irq_domain, 32, 1,
|
2013-06-26 15:18:48 +08:00
|
|
|
"nvic_irq", handle_fasteoi_irq,
|
|
|
|
clr, 0, IRQ_GC_INIT_MASK_CACHE);
|
|
|
|
if (ret) {
|
|
|
|
pr_warn("Failed to allocate irq chips\n");
|
|
|
|
irq_domain_remove(nvic_irq_domain);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numbanks; ++i) {
|
|
|
|
struct irq_chip_generic *gc;
|
|
|
|
|
|
|
|
gc = irq_get_domain_generic_chip(nvic_irq_domain, 32 * i);
|
|
|
|
gc->reg_base = nvic_base + 4 * i;
|
|
|
|
gc->chip_types[0].regs.enable = NVIC_ISER;
|
|
|
|
gc->chip_types[0].regs.disable = NVIC_ICER;
|
|
|
|
gc->chip_types[0].chip.irq_mask = irq_gc_mask_disable_reg;
|
|
|
|
gc->chip_types[0].chip.irq_unmask = irq_gc_unmask_enable_reg;
|
2014-06-04 23:01:52 +08:00
|
|
|
/* This is a no-op as end of interrupt is signaled by the
|
|
|
|
* exception return sequence.
|
|
|
|
*/
|
|
|
|
gc->chip_types[0].chip.irq_eoi = irq_gc_noop;
|
2013-06-26 15:18:48 +08:00
|
|
|
|
|
|
|
/* disable interrupts */
|
|
|
|
writel_relaxed(~0, gc->reg_base + NVIC_ICER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set priority on all interrupts */
|
|
|
|
for (i = 0; i < irqs; i += 4)
|
|
|
|
writel_relaxed(0, nvic_base + NVIC_IPR + i);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
IRQCHIP_DECLARE(armv7m_nvic, "arm,armv7m-nvic", nvic_of_init);
|