port.hh (5489:94a7bb476fca) port.hh (5494:85c8d296c1cb)
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
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 protected:
77 /** Descriptive name (for DPRINTF output) */
78 mutable std::string portName;
79
80 /** A pointer to the peer port. Ports always come in pairs, that way they
81 can use a standardized interface to communicate between different
82 memory objects. */
83 Port *peer;
84
85 /** A pointer to the MemObject that owns this port. This may not be set. */
86 MemObject *owner;
87
88 public:
89
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
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 protected:
77 /** Descriptive name (for DPRINTF output) */
78 mutable std::string portName;
79
80 /** A pointer to the peer port. Ports always come in pairs, that way they
81 can use a standardized interface to communicate between different
82 memory objects. */
83 Port *peer;
84
85 /** A pointer to the MemObject that owns this port. This may not be set. */
86 MemObject *owner;
87
88 public:
89
90 Port();
91
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.
95 * @param _owner Pointer to the MemObject that owns this port.
92 /**
93 * Constructor.
94 *
95 * @param _name Port name for DPRINTF output. Should include name
96 * of memory system object to which the port belongs.
97 * @param _owner Pointer to the MemObject that owns this port.
98 * Will not necessarily be set.
96 */
99 */
97 Port(const std::string &_name, MemObject *_owner, Port *_peer = NULL);
100 Port(const std::string &_name, MemObject *_owner = NULL);
98
99 /** Return port name (for DPRINTF). */
100 const std::string &name() const { return portName; }
101
102 virtual ~Port();
103
104 // mey be better to use subclasses & RTTI?
105 /** Holds the ports status. Currently just that a range recomputation needs
106 * to be done. */
107 enum Status {
108 RangeChange
109 };
110
101
102 /** Return port name (for DPRINTF). */
103 const std::string &name() const { return portName; }
104
105 virtual ~Port();
106
107 // mey be better to use subclasses & RTTI?
108 /** Holds the ports status. Currently just that a range recomputation needs
109 * to be done. */
110 enum Status {
111 RangeChange
112 };
113
114 void setName(const std::string &name)
115 { portName = name; }
116
111 /** Function to set the pointer for the peer port. */
112 virtual void setPeer(Port *port);
113
114 /** Function to get the pointer to the peer port. */
115 Port *getPeer() { return peer; }
116
117 /** Function to set the pointer for the peer port. */
118 virtual void setPeer(Port *port);
119
120 /** Function to get the pointer to the peer port. */
121 Port *getPeer() { return peer; }
122
123 /** Function to set the owner of this port. */
124 void setOwner(MemObject *_owner) { owner = _owner; }
125
117 /** Function to return the owner of this port. */
118 MemObject *getOwner() { return owner; }
119
126 /** Function to return the owner of this port. */
127 MemObject *getOwner() { return owner; }
128
120 /** Notify my peer port that I'm disconnecting (by calling its
121 * disconnect() method) so it can clean up. */
122 void disconnectFromPeer();
129 /** Inform the peer port to delete itself and notify it's owner about it's
130 * demise. */
131 void removeConn();
123
124 virtual bool isDefaultPort() const { return false; }
125
126 bool isConnected() { return peer && !peer->isDefaultPort(); }
127
128 protected:
129
130 /** These functions are protected because they should only be
131 * called by a peer port, never directly by any outside object. */
132
133 /** Called to recive a timing call from the peer port. */
134 virtual bool recvTiming(PacketPtr pkt) = 0;
135
136 /** Called to recive a atomic call from the peer port. */
137 virtual Tick recvAtomic(PacketPtr pkt) = 0;
138
139 /** Called to recive a functional call from the peer port. */
140 virtual void recvFunctional(PacketPtr pkt) = 0;
141
142 /** Called to recieve a status change from the peer port. */
143 virtual void recvStatusChange(Status status) = 0;
144
145 /** Called by a peer port if the send was unsuccesful, and had to
146 wait. This shouldn't be valid for response paths (IO Devices).
147 so it is set to panic if it isn't already defined.
148 */
149 virtual void recvRetry() { panic("??"); }
150
151 /** Called by a peer port in order to determine the block size of the
152 device connected to this port. It sometimes doesn't make sense for
153 this function to be called, so it just returns 0. Anytthing that is
154 concerned with the size should just ignore that.
155 */
156 virtual int deviceBlockSize() { return 0; }
157
158 /** The peer port is requesting us to reply with a list of the ranges we
159 are responsible for.
160 @param resp is a list of ranges responded to
161 @param snoop is a list of ranges snooped
162 */
163 virtual void getDeviceAddressRanges(AddrRangeList &resp,
164 bool &snoop)
165 { panic("??"); }
166
167 public:
168
169 /** Function called by associated memory device (cache, memory, iodevice)
170 in order to send a timing request to the port. Simply calls the peer
171 port receive function.
172 @return This function returns if the send was succesful in it's
173 recieve. If it was a failure, then the port will wait for a recvRetry
174 at which point it can possibly issue a successful sendTiming. This is used in
175 case a cache has a higher priority request come in while waiting for
176 the bus to arbitrate.
177 */
178 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
179
180 /** Function called by the associated device to send an atomic
181 * access, an access in which the data is moved and the state is
182 * updated in one cycle, without interleaving with other memory
183 * accesses. Returns estimated latency of access.
184 */
185 Tick sendAtomic(PacketPtr pkt)
186 { return peer->recvAtomic(pkt); }
187
188 /** Function called by the associated device to send a functional access,
189 an access in which the data is instantly updated everywhere in the
190 memory system, without affecting the current state of any block or
191 moving the block.
192 */
193 void sendFunctional(PacketPtr pkt)
194 { return peer->recvFunctional(pkt); }
195
196 /** Called by the associated device to send a status change to the device
197 connected to the peer interface.
198 */
199 void sendStatusChange(Status status) {peer->recvStatusChange(status); }
200
201 /** When a timing access doesn't return a success, some time later the
202 Retry will be sent.
203 */
204 void sendRetry() { return peer->recvRetry(); }
205
206 /** Called by the associated device if it wishes to find out the blocksize
207 of the device on attached to the peer port.
208 */
209 int peerBlockSize() { return peer->deviceBlockSize(); }
210
211 /** Called by the associated device if it wishes to find out the address
212 ranges connected to the peer ports devices.
213 */
214 void getPeerAddressRanges(AddrRangeList &resp, bool &snoop)
215 { peer->getDeviceAddressRanges(resp, snoop); }
216
217 /** This function is a wrapper around sendFunctional()
218 that breaks a larger, arbitrarily aligned access into
219 appropriate chunks. The default implementation can use
220 getBlockSize() to determine the block size and go from there.
221 */
222 virtual void readBlob(Addr addr, uint8_t *p, int size);
223
224 /** This function is a wrapper around sendFunctional()
225 that breaks a larger, arbitrarily aligned access into
226 appropriate chunks. The default implementation can use
227 getBlockSize() to determine the block size and go from there.
228 */
229 virtual void writeBlob(Addr addr, uint8_t *p, int size);
230
231 /** Fill size bytes starting at addr with byte value val. This
232 should not need to be virtual, since it can be implemented in
233 terms of writeBlob(). However, it shouldn't be
234 performance-critical either, so it could be if we wanted to.
235 */
236 virtual void memsetBlob(Addr addr, uint8_t val, int size);
237
238 /** Inject a PrintReq for the given address to print the state of
239 * that address throughout the memory system. For debugging.
240 */
241 void printAddr(Addr a);
242
243 private:
244
245 /** Internal helper function for read/writeBlob().
246 */
247 void blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd);
132
133 virtual bool isDefaultPort() const { return false; }
134
135 bool isConnected() { return peer && !peer->isDefaultPort(); }
136
137 protected:
138
139 /** These functions are protected because they should only be
140 * called by a peer port, never directly by any outside object. */
141
142 /** Called to recive a timing call from the peer port. */
143 virtual bool recvTiming(PacketPtr pkt) = 0;
144
145 /** Called to recive a atomic call from the peer port. */
146 virtual Tick recvAtomic(PacketPtr pkt) = 0;
147
148 /** Called to recive a functional call from the peer port. */
149 virtual void recvFunctional(PacketPtr pkt) = 0;
150
151 /** Called to recieve a status change from the peer port. */
152 virtual void recvStatusChange(Status status) = 0;
153
154 /** Called by a peer port if the send was unsuccesful, and had to
155 wait. This shouldn't be valid for response paths (IO Devices).
156 so it is set to panic if it isn't already defined.
157 */
158 virtual void recvRetry() { panic("??"); }
159
160 /** Called by a peer port in order to determine the block size of the
161 device connected to this port. It sometimes doesn't make sense for
162 this function to be called, so it just returns 0. Anytthing that is
163 concerned with the size should just ignore that.
164 */
165 virtual int deviceBlockSize() { return 0; }
166
167 /** The peer port is requesting us to reply with a list of the ranges we
168 are responsible for.
169 @param resp is a list of ranges responded to
170 @param snoop is a list of ranges snooped
171 */
172 virtual void getDeviceAddressRanges(AddrRangeList &resp,
173 bool &snoop)
174 { panic("??"); }
175
176 public:
177
178 /** Function called by associated memory device (cache, memory, iodevice)
179 in order to send a timing request to the port. Simply calls the peer
180 port receive function.
181 @return This function returns if the send was succesful in it's
182 recieve. If it was a failure, then the port will wait for a recvRetry
183 at which point it can possibly issue a successful sendTiming. This is used in
184 case a cache has a higher priority request come in while waiting for
185 the bus to arbitrate.
186 */
187 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
188
189 /** Function called by the associated device to send an atomic
190 * access, an access in which the data is moved and the state is
191 * updated in one cycle, without interleaving with other memory
192 * accesses. Returns estimated latency of access.
193 */
194 Tick sendAtomic(PacketPtr pkt)
195 { return peer->recvAtomic(pkt); }
196
197 /** Function called by the associated device to send a functional access,
198 an access in which the data is instantly updated everywhere in the
199 memory system, without affecting the current state of any block or
200 moving the block.
201 */
202 void sendFunctional(PacketPtr pkt)
203 { return peer->recvFunctional(pkt); }
204
205 /** Called by the associated device to send a status change to the device
206 connected to the peer interface.
207 */
208 void sendStatusChange(Status status) {peer->recvStatusChange(status); }
209
210 /** When a timing access doesn't return a success, some time later the
211 Retry will be sent.
212 */
213 void sendRetry() { return peer->recvRetry(); }
214
215 /** Called by the associated device if it wishes to find out the blocksize
216 of the device on attached to the peer port.
217 */
218 int peerBlockSize() { return peer->deviceBlockSize(); }
219
220 /** Called by the associated device if it wishes to find out the address
221 ranges connected to the peer ports devices.
222 */
223 void getPeerAddressRanges(AddrRangeList &resp, bool &snoop)
224 { peer->getDeviceAddressRanges(resp, snoop); }
225
226 /** This function is a wrapper around sendFunctional()
227 that breaks a larger, arbitrarily aligned access into
228 appropriate chunks. The default implementation can use
229 getBlockSize() to determine the block size and go from there.
230 */
231 virtual void readBlob(Addr addr, uint8_t *p, int size);
232
233 /** This function is a wrapper around sendFunctional()
234 that breaks a larger, arbitrarily aligned access into
235 appropriate chunks. The default implementation can use
236 getBlockSize() to determine the block size and go from there.
237 */
238 virtual void writeBlob(Addr addr, uint8_t *p, int size);
239
240 /** Fill size bytes starting at addr with byte value val. This
241 should not need to be virtual, since it can be implemented in
242 terms of writeBlob(). However, it shouldn't be
243 performance-critical either, so it could be if we wanted to.
244 */
245 virtual void memsetBlob(Addr addr, uint8_t val, int size);
246
247 /** Inject a PrintReq for the given address to print the state of
248 * that address throughout the memory system. For debugging.
249 */
250 void printAddr(Addr a);
251
252 private:
253
254 /** Internal helper function for read/writeBlob().
255 */
256 void blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd);
248
249 /** Receive notification that my peer is disconnecting and clean
250 * up (potentially deleting myself in the process). Should be
251 * called only from peer's disconnectFromPeer(). */
252 void disconnect();
253};
254
255/** A simple functional port that is only meant for one way communication to
256 * physical memory. It is only meant to be used to load data into memory before
257 * the simulation begins.
258 */
259
260class FunctionalPort : public Port
261{
262 public:
263 FunctionalPort(const std::string &_name, MemObject *_owner = NULL)
264 : Port(_name, _owner)
265 {}
266
267 protected:
268 virtual bool recvTiming(PacketPtr pkt) { panic("FuncPort is UniDir");
269 M5_DUMMY_RETURN }
270 virtual Tick recvAtomic(PacketPtr pkt) { panic("FuncPort is UniDir");
271 M5_DUMMY_RETURN }
272 virtual void recvFunctional(PacketPtr pkt) { panic("FuncPort is UniDir"); }
273 virtual void recvStatusChange(Status status) {}
274
275 public:
276 /** a write function that also does an endian conversion. */
277 template <typename T>
278 inline void writeHtoG(Addr addr, T d);
279
280 /** a read function that also does an endian conversion. */
281 template <typename T>
282 inline T readGtoH(Addr addr);
283
284 template <typename T>
285 inline void write(Addr addr, T d)
286 {
287 writeBlob(addr, (uint8_t*)&d, sizeof(T));
288 }
289
290 template <typename T>
291 inline T read(Addr addr)
292 {
293 T d;
294 readBlob(addr, (uint8_t*)&d, sizeof(T));
295 return d;
296 }
297};
298
299#endif //__MEM_PORT_HH__
257};
258
259/** A simple functional port that is only meant for one way communication to
260 * physical memory. It is only meant to be used to load data into memory before
261 * the simulation begins.
262 */
263
264class FunctionalPort : public Port
265{
266 public:
267 FunctionalPort(const std::string &_name, MemObject *_owner = NULL)
268 : Port(_name, _owner)
269 {}
270
271 protected:
272 virtual bool recvTiming(PacketPtr pkt) { panic("FuncPort is UniDir");
273 M5_DUMMY_RETURN }
274 virtual Tick recvAtomic(PacketPtr pkt) { panic("FuncPort is UniDir");
275 M5_DUMMY_RETURN }
276 virtual void recvFunctional(PacketPtr pkt) { panic("FuncPort is UniDir"); }
277 virtual void recvStatusChange(Status status) {}
278
279 public:
280 /** a write function that also does an endian conversion. */
281 template <typename T>
282 inline void writeHtoG(Addr addr, T d);
283
284 /** a read function that also does an endian conversion. */
285 template <typename T>
286 inline T readGtoH(Addr addr);
287
288 template <typename T>
289 inline void write(Addr addr, T d)
290 {
291 writeBlob(addr, (uint8_t*)&d, sizeof(T));
292 }
293
294 template <typename T>
295 inline T read(Addr addr)
296 {
297 T d;
298 readBlob(addr, (uint8_t*)&d, sizeof(T));
299 return d;
300 }
301};
302
303#endif //__MEM_PORT_HH__