bridge.hh revision 5386
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 <string>
412568SN/A#include <list>
422568SN/A#include <inttypes.h>
432568SN/A#include <queue>
442568SN/A
455386Sstever@gmail.com#include "base/fast_alloc.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:
1492643Sstever@eecs.umich.edu            SendEvent(BridgePort *p)
1502643Sstever@eecs.umich.edu                : Event(&mainEventQueue), port(p) {}
1512643Sstever@eecs.umich.edu
1522643Sstever@eecs.umich.edu            virtual void process() { port->trySend(); }
1532643Sstever@eecs.umich.edu
1545336Shines@cs.fsu.edu            virtual const char *description() const { return "bridge send"; }
1552643Sstever@eecs.umich.edu        };
1562643Sstever@eecs.umich.edu
1572643Sstever@eecs.umich.edu        SendEvent sendEvent;
1582568SN/A
1592568SN/A      public:
1602568SN/A        /** Constructor for the BusPort.*/
1614435Ssaidi@eecs.umich.edu        BridgePort(const std::string &_name, Bridge *_bridge,
1624435Ssaidi@eecs.umich.edu                BridgePort *_otherPort, int _delay, int _nack_delay,
1634965Ssaidi@eecs.umich.edu                int _req_limit, int _resp_limit,
1644965Ssaidi@eecs.umich.edu                std::vector<Range<Addr> > filter_ranges);
1652568SN/A
1662568SN/A      protected:
1672568SN/A
1682643Sstever@eecs.umich.edu        /** When receiving a timing request from the peer port,
1692643Sstever@eecs.umich.edu            pass it to the bridge. */
1703349Sbinkertn@umich.edu        virtual bool recvTiming(PacketPtr pkt);
1712568SN/A
1722643Sstever@eecs.umich.edu        /** When receiving a retry request from the peer port,
1732568SN/A            pass it to the bridge. */
1742657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1752568SN/A
1762643Sstever@eecs.umich.edu        /** When receiving a Atomic requestfrom the peer port,
1772568SN/A            pass it to the bridge. */
1783349Sbinkertn@umich.edu        virtual Tick recvAtomic(PacketPtr pkt);
1792568SN/A
1802643Sstever@eecs.umich.edu        /** When receiving a Functional request from the peer port,
1812568SN/A            pass it to the bridge. */
1823349Sbinkertn@umich.edu        virtual void recvFunctional(PacketPtr pkt);
1832568SN/A
1842643Sstever@eecs.umich.edu        /** When receiving a status changefrom the peer port,
1852568SN/A            pass it to the bridge. */
1862643Sstever@eecs.umich.edu        virtual void recvStatusChange(Status status);
1872568SN/A
1882643Sstever@eecs.umich.edu        /** When receiving a address range request the peer port,
1892568SN/A            pass it to the bridge. */
1902643Sstever@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1914475Sstever@eecs.umich.edu                                            bool &snoop);
1922568SN/A    };
1932568SN/A
1942643Sstever@eecs.umich.edu    BridgePort portA, portB;
1952568SN/A
1962568SN/A    /** If this bridge should acknowledge writes. */
1972568SN/A    bool ackWrites;
1982568SN/A
1992568SN/A  public:
2004762Snate@binkert.org    typedef BridgeParams Params;
2014435Ssaidi@eecs.umich.edu
2024435Ssaidi@eecs.umich.edu  protected:
2034435Ssaidi@eecs.umich.edu    Params *_params;
2044435Ssaidi@eecs.umich.edu
2054435Ssaidi@eecs.umich.edu  public:
2064435Ssaidi@eecs.umich.edu    const Params *params() const { return _params; }
2072568SN/A
2082568SN/A    /** A function used to return the port associated with this bus object. */
2092738Sstever@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
2102568SN/A
2112568SN/A    virtual void init();
2122568SN/A
2134435Ssaidi@eecs.umich.edu    Bridge(Params *p);
2142568SN/A};
2152568SN/A
2162568SN/A#endif //__MEM_BUS_HH__
217