Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / xtensa / kernel / irq.c
blobb1e410f6b5ab8e043759b66693f86eae90b668fd
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/xtensa/kernel/irq.c
5 * Xtensa built-in interrupt controller and some generic functions copied
6 * from i386.
8 * Copyright (C) 2002 - 2013 Tensilica, Inc.
9 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
12 * Chris Zankel <chris@zankel.net>
13 * Kevin Chea
17 #include <linux/module.h>
18 #include <linux/seq_file.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/kernel_stat.h>
22 #include <linux/irqchip.h>
23 #include <linux/irqchip/xtensa-mx.h>
24 #include <linux/irqchip/xtensa-pic.h>
25 #include <linux/irqdomain.h>
26 #include <linux/of.h>
28 #include <asm/mxregs.h>
29 #include <linux/uaccess.h>
30 #include <asm/platform.h>
31 #include <asm/traps.h>
33 DECLARE_PER_CPU(unsigned long, nmi_count);
35 asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
37 #ifdef CONFIG_DEBUG_STACKOVERFLOW
38 /* Debugging check for stack overflow: is there less than 1KB free? */
40 unsigned long sp = current_stack_pointer;
42 sp &= THREAD_SIZE - 1;
44 if (unlikely(sp < (sizeof(thread_info) + 1024)))
45 printk("Stack overflow in do_IRQ: %ld\n",
46 sp - sizeof(struct thread_info));
48 #endif
49 generic_handle_domain_irq(NULL, hwirq);
52 int arch_show_interrupts(struct seq_file *p, int prec)
54 unsigned cpu __maybe_unused;
55 #ifdef CONFIG_SMP
56 show_ipi_list(p, prec);
57 #endif
58 #if XTENSA_FAKE_NMI
59 seq_printf(p, "%*s:", prec, "NMI");
60 for_each_online_cpu(cpu)
61 seq_printf(p, " %10lu", per_cpu(nmi_count, cpu));
62 seq_puts(p, " Non-maskable interrupts\n");
63 #endif
64 return 0;
67 int xtensa_irq_domain_xlate(const u32 *intspec, unsigned int intsize,
68 unsigned long int_irq, unsigned long ext_irq,
69 unsigned long *out_hwirq, unsigned int *out_type)
71 if (WARN_ON(intsize < 1 || intsize > 2))
72 return -EINVAL;
73 if (intsize == 2 && intspec[1] == 1) {
74 int_irq = xtensa_map_ext_irq(ext_irq);
75 if (int_irq < XCHAL_NUM_INTERRUPTS)
76 *out_hwirq = int_irq;
77 else
78 return -EINVAL;
79 } else {
80 *out_hwirq = int_irq;
82 *out_type = IRQ_TYPE_NONE;
83 return 0;
86 int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
87 irq_hw_number_t hw)
89 struct irq_chip *irq_chip = d->host_data;
90 u32 mask = 1 << hw;
92 if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) {
93 irq_set_chip_and_handler_name(irq, irq_chip,
94 handle_simple_irq, "level");
95 irq_set_status_flags(irq, IRQ_LEVEL);
96 } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) {
97 irq_set_chip_and_handler_name(irq, irq_chip,
98 handle_edge_irq, "edge");
99 irq_clear_status_flags(irq, IRQ_LEVEL);
100 } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) {
101 irq_set_chip_and_handler_name(irq, irq_chip,
102 handle_level_irq, "level");
103 irq_set_status_flags(irq, IRQ_LEVEL);
104 } else if (mask & XCHAL_INTTYPE_MASK_TIMER) {
105 irq_set_chip_and_handler_name(irq, irq_chip,
106 handle_percpu_irq, "timer");
107 irq_clear_status_flags(irq, IRQ_LEVEL);
108 #ifdef XCHAL_INTTYPE_MASK_PROFILING
109 } else if (mask & XCHAL_INTTYPE_MASK_PROFILING) {
110 irq_set_chip_and_handler_name(irq, irq_chip,
111 handle_percpu_irq, "profiling");
112 irq_set_status_flags(irq, IRQ_LEVEL);
113 #endif
114 } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */
115 /* XCHAL_INTTYPE_MASK_NMI */
116 irq_set_chip_and_handler_name(irq, irq_chip,
117 handle_level_irq, "level");
118 irq_set_status_flags(irq, IRQ_LEVEL);
120 return 0;
123 unsigned xtensa_map_ext_irq(unsigned ext_irq)
125 unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE |
126 XCHAL_INTTYPE_MASK_EXTERN_LEVEL;
127 unsigned i;
129 for (i = 0; mask; ++i, mask >>= 1) {
130 if ((mask & 1) && ext_irq-- == 0)
131 return i;
133 return XCHAL_NUM_INTERRUPTS;
136 unsigned xtensa_get_ext_irq_no(unsigned irq)
138 unsigned mask = (XCHAL_INTTYPE_MASK_EXTERN_EDGE |
139 XCHAL_INTTYPE_MASK_EXTERN_LEVEL) &
140 ((1u << irq) - 1);
141 return hweight32(mask);
144 void __init init_IRQ(void)
146 #ifdef CONFIG_USE_OF
147 irqchip_init();
148 #else
149 #ifdef CONFIG_HAVE_SMP
150 xtensa_mx_init_legacy(NULL);
151 #else
152 xtensa_pic_init_legacy(NULL);
153 #endif
154 #endif
156 #ifdef CONFIG_SMP
157 ipi_init();
158 #endif
161 #ifdef CONFIG_HOTPLUG_CPU
163 * The CPU has been marked offline. Migrate IRQs off this CPU. If
164 * the affinity settings do not allow other CPUs, force them onto any
165 * available CPU.
167 void migrate_irqs(void)
169 unsigned int i, cpu = smp_processor_id();
171 for_each_active_irq(i) {
172 struct irq_data *data = irq_get_irq_data(i);
173 const struct cpumask *mask;
174 unsigned int newcpu;
176 if (irqd_is_per_cpu(data))
177 continue;
179 mask = irq_data_get_affinity_mask(data);
180 if (!cpumask_test_cpu(cpu, mask))
181 continue;
183 newcpu = cpumask_any_and(mask, cpu_online_mask);
185 if (newcpu >= nr_cpu_ids) {
186 pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
187 i, cpu);
189 irq_set_affinity(i, cpu_all_mask);
190 } else {
191 irq_set_affinity(i, mask);
195 #endif /* CONFIG_HOTPLUG_CPU */