Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 2 | |
Hanjun Guo | 6ecfe60 | 2021-06-02 16:54:34 +0800 | [diff] [blame] | 3 | #define pr_fmt(fmt) "ACPI: " fmt |
| 4 | |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 5 | #include <linux/pci.h> |
| 6 | #include <linux/acpi.h> |
| 7 | #include <acpi/reboot.h> |
Zhang Rui | 9a48888 | 2020-10-13 15:35:57 +0800 | [diff] [blame] | 8 | #include <linux/delay.h> |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 9 | |
Sinan Kaya | 8668977 | 2018-12-19 22:46:54 +0000 | [diff] [blame] | 10 | #ifdef CONFIG_PCI |
Sinan Kaya | 36ad7d2 | 2018-12-19 22:46:53 +0000 | [diff] [blame] | 11 | static void acpi_pci_reboot(struct acpi_generic_address *rr, u8 reset_value) |
| 12 | { |
| 13 | unsigned int devfn; |
| 14 | struct pci_bus *bus0; |
| 15 | |
| 16 | /* The reset register can only live on bus 0. */ |
| 17 | bus0 = pci_find_bus(0, 0); |
| 18 | if (!bus0) |
| 19 | return; |
| 20 | /* Form PCI device/function pair. */ |
| 21 | devfn = PCI_DEVFN((rr->address >> 32) & 0xffff, |
| 22 | (rr->address >> 16) & 0xffff); |
| 23 | pr_debug("Resetting with ACPI PCI RESET_REG.\n"); |
| 24 | /* Write the value that resets us. */ |
| 25 | pci_bus_write_config_byte(bus0, devfn, |
| 26 | (rr->address & 0xffff), reset_value); |
| 27 | } |
Sinan Kaya | 8668977 | 2018-12-19 22:46:54 +0000 | [diff] [blame] | 28 | #else |
| 29 | static inline void acpi_pci_reboot(struct acpi_generic_address *rr, |
| 30 | u8 reset_value) |
| 31 | { |
| 32 | pr_warn_once("PCI configuration space access is not supported\n"); |
| 33 | } |
| 34 | #endif |
Sinan Kaya | 36ad7d2 | 2018-12-19 22:46:53 +0000 | [diff] [blame] | 35 | |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 36 | void acpi_reboot(void) |
| 37 | { |
| 38 | struct acpi_generic_address *rr; |
Laszlo Toth | dd73e72 | 2018-04-10 19:10:38 +0200 | [diff] [blame] | 39 | u8 reset_value; |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 40 | |
| 41 | if (acpi_disabled) |
| 42 | return; |
| 43 | |
| 44 | rr = &acpi_gbl_FADT.reset_register; |
| 45 | |
Matthew Garrett | 95cf3e1 | 2011-03-11 16:12:20 -0500 | [diff] [blame] | 46 | /* ACPI reset register was only introduced with v2 of the FADT */ |
| 47 | |
| 48 | if (acpi_gbl_FADT.header.revision < 2) |
| 49 | return; |
| 50 | |
Matthew Garrett | 6734fe5 | 2011-03-11 16:12:19 -0500 | [diff] [blame] | 51 | /* Is the reset register supported? The spec says we should be |
| 52 | * checking the bit width and bit offset, but Windows ignores |
| 53 | * these fields */ |
Linus Torvalds | 19244ad | 2012-04-20 11:19:35 -0700 | [diff] [blame] | 54 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER)) |
| 55 | return; |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 56 | |
| 57 | reset_value = acpi_gbl_FADT.reset_value; |
| 58 | |
| 59 | /* The reset register can only exist in I/O, Memory or PCI config space |
| 60 | * on a device on bus 0. */ |
| 61 | switch (rr->space_id) { |
| 62 | case ACPI_ADR_SPACE_PCI_CONFIG: |
Sinan Kaya | 36ad7d2 | 2018-12-19 22:46:53 +0000 | [diff] [blame] | 63 | acpi_pci_reboot(rr, reset_value); |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 64 | break; |
| 65 | |
| 66 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 67 | case ACPI_ADR_SPACE_SYSTEM_IO: |
Hanjun Guo | 6ecfe60 | 2021-06-02 16:54:34 +0800 | [diff] [blame] | 68 | pr_debug("ACPI MEMORY or I/O RESET_REG.\n"); |
Lin Ming | 2ee6261 | 2008-12-16 16:40:31 +0800 | [diff] [blame] | 69 | acpi_reset(); |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 70 | break; |
| 71 | } |
Zhang Rui | 9a48888 | 2020-10-13 15:35:57 +0800 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * Some platforms do not shut down immediately after writing to the |
| 75 | * ACPI reset register, and this results in racing with the |
| 76 | * subsequent reboot mechanism. |
| 77 | * |
| 78 | * The 15ms delay has been found to be long enough for the system |
| 79 | * to reboot on the affected platforms. |
| 80 | */ |
| 81 | mdelay(15); |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 82 | } |