gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
VirtQueue Class Reference

Base wrapper around a virtqueue. More...

#include <base.hh>

Inheritance diagram for VirtQueue:
Serializable VirtIO9PBase::FSQueue VirtIOBlock::RequestQueue VirtIOConsole::TermRecvQueue VirtIOConsole::TermTransQueue

Classes

class  VirtRing
 VirtIO ring buffer wrapper. More...
 

Public Member Functions

virtual ~VirtQueue ()
 
Checkpointing Interface
void serialize (CheckpointOut &cp) const override
 Serialize an object. More...
 
void unserialize (CheckpointIn &cp) override
 Unserialize an object. More...
 
Low-level Device Interface
void setAddress (Addr address)
 Set the base address of this queue. More...
 
Addr getAddress () const
 Get the guest physical address of this queue. More...
 
uint16_t getSize () const
 Get the number of descriptors available in this queue. More...
 
VirtDescriptorgetDescriptor (VirtDescriptor::Index index)
 Get a pointer to a specific descriptor in the queue. More...
 
Device Model Interfaces
VirtDescriptorconsumeDescriptor ()
 Get an incoming descriptor chain from the queue. More...
 
void produceDescriptor (VirtDescriptor *desc, uint32_t len)
 Send a descriptor chain to the guest. More...
 
Device Model Callbacks
virtual void onNotify ()
 Notify queue of pending events. More...
 
virtual void onNotifyDescriptor (VirtDescriptor *desc)
 Notify queue of pending incoming descriptor. More...
 
Debug interfaces
void dump () const
 Dump the contents of a queue. More...
 
- 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)
 

Static Public Attributes

static const unsigned ALIGN_BITS = 12
 Page size used by VirtIO. It's hard-coded to 4096 bytes in the spec for historical reasons. More...
 
static const unsigned ALIGN_SIZE = 1 << ALIGN_BITS
 
- Static Public Attributes inherited from Serializable
static int ckptCount = 0
 
static int ckptMaxCount = 0
 
static int ckptPrevCount = -1
 

Protected Member Functions

 VirtQueue (PortProxy &proxy, uint16_t size)
 Instantiate a new virtqueue. More...
 

Private Member Functions

 VirtQueue ()
 

Private Attributes

const uint16_t _size
 Queue size in terms of number of descriptors. More...
 
Addr _address
 Base address of the queue. More...
 
PortProxymemProxy
 Guest physical memory proxy. More...
 
VirtRing< VirtDescriptor::Indexavail
 Ring of available (incoming) descriptors. More...
 
VirtRing< struct vring_used_elemused
 Ring of used (outgoing) descriptors. More...
 
uint16_t _last_avail
 Offset of last consumed descriptor in the VirtQueue::avail ring. More...
 
std::vector< VirtDescriptordescriptors
 Vector of pre-created descriptors indexed by their index into the queue. More...
 

Additional Inherited Members

- 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)
 

Detailed Description

Base wrapper around a virtqueue.

VirtIO device models typically need to extend this class to implement their own device queues.

Note
Queues must be registered with VirtIODeviceBase::registerQueue() to be active.

Definition at line 317 of file base.hh.

Constructor & Destructor Documentation

virtual VirtQueue::~VirtQueue ( )
inlinevirtual

Definition at line 319 of file base.hh.

VirtQueue::VirtQueue ( PortProxy proxy,
uint16_t  size 
)
protected

Instantiate a new virtqueue.

Instantiate a virtqueue with a fixed size. The size is specified in descriptors which are defined as 4096 bytes each.

Parameters
proxyProxy to the guest physical memory.
sizeSize in descriptors/pages.

Definition at line 227 of file base.cc.

References _size, descriptors, and ArmISA::i.

VirtQueue::VirtQueue ( )
private

Member Function Documentation

VirtDescriptor * VirtQueue::consumeDescriptor ( )

Get an incoming descriptor chain from the queue.

Returns
Pointer to descriptor on success, NULL if no pending descriptors are available.

Definition at line 271 of file base.cc.

References _last_avail, avail, ArmISA::d, descriptors, DPRINTF, VirtQueue::VirtRing< T >::header, MipsISA::index, VirtQueue::VirtRing< T >::read(), VirtQueue::VirtRing< T >::ring, VirtDescriptor::updateChain(), and used.

Referenced by onNotify(), and VirtIOConsole::TermRecvQueue::trySend().

void VirtQueue::dump ( ) const

Dump the contents of a queue.

Definition at line 304 of file base.cc.

References ArmISA::d, descriptors, and DTRACE.

Addr VirtQueue::getAddress ( ) const
inline

Get the guest physical address of this queue.

Returns
Physical address in guest where this queue resides.

Definition at line 341 of file base.hh.

References _address.

Referenced by VirtDescriptor::update().

VirtDescriptor* VirtQueue::getDescriptor ( VirtDescriptor::Index  index)
inline

Get a pointer to a specific descriptor in the queue.

Note
This interfaces is normally only used by VirtDescriptor to follow descriptor chains. Device models typically don't need to use it.
Returns
Pointer to a VirtDescriptor.

Definition at line 359 of file base.hh.

References descriptors, and MipsISA::index.

Referenced by VirtDescriptor::next().

uint16_t VirtQueue::getSize ( ) const
inline

Get the number of descriptors available in this queue.

Returns
Size of queue in descriptors.

Definition at line 348 of file base.hh.

References _size.

Referenced by VirtIODeviceBase::getQueueSize().

void VirtQueue::onNotify ( )
virtual

Notify queue of pending events.

This method is called by VirtIODeviceBase::onNotify() to notify the device model of pending data in a virtqueue. The default implementation of this method iterates over the available descriptor chains and calls onNotifyDescriptor() for every new incoming chain.

Device models should normally overload one of onNotify() and onNotifyDescriptor().

Reimplemented in VirtIOConsole::TermRecvQueue.

Definition at line 314 of file base.cc.

References consumeDescriptor(), ArmISA::d, DPRINTF, and onNotifyDescriptor().

virtual void VirtQueue::onNotifyDescriptor ( VirtDescriptor desc)
inlinevirtual

Notify queue of pending incoming descriptor.

This method is called by the default implementation of onNotify() to notify the device model of pending data in a descriptor chain.

Device models should normally overload one of onNotify() and onNotifyDescriptor().

Reimplemented in VirtIOBlock::RequestQueue, VirtIO9PBase::FSQueue, and VirtIOConsole::TermTransQueue.

Definition at line 421 of file base.hh.

Referenced by onNotify().

void VirtQueue::produceDescriptor ( VirtDescriptor desc,
uint32_t  len 
)

Send a descriptor chain to the guest.

This method posts a descriptor chain to the guest after a device model has finished processing it. The device model typically needs to call VirtIODeviceBase::kick() to deliver notify tell the guest that the queue has been updated.

Note
The desc parameter must refer to the first descriptor in a chain that has been retrieved using consumeDescriptor().
The len parameter specified the amount of data produced by the device model. It seems to be ignored by Linux and it is not well defined.
Parameters
descStart of descriptor chain.
lenLength of the produced data.

Definition at line 290 of file base.cc.

References DPRINTF, ArmISA::e, VirtQueue::VirtRing< T >::header, VirtDescriptor::index(), ArmISA::len, VirtQueue::VirtRing< T >::readHeader(), VirtQueue::VirtRing< T >::ring, used, and VirtQueue::VirtRing< T >::write().

Referenced by VirtIOBlock::RequestQueue::onNotifyDescriptor(), VirtIO9PBase::sendRMsg(), and VirtIOConsole::TermRecvQueue::trySend().

void VirtQueue::serialize ( CheckpointOut cp) const
overridevirtual

Serialize an object.

Output an object's state into the current checkpoint section.

Parameters
cpCheckpoint state

Implements Serializable.

Definition at line 238 of file base.cc.

References _address, _last_avail, and SERIALIZE_SCALAR.

void VirtQueue::setAddress ( Addr  address)

Set the base address of this queue.

Parameters
addressGuest physical base address of the queue.

Definition at line 258 of file base.cc.

References _address, _size, ALIGN_SIZE, avail, VirtQueue::VirtRing< T >::setAddress(), and used.

Referenced by VirtIODeviceBase::setQueueAddress(), and unserialize().

void VirtQueue::unserialize ( CheckpointIn cp)
overridevirtual

Unserialize an object.

Read an object's state from the current checkpoint section.

Parameters
cpCheckpoint state

Implements Serializable.

Definition at line 245 of file base.cc.

References _last_avail, paramIn(), setAddress(), and UNSERIALIZE_SCALAR.

Member Data Documentation

Addr VirtQueue::_address
private

Base address of the queue.

Definition at line 458 of file base.hh.

Referenced by getAddress(), serialize(), and setAddress().

uint16_t VirtQueue::_last_avail
private

Offset of last consumed descriptor in the VirtQueue::avail ring.

Definition at line 553 of file base.hh.

Referenced by consumeDescriptor(), serialize(), and unserialize().

const uint16_t VirtQueue::_size
private

Queue size in terms of number of descriptors.

Definition at line 456 of file base.hh.

Referenced by getSize(), setAddress(), and VirtQueue().

const unsigned VirtQueue::ALIGN_BITS = 12
static

Page size used by VirtIO. It's hard-coded to 4096 bytes in the spec for historical reasons.

Definition at line 436 of file base.hh.

Referenced by VirtIODeviceBase::getQueueAddress().

const unsigned VirtQueue::ALIGN_SIZE = 1 << ALIGN_BITS
static

Definition at line 437 of file base.hh.

Referenced by setAddress(), and VirtIODeviceBase::setQueueAddress().

VirtRing<VirtDescriptor::Index> VirtQueue::avail
private

Ring of available (incoming) descriptors.

Definition at line 547 of file base.hh.

Referenced by consumeDescriptor(), and setAddress().

std::vector<VirtDescriptor> VirtQueue::descriptors
private

Vector of pre-created descriptors indexed by their index into the queue.

Definition at line 557 of file base.hh.

Referenced by consumeDescriptor(), dump(), getDescriptor(), and VirtQueue().

PortProxy& VirtQueue::memProxy
private

Guest physical memory proxy.

Definition at line 460 of file base.hh.

VirtRing<struct vring_used_elem> VirtQueue::used
private

Ring of used (outgoing) descriptors.

Definition at line 549 of file base.hh.

Referenced by consumeDescriptor(), produceDescriptor(), and setAddress().


The documentation for this class was generated from the following files:

Generated on Fri Jun 9 2017 13:04:23 for gem5 by doxygen 1.8.6