gem5  v20.0.0.0
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 "debug/SMMUv3.hh"
41 #include "dev/arm/smmu_v3.hh"
43 
45  const SMMUv3SlaveInterfaceParams *p) :
46  ClockedObject(p),
47  smmu(nullptr),
48  microTLB(new SMMUTLB(p->utlb_entries,
49  p->utlb_assoc,
50  p->utlb_policy)),
51  mainTLB(new SMMUTLB(p->tlb_entries,
52  p->tlb_assoc,
53  p->tlb_policy)),
54  microTLBEnable(p->utlb_enable),
55  mainTLBEnable(p->tlb_enable),
56  slavePortSem(1),
57  microTLBSem(p->utlb_slots),
58  mainTLBSem(p->tlb_slots),
59  microTLBLat(p->utlb_lat),
60  mainTLBLat(p->tlb_lat),
61  slavePort(new SMMUSlavePort(csprintf("%s.slave", name()), *this)),
62  atsSlavePort(name() + ".atsSlave", *this),
63  atsMasterPort(name() + ".atsMaster", *this),
64  portWidth(p->port_width),
65  wrBufSlotsRemaining(p->wrbuf_slots),
66  xlateSlotsRemaining(p->xlate_slots),
67  pendingMemAccesses(0),
68  prefetchEnable(p->prefetch_enable),
69  prefetchReserveLastWay(
70  p->prefetch_reserve_last_way),
71  deviceNeedsRetry(false),
72  atsDeviceNeedsRetry(false),
73  sendDeviceRetryEvent(*this),
74  atsSendDeviceRetryEvent(this)
75 {}
76 
77 void
79 {
80  if (slavePort->isConnected()) {
81  inform("Slave port is connected to %s\n", slavePort->getPeer());
82 
84  } else {
85  fatal("Slave port is not connected.\n");
86  }
87 }
88 
89 Port&
90 SMMUv3SlaveInterface::getPort(const std::string &name, PortID id)
91 {
92  if (name == "ats_master") {
93  return atsMasterPort;
94  } else if (name == "slave") {
95  return *slavePort;
96  } else if (name == "ats_slave") {
97  return atsSlavePort;
98  } else {
99  return ClockedObject::getPort(name, id);
100  }
101 }
102 
103 void
105 {
107 }
108 
109 void
111 {
113 
114  if (atsDeviceNeedsRetry) {
115  atsDeviceNeedsRetry = false;
117  }
118 }
119 
120 Tick
122 {
123  DPRINTF(SMMUv3, "[a] req from %s addr=%#x size=%#x\n",
124  slavePort->getPeer(), pkt->getAddr(), pkt->getSize());
125 
126  std::string proc_name = csprintf("%s.port", name());
127  SMMUTranslationProcess proc(proc_name, *smmu, *this);
129 
130  SMMUAction a = smmu->runProcessAtomic(&proc, pkt);
131  assert(a.type == ACTION_SEND_RESP);
132 
133  return a.delay;
134 }
135 
136 bool
138 {
139  DPRINTF(SMMUv3, "[t] req from %s addr=%#x size=%#x\n",
140  slavePort->getPeer(), pkt->getAddr(), pkt->getSize());
141 
142  // @todo: We need to pay for this and not just zero it out
143  pkt->headerDelay = pkt->payloadDelay = 0;
144 
145  unsigned nbeats =
146  (pkt->getSize() + (portWidth-1)) / portWidth;
147 
148  if (xlateSlotsRemaining==0 ||
149  (pkt->isWrite() && wrBufSlotsRemaining < nbeats))
150  {
151  deviceNeedsRetry = true;
152  return false;
153  }
154 
155  if (pkt->isWrite())
156  wrBufSlotsRemaining -= nbeats;
157 
158  std::string proc_name = csprintf("%s.port", name());
159  SMMUTranslationProcess *proc =
160  new SMMUTranslationProcess(proc_name, *smmu, *this);
162 
163  smmu->runProcessTiming(proc, pkt);
164 
165  return true;
166 }
167 
168 Tick
170 {
171  DPRINTF(SMMUv3, "[a] ATS slave req addr=%#x size=%#x\n",
172  pkt->getAddr(), pkt->getSize());
173 
174  std::string proc_name = csprintf("%s.atsport", name());
175  const bool ats_request = true;
177  proc_name, *smmu, *this);
178  proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request));
179 
180  SMMUAction a = smmu->runProcessAtomic(&proc, pkt);
181  assert(a.type == ACTION_SEND_RESP_ATS);
182 
183  return a.delay;
184 }
185 
186 bool
188 {
189  DPRINTF(SMMUv3, "[t] ATS slave req addr=%#x size=%#x\n",
190  pkt->getAddr(), pkt->getSize());
191 
192  // @todo: We need to pay for this and not just zero it out
193  pkt->headerDelay = pkt->payloadDelay = 0;
194 
195  if (xlateSlotsRemaining == 0) {
196  deviceNeedsRetry = true;
197  return false;
198  }
199 
200  std::string proc_name = csprintf("%s.atsport", name());
201  const bool ats_request = true;
202  SMMUTranslationProcess *proc =
203  new SMMUTranslationProcess(proc_name, *smmu, *this);
204  proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request));
205 
206  smmu->runProcessTiming(proc, pkt);
207 
208  return true;
209 }
210 
211 bool
213 {
214  DPRINTF(SMMUv3, "[t] ATS master resp addr=%#x size=%#x\n",
215  pkt->getAddr(), pkt->getSize());
216 
217  // @todo: We need to pay for this and not just zero it out
218  pkt->headerDelay = pkt->payloadDelay = 0;
219 
220  SMMUProcess *proc =
222 
223  smmu->runProcessTiming(proc, pkt);
224 
225  return true;
226 }
227 
228 void
230 {
232 }
233 
234 void
236 {
237  DPRINTF(SMMUv3, "ATS retry\n");
239 }
240 
241 void
243 {
245  DPRINTF(SMMUv3, "sched slave retry\n");
246  deviceNeedsRetry = false;
248  }
249 }
250 
253 {
254  // Wait until all SMMU translations are completed
255  if (xlateSlotsRemaining < params()->xlate_slots) {
256  return DrainState::Draining;
257  }
258  return DrainState::Drained;
259 }
260 
262 SMMUv3SlaveInterfaceParams::create()
263 {
264  return new SMMUv3SlaveInterface(this);
265 }
#define DPRINTF(x,...)
Definition: trace.hh:225
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:934
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:459
This is an implementation of the SMMUv3 architecture.
virtual const std::string name() const
Definition: sim_object.hh:129
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 Thu May 28 2020 16:21:32 for gem5 by doxygen 1.8.13