Changeset 5441

Show
Ignore:
Timestamp:
11/27/08 18:44:12 (4 years ago)
Author:
khali
Message:

Fix bus number prediction logic (#2327). We don't need anything complex,
given how rare are the cases where this really matters. On most systems
we will only load one I2C bus driver, so the bus numbers simply can't
change.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5434 r5441  
    2929                  Fix handling of bus driver names with an underscore 
    3030                  Simplify loading of bus drivers 
     31                  Fix bus number prediction logic (#2327) 
    3132 
    32333.0.3 (2008-09-28) 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect

    r5440 r5441  
    51365136} 
    51375137 
    5138 # We build here an array adapters, indexed on the number the adapter has 
    5139 # at this moment (we assume only loaded adapters are interesting at all; 
    5140 # everything that got scanned also got loaded). Each entry is a reference 
    5141 # to a hash containing: 
    5142 #  driver: Name of the adapter driver 
    5143 #  nr_now: Number of the bus now 
    5144 #  nr_later: Number of the bus when the modprobes are done (not included if the 
    5145 #        driver should not be loaded) 
    5146 # A second array, called 
    51475138sub generate_modprobes 
    51485139{ 
    5149   my ($chip, $detection, $nr, $i, @optionlist, $driver, $isa, $adap); 
     5140  my ($chip, $detection, @optionlist, $isa, $adap); 
    51505141  my $ipmi = 0; 
    5151   my $modprobes = ""; 
     5142  my $modprobes; 
    51525143  my $configfile; 
    51535144 
    5154   # Collect all adapters used 
    5155   $nr = 0; 
     5145  # Handle aliases 
     5146  # As of kernel 2.6.28, alias detection is handled by kernel drivers 
     5147  # directly, so module options are no longer needed. 
     5148  unless (kernel_version_at_least(2, 6, 28)) { 
     5149    foreach $chip (@chips_detected) { 
     5150      @optionlist = (); 
     5151      foreach $detection (@{$chip->{detected}}) { 
     5152        if (exists $detection->{i2c_driver} and 
     5153            exists $detection->{isa_addr}) { 
     5154          push @optionlist, $detection->{i2c_devnr}, 
     5155                            $detection->{i2c_addr}; 
     5156        } 
     5157      } 
     5158 
     5159      next if not @optionlist; 
     5160      $configfile = "# hwmon module options\n" unless defined $configfile; 
     5161      $configfile .= "options $chip->{driver}"; 
     5162      $configfile .= sprintf(" ignore=%d,0x%02x", shift @optionlist, 
     5163                                                  shift @optionlist); 
     5164      $configfile .= sprintf(",%d,0x%02x", shift @optionlist, 
     5165                             shift @optionlist) while @optionlist; 
     5166      $configfile .= "\n"; 
     5167    } 
     5168  } 
     5169 
    51565170  $isa = 0; 
    51575171  foreach $chip (@chips_detected) { 
    51585172    foreach $detection (@{$chip->{detected}}) { 
    5159       # If there is more than one bus detected by a driver, they are 
    5160       # still all added. So we number them in the correct order 
    5161       if (exists $detection->{i2c_driver} and 
    5162           not exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later} and 
    5163           not exists $detection->{isa_addr}) { # Always use ISA access if possible 
    5164          foreach $adap (@i2c_adapters) { 
    5165            next unless exists $adap->{driver}; 
    5166            $adap->{nr_later} = $nr++ if $adap->{driver} eq $detection->{i2c_driver}; 
    5167          } 
     5173      # Tag adapters which host hardware monitoring chips we want to access 
     5174      if (exists $detection->{i2c_devnr} 
     5175       && !exists $detection->{isa_addr}) { 
     5176           $i2c_adapters[$detection->{i2c_devnr}]->{used}++; 
    51685177      } 
     5178 
    51695179      if (exists $detection->{isa_addr}) { 
    51705180           $isa = 1; 
     
    51765186  } 
    51775187 
    5178   $modprobes .= "# I2C adapter drivers\n" if $nr; 
    5179   for ($i = 0; $i < $nr; $i++) { 
    5180     foreach $adap (@i2c_adapters) { 
    5181       next unless exists $adap->{nr_later} and $adap->{nr_later} == $i; 
    5182       if ($adap->{driver} eq "UNKNOWN") { 
    5183         $modprobes .= "# modprobe unknown adapter ".$adap->{name}."\n"; 
    5184       } else { 
    5185         $modprobes .= "modprobe $adap->{driver}\n" 
    5186           unless $modprobes =~ /modprobe $adap->{driver}\n/; 
    5187       } 
    5188       last; 
    5189     } 
    5190   } 
     5188  # If we added any module option to handle aliases, we need to load all 
     5189  # the adapter drivers so that the numbers will be the same. If not, then 
     5190  # we only load the adapter drivers which are useful. 
     5191  foreach $adap (@i2c_adapters) { 
     5192    next unless contains($adap->{driver}, @modules_we_loaded); 
     5193    next if not defined $configfile and not $adap->{used}; 
     5194    $modprobes .= "# I2C adapter drivers\n" unless defined $modprobes; 
     5195    $modprobes .= "modprobe $adap->{driver}\n" 
     5196      unless $modprobes =~ /modprobe $adap->{driver}\n/; 
     5197  } 
     5198 
    51915199  # i2c-isa is loaded automatically (as a dependency) since 2.6.14, 
    51925200  # and will soon be gone. 
     
    52235231       $modprobes .= "modprobe $chip->{driver}\n"; 
    52245232    } 
    5225  
    5226     # Handle aliases 
    5227     # As of kernel 2.6.28, alias detection is handled by kernel drivers 
    5228     # directly, so module options are no longer needed. 
    5229     unless (kernel_version_at_least(2, 6, 28)) { 
    5230       foreach $detection (@{$chip->{detected}}) { 
    5231         if (exists $detection->{i2c_driver} and 
    5232             exists $detection->{isa_addr} and 
    5233             exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}) { 
    5234           push @optionlist, $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}, 
    5235                             $detection->{i2c_addr}; 
    5236         } 
    5237       } 
    5238     } 
    5239  
    5240     next if not @optionlist; 
    5241     $configfile = "# hwmon module options\n" unless defined $configfile; 
    5242     $configfile .= "options $chip->{driver}"; 
    5243     $configfile .= sprintf(" ignore=%d,0x%02x", shift @optionlist, 
    5244                                                shift @optionlist) 
    5245                   if @optionlist; 
    5246     $configfile .= sprintf(",%d,0x%02x", shift @optionlist, shift @optionlist) 
    5247                   while @optionlist; 
    5248     $configfile .= "\n"; 
    52495233  } 
    52505234