From patchwork Wed Apr 6 16:15:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65207 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1147462lbc; Wed, 6 Apr 2016 09:16:34 -0700 (PDT) X-Received: by 10.98.32.136 with SMTP id m8mr39719330pfj.11.1459959390674; Wed, 06 Apr 2016 09:16:30 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id d2si5474195pfb.112.2016.04.06.09.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Apr 2016 09:16:30 -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 3AD071A1FEA; Wed, 6 Apr 2016 09:16:00 -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 B2AA51A1FBF for ; Wed, 6 Apr 2016 09:15:58 -0700 (PDT) Received: by mail-wm0-x22a.google.com with SMTP id u206so52749856wme.1 for ; Wed, 06 Apr 2016 09:15:58 -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=UsGojkTvWVNq0LWVDoQOtKXfS0CDTHLIF3HPwFIY5hc=; b=iOqsUt/+SFbC8Qx2B+vNKEHzSdahK1XgiN2RI0RkAW+08VUHuuIewnfvPlRzsuMtcF cSX8RShHVB41kskD/ge+jknpCCb8IccMbEK6oFzfPfLYohIg5Ziye/kQS0FBxAq9F8XR SZ3Y/fNFYiJncyR7k9r3EEo9ekLu3kMbxZNI0= 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=UsGojkTvWVNq0LWVDoQOtKXfS0CDTHLIF3HPwFIY5hc=; b=bVyR2KXNnTfdHPd4p6kOUYCMD1d1Lt5/EAmFMmi0wIK3B/IDnoQ9X7TifotBxKO7WD TKNyaKyiGf63WtX6DK1hY0+cwpIZFnOMJZIP6usXTOer8TjCO6QTeTHtDw/oX7eUDlP0 86r41cb+5lgncwCJVswJhJ81iagPCx97XEZFX05A1vT/pDI1IR4cHLJ4MW9vGdofwB9v ECRA1XdpQoFTmukw2ocX6d4Q5lR4p8xkMJocaEQ3UKKDyC4HX22FaPmFxRB2Tmtf1vd5 tIk07zYsJHFS4D8GyODfjHfv65XzX0iB4B++gI/GTnmBQFHmerKdUFMYwjyVMp7OtKmB brLA== X-Gm-Message-State: AD7BkJIlUt3FbJJ2OFiV2uSkFfrLIIVQqEnT21hAx07KsBSxGPnw1P0iYEoRHgHMxzQAK7iI X-Received: by 10.28.150.195 with SMTP id y186mr24441375wmd.43.1459959357482; Wed, 06 Apr 2016 09:15:57 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id om6sm3961219wjc.40.2016.04.06.09.15.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Apr 2016 09:15:56 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Wed, 6 Apr 2016 18:15:16 +0200 Message-Id: <1459959319-19293-19-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 18/21] 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 | 48 ++++++++++++++ 2 files changed, 117 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..9af50d641234 --- /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 + +EFI_STATUS +EFIAPI +ArmVirtRtcFdtClientLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + CONST VOID *Reg; + UINTN RegSize; + UINT64 RegBase; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, (VOID **)&FdtClient); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", &Reg, &RegSize); + if (EFI_ERROR (Status)) { + return Status; + } + + ASSERT (RegSize == 16); + + RegBase = fdt64_to_cpu (((UINT64 *)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", 8); + 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..93a78d115d2c --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtRtcFdtClientLib/ArmVirtRtcFdtClientLib.inf @@ -0,0 +1,48 @@ +#/** @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 = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmVirtRtcFdtClientLib + CONSTRUCTOR = ArmVirtRtcFdtClientLibConstructor + +[Sources] + ArmVirtRtcFdtClientLib.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + DebugLib + BaseLib + FdtLib + PcdLib + +[Protocols] + gFdtClientProtocolGuid + +[Pcd] + gArmPlatformTokenSpaceGuid.PcdPL031RtcBase + +[Depex] + gFdtClientProtocolGuid