gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
smmu_v3_proc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, 2018-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  */
39 
40 #include "dev/arm/smmu_v3_proc.hh"
41 
42 #include "dev/arm/smmu_v3.hh"
43 #include "sim/system.hh"
44 
45 SMMUProcess::SMMUProcess(const std::string &name, SMMUv3 &_smmu) :
46  coroutine(NULL),
47  myName(name),
48  smmu(_smmu)
49 {}
50 
52 {
53  delete coroutine;
54 }
55 
56 void
58 {
59  smmu.runProcess(this, NULL);
60 }
61 
62 void
64 {
65  delete coroutine;
66  coroutine = new Coroutine(
67  std::bind(&SMMUProcess::main, this, std::placeholders::_1));
68 }
69 
70 void
71 SMMUProcess::doRead(Yield &yield, Addr addr, void *ptr, size_t size)
72 {
74  doDelay(yield, Cycles(1)); // request - assume 1 cycle
76 
77  SMMUAction a;
79 
80  RequestPtr req = std::make_shared<Request>(
81  addr, size, 0, smmu.masterId);
82 
83  req->taskId(ContextSwitchTaskId::DMA);
84 
85  a.pkt = new Packet(req, MemCmd::ReadReq);
86  a.pkt->dataStatic(ptr);
87 
88  a.delay = 0;
89 
90  PacketPtr pkt = yield(a).get();
91 
92  assert(pkt);
93  // >= because we may get the whole cache line
94  assert(pkt->getSize() >= size);
95 
96  delete pkt;
97 }
98 
99 void
100 SMMUProcess::doWrite(Yield &yield, Addr addr, const void *ptr, size_t size)
101 {
102  unsigned nbeats = (size + (smmu.masterPortWidth-1)) / smmu.masterPortWidth;
103 
105  doDelay(yield, Cycles(nbeats));
107 
108 
109  SMMUAction a;
110  a.type = ACTION_SEND_REQ;
111 
112  RequestPtr req = std::make_shared<Request>(
113  addr, size, 0, smmu.masterId);
114 
115  req->taskId(ContextSwitchTaskId::DMA);
116 
117  a.pkt = new Packet(req, MemCmd::WriteReq);
118  a.pkt->dataStatic(ptr);
119 
120  PacketPtr pkt = yield(a).get();
121 
122  delete pkt;
123 }
124 
125 void
127 {
128  if (smmu.system.isTimingMode())
129  scheduleWakeup(smmu.clockEdge(cycles));
130 
131  SMMUAction a;
132  a.type = ACTION_DELAY;
133  a.delay = cycles * smmu.clockPeriod();
134  yield(a);
135 }
136 
137 void
139 {
140  SMMUAction a;
141  a.type = ACTION_SLEEP;
142  yield(a);
143 }
144 
145 void
147 {
148  while (sem.count == 0) {
149  sem.queue.push(this);
150  doSleep(yield);
151  }
152 
153  sem.count--;
154  return;
155 }
156 
157 void
159 {
160  sem.count++;
161  if (!sem.queue.empty()) {
162  SMMUProcess *next_proc = sem.queue.front();
163  sem.queue.pop();
164 
165  // Schedule event in the current tick instead of
166  // calling the function directly to avoid overflowing
167  // the stack in this coroutine.
168  next_proc->scheduleWakeup(curTick());
169  }
170 }
171 
172 void
174 {
175  sig.waiting.push_back(this);
176  doSleep(yield);
177 }
178 
179 void
181 {
182  if (!sig.waiting.empty()) {
183  for (auto it : sig.waiting) {
184  // Schedule event in the current tick instead of
185  // calling the function directly to avoid overflowing
186  // the stack in this coroutine.
187  it->scheduleWakeup(curTick());
188  }
189 
190  sig.waiting.clear();
191  }
192 }
193 
194 void
196 {
197  auto *ep = new EventWrapper<
198  SMMUProcess, &SMMUProcess::wakeup> (this, true);
199 
200  smmu.schedule(ep, when);
201 }
202 
205 {
206  assert(coroutine != NULL);
207  assert(*coroutine);
208  return (*coroutine)(pkt).get();
209 }
void doDelay(Yield &yield, Cycles cycles)
std::queue< SMMUProcess * > queue
Definition: smmu_v3_proc.hh:87
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
SMMUAction runProcess(SMMUProcess *proc, PacketPtr pkt)
Definition: smmu_v3.cc:221
const std::string & name()
Definition: trace.cc:54
std::list< SMMUProcess * > waiting
Definition: smmu_v3_proc.hh:92
SMMUAction run(PacketPtr pkt)
void wakeup()
Definition: smmu_v3_proc.cc:57
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
Bitfield< 8 > a
ip6_addr_t addr
Definition: inet.hh:335
const unsigned masterPortWidth
Definition: smmu_v3.hh:113
void doSleep(Yield &yield)
SMMUProcess(const std::string &name, SMMUv3 &_smmu)
Definition: smmu_v3_proc.cc:45
unsigned count
Definition: smmu_v3_proc.hh:85
Tick clockPeriod() const
void reinit()
Definition: smmu_v3_proc.cc:63
void doBroadcastSignal(SMMUSignal &sig)
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1040
PacketPtr pkt
Definition: smmu_v3_proc.hh:71
CallerType: A reference to an object of this class will be passed to the coroutine task...
Definition: coroutine.hh:85
virtual void main(Yield &yield)=0
void doRead(Yield &yield, Addr addr, void *ptr, size_t size)
Definition: smmu_v3_proc.cc:71
unsigned getSize() const
Definition: packet.hh:736
Tick curTick()
The current simulated tick.
Definition: core.hh:47
void doWrite(Yield &yield, Addr addr, const void *ptr, size_t size)
uint64_t Tick
Tick count type.
Definition: types.hh:63
virtual ~SMMUProcess()
Definition: smmu_v3_proc.cc:51
SMMUActionType type
Definition: smmu_v3_proc.hh:70
void doSemaphoreUp(SMMUSemaphore &sem)
void scheduleWakeup(Tick when)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
SMMUSemaphore masterPortSem
Definition: smmu_v3.hh:121
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
This is an implementation of the SMMUv3 architecture.
SMMUv3 & smmu
m5::Coroutine< PacketPtr, SMMUAction > Coroutine
Definition: smmu_v3_proc.hh:98
const System & system
Definition: smmu_v3.hh:92
void doWaitForSignal(Yield &yield, SMMUSignal &sig)
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
std::enable_if<!std::is_same< T, void >::value, T >::type get()
get() is the way we can extrapolate arguments from the coroutine caller.
Definition: coroutine.hh:136
Coroutine * coroutine
void doSemaphoreDown(Yield &yield, SMMUSemaphore &sem)
bool isTimingMode() const
Is the system in timing mode?
Definition: system.hh:150
const MasterID masterId
Definition: smmu_v3.hh:93
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:104
Bitfield< 1 > ep

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