1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2016-2018 Alexander Graf et al.
10 #include <efi_loader.h>
12 #define OBJ_LIST_NOT_INITIALIZED 1
14 static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
17 * Allow unaligned memory access.
19 * This routine is overridden by architectures providing this feature.
21 void __weak allow_unaligned(void)
26 * efi_init_platform_lang() - define supported languages
28 * Set the PlatformLangCodes and PlatformLang variables.
32 static efi_status_t efi_init_platform_lang(void)
35 efi_uintn_t data_size = 0;
36 char *lang = CONFIG_EFI_PLATFORM_LANG_CODES;
40 * Variable PlatformLangCodes defines the language codes that the
41 * machine can support.
43 ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes",
44 &efi_global_variable_guid,
45 EFI_VARIABLE_BOOTSERVICE_ACCESS |
46 EFI_VARIABLE_RUNTIME_ACCESS,
47 sizeof(CONFIG_EFI_PLATFORM_LANG_CODES),
48 CONFIG_EFI_PLATFORM_LANG_CODES));
49 if (ret != EFI_SUCCESS)
53 * Variable PlatformLang defines the language that the machine has been
56 ret = EFI_CALL(efi_get_variable(L"PlatformLang",
57 &efi_global_variable_guid,
58 NULL, &data_size, &pos));
59 if (ret == EFI_BUFFER_TOO_SMALL) {
60 /* The variable is already set. Do not change it. */
66 * The list of supported languages is semicolon separated. Use the first
67 * language to initialize PlatformLang.
69 pos = strchr(lang, ';');
73 ret = EFI_CALL(efi_set_variable(L"PlatformLang",
74 &efi_global_variable_guid,
75 EFI_VARIABLE_NON_VOLATILE |
76 EFI_VARIABLE_BOOTSERVICE_ACCESS |
77 EFI_VARIABLE_RUNTIME_ACCESS,
78 1 + strlen(lang), lang));
80 if (ret != EFI_SUCCESS)
81 printf("EFI: cannot initialize platform language settings\n");
86 * efi_init_obj_list() - Initialize and populate EFI object list
90 efi_status_t efi_init_obj_list(void)
92 u64 os_indications_supported = 0; /* None */
93 efi_status_t ret = EFI_SUCCESS;
95 /* Initialize once only */
96 if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
97 return efi_obj_list_initialized;
99 /* Allow unaligned memory access */
102 /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */
103 switch_to_non_secure_mode();
105 /* Define supported languages */
106 ret = efi_init_platform_lang();
107 if (ret != EFI_SUCCESS)
110 /* Indicate supported features */
111 ret = EFI_CALL(efi_set_variable(L"OsIndicationsSupported",
112 &efi_global_variable_guid,
113 EFI_VARIABLE_BOOTSERVICE_ACCESS |
114 EFI_VARIABLE_RUNTIME_ACCESS,
115 sizeof(os_indications_supported),
116 &os_indications_supported));
117 if (ret != EFI_SUCCESS)
120 /* Initialize system table */
121 ret = efi_initialize_system_table();
122 if (ret != EFI_SUCCESS)
125 /* Initialize root node */
126 ret = efi_root_node_register();
127 if (ret != EFI_SUCCESS)
130 /* Initialize EFI driver uclass */
131 ret = efi_driver_init();
132 if (ret != EFI_SUCCESS)
135 ret = efi_console_register();
136 if (ret != EFI_SUCCESS)
138 #ifdef CONFIG_PARTITIONS
139 ret = efi_disk_register();
140 if (ret != EFI_SUCCESS)
143 #if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
144 ret = efi_gop_register();
145 if (ret != EFI_SUCCESS)
149 ret = efi_net_register();
150 if (ret != EFI_SUCCESS)
153 #ifdef CONFIG_GENERATE_ACPI_TABLE
154 ret = efi_acpi_register();
155 if (ret != EFI_SUCCESS)
158 #ifdef CONFIG_GENERATE_SMBIOS_TABLE
159 ret = efi_smbios_register();
160 if (ret != EFI_SUCCESS)
163 ret = efi_watchdog_register();
164 if (ret != EFI_SUCCESS)
167 /* Initialize EFI runtime services */
168 ret = efi_reset_system_init();
169 if (ret != EFI_SUCCESS)
173 efi_obj_list_initialized = ret;