pci

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: GPL-2.0, GPL-2.0-or-later Imports: 14 Imported by: 2

Documentation

Overview

Generic devices on PCI bus.

Index

Constants

This section is empty.

Variables

View Source
var DefaultBus = &vfio_main{}

Functions

func CloseDiscoveredDevices

func CloseDiscoveredDevices(bus Bus) (err error)

func DiscoverDevices

func DiscoverDevices(bus Bus) (err error)

func SetDriver

func SetDriver(v Driver, args ...interface{}) (err error)

SetDriver gives a driver for a given list of devices (vendor, device pairs).

Types

type BaseAddressReg

type BaseAddressReg U32

func (BaseAddressReg) Addr

func (b BaseAddressReg) Addr() uint32

func (BaseAddressReg) IsMem

func (b BaseAddressReg) IsMem() bool

func (BaseAddressReg) String

func (b BaseAddressReg) String() string

func (BaseAddressReg) Valid

func (b BaseAddressReg) Valid() bool

type Bus

type Bus interface {
	NewDevice() BusDevice
	Validate() error
	// contains filtered or unexported methods
}

type BusAddress

type BusAddress struct {
	Domain        uint16
	Bus, Slot, Fn uint8
}

func (BusAddress) String

func (a BusAddress) String() string

type BusDevice

type BusDevice interface {
	ConfigRw(offset, vʹ, nBytes uint, isWrite bool) (v uint)
	GetDevice() *Device
	Open() error
	Close() error
	MapResource(index uint) (res uintptr, err error)
	UnmapResource(index uint) (err error)
	InterruptEnable(UseMsi bool) (err error)
}

Things a bus driver device must do.

type Capability

type Capability U8
const (
	PowerManagement Capability = iota + 1
	AGP
	VitalProductData
	SlotIdentification
	MSI
	CompactPCIHotSwap
	PCIX
	HyperTransport
	VendorSpecific
	DebugPort
	CompactPciCentralControl
	PCIHotPlugController
	SSVID
	AGP3
	SecureDevice
	PCIE
	MSIX
	SATA
	AdvancedFeatures
)

func (Capability) String

func (i Capability) String() string

type CapabilityHeader

type CapabilityHeader struct {
	Capability

	// Pointer to next capability header
	NextCapabilityHeader U8
}

Common header for capabilities.

type Command

type Command U16
const (
	IOEnable Command = 1 << iota
	MemoryEnable
	BusMasterEnable
	SpecialCycles
	WriteInvalidate
	VgaPaletteSnoop
	Parity
	AddressDataStepping
	SERR
	BackToBackWrite
	INTxEmulationDisable
)

func (*Command) Get

func (c *Command) Get(d *Device) Command

func (*Command) Set

func (c *Command) Set(d *Device, v Command)

type ConfigHeader

type ConfigHeader struct {
	DeviceID
	Command
	Status

	Revision U8

	// Distinguishes programming interface for device.
	// For example, different standards for USB controllers.
	SoftwareInterface

	DeviceClass

	CacheSize    uint8
	LatencyTimer uint8

	// If bit 7 of this register is set, the device has multiple functions;
	// otherwise, it is a single function device.
	Tp uint8

	Bist uint8
}

Under PCI, each device has 256 bytes of configuration address space, of which the first 64 bytes are standardized as follows:

func (ConfigHeader) Type

func (c ConfigHeader) Type() HeaderType

type Device

type Device struct {
	ID        DeviceID
	Addr      BusAddress
	Resources []Resource
	Driver
	DriverDevice
	BusDevice
}

func (*Device) ConfigRw

func (d *Device) ConfigRw(offset, vʹ, nBytes uint, isWrite bool) (v uint)

func (*Device) DeviceID

func (d *Device) DeviceID() VendorDeviceID

func (*Device) FindCap

func (d *Device) FindCap(c Capability) (offset uint, found bool)

func (*Device) FindExtCap

func (d *Device) FindExtCap(c ExtCapability) (offset uint, found bool)

func (*Device) ForeachCap

func (d *Device) ForeachCap(f func(h *CapabilityHeader, offset uint) (done bool, err error)) (err error)

func (*Device) ForeachExtCap

func (d *Device) ForeachExtCap(f func(h *ExtCapabilityHeader, offset uint) (done bool, err error)) (err error)

func (*Device) GetCap

func (d *Device) GetCap(c Capability) (p unsafe.Pointer)

func (*Device) GetConfig

func (d *Device) GetConfig() *ConfigHeader

func (*Device) GetDeviceConfig

func (d *Device) GetDeviceConfig() *DeviceConfig

func (*Device) GetExtCap

func (d *Device) GetExtCap(c ExtCapability) (p unsafe.Pointer)

func (*Device) MapResource

func (d *Device) MapResource(bar uint) (res uintptr, err error)

func (*Device) ReadConfigUint16

func (d *Device) ReadConfigUint16(o uint) (v uint16)

func (*Device) ReadConfigUint32

func (d *Device) ReadConfigUint32(o uint) (v uint32)

func (*Device) ReadConfigUint8

func (d *Device) ReadConfigUint8(o uint) (v uint8)

func (*Device) ReadRawConfigUint16

func (d *Device) ReadRawConfigUint16(o uint) (v uint16)

func (*Device) ReadRawConfigUint32

func (d *Device) ReadRawConfigUint32(o uint) (v uint32)

func (*Device) ReadRawConfigUint8

func (d *Device) ReadRawConfigUint8(o uint) (v uint8)

func (*Device) SetMaster

func (d *Device) SetMaster(enable bool)

Set bus master in pci command register. Otherwise no love with device dma or msi interrupts.

func (*Device) String

func (d *Device) String() string

func (*Device) SysfsOpenFile

func (d *Device) SysfsOpenFile(format string, mode int, args ...interface{}) (f *os.File, err error)

func (*Device) SysfsPath

func (d *Device) SysfsPath(format string, args ...interface{}) (path string)

func (*Device) SysfsReadHexFile

func (d *Device) SysfsReadHexFile(format string, mode int, args ...interface{}) (v uint, err error)

func (*Device) UnmapResource

func (d *Device) UnmapResource(bar uint) (err error)

func (*Device) VendorID

func (d *Device) VendorID() VendorID

func (*Device) WriteConfigUint16

func (d *Device) WriteConfigUint16(o uint, value uint16)

func (*Device) WriteConfigUint32

func (d *Device) WriteConfigUint32(o uint, value uint32)

func (*Device) WriteConfigUint8

func (d *Device) WriteConfigUint8(o uint, value uint8)

func (*Device) WriteRawConfigUint16

func (d *Device) WriteRawConfigUint16(o uint, value uint16)

func (*Device) WriteRawConfigUint32

func (d *Device) WriteRawConfigUint32(o uint, value uint32)

func (*Device) WriteRawConfigUint8

func (d *Device) WriteRawConfigUint8(o uint, value uint8)

type DeviceClass

type DeviceClass uint16
const (
	Undefined                  DeviceClass = 0x0000
	Undefined_VGA              DeviceClass = 0x0001
	Storage_SCSI               DeviceClass = 0x0100
	Storage_IDE                DeviceClass = 0x0101
	Storage_Floppy             DeviceClass = 0x0102
	Storage_IPI                DeviceClass = 0x0103
	Storage_RAID               DeviceClass = 0x0104
	Storage_SATA               DeviceClass = 0x0106
	Storage_SAS                DeviceClass = 0x0107
	Storage_Other              DeviceClass = 0x0180
	Network_Ethernet           DeviceClass = 0x0200
	Network_Token_Ring         DeviceClass = 0x0201
	Network_FDDI               DeviceClass = 0x0202
	Network_ATM                DeviceClass = 0x0203
	Network_Other              DeviceClass = 0x0280
	Display_VGA                DeviceClass = 0x0300
	Display_XGA                DeviceClass = 0x0301
	Display_3D                 DeviceClass = 0x0302
	Display_Other              DeviceClass = 0x0380
	Multimedia_Video           DeviceClass = 0x0400
	Multimedia_Audio           DeviceClass = 0x0401
	Multimedia_Phone           DeviceClass = 0x0402
	Multimedia_Audio_Device    DeviceClass = 0x0403
	Multimedia_Other           DeviceClass = 0x0480
	Memory_RAM                 DeviceClass = 0x0500
	Memory_Flash               DeviceClass = 0x0501
	Memory_Other               DeviceClass = 0x0580
	Bridge_Host                DeviceClass = 0x0600
	Bridge_ISA                 DeviceClass = 0x0601
	Bridge_EISA                DeviceClass = 0x0602
	Bridge_MC                  DeviceClass = 0x0603
	Bridge_PCI                 DeviceClass = 0x0604
	Bridge_PCMCIA              DeviceClass = 0x0605
	Bridge_NUBUS               DeviceClass = 0x0606
	Bridge_CARDBUS             DeviceClass = 0x0607
	Bridge_RACEWAY             DeviceClass = 0x0608
	Bridge_Other               DeviceClass = 0x0680
	Communication_Serial       DeviceClass = 0x0700
	Communication_Parallel     DeviceClass = 0x0701
	Communication_Multi_Serial DeviceClass = 0x0702
	Communication_Modem        DeviceClass = 0x0703
	Communication_Other        DeviceClass = 0x0780
	System_PIC                 DeviceClass = 0x0800
	System_DMA                 DeviceClass = 0x0801
	System_Timer               DeviceClass = 0x0802
	System_RTC                 DeviceClass = 0x0803
	System_PCI_Hotplug         DeviceClass = 0x0804
	System_SDHCI               DeviceClass = 0x0805
	System_Other               DeviceClass = 0x0880
	Input_Keyboard             DeviceClass = 0x0900
	Input_Pen                  DeviceClass = 0x0901
	Input_Mouse                DeviceClass = 0x0902
	Input_Scanner              DeviceClass = 0x0903
	Input_GAMEPORT             DeviceClass = 0x0904
	Input_Other                DeviceClass = 0x0980
	Docking_GENERIC            DeviceClass = 0x0a00
	Docking_Other              DeviceClass = 0x0a80
	Processor_386              DeviceClass = 0x0b00
	Processor_486              DeviceClass = 0x0b01
	Processor_Pentium          DeviceClass = 0x0b02
	Processor_Alpha            DeviceClass = 0x0b10
	Processor_Powerpc          DeviceClass = 0x0b20
	Processor_MIPS             DeviceClass = 0x0b30
	Processor_CO               DeviceClass = 0x0b40
	Serial_Firewire            DeviceClass = 0x0c00
	Serial_Access              DeviceClass = 0x0c01
	Serial_SSA                 DeviceClass = 0x0c02
	Serial_USB                 DeviceClass = 0x0c03
	Serial_Fiber               DeviceClass = 0x0c04
	Serial_SMBUS               DeviceClass = 0x0c05
	Wireless_RF_Controller     DeviceClass = 0x0d10
	Intelligent_I2O            DeviceClass = 0x0e00
	Satellite_TV               DeviceClass = 0x0f00
	Satellite_Audio            DeviceClass = 0x0f01
	Satellite_Voice            DeviceClass = 0x0f03
	Satellite_Data             DeviceClass = 0x0f04
	Crypt_Network              DeviceClass = 0x1000
	Crypt_entertainment        DeviceClass = 0x1001
	Crypt_Other                DeviceClass = 0x1080
	SP_DPIO                    DeviceClass = 0x1100
	SP_Other                   DeviceClass = 0x1180
)

func (DeviceClass) String

func (i DeviceClass) String() string

type DeviceConfig

type DeviceConfig struct {
	ConfigHeader

	// Base addresses specify locations in memory or I/O space.
	// Decoded size can be determined by writing a value of 0xffffffff to the register, and reading it back.
	// Only 1 bits are decoded.
	BaseAddressRegs [6]BaseAddressReg

	CardBusCIS U32

	SubID DeviceID

	RomAddress U32

	// Config space offset of start of capability list.
	CapabilityOffset U8

	InterruptLine U8
	InterruptPin  U8
	MinGrant      U8
	MaxLatency    U8
	// contains filtered or unexported fields
}

Header type 0 (normal devices)

type DeviceID

type DeviceID struct {
	Vendor VendorID
	Device VendorDeviceID
}

Vendor/Device pair

func (*DeviceID) Get

func (r *DeviceID) Get(d *Device) (i DeviceID)

type Driver

type Driver interface {
	// Device matches registered devices for this driver.
	NewDevice(d BusDevice) (i DriverDevice, err error)
}

Things a driver must do.

func GetDriver

func GetDriver(d DeviceID) Driver

type DriverDevice

type DriverDevice interface {
	Init() (err error)
	Exit() (err error)
	Interrupt()
}

This a device handled by driver must do.

type ExtCapability

type ExtCapability U16
const (
	AdvancedErrorReporting ExtCapability = iota + 1
	VirtualChannel
	DeviceSerialNumber
	PowerBudgeting
	RootComplexLinkDeclaration
	RootComplexInternalLinkControl
	RootComplexEventCollector
	MultiFunctionVC
	VirtualChannel9
	RootComplexRB
	ExtVendorSpecific
	ConfigAccess
	AccessControlServices
	AlternateRoutingID
	AddressTranslationServices
	SingleRootIOVirtualization
	MultiRootIOVirtualization
	Multicast
	PageRequestInterface
	ReservedAMD
	ResizableBAR
	DynamicPowerAllocation
	TPHRequester
	LatencyToleranceReporting
	SecondaryPCIeCapability
	ProtocolMultiplexing
	ProcessAddressSpaceID
)

func (ExtCapability) String

func (i ExtCapability) String() string

type ExtCapabilityHeader

type ExtCapabilityHeader struct {
	ExtCapability

	// [15:4] next pointer
	// [3:0] version
	VersionAndNextOffset U16
}

Common header for extended capabilities.

type HeaderType

type HeaderType uint8
const (
	Normal HeaderType = iota
	Bridge
	CardBus
)

func (HeaderType) String

func (i HeaderType) String() string

type Resource

type Resource struct {
	Index      uint32 // index of BAR
	Base, Size uint64
	Mem        []byte
}

func (Resource) String

func (r Resource) String() string

type SoftwareInterface

type SoftwareInterface U8

func (SoftwareInterface) String

func (x SoftwareInterface) String() string

type Status

type Status U16

type U16

type U16 hw.U16

func (*U16) Get

func (r *U16) Get(d *Device) uint16

func (*U16) GetRaw

func (r *U16) GetRaw(d *Device) uint16

func (*U16) Set

func (r *U16) Set(d *Device, v uint16)

func (*U16) SetRaw

func (r *U16) SetRaw(d *Device, v uint16)

type U32

type U32 hw.U32

func (*U32) Get

func (r *U32) Get(d *Device) uint32

func (*U32) GetRaw

func (r *U32) GetRaw(d *Device) uint32

func (*U32) Set

func (r *U32) Set(d *Device, v uint32)

func (*U32) SetRaw

func (r *U32) SetRaw(d *Device, v uint32)

type U8

type U8 hw.U8

func (*U8) Get

func (r *U8) Get(d *Device) uint8

func (*U8) GetRaw

func (r *U8) GetRaw(d *Device) uint8

func (*U8) Set

func (r *U8) Set(d *Device, v uint8)

func (*U8) SetRaw

func (r *U8) SetRaw(d *Device, v uint8)

type VendorDeviceID

type VendorDeviceID U16

func (*VendorDeviceID) Get

func (VendorDeviceID) String

func (d VendorDeviceID) String() string

type VendorID

type VendorID U16

Device/vendor ID from PCI config space.

const (
	Broadcom VendorID = 0x14e4
	Intel    VendorID = 0x8086
)

func (*VendorID) Get

func (r *VendorID) Get(d *Device) VendorID

func (VendorID) String

func (i VendorID) String() string

Jump to

Keyboard shortcuts

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