TianoCore EDK2 master
Loading...
Searching...
No Matches
ScmiBaseProtocol.c
Go to the documentation of this file.
1
12#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
16
18#include "ScmiPrivate.h"
19
34 OUT UINT32 *Version
35 )
36{
37 return ScmiGetProtocolVersion (ScmiProtocolIdBase, Version);
38}
39
54 OUT UINT32 *TotalProtocols
55 )
56{
57 EFI_STATUS Status;
58 UINT32 *ReturnValues;
59
60 Status = ScmiGetProtocolAttributes (ScmiProtocolIdBase, &ReturnValues);
61 if (EFI_ERROR (Status)) {
62 return Status;
63 }
64
65 *TotalProtocols = SCMI_TOTAL_PROTOCOLS (ReturnValues[0]);
66
67 return EFI_SUCCESS;
68}
69
85 IN SCMI_MESSAGE_ID_BASE MessageId,
86 OUT UINT8 VendorIdentifier[SCMI_MAX_STR_LEN]
87 )
88{
89 EFI_STATUS Status;
90 UINT32 *ReturnValues;
91 SCMI_COMMAND Cmd;
92 UINT32 PayloadLength;
93
94 Cmd.ProtocolId = ScmiProtocolIdBase;
95 Cmd.MessageId = MessageId;
96
97 PayloadLength = 0;
98
99 Status = ScmiCommandExecute (
100 &Cmd,
101 &PayloadLength,
102 &ReturnValues
103 );
104 if (EFI_ERROR (Status)) {
105 return Status;
106 }
107
109 (CHAR8 *)VendorIdentifier,
110 SCMI_MAX_STR_LEN,
111 (CONST CHAR8 *)ReturnValues
112 );
113
114 return EFI_SUCCESS;
115}
116
128STATIC
132 OUT UINT8 VendorIdentifier[SCMI_MAX_STR_LEN]
133 )
134{
136 ScmiMessageIdBaseDiscoverVendor,
137 VendorIdentifier
138 );
139}
140
155 OUT UINT8 VendorIdentifier[SCMI_MAX_STR_LEN]
156 )
157{
159 ScmiMessageIdBaseDiscoverSubVendor,
160 VendorIdentifier
161 );
162}
163
174STATIC
178 OUT UINT32 *ImplementationVersion
179 )
180{
181 EFI_STATUS Status;
182 UINT32 *ReturnValues;
183 SCMI_COMMAND Cmd;
184 UINT32 PayloadLength;
185
186 Cmd.ProtocolId = ScmiProtocolIdBase;
187 Cmd.MessageId = ScmiMessageIdBaseDiscoverImplementationVersion;
188
189 PayloadLength = 0;
190
191 Status = ScmiCommandExecute (
192 &Cmd,
193 &PayloadLength,
194 &ReturnValues
195 );
196 if (EFI_ERROR (Status)) {
197 return Status;
198 }
199
200 *ImplementationVersion = ReturnValues[0];
201
202 return EFI_SUCCESS;
203}
204
219STATIC
223 IN OUT UINT32 *ProtocolListSize,
224 OUT UINT8 *ProtocolList
225 )
226{
227 EFI_STATUS Status;
228 UINT32 TotalProtocols;
229 UINT32 *MessageParams;
230 BASE_DISCOVER_LIST *DiscoverList;
231 UINT32 Skip;
232 UINT32 Index;
233 SCMI_COMMAND Cmd;
234 UINT32 PayloadLength;
235 UINT32 RequiredSize;
236
237 Status = BaseGetTotalProtocols (This, &TotalProtocols);
238 if (EFI_ERROR (Status)) {
239 return Status;
240 }
241
242 Status = ScmiCommandGetPayload (&MessageParams);
243 if (EFI_ERROR (Status)) {
244 return Status;
245 }
246
247 RequiredSize = sizeof (UINT8) * TotalProtocols;
248 if (*ProtocolListSize < RequiredSize) {
249 *ProtocolListSize = RequiredSize;
250 return EFI_BUFFER_TOO_SMALL;
251 }
252
253 Cmd.ProtocolId = ScmiProtocolIdBase;
254 Cmd.MessageId = ScmiMessageIdBaseDiscoverListProtocols;
255
256 Skip = 0;
257
258 while (Skip < TotalProtocols) {
259 *MessageParams = Skip;
260
261 // Note PayloadLength is a IN/OUT parameter.
262 PayloadLength = sizeof (Skip);
263
264 Status = ScmiCommandExecute (
265 &Cmd,
266 &PayloadLength,
267 (UINT32 **)&DiscoverList
268 );
269 if (EFI_ERROR (Status)) {
270 return Status;
271 }
272
273 for (Index = 0; Index < DiscoverList->NumProtocols; Index++) {
274 ProtocolList[Skip++] = DiscoverList->Protocols[Index];
275 }
276 }
277
278 *ProtocolListSize = RequiredSize;
279
280 return EFI_SUCCESS;
281}
282
283// Instance of the SCMI Base protocol.
284STATIC CONST SCMI_BASE_PROTOCOL BaseProtocol = {
291};
292
302 IN OUT EFI_HANDLE *Handle
303 )
304{
305 return gBS->InstallMultipleProtocolInterfaces (
306 Handle,
307 &gArmScmiBaseProtocolGuid,
308 &BaseProtocol,
309 NULL
310 );
311}
#define SCMI_TOTAL_PROTOCOLS(Attr)
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
Definition: SafeString.c:1797
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS ScmiGetProtocolVersion(IN SCMI_PROTOCOL_ID ProtocolId, OUT UINT32 *Version)
Definition: Scmi.c:190
EFI_STATUS ScmiCommandExecute(IN SCMI_COMMAND *Command, IN OUT UINT32 *PayloadLength, OUT UINT32 **ReturnValues OPTIONAL)
Definition: Scmi.c:76
EFI_STATUS ScmiCommandGetPayload(OUT UINT32 **Payload)
Definition: Scmi.c:31
EFI_STATUS ScmiGetProtocolAttributes(IN SCMI_PROTOCOL_ID ProtocolId, OUT UINT32 **ReturnValues)
Definition: Scmi.c:222
EFI_STATUS ScmiBaseProtocolInit(IN OUT EFI_HANDLE *Handle)
STATIC EFI_STATUS BaseDiscoverListProtocols(IN SCMI_BASE_PROTOCOL *This, IN OUT UINT32 *ProtocolListSize, OUT UINT8 *ProtocolList)
EFI_STATUS BaseDiscoverSubVendor(IN SCMI_BASE_PROTOCOL *This, OUT UINT8 VendorIdentifier[SCMI_MAX_STR_LEN])
STATIC EFI_STATUS BaseDiscoverVendorDetails(IN SCMI_MESSAGE_ID_BASE MessageId, OUT UINT8 VendorIdentifier[SCMI_MAX_STR_LEN])
STATIC EFI_STATUS BaseGetTotalProtocols(IN SCMI_BASE_PROTOCOL *This, OUT UINT32 *TotalProtocols)
STATIC EFI_STATUS BaseDiscoverImplVersion(IN SCMI_BASE_PROTOCOL *This, OUT UINT32 *ImplementationVersion)
STATIC EFI_STATUS BaseGetVersion(IN SCMI_BASE_PROTOCOL *This, OUT UINT32 *Version)
STATIC EFI_STATUS BaseDiscoverVendor(IN SCMI_BASE_PROTOCOL *This, OUT UINT8 VendorIdentifier[SCMI_MAX_STR_LEN])
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS