port.hh revision 3091:dba513d68c16
1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Ron Dreslinski 29 */ 30 31/** 32 * @file 33 * Port Object Declaration. Ports are used to interface memory objects to 34 * each other. They will always come in pairs, and we refer to the other 35 * port object as the peer. These are used to make the design more 36 * modular so that a specific interface between every type of objcet doesn't 37 * have to be created. 38 */ 39 40#ifndef __MEM_PORT_HH__ 41#define __MEM_PORT_HH__ 42 43#include <list> 44#include <inttypes.h> 45 46#include "base/misc.hh" 47#include "base/range.hh" 48#include "mem/packet.hh" 49#include "mem/request.hh" 50 51/** This typedef is used to clean up the parameter list of 52 * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 53 * outside the Port object since it's also used by some mem objects. 54 * Eventually we should move this typedef to wherever Addr is 55 * defined. 56 */ 57 58typedef std::list<Range<Addr> > AddrRangeList; 59typedef std::list<Range<Addr> >::iterator AddrRangeIter; 60 61/** 62 * Ports are used to interface memory objects to 63 * each other. They will always come in pairs, and we refer to the other 64 * port object as the peer. These are used to make the design more 65 * modular so that a specific interface between every type of objcet doesn't 66 * have to be created. 67 * 68 * Recv accesor functions are being called from the peer interface. 69 * Send accessor functions are being called from the device the port is 70 * associated with, and it will call the peer recv. accessor function. 71 */ 72class Port 73{ 74 private: 75 76 /** Descriptive name (for DPRINTF output) */ 77 mutable std::string portName; 78 79 /** A pointer to the peer port. Ports always come in pairs, that way they 80 can use a standardized interface to communicate between different 81 memory objects. */ 82 Port *peer; 83 84 public: 85 86 Port() 87 : peer(NULL) 88 { } 89 90 /** 91 * Constructor. 92 * 93 * @param _name Port name for DPRINTF output. Should include name 94 * of memory system object to which the port belongs. 95 */ 96 Port(const std::string &_name) 97 : portName(_name), peer(NULL) 98 { } 99 100 /** Return port name (for DPRINTF). */ 101 const std::string &name() const { return portName; } 102 103 virtual ~Port() {}; 104 105 // mey be better to use subclasses & RTTI? 106 /** Holds the ports status. Currently just that a range recomputation needs 107 * to be done. */ 108 enum Status { 109 RangeChange, 110 SnoopSquash 111 }; 112 113 void setName(const std::string &name) 114 { portName = name; } 115 116 /** Function to set the pointer for the peer port. 117 @todo should be called by the configuration stuff (python). 118 */ 119 void setPeer(Port *port); 120 121 /** Function to set the pointer for the peer port. 122 @todo should be called by the configuration stuff (python). 123 */ 124 Port *getPeer() { return peer; } 125 126 protected: 127 128 /** These functions are protected because they should only be 129 * called by a peer port, never directly by any outside object. */ 130 131 /** Called to recive a timing call from the peer port. */ 132 virtual bool recvTiming(Packet *pkt) = 0; 133 134 /** Called to recive a atomic call from the peer port. */ 135 virtual Tick recvAtomic(Packet *pkt) = 0; 136 137 /** Called to recive a functional call from the peer port. */ 138 virtual void recvFunctional(Packet *pkt) = 0; 139 140 /** Called to recieve a status change from the peer port. */ 141 virtual void recvStatusChange(Status status) = 0; 142 143 /** Called by a peer port if the send was unsuccesful, and had to 144 wait. This shouldn't be valid for response paths (IO Devices). 145 so it is set to panic if it isn't already defined. 146 */ 147 virtual void recvRetry() { panic("??"); } 148 149 /** Called by a peer port in order to determine the block size of the 150 device connected to this port. It sometimes doesn't make sense for 151 this function to be called, a DMA interface doesn't really have a 152 block size, so it is defaulted to a panic. 153 */ 154 virtual int deviceBlockSize() { panic("??"); } 155 156 /** The peer port is requesting us to reply with a list of the ranges we 157 are responsible for. 158 @param resp is a list of ranges responded to 159 @param snoop is a list of ranges snooped 160 */ 161 virtual void getDeviceAddressRanges(AddrRangeList &resp, 162 AddrRangeList &snoop) 163 { panic("??"); } 164 165 public: 166 167 /** Function called by associated memory device (cache, memory, iodevice) 168 in order to send a timing request to the port. Simply calls the peer 169 port receive function. 170 @return This function returns if the send was succesful in it's 171 recieve. If it was a failure, then the port will wait for a recvRetry 172 at which point it can possibly issue a successful sendTiming. This is used in 173 case a cache has a higher priority request come in while waiting for 174 the bus to arbitrate. 175 */ 176 bool sendTiming(Packet *pkt) { return peer->recvTiming(pkt); } 177 178 /** Function called by the associated device to send an atomic 179 * access, an access in which the data is moved and the state is 180 * updated in one cycle, without interleaving with other memory 181 * accesses. Returns estimated latency of access. 182 */ 183 Tick sendAtomic(Packet *pkt) 184 { return peer->recvAtomic(pkt); } 185 186 /** Function called by the associated device to send a functional access, 187 an access in which the data is instantly updated everywhere in the 188 memory system, without affecting the current state of any block or 189 moving the block. 190 */ 191 void sendFunctional(Packet *pkt) 192 { return peer->recvFunctional(pkt); } 193 194 /** Called by the associated device to send a status change to the device 195 connected to the peer interface. 196 */ 197 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 198 199 /** When a timing access doesn't return a success, some time later the 200 Retry will be sent. 201 */ 202 void sendRetry() { return peer->recvRetry(); } 203 204 /** Called by the associated device if it wishes to find out the blocksize 205 of the device on attached to the peer port. 206 */ 207 int peerBlockSize() { return peer->deviceBlockSize(); } 208 209 /** Called by the associated device if it wishes to find out the address 210 ranges connected to the peer ports devices. 211 */ 212 void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 213 { peer->getDeviceAddressRanges(resp, snoop); } 214 215 /** This function is a wrapper around sendFunctional() 216 that breaks a larger, arbitrarily aligned access into 217 appropriate chunks. The default implementation can use 218 getBlockSize() to determine the block size and go from there. 219 */ 220 virtual void readBlob(Addr addr, uint8_t *p, int size); 221 222 /** This function is a wrapper around sendFunctional() 223 that breaks a larger, arbitrarily aligned access into 224 appropriate chunks. The default implementation can use 225 getBlockSize() to determine the block size and go from there. 226 */ 227 virtual void writeBlob(Addr addr, uint8_t *p, int size); 228 229 /** Fill size bytes starting at addr with byte value val. This 230 should not need to be virtual, since it can be implemented in 231 terms of writeBlob(). However, it shouldn't be 232 performance-critical either, so it could be if we wanted to. 233 */ 234 virtual void memsetBlob(Addr addr, uint8_t val, int size); 235 236 private: 237 238 /** Internal helper function for read/writeBlob(). 239 */ 240 void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd); 241}; 242 243/** A simple functional port that is only meant for one way communication to 244 * physical memory. It is only meant to be used to load data into memory before 245 * the simulation begins. 246 */ 247 248class FunctionalPort : public Port 249{ 250 public: 251 FunctionalPort(const std::string &_name) 252 : Port(_name) 253 {} 254 255 protected: 256 virtual bool recvTiming(Packet *pkt) { panic("FuncPort is UniDir"); } 257 virtual Tick recvAtomic(Packet *pkt) { panic("FuncPort is UniDir"); } 258 virtual void recvFunctional(Packet *pkt) { panic("FuncPort is UniDir"); } 259 virtual void recvStatusChange(Status status) {} 260 261 public: 262 /** a write function that also does an endian conversion. */ 263 template <typename T> 264 inline void writeHtoG(Addr addr, T d); 265 266 /** a read function that also does an endian conversion. */ 267 template <typename T> 268 inline T readGtoH(Addr addr); 269 270 template <typename T> 271 inline void write(Addr addr, T d) 272 { 273 writeBlob(addr, (uint8_t*)&d, sizeof(T)); 274 } 275 276 template <typename T> 277 inline T read(Addr addr) 278 { 279 T d; 280 readBlob(addr, (uint8_t*)&d, sizeof(T)); 281 return d; 282 } 283}; 284 285#endif //__MEM_PORT_HH__ 286