3 Copyright (c) 2017-2021, Arm Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 System Control and Management Interface V1.0
8 http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/
9 DEN0056A_System_Control_and_Management_Interface.pdf
12 #include <Library/BaseLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Protocol/ArmScmiBaseProtocol.h>
17 #include "ArmScmiBaseProtocolPrivate.h"
18 #include "ScmiPrivate.h"
20 /** Return version of the Base protocol supported by SCP firmware.
22 @param[in] This A Pointer to SCMI_BASE_PROTOCOL Instance.
24 @param[out] Version Version of the supported SCMI Base protocol.
26 @retval EFI_SUCCESS The version of the protocol is returned.
27 @retval EFI_DEVICE_ERROR SCP returns an SCMI error.
28 @retval !(EFI_SUCCESS) Other errors.
33 IN SCMI_BASE_PROTOCOL
*This
,
37 return ScmiGetProtocolVersion (ScmiProtocolIdBase
, Version
);
40 /** Return total number of SCMI protocols supported by the SCP firmware.
42 @param[in] This A Pointer to SCMI_BASE_PROTOCOL Instance.
44 @param[out] TotalProtocols Total number of SCMI protocols supported.
46 @retval EFI_SUCCESS Total number of protocols supported are returned.
47 @retval EFI_DEVICE_ERROR SCP returns a SCMI error.
48 @retval !(EFI_SUCCESS) Other errors.
52 BaseGetTotalProtocols (
53 IN SCMI_BASE_PROTOCOL
*This
,
54 OUT UINT32
*TotalProtocols
60 Status
= ScmiGetProtocolAttributes (ScmiProtocolIdBase
, &ReturnValues
);
61 if (EFI_ERROR (Status
)) {
65 *TotalProtocols
= SCMI_TOTAL_PROTOCOLS (ReturnValues
[0]);
70 /** Common function which returns vendor details.
72 @param[in] MessageId ScmiMessageIdBaseDiscoverVendor
74 ScmiMessageIdBaseDiscoverSubVendor
76 @param[out] VendorIdentifier ASCII name of the vendor/subvendor.
78 @retval EFI_SUCCESS VendorIdentifier is returned.
79 @retval EFI_DEVICE_ERROR SCP returns an SCMI error.
80 @retval !(EFI_SUCCESS) Other errors.
84 BaseDiscoverVendorDetails (
85 IN SCMI_MESSAGE_ID_BASE MessageId
,
86 OUT UINT8 VendorIdentifier
[SCMI_MAX_STR_LEN
]
94 Cmd
.ProtocolId
= ScmiProtocolIdBase
;
95 Cmd
.MessageId
= MessageId
;
99 Status
= ScmiCommandExecute (
104 if (EFI_ERROR (Status
)) {
109 (CHAR8
*)VendorIdentifier
,
111 (CONST CHAR8
*)ReturnValues
117 /** Return vendor name.
119 @param[in] This A Pointer to SCMI_BASE_PROTOCOL Instance.
121 @param[out] VendorIdentifier Null terminated ASCII string of up to
122 16 bytes with a vendor name.
124 @retval EFI_SUCCESS VendorIdentifier is returned.
125 @retval EFI_DEVICE_ERROR SCP returns a SCMI error.
126 @retval !(EFI_SUCCESS) Other errors.
131 IN SCMI_BASE_PROTOCOL
*This
,
132 OUT UINT8 VendorIdentifier
[SCMI_MAX_STR_LEN
]
135 return BaseDiscoverVendorDetails (
136 ScmiMessageIdBaseDiscoverVendor
,
141 /** Return sub vendor name.
143 @param[in] This A Pointer to SCMI_BASE_PROTOCOL Instance.
145 @param[out] VendorIdentifier Null terminated ASCII string of up to
146 16 bytes with a sub vendor name.
148 @retval EFI_SUCCESS VendorIdentifier is returned.
149 @retval EFI_DEVICE_ERROR SCP returns a SCMI error.
150 @retval !(EFI_SUCCESS) Other errors.
153 BaseDiscoverSubVendor (
154 IN SCMI_BASE_PROTOCOL
*This
,
155 OUT UINT8 VendorIdentifier
[SCMI_MAX_STR_LEN
]
158 return BaseDiscoverVendorDetails (
159 ScmiMessageIdBaseDiscoverSubVendor
,
164 /** Return implementation version.
166 @param[in] This A Pointer to SCMI_BASE_PROTOCOL Instance.
168 @param[out] ImplementationVersion Vendor specific implementation version.
170 @retval EFI_SUCCESS Implementation version is returned.
171 @retval EFI_DEVICE_ERROR SCP returns a SCMI error.
172 @retval !(EFI_SUCCESS) Other errors.
176 BaseDiscoverImplVersion (
177 IN SCMI_BASE_PROTOCOL
*This
,
178 OUT UINT32
*ImplementationVersion
182 UINT32
*ReturnValues
;
184 UINT32 PayloadLength
;
186 Cmd
.ProtocolId
= ScmiProtocolIdBase
;
187 Cmd
.MessageId
= ScmiMessageIdBaseDiscoverImplementationVersion
;
191 Status
= ScmiCommandExecute (
196 if (EFI_ERROR (Status
)) {
200 *ImplementationVersion
= ReturnValues
[0];
205 /** Return list of protocols.
207 @param[in] This A Pointer to SCMI_BASE_PROTOCOL Instance.
209 @param[out] ProtocolListSize Size of the ProtocolList.
211 @param[out] ProtocolList Protocol list.
213 @retval EFI_SUCCESS List of protocols is returned.
214 @retval EFI_BUFFER_TOO_SMALL ProtocolListSize is too small for the result.
215 It has been updated to the size needed.
216 @retval EFI_DEVICE_ERROR SCP returns a SCMI error.
217 @retval !(EFI_SUCCESS) Other errors.
221 BaseDiscoverListProtocols (
222 IN SCMI_BASE_PROTOCOL
*This
,
223 IN OUT UINT32
*ProtocolListSize
,
224 OUT UINT8
*ProtocolList
228 UINT32 TotalProtocols
;
229 UINT32
*MessageParams
;
230 BASE_DISCOVER_LIST
*DiscoverList
;
234 UINT32 PayloadLength
;
237 Status
= BaseGetTotalProtocols (This
, &TotalProtocols
);
238 if (EFI_ERROR (Status
)) {
242 Status
= ScmiCommandGetPayload (&MessageParams
);
243 if (EFI_ERROR (Status
)) {
247 RequiredSize
= sizeof (UINT8
) * TotalProtocols
;
248 if (*ProtocolListSize
< RequiredSize
) {
249 *ProtocolListSize
= RequiredSize
;
250 return EFI_BUFFER_TOO_SMALL
;
253 Cmd
.ProtocolId
= ScmiProtocolIdBase
;
254 Cmd
.MessageId
= ScmiMessageIdBaseDiscoverListProtocols
;
258 while (Skip
< TotalProtocols
) {
259 *MessageParams
= Skip
;
261 // Note PayloadLength is a IN/OUT parameter.
262 PayloadLength
= sizeof (Skip
);
264 Status
= ScmiCommandExecute (
267 (UINT32
**)&DiscoverList
269 if (EFI_ERROR (Status
)) {
273 for (Index
= 0; Index
< DiscoverList
->NumProtocols
; Index
++) {
274 ProtocolList
[Skip
++] = DiscoverList
->Protocols
[Index
];
278 *ProtocolListSize
= RequiredSize
;
283 // Instance of the SCMI Base protocol.
284 STATIC CONST SCMI_BASE_PROTOCOL BaseProtocol
= {
286 BaseGetTotalProtocols
,
288 BaseDiscoverSubVendor
,
289 BaseDiscoverImplVersion
,
290 BaseDiscoverListProtocols
293 /** Initialize Base protocol and install protocol on a given handle.
295 @param[in] Handle Handle to install Base protocol.
297 @retval EFI_SUCCESS Base protocol interface installed
301 ScmiBaseProtocolInit (
302 IN OUT EFI_HANDLE
*Handle
305 return gBS
->InstallMultipleProtocolInterfaces (
307 &gArmScmiBaseProtocolGuid
,