gem5  v21.1.0.2
scmi_platform.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 <stddef.h>
41 
42 #include "debug/SCMI.hh"
43 #include "dev/arm/doorbell.hh"
44 #include "mem/packet_access.hh"
45 
46 namespace gem5
47 {
48 
49 using namespace scmi;
50 
51 AgentChannel::AgentChannel(const ScmiChannelParams &p)
52  : VirtualChannel(p),
53  readLengthEvent([this]{ readLength(); }, name()),
54  readMessageEvent([this]{ readMessage(); }, name()),
55  handleMessageEvent([this]{ handleMessage(); }, name())
56 {}
57 
58 void
60 {
61  if (!pendingMessage) {
62  pendingMessage = true;
63  msgBuffer = Message();
64  readStatus();
65  } else {
66  DPRINTF(SCMI, "Pending message\n");
67  }
68 }
69 
70 void
72 {
73  const auto offset = offsetof(Message, channelStatus);
74  const Addr address = shmem.start() + offset;
75 
76  // Reading the the mailbox to check the
77  // channel status. The value will be handled by the readLength
78  // event/method
79  dmaPort->dmaAction(MemCmd::ReadReq, address, sizeof(uint32_t),
82 }
83 
84 void
86 {
87  DPRINTF(SCMI, "SCMI Virtual channel %u, channel.status: %u\n",
89 
90  // Check if the channel is busy. If it is busy it means there is a
91  // message so we need to process it. Abort the reads otherwise
92  if (msgBuffer.channelStatus & 0x1) {
93  // Channel is free: Terminate: reset message buffer
94  pendingMessage = false;
95  msgBuffer = Message();
96  } else {
97  // Read mailbox length
98  const auto offset = offsetof(Message, length);
99  const Addr address = shmem.start() + offset;
100 
101  dmaPort->dmaAction(MemCmd::ReadReq, address, sizeof(msgBuffer.length),
102  &readMessageEvent, (uint8_t*)&msgBuffer.length,
104  }
105 }
106 
107 void
109 {
110  const auto offset = offsetof(Message, header);
111  const Addr address = shmem.start() + offset;
112 
113  DPRINTF(SCMI, "SCMI Virtual channel %u, message.length: %u\n",
115 
118  &handleMessageEvent, (uint8_t*)&msgBuffer.header,
120 }
121 
122 void
124 {
125  DPRINTF(SCMI,
126  "SCMI Virtual channel %u, message.header: %#x\n",
128 
129  // Send the message to the platform which is gonna handle it
130  // We are also forwarding a pointer to the agent channel so
131  // the platform can retrieve the platform channel
133 }
134 
135 PlatformChannel::PlatformChannel(const ScmiChannelParams &p)
136  : VirtualChannel(p),
137  clearDoorbellEvent([this]{ clearDoorbell(); }, name()),
138  notifyAgentEvent([this]{ notifyAgent(); }, name()),
139  completeEvent([this]{ complete(); }, name()),
140  agentDoorbellVal(0),
141  platformDoorbellVal(0)
142 {}
143 
144 void
146 {
147  DPRINTF(SCMI,
148  "SCMI Virtual channel %u, writing back message %u"
149  " with status code: %d\n",
150  virtID, Platform::messageID(msg), msg.payload.status);
151 
152  // Field by field copy of the message
153  msgBuffer = msg;
154 
155  // Mark the channel as free in the message buffer
156  msgBuffer.channelStatus = 0x1;
157 
159  &clearDoorbellEvent, (uint8_t*)&msgBuffer,
161 }
162 
163 void
165 {
166  DPRINTF(SCMI,
167  "SCMI Virtual channel %u, clearing doorbell\n",
168  virtID);
169 
170  AgentChannel* agent_ch = platform->find(this);
171  agent_ch->pendingMessage = false;
172 
173  agentDoorbellVal = 0xffffffff;
175  agent_ch->doorbell->clearAddress(),
176  sizeof(uint32_t),
177  &notifyAgentEvent, (uint8_t*)&agentDoorbellVal,
179 }
180 
181 void
183 {
184  DPRINTF(SCMI,
185  "SCMI Virtual channel %u, notifying agent\n",
186  virtID);
187 
190  sizeof(uint32_t),
191  &completeEvent, (uint8_t*)&platformDoorbellVal,
193 }
194 
195 void
197 {
198  pendingMessage = false;
199  msgBuffer = Message();
200 }
201 
202 Platform::Platform(const ScmiPlatformParams &p)
203  : Scp(p),
204  comms(p.comms),
205  agents(p.agents),
206  protocols({ {BASE, new BaseProtocol(*this)} }),
207  dmaPort(this, p.sys)
208 {
209  for (auto comm : comms) {
210  comm->agentChan->dmaPort = &dmaPort;
211  comm->agentChan->setPlatform(this);
212 
213  comm->platformChan->dmaPort = &dmaPort;
214  comm->platformChan->setPlatform(this);
215  }
216 
218  "The number of instantiated protocols are not matching the"
219  " architected limit");
220 }
221 
223 {
224  for (auto& kv : protocols) {
225  delete kv.second;
226  }
227 }
228 
229 Port &
230 Platform::getPort(const std::string &if_name, PortID idx)
231 {
232  if (if_name == "dma") {
233  return dmaPort;
234  }
235  return Scp::getPort(if_name, idx);
236 }
237 
238 void
240 {
241  auto prot_id = protocolID(msg);
242 
243  auto it = protocols.find(prot_id);
244 
245  panic_if(it == protocols.end(),
246  "Unimplemented SCMI protocol: %u\n", prot_id);
247 
248  Protocol *protocol = it->second;
249  protocol->handleMessage(msg);
250 
251  // Find the platform channel
252  PlatformChannel *platform_ch = find(agent_ch);
253 
254  // Send the message back to the platform channel
255  platform_ch->writeBackMessage(msg);
256 }
257 
258 void
260 {
261  DPRINTF(SCMI, "Raise interrupt in SCMI platform\n");
262 
263  // Now we need to read the physical channel in the mailbox
264  // to get the virtual channel, we avoid this
265 
266  // Select the associated virtual channel with the doorbell
267  for (auto comm : comms) {
268  auto channel = comm->agentChan;
269  if (channel->doorbell == doorbell) {
270  // There is a matching virtual channel: make it
271  // start reading the message the shared memory area
272  channel->initiateRead();
273  return;
274  }
275  }
276 
277  panic("No matching virtual channel\n");
278 }
279 
280 void
282 {
283  DPRINTF(SCMI, "Clear interrupt in SCMI platform\n");
284 }
285 
288 {
289  for (auto comm : comms) {
290  if (comm->platformChan == platform) {
291  return comm->agentChan;
292  }
293  }
294 
295  return nullptr;
296 }
297 
300 {
301  for (auto comm : comms) {
302  if (comm->agentChan == agent) {
303  return comm->platformChan;
304  }
305  }
306 
307  return nullptr;
308 }
309 
310 } // namespace gem5
gem5::scmi::VirtualChannel::platform
Platform * platform
Definition: scmi_platform.hh:198
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
gem5::scmi::AgentChannel::readStatus
void readStatus()
Definition: scmi_platform.cc:71
gem5::SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:126
gem5::scmi::Protocol
Definition: scmi_protocols.hh:71
gem5::scmi::Message::channelStatus
uint32_t channelStatus
Definition: scmi_platform.hh:160
gem5::scmi::Platform::~Platform
~Platform()
Definition: scmi_platform.cc:222
gem5::AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:317
gem5::scmi::PlatformChannel
This is a Platform to Agent channel (The platform is the initiator)
Definition: scmi_platform.hh:227
gem5::scmi::PlatformChannel::notifyAgent
void notifyAgent()
Definition: scmi_platform.cc:182
gem5::scmi::Protocol::handleMessage
virtual void handleMessage(Message &msg)=0
gem5::scmi::PlatformChannel::notifyAgentEvent
EventFunctionWrapper notifyAgentEvent
Definition: scmi_platform.hh:238
gem5::Request::UNCACHEABLE
@ UNCACHEABLE
The request is to an uncacheable address.
Definition: request.hh:125
gem5::scmi::PlatformChannel::agentDoorbellVal
uint32_t agentDoorbellVal
Definition: scmi_platform.hh:242
gem5::scmi::Platform::handleMessage
void handleMessage(AgentChannel *ch, Message &msg)
Definition: scmi_platform.cc:239
gem5::scmi::PlatformChannel::PlatformChannel
PlatformChannel(const ScmiChannelParams &p)
Definition: scmi_platform.cc:135
gem5::DmaPort::dmaAction
void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, uint8_t *data, Tick delay, Request::Flags flag=0)
Definition: dma_device.cc:196
gem5::scmi::AgentChannel::readMessageEvent
EventFunctionWrapper readMessageEvent
Definition: scmi_platform.hh:220
header
output header
Definition: nop.cc:36
gem5::scmi::Message::payload
Payload payload
Definition: scmi_platform.hh:165
gem5::scmi::AgentChannel::initiateRead
void initiateRead()
Definition: scmi_platform.cc:59
gem5::scmi::VirtualChannel
Generic communication channel between the Agent and the Platform.
Definition: scmi_platform.hh:171
doorbell.hh
gem5::scmi::BaseProtocol
This protocol describes the properties of the implementation and provides generic error management.
Definition: scmi_protocols.hh:111
gem5::scmi::VirtualChannel::shmem
const AddrRange shmem
Definition: scmi_platform.hh:191
gem5::scmi::AgentChannel::readMessage
void readMessage()
Definition: scmi_platform.cc:108
gem5::scmi::AgentChannel
This is a Agent to Platform channel (The agent is the initiator)
Definition: scmi_platform.hh:207
gem5::scmi::Platform::clearInterrupt
void clearInterrupt(const Doorbell *doorbell) override
Definition: scmi_platform.cc:281
gem5::scmi::AgentChannel::handleMessage
void handleMessage()
Definition: scmi_platform.cc:123
gem5::scmi::Platform::messageID
static uint32_t messageID(const Message &msg)
Definition: scmi_platform.hh:303
gem5::scmi::PlatformChannel::writeBackMessage
void writeBackMessage(const Message &msg)
Definition: scmi_platform.cc:145
gem5::Scp
Definition: scp.hh:48
gem5::scmi::VirtualChannel::doorbell
Doorbell * doorbell
Definition: scmi_platform.hh:197
gem5::scmi::AgentChannel::handleMessageEvent
EventFunctionWrapper handleMessageEvent
Definition: scmi_platform.hh:221
gem5::scmi::PlatformChannel::complete
void complete()
Definition: scmi_platform.cc:196
gem5::scmi::Platform::find
AgentChannel * find(PlatformChannel *platform) const
Definition: scmi_platform.cc:287
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::scmi::AgentChannel::AgentChannel
AgentChannel(const ScmiChannelParams &p)
Definition: scmi_platform.cc:51
gem5::scmi::PROTOCOL_MAX
static const uint8_t PROTOCOL_MAX
Definition: scmi_platform.hh:58
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::scmi::PlatformChannel::platformDoorbellVal
uint32_t platformDoorbellVal
Definition: scmi_platform.hh:243
gem5::MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:86
gem5::scmi::Platform::Platform
Platform(const Params &p)
Definition: platform.cc:36
gem5::scmi::Platform::raiseInterrupt
void raiseInterrupt(const Doorbell *doorbell) override
Definition: scmi_platform.cc:259
gem5::Doorbell::setAddress
Addr setAddress() const
Definition: doorbell.hh:61
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::scmi::Platform::dmaPort
DmaPort dmaPort
Definition: scmi_platform.hh:329
gem5::scmi::VirtualChannel::msgBuffer
Message msgBuffer
Definition: scmi_platform.hh:188
gem5::scmi::Platform::protocolID
static uint32_t protocolID(const Message &msg)
Definition: scmi_platform.hh:297
gem5::scmi::Platform::getPort
Port & getPort(const std::string &if_name, PortID idx) override
Get a port with a given name and index.
Definition: scmi_platform.cc:230
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::scmi::AgentChannel::readLength
void readLength()
Definition: scmi_platform.cc:85
gem5::scmi::PlatformChannel::completeEvent
EventFunctionWrapper completeEvent
Definition: scmi_platform.hh:239
gem5::scmi::VirtualChannel::dmaPort
DmaPort * dmaPort
Definition: scmi_platform.hh:196
name
const std::string & name()
Definition: trace.cc:49
gem5::scmi::AgentChannel::readLengthEvent
EventFunctionWrapper readLengthEvent
Definition: scmi_platform.hh:219
packet_access.hh
gem5::scmi::PlatformChannel::clearDoorbell
void clearDoorbell()
Definition: scmi_platform.cc:164
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::Doorbell
Generic doorbell interface.
Definition: doorbell.hh:53
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::scmi::PlatformChannel::clearDoorbellEvent
EventFunctionWrapper clearDoorbellEvent
Definition: scmi_platform.hh:237
gem5::Doorbell::clearAddress
Addr clearAddress() const
Definition: doorbell.hh:62
gem5::scmi::Platform::comms
std::vector< Communication * > comms
Definition: scmi_platform.hh:324
gem5::MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:89
gem5::scmi::BASE
@ BASE
Definition: scmi_platform.hh:62
gem5::scmi::VirtualChannel::pendingMessage
bool pendingMessage
Definition: scmi_platform.hh:189
gem5::scmi::Message::header
uint32_t header
Definition: scmi_platform.hh:164
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:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::scmi::Platform::protocols
ProtocolList protocols
Definition: scmi_platform.hh:327
gem5::scmi::Platform::numProtocols
uint32_t numProtocols() const
Returns the number of protocols implemented, except for the base protocol.
Definition: scmi_platform.hh:289
gem5::scmi::Message
Definition: scmi_platform.hh:157
gem5::scmi::Message::length
uint32_t length
Definition: scmi_platform.hh:163
scmi_platform.hh
gem5::scmi::VirtualChannel::virtID
const uint32_t virtID
Definition: scmi_platform.hh:194
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177

Generated on Tue Sep 21 2021 12:25:09 for gem5 by doxygen 1.8.17