]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
Remove unnecessary TPL operations in BDS module & library.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / DeviceMngr / DeviceManager.c
1 /** @file
2 The platform device manager reference implement
3
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DeviceManager.h"
16
17 DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,
19 NULL,
20 NULL,
21 {
22 FakeExtractConfig,
23 FakeRouteConfig,
24 DeviceManagerCallback
25 }
26 };
27
28 EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;
29
30 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = {
31 { STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS },
32 { STRING_TOKEN (STR_VIDEO_DEVICE), EFI_VIDEO_DEVICE_CLASS },
33 { STRING_TOKEN (STR_NETWORK_DEVICE), EFI_NETWORK_DEVICE_CLASS },
34 { STRING_TOKEN (STR_INPUT_DEVICE), EFI_INPUT_DEVICE_CLASS },
35 { STRING_TOKEN (STR_ON_BOARD_DEVICE), EFI_ON_BOARD_DEVICE_CLASS },
36 { STRING_TOKEN (STR_OTHER_DEVICE), EFI_OTHER_DEVICE_CLASS }
37 };
38
39 #define MENU_ITEM_NUM \
40 (sizeof (mDeviceManagerMenuItemTable) / sizeof (DEVICE_MANAGER_MENU_ITEM))
41
42 /**
43 This function is invoked if user selected a iteractive opcode from Device Manager's
44 Formset. The decision by user is saved to gCallbackKey for later processing. If
45 user set VBIOS, the new value is saved to EFI variable.
46
47
48 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
49 @param Action Specifies the type of action taken by the browser.
50 @param QuestionId A unique value which is sent to the original exporting driver
51 so that it can identify the type of data to expect.
52 @param Type The type of value for the question.
53 @param Value A pointer to the data being sent to the original exporting driver.
54 @param ActionRequest On return, points to the action requested by the callback function.
55
56 @retval EFI_SUCCESS The callback successfully handled the action.
57 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
58
59 **/
60 EFI_STATUS
61 EFIAPI
62 DeviceManagerCallback (
63 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
64 IN EFI_BROWSER_ACTION Action,
65 IN EFI_QUESTION_ID QuestionId,
66 IN UINT8 Type,
67 IN EFI_IFR_TYPE_VALUE *Value,
68 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
69 )
70 {
71 DEVICE_MANAGER_CALLBACK_DATA *PrivateData;
72
73 if ((Value == NULL) || (ActionRequest == NULL)) {
74 return EFI_INVALID_PARAMETER;
75 }
76
77 PrivateData = DEVICE_MANAGER_CALLBACK_DATA_FROM_THIS (This);
78
79 switch (QuestionId) {
80 case DEVICE_MANAGER_KEY_VBIOS:
81 PrivateData->VideoBios = Value->u8;
82 gRT->SetVariable (
83 L"VBIOS",
84 &gEfiGenericPlatformVariableGuid,
85 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
86 sizeof (UINT8),
87 &PrivateData->VideoBios
88 );
89
90 //
91 // Tell browser not to ask for confirmation of changes,
92 // since we have already applied.
93 //
94 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
95 break;
96
97 default:
98 //
99 // The key corresponds the Handle Index which was requested to be displayed
100 //
101 gCallbackKey = QuestionId;
102
103 //
104 // Request to exit SendForm(), so as to switch to selected form
105 //
106 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
107 break;
108 }
109
110 return EFI_SUCCESS;
111 }
112
113 /**
114
115 This function registers HII packages to HII database.
116
117 @retval EFI_SUCCESS This function complete successfully.
118 @return Other value if failed to register HII packages.
119
120 **/
121 EFI_STATUS
122 InitializeDeviceManager (
123 VOID
124 )
125 {
126 EFI_STATUS Status;
127 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
128
129 //
130 // Create driver handle used by HII database
131 //
132 Status = HiiLibCreateHiiDriverHandle (&gDeviceManagerPrivate.DriverHandle);
133 if (EFI_ERROR (Status)) {
134 return Status;
135 }
136
137 //
138 // Install Config Access protocol to driver handle
139 //
140 Status = gBS->InstallProtocolInterface (
141 &gDeviceManagerPrivate.DriverHandle,
142 &gEfiHiiConfigAccessProtocolGuid,
143 EFI_NATIVE_INTERFACE,
144 &gDeviceManagerPrivate.ConfigAccess
145 );
146 ASSERT_EFI_ERROR (Status);
147
148 //
149 // Publish our HII data
150 //
151 PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings);
152 ASSERT (PackageList != NULL);
153
154 Status = gHiiDatabase->NewPackageList (
155 gHiiDatabase,
156 PackageList,
157 gDeviceManagerPrivate.DriverHandle,
158 &gDeviceManagerPrivate.HiiHandle
159 );
160 FreePool (PackageList);
161
162 return Status;
163 }
164
165 /**
166
167 Call the browser and display the device manager to allow user
168 to configure the platform.
169
170 This function create the dynamic content for device manager. It includes
171 section header for all class of devices, one-of opcode to set VBIOS.
172
173 @retval EFI_SUCCESS Operation is successful.
174 @retval Other values if failed to clean up the dynamic content from HII
175 database.
176
177 **/
178 EFI_STATUS
179 CallDeviceManager (
180 VOID
181 )
182 {
183 EFI_STATUS Status;
184 UINTN Count;
185 UINTN Index;
186 CHAR16 *String;
187 UINTN StringLength;
188 EFI_HII_UPDATE_DATA UpdateData[MENU_ITEM_NUM];
189 EFI_STRING_ID Token;
190 EFI_STRING_ID TokenHelp;
191 IFR_OPTION *IfrOptionList;
192 UINT8 *VideoOption;
193 UINTN VideoOptionSize;
194 EFI_HII_HANDLE *HiiHandles;
195 UINTN HandleBufferLength;
196 UINTN NumberOfHiiHandles;
197 EFI_HII_HANDLE HiiHandle;
198 UINT16 FormSetClass;
199 EFI_STRING_ID FormSetTitle;
200 EFI_STRING_ID FormSetHelp;
201 EFI_BROWSER_ACTION_REQUEST ActionRequest;
202 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
203
204 IfrOptionList = NULL;
205 VideoOption = NULL;
206 HiiHandles = NULL;
207 HandleBufferLength = 0;
208
209 Status = EFI_SUCCESS;
210 gCallbackKey = 0;
211
212 //
213 // Connect all prior to entering the platform setup menu.
214 //
215 if (!gConnectAllHappened) {
216 BdsLibConnectAllDriversToAllControllers ();
217 gConnectAllHappened = TRUE;
218 }
219
220 //
221 // Create Subtitle OpCodes
222 //
223 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
224 //
225 // Allocate space for creation of UpdateData Buffer
226 //
227 UpdateData[Index].BufferSize = 0x1000;
228 UpdateData[Index].Offset = 0;
229 UpdateData[Index].Data = AllocatePool (0x1000);
230 ASSERT (UpdateData[Index].Data != NULL);
231
232 CreateSubTitleOpCode (mDeviceManagerMenuItemTable[Index].StringId, 0, 0, 1, &UpdateData[Index]);
233 }
234
235 //
236 // Get all the Hii handles
237 //
238 Status = HiiLibGetHiiHandles (&HandleBufferLength, &HiiHandles);
239 ASSERT_EFI_ERROR (Status);
240
241 HiiHandle = gDeviceManagerPrivate.HiiHandle;
242
243 StringLength = 0x1000;
244 String = AllocateZeroPool (StringLength);
245 ASSERT (String != NULL);
246
247 //
248 // Search for formset of each class type
249 //
250 NumberOfHiiHandles = HandleBufferLength / sizeof (EFI_HII_HANDLE);
251 for (Index = 0; Index < NumberOfHiiHandles; Index++) {
252 IfrLibExtractClassFromHiiHandle (HiiHandles[Index], &FormSetClass, &FormSetTitle, &FormSetHelp);
253
254 if (FormSetClass == EFI_NON_DEVICE_CLASS) {
255 continue;
256 }
257
258 Token = 0;
259 *String = 0;
260 StringLength = 0x1000;
261 HiiLibGetString (HiiHandles[Index], FormSetTitle, String, &StringLength);
262 HiiLibNewString (HiiHandle, &Token, String);
263
264 TokenHelp = 0;
265 *String = 0;
266 StringLength = 0x1000;
267 HiiLibGetString (HiiHandles[Index], FormSetHelp, String, &StringLength);
268 HiiLibNewString (HiiHandle, &TokenHelp, String);
269
270 for (Count = 0; Count < MENU_ITEM_NUM; Count++) {
271 if (FormSetClass & mDeviceManagerMenuItemTable[Count].Class) {
272 CreateActionOpCode (
273 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
274 Token,
275 TokenHelp,
276 EFI_IFR_FLAG_CALLBACK,
277 0,
278 &UpdateData[Count]
279 );
280 }
281 }
282 }
283 FreePool (String);
284
285 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
286 //
287 // Add End Opcode for Subtitle
288 //
289 CreateEndOpCode (&UpdateData[Index]);
290
291 IfrLibUpdateForm (
292 HiiHandle,
293 &mDeviceManagerGuid,
294 DEVICE_MANAGER_FORM_ID,
295 mDeviceManagerMenuItemTable[Index].Class,
296 FALSE,
297 &UpdateData[Index]
298 );
299 }
300
301 //
302 // Add oneof for video BIOS selection
303 //
304 VideoOption = BdsLibGetVariableAndSize (
305 L"VBIOS",
306 &gEfiGenericPlatformVariableGuid,
307 &VideoOptionSize
308 );
309 if (NULL == VideoOption) {
310 gDeviceManagerPrivate.VideoBios = 0;
311 } else {
312 gDeviceManagerPrivate.VideoBios = VideoOption[0];
313 FreePool (VideoOption);
314 }
315
316 ASSERT (gDeviceManagerPrivate.VideoBios <= 1);
317
318 IfrOptionList = AllocatePool (2 * sizeof (IFR_OPTION));
319 ASSERT (IfrOptionList != NULL);
320 IfrOptionList[0].Flags = 0;
321 IfrOptionList[0].StringToken = STRING_TOKEN (STR_ONE_OF_PCI);
322 IfrOptionList[0].Value.u8 = 0;
323 IfrOptionList[1].Flags = 0;
324 IfrOptionList[1].StringToken = STRING_TOKEN (STR_ONE_OF_AGP);
325 IfrOptionList[1].Value.u8 = 1;
326 IfrOptionList[gDeviceManagerPrivate.VideoBios].Flags |= EFI_IFR_OPTION_DEFAULT;
327
328 UpdateData[0].Offset = 0;
329 CreateOneOfOpCode (
330 DEVICE_MANAGER_KEY_VBIOS,
331 0,
332 0,
333 STRING_TOKEN (STR_ONE_OF_VBIOS),
334 STRING_TOKEN (STR_ONE_OF_VBIOS_HELP),
335 EFI_IFR_FLAG_CALLBACK,
336 EFI_IFR_NUMERIC_SIZE_1,
337 IfrOptionList,
338 2,
339 &UpdateData[0]
340 );
341
342 IfrLibUpdateForm (
343 HiiHandle,
344 &mDeviceManagerGuid,
345 DEVICE_MANAGER_FORM_ID,
346 LABEL_VBIOS,
347 FALSE,
348 &UpdateData[0]
349 );
350
351 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
352 Status = gFormBrowser2->SendForm (
353 gFormBrowser2,
354 &HiiHandle,
355 1,
356 NULL,
357 0,
358 NULL,
359 &ActionRequest
360 );
361 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
362 EnableResetRequired ();
363 }
364
365 //
366 // We will have returned from processing a callback - user either hit ESC to exit, or selected
367 // a target to display
368 //
369 if (gCallbackKey != 0) {
370 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
371 Status = gFormBrowser2->SendForm (
372 gFormBrowser2,
373 &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],
374 1,
375 NULL,
376 0,
377 NULL,
378 &ActionRequest
379 );
380
381 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
382 EnableResetRequired ();
383 }
384
385 //
386 // Force return to Device Manager
387 //
388 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
389 }
390
391 //
392 // Cleanup dynamic created strings in HII database by reinstall the packagelist
393 //
394 gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
395 PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings);
396 ASSERT (PackageList != NULL);
397 Status = gHiiDatabase->NewPackageList (
398 gHiiDatabase,
399 PackageList,
400 gDeviceManagerPrivate.DriverHandle,
401 &gDeviceManagerPrivate.HiiHandle
402 );
403 FreePool (PackageList);
404
405 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
406 FreePool (UpdateData[Index].Data);
407 }
408 FreePool (HiiHandles);
409
410 return Status;
411 }