bridge.hh revision 3349
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"
482568SN/A#include "sim/eventq.hh"
492568SN/A
502568SN/Aclass Bridge : public MemObject
512568SN/A{
522568SN/A  protected:
532982Sstever@eecs.umich.edu    /** Declaration of the buses port type, one will be instantiated for each
542568SN/A        of the interfaces connecting to the bus. */
552568SN/A    class BridgePort : public Port
562568SN/A    {
572643Sstever@eecs.umich.edu        /** A pointer to the bridge to which this port belongs. */
582568SN/A        Bridge *bridge;
592568SN/A
602643Sstever@eecs.umich.edu        /**
612643Sstever@eecs.umich.edu         * Pointer to the port on the other side of the bridge
622643Sstever@eecs.umich.edu         * (connected to the other bus).
632643Sstever@eecs.umich.edu         */
642643Sstever@eecs.umich.edu        BridgePort *otherPort;
652643Sstever@eecs.umich.edu
662643Sstever@eecs.umich.edu        /** Minimum delay though this bridge. */
672643Sstever@eecs.umich.edu        Tick delay;
682643Sstever@eecs.umich.edu
692643Sstever@eecs.umich.edu        class PacketBuffer : public Packet::SenderState {
702643Sstever@eecs.umich.edu
712643Sstever@eecs.umich.edu          public:
722643Sstever@eecs.umich.edu            Tick ready;
733349Sbinkertn@umich.edu            PacketPtr pkt;
742643Sstever@eecs.umich.edu            Packet::SenderState *origSenderState;
752643Sstever@eecs.umich.edu            short origSrc;
762643Sstever@eecs.umich.edu            bool expectResponse;
772643Sstever@eecs.umich.edu
783349Sbinkertn@umich.edu            PacketBuffer(PacketPtr _pkt, Tick t)
792643Sstever@eecs.umich.edu                : ready(t), pkt(_pkt),
802643Sstever@eecs.umich.edu                  origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
812643Sstever@eecs.umich.edu                  expectResponse(_pkt->needsResponse())
822643Sstever@eecs.umich.edu            {
832657Ssaidi@eecs.umich.edu                if (!pkt->isResponse())
842657Ssaidi@eecs.umich.edu                    pkt->senderState = this;
852643Sstever@eecs.umich.edu            }
862643Sstever@eecs.umich.edu
873349Sbinkertn@umich.edu            void fixResponse(PacketPtr pkt)
882643Sstever@eecs.umich.edu            {
892643Sstever@eecs.umich.edu                assert(pkt->senderState == this);
902643Sstever@eecs.umich.edu                pkt->setDest(origSrc);
912643Sstever@eecs.umich.edu                pkt->senderState = origSenderState;
922643Sstever@eecs.umich.edu            }
932643Sstever@eecs.umich.edu        };
942643Sstever@eecs.umich.edu
952643Sstever@eecs.umich.edu        /**
962643Sstever@eecs.umich.edu         * Outbound packet queue.  Packets are held in this queue for a
972643Sstever@eecs.umich.edu         * specified delay to model the processing delay of the
982643Sstever@eecs.umich.edu         * bridge.
992643Sstever@eecs.umich.edu         */
1002643Sstever@eecs.umich.edu        std::list<PacketBuffer*> sendQueue;
1012643Sstever@eecs.umich.edu
1022643Sstever@eecs.umich.edu        int outstandingResponses;
1032643Sstever@eecs.umich.edu
1042643Sstever@eecs.umich.edu        /** Max queue size for outbound packets */
1052643Sstever@eecs.umich.edu        int queueLimit;
1062643Sstever@eecs.umich.edu
1072643Sstever@eecs.umich.edu        /**
1082643Sstever@eecs.umich.edu         * Is this side blocked from accepting outbound packets?
1092643Sstever@eecs.umich.edu         */
1102643Sstever@eecs.umich.edu        bool queueFull() { return (sendQueue.size() == queueLimit); }
1112643Sstever@eecs.umich.edu
1123349Sbinkertn@umich.edu        bool queueForSendTiming(PacketPtr pkt);
1132643Sstever@eecs.umich.edu
1142643Sstever@eecs.umich.edu        void finishSend(PacketBuffer *buf);
1152643Sstever@eecs.umich.edu
1162643Sstever@eecs.umich.edu        /**
1172643Sstever@eecs.umich.edu         * Handle send event, scheduled when the packet at the head of
1182643Sstever@eecs.umich.edu         * the outbound queue is ready to transmit (for timing
1192643Sstever@eecs.umich.edu         * accesses only).
1202643Sstever@eecs.umich.edu         */
1212643Sstever@eecs.umich.edu        void trySend();
1222643Sstever@eecs.umich.edu
1232643Sstever@eecs.umich.edu        class SendEvent : public Event
1242643Sstever@eecs.umich.edu        {
1252643Sstever@eecs.umich.edu            BridgePort *port;
1262643Sstever@eecs.umich.edu
1272643Sstever@eecs.umich.edu          public:
1282643Sstever@eecs.umich.edu            SendEvent(BridgePort *p)
1292643Sstever@eecs.umich.edu                : Event(&mainEventQueue), port(p) {}
1302643Sstever@eecs.umich.edu
1312643Sstever@eecs.umich.edu            virtual void process() { port->trySend(); }
1322643Sstever@eecs.umich.edu
1332643Sstever@eecs.umich.edu            virtual const char *description() { return "bridge send event"; }
1342643Sstever@eecs.umich.edu        };
1352643Sstever@eecs.umich.edu
1362643Sstever@eecs.umich.edu        SendEvent sendEvent;
1372568SN/A
1382568SN/A      public:
1392568SN/A
1402568SN/A        /** Constructor for the BusPort.*/
1412643Sstever@eecs.umich.edu        BridgePort(const std::string &_name,
1422643Sstever@eecs.umich.edu                   Bridge *_bridge, BridgePort *_otherPort,
1432643Sstever@eecs.umich.edu                   int _delay, int _queueLimit);
1442568SN/A
1452568SN/A      protected:
1462568SN/A
1472643Sstever@eecs.umich.edu        /** When receiving a timing request from the peer port,
1482643Sstever@eecs.umich.edu            pass it to the bridge. */
1493349Sbinkertn@umich.edu        virtual bool recvTiming(PacketPtr pkt);
1502568SN/A
1512643Sstever@eecs.umich.edu        /** When receiving a retry request from the peer port,
1522568SN/A            pass it to the bridge. */
1532657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1542568SN/A
1552643Sstever@eecs.umich.edu        /** When receiving a Atomic requestfrom the peer port,
1562568SN/A            pass it to the bridge. */
1573349Sbinkertn@umich.edu        virtual Tick recvAtomic(PacketPtr pkt);
1582568SN/A
1592643Sstever@eecs.umich.edu        /** When receiving a Functional request from the peer port,
1602568SN/A            pass it to the bridge. */
1613349Sbinkertn@umich.edu        virtual void recvFunctional(PacketPtr pkt);
1622568SN/A
1632643Sstever@eecs.umich.edu        /** When receiving a status changefrom the peer port,
1642568SN/A            pass it to the bridge. */
1652643Sstever@eecs.umich.edu        virtual void recvStatusChange(Status status);
1662568SN/A
1672643Sstever@eecs.umich.edu        /** When receiving a address range request the peer port,
1682568SN/A            pass it to the bridge. */
1692643Sstever@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1702643Sstever@eecs.umich.edu                                            AddrRangeList &snoop);
1712568SN/A    };
1722568SN/A
1732643Sstever@eecs.umich.edu    BridgePort portA, portB;
1742568SN/A
1752568SN/A    /** If this bridge should acknowledge writes. */
1762568SN/A    bool ackWrites;
1772568SN/A
1782568SN/A  public:
1792568SN/A
1802568SN/A    /** A function used to return the port associated with this bus object. */
1812738Sstever@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
1822568SN/A
1832568SN/A    virtual void init();
1842568SN/A
1852643Sstever@eecs.umich.edu    Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack);
1862568SN/A};
1872568SN/A
1882568SN/A#endif //__MEM_BUS_HH__
189