summaryrefslogtreecommitdiffstats
path: root/convert
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2000-12-15 23:54:39 +0000
committerPascal Rigaux <pixel@mandriva.com>2000-12-15 23:54:39 +0000
commit795cbb9daaaccff2e81422fa266e095767d8e5f8 (patch)
tree7ce0b5ab7ff28e5059893512d1aa82245be4521f /convert
parent96db78ac384ac0119eadea1f296567a34912f592 (diff)
downloadldetect-lst-795cbb9daaaccff2e81422fa266e095767d8e5f8.tar
ldetect-lst-795cbb9daaaccff2e81422fa266e095767d8e5f8.tar.gz
ldetect-lst-795cbb9daaaccff2e81422fa266e095767d8e5f8.tar.bz2
ldetect-lst-795cbb9daaaccff2e81422fa266e095767d8e5f8.tar.xz
ldetect-lst-795cbb9daaaccff2e81422fa266e095767d8e5f8.zip
move to convert directory the convert tools
Diffstat (limited to 'convert')
-rw-r--r--convert/Makefile13
-rw-r--r--convert/README.pcitable14
-rwxr-xr-xconvert/merge2pcitable.pl141
-rw-r--r--convert/xf86PciInfo2pcitable.c22
-rw-r--r--convert/xf86str.h13
5 files changed, 203 insertions, 0 deletions
diff --git a/convert/Makefile b/convert/Makefile
new file mode 100644
index 00000000..1aec5909
--- /dev/null
+++ b/convert/Makefile
@@ -0,0 +1,13 @@
+FILES = xf86PciInfo2pcitable
+
+all: $(FILES)
+
+clean:
+ rm -f $(FILES)
+
+xf86PciInfo2pcitable: %: %.c xf86PciInfo.h
+ gcc -o $@ $<
+
+#do
+# take new xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h in XFree86-4
+# make ; ./xf86PciInfo2pcitable > /tmp/xf_pcitable ; perl rh_pcitable2pcitable /tmp/xf_pcitable ../pcitable
diff --git a/convert/README.pcitable b/convert/README.pcitable
new file mode 100644
index 00000000..c792a3e1
--- /dev/null
+++ b/convert/README.pcitable
@@ -0,0 +1,14 @@
+################################################################################
+# How to merge the pcitable with various source:
+#
+# update pciutils
+./merge2pcitable pciids /usr/share/pci.ids pcitable > pcitable.new
+
+# with redhat's pcitable in /tmp/rh_pcitable (from kudzu or anaconda)
+./merge2pcitable pcitable /tmp/rh_pcitable pcitable > pcitable.new
+
+# with a new kernel
+./merge2pcitable kernel_pcimap $(echo /lib/modules/2.4.*/modules.pcimap | sed 's/ .*//') pcitable > pcitable.new
+
+# checking the pcitable
+./merge2pcitable pcitable pcitable pcitable > /dev/null
diff --git a/convert/merge2pcitable.pl b/convert/merge2pcitable.pl
new file mode 100755
index 00000000..a5d85046
--- /dev/null
+++ b/convert/merge2pcitable.pl
@@ -0,0 +1,141 @@
+#!/usr/bin/perl
+
+$ARGV[0] eq '-f' and $force = shift;
+$ARGV[0] eq '-a' and $all = shift;
+
+my $formats = join '|', grep {$_} map { /^read_(.*)/ ? $1 : '' } keys %main::;
+
+@ARGV == 3 or die "usage: $0 [-f] [-a] $formats <in_file> <mdk_pcitable>\n";
+
+($format, $in, $pcitable) = @ARGV;
+
+my $read = $main::{"read_$format"} or die "unknown format $format (must be one of $formats)\n";
+my $d_pci = read_pcitable($pcitable);
+my $d_in = $read->($in);
+merge($d_pci, $d_in);
+write_pcitable($d_pci);
+
+sub to_string {
+ my ($id, $driver) = @_;
+ my ($module, $text) = map { qq("$_") } @$driver;
+ my ($id1, $id2, $subid1, $subid2) = map { "0x$_" } ($id =~ /(....)/g);
+ join "\t", $id1, $id2, "$subid1 $subid2" ne "0xffff 0xffff" ? ($subid1, $subid2) : (), $module, $text;
+}
+
+# works for RedHat's pcitable old and new format, + mdk format (alike RedHat's old one)
+# (the new format has ending .o's and double quotes are removed)
+sub read_pcitable {
+ my ($f) = @_;
+ my %drivers;
+ my $rm_quote = sub { s/^"//; s/"$//; $_ };
+ open F, $f or die "read_pcitable: can't open $f\n";
+ my $line = 0;
+ foreach (<F>) {
+ chomp; $line++;
+ next if /^#/ || /^\s*$/;
+ if (my ($id1, $id2, @l) = split /\t+/) {
+ my ($subid1, $subid2) = ('ffff', 'ffff');
+ ($subid1, $subid2, @l) = @l if @l == 4;
+ @l == 2 or die "$f $line: bad number of fields (in $_)\n";
+ my ($module, $text) = @l;
+
+ my $class = $text =~ /(.*?)|/;
+ my $id1_ = $rm_quote->($id1);
+ if ($class{$id1_}) {
+ print STDERR "$f $line: class $id1_ named both $class and $class{$id1_}, taking $class{$id1_}\n";
+ $class{$id1_} ||= $1;
+ $text =~ s/(.*?)|/$class{$id1_}|/;
+ }
+
+ $module =~ s/\.o$//;
+ $module = "unknown" if $module =~ /alsa|ignore/; # stupid rh stuff
+ my $id = join '', map { s/^0x//; $_ } $id1, $id2, $subid1, $subid2;
+ $drivers{$id} and print STDERR "$f $line: multiple entry for $id (skipping $module $text)\n";
+ $drivers{$id} ||= [ map &$rm_quote, $module, $text ];
+ }
+ }
+ \%drivers;
+}
+
+sub read_kernel_pcimap {
+ my ($f) = @_;
+ my %drivers;
+ open F, $f or die "read_kernel_pcimap: can't open $f\n";
+ foreach (<F>) {
+ chomp;
+ next if /^#/ || /^\s*$/;
+ my ($module, $id1, $id2, $subid1, $subid2) = split;
+ $drivers{join '', map { /(....)$/ } $id1, $id2, $subid1, $subid2} = [ $module, '' ];
+ }
+ \%drivers;
+}
+
+sub read_pciids {
+ my ($f) = @_;
+ my %drivers;
+ my ($id1, $id2, $class, $line);
+ open F, $f or die "read_pciids: can't open $f\n";
+ foreach (<F>) {
+ chomp; $line++;
+ next if /^#/ || /^;/ || /^\s*$/;
+ if (/^C\s/) {
+ last;
+ } elsif (/^\t\t(\S+)\s+(\S+)\s+(.*)/) {
+ $id1 && $id2 or die "$f $line: unexpected device\n";
+ $drivers{"$id1$id2$1$2"} = [ "unknown", "$class|$3" ];
+ } elsif (/^\t(\S+)\s+(.*)/) {
+ $id2 = $1;
+ $id1 && $id2 or die "$f $line: unexpected device\n";
+ $drivers{"$id1${id2}ffffffff"} = [ "unknown", "$class|$2" ];
+ } elsif (/^(\S+)\s+(.*)/) {
+ $id1 = $1;
+ $class = $class{$2} || $2;
+ } else {
+ die "bad line: $_";
+ }
+ }
+ \%drivers;
+}
+
+sub read_pcitablepm {
+ my ($f) = @_;
+ open F, $f or die "read_pcitablepm: can't open $f\n";
+ eval join('', <F>);
+
+ %pci_probing::pcitable::ids or die;
+ while (my ($k, $v) = each %pci_probing::pcitable::ids) {
+ $drivers{sprintf qq(%08xffffffff), $k >> 32} = [ $v->[1], $v->[0] ];
+ }
+ \%drivers;
+}
+
+# write in RedHat's pcitable old format (mdk one)
+sub write_pcitable {
+ my ($drivers) = @_;
+ foreach (sort keys %$drivers) {
+ print to_string($_, $drivers->{$_}), "\n";
+ }
+}
+
+sub merge {
+ my ($drivers, $new) = @_;
+
+ foreach (keys %$new) {
+ next if $new->{$_}[0] =~ /parport_pc|i810_ng/;
+ if ($drivers->{$_}) {
+ if ($new->{$_}[0] !~ /unknown|ignore/) {
+ if ($drivers->{$_}[0] =~ /unknown|ignore/ || $force) {
+ $drivers->{$_}[0] = $new->{$_}[0];
+ } elsif ($drivers->{$_}[0] ne $new->{$_}[0]) {
+ print STDERR "different($drivers->{$_}[0] $new->{$_}[0]): ", to_string($_, $drivers->{$_}), "\n"
+ # special case for framebuffer modules
+ unless $new->{$_}[0] =~ /fb/ && $drivers->{$_}[0] =~ /^(Card|Server):/;
+ }
+ }
+ } else {
+ $drivers->{$_} = $new->{$_}
+ # don't keep sub-entries with unknown drivers
+ if $all || /ffffffff$/ || $new->{$_}[0] !~ /(unknown|ignore)/;
+ }
+ }
+}
diff --git a/convert/xf86PciInfo2pcitable.c b/convert/xf86PciInfo2pcitable.c
new file mode 100644
index 00000000..30374b79
--- /dev/null
+++ b/convert/xf86PciInfo2pcitable.c
@@ -0,0 +1,22 @@
+/* take xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h in XFree86-4 */
+#include "xf86PciInfo.h"
+
+const char *vendor2text(int id) {
+ SymTabRec *p;
+ for (p = xf86PCIVendorNameInfoData; p->token; p++)
+ if (p->token == id) return p->name;
+ fprintf(stderr, "error, bad vendor id\n");
+ exit(1);
+}
+
+main() {
+ pciVendorDeviceInfo *p;
+
+ for (p = xf86PCIVendorInfoData; p->VendorID; p++) {
+ struct pciDevice *q;
+ const char *vendor = vendor2text(p->VendorID);
+ for (q = p->Device; q->DeviceID; q++) {
+ printf("0x%04x\t0x%04x\t\"unknown\"\t\"%s|%s\"\n", p->VendorID, q->DeviceID, vendor, q->DeviceName);
+ }
+ }
+}
diff --git a/convert/xf86str.h b/convert/xf86str.h
new file mode 100644
index 00000000..9d9f5001
--- /dev/null
+++ b/convert/xf86str.h
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+typedef struct {
+ int token; /* id of the token */
+ const char * name; /* token name */
+} SymTabRec, *SymTabPtr;
+
+#define CARD16 int
+
+#define INIT_PCI_CARD_INFO
+#define INIT_PCI_VENDOR_INFO
+#define INIT_PCI_VENDOR_NAME_INFO
+#define VENDOR_INCLUDE_NONVIDEO