be5756ab7bc3a2d27ddce8dbf112bdc6f021c2da
2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "base/chunk_generator.hh"
33 #include "base/trace.hh"
34 #include "dev/io_device.hh"
35 #include "sim/builder.hh"
36 #include "sim/system.hh"
39 PioPort::PioPort(PioDevice
*dev
, System
*s
, std::string pname
)
40 : SimpleTimingPort(dev
->name() + pname
, dev
), device(dev
)
45 PioPort::recvAtomic(PacketPtr pkt
)
47 return pkt
->isRead() ? device
->read(pkt
) : device
->write(pkt
);
51 PioPort::getDeviceAddressRanges(AddrRangeList
&resp
, bool &snoop
)
54 device
->addressRanges(resp
);
58 PioDevice::~PioDevice()
68 panic("Pio port not connected to anything!");
69 pioPort
->sendStatusChange(Port::RangeChange
);
74 PioDevice::drain(Event
*de
)
77 count
= pioPort
->drain(de
);
79 changeState(Draining
);
86 BasicPioDevice::addressRanges(AddrRangeList
&range_list
)
90 range_list
.push_back(RangeSize(pioAddr
, pioSize
));
94 DmaPort::DmaPort(DmaDevice
*dev
, System
*s
)
95 : Port(dev
->name() + "-dmaport", dev
), device(dev
), sys(s
),
96 pendingCount(0), actionInProgress(0), drainEvent(NULL
),
97 backoffTime(0), inRetry(false), backoffEvent(this)
101 DmaPort::recvTiming(PacketPtr pkt
)
105 if (pkt
->result
== Packet::Nacked
) {
106 DPRINTF(DMA
, "Received nacked %s addr %#x\n",
107 pkt
->cmdString(), pkt
->getAddr());
109 if (backoffTime
< device
->minBackoffDelay
)
110 backoffTime
= device
->minBackoffDelay
;
111 else if (backoffTime
< device
->maxBackoffDelay
)
114 backoffEvent
.reschedule(curTick
+ backoffTime
, true);
116 DPRINTF(DMA
, "Backoff time set to %d ticks\n", backoffTime
);
120 } else if (pkt
->senderState
) {
124 DPRINTF(DMA
, "Received response %s addr %#x size %#x\n",
125 pkt
->cmdString(), pkt
->getAddr(), pkt
->req
->getSize());
126 state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
129 assert(pendingCount
>= 0);
132 state
->numBytes
+= pkt
->req
->getSize();
133 assert(state
->totBytes
>= state
->numBytes
);
134 if (state
->totBytes
== state
->numBytes
) {
135 state
->completionEvent
->process();
141 if (pendingCount
== 0 && drainEvent
) {
142 drainEvent
->process();
146 panic("Got packet without sender state... huh?\n");
152 DmaDevice::DmaDevice(Params
*p
)
153 : PioDevice(p
), dmaPort(NULL
), minBackoffDelay(p
->min_backoff_delay
),
154 maxBackoffDelay(p
->max_backoff_delay
)
159 DmaDevice::drain(Event
*de
)
162 count
= pioPort
->drain(de
) + dmaPort
->drain(de
);
164 changeState(Draining
);
166 changeState(Drained
);
171 DmaPort::drain(Event
*de
)
173 if (pendingCount
== 0)
183 assert(transmitList
.size());
184 PacketPtr pkt
= transmitList
.front();
187 DPRINTF(DMA
, "Retry on %s addr %#x\n",
188 pkt
->cmdString(), pkt
->getAddr());
189 result
= sendTiming(pkt
);
191 DPRINTF(DMA
, "-- Done\n");
192 transmitList
.pop_front();
196 DPRINTF(DMA
, "-- Failed, queued\n");
198 } while (!backoffTime
&& result
&& transmitList
.size());
200 if (transmitList
.size() && backoffTime
&& !inRetry
) {
201 DPRINTF(DMA
, "Scheduling backoff for %d\n", curTick
+backoffTime
);
202 if (!backoffEvent
.scheduled())
203 backoffEvent
.schedule(backoffTime
+curTick
);
205 DPRINTF(DMA
, "TransmitList: %d, backoffTime: %d inRetry: %d es: %d\n",
206 transmitList
.size(), backoffTime
, inRetry
,
207 backoffEvent
.scheduled());
212 DmaPort::dmaAction(Packet::Command cmd
, Addr addr
, int size
, Event
*event
,
217 assert(device
->getState() == SimObject::Running
);
219 DmaReqState
*reqState
= new DmaReqState(event
, this, size
);
222 DPRINTF(DMA
, "Starting DMA for addr: %#x size: %d sched: %d\n", addr
, size
,
224 for (ChunkGenerator
gen(addr
, size
, peerBlockSize());
225 !gen
.done(); gen
.next()) {
226 Request
*req
= new Request(gen
.addr(), gen
.size(), 0);
227 PacketPtr pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
229 // Increment the data pointer on a write
231 pkt
->dataStatic(data
+ gen
.complete());
233 pkt
->senderState
= reqState
;
235 assert(pendingCount
>= 0);
237 DPRINTF(DMA
, "--Queuing DMA for addr: %#x size: %d\n", gen
.addr(),
245 DmaPort::queueDma(PacketPtr pkt
, bool front
)
249 transmitList
.push_front(pkt
);
251 transmitList
.push_back(pkt
);
259 // some kind of selction between access methods
260 // more work is going to have to be done to make
261 // switching actually work
262 assert(transmitList
.size());
263 PacketPtr pkt
= transmitList
.front();
265 System::MemoryMode state
= sys
->getMemoryMode();
266 if (state
== System::Timing
) {
267 if (backoffEvent
.scheduled() || inRetry
) {
268 DPRINTF(DMA
, "Can't send immediately, waiting for retry or backoff timer\n");
272 DPRINTF(DMA
, "Attempting to send %s addr %#x\n",
273 pkt
->cmdString(), pkt
->getAddr());
277 result
= sendTiming(pkt
);
279 transmitList
.pop_front();
280 DPRINTF(DMA
, "-- Done\n");
283 DPRINTF(DMA
, "-- Failed: queued\n");
285 } while (result
&& !backoffTime
&& transmitList
.size());
287 if (transmitList
.size() && backoffTime
&& !inRetry
&&
288 !backoffEvent
.scheduled()) {
289 DPRINTF(DMA
, "-- Scheduling backoff timer for %d\n",
290 backoffTime
+curTick
);
291 backoffEvent
.schedule(backoffTime
+curTick
);
293 } else if (state
== System::Atomic
) {
294 transmitList
.pop_front();
297 DPRINTF(DMA
, "--Sending DMA for addr: %#x size: %d\n",
298 pkt
->req
->getPaddr(), pkt
->req
->getSize());
299 lat
= sendAtomic(pkt
);
300 assert(pkt
->senderState
);
301 DmaReqState
*state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
303 state
->numBytes
+= pkt
->req
->getSize();
305 DPRINTF(DMA
, "--Received response for DMA for addr: %#x size: %d nb: %d, tot: %d sched %d\n",
306 pkt
->req
->getPaddr(), pkt
->req
->getSize(), state
->numBytes
,
307 state
->totBytes
, state
->completionEvent
->scheduled());
309 if (state
->totBytes
== state
->numBytes
) {
310 assert(!state
->completionEvent
->scheduled());
311 state
->completionEvent
->schedule(curTick
+ lat
);
316 assert(pendingCount
>= 0);
319 if (pendingCount
== 0 && drainEvent
) {
320 drainEvent
->process();
325 panic("Unknown memory command state.");
328 DmaDevice::~DmaDevice()