aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/mac/macints.c
diff options
context:
space:
mode:
authorRoman Zippel <zippel@linux-m68k.org>2006-06-25 08:47:04 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-25 13:00:58 -0400
commit9c5f4afdfbe72d5d1c814ad7286a4524d00c7b96 (patch)
tree7492a9533010d2016ff90a7372465edebcbb0d20 /arch/m68k/mac/macints.c
parent35353bb8b869f3a0a153d0674cdafbe4f64aaa05 (diff)
[PATCH] m68k: convert mac irq code
Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/m68k/mac/macints.c')
-rw-r--r--arch/m68k/mac/macints.c496
1 files changed, 127 insertions, 369 deletions
diff --git a/arch/m68k/mac/macints.c b/arch/m68k/mac/macints.c
index 73b39cd3f94c..694b14bb0de1 100644
--- a/arch/m68k/mac/macints.c
+++ b/arch/m68k/mac/macints.c
@@ -137,14 +137,6 @@
137#define DEBUG_SPURIOUS 137#define DEBUG_SPURIOUS
138#define SHUTUP_SONIC 138#define SHUTUP_SONIC
139 139
140/*
141 * The mac_irq_list array is an array of linked lists of irq_node_t nodes.
142 * Each node contains one handler to be called whenever the interrupt
143 * occurs, with fast handlers listed before slow handlers.
144 */
145
146irq_node_t *mac_irq_list[NUM_MAC_SOURCES];
147
148/* SCC interrupt mask */ 140/* SCC interrupt mask */
149 141
150static int scc_mask; 142static int scc_mask;
@@ -209,8 +201,8 @@ extern int baboon_irq_pending(int);
209 * SCC interrupt routines 201 * SCC interrupt routines
210 */ 202 */
211 203
212static void scc_irq_enable(int); 204static void scc_irq_enable(unsigned int);
213static void scc_irq_disable(int); 205static void scc_irq_disable(unsigned int);
214 206
215/* 207/*
216 * console_loglevel determines NMI handler function 208 * console_loglevel determines NMI handler function
@@ -221,21 +213,25 @@ irqreturn_t mac_debug_handler(int, void *, struct pt_regs *);
221 213
222/* #define DEBUG_MACINTS */ 214/* #define DEBUG_MACINTS */
223 215
216static void mac_enable_irq(unsigned int irq);
217static void mac_disable_irq(unsigned int irq);
218
219static struct irq_controller mac_irq_controller = {
220 .name = "mac",
221 .lock = SPIN_LOCK_UNLOCKED,
222 .enable = mac_enable_irq,
223 .disable = mac_disable_irq,
224};
225
224void mac_init_IRQ(void) 226void mac_init_IRQ(void)
225{ 227{
226 int i;
227
228#ifdef DEBUG_MACINTS 228#ifdef DEBUG_MACINTS
229 printk("mac_init_IRQ(): Setting things up...\n"); 229 printk("mac_init_IRQ(): Setting things up...\n");
230#endif 230#endif
231 /* Initialize the IRQ handler lists. Initially each list is empty, */
232
233 for (i = 0; i < NUM_MAC_SOURCES; i++) {
234 mac_irq_list[i] = NULL;
235 }
236
237 scc_mask = 0; 231 scc_mask = 0;
238 232
233 m68k_setup_irq_controller(&mac_irq_controller, IRQ_USER,
234 NUM_MAC_SOURCES - IRQ_USER);
239 /* Make sure the SONIC interrupt is cleared or things get ugly */ 235 /* Make sure the SONIC interrupt is cleared or things get ugly */
240#ifdef SHUTUP_SONIC 236#ifdef SHUTUP_SONIC
241 printk("Killing onboard sonic... "); 237 printk("Killing onboard sonic... ");
@@ -252,15 +248,16 @@ void mac_init_IRQ(void)
252 * at levels 1-7. Most of the work is done elsewhere. 248 * at levels 1-7. Most of the work is done elsewhere.
253 */ 249 */
254 250
255 if (oss_present) { 251 if (oss_present)
256 oss_register_interrupts(); 252 oss_register_interrupts();
257 } else { 253 else
258 via_register_interrupts(); 254 via_register_interrupts();
259 } 255 if (psc_present)
260 if (psc_present) psc_register_interrupts(); 256 psc_register_interrupts();
261 if (baboon_present) baboon_register_interrupts(); 257 if (baboon_present)
258 baboon_register_interrupts();
262 iop_register_interrupts(); 259 iop_register_interrupts();
263 cpu_request_irq(7, mac_nmi_handler, IRQ_FLG_LOCK, "NMI", 260 request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
264 mac_nmi_handler); 261 mac_nmi_handler);
265#ifdef DEBUG_MACINTS 262#ifdef DEBUG_MACINTS
266 printk("mac_init_IRQ(): Done!\n"); 263 printk("mac_init_IRQ(): Done!\n");
@@ -268,104 +265,6 @@ void mac_init_IRQ(void)
268} 265}
269 266
270/* 267/*
271 * Routines to work with irq_node_t's on linked lists lifted from
272 * the Amiga code written by Roman Zippel.
273 */
274
275static inline void mac_insert_irq(irq_node_t **list, irq_node_t *node)
276{
277 unsigned long flags;
278 irq_node_t *cur;
279
280 if (!node->dev_id)
281 printk("%s: Warning: dev_id of %s is zero\n",
282 __FUNCTION__, node->devname);
283
284 local_irq_save(flags);
285
286 cur = *list;
287
288 if (node->flags & IRQ_FLG_FAST) {
289 node->flags &= ~IRQ_FLG_SLOW;
290 while (cur && cur->flags & IRQ_FLG_FAST) {
291 list = &cur->next;
292 cur = cur->next;
293 }
294 } else if (node->flags & IRQ_FLG_SLOW) {
295 while (cur) {
296 list = &cur->next;
297 cur = cur->next;
298 }
299 } else {
300 while (cur && !(cur->flags & IRQ_FLG_SLOW)) {
301 list = &cur->next;
302 cur = cur->next;
303 }
304 }
305
306 node->next = cur;
307 *list = node;
308
309 local_irq_restore(flags);
310}
311
312static inline void mac_delete_irq(irq_node_t **list, void *dev_id)
313{
314 unsigned long flags;
315 irq_node_t *node;
316
317 local_irq_save(flags);
318
319 for (node = *list; node; list = &node->next, node = *list) {
320 if (node->dev_id == dev_id) {
321 *list = node->next;
322 /* Mark it as free. */
323 node->handler = NULL;
324 local_irq_restore(flags);
325 return;
326 }
327 }
328 local_irq_restore(flags);
329 printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
330}
331
332/*
333 * Call all the handlers for a given interrupt. Fast handlers are called
334 * first followed by slow handlers.
335 *
336 * This code taken from the original Amiga code written by Roman Zippel.
337 */
338
339void mac_do_irq_list(int irq, struct pt_regs *fp)
340{
341 irq_node_t *node, *slow_nodes;
342 unsigned long flags;
343
344 kstat_cpu(0).irqs[irq]++;
345
346#ifdef DEBUG_SPURIOUS
347 if (!mac_irq_list[irq] && (console_loglevel > 7)) {
348 printk("mac_do_irq_list: spurious interrupt %d!\n", irq);
349 return;
350 }
351#endif
352
353 /* serve first fast and normal handlers */
354 for (node = mac_irq_list[irq];
355 node && (!(node->flags & IRQ_FLG_SLOW));
356 node = node->next)
357 node->handler(irq, node->dev_id, fp);
358 if (!node) return;
359 local_save_flags(flags);
360 local_irq_restore((flags & ~0x0700) | (fp->sr & 0x0700));
361 /* if slow handlers exists, serve them now */
362 slow_nodes = node;
363 for (; node; node = node->next) {
364 node->handler(irq, node->dev_id, fp);
365 }
366}
367
368/*
369 * mac_enable_irq - enable an interrupt source 268 * mac_enable_irq - enable an interrupt source
370 * mac_disable_irq - disable an interrupt source 269 * mac_disable_irq - disable an interrupt source
371 * mac_clear_irq - clears a pending interrupt 270 * mac_clear_irq - clears a pending interrupt
@@ -374,265 +273,120 @@ void mac_do_irq_list(int irq, struct pt_regs *fp)
374 * These routines are just dispatchers to the VIA/OSS/PSC routines. 273 * These routines are just dispatchers to the VIA/OSS/PSC routines.
375 */ 274 */
376 275
377void mac_enable_irq (unsigned int irq) 276static void mac_enable_irq(unsigned int irq)
378{ 277{
379 int irq_src = IRQ_SRC(irq); 278 int irq_src = IRQ_SRC(irq);
380 279
381 switch(irq_src) { 280 switch(irq_src) {
382 case 1: via_irq_enable(irq); 281 case 1:
383 break; 282 via_irq_enable(irq);
384 case 2: 283 break;
385 case 7: if (oss_present) { 284 case 2:
386 oss_irq_enable(irq); 285 case 7:
387 } else { 286 if (oss_present)
388 via_irq_enable(irq); 287 oss_irq_enable(irq);
389 } 288 else
390 break; 289 via_irq_enable(irq);
391 case 3: 290 break;
392 case 4: 291 case 3:
393 case 5: 292 case 4:
394 case 6: if (psc_present) { 293 case 5:
395 psc_irq_enable(irq); 294 case 6:
396 } else if (oss_present) { 295 if (psc_present)
397 oss_irq_enable(irq); 296 psc_irq_enable(irq);
398 } else if (irq_src == 4) { 297 else if (oss_present)
399 scc_irq_enable(irq); 298 oss_irq_enable(irq);
400 } 299 else if (irq_src == 4)
401 break; 300 scc_irq_enable(irq);
402 case 8: if (baboon_present) { 301 break;
403 baboon_irq_enable(irq); 302 case 8:
404 } 303 if (baboon_present)
405 break; 304 baboon_irq_enable(irq);
305 break;
406 } 306 }
407} 307}
408 308
409void mac_disable_irq (unsigned int irq) 309static void mac_disable_irq(unsigned int irq)
410{ 310{
411 int irq_src = IRQ_SRC(irq); 311 int irq_src = IRQ_SRC(irq);
412 312
413 switch(irq_src) { 313 switch(irq_src) {
414 case 1: via_irq_disable(irq); 314 case 1:
415 break; 315 via_irq_disable(irq);
416 case 2: 316 break;
417 case 7: if (oss_present) { 317 case 2:
418 oss_irq_disable(irq); 318 case 7:
419 } else { 319 if (oss_present)
420 via_irq_disable(irq); 320 oss_irq_disable(irq);
421 } 321 else
422 break; 322 via_irq_disable(irq);
423 case 3: 323 break;
424 case 4: 324 case 3:
425 case 5: 325 case 4:
426 case 6: if (psc_present) { 326 case 5:
427 psc_irq_disable(irq); 327 case 6:
428 } else if (oss_present) { 328 if (psc_present)
429 oss_irq_disable(irq); 329 psc_irq_disable(irq);
430 } else if (irq_src == 4) { 330 else if (oss_present)
431 scc_irq_disable(irq); 331 oss_irq_disable(irq);
432 } 332 else if (irq_src == 4)
433 break; 333 scc_irq_disable(irq);
434 case 8: if (baboon_present) { 334 break;
435 baboon_irq_disable(irq); 335 case 8:
436 } 336 if (baboon_present)
437 break; 337 baboon_irq_disable(irq);
338 break;
438 } 339 }
439} 340}
440 341
441void mac_clear_irq( unsigned int irq ) 342void mac_clear_irq(unsigned int irq)
442{ 343{
443 switch(IRQ_SRC(irq)) { 344 switch(IRQ_SRC(irq)) {
444 case 1: via_irq_clear(irq); 345 case 1:
445 break; 346 via_irq_clear(irq);
446 case 2: 347 break;
447 case 7: if (oss_present) { 348 case 2:
448 oss_irq_clear(irq); 349 case 7:
449 } else { 350 if (oss_present)
450 via_irq_clear(irq); 351 oss_irq_clear(irq);
451 } 352 else
452 break; 353 via_irq_clear(irq);
453 case 3: 354 break;
454 case 4: 355 case 3:
455 case 5: 356 case 4:
456 case 6: if (psc_present) { 357 case 5:
457 psc_irq_clear(irq); 358 case 6:
458 } else if (oss_present) { 359 if (psc_present)
459 oss_irq_clear(irq); 360 psc_irq_clear(irq);
460 } 361 else if (oss_present)
461 break; 362 oss_irq_clear(irq);
462 case 8: if (baboon_present) { 363 break;
463 baboon_irq_clear(irq); 364 case 8:
464 } 365 if (baboon_present)
465 break; 366 baboon_irq_clear(irq);
367 break;
466 } 368 }
467} 369}
468 370
469int mac_irq_pending( unsigned int irq ) 371int mac_irq_pending(unsigned int irq)
470{ 372{
471 switch(IRQ_SRC(irq)) { 373 switch(IRQ_SRC(irq)) {
472 case 1: return via_irq_pending(irq); 374 case 1:
473 case 2: 375 return via_irq_pending(irq);
474 case 7: if (oss_present) { 376 case 2:
475 return oss_irq_pending(irq); 377 case 7:
476 } else { 378 if (oss_present)
477 return via_irq_pending(irq); 379 return oss_irq_pending(irq);
478 } 380 else
479 case 3: 381 return via_irq_pending(irq);
480 case 4: 382 case 3:
481 case 5: 383 case 4:
482 case 6: if (psc_present) { 384 case 5:
483 return psc_irq_pending(irq); 385 case 6:
484 } else if (oss_present) { 386 if (psc_present)
485 return oss_irq_pending(irq); 387 return psc_irq_pending(irq);
486 } 388 else if (oss_present)
487 } 389 return oss_irq_pending(irq);
488 return 0;
489}
490
491/*
492 * Add an interrupt service routine to an interrupt source.
493 * Returns 0 on success.
494 *
495 * FIXME: You can register interrupts on nonexistent source (ie PSC4 on a
496 * non-PSC machine). We should return -EINVAL in those cases.
497 */
498
499int mac_request_irq(unsigned int irq,
500 irqreturn_t (*handler)(int, void *, struct pt_regs *),
501 unsigned long flags, const char *devname, void *dev_id)
502{
503 irq_node_t *node;
504
505#ifdef DEBUG_MACINTS
506 printk ("%s: irq %d requested for %s\n", __FUNCTION__, irq, devname);
507#endif
508
509 if (irq < VIA1_SOURCE_BASE) {
510 return cpu_request_irq(irq, handler, flags, devname, dev_id);
511 }
512
513 if (irq >= NUM_MAC_SOURCES) {
514 printk ("%s: unknown irq %d requested by %s\n",
515 __FUNCTION__, irq, devname);
516 }
517
518 /* Get a node and stick it onto the right list */
519
520 if (!(node = new_irq_node())) return -ENOMEM;
521
522 node->handler = handler;
523 node->flags = flags;
524 node->dev_id = dev_id;
525 node->devname = devname;
526 node->next = NULL;
527 mac_insert_irq(&mac_irq_list[irq], node);
528
529 /* Now enable the IRQ source */
530
531 mac_enable_irq(irq);
532
533 return 0;
534}
535
536/*
537 * Removes an interrupt service routine from an interrupt source.
538 */
539
540void mac_free_irq(unsigned int irq, void *dev_id)
541{
542#ifdef DEBUG_MACINTS
543 printk ("%s: irq %d freed by %p\n", __FUNCTION__, irq, dev_id);
544#endif
545
546 if (irq < VIA1_SOURCE_BASE) {
547 cpu_free_irq(irq, dev_id);
548 return;
549 }
550
551 if (irq >= NUM_MAC_SOURCES) {
552 printk ("%s: unknown irq %d freed\n",
553 __FUNCTION__, irq);
554 return;
555 }
556
557 mac_delete_irq(&mac_irq_list[irq], dev_id);
558
559 /* If the list for this interrupt is */
560 /* empty then disable the source. */
561
562 if (!mac_irq_list[irq]) {
563 mac_disable_irq(irq);
564 }
565}
566
567/*
568 * Generate a pretty listing for /proc/interrupts
569 *
570 * By the time we're called the autovector interrupt list has already been
571 * generated, so we just need to do the machspec interrupts.
572 *
573 * 990506 (jmt) - rewritten to handle chained machspec interrupt handlers.
574 * Also removed display of num_spurious it is already
575 * displayed for us as autovector irq 0.
576 */
577
578int show_mac_interrupts(struct seq_file *p, void *v)
579{
580 int i;
581 irq_node_t *node;
582 char *base;
583
584 /* Don't do Nubus interrupts in this loop; we do them separately */
585 /* below so that we can print slot numbers instead of IRQ numbers */
586
587 for (i = VIA1_SOURCE_BASE ; i < NUM_MAC_SOURCES ; ++i) {
588
589 /* Nonexistant interrupt or nothing registered; skip it. */
590
591 if ((node = mac_irq_list[i]) == NULL) continue;
592 if (node->flags & IRQ_FLG_STD) continue;
593
594 base = "";
595 switch(IRQ_SRC(i)) {
596 case 1: base = "via1";
597 break;
598 case 2: if (oss_present) {
599 base = "oss";
600 } else {
601 base = "via2";
602 }
603 break;
604 case 3:
605 case 4:
606 case 5:
607 case 6: if (psc_present) {
608 base = "psc";
609 } else if (oss_present) {
610 base = "oss";
611 } else {
612 if (IRQ_SRC(i) == 4) base = "scc";
613 }
614 break;
615 case 7: base = "nbus";
616 break;
617 case 8: base = "bbn";
618 break;
619 }
620 seq_printf(p, "%4s %2d: %10u ", base, i, kstat_cpu(0).irqs[i]);
621
622 do {
623 if (node->flags & IRQ_FLG_FAST) {
624 seq_puts(p, "F ");
625 } else if (node->flags & IRQ_FLG_SLOW) {
626 seq_puts(p, "S ");
627 } else {
628 seq_puts(p, " ");
629 }
630 seq_printf(p, "%s\n", node->devname);
631 if ((node = node->next)) {
632 seq_puts(p, " ");
633 }
634 } while(node);
635
636 } 390 }
637 return 0; 391 return 0;
638} 392}
@@ -676,7 +430,7 @@ irqreturn_t mac_nmi_handler(int irq, void *dev_id, struct pt_regs *fp)
676 while (nmi_hold == 1) 430 while (nmi_hold == 1)
677 udelay(1000); 431 udelay(1000);
678 432
679 if ( console_loglevel >= 8 ) { 433 if (console_loglevel >= 8) {
680#if 0 434#if 0
681 show_state(); 435 show_state();
682 printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp); 436 printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp);
@@ -705,14 +459,16 @@ irqreturn_t mac_nmi_handler(int irq, void *dev_id, struct pt_regs *fp)
705 * done in hardware (only the PSC can do that.) 459 * done in hardware (only the PSC can do that.)
706 */ 460 */
707 461
708static void scc_irq_enable(int irq) { 462static void scc_irq_enable(unsigned int irq)
709 int irq_idx = IRQ_IDX(irq); 463{
464 int irq_idx = IRQ_IDX(irq);
710 465
711 scc_mask |= (1 << irq_idx); 466 scc_mask |= (1 << irq_idx);
712} 467}
713 468
714static void scc_irq_disable(int irq) { 469static void scc_irq_disable(unsigned int irq)
715 int irq_idx = IRQ_IDX(irq); 470{
471 int irq_idx = IRQ_IDX(irq);
716 472
717 scc_mask &= ~(1 << irq_idx); 473 scc_mask &= ~(1 << irq_idx);
718} 474}
@@ -747,6 +503,8 @@ void mac_scc_dispatch(int irq, void *dev_id, struct pt_regs *regs)
747 /* and since they're autovector interrupts they */ 503 /* and since they're autovector interrupts they */
748 /* pretty much kill the system. */ 504 /* pretty much kill the system. */
749 505
750 if (reg & 0x38) mac_do_irq_list(IRQ_SCCA, regs); 506 if (reg & 0x38)
751 if (reg & 0x07) mac_do_irq_list(IRQ_SCCB, regs); 507 m68k_handle_int(IRQ_SCCA, regs);
508 if (reg & 0x07)
509 m68k_handle_int(IRQ_SCCB, regs);
752} 510}