port.hh revision 13771
1/* 2 * Copyright (c) 2011-2012,2015,2017 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 2002-2005 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution; 24 * neither the name of the copyright holders nor the names of its 25 * contributors may be used to endorse or promote products derived from 26 * this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 * 40 * Authors: Ron Dreslinski 41 * Andreas Hansson 42 * William Wang 43 */ 44 45/** 46 * @file 47 * Port Object Declaration. 48 */ 49 50#ifndef __MEM_PORT_HH__ 51#define __MEM_PORT_HH__ 52 53#include "base/addr_range.hh" 54#include "mem/packet.hh" 55#include "sim/port.hh" 56 57class MemObject; 58 59/** Forward declaration */ 60class BaseSlavePort; 61 62/** 63 * A BaseMasterPort is a protocol-agnostic master port, responsible 64 * only for the structural connection to a slave port. The final 65 * master port that inherits from the base class must override the 66 * bind member function for the specific slave port class. 67 */ 68class BaseMasterPort : public Port 69{ 70 71 protected: 72 73 BaseSlavePort* _baseSlavePort; 74 75 BaseMasterPort(const std::string& name, PortID id=InvalidPortID); 76 virtual ~BaseMasterPort(); 77 78 public: 79 80 virtual void bind(BaseSlavePort& slave_port) = 0; 81 virtual void unbind() = 0; 82 BaseSlavePort& getSlavePort() const; 83 bool isConnected() const; 84 85}; 86 87/** 88 * A BaseSlavePort is a protocol-agnostic slave port, responsible 89 * only for the structural connection to a master port. 90 */ 91class BaseSlavePort : public Port 92{ 93 94 protected: 95 96 BaseMasterPort* _baseMasterPort; 97 98 BaseSlavePort(const std::string& name, PortID id=InvalidPortID); 99 virtual ~BaseSlavePort(); 100 101 public: 102 103 BaseMasterPort& getMasterPort() const; 104 bool isConnected() const; 105 106}; 107 108/** Forward declaration */ 109class SlavePort; 110 111/** 112 * A MasterPort is a specialisation of a BaseMasterPort, which 113 * implements the default protocol for the three different level of 114 * transport functions. In addition to the basic functionality of 115 * sending packets, it also has functions to receive range changes or 116 * determine if the port is snooping or not. 117 */ 118class MasterPort : public BaseMasterPort 119{ 120 121 friend class SlavePort; 122 123 private: 124 125 SlavePort* _slavePort; 126 127 protected: 128 129 MemObject& owner; 130 131 public: 132 133 MasterPort(const std::string& name, MemObject* _owner, 134 PortID id=InvalidPortID); 135 virtual ~MasterPort(); 136 137 /** 138 * Bind this master port to a slave port. This also does the 139 * mirror action and binds the slave port to the master port. 140 */ 141 void bind(BaseSlavePort& slave_port); 142 143 /** 144 * Unbind this master port and the associated slave port. 145 */ 146 void unbind(); 147 148 /** 149 * Send an atomic request packet, where the data is moved and the 150 * state is updated in zero time, without interleaving with other 151 * memory accesses. 152 * 153 * @param pkt Packet to send. 154 * 155 * @return Estimated latency of access. 156 */ 157 Tick sendAtomic(PacketPtr pkt); 158 159 /** 160 * Send a functional request packet, where the data is instantly 161 * updated everywhere in the memory system, without affecting the 162 * current state of any block or moving the block. 163 * 164 * @param pkt Packet to send. 165 */ 166 void sendFunctional(PacketPtr pkt); 167 168 /** 169 * Attempt to send a timing request to the slave port by calling 170 * its corresponding receive function. If the send does not 171 * succeed, as indicated by the return value, then the sender must 172 * wait for a recvReqRetry at which point it can re-issue a 173 * sendTimingReq. 174 * 175 * @param pkt Packet to send. 176 * 177 * @return If the send was succesful or not. 178 */ 179 bool sendTimingReq(PacketPtr pkt); 180 181 /** 182 * Check if the slave can handle a timing request. 183 * 184 * If the send cannot be handled at the moment, as indicated by 185 * the return value, then the sender will receive a recvReqRetry 186 * at which point it can re-issue a sendTimingReq. 187 * 188 * @param pkt Packet to send. 189 * 190 * @return If the send was succesful or not. 191 */ 192 bool tryTiming(PacketPtr pkt) const; 193 194 /** 195 * Attempt to send a timing snoop response packet to the slave 196 * port by calling its corresponding receive function. If the send 197 * does not succeed, as indicated by the return value, then the 198 * sender must wait for a recvRetrySnoop at which point it can 199 * re-issue a sendTimingSnoopResp. 200 * 201 * @param pkt Packet to send. 202 */ 203 bool sendTimingSnoopResp(PacketPtr pkt); 204 205 /** 206 * Send a retry to the slave port that previously attempted a 207 * sendTimingResp to this master port and failed. Note that this 208 * is virtual so that the "fake" snoop response port in the 209 * coherent crossbar can override the behaviour. 210 */ 211 virtual void sendRetryResp(); 212 213 /** 214 * Determine if this master port is snooping or not. The default 215 * implementation returns false and thus tells the neighbour we 216 * are not snooping. Any master port that wants to receive snoop 217 * requests (e.g. a cache connected to a bus) has to override this 218 * function. 219 * 220 * @return true if the port should be considered a snooper 221 */ 222 virtual bool isSnooping() const { return false; } 223 224 /** 225 * Get the address ranges of the connected slave port. 226 */ 227 AddrRangeList getAddrRanges() const; 228 229 /** Inject a PrintReq for the given address to print the state of 230 * that address throughout the memory system. For debugging. 231 */ 232 void printAddr(Addr a); 233 234 protected: 235 236 /** 237 * Receive an atomic snoop request packet from the slave port. 238 */ 239 virtual Tick recvAtomicSnoop(PacketPtr pkt) 240 { 241 panic("%s was not expecting an atomic snoop request\n", name()); 242 return 0; 243 } 244 245 /** 246 * Receive a functional snoop request packet from the slave port. 247 */ 248 virtual void recvFunctionalSnoop(PacketPtr pkt) 249 { 250 panic("%s was not expecting a functional snoop request\n", name()); 251 } 252 253 /** 254 * Receive a timing response from the slave port. 255 */ 256 virtual bool recvTimingResp(PacketPtr pkt) = 0; 257 258 /** 259 * Receive a timing snoop request from the slave port. 260 */ 261 virtual void recvTimingSnoopReq(PacketPtr pkt) 262 { 263 panic("%s was not expecting a timing snoop request\n", name()); 264 } 265 266 /** 267 * Called by the slave port if sendTimingReq was called on this 268 * master port (causing recvTimingReq to be called on the slave 269 * port) and was unsuccesful. 270 */ 271 virtual void recvReqRetry() = 0; 272 273 /** 274 * Called by the slave port if sendTimingSnoopResp was called on this 275 * master port (causing recvTimingSnoopResp to be called on the slave 276 * port) and was unsuccesful. 277 */ 278 virtual void recvRetrySnoopResp() 279 { 280 panic("%s was not expecting a snoop retry\n", name()); 281 } 282 283 /** 284 * Called to receive an address range change from the peer slave 285 * port. The default implementation ignores the change and does 286 * nothing. Override this function in a derived class if the owner 287 * needs to be aware of the address ranges, e.g. in an 288 * interconnect component like a bus. 289 */ 290 virtual void recvRangeChange() { } 291}; 292 293/** 294 * A SlavePort is a specialisation of a port. In addition to the 295 * basic functionality of sending packets to its master peer, it also 296 * has functions specific to a slave, e.g. to send range changes 297 * and get the address ranges that the port responds to. 298 */ 299class SlavePort : public BaseSlavePort 300{ 301 302 friend class MasterPort; 303 304 private: 305 306 MasterPort* _masterPort; 307 308 protected: 309 310 MemObject& owner; 311 312 public: 313 314 SlavePort(const std::string& name, MemObject* _owner, 315 PortID id=InvalidPortID); 316 virtual ~SlavePort(); 317 318 /** 319 * Send an atomic snoop request packet, where the data is moved 320 * and the state is updated in zero time, without interleaving 321 * with other memory accesses. 322 * 323 * @param pkt Snoop packet to send. 324 * 325 * @return Estimated latency of access. 326 */ 327 Tick sendAtomicSnoop(PacketPtr pkt); 328 329 /** 330 * Send a functional snoop request packet, where the data is 331 * instantly updated everywhere in the memory system, without 332 * affecting the current state of any block or moving the block. 333 * 334 * @param pkt Snoop packet to send. 335 */ 336 void sendFunctionalSnoop(PacketPtr pkt); 337 338 /** 339 * Attempt to send a timing response to the master port by calling 340 * its corresponding receive function. If the send does not 341 * succeed, as indicated by the return value, then the sender must 342 * wait for a recvRespRetry at which point it can re-issue a 343 * sendTimingResp. 344 * 345 * @param pkt Packet to send. 346 * 347 * @return If the send was succesful or not. 348 */ 349 bool sendTimingResp(PacketPtr pkt); 350 351 /** 352 * Attempt to send a timing snoop request packet to the master port 353 * by calling its corresponding receive function. Snoop requests 354 * always succeed and hence no return value is needed. 355 * 356 * @param pkt Packet to send. 357 */ 358 void sendTimingSnoopReq(PacketPtr pkt); 359 360 /** 361 * Send a retry to the master port that previously attempted a 362 * sendTimingReq to this slave port and failed. 363 */ 364 void sendRetryReq(); 365 366 /** 367 * Send a retry to the master port that previously attempted a 368 * sendTimingSnoopResp to this slave port and failed. 369 */ 370 void sendRetrySnoopResp(); 371 372 /** 373 * Find out if the peer master port is snooping or not. 374 * 375 * @return true if the peer master port is snooping 376 */ 377 bool isSnooping() const { return _masterPort->isSnooping(); } 378 379 /** 380 * Called by the owner to send a range change 381 */ 382 void sendRangeChange() const { 383 if (!_masterPort) 384 fatal("%s cannot sendRangeChange() without master port", name()); 385 _masterPort->recvRangeChange(); 386 } 387 388 /** 389 * Get a list of the non-overlapping address ranges the owner is 390 * responsible for. All slave ports must override this function 391 * and return a populated list with at least one item. 392 * 393 * @return a list of ranges responded to 394 */ 395 virtual AddrRangeList getAddrRanges() const = 0; 396 397 protected: 398 399 /** 400 * Called by the master port to unbind. Should never be called 401 * directly. 402 */ 403 void unbind(); 404 405 /** 406 * Called by the master port to bind. Should never be called 407 * directly. 408 */ 409 void bind(MasterPort& master_port); 410 411 /** 412 * Receive an atomic request packet from the master port. 413 */ 414 virtual Tick recvAtomic(PacketPtr pkt) = 0; 415 416 /** 417 * Receive a functional request packet from the master port. 418 */ 419 virtual void recvFunctional(PacketPtr pkt) = 0; 420 421 /** 422 * Receive a timing request from the master port. 423 */ 424 virtual bool recvTimingReq(PacketPtr pkt) = 0; 425 426 /** 427 * Availability request from the master port. 428 */ 429 virtual bool tryTiming(PacketPtr pkt) { 430 panic("%s was not expecting a %s\n", name(), __func__); 431 } 432 433 /** 434 * Receive a timing snoop response from the master port. 435 */ 436 virtual bool recvTimingSnoopResp(PacketPtr pkt) 437 { 438 panic("%s was not expecting a timing snoop response\n", name()); 439 } 440 441 /** 442 * Called by the master port if sendTimingResp was called on this 443 * slave port (causing recvTimingResp to be called on the master 444 * port) and was unsuccesful. 445 */ 446 virtual void recvRespRetry() = 0; 447 448}; 449 450#endif //__MEM_PORT_HH__ 451