]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/Library/Nt32BdsLib/BdsPlatform.c
UEFI HII: Merge UEFI HII support changes from branch.
[mirror_edk2.git] / Nt32Pkg / Library / Nt32BdsLib / BdsPlatform.c
diff --git a/Nt32Pkg/Library/Nt32BdsLib/BdsPlatform.c b/Nt32Pkg/Library/Nt32BdsLib/BdsPlatform.c
new file mode 100644 (file)
index 0000000..d6ee955
--- /dev/null
@@ -0,0 +1,516 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2006, Intel Corporation                                                         \r
+All rights reserved. This program and the accompanying materials                          \r
+are licensed and made available under the terms and conditions of the BSD License         \r
+which accompanies this distribution.  The full text of the license may be found at        \r
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  BdsPlatform.c\r
+\r
+Abstract:\r
+\r
+  This file include all platform action which can be customized\r
+  by IBV/OEM.\r
+\r
+--*/\r
+\r
+#include "BdsPlatform.h"\r
+\r
+CHAR16  mFirmwareVendor[] = L"TianoCore.org";\r
+\r
+//\r
+// BDS Platform Functions\r
+//\r
+VOID\r
+PlatformBdsInit (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Platform Bds init. Incude the platform firmware vendor, revision\r
+  and so crc check.\r
+\r
+Arguments:\r
+\r
+  PrivateData  - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
+\r
+Returns:\r
+\r
+  None.\r
+\r
+--*/\r
+{\r
+  //\r
+  // set firmwarevendor, here can be IBV/OEM customize\r
+  //\r
+  gST->FirmwareVendor = AllocateRuntimeCopyPool (\r
+                          sizeof (mFirmwareVendor),\r
+                          &mFirmwareVendor\r
+                          );\r
+  ASSERT (gST->FirmwareVendor != NULL);\r
+\r
+  gST->FirmwareRevision = 0;\r
+\r
+  //\r
+  // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
+  //\r
+  gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
+\r
+}\r
+\r
+EFI_STATUS\r
+PlatformBdsConnectConsole (\r
+  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Connect the predefined platform default console device. Always try to find\r
+  and enable the vga device if have.\r
+\r
+Arguments:\r
+\r
+  PlatformConsole         - Predfined platform default console device array.\r
\r
+Returns:\r
+\r
+  EFI_SUCCESS             - Success connect at least one ConIn and ConOut \r
+                            device, there must have one ConOut device is \r
+                            active vga device.\r
+  \r
+  EFI_STATUS              - Return the status of \r
+                            BdsLibConnectAllDefaultConsoles ()\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       Index;\r
+\r
+  Index   = 0;\r
+  Status  = EFI_SUCCESS;\r
+\r
+  //\r
+  // Have chance to connect the platform default console,\r
+  // the platform default console is the minimue device group\r
+  // the platform should support\r
+  //\r
+  while (PlatformConsole[Index].DevicePath != NULL) {\r
+    //\r
+    // Update the console variable with the connect type\r
+    //\r
+    if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
+      BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
+      BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
+      BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    Index++;\r
+  }\r
+  //\r
+  // Connect the all the default console with current cosole variable\r
+  //\r
+  Status = BdsLibConnectAllDefaultConsoles ();\r
+  \r
+  return Status;\r
+}\r
+\r
+VOID\r
+PlatformBdsConnectSequence (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Connect with predeined platform connect sequence, \r
+  the OEM/IBV can customize with their own connect sequence.\r
+  \r
+Arguments:\r
+\r
+  None.\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Here we can get the customized platform connect sequence\r
+  // Notes: we can connect with new variable which record the\r
+  // last time boots connect device path sequence\r
+  //\r
+  while (gPlatformConnectSequence[Index] != NULL) {\r
+    //\r
+    // Build the platform boot option\r
+    //\r
+    BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
+    Index++;\r
+  }\r
+\r
+  //\r
+  // Jst use the simple policy to connect all devices\r
+  //\r
+  BdsLibConnectAll ();\r
+}\r
+\r
+VOID\r
+PlatformBdsGetDriverOption (\r
+  IN OUT LIST_ENTRY              *BdsDriverLists\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load the predefined driver option, OEM/IBV can customize this\r
+  to load their own drivers\r
+  \r
+Arguments:\r
+\r
+  BdsDriverLists  - The header of the driver option link list.\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Here we can get the customized platform driver option\r
+  //\r
+  while (gPlatformDriverOption[Index] != NULL) {\r
+    //\r
+    // Build the platform boot option\r
+    //\r
+    BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
+    Index++;\r
+  }\r
+\r
+}\r
+\r
+VOID\r
+PlatformBdsDiagnostics (\r
+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
+  IN BOOLEAN                     QuietBoot\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
+  can customize this fuction to support specific platform diagnostic.\r
+  \r
+Arguments:\r
+\r
+  MemoryTestLevel  - The memory test intensive level\r
+  \r
+  QuietBoot        - Indicate if need to enable the quiet boot\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Here we can decide if we need to show\r
+  // the diagnostics screen\r
+  // Notes: this quiet boot code should be remove\r
+  // from the graphic lib\r
+  //\r
+  if (QuietBoot) {\r
+    EnableQuietBootEx (&gEfiDefaultBmpLogoGuid, mBdsImageHandle);\r
+    //\r
+    // Perform system diagnostic\r
+    //\r
+    Status = BdsMemoryTest (MemoryTestLevel);\r
+    if (EFI_ERROR (Status)) {\r
+      DisableQuietBoot ();\r
+    }\r
+\r
+    return ;\r
+  }\r
+  //\r
+  // Perform system diagnostic\r
+  //\r
+  Status = BdsMemoryTest (MemoryTestLevel);\r
+}\r
+\r
+VOID\r
+PlatformBdsPolicyBehavior (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData,\r
+  IN OUT LIST_ENTRY                  *DriverOptionList,\r
+  IN OUT LIST_ENTRY                  *BootOptionList\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The function will excute with as the platform policy, current policy\r
+  is driven by boot mode. IBV/OEM can customize this code for their specific\r
+  policy action.\r
+  \r
+Arguments:\r
+\r
+  PrivateData      - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
+  \r
+  DriverOptionList - The header of the driver option link list\r
+  \r
+  BootOptionList   - The header of the boot option link list\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT16      Timeout;\r
+\r
+  //\r
+  // Init the time out value\r
+  //\r
+  Timeout = BdsLibGetTimeout ();\r
+\r
+  //\r
+  // Load the driver option as the driver option list\r
+  //\r
+  PlatformBdsGetDriverOption (DriverOptionList);\r
+\r
+  //\r
+  // Get current Boot Mode\r
+  //\r
+  Status = BdsLibGetBootMode (&PrivateData->BootMode);\r
+\r
+  //\r
+  // Go the different platform policy with different boot mode\r
+  // Notes: this part code can be change with the table policy\r
+  //\r
+  switch (PrivateData->BootMode) {\r
+\r
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
+  case BOOT_WITH_MINIMAL_CONFIGURATION:\r
+    //\r
+    // In no-configuration boot mode, we can connect the\r
+    // console directly.\r
+    //\r
+    BdsLibConnectAllDefaultConsoles ();\r
+    PlatformBdsDiagnostics (IGNORE, TRUE);\r
+\r
+    //\r
+    // Perform some platform specific connect sequence\r
+    //\r
+    PlatformBdsConnectSequence ();\r
+\r
+    //\r
+    // Notes: current time out = 0 can not enter the\r
+    // front page\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+\r
+    //\r
+    // Check the boot option with the boot option list\r
+    //\r
+    BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
+    break;\r
+\r
+  case BOOT_ON_FLASH_UPDATE:\r
+    //\r
+    // Boot with the specific configuration\r
+    //\r
+    PlatformBdsConnectConsole (gPlatformConsole);\r
+    PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
+    BdsLibConnectAll ();\r
+    ProcessCapsules (BOOT_ON_FLASH_UPDATE);\r
+    break;\r
+\r
+  case BOOT_IN_RECOVERY_MODE:\r
+    //\r
+    // In recovery mode, just connect platform console\r
+    // and show up the front page\r
+    //\r
+    PlatformBdsConnectConsole (gPlatformConsole);\r
+    PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
+\r
+    //\r
+    // In recovery boot mode, we still enter to the\r
+    // frong page now\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+    break;\r
+\r
+  case BOOT_WITH_FULL_CONFIGURATION:\r
+  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:\r
+  case BOOT_WITH_DEFAULT_SETTINGS:\r
+  default:\r
+    //\r
+    // Connect platform console\r
+    //\r
+    Status = PlatformBdsConnectConsole (gPlatformConsole);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Here OEM/IBV can customize with defined action\r
+      //\r
+      PlatformBdsNoConsoleAction ();\r
+    }\r
+\r
+    PlatformBdsDiagnostics (IGNORE, TRUE);\r
+\r
+    //\r
+    // Perform some platform specific connect sequence\r
+    //\r
+    PlatformBdsConnectSequence ();\r
+\r
+    //\r
+    // Give one chance to enter the setup if we\r
+    // have the time out\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+\r
+    //\r
+    // Here we have enough time to do the enumeration of boot device\r
+    //\r
+    BdsLibEnumerateAllBootOption (BootOptionList);\r
+    break;\r
+  }\r
+\r
+  return ;\r
+\r
+}\r
+\r
+VOID\r
+PlatformBdsBootSuccess (\r
+  IN  BDS_COMMON_OPTION   *Option\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
+  return, so the EFI 1.0 specification defines that you will default to an\r
+  interactive mode and stop processing the BootOrder list in this case. This\r
+  is alos a platform implementation and can be customized by IBV/OEM.\r
+\r
+Arguments:\r
+\r
+  Option - Pointer to Boot Option that succeeded to boot.\r
+\r
+Returns:\r
+  \r
+  None.\r
+\r
+--*/\r
+{\r
+  CHAR16  *TmpStr;\r
+\r
+  //\r
+  // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
+  // select loop then we need to pop up a UI and wait for user input.\r
+  //\r
+  TmpStr = Option->StatusString;\r
+  if (TmpStr != NULL) {\r
+    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
+    FreePool (TmpStr);\r
+  }\r
+}\r
+\r
+VOID\r
+PlatformBdsBootFail (\r
+  IN  BDS_COMMON_OPTION  *Option,\r
+  IN  EFI_STATUS         Status,\r
+  IN  CHAR16             *ExitData,\r
+  IN  UINTN              ExitDataSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  Hook point after a boot attempt fails.\r
+\r
+Arguments:\r
+  \r
+  Option - Pointer to Boot Option that failed to boot.\r
+\r
+  Status - Status returned from failed boot.\r
+\r
+  ExitData - Exit data returned from failed boot.\r
+\r
+  ExitDataSize - Exit data size returned from failed boot.\r
+\r
+Returns:\r
+  \r
+  None.\r
+\r
+--*/\r
+{\r
+  CHAR16  *TmpStr;\r
+\r
+  //\r
+  // If Boot returned with failed status then we need to pop up a UI and wait\r
+  // for user input.\r
+  //\r
+  TmpStr = Option->StatusString;\r
+  if (TmpStr != NULL) {\r
+    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
+    FreePool (TmpStr);\r
+  }\r
+\r
+}\r
+\r
+EFI_STATUS\r
+PlatformBdsNoConsoleAction (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This function is remained for IBV/OEM to do some platform action,\r
+  if there no console device can be connected.\r
+\r
+Arguments:\r
+  \r
+  None.\r
+  \r
+Returns:\r
+  \r
+  EFI_SUCCESS      - Direct return success now.\r
+\r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformBdsLockNonUpdatableFlash (\r
+  VOID\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r