diff options
author | Gabe Black <gabeblack@google.com> | 2019-03-07 01:32:54 -0800 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2019-03-19 10:21:46 +0000 |
commit | 7f1458bec4ae3ea3fb5f0948f0323355e1f20512 (patch) | |
tree | 4bdf685549971f6bd5b56e8049092f88a526f09d /src/mem/port.cc | |
parent | 8e89366ada0213d45af088945406c82187b5014a (diff) | |
download | gem5-7f1458bec4ae3ea3fb5f0948f0323355e1f20512.tar.xz |
mem: Move bind() and unbind() into the Port class.
These are now pure virtual methods which more specialized port
subclasses will need to implement. The SlavePort class implements them
by ignoring them and then providing parallel functions for the
MasterPort to call. The MasterPort's methods do basically what they
did before, except now bind() uses dynamic cast to check if its peer
is of the appropriate type and also to convert it into that type before
connecting to it.
Change-Id: I0948799bc954acaebf371e6b6612cee1d3023bc4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17038
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/mem/port.cc')
-rw-r--r-- | src/mem/port.cc | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/src/mem/port.cc b/src/mem/port.cc index 6f72bbd38..001576fe3 100644 --- a/src/mem/port.cc +++ b/src/mem/port.cc @@ -70,12 +70,6 @@ BaseMasterPort::getSlavePort() const return *_baseSlavePort; } -bool -BaseMasterPort::isConnected() const -{ - return _baseSlavePort != NULL; -} - BaseSlavePort::BaseSlavePort(const std::string &name, PortID _id) : Port(name, _id), _baseMasterPort(NULL) { @@ -95,12 +89,6 @@ BaseSlavePort::getMasterPort() const return *_baseMasterPort; } -bool -BaseSlavePort::isConnected() const -{ - return _baseMasterPort != NULL; -} - /** * Master port */ @@ -114,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 @@ -140,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; } @@ -218,17 +204,19 @@ 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 |