]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/PciTab.pm
Initial revision
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / PciTab.pm
1 #!perl -w
2 #
3 # PciTab -- encapsulate modules.pcimap
4 #   Copyright (C) 2005  Erik van Konijnenburg
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 #
20
21 use strict;
22 use warnings;
23 use Base;
24 use Conf;
25 use PciMapEntry;
26 package PciTab;
27
28 my $pciList = undef;
29
30 # Parse this:
31 # # pci module         vendor     device     subvendor  subdevice  class      class_mask driver_data
32 # parport_pc           0x00001106 0x00000686 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0
33 # parport_pc           0x00001106 0x00008231 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0
34
35 sub init () {
36         if (defined ($pciList)) {
37                 return;
38         }
39         $pciList = [];
40         my $name = Conf::get('pciMap');
41         if (! open (IN, "<", "$name")) {
42                 Base::fatal ("can't open pci module list $name");
43         }
44         while (defined (my $line = <IN>)) {
45                 chomp $line;
46                 $line =~ s/#.*//;
47                 $line =~ s/^\s+//;
48                 $line =~ s/\s+$//;
49                 next if ($line eq "");
50                 my @fields = split (/\s+/, $line, 999);
51                 if ($#fields != 7) {
52                         Base::fatal "malformed line in pci module list $name";
53                 }
54                 push @{$pciList}, PciMapEntry->new (
55                         module => $fields[0],
56                         vendor => hex ($fields[1]),
57                         device => hex ($fields[2]),
58                         subvendor => hex ($fields[3]),
59                         subdevice => hex ($fields[4]),
60                         class => hex ($fields[5]),
61                         classmask => hex ($fields[6]),
62                         driver_data => hex ($fields[7]),
63                         );
64         }
65         if (! close (IN)) {
66                 Base::fatal "could not read pci module list $name";
67         }
68 }
69
70 sub all () {
71         init;
72         return $pciList;
73 }
74
75 # given pathname in devices tree, find module name in PCI map as a list.
76 sub find ($) {
77         my ($dev) = @_;
78         my @result = ();
79         for my $pme (@{PciTab::all()}) {
80                 if ($pme->matches ($dev)) {
81                         push @result, $pme->module;
82                 }
83         }
84         return [@result];
85 }
86
87
88 1;
89