]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg: implement ArmVirtPL031FdtClientLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 8 Apr 2016 09:45:03 +0000 (11:45 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 13 Apr 2016 14:55:24 +0000 (16:55 +0200)
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.

The NULL library class resolution approach to strictly order production and
consumption of dynamic PCDs is not generally safe in cases such as this one,
where the producer and the consumer of the PCD are both libraries. However,
since the PCD is produced in this library's constructor, and the consumer
library's constructor 'LibRtcInitialize' is not a 'true' constructor (it is
invoked explicitly by RealTimeClockRuntimeDxe), this case is guaranteed to
be safe after all.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c [new file with mode: 0644]
ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf [new file with mode: 0644]

diff --git a/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c b/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c
new file mode 100644 (file)
index 0000000..3c4e44c
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  FDT client library for ARM's PL031 RTC driver\r
+\r
+  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/FdtClient.h>\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+ArmVirtPL031FdtClientLibConstructor (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  FDT_CLIENT_PROTOCOL           *FdtClient;\r
+  INT32                         Node;\r
+  CONST UINT64                  *Reg;\r
+  UINT32                        RegSize;\r
+  UINT64                        RegBase;\r
+\r
+  Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
+                  (VOID **)&FdtClient);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_WARN, "%a: No 'arm,pl031' compatible DT node found\n",\r
+      __FUNCTION__));\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r
+                        (CONST VOID **)&Reg, &RegSize);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_WARN,\r
+      "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",\r
+      __FUNCTION__));\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  ASSERT (RegSize == 16);\r
+\r
+  RegBase = SwapBytes64 (Reg[0]);\r
+  ASSERT (RegBase < MAX_UINT32);\r
+\r
+  PcdSet32 (PcdPL031RtcBase, (UINT32)RegBase);\r
+\r
+  DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));\r
+\r
+  if (!FeaturePcdGet (PcdPureAcpiBoot)) {\r
+    //\r
+    // UEFI takes ownership of the RTC hardware, and exposes its functionality\r
+    // through the UEFI Runtime Services GetTime, SetTime, etc. This means we\r
+    // need to disable it in the device tree to prevent the OS from attaching\r
+    // its device driver as well.\r
+    //\r
+    Status = FdtClient->SetNodeProperty (FdtClient, Node, "status",\r
+                          "disabled", sizeof ("disabled"));\r
+    if (EFI_ERROR (Status)) {\r
+        DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n"));\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf b/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.inf
new file mode 100644 (file)
index 0000000..32dbff6
--- /dev/null
@@ -0,0 +1,49 @@
+#/** @file\r
+#  FDT client library for ARM's PL031 RTC driver\r
+#\r
+#  Copyright (c) 2016, Linaro Ltd. All rights reserved.\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmVirtPL031FdtClientLib\r
+  FILE_GUID                      = 13173319-B270-4669-8592-3BB2B31E9E29\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmVirtPL031FdtClientLib|DXE_DRIVER DXE_RUNTIME_DRIVER\r
+  CONSTRUCTOR                    = ArmVirtPL031FdtClientLibConstructor\r
+\r
+[Sources]\r
+  ArmVirtPL031FdtClientLib.c\r
+\r
+[Packages]\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  ArmVirtPkg/ArmVirtPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  PcdLib\r
+  UefiBootServicesTableLib\r
+\r
+[Protocols]\r
+  gFdtClientProtocolGuid                                ## CONSUMES\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdPL031RtcBase\r
+\r
+[FeaturePcd]\r
+  gArmVirtTokenSpaceGuid.PcdPureAcpiBoot\r
+\r
+[Depex]\r
+  gFdtClientProtocolGuid\r