port.hh revision 2640
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
772381SN/A  public:
782381SN/A
792640Sstever@eecs.umich.edu    /**
802640Sstever@eecs.umich.edu     * Constructor.
812640Sstever@eecs.umich.edu     *
822640Sstever@eecs.umich.edu     * @param _name Port name for DPRINTF output.  Should include name
832640Sstever@eecs.umich.edu     * of memory system object to which the port belongs.
842640Sstever@eecs.umich.edu     */
852640Sstever@eecs.umich.edu    Port(const std::string &_name)
862640Sstever@eecs.umich.edu        : portName(_name)
872640Sstever@eecs.umich.edu    { }
882640Sstever@eecs.umich.edu
892640Sstever@eecs.umich.edu    /** Return port name (for DPRINTF). */
902640Sstever@eecs.umich.edu    const std::string &name() const { return portName; }
912640Sstever@eecs.umich.edu
922474SN/A    virtual ~Port() {};
932640Sstever@eecs.umich.edu
942381SN/A    // mey be better to use subclasses & RTTI?
952381SN/A    /** Holds the ports status.  Keeps track if it is blocked, or has
962381SN/A        calculated a range change. */
972381SN/A    enum Status {
982381SN/A        Blocked,
992381SN/A        Unblocked,
1002381SN/A        RangeChange
1012381SN/A    };
1022381SN/A
1032381SN/A  private:
1042381SN/A
1052381SN/A    /** A pointer to the peer port.  Ports always come in pairs, that way they
1062381SN/A        can use a standardized interface to communicate between different
1072381SN/A        memory objects. */
1082381SN/A    Port *peer;
1092381SN/A
1102381SN/A  public:
1112381SN/A
1122381SN/A    /** Function to set the pointer for the peer port.
1132381SN/A        @todo should be called by the configuration stuff (python).
1142381SN/A    */
1152381SN/A    void setPeer(Port *port) { peer = port; }
1162381SN/A
1172408SN/A        /** Function to set the pointer for the peer port.
1182408SN/A        @todo should be called by the configuration stuff (python).
1192408SN/A    */
1202409SN/A    Port *getPeer() { return peer; }
1212408SN/A
1222381SN/A  protected:
1232381SN/A
1242406SN/A    /** These functions are protected because they should only be
1252406SN/A     * called by a peer port, never directly by any outside object. */
1262406SN/A
1272381SN/A    /** Called to recive a timing call from the peer port. */
1282630SN/A    virtual bool recvTiming(Packet *pkt) = 0;
1292381SN/A
1302381SN/A    /** Called to recive a atomic call from the peer port. */
1312630SN/A    virtual Tick recvAtomic(Packet *pkt) = 0;
1322381SN/A
1332381SN/A    /** Called to recive a functional call from the peer port. */
1342630SN/A    virtual void recvFunctional(Packet *pkt) = 0;
1352381SN/A
1362381SN/A    /** Called to recieve a status change from the peer port. */
1372381SN/A    virtual void recvStatusChange(Status status) = 0;
1382381SN/A
1392381SN/A    /** Called by a peer port if the send was unsuccesful, and had to
1402381SN/A        wait.  This shouldn't be valid for response paths (IO Devices).
1412381SN/A        so it is set to panic if it isn't already defined.
1422381SN/A    */
1432381SN/A    virtual Packet *recvRetry() { panic("??"); }
1442381SN/A
1452381SN/A    /** Called by a peer port in order to determine the block size of the
1462381SN/A        device connected to this port.  It sometimes doesn't make sense for
1472381SN/A        this function to be called, a DMA interface doesn't really have a
1482381SN/A        block size, so it is defaulted to a panic.
1492381SN/A    */
1502406SN/A    virtual int deviceBlockSize() { panic("??"); }
1512381SN/A
1522381SN/A    /** The peer port is requesting us to reply with a list of the ranges we
1532381SN/A        are responsible for.
1542521SN/A        @param resp is a list of ranges responded to
1552521SN/A        @param snoop is a list of ranges snooped
1562381SN/A    */
1572521SN/A    virtual void getDeviceAddressRanges(AddrRangeList &resp,
1582521SN/A            AddrRangeList &snoop)
1592407SN/A    { panic("??"); }
1602381SN/A
1612381SN/A  public:
1622381SN/A
1632381SN/A    /** Function called by associated memory device (cache, memory, iodevice)
1642381SN/A        in order to send a timing request to the port.  Simply calls the peer
1652381SN/A        port receive function.
1662381SN/A        @return This function returns if the send was succesful in it's
1672381SN/A        recieve. If it was a failure, then the port will wait for a recvRetry
1682381SN/A        at which point it can issue a successful sendTiming.  This is used in
1692381SN/A        case a cache has a higher priority request come in while waiting for
1702381SN/A        the bus to arbitrate.
1712381SN/A    */
1722630SN/A    bool sendTiming(Packet *pkt) { return peer->recvTiming(pkt); }
1732381SN/A
1742381SN/A    /** Function called by the associated device to send an atomic access,
1752381SN/A        an access in which the data is moved and the state is updated in one
1762381SN/A        cycle, without interleaving with other memory accesses.
1772381SN/A    */
1782630SN/A    Tick sendAtomic(Packet *pkt)
1792381SN/A        { return peer->recvAtomic(pkt); }
1802381SN/A
1812381SN/A    /** Function called by the associated device to send a functional access,
1822381SN/A        an access in which the data is instantly updated everywhere in the
1832520SN/A        memory system, without affecting the current state of any block or
1842520SN/A        moving the block.
1852381SN/A    */
1862630SN/A    void sendFunctional(Packet *pkt)
1872381SN/A        { return peer->recvFunctional(pkt); }
1882381SN/A
1892381SN/A    /** Called by the associated device to send a status change to the device
1902381SN/A        connected to the peer interface.
1912381SN/A    */
1922381SN/A    void sendStatusChange(Status status) {peer->recvStatusChange(status); }
1932381SN/A
1942381SN/A    /** When a timing access doesn't return a success, some time later the
1952381SN/A        Retry will be sent.
1962381SN/A    */
1972381SN/A    Packet *sendRetry() { return peer->recvRetry(); }
1982381SN/A
1992381SN/A    /** Called by the associated device if it wishes to find out the blocksize
2002381SN/A        of the device on attached to the peer port.
2012381SN/A    */
2022406SN/A    int peerBlockSize() { return peer->deviceBlockSize(); }
2032381SN/A
2042381SN/A    /** Called by the associated device if it wishes to find out the address
2052381SN/A        ranges connected to the peer ports devices.
2062381SN/A    */
2072521SN/A    void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop)
2082521SN/A    { peer->getDeviceAddressRanges(resp, snoop); }
2092381SN/A
2102461SN/A    /** This function is a wrapper around sendFunctional()
2112461SN/A        that breaks a larger, arbitrarily aligned access into
2122461SN/A        appropriate chunks.  The default implementation can use
2132461SN/A        getBlockSize() to determine the block size and go from there.
2142461SN/A    */
2152519SN/A    virtual void readBlob(Addr addr, uint8_t *p, int size);
2162381SN/A
2172381SN/A    /** This function is a wrapper around sendFunctional()
2182381SN/A        that breaks a larger, arbitrarily aligned access into
2192381SN/A        appropriate chunks.  The default implementation can use
2202381SN/A        getBlockSize() to determine the block size and go from there.
2212381SN/A    */
2222519SN/A    virtual void writeBlob(Addr addr, uint8_t *p, int size);
2232381SN/A
2242381SN/A    /** Fill size bytes starting at addr with byte value val.  This
2252381SN/A        should not need to be virtual, since it can be implemented in
2262461SN/A        terms of writeBlob().  However, it shouldn't be
2272381SN/A        performance-critical either, so it could be if we wanted to.
2282381SN/A    */
2292519SN/A    virtual void memsetBlob(Addr addr, uint8_t val, int size);
2302405SN/A
2312405SN/A  private:
2322405SN/A
2332405SN/A    /** Internal helper function for read/writeBlob().
2342405SN/A     */
2352405SN/A    void blobHelper(Addr addr, uint8_t *p, int size, Command cmd);
2362381SN/A};
2372381SN/A
2382520SN/A/** A simple functional port that is only meant for one way communication to
2392520SN/A * physical memory. It is only meant to be used to load data into memory before
2402520SN/A * the simulation begins.
2412520SN/A */
2422520SN/A
2432520SN/Aclass FunctionalPort : public Port
2442520SN/A{
2452520SN/A  public:
2462640Sstever@eecs.umich.edu    FunctionalPort(const std::string &_name)
2472640Sstever@eecs.umich.edu        : Port(_name)
2482640Sstever@eecs.umich.edu    {}
2492640Sstever@eecs.umich.edu
2502630SN/A    virtual bool recvTiming(Packet *pkt) { panic("FuncPort is UniDir"); }
2512630SN/A    virtual Tick recvAtomic(Packet *pkt) { panic("FuncPort is UniDir"); }
2522630SN/A    virtual void recvFunctional(Packet *pkt) { panic("FuncPort is UniDir"); }
2532590SN/A    virtual void recvStatusChange(Status status) {}
2542521SN/A
2552521SN/A    template <typename T>
2562521SN/A    inline void write(Addr addr, T d)
2572521SN/A    {
2582521SN/A        writeBlob(addr, (uint8_t*)&d, sizeof(T));
2592521SN/A    }
2602521SN/A
2612521SN/A    template <typename T>
2622521SN/A    inline T read(Addr addr)
2632521SN/A    {
2642521SN/A        T d;
2652521SN/A        readBlob(addr, (uint8_t*)&d, sizeof(T));
2662521SN/A        return d;
2672521SN/A    }
2682520SN/A};
2692520SN/A
2702381SN/A#endif //__MEM_PORT_HH__
271