2 * Copyright (c) 2011-2012,2015 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__
53 #include "base/addr_range.hh"
54 #include "mem/packet.hh"
59 * Ports are used to interface memory objects to each other. A port is
60 * either a master or a slave and the connected peer is always of the
61 * opposite role. Each port has a name, an owner, and an identifier.
68 /** Descriptive name (for DPRINTF output) */
74 * A numeric identifier to distinguish ports in a vector, and set
75 * to InvalidPortID in case this port is not part of a vector.
79 /** A reference to the MemObject that owns this port. */
83 * Abstract base class for ports
85 * @param _name Port name including the owners name
86 * @param _owner The MemObject that is the structural owner of this port
87 * @param _id A port identifier for vector ports
89 Port(const std::string& _name, MemObject& _owner, PortID _id);
92 * Virtual destructor due to inheritance.
98 /** Return port name (for DPRINTF). */
99 const std::string name() const { return portName; }
101 /** Get the port id. */
102 PortID getId() const { return id; }
106 /** Forward declaration */
110 * A BaseMasterPort is a protocol-agnostic master port, responsible
111 * only for the structural connection to a slave port. The final
112 * master port that inherits from the base class must override the
113 * bind member function for the specific slave port class.
115 class BaseMasterPort : public Port
120 BaseSlavePort* _baseSlavePort;
122 BaseMasterPort(const std::string& name, MemObject* owner,
123 PortID id = InvalidPortID);
124 virtual ~BaseMasterPort();
128 virtual void bind(BaseSlavePort& slave_port) = 0;
129 virtual void unbind() = 0;
130 BaseSlavePort& getSlavePort() const;
131 bool isConnected() const;
136 * A BaseSlavePort is a protocol-agnostic slave port, responsible
137 * only for the structural connection to a master port.
139 class BaseSlavePort : public Port
144 BaseMasterPort* _baseMasterPort;
146 BaseSlavePort(const std::string& name, MemObject* owner,
147 PortID id = InvalidPortID);
148 virtual ~BaseSlavePort();
152 BaseMasterPort& getMasterPort() const;
153 bool isConnected() const;
157 /** Forward declaration */
161 * A MasterPort is a specialisation of a BaseMasterPort, which
162 * implements the default protocol for the three different level of
163 * transport functions. In addition to the basic functionality of
164 * sending packets, it also has functions to receive range changes or
165 * determine if the port is snooping or not.
167 class MasterPort : public BaseMasterPort
170 friend class SlavePort;
174 SlavePort* _slavePort;
178 MasterPort(const std::string& name, MemObject* owner,
179 PortID id = InvalidPortID);
180 virtual ~MasterPort();
183 * Bind this master port to a slave port. This also does the
184 * mirror action and binds the slave port to the master port.
186 void bind(BaseSlavePort& slave_port);
189 * Unbind this master port and the associated slave port.
194 * Send an atomic request packet, where the data is moved and the
195 * state is updated in zero time, without interleaving with other
198 * @param pkt Packet to send.
200 * @return Estimated latency of access.
202 Tick sendAtomic(PacketPtr pkt);
205 * Send a functional request packet, where the data is instantly
206 * updated everywhere in the memory system, without affecting the
207 * current state of any block or moving the block.
209 * @param pkt Packet to send.
211 void sendFunctional(PacketPtr pkt);
214 * Attempt to send a timing request to the slave port by calling
215 * its corresponding receive function. If the send does not
216 * succeed, as indicated by the return value, then the sender must
217 * wait for a recvReqRetry at which point it can re-issue a
220 * @param pkt Packet to send.
222 * @return If the send was succesful or not.
224 bool sendTimingReq(PacketPtr pkt);
227 * Attempt to send a timing snoop response packet to the slave
228 * port by calling its corresponding receive function. If the send
229 * does not succeed, as indicated by the return value, then the
230 * sender must wait for a recvRetrySnoop at which point it can
231 * re-issue a sendTimingSnoopResp.
233 * @param pkt Packet to send.
235 bool sendTimingSnoopResp(PacketPtr pkt);
238 * Send a retry to the slave port that previously attempted a
239 * sendTimingResp to this master port and failed. Note that this
240 * is virtual so that the "fake" snoop response port in the
241 * coherent crossbar can override the behaviour.
243 virtual void sendRetryResp();
246 * Determine if this master port is snooping or not. The default
247 * implementation returns false and thus tells the neighbour we
248 * are not snooping. Any master port that wants to receive snoop
249 * requests (e.g. a cache connected to a bus) has to override this
252 * @return true if the port should be considered a snooper
254 virtual bool isSnooping() const { return false; }
257 * Get the address ranges of the connected slave port.
259 AddrRangeList getAddrRanges() const;
261 /** Inject a PrintReq for the given address to print the state of
262 * that address throughout the memory system. For debugging.
264 void printAddr(Addr a);
269 * Receive an atomic snoop request packet from the slave port.
271 virtual Tick recvAtomicSnoop(PacketPtr pkt)
273 panic("%s was not expecting an atomic snoop request\n", name());
278 * Receive a functional snoop request packet from the slave port.
280 virtual void recvFunctionalSnoop(PacketPtr pkt)
282 panic("%s was not expecting a functional snoop request\n", name());
286 * Receive a timing response from the slave port.
288 virtual bool recvTimingResp(PacketPtr pkt) = 0;
291 * Receive a timing snoop request from the slave port.
293 virtual void recvTimingSnoopReq(PacketPtr pkt)
295 panic("%s was not expecting a timing snoop request\n", name());
299 * Called by the slave port if sendTimingReq was called on this
300 * master port (causing recvTimingReq to be called on the slave
301 * port) and was unsuccesful.
303 virtual void recvReqRetry() = 0;
306 * Called by the slave port if sendTimingSnoopResp was called on this
307 * master port (causing recvTimingSnoopResp to be called on the slave
308 * port) and was unsuccesful.
310 virtual void recvRetrySnoopResp()
312 panic("%s was not expecting a snoop retry\n", name());
316 * Called to receive an address range change from the peer slave
317 * port. The default implementation ignores the change and does
318 * nothing. Override this function in a derived class if the owner
319 * needs to be aware of the address ranges, e.g. in an
320 * interconnect component like a bus.
322 virtual void recvRangeChange() { }
326 * A SlavePort is a specialisation of a port. In addition to the
327 * basic functionality of sending packets to its master peer, it also
328 * has functions specific to a slave, e.g. to send range changes
329 * and get the address ranges that the port responds to.
331 class SlavePort : public BaseSlavePort
334 friend class MasterPort;
338 MasterPort* _masterPort;
342 SlavePort(const std::string& name, MemObject* owner,
343 PortID id = InvalidPortID);
344 virtual ~SlavePort();
347 * Send an atomic snoop request packet, where the data is moved
348 * and the state is updated in zero time, without interleaving
349 * with other memory accesses.
351 * @param pkt Snoop packet to send.
353 * @return Estimated latency of access.
355 Tick sendAtomicSnoop(PacketPtr pkt);
358 * Send a functional snoop request packet, where the data is
359 * instantly updated everywhere in the memory system, without
360 * affecting the current state of any block or moving the block.
362 * @param pkt Snoop packet to send.
364 void sendFunctionalSnoop(PacketPtr pkt);
367 * Attempt to send a timing response to the master port by calling
368 * its corresponding receive function. If the send does not
369 * succeed, as indicated by the return value, then the sender must
370 * wait for a recvRespRetry at which point it can re-issue a
373 * @param pkt Packet to send.
375 * @return If the send was succesful or not.
377 bool sendTimingResp(PacketPtr pkt);
380 * Attempt to send a timing snoop request packet to the master port
381 * by calling its corresponding receive function. Snoop requests
382 * always succeed and hence no return value is needed.
384 * @param pkt Packet to send.
386 void sendTimingSnoopReq(PacketPtr pkt);
389 * Send a retry to the master port that previously attempted a
390 * sendTimingReq to this slave port and failed.
395 * Send a retry to the master port that previously attempted a
396 * sendTimingSnoopResp to this slave port and failed.
398 void sendRetrySnoopResp();
401 * Find out if the peer master port is snooping or not.
403 * @return true if the peer master port is snooping
405 bool isSnooping() const { return _masterPort->isSnooping(); }
408 * Called by the owner to send a range change
410 void sendRangeChange() const {
412 fatal("%s cannot sendRangeChange() without master port", name());
413 _masterPort->recvRangeChange();
417 * Get a list of the non-overlapping address ranges the owner is
418 * responsible for. All slave ports must override this function
419 * and return a populated list with at least one item.
421 * @return a list of ranges responded to
423 virtual AddrRangeList getAddrRanges() const = 0;
428 * Called by the master port to unbind. Should never be called
434 * Called by the master port to bind. Should never be called
437 void bind(MasterPort& master_port);
440 * Receive an atomic request packet from the master port.
442 virtual Tick recvAtomic(PacketPtr pkt) = 0;
445 * Receive a functional request packet from the master port.
447 virtual void recvFunctional(PacketPtr pkt) = 0;
450 * Receive a timing request from the master port.
452 virtual bool recvTimingReq(PacketPtr pkt) = 0;
455 * Receive a timing snoop response from the master port.
457 virtual bool recvTimingSnoopResp(PacketPtr pkt)
459 panic("%s was not expecting a timing snoop response\n", name());
463 * Called by the master port if sendTimingResp was called on this
464 * slave port (causing recvTimingResp to be called on the master
465 * port) and was unsuccesful.
467 virtual void recvRespRetry() = 0;
471 #endif //__MEM_PORT_HH__