]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Drivers / ArmScmiDxe / ScmiDxe.c
CommitLineData
4f2494cf
GP
1/** @file\r
2\r
462f95ec 3 Copyright (c) 2017-2021, Arm Limited. All rights reserved.<BR>\r
4f2494cf 4\r
4059386c 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
4f2494cf 6\r
375f2d8e
NM
7 @par Specification Reference:\r
8 - Arm System Control and Management Interface - Platform Design Document\r
9 (https://developer.arm.com/documentation/den0056/)\r
4f2494cf
GP
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
429309e0
MK
26STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {\r
27 { ScmiProtocolIdBase, ScmiBaseProtocolInit },\r
462f95ec 28 { ScmiProtocolIdPerformance, ScmiPerformanceProtocolInit },\r
429309e0 29 { ScmiProtocolIdClock, 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
429309e0
MK
50 IN EFI_HANDLE ImageHandle,\r
51 IN EFI_SYSTEM_TABLE *SystemTable\r
4f2494cf
GP
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
462f95ec 64 ASSERT (Protocols[0].Id == ScmiProtocolIdBase);\r
889cf68c
GP
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
429309e0 75 (VOID **)&BaseProtocol\r
4f2494cf
GP
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
375f2d8e
NM
89 // Accept any version between SCMI v1.0 and SCMI v2.0\r
90 if ((Version < BASE_PROTOCOL_VERSION_V1) ||\r
429309e0
MK
91 (Version > BASE_PROTOCOL_VERSION_V2))\r
92 {\r
4f2494cf
GP
93 ASSERT (FALSE);\r
94 return EFI_UNSUPPORTED;\r
95 }\r
96\r
97 // Apart from Base protocol, SCMI may implement various other protocols,\r
98 // query total protocols implemented by the SCP firmware.\r
99 NumProtocols = 0;\r
429309e0 100 Status = BaseProtocol->GetTotalProtocols (BaseProtocol, &NumProtocols);\r
4f2494cf
GP
101 if (EFI_ERROR (Status)) {\r
102 ASSERT (FALSE);\r
103 return Status;\r
104 }\r
105\r
106 ASSERT (NumProtocols != 0);\r
107\r
3b03b5e9
GP
108 SupportedListSize = (NumProtocols * sizeof (*SupportedList));\r
109\r
110 Status = gBS->AllocatePool (\r
111 EfiBootServicesData,\r
112 SupportedListSize,\r
429309e0 113 (VOID **)&SupportedList\r
3b03b5e9
GP
114 );\r
115 if (EFI_ERROR (Status)) {\r
116 ASSERT (FALSE);\r
117 return Status;\r
118 }\r
119\r
4f2494cf
GP
120 // Get the list of protocols supported by SCP firmware on the platform.\r
121 Status = BaseProtocol->DiscoverListProtocols (\r
3b03b5e9
GP
122 BaseProtocol,\r
123 &SupportedListSize,\r
124 SupportedList\r
125 );\r
4f2494cf 126 if (EFI_ERROR (Status)) {\r
3b03b5e9 127 gBS->FreePool (SupportedList);\r
4f2494cf
GP
128 ASSERT (FALSE);\r
129 return Status;\r
130 }\r
131\r
132 // Install supported protocol on ImageHandle.\r
889cf68c 133 for (ProtocolIndex = 1; ProtocolIndex < ARRAY_SIZE (Protocols);\r
429309e0
MK
134 ProtocolIndex++)\r
135 {\r
889cf68c
GP
136 for (Index = 0; Index < NumProtocols; Index++) {\r
137 if (Protocols[ProtocolIndex].Id == SupportedList[Index]) {\r
138 Status = Protocols[ProtocolIndex].InitFn (&ImageHandle);\r
139 if (EFI_ERROR (Status)) {\r
140 ASSERT_EFI_ERROR (Status);\r
141 return Status;\r
142 }\r
429309e0 143\r
889cf68c 144 break;\r
4f2494cf
GP
145 }\r
146 }\r
147 }\r
148\r
3b03b5e9
GP
149 gBS->FreePool (SupportedList);\r
150\r
4f2494cf
GP
151 return EFI_SUCCESS;\r
152}\r