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"
37 PioPort::PioPort(PioDevice
*dev
, Platform
*p
)
38 : Port(dev
->name() + "-pioport"), device(dev
), platform(p
)
43 PioPort::recvAtomic(Packet
*pkt
)
45 return device
->recvAtomic(pkt
);
49 PioPort::recvFunctional(Packet
*pkt
)
51 device
->recvAtomic(pkt
);
55 PioPort::getDeviceAddressRanges(AddrRangeList
&resp
, AddrRangeList
&snoop
)
58 device
->addressRanges(resp
);
66 while (result
&& transmitList
.size()) {
67 result
= Port::sendTiming(transmitList
.front());
69 transmitList
.pop_front();
74 PioPort::SendEvent::process()
76 if (port
->Port::sendTiming(packet
))
79 port
->transmitList
.push_back(packet
);
85 PioPort::recvTiming(Packet
*pkt
)
87 if (pkt
->result
== Packet::Nacked
) {
89 if (transmitList
.size()) {
90 transmitList
.push_front(pkt
);
92 if (!Port::sendTiming(pkt
))
93 transmitList
.push_front(pkt
);
96 Tick latency
= device
->recvAtomic(pkt
);
97 // turn packet around to go back to requester
98 pkt
->makeTimingResponse();
99 sendTiming(pkt
, latency
);
104 PioDevice::~PioDevice()
114 panic("Pio port not connected to anything!");
115 pioPort
->sendStatusChange(Port::RangeChange
);
119 BasicPioDevice::addressRanges(AddrRangeList
&range_list
)
121 assert(pioSize
!= 0);
123 range_list
.push_back(RangeSize(pioAddr
, pioSize
));
127 DmaPort::DmaPort(DmaDevice
*dev
, Platform
*p
)
128 : Port(dev
->name() + "-dmaport"), device(dev
), platform(p
), pendingCount(0)
132 DmaPort::recvTiming(Packet
*pkt
)
136 if (pkt
->result
== Packet::Nacked
) {
137 DPRINTF(DMA
, "Received nacked Pkt %#x with State: %#x Addr: %#x\n",
138 pkt
, pkt
->senderState
, pkt
->getAddr());
141 } else if (pkt
->senderState
) {
143 DPRINTF(DMA
, "Received response Pkt %#x with State: %#x Addr: %#x\n",
144 pkt
, pkt
->senderState
, pkt
->getAddr());
145 state
= dynamic_cast<DmaReqState
*>(pkt
->senderState
);
148 assert(pendingCount
>= 0);
151 state
->numBytes
+= pkt
->req
->getSize();
152 if (state
->totBytes
== state
->numBytes
) {
153 state
->completionEvent
->process();
159 panic("Got packet without sender state... huh?\n");
165 DmaDevice::DmaDevice(Params
*p
)
166 : PioDevice(p
), dmaPort(NULL
)
172 Packet
* pkt
= transmitList
.front();
174 while (result
&& transmitList
.size()) {
175 DPRINTF(DMA
, "Retry on Packet %#x with senderState: %#x\n",
176 pkt
, pkt
->senderState
);
177 result
= sendTiming(pkt
);
179 DPRINTF(DMA
, "-- Done\n");
180 transmitList
.pop_front();
182 DPRINTF(DMA
, "-- Failed, queued\n");
189 DmaPort::dmaAction(Packet::Command cmd
, Addr addr
, int size
, Event
*event
,
194 DmaReqState
*reqState
= new DmaReqState(event
, this, size
);
196 for (ChunkGenerator
gen(addr
, size
, peerBlockSize());
197 !gen
.done(); gen
.next()) {
198 Request
*req
= new Request(gen
.addr(), gen
.size(), 0);
199 Packet
*pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
201 // Increment the data pointer on a write
203 pkt
->dataStatic(data
+ gen
.complete());
205 pkt
->senderState
= reqState
;
207 assert(pendingCount
>= 0);
215 DmaPort::sendDma(Packet
*pkt
, bool front
)
217 // some kind of selction between access methods
218 // more work is going to have to be done to make
219 // switching actually work
220 /* MemState state = device->platform->system->memState;
222 if (state == Timing) { */
223 DPRINTF(DMA
, "Attempting to send Packet %#x with addr: %#x\n",
224 pkt
, pkt
->getAddr());
225 if (transmitList
.size() || !sendTiming(pkt
)) {
227 transmitList
.push_front(pkt
);
229 transmitList
.push_back(pkt
);
230 DPRINTF(DMA
, "-- Failed: queued\n");
232 DPRINTF(DMA
, "-- Done\n");
234 /* } else if (state == Atomic) {
236 if (pkt->senderState) {
237 DmaReqState *state = dynamic_cast<DmaReqState*>(pkt->senderState);
239 state->completionEvent->schedule(curTick + (pkt->time -
240 pkt->req->getTime()) +1);
244 assert(pendingCount >= 0);
248 } else if (state == Functional) {
250 // Is this correct???
251 completionEvent->schedule(pkt->req->responseTime - pkt->req->requestTime);
252 completionEvent == NULL;
254 panic("Unknown memory command state.");
258 DmaDevice::~DmaDevice()