TianoCore EDK2 master
Loading...
Searching...
No Matches
Scmi.c
Go to the documentation of this file.
1
12#include <Library/ArmMtlLib.h>
13#include <Library/DebugLib.h>
16
17#include "ScmiPrivate.h"
18
19// Arbitrary timeout value 20ms.
20#define RESPONSE_TIMEOUT 20000
21
32 OUT UINT32 **Payload
33 )
34{
35 EFI_STATUS Status;
36 MTL_CHANNEL *Channel;
37
38 // Get handle to the Channel.
39 Status = MtlGetChannel (MTL_CHANNEL_TYPE_LOW, &Channel);
40 if (EFI_ERROR (Status)) {
41 return Status;
42 }
43
44 // Payload will not be populated until channel is free.
45 Status = MtlWaitUntilChannelFree (Channel, RESPONSE_TIMEOUT);
46 if (EFI_ERROR (Status)) {
47 return Status;
48 }
49
50 // Get the address of the payload.
51 *Payload = MtlGetChannelPayload (Channel);
52
53 return EFI_SUCCESS;
54}
55
77 IN SCMI_COMMAND *Command,
78 IN OUT UINT32 *PayloadLength,
79 OUT UINT32 **ReturnValues OPTIONAL
80 )
81{
82 EFI_STATUS Status;
83 SCMI_MESSAGE_RESPONSE *Response;
84 UINT32 MessageHeader;
85 UINT32 ResponseHeader;
86 MTL_CHANNEL *Channel;
87
88 ASSERT (PayloadLength != NULL);
89
90 Status = MtlGetChannel (MTL_CHANNEL_TYPE_LOW, &Channel);
91 if (EFI_ERROR (Status)) {
92 return Status;
93 }
94
95 // Fill in message header.
96 MessageHeader = SCMI_MESSAGE_HEADER (
97 Command->MessageId,
98 ScmiMessageTypeCommand,
99 Command->ProtocolId
100 );
101
102 // Send payload using MTL channel.
103 Status = MtlSendMessage (
104 Channel,
105 MessageHeader,
106 *PayloadLength
107 );
108 if (EFI_ERROR (Status)) {
109 return Status;
110 }
111
112 // Wait for the response on the channel.
113 Status = MtlReceiveMessage (Channel, &ResponseHeader, PayloadLength);
114 if (EFI_ERROR (Status)) {
115 return Status;
116 }
117
118 // SCMI must return MessageHeader unmodified.
119 if (MessageHeader != ResponseHeader) {
120 ASSERT (FALSE);
121 return EFI_DEVICE_ERROR;
122 }
123
124 Response = (SCMI_MESSAGE_RESPONSE *)MtlGetChannelPayload (Channel);
125
126 if (Response->Status != ScmiSuccess) {
127 DEBUG ((
128 DEBUG_ERROR,
129 "SCMI error: ProtocolId = 0x%x, MessageId = 0x%x, error = %d\n",
130 Command->ProtocolId,
131 Command->MessageId,
132 Response->Status
133 ));
134
135 ASSERT (FALSE);
136 return EFI_DEVICE_ERROR;
137 }
138
139 if (ReturnValues != NULL) {
140 *ReturnValues = Response->ReturnValues;
141 }
142
143 return EFI_SUCCESS;
144}
145
157STATIC
160 IN SCMI_PROTOCOL_ID ProtocolId,
161 IN SCMI_MESSAGE_ID MessageId,
162 OUT UINT32 **ReturnValues
163 )
164{
165 SCMI_COMMAND Command;
166 UINT32 PayloadLength;
167
168 PayloadLength = 0;
169 Command.ProtocolId = ProtocolId;
170 Command.MessageId = MessageId;
171
172 return ScmiCommandExecute (
173 &Command,
174 &PayloadLength,
175 ReturnValues
176 );
177}
178
191 IN SCMI_PROTOCOL_ID ProtocolId,
192 OUT UINT32 *Version
193 )
194{
195 EFI_STATUS Status;
196 UINT32 *ProtocolVersion;
197
199 ProtocolId,
200 ScmiMessageIdProtocolVersion,
201 (UINT32 **)&ProtocolVersion
202 );
203 if (EFI_ERROR (Status)) {
204 return Status;
205 }
206
207 *Version = *ProtocolVersion;
208
209 return EFI_SUCCESS;
210}
211
223 IN SCMI_PROTOCOL_ID ProtocolId,
224 OUT UINT32 **ReturnValues
225 )
226{
228 ProtocolId,
229 ScmiMessageIdProtocolAttributes,
230 ReturnValues
231 );
232}
233
245 IN SCMI_PROTOCOL_ID ProtocolId,
246 OUT UINT32 **ReturnValues
247 )
248{
250 ProtocolId,
251 ScmiMessageIdProtocolMessageAttributes,
252 ReturnValues
253 );
254}
EFI_STATUS MtlGetChannel(IN MTL_CHANNEL_TYPE ChannelType, OUT MTL_CHANNEL **Channel)
Definition: ArmMtlNullLib.c:58
EFI_STATUS MtlReceiveMessage(IN MTL_CHANNEL *Channel, OUT UINT32 *MessageHeader, OUT UINT32 *PayloadLength)
Definition: ArmMtlNullLib.c:95
EFI_STATUS MtlWaitUntilChannelFree(IN MTL_CHANNEL *Channel, IN UINTN TimeOutInMicroSeconds)
Definition: ArmMtlNullLib.c:23
EFI_STATUS MtlSendMessage(IN MTL_CHANNEL *Channel, IN UINT32 MessageHeader, OUT UINT32 PayloadLength)
Definition: ArmMtlNullLib.c:76
UINT32 * MtlGetChannelPayload(IN MTL_CHANNEL *Channel)
Definition: ArmMtlNullLib.c:38
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS ScmiGetProtocolVersion(IN SCMI_PROTOCOL_ID ProtocolId, OUT UINT32 *Version)
Definition: Scmi.c:190
EFI_STATUS ScmiGetProtocolMessageAttributes(IN SCMI_PROTOCOL_ID ProtocolId, OUT UINT32 **ReturnValues)
Definition: Scmi.c:244
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
STATIC EFI_STATUS ScmiProtocolDiscoveryCommon(IN SCMI_PROTOCOL_ID ProtocolId, IN SCMI_MESSAGE_ID MessageId, OUT UINT32 **ReturnValues)
Definition: Scmi.c:159
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112