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