port.hh revision 2405
112291Sgabeblack@google.com/* 212291Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 312291Sgabeblack@google.com * All rights reserved. 412291Sgabeblack@google.com * 512291Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612291Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712291Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812291Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912291Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012291Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112291Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212291Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312291Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412291Sgabeblack@google.com * this software without specific prior written permission. 1512291Sgabeblack@google.com * 1612291Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712291Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812291Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912291Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012291Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112291Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212291Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312291Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412291Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512291Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612291Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712291Sgabeblack@google.com */ 2812291Sgabeblack@google.com 2912291Sgabeblack@google.com/** 3012291Sgabeblack@google.com * @file 3112291Sgabeblack@google.com * Port Object Decleration. Ports are used to interface memory objects to 3212291Sgabeblack@google.com * each other. They will always come in pairs, and we refer to the other 3312291Sgabeblack@google.com * port object as the peer. These are used to make the design more 3412291Sgabeblack@google.com * modular so that a specific interface between every type of objcet doesn't 3512291Sgabeblack@google.com * have to be created. 3612291Sgabeblack@google.com */ 3712291Sgabeblack@google.com 3812291Sgabeblack@google.com#ifndef __MEM_PORT_HH__ 3912291Sgabeblack@google.com#define __MEM_PORT_HH__ 4012291Sgabeblack@google.com 4112291Sgabeblack@google.com#include <string> 4212291Sgabeblack@google.com#include <list> 4312291Sgabeblack@google.com#include <inttypes.h> 4412291Sgabeblack@google.com 4512291Sgabeblack@google.com#include "base/range.hh" 4612291Sgabeblack@google.com#include "mem/packet.hh" 4712291Sgabeblack@google.com#include "mem/request.hh" 4812291Sgabeblack@google.com 4912291Sgabeblack@google.com/** 5012291Sgabeblack@google.com * Ports are used to interface memory objects to 5112291Sgabeblack@google.com * each other. They will always come in pairs, and we refer to the other 5212291Sgabeblack@google.com * port object as the peer. These are used to make the design more 5312291Sgabeblack@google.com * modular so that a specific interface between every type of objcet doesn't 5412291Sgabeblack@google.com * have to be created. 5512291Sgabeblack@google.com * 5612291Sgabeblack@google.com * Recv accesor functions are being called from the peer interface. 5712291Sgabeblack@google.com * Send accessor functions are being called from the device the port is 5812291Sgabeblack@google.com * associated with, and it will call the peer recv. accessor function. 5912291Sgabeblack@google.com */ 6012291Sgabeblack@google.comclass Port 6112291Sgabeblack@google.com{ 6212291Sgabeblack@google.com public: 6312291Sgabeblack@google.com 6412291Sgabeblack@google.com // mey be better to use subclasses & RTTI? 6512291Sgabeblack@google.com /** Holds the ports status. Keeps track if it is blocked, or has 6612291Sgabeblack@google.com calculated a range change. */ 6712291Sgabeblack@google.com enum Status { 6812291Sgabeblack@google.com Blocked, 6912291Sgabeblack@google.com Unblocked, 7012291Sgabeblack@google.com RangeChange 7112291Sgabeblack@google.com }; 7212291Sgabeblack@google.com 7312291Sgabeblack@google.com private: 7412291Sgabeblack@google.com 7512291Sgabeblack@google.com /** A pointer to the peer port. Ports always come in pairs, that way they 7612291Sgabeblack@google.com can use a standardized interface to communicate between different 7712291Sgabeblack@google.com memory objects. */ 7812291Sgabeblack@google.com Port *peer; 7912291Sgabeblack@google.com 8012291Sgabeblack@google.com public: 8112291Sgabeblack@google.com 8212291Sgabeblack@google.com /** Function to set the pointer for the peer port. 8312291Sgabeblack@google.com @todo should be called by the configuration stuff (python). 8412291Sgabeblack@google.com */ 8512291Sgabeblack@google.com void setPeer(Port *port) { peer = port; } 8612291Sgabeblack@google.com 8712291Sgabeblack@google.com protected: 8812291Sgabeblack@google.com 8912291Sgabeblack@google.com /** Called to recive a timing call from the peer port. */ 9012291Sgabeblack@google.com virtual bool recvTiming(Packet &pkt) = 0; 9112291Sgabeblack@google.com 9212291Sgabeblack@google.com /** Called to recive a atomic call from the peer port. */ 9312291Sgabeblack@google.com virtual Tick recvAtomic(Packet &pkt) = 0; 9412291Sgabeblack@google.com 9512291Sgabeblack@google.com /** Called to recive a functional call from the peer port. */ 9612291Sgabeblack@google.com virtual void recvFunctional(Packet &pkt) = 0; 9712291Sgabeblack@google.com 9812291Sgabeblack@google.com /** Called to recieve a status change from the peer port. */ 9912291Sgabeblack@google.com virtual void recvStatusChange(Status status) = 0; 10012291Sgabeblack@google.com 10112291Sgabeblack@google.com /** Called by a peer port if the send was unsuccesful, and had to 10212291Sgabeblack@google.com wait. This shouldn't be valid for response paths (IO Devices). 10312291Sgabeblack@google.com so it is set to panic if it isn't already defined. 10412291Sgabeblack@google.com */ 10512291Sgabeblack@google.com virtual Packet *recvRetry() { panic("??"); } 10612291Sgabeblack@google.com 10712291Sgabeblack@google.com /** Called by a peer port in order to determine the block size of the 10812291Sgabeblack@google.com device connected to this port. It sometimes doesn't make sense for 10912291Sgabeblack@google.com this function to be called, a DMA interface doesn't really have a 11012291Sgabeblack@google.com block size, so it is defaulted to a panic. 11112291Sgabeblack@google.com */ 11212291Sgabeblack@google.com virtual int recvBlockSizeQuery() { panic("??"); } 11312291Sgabeblack@google.com 11412291Sgabeblack@google.com /** The peer port is requesting us to reply with a list of the ranges we 11512291Sgabeblack@google.com are responsible for. 11612291Sgabeblack@google.com @param owner is an output param that, if set, indicates that the 11712291Sgabeblack@google.com port is the owner of the specified ranges (i.e., slave, default 11812291Sgabeblack@google.com responder, etc.). If 'owner' is false, the interface is 11912291Sgabeblack@google.com interested in the specified ranges for snooping purposes. If 12012291Sgabeblack@google.com an object wants to own some ranges and snoop on others, it will 12112291Sgabeblack@google.com need to use two different ports. 12212291Sgabeblack@google.com */ 123 virtual void recvAddressRangesQuery(std::list<Range<Addr> > &range_list, 124 bool &owner) { panic("??"); } 125 126 public: 127 128 /** Function called by associated memory device (cache, memory, iodevice) 129 in order to send a timing request to the port. Simply calls the peer 130 port receive function. 131 @return This function returns if the send was succesful in it's 132 recieve. If it was a failure, then the port will wait for a recvRetry 133 at which point it can issue a successful sendTiming. This is used in 134 case a cache has a higher priority request come in while waiting for 135 the bus to arbitrate. 136 */ 137 bool sendTiming(Packet &pkt) { return peer->recvTiming(pkt); } 138 139 /** Function called by the associated device to send an atomic access, 140 an access in which the data is moved and the state is updated in one 141 cycle, without interleaving with other memory accesses. 142 */ 143 Tick sendAtomic(Packet &pkt) 144 { return peer->recvAtomic(pkt); } 145 146 /** Function called by the associated device to send a functional access, 147 an access in which the data is instantly updated everywhere in the 148 memory system, without affecting the current state of any block 149 or moving the block. 150 */ 151 void sendFunctional(Packet &pkt) 152 { return peer->recvFunctional(pkt); } 153 154 /** Called by the associated device to send a status change to the device 155 connected to the peer interface. 156 */ 157 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 158 159 /** When a timing access doesn't return a success, some time later the 160 Retry will be sent. 161 */ 162 Packet *sendRetry() { return peer->recvRetry(); } 163 164 /** Called by the associated device if it wishes to find out the blocksize 165 of the device on attached to the peer port. 166 */ 167 int sendBlockSizeQuery() { return peer->recvBlockSizeQuery(); } 168 169 /** Called by the associated device if it wishes to find out the address 170 ranges connected to the peer ports devices. 171 */ 172 void sendAddressRangesQuery(std::list<Range<Addr> > &range_list, 173 bool &owner) 174 { peer->recvAddressRangesQuery(range_list, owner); } 175 176 // Do we need similar wrappers for sendAtomic()? If not, should 177 // we drop the "Functional" from the names? 178 179 /** This function is a wrapper around sendFunctional() 180 that breaks a larger, arbitrarily aligned access into 181 appropriate chunks. The default implementation can use 182 getBlockSize() to determine the block size and go from there. 183 */ 184 void readBlobFunctional(Addr addr, uint8_t *p, int size); 185 186 /** This function is a wrapper around sendFunctional() 187 that breaks a larger, arbitrarily aligned access into 188 appropriate chunks. The default implementation can use 189 getBlockSize() to determine the block size and go from there. 190 */ 191 void writeBlobFunctional(Addr addr, uint8_t *p, int size); 192 193 /** Fill size bytes starting at addr with byte value val. This 194 should not need to be virtual, since it can be implemented in 195 terms of writeBlobFunctional(). However, it shouldn't be 196 performance-critical either, so it could be if we wanted to. 197 Not even sure if this is actually needed anywhere (there's a 198 prot_memset on the old functional memory that's never used), 199 but Nate claims it is. 200 */ 201 void memsetBlobFunctional(Addr addr, uint8_t val, int size); 202 203 private: 204 205 /** Internal helper function for read/writeBlob(). 206 */ 207 void blobHelper(Addr addr, uint8_t *p, int size, Command cmd); 208}; 209 210#endif //__MEM_PORT_HH__ 211