virtio

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlkIOPortStart = 0x6300
	BlkIOPortSize  = 0x100

	SectorSize = 512
)
View Source
const (
	NetIOPortStart = 0x6200
	NetIOPortSize  = 0x100
)
View Source
const (
	// The number of free descriptors in virt queue must exceed
	// MAX_SKB_FRAGS (16). Otherwise, packet transmission from
	// the guest to the host will be stopped.
	//
	// refs https://github.com/torvalds/linux/blob/5859a2b/drivers/net/virtio_net.c#L1754
	QueueSize = 32
)

Variables

View Source
var (
	ErrInvalidSel  = errors.New("queue sel is invalid")
	ErrIONotPermit = errors.New("IO is not permitted for virtio device")
	ErrNoTxPacket  = errors.New("no packet for tx")
	ErrNoRxPacket  = errors.New("no packet for rx")
	ErrVQNotInit   = errors.New("vq not initialized")
	ErrNoRxBuf     = errors.New("no buffer found for rx")
)

Functions

This section is empty.

Types

type Blk added in v0.0.7

type Blk struct {
	Hdr blkHdr

	VirtQueue    [1]*VirtQueue
	Mem          []byte
	LastAvailIdx [1]uint16

	IRQInjector IRQInjector
	// contains filtered or unexported fields
}

func NewBlk added in v0.0.7

func NewBlk(path string, irq uint8, irqInjector IRQInjector, mem []byte) (*Blk, error)

func (Blk) GetDeviceHeader added in v0.0.7

func (v Blk) GetDeviceHeader() pci.DeviceHeader

func (Blk) GetIORange added in v0.0.7

func (v Blk) GetIORange() (start, end uint64)

func (*Blk) IO added in v0.0.7

func (v *Blk) IO() error

func (Blk) IOInHandler added in v0.0.7

func (v Blk) IOInHandler(port uint64, bytes []byte) error

func (*Blk) IOOutHandler added in v0.0.7

func (v *Blk) IOOutHandler(port uint64, bytes []byte) error

func (*Blk) IOThreadEntry added in v0.0.7

func (v *Blk) IOThreadEntry()

type BlkReq added in v0.0.7

type BlkReq struct {
	Type uint32

	Sector uint64
	// contains filtered or unexported fields
}

type IRQInjector added in v0.0.6

type IRQInjector interface {
	InjectVirtioNetIRQ() error
	InjectVirtioBlkIRQ() error
}

type Net

type Net struct {
	Hdr netHdr

	VirtQueue    [2]*VirtQueue
	Mem          []byte
	LastAvailIdx [2]uint16

	IRQInjector IRQInjector
	// contains filtered or unexported fields
}

func NewNet

func NewNet(irq uint8, irqInjector IRQInjector, tap io.ReadWriter, mem []byte) *Net

func (Net) GetDeviceHeader

func (v Net) GetDeviceHeader() pci.DeviceHeader

func (Net) GetIORange

func (v Net) GetIORange() (start, end uint64)

func (Net) IOInHandler

func (v Net) IOInHandler(port uint64, bytes []byte) error

func (*Net) IOOutHandler

func (v *Net) IOOutHandler(port uint64, bytes []byte) error

func (*Net) Rx

func (v *Net) Rx() error

func (*Net) RxThreadEntry

func (v *Net) RxThreadEntry()

func (*Net) Tx

func (v *Net) Tx() error

func (*Net) TxThreadEntry

func (v *Net) TxThreadEntry()

type VirtQueue

type VirtQueue struct {
	DescTable [QueueSize]struct {
		Addr  uint64
		Len   uint32
		Flags uint16
		Next  uint16
	}

	AvailRing struct {
		Flags     uint16
		Idx       uint16
		Ring      [QueueSize]uint16
		UsedEvent uint16
	}

	UsedRing struct {
		Flags uint16
		Idx   uint16
		Ring  [QueueSize]struct {
			Idx uint32
			Len uint32
		}
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

refs: https://wiki.osdev.org/Virtio#Virtual_Queue_Descriptor

Jump to

Keyboard shortcuts

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