From: Gabe Black Date: Fri, 14 Aug 2020 08:13:11 +0000 (-0700) Subject: dev: Replace Callback in the virtio device with a lambda. X-Git-Tag: v20.1.0.0~284 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35f0e8f4f33e96e52bc83267a73669dd3525dc82;p=gem5.git dev: Replace Callback in the virtio device with a lambda. Issue-on: https://gem5.atlassian.net/browse/GEM5-698 Change-Id: Ia628ceb0080b11b81c7eee82e7c8c0049b2cd62f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32649 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/dev/arm/vio_mmio.cc b/src/dev/arm/vio_mmio.cc index e0117af55..2dfbc61a3 100644 --- a/src/dev/arm/vio_mmio.cc +++ b/src/dev/arm/vio_mmio.cc @@ -45,13 +45,12 @@ MmioVirtIO::MmioVirtIO(const MmioVirtIOParams *params) : BasicPioDevice(params, params->pio_size), hostFeaturesSelect(0), guestFeaturesSelect(0), pageSize(0), - interruptStatus(0), - callbackKick(this), vio(*params->vio), + interruptStatus(0), vio(*params->vio), interrupt(params->interrupt->get()) { fatal_if(!interrupt, "No MMIO VirtIO interrupt specified\n"); - vio.registerKickCallback(&callbackKick); + vio.registerKickCallback([this]() { kick(); }); } MmioVirtIO::~MmioVirtIO() diff --git a/src/dev/arm/vio_mmio.hh b/src/dev/arm/vio_mmio.hh index fddbb83e6..d42d92a44 100644 --- a/src/dev/arm/vio_mmio.hh +++ b/src/dev/arm/vio_mmio.hh @@ -103,8 +103,6 @@ class MmioVirtIO : public BasicPioDevice uint32_t pageSize; uint32_t interruptStatus; - MakeCallback callbackKick; - protected: // Params VirtIODeviceBase &vio; ArmInterruptPin *const interrupt; diff --git a/src/dev/virtio/base.cc b/src/dev/virtio/base.cc index fef054c14..6b4fe0a36 100644 --- a/src/dev/virtio/base.cc +++ b/src/dev/virtio/base.cc @@ -328,8 +328,7 @@ VirtIODeviceBase::VirtIODeviceBase(Params *params, DeviceId id, guestFeatures(0), byteOrder(params->system->getGuestByteOrder()), deviceId(id), configSize(config_size), deviceFeatures(features), - _deviceStatus(0), _queueSelect(0), - transKick(NULL) + _deviceStatus(0), _queueSelect(0) { } diff --git a/src/dev/virtio/base.hh b/src/dev/virtio/base.hh index 98c48a5b8..7c4c3f886 100644 --- a/src/dev/virtio/base.hh +++ b/src/dev/virtio/base.hh @@ -38,9 +38,10 @@ #ifndef __DEV_VIRTIO_BASE_HH__ #define __DEV_VIRTIO_BASE_HH__ +#include + #include "arch/isa_traits.hh" #include "base/bitunion.hh" -#include "base/callback.hh" #include "dev/virtio/virtio_ring.h" #include "mem/port_proxy.hh" #include "sim/sim_object.hh" @@ -605,9 +606,11 @@ class VirtIODeviceBase : public SimObject * typically through an interrupt. Device models call this method * to tell the transport interface to notify the guest. */ - void kick() { + void + kick() + { assert(transKick); - transKick->process(); + transKick(); }; /** @@ -725,11 +728,13 @@ class VirtIODeviceBase : public SimObject * Register a callback to kick the guest through the transport * interface. * - * @param c Callback into transport interface. + * @param callback Callback into transport interface. */ - void registerKickCallback(Callback *c) { + void + registerKickCallback(const std::function &callback) + { assert(!transKick); - transKick = c; + transKick = callback; } @@ -867,7 +872,7 @@ class VirtIODeviceBase : public SimObject std::vector _queues; /** Callbacks to kick the guest through the transport layer */ - Callback *transKick; + std::function transKick; }; class VirtIODummyDevice : public VirtIODeviceBase diff --git a/src/dev/virtio/pci.cc b/src/dev/virtio/pci.cc index 6931581b2..115136eee 100644 --- a/src/dev/virtio/pci.cc +++ b/src/dev/virtio/pci.cc @@ -44,7 +44,7 @@ PciVirtIO::PciVirtIO(const Params *params) : PciDevice(params), queueNotify(0), interruptDeliveryPending(false), - vio(*params->vio), callbackKick(this) + vio(*params->vio) { // Override the subsystem ID with the device ID from VirtIO config.subsystemID = htole(vio.deviceId); @@ -55,7 +55,7 @@ PciVirtIO::PciVirtIO(const Params *params) // used to check accesses later on. BARSize[0] = alignToPowerOfTwo(BAR0_SIZE_BASE + vio.configSize); - vio.registerKickCallback(&callbackKick); + vio.registerKickCallback([this]() { kick(); }); } PciVirtIO::~PciVirtIO() diff --git a/src/dev/virtio/pci.hh b/src/dev/virtio/pci.hh index 7bb4633c8..b6c162c79 100644 --- a/src/dev/virtio/pci.hh +++ b/src/dev/virtio/pci.hh @@ -80,8 +80,6 @@ class PciVirtIO : public PciDevice bool interruptDeliveryPending; VirtIODeviceBase &vio; - - MakeCallback callbackKick; }; #endif // __DEV_VIRTIO_PCI_HH__