]>
Commit | Line | Data |
---|---|---|
bc11b829 | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006 - 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | DeviceManager.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | The platform device manager reference implement\r | |
19 | \r | |
20 | --*/\r | |
21 | //\r | |
22 | // Include common header file for this module.\r | |
23 | //\r | |
24 | #include "CommonHeader.h"\r | |
bc11b829 | 25 | #include "DeviceManager.h"\r |
26 | \r | |
27 | STATIC UINT16 mTokenCount;\r | |
28 | EFI_FRONTPAGE_CALLBACK_INFO FPCallbackInfo;\r | |
29 | extern UINTN gCallbackKey;\r | |
30 | extern EFI_FORM_BROWSER_PROTOCOL *gBrowser;\r | |
31 | extern EFI_GUID gBdsStringPackGuid;\r | |
32 | extern BOOLEAN gConnectAllHappened;\r | |
33 | \r | |
34 | STRING_REF gStringTokenTable[] = {\r | |
35 | STR_VIDEO_DEVICE,\r | |
36 | STR_NETWORK_DEVICE,\r | |
37 | STR_INPUT_DEVICE,\r | |
38 | STR_ON_BOARD_DEVICE,\r | |
39 | STR_OTHER_DEVICE,\r | |
40 | STR_EMPTY_STRING,\r | |
41 | 0xFFFF\r | |
42 | };\r | |
43 | \r | |
44 | EFI_STATUS\r | |
45 | EFIAPI\r | |
46 | DeviceManagerCallbackRoutine (\r | |
47 | IN EFI_FORM_CALLBACK_PROTOCOL *This,\r | |
48 | IN UINT16 KeyValue,\r | |
49 | IN EFI_IFR_DATA_ARRAY *DataArray,\r | |
50 | OUT EFI_HII_CALLBACK_PACKET **Packet\r | |
51 | )\r | |
52 | /*++\r | |
53 | \r | |
54 | Routine Description:\r | |
55 | \r | |
56 | This is the function that is called to provide results data to the driver. This data\r | |
57 | consists of a unique key which is used to identify what data is either being passed back\r | |
58 | or being asked for.\r | |
59 | \r | |
60 | Arguments:\r | |
61 | \r | |
62 | KeyValue - A unique value which is sent to the original exporting driver so that it\r | |
63 | can identify the type of data to expect. The format of the data tends to\r | |
64 | vary based on the op-code that geerated the callback.\r | |
65 | \r | |
66 | Data - A pointer to the data being sent to the original exporting driver.\r | |
67 | \r | |
68 | Returns:\r | |
69 | \r | |
70 | --*/\r | |
71 | {\r | |
72 | //\r | |
73 | // The KeyValue corresponds in this case to the handle which was requested to be displayed\r | |
74 | //\r | |
75 | EFI_FRONTPAGE_CALLBACK_INFO *CallbackInfo;\r | |
76 | \r | |
77 | CallbackInfo = EFI_FP_CALLBACK_DATA_FROM_THIS (This);\r | |
78 | switch (KeyValue) {\r | |
79 | case 0x2000:\r | |
80 | CallbackInfo->Data.VideoBIOS = (UINT8) (UINTN) (((EFI_IFR_DATA_ENTRY *)(DataArray + 1))->Data);\r | |
81 | gRT->SetVariable (\r | |
82 | L"VBIOS",\r | |
83 | &gEfiGenericPlatformVariableGuid,\r | |
84 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r | |
85 | sizeof (UINT8),\r | |
86 | &CallbackInfo->Data.VideoBIOS\r | |
87 | );\r | |
88 | break;\r | |
89 | \r | |
90 | default:\r | |
91 | break;\r | |
92 | }\r | |
93 | \r | |
94 | gCallbackKey = KeyValue;\r | |
95 | return EFI_SUCCESS;\r | |
96 | }\r | |
97 | \r | |
98 | EFI_STATUS\r | |
99 | InitializeDeviceManager (\r | |
100 | VOID\r | |
101 | )\r | |
102 | /*++\r | |
103 | \r | |
104 | Routine Description:\r | |
105 | \r | |
106 | Initialize HII information for the FrontPage\r | |
107 | \r | |
108 | Arguments:\r | |
109 | None\r | |
110 | \r | |
111 | Returns:\r | |
112 | \r | |
113 | --*/\r | |
114 | {\r | |
115 | EFI_STATUS Status;\r | |
116 | EFI_HII_PACKAGES *PackageList;\r | |
117 | EFI_HII_UPDATE_DATA *UpdateData;\r | |
118 | \r | |
119 | //\r | |
120 | // Allocate space for creation of UpdateData Buffer\r | |
121 | //\r | |
122 | UpdateData = AllocateZeroPool (0x1000);\r | |
123 | ASSERT (UpdateData != NULL);\r | |
124 | \r | |
125 | PackageList = PreparePackages (1, &gBdsStringPackGuid, DeviceManagerVfrBin);\r | |
126 | Status = Hii->NewPack (Hii, PackageList, &FPCallbackInfo.DevMgrHiiHandle);\r | |
127 | FreePool (PackageList);\r | |
128 | \r | |
129 | //\r | |
130 | // This example does not implement worker functions for the NV accessor functions. Only a callback evaluator\r | |
131 | //\r | |
132 | FPCallbackInfo.Signature = EFI_FP_CALLBACK_DATA_SIGNATURE;\r | |
133 | FPCallbackInfo.DevMgrCallback.NvRead = NULL;\r | |
134 | FPCallbackInfo.DevMgrCallback.NvWrite = NULL;\r | |
135 | FPCallbackInfo.DevMgrCallback.Callback = DeviceManagerCallbackRoutine;\r | |
136 | \r | |
137 | //\r | |
138 | // Install protocol interface\r | |
139 | //\r | |
140 | FPCallbackInfo.CallbackHandle = NULL;\r | |
141 | \r | |
142 | Status = gBS->InstallProtocolInterface (\r | |
143 | &FPCallbackInfo.CallbackHandle,\r | |
144 | &gEfiFormCallbackProtocolGuid,\r | |
145 | EFI_NATIVE_INTERFACE,\r | |
146 | &FPCallbackInfo.DevMgrCallback\r | |
147 | );\r | |
148 | \r | |
149 | ASSERT_EFI_ERROR (Status);\r | |
150 | \r | |
151 | //\r | |
152 | // Flag update pending in FormSet\r | |
153 | //\r | |
154 | UpdateData->FormSetUpdate = TRUE;\r | |
155 | //\r | |
156 | // Register CallbackHandle data for FormSet\r | |
157 | //\r | |
158 | UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) FPCallbackInfo.CallbackHandle;\r | |
159 | //\r | |
160 | // Simply registering the callback handle\r | |
161 | //\r | |
162 | Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) 0x0000, TRUE, UpdateData);\r | |
163 | \r | |
164 | FreePool (UpdateData);\r | |
165 | return Status;\r | |
166 | }\r | |
167 | \r | |
168 | EFI_STATUS\r | |
169 | CallDeviceManager (\r | |
170 | VOID\r | |
171 | )\r | |
172 | /*++\r | |
173 | \r | |
174 | Routine Description:\r | |
175 | \r | |
176 | Call the browser and display the device manager\r | |
177 | \r | |
178 | Arguments:\r | |
179 | \r | |
180 | None\r | |
181 | \r | |
182 | Returns:\r | |
183 | EFI_SUCCESS - Operation is successful.\r | |
184 | EFI_INVALID_PARAMETER - If the inputs to SendForm function is not valid.\r | |
185 | \r | |
186 | --*/\r | |
187 | {\r | |
188 | EFI_STATUS Status;\r | |
189 | UINTN BufferSize;\r | |
190 | UINTN Count;\r | |
191 | EFI_HII_HANDLE Index;\r | |
192 | UINT8 *Buffer;\r | |
193 | EFI_IFR_FORM_SET *FormSetData;\r | |
194 | CHAR16 *String;\r | |
195 | UINTN StringLength;\r | |
196 | EFI_HII_UPDATE_DATA *UpdateData;\r | |
197 | STRING_REF Token;\r | |
198 | STRING_REF TokenHelp;\r | |
199 | IFR_OPTION *IfrOptionList;\r | |
200 | UINT8 *VideoOption;\r | |
201 | UINTN VideoOptionSize;\r | |
202 | EFI_HII_HANDLE *HiiHandles;\r | |
203 | UINT16 HandleBufferLength;\r | |
204 | BOOLEAN BootDeviceMngrMenuResetRequired;\r | |
205 | \r | |
206 | IfrOptionList = NULL;\r | |
207 | VideoOption = NULL;\r | |
208 | HiiHandles = NULL;\r | |
209 | HandleBufferLength = 0;\r | |
210 | \r | |
211 | //\r | |
212 | // Connect all prior to entering the platform setup menu.\r | |
213 | //\r | |
214 | if (!gConnectAllHappened) {\r | |
215 | BdsLibConnectAllDriversToAllControllers ();\r | |
216 | gConnectAllHappened = TRUE;\r | |
217 | }\r | |
218 | //\r | |
219 | // Allocate space for creation of UpdateData Buffer\r | |
220 | //\r | |
221 | UpdateData = AllocateZeroPool (0x1000);\r | |
222 | ASSERT (UpdateData != NULL);\r | |
223 | \r | |
224 | Status = EFI_SUCCESS;\r | |
225 | Buffer = NULL;\r | |
226 | FormSetData = NULL;\r | |
227 | gCallbackKey = 0;\r | |
228 | if (mTokenCount == 0) {\r | |
229 | Hii->NewString (Hii, NULL, FPCallbackInfo.DevMgrHiiHandle, &mTokenCount, L" ");\r | |
230 | }\r | |
231 | \r | |
232 | Token = mTokenCount;\r | |
233 | TokenHelp = (UINT16) (Token + 1);\r | |
234 | \r | |
235 | //\r | |
236 | // Reset the menu\r | |
237 | //\r | |
238 | for (Index = 0, Count = 1; Count < 0x10000; Count <<= 1, Index++) {\r | |
239 | //\r | |
240 | // We will strip off all previous menu entries\r | |
241 | //\r | |
242 | UpdateData->DataCount = 0xFF;\r | |
243 | \r | |
244 | //\r | |
245 | // Erase entries on this label\r | |
246 | //\r | |
247 | Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) Count, FALSE, UpdateData);\r | |
248 | \r | |
249 | //\r | |
250 | // Did we reach the end of the Token Table?\r | |
251 | //\r | |
252 | if (gStringTokenTable[Index] == 0xFFFF) {\r | |
253 | break;\r | |
254 | }\r | |
255 | \r | |
256 | CreateSubTitleOpCode (gStringTokenTable[Index], &UpdateData->Data);\r | |
257 | //\r | |
258 | // Add a single menu item - in this case a subtitle for the device type\r | |
259 | //\r | |
260 | UpdateData->DataCount = 1;\r | |
261 | \r | |
262 | //\r | |
263 | // Add default title for this label\r | |
264 | //\r | |
265 | Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) Count, TRUE, UpdateData);\r | |
266 | }\r | |
267 | //\r | |
268 | // Add a space and an exit string. Remember since we add things at the label and push other things beyond the\r | |
269 | // label down, we add this in reverse order\r | |
270 | //\r | |
271 | CreateSubTitleOpCode (STRING_TOKEN (STR_EXIT_STRING), &UpdateData->Data);\r | |
272 | Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) Count, TRUE, UpdateData);\r | |
273 | CreateSubTitleOpCode (STR_EMPTY_STRING, &UpdateData->Data);\r | |
274 | Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) Count, TRUE, UpdateData);\r | |
275 | \r | |
276 | //\r | |
277 | // Get all the Hii handles\r | |
278 | //\r | |
279 | Status = BdsLibGetHiiHandles (Hii, &HandleBufferLength, &HiiHandles);\r | |
280 | ASSERT_EFI_ERROR (Status);\r | |
281 | \r | |
282 | for (Index = 1, BufferSize = 0; Index < HandleBufferLength; Index++) {\r | |
283 | //\r | |
284 | // Am not initializing Buffer since the first thing checked is the size\r | |
285 | // this way I can get the real buffersize in the smallest code size\r | |
286 | //\r | |
287 | Status = Hii->GetForms (Hii, Index, 0, &BufferSize, Buffer);\r | |
288 | \r | |
289 | if (Status != EFI_NOT_FOUND) {\r | |
290 | //\r | |
291 | // BufferSize should have the real size of the forms now\r | |
292 | //\r | |
293 | Buffer = AllocateZeroPool (BufferSize);\r | |
294 | ASSERT (Buffer != NULL);\r | |
295 | \r | |
296 | //\r | |
297 | // Am not initializing Buffer since the first thing checked is the size\r | |
298 | // this way I can get the real buffersize in the smallest code size\r | |
299 | //\r | |
300 | Status = Hii->GetForms (Hii, Index, 0, &BufferSize, Buffer);\r | |
301 | \r | |
302 | //\r | |
303 | // Skip EFI_HII_PACK_HEADER, advance to EFI_IFR_FORM_SET data.\r | |
304 | //\r | |
305 | FormSetData = (EFI_IFR_FORM_SET *) (Buffer + sizeof (EFI_HII_PACK_HEADER));\r | |
306 | \r | |
307 | //\r | |
308 | // If this formset belongs in the device manager, add it to the menu\r | |
309 | //\r | |
310 | if (FormSetData->Class != EFI_NON_DEVICE_CLASS) {\r | |
311 | \r | |
312 | StringLength = 0x1000;\r | |
313 | String = AllocateZeroPool (StringLength);\r | |
314 | ASSERT (String != NULL);\r | |
315 | \r | |
316 | Status = Hii->GetString (Hii, Index, FormSetData->FormSetTitle, TRUE, NULL, &StringLength, String);\r | |
317 | Status = Hii->NewString (Hii, NULL, FPCallbackInfo.DevMgrHiiHandle, &Token, String);\r | |
318 | \r | |
319 | //\r | |
320 | // If token value exceeded real token value - we need to add a new token values\r | |
321 | //\r | |
322 | if (Status == EFI_INVALID_PARAMETER) {\r | |
323 | Token = 0;\r | |
324 | TokenHelp = 0;\r | |
325 | Status = Hii->NewString (Hii, NULL, FPCallbackInfo.DevMgrHiiHandle, &Token, String);\r | |
326 | }\r | |
327 | \r | |
328 | StringLength = 0x1000;\r | |
329 | if (FormSetData->Help == 0) {\r | |
330 | TokenHelp = 0;\r | |
331 | } else {\r | |
332 | Status = Hii->GetString (Hii, Index, FormSetData->Help, TRUE, NULL, &StringLength, String);\r | |
333 | if (StringLength == 0x02) {\r | |
334 | TokenHelp = 0;\r | |
335 | } else {\r | |
336 | Status = Hii->NewString (Hii, NULL, FPCallbackInfo.DevMgrHiiHandle, &TokenHelp, String);\r | |
337 | if (Status == EFI_INVALID_PARAMETER) {\r | |
338 | TokenHelp = 0;\r | |
339 | Status = Hii->NewString (Hii, NULL, FPCallbackInfo.DevMgrHiiHandle, &TokenHelp, String);\r | |
340 | }\r | |
341 | }\r | |
342 | }\r | |
343 | \r | |
344 | FreePool (String);\r | |
345 | \r | |
346 | CreateGotoOpCode (\r | |
347 | 0x1000, // Device Manager Page\r | |
348 | Token, // Description String Token\r | |
349 | TokenHelp, // Description Help String Token\r | |
350 | EFI_IFR_FLAG_INTERACTIVE | EFI_IFR_FLAG_NV_ACCESS, // Flag designating callback is active\r | |
351 | (UINT16) Index, // Callback key value\r | |
352 | &UpdateData->Data // Buffer to fill with op-code\r | |
353 | );\r | |
354 | \r | |
355 | //\r | |
356 | // In the off-chance that we have lots of extra tokens allocated to the DeviceManager\r | |
357 | // this ensures we are fairly re-using the tokens instead of constantly growing the token\r | |
358 | // storage for this one handle. If we incremented the token value beyond what it normally\r | |
359 | // would use, we will fall back into the error path which seeds the token value with a 0\r | |
360 | // so that we can correctly add a token value.\r | |
361 | //\r | |
362 | if (TokenHelp == 0) {\r | |
363 | //\r | |
364 | // Since we didn't add help, only advance Token by 1\r | |
365 | //\r | |
366 | Token++;\r | |
367 | } else {\r | |
368 | Token = (UINT16) (Token + 2);\r | |
369 | TokenHelp = (UINT16) (TokenHelp + 2);\r | |
370 | }\r | |
371 | //\r | |
372 | // This for loop basically will take the Class value which is a bitmask and\r | |
373 | // update the form for every active bit. There will be a label at each bit\r | |
374 | // location. So if someone had a device which a class of EFI_DISK_DEVICE_CLASS |\r | |
375 | // EFI_ON_BOARD_DEVICE_CLASS, this routine will unwind that mask and drop the menu entry\r | |
376 | // on each corresponding label.\r | |
377 | //\r | |
378 | for (Count = 1; Count < 0x10000; Count <<= 1) {\r | |
379 | //\r | |
380 | // This is an active bit, so update the form\r | |
381 | //\r | |
382 | if (FormSetData->Class & Count) {\r | |
383 | Hii->UpdateForm (\r | |
384 | Hii,\r | |
385 | FPCallbackInfo.DevMgrHiiHandle,\r | |
386 | (EFI_FORM_LABEL) (FormSetData->Class & Count),\r | |
387 | TRUE,\r | |
388 | UpdateData\r | |
389 | );\r | |
390 | }\r | |
391 | }\r | |
392 | }\r | |
393 | \r | |
394 | BufferSize = 0;\r | |
395 | //\r | |
396 | // Reset Buffer pointer to original location\r | |
397 | //\r | |
398 | FreePool (Buffer);\r | |
399 | }\r | |
400 | }\r | |
401 | //\r | |
402 | // Add oneof for video BIOS selection\r | |
403 | //\r | |
404 | VideoOption = BdsLibGetVariableAndSize (\r | |
405 | L"VBIOS",\r | |
406 | &gEfiGenericPlatformVariableGuid,\r | |
407 | &VideoOptionSize\r | |
408 | );\r | |
409 | if (NULL == VideoOption) {\r | |
410 | FPCallbackInfo.Data.VideoBIOS = 0;\r | |
411 | } else {\r | |
412 | FPCallbackInfo.Data.VideoBIOS = VideoOption[0];\r | |
413 | FreePool (VideoOption);\r | |
414 | }\r | |
415 | \r | |
416 | ASSERT (FPCallbackInfo.Data.VideoBIOS <= 1);\r | |
417 | \r | |
418 | IfrOptionList = AllocatePool (2 * sizeof (IFR_OPTION));\r | |
419 | if (IfrOptionList != NULL) {\r | |
420 | IfrOptionList[0].Flags = EFI_IFR_FLAG_INTERACTIVE;\r | |
421 | IfrOptionList[0].Key = SET_VIDEO_BIOS_TYPE_QUESTION_ID + 0x2000;\r | |
422 | IfrOptionList[0].StringToken = STRING_TOKEN (STR_ONE_OF_PCI);\r | |
423 | IfrOptionList[0].Value = 0;\r | |
424 | IfrOptionList[0].OptionString = NULL;\r | |
425 | IfrOptionList[1].Flags = EFI_IFR_FLAG_INTERACTIVE;\r | |
426 | IfrOptionList[1].Key = SET_VIDEO_BIOS_TYPE_QUESTION_ID + 0x2000;\r | |
427 | IfrOptionList[1].StringToken = STRING_TOKEN (STR_ONE_OF_AGP);\r | |
428 | IfrOptionList[1].Value = 1;\r | |
429 | IfrOptionList[1].OptionString = NULL;\r | |
430 | IfrOptionList[FPCallbackInfo.Data.VideoBIOS].Flags |= EFI_IFR_FLAG_DEFAULT;\r | |
431 | \r | |
432 | CreateOneOfOpCode (\r | |
433 | SET_VIDEO_BIOS_TYPE_QUESTION_ID,\r | |
434 | (UINT8) 1,\r | |
435 | STRING_TOKEN (STR_ONE_OF_VBIOS),\r | |
436 | STRING_TOKEN (STR_ONE_OF_VBIOS_HELP),\r | |
437 | IfrOptionList,\r | |
438 | 2,\r | |
439 | &UpdateData->Data\r | |
440 | );\r | |
441 | \r | |
442 | UpdateData->DataCount = 4;\r | |
443 | Hii->UpdateForm (Hii, FPCallbackInfo.DevMgrHiiHandle, (EFI_FORM_LABEL) EFI_VBIOS_CLASS, TRUE, UpdateData);\r | |
444 | FreePool (IfrOptionList);\r | |
445 | }\r | |
446 | \r | |
447 | BootDeviceMngrMenuResetRequired = FALSE;\r | |
448 | Status = gBrowser->SendForm (\r | |
449 | gBrowser,\r | |
450 | TRUE, // Use the database\r | |
451 | &FPCallbackInfo.DevMgrHiiHandle, // The HII Handle\r | |
452 | 1,\r | |
453 | NULL,\r | |
454 | FPCallbackInfo.CallbackHandle,\r | |
455 | (UINT8 *) &FPCallbackInfo.Data,\r | |
456 | NULL,\r | |
457 | &BootDeviceMngrMenuResetRequired\r | |
458 | );\r | |
459 | \r | |
460 | if (BootDeviceMngrMenuResetRequired) {\r | |
461 | EnableResetRequired ();\r | |
462 | }\r | |
463 | \r | |
464 | Hii->ResetStrings (Hii, FPCallbackInfo.DevMgrHiiHandle);\r | |
465 | \r | |
466 | //\r | |
467 | // We will have returned from processing a callback - user either hit ESC to exit, or selected\r | |
468 | // a target to display\r | |
469 | //\r | |
470 | if (gCallbackKey != 0 && gCallbackKey < 0x2000) {\r | |
471 | BootDeviceMngrMenuResetRequired = FALSE;\r | |
472 | Status = gBrowser->SendForm (\r | |
473 | gBrowser,\r | |
474 | TRUE, // Use the database\r | |
475 | (EFI_HII_HANDLE *) &gCallbackKey, // The HII Handle\r | |
476 | 1,\r | |
477 | NULL,\r | |
478 | NULL, // This is the handle that the interface to the callback was installed on\r | |
479 | NULL,\r | |
480 | NULL,\r | |
481 | &BootDeviceMngrMenuResetRequired\r | |
482 | );\r | |
483 | \r | |
484 | if (BootDeviceMngrMenuResetRequired) {\r | |
485 | EnableResetRequired ();\r | |
486 | }\r | |
487 | //\r | |
488 | // Force return to Device Manager\r | |
489 | //\r | |
490 | gCallbackKey = 4;\r | |
491 | }\r | |
492 | \r | |
493 | if (gCallbackKey >= 0x2000) {\r | |
494 | gCallbackKey = 4;\r | |
495 | }\r | |
496 | \r | |
497 | FreePool (UpdateData);\r | |
498 | FreePool (HiiHandles);\r | |
499 | \r | |
500 | return Status;\r | |
501 | }\r |