]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
UefiCpuPkg: Change complex DEBUG_CODE() to DEBUG_CODE_BEGIN/END()
[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
889cf68c 26STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {\r
462f95ec
PG
27 { ScmiProtocolIdBase, ScmiBaseProtocolInit },\r
28 { ScmiProtocolIdPerformance, ScmiPerformanceProtocolInit },\r
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
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
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
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
375f2d8e
NM
89 // Accept any version between SCMI v1.0 and SCMI v2.0\r
90 if ((Version < BASE_PROTOCOL_VERSION_V1) ||\r
91 (Version > BASE_PROTOCOL_VERSION_V2)) {\r
4f2494cf
GP
92 ASSERT (FALSE);\r
93 return EFI_UNSUPPORTED;\r
94 }\r
95\r
96 // Apart from Base protocol, SCMI may implement various other protocols,\r
97 // query total protocols implemented by the SCP firmware.\r
98 NumProtocols = 0;\r
99 Status = BaseProtocol->GetTotalProtocols (BaseProtocol, &NumProtocols);\r
100 if (EFI_ERROR (Status)) {\r
101 ASSERT (FALSE);\r
102 return Status;\r
103 }\r
104\r
105 ASSERT (NumProtocols != 0);\r
106\r
3b03b5e9
GP
107 SupportedListSize = (NumProtocols * sizeof (*SupportedList));\r
108\r
109 Status = gBS->AllocatePool (\r
110 EfiBootServicesData,\r
111 SupportedListSize,\r
112 (VOID**)&SupportedList\r
113 );\r
114 if (EFI_ERROR (Status)) {\r
115 ASSERT (FALSE);\r
116 return Status;\r
117 }\r
118\r
4f2494cf
GP
119 // Get the list of protocols supported by SCP firmware on the platform.\r
120 Status = BaseProtocol->DiscoverListProtocols (\r
3b03b5e9
GP
121 BaseProtocol,\r
122 &SupportedListSize,\r
123 SupportedList\r
124 );\r
4f2494cf 125 if (EFI_ERROR (Status)) {\r
3b03b5e9 126 gBS->FreePool (SupportedList);\r
4f2494cf
GP
127 ASSERT (FALSE);\r
128 return Status;\r
129 }\r
130\r
131 // Install supported protocol on ImageHandle.\r
889cf68c
GP
132 for (ProtocolIndex = 1; ProtocolIndex < ARRAY_SIZE (Protocols);\r
133 ProtocolIndex++) {\r
134 for (Index = 0; Index < NumProtocols; Index++) {\r
135 if (Protocols[ProtocolIndex].Id == SupportedList[Index]) {\r
136 Status = Protocols[ProtocolIndex].InitFn (&ImageHandle);\r
137 if (EFI_ERROR (Status)) {\r
138 ASSERT_EFI_ERROR (Status);\r
139 return Status;\r
140 }\r
141 break;\r
4f2494cf
GP
142 }\r
143 }\r
144 }\r
145\r
3b03b5e9
GP
146 gBS->FreePool (SupportedList);\r
147\r
4f2494cf
GP
148 return EFI_SUCCESS;\r
149}\r