b06e8b85d4580ffc8e0e5f15e9c8e52198fc166a
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
), device(dev
), sys(s
)
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
);
65 PioPort::recvTiming(Packet
*pkt
)
67 if (pkt
->result
== Packet::Nacked
) {
70 Tick latency
= device
->recvAtomic(pkt
);
71 // turn packet around to go back to requester
72 pkt
->makeTimingResponse();
73 sendTiming(pkt
, latency
);
78 PioDevice::~PioDevice()
88 panic("Pio port not connected to anything!");
89 pioPort
->sendStatusChange(Port::RangeChange
);
94 PioDevice::drain(Event
*de
)
97 count
= pioPort
->drain(de
);
99 changeState(Draining
);
101 changeState(Drained
);
106 BasicPioDevice::addressRanges(AddrRangeList
&range_list
)
108 assert(pioSize
!= 0);
110 range_list
.push_back(RangeSize(pioAddr
, pioSize
));
114 DmaPort::DmaPort(DmaDevice
*dev
, System
*s
)
115 : Port(dev
->name() + "-dmaport"), device(dev
), sys(s
), pendingCount(0),
116 actionInProgress(0), drainEvent(NULL
)
120 DmaPort::recvTiming(Packet
*pkt
)
124 if (pkt
->result
== Packet::Nacked
) {
125 DPRINTF(DMA
, "Received nacked Pkt %#x with State: %#x Addr: %#x\n",
126 pkt
, pkt
->senderState
, pkt
->getAddr());
129 } else if (pkt
->senderState
) {
131 DPRINTF(DMA
, "Received response Pkt %#x with State: %#x Addr: %#x\n",
132 pkt
, pkt
->senderState
, pkt
->getAddr());
133 state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
136 assert(pendingCount
>= 0);
139 state
->numBytes
+= pkt
->req
->getSize();
140 if (state
->totBytes
== state
->numBytes
) {
141 state
->completionEvent
->process();
147 if (pendingCount
== 0 && drainEvent
) {
148 drainEvent
->process();
152 panic("Got packet without sender state... huh?\n");
158 DmaDevice::DmaDevice(Params
*p
)
159 : PioDevice(p
), dmaPort(NULL
)
164 DmaDevice::drain(Event
*de
)
167 count
= pioPort
->drain(de
) + dmaPort
->drain(de
);
169 changeState(Draining
);
171 changeState(Drained
);
176 DmaPort::drain(Event
*de
)
178 if (pendingCount
== 0)
188 Packet
* pkt
= transmitList
.front();
190 while (result
&& transmitList
.size()) {
191 DPRINTF(DMA
, "Retry on Packet %#x with senderState: %#x\n",
192 pkt
, pkt
->senderState
);
193 result
= sendTiming(pkt
);
195 DPRINTF(DMA
, "-- Done\n");
196 transmitList
.pop_front();
198 DPRINTF(DMA
, "-- Failed, queued\n");
205 DmaPort::dmaAction(Packet::Command cmd
, Addr addr
, int size
, Event
*event
,
210 assert(device
->getState() == SimObject::Running
);
212 DmaReqState
*reqState
= new DmaReqState(event
, this, size
);
214 for (ChunkGenerator
gen(addr
, size
, peerBlockSize());
215 !gen
.done(); gen
.next()) {
216 Request
*req
= new Request(gen
.addr(), gen
.size(), 0);
217 Packet
*pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
219 // Increment the data pointer on a write
221 pkt
->dataStatic(data
+ gen
.complete());
223 pkt
->senderState
= reqState
;
225 assert(pendingCount
>= 0);
234 DmaPort::sendDma(Packet
*pkt
, bool front
)
236 // some kind of selction between access methods
237 // more work is going to have to be done to make
238 // switching actually work
240 System::MemoryMode state
= sys
->getMemoryMode();
241 if (state
== System::Timing
) {
242 DPRINTF(DMA
, "Attempting to send Packet %#x with addr: %#x\n",
243 pkt
, pkt
->getAddr());
244 if (transmitList
.size() || !sendTiming(pkt
)) {
246 transmitList
.push_front(pkt
);
248 transmitList
.push_back(pkt
);
249 DPRINTF(DMA
, "-- Failed: queued\n");
251 DPRINTF(DMA
, "-- Done\n");
253 } else if (state
== System::Atomic
) {
255 lat
= sendAtomic(pkt
);
256 assert(pkt
->senderState
);
257 DmaReqState
*state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
260 state
->numBytes
+= pkt
->req
->getSize();
261 if (state
->totBytes
== state
->numBytes
) {
262 state
->completionEvent
->schedule(curTick
+ lat
);
267 assert(pendingCount
>= 0);
270 if (pendingCount
== 0 && drainEvent
) {
271 drainEvent
->process();
276 panic("Unknown memory command state.");
279 DmaDevice::~DmaDevice()