mem-cache: Avoid hiding a virtual method in the dictionary compressor.
[gem5.git] / src / mem / port.cc
index 4b7b040cbdd647668de1d6830340a69038b36a64..36e11caec8c9f7c87ecc9abbc260171b7d555a4b 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)
-    : portName(_name), peer(NULL), owner(_owner)
-{
-}
-
-Port::~Port()
-{
-}
+#include "base/trace.hh"
+#include "sim/sim_object.hh"
 
 /**
  * Master port
  */
-MasterPort::MasterPort(const std::string& name, MemObject* owner)
-    : Port(name, *owner), _slavePort(NULL)
+MasterPort::MasterPort(const std::string& name, SimObject* _owner, PortID _id)
+    : Port(name, _id), _slavePort(NULL), owner(*_owner)
 {
 }
 
@@ -71,56 +63,45 @@ MasterPort::~MasterPort()
 {
 }
 
-SlavePort&
-MasterPort::getSlavePort() const
-{
-    if(_slavePort == NULL)
-        panic("Cannot getSlavePort on master port %s that is not connected\n",
-              name());
-
-    return *_slavePort;
-}
-
 void
-MasterPort::bind(SlavePort& slave_port)
+MasterPort::bind(Port &peer)
 {
+    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;
-    peer = &slave_port;
-
+    _slavePort = slave_port;
+    Port::bind(peer);
     // slave port also keeps track of master port
-    _slavePort->bind(*this);
-}
-
-bool
-MasterPort::isConnected() const
-{
-    return _slavePort != NULL;
+    _slavePort->slaveBind(*this);
 }
 
-unsigned
-MasterPort::peerBlockSize() const
-{
-    return _slavePort->deviceBlockSize();
-}
-
-Tick
-MasterPort::sendAtomic(PacketPtr pkt)
+void
+MasterPort::unbind()
 {
-    return _slavePort->recvAtomic(pkt);
+    if (_slavePort == NULL)
+        panic("Attempting to unbind master port %s that is not connected\n",
+              name());
+    _slavePort->slaveUnbind();
+    _slavePort = nullptr;
+    Port::unbind();
 }
 
-void
-MasterPort::sendFunctional(PacketPtr pkt)
+AddrRangeList
+MasterPort::getAddrRanges() const
 {
-    return _slavePort->recvFunctional(pkt);
+    return _slavePort->getAddrRanges();
 }
 
 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;
 
@@ -130,8 +111,9 @@ MasterPort::printAddr(Addr a)
 /**
  * Slave port
  */
-SlavePort::SlavePort(const std::string& name, MemObject* owner)
-    : Port(name, *owner), _masterPort(NULL)
+SlavePort::SlavePort(const std::string& name, SimObject* _owner, PortID id)
+    : Port(name, id), _masterPort(NULL), defaultBackdoorWarned(false),
+    owner(*_owner)
 {
 }
 
@@ -140,42 +122,25 @@ SlavePort::~SlavePort()
 }
 
 void
-SlavePort::bind(MasterPort& master_port)
-{
-    _masterPort = &master_port;
-    peer = &master_port;
-}
-
-MasterPort&
-SlavePort::getMasterPort() const
+SlavePort::slaveUnbind()
 {
-    if (_masterPort == NULL)
-        panic("Cannot getMasterPort on slave port %s that is not connected\n",
-              name());
-
-    return *_masterPort;
+    _masterPort = NULL;
+    Port::unbind();
 }
 
-unsigned
-SlavePort::peerBlockSize() const
-{
-    return _masterPort->deviceBlockSize();
-}
-
-bool
-SlavePort::isConnected() const
+void
+SlavePort::slaveBind(MasterPort& master_port)
 {
-    return _masterPort != NULL;
+    _masterPort = &master_port;
+    Port::bind(master_port);
 }
 
 Tick
-SlavePort::sendAtomicSnoop(PacketPtr pkt)
-{
-    return _masterPort->recvAtomicSnoop(pkt);
-}
-
-void
-SlavePort::sendFunctionalSnoop(PacketPtr pkt)
+SlavePort::recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor)
 {
-    return _masterPort->recvFunctionalSnoop(pkt);
+    if (!defaultBackdoorWarned) {
+        warn("Port %s doesn't support requesting a back door.", name());
+        defaultBackdoorWarned = true;
+    }
+    return recvAtomic(pkt);
 }