diff options
Diffstat (limited to 'src/mem/port.cc')
-rw-r--r-- | src/mem/port.cc | 120 |
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) { |