]>
Commit | Line | Data |
---|---|---|
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 | |
26 | typedef struct {\r | |
27 | UINT32 Type;\r | |
28 | UINT32 Number;\r | |
29 | UINT32 Flags;\r | |
30 | } INTERRUPT_PROPERTY;\r | |
31 | #pragma pack ()\r | |
32 | \r | |
33 | RETURN_STATUS\r | |
34 | EFIAPI\r | |
35 | ArmVirtTimerFdtClientLibConstructor (\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 | |
537eb072 | 44 | RETURN_STATUS PcdStatus;\r |
ea62bb76 AB |
45 | \r |
46 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r | |
47 | (VOID **)&FdtClient);\r | |
48 | ASSERT_EFI_ERROR (Status);\r | |
49 | \r | |
50 | Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,armv7-timer",\r | |
51 | "interrupts", (CONST VOID **)&InterruptProp,\r | |
52 | &PropSize);\r | |
53 | if (Status == EFI_NOT_FOUND) {\r | |
54 | Status = FdtClient->FindCompatibleNodeProperty (FdtClient,\r | |
55 | "arm,armv8-timer", "interrupts",\r | |
56 | (CONST VOID **)&InterruptProp,\r | |
57 | &PropSize);\r | |
58 | }\r | |
59 | \r | |
60 | if (EFI_ERROR (Status)) {\r | |
61 | return Status;\r | |
62 | }\r | |
63 | \r | |
64 | //\r | |
65 | // - interrupts : Interrupt list for secure, non-secure, virtual and\r | |
66 | // hypervisor timers, in that order.\r | |
67 | //\r | |
68 | ASSERT (PropSize == 36 || PropSize == 48);\r | |
69 | \r | |
70 | SecIntrNum = SwapBytes32 (InterruptProp[0].Number)\r | |
71 | + (InterruptProp[0].Type ? 16 : 0);\r | |
72 | IntrNum = SwapBytes32 (InterruptProp[1].Number)\r | |
73 | + (InterruptProp[1].Type ? 16 : 0);\r | |
74 | VirtIntrNum = SwapBytes32 (InterruptProp[2].Number)\r | |
75 | + (InterruptProp[2].Type ? 16 : 0);\r | |
76 | HypIntrNum = PropSize < 48 ? 0 : SwapBytes32 (InterruptProp[3].Number)\r | |
77 | + (InterruptProp[3].Type ? 16 : 0);\r | |
78 | \r | |
79 | DEBUG ((EFI_D_INFO, "Found Timer interrupts %d, %d, %d, %d\n",\r | |
80 | SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum));\r | |
81 | \r | |
537eb072 LE |
82 | PcdStatus = PcdSet32S (PcdArmArchTimerSecIntrNum, SecIntrNum);\r |
83 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
84 | PcdStatus = PcdSet32S (PcdArmArchTimerIntrNum, IntrNum);\r | |
85 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
86 | PcdStatus = PcdSet32S (PcdArmArchTimerVirtIntrNum, VirtIntrNum);\r | |
87 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
88 | PcdStatus = PcdSet32S (PcdArmArchTimerHypIntrNum, HypIntrNum);\r | |
89 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
ea62bb76 AB |
90 | \r |
91 | return EFI_SUCCESS;\r | |
92 | }\r |