bridge.cc revision 3293
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/** 342982Sstever@eecs.umich.edu * @file 352982Sstever@eecs.umich.edu * Definition of a simple bus bridge without buffering. 362568SN/A */ 372568SN/A 382643Sstever@eecs.umich.edu#include <algorithm> 392568SN/A 402568SN/A#include "base/trace.hh" 412568SN/A#include "mem/bridge.hh" 422568SN/A#include "sim/builder.hh" 432568SN/A 442643Sstever@eecs.umich.eduBridge::BridgePort::BridgePort(const std::string &_name, 452643Sstever@eecs.umich.edu Bridge *_bridge, BridgePort *_otherPort, 462643Sstever@eecs.umich.edu int _delay, int _queueLimit) 472643Sstever@eecs.umich.edu : Port(_name), bridge(_bridge), otherPort(_otherPort), 482643Sstever@eecs.umich.edu delay(_delay), outstandingResponses(0), 492643Sstever@eecs.umich.edu queueLimit(_queueLimit), sendEvent(this) 502643Sstever@eecs.umich.edu{ 512643Sstever@eecs.umich.edu} 522643Sstever@eecs.umich.edu 532643Sstever@eecs.umich.eduBridge::Bridge(const std::string &n, int qsa, int qsb, 542643Sstever@eecs.umich.edu Tick _delay, int write_ack) 552643Sstever@eecs.umich.edu : MemObject(n), 562643Sstever@eecs.umich.edu portA(n + "-portA", this, &portB, _delay, qsa), 572643Sstever@eecs.umich.edu portB(n + "-portB", this, &portA, _delay, qsa), 582643Sstever@eecs.umich.edu ackWrites(write_ack) 592643Sstever@eecs.umich.edu{ 602643Sstever@eecs.umich.edu} 612643Sstever@eecs.umich.edu 622643Sstever@eecs.umich.eduPort * 632738Sstever@eecs.umich.eduBridge::getPort(const std::string &if_name, int idx) 642643Sstever@eecs.umich.edu{ 652643Sstever@eecs.umich.edu BridgePort *port; 662643Sstever@eecs.umich.edu 672643Sstever@eecs.umich.edu if (if_name == "side_a") 682643Sstever@eecs.umich.edu port = &portA; 692643Sstever@eecs.umich.edu else if (if_name == "side_b") 702643Sstever@eecs.umich.edu port = &portB; 712643Sstever@eecs.umich.edu else 722643Sstever@eecs.umich.edu return NULL; 732643Sstever@eecs.umich.edu 742643Sstever@eecs.umich.edu if (port->getPeer() != NULL) 752643Sstever@eecs.umich.edu panic("bridge side %s already connected to.", if_name); 762643Sstever@eecs.umich.edu return port; 772643Sstever@eecs.umich.edu} 782643Sstever@eecs.umich.edu 792643Sstever@eecs.umich.edu 802568SN/Avoid 812568SN/ABridge::init() 822568SN/A{ 832568SN/A // Make sure that both sides are connected to. 842643Sstever@eecs.umich.edu if (portA.getPeer() == NULL || portB.getPeer() == NULL) 852568SN/A panic("Both ports of bus bridge are not connected to a bus.\n"); 862568SN/A} 872568SN/A 882568SN/A 892643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Timing 902568SN/A * transaction.*/ 912568SN/Abool 922643Sstever@eecs.umich.eduBridge::BridgePort::recvTiming(Packet *pkt) 932568SN/A{ 942643Sstever@eecs.umich.edu DPRINTF(BusBridge, "recvTiming: src %d dest %d addr 0x%x\n", 952643Sstever@eecs.umich.edu pkt->getSrc(), pkt->getDest(), pkt->getAddr()); 962643Sstever@eecs.umich.edu 972657Ssaidi@eecs.umich.edu return otherPort->queueForSendTiming(pkt); 982657Ssaidi@eecs.umich.edu} 992657Ssaidi@eecs.umich.edu 1002657Ssaidi@eecs.umich.edu 1012657Ssaidi@eecs.umich.edubool 1022657Ssaidi@eecs.umich.eduBridge::BridgePort::queueForSendTiming(Packet *pkt) 1032657Ssaidi@eecs.umich.edu{ 1042657Ssaidi@eecs.umich.edu if (queueFull()) 1052657Ssaidi@eecs.umich.edu return false; 1062657Ssaidi@eecs.umich.edu 1072657Ssaidi@eecs.umich.edu if (pkt->isResponse()) { 1082643Sstever@eecs.umich.edu // This is a response for a request we forwarded earlier. The 1092643Sstever@eecs.umich.edu // corresponding PacketBuffer should be stored in the packet's 1102643Sstever@eecs.umich.edu // senderState field. 1112643Sstever@eecs.umich.edu PacketBuffer *buf = dynamic_cast<PacketBuffer*>(pkt->senderState); 1122643Sstever@eecs.umich.edu assert(buf != NULL); 1132643Sstever@eecs.umich.edu // set up new packet dest & senderState based on values saved 1142643Sstever@eecs.umich.edu // from original request 1152643Sstever@eecs.umich.edu buf->fixResponse(pkt); 1162657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, "restoring sender state: %#X, from packet buffer: %#X\n", 1172657Ssaidi@eecs.umich.edu pkt->senderState, buf); 1182643Sstever@eecs.umich.edu DPRINTF(BusBridge, " is response, new dest %d\n", pkt->getDest()); 1192643Sstever@eecs.umich.edu delete buf; 1202643Sstever@eecs.umich.edu } 1212643Sstever@eecs.umich.edu 1222643Sstever@eecs.umich.edu Tick readyTime = curTick + delay; 1232643Sstever@eecs.umich.edu PacketBuffer *buf = new PacketBuffer(pkt, readyTime); 1242657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, "old sender state: %#X, new sender state: %#X\n", 1252657Ssaidi@eecs.umich.edu buf->origSenderState, buf); 1262643Sstever@eecs.umich.edu 1272643Sstever@eecs.umich.edu // If we're about to put this packet at the head of the queue, we 1282643Sstever@eecs.umich.edu // need to schedule an event to do the transmit. Otherwise there 1292643Sstever@eecs.umich.edu // should already be an event scheduled for sending the head 1302643Sstever@eecs.umich.edu // packet. 1312643Sstever@eecs.umich.edu if (sendQueue.empty()) { 1322643Sstever@eecs.umich.edu sendEvent.schedule(readyTime); 1332568SN/A } 1342643Sstever@eecs.umich.edu 1352643Sstever@eecs.umich.edu sendQueue.push_back(buf); 1362643Sstever@eecs.umich.edu 1372568SN/A return true; 1382568SN/A} 1392568SN/A 1402568SN/Avoid 1412643Sstever@eecs.umich.eduBridge::BridgePort::trySend() 1422568SN/A{ 1432643Sstever@eecs.umich.edu assert(!sendQueue.empty()); 1442568SN/A 1452657Ssaidi@eecs.umich.edu bool was_full = queueFull(); 1462657Ssaidi@eecs.umich.edu 1472643Sstever@eecs.umich.edu PacketBuffer *buf = sendQueue.front(); 1482643Sstever@eecs.umich.edu 1492643Sstever@eecs.umich.edu assert(buf->ready <= curTick); 1502643Sstever@eecs.umich.edu 1512643Sstever@eecs.umich.edu Packet *pkt = buf->pkt; 1522643Sstever@eecs.umich.edu 1532643Sstever@eecs.umich.edu DPRINTF(BusBridge, "trySend: origSrc %d dest %d addr 0x%x\n", 1542643Sstever@eecs.umich.edu buf->origSrc, pkt->getDest(), pkt->getAddr()); 1552643Sstever@eecs.umich.edu 1563293Srdreslin@umich.edu pkt->flags &= ~SNOOP_COMMIT; //CLear it if it was set 1572643Sstever@eecs.umich.edu if (sendTiming(pkt)) { 1582643Sstever@eecs.umich.edu // send successful 1592643Sstever@eecs.umich.edu sendQueue.pop_front(); 1602643Sstever@eecs.umich.edu buf->pkt = NULL; // we no longer own packet, so it's not safe to look at it 1612657Ssaidi@eecs.umich.edu 1622657Ssaidi@eecs.umich.edu if (buf->expectResponse) { 1632657Ssaidi@eecs.umich.edu // Must wait for response. We just need to count outstanding 1642657Ssaidi@eecs.umich.edu // responses (in case we want to cap them); PacketBuffer 1652657Ssaidi@eecs.umich.edu // pointer will be recovered on response. 1662657Ssaidi@eecs.umich.edu ++outstandingResponses; 1672657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, " successful: awaiting response (%d)\n", 1682657Ssaidi@eecs.umich.edu outstandingResponses); 1692657Ssaidi@eecs.umich.edu } else { 1702657Ssaidi@eecs.umich.edu // no response expected... deallocate packet buffer now. 1712657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, " successful: no response expected\n"); 1722657Ssaidi@eecs.umich.edu delete buf; 1732657Ssaidi@eecs.umich.edu } 1742657Ssaidi@eecs.umich.edu 1752657Ssaidi@eecs.umich.edu // If there are more packets to send, schedule event to try again. 1762657Ssaidi@eecs.umich.edu if (!sendQueue.empty()) { 1772657Ssaidi@eecs.umich.edu buf = sendQueue.front(); 1782657Ssaidi@eecs.umich.edu sendEvent.schedule(std::max(buf->ready, curTick + 1)); 1792657Ssaidi@eecs.umich.edu } 1802657Ssaidi@eecs.umich.edu // Let things start sending again 1812657Ssaidi@eecs.umich.edu if (was_full) { 1822657Ssaidi@eecs.umich.edu DPRINTF(BusBridge, "Queue was full, sending retry\n"); 1832657Ssaidi@eecs.umich.edu otherPort->sendRetry(); 1842657Ssaidi@eecs.umich.edu } 1852657Ssaidi@eecs.umich.edu 1862643Sstever@eecs.umich.edu } else { 1872643Sstever@eecs.umich.edu DPRINTF(BusBridge, " unsuccessful\n"); 1882643Sstever@eecs.umich.edu } 1892568SN/A} 1902568SN/A 1912568SN/A 1922657Ssaidi@eecs.umich.eduvoid 1932568SN/ABridge::BridgePort::recvRetry() 1942568SN/A{ 1952657Ssaidi@eecs.umich.edu trySend(); 1962568SN/A} 1972568SN/A 1982643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Atomic 1992568SN/A * transaction.*/ 2002568SN/ATick 2012643Sstever@eecs.umich.eduBridge::BridgePort::recvAtomic(Packet *pkt) 2022568SN/A{ 2032643Sstever@eecs.umich.edu return otherPort->sendAtomic(pkt) + delay; 2042568SN/A} 2052568SN/A 2062643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a Functional 2072568SN/A * transaction.*/ 2082568SN/Avoid 2092643Sstever@eecs.umich.eduBridge::BridgePort::recvFunctional(Packet *pkt) 2102568SN/A{ 2112643Sstever@eecs.umich.edu std::list<PacketBuffer*>::iterator i; 2122568SN/A bool pktContinue = true; 2132568SN/A 2142643Sstever@eecs.umich.edu for (i = sendQueue.begin(); i != sendQueue.end(); ++i) { 2152643Sstever@eecs.umich.edu if (pkt->intersect((*i)->pkt)) { 2162643Sstever@eecs.umich.edu pktContinue &= fixPacket(pkt, (*i)->pkt); 2172568SN/A } 2182568SN/A } 2192568SN/A 2202568SN/A if (pktContinue) { 2212643Sstever@eecs.umich.edu otherPort->sendFunctional(pkt); 2222568SN/A } 2232568SN/A} 2242568SN/A 2252643Sstever@eecs.umich.edu/** Function called by the port when the bus is receiving a status change.*/ 2262568SN/Avoid 2272643Sstever@eecs.umich.eduBridge::BridgePort::recvStatusChange(Port::Status status) 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