blob: d484ec5de49ca53e8811954dbfe6da48fdd5ea9d [file] [log] [blame]
Bin Mengd18cdd42018-07-03 02:48:40 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4 *
5 * Generic reset driver for x86 processor
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <sysreset.h>
11#include <asm/io.h>
12#include <asm/processor.h>
Alexander Graff6cc0db2019-01-30 11:46:34 +010013#include <efi_loader.h>
Bin Mengd18cdd42018-07-03 02:48:40 -070014
Simon Glassa21dda92019-05-02 10:52:13 -060015static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
Bin Mengd18cdd42018-07-03 02:48:40 -070016{
17 int value;
18
19 switch (type) {
20 case SYSRESET_WARM:
21 value = SYS_RST | RST_CPU;
22 break;
23 case SYSRESET_COLD:
24 value = SYS_RST | RST_CPU | FULL_RST;
25 break;
26 default:
27 return -ENOSYS;
28 }
29
30 outb(value, IO_PORT_RESET);
31
32 return -EINPROGRESS;
33}
34
Alexander Graff6cc0db2019-01-30 11:46:34 +010035#ifdef CONFIG_EFI_LOADER
36void __efi_runtime EFIAPI efi_reset_system(
37 enum efi_reset_type reset_type,
38 efi_status_t reset_status,
39 unsigned long data_size, void *reset_data)
40{
Simon Glassa21dda92019-05-02 10:52:13 -060041 int value;
42
43 /*
44 * inline this code since we are not caused in the context of a
45 * udevice and passing NULL to x86_sysreset_request() is too horrible.
46 */
Alexander Graff6cc0db2019-01-30 11:46:34 +010047 if (reset_type == EFI_RESET_COLD ||
48 reset_type == EFI_RESET_PLATFORM_SPECIFIC)
Simon Glassa21dda92019-05-02 10:52:13 -060049 value = SYS_RST | RST_CPU | FULL_RST;
50 else /* assume EFI_RESET_WARM since we cannot return an error */
51 value = SYS_RST | RST_CPU;
52 outb(value, IO_PORT_RESET);
Alexander Graff6cc0db2019-01-30 11:46:34 +010053
54 /* TODO EFI_RESET_SHUTDOWN */
55
56 while (1) { }
57}
58#endif
59
60
Bin Mengd18cdd42018-07-03 02:48:40 -070061static const struct udevice_id x86_sysreset_ids[] = {
62 { .compatible = "x86,reset" },
63 { }
64};
65
66static struct sysreset_ops x86_sysreset_ops = {
67 .request = x86_sysreset_request,
68};
69
70U_BOOT_DRIVER(x86_sysreset) = {
71 .name = "x86-sysreset",
72 .id = UCLASS_SYSRESET,
73 .of_match = x86_sysreset_ids,
74 .ops = &x86_sysreset_ops,
Bin Mengd18cdd42018-07-03 02:48:40 -070075};