/[soft]/ldetect-lst/trunk/convert/uniquify-modalias.pl
ViewVC logotype

Contents of /ldetect-lst/trunk/convert/uniquify-modalias.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1357 - (show annotations) (download)
Tue May 17 09:21:22 2011 UTC (12 years, 11 months ago) by dmorgan
File MIME type: text/plain
File size: 5350 byte(s)
Import  ldetect
1 #!/usr/bin/perl
2
3 use lib qw(/usr/lib/libDrakX);
4 use File::FnMatch;
5 use MDK::Common;
6 use list_modules;
7 use modalias;
8
9 #- known bugs:
10 #- o does not match subvendors, they have to be handled on a case-by-case basis
11 #- o does not match PCI class (thus ahci won't match jmicron devices)
12
13 my @ignored_modules = (
14 "intelfb", "savagefb", "tdfxfb", qr/_agp$/,
15 qr/_rng$/,
16 );
17 my @preferred_modules = (
18 "pata_marvell", #- prefer over ahci since ahci need marvel_enabled=1 to make it work (#43975)
19 "bcm43xx", #- prefer over b43, b43legacy and ssb
20 "dpt_i2o", #- prefer over i2o_core
21 "dmfe", #- prefer over tulip, it only lists supported devices
22 "c4", #- subvendors listed in c4 driver seems not to be supported by DAC960
23 "i2c_viapro", #- prefer over via686a
24 "ipr", #- subvendors listed in ipr driver seems not to be supported by DAC960
25 "mxser_new", #- experimental clone of mxser
26 "p54pci", #- prefer over prism54
27 "p54usb", #- prefer over prism54
28 "ipw3945", #- prefer over iwl3945, which has some stability/performance issues
29 "rt2400", "rt2500", "rt2570", "rt61", "rt73", #- prefer legacy Ralink drivers
30 "skge", #- prefer over sk98lin
31 qr/^snd_/, #- prefer alsa drivers
32 "sx", #- prefer over specialix (sx matches subvendors)
33 );
34 my @depreciated_modules = (
35 #- defer *piix over ahci (install will still try both ahci and ata_piix), depends on BIOS settings
36 #- do it without explicitely listing ahci in preferred modules,
37 #- to allow ahci to be overriden by pata_marvell
38 #- ata_piix will still be preferred over piix, because ata_piix is in the disk/sata preferred category
39 "ata_piix", "piix",
40 "gspca", #- kernel hackers value it as poorly coded
41 "ir_usb", #- false positive because of pattern
42 "usb_storage", #- false positive because we don't use subvendors/subdevices
43 "snd_usb_audio", #- prefer video camera drivers if any
44 );
45 my @preferred_categories = (
46 "disk/sata",
47 "disk/scsi",
48 );
49 #- For the following categories, the deferred modules are ignored, and
50 #- an explicit alias is set even if only one module match exactly.
51 #- This allows to workaround modules having class wildcards, which isn't supported.
52 my %category_deferred_modules = (
53 #- prefer full implementation or "generic" libata module, not old IDE generic module
54 "disk/ide" => [ "ide_pci_generic" ],
55 "disk/sata" => [ "ata_generic", "pata_acpi" ],
56 "input/tablet" => [ "usbmouse" ],
57 );
58
59 sub build_modalias {
60 my ($class, $vendor, $device) = @_;
61 {
62 pci => "pci:v0000${vendor}d0000${device}sv*sd*bc*i*",
63 usb => "usb:v${vendor}p${device}d*dc*dsc*dp*ic*isc*ip*",
64 }->{$class};
65 }
66
67 sub match_module {
68 my ($module, $pattern) = @_;
69 ref $pattern eq 'Regexp' ? $module =~ $pattern : $module eq $pattern;
70 }
71
72 sub grep_non_matching {
73 my ($modules, $list) = @_;
74 grep {
75 my $m = $_->[1];
76 every { !match_module($m, $_) } @$list;
77 } @$modules;
78 }
79
80 sub grep_matching {
81 my ($modules, $list) = @_;
82 grep {
83 my $m = $_->[1];
84 grep { match_module($m, $_) } @$list;
85 } @$modules;
86 }
87
88 sub print_module {
89 my ($modalias, $aliases, $class_other) = @_;
90 my @aliases = group_by2(@$aliases);
91 my @other = grep { File::FnMatch::fnmatch($_->[0], $modalias) } @$class_other;
92 my @modules = uniq_ { $_->[1] } @aliases, @other;
93
94 @modules or return;
95
96 my @category_deferred_modules;
97 foreach (map { list_modules::module2category($_->[1]) } @modules) {
98 push @category_deferred_modules, @{$category_deferred_modules{$_} || []}
99 }
100
101 @modules > 1 || @category_deferred_modules or return;
102
103 my @non_ignored = grep_non_matching(\@modules, [ @ignored_modules ]);
104 if (@non_ignored == 1) {
105 print "alias $modalias $non_ignored[0][1]\n";
106 return;
107 } elsif (@non_ignored == 0) {
108 print "alias $modalias off\n";
109 return;
110 }
111
112 @modules = @non_ignored;
113 my @non_depreciated = grep_non_matching(\@modules, \@depreciated_modules);
114 if (@non_depreciated == 1) {
115 print "alias $modalias $non_depreciated[0][1]\n";
116 return;
117 }
118
119 @modules = @non_depreciated if @non_depreciated > 1;
120 my @preferred = grep_matching(\@modules, \@preferred_modules);
121 @preferred or @preferred = grep { member(module2category($_->[1]), @preferred_categories) } @modules;
122 if (@preferred == 1) {
123 print "alias $modalias $preferred[0][1]\n";
124 return;
125 } else {
126 my @non_deferred = grep_non_matching(\@modules, [ @category_deferred_modules ]);
127 if (@non_deferred == 1) {
128 print "alias $modalias $non_deferred[0][1]\n";
129 return;
130 }
131 }
132
133 print STDERR "unable to choose for $modalias " . join(" ", map { $_->[1] } @modules) . "\n";
134 }
135
136 my $alias_group = {};
137 modalias::parse_path($alias_group, "../lst/fallback-modules.alias");
138
139 foreach my $class (qw(pci pcmcia usb)) {
140 my @class_other = group_by2(@{$alias_group->{$class}{other}});
141 foreach my $vendor (sort(keys(%{$alias_group->{$class}}))) {
142 $vendor eq "other" and next;
143 foreach my $device (sort(keys(%{$alias_group->{$class}{$vendor}}))) {
144 my $modalias = build_modalias($class, $vendor, $device);
145 print_module($modalias, $alias_group->{$class}{$vendor}{$device}, \@class_other);
146 }
147 }
148 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.30