: RequestPort(dev->name() + ".dma", dev),
device(dev), sys(s), requestorId(s->getRequestorId(dev)),
sendEvent([this]{ sendDma(); }, dev->name()),
- pendingCount(0), inRetry(false),
- defaultSid(sid),
- defaultSSid(ssid)
+ defaultSid(sid), defaultSSid(ssid)
{ }
void
assert(pkt->isResponse());
// get the DMA sender state
- DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState);
+ auto *state = dynamic_cast<DmaReqState*>(pkt->senderState);
assert(state);
DPRINTF(DMA, "Received response %s for addr: %#x size: %d nb: %d," \
void
DmaDevice::init()
{
- if (!dmaPort.isConnected())
- panic("DMA port of %s not connected to anything!", name());
+ panic_if(!dmaPort.isConnected(),
+ "DMA port of %s not connected to anything!", name());
PioDevice::init();
}
// We're only interested in this when there will only be one request.
// For simplicity, we return the last request, which would also be
// the only request in that case.
- RequestPtr req = NULL;
+ RequestPtr req = nullptr;
DPRINTF(DMA, "Starting DMA for addr: %#x size: %d sched: %d\n", addr, size,
event ? event->scheduled() : -1);
handleResp(pkt, lat);
}
- } else
+ } else {
panic("Unknown memory mode.");
+ }
}
Port &
unsigned max_pending,
Request::Flags flags)
: maxReqSize(max_req_size), fifoSize(size),
- reqFlags(flags), port(_port),
- buffer(size),
- nextAddr(0), endAddr(0)
+ reqFlags(flags), port(_port), buffer(size)
{
freeRequests.resize(max_pending);
for (auto &e : freeRequests)
void
DmaReadFifo::get(uint8_t *dst, size_t len)
{
- const bool success(tryGet(dst, len));
- panic_if(!success, "Buffer underrun in DmaReadFifo::get()\n");
+ panic_if(!tryGet(dst, len), "Buffer underrun in DmaReadFifo::get()");
}
void
DrainState
DmaReadFifo::drain()
{
- return pendingRequests.empty() ? DrainState::Drained : DrainState::Draining;
+ return pendingRequests.empty() ?
+ DrainState::Drained : DrainState::Draining;
}
-DmaReadFifo::DmaDoneEvent::DmaDoneEvent(DmaReadFifo *_parent,
- size_t max_size)
- : parent(_parent), _done(false), _canceled(false), _data(max_size, 0)
+DmaReadFifo::DmaDoneEvent::DmaDoneEvent(DmaReadFifo *_parent, size_t max_size)
+ : parent(_parent), _data(max_size, 0)
{
}
* @param pkt Response packet to handler
* @param delay Additional delay for scheduling the completion event
*/
- void handleResp(PacketPtr pkt, Tick delay = 0);
+ void handleResp(PacketPtr pkt, Tick delay=0);
struct DmaReqState : public Packet::SenderState
{
const Addr totBytes;
/** Number of bytes that have been acked for this transaction. */
- Addr numBytes;
+ Addr numBytes = 0;
/** Amount to delay completion of dma by */
const Tick delay;
DmaReqState(Event *ce, Addr tb, Tick _delay)
- : completionEvent(ce), totBytes(tb), numBytes(0), delay(_delay)
+ : completionEvent(ce), totBytes(tb), delay(_delay)
{}
};
EventFunctionWrapper sendEvent;
/** Number of outstanding packets the dma port has. */
- uint32_t pendingCount;
+ uint32_t pendingCount = 0;
/** If the port is currently waiting for a retry before it can
* send whatever it is that it's sending. */
- bool inRetry;
+ bool inRetry = false;
/** Default streamId */
const uint32_t defaultSid;
public:
- DmaPort(ClockedObject *dev, System *s,
- uint32_t sid = 0, uint32_t ssid = 0);
+ DmaPort(ClockedObject *dev, System *s, uint32_t sid=0, uint32_t ssid=0);
RequestPtr
dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
- uint8_t *data, Tick delay, Request::Flags flag = 0);
+ uint8_t *data, Tick delay, Request::Flags flag=0);
RequestPtr
dmaAction(Packet::Command cmd, Addr addr, int size, Event *event,
uint8_t *data, uint32_t sid, uint32_t ssid, Tick delay,
- Request::Flags flag = 0);
+ Request::Flags flag=0);
bool dmaPending() const { return pendingCount > 0; }
public:
typedef DmaDeviceParams Params;
DmaDevice(const Params &p);
- virtual ~DmaDevice() { }
+ virtual ~DmaDevice() = default;
- void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
- uint32_t sid, uint32_t ssid, Tick delay = 0)
+ void
+ dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
+ uint32_t sid, uint32_t ssid, Tick delay=0)
{
dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data,
sid, ssid, delay);
}
- void dmaWrite(Addr addr, int size, Event *event, uint8_t *data,
- Tick delay = 0)
+ void
+ dmaWrite(Addr addr, int size, Event *event, uint8_t *data, Tick delay=0)
{
dmaPort.dmaAction(MemCmd::WriteReq, addr, size, event, data, delay);
}
- void dmaRead(Addr addr, int size, Event *event, uint8_t *data,
- uint32_t sid, uint32_t ssid, Tick delay = 0)
+ void
+ dmaRead(Addr addr, int size, Event *event, uint8_t *data,
+ uint32_t sid, uint32_t ssid, Tick delay=0)
{
dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data,
sid, ssid, delay);
}
- 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, Tick delay=0)
{
dmaPort.dmaAction(MemCmd::ReadReq, addr, size, event, data, delay);
}
* complete until count is 0, which ensures that all outstanding
* DmaChunkEvents associated with this DmaCallback have fired.
*/
- DrainState drain() override
+ DrainState
+ drain() override
{
return count ? DrainState::Draining : DrainState::Drained;
}
protected:
- int count;
+ int count = 0;
- DmaCallback()
- : count(0)
- { }
-
- virtual ~DmaCallback() { }
+ virtual ~DmaCallback() = default;
/**
* Callback function invoked on completion of all chunks.
* Since the object may delete itself here, callers should not use
* the object pointer after calling this function.
*/
- void chunkComplete()
+ void
+ chunkComplete()
{
if (--count == 0) {
process();
* Request a chunk event. Chunks events should be provided to each DMA
* request that wishes to participate in this DmaCallback.
*/
- Event *getChunkEvent()
+ Event *
+ getChunkEvent()
{
++count;
return new EventFunctionWrapper([this]{ chunkComplete(); }, name(),
DmaReadFifo(DmaPort &port, size_t size,
unsigned max_req_size,
unsigned max_pending,
- Request::Flags flags = 0);
+ Request::Flags flags=0);
~DmaReadFifo();
bool tryGet(uint8_t *dst, size_t len);
template<typename T>
- bool tryGet(T &value) {
+ bool
+ tryGet(T &value)
+ {
return tryGet(static_cast<T *>(&value), sizeof(T));
};
void get(uint8_t *dst, size_t len);
template<typename T>
- T get() {
+ T
+ get()
+ {
T value;
get(static_cast<uint8_t *>(&value), sizeof(T));
return value;
* Has the DMA engine sent out the last request for the active
* block?
*/
- bool atEndOfBlock() const {
- return nextAddr == endAddr;
- }
+ bool atEndOfBlock() const { return nextAddr == endAddr; }
/**
* Is the DMA engine active (i.e., are there still in-flight
* accesses)?
*/
- bool isActive() const {
+ bool
+ isActive() const
+ {
return !(pendingRequests.empty() && atEndOfBlock());
}
private:
DmaReadFifo *parent;
- bool _done;
- bool _canceled;
+ bool _done = false;
+ bool _canceled = false;
size_t _requestSize;
std::vector<uint8_t> _data;
};
private: // Internal state
Fifo<uint8_t> buffer;
- Addr nextAddr;
- Addr endAddr;
+ Addr nextAddr = 0;
+ Addr endAddr = 0;
std::deque<DmaDoneEventUPtr> pendingRequests;
std::deque<DmaDoneEventUPtr> freeRequests;