gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Ali Saidi
41  * Nathan Binkert
42  * Andreas Sandberg
43  */
44 
45 #ifndef __DEV_DMA_DEVICE_HH__
46 #define __DEV_DMA_DEVICE_HH__
47 
48 #include <deque>
49 #include <memory>
50 
51 #include "base/circlebuf.hh"
52 #include "dev/io_device.hh"
53 #include "params/DmaDevice.hh"
54 #include "sim/drain.hh"
55 #include "sim/system.hh"
56 
57 class ClockedObject;
58 
59 class DmaPort : public MasterPort, public Drainable
60 {
61  private:
62 
69  void trySendTimingReq();
70 
78  void sendDma();
79 
90  void handleResp(PacketPtr pkt, Tick delay = 0);
91 
93  {
97 
99  const Addr totBytes;
100 
103 
105  const Tick delay;
106 
108  : completionEvent(ce), totBytes(tb), numBytes(0), delay(_delay)
109  {}
110  };
111 
112  public:
115 
118  System *const sys;
119 
122 
123  protected:
126 
129 
131  uint32_t pendingCount;
132 
135  bool inRetry;
136 
138  const uint32_t defaultSid;
139 
141  const uint32_t defaultSSid;
142 
143  protected:
144 
145  bool recvTimingResp(PacketPtr pkt) override;
146  void recvReqRetry() override;
147 
148  void queueDma(PacketPtr pkt);
149 
150  public:
151 
152  DmaPort(ClockedObject *dev, System *s,
153  uint32_t sid = 0, uint32_t ssid = 0);
154 
155  RequestPtr
156  dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
157  uint8_t *data, Tick delay, Request::Flags flag = 0);
158 
159  RequestPtr
160  dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
161  uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay,
162  Request::Flags flag = 0);
163 
164  bool dmaPending() const { return pendingCount > 0; }
165 
166  DrainState drain() override;
167 };
168 
169 class DmaDevice : public PioDevice
170 {
171  protected:
173 
174  public:
175  typedef DmaDeviceParams Params;
176  DmaDevice(const Params *p);
177  virtual ~DmaDevice() { }
178 
179  void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
180  uint32_t sid, uint32_t ssid, Tick delay = 0)
181  {
182  dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data,
183  sid, ssid, delay);
184  }
185 
186  void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
187  Tick delay = 0)
188  {
189  dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
190  }
191 
192  void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
193  uint32_t sid, uint32_t ssid, Tick delay = 0)
194  {
195  dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data,
196  sid, ssid, delay);
197  }
198 
199  void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
200  Tick delay = 0)
201  {
202  dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
203  }
204 
205  bool dmaPending() const { return dmaPort.dmaPending(); }
206 
207  void init() override;
208 
209  unsigned int cacheBlockSize() const { return sys->cacheLineSize(); }
210 
211  Port &getPort(const std::string &if_name,
212  PortID idx=InvalidPortID) override;
213 
214 };
215 
224 class DmaCallback : public Drainable
225 {
226  public:
227  virtual const std::string name() const { return "DmaCallback"; }
228 
236  DrainState drain() override
237  {
239  }
240 
241  protected:
242  int count;
243 
245  : count(0)
246  { }
247 
248  virtual ~DmaCallback() { }
249 
253  virtual void process() = 0;
254 
255  private:
262  {
263  if (--count == 0) {
264  process();
265  // Need to notify DrainManager that this object is finished
266  // draining, even though it is immediately deleted.
267  signalDrainDone();
268  delete this;
269  }
270  }
271 
272  public:
273 
279  {
280  ++count;
281  return new EventFunctionWrapper([this]{ chunkComplete(); }, name(),
282  true);
283  }
284 };
285 
329 class DmaReadFifo : public Drainable, public Serializable
330 {
331  public:
332  DmaReadFifo(DmaPort &port, size_t size,
333  unsigned max_req_size,
334  unsigned max_pending,
335  Request::Flags flags = 0);
336 
337  ~DmaReadFifo();
338 
339  public: // Serializable
340  void serialize(CheckpointOut &cp) const override;
341  void unserialize(CheckpointIn &cp) override;
342 
343  public: // Drainable
344  DrainState drain() override;
345 
346  public: // FIFO access
363  bool tryGet(uint8_t *dst, size_t len);
364 
365  template<typename T>
366  bool tryGet(T &value) {
367  return tryGet(static_cast<T *>(&value), sizeof(T));
368  };
369 
378  void get(uint8_t *dst, size_t len);
379 
380  template<typename T>
381  T get() {
382  T value;
383  get(static_cast<uint8_t *>(&value), sizeof(T));
384  return value;
385  };
386 
388  size_t size() const { return buffer.size(); }
390  void flush() { buffer.flush(); }
391 
393  public: // FIFO fill control
408  void startFill(Addr start, size_t size);
409 
418  void stopFill();
419 
424  bool atEndOfBlock() const {
425  return nextAddr == endAddr;
426  }
427 
432  bool isActive() const {
433  return !(pendingRequests.empty() && atEndOfBlock());
434  }
435 
437  protected: // Callbacks
449  virtual void onEndOfBlock() {};
450 
462  virtual void onIdle() {};
463 
465  private: // Configuration
467  const Addr maxReqSize;
469  const size_t fifoSize;
472 
474 
475  private:
476  class DmaDoneEvent : public Event
477  {
478  public:
479  DmaDoneEvent(DmaReadFifo *_parent, size_t max_size);
480 
481  void kill();
482  void cancel();
483  bool canceled() const { return _canceled; }
484  void reset(size_t size);
485  void process();
486 
487  bool done() const { return _done; }
488  size_t requestSize() const { return _requestSize; }
489  const uint8_t *data() const { return _data.data(); }
490  uint8_t *data() { return _data.data(); }
491 
492  private:
494  bool _done;
495  bool _canceled;
496  size_t _requestSize;
498  };
499 
500  typedef std::unique_ptr<DmaDoneEvent> DmaDoneEventUPtr;
501 
506  void dmaDone();
507 
509  void handlePending();
510 
512  void resumeFill();
513 
515  void resumeFillTiming();
516 
518  void resumeFillFunctional();
519 
520  private: // Internal state
522 
525 
528 };
529 
530 #endif // __DEV_DMA_DEVICE_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
count
Definition: misc.hh:705
Bitfield< 27 > tb
Definition: dt_constants.hh:76
Ports are used to interface objects to each other.
Definition: port.hh:60
void queueDma(PacketPtr pkt)
Definition: dma_device.cc:210
std::unique_ptr< DmaDoneEvent > DmaDoneEventUPtr
Definition: dma_device.hh:500
Addr numBytes
Number of bytes that have been acked for this transaction.
Definition: dma_device.hh:102
const Tick delay
Amount to delay completion of dma by.
Definition: dma_device.hh:105
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
Definition: dma_device.hh:199
DmaPort(ClockedObject *dev, System *s, uint32_t sid=0, uint32_t ssid=0)
Definition: dma_device.cc:57
Buffered DMA engine helper class.
Definition: dma_device.hh:329
const PortID InvalidPortID
Definition: types.hh:238
DrainState
Object drain/handover states.
Definition: drain.hh:71
Running normally.
ClockedObject *const device
The device that owns this port.
Definition: dma_device.hh:114
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
Definition: dma_device.hh:179
DrainState drain() override
DmaPort ensures that all oustanding DMA accesses have completed before it finishes draining...
Definition: dma_device.hh:236
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
void chunkComplete()
Called by DMA engine completion event on each chunk completion.
Definition: dma_device.hh:261
ip6_addr_t addr
Definition: inet.hh:335
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: dma_device.cc:111
Bitfield< 29, 28 > ce
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:267
void reset()
Definition: statistics.cc:570
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
Definition: dma_device.hh:186
void trySendTimingReq()
Take the first packet of the transmit list and attempt to send it as a timing request.
Definition: dma_device.cc:220
Definition: system.hh:77
uint32_t pendingCount
Number of outstanding packets the dma port has.
Definition: dma_device.hh:131
virtual ~DmaDevice()
Definition: dma_device.hh:177
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:68
DmaPort & port
Definition: dma_device.hh:473
Definition: cprintf.cc:42
const Request::Flags reqFlags
Request flags.
Definition: dma_device.hh:471
std::deque< DmaDoneEventUPtr > freeRequests
Definition: dma_device.hh:527
Fifo< uint8_t > buffer
Definition: dma_device.hh:521
EventFunctionWrapper sendEvent
Event used to schedule a future sending from the transmit list.
Definition: dma_device.hh:128
const MasterID masterId
Id for all requests.
Definition: dma_device.hh:121
virtual ~DmaCallback()
Definition: dma_device.hh:248
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:223
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:249
Bitfield< 4 > s
DmaDeviceParams Params
Definition: dma_device.hh:175
uint64_t Tick
Tick count type.
Definition: types.hh:63
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
Definition: dma_device.hh:192
bool tryGet(T &value)
Definition: dma_device.hh:366
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:146
virtual const std::string name() const
Definition: dma_device.hh:227
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Bitfield< 18, 16 > len
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
std::vector< uint8_t > _data
Definition: dma_device.hh:497
const uint8_t * data() const
Definition: dma_device.hh:489
virtual void onIdle()
Last response received callback.
Definition: dma_device.hh:462
const size_t fifoSize
Maximum FIFO size in bytes.
Definition: dma_device.hh:469
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:102
virtual void onEndOfBlock()
End of block callback.
Definition: dma_device.hh:449
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint16_t MasterID
Definition: request.hh:86
Draining buffers pending serialization/handover.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
System *const sys
The system that device/port are in.
Definition: dma_device.hh:118
bool dmaPending() const
Definition: dma_device.hh:205
Bitfield< 10, 5 > event
Basic support for object serialization.
Definition: serialize.hh:153
A virtual base opaque structure used to hold state associated with the packet (e.g., an MSHR), specific to a SimObject that sees the packet.
Definition: packet.hh:403
RequestPtr dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, uint8_t *data, Tick delay, Request::Flags flag=0)
Definition: dma_device.cc:202
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: dma_device.cc:135
Event * getChunkEvent()
Request a chunk event.
Definition: dma_device.hh:278
DMA callback class.
Definition: dma_device.hh:224
STL deque class.
Definition: stl.hh:47
const Addr totBytes
Total number of bytes that this transaction involves.
Definition: dma_device.hh:99
DmaReqState(Event *ce, Addr tb, Tick _delay)
Definition: dma_device.hh:107
std::deque< DmaDoneEventUPtr > pendingRequests
Definition: dma_device.hh:526
bool isActive() const
Is the DMA engine active (i.e., are there still in-flight accesses)?
Definition: dma_device.hh:432
const uint32_t defaultSSid
Default substreamId.
Definition: dma_device.hh:141
const uint32_t defaultSid
Default streamId.
Definition: dma_device.hh:138
std::ostream CheckpointOut
Definition: serialize.hh:68
unsigned int cacheBlockSize() const
Definition: dma_device.hh:209
Definition: eventq.hh:189
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
bool dmaPending() const
Definition: dma_device.hh:164
void unserialize(ThreadContext &tc, CheckpointIn &cp)
Event * completionEvent
Event to call on the device when this transaction (all packets) complete.
Definition: dma_device.hh:96
bool atEndOfBlock() const
Has the DMA engine sent out the last request for the active block?
Definition: dma_device.hh:424
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
DmaPort dmaPort
Definition: dma_device.hh:172
size_t size() const
Get the amount of data stored in the FIFO.
Definition: dma_device.hh:388
size_t requestSize() const
Definition: dma_device.hh:488
Command
List of all commands associated with a packet.
Definition: packet.hh:84
Bitfield< 0 > p
void flush()
Flush the FIFO.
Definition: dma_device.hh:390
const char data[]
bool inRetry
If the port is currently waiting for a retry before it can send whatever it is that it&#39;s sending...
Definition: dma_device.hh:135
const FlagsType init
This Stat is Initialized.
Definition: info.hh:47
std::deque< PacketPtr > transmitList
Use a deque as we never do any insertion or removal in the middle.
Definition: dma_device.hh:125
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:188

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