summaryrefslogtreecommitdiff
path: root/src/mem/port.cc
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2012-10-15 08:12:35 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2012-10-15 08:12:35 -0400
commit2a740aa09682c32eb8f1f8880f279c943d8c6ee1 (patch)
tree61ca1dcb9336bc1f4dbc791c876875c1c260ca8d /src/mem/port.cc
parent9baa35ba802f2cfb9fb9ecdebf111f4cd793a428 (diff)
downloadgem5-2a740aa09682c32eb8f1f8880f279c943d8c6ee1.tar.xz
Port: Add protocol-agnostic ports in the port hierarchy
This patch adds an additional level of ports in the inheritance hierarchy, separating out the protocol-specific and protocl-agnostic parts. All the functionality related to the binding of ports is now confined to use BaseMaster/BaseSlavePorts, and all the protocol-specific parts stay in the Master/SlavePort. In the future it will be possible to add other protocol-specific implementations. The functions used in the binding of ports, i.e. getMaster/SlavePort now use the base classes, and the index parameter is updated to use the PortID typedef with the symbolic InvalidPortID as the default.
Diffstat (limited to 'src/mem/port.cc')
-rw-r--r--src/mem/port.cc120
1 files changed, 75 insertions, 45 deletions
diff --git a/src/mem/port.cc b/src/mem/port.cc
index 9b65da756..45045f40e 100644
--- a/src/mem/port.cc
+++ b/src/mem/port.cc
@@ -59,56 +59,100 @@ Port::~Port()
{
}
-/**
- * Master port
- */
-MasterPort::MasterPort(const std::string& name, MemObject* owner, PortID _id)
- : Port(name, *owner, _id), _slavePort(NULL)
+BaseMasterPort::BaseMasterPort(const std::string& name, MemObject* owner,
+ PortID _id)
+ : Port(name, *owner, _id), _baseSlavePort(NULL)
{
}
-MasterPort::~MasterPort()
+BaseMasterPort::~BaseMasterPort()
{
}
-SlavePort&
-MasterPort::getSlavePort() const
+BaseSlavePort&
+BaseMasterPort::getSlavePort() const
{
- if(_slavePort == NULL)
+ if(_baseSlavePort == NULL)
panic("Cannot getSlavePort on master port %s that is not connected\n",
name());
- return *_slavePort;
+ return *_baseSlavePort;
}
-void
-MasterPort::unbind()
+bool
+BaseMasterPort::isConnected() const
{
- if (_slavePort == NULL)
- panic("Attempting to unbind master port %s that is not connected\n",
- name());
- _slavePort->unbind();
- _slavePort = NULL;
+ return _baseSlavePort != NULL;
}
-void
-MasterPort::bind(SlavePort& slave_port)
+BaseSlavePort::BaseSlavePort(const std::string& name, MemObject* owner,
+ PortID _id)
+ : Port(name, *owner, _id), _baseMasterPort(NULL)
{
- if (_slavePort != NULL)
- panic("Attempting to bind master port %s that is already connected\n",
- name());
+}
+
+BaseSlavePort::~BaseSlavePort()
+{
+}
- // master port keeps track of the slave port
- _slavePort = &slave_port;
+BaseMasterPort&
+BaseSlavePort::getMasterPort() const
+{
+ if(_baseMasterPort == NULL)
+ panic("Cannot getMasterPort on slave port %s that is not connected\n",
+ name());
- // slave port also keeps track of master port
- _slavePort->bind(*this);
+ return *_baseMasterPort;
}
bool
-MasterPort::isConnected() const
+BaseSlavePort::isConnected() const
+{
+ return _baseMasterPort != NULL;
+}
+
+/**
+ * Master port
+ */
+MasterPort::MasterPort(const std::string& name, MemObject* owner, PortID _id)
+ : BaseMasterPort(name, owner, _id), _slavePort(NULL)
{
- return _slavePort != NULL;
+}
+
+MasterPort::~MasterPort()
+{
+}
+
+void
+MasterPort::bind(BaseSlavePort& slave_port)
+{
+ // 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());
+ }
+}
+
+void
+MasterPort::unbind()
+{
+ if (_slavePort == NULL)
+ panic("Attempting to unbind master port %s that is not connected\n",
+ name());
+ _slavePort->unbind();
+ _slavePort = NULL;
+ _baseSlavePort = NULL;
}
unsigned
@@ -172,7 +216,7 @@ MasterPort::printAddr(Addr a)
* Slave port
*/
SlavePort::SlavePort(const std::string& name, MemObject* owner, PortID id)
- : Port(name, *owner, id), _masterPort(NULL)
+ : BaseSlavePort(name, owner, id), _masterPort(NULL)
{
}
@@ -183,37 +227,23 @@ SlavePort::~SlavePort()
void
SlavePort::unbind()
{
+ _baseMasterPort = NULL;
_masterPort = NULL;
}
void
SlavePort::bind(MasterPort& master_port)
{
+ _baseMasterPort = &master_port;
_masterPort = &master_port;
}
-MasterPort&
-SlavePort::getMasterPort() const
-{
- if (_masterPort == NULL)
- panic("Cannot getMasterPort on slave port %s that is not connected\n",
- name());
-
- return *_masterPort;
-}
-
unsigned
SlavePort::peerBlockSize() const
{
return _masterPort->deviceBlockSize();
}
-bool
-SlavePort::isConnected() const
-{
- return _masterPort != NULL;
-}
-
Tick
SlavePort::sendAtomicSnoop(PacketPtr pkt)
{