Merge git://git.denx.de/u-boot-marvell
[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 __efi_runtime int x86_sysreset_request(struct udevice *dev,
16                                               enum sysreset_t type)
17 {
18         int value;
19
20         switch (type) {
21         case SYSRESET_WARM:
22                 value = SYS_RST | RST_CPU;
23                 break;
24         case SYSRESET_COLD:
25                 value = SYS_RST | RST_CPU | FULL_RST;
26                 break;
27         default:
28                 return -ENOSYS;
29         }
30
31         outb(value, IO_PORT_RESET);
32
33         return -EINPROGRESS;
34 }
35
36 #ifdef CONFIG_EFI_LOADER
37 void __efi_runtime EFIAPI efi_reset_system(
38                         enum efi_reset_type reset_type,
39                         efi_status_t reset_status,
40                         unsigned long data_size, void *reset_data)
41 {
42         if (reset_type == EFI_RESET_COLD ||
43                  reset_type == EFI_RESET_PLATFORM_SPECIFIC)
44                 x86_sysreset_request(NULL, SYSRESET_COLD);
45         else if (reset_type == EFI_RESET_WARM)
46                 x86_sysreset_request(NULL, SYSRESET_WARM);
47
48         /* TODO EFI_RESET_SHUTDOWN */
49
50         while (1) { }
51 }
52 #endif
53
54
55 static const struct udevice_id x86_sysreset_ids[] = {
56         { .compatible = "x86,reset" },
57         { }
58 };
59
60 static struct sysreset_ops x86_sysreset_ops = {
61         .request = x86_sysreset_request,
62 };
63
64 U_BOOT_DRIVER(x86_sysreset) = {
65         .name = "x86-sysreset",
66         .id = UCLASS_SYSRESET,
67         .of_match = x86_sysreset_ids,
68         .ops = &x86_sysreset_ops,
69 };