From patchwork Fri Apr 8 09:44:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65372 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp569208lbl; Fri, 8 Apr 2016 02:45:42 -0700 (PDT) X-Received: by 10.98.13.130 with SMTP id 2mr11396143pfn.97.1460108739065; Fri, 08 Apr 2016 02:45:39 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id hj1si21883pac.235.2016.04.08.02.45.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 02:45:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4A7531A1FC0; Fri, 8 Apr 2016 02:45:33 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.google.com [IPv6:2a00:1450:400c:c09::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 143701A1FC0 for ; Fri, 8 Apr 2016 02:45:32 -0700 (PDT) Received: by mail-wm0-x22a.google.com with SMTP id u206so15474019wme.1 for ; Fri, 08 Apr 2016 02:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oh+t4Cjwtkv5ytkXV/SBa71jZp+lccwc1THMgDsZpPo=; b=MhN2A4vh+bAk8anBhqmEfYIsgFubtTXNrlUEbc9hhPX0UNbPdL24IMjPVa+8ZwMexl Ruk0FDS2T4cqYtgXOYxUNXmhvjeJN+/Wwe/jQUboCDH4ag+2Ld7AOwJMoz47WjQJYRhq JdIeW85DxrAgbUkS9a3L7j4KnxvcjBYXy5qoU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oh+t4Cjwtkv5ytkXV/SBa71jZp+lccwc1THMgDsZpPo=; b=KxwvwbXNyEPPs8mn8FqSdo+VKDvrc9GhK9migZOC1alf4rwwUEWr8bBbpY7nMhCZXt 8jRkbkCrBhEqD/N1SVR/OkdkV7Il8Pd7Q0BorcHTWSjAjuRxQeOkEfIrDWu+Br/3HISU RQ2ZPRglL16BZ+5bODIHy9FwKEvS/u8TJQIhSO32E1oe8EESBEIglgnfIVADWpwFhfxB dkGt9T6XoZFwuZzbxzsjyGYURc7xQK6StAxWD8q7c8+h/SPGp6SiEnbUZ+BB+cdTFAe/ Yba4xeOgND+RP1gx3vPPWEorXQmNhsO6Y5CmrhlLAqW4tfY+ixGcuJd1z5+zBXuwVdHq iVCQ== X-Gm-Message-State: AD7BkJI73VJxPxAmJHDqbHqZ9vGYZoCAcjBtLChnaQFDpKBwuZ93QH2j+4iRTMx75ZMoYo1F X-Received: by 10.28.63.73 with SMTP id m70mr2730518wma.55.1460108730726; Fri, 08 Apr 2016 02:45:30 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id s10sm9710681wjp.3.2016.04.08.02.45.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Apr 2016 02:45:29 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Fri, 8 Apr 2016 11:44:55 +0200 Message-Id: <1460108711-12122-9-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460108711-12122-1-git-send-email-ard.biesheuvel@linaro.org> References: <1460108711-12122-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 08/24] ArmVirtPkg: implement ArmVirtTimerFdtClientLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" This implements a library ArmVirtTimerFdtClientLib which is intended to be incorporated into TimerDxe via NULL library class resolution. This allows us to make TimerDxe depend on the FDT client protocol, and discover the timer interrupts from the device tree directly rather than relying on VirtFdtDxe to set the dynamic PCDs. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c | 86 ++++++++++++++++++++ ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf | 45 ++++++++++ 2 files changed, 131 insertions(+) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c new file mode 100644 index 000000000000..08e24fd82be5 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c @@ -0,0 +1,86 @@ +/** @file + FDT client library for ARM's TimerDxe + + Copyright (c) 2016, Linaro Ltd. All rights reserved.
+ + 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 + +typedef struct { + UINT32 Type; + UINT32 Number; + UINT32 Flags; +} INTERRUPT_PROPERTY; + +RETURN_STATUS +EFIAPI +ArmVirtTimerFdtClientLibConstructor ( + VOID + ) +{ + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST INTERRUPT_PROPERTY *InterruptProp; + UINT32 PropSize; + INT32 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,armv7-timer", + "interrupts", (CONST VOID **)&InterruptProp, + &PropSize); + if (Status == EFI_NOT_FOUND) { + Status = FdtClient->FindCompatibleNodeProperty (FdtClient, + "arm,armv8-timer", "interrupts", + (CONST VOID **)&InterruptProp, + &PropSize); + } + + if (EFI_ERROR (Status)) { + return Status; + } + + // + // - interrupts : Interrupt list for secure, non-secure, virtual and + // hypervisor timers, in that order. + // + ASSERT (PropSize == 36 || PropSize == 48); + + SecIntrNum = SwapBytes32 (InterruptProp[0].Number) + + (InterruptProp[0].Type ? 16 : 0); + IntrNum = SwapBytes32 (InterruptProp[1].Number) + + (InterruptProp[1].Type ? 16 : 0); + VirtIntrNum = SwapBytes32 (InterruptProp[2].Number) + + (InterruptProp[2].Type ? 16 : 0); + HypIntrNum = PropSize < 48 ? 0 : SwapBytes32 (InterruptProp[3].Number) + + (InterruptProp[3].Type ? 16 : 0); + + DEBUG ((EFI_D_INFO, "Found Timer interrupts %d, %d, %d, %d\n", + SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum)); + + PcdSet32 (PcdArmArchTimerSecIntrNum, SecIntrNum); + PcdSet32 (PcdArmArchTimerIntrNum, IntrNum); + PcdSet32 (PcdArmArchTimerVirtIntrNum, VirtIntrNum); + PcdSet32 (PcdArmArchTimerHypIntrNum, HypIntrNum); + + return EFI_SUCCESS; +} + diff --git a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf new file mode 100644 index 000000000000..e54c401b305e --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf @@ -0,0 +1,45 @@ +#/** @file +# FDT client library for ARM's TimerDxe +# +# Copyright (c) 2016, Linaro Ltd. All rights reserved. +# +# 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 = 0x00010005 + BASE_NAME = ArmVirtTimerFdtClientLib + FILE_GUID = 77EA80CA-2EFB-4AB4-8567-230D968F6B37 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmVirtTimerFdtClientLib|DXE_DRIVER + CONSTRUCTOR = ArmVirtTimerFdtClientLibConstructor + +[Sources] + ArmVirtTimerFdtClientLib.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Pcd] + gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum