gem5  v20.1.0.0
smmu_v3_deviceifc.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 SMMUv3DeviceInterfaceParams *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  devicePortSem(1),
58  microTLBSem(p->utlb_slots),
59  mainTLBSem(p->tlb_slots),
60  microTLBLat(p->utlb_lat),
61  mainTLBLat(p->tlb_lat),
62  devicePort(new SMMUDevicePort(csprintf("%s.device_port",
63  name()), *this)),
64  atsDevicePort(name() + ".atsDevicePort", *this),
65  atsMemPort(name() + ".atsMemPort", *this),
66  portWidth(p->port_width),
67  wrBufSlotsRemaining(p->wrbuf_slots),
68  xlateSlotsRemaining(p->xlate_slots),
69  pendingMemAccesses(0),
70  prefetchEnable(p->prefetch_enable),
71  prefetchReserveLastWay(
72  p->prefetch_reserve_last_way),
73  deviceNeedsRetry(false),
74  atsDeviceNeedsRetry(false),
75  sendDeviceRetryEvent(*this),
76  atsSendDeviceRetryEvent(this)
77 {}
78 
79 void
81 {
82  if (devicePort->isConnected()) {
83  inform("Device port is connected to %s\n", devicePort->getPeer());
84 
86  } else {
87  fatal("Device port is not connected.\n");
88  }
89 }
90 
91 Port&
93 {
94  if (name == "ats_mem_side_port") {
95  return atsMemPort;
96  } else if (name == "device_port") {
97  return *devicePort;
98  } else if (name == "ats_dev_side_port") {
99  return atsDevicePort;
100  } else {
101  return ClockedObject::getPort(name, id);
102  }
103 }
104 
105 void
107 {
109 }
110 
111 void
113 {
115 
116  if (atsDeviceNeedsRetry) {
117  atsDeviceNeedsRetry = false;
119  }
120 }
121 
122 Tick
124 {
125  DPRINTF(SMMUv3, "[a] req from %s addr=%#x size=%#x\n",
126  devicePort->getPeer(), pkt->getAddr(), pkt->getSize());
127 
128  std::string proc_name = csprintf("%s.port", name());
129  SMMUTranslationProcess proc(proc_name, *smmu, *this);
131 
132  SMMUAction a = smmu->runProcessAtomic(&proc, pkt);
133  assert(a.type == ACTION_SEND_RESP);
134 
135  return a.delay;
136 }
137 
138 bool
140 {
141  DPRINTF(SMMUv3, "[t] req from %s addr=%#x size=%#x\n",
142  devicePort->getPeer(), pkt->getAddr(), pkt->getSize());
143 
144  // @todo: We need to pay for this and not just zero it out
145  pkt->headerDelay = pkt->payloadDelay = 0;
146 
147  unsigned nbeats =
148  (pkt->getSize() + (portWidth-1)) / portWidth;
149 
150  if (xlateSlotsRemaining==0 ||
151  (pkt->isWrite() && wrBufSlotsRemaining < nbeats))
152  {
153  deviceNeedsRetry = true;
154  return false;
155  }
156 
157  if (pkt->isWrite())
158  wrBufSlotsRemaining -= nbeats;
159 
160  std::string proc_name = csprintf("%s.port", name());
161  SMMUTranslationProcess *proc =
162  new SMMUTranslationProcess(proc_name, *smmu, *this);
164 
165  smmu->runProcessTiming(proc, pkt);
166 
167  return true;
168 }
169 
170 Tick
172 {
173  DPRINTF(SMMUv3, "[a] ATS responder req addr=%#x size=%#x\n",
174  pkt->getAddr(), pkt->getSize());
175 
176  std::string proc_name = csprintf("%s.atsport", name());
177  const bool ats_request = true;
179  proc_name, *smmu, *this);
180  proc.beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request));
181 
182  SMMUAction a = smmu->runProcessAtomic(&proc, pkt);
183  assert(a.type == ACTION_SEND_RESP_ATS);
184 
185  return a.delay;
186 }
187 
188 bool
190 {
191  DPRINTF(SMMUv3, "[t] ATS responder req addr=%#x size=%#x\n",
192  pkt->getAddr(), pkt->getSize());
193 
194  // @todo: We need to pay for this and not just zero it out
195  pkt->headerDelay = pkt->payloadDelay = 0;
196 
197  if (xlateSlotsRemaining == 0) {
198  deviceNeedsRetry = true;
199  return false;
200  }
201 
202  std::string proc_name = csprintf("%s.atsport", name());
203  const bool ats_request = true;
204  SMMUTranslationProcess *proc =
205  new SMMUTranslationProcess(proc_name, *smmu, *this);
206  proc->beginTransaction(SMMUTranslRequest::fromPacket(pkt, ats_request));
207 
208  smmu->runProcessTiming(proc, pkt);
209 
210  return true;
211 }
212 
213 bool
215 {
216  DPRINTF(SMMUv3, "[t] ATS requestor resp addr=%#x size=%#x\n",
217  pkt->getAddr(), pkt->getSize());
218 
219  // @todo: We need to pay for this and not just zero it out
220  pkt->headerDelay = pkt->payloadDelay = 0;
221 
222  SMMUProcess *proc =
223  safe_cast<SMMUProcess *>(pkt->popSenderState());
224 
225  smmu->runProcessTiming(proc, pkt);
226 
227  return true;
228 }
229 
230 void
232 {
234 }
235 
236 void
238 {
239  DPRINTF(SMMUv3, "ATS retry\n");
241 }
242 
243 void
245 {
247  DPRINTF(SMMUv3, "sched responder retry\n");
248  deviceNeedsRetry = false;
250  }
251 }
252 
255 {
256  // Wait until all SMMU translations are completed
257  if (xlateSlotsRemaining < params()->xlate_slots) {
258  return DrainState::Draining;
259  }
260  return DrainState::Drained;
261 }
262 
264 SMMUv3DeviceInterfaceParams::create()
265 {
266  return new SMMUv3DeviceInterface(this);
267 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
SMMUv3DeviceInterface::atsDevicePort
SMMUATSDevicePort atsDevicePort
Definition: smmu_v3_deviceifc.hh:76
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:460
SMMUv3DeviceInterface::schedTimingResp
void schedTimingResp(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:106
SMMUv3DeviceInterface::drain
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: smmu_v3_deviceifc.cc:254
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
SMMUv3DeviceInterface::smmu
SMMUv3 * smmu
Definition: smmu_v3_deviceifc.hh:61
Packet::payloadDelay
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:412
SMMUProcess
Definition: smmu_v3_proc.hh:93
SMMUv3DeviceInterface::devicePort
SMMUDevicePort * devicePort
Definition: smmu_v3_deviceifc.hh:75
SMMUv3DeviceInterface::wrBufSlotsRemaining
unsigned wrBufSlotsRemaining
Definition: smmu_v3_deviceifc.hh:82
smmu_v3_transl.hh
SMMUv3DeviceInterface::atsRecvTimingResp
bool atsRecvTimingResp(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:214
SMMUv3DeviceInterface::recvTimingReq
bool recvTimingReq(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:139
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
SMMUv3DeviceInterface::sendDeviceRetryEvent
SMMUDeviceRetryEvent sendDeviceRetryEvent
Definition: smmu_v3_deviceifc.hh:113
SMMUv3DeviceInterface::SMMUv3DeviceInterface
SMMUv3DeviceInterface(const SMMUv3DeviceInterfaceParams *p)
Definition: smmu_v3_deviceifc.cc:45
SMMUv3::runProcessTiming
SMMUAction runProcessTiming(SMMUProcess *proc, PacketPtr pkt)
Definition: smmu_v3.cc:280
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
SMMUv3DeviceInterface::atsMemPort
SMMUATSMemoryPort atsMemPort
Definition: smmu_v3_deviceifc.hh:77
QueuedResponsePort::schedTimingResp
void schedTimingResp(PacketPtr pkt, Tick when)
Schedule the sending of a timing response.
Definition: qport.hh:90
Packet::headerDelay
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:394
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
SMMUv3DeviceInterface
Definition: smmu_v3_deviceifc.hh:55
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
SMMUv3::runProcessAtomic
SMMUAction runProcessAtomic(SMMUProcess *proc, PacketPtr pkt)
Definition: smmu_v3.cc:231
SMMUv3DeviceInterface::sendRange
void sendRange()
Definition: smmu_v3_deviceifc.cc:80
SMMUv3DeviceInterface::SMMUTranslationProcess
friend class SMMUTranslationProcess
Definition: smmu_v3_deviceifc.hh:58
SMMUv3DeviceInterface::deviceNeedsRetry
bool deviceNeedsRetry
Definition: smmu_v3_deviceifc.hh:110
SMMUDevicePort
Definition: smmu_v3_ports.hh:74
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
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:123
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
SMMUTranslRequest::fromPacket
static SMMUTranslRequest fromPacket(PacketPtr pkt, bool ats=false)
Definition: smmu_v3_transl.cc:47
SMMUTLB
Definition: smmu_v3_caches.hh:90
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
SMMUAction
Definition: smmu_v3_proc.hh:66
ACTION_SEND_RESP_ATS
@ ACTION_SEND_RESP_ATS
Definition: smmu_v3_proc.hh:60
smmu_v3_deviceifc.hh
name
const std::string & name()
Definition: trace.cc:50
SMMUv3DeviceInterface::getPort
Port & getPort(const std::string &name, PortID id) override
Get a port with a given name and index.
Definition: smmu_v3_deviceifc.cc:92
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
SMMUv3DeviceInterface::atsRecvAtomic
Tick atsRecvAtomic(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:171
SMMUv3DeviceInterface::schedAtsTimingResp
void schedAtsTimingResp(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:112
smmu_v3.hh
inform
#define inform(...)
Definition: logging.hh:240
SMMUv3DeviceInterface::xlateSlotsRemaining
unsigned xlateSlotsRemaining
Definition: smmu_v3_deviceifc.hh:83
SMMUv3DeviceInterface::recvAtomic
Tick recvAtomic(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:123
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
SMMUTranslationProcess
Definition: smmu_v3_transl.hh:63
SMMUv3DeviceInterface::params
const SMMUv3DeviceInterfaceParams * params() const
Definition: smmu_v3_deviceifc.hh:130
SMMUv3DeviceInterface::atsRecvTimingReq
bool atsRecvTimingReq(PacketPtr pkt)
Definition: smmu_v3_deviceifc.cc:189
Packet::popSenderState
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:340
SMMUv3DeviceInterface::atsSendDeviceRetryEvent
EventWrapper< SMMUv3DeviceInterface, &SMMUv3DeviceInterface::atsSendDeviceRetry > atsSendDeviceRetryEvent
Definition: smmu_v3_deviceifc.hh:116
Port::getPeer
Port & getPeer()
Return a reference to this port's peer.
Definition: port.hh:103
Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
SMMUv3DeviceInterface::atsDeviceNeedsRetry
bool atsDeviceNeedsRetry
Definition: smmu_v3_deviceifc.hh:111
Packet::isWrite
bool isWrite() const
Definition: packet.hh:557
Clocked::nextCycle
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
Definition: clocked_object.hh:210
SMMUv3DeviceInterface::sendDeviceRetry
void sendDeviceRetry()
Definition: smmu_v3_deviceifc.cc:231
SMMUv3
Definition: smmu_v3.hh:81
trace.hh
ResponsePort::sendRetryReq
void sendRetryReq()
Send a retry to the request port that previously attempted a sendTimingReq to this response port and ...
Definition: port.hh:398
SMMUTranslationProcess::beginTransaction
void beginTransaction(const SMMUTranslRequest &req)
Definition: smmu_v3_transl.cc:107
SMMUv3DeviceInterface::atsSendDeviceRetry
void atsSendDeviceRetry()
Definition: smmu_v3_deviceifc.cc:237
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:293
ACTION_SEND_RESP
@ ACTION_SEND_RESP
Definition: smmu_v3_proc.hh:59
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
SMMUv3DeviceInterface::scheduleDeviceRetry
void scheduleDeviceRetry()
Definition: smmu_v3_deviceifc.cc:244
DrainState::Draining
@ Draining
Draining buffers pending serialization/handover.
SMMUv3DeviceInterface::portWidth
const unsigned portWidth
Definition: smmu_v3_deviceifc.hh:80

Generated on Wed Sep 30 2020 14:02:10 for gem5 by doxygen 1.8.17