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