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.
31 #include "mem/tport.hh"
35 SimpleTimingPort::SimpleTimingPort(string pname
, MemObject
*_owner
)
36 : Port(pname
, _owner
), sendEvent(0), drainEvent(NULL
),
39 sendEvent
= new EventWrapper
<SimpleTimingPort
,
40 &SimpleTimingPort::processSendEvent
>(this);
43 SimpleTimingPort::~SimpleTimingPort()
49 SimpleTimingPort::checkFunctional(PacketPtr pkt
)
51 DeferredPacketIterator i
= transmitList
.begin();
52 DeferredPacketIterator end
= transmitList
.end();
54 for (; i
!= end
; ++i
) {
55 PacketPtr target
= i
->pkt
;
56 // If the target contains data, and it overlaps the
57 // probed request, need to update data
58 if (pkt
->checkFunctional(target
)) {
67 SimpleTimingPort::recvFunctional(PacketPtr pkt
)
69 if (!checkFunctional(pkt
)) {
70 // Just do an atomic access and throw away the returned latency
76 SimpleTimingPort::recvTiming(PacketPtr pkt
)
78 // If the device is only a slave, it should only be sending
79 // responses, which should never get nacked. There used to be
80 // code to hanldle nacks here, but I'm pretty sure it didn't work
81 // correctly with the drain code, so that would need to be fixed
82 // if we ever added it back.
84 if (pkt
->memInhibitAsserted()) {
85 // snooper will supply based on copy of packet
86 // still target's responsibility to delete packet
91 bool needsResponse
= pkt
->needsResponse();
92 Tick latency
= recvAtomic(pkt
);
93 // turn packet around to go back to requester if response expected
95 // recvAtomic() should already have turned packet into
97 assert(pkt
->isResponse());
98 schedSendTiming(pkt
, curTick
+ latency
);
108 SimpleTimingPort::schedSendTiming(PacketPtr pkt
, Tick when
)
110 assert(when
> curTick
);
111 assert(when
< curTick
+ SimClock::Int::ms
);
113 // Nothing is on the list: add it and schedule an event
114 if (transmitList
.empty() || when
< transmitList
.front().tick
) {
115 transmitList
.push_front(DeferredPacket(when
, pkt
));
116 schedSendEvent(when
);
120 // list is non-empty & this belongs at the end
121 if (when
>= transmitList
.back().tick
) {
122 transmitList
.push_back(DeferredPacket(when
, pkt
));
126 // this belongs in the middle somewhere
127 DeferredPacketIterator i
= transmitList
.begin();
128 i
++; // already checked for insertion at front
129 DeferredPacketIterator end
= transmitList
.end();
131 for (; i
!= end
; ++i
) {
132 if (when
< i
->tick
) {
133 transmitList
.insert(i
, DeferredPacket(when
, pkt
));
137 assert(false); // should never get here
142 SimpleTimingPort::sendDeferredPacket()
144 assert(deferredPacketReady());
145 // take packet off list here; if recvTiming() on the other side
146 // calls sendTiming() back on us (like SimpleTimingCpu does), then
147 // we get confused by having a non-active packet on transmitList
148 DeferredPacket dp
= transmitList
.front();
149 transmitList
.pop_front();
150 bool success
= sendTiming(dp
.pkt
);
153 if (!transmitList
.empty() && !sendEvent
->scheduled()) {
154 Tick time
= transmitList
.front().tick
;
155 schedule(sendEvent
, time
<= curTick
? curTick
+1 : time
);
158 if (transmitList
.empty() && drainEvent
&& !sendEvent
->scheduled()) {
159 drainEvent
->process();
163 // Unsuccessful, need to put back on transmitList. Callee
164 // should not have messed with it (since it didn't accept that
165 // packet), so we can just push it back on the front.
166 assert(!sendEvent
->scheduled());
167 transmitList
.push_front(dp
);
170 waitingOnRetry
= !success
;
172 if (waitingOnRetry
) {
173 DPRINTF(Bus
, "Send failed, waiting on retry\n");
179 SimpleTimingPort::recvRetry()
181 DPRINTF(Bus
, "Received retry\n");
182 assert(waitingOnRetry
);
183 sendDeferredPacket();
188 SimpleTimingPort::processSendEvent()
190 assert(!waitingOnRetry
);
191 sendDeferredPacket();
196 SimpleTimingPort::drain(Event
*de
)
198 if (transmitList
.size() == 0 && !sendEvent
->scheduled())