--- /dev/null
+/** @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
--- /dev/null
+#/** @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