x86: sysreset: Separate out the EFI code
[oweals/u-boot.git] / drivers / sysreset / sysreset_x86.c
1 // 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>
13 #include <efi_loader.h>
14
15 static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
16 {
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
35 #ifdef CONFIG_EFI_LOADER
36 void __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 {
41         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          */
47         if (reset_type == EFI_RESET_COLD ||
48                  reset_type == EFI_RESET_PLATFORM_SPECIFIC)
49                 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);
53
54         /* TODO EFI_RESET_SHUTDOWN */
55
56         while (1) { }
57 }
58 #endif
59
60
61 static const struct udevice_id x86_sysreset_ids[] = {
62         { .compatible = "x86,reset" },
63         { }
64 };
65
66 static struct sysreset_ops x86_sysreset_ops = {
67         .request = x86_sysreset_request,
68 };
69
70 U_BOOT_DRIVER(x86_sysreset) = {
71         .name = "x86-sysreset",
72         .id = UCLASS_SYSRESET,
73         .of_match = x86_sysreset_ids,
74         .ops = &x86_sysreset_ops,
75 };