10 my $progname = basename($0);
12 sub parse_linux_header ($)
16 open(my $fh, '<', $header) or die "Can't open Linux header: $!\n";
22 my $current_vendor_define;
24 while (my $line = <$fh>) {
25 if ($line =~ /^#define +([^ ]+) +/) {
26 $current_vendor_define = $1;
27 $pciids{$current_vendor_define} = {};
28 } elsif ($line =~ /^\t\{0x([0-9a-fA-F]{4}), *0x([0-9a-fA-F]{4}),[^,]+,[^,]+,[^,]+,[^,]+, *([^}]+)\}/) {
29 my $vendor_id = uc($1);
30 my $device_id = uc($2);
33 $pciids{$current_vendor_define}{$device_id} = {
34 'vendor_id' => $vendor_id,
45 sub parse_freebsd_header ($) {
48 open(my $fh, '<', $header) or die "Can't open FreeBSD header: $!\n";
54 my $current_vendor_define;
56 while (my $line = <$fh>) {
57 if ($line =~ /^#define +([^ ]+) +/) {
58 $current_vendor_define = $1;
59 $pciids{$current_vendor_define} = {};
60 } elsif ($line =~ /^\t\{0x([0-9a-fA-F]{4}), *0x([0-9a-fA-F]{4}), *([^,]+), *"([^"]+)"\}/) {
61 my $vendor_id = uc($1);
62 my $device_id = uc($2);
66 $pciids{$current_vendor_define}{$device_id} = {
67 'vendor_id' => $vendor_id,
79 sub parse_pciids_db ($) {
82 open(my $fh, '<', $header) or die "Can't open PCI IDs database: $!\n";
86 my $current_vendor_id;
88 while (my $line = <$fh>) {
89 if (!$line || $line =~ /^#/) {
92 if ($line =~ /^([0-9a-fA-F]{4}) (.+)/) {
94 my $vendor_id = uc($1);
96 $pciids{$vendor_id} = {
97 'name' => $vendor_name,
101 $current_vendor_id = $vendor_id;
102 } elsif ($line =~ /^\t([0-9a-fA-F]{4}) (.+)/) {
104 my $device_id = uc($1);
105 my $device_name = $2;
106 $pciids{$current_vendor_id}{'devices'}{$device_id} = $device_name;
115 if (scalar(@ARGV) != 3) {
116 print STDERR "Syntax: $progname <linux_header> <freebsd_header> <pciids_db> [<vendor_define>]\n";
120 my $linux_header = $ARGV[0];
121 my $freebsd_header = $ARGV[1];
122 my $pciids_db = $ARGV[2];
123 my $only_vendor = $ARGV[3];
125 my %linux_pciids = parse_linux_header($linux_header);
126 my %freebsd_pciids = parse_freebsd_header($freebsd_header);
127 my %pciids_db = parse_pciids_db($pciids_db);
129 print STDERR "Update FreeBSD's PCI IDs:\n";
130 foreach my $vendor_define (sort keys(%linux_pciids)) {
131 if ($only_vendor && $vendor_define ne $only_vendor) {
132 print STDERR "(skip unwanted define: $vendor_define)\n";
134 } elsif (!$only_vendor && !exists($freebsd_pciids{$vendor_define})) {
135 print STDERR "(skip unsupport define: $vendor_define)\n";
139 foreach my $device_id (sort keys(%{$linux_pciids{$vendor_define}})) {
140 my $vendor_id = $linux_pciids{$vendor_define}{$device_id}{'vendor_id'};
142 if (exists($freebsd_pciids{$vendor_define}{$device_id})) {
143 print STDERR " $vendor_define: $vendor_id:$device_id already in header\n";
147 my $flags = $linux_pciids{$vendor_define}{$device_id}{'flags'};
148 my $name = $pciids_db{$vendor_id}{'devices'}{$device_id} || "Unknown device name";
149 print STDERR " $vendor_define: $vendor_id:$device_id is missing ($name)\n";
150 $freebsd_pciids{$vendor_define}{$device_id} = {
151 'vendor_id' => $vendor_id,
158 print STDERR "\nWrite FreeBSD header to stdout...\n";
165 * Generated by $progname from:
166 * o previous FreeBSD's drm_pciids.h
167 * o Linux' drm_pciids.h
168 * o the PCI ID repository (http://pciids.sourceforge.net/)
170 * See tools/tools/drm/$progname.
173 foreach my $vendor_define (sort keys(%freebsd_pciids)) {
174 print "\n#define $vendor_define \\\n";
175 foreach my $device_id (sort keys(%{$freebsd_pciids{$vendor_define}})) {
176 my $vendor_id = $freebsd_pciids{$vendor_define}{$device_id}{'vendor_id'};
177 my $flags = $freebsd_pciids{$vendor_define}{$device_id}{'flags'};
178 my $name = $freebsd_pciids{$vendor_define}{$device_id}{'name'};
180 print "\t{0x$vendor_id, 0x$device_id, $flags, \"$name\"}, \\\n";
182 print "\t{0, 0, 0, NULL}\n";