port.hh revision 2520
14202Sbinkertn@umich.edu/* 24202Sbinkertn@umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 34202Sbinkertn@umich.edu * All rights reserved. 44202Sbinkertn@umich.edu * 54202Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 64202Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are 74202Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright 84202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer; 94202Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright 104202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 114202Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution; 124202Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 134202Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 144202Sbinkertn@umich.edu * this software without specific prior written permission. 154202Sbinkertn@umich.edu * 164202Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174202Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184202Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194202Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204202Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214202Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224202Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244202Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254202Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264202Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274202Sbinkertn@umich.edu */ 284202Sbinkertn@umich.edu 294202Sbinkertn@umich.edu/** 304202Sbinkertn@umich.edu * @file 314202Sbinkertn@umich.edu * Port Object Decleration. Ports are used to interface memory objects to 324202Sbinkertn@umich.edu * each other. They will always come in pairs, and we refer to the other 335628Sgblack@eecs.umich.edu * port object as the peer. These are used to make the design more 344486Sbinkertn@umich.edu * modular so that a specific interface between every type of objcet doesn't 354776Sgblack@eecs.umich.edu * have to be created. 364486Sbinkertn@umich.edu */ 378774Sgblack@eecs.umich.edu 384202Sbinkertn@umich.edu#ifndef __MEM_PORT_HH__ 394202Sbinkertn@umich.edu#define __MEM_PORT_HH__ 404202Sbinkertn@umich.edu 414202Sbinkertn@umich.edu#include <string> 425522Snate@binkert.org#include <list> 438233Snate@binkert.org#include <inttypes.h> 444202Sbinkertn@umich.edu 454202Sbinkertn@umich.edu#include "base/misc.hh" 464202Sbinkertn@umich.edu#include "base/range.hh" 474202Sbinkertn@umich.edu#include "mem/packet.hh" 484202Sbinkertn@umich.edu#include "mem/request.hh" 494202Sbinkertn@umich.edu 508770Sgblack@eecs.umich.edu/** This typedef is used to clean up the parameter list of 517768SAli.Saidi@ARM.com * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 527768SAli.Saidi@ARM.com * outside the Port object since it's also used by some mem objects. 538766Sgblack@eecs.umich.edu * Eventually we should move this typedef to wherever Addr is 547768SAli.Saidi@ARM.com * defined. 557768SAli.Saidi@ARM.com */ 568766Sgblack@eecs.umich.edu 577768SAli.Saidi@ARM.comtypedef std::list<Range<Addr> > AddrRangeList; 587768SAli.Saidi@ARM.com 594202Sbinkertn@umich.edu/** 608784Sgblack@eecs.umich.edu * Ports are used to interface memory objects to 615016Sgblack@eecs.umich.edu * each other. They will always come in pairs, and we refer to the other 624486Sbinkertn@umich.edu * port object as the peer. These are used to make the design more 638335Snate@binkert.org * modular so that a specific interface between every type of objcet doesn't 648335Snate@binkert.org * have to be created. 659152Satgutier@umich.edu * 668335Snate@binkert.org * Recv accesor functions are being called from the peer interface. 678335Snate@binkert.org * Send accessor functions are being called from the device the port is 688335Snate@binkert.org * associated with, and it will call the peer recv. accessor function. 698335Snate@binkert.org */ 708335Snate@binkert.orgclass Port 718335Snate@binkert.org{ 728335Snate@binkert.org public: 738335Snate@binkert.org 748335Snate@binkert.org virtual ~Port() {}; 758335Snate@binkert.org // mey be better to use subclasses & RTTI? 768335Snate@binkert.org /** Holds the ports status. Keeps track if it is blocked, or has 778335Snate@binkert.org calculated a range change. */ 788335Snate@binkert.org enum Status { 798335Snate@binkert.org Blocked, 808335Snate@binkert.org Unblocked, 81 RangeChange 82 }; 83 84 private: 85 86 /** A pointer to the peer port. Ports always come in pairs, that way they 87 can use a standardized interface to communicate between different 88 memory objects. */ 89 Port *peer; 90 91 public: 92 93 /** Function to set the pointer for the peer port. 94 @todo should be called by the configuration stuff (python). 95 */ 96 void setPeer(Port *port) { peer = port; } 97 98 /** Function to set the pointer for the peer port. 99 @todo should be called by the configuration stuff (python). 100 */ 101 Port *getPeer() { return peer; } 102 103 protected: 104 105 /** These functions are protected because they should only be 106 * called by a peer port, never directly by any outside object. */ 107 108 /** Called to recive a timing call from the peer port. */ 109 virtual bool recvTiming(Packet &pkt) = 0; 110 111 /** Called to recive a atomic call from the peer port. */ 112 virtual Tick recvAtomic(Packet &pkt) = 0; 113 114 /** Called to recive a functional call from the peer port. */ 115 virtual void recvFunctional(Packet &pkt) = 0; 116 117 /** Called to recieve a status change from the peer port. */ 118 virtual void recvStatusChange(Status status) = 0; 119 120 /** Called by a peer port if the send was unsuccesful, and had to 121 wait. This shouldn't be valid for response paths (IO Devices). 122 so it is set to panic if it isn't already defined. 123 */ 124 virtual Packet *recvRetry() { panic("??"); } 125 126 /** Called by a peer port in order to determine the block size of the 127 device connected to this port. It sometimes doesn't make sense for 128 this function to be called, a DMA interface doesn't really have a 129 block size, so it is defaulted to a panic. 130 */ 131 virtual int deviceBlockSize() { panic("??"); } 132 133 /** The peer port is requesting us to reply with a list of the ranges we 134 are responsible for. 135 @param owner is an output param that, if set, indicates that the 136 port is the owner of the specified ranges (i.e., slave, default 137 responder, etc.). If 'owner' is false, the interface is 138 interested in the specified ranges for snooping purposes. If 139 an object wants to own some ranges and snoop on others, it will 140 need to use two different ports. 141 */ 142 virtual void getDeviceAddressRanges(AddrRangeList &range_list, 143 bool &owner) 144 { panic("??"); } 145 146 public: 147 148 /** Function called by associated memory device (cache, memory, iodevice) 149 in order to send a timing request to the port. Simply calls the peer 150 port receive function. 151 @return This function returns if the send was succesful in it's 152 recieve. If it was a failure, then the port will wait for a recvRetry 153 at which point it can issue a successful sendTiming. This is used in 154 case a cache has a higher priority request come in while waiting for 155 the bus to arbitrate. 156 */ 157 bool sendTiming(Packet &pkt) { return peer->recvTiming(pkt); } 158 159 /** Function called by the associated device to send an atomic access, 160 an access in which the data is moved and the state is updated in one 161 cycle, without interleaving with other memory accesses. 162 */ 163 Tick sendAtomic(Packet &pkt) 164 { return peer->recvAtomic(pkt); } 165 166 /** Function called by the associated device to send a functional access, 167 an access in which the data is instantly updated everywhere in the 168 memory system, without affecting the current state of any block or 169 moving the block. 170 */ 171 void sendFunctional(Packet &pkt) 172 { return peer->recvFunctional(pkt); } 173 174 /** Called by the associated device to send a status change to the device 175 connected to the peer interface. 176 */ 177 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 178 179 /** When a timing access doesn't return a success, some time later the 180 Retry will be sent. 181 */ 182 Packet *sendRetry() { return peer->recvRetry(); } 183 184 /** Called by the associated device if it wishes to find out the blocksize 185 of the device on attached to the peer port. 186 */ 187 int peerBlockSize() { return peer->deviceBlockSize(); } 188 189 /** Called by the associated device if it wishes to find out the address 190 ranges connected to the peer ports devices. 191 */ 192 void getPeerAddressRanges(AddrRangeList &range_list, bool &owner) 193 { peer->getDeviceAddressRanges(range_list, owner); } 194 195 /** This function is a wrapper around sendFunctional() 196 that breaks a larger, arbitrarily aligned access into 197 appropriate chunks. The default implementation can use 198 getBlockSize() to determine the block size and go from there. 199 */ 200 virtual void readBlob(Addr addr, uint8_t *p, int size); 201 202 /** This function is a wrapper around sendFunctional() 203 that breaks a larger, arbitrarily aligned access into 204 appropriate chunks. The default implementation can use 205 getBlockSize() to determine the block size and go from there. 206 */ 207 virtual void writeBlob(Addr addr, uint8_t *p, int size); 208 209 /** Fill size bytes starting at addr with byte value val. This 210 should not need to be virtual, since it can be implemented in 211 terms of writeBlob(). However, it shouldn't be 212 performance-critical either, so it could be if we wanted to. 213 */ 214 virtual void memsetBlob(Addr addr, uint8_t val, int size); 215 216 private: 217 218 /** Internal helper function for read/writeBlob(). 219 */ 220 void blobHelper(Addr addr, uint8_t *p, int size, Command cmd); 221}; 222 223/** A simple functional port that is only meant for one way communication to 224 * physical memory. It is only meant to be used to load data into memory before 225 * the simulation begins. 226 */ 227 228class FunctionalPort : public Port 229{ 230 public: 231 virtual bool recvTiming(Packet &pkt) { panic("FuncPort is UniDir"); } 232 virtual Tick recvAtomic(Packet &pkt) { panic("FuncPort is UniDir"); } 233 virtual void recvFunctional(Packet &pkt) { panic("FuncPort is UniDir"); } 234 virtual void recvStatusChange(Status status) {panic("FuncPort is UniDir");} 235}; 236 237 238#endif //__MEM_PORT_HH__ 239