]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
9792fb0e 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
658e7a41
AB
7\r
8**/\r
9\r
10#include <Uefi.h>\r
11\r
12#include <Library/BaseLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/PcdLib.h>\r
15#include <Library/UefiBootServicesTableLib.h>\r
16\r
17#include <Protocol/FdtClient.h>\r
18\r
19RETURN_STATUS\r
20EFIAPI\r
21ArmVirtPL031FdtClientLibConstructor (\r
22 VOID\r
23 )\r
24{\r
2b16a4fb
MK
25 EFI_STATUS Status;\r
26 FDT_CLIENT_PROTOCOL *FdtClient;\r
27 INT32 Node;\r
28 CONST UINT64 *Reg;\r
29 UINT32 RegSize;\r
30 UINT64 RegBase;\r
31 RETURN_STATUS PcdStatus;\r
32\r
33 Status = gBS->LocateProtocol (\r
34 &gFdtClientProtocolGuid,\r
35 NULL,\r
36 (VOID **)&FdtClient\r
37 );\r
658e7a41
AB
38 ASSERT_EFI_ERROR (Status);\r
39\r
40 Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);\r
41 if (EFI_ERROR (Status)) {\r
2b16a4fb
MK
42 DEBUG ((\r
43 DEBUG_WARN,\r
44 "%a: No 'arm,pl031' compatible DT node found\n",\r
45 __FUNCTION__\r
46 ));\r
658e7a41
AB
47 return EFI_SUCCESS;\r
48 }\r
49\r
2b16a4fb
MK
50 Status = FdtClient->GetNodeProperty (\r
51 FdtClient,\r
52 Node,\r
53 "reg",\r
54 (CONST VOID **)&Reg,\r
55 &RegSize\r
56 );\r
658e7a41 57 if (EFI_ERROR (Status)) {\r
2b16a4fb
MK
58 DEBUG ((\r
59 DEBUG_WARN,\r
658e7a41 60 "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",\r
2b16a4fb
MK
61 __FUNCTION__\r
62 ));\r
658e7a41
AB
63 return EFI_SUCCESS;\r
64 }\r
65\r
66 ASSERT (RegSize == 16);\r
67\r
68 RegBase = SwapBytes64 (Reg[0]);\r
69 ASSERT (RegBase < MAX_UINT32);\r
70\r
a79d29b6
LE
71 PcdStatus = PcdSet32S (PcdPL031RtcBase, (UINT32)RegBase);\r
72 ASSERT_RETURN_ERROR (PcdStatus);\r
658e7a41 73\r
c5b3a56e 74 DEBUG ((DEBUG_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));\r
658e7a41 75\r
d5256ba9
AB
76 //\r
77 // UEFI takes ownership of the RTC hardware, and exposes its functionality\r
78 // through the UEFI Runtime Services GetTime, SetTime, etc. This means we\r
79 // need to disable it in the device tree to prevent the OS from attaching\r
80 // its device driver as well.\r
81 //\r
2b16a4fb
MK
82 Status = FdtClient->SetNodeProperty (\r
83 FdtClient,\r
84 Node,\r
85 "status",\r
86 "disabled",\r
87 sizeof ("disabled")\r
88 );\r
d5256ba9 89 if (EFI_ERROR (Status)) {\r
2b16a4fb 90 DEBUG ((DEBUG_WARN, "Failed to set PL031 status to 'disabled'\n"));\r
658e7a41
AB
91 }\r
92\r
93 return EFI_SUCCESS;\r
94}\r