ed2862065bbc99231e574fe87674ceb5c30e13ac
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/trace.hh"
33 #include "dev/io_device.hh"
34 #include "sim/builder.hh"
35 #include "sim/system.hh"
38 PioPort::PioPort(PioDevice
*dev
, System
*s
, std::string pname
)
39 : Port(dev
->name() + pname
), device(dev
), sys(s
),
40 outTiming(0), drainEvent(NULL
)
45 PioPort::recvAtomic(Packet
*pkt
)
47 return device
->recvAtomic(pkt
);
51 PioPort::recvFunctional(Packet
*pkt
)
53 device
->recvAtomic(pkt
);
57 PioPort::getDeviceAddressRanges(AddrRangeList
&resp
, AddrRangeList
&snoop
)
60 device
->addressRanges(resp
);
68 while (result
&& transmitList
.size()) {
69 result
= Port::sendTiming(transmitList
.front());
71 transmitList
.pop_front();
73 if (transmitList
.size() == 0 && drainEvent
) {
74 drainEvent
->process();
80 PioPort::SendEvent::process()
83 assert(port
->outTiming
>= 0);
84 if (port
->Port::sendTiming(packet
))
85 if (port
->transmitList
.size() == 0 && port
->drainEvent
) {
86 port
->drainEvent
->process();
87 port
->drainEvent
= NULL
;
91 port
->transmitList
.push_back(packet
);
95 PioPort::resendNacked(Packet
*pkt
) {
97 if (transmitList
.size()) {
98 transmitList
.push_front(pkt
);
100 if (!Port::sendTiming(pkt
))
101 transmitList
.push_front(pkt
);
107 PioPort::recvTiming(Packet
*pkt
)
109 if (pkt
->result
== Packet::Nacked
) {
112 Tick latency
= device
->recvAtomic(pkt
);
113 // turn packet around to go back to requester
114 pkt
->makeTimingResponse();
115 sendTiming(pkt
, latency
);
121 PioPort::drain(Event
*de
)
123 if (outTiming
== 0 && transmitList
.size() == 0)
129 PioDevice::~PioDevice()
139 panic("Pio port not connected to anything!");
140 pioPort
->sendStatusChange(Port::RangeChange
);
145 PioDevice::drain(Event
*de
)
148 count
= pioPort
->drain(de
);
150 changeState(Draining
);
152 changeState(Drained
);
157 BasicPioDevice::addressRanges(AddrRangeList
&range_list
)
159 assert(pioSize
!= 0);
161 range_list
.push_back(RangeSize(pioAddr
, pioSize
));
165 DmaPort::DmaPort(DmaDevice
*dev
, System
*s
)
166 : Port(dev
->name() + "-dmaport"), device(dev
), sys(s
), pendingCount(0),
167 actionInProgress(0), drainEvent(NULL
)
171 DmaPort::recvTiming(Packet
*pkt
)
175 if (pkt
->result
== Packet::Nacked
) {
176 DPRINTF(DMA
, "Received nacked Pkt %#x with State: %#x Addr: %#x\n",
177 pkt
, pkt
->senderState
, pkt
->getAddr());
180 } else if (pkt
->senderState
) {
182 DPRINTF(DMA
, "Received response Pkt %#x with State: %#x Addr: %#x\n",
183 pkt
, pkt
->senderState
, pkt
->getAddr());
184 state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
187 assert(pendingCount
>= 0);
190 state
->numBytes
+= pkt
->req
->getSize();
191 if (state
->totBytes
== state
->numBytes
) {
192 state
->completionEvent
->process();
198 if (pendingCount
== 0 && drainEvent
) {
199 drainEvent
->process();
203 panic("Got packet without sender state... huh?\n");
209 DmaDevice::DmaDevice(Params
*p
)
210 : PioDevice(p
), dmaPort(NULL
)
215 DmaDevice::drain(Event
*de
)
218 count
= pioPort
->drain(de
) + dmaPort
->drain(de
);
220 changeState(Draining
);
222 changeState(Drained
);
227 DmaPort::drain(Event
*de
)
229 if (pendingCount
== 0)
239 Packet
* pkt
= transmitList
.front();
241 while (result
&& transmitList
.size()) {
242 DPRINTF(DMA
, "Retry on Packet %#x with senderState: %#x\n",
243 pkt
, pkt
->senderState
);
244 result
= sendTiming(pkt
);
246 DPRINTF(DMA
, "-- Done\n");
247 transmitList
.pop_front();
249 DPRINTF(DMA
, "-- Failed, queued\n");
256 DmaPort::dmaAction(Packet::Command cmd
, Addr addr
, int size
, Event
*event
,
261 assert(device
->getState() == SimObject::Running
);
263 DmaReqState
*reqState
= new DmaReqState(event
, this, size
);
265 for (ChunkGenerator
gen(addr
, size
, peerBlockSize());
266 !gen
.done(); gen
.next()) {
267 Request
*req
= new Request(gen
.addr(), gen
.size(), 0);
268 Packet
*pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
270 // Increment the data pointer on a write
272 pkt
->dataStatic(data
+ gen
.complete());
274 pkt
->senderState
= reqState
;
276 assert(pendingCount
>= 0);
285 DmaPort::sendDma(Packet
*pkt
, bool front
)
287 // some kind of selction between access methods
288 // more work is going to have to be done to make
289 // switching actually work
290 System::MemoryMode state
= sys
->getMemoryMode();
291 if (state
== System::Timing
) {
292 DPRINTF(DMA
, "Attempting to send Packet %#x with addr: %#x\n",
293 pkt
, pkt
->getAddr());
294 if (transmitList
.size() || !sendTiming(pkt
)) {
296 transmitList
.push_front(pkt
);
298 transmitList
.push_back(pkt
);
299 DPRINTF(DMA
, "-- Failed: queued\n");
301 DPRINTF(DMA
, "-- Done\n");
303 } else if (state
== System::Atomic
) {
305 assert(pkt
->senderState
);
306 DmaReqState
*state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
309 state
->numBytes
+= pkt
->req
->getSize();
310 if (state
->totBytes
== state
->numBytes
) {
311 state
->completionEvent
->schedule(curTick
+
312 (pkt
->time
- pkt
->req
->getTime()) +1);
317 assert(pendingCount
>= 0);
320 if (pendingCount
== 0 && drainEvent
) {
321 drainEvent
->process();
326 panic("Unknown memory command state.");
329 DmaDevice::~DmaDevice()