]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c
MdeModulePkg: Make HII configuration settings available to OS runtime
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / HiiDatabaseEntry.c
1 /** @file
2 This file contains the entry code to the HII database, which is defined by
3 UEFI 2.1 specification.
4
5 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 //
20 // Global variables
21 //
22 EFI_EVENT gHiiKeyboardLayoutChanged;
23 BOOLEAN gExportAfterReadyToBoot = FALSE;
24
25 HII_DATABASE_PRIVATE_DATA mPrivate = {
26 HII_DATABASE_PRIVATE_DATA_SIGNATURE,
27 {
28 (LIST_ENTRY *) NULL,
29 (LIST_ENTRY *) NULL
30 },
31 {
32 (LIST_ENTRY *) NULL,
33 (LIST_ENTRY *) NULL
34 },
35 {
36 HiiStringToImage,
37 HiiStringIdToImage,
38 HiiGetGlyph,
39 HiiGetFontInfo
40 },
41 {
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL
47 },
48 {
49 HiiNewString,
50 HiiGetString,
51 HiiSetString,
52 HiiGetLanguages,
53 HiiGetSecondaryLanguages
54 },
55 {
56 HiiNewPackageList,
57 HiiRemovePackageList,
58 HiiUpdatePackageList,
59 HiiListPackageLists,
60 HiiExportPackageLists,
61 HiiRegisterPackageNotify,
62 HiiUnregisterPackageNotify,
63 HiiFindKeyboardLayouts,
64 HiiGetKeyboardLayout,
65 HiiSetKeyboardLayout,
66 HiiGetPackageListHandle
67 },
68 {
69 HiiConfigRoutingExtractConfig,
70 HiiConfigRoutingExportConfig,
71 HiiConfigRoutingRouteConfig,
72 HiiBlockToConfig,
73 HiiConfigToBlock,
74 HiiGetAltCfg
75 },
76 {
77 EfiConfigKeywordHandlerSetData,
78 EfiConfigKeywordHandlerGetData
79 },
80 {
81 (LIST_ENTRY *) NULL,
82 (LIST_ENTRY *) NULL
83 },
84 0,
85 {
86 (LIST_ENTRY *) NULL,
87 (LIST_ENTRY *) NULL
88 },
89 EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK),
90 {
91 0x00000000,
92 0x0000,
93 0x0000,
94 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
95 },
96 NULL
97 };
98
99 GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_IMAGE_PROTOCOL mImageProtocol = {
100 HiiNewImage,
101 HiiGetImage,
102 HiiSetImage,
103 HiiDrawImage,
104 HiiDrawImageId
105 };
106
107 /**
108 The default event handler for gHiiKeyboardLayoutChanged
109 event group.
110
111 This is internal function.
112
113 @param Event The event that triggered this notification function.
114 @param Context Pointer to the notification functions context.
115
116 **/
117 VOID
118 EFIAPI
119 KeyboardLayoutChangeNullEvent (
120 IN EFI_EVENT Event,
121 IN VOID *Context
122 )
123 {
124 return;
125 }
126
127 /**
128 On Ready To Boot Services Event notification handler.
129
130 To trigger the function that to export the Hii Configuration setting.
131
132 @param[in] Event Event whose notification function is being invoked
133 @param[in] Context Pointer to the notification function's context
134
135 **/
136 VOID
137 EFIAPI
138 OnReadyToBoot (
139 IN EFI_EVENT Event,
140 IN VOID *Context
141 )
142 {
143 //
144 // When ready to boot, we begin to export the HiiDatabase date.
145 // And hook all the possible HiiDatabase change actions to export data.
146 //
147 HiiGetConfigurationSetting(&mPrivate.HiiDatabase);
148 gExportAfterReadyToBoot = TRUE;
149 }
150
151 /**
152 Initialize HII Database.
153
154
155 @param ImageHandle The image handle.
156 @param SystemTable The system table.
157
158 @retval EFI_SUCCESS The Hii database is setup correctly.
159 @return Other value if failed to create the default event for
160 gHiiKeyboardLayoutChanged. Check gBS->CreateEventEx for
161 details. Or failed to insatll the protocols.
162 Check gBS->InstallMultipleProtocolInterfaces for details.
163 Or failed to create Ready To Boot Event.
164 Check EfiCreateEventReadyToBootEx for details.
165
166 **/
167 EFI_STATUS
168 EFIAPI
169 InitializeHiiDatabase (
170 IN EFI_HANDLE ImageHandle,
171 IN EFI_SYSTEM_TABLE *SystemTable
172 )
173 {
174 EFI_STATUS Status;
175 EFI_HANDLE Handle;
176 EFI_EVENT ReadyToBootEvent;
177
178 //
179 // There will be only one HII Database in the system
180 // If there is another out there, someone is trying to install us
181 // again. Fail that scenario.
182 //
183 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiDatabaseProtocolGuid);
184 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiFontProtocolGuid);
185 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiImageProtocolGuid);
186 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiStringProtocolGuid);
187 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiHiiConfigRoutingProtocolGuid);
188 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiConfigKeywordHandlerProtocolGuid);
189
190 InitializeListHead (&mPrivate.DatabaseList);
191 InitializeListHead (&mPrivate.DatabaseNotifyList);
192 InitializeListHead (&mPrivate.HiiHandleList);
193 InitializeListHead (&mPrivate.FontInfoList);
194
195 //
196 // Create a event with EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group type.
197 //
198 Status = gBS->CreateEventEx (
199 EVT_NOTIFY_SIGNAL,
200 TPL_NOTIFY,
201 KeyboardLayoutChangeNullEvent,
202 NULL,
203 &gEfiHiiKeyBoardLayoutGuid,
204 &gHiiKeyboardLayoutChanged
205 );
206 if (EFI_ERROR (Status)) {
207 return Status;
208 }
209
210 Handle = NULL;
211 Status = gBS->InstallMultipleProtocolInterfaces (
212 &Handle,
213 &gEfiHiiFontProtocolGuid,
214 &mPrivate.HiiFont,
215 &gEfiHiiStringProtocolGuid,
216 &mPrivate.HiiString,
217 &gEfiHiiDatabaseProtocolGuid,
218 &mPrivate.HiiDatabase,
219 &gEfiHiiConfigRoutingProtocolGuid,
220 &mPrivate.ConfigRouting,
221 &gEfiConfigKeywordHandlerProtocolGuid,
222 &mPrivate.ConfigKeywordHandler,
223 NULL
224 );
225
226 if (EFI_ERROR (Status)) {
227 return Status;
228 }
229
230 if (FeaturePcdGet (PcdSupportHiiImageProtocol)) {
231 CopyMem (&mPrivate.HiiImage, &mImageProtocol, sizeof (mImageProtocol));
232
233 Status = gBS->InstallMultipleProtocolInterfaces (
234 &Handle,
235 &gEfiHiiImageProtocolGuid,
236 &mPrivate.HiiImage,
237 NULL
238 );
239
240 }
241
242 if (FeaturePcdGet(PcdHiiOsRuntimeSupport)) {
243 Status = EfiCreateEventReadyToBootEx (
244 TPL_CALLBACK,
245 OnReadyToBoot,
246 NULL,
247 &ReadyToBootEvent
248 );
249 if (EFI_ERROR (Status)) {
250 return Status;
251 }
252 }
253
254 return Status;
255 }
256