gem5  v21.1.0.2
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
gem5::VirtQueue Class Reference

Base wrapper around a virtqueue. More...

#include <base.hh>

Inheritance diagram for gem5::VirtQueue:
gem5::Serializable gem5::VirtIO9PBase::FSQueue gem5::VirtIOBlock::RequestQueue gem5::VirtIOConsole::TermRecvQueue gem5::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 reset ()
 Reset cached state in this queue and in the associated ring buffers. More...
 
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 gem5::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 Addr ALIGN_BITS = 12
 Page size used by VirtIO. It's hard-coded to 4096 bytes in the spec for historical reasons. More...
 
static const Addr ALIGN_SIZE = 1 << ALIGN_BITS
 

Protected Member Functions

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

Protected Attributes

ByteOrder byteOrder
 Byte order in this queue. 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 gem5::Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section. More...
 
static void generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream)
 Generate a checkpoint file so that the serialization can be routed to it. More...
 

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 302 of file base.hh.

Constructor & Destructor Documentation

◆ ~VirtQueue()

virtual gem5::VirtQueue::~VirtQueue ( )
inlinevirtual

Definition at line 305 of file base.hh.

◆ VirtQueue() [1/2]

gem5::VirtQueue::VirtQueue ( PortProxy proxy,
ByteOrder  bo,
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 231 of file base.cc.

References _size, gem5::PowerISA::bo, descriptors, and gem5::ArmISA::i.

◆ VirtQueue() [2/2]

gem5::VirtQueue::VirtQueue ( )
private

Member Function Documentation

◆ consumeDescriptor()

VirtDescriptor * gem5::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 285 of file base.cc.

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

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

◆ dump()

void gem5::VirtQueue::dump ( ) const

Dump the contents of a queue.

Definition at line 318 of file base.cc.

References gem5::ArmISA::d, and descriptors.

◆ getAddress()

Addr gem5::VirtQueue::getAddress ( ) const
inline

Get the guest physical address of this queue.

Returns
Physical address in guest where this queue resides.

Definition at line 335 of file base.hh.

References _address.

Referenced by gem5::VirtDescriptor::update().

◆ getDescriptor()

VirtDescriptor* gem5::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 353 of file base.hh.

References descriptors, and gem5::MipsISA::index.

Referenced by gem5::VirtDescriptor::next().

◆ getSize()

uint16_t gem5::VirtQueue::getSize ( ) const
inline

Get the number of descriptors available in this queue.

Returns
Size of queue in descriptors.

Definition at line 342 of file base.hh.

References _size.

Referenced by gem5::VirtIODeviceBase::getQueueSize().

◆ onNotify()

void gem5::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 gem5::VirtIOConsole::TermRecvQueue.

Definition at line 328 of file base.cc.

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

◆ onNotifyDescriptor()

virtual void gem5::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 gem5::VirtIOBlock::RequestQueue, gem5::VirtIO9PBase::FSQueue, and gem5::VirtIOConsole::TermTransQueue.

Definition at line 415 of file base.hh.

Referenced by onNotify().

◆ produceDescriptor()

void gem5::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 304 of file base.cc.

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

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

◆ reset()

void gem5::VirtQueue::reset ( )

Reset cached state in this queue and in the associated ring buffers.

A client of this method should be the VirtIODeviceBase::reset.

Definition at line 262 of file base.cc.

References _address, _last_avail, avail, gem5::VirtQueue::VirtRing< T >::reset(), and used.

◆ serialize()

void gem5::VirtQueue::serialize ( CheckpointOut cp) const
overridevirtual

Serialize an object.

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

Parameters
cpCheckpoint state

Implements gem5::Serializable.

Definition at line 242 of file base.cc.

References _address, _last_avail, and SERIALIZE_SCALAR.

◆ setAddress()

void gem5::VirtQueue::setAddress ( Addr  address)

Set the base address of this queue.

Parameters
addressGuest physical base address of the queue.

Definition at line 272 of file base.cc.

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

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

◆ unserialize()

void gem5::VirtQueue::unserialize ( CheckpointIn cp)
overridevirtual

Unserialize an object.

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

Parameters
cpCheckpoint state

Implements gem5::Serializable.

Definition at line 249 of file base.cc.

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

Member Data Documentation

◆ _address

Addr gem5::VirtQueue::_address
private

Base address of the queue.

Definition at line 455 of file base.hh.

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

◆ _last_avail

uint16_t gem5::VirtQueue::_last_avail
private

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

Definition at line 570 of file base.hh.

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

◆ _size

const uint16_t gem5::VirtQueue::_size
private

Queue size in terms of number of descriptors.

Definition at line 453 of file base.hh.

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

◆ ALIGN_BITS

const Addr gem5::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 430 of file base.hh.

Referenced by gem5::VirtIODeviceBase::getQueueAddress().

◆ ALIGN_SIZE

const Addr gem5::VirtQueue::ALIGN_SIZE = 1 << ALIGN_BITS
static

◆ avail

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

Ring of available (incoming) descriptors.

Definition at line 564 of file base.hh.

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

◆ byteOrder

ByteOrder gem5::VirtQueue::byteOrder
protected

Byte order in this queue.

Definition at line 447 of file base.hh.

Referenced by gem5::VirtIOBlock::RequestQueue::onNotifyDescriptor().

◆ descriptors

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

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

Definition at line 574 of file base.hh.

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

◆ memProxy

PortProxy& gem5::VirtQueue::memProxy
private

Guest physical memory proxy.

Definition at line 457 of file base.hh.

◆ used

VirtRing<struct vring_used_elem> gem5::VirtQueue::used
private

Ring of used (outgoing) descriptors.

Definition at line 566 of file base.hh.

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


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

Generated on Tue Sep 21 2021 12:28:22 for gem5 by doxygen 1.8.17