From patchwork Wed Apr 13 08:02:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65682 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2362641qge; Wed, 13 Apr 2016 01:02:30 -0700 (PDT) X-Received: by 10.66.62.232 with SMTP id b8mr11002635pas.104.1460534550471; Wed, 13 Apr 2016 01:02:30 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id 18si14863659pfs.117.2016.04.13.01.02.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Apr 2016 01:02:30 -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 13C2B1A2052; Wed, 13 Apr 2016 01:02:30 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x234.google.com (mail-wm0-x234.google.com [IPv6:2a00:1450:400c:c09::234]) (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 53BF51A2052 for ; Wed, 13 Apr 2016 01:02:28 -0700 (PDT) Received: by mail-wm0-x234.google.com with SMTP id u206so61932517wme.1 for ; Wed, 13 Apr 2016 01:02:28 -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=ji4kSwWvefH96WhdOXSSSfOFsoudVaphtQWphHpoz70=; b=ACa4atLUr2sIyeqyjQUOVK7ETEBAXTWixxFGx1hOM+WjzGhG6vgCpusysD3+v5bedP zWvfyBMVNTP0lUjQ6FO08/t4azuMzIck8WNhXGID9uv21l9PP/k0RycblgXzFJ3Jo9YF P8IMJ/517lgkrcsuPdjbocQ4Mx2Rucxlid+X8= 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=ji4kSwWvefH96WhdOXSSSfOFsoudVaphtQWphHpoz70=; b=b8x6OlQNfZehbTB9W778ojZ1SCTfunzzEFyDlanWFDviLgpN7lSwYnBc/eYgSwzDAs 5PEaEZHvp9oCcvD5TXON+F1pJjBhZxyKX6C6ysapPg7pwkuijU+EMvRoWzBNfpKxTXUc +ZSqAYZeJaFtvJUtrKLafy9ENuCkH7qkQ0UZwZy4gGz77uJKBypWC8SzvcLRPvCa0oXE wCRJZIMogR1X97wDEgA0WB64ew0bDPr7lzeJ2b4DFCJn8qPD1D5R8B0DDjGOYi9ZotpC VhAxW+9wNa8ZlsZ6ESOe25e1hhRBNG1zywfU6ph2tQiRJ38J4qOMTUK2YwY691J6ivMU WhLg== X-Gm-Message-State: AOPr4FWB85Sus5aGl0hxPTSZZEcV6mV37p4aDryi1B0nt88V8G6SmvY6FjHpWcG9WD38DFc0 X-Received: by 10.194.174.197 with SMTP id bu5mr8734142wjc.23.1460534546821; Wed, 13 Apr 2016 01:02:26 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id i206sm26686549wmf.1.2016.04.13.01.02.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 01:02:26 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Wed, 13 Apr 2016 10:02:11 +0200 Message-Id: <1460534539-2169-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460534539-2169-1-git-send-email-ard.biesheuvel@linaro.org> References: <1460534539-2169-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v3 1/9] ArmVirtPkg: implement ArmVirtPL031FdtClientLib 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 ArmVirtPL031FdtClientLib 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 PL031 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/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf | 47 ++++++++++++ ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c | 80 ++++++++++++++++++++ 2 files changed, 127 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/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf b/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf new file mode 100644 index 000000000000..65ba8f356d1d --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf @@ -0,0 +1,47 @@ +#/** @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 = ArmVirtPL031FdtClientLib + FILE_GUID = 13173319-B270-4669-8592-3BB2B31E9E29 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmVirtPL031FdtClientLib|DXE_DRIVER DXE_RUNTIME_DRIVER + CONSTRUCTOR = ArmVirtPL031FdtClientLibConstructor + +[Sources] + ArmVirtPL031FdtClientLib.c + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Pcd] + gArmPlatformTokenSpaceGuid.PcdPL031RtcBase + +[Depex] + gFdtClientProtocolGuid diff --git a/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c b/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c new file mode 100644 index 000000000000..02ab404d5763 --- /dev/null +++ b/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c @@ -0,0 +1,80 @@ +/** @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 +ArmVirtPL031FdtClientLibConstructor ( + 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)) { + DEBUG ((EFI_D_WARN, "%a: No 'arm,pl031' compatible DT node found\n", + __FUNCTION__)); + return EFI_SUCCESS; + } + + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", + (CONST VOID **)&Reg, &RegSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_WARN, + "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n", + __FUNCTION__)); + return EFI_SUCCESS; + } + + 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)); + + // + // UEFI takes ownership of the RTC hardware, and exposes its functionality + // through the UEFI Runtime Services GetTime, SetTime, etc. This means we + // need to disable it in the device tree to prevent the OS from attaching + // its device driver as well. + // + 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; +}