gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
49#include "base/circlebuf.hh"
50#include "dev/io_device.hh"
51#include "mem/backdoor.hh"
52#include "params/DmaDevice.hh"
53#include "sim/drain.hh"
54#include "sim/system.hh"
55
56namespace gem5
57{
58
59class ClockedObject;
60
61class DmaPort : public RequestPort, public Drainable
62{
63 private:
65
71 void trySendTimingReq();
72
80 void sendDma();
81
83 {
87
90
92 bool aborted = false;
93
96
99
101 const Tick delay;
102
105
107 uint8_t *const data = nullptr;
108
111
114
116 const uint32_t sid;
117 const uint32_t ssid;
118
121
123 uint8_t *_data, Request::Flags _flags, RequestorID _id,
124 uint32_t _sid, uint32_t _ssid, Event *ce, Tick _delay,
125 Event *ae=nullptr)
126 : completionEvent(ce), abortEvent(ae), totBytes(tb), delay(_delay),
127 gen(addr, tb, chunk_sz), data(_data), flags(_flags), id(_id),
128 sid(_sid), ssid(_ssid), cmd(_cmd)
129 {}
130
132 };
133
135 bool sendAtomicReq(DmaReqState *state);
140 bool sendAtomicBdReq(DmaReqState *state);
141
152 void handleRespPacket(PacketPtr pkt, Tick delay=0);
153 void handleResp(DmaReqState *state, Addr addr, Addr size, Tick delay=0);
154
155 public:
158
161 System *const sys;
162
165
166 protected:
169
172
174 uint32_t pendingCount = 0;
175
182 bool retryPending = false;
183
185 const uint32_t defaultSid;
186
188 const uint32_t defaultSSid;
189
191
192 protected:
193
194 bool recvTimingResp(PacketPtr pkt) override;
195 void recvReqRetry() override;
196
197 public:
198
199 DmaPort(ClockedObject *dev, System *s, uint32_t sid=0, uint32_t ssid=0);
200
201 void
202 dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
203 uint8_t *data, Tick delay, Request::Flags flag=0);
204
205 void
206 dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
207 uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay,
208 Request::Flags flag=0);
209
210 // Abort and remove any pending DMA transmissions.
211 void abortPending();
212
213 bool dmaPending() const { return pendingCount > 0; }
214
215 DrainState drain() override;
216};
217
218class DmaDevice : public PioDevice
219{
220 protected:
222
223 public:
224 typedef DmaDeviceParams Params;
225 DmaDevice(const Params &p);
226 virtual ~DmaDevice() = default;
227
228 void
229 dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
230 uint32_t sid, uint32_t ssid, Tick delay=0)
231 {
233 sid, ssid, delay);
234 }
235
236 void
237 dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
238 {
240 }
241
242 void
243 dmaRead(Addr addr, int size, Event *event, uint8_t *data,
244 uint32_t sid, uint32_t ssid, Tick delay=0)
245 {
247 sid, ssid, delay);
248 }
249
250 void
251 dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
252 {
254 }
255
256 bool dmaPending() const { return dmaPort.dmaPending(); }
257
258 void init() override;
259
260 Addr cacheBlockSize() const { return sys->cacheLineSize(); }
261
262 Port &getPort(const std::string &if_name,
263 PortID idx=InvalidPortID) override;
264
265};
266
275class DmaCallback : public Drainable
276{
277 public:
278 virtual const std::string name() const { return "DmaCallback"; }
279
288 drain() override
289 {
291 }
292
293 protected:
294 int count = 0;
295
296 virtual ~DmaCallback() = default;
297
301 virtual void process() = 0;
302
303 private:
309 void
311 {
312 if (--count == 0) {
313 process();
314 // Need to notify DrainManager that this object is finished
315 // draining, even though it is immediately deleted.
317 delete this;
318 }
319 }
320
321 public:
322
327 Event *
329 {
330 ++count;
331 return new EventFunctionWrapper([this]{ chunkComplete(); }, name(),
332 true);
333 }
334};
335
379class DmaReadFifo : public Drainable, public Serializable
380{
381 public:
382 DmaReadFifo(DmaPort &port, size_t size,
383 unsigned max_req_size,
384 unsigned max_pending,
386
387 ~DmaReadFifo();
388
389 public: // Serializable
390 void serialize(CheckpointOut &cp) const override;
391 void unserialize(CheckpointIn &cp) override;
392
393 public: // Drainable
394 DrainState drain() override;
395
396 public: // FIFO access
413 bool tryGet(uint8_t *dst, size_t len);
414
415 template<typename T>
416 bool
417 tryGet(T &value)
418 {
419 return tryGet(static_cast<T *>(&value), sizeof(T));
420 };
421
430 void get(uint8_t *dst, size_t len);
431
432 template<typename T>
433 T
435 {
436 T value;
437 get(static_cast<uint8_t *>(&value), sizeof(T));
438 return value;
439 };
440
442 size_t size() const { return buffer.size(); }
444 void flush() { buffer.flush(); }
445
447 public: // FIFO fill control
462 void startFill(Addr start, size_t size);
463
472 void stopFill();
473
478 bool atEndOfBlock() const { return nextAddr == endAddr; }
479
484 bool
485 isActive() const
486 {
487 return !(pendingRequests.empty() && atEndOfBlock());
488 }
489
491 protected: // Callbacks
503 virtual void onEndOfBlock() {};
504
516 virtual void onIdle() {};
517
519 private: // Configuration
523 const size_t fifoSize;
526
528
530
531 private:
532 class DmaDoneEvent : public Event
533 {
534 public:
535 DmaDoneEvent(DmaReadFifo *_parent, size_t max_size);
536
537 void kill();
538 void cancel();
539 bool canceled() const { return _canceled; }
540 void reset(size_t size);
541 void process();
542
543 bool done() const { return _done; }
544 size_t requestSize() const { return _requestSize; }
545 const uint8_t *data() const { return _data.data(); }
546 uint8_t *data() { return _data.data(); }
547
548 private:
550 bool _done = false;
551 bool _canceled = false;
554 };
555
556 typedef std::unique_ptr<DmaDoneEvent> DmaDoneEventUPtr;
557
562 void dmaDone();
563
565 void handlePending();
566
568 void resumeFill();
569
571 void resumeFillTiming();
572
574 void resumeFillBypass();
575
576 private: // Internal state
578
581
584};
585
586} // namespace gem5
587
588#endif // __DEV_DMA_DEVICE_HH__
Declaration and inline definition of ChunkGenerator object.
const char data[]
The AddrRangeMap uses an STL map to implement an interval tree for address decoding.
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
DMA callback class.
Event * getChunkEvent()
Request a chunk event.
void chunkComplete()
Called by DMA engine completion event on each chunk completion.
virtual ~DmaCallback()=default
DrainState drain() override
DmaPort ensures that all oustanding DMA accesses have completed before it finishes draining.
virtual const std::string name() const
virtual void process()=0
Callback function invoked on completion of all chunks.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
bool dmaPending() const
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
void dmaRead(Addr addr, int size, Event *event, uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay=0)
virtual ~DmaDevice()=default
Addr cacheBlockSize() const
void dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
DmaDevice(const Params &p)
DmaDeviceParams Params
void abortPending()
bool dmaPending() const
ClockedObject *const device
The device that owns this port.
EventFunctionWrapper sendEvent
Event used to schedule a future sending from the transmit list.
System *const sys
The system that device/port are in.
void dmaAction(Packet::Command cmd, Addr addr, int size, Event *event, uint8_t *data, Tick delay, Request::Flags flag=0)
bool sendAtomicBdReq(DmaReqState *state)
Send the next packet from a DMA request in atomic mode, and request and/or use memory backdoors if po...
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
DmaPort(ClockedObject *dev, System *s, uint32_t sid=0, uint32_t ssid=0)
Definition dma_device.cc:58
void trySendTimingReq()
Take the first request on the transmit list and attempt to send a timing packet from it.
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
PacketPtr inRetry
The packet (if any) waiting for a retry to send.
uint32_t pendingCount
Number of outstanding packets the dma port has.
std::deque< DmaReqState * > transmitList
Use a deque as we never do any insertion or removal in the middle.
AddrRangeMap< MemBackdoorPtr, 1 > memBackdoors
Definition dma_device.hh:64
void sendDma()
For timing, attempt to send the first item on the transmit list, and if it is successful and there ar...
const uint32_t defaultSid
Default streamId.
void handleResp(DmaReqState *state, Addr addr, Addr size, Tick delay=0)
Definition dma_device.cc:83
bool retryPending
Whether the other side expects us to wait for a retry.
const RequestorID requestorId
Id for all requests.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
bool sendAtomicReq(DmaReqState *state)
Send the next packet from a DMA request in atomic mode.
const uint32_t defaultSSid
Default substreamId.
void handleRespPacket(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:67
const Addr cacheLineSize
std::vector< uint8_t > _data
const uint8_t * data() const
DmaDoneEvent(DmaReadFifo *_parent, size_t max_size)
Buffered DMA engine helper class.
Fifo< uint8_t > buffer
void serialize(CheckpointOut &cp) const override
Serialize an object.
size_t size() const
Get the amount of data stored in the FIFO.
bool tryGet(T &value)
virtual void onIdle()
Last response received callback.
bool tryGet(uint8_t *dst, size_t len)
Try to read data from the FIFO.
void startFill(Addr start, size_t size)
Start filling the FIFO.
DmaReadFifo(DmaPort &port, size_t size, unsigned max_req_size, unsigned max_pending, Request::Flags flags=0)
const Request::Flags reqFlags
Request flags.
virtual void onEndOfBlock()
End of block callback.
void resumeFill()
Try to issue new DMA requests or bypass DMA requests.
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
void unserialize(CheckpointIn &cp) override
Unserialize an object.
std::deque< DmaDoneEventUPtr > freeRequests
void flush()
Flush the FIFO.
void dmaDone()
DMA request done, handle incoming data and issue new request.
bool isActive() const
Is the DMA engine active (i.e., are there still in-flight accesses)?
void stopFill()
Stop the DMA engine.
void resumeFillBypass()
Try to bypass DMA requests in non-caching mode.
bool atEndOfBlock() const
Has the DMA engine sent out the last request for the active block?
const Addr maxReqSize
Maximum request size in bytes.
const size_t fifoSize
Maximum FIFO size in bytes.
void handlePending()
Handle pending requests that have been flagged as done.
const Addr cacheLineSize
void resumeFillTiming()
Try to issue new DMA requests during normal execution.
std::unique_ptr< DmaDoneEvent > DmaDoneEventUPtr
std::deque< DmaDoneEventUPtr > pendingRequests
Interface for objects that might require draining before checkpointing.
Definition drain.hh:235
Simple FIFO implementation backed by a circular buffer.
Definition circlebuf.hh:214
void flush()
Definition circlebuf.hh:225
size_t size() const
Definition circlebuf.hh:222
Command
List of all commands associated with a packet.
Definition packet.hh:85
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
This device is the base class which all devices senstive to an address range inherit from.
Definition io_device.hh:103
Ports are used to interface objects to each other.
Definition port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
Basic support for object serialization.
Definition serialize.hh:170
Addr cacheLineSize() const
Get the cache line size of the system.
Definition system.hh:308
STL deque class.
Definition stl.hh:44
STL vector class.
Definition stl.hh:37
void signalDrainDone() const
Signal that an object is drained.
Definition drain.hh:305
DrainState
Object drain/handover states.
Definition drain.hh:75
@ Draining
Draining buffers pending serialization/handover.
@ Drained
Buffers drained, ready for serialization/handover.
atomic_var_t state
Definition helpers.cc:211
uint8_t flags
Definition helpers.cc:87
Bitfield< 18, 16 > len
Bitfield< 4 > s
Bitfield< 10, 5 > event
Bitfield< 29, 28 > ce
Bitfield< 27 > tb
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
const Packet::Command cmd
Command for the request.
const Addr totBytes
Total number of bytes that this transaction involves.
Definition dma_device.hh:95
Event * completionEvent
Event to call on the device when this transaction (all packets) complete.
Definition dma_device.hh:86
Addr numBytes
Number of bytes that have been acked for this transaction.
Definition dma_device.hh:98
const uint32_t sid
Stream IDs.
const RequestorID id
The requestor ID to use for requests.
const Tick delay
Amount to delay completion of dma by.
DmaReqState(Packet::Command _cmd, Addr addr, Addr chunk_sz, Addr tb, uint8_t *_data, Request::Flags _flags, RequestorID _id, uint32_t _sid, uint32_t _ssid, Event *ce, Tick _delay, Event *ae=nullptr)
ChunkGenerator gen
Object to track what chunks of bytes to send at a time.
uint8_t *const data
Pointer to a buffer for the data.
Event * abortEvent
Event to call on the device when this transaction is aborted.
Definition dma_device.hh:89
const Request::Flags flags
The flags to use for requests.
bool aborted
Whether this request was aborted.
Definition dma_device.hh:92
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition packet.hh:469

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0