Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 Ralf Baechle |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | * |
| 9 | * Handler for RM9000 extended interrupts. These are a non-standard |
| 10 | * feature so we handle them separately from standard interrupts. |
| 11 | */ |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/interrupt.h> |
David Howells | ca4d3e67 | 2010-10-07 14:08:54 +0100 | [diff] [blame] | 14 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | |
| 18 | #include <asm/irq_cpu.h> |
| 19 | #include <asm/mipsregs.h> |
| 20 | #include <asm/system.h> |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static inline void unmask_rm9k_irq(unsigned int irq) |
| 23 | { |
Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 24 | set_c0_intcontrol(0x1000 << (irq - RM9K_CPU_IRQ_BASE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | static inline void mask_rm9k_irq(unsigned int irq) |
| 28 | { |
Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 29 | clear_c0_intcontrol(0x1000 << (irq - RM9K_CPU_IRQ_BASE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static inline void rm9k_cpu_irq_enable(unsigned int irq) |
| 33 | { |
| 34 | unsigned long flags; |
| 35 | |
| 36 | local_irq_save(flags); |
| 37 | unmask_rm9k_irq(irq); |
| 38 | local_irq_restore(flags); |
| 39 | } |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* |
| 42 | * Performance counter interrupts are global on all processors. |
| 43 | */ |
| 44 | static void local_rm9k_perfcounter_irq_startup(void *args) |
| 45 | { |
| 46 | unsigned int irq = (unsigned int) args; |
| 47 | |
| 48 | rm9k_cpu_irq_enable(irq); |
| 49 | } |
| 50 | |
| 51 | static unsigned int rm9k_perfcounter_irq_startup(unsigned int irq) |
| 52 | { |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 53 | on_each_cpu(local_rm9k_perfcounter_irq_startup, (void *) irq, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static void local_rm9k_perfcounter_irq_shutdown(void *args) |
| 59 | { |
| 60 | unsigned int irq = (unsigned int) args; |
| 61 | unsigned long flags; |
| 62 | |
| 63 | local_irq_save(flags); |
| 64 | mask_rm9k_irq(irq); |
| 65 | local_irq_restore(flags); |
| 66 | } |
| 67 | |
| 68 | static void rm9k_perfcounter_irq_shutdown(unsigned int irq) |
| 69 | { |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 70 | on_each_cpu(local_rm9k_perfcounter_irq_shutdown, (void *) irq, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Ralf Baechle | 94dee17 | 2006-07-02 14:41:42 +0100 | [diff] [blame] | 73 | static struct irq_chip rm9k_irq_controller = { |
Atsushi Nemoto | 70d21cd | 2007-01-15 00:07:25 +0900 | [diff] [blame] | 74 | .name = "RM9000", |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 75 | .ack = mask_rm9k_irq, |
| 76 | .mask = mask_rm9k_irq, |
| 77 | .mask_ack = mask_rm9k_irq, |
| 78 | .unmask = unmask_rm9k_irq, |
Thomas Koeller | c42d95d | 2008-02-11 23:42:12 +0100 | [diff] [blame] | 79 | .eoi = unmask_rm9k_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Ralf Baechle | 94dee17 | 2006-07-02 14:41:42 +0100 | [diff] [blame] | 82 | static struct irq_chip rm9k_perfcounter_irq = { |
Atsushi Nemoto | 70d21cd | 2007-01-15 00:07:25 +0900 | [diff] [blame] | 83 | .name = "RM9000", |
Ralf Baechle | 8ab00b9 | 2005-02-28 13:39:57 +0000 | [diff] [blame] | 84 | .startup = rm9k_perfcounter_irq_startup, |
| 85 | .shutdown = rm9k_perfcounter_irq_shutdown, |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 86 | .ack = mask_rm9k_irq, |
| 87 | .mask = mask_rm9k_irq, |
| 88 | .mask_ack = mask_rm9k_irq, |
| 89 | .unmask = unmask_rm9k_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | unsigned int rm9000_perfcount_irq; |
| 93 | |
| 94 | EXPORT_SYMBOL(rm9000_perfcount_irq); |
| 95 | |
Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 96 | void __init rm9k_cpu_irq_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 98 | int base = RM9K_CPU_IRQ_BASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | int i; |
| 100 | |
| 101 | clear_c0_intcontrol(0x0000f000); /* Mask all */ |
| 102 | |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 103 | for (i = base; i < base + 4; i++) |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame] | 104 | set_irq_chip_and_handler(i, &rm9k_irq_controller, |
| 105 | handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | rm9000_perfcount_irq = base + 1; |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame] | 108 | set_irq_chip_and_handler(rm9000_perfcount_irq, &rm9k_perfcounter_irq, |
Ralf Baechle | 30e748a | 2007-11-15 19:37:15 +0000 | [diff] [blame] | 109 | handle_percpu_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |