reboot.c 2.0 KB

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