virtq

package
v0.0.0-...-9c233c6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package virtq partially implements packed virtqueues as described by the Virtual I/O Device (VIRTIO) Version 1.2 spec. Split virtqueues are not supported.

Index

Constants

View Source
const (
	DescFNext     = 1 // buffer continues in the next descriptor
	DescFWrite    = 2 // buffer is device wo (otherwise ro)
	DescFIndirect = 4 // buffer contains a descriptor table
	DescFAvail    = 1 << 7
	DescFUsed     = 1 << 15
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	Desc []Desc
	// contains filtered or unexported fields
}

Chain is a descriptor chain in a packed virtqueue.

func (*Chain) Buf

func (c *Chain) Buf(i int) ([]byte, error)

Buf returns a slice aliasing the buffer described by the descriptor at the given index. It panics if the index is out of range. If the queue's MemAt callback fails, Buf returns the error.

func (*Chain) Release

func (c *Chain) Release(bytesWritten int) error

Release marks the chain as used, recording the number of bytes written to the chain. It returns an error if the queue's Notify callback fails.

type Config

type Config struct {
	MemAt  func(addr uint64, len int) ([]byte, error)
	Notify func() error
}

type Desc

type Desc struct {
	Addr  uint64
	Len   uint32
	ID    uint16
	Flags uint16
}

Desc is a packed virtqueue descriptor.

func (Desc) Continues

func (d Desc) Continues() bool

Continues returns true if the descriptor's buffer continues in the next descriptor.

func (Desc) IsIndirect

func (d Desc) IsIndirect() bool

IsIndirect returns true if the descriptor's buffer contains more descriptors.

func (Desc) IsRO

func (d Desc) IsRO() bool

IsRO returns true if the descriptor's buffer is device read-only.

func (Desc) IsWO

func (d Desc) IsWO() bool

IsWO returns true if the descriptor's buffer is device write-only.

type EventSuppress

type EventSuppress struct {
	Desc  uint16
	Flags uint16
}

EventSuppress is the driver or device event suppression area for a packed virtqueue.

func (EventSuppress) ShouldNotify

func (e EventSuppress) ShouldNotify(index uint16, wrap bool) bool

ShouldNotify returns true if a notification should be sent for the given descriptor index and wrap counter, or false if the event is suppressed.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a packed virtqueue.

func New

func New(ring []Desc, drvE, devE *EventSuppress, cfg Config) *Queue

New returns a new virtqueue backed by the given ring and event suppression areas.

func (*Queue) Next

func (q *Queue) Next() (avail *Chain, err error)

Next returns the next available descriptor chain, or nil if no descriptors are available. It returns an error if the queue's MemAt callback fails while resolving an indirect descriptor, or if an indirect descriptor has a malformed buffer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL