2005-04-16 22:20:36 +00:00
|
|
|
/* Various gunk just to reboot the machine. */
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/string.h>
|
2006-01-11 21:43:12 +00:00
|
|
|
#include <linux/pm.h>
|
2007-05-08 07:27:03 +00:00
|
|
|
#include <linux/kdebug.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-20 21:22:52 +00:00
|
|
|
#include <linux/sched.h>
|
2008-01-30 12:31:19 +00:00
|
|
|
#include <linux/efi.h>
|
2008-01-30 12:31:17 +00:00
|
|
|
#include <acpi/reboot.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/delay.h>
|
2007-10-19 18:35:03 +00:00
|
|
|
#include <asm/desc.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/apic.h>
|
2007-12-03 16:17:10 +00:00
|
|
|
#include <asm/hpet.h>
|
2007-10-24 10:49:47 +00:00
|
|
|
#include <asm/gart.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Power off function, if any
|
|
|
|
*/
|
|
|
|
void (*pm_power_off)(void);
|
2006-06-26 11:59:44 +00:00
|
|
|
EXPORT_SYMBOL(pm_power_off);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static long no_idt[3];
|
2008-01-30 12:31:19 +00:00
|
|
|
enum reboot_type reboot_type = BOOT_KBD;
|
2005-04-16 22:20:36 +00:00
|
|
|
static int reboot_mode = 0;
|
|
|
|
int reboot_force;
|
|
|
|
|
2008-01-30 12:31:19 +00:00
|
|
|
/* reboot=t[riple] | k[bd] | e[fi] [, [w]arm | [c]old]
|
2005-04-16 22:20:36 +00:00
|
|
|
warm Don't set the cold reboot flag
|
|
|
|
cold Set the cold reboot flag
|
|
|
|
triple Force a triple fault (init)
|
|
|
|
kbd Use the keyboard controller. cold reset (default)
|
2008-01-30 12:31:17 +00:00
|
|
|
acpi Use the RESET_REG in the FADT
|
2008-01-30 12:31:19 +00:00
|
|
|
efi Use efi reset_system runtime service
|
2005-04-16 22:20:36 +00:00
|
|
|
force Avoid anything that could hang.
|
|
|
|
*/
|
|
|
|
static int __init reboot_setup(char *str)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
switch (*str) {
|
|
|
|
case 'w':
|
|
|
|
reboot_mode = 0x1234;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
reboot_mode = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
2008-01-30 12:31:17 +00:00
|
|
|
case 'a':
|
2005-04-16 22:20:36 +00:00
|
|
|
case 'b':
|
|
|
|
case 'k':
|
2008-01-30 12:31:19 +00:00
|
|
|
case 'e':
|
2005-04-16 22:20:36 +00:00
|
|
|
reboot_type = *str;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
reboot_force = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if((str = strchr(str,',')) != NULL)
|
|
|
|
str++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("reboot=", reboot_setup);
|
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
static inline void kb_wait(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-06-25 21:58:02 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
for (i=0; i<0x10000; i++)
|
|
|
|
if ((inb_p(0x64) & 0x02) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
void machine_shutdown(void)
|
|
|
|
{
|
2005-11-05 16:25:54 +00:00
|
|
|
unsigned long flags;
|
2007-07-21 15:11:28 +00:00
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
/* Stop the cpus and apics */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
int reboot_cpu_id;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
/* The boot cpu is always logical cpu 0 */
|
|
|
|
reboot_cpu_id = 0;
|
|
|
|
|
|
|
|
/* Make certain the cpu I'm about to reboot on is online */
|
|
|
|
if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
|
|
|
|
reboot_cpu_id = smp_processor_id();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
/* Make certain I only run on the appropriate processor */
|
|
|
|
set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
|
|
|
|
|
|
|
|
/* O.K Now that I'm on the appropriate processor,
|
|
|
|
* stop all of the others.
|
|
|
|
*/
|
|
|
|
smp_send_stop();
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-05 16:25:54 +00:00
|
|
|
local_irq_save(flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-25 21:58:02 +00:00
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
disable_local_APIC();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
disable_IO_APIC();
|
|
|
|
|
2007-12-03 16:17:10 +00:00
|
|
|
#ifdef CONFIG_HPET_TIMER
|
|
|
|
hpet_disable();
|
|
|
|
#endif
|
2005-11-05 16:25:54 +00:00
|
|
|
local_irq_restore(flags);
|
2007-07-21 15:11:28 +00:00
|
|
|
|
|
|
|
pci_iommu_shutdown();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-07-26 17:45:31 +00:00
|
|
|
void machine_emergency_restart(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Tell the BIOS if we want cold or warm reboot */
|
|
|
|
*((unsigned short *)__va(0x472)) = reboot_mode;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* Could also try the reset bit in the Hammer NB */
|
|
|
|
switch (reboot_type) {
|
|
|
|
case BOOT_KBD:
|
2005-11-05 16:25:54 +00:00
|
|
|
for (i=0; i<10; i++) {
|
2005-04-16 22:20:36 +00:00
|
|
|
kb_wait();
|
|
|
|
udelay(50);
|
|
|
|
outb(0xfe,0x64); /* pulse reset low */
|
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
case BOOT_TRIPLE:
|
2007-10-19 18:35:03 +00:00
|
|
|
load_idt((const struct desc_ptr *)&no_idt);
|
2005-04-16 22:20:36 +00:00
|
|
|
__asm__ __volatile__("int3");
|
|
|
|
|
|
|
|
reboot_type = BOOT_KBD;
|
|
|
|
break;
|
2008-01-30 12:31:17 +00:00
|
|
|
|
|
|
|
case BOOT_ACPI:
|
|
|
|
acpi_reboot();
|
|
|
|
reboot_type = BOOT_KBD;
|
|
|
|
break;
|
2008-01-30 12:31:19 +00:00
|
|
|
|
|
|
|
case BOOT_EFI:
|
|
|
|
if (efi_enabled)
|
|
|
|
efi.reset_system(reboot_mode ? EFI_RESET_WARM : EFI_RESET_COLD,
|
|
|
|
EFI_SUCCESS, 0, NULL);
|
|
|
|
reboot_type = BOOT_KBD;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-26 17:45:31 +00:00
|
|
|
void machine_restart(char * __unused)
|
|
|
|
{
|
|
|
|
printk("machine restart\n");
|
|
|
|
|
|
|
|
if (!reboot_force) {
|
|
|
|
machine_shutdown();
|
|
|
|
}
|
|
|
|
machine_emergency_restart();
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
void machine_halt(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void machine_power_off(void)
|
|
|
|
{
|
2006-01-11 21:43:12 +00:00
|
|
|
if (pm_power_off) {
|
|
|
|
if (!reboot_force) {
|
|
|
|
machine_shutdown();
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
pm_power_off();
|
2006-01-11 21:43:12 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|