bridge.hh revision 2738
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/**
332568SN/A * @file Decleration of a simple bus bridge object with no buffering
342568SN/A */
352568SN/A
362568SN/A#ifndef __MEM_BRIDGE_HH__
372568SN/A#define __MEM_BRIDGE_HH__
382568SN/A
392568SN/A#include <string>
402568SN/A#include <list>
412568SN/A#include <inttypes.h>
422568SN/A#include <queue>
432568SN/A
442568SN/A#include "mem/mem_object.hh"
452568SN/A#include "mem/packet.hh"
462568SN/A#include "mem/port.hh"
472568SN/A#include "sim/eventq.hh"
482568SN/A
492568SN/Aclass Bridge : public MemObject
502568SN/A{
512568SN/A  protected:
522568SN/A    /** Decleration of the buses port type, one will be instantiated for each
532568SN/A        of the interfaces connecting to the bus. */
542568SN/A    class BridgePort : public Port
552568SN/A    {
562643Sstever@eecs.umich.edu        /** A pointer to the bridge to which this port belongs. */
572568SN/A        Bridge *bridge;
582568SN/A
592643Sstever@eecs.umich.edu        /**
602643Sstever@eecs.umich.edu         * Pointer to the port on the other side of the bridge
612643Sstever@eecs.umich.edu         * (connected to the other bus).
622643Sstever@eecs.umich.edu         */
632643Sstever@eecs.umich.edu        BridgePort *otherPort;
642643Sstever@eecs.umich.edu
652643Sstever@eecs.umich.edu        /** Minimum delay though this bridge. */
662643Sstever@eecs.umich.edu        Tick delay;
672643Sstever@eecs.umich.edu
682643Sstever@eecs.umich.edu        class PacketBuffer : public Packet::SenderState {
692643Sstever@eecs.umich.edu
702643Sstever@eecs.umich.edu          public:
712643Sstever@eecs.umich.edu            Tick ready;
722643Sstever@eecs.umich.edu            Packet *pkt;
732643Sstever@eecs.umich.edu            Packet::SenderState *origSenderState;
742643Sstever@eecs.umich.edu            short origSrc;
752643Sstever@eecs.umich.edu            bool expectResponse;
762643Sstever@eecs.umich.edu
772643Sstever@eecs.umich.edu            PacketBuffer(Packet *_pkt, Tick t)
782643Sstever@eecs.umich.edu                : ready(t), pkt(_pkt),
792643Sstever@eecs.umich.edu                  origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
802643Sstever@eecs.umich.edu                  expectResponse(_pkt->needsResponse())
812643Sstever@eecs.umich.edu            {
822657Ssaidi@eecs.umich.edu                if (!pkt->isResponse())
832657Ssaidi@eecs.umich.edu                    pkt->senderState = this;
842643Sstever@eecs.umich.edu            }
852643Sstever@eecs.umich.edu
862643Sstever@eecs.umich.edu            void fixResponse(Packet *pkt)
872643Sstever@eecs.umich.edu            {
882643Sstever@eecs.umich.edu                assert(pkt->senderState == this);
892643Sstever@eecs.umich.edu                pkt->setDest(origSrc);
902643Sstever@eecs.umich.edu                pkt->senderState = origSenderState;
912643Sstever@eecs.umich.edu            }
922643Sstever@eecs.umich.edu        };
932643Sstever@eecs.umich.edu
942643Sstever@eecs.umich.edu        /**
952643Sstever@eecs.umich.edu         * Outbound packet queue.  Packets are held in this queue for a
962643Sstever@eecs.umich.edu         * specified delay to model the processing delay of the
972643Sstever@eecs.umich.edu         * bridge.
982643Sstever@eecs.umich.edu         */
992643Sstever@eecs.umich.edu        std::list<PacketBuffer*> sendQueue;
1002643Sstever@eecs.umich.edu
1012643Sstever@eecs.umich.edu        int outstandingResponses;
1022643Sstever@eecs.umich.edu
1032643Sstever@eecs.umich.edu        /** Max queue size for outbound packets */
1042643Sstever@eecs.umich.edu        int queueLimit;
1052643Sstever@eecs.umich.edu
1062643Sstever@eecs.umich.edu        /**
1072643Sstever@eecs.umich.edu         * Is this side blocked from accepting outbound packets?
1082643Sstever@eecs.umich.edu         */
1092643Sstever@eecs.umich.edu        bool queueFull() { return (sendQueue.size() == queueLimit); }
1102643Sstever@eecs.umich.edu
1112643Sstever@eecs.umich.edu        bool queueForSendTiming(Packet *pkt);
1122643Sstever@eecs.umich.edu
1132643Sstever@eecs.umich.edu        void finishSend(PacketBuffer *buf);
1142643Sstever@eecs.umich.edu
1152643Sstever@eecs.umich.edu        /**
1162643Sstever@eecs.umich.edu         * Handle send event, scheduled when the packet at the head of
1172643Sstever@eecs.umich.edu         * the outbound queue is ready to transmit (for timing
1182643Sstever@eecs.umich.edu         * accesses only).
1192643Sstever@eecs.umich.edu         */
1202643Sstever@eecs.umich.edu        void trySend();
1212643Sstever@eecs.umich.edu
1222643Sstever@eecs.umich.edu        class SendEvent : public Event
1232643Sstever@eecs.umich.edu        {
1242643Sstever@eecs.umich.edu            BridgePort *port;
1252643Sstever@eecs.umich.edu
1262643Sstever@eecs.umich.edu          public:
1272643Sstever@eecs.umich.edu            SendEvent(BridgePort *p)
1282643Sstever@eecs.umich.edu                : Event(&mainEventQueue), port(p) {}
1292643Sstever@eecs.umich.edu
1302643Sstever@eecs.umich.edu            virtual void process() { port->trySend(); }
1312643Sstever@eecs.umich.edu
1322643Sstever@eecs.umich.edu            virtual const char *description() { return "bridge send event"; }
1332643Sstever@eecs.umich.edu        };
1342643Sstever@eecs.umich.edu
1352643Sstever@eecs.umich.edu        SendEvent sendEvent;
1362568SN/A
1372568SN/A      public:
1382568SN/A
1392568SN/A        /** Constructor for the BusPort.*/
1402643Sstever@eecs.umich.edu        BridgePort(const std::string &_name,
1412643Sstever@eecs.umich.edu                   Bridge *_bridge, BridgePort *_otherPort,
1422643Sstever@eecs.umich.edu                   int _delay, int _queueLimit);
1432568SN/A
1442568SN/A      protected:
1452568SN/A
1462643Sstever@eecs.umich.edu        /** When receiving a timing request from the peer port,
1472643Sstever@eecs.umich.edu            pass it to the bridge. */
1482643Sstever@eecs.umich.edu        virtual bool recvTiming(Packet *pkt);
1492568SN/A
1502643Sstever@eecs.umich.edu        /** When receiving a retry request from the peer port,
1512568SN/A            pass it to the bridge. */
1522657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1532568SN/A
1542643Sstever@eecs.umich.edu        /** When receiving a Atomic requestfrom the peer port,
1552568SN/A            pass it to the bridge. */
1562643Sstever@eecs.umich.edu        virtual Tick recvAtomic(Packet *pkt);
1572568SN/A
1582643Sstever@eecs.umich.edu        /** When receiving a Functional request from the peer port,
1592568SN/A            pass it to the bridge. */
1602643Sstever@eecs.umich.edu        virtual void recvFunctional(Packet *pkt);
1612568SN/A
1622643Sstever@eecs.umich.edu        /** When receiving a status changefrom the peer port,
1632568SN/A            pass it to the bridge. */
1642643Sstever@eecs.umich.edu        virtual void recvStatusChange(Status status);
1652568SN/A
1662643Sstever@eecs.umich.edu        /** When receiving a address range request the peer port,
1672568SN/A            pass it to the bridge. */
1682643Sstever@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1692643Sstever@eecs.umich.edu                                            AddrRangeList &snoop);
1702568SN/A    };
1712568SN/A
1722643Sstever@eecs.umich.edu    BridgePort portA, portB;
1732568SN/A
1742568SN/A    /** If this bridge should acknowledge writes. */
1752568SN/A    bool ackWrites;
1762568SN/A
1772568SN/A  public:
1782568SN/A
1792568SN/A    /** A function used to return the port associated with this bus object. */
1802738Sstever@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
1812568SN/A
1822568SN/A    virtual void init();
1832568SN/A
1842643Sstever@eecs.umich.edu    Bridge(const std::string &n, int qsa, int qsb, Tick _delay, int write_ack);
1852568SN/A};
1862568SN/A
1872568SN/A#endif //__MEM_BUS_HH__
188