| Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 2 | * SS1000/SC2000 interrupt handling. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * | 
|  | 4 | *  Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | 
|  | 5 | *  Heavily based on arch/sparc/kernel/irq.c. | 
|  | 6 | */ | 
|  | 7 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/kernel_stat.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/seq_file.h> | 
|  | 10 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/timer.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/traps.h> | 
|  | 13 | #include <asm/irq.h> | 
|  | 14 | #include <asm/io.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/sbi.h> | 
|  | 16 | #include <asm/cacheflush.h> | 
| Daniel Hellstrom | 5fcafb7 | 2011-04-21 04:20:23 +0000 | [diff] [blame] | 17 | #include <asm/setup.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 |  | 
| Sam Ravnborg | 81265fd | 2008-12-08 01:08:24 -0800 | [diff] [blame] | 19 | #include "kernel.h" | 
| Al Viro | 32231a6 | 2007-07-21 19:18:57 -0700 | [diff] [blame] | 20 | #include "irq.h" | 
|  | 21 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 22 | /* Sun4d interrupts fall roughly into two categories.  SBUS and | 
|  | 23 | * cpu local.  CPU local interrupts cover the timer interrupts | 
|  | 24 | * and whatnot, and we encode those as normal PILs between | 
|  | 25 | * 0 and 15. | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 26 | * SBUS interrupts are encodes as a combination of board, level and slot. | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 27 | */ | 
|  | 28 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 29 | struct sun4d_handler_data { | 
|  | 30 | unsigned int cpuid;    /* target cpu */ | 
|  | 31 | unsigned int real_irq; /* interrupt level */ | 
|  | 32 | }; | 
|  | 33 |  | 
|  | 34 |  | 
|  | 35 | static unsigned int sun4d_encode_irq(int board, int lvl, int slot) | 
|  | 36 | { | 
|  | 37 | return (board + 1) << 5 | (lvl << 2) | slot; | 
|  | 38 | } | 
|  | 39 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 40 | struct sun4d_timer_regs { | 
|  | 41 | u32	l10_timer_limit; | 
|  | 42 | u32	l10_cur_countx; | 
|  | 43 | u32	l10_limit_noclear; | 
|  | 44 | u32	ctrl; | 
|  | 45 | u32	l10_cur_count; | 
|  | 46 | }; | 
|  | 47 |  | 
|  | 48 | static struct sun4d_timer_regs __iomem *sun4d_timers; | 
|  | 49 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 50 | #define SUN4D_TIMER_IRQ        10 | 
| Sam Ravnborg | db1cdd1 | 2011-04-18 11:25:42 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | /* Specify which cpu handle interrupts from which board. | 
|  | 53 | * Index is board - value is cpu. | 
|  | 54 | */ | 
|  | 55 | static unsigned char board_to_cpu[32]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static int pil_to_sbus[] = { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 58 | 0, | 
|  | 59 | 0, | 
|  | 60 | 1, | 
|  | 61 | 2, | 
|  | 62 | 0, | 
|  | 63 | 3, | 
|  | 64 | 0, | 
|  | 65 | 4, | 
|  | 66 | 0, | 
|  | 67 | 5, | 
|  | 68 | 0, | 
|  | 69 | 6, | 
|  | 70 | 0, | 
|  | 71 | 7, | 
|  | 72 | 0, | 
|  | 73 | 0, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; | 
|  | 75 |  | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 76 | /* Exported for sun4d_smp.c */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | DEFINE_SPINLOCK(sun4d_imsk_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 79 | /* SBUS interrupts are encoded integers including the board number | 
|  | 80 | * (plus one), the SBUS level, and the SBUS slot number.  Sun4D | 
|  | 81 | * IRQ dispatch is done by: | 
|  | 82 | * | 
|  | 83 | * 1) Reading the BW local interrupt table in order to get the bus | 
|  | 84 | *    interrupt mask. | 
|  | 85 | * | 
|  | 86 | *    This table is indexed by SBUS interrupt level which can be | 
|  | 87 | *    derived from the PIL we got interrupted on. | 
|  | 88 | * | 
|  | 89 | * 2) For each bus showing interrupt pending from #1, read the | 
|  | 90 | *    SBI interrupt state register.  This will indicate which slots | 
|  | 91 | *    have interrupts pending for that SBUS interrupt level. | 
|  | 92 | * | 
|  | 93 | * 3) Call the genreric IRQ support. | 
|  | 94 | */ | 
|  | 95 | static void sun4d_sbus_handler_irq(int sbusl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 97 | unsigned int bus_mask; | 
|  | 98 | unsigned int sbino, slot; | 
|  | 99 | unsigned int sbil; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 101 | bus_mask = bw_get_intr_mask(sbusl) & 0x3ffff; | 
|  | 102 | bw_clear_intr_mask(sbusl, bus_mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 104 | sbil = (sbusl << 2); | 
|  | 105 | /* Loop for each pending SBI */ | 
| oftedal | ea16058 | 2011-06-01 11:04:20 +0000 | [diff] [blame] | 106 | for (sbino = 0; bus_mask; sbino++, bus_mask >>= 1) { | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 107 | unsigned int idx, mask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 109 | if (!(bus_mask & 1)) | 
|  | 110 | continue; | 
|  | 111 | /* XXX This seems to ACK the irq twice.  acquire_sbi() | 
|  | 112 | * XXX uses swap, therefore this writes 0xf << sbil, | 
|  | 113 | * XXX then later release_sbi() will write the individual | 
|  | 114 | * XXX bits which were set again. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | */ | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 116 | mask = acquire_sbi(SBI2DEVID(sbino), 0xf << sbil); | 
|  | 117 | mask &= (0xf << sbil); | 
|  | 118 |  | 
|  | 119 | /* Loop for each pending SBI slot */ | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 120 | slot = (1 << sbil); | 
| oftedal | ea16058 | 2011-06-01 11:04:20 +0000 | [diff] [blame] | 121 | for (idx = 0; mask != 0; idx++, slot <<= 1) { | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 122 | unsigned int pil; | 
|  | 123 | struct irq_bucket *p; | 
|  | 124 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 125 | if (!(mask & slot)) | 
|  | 126 | continue; | 
|  | 127 |  | 
|  | 128 | mask &= ~slot; | 
| oftedal | ea16058 | 2011-06-01 11:04:20 +0000 | [diff] [blame] | 129 | pil = sun4d_encode_irq(sbino, sbusl, idx); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 130 |  | 
|  | 131 | p = irq_map[pil]; | 
|  | 132 | while (p) { | 
|  | 133 | struct irq_bucket *next; | 
|  | 134 |  | 
|  | 135 | next = p->next; | 
|  | 136 | generic_handle_irq(p->irq); | 
|  | 137 | p = next; | 
|  | 138 | } | 
|  | 139 | release_sbi(SBI2DEVID(sbino), slot); | 
|  | 140 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } | 
|  | 143 |  | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 144 | void sun4d_handler_irq(int pil, struct pt_regs *regs) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 146 | struct pt_regs *old_regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* SBUS IRQ level (1 - 7) */ | 
| Sam Ravnborg | d4d1ec4 | 2011-01-22 11:32:15 +0000 | [diff] [blame] | 148 | int sbusl = pil_to_sbus[pil]; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 149 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* FIXME: Is this necessary?? */ | 
|  | 151 | cc_get_ipen(); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 152 |  | 
| Sam Ravnborg | d4d1ec4 | 2011-01-22 11:32:15 +0000 | [diff] [blame] | 153 | cc_set_iclr(1 << pil); | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 154 |  | 
| Daniel Hellstrom | 55dd23e | 2011-05-02 00:08:54 +0000 | [diff] [blame] | 155 | #ifdef CONFIG_SMP | 
|  | 156 | /* | 
|  | 157 | * Check IPI data structures after IRQ has been cleared. Hard and Soft | 
|  | 158 | * IRQ can happen at the same time, so both cases are always handled. | 
|  | 159 | */ | 
|  | 160 | if (pil == SUN4D_IPI_IRQ) | 
|  | 161 | sun4d_ipi_interrupt(); | 
|  | 162 | #endif | 
|  | 163 |  | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 164 | old_regs = set_irq_regs(regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | irq_enter(); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 166 | if (sbusl == 0) { | 
|  | 167 | /* cpu interrupt */ | 
|  | 168 | struct irq_bucket *p; | 
|  | 169 |  | 
|  | 170 | p = irq_map[pil]; | 
|  | 171 | while (p) { | 
|  | 172 | struct irq_bucket *next; | 
|  | 173 |  | 
|  | 174 | next = p->next; | 
|  | 175 | generic_handle_irq(p->irq); | 
|  | 176 | p = next; | 
|  | 177 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } else { | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 179 | /* SBUS interrupt */ | 
|  | 180 | sun4d_sbus_handler_irq(sbusl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } | 
|  | 182 | irq_exit(); | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 183 | set_irq_regs(old_regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } | 
|  | 185 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 186 |  | 
|  | 187 | static void sun4d_mask_irq(struct irq_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 189 | struct sun4d_handler_data *handler_data = data->handler_data; | 
|  | 190 | unsigned int real_irq; | 
|  | 191 | #ifdef CONFIG_SMP | 
|  | 192 | int cpuid = handler_data->cpuid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | unsigned long flags; | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 194 | #endif | 
|  | 195 | real_irq = handler_data->real_irq; | 
|  | 196 | #ifdef CONFIG_SMP | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | spin_lock_irqsave(&sun4d_imsk_lock, flags); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 198 | cc_set_imsk_other(cpuid, cc_get_imsk_other(cpuid) | (1 << real_irq)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | spin_unlock_irqrestore(&sun4d_imsk_lock, flags); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 200 | #else | 
|  | 201 | cc_set_imsk(cc_get_imsk() | (1 << real_irq)); | 
|  | 202 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } | 
|  | 204 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 205 | static void sun4d_unmask_irq(struct irq_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 207 | struct sun4d_handler_data *handler_data = data->handler_data; | 
|  | 208 | unsigned int real_irq; | 
|  | 209 | #ifdef CONFIG_SMP | 
|  | 210 | int cpuid = handler_data->cpuid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | unsigned long flags; | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 212 | #endif | 
|  | 213 | real_irq = handler_data->real_irq; | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 214 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 215 | #ifdef CONFIG_SMP | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | spin_lock_irqsave(&sun4d_imsk_lock, flags); | 
| oftedal | ea16058 | 2011-06-01 11:04:20 +0000 | [diff] [blame] | 217 | cc_set_imsk_other(cpuid, cc_get_imsk_other(cpuid) & ~(1 << real_irq)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | spin_unlock_irqrestore(&sun4d_imsk_lock, flags); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 219 | #else | 
| oftedal | ea16058 | 2011-06-01 11:04:20 +0000 | [diff] [blame] | 220 | cc_set_imsk(cc_get_imsk() & ~(1 << real_irq)); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 221 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } | 
|  | 223 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 224 | static unsigned int sun4d_startup_irq(struct irq_data *data) | 
|  | 225 | { | 
|  | 226 | irq_link(data->irq); | 
|  | 227 | sun4d_unmask_irq(data); | 
|  | 228 | return 0; | 
|  | 229 | } | 
|  | 230 |  | 
|  | 231 | static void sun4d_shutdown_irq(struct irq_data *data) | 
|  | 232 | { | 
|  | 233 | sun4d_mask_irq(data); | 
|  | 234 | irq_unlink(data->irq); | 
|  | 235 | } | 
|  | 236 |  | 
|  | 237 | struct irq_chip sun4d_irq = { | 
|  | 238 | .name		= "sun4d", | 
|  | 239 | .irq_startup	= sun4d_startup_irq, | 
|  | 240 | .irq_shutdown	= sun4d_shutdown_irq, | 
|  | 241 | .irq_unmask	= sun4d_unmask_irq, | 
|  | 242 | .irq_mask	= sun4d_mask_irq, | 
|  | 243 | }; | 
|  | 244 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | #ifdef CONFIG_SMP | 
|  | 246 | static void sun4d_set_cpu_int(int cpu, int level) | 
|  | 247 | { | 
|  | 248 | sun4d_send_ipi(cpu, level); | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | static void sun4d_clear_ipi(int cpu, int level) | 
|  | 252 | { | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | static void sun4d_set_udt(int cpu) | 
|  | 256 | { | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | /* Setup IRQ distribution scheme. */ | 
|  | 260 | void __init sun4d_distribute_irqs(void) | 
|  | 261 | { | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 262 | struct device_node *dp; | 
|  | 263 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | int cpuid = cpu_logical_map(1); | 
|  | 265 |  | 
|  | 266 | if (cpuid == -1) | 
|  | 267 | cpuid = cpu_logical_map(0); | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 268 | for_each_node_by_name(dp, "sbi") { | 
|  | 269 | int devid = of_getintprop_default(dp, "device-id", 0); | 
|  | 270 | int board = of_getintprop_default(dp, "board#", 0); | 
| Sam Ravnborg | db1cdd1 | 2011-04-18 11:25:42 +0000 | [diff] [blame] | 271 | board_to_cpu[board] = cpuid; | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 272 | set_sbi_tid(devid, cpuid << 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 274 | printk(KERN_ERR "All sbus IRQs directed to CPU%d\n", cpuid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } | 
|  | 276 | #endif | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 277 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | static void sun4d_clear_clock_irq(void) | 
|  | 279 | { | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 280 | sbus_readl(&sun4d_timers->l10_timer_limit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } | 
|  | 282 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | static void sun4d_load_profile_irq(int cpu, unsigned int limit) | 
|  | 284 | { | 
|  | 285 | bw_set_prof_limit(cpu, limit); | 
|  | 286 | } | 
|  | 287 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 288 | static void __init sun4d_load_profile_irqs(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 290 | int cpu = 0, mid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | while (!cpu_find_by_instance(cpu, NULL, &mid)) { | 
|  | 293 | sun4d_load_profile_irq(mid >> 3, 0); | 
|  | 294 | cpu++; | 
|  | 295 | } | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 296 | } | 
|  | 297 |  | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 298 | unsigned int _sun4d_build_device_irq(unsigned int real_irq, | 
|  | 299 | unsigned int pil, | 
|  | 300 | unsigned int board) | 
|  | 301 | { | 
|  | 302 | struct sun4d_handler_data *handler_data; | 
|  | 303 | unsigned int irq; | 
|  | 304 |  | 
|  | 305 | irq = irq_alloc(real_irq, pil); | 
|  | 306 | if (irq == 0) { | 
|  | 307 | prom_printf("IRQ: allocate for %d %d %d failed\n", | 
|  | 308 | real_irq, pil, board); | 
|  | 309 | goto err_out; | 
|  | 310 | } | 
|  | 311 |  | 
|  | 312 | handler_data = irq_get_handler_data(irq); | 
|  | 313 | if (unlikely(handler_data)) | 
|  | 314 | goto err_out; | 
|  | 315 |  | 
|  | 316 | handler_data = kzalloc(sizeof(struct sun4d_handler_data), GFP_ATOMIC); | 
|  | 317 | if (unlikely(!handler_data)) { | 
|  | 318 | prom_printf("IRQ: kzalloc(sun4d_handler_data) failed.\n"); | 
|  | 319 | prom_halt(); | 
|  | 320 | } | 
|  | 321 | handler_data->cpuid    = board_to_cpu[board]; | 
|  | 322 | handler_data->real_irq = real_irq; | 
|  | 323 | irq_set_chip_and_handler_name(irq, &sun4d_irq, | 
|  | 324 | handle_level_irq, "level"); | 
|  | 325 | irq_set_handler_data(irq, handler_data); | 
|  | 326 |  | 
|  | 327 | err_out: | 
|  | 328 | return irq; | 
|  | 329 | } | 
|  | 330 |  | 
|  | 331 |  | 
|  | 332 |  | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 333 | unsigned int sun4d_build_device_irq(struct platform_device *op, | 
|  | 334 | unsigned int real_irq) | 
|  | 335 | { | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 336 | struct device_node *dp = op->dev.of_node; | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 337 | struct device_node *board_parent, *bus = dp->parent; | 
|  | 338 | char *bus_connection; | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 339 | const struct linux_prom_registers *regs; | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 340 | unsigned int pil; | 
|  | 341 | unsigned int irq; | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 342 | int board, slot; | 
|  | 343 | int sbusl; | 
|  | 344 |  | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 345 | irq = real_irq; | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 346 | while (bus) { | 
|  | 347 | if (!strcmp(bus->name, "sbi")) { | 
|  | 348 | bus_connection = "io-unit"; | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 349 | break; | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 350 | } | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 351 |  | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 352 | if (!strcmp(bus->name, "bootbus")) { | 
|  | 353 | bus_connection = "cpu-unit"; | 
|  | 354 | break; | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | bus = bus->parent; | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 358 | } | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 359 | if (!bus) | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 360 | goto err_out; | 
|  | 361 |  | 
|  | 362 | regs = of_get_property(dp, "reg", NULL); | 
|  | 363 | if (!regs) | 
|  | 364 | goto err_out; | 
|  | 365 |  | 
|  | 366 | slot = regs->which_io; | 
|  | 367 |  | 
|  | 368 | /* | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 369 | * If Bus nodes parent is not io-unit/cpu-unit or the io-unit/cpu-unit | 
|  | 370 | * lacks a "board#" property, something is very wrong. | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 371 | */ | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 372 | if (!bus->parent || strcmp(bus->parent->name, bus_connection)) { | 
|  | 373 | printk(KERN_ERR "%s: Error, parent is not %s.\n", | 
|  | 374 | bus->full_name, bus_connection); | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 375 | goto err_out; | 
|  | 376 | } | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 377 | board_parent = bus->parent; | 
|  | 378 | board = of_getintprop_default(board_parent, "board#", -1); | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 379 | if (board == -1) { | 
| oftedal | 9eeb089 | 2011-06-01 11:11:41 +0000 | [diff] [blame] | 380 | printk(KERN_ERR "%s: Error, lacks board# property.\n", | 
|  | 381 | board_parent->full_name); | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 382 | goto err_out; | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | sbusl = pil_to_sbus[real_irq]; | 
|  | 386 | if (sbusl) | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 387 | pil = sun4d_encode_irq(board, sbusl, slot); | 
|  | 388 | else | 
|  | 389 | pil = real_irq; | 
|  | 390 |  | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 391 | irq = _sun4d_build_device_irq(real_irq, pil, board); | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 392 | err_out: | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 393 | return irq; | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 394 | } | 
|  | 395 |  | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 396 | unsigned int sun4d_build_timer_irq(unsigned int board, unsigned int real_irq) | 
|  | 397 | { | 
|  | 398 | return _sun4d_build_device_irq(real_irq, real_irq, board); | 
|  | 399 | } | 
|  | 400 |  | 
|  | 401 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 402 | static void __init sun4d_fixup_trap_table(void) | 
|  | 403 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | #ifdef CONFIG_SMP | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 405 | unsigned long flags; | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 406 | struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 408 | /* Adjust so that we jump directly to smp4d_ticker */ | 
|  | 409 | lvl14_save[2] += smp4d_ticker - real_irq_entry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 411 | /* For SMP we use the level 14 ticker, however the bootup code | 
|  | 412 | * has copied the firmware's level 14 vector into the boot cpu's | 
|  | 413 | * trap table, we must fix this now or we get squashed. | 
|  | 414 | */ | 
|  | 415 | local_irq_save(flags); | 
|  | 416 | patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */ | 
|  | 417 | trap_table->inst_one = lvl14_save[0]; | 
|  | 418 | trap_table->inst_two = lvl14_save[1]; | 
|  | 419 | trap_table->inst_three = lvl14_save[2]; | 
|  | 420 | trap_table->inst_four = lvl14_save[3]; | 
|  | 421 | local_flush_cache_all(); | 
|  | 422 | local_irq_restore(flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | #endif | 
|  | 424 | } | 
|  | 425 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 426 | static void __init sun4d_init_timers(irq_handler_t counter_fn) | 
|  | 427 | { | 
|  | 428 | struct device_node *dp; | 
|  | 429 | struct resource res; | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 430 | unsigned int irq; | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 431 | const u32 *reg; | 
|  | 432 | int err; | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 433 | int board; | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 434 |  | 
|  | 435 | dp = of_find_node_by_name(NULL, "cpu-unit"); | 
|  | 436 | if (!dp) { | 
|  | 437 | prom_printf("sun4d_init_timers: Unable to find cpu-unit\n"); | 
|  | 438 | prom_halt(); | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 | /* Which cpu-unit we use is arbitrary, we can view the bootbus timer | 
|  | 442 | * registers via any cpu's mapping.  The first 'reg' property is the | 
|  | 443 | * bootbus. | 
|  | 444 | */ | 
|  | 445 | reg = of_get_property(dp, "reg", NULL); | 
|  | 446 | if (!reg) { | 
|  | 447 | prom_printf("sun4d_init_timers: No reg property\n"); | 
|  | 448 | prom_halt(); | 
|  | 449 | } | 
|  | 450 |  | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 451 | board = of_getintprop_default(dp, "board#", -1); | 
|  | 452 | if (board == -1) { | 
|  | 453 | prom_printf("sun4d_init_timers: No board# property on cpu-unit\n"); | 
|  | 454 | prom_halt(); | 
|  | 455 | } | 
|  | 456 |  | 
|  | 457 | of_node_put(dp); | 
|  | 458 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 459 | res.start = reg[1]; | 
|  | 460 | res.end = reg[2] - 1; | 
|  | 461 | res.flags = reg[0] & 0xff; | 
|  | 462 | sun4d_timers = of_ioremap(&res, BW_TIMER_LIMIT, | 
|  | 463 | sizeof(struct sun4d_timer_regs), "user timer"); | 
|  | 464 | if (!sun4d_timers) { | 
|  | 465 | prom_printf("sun4d_init_timers: Can't map timer regs\n"); | 
|  | 466 | prom_halt(); | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | sbus_writel((((1000000/HZ) + 1) << 10), &sun4d_timers->l10_timer_limit); | 
|  | 470 |  | 
|  | 471 | master_l10_counter = &sun4d_timers->l10_cur_count; | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 472 |  | 
| oftedal | 5fba170 | 2011-06-01 10:43:50 +0000 | [diff] [blame] | 473 | irq = sun4d_build_timer_irq(board, SUN4D_TIMER_IRQ); | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 474 | err = request_irq(irq, counter_fn, IRQF_TIMER, "timer", NULL); | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 475 | if (err) { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 476 | prom_printf("sun4d_init_timers: request_irq() failed with %d\n", | 
|  | 477 | err); | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 478 | prom_halt(); | 
|  | 479 | } | 
|  | 480 | sun4d_load_profile_irqs(); | 
|  | 481 | sun4d_fixup_trap_table(); | 
|  | 482 | } | 
|  | 483 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | void __init sun4d_init_sbi_irq(void) | 
|  | 485 | { | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 486 | struct device_node *dp; | 
| Daniel Hellstrom | 5fcafb7 | 2011-04-21 04:20:23 +0000 | [diff] [blame] | 487 | int target_cpu; | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 488 |  | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 489 | target_cpu = boot_cpu_id; | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 490 | for_each_node_by_name(dp, "sbi") { | 
|  | 491 | int devid = of_getintprop_default(dp, "device-id", 0); | 
|  | 492 | int board = of_getintprop_default(dp, "board#", 0); | 
|  | 493 | unsigned int mask; | 
|  | 494 |  | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 495 | set_sbi_tid(devid, target_cpu << 3); | 
| Sam Ravnborg | db1cdd1 | 2011-04-18 11:25:42 +0000 | [diff] [blame] | 496 | board_to_cpu[board] = target_cpu; | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 497 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* Get rid of pending irqs from PROM */ | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 499 | mask = acquire_sbi(devid, 0xffffffff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (mask) { | 
| Sam Ravnborg | e54f854 | 2011-01-28 22:08:21 +0000 | [diff] [blame] | 501 | printk(KERN_ERR "Clearing pending IRQs %08x on SBI %d\n", | 
|  | 502 | mask, board); | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 503 | release_sbi(devid, mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } | 
|  | 505 | } | 
|  | 506 | } | 
|  | 507 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | void __init sun4d_init_IRQ(void) | 
|  | 509 | { | 
|  | 510 | local_irq_disable(); | 
|  | 511 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | BTFIXUPSET_CALL(clear_clock_irq, sun4d_clear_clock_irq, BTFIXUPCALL_NORM); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | BTFIXUPSET_CALL(load_profile_irq, sun4d_load_profile_irq, BTFIXUPCALL_NORM); | 
| Sam Ravnborg | bbdc266 | 2011-02-25 23:00:19 -0800 | [diff] [blame] | 514 |  | 
| Sam Ravnborg | 6baa9b2 | 2011-04-18 11:25:44 +0000 | [diff] [blame] | 515 | sparc_irq_config.init_timers      = sun4d_init_timers; | 
| Sam Ravnborg | 1d05995 | 2011-02-25 23:01:19 -0800 | [diff] [blame] | 516 | sparc_irq_config.build_device_irq = sun4d_build_device_irq; | 
| Sam Ravnborg | bbdc266 | 2011-02-25 23:00:19 -0800 | [diff] [blame] | 517 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | #ifdef CONFIG_SMP | 
|  | 519 | BTFIXUPSET_CALL(set_cpu_int, sun4d_set_cpu_int, BTFIXUPCALL_NORM); | 
|  | 520 | BTFIXUPSET_CALL(clear_cpu_int, sun4d_clear_ipi, BTFIXUPCALL_NOP); | 
|  | 521 | BTFIXUPSET_CALL(set_irq_udt, sun4d_set_udt, BTFIXUPCALL_NOP); | 
|  | 522 | #endif | 
|  | 523 | /* Cannot enable interrupts until OBP ticker is disabled. */ | 
|  | 524 | } |