nvpci

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 13 Imported by: 4

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 InterfaceMock added in v0.7.4

type InterfaceMock struct {
	// Get3DControllersFunc mocks the Get3DControllers method.
	Get3DControllersFunc func() ([]*NvidiaPCIDevice, error)

	// GetAllDevicesFunc mocks the GetAllDevices method.
	GetAllDevicesFunc func() ([]*NvidiaPCIDevice, error)

	// GetDPUsFunc mocks the GetDPUs method.
	GetDPUsFunc func() ([]*NvidiaPCIDevice, error)

	// GetGPUByIndexFunc mocks the GetGPUByIndex method.
	GetGPUByIndexFunc func(n int) (*NvidiaPCIDevice, error)

	// GetGPUByPciBusIDFunc mocks the GetGPUByPciBusID method.
	GetGPUByPciBusIDFunc func(s string) (*NvidiaPCIDevice, error)

	// GetGPUsFunc mocks the GetGPUs method.
	GetGPUsFunc func() ([]*NvidiaPCIDevice, error)

	// GetNVSwitchesFunc mocks the GetNVSwitches method.
	GetNVSwitchesFunc func() ([]*NvidiaPCIDevice, error)

	// GetNetworkControllersFunc mocks the GetNetworkControllers method.
	GetNetworkControllersFunc func() ([]*NvidiaPCIDevice, error)

	// GetPciBridgesFunc mocks the GetPciBridges method.
	GetPciBridgesFunc func() ([]*NvidiaPCIDevice, error)

	// GetVGAControllersFunc mocks the GetVGAControllers method.
	GetVGAControllersFunc func() ([]*NvidiaPCIDevice, error)
	// contains filtered or unexported fields
}

InterfaceMock is a mock implementation of Interface.

func TestSomethingThatUsesInterface(t *testing.T) {

	// make and configure a mocked Interface
	mockedInterface := &InterfaceMock{
		Get3DControllersFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the Get3DControllers method")
		},
		GetAllDevicesFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetAllDevices method")
		},
		GetDPUsFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetDPUs method")
		},
		GetGPUByIndexFunc: func(n int) (*NvidiaPCIDevice, error) {
			panic("mock out the GetGPUByIndex method")
		},
		GetGPUByPciBusIDFunc: func(s string) (*NvidiaPCIDevice, error) {
			panic("mock out the GetGPUByPciBusID method")
		},
		GetGPUsFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetGPUs method")
		},
		GetNVSwitchesFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetNVSwitches method")
		},
		GetNetworkControllersFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetNetworkControllers method")
		},
		GetPciBridgesFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetPciBridges method")
		},
		GetVGAControllersFunc: func() ([]*NvidiaPCIDevice, error) {
			panic("mock out the GetVGAControllers method")
		},
	}

	// use mockedInterface in code that requires Interface
	// and then make assertions.

}

func (*InterfaceMock) Get3DControllers added in v0.7.4

func (mock *InterfaceMock) Get3DControllers() ([]*NvidiaPCIDevice, error)

Get3DControllers calls Get3DControllersFunc.

func (*InterfaceMock) Get3DControllersCalls added in v0.7.4

func (mock *InterfaceMock) Get3DControllersCalls() []struct {
}

Get3DControllersCalls gets all the calls that were made to Get3DControllers. Check the length with:

len(mockedInterface.Get3DControllersCalls())

func (*InterfaceMock) GetAllDevices added in v0.7.4

func (mock *InterfaceMock) GetAllDevices() ([]*NvidiaPCIDevice, error)

GetAllDevices calls GetAllDevicesFunc.

func (*InterfaceMock) GetAllDevicesCalls added in v0.7.4

func (mock *InterfaceMock) GetAllDevicesCalls() []struct {
}

GetAllDevicesCalls gets all the calls that were made to GetAllDevices. Check the length with:

len(mockedInterface.GetAllDevicesCalls())

func (*InterfaceMock) GetDPUs added in v0.7.4

func (mock *InterfaceMock) GetDPUs() ([]*NvidiaPCIDevice, error)

GetDPUs calls GetDPUsFunc.

func (*InterfaceMock) GetDPUsCalls added in v0.7.4

func (mock *InterfaceMock) GetDPUsCalls() []struct {
}

GetDPUsCalls gets all the calls that were made to GetDPUs. Check the length with:

len(mockedInterface.GetDPUsCalls())

func (*InterfaceMock) GetGPUByIndex added in v0.7.4

func (mock *InterfaceMock) GetGPUByIndex(n int) (*NvidiaPCIDevice, error)

GetGPUByIndex calls GetGPUByIndexFunc.

func (*InterfaceMock) GetGPUByIndexCalls added in v0.7.4

func (mock *InterfaceMock) GetGPUByIndexCalls() []struct {
	N int
}

GetGPUByIndexCalls gets all the calls that were made to GetGPUByIndex. Check the length with:

len(mockedInterface.GetGPUByIndexCalls())

func (*InterfaceMock) GetGPUByPciBusID added in v0.7.4

func (mock *InterfaceMock) GetGPUByPciBusID(s string) (*NvidiaPCIDevice, error)

GetGPUByPciBusID calls GetGPUByPciBusIDFunc.

func (*InterfaceMock) GetGPUByPciBusIDCalls added in v0.7.4

func (mock *InterfaceMock) GetGPUByPciBusIDCalls() []struct {
	S string
}

GetGPUByPciBusIDCalls gets all the calls that were made to GetGPUByPciBusID. Check the length with:

len(mockedInterface.GetGPUByPciBusIDCalls())

func (*InterfaceMock) GetGPUs added in v0.7.4

func (mock *InterfaceMock) GetGPUs() ([]*NvidiaPCIDevice, error)

GetGPUs calls GetGPUsFunc.

func (*InterfaceMock) GetGPUsCalls added in v0.7.4

func (mock *InterfaceMock) GetGPUsCalls() []struct {
}

GetGPUsCalls gets all the calls that were made to GetGPUs. Check the length with:

len(mockedInterface.GetGPUsCalls())

func (*InterfaceMock) GetNVSwitches added in v0.7.4

func (mock *InterfaceMock) GetNVSwitches() ([]*NvidiaPCIDevice, error)

GetNVSwitches calls GetNVSwitchesFunc.

func (*InterfaceMock) GetNVSwitchesCalls added in v0.7.4

func (mock *InterfaceMock) GetNVSwitchesCalls() []struct {
}

GetNVSwitchesCalls gets all the calls that were made to GetNVSwitches. Check the length with:

len(mockedInterface.GetNVSwitchesCalls())

func (*InterfaceMock) GetNetworkControllers added in v0.7.4

func (mock *InterfaceMock) GetNetworkControllers() ([]*NvidiaPCIDevice, error)

GetNetworkControllers calls GetNetworkControllersFunc.

func (*InterfaceMock) GetNetworkControllersCalls added in v0.7.4

func (mock *InterfaceMock) GetNetworkControllersCalls() []struct {
}

GetNetworkControllersCalls gets all the calls that were made to GetNetworkControllers. Check the length with:

len(mockedInterface.GetNetworkControllersCalls())

func (*InterfaceMock) GetPciBridges added in v0.7.4

func (mock *InterfaceMock) GetPciBridges() ([]*NvidiaPCIDevice, error)

GetPciBridges calls GetPciBridgesFunc.

func (*InterfaceMock) GetPciBridgesCalls added in v0.7.4

func (mock *InterfaceMock) GetPciBridgesCalls() []struct {
}

GetPciBridgesCalls gets all the calls that were made to GetPciBridges. Check the length with:

len(mockedInterface.GetPciBridgesCalls())

func (*InterfaceMock) GetVGAControllers added in v0.7.4

func (mock *InterfaceMock) GetVGAControllers() ([]*NvidiaPCIDevice, error)

GetVGAControllers calls GetVGAControllersFunc.

func (*InterfaceMock) GetVGAControllersCalls added in v0.7.4

func (mock *InterfaceMock) GetVGAControllersCalls() []struct {
}

GetVGAControllersCalls gets all the calls that were made to GetVGAControllers. Check the length with:

len(mockedInterface.GetVGAControllersCalls())

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 addressable 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, sriov *SriovInfo) 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
	SriovInfo  SriovInfo
}

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.

type SriovInfo added in v0.6.0

type SriovInfo struct {
	PhysicalFunction *SriovPhysicalFunction
	VirtualFunction  *SriovVirtualFunction
}

SriovInfo indicates whether device is VF/PF for SRIOV capable devices. Only one should be set at any given time.

func (*SriovInfo) IsPF added in v0.6.0

func (s *SriovInfo) IsPF() bool

func (*SriovInfo) IsVF added in v0.6.0

func (s *SriovInfo) IsVF() bool

type SriovPhysicalFunction added in v0.6.0

type SriovPhysicalFunction struct {
	TotalVFs uint64
	NumVFs   uint64
}

SriovPhysicalFunction stores info about SRIOV physical function.

type SriovVirtualFunction added in v0.6.0

type SriovVirtualFunction struct {
	PhysicalFunction *NvidiaPCIDevice
}

SriovVirtualFunction keeps data about SRIOV virtual function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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