#include "mem/mem_object.hh"
#include "mem/port.hh"
-Port::Port(const std::string &_name, MemObject& _owner, PortId _id)
- : portName(_name), id(_id), peer(NULL), owner(_owner)
+Port::Port(const std::string &_name, MemObject& _owner, PortID _id)
+ : portName(_name), id(_id), owner(_owner)
{
}
{
}
-/**
- * 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::bind(SlavePort& slave_port)
+bool
+BaseMasterPort::isConnected() const
+{
+ return _baseSlavePort != NULL;
+}
+
+BaseSlavePort::BaseSlavePort(const std::string& name, MemObject* owner,
+ PortID _id)
+ : Port(name, *owner, _id), _baseMasterPort(NULL)
{
- // master port keeps track of the slave port
- _slavePort = &slave_port;
- peer = &slave_port;
+}
- // slave port also keeps track of master port
- _slavePort->bind(*this);
+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
-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
return _slavePort->deviceBlockSize();
}
+AddrRangeList
+MasterPort::getAddrRanges() const
+{
+ return _slavePort->getAddrRanges();
+}
+
Tick
MasterPort::sendAtomic(PacketPtr pkt)
{
return _slavePort->recvTimingSnoopResp(pkt);
}
+void
+MasterPort::sendRetry()
+{
+ _slavePort->recvRetry();
+}
+
void
MasterPort::printAddr(Addr a)
{
/**
* Slave port
*/
-SlavePort::SlavePort(const std::string& name, MemObject* owner, PortId id)
- : Port(name, *owner, id), _masterPort(NULL)
+SlavePort::SlavePort(const std::string& name, MemObject* owner, PortID id)
+ : BaseSlavePort(name, owner, id), _masterPort(NULL)
{
}
}
void
-SlavePort::bind(MasterPort& master_port)
+SlavePort::unbind()
{
- _masterPort = &master_port;
- peer = &master_port;
+ _baseMasterPort = NULL;
+ _masterPort = NULL;
}
-MasterPort&
-SlavePort::getMasterPort() const
+void
+SlavePort::bind(MasterPort& master_port)
{
- if (_masterPort == NULL)
- panic("Cannot getMasterPort on slave port %s that is not connected\n",
- name());
-
- return *_masterPort;
+ _baseMasterPort = &master_port;
+ _masterPort = &master_port;
}
unsigned
return _masterPort->deviceBlockSize();
}
-bool
-SlavePort::isConnected() const
-{
- return _masterPort != NULL;
-}
-
Tick
SlavePort::sendAtomicSnoop(PacketPtr pkt)
{
assert(pkt->isRequest());
_masterPort->recvTimingSnoopReq(pkt);
}
+
+void
+SlavePort::sendRetry()
+{
+ _masterPort->recvRetry();
+}