interrupts.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2003
  6. * Gleb Natapov <gnatapov@mrv.com>
  7. *
  8. * (C) Copyright 2007
  9. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <asm/processor.h>
  31. #include <asm/irq.h>
  32. /* Implemented by SPARC CPUs */
  33. extern int interrupt_init_cpu(void);
  34. extern void timer_interrupt_cpu(void *arg);
  35. extern int timer_interrupt_init_cpu(void);
  36. int intLock(void)
  37. {
  38. unsigned int pil;
  39. pil = get_pil();
  40. /* set PIL to 15 ==> no pending interrupts will interrupt CPU */
  41. set_pil(15);
  42. return pil;
  43. }
  44. void intUnlock(int oldLevel)
  45. {
  46. set_pil(oldLevel);
  47. }
  48. void enable_interrupts(void)
  49. {
  50. set_pil(0); /* enable all interrupts */
  51. }
  52. int disable_interrupts(void)
  53. {
  54. return intLock();
  55. }
  56. int interrupt_init(void)
  57. {
  58. int ret;
  59. /* call cpu specific function from $(CPU)/interrupts.c */
  60. ret = interrupt_init_cpu();
  61. /* enable global interrupts */
  62. enable_interrupts();
  63. return ret;
  64. }
  65. /* timer interrupt/overflow counter */
  66. static volatile ulong timestamp = 0;
  67. /* regs can not be used here! regs is actually the pointer given in
  68. * irq_install_handler
  69. */
  70. void timer_interrupt(struct pt_regs *regs)
  71. {
  72. /* call cpu specific function from $(CPU)/interrupts.c */
  73. timer_interrupt_cpu((void *)regs);
  74. timestamp++;
  75. }
  76. void reset_timer(void)
  77. {
  78. timestamp = 0;
  79. }
  80. ulong get_timer(ulong base)
  81. {
  82. return (timestamp - base);
  83. }
  84. void set_timer(ulong t)
  85. {
  86. timestamp = t;
  87. }
  88. void timer_interrupt_init(void)
  89. {
  90. int irq;
  91. reset_timer();
  92. irq = timer_interrupt_init_cpu();
  93. if (irq < 0) {
  94. /* cpu specific code handled the interrupt registration it self */
  95. return;
  96. }
  97. /* register interrupt handler for timer */
  98. irq_install_handler(irq, (void (*)(void *))timer_interrupt, NULL);
  99. }