port.hh (8922:17f037ad8918) port.hh (8948:e95ee70f876c)
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ron Dreslinski
41 * Andreas Hansson
42 * William Wang
43 */
44
45/**
46 * @file
47 * Port Object Declaration.
48 */
49
50#ifndef __MEM_PORT_HH__
51#define __MEM_PORT_HH__
52
53#include <list>
54
55#include "base/range.hh"
56#include "mem/packet.hh"
57
58/**
59 * This typedef is used to clean up getAddrRanges(). It's declared
60 * outside the Port object since it's also used by some mem objects.
61 * Eventually we should move this typedef to wherever Addr is
62 * defined.
63 */
64
65typedef std::list<Range<Addr> > AddrRangeList;
66typedef std::list<Range<Addr> >::iterator AddrRangeIter;
67
68class MemObject;
69
70/**
71 * Ports are used to interface memory objects to each other. A port is
72 * either a master or a slave and the connected peer is always of the
73 * opposite role.
74 *
75 * Each port has a name and an owner, and enables three basic types of
76 * accesses to the peer port: sendFunctional, sendAtomic and
77 * sendTiming.
78 */
79class Port
80{
81
82 private:
83
84 /** Descriptive name (for DPRINTF output) */
85 std::string portName;
86
87 protected:
88
89 /** A pointer to the peer port. */
90 Port* peer;
91
92 /** A reference to the MemObject that owns this port. */
93 MemObject& owner;
94
95 /**
96 * Abstract base class for ports
97 *
98 * @param _name Port name including the owners name
99 * @param _owner The MemObject that is the structural owner of this port
100 */
101 Port(const std::string& _name, MemObject& _owner);
102
103 /**
104 * Virtual destructor due to inheritance.
105 */
106 virtual ~Port();
107
108 public:
109
110 /** Return port name (for DPRINTF). */
111 const std::string name() const { return portName; }
112
113 protected:
114
115 /** These functions are protected because they should only be
116 * called by a peer port, never directly by any outside object. */
117
1/*
2 * Copyright (c) 2011-2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ron Dreslinski
41 * Andreas Hansson
42 * William Wang
43 */
44
45/**
46 * @file
47 * Port Object Declaration.
48 */
49
50#ifndef __MEM_PORT_HH__
51#define __MEM_PORT_HH__
52
53#include <list>
54
55#include "base/range.hh"
56#include "mem/packet.hh"
57
58/**
59 * This typedef is used to clean up getAddrRanges(). It's declared
60 * outside the Port object since it's also used by some mem objects.
61 * Eventually we should move this typedef to wherever Addr is
62 * defined.
63 */
64
65typedef std::list<Range<Addr> > AddrRangeList;
66typedef std::list<Range<Addr> >::iterator AddrRangeIter;
67
68class MemObject;
69
70/**
71 * Ports are used to interface memory objects to each other. A port is
72 * either a master or a slave and the connected peer is always of the
73 * opposite role.
74 *
75 * Each port has a name and an owner, and enables three basic types of
76 * accesses to the peer port: sendFunctional, sendAtomic and
77 * sendTiming.
78 */
79class Port
80{
81
82 private:
83
84 /** Descriptive name (for DPRINTF output) */
85 std::string portName;
86
87 protected:
88
89 /** A pointer to the peer port. */
90 Port* peer;
91
92 /** A reference to the MemObject that owns this port. */
93 MemObject& owner;
94
95 /**
96 * Abstract base class for ports
97 *
98 * @param _name Port name including the owners name
99 * @param _owner The MemObject that is the structural owner of this port
100 */
101 Port(const std::string& _name, MemObject& _owner);
102
103 /**
104 * Virtual destructor due to inheritance.
105 */
106 virtual ~Port();
107
108 public:
109
110 /** Return port name (for DPRINTF). */
111 const std::string name() const { return portName; }
112
113 protected:
114
115 /** These functions are protected because they should only be
116 * called by a peer port, never directly by any outside object. */
117
118 /** Called to recive a timing call from the peer port. */
118 /**
119 * Receive a timing request or response packet from the peer port.
120 */
119 virtual bool recvTiming(PacketPtr pkt) = 0;
120
121 virtual bool recvTiming(PacketPtr pkt) = 0;
122
121 /** Called to recive a atomic call from the peer port. */
122 virtual Tick recvAtomic(PacketPtr pkt) = 0;
123 /**
124 * Receive a timing snoop request or snoop response packet from
125 * the peer port.
126 */
127 virtual bool recvTimingSnoop(PacketPtr pkt)
128 {
129 panic("%s was not expecting a timing snoop\n", name());
130 return false;
131 }
123
132
124 /** Called to recive a functional call from the peer port. */
125 virtual void recvFunctional(PacketPtr pkt) = 0;
126
127 /**
133 /**
128 * Called by a peer port if sendTiming was unsuccesful, and had to
129 * wait.
134 * Called by a peer port if sendTiming or sendTimingSnoop was
135 * unsuccesful, and had to wait.
130 */
131 virtual void recvRetry() = 0;
132
133 public:
134
135 /**
136 */
137 virtual void recvRetry() = 0;
138
139 public:
140
141 /**
136 * Attempt to send a timing packet to the peer port by calling its
137 * receive function. If the send does not succeed, as indicated by
138 * the return value, then the sender must wait for a recvRetry at
139 * which point it can re-issue a sendTiming.
142 * Attempt to send a timing request or response packet to the peer
143 * port by calling its receive function. If the send does not
144 * succeed, as indicated by the return value, then the sender must
145 * wait for a recvRetry at which point it can re-issue a
146 * sendTiming.
140 *
141 * @param pkt Packet to send.
142 *
143 * @return If the send was succesful or not.
144 */
145 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
146
147 /**
147 *
148 * @param pkt Packet to send.
149 *
150 * @return If the send was succesful or not.
151 */
152 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
153
154 /**
148 * Send a retry to a peer port that previously attempted a sendTiming
149 * which was unsuccessful.
150 */
151 void sendRetry() { return peer->recvRetry(); }
152
153 /**
154 * Send an atomic packet, where the data is moved and the state
155 * is updated in zero time, without interleaving with other
156 * memory accesses.
155 * Attempt to send a timing snoop request or snoop response packet
156 * to the peer port by calling its receive function. If the send
157 * does not succeed, as indicated by the return value, then the
158 * sender must wait for a recvRetry at which point it can re-issue
159 * a sendTimingSnoop.
157 *
158 * @param pkt Packet to send.
159 *
160 *
161 * @param pkt Packet to send.
162 *
160 * @return Estimated latency of access.
161 */
162 Tick sendAtomic(PacketPtr pkt) { return peer->recvAtomic(pkt); }
163 * @return If the send was succesful or not.
164 */
165 bool sendTimingSnoop(PacketPtr pkt) { return peer->recvTimingSnoop(pkt); }
163
164 /**
166
167 /**
165 * Send a functional packet, where the data is instantly updated
166 * everywhere in the memory system, without affecting the current
167 * state of any block or moving the block.
168 *
169 * @param pkt Packet to send.
168 * Send a retry to a peer port that previously attempted a
169 * sendTiming or sendTimingSnoop which was unsuccessful.
170 */
170 */
171 void sendFunctional(PacketPtr pkt) { return peer->recvFunctional(pkt); }
171 void sendRetry() { return peer->recvRetry(); }
172
173};
174
175/** Forward declaration */
176class SlavePort;
177
178/**
179 * A MasterPort is a specialisation of a port. In addition to the
180 * basic functionality of sending packets to its slave peer, it also
181 * has functions specific to a master, e.g. to receive range changes
182 * or determine if the port is snooping or not.
183 */
184class MasterPort : public Port
185{
186
187 private:
188
189 SlavePort* _slavePort;
190
191 public:
192
193 MasterPort(const std::string& name, MemObject* owner);
194 virtual ~MasterPort();
195
196 void bind(SlavePort& slave_port);
197 SlavePort& getSlavePort() const;
198 bool isConnected() const;
199
200 /**
172
173};
174
175/** Forward declaration */
176class SlavePort;
177
178/**
179 * A MasterPort is a specialisation of a port. In addition to the
180 * basic functionality of sending packets to its slave peer, it also
181 * has functions specific to a master, e.g. to receive range changes
182 * or determine if the port is snooping or not.
183 */
184class MasterPort : public Port
185{
186
187 private:
188
189 SlavePort* _slavePort;
190
191 public:
192
193 MasterPort(const std::string& name, MemObject* owner);
194 virtual ~MasterPort();
195
196 void bind(SlavePort& slave_port);
197 SlavePort& getSlavePort() const;
198 bool isConnected() const;
199
200 /**
201 * Send an atomic request packet, where the data is moved and the
202 * state is updated in zero time, without interleaving with other
203 * memory accesses.
204 *
205 * @param pkt Packet to send.
206 *
207 * @return Estimated latency of access.
208 */
209 Tick sendAtomic(PacketPtr pkt);
210
211 /**
212 * Send a functional request packet, where the data is instantly
213 * updated everywhere in the memory system, without affecting the
214 * current state of any block or moving the block.
215 *
216 * @param pkt Packet to send.
217 */
218 void sendFunctional(PacketPtr pkt);
219
220 /**
221 * Receive an atomic snoop request packet from the slave port.
222 */
223 virtual Tick recvAtomicSnoop(PacketPtr pkt)
224 {
225 panic("%s was not expecting an atomic snoop\n", name());
226 return 0;
227 }
228
229 /**
230 * Receive a functional snoop request packet from the slave port.
231 */
232 virtual void recvFunctionalSnoop(PacketPtr pkt)
233 {
234 panic("%s was not expecting a functional snoop\n", name());
235 }
236
237 /**
201 * Called to receive an address range change from the peer slave
202 * port. the default implementation ignored the change and does
203 * nothing. Override this function in a derived class if the owner
204 * needs to be aware of he laesddress ranges, e.g. in an
205 * interconnect component like a bus.
206 */
207 virtual void recvRangeChange() { }
208
209 /**
210 * Determine if this master port is snooping or not. The default
211 * implementation returns false and thus tells the neighbour we
212 * are not snooping. Any master port that wants to receive snoop
213 * requests (e.g. a cache connected to a bus) has to override this
214 * function.
215 *
216 * @return true if the port should be considered a snooper
217 */
218 virtual bool isSnooping() const { return false; }
219
220 /**
221 * Called by a peer port in order to determine the block size of
222 * the owner of this port.
223 */
224 virtual unsigned deviceBlockSize() const { return 0; }
225
226 /** Called by the associated device if it wishes to find out the blocksize
227 of the device on attached to the peer port.
228 */
229 unsigned peerBlockSize() const;
230
231 /** Inject a PrintReq for the given address to print the state of
232 * that address throughout the memory system. For debugging.
233 */
234 void printAddr(Addr a);
235};
236
237/**
238 * A SlavePort is a specialisation of a port. In addition to the
239 * basic functionality of sending packets to its master peer, it also
240 * has functions specific to a slave, e.g. to send range changes
241 * and get the address ranges that the port responds to.
242 */
243class SlavePort : public Port
244{
245
246 private:
247
248 MasterPort* _masterPort;
249
250 public:
251
252 SlavePort(const std::string& name, MemObject* owner);
253 virtual ~SlavePort();
254
255 void bind(MasterPort& master_port);
256 MasterPort& getMasterPort() const;
257 bool isConnected() const;
258
259 /**
238 * Called to receive an address range change from the peer slave
239 * port. the default implementation ignored the change and does
240 * nothing. Override this function in a derived class if the owner
241 * needs to be aware of he laesddress ranges, e.g. in an
242 * interconnect component like a bus.
243 */
244 virtual void recvRangeChange() { }
245
246 /**
247 * Determine if this master port is snooping or not. The default
248 * implementation returns false and thus tells the neighbour we
249 * are not snooping. Any master port that wants to receive snoop
250 * requests (e.g. a cache connected to a bus) has to override this
251 * function.
252 *
253 * @return true if the port should be considered a snooper
254 */
255 virtual bool isSnooping() const { return false; }
256
257 /**
258 * Called by a peer port in order to determine the block size of
259 * the owner of this port.
260 */
261 virtual unsigned deviceBlockSize() const { return 0; }
262
263 /** Called by the associated device if it wishes to find out the blocksize
264 of the device on attached to the peer port.
265 */
266 unsigned peerBlockSize() const;
267
268 /** Inject a PrintReq for the given address to print the state of
269 * that address throughout the memory system. For debugging.
270 */
271 void printAddr(Addr a);
272};
273
274/**
275 * A SlavePort is a specialisation of a port. In addition to the
276 * basic functionality of sending packets to its master peer, it also
277 * has functions specific to a slave, e.g. to send range changes
278 * and get the address ranges that the port responds to.
279 */
280class SlavePort : public Port
281{
282
283 private:
284
285 MasterPort* _masterPort;
286
287 public:
288
289 SlavePort(const std::string& name, MemObject* owner);
290 virtual ~SlavePort();
291
292 void bind(MasterPort& master_port);
293 MasterPort& getMasterPort() const;
294 bool isConnected() const;
295
296 /**
297 * Send an atomic snoop request packet, where the data is moved
298 * and the state is updated in zero time, without interleaving
299 * with other memory accesses.
300 *
301 * @param pkt Snoop packet to send.
302 *
303 * @return Estimated latency of access.
304 */
305 Tick sendAtomicSnoop(PacketPtr pkt);
306
307 /**
308 * Send a functional snoop request packet, where the data is
309 * instantly updated everywhere in the memory system, without
310 * affecting the current state of any block or moving the block.
311 *
312 * @param pkt Snoop packet to send.
313 */
314 void sendFunctionalSnoop(PacketPtr pkt);
315
316 /**
317 * Receive an atomic request packet from the master port.
318 */
319 virtual Tick recvAtomic(PacketPtr pkt) = 0;
320
321 /**
322 * Receive a functional request packet from the master port.
323 */
324 virtual void recvFunctional(PacketPtr pkt) = 0;
325
326 /**
260 * Called by a peer port in order to determine the block size of
261 * the owner of this port.
262 */
263 virtual unsigned deviceBlockSize() const { return 0; }
264
265 /** Called by the associated device if it wishes to find out the blocksize
266 of the device on attached to the peer port.
267 */
268 unsigned peerBlockSize() const;
269
270 /**
271 * Called by the owner to send a range change
272 */
273 void sendRangeChange() const { _masterPort->recvRangeChange(); }
274
275 /**
276 * Get a list of the non-overlapping address ranges the owner is
277 * responsible for. All slave ports must override this function
278 * and return a populated list with at least one item.
279 *
280 * @return a list of ranges responded to
281 */
282 virtual AddrRangeList getAddrRanges() = 0;
283};
284
285#endif //__MEM_PORT_HH__
327 * Called by a peer port in order to determine the block size of
328 * the owner of this port.
329 */
330 virtual unsigned deviceBlockSize() const { return 0; }
331
332 /** Called by the associated device if it wishes to find out the blocksize
333 of the device on attached to the peer port.
334 */
335 unsigned peerBlockSize() const;
336
337 /**
338 * Called by the owner to send a range change
339 */
340 void sendRangeChange() const { _masterPort->recvRangeChange(); }
341
342 /**
343 * Get a list of the non-overlapping address ranges the owner is
344 * responsible for. All slave ports must override this function
345 * and return a populated list with at least one item.
346 *
347 * @return a list of ranges responded to
348 */
349 virtual AddrRangeList getAddrRanges() = 0;
350};
351
352#endif //__MEM_PORT_HH__