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