| Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | *  arch/sparc/kernel/sun4d_irq.c: | 
|  | 3 | *			SS1000/SC2000 interrupt handling. | 
|  | 4 | * | 
|  | 5 | *  Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | 
|  | 6 | *  Heavily based on arch/sparc/kernel/irq.c. | 
|  | 7 | */ | 
|  | 8 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/errno.h> | 
|  | 10 | #include <linux/linkage.h> | 
|  | 11 | #include <linux/kernel_stat.h> | 
|  | 12 | #include <linux/signal.h> | 
|  | 13 | #include <linux/sched.h> | 
|  | 14 | #include <linux/ptrace.h> | 
|  | 15 | #include <linux/interrupt.h> | 
|  | 16 | #include <linux/slab.h> | 
|  | 17 | #include <linux/random.h> | 
|  | 18 | #include <linux/init.h> | 
|  | 19 | #include <linux/smp.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/spinlock.h> | 
|  | 21 | #include <linux/seq_file.h> | 
| David S. Miller | 454eeb2 | 2008-08-27 04:05:35 -0700 | [diff] [blame] | 22 | #include <linux/of.h> | 
|  | 23 | #include <linux/of_device.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | #include <asm/ptrace.h> | 
|  | 26 | #include <asm/processor.h> | 
|  | 27 | #include <asm/system.h> | 
|  | 28 | #include <asm/psr.h> | 
|  | 29 | #include <asm/smp.h> | 
|  | 30 | #include <asm/vaddrs.h> | 
|  | 31 | #include <asm/timer.h> | 
|  | 32 | #include <asm/openprom.h> | 
|  | 33 | #include <asm/oplib.h> | 
|  | 34 | #include <asm/traps.h> | 
|  | 35 | #include <asm/irq.h> | 
|  | 36 | #include <asm/io.h> | 
|  | 37 | #include <asm/pgalloc.h> | 
|  | 38 | #include <asm/pgtable.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/sbi.h> | 
|  | 40 | #include <asm/cacheflush.h> | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 41 | #include <asm/irq_regs.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
| Sam Ravnborg | 81265fd | 2008-12-08 01:08:24 -0800 | [diff] [blame] | 43 | #include "kernel.h" | 
| Al Viro | 32231a6 | 2007-07-21 19:18:57 -0700 | [diff] [blame] | 44 | #include "irq.h" | 
|  | 45 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* If you trust current SCSI layer to handle different SCSI IRQs, enable this. I don't trust it... -jj */ | 
|  | 47 | /* #define DISTRIBUTE_IRQS */ | 
|  | 48 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 49 | struct sun4d_timer_regs { | 
|  | 50 | u32	l10_timer_limit; | 
|  | 51 | u32	l10_cur_countx; | 
|  | 52 | u32	l10_limit_noclear; | 
|  | 53 | u32	ctrl; | 
|  | 54 | u32	l10_cur_count; | 
|  | 55 | }; | 
|  | 56 |  | 
|  | 57 | static struct sun4d_timer_regs __iomem *sun4d_timers; | 
|  | 58 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define TIMER_IRQ	10 | 
|  | 60 |  | 
|  | 61 | #define MAX_STATIC_ALLOC	4 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | extern int static_irq_count; | 
| Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 63 | static unsigned char sbus_tid[32]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 |  | 
| Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 65 | static struct irqaction *irq_action[NR_IRQS]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | extern spinlock_t irq_action_lock; | 
|  | 67 |  | 
| Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 68 | static struct sbus_action { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | struct irqaction *action; | 
|  | 70 | /* For SMP this needs to be extended */ | 
|  | 71 | } *sbus_actions; | 
|  | 72 |  | 
|  | 73 | static int pil_to_sbus[] = { | 
|  | 74 | 0, 0, 1, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 0, | 
|  | 75 | }; | 
|  | 76 |  | 
|  | 77 | static int sbus_to_pil[] = { | 
|  | 78 | 0, 2, 3, 5, 7, 9, 11, 13, | 
|  | 79 | }; | 
|  | 80 |  | 
|  | 81 | static int nsbi; | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | /* Exported for sun4d_smp.c */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | DEFINE_SPINLOCK(sun4d_imsk_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 |  | 
|  | 86 | int show_sun4d_interrupts(struct seq_file *p, void *v) | 
|  | 87 | { | 
|  | 88 | int i = *(loff_t *) v, j = 0, k = 0, sbusl; | 
|  | 89 | struct irqaction * action; | 
|  | 90 | unsigned long flags; | 
|  | 91 | #ifdef CONFIG_SMP | 
|  | 92 | int x; | 
|  | 93 | #endif | 
|  | 94 |  | 
|  | 95 | spin_lock_irqsave(&irq_action_lock, flags); | 
|  | 96 | if (i < NR_IRQS) { | 
|  | 97 | sbusl = pil_to_sbus[i]; | 
|  | 98 | if (!sbusl) { | 
|  | 99 | action = *(i + irq_action); | 
|  | 100 | if (!action) | 
|  | 101 | goto out_unlock; | 
|  | 102 | } else { | 
|  | 103 | for (j = 0; j < nsbi; j++) { | 
|  | 104 | for (k = 0; k < 4; k++) | 
|  | 105 | if ((action = sbus_actions [(j << 5) + (sbusl << 2) + k].action)) | 
|  | 106 | goto found_it; | 
|  | 107 | } | 
|  | 108 | goto out_unlock; | 
|  | 109 | } | 
|  | 110 | found_it:	seq_printf(p, "%3d: ", i); | 
|  | 111 | #ifndef CONFIG_SMP | 
|  | 112 | seq_printf(p, "%10u ", kstat_irqs(i)); | 
|  | 113 | #else | 
| Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 114 | for_each_online_cpu(x) | 
|  | 115 | seq_printf(p, "%10u ", | 
|  | 116 | kstat_cpu(cpu_logical_map(x)).irqs[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #endif | 
|  | 118 | seq_printf(p, "%c %s", | 
| Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 119 | (action->flags & IRQF_DISABLED) ? '+' : ' ', | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | action->name); | 
|  | 121 | action = action->next; | 
|  | 122 | for (;;) { | 
|  | 123 | for (; action; action = action->next) { | 
|  | 124 | seq_printf(p, ",%s %s", | 
| Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 125 | (action->flags & IRQF_DISABLED) ? " +" : "", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | action->name); | 
|  | 127 | } | 
|  | 128 | if (!sbusl) break; | 
|  | 129 | k++; | 
|  | 130 | if (k < 4) | 
|  | 131 | action = sbus_actions [(j << 5) + (sbusl << 2) + k].action; | 
|  | 132 | else { | 
|  | 133 | j++; | 
|  | 134 | if (j == nsbi) break; | 
|  | 135 | k = 0; | 
|  | 136 | action = sbus_actions [(j << 5) + (sbusl << 2)].action; | 
|  | 137 | } | 
|  | 138 | } | 
|  | 139 | seq_putc(p, '\n'); | 
|  | 140 | } | 
|  | 141 | out_unlock: | 
|  | 142 | spin_unlock_irqrestore(&irq_action_lock, flags); | 
|  | 143 | return 0; | 
|  | 144 | } | 
|  | 145 |  | 
|  | 146 | void sun4d_free_irq(unsigned int irq, void *dev_id) | 
|  | 147 | { | 
|  | 148 | struct irqaction *action, **actionp; | 
|  | 149 | struct irqaction *tmp = NULL; | 
|  | 150 | unsigned long flags; | 
|  | 151 |  | 
|  | 152 | spin_lock_irqsave(&irq_action_lock, flags); | 
|  | 153 | if (irq < 15) | 
|  | 154 | actionp = irq + irq_action; | 
|  | 155 | else | 
|  | 156 | actionp = &(sbus_actions[irq - (1 << 5)].action); | 
|  | 157 | action = *actionp; | 
|  | 158 | if (!action) { | 
|  | 159 | printk("Trying to free free IRQ%d\n",irq); | 
|  | 160 | goto out_unlock; | 
|  | 161 | } | 
|  | 162 | if (dev_id) { | 
|  | 163 | for (; action; action = action->next) { | 
|  | 164 | if (action->dev_id == dev_id) | 
|  | 165 | break; | 
|  | 166 | tmp = action; | 
|  | 167 | } | 
|  | 168 | if (!action) { | 
|  | 169 | printk("Trying to free free shared IRQ%d\n",irq); | 
|  | 170 | goto out_unlock; | 
|  | 171 | } | 
| Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 172 | } else if (action->flags & IRQF_SHARED) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | printk("Trying to free shared IRQ%d with NULL device ID\n", irq); | 
|  | 174 | goto out_unlock; | 
|  | 175 | } | 
|  | 176 | if (action->flags & SA_STATIC_ALLOC) | 
|  | 177 | { | 
|  | 178 | /* This interrupt is marked as specially allocated | 
|  | 179 | * so it is a bad idea to free it. | 
|  | 180 | */ | 
|  | 181 | printk("Attempt to free statically allocated IRQ%d (%s)\n", | 
|  | 182 | irq, action->name); | 
|  | 183 | goto out_unlock; | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | if (action && tmp) | 
|  | 187 | tmp->next = action->next; | 
|  | 188 | else | 
|  | 189 | *actionp = action->next; | 
|  | 190 |  | 
|  | 191 | spin_unlock_irqrestore(&irq_action_lock, flags); | 
|  | 192 |  | 
|  | 193 | synchronize_irq(irq); | 
|  | 194 |  | 
|  | 195 | spin_lock_irqsave(&irq_action_lock, flags); | 
|  | 196 |  | 
|  | 197 | kfree(action); | 
|  | 198 |  | 
|  | 199 | if (!(*actionp)) | 
| Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 200 | __disable_irq(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 |  | 
|  | 202 | out_unlock: | 
|  | 203 | spin_unlock_irqrestore(&irq_action_lock, flags); | 
|  | 204 | } | 
|  | 205 |  | 
|  | 206 | extern void unexpected_irq(int, void *, struct pt_regs *); | 
|  | 207 |  | 
|  | 208 | void sun4d_handler_irq(int irq, struct pt_regs * regs) | 
|  | 209 | { | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 210 | struct pt_regs *old_regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | struct irqaction * action; | 
|  | 212 | int cpu = smp_processor_id(); | 
|  | 213 | /* SBUS IRQ level (1 - 7) */ | 
|  | 214 | int sbusl = pil_to_sbus[irq]; | 
|  | 215 |  | 
|  | 216 | /* FIXME: Is this necessary?? */ | 
|  | 217 | cc_get_ipen(); | 
|  | 218 |  | 
|  | 219 | cc_set_iclr(1 << irq); | 
|  | 220 |  | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 221 | old_regs = set_irq_regs(regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | irq_enter(); | 
|  | 223 | kstat_cpu(cpu).irqs[irq]++; | 
|  | 224 | if (!sbusl) { | 
|  | 225 | action = *(irq + irq_action); | 
|  | 226 | if (!action) | 
|  | 227 | unexpected_irq(irq, NULL, regs); | 
|  | 228 | do { | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 229 | action->handler(irq, action->dev_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | action = action->next; | 
|  | 231 | } while (action); | 
|  | 232 | } else { | 
|  | 233 | int bus_mask = bw_get_intr_mask(sbusl) & 0x3ffff; | 
|  | 234 | int sbino; | 
|  | 235 | struct sbus_action *actionp; | 
|  | 236 | unsigned mask, slot; | 
|  | 237 | int sbil = (sbusl << 2); | 
|  | 238 |  | 
|  | 239 | bw_clear_intr_mask(sbusl, bus_mask); | 
|  | 240 |  | 
|  | 241 | /* Loop for each pending SBI */ | 
|  | 242 | for (sbino = 0; bus_mask; sbino++, bus_mask >>= 1) | 
|  | 243 | if (bus_mask & 1) { | 
|  | 244 | mask = acquire_sbi(SBI2DEVID(sbino), 0xf << sbil); | 
|  | 245 | mask &= (0xf << sbil); | 
|  | 246 | actionp = sbus_actions + (sbino << 5) + (sbil); | 
|  | 247 | /* Loop for each pending SBI slot */ | 
|  | 248 | for (slot = (1 << sbil); mask; slot <<= 1, actionp++) | 
|  | 249 | if (mask & slot) { | 
|  | 250 | mask &= ~slot; | 
|  | 251 | action = actionp->action; | 
|  | 252 |  | 
|  | 253 | if (!action) | 
|  | 254 | unexpected_irq(irq, NULL, regs); | 
|  | 255 | do { | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 256 | action->handler(irq, action->dev_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | action = action->next; | 
|  | 258 | } while (action); | 
|  | 259 | release_sbi(SBI2DEVID(sbino), slot); | 
|  | 260 | } | 
|  | 261 | } | 
|  | 262 | } | 
|  | 263 | irq_exit(); | 
| Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 264 | set_irq_regs(old_regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } | 
|  | 266 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | int sun4d_request_irq(unsigned int irq, | 
| David Howells | 40220c1 | 2006-10-09 12:19:47 +0100 | [diff] [blame] | 268 | irq_handler_t handler, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | unsigned long irqflags, const char * devname, void *dev_id) | 
|  | 270 | { | 
|  | 271 | struct irqaction *action, *tmp = NULL, **actionp; | 
|  | 272 | unsigned long flags; | 
|  | 273 | int ret; | 
|  | 274 |  | 
|  | 275 | if(irq > 14 && irq < (1 << 5)) { | 
|  | 276 | ret = -EINVAL; | 
|  | 277 | goto out; | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | if (!handler) { | 
|  | 281 | ret = -EINVAL; | 
|  | 282 | goto out; | 
|  | 283 | } | 
|  | 284 |  | 
|  | 285 | spin_lock_irqsave(&irq_action_lock, flags); | 
|  | 286 |  | 
|  | 287 | if (irq >= (1 << 5)) | 
|  | 288 | actionp = &(sbus_actions[irq - (1 << 5)].action); | 
|  | 289 | else | 
|  | 290 | actionp = irq + irq_action; | 
|  | 291 | action = *actionp; | 
|  | 292 |  | 
|  | 293 | if (action) { | 
| Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 294 | if ((action->flags & IRQF_SHARED) && (irqflags & IRQF_SHARED)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | for (tmp = action; tmp->next; tmp = tmp->next); | 
|  | 296 | } else { | 
|  | 297 | ret = -EBUSY; | 
|  | 298 | goto out_unlock; | 
|  | 299 | } | 
| Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 300 | if ((action->flags & IRQF_DISABLED) ^ (irqflags & IRQF_DISABLED)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq); | 
|  | 302 | ret = -EBUSY; | 
|  | 303 | goto out_unlock; | 
|  | 304 | } | 
|  | 305 | action = NULL;		/* Or else! */ | 
|  | 306 | } | 
|  | 307 |  | 
|  | 308 | /* If this is flagged as statically allocated then we use our | 
|  | 309 | * private struct which is never freed. | 
|  | 310 | */ | 
|  | 311 | if (irqflags & SA_STATIC_ALLOC) { | 
|  | 312 | if (static_irq_count < MAX_STATIC_ALLOC) | 
|  | 313 | action = &static_irqaction[static_irq_count++]; | 
|  | 314 | else | 
|  | 315 | printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname); | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | if (action == NULL) | 
| Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 319 | action = kmalloc(sizeof(struct irqaction), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | GFP_ATOMIC); | 
|  | 321 |  | 
|  | 322 | if (!action) { | 
|  | 323 | ret = -ENOMEM; | 
|  | 324 | goto out_unlock; | 
|  | 325 | } | 
|  | 326 |  | 
|  | 327 | action->handler = handler; | 
|  | 328 | action->flags = irqflags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | action->name = devname; | 
|  | 330 | action->next = NULL; | 
|  | 331 | action->dev_id = dev_id; | 
|  | 332 |  | 
|  | 333 | if (tmp) | 
|  | 334 | tmp->next = action; | 
|  | 335 | else | 
|  | 336 | *actionp = action; | 
|  | 337 |  | 
| Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 338 | __enable_irq(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 |  | 
|  | 340 | ret = 0; | 
|  | 341 | out_unlock: | 
|  | 342 | spin_unlock_irqrestore(&irq_action_lock, flags); | 
|  | 343 | out: | 
|  | 344 | return ret; | 
|  | 345 | } | 
|  | 346 |  | 
|  | 347 | static void sun4d_disable_irq(unsigned int irq) | 
|  | 348 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | int tid = sbus_tid[(irq >> 5) - 1]; | 
|  | 350 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 |  | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 352 | if (irq < NR_IRQS) | 
|  | 353 | return; | 
|  | 354 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | spin_lock_irqsave(&sun4d_imsk_lock, flags); | 
|  | 356 | cc_set_imsk_other(tid, cc_get_imsk_other(tid) | (1 << sbus_to_pil[(irq >> 2) & 7])); | 
|  | 357 | spin_unlock_irqrestore(&sun4d_imsk_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } | 
|  | 359 |  | 
|  | 360 | static void sun4d_enable_irq(unsigned int irq) | 
|  | 361 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | int tid = sbus_tid[(irq >> 5) - 1]; | 
|  | 363 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 |  | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 365 | if (irq < NR_IRQS) | 
|  | 366 | return; | 
|  | 367 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | spin_lock_irqsave(&sun4d_imsk_lock, flags); | 
|  | 369 | cc_set_imsk_other(tid, cc_get_imsk_other(tid) & ~(1 << sbus_to_pil[(irq >> 2) & 7])); | 
|  | 370 | spin_unlock_irqrestore(&sun4d_imsk_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } | 
|  | 372 |  | 
|  | 373 | #ifdef CONFIG_SMP | 
|  | 374 | static void sun4d_set_cpu_int(int cpu, int level) | 
|  | 375 | { | 
|  | 376 | sun4d_send_ipi(cpu, level); | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | static void sun4d_clear_ipi(int cpu, int level) | 
|  | 380 | { | 
|  | 381 | } | 
|  | 382 |  | 
|  | 383 | static void sun4d_set_udt(int cpu) | 
|  | 384 | { | 
|  | 385 | } | 
|  | 386 |  | 
|  | 387 | /* Setup IRQ distribution scheme. */ | 
|  | 388 | void __init sun4d_distribute_irqs(void) | 
|  | 389 | { | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 390 | struct device_node *dp; | 
|  | 391 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | #ifdef DISTRIBUTE_IRQS | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 393 | cpumask_t sbus_serving_map; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 |  | 
|  | 395 | sbus_serving_map = cpu_present_map; | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 396 | for_each_node_by_name(dp, "sbi") { | 
|  | 397 | int board = of_getintprop_default(dp, "board#", 0); | 
|  | 398 |  | 
|  | 399 | if ((board * 2) == boot_cpu_id && cpu_isset(board * 2 + 1, cpu_present_map)) | 
|  | 400 | sbus_tid[board] = (board * 2 + 1); | 
|  | 401 | else if (cpu_isset(board * 2, cpu_present_map)) | 
|  | 402 | sbus_tid[board] = (board * 2); | 
|  | 403 | else if (cpu_isset(board * 2 + 1, cpu_present_map)) | 
|  | 404 | sbus_tid[board] = (board * 2 + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | else | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 406 | sbus_tid[board] = 0xff; | 
|  | 407 | if (sbus_tid[board] != 0xff) | 
|  | 408 | cpu_clear(sbus_tid[board], sbus_serving_map); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 410 | for_each_node_by_name(dp, "sbi") { | 
|  | 411 | int board = of_getintprop_default(dp, "board#", 0); | 
|  | 412 | if (sbus_tid[board] == 0xff) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | int i = 31; | 
|  | 414 |  | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 415 | if (cpus_empty(sbus_serving_map)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | sbus_serving_map = cpu_present_map; | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 417 | while (cpu_isset(i, sbus_serving_map)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | i--; | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 419 | sbus_tid[board] = i; | 
|  | 420 | cpu_clear(i, sbus_serving_map); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 422 | } | 
|  | 423 | for_each_node_by_name(dp, "sbi") { | 
|  | 424 | int devid = of_getintprop_default(dp, "device-id", 0); | 
|  | 425 | int board = of_getintprop_default(dp, "board#", 0); | 
|  | 426 | printk("sbus%d IRQs directed to CPU%d\n", board, sbus_tid[board]); | 
|  | 427 | set_sbi_tid(devid, sbus_tid[board] << 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } | 
|  | 429 | #else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | int cpuid = cpu_logical_map(1); | 
|  | 431 |  | 
|  | 432 | if (cpuid == -1) | 
|  | 433 | cpuid = cpu_logical_map(0); | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 434 | for_each_node_by_name(dp, "sbi") { | 
|  | 435 | int devid = of_getintprop_default(dp, "device-id", 0); | 
|  | 436 | int board = of_getintprop_default(dp, "board#", 0); | 
|  | 437 | sbus_tid[board] = cpuid; | 
|  | 438 | set_sbi_tid(devid, cpuid << 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } | 
|  | 440 | printk("All sbus IRQs directed to CPU%d\n", cpuid); | 
|  | 441 | #endif | 
|  | 442 | } | 
|  | 443 | #endif | 
|  | 444 |  | 
|  | 445 | static void sun4d_clear_clock_irq(void) | 
|  | 446 | { | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 447 | sbus_readl(&sun4d_timers->l10_timer_limit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } | 
|  | 449 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | static void sun4d_load_profile_irq(int cpu, unsigned int limit) | 
|  | 451 | { | 
|  | 452 | bw_set_prof_limit(cpu, limit); | 
|  | 453 | } | 
|  | 454 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 455 | static void __init sun4d_load_profile_irqs(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 457 | int cpu = 0, mid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | while (!cpu_find_by_instance(cpu, NULL, &mid)) { | 
|  | 460 | sun4d_load_profile_irq(mid >> 3, 0); | 
|  | 461 | cpu++; | 
|  | 462 | } | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 463 | } | 
|  | 464 |  | 
|  | 465 | static void __init sun4d_fixup_trap_table(void) | 
|  | 466 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | #ifdef CONFIG_SMP | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 468 | unsigned long flags; | 
|  | 469 | extern unsigned long lvl14_save[4]; | 
|  | 470 | struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)]; | 
|  | 471 | extern unsigned int real_irq_entry[], smp4d_ticker[]; | 
|  | 472 | extern unsigned int patchme_maybe_smp_msg[]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 474 | /* Adjust so that we jump directly to smp4d_ticker */ | 
|  | 475 | lvl14_save[2] += smp4d_ticker - real_irq_entry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 477 | /* For SMP we use the level 14 ticker, however the bootup code | 
|  | 478 | * has copied the firmware's level 14 vector into the boot cpu's | 
|  | 479 | * trap table, we must fix this now or we get squashed. | 
|  | 480 | */ | 
|  | 481 | local_irq_save(flags); | 
|  | 482 | patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */ | 
|  | 483 | trap_table->inst_one = lvl14_save[0]; | 
|  | 484 | trap_table->inst_two = lvl14_save[1]; | 
|  | 485 | trap_table->inst_three = lvl14_save[2]; | 
|  | 486 | trap_table->inst_four = lvl14_save[3]; | 
|  | 487 | local_flush_cache_all(); | 
|  | 488 | local_irq_restore(flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | #endif | 
|  | 490 | } | 
|  | 491 |  | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 492 | static void __init sun4d_init_timers(irq_handler_t counter_fn) | 
|  | 493 | { | 
|  | 494 | struct device_node *dp; | 
|  | 495 | struct resource res; | 
|  | 496 | const u32 *reg; | 
|  | 497 | int err; | 
|  | 498 |  | 
|  | 499 | dp = of_find_node_by_name(NULL, "cpu-unit"); | 
|  | 500 | if (!dp) { | 
|  | 501 | prom_printf("sun4d_init_timers: Unable to find cpu-unit\n"); | 
|  | 502 | prom_halt(); | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | /* Which cpu-unit we use is arbitrary, we can view the bootbus timer | 
|  | 506 | * registers via any cpu's mapping.  The first 'reg' property is the | 
|  | 507 | * bootbus. | 
|  | 508 | */ | 
|  | 509 | reg = of_get_property(dp, "reg", NULL); | 
| Nicolas Palix | c2e27c3 | 2008-12-03 21:10:57 -0800 | [diff] [blame] | 510 | of_node_put(dp); | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 511 | if (!reg) { | 
|  | 512 | prom_printf("sun4d_init_timers: No reg property\n"); | 
|  | 513 | prom_halt(); | 
|  | 514 | } | 
|  | 515 |  | 
|  | 516 | res.start = reg[1]; | 
|  | 517 | res.end = reg[2] - 1; | 
|  | 518 | res.flags = reg[0] & 0xff; | 
|  | 519 | sun4d_timers = of_ioremap(&res, BW_TIMER_LIMIT, | 
|  | 520 | sizeof(struct sun4d_timer_regs), "user timer"); | 
|  | 521 | if (!sun4d_timers) { | 
|  | 522 | prom_printf("sun4d_init_timers: Can't map timer regs\n"); | 
|  | 523 | prom_halt(); | 
|  | 524 | } | 
|  | 525 |  | 
|  | 526 | sbus_writel((((1000000/HZ) + 1) << 10), &sun4d_timers->l10_timer_limit); | 
|  | 527 |  | 
|  | 528 | master_l10_counter = &sun4d_timers->l10_cur_count; | 
| David S. Miller | f5f1085 | 2008-09-13 22:04:55 -0700 | [diff] [blame] | 529 |  | 
|  | 530 | err = request_irq(TIMER_IRQ, counter_fn, | 
|  | 531 | (IRQF_DISABLED | SA_STATIC_ALLOC), | 
|  | 532 | "timer", NULL); | 
|  | 533 | if (err) { | 
|  | 534 | prom_printf("sun4d_init_timers: request_irq() failed with %d\n", err); | 
|  | 535 | prom_halt(); | 
|  | 536 | } | 
|  | 537 | sun4d_load_profile_irqs(); | 
|  | 538 | sun4d_fixup_trap_table(); | 
|  | 539 | } | 
|  | 540 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | void __init sun4d_init_sbi_irq(void) | 
|  | 542 | { | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 543 | struct device_node *dp; | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 544 | int target_cpu = 0; | 
|  | 545 |  | 
|  | 546 | #ifdef CONFIG_SMP | 
|  | 547 | target_cpu = boot_cpu_id; | 
|  | 548 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 |  | 
|  | 550 | nsbi = 0; | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 551 | for_each_node_by_name(dp, "sbi") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | nsbi++; | 
| Yan Burman | c80892d | 2006-11-30 17:07:04 -0800 | [diff] [blame] | 553 | sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC); | 
| David S. Miller | d4accd6 | 2006-11-30 17:11:26 -0800 | [diff] [blame] | 554 | if (!sbus_actions) { | 
|  | 555 | prom_printf("SUN4D: Cannot allocate sbus_actions, halting.\n"); | 
|  | 556 | prom_halt(); | 
|  | 557 | } | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 558 | for_each_node_by_name(dp, "sbi") { | 
|  | 559 | int devid = of_getintprop_default(dp, "device-id", 0); | 
|  | 560 | int board = of_getintprop_default(dp, "board#", 0); | 
|  | 561 | unsigned int mask; | 
|  | 562 |  | 
| David S. Miller | f8376e9 | 2008-09-13 22:05:25 -0700 | [diff] [blame] | 563 | set_sbi_tid(devid, target_cpu << 3); | 
|  | 564 | sbus_tid[board] = target_cpu; | 
|  | 565 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* Get rid of pending irqs from PROM */ | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 567 | mask = acquire_sbi(devid, 0xffffffff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | if (mask) { | 
| David S. Miller | 71d3721 | 2008-08-27 02:50:57 -0700 | [diff] [blame] | 569 | printk ("Clearing pending IRQs %08x on SBI %d\n", mask, board); | 
|  | 570 | release_sbi(devid, mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } | 
|  | 572 | } | 
|  | 573 | } | 
|  | 574 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | void __init sun4d_init_IRQ(void) | 
|  | 576 | { | 
|  | 577 | local_irq_disable(); | 
|  | 578 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | BTFIXUPSET_CALL(enable_irq, sun4d_enable_irq, BTFIXUPCALL_NORM); | 
|  | 580 | BTFIXUPSET_CALL(disable_irq, sun4d_disable_irq, BTFIXUPCALL_NORM); | 
|  | 581 | BTFIXUPSET_CALL(clear_clock_irq, sun4d_clear_clock_irq, BTFIXUPCALL_NORM); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | BTFIXUPSET_CALL(load_profile_irq, sun4d_load_profile_irq, BTFIXUPCALL_NORM); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | sparc_init_timers = sun4d_init_timers; | 
|  | 584 | #ifdef CONFIG_SMP | 
|  | 585 | BTFIXUPSET_CALL(set_cpu_int, sun4d_set_cpu_int, BTFIXUPCALL_NORM); | 
|  | 586 | BTFIXUPSET_CALL(clear_cpu_int, sun4d_clear_ipi, BTFIXUPCALL_NOP); | 
|  | 587 | BTFIXUPSET_CALL(set_irq_udt, sun4d_set_udt, BTFIXUPCALL_NOP); | 
|  | 588 | #endif | 
|  | 589 | /* Cannot enable interrupts until OBP ticker is disabled. */ | 
|  | 590 | } |