| 5160 | | sub main |
| 5161 | | { |
| 5162 | | my ($input, $superio_features); |
| 5163 | | |
| 5164 | | # Handle special command line cases first |
| 5165 | | if (defined $ARGV[0] && $ARGV[0] eq "--stat") { |
| 5166 | | show_i2c_stats(); |
| 5167 | | exit 0; |
| 5168 | | } |
| 5169 | | |
| 5170 | | # We won't go very far if not root |
| 5171 | | unless ($> == 0) { |
| 5172 | | print "You need to be root to run this script.\n"; |
| 5173 | | exit -1; |
| 5174 | | } |
| 5175 | | |
| 5176 | | if (-x "/sbin/service" && -f "/etc/init.d/lm_sensors" && |
| 5177 | | -f "/var/lock/subsys/lm_sensors") { |
| 5178 | | system("/sbin/service", "lm_sensors", "stop"); |
| 5179 | | } |
| 5180 | | |
| 5181 | | initialize_kernel_version(); |
| 5182 | | initialize_conf(); |
| 5183 | | initialize_pci(); |
| 5184 | | initialize_modules_list(); |
| 5185 | | # Make sure any special case chips are added to the chip_ids list |
| 5186 | | # before making the support modules list |
| 5187 | | chip_special_cases(); |
| 5188 | | initialize_modules_supported(); |
| 5189 | | initialize_cpu_list(); |
| 5190 | | |
| 5191 | | print "# sensors-detect revision $revision\n"; |
| 5192 | | initialize_dmi_data(); |
| 5193 | | print_dmi_summary(); |
| 5194 | | print "\n"; |
| 5195 | | print "This program will help you determine which kernel modules you need\n", |
| 5196 | | "to load to use lm_sensors most effectively. It is generally safe\n", |
| 5197 | | "and recommended to accept the default answers to all questions,\n", |
| 5198 | | "unless you know what you're doing.\n\n"; |
| 5199 | | |
| 5200 | | print "Some south bridges, CPUs or memory controllers contain embedded sensors.\n". |
| 5201 | | "Do you want to scan for them? This is totally safe. (YES/no): "; |
| 5202 | | unless (<STDIN> =~ /^\s*n/i) { |
| 5203 | | $| = 1; |
| 5204 | | foreach my $entry (@cpu_ids) { |
| 5205 | | scan_cpu($entry); |
| 5206 | | } |
| 5207 | | $| = 0; |
| 5208 | | } |
| 5209 | | print "\n"; |
| 5210 | | |
| 5211 | | $superio_features = 0; |
| 5212 | | # Skip "random" I/O port probing on PPC |
| 5213 | | if ($kernel_arch ne 'ppc' |
| 5214 | | && $kernel_arch ne 'ppc64') { |
| 5215 | | print "Some Super I/O chips contain embedded sensors. We have to write to\n". |
| 5216 | | "standard I/O ports to probe them. This is usually safe.\n"; |
| 5217 | | print "Do you want to scan for Super I/O sensors? (YES/no): "; |
| 5218 | | unless (<STDIN> =~ /^\s*n/i) { |
| 5219 | | initialize_ioports(); |
| 5220 | | $superio_features |= scan_superio(0x2e, 0x2f); |
| 5221 | | $superio_features |= scan_superio(0x4e, 0x4f); |
| 5222 | | close_ioports(); |
| 5223 | | } |
| 5224 | | print "\n"; |
| 5225 | | |
| 5226 | | unless (is_laptop()) { |
| 5227 | | print "Some systems (mainly servers) implement IPMI, a set of common interfaces\n". |
| 5228 | | "through which system health data may be retrieved, amongst other things.\n". |
| 5229 | | "We have to read from arbitrary I/O ports to probe for such interfaces.\n". |
| 5230 | | "This is normally safe. Do you want to scan for IPMI interfaces?\n". |
| 5231 | | "(YES/no): "; |
| 5232 | | unless (<STDIN> =~ /^\s*n/i) { |
| 5233 | | initialize_ioports(); |
| 5234 | | scan_isa_bus(\@ipmi_ifs); |
| 5235 | | close_ioports(); |
| 5236 | | } |
| 5237 | | print "\n"; |
| 5238 | | } |
| 5239 | | |
| 5240 | | printf "Some hardware monitoring chips are accessible through the ISA I/O ports.\n". |
| 5241 | | "We have to write to arbitrary I/O ports to probe them. This is usually\n". |
| 5242 | | "safe though. Yes, you do have ISA I/O ports even if you do not have any\n". |
| 5243 | | "ISA slots! Do you want to scan the ISA I/O ports? (\%s): ", |
| 5244 | | $superio_features ? "yes/NO" : "YES/no"; |
| 5245 | | $input = <STDIN>; |
| 5246 | | unless ($input =~ /^\s*n/i |
| 5247 | | || ($superio_features && $input !~ /^\s*y/i)) { |
| 5248 | | initialize_ioports(); |
| 5249 | | scan_isa_bus(\@chip_ids); |
| 5250 | | close_ioports(); |
| 5251 | | } |
| 5252 | | print "\n"; |
| 5253 | | } |
| 5254 | | |
| 5255 | | print "Lastly, we can probe the I2C/SMBus adapters for connected hardware\n". |
| 5256 | | "monitoring devices. This is the most risky part, and while it works\n". |
| 5257 | | "reasonably well on most systems, it has been reported to cause trouble\n". |
| 5258 | | "on some systems.\n". |
| 5259 | | "Do you want to probe the I2C/SMBus adapters now? (YES/no): "; |
| 5260 | | |
| 5261 | | unless (<STDIN> =~ /^\s*n/i) { |
| 5262 | | adapter_pci_detection(); |
| 5263 | | load_module("i2c-dev") unless -e "$sysfs_root/class/i2c-dev"; |
| 5264 | | initialize_i2c_adapters_list(); |
| 5265 | | $i2c_addresses_to_scan = i2c_addresses_to_scan(); |
| 5266 | | print "\n"; |
| 5267 | | |
| 5268 | | # Skip SMBus probing by default if Super-I/O has all the features |
| 5269 | | my $by_default = ~$superio_features & (FEAT_IN | FEAT_FAN | FEAT_TEMP); |
| 5270 | | # Except on Asus and Tyan boards which often have more than |
| 5271 | | # one hardware monitoring chip |
| 5272 | | $by_default = 1 if dmi_match('board_vendor', 'asustek', 'tyan', |
| 5273 | | 'supermicro'); |
| 5274 | | |
| 5275 | | for (my $dev_nr = 0; $dev_nr < @i2c_adapters; $dev_nr++) { |
| 5276 | | next unless exists $i2c_adapters[$dev_nr]; |
| 5277 | | scan_i2c_adapter($dev_nr, $by_default); |
| 5278 | | } |
| 5279 | | } |
| 5280 | | |
| 5281 | | if (!keys %chips_detected) { |
| 5282 | | print "Sorry, no sensors were detected.\n"; |
| 5283 | | if (is_laptop() && -d "$sysfs_root/firmware/acpi") { |
| 5284 | | print "This is relatively common on laptops, where thermal management is\n". |
| 5285 | | "handled by ACPI rather than the OS.\n"; |
| 5286 | | } else { |
| 5287 | | print "Either your system has no sensors, or they are not supported, or\n". |
| 5288 | | "they are connected to an I2C or SMBus adapter that is not\n". |
| 5289 | | "supported. If you find out what chips are on your board, check\n". |
| 5290 | | "http://www.lm-sensors.org/wiki/Devices for driver status.\n"; |
| 5291 | | } |
| 5292 | | exit; |
| 5293 | | } |
| 5294 | | |
| 5295 | | print "Now follows a summary of the probes I have just done.\n". |
| 5296 | | "Just press ENTER to continue: "; |
| 5297 | | <STDIN>; |
| 5298 | | |
| 5299 | | foreach my $driver (keys %chips_detected) { |
| 5300 | | next unless @{$chips_detected{$driver}}; |
| 5301 | | find_aliases($chips_detected{$driver}); |
| 5302 | | print "\nDriver `$driver':\n"; |
| 5303 | | print_chips_report($chips_detected{$driver}); |
| 5304 | | } |
| 5305 | | print "\n"; |
| 5306 | | |
| 5307 | | my ($modprobes, $configfile, $bus_modules, $hwmon_modules) = generate_modprobes(); |
| | 5160 | sub write_config |
| | 5161 | { |
| | 5162 | my ($modprobes, $configfile, $bus_modules, $hwmon_modules) = @_; |
| | 5261 | } |
| | 5262 | |
| | 5263 | sub main |
| | 5264 | { |
| | 5265 | my ($input, $superio_features); |
| | 5266 | |
| | 5267 | # Handle special command line cases first |
| | 5268 | if (defined $ARGV[0] && $ARGV[0] eq "--stat") { |
| | 5269 | show_i2c_stats(); |
| | 5270 | exit 0; |
| | 5271 | } |
| | 5272 | |
| | 5273 | # We won't go very far if not root |
| | 5274 | unless ($> == 0) { |
| | 5275 | print "You need to be root to run this script.\n"; |
| | 5276 | exit -1; |
| | 5277 | } |
| | 5278 | |
| | 5279 | if (-x "/sbin/service" && -f "/etc/init.d/lm_sensors" && |
| | 5280 | -f "/var/lock/subsys/lm_sensors") { |
| | 5281 | system("/sbin/service", "lm_sensors", "stop"); |
| | 5282 | } |
| | 5283 | |
| | 5284 | initialize_kernel_version(); |
| | 5285 | initialize_conf(); |
| | 5286 | initialize_pci(); |
| | 5287 | initialize_modules_list(); |
| | 5288 | # Make sure any special case chips are added to the chip_ids list |
| | 5289 | # before making the support modules list |
| | 5290 | chip_special_cases(); |
| | 5291 | initialize_modules_supported(); |
| | 5292 | initialize_cpu_list(); |
| | 5293 | |
| | 5294 | print "# sensors-detect revision $revision\n"; |
| | 5295 | initialize_dmi_data(); |
| | 5296 | print_dmi_summary(); |
| | 5297 | print "\n"; |
| | 5298 | print "This program will help you determine which kernel modules you need\n", |
| | 5299 | "to load to use lm_sensors most effectively. It is generally safe\n", |
| | 5300 | "and recommended to accept the default answers to all questions,\n", |
| | 5301 | "unless you know what you're doing.\n\n"; |
| | 5302 | |
| | 5303 | print "Some south bridges, CPUs or memory controllers contain embedded sensors.\n". |
| | 5304 | "Do you want to scan for them? This is totally safe. (YES/no): "; |
| | 5305 | unless (<STDIN> =~ /^\s*n/i) { |
| | 5306 | $| = 1; |
| | 5307 | foreach my $entry (@cpu_ids) { |
| | 5308 | scan_cpu($entry); |
| | 5309 | } |
| | 5310 | $| = 0; |
| | 5311 | } |
| | 5312 | print "\n"; |
| | 5313 | |
| | 5314 | $superio_features = 0; |
| | 5315 | # Skip "random" I/O port probing on PPC |
| | 5316 | if ($kernel_arch ne 'ppc' |
| | 5317 | && $kernel_arch ne 'ppc64') { |
| | 5318 | print "Some Super I/O chips contain embedded sensors. We have to write to\n". |
| | 5319 | "standard I/O ports to probe them. This is usually safe.\n"; |
| | 5320 | print "Do you want to scan for Super I/O sensors? (YES/no): "; |
| | 5321 | unless (<STDIN> =~ /^\s*n/i) { |
| | 5322 | initialize_ioports(); |
| | 5323 | $superio_features |= scan_superio(0x2e, 0x2f); |
| | 5324 | $superio_features |= scan_superio(0x4e, 0x4f); |
| | 5325 | close_ioports(); |
| | 5326 | } |
| | 5327 | print "\n"; |
| | 5328 | |
| | 5329 | unless (is_laptop()) { |
| | 5330 | print "Some systems (mainly servers) implement IPMI, a set of common interfaces\n". |
| | 5331 | "through which system health data may be retrieved, amongst other things.\n". |
| | 5332 | "We have to read from arbitrary I/O ports to probe for such interfaces.\n". |
| | 5333 | "This is normally safe. Do you want to scan for IPMI interfaces?\n". |
| | 5334 | "(YES/no): "; |
| | 5335 | unless (<STDIN> =~ /^\s*n/i) { |
| | 5336 | initialize_ioports(); |
| | 5337 | scan_isa_bus(\@ipmi_ifs); |
| | 5338 | close_ioports(); |
| | 5339 | } |
| | 5340 | print "\n"; |
| | 5341 | } |
| | 5342 | |
| | 5343 | printf "Some hardware monitoring chips are accessible through the ISA I/O ports.\n". |
| | 5344 | "We have to write to arbitrary I/O ports to probe them. This is usually\n". |
| | 5345 | "safe though. Yes, you do have ISA I/O ports even if you do not have any\n". |
| | 5346 | "ISA slots! Do you want to scan the ISA I/O ports? (\%s): ", |
| | 5347 | $superio_features ? "yes/NO" : "YES/no"; |
| | 5348 | $input = <STDIN>; |
| | 5349 | unless ($input =~ /^\s*n/i |
| | 5350 | || ($superio_features && $input !~ /^\s*y/i)) { |
| | 5351 | initialize_ioports(); |
| | 5352 | scan_isa_bus(\@chip_ids); |
| | 5353 | close_ioports(); |
| | 5354 | } |
| | 5355 | print "\n"; |
| | 5356 | } |
| | 5357 | |
| | 5358 | print "Lastly, we can probe the I2C/SMBus adapters for connected hardware\n". |
| | 5359 | "monitoring devices. This is the most risky part, and while it works\n". |
| | 5360 | "reasonably well on most systems, it has been reported to cause trouble\n". |
| | 5361 | "on some systems.\n". |
| | 5362 | "Do you want to probe the I2C/SMBus adapters now? (YES/no): "; |
| | 5363 | |
| | 5364 | unless (<STDIN> =~ /^\s*n/i) { |
| | 5365 | adapter_pci_detection(); |
| | 5366 | load_module("i2c-dev") unless -e "$sysfs_root/class/i2c-dev"; |
| | 5367 | initialize_i2c_adapters_list(); |
| | 5368 | $i2c_addresses_to_scan = i2c_addresses_to_scan(); |
| | 5369 | print "\n"; |
| | 5370 | |
| | 5371 | # Skip SMBus probing by default if Super-I/O has all the features |
| | 5372 | my $by_default = ~$superio_features & (FEAT_IN | FEAT_FAN | FEAT_TEMP); |
| | 5373 | # Except on Asus and Tyan boards which often have more than |
| | 5374 | # one hardware monitoring chip |
| | 5375 | $by_default = 1 if dmi_match('board_vendor', 'asustek', 'tyan', |
| | 5376 | 'supermicro'); |
| | 5377 | |
| | 5378 | for (my $dev_nr = 0; $dev_nr < @i2c_adapters; $dev_nr++) { |
| | 5379 | next unless exists $i2c_adapters[$dev_nr]; |
| | 5380 | scan_i2c_adapter($dev_nr, $by_default); |
| | 5381 | } |
| | 5382 | } |
| | 5383 | |
| | 5384 | if (!keys %chips_detected) { |
| | 5385 | print "Sorry, no sensors were detected.\n"; |
| | 5386 | if (is_laptop() && -d "$sysfs_root/firmware/acpi") { |
| | 5387 | print "This is relatively common on laptops, where thermal management is\n". |
| | 5388 | "handled by ACPI rather than the OS.\n"; |
| | 5389 | } else { |
| | 5390 | print "Either your system has no sensors, or they are not supported, or\n". |
| | 5391 | "they are connected to an I2C or SMBus adapter that is not\n". |
| | 5392 | "supported. If you find out what chips are on your board, check\n". |
| | 5393 | "http://www.lm-sensors.org/wiki/Devices for driver status.\n"; |
| | 5394 | } |
| | 5395 | exit; |
| | 5396 | } |
| | 5397 | |
| | 5398 | print "Now follows a summary of the probes I have just done.\n". |
| | 5399 | "Just press ENTER to continue: "; |
| | 5400 | <STDIN>; |
| | 5401 | |
| | 5402 | foreach my $driver (keys %chips_detected) { |
| | 5403 | next unless @{$chips_detected{$driver}}; |
| | 5404 | find_aliases($chips_detected{$driver}); |
| | 5405 | print "\nDriver `$driver':\n"; |
| | 5406 | print_chips_report($chips_detected{$driver}); |
| | 5407 | } |
| | 5408 | print "\n"; |
| | 5409 | |
| | 5410 | my ($modprobes, $configfile, $bus_modules, $hwmon_modules) = generate_modprobes(); |
| | 5411 | write_config($modprobes, $configfile, $bus_modules, $hwmon_modules); |
| | 5412 | |