]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
ArmPlatformPkg/ArmVirtualizationPkg: Added support for Intel BDS
[mirror_edk2.git] / ArmPlatformPkg / Library / PlatformIntelBdsLib / IntelBdsPlatform.c
diff --git a/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c b/ArmPlatformPkg/Library/PlatformIntelBdsLib/IntelBdsPlatform.c
new file mode 100644 (file)
index 0000000..c07fc0f
--- /dev/null
@@ -0,0 +1,376 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
+\r
+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
+**/\r
+\r
+#include "IntelBdsPlatform.h"\r
+\r
+///\r
+/// Predefined platform default time out value\r
+///\r
+UINT16                      gPlatformBootTimeOutDefault;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformIntelBdsConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  gPlatformBootTimeOutDefault = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// BDS Platform Functions\r
+//\r
+/**\r
+  Platform Bds init. Include the platform firmware vendor, revision\r
+  and so crc check.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBdsInit (\r
+  VOID\r
+  )\r
+{\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetConsoleDevicePathFromVariable (\r
+  IN  CHAR16*             ConsoleVarName,\r
+  IN  CHAR16*             DefaultConsolePaths,\r
+  OUT EFI_DEVICE_PATH**   DevicePaths\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  UINTN                     Size;\r
+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstances;\r
+  EFI_DEVICE_PATH_PROTOCOL* DevicePathInstance;\r
+  CHAR16*                   DevicePathStr;\r
+  CHAR16*                   NextDevicePathStr;\r
+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;\r
+\r
+  Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);\r
+  if (EFI_ERROR(Status)) {\r
+    // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)\r
+    if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {\r
+      *DevicePaths = NULL;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
+    ASSERT_EFI_ERROR(Status);\r
+\r
+    DevicePathInstances = NULL;\r
+\r
+    // Extract the Device Path instances from the multi-device path string\r
+    while ((DefaultConsolePaths != NULL) && (DefaultConsolePaths[0] != L'\0')) {\r
+      NextDevicePathStr = StrStr (DefaultConsolePaths, L";");\r
+      if (NextDevicePathStr == NULL) {\r
+        DevicePathStr = DefaultConsolePaths;\r
+        DefaultConsolePaths = NULL;\r
+      } else {\r
+        DevicePathStr = (CHAR16*)AllocateCopyPool ((NextDevicePathStr - DefaultConsolePaths + 1) * sizeof(CHAR16), DefaultConsolePaths);\r
+        *(DevicePathStr + (NextDevicePathStr - DefaultConsolePaths)) = L'\0';\r
+        DefaultConsolePaths = NextDevicePathStr;\r
+        if (DefaultConsolePaths[0] == L';') {\r
+          DefaultConsolePaths++;\r
+        }\r
+      }\r
+\r
+      DevicePathInstance = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (DevicePathStr);\r
+      ASSERT(DevicePathInstance != NULL);\r
+      DevicePathInstances = AppendDevicePathInstance (DevicePathInstances, DevicePathInstance);\r
+\r
+      if (NextDevicePathStr != NULL) {\r
+        FreePool (DevicePathStr);\r
+      }\r
+      FreePool (DevicePathInstance);\r
+    }\r
+\r
+    // Set the environment variable with this device path multi-instances\r
+    Size = GetDevicePathSize (DevicePathInstances);\r
+    if (Size > 0) {\r
+      gRT->SetVariable (\r
+          ConsoleVarName,\r
+          &gEfiGlobalVariableGuid,\r
+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+          Size,\r
+          DevicePathInstances\r
+          );\r
+    } else {\r
+      Status = EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR(Status)) {\r
+    *DevicePaths = DevicePathInstances;\r
+  }\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+InitializeConsolePipe (\r
+  IN EFI_DEVICE_PATH    *ConsoleDevicePaths,\r
+  IN EFI_GUID           *Protocol,\r
+  OUT EFI_HANDLE        *Handle,\r
+  OUT VOID*             *Interface\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  UINTN                     Size;\r
+  UINTN                     NoHandles;\r
+  EFI_HANDLE                *Buffer;\r
+  EFI_DEVICE_PATH_PROTOCOL* DevicePath;\r
+\r
+  // Connect all the Device Path Consoles\r
+  while (ConsoleDevicePaths != NULL) {\r
+    DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);\r
+\r
+    Status = BdsConnectDevicePath (DevicePath, Handle, NULL);\r
+    DEBUG_CODE_BEGIN();\r
+      if (EFI_ERROR(Status)) {\r
+        // We convert back to the text representation of the device Path\r
+        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
+        CHAR16* DevicePathTxt;\r
+        EFI_STATUS Status;\r
+\r
+        Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
+        if (!EFI_ERROR(Status)) {\r
+          DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);\r
+\r
+          DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));\r
+\r
+          FreePool (DevicePathTxt);\r
+        }\r
+      }\r
+    DEBUG_CODE_END();\r
+\r
+    // If the console splitter driver is not supported by the platform then use the first Device Path\r
+    // instance for the console interface.\r
+    if (!EFI_ERROR(Status) && (*Interface == NULL)) {\r
+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
+    }\r
+  }\r
+\r
+  // No Device Path has been defined for this console interface. We take the first protocol implementation\r
+  if (*Interface == NULL) {\r
+    Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      BdsConnectAllDrivers ();\r
+      Status = gBS->LocateHandleBuffer (ByProtocol, Protocol, NULL, &NoHandles, &Buffer);\r
+    }\r
+\r
+    if (!EFI_ERROR(Status)) {\r
+      *Handle = Buffer[0];\r
+      Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+    FreePool (Buffer);\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Connect the predefined platform default console device. Always try to find\r
+  and enable the vga device if have.\r
+\r
+  @param PlatformConsole          Predefined platform default console device array.\r
+\r
+  @retval EFI_SUCCESS             Success connect at least one ConIn and ConOut\r
+                                  device, there must have one ConOut device is\r
+                                  active vga device.\r
+  @return Return the status of BdsLibConnectAllDefaultConsoles ()\r
+\r
+**/\r
+EFI_STATUS\r
+PlatformBdsConnectConsole (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH*          ConOutDevicePaths;\r
+  EFI_DEVICE_PATH*          ConInDevicePaths;\r
+  EFI_DEVICE_PATH*          ConErrDevicePaths;\r
+\r
+  // By getting the Console Device Paths from the environment variables before initializing the console pipe, we\r
+  // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface\r
+  // of newly installed console drivers\r
+  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  // Initialize the Consoles\r
+  Status = InitializeConsolePipe (ConOutDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **)&gST->ConOut);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = InitializeConsolePipe (ConInDevicePaths, &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **)&gST->ConIn);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = InitializeConsolePipe (ConErrDevicePaths, &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **)&gST->StdErr);\r
+  if (EFI_ERROR(Status)) {\r
+    // In case of error, we reuse the console output for the error output\r
+    gST->StandardErrorHandle = gST->ConsoleOutHandle;\r
+    gST->StdErr = gST->ConOut;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Connect with predefined platform connect sequence,\r
+  the OEM/IBV can customize with their own connect sequence.\r
+**/\r
+VOID\r
+PlatformBdsConnectSequence (\r
+  VOID\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Load the predefined driver option, OEM/IBV can customize this\r
+  to load their own drivers\r
+\r
+  @param BdsDriverLists  - The header of the driver option link list.\r
+\r
+**/\r
+VOID\r
+PlatformBdsGetDriverOption (\r
+  IN OUT LIST_ENTRY              *BdsDriverLists\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
+  can customize this function to support specific platform diagnostic.\r
+\r
+  @param MemoryTestLevel  The memory test intensive level\r
+  @param QuietBoot        Indicate if need to enable the quiet boot\r
+  @param BaseMemoryTest   A pointer to BdsMemoryTest()\r
+\r
+**/\r
+VOID\r
+PlatformBdsDiagnostics (\r
+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
+  IN BOOLEAN                     QuietBoot,\r
+  IN BASEM_MEMORY_TEST           BaseMemoryTest\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  The function will execute 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
+  @param  DriverOptionList        The header of the driver option link list\r
+  @param  BootOptionList          The header of the boot option link list\r
+  @param  ProcessCapsules         A pointer to ProcessCapsules()\r
+  @param  BaseMemoryTest          A pointer to BaseMemoryTest()\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBdsPolicyBehavior (\r
+  IN LIST_ENTRY                      *DriverOptionList,\r
+  IN LIST_ENTRY                      *BootOptionList,\r
+  IN PROCESS_CAPSULES                ProcessCapsules,\r
+  IN BASEM_MEMORY_TEST               BaseMemoryTest\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+\r
+  Status = PlatformBdsConnectConsole ();\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
+  return, so the UEFI 2.0 specification defines that you will default to an\r
+  interactive mode and stop processing the BootOrder list in this case. This\r
+  is also a platform implementation and can be customized by IBV/OEM.\r
+\r
+  @param  Option                  Pointer to Boot Option that succeeded to boot.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBdsBootSuccess (\r
+  IN  BDS_COMMON_OPTION *Option\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Hook point after a boot attempt fails.\r
+\r
+  @param  Option                  Pointer to Boot Option that failed to boot.\r
+  @param  Status                  Status returned from failed boot.\r
+  @param  ExitData                Exit data returned from failed boot.\r
+  @param  ExitDataSize            Exit data size returned from failed boot.\r
+\r
+**/\r
+VOID\r
+EFIAPI\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
+\r
+/**\r
+  This function locks platform flash that is not allowed to be updated during normal boot path.\r
+  The flash layout is platform specific.\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformBdsLockNonUpdatableFlash (\r
+  VOID\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+\r
+/**\r
+  Lock the ConsoleIn device in system table. All key\r
+  presses will be ignored until the Password is typed in. The only way to\r
+  disable the password is to type it in to a ConIn device.\r
+\r
+  @param  Password        Password used to lock ConIn device.\r
+\r
+  @retval EFI_SUCCESS     lock the Console In Spliter virtual handle successfully.\r
+  @retval EFI_UNSUPPORTED Password not found\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LockKeyboards (\r
+  IN  CHAR16    *Password\r
+  )\r
+{\r
+    return EFI_UNSUPPORTED;\r
+}\r