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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/reboot.hlinux/init.hlinux/pm.hlinux/efi.hlinux/dmi.hlinux/sched.hlinux/tboot.hlinux/delay.hlinux/objtool.hlinux/pgtable.hlinux/kexec.hlinux/kvm_types.hacpi/reboot.hasm/io.hasm/apic.hasm/io_apic.hasm/desc.hasm/hpet.hasm/proto.hasm/reboot_fixups.hasm/reboot.hasm/pci_x86.hasm/cpu.hasm/nmi.hasm/smp.hasm/virt.hlinux/ctype.hlinux/mc146818rtc.hasm/realmode.hasm/x86_init.hasm/efi.h
Detected Declarations
function set_acpi_rebootfunction set_bios_rebootfunction set_efi_rebootfunction machine_real_restartfunction set_pci_rebootfunction set_kbd_rebootfunction reboot_initfunction kb_waitfunction emergency_reboot_disable_virtualizationfunction emergency_reboot_disable_virtualizationfunction native_machine_shutdownfunction __machine_emergency_restartfunction native_machine_restartfunction native_machine_haltfunction native_machine_power_offfunction machine_power_offfunction machine_shutdownfunction machine_emergency_restartfunction machine_restartfunction machine_haltfunction machine_crash_shutdownfunction crash_nmi_callbackfunction nmi_shootdown_cpusfunction nmi_shootdown_cpus_on_restartfunction run_crash_ipi_callbackfunction nmi_panic_self_stopfunction nmi_shootdown_cpusmodule init reboot_initexport pm_power_offexport machine_real_restart
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
- Immediate include surface: `linux/export.h`, `linux/reboot.h`, `linux/init.h`, `linux/pm.h`, `linux/efi.h`, `linux/dmi.h`, `linux/sched.h`, `linux/tboot.h`.
- Detected declarations: `function set_acpi_reboot`, `function set_bios_reboot`, `function set_efi_reboot`, `function machine_real_restart`, `function set_pci_reboot`, `function set_kbd_reboot`, `function reboot_init`, `function kb_wait`, `function emergency_reboot_disable_virtualization`, `function emergency_reboot_disable_virtualization`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.