Changeset 4142

Show
Ignore:
Timestamp:
09/05/06 12:01:15 (8 years ago)
Author:
khali
Message:

sensors-detect: Use sysfs for PCI device enumeration where available
(Linux 2.6). Still fallback to /proc (Linux 2.4). sysfs provides the PCI
device domain and class, which were hard to get from /proc.

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r4140 r4142  
    8282                          Add VT8237A and VT8251 
    8383                          Remove detection of nVidia graphics adapters 
     84                          Use sysfs for PCI device enumeration 
    8485 
    8586 
  • lm-sensors/trunk/prog/detect/sensors-detect

    r4141 r4142  
    20862086use vars qw(%pci_list); 
    20872087 
    2088 # This function returns a hash of hashes. Each hash has some PCI information: 
     2088# This function returns a list of hashes. Each hash has some PCI information: 
     2089# 'domain', 'bus', 'slot' and 'func' uniquely identify a PCI device in a 
     2090# computer; 'vendid' and 'devid' uniquely identify a type of device. 
     2091# 'class' lets us spot unknown SMBus adapters. 
     2092# This function is used when sysfs is available (Linux 2.6). 
     2093sub read_sys_dev_pci($) 
     2094{ 
     2095  my $devices = shift; 
     2096  my ($dev, @pci_list); 
     2097 
     2098  opendir(local *DEVICES, "$devices") 
     2099    or die "$devices: $!"; 
     2100 
     2101  while (defined($dev = readdir(DEVICES))) { 
     2102    my %record; 
     2103    next unless $dev =~ 
     2104      m/^(?:([\da-f]+):)?([\da-f]+):([\da-f]+)\.([\da-f]+)$/; 
     2105 
     2106    $record{domain} = hex $1; 
     2107    $record{bus} = hex $2; 
     2108    $record{slot} = hex $3; 
     2109    $record{func} = hex $4; 
     2110 
     2111    $record{vendid} = oct sysfs_device_attribute("$devices/$dev", "vendor"); 
     2112    $record{devid} = oct sysfs_device_attribute("$devices/$dev", "device"); 
     2113    $record{class} = (oct sysfs_device_attribute("$devices/$dev", "class")) 
     2114                     >> 8; 
     2115 
     2116    push @pci_list, \%record; 
     2117  } 
     2118 
     2119  return \@pci_list; 
     2120} 
     2121 
     2122# This function returns a list of hashes. Each hash has some PCI information: 
    20892123# 'bus', 'slot' and 'func' uniquely identify a PCI device in a computer; 
    20902124# 'vendid' and 'devid' uniquely identify a type of device. 
     2125# This function is used when sysfs is not available (Linux 2.4). 
    20912126sub read_proc_dev_pci 
    20922127{ 
    2093   my ($dfn,$vend,%pci_list); 
    2094   open(local *INPUTFILE, "/proc/bus/pci/devices") or return; 
     2128  my ($dfn, $vend, @pci_list); 
     2129  open(local *INPUTFILE, "/proc/bus/pci/devices") 
     2130    or die "/proc/bus/pci/devices: $!"; 
    20952131  local $_; 
    20962132  while (<INPUTFILE>) { 
     
    21032139    $record{devid} = $vend & 0xffff; 
    21042140     
    2105     $pci_list{ sprintf("%04x:%04x",$record{vendid},$record{devid}) } = 
    2106         \%record; 
    2107   } 
    2108   return %pci_list; 
     2141    push @pci_list, \%record; 
     2142  } 
     2143  return \@pci_list; 
    21092144} 
    21102145 
    21112146sub initialize_proc_pci 
    21122147{ 
    2113   %pci_list = read_proc_dev_pci; 
    2114   die "Can't access /proc/bus/pci/devices!" if not defined %pci_list; 
     2148  my $pci_list; 
     2149 
     2150  if (defined $sysfs_root) { 
     2151    $pci_list = read_sys_dev_pci("$sysfs_root/bus/pci/devices"); 
     2152  } else { 
     2153    $pci_list = read_proc_dev_pci(); 
     2154  } 
     2155 
     2156  # Note that we lose duplicate devices at this point, but we don't 
     2157  # really care. What matters to us is which unique devices are present, 
     2158  # not how many of each. 
     2159  %pci_list = map { 
     2160    sprintf("%04x:%04x", $_->{vendid}, $_->{devid}) => $_ 
     2161  } @{$pci_list}; 
    21152162} 
    21162163 
     
    21752222    if (exists $pci_list{$key}) { 
    21762223        $device = $pci_list{$key}; 
    2177         printf "Use driver `%s' for device %02x:%02x.%x: %s\n", 
     2224        printf "Use driver `\%s' for device \%s: \%s\n", 
    21782225               $try->{driver}, 
    2179                $device->{bus},$device->{slot},$device->{func},$try->{procid}; 
     2226               (defined $device->{domain} ? 
     2227                sprintf("\%04x:\%02x:\%02x.\%x", $device->{domain}, 
     2228                        $device->{bus}, $device->{slot}, $device->{func}) : 
     2229                sprintf("\%02x:\%02x.\%x", 
     2230                        $device->{bus}, $device->{slot}, $device->{func})), 
     2231               $try->{procid}; 
    21802232        if ($try->{driver} eq "to-be-tested") { 
    21812233          print "\nWe are currently looking for testers for this adapter!\n".