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

Generated on Mon Jun 8 2020 15:45:10 for gem5 by doxygen 1.8.13