blob: 009f3766027f8e3f77fee63a29555a7dc4305d51 [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
Alexander Graff6cc0db2019-01-30 11:46:34 +010015static __efi_runtime int x86_sysreset_request(struct udevice *dev,
16 enum sysreset_t type)
Bin Mengd18cdd42018-07-03 02:48:40 -070017{
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
Alexander Graff6cc0db2019-01-30 11:46:34 +010036#ifdef CONFIG_EFI_LOADER
37void __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
Bin Mengd18cdd42018-07-03 02:48:40 -070055static const struct udevice_id x86_sysreset_ids[] = {
56 { .compatible = "x86,reset" },
57 { }
58};
59
60static struct sysreset_ops x86_sysreset_ops = {
61 .request = x86_sysreset_request,
62};
63
64U_BOOT_DRIVER(x86_sysreset) = {
65 .name = "x86-sysreset",
66 .id = UCLASS_SYSRESET,
67 .of_match = x86_sysreset_ids,
68 .ops = &x86_sysreset_ops,
Bin Mengd18cdd42018-07-03 02:48:40 -070069};