Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions hwinfo/pci/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Core PCI module"""

class PCIDevice(object):

def __init__(self, record):
self.rec = record

def lookup_value(self, k):
return self.rec[k]

def get_device_name(self):
name = self.lookup_value('pci_device_name')
if name == 'Device':
# If the input has come from lspci, this is the value for
# not being able to find a key in the pciids db.
return 'unknown [%s]' % self.get_device_id()
else:
return name


def get_device_id(self):
return self.lookup_value('pci_device_id')

def get_vendor_name(self):
return self.lookup_value('pci_vendor_name')

def get_vendor_id(self):
return self.lookup_value('pci_vendor_id')

def get_subdevice_name(self):
name = self.lookup_value('pci_subdevice_name')
if name == 'Device':
# If the input has come from lspci, this is the value for
# not being able to find a key in the pciids db.
return 'unknown [%s]' % self.get_subdevice_id()
else:
return name

def get_subdevice_id(self):
return self.lookup_value('pci_subdevice_id')

def get_subvendor_name(self):
return self.lookup_value('pci_subvendor_name')

def get_subvendor_id(self):
return self.lookup_value('pci_subvendor_id')

def get_pci_id(self):
return "%s:%s %s:%s" % (
self.lookup_value('pci_vendor_id'),
self.lookup_value('pci_device_id'),
self.lookup_value('pci_subvendor_id'),
self.lookup_value('pci_subdevice_id'),
)

def is_subdevice(self):
return 'pci_subvendor_id' in self.rec and 'pci_subdevice_id' in self.rec

def get_info(self):

if self.is_subdevice():
return "%s %s (%s %s)" % (self.get_subvendor_name(), self.get_subdevice_name(), self.get_vendor_name(), self.get_device_name())
37 changes: 37 additions & 0 deletions hwinfo/pci/tests/data/lspci-nnmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
00:00.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor DMI [d130]" -r11 "Dell [1028]" "Device [02a3]"
00:03.0 "PCI bridge [0604]" "Intel Corporation [8086]" "Core Processor PCI Express Root Port 1 [d138]" -r11 "" ""
00:05.0 "PCI bridge [0604]" "Intel Corporation [8086]" "Core Processor PCI Express Root Port 3 [d13a]" -r11 "" ""
00:08.0 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor System Management Registers [d155]" -r11 "" ""
00:08.1 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor Semaphore and Scratchpad Registers [d156]" -r11 "" ""
00:08.2 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor System Control and Status Registers [d157]" -r11 "" ""
00:08.3 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor Miscellaneous Registers [d158]" -r11 "" ""
00:10.0 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor QPI Link [d150]" -r11 "" ""
00:10.1 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor QPI Routing and Protocol Registers [d151]" -r11 "" ""
00:1a.0 "USB controller [0c03]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset USB2 Enhanced Host Controller [3b3c]" -r05 -p20 "Dell [1028]" "Device [02a3]"
00:1c.0 "PCI bridge [0604]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset PCI Express Root Port 1 [3b42]" -r05 "" ""
00:1c.4 "PCI bridge [0604]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset PCI Express Root Port 5 [3b4a]" -r05 "" ""
00:1d.0 "USB controller [0c03]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset USB2 Enhanced Host Controller [3b34]" -r05 -p20 "Dell [1028]" "Device [02a3]"
00:1e.0 "PCI bridge [0604]" "Intel Corporation [8086]" "82801 PCI Bridge [244e]" -ra5 -p01 "" ""
00:1f.0 "ISA bridge [0601]" "Intel Corporation [8086]" "3400 Series Chipset LPC Interface Controller [3b14]" -r05 "Dell [1028]" "Device [02a3]"
00:1f.2 "IDE interface [0101]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset 4 port SATA IDE Controller [3b20]" -r05 -p8f "Dell [1028]" "Device [02a3]"
00:1f.5 "IDE interface [0101]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset 2 port SATA IDE Controller [3b26]" -r05 -p85 "Dell [1028]" "Device [02a3]"
01:03.0 "VGA compatible controller [0300]" "Matrox Electronics Systems Ltd. [102b]" "MGA G200eW WPCM450 [0532]" -r0a "Dell [1028]" "Device [02a3]"
02:00.0 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"
02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"
03:00.0 "SCSI storage controller [0100]" "LSI Logic / Symbios Logic [1000]" "SAS1068E PCI-Express Fusion-MPT SAS [0058]" -r08 "Dell [1028]" "SAS 6/iR Integrated Blades RAID Controller [1f0f]"
ff:00.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QuickPath Architecture Generic Non-Core Registers [2c50]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:00.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QuickPath Architecture System Address Decoder [2c81]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:02.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QPI Link 0 [2c90]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:02.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QPI Physical 0 [2c91]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:03.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller [2c98]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:03.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Target Address Decoder [2c99]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:03.2 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Test Registers [2c9a]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:03.4 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Test Registers [2c9c]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:04.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 0 Control Registers [2ca0]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:04.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 0 Address Registers [2ca1]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:04.2 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 0 Rank Registers [2ca2]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:04.3 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 0 Thermal Control Registers [2ca3]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:05.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 1 Control Registers [2ca8]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:05.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 1 Address Registers [2ca9]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:05.2 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 1 Rank Registers [2caa]" -r04 "Intel Corporation [8086]" "Device [8086]"
ff:05.3 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Channel 1 Thermal Control Registers [2cab]" -r04 "Intel Corporation [8086]" "Device [8086]"
66 changes: 66 additions & 0 deletions hwinfo/pci/tests/test_pci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Module for unittesting the core pci module"""

import unittest
from hwinfo.pci import *

class TestPCIDeviceObject(unittest.TestCase):

DEVICE_REC = {
'pci_device_bus_id': '02:00.0',
'pci_device_type_id': '0200',
'pci_device_type_name': 'Ethernet controller',
'pci_vendor_name': 'Broadcom Corporation',
'pci_vendor_id': '14e4',
'pci_device_id': '163b',
'pci_device_name': 'NetXtreme II BCM5716 Gigabit Ethernet',
'pci_subvendor_name': 'Dell',
'pci_subvendor_id': '1028',
'pci_subdevice_name': 'Device',
'pci_subdevice_id': '02a3',
}

def setUp(self):
self.device = PCIDevice(self.DEVICE_REC)

def test_get_device_name(self):
name = self.device.get_device_name()
self.assertEqual(name, 'NetXtreme II BCM5716 Gigabit Ethernet')

def test_get_vendor_name(self):
name = self.device.get_vendor_name()
self.assertEqual(name, 'Broadcom Corporation')

def test_get_vendor_id(self):
name = self.device.get_vendor_id()
self.assertEqual(name, '14e4')

def test_get_subdevice_name(self):
name = self.device.get_subdevice_name()
self.assertEqual(name, 'unknown [02a3]')

def test_get_subvendor_name(self):
name = self.device.get_subvendor_name()
self.assertEqual(name, 'Dell')

def test_get_subvendor_id(self):
name = self.device.get_subvendor_id()
self.assertEqual(name, '1028')

def test_get_device_id(self):
name = self.device.get_device_id()
self.assertEqual(name, '163b')

def test_get_subdevice_id(self):
name = self.device.get_subdevice_id()
self.assertEqual(name, '02a3')

def test_get_pci_id(self):
pciid = self.device.get_pci_id()
self.assertEqual(pciid, '14e4:163b 1028:02a3')

def test_is_subdevice(self):
self.assertTrue(self.device.is_subdevice())

def test_get_device_info(self):
info = self.device.get_info()
self.assertEqual(info, 'Dell unknown [02a3] (Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet)')