xref: /linux/arch/loongarch/kernel/irq.c (revision a2a4ee550704901aa148b57a55cb73cc1e8ae9b1)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #include <linux/kernel.h>
6 #include <linux/acpi.h>
7 #include <linux/atomic.h>
8 #include <linux/delay.h>
9 #include <linux/init.h>
10 #include <linux/interrupt.h>
11 #include <linux/irqchip.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/proc_fs.h>
14 #include <linux/mm.h>
15 #include <linux/sched.h>
16 #include <linux/seq_file.h>
17 #include <linux/kallsyms.h>
18 #include <linux/uaccess.h>
19 
20 #include <asm/irq.h>
21 #include <asm/loongson.h>
22 #include <asm/setup.h>
23 
24 DEFINE_PER_CPU(unsigned long, irq_stack);
25 
26 struct irq_domain *cpu_domain;
27 struct irq_domain *liointc_domain;
28 struct irq_domain *pch_lpc_domain;
29 struct irq_domain *pch_msi_domain[MAX_IO_PICS];
30 struct irq_domain *pch_pic_domain[MAX_IO_PICS];
31 
32 /*
33  * 'what should we do if we get a hw irq event on an illegal vector'.
34  * each architecture has to answer this themselves.
35  */
36 void ack_bad_irq(unsigned int irq)
37 {
38 	pr_warn("Unexpected IRQ # %d\n", irq);
39 }
40 
41 atomic_t irq_err_count;
42 
43 asmlinkage void spurious_interrupt(void)
44 {
45 	atomic_inc(&irq_err_count);
46 }
47 
48 int arch_show_interrupts(struct seq_file *p, int prec)
49 {
50 #ifdef CONFIG_SMP
51 	show_ipi_list(p, prec);
52 #endif
53 	seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
54 	return 0;
55 }
56 
57 void __init init_IRQ(void)
58 {
59 	int i, r, ipi_irq;
60 	static int ipi_dummy_dev;
61 	unsigned int order = get_order(IRQ_STACK_SIZE);
62 	struct page *page;
63 
64 	clear_csr_ecfg(ECFG0_IM);
65 	clear_csr_estat(ESTATF_IP);
66 
67 	irqchip_init();
68 #ifdef CONFIG_SMP
69 	ipi_irq = EXCCODE_IPI - EXCCODE_INT_START;
70 	irq_set_percpu_devid(ipi_irq);
71 	r = request_percpu_irq(ipi_irq, loongson3_ipi_interrupt, "IPI", &ipi_dummy_dev);
72 	if (r < 0)
73 		panic("IPI IRQ request failed\n");
74 #endif
75 
76 	for (i = 0; i < NR_IRQS; i++)
77 		irq_set_noprobe(i);
78 
79 	for_each_possible_cpu(i) {
80 		page = alloc_pages_node(cpu_to_node(i), GFP_KERNEL, order);
81 
82 		per_cpu(irq_stack, i) = (unsigned long)page_address(page);
83 		pr_debug("CPU%d IRQ stack at 0x%lx - 0x%lx\n", i,
84 			per_cpu(irq_stack, i), per_cpu(irq_stack, i) + IRQ_STACK_SIZE);
85 	}
86 
87 	set_csr_ecfg(ECFGF_IP0 | ECFGF_IP1 | ECFGF_IP2 | ECFGF_IPI | ECFGF_PMC);
88 }
89