gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
46namespace gem5
47{
48
49using namespace scmi;
50
51AgentChannel::AgentChannel(const ScmiChannelParams &p)
53 readLengthEvent([this]{ readLength(); }, name()),
54 readMessageEvent([this]{ readMessage(); }, name()),
55 handleMessageEvent([this]{ handleMessage(); }, name())
56{}
57
58void
60{
61 if (!pendingMessage) {
62 pendingMessage = true;
64 readStatus();
65 } else {
66 DPRINTF(SCMI, "Pending message\n");
67 }
68}
69
70void
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
84void
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;
96 } else {
97 // Read mailbox length
98 const auto offset = offsetof(Message, length);
99 const Addr address = shmem.start() + offset;
100
102 &readMessageEvent, (uint8_t*)&msgBuffer.length,
104 }
105}
106
107void
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
120}
121
122void
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
135PlatformChannel::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
144void
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
157
159 &clearDoorbellEvent, (uint8_t*)&msgBuffer,
161}
162
163void
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),
179}
180
181void
183{
184 DPRINTF(SCMI,
185 "SCMI Virtual channel %u, notifying agent\n",
186 virtID);
187
190 sizeof(uint32_t),
193}
194
195void
201
202Platform::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
229Port &
230Platform::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
238void
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
258void
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
280void
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
#define DPRINTF(x,...)
Definition trace.hh:210
void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, uint8_t *data, Tick delay, Request::Flags flag=0)
Generic doorbell interface.
Definition doorbell.hh:54
Addr setAddress() const
Definition doorbell.hh:61
Addr clearAddress() const
Definition doorbell.hh:62
Ports are used to interface objects to each other.
Definition port.hh:62
@ UNCACHEABLE
The request is to an uncacheable address.
Definition request.hh:125
This is a Agent to Platform channel (The agent is the initiator)
AgentChannel(const ScmiChannelParams &p)
EventFunctionWrapper handleMessageEvent
EventFunctionWrapper readLengthEvent
EventFunctionWrapper readMessageEvent
This protocol describes the properties of the implementation and provides generic error management.
This is a Platform to Agent channel (The platform is the initiator)
EventFunctionWrapper completeEvent
PlatformChannel(const ScmiChannelParams &p)
EventFunctionWrapper notifyAgentEvent
EventFunctionWrapper clearDoorbellEvent
void writeBackMessage(const Message &msg)
static uint32_t protocolID(const Message &msg)
static uint32_t messageID(const Message &msg)
AgentChannel * find(PlatformChannel *platform) const
std::vector< Communication * > comms
Port & getPort(const std::string &if_name, PortID idx) override
Get a port with a given name and index.
void handleMessage(AgentChannel *ch, Message &msg)
void raiseInterrupt(const Doorbell *doorbell) override
void clearInterrupt(const Doorbell *doorbell) override
uint32_t numProtocols() const
Returns the number of protocols implemented, except for the base protocol.
Platform(const Params &p)
Definition platform.cc:36
virtual void handleMessage(Message &msg)=0
Generic communication channel between the Agent and the Platform.
Addr start() const
Get the start address of the range.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
static const uint8_t PROTOCOL_MAX
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
output header
Definition nop.cc:36
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0