diff mbox

[edk2,18/21] ArmVirtPkg: implement ArmVirtRtcFdtClientLib

Message ID 1459959319-19293-19-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel April 6, 2016, 4:15 p.m. UTC
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 <ard.biesheuvel@linaro.org>

---
 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 mbox

Patch

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.<BR>
+
+  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 <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <libfdt.h>
+
+#include <Protocol/FdtClient.h>
+
+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