1 /*++ @file 2 3 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR> 4 Portions copyright (c) 2011, Apple Inc. All rights reserved. 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 #include "BdsPlatform.h" 16 17 EMU_SYSTEM_CONFIGURATION mSystemConfigData; 18 19 VOID 20 SetupVariableInit ( 21 VOID 22 ) 23 { 24 EFI_STATUS Status; 25 UINTN Size; 26 27 Size = sizeof (mSystemConfigData); 28 Status = gRT->GetVariable ( 29 L"Setup", 30 &gEmuSystemConfigGuid, 31 NULL, 32 &Size, 33 (VOID *) &mSystemConfigData 34 ); 35 36 if (EFI_ERROR (Status)) { 37 // 38 // SetupVariable is corrupt 39 // 40 mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn); 41 mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow); 42 43 Status = gRT->SetVariable ( 44 L"Setup", 45 &gEmuSystemConfigGuid, 46 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 47 sizeof (mSystemConfigData), 48 (VOID *) &mSystemConfigData 49 ); 50 if (EFI_ERROR (Status)) { 51 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status)); 52 } 53 } 54 } 55 56 // 57 // BDS Platform Functions 58 // 59 VOID 60 EFIAPI 61 PlatformBdsInit ( 62 VOID 63 ) 64 /*++ 65 66 Routine Description: 67 68 Platform Bds init. Include the platform firmware vendor, revision 69 and so crc check. 70 71 Arguments: 72 73 Returns: 74 75 None. 76 77 **/ 78 { 79 SetupVariableInit (); 80 } 81 82 EFI_STATUS 83 PlatformBdsConnectConsole ( 84 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole 85 ) 86 /*++ 87 88 Routine Description: 89 90 Connect the predefined platform default console device. Always try to find 91 and enable the vga device if have. 92 93 Arguments: 94 95 PlatformConsole - Predfined platform default console device array. 96 97 Returns: 98 99 EFI_SUCCESS - Success connect at least one ConIn and ConOut 100 device, there must have one ConOut device is 101 active vga device. 102 103 EFI_STATUS - Return the status of 104 BdsLibConnectAllDefaultConsoles () 105 106 **/ 107 { 108 EFI_STATUS Status; 109 UINTN Index; 110 111 Index = 0; 112 Status = EFI_SUCCESS; 113 114 // 115 // Have chance to connect the platform default console, 116 // the platform default console is the minimue device group 117 // the platform should support 118 // 119 while (PlatformConsole[Index].DevicePath != NULL) { 120 // 121 // Update the console variable with the connect type 122 // 123 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) { 124 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL); 125 } 126 127 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) { 128 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL); 129 } 130 131 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) { 132 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL); 133 } 134 135 Index++; 136 } 137 // 138 // Connect the all the default console with current cosole variable 139 // 140 Status = BdsLibConnectAllDefaultConsoles (); 141 return Status; 142 } 143 144 VOID 145 PlatformBdsConnectSequence ( 146 VOID 147 ) 148 /*++ 149 150 Routine Description: 151 152 Connect with predeined platform connect sequence, 153 the OEM/IBV can customize with their own connect sequence. 154 155 Arguments: 156 157 None. 158 159 Returns: 160 161 None. 162 163 **/ 164 { 165 UINTN Index; 166 167 Index = 0; 168 169 // 170 // Here we can get the customized platform connect sequence 171 // Notes: we can connect with new variable which record the 172 // last time boots connect device path sequence 173 // 174 while (gPlatformConnectSequence[Index] != NULL) { 175 // 176 // Build the platform boot option 177 // 178 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]); 179 Index++; 180 } 181 182 // 183 // Just use the simple policy to connect all devices 184 // 185 BdsLibConnectAll (); 186 } 187 188 VOID 189 PlatformBdsGetDriverOption ( 190 IN OUT LIST_ENTRY *BdsDriverLists 191 ) 192 /*++ 193 194 Routine Description: 195 196 Load the predefined driver option, OEM/IBV can customize this 197 to load their own drivers 198 199 Arguments: 200 201 BdsDriverLists - The header of the driver option link list. 202 203 Returns: 204 205 None. 206 207 **/ 208 { 209 UINTN Index; 210 211 Index = 0; 212 213 // 214 // Here we can get the customized platform driver option 215 // 216 while (gPlatformDriverOption[Index] != NULL) { 217 // 218 // Build the platform boot option 219 // 220 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder"); 221 Index++; 222 } 223 224 } 225 226 VOID 227 PlatformBdsDiagnostics ( 228 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel, 229 IN BOOLEAN QuietBoot, 230 IN BASEM_MEMORY_TEST BaseMemoryTest 231 ) 232 /*++ 233 234 Routine Description: 235 236 Perform the platform diagnostic, such like test memory. OEM/IBV also 237 can customize this fuction to support specific platform diagnostic. 238 239 Arguments: 240 241 MemoryTestLevel - The memory test intensive level 242 243 QuietBoot - Indicate if need to enable the quiet boot 244 245 BaseMemoryTest - A pointer to BdsMemoryTest() 246 247 Returns: 248 249 None. 250 251 **/ 252 { 253 EFI_STATUS Status; 254 255 // 256 // Here we can decide if we need to show 257 // the diagnostics screen 258 // Notes: this quiet boot code should be remove 259 // from the graphic lib 260 // 261 if (QuietBoot) { 262 EnableQuietBoot (PcdGetPtr(PcdLogoFile)); 263 // 264 // Perform system diagnostic 265 // 266 Status = BaseMemoryTest (MemoryTestLevel); 267 if (EFI_ERROR (Status)) { 268 DisableQuietBoot (); 269 } 270 271 return ; 272 } 273 // 274 // Perform system diagnostic 275 // 276 Status = BaseMemoryTest (MemoryTestLevel); 277 } 278 279 VOID 280 EFIAPI 281 PlatformBdsPolicyBehavior ( 282 IN OUT LIST_ENTRY *DriverOptionList, 283 IN OUT LIST_ENTRY *BootOptionList, 284 IN PROCESS_CAPSULES ProcessCapsules, 285 IN BASEM_MEMORY_TEST BaseMemoryTest 286 ) 287 /*++ 288 289 Routine Description: 290 291 The function will excute with as the platform policy, current policy 292 is driven by boot mode. IBV/OEM can customize this code for their specific 293 policy action. 294 295 Arguments: 296 297 DriverOptionList - The header of the driver option link list 298 299 BootOptionList - The header of the boot option link list 300 301 ProcessCapsules - A pointer to ProcessCapsules() 302 303 BaseMemoryTest - A pointer to BaseMemoryTest() 304 305 Returns: 306 307 None. 308 309 **/ 310 { 311 EFI_STATUS Status; 312 UINT16 Timeout; 313 EFI_BOOT_MODE BootMode; 314 315 // 316 // Init the time out value 317 // 318 Timeout = PcdGet16 (PcdPlatformBootTimeOut); 319 320 // 321 // Load the driver option as the driver option list 322 // 323 PlatformBdsGetDriverOption (DriverOptionList); 324 325 // 326 // Get current Boot Mode 327 // 328 Status = BdsLibGetBootMode (&BootMode); 329 330 // 331 // Go the different platform policy with different boot mode 332 // Notes: this part code can be change with the table policy 333 // 334 switch (BootMode) { 335 336 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES: 337 case BOOT_WITH_MINIMAL_CONFIGURATION: 338 // 339 // In no-configuration boot mode, we can connect the 340 // console directly. 341 // 342 BdsLibConnectAllDefaultConsoles (); 343 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest); 344 345 // 346 // Perform some platform specific connect sequence 347 // 348 PlatformBdsConnectSequence (); 349 350 // 351 // Notes: current time out = 0 can not enter the 352 // front page 353 // 354 PlatformBdsEnterFrontPage (Timeout, FALSE); 355 356 // 357 // Check the boot option with the boot option list 358 // 359 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder"); 360 break; 361 362 case BOOT_ON_FLASH_UPDATE: 363 // 364 // Boot with the specific configuration 365 // 366 PlatformBdsConnectConsole (gPlatformConsole); 367 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest); 368 BdsLibConnectAll (); 369 ProcessCapsules (BOOT_ON_FLASH_UPDATE); 370 break; 371 372 case BOOT_IN_RECOVERY_MODE: 373 // 374 // In recovery mode, just connect platform console 375 // and show up the front page 376 // 377 PlatformBdsConnectConsole (gPlatformConsole); 378 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest); 379 380 // 381 // In recovery boot mode, we still enter to the 382 // frong page now 383 // 384 PlatformBdsEnterFrontPage (Timeout, FALSE); 385 break; 386 387 case BOOT_WITH_FULL_CONFIGURATION: 388 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS: 389 case BOOT_WITH_DEFAULT_SETTINGS: 390 default: 391 // 392 // Connect platform console 393 // 394 Status = PlatformBdsConnectConsole (gPlatformConsole); 395 if (EFI_ERROR (Status)) { 396 // 397 // Here OEM/IBV can customize with defined action 398 // 399 PlatformBdsNoConsoleAction (); 400 } 401 402 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest); 403 404 // 405 // Perform some platform specific connect sequence 406 // 407 PlatformBdsConnectSequence (); 408 409 // 410 // Give one chance to enter the setup if we 411 // have the time out 412 // 413 PlatformBdsEnterFrontPage (Timeout, FALSE); 414 415 // 416 // Here we have enough time to do the enumeration of boot device 417 // 418 BdsLibEnumerateAllBootOption (BootOptionList); 419 break; 420 } 421 422 return ; 423 424 } 425 426 VOID 427 EFIAPI 428 PlatformBdsBootSuccess ( 429 IN BDS_COMMON_OPTION *Option 430 ) 431 /*++ 432 433 Routine Description: 434 435 Hook point after a boot attempt succeeds. We don't expect a boot option to 436 return, so the EFI 1.0 specification defines that you will default to an 437 interactive mode and stop processing the BootOrder list in this case. This 438 is alos a platform implementation and can be customized by IBV/OEM. 439 440 Arguments: 441 442 Option - Pointer to Boot Option that succeeded to boot. 443 444 Returns: 445 446 None. 447 448 **/ 449 { 450 CHAR16 *TmpStr; 451 452 // 453 // If Boot returned with EFI_SUCCESS and there is not in the boot device 454 // select loop then we need to pop up a UI and wait for user input. 455 // 456 TmpStr = Option->StatusString; 457 if (TmpStr != NULL) { 458 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL); 459 FreePool (TmpStr); 460 } 461 } 462 463 VOID 464 EFIAPI 465 PlatformBdsBootFail ( 466 IN BDS_COMMON_OPTION *Option, 467 IN EFI_STATUS Status, 468 IN CHAR16 *ExitData, 469 IN UINTN ExitDataSize 470 ) 471 /*++ 472 473 Routine Description: 474 475 Hook point after a boot attempt fails. 476 477 Arguments: 478 479 Option - Pointer to Boot Option that failed to boot. 480 481 Status - Status returned from failed boot. 482 483 ExitData - Exit data returned from failed boot. 484 485 ExitDataSize - Exit data size returned from failed boot. 486 487 Returns: 488 489 None. 490 491 **/ 492 { 493 CHAR16 *TmpStr; 494 495 // 496 // If Boot returned with failed status then we need to pop up a UI and wait 497 // for user input. 498 // 499 TmpStr = Option->StatusString; 500 if (TmpStr != NULL) { 501 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL); 502 FreePool (TmpStr); 503 } 504 } 505 506 EFI_STATUS 507 PlatformBdsNoConsoleAction ( 508 VOID 509 ) 510 /*++ 511 512 Routine Description: 513 514 This function is remained for IBV/OEM to do some platform action, 515 if there no console device can be connected. 516 517 Arguments: 518 519 None. 520 521 Returns: 522 523 EFI_SUCCESS - Direct return success now. 524 525 **/ 526 { 527 return EFI_SUCCESS; 528 } 529 530 VOID 531 EFIAPI 532 PlatformBdsLockNonUpdatableFlash ( 533 VOID 534 ) 535 { 536 return; 537 } 538 539 /** 540 Lock the ConsoleIn device in system table. All key 541 presses will be ignored until the Password is typed in. The only way to 542 disable the password is to type it in to a ConIn device. 543 544 @param Password Password used to lock ConIn device. 545 546 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully. 547 @retval EFI_UNSUPPORTED Password not found 548 549 **/ 550 EFI_STATUS 551 EFIAPI 552 LockKeyboards ( 553 IN CHAR16 *Password 554 ) 555 { 556 return EFI_UNSUPPORTED; 557 } 558