From bdb327295261dae9e155b2a88b6923c66a939ccd Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 2 Sep 2019 21:41:53 -0700 Subject: [PATCH] dev: Templatize PioPort. When creating a base class which needs to be a SimObject, it's necessary to decide ahead of time whether to use PioDevice or BasicPioDevice in the hierarchy because they inherit from SimObject. If they were added into the hierarchy later, then the original class would inherit from SimObject, as would PioDevice. That would create a diamond inheritance structure which would require virtual inheritance, and that's a can of worms we'd rather not get into. A big part of the PioPort mechanism is the PioPort itself which holds a pointer to its parent device and delegates reads/writes to it. It does that with a PioDevice pointer, and PioDevice declares virtual functions for all the callbacks the port can call into. Instead of that, this change templatizes PioPort based on the class of the device that holds it. That will let you use a PioPort on *any* class, as long as it has the methods PioPort depends on. That removes the need to create an inheritance diamond to add a PioPort down the line since PioDevice is no longer strictly required. The PioDevice and BasicPioDevice classes are still around since they still provide some additional functionality and there are existing classes which depend on them. Change-Id: I753afc1e0fa54b91217d54c1f8743c150537e960 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20568 Reviewed-by: Andreas Sandberg Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/dev/io_device.cc | 24 ------------------------ src/dev/io_device.hh | 35 ++++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/dev/io_device.cc b/src/dev/io_device.cc index 425c2f41f..64550eade 100644 --- a/src/dev/io_device.cc +++ b/src/dev/io_device.cc @@ -47,30 +47,6 @@ #include "debug/AddrRanges.hh" #include "sim/system.hh" -PioPort::PioPort(PioDevice *dev) - : SimpleTimingPort(dev->name() + ".pio", dev), device(dev) -{ -} - -Tick -PioPort::recvAtomic(PacketPtr pkt) -{ - // technically the packet only reaches us after the header delay, - // and typically we also need to deserialise any payload - Tick receive_delay = pkt->headerDelay + pkt->payloadDelay; - pkt->headerDelay = pkt->payloadDelay = 0; - - const Tick delay(pkt->isRead() ? device->read(pkt) : device->write(pkt)); - assert(pkt->isResponse() || pkt->isError()); - return delay + receive_delay; -} - -AddrRangeList -PioPort::getAddrRanges() const -{ - return device->getAddrRanges(); -} - PioDevice::PioDevice(const Params *p) : ClockedObject(p), sys(p->system), pioPort(this) {} diff --git a/src/dev/io_device.hh b/src/dev/io_device.hh index c9e25d224..804133893 100644 --- a/src/dev/io_device.hh +++ b/src/dev/io_device.hh @@ -59,19 +59,37 @@ class System; * must respond to. The device must also provide getAddrRanges() function * with which it returns the address ranges it is interested in. */ +template class PioPort : public SimpleTimingPort { protected: /** The device that this port serves. */ - PioDevice *device; + Device *device; - virtual Tick recvAtomic(PacketPtr pkt); + Tick + recvAtomic(PacketPtr pkt) override + { + // Technically the packet only reaches us after the header delay, + // and typically we also need to deserialise any payload. + Tick receive_delay = pkt->headerDelay + pkt->payloadDelay; + pkt->headerDelay = pkt->payloadDelay = 0; + + const Tick delay = + pkt->isRead() ? device->read(pkt) : device->write(pkt); + assert(pkt->isResponse() || pkt->isError()); + return delay + receive_delay; + } - virtual AddrRangeList getAddrRanges() const; + AddrRangeList + getAddrRanges() const override + { + return device->getAddrRanges(); + } public: - - PioPort(PioDevice *dev); + PioPort(Device *dev) : + SimpleTimingPort(dev->name() + ".pio", dev), device(dev) + {} }; /** @@ -88,7 +106,7 @@ class PioDevice : public ClockedObject /** The pioPort that handles the requests for us and provides us requests * that it sees. */ - PioPort pioPort; + PioPort pioPort; /** * Every PIO device is obliged to provide an implementation that @@ -128,7 +146,7 @@ class PioDevice : public ClockedObject Port &getPort(const std::string &if_name, PortID idx=InvalidPortID) override; - friend class PioPort; + friend class PioPort; }; @@ -159,8 +177,7 @@ class BasicPioDevice : public PioDevice * * @return a list of non-overlapping address ranges */ - virtual AddrRangeList getAddrRanges() const; - + AddrRangeList getAddrRanges() const override; }; #endif // __DEV_IO_DEVICE_HH__ -- 2.30.2