blob: 186abc577b2bf599d448e132b7b9115276f979b4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Thomas Gleixnerdd3e6e82009-08-20 15:35:23 +02002 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
Thomas Gleixnerecce8502009-08-20 15:28:50 +020012#include <linux/clockchips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/interrupt.h>
14#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/mca.h>
16
Thomas Gleixnerdd3e6e82009-08-20 15:35:23 +020017#include <asm/vsyscall.h>
18#include <asm/x86_init.h>
Thomas Gleixnerecce8502009-08-20 15:28:50 +020019#include <asm/i8259.h>
20#include <asm/i8253.h>
Thomas Gleixnerdd3e6e82009-08-20 15:35:23 +020021#include <asm/timer.h>
22#include <asm/hpet.h>
23#include <asm/time.h>
24#include <asm/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Thomas Gleixner64fcbac2009-08-20 15:54:21 +020026#if defined(CONFIG_X86_32) && defined(CONFIG_X86_IO_APIC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027int timer_ack;
Thomas Gleixner64fcbac2009-08-20 15:54:21 +020028#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Thomas Gleixner454ede72009-08-20 16:07:40 +020030#ifdef CONFIG_X86_64
31volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
32#endif
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034unsigned long profile_pc(struct pt_regs *regs)
35{
36 unsigned long pc = instruction_pointer(regs);
37
Andi Kleen0cb91a22006-09-26 10:52:28 +020038#ifdef CONFIG_SMP
Glauber Costa2c44e662008-07-11 13:48:07 -030039 if (!user_mode_vm(regs) && in_lock_functions(pc)) {
Andi Kleen0cb91a22006-09-26 10:52:28 +020040#ifdef CONFIG_FRAME_POINTER
Glauber Costa2c460d02008-07-11 16:06:40 -030041 return *(unsigned long *)(regs->bp + sizeof(long));
Andi Kleen0cb91a22006-09-26 10:52:28 +020042#else
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010043 unsigned long *sp = (unsigned long *)&regs->sp;
Zachary Amsden7b355202007-02-13 13:26:21 +010044
Andi Kleen0cb91a22006-09-26 10:52:28 +020045 /* Return address is either directly at stack pointer
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010046 or above a saved flags. Eflags has bits 22-31 zero,
Andi Kleen0cb91a22006-09-26 10:52:28 +020047 kernel addresses don't. */
Thomas Gleixnerfe599f92008-01-30 13:30:26 +010048 if (sp[0] >> 22)
Andi Kleen0cb91a22006-09-26 10:52:28 +020049 return sp[0];
50 if (sp[1] >> 22)
51 return sp[1];
52#endif
53 }
54#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return pc;
56}
57EXPORT_SYMBOL(profile_pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/*
Thomas Gleixner454ede72009-08-20 16:07:40 +020060 * Default timer interrupt handler for PIT/HPET
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
Thomas Gleixner845b3942009-08-19 15:37:03 +020062static irqreturn_t timer_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Thomas Gleixner3c9aea42007-10-12 23:04:06 +020064 /* Keep nmi watchdog up to date */
Hiroshi Shimamoto8ae93662008-12-12 15:52:26 -080065 inc_irq_stat(irq0_irqs);
Thomas Gleixner3c9aea42007-10-12 23:04:06 +020066
Thomas Gleixner64fcbac2009-08-20 15:54:21 +020067 /* Optimized out for !IO_APIC and x86_64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 if (timer_ack) {
69 /*
70 * Subtle, when I/O APICs are used we have to ack timer IRQ
Maciej W. Rozyckid11d5792008-05-21 22:09:11 +010071 * manually to deassert NMI lines for the watchdog if run
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * on an 82489DX-based system.
73 */
74 spin_lock(&i8259A_lock);
75 outb(0x0c, PIC_MASTER_OCW3);
76 /* Ack the IRQ; AEOI will end it automatically. */
77 inb(PIC_MASTER_POLL);
78 spin_unlock(&i8259A_lock);
79 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Thomas Gleixnerecce8502009-08-20 15:28:50 +020081 global_clock_event->event_handler(global_clock_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Thomas Gleixner0be69392009-08-20 15:59:35 +020083 /* MCA bus quirk: Acknowledge irq0 by setting bit 7 in port 0x61 */
84 if (MCA_bus)
85 outb_p(inb_p(0x61)| 0x80, 0x61);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return IRQ_HANDLED;
88}
89
Thomas Gleixner845b3942009-08-19 15:37:03 +020090static struct irqaction irq0 = {
91 .handler = timer_interrupt,
92 .flags = IRQF_DISABLED | IRQF_NOBALANCING | IRQF_IRQPOLL | IRQF_TIMER,
93 .name = "timer"
94};
95
96void __init setup_default_timer_irq(void)
97{
98 irq0.mask = cpumask_of_cpu(0);
99 setup_irq(0, &irq0);
100}
101
102/* Default timer init function */
Zachary Amsdene30fab32007-03-05 00:30:39 -0800103void __init hpet_time_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800105 if (!hpet_enable())
106 setup_pit_timer();
Thomas Gleixner845b3942009-08-19 15:37:03 +0200107 setup_default_timer_irq();
108}
109
110static void x86_late_time_init(void)
111{
112 x86_init.timers.timer_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Zachary Amsdene30fab32007-03-05 00:30:39 -0800115/*
Thomas Gleixner845b3942009-08-19 15:37:03 +0200116 * Initialize TSC and delay the periodic timer init to
117 * late x86_late_time_init() so ioremap works.
Zachary Amsdene30fab32007-03-05 00:30:39 -0800118 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119void __init time_init(void)
120{
john stultz6bb74df2007-03-05 00:30:50 -0800121 tsc_init();
Thomas Gleixner845b3942009-08-19 15:37:03 +0200122 late_time_init = x86_late_time_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}