Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: irq.c,v 1.114 2002/01/11 08:45:38 davem Exp $ |
| 2 | * irq.c: UltraSparc IRQ handling/init/registry. |
| 3 | * |
| 4 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) |
| 5 | * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) |
| 6 | * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz) |
| 7 | */ |
| 8 | |
| 9 | #include <linux/config.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/ptrace.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel_stat.h> |
| 15 | #include <linux/signal.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/random.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/proc_fs.h> |
| 23 | #include <linux/seq_file.h> |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 24 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include <asm/ptrace.h> |
| 27 | #include <asm/processor.h> |
| 28 | #include <asm/atomic.h> |
| 29 | #include <asm/system.h> |
| 30 | #include <asm/irq.h> |
Sven Hartge | 2e457ef | 2005-10-08 21:12:04 -0700 | [diff] [blame] | 31 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/sbus.h> |
| 33 | #include <asm/iommu.h> |
| 34 | #include <asm/upa.h> |
| 35 | #include <asm/oplib.h> |
| 36 | #include <asm/timer.h> |
| 37 | #include <asm/smp.h> |
| 38 | #include <asm/starfire.h> |
| 39 | #include <asm/uaccess.h> |
| 40 | #include <asm/cache.h> |
| 41 | #include <asm/cpudata.h> |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 42 | #include <asm/auxio.h> |
David S. Miller | 92704a1 | 2006-02-26 23:27:19 -0800 | [diff] [blame] | 43 | #include <asm/head.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #ifdef CONFIG_SMP |
| 46 | static void distribute_irqs(void); |
| 47 | #endif |
| 48 | |
| 49 | /* UPA nodes send interrupt packet to UltraSparc with first data reg |
| 50 | * value low 5 (7 on Starfire) bits holding the IRQ identifier being |
| 51 | * delivered. We must translate this into a non-vector IRQ so we can |
| 52 | * set the softint on this cpu. |
| 53 | * |
| 54 | * To make processing these packets efficient and race free we use |
| 55 | * an array of irq buckets below. The interrupt vector handler in |
| 56 | * entry.S feeds incoming packets into per-cpu pil-indexed lists. |
| 57 | * The IVEC handler does not need to act atomically, the PIL dispatch |
| 58 | * code uses CAS to get an atomic snapshot of the list and clear it |
| 59 | * at the same time. |
| 60 | */ |
| 61 | |
| 62 | struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES))); |
| 63 | |
| 64 | /* This has to be in the main kernel image, it cannot be |
| 65 | * turned into per-cpu data. The reason is that the main |
| 66 | * kernel image is locked into the TLB and this structure |
| 67 | * is accessed from the vectored interrupt trap handler. If |
| 68 | * access to this structure takes a TLB miss it could cause |
| 69 | * the 5-level sparc v9 trap stack to overflow. |
| 70 | */ |
| 71 | struct irq_work_struct { |
| 72 | unsigned int irq_worklists[16]; |
| 73 | }; |
| 74 | struct irq_work_struct __irq_work[NR_CPUS]; |
| 75 | #define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)]) |
| 76 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 77 | static struct irqaction *irq_action[NR_IRQS+1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* This only synchronizes entities which modify IRQ handler |
| 80 | * state and some selected user-level spots that want to |
| 81 | * read things in the table. IRQ handler processing orders |
| 82 | * its' accesses such that no locking is needed. |
| 83 | */ |
| 84 | static DEFINE_SPINLOCK(irq_action_lock); |
| 85 | |
| 86 | static void register_irq_proc (unsigned int irq); |
| 87 | |
| 88 | /* |
| 89 | * Upper 2b of irqaction->flags holds the ino. |
| 90 | * irqaction->mask holds the smp affinity information. |
| 91 | */ |
| 92 | #define put_ino_in_irqaction(action, irq) \ |
| 93 | action->flags &= 0xffffffffffffUL; \ |
| 94 | if (__bucket(irq) == &pil0_dummy_bucket) \ |
| 95 | action->flags |= 0xdeadUL << 48; \ |
| 96 | else \ |
| 97 | action->flags |= __irq_ino(irq) << 48; |
| 98 | #define get_ino_in_irqaction(action) (action->flags >> 48) |
| 99 | |
| 100 | #define put_smpaff_in_irqaction(action, smpaff) (action)->mask = (smpaff) |
| 101 | #define get_smpaff_in_irqaction(action) ((action)->mask) |
| 102 | |
| 103 | int show_interrupts(struct seq_file *p, void *v) |
| 104 | { |
| 105 | unsigned long flags; |
| 106 | int i = *(loff_t *) v; |
| 107 | struct irqaction *action; |
| 108 | #ifdef CONFIG_SMP |
| 109 | int j; |
| 110 | #endif |
| 111 | |
| 112 | spin_lock_irqsave(&irq_action_lock, flags); |
| 113 | if (i <= NR_IRQS) { |
| 114 | if (!(action = *(i + irq_action))) |
| 115 | goto out_unlock; |
| 116 | seq_printf(p, "%3d: ", i); |
| 117 | #ifndef CONFIG_SMP |
| 118 | seq_printf(p, "%10u ", kstat_irqs(i)); |
| 119 | #else |
| 120 | for (j = 0; j < NR_CPUS; j++) { |
| 121 | if (!cpu_online(j)) |
| 122 | continue; |
| 123 | seq_printf(p, "%10u ", |
| 124 | kstat_cpu(j).irqs[i]); |
| 125 | } |
| 126 | #endif |
| 127 | seq_printf(p, " %s:%lx", action->name, |
| 128 | get_ino_in_irqaction(action)); |
| 129 | for (action = action->next; action; action = action->next) { |
| 130 | seq_printf(p, ", %s:%lx", action->name, |
| 131 | get_ino_in_irqaction(action)); |
| 132 | } |
| 133 | seq_putc(p, '\n'); |
| 134 | } |
| 135 | out_unlock: |
| 136 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /* Now these are always passed a true fully specified sun4u INO. */ |
| 142 | void enable_irq(unsigned int irq) |
| 143 | { |
| 144 | struct ino_bucket *bucket = __bucket(irq); |
| 145 | unsigned long imap; |
| 146 | unsigned long tid; |
| 147 | |
| 148 | imap = bucket->imap; |
| 149 | if (imap == 0UL) |
| 150 | return; |
| 151 | |
| 152 | preempt_disable(); |
| 153 | |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 154 | if (tlb_type == hypervisor) { |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 155 | unsigned int ino = __irq_ino(irq); |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 156 | int cpu = hard_smp_processor_id(); |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 157 | int err; |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 158 | |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 159 | err = sun4v_intr_settarget(ino, cpu); |
| 160 | if (err != HV_EOK) |
| 161 | printk("sun4v_intr_settarget(%x,%d): err(%d)\n", |
| 162 | ino, cpu, err); |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 163 | sun4v_intr_setenabled(ino, HV_INTR_ENABLED); |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 164 | if (err != HV_EOK) |
| 165 | printk("sun4v_intr_setenabled(%x): err(%d)\n", |
| 166 | ino, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } else { |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 168 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 169 | unsigned long ver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 171 | __asm__ ("rdpr %%ver, %0" : "=r" (ver)); |
| 172 | if ((ver >> 32) == __JALAPENO_ID || |
| 173 | (ver >> 32) == __SERRANO_ID) { |
| 174 | /* We set it to our JBUS ID. */ |
| 175 | __asm__ __volatile__("ldxa [%%g0] %1, %0" |
| 176 | : "=r" (tid) |
| 177 | : "i" (ASI_JBUS_CONFIG)); |
| 178 | tid = ((tid & (0x1fUL<<17)) << 9); |
| 179 | tid &= IMAP_TID_JBUS; |
| 180 | } else { |
| 181 | /* We set it to our Safari AID. */ |
| 182 | __asm__ __volatile__("ldxa [%%g0] %1, %0" |
| 183 | : "=r" (tid) |
| 184 | : "i"(ASI_SAFARI_CONFIG)); |
| 185 | tid = ((tid & (0x3ffUL<<17)) << 9); |
| 186 | tid &= IMAP_AID_SAFARI; |
| 187 | } |
| 188 | } else if (this_is_starfire == 0) { |
| 189 | /* We set it to our UPA MID. */ |
| 190 | __asm__ __volatile__("ldxa [%%g0] %1, %0" |
| 191 | : "=r" (tid) |
| 192 | : "i" (ASI_UPA_CONFIG)); |
| 193 | tid = ((tid & UPA_CONFIG_MID) << 9); |
| 194 | tid &= IMAP_TID_UPA; |
| 195 | } else { |
| 196 | tid = (starfire_translate(imap, |
| 197 | smp_processor_id()) << 26); |
| 198 | tid &= IMAP_TID_UPA; |
| 199 | } |
| 200 | |
| 201 | /* NOTE NOTE NOTE, IGN and INO are read-only, IGN is a product |
| 202 | * of this SYSIO's preconfigured IGN in the SYSIO Control |
| 203 | * Register, the hardware just mirrors that value here. |
| 204 | * However for Graphics and UPA Slave devices the full |
| 205 | * IMAP_INR field can be set by the programmer here. |
| 206 | * |
| 207 | * Things like FFB can now be handled via the new IRQ |
| 208 | * mechanism. |
| 209 | */ |
| 210 | upa_writel(tid | IMAP_VALID, imap); |
| 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | preempt_enable(); |
| 214 | } |
| 215 | |
| 216 | /* This now gets passed true ino's as well. */ |
| 217 | void disable_irq(unsigned int irq) |
| 218 | { |
| 219 | struct ino_bucket *bucket = __bucket(irq); |
| 220 | unsigned long imap; |
| 221 | |
| 222 | imap = bucket->imap; |
| 223 | if (imap != 0UL) { |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 224 | if (tlb_type == hypervisor) { |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 225 | unsigned int ino = __irq_ino(irq); |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 226 | int err; |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 227 | |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 228 | err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED); |
| 229 | if (err != HV_EOK) |
| 230 | printk("sun4v_intr_setenabled(%x): " |
| 231 | "err(%d)\n", ino, err); |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 232 | } else { |
| 233 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 235 | /* NOTE: We do not want to futz with the IRQ clear registers |
| 236 | * and move the state to IDLE, the SCSI code does call |
| 237 | * disable_irq() to assure atomicity in the queue cmd |
| 238 | * SCSI adapter driver code. Thus we'd lose interrupts. |
| 239 | */ |
| 240 | tmp = upa_readl(imap); |
| 241 | tmp &= ~IMAP_VALID; |
| 242 | upa_writel(tmp, imap); |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | /* The timer is the one "weird" interrupt which is generated by |
| 248 | * the CPU %tick register and not by some normal vectored interrupt |
| 249 | * source. To handle this special case, we use this dummy INO bucket. |
| 250 | */ |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 251 | static struct irq_desc pil0_dummy_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | static struct ino_bucket pil0_dummy_bucket = { |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 253 | .irq_info = &pil0_dummy_desc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 256 | static void build_irq_error(const char *msg, unsigned int ino, int pil, int inofixup, |
| 257 | unsigned long iclr, unsigned long imap, |
| 258 | struct ino_bucket *bucket) |
| 259 | { |
| 260 | prom_printf("IRQ: INO %04x (%d:%016lx:%016lx) --> " |
| 261 | "(%d:%d:%016lx:%016lx), halting...\n", |
| 262 | ino, bucket->pil, bucket->iclr, bucket->imap, |
| 263 | pil, inofixup, iclr, imap); |
| 264 | prom_halt(); |
| 265 | } |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | unsigned int build_irq(int pil, int inofixup, unsigned long iclr, unsigned long imap) |
| 268 | { |
| 269 | struct ino_bucket *bucket; |
| 270 | int ino; |
| 271 | |
| 272 | if (pil == 0) { |
| 273 | if (iclr != 0UL || imap != 0UL) { |
| 274 | prom_printf("Invalid dummy bucket for PIL0 (%lx:%lx)\n", |
| 275 | iclr, imap); |
| 276 | prom_halt(); |
| 277 | } |
| 278 | return __irq(&pil0_dummy_bucket); |
| 279 | } |
| 280 | |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 281 | BUG_ON(tlb_type == hypervisor); |
| 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | /* RULE: Both must be specified in all other cases. */ |
| 284 | if (iclr == 0UL || imap == 0UL) { |
| 285 | prom_printf("Invalid build_irq %d %d %016lx %016lx\n", |
| 286 | pil, inofixup, iclr, imap); |
| 287 | prom_halt(); |
| 288 | } |
| 289 | |
| 290 | ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup; |
| 291 | if (ino > NUM_IVECS) { |
| 292 | prom_printf("Invalid INO %04x (%d:%d:%016lx:%016lx)\n", |
| 293 | ino, pil, inofixup, iclr, imap); |
| 294 | prom_halt(); |
| 295 | } |
| 296 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 297 | bucket = &ivector_table[ino]; |
| 298 | if (bucket->flags & IBF_ACTIVE) |
| 299 | build_irq_error("IRQ: Trying to build active INO bucket.\n", |
| 300 | ino, pil, inofixup, iclr, imap, bucket); |
| 301 | |
| 302 | if (bucket->irq_info) { |
| 303 | if (bucket->imap != imap || bucket->iclr != iclr) |
| 304 | build_irq_error("IRQ: Trying to reinit INO bucket.\n", |
| 305 | ino, pil, inofixup, iclr, imap, bucket); |
| 306 | |
| 307 | goto out; |
| 308 | } |
| 309 | |
| 310 | bucket->irq_info = kmalloc(sizeof(struct irq_desc), GFP_ATOMIC); |
| 311 | if (!bucket->irq_info) { |
| 312 | prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n"); |
| 313 | prom_halt(); |
| 314 | } |
| 315 | memset(bucket->irq_info, 0, sizeof(struct irq_desc)); |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /* Ok, looks good, set it up. Don't touch the irq_chain or |
| 318 | * the pending flag. |
| 319 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | bucket->imap = imap; |
| 321 | bucket->iclr = iclr; |
| 322 | bucket->pil = pil; |
| 323 | bucket->flags = 0; |
| 324 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 325 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return __irq(bucket); |
| 327 | } |
| 328 | |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 329 | unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino, int pil, unsigned char flags) |
| 330 | { |
| 331 | struct ino_bucket *bucket; |
| 332 | unsigned long sysino; |
| 333 | |
| 334 | sysino = sun4v_devino_to_sysino(devhandle, devino); |
| 335 | |
David S. Miller | 87bdc36 | 2006-02-13 21:36:30 -0800 | [diff] [blame] | 336 | printk(KERN_INFO "sun4v_irq: Mapping (%x:%x) --> sysino[%lx]\n", |
| 337 | devhandle, devino, sysino); |
David S. Miller | e399957 | 2006-02-13 18:16:10 -0800 | [diff] [blame] | 338 | |
| 339 | bucket = &ivector_table[sysino]; |
| 340 | |
| 341 | /* Catch accidental accesses to these things. IMAP/ICLR handling |
| 342 | * is done by hypervisor calls on sun4v platforms, not by direct |
| 343 | * register accesses. |
| 344 | */ |
| 345 | bucket->imap = ~0UL; |
| 346 | bucket->iclr = ~0UL; |
| 347 | |
| 348 | bucket->pil = pil; |
| 349 | bucket->flags = flags; |
| 350 | |
| 351 | bucket->irq_info = kmalloc(sizeof(struct irq_desc), GFP_ATOMIC); |
| 352 | if (!bucket->irq_info) { |
| 353 | prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n"); |
| 354 | prom_halt(); |
| 355 | } |
| 356 | memset(bucket->irq_info, 0, sizeof(struct irq_desc)); |
| 357 | |
| 358 | return __irq(bucket); |
| 359 | } |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | static void atomic_bucket_insert(struct ino_bucket *bucket) |
| 362 | { |
| 363 | unsigned long pstate; |
| 364 | unsigned int *ent; |
| 365 | |
| 366 | __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate)); |
| 367 | __asm__ __volatile__("wrpr %0, %1, %%pstate" |
| 368 | : : "r" (pstate), "i" (PSTATE_IE)); |
| 369 | ent = irq_work(smp_processor_id(), bucket->pil); |
| 370 | bucket->irq_chain = *ent; |
| 371 | *ent = __irq(bucket); |
| 372 | __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate)); |
| 373 | } |
| 374 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 375 | static int check_irq_sharing(int pil, unsigned long irqflags) |
| 376 | { |
| 377 | struct irqaction *action, *tmp; |
| 378 | |
| 379 | action = *(irq_action + pil); |
| 380 | if (action) { |
| 381 | if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) { |
| 382 | for (tmp = action; tmp->next; tmp = tmp->next) |
| 383 | ; |
| 384 | } else { |
| 385 | return -EBUSY; |
| 386 | } |
| 387 | } |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static void append_irq_action(int pil, struct irqaction *action) |
| 392 | { |
| 393 | struct irqaction **pp = irq_action + pil; |
| 394 | |
| 395 | while (*pp) |
| 396 | pp = &((*pp)->next); |
| 397 | *pp = action; |
| 398 | } |
| 399 | |
| 400 | static struct irqaction *get_action_slot(struct ino_bucket *bucket) |
| 401 | { |
| 402 | struct irq_desc *desc = bucket->irq_info; |
| 403 | int max_irq, i; |
| 404 | |
| 405 | max_irq = 1; |
| 406 | if (bucket->flags & IBF_PCI) |
| 407 | max_irq = MAX_IRQ_DESC_ACTION; |
| 408 | for (i = 0; i < max_irq; i++) { |
| 409 | struct irqaction *p = &desc->action[i]; |
| 410 | u32 mask = (1 << i); |
| 411 | |
| 412 | if (desc->action_active_mask & mask) |
| 413 | continue; |
| 414 | |
| 415 | desc->action_active_mask |= mask; |
| 416 | return p; |
| 417 | } |
| 418 | return NULL; |
| 419 | } |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), |
| 422 | unsigned long irqflags, const char *name, void *dev_id) |
| 423 | { |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 424 | struct irqaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | struct ino_bucket *bucket = __bucket(irq); |
| 426 | unsigned long flags; |
| 427 | int pending = 0; |
| 428 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 429 | if (unlikely(!handler)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | return -EINVAL; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 431 | |
| 432 | if (unlikely(!bucket->irq_info)) |
| 433 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | if ((bucket != &pil0_dummy_bucket) && (irqflags & SA_SAMPLE_RANDOM)) { |
| 436 | /* |
| 437 | * This function might sleep, we want to call it first, |
| 438 | * outside of the atomic block. In SA_STATIC_ALLOC case, |
| 439 | * random driver's kmalloc will fail, but it is safe. |
| 440 | * If already initialized, random driver will not reinit. |
| 441 | * Yes, this might clear the entropy pool if the wrong |
| 442 | * driver is attempted to be loaded, without actually |
| 443 | * installing a new handler, but is this really a problem, |
| 444 | * only the sysadmin is able to do this. |
| 445 | */ |
| 446 | rand_initialize_irq(irq); |
| 447 | } |
| 448 | |
| 449 | spin_lock_irqsave(&irq_action_lock, flags); |
| 450 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 451 | if (check_irq_sharing(bucket->pil, irqflags)) { |
| 452 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 453 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 456 | action = get_action_slot(bucket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | if (!action) { |
| 458 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 459 | return -ENOMEM; |
| 460 | } |
| 461 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 462 | bucket->flags |= IBF_ACTIVE; |
| 463 | pending = 0; |
| 464 | if (bucket != &pil0_dummy_bucket) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | pending = bucket->pending; |
| 466 | if (pending) |
| 467 | bucket->pending = 0; |
| 468 | } |
| 469 | |
| 470 | action->handler = handler; |
| 471 | action->flags = irqflags; |
| 472 | action->name = name; |
| 473 | action->next = NULL; |
| 474 | action->dev_id = dev_id; |
| 475 | put_ino_in_irqaction(action, irq); |
| 476 | put_smpaff_in_irqaction(action, CPU_MASK_NONE); |
| 477 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 478 | append_irq_action(bucket->pil, action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
| 480 | enable_irq(irq); |
| 481 | |
| 482 | /* We ate the IVEC already, this makes sure it does not get lost. */ |
| 483 | if (pending) { |
| 484 | atomic_bucket_insert(bucket); |
| 485 | set_softint(1 << bucket->pil); |
| 486 | } |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | spin_unlock_irqrestore(&irq_action_lock, flags); |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 489 | |
| 490 | if (bucket != &pil0_dummy_bucket) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | register_irq_proc(__irq_ino(irq)); |
| 492 | |
| 493 | #ifdef CONFIG_SMP |
| 494 | distribute_irqs(); |
| 495 | #endif |
| 496 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | EXPORT_SYMBOL(request_irq); |
| 500 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 501 | static struct irqaction *unlink_irq_action(unsigned int irq, void *dev_id) |
| 502 | { |
| 503 | struct ino_bucket *bucket = __bucket(irq); |
| 504 | struct irqaction *action, **pp; |
| 505 | |
| 506 | pp = irq_action + bucket->pil; |
| 507 | action = *pp; |
| 508 | if (unlikely(!action)) |
| 509 | return NULL; |
| 510 | |
| 511 | if (unlikely(!action->handler)) { |
| 512 | printk("Freeing free IRQ %d\n", bucket->pil); |
| 513 | return NULL; |
| 514 | } |
| 515 | |
| 516 | while (action && action->dev_id != dev_id) { |
| 517 | pp = &action->next; |
| 518 | action = *pp; |
| 519 | } |
| 520 | |
| 521 | if (likely(action)) |
| 522 | *pp = action->next; |
| 523 | |
| 524 | return action; |
| 525 | } |
| 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | void free_irq(unsigned int irq, void *dev_id) |
| 528 | { |
| 529 | struct irqaction *action; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 530 | struct ino_bucket *bucket; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | spin_lock_irqsave(&irq_action_lock, flags); |
| 534 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 535 | action = unlink_irq_action(irq, dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 538 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 539 | if (unlikely(!action)) |
| 540 | return; |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | synchronize_irq(irq); |
| 543 | |
| 544 | spin_lock_irqsave(&irq_action_lock, flags); |
| 545 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 546 | bucket = __bucket(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | if (bucket != &pil0_dummy_bucket) { |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 548 | struct irq_desc *desc = bucket->irq_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | unsigned long imap = bucket->imap; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 550 | int ent, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 552 | for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) { |
| 553 | struct irqaction *p = &desc->action[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 555 | if (p == action) { |
| 556 | desc->action_active_mask &= ~(1 << i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | break; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 558 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 561 | if (!desc->action_active_mask) { |
| 562 | /* This unique interrupt source is now inactive. */ |
| 563 | bucket->flags &= ~IBF_ACTIVE; |
| 564 | |
| 565 | /* See if any other buckets share this bucket's IMAP |
| 566 | * and are still active. |
| 567 | */ |
| 568 | for (ent = 0; ent < NUM_IVECS; ent++) { |
| 569 | struct ino_bucket *bp = &ivector_table[ent]; |
| 570 | if (bp != bucket && |
| 571 | bp->imap == imap && |
| 572 | (bp->flags & IBF_ACTIVE) != 0) |
| 573 | break; |
| 574 | } |
| 575 | |
| 576 | /* Only disable when no other sub-irq levels of |
| 577 | * the same IMAP are active. |
| 578 | */ |
| 579 | if (ent == NUM_IVECS) |
| 580 | disable_irq(irq); |
| 581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 585 | } |
| 586 | |
| 587 | EXPORT_SYMBOL(free_irq); |
| 588 | |
| 589 | #ifdef CONFIG_SMP |
| 590 | void synchronize_irq(unsigned int irq) |
| 591 | { |
| 592 | struct ino_bucket *bucket = __bucket(irq); |
| 593 | |
| 594 | #if 0 |
| 595 | /* The following is how I wish I could implement this. |
| 596 | * Unfortunately the ICLR registers are read-only, you can |
| 597 | * only write ICLR_foo values to them. To get the current |
| 598 | * IRQ status you would need to get at the IRQ diag registers |
| 599 | * in the PCI/SBUS controller and the layout of those vary |
| 600 | * from one controller to the next, sigh... -DaveM |
| 601 | */ |
| 602 | unsigned long iclr = bucket->iclr; |
| 603 | |
| 604 | while (1) { |
| 605 | u32 tmp = upa_readl(iclr); |
| 606 | |
| 607 | if (tmp == ICLR_TRANSMIT || |
| 608 | tmp == ICLR_PENDING) { |
| 609 | cpu_relax(); |
| 610 | continue; |
| 611 | } |
| 612 | break; |
| 613 | } |
| 614 | #else |
| 615 | /* So we have to do this with a INPROGRESS bit just like x86. */ |
| 616 | while (bucket->flags & IBF_INPROGRESS) |
| 617 | cpu_relax(); |
| 618 | #endif |
| 619 | } |
| 620 | #endif /* CONFIG_SMP */ |
| 621 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 622 | static void process_bucket(int irq, struct ino_bucket *bp, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 624 | struct irq_desc *desc = bp->irq_info; |
| 625 | unsigned char flags = bp->flags; |
| 626 | u32 action_mask, i; |
| 627 | int random; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 629 | bp->flags |= IBF_INPROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 631 | if (unlikely(!(flags & IBF_ACTIVE))) { |
| 632 | bp->pending = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
| 635 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 636 | if (desc->pre_handler) |
| 637 | desc->pre_handler(bp, |
| 638 | desc->pre_handler_arg1, |
| 639 | desc->pre_handler_arg2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 641 | action_mask = desc->action_active_mask; |
| 642 | random = 0; |
| 643 | for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) { |
| 644 | struct irqaction *p = &desc->action[i]; |
| 645 | u32 mask = (1 << i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 647 | if (!(action_mask & mask)) |
| 648 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 650 | action_mask &= ~mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 652 | if (p->handler(__irq(bp), p->dev_id, regs) == IRQ_HANDLED) |
| 653 | random |= p->flags; |
| 654 | |
| 655 | if (!action_mask) |
| 656 | break; |
| 657 | } |
| 658 | if (bp->pil != 0) { |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 659 | if (tlb_type == hypervisor) { |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 660 | unsigned int ino = __irq_ino(bp); |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 661 | int err; |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 662 | |
David S. Miller | c4bea28 | 2006-02-13 22:56:27 -0800 | [diff] [blame^] | 663 | err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE); |
| 664 | if (err != HV_EOK) |
| 665 | printk("sun4v_intr_setstate(%x): " |
| 666 | "err(%d)\n", ino, err); |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 667 | } else { |
| 668 | upa_writel(ICLR_IDLE, bp->iclr); |
| 669 | /* Test and add entropy */ |
| 670 | if (random & SA_SAMPLE_RANDOM) |
| 671 | add_interrupt_randomness(irq); |
| 672 | } |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 673 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | out: |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 675 | bp->flags &= ~IBF_INPROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | void handler_irq(int irq, struct pt_regs *regs) |
| 679 | { |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 680 | struct ino_bucket *bp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | int cpu = smp_processor_id(); |
| 682 | |
| 683 | #ifndef CONFIG_SMP |
| 684 | /* |
| 685 | * Check for TICK_INT on level 14 softint. |
| 686 | */ |
| 687 | { |
| 688 | unsigned long clr_mask = 1 << irq; |
| 689 | unsigned long tick_mask = tick_ops->softint_mask; |
| 690 | |
| 691 | if ((irq == 14) && (get_softint() & tick_mask)) { |
| 692 | irq = 0; |
| 693 | clr_mask = tick_mask; |
| 694 | } |
| 695 | clear_softint(clr_mask); |
| 696 | } |
| 697 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | clear_softint(1 << irq); |
| 699 | #endif |
| 700 | |
| 701 | irq_enter(); |
| 702 | kstat_this_cpu.irqs[irq]++; |
| 703 | |
| 704 | /* Sliiiick... */ |
| 705 | #ifndef CONFIG_SMP |
| 706 | bp = ((irq != 0) ? |
| 707 | __bucket(xchg32(irq_work(cpu, irq), 0)) : |
| 708 | &pil0_dummy_bucket); |
| 709 | #else |
| 710 | bp = __bucket(xchg32(irq_work(cpu, irq), 0)); |
| 711 | #endif |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 712 | while (bp) { |
| 713 | struct ino_bucket *nbp = __bucket(bp->irq_chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | bp->irq_chain = 0; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 716 | process_bucket(irq, bp, regs); |
| 717 | bp = nbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | irq_exit(); |
| 720 | } |
| 721 | |
| 722 | #ifdef CONFIG_BLK_DEV_FD |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 723 | extern irqreturn_t floppy_interrupt(int, void *, struct pt_regs *);; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 725 | /* XXX No easy way to include asm/floppy.h XXX */ |
| 726 | extern unsigned char *pdma_vaddr; |
| 727 | extern unsigned long pdma_size; |
| 728 | extern volatile int doing_pdma; |
| 729 | extern unsigned long fdc_status; |
| 730 | |
| 731 | irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | { |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 733 | if (likely(doing_pdma)) { |
| 734 | void __iomem *stat = (void __iomem *) fdc_status; |
| 735 | unsigned char *vaddr = pdma_vaddr; |
| 736 | unsigned long size = pdma_size; |
| 737 | u8 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 739 | while (size) { |
| 740 | val = readb(stat); |
| 741 | if (unlikely(!(val & 0x80))) { |
| 742 | pdma_vaddr = vaddr; |
| 743 | pdma_size = size; |
| 744 | return IRQ_HANDLED; |
| 745 | } |
| 746 | if (unlikely(!(val & 0x20))) { |
| 747 | pdma_vaddr = vaddr; |
| 748 | pdma_size = size; |
| 749 | doing_pdma = 0; |
| 750 | goto main_interrupt; |
| 751 | } |
| 752 | if (val & 0x40) { |
| 753 | /* read */ |
| 754 | *vaddr++ = readb(stat + 1); |
| 755 | } else { |
| 756 | unsigned char data = *vaddr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 758 | /* write */ |
| 759 | writeb(data, stat + 1); |
| 760 | } |
| 761 | size--; |
| 762 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 764 | pdma_vaddr = vaddr; |
| 765 | pdma_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 767 | /* Send Terminal Count pulse to floppy controller. */ |
| 768 | val = readb(auxio_register); |
| 769 | val |= AUXIO_AUX1_FTCNT; |
| 770 | writeb(val, auxio_register); |
Bernhard R Link | 94bbc17 | 2006-03-10 01:23:13 -0800 | [diff] [blame] | 771 | val &= ~AUXIO_AUX1_FTCNT; |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 772 | writeb(val, auxio_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 774 | doing_pdma = 0; |
| 775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 777 | main_interrupt: |
| 778 | return floppy_interrupt(irq, dev_cookie, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 780 | EXPORT_SYMBOL(sparc_floppy_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | #endif |
| 782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | /* We really don't need these at all on the Sparc. We only have |
| 784 | * stubs here because they are exported to modules. |
| 785 | */ |
| 786 | unsigned long probe_irq_on(void) |
| 787 | { |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | EXPORT_SYMBOL(probe_irq_on); |
| 792 | |
| 793 | int probe_irq_off(unsigned long mask) |
| 794 | { |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | EXPORT_SYMBOL(probe_irq_off); |
| 799 | |
| 800 | #ifdef CONFIG_SMP |
| 801 | static int retarget_one_irq(struct irqaction *p, int goal_cpu) |
| 802 | { |
| 803 | struct ino_bucket *bucket = get_ino_in_irqaction(p) + ivector_table; |
| 804 | unsigned long imap = bucket->imap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
| 806 | while (!cpu_online(goal_cpu)) { |
| 807 | if (++goal_cpu >= NR_CPUS) |
| 808 | goal_cpu = 0; |
| 809 | } |
| 810 | |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 811 | if (tlb_type == hypervisor) { |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 812 | unsigned int ino = __irq_ino(bucket); |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 813 | |
David S. Miller | 4bf447d | 2006-02-13 22:37:32 -0800 | [diff] [blame] | 814 | sun4v_intr_settarget(ino, goal_cpu); |
| 815 | sun4v_intr_setenabled(ino, HV_INTR_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } else { |
David S. Miller | 10951ee | 2006-02-13 18:22:57 -0800 | [diff] [blame] | 817 | unsigned int tid; |
| 818 | |
| 819 | if (tlb_type == cheetah || tlb_type == cheetah_plus) { |
| 820 | tid = goal_cpu << 26; |
| 821 | tid &= IMAP_AID_SAFARI; |
| 822 | } else if (this_is_starfire == 0) { |
| 823 | tid = goal_cpu << 26; |
| 824 | tid &= IMAP_TID_UPA; |
| 825 | } else { |
| 826 | tid = (starfire_translate(imap, goal_cpu) << 26); |
| 827 | tid &= IMAP_TID_UPA; |
| 828 | } |
| 829 | upa_writel(tid | IMAP_VALID, imap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
David S. Miller | cee2824 | 2005-05-03 22:04:36 -0700 | [diff] [blame] | 832 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | if (++goal_cpu >= NR_CPUS) |
| 834 | goal_cpu = 0; |
David S. Miller | cee2824 | 2005-05-03 22:04:36 -0700 | [diff] [blame] | 835 | } while (!cpu_online(goal_cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
| 837 | return goal_cpu; |
| 838 | } |
| 839 | |
| 840 | /* Called from request_irq. */ |
| 841 | static void distribute_irqs(void) |
| 842 | { |
| 843 | unsigned long flags; |
| 844 | int cpu, level; |
| 845 | |
| 846 | spin_lock_irqsave(&irq_action_lock, flags); |
| 847 | cpu = 0; |
| 848 | |
| 849 | /* |
| 850 | * Skip the timer at [0], and very rare error/power intrs at [15]. |
| 851 | * Also level [12], it causes problems on Ex000 systems. |
| 852 | */ |
| 853 | for (level = 1; level < NR_IRQS; level++) { |
| 854 | struct irqaction *p = irq_action[level]; |
David S. Miller | 088dd1f | 2005-07-04 13:24:38 -0700 | [diff] [blame] | 855 | |
| 856 | if (level == 12) |
| 857 | continue; |
| 858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | while(p) { |
| 860 | cpu = retarget_one_irq(p, cpu); |
| 861 | p = p->next; |
| 862 | } |
| 863 | } |
| 864 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 865 | } |
| 866 | #endif |
| 867 | |
David S. Miller | cdd5186 | 2005-07-24 19:36:13 -0700 | [diff] [blame] | 868 | struct sun5_timer { |
| 869 | u64 count0; |
| 870 | u64 limit0; |
| 871 | u64 count1; |
| 872 | u64 limit1; |
| 873 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
David S. Miller | cdd5186 | 2005-07-24 19:36:13 -0700 | [diff] [blame] | 875 | static struct sun5_timer *prom_timers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | static u64 prom_limit0, prom_limit1; |
| 877 | |
| 878 | static void map_prom_timers(void) |
| 879 | { |
| 880 | unsigned int addr[3]; |
| 881 | int tnode, err; |
| 882 | |
| 883 | /* PROM timer node hangs out in the top level of device siblings... */ |
| 884 | tnode = prom_finddevice("/counter-timer"); |
| 885 | |
| 886 | /* Assume if node is not present, PROM uses different tick mechanism |
| 887 | * which we should not care about. |
| 888 | */ |
| 889 | if (tnode == 0 || tnode == -1) { |
| 890 | prom_timers = (struct sun5_timer *) 0; |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | /* If PROM is really using this, it must be mapped by him. */ |
| 895 | err = prom_getproperty(tnode, "address", (char *)addr, sizeof(addr)); |
| 896 | if (err == -1) { |
| 897 | prom_printf("PROM does not have timer mapped, trying to continue.\n"); |
| 898 | prom_timers = (struct sun5_timer *) 0; |
| 899 | return; |
| 900 | } |
| 901 | prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]); |
| 902 | } |
| 903 | |
| 904 | static void kill_prom_timer(void) |
| 905 | { |
| 906 | if (!prom_timers) |
| 907 | return; |
| 908 | |
| 909 | /* Save them away for later. */ |
| 910 | prom_limit0 = prom_timers->limit0; |
| 911 | prom_limit1 = prom_timers->limit1; |
| 912 | |
| 913 | /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14. |
| 914 | * We turn both off here just to be paranoid. |
| 915 | */ |
| 916 | prom_timers->limit0 = 0; |
| 917 | prom_timers->limit1 = 0; |
| 918 | |
| 919 | /* Wheee, eat the interrupt packet too... */ |
| 920 | __asm__ __volatile__( |
| 921 | " mov 0x40, %%g2\n" |
| 922 | " ldxa [%%g0] %0, %%g1\n" |
| 923 | " ldxa [%%g2] %1, %%g1\n" |
| 924 | " stxa %%g0, [%%g0] %0\n" |
| 925 | " membar #Sync\n" |
| 926 | : /* no outputs */ |
| 927 | : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R) |
| 928 | : "g1", "g2"); |
| 929 | } |
| 930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | void init_irqwork_curcpu(void) |
| 932 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | int cpu = hard_smp_processor_id(); |
| 934 | |
David S. Miller | 56fb4df | 2006-02-26 23:24:22 -0800 | [diff] [blame] | 935 | memset(__irq_work + cpu, 0, sizeof(struct irq_work_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | } |
| 937 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 938 | static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type) |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 939 | { |
David S. Miller | 164c220 | 2006-02-09 22:57:21 -0800 | [diff] [blame] | 940 | register unsigned long func __asm__("%o5"); |
| 941 | register unsigned long arg0 __asm__("%o0"); |
| 942 | register unsigned long arg1 __asm__("%o1"); |
| 943 | register unsigned long arg2 __asm__("%o2"); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 944 | |
| 945 | func = HV_FAST_CPU_QCONF; |
| 946 | arg0 = type; |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 947 | arg1 = paddr; |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 948 | arg2 = 128; /* XXX Implied by Niagara queue offsets. XXX */ |
| 949 | __asm__ __volatile__("ta %8" |
| 950 | : "=&r" (func), "=&r" (arg0), |
| 951 | "=&r" (arg1), "=&r" (arg2) |
| 952 | : "0" (func), "1" (arg0), |
| 953 | "2" (arg1), "3" (arg2), |
| 954 | "i" (HV_FAST_TRAP)); |
| 955 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 956 | if (arg0 != HV_EOK) { |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 957 | prom_printf("SUN4V: cpu_qconf(%lu) failed with error %lu\n", |
| 958 | type, func); |
| 959 | prom_halt(); |
| 960 | } |
| 961 | } |
| 962 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 963 | static void __cpuinit sun4v_register_mondo_queues(int this_cpu) |
David S. Miller | 5b0c057 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 964 | { |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 965 | struct trap_per_cpu *tb = &trap_block[this_cpu]; |
| 966 | |
| 967 | register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO); |
| 968 | register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO); |
| 969 | register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR); |
| 970 | register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR); |
| 971 | } |
| 972 | |
| 973 | static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, int use_bootmem) |
| 974 | { |
| 975 | void *page; |
| 976 | |
| 977 | if (use_bootmem) |
| 978 | page = alloc_bootmem_low_pages(PAGE_SIZE); |
| 979 | else |
| 980 | page = (void *) get_zeroed_page(GFP_ATOMIC); |
| 981 | |
| 982 | if (!page) { |
| 983 | prom_printf("SUN4V: Error, cannot allocate mondo queue.\n"); |
| 984 | prom_halt(); |
| 985 | } |
| 986 | |
| 987 | *pa_ptr = __pa(page); |
| 988 | } |
| 989 | |
| 990 | static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, int use_bootmem) |
| 991 | { |
| 992 | void *page; |
| 993 | |
| 994 | if (use_bootmem) |
| 995 | page = alloc_bootmem_low_pages(PAGE_SIZE); |
| 996 | else |
| 997 | page = (void *) get_zeroed_page(GFP_ATOMIC); |
David S. Miller | 5b0c057 | 2006-02-08 02:53:50 -0800 | [diff] [blame] | 998 | |
| 999 | if (!page) { |
| 1000 | prom_printf("SUN4V: Error, cannot allocate kbuf page.\n"); |
| 1001 | prom_halt(); |
| 1002 | } |
| 1003 | |
| 1004 | *pa_ptr = __pa(page); |
| 1005 | } |
| 1006 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1007 | static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem) |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1008 | { |
| 1009 | #ifdef CONFIG_SMP |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1010 | void *page; |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1011 | |
| 1012 | BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64)); |
| 1013 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1014 | if (use_bootmem) |
| 1015 | page = alloc_bootmem_low_pages(PAGE_SIZE); |
| 1016 | else |
| 1017 | page = (void *) get_zeroed_page(GFP_ATOMIC); |
| 1018 | |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1019 | if (!page) { |
| 1020 | prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n"); |
| 1021 | prom_halt(); |
| 1022 | } |
| 1023 | |
| 1024 | tb->cpu_mondo_block_pa = __pa(page); |
| 1025 | tb->cpu_list_pa = __pa(page + 64); |
| 1026 | #endif |
| 1027 | } |
| 1028 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1029 | /* Allocate and register the mondo and error queues for this cpu. */ |
| 1030 | void __cpuinit sun4v_init_mondo_queues(int use_bootmem) |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1031 | { |
| 1032 | int cpu = hard_smp_processor_id(); |
| 1033 | struct trap_per_cpu *tb = &trap_block[cpu]; |
| 1034 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1035 | alloc_one_mondo(&tb->cpu_mondo_pa, use_bootmem); |
| 1036 | alloc_one_mondo(&tb->dev_mondo_pa, use_bootmem); |
| 1037 | alloc_one_mondo(&tb->resum_mondo_pa, use_bootmem); |
| 1038 | alloc_one_kbuf(&tb->resum_kernel_buf_pa, use_bootmem); |
| 1039 | alloc_one_mondo(&tb->nonresum_mondo_pa, use_bootmem); |
| 1040 | alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, use_bootmem); |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1041 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1042 | init_cpu_send_mondo_info(tb, use_bootmem); |
David S. Miller | 1d2f1f9 | 2006-02-08 16:41:20 -0800 | [diff] [blame] | 1043 | |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1044 | sun4v_register_mondo_queues(cpu); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1045 | } |
| 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | /* Only invoked on boot processor. */ |
| 1048 | void __init init_IRQ(void) |
| 1049 | { |
| 1050 | map_prom_timers(); |
| 1051 | kill_prom_timer(); |
| 1052 | memset(&ivector_table[0], 0, sizeof(ivector_table)); |
| 1053 | |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1054 | if (tlb_type == hypervisor) |
David S. Miller | b5a37e9 | 2006-02-11 23:07:13 -0800 | [diff] [blame] | 1055 | sun4v_init_mondo_queues(1); |
David S. Miller | ac29c11 | 2006-02-08 00:08:23 -0800 | [diff] [blame] | 1056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | /* We need to clear any IRQ's pending in the soft interrupt |
| 1058 | * registers, a spurious one could be left around from the |
| 1059 | * PROM timer which we just disabled. |
| 1060 | */ |
| 1061 | clear_softint(get_softint()); |
| 1062 | |
| 1063 | /* Now that ivector table is initialized, it is safe |
| 1064 | * to receive IRQ vector traps. We will normally take |
| 1065 | * one or two right now, in case some device PROM used |
| 1066 | * to boot us wants to speak to us. We just ignore them. |
| 1067 | */ |
| 1068 | __asm__ __volatile__("rdpr %%pstate, %%g1\n\t" |
| 1069 | "or %%g1, %0, %%g1\n\t" |
| 1070 | "wrpr %%g1, 0x0, %%pstate" |
| 1071 | : /* No outputs */ |
| 1072 | : "i" (PSTATE_IE) |
| 1073 | : "g1"); |
| 1074 | } |
| 1075 | |
| 1076 | static struct proc_dir_entry * root_irq_dir; |
| 1077 | static struct proc_dir_entry * irq_dir [NUM_IVECS]; |
| 1078 | |
| 1079 | #ifdef CONFIG_SMP |
| 1080 | |
| 1081 | static int irq_affinity_read_proc (char *page, char **start, off_t off, |
| 1082 | int count, int *eof, void *data) |
| 1083 | { |
| 1084 | struct ino_bucket *bp = ivector_table + (long)data; |
Eddie C. Dost | 12cf649 | 2005-07-06 15:40:21 -0700 | [diff] [blame] | 1085 | struct irq_desc *desc = bp->irq_info; |
| 1086 | struct irqaction *ap = desc->action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | cpumask_t mask; |
| 1088 | int len; |
| 1089 | |
| 1090 | mask = get_smpaff_in_irqaction(ap); |
| 1091 | if (cpus_empty(mask)) |
| 1092 | mask = cpu_online_map; |
| 1093 | |
| 1094 | len = cpumask_scnprintf(page, count, mask); |
| 1095 | if (count - len < 2) |
| 1096 | return -EINVAL; |
| 1097 | len += sprintf(page + len, "\n"); |
| 1098 | return len; |
| 1099 | } |
| 1100 | |
| 1101 | static inline void set_intr_affinity(int irq, cpumask_t hw_aff) |
| 1102 | { |
| 1103 | struct ino_bucket *bp = ivector_table + irq; |
Eddie C. Dost | 12cf649 | 2005-07-06 15:40:21 -0700 | [diff] [blame] | 1104 | struct irq_desc *desc = bp->irq_info; |
| 1105 | struct irqaction *ap = desc->action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
| 1107 | /* Users specify affinity in terms of hw cpu ids. |
| 1108 | * As soon as we do this, handler_irq() might see and take action. |
| 1109 | */ |
Eddie C. Dost | 12cf649 | 2005-07-06 15:40:21 -0700 | [diff] [blame] | 1110 | put_smpaff_in_irqaction(ap, hw_aff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
| 1112 | /* Migration is simply done by the next cpu to service this |
| 1113 | * interrupt. |
| 1114 | */ |
| 1115 | } |
| 1116 | |
| 1117 | static int irq_affinity_write_proc (struct file *file, const char __user *buffer, |
| 1118 | unsigned long count, void *data) |
| 1119 | { |
| 1120 | int irq = (long) data, full_count = count, err; |
| 1121 | cpumask_t new_value; |
| 1122 | |
| 1123 | err = cpumask_parse(buffer, count, new_value); |
| 1124 | |
| 1125 | /* |
| 1126 | * Do not allow disabling IRQs completely - it's a too easy |
| 1127 | * way to make the system unusable accidentally :-) At least |
| 1128 | * one online CPU still has to be targeted. |
| 1129 | */ |
| 1130 | cpus_and(new_value, new_value, cpu_online_map); |
| 1131 | if (cpus_empty(new_value)) |
| 1132 | return -EINVAL; |
| 1133 | |
| 1134 | set_intr_affinity(irq, new_value); |
| 1135 | |
| 1136 | return full_count; |
| 1137 | } |
| 1138 | |
| 1139 | #endif |
| 1140 | |
| 1141 | #define MAX_NAMELEN 10 |
| 1142 | |
| 1143 | static void register_irq_proc (unsigned int irq) |
| 1144 | { |
| 1145 | char name [MAX_NAMELEN]; |
| 1146 | |
| 1147 | if (!root_irq_dir || irq_dir[irq]) |
| 1148 | return; |
| 1149 | |
| 1150 | memset(name, 0, MAX_NAMELEN); |
| 1151 | sprintf(name, "%x", irq); |
| 1152 | |
| 1153 | /* create /proc/irq/1234 */ |
| 1154 | irq_dir[irq] = proc_mkdir(name, root_irq_dir); |
| 1155 | |
| 1156 | #ifdef CONFIG_SMP |
| 1157 | /* XXX SMP affinity not supported on starfire yet. */ |
| 1158 | if (this_is_starfire == 0) { |
| 1159 | struct proc_dir_entry *entry; |
| 1160 | |
| 1161 | /* create /proc/irq/1234/smp_affinity */ |
| 1162 | entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]); |
| 1163 | |
| 1164 | if (entry) { |
| 1165 | entry->nlink = 1; |
| 1166 | entry->data = (void *)(long)irq; |
| 1167 | entry->read_proc = irq_affinity_read_proc; |
| 1168 | entry->write_proc = irq_affinity_write_proc; |
| 1169 | } |
| 1170 | } |
| 1171 | #endif |
| 1172 | } |
| 1173 | |
| 1174 | void init_irq_proc (void) |
| 1175 | { |
| 1176 | /* create /proc/irq */ |
| 1177 | root_irq_dir = proc_mkdir("irq", NULL); |
| 1178 | } |
| 1179 | |