mem-cache: Avoid write merging if there are reads in between
[gem5.git] / src / mem / port.cc
index ab62ccf1d45735a4e23e3d655ec5ea55636c7e46..36e11caec8c9f7c87ecc9abbc260171b7d555a4b 100644 (file)
 #include "mem/port.hh"
 
 #include "base/trace.hh"
-#include "mem/mem_object.hh"
-
-Port::Port(const std::string &_name, PortID _id)
-    : portName(_name), id(_id)
-{
-}
-
-Port::~Port()
-{
-}
-
-BaseMasterPort::BaseMasterPort(const std::string &name, PortID _id)
-    : Port(name, _id), _baseSlavePort(NULL)
-{
-}
-
-BaseMasterPort::~BaseMasterPort()
-{
-}
-
-BaseSlavePort&
-BaseMasterPort::getSlavePort() const
-{
-    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, PortID _id)
-    : Port(name, _id), _baseMasterPort(NULL)
-{
-}
-
-BaseSlavePort::~BaseSlavePort()
-{
-}
-
-BaseMasterPort&
-BaseSlavePort::getMasterPort() const
-{
-    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;
-}
+#include "sim/sim_object.hh"
 
 /**
  * Master port
  */
-MasterPort::MasterPort(const std::string& name, MemObject* _owner, PortID _id)
-    : BaseMasterPort(name, _id), _slavePort(NULL), owner(*_owner)
+MasterPort::MasterPort(const std::string& name, SimObject* _owner, PortID _id)
+    : Port(name, _id), _slavePort(NULL), owner(*_owner)
 {
 }
 
@@ -123,24 +64,18 @@ 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());
     }
+    // master port keeps track of the slave port
+    _slavePort = slave_port;
+    Port::bind(peer);
+    // slave port also keeps track of master port
+    _slavePort->slaveBind(*this);
 }
 
 void
@@ -149,9 +84,9 @@ MasterPort::unbind()
     if (_slavePort == NULL)
         panic("Attempting to unbind master port %s that is not connected\n",
               name());
-    _slavePort->unbind();
-    _slavePort = NULL;
-    _baseSlavePort = NULL;
+    _slavePort->slaveUnbind();
+    _slavePort = nullptr;
+    Port::unbind();
 }
 
 AddrRangeList
@@ -160,47 +95,6 @@ MasterPort::getAddrRanges() const
     return _slavePort->getAddrRanges();
 }
 
-Tick
-MasterPort::sendAtomic(PacketPtr pkt)
-{
-    assert(pkt->isRequest());
-    return _slavePort->recvAtomic(pkt);
-}
-
-void
-MasterPort::sendFunctional(PacketPtr pkt)
-{
-    assert(pkt->isRequest());
-    return _slavePort->recvFunctional(pkt);
-}
-
-bool
-MasterPort::sendTimingReq(PacketPtr pkt)
-{
-    assert(pkt->isRequest());
-    return _slavePort->recvTimingReq(pkt);
-}
-
-bool
-MasterPort::tryTiming(PacketPtr pkt) const
-{
-  assert(pkt->isRequest());
-  return _slavePort->tryTiming(pkt);
-}
-
-bool
-MasterPort::sendTimingSnoopResp(PacketPtr pkt)
-{
-    assert(pkt->isResponse());
-    return _slavePort->recvTimingSnoopResp(pkt);
-}
-
-void
-MasterPort::sendRetryResp()
-{
-    _slavePort->recvRespRetry();
-}
-
 void
 MasterPort::printAddr(Addr a)
 {
@@ -217,8 +111,9 @@ MasterPort::printAddr(Addr a)
 /**
  * Slave port
  */
-SlavePort::SlavePort(const std::string& name, MemObject* _owner, PortID id)
-    : BaseSlavePort(name, id), _masterPort(NULL), owner(*_owner)
+SlavePort::SlavePort(const std::string& name, SimObject* _owner, PortID id)
+    : Port(name, id), _masterPort(NULL), defaultBackdoorWarned(false),
+    owner(*_owner)
 {
 }
 
@@ -227,55 +122,25 @@ SlavePort::~SlavePort()
 }
 
 void
-SlavePort::unbind()
+SlavePort::slaveUnbind()
 {
-    _baseMasterPort = NULL;
     _masterPort = NULL;
+    Port::unbind();
 }
 
 void
-SlavePort::bind(MasterPort& master_port)
+SlavePort::slaveBind(MasterPort& master_port)
 {
-    _baseMasterPort = &master_port;
     _masterPort = &master_port;
+    Port::bind(master_port);
 }
 
 Tick
-SlavePort::sendAtomicSnoop(PacketPtr pkt)
-{
-    assert(pkt->isRequest());
-    return _masterPort->recvAtomicSnoop(pkt);
-}
-
-void
-SlavePort::sendFunctionalSnoop(PacketPtr pkt)
-{
-    assert(pkt->isRequest());
-    return _masterPort->recvFunctionalSnoop(pkt);
-}
-
-bool
-SlavePort::sendTimingResp(PacketPtr pkt)
-{
-    assert(pkt->isResponse());
-    return _masterPort->recvTimingResp(pkt);
-}
-
-void
-SlavePort::sendTimingSnoopReq(PacketPtr pkt)
+SlavePort::recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
 {
-    assert(pkt->isRequest());
-    _masterPort->recvTimingSnoopReq(pkt);
-}
-
-void
-SlavePort::sendRetryReq()
-{
-    _masterPort->recvReqRetry();
-}
-
-void
-SlavePort::sendRetrySnoopResp()
-{
-    _masterPort->recvRetrySnoopResp();
+    if (!defaultBackdoorWarned) {
+        warn("Port %s doesn't support requesting a back door.", name());
+        defaultBackdoorWarned = true;
+    }
+    return recvAtomic(pkt);
 }