From patchwork Fri Apr 8 09:45:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65380 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp569422lbl; Fri, 8 Apr 2016 02:46:17 -0700 (PDT) X-Received: by 10.98.86.77 with SMTP id k74mr11304261pfb.28.1460108765667; Fri, 08 Apr 2016 02:46:05 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id tb4si13716pab.121.2016.04.08.02.46.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 02:46:05 -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 5BFCB1A1FDB; Fri, 8 Apr 2016 02:45:46 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) (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 841961A1FDB for ; Fri, 8 Apr 2016 02:45:44 -0700 (PDT) Received: by mail-wm0-x235.google.com with SMTP id n3so15534176wmn.0 for ; Fri, 08 Apr 2016 02:45:44 -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=gBqvNzmq7IlI6K5ofzObf+3B/X5iTILN2UQe5TULFGw=; b=dNAn/xGWGQJcjKsbs8QYT5FIROAkDziDOJTo1hch+i1tjeHd6SwMH35upnZoyfldQa gptbm3Kbwvy39hanygA85ir75yUZTw8CN6NGTi+zoq0jL3pEUBHZirp5znHKj6R9ATuw b75TG3qkmiF5jIuKqO6AyEE2NW+NMCpmTAWTM= 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=gBqvNzmq7IlI6K5ofzObf+3B/X5iTILN2UQe5TULFGw=; b=J5st7hVg3UxKdvERVG94JBk9anlX/Bf86UzSrNGVVA/9TwSTtc04x9ealpNH4Xprxn /a/O1roA1PSMdeO5dFs61Q4l2TE8ajJu4rXVtNwPzUEtk+ZGTLt/raw//jfpcJpf0ZYd GlSRvf+gvcy9U8s2pV9m2oygyDjnobZ+jUM9i+8aLn5OziH0kSq8rU+Q6ayGvHTGTyky xhHYGEsSkfbFzZKW4a8bdKGNX7SYMuvPuCrWwJEDgHbFf5IBeiZQ1kF5eGb0XPuIa34U ELdlmEIhZYWqS0WCT3fv64yltUB66s7n5VUf8NhgjnEEEJVDjAmNHpiAfOxV6n9pnOpM i9og== X-Gm-Message-State: AOPr4FWqHB3nikCz8zA3lIZyjsnwwk5jbtnOamezEuRAHoyajulAeoksnhMANFOWRLn6KI/L X-Received: by 10.194.235.39 with SMTP id uj7mr1854151wjc.78.1460108743215; Fri, 08 Apr 2016 02:45:43 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id s10sm9710681wjp.3.2016.04.08.02.45.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Apr 2016 02:45:42 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Fri, 8 Apr 2016 11:45:03 +0200 Message-Id: <1460108711-12122-17-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 16/24] ArmVirtPkg: implement ArmVirtRtcFdtClientLib 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 ArmVirtRtcFdtClientLib which is intended to be incorporated into RealTimeClockRuntimeDxe via NULL library class resolution. This allows us to make RealTimeClockRuntimeDxe depend on the FDT client protocol, and discover the RTC base address 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/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.c | 69 ++++++++++++++++++++ ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.inf | 46 +++++++++++++ 2 files changed, 115 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/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.c b/ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.c new file mode 100644 index 000000000000..4c0c4f7ba6b2 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.c @@ -0,0 +1,69 @@ +/** @file + FDT client library for ARM's PL031 RTC driver + + 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 + +RETURN_STATUS +EFIAPI +ArmVirtRtcFdtClientLibConstructor ( + VOID + ) +{ + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + CONST UINT64 *Reg; + UINT32 RegSize; + UINT64 RegBase; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", + (CONST VOID **)&Reg, &RegSize); + if (EFI_ERROR (Status)) { + return Status; + } + + ASSERT (RegSize == 16); + + RegBase = SwapBytes64 (Reg[0]); + ASSERT (RegBase < MAX_UINT32); + + PcdSet32 (PcdPL031RtcBase, (UINT32)RegBase); + + DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase)); + + Status = FdtClient->SetNodeProperty (FdtClient, Node, "status", + "disabled", sizeof ("disabled")); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n")); + } + + return EFI_SUCCESS; +} diff --git a/ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.inf b/ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.inf new file mode 100644 index 000000000000..d4f508498ee2 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.inf @@ -0,0 +1,46 @@ +#/** @file +# FDT client library for ARM's PL031 RTC driver +# +# 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 = ArmVirtRtcFdtClientLib + FILE_GUID = 13173319-B270-4669-8592-3BB2B31E9E29 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmVirtRtcFdtClientLib|DXE_DRIVER DXE_RUNTIME_DRIVER + CONSTRUCTOR = ArmVirtRtcFdtClientLibConstructor + +[Sources] + ArmVirtRtcFdtClientLib.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Pcd] + gArmPlatformTokenSpaceGuid.PcdPL031RtcBase + +[Depex] + gFdtClientProtocolGuid