blob: 2a61f884e2228c8c64a62e1c15a0b73988ea7f90 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Aaron Durbin4d387042008-07-16 23:27:08 +02002
3#include <linux/pci.h>
4#include <linux/acpi.h>
5#include <acpi/reboot.h>
Zhang Rui9a488882020-10-13 15:35:57 +08006#include <linux/delay.h>
Aaron Durbin4d387042008-07-16 23:27:08 +02007
Sinan Kaya86689772018-12-19 22:46:54 +00008#ifdef CONFIG_PCI
Sinan Kaya36ad7d22018-12-19 22:46:53 +00009static void acpi_pci_reboot(struct acpi_generic_address *rr, u8 reset_value)
10{
11 unsigned int devfn;
12 struct pci_bus *bus0;
13
14 /* The reset register can only live on bus 0. */
15 bus0 = pci_find_bus(0, 0);
16 if (!bus0)
17 return;
18 /* Form PCI device/function pair. */
19 devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
20 (rr->address >> 16) & 0xffff);
21 pr_debug("Resetting with ACPI PCI RESET_REG.\n");
22 /* Write the value that resets us. */
23 pci_bus_write_config_byte(bus0, devfn,
24 (rr->address & 0xffff), reset_value);
25}
Sinan Kaya86689772018-12-19 22:46:54 +000026#else
27static inline void acpi_pci_reboot(struct acpi_generic_address *rr,
28 u8 reset_value)
29{
30 pr_warn_once("PCI configuration space access is not supported\n");
31}
32#endif
Sinan Kaya36ad7d22018-12-19 22:46:53 +000033
Aaron Durbin4d387042008-07-16 23:27:08 +020034void acpi_reboot(void)
35{
36 struct acpi_generic_address *rr;
Laszlo Tothdd73e722018-04-10 19:10:38 +020037 u8 reset_value;
Aaron Durbin4d387042008-07-16 23:27:08 +020038
39 if (acpi_disabled)
40 return;
41
42 rr = &acpi_gbl_FADT.reset_register;
43
Matthew Garrett95cf3e12011-03-11 16:12:20 -050044 /* ACPI reset register was only introduced with v2 of the FADT */
45
46 if (acpi_gbl_FADT.header.revision < 2)
47 return;
48
Matthew Garrett6734fe52011-03-11 16:12:19 -050049 /* Is the reset register supported? The spec says we should be
50 * checking the bit width and bit offset, but Windows ignores
51 * these fields */
Linus Torvalds19244ad2012-04-20 11:19:35 -070052 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER))
53 return;
Aaron Durbin4d387042008-07-16 23:27:08 +020054
55 reset_value = acpi_gbl_FADT.reset_value;
56
57 /* The reset register can only exist in I/O, Memory or PCI config space
58 * on a device on bus 0. */
59 switch (rr->space_id) {
60 case ACPI_ADR_SPACE_PCI_CONFIG:
Sinan Kaya36ad7d22018-12-19 22:46:53 +000061 acpi_pci_reboot(rr, reset_value);
Aaron Durbin4d387042008-07-16 23:27:08 +020062 break;
63
64 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
65 case ACPI_ADR_SPACE_SYSTEM_IO:
66 printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n");
Lin Ming2ee62612008-12-16 16:40:31 +080067 acpi_reset();
Aaron Durbin4d387042008-07-16 23:27:08 +020068 break;
69 }
Zhang Rui9a488882020-10-13 15:35:57 +080070
71 /*
72 * Some platforms do not shut down immediately after writing to the
73 * ACPI reset register, and this results in racing with the
74 * subsequent reboot mechanism.
75 *
76 * The 15ms delay has been found to be long enough for the system
77 * to reboot on the affected platforms.
78 */
79 mdelay(15);
Aaron Durbin4d387042008-07-16 23:27:08 +020080}