aboutsummaryrefslogtreecommitdiffstats
path: root/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe
diff options
context:
space:
mode:
Diffstat (limited to 'roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe')
-rw-r--r--roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c208
-rw-r--r--roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.h25
-rw-r--r--roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf54
-rw-r--r--roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.uni21
-rw-r--r--roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.vfr38
5 files changed, 346 insertions, 0 deletions
diff --git a/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c
new file mode 100644
index 000000000..a6ac30c32
--- /dev/null
+++ b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c
@@ -0,0 +1,208 @@
+/** @file
+*
+* Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+*
+* SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/DtPlatformDtbLoaderLib.h>
+#include <Library/HiiLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+
+#include "DtPlatformDxe.h"
+
+extern UINT8 DtPlatformHiiBin[];
+extern UINT8 DtPlatformDxeStrings[];
+
+typedef struct {
+ VENDOR_DEVICE_PATH VendorDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} HII_VENDOR_DEVICE_PATH;
+
+STATIC HII_VENDOR_DEVICE_PATH mDtPlatformDxeVendorDevicePath = {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ {
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
+ }
+ },
+ DT_PLATFORM_FORMSET_GUID
+ },
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ (UINT8) (END_DEVICE_PATH_LENGTH),
+ (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
+ }
+ }
+};
+
+STATIC
+EFI_STATUS
+InstallHiiPages (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_HII_HANDLE HiiHandle;
+ EFI_HANDLE DriverHandle;
+
+ DriverHandle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle,
+ &gEfiDevicePathProtocolGuid,
+ &mDtPlatformDxeVendorDevicePath,
+ NULL);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ HiiHandle = HiiAddPackages (&gDtPlatformFormSetGuid,
+ DriverHandle,
+ DtPlatformDxeStrings,
+ DtPlatformHiiBin,
+ NULL);
+
+ if (HiiHandle == NULL) {
+ gBS->UninstallMultipleProtocolInterfaces (DriverHandle,
+ &gEfiDevicePathProtocolGuid,
+ &mDtPlatformDxeVendorDevicePath,
+ NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+ return EFI_SUCCESS;
+}
+
+/**
+ The entry point for DtPlatformDxe driver.
+
+ @param[in] ImageHandle The image handle of the driver.
+ @param[in] SystemTable The system table.
+
+ @retval EFI_ALREADY_STARTED The driver already exists in system.
+ @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
+ resources.
+ @retval EFI_SUCCESS All the related protocols are installed on
+ the driver.
+
+**/
+EFI_STATUS
+EFIAPI
+DtPlatformDxeEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ DT_ACPI_VARSTORE_DATA DtAcpiPref;
+ UINTN BufferSize;
+ VOID *Dtb;
+ UINTN DtbSize;
+
+ Dtb = NULL;
+ Status = DtPlatformLoadDtb (&Dtb, &DtbSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN,
+ "%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n",
+ __FUNCTION__, Status));
+ DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;
+ } else {
+ //
+ // Get the current DT/ACPI preference from the DtAcpiPref variable.
+ //
+ BufferSize = sizeof (DtAcpiPref);
+ Status = gRT->GetVariable(DT_ACPI_VARIABLE_NAME, &gDtPlatformFormSetGuid,
+ NULL, &BufferSize, &DtAcpiPref);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "%a: no DT/ACPI preference found, defaulting to %a\n",
+ __FUNCTION__, PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"));
+ DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT
+ : DT_ACPI_SELECT_ACPI;
+ }
+ }
+
+ if (!EFI_ERROR (Status) &&
+ DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI &&
+ DtAcpiPref.Pref != DT_ACPI_SELECT_DT) {
+ DEBUG ((DEBUG_WARN, "%a: invalid value for %s, defaulting to %a\n",
+ __FUNCTION__, DT_ACPI_VARIABLE_NAME,
+ PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"));
+ DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT
+ : DT_ACPI_SELECT_ACPI;
+ Status = EFI_INVALID_PARAMETER; // trigger setvar below
+ }
+
+ //
+ // Write the newly selected default value back to the variable store.
+ //
+ if (EFI_ERROR (Status)) {
+ Status = gRT->SetVariable(DT_ACPI_VARIABLE_NAME, &gDtPlatformFormSetGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ sizeof (DtAcpiPref), &DtAcpiPref);
+ if (EFI_ERROR (Status)) {
+ goto FreeDtb;
+ }
+ }
+
+ if (DtAcpiPref.Pref == DT_ACPI_SELECT_ACPI) {
+ //
+ // ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a
+ // NULL protocol to unlock dispatch of ACPI related drivers.
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle,
+ &gEdkiiPlatformHasAcpiGuid, NULL, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",
+ __FUNCTION__));
+ goto FreeDtb;
+ }
+ } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {
+ //
+ // DT was selected: copy the blob into newly allocated memory and install
+ // a reference to it as the FDT configuration table.
+ //
+ Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n",
+ __FUNCTION__));
+ goto FreeDtb;
+ }
+ } else {
+ ASSERT (FALSE);
+ }
+
+ //
+ // No point in installing the HII pages if ACPI is the only description
+ // we have
+ //
+ if (Dtb == NULL) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Note that we don't uninstall the gEdkiiPlatformHasAcpiGuid protocol nor
+ // the FDT configuration table if the following call fails. While that will
+ // cause loading of this driver to fail, proceeding with ACPI and DT both
+ // disabled will guarantee a failed boot, and so it is better to leave them
+ // installed in that case.
+ //
+ return InstallHiiPages ();
+
+FreeDtb:
+ if (Dtb != NULL) {
+ FreePool (Dtb);
+ }
+
+ return Status;
+}
diff --git a/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.h b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.h
new file mode 100644
index 000000000..89e631e6c
--- /dev/null
+++ b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.h
@@ -0,0 +1,25 @@
+/** @file
+*
+* Copyright (c) 2017, Linaro Limited. All rights reserved.
+*
+* SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+
+#ifndef __DT_PLATFORM_DXE_H__
+#define __DT_PLATFORM_DXE_H__
+
+#include <Guid/HiiPlatformSetupFormset.h>
+#include <Guid/DtPlatformFormSet.h>
+
+#define DT_ACPI_SELECT_DT 0x0
+#define DT_ACPI_SELECT_ACPI 0x1
+
+#define DT_ACPI_VARIABLE_NAME L"DtAcpiPref"
+
+typedef struct {
+ UINT8 Pref;
+ UINT8 Reserved[3];
+} DT_ACPI_VARSTORE_DATA;
+
+#endif
diff --git a/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf
new file mode 100644
index 000000000..450ea29b4
--- /dev/null
+++ b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.inf
@@ -0,0 +1,54 @@
+## @file
+#
+# Copyright (c) 2017, Linaro, Ltd. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010019
+ BASE_NAME = DtPlatformDxe
+ FILE_GUID = FC097B3C-2EBD-4A75-A3DA-121DCAB365CC
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = DtPlatformDxeEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ DtPlatformDxe.c
+ DtPlatformHii.vfr
+ DtPlatformHii.uni
+
+[Packages]
+ EmbeddedPkg/EmbeddedPkg.dec
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ DtPlatformDtbLoaderLib
+ HiiLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+ UefiRuntimeServicesTableLib
+
+[Guids]
+ gDtPlatformFormSetGuid
+ gDtPlatformDefaultDtbFileGuid
+ gEdkiiPlatformHasAcpiGuid
+ gFdtTableGuid
+
+[Pcd]
+ gEmbeddedTokenSpaceGuid.PcdDefaultDtPref
+
+[Depex]
+ gEfiVariableArchProtocolGuid AND
+ gEfiVariableWriteArchProtocolGuid
diff --git a/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.uni b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.uni
new file mode 100644
index 000000000..5f24061a7
--- /dev/null
+++ b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.uni
@@ -0,0 +1,21 @@
+/** @file
+*
+* Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+*
+* SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+
+#langdef en-US "English"
+
+#string STR_FORM_SET_TITLE #language en-US "O/S Hardware Description Selection"
+#string STR_FORM_SET_TITLE_HELP #language en-US "Press <Enter> to choose between ACPI and DT hardware descriptions."
+
+#string STR_MAIN_FORM_TITLE #language en-US "O/S Hardware Description Selection"
+#string STR_NULL_STRING #language en-US ""
+
+#string STR_DT_ACPI_SELECT_PROMPT #language en-US "O/S Hardware Description"
+#string STR_DT_ACPI_SELECT_HELP #language en-US "Select the hardware description that will be exposed to the O/S."
+
+#string STR_DT_ACPI_SELECT_DT #language en-US "Device Tree"
+#string STR_DT_ACPI_SELECT_ACPI #language en-US "ACPI"
diff --git a/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.vfr b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.vfr
new file mode 100644
index 000000000..de8bb9681
--- /dev/null
+++ b/roms/edk2/EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformHii.vfr
@@ -0,0 +1,38 @@
+/** @file
+*
+* Copyright (c) 2017, Linaro, Ltd. All rights reserved.
+*
+* SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+
+#include <Uefi/UefiMultiPhase.h>
+#include "DtPlatformDxe.h"
+
+formset
+ guid = DT_PLATFORM_FORMSET_GUID,
+ title = STRING_TOKEN(STR_FORM_SET_TITLE),
+ help = STRING_TOKEN(STR_FORM_SET_TITLE_HELP),
+ classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,
+
+ efivarstore DT_ACPI_VARSTORE_DATA,
+ attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, // EFI variable attributes
+ name = DtAcpiPref,
+ guid = DT_PLATFORM_FORMSET_GUID;
+
+ form formid = 0x1000,
+ title = STRING_TOKEN(STR_MAIN_FORM_TITLE);
+
+ oneof varid = DtAcpiPref.Pref,
+ prompt = STRING_TOKEN(STR_DT_ACPI_SELECT_PROMPT),
+ help = STRING_TOKEN(STR_DT_ACPI_SELECT_HELP),
+ flags = NUMERIC_SIZE_1 | INTERACTIVE | RESET_REQUIRED,
+ option text = STRING_TOKEN(STR_DT_ACPI_SELECT_DT), value = DT_ACPI_SELECT_DT, flags = DEFAULT;
+ option text = STRING_TOKEN(STR_DT_ACPI_SELECT_ACPI), value = DT_ACPI_SELECT_ACPI, flags = 0;
+ endoneof;
+
+ subtitle text = STRING_TOKEN(STR_NULL_STRING);
+
+ endform;
+
+endformset;