port.hh revision 2407
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 29/** 30 * @file 31 * Port Object Decleration. Ports are used to interface memory objects to 32 * each other. They will always come in pairs, and we refer to the other 33 * port object as the peer. These are used to make the design more 34 * modular so that a specific interface between every type of objcet doesn't 35 * have to be created. 36 */ 37 38#ifndef __MEM_PORT_HH__ 39#define __MEM_PORT_HH__ 40 41#include <string> 42#include <list> 43#include <inttypes.h> 44 45#include "base/range.hh" 46#include "mem/packet.hh" 47#include "mem/request.hh" 48 49/** This typedef is used to clean up the parameter list of 50 * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 51 * outside the Port object since it's also used by some mem objects. 52 * Eventually we should move this typedef to wherever Addr is 53 * defined. 54 */ 55 56typedef std::list<Range<Addr> > AddrRangeList; 57 58/** 59 * Ports are used to interface memory objects to 60 * each other. They will always come in pairs, and we refer to the other 61 * port object as the peer. These are used to make the design more 62 * modular so that a specific interface between every type of objcet doesn't 63 * have to be created. 64 * 65 * Recv accesor functions are being called from the peer interface. 66 * Send accessor functions are being called from the device the port is 67 * associated with, and it will call the peer recv. accessor function. 68 */ 69class Port 70{ 71 public: 72 73 // mey be better to use subclasses & RTTI? 74 /** Holds the ports status. Keeps track if it is blocked, or has 75 calculated a range change. */ 76 enum Status { 77 Blocked, 78 Unblocked, 79 RangeChange 80 }; 81 82 private: 83 84 /** A pointer to the peer port. Ports always come in pairs, that way they 85 can use a standardized interface to communicate between different 86 memory objects. */ 87 Port *peer; 88 89 public: 90 91 /** Function to set the pointer for the peer port. 92 @todo should be called by the configuration stuff (python). 93 */ 94 void setPeer(Port *port) { peer = port; } 95 96 protected: 97 98 /** These functions are protected because they should only be 99 * called by a peer port, never directly by any outside object. */ 100 101 /** Called to recive a timing call from the peer port. */ 102 virtual bool recvTiming(Packet &pkt) = 0; 103 104 /** Called to recive a atomic call from the peer port. */ 105 virtual Tick recvAtomic(Packet &pkt) = 0; 106 107 /** Called to recive a functional call from the peer port. */ 108 virtual void recvFunctional(Packet &pkt) = 0; 109 110 /** Called to recieve a status change from the peer port. */ 111 virtual void recvStatusChange(Status status) = 0; 112 113 /** Called by a peer port if the send was unsuccesful, and had to 114 wait. This shouldn't be valid for response paths (IO Devices). 115 so it is set to panic if it isn't already defined. 116 */ 117 virtual Packet *recvRetry() { panic("??"); } 118 119 /** Called by a peer port in order to determine the block size of the 120 device connected to this port. It sometimes doesn't make sense for 121 this function to be called, a DMA interface doesn't really have a 122 block size, so it is defaulted to a panic. 123 */ 124 virtual int deviceBlockSize() { panic("??"); } 125 126 /** The peer port is requesting us to reply with a list of the ranges we 127 are responsible for. 128 @param owner is an output param that, if set, indicates that the 129 port is the owner of the specified ranges (i.e., slave, default 130 responder, etc.). If 'owner' is false, the interface is 131 interested in the specified ranges for snooping purposes. If 132 an object wants to own some ranges and snoop on others, it will 133 need to use two different ports. 134 */ 135 virtual void getDeviceAddressRanges(AddrRangeList &range_list, 136 bool &owner) 137 { panic("??"); } 138 139 public: 140 141 /** Function called by associated memory device (cache, memory, iodevice) 142 in order to send a timing request to the port. Simply calls the peer 143 port receive function. 144 @return This function returns if the send was succesful in it's 145 recieve. If it was a failure, then the port will wait for a recvRetry 146 at which point it can issue a successful sendTiming. This is used in 147 case a cache has a higher priority request come in while waiting for 148 the bus to arbitrate. 149 */ 150 bool sendTiming(Packet &pkt) { return peer->recvTiming(pkt); } 151 152 /** Function called by the associated device to send an atomic access, 153 an access in which the data is moved and the state is updated in one 154 cycle, without interleaving with other memory accesses. 155 */ 156 Tick sendAtomic(Packet &pkt) 157 { return peer->recvAtomic(pkt); } 158 159 /** Function called by the associated device to send a functional access, 160 an access in which the data is instantly updated everywhere in the 161 memory system, without affecting the current state of any block 162 or moving the block. 163 */ 164 void sendFunctional(Packet &pkt) 165 { return peer->recvFunctional(pkt); } 166 167 /** Called by the associated device to send a status change to the device 168 connected to the peer interface. 169 */ 170 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 171 172 /** When a timing access doesn't return a success, some time later the 173 Retry will be sent. 174 */ 175 Packet *sendRetry() { return peer->recvRetry(); } 176 177 /** Called by the associated device if it wishes to find out the blocksize 178 of the device on attached to the peer port. 179 */ 180 int peerBlockSize() { return peer->deviceBlockSize(); } 181 182 /** Called by the associated device if it wishes to find out the address 183 ranges connected to the peer ports devices. 184 */ 185 void getPeerAddressRanges(AddrRangeList &range_list, bool &owner) 186 { peer->getDeviceAddressRanges(range_list, owner); } 187 188 // Do we need similar wrappers for sendAtomic()? If not, should 189 // we drop the "Functional" from the names? 190 191 /** This function is a wrapper around sendFunctional() 192 that breaks a larger, arbitrarily aligned access into 193 appropriate chunks. The default implementation can use 194 getBlockSize() to determine the block size and go from there. 195 */ 196 void readBlobFunctional(Addr addr, uint8_t *p, int size); 197 198 /** This function is a wrapper around sendFunctional() 199 that breaks a larger, arbitrarily aligned access into 200 appropriate chunks. The default implementation can use 201 getBlockSize() to determine the block size and go from there. 202 */ 203 void writeBlobFunctional(Addr addr, uint8_t *p, int size); 204 205 /** Fill size bytes starting at addr with byte value val. This 206 should not need to be virtual, since it can be implemented in 207 terms of writeBlobFunctional(). However, it shouldn't be 208 performance-critical either, so it could be if we wanted to. 209 Not even sure if this is actually needed anywhere (there's a 210 prot_memset on the old functional memory that's never used), 211 but Nate claims it is. 212 */ 213 void memsetBlobFunctional(Addr addr, uint8_t val, int size); 214 215 private: 216 217 /** Internal helper function for read/writeBlob(). 218 */ 219 void blobHelper(Addr addr, uint8_t *p, int size, Command cmd); 220}; 221 222#endif //__MEM_PORT_HH__ 223