machine

package
v0.0.0-...-278237d Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2015 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemoryTypeReserved MemoryType = iota
	MemoryTypeUser                = 1
	MemoryTypeAcpi                = 2
	MemoryTypeSpecial             = 3
)
View Source
const (
	PciMsiXControlMasked = 0x4000
	PciMsiXControlEnable = 0x8000
)
View Source
const (
	PciClassStorage        PciClass = 0x1
	PciClassNetwork                 = 0x2
	PciClassDisplay                 = 0x3
	PciClassMultimedia              = 0x4
	PciClassMemory                  = 0x5
	PciClassBridge                  = 0x6
	PciClassCommunications          = 0x7
	PciClassBase                    = 0x8
	PciClassInput                   = 0x9
	PciClassDocking                 = 0xa
	PciClassProcessorts             = 0xb
	PciClassSerial                  = 0xc
	PciClassMisc                    = 0xff
)
View Source
const (
	PciConfigOffsetVendorId          = 0x0
	PciConfigOffsetDeviceId          = 0x2
	PciConfigOffsetCommand           = 0x4
	PciConfigOffsetStatus            = 0x6
	PciConfigOffsetRevision          = 0x8
	PciConfigOffsetProgIf            = 0x9
	PciConfigOffsetSubclassId        = 0xa
	PciConfigOffsetClassId           = 0xb
	PciConfigOffsetHeaderType        = 0xe
	PciConfigOffsetSubsystemVendorId = 0x2c
	PciConfigOffsetSubsystemDeviceId = 0x2e
	PciConfigOffsetCapabilities      = 0x34
	PciConfigOffsetInterruptLine     = 0x3c
	PciConfigOffsetInterruptPin      = 0x3d
)

Configuration offsets.

View Source
const (
	RtcSecond      = 0x00
	RtcSecondAlarm = 0x01
	RtcMinute      = 0x02
	RtcMinuteAlarm = 0x03
	RtcHour        = 0x04
	RtcHourAlarm   = 0x05
	RtcWeekday     = 0x06
	RtcDay         = 0x07
	RtcMonth       = 0x08
	RtcYear        = 0x09
	RtcStatusA     = 0xa
	RtcStatusB     = 0xb
	RtcIntr        = 0xc
	RtcStatusD     = 0xd
	RtcCentury     = 0x32
)
View Source
const (
	RtcStatusBDST   = 0x01
	RtcStatusB24HR  = 0x02
	RtcStatusBBIN   = 0x04
	RtcStatusBPINTR = 0x40
	RtcStatusBHALT  = 0x80
)
View Source
const (
	UartDefaultRclk = 1843200
	UartDefaultBaud = 9600
)
View Source
const (
	UartIerERXRDY = 0x1
	UartIerETXRDY = 0x2
	UartIerERLS   = 0x4
	UartIerEMSC   = 0x8
)
View Source
const (
	UartIirIMASK  = 0xf
	UartIirRXTOUT = 0xc
	UartIirBUSY   = 0x7
	UartIirRLS    = 0x6
	UartIirMLSC   = 0x5
	UartIirRXRDY  = 0x4
	UartIirTXRDY  = 0x2
	UartIirNOPEND = 0x1
)
View Source
const (
	UartMsrPRESCALE = 0x80
	UartMsrLOOPBACK = 0x10
	UartMsrIE       = 0x08
	UartMsrDRS      = 0x04
	UartMsrRTS      = 0x02

	UartMsrMASK = 0xf
)
View Source
const (
	UartLsrFIFO  = 0x80
	UartLsrTEMT  = 0x40
	UartLsrTHRE  = 0x20
	UartLsrBI    = 0x10
	UartLsrFE    = 0x08
	UartLsrPE    = 0x04
	UartLsrOE    = 0x02
	UartLsrRXRDY = 0x01
)
View Source
const (
	UartMsrDCD  = 0x80
	UartMsrRI   = 0x40
	UartMsrDSR  = 0x20
	UartMsrCTS  = 0x10
	UartMsrDDCD = 0x08
	UartMsrTERI = 0x04
	UartMsrDDSR = 0x02
	UartMsrDCTS = 0x01
)
View Source
const (
	VirtioStatusReboot   = 0x0
	VirtioStatusAck      = 0x1
	VirtioStatusDriver   = 0x2
	VirtioStatusDriverOk = 0x4
	VirtioStatusFailed   = 0x80
)

Virtio status.

View Source
const (
	VirtioTypeNet      = 1
	VirtioTypeBlock    = 2
	VirtioTypeConsole  = 3
	VirtioTypeEntropy  = 4
	VirtioTypeBalloon  = 5
	VirtioTypeIoMemory = 6
	VirtioTypeRpMsg    = 7
	VirtioTypeScsi     = 8
	VirtioType9p       = 9
)

Virtio device types.

View Source
const (
	VirtioOffsetHostCap     = 0x00
	VirtioOffsetGuestCap    = 0x04
	VirtioOffsetQueuePfn    = 0x08
	VirtioOffsetQueueSize   = 0x0c
	VirtioOffsetQueueSel    = 0x0e
	VirtioOffsetQueueNotify = 0x10
	VirtioOffsetStatus      = 0x12
	VirtioOffsetIsr         = 0x13
	VirtioOffsetCfgVec      = 0x14
	VirtioOffsetQueueVec    = 0x16
)

Our configuration space constants.

View Source
const (
	VirtioBlockTIn       = 0
	VirtioBlockTOut      = 1
	VirtioBlockTFlush    = 4
	VirtioBlockTFlushOut = 5
	VirtioBlockTBarrier  = 0x80000000
)

Commands.

View Source
const (
	VirtioBlockSOk          = 0
	VirtioBlockSIoErr       = 1
	VirtioBlockSUnsupported = 2
)

Status values.

View Source
const (
	VirtioConsoleFSize      = 1
	VirtioConsoleFMultiPort = 2
)
View Source
const (
	VirtioConsoleDeviceReady = 0
	VirtioConsolePortAdd     = 1
	VirtioConsolePortRemove  = 2
	VirtioConsolePortReady   = 3
	VirtioConsolePortConsole = 4
	VirtioConsolePortResize  = 5
	VirtioConsolePortOpen    = 6
	VirtioConsolePortName    = 7
)
View Source
const (
	VirtioNetFCsum     uint32 = 1 << 0
	VirtioNetFMac             = 1 << 5
	VirtioNetFHostTso4        = 1 << 11
	VirtioNetFHostTso6        = 1 << 12
	VirtioNetFHostEcn         = 1 << 13
	VirtioNetFHostUfo         = 1 << 14
	VirtioNetFStatus          = 1 << 16
)

Virtio Net Features

View Source
const (
	VirtioNetLinkUp   = (1 << 0)
	VirtioNetAnnounce = (1 << 1)
)

VirtioNet Status Bits

View Source
const (
	VirtioNetMacOffset    = 0
	VirtioNetMacLen       = 6
	VirtioNetStatusOffset = (VirtioNetMacOffset + VirtioNetMacLen)
	VirtioNetStatusLen    = 2
	VirtioNetConfigLen    = (VirtioNetMacLen + VirtioNetStatusLen)
)

VirtioNet Config Space

View Source
const (
	PciCapabilityMSIX = 0x11
)
View Source
const (
	PciCapabilityPortRoot = 0x40
)
View Source
const (
	PciFunctionVendor = 0
)
View Source
const (
	PciMsiXEntryControlMasked = 0x01
)
View Source
const (
	PciMsiXEntrySize = 0x10
)
View Source
const (
	RtcStatusATUP = 0x80
)
View Source
const (
	RtcStatusDPWR = 0x80
)
View Source
const (
	UartFcrRXMASK = 0xc0
)
View Source
const (
	UartLcrDLAB = 0x80
)
View Source
const (
	VirtioFsFMount = 1
)
View Source
const (
	VirtioNetHeaderSize = 10
)

VirtioNet VLAN support

View Source
const VirtioPciVendor = 0x1af4

Our vendor Id.

View Source
const (
	VirtioRingFEventIdx = 1 << 29
)

Generic features.

Variables

View Source
var Bin2Bcd = []uint8{
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
	0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
	0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
	0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
	0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
}
View Source
var DeviceAlreadyPaused = errors.New("Device already paused!")

Basic errors.

View Source
var DeviceNotPaused = errors.New("Device not paused!")
View Source
var InterruptConflict = errors.New("Device interrupt conflict!")

Interrupt allocation errors.

View Source
var InterruptUnavailable = errors.New("No interrupt available!")
View Source
var MemoryBusy = errors.New("Memory could not be allocated!")
View Source
var MemoryConflict = errors.New("Memory regions conflict!")

Memory allocation / layout errors.

View Source
var MemoryNotFound = errors.New("Memory region not found!")
View Source
var MemoryUnaligned = errors.New("Memory not aligned!")
View Source
var PciBusNotFound = errors.New("Requested PCI devices, but no bus found?")
View Source
var PciCapabilityMismatch = errors.New("Capability mismatch!")
View Source
var PciInvalidAddress = errors.New("Invalid PCI address!")

PCI errors.

View Source
var PciMSIError = errors.New("MSI internal error?")
View Source
var SaveIO = errors.New("Save I/O request (internal error).")

I/O memoize errors. This is an internal-only error which is returned from a write handler. When this is returned (and the cache has had a significant number of hits at that address) we will create an eventfd for that particular address and value. This will reduce the number of kernel-user switches necessary to handle that particular address.

View Source
var UartUnknown = errors.New("Unknown COM port.")

UART errors.

View Source
var UserMemoryNotFound = errors.New("No user memory found?")
View Source
var VirtioInvalidQueueSize = errors.New("Invalid VirtIO queue size!")

Virtio errors.

View Source
var VirtioUnsupportedVnetHeader = errors.New("Unsupported vnet header size.")

Functions

func DriverUnknown

func DriverUnknown(name string) error

Driver errors.

Types

type Acpi

type Acpi struct {
	BaseDevice

	Addr platform.Paddr `json:"address"`
	Data []byte         `json:"data"`
}

func (*Acpi) Attach

func (acpi *Acpi) Attach(vm *platform.Vm, model *Model) error

type Apic

type Apic struct {
	BaseDevice

	// Our addresses.
	// At the moment, these are at fixed address.
	// But just check that they meet expectations.
	IOApic platform.Paddr `json:"ioapic"`
	LApic  platform.Paddr `json:"lapic"`

	// Our platform APIC.
	State platform.IrqChip `json:"state"`
}

func (*Apic) Attach

func (apic *Apic) Attach(vm *platform.Vm, model *Model) error

func (*Apic) Load

func (apic *Apic) Load(vm *platform.Vm) error

func (*Apic) Save

func (apic *Apic) Save(vm *platform.Vm) error

type BaseDevice

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

func (*BaseDevice) Acquire

func (device *BaseDevice) Acquire()

func (*BaseDevice) Attach

func (device *BaseDevice) Attach(vm *platform.Vm, model *Model) error

func (*BaseDevice) Debug

func (device *BaseDevice) Debug(format string, v ...interface{})

func (*BaseDevice) Driver

func (device *BaseDevice) Driver() string

func (*BaseDevice) Interrupt

func (device *BaseDevice) Interrupt() error

func (*BaseDevice) IsDebugging

func (device *BaseDevice) IsDebugging() bool

func (*BaseDevice) Load

func (device *BaseDevice) Load(vm *platform.Vm) error

func (*BaseDevice) MmioHandlers

func (device *BaseDevice) MmioHandlers() IoHandlers

func (*BaseDevice) Name

func (device *BaseDevice) Name() string

func (*BaseDevice) Pause

func (device *BaseDevice) Pause(manual bool) error

func (*BaseDevice) PioHandlers

func (device *BaseDevice) PioHandlers() IoHandlers

func (*BaseDevice) Release

func (device *BaseDevice) Release()

func (*BaseDevice) Save

func (device *BaseDevice) Save(vm *platform.Vm) error

func (*BaseDevice) SetDebugging

func (device *BaseDevice) SetDebugging(debug bool)

func (*BaseDevice) Unpause

func (device *BaseDevice) Unpause(manual bool) error

type Bios

type Bios struct {
	BaseDevice

	// Our reserved TSS (for Intel VTX).
	TSSAddr platform.Paddr `json:"tss"`
}

func (*Bios) Attach

func (bios *Bios) Attach(vm *platform.Vm, model *Model) error

type Clock

type Clock struct {
	BaseDevice

	// Our clock state.
	Clock platform.Clock `json:"clock"`
}

func (*Clock) Attach

func (clock *Clock) Attach(vm *platform.Vm, model *Model) error

func (*Clock) Load

func (clock *Clock) Load(vm *platform.Vm) error

func (*Clock) Save

func (clock *Clock) Save(vm *platform.Vm) error

type Device

type Device interface {
	Name() string
	Driver() string

	PioHandlers() IoHandlers
	MmioHandlers() IoHandlers

	Attach(vm *platform.Vm, model *Model) error
	Load(vm *platform.Vm) error
	Save(vm *platform.Vm) error

	Pause(manual bool) error
	Unpause(manual bool) error

	Acquire()
	Release()

	Interrupt() error

	Debug(format string, v ...interface{})
	IsDebugging() bool
	SetDebugging(debug bool)
}

func NewAcpi

func NewAcpi(info *DeviceInfo) (Device, error)

func NewApic

func NewApic(info *DeviceInfo) (Device, error)

func NewBios

func NewBios(info *DeviceInfo) (Device, error)

func NewClock

func NewClock(info *DeviceInfo) (Device, error)

func NewPciBus

func NewPciBus(info *DeviceInfo) (Device, error)

func NewPciHostBridge

func NewPciHostBridge(info *DeviceInfo) (Device, error)

func NewPit

func NewPit(info *DeviceInfo) (Device, error)

func NewRtc

func NewRtc(info *DeviceInfo) (Device, error)

func NewUart

func NewUart(info *DeviceInfo) (Device, error)

func NewUserMemory

func NewUserMemory(info *DeviceInfo) (Device, error)

func NewVirtioMmioBlock

func NewVirtioMmioBlock(info *DeviceInfo) (Device, error)

func NewVirtioMmioConsole

func NewVirtioMmioConsole(info *DeviceInfo) (Device, error)

func NewVirtioMmioFs

func NewVirtioMmioFs(info *DeviceInfo) (Device, error)

func NewVirtioMmioNet

func NewVirtioMmioNet(info *DeviceInfo) (Device, error)

func NewVirtioPciBlock

func NewVirtioPciBlock(info *DeviceInfo) (Device, error)

func NewVirtioPciConsole

func NewVirtioPciConsole(info *DeviceInfo) (Device, error)

func NewVirtioPciFs

func NewVirtioPciFs(info *DeviceInfo) (Device, error)

func NewVirtioPciNet

func NewVirtioPciNet(info *DeviceInfo) (Device, error)

type DeviceInfo

type DeviceInfo struct {
	// Friendly name.
	Name string `json:"name"`

	// Driver name.
	Driver string `json:"driver"`

	// Device-specific info.
	Data interface{} `json:"data"`

	// Debugging?
	Debug bool `json:"debug"`
}

func NewDeviceInfo

func NewDeviceInfo(device Device) (DeviceInfo, error)

func (DeviceInfo) Load

func (info DeviceInfo) Load() (Device, error)

type Driver

type Driver func(info *DeviceInfo) (Device, error)

A driver load function.

type InterruptMap

type InterruptMap map[platform.Irq]Device

type IoCache

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

func NewIoCache

func NewIoCache(handlers []IoHandlers, is_pio bool) *IoCache

type IoEvent

type IoEvent interface {
	Size() uint

	GetData() uint64
	SetData(val uint64)

	IsWrite() bool
}

type IoHandler

type IoHandler struct {
	Device
	// contains filtered or unexported fields
}

func NewIoHandler

func NewIoHandler(
	device Device,
	start platform.Paddr,
	operations IoOperations) *IoHandler

func (*IoHandler) Run

func (io *IoHandler) Run()

type IoHandlers

type IoHandlers map[MemoryRegion]*IoHandler

type IoMap

type IoMap map[MemoryRegion]IoOperations

type IoOperations

type IoOperations interface {
	Read(offset uint64, size uint) (uint64, error)
	Write(offset uint64, size uint, value uint64) error
}

type IoQueue

type IoQueue chan IoRequest

func (IoQueue) Submit

func (queue IoQueue) Submit(event IoEvent, offset uint64) error

type IoRequest

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

type MemoryMap

type MemoryMap []*TypedMemoryRegion

MemoryMap --

Our collection of current memory regions.

func (*MemoryMap) Add

func (memory *MemoryMap) Add(region *TypedMemoryRegion) error

func (*MemoryMap) Allocate

func (memory *MemoryMap) Allocate(
	memtype MemoryType,
	start platform.Paddr,
	end platform.Paddr,
	size uint64,
	top bool) (platform.Paddr, []byte, error)

func (*MemoryMap) Conflicts

func (memory *MemoryMap) Conflicts(start platform.Paddr, size uint64) bool

func (*MemoryMap) Len

func (memory *MemoryMap) Len() int

func (*MemoryMap) Less

func (memory *MemoryMap) Less(i int, j int) bool

func (*MemoryMap) Load

func (memory *MemoryMap) Load(
	start platform.Paddr,
	end platform.Paddr,
	data []byte,
	top bool) (platform.Paddr, error)

func (*MemoryMap) Map

func (memory *MemoryMap) Map(
	memtype MemoryType,
	addr platform.Paddr,
	size uint64,
	allocate bool) ([]byte, error)

func (*MemoryMap) Max

func (memory *MemoryMap) Max() platform.Paddr

func (*MemoryMap) Reserve

func (memory *MemoryMap) Reserve(
	vm *platform.Vm,
	device Device,
	memtype MemoryType,
	start platform.Paddr,
	size uint64,
	user []byte) error

func (*MemoryMap) Swap

func (memory *MemoryMap) Swap(i int, j int)

type MemoryRegion

type MemoryRegion struct {
	Start platform.Paddr `json:"start"`
	Size  uint64         `json:"size"`
}

MemoryRegion --

This is a serializable type. It is basically a specification for a region of memory, but it doesn't carry any information about what type of region it should be (or the owner). This is used to track the runtime state of the model, and will be recreated from state on resume.

func (*MemoryRegion) Contains

func (region *MemoryRegion) Contains(start platform.Paddr, size uint64) bool

func (*MemoryRegion) End

func (region *MemoryRegion) End() platform.Paddr

func (*MemoryRegion) Overlaps

func (region *MemoryRegion) Overlaps(start platform.Paddr, size uint64) bool

type MemoryType

type MemoryType int

type MmioDevice

type MmioDevice struct {
	BaseDevice

	// A map of our available I/O.
	IoMap      `json:"-"`
	IoHandlers `json:"-"`

	// Our address in memory.
	Offset platform.Paddr `json:"address"`

	// Our assigned interrupt.
	InterruptNumber platform.Irq `json:"interrupt"`
	// contains filtered or unexported fields
}

func (*MmioDevice) Attach

func (mmio *MmioDevice) Attach(vm *platform.Vm, model *Model) error

func (*MmioDevice) MmioHandlers

func (mmio *MmioDevice) MmioHandlers() IoHandlers

type MmioEvent

type MmioEvent struct {
	*platform.ExitMmio
}

func (MmioEvent) GetData

func (mmio MmioEvent) GetData() uint64

func (MmioEvent) IsWrite

func (mmio MmioEvent) IsWrite() bool

func (MmioEvent) SetData

func (mmio MmioEvent) SetData(val uint64)

func (MmioEvent) Size

func (mmio MmioEvent) Size() uint

type Model

type Model struct {

	// Basic memory layout:
	// This is generally accessible from the loader,
	// and other modules that may need to tweak memory.
	MemoryMap

	// Basic interrupt layout:
	// This maps interrupts to devices.
	InterruptMap
	// contains filtered or unexported fields
}

func NewModel

func NewModel(vm *platform.Vm) (*Model, error)

func (*Model) CreateDevices

func (model *Model) CreateDevices(
	vm *platform.Vm,
	spec []DeviceInfo,
	debug bool) (Proxy, error)

func (*Model) DeviceInfo

func (model *Model) DeviceInfo(vm *platform.Vm) ([]DeviceInfo, error)

func (*Model) Devices

func (model *Model) Devices() []Device

func (*Model) Handle

func (model *Model) Handle(
	vm *platform.Vm,
	cache *IoCache,
	handler *IoHandler,
	ioevent IoEvent,
	addr platform.Paddr) error

func (*Model) HandleMmio

func (model *Model) HandleMmio(
	vm *platform.Vm,
	event *platform.ExitMmio) error

func (*Model) HandlePio

func (model *Model) HandlePio(
	vm *platform.Vm,
	event *platform.ExitPio) error

func (*Model) Load

func (model *Model) Load(vm *platform.Vm) error

func (*Model) Pause

func (model *Model) Pause(manual bool) error

func (*Model) Save

func (model *Model) Save(vm *platform.Vm) error

func (*Model) Unpause

func (model *Model) Unpause(manual bool) error

type MsiXConf

type MsiXConf struct {
	*MsiXDevice `json:"-"`

	// The MSI control register.
	Control Register `json:"control"`

	// The table offset (& BAR).
	TableOffset Register `json:"table"`

	// The PBA offset (& BAR).
	PbaOffset Register `json:"pba"`
}

func (*MsiXConf) Read

func (msix *MsiXConf) Read(offset uint64, size uint) (uint64, error)

func (*MsiXConf) Write

func (msix *MsiXConf) Write(offset uint64, size uint, value uint64) error

type MsiXDevice

type MsiXDevice struct {
	*PciDevice

	// Our Pci configuration.
	*MsiXConf

	// Our pending bit array.
	Pending *Ram `json:"pending"`

	// The entries are a device that we expose
	// to the PCI Bar as specified in the creation.
	Entries []MsiXEntry `json:"entries"`
	// contains filtered or unexported fields
}

func NewMsiXDevice

func NewMsiXDevice(
	pcidevice *PciDevice,
	barno uint,
	vectors uint) *MsiXDevice

func (*MsiXDevice) Attach

func (msix *MsiXDevice) Attach(vm *platform.Vm, model *Model) error

func (*MsiXDevice) CheckAllPending

func (msix *MsiXDevice) CheckAllPending()

func (*MsiXDevice) CheckPending

func (msix *MsiXDevice) CheckPending(vector int)

func (*MsiXDevice) ClearPending

func (msix *MsiXDevice) ClearPending(vector int)

func (*MsiXDevice) FindEntry

func (msix *MsiXDevice) FindEntry(vector int) *MsiXEntry

func (*MsiXDevice) IsMSIXEnabled

func (msix *MsiXDevice) IsMSIXEnabled() bool

func (*MsiXDevice) IsMasked

func (msix *MsiXDevice) IsMasked(vector int) bool

func (*MsiXDevice) IsPending

func (msix *MsiXDevice) IsPending(vector int) bool

func (*MsiXDevice) Read

func (msix *MsiXDevice) Read(offset uint64, size uint) (uint64, error)

func (*MsiXDevice) SendInterrupt

func (msix *MsiXDevice) SendInterrupt(vector int) error

func (*MsiXDevice) SetPending

func (msix *MsiXDevice) SetPending(vector int)

func (*MsiXDevice) Write

func (msix *MsiXDevice) Write(offset uint64, size uint, value uint64) error

type MsiXEntry

type MsiXEntry struct {
	*MsiXDevice `json:"-"`

	// The control dword.
	Control Register `json:"control"`

	// The lower address (+masked & pending bits).
	Address Register `json:"address"`

	// The Data.
	Data Register `json:"data"`
}

func (*MsiXEntry) Read

func (msix *MsiXEntry) Read(offset uint64, size uint) (uint64, error)

func (*MsiXEntry) Write

func (msix *MsiXEntry) Write(offset uint64, size uint, value uint64) error

type PciBarOps

type PciBarOps map[uint]IoOperations

Our bar operations will be called when the system maps any given bar. (The system may choose to map a size that is larger or smaller than the given bar size, this has to be handled).

type PciBarSizes

type PciBarSizes map[uint]uint32

Our barsizes determine what we report for the size of each bar to the system.

type PciBus

type PciBus struct {
	PioDevice

	// Our Mmio Handlers.
	IoHandlers `json:"-"`

	// Our pci hole in memory.
	Hole MemoryRegion `json:"hole"`

	// Our configuration address.
	Addr Register `json:"config-address"`

	// Our reserved high-mem region.
	MemoryRegion platform.Paddr `json:"reserved"`
	// contains filtered or unexported fields
}

func (*PciBus) AddDevice

func (pcibus *PciBus) AddDevice(device *PciDevice) error

func (*PciBus) Attach

func (pcibus *PciBus) Attach(vm *platform.Vm, model *Model) error

func (*PciBus) MmioHandlers

func (pcibus *PciBus) MmioHandlers() IoHandlers

type PciCapability

type PciCapability struct {

	// The pci capability id.
	Id byte `json:"id"`

	// The handlers.
	IoOperations `json:"-"`

	// The size of the data.
	Size uint64 `json:"size"`

	// The offset in configuration.
	// (NOTE: This does not include ptrs).
	Offset uint64 `json:"offset"`
}

The capability is a generic set of IoHandlers, (typically a device itself or register) associated with some offset in the pci configuration space.

type PciCapabilityMap

type PciCapabilityMap map[byte]*PciCapability

Our map of capabilities.

func (*PciCapabilityMap) MarshalJSON

func (capmap *PciCapabilityMap) MarshalJSON() ([]byte, error)

func (*PciCapabilityMap) UnmarshalJSON

func (capmap *PciCapabilityMap) UnmarshalJSON(data []byte) error

type PciClass

type PciClass uint8

type PciConfAddr

type PciConfAddr struct {
	*PciBus
}

func (*PciConfAddr) Read

func (reg *PciConfAddr) Read(offset uint64, size uint) (uint64, error)

func (*PciConfAddr) Write

func (reg *PciConfAddr) Write(offset uint64, size uint, value uint64) error

type PciConfData

type PciConfData struct {
	*PciBus
}

func (*PciConfData) Read

func (reg *PciConfData) Read(offset uint64, size uint) (uint64, error)

func (*PciConfData) Write

func (reg *PciConfData) Write(offset uint64, size uint, value uint64) error

type PciDevice

type PciDevice struct {
	MmioDevice

	// Packed configuration data.
	// (This encodes the vendor/device, etc.)
	Config *Ram `json:"config"`

	// Capabilities.
	// Once they have been built, we actually
	// call RefreshCapabilities to reload the map.
	Capabilities PciCapabilityMap `json:"capabilities"`

	// Bar sizes and operations.
	PciBarCount uint `json:"-"`
	PciBarSizes `json:"-"`
	PciBarOps   `json:"-"`
	// contains filtered or unexported fields
}

func NewPciDevice

func NewPciDevice(
	info *DeviceInfo,
	vendor_id PciVendorId,
	device_id PciDeviceId,
	class PciClass,
	revision PciRevision,
	subsystem_vendor_id PciSubsystemVendorId,
	subsystem_device_id PciSubsystemDeviceId) (*PciDevice, error)

func (*PciDevice) Attach

func (pcidevice *PciDevice) Attach(vm *platform.Vm, model *Model) error

func (*PciDevice) Interrupt

func (pcidevice *PciDevice) Interrupt() error

func (*PciDevice) RebuildBars

func (pcidevice *PciDevice) RebuildBars()

func (*PciDevice) RebuildCapabilities

func (pcidevice *PciDevice) RebuildCapabilities()

type PciDeviceId

type PciDeviceId uint16

type PciRevision

type PciRevision uint8

type PciSubsystemDeviceId

type PciSubsystemDeviceId PciDeviceId

type PciSubsystemVendorId

type PciSubsystemVendorId PciVendorId

type PciVendorId

type PciVendorId uint16

type PioDevice

type PioDevice struct {
	BaseDevice

	// A map of our available ports.
	IoMap      `json:"-"`
	IoHandlers `json:"-"`

	// Our address in memory.
	Offset platform.Paddr `json:"base"`
}

func (*PioDevice) Attach

func (pio *PioDevice) Attach(vm *platform.Vm, model *Model) error

func (*PioDevice) PioHandlers

func (pio *PioDevice) PioHandlers() IoHandlers

type PioEvent

type PioEvent struct {
	*platform.ExitPio
}

func (PioEvent) GetData

func (pio PioEvent) GetData() uint64

func (PioEvent) IsWrite

func (pio PioEvent) IsWrite() bool

func (PioEvent) SetData

func (pio PioEvent) SetData(val uint64)

func (PioEvent) Size

func (pio PioEvent) Size() uint

type Pit

type Pit struct {
	BaseDevice

	// Our pit state.
	// Similar to the pit, we consider the platform
	// PIT to be an intrinsic part of our "pit".
	Pit platform.PitState `json:"pit"`
}

func (*Pit) Attach

func (pit *Pit) Attach(vm *platform.Vm, model *Model) error

func (*Pit) Load

func (pit *Pit) Load(vm *platform.Vm) error

func (*Pit) Save

func (pit *Pit) Save(vm *platform.Vm) error

type Proxy

type Proxy interface {
	io.ReadWriteCloser
}

type Ram

type Ram struct {
	Data []byte `json:"data"`
}

func NewRam

func NewRam(size int) *Ram

func (*Ram) Get16

func (ram *Ram) Get16(offset int) uint16

func (*Ram) Get32

func (ram *Ram) Get32(offset int) uint32

func (*Ram) Get64

func (ram *Ram) Get64(offset int) uint64

func (*Ram) Get8

func (ram *Ram) Get8(offset int) uint8

func (*Ram) GrowTo

func (ram *Ram) GrowTo(size int)

func (*Ram) Read

func (ram *Ram) Read(offset uint64, size uint) (uint64, error)

func (*Ram) Set16

func (ram *Ram) Set16(offset int, data uint16)

func (*Ram) Set32

func (ram *Ram) Set32(offset int, data uint32)

func (*Ram) Set64

func (ram *Ram) Set64(offset int, data uint64)

func (*Ram) Set8

func (ram *Ram) Set8(offset int, data uint8)

func (*Ram) Size

func (ram *Ram) Size() int

func (*Ram) Write

func (ram *Ram) Write(offset uint64, size uint, value uint64) error

type Register

type Register struct {
	// The value of the register.
	Value uint64 `json:"value"`
	// contains filtered or unexported fields
}

func (*Register) Read

func (register *Register) Read(offset uint64, size uint) (uint64, error)

func (*Register) Write

func (register *Register) Write(offset uint64, size uint, value uint64) error

type Rtc

type Rtc struct {
	PioDevice

	// The time.
	Now time.Time `json:"now"`

	// Registers.
	Addr        uint8 `json:"selector"`
	AlarmSecond uint8 `json:"alarm-second"`
	AlarmMinute uint8 `json:"alarm-minute"`
	AlarmHour   uint8 `json:"alarm-hour"`
	StatusA     uint8 `json:"statusa"`
	StatusB     uint8 `json:"statusb"`
	// contains filtered or unexported fields
}

func (*Rtc) Attach

func (rtc *Rtc) Attach(vm *platform.Vm, model *Model) error

func (*Rtc) Tick

func (rtc *Rtc) Tick(alive bool)

func (*Rtc) Val

func (rtc *Rtc) Val(data int) uint64

type RtcAddr

type RtcAddr struct {
	*Rtc
}

func (*RtcAddr) Read

func (reg *RtcAddr) Read(offset uint64, size uint) (uint64, error)

func (*RtcAddr) Write

func (reg *RtcAddr) Write(offset uint64, size uint, value uint64) error

type RtcData

type RtcData struct {
	*Rtc
}

func (*RtcData) Read

func (reg *RtcData) Read(offset uint64, size uint) (uint64, error)

func (*RtcData) Write

func (reg *RtcData) Write(offset uint64, size uint, value uint64) error

type TypedMemoryRegion

type TypedMemoryRegion struct {
	MemoryRegion
	MemoryType

	// The owner.
	Device
	// contains filtered or unexported fields
}

TypedMemoryRegion --

This is used for tracking runtime state. These TypedMemoryRegion's will be created and tracked in a MemoryMap (below) within the model, and relate directly to runtime platform state.

type Uart

type Uart struct {
	PioDevice

	// Registers.
	Ier Register `json:"ier"`
	Iir Register `json:"iir"`
	Lcr Register `json:"lcr"`
	Mcr Register `json:"mcr"`
	Lsr Register `json:"lsr"`
	Msr Register `json:"msr"`
	Fcr Register `json:"fcr"`
	Scr Register `json:"scr"`
	Dll Register `json:"dll"`
	Dlh Register `json:"dlh"`

	// Our allocated interrupt.
	InterruptNumber platform.Irq `json:"interrupt"`
}

type UartData

type UartData struct {
	*Uart
}

func (*UartData) Read

func (uart *UartData) Read(offset uint64, size uint) (uint64, error)

func (*UartData) Write

func (uart *UartData) Write(offset uint64, size uint, value uint64) error

type UartIntr

type UartIntr struct {
	*Uart
}

func (*UartIntr) Read

func (uart *UartIntr) Read(offset uint64, size uint) (uint64, error)

func (*UartIntr) Write

func (uart *UartIntr) Write(offset uint64, size uint, value uint64) error

type UserMemory

type UserMemory struct {
	BaseDevice

	// As laid-out.
	// This is indexed by offset in the file,
	// and each offset points to the given region.
	Allocated []UserMemorySegment `json:"allocated"`

	// The offset in the file.
	Offset int64 `json:"offset"`

	// The FD to map for regions.
	Fd int `json:"fd"`
	// contains filtered or unexported fields
}

UserMemory --

The user memory device allocates and maintains a mapping of user memory to a backing file. The file can be of any type (i.e. opening /dev/zero or any other temporary file) and we rely on the management stack to determine the best way to provide memory.

func (*UserMemory) Attach

func (user *UserMemory) Attach(vm *platform.Vm, model *Model) error

func (*UserMemory) Layout

func (user *UserMemory) Layout(
	vm *platform.Vm,
	model *Model,
	start uint64,
	memory uint64) error

func (*UserMemory) Reload

func (user *UserMemory) Reload(
	vm *platform.Vm,
	model *Model) (uint64, uint64, error)

type UserMemorySegment

type UserMemorySegment struct {
	// The offset in the file.
	Offset uint64 `json:"offset"`

	// The segment of virtual machine memory.
	Region MemoryRegion `json:"region"`
}

UserMemorySegment --

This maps a file offset to a segment of user memory.

type VirtioBlockDevice

type VirtioBlockDevice struct {
	*VirtioDevice

	// The device.
	Dev string `json:"dev"`

	// The backing file.
	Fd int `json:"fd"`
}

func (*VirtioBlockDevice) Attach

func (block *VirtioBlockDevice) Attach(vm *platform.Vm, model *Model) error

type VirtioBuffer

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

func NewVirtioBuffer

func NewVirtioBuffer(index uint16, readonly bool) *VirtioBuffer

func (*VirtioBuffer) Append

func (buf *VirtioBuffer) Append(data []byte)

func (*VirtioBuffer) CopyOut

func (buf *VirtioBuffer) CopyOut(
	offset int,
	output []byte) int

func (*VirtioBuffer) Gather

func (buf *VirtioBuffer) Gather(
	offset int,
	length int) ([]unsafe.Pointer, []C.int)

func (*VirtioBuffer) Length

func (buf *VirtioBuffer) Length() int

func (*VirtioBuffer) Map

func (buf *VirtioBuffer) Map(
	offset int,
	length int) []byte

func (*VirtioBuffer) PRead

func (buf *VirtioBuffer) PRead(
	fd int,
	fd_offset int64,
	buf_offset int,
	length int) (int, error)

func (*VirtioBuffer) PWrite

func (buf *VirtioBuffer) PWrite(
	fd int,
	fd_offset int64,
	buf_offset int,
	length int) (int, error)

func (*VirtioBuffer) Read

func (buf *VirtioBuffer) Read(
	fd int,
	buf_offset int,
	length int) (int, error)

func (*VirtioBuffer) SetLength

func (buf *VirtioBuffer) SetLength(length int)

func (*VirtioBuffer) Write

func (buf *VirtioBuffer) Write(
	fd int,
	buf_offset int,
	length int) (int, error)

type VirtioBufferSet

type VirtioBufferSet map[uint16]bool

The set of "in-progress" buffers. This is used for correctly suspending and resuming the active state of the device.

func (*VirtioBufferSet) MarshalJSON

func (set *VirtioBufferSet) MarshalJSON() ([]byte, error)

func (*VirtioBufferSet) UnmarshalJSON

func (set *VirtioBufferSet) UnmarshalJSON(data []byte) error

type VirtioChannel

type VirtioChannel struct {
	*VirtioDevice `json:"-"`

	// Our channel number (set in Marshal()).
	Channel uint `json:"channel"`

	// What index have we consumed up to?
	Consumed uint16 `json:"consumed"`

	// Our outstanding buffers.
	Outstanding VirtioBufferSet `json:"outstanding"`

	// The queue size.
	QueueSize Register `json:"queue-size"`

	// The address written.
	QueueAddress Register `json:"queue-address"`

	// Our MSI-X Vectors.
	CfgVec   Register `json:"config-vector"`
	QueueVec Register `json:"queue-vector"`
	// contains filtered or unexported fields
}

func NewVirtioChannel

func NewVirtioChannel(n uint, size uint) *VirtioChannel

func (*VirtioChannel) Interrupt

func (vchannel *VirtioChannel) Interrupt(queue bool)

func (*VirtioChannel) ProcessIncoming

func (vchannel *VirtioChannel) ProcessIncoming() error

func (*VirtioChannel) ProcessOutgoing

func (vchannel *VirtioChannel) ProcessOutgoing() error

type VirtioChannelMap

type VirtioChannelMap map[uint]*VirtioChannel

Our channel map is just queue# => channel object.

func (*VirtioChannelMap) MarshalJSON

func (chanmap *VirtioChannelMap) MarshalJSON() ([]byte, error)

func (*VirtioChannelMap) UnmarshalJSON

func (chanmap *VirtioChannelMap) UnmarshalJSON(data []byte) error

type VirtioChannelSafe

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

func (*VirtioChannelSafe) MarshalJSON

func (vchannel *VirtioChannelSafe) MarshalJSON() ([]byte, error)

func (*VirtioChannelSafe) UnmarshalJSON

func (vchannel *VirtioChannelSafe) UnmarshalJSON(data []byte) error

type VirtioConf

type VirtioConf struct {
	*VirtioDevice
}

func (*VirtioConf) Read

func (reg *VirtioConf) Read(offset uint64, size uint) (uint64, error)

func (*VirtioConf) Write

func (reg *VirtioConf) Write(offset uint64, size uint, value uint64) error

type VirtioConsoleDevice

type VirtioConsoleDevice struct {
	*VirtioDevice

	Opened bool `json:"opened"`
	// contains filtered or unexported fields
}

func (*VirtioConsoleDevice) Attach

func (console *VirtioConsoleDevice) Attach(vm *platform.Vm, model *Model) error

func (*VirtioConsoleDevice) Close

func (console *VirtioConsoleDevice) Close() error

func (*VirtioConsoleDevice) Read

func (console *VirtioConsoleDevice) Read(p []byte) (int, error)

func (*VirtioConsoleDevice) Write

func (console *VirtioConsoleDevice) Write(p []byte) (int, error)

type VirtioDevice

type VirtioDevice struct {
	Device `json:"device"`

	// Our channels.
	// We expect that these will be configured
	// by the different devices.
	Channels VirtioChannelMap `json:"channels"`

	// Our configuration.
	Config *Ram `json:"config"`

	// Our virtio-specific registers.
	HostFeatures  Register `json:"host-features"`
	GuestFeatures Register `json:"guest-features"`
	QueueSelect   Register `json:"queue-select"`
	QueueNotify   Register `json:"queue-notify"`
	DeviceStatus  Register `json:"device-status"`
	IsrStatus     Register `json:"isr-status"`
	// contains filtered or unexported fields
}

We store the common configuration here and run a few different routines that allow us to multiplex onto the data channel. This abstracts all the H/W details away from the actual device logic.

func NewMmioVirtioDevice

func NewMmioVirtioDevice(
	info *DeviceInfo,
	class int) (*VirtioDevice, error)

func NewPciVirtioDevice

func NewPciVirtioDevice(
	info *DeviceInfo,
	class PciClass,
	subsystem_id PciSubsystemDeviceId,
	vectors uint) (*VirtioDevice, error)

func NewVirtioDevice

func NewVirtioDevice(device Device) *VirtioDevice

func (*VirtioDevice) Attach

func (virtio *VirtioDevice) Attach(vm *platform.Vm, model *Model) error

func (*VirtioDevice) GetFeatures

func (virtio *VirtioDevice) GetFeatures() uint32

func (*VirtioDevice) HasFeatures

func (virtio *VirtioDevice) HasFeatures(features uint32) bool

func (*VirtioDevice) Interrupt

func (virtio *VirtioDevice) Interrupt() error

func (*VirtioDevice) IsMSIXEnabled

func (virtio *VirtioDevice) IsMSIXEnabled() bool

func (*VirtioDevice) SetFeatures

func (virtio *VirtioDevice) SetFeatures(features uint32)

type VirtioFsDevice

type VirtioFsDevice struct {
	*VirtioDevice

	// Our filesystem tag.
	Tag string `json:"tag"`

	// Debug fs operations?
	Debugfs bool `json:"debugfs"`

	// Our plan9 server.
	plan9.Fs
}

func (*VirtioFsDevice) Attach

func (fs *VirtioFsDevice) Attach(vm *platform.Vm, model *Model) error

type VirtioMmioConf

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

func (*VirtioMmioConf) Read

func (reg *VirtioMmioConf) Read(offset uint64, size uint) (uint64, error)

func (*VirtioMmioConf) Write

func (reg *VirtioMmioConf) Write(offset uint64, size uint, value uint64) error

type VirtioMmioDevice

type VirtioMmioDevice struct {
	MmioDevice
}

type VirtioNetDevice

type VirtioNetDevice struct {
	*VirtioDevice

	// The tap device file descriptor.
	Fd int `json:"fd"`

	// The mac address.
	Mac string `json:"mac"`

	// Size of vnet header expected by the tap device.
	Vnet int `json:"vnet"`

	// Hardware offloads supported by tap device?
	Offload bool `json:"offload"`
}

func (*VirtioNetDevice) Attach

func (nic *VirtioNetDevice) Attach(vm *platform.Vm, model *Model) error

type VirtioNotification

type VirtioNotification struct {
}

Simple notification (for channels).

type VirtioStream

type VirtioStream struct {
	*VirtioBuffer
	// contains filtered or unexported fields
}

func NewVirtioStream

func NewVirtioStream(
	buffer *VirtioBuffer,
	bookmark int) *VirtioStream

func (*VirtioStream) Read16

func (stream *VirtioStream) Read16() uint16

func (*VirtioStream) Read32

func (stream *VirtioStream) Read32() uint32

func (*VirtioStream) Read64

func (stream *VirtioStream) Read64() uint64

func (*VirtioStream) Read8

func (stream *VirtioStream) Read8() uint8

func (*VirtioStream) ReadBytes

func (stream *VirtioStream) ReadBytes(length int) []byte

func (*VirtioStream) ReadFromFd

func (stream *VirtioStream) ReadFromFd(
	fd int,
	offset int64,
	length int) (int, error)

func (*VirtioStream) ReadLeft

func (stream *VirtioStream) ReadLeft() int

func (*VirtioStream) ReadN

func (stream *VirtioStream) ReadN(size int) uint64

func (*VirtioStream) ReadRewind

func (stream *VirtioStream) ReadRewind()

func (*VirtioStream) ReadString

func (stream *VirtioStream) ReadString() string

func (*VirtioStream) Write16

func (stream *VirtioStream) Write16(value uint16)

func (*VirtioStream) Write32

func (stream *VirtioStream) Write32(value uint32)

func (*VirtioStream) Write64

func (stream *VirtioStream) Write64(value uint64)

func (*VirtioStream) Write8

func (stream *VirtioStream) Write8(value uint8)

func (*VirtioStream) WriteBytes

func (stream *VirtioStream) WriteBytes(data []byte)

func (*VirtioStream) WriteLeft

func (stream *VirtioStream) WriteLeft() int

func (*VirtioStream) WriteN

func (stream *VirtioStream) WriteN(size int, value uint64)

func (*VirtioStream) WriteRewind

func (stream *VirtioStream) WriteRewind()

func (*VirtioStream) WriteString

func (stream *VirtioStream) WriteString(value string)

func (*VirtioStream) WriteToFd

func (stream *VirtioStream) WriteToFd(
	fd int,
	offset int64,
	length int) (int, error)

type WriteIoEvent

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

func (*WriteIoEvent) GetData

func (event *WriteIoEvent) GetData() uint64

func (*WriteIoEvent) IsWrite

func (event *WriteIoEvent) IsWrite() bool

func (*WriteIoEvent) SetData

func (event *WriteIoEvent) SetData(val uint64)

func (*WriteIoEvent) Size

func (event *WriteIoEvent) Size() uint

Jump to

Keyboard shortcuts

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