]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c
ArmVirtPkg: implement ArmVirtPL031FdtClientLib
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPL031FdtClientLib / ArmVirtPL031FdtClientLib.c
CommitLineData
658e7a41
AB
1/** @file\r
2 FDT client library for ARM's PL031 RTC driver\r
3\r
4 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Uefi.h>\r
17\r
18#include <Library/BaseLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22\r
23#include <Protocol/FdtClient.h>\r
24\r
25RETURN_STATUS\r
26EFIAPI\r
27ArmVirtPL031FdtClientLibConstructor (\r
28 VOID\r
29 )\r
30{\r
31 EFI_STATUS Status;\r
32 FDT_CLIENT_PROTOCOL *FdtClient;\r
33 INT32 Node;\r
34 CONST UINT64 *Reg;\r
35 UINT32 RegSize;\r
36 UINT64 RegBase;\r
37\r
38 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
39 (VOID **)&FdtClient);\r
40 ASSERT_EFI_ERROR (Status);\r
41\r
42 Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);\r
43 if (EFI_ERROR (Status)) {\r
44 DEBUG ((EFI_D_WARN, "%a: No 'arm,pl031' compatible DT node found\n",\r
45 __FUNCTION__));\r
46 return EFI_SUCCESS;\r
47 }\r
48\r
49 Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r
50 (CONST VOID **)&Reg, &RegSize);\r
51 if (EFI_ERROR (Status)) {\r
52 DEBUG ((EFI_D_WARN,\r
53 "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",\r
54 __FUNCTION__));\r
55 return EFI_SUCCESS;\r
56 }\r
57\r
58 ASSERT (RegSize == 16);\r
59\r
60 RegBase = SwapBytes64 (Reg[0]);\r
61 ASSERT (RegBase < MAX_UINT32);\r
62\r
63 PcdSet32 (PcdPL031RtcBase, (UINT32)RegBase);\r
64\r
65 DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));\r
66\r
67 if (!FeaturePcdGet (PcdPureAcpiBoot)) {\r
68 //\r
69 // UEFI takes ownership of the RTC hardware, and exposes its functionality\r
70 // through the UEFI Runtime Services GetTime, SetTime, etc. This means we\r
71 // need to disable it in the device tree to prevent the OS from attaching\r
72 // its device driver as well.\r
73 //\r
74 Status = FdtClient->SetNodeProperty (FdtClient, Node, "status",\r
75 "disabled", sizeof ("disabled"));\r
76 if (EFI_ERROR (Status)) {\r
77 DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n"));\r
78 }\r
79 }\r
80\r
81 return EFI_SUCCESS;\r
82}\r