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
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.
18 This file include all platform action which can be customized
23 #include "Generic/Bds.h"
24 #include "BdsPlatform.h"
25 #include "Generic/BdsString.h"
26 #include "Generic/Language.h"
27 #include "Generic/FrontPage.h"
29 CHAR16 mFirmwareVendor
[] = L
"TianoCore.org";
31 EFI_EVENT mReadyToBootEvent
;
33 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
34 { EfiACPIReclaimMemory
, 0 },
35 { EfiACPIMemoryNVS
, 0 },
36 { EfiReservedMemoryType
, 0 },
37 { EfiRuntimeServicesData
, 0 },
38 { EfiRuntimeServicesCode
, 0 },
39 { EfiBootServicesCode
, 0 },
40 { EfiBootServicesData
, 0 },
43 { EfiMaxMemoryType
, 0 }
47 BdsSetMemoryTypeInformationVariable (
52 EFI_MEMORY_TYPE_INFORMATION
*PreviousMemoryTypeInformation
;
53 EFI_MEMORY_TYPE_INFORMATION
*CurrentMemoryTypeInformation
;
55 BOOLEAN UpdateRequired
;
61 EFI_HOB_GUID_TYPE
*Hob
;
63 UpdateRequired
= FALSE
;
66 // Retrieve the current memory usage statistics. If they are not found, then
67 // no adjustments can be made to the Memory Type Information variable.
69 Status
= EfiGetSystemConfigurationTable (&gEfiMemoryTypeInformationGuid
, (VOID
**)&CurrentMemoryTypeInformation
);
70 if (EFI_ERROR (Status
)) {
75 // Get the Memory Type Information settings from a previous boot if they exist.
77 PreviousMemoryTypeInformation
= BdsLibGetVariableAndSize (
78 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
79 &gEfiMemoryTypeInformationGuid
,
84 // If the previous Memory Type Information is not available, then set defaults
86 if (PreviousMemoryTypeInformation
== NULL
) {
87 Hob
= GetFirstGuidHob (&gEfiMemoryTypeInformationGuid
);
90 PreviousMemoryTypeInformation
= GET_GUID_HOB_DATA (Hob
);
91 VariableSize
= GET_GUID_HOB_DATA_SIZE (Hob
);
92 ASSERT (VariableSize
== sizeof (mDefaultMemoryTypeInformation
));
93 CopyMem (mDefaultMemoryTypeInformation
, PreviousMemoryTypeInformation
, VariableSize
);
95 PreviousMemoryTypeInformation
= mDefaultMemoryTypeInformation
;
96 VariableSize
= sizeof (mDefaultMemoryTypeInformation
);
98 UpdateRequired
= TRUE
;
102 // Use a hueristic to adjust the Memory Type Information for the next boot
104 for (Index
= 0; PreviousMemoryTypeInformation
[Index
].Type
!= EfiMaxMemoryType
; Index
++) {
107 for (Index1
= 0; CurrentMemoryTypeInformation
[Index1
].Type
!= EfiMaxMemoryType
; Index1
++) {
108 if (PreviousMemoryTypeInformation
[Index
].Type
== CurrentMemoryTypeInformation
[Index1
].Type
) {
109 Current
= CurrentMemoryTypeInformation
[Index1
].NumberOfPages
;
114 if (CurrentMemoryTypeInformation
[Index1
].Type
== EfiMaxMemoryType
) {
118 Previous
= PreviousMemoryTypeInformation
[Index
].NumberOfPages
;
120 if (Current
> Previous
) {
121 Next
= Current
+ (Current
>> 2);
122 } else if (Current
< (Previous
>> 1)) {
123 Next
= Previous
- (Previous
>> 2);
127 if (Next
> 0 && Next
<= 16) {
131 if (Next
!= Previous
) {
132 PreviousMemoryTypeInformation
[Index
].NumberOfPages
= Next
;
133 UpdateRequired
= TRUE
;
138 // If any changes were made to the Memory Type Information settings, then set the new variable value
140 if (UpdateRequired
) {
141 Status
= gRT
->SetVariable (
142 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
143 &gEfiMemoryTypeInformationGuid
,
144 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
146 PreviousMemoryTypeInformation
158 This routine is a notification function for legayc boot or exit boot
159 service event. It will adjust the memory information for different
160 memory type and save them into the variables for next boot
164 Event - The event that triggered this notification function
165 Context - Pointer to the notification functions context
174 BdsReadyToBootEvent (
179 BdsSetMemoryTypeInformationVariable ();
183 // BDS Platform Functions
187 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
193 Platform Bds init. Incude the platform firmware vendor, revision
198 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
207 // set firmwarevendor, here can be IBV/OEM customize
209 gST
->FirmwareVendor
= AllocateRuntimeCopyPool (
210 sizeof (mFirmwareVendor
),
213 ASSERT (gST
->FirmwareVendor
!= NULL
);
215 gST
->FirmwareRevision
= FIRMWARE_REVISION
;
218 // Fixup Tasble CRC after we updated Firmware Vendor and Revision
220 gBS
->CalculateCrc32 ((VOID
*) gST
, sizeof (EFI_SYSTEM_TABLE
), &gST
->Hdr
.CRC32
);
223 // Create Ready To Boot event
225 EfiCreateEventReadyToBootEx (
233 // Initialize the platform specific string and language
235 InitializeStringSupport ();
236 InitializeLanguage (TRUE
);
237 InitializeFrontPage (FALSE
);
242 PlatformBdsConnectConsole (
243 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
249 Connect the predefined platform default console device. Always try to find
250 and enable the vga device if have.
254 PlatformConsole - Predfined platform default console device array.
258 EFI_SUCCESS - Success connect at least one ConIn and ConOut
259 device, there must have one ConOut device is
262 EFI_STATUS - Return the status of
263 BdsLibConnectAllDefaultConsoles ()
271 Status
= EFI_SUCCESS
;
274 // Have chance to connect the platform default console,
275 // the platform default console is the minimue device group
276 // the platform should support
278 while (PlatformConsole
[Index
].DevicePath
!= NULL
) {
280 // Update the console variable with the connect type
282 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
283 BdsLibUpdateConsoleVariable (L
"ConIn", PlatformConsole
[Index
].DevicePath
, NULL
);
286 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
287 BdsLibUpdateConsoleVariable (L
"ConOut", PlatformConsole
[Index
].DevicePath
, NULL
);
290 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
291 BdsLibUpdateConsoleVariable (L
"ErrOut", PlatformConsole
[Index
].DevicePath
, NULL
);
297 // Connect the all the default console with current cosole variable
299 Status
= BdsLibConnectAllDefaultConsoles ();
300 if (EFI_ERROR (Status
)) {
308 PlatformBdsConnectSequence (
315 Connect with predeined platform connect sequence,
316 the OEM/IBV can customize with their own connect sequence.
333 // Here we can get the customized platform connect sequence
334 // Notes: we can connect with new variable which record the
335 // last time boots connect device path sequence
337 while (gPlatformConnectSequence
[Index
] != NULL
) {
339 // Build the platform boot option
341 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
348 PlatformBdsGetDriverOption (
349 IN OUT LIST_ENTRY
*BdsDriverLists
355 Load the predefined driver option, OEM/IBV can customize this
356 to load their own drivers
360 BdsDriverLists - The header of the driver option link list.
373 // Here we can get the customized platform driver option
375 while (gPlatformDriverOption
[Index
] != NULL
) {
377 // Build the platform boot option
379 BdsLibRegisterNewOption (BdsDriverLists
, gPlatformDriverOption
[Index
], NULL
, L
"DriverOrder");
386 PlatformBdsDiagnostics (
387 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
394 Perform the platform diagnostic, such like test memory. OEM/IBV also
395 can customize this fuction to support specific platform diagnostic.
399 MemoryTestLevel - The memory test intensive level
401 QuietBoot - Indicate if need to enable the quiet boot
412 // Here we can decide if we need to show
413 // the diagnostics screen
414 // Notes: this quiet boot code should be remove
415 // from the graphic lib
418 EnableQuietBoot (&gEfiDefaultBmpLogoGuid
);
420 // Perform system diagnostic
422 Status
= BdsMemoryTest (MemoryTestLevel
);
423 if (EFI_ERROR (Status
)) {
430 // Perform system diagnostic
432 Status
= BdsMemoryTest (MemoryTestLevel
);
436 PlatformBdsPolicyBehavior (
437 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE
*PrivateData
,
438 IN OUT LIST_ENTRY
*DriverOptionList
,
439 IN OUT LIST_ENTRY
*BootOptionList
445 The function will excute with as the platform policy, current policy
446 is driven by boot mode. IBV/OEM can customize this code for their specific
451 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
453 DriverOptionList - The header of the driver option link list
455 BootOptionList - The header of the boot option link list
467 // Init the time out value
469 Timeout
= BdsLibGetTimeout ();
472 // Load the driver option as the driver option list
474 PlatformBdsGetDriverOption (DriverOptionList
);
477 // Get current Boot Mode
479 PrivateData
->BootMode
= GetBootModeHob();
482 // Go the different platform policy with different boot mode
483 // Notes: this part code can be change with the table policy
485 switch (PrivateData
->BootMode
) {
487 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES
:
488 case BOOT_WITH_MINIMAL_CONFIGURATION
:
490 // In no-configuration boot mode, we can connect the
493 BdsLibConnectAllDefaultConsoles ();
494 PlatformBdsDiagnostics (IGNORE
, TRUE
);
497 // Perform some platform specific connect sequence
499 PlatformBdsConnectSequence ();
502 // Notes: current time out = 0 can not enter the
505 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
508 // Check the boot option with the boot option list
510 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
513 case BOOT_ON_FLASH_UPDATE
:
515 // Boot with the specific configuration
517 PlatformBdsConnectConsole (gPlatformConsole
);
518 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
);
520 ProcessCapsules (BOOT_ON_FLASH_UPDATE
);
523 case BOOT_IN_RECOVERY_MODE
:
525 // In recovery mode, just connect platform console
526 // and show up the front page
528 PlatformBdsConnectConsole (gPlatformConsole
);
529 PlatformBdsDiagnostics (EXTENSIVE
, FALSE
);
532 // In recovery boot mode, we still enter to the
535 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
538 case BOOT_WITH_FULL_CONFIGURATION
:
539 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS
:
540 case BOOT_WITH_DEFAULT_SETTINGS
:
543 // Connect platform console
545 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
546 if (EFI_ERROR (Status
)) {
548 // Here OEM/IBV can customize with defined action
550 PlatformBdsNoConsoleAction ();
553 PlatformBdsDiagnostics (IGNORE
, TRUE
);
556 // Perform some platform specific connect sequence
558 PlatformBdsConnectSequence ();
561 // Give one chance to enter the setup if we
564 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
567 // Here we have enough time to do the enumeration of boot device
569 BdsLibEnumerateAllBootOption (BootOptionList
);
578 PlatformBdsBootSuccess (
579 IN BDS_COMMON_OPTION
*Option
585 Hook point after a boot attempt succeeds. We don't expect a boot option to
586 return, so the UEFI 2.0 specification defines that you will default to an
587 interactive mode and stop processing the BootOrder list in this case. This
588 is alos a platform implementation and can be customized by IBV/OEM.
592 Option - Pointer to Boot Option that succeeded to boot.
603 // If Boot returned with EFI_SUCCESS and there is not in the boot device
604 // select loop then we need to pop up a UI and wait for user input.
606 TmpStr
= GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED
));
607 if (TmpStr
!= NULL
) {
608 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
614 PlatformBdsBootFail (
615 IN BDS_COMMON_OPTION
*Option
,
616 IN EFI_STATUS Status
,
618 IN UINTN ExitDataSize
624 Hook point after a boot attempt fails.
628 Option - Pointer to Boot Option that failed to boot.
630 Status - Status returned from failed boot.
632 ExitData - Exit data returned from failed boot.
634 ExitDataSize - Exit data size returned from failed boot.
645 // If Boot returned with failed status then we need to pop up a UI and wait
648 TmpStr
= GetStringById (STRING_TOKEN (STR_BOOT_FAILED
));
649 if (TmpStr
!= NULL
) {
650 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
657 PlatformBdsNoConsoleAction (
664 This function is remained for IBV/OEM to do some platform action,
665 if there no console device can be connected.
673 EFI_SUCCESS - Direct return success now.