qport.hh revision 8922
18914Sandreas.hansson@arm.com/*
28914Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
38914Sandreas.hansson@arm.com * All rights reserved.
48914Sandreas.hansson@arm.com *
58914Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68914Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78914Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88914Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98914Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108914Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118914Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128914Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138914Sandreas.hansson@arm.com *
148914Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
158914Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
168914Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
178914Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
188914Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
198914Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
208914Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
218914Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
228914Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
238914Sandreas.hansson@arm.com * this software without specific prior written permission.
248914Sandreas.hansson@arm.com *
258914Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
268914Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
278914Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
288914Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
298914Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
308914Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
318914Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
328914Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
338914Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
348914Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
358914Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
368914Sandreas.hansson@arm.com *
378914Sandreas.hansson@arm.com * Authors: Andreas Hansson
388914Sandreas.hansson@arm.com */
398914Sandreas.hansson@arm.com
408914Sandreas.hansson@arm.com#ifndef __MEM_QPORT_HH__
418914Sandreas.hansson@arm.com#define __MEM_QPORT_HH__
428914Sandreas.hansson@arm.com
438914Sandreas.hansson@arm.com/**
448914Sandreas.hansson@arm.com * @file
458914Sandreas.hansson@arm.com * Declaration of the queued port.
468914Sandreas.hansson@arm.com */
478914Sandreas.hansson@arm.com
488914Sandreas.hansson@arm.com#include "mem/packet_queue.hh"
498914Sandreas.hansson@arm.com#include "mem/port.hh"
508914Sandreas.hansson@arm.com
518914Sandreas.hansson@arm.com/**
528914Sandreas.hansson@arm.com * A queued port is a port that has an infinite queue for outgoing
538914Sandreas.hansson@arm.com * packets and thus decouples the module that wants to send
548914Sandreas.hansson@arm.com * request/responses from the flow control (retry mechanism) of the
558914Sandreas.hansson@arm.com * port. A queued port can be used by both a master and a slave. The
568914Sandreas.hansson@arm.com * queue is a parameter to allow tailoring of the queue implementation
578914Sandreas.hansson@arm.com * (used in the cache).
588914Sandreas.hansson@arm.com */
598922Swilliam.wang@arm.comclass QueuedSlavePort : public SlavePort
608914Sandreas.hansson@arm.com{
618914Sandreas.hansson@arm.com
628914Sandreas.hansson@arm.com  protected:
638914Sandreas.hansson@arm.com
648914Sandreas.hansson@arm.com    /** Packet queue used to store outgoing requests and responses. */
658914Sandreas.hansson@arm.com    PacketQueue &queue;
668914Sandreas.hansson@arm.com
678914Sandreas.hansson@arm.com     /** This function is notification that the device should attempt to send a
688914Sandreas.hansson@arm.com      * packet again. */
698914Sandreas.hansson@arm.com    virtual void recvRetry() { queue.retry(); }
708914Sandreas.hansson@arm.com
718922Swilliam.wang@arm.com  public:
728922Swilliam.wang@arm.com
738922Swilliam.wang@arm.com    /**
748922Swilliam.wang@arm.com     * Create a QueuedPort with a given name, owner, and a supplied
758922Swilliam.wang@arm.com     * implementation of a packet queue. The external definition of
768922Swilliam.wang@arm.com     * the queue enables e.g. the cache to implement a specific queue
778922Swilliam.wang@arm.com     * behaviuor in a subclass, and provide the latter to the
788922Swilliam.wang@arm.com     * QueuePort constructor.
798922Swilliam.wang@arm.com     */
808922Swilliam.wang@arm.com    QueuedSlavePort(const std::string& name, MemObject* owner,
818922Swilliam.wang@arm.com                    PacketQueue &queue) :
828922Swilliam.wang@arm.com        SlavePort(name, owner), queue(queue)
838922Swilliam.wang@arm.com    { }
848922Swilliam.wang@arm.com
858922Swilliam.wang@arm.com    virtual ~QueuedSlavePort() { }
868922Swilliam.wang@arm.com
878922Swilliam.wang@arm.com    /** Check the list of buffered packets against the supplied
888922Swilliam.wang@arm.com     * functional request. */
898922Swilliam.wang@arm.com    bool checkFunctional(PacketPtr pkt) { return queue.checkFunctional(pkt); }
908922Swilliam.wang@arm.com
918922Swilliam.wang@arm.com    /**
928922Swilliam.wang@arm.com     * Hook for draining the queued port.
938922Swilliam.wang@arm.com     *
948922Swilliam.wang@arm.com     * @param de an event which is used to signal back to the caller
958922Swilliam.wang@arm.com     * @returns a number indicating how many times process will be called
968922Swilliam.wang@arm.com     */
978922Swilliam.wang@arm.com    unsigned int drain(Event *de) { return queue.drain(de); }
988922Swilliam.wang@arm.com};
998922Swilliam.wang@arm.com
1008922Swilliam.wang@arm.comclass QueuedMasterPort : public MasterPort
1018922Swilliam.wang@arm.com{
1028922Swilliam.wang@arm.com
1038922Swilliam.wang@arm.com  protected:
1048922Swilliam.wang@arm.com
1058922Swilliam.wang@arm.com    /** Packet queue used to store outgoing requests and responses. */
1068922Swilliam.wang@arm.com    PacketQueue &queue;
1078922Swilliam.wang@arm.com
1088922Swilliam.wang@arm.com     /** This function is notification that the device should attempt to send a
1098922Swilliam.wang@arm.com      * packet again. */
1108922Swilliam.wang@arm.com    virtual void recvRetry() { queue.retry(); }
1118914Sandreas.hansson@arm.com
1128914Sandreas.hansson@arm.com  public:
1138914Sandreas.hansson@arm.com
1148914Sandreas.hansson@arm.com    /**
1158914Sandreas.hansson@arm.com     * Create a QueuedPort with a given name, owner, and a supplied
1168914Sandreas.hansson@arm.com     * implementation of a packet queue. The external definition of
1178914Sandreas.hansson@arm.com     * the queue enables e.g. the cache to implement a specific queue
1188914Sandreas.hansson@arm.com     * behaviuor in a subclass, and provide the latter to the
1198914Sandreas.hansson@arm.com     * QueuePort constructor.
1208914Sandreas.hansson@arm.com     */
1218922Swilliam.wang@arm.com    QueuedMasterPort(const std::string& name, MemObject* owner,
1228922Swilliam.wang@arm.com                    PacketQueue &queue) :
1238922Swilliam.wang@arm.com        MasterPort(name, owner), queue(queue)
1248914Sandreas.hansson@arm.com    { }
1258914Sandreas.hansson@arm.com
1268922Swilliam.wang@arm.com    virtual ~QueuedMasterPort() { }
1278914Sandreas.hansson@arm.com
1288914Sandreas.hansson@arm.com    /** Check the list of buffered packets against the supplied
1298914Sandreas.hansson@arm.com     * functional request. */
1308914Sandreas.hansson@arm.com    bool checkFunctional(PacketPtr pkt) { return queue.checkFunctional(pkt); }
1318914Sandreas.hansson@arm.com
1328914Sandreas.hansson@arm.com    /**
1338914Sandreas.hansson@arm.com     * Hook for draining the queued port.
1348914Sandreas.hansson@arm.com     *
1358914Sandreas.hansson@arm.com     * @param de an event which is used to signal back to the caller
1368914Sandreas.hansson@arm.com     * @returns a number indicating how many times process will be called
1378914Sandreas.hansson@arm.com     */
1388914Sandreas.hansson@arm.com    unsigned int drain(Event *de) { return queue.drain(de); }
1398914Sandreas.hansson@arm.com};
1408914Sandreas.hansson@arm.com
1418914Sandreas.hansson@arm.com#endif // __MEM_QPORT_HH__
142