interrupts.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <asm/processor.h>
  15. #include <asm/irq.h>
  16. /* Implemented by SPARC CPUs */
  17. extern int interrupt_init_cpu(void);
  18. extern void timer_interrupt_cpu(void *arg);
  19. extern int timer_interrupt_init_cpu(void);
  20. int intLock(void)
  21. {
  22. unsigned int pil;
  23. pil = get_pil();
  24. /* set PIL to 15 ==> no pending interrupts will interrupt CPU */
  25. set_pil(15);
  26. return pil;
  27. }
  28. void intUnlock(int oldLevel)
  29. {
  30. set_pil(oldLevel);
  31. }
  32. void enable_interrupts(void)
  33. {
  34. set_pil(0); /* enable all interrupts */
  35. }
  36. int disable_interrupts(void)
  37. {
  38. return intLock();
  39. }
  40. int interrupt_init(void)
  41. {
  42. int ret;
  43. /* call cpu specific function from $(CPU)/interrupts.c */
  44. ret = interrupt_init_cpu();
  45. /* enable global interrupts */
  46. enable_interrupts();
  47. return ret;
  48. }
  49. /* timer interrupt/overflow counter */
  50. static volatile ulong timestamp = 0;
  51. /* regs can not be used here! regs is actually the pointer given in
  52. * irq_install_handler
  53. */
  54. void timer_interrupt(struct pt_regs *regs)
  55. {
  56. /* call cpu specific function from $(CPU)/interrupts.c */
  57. timer_interrupt_cpu((void *)regs);
  58. timestamp++;
  59. }
  60. ulong get_timer(ulong base)
  61. {
  62. return (timestamp - base);
  63. }
  64. void timer_interrupt_init(void)
  65. {
  66. int irq;
  67. timestamp = 0;
  68. irq = timer_interrupt_init_cpu();
  69. if (irq < 0) {
  70. /* cpu specific code handled the interrupt registration it self */
  71. return;
  72. }
  73. /* register interrupt handler for timer */
  74. irq_install_handler(irq, (void (*)(void *))timer_interrupt, NULL);
  75. }