AKASHI Takahiro | 056b45b | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * EFI setup code |
| 4 | * |
| 5 | * Copyright (c) 2016-2018 Alexander Graf et al. |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <efi_loader.h> |
| 10 | |
| 11 | #define OBJ_LIST_NOT_INITIALIZED 1 |
| 12 | |
Heinrich Schuchardt | 734d325 | 2019-04-05 02:45:21 +0200 | [diff] [blame^] | 13 | /* Language code for American English according to RFC 4646 */ |
| 14 | #define EN_US L"en-US" |
| 15 | |
AKASHI Takahiro | 056b45b | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 16 | static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED; |
| 17 | |
| 18 | /* Initialize and populate EFI object list */ |
| 19 | efi_status_t efi_init_obj_list(void) |
| 20 | { |
| 21 | efi_status_t ret = EFI_SUCCESS; |
| 22 | |
| 23 | /* |
| 24 | * On the ARM architecture gd is mapped to a fixed register (r9 or x18). |
| 25 | * As this register may be overwritten by an EFI payload we save it here |
| 26 | * and restore it on every callback entered. |
| 27 | */ |
| 28 | efi_save_gd(); |
| 29 | |
Heinrich Schuchardt | 734d325 | 2019-04-05 02:45:21 +0200 | [diff] [blame^] | 30 | /* |
| 31 | * Variable PlatformLang defines the language that the machine has been |
| 32 | * configured for. |
| 33 | */ |
| 34 | ret = EFI_CALL(efi_set_variable(L"PlatformLang", |
| 35 | &efi_global_variable_guid, |
| 36 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 37 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 38 | sizeof(EN_US), EN_US)); |
| 39 | if (ret != EFI_SUCCESS) |
| 40 | goto out; |
| 41 | |
| 42 | /* |
| 43 | * Variable PlatformLangCodes defines the language codes that the |
| 44 | * machine can support. |
| 45 | */ |
| 46 | ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes", |
| 47 | &efi_global_variable_guid, |
| 48 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 49 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 50 | sizeof(EN_US), EN_US)); |
| 51 | if (ret != EFI_SUCCESS) |
| 52 | goto out; |
| 53 | |
AKASHI Takahiro | 056b45b | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 54 | /* Initialize once only */ |
| 55 | if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) |
| 56 | return efi_obj_list_initialized; |
| 57 | |
| 58 | /* Initialize system table */ |
| 59 | ret = efi_initialize_system_table(); |
| 60 | if (ret != EFI_SUCCESS) |
| 61 | goto out; |
| 62 | |
| 63 | /* Initialize root node */ |
| 64 | ret = efi_root_node_register(); |
| 65 | if (ret != EFI_SUCCESS) |
| 66 | goto out; |
| 67 | |
| 68 | /* Initialize EFI driver uclass */ |
| 69 | ret = efi_driver_init(); |
| 70 | if (ret != EFI_SUCCESS) |
| 71 | goto out; |
| 72 | |
| 73 | ret = efi_console_register(); |
| 74 | if (ret != EFI_SUCCESS) |
| 75 | goto out; |
| 76 | #ifdef CONFIG_PARTITIONS |
| 77 | ret = efi_disk_register(); |
| 78 | if (ret != EFI_SUCCESS) |
| 79 | goto out; |
| 80 | #endif |
| 81 | #if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO) |
| 82 | ret = efi_gop_register(); |
| 83 | if (ret != EFI_SUCCESS) |
| 84 | goto out; |
| 85 | #endif |
| 86 | #ifdef CONFIG_NET |
| 87 | ret = efi_net_register(); |
| 88 | if (ret != EFI_SUCCESS) |
| 89 | goto out; |
| 90 | #endif |
| 91 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
| 92 | ret = efi_acpi_register(); |
| 93 | if (ret != EFI_SUCCESS) |
| 94 | goto out; |
| 95 | #endif |
| 96 | #ifdef CONFIG_GENERATE_SMBIOS_TABLE |
| 97 | ret = efi_smbios_register(); |
| 98 | if (ret != EFI_SUCCESS) |
| 99 | goto out; |
| 100 | #endif |
| 101 | ret = efi_watchdog_register(); |
| 102 | if (ret != EFI_SUCCESS) |
| 103 | goto out; |
| 104 | |
| 105 | /* Initialize EFI runtime services */ |
| 106 | ret = efi_reset_system_init(); |
| 107 | if (ret != EFI_SUCCESS) |
| 108 | goto out; |
| 109 | |
| 110 | out: |
| 111 | efi_obj_list_initialized = ret; |
| 112 | return ret; |
| 113 | } |