gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
scmi_protocols.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
39 
40 #include "debug/SCMI.hh"
42 
43 using namespace SCMI;
44 
45 const std::string
47 {
48  return platform.name();
49 }
50 
52  : Protocol(_platform),
53  vendor(platform.params().base_vendor),
54  subvendor(platform.params().base_subvendor),
55  implementationVersion(platform.params().base_impl_version)
56 {
57  fatal_if(vendor.length() > MAX_STRING_SIZE,
58  "Invalid BASE_PROTOCOL VENDOR size\n");
60  "Invalid BASE_PROTOCOL SUBVENDOR size\n");
61 }
62 
63 void
65 {
66  auto message_id = Platform::messageID(msg);
67 
68  DPRINTF(SCMI, "Handling SCMI message:\n");
69  DPRINTF(SCMI, "# Message Protocol = BASE_PROTOCOL\n");
70  DPRINTF(SCMI, "# Message ID = %u\n", message_id);
71 
72  switch (static_cast<Commands>(message_id)) {
73  case Commands::VERSION:
74  version(msg);
75  break;
77  attributes(msg);
78  break;
80  messageAttributes(msg);
81  break;
83  discoverVendor(msg);
84  break;
86  discoverSubVendor(msg);
87  break;
90  break;
93  break;
95  discoverAgent(msg);
96  break;
101  default:
102  invalidCommand(msg);
103  warn("Unimplemented SCMI command: %u\n", message_id);
104  }
105 }
106 
107 void
109 {
110  auto& payload = msg.payload.baseProtocolVersion;
111  payload.status = SUCCESS;
112  payload.version = PROTOCOL_VERSION;
113 
114  // header + status + return
115  msg.length = sizeof(uint32_t) * 3;
116 }
117 
118 void
120 {
121  uint32_t _attributes = 0;
122 
123  replaceBits(_attributes, 15, 8, platform.numAgents());
124  replaceBits(_attributes, 7, 0, platform.numProtocols());
125 
126  auto& payload = msg.payload.baseProtocolAttributes;
127  payload.status = SUCCESS;
128  payload.attributes = _attributes;
129 
130  // header + status + return
131  msg.length = sizeof(uint32_t) * 3;
132 }
133 
134 bool
136 {
137  switch (message_id) {
138  case Commands::VERSION:
146  return true;
147  default:
148  return false;
149  }
150 }
151 
152 void
154 {
155  auto& payload = msg.payload.baseProtocolMessageAttributes;
156  const auto message_id = static_cast<Commands>(
157  payload.messageId);
158 
159  if (!implementedProtocol(message_id)) {
160  payload.status = NOT_FOUND;
161  } else {
162  payload.status = SUCCESS;
163  }
164 
165  // For all messages in the Base protocol, 0 must be returned
166  payload.attributes = 0;
167 
168  // header + status + return
169  msg.length = sizeof(uint32_t) * 3;
170 }
171 
172 void
174 {
175  auto& payload = msg.payload.baseDiscoverVendor;
176  payload.status = SUCCESS;
177 
178  auto vendor_size = vendor.copy(
179  (char*)&payload.vendorIdentifier, MAX_STRING_SIZE);
180 
181  // header + status + payload
182  msg.length = sizeof(uint32_t) * 2 + vendor_size;
183 }
184 
185 void
187 {
188  auto& payload = msg.payload.baseDiscoverSubVendor;
189  payload.status = SUCCESS;
190 
191  auto subvendor_size = subvendor.copy(
192  (char*)&payload.vendorIdentifier, MAX_STRING_SIZE);
193 
194  // header + status + payload
195  msg.length = sizeof(uint32_t) * 2 + subvendor_size;
196 }
197 
198 void
200 {
201  auto& payload = msg.payload.baseDiscoverImplementationVersion;
202  payload.status = SUCCESS;
203  payload.implementationVersion = implementationVersion;
204 
205  // header + status + return
206  msg.length = sizeof(uint32_t) * 3;
207 }
208 
209 void
211 {
212  auto& payload = msg.payload.baseDiscoverListProtocols;
213  const uint32_t skip = payload.skip;
214  const auto num_protocols = platform.numProtocols();
215 
216  if (skip > num_protocols) {
217  payload.status = INVALID_PARAMETERS;
218  msg.length = sizeof(uint32_t) * 2;
219 
220  } else {
221  const auto& protocol_list = platform.protocolList();
222  auto *protocols = (uint8_t*)payload.protocols;
223  uint32_t num_implemented = 0;
224 
225  for (auto protoc_id = START + skip; protoc_id <= END; protoc_id++) {
226  auto it = protocol_list.find(protoc_id);
227  if (it != protocol_list.end()) {
228  num_implemented++;
229 
230  *protocols = it->first;
231  protocols++;
232  }
233  }
234 
235  payload.status = SUCCESS;
236  payload.numProtocols = num_implemented;
237 
238  // header + status + return
239  msg.length = sizeof(uint32_t) * 3;
240  }
241 }
242 
243 void
245 {
246  auto& payload = msg.payload.baseDiscoverAgent;
247  const uint32_t agent_id = payload.agentId;
248 
249  if (agent_id > platform.numAgents()) {
250  payload.status = NOT_FOUND;
251  msg.length = sizeof(uint32_t) * 2;
252 
253  } else {
254  auto agent_size = 0;
255  auto agent_name = std::string();
256 
257  if (agent_id) {
258  // Subtracting one to the agent_id, since agent_id 0 is reserved
259  // for the platform.
260  agent_name = platform.getAgent(agent_id - 1);
261  } else {
262  agent_name = "platform";
263  }
264 
265  agent_size = agent_name.length();
266 
267  strncpy((char *)&payload.name,
268  agent_name.c_str(), agent_size);
269 
270  payload.status = SUCCESS;
271  // header + status + payload
272  msg.length = sizeof(uint32_t) * 2 + agent_size;
273  }
274 }
275 
276 void
278 {
279  auto& payload = msg.payload.invalidCommand;
280  payload.status = NOT_FOUND;
281  msg.length = sizeof(uint32_t) * 2;
282 }
SCMI::START
@ START
Definition: scmi_platform.hh:60
SCMI::Protocol
Definition: scmi_protocols.hh:65
SCMI::BaseProtocol::vendor
const std::string vendor
Definition: scmi_protocols.hh:145
warn
#define warn(...)
Definition: logging.hh:239
SCMI::BaseProtocol::Commands::DISCOVER_SUB_VENDOR
@ DISCOVER_SUB_VENDOR
SCMI::SUCCESS
@ SUCCESS
Definition: scmi_protocols.hh:52
SCMI::INVALID_PARAMETERS
@ INVALID_PARAMETERS
Definition: scmi_protocols.hh:54
SCMI::Protocol::name
const std::string name() const
Definition: scmi_protocols.cc:46
SCMI::BaseProtocol::Commands::DISCOVER_IMPLEMENTATION_VERSION
@ DISCOVER_IMPLEMENTATION_VERSION
SCMI::BaseProtocol::BaseProtocol
BaseProtocol(Platform &_platform)
Definition: scmi_protocols.cc:51
SCMI::BaseProtocol::Commands::SET_DEVICE_PERMISSIONS
@ SET_DEVICE_PERMISSIONS
SCMI::BaseProtocol::Commands::DISCOVER_LIST_PROTOCOLS
@ DISCOVER_LIST_PROTOCOLS
SCMI::BaseProtocol::implementationVersion
const uint32_t implementationVersion
Definition: scmi_protocols.hh:147
SCMI::Message::payload
Payload payload
Definition: scmi_platform.hh:162
SCMI::BaseProtocol::discoverImplVersion
void discoverImplVersion(Message &msg)
Definition: scmi_protocols.cc:199
SCMI::BaseProtocol::Commands::RESET_AGENT_CONFIGURATION
@ RESET_AGENT_CONFIGURATION
SCMI::Platform::getAgent
const char * getAgent(unsigned index) const
Returns the name of an agent given an index.
Definition: scmi_platform.hh:277
SCMI::Platform::numAgents
uint32_t numAgents() const
Returns the number of agents in the system.
Definition: scmi_platform.hh:273
SCMI::Platform::messageID
static uint32_t messageID(const Message &msg)
Definition: scmi_platform.hh:300
SCMI::Platform::numProtocols
uint32_t numProtocols() const
Returns the number of protocols implemented, except for the base protocol.
Definition: scmi_platform.hh:286
SCMI::BaseProtocol::implementedProtocol
bool implementedProtocol(Commands message_id) const
Definition: scmi_protocols.cc:135
SCMI::BaseProtocol::PROTOCOL_VERSION
static const uint32_t PROTOCOL_VERSION
Definition: scmi_protocols.hh:107
SCMI::BaseProtocol::Commands::VERSION
@ VERSION
SCMI::Platform
Definition: scmi_platform.hh:261
SCMI::BaseProtocol::discoverAgent
void discoverAgent(Message &msg)
Definition: scmi_protocols.cc:244
SCMI::BaseProtocol::Commands::SET_PROTOCOL_PERMISSIONS
@ SET_PROTOCOL_PERMISSIONS
SCMI::Protocol::MAX_STRING_SIZE
static const uint32_t MAX_STRING_SIZE
Definition: scmi_protocols.hh:71
scmi_protocols.hh
SCMI::Message::length
uint32_t length
Definition: scmi_platform.hh:160
SCMI::Protocol::platform
Platform & platform
Definition: scmi_protocols.hh:90
SCMI::BaseProtocol::discoverListProtocols
void discoverListProtocols(Message &msg)
Definition: scmi_protocols.cc:210
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
SCMI::BaseProtocol::subvendor
const std::string subvendor
Definition: scmi_protocols.hh:146
SCMI::NOT_FOUND
@ NOT_FOUND
Definition: scmi_protocols.hh:56
SCMI::BaseProtocol::Commands::MESSAGE_ATTRIBUTES
@ MESSAGE_ATTRIBUTES
SCMI::BaseProtocol::messageAttributes
void messageAttributes(Message &msg) override
Definition: scmi_protocols.cc:153
SCMI::BaseProtocol::discoverVendor
void discoverVendor(Message &msg)
Definition: scmi_protocols.cc:173
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
SCMI::BaseProtocol::discoverSubVendor
void discoverSubVendor(Message &msg)
Definition: scmi_protocols.cc:186
SCMI::BaseProtocol::invalidCommand
void invalidCommand(Message &msg)
Definition: scmi_protocols.cc:277
SCMI::BaseProtocol::Commands::NOTIFY_ERRORS
@ NOTIFY_ERRORS
SCMI::BaseProtocol::Commands::DISCOVER_AGENT
@ DISCOVER_AGENT
SCMI::BaseProtocol::version
void version(Message &msg) override
Definition: scmi_protocols.cc:108
SCMI::Platform::protocolList
const ProtocolList & protocolList() const
Definition: scmi_platform.hh:312
SCMI::Message
Definition: scmi_platform.hh:154
SCMI::BaseProtocol::Commands
Commands
Definition: scmi_protocols.hh:112
SCMI::END
@ END
Definition: scmi_platform.hh:66
SCMI::BaseProtocol::handleMessage
void handleMessage(Message &msg) override
Definition: scmi_protocols.cc:64
SCMI::BaseProtocol::Commands::ATTRIBUTES
@ ATTRIBUTES
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
SCMI
Definition: scmi_platform.hh:49
scmi_platform.hh
SCMI::BaseProtocol::attributes
void attributes(Message &msg) override
Definition: scmi_protocols.cc:119
SCMI::BaseProtocol::Commands::DISCOVER_VENDOR
@ DISCOVER_VENDOR
replaceBits
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition: bitfield.hh:174

Generated on Tue Mar 23 2021 19:41:25 for gem5 by doxygen 1.8.17