Show
Ignore:
Timestamp:
01/19/11 10:56:53 (16 months ago)
Author:
khali
Message:

Implement universal detection for Intel digital thermal sensors. This
relies on a flag returned by the cpuid instruction, as the coretemp
driver itself does since kernel 2.6.35.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/detect/sensors-detect

    r5904 r5905  
    2424 
    2525use strict; 
    26 use Fcntl; 
     26use Fcntl qw(:DEFAULT :seek); 
    2727use File::Basename; 
    2828 
     
    20472047                detect => \&fam11h_pci_detect, 
    20482048        }, { 
    2049                 name => "Intel Core family thermal sensor", 
     2049                name => "Intel digital thermal sensor", 
    20502050                driver => "coretemp", 
    2051                 detect => sub { coretemp_detect(0); }, 
    2052         }, { 
    2053                 name => "Intel Atom thermal sensor", 
    2054                 driver => "coretemp", 
    2055                 detect => sub { coretemp_detect(1); }, 
     2051                detect => \&coretemp_detect, 
    20562052        }, { 
    20572053                name => "Intel AMB FB-DIMM thermal sensor", 
     
    23152311                if (m/^processor\s*:\s*(\d+)/) { 
    23162312                        push @cpu, $entry if scalar keys(%{$entry}); # Previous entry 
    2317                         $entry = {}; # New entry 
     2313                        $entry = { nr => $1 }; # New entry 
    23182314                        next; 
    23192315                } 
    2320                 if (m/^(vendor_id|cpu family|model|model name|stepping)\s*:\s*(.+)$/) { 
     2316                if (m/^(vendor_id|cpu family|model|model name|stepping|cpuid level)\s*:\s*(.+)$/) { 
    23212317                        my $k = $1; 
    23222318                        my $v = $2; 
     
    24852481        $normalized =~ tr/-/_/; 
    24862482        $modules_list{$normalized} = 1; 
     2483} 
     2484 
     2485# udev may take some time to create device nodes when loading modules 
     2486sub udev_settle 
     2487{ 
     2488        if (!(-x "/sbin/udevadm" && system("/sbin/udevadm settle") == 0) 
     2489         && !(-x "/sbin/udevsettle" && system("/sbin/udevsettle") == 0)) { 
     2490                sleep(1); 
     2491        } 
    24872492} 
    24882493 
     
    58345839} 
    58355840 
     5841sub cpuid 
     5842{ 
     5843        my ($cpu_nr, $eax) = @_; 
     5844 
     5845        sysopen(CPUID, "/dev/cpu/$cpu_nr/cpuid", O_RDONLY) or return; 
     5846        binmode CPUID; 
     5847        sysseek(CPUID, $eax, SEEK_SET) 
     5848                or die "Cannot seek /dev/cpu/$cpu_nr/cpuid"; 
     5849        sysread(CPUID, my $data, 16) 
     5850                or die "Cannot read /dev/cpu/$cpu_nr/cpuid"; 
     5851        close CPUID; 
     5852 
     5853        return unpack("L4", $data); 
     5854} 
     5855 
    58365856sub coretemp_detect 
    58375857{ 
    5838         my $chip = shift; 
    58395858        my $probecpu; 
    58405859 
    58415860        foreach $probecpu (@cpu) { 
    58425861                next unless $probecpu->{vendor_id} eq 'GenuineIntel' && 
    5843                             $probecpu->{'cpu family'} == 6; 
    5844                 return 9 if $chip == 0 && 
    5845                         ($probecpu->{model} == 14 ||    # Pentium M DC 
    5846                          $probecpu->{model} == 15 ||    # Core 2 DC 65nm 
    5847                          $probecpu->{model} == 0x16 ||  # Core 2 SC 65nm 
    5848                          $probecpu->{model} == 0x17 ||  # Penryn 45nm 
    5849                          $probecpu->{model} == 0x1a ||  # Nehalem 
    5850                          $probecpu->{model} == 0x1e);   # Lynnfield 
    5851                 return 9 if $chip == 1 && 
    5852                         ($probecpu->{model} == 0x1c);   # Atom 
     5862                            $probecpu->{'cpuid level'} >= 6; 
     5863 
     5864                # Now we check for the DTS flag 
     5865                my @regs = cpuid($probecpu->{nr}, 6); 
     5866                return unless @regs == 4; 
     5867                return 9 if ($regs[0] & (1 << 0));      # eax, bit 0 
    58535868        } 
    58545869        return; 
     
    62046219              "Do you want to scan for them? This is totally safe. (YES/no): "; 
    62056220        unless (<STDIN> =~ /^\s*n/i) { 
     6221                # Load the cpuid driver if needed 
     6222                unless (-e "/dev/cpu/$cpu[0]->{nr}/cpuid") { 
     6223                        load_module("cpuid"); 
     6224                        udev_settle(); 
     6225                } 
     6226 
    62066227                $| = 1; 
    62076228                foreach my $entry (@cpu_ids) { 
     
    62796300                                             'supermicro'); 
    62806301 
    6281                 # udev may take some time to create the device node 
    6282                 if (!(-x "/sbin/udevadm" && system("/sbin/udevadm settle") == 0) 
    6283                  && !(-x "/sbin/udevsettle" && system("/sbin/udevsettle") == 0)) { 
    6284                         sleep(1); 
    6285                 } 
    6286  
     6302                udev_settle(); 
    62876303                for (my $dev_nr = 0; $dev_nr < @i2c_adapters; $dev_nr++) { 
    62886304                        next unless exists $i2c_adapters[$dev_nr];