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: functional, atomic and timing.
83 /** A type name for the port identifier. */
86 /** A symbolic name for the absence of a port id. */
87 static const PortId INVALID_PORT_ID = -1;
91 /** Descriptive name (for DPRINTF output) */
97 * A numeric identifier to distinguish ports in a vector, and set
98 * to INVALID_PORT_ID in case this port is not part of a vector.
102 /** A pointer to the peer port. */
105 /** A reference to the MemObject that owns this port. */
109 * Abstract base class for ports
111 * @param _name Port name including the owners name
112 * @param _owner The MemObject that is the structural owner of this port
113 * @param _id A port identifier for vector ports
115 Port(const std::string& _name, MemObject& _owner, PortId _id);
118 * Virtual destructor due to inheritance.
124 /** Return port name (for DPRINTF). */
125 const std::string name() const { return portName; }
127 /** Get the port id. */
128 PortId getId() const { return id; }
133 * Called by a peer port if sendTimingReq, sendTimingResp or
134 * sendTimingSnoopResp was unsuccesful, and had to wait.
136 virtual void recvRetry() = 0;
141 * Send a retry to a peer port that previously attempted a
142 * sendTimingReq, sendTimingResp or sendTimingSnoopResp which was
145 void sendRetry() { return peer->recvRetry(); }
149 /** Forward declaration */
153 * A MasterPort is a specialisation of a port. In addition to the
154 * basic functionality of sending packets to its slave peer, it also
155 * has functions specific to a master, e.g. to receive range changes
156 * or determine if the port is snooping or not.
158 class MasterPort : public Port
161 friend class SlavePort;
165 SlavePort* _slavePort;
169 MasterPort(const std::string& name, MemObject* owner,
170 PortId id = INVALID_PORT_ID);
171 virtual ~MasterPort();
173 void bind(SlavePort& slave_port);
174 SlavePort& getSlavePort() const;
175 bool isConnected() const;
178 * Send an atomic request packet, where the data is moved and the
179 * state is updated in zero time, without interleaving with other
182 * @param pkt Packet to send.
184 * @return Estimated latency of access.
186 Tick sendAtomic(PacketPtr pkt);
189 * Send a functional request packet, where the data is instantly
190 * updated everywhere in the memory system, without affecting the
191 * current state of any block or moving the block.
193 * @param pkt Packet to send.
195 void sendFunctional(PacketPtr pkt);
198 * Attempt to send a timing request to the slave port by calling
199 * its corresponding receive function. If the send does not
200 * succeed, as indicated by the return value, then the sender must
201 * wait for a recvRetry at which point it can re-issue a
204 * @param pkt Packet to send.
206 * @return If the send was succesful or not.
208 bool sendTimingReq(PacketPtr pkt);
211 * Attempt to send a timing snoop response packet to the slave
212 * port by calling its corresponding receive function. If the send
213 * does not succeed, as indicated by the return value, then the
214 * sender must wait for a recvRetry at which point it can re-issue
215 * a sendTimingSnoopResp.
217 * @param pkt Packet to send.
219 bool sendTimingSnoopResp(PacketPtr pkt);
222 * Determine if this master port is snooping or not. The default
223 * implementation returns false and thus tells the neighbour we
224 * are not snooping. Any master port that wants to receive snoop
225 * requests (e.g. a cache connected to a bus) has to override this
228 * @return true if the port should be considered a snooper
230 virtual bool isSnooping() const { return false; }
233 * Called by a peer port in order to determine the block size of
234 * the owner of this port.
236 virtual unsigned deviceBlockSize() const { return 0; }
238 /** Called by the associated device if it wishes to find out the blocksize
239 of the device on attached to the peer port.
241 unsigned peerBlockSize() const;
243 /** Inject a PrintReq for the given address to print the state of
244 * that address throughout the memory system. For debugging.
246 void printAddr(Addr a);
251 * Receive an atomic snoop request packet from the slave port.
253 virtual Tick recvAtomicSnoop(PacketPtr pkt)
255 panic("%s was not expecting an atomic snoop request\n", name());
260 * Receive a functional snoop request packet from the slave port.
262 virtual void recvFunctionalSnoop(PacketPtr pkt)
264 panic("%s was not expecting a functional snoop request\n", name());
268 * Receive a timing response from the slave port.
270 virtual bool recvTimingResp(PacketPtr pkt) = 0;
273 * Receive a timing snoop request from the slave port.
275 virtual void recvTimingSnoopReq(PacketPtr pkt)
277 panic("%s was not expecting a timing snoop request\n", name());
281 * Called to receive an address range change from the peer slave
282 * port. the default implementation ignored the change and does
283 * nothing. Override this function in a derived class if the owner
284 * needs to be aware of he laesddress ranges, e.g. in an
285 * interconnect component like a bus.
287 virtual void recvRangeChange() { }
291 * A SlavePort is a specialisation of a port. In addition to the
292 * basic functionality of sending packets to its master peer, it also
293 * has functions specific to a slave, e.g. to send range changes
294 * and get the address ranges that the port responds to.
296 class SlavePort : public Port
299 friend class MasterPort;
303 MasterPort* _masterPort;
307 SlavePort(const std::string& name, MemObject* owner,
308 PortId id = INVALID_PORT_ID);
309 virtual ~SlavePort();
311 void bind(MasterPort& master_port);
312 MasterPort& getMasterPort() const;
313 bool isConnected() const;
316 * Send an atomic snoop request packet, where the data is moved
317 * and the state is updated in zero time, without interleaving
318 * with other memory accesses.
320 * @param pkt Snoop packet to send.
322 * @return Estimated latency of access.
324 Tick sendAtomicSnoop(PacketPtr pkt);
327 * Send a functional snoop request packet, where the data is
328 * instantly updated everywhere in the memory system, without
329 * affecting the current state of any block or moving the block.
331 * @param pkt Snoop packet to send.
333 void sendFunctionalSnoop(PacketPtr pkt);
336 * Attempt to send a timing response to the master port by calling
337 * its corresponding receive function. If the send does not
338 * succeed, as indicated by the return value, then the sender must
339 * wait for a recvRetry at which point it can re-issue a
342 * @param pkt Packet to send.
344 * @return If the send was succesful or not.
346 bool sendTimingResp(PacketPtr pkt);
349 * Attempt to send a timing snoop request packet to the master port
350 * by calling its corresponding receive function. Snoop requests
351 * always succeed and hence no return value is needed.
353 * @param pkt Packet to send.
355 void sendTimingSnoopReq(PacketPtr pkt);
358 * Called by a peer port in order to determine the block size of
359 * the owner of this port.
361 virtual unsigned deviceBlockSize() const { return 0; }
363 /** Called by the associated device if it wishes to find out the blocksize
364 of the device on attached to the peer port.
366 unsigned peerBlockSize() const;
369 * Called by the owner to send a range change
371 void sendRangeChange() const { _masterPort->recvRangeChange(); }
374 * Get a list of the non-overlapping address ranges the owner is
375 * responsible for. All slave ports must override this function
376 * and return a populated list with at least one item.
378 * @return a list of ranges responded to
380 virtual AddrRangeList getAddrRanges() = 0;
385 * Receive an atomic request packet from the master port.
387 virtual Tick recvAtomic(PacketPtr pkt) = 0;
390 * Receive a functional request packet from the master port.
392 virtual void recvFunctional(PacketPtr pkt) = 0;
395 * Receive a timing request from the master port.
397 virtual bool recvTimingReq(PacketPtr pkt) = 0;
400 * Receive a timing snoop response from the master port.
402 virtual bool recvTimingSnoopResp(PacketPtr pkt)
404 panic("%s was not expecting a timing snoop response\n", name());
409 #endif //__MEM_PORT_HH__