bridge.cc revision 2738
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. 282665Ssaidi@eecs.umich.edu * 292665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 302665Ssaidi@eecs.umich.edu * Steve Reinhardt 312568SN/A */ 322568SN/A 332568SN/A/** 342568SN/A * @file Definition of a simple bus bridge without buffering. 352568SN/A */ 362568SN/A 372643Sstever@eecs.umich.edu#include <algorithm> 382568SN/A 392568SN/A#include "base/trace.hh" 402568SN/A#include "mem/bridge.hh" 412568SN/A#include "sim/builder.hh" 422568SN/A 432643Sstever@eecs.umich.eduBridge::BridgePort::BridgePort(const std::string &_name, 442643Sstever@eecs.umich.edu Bridge *_bridge, BridgePort *_otherPort, 452643Sstever@eecs.umich.edu int _delay, int _queueLimit) 462643Sstever@eecs.umich.edu : Port(_name), bridge(_bridge), otherPort(_otherPort), 472643Sstever@eecs.umich.edu delay(_delay), outstandingResponses(0), 482643Sstever@eecs.umich.edu queueLimit(_queueLimit), sendEvent(this) 492643Sstever@eecs.umich.edu{ 502643Sstever@eecs.umich.edu} 512643Sstever@eecs.umich.edu 522643Sstever@eecs.umich.eduBridge::Bridge(const std::string &n, int qsa, int qsb, 532643Sstever@eecs.umich.edu Tick _delay, int write_ack) 542643Sstever@eecs.umich.edu : MemObject(n), 552643Sstever@eecs.umich.edu portA(n + "-portA", this, &portB, _delay, qsa), 562643Sstever@eecs.umich.edu portB(n + "-portB", this, &portA, _delay, qsa), 572643Sstever@eecs.umich.edu ackWrites(write_ack) 582643Sstever@eecs.umich.edu{ 592643Sstever@eecs.umich.edu} 602643Sstever@eecs.umich.edu 612643Sstever@eecs.umich.eduPort * 622738Sstever@eecs.umich.eduBridge::getPort(const std::string &if_name, int idx) 632643Sstever@eecs.umich.edu{ 642643Sstever@eecs.umich.edu BridgePort *port; 652643Sstever@eecs.umich.edu 662643Sstever@eecs.umich.edu if (if_name == "side_a") 672643Sstever@eecs.umich.edu port = &portA; 682643Sstever@eecs.umich.edu else if (if_name == "side_b") 692643Sstever@eecs.umich.edu port = &portB; 702643Sstever@eecs.umich.edu else 712643Sstever@eecs.umich.edu return NULL; 722643Sstever@eecs.umich.edu 732643Sstever@eecs.umich.edu if (port->getPeer() != NULL) 742643Sstever@eecs.umich.edu panic("bridge side %s already connected to.", if_name); 752643Sstever@eecs.umich.edu return port; 762643Sstever@eecs.umich.edu} 772643Sstever@eecs.umich.edu 782643Sstever@eecs.umich.edu 792568SN/Avoid 802568SN/ABridge::init() 812568SN/A{ 822568SN/A // Make sure that both sides are connected to. 832643Sstever@eecs.umich.edu if (portA.getPeer() == NULL || portB.getPeer() == NULL) 842568SN/A panic("Both ports of bus bridge are not connected to a bus.\n"); 852568SN/A} 862568SN/A 872568SN/A 882643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Timing 892568SN/A * transaction.*/ 902568SN/Abool 912643Sstever@eecs.umich.eduBridge::BridgePort::recvTiming(Packet *pkt) 922568SN/A{ 932643Sstever@eecs.umich.edu DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 942643Sstever@eecs.umich.edu pkt->getSrc(), pkt->getDest(), pkt->getAddr()); 952643Sstever@eecs.umich.edu 962657Ssaidi@eecs.umich.edu return otherPort->queueForSendTiming(pkt); 972657Ssaidi@eecs.umich.edu} 982657Ssaidi@eecs.umich.edu 992657Ssaidi@eecs.umich.edu 1002657Ssaidi@eecs.umich.edubool 1012657Ssaidi@eecs.umich.eduBridge::BridgePort::queueForSendTiming(Packet *pkt) 1022657Ssaidi@eecs.umich.edu{ 1032657Ssaidi@eecs.umich.edu if (queueFull()) 1042657Ssaidi@eecs.umich.edu return false; 1052657Ssaidi@eecs.umich.edu 1062657Ssaidi@eecs.umich.edu if (pkt->isResponse()) { 1072643Sstever@eecs.umich.edu // This is a response for a request we forwarded earlier. The 1082643Sstever@eecs.umich.edu // corresponding PacketBuffer should be stored in the packet's 1092643Sstever@eecs.umich.edu // senderState field. 1102643Sstever@eecs.umich.edu PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState); 1112643Sstever@eecs.umich.edu assert(buf != NULL); 1122643Sstever@eecs.umich.edu // set up new packet dest & senderState based on values saved 1132643Sstever@eecs.umich.edu // from original request 1142643Sstever@eecs.umich.edu buf->fixResponse(pkt); 1152657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, "restoring sender state: %#X, from packet buffer: %#X\n", 1162657Ssaidi@eecs.umich.edu pkt->senderState, buf); 1172643Sstever@eecs.umich.edu DPRINTF(BusBridge, " is response, new dest %d\n", pkt->getDest()); 1182643Sstever@eecs.umich.edu delete buf; 1192643Sstever@eecs.umich.edu } 1202643Sstever@eecs.umich.edu 1212643Sstever@eecs.umich.edu Tick readyTime = curTick + delay; 1222643Sstever@eecs.umich.edu PacketBuffer *buf = new PacketBuffer(pkt, readyTime); 1232657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, "old sender state: %#X, new sender state: %#X\n", 1242657Ssaidi@eecs.umich.edu buf->origSenderState, buf); 1252643Sstever@eecs.umich.edu 1262643Sstever@eecs.umich.edu // If we're about to put this packet at the head of the queue, we 1272643Sstever@eecs.umich.edu // need to schedule an event to do the transmit. Otherwise there 1282643Sstever@eecs.umich.edu // should already be an event scheduled for sending the head 1292643Sstever@eecs.umich.edu // packet. 1302643Sstever@eecs.umich.edu if (sendQueue.empty()) { 1312643Sstever@eecs.umich.edu sendEvent.schedule(readyTime); 1322568SN/A } 1332643Sstever@eecs.umich.edu 1342643Sstever@eecs.umich.edu sendQueue.push_back(buf); 1352643Sstever@eecs.umich.edu 1362568SN/A return true; 1372568SN/A} 1382568SN/A 1392568SN/Avoid 1402643Sstever@eecs.umich.eduBridge::BridgePort::trySend() 1412568SN/A{ 1422643Sstever@eecs.umich.edu assert(!sendQueue.empty()); 1432568SN/A 1442657Ssaidi@eecs.umich.edu bool was_full = queueFull(); 1452657Ssaidi@eecs.umich.edu 1462643Sstever@eecs.umich.edu PacketBuffer *buf = sendQueue.front(); 1472643Sstever@eecs.umich.edu 1482643Sstever@eecs.umich.edu assert(buf->ready <= curTick); 1492643Sstever@eecs.umich.edu 1502643Sstever@eecs.umich.edu Packet *pkt = buf->pkt; 1512643Sstever@eecs.umich.edu 1522643Sstever@eecs.umich.edu DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 1532643Sstever@eecs.umich.edu buf->origSrc, pkt->getDest(), pkt->getAddr()); 1542643Sstever@eecs.umich.edu 1552643Sstever@eecs.umich.edu if (sendTiming(pkt)) { 1562643Sstever@eecs.umich.edu // send successful 1572643Sstever@eecs.umich.edu sendQueue.pop_front(); 1582643Sstever@eecs.umich.edu buf->pkt = NULL; // we no longer own packet, so it's not safe to look at it 1592657Ssaidi@eecs.umich.edu 1602657Ssaidi@eecs.umich.edu if (buf->expectResponse) { 1612657Ssaidi@eecs.umich.edu // Must wait for response. We just need to count outstanding 1622657Ssaidi@eecs.umich.edu // responses (in case we want to cap them); PacketBuffer 1632657Ssaidi@eecs.umich.edu // pointer will be recovered on response. 1642657Ssaidi@eecs.umich.edu ++outstandingResponses; 1652657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, " successful: awaiting response (%d)\n", 1662657Ssaidi@eecs.umich.edu outstandingResponses); 1672657Ssaidi@eecs.umich.edu } else { 1682657Ssaidi@eecs.umich.edu // no response expected... deallocate packet buffer now. 1692657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, " successful: no response expected\n"); 1702657Ssaidi@eecs.umich.edu delete buf; 1712657Ssaidi@eecs.umich.edu } 1722657Ssaidi@eecs.umich.edu 1732657Ssaidi@eecs.umich.edu // If there are more packets to send, schedule event to try again. 1742657Ssaidi@eecs.umich.edu if (!sendQueue.empty()) { 1752657Ssaidi@eecs.umich.edu buf = sendQueue.front(); 1762657Ssaidi@eecs.umich.edu sendEvent.schedule(std::max(buf->ready, curTick + 1)); 1772657Ssaidi@eecs.umich.edu } 1782657Ssaidi@eecs.umich.edu // Let things start sending again 1792657Ssaidi@eecs.umich.edu if (was_full) { 1802657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, "Queue was full, sending retry\n"); 1812657Ssaidi@eecs.umich.edu otherPort->sendRetry(); 1822657Ssaidi@eecs.umich.edu } 1832657Ssaidi@eecs.umich.edu 1842643Sstever@eecs.umich.edu } else { 1852643Sstever@eecs.umich.edu DPRINTF(BusBridge, " unsuccessful\n"); 1862643Sstever@eecs.umich.edu } 1872568SN/A} 1882568SN/A 1892568SN/A 1902657Ssaidi@eecs.umich.eduvoid 1912568SN/ABridge::BridgePort::recvRetry() 1922568SN/A{ 1932657Ssaidi@eecs.umich.edu trySend(); 1942568SN/A} 1952568SN/A 1962643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Atomic 1972568SN/A * transaction.*/ 1982568SN/ATick 1992643Sstever@eecs.umich.eduBridge::BridgePort::recvAtomic(Packet *pkt) 2002568SN/A{ 2012643Sstever@eecs.umich.edu return otherPort->sendAtomic(pkt) + delay; 2022568SN/A} 2032568SN/A 2042643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Functional 2052568SN/A * transaction.*/ 2062568SN/Avoid 2072643Sstever@eecs.umich.eduBridge::BridgePort::recvFunctional(Packet *pkt) 2082568SN/A{ 2092643Sstever@eecs.umich.edu std::list<PacketBuffer*>::iterator i; 2102568SN/A bool pktContinue = true; 2112568SN/A 2122643Sstever@eecs.umich.edu for (i = sendQueue.begin(); i != sendQueue.end(); ++i) { 2132643Sstever@eecs.umich.edu if (pkt->intersect((*i)->pkt)) { 2142643Sstever@eecs.umich.edu pktContinue &= fixPacket(pkt, (*i)->pkt); 2152568SN/A } 2162568SN/A } 2172568SN/A 2182568SN/A if (pktContinue) { 2192643Sstever@eecs.umich.edu otherPort->sendFunctional(pkt); 2202568SN/A } 2212568SN/A} 2222568SN/A 2232643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a status change.*/ 2242568SN/Avoid 2252643Sstever@eecs.umich.eduBridge::BridgePort::recvStatusChange(Port::Status status) 2262568SN/A{ 2272643Sstever@eecs.umich.edu otherPort->sendStatusChange(status); 2282568SN/A} 2292568SN/A 2302568SN/Avoid 2312643Sstever@eecs.umich.eduBridge::BridgePort::getDeviceAddressRanges(AddrRangeList &resp, 2322643Sstever@eecs.umich.edu AddrRangeList &snoop) 2332568SN/A{ 2342643Sstever@eecs.umich.edu otherPort->getPeerAddressRanges(resp, snoop); 2352568SN/A} 2362568SN/A 2372568SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(Bridge) 2382568SN/A 2392568SN/A Param<int> queue_size_a; 2402568SN/A Param<int> queue_size_b; 2412568SN/A Param<Tick> delay; 2422568SN/A Param<bool> write_ack; 2432568SN/A 2442568SN/AEND_DECLARE_SIM_OBJECT_PARAMS(Bridge) 2452568SN/A 2462568SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(Bridge) 2472568SN/A 2482568SN/A INIT_PARAM(queue_size_a, "The size of the queue for data coming into side a"), 2492568SN/A INIT_PARAM(queue_size_b, "The size of the queue for data coming into side b"), 2502568SN/A INIT_PARAM(delay, "The miminum delay to cross this bridge"), 2512568SN/A INIT_PARAM(write_ack, "Acknowledge any writes that are received.") 2522568SN/A 2532568SN/AEND_INIT_SIM_OBJECT_PARAMS(Bridge) 2542568SN/A 2552568SN/ACREATE_SIM_OBJECT(Bridge) 2562568SN/A{ 2572568SN/A return new Bridge(getInstanceName(), queue_size_a, queue_size_b, delay, 2582568SN/A write_ack); 2592568SN/A} 2602568SN/A 2612568SN/AREGISTER_SIM_OBJECT("Bridge", Bridge) 262