···11+/*22+ * Copyright (C) 2013 Altera Corporation33+ * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>44+ *55+ * This program is free software; you can redistribute it and/or modify66+ * it under the terms of the GNU General Public License as published by77+ * the Free Software Foundation; either version 2 of the License, or88+ * (at your option) any later version.99+ *1010+ * This program is distributed in the hope that it will be useful,1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313+ * GNU General Public License for more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1717+ *1818+ */1919+2020+#ifndef _ASM_NIOS2_IRQ_H2121+#define _ASM_NIOS2_IRQ_H2222+2323+#define NIOS2_CPU_NR_IRQS 322424+2525+#include <asm-generic/irq.h>2626+#include <linux/irqdomain.h>2727+2828+#endif
+72
arch/nios2/include/asm/irqflags.h
···11+/*22+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or77+ * (at your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful,1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ *1414+ * You should have received a copy of the GNU General Public License1515+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1616+ *1717+ */1818+#ifndef _ASM_IRQFLAGS_H1919+#define _ASM_IRQFLAGS_H2020+2121+#include <asm/registers.h>2222+2323+static inline unsigned long arch_local_save_flags(void)2424+{2525+ return RDCTL(CTL_STATUS);2626+}2727+2828+/*2929+ * This will restore ALL status register flags, not only the interrupt3030+ * mask flag.3131+ */3232+static inline void arch_local_irq_restore(unsigned long flags)3333+{3434+ WRCTL(CTL_STATUS, flags);3535+}3636+3737+static inline void arch_local_irq_disable(void)3838+{3939+ unsigned long flags;4040+4141+ flags = arch_local_save_flags();4242+ arch_local_irq_restore(flags & ~STATUS_PIE);4343+}4444+4545+static inline void arch_local_irq_enable(void)4646+{4747+ unsigned long flags;4848+4949+ flags = arch_local_save_flags();5050+ arch_local_irq_restore(flags | STATUS_PIE);5151+}5252+5353+static inline int arch_irqs_disabled_flags(unsigned long flags)5454+{5555+ return (flags & STATUS_PIE) == 0;5656+}5757+5858+static inline int arch_irqs_disabled(void)5959+{6060+ return arch_irqs_disabled_flags(arch_local_save_flags());6161+}6262+6363+static inline unsigned long arch_local_irq_save(void)6464+{6565+ unsigned long flags;6666+6767+ flags = arch_local_save_flags();6868+ arch_local_irq_restore(flags & ~STATUS_PIE);6969+ return flags;7070+}7171+7272+#endif /* _ASM_IRQFLAGS_H */
+93
arch/nios2/kernel/irq.c
···11+/*22+ * Copyright (C) 2013 Altera Corporation33+ * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>44+ * Copyright (C) 2008 Thomas Chou <thomas@wytron.com.tw>55+ *66+ * based on irq.c from m68k which is:77+ *88+ * Copyright (C) 2007 Greg Ungerer <gerg@snapgear.com>99+ *1010+ * This program is free software; you can redistribute it and/or modify1111+ * it under the terms of the GNU General Public License as published by1212+ * the Free Software Foundation; either version 2 of the License, or1313+ * (at your option) any later version.1414+ *1515+ * This program is distributed in the hope that it will be useful,1616+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1717+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1818+ * GNU General Public License for more details.1919+ *2020+ * You should have received a copy of the GNU General Public License2121+ * along with this program. If not, see <http://www.gnu.org/licenses/>.2222+ *2323+ */2424+2525+#include <linux/init.h>2626+#include <linux/interrupt.h>2727+#include <linux/of.h>2828+2929+static u32 ienable;3030+3131+asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)3232+{3333+ struct pt_regs *oldregs = set_irq_regs(regs);3434+ int irq;3535+3636+ irq_enter();3737+ irq = irq_find_mapping(NULL, hwirq);3838+ generic_handle_irq(irq);3939+ irq_exit();4040+4141+ set_irq_regs(oldregs);4242+}4343+4444+static void chip_unmask(struct irq_data *d)4545+{4646+ ienable |= (1 << d->hwirq);4747+ WRCTL(CTL_IENABLE, ienable);4848+}4949+5050+static void chip_mask(struct irq_data *d)5151+{5252+ ienable &= ~(1 << d->hwirq);5353+ WRCTL(CTL_IENABLE, ienable);5454+}5555+5656+static struct irq_chip m_irq_chip = {5757+ .name = "NIOS2-INTC",5858+ .irq_unmask = chip_unmask,5959+ .irq_mask = chip_mask,6060+};6161+6262+static int irq_map(struct irq_domain *h, unsigned int virq,6363+ irq_hw_number_t hw_irq_num)6464+{6565+ irq_set_chip_and_handler(virq, &m_irq_chip, handle_level_irq);6666+6767+ return 0;6868+}6969+7070+static struct irq_domain_ops irq_ops = {7171+ .map = irq_map,7272+ .xlate = irq_domain_xlate_onecell,7373+};7474+7575+void __init init_IRQ(void)7676+{7777+ struct irq_domain *domain;7878+ struct device_node *node;7979+8080+ node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.0");8181+ if (!node)8282+ node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.1");8383+8484+ BUG_ON(!node);8585+8686+ domain = irq_domain_add_linear(node, NIOS2_CPU_NR_IRQS, &irq_ops, NULL);8787+ BUG_ON(!domain);8888+8989+ irq_set_default_host(domain);9090+ of_node_put(node);9191+ /* Load the initial ienable value */9292+ ienable = RDCTL(CTL_IENABLE);9393+}