port.hh revision 2661
12381SN/A/*
22381SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32381SN/A * All rights reserved.
42381SN/A *
52381SN/A * Redistribution and use in source and binary forms, with or without
62381SN/A * modification, are permitted provided that the following conditions are
72381SN/A * met: redistributions of source code must retain the above copyright
82381SN/A * notice, this list of conditions and the following disclaimer;
92381SN/A * redistributions in binary form must reproduce the above copyright
102381SN/A * notice, this list of conditions and the following disclaimer in the
112381SN/A * documentation and/or other materials provided with the distribution;
122381SN/A * neither the name of the copyright holders nor the names of its
132381SN/A * contributors may be used to endorse or promote products derived from
142381SN/A * this software without specific prior written permission.
152381SN/A *
162381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272381SN/A */
282381SN/A
292381SN/A/**
302381SN/A * @file
312381SN/A * Port Object Decleration. Ports are used to interface memory objects to
322381SN/A * each other.  They will always come in pairs, and we refer to the other
332381SN/A * port object as the peer.  These are used to make the design more
342381SN/A * modular so that a specific interface between every type of objcet doesn't
352381SN/A * have to be created.
362381SN/A */
372381SN/A
382381SN/A#ifndef __MEM_PORT_HH__
392381SN/A#define __MEM_PORT_HH__
402381SN/A
412381SN/A#include <list>
422381SN/A#include <inttypes.h>
432381SN/A
442439SN/A#include "base/misc.hh"
452381SN/A#include "base/range.hh"
462381SN/A#include "mem/packet.hh"
472381SN/A#include "mem/request.hh"
482381SN/A
492407SN/A/** This typedef is used to clean up the parameter list of
502407SN/A * getDeviceAddressRanges() and getPeerAddressRanges().  It's declared
512407SN/A * outside the Port object since it's also used by some mem objects.
522407SN/A * Eventually we should move this typedef to wherever Addr is
532407SN/A * defined.
542407SN/A */
552407SN/A
562407SN/Atypedef std::list<Range<Addr> > AddrRangeList;
572521SN/Atypedef std::list<Range<Addr> >::iterator AddrRangeIter;
582407SN/A
592381SN/A/**
602381SN/A * Ports are used to interface memory objects to
612381SN/A * each other.  They will always come in pairs, and we refer to the other
622381SN/A * port object as the peer.  These are used to make the design more
632381SN/A * modular so that a specific interface between every type of objcet doesn't
642381SN/A * have to be created.
652381SN/A *
662381SN/A * Recv accesor functions are being called from the peer interface.
672381SN/A * Send accessor functions are being called from the device the port is
682381SN/A * associated with, and it will call the peer recv. accessor function.
692381SN/A */
702381SN/Aclass Port
712381SN/A{
722640Sstever@eecs.umich.edu  private:
732640Sstever@eecs.umich.edu
742640Sstever@eecs.umich.edu    /** Descriptive name (for DPRINTF output) */
752640Sstever@eecs.umich.edu    const std::string portName;
762640Sstever@eecs.umich.edu
772661Sstever@eecs.umich.edu    /** A pointer to the peer port.  Ports always come in pairs, that way they
782661Sstever@eecs.umich.edu        can use a standardized interface to communicate between different
792661Sstever@eecs.umich.edu        memory objects. */
802661Sstever@eecs.umich.edu    Port *peer;
812661Sstever@eecs.umich.edu
822381SN/A  public:
832381SN/A
842640Sstever@eecs.umich.edu    /**
852640Sstever@eecs.umich.edu     * Constructor.
862640Sstever@eecs.umich.edu     *
872640Sstever@eecs.umich.edu     * @param _name Port name for DPRINTF output.  Should include name
882640Sstever@eecs.umich.edu     * of memory system object to which the port belongs.
892640Sstever@eecs.umich.edu     */
902640Sstever@eecs.umich.edu    Port(const std::string &_name)
912661Sstever@eecs.umich.edu        : portName(_name), peer(NULL)
922640Sstever@eecs.umich.edu    { }
932640Sstever@eecs.umich.edu
942640Sstever@eecs.umich.edu    /** Return port name (for DPRINTF). */
952640Sstever@eecs.umich.edu    const std::string &name() const { return portName; }
962640Sstever@eecs.umich.edu
972474SN/A    virtual ~Port() {};
982640Sstever@eecs.umich.edu
992381SN/A    // mey be better to use subclasses & RTTI?
1002657Ssaidi@eecs.umich.edu    /** Holds the ports status.  Currently just that a range recomputation needs
1012657Ssaidi@eecs.umich.edu     * to be done. */
1022381SN/A    enum Status {
1032381SN/A        RangeChange
1042381SN/A    };
1052381SN/A
1062381SN/A    /** Function to set the pointer for the peer port.
1072381SN/A        @todo should be called by the configuration stuff (python).
1082381SN/A    */
1092642Sstever@eecs.umich.edu    void setPeer(Port *port);
1102381SN/A
1112642Sstever@eecs.umich.edu    /** Function to set the pointer for the peer port.
1122408SN/A        @todo should be called by the configuration stuff (python).
1132408SN/A    */
1142409SN/A    Port *getPeer() { return peer; }
1152408SN/A
1162381SN/A  protected:
1172381SN/A
1182406SN/A    /** These functions are protected because they should only be
1192406SN/A     * called by a peer port, never directly by any outside object. */
1202406SN/A
1212381SN/A    /** Called to recive a timing call from the peer port. */
1222630SN/A    virtual bool recvTiming(Packet *pkt) = 0;
1232381SN/A
1242381SN/A    /** Called to recive a atomic call from the peer port. */
1252630SN/A    virtual Tick recvAtomic(Packet *pkt) = 0;
1262381SN/A
1272381SN/A    /** Called to recive a functional call from the peer port. */
1282630SN/A    virtual void recvFunctional(Packet *pkt) = 0;
1292381SN/A
1302381SN/A    /** Called to recieve a status change from the peer port. */
1312381SN/A    virtual void recvStatusChange(Status status) = 0;
1322381SN/A
1332381SN/A    /** Called by a peer port if the send was unsuccesful, and had to
1342381SN/A        wait.  This shouldn't be valid for response paths (IO Devices).
1352381SN/A        so it is set to panic if it isn't already defined.
1362381SN/A    */
1372657Ssaidi@eecs.umich.edu    virtual void recvRetry() { panic("??"); }
1382381SN/A
1392381SN/A    /** Called by a peer port in order to determine the block size of the
1402381SN/A        device connected to this port.  It sometimes doesn't make sense for
1412381SN/A        this function to be called, a DMA interface doesn't really have a
1422381SN/A        block size, so it is defaulted to a panic.
1432381SN/A    */
1442406SN/A    virtual int deviceBlockSize() { panic("??"); }
1452381SN/A
1462381SN/A    /** The peer port is requesting us to reply with a list of the ranges we
1472381SN/A        are responsible for.
1482521SN/A        @param resp is a list of ranges responded to
1492521SN/A        @param snoop is a list of ranges snooped
1502381SN/A    */
1512521SN/A    virtual void getDeviceAddressRanges(AddrRangeList &resp,
1522521SN/A            AddrRangeList &snoop)
1532407SN/A    { panic("??"); }
1542381SN/A
1552381SN/A  public:
1562381SN/A
1572381SN/A    /** Function called by associated memory device (cache, memory, iodevice)
1582381SN/A        in order to send a timing request to the port.  Simply calls the peer
1592381SN/A        port receive function.
1602381SN/A        @return This function returns if the send was succesful in it's
1612381SN/A        recieve. If it was a failure, then the port will wait for a recvRetry
1622657Ssaidi@eecs.umich.edu        at which point it can possibly issue a successful sendTiming.  This is used in
1632381SN/A        case a cache has a higher priority request come in while waiting for
1642381SN/A        the bus to arbitrate.
1652381SN/A    */
1662630SN/A    bool sendTiming(Packet *pkt) { return peer->recvTiming(pkt); }
1672381SN/A
1682381SN/A    /** Function called by the associated device to send an atomic access,
1692381SN/A        an access in which the data is moved and the state is updated in one
1702381SN/A        cycle, without interleaving with other memory accesses.
1712381SN/A    */
1722630SN/A    Tick sendAtomic(Packet *pkt)
1732381SN/A        { return peer->recvAtomic(pkt); }
1742381SN/A
1752381SN/A    /** Function called by the associated device to send a functional access,
1762381SN/A        an access in which the data is instantly updated everywhere in the
1772520SN/A        memory system, without affecting the current state of any block or
1782520SN/A        moving the block.
1792381SN/A    */
1802630SN/A    void sendFunctional(Packet *pkt)
1812381SN/A        { return peer->recvFunctional(pkt); }
1822381SN/A
1832381SN/A    /** Called by the associated device to send a status change to the device
1842381SN/A        connected to the peer interface.
1852381SN/A    */
1862381SN/A    void sendStatusChange(Status status) {peer->recvStatusChange(status); }
1872381SN/A
1882381SN/A    /** When a timing access doesn't return a success, some time later the
1892381SN/A        Retry will be sent.
1902381SN/A    */
1912657Ssaidi@eecs.umich.edu    void sendRetry() { return peer->recvRetry(); }
1922381SN/A
1932381SN/A    /** Called by the associated device if it wishes to find out the blocksize
1942381SN/A        of the device on attached to the peer port.
1952381SN/A    */
1962406SN/A    int peerBlockSize() { return peer->deviceBlockSize(); }
1972381SN/A
1982381SN/A    /** Called by the associated device if it wishes to find out the address
1992381SN/A        ranges connected to the peer ports devices.
2002381SN/A    */
2012521SN/A    void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
2022521SN/A    { peer->getDeviceAddressRanges(resp, snoop); }
2032381SN/A
2042461SN/A    /** This function is a wrapper around sendFunctional()
2052461SN/A        that breaks a larger, arbitrarily aligned access into
2062461SN/A        appropriate chunks.  The default implementation can use
2072461SN/A        getBlockSize() to determine the block size and go from there.
2082461SN/A    */
2092519SN/A    virtual void readBlob(Addr addr, uint8_t *p, int size);
2102381SN/A
2112381SN/A    /** This function is a wrapper around sendFunctional()
2122381SN/A        that breaks a larger, arbitrarily aligned access into
2132381SN/A        appropriate chunks.  The default implementation can use
2142381SN/A        getBlockSize() to determine the block size and go from there.
2152381SN/A    */
2162519SN/A    virtual void writeBlob(Addr addr, uint8_t *p, int size);
2172381SN/A
2182381SN/A    /** Fill size bytes starting at addr with byte value val.  This
2192381SN/A        should not need to be virtual, since it can be implemented in
2202461SN/A        terms of writeBlob().  However, it shouldn't be
2212381SN/A        performance-critical either, so it could be if we wanted to.
2222381SN/A    */
2232519SN/A    virtual void memsetBlob(Addr addr, uint8_t val, int size);
2242405SN/A
2252405SN/A  private:
2262405SN/A
2272405SN/A    /** Internal helper function for read/writeBlob().
2282405SN/A     */
2292641Sstever@eecs.umich.edu    void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd);
2302381SN/A};
2312381SN/A
2322520SN/A/** A simple functional port that is only meant for one way communication to
2332520SN/A * physical memory. It is only meant to be used to load data into memory before
2342520SN/A * the simulation begins.
2352520SN/A */
2362520SN/A
2372520SN/Aclass FunctionalPort : public Port
2382520SN/A{
2392520SN/A  public:
2402640Sstever@eecs.umich.edu    FunctionalPort(const std::string &_name)
2412640Sstever@eecs.umich.edu        : Port(_name)
2422640Sstever@eecs.umich.edu    {}
2432640Sstever@eecs.umich.edu
2442630SN/A    virtual bool recvTiming(Packet *pkt) { panic("FuncPort is UniDir"); }
2452630SN/A    virtual Tick recvAtomic(Packet *pkt) { panic("FuncPort is UniDir"); }
2462630SN/A    virtual void recvFunctional(Packet *pkt) { panic("FuncPort is UniDir"); }
2472590SN/A    virtual void recvStatusChange(Status status) {}
2482521SN/A
2492521SN/A    template <typename T>
2502521SN/A    inline void write(Addr addr, T d)
2512521SN/A    {
2522521SN/A        writeBlob(addr, (uint8_t*)&d, sizeof(T));
2532521SN/A    }
2542521SN/A
2552521SN/A    template <typename T>
2562521SN/A    inline T read(Addr addr)
2572521SN/A    {
2582521SN/A        T d;
2592521SN/A        readBlob(addr, (uint8_t*)&d, sizeof(T));
2602521SN/A        return d;
2612521SN/A    }
2622520SN/A};
2632520SN/A
2642381SN/A#endif //__MEM_PORT_HH__
265