]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
Update the function headers to Doxygen format.
[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 processes the results of changes in configuration.
44
45
46 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
47 @param Action Specifies the type of action taken by the browser.
48 @param QuestionId A unique value which is sent to the original exporting driver
49 so that it can identify the type of data to expect.
50 @param Type The type of value for the question.
51 @param Value A pointer to the data being sent to the original exporting driver.
52 @param ActionRequest On return, points to the action requested by the callback function.
53
54 @retval EFI_SUCCESS The callback successfully handled the action.
55 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
56 @retval EFI_DEVICE_ERROR The variable could not be saved.
57 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
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 Initialize HII information for the FrontPage
116
117
118 @param VOID EDES_TODO: Add parameter description
119
120 @return EDES_TODO: Add description for return value
121
122 **/
123 EFI_STATUS
124 InitializeDeviceManager (
125 VOID
126 )
127 {
128 EFI_STATUS Status;
129 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
130
131 //
132 // Create driver handle used by HII database
133 //
134 Status = HiiLibCreateHiiDriverHandle (&gDeviceManagerPrivate.DriverHandle);
135 if (EFI_ERROR (Status)) {
136 return Status;
137 }
138
139 //
140 // Install Config Access protocol to driver handle
141 //
142 Status = gBS->InstallProtocolInterface (
143 &gDeviceManagerPrivate.DriverHandle,
144 &gEfiHiiConfigAccessProtocolGuid,
145 EFI_NATIVE_INTERFACE,
146 &gDeviceManagerPrivate.ConfigAccess
147 );
148 ASSERT_EFI_ERROR (Status);
149
150 //
151 // Publish our HII data
152 //
153 PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings);
154 ASSERT (PackageList != NULL);
155
156 Status = gHiiDatabase->NewPackageList (
157 gHiiDatabase,
158 PackageList,
159 gDeviceManagerPrivate.DriverHandle,
160 &gDeviceManagerPrivate.HiiHandle
161 );
162 FreePool (PackageList);
163
164 return Status;
165 }
166
167 /**
168
169 Call the browser and display the device manager
170
171
172 @param VOID EDES_TODO: Add parameter description
173
174 @retval EFI_SUCCESS Operation is successful.
175 @retval EFI_INVALID_PARAMETER If the inputs to SendForm function is not valid.
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 //
352 // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION
353 //
354 gBS->RestoreTPL (TPL_APPLICATION);
355
356 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
357 Status = gFormBrowser2->SendForm (
358 gFormBrowser2,
359 &HiiHandle,
360 1,
361 NULL,
362 0,
363 NULL,
364 &ActionRequest
365 );
366 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
367 EnableResetRequired ();
368 }
369
370 //
371 // We will have returned from processing a callback - user either hit ESC to exit, or selected
372 // a target to display
373 //
374 if (gCallbackKey != 0) {
375 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
376 Status = gFormBrowser2->SendForm (
377 gFormBrowser2,
378 &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],
379 1,
380 NULL,
381 0,
382 NULL,
383 &ActionRequest
384 );
385
386 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
387 EnableResetRequired ();
388 }
389
390 //
391 // Force return to Device Manager
392 //
393 gCallbackKey = FRONT_PAGE_KEY_DEVICE_MANAGER;
394 }
395
396 //
397 // Cleanup dynamic created strings in HII database by reinstall the packagelist
398 //
399 gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);
400 PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings);
401 ASSERT (PackageList != NULL);
402 Status = gHiiDatabase->NewPackageList (
403 gHiiDatabase,
404 PackageList,
405 gDeviceManagerPrivate.DriverHandle,
406 &gDeviceManagerPrivate.HiiHandle
407 );
408 FreePool (PackageList);
409
410 for (Index = 0; Index < MENU_ITEM_NUM; Index++) {
411 FreePool (UpdateData[Index].Data);
412 }
413 FreePool (HiiHandles);
414
415 gBS->RaiseTPL (TPL_APPLICATION);
416
417 return Status;
418 }