port.hh revision 2661
12914Ssaidi@eecs.umich.edu/* 22914Ssaidi@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 32914Ssaidi@eecs.umich.edu * All rights reserved. 42914Ssaidi@eecs.umich.edu * 52914Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 62914Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 72914Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 82914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 92914Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 102914Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 112914Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 122914Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 132914Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 142914Ssaidi@eecs.umich.edu * this software without specific prior written permission. 152914Ssaidi@eecs.umich.edu * 162914Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172914Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182914Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192914Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202914Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212914Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222914Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232914Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242914Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252914Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262914Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272914Ssaidi@eecs.umich.edu */ 282914Ssaidi@eecs.umich.edu 292914Ssaidi@eecs.umich.edu/** 302914Ssaidi@eecs.umich.edu * @file 312914Ssaidi@eecs.umich.edu * Port Object Decleration. Ports are used to interface memory objects to 322914Ssaidi@eecs.umich.edu * each other. They will always come in pairs, and we refer to the other 332914Ssaidi@eecs.umich.edu * port object as the peer. These are used to make the design more 342914Ssaidi@eecs.umich.edu * modular so that a specific interface between every type of objcet doesn't 352914Ssaidi@eecs.umich.edu * have to be created. 362914Ssaidi@eecs.umich.edu */ 372914Ssaidi@eecs.umich.edu 382914Ssaidi@eecs.umich.edu#ifndef __MEM_PORT_HH__ 392914Ssaidi@eecs.umich.edu#define __MEM_PORT_HH__ 402914Ssaidi@eecs.umich.edu 412914Ssaidi@eecs.umich.edu#include <list> 422914Ssaidi@eecs.umich.edu#include <inttypes.h> 432914Ssaidi@eecs.umich.edu 442914Ssaidi@eecs.umich.edu#include "base/misc.hh" 452914Ssaidi@eecs.umich.edu#include "base/range.hh" 462914Ssaidi@eecs.umich.edu#include "mem/packet.hh" 472914Ssaidi@eecs.umich.edu#include "mem/request.hh" 482914Ssaidi@eecs.umich.edu 492914Ssaidi@eecs.umich.edu/** This typedef is used to clean up the parameter list of 502914Ssaidi@eecs.umich.edu * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 512914Ssaidi@eecs.umich.edu * outside the Port object since it's also used by some mem objects. 522914Ssaidi@eecs.umich.edu * Eventually we should move this typedef to wherever Addr is 532914Ssaidi@eecs.umich.edu * defined. 542914Ssaidi@eecs.umich.edu */ 552914Ssaidi@eecs.umich.edu 562914Ssaidi@eecs.umich.edutypedef std::list<Range<Addr> > AddrRangeList; 572914Ssaidi@eecs.umich.edutypedef std::list<Range<Addr> >::iterator AddrRangeIter; 582914Ssaidi@eecs.umich.edu 592914Ssaidi@eecs.umich.edu/** 602914Ssaidi@eecs.umich.edu * Ports are used to interface memory objects to 612914Ssaidi@eecs.umich.edu * each other. They will always come in pairs, and we refer to the other 622914Ssaidi@eecs.umich.edu * port object as the peer. These are used to make the design more 632914Ssaidi@eecs.umich.edu * modular so that a specific interface between every type of objcet doesn't 642914Ssaidi@eecs.umich.edu * have to be created. 652914Ssaidi@eecs.umich.edu * 662914Ssaidi@eecs.umich.edu * Recv accesor functions are being called from the peer interface. 672914Ssaidi@eecs.umich.edu * Send accessor functions are being called from the device the port is 682914Ssaidi@eecs.umich.edu * associated with, and it will call the peer recv. accessor function. 692914Ssaidi@eecs.umich.edu */ 702914Ssaidi@eecs.umich.educlass Port 712914Ssaidi@eecs.umich.edu{ 722914Ssaidi@eecs.umich.edu private: 732914Ssaidi@eecs.umich.edu 742914Ssaidi@eecs.umich.edu /** Descriptive name (for DPRINTF output) */ 752914Ssaidi@eecs.umich.edu const std::string portName; 762914Ssaidi@eecs.umich.edu 772914Ssaidi@eecs.umich.edu /** A pointer to the peer port. Ports always come in pairs, that way they 782914Ssaidi@eecs.umich.edu can use a standardized interface to communicate between different 792914Ssaidi@eecs.umich.edu memory objects. */ 802914Ssaidi@eecs.umich.edu Port *peer; 812914Ssaidi@eecs.umich.edu 822914Ssaidi@eecs.umich.edu public: 83 84 /** 85 * Constructor. 86 * 87 * @param _name Port name for DPRINTF output. Should include name 88 * of memory system object to which the port belongs. 89 */ 90 Port(const std::string &_name) 91 : portName(_name), peer(NULL) 92 { } 93 94 /** Return port name (for DPRINTF). */ 95 const std::string &name() const { return portName; } 96 97 virtual ~Port() {}; 98 99 // mey be better to use subclasses & RTTI? 100 /** Holds the ports status. Currently just that a range recomputation needs 101 * to be done. */ 102 enum Status { 103 RangeChange 104 }; 105 106 /** Function to set the pointer for the peer port. 107 @todo should be called by the configuration stuff (python). 108 */ 109 void setPeer(Port *port); 110 111 /** Function to set the pointer for the peer port. 112 @todo should be called by the configuration stuff (python). 113 */ 114 Port *getPeer() { return peer; } 115 116 protected: 117 118 /** These functions are protected because they should only be 119 * called by a peer port, never directly by any outside object. */ 120 121 /** Called to recive a timing call from the peer port. */ 122 virtual bool recvTiming(Packet *pkt) = 0; 123 124 /** Called to recive a atomic call from the peer port. */ 125 virtual Tick recvAtomic(Packet *pkt) = 0; 126 127 /** Called to recive a functional call from the peer port. */ 128 virtual void recvFunctional(Packet *pkt) = 0; 129 130 /** Called to recieve a status change from the peer port. */ 131 virtual void recvStatusChange(Status status) = 0; 132 133 /** Called by a peer port if the send was unsuccesful, and had to 134 wait. This shouldn't be valid for response paths (IO Devices). 135 so it is set to panic if it isn't already defined. 136 */ 137 virtual void recvRetry() { panic("??"); } 138 139 /** Called by a peer port in order to determine the block size of the 140 device connected to this port. It sometimes doesn't make sense for 141 this function to be called, a DMA interface doesn't really have a 142 block size, so it is defaulted to a panic. 143 */ 144 virtual int deviceBlockSize() { panic("??"); } 145 146 /** The peer port is requesting us to reply with a list of the ranges we 147 are responsible for. 148 @param resp is a list of ranges responded to 149 @param snoop is a list of ranges snooped 150 */ 151 virtual void getDeviceAddressRanges(AddrRangeList &resp, 152 AddrRangeList &snoop) 153 { panic("??"); } 154 155 public: 156 157 /** Function called by associated memory device (cache, memory, iodevice) 158 in order to send a timing request to the port. Simply calls the peer 159 port receive function. 160 @return This function returns if the send was succesful in it's 161 recieve. If it was a failure, then the port will wait for a recvRetry 162 at which point it can possibly issue a successful sendTiming. This is used in 163 case a cache has a higher priority request come in while waiting for 164 the bus to arbitrate. 165 */ 166 bool sendTiming(Packet *pkt) { return peer->recvTiming(pkt); } 167 168 /** Function called by the associated device to send an atomic access, 169 an access in which the data is moved and the state is updated in one 170 cycle, without interleaving with other memory accesses. 171 */ 172 Tick sendAtomic(Packet *pkt) 173 { return peer->recvAtomic(pkt); } 174 175 /** Function called by the associated device to send a functional access, 176 an access in which the data is instantly updated everywhere in the 177 memory system, without affecting the current state of any block or 178 moving the block. 179 */ 180 void sendFunctional(Packet *pkt) 181 { return peer->recvFunctional(pkt); } 182 183 /** Called by the associated device to send a status change to the device 184 connected to the peer interface. 185 */ 186 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 187 188 /** When a timing access doesn't return a success, some time later the 189 Retry will be sent. 190 */ 191 void sendRetry() { return peer->recvRetry(); } 192 193 /** Called by the associated device if it wishes to find out the blocksize 194 of the device on attached to the peer port. 195 */ 196 int peerBlockSize() { return peer->deviceBlockSize(); } 197 198 /** Called by the associated device if it wishes to find out the address 199 ranges connected to the peer ports devices. 200 */ 201 void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 202 { peer->getDeviceAddressRanges(resp, snoop); } 203 204 /** This function is a wrapper around sendFunctional() 205 that breaks a larger, arbitrarily aligned access into 206 appropriate chunks. The default implementation can use 207 getBlockSize() to determine the block size and go from there. 208 */ 209 virtual void readBlob(Addr addr, uint8_t *p, int size); 210 211 /** This function is a wrapper around sendFunctional() 212 that breaks a larger, arbitrarily aligned access into 213 appropriate chunks. The default implementation can use 214 getBlockSize() to determine the block size and go from there. 215 */ 216 virtual void writeBlob(Addr addr, uint8_t *p, int size); 217 218 /** Fill size bytes starting at addr with byte value val. This 219 should not need to be virtual, since it can be implemented in 220 terms of writeBlob(). However, it shouldn't be 221 performance-critical either, so it could be if we wanted to. 222 */ 223 virtual void memsetBlob(Addr addr, uint8_t val, int size); 224 225 private: 226 227 /** Internal helper function for read/writeBlob(). 228 */ 229 void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd); 230}; 231 232/** A simple functional port that is only meant for one way communication to 233 * physical memory. It is only meant to be used to load data into memory before 234 * the simulation begins. 235 */ 236 237class FunctionalPort : public Port 238{ 239 public: 240 FunctionalPort(const std::string &_name) 241 : Port(_name) 242 {} 243 244 virtual bool recvTiming(Packet *pkt) { panic("FuncPort is UniDir"); } 245 virtual Tick recvAtomic(Packet *pkt) { panic("FuncPort is UniDir"); } 246 virtual void recvFunctional(Packet *pkt) { panic("FuncPort is UniDir"); } 247 virtual void recvStatusChange(Status status) {} 248 249 template <typename T> 250 inline void write(Addr addr, T d) 251 { 252 writeBlob(addr, (uint8_t*)&d, sizeof(T)); 253 } 254 255 template <typename T> 256 inline T read(Addr addr) 257 { 258 T d; 259 readBlob(addr, (uint8_t*)&d, sizeof(T)); 260 return d; 261 } 262}; 263 264#endif //__MEM_PORT_HH__ 265