bridge.cc revision 2643
12568SN/A 22568SN/A/* 32568SN/A * Copyright (c) 2006 The Regents of The University of Michigan 42568SN/A * All rights reserved. 52568SN/A * 62568SN/A * Redistribution and use in source and binary forms, with or without 72568SN/A * modification, are permitted provided that the following conditions are 82568SN/A * met: redistributions of source code must retain the above copyright 92568SN/A * notice, this list of conditions and the following disclaimer; 102568SN/A * redistributions in binary form must reproduce the above copyright 112568SN/A * notice, this list of conditions and the following disclaimer in the 122568SN/A * documentation and/or other materials provided with the distribution; 132568SN/A * neither the name of the copyright holders nor the names of its 142568SN/A * contributors may be used to endorse or promote products derived from 152568SN/A * this software without specific prior written permission. 162568SN/A * 172568SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182568SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192568SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202568SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212568SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222568SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232568SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242568SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252568SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262568SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272568SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282568SN/A */ 292568SN/A 302568SN/A/** 312568SN/A * @file Definition of a simple bus bridge without buffering. 322568SN/A */ 332568SN/A 342643Sstever@eecs.umich.edu#include <algorithm> 352568SN/A 362568SN/A#include "base/trace.hh" 372568SN/A#include "mem/bridge.hh" 382568SN/A#include "sim/builder.hh" 392568SN/A 402643Sstever@eecs.umich.eduBridge::BridgePort::BridgePort(const std::string &_name, 412643Sstever@eecs.umich.edu Bridge *_bridge, BridgePort *_otherPort, 422643Sstever@eecs.umich.edu int _delay, int _queueLimit) 432643Sstever@eecs.umich.edu : Port(_name), bridge(_bridge), otherPort(_otherPort), 442643Sstever@eecs.umich.edu delay(_delay), outstandingResponses(0), 452643Sstever@eecs.umich.edu queueLimit(_queueLimit), sendEvent(this) 462643Sstever@eecs.umich.edu{ 472643Sstever@eecs.umich.edu} 482643Sstever@eecs.umich.edu 492643Sstever@eecs.umich.eduBridge::Bridge(const std::string &n, int qsa, int qsb, 502643Sstever@eecs.umich.edu Tick _delay, int write_ack) 512643Sstever@eecs.umich.edu : MemObject(n), 522643Sstever@eecs.umich.edu portA(n + "-portA", this, &portB, _delay, qsa), 532643Sstever@eecs.umich.edu portB(n + "-portB", this, &portA, _delay, qsa), 542643Sstever@eecs.umich.edu ackWrites(write_ack) 552643Sstever@eecs.umich.edu{ 562643Sstever@eecs.umich.edu} 572643Sstever@eecs.umich.edu 582643Sstever@eecs.umich.eduPort * 592643Sstever@eecs.umich.eduBridge::getPort(const std::string &if_name) 602643Sstever@eecs.umich.edu{ 612643Sstever@eecs.umich.edu BridgePort *port; 622643Sstever@eecs.umich.edu 632643Sstever@eecs.umich.edu if (if_name == "side_a") 642643Sstever@eecs.umich.edu port = &portA; 652643Sstever@eecs.umich.edu else if (if_name == "side_b") 662643Sstever@eecs.umich.edu port = &portB; 672643Sstever@eecs.umich.edu else 682643Sstever@eecs.umich.edu return NULL; 692643Sstever@eecs.umich.edu 702643Sstever@eecs.umich.edu if (port->getPeer() != NULL) 712643Sstever@eecs.umich.edu panic("bridge side %s already connected to.", if_name); 722643Sstever@eecs.umich.edu return port; 732643Sstever@eecs.umich.edu} 742643Sstever@eecs.umich.edu 752643Sstever@eecs.umich.edu 762568SN/Avoid 772568SN/ABridge::init() 782568SN/A{ 792568SN/A // Make sure that both sides are connected to. 802643Sstever@eecs.umich.edu if (portA.getPeer() == NULL || portB.getPeer() == NULL) 812568SN/A panic("Both ports of bus bridge are not connected to a bus.\n"); 822568SN/A} 832568SN/A 842568SN/A 852643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Timing 862568SN/A * transaction.*/ 872568SN/Abool 882643Sstever@eecs.umich.eduBridge::BridgePort::recvTiming(Packet *pkt) 892568SN/A{ 902643Sstever@eecs.umich.edu DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 912643Sstever@eecs.umich.edu pkt->getSrc(), pkt->getDest(), pkt->getAddr()); 922643Sstever@eecs.umich.edu 932643Sstever@eecs.umich.edu if (pkt->isResponse()) { 942643Sstever@eecs.umich.edu // This is a response for a request we forwarded earlier. The 952643Sstever@eecs.umich.edu // corresponding PacketBuffer should be stored in the packet's 962643Sstever@eecs.umich.edu // senderState field. 972643Sstever@eecs.umich.edu PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState); 982643Sstever@eecs.umich.edu assert(buf != NULL); 992643Sstever@eecs.umich.edu // set up new packet dest & senderState based on values saved 1002643Sstever@eecs.umich.edu // from original request 1012643Sstever@eecs.umich.edu buf->fixResponse(pkt); 1022643Sstever@eecs.umich.edu DPRINTF(BusBridge, " is response, new dest %d\n", pkt->getDest()); 1032643Sstever@eecs.umich.edu delete buf; 1042643Sstever@eecs.umich.edu } 1052643Sstever@eecs.umich.edu 1062643Sstever@eecs.umich.edu return otherPort->queueForSendTiming(pkt); 1072643Sstever@eecs.umich.edu} 1082643Sstever@eecs.umich.edu 1092643Sstever@eecs.umich.edu 1102643Sstever@eecs.umich.edubool 1112643Sstever@eecs.umich.eduBridge::BridgePort::queueForSendTiming(Packet *pkt) 1122643Sstever@eecs.umich.edu{ 1132643Sstever@eecs.umich.edu if (queueFull()) 1142568SN/A return false; 1152568SN/A 1162643Sstever@eecs.umich.edu Tick readyTime = curTick + delay; 1172643Sstever@eecs.umich.edu PacketBuffer *buf = new PacketBuffer(pkt, readyTime); 1182643Sstever@eecs.umich.edu 1192643Sstever@eecs.umich.edu // If we're about to put this packet at the head of the queue, we 1202643Sstever@eecs.umich.edu // need to schedule an event to do the transmit. Otherwise there 1212643Sstever@eecs.umich.edu // should already be an event scheduled for sending the head 1222643Sstever@eecs.umich.edu // packet. 1232643Sstever@eecs.umich.edu if (sendQueue.empty()) { 1242643Sstever@eecs.umich.edu sendEvent.schedule(readyTime); 1252568SN/A } 1262643Sstever@eecs.umich.edu 1272643Sstever@eecs.umich.edu sendQueue.push_back(buf); 1282643Sstever@eecs.umich.edu 1292643Sstever@eecs.umich.edu // Did we just become blocked? If yes, let other side know. 1302643Sstever@eecs.umich.edu if (queueFull()) 1312643Sstever@eecs.umich.edu otherPort->sendStatusChange(Port::Blocked); 1322643Sstever@eecs.umich.edu 1332568SN/A return true; 1342568SN/A} 1352568SN/A 1362643Sstever@eecs.umich.edu 1372568SN/Avoid 1382643Sstever@eecs.umich.eduBridge::BridgePort::finishSend(PacketBuffer *buf) 1392568SN/A{ 1402643Sstever@eecs.umich.edu if (buf->expectResponse) { 1412643Sstever@eecs.umich.edu // Must wait for response. We just need to count outstanding 1422643Sstever@eecs.umich.edu // responses (in case we want to cap them); PacketBuffer 1432643Sstever@eecs.umich.edu // pointer will be recovered on response. 1442643Sstever@eecs.umich.edu ++outstandingResponses; 1452643Sstever@eecs.umich.edu DPRINTF(BusBridge, " successful: awaiting response (%d)\n", 1462643Sstever@eecs.umich.edu outstandingResponses); 1472568SN/A } else { 1482643Sstever@eecs.umich.edu // no response expected... deallocate packet buffer now. 1492643Sstever@eecs.umich.edu DPRINTF(BusBridge, " successful: no response expected\n"); 1502643Sstever@eecs.umich.edu delete buf; 1512643Sstever@eecs.umich.edu } 1522643Sstever@eecs.umich.edu 1532643Sstever@eecs.umich.edu // If there are more packets to send, schedule event to try again. 1542643Sstever@eecs.umich.edu if (!sendQueue.empty()) { 1552643Sstever@eecs.umich.edu buf = sendQueue.front(); 1562643Sstever@eecs.umich.edu sendEvent.schedule(std::max(buf->ready, curTick + 1)); 1572568SN/A } 1582568SN/A} 1592568SN/A 1602568SN/A 1612568SN/Avoid 1622643Sstever@eecs.umich.eduBridge::BridgePort::trySend() 1632568SN/A{ 1642643Sstever@eecs.umich.edu assert(!sendQueue.empty()); 1652568SN/A 1662643Sstever@eecs.umich.edu PacketBuffer *buf = sendQueue.front(); 1672643Sstever@eecs.umich.edu 1682643Sstever@eecs.umich.edu assert(buf->ready <= curTick); 1692643Sstever@eecs.umich.edu 1702643Sstever@eecs.umich.edu Packet *pkt = buf->pkt; 1712643Sstever@eecs.umich.edu 1722643Sstever@eecs.umich.edu DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 1732643Sstever@eecs.umich.edu buf->origSrc, pkt->getDest(), pkt->getAddr()); 1742643Sstever@eecs.umich.edu 1752643Sstever@eecs.umich.edu if (sendTiming(pkt)) { 1762643Sstever@eecs.umich.edu // send successful 1772643Sstever@eecs.umich.edu sendQueue.pop_front(); 1782643Sstever@eecs.umich.edu buf->pkt = NULL; // we no longer own packet, so it's not safe to look at it 1792643Sstever@eecs.umich.edu finishSend(buf); 1802643Sstever@eecs.umich.edu } else { 1812643Sstever@eecs.umich.edu DPRINTF(BusBridge, " unsuccessful\n"); 1822643Sstever@eecs.umich.edu } 1832568SN/A} 1842568SN/A 1852568SN/A 1862568SN/APacket * 1872568SN/ABridge::BridgePort::recvRetry() 1882568SN/A{ 1892643Sstever@eecs.umich.edu PacketBuffer *buf = sendQueue.front(); 1902643Sstever@eecs.umich.edu Packet *pkt = buf->pkt; 1912643Sstever@eecs.umich.edu finishSend(buf); 1922568SN/A return pkt; 1932568SN/A} 1942568SN/A 1952643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Atomic 1962568SN/A * transaction.*/ 1972568SN/ATick 1982643Sstever@eecs.umich.eduBridge::BridgePort::recvAtomic(Packet *pkt) 1992568SN/A{ 2002643Sstever@eecs.umich.edu return otherPort->sendAtomic(pkt) + delay; 2012568SN/A} 2022568SN/A 2032643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Functional 2042568SN/A * transaction.*/ 2052568SN/Avoid 2062643Sstever@eecs.umich.eduBridge::BridgePort::recvFunctional(Packet *pkt) 2072568SN/A{ 2082643Sstever@eecs.umich.edu std::list<PacketBuffer*>::iterator i; 2092568SN/A bool pktContinue = true; 2102568SN/A 2112643Sstever@eecs.umich.edu for (i = sendQueue.begin(); i != sendQueue.end(); ++i) { 2122643Sstever@eecs.umich.edu if (pkt->intersect((*i)->pkt)) { 2132643Sstever@eecs.umich.edu pktContinue &= fixPacket(pkt, (*i)->pkt); 2142568SN/A } 2152568SN/A } 2162568SN/A 2172568SN/A if (pktContinue) { 2182643Sstever@eecs.umich.edu otherPort->sendFunctional(pkt); 2192568SN/A } 2202568SN/A} 2212568SN/A 2222643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a status change.*/ 2232568SN/Avoid 2242643Sstever@eecs.umich.eduBridge::BridgePort::recvStatusChange(Port::Status status) 2252568SN/A{ 2262568SN/A if (status == Port::Blocked || status == Port::Unblocked) 2272643Sstever@eecs.umich.edu return; 2282568SN/A 2292643Sstever@eecs.umich.edu otherPort->sendStatusChange(status); 2302568SN/A} 2312568SN/A 2322568SN/Avoid 2332643Sstever@eecs.umich.eduBridge::BridgePort::getDeviceAddressRanges(AddrRangeList &resp, 2342643Sstever@eecs.umich.edu AddrRangeList &snoop) 2352568SN/A{ 2362643Sstever@eecs.umich.edu otherPort->getPeerAddressRanges(resp, snoop); 2372568SN/A} 2382568SN/A 2392568SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(Bridge) 2402568SN/A 2412568SN/A Param<int> queue_size_a; 2422568SN/A Param<int> queue_size_b; 2432568SN/A Param<Tick> delay; 2442568SN/A Param<bool> write_ack; 2452568SN/A 2462568SN/AEND_DECLARE_SIM_OBJECT_PARAMS(Bridge) 2472568SN/A 2482568SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(Bridge) 2492568SN/A 2502568SN/A INIT_PARAM(queue_size_a, "The size of the queue for data coming into side a"), 2512568SN/A INIT_PARAM(queue_size_b, "The size of the queue for data coming into side b"), 2522568SN/A INIT_PARAM(delay, "The miminum delay to cross this bridge"), 2532568SN/A INIT_PARAM(write_ack, "Acknowledge any writes that are received.") 2542568SN/A 2552568SN/AEND_INIT_SIM_OBJECT_PARAMS(Bridge) 2562568SN/A 2572568SN/ACREATE_SIM_OBJECT(Bridge) 2582568SN/A{ 2592568SN/A return new Bridge(getInstanceName(), queue_size_a, queue_size_b, delay, 2602568SN/A write_ack); 2612568SN/A} 2622568SN/A 2632568SN/AREGISTER_SIM_OBJECT("Bridge", Bridge) 264