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
, AddrRangeList
&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
)
100 DmaPort::recvTiming(PacketPtr pkt
)
104 if (pkt
->result
== Packet::Nacked
) {
105 DPRINTF(DMA
, "Received nacked Pkt %#x with State: %#x Addr: %#x\n",
106 pkt
, pkt
->senderState
, pkt
->getAddr());
109 } else if (pkt
->senderState
) {
111 DPRINTF(DMA
, "Received response Pkt %#x with State: %#x Addr: %#x\n",
112 pkt
, pkt
->senderState
, pkt
->getAddr());
113 state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
116 assert(pendingCount
>= 0);
119 state
->numBytes
+= pkt
->req
->getSize();
120 if (state
->totBytes
== state
->numBytes
) {
121 state
->completionEvent
->process();
127 if (pendingCount
== 0 && drainEvent
) {
128 drainEvent
->process();
132 panic("Got packet without sender state... huh?\n");
138 DmaDevice::DmaDevice(Params
*p
)
139 : PioDevice(p
), dmaPort(NULL
)
144 DmaDevice::drain(Event
*de
)
147 count
= pioPort
->drain(de
) + dmaPort
->drain(de
);
149 changeState(Draining
);
151 changeState(Drained
);
156 DmaPort::drain(Event
*de
)
158 if (pendingCount
== 0)
168 PacketPtr pkt
= transmitList
.front();
170 while (result
&& transmitList
.size()) {
171 DPRINTF(DMA
, "Retry on Packet %#x with senderState: %#x\n",
172 pkt
, pkt
->senderState
);
173 result
= sendTiming(pkt
);
175 DPRINTF(DMA
, "-- Done\n");
176 transmitList
.pop_front();
178 DPRINTF(DMA
, "-- Failed, queued\n");
185 DmaPort::dmaAction(Packet::Command cmd
, Addr addr
, int size
, Event
*event
,
190 assert(device
->getState() == SimObject::Running
);
192 DmaReqState
*reqState
= new DmaReqState(event
, this, size
);
194 for (ChunkGenerator
gen(addr
, size
, peerBlockSize());
195 !gen
.done(); gen
.next()) {
196 Request
*req
= new Request(gen
.addr(), gen
.size(), 0);
197 PacketPtr pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
199 // Increment the data pointer on a write
201 pkt
->dataStatic(data
+ gen
.complete());
203 pkt
->senderState
= reqState
;
205 assert(pendingCount
>= 0);
214 DmaPort::sendDma(PacketPtr pkt
, bool front
)
216 // some kind of selction between access methods
217 // more work is going to have to be done to make
218 // switching actually work
220 System::MemoryMode state
= sys
->getMemoryMode();
221 if (state
== System::Timing
) {
222 DPRINTF(DMA
, "Attempting to send Packet %#x with addr: %#x\n",
223 pkt
, pkt
->getAddr());
224 if (transmitList
.size() || !sendTiming(pkt
)) {
226 transmitList
.push_front(pkt
);
228 transmitList
.push_back(pkt
);
229 DPRINTF(DMA
, "-- Failed: queued\n");
231 DPRINTF(DMA
, "-- Done\n");
233 } else if (state
== System::Atomic
) {
235 lat
= sendAtomic(pkt
);
236 assert(pkt
->senderState
);
237 DmaReqState
*state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
240 state
->numBytes
+= pkt
->req
->getSize();
241 if (state
->totBytes
== state
->numBytes
) {
242 state
->completionEvent
->schedule(curTick
+ lat
);
247 assert(pendingCount
>= 0);
250 if (pendingCount
== 0 && drainEvent
) {
251 drainEvent
->process();
256 panic("Unknown memory command state.");
259 DmaDevice::~DmaDevice()