AKASHI Takahiro | 7e0badb | 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 | |
| 13 | static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED; |
| 14 | |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 15 | /** |
| 16 | * efi_init_platform_lang() - define supported languages |
| 17 | * |
| 18 | * Set the PlatformLangCodes and PlatformLang variables. |
| 19 | * |
| 20 | * Return: status code |
| 21 | */ |
| 22 | static efi_status_t efi_init_platform_lang(void) |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 23 | { |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 24 | efi_status_t ret; |
| 25 | efi_uintn_t data_size = 0; |
| 26 | char *lang = CONFIG_EFI_PLATFORM_LANG_CODES; |
| 27 | char *pos; |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 28 | |
| 29 | /* |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 30 | * Variable PlatformLangCodes defines the language codes that the |
| 31 | * machine can support. |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 32 | */ |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 33 | ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes", |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 34 | &efi_global_variable_guid, |
| 35 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 36 | EFI_VARIABLE_RUNTIME_ACCESS, |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 37 | sizeof(CONFIG_EFI_PLATFORM_LANG_CODES), |
| 38 | CONFIG_EFI_PLATFORM_LANG_CODES)); |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 39 | if (ret != EFI_SUCCESS) |
| 40 | goto out; |
| 41 | |
| 42 | /* |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 43 | * Variable PlatformLang defines the language that the machine has been |
| 44 | * configured for. |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 45 | */ |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 46 | ret = EFI_CALL(efi_get_variable(L"PlatformLang", |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 47 | &efi_global_variable_guid, |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 48 | NULL, &data_size, &pos)); |
| 49 | if (ret == EFI_BUFFER_TOO_SMALL) { |
| 50 | /* The variable is already set. Do not change it. */ |
| 51 | ret = EFI_SUCCESS; |
| 52 | goto out; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * The list of supported languages is semicolon separated. Use the first |
| 57 | * language to initialize PlatformLang. |
| 58 | */ |
| 59 | pos = strchr(lang, ';'); |
| 60 | if (pos) |
| 61 | *pos = 0; |
| 62 | |
| 63 | ret = EFI_CALL(efi_set_variable(L"PlatformLang", |
| 64 | &efi_global_variable_guid, |
| 65 | EFI_VARIABLE_NON_VOLATILE | |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 66 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 67 | EFI_VARIABLE_RUNTIME_ACCESS, |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 68 | 1 + strlen(lang), lang)); |
| 69 | out: |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 70 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 71 | printf("EFI: cannot initialize platform language settings\n"); |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * efi_init_obj_list() - Initialize and populate EFI object list |
| 77 | * |
| 78 | * Return: status code |
| 79 | */ |
| 80 | efi_status_t efi_init_obj_list(void) |
| 81 | { |
AKASHI Takahiro | 3a48925 | 2019-04-24 15:30:38 +0900 | [diff] [blame] | 82 | u64 os_indications_supported = 0; /* None */ |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 83 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | f7fe45b | 2019-04-05 02:45:21 +0200 | [diff] [blame] | 84 | |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 85 | /* Initialize once only */ |
| 86 | if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) |
| 87 | return efi_obj_list_initialized; |
| 88 | |
Heinrich Schuchardt | 3700d57 | 2019-04-11 07:34:24 +0200 | [diff] [blame] | 89 | /* Define supported languages */ |
| 90 | ret = efi_init_platform_lang(); |
| 91 | if (ret != EFI_SUCCESS) |
| 92 | goto out; |
| 93 | |
AKASHI Takahiro | 3a48925 | 2019-04-24 15:30:38 +0900 | [diff] [blame] | 94 | /* Indicate supported features */ |
| 95 | ret = EFI_CALL(efi_set_variable(L"OsIndicationsSupported", |
| 96 | &efi_global_variable_guid, |
| 97 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 98 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 99 | sizeof(os_indications_supported), |
| 100 | &os_indications_supported)); |
| 101 | if (ret != EFI_SUCCESS) |
| 102 | goto out; |
| 103 | |
AKASHI Takahiro | 7e0badb | 2018-12-30 15:16:55 +0100 | [diff] [blame] | 104 | /* Initialize system table */ |
| 105 | ret = efi_initialize_system_table(); |
| 106 | if (ret != EFI_SUCCESS) |
| 107 | goto out; |
| 108 | |
| 109 | /* Initialize root node */ |
| 110 | ret = efi_root_node_register(); |
| 111 | if (ret != EFI_SUCCESS) |
| 112 | goto out; |
| 113 | |
| 114 | /* Initialize EFI driver uclass */ |
| 115 | ret = efi_driver_init(); |
| 116 | if (ret != EFI_SUCCESS) |
| 117 | goto out; |
| 118 | |
| 119 | ret = efi_console_register(); |
| 120 | if (ret != EFI_SUCCESS) |
| 121 | goto out; |
| 122 | #ifdef CONFIG_PARTITIONS |
| 123 | ret = efi_disk_register(); |
| 124 | if (ret != EFI_SUCCESS) |
| 125 | goto out; |
| 126 | #endif |
| 127 | #if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO) |
| 128 | ret = efi_gop_register(); |
| 129 | if (ret != EFI_SUCCESS) |
| 130 | goto out; |
| 131 | #endif |
| 132 | #ifdef CONFIG_NET |
| 133 | ret = efi_net_register(); |
| 134 | if (ret != EFI_SUCCESS) |
| 135 | goto out; |
| 136 | #endif |
| 137 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
| 138 | ret = efi_acpi_register(); |
| 139 | if (ret != EFI_SUCCESS) |
| 140 | goto out; |
| 141 | #endif |
| 142 | #ifdef CONFIG_GENERATE_SMBIOS_TABLE |
| 143 | ret = efi_smbios_register(); |
| 144 | if (ret != EFI_SUCCESS) |
| 145 | goto out; |
| 146 | #endif |
| 147 | ret = efi_watchdog_register(); |
| 148 | if (ret != EFI_SUCCESS) |
| 149 | goto out; |
| 150 | |
| 151 | /* Initialize EFI runtime services */ |
| 152 | ret = efi_reset_system_init(); |
| 153 | if (ret != EFI_SUCCESS) |
| 154 | goto out; |
| 155 | |
| 156 | out: |
| 157 | efi_obj_list_initialized = ret; |
| 158 | return ret; |
| 159 | } |