Go to the documentation of this file.
41 #include "debug/VIO.hh"
42 #include "params/VirtIODeviceBase.hh"
43 #include "params/VirtIODummyDevice.hh"
51 : memProxy(&_memProxy), queue(&_queue),
byteOrder(
bo), _index(descIndex),
58 *
this = std::forward<VirtDescriptor>(other);
68 memProxy = std::move(rhs.memProxy);
69 queue = std::move(rhs.queue);
71 _index = std::move(rhs._index);
72 desc = std::move(rhs.desc);
85 assert(_index < queue->getSize());
91 "VirtDescriptor(%i): Addr: 0x%x, Len: %i, Flags: 0x%x, "
105 panic(
"Loop in descriptor chain!\n");
114 DPRINTF(VIO,
"Descriptor[%i]: "
115 "Addr: 0x%x, Len: %i, Flags: 0x%x, Next: 0x%x\n",
150 DPRINTF(VIO,
"VirtDescriptor(%p, 0x%x, %i)::read: offset: %i, dst: 0x%x, size: %i\n",
154 panic(
"Trying to read from outgoing buffer\n");
162 DPRINTF(VIO,
"VirtDescriptor(%p, 0x%x, %i)::write: offset: %i, src: 0x%x, size: %i\n",
166 panic(
"Trying to write to incoming buffer\n");
175 const size_t full_size(
size);
177 if (offset < desc->
size()) {
189 panic(
"Failed to read %i bytes from chain of %i bytes @ offset %i\n",
198 const size_t full_size(
size);
200 if (offset < desc->
size()) {
212 panic(
"Failed to write %i bytes into chain of %i bytes @ offset %i\n",
232 :
byteOrder(
bo), _size(size), _address(0), memProxy(proxy),
233 avail(proxy,
bo, size), used(proxy,
bo, size),
253 paramIn(cp,
"_address", addr_in);
276 _size *
sizeof(uint16_t));
277 const Addr addr_used((addr_avail_end +
sizeof(uint16_t) +
288 DPRINTF(VIO,
"consumeDescriptor: _last_avail: %i, avail.idx: %i (->%i)\n",
307 DPRINTF(VIO,
"produceDescriptor: dscIdx: %i, len: %i, used.idx: %i\n",
344 deviceId(
id), configSize(config_size), deviceFeatures(features),
345 _deviceStatus(0), _queueSelect(0)
388 DPRINTF(VIO,
"onNotify: idx: %i\n", idx);
390 panic(
"Guest tried to notify queue (%i), but only %i "
391 "queues registered.\n",
400 DPRINTF(VIO,
"Setting guest features: 0x%x\n", features);
402 panic(
"Guest tried to enable unsupported features:\n"
403 "Device features: 0x%x\n"
404 "Requested features: 0x%x\n",
415 DPRINTF(VIO,
"ACK: %i, DRIVER: %i, DRIVER_OK: %i, FAILED: %i\n",
424 panic(
"Unhandled device config read (offset: 0x%x).\n", cfgOffset);
430 panic(
"Unhandled device config write (offset: 0x%x).\n", cfgOffset);
436 const unsigned size(pkt->
getSize());
439 panic(
"Config read out of bounds.\n");
442 pkt->
setData(
const_cast<uint8_t *
>(cfg) + cfgOffset);
448 const unsigned size(pkt->
getSize());
451 panic(
"Config write out of bounds.\n");
454 pkt->
writeData((uint8_t *)cfg + cfgOffset);
const VirtQueue & getCurrentQueue() const
Convenience method to get the currently selected queue.
VirtRing< struct vring_used_elem > used
Ring of used (outgoing) descriptors.
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
void writeConfigBlob(PacketPtr pkt, Addr cfgOffset, uint8_t *cfg)
Write configuration data to a device structure.
virtual ~VirtIODeviceBase()
void write(size_t offset, const uint8_t *src, size_t size)
Write to the contents of a descriptor.
void dumpChain() const
Dump the contents of a descriptor chain starting at this descriptor.
#define UNSERIALIZE_SCALAR(scalar)
Index index() const
Get the descriptor's index into the virtqueue.
VirtDescriptor & operator=(VirtDescriptor &&rhs) noexcept
vring_desc desc
Underlying descriptor.
void setData(const uint8_t *p)
Copy data into the packet from the provided pointer.
bool hasNext() const
Is this descriptor chained to another descriptor?
uint16_t DeviceId
Device Type (sometimes known as subsystem ID)
Addr getAddress() const
Get the guest physical address of this queue.
uint16_t Index
Descriptor index in virtqueue.
bool isIncoming() const
Check if this is a read-only descriptor (incoming data).
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void update()
Populate this descriptor with data from the guest.
void reset()
Reset cached state in this queue and in the associated ring buffers.
VirtQueue * queue
Pointer to virtqueue owning this descriptor.
void dump() const
Dump the contents of a queue.
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
QueueID _queueSelect
Queue select register (set by guest)
const size_t configSize
Size of the device's configuration space.
static const Addr ALIGN_BITS
Page size used by VirtIO. It's hard-coded to 4096 bytes in the spec for historical reasons.
virtual void writeConfig(PacketPtr pkt, Addr cfgOffset)
Write to the configuration space of a device.
ByteOrder byteOrder(const ThreadContext *tc)
std::string csprintf(const char *format, const Args &...args)
void chainWrite(size_t offset, const uint8_t *src, size_t size)
Write to a descriptor chain.
void setGuestFeatures(FeatureBits features)
Set feature bits accepted by the guest driver.
void dump() const
Dump the contents of a descriptor.
void reset()
Reset any state in the ring buffer.
void readConfigBlob(PacketPtr pkt, Addr cfgOffset, const uint8_t *cfg)
Read configuration data from a device structure.
VirtDescriptor * next() const
Get the pointer to the next descriptor in a chain.
bool isOutgoing() const
Check if this is a write-only descriptor (outgoing data).
virtual void reset()
Driver-request device reset.
void serialize(CheckpointOut &cp) const override
Serialize an object.
Base wrapper around a virtqueue.
virtual void onNotify()
Notify queue of pending events.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
size_t chainSize() const
Retrieve the size of this descriptor chain.
void registerQueue(VirtQueue &queue)
Register a new VirtQueue with the device model.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
void setQueueAddress(uint32_t address)
Change the host physical address of the currently active queue.
std::vector< VirtQueue * > _queues
List of virtual queues supported by this device.
DeviceStatus _deviceStatus
Status of the device.
void setAddress(Addr address)
Set the base address of this queue.
PortProxy * memProxy
Pointer to memory proxy.
const FeatureBits deviceFeatures
Feature set offered by the device.
size_t size() const
Retrieve the size of this descriptor.
void readHeader()
Update the ring buffer header with data from the guest.
T gtoh(T value, ByteOrder guest_byte_order)
FeatureBits guestFeatures
Feature set accepted by the guest.
This object is a proxy for a port or other object which implements the functional response protocol,...
VirtIODummyDevice(const VirtIODummyDeviceParams ¶ms)
ByteOrder byteOrder
The byte order the descriptor is stored in.
Base class for all VirtIO-based devices.
void onNotify(QueueID index)
Driver is requesting service.
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Abstract superclass for simulation objects.
void writeData(uint8_t *p) const
Copy data from the packet to the memory at the provided pointer.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
std::vector< VirtDescriptor > descriptors
Vector of pre-created descriptors indexed by their index into the queue.
Header header
Ring buffer header in host byte order.
#define SERIALIZE_SCALAR(scalar)
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
void setAddress(Addr addr)
Set the base address of the VirtIO ring buffer.
const uint16_t _size
Queue size in terms of number of descriptors.
Index _index
Index in virtqueue.
VirtRing< VirtDescriptor::Index > avail
Ring of available (incoming) descriptors.
virtual void onNotifyDescriptor(VirtDescriptor *desc)
Notify queue of pending incoming descriptor.
VirtIO descriptor (chain) wrapper.
static const Addr ALIGN_SIZE
void produceDescriptor(VirtDescriptor *desc, uint32_t len)
Send a descriptor chain to the guest.
VirtDescriptor * getDescriptor(VirtDescriptor::Index index)
Get a pointer to a specific descriptor in the queue.
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void chainRead(size_t offset, uint8_t *dst, size_t size) const
Read the contents of a descriptor chain.
VirtIODeviceBase(const Params ¶ms, DeviceId id, size_t config_size, FeatureBits features)
Addr _address
Base address of the queue.
std::ostream CheckpointOut
~VirtDescriptor() noexcept
uint16_t _last_avail
Offset of last consumed descriptor in the VirtQueue::avail ring.
std::vector< T > ring
Elements in ring in host byte order.
uint32_t getQueueAddress() const
Get the host physical address of the currently active queue.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void read(size_t offset, uint8_t *dst, size_t size) const
Read the contents of a descriptor.
VirtDescriptor * consumeDescriptor()
Get an incoming descriptor chain from the queue.
void updateChain()
Populate this descriptor chain with data from the guest.
virtual void readConfig(PacketPtr pkt, Addr cfgOffset)
Read from the configuration space of a device.
#define panic(...)
This implements a cprintf based panic() function.
void setDeviceStatus(DeviceStatus status)
Update device status and optionally reset device.
Generated on Sun Jul 30 2023 01:56:52 for gem5 by doxygen 1.8.17