]>
Commit | Line | Data |
---|---|---|
4f2494cf GP |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2017-2018, Arm Limited. All rights reserved.\r | |
4 | \r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | System Control and Management Interface V1.0\r | |
14 | http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/\r | |
15 | DEN0056A_System_Control_and_Management_Interface.pdf\r | |
16 | **/\r | |
17 | \r | |
18 | #include <Base.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/MemoryAllocationLib.h>\r | |
21 | #include <Library/UefiBootServicesTableLib.h>\r | |
22 | #include <Protocol/ArmScmiBaseProtocol.h>\r | |
23 | #include <Protocol/ArmScmiClockProtocol.h>\r | |
24 | #include <Protocol/ArmScmiPerformanceProtocol.h>\r | |
25 | \r | |
26 | #include "ArmScmiBaseProtocolPrivate.h"\r | |
27 | #include "ArmScmiClockProtocolPrivate.h"\r | |
28 | #include "ArmScmiPerformanceProtocolPrivate.h"\r | |
29 | #include "ScmiDxe.h"\r | |
30 | #include "ScmiPrivate.h"\r | |
31 | \r | |
889cf68c GP |
32 | STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {\r |
33 | { SCMI_PROTOCOL_ID_BASE, ScmiBaseProtocolInit },\r | |
34 | { SCMI_PROTOCOL_ID_PERFORMANCE, ScmiPerformanceProtocolInit },\r | |
35 | { SCMI_PROTOCOL_ID_CLOCK, ScmiClockProtocolInit }\r | |
4f2494cf GP |
36 | };\r |
37 | \r | |
38 | /** ARM SCMI driver entry point function.\r | |
39 | \r | |
40 | This function installs the SCMI Base protocol and a list of other\r | |
41 | protocols is queried using the Base protocol. If protocol is supported,\r | |
42 | driver will call each protocol init function to install the protocol on\r | |
43 | the ImageHandle.\r | |
44 | \r | |
45 | @param[in] ImageHandle Handle to this EFI Image which will be used to\r | |
46 | install Base, Clock and Performance protocols.\r | |
47 | @param[in] SystemTable A pointer to boot time system table.\r | |
48 | \r | |
49 | @retval EFI_SUCCESS Driver initalized successfully.\r | |
50 | @retval EFI_UNSUPPORTED If SCMI base protocol version is not supported.\r | |
51 | @retval !(EFI_SUCCESS) Other errors.\r | |
52 | **/\r | |
53 | EFI_STATUS\r | |
54 | EFIAPI\r | |
55 | ArmScmiDxeEntryPoint (\r | |
56 | IN EFI_HANDLE ImageHandle,\r | |
57 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
58 | )\r | |
59 | {\r | |
60 | EFI_STATUS Status;\r | |
61 | SCMI_BASE_PROTOCOL *BaseProtocol;\r | |
62 | UINT32 Version;\r | |
63 | UINT32 Index;\r | |
64 | UINT32 NumProtocols;\r | |
889cf68c | 65 | UINT32 ProtocolIndex;\r |
3b03b5e9 GP |
66 | UINT8 *SupportedList;\r |
67 | UINT32 SupportedListSize;\r | |
4f2494cf | 68 | \r |
4f2494cf | 69 | // Every SCMI implementation must implement the base protocol.\r |
889cf68c GP |
70 | ASSERT (Protocols[0].Id == SCMI_PROTOCOL_ID_BASE);\r |
71 | \r | |
72 | Status = ScmiBaseProtocolInit (&ImageHandle);\r | |
4f2494cf GP |
73 | if (EFI_ERROR (Status)) {\r |
74 | ASSERT (FALSE);\r | |
75 | return Status;\r | |
76 | }\r | |
77 | \r | |
78 | Status = gBS->LocateProtocol (\r | |
79 | &gArmScmiBaseProtocolGuid,\r | |
80 | NULL,\r | |
81 | (VOID**)&BaseProtocol\r | |
82 | );\r | |
83 | if (EFI_ERROR (Status)) {\r | |
84 | ASSERT (FALSE);\r | |
85 | return Status;\r | |
86 | }\r | |
87 | \r | |
88 | // Get SCMI Base protocol version.\r | |
89 | Status = BaseProtocol->GetVersion (BaseProtocol, &Version);\r | |
90 | if (EFI_ERROR (Status)) {\r | |
91 | ASSERT (FALSE);\r | |
92 | return Status;\r | |
93 | }\r | |
94 | \r | |
95 | if (Version != BASE_PROTOCOL_VERSION) {\r | |
96 | ASSERT (FALSE);\r | |
97 | return EFI_UNSUPPORTED;\r | |
98 | }\r | |
99 | \r | |
100 | // Apart from Base protocol, SCMI may implement various other protocols,\r | |
101 | // query total protocols implemented by the SCP firmware.\r | |
102 | NumProtocols = 0;\r | |
103 | Status = BaseProtocol->GetTotalProtocols (BaseProtocol, &NumProtocols);\r | |
104 | if (EFI_ERROR (Status)) {\r | |
105 | ASSERT (FALSE);\r | |
106 | return Status;\r | |
107 | }\r | |
108 | \r | |
109 | ASSERT (NumProtocols != 0);\r | |
110 | \r | |
3b03b5e9 GP |
111 | SupportedListSize = (NumProtocols * sizeof (*SupportedList));\r |
112 | \r | |
113 | Status = gBS->AllocatePool (\r | |
114 | EfiBootServicesData,\r | |
115 | SupportedListSize,\r | |
116 | (VOID**)&SupportedList\r | |
117 | );\r | |
118 | if (EFI_ERROR (Status)) {\r | |
119 | ASSERT (FALSE);\r | |
120 | return Status;\r | |
121 | }\r | |
122 | \r | |
4f2494cf GP |
123 | // Get the list of protocols supported by SCP firmware on the platform.\r |
124 | Status = BaseProtocol->DiscoverListProtocols (\r | |
3b03b5e9 GP |
125 | BaseProtocol,\r |
126 | &SupportedListSize,\r | |
127 | SupportedList\r | |
128 | );\r | |
4f2494cf | 129 | if (EFI_ERROR (Status)) {\r |
3b03b5e9 | 130 | gBS->FreePool (SupportedList);\r |
4f2494cf GP |
131 | ASSERT (FALSE);\r |
132 | return Status;\r | |
133 | }\r | |
134 | \r | |
135 | // Install supported protocol on ImageHandle.\r | |
889cf68c GP |
136 | for (ProtocolIndex = 1; ProtocolIndex < ARRAY_SIZE (Protocols);\r |
137 | ProtocolIndex++) {\r | |
138 | for (Index = 0; Index < NumProtocols; Index++) {\r | |
139 | if (Protocols[ProtocolIndex].Id == SupportedList[Index]) {\r | |
140 | Status = Protocols[ProtocolIndex].InitFn (&ImageHandle);\r | |
141 | if (EFI_ERROR (Status)) {\r | |
142 | ASSERT_EFI_ERROR (Status);\r | |
143 | return Status;\r | |
144 | }\r | |
145 | break;\r | |
4f2494cf GP |
146 | }\r |
147 | }\r | |
148 | }\r | |
149 | \r | |
3b03b5e9 GP |
150 | gBS->FreePool (SupportedList);\r |
151 | \r | |
4f2494cf GP |
152 | return EFI_SUCCESS;\r |
153 | }\r |