summaryrefslogtreecommitdiff
path: root/src/dev/io_device.cc
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2012-02-24 11:43:53 -0500
committerAndreas Hansson <andreas.hansson@arm.com>2012-02-24 11:43:53 -0500
commit1031b824b975cec999c37cabc8c05c485a4ae5ca (patch)
tree18af5987accd59781642001849908ddb486d069a /src/dev/io_device.cc
parent9f07d2ce7ecf435b9a1946f15fb3491bb4636637 (diff)
downloadgem5-1031b824b975cec999c37cabc8c05c485a4ae5ca.tar.xz
MEM: Move port creation to the memory object(s) construction
This patch moves all port creation from the getPort method to be consistently done in the MemObject's constructor. This is possible thanks to the Swig interface passing the length of the vector ports. Previously there was a mix of: 1) creating the ports as members (at object construction time) and using getPort for the name resolution, or 2) dynamically creating the ports in the getPort call. This is now uniform. Furthermore, objects that would not be complete without a port have these ports as members rather than having pointers to dynamically allocated ports. This patch also enables an elaboration-time enumeration of all the ports in the system which can be used to determine the masterId.
Diffstat (limited to 'src/dev/io_device.cc')
-rw-r--r--src/dev/io_device.cc39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/dev/io_device.cc b/src/dev/io_device.cc
index b1f6f5e02..5d6255f5c 100644
--- a/src/dev/io_device.cc
+++ b/src/dev/io_device.cc
@@ -55,33 +55,28 @@ PioPort::getAddrRanges()
PioDevice::PioDevice(const Params *p)
- : MemObject(p), sys(p->system), pioPort(NULL)
+ : MemObject(p), sys(p->system), pioPort(this, sys)
{}
PioDevice::~PioDevice()
{
- if (pioPort)
- delete pioPort;
}
void
PioDevice::init()
{
- if (!pioPort)
+ if (!pioPort.isConnected())
panic("Pio port of %s not connected to anything!", name());
- pioPort->sendRangeChange();
+ pioPort.sendRangeChange();
}
Port *
PioDevice::getPort(const std::string &if_name, int idx)
{
if (if_name == "pio") {
- if (pioPort != NULL)
- fatal("%s: pio port already connected to %s",
- name(), pioPort->getPeer()->name());
- pioPort = new PioPort(this, sys);
- return pioPort;
+ return &pioPort;
}
+ panic("PioDevice %s has no port named %s\n", name(), if_name);
return NULL;
}
@@ -89,7 +84,7 @@ unsigned int
PioDevice::drain(Event *de)
{
unsigned int count;
- count = pioPort->drain(de);
+ count = pioPort.drain(de);
if (count)
changeState(Draining);
else
@@ -185,14 +180,23 @@ DmaPort::recvTiming(PacketPtr pkt)
}
DmaDevice::DmaDevice(const Params *p)
- : PioDevice(p), dmaPort(NULL)
+ : PioDevice(p), dmaPort(this, sys, params()->min_backoff_delay,
+ params()->max_backoff_delay)
{ }
+void
+DmaDevice::init()
+{
+ if (!dmaPort.isConnected())
+ panic("DMA port of %s not connected to anything!", name());
+ PioDevice::init();
+}
+
unsigned int
DmaDevice::drain(Event *de)
{
unsigned int count;
- count = pioPort->drain(de) + dmaPort->drain(de);
+ count = pioPort.drain(de) + dmaPort.drain(de);
if (count)
changeState(Draining);
else
@@ -362,8 +366,6 @@ DmaPort::sendDma()
DmaDevice::~DmaDevice()
{
- if (dmaPort)
- delete dmaPort;
}
@@ -371,12 +373,7 @@ Port *
DmaDevice::getPort(const std::string &if_name, int idx)
{
if (if_name == "dma") {
- if (dmaPort != NULL)
- fatal("%s: dma port already connected to %s",
- name(), dmaPort->getPeer()->name());
- dmaPort = new DmaPort(this, sys, params()->min_backoff_delay,
- params()->max_backoff_delay);
- return dmaPort;
+ return &dmaPort;
}
return PioDevice::getPort(if_name, idx);
}