2 * Copyright (c) 2011-2012 ARM Limited
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.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
40 * Authors: Ron Dreslinski
47 * Port Object Declaration.
50 #ifndef __MEM_PORT_HH__
51 #define __MEM_PORT_HH__
55 #include "base/range.hh"
56 #include "mem/packet.hh"
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
65 typedef std::list<Range<Addr> > AddrRangeList;
66 typedef std::list<Range<Addr> >::iterator AddrRangeIter;
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
75 * Each port has a name and an owner, and enables three basic types of
76 * accesses to the peer port: sendFunctional, sendAtomic and
84 /** Descriptive name (for DPRINTF output) */
89 /** A pointer to the peer port. */
92 /** A reference to the MemObject that owns this port. */
96 * Abstract base class for ports
98 * @param _name Port name including the owners name
99 * @param _owner The MemObject that is the structural owner of this port
101 Port(const std::string& _name, MemObject& _owner);
104 * Virtual destructor due to inheritance.
110 /** Return port name (for DPRINTF). */
111 const std::string name() const { return portName; }
115 /** These functions are protected because they should only be
116 * called by a peer port, never directly by any outside object. */
118 /** Called to recive a timing call from the peer port. */
119 virtual bool recvTiming(PacketPtr pkt) = 0;
121 /** Called to recive a atomic call from the peer port. */
122 virtual Tick recvAtomic(PacketPtr pkt) = 0;
124 /** Called to recive a functional call from the peer port. */
125 virtual void recvFunctional(PacketPtr pkt) = 0;
128 * Called by a peer port if sendTiming was unsuccesful, and had to
131 virtual void recvRetry() = 0;
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.
141 * @param pkt Packet to send.
143 * @return If the send was succesful or not.
145 bool sendTiming(PacketPtr pkt) { return peer->recvTiming(pkt); }
148 * Send a retry to a peer port that previously attempted a sendTiming
149 * which was unsuccessful.
151 void sendRetry() { return peer->recvRetry(); }
154 * Send an atomic packet, where the data is moved and the state
155 * is updated in zero time, without interleaving with other
158 * @param pkt Packet to send.
160 * @return Estimated latency of access.
162 Tick sendAtomic(PacketPtr pkt) { return peer->recvAtomic(pkt); }
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.
169 * @param pkt Packet to send.
171 void sendFunctional(PacketPtr pkt) { return peer->recvFunctional(pkt); }
175 /** Forward declaration */
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.
184 class MasterPort : public Port
189 SlavePort* _slavePort;
193 MasterPort(const std::string& name, MemObject* owner);
194 virtual ~MasterPort();
196 void bind(SlavePort& slave_port);
197 SlavePort& getSlavePort() const;
198 bool isConnected() const;
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.
207 virtual void recvRangeChange() { }
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
216 * @return true if the port should be considered a snooper
218 virtual bool isSnooping() const { return false; }
221 * Called by a peer port in order to determine the block size of
222 * the owner of this port.
224 virtual unsigned deviceBlockSize() const { return 0; }
226 /** Called by the associated device if it wishes to find out the blocksize
227 of the device on attached to the peer port.
229 unsigned peerBlockSize() const;
231 /** Inject a PrintReq for the given address to print the state of
232 * that address throughout the memory system. For debugging.
234 void printAddr(Addr a);
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.
243 class SlavePort : public Port
248 MasterPort* _masterPort;
252 SlavePort(const std::string& name, MemObject* owner);
253 virtual ~SlavePort();
255 void bind(MasterPort& master_port);
256 MasterPort& getMasterPort() const;
257 bool isConnected() const;
260 * Called by a peer port in order to determine the block size of
261 * the owner of this port.
263 virtual unsigned deviceBlockSize() const { return 0; }
265 /** Called by the associated device if it wishes to find out the blocksize
266 of the device on attached to the peer port.
268 unsigned peerBlockSize() const;
271 * Called by the owner to send a range change
273 void sendRangeChange() const { _masterPort->recvRangeChange(); }
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.
280 * @return a list of ranges responded to
282 virtual AddrRangeList getAddrRanges() = 0;
285 #endif //__MEM_PORT_HH__