/*
- * Copyright (c) 2012 ARM Limited
+ * Copyright (c) 2012,2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
#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
{
- // master port keeps track of the slave port
- _slavePort = &slave_port;
- peer = &slave_port;
+ return _baseSlavePort != NULL;
+}
- // slave port also keeps track of master port
- _slavePort->bind(*this);
+BaseSlavePort::BaseSlavePort(const std::string& name, MemObject* owner,
+ PortID _id)
+ : Port(name, *owner, _id), _baseMasterPort(NULL)
+{
+}
+
+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 _slavePort != NULL;
+ return _baseMasterPort != NULL;
}
-unsigned
-MasterPort::peerBlockSize() const
+/**
+ * Master port
+ */
+MasterPort::MasterPort(const std::string& name, MemObject* owner, PortID _id)
+ : BaseMasterPort(name, owner, _id), _slavePort(NULL)
+{
+}
+
+MasterPort::~MasterPort()
+{
+}
+
+void
+MasterPort::bind(BaseSlavePort& slave_port)
{
- return _slavePort->deviceBlockSize();
+ // 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;
+}
+
+AddrRangeList
+MasterPort::getAddrRanges() const
+{
+ return _slavePort->getAddrRanges();
}
Tick
MasterPort::sendAtomic(PacketPtr pkt)
{
+ assert(pkt->isRequest());
return _slavePort->recvAtomic(pkt);
}
void
MasterPort::sendFunctional(PacketPtr pkt)
{
+ assert(pkt->isRequest());
return _slavePort->recvFunctional(pkt);
}
+bool
+MasterPort::sendTimingReq(PacketPtr pkt)
+{
+ assert(pkt->isRequest());
+ return _slavePort->recvTimingReq(pkt);
+}
+
+bool
+MasterPort::sendTimingSnoopResp(PacketPtr pkt)
+{
+ assert(pkt->isResponse());
+ return _slavePort->recvTimingSnoopResp(pkt);
+}
+
+void
+MasterPort::sendRetryResp()
+{
+ _slavePort->recvRespRetry();
+}
+
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::unbind()
+{
+ _baseMasterPort = NULL;
+ _masterPort = NULL;
+}
+
void
SlavePort::bind(MasterPort& master_port)
{
+ _baseMasterPort = &master_port;
_masterPort = &master_port;
- peer = &master_port;
}
-MasterPort&
-SlavePort::getMasterPort() const
+Tick
+SlavePort::sendAtomicSnoop(PacketPtr pkt)
{
- if (_masterPort == NULL)
- panic("Cannot getMasterPort on slave port %s that is not connected\n",
- name());
-
- return *_masterPort;
+ assert(pkt->isRequest());
+ return _masterPort->recvAtomicSnoop(pkt);
}
-unsigned
-SlavePort::peerBlockSize() const
+void
+SlavePort::sendFunctionalSnoop(PacketPtr pkt)
{
- return _masterPort->deviceBlockSize();
+ assert(pkt->isRequest());
+ return _masterPort->recvFunctionalSnoop(pkt);
}
bool
-SlavePort::isConnected() const
+SlavePort::sendTimingResp(PacketPtr pkt)
{
- return _masterPort != NULL;
+ assert(pkt->isResponse());
+ return _masterPort->recvTimingResp(pkt);
}
-Tick
-SlavePort::sendAtomicSnoop(PacketPtr pkt)
+void
+SlavePort::sendTimingSnoopReq(PacketPtr pkt)
{
- return _masterPort->recvAtomicSnoop(pkt);
+ assert(pkt->isRequest());
+ _masterPort->recvTimingSnoopReq(pkt);
}
void
-SlavePort::sendFunctionalSnoop(PacketPtr pkt)
+SlavePort::sendRetryReq()
{
- return _masterPort->recvFunctionalSnoop(pkt);
+ _masterPort->recvReqRetry();
+}
+
+void
+SlavePort::sendRetrySnoopResp()
+{
+ _masterPort->recvRetrySnoopResp();
}