bridge.hh revision 4986
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
452568SN/A#include "mem/mem_object.hh"
462568SN/A#include "mem/packet.hh"
472568SN/A#include "mem/port.hh"
484762Snate@binkert.org#include "params/Bridge.hh"
492568SN/A#include "sim/eventq.hh"
502568SN/A
512568SN/Aclass Bridge : public MemObject
522568SN/A{
532568SN/A  protected:
542982Sstever@eecs.umich.edu    /** Declaration of the buses port type, one will be instantiated for each
552568SN/A        of the interfaces connecting to the bus. */
562568SN/A    class BridgePort : public Port
572568SN/A    {
582643Sstever@eecs.umich.edu        /** A pointer to the bridge to which this port belongs. */
592568SN/A        Bridge *bridge;
602568SN/A
612643Sstever@eecs.umich.edu        /**
622643Sstever@eecs.umich.edu         * Pointer to the port on the other side of the bridge
632643Sstever@eecs.umich.edu         * (connected to the other bus).
642643Sstever@eecs.umich.edu         */
652643Sstever@eecs.umich.edu        BridgePort *otherPort;
662643Sstever@eecs.umich.edu
672643Sstever@eecs.umich.edu        /** Minimum delay though this bridge. */
682643Sstever@eecs.umich.edu        Tick delay;
692643Sstever@eecs.umich.edu
704435Ssaidi@eecs.umich.edu        /** Min delay to respond to a nack. */
714435Ssaidi@eecs.umich.edu        Tick nackDelay;
724435Ssaidi@eecs.umich.edu
734965Ssaidi@eecs.umich.edu        /** Pass ranges from one side of the bridge to the other? */
744965Ssaidi@eecs.umich.edu        std::vector<Range<Addr> > filterRanges;
754432Ssaidi@eecs.umich.edu
762643Sstever@eecs.umich.edu        class PacketBuffer : public Packet::SenderState {
772643Sstever@eecs.umich.edu
782643Sstever@eecs.umich.edu          public:
792643Sstever@eecs.umich.edu            Tick ready;
803349Sbinkertn@umich.edu            PacketPtr pkt;
814986Ssaidi@eecs.umich.edu            bool nackedHere;
822643Sstever@eecs.umich.edu            Packet::SenderState *origSenderState;
832643Sstever@eecs.umich.edu            short origSrc;
842643Sstever@eecs.umich.edu            bool expectResponse;
852643Sstever@eecs.umich.edu
864433Ssaidi@eecs.umich.edu            PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
874986Ssaidi@eecs.umich.edu                : ready(t), pkt(_pkt), nackedHere(nack),
884986Ssaidi@eecs.umich.edu                  origSenderState(_pkt->senderState),
894986Ssaidi@eecs.umich.edu                  origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ),
904454Ssaidi@eecs.umich.edu                  expectResponse(_pkt->needsResponse() && !nack)
914433Ssaidi@eecs.umich.edu
922643Sstever@eecs.umich.edu            {
934986Ssaidi@eecs.umich.edu                if (!pkt->isResponse() && !nack)
942657Ssaidi@eecs.umich.edu                    pkt->senderState = this;
952643Sstever@eecs.umich.edu            }
962643Sstever@eecs.umich.edu
973349Sbinkertn@umich.edu            void fixResponse(PacketPtr pkt)
982643Sstever@eecs.umich.edu            {
992643Sstever@eecs.umich.edu                assert(pkt->senderState == this);
1002643Sstever@eecs.umich.edu                pkt->setDest(origSrc);
1012643Sstever@eecs.umich.edu                pkt->senderState = origSenderState;
1022643Sstever@eecs.umich.edu            }
1032643Sstever@eecs.umich.edu        };
1042643Sstever@eecs.umich.edu
1052643Sstever@eecs.umich.edu        /**
1062643Sstever@eecs.umich.edu         * Outbound packet queue.  Packets are held in this queue for a
1072643Sstever@eecs.umich.edu         * specified delay to model the processing delay of the
1082643Sstever@eecs.umich.edu         * bridge.
1092643Sstever@eecs.umich.edu         */
1102643Sstever@eecs.umich.edu        std::list<PacketBuffer*> sendQueue;
1112643Sstever@eecs.umich.edu
1122643Sstever@eecs.umich.edu        int outstandingResponses;
1134433Ssaidi@eecs.umich.edu        int queuedRequests;
1142643Sstever@eecs.umich.edu
1154435Ssaidi@eecs.umich.edu        /** If we're waiting for a retry to happen.*/
1164435Ssaidi@eecs.umich.edu        bool inRetry;
1174435Ssaidi@eecs.umich.edu
1182643Sstever@eecs.umich.edu        /** Max queue size for outbound packets */
1194435Ssaidi@eecs.umich.edu        int reqQueueLimit;
1204435Ssaidi@eecs.umich.edu
1214435Ssaidi@eecs.umich.edu        /** Max queue size for reserved responses. */
1224435Ssaidi@eecs.umich.edu        int respQueueLimit;
1232643Sstever@eecs.umich.edu
1242643Sstever@eecs.umich.edu        /**
1252643Sstever@eecs.umich.edu         * Is this side blocked from accepting outbound packets?
1262643Sstever@eecs.umich.edu         */
1274435Ssaidi@eecs.umich.edu        bool respQueueFull();
1284435Ssaidi@eecs.umich.edu        bool reqQueueFull();
1292643Sstever@eecs.umich.edu
1304433Ssaidi@eecs.umich.edu        void queueForSendTiming(PacketPtr pkt);
1312643Sstever@eecs.umich.edu
1322643Sstever@eecs.umich.edu        void finishSend(PacketBuffer *buf);
1332643Sstever@eecs.umich.edu
1344433Ssaidi@eecs.umich.edu        void nackRequest(PacketPtr pkt);
1354433Ssaidi@eecs.umich.edu
1362643Sstever@eecs.umich.edu        /**
1372643Sstever@eecs.umich.edu         * Handle send event, scheduled when the packet at the head of
1382643Sstever@eecs.umich.edu         * the outbound queue is ready to transmit (for timing
1392643Sstever@eecs.umich.edu         * accesses only).
1402643Sstever@eecs.umich.edu         */
1412643Sstever@eecs.umich.edu        void trySend();
1422643Sstever@eecs.umich.edu
1432643Sstever@eecs.umich.edu        class SendEvent : public Event
1442643Sstever@eecs.umich.edu        {
1452643Sstever@eecs.umich.edu            BridgePort *port;
1462643Sstever@eecs.umich.edu
1472643Sstever@eecs.umich.edu          public:
1482643Sstever@eecs.umich.edu            SendEvent(BridgePort *p)
1492643Sstever@eecs.umich.edu                : Event(&mainEventQueue), port(p) {}
1502643Sstever@eecs.umich.edu
1512643Sstever@eecs.umich.edu            virtual void process() { port->trySend(); }
1522643Sstever@eecs.umich.edu
1534873Sstever@eecs.umich.edu            virtual const char *description() { return "bridge send"; }
1542643Sstever@eecs.umich.edu        };
1552643Sstever@eecs.umich.edu
1562643Sstever@eecs.umich.edu        SendEvent sendEvent;
1572568SN/A
1582568SN/A      public:
1592568SN/A        /** Constructor for the BusPort.*/
1604435Ssaidi@eecs.umich.edu        BridgePort(const std::string &_name, Bridge *_bridge,
1614435Ssaidi@eecs.umich.edu                BridgePort *_otherPort, int _delay, int _nack_delay,
1624965Ssaidi@eecs.umich.edu                int _req_limit, int _resp_limit,
1634965Ssaidi@eecs.umich.edu                std::vector<Range<Addr> > filter_ranges);
1642568SN/A
1652568SN/A      protected:
1662568SN/A
1672643Sstever@eecs.umich.edu        /** When receiving a timing request from the peer port,
1682643Sstever@eecs.umich.edu            pass it to the bridge. */
1693349Sbinkertn@umich.edu        virtual bool recvTiming(PacketPtr pkt);
1702568SN/A
1712643Sstever@eecs.umich.edu        /** When receiving a retry request from the peer port,
1722568SN/A            pass it to the bridge. */
1732657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1742568SN/A
1752643Sstever@eecs.umich.edu        /** When receiving a Atomic requestfrom the peer port,
1762568SN/A            pass it to the bridge. */
1773349Sbinkertn@umich.edu        virtual Tick recvAtomic(PacketPtr pkt);
1782568SN/A
1792643Sstever@eecs.umich.edu        /** When receiving a Functional request from the peer port,
1802568SN/A            pass it to the bridge. */
1813349Sbinkertn@umich.edu        virtual void recvFunctional(PacketPtr pkt);
1822568SN/A
1832643Sstever@eecs.umich.edu        /** When receiving a status changefrom the peer port,
1842568SN/A            pass it to the bridge. */
1852643Sstever@eecs.umich.edu        virtual void recvStatusChange(Status status);
1862568SN/A
1872643Sstever@eecs.umich.edu        /** When receiving a address range request the peer port,
1882568SN/A            pass it to the bridge. */
1892643Sstever@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1904475Sstever@eecs.umich.edu                                            bool &snoop);
1912568SN/A    };
1922568SN/A
1932643Sstever@eecs.umich.edu    BridgePort portA, portB;
1942568SN/A
1952568SN/A    /** If this bridge should acknowledge writes. */
1962568SN/A    bool ackWrites;
1972568SN/A
1982568SN/A  public:
1994762Snate@binkert.org    typedef BridgeParams Params;
2004435Ssaidi@eecs.umich.edu
2014435Ssaidi@eecs.umich.edu  protected:
2024435Ssaidi@eecs.umich.edu    Params *_params;
2034435Ssaidi@eecs.umich.edu
2044435Ssaidi@eecs.umich.edu  public:
2054435Ssaidi@eecs.umich.edu    const Params *params() const { return _params; }
2062568SN/A
2072568SN/A    /** A function used to return the port associated with this bus object. */
2082738Sstever@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
2092568SN/A
2102568SN/A    virtual void init();
2112568SN/A
2124435Ssaidi@eecs.umich.edu    Bridge(Params *p);
2132568SN/A};
2142568SN/A
2152568SN/A#endif //__MEM_BUS_HH__
216