Put this in it's own file. Maybe at some point there will be other aarch64 laptops from other SoC vendors which need their own specific dt patching.
Signed-off-by: Rob Clark robdclark@gmail.com --- .../Application/ConfigTableLoader/DtbLoader.c | 2 + .../ConfigTableLoader/DtbLoader.inf | 1 + .../Application/ConfigTableLoader/Qcom.c | 94 +++++++++++++++++++ .../Application/ConfigTableLoader/Qcom.h | 30 ++++++ 4 files changed, 127 insertions(+) create mode 100644 EmbeddedPkg/Application/ConfigTableLoader/Qcom.c create mode 100644 EmbeddedPkg/Application/ConfigTableLoader/Qcom.h
diff --git a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c index 2d32cc5b64..adda525847 100644 --- a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c +++ b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.c @@ -25,6 +25,7 @@ #include <Guid/FileInfo.h>
#include "Common.h" +#include "Qcom.h"
STATIC struct { UINT32 Crc32; @@ -490,6 +491,7 @@ LoadAndRegisterDtb (VOID) EFI_EVENT ExitBootServicesEvent;
ResizeBlob (&Blob); + QcomDetectPanel (Blob); RegisterDtBlob (Blob);
Status = gBS->CreateEvent ( diff --git a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf index 1f73594d60..bb91739950 100644 --- a/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf +++ b/EmbeddedPkg/Application/ConfigTableLoader/DtbLoader.inf @@ -29,6 +29,7 @@ [Sources.common] Common.c DtbLoader.c + Qcom.c
[LibraryClasses] BaseLib diff --git a/EmbeddedPkg/Application/ConfigTableLoader/Qcom.c b/EmbeddedPkg/Application/ConfigTableLoader/Qcom.c new file mode 100644 index 0000000000..ad33b738ed --- /dev/null +++ b/EmbeddedPkg/Application/ConfigTableLoader/Qcom.c @@ -0,0 +1,94 @@ +/** @file + + Copyright (c) 2019, Linaro. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <libfdt.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiLib.h> +#include <Library/UefiBootServicesTableLib.h> + +#include "Common.h" + +/* + * We (at least currently) don't care about most of the fields, just + * panel_id: + */ +typedef struct { + UINT32 VersionInfo; + UINT32 pad0[9]; + UINT32 PanelId; + UINT32 pad1[17]; +} MdpDispInfo; + +#define MDP_DISP_INFO_VERSION_MAGIC 0xaa + + +/** + Detect (if present) the qcom specific UEFIDisplayInfo variable, and + patch /chosen/panel-id accordingly. + + @param[in] Blob The fdt blob to patch if panel id is detected + + @retval EFI_SUCCESS The panel was detected and dt patched successfully. + @retval other Error. + +**/ +EFI_STATUS +EFIAPI +QcomDetectPanel ( + IN VOID *Blob + ) +{ + EFI_STATUS Status; + MdpDispInfo *DispInfo; + INT32 ChosenNode; + UINT32 FdtPanelId; + INT32 Err; + + Status = GetVariable3 ( + L"UEFIDisplayInfo", + &gEfiGraphicsOutputProtocolGuid, + (VOID **) &DispInfo, + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + Print (L"%a:%d: Status = %x\n", __func__, __LINE__, Status); + return Status; + } + + Dbg (L"Got VersionInfo: 0x%08x\n", DispInfo->VersionInfo); + + if ((DispInfo->VersionInfo >> 16) != MDP_DISP_INFO_VERSION_MAGIC) { + Print (L"Bad VersionInfo magic: 0x%08x\n", DispInfo->VersionInfo); + goto Cleanup; + } + + Dbg (L"Got PanelId: 0x%x\n", DispInfo->PanelId); + + /* We found our panel-id, now patch up the fdt: */ + ChosenNode = fdt_subnode_offset (Blob, 0, "chosen"); + if (ChosenNode < 0) { + Print (L"ChosenNode not found: %s\n", fdt_strerror (ChosenNode)); + return EFI_NOT_FOUND; + } + + FdtPanelId = cpu_to_fdt32 (DispInfo->PanelId); + Err = fdt_setprop (Blob, ChosenNode, "panel-id", &FdtPanelId, sizeof(FdtPanelId)); + if (Err) { + Print (L"Could not add panel-id: %a\n", fdt_strerror (Err)); + return EFI_OUT_OF_RESOURCES; + } + + Dbg (L"fdt patched successfully\n"); + + Cleanup: + FreePool (DispInfo); + return Status; +} diff --git a/EmbeddedPkg/Application/ConfigTableLoader/Qcom.h b/EmbeddedPkg/Application/ConfigTableLoader/Qcom.h new file mode 100644 index 0000000000..8a92033cbe --- /dev/null +++ b/EmbeddedPkg/Application/ConfigTableLoader/Qcom.h @@ -0,0 +1,30 @@ +/** @file + + Copyright (c) 2019, Linaro. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef QCOM_H_ +#define QCOM_H_ + +#include <Uefi.h> + +/** + Detect (if present) the qcom specific UEFIDisplayInfo variable, and + patch /chosen/panel-id accordingly. + + @param[in] Blob The fdt blob to patch if panel id is detected + + @retval EFI_SUCCESS The panel was detected and dt patched successfully. + @retval other Error. + +**/ +EFI_STATUS +EFIAPI +QcomDetectPanel ( + IN VOID *Blob + ); + +#endif /* QCOM_H_ */