gem5
|
Base class for all VirtIO-based devices. More...
#include <base.hh>
Public Types | |
typedef uint16_t | QueueID |
typedef uint32_t | FeatureBits |
typedef uint16_t | VirtAddress |
This is a VirtQueue address as exposed through the low-level interface. The address needs to be multiplied by the page size (seems to be hardcoded to 4096 in the spec) to get the real physical address. More... | |
typedef uint16_t | DeviceId |
Device Type (sometimes known as subsystem ID) More... | |
Public Types inherited from SimObject | |
typedef SimObjectParams | Params |
Public Member Functions | |
BitUnion8 (DeviceStatus) Bitfield< 7 > failed | |
EndBitUnion (DeviceStatus) typedef VirtIODeviceBaseParams Params | |
VirtIODeviceBase (Params *params, DeviceId id, size_t config_size, FeatureBits features) | |
virtual | ~VirtIODeviceBase () |
SimObject Interfaces | |
void | serialize (CheckpointOut &cp) const override |
Serialize an object. More... | |
void | unserialize (CheckpointIn &cp) override |
Unserialize an object. More... | |
Optional VirtIO Interfaces | |
virtual void | readConfig (PacketPtr pkt, Addr cfgOffset) |
Read from the configuration space of a device. More... | |
virtual void | writeConfig (PacketPtr pkt, Addr cfgOffset) |
Write to the configuration space of a device. More... | |
virtual void | reset () |
Driver-request device reset. More... | |
Public Member Functions inherited from SimObject | |
const Params * | params () const |
SimObject (const Params *_params) | |
virtual | ~SimObject () |
virtual const std::string | name () const |
virtual void | init () |
init() is called after all C++ SimObjects have been created and all ports are connected. More... | |
virtual void | loadState (CheckpointIn &cp) |
loadState() is called on each SimObject when restoring from a checkpoint. More... | |
virtual void | initState () |
initState() is called on each SimObject when not restoring from a checkpoint. More... | |
virtual void | regStats () |
Register statistics for this object. More... | |
virtual void | resetStats () |
Reset statistics associated with this object. More... | |
virtual void | regProbePoints () |
Register probe points for this object. More... | |
virtual void | regProbeListeners () |
Register probe listeners for this object. More... | |
ProbeManager * | getProbeManager () |
Get the probe manager for this object. More... | |
virtual void | startup () |
startup() is the final initialization call before simulation. More... | |
DrainState | drain () override |
Provide a default implementation of the drain interface for objects that don't need draining. More... | |
virtual void | memWriteback () |
Write back dirty buffers to memory using functional writes. More... | |
virtual void | memInvalidate () |
Invalidate the contents of memory buffers. More... | |
void | serialize (CheckpointOut &cp) const override |
Serialize an object. More... | |
void | unserialize (CheckpointIn &cp) override |
Unserialize an object. More... | |
Public Member Functions inherited from EventManager | |
EventManager (EventManager &em) | |
EventManager (EventManager *em) | |
EventManager (EventQueue *eq) | |
EventQueue * | eventQueue () const |
void | schedule (Event &event, Tick when) |
void | deschedule (Event &event) |
void | reschedule (Event &event, Tick when, bool always=false) |
void | schedule (Event *event, Tick when) |
void | deschedule (Event *event) |
void | reschedule (Event *event, Tick when, bool always=false) |
void | wakeupEventQueue (Tick when=(Tick)-1) |
void | setCurTick (Tick newVal) |
Public Member Functions inherited from Serializable | |
Serializable () | |
virtual | ~Serializable () |
void | serializeSection (CheckpointOut &cp, const char *name) const |
Serialize an object into a new section. More... | |
void | serializeSection (CheckpointOut &cp, const std::string &name) const |
void | unserializeSection (CheckpointIn &cp, const char *name) |
Unserialize an a child object. More... | |
void | unserializeSection (CheckpointIn &cp, const std::string &name) |
Public Member Functions inherited from Drainable | |
DrainState | drainState () const |
Return the current drain state of an object. More... | |
virtual void | notifyFork () |
Notify a child process of a fork. More... | |
Public Attributes | |
Bitfield< 2 > | driver_ok |
Bitfield< 1 > | driver |
Bitfield< 0 > | acknowledge |
Protected Member Functions | |
Device Model Helpers | |
void | readConfigBlob (PacketPtr pkt, Addr cfgOffset, const uint8_t *cfg) |
Read configuration data from a device structure. More... | |
void | writeConfigBlob (PacketPtr pkt, Addr cfgOffset, uint8_t *cfg) |
Write configuration data to a device structure. More... | |
Protected Member Functions inherited from Drainable | |
Drainable () | |
virtual | ~Drainable () |
virtual void | drainResume () |
Resume execution after a successful drain. More... | |
void | signalDrainDone () const |
Signal that an object is drained. More... | |
Private Member Functions | |
const VirtQueue & | getCurrentQueue () const |
Convenience method to get the currently selected queue. More... | |
VirtQueue & | getCurrentQueue () |
Convenience method to get the currently selected queue. More... | |
Private Attributes | |
DeviceStatus | _deviceStatus |
Status of the device. More... | |
QueueID | _queueSelect |
Queue select register (set by guest) More... | |
std::vector< VirtQueue * > | _queues |
List of virtual queues supported by this device. More... | |
Callback * | transKick |
Callbacks to kick the guest through the transport layer. More... | |
Device Model Interfaces | |
FeatureBits | guestFeatures |
Feature set accepted by the guest. More... | |
void | kick () |
Inform the guest of available buffers. More... | |
void | registerQueue (VirtQueue &queue) |
Register a new VirtQueue with the device model. More... | |
VirtIO Transport Interfaces | |
const DeviceId | deviceId |
Device ID (sometimes known as subsystem ID) More... | |
const size_t | configSize |
Size of the device's configuration space. More... | |
const FeatureBits | deviceFeatures |
Feature set offered by the device. More... | |
void | registerKickCallback (Callback *c) |
Register a callback to kick the guest through the transport interface. More... | |
void | onNotify (QueueID index) |
Driver is requesting service. More... | |
void | setQueueSelect (QueueID idx) |
Change currently active queue. More... | |
QueueID | getQueueSelect () const |
Get the currently active queue. More... | |
void | setQueueAddress (uint32_t address) |
Change the host physical address of the currently active queue. More... | |
uint32_t | getQueueAddress () const |
Get the host physical address of the currently active queue. More... | |
uint16_t | getQueueSize () const |
Get the size (descriptors) of the currently active queue. More... | |
void | setDeviceStatus (DeviceStatus status) |
Update device status and optionally reset device. More... | |
DeviceStatus | getDeviceStatus () const |
Retrieve the device status. More... | |
void | setGuestFeatures (FeatureBits features) |
Set feature bits accepted by the guest driver. More... | |
FeatureBits | getGuestFeatures () const |
Get features accepted by the guest driver. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from SimObject | |
static void | serializeAll (CheckpointOut &cp) |
Serialize all SimObjects in the system. More... | |
static SimObject * | find (const char *name) |
Find the SimObject with the given name and return a pointer to it. More... | |
Static Public Member Functions inherited from Serializable | |
static const std::string & | currentSection () |
Get the fully-qualified name of the active section. More... | |
static void | serializeAll (const std::string &cpt_dir) |
static void | unserializeGlobals (CheckpointIn &cp) |
Static Public Attributes inherited from Serializable | |
static int | ckptCount = 0 |
static int | ckptMaxCount = 0 |
static int | ckptPrevCount = -1 |
Protected Attributes inherited from SimObject | |
const SimObjectParams * | _params |
Cached copy of the object parameters. More... | |
Protected Attributes inherited from EventManager | |
EventQueue * | eventq |
A pointer to this object's event queue. More... | |
Base class for all VirtIO-based devices.
This class implements the functionality of the VirtIO 0.9.5 specification. This version of VirtIO is also known as "legacy" in the VirtIO 1.0 specification from OASIS.
typedef uint16_t VirtIODeviceBase::DeviceId |
typedef uint32_t VirtIODeviceBase::FeatureBits |
typedef uint16_t VirtIODeviceBase::QueueID |
typedef uint16_t VirtIODeviceBase::VirtAddress |
VirtIODeviceBase::VirtIODeviceBase | ( | Params * | params, |
DeviceId | id, | ||
size_t | config_size, | ||
FeatureBits | features | ||
) |
VirtIODeviceBase::BitUnion8 | ( | DeviceStatus | ) |
VirtIODeviceBase::EndBitUnion | ( | DeviceStatus | ) |
|
private |
Convenience method to get the currently selected queue.
Definition at line 445 of file base.cc.
References _queues, _queueSelect, and panic.
Referenced by getQueueAddress(), getQueueSize(), and setQueueAddress().
|
private |
Convenience method to get the currently selected queue.
Definition at line 454 of file base.cc.
References _queues, _queueSelect, and panic.
|
inline |
Retrieve the device status.
Definition at line 829 of file base.hh.
References _deviceStatus.
Referenced by PciVirtIO::read().
|
inline |
Get features accepted by the guest driver.
Definition at line 844 of file base.hh.
References guestFeatures.
Referenced by PciVirtIO::read().
uint32_t VirtIODeviceBase::getQueueAddress | ( | ) | const |
Get the host physical address of the currently active queue.
Definition at line 469 of file base.cc.
References VirtQueue::ALIGN_BITS, and getCurrentQueue().
Referenced by PciVirtIO::read().
|
inline |
Get the currently active queue.
The transport interface works on a queue at a time. The currently active queue is decided by the value of the queue select field in a device.
Definition at line 774 of file base.hh.
References _queueSelect.
Referenced by PciVirtIO::read().
|
inline |
Get the size (descriptors) of the currently active queue.
Definition at line 812 of file base.hh.
References getCurrentQueue(), and VirtQueue::getSize().
Referenced by PciVirtIO::read().
|
inlineprotected |
Inform the guest of available buffers.
When a device model has finished processing incoming buffers (after onNotify has been called), it typically needs to inform the guest that there are new pending outgoing buffers. The method used to inform the guest is transport dependent, but is typically through an interrupt. Device models call this method to tell the transport interface to notify the guest.
Definition at line 620 of file base.hh.
References Callback::process(), and transKick.
Referenced by VirtIOBlock::RequestQueue::onNotifyDescriptor(), VirtIO9PBase::sendRMsg(), and VirtIOConsole::TermRecvQueue::trySend().
void VirtIODeviceBase::onNotify | ( | QueueID | index | ) |
Driver is requesting service.
This method is called by the underlying hardware interface (e.g., PciVirtIO or MmmioVirtIO) to notify a device of pending incoming descriptors.
index | ID of the queue with pending actions. |
Definition at line 372 of file base.cc.
References _queues, DPRINTF, and panic.
Referenced by PciVirtIO::write().
Read from the configuration space of a device.
This method is called by the transport interface to read data from a device model's configuration space. The device model should use the cfgOffset parameter as the offset into its configuration space.
pkt | Read request packet. |
cfgOffset | Offset into the device's configuration space. |
Reimplemented in VirtIO9PBase, VirtIOBlock, and VirtIOConsole.
Definition at line 408 of file base.cc.
References panic.
Referenced by PciVirtIO::read().
|
protected |
Read configuration data from a device structure.
pkt | Read request packet. |
cfgOffset | Offset into the device's configuration space. |
cfg | Device configuration |
Definition at line 420 of file base.cc.
References configSize, Packet::getSize(), Packet::makeResponse(), panic, Packet::setData(), and X86ISA::size().
Referenced by VirtIOConsole::readConfig(), VirtIOBlock::readConfig(), and VirtIO9PBase::readConfig().
|
inline |
|
protected |
Register a new VirtQueue with the device model.
Devices typically register at least one VirtQueue to use for communication with the guest. This must be done from the constructor since the number of queues are assumed to be constant throughout the lifetime of the device.
Definition at line 477 of file base.cc.
References _queues.
Referenced by VirtIO9PBase::VirtIO9PBase(), VirtIOBlock::VirtIOBlock(), and VirtIOConsole::VirtIOConsole().
|
virtual |
Driver-request device reset.
The device driver may reset a device by writing zero to the device status register (using setDeviceStatus()), which causes this method to be called. Device models overriding this method must ensure that the reset method of the base class is called when the device is reset.
Definition at line 361 of file base.cc.
References _deviceStatus, _queues, _queueSelect, guestFeatures, and ArmISA::i.
Referenced by setDeviceStatus().
|
overridevirtual |
Serialize an object.
Output an object's state into the current checkpoint section.
cp | Checkpoint state |
Implements Serializable.
Reimplemented in VirtIO9PProxy.
Definition at line 341 of file base.cc.
References _deviceStatus, _queues, _queueSelect, csprintf(), guestFeatures, ArmISA::i, SERIALIZE_SCALAR, and Serializable::serializeSection().
Referenced by VirtIO9PProxy::serialize().
void VirtIODeviceBase::setDeviceStatus | ( | DeviceStatus | status | ) |
Update device status and optionally reset device.
The special device status of 0 is used to reset the device by calling reset().
status | New device status. |
Definition at line 398 of file base.cc.
References _deviceStatus, DPRINTF, reset(), and ArmISA::status.
Referenced by PciVirtIO::write().
void VirtIODeviceBase::setGuestFeatures | ( | FeatureBits | features | ) |
Set feature bits accepted by the guest driver.
This enables a subset of the features offered by the device model through the getGuestFeatures() interface.
Definition at line 384 of file base.cc.
References deviceFeatures, DPRINTF, guestFeatures, and panic.
Referenced by PciVirtIO::write().
void VirtIODeviceBase::setQueueAddress | ( | uint32_t | address | ) |
Change the host physical address of the currently active queue.
address | New address of the currently active queue (in pages). |
Definition at line 463 of file base.cc.
References VirtQueue::ALIGN_SIZE, getCurrentQueue(), and VirtQueue::setAddress().
Referenced by PciVirtIO::write().
|
inline |
Change currently active queue.
The transport interface works on a queue at a time. The currently active queue is decided by the value of the queue select field in a device.
idx | ID of the queue to select. |
Definition at line 764 of file base.hh.
References _queueSelect.
Referenced by PciVirtIO::write().
|
overridevirtual |
Unserialize an object.
Read an object's state from the current checkpoint section.
cp | Checkpoint state |
Implements Serializable.
Reimplemented in VirtIO9PProxy.
Definition at line 351 of file base.cc.
References _deviceStatus, _queues, _queueSelect, csprintf(), guestFeatures, ArmISA::i, UNSERIALIZE_SCALAR, and Serializable::unserializeSection().
Referenced by VirtIO9PProxy::unserialize().
Write to the configuration space of a device.
This method is called by the transport interface to write data into a device model's configuration space. The device model should use the cfgOffset parameter as the offset into its configuration space.
pkt | Write request packet. |
cfgOffset | Offset into the device's configuration space. |
Definition at line 414 of file base.cc.
References panic.
Referenced by PciVirtIO::write().
Write configuration data to a device structure.
pkt | Write request packet. |
cfgOffset | Offset into the device's configuration space. |
cfg | Device configuration |
Definition at line 432 of file base.cc.
References configSize, Packet::getSize(), Packet::makeResponse(), panic, X86ISA::size(), and Packet::writeData().
|
private |
Status of the device.
Definition at line 868 of file base.hh.
Referenced by getDeviceStatus(), reset(), serialize(), setDeviceStatus(), and unserialize().
|
private |
List of virtual queues supported by this device.
Definition at line 874 of file base.hh.
Referenced by getCurrentQueue(), onNotify(), registerQueue(), reset(), serialize(), and unserialize().
|
private |
Queue select register (set by guest)
Definition at line 871 of file base.hh.
Referenced by getCurrentQueue(), getQueueSelect(), reset(), serialize(), setQueueSelect(), and unserialize().
const size_t VirtIODeviceBase::configSize |
Size of the device's configuration space.
Definition at line 850 of file base.hh.
Referenced by PciVirtIO::PciVirtIO(), readConfigBlob(), VirtIO9PBase::VirtIO9PBase(), and writeConfigBlob().
const FeatureBits VirtIODeviceBase::deviceFeatures |
Feature set offered by the device.
Definition at line 853 of file base.hh.
Referenced by PciVirtIO::read(), and setGuestFeatures().
const DeviceId VirtIODeviceBase::deviceId |
Device ID (sometimes known as subsystem ID)
Definition at line 847 of file base.hh.
Referenced by PciVirtIO::PciVirtIO().
|
protected |
Feature set accepted by the guest.
When the guest starts the driver for the device, it starts by negotiating features. The device first offers a set of features (see deviceFeatures), the driver then notifies the device of which features it accepted. The base class will automatically accept any feature set that is a subset of the features offered by the device.
Definition at line 649 of file base.hh.
Referenced by getGuestFeatures(), reset(), serialize(), setGuestFeatures(), and unserialize().
|
private |
Callbacks to kick the guest through the transport layer.
Definition at line 877 of file base.hh.
Referenced by kick(), and registerKickCallback().