]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
Add some ASSERT()s.
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / BdsMisc.c
CommitLineData
897f0eee 1/** @file\r
2 Misc BDS library function\r
3\r
4Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "InternalBdsLib.h"\r
16\r
17\r
18#define MAX_STRING_LEN 200\r
19\r
11ef23f9 20BOOLEAN mFeaturerSwitch = TRUE;\r
ec8cd35c 21BOOLEAN mResetRequired = FALSE;\r
897f0eee 22\r
23extern UINT16 gPlatformBootTimeOutDefault;\r
24\r
25\r
26/**\r
27 Return the default value for system Timeout variable.\r
28\r
29 @return Timeout value.\r
30\r
31**/\r
32UINT16\r
33EFIAPI\r
34BdsLibGetTimeout (\r
35 VOID\r
36 )\r
37{\r
38 UINT16 Timeout;\r
39 UINTN Size;\r
40 EFI_STATUS Status;\r
41\r
42 //\r
43 // Return Timeout variable or 0xffff if no valid\r
44 // Timeout variable exists.\r
45 //\r
46 Size = sizeof (UINT16);\r
47 Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);\r
0ef93eb7 48 if (EFI_ERROR (Status)) {\r
49 //\r
50 // According to UEFI 2.0 spec, it should treat the Timeout value as 0xffff\r
51 // (default value PcdPlatformBootTimeOutDefault) when L"Timeout" variable is not present.\r
52 // To make the current EFI Automatic-Test activity possible, platform can choose other value\r
53 // for automatic boot when the variable is not present.\r
54 //\r
55 Timeout = PcdGet16 (PcdPlatformBootTimeOutDefault);\r
897f0eee 56 }\r
897f0eee 57\r
897f0eee 58 return Timeout;\r
59}\r
60\r
897f0eee 61/**\r
0d401d4d 62 The function will go through the driver option link list, load and start\r
63 every driver the driver option device path point to.\r
897f0eee 64\r
65 @param BdsDriverLists The header of the current driver option link list\r
66\r
67**/\r
68VOID\r
69EFIAPI\r
70BdsLibLoadDrivers (\r
71 IN LIST_ENTRY *BdsDriverLists\r
72 )\r
73{\r
74 EFI_STATUS Status;\r
75 LIST_ENTRY *Link;\r
76 BDS_COMMON_OPTION *Option;\r
77 EFI_HANDLE ImageHandle;\r
78 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r
79 UINTN ExitDataSize;\r
80 CHAR16 *ExitData;\r
81 BOOLEAN ReconnectAll;\r
82\r
83 ReconnectAll = FALSE;\r
84\r
85 //\r
86 // Process the driver option\r
87 //\r
88 for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {\r
89 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
ec8cd35c 90 \r
897f0eee 91 //\r
92 // If a load option is not marked as LOAD_OPTION_ACTIVE,\r
93 // the boot manager will not automatically load the option.\r
94 //\r
95 if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {\r
96 continue;\r
97 }\r
ec8cd35c 98 \r
897f0eee 99 //\r
100 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,\r
101 // then all of the EFI drivers in the system will be disconnected and\r
102 // reconnected after the last driver load option is processed.\r
103 //\r
104 if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {\r
105 ReconnectAll = TRUE;\r
106 }\r
ec8cd35c 107 \r
897f0eee 108 //\r
109 // Make sure the driver path is connected.\r
110 //\r
111 BdsLibConnectDevicePath (Option->DevicePath);\r
112\r
113 //\r
114 // Load and start the image that Driver#### describes\r
115 //\r
116 Status = gBS->LoadImage (\r
117 FALSE,\r
118 mBdsImageHandle,\r
119 Option->DevicePath,\r
120 NULL,\r
121 0,\r
122 &ImageHandle\r
123 );\r
124\r
125 if (!EFI_ERROR (Status)) {\r
126 gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);\r
127\r
128 //\r
129 // Verify whether this image is a driver, if not,\r
130 // exit it and continue to parse next load option\r
131 //\r
132 if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {\r
133 gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);\r
134 continue;\r
135 }\r
136\r
137 if (Option->LoadOptionsSize != 0) {\r
138 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;\r
139 ImageInfo->LoadOptions = Option->LoadOptions;\r
140 }\r
141 //\r
142 // Before calling the image, enable the Watchdog Timer for\r
143 // the 5 Minute period\r
144 //\r
145 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
146\r
147 Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);\r
148 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Driver Return Status = %r\n", Status));\r
149\r
150 //\r
151 // Clear the Watchdog Timer after the image returns\r
152 //\r
153 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
154 }\r
155 }\r
ec8cd35c 156 \r
897f0eee 157 //\r
158 // Process the LOAD_OPTION_FORCE_RECONNECT driver option\r
159 //\r
160 if (ReconnectAll) {\r
161 BdsLibDisconnectAllEfi ();\r
162 BdsLibConnectAll ();\r
163 }\r
164\r
165}\r
166\r
897f0eee 167/**\r
11ef23f9 168 Get the Option Number that does not used.\r
0d401d4d 169 Try to locate the specific option variable one by one utile find a free number.\r
897f0eee 170\r
171 @param VariableName Indicate if the boot#### or driver#### option\r
172\r
173 @return The Minimal Free Option Number\r
174\r
175**/\r
176UINT16\r
177BdsLibGetFreeOptionNumber (\r
178 IN CHAR16 *VariableName\r
179 )\r
180{\r
897f0eee 181 UINTN Index;\r
182 CHAR16 StrTemp[10];\r
183 UINT16 *OptionBuffer;\r
184 UINTN OptionSize;\r
185\r
186 //\r
187 // Try to find the minimum free number from 0, 1, 2, 3....\r
188 //\r
189 Index = 0;\r
190 do {\r
191 if (*VariableName == 'B') {\r
192 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index);\r
193 } else {\r
194 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Driver%04x", Index);\r
195 }\r
196 //\r
197 // try if the option number is used\r
198 //\r
199 OptionBuffer = BdsLibGetVariableAndSize (\r
ec8cd35c 200 StrTemp,\r
201 &gEfiGlobalVariableGuid,\r
202 &OptionSize\r
203 );\r
897f0eee 204 if (OptionBuffer == NULL) {\r
205 break;\r
206 }\r
0d401d4d 207 Index++;\r
ec8cd35c 208 } while (TRUE);\r
897f0eee 209\r
ec8cd35c 210 return ((UINT16) Index);\r
897f0eee 211}\r
212\r
213\r
214/**\r
215 This function will register the new boot#### or driver#### option base on\r
216 the VariableName. The new registered boot#### or driver#### will be linked\r
217 to BdsOptionList and also update to the VariableName. After the boot#### or\r
218 driver#### updated, the BootOrder or DriverOrder will also be updated.\r
219\r
220 @param BdsOptionList The header of the boot#### or driver#### link list\r
221 @param DevicePath The device path which the boot#### or driver####\r
222 option present\r
223 @param String The description of the boot#### or driver####\r
224 @param VariableName Indicate if the boot#### or driver#### option\r
225\r
226 @retval EFI_SUCCESS The boot#### or driver#### have been success\r
227 registered\r
228 @retval EFI_STATUS Return the status of gRT->SetVariable ().\r
229\r
230**/\r
231EFI_STATUS\r
232EFIAPI\r
233BdsLibRegisterNewOption (\r
234 IN LIST_ENTRY *BdsOptionList,\r
235 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
236 IN CHAR16 *String,\r
237 IN CHAR16 *VariableName\r
238 )\r
239{\r
240 EFI_STATUS Status;\r
241 UINTN Index;\r
242 UINT16 RegisterOptionNumber;\r
243 UINT16 *TempOptionPtr;\r
244 UINTN TempOptionSize;\r
245 UINT16 *OptionOrderPtr;\r
246 VOID *OptionPtr;\r
247 UINTN OptionSize;\r
248 UINT8 *TempPtr;\r
249 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
250 CHAR16 *Description;\r
251 CHAR16 OptionName[10];\r
252 BOOLEAN UpdateDescription;\r
253 UINT16 BootOrderEntry;\r
254 UINTN OrderItemNum;\r
255\r
256\r
257 OptionPtr = NULL;\r
258 OptionSize = 0;\r
259 TempPtr = NULL;\r
260 OptionDevicePath = NULL;\r
261 Description = NULL;\r
262 OptionOrderPtr = NULL;\r
263 UpdateDescription = FALSE;\r
ec8cd35c 264 Status = EFI_SUCCESS;\r
897f0eee 265 ZeroMem (OptionName, sizeof (OptionName));\r
266\r
267 TempOptionSize = 0;\r
268 TempOptionPtr = BdsLibGetVariableAndSize (\r
269 VariableName,\r
270 &gEfiGlobalVariableGuid,\r
271 &TempOptionSize\r
272 );\r
8c80d394 273 ASSERT (TempOptionPtr != NULL);\r
897f0eee 274 //\r
275 // Compare with current option variable\r
276 //\r
277 for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {\r
278\r
279 if (*VariableName == 'B') {\r
280 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);\r
281 } else {\r
282 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);\r
283 }\r
284\r
285 OptionPtr = BdsLibGetVariableAndSize (\r
286 OptionName,\r
287 &gEfiGlobalVariableGuid,\r
288 &OptionSize\r
289 );\r
290 if (OptionPtr == NULL) {\r
291 continue;\r
292 }\r
ec8cd35c 293 TempPtr = OptionPtr;\r
294 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
295 Description = (CHAR16 *) TempPtr;\r
296 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
297 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
897f0eee 298\r
299 //\r
300 // Notes: the description may will change base on the GetStringToken\r
301 //\r
302 if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {\r
303 if (CompareMem (Description, String, StrSize (Description)) == 0) { \r
304 //\r
305 // Got the option, so just return\r
306 //\r
676df92c 307 FreePool (OptionPtr);\r
383ad679 308 FreePool (TempOptionPtr);\r
897f0eee 309 return EFI_SUCCESS;\r
310 } else {\r
311 //\r
312 // Option description changed, need update.\r
313 //\r
314 UpdateDescription = TRUE;\r
676df92c 315 FreePool (OptionPtr);\r
897f0eee 316 break;\r
317 }\r
318 }\r
319\r
676df92c 320 FreePool (OptionPtr);\r
897f0eee 321 }\r
322\r
323 OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);\r
ec8cd35c 324 OptionSize += GetDevicePathSize (DevicePath);\r
897f0eee 325 OptionPtr = AllocateZeroPool (OptionSize);\r
676df92c 326 ASSERT (OptionPtr != NULL);\r
327 \r
897f0eee 328 TempPtr = OptionPtr;\r
329 *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;\r
ec8cd35c 330 TempPtr += sizeof (UINT32);\r
897f0eee 331 *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);\r
ec8cd35c 332 TempPtr += sizeof (UINT16);\r
897f0eee 333 CopyMem (TempPtr, String, StrSize (String));\r
ec8cd35c 334 TempPtr += StrSize (String);\r
897f0eee 335 CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));\r
336\r
337 if (UpdateDescription) {\r
338 //\r
339 // The number in option#### to be updated\r
340 //\r
341 RegisterOptionNumber = TempOptionPtr[Index];\r
342 } else {\r
343 //\r
344 // The new option#### number\r
345 //\r
346 RegisterOptionNumber = BdsLibGetFreeOptionNumber(VariableName);\r
347 }\r
348\r
349 if (*VariableName == 'B') {\r
350 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);\r
351 } else {\r
352 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);\r
353 }\r
354\r
355 Status = gRT->SetVariable (\r
356 OptionName,\r
357 &gEfiGlobalVariableGuid,\r
358 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
359 OptionSize,\r
360 OptionPtr\r
361 );\r
362 //\r
363 // Return if only need to update a changed description or fail to set option.\r
364 //\r
365 if (EFI_ERROR (Status) || UpdateDescription) {\r
676df92c 366 FreePool (OptionPtr);\r
c473cc17 367 if (TempOptionPtr != NULL) {\r
368 FreePool (TempOptionPtr);\r
369 }\r
897f0eee 370 return Status;\r
371 }\r
372\r
676df92c 373 FreePool (OptionPtr);\r
897f0eee 374\r
375 //\r
376 // Update the option order variable\r
377 //\r
378\r
379 //\r
380 // If no option order\r
381 //\r
382 if (TempOptionSize == 0) {\r
383 BootOrderEntry = 0;\r
384 Status = gRT->SetVariable (\r
385 VariableName,\r
386 &gEfiGlobalVariableGuid,\r
387 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
388 sizeof (UINT16),\r
389 &BootOrderEntry\r
390 );\r
c473cc17 391 if (TempOptionPtr != NULL) {\r
392 FreePool (TempOptionPtr);\r
393 }\r
ec8cd35c 394 return Status;\r
897f0eee 395 }\r
396\r
397 //\r
398 // Append the new option number to the original option order\r
399 //\r
400 OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;\r
401 OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));\r
676df92c 402 ASSERT (OptionOrderPtr!= NULL);\r
403 \r
897f0eee 404 CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));\r
405\r
406 OptionOrderPtr[Index] = RegisterOptionNumber;\r
407\r
408 Status = gRT->SetVariable (\r
409 VariableName,\r
410 &gEfiGlobalVariableGuid,\r
411 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
412 OrderItemNum * sizeof (UINT16),\r
413 OptionOrderPtr\r
414 );\r
676df92c 415 FreePool (TempOptionPtr);\r
416 FreePool (OptionOrderPtr);\r
897f0eee 417\r
ec8cd35c 418 return Status;\r
897f0eee 419}\r
420\r
421\r
422/**\r
423 Build the boot#### or driver#### option from the VariableName, the\r
11ef23f9 424 build boot#### or driver#### will also be linked to BdsCommonOptionList.\r
897f0eee 425\r
426 @param BdsCommonOptionList The header of the boot#### or driver#### option\r
427 link list\r
428 @param VariableName EFI Variable name indicate if it is boot#### or\r
429 driver####\r
430\r
431 @retval BDS_COMMON_OPTION Get the option just been created\r
432 @retval NULL Failed to get the new option\r
433\r
434**/\r
435BDS_COMMON_OPTION *\r
436EFIAPI\r
437BdsLibVariableToOption (\r
438 IN OUT LIST_ENTRY *BdsCommonOptionList,\r
439 IN CHAR16 *VariableName\r
440 )\r
441{\r
442 UINT32 Attribute;\r
443 UINT16 FilePathSize;\r
444 UINT8 *Variable;\r
445 UINT8 *TempPtr;\r
446 UINTN VariableSize;\r
447 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
448 BDS_COMMON_OPTION *Option;\r
449 VOID *LoadOptions;\r
450 UINT32 LoadOptionsSize;\r
451 CHAR16 *Description;\r
452 UINT8 NumOff;\r
453 //\r
454 // Read the variable. We will never free this data.\r
455 //\r
456 Variable = BdsLibGetVariableAndSize (\r
457 VariableName,\r
458 &gEfiGlobalVariableGuid,\r
459 &VariableSize\r
460 );\r
461 if (Variable == NULL) {\r
462 return NULL;\r
463 }\r
464 //\r
465 // Notes: careful defined the variable of Boot#### or\r
466 // Driver####, consider use some macro to abstract the code\r
467 //\r
468 //\r
469 // Get the option attribute\r
470 //\r
ec8cd35c 471 TempPtr = Variable;\r
472 Attribute = *(UINT32 *) Variable;\r
473 TempPtr += sizeof (UINT32);\r
897f0eee 474\r
475 //\r
476 // Get the option's device path size\r
477 //\r
ec8cd35c 478 FilePathSize = *(UINT16 *) TempPtr;\r
479 TempPtr += sizeof (UINT16);\r
897f0eee 480\r
481 //\r
482 // Get the option's description string\r
483 //\r
484 Description = (CHAR16 *) TempPtr;\r
485\r
486 //\r
487 // Get the option's description string size\r
488 //\r
ec8cd35c 489 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
897f0eee 490\r
491 //\r
492 // Get the option's device path\r
493 //\r
ec8cd35c 494 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
495 TempPtr += FilePathSize;\r
897f0eee 496\r
497 LoadOptions = TempPtr;\r
498 LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));\r
499\r
500 //\r
501 // The Console variables may have multiple device paths, so make\r
502 // an Entry for each one.\r
503 //\r
504 Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));\r
505 if (Option == NULL) {\r
506 return NULL;\r
507 }\r
508\r
509 Option->Signature = BDS_LOAD_OPTION_SIGNATURE;\r
510 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));\r
0d401d4d 511 ASSERT(Option->DevicePath != NULL);\r
897f0eee 512 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));\r
0d401d4d 513\r
897f0eee 514 Option->Attribute = Attribute;\r
515 Option->Description = AllocateZeroPool (StrSize (Description));\r
0d401d4d 516 ASSERT(Option->Description != NULL);\r
897f0eee 517 CopyMem (Option->Description, Description, StrSize (Description));\r
0d401d4d 518\r
897f0eee 519 Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);\r
0d401d4d 520 ASSERT(Option->LoadOptions != NULL);\r
897f0eee 521 CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);\r
522 Option->LoadOptionsSize = LoadOptionsSize;\r
523\r
524 //\r
525 // Get the value from VariableName Unicode string\r
526 // since the ISO standard assumes ASCII equivalent abbreviations, we can be safe in converting this\r
527 // Unicode stream to ASCII without any loss in meaning.\r
528 //\r
529 if (*VariableName == 'B') {\r
530 NumOff = sizeof (L"Boot")/sizeof(CHAR16) -1 ;\r
531 Option->BootCurrent = (UINT16) ((VariableName[NumOff] -'0') * 0x1000);\r
532 Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+1]-'0') * 0x100));\r
533 Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+2]-'0') * 0x10));\r
534 Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+3]-'0')));\r
535 }\r
536 //\r
537 // Insert active entry to BdsDeviceList\r
538 //\r
539 if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {\r
540 InsertTailList (BdsCommonOptionList, &Option->Link);\r
676df92c 541 FreePool (Variable);\r
897f0eee 542 return Option;\r
543 }\r
544\r
676df92c 545 FreePool (Variable);\r
546 FreePool (Option);\r
897f0eee 547 return NULL;\r
548\r
549}\r
550\r
897f0eee 551/**\r
552 Process BootOrder, or DriverOrder variables, by calling\r
553 BdsLibVariableToOption () for each UINT16 in the variables.\r
554\r
555 @param BdsCommonOptionList The header of the option list base on variable\r
556 VariableName\r
557 @param VariableName EFI Variable name indicate the BootOrder or\r
558 DriverOrder\r
559\r
560 @retval EFI_SUCCESS Success create the boot option or driver option\r
561 list\r
562 @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list\r
563\r
564**/\r
565EFI_STATUS\r
566EFIAPI\r
567BdsLibBuildOptionFromVar (\r
568 IN LIST_ENTRY *BdsCommonOptionList,\r
569 IN CHAR16 *VariableName\r
570 )\r
571{\r
572 UINT16 *OptionOrder;\r
573 UINTN OptionOrderSize;\r
574 UINTN Index;\r
575 BDS_COMMON_OPTION *Option;\r
576 CHAR16 OptionName[20];\r
577\r
578 //\r
579 // Zero Buffer in order to get all BOOT#### variables\r
580 //\r
581 ZeroMem (OptionName, sizeof (OptionName));\r
582\r
583 //\r
584 // Read the BootOrder, or DriverOrder variable.\r
585 //\r
586 OptionOrder = BdsLibGetVariableAndSize (\r
587 VariableName,\r
588 &gEfiGlobalVariableGuid,\r
589 &OptionOrderSize\r
590 );\r
591 if (OptionOrder == NULL) {\r
592 return EFI_OUT_OF_RESOURCES;\r
593 }\r
594\r
595 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {\r
596 if (*VariableName == 'B') {\r
597 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);\r
598 } else {\r
599 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);\r
600 }\r
601\r
602 Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);\r
8c80d394 603 ASSERT (Option != NULL);\r
897f0eee 604 Option->BootCurrent = OptionOrder[Index];\r
605\r
606 }\r
607\r
676df92c 608 FreePool (OptionOrder);\r
897f0eee 609\r
610 return EFI_SUCCESS;\r
611}\r
612\r
897f0eee 613/**\r
614 Get boot mode by looking up configuration table and parsing HOB list\r
615\r
616 @param BootMode Boot mode from PEI handoff HOB.\r
617\r
618 @retval EFI_SUCCESS Successfully get boot mode\r
619\r
620**/\r
621EFI_STATUS\r
622EFIAPI\r
623BdsLibGetBootMode (\r
624 OUT EFI_BOOT_MODE *BootMode\r
625 )\r
626{\r
627 *BootMode = GetBootModeHob ();\r
628\r
629 return EFI_SUCCESS;\r
630}\r
631\r
897f0eee 632/**\r
633 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
634 buffer, and the size of the buffer. If failure return NULL.\r
635\r
636 @param Name String part of EFI variable name\r
637 @param VendorGuid GUID part of EFI variable name\r
638 @param VariableSize Returns the size of the EFI variable that was read\r
639\r
262b0668 640 @return Dynamically allocated memory that contains a copy of the EFI variable\r
641 Caller is responsible freeing the buffer.\r
897f0eee 642 @retval NULL Variable was not read\r
643\r
644**/\r
645VOID *\r
646EFIAPI\r
647BdsLibGetVariableAndSize (\r
648 IN CHAR16 *Name,\r
649 IN EFI_GUID *VendorGuid,\r
650 OUT UINTN *VariableSize\r
651 )\r
652{\r
653 EFI_STATUS Status;\r
654 UINTN BufferSize;\r
655 VOID *Buffer;\r
656\r
657 Buffer = NULL;\r
658\r
659 //\r
660 // Pass in a zero size buffer to find the required buffer size.\r
661 //\r
662 BufferSize = 0;\r
663 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
664 if (Status == EFI_BUFFER_TOO_SMALL) {\r
665 //\r
666 // Allocate the buffer to return\r
667 //\r
668 Buffer = AllocateZeroPool (BufferSize);\r
669 if (Buffer == NULL) {\r
670 return NULL;\r
671 }\r
672 //\r
673 // Read variable into the allocated buffer.\r
674 //\r
675 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
676 if (EFI_ERROR (Status)) {\r
677 BufferSize = 0;\r
678 }\r
679 }\r
680\r
681 *VariableSize = BufferSize;\r
682 return Buffer;\r
683}\r
684\r
897f0eee 685/**\r
686 Delete the instance in Multi which matches partly with Single instance\r
687\r
688 @param Multi A pointer to a multi-instance device path data\r
689 structure.\r
690 @param Single A pointer to a single-instance device path data\r
691 structure.\r
692\r
693 @return This function will remove the device path instances in Multi which partly\r
694 match with the Single, and return the result device path. If there is no\r
695 remaining device path as a result, this function will return NULL.\r
696\r
697**/\r
698EFI_DEVICE_PATH_PROTOCOL *\r
699EFIAPI\r
700BdsLibDelPartMatchInstance (\r
701 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
702 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
703 )\r
704{\r
705 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
706 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
707 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r
708 UINTN InstanceSize;\r
709 UINTN SingleDpSize;\r
710 UINTN Size;\r
711\r
712 NewDevicePath = NULL;\r
713 TempNewDevicePath = NULL;\r
714\r
715 if (Multi == NULL || Single == NULL) {\r
716 return Multi;\r
717 }\r
718\r
719 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
720 SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;\r
721 InstanceSize -= END_DEVICE_PATH_LENGTH;\r
722\r
723 while (Instance != NULL) {\r
724\r
725 Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;\r
726\r
727 if ((CompareMem (Instance, Single, Size) != 0)) {\r
728 //\r
729 // Append the device path instance which does not match with Single\r
730 //\r
731 TempNewDevicePath = NewDevicePath;\r
732 NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);\r
676df92c 733 if (TempNewDevicePath != NULL) {\r
734 FreePool(TempNewDevicePath);\r
735 }\r
897f0eee 736 }\r
676df92c 737 FreePool(Instance);\r
897f0eee 738 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
739 InstanceSize -= END_DEVICE_PATH_LENGTH;\r
740 }\r
741\r
742 return NewDevicePath;\r
743}\r
744\r
897f0eee 745/**\r
746 Function compares a device path data structure to that of all the nodes of a\r
747 second device path instance.\r
748\r
749 @param Multi A pointer to a multi-instance device path data\r
750 structure.\r
751 @param Single A pointer to a single-instance device path data\r
752 structure.\r
753\r
262b0668 754 @retval TRUE If the Single device path is contained within Multi device path.\r
755 @retval FALSE The Single device path is not match within Multi device path.\r
897f0eee 756\r
757**/\r
758BOOLEAN\r
759EFIAPI\r
760BdsLibMatchDevicePaths (\r
761 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
762 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
763 )\r
764{\r
765 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
766 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
767 UINTN Size;\r
768\r
ff6bf04b 769 if (Multi == NULL || Single == NULL) {\r
897f0eee 770 return FALSE;\r
771 }\r
772\r
773 DevicePath = Multi;\r
774 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
775\r
776 //\r
777 // Search for the match of 'Single' in 'Multi'\r
778 //\r
779 while (DevicePathInst != NULL) {\r
780 //\r
781 // If the single device path is found in multiple device paths,\r
782 // return success\r
783 //\r
784 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
676df92c 785 FreePool (DevicePathInst);\r
897f0eee 786 return TRUE;\r
787 }\r
788\r
676df92c 789 FreePool (DevicePathInst);\r
897f0eee 790 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
791 }\r
792\r
793 return FALSE;\r
794}\r
795\r
897f0eee 796/**\r
797 This function prints a series of strings.\r
798\r
799 @param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
800 @param ... A variable argument list containing series of\r
801 strings, the last string must be NULL.\r
802\r
803 @retval EFI_SUCCESS Success print out the string using ConOut.\r
804 @retval EFI_STATUS Return the status of the ConOut->OutputString ().\r
805\r
806**/\r
807EFI_STATUS\r
808EFIAPI\r
809BdsLibOutputStrings (\r
810 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,\r
811 ...\r
812 )\r
813{\r
11ef23f9 814 VA_LIST Args;\r
897f0eee 815 EFI_STATUS Status;\r
816 CHAR16 *String;\r
817\r
818 Status = EFI_SUCCESS;\r
11ef23f9 819 VA_START (Args, ConOut);\r
897f0eee 820\r
821 while (!EFI_ERROR (Status)) {\r
822 //\r
823 // If String is NULL, then it's the end of the list\r
824 //\r
11ef23f9 825 String = VA_ARG (Args, CHAR16 *);\r
826 if (String != NULL) {\r
897f0eee 827 break;\r
828 }\r
829\r
830 Status = ConOut->OutputString (ConOut, String);\r
831\r
832 if (EFI_ERROR (Status)) {\r
833 break;\r
834 }\r
835 }\r
0d401d4d 836 \r
837 VA_END(Args);\r
897f0eee 838 return Status;\r
839}\r
840\r
841//\r
842// Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.\r
843// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if\r
844// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.\r
845//\r
846\r
847\r
848/**\r
849 Enable the setup browser reset reminder feature.\r
850 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.\r
851\r
852**/\r
853VOID\r
854EFIAPI\r
855EnableResetReminderFeature (\r
856 VOID\r
857 )\r
858{\r
859 mFeaturerSwitch = TRUE;\r
860}\r
861\r
862\r
863/**\r
864 Disable the setup browser reset reminder feature.\r
865 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.\r
866\r
867**/\r
868VOID\r
869EFIAPI\r
870DisableResetReminderFeature (\r
871 VOID\r
872 )\r
873{\r
874 mFeaturerSwitch = FALSE;\r
875}\r
876\r
877\r
878/**\r
879 Record the info that a reset is required.\r
880 A module boolean variable is used to record whether a reset is required.\r
881\r
882**/\r
883VOID\r
884EFIAPI\r
885EnableResetRequired (\r
886 VOID\r
887 )\r
888{\r
889 mResetRequired = TRUE;\r
890}\r
891\r
892\r
893/**\r
894 Record the info that no reset is required.\r
895 A module boolean variable is used to record whether a reset is required.\r
896\r
897**/\r
898VOID\r
899EFIAPI\r
900DisableResetRequired (\r
901 VOID\r
902 )\r
903{\r
904 mResetRequired = FALSE;\r
905}\r
906\r
907\r
908/**\r
909 Check whether platform policy enable the reset reminder feature. The default is enabled.\r
910\r
911**/\r
912BOOLEAN\r
913EFIAPI\r
914IsResetReminderFeatureEnable (\r
915 VOID\r
916 )\r
917{\r
918 return mFeaturerSwitch;\r
919}\r
920\r
921\r
922/**\r
923 Check if user changed any option setting which needs a system reset to be effective.\r
924\r
925**/\r
926BOOLEAN\r
927EFIAPI\r
928IsResetRequired (\r
929 VOID\r
930 )\r
931{\r
932 return mResetRequired;\r
933}\r
934\r
935\r
936/**\r
937 Check whether a reset is needed, and finish the reset reminder feature.\r
938 If a reset is needed, Popup a menu to notice user, and finish the feature\r
939 according to the user selection.\r
940\r
941**/\r
942VOID\r
943EFIAPI\r
944SetupResetReminder (\r
945 VOID\r
946 )\r
947{\r
948 EFI_INPUT_KEY Key;\r
949 CHAR16 *StringBuffer1;\r
950 CHAR16 *StringBuffer2;\r
951\r
952\r
953 //\r
954 //check any reset required change is applied? if yes, reset system\r
955 //\r
956 if (IsResetReminderFeatureEnable ()) {\r
957 if (IsResetRequired ()) {\r
958\r
959 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
960 ASSERT (StringBuffer1 != NULL);\r
961 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
962 ASSERT (StringBuffer2 != NULL);\r
963 StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");\r
964 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");\r
965 //\r
966 // Popup a menu to notice user\r
967 //\r
968 do {\r
969 IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2);\r
970 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
971\r
676df92c 972 FreePool (StringBuffer1);\r
973 FreePool (StringBuffer2);\r
897f0eee 974 //\r
975 // If the user hits the YES Response key, reset\r
976 //\r
977 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {\r
978 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
979 }\r
980 gST->ConOut->ClearScreen (gST->ConOut);\r
981 }\r
982 }\r
983}\r
984\r
897f0eee 985/**\r
262b0668 986 Get the headers (dos, image, optional header) from an image\r
897f0eee 987\r
988 @param Device SimpleFileSystem device handle\r
989 @param FileName File name for the image\r
990 @param DosHeader Pointer to dos header\r
262b0668 991 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
897f0eee 992\r
993 @retval EFI_SUCCESS Successfully get the machine type.\r
994 @retval EFI_NOT_FOUND The file is not found.\r
995 @retval EFI_LOAD_ERROR File is not a valid image file.\r
996\r
997**/\r
998EFI_STATUS\r
999EFIAPI\r
1000BdsLibGetImageHeader (\r
1001 IN EFI_HANDLE Device,\r
1002 IN CHAR16 *FileName,\r
1003 OUT EFI_IMAGE_DOS_HEADER *DosHeader,\r
1004 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
1005 )\r
1006{\r
1007 EFI_STATUS Status;\r
1008 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;\r
1009 EFI_FILE_HANDLE Root;\r
1010 EFI_FILE_HANDLE ThisFile;\r
1011 UINTN BufferSize;\r
1012 UINT64 FileSize;\r
1013 EFI_FILE_INFO *Info;\r
1014\r
1015 Root = NULL;\r
1016 ThisFile = NULL;\r
1017 //\r
1018 // Handle the file system interface to the device\r
1019 //\r
1020 Status = gBS->HandleProtocol (\r
1021 Device,\r
1022 &gEfiSimpleFileSystemProtocolGuid,\r
1023 (VOID *) &Volume\r
1024 );\r
1025 if (EFI_ERROR (Status)) {\r
1026 goto Done;\r
1027 }\r
1028\r
1029 Status = Volume->OpenVolume (\r
1030 Volume,\r
1031 &Root\r
1032 );\r
1033 if (EFI_ERROR (Status)) {\r
676df92c 1034 Root = NULL;\r
897f0eee 1035 goto Done;\r
1036 }\r
1037\r
1038 Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);\r
1039 if (EFI_ERROR (Status)) {\r
1040 goto Done;\r
1041 }\r
1042\r
1043 //\r
1044 // Get file size\r
1045 //\r
1046 BufferSize = SIZE_OF_EFI_FILE_INFO + 200;\r
1047 do {\r
1048 Info = NULL;\r
1049 Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);\r
1050 if (EFI_ERROR (Status)) {\r
1051 goto Done;\r
1052 }\r
1053 Status = ThisFile->GetInfo (\r
1054 ThisFile,\r
1055 &gEfiFileInfoGuid,\r
1056 &BufferSize,\r
1057 Info\r
1058 );\r
1059 if (!EFI_ERROR (Status)) {\r
1060 break;\r
1061 }\r
1062 if (Status != EFI_BUFFER_TOO_SMALL) {\r
676df92c 1063 FreePool (Info);\r
897f0eee 1064 goto Done;\r
1065 }\r
676df92c 1066 FreePool (Info);\r
897f0eee 1067 } while (TRUE);\r
1068\r
1069 FileSize = Info->FileSize;\r
676df92c 1070 FreePool (Info);\r
897f0eee 1071\r
1072 //\r
1073 // Read dos header\r
1074 //\r
1075 BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);\r
1076 Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);\r
1077 if (EFI_ERROR (Status) ||\r
1078 BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||\r
1079 FileSize <= DosHeader->e_lfanew ||\r
1080 DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
1081 Status = EFI_LOAD_ERROR;\r
1082 goto Done;\r
1083 }\r
1084\r
1085 //\r
1086 // Move to PE signature\r
1087 //\r
1088 Status = ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew);\r
1089 if (EFI_ERROR (Status)) {\r
1090 Status = EFI_LOAD_ERROR;\r
1091 goto Done;\r
1092 }\r
1093\r
1094 //\r
1095 // Read and check PE signature\r
1096 //\r
1097 BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);\r
1098 Status = ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32);\r
1099 if (EFI_ERROR (Status) ||\r
1100 BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||\r
1101 Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
1102 Status = EFI_LOAD_ERROR;\r
1103 goto Done;\r
1104 }\r
1105\r
1106 //\r
1107 // Check PE32 or PE32+ magic\r
1108 //\r
1109 if (Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&\r
1110 Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
1111 Status = EFI_LOAD_ERROR;\r
1112 goto Done;\r
1113 }\r
1114\r
1115 Done:\r
1116 if (ThisFile != NULL) {\r
1117 ThisFile->Close (ThisFile);\r
1118 }\r
1119 if (Root != NULL) {\r
1120 Root->Close (Root);\r
1121 }\r
1122 return Status;\r
1123}\r
1124\r
11ef23f9 1125/**\r
897f0eee 1126\r
1127 This routine is a notification function for legayc boot or exit boot\r
1128 service event. It will adjust the memory information for different\r
11ef23f9 1129 memory type and save them into the variables for next boot.\r
897f0eee 1130\r
897f0eee 1131\r
11ef23f9 1132 @param Event The event that triggered this notification function.\r
1133 @param Context Pointer to the notification functions context.\r
897f0eee 1134\r
11ef23f9 1135**/\r
1136VOID\r
1137EFIAPI\r
1138BdsSetMemoryTypeInformationVariable (\r
1139 EFI_EVENT Event,\r
1140 VOID *Context\r
1141 )\r
897f0eee 1142{\r
1143 EFI_STATUS Status;\r
1144 EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation;\r
1145 EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation;\r
1146 UINTN VariableSize;\r
1147 BOOLEAN UpdateRequired;\r
1148 UINTN Index;\r
1149 UINTN Index1;\r
1150 UINT32 Previous;\r
1151 UINT32 Current;\r
1152 UINT32 Next;\r
1153 EFI_HOB_GUID_TYPE *GuidHob;\r
1154\r
1155 UpdateRequired = FALSE;\r
1156\r
1157 //\r
1158 // Retrieve the current memory usage statistics. If they are not found, then\r
1159 // no adjustments can be made to the Memory Type Information variable.\r
1160 //\r
1161 Status = EfiGetSystemConfigurationTable (\r
1162 &gEfiMemoryTypeInformationGuid,\r
1163 (VOID **) &CurrentMemoryTypeInformation\r
1164 );\r
1165 if (EFI_ERROR (Status)) {\r
1166 return;\r
1167 }\r
1168\r
1169 //\r
1170 // Get the Memory Type Information settings from Hob if they exist,\r
1171 // PEI is responsible for getting them from variable and build a Hob to save them.\r
1172 // If the previous Memory Type Information is not available, then set defaults\r
1173 //\r
1174 GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid);\r
1175 if (GuidHob == NULL) {\r
1176 //\r
1177 // If Platform has not built Memory Type Info into the Hob, just return.\r
1178 //\r
1179 return;\r
1180 }\r
1181 PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);\r
1182 VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
1183\r
1184 //\r
1185 // Use a heuristic to adjust the Memory Type Information for the next boot\r
1186 //\r
1187 for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {\r
1188\r
1189 Current = 0;\r
1190 for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {\r
1191 if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {\r
1192 Current = CurrentMemoryTypeInformation[Index1].NumberOfPages;\r
1193 break;\r
1194 }\r
1195 }\r
1196\r
1197 if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {\r
1198 continue;\r
1199 }\r
1200\r
1201 Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;\r
1202\r
1203 //\r
1204 // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail\r
1205 //\r
1206 if (Current > Previous) {\r
1207 Next = Current + (Current >> 2);\r
1208 } else {\r
1209 Next = Previous;\r
1210 }\r
1211 if (Next > 0 && Next < 4) {\r
1212 Next = 4;\r
1213 }\r
1214\r
1215 if (Next != Previous) {\r
1216 PreviousMemoryTypeInformation[Index].NumberOfPages = Next;\r
1217 UpdateRequired = TRUE;\r
1218 }\r
1219\r
1220 }\r
1221\r
1222 //\r
1223 // If any changes were made to the Memory Type Information settings, then set the new variable value\r
1224 //\r
1225 if (UpdateRequired) {\r
1226 Status = gRT->SetVariable (\r
1227 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
1228 &gEfiMemoryTypeInformationGuid,\r
1229 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
1230 VariableSize,\r
1231 PreviousMemoryTypeInformation\r
1232 );\r
1233 }\r
1234\r
1235 return;\r
1236}\r
1237\r
897f0eee 1238/**\r
262b0668 1239 This routine register a function to adjust the different type memory page number\r
1240 just before booting and save the updated info into the variable for next boot to use.\r
897f0eee 1241\r
1242**/\r
1243VOID\r
1244EFIAPI\r
1245BdsLibSaveMemoryTypeInformation (\r
1246 VOID\r
1247 )\r
1248{\r
1249 EFI_STATUS Status;\r
1250 EFI_EVENT ReadyToBootEvent;\r
1251\r
1252 Status = EfiCreateEventReadyToBootEx (\r
1253 TPL_CALLBACK,\r
1254 BdsSetMemoryTypeInformationVariable,\r
1255 NULL,\r
1256 &ReadyToBootEvent\r
1257 );\r
1258 if (EFI_ERROR (Status)) {\r
1259 DEBUG ((DEBUG_ERROR,"Bds Set Memory Type Informationa Variable Fails\n"));\r
1260 }\r
1261\r
1262}\r
1263\r
1264\r