summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordumbbell <dumbbell@FreeBSD.org>2013-08-25 12:20:57 +0000
committerdumbbell <dumbbell@FreeBSD.org>2013-08-25 12:20:57 +0000
commit2883d71285fddaf970d2e695cdba1abf61d642c8 (patch)
treed8ed531efb2727699b065a5b9a24107266319f2f /tools
parent242eb425eb49280c3c6f8151c4980a2192e36a94 (diff)
downloadFreeBSD-src-2883d71285fddaf970d2e695cdba1abf61d642c8.zip
FreeBSD-src-2883d71285fddaf970d2e695cdba1abf61d642c8.tar.gz
drm: Update drm_pciids.h based on Linux 3.8
This header can be easily updated using the new "gen-drm_pciids" script, available in tools/tools/drm. The script uses the Linux' drm_pciids.h header for new IDs, the FreeBSD's one because we add the name of the device to each IDs, and the PCI IDs database (misc/pciids port) to fill this name automatically for new IDS. To call the script: tools/tools/drm/gen-drm_pciids \ /path/to/linux/drm_pciids.h \ /path/to/freebsd/drm_pciids.h \ /path/to/pciids/pci.ids
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/README1
-rw-r--r--tools/tools/drm/README4
-rwxr-xr-xtools/tools/drm/gen-drm_pciids183
3 files changed, 188 insertions, 0 deletions
diff --git a/tools/tools/README b/tools/tools/README
index 1260683..ef05ee0 100644
--- a/tools/tools/README
+++ b/tools/tools/README
@@ -18,6 +18,7 @@ cxgbetool A tool for the cxgbe(4) driver.
cxgbtool A tool for the cxgb(4) driver.
diffburst OBSOLETE: equivalent functionality is available via split -p.
For example: "split -p ^diff < patchfile". See split(1).
+drm Tools specific to the DRM/KMS device drivers.
editing Editor modes and the like to help editing FreeBSD code.
epfe Extract printing filter examples from printing.sgml.
ether_reflect An Ethernet packet reflector for low level testing.
diff --git a/tools/tools/drm/README b/tools/tools/drm/README
new file mode 100644
index 0000000..1bb25ad
--- /dev/null
+++ b/tools/tools/drm/README
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+gen-drm_pciids Generate drm_pciids.h based on Linux' drm_pciids.h, FreeBSD's
+ drm_pciids.h and misc/pciids database.
diff --git a/tools/tools/drm/gen-drm_pciids b/tools/tools/drm/gen-drm_pciids
new file mode 100755
index 0000000..02ed562
--- /dev/null
+++ b/tools/tools/drm/gen-drm_pciids
@@ -0,0 +1,183 @@
+#!/usr/bin/perl
+# $FreeBSD$
+
+use strict;
+use warnings;
+use utf8;
+
+use File::Basename;
+
+my $progname = basename($0);
+
+sub parse_linux_header ($)
+{
+ my ($header) = @_;
+
+ open(my $fh, '<', $header) or die "Can't open Linux header: $!\n";
+
+ my $in_list = 0;
+
+ my %pciids = ();
+
+ my $current_vendor_define;
+
+ while (my $line = <$fh>) {
+ if ($line =~ /^#define +([^ ]+) +/) {
+ $current_vendor_define = $1;
+ $pciids{$current_vendor_define} = {};
+ } elsif ($line =~ /^\t\{0x([0-9a-fA-F]{4}), *0x([0-9a-fA-F]{4}),[^,]+,[^,]+,[^,]+,[^,]+, *([^}]+)\}/) {
+ my $vendor_id = uc($1);
+ my $device_id = uc($2);
+ my $flags = $3;
+
+ $pciids{$current_vendor_define}{$device_id} = {
+ 'vendor_id' => $vendor_id,
+ 'flags' => $flags
+ };
+ }
+ }
+
+ close($fh);
+
+ return %pciids;
+}
+
+sub parse_freebsd_header ($) {
+ my ($header) = @_;
+
+ open(my $fh, '<', $header) or die "Can't open FreeBSD header: $!\n";
+
+ my $in_list = 0;
+
+ my %pciids = ();
+
+ my $current_vendor_define;
+
+ while (my $line = <$fh>) {
+ if ($line =~ /^#define +([^ ]+) +/) {
+ $current_vendor_define = $1;
+ $pciids{$current_vendor_define} = {};
+ } elsif ($line =~ /^\t\{0x([0-9a-fA-F]{4}), *0x([0-9a-fA-F]{4}), *([^,]+), *"([^"]+)"\}/) {
+ my $vendor_id = uc($1);
+ my $device_id = uc($2);
+ my $flags = $3;
+ my $name = $4;
+
+ $pciids{$current_vendor_define}{$device_id} = {
+ 'vendor_id' => $vendor_id,
+ 'flags' => $flags,
+ 'name' => $name
+ };
+ }
+ }
+
+ close($fh);
+
+ return %pciids;
+}
+
+sub parse_pciids_db ($) {
+ my ($header) = @_;
+
+ open(my $fh, '<', $header) or die "Can't open PCI IDs database: $!\n";
+
+ my %pciids = ();
+
+ my $current_vendor_id;
+
+ while (my $line = <$fh>) {
+ if (!$line || $line =~ /^#/) {
+ next;
+ }
+ if ($line =~ /^([0-9a-fA-F]{4}) (.+)/) {
+ # Vendor ID & name.
+ my $vendor_id = uc($1);
+ my $vendor_name = $2;
+ $pciids{$vendor_id} = {
+ 'name' => $vendor_name,
+ 'devices' => {}
+ };
+
+ $current_vendor_id = $vendor_id;
+ } elsif ($line =~ /^\t([0-9a-fA-F]{4}) (.+)/) {
+ # Device ID & name.
+ my $device_id = uc($1);
+ my $device_name = $2;
+ $pciids{$current_vendor_id}{'devices'}{$device_id} = $device_name;
+ }
+ }
+
+ close($fh);
+
+ return %pciids;
+}
+
+if (scalar(@ARGV) != 3) {
+ print STDERR "Syntax: $progname <linux_header> <freebsd_header> <pciids_db> [<vendor_define>]\n";
+ exit 1;
+}
+
+my $linux_header = $ARGV[0];
+my $freebsd_header = $ARGV[1];
+my $pciids_db = $ARGV[2];
+my $only_vendor = $ARGV[3];
+
+my %linux_pciids = parse_linux_header($linux_header);
+my %freebsd_pciids = parse_freebsd_header($freebsd_header);
+my %pciids_db = parse_pciids_db($pciids_db);
+
+print STDERR "Update FreeBSD's PCI IDs:\n";
+foreach my $vendor_define (sort keys(%linux_pciids)) {
+ if ($only_vendor && $vendor_define ne $only_vendor) {
+ print STDERR "(skip unwanted define: $vendor_define)\n";
+ next;
+ } elsif (!$only_vendor && !exists($freebsd_pciids{$vendor_define})) {
+ print STDERR "(skip unsupport define: $vendor_define)\n";
+ next;
+ }
+
+ foreach my $device_id (sort keys(%{$linux_pciids{$vendor_define}})) {
+ my $vendor_id = $linux_pciids{$vendor_define}{$device_id}{'vendor_id'};
+
+ if (exists($freebsd_pciids{$vendor_define}{$device_id})) {
+ print STDERR " $vendor_define: $vendor_id:$device_id already in header\n";
+ next;
+ }
+
+ my $flags = $linux_pciids{$vendor_define}{$device_id}{'flags'};
+ my $name = $pciids_db{$vendor_id}{'devices'}{$device_id} || "Unknown device name";
+ print STDERR " $vendor_define: $vendor_id:$device_id is missing ($name)\n";
+ $freebsd_pciids{$vendor_define}{$device_id} = {
+ 'vendor_id' => $vendor_id,
+ 'flags' => $flags,
+ 'name' => $name
+ };
+ }
+}
+
+print STDERR "\nWrite FreeBSD header to stdout...\n";
+print <<"EOF";
+/*
+ * \$FreeBSD\$
+ */
+
+/*
+ * Generated by $progname from:
+ * o previous FreeBSD's drm_pciids.h
+ * o Linux' drm_pciids.h
+ * o the PCI ID repository (http://pciids.sourceforge.net/)
+ *
+ * See tools/tools/drm/$progname.
+ */
+EOF
+foreach my $vendor_define (sort keys(%freebsd_pciids)) {
+ print "\n#define $vendor_define \\\n";
+ foreach my $device_id (sort keys(%{$freebsd_pciids{$vendor_define}})) {
+ my $vendor_id = $freebsd_pciids{$vendor_define}{$device_id}{'vendor_id'};
+ my $flags = $freebsd_pciids{$vendor_define}{$device_id}{'flags'};
+ my $name = $freebsd_pciids{$vendor_define}{$device_id}{'name'};
+
+ print "\t{0x$vendor_id, 0x$device_id, $flags, \"$name\"}, \\\n";
+ }
+ print "\t{0, 0, 0, NULL}\n";
+}
OpenPOWER on IntegriCloud