blob: 87db51cbb74fa58c67fd5462e22ce67ca4b55afd [file] [log] [blame]
AKASHI Takahiro7e0badb2018-12-30 15:16:55 +01001// 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
13static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
14
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020015/**
16 * efi_init_platform_lang() - define supported languages
17 *
18 * Set the PlatformLangCodes and PlatformLang variables.
19 *
20 * Return: status code
21 */
22static efi_status_t efi_init_platform_lang(void)
AKASHI Takahiro7e0badb2018-12-30 15:16:55 +010023{
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020024 efi_status_t ret;
25 efi_uintn_t data_size = 0;
26 char *lang = CONFIG_EFI_PLATFORM_LANG_CODES;
27 char *pos;
AKASHI Takahiro7e0badb2018-12-30 15:16:55 +010028
29 /*
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020030 * Variable PlatformLangCodes defines the language codes that the
31 * machine can support.
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020032 */
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020033 ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes",
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020034 &efi_global_variable_guid,
35 EFI_VARIABLE_BOOTSERVICE_ACCESS |
36 EFI_VARIABLE_RUNTIME_ACCESS,
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020037 sizeof(CONFIG_EFI_PLATFORM_LANG_CODES),
38 CONFIG_EFI_PLATFORM_LANG_CODES));
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020039 if (ret != EFI_SUCCESS)
40 goto out;
41
42 /*
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020043 * Variable PlatformLang defines the language that the machine has been
44 * configured for.
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020045 */
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020046 ret = EFI_CALL(efi_get_variable(L"PlatformLang",
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020047 &efi_global_variable_guid,
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020048 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 Schuchardtf7fe45b2019-04-05 02:45:21 +020066 EFI_VARIABLE_BOOTSERVICE_ACCESS |
67 EFI_VARIABLE_RUNTIME_ACCESS,
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020068 1 + strlen(lang), lang));
69out:
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020070 if (ret != EFI_SUCCESS)
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020071 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 */
80efi_status_t efi_init_obj_list(void)
81{
AKASHI Takahiro3a489252019-04-24 15:30:38 +090082 u64 os_indications_supported = 0; /* None */
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020083 efi_status_t ret = EFI_SUCCESS;
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020084
AKASHI Takahiro7e0badb2018-12-30 15:16:55 +010085 /* Initialize once only */
86 if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
87 return efi_obj_list_initialized;
88
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020089 /* Define supported languages */
90 ret = efi_init_platform_lang();
91 if (ret != EFI_SUCCESS)
92 goto out;
93
AKASHI Takahiro3a489252019-04-24 15:30:38 +090094 /* 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 Takahiro7e0badb2018-12-30 15:16:55 +0100104 /* 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
156out:
157 efi_obj_list_initialized = ret;
158 return ret;
159}