port.hh revision 2684
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. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Ron Dreslinski 292381SN/A */ 302381SN/A 312381SN/A/** 322381SN/A * @file 332381SN/A * Port Object Decleration. Ports are used to interface memory objects to 342381SN/A * each other. They will always come in pairs, and we refer to the other 352381SN/A * port object as the peer. These are used to make the design more 362381SN/A * modular so that a specific interface between every type of objcet doesn't 372381SN/A * have to be created. 382381SN/A */ 392381SN/A 402381SN/A#ifndef __MEM_PORT_HH__ 412381SN/A#define __MEM_PORT_HH__ 422381SN/A 432381SN/A#include <list> 442381SN/A#include <inttypes.h> 452381SN/A 462439SN/A#include "base/misc.hh" 472381SN/A#include "base/range.hh" 482381SN/A#include "mem/packet.hh" 492381SN/A#include "mem/request.hh" 502381SN/A 512407SN/A/** This typedef is used to clean up the parameter list of 522407SN/A * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 532407SN/A * outside the Port object since it's also used by some mem objects. 542407SN/A * Eventually we should move this typedef to wherever Addr is 552407SN/A * defined. 562407SN/A */ 572407SN/A 582407SN/Atypedef std::list<Range<Addr> > AddrRangeList; 592521SN/Atypedef std::list<Range<Addr> >::iterator AddrRangeIter; 602407SN/A 612381SN/A/** 622381SN/A * Ports are used to interface memory objects to 632381SN/A * each other. They will always come in pairs, and we refer to the other 642381SN/A * port object as the peer. These are used to make the design more 652381SN/A * modular so that a specific interface between every type of objcet doesn't 662381SN/A * have to be created. 672381SN/A * 682381SN/A * Recv accesor functions are being called from the peer interface. 692381SN/A * Send accessor functions are being called from the device the port is 702381SN/A * associated with, and it will call the peer recv. accessor function. 712381SN/A */ 722381SN/Aclass Port 732381SN/A{ 742640Sstever@eecs.umich.edu private: 752640Sstever@eecs.umich.edu 762640Sstever@eecs.umich.edu /** Descriptive name (for DPRINTF output) */ 772640Sstever@eecs.umich.edu const std::string portName; 782640Sstever@eecs.umich.edu 792661Sstever@eecs.umich.edu /** A pointer to the peer port. Ports always come in pairs, that way they 802661Sstever@eecs.umich.edu can use a standardized interface to communicate between different 812661Sstever@eecs.umich.edu memory objects. */ 822661Sstever@eecs.umich.edu Port *peer; 832661Sstever@eecs.umich.edu 842381SN/A public: 852381SN/A 862640Sstever@eecs.umich.edu /** 872640Sstever@eecs.umich.edu * Constructor. 882640Sstever@eecs.umich.edu * 892640Sstever@eecs.umich.edu * @param _name Port name for DPRINTF output. Should include name 902640Sstever@eecs.umich.edu * of memory system object to which the port belongs. 912640Sstever@eecs.umich.edu */ 922640Sstever@eecs.umich.edu Port(const std::string &_name) 932661Sstever@eecs.umich.edu : portName(_name), peer(NULL) 942640Sstever@eecs.umich.edu { } 952640Sstever@eecs.umich.edu 962640Sstever@eecs.umich.edu /** Return port name (for DPRINTF). */ 972640Sstever@eecs.umich.edu const std::string &name() const { return portName; } 982640Sstever@eecs.umich.edu 992474SN/A virtual ~Port() {}; 1002640Sstever@eecs.umich.edu 1012381SN/A // mey be better to use subclasses & RTTI? 1022657Ssaidi@eecs.umich.edu /** Holds the ports status. Currently just that a range recomputation needs 1032657Ssaidi@eecs.umich.edu * to be done. */ 1042381SN/A enum Status { 1052381SN/A RangeChange 1062381SN/A }; 1072381SN/A 1082381SN/A /** Function to set the pointer for the peer port. 1092381SN/A @todo should be called by the configuration stuff (python). 1102381SN/A */ 1112642Sstever@eecs.umich.edu void setPeer(Port *port); 1122381SN/A 1132642Sstever@eecs.umich.edu /** Function to set the pointer for the peer port. 1142408SN/A @todo should be called by the configuration stuff (python). 1152408SN/A */ 1162409SN/A Port *getPeer() { return peer; } 1172408SN/A 1182381SN/A protected: 1192381SN/A 1202406SN/A /** These functions are protected because they should only be 1212406SN/A * called by a peer port, never directly by any outside object. */ 1222406SN/A 1232381SN/A /** Called to recive a timing call from the peer port. */ 1242630SN/A virtual bool recvTiming(Packet *pkt) = 0; 1252381SN/A 1262381SN/A /** Called to recive a atomic call from the peer port. */ 1272630SN/A virtual Tick recvAtomic(Packet *pkt) = 0; 1282381SN/A 1292381SN/A /** Called to recive a functional call from the peer port. */ 1302630SN/A virtual void recvFunctional(Packet *pkt) = 0; 1312381SN/A 1322381SN/A /** Called to recieve a status change from the peer port. */ 1332381SN/A virtual void recvStatusChange(Status status) = 0; 1342381SN/A 1352381SN/A /** Called by a peer port if the send was unsuccesful, and had to 1362381SN/A wait. This shouldn't be valid for response paths (IO Devices). 1372381SN/A so it is set to panic if it isn't already defined. 1382381SN/A */ 1392657Ssaidi@eecs.umich.edu virtual void recvRetry() { panic("??"); } 1402381SN/A 1412381SN/A /** Called by a peer port in order to determine the block size of the 1422381SN/A device connected to this port. It sometimes doesn't make sense for 1432381SN/A this function to be called, a DMA interface doesn't really have a 1442381SN/A block size, so it is defaulted to a panic. 1452381SN/A */ 1462406SN/A virtual int deviceBlockSize() { panic("??"); } 1472381SN/A 1482381SN/A /** The peer port is requesting us to reply with a list of the ranges we 1492381SN/A are responsible for. 1502521SN/A @param resp is a list of ranges responded to 1512521SN/A @param snoop is a list of ranges snooped 1522381SN/A */ 1532521SN/A virtual void getDeviceAddressRanges(AddrRangeList &resp, 1542521SN/A AddrRangeList &snoop) 1552407SN/A { panic("??"); } 1562381SN/A 1572381SN/A public: 1582381SN/A 1592381SN/A /** Function called by associated memory device (cache, memory, iodevice) 1602381SN/A in order to send a timing request to the port. Simply calls the peer 1612381SN/A port receive function. 1622381SN/A @return This function returns if the send was succesful in it's 1632381SN/A recieve. If it was a failure, then the port will wait for a recvRetry 1642657Ssaidi@eecs.umich.edu at which point it can possibly issue a successful sendTiming. This is used in 1652381SN/A case a cache has a higher priority request come in while waiting for 1662381SN/A the bus to arbitrate. 1672381SN/A */ 1682630SN/A bool sendTiming(Packet *pkt) { return peer->recvTiming(pkt); } 1692381SN/A 1702662Sstever@eecs.umich.edu /** Function called by the associated device to send an atomic 1712662Sstever@eecs.umich.edu * access, an access in which the data is moved and the state is 1722662Sstever@eecs.umich.edu * updated in one cycle, without interleaving with other memory 1732662Sstever@eecs.umich.edu * accesses. Returns estimated latency of access. 1742662Sstever@eecs.umich.edu */ 1752630SN/A Tick sendAtomic(Packet *pkt) 1762381SN/A { return peer->recvAtomic(pkt); } 1772381SN/A 1782381SN/A /** Function called by the associated device to send a functional access, 1792381SN/A an access in which the data is instantly updated everywhere in the 1802520SN/A memory system, without affecting the current state of any block or 1812520SN/A moving the block. 1822381SN/A */ 1832630SN/A void sendFunctional(Packet *pkt) 1842381SN/A { return peer->recvFunctional(pkt); } 1852381SN/A 1862381SN/A /** Called by the associated device to send a status change to the device 1872381SN/A connected to the peer interface. 1882381SN/A */ 1892381SN/A void sendStatusChange(Status status) {peer->recvStatusChange(status); } 1902381SN/A 1912381SN/A /** When a timing access doesn't return a success, some time later the 1922381SN/A Retry will be sent. 1932381SN/A */ 1942657Ssaidi@eecs.umich.edu void sendRetry() { return peer->recvRetry(); } 1952381SN/A 1962381SN/A /** Called by the associated device if it wishes to find out the blocksize 1972381SN/A of the device on attached to the peer port. 1982381SN/A */ 1992406SN/A int peerBlockSize() { return peer->deviceBlockSize(); } 2002381SN/A 2012381SN/A /** Called by the associated device if it wishes to find out the address 2022381SN/A ranges connected to the peer ports devices. 2032381SN/A */ 2042521SN/A void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 2052521SN/A { peer->getDeviceAddressRanges(resp, snoop); } 2062381SN/A 2072461SN/A /** This function is a wrapper around sendFunctional() 2082461SN/A that breaks a larger, arbitrarily aligned access into 2092461SN/A appropriate chunks. The default implementation can use 2102461SN/A getBlockSize() to determine the block size and go from there. 2112461SN/A */ 2122519SN/A virtual void readBlob(Addr addr, uint8_t *p, int size); 2132381SN/A 2142381SN/A /** This function is a wrapper around sendFunctional() 2152381SN/A that breaks a larger, arbitrarily aligned access into 2162381SN/A appropriate chunks. The default implementation can use 2172381SN/A getBlockSize() to determine the block size and go from there. 2182381SN/A */ 2192519SN/A virtual void writeBlob(Addr addr, uint8_t *p, int size); 2202381SN/A 2212381SN/A /** Fill size bytes starting at addr with byte value val. This 2222381SN/A should not need to be virtual, since it can be implemented in 2232461SN/A terms of writeBlob(). However, it shouldn't be 2242381SN/A performance-critical either, so it could be if we wanted to. 2252381SN/A */ 2262519SN/A virtual void memsetBlob(Addr addr, uint8_t val, int size); 2272405SN/A 2282405SN/A private: 2292405SN/A 2302405SN/A /** Internal helper function for read/writeBlob(). 2312405SN/A */ 2322641Sstever@eecs.umich.edu void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd); 2332381SN/A}; 2342381SN/A 2352520SN/A/** A simple functional port that is only meant for one way communication to 2362520SN/A * physical memory. It is only meant to be used to load data into memory before 2372520SN/A * the simulation begins. 2382520SN/A */ 2392520SN/A 2402520SN/Aclass FunctionalPort : public Port 2412520SN/A{ 2422520SN/A public: 2432640Sstever@eecs.umich.edu FunctionalPort(const std::string &_name) 2442640Sstever@eecs.umich.edu : Port(_name) 2452640Sstever@eecs.umich.edu {} 2462640Sstever@eecs.umich.edu 2472630SN/A virtual bool recvTiming(Packet *pkt) { panic("FuncPort is UniDir"); } 2482630SN/A virtual Tick recvAtomic(Packet *pkt) { panic("FuncPort is UniDir"); } 2492630SN/A virtual void recvFunctional(Packet *pkt) { panic("FuncPort is UniDir"); } 2502590SN/A virtual void recvStatusChange(Status status) {} 2512521SN/A 2522684Ssaidi@eecs.umich.edu /** a write function that also does an endian conversion. */ 2532684Ssaidi@eecs.umich.edu template <typename T> 2542684Ssaidi@eecs.umich.edu inline void writeHtoG(Addr addr, T d); 2552684Ssaidi@eecs.umich.edu 2562684Ssaidi@eecs.umich.edu /** a read function that also does an endian conversion. */ 2572684Ssaidi@eecs.umich.edu template <typename T> 2582684Ssaidi@eecs.umich.edu inline T readGtoH(Addr addr); 2592684Ssaidi@eecs.umich.edu 2602521SN/A template <typename T> 2612521SN/A inline void write(Addr addr, T d) 2622521SN/A { 2632521SN/A writeBlob(addr, (uint8_t*)&d, sizeof(T)); 2642521SN/A } 2652521SN/A 2662521SN/A template <typename T> 2672521SN/A inline T read(Addr addr) 2682521SN/A { 2692521SN/A T d; 2702521SN/A readBlob(addr, (uint8_t*)&d, sizeof(T)); 2712521SN/A return d; 2722521SN/A } 2732520SN/A}; 2742520SN/A 2752381SN/A#endif //__MEM_PORT_HH__ 276