reboot.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Reboot command: ACPI reset register first, then the legacy fallbacks.
  2. *
  3. * The 8042 pulse alone does nothing on machines without a legacy keyboard
  4. * controller (the Chromebook), which used to leave the BSP halted with the
  5. * BKL held. The FADT RESET_REG/RESET_VALUE pair is the firmware-provided
  6. * reset path; 0xCF9 is the Intel PCH fallback, and a triple fault is the
  7. * last resort. */
  8. #include "acpi.h"
  9. #include "pci.h"
  10. #include "timer.h"
  11. static void wait_ms(unsigned int ms)
  12. {
  13. unsigned int t0 = get_ticks_ms();
  14. while (get_ticks_ms() - t0 < ms)
  15. __asm__ volatile ("hlt");
  16. }
  17. void program_reboot_main(void)
  18. {
  19. if (acpi_reset() == 0)
  20. wait_ms(500);
  21. /* Intel PCH reset control: SYS_RST, then RST_CPU|SYS_RST. */
  22. port_outb(0xCF9, 0x02);
  23. port_outb(0xCF9, 0x06);
  24. wait_ms(300);
  25. /* Legacy 8042 reset pulse, for boards where that is the only path. */
  26. port_outb(0x64, 0xFE);
  27. wait_ms(300);
  28. /* Zero IDT + int3: a triple fault forces a CPU reset. */
  29. {
  30. struct {
  31. unsigned short limit;
  32. unsigned int base;
  33. } __attribute__((packed)) idt = { 0, 0 };
  34. __asm__ volatile ("lidt %0" : : "m"(idt));
  35. __asm__ volatile ("int3");
  36. }
  37. for (;;)
  38. __asm__ volatile ("hlt");
  39. }