summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dev/net/etherint.cc19
-rw-r--r--src/dev/net/etherint.hh3
-rw-r--r--src/mem/port.cc50
-rw-r--r--src/mem/port.hh18
-rw-r--r--src/sim/port.cc4
-rw-r--r--src/sim/port.hh14
6 files changed, 67 insertions, 41 deletions
diff --git a/src/dev/net/etherint.cc b/src/dev/net/etherint.cc
index 0c5e6b817..b55e625f7 100644
--- a/src/dev/net/etherint.cc
+++ b/src/dev/net/etherint.cc
@@ -34,6 +34,25 @@
#include "sim/sim_object.hh"
void
+EtherInt::bind(Port &peer)
+{
+ EtherInt *p = dynamic_cast<EtherInt *>(&peer);
+ if (!p) {
+ fatal("Attempt to bind port %s to non-ethernet port %s.",
+ name(), peer.name());
+ }
+ setPeer(p);
+ _connected = true;
+}
+
+void
+EtherInt::unbind()
+{
+ peer = nullptr;
+ _connected = false;
+}
+
+void
EtherInt::setPeer(EtherInt *p)
{
if (peer && peer != p)
diff --git a/src/dev/net/etherint.hh b/src/dev/net/etherint.hh
index 77032208c..0486631b2 100644
--- a/src/dev/net/etherint.hh
+++ b/src/dev/net/etherint.hh
@@ -60,6 +60,9 @@ class EtherInt : public Port
/** Return port name (for DPRINTF). */
const std::string &name() const { return portName; }
+ void bind(Port &peer) override;
+ void unbind() override;
+
void setPeer(EtherInt *p);
EtherInt* getPeer() { return peer; }
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
diff --git a/src/mem/port.hh b/src/mem/port.hh
index 77081db4d..2154da007 100644
--- a/src/mem/port.hh
+++ b/src/mem/port.hh
@@ -77,10 +77,7 @@ class BaseMasterPort : public Port
public:
- virtual void bind(BaseSlavePort& slave_port) = 0;
- virtual void unbind() = 0;
BaseSlavePort& getSlavePort() const;
- bool isConnected() const;
};
@@ -101,7 +98,6 @@ class BaseSlavePort : public Port
public:
BaseMasterPort& getMasterPort() const;
- bool isConnected() const;
};
@@ -138,12 +134,12 @@ class MasterPort : public BaseMasterPort
* Bind this master port to a slave port. This also does the
* mirror action and binds the slave port to the master port.
*/
- void bind(BaseSlavePort& slave_port);
+ void bind(Port &peer) override;
/**
* Unbind this master port and the associated slave port.
*/
- void unbind();
+ void unbind() override;
/**
* Send an atomic request packet, where the data is moved and the
@@ -394,19 +390,25 @@ class SlavePort : public BaseSlavePort
*/
virtual AddrRangeList getAddrRanges() const = 0;
+ /**
+ * We let the master port do the work, so these don't do anything.
+ */
+ void unbind() override {}
+ void bind(Port &peer) override {}
+
protected:
/**
* Called by the master port to unbind. Should never be called
* directly.
*/
- void unbind();
+ void slaveUnbind();
/**
* Called by the master port to bind. Should never be called
* directly.
*/
- void bind(MasterPort& master_port);
+ void slaveBind(MasterPort& master_port);
/**
* Receive an atomic request packet from the master port.
diff --git a/src/sim/port.cc b/src/sim/port.cc
index 551785ba4..b3139a630 100644
--- a/src/sim/port.cc
+++ b/src/sim/port.cc
@@ -49,5 +49,7 @@
#include "sim/port.hh"
-Port::Port(const std::string& _name, PortID _id) : portName(_name), id(_id) {}
+Port::Port(const std::string& _name, PortID _id) :
+ portName(_name), id(_id), _connected(false)
+{}
Port::~Port() {}
diff --git a/src/sim/port.hh b/src/sim/port.hh
index 368f46783..e1811643f 100644
--- a/src/sim/port.hh
+++ b/src/sim/port.hh
@@ -63,7 +63,7 @@ class Port
private:
/** Descriptive name (for DPRINTF output) */
- std::string portName;
+ const std::string portName;
protected:
@@ -72,6 +72,10 @@ class Port
* to InvalidPortID in case this port is not part of a vector.
*/
const PortID id;
+ /**
+ * Whether this port is currently connected to a peer port.
+ */
+ bool _connected;
/**
* Abstract base class for ports
@@ -94,6 +98,14 @@ class Port
/** Get the port id. */
PortID getId() const { return id; }
+ /** Attach to a peer port. */
+ virtual void bind(Port &peer) = 0;
+
+ /** Dettach from a peer port. */
+ virtual void unbind() = 0;
+
+ /** Is this port currently connected to a peer? */
+ bool isConnected() const { return _connected; }
};
#endif //__SIM_PORT_HH__