tport.cc revision 4492
12817Sksewell@umich.edu/*
22817Sksewell@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
32817Sksewell@umich.edu * All rights reserved.
42817Sksewell@umich.edu *
52817Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
62817Sksewell@umich.edu * modification, are permitted provided that the following conditions are
72817Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
82817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
92817Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
102817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
112817Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
122817Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
132817Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
142817Sksewell@umich.edu * this software without specific prior written permission.
152817Sksewell@umich.edu *
162817Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172817Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182817Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192817Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202817Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212817Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222817Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232817Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242817Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252817Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262817Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272817Sksewell@umich.edu *
282817Sksewell@umich.edu * Authors: Ali Saidi
294202Sbinkertn@umich.edu */
302817Sksewell@umich.edu
312817Sksewell@umich.edu#include "mem/tport.hh"
322817Sksewell@umich.edu
334202Sbinkertn@umich.eduvoid
342817Sksewell@umich.eduSimpleTimingPort::checkFunctional(PacketPtr pkt)
355192Ssaidi@eecs.umich.edu{
368335Snate@binkert.org    DeferredPacketIterator i = transmitList.begin();
378335Snate@binkert.org    DeferredPacketIterator end = transmitList.end();
388335Snate@binkert.org
395192Ssaidi@eecs.umich.edu    for (; i != end; ++i) {
404202Sbinkertn@umich.edu        PacketPtr target = i->pkt;
414486Sbinkertn@umich.edu        // If the target contains data, and it overlaps the
424486Sbinkertn@umich.edu        // probed request, need to update data
434486Sbinkertn@umich.edu        if (target->intersect(pkt)) {
444486Sbinkertn@umich.edu            if (!fixPacket(pkt, target)) {
454202Sbinkertn@umich.edu                // fixPacket returns true for continue, false for done
464202Sbinkertn@umich.edu                return;
474202Sbinkertn@umich.edu            }
484202Sbinkertn@umich.edu        }
499341SAndreas.Sandberg@arm.com    }
504202Sbinkertn@umich.edu}
515597Sgblack@eecs.umich.edu
524202Sbinkertn@umich.eduvoid
534202Sbinkertn@umich.eduSimpleTimingPort::recvFunctional(PacketPtr pkt)
544202Sbinkertn@umich.edu{
554202Sbinkertn@umich.edu    checkFunctional(pkt);
564202Sbinkertn@umich.edu
574202Sbinkertn@umich.edu    // Just do an atomic access and throw away the returned latency
584202Sbinkertn@umich.edu    if (pkt->result != Packet::Success)
594202Sbinkertn@umich.edu        recvAtomic(pkt);
604202Sbinkertn@umich.edu}
614202Sbinkertn@umich.edu
624202Sbinkertn@umich.edubool
634202Sbinkertn@umich.eduSimpleTimingPort::recvTiming(PacketPtr pkt)
644202Sbinkertn@umich.edu{
655597Sgblack@eecs.umich.edu    // If the device is only a slave, it should only be sending
662817Sksewell@umich.edu    // responses, which should never get nacked.  There used to be
678335Snate@binkert.org    // code to hanldle nacks here, but I'm pretty sure it didn't work
688335Snate@binkert.org    // correctly with the drain code, so that would need to be fixed
698335Snate@binkert.org    // if we ever added it back.
708335Snate@binkert.org    assert(pkt->result != Packet::Nacked);
718335Snate@binkert.org    Tick latency = recvAtomic(pkt);
728335Snate@binkert.org    // turn packet around to go back to requester if response expected
738335Snate@binkert.org    if (pkt->needsResponse()) {
748335Snate@binkert.org        pkt->makeTimingResponse();
758335Snate@binkert.org        schedSendTiming(pkt, latency);
765192Ssaidi@eecs.umich.edu    }
775192Ssaidi@eecs.umich.edu    else if (pkt->cmd != MemCmd::UpgradeReq) {
785192Ssaidi@eecs.umich.edu        delete pkt->req;
795192Ssaidi@eecs.umich.edu        delete pkt;
805192Ssaidi@eecs.umich.edu    }
818887Sgeoffrey.blake@arm.com    return true;
829340SAndreas.Sandberg@arm.com}
83
84
85void
86SimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when)
87{
88    assert(when > curTick);
89
90    // Nothing is on the list: add it and schedule an event
91    if (transmitList.empty()) {
92        assert(!sendEvent->scheduled());
93        sendEvent->schedule(when);
94        transmitList.push_back(DeferredPacket(when, pkt));
95        return;
96    }
97
98    // something is on the list and this belongs at the end
99    if (when >= transmitList.back().tick) {
100        transmitList.push_back(DeferredPacket(when, pkt));
101        return;
102    }
103    // Something is on the list and this belongs somewhere else
104    DeferredPacketIterator i = transmitList.begin();
105    DeferredPacketIterator end = transmitList.end();
106
107    for (; i != end; ++i) {
108        if (when < i->tick) {
109            if (i == transmitList.begin()) {
110                //Inserting at begining, reschedule
111                sendEvent->reschedule(when);
112            }
113            transmitList.insert(i, DeferredPacket(when, pkt));
114            return;
115        }
116    }
117    assert(false); // should never get here
118}
119
120
121void
122SimpleTimingPort::sendDeferredPacket()
123{
124    assert(deferredPacketReady());
125    bool success = sendTiming(transmitList.front().pkt);
126
127    if (success) {
128        //send successful, remove packet
129        transmitList.pop_front();
130        if (!transmitList.empty()) {
131            Tick time = transmitList.front().tick;
132            sendEvent->schedule(time <= curTick ? curTick+1 : time);
133        }
134
135        if (transmitList.empty() && drainEvent) {
136            drainEvent->process();
137            drainEvent = NULL;
138        }
139    }
140
141    waitingOnRetry = !success;
142
143    if (waitingOnRetry) {
144        DPRINTF(Bus, "Send failed, waiting on retry\n");
145    }
146}
147
148
149void
150SimpleTimingPort::recvRetry()
151{
152    DPRINTF(Bus, "Received retry\n");
153    assert(waitingOnRetry);
154    sendDeferredPacket();
155}
156
157
158void
159SimpleTimingPort::processSendEvent()
160{
161    assert(!waitingOnRetry);
162    sendDeferredPacket();
163}
164
165
166unsigned int
167SimpleTimingPort::drain(Event *de)
168{
169    if (transmitList.size() == 0)
170        return 0;
171    drainEvent = de;
172    return 1;
173}
174