tport.cc revision 4670
12292SN/A/*
22329SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32292SN/A * All rights reserved.
42292SN/A *
52292SN/A * Redistribution and use in source and binary forms, with or without
62292SN/A * modification, are permitted provided that the following conditions are
72292SN/A * met: redistributions of source code must retain the above copyright
82292SN/A * notice, this list of conditions and the following disclaimer;
92292SN/A * redistributions in binary form must reproduce the above copyright
102292SN/A * notice, this list of conditions and the following disclaimer in the
112292SN/A * documentation and/or other materials provided with the distribution;
122292SN/A * neither the name of the copyright holders nor the names of its
132292SN/A * contributors may be used to endorse or promote products derived from
142292SN/A * 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.
272689Sktlim@umich.edu *
282689Sktlim@umich.edu * Authors: Ali Saidi
292689Sktlim@umich.edu */
302292SN/A
312292SN/A#include "mem/tport.hh"
322292SN/A
332292SN/Avoid
342292SN/ASimpleTimingPort::checkFunctional(PacketPtr pkt)
352329SN/A{
364395Ssaidi@eecs.umich.edu    DeferredPacketIterator i = transmitList.begin();
372292SN/A    DeferredPacketIterator end = transmitList.end();
382292SN/A
392292SN/A    for (; i != end; ++i) {
408591Sgblack@eecs.umich.edu        PacketPtr target = i->pkt;
418506Sgblack@eecs.umich.edu        // If the target contains data, and it overlaps the
423326Sktlim@umich.edu        // probed request, need to update data
438481Sgblack@eecs.umich.edu        if (target->intersect(pkt)) {
448229Snate@binkert.org            if (!fixPacket(pkt, target)) {
456658Snate@binkert.org                // fixPacket returns true for continue, false for done
462292SN/A                return;
478230Snate@binkert.org            }
488232Snate@binkert.org        }
493348Sbinkertn@umich.edu    }
502669Sktlim@umich.edu}
518817Sgblack@eecs.umich.edu
522292SN/Avoid
538737Skoansin.tan@gmail.comSimpleTimingPort::recvFunctional(PacketPtr pkt)
545529Snate@binkert.org{
552292SN/A    checkFunctional(pkt);
562329SN/A
572329SN/A    // Just do an atomic access and throw away the returned latency
582329SN/A    if (pkt->result != Packet::Success)
592329SN/A        recvAtomic(pkt);
602329SN/A}
612329SN/A
622329SN/Abool
632329SN/ASimpleTimingPort::recvTiming(PacketPtr pkt)
642329SN/A{
652329SN/A    // If the device is only a slave, it should only be sending
662292SN/A    // 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.
702733Sktlim@umich.edu    assert(pkt->isRequest());
712292SN/A    assert(pkt->result == Packet::Unknown);
722292SN/A
732907Sktlim@umich.edu    if (pkt->memInhibitAsserted()) {
742292SN/A        // snooper will supply based on copy of packet
752292SN/A        // still target's responsibility to delete packet
762292SN/A        delete pkt->req;
772292SN/A        delete pkt;
782292SN/A        return true;
792292SN/A    }
802292SN/A
815529Snate@binkert.org    bool needsResponse = pkt->needsResponse();
825529Snate@binkert.org    Tick latency = recvAtomic(pkt);
835529Snate@binkert.org    // turn packet around to go back to requester if response expected
842292SN/A    if (needsResponse) {
852292SN/A        // recvAtomic() should already have turned packet into
862292SN/A        // atomic response
872292SN/A        assert(pkt->isResponse());
882727Sktlim@umich.edu        pkt->convertAtomicToTimingResponse();
892727Sktlim@umich.edu        schedSendTiming(pkt, curTick + latency);
902727Sktlim@umich.edu    } else {
912907Sktlim@umich.edu        delete pkt->req;
928922Swilliam.wang@arm.com        delete pkt;
932907Sktlim@umich.edu    }
942348SN/A
952307SN/A    return true;
962307SN/A}
972348SN/A
982307SN/A
992307SN/Avoid
1002348SN/ASimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when)
1012307SN/A{
1022307SN/A    assert(when > curTick);
1032292SN/A
1042292SN/A    // Nothing is on the list: add it and schedule an event
1052292SN/A    if (transmitList.empty() || when < transmitList.front().tick) {
1062292SN/A        transmitList.push_front(DeferredPacket(when, pkt));
1072292SN/A        schedSendEvent(when);
1082292SN/A        return;
1092292SN/A    }
1102292SN/A
1112292SN/A    // list is non-empty and this is not the head, so event should
1122292SN/A    // already be scheduled
1132292SN/A    assert(waitingOnRetry ||
1142292SN/A           (sendEvent->scheduled() && sendEvent->when() <= when));
1152292SN/A
1162292SN/A    // list is non-empty & this belongs at the end
1178545Ssaidi@eecs.umich.edu    if (when >= transmitList.back().tick) {
1188545Ssaidi@eecs.umich.edu        transmitList.push_back(DeferredPacket(when, pkt));
1198545Ssaidi@eecs.umich.edu        return;
1208199SAli.Saidi@ARM.com    }
1218199SAli.Saidi@ARM.com
1228199SAli.Saidi@ARM.com    // this belongs in the middle somewhere
1238199SAli.Saidi@ARM.com    DeferredPacketIterator i = transmitList.begin();
1248199SAli.Saidi@ARM.com    i++; // already checked for insertion at front
1258545Ssaidi@eecs.umich.edu    DeferredPacketIterator end = transmitList.end();
1268545Ssaidi@eecs.umich.edu
1278545Ssaidi@eecs.umich.edu    for (; i != end; ++i) {
1288545Ssaidi@eecs.umich.edu        if (when < i->tick) {
1298545Ssaidi@eecs.umich.edu            transmitList.insert(i, DeferredPacket(when, pkt));
1308545Ssaidi@eecs.umich.edu            return;
1312292SN/A        }
1322292SN/A    }
1332292SN/A    assert(false); // should never get here
1342329SN/A}
1352292SN/A
1362292SN/A
1372292SN/Avoid
1382292SN/ASimpleTimingPort::sendDeferredPacket()
1392292SN/A{
1402292SN/A    assert(deferredPacketReady());
1412292SN/A    bool success = sendTiming(transmitList.front().pkt);
1422292SN/A
1432292SN/A    if (success) {
1442292SN/A        //send successful, remove packet
1452292SN/A        transmitList.pop_front();
1462292SN/A        if (!transmitList.empty()) {
1472292SN/A            Tick time = transmitList.front().tick;
1482292SN/A            sendEvent->schedule(time <= curTick ? curTick+1 : time);
1492790Sktlim@umich.edu        }
1502790Sktlim@umich.edu
1512669Sktlim@umich.edu        if (transmitList.empty() && drainEvent) {
1522669Sktlim@umich.edu            drainEvent->process();
1532292SN/A            drainEvent = NULL;
1542292SN/A        }
1552292SN/A    }
1562292SN/A
1572292SN/A    waitingOnRetry = !success;
1582292SN/A
1592292SN/A    if (waitingOnRetry) {
1602292SN/A        DPRINTF(Bus, "Send failed, waiting on retry\n");
1612292SN/A    }
1622292SN/A}
1632292SN/A
1642292SN/A
1652292SN/Avoid
1662292SN/ASimpleTimingPort::recvRetry()
1672292SN/A{
1682292SN/A    DPRINTF(Bus, "Received retry\n");
1692292SN/A    assert(waitingOnRetry);
1702292SN/A    sendDeferredPacket();
1712292SN/A}
1722292SN/A
1732292SN/A
1742292SN/Avoid
1752292SN/ASimpleTimingPort::processSendEvent()
1762329SN/A{
1772292SN/A    assert(!waitingOnRetry);
1782292SN/A    sendDeferredPacket();
1792292SN/A}
1802348SN/A
1812292SN/A
1822292SN/Aunsigned int
1832292SN/ASimpleTimingPort::drain(Event *de)
1842348SN/A{
1852292SN/A    if (transmitList.size() == 0)
1862292SN/A        return 0;
1872292SN/A    drainEvent = de;
1882348SN/A    return 1;
1892292SN/A}
1902292SN/A