2 * Copyright (c) 2011-2012,2015,2017 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/backdoor.hh"
55 #include "mem/packet.hh"
56 #include "sim/port.hh"
60 /** Forward declaration */
64 * A BaseMasterPort is a protocol-agnostic master port, responsible
65 * only for the structural connection to a slave port. The final
66 * master port that inherits from the base class must override the
67 * bind member function for the specific slave port class.
69 class BaseMasterPort : public Port
74 BaseSlavePort* _baseSlavePort;
76 BaseMasterPort(const std::string& name, PortID id=InvalidPortID);
77 virtual ~BaseMasterPort();
81 BaseSlavePort& getSlavePort() const;
86 * A BaseSlavePort is a protocol-agnostic slave port, responsible
87 * only for the structural connection to a master port.
89 class BaseSlavePort : public Port
94 BaseMasterPort* _baseMasterPort;
96 BaseSlavePort(const std::string& name, PortID id=InvalidPortID);
97 virtual ~BaseSlavePort();
101 BaseMasterPort& getMasterPort() const;
105 /** Forward declaration */
109 * A MasterPort is a specialisation of a BaseMasterPort, which
110 * implements the default protocol for the three different level of
111 * transport functions. In addition to the basic functionality of
112 * sending packets, it also has functions to receive range changes or
113 * determine if the port is snooping or not.
115 class MasterPort : public BaseMasterPort
118 friend class SlavePort;
122 SlavePort* _slavePort;
130 MasterPort(const std::string& name, MemObject* _owner,
131 PortID id=InvalidPortID);
132 virtual ~MasterPort();
135 * Bind this master port to a slave port. This also does the
136 * mirror action and binds the slave port to the master port.
138 void bind(Port &peer) override;
141 * Unbind this master port and the associated slave port.
143 void unbind() override;
146 * Send an atomic request packet, where the data is moved and the
147 * state is updated in zero time, without interleaving with other
150 * @param pkt Packet to send.
152 * @return Estimated latency of access.
154 Tick sendAtomic(PacketPtr pkt);
157 * Send an atomic request packet like above, but also request a backdoor
158 * to the data being accessed.
160 * @param pkt Packet to send.
161 * @param backdoor Can be set to a back door pointer by the target to let
162 * caller have direct access to the requested data.
164 * @return Estimated latency of access.
166 Tick sendAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor);
169 * Send a functional request packet, where the data is instantly
170 * updated everywhere in the memory system, without affecting the
171 * current state of any block or moving the block.
173 * @param pkt Packet to send.
175 void sendFunctional(PacketPtr pkt);
178 * Attempt to send a timing request to the slave port by calling
179 * its corresponding receive function. If the send does not
180 * succeed, as indicated by the return value, then the sender must
181 * wait for a recvReqRetry at which point it can re-issue a
184 * @param pkt Packet to send.
186 * @return If the send was succesful or not.
188 bool sendTimingReq(PacketPtr pkt);
191 * Check if the slave can handle a timing request.
193 * If the send cannot be handled at the moment, as indicated by
194 * the return value, then the sender will receive a recvReqRetry
195 * at which point it can re-issue a sendTimingReq.
197 * @param pkt Packet to send.
199 * @return If the send was succesful or not.
201 bool tryTiming(PacketPtr pkt) const;
204 * Attempt to send a timing snoop response packet to the slave
205 * port by calling its corresponding receive function. If the send
206 * does not succeed, as indicated by the return value, then the
207 * sender must wait for a recvRetrySnoop at which point it can
208 * re-issue a sendTimingSnoopResp.
210 * @param pkt Packet to send.
212 bool sendTimingSnoopResp(PacketPtr pkt);
215 * Send a retry to the slave port that previously attempted a
216 * sendTimingResp to this master port and failed. Note that this
217 * is virtual so that the "fake" snoop response port in the
218 * coherent crossbar can override the behaviour.
220 virtual void sendRetryResp();
223 * Determine if this master port is snooping or not. The default
224 * implementation returns false and thus tells the neighbour we
225 * are not snooping. Any master port that wants to receive snoop
226 * requests (e.g. a cache connected to a bus) has to override this
229 * @return true if the port should be considered a snooper
231 virtual bool isSnooping() const { return false; }
234 * Get the address ranges of the connected slave port.
236 AddrRangeList getAddrRanges() const;
238 /** Inject a PrintReq for the given address to print the state of
239 * that address throughout the memory system. For debugging.
241 void printAddr(Addr a);
246 * Receive an atomic snoop request packet from the slave port.
248 virtual Tick recvAtomicSnoop(PacketPtr pkt)
250 panic("%s was not expecting an atomic snoop request\n", name());
255 * Receive a functional snoop request packet from the slave port.
257 virtual void recvFunctionalSnoop(PacketPtr pkt)
259 panic("%s was not expecting a functional snoop request\n", name());
263 * Receive a timing response from the slave port.
265 virtual bool recvTimingResp(PacketPtr pkt) = 0;
268 * Receive a timing snoop request from the slave port.
270 virtual void recvTimingSnoopReq(PacketPtr pkt)
272 panic("%s was not expecting a timing snoop request\n", name());
276 * Called by the slave port if sendTimingReq was called on this
277 * master port (causing recvTimingReq to be called on the slave
278 * port) and was unsuccesful.
280 virtual void recvReqRetry() = 0;
283 * Called by the slave port if sendTimingSnoopResp was called on this
284 * master port (causing recvTimingSnoopResp to be called on the slave
285 * port) and was unsuccesful.
287 virtual void recvRetrySnoopResp()
289 panic("%s was not expecting a snoop retry\n", name());
293 * Called to receive an address range change from the peer slave
294 * port. The default implementation ignores the change and does
295 * nothing. Override this function in a derived class if the owner
296 * needs to be aware of the address ranges, e.g. in an
297 * interconnect component like a bus.
299 virtual void recvRangeChange() { }
303 * A SlavePort is a specialisation of a port. In addition to the
304 * basic functionality of sending packets to its master peer, it also
305 * has functions specific to a slave, e.g. to send range changes
306 * and get the address ranges that the port responds to.
308 class SlavePort : public BaseSlavePort
311 friend class MasterPort;
315 MasterPort* _masterPort;
316 bool defaultBackdoorWarned;
324 SlavePort(const std::string& name, MemObject* _owner,
325 PortID id=InvalidPortID);
326 virtual ~SlavePort();
329 * Send an atomic snoop request packet, where the data is moved
330 * and the state is updated in zero time, without interleaving
331 * with other memory accesses.
333 * @param pkt Snoop packet to send.
335 * @return Estimated latency of access.
337 Tick sendAtomicSnoop(PacketPtr pkt);
340 * Send a functional snoop request packet, where the data is
341 * instantly updated everywhere in the memory system, without
342 * affecting the current state of any block or moving the block.
344 * @param pkt Snoop packet to send.
346 void sendFunctionalSnoop(PacketPtr pkt);
349 * Attempt to send a timing response to the master port by calling
350 * its corresponding receive function. If the send does not
351 * succeed, as indicated by the return value, then the sender must
352 * wait for a recvRespRetry at which point it can re-issue a
355 * @param pkt Packet to send.
357 * @return If the send was succesful or not.
359 bool sendTimingResp(PacketPtr pkt);
362 * Attempt to send a timing snoop request packet to the master port
363 * by calling its corresponding receive function. Snoop requests
364 * always succeed and hence no return value is needed.
366 * @param pkt Packet to send.
368 void sendTimingSnoopReq(PacketPtr pkt);
371 * Send a retry to the master port that previously attempted a
372 * sendTimingReq to this slave port and failed.
377 * Send a retry to the master port that previously attempted a
378 * sendTimingSnoopResp to this slave port and failed.
380 void sendRetrySnoopResp();
383 * Find out if the peer master port is snooping or not.
385 * @return true if the peer master port is snooping
387 bool isSnooping() const { return _masterPort->isSnooping(); }
390 * Called by the owner to send a range change
392 void sendRangeChange() const {
394 fatal("%s cannot sendRangeChange() without master port", name());
395 _masterPort->recvRangeChange();
399 * Get a list of the non-overlapping address ranges the owner is
400 * responsible for. All slave ports must override this function
401 * and return a populated list with at least one item.
403 * @return a list of ranges responded to
405 virtual AddrRangeList getAddrRanges() const = 0;
408 * We let the master port do the work, so these don't do anything.
410 void unbind() override {}
411 void bind(Port &peer) override {}
416 * Called by the master port to unbind. Should never be called
422 * Called by the master port to bind. Should never be called
425 void slaveBind(MasterPort& master_port);
428 * Receive an atomic request packet from the master port.
430 virtual Tick recvAtomic(PacketPtr pkt) = 0;
433 * Receive an atomic request packet from the master port, and optionally
434 * provide a backdoor to the data being accessed.
436 virtual Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor);
439 * Receive a functional request packet from the master port.
441 virtual void recvFunctional(PacketPtr pkt) = 0;
444 * Receive a timing request from the master port.
446 virtual bool recvTimingReq(PacketPtr pkt) = 0;
449 * Availability request from the master port.
451 virtual bool tryTiming(PacketPtr pkt) {
452 panic("%s was not expecting a %s\n", name(), __func__);
456 * Receive a timing snoop response from the master port.
458 virtual bool recvTimingSnoopResp(PacketPtr pkt)
460 panic("%s was not expecting a timing snoop response\n", name());
464 * Called by the master port if sendTimingResp was called on this
465 * slave port (causing recvTimingResp to be called on the master
466 * port) and was unsuccesful.
468 virtual void recvRespRetry() = 0;
472 #endif //__MEM_PORT_HH__