interrupts.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000-2004
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2007 Freescale Semiconductor Inc
  7. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  8. */
  9. #include <common.h>
  10. #include <watchdog.h>
  11. #include <asm/processor.h>
  12. #include <asm/immap.h>
  13. #define NR_IRQS (CONFIG_SYS_NUM_IRQS)
  14. /*
  15. * Interrupt vector functions.
  16. */
  17. struct interrupt_action {
  18. interrupt_handler_t *handler;
  19. void *arg;
  20. };
  21. static struct interrupt_action irq_vecs[NR_IRQS];
  22. static __inline__ unsigned short get_sr (void)
  23. {
  24. unsigned short sr;
  25. asm volatile ("move.w %%sr,%0":"=r" (sr):);
  26. return sr;
  27. }
  28. static __inline__ void set_sr (unsigned short sr)
  29. {
  30. asm volatile ("move.w %0,%%sr"::"r" (sr));
  31. }
  32. /************************************************************************/
  33. /*
  34. * Install and free an interrupt handler
  35. */
  36. void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  37. {
  38. if ((vec < 0) || (vec >= NR_IRQS)) {
  39. printf ("irq_install_handler: wrong interrupt vector %d\n",
  40. vec);
  41. return;
  42. }
  43. irq_vecs[vec].handler = handler;
  44. irq_vecs[vec].arg = arg;
  45. }
  46. void irq_free_handler (int vec)
  47. {
  48. if ((vec < 0) || (vec >= NR_IRQS)) {
  49. return;
  50. }
  51. irq_vecs[vec].handler = NULL;
  52. irq_vecs[vec].arg = NULL;
  53. }
  54. void enable_interrupts (void)
  55. {
  56. unsigned short sr;
  57. sr = get_sr ();
  58. set_sr (sr & ~0x0700);
  59. }
  60. int disable_interrupts (void)
  61. {
  62. unsigned short sr;
  63. sr = get_sr ();
  64. set_sr (sr | 0x0700);
  65. return ((sr & 0x0700) == 0); /* return true, if interrupts were enabled before */
  66. }
  67. void int_handler (struct pt_regs *fp)
  68. {
  69. int vec;
  70. vec = (fp->vector >> 2) & 0xff;
  71. if (vec > 0x40)
  72. vec -= 0x40;
  73. if (irq_vecs[vec].handler != NULL) {
  74. irq_vecs[vec].handler (irq_vecs[vec].arg);
  75. } else {
  76. printf ("\nBogus External Interrupt Vector %d\n", vec);
  77. }
  78. }