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/addr_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<AddrRange> AddrRangeList;
66 typedef std::list<AddrRange>::iterator AddrRangeIter;
67 typedef std::list<AddrRange>::const_iterator AddrRangeConstIter;
72 * Ports are used to interface memory objects to each other. A port is
73 * either a master or a slave and the connected peer is always of the
74 * opposite role. Each port has a name, an owner, and an identifier.
81 /** Descriptive name (for DPRINTF output) */
87 * A numeric identifier to distinguish ports in a vector, and set
88 * to InvalidPortID in case this port is not part of a vector.
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
100 * @param _id A port identifier for vector ports
102 Port(const std::string& _name, MemObject& _owner, PortID _id);
105 * Virtual destructor due to inheritance.
111 /** Return port name (for DPRINTF). */
112 const std::string name() const { return portName; }
114 /** Get the port id. */
115 PortID getId() const { return id; }
119 /** Forward declaration */
123 * A BaseMasterPort is a protocol-agnostic master port, responsible
124 * only for the structural connection to a slave port. The final
125 * master port that inherits from the base class must override the
126 * bind member function for the specific slave port class.
128 class BaseMasterPort : public Port
133 BaseSlavePort* _baseSlavePort;
135 BaseMasterPort(const std::string& name, MemObject* owner,
136 PortID id = InvalidPortID);
137 virtual ~BaseMasterPort();
141 virtual void bind(BaseSlavePort& slave_port) = 0;
142 virtual void unbind() = 0;
143 BaseSlavePort& getSlavePort() const;
144 bool isConnected() const;
149 * A BaseSlavePort is a protocol-agnostic slave port, responsible
150 * only for the structural connection to a master port.
152 class BaseSlavePort : public Port
157 BaseMasterPort* _baseMasterPort;
159 BaseSlavePort(const std::string& name, MemObject* owner,
160 PortID id = InvalidPortID);
161 virtual ~BaseSlavePort();
165 BaseMasterPort& getMasterPort() const;
166 bool isConnected() const;
170 /** Forward declaration */
174 * A MasterPort is a specialisation of a BaseMasterPort, which
175 * implements the default protocol for the three different level of
176 * transport functions. In addition to the basic functionality of
177 * sending packets, it also has functions to receive range changes or
178 * determine if the port is snooping or not.
180 class MasterPort : public BaseMasterPort
183 friend class SlavePort;
187 SlavePort* _slavePort;
191 MasterPort(const std::string& name, MemObject* owner,
192 PortID id = InvalidPortID);
193 virtual ~MasterPort();
196 * Bind this master port to a slave port. This also does the
197 * mirror action and binds the slave port to the master port.
199 void bind(BaseSlavePort& slave_port);
202 * Unbind this master port and the associated slave port.
207 * Send an atomic request packet, where the data is moved and the
208 * state is updated in zero time, without interleaving with other
211 * @param pkt Packet to send.
213 * @return Estimated latency of access.
215 Tick sendAtomic(PacketPtr pkt);
218 * Send a functional request packet, where the data is instantly
219 * updated everywhere in the memory system, without affecting the
220 * current state of any block or moving the block.
222 * @param pkt Packet to send.
224 void sendFunctional(PacketPtr pkt);
227 * Attempt to send a timing request to the slave port by calling
228 * its corresponding receive function. If the send does not
229 * succeed, as indicated by the return value, then the sender must
230 * wait for a recvRetry at which point it can re-issue a
233 * @param pkt Packet to send.
235 * @return If the send was succesful or not.
237 bool sendTimingReq(PacketPtr pkt);
240 * Attempt to send a timing snoop response packet to the slave
241 * port by calling its corresponding receive function. If the send
242 * does not succeed, as indicated by the return value, then the
243 * sender must wait for a recvRetry at which point it can re-issue
244 * a sendTimingSnoopResp.
246 * @param pkt Packet to send.
248 bool sendTimingSnoopResp(PacketPtr pkt);
251 * Send a retry to the slave port that previously attempted a
252 * sendTimingResp to this master port and failed.
254 virtual void sendRetry();
257 * Determine if this master port is snooping or not. The default
258 * implementation returns false and thus tells the neighbour we
259 * are not snooping. Any master port that wants to receive snoop
260 * requests (e.g. a cache connected to a bus) has to override this
263 * @return true if the port should be considered a snooper
265 virtual bool isSnooping() const { return false; }
268 * Get the address ranges of the connected slave port.
270 AddrRangeList getAddrRanges() const;
272 /** Inject a PrintReq for the given address to print the state of
273 * that address throughout the memory system. For debugging.
275 void printAddr(Addr a);
280 * Receive an atomic snoop request packet from the slave port.
282 virtual Tick recvAtomicSnoop(PacketPtr pkt)
284 panic("%s was not expecting an atomic snoop request\n", name());
289 * Receive a functional snoop request packet from the slave port.
291 virtual void recvFunctionalSnoop(PacketPtr pkt)
293 panic("%s was not expecting a functional snoop request\n", name());
297 * Receive a timing response from the slave port.
299 virtual bool recvTimingResp(PacketPtr pkt) = 0;
302 * Receive a timing snoop request from the slave port.
304 virtual void recvTimingSnoopReq(PacketPtr pkt)
306 panic("%s was not expecting a timing snoop request\n", name());
310 * Called by the slave port if sendTimingReq or
311 * sendTimingSnoopResp was called on this master port (causing
312 * recvTimingReq and recvTimingSnoopResp to be called on the
313 * slave port) and was unsuccesful.
315 virtual void recvRetry() = 0;
318 * Called to receive an address range change from the peer slave
319 * port. The default implementation ignores the change and does
320 * nothing. Override this function in a derived class if the owner
321 * needs to be aware of the address ranges, e.g. in an
322 * interconnect component like a bus.
324 virtual void recvRangeChange() { }
328 * A SlavePort is a specialisation of a port. In addition to the
329 * basic functionality of sending packets to its master peer, it also
330 * has functions specific to a slave, e.g. to send range changes
331 * and get the address ranges that the port responds to.
333 class SlavePort : public BaseSlavePort
336 friend class MasterPort;
340 MasterPort* _masterPort;
344 SlavePort(const std::string& name, MemObject* owner,
345 PortID id = InvalidPortID);
346 virtual ~SlavePort();
349 * Send an atomic snoop request packet, where the data is moved
350 * and the state is updated in zero time, without interleaving
351 * with other memory accesses.
353 * @param pkt Snoop packet to send.
355 * @return Estimated latency of access.
357 Tick sendAtomicSnoop(PacketPtr pkt);
360 * Send a functional snoop request packet, where the data is
361 * instantly updated everywhere in the memory system, without
362 * affecting the current state of any block or moving the block.
364 * @param pkt Snoop packet to send.
366 void sendFunctionalSnoop(PacketPtr pkt);
369 * Attempt to send a timing response to the master port by calling
370 * its corresponding receive function. If the send does not
371 * succeed, as indicated by the return value, then the sender must
372 * wait for a recvRetry at which point it can re-issue a
375 * @param pkt Packet to send.
377 * @return If the send was succesful or not.
379 bool sendTimingResp(PacketPtr pkt);
382 * Attempt to send a timing snoop request packet to the master port
383 * by calling its corresponding receive function. Snoop requests
384 * always succeed and hence no return value is needed.
386 * @param pkt Packet to send.
388 void sendTimingSnoopReq(PacketPtr pkt);
391 * Send a retry to the master port that previously attempted a
392 * sendTimingReq or sendTimingSnoopResp to this slave port and
398 * Find out if the peer master port is snooping or not.
400 * @return true if the peer master port is snooping
402 bool isSnooping() const { return _masterPort->isSnooping(); }
405 * Called by the owner to send a range change
407 void sendRangeChange() const { _masterPort->recvRangeChange(); }
410 * Get a list of the non-overlapping address ranges the owner is
411 * responsible for. All slave ports must override this function
412 * and return a populated list with at least one item.
414 * @return a list of ranges responded to
416 virtual AddrRangeList getAddrRanges() const = 0;
421 * Called by the master port to unbind. Should never be called
427 * Called by the master port to bind. Should never be called
430 void bind(MasterPort& master_port);
433 * Receive an atomic request packet from the master port.
435 virtual Tick recvAtomic(PacketPtr pkt) = 0;
438 * Receive a functional request packet from the master port.
440 virtual void recvFunctional(PacketPtr pkt) = 0;
443 * Receive a timing request from the master port.
445 virtual bool recvTimingReq(PacketPtr pkt) = 0;
448 * Receive a timing snoop response from the master port.
450 virtual bool recvTimingSnoopResp(PacketPtr pkt)
452 panic("%s was not expecting a timing snoop response\n", name());
456 * Called by the master port if sendTimingResp was called on this
457 * slave port (causing recvTimingResp to be called on the master
458 * port) and was unsuccesful.
460 virtual void recvRetry() = 0;
464 #endif //__MEM_PORT_HH__