port.hh revision 2474
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/misc.hh" 46#include "base/range.hh" 47#include "mem/packet.hh" 48#include "mem/request.hh" 49 50/** This typedef is used to clean up the parameter list of 51 * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 52 * outside the Port object since it's also used by some mem objects. 53 * Eventually we should move this typedef to wherever Addr is 54 * defined. 55 */ 56 57typedef std::list<Range<Addr> > AddrRangeList; 58 59/** 60 * Ports are used to interface memory objects to 61 * each other. They will always come in pairs, and we refer to the other 62 * port object as the peer. These are used to make the design more 63 * modular so that a specific interface between every type of objcet doesn't 64 * have to be created. 65 * 66 * Recv accesor functions are being called from the peer interface. 67 * Send accessor functions are being called from the device the port is 68 * associated with, and it will call the peer recv. accessor function. 69 */ 70class Port 71{ 72 public: 73 74 virtual ~Port() {}; 75 // mey be better to use subclasses & RTTI? 76 /** Holds the ports status. Keeps track if it is blocked, or has 77 calculated a range change. */ 78 enum Status { 79 Blocked, 80 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 169 or 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 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 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 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#endif //__MEM_PORT_HH__ 224