time_32.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 1991,1992,1995 Linus Torvalds
  3. * Copyright (c) 1994 Alan Modra
  4. * Copyright (c) 1995 Markus Kuhn
  5. * Copyright (c) 1996 Ingo Molnar
  6. * Copyright (c) 1998 Andrea Arcangeli
  7. * Copyright (c) 2002,2006 Vojtech Pavlik
  8. * Copyright (c) 2003 Andi Kleen
  9. *
  10. */
  11. #include <linux/clockchips.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/time.h>
  14. #include <linux/mca.h>
  15. #include <asm/vsyscall.h>
  16. #include <asm/x86_init.h>
  17. #include <asm/i8259.h>
  18. #include <asm/i8253.h>
  19. #include <asm/timer.h>
  20. #include <asm/hpet.h>
  21. #include <asm/time.h>
  22. #include <asm/nmi.h>
  23. #if defined(CONFIG_X86_32) && defined(CONFIG_X86_IO_APIC)
  24. int timer_ack;
  25. #endif
  26. unsigned long profile_pc(struct pt_regs *regs)
  27. {
  28. unsigned long pc = instruction_pointer(regs);
  29. #ifdef CONFIG_SMP
  30. if (!user_mode_vm(regs) && in_lock_functions(pc)) {
  31. #ifdef CONFIG_FRAME_POINTER
  32. return *(unsigned long *)(regs->bp + sizeof(long));
  33. #else
  34. unsigned long *sp = (unsigned long *)&regs->sp;
  35. /* Return address is either directly at stack pointer
  36. or above a saved flags. Eflags has bits 22-31 zero,
  37. kernel addresses don't. */
  38. if (sp[0] >> 22)
  39. return sp[0];
  40. if (sp[1] >> 22)
  41. return sp[1];
  42. #endif
  43. }
  44. #endif
  45. return pc;
  46. }
  47. EXPORT_SYMBOL(profile_pc);
  48. /*
  49. * This is the same as the above, except we _also_ save the current
  50. * Time Stamp Counter value at the time of the timer interrupt, so that
  51. * we later on can estimate the time of day more exactly.
  52. */
  53. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  54. {
  55. /* Keep nmi watchdog up to date */
  56. inc_irq_stat(irq0_irqs);
  57. /* Optimized out for !IO_APIC and x86_64 */
  58. if (timer_ack) {
  59. /*
  60. * Subtle, when I/O APICs are used we have to ack timer IRQ
  61. * manually to deassert NMI lines for the watchdog if run
  62. * on an 82489DX-based system.
  63. */
  64. spin_lock(&i8259A_lock);
  65. outb(0x0c, PIC_MASTER_OCW3);
  66. /* Ack the IRQ; AEOI will end it automatically. */
  67. inb(PIC_MASTER_POLL);
  68. spin_unlock(&i8259A_lock);
  69. }
  70. global_clock_event->event_handler(global_clock_event);
  71. #ifdef CONFIG_MCA
  72. if (MCA_bus) {
  73. /* The PS/2 uses level-triggered interrupts. You can't
  74. turn them off, nor would you want to (any attempt to
  75. enable edge-triggered interrupts usually gets intercepted by a
  76. special hardware circuit). Hence we have to acknowledge
  77. the timer interrupt. Through some incredibly stupid
  78. design idea, the reset for IRQ 0 is done by setting the
  79. high bit of the PPI port B (0x61). Note that some PS/2s,
  80. notably the 55SX, work fine if this is removed. */
  81. u8 irq_v = inb_p(0x61); /* read the current state */
  82. outb_p(irq_v | 0x80, 0x61); /* reset the IRQ */
  83. }
  84. #endif
  85. return IRQ_HANDLED;
  86. }
  87. static struct irqaction irq0 = {
  88. .handler = timer_interrupt,
  89. .flags = IRQF_DISABLED | IRQF_NOBALANCING | IRQF_IRQPOLL | IRQF_TIMER,
  90. .name = "timer"
  91. };
  92. void __init setup_default_timer_irq(void)
  93. {
  94. irq0.mask = cpumask_of_cpu(0);
  95. setup_irq(0, &irq0);
  96. }
  97. /* Default timer init function */
  98. void __init hpet_time_init(void)
  99. {
  100. if (!hpet_enable())
  101. setup_pit_timer();
  102. setup_default_timer_irq();
  103. }
  104. static void x86_late_time_init(void)
  105. {
  106. x86_init.timers.timer_init();
  107. }
  108. /*
  109. * Initialize TSC and delay the periodic timer init to
  110. * late x86_late_time_init() so ioremap works.
  111. */
  112. void __init time_init(void)
  113. {
  114. tsc_init();
  115. late_time_init = x86_late_time_init;
  116. }