reboot.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/pci.h>
  3. #include <linux/acpi.h>
  4. #include <acpi/reboot.h>
  5. void acpi_reboot(void)
  6. {
  7. struct acpi_generic_address *rr;
  8. struct pci_bus *bus0;
  9. unsigned int devfn;
  10. u8 reset_value;
  11. if (acpi_disabled)
  12. return;
  13. rr = &acpi_gbl_FADT.reset_register;
  14. /* ACPI reset register was only introduced with v2 of the FADT */
  15. if (acpi_gbl_FADT.header.revision < 2)
  16. return;
  17. /* Is the reset register supported? The spec says we should be
  18. * checking the bit width and bit offset, but Windows ignores
  19. * these fields */
  20. if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER))
  21. return;
  22. reset_value = acpi_gbl_FADT.reset_value;
  23. /* The reset register can only exist in I/O, Memory or PCI config space
  24. * on a device on bus 0. */
  25. switch (rr->space_id) {
  26. case ACPI_ADR_SPACE_PCI_CONFIG:
  27. /* The reset register can only live on bus 0. */
  28. bus0 = pci_find_bus(0, 0);
  29. if (!bus0)
  30. return;
  31. /* Form PCI device/function pair. */
  32. devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
  33. (rr->address >> 16) & 0xffff);
  34. printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG.\n");
  35. /* Write the value that resets us. */
  36. pci_bus_write_config_byte(bus0, devfn,
  37. (rr->address & 0xffff), reset_value);
  38. break;
  39. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  40. case ACPI_ADR_SPACE_SYSTEM_IO:
  41. printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n");
  42. acpi_reset();
  43. break;
  44. }
  45. }