interrupts.c 1.8 KB

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