arch/x86/kernel/reboot.c

Source file repositories/reference/linux-study-clean/arch/x86/kernel/reboot.c

File Facts

System
Linux kernel
Corpus path
arch/x86/kernel/reboot.c
Extension
.c
Size
24491 bytes
Lines
947
Domain
Architecture Layer
Bucket
arch/x86
Inferred role
Architecture Layer: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

core_initcall(reboot_init);

static inline void kb_wait(void)
{
	int i;

	for (i = 0; i < 0x10000; i++) {
		if ((inb(0x64) & 0x02) == 0)
			break;
		udelay(2);
	}
}

static inline void nmi_shootdown_cpus_on_restart(void);

#if IS_ENABLED(CONFIG_KVM_X86)
static void emergency_reboot_disable_virtualization(void)
{
	local_irq_disable();

	/*
	 * Disable virtualization on all CPUs before rebooting to avoid hanging
	 * the system, as VMX and SVM block INIT when running in the host.
	 *
	 * We can't take any locks and we may be on an inconsistent state, so
	 * use NMIs as IPIs to tell the other CPUs to disable VMX/SVM and halt.
	 *
	 * Safely force _this_ CPU out of VMX/SVM operation, and if necessary,
	 * blast NMIs to force other CPUs out of VMX/SVM as well.k
	 */
	if (!x86_virt_emergency_disable_virtualization_cpu())
		nmi_shootdown_cpus_on_restart();
}
#else
static void emergency_reboot_disable_virtualization(void) { }
#endif /* CONFIG_KVM_X86 */

void __attribute__((weak)) mach_reboot_fixups(void)
{
}

/*
 * To the best of our knowledge Windows compatible x86 hardware expects
 * the following on reboot:
 *
 * 1) If the FADT has the ACPI reboot register flag set, try it
 * 2) If still alive, write to the keyboard controller
 * 3) If still alive, write to the ACPI reboot register again
 * 4) If still alive, write to the keyboard controller again
 * 5) If still alive, call the EFI runtime service to reboot
 * 6) If no EFI runtime service, call the BIOS to do a reboot
 *
 * We default to following the same pattern. We also have
 * two other reboot methods: 'triple fault' and 'PCI', which
 * can be triggered via the reboot= kernel boot option or
 * via quirks.
 *
 * This means that this function can never return, it can misbehave
 * by not rebooting properly and hanging.
 */
static void native_machine_emergency_restart(void)
{
	int i;
	int attempt = 0;
	int orig_reboot_type = reboot_type;
	unsigned short mode;

	if (reboot_emergency)
		emergency_reboot_disable_virtualization();

	tboot_shutdown(TB_SHUTDOWN_REBOOT);

	/* Tell the BIOS if we want cold or warm reboot */
	mode = reboot_mode == REBOOT_WARM ? 0x1234 : 0;
	*((unsigned short *)__va(0x472)) = mode;

	/*
	 * If an EFI capsule has been registered with the firmware then
	 * override the reboot= parameter.
	 */
	if (efi_capsule_pending(NULL)) {
		pr_info("EFI capsule is pending, forcing EFI reboot.\n");
		reboot_type = BOOT_EFI;
	}

	for (;;) {
		/* Could also try the reset bit in the Hammer NB */
		switch (reboot_type) {
		case BOOT_ACPI:
			acpi_reboot();

Annotation

Implementation Notes