VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/ArmVirtPkg/Library/ArmVirtPL031FdtClientLib/ArmVirtPL031FdtClientLib.c@ 102513

Last change on this file since 102513 was 102513, checked in by vboxsync, 12 months ago

Devices/EFI/Firmware: Allow the PL031 RTC device to be accessible anywhere in the 64-bit address space, bugref:10528

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
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
19RETURN_STATUS
20EFIAPI
21ArmVirtPL031FdtClientLibConstructor (
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 (
34 &gFdtClientProtocolGuid,
35 NULL,
36 (VOID **)&FdtClient
37 );
38 ASSERT_EFI_ERROR (Status);
39
40 Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);
41 if (EFI_ERROR (Status)) {
42 DEBUG ((
43 DEBUG_WARN,
44 "%a: No 'arm,pl031' compatible DT node found\n",
45 __func__
46 ));
47 return EFI_SUCCESS;
48 }
49
50 Status = FdtClient->GetNodeProperty (
51 FdtClient,
52 Node,
53 "reg",
54 (CONST VOID **)&Reg,
55 &RegSize
56 );
57 if (EFI_ERROR (Status)) {
58 DEBUG ((
59 DEBUG_WARN,
60 "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",
61 __func__
62 ));
63 return EFI_SUCCESS;
64 }
65
66 ASSERT (RegSize == 16);
67
68 RegBase = SwapBytes64 (Reg[0]);
69#ifdef VBOX
70 PcdStatus = PcdSet64S (PcdPL031RtcBase, RegBase);
71#else
72 ASSERT (RegBase < MAX_UINT32);
73
74 PcdStatus = PcdSet32S (PcdPL031RtcBase, (UINT32)RegBase);
75#endif
76 ASSERT_RETURN_ERROR (PcdStatus);
77
78 DEBUG ((DEBUG_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));
79
80 //
81 // UEFI takes ownership of the RTC hardware, and exposes its functionality
82 // through the UEFI Runtime Services GetTime, SetTime, etc. This means we
83 // need to disable it in the device tree to prevent the OS from attaching
84 // its device driver as well.
85 //
86 Status = FdtClient->SetNodeProperty (
87 FdtClient,
88 Node,
89 "status",
90 "disabled",
91 sizeof ("disabled")
92 );
93 if (EFI_ERROR (Status)) {
94 DEBUG ((DEBUG_WARN, "Failed to set PL031 status to 'disabled'\n"));
95 }
96
97 return EFI_SUCCESS;
98}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette