bridge.hh revision 5386:5614618f4027
12292SN/A/*
22329SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32292SN/A * All rights reserved.
42292SN/A *
52292SN/A * Redistribution and use in source and binary forms, with or without
62292SN/A * modification, are permitted provided that the following conditions are
72292SN/A * met: redistributions of source code must retain the above copyright
82292SN/A * notice, this list of conditions and the following disclaimer;
92292SN/A * redistributions in binary form must reproduce the above copyright
102292SN/A * notice, this list of conditions and the following disclaimer in the
112292SN/A * documentation and/or other materials provided with the distribution;
122292SN/A * neither the name of the copyright holders nor the names of its
132292SN/A * contributors may be used to endorse or promote products derived from
142292SN/A * this software without specific prior written permission.
152292SN/A *
162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu *
282689Sktlim@umich.edu * Authors: Ali Saidi
292689Sktlim@umich.edu *          Steve Reinhardt
302292SN/A */
312292SN/A
322292SN/A/**
332292SN/A * @file
342292SN/A * Declaration of a simple bus bridge object with no buffering
352329SN/A */
364395Ssaidi@eecs.umich.edu
372292SN/A#ifndef __MEM_BRIDGE_HH__
382292SN/A#define __MEM_BRIDGE_HH__
392292SN/A
402329SN/A#include <string>
413326Sktlim@umich.edu#include <list>
428481Sgblack@eecs.umich.edu#include <inttypes.h>
438229Snate@binkert.org#include <queue>
448229Snate@binkert.org
452292SN/A#include "base/fast_alloc.hh"
466658Snate@binkert.org#include "mem/mem_object.hh"
472292SN/A#include "mem/packet.hh"
488230Snate@binkert.org#include "mem/port.hh"
498232Snate@binkert.org#include "params/Bridge.hh"
503348Sbinkertn@umich.edu#include "sim/eventq.hh"
512669Sktlim@umich.edu
522292SN/Aclass Bridge : public MemObject
535529Snate@binkert.org{
545529Snate@binkert.org  protected:
552292SN/A    /** Declaration of the buses port type, one will be instantiated for each
562329SN/A        of the interfaces connecting to the bus. */
572329SN/A    class BridgePort : public Port
582329SN/A    {
592329SN/A        /** A pointer to the bridge to which this port belongs. */
602329SN/A        Bridge *bridge;
612329SN/A
622329SN/A        /**
632329SN/A         * Pointer to the port on the other side of the bridge
642329SN/A         * (connected to the other bus).
652329SN/A         */
662292SN/A        BridgePort *otherPort;
672292SN/A
682292SN/A        /** Minimum delay though this bridge. */
692292SN/A        Tick delay;
702733Sktlim@umich.edu
712292SN/A        /** Min delay to respond to a nack. */
722292SN/A        Tick nackDelay;
732907Sktlim@umich.edu
742292SN/A        /** Pass ranges from one side of the bridge to the other? */
752292SN/A        std::vector<Range<Addr> > filterRanges;
762292SN/A
772292SN/A        class PacketBuffer : public Packet::SenderState, public FastAlloc {
782292SN/A
792292SN/A          public:
802292SN/A            Tick ready;
815529Snate@binkert.org            PacketPtr pkt;
825529Snate@binkert.org            bool nackedHere;
835529Snate@binkert.org            Packet::SenderState *origSenderState;
842292SN/A            short origSrc;
852292SN/A            bool expectResponse;
862292SN/A
872292SN/A            PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
882727Sktlim@umich.edu                : ready(t), pkt(_pkt), nackedHere(nack),
892727Sktlim@umich.edu                  origSenderState(_pkt->senderState),
902727Sktlim@umich.edu                  origSrc(nack ? _pkt->getDest() : _pkt->getSrc() ),
912907Sktlim@umich.edu                  expectResponse(_pkt->needsResponse() && !nack)
924329Sktlim@umich.edu
932907Sktlim@umich.edu            {
942348SN/A                if (!pkt->isResponse() && !nack)
952307SN/A                    pkt->senderState = this;
962307SN/A            }
972348SN/A
982307SN/A            void fixResponse(PacketPtr pkt)
992307SN/A            {
1002348SN/A                assert(pkt->senderState == this);
1012307SN/A                pkt->setDest(origSrc);
1022307SN/A                pkt->senderState = origSenderState;
1032292SN/A            }
1042292SN/A        };
1052292SN/A
1062292SN/A        /**
1072292SN/A         * Outbound packet queue.  Packets are held in this queue for a
1082292SN/A         * specified delay to model the processing delay of the
1092292SN/A         * bridge.
1102292SN/A         */
1112292SN/A        std::list<PacketBuffer*> sendQueue;
1122292SN/A
1132292SN/A        int outstandingResponses;
1142292SN/A        int queuedRequests;
1152292SN/A
1162292SN/A        /** If we're waiting for a retry to happen.*/
1178199SAli.Saidi@ARM.com        bool inRetry;
1188199SAli.Saidi@ARM.com
1198199SAli.Saidi@ARM.com        /** Max queue size for outbound packets */
1208199SAli.Saidi@ARM.com        int reqQueueLimit;
1218199SAli.Saidi@ARM.com
1228199SAli.Saidi@ARM.com        /** Max queue size for reserved responses. */
1232292SN/A        int respQueueLimit;
1242292SN/A
1252292SN/A        /**
1262329SN/A         * Is this side blocked from accepting outbound packets?
1272292SN/A         */
1282292SN/A        bool respQueueFull();
1292292SN/A        bool reqQueueFull();
1302292SN/A
1312292SN/A        void queueForSendTiming(PacketPtr pkt);
1322292SN/A
1332292SN/A        void finishSend(PacketBuffer *buf);
1342292SN/A
1352292SN/A        void nackRequest(PacketPtr pkt);
1362292SN/A
1372292SN/A        /**
1382292SN/A         * Handle send event, scheduled when the packet at the head of
1392292SN/A         * the outbound queue is ready to transmit (for timing
1402292SN/A         * accesses only).
1412790Sktlim@umich.edu         */
1422790Sktlim@umich.edu        void trySend();
1432669Sktlim@umich.edu
1442669Sktlim@umich.edu        class SendEvent : public Event
1452292SN/A        {
1462292SN/A            BridgePort *port;
1472292SN/A
1482292SN/A          public:
1492292SN/A            SendEvent(BridgePort *p)
1502292SN/A                : Event(&mainEventQueue), port(p) {}
1512292SN/A
1522292SN/A            virtual void process() { port->trySend(); }
1532292SN/A
1542292SN/A            virtual const char *description() const { return "bridge send"; }
1552292SN/A        };
1562292SN/A
1572292SN/A        SendEvent sendEvent;
1582292SN/A
1592292SN/A      public:
1602292SN/A        /** Constructor for the BusPort.*/
1612292SN/A        BridgePort(const std::string &_name, Bridge *_bridge,
1622292SN/A                BridgePort *_otherPort, int _delay, int _nack_delay,
1632292SN/A                int _req_limit, int _resp_limit,
1642292SN/A                std::vector<Range<Addr> > filter_ranges);
1652292SN/A
1662292SN/A      protected:
1672292SN/A
1682329SN/A        /** When receiving a timing request from the peer port,
1692292SN/A            pass it to the bridge. */
1702292SN/A        virtual bool recvTiming(PacketPtr pkt);
1712292SN/A
1722348SN/A        /** When receiving a retry request from the peer port,
1732292SN/A            pass it to the bridge. */
1742292SN/A        virtual void recvRetry();
1752292SN/A
1762348SN/A        /** When receiving a Atomic requestfrom the peer port,
1772292SN/A            pass it to the bridge. */
1782292SN/A        virtual Tick recvAtomic(PacketPtr pkt);
1792292SN/A
1802348SN/A        /** When receiving a Functional request from the peer port,
1812292SN/A            pass it to the bridge. */
1822292SN/A        virtual void recvFunctional(PacketPtr pkt);
1832292SN/A
1842292SN/A        /** When receiving a status changefrom the peer port,
1852292SN/A            pass it to the bridge. */
1862292SN/A        virtual void recvStatusChange(Status status);
1872292SN/A
1882292SN/A        /** When receiving a address range request the peer port,
1892292SN/A            pass it to the bridge. */
1902292SN/A        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1912292SN/A                                            bool &snoop);
1922292SN/A    };
1932292SN/A
1942292SN/A    BridgePort portA, portB;
1952292SN/A
1962292SN/A    /** If this bridge should acknowledge writes. */
1972292SN/A    bool ackWrites;
1982292SN/A
1992292SN/A  public:
2002292SN/A    typedef BridgeParams Params;
2012292SN/A
2022292SN/A  protected:
2032292SN/A    Params *_params;
2042292SN/A
2052292SN/A  public:
2062292SN/A    const Params *params() const { return _params; }
2072292SN/A
2082292SN/A    /** A function used to return the port associated with this bus object. */
2092292SN/A    virtual Port *getPort(const std::string &if_name, int idx = -1);
2102292SN/A
2112292SN/A    virtual void init();
2122292SN/A
2132292SN/A    Bridge(Params *p);
2142292SN/A};
2152292SN/A
2162678Sktlim@umich.edu#endif //__MEM_BUS_HH__
2172678Sktlim@umich.edu