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