Blame view
drivers/acpi/acpi_processor.c
23.5 KB
d2912cb15 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
ac212b698 ACPI / processor:... |
2 3 4 5 6 7 8 9 10 |
/* * acpi_processor.c - ACPI processor enumeration support * * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> * Copyright (C) 2013, Intel Corporation * Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
ac212b698 ACPI / processor:... |
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
*/ #include <linux/acpi.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include <acpi/processor.h> #include <asm/cpu.h> #include "internal.h" #define _COMPONENT ACPI_PROCESSOR_COMPONENT ACPI_MODULE_NAME("processor"); |
2e4f1db49 ACPI / processor:... |
28 29 |
DEFINE_PER_CPU(struct acpi_processor *, processors); EXPORT_PER_CPU_SYMBOL(processors); |
ac212b698 ACPI / processor:... |
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
/* -------------------------------------------------------------------------- Errata Handling -------------------------------------------------------------------------- */ struct acpi_processor_errata errata __read_mostly; EXPORT_SYMBOL_GPL(errata); static int acpi_processor_errata_piix4(struct pci_dev *dev) { u8 value1 = 0; u8 value2 = 0; if (!dev) return -EINVAL; /* * Note that 'dev' references the PIIX4 ACPI Controller. */ switch (dev->revision) { case 0: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step ")); break; case 1: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step ")); break; case 2: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E ")); break; case 3: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M ")); break; default: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4 ")); break; } switch (dev->revision) { case 0: /* PIIX4 A-step */ case 1: /* PIIX4 B-step */ /* * See specification changes #13 ("Manual Throttle Duty Cycle") * and #14 ("Enabling and Disabling Manual Throttle"), plus * erratum #5 ("STPCLK# Deassertion Time") from the January * 2002 PIIX4 specification update. Applies to only older * PIIX4 models. */ errata.piix4.throttle = 1; |
57d2dd4bd ACPI: Use fallthr... |
85 |
fallthrough; |
ac212b698 ACPI / processor:... |
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
case 2: /* PIIX4E */ case 3: /* PIIX4M */ /* * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA * Livelock") from the January 2002 PIIX4 specification update. * Applies to all PIIX4 models. */ /* * BM-IDE * ------ * Find the PIIX4 IDE Controller and get the Bus Master IDE * Status register address. We'll use this later to read * each IDE controller's DMA status to make sure we catch all * DMA activity. */ dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB, PCI_ANY_ID, PCI_ANY_ID, NULL); if (dev) { errata.piix4.bmisx = pci_resource_start(dev, 4); pci_dev_put(dev); } /* * Type-F DMA * ---------- * Find the PIIX4 ISA Controller and read the Motherboard * DMA controller's status to see if Type-F (Fast) DMA mode * is enabled (bit 7) on either channel. Note that we'll * disable C3 support if this is enabled, as some legacy * devices won't operate well if fast DMA is disabled. */ dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0, PCI_ANY_ID, PCI_ANY_ID, NULL); if (dev) { pci_read_config_byte(dev, 0x76, &value1); pci_read_config_byte(dev, 0x77, &value2); if ((value1 & 0x80) || (value2 & 0x80)) errata.piix4.fdma = 1; pci_dev_put(dev); } break; } if (errata.piix4.bmisx) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Bus master activity detection (BM-IDE) erratum enabled ")); if (errata.piix4.fdma) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Type-F DMA livelock erratum (C3 disabled) ")); return 0; } |
082e12a05 ACPI / processor:... |
145 |
static int acpi_processor_errata(void) |
ac212b698 ACPI / processor:... |
146 147 148 |
{ int result = 0; struct pci_dev *dev = NULL; |
ac212b698 ACPI / processor:... |
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
/* * PIIX4 */ dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, PCI_ANY_ID, NULL); if (dev) { result = acpi_processor_errata_piix4(dev); pci_dev_put(dev); } return result; } /* -------------------------------------------------------------------------- Initialization -------------------------------------------------------------------------- */ #ifdef CONFIG_ACPI_HOTPLUG_CPU |
56cdc2a05 ACPI: Add weak ro... |
168 |
int __weak acpi_map_cpu(acpi_handle handle, |
febf24074 x86/ACPI: keep x8... |
169 |
phys_cpuid_t physid, u32 acpi_id, int *pcpu) |
56cdc2a05 ACPI: Add weak ro... |
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
{ return -ENODEV; } int __weak acpi_unmap_cpu(int cpu) { return -ENODEV; } int __weak arch_register_cpu(int cpu) { return -ENODEV; } void __weak arch_unregister_cpu(int cpu) {} |
ac212b698 ACPI / processor:... |
185 186 187 188 189 |
static int acpi_processor_hotadd_init(struct acpi_processor *pr) { unsigned long long sta; acpi_status status; int ret; |
ddcc18f5b ACPI / processor:... |
190 |
if (invalid_phys_cpuid(pr->phys_id)) |
4985c32ee ACPI / processor:... |
191 |
return -ENODEV; |
ac212b698 ACPI / processor:... |
192 193 194 |
status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta); if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) return -ENODEV; |
b9d10be7a ACPI / processor:... |
195 196 |
cpu_maps_update_begin(); cpu_hotplug_begin(); |
febf24074 x86/ACPI: keep x8... |
197 |
ret = acpi_map_cpu(pr->handle, pr->phys_id, pr->acpi_id, &pr->id); |
ac212b698 ACPI / processor:... |
198 |
if (ret) |
b9d10be7a ACPI / processor:... |
199 |
goto out; |
ac212b698 ACPI / processor:... |
200 201 202 |
ret = arch_register_cpu(pr->id); if (ret) { |
d02dc27db ACPI / processor:... |
203 |
acpi_unmap_cpu(pr->id); |
b9d10be7a ACPI / processor:... |
204 |
goto out; |
ac212b698 ACPI / processor:... |
205 206 207 208 209 210 211 212 213 214 |
} /* * CPU got hot-added, but cpu_data is not initialized yet. Set a flag * to delay cpu_idle/throttling initialization and do it when the CPU * gets online for the first time. */ pr_info("CPU%d has been hot-added ", pr->id); pr->flags.need_hotplug_init = 1; |
b9d10be7a ACPI / processor:... |
215 216 217 218 219 |
out: cpu_hotplug_done(); cpu_maps_update_done(); return ret; |
ac212b698 ACPI / processor:... |
220 221 222 223 224 225 226 227 228 229 230 231 232 |
} #else static inline int acpi_processor_hotadd_init(struct acpi_processor *pr) { return -ENODEV; } #endif /* CONFIG_ACPI_HOTPLUG_CPU */ static int acpi_processor_get_info(struct acpi_device *device) { union acpi_object object = { 0 }; struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; struct acpi_processor *pr = acpi_driver_data(device); |
05eb3cd8b ACPI / processor:... |
233 |
int device_declaration = 0; |
ac212b698 ACPI / processor:... |
234 235 |
acpi_status status = AE_OK; static int cpu0_initialized; |
6ebb5bc9e acpi_processor: c... |
236 |
unsigned long long value; |
ac212b698 ACPI / processor:... |
237 |
|
082e12a05 ACPI / processor:... |
238 |
acpi_processor_errata(); |
ac212b698 ACPI / processor:... |
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
/* * Check to see if we have bus mastering arbitration control. This * is required for proper C3 usage (to maintain cache coherency). */ if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) { pr->flags.bm_control = 1; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Bus mastering arbitration control present ")); } else ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No bus mastering arbitration control ")); if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) { /* Declared with "Processor" statement; match ProcessorID */ status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer); if (ACPI_FAILURE(status)) { dev_err(&device->dev, "Failed to evaluate processor object (0x%x) ", status); return -ENODEV; } |
ac212b698 ACPI / processor:... |
264 265 266 267 |
pr->acpi_id = object.processor.proc_id; } else { /* * Declared with "Device" statement; match _UID. |
ac212b698 ACPI / processor:... |
268 |
*/ |
ac212b698 ACPI / processor:... |
269 270 271 272 273 274 275 276 277 278 279 280 |
status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID, NULL, &value); if (ACPI_FAILURE(status)) { dev_err(&device->dev, "Failed to evaluate processor _UID (0x%x) ", status); return -ENODEV; } device_declaration = 1; pr->acpi_id = value; } |
ac212b698 ACPI / processor:... |
281 |
|
a77d6cd96 acpi/processor: C... |
282 |
if (acpi_duplicate_processor_id(pr->acpi_id)) { |
2c2b005f5 ACPI / processor:... |
283 284 285 286 287 288 289 290 291 |
if (pr->acpi_id == 0xff) dev_info_once(&device->dev, "Entry not well-defined, consider updating BIOS "); else dev_err(&device->dev, "Failed to get unique processor _UID (0x%x) ", pr->acpi_id); |
a77d6cd96 acpi/processor: C... |
292 293 |
return -ENODEV; } |
8416c5bda ACPI / processor:... |
294 295 |
pr->phys_id = acpi_get_phys_id(pr->handle, device_declaration, pr->acpi_id); |
ddcc18f5b ACPI / processor:... |
296 |
if (invalid_phys_cpuid(pr->phys_id)) |
af8f3f514 ACPI / processor:... |
297 298 |
acpi_handle_debug(pr->handle, "failed to get CPU physical ID. "); |
ac212b698 ACPI / processor:... |
299 |
|
05eb3cd8b ACPI / processor:... |
300 |
pr->id = acpi_map_cpuid(pr->phys_id, pr->acpi_id); |
b50154d53 ACPI: Don't use a... |
301 |
if (!cpu0_initialized && !acpi_has_cpu_in_madt()) { |
b981513f8 ACPI / scan: bail... |
302 |
cpu0_initialized = 1; |
af8f3f514 ACPI / processor:... |
303 304 305 306 |
/* * Handle UP system running SMP kernel, with no CPU * entry in MADT */ |
05eb3cd8b ACPI / processor:... |
307 308 |
if (invalid_logical_cpuid(pr->id) && (num_online_cpus() == 1)) pr->id = 0; |
b981513f8 ACPI / scan: bail... |
309 |
} |
ac212b698 ACPI / processor:... |
310 311 312 313 314 |
/* * Extra Processor objects may be enumerated on MP systems with * less than the max # of CPUs. They should be ignored _iff * they are physically not present. |
8ad893faf x86/acpi: Enable ... |
315 316 317 |
* * NOTE: Even if the processor has a cpuid, it may not be present * because cpuid <-> apicid mapping is persistent now. |
ac212b698 ACPI / processor:... |
318 |
*/ |
8ad893faf x86/acpi: Enable ... |
319 |
if (invalid_logical_cpuid(pr->id) || !cpu_present(pr->id)) { |
ac212b698 ACPI / processor:... |
320 321 322 323 |
int ret = acpi_processor_hotadd_init(pr); if (ret) return ret; } |
b981513f8 ACPI / scan: bail... |
324 |
|
ac212b698 ACPI / processor:... |
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
/* * On some boxes several processors use the same processor bus id. * But they are located in different scope. For example: * \_SB.SCK0.CPU0 * \_SB.SCK1.CPU0 * Rename the processor device bus id. And the new bus id will be * generated as the following format: * CPU+CPU ID. */ sprintf(acpi_device_bid(device), "CPU%X", pr->id); ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d] ", pr->id, pr->acpi_id)); if (!object.processor.pblk_address) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address) ")); else if (object.processor.pblk_length != 6) dev_err(&device->dev, "Invalid PBLK length [%d] ", object.processor.pblk_length); else { pr->throttling.address = object.processor.pblk_address; pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset; pr->throttling.duty_width = acpi_gbl_FADT.duty_width; pr->pblk = object.processor.pblk_address; |
ac212b698 ACPI / processor:... |
352 353 354 355 356 357 358 |
} /* * If ACPI describes a slot number for this CPU, we can use it to * ensure we get the right value in the "physical id" field * of /proc/cpuinfo */ |
6ebb5bc9e acpi_processor: c... |
359 |
status = acpi_evaluate_integer(pr->handle, "_SUN", NULL, &value); |
ac212b698 ACPI / processor:... |
360 |
if (ACPI_SUCCESS(status)) |
6ebb5bc9e acpi_processor: c... |
361 |
arch_fix_phys_package_id(pr->id, value); |
ac212b698 ACPI / processor:... |
362 363 364 365 366 367 368 369 370 371 372 |
return 0; } /* * Do not put anything in here which needs the core to be online. * For example MSR access or setting up things which check for cpuinfo_x86 * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc. * Such things have to be put in and set up by the processor driver's .probe(). */ static DEFINE_PER_CPU(void *, processor_device_array); |
fe7bf106e acpi: delete __cp... |
373 |
static int acpi_processor_add(struct acpi_device *device, |
ac212b698 ACPI / processor:... |
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
const struct acpi_device_id *id) { struct acpi_processor *pr; struct device *dev; int result = 0; pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); if (!pr) return -ENOMEM; if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) { result = -ENOMEM; goto err_free_pr; } pr->handle = device->handle; strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS); device->driver_data = pr; result = acpi_processor_get_info(device); if (result) /* Processor is not physically present or unavailable */ return 0; |
ac212b698 ACPI / processor:... |
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
BUG_ON(pr->id >= nr_cpu_ids); /* * Buggy BIOS check. * ACPI id of processors can be reported wrongly by the BIOS. * Don't trust it blindly */ if (per_cpu(processor_device_array, pr->id) != NULL && per_cpu(processor_device_array, pr->id) != device) { dev_warn(&device->dev, "BIOS reported wrong ACPI id %d for the processor ", pr->id); /* Give up, but do not abort the namespace scan. */ goto err; } /* * processor_device_array is not cleared on errors to allow buggy BIOS * checks. */ per_cpu(processor_device_array, pr->id) = device; |
2e4f1db49 ACPI / processor:... |
418 |
per_cpu(processors, pr->id) = pr; |
ac212b698 ACPI / processor:... |
419 420 |
dev = get_cpu_device(pr->id); |
173a5a4c9 ACPI / processor:... |
421 422 423 424 |
if (!dev) { result = -ENODEV; goto err; } |
24dee1fc9 ACPI / bind: Pass... |
425 |
result = acpi_bind_one(dev, device); |
ac212b698 ACPI / processor:... |
426 427 428 429 |
if (result) goto err; pr->dev = dev; |
ac212b698 ACPI / processor:... |
430 431 432 433 434 435 436 437 438 439 440 441 |
/* Trigger the processor driver's .probe() if present. */ if (device_attach(dev) >= 0) return 1; dev_err(dev, "Processor driver could not be attached "); acpi_unbind_one(dev); err: free_cpumask_var(pr->throttling.shared_cpu_map); device->driver_data = NULL; |
2e4f1db49 ACPI / processor:... |
442 |
per_cpu(processors, pr->id) = NULL; |
ac212b698 ACPI / processor:... |
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
err_free_pr: kfree(pr); return result; } #ifdef CONFIG_ACPI_HOTPLUG_CPU /* -------------------------------------------------------------------------- Removal -------------------------------------------------------------------------- */ static void acpi_processor_remove(struct acpi_device *device) { struct acpi_processor *pr; if (!device || !acpi_driver_data(device)) return; pr = acpi_driver_data(device); if (pr->id >= nr_cpu_ids) goto out; /* * The only reason why we ever get here is CPU hot-removal. The CPU is * already offline and the ACPI device removal locking prevents it from * being put back online at this point. * * Unbind the driver from the processor device and detach it from the * ACPI companion object. */ device_release_driver(pr->dev); acpi_unbind_one(pr->dev); /* Clean up. */ per_cpu(processor_device_array, pr->id) = NULL; |
2e4f1db49 ACPI / processor:... |
477 |
per_cpu(processors, pr->id) = NULL; |
ac212b698 ACPI / processor:... |
478 |
|
b9d10be7a ACPI / processor:... |
479 480 |
cpu_maps_update_begin(); cpu_hotplug_begin(); |
ac212b698 ACPI / processor:... |
481 |
/* Remove the CPU. */ |
ac212b698 ACPI / processor:... |
482 |
arch_unregister_cpu(pr->id); |
d02dc27db ACPI / processor:... |
483 |
acpi_unmap_cpu(pr->id); |
b9d10be7a ACPI / processor:... |
484 485 486 |
cpu_hotplug_done(); cpu_maps_update_done(); |
ac212b698 ACPI / processor:... |
487 |
|
1e385f6f9 ACPI / processor:... |
488 |
try_offline_node(cpu_to_node(pr->id)); |
ac212b698 ACPI / processor:... |
489 490 491 492 493 |
out: free_cpumask_var(pr->throttling.shared_cpu_map); kfree(pr); } #endif /* CONFIG_ACPI_HOTPLUG_CPU */ |
a21211672 ACPI / processor:... |
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
#ifdef CONFIG_X86 static bool acpi_hwp_native_thermal_lvt_set; static acpi_status __init acpi_hwp_native_thermal_lvt_osc(acpi_handle handle, u32 lvl, void *context, void **rv) { u8 sb_uuid_str[] = "4077A616-290C-47BE-9EBD-D87058713953"; u32 capbuf[2]; struct acpi_osc_context osc_context = { .uuid_str = sb_uuid_str, .rev = 1, .cap.length = 8, .cap.pointer = capbuf, }; if (acpi_hwp_native_thermal_lvt_set) return AE_CTRL_TERMINATE; capbuf[0] = 0x0000; capbuf[1] = 0x1000; /* set bit 12 */ if (ACPI_SUCCESS(acpi_run_osc(handle, &osc_context))) { if (osc_context.ret.pointer && osc_context.ret.length > 1) { u32 *capbuf_ret = osc_context.ret.pointer; if (capbuf_ret[1] & 0x1000) { acpi_handle_info(handle, "_OSC native thermal LVT Acked "); acpi_hwp_native_thermal_lvt_set = true; } } kfree(osc_context.ret.pointer); } return AE_OK; } void __init acpi_early_processor_osc(void) { if (boot_cpu_has(X86_FEATURE_HWP)) { acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_hwp_native_thermal_lvt_osc, NULL, NULL, NULL); acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, acpi_hwp_native_thermal_lvt_osc, NULL, NULL); } } #endif |
ac212b698 ACPI / processor:... |
546 547 548 549 550 551 552 553 554 555 556 |
/* * The following ACPI IDs are known to be suitable for representing as * processor devices. */ static const struct acpi_device_id processor_device_ids[] = { { ACPI_PROCESSOR_OBJECT_HID, }, { ACPI_PROCESSOR_DEVICE_HID, }, { } }; |
8ce344c66 ACPI / processor:... |
557 |
static struct acpi_scan_handler processor_handler = { |
ac212b698 ACPI / processor:... |
558 559 560 561 562 563 564 565 566 |
.ids = processor_device_ids, .attach = acpi_processor_add, #ifdef CONFIG_ACPI_HOTPLUG_CPU .detach = acpi_processor_remove, #endif .hotplug = { .enabled = true, }, }; |
db62fda31 ACPI / processor ... |
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
static int acpi_processor_container_attach(struct acpi_device *dev, const struct acpi_device_id *id) { return 1; } static const struct acpi_device_id processor_container_ids[] = { { ACPI_PROCESSOR_CONTAINER_HID, }, { } }; static struct acpi_scan_handler processor_container_handler = { .ids = processor_container_ids, .attach = acpi_processor_container_attach, }; |
8e089eaa1 acpi: Provide mec... |
582 583 584 585 |
/* The number of the unique processor IDs */ static int nr_unique_ids __initdata; /* The number of the duplicate processor IDs */ |
a77d6cd96 acpi/processor: C... |
586 |
static int nr_duplicate_ids; |
8e089eaa1 acpi: Provide mec... |
587 588 589 590 591 592 593 |
/* Used to store the unique processor IDs */ static int unique_processor_ids[] __initdata = { [0 ... NR_CPUS - 1] = -1, }; /* Used to store the duplicate processor IDs */ |
a77d6cd96 acpi/processor: C... |
594 |
static int duplicate_processor_ids[] = { |
8e089eaa1 acpi: Provide mec... |
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
[0 ... NR_CPUS - 1] = -1, }; static void __init processor_validated_ids_update(int proc_id) { int i; if (nr_unique_ids == NR_CPUS||nr_duplicate_ids == NR_CPUS) return; /* * Firstly, compare the proc_id with duplicate IDs, if the proc_id is * already in the IDs, do nothing. */ for (i = 0; i < nr_duplicate_ids; i++) { if (duplicate_processor_ids[i] == proc_id) return; } /* * Secondly, compare the proc_id with unique IDs, if the proc_id is in * the IDs, put it in the duplicate IDs. */ for (i = 0; i < nr_unique_ids; i++) { if (unique_processor_ids[i] == proc_id) { duplicate_processor_ids[nr_duplicate_ids] = proc_id; nr_duplicate_ids++; return; } } /* * Lastly, the proc_id is a unique ID, put it in the unique IDs. */ unique_processor_ids[nr_unique_ids] = proc_id; nr_unique_ids++; } static acpi_status __init acpi_processor_ids_walk(acpi_handle handle, u32 lvl, void *context, void **rv) { acpi_status status; |
8c8cb30f4 acpi/processor: I... |
639 640 |
acpi_object_type acpi_type; unsigned long long uid; |
8e089eaa1 acpi: Provide mec... |
641 642 |
union acpi_object object = { 0 }; struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; |
8c8cb30f4 acpi/processor: I... |
643 |
status = acpi_get_type(handle, &acpi_type); |
8e089eaa1 acpi: Provide mec... |
644 |
if (ACPI_FAILURE(status)) |
d0381bf4f ACPI / processor:... |
645 |
return status; |
8c8cb30f4 acpi/processor: I... |
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
switch (acpi_type) { case ACPI_TYPE_PROCESSOR: status = acpi_evaluate_object(handle, NULL, NULL, &buffer); if (ACPI_FAILURE(status)) goto err; uid = object.processor.proc_id; break; case ACPI_TYPE_DEVICE: status = acpi_evaluate_integer(handle, "_UID", NULL, &uid); if (ACPI_FAILURE(status)) goto err; break; default: goto err; } processor_validated_ids_update(uid); |
d0381bf4f ACPI / processor:... |
665 |
return AE_OK; |
8c8cb30f4 acpi/processor: I... |
666 667 |
err: |
d0381bf4f ACPI / processor:... |
668 |
/* Exit on error, but don't abort the namespace walk */ |
8c8cb30f4 acpi/processor: I... |
669 670 |
acpi_handle_info(handle, "Invalid processor object "); |
d0381bf4f ACPI / processor:... |
671 |
return AE_OK; |
8e089eaa1 acpi: Provide mec... |
672 |
|
8e089eaa1 acpi: Provide mec... |
673 |
} |
0ed780e31 ACPI / processor:... |
674 |
static void __init acpi_processor_check_duplicates(void) |
8e089eaa1 acpi: Provide mec... |
675 |
{ |
8c8cb30f4 acpi/processor: I... |
676 |
/* check the correctness for all processors in ACPI namespace */ |
8e089eaa1 acpi: Provide mec... |
677 678 679 680 |
acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_processor_ids_walk, NULL, NULL, NULL); |
8c8cb30f4 acpi/processor: I... |
681 682 |
acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, acpi_processor_ids_walk, NULL, NULL); |
8e089eaa1 acpi: Provide mec... |
683 |
} |
a77d6cd96 acpi/processor: C... |
684 |
bool acpi_duplicate_processor_id(int proc_id) |
fd74da217 acpi: Validate pr... |
685 686 687 688 689 690 691 692 693 694 695 696 697 |
{ int i; /* * compare the proc_id with duplicate IDs, if the proc_id is already * in the duplicate IDs, return true, otherwise, return false. */ for (i = 0; i < nr_duplicate_ids; i++) { if (duplicate_processor_ids[i] == proc_id) return true; } return false; } |
ac212b698 ACPI / processor:... |
698 699 |
void __init acpi_processor_init(void) { |
8e089eaa1 acpi: Provide mec... |
700 |
acpi_processor_check_duplicates(); |
ac212b698 ACPI / processor:... |
701 |
acpi_scan_add_handler_with_hotplug(&processor_handler, "processor"); |
db62fda31 ACPI / processor ... |
702 |
acpi_scan_add_handler(&processor_container_handler); |
ac212b698 ACPI / processor:... |
703 |
} |
bc9463888 ACPI: processor: ... |
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
#ifdef CONFIG_ACPI_PROCESSOR_CSTATE /** * acpi_processor_claim_cst_control - Request _CST control from the platform. */ bool acpi_processor_claim_cst_control(void) { static bool cst_control_claimed; acpi_status status; if (!acpi_gbl_FADT.cst_control || cst_control_claimed) return true; status = acpi_os_write_port(acpi_gbl_FADT.smi_command, acpi_gbl_FADT.cst_control, 8); if (ACPI_FAILURE(status)) { pr_warn("ACPI: Failed to claim processor _CST control "); return false; } cst_control_claimed = true; return true; } EXPORT_SYMBOL_GPL(acpi_processor_claim_cst_control); |
77fb4e0a5 ACPI: processor: ... |
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
/** * acpi_processor_evaluate_cst - Evaluate the processor _CST control method. * @handle: ACPI handle of the processor object containing the _CST. * @cpu: The numeric ID of the target CPU. * @info: Object write the C-states information into. * * Extract the C-state information for the given CPU from the output of the _CST * control method under the corresponding ACPI processor object (or processor * device object) and populate @info with it. * * If any ACPI_ADR_SPACE_FIXED_HARDWARE C-states are found, invoke * acpi_processor_ffh_cstate_probe() to verify them and update the * cpu_cstate_entry data for @cpu. */ int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, struct acpi_processor_power *info) { struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *cst; acpi_status status; u64 count; int last_index = 0; int i, ret = 0; status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); if (ACPI_FAILURE(status)) { acpi_handle_debug(handle, "No _CST "); return -ENODEV; } cst = buffer.pointer; /* There must be at least 2 elements. */ if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) { acpi_handle_warn(handle, "Invalid _CST output "); ret = -EFAULT; goto end; } count = cst->package.elements[0].integer.value; /* Validate the number of C-states. */ if (count < 1 || count != cst->package.count - 1) { acpi_handle_warn(handle, "Inconsistent _CST data "); ret = -EFAULT; goto end; } for (i = 1; i <= count; i++) { union acpi_object *element; union acpi_object *obj; struct acpi_power_register *reg; struct acpi_processor_cx cx; /* * If there is not enough space for all C-states, skip the * excess ones and log a warning. */ if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) { acpi_handle_warn(handle, "No room for more idle states (limit: %d) ", ACPI_PROCESSOR_MAX_POWER - 1); break; } memset(&cx, 0, sizeof(cx)); element = &cst->package.elements[i]; |
653f68b6e ACPI: processor: ... |
802 803 804 805 |
if (element->type != ACPI_TYPE_PACKAGE) { acpi_handle_info(handle, "_CST C%d type(%x) is not package, skip... ", i, element->type); |
77fb4e0a5 ACPI: processor: ... |
806 |
continue; |
653f68b6e ACPI: processor: ... |
807 |
} |
77fb4e0a5 ACPI: processor: ... |
808 |
|
653f68b6e ACPI: processor: ... |
809 810 811 812 |
if (element->package.count != 4) { acpi_handle_info(handle, "_CST C%d package count(%d) is not 4, skip... ", i, element->package.count); |
77fb4e0a5 ACPI: processor: ... |
813 |
continue; |
653f68b6e ACPI: processor: ... |
814 |
} |
77fb4e0a5 ACPI: processor: ... |
815 816 |
obj = &element->package.elements[0]; |
653f68b6e ACPI: processor: ... |
817 818 819 820 |
if (obj->type != ACPI_TYPE_BUFFER) { acpi_handle_info(handle, "_CST C%d package element[0] type(%x) is not buffer, skip... ", i, obj->type); |
77fb4e0a5 ACPI: processor: ... |
821 |
continue; |
653f68b6e ACPI: processor: ... |
822 |
} |
77fb4e0a5 ACPI: processor: ... |
823 824 825 826 |
reg = (struct acpi_power_register *)obj->buffer.pointer; obj = &element->package.elements[1]; |
653f68b6e ACPI: processor: ... |
827 828 829 830 |
if (obj->type != ACPI_TYPE_INTEGER) { acpi_handle_info(handle, "_CST C[%d] package element[1] type(%x) is not integer, skip... ", i, obj->type); |
77fb4e0a5 ACPI: processor: ... |
831 |
continue; |
653f68b6e ACPI: processor: ... |
832 |
} |
77fb4e0a5 ACPI: processor: ... |
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
cx.type = obj->integer.value; /* * There are known cases in which the _CST output does not * contain C1, so if the type of the first state found is not * C1, leave an empty slot for C1 to be filled in later. */ if (i == 1 && cx.type != ACPI_STATE_C1) last_index = 1; cx.address = reg->address; cx.index = last_index + 1; if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { if (!acpi_processor_ffh_cstate_probe(cpu, &cx, reg)) { /* * In the majority of cases _CST describes C1 as * a FIXED_HARDWARE C-state, but if the command * line forbids using MWAIT, use CSTATE_HALT for * C1 regardless. */ if (cx.type == ACPI_STATE_C1 && boot_option_idle_override == IDLE_NOMWAIT) { cx.entry_method = ACPI_CSTATE_HALT; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); } else { cx.entry_method = ACPI_CSTATE_FFH; } } else if (cx.type == ACPI_STATE_C1) { /* * In the special case of C1, FIXED_HARDWARE can * be handled by executing the HLT instruction. */ cx.entry_method = ACPI_CSTATE_HALT; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); } else { |
653f68b6e ACPI: processor: ... |
869 870 871 |
acpi_handle_info(handle, "_CST C%d declares FIXED_HARDWARE C-state but not supported in hardware, skip... ", i); |
77fb4e0a5 ACPI: processor: ... |
872 873 874 875 876 877 878 |
continue; } } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { cx.entry_method = ACPI_CSTATE_SYSTEMIO; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", cx.address); } else { |
653f68b6e ACPI: processor: ... |
879 880 881 |
acpi_handle_info(handle, "_CST C%d space_id(%x) neither FIXED_HARDWARE nor SYSTEM_IO, skip... ", i, reg->space_id); |
77fb4e0a5 ACPI: processor: ... |
882 883 884 885 886 887 888 |
continue; } if (cx.type == ACPI_STATE_C1) cx.valid = 1; obj = &element->package.elements[2]; |
653f68b6e ACPI: processor: ... |
889 890 891 892 |
if (obj->type != ACPI_TYPE_INTEGER) { acpi_handle_info(handle, "_CST C%d package element[2] type(%x) not integer, skip... ", i, obj->type); |
77fb4e0a5 ACPI: processor: ... |
893 |
continue; |
653f68b6e ACPI: processor: ... |
894 |
} |
77fb4e0a5 ACPI: processor: ... |
895 896 897 898 |
cx.latency = obj->integer.value; obj = &element->package.elements[3]; |
653f68b6e ACPI: processor: ... |
899 900 901 902 |
if (obj->type != ACPI_TYPE_INTEGER) { acpi_handle_info(handle, "_CST C%d package element[3] type(%x) not integer, skip... ", i, obj->type); |
77fb4e0a5 ACPI: processor: ... |
903 |
continue; |
653f68b6e ACPI: processor: ... |
904 |
} |
77fb4e0a5 ACPI: processor: ... |
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
memcpy(&info->states[++last_index], &cx, sizeof(cx)); } acpi_handle_info(handle, "Found %d idle states ", last_index); info->count = last_index; end: kfree(buffer.pointer); return ret; } EXPORT_SYMBOL_GPL(acpi_processor_evaluate_cst); |
bc9463888 ACPI: processor: ... |
920 |
#endif /* CONFIG_ACPI_PROCESSOR_CSTATE */ |