ia64/xen-unstable

changeset 9585:5baf152d63ef

We had reports of reboot not working on certain machines (specifically
Compaq/HP notebooks), where Linux already has code to deal with
that. Apparently that code was either deleted during the original port
or got added to Linux after the original port was done. Anyway, this
patch adds the respective Linux code (slightly adjusted) to deal with
the same systems in Xen.

From: Jan Beulich

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Apr 04 15:20:12 2006 +0100 (2006-04-04)
parents 7086a4e96ce0
children 806d04252761
files xen/arch/x86/Makefile xen/arch/x86/domain.c xen/arch/x86/shutdown.c
line diff
     1.1 --- a/xen/arch/x86/Makefile	Tue Apr 04 15:06:38 2006 +0100
     1.2 +++ b/xen/arch/x86/Makefile	Tue Apr 04 15:20:12 2006 +0100
     1.3 @@ -30,6 +30,7 @@ obj-y += nmi.o
     1.4  obj-y += physdev.o
     1.5  obj-y += rwlock.o
     1.6  obj-y += setup.o
     1.7 +obj-y += shutdown.o
     1.8  obj-y += smp.o
     1.9  obj-y += smpboot.o
    1.10  obj-y += string.o
     2.1 --- a/xen/arch/x86/domain.c	Tue Apr 04 15:06:38 2006 +0100
     2.2 +++ b/xen/arch/x86/domain.c	Tue Apr 04 15:20:12 2006 +0100
     2.3 @@ -41,10 +41,6 @@
     2.4  #include <xen/kernel.h>
     2.5  #include <xen/multicall.h>
     2.6  
     2.7 -/* opt_noreboot: If true, machine will need manual reset on error. */
     2.8 -static int opt_noreboot = 0;
     2.9 -boolean_param("noreboot", opt_noreboot);
    2.10 -
    2.11  struct percpu_ctxt {
    2.12      struct vcpu *curr_vcpu;
    2.13      unsigned int dirty_segment_mask;
    2.14 @@ -99,84 +95,6 @@ void startup_cpu_idle_loop(void)
    2.15      reset_stack_and_jump(idle_loop);
    2.16  }
    2.17  
    2.18 -static long no_idt[2];
    2.19 -static int reboot_mode;
    2.20 -
    2.21 -static inline void kb_wait(void)
    2.22 -{
    2.23 -    int i;
    2.24 -
    2.25 -    for ( i = 0; i < 0x10000; i++ )
    2.26 -        if ( (inb_p(0x64) & 0x02) == 0 )
    2.27 -            break;
    2.28 -}
    2.29 -
    2.30 -void __attribute__((noreturn)) __machine_halt(void *unused)
    2.31 -{
    2.32 -    for ( ; ; )
    2.33 -        safe_halt();
    2.34 -}
    2.35 -
    2.36 -void machine_halt(void)
    2.37 -{
    2.38 -    watchdog_disable();
    2.39 -    console_start_sync();
    2.40 -    smp_call_function(__machine_halt, NULL, 1, 0);
    2.41 -    __machine_halt(NULL);
    2.42 -}
    2.43 -
    2.44 -void machine_restart(char * __unused)
    2.45 -{
    2.46 -    int i;
    2.47 -
    2.48 -    if ( opt_noreboot )
    2.49 -    {
    2.50 -        printk("Reboot disabled on cmdline: require manual reset\n");
    2.51 -        machine_halt();
    2.52 -    }
    2.53 -
    2.54 -    watchdog_disable();
    2.55 -    console_start_sync();
    2.56 -
    2.57 -    local_irq_enable();
    2.58 -
    2.59 -    /* Ensure we are the boot CPU. */
    2.60 -    if ( GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid )
    2.61 -    {
    2.62 -        smp_call_function((void *)machine_restart, NULL, 1, 0);
    2.63 -        for ( ; ; )
    2.64 -            safe_halt();
    2.65 -    }
    2.66 -
    2.67 -    /*
    2.68 -     * Stop all CPUs and turn off local APICs and the IO-APIC, so
    2.69 -     * other OSs see a clean IRQ state.
    2.70 -     */
    2.71 -    smp_send_stop();
    2.72 -    disable_IO_APIC();
    2.73 -    hvm_disable();
    2.74 -
    2.75 -    /* Rebooting needs to touch the page at absolute address 0. */
    2.76 -    *((unsigned short *)__va(0x472)) = reboot_mode;
    2.77 -
    2.78 -    for ( ; ; )
    2.79 -    {
    2.80 -        /* Pulse the keyboard reset line. */
    2.81 -        for ( i = 0; i < 100; i++ )
    2.82 -        {
    2.83 -            kb_wait();
    2.84 -            udelay(50);
    2.85 -            outb(0xfe,0x64); /* pulse reset low */
    2.86 -            udelay(50);
    2.87 -        }
    2.88 -
    2.89 -        /* That didn't work - force a triple fault.. */
    2.90 -        __asm__ __volatile__("lidt %0": "=m" (no_idt));
    2.91 -        __asm__ __volatile__("int3");
    2.92 -    }
    2.93 -}
    2.94 -
    2.95 -
    2.96  void dump_pageframe_info(struct domain *d)
    2.97  {
    2.98      struct page_info *page;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xen/arch/x86/shutdown.c	Tue Apr 04 15:20:12 2006 +0100
     3.3 @@ -0,0 +1,342 @@
     3.4 +/******************************************************************************
     3.5 + * arch/x86/shutdown.c
     3.6 + *
     3.7 + * x86-specific shutdown handling.
     3.8 + */
     3.9 +
    3.10 +#include <xen/config.h>
    3.11 +#include <xen/init.h>
    3.12 +#include <xen/lib.h>
    3.13 +#include <xen/sched.h>
    3.14 +#include <xen/smp.h>
    3.15 +#include <xen/delay.h>
    3.16 +#include <xen/dmi.h>
    3.17 +#include <asm/regs.h>
    3.18 +#include <asm/mc146818rtc.h>
    3.19 +#include <asm/system.h>
    3.20 +#include <asm/io.h>
    3.21 +#include <asm/processor.h>
    3.22 +#include <asm/mpspec.h>
    3.23 +#include <xen/irq.h>
    3.24 +#include <xen/console.h>
    3.25 +#include <asm/msr.h>
    3.26 +
    3.27 +/* opt_noreboot: If true, machine will need manual reset on error. */
    3.28 +static int opt_noreboot = 0;
    3.29 +boolean_param("noreboot", opt_noreboot);
    3.30 +
    3.31 +/* reboot_str: comma-separated list of reboot options. */
    3.32 +static char __initdata reboot_str[10] = "";
    3.33 +string_param("reboot", reboot_str);
    3.34 +
    3.35 +static long no_idt[2];
    3.36 +static int reboot_mode;
    3.37 +
    3.38 +static inline void kb_wait(void)
    3.39 +{
    3.40 +    int i;
    3.41 +
    3.42 +    for ( i = 0; i < 0x10000; i++ )
    3.43 +        if ( (inb_p(0x64) & 0x02) == 0 )
    3.44 +            break;
    3.45 +}
    3.46 +
    3.47 +void __attribute__((noreturn)) __machine_halt(void *unused)
    3.48 +{
    3.49 +    for ( ; ; )
    3.50 +        safe_halt();
    3.51 +}
    3.52 +
    3.53 +void machine_halt(void)
    3.54 +{
    3.55 +    watchdog_disable();
    3.56 +    console_start_sync();
    3.57 +    smp_call_function(__machine_halt, NULL, 1, 0);
    3.58 +    __machine_halt(NULL);
    3.59 +}
    3.60 +
    3.61 +#ifdef __i386__
    3.62 +
    3.63 +static int reboot_thru_bios;
    3.64 +
    3.65 +/* The following code and data reboots the machine by switching to real
    3.66 +   mode and jumping to the BIOS reset entry point, as if the CPU has
    3.67 +   really been reset.  The previous version asked the keyboard
    3.68 +   controller to pulse the CPU reset line, which is more thorough, but
    3.69 +   doesn't work with at least one type of 486 motherboard.  It is easy
    3.70 +   to stop this code working; hence the copious comments. */
    3.71 +
    3.72 +static unsigned long long
    3.73 +real_mode_gdt_entries [3] =
    3.74 +{
    3.75 +    0x0000000000000000ULL,      /* Null descriptor */
    3.76 +    0x00009a000000ffffULL,      /* 16-bit real-mode 64k code at 0x00000000 */
    3.77 +    0x000092000100ffffULL       /* 16-bit real-mode 64k data at 0x00000100 */
    3.78 +};
    3.79 +
    3.80 +static const struct
    3.81 +{
    3.82 +    unsigned short       size __attribute__ ((packed));
    3.83 +    unsigned long long * base __attribute__ ((packed));
    3.84 +}
    3.85 +real_mode_gdt = { sizeof (real_mode_gdt_entries) - 1, real_mode_gdt_entries },
    3.86 +real_mode_idt = { 0x3ff, NULL };
    3.87 +
    3.88 +
    3.89 +/* This is 16-bit protected mode code to disable paging and the cache,
    3.90 +   switch to real mode and jump to the BIOS reset code.
    3.91 +
    3.92 +   The instruction that switches to real mode by writing to CR0 must be
    3.93 +   followed immediately by a far jump instruction, which set CS to a
    3.94 +   valid value for real mode, and flushes the prefetch queue to avoid
    3.95 +   running instructions that have already been decoded in protected
    3.96 +   mode.
    3.97 +
    3.98 +   Clears all the flags except ET, especially PG (paging), PE
    3.99 +   (protected-mode enable) and TS (task switch for coprocessor state
   3.100 +   save).  Flushes the TLB after paging has been disabled.  Sets CD and
   3.101 +   NW, to disable the cache on a 486, and invalidates the cache.  This
   3.102 +   is more like the state of a 486 after reset.  I don't know if
   3.103 +   something else should be done for other chips.
   3.104 +
   3.105 +   More could be done here to set up the registers as if a CPU reset had
   3.106 +   occurred; hopefully real BIOSs don't assume much. */
   3.107 +
   3.108 +static const unsigned char real_mode_switch [] =
   3.109 +{
   3.110 +    0x0f, 0x20, 0xc0,                           /*    movl  %cr0,%eax        */
   3.111 +    0x66, 0x83, 0xe0, 0x11,                     /*    andl  $0x00000011,%eax */
   3.112 +    0x66, 0x0d, 0x00, 0x00, 0x00, 0x60,         /*    orl   $0x60000000,%eax */
   3.113 +    0x0f, 0x22, 0xc0,                           /*    movl  %eax,%cr0        */
   3.114 +    0x0f, 0x22, 0xd8,                           /*    movl  %eax,%cr3        */
   3.115 +    0x0f, 0x20, 0xc2,                           /*    movl  %cr0,%edx        */
   3.116 +    0x66, 0x81, 0xe2, 0x00, 0x00, 0x00, 0x60,   /*    andl  $0x60000000,%edx */
   3.117 +    0x74, 0x02,                                 /*    jz    f                */
   3.118 +    0x0f, 0x09,                                 /*    wbinvd                 */
   3.119 +    0x24, 0x10,                                 /* f: andb  $0x10,al         */
   3.120 +    0x0f, 0x22, 0xc0                            /*    movl  %eax,%cr0        */
   3.121 +};
   3.122 +#define MAX_LENGTH 0x40
   3.123 +static const unsigned char jump_to_bios [] =
   3.124 +{
   3.125 +    0xea, 0xf0, 0xff, 0x00, 0xf0                /*    ljmp  $0xf000,$0xfff0  */
   3.126 +};
   3.127 +
   3.128 +/*
   3.129 + * Switch to real mode and then execute the code
   3.130 + * specified by the code and length parameters.
   3.131 + * We assume that length will aways be less that MAX_LENGTH!
   3.132 + */
   3.133 +void machine_real_restart(const unsigned char *code, unsigned length)
   3.134 +{
   3.135 +    local_irq_disable();
   3.136 +
   3.137 +    /* Write zero to CMOS register number 0x0f, which the BIOS POST
   3.138 +       routine will recognize as telling it to do a proper reboot.  (Well
   3.139 +       that's what this book in front of me says -- it may only apply to
   3.140 +       the Phoenix BIOS though, it's not clear).  At the same time,
   3.141 +       disable NMIs by setting the top bit in the CMOS address register,
   3.142 +       as we're about to do peculiar things to the CPU. */
   3.143 +
   3.144 +    spin_lock(&rtc_lock);
   3.145 +    CMOS_WRITE(0x00, 0x8f);
   3.146 +    spin_unlock(&rtc_lock);
   3.147 +
   3.148 +    /* Identity-map virtual address zero. */
   3.149 +
   3.150 +    map_pages_to_xen(0, 0, 1, __PAGE_HYPERVISOR|MAP_SMALL_PAGES);
   3.151 +    set_current(idle_vcpu[0]);
   3.152 +    write_ptbase(idle_vcpu[0]);
   3.153 +
   3.154 +    /* For the switch to real mode, copy some code to low memory.  It has
   3.155 +       to be in the first 64k because it is running in 16-bit mode, and it
   3.156 +       has to have the same physical and virtual address, because it turns
   3.157 +       off paging.  Copy it near the end of the first page, out of the way
   3.158 +       of BIOS variables. */
   3.159 +
   3.160 +    memcpy((void *)(PAGE_SIZE - sizeof(real_mode_switch) - MAX_LENGTH),
   3.161 +           real_mode_switch, sizeof(real_mode_switch));
   3.162 +    memcpy((void *)(PAGE_SIZE - MAX_LENGTH), code, length);
   3.163 +
   3.164 +    /* Set up the IDT for real mode. */
   3.165 +
   3.166 +    __asm__ __volatile__("lidt %0": : "m" (real_mode_idt));
   3.167 +
   3.168 +    /* Set up a GDT from which we can load segment descriptors for real
   3.169 +       mode.  The GDT is not used in real mode; it is just needed here to
   3.170 +       prepare the descriptors. */
   3.171 +
   3.172 +    __asm__ __volatile__("lgdt %0": : "m" (real_mode_gdt));
   3.173 +
   3.174 +    /* Load the data segment registers, and thus the descriptors ready for
   3.175 +       real mode.  The base address of each segment is 0x100, 16 times the
   3.176 +       selector value being loaded here.  This is so that the segment
   3.177 +       registers don't have to be reloaded after switching to real mode:
   3.178 +       the values are consistent for real mode operation already. */
   3.179 +
   3.180 +    __asm__ __volatile__ ("\tmov %0,%%ds\n"
   3.181 +                          "\tmov %0,%%es\n"
   3.182 +                          "\tmov %0,%%fs\n"
   3.183 +                          "\tmov %0,%%gs\n"
   3.184 +                          "\tmov %0,%%ss"
   3.185 +                          :
   3.186 +                          : "r" (0x0010));
   3.187 +
   3.188 +    /* Jump to the 16-bit code that we copied earlier.  It disables paging
   3.189 +       and the cache, switches to real mode, and jumps to the BIOS reset
   3.190 +       entry point. */
   3.191 +
   3.192 +    __asm__ __volatile__ ("ljmp $0x0008,%0"
   3.193 +                          :
   3.194 +                          : "i" ((void *)(PAGE_SIZE -
   3.195 +                                          sizeof(real_mode_switch) -
   3.196 +                                          MAX_LENGTH)));
   3.197 +}
   3.198 +
   3.199 +#else /* __x86_64__ */
   3.200 +
   3.201 +#define machine_real_restart(x, y)
   3.202 +#define reboot_thru_bios 0
   3.203 +
   3.204 +#endif
   3.205 +
   3.206 +void machine_restart(char * __unused)
   3.207 +{
   3.208 +    int i;
   3.209 +
   3.210 +    if ( opt_noreboot )
   3.211 +    {
   3.212 +        printk("Reboot disabled on cmdline: require manual reset\n");
   3.213 +        machine_halt();
   3.214 +    }
   3.215 +
   3.216 +    watchdog_disable();
   3.217 +    console_start_sync();
   3.218 +
   3.219 +    local_irq_enable();
   3.220 +
   3.221 +    /* Ensure we are the boot CPU. */
   3.222 +    if ( GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid )
   3.223 +    {
   3.224 +        smp_call_function((void *)machine_restart, NULL, 1, 0);
   3.225 +        for ( ; ; )
   3.226 +            safe_halt();
   3.227 +    }
   3.228 +
   3.229 +    /*
   3.230 +     * Stop all CPUs and turn off local APICs and the IO-APIC, so
   3.231 +     * other OSs see a clean IRQ state.
   3.232 +     */
   3.233 +    smp_send_stop();
   3.234 +    disable_IO_APIC();
   3.235 +    hvm_disable();
   3.236 +
   3.237 +    /* Rebooting needs to touch the page at absolute address 0. */
   3.238 +    *((unsigned short *)__va(0x472)) = reboot_mode;
   3.239 +
   3.240 +    if (reboot_thru_bios <= 0)
   3.241 +    {
   3.242 +        for ( ; ; )
   3.243 +        {
   3.244 +            /* Pulse the keyboard reset line. */
   3.245 +            for ( i = 0; i < 100; i++ )
   3.246 +            {
   3.247 +                kb_wait();
   3.248 +                udelay(50);
   3.249 +                outb(0xfe,0x64); /* pulse reset low */
   3.250 +                udelay(50);
   3.251 +            }
   3.252 +
   3.253 +            /* That didn't work - force a triple fault.. */
   3.254 +            __asm__ __volatile__("lidt %0": "=m" (no_idt));
   3.255 +            __asm__ __volatile__("int3");
   3.256 +        }
   3.257 +    }
   3.258 +    machine_real_restart(jump_to_bios, sizeof(jump_to_bios));
   3.259 +}
   3.260 +
   3.261 +#ifndef reboot_thru_bios
   3.262 +static int __init set_bios_reboot(struct dmi_system_id *d)
   3.263 +{
   3.264 +    if ( !reboot_thru_bios )
   3.265 +    {
   3.266 +        reboot_thru_bios = 1;
   3.267 +        printk("%s series board detected. "
   3.268 +               "Selecting BIOS-method for reboots.\n", d->ident);
   3.269 +    }
   3.270 +    return 0;
   3.271 +}
   3.272 +
   3.273 +static struct dmi_system_id __initdata reboot_dmi_table[] = {
   3.274 +    {    /* Handle problems with rebooting on Dell 1300's */
   3.275 +        .callback = set_bios_reboot,
   3.276 +        .ident = "Dell PowerEdge 1300",
   3.277 +        .matches = {
   3.278 +            DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
   3.279 +            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"),
   3.280 +        },
   3.281 +    },
   3.282 +    {    /* Handle problems with rebooting on Dell 300's */
   3.283 +        .callback = set_bios_reboot,
   3.284 +        .ident = "Dell PowerEdge 300",
   3.285 +        .matches = {
   3.286 +            DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
   3.287 +            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"),
   3.288 +        },
   3.289 +    },
   3.290 +    {    /* Handle problems with rebooting on Dell 2400's */
   3.291 +        .callback = set_bios_reboot,
   3.292 +        .ident = "Dell PowerEdge 2400",
   3.293 +        .matches = {
   3.294 +            DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
   3.295 +            DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"),
   3.296 +        },
   3.297 +    },
   3.298 +    {    /* Handle problems with rebooting on HP laptops */
   3.299 +        .callback = set_bios_reboot,
   3.300 +        .ident = "HP Compaq Laptop",
   3.301 +        .matches = {
   3.302 +            DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
   3.303 +            DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
   3.304 +        },
   3.305 +    },
   3.306 +    { }
   3.307 +};
   3.308 +#endif
   3.309 +
   3.310 +static int __init reboot_init(void)
   3.311 +{
   3.312 +    const char *str;
   3.313 +
   3.314 +    for ( str = reboot_str; *str != '\0'; str++ )
   3.315 +    {
   3.316 +        switch ( *str )
   3.317 +        {
   3.318 +        case 'n': /* no reboot */
   3.319 +            opt_noreboot = 1;
   3.320 +            break;
   3.321 +        case 'w': /* "warm" reboot (no memory testing etc) */
   3.322 +            reboot_mode = 0x1234;
   3.323 +            break;
   3.324 +        case 'c': /* "cold" reboot (with memory testing etc) */
   3.325 +            reboot_mode = 0x0;
   3.326 +            break;
   3.327 +#ifndef reboot_thru_bios
   3.328 +        case 'b': /* "bios" reboot by jumping through the BIOS */
   3.329 +            reboot_thru_bios = 1;
   3.330 +            break;
   3.331 +        case 'h': /* "hard" reboot by toggling RESET and/or crashing the CPU */
   3.332 +            reboot_thru_bios = -1;
   3.333 +            break;
   3.334 +#endif
   3.335 +        }
   3.336 +        if ( (str = strchr(str, ',')) == NULL )
   3.337 +            break;
   3.338 +    }
   3.339 +
   3.340 +#ifndef reboot_thru_bios
   3.341 +    dmi_check_system(reboot_dmi_table);
   3.342 +#endif
   3.343 +    return 0;
   3.344 +}
   3.345 +__initcall(reboot_init);