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