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

Generated on Tue Jun 22 2021 15:28:27 for gem5 by doxygen 1.8.17