gem5  v19.0.0.0
smmu_v3_slaveifc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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  * Authors: Stan Czerniawski
38  * Giacomo Travaglini
39  */
40 
42 
43 #include "debug/SMMUv3.hh"
44 #include "dev/arm/smmu_v3.hh"
46 
48  const SMMUv3SlaveInterfaceParams *p) :
49  ClockedObject(p),
50  smmu(nullptr),
51  microTLB(new SMMUTLB(p->utlb_entries,
52  p->utlb_assoc,
53  p->utlb_policy)),
54  mainTLB(new SMMUTLB(p->tlb_entries,
55  p->tlb_assoc,
56  p->tlb_policy)),
57  microTLBEnable(p->utlb_enable),
58  mainTLBEnable(p->tlb_enable),
59  slavePortSem(1),
60  microTLBSem(p->utlb_slots),
61  mainTLBSem(p->tlb_slots),
62  microTLBLat(p->utlb_lat),
63  mainTLBLat(p->tlb_lat),
64  slavePort(new SMMUSlavePort(csprintf("%s.slave", name()), *this)),
65  atsSlavePort(name() + ".atsSlave", *this),
66  atsMasterPort(name() + ".atsMaster", *this),
67  portWidth(p->port_width),
68  wrBufSlotsRemaining(p->wrbuf_slots),
69  xlateSlotsRemaining(p->xlate_slots),
70  pendingMemAccesses(0),
71  prefetchEnable(p->prefetch_enable),
72  prefetchReserveLastWay(
73  p->prefetch_reserve_last_way),
74  deviceNeedsRetry(false),
75  atsDeviceNeedsRetry(false),
76  sendDeviceRetryEvent(*this),
77  atsSendDeviceRetryEvent(this)
78 {}
79 
80 void
82 {
83  if (slavePort->isConnected()) {
84  inform("Slave port is connected to %s\n", slavePort->getPeer());
85 
87  } else {
88  fatal("Slave port is not connected.\n");
89  }
90 }
91 
92 Port&
93 SMMUv3SlaveInterface::getPort(const std::string &name, PortID id)
94 {
95  if (name == "ats_master") {
96  return atsMasterPort;
97  } else if (name == "slave") {
98  return *slavePort;
99  } else if (name == "ats_slave") {
100  return atsSlavePort;
101  } else {
102  return ClockedObject::getPort(name, id);
103  }
104 }
105 
106 void
108 {
110 }
111 
112 void
114 {
116 
117  if (atsDeviceNeedsRetry) {
118  atsDeviceNeedsRetry = false;
120  }
121 }
122 
123 Tick
125 {
126  DPRINTF(SMMUv3, "[a] req from %s addr=%#x size=%#x\n",
127  slavePort->getPeer(), pkt->getAddr(), pkt->getSize());
128 
129  std::string proc_name = csprintf("%s.port", name());
130  SMMUTranslationProcess proc(proc_name, *smmu, *this);
132 
133  SMMUAction a = smmu->runProcessAtomic(&proc, pkt);
134  assert(a.type == ACTION_SEND_RESP);
135 
136  return a.delay;
137 }
138 
139 bool
141 {
142  DPRINTF(SMMUv3, "[t] req from %s addr=%#x size=%#x\n",
143  slavePort->getPeer(), pkt->getAddr(), pkt->getSize());
144 
145  // @todo: We need to pay for this and not just zero it out
146  pkt->headerDelay = pkt->payloadDelay = 0;
147 
148  unsigned nbeats =
149  (pkt->getSize() + (portWidth-1)) / portWidth;
150 
151  if (xlateSlotsRemaining==0 ||
152  (pkt->isWrite() && wrBufSlotsRemaining < nbeats))
153  {
154  deviceNeedsRetry = true;
155  return false;
156  }
157 
158  if (pkt->isWrite())
159  wrBufSlotsRemaining -= nbeats;
160 
161  std::string proc_name = csprintf("%s.port", name());
162  SMMUTranslationProcess *proc =
163  new SMMUTranslationProcess(proc_name, *smmu, *this);
165 
166  smmu->runProcessTiming(proc, pkt);
167 
168  return true;
169 }
170 
171 Tick
173 {
174  DPRINTF(SMMUv3, "[a] ATS slave req addr=%#x size=%#x\n",
175  pkt->getAddr(), pkt->getSize());
176 
177  std::string proc_name = csprintf("%s.atsport", name());
178  const bool ats_request = true;
180  proc_name, *smmu, *this);
181  proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request));
182 
183  SMMUAction a = smmu->runProcessAtomic(&proc, pkt);
184  assert(a.type == ACTION_SEND_RESP_ATS);
185 
186  return a.delay;
187 }
188 
189 bool
191 {
192  DPRINTF(SMMUv3, "[t] ATS slave req addr=%#x size=%#x\n",
193  pkt->getAddr(), pkt->getSize());
194 
195  // @todo: We need to pay for this and not just zero it out
196  pkt->headerDelay = pkt->payloadDelay = 0;
197 
198  if (xlateSlotsRemaining == 0) {
199  deviceNeedsRetry = true;
200  return false;
201  }
202 
203  std::string proc_name = csprintf("%s.atsport", name());
204  const bool ats_request = true;
205  SMMUTranslationProcess *proc =
206  new SMMUTranslationProcess(proc_name, *smmu, *this);
207  proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request));
208 
209  smmu->runProcessTiming(proc, pkt);
210 
211  return true;
212 }
213 
214 bool
216 {
217  DPRINTF(SMMUv3, "[t] ATS master resp addr=%#x size=%#x\n",
218  pkt->getAddr(), pkt->getSize());
219 
220  // @todo: We need to pay for this and not just zero it out
221  pkt->headerDelay = pkt->payloadDelay = 0;
222 
223  SMMUProcess *proc =
225 
226  smmu->runProcessTiming(proc, pkt);
227 
228  return true;
229 }
230 
231 void
233 {
235 }
236 
237 void
239 {
240  DPRINTF(SMMUv3, "ATS retry\n");
242 }
243 
244 void
246 {
248  DPRINTF(SMMUv3, "sched slave retry\n");
249  deviceNeedsRetry = false;
251  }
252 }
253 
256 {
257  // Wait until all SMMU translations are completed
258  if (xlateSlotsRemaining < params()->xlate_slots) {
259  return DrainState::Draining;
260  }
261  return DrainState::Drained;
262 }
263 
265 SMMUv3SlaveInterfaceParams::create()
266 {
267  return new SMMUv3SlaveInterface(this);
268 }
#define DPRINTF(x,...)
Definition: trace.hh:229
Ports are used to interface objects to each other.
Definition: port.hh:60
Tick recvAtomic(PacketPtr pkt)
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
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:286
SMMUDeviceRetryEvent sendDeviceRetryEvent
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
const std::string & name()
Definition: trace.cc:54
DrainState
Object drain/handover states.
Definition: drain.hh:71
Running normally.
Port & getPeer()
Return a reference to this port&#39;s peer.
Definition: port.hh:103
void schedAtsTimingResp(PacketPtr pkt)
Bitfield< 8 > a
SMMUATSSlavePort atsSlavePort
bool atsSlaveRecvTimingReq(PacketPtr pkt)
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
bool isWrite() const
Definition: packet.hh:529
bool recvTimingReq(PacketPtr pkt)
const SMMUv3SlaveInterfaceParams * params() const
unsigned getSize() const
Definition: packet.hh:736
friend class SMMUTranslationProcess
#define inform(...)
Definition: logging.hh:213
void beginTransaction(const SMMUTranslRequest &req)
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:162
bool atsMasterRecvTimingResp(PacketPtr pkt)
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:385
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:366
void schedTimingResp(PacketPtr pkt, Tick when)
Schedule the sending of a timing response.
Definition: qport.hh:92
uint64_t Tick
Tick count type.
Definition: types.hh:63
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
SMMUActionType type
Definition: smmu_v3_proc.hh:70
SMMUv3SlaveInterface(const SMMUv3SlaveInterfaceParams *p)
SMMUATSMasterPort atsMasterPort
Tick atsSlaveRecvAtomic(PacketPtr pkt)
Addr getAddr() const
Definition: packet.hh:726
static SMMUTranslRequest fromPacket(PacketPtr pkt, bool ats=false)
void schedTimingResp(PacketPtr pkt)
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
Draining buffers pending serialization/handover.
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:384
virtual const std::string name() const
Definition: sim_object.hh:120
T safe_cast(U ptr)
Definition: cast.hh:61
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
This is an implementation of the SMMUv3 architecture.
SMMUAction runProcessTiming(SMMUProcess *proc, PacketPtr pkt)
Definition: smmu_v3.cc:282
void sendRetryReq()
Send a retry to the master port that previously attempted a sendTimingReq to this slave port and fail...
Definition: port.hh:380
DrainState drain() override
Notify an object that it needs to drain its state.
const unsigned portWidth
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:327
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
EventWrapper< SMMUv3SlaveInterface, &SMMUv3SlaveInterface::atsSendDeviceRetry > atsSendDeviceRetryEvent
Bitfield< 0 > p
Port & getPort(const std::string &name, PortID id) override
Get a port with a given name and index.
SMMUAction runProcessAtomic(SMMUProcess *proc, PacketPtr pkt)
Definition: smmu_v3.cc:233
SMMUSlavePort * slavePort

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13