bridge.hh revision 4475
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
694435Ssaidi@eecs.umich.edu        /** Min delay to respond to a nack. */
704435Ssaidi@eecs.umich.edu        Tick nackDelay;
714435Ssaidi@eecs.umich.edu
724432Ssaidi@eecs.umich.edu        bool fixPartialWrite;
734432Ssaidi@eecs.umich.edu
742643Sstever@eecs.umich.edu        class PacketBuffer : public Packet::SenderState {
752643Sstever@eecs.umich.edu
762643Sstever@eecs.umich.edu          public:
772643Sstever@eecs.umich.edu            Tick ready;
783349Sbinkertn@umich.edu            PacketPtr pkt;
792643Sstever@eecs.umich.edu            Packet::SenderState *origSenderState;
802643Sstever@eecs.umich.edu            short origSrc;
812643Sstever@eecs.umich.edu            bool expectResponse;
822643Sstever@eecs.umich.edu
834433Ssaidi@eecs.umich.edu            PacketBuffer(PacketPtr _pkt, Tick t, bool nack = false)
842643Sstever@eecs.umich.edu                : ready(t), pkt(_pkt),
852643Sstever@eecs.umich.edu                  origSenderState(_pkt->senderState), origSrc(_pkt->getSrc()),
864454Ssaidi@eecs.umich.edu                  expectResponse(_pkt->needsResponse() && !nack)
874433Ssaidi@eecs.umich.edu
882643Sstever@eecs.umich.edu            {
894450Ssaidi@eecs.umich.edu                if (!pkt->isResponse() && !nack && pkt->result != Packet::Nacked)
902657Ssaidi@eecs.umich.edu                    pkt->senderState = this;
912643Sstever@eecs.umich.edu            }
922643Sstever@eecs.umich.edu
933349Sbinkertn@umich.edu            void fixResponse(PacketPtr pkt)
942643Sstever@eecs.umich.edu            {
952643Sstever@eecs.umich.edu                assert(pkt->senderState == this);
962643Sstever@eecs.umich.edu                pkt->setDest(origSrc);
972643Sstever@eecs.umich.edu                pkt->senderState = origSenderState;
982643Sstever@eecs.umich.edu            }
992643Sstever@eecs.umich.edu        };
1002643Sstever@eecs.umich.edu
1012643Sstever@eecs.umich.edu        /**
1022643Sstever@eecs.umich.edu         * Outbound packet queue.  Packets are held in this queue for a
1032643Sstever@eecs.umich.edu         * specified delay to model the processing delay of the
1042643Sstever@eecs.umich.edu         * bridge.
1052643Sstever@eecs.umich.edu         */
1062643Sstever@eecs.umich.edu        std::list<PacketBuffer*> sendQueue;
1072643Sstever@eecs.umich.edu
1082643Sstever@eecs.umich.edu        int outstandingResponses;
1094433Ssaidi@eecs.umich.edu        int queuedRequests;
1102643Sstever@eecs.umich.edu
1114435Ssaidi@eecs.umich.edu        /** If we're waiting for a retry to happen.*/
1124435Ssaidi@eecs.umich.edu        bool inRetry;
1134435Ssaidi@eecs.umich.edu
1142643Sstever@eecs.umich.edu        /** Max queue size for outbound packets */
1154435Ssaidi@eecs.umich.edu        int reqQueueLimit;
1164435Ssaidi@eecs.umich.edu
1174435Ssaidi@eecs.umich.edu        /** Max queue size for reserved responses. */
1184435Ssaidi@eecs.umich.edu        int respQueueLimit;
1192643Sstever@eecs.umich.edu
1202643Sstever@eecs.umich.edu        /**
1212643Sstever@eecs.umich.edu         * Is this side blocked from accepting outbound packets?
1222643Sstever@eecs.umich.edu         */
1234435Ssaidi@eecs.umich.edu        bool respQueueFull();
1244435Ssaidi@eecs.umich.edu        bool reqQueueFull();
1252643Sstever@eecs.umich.edu
1264433Ssaidi@eecs.umich.edu        void queueForSendTiming(PacketPtr pkt);
1272643Sstever@eecs.umich.edu
1282643Sstever@eecs.umich.edu        void finishSend(PacketBuffer *buf);
1292643Sstever@eecs.umich.edu
1304433Ssaidi@eecs.umich.edu        void nackRequest(PacketPtr pkt);
1314433Ssaidi@eecs.umich.edu
1322643Sstever@eecs.umich.edu        /**
1332643Sstever@eecs.umich.edu         * Handle send event, scheduled when the packet at the head of
1342643Sstever@eecs.umich.edu         * the outbound queue is ready to transmit (for timing
1352643Sstever@eecs.umich.edu         * accesses only).
1362643Sstever@eecs.umich.edu         */
1372643Sstever@eecs.umich.edu        void trySend();
1382643Sstever@eecs.umich.edu
1392643Sstever@eecs.umich.edu        class SendEvent : public Event
1402643Sstever@eecs.umich.edu        {
1412643Sstever@eecs.umich.edu            BridgePort *port;
1422643Sstever@eecs.umich.edu
1432643Sstever@eecs.umich.edu          public:
1442643Sstever@eecs.umich.edu            SendEvent(BridgePort *p)
1452643Sstever@eecs.umich.edu                : Event(&mainEventQueue), port(p) {}
1462643Sstever@eecs.umich.edu
1472643Sstever@eecs.umich.edu            virtual void process() { port->trySend(); }
1482643Sstever@eecs.umich.edu
1492643Sstever@eecs.umich.edu            virtual const char *description() { return "bridge send event"; }
1502643Sstever@eecs.umich.edu        };
1512643Sstever@eecs.umich.edu
1522643Sstever@eecs.umich.edu        SendEvent sendEvent;
1532568SN/A
1542568SN/A      public:
1552568SN/A        /** Constructor for the BusPort.*/
1564435Ssaidi@eecs.umich.edu        BridgePort(const std::string &_name, Bridge *_bridge,
1574435Ssaidi@eecs.umich.edu                BridgePort *_otherPort, int _delay, int _nack_delay,
1584435Ssaidi@eecs.umich.edu                int _req_limit, int _resp_limit, bool fix_partial_write);
1592568SN/A
1602568SN/A      protected:
1612568SN/A
1622643Sstever@eecs.umich.edu        /** When receiving a timing request from the peer port,
1632643Sstever@eecs.umich.edu            pass it to the bridge. */
1643349Sbinkertn@umich.edu        virtual bool recvTiming(PacketPtr pkt);
1652568SN/A
1662643Sstever@eecs.umich.edu        /** When receiving a retry request from the peer port,
1672568SN/A            pass it to the bridge. */
1682657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1692568SN/A
1702643Sstever@eecs.umich.edu        /** When receiving a Atomic requestfrom the peer port,
1712568SN/A            pass it to the bridge. */
1723349Sbinkertn@umich.edu        virtual Tick recvAtomic(PacketPtr pkt);
1732568SN/A
1742643Sstever@eecs.umich.edu        /** When receiving a Functional request from the peer port,
1752568SN/A            pass it to the bridge. */
1763349Sbinkertn@umich.edu        virtual void recvFunctional(PacketPtr pkt);
1772568SN/A
1782643Sstever@eecs.umich.edu        /** When receiving a status changefrom the peer port,
1792568SN/A            pass it to the bridge. */
1802643Sstever@eecs.umich.edu        virtual void recvStatusChange(Status status);
1812568SN/A
1822643Sstever@eecs.umich.edu        /** When receiving a address range request the peer port,
1832568SN/A            pass it to the bridge. */
1842643Sstever@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1854475Sstever@eecs.umich.edu                                            bool &snoop);
1862568SN/A    };
1872568SN/A
1882643Sstever@eecs.umich.edu    BridgePort portA, portB;
1892568SN/A
1902568SN/A    /** If this bridge should acknowledge writes. */
1912568SN/A    bool ackWrites;
1922568SN/A
1932568SN/A  public:
1944435Ssaidi@eecs.umich.edu    struct Params
1954435Ssaidi@eecs.umich.edu    {
1964435Ssaidi@eecs.umich.edu        std::string name;
1974435Ssaidi@eecs.umich.edu        int req_size_a;
1984435Ssaidi@eecs.umich.edu        int req_size_b;
1994435Ssaidi@eecs.umich.edu        int resp_size_a;
2004435Ssaidi@eecs.umich.edu        int resp_size_b;
2014435Ssaidi@eecs.umich.edu        Tick delay;
2024435Ssaidi@eecs.umich.edu        Tick nack_delay;
2034435Ssaidi@eecs.umich.edu        bool write_ack;
2044435Ssaidi@eecs.umich.edu        bool fix_partial_write_a;
2054435Ssaidi@eecs.umich.edu        bool fix_partial_write_b;
2064435Ssaidi@eecs.umich.edu    };
2074435Ssaidi@eecs.umich.edu
2084435Ssaidi@eecs.umich.edu  protected:
2094435Ssaidi@eecs.umich.edu    Params *_params;
2104435Ssaidi@eecs.umich.edu
2114435Ssaidi@eecs.umich.edu  public:
2124435Ssaidi@eecs.umich.edu    const Params *params() const { return _params; }
2132568SN/A
2142568SN/A    /** A function used to return the port associated with this bus object. */
2152738Sstever@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
2162568SN/A
2172568SN/A    virtual void init();
2182568SN/A
2194435Ssaidi@eecs.umich.edu    Bridge(Params *p);
2202568SN/A};
2212568SN/A
2222568SN/A#endif //__MEM_BUS_HH__
223