mem-cache: Add match functions to QueueEntry
[gem5.git] / src / mem / port.cc
index 898f19c08547c73010a536e335708d1942adc7f7..933e98243947d0798d12ae58516979670314d40a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 ARM Limited
+ * Copyright (c) 2012,2015,2017 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
  * @file
  * Port object definitions.
  */
-#include "base/trace.hh"
-#include "mem/mem_object.hh"
 #include "mem/port.hh"
 
-Port::Port(const std::string &_name, MemObject& _owner, PortID _id)
-    : portName(_name), id(_id), owner(_owner)
-{
-}
-
-Port::~Port()
-{
-}
+#include "base/trace.hh"
+#include "mem/mem_object.hh"
 
-BaseMasterPort::BaseMasterPort(const std::string& name, MemObject* owner,
-                               PortID _id)
-    : Port(name, *owner, _id), _baseSlavePort(NULL)
+BaseMasterPort::BaseMasterPort(const std::string &name, PortID _id)
+    : Port(name, _id), _baseSlavePort(NULL)
 {
 }
 
@@ -72,22 +63,15 @@ BaseMasterPort::~BaseMasterPort()
 BaseSlavePort&
 BaseMasterPort::getSlavePort() const
 {
-    if(_baseSlavePort == NULL)
+    if (_baseSlavePort == NULL)
         panic("Cannot getSlavePort on master port %s that is not connected\n",
               name());
 
     return *_baseSlavePort;
 }
 
-bool
-BaseMasterPort::isConnected() const
-{
-    return _baseSlavePort != NULL;
-}
-
-BaseSlavePort::BaseSlavePort(const std::string& name, MemObject* owner,
-                             PortID _id)
-    : Port(name, *owner, _id), _baseMasterPort(NULL)
+BaseSlavePort::BaseSlavePort(const std::string &name, PortID _id)
+    : Port(name, _id), _baseMasterPort(NULL)
 {
 }
 
@@ -98,24 +82,18 @@ BaseSlavePort::~BaseSlavePort()
 BaseMasterPort&
 BaseSlavePort::getMasterPort() const
 {
-    if(_baseMasterPort == NULL)
+    if (_baseMasterPort == NULL)
         panic("Cannot getMasterPort on slave port %s that is not connected\n",
               name());
 
     return *_baseMasterPort;
 }
 
-bool
-BaseSlavePort::isConnected() const
-{
-    return _baseMasterPort != NULL;
-}
-
 /**
  * Master port
  */
-MasterPort::MasterPort(const std::string& name, MemObject* owner, PortID _id)
-    : BaseMasterPort(name, owner, _id), _slavePort(NULL)
+MasterPort::MasterPort(const std::string& name, MemObject* _owner, PortID _id)
+    : BaseMasterPort(name, _id), _slavePort(NULL), owner(*_owner)
 {
 }
 
@@ -124,24 +102,21 @@ MasterPort::~MasterPort()
 }
 
 void
-MasterPort::bind(BaseSlavePort& slave_port)
+MasterPort::bind(Port &peer)
 {
-    // bind on the level of the base ports
-    _baseSlavePort = &slave_port;
-
-    // also attempt to base the slave to the appropriate type
-    SlavePort* cast_slave_port = dynamic_cast<SlavePort*>(&slave_port);
-
-    // if this port is compatible, then proceed with the binding
-    if (cast_slave_port != NULL) {
-        // master port keeps track of the slave port
-        _slavePort = cast_slave_port;
-        // slave port also keeps track of master port
-        _slavePort->bind(*this);
-    } else {
-        fatal("Master port %s cannot bind to %s\n", name(),
-              slave_port.name());
+    auto *slave_port = dynamic_cast<SlavePort *>(&peer);
+    if (!slave_port) {
+        fatal("Attempt to bind port %s to non-slave port %s.",
+                name(), peer.name());
     }
+    // bind on the level of the base ports
+    _baseSlavePort = slave_port;
+
+    // master port keeps track of the slave port
+    _slavePort = slave_port;
+    _connected = true;
+    // slave port also keeps track of master port
+    _slavePort->slaveBind(*this);
 }
 
 void
@@ -150,8 +125,9 @@ MasterPort::unbind()
     if (_slavePort == NULL)
         panic("Attempting to unbind master port %s that is not connected\n",
               name());
-    _slavePort->unbind();
+    _slavePort->slaveUnbind();
     _slavePort = NULL;
+    _connected = false;
     _baseSlavePort = NULL;
 }
 
@@ -168,6 +144,13 @@ MasterPort::sendAtomic(PacketPtr pkt)
     return _slavePort->recvAtomic(pkt);
 }
 
+Tick
+MasterPort::sendAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
+{
+    assert(pkt->isRequest());
+    return _slavePort->recvAtomicBackdoor(pkt, backdoor);
+}
+
 void
 MasterPort::sendFunctional(PacketPtr pkt)
 {
@@ -182,6 +165,13 @@ MasterPort::sendTimingReq(PacketPtr pkt)
     return _slavePort->recvTimingReq(pkt);
 }
 
+bool
+MasterPort::tryTiming(PacketPtr pkt) const
+{
+  assert(pkt->isRequest());
+  return _slavePort->tryTiming(pkt);
+}
+
 bool
 MasterPort::sendTimingSnoopResp(PacketPtr pkt)
 {
@@ -190,16 +180,18 @@ MasterPort::sendTimingSnoopResp(PacketPtr pkt)
 }
 
 void
-MasterPort::sendRetry()
+MasterPort::sendRetryResp()
 {
-    _slavePort->recvRetry();
+    _slavePort->recvRespRetry();
 }
 
 void
 MasterPort::printAddr(Addr a)
 {
-    Request req(a, 1, 0, Request::funcMasterId);
-    Packet pkt(&req, MemCmd::PrintReq);
+    auto req = std::make_shared<Request>(
+        a, 1, 0, Request::funcMasterId);
+
+    Packet pkt(req, MemCmd::PrintReq);
     Packet::PrintReqState prs(std::cerr);
     pkt.senderState = &prs;
 
@@ -209,8 +201,9 @@ MasterPort::printAddr(Addr a)
 /**
  * Slave port
  */
-SlavePort::SlavePort(const std::string& name, MemObject* owner, PortID id)
-    : BaseSlavePort(name, owner, id), _masterPort(NULL)
+SlavePort::SlavePort(const std::string& name, MemObject* _owner, PortID id)
+    : BaseSlavePort(name, id), _masterPort(NULL), defaultBackdoorWarned(false),
+    owner(*_owner)
 {
 }
 
@@ -219,17 +212,29 @@ SlavePort::~SlavePort()
 }
 
 void
-SlavePort::unbind()
+SlavePort::slaveUnbind()
 {
     _baseMasterPort = NULL;
     _masterPort = NULL;
+    _connected = false;
 }
 
 void
-SlavePort::bind(MasterPort& master_port)
+SlavePort::slaveBind(MasterPort& master_port)
 {
     _baseMasterPort = &master_port;
     _masterPort = &master_port;
+    _connected = true;
+}
+
+Tick
+SlavePort::recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
+{
+    if (!defaultBackdoorWarned) {
+        warn("Port %s doesn't support requesting a back door.", name());
+        defaultBackdoorWarned = true;
+    }
+    return recvAtomic(pkt);
 }
 
 Tick
@@ -261,7 +266,13 @@ SlavePort::sendTimingSnoopReq(PacketPtr pkt)
 }
 
 void
-SlavePort::sendRetry()
+SlavePort::sendRetryReq()
+{
+    _masterPort->recvReqRetry();
+}
+
+void
+SlavePort::sendRetrySnoopResp()
 {
-    _masterPort->recvRetry();
+    _masterPort->recvRetrySnoopResp();
 }