From patchwork Wed Apr 6 16:15:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65199 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1147140lbc; Wed, 6 Apr 2016 09:16:02 -0700 (PDT) X-Received: by 10.98.18.71 with SMTP id a68mr39844844pfj.41.1459959359468; Wed, 06 Apr 2016 09:15:59 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id s6si5460835pfi.138.2016.04.06.09.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Apr 2016 09:15:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; 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 2001:19d0:306:5::1 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 4423E1A1FD1; Wed, 6 Apr 2016 09:15:47 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com [IPv6:2a00:1450:400c:c09::22b]) (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 975BE1A1FB2 for ; Wed, 6 Apr 2016 09:15:46 -0700 (PDT) Received: by mail-wm0-x22b.google.com with SMTP id f198so80670478wme.0 for ; Wed, 06 Apr 2016 09:15:46 -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=gDZB4kvilOvfQntFu5DB9Hnk1/aG1lcKVWC7YwPjpd4=; b=E7RRqneYm0x1OOi+qkG/JtUNJKgdNVJr/yx49WIIeJAm6WflldQ6vCBLvIOzHJsCbD neocH8Go5dQ/SvVkNmMSnmGBgzMYjzanu6c613HuQiDyIu9e4IHmkQPvtcdIVeeQYVjU GRqlypmLqtGPw8d9pCcCCdotiscPhCL5cqFEE= 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=gDZB4kvilOvfQntFu5DB9Hnk1/aG1lcKVWC7YwPjpd4=; b=YLh3BDM9MdydIa0bZI3u464PEzUTwC47IpssAJHB6wpqEtAO5CaI7/fH3r3Gj1IxLQ 25MnbzWulvXZUoCR+2lizhCGVYLuPSF6eG+zVIrUIUpui9iCoSv5i7+XvvPKalH+eJYn s/wKn8jr/LUbi5+8cNlZ0DqBczTI1M+VEItxRT67bNy9bw3wQj9GqKtrQj2m6qB+NQRq ndvbDc3qmXl7GPkaSaDqRitm7HVkOUYFF5ll0ZQhddw1TShKt18jtkohhRjUdHPToVmO 3xXVGlUUnKVtKZ0vn70u76rWIXX4X3qaLZmR1RkKOLsujBEHKOo3M/0KX6YXidypRdNs jTuQ== X-Gm-Message-State: AD7BkJKuY6RK5Mcwt8LCDQGNnHyfPicQOfOmFYRPSd/pStJ0IrgsuxtmpbWV5gwbPz6/eWWq X-Received: by 10.194.71.171 with SMTP id w11mr11206296wju.36.1459959345319; Wed, 06 Apr 2016 09:15:45 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id om6sm3961219wjc.40.2016.04.06.09.15.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Apr 2016 09:15:44 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Wed, 6 Apr 2016 18:15:08 +0200 Message-Id: <1459959319-19293-11-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459959319-19293-1-git-send-email-ard.biesheuvel@linaro.org> References: <1459959319-19293-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 10/21] 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 | 90 ++++++++++++++++++++ ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf | 47 ++++++++++ 2 files changed, 137 insertions(+) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c new file mode 100644 index 000000000000..0001f8fbcd82 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c @@ -0,0 +1,90 @@ +/** @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; + +EFI_STATUS +EFIAPI +ArmVirtTimerFdtClientLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST INTERRUPT_PROPERTY *InterruptProp; + UINTN PropSize; + INT32 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, (VOID **)&FdtClient); + if (EFI_ERROR (Status)) { + return 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 = fdt32_to_cpu (InterruptProp[0].Number) + + (InterruptProp[0].Type ? 16 : 0); + IntrNum = fdt32_to_cpu (InterruptProp[1].Number) + + (InterruptProp[1].Type ? 16 : 0); + VirtIntrNum = fdt32_to_cpu (InterruptProp[2].Number) + + (InterruptProp[2].Type ? 16 : 0); + HypIntrNum = PropSize < 48 ? 0 : fdt32_to_cpu (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..b694c5c817a5 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf @@ -0,0 +1,47 @@ +#/** @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 = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmVirtTimerFdtClientLib + CONSTRUCTOR = ArmVirtTimerFdtClientLibConstructor + +[Sources] + ArmVirtTimerFdtClientLib.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + DebugLib + BaseLib + FdtLib + PcdLib + +[Protocols] + gFdtClientProtocolGuid + +[Pcd] + gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum + gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum