Add the status byte check

This commit is contained in:
zvonkok 2022-02-16 10:45:15 +01:00
parent 1f718a1568
commit 9196546dcc
2 changed files with 8 additions and 0 deletions

View File

@ -27,6 +27,8 @@ const (
pciCfgSpaceStandardSize = 256 pciCfgSpaceStandardSize = 256
pciCfgSpaceExtendedSize = 4096 pciCfgSpaceExtendedSize = 4096
pciCapabilityListPointer = 0x34 pciCapabilityListPointer = 0x34
pciStatusCapabilityList = 0x10
pciStatusBytePosition = 0x06
) )
// ConfigSpace PCI configuration space (standard extended) file path // ConfigSpace PCI configuration space (standard extended) file path
@ -85,6 +87,11 @@ func (cs *configSpaceIO) GetPCICapabilities() (*PCICapabilities, error) {
make(map[uint16]*PCIExtendedCapability), make(map[uint16]*PCIExtendedCapability),
} }
support := cs.Read8(pciStatusBytePosition) & pciStatusCapabilityList
if support == 0 {
return nil, fmt.Errorf("pci device does not support capability list")
}
soffset := cs.Read8(pciCapabilityListPointer) soffset := cs.Read8(pciCapabilityListPointer)
if int(soffset) >= cs.Len() { if int(soffset) >= cs.Len() {
return nil, fmt.Errorf("capability list pointer out of bounds") return nil, fmt.Errorf("capability list pointer out of bounds")

View File

@ -108,6 +108,7 @@ func (m *MockNvpci) AddMockA100(address string, numaNode int) error {
data := bytes.New(&_data) data := bytes.New(&_data)
data.Write16(0, pciNvidiaVendorID) data.Write16(0, pciNvidiaVendorID)
data.Write16(2, uint16(0x20bf)) data.Write16(2, uint16(0x20bf))
data.Write8(pciStatusBytePosition, pciStatusCapabilityList)
_, err = config.Write(*data.Raw()) _, err = config.Write(*data.Raw())
if err != nil { if err != nil {
return err return err