-
-
-class merge_hw_tables:
-
- def merge_files(self, modules_dep_path, modules_pcimap_path, pcitable_path):
- """
- merge the three files as described above, and return a dictionary.
- keys are module names, value is a list of pci ids for that module,
- in the form "0e11:b178"
- """
+PCI_ANY = 0xffffffffL
+
+def merge_files(modules_dep_path, modules_pcimap_path, pcitable_path):
+ """
+ merge the three files as described above, and return a dictionary.
+ keys are module names, value is a list of pci ids for that module,
+ in the form "0e11:b178"
+ """
+
+ try:
+ modulesdep_file= file(modules_dep_path,"r")
+ except IOError:
+ sys.stderr.write( "Unable to open modules.dep: %s\n" %
+ modules_dep_path )
+ return
+
+ try:
+ pcimap_file= file(modules_pcimap_path,"r")
+ except IOError:
+ sys.stderr.write( "Unable to open modules.pcimap: %s\n" %
+ modules_pcimap_path )
+ return
+
+ try:
+ pcitable_file= file(pcitable_path,"r")
+ except IOError:
+ sys.stderr.write( "Unable to open pcitable: %s\n" %
+ pcitable_path )
+ return
+
+ # associative array to store all matches of module -> ['vendor:device',..]
+ # entries
+ all_modules= {}
+ all_pci_ids= {}
+
+ # first step, create an associative array of all the built modules
+ for line in modulesdep_file:
+ parts= string.split(line,":")
+ if len(parts) < 2:
+ continue
+
+ full_mod_path= parts[0]
+ parts= string.split(full_mod_path,"/")
+ module= parts[len(parts)-1]
+ module_len= len(module)
+ if module[module_len-3:] == ".ko":
+ module= module[:-3]
+ all_modules[module]= []
+
+ modulesdep_file.close()
+
+ # now, parse the pcimap and add devices
+ line_num= 0
+ for line in pcimap_file:
+ line_num= line_num+1
+
+ # skip blank lines, or lines that begin with # (comments)
+ line= string.strip(line)
+ if len(line) == 0:
+ continue
+
+ if line[0] == "#":
+ continue
+
+ line_parts= string.split(line)
+ if line_parts is None or len(line_parts) != 8:
+ sys.stderr.write( "Skipping line %d in pcimap " \
+ "(incorrect format %s)\n" % (line_num,line) )
+ continue
+
+ # first two parts are always vendor / device id
+ module= line_parts[0]