summaryrefslogtreecommitdiff
path: root/src/mem
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2012-04-25 10:41:23 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2012-04-25 10:41:23 -0400
commit4c92708b48d51bfb6592ff48925f5a7a0157da5b (patch)
tree2535fb1529ef60f64a3f26f943af5d8d681b22d8 /src/mem
parent79750fc575db0966ff9d0530975377c35f630eca (diff)
downloadgem5-4c92708b48d51bfb6592ff48925f5a7a0157da5b.tar.xz
MEM: Add the PortId type and a corresponding id field to Port
This patch introduces the PortId type, moves the definition of INVALID_PORT_ID to the Port class, and also gives every port an id to reflect the fact that each element in a vector port has an identifier/index. Previously the bus and Ruby testers (and potentially other users of the vector ports) added the id field in their port subclasses, and now this functionality is always present as it is moved to the base class.
Diffstat (limited to 'src/mem')
-rw-r--r--src/mem/bus.cc30
-rw-r--r--src/mem/bus.hh43
-rw-r--r--src/mem/port.cc12
-rw-r--r--src/mem/port.hh26
4 files changed, 60 insertions, 51 deletions
diff --git a/src/mem/bus.cc b/src/mem/bus.cc
index daf69c6df..488c3c4cb 100644
--- a/src/mem/bus.cc
+++ b/src/mem/bus.cc
@@ -57,7 +57,8 @@ Bus::Bus(const BusParams *p)
: MemObject(p), clock(p->clock),
headerCycles(p->header_cycles), width(p->width), tickNextIdle(0),
drainEvent(NULL), busIdleEvent(this), inRetry(false),
- defaultPortId(INVALID_PORT_ID), useDefaultRange(p->use_default_range),
+ defaultPortId(Port::INVALID_PORT_ID),
+ useDefaultRange(p->use_default_range),
defaultBlockSize(p->block_size),
cachedBlockSize(0), cachedBlockSizeValid(false)
{
@@ -304,7 +305,7 @@ Bus::recvTimingSnoop(PacketPtr pkt)
assert(pkt->isExpressSnoop());
// forward to all snoopers
- forwardTiming(pkt, INVALID_PORT_ID);
+ forwardTiming(pkt, Port::INVALID_PORT_ID);
// a snoop request came from a connected slave device (one of
// our master ports), and if it is not coming from the slave
@@ -403,7 +404,7 @@ Bus::forwardTiming(PacketPtr pkt, int exclude_slave_port_id)
// (corresponding to our own slave port that is also in
// snoopPorts) and should not send it back to where it came
// from
- if (exclude_slave_port_id == INVALID_PORT_ID ||
+ if (exclude_slave_port_id == Port::INVALID_PORT_ID ||
p->getId() != exclude_slave_port_id) {
// cache is not allowed to refuse snoop
bool success M5_VAR_USED = p->sendTimingSnoop(pkt);
@@ -467,7 +468,7 @@ Bus::retryWaiting()
}
void
-Bus::recvRetry(int id)
+Bus::recvRetry(Port::PortId id)
{
// we got a retry from a peer that we tried to send something to
// and failed, but we sent it on the account of someone else, and
@@ -493,7 +494,7 @@ Bus::findPort(Addr addr)
int dest_id;
dest_id = checkPortCache(addr);
- if (dest_id != INVALID_PORT_ID)
+ if (dest_id != Port::INVALID_PORT_ID)
return dest_id;
// Check normal port ranges
@@ -513,7 +514,7 @@ Bus::findPort(Addr addr)
return defaultPortId;
}
}
- } else if (defaultPortId != INVALID_PORT_ID) {
+ } else if (defaultPortId != Port::INVALID_PORT_ID) {
DPRINTF(Bus, "Unable to find destination for addr %#llx, "
"will use default port\n", addr);
return defaultPortId;
@@ -570,7 +571,8 @@ Bus::recvAtomicSnoop(PacketPtr pkt)
assert(pkt->isRequest());
// forward to all snoopers
- std::pair<MemCmd, Tick> snoop_result = forwardAtomic(pkt, INVALID_PORT_ID);
+ std::pair<MemCmd, Tick> snoop_result =
+ forwardAtomic(pkt, Port::INVALID_PORT_ID);
MemCmd snoop_response_cmd = snoop_result.first;
Tick snoop_response_latency = snoop_result.second;
@@ -599,7 +601,7 @@ Bus::forwardAtomic(PacketPtr pkt, int exclude_slave_port_id)
// (corresponding to our own slave port that is also in
// snoopPorts) and should not send it back to where it came
// from
- if (exclude_slave_port_id == INVALID_PORT_ID ||
+ if (exclude_slave_port_id == Port::INVALID_PORT_ID ||
p->getId() != exclude_slave_port_id) {
Tick latency = p->sendAtomicSnoop(pkt);
// in contrast to a functional access, we have to keep on
@@ -668,7 +670,7 @@ Bus::recvFunctionalSnoop(PacketPtr pkt)
assert(pkt->isRequest());
// forward to all snoopers
- forwardFunctional(pkt, INVALID_PORT_ID);
+ forwardFunctional(pkt, Port::INVALID_PORT_ID);
}
void
@@ -681,7 +683,7 @@ Bus::forwardFunctional(PacketPtr pkt, int exclude_slave_port_id)
// (corresponding to our own slave port that is also in
// snoopPorts) and should not send it back to where it came
// from
- if (exclude_slave_port_id == INVALID_PORT_ID ||
+ if (exclude_slave_port_id == Port::INVALID_PORT_ID ||
p->getId() != exclude_slave_port_id)
p->sendFunctionalSnoop(pkt);
@@ -694,7 +696,7 @@ Bus::forwardFunctional(PacketPtr pkt, int exclude_slave_port_id)
/** Function called by the port when the bus is receiving a range change.*/
void
-Bus::recvRangeChange(int id)
+Bus::recvRangeChange(Port::PortId id)
{
AddrRangeList ranges;
AddrRangeIter iter;
@@ -758,7 +760,7 @@ Bus::recvRangeChange(int id)
}
AddrRangeList
-Bus::getAddrRanges(int id)
+Bus::getAddrRanges(Port::PortId id)
{
AddrRangeList ranges;
@@ -799,14 +801,14 @@ Bus::getAddrRanges(int id)
}
bool
-Bus::isSnooping(int id) const
+Bus::isSnooping(Port::PortId id) const
{
// in essence, answer the question if there are snooping ports
return !snoopPorts.empty();
}
unsigned
-Bus::findBlockSize(int id)
+Bus::findBlockSize(Port::PortId id)
{
if (cachedBlockSizeValid)
return cachedBlockSize;
diff --git a/src/mem/bus.hh b/src/mem/bus.hh
index 8a0676353..2c05b6025 100644
--- a/src/mem/bus.hh
+++ b/src/mem/bus.hh
@@ -77,18 +77,13 @@ class Bus : public MemObject
/** A pointer to the bus to which this port belongs. */
Bus *bus;
- /** A id to keep track of the interface ID of this port. */
- int id;
-
public:
/** Constructor for the BusSlavePort.*/
- BusSlavePort(const std::string &_name, Bus *_bus, int _id)
- : SlavePort(_name, _bus), bus(_bus), id(_id)
+ BusSlavePort(const std::string &_name, Bus *_bus, Port::PortId _id)
+ : SlavePort(_name, _bus, _id), bus(_bus)
{ }
- int getId() const { return id; }
-
protected:
/**
@@ -147,18 +142,13 @@ class Bus : public MemObject
/** A pointer to the bus to which this port belongs. */
Bus *bus;
- /** A id to keep track of the interface ID of this port. */
- int id;
-
public:
/** Constructor for the BusMasterPort.*/
- BusMasterPort(const std::string &_name, Bus *_bus, int _id)
- : MasterPort(_name, _bus), bus(_bus), id(_id)
+ BusMasterPort(const std::string &_name, Bus *_bus, Port::PortId _id)
+ : MasterPort(_name, _bus, _id), bus(_bus)
{ }
- int getId() const { return id; }
-
/**
* Determine if this port should be considered a snooper. This
* is determined by the bus.
@@ -254,7 +244,7 @@ class Bus : public MemObject
* @param pkt Packet to forward
* @param exclude_slave_port_id Id of slave port to exclude
*/
- void forwardTiming(PacketPtr pkt, int exclude_slave_port_id);
+ void forwardTiming(PacketPtr pkt, Port::PortId exclude_slave_port_id);
/**
* Determine if the bus is to be considered occupied when being
@@ -296,7 +286,7 @@ class Bus : public MemObject
* @return a pair containing the snoop response and snoop latency
*/
std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt,
- int exclude_slave_port_id);
+ Port::PortId exclude_slave_port_id);
/** Function called by the port when the bus is recieving a Functional
transaction.*/
@@ -314,14 +304,14 @@ class Bus : public MemObject
* @param pkt Packet to forward
* @param exclude_slave_port_id Id of slave port to exclude
*/
- void forwardFunctional(PacketPtr pkt, int exclude_slave_port_id);
+ void forwardFunctional(PacketPtr pkt, Port::PortId exclude_slave_port_id);
/** Timing function called by port when it is once again able to process
* requests. */
- void recvRetry(int id);
+ void recvRetry(Port::PortId id);
/** Function called by the port when the bus is recieving a range change.*/
- void recvRangeChange(int id);
+ void recvRangeChange(Port::PortId id);
/** Find which port connected to this bus (if any) should be given a packet
* with this address.
@@ -333,7 +323,7 @@ class Bus : public MemObject
// Cache for the findPort function storing recently used ports from portMap
struct PortCache {
bool valid;
- int id;
+ Port::PortId id;
Addr start;
Addr end;
};
@@ -356,7 +346,7 @@ class Bus : public MemObject
return portCache[2].id;
}
- return INVALID_PORT_ID;
+ return Port::INVALID_PORT_ID;
}
// Clears the earliest entry of the cache and inserts a new port entry
@@ -391,7 +381,7 @@ class Bus : public MemObject
*
* @return a list of non-overlapping address ranges
*/
- AddrRangeList getAddrRanges(int id);
+ AddrRangeList getAddrRanges(Port::PortId id);
/**
* Determine if the bus port is snooping or not.
@@ -400,7 +390,7 @@ class Bus : public MemObject
*
* @return a boolean indicating if this port is snooping or not
*/
- bool isSnooping(int id) const;
+ bool isSnooping(Port::PortId id) const;
/** Calculate the timing parameters for the packet. Updates the
* firstWordTime and finishTime fields of the packet object.
@@ -429,13 +419,13 @@ class Bus : public MemObject
* @param id id of the busport that made the request
* @return the max of all the sizes
*/
- unsigned findBlockSize(int id);
+ unsigned findBlockSize(Port::PortId id);
// event used to schedule a release of the bus
EventWrapper<Bus, &Bus::releaseBus> busIdleEvent;
bool inRetry;
- std::set<int> inRecvRangeChange;
+ std::set<Port::PortId> inRecvRangeChange;
/** The master and slave ports of the bus */
std::vector<BusSlavePort*> slavePorts;
@@ -467,9 +457,6 @@ class Bus : public MemObject
/** Port that handles requests that don't match any of the interfaces.*/
short defaultPortId;
- /** A symbolic name for a port id that denotes no port. */
- static const short INVALID_PORT_ID = -1;
-
/** If true, use address range provided by default device. Any
address not handled by another port and not in default device's
range will cause a fatal error. If false, just send all
diff --git a/src/mem/port.cc b/src/mem/port.cc
index 4b7b040cb..fc3a42c02 100644
--- a/src/mem/port.cc
+++ b/src/mem/port.cc
@@ -50,8 +50,8 @@
#include "mem/mem_object.hh"
#include "mem/port.hh"
-Port::Port(const std::string &_name, MemObject& _owner)
- : portName(_name), peer(NULL), owner(_owner)
+Port::Port(const std::string &_name, MemObject& _owner, PortId _id)
+ : portName(_name), id(_id), peer(NULL), owner(_owner)
{
}
@@ -62,8 +62,8 @@ Port::~Port()
/**
* Master port
*/
-MasterPort::MasterPort(const std::string& name, MemObject* owner)
- : Port(name, *owner), _slavePort(NULL)
+MasterPort::MasterPort(const std::string& name, MemObject* owner, PortId _id)
+ : Port(name, *owner, _id), _slavePort(NULL)
{
}
@@ -130,8 +130,8 @@ MasterPort::printAddr(Addr a)
/**
* Slave port
*/
-SlavePort::SlavePort(const std::string& name, MemObject* owner)
- : Port(name, *owner), _masterPort(NULL)
+SlavePort::SlavePort(const std::string& name, MemObject* owner, PortId id)
+ : Port(name, *owner, id), _masterPort(NULL)
{
}
diff --git a/src/mem/port.hh b/src/mem/port.hh
index 61c92d8e4..e1f643e8e 100644
--- a/src/mem/port.hh
+++ b/src/mem/port.hh
@@ -79,6 +79,14 @@ class MemObject;
class Port
{
+ public:
+
+ /** A type name for the port identifier. */
+ typedef int PortId;
+
+ /** A symbolic name for the absence of a port id. */
+ static const PortId INVALID_PORT_ID = -1;
+
private:
/** Descriptive name (for DPRINTF output) */
@@ -86,6 +94,12 @@ class Port
protected:
+ /**
+ * A numeric identifier to distinguish ports in a vector, and set
+ * to INVALID_PORT_ID in case this port is not part of a vector.
+ */
+ const PortId id;
+
/** A pointer to the peer port. */
Port* peer;
@@ -97,8 +111,9 @@ class Port
*
* @param _name Port name including the owners name
* @param _owner The MemObject that is the structural owner of this port
+ * @param _id A port identifier for vector ports
*/
- Port(const std::string& _name, MemObject& _owner);
+ Port(const std::string& _name, MemObject& _owner, PortId _id);
/**
* Virtual destructor due to inheritance.
@@ -110,6 +125,9 @@ class Port
/** Return port name (for DPRINTF). */
const std::string name() const { return portName; }
+ /** Get the port id. */
+ PortId getId() const { return id; }
+
protected:
/** These functions are protected because they should only be
@@ -190,7 +208,8 @@ class MasterPort : public Port
public:
- MasterPort(const std::string& name, MemObject* owner);
+ MasterPort(const std::string& name, MemObject* owner,
+ PortId id = INVALID_PORT_ID);
virtual ~MasterPort();
void bind(SlavePort& slave_port);
@@ -286,7 +305,8 @@ class SlavePort : public Port
public:
- SlavePort(const std::string& name, MemObject* owner);
+ SlavePort(const std::string& name, MemObject* owner,
+ PortId id = INVALID_PORT_ID);
virtual ~SlavePort();
void bind(MasterPort& master_port);