-#!/usr/bin/python2
+#!/usr/bin/python
# Copyright (c) 2003 Intel Corporation
# All rights reserved.
import re
import errno
import ModelOptions
-try:
- from pypciscan import get_devices
-except:
- def get_devices():
- """ This is a replacement to the version in pypciscan library for 3.3 and lower bootcds
- that will help maintain backward compatibility. This version has limitations wrt accuracy
- that the library does not. In particular it is limited to the output of
- lspci and 'forces' all devices to appear on the '0000' domain, rather than
- where they actually are."""
-
- ret = {}
- #pci = os.popen("lspci -nm | sed -e 's/\"//g'", 'r')
- pci = os.popen("lspci -nm | sed -e 's/\"//g' -e 's/Class //g'", 'r')
- for line in pci:
- l = line[:-1]
- f = l.split(" ")
- key = "0000:%s" % f[0]
- ret[key] = (int(f[2],16), int(f[3],16), 0xffff, 0xffff, int(f[1],16) << 8)
- return ret
-
-import pypcimap
+from pypci import *
from Exceptions import *
"""
BLOCKS_PER_GB = pow(10, 9) / 1024.0;
-# -n is numeric ids (no lookup), -m is machine readable
-LSPCI_CMD= "/sbin/lspci -nm"
-
MODULE_CLASS_NETWORK= "network"
MODULE_CLASS_SCSI= "scsi"
-PCI_BASE_CLASS_NETWORK=0x02L
-PCI_BASE_CLASS_STORAGE=0x01L
-
-PCI_ANY=0xffffffffL
+#PCI_* is now defined in the pypci modules
+#PCI_BASE_CLASS_NETWORK=0x02L
+#PCI_BASE_CLASS_STORAGE=0x01L
def get_total_phsyical_mem(vars = {}, log = sys.stderr):
"""
# table with valid scsi/sata/ide/raid block device names
valid_blk_names = {}
# add in valid sd and hd block device names
- for blk_prefix in ('sd','hd'):
+ # also check for vd (virtio devices used with kvm)
+ for blk_prefix in ('sd','hd','vd'):
for blk_num in map ( \
lambda x: chr(x), range(ord('a'),ord('z')+1)):
devicename="%s%c" % (blk_prefix, blk_num)
modules_pcimap_path = "%s/lib/modules/%s/modules.pcimap" % \
(SYSIMG_PATH,kernel_version)
if not os.access(modules_pcimap_path,os.R_OK):
- print( "Unable to read %s" % path )
+ print( "WARNING: Unable to read %s" % modules_pcimap_path )
return
pcimap = pypcimap.PCIMap(modules_pcimap_path)
# XXX: this is really similar to what BootCD/conf_files/pl_hwinit does. merge?
pcidevs = get_devices()
- for (slot, dev) in pcidevs.iteritems():
+ devlist=pcidevs.keys()
+ devlist.sort()
+ for slot in devlist:
+ dev = pcidevs[slot]
base = (dev[4] & 0xff0000) >> 16
+ modules = pcimap.get(dev)
if base not in (PCI_BASE_CLASS_STORAGE,
PCI_BASE_CLASS_NETWORK):
- continue
+ # special exception for forcedeth NICs whose base id
+ # claims to be a Bridge, even though it is clearly a
+ # network device
+ if "forcedeth" in modules:
+ base=PCI_BASE_CLASS_NETWORK
+ else:
+ continue
- modules = pcimap.get(dev)
if len(modules) > 0:
if base == PCI_BASE_CLASS_NETWORK:
network_mods += modules
if not modules:
print "unable to list system modules"
else:
- for type in modules:
- if type == MODULE_CLASS_SCSI:
- print( "all scsi modules:" )
- for a_mod in modules[type]:
- print a_mod
- elif type == MODULE_CLASS_NETWORK:
- print( "all network modules:" )
- for a_mod in modules[type]:
- print a_mod
+ for module_class in (MODULE_CLASS_SCSI,MODULE_CLASS_NETWORK):
+ if len(modules[module_class]) > 0:
+ module_list = ""
+ for a_mod in modules[module_class]:
+ module_list = module_list + "%s " % a_mod
+ print "all %s modules: %s" % (module_class, module_list)