/*1* Copyright (C) 1999, 2005 MIPS Technologies, Inc. All rights reserved.2*3* This program is free software; you can distribute it and/or modify it4* under the terms of the GNU General Public License (Version 2) as5* published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* for more details.11*12* You should have received a copy of the GNU General Public License along13* with this program; if not, write to the Free Software Foundation, Inc.,14* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.15*16*/17#include <linux/init.h>18#include <linux/sched.h>19#include <linux/interrupt.h>20#include <linux/kernel_stat.h>21#include <asm/mips-boards/simint.h>22#include <asm/irq_cpu.h>2324static inline int clz(unsigned long x)25{26__asm__(27" .set push \n"28" .set mips32 \n"29" clz %0, %1 \n"30" .set pop \n"31: "=r" (x)32: "r" (x));3334return x;35}3637/*38* Version of ffs that only looks at bits 12..15.39*/40static inline unsigned int irq_ffs(unsigned int pending)41{42#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)43return -clz(pending) + 31 - CAUSEB_IP;44#else45unsigned int a0 = 7;46unsigned int t0;4748t0 = s0 & 0xf000;49t0 = t0 < 1;50t0 = t0 << 2;51a0 = a0 - t0;52s0 = s0 << t0;5354t0 = s0 & 0xc000;55t0 = t0 < 1;56t0 = t0 << 1;57a0 = a0 - t0;58s0 = s0 << t0;5960t0 = s0 & 0x8000;61t0 = t0 < 1;62/* t0 = t0 << 2; */63a0 = a0 - t0;64/* s0 = s0 << t0; */6566return a0;67#endif68}6970asmlinkage void plat_irq_dispatch(void)71{72unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;73int irq;7475irq = irq_ffs(pending);7677if (irq > 0)78do_IRQ(MIPS_CPU_IRQ_BASE + irq);79else80spurious_interrupt();81}8283void __init arch_init_irq(void)84{85mips_cpu_irq_init();86}878889