bridge.hh revision 12823:ba630bc7a36d
15323Sgblack@eecs.umich.edu/*
22934Sktlim@umich.edu * Copyright (c) 2011-2013 ARM Limited
32934Sktlim@umich.edu * All rights reserved
42934Sktlim@umich.edu *
52934Sktlim@umich.edu * The license below extends only to copyright in the software and shall
62934Sktlim@umich.edu * not be construed as granting a license to any other intellectual
72934Sktlim@umich.edu * property including but not limited to intellectual property relating
82934Sktlim@umich.edu * to a hardware implementation of the functionality of the software
92934Sktlim@umich.edu * licensed hereunder.  You may use the software subject to the license
102934Sktlim@umich.edu * terms below provided that you ensure that this notice is replicated
112934Sktlim@umich.edu * unmodified and in its entirety in all distributions of the software,
122934Sktlim@umich.edu * modified or unmodified, in source code or in binary form.
132934Sktlim@umich.edu *
142934Sktlim@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
152934Sktlim@umich.edu * All rights reserved.
162934Sktlim@umich.edu *
172934Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without
182934Sktlim@umich.edu * modification, are permitted provided that the following conditions are
192934Sktlim@umich.edu * met: redistributions of source code must retain the above copyright
202934Sktlim@umich.edu * notice, this list of conditions and the following disclaimer;
212934Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright
222934Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the
232934Sktlim@umich.edu * documentation and/or other materials provided with the distribution;
242934Sktlim@umich.edu * neither the name of the copyright holders nor the names of its
252934Sktlim@umich.edu * contributors may be used to endorse or promote products derived from
262934Sktlim@umich.edu * this software without specific prior written permission.
272934Sktlim@umich.edu *
282934Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292934Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302995Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312934Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322934Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332934Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342934Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352934Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362934Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372934Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382934Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396122SSteve.Reinhardt@amd.com *
406122SSteve.Reinhardt@amd.com * Authors: Ali Saidi
416122SSteve.Reinhardt@amd.com *          Steve Reinhardt
426122SSteve.Reinhardt@amd.com *          Andreas Hansson
436122SSteve.Reinhardt@amd.com */
444520Ssaidi@eecs.umich.edu
454520Ssaidi@eecs.umich.edu/**
464982Ssaidi@eecs.umich.edu * @file
474520Ssaidi@eecs.umich.edu * Declaration of a memory-mapped bridge that connects a master
484520Ssaidi@eecs.umich.edu * and a slave through a request and response queue.
492934Sktlim@umich.edu */
502934Sktlim@umich.edu
513005Sstever@eecs.umich.edu#ifndef __MEM_BRIDGE_HH__
523005Sstever@eecs.umich.edu#define __MEM_BRIDGE_HH__
533304Sstever@eecs.umich.edu
542995Ssaidi@eecs.umich.edu#include <deque>
552934Sktlim@umich.edu
566122SSteve.Reinhardt@amd.com#include "base/types.hh"
574965Ssaidi@eecs.umich.edu#include "mem/mem_object.hh"
585266Sksewell@umich.edu#include "params/Bridge.hh"
592934Sktlim@umich.edu
602934Sktlim@umich.edu/**
612934Sktlim@umich.edu * A bridge is used to interface two different crossbars (or in general a
622934Sktlim@umich.edu * memory-mapped master and slave), with buffering for requests and
632934Sktlim@umich.edu * responses. The bridge has a fixed delay for packets passing through
642995Ssaidi@eecs.umich.edu * it and responds to a fixed set of address ranges.
652934Sktlim@umich.edu *
662934Sktlim@umich.edu * The bridge comprises a slave port and a master port, that buffer
672934Sktlim@umich.edu * outgoing responses and requests respectively. Buffer space is
682934Sktlim@umich.edu * reserved when a request arrives, also reserving response space
692934Sktlim@umich.edu * before forwarding the request. If there is no space present, then
702995Ssaidi@eecs.umich.edu * the bridge will delay accepting the packet until space becomes
712934Sktlim@umich.edu * available.
722934Sktlim@umich.edu */
732953Sktlim@umich.educlass Bridge : public MemObject
745478Snate@binkert.org{
752934Sktlim@umich.edu  protected:
763449Shsul@eecs.umich.edu
772934Sktlim@umich.edu    /**
782934Sktlim@umich.edu     * A deferred packet stores a packet along with its scheduled
792934Sktlim@umich.edu     * transmission time
802934Sktlim@umich.edu     */
812934Sktlim@umich.edu    class DeferredPacket
827014SBrad.Beckmann@amd.com    {
836765SBrad.Beckmann@amd.com
846765SBrad.Beckmann@amd.com      public:
856765SBrad.Beckmann@amd.com
866765SBrad.Beckmann@amd.com        const Tick tick;
876765SBrad.Beckmann@amd.com        const PacketPtr pkt;
887014SBrad.Beckmann@amd.com
897014SBrad.Beckmann@amd.com        DeferredPacket(PacketPtr _pkt, Tick _tick) : tick(_tick), pkt(_pkt)
906765SBrad.Beckmann@amd.com        { }
916765SBrad.Beckmann@amd.com    };
926765SBrad.Beckmann@amd.com
936765SBrad.Beckmann@amd.com    // Forward declaration to allow the slave port to have a pointer
946765SBrad.Beckmann@amd.com    class BridgeMasterPort;
956765SBrad.Beckmann@amd.com
966765SBrad.Beckmann@amd.com    /**
976893SBrad.Beckmann@amd.com     * The port on the side that receives requests and sends
986893SBrad.Beckmann@amd.com     * responses. The slave port has a set of address ranges that it
996893SBrad.Beckmann@amd.com     * is responsible for. The slave port also has a buffer for the
1006893SBrad.Beckmann@amd.com     * responses not yet sent.
1016893SBrad.Beckmann@amd.com     */
1026893SBrad.Beckmann@amd.com    class BridgeSlavePort : public SlavePort
1037014SBrad.Beckmann@amd.com    {
1046893SBrad.Beckmann@amd.com
1056765SBrad.Beckmann@amd.com      private:
1066765SBrad.Beckmann@amd.com
1076765SBrad.Beckmann@amd.com        /** The bridge to which this port belongs. */
1086765SBrad.Beckmann@amd.com        Bridge& bridge;
1096765SBrad.Beckmann@amd.com
1106765SBrad.Beckmann@amd.com        /**
1116765SBrad.Beckmann@amd.com         * Master port on the other side of the bridge.
1126765SBrad.Beckmann@amd.com         */
1136765SBrad.Beckmann@amd.com        BridgeMasterPort& masterPort;
1146893SBrad.Beckmann@amd.com
1156893SBrad.Beckmann@amd.com        /** Minimum request delay though this bridge. */
1166893SBrad.Beckmann@amd.com        const Cycles delay;
1176893SBrad.Beckmann@amd.com
1186765SBrad.Beckmann@amd.com        /** Address ranges to pass through the bridge */
1196765SBrad.Beckmann@amd.com        const AddrRangeList ranges;
1206765SBrad.Beckmann@amd.com
1216765SBrad.Beckmann@amd.com        /**
1226765SBrad.Beckmann@amd.com         * Response packet queue. Response packets are held in this
1236765SBrad.Beckmann@amd.com         * queue for a specified delay to model the processing delay
1246765SBrad.Beckmann@amd.com         * of the bridge. We use a deque as we need to iterate over
1256765SBrad.Beckmann@amd.com         * the items for functional accesses.
1266765SBrad.Beckmann@amd.com         */
1276765SBrad.Beckmann@amd.com        std::deque<DeferredPacket> transmitList;
1286765SBrad.Beckmann@amd.com
1296765SBrad.Beckmann@amd.com        /** Counter to track the outstanding responses. */
1306765SBrad.Beckmann@amd.com        unsigned int outstandingResponses;
1313584Ssaidi@eecs.umich.edu
1324486Sbinkertn@umich.edu        /** If we should send a retry when space becomes available. */
1334486Sbinkertn@umich.edu        bool retryReq;
1344486Sbinkertn@umich.edu
1354486Sbinkertn@umich.edu        /** Max queue size for reserved responses. */
1364486Sbinkertn@umich.edu        unsigned int respQueueLimit;
1374486Sbinkertn@umich.edu
1384486Sbinkertn@umich.edu        /**
1393584Ssaidi@eecs.umich.edu         * Upstream caches need this packet until true is returned, so
1403584Ssaidi@eecs.umich.edu         * hold it for deletion until a subsequent call
1413584Ssaidi@eecs.umich.edu         */
1423584Ssaidi@eecs.umich.edu        std::unique_ptr<Packet> pendingDelete;
1433584Ssaidi@eecs.umich.edu
1443743Sgblack@eecs.umich.edu        /**
1456122SSteve.Reinhardt@amd.com         * Is this side blocked from accepting new response packets.
1464972Ssaidi@eecs.umich.edu         *
1473743Sgblack@eecs.umich.edu         * @return true if the reserved space has reached the set limit
1484104Ssaidi@eecs.umich.edu         */
1493743Sgblack@eecs.umich.edu        bool respQueueFull() const;
1503823Ssaidi@eecs.umich.edu
1513814Ssaidi@eecs.umich.edu        /**
1523743Sgblack@eecs.umich.edu         * Handle send event, scheduled when the packet at the head of
1533743Sgblack@eecs.umich.edu         * the response queue is ready to transmit (for timing
1543584Ssaidi@eecs.umich.edu         * accesses only).
1553814Ssaidi@eecs.umich.edu         */
1563584Ssaidi@eecs.umich.edu        void trySendTiming();
1573745Sgblack@eecs.umich.edu
1583745Sgblack@eecs.umich.edu        /** Send event for the response queue. */
1593745Sgblack@eecs.umich.edu        EventFunctionWrapper sendEvent;
1603584Ssaidi@eecs.umich.edu
1613898Ssaidi@eecs.umich.edu      public:
1623898Ssaidi@eecs.umich.edu
1633898Ssaidi@eecs.umich.edu        /**
1644103Ssaidi@eecs.umich.edu         * Constructor for the BridgeSlavePort.
1654103Ssaidi@eecs.umich.edu         *
1664103Ssaidi@eecs.umich.edu         * @param _name the port name including the owner
1673745Sgblack@eecs.umich.edu         * @param _bridge the structural owner
1683745Sgblack@eecs.umich.edu         * @param _masterPort the master port on the other side of the bridge
1693745Sgblack@eecs.umich.edu         * @param _delay the delay in cycles from receiving to sending
1703584Ssaidi@eecs.umich.edu         * @param _resp_limit the size of the response queue
1713584Ssaidi@eecs.umich.edu         * @param _ranges a number of address ranges to forward
1723584Ssaidi@eecs.umich.edu         */
1735222Sksewell@umich.edu        BridgeSlavePort(const std::string& _name, Bridge& _bridge,
1745222Sksewell@umich.edu                        BridgeMasterPort& _masterPort, Cycles _delay,
1755222Sksewell@umich.edu                        int _resp_limit, std::vector<AddrRange> _ranges);
1765222Sksewell@umich.edu
1775222Sksewell@umich.edu        /**
1785222Sksewell@umich.edu         * Queue a response packet to be sent out later and also schedule
1795222Sksewell@umich.edu         * a send if necessary.
1805222Sksewell@umich.edu         *
1815222Sksewell@umich.edu         * @param pkt a response to send out after a delay
1825222Sksewell@umich.edu         * @param when tick when response packet should be sent
1835222Sksewell@umich.edu         */
1845222Sksewell@umich.edu        void schedTimingResp(PacketPtr pkt, Tick when);
1856122SSteve.Reinhardt@amd.com
1865222Sksewell@umich.edu        /**
1875222Sksewell@umich.edu         * Retry any stalled request that we have failed to accept at
1885222Sksewell@umich.edu         * an earlier point in time. This call will do nothing if no
1895222Sksewell@umich.edu         * request is waiting.
1905222Sksewell@umich.edu         */
1915222Sksewell@umich.edu        void retryStalledReq();
1925222Sksewell@umich.edu
1935222Sksewell@umich.edu      protected:
1945222Sksewell@umich.edu
1955222Sksewell@umich.edu        /** When receiving a timing request from the peer port,
1965222Sksewell@umich.edu            pass it to the bridge. */
1975222Sksewell@umich.edu        bool recvTimingReq(PacketPtr pkt);
1985222Sksewell@umich.edu
1995222Sksewell@umich.edu        /** When receiving a retry request from the peer port,
2005222Sksewell@umich.edu            pass it to the bridge. */
2015222Sksewell@umich.edu        void recvRespRetry();
2025222Sksewell@umich.edu
2035478Snate@binkert.org        /** When receiving a Atomic requestfrom the peer port,
2045222Sksewell@umich.edu            pass it to the bridge. */
2055222Sksewell@umich.edu        Tick recvAtomic(PacketPtr pkt);
2065222Sksewell@umich.edu
2075222Sksewell@umich.edu        /** When receiving a Functional request from the peer port,
2085222Sksewell@umich.edu            pass it to the bridge. */
2095222Sksewell@umich.edu        void recvFunctional(PacketPtr pkt);
2105323Sgblack@eecs.umich.edu
2115357Sgblack@eecs.umich.edu        /** When receiving a address range request the peer port,
2125323Sgblack@eecs.umich.edu            pass it to the bridge. */
2135323Sgblack@eecs.umich.edu        AddrRangeList getAddrRanges() const;
2146135Sgblack@eecs.umich.edu    };
2155613Sgblack@eecs.umich.edu
2165613Sgblack@eecs.umich.edu
2175613Sgblack@eecs.umich.edu    /**
2185133Sgblack@eecs.umich.edu     * Port on the side that forwards requests and receives
2195133Sgblack@eecs.umich.edu     * responses. The master port has a buffer for the requests not
2205133Sgblack@eecs.umich.edu     * yet sent.
2215841Sgblack@eecs.umich.edu     */
2225133Sgblack@eecs.umich.edu    class BridgeMasterPort : public MasterPort
2235133Sgblack@eecs.umich.edu    {
2246802Sgblack@eecs.umich.edu
2256802Sgblack@eecs.umich.edu      private:
2265133Sgblack@eecs.umich.edu
2276122SSteve.Reinhardt@amd.com        /** The bridge to which this port belongs. */
2285450Sgblack@eecs.umich.edu        Bridge& bridge;
2295133Sgblack@eecs.umich.edu
2305133Sgblack@eecs.umich.edu        /**
2315613Sgblack@eecs.umich.edu         * The slave port on the other side of the bridge.
2325613Sgblack@eecs.umich.edu         */
2335613Sgblack@eecs.umich.edu        BridgeSlavePort& slavePort;
2345613Sgblack@eecs.umich.edu
2355613Sgblack@eecs.umich.edu        /** Minimum delay though this bridge. */
2365613Sgblack@eecs.umich.edu        const Cycles delay;
2375613Sgblack@eecs.umich.edu
2385638Sgblack@eecs.umich.edu        /**
2395613Sgblack@eecs.umich.edu         * Request packet queue. Request packets are held in this
2405613Sgblack@eecs.umich.edu         * queue for a specified delay to model the processing delay
2415613Sgblack@eecs.umich.edu         * of the bridge.  We use a deque as we need to iterate over
2425613Sgblack@eecs.umich.edu         * the items for functional accesses.
2435841Sgblack@eecs.umich.edu         */
2445841Sgblack@eecs.umich.edu        std::deque<DeferredPacket> transmitList;
2455841Sgblack@eecs.umich.edu
2465841Sgblack@eecs.umich.edu        /** Max queue size for request packets */
2475841Sgblack@eecs.umich.edu        const unsigned int reqQueueLimit;
2485841Sgblack@eecs.umich.edu
2495841Sgblack@eecs.umich.edu        /**
2505615Sgblack@eecs.umich.edu         * Handle send event, scheduled when the packet at the head of
2515615Sgblack@eecs.umich.edu         * the outbound queue is ready to transmit (for timing
2525615Sgblack@eecs.umich.edu         * accesses only).
2535615Sgblack@eecs.umich.edu         */
2545641Sgblack@eecs.umich.edu        void trySendTiming();
2556135Sgblack@eecs.umich.edu
2566135Sgblack@eecs.umich.edu        /** Send event for the request queue. */
2576135Sgblack@eecs.umich.edu        EventFunctionWrapper sendEvent;
2586135Sgblack@eecs.umich.edu
2596135Sgblack@eecs.umich.edu      public:
2606135Sgblack@eecs.umich.edu
2616135Sgblack@eecs.umich.edu        /**
2625644Sgblack@eecs.umich.edu         * Constructor for the BridgeMasterPort.
2636135Sgblack@eecs.umich.edu         *
2645644Sgblack@eecs.umich.edu         * @param _name the port name including the owner
2655644Sgblack@eecs.umich.edu         * @param _bridge the structural owner
2665644Sgblack@eecs.umich.edu         * @param _slavePort the slave port on the other side of the bridge
2676135Sgblack@eecs.umich.edu         * @param _delay the delay in cycles from receiving to sending
2685644Sgblack@eecs.umich.edu         * @param _req_limit the size of the request queue
2695644Sgblack@eecs.umich.edu         */
2705644Sgblack@eecs.umich.edu        BridgeMasterPort(const std::string& _name, Bridge& _bridge,
2715843Sgblack@eecs.umich.edu                         BridgeSlavePort& _slavePort, Cycles _delay,
2725843Sgblack@eecs.umich.edu                         int _req_limit);
2735843Sgblack@eecs.umich.edu
2745843Sgblack@eecs.umich.edu        /**
2755843Sgblack@eecs.umich.edu         * Is this side blocked from accepting new request packets.
2765843Sgblack@eecs.umich.edu         *
2775843Sgblack@eecs.umich.edu         * @return true if the occupied space has reached the set limit
2785843Sgblack@eecs.umich.edu         */
2795843Sgblack@eecs.umich.edu        bool reqQueueFull() const;
2805843Sgblack@eecs.umich.edu
2815843Sgblack@eecs.umich.edu        /**
2826044Sgblack@eecs.umich.edu         * Queue a request packet to be sent out later and also schedule
2835843Sgblack@eecs.umich.edu         * a send if necessary.
2846074Sgblack@eecs.umich.edu         *
2856135Sgblack@eecs.umich.edu         * @param pkt a request to send out after a delay
2866135Sgblack@eecs.umich.edu         * @param when tick when response packet should be sent
2876135Sgblack@eecs.umich.edu         */
2886135Sgblack@eecs.umich.edu        void schedTimingReq(PacketPtr pkt, Tick when);
2896135Sgblack@eecs.umich.edu
2906135Sgblack@eecs.umich.edu        /**
2916135Sgblack@eecs.umich.edu         * Check a functional request against the packets in our
2926135Sgblack@eecs.umich.edu         * request queue.
2936135Sgblack@eecs.umich.edu         *
2946135Sgblack@eecs.umich.edu         * @param pkt packet to check against
2956135Sgblack@eecs.umich.edu         *
2966135Sgblack@eecs.umich.edu         * @return true if we find a match
2976135Sgblack@eecs.umich.edu         */
2986135Sgblack@eecs.umich.edu        bool trySatisfyFunctional(PacketPtr pkt);
2996135Sgblack@eecs.umich.edu
3006135Sgblack@eecs.umich.edu      protected:
3016135Sgblack@eecs.umich.edu
3026135Sgblack@eecs.umich.edu        /** When receiving a timing request from the peer port,
3036135Sgblack@eecs.umich.edu            pass it to the bridge. */
3046135Sgblack@eecs.umich.edu        bool recvTimingResp(PacketPtr pkt);
3056135Sgblack@eecs.umich.edu
3066135Sgblack@eecs.umich.edu        /** When receiving a retry request from the peer port,
3076135Sgblack@eecs.umich.edu            pass it to the bridge. */
3085641Sgblack@eecs.umich.edu        void recvReqRetry();
3095613Sgblack@eecs.umich.edu    };
3106135Sgblack@eecs.umich.edu
3115613Sgblack@eecs.umich.edu    /** Slave port of the bridge. */
3125613Sgblack@eecs.umich.edu    BridgeSlavePort slavePort;
3135613Sgblack@eecs.umich.edu
3146135Sgblack@eecs.umich.edu    /** Master port of the bridge. */
3155613Sgblack@eecs.umich.edu    BridgeMasterPort masterPort;
3165450Sgblack@eecs.umich.edu
3175450Sgblack@eecs.umich.edu  public:
3185450Sgblack@eecs.umich.edu
3195450Sgblack@eecs.umich.edu    virtual BaseMasterPort& getMasterPort(const std::string& if_name,
3205450Sgblack@eecs.umich.edu                                          PortID idx = InvalidPortID);
3215450Sgblack@eecs.umich.edu    virtual BaseSlavePort& getSlavePort(const std::string& if_name,
3225450Sgblack@eecs.umich.edu                                        PortID idx = InvalidPortID);
3235450Sgblack@eecs.umich.edu
3245450Sgblack@eecs.umich.edu    virtual void init();
3255450Sgblack@eecs.umich.edu
3265450Sgblack@eecs.umich.edu    typedef BridgeParams Params;
3275450Sgblack@eecs.umich.edu
3285450Sgblack@eecs.umich.edu    Bridge(Params *p);
3296072Sgblack@eecs.umich.edu};
3305450Sgblack@eecs.umich.edu
3315450Sgblack@eecs.umich.edu#endif //__MEM_BRIDGE_HH__
3325330Sgblack@eecs.umich.edu