--- /dev/null
+/** @file\r
+*\r
+* Copyright (c) 2017, Linaro, Ltd. All rights reserved.\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 <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+\r
+#include "DtPlatformDxe.h"\r
+\r
+extern UINT8 DtPlatformHiiBin[];\r
+extern UINT8 DtPlatformDxeStrings[];\r
+\r
+typedef struct {\r
+ VENDOR_DEVICE_PATH VendorDevicePath;\r
+ EFI_DEVICE_PATH_PROTOCOL End;\r
+} HII_VENDOR_DEVICE_PATH;\r
+\r
+STATIC HII_VENDOR_DEVICE_PATH mDtPlatformDxeVendorDevicePath = {\r
+ {\r
+ {\r
+ HARDWARE_DEVICE_PATH,\r
+ HW_VENDOR_DP,\r
+ {\r
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+ }\r
+ },\r
+ DT_PLATFORM_FORMSET_GUID\r
+ },\r
+ {\r
+ END_DEVICE_PATH_TYPE,\r
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+ {\r
+ (UINT8) (END_DEVICE_PATH_LENGTH),\r
+ (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
+ }\r
+ }\r
+};\r
+\r
+STATIC\r
+EFI_STATUS\r
+InstallHiiPages (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HII_HANDLE HiiHandle;\r
+ EFI_HANDLE DriverHandle;\r
+\r
+ DriverHandle = NULL;\r
+ Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &mDtPlatformDxeVendorDevicePath,\r
+ NULL);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ HiiHandle = HiiAddPackages (&gDtPlatformFormSetGuid,\r
+ DriverHandle,\r
+ DtPlatformDxeStrings,\r
+ DtPlatformHiiBin,\r
+ NULL);\r
+\r
+ if (HiiHandle == NULL) {\r
+ gBS->UninstallMultipleProtocolInterfaces (DriverHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &mDtPlatformDxeVendorDevicePath,\r
+ NULL);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ The entry point for DtPlatformDxe driver.\r
+\r
+ @param[in] ImageHandle The image handle of the driver.\r
+ @param[in] SystemTable The system table.\r
+\r
+ @retval EFI_ALREADY_STARTED The driver already exists in system.\r
+ @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of\r
+ resources.\r
+ @retval EFI_SUCCES All the related protocols are installed on\r
+ the driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DtPlatformDxeEntryPoint (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ DT_ACPI_VARSTORE_DATA DtAcpiPref;\r
+ UINTN BufferSize;\r
+ VOID *Dtb;\r
+ UINTN DtbSize;\r
+ VOID *DtbCopy;\r
+\r
+ //\r
+ // Check whether a DTB blob is included in the firmware image.\r
+ //\r
+ Dtb = NULL;\r
+ Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid,\r
+ EFI_SECTION_RAW, 0, &Dtb, &DtbSize);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_WARN, "%a: no DTB blob found, defaulting to ACPI\n",\r
+ __FUNCTION__));\r
+ DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;\r
+ } else {\r
+ //\r
+ // Get the current DT/ACPI preference from the DtAcpiPref variable.\r
+ //\r
+ BufferSize = sizeof (DtAcpiPref);\r
+ Status = gRT->GetVariable(DT_ACPI_VARIABLE_NAME, &gDtPlatformFormSetGuid,\r
+ NULL, &BufferSize, &DtAcpiPref);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_WARN, "%a: no DT/ACPI preference found, defaulting to DT\n",\r
+ __FUNCTION__));\r
+ DtAcpiPref.Pref = DT_ACPI_SELECT_DT;\r
+ }\r
+ }\r
+\r
+ if (!EFI_ERROR (Status) &&\r
+ DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI &&\r
+ DtAcpiPref.Pref != DT_ACPI_SELECT_DT) {\r
+ DEBUG ((DEBUG_WARN, "%a: invalid value for %s, defaulting to DT\n",\r
+ __FUNCTION__, DT_ACPI_VARIABLE_NAME));\r
+ DtAcpiPref.Pref = DT_ACPI_SELECT_DT;\r
+ Status = EFI_INVALID_PARAMETER; // trigger setvar below\r
+ }\r
+\r
+ //\r
+ // Write the newly selected default value back to the variable store.\r
+ //\r
+ if (EFI_ERROR (Status)) {\r
+ Status = gRT->SetVariable(DT_ACPI_VARIABLE_NAME, &gDtPlatformFormSetGuid,\r
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+ sizeof (DtAcpiPref), &DtAcpiPref);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ if (DtAcpiPref.Pref == DT_ACPI_SELECT_ACPI) {\r
+ //\r
+ // ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a\r
+ // NULL protocol to unlock dispatch of ACPI related drivers.\r
+ //\r
+ Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle,\r
+ &gEdkiiPlatformHasAcpiGuid, NULL, NULL);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR,\r
+ "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",\r
+ __FUNCTION__));\r
+ return Status;\r
+ }\r
+ } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {\r
+ //\r
+ // DT was selected: copy the blob into newly allocated memory and install\r
+ // a reference to it as the FDT configuration table.\r
+ //\r
+ DtbCopy = AllocateCopyPool (DtbSize, Dtb);\r
+ if (DtbCopy == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DtbCopy);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n",\r
+ __FUNCTION__));\r
+ FreePool (DtbCopy);\r
+ return Status;\r
+ }\r
+ } else {\r
+ ASSERT (FALSE);\r
+ }\r
+\r
+ //\r
+ // No point in installing the HII pages if ACPI is the only description\r
+ // we have\r
+ //\r
+ if (Dtb == NULL) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Note that we don't uninstall the gEdkiiPlatformHasAcpiGuid protocol nor\r
+ // the FDT configuration table if the following call fails. While that will\r
+ // cause loading of this driver to fail, proceeding with ACPI and DT both\r
+ // disabled will guarantee a failed boot, and so it is better to leave them\r
+ // installed in that case.\r
+ //\r
+ return InstallHiiPages ();\r
+}\r
--- /dev/null
+/** @file\r
+*\r
+* Copyright (c) 2017, Linaro Limited. All rights reserved.\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
+#ifndef __DT_PLATFORM_DXE_H__\r
+#define __DT_PLATFORM_DXE_H__\r
+\r
+#include <Guid/HiiPlatformSetupFormset.h>\r
+#include <Guid/DtPlatformFormSet.h>\r
+\r
+#define DT_ACPI_SELECT_DT 0x0\r
+#define DT_ACPI_SELECT_ACPI 0x1\r
+\r
+#define DT_ACPI_VARIABLE_NAME L"DtAcpiPref"\r
+\r
+typedef struct {\r
+ UINT8 Pref;\r
+ UINT8 Reserved[3];\r
+} DT_ACPI_VARSTORE_DATA;\r
+\r
+#endif\r
--- /dev/null
+## @file\r
+#\r
+# Copyright (c) 2017, Linaro, Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are licensed and made\r
+# available under the terms and conditions of the BSD License which\r
+# accompanies this distribution. The full text of the license may be\r
+# found at 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\r
+# IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010019\r
+ BASE_NAME = DtPlatformDxe\r
+ FILE_GUID = FC097B3C-2EBD-4A75-A3DA-121DCAB365CC\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ ENTRY_POINT = DtPlatformDxeEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64\r
+#\r
+\r
+[Sources]\r
+ DtPlatformDxe.c\r
+ DtPlatformHii.vfr\r
+ DtPlatformHii.uni\r
+\r
+[Packages]\r
+ EmbeddedPkg/EmbeddedPkg.dec\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ DebugLib\r
+ DxeServicesLib\r
+ HiiLib\r
+ MemoryAllocationLib\r
+ UefiBootServicesTableLib\r
+ UefiDriverEntryPoint\r
+ UefiRuntimeServicesTableLib\r
+\r
+[Guids]\r
+ gDtPlatformFormSetGuid\r
+ gDtPlatformDefaultDtbFileGuid\r
+ gEdkiiPlatformHasAcpiGuid\r
+ gFdtTableGuid\r
+\r
+[Depex]\r
+ gEfiVariableArchProtocolGuid AND\r
+ gEfiVariableWriteArchProtocolGuid\r
--- /dev/null
+/** @file\r
+*\r
+* Copyright (c) 2017, Linaro, Ltd. All rights reserved.\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
+#langdef en-US "English"\r
+\r
+#string STR_FORM_SET_TITLE #language en-US "O/S Hardware Description Selection"\r
+#string STR_FORM_SET_TITLE_HELP #language en-US "Press <Enter> to choose between ACPI and DT hardware descriptions."\r
+\r
+#string STR_MAIN_FORM_TITLE #language en-US "O/S Hardware Description Selection"\r
+#string STR_NULL_STRING #language en-US ""\r
+\r
+#string STR_DT_ACPI_SELECT_PROMPT #language en-US "O/S Hardware Description"\r
+#string STR_DT_ACPI_SELECT_HELP #language en-US "Select the hardware description that will be exposed to the O/S."\r
+\r
+#string STR_DT_ACPI_SELECT_DT #language en-US "Device Tree"\r
+#string STR_DT_ACPI_SELECT_ACPI #language en-US "ACPI"\r
--- /dev/null
+/** @file\r
+*\r
+* Copyright (c) 2017, Linaro, Ltd. All rights reserved.\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 "DtPlatformDxe.h"\r
+\r
+//\r
+// EFI Variable attributes\r
+//\r
+#define EFI_VARIABLE_NON_VOLATILE 0x00000001\r
+#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002\r
+#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004\r
+#define EFI_VARIABLE_READ_ONLY 0x00000008\r
+\r
+formset\r
+ guid = DT_PLATFORM_FORMSET_GUID,\r
+ title = STRING_TOKEN(STR_FORM_SET_TITLE),\r
+ help = STRING_TOKEN(STR_FORM_SET_TITLE_HELP),\r
+ classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,\r
+\r
+ efivarstore DT_ACPI_VARSTORE_DATA,\r
+ attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, // EFI variable attributes\r
+ name = DtAcpiPref,\r
+ guid = DT_PLATFORM_FORMSET_GUID;\r
+\r
+ form formid = 0x1000,\r
+ title = STRING_TOKEN(STR_MAIN_FORM_TITLE);\r
+\r
+ oneof varid = DtAcpiPref.Pref,\r
+ prompt = STRING_TOKEN(STR_DT_ACPI_SELECT_PROMPT),\r
+ help = STRING_TOKEN(STR_DT_ACPI_SELECT_HELP),\r
+ flags = NUMERIC_SIZE_1 | INTERACTIVE | RESET_REQUIRED,\r
+ option text = STRING_TOKEN(STR_DT_ACPI_SELECT_DT), value = DT_ACPI_SELECT_DT, flags = DEFAULT;\r
+ option text = STRING_TOKEN(STR_DT_ACPI_SELECT_ACPI), value = DT_ACPI_SELECT_ACPI, flags = 0;\r
+ endoneof;\r
+\r
+ subtitle text = STRING_TOKEN(STR_NULL_STRING);\r
+\r
+ endform;\r
+\r
+endformset;\r
## Include/Guid/PlatformHasDeviceTree.h\r
gEdkiiPlatformHasDeviceTreeGuid = { 0x7ebb920d, 0x1aaf, 0x46d9, { 0xb2, 0xaf, 0x54, 0x1e, 0x1d, 0xce, 0x14, 0x8b } }\r
\r
+ # HII form set GUID for DtPlatformDxe driver\r
+ gDtPlatformFormSetGuid = { 0x2b7a240d, 0xd5ad, 0x4fd6, { 0xbe, 0x1c, 0xdf, 0xa4, 0x41, 0x5f, 0x55, 0x26 } }\r
+\r
+ # File GUID for default DTB image embedded in the firmware volume\r
+ gDtPlatformDefaultDtbFileGuid = { 0x25462cda, 0x221f, 0x47df, { 0xac, 0x1d, 0x25, 0x9c, 0xfa, 0xa4, 0xe3, 0x26 } }\r
+\r
[Protocols.common]\r
gHardwareInterruptProtocolGuid = { 0x2890B3EA, 0x053D, 0x1643, { 0xAD, 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } }\r
gEfiDebugSupportPeriodicCallbackProtocolGuid = { 0x9546e07c, 0x2cbb, 0x4c88, { 0x98, 0x6c, 0xcd, 0x34, 0x10, 0x86, 0xf0, 0x44 } }\r
--- /dev/null
+/** @file\r
+*\r
+* Copyright (c) 2017, Linaro Limited. All rights reserved.\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
+#ifndef __DT_PLATFORM_DEFAULT_DTB_FILE_H__\r
+#define __DT_PLATFORM_DEFAULT_DTB_FILE_H__\r
+\r
+#define DT_PLATFORM_DEFAULT_DTB_FILE_GUID \\r
+ { 0x25462cda, 0x221f, 0x47df, { 0xac, 0x1d, 0x25, 0x9c, 0xfa, 0xa4, 0xe3, 0x26 } }\r
+\r
+extern EFI_GUID gDtPlatformDefaultDtbFileGuid;\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+*\r
+* Copyright (c) 2017, Linaro Limited. All rights reserved.\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
+#ifndef __DT_PLATFORM_FORMSET_H__\r
+#define __DT_PLATFORM_FORMSET_H__\r
+\r
+#define DT_PLATFORM_FORMSET_GUID \\r
+ { 0x2b7a240d, 0xd5ad, 0x4fd6, { 0xbe, 0x1c, 0xdf, 0xa4, 0x41, 0x5f, 0x55, 0x26 } }\r
+\r
+extern EFI_GUID gDtPlatformFormSetGuid;\r
+\r
+#endif\r