From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=gmlp4wWm; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.167.65, mailfrom: mw@semihalf.com) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by groups.io with SMTP; Fri, 12 Apr 2019 03:20:04 -0700 Received: by mail-lf1-f65.google.com with SMTP id r25so7050591lfn.13 for ; Fri, 12 Apr 2019 03:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IXYsCKBu8t4lI67Z8WKUYdPNyQTz8gZXfQXe+N0ozUc=; b=gmlp4wWmwp4+aj8KrI9XGoBPd1/kBAr3CiMTIRVQYGlz6PJsHzUzZteWc6ddnjnvH6 jM/GCd9XWitlsKIK2VehOMVtNFCyzsv0JMpXFZK9scyHRgQCepF0yQlxr36dW2m4F4J5 fb3q2oeClHLjTyXA8wOE9YCBHeJ/o3jdv++kii9Kbk3EZn3vsC6YtdjrMRVomHm6Gwix CpxxNQho/oGN2QO4IoW5/0HIuK7V8LpiGry3wiKvnJLKgGCkClf53jJR+RgR8vgEhyT0 kVwJz7tAOdAesNpyLcem8sfnHGY9j9UzQQTchv9GtQ69xYujTYeNsxszyf5sxnIxCStz oTNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IXYsCKBu8t4lI67Z8WKUYdPNyQTz8gZXfQXe+N0ozUc=; b=FarSXzeU5hf8QWj6IbqyTjmgBEQfkcvy6Xjz8HnfGIFX73zd/lpDwMu+dlcILFDRP4 xwtfqE/AAMb2phXxmE2qugAA/K5Iov4qx5aEOF507fwkcc0VsXgJx+InB7/k7LcmgH4Y Vln4+O8z2ZsgL6LK+Hn8ZUvqyqnoC4MsuSGn++zlWRSUJSa+n6EQa+lSWZMvZl/2slfA NQfLi8APTEk+/bDWs3vyQt6ODFx+1D5suKjidS7JiyFw+R3r4C4CzfCAFkU/+M5i7LXL HVMUrvJm5ec9sTdLjVQ573hxqo6psfV+OcVnlzKdV8BMp2hQihHgdNW1kzgLB9uEy17w xSWg== X-Gm-Message-State: APjAAAW8UdvpO5moOB/WEIlHAfmVCI0OnczrRPaJm07fnFUyso+Yyi9H 74Bq79ad6o14HJYnhdfxamVT1WIzRqdpRlLt X-Google-Smtp-Source: APXvYqyykoI4zUGyTNlUFQTo5A4PMbKa/x4bTBa0CnfPBUrDKvlqHq/F7JF1rinQylzMTbsYmphdfQ== X-Received: by 2002:a05:6512:c8:: with SMTP id c8mr11898283lfp.138.1555064402130; Fri, 12 Apr 2019 03:20:02 -0700 (PDT) Return-Path: Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id o3sm8025240lfd.53.2019.04.12.03.20.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Apr 2019 03:20:01 -0700 (PDT) From: "Marcin Wojtas" To: devel@edk2.groups.io Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com, kostap@marvell.com, jeremy.linton@arm.com, Jici.Gao@arm.com Subject: [edk2-platforms: PATCH 3/6] Marvell/Armada7k8k: Implement custom DtLoaderLib Date: Fri, 12 Apr 2019 12:19:33 +0200 Message-Id: <1555064376-22302-4-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555064376-22302-1-git-send-email-mw@semihalf.com> References: <1555064376-22302-1-git-send-email-mw@semihalf.com> In order to provide special handling for DT environment, implement custom version of DtLoaderLib, which registers ExitBootServices event upon generic 'DtAcpiPref' variable. The routine is responsible for disabling the PMU workaround, that is valid only for UEFI and OS + APCI. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc | 2 +- Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.inf | 43 +++++++ Silicon/Marvell/Include/IndustryStandard/MvSmc.h | 2 + Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.c | 130 ++++++++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.inf create mode 100644 Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.c diff --git a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc index 8291582..5ed742f 100644 --- a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc +++ b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc @@ -200,7 +200,7 @@ PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf NonDiscoverableDeviceRegistrationLib|MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverableDeviceRegistrationLib.inf - DtPlatformDtbLoaderLib|EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf + DtPlatformDtbLoaderLib|Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.inf [LibraryClasses.common.UEFI_APPLICATION] PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf diff --git a/Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.inf b/Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.inf new file mode 100644 index 0000000..ec3f3a5 --- /dev/null +++ b/Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.inf @@ -0,0 +1,43 @@ +/** @file +* +* Copyright (c) 2017, Linaro, Ltd. All rights reserved. +* Copyright (c) 2018, Marvell International Ltd. and its affiliates +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +[Defines] + INF_VERSION = 0x0001001A + BASE_NAME = DxeDtPlatformDtbLoaderLibDefault + FILE_GUID = dde55569-ad3f-421d-b94b-3be66bb916ce + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = DtPlatformDtbLoaderLib|DXE_DRIVER + +[Sources] + DxeDtPlatformDtbLoaderLib.c + +[Packages] + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + Silicon/Marvell/Marvell.dec + +[LibraryClasses] + ArmSmcLib + BaseLib + DebugLib + DxeServicesLib + MemoryAllocationLib + UefiRuntimeServicesTableLib + +[Guids] + gDtPlatformDefaultDtbFileGuid + gDtPlatformFormSetGuid diff --git a/Silicon/Marvell/Include/IndustryStandard/MvSmc.h b/Silicon/Marvell/Include/IndustryStandard/MvSmc.h index 0c90f11..e5c89d9 100644 --- a/Silicon/Marvell/Include/IndustryStandard/MvSmc.h +++ b/Silicon/Marvell/Include/IndustryStandard/MvSmc.h @@ -20,5 +20,7 @@ #define MV_SMC_ID_COMPHY_POWER_OFF 0x82000002 #define MV_SMC_ID_COMPHY_PLL_LOCK 0x82000003 #define MV_SMC_ID_DRAM_SIZE 0x82000010 +#define MV_SMC_ID_PMU_IRQ_ENABLE 0x82000012 +#define MV_SMC_ID_PMU_IRQ_DISABLE 0x82000013 #endif //__MV_SMC_H__ diff --git a/Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.c b/Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.c new file mode 100644 index 0000000..b189f47 --- /dev/null +++ b/Silicon/Marvell/Armada7k8k/Library/DxeDtPlatformDtbLoaderLib/DxeDtPlatformDtbLoaderLib.c @@ -0,0 +1,130 @@ +/** @file +* +* Copyright (c) 2017, Linaro, Ltd. All rights reserved. +* Copyright (c) 2018, Marvell International Ltd. and its affiliates +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +STATIC EFI_EVENT mArmada7k8kExitBootServicesEvent; + +#define DT_ACPI_SELECT_DT 0x0 +#define DT_ACPI_SELECT_ACPI 0x1 + +typedef struct { + UINT8 Pref; + UINT8 Reserved[3]; +} DT_ACPI_VARSTORE_DATA; + +/** + Disable extra EL3 handling of the PMU interrupts for DT world. + + @param[in] Event Event structure + @param[in] Context Notification context + +**/ +STATIC +VOID +Armada7k8kExitBootEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + ARM_SMC_ARGS SmcRegs = {0}; + + SmcRegs.Arg0 = MV_SMC_ID_PMU_IRQ_DISABLE; + ArmCallSmc (&SmcRegs); + + return; +} + +/** + Return a pool allocated copy of the DTB image that is appropriate for + booting the current platform via DT. + + @param[out] Dtb Pointer to the DTB copy + @param[out] DtbSize Size of the DTB copy + + @retval EFI_SUCCESS Operation completed successfully + @retval EFI_NOT_FOUND No suitable DTB image could be located + @retval EFI_OUT_OF_RESOURCES No pool memory available + +**/ +EFI_STATUS +EFIAPI +DtPlatformLoadDtb ( + OUT VOID **Dtb, + OUT UINTN *DtbSize + ) +{ + DT_ACPI_VARSTORE_DATA DtAcpiPref; + ARM_SMC_ARGS SmcRegs = {0}; + EFI_STATUS Status; + VOID *OrigDtb; + VOID *CopyDtb; + UINTN OrigDtbSize; + UINTN BufferSize; + + Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid, + EFI_SECTION_RAW, + 0, + &OrigDtb, + &OrigDtbSize); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + CopyDtb = AllocateCopyPool (OrigDtbSize, OrigDtb); + if (CopyDtb == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *Dtb = CopyDtb; + *DtbSize = OrigDtbSize; + + /* Enable EL3 handler for regardless HW description */ + SmcRegs.Arg0 = MV_SMC_ID_PMU_IRQ_ENABLE; + ArmCallSmc (&SmcRegs); + + /* + * Get the current DT/ACPI preference from the DtAcpiPref variable. + * Register ExitBootServices event only in case the DT will be used. + */ + BufferSize = sizeof (DtAcpiPref); + Status = gRT->GetVariable (L"DtAcpiPref", + &gDtPlatformFormSetGuid, + NULL, + &BufferSize, + &DtAcpiPref); + if (EFI_ERROR (Status) || DtAcpiPref.Pref == DT_ACPI_SELECT_DT) { + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_NOTIFY, + Armada7k8kExitBootEvent, + NULL, + &mArmada7k8kExitBootServicesEvent); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to register EBS event\n", __FUNCTION__)); + } + } + + return EFI_SUCCESS; +} -- 2.7.4