1 |
dmorgan |
1357 |
package MDV::Lspciusb; |
2 |
|
|
#***************************************************************************** |
3 |
|
|
# |
4 |
|
|
# Copyright (c) 2006-2007 Mandriva SA |
5 |
|
|
# |
6 |
|
|
# This program is free software; you can redistribute it and/or modify |
7 |
|
|
# it under the terms of the GNU General Public License version 2, as |
8 |
|
|
# published by the Free Software Foundation. |
9 |
|
|
# |
10 |
|
|
# This program is distributed in the hope that it will be useful, |
11 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
# GNU General Public License for more details. |
14 |
|
|
# |
15 |
|
|
# You should have received a copy of the GNU General Public License |
16 |
|
|
# along with this program; if not, write to the Free Software |
17 |
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
|
|
# |
19 |
|
|
#***************************************************************************** |
20 |
|
|
# |
21 |
|
|
# $Id: Lspciusb.pm 44676 2007-02-26 16:56:43Z tv $ |
22 |
|
|
|
23 |
|
|
use lib qw(/usr/lib/libDrakX); |
24 |
|
|
use modalias; |
25 |
|
|
use MDK::Common; |
26 |
|
|
use detect_devices; |
27 |
|
|
|
28 |
|
|
my %bus_get_description = ( |
29 |
|
|
usb => sub { |
30 |
|
|
my ($dev_path, $_values) = @_; |
31 |
|
|
my $full_path = dirname($dev_path) . "/" . readlink($dev_path); |
32 |
|
|
my $parent_path = dirname($full_path); |
33 |
|
|
chomp_(cat_("$parent_path/product")); |
34 |
|
|
}, |
35 |
|
|
); |
36 |
|
|
|
37 |
|
|
sub list { |
38 |
|
|
my (@bus) = @_; |
39 |
|
|
@bus = qw(usb) if !@bus; |
40 |
|
|
map { |
41 |
|
|
my ($modalias_path, $desc); |
42 |
|
|
if (ref $_) { |
43 |
|
|
my $device = $_; |
44 |
|
|
$modalias_path = sprintf('/sys/bus/pci/devices/%04x:%02x:%02x.%x/modalias', $device->{pci_domain}, $device->{pci_bus}, $device->{pci_device}, $device->{pci_function}); |
45 |
|
|
$desc = $device->{description}; |
46 |
|
|
} else { |
47 |
|
|
$modalias_path = $_; |
48 |
|
|
} |
49 |
|
|
my $modalias = chomp_(cat_($modalias_path)); |
50 |
|
|
my $dev_path = dirname($modalias_path); |
51 |
|
|
my ($bus, $values) = $modalias =~ /^([^:]+):(\S+)$/; # modalias::get_bus |
52 |
|
|
my @modules = modalias::get_modules($modalias); |
53 |
|
|
my $module = first(@modules) || "unknown"; |
54 |
|
|
my $modules = @modules > 1 ? " (" . join(",", @modules) . ")" : ""; |
55 |
|
|
if (my $get_desc = $bus_get_description{$bus} and !$desc) { |
56 |
|
|
$desc = $get_desc->($dev_path, $values); |
57 |
|
|
} |
58 |
|
|
$desc ||= "unknown"; |
59 |
|
|
{ module => $module, descr => $desc, modules => $modules }; |
60 |
|
|
} detect_devices::pci_probe(), map { glob("/sys/bus/$_/devices/*/modalias") } @bus; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
1; |