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 | |
| 3 | #include <linux/pci.h> |
| 4 | #include <linux/acpi.h> |
| 5 | #include <acpi/reboot.h> |
| 6 | |
| 7 | void acpi_reboot(void) |
| 8 | { |
| 9 | struct acpi_generic_address *rr; |
| 10 | struct pci_bus *bus0; |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 11 | unsigned int devfn; |
Laszlo Toth | dd73e72 | 2018-04-10 19:10:38 +0200 | [diff] [blame] | 12 | u8 reset_value; |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 13 | |
| 14 | if (acpi_disabled) |
| 15 | return; |
| 16 | |
| 17 | rr = &acpi_gbl_FADT.reset_register; |
| 18 | |
Matthew Garrett | 95cf3e1 | 2011-03-11 16:12:20 -0500 | [diff] [blame] | 19 | /* ACPI reset register was only introduced with v2 of the FADT */ |
| 20 | |
| 21 | if (acpi_gbl_FADT.header.revision < 2) |
| 22 | return; |
| 23 | |
Matthew Garrett | 6734fe5 | 2011-03-11 16:12:19 -0500 | [diff] [blame] | 24 | /* Is the reset register supported? The spec says we should be |
| 25 | * checking the bit width and bit offset, but Windows ignores |
| 26 | * these fields */ |
Linus Torvalds | 19244ad | 2012-04-20 11:19:35 -0700 | [diff] [blame] | 27 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER)) |
| 28 | return; |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 29 | |
| 30 | reset_value = acpi_gbl_FADT.reset_value; |
| 31 | |
| 32 | /* The reset register can only exist in I/O, Memory or PCI config space |
| 33 | * on a device on bus 0. */ |
| 34 | switch (rr->space_id) { |
| 35 | case ACPI_ADR_SPACE_PCI_CONFIG: |
| 36 | /* The reset register can only live on bus 0. */ |
| 37 | bus0 = pci_find_bus(0, 0); |
| 38 | if (!bus0) |
| 39 | return; |
| 40 | /* Form PCI device/function pair. */ |
| 41 | devfn = PCI_DEVFN((rr->address >> 32) & 0xffff, |
| 42 | (rr->address >> 16) & 0xffff); |
Laszlo Toth | dd73e72 | 2018-04-10 19:10:38 +0200 | [diff] [blame] | 43 | printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG.\n"); |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 44 | /* Write the value that resets us. */ |
| 45 | pci_bus_write_config_byte(bus0, devfn, |
| 46 | (rr->address & 0xffff), reset_value); |
| 47 | break; |
| 48 | |
| 49 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 50 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 51 | printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n"); |
Lin Ming | 2ee6261 | 2008-12-16 16:40:31 +0800 | [diff] [blame] | 52 | acpi_reset(); |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 53 | break; |
| 54 | } |
Aaron Durbin | 4d38704 | 2008-07-16 23:27:08 +0200 | [diff] [blame] | 55 | } |