interrupts.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * Rob Taylor, Flying Pig Systems. robt@flyingpig.com
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <mpc824x.h>
  26. #include <asm/processor.h>
  27. #include <asm/pci_io.h>
  28. #include <commproc.h>
  29. #include "drivers/epic.h"
  30. /****************************************************************************/
  31. unsigned decrementer_count; /* count val for 1e6/HZ microseconds */
  32. static __inline__ unsigned long get_msr (void)
  33. {
  34. unsigned long msr;
  35. asm volatile ("mfmsr %0":"=r" (msr):);
  36. return msr;
  37. }
  38. static __inline__ void set_msr (unsigned long msr)
  39. {
  40. asm volatile ("mtmsr %0"::"r" (msr));
  41. }
  42. static __inline__ unsigned long get_dec (void)
  43. {
  44. unsigned long val;
  45. asm volatile ("mfdec %0":"=r" (val):);
  46. return val;
  47. }
  48. static __inline__ void set_dec (unsigned long val)
  49. {
  50. asm volatile ("mtdec %0"::"r" (val));
  51. }
  52. void enable_interrupts (void)
  53. {
  54. set_msr (get_msr () | MSR_EE);
  55. }
  56. /* returns flag if MSR_EE was set before */
  57. int disable_interrupts (void)
  58. {
  59. ulong msr = get_msr ();
  60. set_msr (msr & ~MSR_EE);
  61. return ((msr & MSR_EE) != 0);
  62. }
  63. /****************************************************************************/
  64. int interrupt_init (void)
  65. {
  66. decrementer_count = (get_bus_freq (0) / 4) / CFG_HZ;
  67. /*
  68. * It's all broken at the moment and I currently don't need
  69. * interrupts. If you want to fix it, have a look at the epic
  70. * drivers in dink32 v12. They do everthing and Motorola said
  71. * I could use the dink source in this project as long as
  72. * copyright notices remain intact.
  73. */
  74. epicInit (EPIC_DIRECT_IRQ, 0);
  75. /* EPIC won't generate INT unless Current Task Pri < 15 */
  76. epicCurTaskPrioSet(0);
  77. set_dec (decrementer_count);
  78. set_msr (get_msr () | MSR_EE);
  79. return (0);
  80. }
  81. /****************************************************************************/
  82. /*
  83. * Handle external interrupts
  84. */
  85. void external_interrupt (struct pt_regs *regs)
  86. {
  87. register unsigned long temp;
  88. pci_readl (CFG_EUMB_ADDR + EPIC_PROC_INT_ACK_REG, temp);
  89. sync (); /* i'm not convinced this is needed, but dink source has it */
  90. temp &= 0xff; /*get vector */
  91. /*TODO: handle them -... */
  92. epicEOI ();
  93. }
  94. /****************************************************************************/
  95. /*
  96. * blank int handlers.
  97. */
  98. void
  99. irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  100. {
  101. }
  102. void irq_free_handler (int vec)
  103. {
  104. }
  105. /*TODO: some handlers for winbond and 87308 interrupts
  106. and what about generic pci inteerupts?
  107. vga?
  108. */
  109. volatile ulong timestamp = 0;
  110. void timer_interrupt (struct pt_regs *regs)
  111. {
  112. /* Restore Decrementer Count */
  113. set_dec (decrementer_count);
  114. timestamp++;
  115. #if defined(CONFIG_WATCHDOG)
  116. if ((timestamp % (CFG_HZ / 2)) == 0) {
  117. #if defined(CONFIG_OXC)
  118. {
  119. extern void oxc_wdt_reset (void);
  120. oxc_wdt_reset ();
  121. }
  122. #endif
  123. }
  124. #endif /* CONFIG_WATCHDOG */
  125. #if defined(CONFIG_SHOW_ACTIVITY) && defined(CONFIG_OXC)
  126. if ((timestamp % (CFG_HZ / 10)) == 0) {
  127. {
  128. extern void oxc_toggle_activeled (void);
  129. oxc_toggle_activeled ();
  130. }
  131. }
  132. #endif
  133. }
  134. void reset_timer (void)
  135. {
  136. timestamp = 0;
  137. }
  138. ulong get_timer (ulong base)
  139. {
  140. return (timestamp - base);
  141. }
  142. void set_timer (ulong t)
  143. {
  144. timestamp = t;
  145. }