gem5  v20.1.0.0
dma_device.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015, 2017, 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  * Copyright (c) 2004-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __DEV_DMA_DEVICE_HH__
42 #define __DEV_DMA_DEVICE_HH__
43 
44 #include <deque>
45 #include <memory>
46 
47 #include "base/circlebuf.hh"
48 #include "dev/io_device.hh"
49 #include "params/DmaDevice.hh"
50 #include "sim/drain.hh"
51 #include "sim/system.hh"
52 
53 class ClockedObject;
54 
55 class DmaPort : public RequestPort, public Drainable
56 {
57  private:
58 
65  void trySendTimingReq();
66 
74  void sendDma();
75 
86  void handleResp(PacketPtr pkt, Tick delay = 0);
87 
89  {
93 
95  const Addr totBytes;
96 
99 
101  const Tick delay;
102 
104  : completionEvent(ce), totBytes(tb), numBytes(0), delay(_delay)
105  {}
106  };
107 
108  public:
111 
114  System *const sys;
115 
118 
119  protected:
122 
125 
127  uint32_t pendingCount;
128 
131  bool inRetry;
132 
134  const uint32_t defaultSid;
135 
137  const uint32_t defaultSSid;
138 
139  protected:
140 
141  bool recvTimingResp(PacketPtr pkt) override;
142  void recvReqRetry() override;
143 
144  void queueDma(PacketPtr pkt);
145 
146  public:
147 
148  DmaPort(ClockedObject *dev, System *s,
149  uint32_t sid = 0, uint32_t ssid = 0);
150 
151  RequestPtr
152  dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
153  uint8_t *data, Tick delay, Request::Flags flag = 0);
154 
155  RequestPtr
156  dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
157  uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay,
158  Request::Flags flag = 0);
159 
160  bool dmaPending() const { return pendingCount > 0; }
161 
162  DrainState drain() override;
163 };
164 
165 class DmaDevice : public PioDevice
166 {
167  protected:
169 
170  public:
171  typedef DmaDeviceParams Params;
172  DmaDevice(const Params *p);
173  virtual ~DmaDevice() { }
174 
175  void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
176  uint32_t sid, uint32_t ssid, Tick delay = 0)
177  {
179  sid, ssid, delay);
180  }
181 
182  void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
183  Tick delay = 0)
184  {
185  dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
186  }
187 
188  void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
189  uint32_t sid, uint32_t ssid, Tick delay = 0)
190  {
192  sid, ssid, delay);
193  }
194 
195  void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
196  Tick delay = 0)
197  {
198  dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
199  }
200 
201  bool dmaPending() const { return dmaPort.dmaPending(); }
202 
203  void init() override;
204 
205  unsigned int cacheBlockSize() const { return sys->cacheLineSize(); }
206 
207  Port &getPort(const std::string &if_name,
208  PortID idx=InvalidPortID) override;
209 
210 };
211 
220 class DmaCallback : public Drainable
221 {
222  public:
223  virtual const std::string name() const { return "DmaCallback"; }
224 
232  DrainState drain() override
233  {
235  }
236 
237  protected:
238  int count;
239 
241  : count(0)
242  { }
243 
244  virtual ~DmaCallback() { }
245 
249  virtual void process() = 0;
250 
251  private:
258  {
259  if (--count == 0) {
260  process();
261  // Need to notify DrainManager that this object is finished
262  // draining, even though it is immediately deleted.
263  signalDrainDone();
264  delete this;
265  }
266  }
267 
268  public:
269 
275  {
276  ++count;
277  return new EventFunctionWrapper([this]{ chunkComplete(); }, name(),
278  true);
279  }
280 };
281 
325 class DmaReadFifo : public Drainable, public Serializable
326 {
327  public:
328  DmaReadFifo(DmaPort &port, size_t size,
329  unsigned max_req_size,
330  unsigned max_pending,
331  Request::Flags flags = 0);
332 
333  ~DmaReadFifo();
334 
335  public: // Serializable
336  void serialize(CheckpointOut &cp) const override;
337  void unserialize(CheckpointIn &cp) override;
338 
339  public: // Drainable
340  DrainState drain() override;
341 
342  public: // FIFO access
359  bool tryGet(uint8_t *dst, size_t len);
360 
361  template<typename T>
362  bool tryGet(T &value) {
363  return tryGet(static_cast<T *>(&value), sizeof(T));
364  };
365 
374  void get(uint8_t *dst, size_t len);
375 
376  template<typename T>
377  T get() {
378  T value;
379  get(static_cast<uint8_t *>(&value), sizeof(T));
380  return value;
381  };
382 
384  size_t size() const { return buffer.size(); }
386  void flush() { buffer.flush(); }
387 
389  public: // FIFO fill control
404  void startFill(Addr start, size_t size);
405 
414  void stopFill();
415 
420  bool atEndOfBlock() const {
421  return nextAddr == endAddr;
422  }
423 
428  bool isActive() const {
429  return !(pendingRequests.empty() && atEndOfBlock());
430  }
431 
433  protected: // Callbacks
445  virtual void onEndOfBlock() {};
446 
458  virtual void onIdle() {};
459 
461  private: // Configuration
463  const Addr maxReqSize;
465  const size_t fifoSize;
468 
470 
471  private:
472  class DmaDoneEvent : public Event
473  {
474  public:
475  DmaDoneEvent(DmaReadFifo *_parent, size_t max_size);
476 
477  void kill();
478  void cancel();
479  bool canceled() const { return _canceled; }
480  void reset(size_t size);
481  void process();
482 
483  bool done() const { return _done; }
484  size_t requestSize() const { return _requestSize; }
485  const uint8_t *data() const { return _data.data(); }
486  uint8_t *data() { return _data.data(); }
487 
488  private:
490  bool _done;
491  bool _canceled;
492  size_t _requestSize;
494  };
495 
496  typedef std::unique_ptr<DmaDoneEvent> DmaDoneEventUPtr;
497 
502  void dmaDone();
503 
505  void handlePending();
506 
508  void resumeFill();
509 
511  void resumeFillTiming();
512 
514  void resumeFillFunctional();
515 
516  private: // Internal state
518 
521 
524 };
525 
526 #endif // __DEV_DMA_DEVICE_HH__
DmaReadFifo::tryGet
bool tryGet(uint8_t *dst, size_t len)
Try to read data from the FIFO.
Definition: dma_device.cc:335
DmaPort::transmitList
std::deque< PacketPtr > transmitList
Use a deque as we never do any insertion or removal in the middle.
Definition: dma_device.hh:121
DmaReadFifo::nextAddr
Addr nextAddr
Definition: dma_device.hh:519
DmaReadFifo::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: dma_device.cc:317
DmaReadFifo::startFill
void startFill(Addr start, size_t size)
Start filling the FIFO.
Definition: dma_device.cc:354
io_device.hh
system.hh
DmaReadFifo::flush
void flush()
Flush the FIFO.
Definition: dma_device.hh:386
DmaReadFifo::DmaDoneEventUPtr
std::unique_ptr< DmaDoneEvent > DmaDoneEventUPtr
Definition: dma_device.hh:496
data
const char data[]
Definition: circlebuf.test.cc:42
InvalidPortID
const PortID InvalidPortID
Definition: types.hh:238
DmaReadFifo::DmaDoneEvent::data
const uint8_t * data() const
Definition: dma_device.hh:485
circlebuf.hh
DmaReadFifo::freeRequests
std::deque< DmaDoneEventUPtr > freeRequests
Definition: dma_device.hh:523
Flags< FlagsType >
Serializable
Basic support for object serialization.
Definition: serialize.hh:172
DmaPort::queueDma
void queueDma(PacketPtr pkt)
Definition: dma_device.cc:205
DmaCallback::drain
DrainState drain() override
DmaPort ensures that all oustanding DMA accesses have completed before it finishes draining.
Definition: dma_device.hh:232
DmaReadFifo::DmaDoneEvent::done
bool done() const
Definition: dma_device.hh:483
DmaPort::drain
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: dma_device.cc:130
DmaPort::trySendTimingReq
void trySendTimingReq()
Take the first packet of the transmit list and attempt to send it as a timing request.
Definition: dma_device.cc:215
MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:82
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
DmaReadFifo::port
DmaPort & port
Definition: dma_device.hh:469
DmaCallback::chunkComplete
void chunkComplete()
Called by DMA engine completion event on each chunk completion.
Definition: dma_device.hh:257
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
DmaPort::DmaReqState::numBytes
Addr numBytes
Number of bytes that have been acked for this transaction.
Definition: dma_device.hh:98
DmaPort::DmaReqState::delay
const Tick delay
Amount to delay completion of dma by.
Definition: dma_device.hh:101
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
DmaDevice::cacheBlockSize
unsigned int cacheBlockSize() const
Definition: dma_device.hh:205
std::vector< uint8_t >
DmaPort::requestorId
const RequestorID requestorId
Id for all requests.
Definition: dma_device.hh:117
DmaPort::defaultSid
const uint32_t defaultSid
Default streamId.
Definition: dma_device.hh:134
MipsISA::ce
Bitfield< 29, 28 > ce
Definition: pra_constants.hh:177
DmaReadFifo::stopFill
void stopFill()
Stop the DMA engine.
Definition: dma_device.cc:364
DmaReadFifo::DmaDoneEvent
Definition: dma_device.hh:472
DmaPort::DmaReqState
Definition: dma_device.hh:88
DmaReadFifo::get
T get()
Definition: dma_device.hh:377
DmaReadFifo::handlePending
void handlePending()
Handle pending requests that have been flagged as done.
Definition: dma_device.cc:455
DmaCallback::~DmaCallback
virtual ~DmaCallback()
Definition: dma_device.hh:244
DmaPort::sendEvent
EventFunctionWrapper sendEvent
Event used to schedule a future sending from the transmit list.
Definition: dma_device.hh:124
DmaPort::device
ClockedObject *const device
The device that owns this port.
Definition: dma_device.hh:110
DmaReadFifo::endAddr
Addr endAddr
Definition: dma_device.hh:520
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
Fifo::flush
void flush()
Definition: circlebuf.hh:153
DmaReadFifo::reqFlags
const Request::Flags reqFlags
Request flags.
Definition: dma_device.hh:467
EventFunctionWrapper
Definition: eventq.hh:1101
PioDevice::sys
System * sys
Definition: io_device.hh:102
DmaReadFifo::buffer
Fifo< uint8_t > buffer
Definition: dma_device.hh:517
DmaReadFifo::~DmaReadFifo
~DmaReadFifo()
Definition: dma_device.cc:300
DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
DmaReadFifo::maxReqSize
const Addr maxReqSize
Maximum request size in bytes.
Definition: dma_device.hh:458
MemCmd::Command
Command
List of all commands associated with a packet.
Definition: packet.hh:79
DmaDevice::dmaPort
DmaPort dmaPort
Definition: dma_device.hh:168
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:85
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
RequestorID
uint16_t RequestorID
Definition: request.hh:85
DmaReadFifo::onIdle
virtual void onIdle()
Last response received callback.
Definition: dma_device.hh:458
DmaDevice::dmaRead
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
Definition: dma_device.hh:188
cp
Definition: cprintf.cc:40
PioDevice
This device is the base class which all devices senstive to an address range inherit from.
Definition: io_device.hh:99
Fifo::size
size_t size() const
Definition: circlebuf.hh:150
DmaDevice::dmaWrite
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
Definition: dma_device.hh:175
Packet::SenderState
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition: packet.hh:431
Drainable
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:230
Event
Definition: eventq.hh:246
Fifo< uint8_t >
DmaReadFifo::drain
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: dma_device.cc:474
DmaReadFifo::DmaDoneEvent::parent
DmaReadFifo * parent
Definition: dma_device.hh:489
DmaReadFifo::DmaDoneEvent::canceled
bool canceled() const
Definition: dma_device.hh:479
System
Definition: system.hh:73
DmaReadFifo::resumeFillFunctional
void resumeFillFunctional()
Try to bypass DMA requests in KVM execution mode.
Definition: dma_device.cc:396
DmaPort::dmaPending
bool dmaPending() const
Definition: dma_device.hh:160
DmaPort::handleResp
void handleResp(PacketPtr pkt, Tick delay=0)
Handle a response packet by updating the corresponding DMA request state to reflect the bytes receive...
Definition: dma_device.cc:63
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
DmaReadFifo::DmaDoneEvent::_done
bool _done
Definition: dma_device.hh:490
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
DmaDevice::DmaDevice
DmaDevice(const Params *p)
Definition: dma_device.cc:117
DmaReadFifo::DmaDoneEvent::requestSize
size_t requestSize() const
Definition: dma_device.hh:484
DmaDevice::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: dma_device.cc:277
DmaCallback::name
virtual const std::string name() const
Definition: dma_device.hh:223
DmaReadFifo::DmaDoneEvent::_data
std::vector< uint8_t > _data
Definition: dma_device.hh:493
DmaReadFifo::DmaDoneEvent::reset
void reset(size_t size)
Definition: dma_device.cc:500
DmaDevice::~DmaDevice
virtual ~DmaDevice()
Definition: dma_device.hh:173
Drainable::signalDrainDone
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:301
DmaReadFifo::DmaDoneEvent::kill
void kill()
Definition: dma_device.cc:487
DmaReadFifo
Buffered DMA engine helper class.
Definition: dma_device.hh:325
DmaDevice::dmaRead
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
Definition: dma_device.hh:195
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
DmaCallback::getChunkEvent
Event * getChunkEvent()
Request a chunk event.
Definition: dma_device.hh:274
DmaPort::DmaReqState::DmaReqState
DmaReqState(Event *ce, Addr tb, Tick _delay)
Definition: dma_device.hh:103
DmaReadFifo::fifoSize
const size_t fifoSize
Maximum FIFO size in bytes.
Definition: dma_device.hh:465
DmaReadFifo::dmaDone
void dmaDone()
DMA request done, handle incoming data and issue new request.
Definition: dma_device.cc:443
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
DmaReadFifo::tryGet
bool tryGet(T &value)
Definition: dma_device.hh:362
DmaPort::sys
System *const sys
The system that device/port are in.
Definition: dma_device.hh:114
DmaPort::dmaAction
RequestPtr dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, uint8_t *data, Tick delay, Request::Flags flag=0)
Definition: dma_device.cc:197
DmaReadFifo::DmaDoneEvent::DmaDoneEvent
DmaDoneEvent(DmaReadFifo *_parent, size_t max_size)
Definition: dma_device.cc:480
DmaReadFifo::resumeFill
void resumeFill()
Try to issue new DMA requests or bypass DMA requests.
Definition: dma_device.cc:377
DmaDevice::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: dma_device.cc:122
DmaReadFifo::resumeFillTiming
void resumeFillTiming()
Try to issue new DMA requests during normal execution.
Definition: dma_device.cc:417
DmaReadFifo::DmaDoneEvent::_canceled
bool _canceled
Definition: dma_device.hh:491
DmaPort::DmaReqState::completionEvent
Event * completionEvent
Event to call on the device when this transaction (all packets) complete.
Definition: dma_device.hh:92
DmaReadFifo::DmaDoneEvent::data
uint8_t * data()
Definition: dma_device.hh:486
DmaPort::recvReqRetry
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: dma_device.cc:141
DmaCallback::process
virtual void process()=0
Callback function invoked on completion of all chunks.
DmaReadFifo::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: dma_device.cc:327
DmaPort::recvTimingResp
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: dma_device.cc:106
DmaDevice
Definition: dma_device.hh:165
DmaReadFifo::pendingRequests
std::deque< DmaDoneEventUPtr > pendingRequests
Definition: dma_device.hh:522
DmaReadFifo::onEndOfBlock
virtual void onEndOfBlock()
End of block callback.
Definition: dma_device.hh:445
DmaReadFifo::DmaDoneEvent::cancel
void cancel()
Definition: dma_device.cc:494
DmaDevice::dmaWrite
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
Definition: dma_device.hh:182
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
std::deque
STL deque class.
Definition: stl.hh:44
DmaPort::pendingCount
uint32_t pendingCount
Number of outstanding packets the dma port has.
Definition: dma_device.hh:127
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
DmaCallback
DMA callback class.
Definition: dma_device.hh:220
addr
ip6_addr_t addr
Definition: inet.hh:423
DmaPort::sendDma
void sendDma()
For timing, attempt to send the first item on the transmit list, and if it is successful and there ar...
Definition: dma_device.cc:244
DmaReadFifo::atEndOfBlock
bool atEndOfBlock() const
Has the DMA engine sent out the last request for the active block?
Definition: dma_device.hh:420
DmaReadFifo::size
size_t size() const
Get the amount of data stored in the FIFO.
Definition: dma_device.hh:384
DmaPort::DmaReqState::totBytes
const Addr totBytes
Total number of bytes that this transaction involves.
Definition: dma_device.hh:95
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
DmaReadFifo::isActive
bool isActive() const
Is the DMA engine active (i.e., are there still in-flight accesses)?
Definition: dma_device.hh:428
drain.hh
DmaCallback::DmaCallback
DmaCallback()
Definition: dma_device.hh:240
DmaPort::defaultSSid
const uint32_t defaultSSid
Default substreamId.
Definition: dma_device.hh:137
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
DmaPort::DmaPort
DmaPort(ClockedObject *dev, System *s, uint32_t sid=0, uint32_t ssid=0)
Definition: dma_device.cc:52
System::cacheLineSize
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:307
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
CheckpointIn
Definition: serialize.hh:67
DmaPort::inRetry
bool inRetry
If the port is currently waiting for a retry before it can send whatever it is that it's sending.
Definition: dma_device.hh:131
DmaReadFifo::DmaReadFifo
DmaReadFifo(DmaPort &port, size_t size, unsigned max_req_size, unsigned max_pending, Request::Flags flags=0)
Definition: dma_device.cc:285
DmaDevice::dmaPending
bool dmaPending() const
Definition: dma_device.hh:201
DmaPort
Definition: dma_device.hh:55
DmaReadFifo::DmaDoneEvent::_requestSize
size_t _requestSize
Definition: dma_device.hh:492
DmaCallback::count
int count
Definition: dma_device.hh:238
DmaDevice::Params
DmaDeviceParams Params
Definition: dma_device.hh:171
DrainState::Draining
@ Draining
Draining buffers pending serialization/handover.
MipsISA::tb
Bitfield< 27 > tb
Definition: dt_constants.hh:74
DmaReadFifo::DmaDoneEvent::process
void process()
Definition: dma_device.cc:509

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