summaryrefslogtreecommitdiffstats
path: root/MDV
diff options
context:
space:
mode:
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;