blob: ca707f5b521d0990370e9f7fdbc531d97497cb4f [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>
6
Sinan Kaya86689772018-12-19 22:46:54 +00007#ifdef CONFIG_PCI
Sinan Kaya36ad7d22018-12-19 22:46:53 +00008static void acpi_pci_reboot(struct acpi_generic_address *rr, u8 reset_value)
9{
10 unsigned int devfn;
11 struct pci_bus *bus0;
12
13 /* The reset register can only live on bus 0. */
14 bus0 = pci_find_bus(0, 0);
15 if (!bus0)
16 return;
17 /* Form PCI device/function pair. */
18 devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
19 (rr->address >> 16) & 0xffff);
20 pr_debug("Resetting with ACPI PCI RESET_REG.\n");
21 /* Write the value that resets us. */
22 pci_bus_write_config_byte(bus0, devfn,
23 (rr->address & 0xffff), reset_value);
24}
Sinan Kaya86689772018-12-19 22:46:54 +000025#else
26static inline void acpi_pci_reboot(struct acpi_generic_address *rr,
27 u8 reset_value)
28{
29 pr_warn_once("PCI configuration space access is not supported\n");
30}
31#endif
Sinan Kaya36ad7d22018-12-19 22:46:53 +000032
Aaron Durbin4d387042008-07-16 23:27:08 +020033void acpi_reboot(void)
34{
35 struct acpi_generic_address *rr;
Laszlo Tothdd73e722018-04-10 19:10:38 +020036 u8 reset_value;
Aaron Durbin4d387042008-07-16 23:27:08 +020037
38 if (acpi_disabled)
39 return;
40
41 rr = &acpi_gbl_FADT.reset_register;
42
Matthew Garrett95cf3e12011-03-11 16:12:20 -050043 /* ACPI reset register was only introduced with v2 of the FADT */
44
45 if (acpi_gbl_FADT.header.revision < 2)
46 return;
47
Matthew Garrett6734fe52011-03-11 16:12:19 -050048 /* Is the reset register supported? The spec says we should be
49 * checking the bit width and bit offset, but Windows ignores
50 * these fields */
Linus Torvalds19244ad2012-04-20 11:19:35 -070051 if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER))
52 return;
Aaron Durbin4d387042008-07-16 23:27:08 +020053
54 reset_value = acpi_gbl_FADT.reset_value;
55
56 /* The reset register can only exist in I/O, Memory or PCI config space
57 * on a device on bus 0. */
58 switch (rr->space_id) {
59 case ACPI_ADR_SPACE_PCI_CONFIG:
Sinan Kaya36ad7d22018-12-19 22:46:53 +000060 acpi_pci_reboot(rr, reset_value);
Aaron Durbin4d387042008-07-16 23:27:08 +020061 break;
62
63 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
64 case ACPI_ADR_SPACE_SYSTEM_IO:
65 printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n");
Lin Ming2ee62612008-12-16 16:40:31 +080066 acpi_reset();
Aaron Durbin4d387042008-07-16 23:27:08 +020067 break;
68 }
Aaron Durbin4d387042008-07-16 23:27:08 +020069}