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 * Authors: Ron Dreslinski 29 */ 30 31/** 32 * @file 33 * Port Object Declaration. Ports are used to interface memory objects to 34 * each other. They will always come in pairs, and we refer to the other 35 * port object as the peer. These are used to make the design more 36 * modular so that a specific interface between every type of objcet doesn't 37 * have to be created. 38 */ 39 40#ifndef __MEM_PORT_HH__ 41#define __MEM_PORT_HH__ 42 43#include <list> 44#include <inttypes.h> 45 46#include "base/misc.hh" 47#include "base/range.hh" 48#include "mem/packet.hh" 49#include "mem/request.hh" 50 51/** This typedef is used to clean up the parameter list of 52 * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 53 * outside the Port object since it's also used by some mem objects. 54 * Eventually we should move this typedef to wherever Addr is 55 * defined. 56 */ 57 58typedef std::list<Range<Addr> > AddrRangeList; 59typedef std::list<Range<Addr> >::iterator AddrRangeIter; 60
| 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 * Authors: Ron Dreslinski 29 */ 30 31/** 32 * @file 33 * Port Object Declaration. Ports are used to interface memory objects to 34 * each other. They will always come in pairs, and we refer to the other 35 * port object as the peer. These are used to make the design more 36 * modular so that a specific interface between every type of objcet doesn't 37 * have to be created. 38 */ 39 40#ifndef __MEM_PORT_HH__ 41#define __MEM_PORT_HH__ 42 43#include <list> 44#include <inttypes.h> 45 46#include "base/misc.hh" 47#include "base/range.hh" 48#include "mem/packet.hh" 49#include "mem/request.hh" 50 51/** This typedef is used to clean up the parameter list of 52 * getDeviceAddressRanges() and getPeerAddressRanges(). It's declared 53 * outside the Port object since it's also used by some mem objects. 54 * Eventually we should move this typedef to wherever Addr is 55 * defined. 56 */ 57 58typedef std::list<Range<Addr> > AddrRangeList; 59typedef std::list<Range<Addr> >::iterator AddrRangeIter; 60
|
| 61class MemObject; 62
|
61/** 62 * Ports are used to interface memory objects to 63 * each other. They will always come in pairs, and we refer to the other 64 * port object as the peer. These are used to make the design more 65 * modular so that a specific interface between every type of objcet doesn't 66 * have to be created. 67 * 68 * Recv accesor functions are being called from the peer interface. 69 * Send accessor functions are being called from the device the port is 70 * associated with, and it will call the peer recv. accessor function. 71 */ 72class Port 73{ 74 private: 75 76 /** Descriptive name (for DPRINTF output) */ 77 mutable std::string portName; 78 79 /** A pointer to the peer port. Ports always come in pairs, that way they 80 can use a standardized interface to communicate between different 81 memory objects. */ 82 Port *peer; 83
| 63/** 64 * Ports are used to interface memory objects to 65 * each other. They will always come in pairs, and we refer to the other 66 * port object as the peer. These are used to make the design more 67 * modular so that a specific interface between every type of objcet doesn't 68 * have to be created. 69 * 70 * Recv accesor functions are being called from the peer interface. 71 * Send accessor functions are being called from the device the port is 72 * associated with, and it will call the peer recv. accessor function. 73 */ 74class Port 75{ 76 private: 77 78 /** Descriptive name (for DPRINTF output) */ 79 mutable std::string portName; 80 81 /** A pointer to the peer port. Ports always come in pairs, that way they 82 can use a standardized interface to communicate between different 83 memory objects. */ 84 Port *peer; 85
|
| 86 /** A pointer to the MemObject that owns this port. This may not be set. */ 87 MemObject *owner; 88
|
84 public: 85 86 Port()
| 89 public: 90 91 Port()
|
87 : peer(NULL)
| 92 : peer(NULL), owner(NULL)
|
88 { } 89 90 /** 91 * Constructor. 92 * 93 * @param _name Port name for DPRINTF output. Should include name 94 * of memory system object to which the port belongs.
| 93 { } 94 95 /** 96 * Constructor. 97 * 98 * @param _name Port name for DPRINTF output. Should include name 99 * of memory system object to which the port belongs.
|
| 100 * @param _owner Pointer to the MemObject that owns this port. 101 * Will not necessarily be set.
|
95 */
| 102 */
|
96 Port(const std::string &_name) 97 : portName(_name), peer(NULL)
| 103 Port(const std::string &_name, MemObject *_owner = NULL) 104 : portName(_name), peer(NULL), owner(_owner)
|
98 { } 99 100 /** Return port name (for DPRINTF). */ 101 const std::string &name() const { return portName; } 102 103 virtual ~Port() {}; 104 105 // mey be better to use subclasses & RTTI? 106 /** Holds the ports status. Currently just that a range recomputation needs 107 * to be done. */ 108 enum Status { 109 RangeChange 110 }; 111 112 void setName(const std::string &name) 113 { portName = name; } 114
| 105 { } 106 107 /** Return port name (for DPRINTF). */ 108 const std::string &name() const { return portName; } 109 110 virtual ~Port() {}; 111 112 // mey be better to use subclasses & RTTI? 113 /** Holds the ports status. Currently just that a range recomputation needs 114 * to be done. */ 115 enum Status { 116 RangeChange 117 }; 118 119 void setName(const std::string &name) 120 { portName = name; } 121
|
115 /** Function to set the pointer for the peer port. 116 @todo should be called by the configuration stuff (python). 117 */
| 122 /** Function to set the pointer for the peer port. */
|
118 void setPeer(Port *port); 119
| 123 void setPeer(Port *port); 124
|
120 /** Function to set the pointer for the peer port. 121 @todo should be called by the configuration stuff (python). 122 */
| 125 /** Function to get the pointer to the peer port. */
|
123 Port *getPeer() { return peer; } 124
| 126 Port *getPeer() { return peer; } 127
|
| 128 /** Function to set the owner of this port. */ 129 void setOwner(MemObject *_owner) { owner = _owner; } 130 131 /** Function to return the owner of this port. */ 132 MemObject *getOwner() { return owner; } 133
|
125 protected: 126 127 /** These functions are protected because they should only be 128 * called by a peer port, never directly by any outside object. */ 129 130 /** Called to recive a timing call from the peer port. */ 131 virtual bool recvTiming(PacketPtr pkt) = 0; 132 133 /** Called to recive a atomic call from the peer port. */ 134 virtual Tick recvAtomic(PacketPtr pkt) = 0; 135 136 /** Called to recive a functional call from the peer port. */ 137 virtual void recvFunctional(PacketPtr pkt) = 0; 138 139 /** Called to recieve a status change from the peer port. */ 140 virtual void recvStatusChange(Status status) = 0; 141 142 /** Called by a peer port if the send was unsuccesful, and had to 143 wait. This shouldn't be valid for response paths (IO Devices). 144 so it is set to panic if it isn't already defined. 145 */ 146 virtual void recvRetry() { panic("??"); } 147 148 /** Called by a peer port in order to determine the block size of the 149 device connected to this port. It sometimes doesn't make sense for 150 this function to be called, a DMA interface doesn't really have a 151 block size, so it is defaulted to a panic. 152 */ 153 virtual int deviceBlockSize() { panic("??"); } 154 155 /** The peer port is requesting us to reply with a list of the ranges we 156 are responsible for. 157 @param resp is a list of ranges responded to 158 @param snoop is a list of ranges snooped 159 */ 160 virtual void getDeviceAddressRanges(AddrRangeList &resp, 161 AddrRangeList &snoop) 162 { panic("??"); } 163 164 public: 165 166 /** Function called by associated memory device (cache, memory, iodevice) 167 in order to send a timing request to the port. Simply calls the peer 168 port receive function. 169 @return This function returns if the send was succesful in it's 170 recieve. If it was a failure, then the port will wait for a recvRetry 171 at which point it can possibly issue a successful sendTiming. This is used in 172 case a cache has a higher priority request come in while waiting for 173 the bus to arbitrate. 174 */ 175 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); } 176 177 /** Function called by the associated device to send an atomic 178 * access, an access in which the data is moved and the state is 179 * updated in one cycle, without interleaving with other memory 180 * accesses. Returns estimated latency of access. 181 */ 182 Tick sendAtomic(PacketPtr pkt) 183 { return peer->recvAtomic(pkt); } 184 185 /** Function called by the associated device to send a functional access, 186 an access in which the data is instantly updated everywhere in the 187 memory system, without affecting the current state of any block or 188 moving the block. 189 */ 190 void sendFunctional(PacketPtr pkt) 191 { return peer->recvFunctional(pkt); } 192 193 /** Called by the associated device to send a status change to the device 194 connected to the peer interface. 195 */ 196 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 197 198 /** When a timing access doesn't return a success, some time later the 199 Retry will be sent. 200 */ 201 void sendRetry() { return peer->recvRetry(); } 202 203 /** Called by the associated device if it wishes to find out the blocksize 204 of the device on attached to the peer port. 205 */ 206 int peerBlockSize() { return peer->deviceBlockSize(); } 207 208 /** Called by the associated device if it wishes to find out the address 209 ranges connected to the peer ports devices. 210 */ 211 void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 212 { peer->getDeviceAddressRanges(resp, snoop); } 213 214 /** This function is a wrapper around sendFunctional() 215 that breaks a larger, arbitrarily aligned access into 216 appropriate chunks. The default implementation can use 217 getBlockSize() to determine the block size and go from there. 218 */ 219 virtual void readBlob(Addr addr, uint8_t *p, int size); 220 221 /** This function is a wrapper around sendFunctional() 222 that breaks a larger, arbitrarily aligned access into 223 appropriate chunks. The default implementation can use 224 getBlockSize() to determine the block size and go from there. 225 */ 226 virtual void writeBlob(Addr addr, uint8_t *p, int size); 227 228 /** Fill size bytes starting at addr with byte value val. This 229 should not need to be virtual, since it can be implemented in 230 terms of writeBlob(). However, it shouldn't be 231 performance-critical either, so it could be if we wanted to. 232 */ 233 virtual void memsetBlob(Addr addr, uint8_t val, int size); 234 235 private: 236 237 /** Internal helper function for read/writeBlob(). 238 */ 239 void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd); 240}; 241 242/** A simple functional port that is only meant for one way communication to 243 * physical memory. It is only meant to be used to load data into memory before 244 * the simulation begins. 245 */ 246 247class FunctionalPort : public Port 248{ 249 public:
| 134 protected: 135 136 /** These functions are protected because they should only be 137 * called by a peer port, never directly by any outside object. */ 138 139 /** Called to recive a timing call from the peer port. */ 140 virtual bool recvTiming(PacketPtr pkt) = 0; 141 142 /** Called to recive a atomic call from the peer port. */ 143 virtual Tick recvAtomic(PacketPtr pkt) = 0; 144 145 /** Called to recive a functional call from the peer port. */ 146 virtual void recvFunctional(PacketPtr pkt) = 0; 147 148 /** Called to recieve a status change from the peer port. */ 149 virtual void recvStatusChange(Status status) = 0; 150 151 /** Called by a peer port if the send was unsuccesful, and had to 152 wait. This shouldn't be valid for response paths (IO Devices). 153 so it is set to panic if it isn't already defined. 154 */ 155 virtual void recvRetry() { panic("??"); } 156 157 /** Called by a peer port in order to determine the block size of the 158 device connected to this port. It sometimes doesn't make sense for 159 this function to be called, a DMA interface doesn't really have a 160 block size, so it is defaulted to a panic. 161 */ 162 virtual int deviceBlockSize() { panic("??"); } 163 164 /** The peer port is requesting us to reply with a list of the ranges we 165 are responsible for. 166 @param resp is a list of ranges responded to 167 @param snoop is a list of ranges snooped 168 */ 169 virtual void getDeviceAddressRanges(AddrRangeList &resp, 170 AddrRangeList &snoop) 171 { panic("??"); } 172 173 public: 174 175 /** Function called by associated memory device (cache, memory, iodevice) 176 in order to send a timing request to the port. Simply calls the peer 177 port receive function. 178 @return This function returns if the send was succesful in it's 179 recieve. If it was a failure, then the port will wait for a recvRetry 180 at which point it can possibly issue a successful sendTiming. This is used in 181 case a cache has a higher priority request come in while waiting for 182 the bus to arbitrate. 183 */ 184 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); } 185 186 /** Function called by the associated device to send an atomic 187 * access, an access in which the data is moved and the state is 188 * updated in one cycle, without interleaving with other memory 189 * accesses. Returns estimated latency of access. 190 */ 191 Tick sendAtomic(PacketPtr pkt) 192 { return peer->recvAtomic(pkt); } 193 194 /** Function called by the associated device to send a functional access, 195 an access in which the data is instantly updated everywhere in the 196 memory system, without affecting the current state of any block or 197 moving the block. 198 */ 199 void sendFunctional(PacketPtr pkt) 200 { return peer->recvFunctional(pkt); } 201 202 /** Called by the associated device to send a status change to the device 203 connected to the peer interface. 204 */ 205 void sendStatusChange(Status status) {peer->recvStatusChange(status); } 206 207 /** When a timing access doesn't return a success, some time later the 208 Retry will be sent. 209 */ 210 void sendRetry() { return peer->recvRetry(); } 211 212 /** Called by the associated device if it wishes to find out the blocksize 213 of the device on attached to the peer port. 214 */ 215 int peerBlockSize() { return peer->deviceBlockSize(); } 216 217 /** Called by the associated device if it wishes to find out the address 218 ranges connected to the peer ports devices. 219 */ 220 void getPeerAddressRanges(AddrRangeList &resp, AddrRangeList &snoop) 221 { peer->getDeviceAddressRanges(resp, snoop); } 222 223 /** This function is a wrapper around sendFunctional() 224 that breaks a larger, arbitrarily aligned access into 225 appropriate chunks. The default implementation can use 226 getBlockSize() to determine the block size and go from there. 227 */ 228 virtual void readBlob(Addr addr, uint8_t *p, int size); 229 230 /** This function is a wrapper around sendFunctional() 231 that breaks a larger, arbitrarily aligned access into 232 appropriate chunks. The default implementation can use 233 getBlockSize() to determine the block size and go from there. 234 */ 235 virtual void writeBlob(Addr addr, uint8_t *p, int size); 236 237 /** Fill size bytes starting at addr with byte value val. This 238 should not need to be virtual, since it can be implemented in 239 terms of writeBlob(). However, it shouldn't be 240 performance-critical either, so it could be if we wanted to. 241 */ 242 virtual void memsetBlob(Addr addr, uint8_t val, int size); 243 244 private: 245 246 /** Internal helper function for read/writeBlob(). 247 */ 248 void blobHelper(Addr addr, uint8_t *p, int size, Packet::Command cmd); 249}; 250 251/** A simple functional port that is only meant for one way communication to 252 * physical memory. It is only meant to be used to load data into memory before 253 * the simulation begins. 254 */ 255 256class FunctionalPort : public Port 257{ 258 public:
|
250 FunctionalPort(const std::string &_name) 251 : Port(_name)
| 259 FunctionalPort(const std::string &_name, MemObject *_owner = NULL) 260 : Port(_name, _owner)
|
252 {} 253 254 protected: 255 virtual bool recvTiming(PacketPtr pkt) { panic("FuncPort is UniDir"); } 256 virtual Tick recvAtomic(PacketPtr pkt) { panic("FuncPort is UniDir"); } 257 virtual void recvFunctional(PacketPtr pkt) { panic("FuncPort is UniDir"); } 258 virtual void recvStatusChange(Status status) {} 259 260 public: 261 /** a write function that also does an endian conversion. */ 262 template <typename T> 263 inline void writeHtoG(Addr addr, T d); 264 265 /** a read function that also does an endian conversion. */ 266 template <typename T> 267 inline T readGtoH(Addr addr); 268 269 template <typename T> 270 inline void write(Addr addr, T d) 271 { 272 writeBlob(addr, (uint8_t*)&d, sizeof(T)); 273 } 274 275 template <typename T> 276 inline T read(Addr addr) 277 { 278 T d; 279 readBlob(addr, (uint8_t*)&d, sizeof(T)); 280 return d; 281 } 282}; 283 284#endif //__MEM_PORT_HH__
| 261 {} 262 263 protected: 264 virtual bool recvTiming(PacketPtr pkt) { panic("FuncPort is UniDir"); } 265 virtual Tick recvAtomic(PacketPtr pkt) { panic("FuncPort is UniDir"); } 266 virtual void recvFunctional(PacketPtr pkt) { panic("FuncPort is UniDir"); } 267 virtual void recvStatusChange(Status status) {} 268 269 public: 270 /** a write function that also does an endian conversion. */ 271 template <typename T> 272 inline void writeHtoG(Addr addr, T d); 273 274 /** a read function that also does an endian conversion. */ 275 template <typename T> 276 inline T readGtoH(Addr addr); 277 278 template <typename T> 279 inline void write(Addr addr, T d) 280 { 281 writeBlob(addr, (uint8_t*)&d, sizeof(T)); 282 } 283 284 template <typename T> 285 inline T read(Addr addr) 286 { 287 T d; 288 readBlob(addr, (uint8_t*)&d, sizeof(T)); 289 return d; 290 } 291}; 292 293#endif //__MEM_PORT_HH__
|