dev: Replace the Callback class with lambdas in ARM's flash devices.
Issue-on: https://gem5.atlassian.net/browse/GEM5-698 Change-Id: I2694dd1952b7412c27c83c9d15d4645899bd28e2 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32648 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Gabe Black <gabeblack@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -99,9 +99,9 @@ class AbstractNVM : public SimObject
|
||||
* data transfer between the disk and the disk controller.
|
||||
*/
|
||||
virtual void readMemory(uint64_t address, uint32_t amount,
|
||||
Callback *event) = 0;
|
||||
const std::function<void()> &event) = 0;
|
||||
virtual void writeMemory(uint64_t address, uint32_t amount,
|
||||
Callback *event) = 0;
|
||||
const std::function<void()> &event) = 0;
|
||||
};
|
||||
|
||||
#endif //__DEV_ARM_ABSTRACT_NVM_HH__
|
||||
|
||||
@@ -160,8 +160,8 @@ FlashDevice::~FlashDevice()
|
||||
* an event that uses the callback function on completion of the action.
|
||||
*/
|
||||
void
|
||||
FlashDevice::accessDevice(uint64_t address, uint32_t amount, Callback *event,
|
||||
Actions action)
|
||||
FlashDevice::accessDevice(uint64_t address, uint32_t amount,
|
||||
const std::function<void()> &event, Actions action)
|
||||
{
|
||||
DPRINTF(FlashDevice, "Flash calculation for %d bytes in %d pages\n"
|
||||
, amount, pageSize);
|
||||
@@ -258,7 +258,6 @@ FlashDevice::accessDevice(uint64_t address, uint32_t amount, Callback *event,
|
||||
else
|
||||
cbe.time = time[count] +
|
||||
planeEventQueue[count].back().time;
|
||||
cbe.function = NULL;
|
||||
planeEventQueue[count].push_back(cbe);
|
||||
|
||||
DPRINTF(FlashDevice, "scheduled at: %ld\n", cbe.time);
|
||||
@@ -308,14 +307,13 @@ FlashDevice::actionComplete()
|
||||
* the callback entry first need to be cleared before it can
|
||||
* be called.
|
||||
*/
|
||||
Callback *temp = planeEventQueue[plane_address].front().
|
||||
function;
|
||||
auto temp = planeEventQueue[plane_address].front().function;
|
||||
planeEventQueue[plane_address].pop_front();
|
||||
|
||||
/**Found a callback, lets make it happen*/
|
||||
if (temp != NULL) {
|
||||
if (temp) {
|
||||
DPRINTF(FlashDevice, "Callback, %d\n", plane_address);
|
||||
temp->process();
|
||||
temp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class FlashDevice : public AbstractNVM
|
||||
|
||||
struct CallBackEntry {
|
||||
Tick time;
|
||||
Callback *function;
|
||||
std::function<void()> function;
|
||||
};
|
||||
|
||||
struct FlashDeviceStats {
|
||||
@@ -105,19 +105,22 @@ class FlashDevice : public AbstractNVM
|
||||
};
|
||||
|
||||
/** Device access functions Inherrited from AbstractNVM*/
|
||||
void initializeMemory(uint64_t disk_size, uint32_t sector_size) override
|
||||
void
|
||||
initializeMemory(uint64_t disk_size, uint32_t sector_size) override
|
||||
{
|
||||
initializeFlash(disk_size, sector_size);
|
||||
}
|
||||
|
||||
void readMemory(uint64_t address, uint32_t amount,
|
||||
Callback *event) override
|
||||
void
|
||||
readMemory(uint64_t address, uint32_t amount,
|
||||
const std::function<void()> &event) override
|
||||
{
|
||||
accessDevice(address, amount, event, ActionRead);
|
||||
}
|
||||
|
||||
void writeMemory(uint64_t address, uint32_t amount,
|
||||
Callback *event) override
|
||||
void
|
||||
writeMemory(uint64_t address, uint32_t amount,
|
||||
const std::function<void()> &event) override
|
||||
{
|
||||
accessDevice(address, amount, event, ActionWrite);
|
||||
}
|
||||
@@ -126,8 +129,8 @@ class FlashDevice : public AbstractNVM
|
||||
void initializeFlash(uint64_t disk_size, uint32_t sector_size);
|
||||
|
||||
/**Flash action function*/
|
||||
void accessDevice(uint64_t address, uint32_t amount, Callback *event,
|
||||
Actions action);
|
||||
void accessDevice(uint64_t address, uint32_t amount,
|
||||
const std::function<void()> &event, Actions action);
|
||||
|
||||
/** Event rescheduler*/
|
||||
void actionComplete();
|
||||
|
||||
@@ -73,8 +73,8 @@
|
||||
* Constructor and destructor functions of UFSHCM device
|
||||
*/
|
||||
UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p,
|
||||
uint32_t lun_id, Callback *transfer_cb,
|
||||
Callback *read_cb):
|
||||
uint32_t lun_id, const Callback &transfer_cb,
|
||||
const Callback &read_cb):
|
||||
SimObject(p),
|
||||
flashDisk(p->image[lun_id]),
|
||||
flashDevice(p->internalflash[lun_id]),
|
||||
@@ -97,11 +97,9 @@ UFSHostDevice::UFSSCSIDevice::UFSSCSIDevice(const UFSHostDeviceParams* p,
|
||||
* or from the UFS SCSI device to the UFS host.
|
||||
*/
|
||||
signalDone = transfer_cb;
|
||||
memReadCallback = new MakeCallback<UFSSCSIDevice,
|
||||
&UFSHostDevice::UFSSCSIDevice::readCallback>(this);
|
||||
memReadCallback = [this]() { readCallback(); };
|
||||
deviceReadCallback = read_cb;
|
||||
memWriteCallback = new MakeCallback<UFSSCSIDevice,
|
||||
&UFSHostDevice::UFSSCSIDevice::SSDWriteDone>(this);
|
||||
memWriteCallback = [this]() { SSDWriteDone(); };
|
||||
|
||||
/**
|
||||
* make ascii out of lun_id (and add more characters)
|
||||
@@ -738,14 +736,10 @@ UFSHostDevice::UFSHostDevice(const UFSHostDeviceParams* p) :
|
||||
lunAvail);
|
||||
UFSDevice.resize(lunAvail);
|
||||
|
||||
transferDoneCallback = new MakeCallback<UFSHostDevice,
|
||||
&UFSHostDevice::LUNSignal>(this);
|
||||
memReadCallback = new MakeCallback<UFSHostDevice,
|
||||
&UFSHostDevice::readCallback>(this);
|
||||
|
||||
for (int count = 0; count < lunAvail; count++) {
|
||||
UFSDevice[count] = new UFSSCSIDevice(p, count, transferDoneCallback,
|
||||
memReadCallback);
|
||||
UFSDevice[count] = new UFSSCSIDevice(p, count,
|
||||
[this]() { LUNSignal(); },
|
||||
[this]() { readCallback(); });
|
||||
}
|
||||
|
||||
if (UFSSlots > 31)
|
||||
@@ -2070,7 +2064,7 @@ UFSHostDevice::UFSSCSIDevice::SSDWriteDone()
|
||||
|
||||
//Callback UFS Host
|
||||
setSignal();
|
||||
signalDone->process();
|
||||
signalDone();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2213,7 +2207,7 @@ UFSHostDevice::UFSSCSIDevice::SSDReadDone()
|
||||
|
||||
/**Callback: transferdone*/
|
||||
setSignal();
|
||||
signalDone->process();
|
||||
signalDone();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2231,7 +2225,7 @@ UFSHostDevice::UFSSCSIDevice::readCallback()
|
||||
* UFSHostDevice::readCallback
|
||||
*/
|
||||
setReadSignal();
|
||||
deviceReadCallback->process();
|
||||
deviceReadCallback();
|
||||
|
||||
//Are we done yet?
|
||||
SSDReadDone();
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
#define __DEV_ARM_UFS_DEVICE_HH__
|
||||
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
|
||||
#include "base/addr_range.hh"
|
||||
#include "base/bitfield.hh"
|
||||
@@ -535,11 +536,13 @@ class UFSHostDevice : public DmaDevice
|
||||
class UFSSCSIDevice: SimObject
|
||||
{
|
||||
public:
|
||||
using Callback = std::function<void()>;
|
||||
|
||||
/**
|
||||
* Constructor and destructor
|
||||
*/
|
||||
UFSSCSIDevice(const UFSHostDeviceParams* p, uint32_t lun_id, Callback*
|
||||
transfer_cb, Callback *read_cb);
|
||||
UFSSCSIDevice(const UFSHostDeviceParams* p, uint32_t lun_id,
|
||||
const Callback &transfer_cb, const Callback &read_cb);
|
||||
~UFSSCSIDevice();
|
||||
|
||||
/**
|
||||
@@ -722,14 +725,14 @@ class UFSHostDevice : public DmaDevice
|
||||
/**
|
||||
* Callbacks between Host and Device
|
||||
*/
|
||||
Callback* signalDone;
|
||||
Callback* deviceReadCallback;
|
||||
Callback signalDone;
|
||||
Callback deviceReadCallback;
|
||||
|
||||
/**
|
||||
* Callbacks between Device and Memory
|
||||
*/
|
||||
Callback* memReadCallback;
|
||||
Callback* memWriteCallback;
|
||||
Callback memReadCallback;
|
||||
Callback memWriteCallback;
|
||||
|
||||
/*
|
||||
* Default response header layout. For more information refer to
|
||||
@@ -1134,14 +1137,6 @@ class UFSHostDevice : public DmaDevice
|
||||
std::deque<EventFunctionWrapper> readDoneEvent;
|
||||
std::deque<EventFunctionWrapper> writeDoneEvent;
|
||||
|
||||
/**
|
||||
* Callbacks for the logic units. One to indicate the completion of a
|
||||
* transaction, the other one to indicate the completion of a read
|
||||
* action.
|
||||
*/
|
||||
Callback* transferDoneCallback;
|
||||
Callback* memReadCallback;
|
||||
|
||||
/**
|
||||
* The events that control the functionality.
|
||||
* After a doorbell has been set, either a taskevent or a transfer event
|
||||
|
||||
Reference in New Issue
Block a user