dev: Replace Callback in the virtio device with a lambda.
authorGabe Black <gabeblack@google.com>
Fri, 14 Aug 2020 08:13:11 +0000 (01:13 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 18 Aug 2020 23:21:04 +0000 (23:21 +0000)
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 <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/dev/arm/vio_mmio.cc
src/dev/arm/vio_mmio.hh
src/dev/virtio/base.cc
src/dev/virtio/base.hh
src/dev/virtio/pci.cc
src/dev/virtio/pci.hh

index e0117af5550b143dc2bbcb22b2c3b2fe7b0460ce..2dfbc61a3b64a2fcfa738133affaabacb6d1de5d 100644 (file)
 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()
index fddbb83e663058df8d89146a94e10b45305821c1..d42d92a44a701a3d4c6dbbcbf812128c1dde7dde 100644 (file)
@@ -103,8 +103,6 @@ class MmioVirtIO : public BasicPioDevice
     uint32_t pageSize;
     uint32_t interruptStatus;
 
-    MakeCallback<MmioVirtIO, &MmioVirtIO::kick> callbackKick;
-
   protected: // Params
     VirtIODeviceBase &vio;
     ArmInterruptPin *const interrupt;
index fef054c14502a06dee8c77b48fb3622005962481..6b4fe0a36ccd46c6a699c8e6cd66dd44e23a0441 100644 (file)
@@ -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)
 {
 }
 
index 98c48a5b8a5a9462ff7d4180f5d061c5933af09f..7c4c3f8865b4b18fc14085b6ca6c8cd73d5e5bf1 100644 (file)
 #ifndef __DEV_VIRTIO_BASE_HH__
 #define __DEV_VIRTIO_BASE_HH__
 
+#include <functional>
+
 #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<void()> &callback)
+    {
         assert(!transKick);
-        transKick = c;
+        transKick = callback;
     }
 
 
@@ -867,7 +872,7 @@ class VirtIODeviceBase : public SimObject
     std::vector<VirtQueue *> _queues;
 
     /** Callbacks to kick the guest through the transport layer  */
-    Callback *transKick;
+    std::function<void()> transKick;
 };
 
 class VirtIODummyDevice : public VirtIODeviceBase
index 6931581b213a1c316e022032e44602843ca05ba3..115136eee7e254266cb304723e7afc9f07ce1dfb 100644 (file)
@@ -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()
index 7bb4633c8f5532e889d164f045f63fbf4af87a58..b6c162c79a20e12f16662f10b5f300fb9a66cc49 100644 (file)
@@ -80,8 +80,6 @@ class PciVirtIO : public PciDevice
     bool interruptDeliveryPending;
 
     VirtIODeviceBase &vio;
-
-    MakeCallback<PciVirtIO, &PciVirtIO::kick> callbackKick;
 };
 
 #endif // __DEV_VIRTIO_PCI_HH__