xcp-1.6-updates/xen-4.1.hg

changeset 23283:494aa5ecd2e1

x86/hpet: disable before reboot or kexec

Linux up to now is not smart enough to properly clear the HPET when it
boots, which is particularly a problem when a kdump attempt from
running under Xen is being made. Linux itself added code to work
around
this to its shutdown paths quite some time ago, so let's do something
similar in Xen: Save the configuration register settings during boot,
and restore them during shutdown. This should cover the majority of
cases where the secondary kernel might not come up because timer
interrupts don't work.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 25101:f06ff3dfde08
xen-unstable date: Tue Mar 27 15:20:23 2012 +0200
author Jan Beulich <jbeulich@suse.com>
date Tue Apr 17 08:35:09 2012 +0100 (2012-04-17)
parents 182633356cd4
children f5f1e6ef9782
files xen/arch/x86/crash.c xen/arch/x86/hpet.c xen/arch/x86/smp.c xen/include/asm-x86/hpet.h
line diff
     1.1 --- a/xen/arch/x86/crash.c	Tue Apr 17 08:34:28 2012 +0100
     1.2 +++ b/xen/arch/x86/crash.c	Tue Apr 17 08:35:09 2012 +0100
     1.3 @@ -94,6 +94,7 @@ static void nmi_shootdown_cpus(void)
     1.4      x2apic_enabled = (current_local_apic_mode() == APIC_MODE_X2APIC);
     1.5  
     1.6      disable_IO_APIC();
     1.7 +    hpet_disable();
     1.8  }
     1.9  
    1.10  void machine_crash_shutdown(void)
     2.1 --- a/xen/arch/x86/hpet.c	Tue Apr 17 08:34:28 2012 +0100
     2.2 +++ b/xen/arch/x86/hpet.c	Tue Apr 17 08:35:09 2012 +0100
     2.3 @@ -744,12 +744,14 @@ int hpet_legacy_irq_tick(void)
     2.4      return 1;
     2.5  }
     2.6  
     2.7 +static u32 *hpet_boot_cfg;
     2.8 +
     2.9  u64 hpet_setup(void)
    2.10  {
    2.11      static u64 hpet_rate;
    2.12      static u32 system_reset_latch;
    2.13      u32 hpet_id, hpet_period, cfg;
    2.14 -    int i;
    2.15 +    unsigned int i, last;
    2.16  
    2.17      if ( system_reset_latch == system_reset_counter )
    2.18          return hpet_rate;
    2.19 @@ -775,13 +777,20 @@ u64 hpet_setup(void)
    2.20          return 0;
    2.21      }
    2.22  
    2.23 +    last = (hpet_id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT;
    2.24 +    hpet_boot_cfg = xmalloc_array(u32, 2 + last);
    2.25 +
    2.26      cfg = hpet_read32(HPET_CFG);
    2.27 +    if ( hpet_boot_cfg )
    2.28 +        *hpet_boot_cfg = cfg;
    2.29      cfg &= ~(HPET_CFG_ENABLE | HPET_CFG_LEGACY);
    2.30      hpet_write32(cfg, HPET_CFG);
    2.31  
    2.32 -    for ( i = 0; i <= ((hpet_id >> 8) & 31); i++ )
    2.33 +    for ( i = 0; i <= last; ++i )
    2.34      {
    2.35          cfg = hpet_read32(HPET_Tn_CFG(i));
    2.36 +        if ( hpet_boot_cfg )
    2.37 +            hpet_boot_cfg[i + 1] = cfg;
    2.38          cfg &= ~HPET_TN_ENABLE;
    2.39          hpet_write32(cfg, HPET_Tn_CFG(i));
    2.40      }
    2.41 @@ -795,3 +804,21 @@ u64 hpet_setup(void)
    2.42  
    2.43      return hpet_rate;
    2.44  }
    2.45 +
    2.46 +void hpet_disable(void)
    2.47 +{
    2.48 +    unsigned int i;
    2.49 +    u32 id;
    2.50 +
    2.51 +    if ( !hpet_boot_cfg )
    2.52 +        return;
    2.53 +
    2.54 +    hpet_write32(*hpet_boot_cfg & ~HPET_CFG_ENABLE, HPET_CFG);
    2.55 +
    2.56 +    id = hpet_read32(HPET_ID);
    2.57 +    for ( i = 0; i <= ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT); ++i )
    2.58 +        hpet_write32(hpet_boot_cfg[i + 1], HPET_Tn_CFG(i));
    2.59 +
    2.60 +    if ( *hpet_boot_cfg & HPET_CFG_ENABLE )
    2.61 +        hpet_write32(*hpet_boot_cfg, HPET_CFG);
    2.62 +}
     3.1 --- a/xen/arch/x86/smp.c	Tue Apr 17 08:34:28 2012 +0100
     3.2 +++ b/xen/arch/x86/smp.c	Tue Apr 17 08:35:09 2012 +0100
     3.3 @@ -19,6 +19,7 @@
     3.4  #include <asm/mc146818rtc.h>
     3.5  #include <asm/flushtlb.h>
     3.6  #include <asm/hardirq.h>
     3.7 +#include <asm/hpet.h>
     3.8  #include <asm/hvm/support.h>
     3.9  #include <mach_apic.h>
    3.10  
    3.11 @@ -372,6 +373,7 @@ void smp_send_stop(void)
    3.12      local_irq_disable();
    3.13      __stop_this_cpu();
    3.14      disable_IO_APIC();
    3.15 +    hpet_disable();
    3.16      local_irq_enable();
    3.17  }
    3.18  
     4.1 --- a/xen/include/asm-x86/hpet.h	Tue Apr 17 08:34:28 2012 +0100
     4.2 +++ b/xen/include/asm-x86/hpet.h	Tue Apr 17 08:35:09 2012 +0100
     4.3 @@ -67,6 +67,11 @@ extern unsigned long hpet_address;
     4.4  u64 hpet_setup(void);
     4.5  
     4.6  /*
     4.7 + * Disable HPET hardware: restore it to boot time state.
     4.8 + */
     4.9 +void hpet_disable(void);
    4.10 +
    4.11 +/*
    4.12   * Callback from legacy timer (PIT channel 0) IRQ handler.
    4.13   * Returns 1 if tick originated from HPET; else 0.
    4.14   */