summaryrefslogtreecommitdiff
path: root/src/mem/port.cc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-08-16 15:27:35 -0700
committerGabe Black <gabeblack@google.com>2019-08-27 22:17:45 +0000
commit2a566b4fa7fbd805746d598d0ffc096c2710cef9 (patch)
tree12c10fb70e8151a81eafefae2e4a5efdf3c63ef3 /src/mem/port.cc
parent3126e84db773f64e46b1d02a9a27892bf6612d30 (diff)
downloadgem5-2a566b4fa7fbd805746d598d0ffc096c2710cef9.tar.xz
mem, sim, systemc: Reorganize Port and co.s bind, unbind slightly.
The base Port class can keep track of its peer, and also whether it's connected. This is partially delegated away from the port subclasses which still keep track of a cast version of their peer pointer for their own conveneince, so that it can be used by generic code. Even with the Port mechanism's new flexibility, each port still has exactly one peer and is either connected or not based on whether there is a peer currently. Change-Id: Id3228617dd1604d196814254a1aadeac5ade7cde Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20232 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/mem/port.cc')
-rw-r--r--src/mem/port.cc48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/mem/port.cc b/src/mem/port.cc
index 40481b0bb..303d1bc41 100644
--- a/src/mem/port.cc
+++ b/src/mem/port.cc
@@ -70,6 +70,22 @@ BaseMasterPort::getSlavePort() const
return *_baseSlavePort;
}
+void
+BaseMasterPort::bind(Port &peer)
+{
+ _baseSlavePort = dynamic_cast<BaseSlavePort *>(&peer);
+ fatal_if(!_baseSlavePort, "Attempt to bind port %s to non-master port %s.",
+ name(), peer.name());
+ Port::bind(peer);
+}
+
+void
+BaseMasterPort::unbind()
+{
+ _baseSlavePort = nullptr;
+ Port::unbind();
+}
+
BaseSlavePort::BaseSlavePort(const std::string &name, PortID _id)
: Port(name, _id), _baseMasterPort(NULL)
{
@@ -89,6 +105,22 @@ BaseSlavePort::getMasterPort() const
return *_baseMasterPort;
}
+void
+BaseSlavePort::bind(Port &peer)
+{
+ _baseMasterPort = dynamic_cast<BaseMasterPort *>(&peer);
+ fatal_if(!_baseMasterPort, "Attempt to bind port %s to non-slave port %s.",
+ name(), peer.name());
+ Port::bind(peer);
+}
+
+void
+BaseSlavePort::unbind()
+{
+ _baseMasterPort = nullptr;
+ Port::unbind();
+}
+
/**
* Master port
*/
@@ -109,12 +141,9 @@ MasterPort::bind(Port &peer)
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;
+ BaseMasterPort::bind(peer);
// slave port also keeps track of master port
_slavePort->slaveBind(*this);
}
@@ -126,9 +155,8 @@ MasterPort::unbind()
panic("Attempting to unbind master port %s that is not connected\n",
name());
_slavePort->slaveUnbind();
- _slavePort = NULL;
- _connected = false;
- _baseSlavePort = NULL;
+ _slavePort = nullptr;
+ BaseMasterPort::unbind();
}
AddrRangeList
@@ -166,17 +194,15 @@ SlavePort::~SlavePort()
void
SlavePort::slaveUnbind()
{
- _baseMasterPort = NULL;
_masterPort = NULL;
- _connected = false;
+ BaseSlavePort::unbind();
}
void
SlavePort::slaveBind(MasterPort& master_port)
{
- _baseMasterPort = &master_port;
_masterPort = &master_port;
- _connected = true;
+ BaseSlavePort::bind(master_port);
}
Tick