summaryrefslogtreecommitdiffstats
path: root/isys/pci/makeids
blob: 99a112ce177073fd1bca0f815fc8d202c04677a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/perl

require("translations");

sub parseLine {
    my($line) = @_;

    $line =~ /"(.*)"/;
    $vendor = $1;
    $device = $2;
    $class =~ s/  *$//;
    $device =~ s/  *$//;
    $id = $vendor . "|" . $device;
    return $id;
}

open(F, "pcitable");
while (<F>) {
    chop;
    if (/^# List of known device classes/) { print "moo\n"; break; }
    if (/^#/) { next; }
    s/  *$//;
    if (!length($_)) { next };
    if ( /([^\t]*)\t([^\t]*)\t([^\t]*)\t"([^"]*)"/) {
      $vendor = $1;
      $device = $2;
      $driver = $3;
      $class =~ s/  *$//;
      $device =~ s/  *$//;
      $id = $vendor . "|" . $device;

      $drivers{$id} = $driver;
    }
}
close(F);

rename("pcitable","pcitable.old");
open(F, "<pci.ids");

open(DRIVERS, ">pcitable");

print DRIVERS "# This file is automatically generated from isys/pci. Editing\n";
print DRIVERS "# it by hand is rarely the right thing to do.";
print DRIVERS "\n";
print DRIVERS "# The format is (\"%d\\t%d\\t%s\\t\"%s\"\\n\", classid, devid, moduleName, cardDescription)";
print DRIVERS "\n\n";

$class = "";


while (<F>) {
    chop;
    s/   */ /g;
    s/^  *//g;
    s/  *$//g;
    if (/^# List of known device classes/) { print "moo\n"; last; }
    if (/^#.*/) { next };
    if (!length($_)) { next };

    if (/^\t/) {
	if ($class eq "") {
	    die "unexpected device\n";
	}
	s/\t([0-9A-Fa-f]+) +//;
	$devid = $1;

	$name = $class . "|" . $_;
	$device = "0x" . $classid . "|0x" . $devid;
	if ($drivers{$device}) {
	    printf(DRIVERS "0x%s\t0x%s\t%s\t\"%s\"\n", $classid, $devid, 
		   $drivers{$device},$name);
	} else {
	    printf(DRIVERS "0x%s\t0x%s\t%s\t\"%s\"\n", $classid, $devid,
	    	  "unknown",$name);
	}
    } else {
	s/([0-9A-Fa-f]+) +//;
	$classid = $1;
	if ($classtr{$_}) {
	    $class = $classtr{$_};
	} else {
	    $class = $_;
	}
    }
}

close(F);