]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c
ArmVirtPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPL031FdtClientLib / ArmVirtPL031FdtClientLib.c
1 /** @file
2 FDT client library for ARM's PL031 RTC driver
3
4 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <Uefi.h>
11
12 #include <Library/BaseLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
16
17 #include <Protocol/FdtClient.h>
18
19 RETURN_STATUS
20 EFIAPI
21 ArmVirtPL031FdtClientLibConstructor (
22 VOID
23 )
24 {
25 EFI_STATUS Status;
26 FDT_CLIENT_PROTOCOL *FdtClient;
27 INT32 Node;
28 CONST UINT64 *Reg;
29 UINT32 RegSize;
30 UINT64 RegBase;
31 RETURN_STATUS PcdStatus;
32
33 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
34 (VOID **)&FdtClient);
35 ASSERT_EFI_ERROR (Status);
36
37 Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);
38 if (EFI_ERROR (Status)) {
39 DEBUG ((EFI_D_WARN, "%a: No 'arm,pl031' compatible DT node found\n",
40 __FUNCTION__));
41 return EFI_SUCCESS;
42 }
43
44 Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",
45 (CONST VOID **)&Reg, &RegSize);
46 if (EFI_ERROR (Status)) {
47 DEBUG ((EFI_D_WARN,
48 "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",
49 __FUNCTION__));
50 return EFI_SUCCESS;
51 }
52
53 ASSERT (RegSize == 16);
54
55 RegBase = SwapBytes64 (Reg[0]);
56 ASSERT (RegBase < MAX_UINT32);
57
58 PcdStatus = PcdSet32S (PcdPL031RtcBase, (UINT32)RegBase);
59 ASSERT_RETURN_ERROR (PcdStatus);
60
61 DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));
62
63 //
64 // UEFI takes ownership of the RTC hardware, and exposes its functionality
65 // through the UEFI Runtime Services GetTime, SetTime, etc. This means we
66 // need to disable it in the device tree to prevent the OS from attaching
67 // its device driver as well.
68 //
69 Status = FdtClient->SetNodeProperty (FdtClient, Node, "status",
70 "disabled", sizeof ("disabled"));
71 if (EFI_ERROR (Status)) {
72 DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n"));
73 }
74
75 return EFI_SUCCESS;
76 }