1/* 2 * acpi_processor.c - ACPI Processor Driver ($Revision: 71 $) 3 * 4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> 7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 8 * - Added processor hotplug support 9 * 10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or (at 15 * your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, but 18 * WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 * General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License along 23 * with this program; if not, write to the Free Software Foundation, Inc., 24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 25 * 26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 * TBD: 28 * 1. Make # power states dynamic. 29 * 2. Support duty_cycle values that span bit 4. 30 * 3. Optimize by having scheduler determine business instead of 31 * having us try to calculate it here. 32 * 4. Need C1 timing -- must modify kernel (IRQ handler) to get this. 33 */ 34 35#include <linux/kernel.h> 36#include <linux/module.h> 37#include <linux/init.h> 38#include <linux/types.h> 39#include <linux/pci.h> 40#include <linux/pm.h> 41#include <linux/cpufreq.h> 42#include <linux/cpu.h> 43#include <linux/proc_fs.h> 44#include <linux/seq_file.h> 45#include <linux/dmi.h> 46#include <linux/moduleparam.h> 47#include <linux/cpuidle.h> 48#include <linux/slab.h> 49 50#include <asm/io.h> 51#include <asm/system.h> 52#include <asm/cpu.h> 53#include <asm/delay.h> 54#include <asm/uaccess.h> 55#include <asm/processor.h> 56#include <asm/smp.h> 57#include <asm/acpi.h> 58 59#include <acpi/acpi_bus.h> 60#include <acpi/acpi_drivers.h> 61#include <acpi/processor.h> 62 63#define PREFIX "ACPI: " 64 65#define ACPI_PROCESSOR_CLASS "processor" 66#define ACPI_PROCESSOR_DEVICE_NAME "Processor" 67#define ACPI_PROCESSOR_FILE_INFO "info" 68#define ACPI_PROCESSOR_FILE_THROTTLING "throttling" 69#define ACPI_PROCESSOR_FILE_LIMIT "limit" 70#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 71#define ACPI_PROCESSOR_NOTIFY_POWER 0x81 72#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 73 74#define ACPI_PROCESSOR_LIMIT_USER 0 75#define ACPI_PROCESSOR_LIMIT_THERMAL 1 76 77#define _COMPONENT ACPI_PROCESSOR_COMPONENT 78ACPI_MODULE_NAME("processor_driver"); 79 80MODULE_AUTHOR("Paul Diefenbaugh"); 81MODULE_DESCRIPTION("ACPI Processor Driver"); 82MODULE_LICENSE("GPL"); 83 84static int acpi_processor_add(struct acpi_device *device); 85static int acpi_processor_remove(struct acpi_device *device, int type); 86static void acpi_processor_notify(struct acpi_device *device, u32 event); 87static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); 88static int acpi_processor_handle_eject(struct acpi_processor *pr); 89 90 91static const struct acpi_device_id processor_device_ids[] = { 92 {ACPI_PROCESSOR_OBJECT_HID, 0}, 93 {"ACPI0007", 0}, 94 {"", 0}, 95}; 96MODULE_DEVICE_TABLE(acpi, processor_device_ids); 97 98static struct acpi_driver acpi_processor_driver = { 99 .name = "processor", 100 .class = ACPI_PROCESSOR_CLASS, 101 .ids = processor_device_ids, 102 .ops = { 103 .add = acpi_processor_add, 104 .remove = acpi_processor_remove, 105 .suspend = acpi_processor_suspend, 106 .resume = acpi_processor_resume, 107 .notify = acpi_processor_notify, 108 }, 109}; 110 111#define INSTALL_NOTIFY_HANDLER 1 112#define UNINSTALL_NOTIFY_HANDLER 2 113 114DEFINE_PER_CPU(struct acpi_processor *, processors); 115EXPORT_PER_CPU_SYMBOL(processors); 116 117struct acpi_processor_errata errata __read_mostly; 118 119/* -------------------------------------------------------------------------- 120 Errata Handling 121 -------------------------------------------------------------------------- */ 122 123static int acpi_processor_errata_piix4(struct pci_dev *dev) 124{ 125 u8 value1 = 0; 126 u8 value2 = 0; 127 128 129 if (!dev) 130 return -EINVAL; 131 132 /* 133 * Note that 'dev' references the PIIX4 ACPI Controller. 134 */ 135 136 switch (dev->revision) { 137 case 0: 138 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n")); 139 break; 140 case 1: 141 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n")); 142 break; 143 case 2: 144 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n")); 145 break; 146 case 3: 147 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n")); 148 break; 149 default: 150 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n")); 151 break; 152 } 153 154 switch (dev->revision) { 155 156 case 0: /* PIIX4 A-step */ 157 case 1: /* PIIX4 B-step */ 158 /* 159 * See specification changes #13 ("Manual Throttle Duty Cycle") 160 * and #14 ("Enabling and Disabling Manual Throttle"), plus 161 * erratum #5 ("STPCLK# Deassertion Time") from the January 162 * 2002 PIIX4 specification update. Applies to only older 163 * PIIX4 models. 164 */ 165 errata.piix4.throttle = 1; 166 167 case 2: /* PIIX4E */ 168 case 3: /* PIIX4M */ 169 /* 170 * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA 171 * Livelock") from the January 2002 PIIX4 specification update. 172 * Applies to all PIIX4 models. 173 */ 174 175 /* 176 * BM-IDE 177 * ------ 178 * Find the PIIX4 IDE Controller and get the Bus Master IDE 179 * Status register address. We'll use this later to read 180 * each IDE controller's DMA status to make sure we catch all 181 * DMA activity. 182 */ 183 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, 184 PCI_DEVICE_ID_INTEL_82371AB, 185 PCI_ANY_ID, PCI_ANY_ID, NULL); 186 if (dev) { 187 errata.piix4.bmisx = pci_resource_start(dev, 4); 188 pci_dev_put(dev); 189 } 190 191 /* 192 * Type-F DMA 193 * ---------- 194 * Find the PIIX4 ISA Controller and read the Motherboard 195 * DMA controller's status to see if Type-F (Fast) DMA mode 196 * is enabled (bit 7) on either channel. Note that we'll 197 * disable C3 support if this is enabled, as some legacy 198 * devices won't operate well if fast DMA is disabled. 199 */ 200 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, 201 PCI_DEVICE_ID_INTEL_82371AB_0, 202 PCI_ANY_ID, PCI_ANY_ID, NULL); 203 if (dev) { 204 pci_read_config_byte(dev, 0x76, &value1); 205 pci_read_config_byte(dev, 0x77, &value2); 206 if ((value1 & 0x80) || (value2 & 0x80)) 207 errata.piix4.fdma = 1; 208 pci_dev_put(dev); 209 } 210 211 break; 212 } 213 214 if (errata.piix4.bmisx) 215 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 216 "Bus master activity detection (BM-IDE) erratum enabled\n")); 217 if (errata.piix4.fdma) 218 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 219 "Type-F DMA livelock erratum (C3 disabled)\n")); 220 221 return 0; 222} 223 224static int acpi_processor_errata(struct acpi_processor *pr) 225{ 226 int result = 0; 227 struct pci_dev *dev = NULL; 228 229 230 if (!pr) 231 return -EINVAL; 232 233 /* 234 * PIIX4 235 */ 236 dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, 237 PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, 238 PCI_ANY_ID, NULL); 239 if (dev) { 240 result = acpi_processor_errata_piix4(dev); 241 pci_dev_put(dev); 242 } 243 244 return result; 245} 246 247static struct proc_dir_entry *acpi_processor_dir = NULL; 248 249static int __cpuinit acpi_processor_add_fs(struct acpi_device *device) 250{ 251 struct proc_dir_entry *entry = NULL; 252 253 254 if (!acpi_device_dir(device)) { 255 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 256 acpi_processor_dir); 257 if (!acpi_device_dir(device)) 258 return -ENODEV; 259 } 260 261 /* 'throttling' [R/W] */ 262 entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING, 263 S_IFREG | S_IRUGO | S_IWUSR, 264 acpi_device_dir(device), 265 &acpi_processor_throttling_fops, 266 acpi_driver_data(device)); 267 if (!entry) 268 return -EIO; 269 return 0; 270} 271static int acpi_processor_remove_fs(struct acpi_device *device) 272{ 273 274 if (acpi_device_dir(device)) { 275 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING, 276 acpi_device_dir(device)); 277 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir); 278 acpi_device_dir(device) = NULL; 279 } 280 281 return 0; 282} 283 284/* -------------------------------------------------------------------------- 285 Driver Interface 286 -------------------------------------------------------------------------- */ 287 288static int acpi_processor_get_info(struct acpi_device *device) 289{ 290 acpi_status status = 0; 291 union acpi_object object = { 0 }; 292 struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; 293 struct acpi_processor *pr; 294 int cpu_index, device_declaration = 0; 295 static int cpu0_initialized; 296 297 pr = acpi_driver_data(device); 298 if (!pr) 299 return -EINVAL; 300 301 if (num_online_cpus() > 1) 302 errata.smp = TRUE; 303 304 acpi_processor_errata(pr); 305 306 /* 307 * Check to see if we have bus mastering arbitration control. This 308 * is required for proper C3 usage (to maintain cache coherency). 309 */ 310 if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) { 311 pr->flags.bm_control = 1; 312 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 313 "Bus mastering arbitration control present\n")); 314 } else 315 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 316 "No bus mastering arbitration control\n")); 317 318 if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) { 319 /* Declared with "Processor" statement; match ProcessorID */ 320 status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); 321 if (ACPI_FAILURE(status)) { 322 printk(KERN_ERR PREFIX "Evaluating processor object\n"); 323 return -ENODEV; 324 } 325 326 pr->acpi_id = object.processor.proc_id; 327 } else { 328 /* 329 * Declared with "Device" statement; match _UID. 330 * Note that we don't handle string _UIDs yet. 331 */ 332 unsigned long long value; 333 status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, 334 NULL, &value); 335 if (ACPI_FAILURE(status)) { 336 printk(KERN_ERR PREFIX 337 "Evaluating processor _UID [%#x]\n", status); 338 return -ENODEV; 339 } 340 device_declaration = 1; 341 pr->acpi_id = value; 342 } 343 cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id); 344 345 /* Handle UP system running SMP kernel, with no LAPIC in MADT */ 346 if (!cpu0_initialized && (cpu_index == -1) && 347 (num_online_cpus() == 1)) { 348 cpu_index = 0; 349 } 350 351 cpu0_initialized = 1; 352 353 pr->id = cpu_index; 354 355 /* 356 * Extra Processor objects may be enumerated on MP systems with 357 * less than the max # of CPUs. They should be ignored _iff 358 * they are physically not present. 359 */ 360 if (pr->id == -1) { 361 if (ACPI_FAILURE 362 (acpi_processor_hotadd_init(pr->handle, &pr->id))) { 363 return -ENODEV; 364 } 365 } 366 /* 367 * On some boxes several processors use the same processor bus id. 368 * But they are located in different scope. For example: 369 * \_SB.SCK0.CPU0 370 * \_SB.SCK1.CPU0 371 * Rename the processor device bus id. And the new bus id will be 372 * generated as the following format: 373 * CPU+CPU ID. 374 */ 375 sprintf(acpi_device_bid(device), "CPU%X", pr->id); 376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id, 377 pr->acpi_id)); 378 379 if (!object.processor.pblk_address) 380 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n")); 381 else if (object.processor.pblk_length != 6) 382 printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n", 383 object.processor.pblk_length); 384 else { 385 pr->throttling.address = object.processor.pblk_address; 386 pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; 387 pr->throttling.duty_width = acpi_gbl_FADT.duty_width; 388 389 pr->pblk = object.processor.pblk_address; 390 391 /* 392 * We don't care about error returns - we just try to mark 393 * these reserved so that nobody else is confused into thinking 394 * that this region might be unused.. 395 * 396 * (In particular, allocating the IO range for Cardbus) 397 */ 398 request_region(pr->throttling.address, 6, "ACPI CPU throttle"); 399 } 400 401 /* 402 * If ACPI describes a slot number for this CPU, we can use it 403 * ensure we get the right value in the "physical id" field 404 * of /proc/cpuinfo 405 */ 406 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer); 407 if (ACPI_SUCCESS(status)) 408 arch_fix_phys_package_id(pr->id, object.integer.value); 409 410 return 0; 411} 412 413static DEFINE_PER_CPU(void *, processor_device_array); 414 415static void acpi_processor_notify(struct acpi_device *device, u32 event) 416{ 417 struct acpi_processor *pr = acpi_driver_data(device); 418 int saved; 419 420 if (!pr) 421 return; 422 423 switch (event) { 424 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: 425 saved = pr->performance_platform_limit; 426 acpi_processor_ppc_has_changed(pr, 1); 427 if (saved == pr->performance_platform_limit) 428 break; 429 acpi_bus_generate_proc_event(device, event, 430 pr->performance_platform_limit); 431 acpi_bus_generate_netlink_event(device->pnp.device_class, 432 dev_name(&device->dev), event, 433 pr->performance_platform_limit); 434 break; 435 case ACPI_PROCESSOR_NOTIFY_POWER: 436 acpi_processor_cst_has_changed(pr); 437 acpi_bus_generate_proc_event(device, event, 0); 438 acpi_bus_generate_netlink_event(device->pnp.device_class, 439 dev_name(&device->dev), event, 0); 440 break; 441 case ACPI_PROCESSOR_NOTIFY_THROTTLING: 442 acpi_processor_tstate_has_changed(pr); 443 acpi_bus_generate_proc_event(device, event, 0); 444 acpi_bus_generate_netlink_event(device->pnp.device_class, 445 dev_name(&device->dev), event, 0); 446 default: 447 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 448 "Unsupported event [0x%x]\n", event)); 449 break; 450 } 451 452 return; 453} 454 455static int acpi_cpu_soft_notify(struct notifier_block *nfb, 456 unsigned long action, void *hcpu) 457{ 458 unsigned int cpu = (unsigned long)hcpu; 459 struct acpi_processor *pr = per_cpu(processors, cpu); 460 461 if (action == CPU_ONLINE && pr) { 462 acpi_processor_ppc_has_changed(pr, 0); 463 acpi_processor_cst_has_changed(pr); 464 acpi_processor_tstate_has_changed(pr); 465 } 466 return NOTIFY_OK; 467} 468 469static struct notifier_block acpi_cpu_notifier = 470{ 471 .notifier_call = acpi_cpu_soft_notify, 472}; 473 474static int __cpuinit acpi_processor_add(struct acpi_device *device) 475{ 476 struct acpi_processor *pr = NULL; 477 int result = 0; 478 struct sys_device *sysdev; 479 480 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); 481 if (!pr) 482 return -ENOMEM; 483 484 if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { 485 kfree(pr); 486 return -ENOMEM; 487 } 488 489 pr->handle = device->handle; 490 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); 491 strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); 492 device->driver_data = pr; 493 494 result = acpi_processor_get_info(device); 495 if (result) { 496 /* Processor is physically not present */ 497 return 0; 498 } 499 500#ifdef CONFIG_SMP 501 if (pr->id >= setup_max_cpus && pr->id != 0) 502 return 0; 503#endif 504 505 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0)); 506 507 /* 508 * Buggy BIOS check 509 * ACPI id of processors can be reported wrongly by the BIOS. 510 * Don't trust it blindly 511 */ 512 if (per_cpu(processor_device_array, pr->id) != NULL && 513 per_cpu(processor_device_array, pr->id) != device) { 514 printk(KERN_WARNING "BIOS reported wrong ACPI id " 515 "for the processor\n"); 516 result = -ENODEV; 517 goto err_free_cpumask; 518 } 519 per_cpu(processor_device_array, pr->id) = device; 520 521 per_cpu(processors, pr->id) = pr; 522 523 result = acpi_processor_add_fs(device); 524 if (result) 525 goto err_free_cpumask; 526 527 sysdev = get_cpu_sysdev(pr->id); 528 if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) { 529 result = -EFAULT; 530 goto err_remove_fs; 531 } 532 533#ifdef CONFIG_CPU_FREQ 534 acpi_processor_ppc_has_changed(pr, 0); 535#endif 536 acpi_processor_get_throttling_info(pr); 537 acpi_processor_get_limit_info(pr); 538 539 540 if (cpuidle_get_driver() == &acpi_idle_driver) 541 acpi_processor_power_init(pr, device); 542 543 pr->cdev = thermal_cooling_device_register("Processor", device, 544 &processor_cooling_ops); 545 if (IS_ERR(pr->cdev)) { 546 result = PTR_ERR(pr->cdev); 547 goto err_power_exit; 548 } 549 550 dev_dbg(&device->dev, "registered as cooling_device%d\n", 551 pr->cdev->id); 552 553 result = sysfs_create_link(&device->dev.kobj, 554 &pr->cdev->device.kobj, 555 "thermal_cooling"); 556 if (result) { 557 printk(KERN_ERR PREFIX "Create sysfs link\n"); 558 goto err_thermal_unregister; 559 } 560 result = sysfs_create_link(&pr->cdev->device.kobj, 561 &device->dev.kobj, 562 "device"); 563 if (result) { 564 printk(KERN_ERR PREFIX "Create sysfs link\n"); 565 goto err_remove_sysfs; 566 } 567 568 return 0; 569 570err_remove_sysfs: 571 sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); 572err_thermal_unregister: 573 thermal_cooling_device_unregister(pr->cdev); 574err_power_exit: 575 acpi_processor_power_exit(pr, device); 576err_remove_fs: 577 acpi_processor_remove_fs(device); 578err_free_cpumask: 579 free_cpumask_var(pr->throttling.shared_cpu_map); 580 581 return result; 582} 583 584static int acpi_processor_remove(struct acpi_device *device, int type) 585{ 586 struct acpi_processor *pr = NULL; 587 588 589 if (!device || !acpi_driver_data(device)) 590 return -EINVAL; 591 592 pr = acpi_driver_data(device); 593 594 if (pr->id >= nr_cpu_ids) 595 goto free; 596 597 if (type == ACPI_BUS_REMOVAL_EJECT) { 598 if (acpi_processor_handle_eject(pr)) 599 return -EINVAL; 600 } 601 602 acpi_processor_power_exit(pr, device); 603 604 sysfs_remove_link(&device->dev.kobj, "sysdev"); 605 606 acpi_processor_remove_fs(device); 607 608 if (pr->cdev) { 609 sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); 610 sysfs_remove_link(&pr->cdev->device.kobj, "device"); 611 thermal_cooling_device_unregister(pr->cdev); 612 pr->cdev = NULL; 613 } 614 615 per_cpu(processors, pr->id) = NULL; 616 per_cpu(processor_device_array, pr->id) = NULL; 617 618free: 619 free_cpumask_var(pr->throttling.shared_cpu_map); 620 kfree(pr); 621 622 return 0; 623} 624 625#ifdef CONFIG_ACPI_HOTPLUG_CPU 626/**************************************************************************** 627 * Acpi processor hotplug support * 628 ****************************************************************************/ 629 630static int is_processor_present(acpi_handle handle) 631{ 632 acpi_status status; 633 unsigned long long sta = 0; 634 635 636 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 637 638 if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT)) 639 return 1; 640 641 /* 642 * _STA is mandatory for a processor that supports hot plug 643 */ 644 if (status == AE_NOT_FOUND) 645 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 646 "Processor does not support hot plug\n")); 647 else 648 ACPI_EXCEPTION((AE_INFO, status, 649 "Processor Device is not present")); 650 return 0; 651} 652 653static 654int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device) 655{ 656 acpi_handle phandle; 657 struct acpi_device *pdev; 658 659 660 if (acpi_get_parent(handle, &phandle)) { 661 return -ENODEV; 662 } 663 664 if (acpi_bus_get_device(phandle, &pdev)) { 665 return -ENODEV; 666 } 667 668 if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) { 669 return -ENODEV; 670 } 671 672 return 0; 673} 674 675static void __ref acpi_processor_hotplug_notify(acpi_handle handle, 676 u32 event, void *data) 677{ 678 struct acpi_processor *pr; 679 struct acpi_device *device = NULL; 680 int result; 681 682 683 switch (event) { 684 case ACPI_NOTIFY_BUS_CHECK: 685 case ACPI_NOTIFY_DEVICE_CHECK: 686 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 687 "Processor driver received %s event\n", 688 (event == ACPI_NOTIFY_BUS_CHECK) ? 689 "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK")); 690 691 if (!is_processor_present(handle)) 692 break; 693 694 if (acpi_bus_get_device(handle, &device)) { 695 result = acpi_processor_device_add(handle, &device); 696 if (result) 697 printk(KERN_ERR PREFIX 698 "Unable to add the device\n"); 699 break; 700 } 701 break; 702 case ACPI_NOTIFY_EJECT_REQUEST: 703 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 704 "received ACPI_NOTIFY_EJECT_REQUEST\n")); 705 706 if (acpi_bus_get_device(handle, &device)) { 707 printk(KERN_ERR PREFIX 708 "Device don't exist, dropping EJECT\n"); 709 break; 710 } 711 pr = acpi_driver_data(device); 712 if (!pr) { 713 printk(KERN_ERR PREFIX 714 "Driver data is NULL, dropping EJECT\n"); 715 return; 716 } 717 break; 718 default: 719 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 720 "Unsupported event [0x%x]\n", event)); 721 break; 722 } 723 724 return; 725} 726 727static acpi_status 728processor_walk_namespace_cb(acpi_handle handle, 729 u32 lvl, void *context, void **rv) 730{ 731 acpi_status status; 732 int *action = context; 733 acpi_object_type type = 0; 734 735 status = acpi_get_type(handle, &type); 736 if (ACPI_FAILURE(status)) 737 return (AE_OK); 738 739 if (type != ACPI_TYPE_PROCESSOR) 740 return (AE_OK); 741 742 switch (*action) { 743 case INSTALL_NOTIFY_HANDLER: 744 acpi_install_notify_handler(handle, 745 ACPI_SYSTEM_NOTIFY, 746 acpi_processor_hotplug_notify, 747 NULL); 748 break; 749 case UNINSTALL_NOTIFY_HANDLER: 750 acpi_remove_notify_handler(handle, 751 ACPI_SYSTEM_NOTIFY, 752 acpi_processor_hotplug_notify); 753 break; 754 default: 755 break; 756 } 757 758 return (AE_OK); 759} 760 761static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) 762{ 763 764 if (!is_processor_present(handle)) { 765 return AE_ERROR; 766 } 767 768 if (acpi_map_lsapic(handle, p_cpu)) 769 return AE_ERROR; 770 771 if (arch_register_cpu(*p_cpu)) { 772 acpi_unmap_lsapic(*p_cpu); 773 return AE_ERROR; 774 } 775 776 return AE_OK; 777} 778 779static int acpi_processor_handle_eject(struct acpi_processor *pr) 780{ 781 if (cpu_online(pr->id)) 782 cpu_down(pr->id); 783 784 arch_unregister_cpu(pr->id); 785 acpi_unmap_lsapic(pr->id); 786 return (0); 787} 788#else 789static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) 790{ 791 return AE_ERROR; 792} 793static int acpi_processor_handle_eject(struct acpi_processor *pr) 794{ 795 return (-EINVAL); 796} 797#endif 798 799static 800void acpi_processor_install_hotplug_notify(void) 801{ 802#ifdef CONFIG_ACPI_HOTPLUG_CPU 803 int action = INSTALL_NOTIFY_HANDLER; 804 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, 805 ACPI_ROOT_OBJECT, 806 ACPI_UINT32_MAX, 807 processor_walk_namespace_cb, NULL, &action, NULL); 808#endif 809 register_hotcpu_notifier(&acpi_cpu_notifier); 810} 811 812static 813void acpi_processor_uninstall_hotplug_notify(void) 814{ 815#ifdef CONFIG_ACPI_HOTPLUG_CPU 816 int action = UNINSTALL_NOTIFY_HANDLER; 817 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, 818 ACPI_ROOT_OBJECT, 819 ACPI_UINT32_MAX, 820 processor_walk_namespace_cb, NULL, &action, NULL); 821#endif 822 unregister_hotcpu_notifier(&acpi_cpu_notifier); 823} 824 825/* 826 * We keep the driver loaded even when ACPI is not running. 827 * This is needed for the powernow-k8 driver, that works even without 828 * ACPI, but needs symbols from this driver 829 */ 830 831static int __init acpi_processor_init(void) 832{ 833 int result = 0; 834 835 if (acpi_disabled) 836 return 0; 837 838 memset(&errata, 0, sizeof(errata)); 839 840 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 841 if (!acpi_processor_dir) 842 return -ENOMEM; 843 844 if (!cpuidle_register_driver(&acpi_idle_driver)) { 845 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", 846 acpi_idle_driver.name); 847 } else { 848 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n", 849 cpuidle_get_driver()->name); 850 } 851 852 result = acpi_bus_register_driver(&acpi_processor_driver); 853 if (result < 0) 854 goto out_cpuidle; 855 856 acpi_processor_install_hotplug_notify(); 857 858 acpi_thermal_cpufreq_init(); 859 860 acpi_processor_ppc_init(); 861 862 acpi_processor_throttling_init(); 863 864 return 0; 865 866out_cpuidle: 867 cpuidle_unregister_driver(&acpi_idle_driver); 868 869 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 870 871 return result; 872} 873 874static void __exit acpi_processor_exit(void) 875{ 876 if (acpi_disabled) 877 return; 878 879 acpi_processor_ppc_exit(); 880 881 acpi_thermal_cpufreq_exit(); 882 883 acpi_processor_uninstall_hotplug_notify(); 884 885 acpi_bus_unregister_driver(&acpi_processor_driver); 886 887 cpuidle_unregister_driver(&acpi_idle_driver); 888 889 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 890 891 return; 892} 893 894module_init(acpi_processor_init); 895module_exit(acpi_processor_exit); 896 897EXPORT_SYMBOL(acpi_processor_set_thermal_limit); 898 899MODULE_ALIAS("processor"); 900