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