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 | |
Simon Glass | a21dda9 | 2019-05-02 10:52:13 -0600 | [diff] [blame^] | 15 | static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type) |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 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 | |
Alexander Graf | f6cc0db | 2019-01-30 11:46:34 +0100 | [diff] [blame] | 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 | { |
Simon Glass | a21dda9 | 2019-05-02 10:52:13 -0600 | [diff] [blame^] | 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 | */ |
Alexander Graf | f6cc0db | 2019-01-30 11:46:34 +0100 | [diff] [blame] | 47 | if (reset_type == EFI_RESET_COLD || |
| 48 | reset_type == EFI_RESET_PLATFORM_SPECIFIC) |
Simon Glass | a21dda9 | 2019-05-02 10:52:13 -0600 | [diff] [blame^] | 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); |
Alexander Graf | f6cc0db | 2019-01-30 11:46:34 +0100 | [diff] [blame] | 53 | |
| 54 | /* TODO EFI_RESET_SHUTDOWN */ |
| 55 | |
| 56 | while (1) { } |
| 57 | } |
| 58 | #endif |
| 59 | |
| 60 | |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 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, |
Bin Meng | d18cdd4 | 2018-07-03 02:48:40 -0700 | [diff] [blame] | 75 | }; |