summaryrefslogtreecommitdiffstats
path: root/MDV
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2007-02-26 16:56:43 +0000
committerThierry Vignaud <tv@mandriva.org>2007-02-26 16:56:43 +0000
commit82fe5aa011c8686b02064fcdd5e420e7250f2b20 (patch)
tree70b85dc9c566ae23ef497f48e46f1b4b09cd859b /MDV
parentc0ad9115a63e164f95d8c624589e78ba001ca62a (diff)
downloadldetect-82fe5aa011c8686b02064fcdd5e420e7250f2b20.tar
ldetect-82fe5aa011c8686b02064fcdd5e420e7250f2b20.tar.gz
ldetect-82fe5aa011c8686b02064fcdd5e420e7250f2b20.tar.bz2
ldetect-82fe5aa011c8686b02064fcdd5e420e7250f2b20.tar.xz
ldetect-82fe5aa011c8686b02064fcdd5e420e7250f2b20.zip
use libldetect for parsing pci.ids & getting PCI description (thus shrinking execution time by 13%)
Diffstat (limited to 'MDV')
-rwxr-xr-xMDV/Lspciusb.pm57
1 files changed, 14 insertions, 43 deletions
diff --git a/MDV/Lspciusb.pm b/MDV/Lspciusb.pm
index 4577bda..cc627a5 100755
--- a/MDV/Lspciusb.pm
+++ b/MDV/Lspciusb.pm
@@ -23,46 +23,9 @@ package MDV::Lspciusb;
use lib qw(/usr/lib/libDrakX);
use modalias;
use MDK::Common;
-
-sub read_pciids {
- my ($f) = @_;
- my %drivers;
- my ($id1, $id2, $vendor, $line);
- foreach (cat_($f)) {
- chomp; $line++;
- next if /^#/ || /^;/ || /^\s*$/;
- if (/^C\s/) {
- last;
- } elsif (my ($subid1, $subid2, $text) = /^\t\t(\S+)\s+(\S+)\s+(.+)/) {
- $text =~ s/\t/ /g;
- $id1 && $id2 or die "$f:$line: unexpected device\n";
- $drivers{sprintf qq(%04x%04x%04x%04x), hex($id1), hex($id2), hex($subid1), hex($subid2)} = "$vendor|$text";
- } elsif (/^\t(\S+)\s+(.+)/) {
- ($id2, $text) = ($1, $2);
- $text =~ s/\t/ /g;
- $id1 && $id2 or die "$f:$line: unexpected device\n";
- $drivers{sprintf qq(%04x%04xffffffff), hex($id1), hex($id2)} = "$vendor|$text";
- } elsif (/^(\S+)\s+(.+)/) {
- $id1 = $1;
- $vendor = $2;
- } else {
- warn "$f:$line: bad line: $_\n";
- }
- }
- \%drivers;
-}
-
-my $pciids = read_pciids("/usr/share/pci.ids");
+use detect_devices;
my %bus_get_description = (
- pci => sub {
- my ($_dev_path, $values) = @_;
- if (my @ids = $values =~ /^v([[:xdigit:]]{8})d([[:xdigit:]]{8})sv([[:xdigit:]]{8})sd([[:xdigit:]]{8})/) {
- my ($v, $d, $sv, $sd) = map { hex($_) } @ids;
- return $pciids->{sprintf(qq(%04x%04x%04x%04x), $v, $d, $sv, $sd)} ||
- $pciids->{sprintf(qq(%04x%04xffffffff), $v, $d)};
- }
- },
usb => sub {
my ($dev_path, $_values) = @_;
my $full_path = dirname($dev_path) . "/" . readlink($dev_path);
@@ -71,22 +34,30 @@ my %bus_get_description = (
},
);
-sub list() {
+sub list {
+ my (@bus) = @_;
+ @bus = qw(usb) if !@bus;
map {
- my $modalias_path = $_;
+ my ($modalias_path, $desc);
+ if (ref $_) {
+ my $device = $_;
+ $modalias_path = sprintf('/sys/bus/pci/devices/%04x:%02x:%02x.%x/modalias', $device->{pci_domain}, $device->{pci_bus}, $device->{pci_device}, $device->{pci_function});
+ $desc = $device->{description};
+ } else {
+ $modalias_path = $_;
+ }
my $modalias = chomp_(cat_($modalias_path));
my $dev_path = dirname($modalias_path);
my ($bus, $values) = $modalias =~ /^([^:]+):(\S+)$/; # modalias::get_bus
my @modules = modalias::get_modules($modalias);
my $module = first(@modules) || "unknown";
my $modules = @modules > 1 ? " (" . join(",", @modules) . ")" : "";
- my $desc;
- if (my $get_desc = $bus_get_description{$bus}) {
+ if (my $get_desc = $bus_get_description{$bus} and !$desc) {
$desc = $get_desc->($dev_path, $values);
}
$desc ||= "unknown";
{ module => $module, descr => $desc, modules => $modules };
- } map { glob("/sys/bus/$_/devices/*/modalias") } qw(pci usb);
+ } detect_devices::pci_probe(), map { glob("/sys/bus/$_/devices/*/modalias") } @bus;
}
1;