657739e2ca196c07081f31617896fc53a2ed8b09
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/system.hh"
38 PioPort::PioPort(PioDevice
*dev
, System
*s
, std::string pname
)
39 : SimpleTimingPort(dev
->name() + pname
, dev
), device(dev
)
44 PioPort::recvAtomic(PacketPtr pkt
)
46 return pkt
->isRead() ? device
->read(pkt
) : device
->write(pkt
);
50 PioPort::getDeviceAddressRanges(AddrRangeList
&resp
, bool &snoop
)
53 device
->addressRanges(resp
);
57 PioDevice::PioDevice(const Params
*p
)
58 : MemObject(p
), platform(p
->platform
), sys(p
->system
), pioPort(NULL
)
61 PioDevice::~PioDevice()
71 panic("Pio port not connected to anything!");
72 pioPort
->sendStatusChange(Port::RangeChange
);
77 PioDevice::drain(Event
*de
)
80 count
= pioPort
->drain(de
);
82 changeState(Draining
);
88 BasicPioDevice::BasicPioDevice(const Params
*p
)
89 : PioDevice(p
), pioAddr(p
->pio_addr
), pioSize(0),
90 pioDelay(p
->pio_latency
)
94 BasicPioDevice::addressRanges(AddrRangeList
&range_list
)
98 range_list
.push_back(RangeSize(pioAddr
, pioSize
));
102 DmaPort::DmaPort(DmaDevice
*dev
, System
*s
)
103 : Port(dev
->name() + "-dmaport", dev
), device(dev
), sys(s
),
104 pendingCount(0), actionInProgress(0), drainEvent(NULL
),
105 backoffTime(0), inRetry(false), backoffEvent(this)
109 DmaPort::recvTiming(PacketPtr pkt
)
113 if (pkt
->result
== Packet::Nacked
) {
114 DPRINTF(DMA
, "Received nacked %s addr %#x\n",
115 pkt
->cmdString(), pkt
->getAddr());
117 if (backoffTime
< device
->minBackoffDelay
)
118 backoffTime
= device
->minBackoffDelay
;
119 else if (backoffTime
< device
->maxBackoffDelay
)
122 backoffEvent
.reschedule(curTick
+ backoffTime
, true);
124 DPRINTF(DMA
, "Backoff time set to %d ticks\n", backoffTime
);
128 } else if (pkt
->senderState
) {
132 DPRINTF(DMA
, "Received response %s addr %#x size %#x\n",
133 pkt
->cmdString(), pkt
->getAddr(), pkt
->req
->getSize());
134 state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
137 assert(pendingCount
>= 0);
140 state
->numBytes
+= pkt
->req
->getSize();
141 assert(state
->totBytes
>= state
->numBytes
);
142 if (state
->totBytes
== state
->numBytes
) {
143 state
->completionEvent
->process();
149 if (pendingCount
== 0 && drainEvent
) {
150 drainEvent
->process();
154 panic("Got packet without sender state... huh?\n");
160 DmaDevice::DmaDevice(const Params
*p
)
161 : PioDevice(p
), dmaPort(NULL
), minBackoffDelay(p
->min_backoff_delay
),
162 maxBackoffDelay(p
->max_backoff_delay
)
167 DmaDevice::drain(Event
*de
)
170 count
= pioPort
->drain(de
) + dmaPort
->drain(de
);
172 changeState(Draining
);
174 changeState(Drained
);
179 DmaPort::drain(Event
*de
)
181 if (pendingCount
== 0)
191 assert(transmitList
.size());
192 PacketPtr pkt
= transmitList
.front();
195 DPRINTF(DMA
, "Retry on %s addr %#x\n",
196 pkt
->cmdString(), pkt
->getAddr());
197 result
= sendTiming(pkt
);
199 DPRINTF(DMA
, "-- Done\n");
200 transmitList
.pop_front();
204 DPRINTF(DMA
, "-- Failed, queued\n");
206 } while (!backoffTime
&& result
&& transmitList
.size());
208 if (transmitList
.size() && backoffTime
&& !inRetry
) {
209 DPRINTF(DMA
, "Scheduling backoff for %d\n", curTick
+backoffTime
);
210 if (!backoffEvent
.scheduled())
211 backoffEvent
.schedule(backoffTime
+curTick
);
213 DPRINTF(DMA
, "TransmitList: %d, backoffTime: %d inRetry: %d es: %d\n",
214 transmitList
.size(), backoffTime
, inRetry
,
215 backoffEvent
.scheduled());
220 DmaPort::dmaAction(Packet::Command cmd
, Addr addr
, int size
, Event
*event
,
225 assert(device
->getState() == SimObject::Running
);
227 DmaReqState
*reqState
= new DmaReqState(event
, this, size
);
230 DPRINTF(DMA
, "Starting DMA for addr: %#x size: %d sched: %d\n", addr
, size
,
232 for (ChunkGenerator
gen(addr
, size
, peerBlockSize());
233 !gen
.done(); gen
.next()) {
234 Request
*req
= new Request(gen
.addr(), gen
.size(), 0);
235 PacketPtr pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
237 // Increment the data pointer on a write
239 pkt
->dataStatic(data
+ gen
.complete());
241 pkt
->senderState
= reqState
;
243 assert(pendingCount
>= 0);
245 DPRINTF(DMA
, "--Queuing DMA for addr: %#x size: %d\n", gen
.addr(),
253 DmaPort::queueDma(PacketPtr pkt
, bool front
)
257 transmitList
.push_front(pkt
);
259 transmitList
.push_back(pkt
);
267 // some kind of selction between access methods
268 // more work is going to have to be done to make
269 // switching actually work
270 assert(transmitList
.size());
271 PacketPtr pkt
= transmitList
.front();
273 Enums::MemoryMode state
= sys
->getMemoryMode();
274 if (state
== Enums::timing
) {
275 if (backoffEvent
.scheduled() || inRetry
) {
276 DPRINTF(DMA
, "Can't send immediately, waiting for retry or backoff timer\n");
280 DPRINTF(DMA
, "Attempting to send %s addr %#x\n",
281 pkt
->cmdString(), pkt
->getAddr());
285 result
= sendTiming(pkt
);
287 transmitList
.pop_front();
288 DPRINTF(DMA
, "-- Done\n");
291 DPRINTF(DMA
, "-- Failed: queued\n");
293 } while (result
&& !backoffTime
&& transmitList
.size());
295 if (transmitList
.size() && backoffTime
&& !inRetry
&&
296 !backoffEvent
.scheduled()) {
297 DPRINTF(DMA
, "-- Scheduling backoff timer for %d\n",
298 backoffTime
+curTick
);
299 backoffEvent
.schedule(backoffTime
+curTick
);
301 } else if (state
== Enums::atomic
) {
302 transmitList
.pop_front();
305 DPRINTF(DMA
, "--Sending DMA for addr: %#x size: %d\n",
306 pkt
->req
->getPaddr(), pkt
->req
->getSize());
307 lat
= sendAtomic(pkt
);
308 assert(pkt
->senderState
);
309 DmaReqState
*state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
311 state
->numBytes
+= pkt
->req
->getSize();
313 DPRINTF(DMA
, "--Received response for DMA for addr: %#x size: %d nb: %d, tot: %d sched %d\n",
314 pkt
->req
->getPaddr(), pkt
->req
->getSize(), state
->numBytes
,
315 state
->totBytes
, state
->completionEvent
->scheduled());
317 if (state
->totBytes
== state
->numBytes
) {
318 assert(!state
->completionEvent
->scheduled());
319 state
->completionEvent
->schedule(curTick
+ lat
);
324 assert(pendingCount
>= 0);
327 if (pendingCount
== 0 && drainEvent
) {
328 drainEvent
->process();
333 panic("Unknown memory command state.");
336 DmaDevice::~DmaDevice()