]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c
Make EdkGenericBdsLib compile.
[mirror_edk2.git] / Nt32Pkg / Library / EdkGenericBdsLib / BdsMisc.c
CommitLineData
869f8e34 1/*++\r
2\r
3Copyright (c) 2006 - 2007, 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 BdsMisc.c\r
15\r
16Abstract:\r
17\r
18 Misc BDS library function\r
19\r
20--*/\r
21\r
22//\r
23// Include common header file for this module.\r
24//\r
25#include "CommonHeader.h"\r
26\r
27#define MAX_STRING_LEN 200\r
28static BOOLEAN mFeaturerSwitch = TRUE;\r
29static BOOLEAN mResetRequired = FALSE;\r
30extern UINT16 gPlatformBootTimeOutDefault;\r
31\r
32UINT16\r
33BdsLibGetTimeout (\r
34 VOID\r
35 )\r
36/*++\r
37\r
38Routine Description:\r
39\r
40 Return the default value for system Timeout variable.\r
41\r
42Arguments:\r
43\r
44 None\r
45\r
46Returns:\r
47\r
48 Timeout value.\r
49\r
50--*/\r
51{\r
52 UINT16 Timeout;\r
53 UINTN Size;\r
54 EFI_STATUS Status;\r
55\r
56 //\r
57 // Return Timeout variable or 0xffff if no valid\r
58 // Timeout variable exists.\r
59 //\r
60 Size = sizeof (UINT16);\r
61 Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);\r
62 if (!EFI_ERROR (Status)) {\r
63 return Timeout;\r
64 }\r
65 //\r
66 // To make the current EFI Automatic-Test activity possible, just add\r
67 // following code to make AutoBoot enabled when this variable is not\r
68 // present.\r
69 // This code should be removed later.\r
70 //\r
71 Timeout = gPlatformBootTimeOutDefault;\r
72\r
73 //\r
74 // Notes: Platform should set default variable if non exists on all error cases!!!\r
75 //\r
76 Status = gRT->SetVariable (\r
77 L"Timeout",\r
78 &gEfiGlobalVariableGuid,\r
79 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
80 sizeof (UINT16),\r
81 &Timeout\r
82 );\r
83 return Timeout;\r
84}\r
85\r
86VOID\r
87BdsLibLoadDrivers (\r
88 IN LIST_ENTRY *BdsDriverLists\r
89 )\r
90/*++\r
91\r
92Routine Description:\r
93\r
94 The function will go through the driver optoin link list, load and start\r
95 every driver the driver optoin device path point to.\r
96\r
97Arguments:\r
98\r
99 BdsDriverLists - The header of the current driver option link list\r
100\r
101Returns:\r
102\r
103 None\r
104\r
105--*/\r
106{\r
107 EFI_STATUS Status;\r
108 LIST_ENTRY *Link;\r
109 BDS_COMMON_OPTION *Option;\r
110 EFI_HANDLE ImageHandle;\r
111 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r
112 UINTN ExitDataSize;\r
113 CHAR16 *ExitData;\r
114 BOOLEAN ReconnectAll;\r
115\r
116 ReconnectAll = FALSE;\r
117\r
118 //\r
119 // Process the driver option\r
120 //\r
121 for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {\r
122 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
123 //\r
124 // If a load option is not marked as LOAD_OPTION_ACTIVE,\r
125 // the boot manager will not automatically load the option.\r
126 //\r
127 if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {\r
128 continue;\r
129 }\r
130 //\r
131 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,\r
132 // then all of the EFI drivers in the system will be disconnected and\r
133 // reconnected after the last driver load option is processed.\r
134 //\r
135 if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {\r
136 ReconnectAll = TRUE;\r
137 }\r
138 //\r
139 // Make sure the driver path is connected.\r
140 //\r
141 BdsLibConnectDevicePath (Option->DevicePath);\r
142\r
143 //\r
144 // Load and start the image that Driver#### describes\r
145 //\r
146 Status = gBS->LoadImage (\r
147 FALSE,\r
148 mBdsImageHandle,\r
149 Option->DevicePath,\r
150 NULL,\r
151 0,\r
152 &ImageHandle\r
153 );\r
154\r
155 if (!EFI_ERROR (Status)) {\r
156 gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, &ImageInfo);\r
157\r
158 //\r
159 // Verify whether this image is a driver, if not,\r
160 // exit it and continue to parse next load option\r
161 //\r
162 if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {\r
163 gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);\r
164 continue;\r
165 }\r
166\r
167 if (Option->LoadOptionsSize != 0) {\r
168 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;\r
169 ImageInfo->LoadOptions = Option->LoadOptions;\r
170 }\r
171 //\r
172 // Before calling the image, enable the Watchdog Timer for\r
173 // the 5 Minute period\r
174 //\r
175 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
176\r
177 Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);\r
178 DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Driver Return Status = %r\n", Status));\r
179\r
180 //\r
181 // Clear the Watchdog Timer after the image returns\r
182 //\r
183 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
184 }\r
185 }\r
186 //\r
187 // Process the LOAD_OPTION_FORCE_RECONNECT driver option\r
188 //\r
189 if (ReconnectAll) {\r
190 BdsLibDisconnectAllEfi ();\r
191 BdsLibConnectAll ();\r
192 }\r
193\r
194}\r
195\r
196EFI_STATUS\r
197BdsLibRegisterNewOption (\r
198 IN LIST_ENTRY *BdsOptionList,\r
199 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
200 IN CHAR16 *String,\r
201 IN CHAR16 *VariableName\r
202 )\r
203/*++\r
204\r
205Routine Description:\r
206\r
207 This function will register the new boot#### or driver#### option base on\r
208 the VariableName. The new registered boot#### or driver#### will be linked\r
209 to BdsOptionList and also update to the VariableName. After the boot#### or\r
210 driver#### updated, the BootOrder or DriverOrder will also be updated.\r
211\r
212Arguments:\r
213\r
214 BdsOptionList - The header of the boot#### or driver#### link list\r
215\r
216 DevicePath - The device path which the boot####\r
217 or driver#### option present\r
218\r
219 String - The description of the boot#### or driver####\r
220\r
221 VariableName - Indicate if the boot#### or driver#### option\r
222\r
223Returns:\r
224\r
225 EFI_SUCCESS - The boot#### or driver#### have been success registered\r
226\r
227 EFI_STATUS - Return the status of gRT->SetVariable ().\r
228\r
229--*/\r
230{\r
231 EFI_STATUS Status;\r
232 UINTN Index;\r
233 UINT16 MaxOptionNumber;\r
234 UINT16 RegisterOptionNumber;\r
235 UINT16 *TempOptionPtr;\r
236 UINTN TempOptionSize;\r
237 UINT16 *OptionOrderPtr;\r
238 VOID *OptionPtr;\r
239 UINTN OptionSize;\r
240 UINT8 *TempPtr;\r
241 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
242 CHAR16 *Description;\r
243 CHAR16 OptionName[10];\r
244 BOOLEAN UpdateBootDevicePath;\r
245\r
246 OptionPtr = NULL;\r
247 OptionSize = 0;\r
248 TempPtr = NULL;\r
249 OptionDevicePath = NULL;\r
250 Description = NULL;\r
251 MaxOptionNumber = 0;\r
252 OptionOrderPtr = NULL;\r
253 UpdateBootDevicePath = FALSE;\r
254 ZeroMem (OptionName, sizeof (OptionName));\r
255\r
256 TempOptionSize = 0;\r
257\r
258 TempOptionPtr = BdsLibGetVariableAndSize (\r
259 VariableName,\r
260 &gEfiGlobalVariableGuid,\r
261 &TempOptionSize\r
262 );\r
263\r
264 //\r
265 // Compare with current option variable\r
266 //\r
267 for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {\r
268 //\r
269 // Got the max option#### number\r
270 //\r
271 if (MaxOptionNumber < TempOptionPtr[Index]) {\r
272 MaxOptionNumber = TempOptionPtr[Index];\r
273 }\r
274\r
275 if (*VariableName == 'B') {\r
276 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);\r
277 } else {\r
278 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);\r
279 }\r
280\r
281 OptionPtr = BdsLibGetVariableAndSize (\r
282 OptionName,\r
283 &gEfiGlobalVariableGuid,\r
284 &OptionSize\r
285 );\r
286 TempPtr = OptionPtr;\r
287 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
288 Description = (CHAR16 *) TempPtr;\r
289 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
290 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
291\r
292 //\r
293 // Notes: the description may will change base on the GetStringToken\r
294 //\r
295 if (CompareMem (Description, String, StrSize (Description)) == 0) {\r
296 if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {\r
297 //\r
298 // Got the option, so just return\r
299 //\r
300 FreePool (OptionPtr);\r
301 FreePool (TempOptionPtr);\r
302 return EFI_SUCCESS;\r
303 } else {\r
304 //\r
305 // Boot device path changed, need update.\r
306 //\r
307 UpdateBootDevicePath = TRUE;\r
308 break;\r
309 }\r
310 }\r
311\r
312 FreePool (OptionPtr);\r
313 }\r
314\r
315 OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String) + GetDevicePathSize (DevicePath);\r
316 OptionPtr = AllocateZeroPool (OptionSize);\r
317 TempPtr = OptionPtr;\r
318 *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;\r
319 TempPtr += sizeof (UINT32);\r
320 *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);\r
321 TempPtr += sizeof (UINT16);\r
322 CopyMem (TempPtr, String, StrSize (String));\r
323 TempPtr += StrSize (String);\r
324 CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));\r
325\r
326 if (UpdateBootDevicePath) {\r
327 //\r
328 // The number in option#### to be updated\r
329 //\r
330 RegisterOptionNumber = TempOptionPtr[Index];\r
331 } else {\r
332 //\r
333 // The new option#### number\r
334 //\r
335 RegisterOptionNumber = MaxOptionNumber + 1;\r
336 }\r
337\r
338 if (*VariableName == 'B') {\r
339 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);\r
340 } else {\r
341 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);\r
342 }\r
343\r
344 Status = gRT->SetVariable (\r
345 OptionName,\r
346 &gEfiGlobalVariableGuid,\r
347 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
348 OptionSize,\r
349 OptionPtr\r
350 );\r
351 if (EFI_ERROR (Status) || UpdateBootDevicePath) {\r
352 FreePool (OptionPtr);\r
353 FreePool (TempOptionPtr);\r
354 return Status;\r
355 }\r
356\r
357 FreePool (OptionPtr);\r
358\r
359 //\r
360 // Update the option order variable\r
361 //\r
362 OptionOrderPtr = AllocateZeroPool ((Index + 1) * sizeof (UINT16));\r
363 CopyMem (OptionOrderPtr, TempOptionPtr, Index * sizeof (UINT16));\r
364 OptionOrderPtr[Index] = RegisterOptionNumber;\r
365 Status = gRT->SetVariable (\r
366 VariableName,\r
367 &gEfiGlobalVariableGuid,\r
368 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
369 (Index + 1) * sizeof (UINT16),\r
370 OptionOrderPtr\r
371 );\r
372 if (EFI_ERROR (Status)) {\r
373 FreePool (TempOptionPtr);\r
374 FreePool (OptionOrderPtr);\r
375 return Status;\r
376 }\r
377\r
378 if (TempOptionPtr != NULL) {\r
379 FreePool (TempOptionPtr);\r
380 }\r
381 FreePool (OptionOrderPtr);\r
382\r
383 return EFI_SUCCESS;\r
384}\r
385\r
386BDS_COMMON_OPTION *\r
387BdsLibVariableToOption (\r
388 IN OUT LIST_ENTRY *BdsCommonOptionList,\r
389 IN CHAR16 *VariableName\r
390 )\r
391/*++\r
392\r
393Routine Description:\r
394\r
395 Build the boot#### or driver#### option from the VariableName, the\r
396 build boot#### or driver#### will also be linked to BdsCommonOptionList\r
397\r
398Arguments:\r
399\r
400 BdsCommonOptionList - The header of the boot#### or driver#### option link list\r
401\r
402 VariableName - EFI Variable name indicate if it is boot#### or driver####\r
403\r
404Returns:\r
405\r
406 BDS_COMMON_OPTION - Get the option just been created\r
407\r
408 NULL - Failed to get the new option\r
409\r
410--*/\r
411{\r
412 UINT32 Attribute;\r
413 UINT16 FilePathSize;\r
414 UINT8 *Variable;\r
415 UINT8 *TempPtr;\r
416 UINTN VariableSize;\r
417 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
418 BDS_COMMON_OPTION *Option;\r
419 VOID *LoadOptions;\r
420 UINT32 LoadOptionsSize;\r
421 CHAR16 *Description;\r
422\r
423 //\r
424 // Read the variable. We will never free this data.\r
425 //\r
426 Variable = BdsLibGetVariableAndSize (\r
427 VariableName,\r
428 &gEfiGlobalVariableGuid,\r
429 &VariableSize\r
430 );\r
431 if (Variable == NULL) {\r
432 return NULL;\r
433 }\r
434 //\r
435 // Notes: careful defined the variable of Boot#### or\r
436 // Driver####, consider use some macro to abstract the code\r
437 //\r
438 //\r
439 // Get the option attribute\r
440 //\r
441 TempPtr = Variable;\r
442 Attribute = *(UINT32 *) Variable;\r
443 TempPtr += sizeof (UINT32);\r
444\r
445 //\r
446 // Get the option's device path size\r
447 //\r
448 FilePathSize = *(UINT16 *) TempPtr;\r
449 TempPtr += sizeof (UINT16);\r
450\r
451 //\r
452 // Get the option's description string\r
453 //\r
454 Description = (CHAR16 *) TempPtr;\r
455\r
456 //\r
457 // Get the option's description string size\r
458 //\r
459 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
460\r
461 //\r
462 // Get the option's device path\r
463 //\r
464 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
465 TempPtr += FilePathSize;\r
466\r
467 LoadOptions = TempPtr;\r
468 LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));\r
469\r
470 //\r
471 // The Console variables may have multiple device paths, so make\r
472 // an Entry for each one.\r
473 //\r
474 Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));\r
475 if (Option == NULL) {\r
476 return NULL;\r
477 }\r
478\r
479 Option->Signature = BDS_LOAD_OPTION_SIGNATURE;\r
480 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));\r
481 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));\r
482 Option->Attribute = Attribute;\r
483 Option->Description = AllocateZeroPool (StrSize (Description));\r
484 CopyMem (Option->Description, Description, StrSize (Description));\r
485 Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);\r
486 CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);\r
487 Option->LoadOptionsSize = LoadOptionsSize;\r
488\r
489 //\r
490 // Insert active entry to BdsDeviceList\r
491 //\r
492 if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {\r
493 InsertTailList (BdsCommonOptionList, &Option->Link);\r
494 FreePool (Variable);\r
495 return Option;\r
496 }\r
497\r
498 FreePool (Variable);\r
499 FreePool (Option);\r
500 return NULL;\r
501\r
502}\r
503\r
504EFI_STATUS\r
505BdsLibBuildOptionFromVar (\r
506 IN LIST_ENTRY *BdsCommonOptionList,\r
507 IN CHAR16 *VariableName\r
508 )\r
509/*++\r
510\r
511Routine Description:\r
512\r
513 Process BootOrder, or DriverOrder variables, by calling\r
514 BdsLibVariableToOption () for each UINT16 in the variables.\r
515\r
516Arguments:\r
517\r
518 BdsCommonOptionList - The header of the option list base on variable\r
519 VariableName\r
520\r
521 VariableName - EFI Variable name indicate the BootOrder or DriverOrder\r
522\r
523Returns:\r
524\r
525 EFI_SUCCESS - Success create the boot option or driver option list\r
526\r
527 EFI_OUT_OF_RESOURCES - Failed to get the boot option or driver option list\r
528\r
529--*/\r
530{\r
531 UINT16 *OptionOrder;\r
532 UINTN OptionOrderSize;\r
533 UINTN Index;\r
534 BDS_COMMON_OPTION *Option;\r
535 CHAR16 OptionName[20];\r
536\r
537 //\r
538 // Zero Buffer in order to get all BOOT#### variables\r
539 //\r
540 ZeroMem (OptionName, sizeof (OptionName));\r
541\r
542 //\r
543 // Read the BootOrder, or DriverOrder variable.\r
544 //\r
545 OptionOrder = BdsLibGetVariableAndSize (\r
546 VariableName,\r
547 &gEfiGlobalVariableGuid,\r
548 &OptionOrderSize\r
549 );\r
550 if (OptionOrder == NULL) {\r
551 return EFI_OUT_OF_RESOURCES;\r
552 }\r
553\r
554 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {\r
555 if (*VariableName == 'B') {\r
556 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);\r
557 } else {\r
558 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);\r
559 }\r
560 Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);\r
561 Option->BootCurrent = OptionOrder[Index];\r
562\r
563 }\r
564\r
565 FreePool (OptionOrder);\r
566\r
567 return EFI_SUCCESS;\r
568}\r
569\r
570VOID *\r
571BdsLibGetVariableAndSize (\r
572 IN CHAR16 *Name,\r
573 IN EFI_GUID *VendorGuid,\r
574 OUT UINTN *VariableSize\r
575 )\r
576/*++\r
577\r
578Routine Description:\r
579\r
580 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
581 buffer, and the size of the buffer. If failure return NULL.\r
582\r
583Arguments:\r
584\r
585 Name - String part of EFI variable name\r
586\r
587 VendorGuid - GUID part of EFI variable name\r
588\r
589 VariableSize - Returns the size of the EFI variable that was read\r
590\r
591Returns:\r
592\r
593 Dynamically allocated memory that contains a copy of the EFI variable.\r
594 Caller is responsible freeing the buffer.\r
595\r
596 NULL - Variable was not read\r
597\r
598--*/\r
599{\r
600 EFI_STATUS Status;\r
601 UINTN BufferSize;\r
602 VOID *Buffer;\r
603\r
604 Buffer = NULL;\r
605\r
606 //\r
607 // Pass in a zero size buffer to find the required buffer size.\r
608 //\r
609 BufferSize = 0;\r
610 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
611 if (Status == EFI_BUFFER_TOO_SMALL) {\r
612 //\r
613 // Allocate the buffer to return\r
614 //\r
615 Buffer = AllocateZeroPool (BufferSize);\r
616 if (Buffer == NULL) {\r
617 return NULL;\r
618 }\r
619 //\r
620 // Read variable into the allocated buffer.\r
621 //\r
622 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
623 if (EFI_ERROR (Status)) {\r
624 BufferSize = 0;\r
625 }\r
626 }\r
627\r
628 *VariableSize = BufferSize;\r
629 return Buffer;\r
630}\r
631\r
632VOID\r
633BdsLibSafeFreePool (\r
634 IN VOID *Buffer\r
635 )\r
636/*++\r
637\r
638Routine Description:\r
639\r
640 Free pool safely.\r
641\r
642Arguments:\r
643\r
644 Buffer - The allocated pool entry to free\r
645\r
646Returns:\r
647\r
648 Pointer of the buffer allocated.\r
649\r
650--*/\r
651{\r
652 if (Buffer != NULL) {\r
653 FreePool (Buffer);\r
654 Buffer = NULL;\r
655 }\r
656}\r
657\r
658EFI_DEVICE_PATH_PROTOCOL *\r
659BdsLibDelPartMatchInstance (\r
660 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
661 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
662 )\r
663/*++\r
664\r
665Routine Description:\r
666\r
667 Delete the instance in Multi which matches partly with Single instance\r
668\r
669Arguments:\r
670\r
671 Multi - A pointer to a multi-instance device path data structure.\r
672\r
673 Single - A pointer to a single-instance device path data structure.\r
674\r
675Returns:\r
676\r
677 This function will remove the device path instances in Multi which partly\r
678 match with the Single, and return the result device path. If there is no\r
679 remaining device path as a result, this function will return NULL.\r
680\r
681--*/\r
682{\r
683 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
684 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
685 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r
686 UINTN InstanceSize;\r
687 UINTN SingleDpSize;\r
688 UINTN Size;\r
689\r
690 NewDevicePath = NULL;\r
691 TempNewDevicePath = NULL;\r
692\r
693 if (Multi == NULL || Single == NULL) {\r
694 return Multi;\r
695 }\r
696\r
697 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
698 SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;\r
699 InstanceSize -= END_DEVICE_PATH_LENGTH;\r
700\r
701 while (Instance != NULL) {\r
702\r
703 Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;\r
704\r
705 if ((CompareMem (Instance, Single, Size) != 0)) {\r
706 //\r
707 // Append the device path instance which does not match with Single\r
708 //\r
709 TempNewDevicePath = NewDevicePath;\r
710 NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);\r
711 BdsLibSafeFreePool(TempNewDevicePath);\r
712 }\r
713 BdsLibSafeFreePool(Instance);\r
714 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
715 InstanceSize -= END_DEVICE_PATH_LENGTH;\r
716 }\r
717\r
718 return NewDevicePath;\r
719}\r
720\r
721BOOLEAN\r
722BdsLibMatchDevicePaths (\r
723 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
724 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
725 )\r
726/*++\r
727\r
728Routine Description:\r
729\r
730 Function compares a device path data structure to that of all the nodes of a\r
731 second device path instance.\r
732\r
733Arguments:\r
734\r
735 Multi - A pointer to a multi-instance device path data structure.\r
736\r
737 Single - A pointer to a single-instance device path data structure.\r
738\r
739Returns:\r
740\r
741 TRUE - If the Single is contained within Multi\r
742\r
743 FALSE - The Single is not match within Multi\r
744\r
745\r
746--*/\r
747{\r
748 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
749 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
750 UINTN Size;\r
751\r
752 if (!Multi || !Single) {\r
753 return FALSE;\r
754 }\r
755\r
756 DevicePath = Multi;\r
757 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
758\r
759 //\r
760 // Search for the match of 'Single' in 'Multi'\r
761 //\r
762 while (DevicePathInst != NULL) {\r
763 //\r
764 // If the single device path is found in multiple device paths,\r
765 // return success\r
766 //\r
767 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
768 FreePool (DevicePathInst);\r
769 return TRUE;\r
770 }\r
771\r
772 FreePool (DevicePathInst);\r
773 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
774 }\r
775\r
776 return FALSE;\r
777}\r
778\r
779EFI_STATUS\r
780BdsLibOutputStrings (\r
29b05264 781 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,\r
869f8e34 782 ...\r
783 )\r
784/*++\r
785\r
786Routine Description:\r
787\r
788 This function prints a series of strings.\r
789\r
790Arguments:\r
791\r
792 ConOut - Pointer to EFI_SIMPLE_TEXT_OUT_PROTOCOL\r
793\r
794 ... - A variable argument list containing series of strings,\r
795 the last string must be NULL.\r
796\r
797Returns:\r
798\r
799 EFI_SUCCESS - Success print out the string using ConOut.\r
800\r
801 EFI_STATUS - Return the status of the ConOut->OutputString ().\r
802\r
803--*/\r
804{\r
805 VA_LIST args;\r
806 EFI_STATUS Status;\r
807 CHAR16 *String;\r
808\r
809 Status = EFI_SUCCESS;\r
810 VA_START (args, ConOut);\r
811\r
812 while (!EFI_ERROR (Status)) {\r
813 //\r
814 // If String is NULL, then it's the end of the list\r
815 //\r
816 String = VA_ARG (args, CHAR16 *);\r
817 if (!String) {\r
818 break;\r
819 }\r
820\r
821 Status = ConOut->OutputString (ConOut, String);\r
822\r
823 if (EFI_ERROR (Status)) {\r
824 break;\r
825 }\r
826 }\r
827\r
828 return Status;\r
829}\r
830\r
831//\r
832// Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.\r
833// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if\r
834// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.\r
835//\r
836\r
837VOID\r
838EnableResetReminderFeature (\r
839 VOID\r
840 )\r
841/*++\r
842\r
843Routine Description:\r
844\r
845 Enable the setup browser reset reminder feature.\r
846 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.\r
847\r
848Arguments:\r
849\r
850 VOID\r
851\r
852Returns:\r
853\r
854 VOID\r
855\r
856--*/\r
857{\r
858 mFeaturerSwitch = TRUE;\r
859}\r
860\r
861VOID\r
862DisableResetReminderFeature (\r
863 VOID\r
864 )\r
865/*++\r
866\r
867Routine Description:\r
868\r
869 Disable the setup browser reset reminder feature.\r
870 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.\r
871\r
872Arguments:\r
873\r
874 VOID\r
875\r
876Returns:\r
877\r
878 VOID\r
879\r
880--*/\r
881{\r
882 mFeaturerSwitch = FALSE;\r
883}\r
884\r
885VOID\r
886EnableResetRequired (\r
887 VOID\r
888 )\r
889/*++\r
890\r
891Routine Description:\r
892\r
893 Record the info that a reset is required.\r
894 A module boolean variable is used to record whether a reset is required.\r
895\r
896Arguments:\r
897\r
898 VOID\r
899\r
900Returns:\r
901\r
902 VOID\r
903\r
904--*/\r
905{\r
906 mResetRequired = TRUE;\r
907}\r
908\r
909VOID\r
910DisableResetRequired (\r
911 VOID\r
912 )\r
913/*++\r
914\r
915Routine Description:\r
916\r
917 Record the info that no reset is required.\r
918 A module boolean variable is used to record whether a reset is required.\r
919\r
920Arguments:\r
921\r
922 VOID\r
923\r
924Returns:\r
925\r
926 VOID\r
927\r
928--*/\r
929{\r
930 mResetRequired = FALSE;\r
931}\r
932\r
933BOOLEAN\r
934IsResetReminderFeatureEnable (\r
935 VOID\r
936 )\r
937/*++\r
938\r
939Routine Description:\r
940\r
941 Check whether platform policy enable the reset reminder feature. The default is enabled.\r
942\r
943Arguments:\r
944\r
945 VOID\r
946\r
947Returns:\r
948\r
949 VOID\r
950\r
951--*/\r
952{\r
953 return mFeaturerSwitch;\r
954}\r
955\r
956BOOLEAN\r
957IsResetRequired (\r
958 VOID\r
959 )\r
960/*++\r
961\r
962Routine Description:\r
963\r
964 Check if user changed any option setting which needs a system reset to be effective.\r
965\r
966Arguments:\r
967\r
968 VOID\r
969\r
970Returns:\r
971\r
972 VOID\r
973\r
974--*/\r
975{\r
976 return mResetRequired;\r
977}\r
978\r
979VOID\r
980SetupResetReminder (\r
981 VOID\r
982 )\r
983/*++\r
984\r
985Routine Description:\r
986\r
987 Check whether a reset is needed, and finish the reset reminder feature.\r
988 If a reset is needed, Popup a menu to notice user, and finish the feature\r
989 according to the user selection.\r
990\r
991Arguments:\r
992\r
993 VOID\r
994\r
995Returns:\r
996\r
997 VOID\r
998\r
999--*/\r
1000{\r
1001 EFI_STATUS Status;\r
1002 EFI_FORM_BROWSER_PROTOCOL *Browser;\r
1003 EFI_INPUT_KEY Key;\r
1004 CHAR16 *StringBuffer1;\r
1005 CHAR16 *StringBuffer2;\r
1006\r
1007\r
1008 //\r
1009 //check any reset required change is applied? if yes, reset system\r
1010 //\r
1011 if (IsResetReminderFeatureEnable ()) {\r
1012 if (IsResetRequired ()) {\r
1013\r
1014 Status = gBS->LocateProtocol (\r
1015 &gEfiFormBrowserProtocolGuid,\r
1016 NULL,\r
1017 &Browser\r
1018 );\r
1019\r
1020 ASSERT (Status != EFI_SUCCESS);\r
1021\r
1022 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
1023 ASSERT (StringBuffer1 != NULL);\r
1024 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
1025 ASSERT (StringBuffer2 != NULL);\r
1026 StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");\r
1027 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");\r
1028 //\r
1029 // Popup a menu to notice user\r
1030 //\r
1031 do {\r
1032 Browser->CreatePopUp (2, TRUE, 0, NULL, &Key, StringBuffer1, StringBuffer2);\r
1033 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1034\r
1035 FreePool (StringBuffer1);\r
1036 FreePool (StringBuffer2);\r
1037 //\r
1038 // If the user hits the YES Response key, reset\r
1039 //\r
1040 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {\r
1041 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
1042 }\r
1043 gST->ConOut->ClearScreen (gST->ConOut);\r
1044 }\r
1045 }\r
1046}\r
1047\r
1048EFI_STATUS\r
1049BdsLibGetHiiHandles (\r
1050 IN EFI_HII_PROTOCOL *Hii,\r
1051 IN OUT UINT16 *HandleBufferLength,\r
1052 OUT EFI_HII_HANDLE **HiiHandleBuffer\r
1053 )\r
1054/*++\r
1055\r
1056Routine Description:\r
1057\r
1058 Determines the handles that are currently active in the database.\r
1059 It's the caller's responsibility to free handle buffer.\r
1060\r
1061Arguments:\r
1062\r
1063 This - A pointer to the EFI_HII_PROTOCOL instance.\r
1064 HandleBufferLength - On input, a pointer to the length of the handle buffer. On output,\r
1065 the length of the handle buffer that is required for the handles found.\r
1066 HiiHandleBuffer - Pointer to an array of EFI_HII_PROTOCOL instances returned.\r
1067\r
1068Returns:\r
1069\r
1070 EFI_SUCCESS - Get an array of EFI_HII_PROTOCOL instances successfully.\r
1071 EFI_INVALID_PARAMETER - Hii is NULL.\r
1072 EFI_NOT_FOUND - Database not found.\r
1073\r
1074--*/\r
1075{\r
1076 UINT16 TempBufferLength;\r
1077 EFI_STATUS Status;\r
1078\r
1079 TempBufferLength = 0;\r
1080\r
1081 //\r
1082 // Try to find the actual buffer size for HiiHandle Buffer.\r
1083 //\r
1084 Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);\r
1085\r
1086 if (Status == EFI_BUFFER_TOO_SMALL) {\r
1087 *HiiHandleBuffer = AllocateZeroPool (TempBufferLength);\r
1088 Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);\r
1089 //\r
1090 // we should not fail here.\r
1091 //\r
1092 ASSERT_EFI_ERROR (Status);\r
1093 }\r
1094\r
1095 *HandleBufferLength = TempBufferLength;\r
1096\r
1097 return Status;\r
1098\r
1099}\r