Skip to content

Commit 52a2a47

Browse files
committed
Merge pull request #4 from rdobson/pcidevice
Adding initial PCIDevice object which should provide a suitable abstract...
2 parents 1e8d14c + 4b5fb2c commit 52a2a47

3 files changed

Lines changed: 165 additions & 0 deletions

File tree

hwinfo/pci/__init__.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""Core PCI module"""
2+
3+
class PCIDevice(object):
4+
5+
def __init__(self, record):
6+
self.rec = record
7+
8+
def lookup_value(self, k):
9+
return self.rec[k]
10+
11+
def get_device_name(self):
12+
name = self.lookup_value('pci_device_name')
13+
if name == 'Device':
14+
# If the input has come from lspci, this is the value for
15+
# not being able to find a key in the pciids db.
16+
return 'unknown [%s]' % self.get_device_id()
17+
else:
18+
return name
19+
20+
21+
def get_device_id(self):
22+
return self.lookup_value('pci_device_id')
23+
24+
def get_vendor_name(self):
25+
return self.lookup_value('pci_vendor_name')
26+
27+
def get_vendor_id(self):
28+
return self.lookup_value('pci_vendor_id')
29+
30+
def get_subdevice_name(self):
31+
name = self.lookup_value('pci_subdevice_name')
32+
if name == 'Device':
33+
# If the input has come from lspci, this is the value for
34+
# not being able to find a key in the pciids db.
35+
return 'unknown [%s]' % self.get_subdevice_id()
36+
else:
37+
return name
38+
39+
def get_subdevice_id(self):
40+
return self.lookup_value('pci_subdevice_id')
41+
42+
def get_subvendor_name(self):
43+
return self.lookup_value('pci_subvendor_name')
44+
45+
def get_subvendor_id(self):
46+
return self.lookup_value('pci_subvendor_id')
47+
48+
def get_pci_id(self):
49+
return "%s:%s %s:%s" % (
50+
self.lookup_value('pci_vendor_id'),
51+
self.lookup_value('pci_device_id'),
52+
self.lookup_value('pci_subvendor_id'),
53+
self.lookup_value('pci_subdevice_id'),
54+
)
55+
56+
def is_subdevice(self):
57+
return 'pci_subvendor_id' in self.rec and 'pci_subdevice_id' in self.rec
58+
59+
def get_info(self):
60+
61+
if self.is_subdevice():
62+
return "%s %s (%s %s)" % (self.get_subvendor_name(), self.get_subdevice_name(), self.get_vendor_name(), self.get_device_name())

hwinfo/pci/tests/data/lspci-nnmm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
00:00.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor DMI [d130]" -r11 "Dell [1028]" "Device [02a3]"
2+
00:03.0 "PCI bridge [0604]" "Intel Corporation [8086]" "Core Processor PCI Express Root Port 1 [d138]" -r11 "" ""
3+
00:05.0 "PCI bridge [0604]" "Intel Corporation [8086]" "Core Processor PCI Express Root Port 3 [d13a]" -r11 "" ""
4+
00:08.0 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor System Management Registers [d155]" -r11 "" ""
5+
00:08.1 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor Semaphore and Scratchpad Registers [d156]" -r11 "" ""
6+
00:08.2 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor System Control and Status Registers [d157]" -r11 "" ""
7+
00:08.3 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor Miscellaneous Registers [d158]" -r11 "" ""
8+
00:10.0 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor QPI Link [d150]" -r11 "" ""
9+
00:10.1 "System peripheral [0880]" "Intel Corporation [8086]" "Core Processor QPI Routing and Protocol Registers [d151]" -r11 "" ""
10+
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]"
11+
00:1c.0 "PCI bridge [0604]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset PCI Express Root Port 1 [3b42]" -r05 "" ""
12+
00:1c.4 "PCI bridge [0604]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset PCI Express Root Port 5 [3b4a]" -r05 "" ""
13+
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]"
14+
00:1e.0 "PCI bridge [0604]" "Intel Corporation [8086]" "82801 PCI Bridge [244e]" -ra5 -p01 "" ""
15+
00:1f.0 "ISA bridge [0601]" "Intel Corporation [8086]" "3400 Series Chipset LPC Interface Controller [3b14]" -r05 "Dell [1028]" "Device [02a3]"
16+
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]"
17+
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]"
18+
01:03.0 "VGA compatible controller [0300]" "Matrox Electronics Systems Ltd. [102b]" "MGA G200eW WPCM450 [0532]" -r0a "Dell [1028]" "Device [02a3]"
19+
02:00.0 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"
20+
02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"
21+
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]"
22+
ff:00.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QuickPath Architecture Generic Non-Core Registers [2c50]" -r04 "Intel Corporation [8086]" "Device [8086]"
23+
ff:00.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QuickPath Architecture System Address Decoder [2c81]" -r04 "Intel Corporation [8086]" "Device [8086]"
24+
ff:02.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QPI Link 0 [2c90]" -r04 "Intel Corporation [8086]" "Device [8086]"
25+
ff:02.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor QPI Physical 0 [2c91]" -r04 "Intel Corporation [8086]" "Device [8086]"
26+
ff:03.0 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller [2c98]" -r04 "Intel Corporation [8086]" "Device [8086]"
27+
ff:03.1 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Target Address Decoder [2c99]" -r04 "Intel Corporation [8086]" "Device [8086]"
28+
ff:03.2 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Test Registers [2c9a]" -r04 "Intel Corporation [8086]" "Device [8086]"
29+
ff:03.4 "Host bridge [0600]" "Intel Corporation [8086]" "Core Processor Integrated Memory Controller Test Registers [2c9c]" -r04 "Intel Corporation [8086]" "Device [8086]"
30+
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]"
31+
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]"
32+
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]"
33+
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]"
34+
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]"
35+
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]"
36+
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]"
37+
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]"

hwinfo/pci/tests/test_pci.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Module for unittesting the core pci module"""
2+
3+
import unittest
4+
from hwinfo.pci import *
5+
6+
class TestPCIDeviceObject(unittest.TestCase):
7+
8+
DEVICE_REC = {
9+
'pci_device_bus_id': '02:00.0',
10+
'pci_device_type_id': '0200',
11+
'pci_device_type_name': 'Ethernet controller',
12+
'pci_vendor_name': 'Broadcom Corporation',
13+
'pci_vendor_id': '14e4',
14+
'pci_device_id': '163b',
15+
'pci_device_name': 'NetXtreme II BCM5716 Gigabit Ethernet',
16+
'pci_subvendor_name': 'Dell',
17+
'pci_subvendor_id': '1028',
18+
'pci_subdevice_name': 'Device',
19+
'pci_subdevice_id': '02a3',
20+
}
21+
22+
def setUp(self):
23+
self.device = PCIDevice(self.DEVICE_REC)
24+
25+
def test_get_device_name(self):
26+
name = self.device.get_device_name()
27+
self.assertEqual(name, 'NetXtreme II BCM5716 Gigabit Ethernet')
28+
29+
def test_get_vendor_name(self):
30+
name = self.device.get_vendor_name()
31+
self.assertEqual(name, 'Broadcom Corporation')
32+
33+
def test_get_vendor_id(self):
34+
name = self.device.get_vendor_id()
35+
self.assertEqual(name, '14e4')
36+
37+
def test_get_subdevice_name(self):
38+
name = self.device.get_subdevice_name()
39+
self.assertEqual(name, 'unknown [02a3]')
40+
41+
def test_get_subvendor_name(self):
42+
name = self.device.get_subvendor_name()
43+
self.assertEqual(name, 'Dell')
44+
45+
def test_get_subvendor_id(self):
46+
name = self.device.get_subvendor_id()
47+
self.assertEqual(name, '1028')
48+
49+
def test_get_device_id(self):
50+
name = self.device.get_device_id()
51+
self.assertEqual(name, '163b')
52+
53+
def test_get_subdevice_id(self):
54+
name = self.device.get_subdevice_id()
55+
self.assertEqual(name, '02a3')
56+
57+
def test_get_pci_id(self):
58+
pciid = self.device.get_pci_id()
59+
self.assertEqual(pciid, '14e4:163b 1028:02a3')
60+
61+
def test_is_subdevice(self):
62+
self.assertTrue(self.device.is_subdevice())
63+
64+
def test_get_device_info(self):
65+
info = self.device.get_info()
66+
self.assertEqual(info, 'Dell unknown [02a3] (Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet)')

0 commit comments

Comments
 (0)