nvpci

package
v0.0.0-...-d954f99 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PCICfgSpaceStandardSize represents the size in bytes of the standard config space
	PCICfgSpaceStandardSize = 256
	// PCICfgSpaceExtendedSize represents the size in bytes of the extended config space
	PCICfgSpaceExtendedSize = 4096
	// PCICapabilityListPointer represents offset for the capability list pointer
	PCICapabilityListPointer = 0x34
	// PCIStatusCapabilityList represents the status register bit which indicates capability list support
	PCIStatusCapabilityList = 0x10
	// PCIStatusBytePosition represents the position of the status register
	PCIStatusBytePosition = 0x06
)
View Source
const (
	// PCIMellanoxVendorID represents PCI vendor id for Mellanox
	PCIMellanoxVendorID uint16 = 0x15b3
	// PCINetworkControllerClass represents the PCI class for network controllers
	PCINetworkControllerClass uint32 = 0x020000
	// PCIBridgeClass represents the PCI class for network controllers
	PCIBridgeClass uint32 = 0x060400
)
View Source
const (
	// PCIDevicesRoot represents base path for all pci devices under sysfs
	PCIDevicesRoot = "/sys/bus/pci/devices"
	// PCINvidiaVendorID represents PCI vendor id for NVIDIA
	PCINvidiaVendorID uint16 = 0x10de
	// PCIVgaControllerClass represents the PCI class for VGA Controllers
	PCIVgaControllerClass uint32 = 0x030000
	// PCI3dControllerClass represents the PCI class for 3D Graphics accellerators
	PCI3dControllerClass uint32 = 0x030200
	// PCINvSwitchClass represents the PCI class for NVSwitches
	PCINvSwitchClass uint32 = 0x068000
	// UnknownDeviceString is the device name to set for devices not found in the PCI database
	UnknownDeviceString = "UNKNOWN_DEVICE"
	// UnknownClassString is the class name to set for devices not found in the PCI database
	UnknownClassString = "UNKNOWN_CLASS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigSpace

type ConfigSpace struct {
	Path string
}

ConfigSpace PCI configuration space (standard extended) file path

func (*ConfigSpace) Read

func (cs *ConfigSpace) Read() (ConfigSpaceIO, error)

type ConfigSpaceIO

type ConfigSpaceIO interface {
	bytes.Bytes
	GetVendorID() uint16
	GetDeviceID() uint16
	GetPCICapabilities() (*PCICapabilities, error)
}

ConfigSpaceIO Interface for reading and writing raw and preconfigured values

type Interface

type Interface interface {
	GetAllDevices() ([]*NvidiaPCIDevice, error)
	Get3DControllers() ([]*NvidiaPCIDevice, error)
	GetVGAControllers() ([]*NvidiaPCIDevice, error)
	GetNVSwitches() ([]*NvidiaPCIDevice, error)
	GetGPUs() ([]*NvidiaPCIDevice, error)
	GetGPUByIndex(int) (*NvidiaPCIDevice, error)
	GetGPUByPciBusID(string) (*NvidiaPCIDevice, error)
	GetNetworkControllers() ([]*NvidiaPCIDevice, error)
	GetPciBridges() ([]*NvidiaPCIDevice, error)
	GetDPUs() ([]*NvidiaPCIDevice, error)
}

Interface allows us to get a list of all NVIDIA PCI devices

func New

func New(opts ...Option) Interface

New interface that allows us to get a list of all NVIDIA PCI devices

type MemoryResource

type MemoryResource struct {
	Start uintptr
	End   uintptr
	Flags uint64
	Path  string
}

MemoryResource represents a mmio region

func (*MemoryResource) OpenRO

func (mr *MemoryResource) OpenRO() (mmio.Mmio, error)

OpenRO read only mmio region

func (*MemoryResource) OpenRW

func (mr *MemoryResource) OpenRW() (mmio.Mmio, error)

OpenRW read write mmio region

type MemoryResources

type MemoryResources map[int]*MemoryResource

MemoryResources a more human readable handle

func (MemoryResources) GetTotalAddressableMemory

func (mrs MemoryResources) GetTotalAddressableMemory(roundUp bool) (uint64, uint64)

GetTotalAddressableMemory will accumulate the 32bit and 64bit memory windows of each BAR and round the value if needed to the next power of 2; first return value is the accumulated 32bit addresable memory size the second one is the accumulated 64bit addressable memory size in bytes. These values are needed to configure virtualized environments.

type MockNvpci

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

MockNvpci mock pci device

func NewMockNvpci

func NewMockNvpci() (mock *MockNvpci, rerr error)

NewMockNvpci create new mock PCI and remove old devices

func (*MockNvpci) AddMockA100

func (m *MockNvpci) AddMockA100(address string, numaNode int) error

AddMockA100 Create an A100 like GPU mock device

func (*MockNvpci) Cleanup

func (m *MockNvpci) Cleanup()

Cleanup remove the mocked PCI devices root folder

func (MockNvpci) Get3DControllers

func (p MockNvpci) Get3DControllers() ([]*NvidiaPCIDevice, error)

Get3DControllers returns all NVIDIA 3D Controller PCI devices on the system

func (MockNvpci) GetAllDevices

func (p MockNvpci) GetAllDevices() ([]*NvidiaPCIDevice, error)

GetAllDevices returns all Nvidia PCI devices on the system

func (MockNvpci) GetDPUs

func (p MockNvpci) GetDPUs() ([]*NvidiaPCIDevice, error)

GetDPUs returns all Mellanox DPU devices on the system

func (MockNvpci) GetGPUByIndex

func (p MockNvpci) GetGPUByIndex(i int) (*NvidiaPCIDevice, error)

GetGPUByIndex returns an NVIDIA GPU device at a particular index

func (MockNvpci) GetGPUByPciBusID

func (p MockNvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error)

GetGPUByPciBusID constructs an NvidiaPCIDevice for the specified address (PCI Bus ID)

func (MockNvpci) GetGPUs

func (p MockNvpci) GetGPUs() ([]*NvidiaPCIDevice, error)

GetGPUs returns all NVIDIA GPU devices on the system

func (MockNvpci) GetNVSwitches

func (p MockNvpci) GetNVSwitches() ([]*NvidiaPCIDevice, error)

GetNVSwitches returns all NVIDIA NVSwitch PCI devices on the system

func (MockNvpci) GetNetworkControllers

func (p MockNvpci) GetNetworkControllers() ([]*NvidiaPCIDevice, error)

GetNetworkControllers returns all Mellanox Network Controller PCI devices on the system

func (MockNvpci) GetPciBridges

func (p MockNvpci) GetPciBridges() ([]*NvidiaPCIDevice, error)

GetPciBridges retrieves all Mellanox PCI(e) Bridges

func (MockNvpci) GetVGAControllers

func (p MockNvpci) GetVGAControllers() ([]*NvidiaPCIDevice, error)

GetVGAControllers returns all NVIDIA VGA Controller PCI devices on the system

type NvidiaPCIDevice

type NvidiaPCIDevice struct {
	Path       string
	Address    string
	Vendor     uint16
	Class      uint32
	ClassName  string
	Device     uint16
	DeviceName string
	Driver     string
	IommuGroup int
	NumaNode   int
	Config     *ConfigSpace
	Resources  MemoryResources
	IsVF       bool
}

NvidiaPCIDevice represents a PCI device for an NVIDIA product

func (*NvidiaPCIDevice) Is3DController

func (d *NvidiaPCIDevice) Is3DController() bool

Is3DController if class == 0x302

func (*NvidiaPCIDevice) IsDPU

func (d *NvidiaPCIDevice) IsDPU() bool

IsDPU returns if a device is a DPU

func (*NvidiaPCIDevice) IsGPU

func (d *NvidiaPCIDevice) IsGPU() bool

IsGPU either VGA for older cards or 3D for newer

func (*NvidiaPCIDevice) IsNVSwitch

func (d *NvidiaPCIDevice) IsNVSwitch() bool

IsNVSwitch if class == 0x068

func (*NvidiaPCIDevice) IsNetworkController

func (d *NvidiaPCIDevice) IsNetworkController() bool

IsNetworkController if class == 0x300

func (*NvidiaPCIDevice) IsPciBridge

func (d *NvidiaPCIDevice) IsPciBridge() bool

IsPciBridge if class == 0x0604

func (*NvidiaPCIDevice) IsResetAvailable

func (d *NvidiaPCIDevice) IsResetAvailable() bool

IsResetAvailable some devices can be reset without rebooting, check if applicable

func (*NvidiaPCIDevice) IsVGAController

func (d *NvidiaPCIDevice) IsVGAController() bool

IsVGAController if class == 0x300

func (*NvidiaPCIDevice) Reset

func (d *NvidiaPCIDevice) Reset() error

Reset perform a reset to apply a new configuration at HW level

type Option

type Option func(*nvpci)

Option defines a function for passing options to the New() call

func WithLogger

func WithLogger(logger logger) Option

WithLogger provides an Option to set the logger for the library

func WithPCIDatabasePath

func WithPCIDatabasePath(path string) Option

WithPCIDatabasePath provides an Option to set the path to the pciids database file.

func WithPCIDevicesRoot

func WithPCIDevicesRoot(root string) Option

WithPCIDevicesRoot provides an Option to set the root path for PCI devices on the system.

type PCICapabilities

type PCICapabilities struct {
	Standard map[uint8]*PCIStandardCapability
	Extended map[uint16]*PCIExtendedCapability
}

PCICapabilities combines the standard and extended config space

type PCIExtendedCapability

type PCIExtendedCapability struct {
	bytes.Bytes
	Version uint8
}

PCIExtendedCapability extended PCI config space

type PCIStandardCapability

type PCIStandardCapability struct {
	bytes.Bytes
}

PCIStandardCapability standard PCI config space

type ResourceInterface

type ResourceInterface interface {
	GetTotalAddressableMemory(bool) (uint64, uint64)
}

ResourceInterface exposes some higher level functions of resources

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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