port.hh (8711:c7e14f52c682) port.hh (8853:0216ed80991b)
1/*
1/*
2 * Copyright (c) 2011 ARM Limited
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
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
41 */
42
43/**
44 * @file
45 * Port Object Declaration. Ports are used to interface memory objects to
46 * each other. They will always come in pairs, and we refer to the other
47 * port object as the peer. These are used to make the design more
48 * modular so that a specific interface between every type of objcet doesn't
49 * have to be created.
50 */
51
52#ifndef __MEM_PORT_HH__
53#define __MEM_PORT_HH__
54
55#include <list>
56
42 */
43
44/**
45 * @file
46 * Port Object Declaration. Ports are used to interface memory objects to
47 * each other. They will always come in pairs, and we refer to the other
48 * port object as the peer. These are used to make the design more
49 * modular so that a specific interface between every type of objcet doesn't
50 * have to be created.
51 */
52
53#ifndef __MEM_PORT_HH__
54#define __MEM_PORT_HH__
55
56#include <list>
57
57#include "base/misc.hh"
58#include "base/range.hh"
58#include "base/range.hh"
59#include "base/types.hh"
60#include "mem/packet.hh"
59#include "mem/packet.hh"
61#include "mem/request.hh"
62
63/** This typedef is used to clean up getAddrRanges(). It's declared
64 * outside the Port object since it's also used by some mem objects.
65 * Eventually we should move this typedef to wherever Addr is
66 * defined.
67 */
68
69typedef std::list<Range<Addr> > AddrRangeList;
70typedef std::list<Range<Addr> >::iterator AddrRangeIter;
71
72class MemObject;
73
74/**
75 * Ports are used to interface memory objects to
76 * each other. They will always come in pairs, and we refer to the other
77 * port object as the peer. These are used to make the design more
78 * modular so that a specific interface between every type of objcet doesn't
79 * have to be created.
80 *
81 * Recv accesor functions are being called from the peer interface.
82 * Send accessor functions are being called from the device the port is
83 * associated with, and it will call the peer recv. accessor function.
84 */
85class Port
86{
87 protected:
88 /** Descriptive name (for DPRINTF output) */
89 mutable std::string portName;
90
91 /** A pointer to the peer port. Ports always come in pairs, that way they
92 can use a standardized interface to communicate between different
93 memory objects. */
94 Port *peer;
95
96 /** A pointer to the MemObject that owns this port. This may not be set. */
97 MemObject *owner;
98
99 public:
100 /**
101 * Constructor.
102 *
103 * @param _name Port name for DPRINTF output. Should include name
104 * of memory system object to which the port belongs.
105 * @param _owner Pointer to the MemObject that owns this port.
106 * Will not necessarily be set.
107 */
108 Port(const std::string &_name, MemObject *_owner);
109
110 /** Return port name (for DPRINTF). */
111 const std::string &name() const { return portName; }
112
113 virtual ~Port();
114
115 void setName(const std::string &name)
116 { portName = name; }
117
118 /** Function to set the pointer for the peer port. */
119 virtual void setPeer(Port *port);
120
121 /** Function to get the pointer to the peer port. */
122 Port *getPeer() { return peer; }
123
124 /** Function to set the owner of this port. */
125 void setOwner(MemObject *_owner);
126
127 /** Function to return the owner of this port. */
128 MemObject *getOwner() { return owner; }
129
130 bool isConnected() { return peer != NULL; }
131
132 protected:
133
134 /** These functions are protected because they should only be
135 * called by a peer port, never directly by any outside object. */
136
137 /** Called to recive a timing call from the peer port. */
138 virtual bool recvTiming(PacketPtr pkt) = 0;
139
140 /** Called to recive a atomic call from the peer port. */
141 virtual Tick recvAtomic(PacketPtr pkt) = 0;
142
143 /** Called to recive a functional call from the peer port. */
144 virtual void recvFunctional(PacketPtr pkt) = 0;
145
146 /** Called to recieve an address range change from the peer port. */
147 virtual void recvRangeChange() = 0;
148
149 /** Called by a peer port if the send was unsuccesful, and had to
150 wait. This shouldn't be valid for response paths (IO Devices).
151 so it is set to panic if it isn't already defined.
152 */
153 virtual void recvRetry() { panic("??"); }
154
155 /** Called by a peer port in order to determine the block size of the
156 device connected to this port. It sometimes doesn't make sense for
157 this function to be called, so it just returns 0. Anytthing that is
158 concerned with the size should just ignore that.
159 */
160 virtual unsigned deviceBlockSize() const { return 0; }
161
162 public:
163
164 /**
165 * Get a list of the non-overlapping address ranges we are
166 * responsible for. The default implementation returns an empty
167 * list and thus no address ranges. Any slave port must override
168 * this function and return a populated list with at least one
169 * item.
170 *
171 * @return a list of ranges responded to
172 */
173 virtual AddrRangeList getAddrRanges()
174 { AddrRangeList ranges; return ranges; }
175
176 /**
177 * Determine if this port is snooping or not. The default
178 * implementation returns false and thus tells the neighbour we
179 * are not snooping. Any port that is to snoop (e.g. a cache
180 * connected to a bus) has to override this function.
181 *
182 * @return true if the port should be considered a snooper
183 */
184 virtual bool isSnooping()
185 { return false; }
186
187 /** Function called by associated memory device (cache, memory, iodevice)
188 in order to send a timing request to the port. Simply calls the peer
189 port receive function.
190 @return This function returns if the send was succesful in it's
191 recieve. If it was a failure, then the port will wait for a recvRetry
192 at which point it can possibly issue a successful sendTiming. This is used in
193 case a cache has a higher priority request come in while waiting for
194 the bus to arbitrate.
195 */
196 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
197
198 /** Function called by the associated device to send an atomic
199 * access, an access in which the data is moved and the state is
200 * updated in one cycle, without interleaving with other memory
201 * accesses. Returns estimated latency of access.
202 */
203 Tick sendAtomic(PacketPtr pkt)
204 { return peer->recvAtomic(pkt); }
205
206 /** Function called by the associated device to send a functional access,
207 an access in which the data is instantly updated everywhere in the
208 memory system, without affecting the current state of any block or
209 moving the block.
210 */
211 void sendFunctional(PacketPtr pkt)
212 { return peer->recvFunctional(pkt); }
213
214 /**
215 * Called by the associated device to send a status range to the
216 * peer interface.
217 */
218 void sendRangeChange() const { peer->recvRangeChange(); }
219
220 /** When a timing access doesn't return a success, some time later the
221 Retry will be sent.
222 */
223 void sendRetry() { return peer->recvRetry(); }
224
225 /** Called by the associated device if it wishes to find out the blocksize
226 of the device on attached to the peer port.
227 */
228 unsigned peerBlockSize() const { return peer->deviceBlockSize(); }
229
60
61/** This typedef is used to clean up getAddrRanges(). It's declared
62 * outside the Port object since it's also used by some mem objects.
63 * Eventually we should move this typedef to wherever Addr is
64 * defined.
65 */
66
67typedef std::list<Range<Addr> > AddrRangeList;
68typedef std::list<Range<Addr> >::iterator AddrRangeIter;
69
70class MemObject;
71
72/**
73 * Ports are used to interface memory objects to
74 * each other. They will always come in pairs, and we refer to the other
75 * port object as the peer. These are used to make the design more
76 * modular so that a specific interface between every type of objcet doesn't
77 * have to be created.
78 *
79 * Recv accesor functions are being called from the peer interface.
80 * Send accessor functions are being called from the device the port is
81 * associated with, and it will call the peer recv. accessor function.
82 */
83class Port
84{
85 protected:
86 /** Descriptive name (for DPRINTF output) */
87 mutable std::string portName;
88
89 /** A pointer to the peer port. Ports always come in pairs, that way they
90 can use a standardized interface to communicate between different
91 memory objects. */
92 Port *peer;
93
94 /** A pointer to the MemObject that owns this port. This may not be set. */
95 MemObject *owner;
96
97 public:
98 /**
99 * Constructor.
100 *
101 * @param _name Port name for DPRINTF output. Should include name
102 * of memory system object to which the port belongs.
103 * @param _owner Pointer to the MemObject that owns this port.
104 * Will not necessarily be set.
105 */
106 Port(const std::string &_name, MemObject *_owner);
107
108 /** Return port name (for DPRINTF). */
109 const std::string &name() const { return portName; }
110
111 virtual ~Port();
112
113 void setName(const std::string &name)
114 { portName = name; }
115
116 /** Function to set the pointer for the peer port. */
117 virtual void setPeer(Port *port);
118
119 /** Function to get the pointer to the peer port. */
120 Port *getPeer() { return peer; }
121
122 /** Function to set the owner of this port. */
123 void setOwner(MemObject *_owner);
124
125 /** Function to return the owner of this port. */
126 MemObject *getOwner() { return owner; }
127
128 bool isConnected() { return peer != NULL; }
129
130 protected:
131
132 /** These functions are protected because they should only be
133 * called by a peer port, never directly by any outside object. */
134
135 /** Called to recive a timing call from the peer port. */
136 virtual bool recvTiming(PacketPtr pkt) = 0;
137
138 /** Called to recive a atomic call from the peer port. */
139 virtual Tick recvAtomic(PacketPtr pkt) = 0;
140
141 /** Called to recive a functional call from the peer port. */
142 virtual void recvFunctional(PacketPtr pkt) = 0;
143
144 /** Called to recieve an address range change from the peer port. */
145 virtual void recvRangeChange() = 0;
146
147 /** Called by a peer port if the send was unsuccesful, and had to
148 wait. This shouldn't be valid for response paths (IO Devices).
149 so it is set to panic if it isn't already defined.
150 */
151 virtual void recvRetry() { panic("??"); }
152
153 /** Called by a peer port in order to determine the block size of the
154 device connected to this port. It sometimes doesn't make sense for
155 this function to be called, so it just returns 0. Anytthing that is
156 concerned with the size should just ignore that.
157 */
158 virtual unsigned deviceBlockSize() const { return 0; }
159
160 public:
161
162 /**
163 * Get a list of the non-overlapping address ranges we are
164 * responsible for. The default implementation returns an empty
165 * list and thus no address ranges. Any slave port must override
166 * this function and return a populated list with at least one
167 * item.
168 *
169 * @return a list of ranges responded to
170 */
171 virtual AddrRangeList getAddrRanges()
172 { AddrRangeList ranges; return ranges; }
173
174 /**
175 * Determine if this port is snooping or not. The default
176 * implementation returns false and thus tells the neighbour we
177 * are not snooping. Any port that is to snoop (e.g. a cache
178 * connected to a bus) has to override this function.
179 *
180 * @return true if the port should be considered a snooper
181 */
182 virtual bool isSnooping()
183 { return false; }
184
185 /** Function called by associated memory device (cache, memory, iodevice)
186 in order to send a timing request to the port. Simply calls the peer
187 port receive function.
188 @return This function returns if the send was succesful in it's
189 recieve. If it was a failure, then the port will wait for a recvRetry
190 at which point it can possibly issue a successful sendTiming. This is used in
191 case a cache has a higher priority request come in while waiting for
192 the bus to arbitrate.
193 */
194 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
195
196 /** Function called by the associated device to send an atomic
197 * access, an access in which the data is moved and the state is
198 * updated in one cycle, without interleaving with other memory
199 * accesses. Returns estimated latency of access.
200 */
201 Tick sendAtomic(PacketPtr pkt)
202 { return peer->recvAtomic(pkt); }
203
204 /** Function called by the associated device to send a functional access,
205 an access in which the data is instantly updated everywhere in the
206 memory system, without affecting the current state of any block or
207 moving the block.
208 */
209 void sendFunctional(PacketPtr pkt)
210 { return peer->recvFunctional(pkt); }
211
212 /**
213 * Called by the associated device to send a status range to the
214 * peer interface.
215 */
216 void sendRangeChange() const { peer->recvRangeChange(); }
217
218 /** When a timing access doesn't return a success, some time later the
219 Retry will be sent.
220 */
221 void sendRetry() { return peer->recvRetry(); }
222
223 /** Called by the associated device if it wishes to find out the blocksize
224 of the device on attached to the peer port.
225 */
226 unsigned peerBlockSize() const { return peer->deviceBlockSize(); }
227
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 readBlob(Addr addr, uint8_t *p, int size);
236
237 /** This function is a wrapper around sendFunctional()
238 that breaks a larger, arbitrarily aligned access into
239 appropriate chunks. The default implementation can use
240 getBlockSize() to determine the block size and go from there.
241 */
242 virtual void writeBlob(Addr addr, uint8_t *p, int size);
243
244 /** Fill size bytes starting at addr with byte value val. This
245 should not need to be virtual, since it can be implemented in
246 terms of writeBlob(). However, it shouldn't be
247 performance-critical either, so it could be if we wanted to.
248 */
249 virtual void memsetBlob(Addr addr, uint8_t val, int size);
250
251 /** Inject a PrintReq for the given address to print the state of
252 * that address throughout the memory system. For debugging.
253 */
254 void printAddr(Addr a);
228 /** Inject a PrintReq for the given address to print the state of
229 * that address throughout the memory system. For debugging.
230 */
231 void printAddr(Addr a);
255
256 private:
257
258 /** Internal helper function for read/writeBlob().
259 */
260 void blobHelper(Addr addr, uint8_t *p, int size, MemCmd cmd);
261};
262
263#endif //__MEM_PORT_HH__
232};
233
234#endif //__MEM_PORT_HH__