reboot.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. #define pr_fmt(fmt) "ACPI: " fmt
  3. #include <linux/pci.h>
  4. #include <linux/acpi.h>
  5. #include <acpi/reboot.h>
  6. #include <linux/delay.h>
  7. #ifdef CONFIG_PCI
  8. static void acpi_pci_reboot(struct acpi_generic_address *rr, u8 reset_value)
  9. {
  10. unsigned int devfn;
  11. struct pci_bus *bus0;
  12. /* The reset register can only live on bus 0. */
  13. bus0 = pci_find_bus(0, 0);
  14. if (!bus0)
  15. return;
  16. /* Form PCI device/function pair. */
  17. devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
  18. (rr->address >> 16) & 0xffff);
  19. pr_debug("Resetting with ACPI PCI RESET_REG.\n");
  20. /* Write the value that resets us. */
  21. pci_bus_write_config_byte(bus0, devfn,
  22. (rr->address & 0xffff), reset_value);
  23. }
  24. #else
  25. static inline void acpi_pci_reboot(struct acpi_generic_address *rr,
  26. u8 reset_value)
  27. {
  28. pr_warn_once("PCI configuration space access is not supported\n");
  29. }
  30. #endif
  31. void acpi_reboot(void)
  32. {
  33. struct acpi_generic_address *rr;
  34. u8 reset_value;
  35. if (acpi_disabled)
  36. return;
  37. rr = &acpi_gbl_FADT.reset_register;
  38. /* ACPI reset register was only introduced with v2 of the FADT */
  39. if (acpi_gbl_FADT.header.revision < 2)
  40. return;
  41. /* Is the reset register supported? The spec says we should be
  42. * checking the bit width and bit offset, but Windows ignores
  43. * these fields */
  44. if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER))
  45. return;
  46. reset_value = acpi_gbl_FADT.reset_value;
  47. /* The reset register can only exist in I/O, Memory or PCI config space
  48. * on a device on bus 0. */
  49. switch (rr->space_id) {
  50. case ACPI_ADR_SPACE_PCI_CONFIG:
  51. acpi_pci_reboot(rr, reset_value);
  52. break;
  53. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  54. case ACPI_ADR_SPACE_SYSTEM_IO:
  55. pr_debug("ACPI MEMORY or I/O RESET_REG.\n");
  56. acpi_reset();
  57. break;
  58. }
  59. /*
  60. * Some platforms do not shut down immediately after writing to the
  61. * ACPI reset register, and this results in racing with the
  62. * subsequent reboot mechanism.
  63. *
  64. * The 15ms delay has been found to be long enough for the system
  65. * to reboot on the affected platforms.
  66. */
  67. mdelay(15);
  68. }