TianoCore EDK2 master
Loading...
Searching...
No Matches
ArmVirtTimerFdtClientLib.c
Go to the documentation of this file.
1
10#include <Uefi.h>
11
12#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
14#include <Library/PcdLib.h>
16
17#include <Protocol/FdtClient.h>
18
19#pragma pack (1)
20typedef struct {
21 UINT32 Type;
22 UINT32 Number;
23 UINT32 Flags;
25#pragma pack ()
26
27RETURN_STATUS
28EFIAPI
29ArmVirtTimerFdtClientLibConstructor (
30 VOID
31 )
32{
33 EFI_STATUS Status;
34 FDT_CLIENT_PROTOCOL *FdtClient;
35 CONST INTERRUPT_PROPERTY *InterruptProp;
36 UINT32 PropSize;
37 INT32 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum;
38 INT32 HypVirtIntrNum;
39 RETURN_STATUS PcdStatus;
40
41 Status = gBS->LocateProtocol (
42 &gFdtClientProtocolGuid,
43 NULL,
44 (VOID **)&FdtClient
45 );
46 ASSERT_EFI_ERROR (Status);
47
48 Status = FdtClient->FindCompatibleNodeProperty (
49 FdtClient,
50 "arm,armv7-timer",
51 "interrupts",
52 (CONST VOID **)&InterruptProp,
53 &PropSize
54 );
55 if (Status == EFI_NOT_FOUND) {
56 Status = FdtClient->FindCompatibleNodeProperty (
57 FdtClient,
58 "arm,armv8-timer",
59 "interrupts",
60 (CONST VOID **)&InterruptProp,
61 &PropSize
62 );
63 }
64
65 if (EFI_ERROR (Status)) {
66 return Status;
67 }
68
69 //
70 // - interrupts : Interrupt list for secure, non-secure, virtual,
71 // hypervisor and hypervisor virtual timers, in that order.
72 //
73 ASSERT (PropSize >= 36);
74
75 SecIntrNum = SwapBytes32 (InterruptProp[0].Number)
76 + (InterruptProp[0].Type ? 16 : 0);
77 IntrNum = SwapBytes32 (InterruptProp[1].Number)
78 + (InterruptProp[1].Type ? 16 : 0);
79 VirtIntrNum = SwapBytes32 (InterruptProp[2].Number)
80 + (InterruptProp[2].Type ? 16 : 0);
81 HypIntrNum = PropSize < 48 ? 0 : SwapBytes32 (InterruptProp[3].Number)
82 + (InterruptProp[3].Type ? 16 : 0);
83 HypVirtIntrNum = PropSize < 60 ? 0 : SwapBytes32 (InterruptProp[4].Number)
84 + (InterruptProp[4].Type ? 16 : 0);
85
86 DEBUG ((
87 DEBUG_INFO,
88 "Found Timer interrupts %d, %d, %d, %d\n",
89 SecIntrNum,
90 IntrNum,
91 VirtIntrNum,
92 HypIntrNum
93 ));
94
95 PcdStatus = PcdSet32S (PcdArmArchTimerSecIntrNum, SecIntrNum);
96 ASSERT_RETURN_ERROR (PcdStatus);
97 PcdStatus = PcdSet32S (PcdArmArchTimerIntrNum, IntrNum);
98 ASSERT_RETURN_ERROR (PcdStatus);
99 PcdStatus = PcdSet32S (PcdArmArchTimerVirtIntrNum, VirtIntrNum);
100 ASSERT_RETURN_ERROR (PcdStatus);
101 PcdStatus = PcdSet32S (PcdArmArchTimerHypIntrNum, HypIntrNum);
102 ASSERT_RETURN_ERROR (PcdStatus);
103 PcdStatus = PcdSet32S (PcdArmArchTimerHypVirtIntrNum, HypVirtIntrNum);
104 ASSERT_RETURN_ERROR (PcdStatus);
105
106 return EFI_SUCCESS;
107}
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define ASSERT_RETURN_ERROR(StatusParameter)
Definition: DebugLib.h:493
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdSet32S(TokenName, Value)
Definition: PcdLib.h:497
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS