Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/arch/sh/kernel/irq.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * SuperH version:  Copyright (C) 1999  Niibe Yutaka
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/machvec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <cpu/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) atomic_t irq_err_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * 'what should we do if we get a hw irq event on an illegal vector'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * each architecture has to answer this themselves, it doesn't deserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * a generic callback i think.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) void ack_bad_irq(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	atomic_inc(&irq_err_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	printk("unexpected IRQ trap at vector %02x\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #if defined(CONFIG_PROC_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * /proc/interrupts printing for arch specific interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) int arch_show_interrupts(struct seq_file *p, int prec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	seq_printf(p, "%*s: ", prec, "NMI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	for_each_online_cpu(j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		seq_printf(p, "%10u ", nmi_count(j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	seq_printf(p, "  Non-maskable interrupts\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #ifdef CONFIG_IRQSTACKS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * per-CPU IRQ handling contexts (thread information and stack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) union irq_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct thread_info	tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u32			stack[THREAD_SIZE/sizeof(u32)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static inline void handle_one_irq(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	union irq_ctx *curctx, *irqctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	curctx = (union irq_ctx *)current_thread_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	irqctx = hardirq_ctx[smp_processor_id()];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * this is where we switch to the IRQ stack. However, if we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * already using the IRQ stack (because we interrupted a hardirq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * handler) we can't do that and just have to keep using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * current stack (which is the irq stack already after all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (curctx != irqctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		u32 *isp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		irqctx->tinfo.task = curctx->tinfo.task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		irqctx->tinfo.previous_sp = current_stack_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		 * Copy the softirq bits in preempt_count so that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		 * softirq checks work in the hardirq context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		irqctx->tinfo.preempt_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			(irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			(curctx->tinfo.preempt_count & SOFTIRQ_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		__asm__ __volatile__ (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			"mov	%0, r4		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			"mov	r15, r8		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			"jsr	@%1		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			/* switch to the irq stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			" mov	%2, r15		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			/* restore the stack (ring zero) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			"mov	r8, r15		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			: /* no outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			: "r" (irq), "r" (generic_handle_irq), "r" (isp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			: "memory", "r0", "r1", "r2", "r3", "r4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			  "r5", "r6", "r7", "r8", "t", "pr"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		generic_handle_irq(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * allocate per-cpu stacks for hardirq and for softirq processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void irq_ctx_init(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	union irq_ctx *irqctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (hardirq_ctx[cpu])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	irqctx->tinfo.task		= NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	irqctx->tinfo.cpu		= cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	irqctx->tinfo.preempt_count	= HARDIRQ_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	irqctx->tinfo.addr_limit	= MAKE_MM_SEG(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	hardirq_ctx[cpu] = irqctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	irqctx->tinfo.task		= NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	irqctx->tinfo.cpu		= cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	irqctx->tinfo.preempt_count	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	irqctx->tinfo.addr_limit	= MAKE_MM_SEG(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	softirq_ctx[cpu] = irqctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	printk("CPU %u irqstacks, hard=%p soft=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void irq_ctx_exit(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	hardirq_ctx[cpu] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) void do_softirq_own_stack(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct thread_info *curctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	union irq_ctx *irqctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	u32 *isp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	curctx = current_thread_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	irqctx = softirq_ctx[smp_processor_id()];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	irqctx->tinfo.task = curctx->task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	irqctx->tinfo.previous_sp = current_stack_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* build the stack frame on the softirq stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	__asm__ __volatile__ (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		"mov	r15, r9		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		"jsr	@%0		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		/* switch to the softirq stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		" mov	%1, r15		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		/* restore the thread stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		"mov	r9, r15		\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		: /* no outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		: "r" (__do_softirq), "r" (isp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		: "memory", "r0", "r1", "r2", "r3", "r4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		  "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static inline void handle_one_irq(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	generic_handle_irq(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct pt_regs *old_regs = set_irq_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	irq_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	irq = irq_demux(irq_lookup(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (irq != NO_IRQ_IGNORE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		handle_one_irq(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		irq_finish(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	set_irq_regs(old_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) void __init init_IRQ(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	plat_irq_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/* Perform the machine specific initialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (sh_mv.mv_init_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		sh_mv.mv_init_irq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	intc_finalize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	irq_ctx_init(smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * The CPU has been marked offline.  Migrate IRQs off this CPU.  If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * the affinity settings do not allow other CPUs, force them onto any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * available CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) void migrate_irqs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	unsigned int irq, cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	for_each_active_irq(irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		struct irq_data *data = irq_get_irq_data(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (irq_data_get_node(data) == cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			struct cpumask *mask = irq_data_get_affinity_mask(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			unsigned int newcpu = cpumask_any_and(mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 							      cpu_online_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			if (newcpu >= nr_cpu_ids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 						    irq, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				cpumask_setall(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			irq_set_affinity(irq, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #endif