tport.cc revision 4870
12292SN/A/*
28948Sandreas.hansson@arm.com * Copyright (c) 2006 The Regents of The University of Michigan
38707Sandreas.hansson@arm.com * All rights reserved.
48707Sandreas.hansson@arm.com *
58707Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
68707Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
78707Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
88707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
98707Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
108707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
118707Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
128707Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
138707Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
142727Sktlim@umich.edu * this software without specific prior written permission.
152292SN/A *
162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272292SN/A *
282292SN/A * Authors: Ali Saidi
292292SN/A */
302292SN/A
312292SN/A#include "mem/tport.hh"
322292SN/A
332292SN/Avoid
342292SN/ASimpleTimingPort::checkFunctional(PacketPtr pkt)
352292SN/A{
362292SN/A    DeferredPacketIterator i = transmitList.begin();
372292SN/A    DeferredPacketIterator end = transmitList.end();
382292SN/A
392689Sktlim@umich.edu    for (; i != end; ++i) {
402689Sktlim@umich.edu        PacketPtr target = i->pkt;
412292SN/A        // If the target contains data, and it overlaps the
422292SN/A        // probed request, need to update data
432329SN/A        if (target->intersect(pkt)) {
442980Sgblack@eecs.umich.edu            if (!fixPacket(pkt, target)) {
452329SN/A                // fixPacket returns true for continue, false for done
462329SN/A                return;
472292SN/A            }
488232Snate@binkert.org        }
498232Snate@binkert.org    }
508232Snate@binkert.org}
516221Snate@binkert.org
522292SN/Avoid
536221Snate@binkert.orgSimpleTimingPort::recvFunctional(PacketPtr pkt)
545529Snate@binkert.org{
552292SN/A    checkFunctional(pkt);
565529Snate@binkert.org
578707Sandreas.hansson@arm.com    // Just do an atomic access and throw away the returned latency
584329Sktlim@umich.edu    if (!pkt->isResponse())
594329Sktlim@umich.edu        recvAtomic(pkt);
605529Snate@binkert.org}
612907Sktlim@umich.edu
622292SN/Abool
632292SN/ASimpleTimingPort::recvTiming(PacketPtr pkt)
642292SN/A{
652292SN/A    // If the device is only a slave, it should only be sending
662980Sgblack@eecs.umich.edu    // responses, which should never get nacked.  There used to be
672292SN/A    // code to hanldle nacks here, but I'm pretty sure it didn't work
682292SN/A    // correctly with the drain code, so that would need to be fixed
692292SN/A    // if we ever added it back.
702292SN/A    assert(pkt->isRequest());
712292SN/A
722292SN/A    if (pkt->memInhibitAsserted()) {
732292SN/A        // snooper will supply based on copy of packet
742292SN/A        // still target's responsibility to delete packet
752292SN/A        delete pkt->req;
762292SN/A        delete pkt;
772292SN/A        return true;
784329Sktlim@umich.edu    }
792292SN/A
802292SN/A    bool needsResponse = pkt->needsResponse();
812292SN/A    Tick latency = recvAtomic(pkt);
822292SN/A    // turn packet around to go back to requester if response expected
832292SN/A    if (needsResponse) {
842292SN/A        // recvAtomic() should already have turned packet into
852292SN/A        // atomic response
864329Sktlim@umich.edu        assert(pkt->isResponse());
872292SN/A        schedSendTiming(pkt, curTick + latency);
888346Sksewell@umich.edu    } else {
892292SN/A        delete pkt->req;
902292SN/A        delete pkt;
912292SN/A    }
922292SN/A
932292SN/A    return true;
942292SN/A}
952292SN/A
962292SN/A
972292SN/Avoid
982292SN/ASimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when)
992292SN/A{
1002292SN/A    assert(when > curTick);
1014329Sktlim@umich.edu
1022292SN/A    // Nothing is on the list: add it and schedule an event
1038346Sksewell@umich.edu    if (transmitList.empty() || when < transmitList.front().tick) {
1042292SN/A        transmitList.push_front(DeferredPacket(when, pkt));
1052292SN/A        schedSendEvent(when);
1062292SN/A        return;
1072292SN/A    }
1082292SN/A
1092292SN/A    // list is non-empty and this is not the head, so event should
1102292SN/A    // already be scheduled
1116221Snate@binkert.org    assert(waitingOnRetry ||
1124329Sktlim@umich.edu           (sendEvent->scheduled() && sendEvent->when() <= when));
1134329Sktlim@umich.edu
1148850Sandreas.hansson@arm.com    // list is non-empty & this belongs at the end
1152292SN/A    if (when >= transmitList.back().tick) {
1162292SN/A        transmitList.push_back(DeferredPacket(when, pkt));
1172292SN/A        return;
1182292SN/A    }
1192292SN/A
1202292SN/A    // this belongs in the middle somewhere
1212292SN/A    DeferredPacketIterator i = transmitList.begin();
1222292SN/A    i++; // already checked for insertion at front
1232292SN/A    DeferredPacketIterator end = transmitList.end();
1242292SN/A
1252292SN/A    for (; i != end; ++i) {
1262292SN/A        if (when < i->tick) {
1272292SN/A            transmitList.insert(i, DeferredPacket(when, pkt));
1282727Sktlim@umich.edu            return;
1292727Sktlim@umich.edu        }
1302727Sktlim@umich.edu    }
1316221Snate@binkert.org    assert(false); // should never get here
1322727Sktlim@umich.edu}
1332727Sktlim@umich.edu
1342727Sktlim@umich.edu
1352727Sktlim@umich.eduvoid
1362727Sktlim@umich.eduSimpleTimingPort::sendDeferredPacket()
1372727Sktlim@umich.edu{
1386221Snate@binkert.org    assert(deferredPacketReady());
1392292SN/A    // take packet off list here; if recvTiming() on the other side
1402292SN/A    // calls sendTiming() back on us (like SimpleTimingCpu does), then
1412292SN/A    // we get confused by having a non-active packet on transmitList
1422292SN/A    DeferredPacket dp = transmitList.front();
1432292SN/A    transmitList.pop_front();
1442292SN/A    bool success = sendTiming(dp.pkt);
1452307SN/A
1462307SN/A    if (success) {
1472307SN/A        if (!transmitList.empty() && !sendEvent->scheduled()) {
1486221Snate@binkert.org            Tick time = transmitList.front().tick;
1492307SN/A            sendEvent->schedule(time <= curTick ? curTick+1 : time);
1502307SN/A        }
1512307SN/A
1522307SN/A        if (transmitList.empty() && drainEvent) {
1532307SN/A            drainEvent->process();
1542307SN/A            drainEvent = NULL;
1552307SN/A        }
1562307SN/A    } else {
1576221Snate@binkert.org        // Unsuccessful, need to put back on transmitList.  Callee
1582307SN/A        // should not have messed with it (since it didn't accept that
1592307SN/A        // packet), so we can just push it back on the front.
1602307SN/A        assert(!sendEvent->scheduled());
1612307SN/A        transmitList.push_front(dp);
1622307SN/A    }
1632292SN/A
1646221Snate@binkert.org    waitingOnRetry = !success;
1652292SN/A
1662292SN/A    if (waitingOnRetry) {
1672292SN/A        DPRINTF(Bus, "Send failed, waiting on retry\n");
1682292SN/A    }
1692292SN/A}
1702292SN/A
1712292SN/A
1722292SN/Avoid
1732292SN/ASimpleTimingPort::recvRetry()
1742292SN/A{
1752292SN/A    DPRINTF(Bus, "Received retry\n");
1762292SN/A    assert(waitingOnRetry);
1772292SN/A    sendDeferredPacket();
1783867Sbinkertn@umich.edu}
1792292SN/A
1802292SN/A
1812292SN/Avoid
1822292SN/ASimpleTimingPort::processSendEvent()
1832292SN/A{
1842292SN/A    assert(!waitingOnRetry);
1852292SN/A    sendDeferredPacket();
1862292SN/A}
1872292SN/A
1882292SN/A
1892292SN/Aunsigned int
1906221Snate@binkert.orgSimpleTimingPort::drain(Event *de)
1916221Snate@binkert.org{
1923867Sbinkertn@umich.edu    if (transmitList.size() == 0)
1933867Sbinkertn@umich.edu        return 0;
1946221Snate@binkert.org    drainEvent = de;
1953867Sbinkertn@umich.edu    return 1;
1963867Sbinkertn@umich.edu}
1972292SN/A