Skip to content

Commit

Permalink
Merge branch 'x86-reboot-for-linus' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/tip/tip

Pull x86/reboot changes from Ingo Molnar:
 "Now that the revampted x86 real-mode trampoline code is upstream and
  seems to be working well, we can extend the 64-bit reboot code to be
  as capable as the 32-bit one."

* 'x86-reboot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86-64, reboot: Be more paranoid in 64-bit reboot=bios
  x86, reboot: Drop redundant write of reboot_mode
  x86-64, reboot: Allow reboot=bios and reboot-cpu override on x86-64
  • Loading branch information
Linus Torvalds committed Jul 22, 2012
2 parents bd3e57f + 9751d76 commit d5d96ed
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 46 deletions.
2 changes: 0 additions & 2 deletions arch/x86/include/asm/emergency-restart.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
enum reboot_type {
BOOT_TRIPLE = 't',
BOOT_KBD = 'k',
#ifdef CONFIG_X86_32
BOOT_BIOS = 'b',
#endif
BOOT_ACPI = 'a',
BOOT_EFI = 'e',
BOOT_CF9 = 'p',
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/include/asm/realmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ struct real_mode_header {
u32 wakeup_header;
#endif
/* APM/BIOS reboot */
#ifdef CONFIG_X86_32
u32 machine_real_restart_asm;
#ifdef CONFIG_X86_64
u32 machine_real_restart_seg;
#endif
};

Expand Down
4 changes: 2 additions & 2 deletions arch/x86/include/asm/reboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ extern struct machine_ops machine_ops;

void native_machine_crash_shutdown(struct pt_regs *regs);
void native_machine_shutdown(void);
void machine_real_restart(unsigned int type);
/* These must match dispatch_table in reboot_32.S */
void __noreturn machine_real_restart(unsigned int type);
/* These must match dispatch in arch/x86/realmore/rm/reboot.S */
#define MRR_BIOS 0
#define MRR_APM 1

Expand Down
60 changes: 24 additions & 36 deletions arch/x86/kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
#include <asm/virtext.h>
#include <asm/cpu.h>
#include <asm/nmi.h>
#include <asm/smp.h>

#ifdef CONFIG_X86_32
# include <linux/ctype.h>
# include <linux/mc146818rtc.h>
# include <asm/realmode.h>
#else
# include <asm/x86_init.h>
#endif
#include <linux/ctype.h>
#include <linux/mc146818rtc.h>
#include <asm/realmode.h>
#include <asm/x86_init.h>

/*
* Power off function, if any
Expand All @@ -51,7 +49,7 @@ int reboot_force;
*/
static int reboot_default = 1;

#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
#ifdef CONFIG_SMP
static int reboot_cpu = -1;
#endif

Expand All @@ -69,8 +67,8 @@ bool port_cf9_safe = false;
* reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci]
* warm Don't set the cold reboot flag
* cold Set the cold reboot flag
* bios Reboot by jumping through the BIOS (only for X86_32)
* smp Reboot by executing reset on BSP or other CPU (only for X86_32)
* bios Reboot by jumping through the BIOS
* smp Reboot by executing reset on BSP or other CPU
* triple Force a triple fault (init)
* kbd Use the keyboard controller. cold reset (default)
* acpi Use the RESET_REG in the FADT
Expand All @@ -97,7 +95,6 @@ static int __init reboot_setup(char *str)
reboot_mode = 0;
break;

#ifdef CONFIG_X86_32
#ifdef CONFIG_SMP
case 's':
if (isdigit(*(str+1))) {
Expand All @@ -114,7 +111,6 @@ static int __init reboot_setup(char *str)
#endif /* CONFIG_SMP */

case 'b':
#endif
case 'a':
case 'k':
case 't':
Expand All @@ -140,7 +136,6 @@ static int __init reboot_setup(char *str)
__setup("reboot=", reboot_setup);


#ifdef CONFIG_X86_32
/*
* Reboot options and system auto-detection code provided by
* Dell Inc. so their systems "just work". :-)
Expand All @@ -160,11 +155,8 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
return 0;
}

void machine_real_restart(unsigned int type)
void __noreturn machine_real_restart(unsigned int type)
{
void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
real_mode_header->machine_real_restart_asm;

local_irq_disable();

/*
Expand All @@ -184,25 +176,28 @@ void machine_real_restart(unsigned int type)
/*
* Switch back to the initial page table.
*/
#ifdef CONFIG_X86_32
load_cr3(initial_page_table);

/*
* Write 0x1234 to absolute memory location 0x472. The BIOS reads
* this on booting to tell it to "Bypass memory test (also warm
* boot)". This seems like a fairly standard thing that gets set by
* REBOOT.COM programs, and the previous reset routine did this
* too. */
*((unsigned short *)0x472) = reboot_mode;
#else
write_cr3(real_mode_header->trampoline_pgd);
#endif

/* Jump to the identity-mapped low memory code */
restart_lowmem(type);
#ifdef CONFIG_X86_32
asm volatile("jmpl *%0" : :
"rm" (real_mode_header->machine_real_restart_asm),
"a" (type));
#else
asm volatile("ljmpl *%0" : :
"m" (real_mode_header->machine_real_restart_asm),
"D" (type));
#endif
unreachable();
}
#ifdef CONFIG_APM_MODULE
EXPORT_SYMBOL(machine_real_restart);
#endif

#endif /* CONFIG_X86_32 */

/*
* Some Apple MacBook and MacBookPro's needs reboot=p to be able to reboot
*/
Expand All @@ -227,11 +222,9 @@ static int __init set_kbd_reboot(const struct dmi_system_id *d)
}

/*
* This is a single dmi_table handling all reboot quirks. Note that
* REBOOT_BIOS is only available for 32bit
* This is a single dmi_table handling all reboot quirks.
*/
static struct dmi_system_id __initdata reboot_dmi_table[] = {
#ifdef CONFIG_X86_32
{ /* Handle problems with rebooting on Dell E520's */
.callback = set_bios_reboot,
.ident = "Dell E520",
Expand Down Expand Up @@ -381,7 +374,6 @@ static struct dmi_system_id __initdata reboot_dmi_table[] = {
DMI_MATCH(DMI_BOARD_NAME, "P4S800"),
},
},
#endif /* CONFIG_X86_32 */

{ /* Handle reboot issue on Acer Aspire one */
.callback = set_kbd_reboot,
Expand Down Expand Up @@ -588,13 +580,11 @@ static void native_machine_emergency_restart(void)
reboot_type = BOOT_KBD;
break;

#ifdef CONFIG_X86_32
case BOOT_BIOS:
machine_real_restart(MRR_BIOS);

reboot_type = BOOT_KBD;
break;
#endif

case BOOT_ACPI:
acpi_reboot();
Expand Down Expand Up @@ -636,12 +626,10 @@ void native_machine_shutdown(void)
/* The boot cpu is always logical cpu 0 */
int reboot_cpu_id = 0;

#ifdef CONFIG_X86_32
/* See if there has been given a command line override */
if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) &&
cpu_online(reboot_cpu))
reboot_cpu_id = reboot_cpu;
#endif

/* Make certain the cpu I'm about to reboot on is online */
if (!cpu_online(reboot_cpu_id))
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/realmode/rm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ wakeup-objs += video-bios.o
realmode-y += header.o
realmode-y += trampoline_$(BITS).o
realmode-y += stack.o
realmode-$(CONFIG_X86_32) += reboot_32.o
realmode-y += reboot.o
realmode-$(CONFIG_ACPI_SLEEP) += $(wakeup-objs)

targets += $(realmode-y)
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/realmode/rm/header.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <linux/linkage.h>
#include <asm/page_types.h>
#include <asm/segment.h>

#include "realmode.h"

Expand All @@ -28,8 +29,9 @@ GLOBAL(real_mode_header)
.long pa_wakeup_header
#endif
/* APM/BIOS reboot */
#ifdef CONFIG_X86_32
.long pa_machine_real_restart_asm
#ifdef CONFIG_X86_64
.long __KERNEL32_CS
#endif
END(real_mode_header)

Expand Down
30 changes: 27 additions & 3 deletions arch/x86/realmode/rm/reboot_32.S → arch/x86/realmode/rm/reboot.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <linux/init.h>
#include <asm/segment.h>
#include <asm/page_types.h>
#include <asm/processor-flags.h>
#include <asm/msr-index.h>
#include "realmode.h"

/*
Expand All @@ -12,13 +14,35 @@
* doesn't work with at least one type of 486 motherboard. It is easy
* to stop this code working; hence the copious comments.
*
* This code is called with the restart type (0 = BIOS, 1 = APM) in %eax.
* This code is called with the restart type (0 = BIOS, 1 = APM) in
* the primary argument register (%eax for 32 bit, %edi for 64 bit).
*/
.section ".text32", "ax"
.code32

.balign 16
ENTRY(machine_real_restart_asm)

#ifdef CONFIG_X86_64
/* Switch to trampoline GDT as it is guaranteed < 4 GiB */
movl $__KERNEL_DS, %eax
movl %eax, %ds
lgdtl pa_tr_gdt

/* Disable paging to drop us out of long mode */
movl %cr0, %eax
andl $~X86_CR0_PG, %eax
movl %eax, %cr0
ljmpl $__KERNEL32_CS, $pa_machine_real_restart_paging_off

GLOBAL(machine_real_restart_paging_off)
xorl %eax, %eax
xorl %edx, %edx
movl $MSR_EFER, %ecx
wrmsr

movl %edi, %eax

#endif /* CONFIG_X86_64 */

/* Set up the IDT for real mode. */
lidtl pa_machine_real_restart_idt

Expand Down

0 comments on commit d5d96ed

Please sign in to comment.