gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dma_device.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015, 2017 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 DmaPort : public MasterPort, public Drainable
58 {
59  private:
60 
67  void trySendTimingReq();
68 
76  void sendDma();
77 
88  void handleResp(PacketPtr pkt, Tick delay = 0);
89 
91  {
95 
97  const Addr totBytes;
98 
101 
103  const Tick delay;
104 
106  : completionEvent(ce), totBytes(tb), numBytes(0), delay(_delay)
107  {}
108  };
109 
110  public:
113 
116  System *const sys;
117 
120 
121  protected:
124 
127 
129  uint32_t pendingCount;
130 
133  bool inRetry;
134 
135  protected:
136 
137  bool recvTimingResp(PacketPtr pkt) override;
138  void recvReqRetry() override;
139 
140  void queueDma(PacketPtr pkt);
141 
142  public:
143 
144  DmaPort(MemObject *dev, System *s);
145 
147  uint8_t *data, Tick delay, Request::Flags flag = 0);
148 
149  bool dmaPending() const { return pendingCount > 0; }
150 
151  DrainState drain() override;
152 };
153 
154 class DmaDevice : public PioDevice
155 {
156  protected:
158 
159  public:
160  typedef DmaDeviceParams Params;
161  DmaDevice(const Params *p);
162  virtual ~DmaDevice() { }
163 
164  void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
165  Tick delay = 0)
166  {
167  dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
168  }
169 
170  void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
171  Tick delay = 0)
172  {
173  dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
174  }
175 
176  bool dmaPending() const { return dmaPort.dmaPending(); }
177 
178  void init() override;
179 
180  unsigned int cacheBlockSize() const { return sys->cacheLineSize(); }
181 
182  BaseMasterPort &getMasterPort(const std::string &if_name,
183  PortID idx = InvalidPortID) override;
184 
185 };
186 
195 class DmaCallback : public Drainable
196 {
197  public:
198  virtual const std::string name() const { return "DmaCallback"; }
199 
207  DrainState drain() override
208  {
210  }
211 
212  protected:
213  int count;
214 
216  : count(0)
217  { }
218 
219  virtual ~DmaCallback() { }
220 
224  virtual void process() = 0;
225 
226  private:
233  {
234  if (--count == 0) {
235  process();
236  // Need to notify DrainManager that this object is finished
237  // draining, even though it is immediately deleted.
238  signalDrainDone();
239  delete this;
240  }
241  }
242 
246  class DmaChunkEvent : public Event
247  {
248  private:
250 
251  public:
254  { }
255 
257  };
258 
259  public:
260 
266  {
267  ++count;
268  return new DmaChunkEvent(this);
269  }
270 };
271 
315 class DmaReadFifo : public Drainable, public Serializable
316 {
317  public:
318  DmaReadFifo(DmaPort &port, size_t size,
319  unsigned max_req_size,
320  unsigned max_pending,
321  Request::Flags flags = 0);
322 
323  ~DmaReadFifo();
324 
325  public: // Serializable
326  void serialize(CheckpointOut &cp) const override;
327  void unserialize(CheckpointIn &cp) override;
328 
329  public: // Drainable
330  DrainState drain() override;
331 
332  public: // FIFO access
349  bool tryGet(uint8_t *dst, size_t len);
350 
351  template<typename T>
352  bool tryGet(T &value) {
353  return tryGet(static_cast<T *>(&value), sizeof(T));
354  };
355 
364  void get(uint8_t *dst, size_t len);
365 
366  template<typename T>
367  T get() {
368  T value;
369  get(static_cast<uint8_t *>(&value), sizeof(T));
370  return value;
371  };
372 
374  size_t size() const { return buffer.size(); }
376  void flush() { buffer.flush(); }
377 
379  public: // FIFO fill control
394  void startFill(Addr start, size_t size);
395 
404  void stopFill();
405 
410  bool atEndOfBlock() const {
411  return nextAddr == endAddr;
412  }
413 
418  bool isActive() const {
419  return !(pendingRequests.empty() && atEndOfBlock());
420  }
421 
423  protected: // Callbacks
435  virtual void onEndOfBlock() {};
436 
448  virtual void onIdle() {};
449 
451  private: // Configuration
453  const Addr maxReqSize;
455  const size_t fifoSize;
458 
460 
461  private:
462  class DmaDoneEvent : public Event
463  {
464  public:
465  DmaDoneEvent(DmaReadFifo *_parent, size_t max_size);
466 
467  void kill();
468  void cancel();
469  bool canceled() const { return _canceled; }
470  void reset(size_t size);
471  void process();
472 
473  bool done() const { return _done; }
474  size_t requestSize() const { return _requestSize; }
475  const uint8_t *data() const { return _data.data(); }
476  uint8_t *data() { return _data.data(); }
477 
478  private:
480  bool _done;
481  bool _canceled;
482  size_t _requestSize;
484  };
485 
486  typedef std::unique_ptr<DmaDoneEvent> DmaDoneEventUPtr;
487 
492  void dmaDone();
493 
495  void handlePending();
496 
498  void resumeFill();
499 
501  void resumeFillTiming();
502 
504  void resumeFillFunctional();
505 
506  private: // Internal state
508 
511 
514 };
515 
516 #endif // __DEV_DMA_DEVICE_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:167
Bitfield< 27 > tb
Definition: dt_constants.hh:76
size_t size() const
Get the amount of data stored in the FIFO.
Definition: dma_device.hh:374
void queueDma(PacketPtr pkt)
Definition: dma_device.cc:191
std::unique_ptr< DmaDoneEvent > DmaDoneEventUPtr
Definition: dma_device.hh:486
Addr numBytes
Number of bytes that have been acked for this transaction.
Definition: dma_device.hh:100
const Tick delay
Amount to delay completion of dma by.
Definition: dma_device.hh:103
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: dma_device.cc:307
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
Definition: dma_device.hh:170
Buffered DMA engine helper class.
Definition: dma_device.hh:315
void startFill(Addr start, size_t size)
Start filling the FIFO.
Definition: dma_device.cc:344
const PortID InvalidPortID
Definition: types.hh:182
DrainState
Object drain/handover states.
Definition: drain.hh:71
Running normally.
DrainState drain() override
DmaPort ensures that all oustanding DMA accesses have completed before it finishes draining...
Definition: dma_device.hh:207
::Flags< FlagsType > Flags
Definition: request.hh:92
bool atEndOfBlock() const
Has the DMA engine sent out the last request for the active block?
Definition: dma_device.hh:410
void chunkComplete()
Called by DMA engine completion event on each chunk completion.
Definition: dma_device.hh:232
ip6_addr_t addr
Definition: inet.hh:335
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the slave port.
Definition: dma_device.cc:107
Bitfield< 29, 28 > ce
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
Definition: dma_device.hh:164
void trySendTimingReq()
Take the first packet of the transmit list and attempt to send it as a timing request.
Definition: dma_device.cc:201
Definition: system.hh:83
uint32_t pendingCount
Number of outstanding packets the dma port has.
Definition: dma_device.hh:129
virtual ~DmaDevice()
Definition: dma_device.hh:162
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
DmaPort & port
Definition: dma_device.hh:459
void handlePending()
Handle pending requests that have been flagged as done.
Definition: dma_device.cc:445
const Request::Flags reqFlags
Request flags.
Definition: dma_device.hh:457
bool dmaPending() const
Definition: dma_device.hh:149
std::deque< DmaDoneEventUPtr > freeRequests
Definition: dma_device.hh:513
Fifo< uint8_t > buffer
Definition: dma_device.hh:507
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:193
const MasterID masterId
Id for all requests.
Definition: dma_device.hh:119
const uint8_t * data() const
Definition: dma_device.hh:475
static const FlagsType AutoDelete
Definition: eventq.hh:103
const char data[]
Definition: circlebuf.cc:43
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: dma_device.cc:123
virtual ~DmaCallback()
Definition: dma_device.hh:219
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:230
DmaDoneEvent(DmaReadFifo *_parent, size_t max_size)
Definition: dma_device.cc:470
DmaDevice(const Params *p)
Definition: dma_device.cc:118
void stopFill()
Stop the DMA engine.
Definition: dma_device.cc:354
Bitfield< 4 > s
Definition: miscregs.hh:1738
bool isActive() const
Is the DMA engine active (i.e., are there still in-flight accesses)?
Definition: dma_device.hh:418
void dmaDone()
DMA request done, handle incoming data and issue new request.
Definition: dma_device.cc:433
DmaDeviceParams Params
Definition: dma_device.hh:160
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool tryGet(T &value)
Definition: dma_device.hh:352
void recvReqRetry() override
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
Definition: dma_device.cc:142
EventWrapper< DmaPort,&DmaPort::sendDma > sendEvent
Event used to schedule a future sending from the transmit list.
Definition: dma_device.hh:126
const Addr maxReqSize
Maximum request size in bytes.
Definition: dma_device.hh:448
unsigned int cacheBlockSize() const
Definition: dma_device.hh:180
size_t size() const
Definition: circlebuf.hh:227
std::vector< uint8_t > _data
Definition: dma_device.hh:483
virtual void onIdle()
Last response received callback.
Definition: dma_device.hh:448
const size_t fifoSize
Maximum FIFO size in bytes.
Definition: dma_device.hh:455
This device is the base class which all devices senstive to an address range inherit from...
Definition: io_device.hh:84
virtual void onEndOfBlock()
End of block callback.
Definition: dma_device.hh:435
BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a master port with a given name and index.
Definition: dma_device.cc:263
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: dma_device.cc:464
uint16_t MasterID
Definition: request.hh:85
Draining buffers pending serialization/handover.
System * sys
Definition: io_device.hh:87
Event invoked by DmaDevice on completion of each chunk.
Definition: dma_device.hh:246
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
System *const sys
The system that device/port are in.
Definition: dma_device.hh:116
Bitfield< 10, 5 > event
void resumeFillFunctional()
Try to bypass DMA requests in KVM execution mode.
Definition: dma_device.cc:386
Basic support for object serialization.
Definition: serialize.hh:220
A virtual base opaque structure used to hold state associated with the packet (e.g., an MSHR), specific to a MemObject that sees the packet.
Definition: packet.hh:377
RequestPtr dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, uint8_t *data, Tick delay, Request::Flags flag=0)
Definition: dma_device.cc:149
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: dma_device.cc:131
virtual void process()=0
Callback function invoked on completion of all chunks.
Event * getChunkEvent()
Request a chunk event.
Definition: dma_device.hh:265
DMA callback class.
Definition: dma_device.hh:195
STL deque class.
Definition: stl.hh:47
const Addr totBytes
Total number of bytes that this transaction involves.
Definition: dma_device.hh:97
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: dma_device.cc:317
DmaReqState(Event *ce, Addr tb, Tick _delay)
Definition: dma_device.hh:105
std::deque< DmaDoneEventUPtr > pendingRequests
Definition: dma_device.hh:512
size_t requestSize() const
Definition: dma_device.hh:474
void resumeFill()
Try to issue new DMA requests or bypass DMA requests.
Definition: dma_device.cc:367
int size()
Definition: pagetable.hh:146
std::ostream CheckpointOut
Definition: serialize.hh:67
Definition: eventq.hh:185
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
Definition: mem_object.hh:60
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:267
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
DmaChunkEvent(DmaCallback *cb)
Definition: dma_device.hh:252
static const Priority Default_Pri
Default is zero for historical reasons.
Definition: eventq.hh:148
void resumeFillTiming()
Try to issue new DMA requests during normal execution.
Definition: dma_device.cc:407
DmaPort(MemObject *dev, System *s)
Definition: dma_device.cc:56
bool tryGet(uint8_t *dst, size_t len)
Try to read data from the FIFO.
Definition: dma_device.cc:325
Event * completionEvent
Event to call on the device when this transaction (all packets) complete.
Definition: dma_device.hh:94
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
DmaPort dmaPort
Definition: dma_device.hh:157
DmaReadFifo(DmaPort &port, size_t size, unsigned max_req_size, unsigned max_pending, Request::Flags flags=0)
Definition: dma_device.cc:275
Command
List of all commands associated with a packet.
Definition: packet.hh:81
bool dmaPending() const
Definition: dma_device.hh:176
Bitfield< 0 > p
void flush()
Flush the FIFO.
Definition: dma_device.hh:376
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:133
virtual const std::string name() const
Definition: dma_device.hh:198
void reset(size_t size)
Definition: dma_device.cc:490
MemObject *const device
The device that owns this port.
Definition: dma_device.hh:112
std::deque< PacketPtr > transmitList
Use a deque as we never do any insertion or removal in the middle.
Definition: dma_device.hh:123
void flush()
Definition: circlebuf.hh:230

Generated on Fri Jun 9 2017 13:03:45 for gem5 by doxygen 1.8.6