]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.c
ArmVirtPkg/PlatformBootManagerLib: rebase boot logo display to BootLogoLib
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtTimerFdtClientLib / ArmVirtTimerFdtClientLib.c
1 /** @file
2 FDT client library for ARM's TimerDxe
3
4 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <Uefi.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22
23 #include <Protocol/FdtClient.h>
24
25 #pragma pack (1)
26 typedef struct {
27 UINT32 Type;
28 UINT32 Number;
29 UINT32 Flags;
30 } INTERRUPT_PROPERTY;
31 #pragma pack ()
32
33 RETURN_STATUS
34 EFIAPI
35 ArmVirtTimerFdtClientLibConstructor (
36 VOID
37 )
38 {
39 EFI_STATUS Status;
40 FDT_CLIENT_PROTOCOL *FdtClient;
41 CONST INTERRUPT_PROPERTY *InterruptProp;
42 UINT32 PropSize;
43 INT32 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum;
44
45 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
46 (VOID **)&FdtClient);
47 ASSERT_EFI_ERROR (Status);
48
49 Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,armv7-timer",
50 "interrupts", (CONST VOID **)&InterruptProp,
51 &PropSize);
52 if (Status == EFI_NOT_FOUND) {
53 Status = FdtClient->FindCompatibleNodeProperty (FdtClient,
54 "arm,armv8-timer", "interrupts",
55 (CONST VOID **)&InterruptProp,
56 &PropSize);
57 }
58
59 if (EFI_ERROR (Status)) {
60 return Status;
61 }
62
63 //
64 // - interrupts : Interrupt list for secure, non-secure, virtual and
65 // hypervisor timers, in that order.
66 //
67 ASSERT (PropSize == 36 || PropSize == 48);
68
69 SecIntrNum = SwapBytes32 (InterruptProp[0].Number)
70 + (InterruptProp[0].Type ? 16 : 0);
71 IntrNum = SwapBytes32 (InterruptProp[1].Number)
72 + (InterruptProp[1].Type ? 16 : 0);
73 VirtIntrNum = SwapBytes32 (InterruptProp[2].Number)
74 + (InterruptProp[2].Type ? 16 : 0);
75 HypIntrNum = PropSize < 48 ? 0 : SwapBytes32 (InterruptProp[3].Number)
76 + (InterruptProp[3].Type ? 16 : 0);
77
78 DEBUG ((EFI_D_INFO, "Found Timer interrupts %d, %d, %d, %d\n",
79 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum));
80
81 PcdSet32 (PcdArmArchTimerSecIntrNum, SecIntrNum);
82 PcdSet32 (PcdArmArchTimerIntrNum, IntrNum);
83 PcdSet32 (PcdArmArchTimerVirtIntrNum, VirtIntrNum);
84 PcdSet32 (PcdArmArchTimerHypIntrNum, HypIntrNum);
85
86 return EFI_SUCCESS;
87 }