| 12345678910111213141516171819202122232425262728293031 |
- /* Poweroff command: ACPI S5 on real hardware, Bochs/QEMU ports as fallback.
- *
- * The ACPI path parses the FADT and the DSDT \_S5 package (acpi.c) and
- * sets SLP_TYP|SLP_EN in the PM1a/PM1b control blocks. The Bochs/QEMU
- * ports are kept for emulators without usable ACPI tables. If no path
- * works the command returns instead of halting, so the desktop survives a
- * failed poweroff and the netlog/kworker can still report the reason. */
- #include "acpi.h"
- #include "pci.h"
- #include "serial.h"
- #include "timer.h"
- static void wait_ms(unsigned int ms)
- {
- unsigned int t0 = get_ticks_ms();
- while (get_ticks_ms() - t0 < ms)
- __asm__ volatile ("hlt");
- }
- void program_poweroff_main(const char *arg)
- {
- (void)arg;
- if (acpi_poweroff() == 0)
- wait_ms(1000);
- port_outw(0x604, 0x2000);
- port_outw(0xB004, 0x2000);
- wait_ms(200);
- serial_puts(SERIAL_COM1, "poweroff: failed\n");
- }
|