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 <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,10 @@
|
||||
#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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -80,8 +80,6 @@ class PciVirtIO : public PciDevice
|
||||
bool interruptDeliveryPending;
|
||||
|
||||
VirtIODeviceBase &vio;
|
||||
|
||||
MakeCallback<PciVirtIO, &PciVirtIO::kick> callbackKick;
|
||||
};
|
||||
|
||||
#endif // __DEV_VIRTIO_PCI_HH__
|
||||
|
||||
Reference in New Issue
Block a user