Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 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> |
Alexander Graf | f6cc0db | 2019-01-30 11:46:34 +0100 | [diff] [blame^] | 13 | #include <efi_loader.h> |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 14 | |
Alexander Graf | f6cc0db | 2019-01-30 11:46:34 +0100 | [diff] [blame^] | 15 | static __efi_runtime int x86_sysreset_request(struct udevice *dev, |
| 16 | enum sysreset_t type) |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 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 | |
Alexander Graf | f6cc0db | 2019-01-30 11:46:34 +0100 | [diff] [blame^] | 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 | |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 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, |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 69 | }; |