1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5 * Generic reset driver for x86 processor
10 #include <efi_loader.h>
13 #include <asm/acpi_s3.h>
15 #include <asm/processor.h>
17 struct x86_sysreset_platdata {
22 * Power down the machine by using the power management sleep control
23 * of the chipset. This will currently only work on Intel chipsets.
24 * However, adapting it to new chipsets is fairly simple. You will
25 * have to find the IO address of the power management register block
26 * in your southbridge, and look up the appropriate SLP_TYP_S5 value
27 * from your southbridge's data sheet.
29 * This function never returns.
31 int pch_sysreset_power_off(struct udevice *dev)
33 struct x86_sysreset_platdata *plat = dev_get_platdata(dev);
34 struct pch_pmbase_info pm;
40 ret = pch_ioctl(plat->pch, PCH_REQ_PMBASE_INFO, &pm, sizeof(pm));
45 * Mask interrupts or system might stay in a coma, not executing code
46 * anymore, but not powered off either.
51 * Avoid any GPI waking the system from S5* or the system might stay in
54 outl(0x00000000, pm.base + pm.gpio0_en_ofs);
56 /* Clear Power Button Status */
57 outw(PWRBTN_STS, pm.base + pm.pm1_sts_ofs);
59 /* PMBASE + 4, Bit 10-12, Sleeping Type, * set to 111 -> S5, soft_off */
60 reg32 = inl(pm.base + pm.pm1_cnt_ofs);
62 /* Set Sleeping Type to S5 (poweroff) */
63 reg32 &= ~(SLP_EN | SLP_TYP);
65 outl(reg32, pm.base + pm.pm1_cnt_ofs);
67 /* Now set the Sleep Enable bit */
69 outl(reg32, pm.base + pm.pm1_cnt_ofs);
75 static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
82 value = SYS_RST | RST_CPU;
85 value = SYS_RST | RST_CPU | FULL_RST;
87 case SYSRESET_POWER_OFF:
88 ret = pch_sysreset_power_off(dev);
96 outb(value, IO_PORT_RESET);
101 #ifdef CONFIG_EFI_LOADER
102 void __efi_runtime EFIAPI efi_reset_system(
103 enum efi_reset_type reset_type,
104 efi_status_t reset_status,
105 unsigned long data_size, void *reset_data)
110 * inline this code since we are not caused in the context of a
111 * udevice and passing NULL to x86_sysreset_request() is too horrible.
113 if (reset_type == EFI_RESET_COLD ||
114 reset_type == EFI_RESET_PLATFORM_SPECIFIC)
115 value = SYS_RST | RST_CPU | FULL_RST;
116 else /* assume EFI_RESET_WARM since we cannot return an error */
117 value = SYS_RST | RST_CPU;
118 outb(value, IO_PORT_RESET);
120 /* TODO EFI_RESET_SHUTDOWN */
126 static int x86_sysreset_probe(struct udevice *dev)
128 struct x86_sysreset_platdata *plat = dev_get_platdata(dev);
130 /* Locate the PCH if there is one. It isn't essential */
131 uclass_first_device(UCLASS_PCH, &plat->pch);
136 static const struct udevice_id x86_sysreset_ids[] = {
137 { .compatible = "x86,reset" },
141 static struct sysreset_ops x86_sysreset_ops = {
142 .request = x86_sysreset_request,
145 U_BOOT_DRIVER(x86_sysreset) = {
146 .name = "x86-sysreset",
147 .id = UCLASS_SYSRESET,
148 .of_match = x86_sysreset_ids,
149 .ops = &x86_sysreset_ops,
150 .probe = x86_sysreset_probe,
151 .platdata_auto_alloc_size = sizeof(struct x86_sysreset_platdata),