blob: b32a7b3f9346637d2719251aefafad683dd36982 [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{
82 efi_status_t ret = EFI_SUCCESS;
Heinrich Schuchardtf7fe45b2019-04-05 02:45:21 +020083
AKASHI Takahiro7e0badb2018-12-30 15:16:55 +010084 /* Initialize once only */
85 if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
86 return efi_obj_list_initialized;
87
Heinrich Schuchardt3700d572019-04-11 07:34:24 +020088 /* Define supported languages */
89 ret = efi_init_platform_lang();
90 if (ret != EFI_SUCCESS)
91 goto out;
92
AKASHI Takahiro7e0badb2018-12-30 15:16:55 +010093 /* Initialize system table */
94 ret = efi_initialize_system_table();
95 if (ret != EFI_SUCCESS)
96 goto out;
97
98 /* Initialize root node */
99 ret = efi_root_node_register();
100 if (ret != EFI_SUCCESS)
101 goto out;
102
103 /* Initialize EFI driver uclass */
104 ret = efi_driver_init();
105 if (ret != EFI_SUCCESS)
106 goto out;
107
108 ret = efi_console_register();
109 if (ret != EFI_SUCCESS)
110 goto out;
111#ifdef CONFIG_PARTITIONS
112 ret = efi_disk_register();
113 if (ret != EFI_SUCCESS)
114 goto out;
115#endif
116#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
117 ret = efi_gop_register();
118 if (ret != EFI_SUCCESS)
119 goto out;
120#endif
121#ifdef CONFIG_NET
122 ret = efi_net_register();
123 if (ret != EFI_SUCCESS)
124 goto out;
125#endif
126#ifdef CONFIG_GENERATE_ACPI_TABLE
127 ret = efi_acpi_register();
128 if (ret != EFI_SUCCESS)
129 goto out;
130#endif
131#ifdef CONFIG_GENERATE_SMBIOS_TABLE
132 ret = efi_smbios_register();
133 if (ret != EFI_SUCCESS)
134 goto out;
135#endif
136 ret = efi_watchdog_register();
137 if (ret != EFI_SUCCESS)
138 goto out;
139
140 /* Initialize EFI runtime services */
141 ret = efi_reset_system_init();
142 if (ret != EFI_SUCCESS)
143 goto out;
144
145out:
146 efi_obj_list_initialized = ret;
147 return ret;
148}