parse_pci_ids.pl revision 18781e08
1#!/usr/bin/perl 2# 3# Copyright 2007 Red Hat Inc. 4# This crappy script written by Dave Airlie to avoid hassle of adding 5# ids in every place. 6# 7use strict; 8use warnings; 9use Text::CSV_XS; 10 11my $file = $ARGV[0]; 12 13my $atioutfile = 'ati_pciids_gen.h'; 14my $radeonpcichipsetfile = 'radeon_pci_chipset_gen.h'; 15my $radeonpcidevicematchfile = 'radeon_pci_device_match_gen.h'; 16my $radeonchipsetfile = 'radeon_chipset_gen.h'; 17my $radeonchipinfofile = 'radeon_chipinfo_gen.h'; 18 19my %uniquechipsets; 20my @uniquearray; 21my $numunique = 0; 22 23my $csv = Text::CSV_XS->new(); 24 25open (CSV, "<", $file) or die $!; 26 27open (ATIOUT, ">", $atioutfile) or die; 28open (PCICHIPSET, ">", $radeonpcichipsetfile) or die; 29open (PCIDEVICEMATCH, ">", $radeonpcidevicematchfile) or die; 30open (RADEONCHIPSET, ">", $radeonchipsetfile) or die; 31open (RADEONCHIPINFO, ">", $radeonchipinfofile) or die; 32 33print RADEONCHIPSET "/* This file is autogenerated please do not edit */\n"; 34print RADEONCHIPSET "SymTabRec RADEONChipsets[] = {\n"; 35print PCICHIPSET "/* This file is autogenerated please do not edit */\n"; 36print PCICHIPSET "static PciChipsets RADEONPciChipsets[] = {\n"; 37print PCIDEVICEMATCH "/* This file is autogenerated please do not edit */\n"; 38print PCIDEVICEMATCH "static const struct pci_id_match radeon_device_match[] = {\n"; 39print RADEONCHIPINFO "/* This file is autogenerated please do not edit */\n"; 40print RADEONCHIPINFO "static RADEONCardInfo RADEONCards[] = {\n"; 41while (<CSV>) { 42 if ($csv->parse($_)) { 43 my @columns = $csv->fields(); 44 45 if ((substr($columns[0], 0, 1) ne "#")) { 46 47 print ATIOUT "#define PCI_CHIP_$columns[1] $columns[0]\n"; 48 49 if (($columns[2] ne "R128") && ($columns[2] ne "MACH64") && ($columns[2] ne "MACH32")) { 50 print PCICHIPSET " { PCI_CHIP_$columns[1], PCI_CHIP_$columns[1], RES_SHARED_VGA },\n"; 51 52 print PCIDEVICEMATCH " ATI_DEVICE_MATCH( PCI_CHIP_$columns[1], 0 ),\n"; 53 54 print RADEONCHIPSET " { PCI_CHIP_$columns[1], \"$columns[8]\" },\n"; 55 if (!$uniquechipsets{$columns[8]}) { 56 $uniquearray[$numunique] = $columns[8]; 57 $uniquechipsets{$columns[8]} = $numunique++; 58 } 59 60 print RADEONCHIPINFO " { $columns[0], CHIP_FAMILY_$columns[2], "; 61 62 if ($columns[3] eq "1") { 63 print RADEONCHIPINFO "1, "; 64 } else { 65 print RADEONCHIPINFO "0, "; 66 } 67 68 if ($columns[4] eq "1") { 69 print RADEONCHIPINFO "1, "; 70 } else { 71 print RADEONCHIPINFO "0, "; 72 } 73 74 if ($columns[5] eq "1") { 75 print RADEONCHIPINFO "1, "; 76 } else { 77 print RADEONCHIPINFO "0, "; 78 } 79 80 if ($columns[6] eq "1") { 81 print RADEONCHIPINFO "1, "; 82 } else { 83 print RADEONCHIPINFO "0, "; 84 } 85 86 if ($columns[7] eq "1") { 87 print RADEONCHIPINFO "1 "; 88 } else { 89 print RADEONCHIPINFO "0 "; 90 } 91 92 print RADEONCHIPINFO "},\n"; 93 } 94 } 95 } else { 96 my $err = $csv->error_input; 97 print "Failed to parse line: $err"; 98 } 99} 100 101print RADEONCHIPINFO "};\n"; 102print RADEONCHIPSET " { -1, NULL }\n};\n\nSymTabRec RADEONUniqueChipsets[] = {\n"; 103foreach (@uniquearray) { 104 print RADEONCHIPSET " { 0, \"$_\" },\n"; 105} 106print RADEONCHIPSET " { -1, NULL }\n};\n"; 107print PCICHIPSET " { -1, -1, RES_UNDEFINED }\n};\n"; 108print PCIDEVICEMATCH " { 0, 0, 0 }\n};\n"; 109close CSV; 110close ATIOUT; 111close PCICHIPSET; 112close PCIDEVICEMATCH; 113close RADEONCHIPSET; 114close RADEONCHIPINFO; 115