*/
 DEFINE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid, BAD_APICID);
 
-/*
- * Knob to control our willingness to enable the local APIC.
- *
- * +1=force-enable
- */
-static int force_enable_local_apic __initdata;
-/*
- * APIC command line parameters
- */
-static int __init parse_lapic(char *arg)
-{
-       force_enable_local_apic = 1;
-       return 0;
-}
-early_param("lapic", parse_lapic);
 /* Local APIC was disabled by the BIOS and enabled by the kernel */
 static int enabled_via_apicbase;
 
 }
 #endif
 
+/*
+ * Knob to control our willingness to enable the local APIC.
+ *
+ * +1=force-enable
+ */
+static int force_enable_local_apic __initdata;
+/*
+ * APIC command line parameters
+ */
+static int __init parse_lapic(char *arg)
+{
+       if (config_enabled(CONFIG_X86_32) && !arg)
+               force_enable_local_apic = 1;
+       else if (!strncmp(arg, "notscdeadline", 13))
+               setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
+       return 0;
+}
+early_param("lapic", parse_lapic);
+
 #ifdef CONFIG_X86_64
 static int apic_calibrate_pmtmr __initdata;
 static __init int setup_apicpmtimer(char *s)
 
 /* Clock divisor */
 #define APIC_DIVISOR 16
+#define TSC_DIVISOR  32
 
 /*
  * This function sets up the local APIC timer, with a timeout of
        lvtt_value = LOCAL_TIMER_VECTOR;
        if (!oneshot)
                lvtt_value |= APIC_LVT_TIMER_PERIODIC;
+       else if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER))
+               lvtt_value |= APIC_LVT_TIMER_TSCDEADLINE;
+
        if (!lapic_is_integrated())
                lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
 
 
        apic_write(APIC_LVTT, lvtt_value);
 
+       if (lvtt_value & APIC_LVT_TIMER_TSCDEADLINE) {
+               printk_once(KERN_DEBUG "TSC deadline timer enabled\n");
+               return;
+       }
+
        /*
         * Divide PICLK by 16
         */
        return 0;
 }
 
+static int lapic_next_deadline(unsigned long delta,
+                              struct clock_event_device *evt)
+{
+       u64 tsc;
+
+       rdtscll(tsc);
+       wrmsrl(MSR_IA32_TSC_DEADLINE, tsc + (((u64) delta) * TSC_DIVISOR));
+       return 0;
+}
+
 /*
  * Setup the lapic timer in periodic or oneshot mode
  */
        memcpy(levt, &lapic_clockevent, sizeof(*levt));
        levt->cpumask = cpumask_of(smp_processor_id());
 
-       clockevents_register_device(levt);
+       if (this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) {
+               levt->features &= ~(CLOCK_EVT_FEAT_PERIODIC |
+                                   CLOCK_EVT_FEAT_DUMMY);
+               levt->set_next_event = lapic_next_deadline;
+               clockevents_config_and_register(levt,
+                                               (tsc_khz / TSC_DIVISOR) * 1000,
+                                               0xF, ~0UL);
+       } else
+               clockevents_register_device(levt);
 }
 
 /*
         * in the clockevent structure and return.
         */
 
-       if (lapic_timer_frequency) {
+       if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) {
+               return 0;
+       } else if (lapic_timer_frequency) {
                apic_printk(APIC_VERBOSE, "lapic timer already calibrated %d\n",
                                lapic_timer_frequency);
                lapic_clockevent.mult = div_sc(lapic_timer_frequency/APIC_DIVISOR,
                return 0;
        }
 
+       apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
+                   "calibrating APIC timer ...\n");
+
        local_irq_disable();
 
        /* Replace the global interrupt handler */
                return;
        }
 
-       apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
-                   "calibrating APIC timer ...\n");
-
        if (calibrate_APIC_clock()) {
                /* No broadcast on UP ! */
                if (num_possible_cpus() > 1)