bridge.hh revision 8229
12568SN/A/* 22568SN/A * Copyright (c) 2006 The Regents of The University of Michigan 32568SN/A * All rights reserved. 42568SN/A * 52568SN/A * Redistribution and use in source and binary forms, with or without 62568SN/A * modification, are permitted provided that the following conditions are 72568SN/A * met: redistributions of source code must retain the above copyright 82568SN/A * notice, this list of conditions and the following disclaimer; 92568SN/A * redistributions in binary form must reproduce the above copyright 102568SN/A * notice, this list of conditions and the following disclaimer in the 112568SN/A * documentation and/or other materials provided with the distribution; 122568SN/A * neither the name of the copyright holders nor the names of its 132568SN/A * contributors may be used to endorse or promote products derived from 142568SN/A * this software without specific prior written permission. 152568SN/A * 162568SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172568SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182568SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192568SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202568SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212568SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222568SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232568SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242568SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252568SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262568SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302568SN/A */ 312568SN/A 322568SN/A/** 332982Sstever@eecs.umich.edu * @file 342982Sstever@eecs.umich.edu * Declaration of a simple bus bridge object with no buffering 352568SN/A */ 362568SN/A 372568SN/A#ifndef __MEM_BRIDGE_HH__ 382568SN/A#define __MEM_BRIDGE_HH__ 392568SN/A 402568SN/A#include <list> 412568SN/A#include <queue> 428229Snate@binkert.org#include <string> 432568SN/A 445386Sstever@gmail.com#include "base/fast_alloc.hh" 456215Snate@binkert.org#include "base/types.hh" 462568SN/A#include "mem/mem_object.hh" 472568SN/A#include "mem/packet.hh" 482568SN/A#include "mem/port.hh" 494762Snate@binkert.org#include "params/Bridge.hh" 502568SN/A#include "sim/eventq.hh" 512568SN/A 522568SN/Aclass Bridge : public MemObject 532568SN/A{ 542568SN/A protected: 552982Sstever@eecs.umich.edu /** Declaration of the buses port type, one will be instantiated for each 562568SN/A of the interfaces connecting to the bus. */ 572568SN/A class BridgePort : public Port 582568SN/A { 592643Sstever@eecs.umich.edu /** A pointer to the bridge to which this port belongs. */ 602568SN/A Bridge *bridge; 612568SN/A 622643Sstever@eecs.umich.edu /** 632643Sstever@eecs.umich.edu * Pointer to the port on the other side of the bridge 642643Sstever@eecs.umich.edu * (connected to the other bus). 652643Sstever@eecs.umich.edu */ 662643Sstever@eecs.umich.edu BridgePort *otherPort; 672643Sstever@eecs.umich.edu 682643Sstever@eecs.umich.edu /** Minimum delay though this bridge. */ 692643Sstever@eecs.umich.edu Tick delay; 702643Sstever@eecs.umich.edu 714435Ssaidi@eecs.umich.edu /** Min delay to respond to a nack. */ 724435Ssaidi@eecs.umich.edu Tick nackDelay; 734435Ssaidi@eecs.umich.edu 744965Ssaidi@eecs.umich.edu /** Pass ranges from one side of the bridge to the other? */ 754965Ssaidi@eecs.umich.edu std::vector<Range<Addr> > filterRanges; 764432Ssaidi@eecs.umich.edu 775386Sstever@gmail.com class PacketBuffer : public Packet::SenderState, public FastAlloc { 782643Sstever@eecs.umich.edu 792643Sstever@eecs.umich.edu public: 802643Sstever@eecs.umich.edu Tick ready; 813349Sbinkertn@umich.edu PacketPtr pkt; 824986Ssaidi@eecs.umich.edu bool nackedHere; 832643Sstever@eecs.umich.edu Packet::SenderState *origSenderState; 842643Sstever@eecs.umich.edu short origSrc; 852643Sstever@eecs.umich.edu bool expectResponse; 862643Sstever@eecs.umich.edu 874433Ssaidi@eecs.umich.edu PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false) 884986Ssaidi@eecs.umich.edu : ready(t), pkt(_pkt), nackedHere(nack), 894986Ssaidi@eecs.umich.edu origSenderState(_pkt->senderState), 904986Ssaidi@eecs.umich.edu origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ), 914454Ssaidi@eecs.umich.edu expectResponse(_pkt->needsResponse() && !nack) 924433Ssaidi@eecs.umich.edu 932643Sstever@eecs.umich.edu { 944986Ssaidi@eecs.umich.edu if (!pkt->isResponse() && !nack) 952657Ssaidi@eecs.umich.edu pkt->senderState = this; 962643Sstever@eecs.umich.edu } 972643Sstever@eecs.umich.edu 983349Sbinkertn@umich.edu void fixResponse(PacketPtr pkt) 992643Sstever@eecs.umich.edu { 1002643Sstever@eecs.umich.edu assert(pkt->senderState == this); 1012643Sstever@eecs.umich.edu pkt->setDest(origSrc); 1022643Sstever@eecs.umich.edu pkt->senderState = origSenderState; 1032643Sstever@eecs.umich.edu } 1042643Sstever@eecs.umich.edu }; 1052643Sstever@eecs.umich.edu 1062643Sstever@eecs.umich.edu /** 1072643Sstever@eecs.umich.edu * Outbound packet queue. Packets are held in this queue for a 1082643Sstever@eecs.umich.edu * specified delay to model the processing delay of the 1092643Sstever@eecs.umich.edu * bridge. 1102643Sstever@eecs.umich.edu */ 1112643Sstever@eecs.umich.edu std::list<PacketBuffer*> sendQueue; 1122643Sstever@eecs.umich.edu 1132643Sstever@eecs.umich.edu int outstandingResponses; 1144433Ssaidi@eecs.umich.edu int queuedRequests; 1152643Sstever@eecs.umich.edu 1164435Ssaidi@eecs.umich.edu /** If we're waiting for a retry to happen.*/ 1174435Ssaidi@eecs.umich.edu bool inRetry; 1184435Ssaidi@eecs.umich.edu 1192643Sstever@eecs.umich.edu /** Max queue size for outbound packets */ 1204435Ssaidi@eecs.umich.edu int reqQueueLimit; 1214435Ssaidi@eecs.umich.edu 1224435Ssaidi@eecs.umich.edu /** Max queue size for reserved responses. */ 1234435Ssaidi@eecs.umich.edu int respQueueLimit; 1242643Sstever@eecs.umich.edu 1252643Sstever@eecs.umich.edu /** 1262643Sstever@eecs.umich.edu * Is this side blocked from accepting outbound packets? 1272643Sstever@eecs.umich.edu */ 1284435Ssaidi@eecs.umich.edu bool respQueueFull(); 1294435Ssaidi@eecs.umich.edu bool reqQueueFull(); 1302643Sstever@eecs.umich.edu 1314433Ssaidi@eecs.umich.edu void queueForSendTiming(PacketPtr pkt); 1322643Sstever@eecs.umich.edu 1332643Sstever@eecs.umich.edu void finishSend(PacketBuffer *buf); 1342643Sstever@eecs.umich.edu 1354433Ssaidi@eecs.umich.edu void nackRequest(PacketPtr pkt); 1364433Ssaidi@eecs.umich.edu 1372643Sstever@eecs.umich.edu /** 1382643Sstever@eecs.umich.edu * Handle send event, scheduled when the packet at the head of 1392643Sstever@eecs.umich.edu * the outbound queue is ready to transmit (for timing 1402643Sstever@eecs.umich.edu * accesses only). 1412643Sstever@eecs.umich.edu */ 1422643Sstever@eecs.umich.edu void trySend(); 1432643Sstever@eecs.umich.edu 1442643Sstever@eecs.umich.edu class SendEvent : public Event 1452643Sstever@eecs.umich.edu { 1462643Sstever@eecs.umich.edu BridgePort *port; 1472643Sstever@eecs.umich.edu 1482643Sstever@eecs.umich.edu public: 1495606Snate@binkert.org SendEvent(BridgePort *p) : port(p) {} 1502643Sstever@eecs.umich.edu virtual void process() { port->trySend(); } 1515336Shines@cs.fsu.edu virtual const char *description() const { return "bridge send"; } 1522643Sstever@eecs.umich.edu }; 1532643Sstever@eecs.umich.edu 1542643Sstever@eecs.umich.edu SendEvent sendEvent; 1552568SN/A 1562568SN/A public: 1572568SN/A /** Constructor for the BusPort.*/ 1584435Ssaidi@eecs.umich.edu BridgePort(const std::string &_name, Bridge *_bridge, 1594435Ssaidi@eecs.umich.edu BridgePort *_otherPort, int _delay, int _nack_delay, 1604965Ssaidi@eecs.umich.edu int _req_limit, int _resp_limit, 1614965Ssaidi@eecs.umich.edu std::vector<Range<Addr> > filter_ranges); 1622568SN/A 1632568SN/A protected: 1642568SN/A 1652643Sstever@eecs.umich.edu /** When receiving a timing request from the peer port, 1662643Sstever@eecs.umich.edu pass it to the bridge. */ 1673349Sbinkertn@umich.edu virtual bool recvTiming(PacketPtr pkt); 1682568SN/A 1692643Sstever@eecs.umich.edu /** When receiving a retry request from the peer port, 1702568SN/A pass it to the bridge. */ 1712657Ssaidi@eecs.umich.edu virtual void recvRetry(); 1722568SN/A 1732643Sstever@eecs.umich.edu /** When receiving a Atomic requestfrom the peer port, 1742568SN/A pass it to the bridge. */ 1753349Sbinkertn@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 1762568SN/A 1772643Sstever@eecs.umich.edu /** When receiving a Functional request from the peer port, 1782568SN/A pass it to the bridge. */ 1793349Sbinkertn@umich.edu virtual void recvFunctional(PacketPtr pkt); 1802568SN/A 1812643Sstever@eecs.umich.edu /** When receiving a status changefrom the peer port, 1822568SN/A pass it to the bridge. */ 1832643Sstever@eecs.umich.edu virtual void recvStatusChange(Status status); 1842568SN/A 1852643Sstever@eecs.umich.edu /** When receiving a address range request the peer port, 1862568SN/A pass it to the bridge. */ 1872643Sstever@eecs.umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 1884475Sstever@eecs.umich.edu bool &snoop); 1892568SN/A }; 1902568SN/A 1912643Sstever@eecs.umich.edu BridgePort portA, portB; 1922568SN/A 1932568SN/A /** If this bridge should acknowledge writes. */ 1942568SN/A bool ackWrites; 1952568SN/A 1962568SN/A public: 1974762Snate@binkert.org typedef BridgeParams Params; 1984435Ssaidi@eecs.umich.edu 1994435Ssaidi@eecs.umich.edu protected: 2004435Ssaidi@eecs.umich.edu Params *_params; 2014435Ssaidi@eecs.umich.edu 2024435Ssaidi@eecs.umich.edu public: 2034435Ssaidi@eecs.umich.edu const Params *params() const { return _params; } 2042568SN/A 2052568SN/A /** A function used to return the port associated with this bus object. */ 2062738Sstever@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1); 2072568SN/A 2082568SN/A virtual void init(); 2092568SN/A 2104435Ssaidi@eecs.umich.edu Bridge(Params *p); 2112568SN/A}; 2122568SN/A 2132568SN/A#endif //__MEM_BUS_HH__ 214