diff options
Diffstat (limited to 'arch/x86/kernel/cpu')
51 files changed, 2273 insertions, 12055 deletions
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 3f0ebe429a01..6042981d0309 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile | |||
@@ -30,7 +30,6 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o | |||
30 | 30 | ||
31 | obj-$(CONFIG_X86_MCE) += mcheck/ | 31 | obj-$(CONFIG_X86_MCE) += mcheck/ |
32 | obj-$(CONFIG_MTRR) += mtrr/ | 32 | obj-$(CONFIG_MTRR) += mtrr/ |
33 | obj-$(CONFIG_CPU_FREQ) += cpufreq/ | ||
34 | 33 | ||
35 | obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o | 34 | obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o |
36 | 35 | ||
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index ba5f62f45f01..b13ed393dfce 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c | |||
@@ -148,7 +148,7 @@ static void __cpuinit amd_k7_smp_check(struct cpuinfo_x86 *c) | |||
148 | { | 148 | { |
149 | #ifdef CONFIG_SMP | 149 | #ifdef CONFIG_SMP |
150 | /* calling is from identify_secondary_cpu() ? */ | 150 | /* calling is from identify_secondary_cpu() ? */ |
151 | if (c->cpu_index == boot_cpu_id) | 151 | if (!c->cpu_index) |
152 | return; | 152 | return; |
153 | 153 | ||
154 | /* | 154 | /* |
@@ -233,18 +233,22 @@ static void __cpuinit init_amd_k7(struct cpuinfo_x86 *c) | |||
233 | } | 233 | } |
234 | #endif | 234 | #endif |
235 | 235 | ||
236 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) | 236 | #ifdef CONFIG_NUMA |
237 | /* | ||
238 | * To workaround broken NUMA config. Read the comment in | ||
239 | * srat_detect_node(). | ||
240 | */ | ||
237 | static int __cpuinit nearby_node(int apicid) | 241 | static int __cpuinit nearby_node(int apicid) |
238 | { | 242 | { |
239 | int i, node; | 243 | int i, node; |
240 | 244 | ||
241 | for (i = apicid - 1; i >= 0; i--) { | 245 | for (i = apicid - 1; i >= 0; i--) { |
242 | node = apicid_to_node[i]; | 246 | node = __apicid_to_node[i]; |
243 | if (node != NUMA_NO_NODE && node_online(node)) | 247 | if (node != NUMA_NO_NODE && node_online(node)) |
244 | return node; | 248 | return node; |
245 | } | 249 | } |
246 | for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) { | 250 | for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) { |
247 | node = apicid_to_node[i]; | 251 | node = __apicid_to_node[i]; |
248 | if (node != NUMA_NO_NODE && node_online(node)) | 252 | if (node != NUMA_NO_NODE && node_online(node)) |
249 | return node; | 253 | return node; |
250 | } | 254 | } |
@@ -253,37 +257,55 @@ static int __cpuinit nearby_node(int apicid) | |||
253 | #endif | 257 | #endif |
254 | 258 | ||
255 | /* | 259 | /* |
256 | * Fixup core topology information for AMD multi-node processors. | 260 | * Fixup core topology information for |
257 | * Assumption: Number of cores in each internal node is the same. | 261 | * (1) AMD multi-node processors |
262 | * Assumption: Number of cores in each internal node is the same. | ||
263 | * (2) AMD processors supporting compute units | ||
258 | */ | 264 | */ |
259 | #ifdef CONFIG_X86_HT | 265 | #ifdef CONFIG_X86_HT |
260 | static void __cpuinit amd_fixup_dcm(struct cpuinfo_x86 *c) | 266 | static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) |
261 | { | 267 | { |
262 | unsigned long long value; | 268 | u32 nodes, cores_per_cu = 1; |
263 | u32 nodes, cores_per_node; | 269 | u8 node_id; |
264 | int cpu = smp_processor_id(); | 270 | int cpu = smp_processor_id(); |
265 | 271 | ||
266 | if (!cpu_has(c, X86_FEATURE_NODEID_MSR)) | 272 | /* get information required for multi-node processors */ |
267 | return; | 273 | if (cpu_has(c, X86_FEATURE_TOPOEXT)) { |
268 | 274 | u32 eax, ebx, ecx, edx; | |
269 | /* fixup topology information only once for a core */ | 275 | |
270 | if (cpu_has(c, X86_FEATURE_AMD_DCM)) | 276 | cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); |
277 | nodes = ((ecx >> 8) & 7) + 1; | ||
278 | node_id = ecx & 7; | ||
279 | |||
280 | /* get compute unit information */ | ||
281 | smp_num_siblings = ((ebx >> 8) & 3) + 1; | ||
282 | c->compute_unit_id = ebx & 0xff; | ||
283 | cores_per_cu += ((ebx >> 8) & 3); | ||
284 | } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { | ||
285 | u64 value; | ||
286 | |||
287 | rdmsrl(MSR_FAM10H_NODE_ID, value); | ||
288 | nodes = ((value >> 3) & 7) + 1; | ||
289 | node_id = value & 7; | ||
290 | } else | ||
271 | return; | 291 | return; |
272 | 292 | ||
273 | rdmsrl(MSR_FAM10H_NODE_ID, value); | 293 | /* fixup multi-node processor information */ |
274 | 294 | if (nodes > 1) { | |
275 | nodes = ((value >> 3) & 7) + 1; | 295 | u32 cores_per_node; |
276 | if (nodes == 1) | 296 | u32 cus_per_node; |
277 | return; | ||
278 | 297 | ||
279 | set_cpu_cap(c, X86_FEATURE_AMD_DCM); | 298 | set_cpu_cap(c, X86_FEATURE_AMD_DCM); |
280 | cores_per_node = c->x86_max_cores / nodes; | 299 | cores_per_node = c->x86_max_cores / nodes; |
300 | cus_per_node = cores_per_node / cores_per_cu; | ||
281 | 301 | ||
282 | /* store NodeID, use llc_shared_map to store sibling info */ | 302 | /* store NodeID, use llc_shared_map to store sibling info */ |
283 | per_cpu(cpu_llc_id, cpu) = value & 7; | 303 | per_cpu(cpu_llc_id, cpu) = node_id; |
284 | 304 | ||
285 | /* fixup core id to be in range from 0 to (cores_per_node - 1) */ | 305 | /* core id has to be in the [0 .. cores_per_node - 1] range */ |
286 | c->cpu_core_id = c->cpu_core_id % cores_per_node; | 306 | c->cpu_core_id %= cores_per_node; |
307 | c->compute_unit_id %= cus_per_node; | ||
308 | } | ||
287 | } | 309 | } |
288 | #endif | 310 | #endif |
289 | 311 | ||
@@ -304,9 +326,7 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c) | |||
304 | c->phys_proc_id = c->initial_apicid >> bits; | 326 | c->phys_proc_id = c->initial_apicid >> bits; |
305 | /* use socket ID also for last level cache */ | 327 | /* use socket ID also for last level cache */ |
306 | per_cpu(cpu_llc_id, cpu) = c->phys_proc_id; | 328 | per_cpu(cpu_llc_id, cpu) = c->phys_proc_id; |
307 | /* fixup topology information on multi-node processors */ | 329 | amd_get_topology(c); |
308 | if ((c->x86 == 0x10) && (c->x86_model == 9)) | ||
309 | amd_fixup_dcm(c); | ||
310 | #endif | 330 | #endif |
311 | } | 331 | } |
312 | 332 | ||
@@ -322,31 +342,40 @@ EXPORT_SYMBOL_GPL(amd_get_nb_id); | |||
322 | 342 | ||
323 | static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) | 343 | static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) |
324 | { | 344 | { |
325 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) | 345 | #ifdef CONFIG_NUMA |
326 | int cpu = smp_processor_id(); | 346 | int cpu = smp_processor_id(); |
327 | int node; | 347 | int node; |
328 | unsigned apicid = c->apicid; | 348 | unsigned apicid = c->apicid; |
329 | 349 | ||
330 | node = per_cpu(cpu_llc_id, cpu); | 350 | node = numa_cpu_node(cpu); |
351 | if (node == NUMA_NO_NODE) | ||
352 | node = per_cpu(cpu_llc_id, cpu); | ||
331 | 353 | ||
332 | if (apicid_to_node[apicid] != NUMA_NO_NODE) | ||
333 | node = apicid_to_node[apicid]; | ||
334 | if (!node_online(node)) { | 354 | if (!node_online(node)) { |
335 | /* Two possibilities here: | 355 | /* |
336 | - The CPU is missing memory and no node was created. | 356 | * Two possibilities here: |
337 | In that case try picking one from a nearby CPU | 357 | * |
338 | - The APIC IDs differ from the HyperTransport node IDs | 358 | * - The CPU is missing memory and no node was created. In |
339 | which the K8 northbridge parsing fills in. | 359 | * that case try picking one from a nearby CPU. |
340 | Assume they are all increased by a constant offset, | 360 | * |
341 | but in the same order as the HT nodeids. | 361 | * - The APIC IDs differ from the HyperTransport node IDs |
342 | If that doesn't result in a usable node fall back to the | 362 | * which the K8 northbridge parsing fills in. Assume |
343 | path for the previous case. */ | 363 | * they are all increased by a constant offset, but in |
344 | 364 | * the same order as the HT nodeids. If that doesn't | |
365 | * result in a usable node fall back to the path for the | ||
366 | * previous case. | ||
367 | * | ||
368 | * This workaround operates directly on the mapping between | ||
369 | * APIC ID and NUMA node, assuming certain relationship | ||
370 | * between APIC ID, HT node ID and NUMA topology. As going | ||
371 | * through CPU mapping may alter the outcome, directly | ||
372 | * access __apicid_to_node[]. | ||
373 | */ | ||
345 | int ht_nodeid = c->initial_apicid; | 374 | int ht_nodeid = c->initial_apicid; |
346 | 375 | ||
347 | if (ht_nodeid >= 0 && | 376 | if (ht_nodeid >= 0 && |
348 | apicid_to_node[ht_nodeid] != NUMA_NO_NODE) | 377 | __apicid_to_node[ht_nodeid] != NUMA_NO_NODE) |
349 | node = apicid_to_node[ht_nodeid]; | 378 | node = __apicid_to_node[ht_nodeid]; |
350 | /* Pick a nearby node */ | 379 | /* Pick a nearby node */ |
351 | if (!node_online(node)) | 380 | if (!node_online(node)) |
352 | node = nearby_node(apicid); | 381 | node = nearby_node(apicid); |
@@ -412,6 +441,23 @@ static void __cpuinit early_init_amd(struct cpuinfo_x86 *c) | |||
412 | set_cpu_cap(c, X86_FEATURE_EXTD_APICID); | 441 | set_cpu_cap(c, X86_FEATURE_EXTD_APICID); |
413 | } | 442 | } |
414 | #endif | 443 | #endif |
444 | |||
445 | /* We need to do the following only once */ | ||
446 | if (c != &boot_cpu_data) | ||
447 | return; | ||
448 | |||
449 | if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { | ||
450 | |||
451 | if (c->x86 > 0x10 || | ||
452 | (c->x86 == 0x10 && c->x86_model >= 0x2)) { | ||
453 | u64 val; | ||
454 | |||
455 | rdmsrl(MSR_K7_HWCR, val); | ||
456 | if (!(val & BIT(24))) | ||
457 | printk(KERN_WARNING FW_BUG "TSC doesn't count " | ||
458 | "with P0 frequency!\n"); | ||
459 | } | ||
460 | } | ||
415 | } | 461 | } |
416 | 462 | ||
417 | static void __cpuinit init_amd(struct cpuinfo_x86 *c) | 463 | static void __cpuinit init_amd(struct cpuinfo_x86 *c) |
@@ -523,7 +569,7 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c) | |||
523 | #endif | 569 | #endif |
524 | 570 | ||
525 | if (c->extended_cpuid_level >= 0x80000006) { | 571 | if (c->extended_cpuid_level >= 0x80000006) { |
526 | if ((c->x86 >= 0x0f) && (cpuid_edx(0x80000006) & 0xf000)) | 572 | if (cpuid_edx(0x80000006) & 0xf000) |
527 | num_cache_leaves = 4; | 573 | num_cache_leaves = 4; |
528 | else | 574 | else |
529 | num_cache_leaves = 3; | 575 | num_cache_leaves = 3; |
@@ -565,6 +611,35 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c) | |||
565 | } | 611 | } |
566 | } | 612 | } |
567 | #endif | 613 | #endif |
614 | |||
615 | /* | ||
616 | * Family 0x12 and above processors have APIC timer | ||
617 | * running in deep C states. | ||
618 | */ | ||
619 | if (c->x86 > 0x11) | ||
620 | set_cpu_cap(c, X86_FEATURE_ARAT); | ||
621 | |||
622 | /* | ||
623 | * Disable GART TLB Walk Errors on Fam10h. We do this here | ||
624 | * because this is always needed when GART is enabled, even in a | ||
625 | * kernel which has no MCE support built in. | ||
626 | */ | ||
627 | if (c->x86 == 0x10) { | ||
628 | /* | ||
629 | * BIOS should disable GartTlbWlk Errors themself. If | ||
630 | * it doesn't do it here as suggested by the BKDG. | ||
631 | * | ||
632 | * Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=33012 | ||
633 | */ | ||
634 | u64 mask; | ||
635 | int err; | ||
636 | |||
637 | err = rdmsrl_safe(MSR_AMD64_MCx_MASK(4), &mask); | ||
638 | if (err == 0) { | ||
639 | mask |= (1 << 10); | ||
640 | checking_wrmsrl(MSR_AMD64_MCx_MASK(4), mask); | ||
641 | } | ||
642 | } | ||
568 | } | 643 | } |
569 | 644 | ||
570 | #ifdef CONFIG_X86_32 | 645 | #ifdef CONFIG_X86_32 |
@@ -639,7 +714,7 @@ EXPORT_SYMBOL_GPL(amd_erratum_383); | |||
639 | 714 | ||
640 | bool cpu_has_amd_erratum(const int *erratum) | 715 | bool cpu_has_amd_erratum(const int *erratum) |
641 | { | 716 | { |
642 | struct cpuinfo_x86 *cpu = ¤t_cpu_data; | 717 | struct cpuinfo_x86 *cpu = __this_cpu_ptr(&cpu_info); |
643 | int osvw_id = *erratum++; | 718 | int osvw_id = *erratum++; |
644 | u32 range; | 719 | u32 range; |
645 | u32 ms; | 720 | u32 ms; |
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index c39576cb3018..525514cf33c3 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | static int __init no_halt(char *s) | 20 | static int __init no_halt(char *s) |
21 | { | 21 | { |
22 | WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n"); | ||
22 | boot_cpu_data.hlt_works_ok = 0; | 23 | boot_cpu_data.hlt_works_ok = 0; |
23 | return 1; | 24 | return 1; |
24 | } | 25 | } |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index f2f9ac7da25c..22a073d7fbff 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -254,6 +254,25 @@ static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) | |||
254 | } | 254 | } |
255 | #endif | 255 | #endif |
256 | 256 | ||
257 | static int disable_smep __cpuinitdata; | ||
258 | static __init int setup_disable_smep(char *arg) | ||
259 | { | ||
260 | disable_smep = 1; | ||
261 | return 1; | ||
262 | } | ||
263 | __setup("nosmep", setup_disable_smep); | ||
264 | |||
265 | static __cpuinit void setup_smep(struct cpuinfo_x86 *c) | ||
266 | { | ||
267 | if (cpu_has(c, X86_FEATURE_SMEP)) { | ||
268 | if (unlikely(disable_smep)) { | ||
269 | setup_clear_cpu_cap(X86_FEATURE_SMEP); | ||
270 | clear_in_cr4(X86_CR4_SMEP); | ||
271 | } else | ||
272 | set_in_cr4(X86_CR4_SMEP); | ||
273 | } | ||
274 | } | ||
275 | |||
257 | /* | 276 | /* |
258 | * Some CPU features depend on higher CPUID levels, which may not always | 277 | * Some CPU features depend on higher CPUID levels, which may not always |
259 | * be available due to CPUID level capping or broken virtualization | 278 | * be available due to CPUID level capping or broken virtualization |
@@ -458,13 +477,6 @@ void __cpuinit detect_ht(struct cpuinfo_x86 *c) | |||
458 | if (smp_num_siblings <= 1) | 477 | if (smp_num_siblings <= 1) |
459 | goto out; | 478 | goto out; |
460 | 479 | ||
461 | if (smp_num_siblings > nr_cpu_ids) { | ||
462 | pr_warning("CPU: Unsupported number of siblings %d", | ||
463 | smp_num_siblings); | ||
464 | smp_num_siblings = 1; | ||
465 | return; | ||
466 | } | ||
467 | |||
468 | index_msb = get_count_order(smp_num_siblings); | 480 | index_msb = get_count_order(smp_num_siblings); |
469 | c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb); | 481 | c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb); |
470 | 482 | ||
@@ -565,8 +577,7 @@ void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c) | |||
565 | 577 | ||
566 | cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); | 578 | cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); |
567 | 579 | ||
568 | if (eax > 0) | 580 | c->x86_capability[9] = ebx; |
569 | c->x86_capability[9] = ebx; | ||
570 | } | 581 | } |
571 | 582 | ||
572 | /* AMD-defined flags: level 0x80000001 */ | 583 | /* AMD-defined flags: level 0x80000001 */ |
@@ -665,9 +676,11 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) | |||
665 | this_cpu->c_early_init(c); | 676 | this_cpu->c_early_init(c); |
666 | 677 | ||
667 | #ifdef CONFIG_SMP | 678 | #ifdef CONFIG_SMP |
668 | c->cpu_index = boot_cpu_id; | 679 | c->cpu_index = 0; |
669 | #endif | 680 | #endif |
670 | filter_cpuid_features(c, false); | 681 | filter_cpuid_features(c, false); |
682 | |||
683 | setup_smep(c); | ||
671 | } | 684 | } |
672 | 685 | ||
673 | void __init early_cpu_init(void) | 686 | void __init early_cpu_init(void) |
@@ -675,7 +688,7 @@ void __init early_cpu_init(void) | |||
675 | const struct cpu_dev *const *cdev; | 688 | const struct cpu_dev *const *cdev; |
676 | int count = 0; | 689 | int count = 0; |
677 | 690 | ||
678 | #ifdef PROCESSOR_SELECT | 691 | #ifdef CONFIG_PROCESSOR_SELECT |
679 | printk(KERN_INFO "KERNEL supported cpus:\n"); | 692 | printk(KERN_INFO "KERNEL supported cpus:\n"); |
680 | #endif | 693 | #endif |
681 | 694 | ||
@@ -687,7 +700,7 @@ void __init early_cpu_init(void) | |||
687 | cpu_devs[count] = cpudev; | 700 | cpu_devs[count] = cpudev; |
688 | count++; | 701 | count++; |
689 | 702 | ||
690 | #ifdef PROCESSOR_SELECT | 703 | #ifdef CONFIG_PROCESSOR_SELECT |
691 | { | 704 | { |
692 | unsigned int j; | 705 | unsigned int j; |
693 | 706 | ||
@@ -704,16 +717,21 @@ void __init early_cpu_init(void) | |||
704 | } | 717 | } |
705 | 718 | ||
706 | /* | 719 | /* |
707 | * The NOPL instruction is supposed to exist on all CPUs with | 720 | * The NOPL instruction is supposed to exist on all CPUs of family >= 6; |
708 | * family >= 6; unfortunately, that's not true in practice because | 721 | * unfortunately, that's not true in practice because of early VIA |
709 | * of early VIA chips and (more importantly) broken virtualizers that | 722 | * chips and (more importantly) broken virtualizers that are not easy |
710 | * are not easy to detect. In the latter case it doesn't even *fail* | 723 | * to detect. In the latter case it doesn't even *fail* reliably, so |
711 | * reliably, so probing for it doesn't even work. Disable it completely | 724 | * probing for it doesn't even work. Disable it completely on 32-bit |
712 | * unless we can find a reliable way to detect all the broken cases. | 725 | * unless we can find a reliable way to detect all the broken cases. |
726 | * Enable it explicitly on 64-bit for non-constant inputs of cpu_has(). | ||
713 | */ | 727 | */ |
714 | static void __cpuinit detect_nopl(struct cpuinfo_x86 *c) | 728 | static void __cpuinit detect_nopl(struct cpuinfo_x86 *c) |
715 | { | 729 | { |
730 | #ifdef CONFIG_X86_32 | ||
716 | clear_cpu_cap(c, X86_FEATURE_NOPL); | 731 | clear_cpu_cap(c, X86_FEATURE_NOPL); |
732 | #else | ||
733 | set_cpu_cap(c, X86_FEATURE_NOPL); | ||
734 | #endif | ||
717 | } | 735 | } |
718 | 736 | ||
719 | static void __cpuinit generic_identify(struct cpuinfo_x86 *c) | 737 | static void __cpuinit generic_identify(struct cpuinfo_x86 *c) |
@@ -748,6 +766,8 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c) | |||
748 | #endif | 766 | #endif |
749 | } | 767 | } |
750 | 768 | ||
769 | setup_smep(c); | ||
770 | |||
751 | get_model_name(c); /* Default name */ | 771 | get_model_name(c); /* Default name */ |
752 | 772 | ||
753 | detect_nopl(c); | 773 | detect_nopl(c); |
@@ -864,7 +884,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) | |||
864 | 884 | ||
865 | select_idle_routine(c); | 885 | select_idle_routine(c); |
866 | 886 | ||
867 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) | 887 | #ifdef CONFIG_NUMA |
868 | numa_add_cpu(smp_processor_id()); | 888 | numa_add_cpu(smp_processor_id()); |
869 | #endif | 889 | #endif |
870 | } | 890 | } |
@@ -882,14 +902,13 @@ static void vgetcpu_set_mode(void) | |||
882 | void __init identify_boot_cpu(void) | 902 | void __init identify_boot_cpu(void) |
883 | { | 903 | { |
884 | identify_cpu(&boot_cpu_data); | 904 | identify_cpu(&boot_cpu_data); |
885 | init_c1e_mask(); | 905 | init_amd_e400_c1e_mask(); |
886 | #ifdef CONFIG_X86_32 | 906 | #ifdef CONFIG_X86_32 |
887 | sysenter_setup(); | 907 | sysenter_setup(); |
888 | enable_sep_cpu(); | 908 | enable_sep_cpu(); |
889 | #else | 909 | #else |
890 | vgetcpu_set_mode(); | 910 | vgetcpu_set_mode(); |
891 | #endif | 911 | #endif |
892 | init_hw_perf_events(); | ||
893 | } | 912 | } |
894 | 913 | ||
895 | void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c) | 914 | void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c) |
@@ -1264,13 +1283,6 @@ void __cpuinit cpu_init(void) | |||
1264 | clear_all_debug_regs(); | 1283 | clear_all_debug_regs(); |
1265 | dbg_restore_debug_regs(); | 1284 | dbg_restore_debug_regs(); |
1266 | 1285 | ||
1267 | /* | ||
1268 | * Force FPU initialization: | ||
1269 | */ | ||
1270 | current_thread_info()->status = 0; | ||
1271 | clear_used_math(); | ||
1272 | mxcsr_feature_mask_init(); | ||
1273 | |||
1274 | fpu_init(); | 1286 | fpu_init(); |
1275 | xsave_init(); | 1287 | xsave_init(); |
1276 | } | 1288 | } |
diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index f668bb1f7d43..e765633f210e 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h | |||
@@ -32,6 +32,7 @@ struct cpu_dev { | |||
32 | extern const struct cpu_dev *const __x86_cpu_dev_start[], | 32 | extern const struct cpu_dev *const __x86_cpu_dev_start[], |
33 | *const __x86_cpu_dev_end[]; | 33 | *const __x86_cpu_dev_end[]; |
34 | 34 | ||
35 | extern void get_cpu_cap(struct cpuinfo_x86 *c); | ||
35 | extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c); | 36 | extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c); |
36 | extern void get_cpu_cap(struct cpuinfo_x86 *c); | 37 | extern void get_cpu_cap(struct cpuinfo_x86 *c); |
37 | 38 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/Kconfig b/arch/x86/kernel/cpu/cpufreq/Kconfig deleted file mode 100644 index 870e6cc6ad28..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/Kconfig +++ /dev/null | |||
@@ -1,266 +0,0 @@ | |||
1 | # | ||
2 | # CPU Frequency scaling | ||
3 | # | ||
4 | |||
5 | menu "CPU Frequency scaling" | ||
6 | |||
7 | source "drivers/cpufreq/Kconfig" | ||
8 | |||
9 | if CPU_FREQ | ||
10 | |||
11 | comment "CPUFreq processor drivers" | ||
12 | |||
13 | config X86_PCC_CPUFREQ | ||
14 | tristate "Processor Clocking Control interface driver" | ||
15 | depends on ACPI && ACPI_PROCESSOR | ||
16 | help | ||
17 | This driver adds support for the PCC interface. | ||
18 | |||
19 | For details, take a look at: | ||
20 | <file:Documentation/cpu-freq/pcc-cpufreq.txt>. | ||
21 | |||
22 | To compile this driver as a module, choose M here: the | ||
23 | module will be called pcc-cpufreq. | ||
24 | |||
25 | If in doubt, say N. | ||
26 | |||
27 | config X86_ACPI_CPUFREQ | ||
28 | tristate "ACPI Processor P-States driver" | ||
29 | select CPU_FREQ_TABLE | ||
30 | depends on ACPI_PROCESSOR | ||
31 | help | ||
32 | This driver adds a CPUFreq driver which utilizes the ACPI | ||
33 | Processor Performance States. | ||
34 | This driver also supports Intel Enhanced Speedstep. | ||
35 | |||
36 | To compile this driver as a module, choose M here: the | ||
37 | module will be called acpi-cpufreq. | ||
38 | |||
39 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
40 | |||
41 | If in doubt, say N. | ||
42 | |||
43 | config ELAN_CPUFREQ | ||
44 | tristate "AMD Elan SC400 and SC410" | ||
45 | select CPU_FREQ_TABLE | ||
46 | depends on X86_ELAN | ||
47 | ---help--- | ||
48 | This adds the CPUFreq driver for AMD Elan SC400 and SC410 | ||
49 | processors. | ||
50 | |||
51 | You need to specify the processor maximum speed as boot | ||
52 | parameter: elanfreq=maxspeed (in kHz) or as module | ||
53 | parameter "max_freq". | ||
54 | |||
55 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
56 | |||
57 | If in doubt, say N. | ||
58 | |||
59 | config SC520_CPUFREQ | ||
60 | tristate "AMD Elan SC520" | ||
61 | select CPU_FREQ_TABLE | ||
62 | depends on X86_ELAN | ||
63 | ---help--- | ||
64 | This adds the CPUFreq driver for AMD Elan SC520 processor. | ||
65 | |||
66 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
67 | |||
68 | If in doubt, say N. | ||
69 | |||
70 | |||
71 | config X86_POWERNOW_K6 | ||
72 | tristate "AMD Mobile K6-2/K6-3 PowerNow!" | ||
73 | select CPU_FREQ_TABLE | ||
74 | depends on X86_32 | ||
75 | help | ||
76 | This adds the CPUFreq driver for mobile AMD K6-2+ and mobile | ||
77 | AMD K6-3+ processors. | ||
78 | |||
79 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
80 | |||
81 | If in doubt, say N. | ||
82 | |||
83 | config X86_POWERNOW_K7 | ||
84 | tristate "AMD Mobile Athlon/Duron PowerNow!" | ||
85 | select CPU_FREQ_TABLE | ||
86 | depends on X86_32 | ||
87 | help | ||
88 | This adds the CPUFreq driver for mobile AMD K7 mobile processors. | ||
89 | |||
90 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
91 | |||
92 | If in doubt, say N. | ||
93 | |||
94 | config X86_POWERNOW_K7_ACPI | ||
95 | bool | ||
96 | depends on X86_POWERNOW_K7 && ACPI_PROCESSOR | ||
97 | depends on !(X86_POWERNOW_K7 = y && ACPI_PROCESSOR = m) | ||
98 | depends on X86_32 | ||
99 | default y | ||
100 | |||
101 | config X86_POWERNOW_K8 | ||
102 | tristate "AMD Opteron/Athlon64 PowerNow!" | ||
103 | select CPU_FREQ_TABLE | ||
104 | depends on ACPI && ACPI_PROCESSOR | ||
105 | help | ||
106 | This adds the CPUFreq driver for K8/K10 Opteron/Athlon64 processors. | ||
107 | |||
108 | To compile this driver as a module, choose M here: the | ||
109 | module will be called powernow-k8. | ||
110 | |||
111 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
112 | |||
113 | config X86_GX_SUSPMOD | ||
114 | tristate "Cyrix MediaGX/NatSemi Geode Suspend Modulation" | ||
115 | depends on X86_32 && PCI | ||
116 | help | ||
117 | This add the CPUFreq driver for NatSemi Geode processors which | ||
118 | support suspend modulation. | ||
119 | |||
120 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
121 | |||
122 | If in doubt, say N. | ||
123 | |||
124 | config X86_SPEEDSTEP_CENTRINO | ||
125 | tristate "Intel Enhanced SpeedStep (deprecated)" | ||
126 | select CPU_FREQ_TABLE | ||
127 | select X86_SPEEDSTEP_CENTRINO_TABLE if X86_32 | ||
128 | depends on X86_32 || (X86_64 && ACPI_PROCESSOR) | ||
129 | help | ||
130 | This is deprecated and this functionality is now merged into | ||
131 | acpi_cpufreq (X86_ACPI_CPUFREQ). Use that driver instead of | ||
132 | speedstep_centrino. | ||
133 | This adds the CPUFreq driver for Enhanced SpeedStep enabled | ||
134 | mobile CPUs. This means Intel Pentium M (Centrino) CPUs | ||
135 | or 64bit enabled Intel Xeons. | ||
136 | |||
137 | To compile this driver as a module, choose M here: the | ||
138 | module will be called speedstep-centrino. | ||
139 | |||
140 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
141 | |||
142 | If in doubt, say N. | ||
143 | |||
144 | config X86_SPEEDSTEP_CENTRINO_TABLE | ||
145 | bool "Built-in tables for Banias CPUs" | ||
146 | depends on X86_32 && X86_SPEEDSTEP_CENTRINO | ||
147 | default y | ||
148 | help | ||
149 | Use built-in tables for Banias CPUs if ACPI encoding | ||
150 | is not available. | ||
151 | |||
152 | If in doubt, say N. | ||
153 | |||
154 | config X86_SPEEDSTEP_ICH | ||
155 | tristate "Intel Speedstep on ICH-M chipsets (ioport interface)" | ||
156 | select CPU_FREQ_TABLE | ||
157 | depends on X86_32 | ||
158 | help | ||
159 | This adds the CPUFreq driver for certain mobile Intel Pentium III | ||
160 | (Coppermine), all mobile Intel Pentium III-M (Tualatin) and all | ||
161 | mobile Intel Pentium 4 P4-M on systems which have an Intel ICH2, | ||
162 | ICH3 or ICH4 southbridge. | ||
163 | |||
164 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
165 | |||
166 | If in doubt, say N. | ||
167 | |||
168 | config X86_SPEEDSTEP_SMI | ||
169 | tristate "Intel SpeedStep on 440BX/ZX/MX chipsets (SMI interface)" | ||
170 | select CPU_FREQ_TABLE | ||
171 | depends on X86_32 && EXPERIMENTAL | ||
172 | help | ||
173 | This adds the CPUFreq driver for certain mobile Intel Pentium III | ||
174 | (Coppermine), all mobile Intel Pentium III-M (Tualatin) | ||
175 | on systems which have an Intel 440BX/ZX/MX southbridge. | ||
176 | |||
177 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
178 | |||
179 | If in doubt, say N. | ||
180 | |||
181 | config X86_P4_CLOCKMOD | ||
182 | tristate "Intel Pentium 4 clock modulation" | ||
183 | select CPU_FREQ_TABLE | ||
184 | help | ||
185 | This adds the CPUFreq driver for Intel Pentium 4 / XEON | ||
186 | processors. When enabled it will lower CPU temperature by skipping | ||
187 | clocks. | ||
188 | |||
189 | This driver should be only used in exceptional | ||
190 | circumstances when very low power is needed because it causes severe | ||
191 | slowdowns and noticeable latencies. Normally Speedstep should be used | ||
192 | instead. | ||
193 | |||
194 | To compile this driver as a module, choose M here: the | ||
195 | module will be called p4-clockmod. | ||
196 | |||
197 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
198 | |||
199 | Unless you are absolutely sure say N. | ||
200 | |||
201 | config X86_CPUFREQ_NFORCE2 | ||
202 | tristate "nVidia nForce2 FSB changing" | ||
203 | depends on X86_32 && EXPERIMENTAL | ||
204 | help | ||
205 | This adds the CPUFreq driver for FSB changing on nVidia nForce2 | ||
206 | platforms. | ||
207 | |||
208 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
209 | |||
210 | If in doubt, say N. | ||
211 | |||
212 | config X86_LONGRUN | ||
213 | tristate "Transmeta LongRun" | ||
214 | depends on X86_32 | ||
215 | help | ||
216 | This adds the CPUFreq driver for Transmeta Crusoe and Efficeon processors | ||
217 | which support LongRun. | ||
218 | |||
219 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
220 | |||
221 | If in doubt, say N. | ||
222 | |||
223 | config X86_LONGHAUL | ||
224 | tristate "VIA Cyrix III Longhaul" | ||
225 | select CPU_FREQ_TABLE | ||
226 | depends on X86_32 && ACPI_PROCESSOR | ||
227 | help | ||
228 | This adds the CPUFreq driver for VIA Samuel/CyrixIII, | ||
229 | VIA Cyrix Samuel/C3, VIA Cyrix Ezra and VIA Cyrix Ezra-T | ||
230 | processors. | ||
231 | |||
232 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
233 | |||
234 | If in doubt, say N. | ||
235 | |||
236 | config X86_E_POWERSAVER | ||
237 | tristate "VIA C7 Enhanced PowerSaver (DANGEROUS)" | ||
238 | select CPU_FREQ_TABLE | ||
239 | depends on X86_32 && EXPERIMENTAL | ||
240 | help | ||
241 | This adds the CPUFreq driver for VIA C7 processors. However, this driver | ||
242 | does not have any safeguards to prevent operating the CPU out of spec | ||
243 | and is thus considered dangerous. Please use the regular ACPI cpufreq | ||
244 | driver, enabled by CONFIG_X86_ACPI_CPUFREQ. | ||
245 | |||
246 | If in doubt, say N. | ||
247 | |||
248 | comment "shared options" | ||
249 | |||
250 | config X86_SPEEDSTEP_LIB | ||
251 | tristate | ||
252 | default (X86_SPEEDSTEP_ICH || X86_SPEEDSTEP_SMI || X86_P4_CLOCKMOD) | ||
253 | |||
254 | config X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
255 | bool "Relaxed speedstep capability checks" | ||
256 | depends on X86_32 && (X86_SPEEDSTEP_SMI || X86_SPEEDSTEP_ICH) | ||
257 | help | ||
258 | Don't perform all checks for a speedstep capable system which would | ||
259 | normally be done. Some ancient or strange systems, though speedstep | ||
260 | capable, don't always indicate that they are speedstep capable. This | ||
261 | option lets the probing code bypass some of those checks if the | ||
262 | parameter "relaxed_check=1" is passed to the module. | ||
263 | |||
264 | endif # CPU_FREQ | ||
265 | |||
266 | endmenu | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/Makefile b/arch/x86/kernel/cpu/cpufreq/Makefile deleted file mode 100644 index bd54bf67e6fb..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/Makefile +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | # Link order matters. K8 is preferred to ACPI because of firmware bugs in early | ||
2 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. | ||
3 | # speedstep-* is preferred over p4-clockmod. | ||
4 | |||
5 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o mperf.o | ||
6 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o | ||
7 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o | ||
8 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o | ||
9 | obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o | ||
10 | obj-$(CONFIG_X86_LONGHAUL) += longhaul.o | ||
11 | obj-$(CONFIG_X86_E_POWERSAVER) += e_powersaver.o | ||
12 | obj-$(CONFIG_ELAN_CPUFREQ) += elanfreq.o | ||
13 | obj-$(CONFIG_SC520_CPUFREQ) += sc520_freq.o | ||
14 | obj-$(CONFIG_X86_LONGRUN) += longrun.o | ||
15 | obj-$(CONFIG_X86_GX_SUSPMOD) += gx-suspmod.o | ||
16 | obj-$(CONFIG_X86_SPEEDSTEP_ICH) += speedstep-ich.o | ||
17 | obj-$(CONFIG_X86_SPEEDSTEP_LIB) += speedstep-lib.o | ||
18 | obj-$(CONFIG_X86_SPEEDSTEP_SMI) += speedstep-smi.o | ||
19 | obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO) += speedstep-centrino.o | ||
20 | obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o | ||
21 | obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c deleted file mode 100644 index cd8da247dda1..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +++ /dev/null | |||
@@ -1,775 +0,0 @@ | |||
1 | /* | ||
2 | * acpi-cpufreq.c - ACPI Processor P-States Driver | ||
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) 2002 - 2004 Dominik Brodowski <linux@brodo.de> | ||
7 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> | ||
8 | * | ||
9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or (at | ||
14 | * your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, but | ||
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License along | ||
22 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
24 | * | ||
25 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
26 | */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/smp.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/cpufreq.h> | ||
34 | #include <linux/compiler.h> | ||
35 | #include <linux/dmi.h> | ||
36 | #include <linux/slab.h> | ||
37 | |||
38 | #include <linux/acpi.h> | ||
39 | #include <linux/io.h> | ||
40 | #include <linux/delay.h> | ||
41 | #include <linux/uaccess.h> | ||
42 | |||
43 | #include <acpi/processor.h> | ||
44 | |||
45 | #include <asm/msr.h> | ||
46 | #include <asm/processor.h> | ||
47 | #include <asm/cpufeature.h> | ||
48 | #include "mperf.h" | ||
49 | |||
50 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
51 | "acpi-cpufreq", msg) | ||
52 | |||
53 | MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); | ||
54 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); | ||
55 | MODULE_LICENSE("GPL"); | ||
56 | |||
57 | enum { | ||
58 | UNDEFINED_CAPABLE = 0, | ||
59 | SYSTEM_INTEL_MSR_CAPABLE, | ||
60 | SYSTEM_IO_CAPABLE, | ||
61 | }; | ||
62 | |||
63 | #define INTEL_MSR_RANGE (0xffff) | ||
64 | |||
65 | struct acpi_cpufreq_data { | ||
66 | struct acpi_processor_performance *acpi_data; | ||
67 | struct cpufreq_frequency_table *freq_table; | ||
68 | unsigned int resume; | ||
69 | unsigned int cpu_feature; | ||
70 | }; | ||
71 | |||
72 | static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); | ||
73 | |||
74 | /* acpi_perf_data is a pointer to percpu data. */ | ||
75 | static struct acpi_processor_performance __percpu *acpi_perf_data; | ||
76 | |||
77 | static struct cpufreq_driver acpi_cpufreq_driver; | ||
78 | |||
79 | static unsigned int acpi_pstate_strict; | ||
80 | |||
81 | static int check_est_cpu(unsigned int cpuid) | ||
82 | { | ||
83 | struct cpuinfo_x86 *cpu = &cpu_data(cpuid); | ||
84 | |||
85 | return cpu_has(cpu, X86_FEATURE_EST); | ||
86 | } | ||
87 | |||
88 | static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data) | ||
89 | { | ||
90 | struct acpi_processor_performance *perf; | ||
91 | int i; | ||
92 | |||
93 | perf = data->acpi_data; | ||
94 | |||
95 | for (i = 0; i < perf->state_count; i++) { | ||
96 | if (value == perf->states[i].status) | ||
97 | return data->freq_table[i].frequency; | ||
98 | } | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) | ||
103 | { | ||
104 | int i; | ||
105 | struct acpi_processor_performance *perf; | ||
106 | |||
107 | msr &= INTEL_MSR_RANGE; | ||
108 | perf = data->acpi_data; | ||
109 | |||
110 | for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { | ||
111 | if (msr == perf->states[data->freq_table[i].index].status) | ||
112 | return data->freq_table[i].frequency; | ||
113 | } | ||
114 | return data->freq_table[0].frequency; | ||
115 | } | ||
116 | |||
117 | static unsigned extract_freq(u32 val, struct acpi_cpufreq_data *data) | ||
118 | { | ||
119 | switch (data->cpu_feature) { | ||
120 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
121 | return extract_msr(val, data); | ||
122 | case SYSTEM_IO_CAPABLE: | ||
123 | return extract_io(val, data); | ||
124 | default: | ||
125 | return 0; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | struct msr_addr { | ||
130 | u32 reg; | ||
131 | }; | ||
132 | |||
133 | struct io_addr { | ||
134 | u16 port; | ||
135 | u8 bit_width; | ||
136 | }; | ||
137 | |||
138 | struct drv_cmd { | ||
139 | unsigned int type; | ||
140 | const struct cpumask *mask; | ||
141 | union { | ||
142 | struct msr_addr msr; | ||
143 | struct io_addr io; | ||
144 | } addr; | ||
145 | u32 val; | ||
146 | }; | ||
147 | |||
148 | /* Called via smp_call_function_single(), on the target CPU */ | ||
149 | static void do_drv_read(void *_cmd) | ||
150 | { | ||
151 | struct drv_cmd *cmd = _cmd; | ||
152 | u32 h; | ||
153 | |||
154 | switch (cmd->type) { | ||
155 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
156 | rdmsr(cmd->addr.msr.reg, cmd->val, h); | ||
157 | break; | ||
158 | case SYSTEM_IO_CAPABLE: | ||
159 | acpi_os_read_port((acpi_io_address)cmd->addr.io.port, | ||
160 | &cmd->val, | ||
161 | (u32)cmd->addr.io.bit_width); | ||
162 | break; | ||
163 | default: | ||
164 | break; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | /* Called via smp_call_function_many(), on the target CPUs */ | ||
169 | static void do_drv_write(void *_cmd) | ||
170 | { | ||
171 | struct drv_cmd *cmd = _cmd; | ||
172 | u32 lo, hi; | ||
173 | |||
174 | switch (cmd->type) { | ||
175 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
176 | rdmsr(cmd->addr.msr.reg, lo, hi); | ||
177 | lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE); | ||
178 | wrmsr(cmd->addr.msr.reg, lo, hi); | ||
179 | break; | ||
180 | case SYSTEM_IO_CAPABLE: | ||
181 | acpi_os_write_port((acpi_io_address)cmd->addr.io.port, | ||
182 | cmd->val, | ||
183 | (u32)cmd->addr.io.bit_width); | ||
184 | break; | ||
185 | default: | ||
186 | break; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | static void drv_read(struct drv_cmd *cmd) | ||
191 | { | ||
192 | int err; | ||
193 | cmd->val = 0; | ||
194 | |||
195 | err = smp_call_function_any(cmd->mask, do_drv_read, cmd, 1); | ||
196 | WARN_ON_ONCE(err); /* smp_call_function_any() was buggy? */ | ||
197 | } | ||
198 | |||
199 | static void drv_write(struct drv_cmd *cmd) | ||
200 | { | ||
201 | int this_cpu; | ||
202 | |||
203 | this_cpu = get_cpu(); | ||
204 | if (cpumask_test_cpu(this_cpu, cmd->mask)) | ||
205 | do_drv_write(cmd); | ||
206 | smp_call_function_many(cmd->mask, do_drv_write, cmd, 1); | ||
207 | put_cpu(); | ||
208 | } | ||
209 | |||
210 | static u32 get_cur_val(const struct cpumask *mask) | ||
211 | { | ||
212 | struct acpi_processor_performance *perf; | ||
213 | struct drv_cmd cmd; | ||
214 | |||
215 | if (unlikely(cpumask_empty(mask))) | ||
216 | return 0; | ||
217 | |||
218 | switch (per_cpu(acfreq_data, cpumask_first(mask))->cpu_feature) { | ||
219 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
220 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | ||
221 | cmd.addr.msr.reg = MSR_IA32_PERF_STATUS; | ||
222 | break; | ||
223 | case SYSTEM_IO_CAPABLE: | ||
224 | cmd.type = SYSTEM_IO_CAPABLE; | ||
225 | perf = per_cpu(acfreq_data, cpumask_first(mask))->acpi_data; | ||
226 | cmd.addr.io.port = perf->control_register.address; | ||
227 | cmd.addr.io.bit_width = perf->control_register.bit_width; | ||
228 | break; | ||
229 | default: | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | cmd.mask = mask; | ||
234 | drv_read(&cmd); | ||
235 | |||
236 | dprintk("get_cur_val = %u\n", cmd.val); | ||
237 | |||
238 | return cmd.val; | ||
239 | } | ||
240 | |||
241 | static unsigned int get_cur_freq_on_cpu(unsigned int cpu) | ||
242 | { | ||
243 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu); | ||
244 | unsigned int freq; | ||
245 | unsigned int cached_freq; | ||
246 | |||
247 | dprintk("get_cur_freq_on_cpu (%d)\n", cpu); | ||
248 | |||
249 | if (unlikely(data == NULL || | ||
250 | data->acpi_data == NULL || data->freq_table == NULL)) { | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | cached_freq = data->freq_table[data->acpi_data->state].frequency; | ||
255 | freq = extract_freq(get_cur_val(cpumask_of(cpu)), data); | ||
256 | if (freq != cached_freq) { | ||
257 | /* | ||
258 | * The dreaded BIOS frequency change behind our back. | ||
259 | * Force set the frequency on next target call. | ||
260 | */ | ||
261 | data->resume = 1; | ||
262 | } | ||
263 | |||
264 | dprintk("cur freq = %u\n", freq); | ||
265 | |||
266 | return freq; | ||
267 | } | ||
268 | |||
269 | static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq, | ||
270 | struct acpi_cpufreq_data *data) | ||
271 | { | ||
272 | unsigned int cur_freq; | ||
273 | unsigned int i; | ||
274 | |||
275 | for (i = 0; i < 100; i++) { | ||
276 | cur_freq = extract_freq(get_cur_val(mask), data); | ||
277 | if (cur_freq == freq) | ||
278 | return 1; | ||
279 | udelay(10); | ||
280 | } | ||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | static int acpi_cpufreq_target(struct cpufreq_policy *policy, | ||
285 | unsigned int target_freq, unsigned int relation) | ||
286 | { | ||
287 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
288 | struct acpi_processor_performance *perf; | ||
289 | struct cpufreq_freqs freqs; | ||
290 | struct drv_cmd cmd; | ||
291 | unsigned int next_state = 0; /* Index into freq_table */ | ||
292 | unsigned int next_perf_state = 0; /* Index into perf table */ | ||
293 | unsigned int i; | ||
294 | int result = 0; | ||
295 | |||
296 | dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu); | ||
297 | |||
298 | if (unlikely(data == NULL || | ||
299 | data->acpi_data == NULL || data->freq_table == NULL)) { | ||
300 | return -ENODEV; | ||
301 | } | ||
302 | |||
303 | perf = data->acpi_data; | ||
304 | result = cpufreq_frequency_table_target(policy, | ||
305 | data->freq_table, | ||
306 | target_freq, | ||
307 | relation, &next_state); | ||
308 | if (unlikely(result)) { | ||
309 | result = -ENODEV; | ||
310 | goto out; | ||
311 | } | ||
312 | |||
313 | next_perf_state = data->freq_table[next_state].index; | ||
314 | if (perf->state == next_perf_state) { | ||
315 | if (unlikely(data->resume)) { | ||
316 | dprintk("Called after resume, resetting to P%d\n", | ||
317 | next_perf_state); | ||
318 | data->resume = 0; | ||
319 | } else { | ||
320 | dprintk("Already at target state (P%d)\n", | ||
321 | next_perf_state); | ||
322 | goto out; | ||
323 | } | ||
324 | } | ||
325 | |||
326 | switch (data->cpu_feature) { | ||
327 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
328 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | ||
329 | cmd.addr.msr.reg = MSR_IA32_PERF_CTL; | ||
330 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
331 | break; | ||
332 | case SYSTEM_IO_CAPABLE: | ||
333 | cmd.type = SYSTEM_IO_CAPABLE; | ||
334 | cmd.addr.io.port = perf->control_register.address; | ||
335 | cmd.addr.io.bit_width = perf->control_register.bit_width; | ||
336 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
337 | break; | ||
338 | default: | ||
339 | result = -ENODEV; | ||
340 | goto out; | ||
341 | } | ||
342 | |||
343 | /* cpufreq holds the hotplug lock, so we are safe from here on */ | ||
344 | if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY) | ||
345 | cmd.mask = policy->cpus; | ||
346 | else | ||
347 | cmd.mask = cpumask_of(policy->cpu); | ||
348 | |||
349 | freqs.old = perf->states[perf->state].core_frequency * 1000; | ||
350 | freqs.new = data->freq_table[next_state].frequency; | ||
351 | for_each_cpu(i, policy->cpus) { | ||
352 | freqs.cpu = i; | ||
353 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
354 | } | ||
355 | |||
356 | drv_write(&cmd); | ||
357 | |||
358 | if (acpi_pstate_strict) { | ||
359 | if (!check_freqs(cmd.mask, freqs.new, data)) { | ||
360 | dprintk("acpi_cpufreq_target failed (%d)\n", | ||
361 | policy->cpu); | ||
362 | result = -EAGAIN; | ||
363 | goto out; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | for_each_cpu(i, policy->cpus) { | ||
368 | freqs.cpu = i; | ||
369 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
370 | } | ||
371 | perf->state = next_perf_state; | ||
372 | |||
373 | out: | ||
374 | return result; | ||
375 | } | ||
376 | |||
377 | static int acpi_cpufreq_verify(struct cpufreq_policy *policy) | ||
378 | { | ||
379 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
380 | |||
381 | dprintk("acpi_cpufreq_verify\n"); | ||
382 | |||
383 | return cpufreq_frequency_table_verify(policy, data->freq_table); | ||
384 | } | ||
385 | |||
386 | static unsigned long | ||
387 | acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) | ||
388 | { | ||
389 | struct acpi_processor_performance *perf = data->acpi_data; | ||
390 | |||
391 | if (cpu_khz) { | ||
392 | /* search the closest match to cpu_khz */ | ||
393 | unsigned int i; | ||
394 | unsigned long freq; | ||
395 | unsigned long freqn = perf->states[0].core_frequency * 1000; | ||
396 | |||
397 | for (i = 0; i < (perf->state_count-1); i++) { | ||
398 | freq = freqn; | ||
399 | freqn = perf->states[i+1].core_frequency * 1000; | ||
400 | if ((2 * cpu_khz) > (freqn + freq)) { | ||
401 | perf->state = i; | ||
402 | return freq; | ||
403 | } | ||
404 | } | ||
405 | perf->state = perf->state_count-1; | ||
406 | return freqn; | ||
407 | } else { | ||
408 | /* assume CPU is at P0... */ | ||
409 | perf->state = 0; | ||
410 | return perf->states[0].core_frequency * 1000; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | static void free_acpi_perf_data(void) | ||
415 | { | ||
416 | unsigned int i; | ||
417 | |||
418 | /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */ | ||
419 | for_each_possible_cpu(i) | ||
420 | free_cpumask_var(per_cpu_ptr(acpi_perf_data, i) | ||
421 | ->shared_cpu_map); | ||
422 | free_percpu(acpi_perf_data); | ||
423 | } | ||
424 | |||
425 | /* | ||
426 | * acpi_cpufreq_early_init - initialize ACPI P-States library | ||
427 | * | ||
428 | * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c) | ||
429 | * in order to determine correct frequency and voltage pairings. We can | ||
430 | * do _PDC and _PSD and find out the processor dependency for the | ||
431 | * actual init that will happen later... | ||
432 | */ | ||
433 | static int __init acpi_cpufreq_early_init(void) | ||
434 | { | ||
435 | unsigned int i; | ||
436 | dprintk("acpi_cpufreq_early_init\n"); | ||
437 | |||
438 | acpi_perf_data = alloc_percpu(struct acpi_processor_performance); | ||
439 | if (!acpi_perf_data) { | ||
440 | dprintk("Memory allocation error for acpi_perf_data.\n"); | ||
441 | return -ENOMEM; | ||
442 | } | ||
443 | for_each_possible_cpu(i) { | ||
444 | if (!zalloc_cpumask_var_node( | ||
445 | &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map, | ||
446 | GFP_KERNEL, cpu_to_node(i))) { | ||
447 | |||
448 | /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ | ||
449 | free_acpi_perf_data(); | ||
450 | return -ENOMEM; | ||
451 | } | ||
452 | } | ||
453 | |||
454 | /* Do initialization in ACPI core */ | ||
455 | acpi_processor_preregister_performance(acpi_perf_data); | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | #ifdef CONFIG_SMP | ||
460 | /* | ||
461 | * Some BIOSes do SW_ANY coordination internally, either set it up in hw | ||
462 | * or do it in BIOS firmware and won't inform about it to OS. If not | ||
463 | * detected, this has a side effect of making CPU run at a different speed | ||
464 | * than OS intended it to run at. Detect it and handle it cleanly. | ||
465 | */ | ||
466 | static int bios_with_sw_any_bug; | ||
467 | |||
468 | static int sw_any_bug_found(const struct dmi_system_id *d) | ||
469 | { | ||
470 | bios_with_sw_any_bug = 1; | ||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | static const struct dmi_system_id sw_any_bug_dmi_table[] = { | ||
475 | { | ||
476 | .callback = sw_any_bug_found, | ||
477 | .ident = "Supermicro Server X6DLP", | ||
478 | .matches = { | ||
479 | DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"), | ||
480 | DMI_MATCH(DMI_BIOS_VERSION, "080010"), | ||
481 | DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"), | ||
482 | }, | ||
483 | }, | ||
484 | { } | ||
485 | }; | ||
486 | |||
487 | static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) | ||
488 | { | ||
489 | /* Intel Xeon Processor 7100 Series Specification Update | ||
490 | * http://www.intel.com/Assets/PDF/specupdate/314554.pdf | ||
491 | * AL30: A Machine Check Exception (MCE) Occurring during an | ||
492 | * Enhanced Intel SpeedStep Technology Ratio Change May Cause | ||
493 | * Both Processor Cores to Lock Up. */ | ||
494 | if (c->x86_vendor == X86_VENDOR_INTEL) { | ||
495 | if ((c->x86 == 15) && | ||
496 | (c->x86_model == 6) && | ||
497 | (c->x86_mask == 8)) { | ||
498 | printk(KERN_INFO "acpi-cpufreq: Intel(R) " | ||
499 | "Xeon(R) 7100 Errata AL30, processors may " | ||
500 | "lock up on frequency changes: disabling " | ||
501 | "acpi-cpufreq.\n"); | ||
502 | return -ENODEV; | ||
503 | } | ||
504 | } | ||
505 | return 0; | ||
506 | } | ||
507 | #endif | ||
508 | |||
509 | static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
510 | { | ||
511 | unsigned int i; | ||
512 | unsigned int valid_states = 0; | ||
513 | unsigned int cpu = policy->cpu; | ||
514 | struct acpi_cpufreq_data *data; | ||
515 | unsigned int result = 0; | ||
516 | struct cpuinfo_x86 *c = &cpu_data(policy->cpu); | ||
517 | struct acpi_processor_performance *perf; | ||
518 | #ifdef CONFIG_SMP | ||
519 | static int blacklisted; | ||
520 | #endif | ||
521 | |||
522 | dprintk("acpi_cpufreq_cpu_init\n"); | ||
523 | |||
524 | #ifdef CONFIG_SMP | ||
525 | if (blacklisted) | ||
526 | return blacklisted; | ||
527 | blacklisted = acpi_cpufreq_blacklist(c); | ||
528 | if (blacklisted) | ||
529 | return blacklisted; | ||
530 | #endif | ||
531 | |||
532 | data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); | ||
533 | if (!data) | ||
534 | return -ENOMEM; | ||
535 | |||
536 | data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu); | ||
537 | per_cpu(acfreq_data, cpu) = data; | ||
538 | |||
539 | if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) | ||
540 | acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
541 | |||
542 | result = acpi_processor_register_performance(data->acpi_data, cpu); | ||
543 | if (result) | ||
544 | goto err_free; | ||
545 | |||
546 | perf = data->acpi_data; | ||
547 | policy->shared_type = perf->shared_type; | ||
548 | |||
549 | /* | ||
550 | * Will let policy->cpus know about dependency only when software | ||
551 | * coordination is required. | ||
552 | */ | ||
553 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL || | ||
554 | policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { | ||
555 | cpumask_copy(policy->cpus, perf->shared_cpu_map); | ||
556 | } | ||
557 | cpumask_copy(policy->related_cpus, perf->shared_cpu_map); | ||
558 | |||
559 | #ifdef CONFIG_SMP | ||
560 | dmi_check_system(sw_any_bug_dmi_table); | ||
561 | if (bios_with_sw_any_bug && cpumask_weight(policy->cpus) == 1) { | ||
562 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; | ||
563 | cpumask_copy(policy->cpus, cpu_core_mask(cpu)); | ||
564 | } | ||
565 | #endif | ||
566 | |||
567 | /* capability check */ | ||
568 | if (perf->state_count <= 1) { | ||
569 | dprintk("No P-States\n"); | ||
570 | result = -ENODEV; | ||
571 | goto err_unreg; | ||
572 | } | ||
573 | |||
574 | if (perf->control_register.space_id != perf->status_register.space_id) { | ||
575 | result = -ENODEV; | ||
576 | goto err_unreg; | ||
577 | } | ||
578 | |||
579 | switch (perf->control_register.space_id) { | ||
580 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
581 | dprintk("SYSTEM IO addr space\n"); | ||
582 | data->cpu_feature = SYSTEM_IO_CAPABLE; | ||
583 | break; | ||
584 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | ||
585 | dprintk("HARDWARE addr space\n"); | ||
586 | if (!check_est_cpu(cpu)) { | ||
587 | result = -ENODEV; | ||
588 | goto err_unreg; | ||
589 | } | ||
590 | data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE; | ||
591 | break; | ||
592 | default: | ||
593 | dprintk("Unknown addr space %d\n", | ||
594 | (u32) (perf->control_register.space_id)); | ||
595 | result = -ENODEV; | ||
596 | goto err_unreg; | ||
597 | } | ||
598 | |||
599 | data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * | ||
600 | (perf->state_count+1), GFP_KERNEL); | ||
601 | if (!data->freq_table) { | ||
602 | result = -ENOMEM; | ||
603 | goto err_unreg; | ||
604 | } | ||
605 | |||
606 | /* detect transition latency */ | ||
607 | policy->cpuinfo.transition_latency = 0; | ||
608 | for (i = 0; i < perf->state_count; i++) { | ||
609 | if ((perf->states[i].transition_latency * 1000) > | ||
610 | policy->cpuinfo.transition_latency) | ||
611 | policy->cpuinfo.transition_latency = | ||
612 | perf->states[i].transition_latency * 1000; | ||
613 | } | ||
614 | |||
615 | /* Check for high latency (>20uS) from buggy BIOSes, like on T42 */ | ||
616 | if (perf->control_register.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE && | ||
617 | policy->cpuinfo.transition_latency > 20 * 1000) { | ||
618 | policy->cpuinfo.transition_latency = 20 * 1000; | ||
619 | printk_once(KERN_INFO | ||
620 | "P-state transition latency capped at 20 uS\n"); | ||
621 | } | ||
622 | |||
623 | /* table init */ | ||
624 | for (i = 0; i < perf->state_count; i++) { | ||
625 | if (i > 0 && perf->states[i].core_frequency >= | ||
626 | data->freq_table[valid_states-1].frequency / 1000) | ||
627 | continue; | ||
628 | |||
629 | data->freq_table[valid_states].index = i; | ||
630 | data->freq_table[valid_states].frequency = | ||
631 | perf->states[i].core_frequency * 1000; | ||
632 | valid_states++; | ||
633 | } | ||
634 | data->freq_table[valid_states].frequency = CPUFREQ_TABLE_END; | ||
635 | perf->state = 0; | ||
636 | |||
637 | result = cpufreq_frequency_table_cpuinfo(policy, data->freq_table); | ||
638 | if (result) | ||
639 | goto err_freqfree; | ||
640 | |||
641 | if (perf->states[0].core_frequency * 1000 != policy->cpuinfo.max_freq) | ||
642 | printk(KERN_WARNING FW_WARN "P-state 0 is not max freq\n"); | ||
643 | |||
644 | switch (perf->control_register.space_id) { | ||
645 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
646 | /* Current speed is unknown and not detectable by IO port */ | ||
647 | policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu); | ||
648 | break; | ||
649 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | ||
650 | acpi_cpufreq_driver.get = get_cur_freq_on_cpu; | ||
651 | policy->cur = get_cur_freq_on_cpu(cpu); | ||
652 | break; | ||
653 | default: | ||
654 | break; | ||
655 | } | ||
656 | |||
657 | /* notify BIOS that we exist */ | ||
658 | acpi_processor_notify_smm(THIS_MODULE); | ||
659 | |||
660 | /* Check for APERF/MPERF support in hardware */ | ||
661 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
662 | acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf; | ||
663 | |||
664 | dprintk("CPU%u - ACPI performance management activated.\n", cpu); | ||
665 | for (i = 0; i < perf->state_count; i++) | ||
666 | dprintk(" %cP%d: %d MHz, %d mW, %d uS\n", | ||
667 | (i == perf->state ? '*' : ' '), i, | ||
668 | (u32) perf->states[i].core_frequency, | ||
669 | (u32) perf->states[i].power, | ||
670 | (u32) perf->states[i].transition_latency); | ||
671 | |||
672 | cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu); | ||
673 | |||
674 | /* | ||
675 | * the first call to ->target() should result in us actually | ||
676 | * writing something to the appropriate registers. | ||
677 | */ | ||
678 | data->resume = 1; | ||
679 | |||
680 | return result; | ||
681 | |||
682 | err_freqfree: | ||
683 | kfree(data->freq_table); | ||
684 | err_unreg: | ||
685 | acpi_processor_unregister_performance(perf, cpu); | ||
686 | err_free: | ||
687 | kfree(data); | ||
688 | per_cpu(acfreq_data, cpu) = NULL; | ||
689 | |||
690 | return result; | ||
691 | } | ||
692 | |||
693 | static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy) | ||
694 | { | ||
695 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
696 | |||
697 | dprintk("acpi_cpufreq_cpu_exit\n"); | ||
698 | |||
699 | if (data) { | ||
700 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
701 | per_cpu(acfreq_data, policy->cpu) = NULL; | ||
702 | acpi_processor_unregister_performance(data->acpi_data, | ||
703 | policy->cpu); | ||
704 | kfree(data); | ||
705 | } | ||
706 | |||
707 | return 0; | ||
708 | } | ||
709 | |||
710 | static int acpi_cpufreq_resume(struct cpufreq_policy *policy) | ||
711 | { | ||
712 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
713 | |||
714 | dprintk("acpi_cpufreq_resume\n"); | ||
715 | |||
716 | data->resume = 1; | ||
717 | |||
718 | return 0; | ||
719 | } | ||
720 | |||
721 | static struct freq_attr *acpi_cpufreq_attr[] = { | ||
722 | &cpufreq_freq_attr_scaling_available_freqs, | ||
723 | NULL, | ||
724 | }; | ||
725 | |||
726 | static struct cpufreq_driver acpi_cpufreq_driver = { | ||
727 | .verify = acpi_cpufreq_verify, | ||
728 | .target = acpi_cpufreq_target, | ||
729 | .bios_limit = acpi_processor_get_bios_limit, | ||
730 | .init = acpi_cpufreq_cpu_init, | ||
731 | .exit = acpi_cpufreq_cpu_exit, | ||
732 | .resume = acpi_cpufreq_resume, | ||
733 | .name = "acpi-cpufreq", | ||
734 | .owner = THIS_MODULE, | ||
735 | .attr = acpi_cpufreq_attr, | ||
736 | }; | ||
737 | |||
738 | static int __init acpi_cpufreq_init(void) | ||
739 | { | ||
740 | int ret; | ||
741 | |||
742 | if (acpi_disabled) | ||
743 | return 0; | ||
744 | |||
745 | dprintk("acpi_cpufreq_init\n"); | ||
746 | |||
747 | ret = acpi_cpufreq_early_init(); | ||
748 | if (ret) | ||
749 | return ret; | ||
750 | |||
751 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); | ||
752 | if (ret) | ||
753 | free_acpi_perf_data(); | ||
754 | |||
755 | return ret; | ||
756 | } | ||
757 | |||
758 | static void __exit acpi_cpufreq_exit(void) | ||
759 | { | ||
760 | dprintk("acpi_cpufreq_exit\n"); | ||
761 | |||
762 | cpufreq_unregister_driver(&acpi_cpufreq_driver); | ||
763 | |||
764 | free_percpu(acpi_perf_data); | ||
765 | } | ||
766 | |||
767 | module_param(acpi_pstate_strict, uint, 0644); | ||
768 | MODULE_PARM_DESC(acpi_pstate_strict, | ||
769 | "value 0 or non-zero. non-zero -> strict ACPI checks are " | ||
770 | "performed during frequency changes."); | ||
771 | |||
772 | late_initcall(acpi_cpufreq_init); | ||
773 | module_exit(acpi_cpufreq_exit); | ||
774 | |||
775 | MODULE_ALIAS("acpi"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c deleted file mode 100644 index 733093d60436..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c +++ /dev/null | |||
@@ -1,446 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2004-2006 Sebastian Witt <se.witt@gmx.net> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * Based upon reverse engineered information | ||
6 | * | ||
7 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/moduleparam.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/cpufreq.h> | ||
15 | #include <linux/pci.h> | ||
16 | #include <linux/delay.h> | ||
17 | |||
18 | #define NFORCE2_XTAL 25 | ||
19 | #define NFORCE2_BOOTFSB 0x48 | ||
20 | #define NFORCE2_PLLENABLE 0xa8 | ||
21 | #define NFORCE2_PLLREG 0xa4 | ||
22 | #define NFORCE2_PLLADR 0xa0 | ||
23 | #define NFORCE2_PLL(mul, div) (0x100000 | (mul << 8) | div) | ||
24 | |||
25 | #define NFORCE2_MIN_FSB 50 | ||
26 | #define NFORCE2_SAFE_DISTANCE 50 | ||
27 | |||
28 | /* Delay in ms between FSB changes */ | ||
29 | /* #define NFORCE2_DELAY 10 */ | ||
30 | |||
31 | /* | ||
32 | * nforce2_chipset: | ||
33 | * FSB is changed using the chipset | ||
34 | */ | ||
35 | static struct pci_dev *nforce2_dev; | ||
36 | |||
37 | /* fid: | ||
38 | * multiplier * 10 | ||
39 | */ | ||
40 | static int fid; | ||
41 | |||
42 | /* min_fsb, max_fsb: | ||
43 | * minimum and maximum FSB (= FSB at boot time) | ||
44 | */ | ||
45 | static int min_fsb; | ||
46 | static int max_fsb; | ||
47 | |||
48 | MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>"); | ||
49 | MODULE_DESCRIPTION("nForce2 FSB changing cpufreq driver"); | ||
50 | MODULE_LICENSE("GPL"); | ||
51 | |||
52 | module_param(fid, int, 0444); | ||
53 | module_param(min_fsb, int, 0444); | ||
54 | |||
55 | MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)"); | ||
56 | MODULE_PARM_DESC(min_fsb, | ||
57 | "Minimum FSB to use, if not defined: current FSB - 50"); | ||
58 | |||
59 | #define PFX "cpufreq-nforce2: " | ||
60 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
61 | "cpufreq-nforce2", msg) | ||
62 | |||
63 | /** | ||
64 | * nforce2_calc_fsb - calculate FSB | ||
65 | * @pll: PLL value | ||
66 | * | ||
67 | * Calculates FSB from PLL value | ||
68 | */ | ||
69 | static int nforce2_calc_fsb(int pll) | ||
70 | { | ||
71 | unsigned char mul, div; | ||
72 | |||
73 | mul = (pll >> 8) & 0xff; | ||
74 | div = pll & 0xff; | ||
75 | |||
76 | if (div > 0) | ||
77 | return NFORCE2_XTAL * mul / div; | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * nforce2_calc_pll - calculate PLL value | ||
84 | * @fsb: FSB | ||
85 | * | ||
86 | * Calculate PLL value for given FSB | ||
87 | */ | ||
88 | static int nforce2_calc_pll(unsigned int fsb) | ||
89 | { | ||
90 | unsigned char xmul, xdiv; | ||
91 | unsigned char mul = 0, div = 0; | ||
92 | int tried = 0; | ||
93 | |||
94 | /* Try to calculate multiplier and divider up to 4 times */ | ||
95 | while (((mul == 0) || (div == 0)) && (tried <= 3)) { | ||
96 | for (xdiv = 2; xdiv <= 0x80; xdiv++) | ||
97 | for (xmul = 1; xmul <= 0xfe; xmul++) | ||
98 | if (nforce2_calc_fsb(NFORCE2_PLL(xmul, xdiv)) == | ||
99 | fsb + tried) { | ||
100 | mul = xmul; | ||
101 | div = xdiv; | ||
102 | } | ||
103 | tried++; | ||
104 | } | ||
105 | |||
106 | if ((mul == 0) || (div == 0)) | ||
107 | return -1; | ||
108 | |||
109 | return NFORCE2_PLL(mul, div); | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * nforce2_write_pll - write PLL value to chipset | ||
114 | * @pll: PLL value | ||
115 | * | ||
116 | * Writes new FSB PLL value to chipset | ||
117 | */ | ||
118 | static void nforce2_write_pll(int pll) | ||
119 | { | ||
120 | int temp; | ||
121 | |||
122 | /* Set the pll addr. to 0x00 */ | ||
123 | pci_write_config_dword(nforce2_dev, NFORCE2_PLLADR, 0); | ||
124 | |||
125 | /* Now write the value in all 64 registers */ | ||
126 | for (temp = 0; temp <= 0x3f; temp++) | ||
127 | pci_write_config_dword(nforce2_dev, NFORCE2_PLLREG, pll); | ||
128 | |||
129 | return; | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * nforce2_fsb_read - Read FSB | ||
134 | * | ||
135 | * Read FSB from chipset | ||
136 | * If bootfsb != 0, return FSB at boot-time | ||
137 | */ | ||
138 | static unsigned int nforce2_fsb_read(int bootfsb) | ||
139 | { | ||
140 | struct pci_dev *nforce2_sub5; | ||
141 | u32 fsb, temp = 0; | ||
142 | |||
143 | /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */ | ||
144 | nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 0x01EF, | ||
145 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
146 | if (!nforce2_sub5) | ||
147 | return 0; | ||
148 | |||
149 | pci_read_config_dword(nforce2_sub5, NFORCE2_BOOTFSB, &fsb); | ||
150 | fsb /= 1000000; | ||
151 | |||
152 | /* Check if PLL register is already set */ | ||
153 | pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp); | ||
154 | |||
155 | if (bootfsb || !temp) | ||
156 | return fsb; | ||
157 | |||
158 | /* Use PLL register FSB value */ | ||
159 | pci_read_config_dword(nforce2_dev, NFORCE2_PLLREG, &temp); | ||
160 | fsb = nforce2_calc_fsb(temp); | ||
161 | |||
162 | return fsb; | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * nforce2_set_fsb - set new FSB | ||
167 | * @fsb: New FSB | ||
168 | * | ||
169 | * Sets new FSB | ||
170 | */ | ||
171 | static int nforce2_set_fsb(unsigned int fsb) | ||
172 | { | ||
173 | u32 temp = 0; | ||
174 | unsigned int tfsb; | ||
175 | int diff; | ||
176 | int pll = 0; | ||
177 | |||
178 | if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) { | ||
179 | printk(KERN_ERR PFX "FSB %d is out of range!\n", fsb); | ||
180 | return -EINVAL; | ||
181 | } | ||
182 | |||
183 | tfsb = nforce2_fsb_read(0); | ||
184 | if (!tfsb) { | ||
185 | printk(KERN_ERR PFX "Error while reading the FSB\n"); | ||
186 | return -EINVAL; | ||
187 | } | ||
188 | |||
189 | /* First write? Then set actual value */ | ||
190 | pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp); | ||
191 | if (!temp) { | ||
192 | pll = nforce2_calc_pll(tfsb); | ||
193 | |||
194 | if (pll < 0) | ||
195 | return -EINVAL; | ||
196 | |||
197 | nforce2_write_pll(pll); | ||
198 | } | ||
199 | |||
200 | /* Enable write access */ | ||
201 | temp = 0x01; | ||
202 | pci_write_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8)temp); | ||
203 | |||
204 | diff = tfsb - fsb; | ||
205 | |||
206 | if (!diff) | ||
207 | return 0; | ||
208 | |||
209 | while ((tfsb != fsb) && (tfsb <= max_fsb) && (tfsb >= min_fsb)) { | ||
210 | if (diff < 0) | ||
211 | tfsb++; | ||
212 | else | ||
213 | tfsb--; | ||
214 | |||
215 | /* Calculate the PLL reg. value */ | ||
216 | pll = nforce2_calc_pll(tfsb); | ||
217 | if (pll == -1) | ||
218 | return -EINVAL; | ||
219 | |||
220 | nforce2_write_pll(pll); | ||
221 | #ifdef NFORCE2_DELAY | ||
222 | mdelay(NFORCE2_DELAY); | ||
223 | #endif | ||
224 | } | ||
225 | |||
226 | temp = 0x40; | ||
227 | pci_write_config_byte(nforce2_dev, NFORCE2_PLLADR, (u8)temp); | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | /** | ||
233 | * nforce2_get - get the CPU frequency | ||
234 | * @cpu: CPU number | ||
235 | * | ||
236 | * Returns the CPU frequency | ||
237 | */ | ||
238 | static unsigned int nforce2_get(unsigned int cpu) | ||
239 | { | ||
240 | if (cpu) | ||
241 | return 0; | ||
242 | return nforce2_fsb_read(0) * fid * 100; | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * nforce2_target - set a new CPUFreq policy | ||
247 | * @policy: new policy | ||
248 | * @target_freq: the target frequency | ||
249 | * @relation: how that frequency relates to achieved frequency | ||
250 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
251 | * | ||
252 | * Sets a new CPUFreq policy. | ||
253 | */ | ||
254 | static int nforce2_target(struct cpufreq_policy *policy, | ||
255 | unsigned int target_freq, unsigned int relation) | ||
256 | { | ||
257 | /* unsigned long flags; */ | ||
258 | struct cpufreq_freqs freqs; | ||
259 | unsigned int target_fsb; | ||
260 | |||
261 | if ((target_freq > policy->max) || (target_freq < policy->min)) | ||
262 | return -EINVAL; | ||
263 | |||
264 | target_fsb = target_freq / (fid * 100); | ||
265 | |||
266 | freqs.old = nforce2_get(policy->cpu); | ||
267 | freqs.new = target_fsb * fid * 100; | ||
268 | freqs.cpu = 0; /* Only one CPU on nForce2 platforms */ | ||
269 | |||
270 | if (freqs.old == freqs.new) | ||
271 | return 0; | ||
272 | |||
273 | dprintk("Old CPU frequency %d kHz, new %d kHz\n", | ||
274 | freqs.old, freqs.new); | ||
275 | |||
276 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
277 | |||
278 | /* Disable IRQs */ | ||
279 | /* local_irq_save(flags); */ | ||
280 | |||
281 | if (nforce2_set_fsb(target_fsb) < 0) | ||
282 | printk(KERN_ERR PFX "Changing FSB to %d failed\n", | ||
283 | target_fsb); | ||
284 | else | ||
285 | dprintk("Changed FSB successfully to %d\n", | ||
286 | target_fsb); | ||
287 | |||
288 | /* Enable IRQs */ | ||
289 | /* local_irq_restore(flags); */ | ||
290 | |||
291 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * nforce2_verify - verifies a new CPUFreq policy | ||
298 | * @policy: new policy | ||
299 | */ | ||
300 | static int nforce2_verify(struct cpufreq_policy *policy) | ||
301 | { | ||
302 | unsigned int fsb_pol_max; | ||
303 | |||
304 | fsb_pol_max = policy->max / (fid * 100); | ||
305 | |||
306 | if (policy->min < (fsb_pol_max * fid * 100)) | ||
307 | policy->max = (fsb_pol_max + 1) * fid * 100; | ||
308 | |||
309 | cpufreq_verify_within_limits(policy, | ||
310 | policy->cpuinfo.min_freq, | ||
311 | policy->cpuinfo.max_freq); | ||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | static int nforce2_cpu_init(struct cpufreq_policy *policy) | ||
316 | { | ||
317 | unsigned int fsb; | ||
318 | unsigned int rfid; | ||
319 | |||
320 | /* capability check */ | ||
321 | if (policy->cpu != 0) | ||
322 | return -ENODEV; | ||
323 | |||
324 | /* Get current FSB */ | ||
325 | fsb = nforce2_fsb_read(0); | ||
326 | |||
327 | if (!fsb) | ||
328 | return -EIO; | ||
329 | |||
330 | /* FIX: Get FID from CPU */ | ||
331 | if (!fid) { | ||
332 | if (!cpu_khz) { | ||
333 | printk(KERN_WARNING PFX | ||
334 | "cpu_khz not set, can't calculate multiplier!\n"); | ||
335 | return -ENODEV; | ||
336 | } | ||
337 | |||
338 | fid = cpu_khz / (fsb * 100); | ||
339 | rfid = fid % 5; | ||
340 | |||
341 | if (rfid) { | ||
342 | if (rfid > 2) | ||
343 | fid += 5 - rfid; | ||
344 | else | ||
345 | fid -= rfid; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | printk(KERN_INFO PFX "FSB currently at %i MHz, FID %d.%d\n", fsb, | ||
350 | fid / 10, fid % 10); | ||
351 | |||
352 | /* Set maximum FSB to FSB at boot time */ | ||
353 | max_fsb = nforce2_fsb_read(1); | ||
354 | |||
355 | if (!max_fsb) | ||
356 | return -EIO; | ||
357 | |||
358 | if (!min_fsb) | ||
359 | min_fsb = max_fsb - NFORCE2_SAFE_DISTANCE; | ||
360 | |||
361 | if (min_fsb < NFORCE2_MIN_FSB) | ||
362 | min_fsb = NFORCE2_MIN_FSB; | ||
363 | |||
364 | /* cpuinfo and default policy values */ | ||
365 | policy->cpuinfo.min_freq = min_fsb * fid * 100; | ||
366 | policy->cpuinfo.max_freq = max_fsb * fid * 100; | ||
367 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
368 | policy->cur = nforce2_get(policy->cpu); | ||
369 | policy->min = policy->cpuinfo.min_freq; | ||
370 | policy->max = policy->cpuinfo.max_freq; | ||
371 | |||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | static int nforce2_cpu_exit(struct cpufreq_policy *policy) | ||
376 | { | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | static struct cpufreq_driver nforce2_driver = { | ||
381 | .name = "nforce2", | ||
382 | .verify = nforce2_verify, | ||
383 | .target = nforce2_target, | ||
384 | .get = nforce2_get, | ||
385 | .init = nforce2_cpu_init, | ||
386 | .exit = nforce2_cpu_exit, | ||
387 | .owner = THIS_MODULE, | ||
388 | }; | ||
389 | |||
390 | /** | ||
391 | * nforce2_detect_chipset - detect the Southbridge which contains FSB PLL logic | ||
392 | * | ||
393 | * Detects nForce2 A2 and C1 stepping | ||
394 | * | ||
395 | */ | ||
396 | static unsigned int nforce2_detect_chipset(void) | ||
397 | { | ||
398 | nforce2_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, | ||
399 | PCI_DEVICE_ID_NVIDIA_NFORCE2, | ||
400 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
401 | |||
402 | if (nforce2_dev == NULL) | ||
403 | return -ENODEV; | ||
404 | |||
405 | printk(KERN_INFO PFX "Detected nForce2 chipset revision %X\n", | ||
406 | nforce2_dev->revision); | ||
407 | printk(KERN_INFO PFX | ||
408 | "FSB changing is maybe unstable and can lead to " | ||
409 | "crashes and data loss.\n"); | ||
410 | |||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | /** | ||
415 | * nforce2_init - initializes the nForce2 CPUFreq driver | ||
416 | * | ||
417 | * Initializes the nForce2 FSB support. Returns -ENODEV on unsupported | ||
418 | * devices, -EINVAL on problems during initiatization, and zero on | ||
419 | * success. | ||
420 | */ | ||
421 | static int __init nforce2_init(void) | ||
422 | { | ||
423 | /* TODO: do we need to detect the processor? */ | ||
424 | |||
425 | /* detect chipset */ | ||
426 | if (nforce2_detect_chipset()) { | ||
427 | printk(KERN_INFO PFX "No nForce2 chipset.\n"); | ||
428 | return -ENODEV; | ||
429 | } | ||
430 | |||
431 | return cpufreq_register_driver(&nforce2_driver); | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * nforce2_exit - unregisters cpufreq module | ||
436 | * | ||
437 | * Unregisters nForce2 FSB change support. | ||
438 | */ | ||
439 | static void __exit nforce2_exit(void) | ||
440 | { | ||
441 | cpufreq_unregister_driver(&nforce2_driver); | ||
442 | } | ||
443 | |||
444 | module_init(nforce2_init); | ||
445 | module_exit(nforce2_exit); | ||
446 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/e_powersaver.c b/arch/x86/kernel/cpu/cpufreq/e_powersaver.c deleted file mode 100644 index 35a257dd4bb7..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/e_powersaver.c +++ /dev/null | |||
@@ -1,367 +0,0 @@ | |||
1 | /* | ||
2 | * Based on documentation provided by Dave Jones. Thanks! | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/cpufreq.h> | ||
13 | #include <linux/ioport.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/timex.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/delay.h> | ||
18 | |||
19 | #include <asm/msr.h> | ||
20 | #include <asm/tsc.h> | ||
21 | |||
22 | #define EPS_BRAND_C7M 0 | ||
23 | #define EPS_BRAND_C7 1 | ||
24 | #define EPS_BRAND_EDEN 2 | ||
25 | #define EPS_BRAND_C3 3 | ||
26 | #define EPS_BRAND_C7D 4 | ||
27 | |||
28 | struct eps_cpu_data { | ||
29 | u32 fsb; | ||
30 | struct cpufreq_frequency_table freq_table[]; | ||
31 | }; | ||
32 | |||
33 | static struct eps_cpu_data *eps_cpu[NR_CPUS]; | ||
34 | |||
35 | |||
36 | static unsigned int eps_get(unsigned int cpu) | ||
37 | { | ||
38 | struct eps_cpu_data *centaur; | ||
39 | u32 lo, hi; | ||
40 | |||
41 | if (cpu) | ||
42 | return 0; | ||
43 | centaur = eps_cpu[cpu]; | ||
44 | if (centaur == NULL) | ||
45 | return 0; | ||
46 | |||
47 | /* Return current frequency */ | ||
48 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
49 | return centaur->fsb * ((lo >> 8) & 0xff); | ||
50 | } | ||
51 | |||
52 | static int eps_set_state(struct eps_cpu_data *centaur, | ||
53 | unsigned int cpu, | ||
54 | u32 dest_state) | ||
55 | { | ||
56 | struct cpufreq_freqs freqs; | ||
57 | u32 lo, hi; | ||
58 | int err = 0; | ||
59 | int i; | ||
60 | |||
61 | freqs.old = eps_get(cpu); | ||
62 | freqs.new = centaur->fsb * ((dest_state >> 8) & 0xff); | ||
63 | freqs.cpu = cpu; | ||
64 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
65 | |||
66 | /* Wait while CPU is busy */ | ||
67 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
68 | i = 0; | ||
69 | while (lo & ((1 << 16) | (1 << 17))) { | ||
70 | udelay(16); | ||
71 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
72 | i++; | ||
73 | if (unlikely(i > 64)) { | ||
74 | err = -ENODEV; | ||
75 | goto postchange; | ||
76 | } | ||
77 | } | ||
78 | /* Set new multiplier and voltage */ | ||
79 | wrmsr(MSR_IA32_PERF_CTL, dest_state & 0xffff, 0); | ||
80 | /* Wait until transition end */ | ||
81 | i = 0; | ||
82 | do { | ||
83 | udelay(16); | ||
84 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
85 | i++; | ||
86 | if (unlikely(i > 64)) { | ||
87 | err = -ENODEV; | ||
88 | goto postchange; | ||
89 | } | ||
90 | } while (lo & ((1 << 16) | (1 << 17))); | ||
91 | |||
92 | /* Return current frequency */ | ||
93 | postchange: | ||
94 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
95 | freqs.new = centaur->fsb * ((lo >> 8) & 0xff); | ||
96 | |||
97 | #ifdef DEBUG | ||
98 | { | ||
99 | u8 current_multiplier, current_voltage; | ||
100 | |||
101 | /* Print voltage and multiplier */ | ||
102 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
103 | current_voltage = lo & 0xff; | ||
104 | printk(KERN_INFO "eps: Current voltage = %dmV\n", | ||
105 | current_voltage * 16 + 700); | ||
106 | current_multiplier = (lo >> 8) & 0xff; | ||
107 | printk(KERN_INFO "eps: Current multiplier = %d\n", | ||
108 | current_multiplier); | ||
109 | } | ||
110 | #endif | ||
111 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
112 | return err; | ||
113 | } | ||
114 | |||
115 | static int eps_target(struct cpufreq_policy *policy, | ||
116 | unsigned int target_freq, | ||
117 | unsigned int relation) | ||
118 | { | ||
119 | struct eps_cpu_data *centaur; | ||
120 | unsigned int newstate = 0; | ||
121 | unsigned int cpu = policy->cpu; | ||
122 | unsigned int dest_state; | ||
123 | int ret; | ||
124 | |||
125 | if (unlikely(eps_cpu[cpu] == NULL)) | ||
126 | return -ENODEV; | ||
127 | centaur = eps_cpu[cpu]; | ||
128 | |||
129 | if (unlikely(cpufreq_frequency_table_target(policy, | ||
130 | &eps_cpu[cpu]->freq_table[0], | ||
131 | target_freq, | ||
132 | relation, | ||
133 | &newstate))) { | ||
134 | return -EINVAL; | ||
135 | } | ||
136 | |||
137 | /* Make frequency transition */ | ||
138 | dest_state = centaur->freq_table[newstate].index & 0xffff; | ||
139 | ret = eps_set_state(centaur, cpu, dest_state); | ||
140 | if (ret) | ||
141 | printk(KERN_ERR "eps: Timeout!\n"); | ||
142 | return ret; | ||
143 | } | ||
144 | |||
145 | static int eps_verify(struct cpufreq_policy *policy) | ||
146 | { | ||
147 | return cpufreq_frequency_table_verify(policy, | ||
148 | &eps_cpu[policy->cpu]->freq_table[0]); | ||
149 | } | ||
150 | |||
151 | static int eps_cpu_init(struct cpufreq_policy *policy) | ||
152 | { | ||
153 | unsigned int i; | ||
154 | u32 lo, hi; | ||
155 | u64 val; | ||
156 | u8 current_multiplier, current_voltage; | ||
157 | u8 max_multiplier, max_voltage; | ||
158 | u8 min_multiplier, min_voltage; | ||
159 | u8 brand = 0; | ||
160 | u32 fsb; | ||
161 | struct eps_cpu_data *centaur; | ||
162 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
163 | struct cpufreq_frequency_table *f_table; | ||
164 | int k, step, voltage; | ||
165 | int ret; | ||
166 | int states; | ||
167 | |||
168 | if (policy->cpu != 0) | ||
169 | return -ENODEV; | ||
170 | |||
171 | /* Check brand */ | ||
172 | printk(KERN_INFO "eps: Detected VIA "); | ||
173 | |||
174 | switch (c->x86_model) { | ||
175 | case 10: | ||
176 | rdmsr(0x1153, lo, hi); | ||
177 | brand = (((lo >> 2) ^ lo) >> 18) & 3; | ||
178 | printk(KERN_CONT "Model A "); | ||
179 | break; | ||
180 | case 13: | ||
181 | rdmsr(0x1154, lo, hi); | ||
182 | brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff; | ||
183 | printk(KERN_CONT "Model D "); | ||
184 | break; | ||
185 | } | ||
186 | |||
187 | switch (brand) { | ||
188 | case EPS_BRAND_C7M: | ||
189 | printk(KERN_CONT "C7-M\n"); | ||
190 | break; | ||
191 | case EPS_BRAND_C7: | ||
192 | printk(KERN_CONT "C7\n"); | ||
193 | break; | ||
194 | case EPS_BRAND_EDEN: | ||
195 | printk(KERN_CONT "Eden\n"); | ||
196 | break; | ||
197 | case EPS_BRAND_C7D: | ||
198 | printk(KERN_CONT "C7-D\n"); | ||
199 | break; | ||
200 | case EPS_BRAND_C3: | ||
201 | printk(KERN_CONT "C3\n"); | ||
202 | return -ENODEV; | ||
203 | break; | ||
204 | } | ||
205 | /* Enable Enhanced PowerSaver */ | ||
206 | rdmsrl(MSR_IA32_MISC_ENABLE, val); | ||
207 | if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
208 | val |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP; | ||
209 | wrmsrl(MSR_IA32_MISC_ENABLE, val); | ||
210 | /* Can be locked at 0 */ | ||
211 | rdmsrl(MSR_IA32_MISC_ENABLE, val); | ||
212 | if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
213 | printk(KERN_INFO "eps: Can't enable Enhanced PowerSaver\n"); | ||
214 | return -ENODEV; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /* Print voltage and multiplier */ | ||
219 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
220 | current_voltage = lo & 0xff; | ||
221 | printk(KERN_INFO "eps: Current voltage = %dmV\n", | ||
222 | current_voltage * 16 + 700); | ||
223 | current_multiplier = (lo >> 8) & 0xff; | ||
224 | printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier); | ||
225 | |||
226 | /* Print limits */ | ||
227 | max_voltage = hi & 0xff; | ||
228 | printk(KERN_INFO "eps: Highest voltage = %dmV\n", | ||
229 | max_voltage * 16 + 700); | ||
230 | max_multiplier = (hi >> 8) & 0xff; | ||
231 | printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier); | ||
232 | min_voltage = (hi >> 16) & 0xff; | ||
233 | printk(KERN_INFO "eps: Lowest voltage = %dmV\n", | ||
234 | min_voltage * 16 + 700); | ||
235 | min_multiplier = (hi >> 24) & 0xff; | ||
236 | printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier); | ||
237 | |||
238 | /* Sanity checks */ | ||
239 | if (current_multiplier == 0 || max_multiplier == 0 | ||
240 | || min_multiplier == 0) | ||
241 | return -EINVAL; | ||
242 | if (current_multiplier > max_multiplier | ||
243 | || max_multiplier <= min_multiplier) | ||
244 | return -EINVAL; | ||
245 | if (current_voltage > 0x1f || max_voltage > 0x1f) | ||
246 | return -EINVAL; | ||
247 | if (max_voltage < min_voltage) | ||
248 | return -EINVAL; | ||
249 | |||
250 | /* Calc FSB speed */ | ||
251 | fsb = cpu_khz / current_multiplier; | ||
252 | /* Calc number of p-states supported */ | ||
253 | if (brand == EPS_BRAND_C7M) | ||
254 | states = max_multiplier - min_multiplier + 1; | ||
255 | else | ||
256 | states = 2; | ||
257 | |||
258 | /* Allocate private data and frequency table for current cpu */ | ||
259 | centaur = kzalloc(sizeof(struct eps_cpu_data) | ||
260 | + (states + 1) * sizeof(struct cpufreq_frequency_table), | ||
261 | GFP_KERNEL); | ||
262 | if (!centaur) | ||
263 | return -ENOMEM; | ||
264 | eps_cpu[0] = centaur; | ||
265 | |||
266 | /* Copy basic values */ | ||
267 | centaur->fsb = fsb; | ||
268 | |||
269 | /* Fill frequency and MSR value table */ | ||
270 | f_table = ¢aur->freq_table[0]; | ||
271 | if (brand != EPS_BRAND_C7M) { | ||
272 | f_table[0].frequency = fsb * min_multiplier; | ||
273 | f_table[0].index = (min_multiplier << 8) | min_voltage; | ||
274 | f_table[1].frequency = fsb * max_multiplier; | ||
275 | f_table[1].index = (max_multiplier << 8) | max_voltage; | ||
276 | f_table[2].frequency = CPUFREQ_TABLE_END; | ||
277 | } else { | ||
278 | k = 0; | ||
279 | step = ((max_voltage - min_voltage) * 256) | ||
280 | / (max_multiplier - min_multiplier); | ||
281 | for (i = min_multiplier; i <= max_multiplier; i++) { | ||
282 | voltage = (k * step) / 256 + min_voltage; | ||
283 | f_table[k].frequency = fsb * i; | ||
284 | f_table[k].index = (i << 8) | voltage; | ||
285 | k++; | ||
286 | } | ||
287 | f_table[k].frequency = CPUFREQ_TABLE_END; | ||
288 | } | ||
289 | |||
290 | policy->cpuinfo.transition_latency = 140000; /* 844mV -> 700mV in ns */ | ||
291 | policy->cur = fsb * current_multiplier; | ||
292 | |||
293 | ret = cpufreq_frequency_table_cpuinfo(policy, ¢aur->freq_table[0]); | ||
294 | if (ret) { | ||
295 | kfree(centaur); | ||
296 | return ret; | ||
297 | } | ||
298 | |||
299 | cpufreq_frequency_table_get_attr(¢aur->freq_table[0], policy->cpu); | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static int eps_cpu_exit(struct cpufreq_policy *policy) | ||
304 | { | ||
305 | unsigned int cpu = policy->cpu; | ||
306 | struct eps_cpu_data *centaur; | ||
307 | u32 lo, hi; | ||
308 | |||
309 | if (eps_cpu[cpu] == NULL) | ||
310 | return -ENODEV; | ||
311 | centaur = eps_cpu[cpu]; | ||
312 | |||
313 | /* Get max frequency */ | ||
314 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
315 | /* Set max frequency */ | ||
316 | eps_set_state(centaur, cpu, hi & 0xffff); | ||
317 | /* Bye */ | ||
318 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
319 | kfree(eps_cpu[cpu]); | ||
320 | eps_cpu[cpu] = NULL; | ||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | static struct freq_attr *eps_attr[] = { | ||
325 | &cpufreq_freq_attr_scaling_available_freqs, | ||
326 | NULL, | ||
327 | }; | ||
328 | |||
329 | static struct cpufreq_driver eps_driver = { | ||
330 | .verify = eps_verify, | ||
331 | .target = eps_target, | ||
332 | .init = eps_cpu_init, | ||
333 | .exit = eps_cpu_exit, | ||
334 | .get = eps_get, | ||
335 | .name = "e_powersaver", | ||
336 | .owner = THIS_MODULE, | ||
337 | .attr = eps_attr, | ||
338 | }; | ||
339 | |||
340 | static int __init eps_init(void) | ||
341 | { | ||
342 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
343 | |||
344 | /* This driver will work only on Centaur C7 processors with | ||
345 | * Enhanced SpeedStep/PowerSaver registers */ | ||
346 | if (c->x86_vendor != X86_VENDOR_CENTAUR | ||
347 | || c->x86 != 6 || c->x86_model < 10) | ||
348 | return -ENODEV; | ||
349 | if (!cpu_has(c, X86_FEATURE_EST)) | ||
350 | return -ENODEV; | ||
351 | |||
352 | if (cpufreq_register_driver(&eps_driver)) | ||
353 | return -EINVAL; | ||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static void __exit eps_exit(void) | ||
358 | { | ||
359 | cpufreq_unregister_driver(&eps_driver); | ||
360 | } | ||
361 | |||
362 | MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>"); | ||
363 | MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's."); | ||
364 | MODULE_LICENSE("GPL"); | ||
365 | |||
366 | module_init(eps_init); | ||
367 | module_exit(eps_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/elanfreq.c b/arch/x86/kernel/cpu/cpufreq/elanfreq.c deleted file mode 100644 index c587db472a75..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/elanfreq.c +++ /dev/null | |||
@@ -1,309 +0,0 @@ | |||
1 | /* | ||
2 | * elanfreq: cpufreq driver for the AMD ELAN family | ||
3 | * | ||
4 | * (c) Copyright 2002 Robert Schwebel <r.schwebel@pengutronix.de> | ||
5 | * | ||
6 | * Parts of this code are (c) Sven Geggus <sven@geggus.net> | ||
7 | * | ||
8 | * All Rights Reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version | ||
13 | * 2 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * 2002-02-13: - initial revision for 2.4.18-pre9 by Robert Schwebel | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/init.h> | ||
22 | |||
23 | #include <linux/delay.h> | ||
24 | #include <linux/cpufreq.h> | ||
25 | |||
26 | #include <asm/msr.h> | ||
27 | #include <linux/timex.h> | ||
28 | #include <linux/io.h> | ||
29 | |||
30 | #define REG_CSCIR 0x22 /* Chip Setup and Control Index Register */ | ||
31 | #define REG_CSCDR 0x23 /* Chip Setup and Control Data Register */ | ||
32 | |||
33 | /* Module parameter */ | ||
34 | static int max_freq; | ||
35 | |||
36 | struct s_elan_multiplier { | ||
37 | int clock; /* frequency in kHz */ | ||
38 | int val40h; /* PMU Force Mode register */ | ||
39 | int val80h; /* CPU Clock Speed Register */ | ||
40 | }; | ||
41 | |||
42 | /* | ||
43 | * It is important that the frequencies | ||
44 | * are listed in ascending order here! | ||
45 | */ | ||
46 | static struct s_elan_multiplier elan_multiplier[] = { | ||
47 | {1000, 0x02, 0x18}, | ||
48 | {2000, 0x02, 0x10}, | ||
49 | {4000, 0x02, 0x08}, | ||
50 | {8000, 0x00, 0x00}, | ||
51 | {16000, 0x00, 0x02}, | ||
52 | {33000, 0x00, 0x04}, | ||
53 | {66000, 0x01, 0x04}, | ||
54 | {99000, 0x01, 0x05} | ||
55 | }; | ||
56 | |||
57 | static struct cpufreq_frequency_table elanfreq_table[] = { | ||
58 | {0, 1000}, | ||
59 | {1, 2000}, | ||
60 | {2, 4000}, | ||
61 | {3, 8000}, | ||
62 | {4, 16000}, | ||
63 | {5, 33000}, | ||
64 | {6, 66000}, | ||
65 | {7, 99000}, | ||
66 | {0, CPUFREQ_TABLE_END}, | ||
67 | }; | ||
68 | |||
69 | |||
70 | /** | ||
71 | * elanfreq_get_cpu_frequency: determine current cpu speed | ||
72 | * | ||
73 | * Finds out at which frequency the CPU of the Elan SOC runs | ||
74 | * at the moment. Frequencies from 1 to 33 MHz are generated | ||
75 | * the normal way, 66 and 99 MHz are called "Hyperspeed Mode" | ||
76 | * and have the rest of the chip running with 33 MHz. | ||
77 | */ | ||
78 | |||
79 | static unsigned int elanfreq_get_cpu_frequency(unsigned int cpu) | ||
80 | { | ||
81 | u8 clockspeed_reg; /* Clock Speed Register */ | ||
82 | |||
83 | local_irq_disable(); | ||
84 | outb_p(0x80, REG_CSCIR); | ||
85 | clockspeed_reg = inb_p(REG_CSCDR); | ||
86 | local_irq_enable(); | ||
87 | |||
88 | if ((clockspeed_reg & 0xE0) == 0xE0) | ||
89 | return 0; | ||
90 | |||
91 | /* Are we in CPU clock multiplied mode (66/99 MHz)? */ | ||
92 | if ((clockspeed_reg & 0xE0) == 0xC0) { | ||
93 | if ((clockspeed_reg & 0x01) == 0) | ||
94 | return 66000; | ||
95 | else | ||
96 | return 99000; | ||
97 | } | ||
98 | |||
99 | /* 33 MHz is not 32 MHz... */ | ||
100 | if ((clockspeed_reg & 0xE0) == 0xA0) | ||
101 | return 33000; | ||
102 | |||
103 | return (1<<((clockspeed_reg & 0xE0) >> 5)) * 1000; | ||
104 | } | ||
105 | |||
106 | |||
107 | /** | ||
108 | * elanfreq_set_cpu_frequency: Change the CPU core frequency | ||
109 | * @cpu: cpu number | ||
110 | * @freq: frequency in kHz | ||
111 | * | ||
112 | * This function takes a frequency value and changes the CPU frequency | ||
113 | * according to this. Note that the frequency has to be checked by | ||
114 | * elanfreq_validatespeed() for correctness! | ||
115 | * | ||
116 | * There is no return value. | ||
117 | */ | ||
118 | |||
119 | static void elanfreq_set_cpu_state(unsigned int state) | ||
120 | { | ||
121 | struct cpufreq_freqs freqs; | ||
122 | |||
123 | freqs.old = elanfreq_get_cpu_frequency(0); | ||
124 | freqs.new = elan_multiplier[state].clock; | ||
125 | freqs.cpu = 0; /* elanfreq.c is UP only driver */ | ||
126 | |||
127 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
128 | |||
129 | printk(KERN_INFO "elanfreq: attempting to set frequency to %i kHz\n", | ||
130 | elan_multiplier[state].clock); | ||
131 | |||
132 | |||
133 | /* | ||
134 | * Access to the Elan's internal registers is indexed via | ||
135 | * 0x22: Chip Setup & Control Register Index Register (CSCI) | ||
136 | * 0x23: Chip Setup & Control Register Data Register (CSCD) | ||
137 | * | ||
138 | */ | ||
139 | |||
140 | /* | ||
141 | * 0x40 is the Power Management Unit's Force Mode Register. | ||
142 | * Bit 6 enables Hyperspeed Mode (66/100 MHz core frequency) | ||
143 | */ | ||
144 | |||
145 | local_irq_disable(); | ||
146 | outb_p(0x40, REG_CSCIR); /* Disable hyperspeed mode */ | ||
147 | outb_p(0x00, REG_CSCDR); | ||
148 | local_irq_enable(); /* wait till internal pipelines and */ | ||
149 | udelay(1000); /* buffers have cleaned up */ | ||
150 | |||
151 | local_irq_disable(); | ||
152 | |||
153 | /* now, set the CPU clock speed register (0x80) */ | ||
154 | outb_p(0x80, REG_CSCIR); | ||
155 | outb_p(elan_multiplier[state].val80h, REG_CSCDR); | ||
156 | |||
157 | /* now, the hyperspeed bit in PMU Force Mode Register (0x40) */ | ||
158 | outb_p(0x40, REG_CSCIR); | ||
159 | outb_p(elan_multiplier[state].val40h, REG_CSCDR); | ||
160 | udelay(10000); | ||
161 | local_irq_enable(); | ||
162 | |||
163 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
164 | }; | ||
165 | |||
166 | |||
167 | /** | ||
168 | * elanfreq_validatespeed: test if frequency range is valid | ||
169 | * @policy: the policy to validate | ||
170 | * | ||
171 | * This function checks if a given frequency range in kHz is valid | ||
172 | * for the hardware supported by the driver. | ||
173 | */ | ||
174 | |||
175 | static int elanfreq_verify(struct cpufreq_policy *policy) | ||
176 | { | ||
177 | return cpufreq_frequency_table_verify(policy, &elanfreq_table[0]); | ||
178 | } | ||
179 | |||
180 | static int elanfreq_target(struct cpufreq_policy *policy, | ||
181 | unsigned int target_freq, | ||
182 | unsigned int relation) | ||
183 | { | ||
184 | unsigned int newstate = 0; | ||
185 | |||
186 | if (cpufreq_frequency_table_target(policy, &elanfreq_table[0], | ||
187 | target_freq, relation, &newstate)) | ||
188 | return -EINVAL; | ||
189 | |||
190 | elanfreq_set_cpu_state(newstate); | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | |||
196 | /* | ||
197 | * Module init and exit code | ||
198 | */ | ||
199 | |||
200 | static int elanfreq_cpu_init(struct cpufreq_policy *policy) | ||
201 | { | ||
202 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
203 | unsigned int i; | ||
204 | int result; | ||
205 | |||
206 | /* capability check */ | ||
207 | if ((c->x86_vendor != X86_VENDOR_AMD) || | ||
208 | (c->x86 != 4) || (c->x86_model != 10)) | ||
209 | return -ENODEV; | ||
210 | |||
211 | /* max freq */ | ||
212 | if (!max_freq) | ||
213 | max_freq = elanfreq_get_cpu_frequency(0); | ||
214 | |||
215 | /* table init */ | ||
216 | for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
217 | if (elanfreq_table[i].frequency > max_freq) | ||
218 | elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
219 | } | ||
220 | |||
221 | /* cpuinfo and default policy values */ | ||
222 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
223 | policy->cur = elanfreq_get_cpu_frequency(0); | ||
224 | |||
225 | result = cpufreq_frequency_table_cpuinfo(policy, elanfreq_table); | ||
226 | if (result) | ||
227 | return result; | ||
228 | |||
229 | cpufreq_frequency_table_get_attr(elanfreq_table, policy->cpu); | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | |||
234 | static int elanfreq_cpu_exit(struct cpufreq_policy *policy) | ||
235 | { | ||
236 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | |||
241 | #ifndef MODULE | ||
242 | /** | ||
243 | * elanfreq_setup - elanfreq command line parameter parsing | ||
244 | * | ||
245 | * elanfreq command line parameter. Use: | ||
246 | * elanfreq=66000 | ||
247 | * to set the maximum CPU frequency to 66 MHz. Note that in | ||
248 | * case you do not give this boot parameter, the maximum | ||
249 | * frequency will fall back to _current_ CPU frequency which | ||
250 | * might be lower. If you build this as a module, use the | ||
251 | * max_freq module parameter instead. | ||
252 | */ | ||
253 | static int __init elanfreq_setup(char *str) | ||
254 | { | ||
255 | max_freq = simple_strtoul(str, &str, 0); | ||
256 | printk(KERN_WARNING "You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n"); | ||
257 | return 1; | ||
258 | } | ||
259 | __setup("elanfreq=", elanfreq_setup); | ||
260 | #endif | ||
261 | |||
262 | |||
263 | static struct freq_attr *elanfreq_attr[] = { | ||
264 | &cpufreq_freq_attr_scaling_available_freqs, | ||
265 | NULL, | ||
266 | }; | ||
267 | |||
268 | |||
269 | static struct cpufreq_driver elanfreq_driver = { | ||
270 | .get = elanfreq_get_cpu_frequency, | ||
271 | .verify = elanfreq_verify, | ||
272 | .target = elanfreq_target, | ||
273 | .init = elanfreq_cpu_init, | ||
274 | .exit = elanfreq_cpu_exit, | ||
275 | .name = "elanfreq", | ||
276 | .owner = THIS_MODULE, | ||
277 | .attr = elanfreq_attr, | ||
278 | }; | ||
279 | |||
280 | |||
281 | static int __init elanfreq_init(void) | ||
282 | { | ||
283 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
284 | |||
285 | /* Test if we have the right hardware */ | ||
286 | if ((c->x86_vendor != X86_VENDOR_AMD) || | ||
287 | (c->x86 != 4) || (c->x86_model != 10)) { | ||
288 | printk(KERN_INFO "elanfreq: error: no Elan processor found!\n"); | ||
289 | return -ENODEV; | ||
290 | } | ||
291 | return cpufreq_register_driver(&elanfreq_driver); | ||
292 | } | ||
293 | |||
294 | |||
295 | static void __exit elanfreq_exit(void) | ||
296 | { | ||
297 | cpufreq_unregister_driver(&elanfreq_driver); | ||
298 | } | ||
299 | |||
300 | |||
301 | module_param(max_freq, int, 0444); | ||
302 | |||
303 | MODULE_LICENSE("GPL"); | ||
304 | MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, " | ||
305 | "Sven Geggus <sven@geggus.net>"); | ||
306 | MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs"); | ||
307 | |||
308 | module_init(elanfreq_init); | ||
309 | module_exit(elanfreq_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c b/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c deleted file mode 100644 index 32974cf84232..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c +++ /dev/null | |||
@@ -1,517 +0,0 @@ | |||
1 | /* | ||
2 | * Cyrix MediaGX and NatSemi Geode Suspend Modulation | ||
3 | * (C) 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
4 | * (C) 2002 Hiroshi Miura <miura@da-cha.org> | ||
5 | * All Rights Reserved | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation | ||
10 | * | ||
11 | * The author(s) of this software shall not be held liable for damages | ||
12 | * of any nature resulting due to the use of this software. This | ||
13 | * software is provided AS-IS with no warranties. | ||
14 | * | ||
15 | * Theoretical note: | ||
16 | * | ||
17 | * (see Geode(tm) CS5530 manual (rev.4.1) page.56) | ||
18 | * | ||
19 | * CPU frequency control on NatSemi Geode GX1/GXLV processor and CS55x0 | ||
20 | * are based on Suspend Modulation. | ||
21 | * | ||
22 | * Suspend Modulation works by asserting and de-asserting the SUSP# pin | ||
23 | * to CPU(GX1/GXLV) for configurable durations. When asserting SUSP# | ||
24 | * the CPU enters an idle state. GX1 stops its core clock when SUSP# is | ||
25 | * asserted then power consumption is reduced. | ||
26 | * | ||
27 | * Suspend Modulation's OFF/ON duration are configurable | ||
28 | * with 'Suspend Modulation OFF Count Register' | ||
29 | * and 'Suspend Modulation ON Count Register'. | ||
30 | * These registers are 8bit counters that represent the number of | ||
31 | * 32us intervals which the SUSP# pin is asserted(ON)/de-asserted(OFF) | ||
32 | * to the processor. | ||
33 | * | ||
34 | * These counters define a ratio which is the effective frequency | ||
35 | * of operation of the system. | ||
36 | * | ||
37 | * OFF Count | ||
38 | * F_eff = Fgx * ---------------------- | ||
39 | * OFF Count + ON Count | ||
40 | * | ||
41 | * 0 <= On Count, Off Count <= 255 | ||
42 | * | ||
43 | * From these limits, we can get register values | ||
44 | * | ||
45 | * off_duration + on_duration <= MAX_DURATION | ||
46 | * on_duration = off_duration * (stock_freq - freq) / freq | ||
47 | * | ||
48 | * off_duration = (freq * DURATION) / stock_freq | ||
49 | * on_duration = DURATION - off_duration | ||
50 | * | ||
51 | * | ||
52 | *--------------------------------------------------------------------------- | ||
53 | * | ||
54 | * ChangeLog: | ||
55 | * Dec. 12, 2003 Hiroshi Miura <miura@da-cha.org> | ||
56 | * - fix on/off register mistake | ||
57 | * - fix cpu_khz calc when it stops cpu modulation. | ||
58 | * | ||
59 | * Dec. 11, 2002 Hiroshi Miura <miura@da-cha.org> | ||
60 | * - rewrite for Cyrix MediaGX Cx5510/5520 and | ||
61 | * NatSemi Geode Cs5530(A). | ||
62 | * | ||
63 | * Jul. ??, 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
64 | * - cs5530_mod patch for 2.4.19-rc1. | ||
65 | * | ||
66 | *--------------------------------------------------------------------------- | ||
67 | * | ||
68 | * Todo | ||
69 | * Test on machines with 5510, 5530, 5530A | ||
70 | */ | ||
71 | |||
72 | /************************************************************************ | ||
73 | * Suspend Modulation - Definitions * | ||
74 | ************************************************************************/ | ||
75 | |||
76 | #include <linux/kernel.h> | ||
77 | #include <linux/module.h> | ||
78 | #include <linux/init.h> | ||
79 | #include <linux/smp.h> | ||
80 | #include <linux/cpufreq.h> | ||
81 | #include <linux/pci.h> | ||
82 | #include <linux/errno.h> | ||
83 | #include <linux/slab.h> | ||
84 | |||
85 | #include <asm/processor-cyrix.h> | ||
86 | |||
87 | /* PCI config registers, all at F0 */ | ||
88 | #define PCI_PMER1 0x80 /* power management enable register 1 */ | ||
89 | #define PCI_PMER2 0x81 /* power management enable register 2 */ | ||
90 | #define PCI_PMER3 0x82 /* power management enable register 3 */ | ||
91 | #define PCI_IRQTC 0x8c /* irq speedup timer counter register:typical 2 to 4ms */ | ||
92 | #define PCI_VIDTC 0x8d /* video speedup timer counter register: typical 50 to 100ms */ | ||
93 | #define PCI_MODOFF 0x94 /* suspend modulation OFF counter register, 1 = 32us */ | ||
94 | #define PCI_MODON 0x95 /* suspend modulation ON counter register */ | ||
95 | #define PCI_SUSCFG 0x96 /* suspend configuration register */ | ||
96 | |||
97 | /* PMER1 bits */ | ||
98 | #define GPM (1<<0) /* global power management */ | ||
99 | #define GIT (1<<1) /* globally enable PM device idle timers */ | ||
100 | #define GTR (1<<2) /* globally enable IO traps */ | ||
101 | #define IRQ_SPDUP (1<<3) /* disable clock throttle during interrupt handling */ | ||
102 | #define VID_SPDUP (1<<4) /* disable clock throttle during vga video handling */ | ||
103 | |||
104 | /* SUSCFG bits */ | ||
105 | #define SUSMOD (1<<0) /* enable/disable suspend modulation */ | ||
106 | /* the below is supported only with cs5530 (after rev.1.2)/cs5530A */ | ||
107 | #define SMISPDUP (1<<1) /* select how SMI re-enable suspend modulation: */ | ||
108 | /* IRQTC timer or read SMI speedup disable reg.(F1BAR[08-09h]) */ | ||
109 | #define SUSCFG (1<<2) /* enable powering down a GXLV processor. "Special 3Volt Suspend" mode */ | ||
110 | /* the below is supported only with cs5530A */ | ||
111 | #define PWRSVE_ISA (1<<3) /* stop ISA clock */ | ||
112 | #define PWRSVE (1<<4) /* active idle */ | ||
113 | |||
114 | struct gxfreq_params { | ||
115 | u8 on_duration; | ||
116 | u8 off_duration; | ||
117 | u8 pci_suscfg; | ||
118 | u8 pci_pmer1; | ||
119 | u8 pci_pmer2; | ||
120 | struct pci_dev *cs55x0; | ||
121 | }; | ||
122 | |||
123 | static struct gxfreq_params *gx_params; | ||
124 | static int stock_freq; | ||
125 | |||
126 | /* PCI bus clock - defaults to 30.000 if cpu_khz is not available */ | ||
127 | static int pci_busclk; | ||
128 | module_param(pci_busclk, int, 0444); | ||
129 | |||
130 | /* maximum duration for which the cpu may be suspended | ||
131 | * (32us * MAX_DURATION). If no parameter is given, this defaults | ||
132 | * to 255. | ||
133 | * Note that this leads to a maximum of 8 ms(!) where the CPU clock | ||
134 | * is suspended -- processing power is just 0.39% of what it used to be, | ||
135 | * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */ | ||
136 | static int max_duration = 255; | ||
137 | module_param(max_duration, int, 0444); | ||
138 | |||
139 | /* For the default policy, we want at least some processing power | ||
140 | * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV) | ||
141 | */ | ||
142 | #define POLICY_MIN_DIV 20 | ||
143 | |||
144 | |||
145 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
146 | "gx-suspmod", msg) | ||
147 | |||
148 | /** | ||
149 | * we can detect a core multipiler from dir0_lsb | ||
150 | * from GX1 datasheet p.56, | ||
151 | * MULT[3:0]: | ||
152 | * 0000 = SYSCLK multiplied by 4 (test only) | ||
153 | * 0001 = SYSCLK multiplied by 10 | ||
154 | * 0010 = SYSCLK multiplied by 4 | ||
155 | * 0011 = SYSCLK multiplied by 6 | ||
156 | * 0100 = SYSCLK multiplied by 9 | ||
157 | * 0101 = SYSCLK multiplied by 5 | ||
158 | * 0110 = SYSCLK multiplied by 7 | ||
159 | * 0111 = SYSCLK multiplied by 8 | ||
160 | * of 33.3MHz | ||
161 | **/ | ||
162 | static int gx_freq_mult[16] = { | ||
163 | 4, 10, 4, 6, 9, 5, 7, 8, | ||
164 | 0, 0, 0, 0, 0, 0, 0, 0 | ||
165 | }; | ||
166 | |||
167 | |||
168 | /**************************************************************** | ||
169 | * Low Level chipset interface * | ||
170 | ****************************************************************/ | ||
171 | static struct pci_device_id gx_chipset_tbl[] __initdata = { | ||
172 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY), }, | ||
173 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5520), }, | ||
174 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), }, | ||
175 | { 0, }, | ||
176 | }; | ||
177 | |||
178 | static void gx_write_byte(int reg, int value) | ||
179 | { | ||
180 | pci_write_config_byte(gx_params->cs55x0, reg, value); | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * gx_detect_chipset: | ||
185 | * | ||
186 | **/ | ||
187 | static __init struct pci_dev *gx_detect_chipset(void) | ||
188 | { | ||
189 | struct pci_dev *gx_pci = NULL; | ||
190 | |||
191 | /* check if CPU is a MediaGX or a Geode. */ | ||
192 | if ((boot_cpu_data.x86_vendor != X86_VENDOR_NSC) && | ||
193 | (boot_cpu_data.x86_vendor != X86_VENDOR_CYRIX)) { | ||
194 | dprintk("error: no MediaGX/Geode processor found!\n"); | ||
195 | return NULL; | ||
196 | } | ||
197 | |||
198 | /* detect which companion chip is used */ | ||
199 | for_each_pci_dev(gx_pci) { | ||
200 | if ((pci_match_id(gx_chipset_tbl, gx_pci)) != NULL) | ||
201 | return gx_pci; | ||
202 | } | ||
203 | |||
204 | dprintk("error: no supported chipset found!\n"); | ||
205 | return NULL; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * gx_get_cpuspeed: | ||
210 | * | ||
211 | * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi | ||
212 | * Geode CPU runs. | ||
213 | */ | ||
214 | static unsigned int gx_get_cpuspeed(unsigned int cpu) | ||
215 | { | ||
216 | if ((gx_params->pci_suscfg & SUSMOD) == 0) | ||
217 | return stock_freq; | ||
218 | |||
219 | return (stock_freq * gx_params->off_duration) | ||
220 | / (gx_params->on_duration + gx_params->off_duration); | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * gx_validate_speed: | ||
225 | * determine current cpu speed | ||
226 | * | ||
227 | **/ | ||
228 | |||
229 | static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration, | ||
230 | u8 *off_duration) | ||
231 | { | ||
232 | unsigned int i; | ||
233 | u8 tmp_on, tmp_off; | ||
234 | int old_tmp_freq = stock_freq; | ||
235 | int tmp_freq; | ||
236 | |||
237 | *off_duration = 1; | ||
238 | *on_duration = 0; | ||
239 | |||
240 | for (i = max_duration; i > 0; i--) { | ||
241 | tmp_off = ((khz * i) / stock_freq) & 0xff; | ||
242 | tmp_on = i - tmp_off; | ||
243 | tmp_freq = (stock_freq * tmp_off) / i; | ||
244 | /* if this relation is closer to khz, use this. If it's equal, | ||
245 | * prefer it, too - lower latency */ | ||
246 | if (abs(tmp_freq - khz) <= abs(old_tmp_freq - khz)) { | ||
247 | *on_duration = tmp_on; | ||
248 | *off_duration = tmp_off; | ||
249 | old_tmp_freq = tmp_freq; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | return old_tmp_freq; | ||
254 | } | ||
255 | |||
256 | |||
257 | /** | ||
258 | * gx_set_cpuspeed: | ||
259 | * set cpu speed in khz. | ||
260 | **/ | ||
261 | |||
262 | static void gx_set_cpuspeed(unsigned int khz) | ||
263 | { | ||
264 | u8 suscfg, pmer1; | ||
265 | unsigned int new_khz; | ||
266 | unsigned long flags; | ||
267 | struct cpufreq_freqs freqs; | ||
268 | |||
269 | freqs.cpu = 0; | ||
270 | freqs.old = gx_get_cpuspeed(0); | ||
271 | |||
272 | new_khz = gx_validate_speed(khz, &gx_params->on_duration, | ||
273 | &gx_params->off_duration); | ||
274 | |||
275 | freqs.new = new_khz; | ||
276 | |||
277 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
278 | local_irq_save(flags); | ||
279 | |||
280 | |||
281 | |||
282 | if (new_khz != stock_freq) { | ||
283 | /* if new khz == 100% of CPU speed, it is special case */ | ||
284 | switch (gx_params->cs55x0->device) { | ||
285 | case PCI_DEVICE_ID_CYRIX_5530_LEGACY: | ||
286 | pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP; | ||
287 | /* FIXME: need to test other values -- Zwane,Miura */ | ||
288 | /* typical 2 to 4ms */ | ||
289 | gx_write_byte(PCI_IRQTC, 4); | ||
290 | /* typical 50 to 100ms */ | ||
291 | gx_write_byte(PCI_VIDTC, 100); | ||
292 | gx_write_byte(PCI_PMER1, pmer1); | ||
293 | |||
294 | if (gx_params->cs55x0->revision < 0x10) { | ||
295 | /* CS5530(rev 1.2, 1.3) */ | ||
296 | suscfg = gx_params->pci_suscfg|SUSMOD; | ||
297 | } else { | ||
298 | /* CS5530A,B.. */ | ||
299 | suscfg = gx_params->pci_suscfg|SUSMOD|PWRSVE; | ||
300 | } | ||
301 | break; | ||
302 | case PCI_DEVICE_ID_CYRIX_5520: | ||
303 | case PCI_DEVICE_ID_CYRIX_5510: | ||
304 | suscfg = gx_params->pci_suscfg | SUSMOD; | ||
305 | break; | ||
306 | default: | ||
307 | local_irq_restore(flags); | ||
308 | dprintk("fatal: try to set unknown chipset.\n"); | ||
309 | return; | ||
310 | } | ||
311 | } else { | ||
312 | suscfg = gx_params->pci_suscfg & ~(SUSMOD); | ||
313 | gx_params->off_duration = 0; | ||
314 | gx_params->on_duration = 0; | ||
315 | dprintk("suspend modulation disabled: cpu runs 100%% speed.\n"); | ||
316 | } | ||
317 | |||
318 | gx_write_byte(PCI_MODOFF, gx_params->off_duration); | ||
319 | gx_write_byte(PCI_MODON, gx_params->on_duration); | ||
320 | |||
321 | gx_write_byte(PCI_SUSCFG, suscfg); | ||
322 | pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg); | ||
323 | |||
324 | local_irq_restore(flags); | ||
325 | |||
326 | gx_params->pci_suscfg = suscfg; | ||
327 | |||
328 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
329 | |||
330 | dprintk("suspend modulation w/ duration of ON:%d us, OFF:%d us\n", | ||
331 | gx_params->on_duration * 32, gx_params->off_duration * 32); | ||
332 | dprintk("suspend modulation w/ clock speed: %d kHz.\n", freqs.new); | ||
333 | } | ||
334 | |||
335 | /**************************************************************** | ||
336 | * High level functions * | ||
337 | ****************************************************************/ | ||
338 | |||
339 | /* | ||
340 | * cpufreq_gx_verify: test if frequency range is valid | ||
341 | * | ||
342 | * This function checks if a given frequency range in kHz is valid | ||
343 | * for the hardware supported by the driver. | ||
344 | */ | ||
345 | |||
346 | static int cpufreq_gx_verify(struct cpufreq_policy *policy) | ||
347 | { | ||
348 | unsigned int tmp_freq = 0; | ||
349 | u8 tmp1, tmp2; | ||
350 | |||
351 | if (!stock_freq || !policy) | ||
352 | return -EINVAL; | ||
353 | |||
354 | policy->cpu = 0; | ||
355 | cpufreq_verify_within_limits(policy, (stock_freq / max_duration), | ||
356 | stock_freq); | ||
357 | |||
358 | /* it needs to be assured that at least one supported frequency is | ||
359 | * within policy->min and policy->max. If it is not, policy->max | ||
360 | * needs to be increased until one freuqency is supported. | ||
361 | * policy->min may not be decreased, though. This way we guarantee a | ||
362 | * specific processing capacity. | ||
363 | */ | ||
364 | tmp_freq = gx_validate_speed(policy->min, &tmp1, &tmp2); | ||
365 | if (tmp_freq < policy->min) | ||
366 | tmp_freq += stock_freq / max_duration; | ||
367 | policy->min = tmp_freq; | ||
368 | if (policy->min > policy->max) | ||
369 | policy->max = tmp_freq; | ||
370 | tmp_freq = gx_validate_speed(policy->max, &tmp1, &tmp2); | ||
371 | if (tmp_freq > policy->max) | ||
372 | tmp_freq -= stock_freq / max_duration; | ||
373 | policy->max = tmp_freq; | ||
374 | if (policy->max < policy->min) | ||
375 | policy->max = policy->min; | ||
376 | cpufreq_verify_within_limits(policy, (stock_freq / max_duration), | ||
377 | stock_freq); | ||
378 | |||
379 | return 0; | ||
380 | } | ||
381 | |||
382 | /* | ||
383 | * cpufreq_gx_target: | ||
384 | * | ||
385 | */ | ||
386 | static int cpufreq_gx_target(struct cpufreq_policy *policy, | ||
387 | unsigned int target_freq, | ||
388 | unsigned int relation) | ||
389 | { | ||
390 | u8 tmp1, tmp2; | ||
391 | unsigned int tmp_freq; | ||
392 | |||
393 | if (!stock_freq || !policy) | ||
394 | return -EINVAL; | ||
395 | |||
396 | policy->cpu = 0; | ||
397 | |||
398 | tmp_freq = gx_validate_speed(target_freq, &tmp1, &tmp2); | ||
399 | while (tmp_freq < policy->min) { | ||
400 | tmp_freq += stock_freq / max_duration; | ||
401 | tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2); | ||
402 | } | ||
403 | while (tmp_freq > policy->max) { | ||
404 | tmp_freq -= stock_freq / max_duration; | ||
405 | tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2); | ||
406 | } | ||
407 | |||
408 | gx_set_cpuspeed(tmp_freq); | ||
409 | |||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy) | ||
414 | { | ||
415 | unsigned int maxfreq, curfreq; | ||
416 | |||
417 | if (!policy || policy->cpu != 0) | ||
418 | return -ENODEV; | ||
419 | |||
420 | /* determine maximum frequency */ | ||
421 | if (pci_busclk) | ||
422 | maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; | ||
423 | else if (cpu_khz) | ||
424 | maxfreq = cpu_khz; | ||
425 | else | ||
426 | maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; | ||
427 | |||
428 | stock_freq = maxfreq; | ||
429 | curfreq = gx_get_cpuspeed(0); | ||
430 | |||
431 | dprintk("cpu max frequency is %d.\n", maxfreq); | ||
432 | dprintk("cpu current frequency is %dkHz.\n", curfreq); | ||
433 | |||
434 | /* setup basic struct for cpufreq API */ | ||
435 | policy->cpu = 0; | ||
436 | |||
437 | if (max_duration < POLICY_MIN_DIV) | ||
438 | policy->min = maxfreq / max_duration; | ||
439 | else | ||
440 | policy->min = maxfreq / POLICY_MIN_DIV; | ||
441 | policy->max = maxfreq; | ||
442 | policy->cur = curfreq; | ||
443 | policy->cpuinfo.min_freq = maxfreq / max_duration; | ||
444 | policy->cpuinfo.max_freq = maxfreq; | ||
445 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
446 | |||
447 | return 0; | ||
448 | } | ||
449 | |||
450 | /* | ||
451 | * cpufreq_gx_init: | ||
452 | * MediaGX/Geode GX initialize cpufreq driver | ||
453 | */ | ||
454 | static struct cpufreq_driver gx_suspmod_driver = { | ||
455 | .get = gx_get_cpuspeed, | ||
456 | .verify = cpufreq_gx_verify, | ||
457 | .target = cpufreq_gx_target, | ||
458 | .init = cpufreq_gx_cpu_init, | ||
459 | .name = "gx-suspmod", | ||
460 | .owner = THIS_MODULE, | ||
461 | }; | ||
462 | |||
463 | static int __init cpufreq_gx_init(void) | ||
464 | { | ||
465 | int ret; | ||
466 | struct gxfreq_params *params; | ||
467 | struct pci_dev *gx_pci; | ||
468 | |||
469 | /* Test if we have the right hardware */ | ||
470 | gx_pci = gx_detect_chipset(); | ||
471 | if (gx_pci == NULL) | ||
472 | return -ENODEV; | ||
473 | |||
474 | /* check whether module parameters are sane */ | ||
475 | if (max_duration > 0xff) | ||
476 | max_duration = 0xff; | ||
477 | |||
478 | dprintk("geode suspend modulation available.\n"); | ||
479 | |||
480 | params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL); | ||
481 | if (params == NULL) | ||
482 | return -ENOMEM; | ||
483 | |||
484 | params->cs55x0 = gx_pci; | ||
485 | gx_params = params; | ||
486 | |||
487 | /* keep cs55x0 configurations */ | ||
488 | pci_read_config_byte(params->cs55x0, PCI_SUSCFG, &(params->pci_suscfg)); | ||
489 | pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1)); | ||
490 | pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2)); | ||
491 | pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration)); | ||
492 | pci_read_config_byte(params->cs55x0, PCI_MODOFF, | ||
493 | &(params->off_duration)); | ||
494 | |||
495 | ret = cpufreq_register_driver(&gx_suspmod_driver); | ||
496 | if (ret) { | ||
497 | kfree(params); | ||
498 | return ret; /* register error! */ | ||
499 | } | ||
500 | |||
501 | return 0; | ||
502 | } | ||
503 | |||
504 | static void __exit cpufreq_gx_exit(void) | ||
505 | { | ||
506 | cpufreq_unregister_driver(&gx_suspmod_driver); | ||
507 | pci_dev_put(gx_params->cs55x0); | ||
508 | kfree(gx_params); | ||
509 | } | ||
510 | |||
511 | MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>"); | ||
512 | MODULE_DESCRIPTION("Cpufreq driver for Cyrix MediaGX and NatSemi Geode"); | ||
513 | MODULE_LICENSE("GPL"); | ||
514 | |||
515 | module_init(cpufreq_gx_init); | ||
516 | module_exit(cpufreq_gx_exit); | ||
517 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.c b/arch/x86/kernel/cpu/cpufreq/longhaul.c deleted file mode 100644 index 03162dac6271..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/longhaul.c +++ /dev/null | |||
@@ -1,1029 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2001-2004 Dave Jones. <davej@redhat.com> | ||
3 | * (C) 2002 Padraig Brady. <padraig@antefacto.com> | ||
4 | * | ||
5 | * Licensed under the terms of the GNU GPL License version 2. | ||
6 | * Based upon datasheets & sample CPUs kindly provided by VIA. | ||
7 | * | ||
8 | * VIA have currently 3 different versions of Longhaul. | ||
9 | * Version 1 (Longhaul) uses the BCR2 MSR at 0x1147. | ||
10 | * It is present only in Samuel 1 (C5A), Samuel 2 (C5B) stepping 0. | ||
11 | * Version 2 of longhaul is backward compatible with v1, but adds | ||
12 | * LONGHAUL MSR for purpose of both frequency and voltage scaling. | ||
13 | * Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C). | ||
14 | * Version 3 of longhaul got renamed to Powersaver and redesigned | ||
15 | * to use only the POWERSAVER MSR at 0x110a. | ||
16 | * It is present in Ezra-T (C5M), Nehemiah (C5X) and above. | ||
17 | * It's pretty much the same feature wise to longhaul v2, though | ||
18 | * there is provision for scaling FSB too, but this doesn't work | ||
19 | * too well in practice so we don't even try to use this. | ||
20 | * | ||
21 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/moduleparam.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/cpufreq.h> | ||
29 | #include <linux/pci.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/string.h> | ||
32 | #include <linux/delay.h> | ||
33 | #include <linux/timex.h> | ||
34 | #include <linux/io.h> | ||
35 | #include <linux/acpi.h> | ||
36 | |||
37 | #include <asm/msr.h> | ||
38 | #include <acpi/processor.h> | ||
39 | |||
40 | #include "longhaul.h" | ||
41 | |||
42 | #define PFX "longhaul: " | ||
43 | |||
44 | #define TYPE_LONGHAUL_V1 1 | ||
45 | #define TYPE_LONGHAUL_V2 2 | ||
46 | #define TYPE_POWERSAVER 3 | ||
47 | |||
48 | #define CPU_SAMUEL 1 | ||
49 | #define CPU_SAMUEL2 2 | ||
50 | #define CPU_EZRA 3 | ||
51 | #define CPU_EZRA_T 4 | ||
52 | #define CPU_NEHEMIAH 5 | ||
53 | #define CPU_NEHEMIAH_C 6 | ||
54 | |||
55 | /* Flags */ | ||
56 | #define USE_ACPI_C3 (1 << 1) | ||
57 | #define USE_NORTHBRIDGE (1 << 2) | ||
58 | |||
59 | static int cpu_model; | ||
60 | static unsigned int numscales = 16; | ||
61 | static unsigned int fsb; | ||
62 | |||
63 | static const struct mV_pos *vrm_mV_table; | ||
64 | static const unsigned char *mV_vrm_table; | ||
65 | |||
66 | static unsigned int highest_speed, lowest_speed; /* kHz */ | ||
67 | static unsigned int minmult, maxmult; | ||
68 | static int can_scale_voltage; | ||
69 | static struct acpi_processor *pr; | ||
70 | static struct acpi_processor_cx *cx; | ||
71 | static u32 acpi_regs_addr; | ||
72 | static u8 longhaul_flags; | ||
73 | static unsigned int longhaul_index; | ||
74 | |||
75 | /* Module parameters */ | ||
76 | static int scale_voltage; | ||
77 | static int disable_acpi_c3; | ||
78 | static int revid_errata; | ||
79 | |||
80 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
81 | "longhaul", msg) | ||
82 | |||
83 | |||
84 | /* Clock ratios multiplied by 10 */ | ||
85 | static int mults[32]; | ||
86 | static int eblcr[32]; | ||
87 | static int longhaul_version; | ||
88 | static struct cpufreq_frequency_table *longhaul_table; | ||
89 | |||
90 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
91 | static char speedbuffer[8]; | ||
92 | |||
93 | static char *print_speed(int speed) | ||
94 | { | ||
95 | if (speed < 1000) { | ||
96 | snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed); | ||
97 | return speedbuffer; | ||
98 | } | ||
99 | |||
100 | if (speed%1000 == 0) | ||
101 | snprintf(speedbuffer, sizeof(speedbuffer), | ||
102 | "%dGHz", speed/1000); | ||
103 | else | ||
104 | snprintf(speedbuffer, sizeof(speedbuffer), | ||
105 | "%d.%dGHz", speed/1000, (speed%1000)/100); | ||
106 | |||
107 | return speedbuffer; | ||
108 | } | ||
109 | #endif | ||
110 | |||
111 | |||
112 | static unsigned int calc_speed(int mult) | ||
113 | { | ||
114 | int khz; | ||
115 | khz = (mult/10)*fsb; | ||
116 | if (mult%10) | ||
117 | khz += fsb/2; | ||
118 | khz *= 1000; | ||
119 | return khz; | ||
120 | } | ||
121 | |||
122 | |||
123 | static int longhaul_get_cpu_mult(void) | ||
124 | { | ||
125 | unsigned long invalue = 0, lo, hi; | ||
126 | |||
127 | rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi); | ||
128 | invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22; | ||
129 | if (longhaul_version == TYPE_LONGHAUL_V2 || | ||
130 | longhaul_version == TYPE_POWERSAVER) { | ||
131 | if (lo & (1<<27)) | ||
132 | invalue += 16; | ||
133 | } | ||
134 | return eblcr[invalue]; | ||
135 | } | ||
136 | |||
137 | /* For processor with BCR2 MSR */ | ||
138 | |||
139 | static void do_longhaul1(unsigned int mults_index) | ||
140 | { | ||
141 | union msr_bcr2 bcr2; | ||
142 | |||
143 | rdmsrl(MSR_VIA_BCR2, bcr2.val); | ||
144 | /* Enable software clock multiplier */ | ||
145 | bcr2.bits.ESOFTBF = 1; | ||
146 | bcr2.bits.CLOCKMUL = mults_index & 0xff; | ||
147 | |||
148 | /* Sync to timer tick */ | ||
149 | safe_halt(); | ||
150 | /* Change frequency on next halt or sleep */ | ||
151 | wrmsrl(MSR_VIA_BCR2, bcr2.val); | ||
152 | /* Invoke transition */ | ||
153 | ACPI_FLUSH_CPU_CACHE(); | ||
154 | halt(); | ||
155 | |||
156 | /* Disable software clock multiplier */ | ||
157 | local_irq_disable(); | ||
158 | rdmsrl(MSR_VIA_BCR2, bcr2.val); | ||
159 | bcr2.bits.ESOFTBF = 0; | ||
160 | wrmsrl(MSR_VIA_BCR2, bcr2.val); | ||
161 | } | ||
162 | |||
163 | /* For processor with Longhaul MSR */ | ||
164 | |||
165 | static void do_powersaver(int cx_address, unsigned int mults_index, | ||
166 | unsigned int dir) | ||
167 | { | ||
168 | union msr_longhaul longhaul; | ||
169 | u32 t; | ||
170 | |||
171 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
172 | /* Setup new frequency */ | ||
173 | if (!revid_errata) | ||
174 | longhaul.bits.RevisionKey = longhaul.bits.RevisionID; | ||
175 | else | ||
176 | longhaul.bits.RevisionKey = 0; | ||
177 | longhaul.bits.SoftBusRatio = mults_index & 0xf; | ||
178 | longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4; | ||
179 | /* Setup new voltage */ | ||
180 | if (can_scale_voltage) | ||
181 | longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f; | ||
182 | /* Sync to timer tick */ | ||
183 | safe_halt(); | ||
184 | /* Raise voltage if necessary */ | ||
185 | if (can_scale_voltage && dir) { | ||
186 | longhaul.bits.EnableSoftVID = 1; | ||
187 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
188 | /* Change voltage */ | ||
189 | if (!cx_address) { | ||
190 | ACPI_FLUSH_CPU_CACHE(); | ||
191 | halt(); | ||
192 | } else { | ||
193 | ACPI_FLUSH_CPU_CACHE(); | ||
194 | /* Invoke C3 */ | ||
195 | inb(cx_address); | ||
196 | /* Dummy op - must do something useless after P_LVL3 | ||
197 | * read */ | ||
198 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
199 | } | ||
200 | longhaul.bits.EnableSoftVID = 0; | ||
201 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
202 | } | ||
203 | |||
204 | /* Change frequency on next halt or sleep */ | ||
205 | longhaul.bits.EnableSoftBusRatio = 1; | ||
206 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
207 | if (!cx_address) { | ||
208 | ACPI_FLUSH_CPU_CACHE(); | ||
209 | halt(); | ||
210 | } else { | ||
211 | ACPI_FLUSH_CPU_CACHE(); | ||
212 | /* Invoke C3 */ | ||
213 | inb(cx_address); | ||
214 | /* Dummy op - must do something useless after P_LVL3 read */ | ||
215 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
216 | } | ||
217 | /* Disable bus ratio bit */ | ||
218 | longhaul.bits.EnableSoftBusRatio = 0; | ||
219 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
220 | |||
221 | /* Reduce voltage if necessary */ | ||
222 | if (can_scale_voltage && !dir) { | ||
223 | longhaul.bits.EnableSoftVID = 1; | ||
224 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
225 | /* Change voltage */ | ||
226 | if (!cx_address) { | ||
227 | ACPI_FLUSH_CPU_CACHE(); | ||
228 | halt(); | ||
229 | } else { | ||
230 | ACPI_FLUSH_CPU_CACHE(); | ||
231 | /* Invoke C3 */ | ||
232 | inb(cx_address); | ||
233 | /* Dummy op - must do something useless after P_LVL3 | ||
234 | * read */ | ||
235 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
236 | } | ||
237 | longhaul.bits.EnableSoftVID = 0; | ||
238 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * longhaul_set_cpu_frequency() | ||
244 | * @mults_index : bitpattern of the new multiplier. | ||
245 | * | ||
246 | * Sets a new clock ratio. | ||
247 | */ | ||
248 | |||
249 | static void longhaul_setstate(unsigned int table_index) | ||
250 | { | ||
251 | unsigned int mults_index; | ||
252 | int speed, mult; | ||
253 | struct cpufreq_freqs freqs; | ||
254 | unsigned long flags; | ||
255 | unsigned int pic1_mask, pic2_mask; | ||
256 | u16 bm_status = 0; | ||
257 | u32 bm_timeout = 1000; | ||
258 | unsigned int dir = 0; | ||
259 | |||
260 | mults_index = longhaul_table[table_index].index; | ||
261 | /* Safety precautions */ | ||
262 | mult = mults[mults_index & 0x1f]; | ||
263 | if (mult == -1) | ||
264 | return; | ||
265 | speed = calc_speed(mult); | ||
266 | if ((speed > highest_speed) || (speed < lowest_speed)) | ||
267 | return; | ||
268 | /* Voltage transition before frequency transition? */ | ||
269 | if (can_scale_voltage && longhaul_index < table_index) | ||
270 | dir = 1; | ||
271 | |||
272 | freqs.old = calc_speed(longhaul_get_cpu_mult()); | ||
273 | freqs.new = speed; | ||
274 | freqs.cpu = 0; /* longhaul.c is UP only driver */ | ||
275 | |||
276 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
277 | |||
278 | dprintk("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n", | ||
279 | fsb, mult/10, mult%10, print_speed(speed/1000)); | ||
280 | retry_loop: | ||
281 | preempt_disable(); | ||
282 | local_irq_save(flags); | ||
283 | |||
284 | pic2_mask = inb(0xA1); | ||
285 | pic1_mask = inb(0x21); /* works on C3. save mask. */ | ||
286 | outb(0xFF, 0xA1); /* Overkill */ | ||
287 | outb(0xFE, 0x21); /* TMR0 only */ | ||
288 | |||
289 | /* Wait while PCI bus is busy. */ | ||
290 | if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE | ||
291 | || ((pr != NULL) && pr->flags.bm_control))) { | ||
292 | bm_status = inw(acpi_regs_addr); | ||
293 | bm_status &= 1 << 4; | ||
294 | while (bm_status && bm_timeout) { | ||
295 | outw(1 << 4, acpi_regs_addr); | ||
296 | bm_timeout--; | ||
297 | bm_status = inw(acpi_regs_addr); | ||
298 | bm_status &= 1 << 4; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | if (longhaul_flags & USE_NORTHBRIDGE) { | ||
303 | /* Disable AGP and PCI arbiters */ | ||
304 | outb(3, 0x22); | ||
305 | } else if ((pr != NULL) && pr->flags.bm_control) { | ||
306 | /* Disable bus master arbitration */ | ||
307 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1); | ||
308 | } | ||
309 | switch (longhaul_version) { | ||
310 | |||
311 | /* | ||
312 | * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B]) | ||
313 | * Software controlled multipliers only. | ||
314 | */ | ||
315 | case TYPE_LONGHAUL_V1: | ||
316 | do_longhaul1(mults_index); | ||
317 | break; | ||
318 | |||
319 | /* | ||
320 | * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5B] and Ezra [C5C] | ||
321 | * | ||
322 | * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N]) | ||
323 | * Nehemiah can do FSB scaling too, but this has never been proven | ||
324 | * to work in practice. | ||
325 | */ | ||
326 | case TYPE_LONGHAUL_V2: | ||
327 | case TYPE_POWERSAVER: | ||
328 | if (longhaul_flags & USE_ACPI_C3) { | ||
329 | /* Don't allow wakeup */ | ||
330 | acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 0); | ||
331 | do_powersaver(cx->address, mults_index, dir); | ||
332 | } else { | ||
333 | do_powersaver(0, mults_index, dir); | ||
334 | } | ||
335 | break; | ||
336 | } | ||
337 | |||
338 | if (longhaul_flags & USE_NORTHBRIDGE) { | ||
339 | /* Enable arbiters */ | ||
340 | outb(0, 0x22); | ||
341 | } else if ((pr != NULL) && pr->flags.bm_control) { | ||
342 | /* Enable bus master arbitration */ | ||
343 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0); | ||
344 | } | ||
345 | outb(pic2_mask, 0xA1); /* restore mask */ | ||
346 | outb(pic1_mask, 0x21); | ||
347 | |||
348 | local_irq_restore(flags); | ||
349 | preempt_enable(); | ||
350 | |||
351 | freqs.new = calc_speed(longhaul_get_cpu_mult()); | ||
352 | /* Check if requested frequency is set. */ | ||
353 | if (unlikely(freqs.new != speed)) { | ||
354 | printk(KERN_INFO PFX "Failed to set requested frequency!\n"); | ||
355 | /* Revision ID = 1 but processor is expecting revision key | ||
356 | * equal to 0. Jumpers at the bottom of processor will change | ||
357 | * multiplier and FSB, but will not change bits in Longhaul | ||
358 | * MSR nor enable voltage scaling. */ | ||
359 | if (!revid_errata) { | ||
360 | printk(KERN_INFO PFX "Enabling \"Ignore Revision ID\" " | ||
361 | "option.\n"); | ||
362 | revid_errata = 1; | ||
363 | msleep(200); | ||
364 | goto retry_loop; | ||
365 | } | ||
366 | /* Why ACPI C3 sometimes doesn't work is a mystery for me. | ||
367 | * But it does happen. Processor is entering ACPI C3 state, | ||
368 | * but it doesn't change frequency. I tried poking various | ||
369 | * bits in northbridge registers, but without success. */ | ||
370 | if (longhaul_flags & USE_ACPI_C3) { | ||
371 | printk(KERN_INFO PFX "Disabling ACPI C3 support.\n"); | ||
372 | longhaul_flags &= ~USE_ACPI_C3; | ||
373 | if (revid_errata) { | ||
374 | printk(KERN_INFO PFX "Disabling \"Ignore " | ||
375 | "Revision ID\" option.\n"); | ||
376 | revid_errata = 0; | ||
377 | } | ||
378 | msleep(200); | ||
379 | goto retry_loop; | ||
380 | } | ||
381 | /* This shouldn't happen. Longhaul ver. 2 was reported not | ||
382 | * working on processors without voltage scaling, but with | ||
383 | * RevID = 1. RevID errata will make things right. Just | ||
384 | * to be 100% sure. */ | ||
385 | if (longhaul_version == TYPE_LONGHAUL_V2) { | ||
386 | printk(KERN_INFO PFX "Switching to Longhaul ver. 1\n"); | ||
387 | longhaul_version = TYPE_LONGHAUL_V1; | ||
388 | msleep(200); | ||
389 | goto retry_loop; | ||
390 | } | ||
391 | } | ||
392 | /* Report true CPU frequency */ | ||
393 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
394 | |||
395 | if (!bm_timeout) | ||
396 | printk(KERN_INFO PFX "Warning: Timeout while waiting for " | ||
397 | "idle PCI bus.\n"); | ||
398 | } | ||
399 | |||
400 | /* | ||
401 | * Centaur decided to make life a little more tricky. | ||
402 | * Only longhaul v1 is allowed to read EBLCR BSEL[0:1]. | ||
403 | * Samuel2 and above have to try and guess what the FSB is. | ||
404 | * We do this by assuming we booted at maximum multiplier, and interpolate | ||
405 | * between that value multiplied by possible FSBs and cpu_mhz which | ||
406 | * was calculated at boot time. Really ugly, but no other way to do this. | ||
407 | */ | ||
408 | |||
409 | #define ROUNDING 0xf | ||
410 | |||
411 | static int guess_fsb(int mult) | ||
412 | { | ||
413 | int speed = cpu_khz / 1000; | ||
414 | int i; | ||
415 | int speeds[] = { 666, 1000, 1333, 2000 }; | ||
416 | int f_max, f_min; | ||
417 | |||
418 | for (i = 0; i < 4; i++) { | ||
419 | f_max = ((speeds[i] * mult) + 50) / 100; | ||
420 | f_max += (ROUNDING / 2); | ||
421 | f_min = f_max - ROUNDING; | ||
422 | if ((speed <= f_max) && (speed >= f_min)) | ||
423 | return speeds[i] / 10; | ||
424 | } | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | |||
429 | static int __cpuinit longhaul_get_ranges(void) | ||
430 | { | ||
431 | unsigned int i, j, k = 0; | ||
432 | unsigned int ratio; | ||
433 | int mult; | ||
434 | |||
435 | /* Get current frequency */ | ||
436 | mult = longhaul_get_cpu_mult(); | ||
437 | if (mult == -1) { | ||
438 | printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n"); | ||
439 | return -EINVAL; | ||
440 | } | ||
441 | fsb = guess_fsb(mult); | ||
442 | if (fsb == 0) { | ||
443 | printk(KERN_INFO PFX "Invalid (reserved) FSB!\n"); | ||
444 | return -EINVAL; | ||
445 | } | ||
446 | /* Get max multiplier - as we always did. | ||
447 | * Longhaul MSR is usefull only when voltage scaling is enabled. | ||
448 | * C3 is booting at max anyway. */ | ||
449 | maxmult = mult; | ||
450 | /* Get min multiplier */ | ||
451 | switch (cpu_model) { | ||
452 | case CPU_NEHEMIAH: | ||
453 | minmult = 50; | ||
454 | break; | ||
455 | case CPU_NEHEMIAH_C: | ||
456 | minmult = 40; | ||
457 | break; | ||
458 | default: | ||
459 | minmult = 30; | ||
460 | break; | ||
461 | } | ||
462 | |||
463 | dprintk("MinMult:%d.%dx MaxMult:%d.%dx\n", | ||
464 | minmult/10, minmult%10, maxmult/10, maxmult%10); | ||
465 | |||
466 | highest_speed = calc_speed(maxmult); | ||
467 | lowest_speed = calc_speed(minmult); | ||
468 | dprintk("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, | ||
469 | print_speed(lowest_speed/1000), | ||
470 | print_speed(highest_speed/1000)); | ||
471 | |||
472 | if (lowest_speed == highest_speed) { | ||
473 | printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n"); | ||
474 | return -EINVAL; | ||
475 | } | ||
476 | if (lowest_speed > highest_speed) { | ||
477 | printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n", | ||
478 | lowest_speed, highest_speed); | ||
479 | return -EINVAL; | ||
480 | } | ||
481 | |||
482 | longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table), | ||
483 | GFP_KERNEL); | ||
484 | if (!longhaul_table) | ||
485 | return -ENOMEM; | ||
486 | |||
487 | for (j = 0; j < numscales; j++) { | ||
488 | ratio = mults[j]; | ||
489 | if (ratio == -1) | ||
490 | continue; | ||
491 | if (ratio > maxmult || ratio < minmult) | ||
492 | continue; | ||
493 | longhaul_table[k].frequency = calc_speed(ratio); | ||
494 | longhaul_table[k].index = j; | ||
495 | k++; | ||
496 | } | ||
497 | if (k <= 1) { | ||
498 | kfree(longhaul_table); | ||
499 | return -ENODEV; | ||
500 | } | ||
501 | /* Sort */ | ||
502 | for (j = 0; j < k - 1; j++) { | ||
503 | unsigned int min_f, min_i; | ||
504 | min_f = longhaul_table[j].frequency; | ||
505 | min_i = j; | ||
506 | for (i = j + 1; i < k; i++) { | ||
507 | if (longhaul_table[i].frequency < min_f) { | ||
508 | min_f = longhaul_table[i].frequency; | ||
509 | min_i = i; | ||
510 | } | ||
511 | } | ||
512 | if (min_i != j) { | ||
513 | swap(longhaul_table[j].frequency, | ||
514 | longhaul_table[min_i].frequency); | ||
515 | swap(longhaul_table[j].index, | ||
516 | longhaul_table[min_i].index); | ||
517 | } | ||
518 | } | ||
519 | |||
520 | longhaul_table[k].frequency = CPUFREQ_TABLE_END; | ||
521 | |||
522 | /* Find index we are running on */ | ||
523 | for (j = 0; j < k; j++) { | ||
524 | if (mults[longhaul_table[j].index & 0x1f] == mult) { | ||
525 | longhaul_index = j; | ||
526 | break; | ||
527 | } | ||
528 | } | ||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | |||
533 | static void __cpuinit longhaul_setup_voltagescaling(void) | ||
534 | { | ||
535 | union msr_longhaul longhaul; | ||
536 | struct mV_pos minvid, maxvid, vid; | ||
537 | unsigned int j, speed, pos, kHz_step, numvscales; | ||
538 | int min_vid_speed; | ||
539 | |||
540 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
541 | if (!(longhaul.bits.RevisionID & 1)) { | ||
542 | printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n"); | ||
543 | return; | ||
544 | } | ||
545 | |||
546 | if (!longhaul.bits.VRMRev) { | ||
547 | printk(KERN_INFO PFX "VRM 8.5\n"); | ||
548 | vrm_mV_table = &vrm85_mV[0]; | ||
549 | mV_vrm_table = &mV_vrm85[0]; | ||
550 | } else { | ||
551 | printk(KERN_INFO PFX "Mobile VRM\n"); | ||
552 | if (cpu_model < CPU_NEHEMIAH) | ||
553 | return; | ||
554 | vrm_mV_table = &mobilevrm_mV[0]; | ||
555 | mV_vrm_table = &mV_mobilevrm[0]; | ||
556 | } | ||
557 | |||
558 | minvid = vrm_mV_table[longhaul.bits.MinimumVID]; | ||
559 | maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; | ||
560 | |||
561 | if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { | ||
562 | printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. " | ||
563 | "Voltage scaling disabled.\n", | ||
564 | minvid.mV/1000, minvid.mV%1000, | ||
565 | maxvid.mV/1000, maxvid.mV%1000); | ||
566 | return; | ||
567 | } | ||
568 | |||
569 | if (minvid.mV == maxvid.mV) { | ||
570 | printk(KERN_INFO PFX "Claims to support voltage scaling but " | ||
571 | "min & max are both %d.%03d. " | ||
572 | "Voltage scaling disabled\n", | ||
573 | maxvid.mV/1000, maxvid.mV%1000); | ||
574 | return; | ||
575 | } | ||
576 | |||
577 | /* How many voltage steps*/ | ||
578 | numvscales = maxvid.pos - minvid.pos + 1; | ||
579 | printk(KERN_INFO PFX | ||
580 | "Max VID=%d.%03d " | ||
581 | "Min VID=%d.%03d, " | ||
582 | "%d possible voltage scales\n", | ||
583 | maxvid.mV/1000, maxvid.mV%1000, | ||
584 | minvid.mV/1000, minvid.mV%1000, | ||
585 | numvscales); | ||
586 | |||
587 | /* Calculate max frequency at min voltage */ | ||
588 | j = longhaul.bits.MinMHzBR; | ||
589 | if (longhaul.bits.MinMHzBR4) | ||
590 | j += 16; | ||
591 | min_vid_speed = eblcr[j]; | ||
592 | if (min_vid_speed == -1) | ||
593 | return; | ||
594 | switch (longhaul.bits.MinMHzFSB) { | ||
595 | case 0: | ||
596 | min_vid_speed *= 13333; | ||
597 | break; | ||
598 | case 1: | ||
599 | min_vid_speed *= 10000; | ||
600 | break; | ||
601 | case 3: | ||
602 | min_vid_speed *= 6666; | ||
603 | break; | ||
604 | default: | ||
605 | return; | ||
606 | break; | ||
607 | } | ||
608 | if (min_vid_speed >= highest_speed) | ||
609 | return; | ||
610 | /* Calculate kHz for one voltage step */ | ||
611 | kHz_step = (highest_speed - min_vid_speed) / numvscales; | ||
612 | |||
613 | j = 0; | ||
614 | while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { | ||
615 | speed = longhaul_table[j].frequency; | ||
616 | if (speed > min_vid_speed) | ||
617 | pos = (speed - min_vid_speed) / kHz_step + minvid.pos; | ||
618 | else | ||
619 | pos = minvid.pos; | ||
620 | longhaul_table[j].index |= mV_vrm_table[pos] << 8; | ||
621 | vid = vrm_mV_table[mV_vrm_table[pos]]; | ||
622 | printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", | ||
623 | speed, j, vid.mV); | ||
624 | j++; | ||
625 | } | ||
626 | |||
627 | can_scale_voltage = 1; | ||
628 | printk(KERN_INFO PFX "Voltage scaling enabled.\n"); | ||
629 | } | ||
630 | |||
631 | |||
632 | static int longhaul_verify(struct cpufreq_policy *policy) | ||
633 | { | ||
634 | return cpufreq_frequency_table_verify(policy, longhaul_table); | ||
635 | } | ||
636 | |||
637 | |||
638 | static int longhaul_target(struct cpufreq_policy *policy, | ||
639 | unsigned int target_freq, unsigned int relation) | ||
640 | { | ||
641 | unsigned int table_index = 0; | ||
642 | unsigned int i; | ||
643 | unsigned int dir = 0; | ||
644 | u8 vid, current_vid; | ||
645 | |||
646 | if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, | ||
647 | relation, &table_index)) | ||
648 | return -EINVAL; | ||
649 | |||
650 | /* Don't set same frequency again */ | ||
651 | if (longhaul_index == table_index) | ||
652 | return 0; | ||
653 | |||
654 | if (!can_scale_voltage) | ||
655 | longhaul_setstate(table_index); | ||
656 | else { | ||
657 | /* On test system voltage transitions exceeding single | ||
658 | * step up or down were turning motherboard off. Both | ||
659 | * "ondemand" and "userspace" are unsafe. C7 is doing | ||
660 | * this in hardware, C3 is old and we need to do this | ||
661 | * in software. */ | ||
662 | i = longhaul_index; | ||
663 | current_vid = (longhaul_table[longhaul_index].index >> 8); | ||
664 | current_vid &= 0x1f; | ||
665 | if (table_index > longhaul_index) | ||
666 | dir = 1; | ||
667 | while (i != table_index) { | ||
668 | vid = (longhaul_table[i].index >> 8) & 0x1f; | ||
669 | if (vid != current_vid) { | ||
670 | longhaul_setstate(i); | ||
671 | current_vid = vid; | ||
672 | msleep(200); | ||
673 | } | ||
674 | if (dir) | ||
675 | i++; | ||
676 | else | ||
677 | i--; | ||
678 | } | ||
679 | longhaul_setstate(table_index); | ||
680 | } | ||
681 | longhaul_index = table_index; | ||
682 | return 0; | ||
683 | } | ||
684 | |||
685 | |||
686 | static unsigned int longhaul_get(unsigned int cpu) | ||
687 | { | ||
688 | if (cpu) | ||
689 | return 0; | ||
690 | return calc_speed(longhaul_get_cpu_mult()); | ||
691 | } | ||
692 | |||
693 | static acpi_status longhaul_walk_callback(acpi_handle obj_handle, | ||
694 | u32 nesting_level, | ||
695 | void *context, void **return_value) | ||
696 | { | ||
697 | struct acpi_device *d; | ||
698 | |||
699 | if (acpi_bus_get_device(obj_handle, &d)) | ||
700 | return 0; | ||
701 | |||
702 | *return_value = acpi_driver_data(d); | ||
703 | return 1; | ||
704 | } | ||
705 | |||
706 | /* VIA don't support PM2 reg, but have something similar */ | ||
707 | static int enable_arbiter_disable(void) | ||
708 | { | ||
709 | struct pci_dev *dev; | ||
710 | int status = 1; | ||
711 | int reg; | ||
712 | u8 pci_cmd; | ||
713 | |||
714 | /* Find PLE133 host bridge */ | ||
715 | reg = 0x78; | ||
716 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, | ||
717 | NULL); | ||
718 | /* Find PM133/VT8605 host bridge */ | ||
719 | if (dev == NULL) | ||
720 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
721 | PCI_DEVICE_ID_VIA_8605_0, NULL); | ||
722 | /* Find CLE266 host bridge */ | ||
723 | if (dev == NULL) { | ||
724 | reg = 0x76; | ||
725 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
726 | PCI_DEVICE_ID_VIA_862X_0, NULL); | ||
727 | /* Find CN400 V-Link host bridge */ | ||
728 | if (dev == NULL) | ||
729 | dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); | ||
730 | } | ||
731 | if (dev != NULL) { | ||
732 | /* Enable access to port 0x22 */ | ||
733 | pci_read_config_byte(dev, reg, &pci_cmd); | ||
734 | if (!(pci_cmd & 1<<7)) { | ||
735 | pci_cmd |= 1<<7; | ||
736 | pci_write_config_byte(dev, reg, pci_cmd); | ||
737 | pci_read_config_byte(dev, reg, &pci_cmd); | ||
738 | if (!(pci_cmd & 1<<7)) { | ||
739 | printk(KERN_ERR PFX | ||
740 | "Can't enable access to port 0x22.\n"); | ||
741 | status = 0; | ||
742 | } | ||
743 | } | ||
744 | pci_dev_put(dev); | ||
745 | return status; | ||
746 | } | ||
747 | return 0; | ||
748 | } | ||
749 | |||
750 | static int longhaul_setup_southbridge(void) | ||
751 | { | ||
752 | struct pci_dev *dev; | ||
753 | u8 pci_cmd; | ||
754 | |||
755 | /* Find VT8235 southbridge */ | ||
756 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL); | ||
757 | if (dev == NULL) | ||
758 | /* Find VT8237 southbridge */ | ||
759 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
760 | PCI_DEVICE_ID_VIA_8237, NULL); | ||
761 | if (dev != NULL) { | ||
762 | /* Set transition time to max */ | ||
763 | pci_read_config_byte(dev, 0xec, &pci_cmd); | ||
764 | pci_cmd &= ~(1 << 2); | ||
765 | pci_write_config_byte(dev, 0xec, pci_cmd); | ||
766 | pci_read_config_byte(dev, 0xe4, &pci_cmd); | ||
767 | pci_cmd &= ~(1 << 7); | ||
768 | pci_write_config_byte(dev, 0xe4, pci_cmd); | ||
769 | pci_read_config_byte(dev, 0xe5, &pci_cmd); | ||
770 | pci_cmd |= 1 << 7; | ||
771 | pci_write_config_byte(dev, 0xe5, pci_cmd); | ||
772 | /* Get address of ACPI registers block*/ | ||
773 | pci_read_config_byte(dev, 0x81, &pci_cmd); | ||
774 | if (pci_cmd & 1 << 7) { | ||
775 | pci_read_config_dword(dev, 0x88, &acpi_regs_addr); | ||
776 | acpi_regs_addr &= 0xff00; | ||
777 | printk(KERN_INFO PFX "ACPI I/O at 0x%x\n", | ||
778 | acpi_regs_addr); | ||
779 | } | ||
780 | |||
781 | pci_dev_put(dev); | ||
782 | return 1; | ||
783 | } | ||
784 | return 0; | ||
785 | } | ||
786 | |||
787 | static int __cpuinit longhaul_cpu_init(struct cpufreq_policy *policy) | ||
788 | { | ||
789 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
790 | char *cpuname = NULL; | ||
791 | int ret; | ||
792 | u32 lo, hi; | ||
793 | |||
794 | /* Check what we have on this motherboard */ | ||
795 | switch (c->x86_model) { | ||
796 | case 6: | ||
797 | cpu_model = CPU_SAMUEL; | ||
798 | cpuname = "C3 'Samuel' [C5A]"; | ||
799 | longhaul_version = TYPE_LONGHAUL_V1; | ||
800 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); | ||
801 | memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr)); | ||
802 | break; | ||
803 | |||
804 | case 7: | ||
805 | switch (c->x86_mask) { | ||
806 | case 0: | ||
807 | longhaul_version = TYPE_LONGHAUL_V1; | ||
808 | cpu_model = CPU_SAMUEL2; | ||
809 | cpuname = "C3 'Samuel 2' [C5B]"; | ||
810 | /* Note, this is not a typo, early Samuel2's had | ||
811 | * Samuel1 ratios. */ | ||
812 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); | ||
813 | memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr)); | ||
814 | break; | ||
815 | case 1 ... 15: | ||
816 | longhaul_version = TYPE_LONGHAUL_V2; | ||
817 | if (c->x86_mask < 8) { | ||
818 | cpu_model = CPU_SAMUEL2; | ||
819 | cpuname = "C3 'Samuel 2' [C5B]"; | ||
820 | } else { | ||
821 | cpu_model = CPU_EZRA; | ||
822 | cpuname = "C3 'Ezra' [C5C]"; | ||
823 | } | ||
824 | memcpy(mults, ezra_mults, sizeof(ezra_mults)); | ||
825 | memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr)); | ||
826 | break; | ||
827 | } | ||
828 | break; | ||
829 | |||
830 | case 8: | ||
831 | cpu_model = CPU_EZRA_T; | ||
832 | cpuname = "C3 'Ezra-T' [C5M]"; | ||
833 | longhaul_version = TYPE_POWERSAVER; | ||
834 | numscales = 32; | ||
835 | memcpy(mults, ezrat_mults, sizeof(ezrat_mults)); | ||
836 | memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr)); | ||
837 | break; | ||
838 | |||
839 | case 9: | ||
840 | longhaul_version = TYPE_POWERSAVER; | ||
841 | numscales = 32; | ||
842 | memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults)); | ||
843 | memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr)); | ||
844 | switch (c->x86_mask) { | ||
845 | case 0 ... 1: | ||
846 | cpu_model = CPU_NEHEMIAH; | ||
847 | cpuname = "C3 'Nehemiah A' [C5XLOE]"; | ||
848 | break; | ||
849 | case 2 ... 4: | ||
850 | cpu_model = CPU_NEHEMIAH; | ||
851 | cpuname = "C3 'Nehemiah B' [C5XLOH]"; | ||
852 | break; | ||
853 | case 5 ... 15: | ||
854 | cpu_model = CPU_NEHEMIAH_C; | ||
855 | cpuname = "C3 'Nehemiah C' [C5P]"; | ||
856 | break; | ||
857 | } | ||
858 | break; | ||
859 | |||
860 | default: | ||
861 | cpuname = "Unknown"; | ||
862 | break; | ||
863 | } | ||
864 | /* Check Longhaul ver. 2 */ | ||
865 | if (longhaul_version == TYPE_LONGHAUL_V2) { | ||
866 | rdmsr(MSR_VIA_LONGHAUL, lo, hi); | ||
867 | if (lo == 0 && hi == 0) | ||
868 | /* Looks like MSR isn't present */ | ||
869 | longhaul_version = TYPE_LONGHAUL_V1; | ||
870 | } | ||
871 | |||
872 | printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname); | ||
873 | switch (longhaul_version) { | ||
874 | case TYPE_LONGHAUL_V1: | ||
875 | case TYPE_LONGHAUL_V2: | ||
876 | printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version); | ||
877 | break; | ||
878 | case TYPE_POWERSAVER: | ||
879 | printk(KERN_CONT "Powersaver supported.\n"); | ||
880 | break; | ||
881 | }; | ||
882 | |||
883 | /* Doesn't hurt */ | ||
884 | longhaul_setup_southbridge(); | ||
885 | |||
886 | /* Find ACPI data for processor */ | ||
887 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, | ||
888 | ACPI_UINT32_MAX, &longhaul_walk_callback, NULL, | ||
889 | NULL, (void *)&pr); | ||
890 | |||
891 | /* Check ACPI support for C3 state */ | ||
892 | if (pr != NULL && longhaul_version == TYPE_POWERSAVER) { | ||
893 | cx = &pr->power.states[ACPI_STATE_C3]; | ||
894 | if (cx->address > 0 && cx->latency <= 1000) | ||
895 | longhaul_flags |= USE_ACPI_C3; | ||
896 | } | ||
897 | /* Disable if it isn't working */ | ||
898 | if (disable_acpi_c3) | ||
899 | longhaul_flags &= ~USE_ACPI_C3; | ||
900 | /* Check if northbridge is friendly */ | ||
901 | if (enable_arbiter_disable()) | ||
902 | longhaul_flags |= USE_NORTHBRIDGE; | ||
903 | |||
904 | /* Check ACPI support for bus master arbiter disable */ | ||
905 | if (!(longhaul_flags & USE_ACPI_C3 | ||
906 | || longhaul_flags & USE_NORTHBRIDGE) | ||
907 | && ((pr == NULL) || !(pr->flags.bm_control))) { | ||
908 | printk(KERN_ERR PFX | ||
909 | "No ACPI support. Unsupported northbridge.\n"); | ||
910 | return -ENODEV; | ||
911 | } | ||
912 | |||
913 | if (longhaul_flags & USE_NORTHBRIDGE) | ||
914 | printk(KERN_INFO PFX "Using northbridge support.\n"); | ||
915 | if (longhaul_flags & USE_ACPI_C3) | ||
916 | printk(KERN_INFO PFX "Using ACPI support.\n"); | ||
917 | |||
918 | ret = longhaul_get_ranges(); | ||
919 | if (ret != 0) | ||
920 | return ret; | ||
921 | |||
922 | if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0)) | ||
923 | longhaul_setup_voltagescaling(); | ||
924 | |||
925 | policy->cpuinfo.transition_latency = 200000; /* nsec */ | ||
926 | policy->cur = calc_speed(longhaul_get_cpu_mult()); | ||
927 | |||
928 | ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table); | ||
929 | if (ret) | ||
930 | return ret; | ||
931 | |||
932 | cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu); | ||
933 | |||
934 | return 0; | ||
935 | } | ||
936 | |||
937 | static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy) | ||
938 | { | ||
939 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
940 | return 0; | ||
941 | } | ||
942 | |||
943 | static struct freq_attr *longhaul_attr[] = { | ||
944 | &cpufreq_freq_attr_scaling_available_freqs, | ||
945 | NULL, | ||
946 | }; | ||
947 | |||
948 | static struct cpufreq_driver longhaul_driver = { | ||
949 | .verify = longhaul_verify, | ||
950 | .target = longhaul_target, | ||
951 | .get = longhaul_get, | ||
952 | .init = longhaul_cpu_init, | ||
953 | .exit = __devexit_p(longhaul_cpu_exit), | ||
954 | .name = "longhaul", | ||
955 | .owner = THIS_MODULE, | ||
956 | .attr = longhaul_attr, | ||
957 | }; | ||
958 | |||
959 | |||
960 | static int __init longhaul_init(void) | ||
961 | { | ||
962 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
963 | |||
964 | if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6) | ||
965 | return -ENODEV; | ||
966 | |||
967 | #ifdef CONFIG_SMP | ||
968 | if (num_online_cpus() > 1) { | ||
969 | printk(KERN_ERR PFX "More than 1 CPU detected, " | ||
970 | "longhaul disabled.\n"); | ||
971 | return -ENODEV; | ||
972 | } | ||
973 | #endif | ||
974 | #ifdef CONFIG_X86_IO_APIC | ||
975 | if (cpu_has_apic) { | ||
976 | printk(KERN_ERR PFX "APIC detected. Longhaul is currently " | ||
977 | "broken in this configuration.\n"); | ||
978 | return -ENODEV; | ||
979 | } | ||
980 | #endif | ||
981 | switch (c->x86_model) { | ||
982 | case 6 ... 9: | ||
983 | return cpufreq_register_driver(&longhaul_driver); | ||
984 | case 10: | ||
985 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); | ||
986 | default: | ||
987 | ; | ||
988 | } | ||
989 | |||
990 | return -ENODEV; | ||
991 | } | ||
992 | |||
993 | |||
994 | static void __exit longhaul_exit(void) | ||
995 | { | ||
996 | int i; | ||
997 | |||
998 | for (i = 0; i < numscales; i++) { | ||
999 | if (mults[i] == maxmult) { | ||
1000 | longhaul_setstate(i); | ||
1001 | break; | ||
1002 | } | ||
1003 | } | ||
1004 | |||
1005 | cpufreq_unregister_driver(&longhaul_driver); | ||
1006 | kfree(longhaul_table); | ||
1007 | } | ||
1008 | |||
1009 | /* Even if BIOS is exporting ACPI C3 state, and it is used | ||
1010 | * with success when CPU is idle, this state doesn't | ||
1011 | * trigger frequency transition in some cases. */ | ||
1012 | module_param(disable_acpi_c3, int, 0644); | ||
1013 | MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support"); | ||
1014 | /* Change CPU voltage with frequency. Very usefull to save | ||
1015 | * power, but most VIA C3 processors aren't supporting it. */ | ||
1016 | module_param(scale_voltage, int, 0644); | ||
1017 | MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); | ||
1018 | /* Force revision key to 0 for processors which doesn't | ||
1019 | * support voltage scaling, but are introducing itself as | ||
1020 | * such. */ | ||
1021 | module_param(revid_errata, int, 0644); | ||
1022 | MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID"); | ||
1023 | |||
1024 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); | ||
1025 | MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors."); | ||
1026 | MODULE_LICENSE("GPL"); | ||
1027 | |||
1028 | late_initcall(longhaul_init); | ||
1029 | module_exit(longhaul_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.h b/arch/x86/kernel/cpu/cpufreq/longhaul.h deleted file mode 100644 index cbf48fbca881..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/longhaul.h +++ /dev/null | |||
@@ -1,353 +0,0 @@ | |||
1 | /* | ||
2 | * longhaul.h | ||
3 | * (C) 2003 Dave Jones. | ||
4 | * | ||
5 | * Licensed under the terms of the GNU GPL License version 2. | ||
6 | * | ||
7 | * VIA-specific information | ||
8 | */ | ||
9 | |||
10 | union msr_bcr2 { | ||
11 | struct { | ||
12 | unsigned Reseved:19, // 18:0 | ||
13 | ESOFTBF:1, // 19 | ||
14 | Reserved2:3, // 22:20 | ||
15 | CLOCKMUL:4, // 26:23 | ||
16 | Reserved3:5; // 31:27 | ||
17 | } bits; | ||
18 | unsigned long val; | ||
19 | }; | ||
20 | |||
21 | union msr_longhaul { | ||
22 | struct { | ||
23 | unsigned RevisionID:4, // 3:0 | ||
24 | RevisionKey:4, // 7:4 | ||
25 | EnableSoftBusRatio:1, // 8 | ||
26 | EnableSoftVID:1, // 9 | ||
27 | EnableSoftBSEL:1, // 10 | ||
28 | Reserved:3, // 11:13 | ||
29 | SoftBusRatio4:1, // 14 | ||
30 | VRMRev:1, // 15 | ||
31 | SoftBusRatio:4, // 19:16 | ||
32 | SoftVID:5, // 24:20 | ||
33 | Reserved2:3, // 27:25 | ||
34 | SoftBSEL:2, // 29:28 | ||
35 | Reserved3:2, // 31:30 | ||
36 | MaxMHzBR:4, // 35:32 | ||
37 | MaximumVID:5, // 40:36 | ||
38 | MaxMHzFSB:2, // 42:41 | ||
39 | MaxMHzBR4:1, // 43 | ||
40 | Reserved4:4, // 47:44 | ||
41 | MinMHzBR:4, // 51:48 | ||
42 | MinimumVID:5, // 56:52 | ||
43 | MinMHzFSB:2, // 58:57 | ||
44 | MinMHzBR4:1, // 59 | ||
45 | Reserved5:4; // 63:60 | ||
46 | } bits; | ||
47 | unsigned long long val; | ||
48 | }; | ||
49 | |||
50 | /* | ||
51 | * Clock ratio tables. Div/Mod by 10 to get ratio. | ||
52 | * The eblcr values specify the ratio read from the CPU. | ||
53 | * The mults values specify what to write to the CPU. | ||
54 | */ | ||
55 | |||
56 | /* | ||
57 | * VIA C3 Samuel 1 & Samuel 2 (stepping 0) | ||
58 | */ | ||
59 | static const int __cpuinitdata samuel1_mults[16] = { | ||
60 | -1, /* 0000 -> RESERVED */ | ||
61 | 30, /* 0001 -> 3.0x */ | ||
62 | 40, /* 0010 -> 4.0x */ | ||
63 | -1, /* 0011 -> RESERVED */ | ||
64 | -1, /* 0100 -> RESERVED */ | ||
65 | 35, /* 0101 -> 3.5x */ | ||
66 | 45, /* 0110 -> 4.5x */ | ||
67 | 55, /* 0111 -> 5.5x */ | ||
68 | 60, /* 1000 -> 6.0x */ | ||
69 | 70, /* 1001 -> 7.0x */ | ||
70 | 80, /* 1010 -> 8.0x */ | ||
71 | 50, /* 1011 -> 5.0x */ | ||
72 | 65, /* 1100 -> 6.5x */ | ||
73 | 75, /* 1101 -> 7.5x */ | ||
74 | -1, /* 1110 -> RESERVED */ | ||
75 | -1, /* 1111 -> RESERVED */ | ||
76 | }; | ||
77 | |||
78 | static const int __cpuinitdata samuel1_eblcr[16] = { | ||
79 | 50, /* 0000 -> RESERVED */ | ||
80 | 30, /* 0001 -> 3.0x */ | ||
81 | 40, /* 0010 -> 4.0x */ | ||
82 | -1, /* 0011 -> RESERVED */ | ||
83 | 55, /* 0100 -> 5.5x */ | ||
84 | 35, /* 0101 -> 3.5x */ | ||
85 | 45, /* 0110 -> 4.5x */ | ||
86 | -1, /* 0111 -> RESERVED */ | ||
87 | -1, /* 1000 -> RESERVED */ | ||
88 | 70, /* 1001 -> 7.0x */ | ||
89 | 80, /* 1010 -> 8.0x */ | ||
90 | 60, /* 1011 -> 6.0x */ | ||
91 | -1, /* 1100 -> RESERVED */ | ||
92 | 75, /* 1101 -> 7.5x */ | ||
93 | -1, /* 1110 -> RESERVED */ | ||
94 | 65, /* 1111 -> 6.5x */ | ||
95 | }; | ||
96 | |||
97 | /* | ||
98 | * VIA C3 Samuel2 Stepping 1->15 | ||
99 | */ | ||
100 | static const int __cpuinitdata samuel2_eblcr[16] = { | ||
101 | 50, /* 0000 -> 5.0x */ | ||
102 | 30, /* 0001 -> 3.0x */ | ||
103 | 40, /* 0010 -> 4.0x */ | ||
104 | 100, /* 0011 -> 10.0x */ | ||
105 | 55, /* 0100 -> 5.5x */ | ||
106 | 35, /* 0101 -> 3.5x */ | ||
107 | 45, /* 0110 -> 4.5x */ | ||
108 | 110, /* 0111 -> 11.0x */ | ||
109 | 90, /* 1000 -> 9.0x */ | ||
110 | 70, /* 1001 -> 7.0x */ | ||
111 | 80, /* 1010 -> 8.0x */ | ||
112 | 60, /* 1011 -> 6.0x */ | ||
113 | 120, /* 1100 -> 12.0x */ | ||
114 | 75, /* 1101 -> 7.5x */ | ||
115 | 130, /* 1110 -> 13.0x */ | ||
116 | 65, /* 1111 -> 6.5x */ | ||
117 | }; | ||
118 | |||
119 | /* | ||
120 | * VIA C3 Ezra | ||
121 | */ | ||
122 | static const int __cpuinitdata ezra_mults[16] = { | ||
123 | 100, /* 0000 -> 10.0x */ | ||
124 | 30, /* 0001 -> 3.0x */ | ||
125 | 40, /* 0010 -> 4.0x */ | ||
126 | 90, /* 0011 -> 9.0x */ | ||
127 | 95, /* 0100 -> 9.5x */ | ||
128 | 35, /* 0101 -> 3.5x */ | ||
129 | 45, /* 0110 -> 4.5x */ | ||
130 | 55, /* 0111 -> 5.5x */ | ||
131 | 60, /* 1000 -> 6.0x */ | ||
132 | 70, /* 1001 -> 7.0x */ | ||
133 | 80, /* 1010 -> 8.0x */ | ||
134 | 50, /* 1011 -> 5.0x */ | ||
135 | 65, /* 1100 -> 6.5x */ | ||
136 | 75, /* 1101 -> 7.5x */ | ||
137 | 85, /* 1110 -> 8.5x */ | ||
138 | 120, /* 1111 -> 12.0x */ | ||
139 | }; | ||
140 | |||
141 | static const int __cpuinitdata ezra_eblcr[16] = { | ||
142 | 50, /* 0000 -> 5.0x */ | ||
143 | 30, /* 0001 -> 3.0x */ | ||
144 | 40, /* 0010 -> 4.0x */ | ||
145 | 100, /* 0011 -> 10.0x */ | ||
146 | 55, /* 0100 -> 5.5x */ | ||
147 | 35, /* 0101 -> 3.5x */ | ||
148 | 45, /* 0110 -> 4.5x */ | ||
149 | 95, /* 0111 -> 9.5x */ | ||
150 | 90, /* 1000 -> 9.0x */ | ||
151 | 70, /* 1001 -> 7.0x */ | ||
152 | 80, /* 1010 -> 8.0x */ | ||
153 | 60, /* 1011 -> 6.0x */ | ||
154 | 120, /* 1100 -> 12.0x */ | ||
155 | 75, /* 1101 -> 7.5x */ | ||
156 | 85, /* 1110 -> 8.5x */ | ||
157 | 65, /* 1111 -> 6.5x */ | ||
158 | }; | ||
159 | |||
160 | /* | ||
161 | * VIA C3 (Ezra-T) [C5M]. | ||
162 | */ | ||
163 | static const int __cpuinitdata ezrat_mults[32] = { | ||
164 | 100, /* 0000 -> 10.0x */ | ||
165 | 30, /* 0001 -> 3.0x */ | ||
166 | 40, /* 0010 -> 4.0x */ | ||
167 | 90, /* 0011 -> 9.0x */ | ||
168 | 95, /* 0100 -> 9.5x */ | ||
169 | 35, /* 0101 -> 3.5x */ | ||
170 | 45, /* 0110 -> 4.5x */ | ||
171 | 55, /* 0111 -> 5.5x */ | ||
172 | 60, /* 1000 -> 6.0x */ | ||
173 | 70, /* 1001 -> 7.0x */ | ||
174 | 80, /* 1010 -> 8.0x */ | ||
175 | 50, /* 1011 -> 5.0x */ | ||
176 | 65, /* 1100 -> 6.5x */ | ||
177 | 75, /* 1101 -> 7.5x */ | ||
178 | 85, /* 1110 -> 8.5x */ | ||
179 | 120, /* 1111 -> 12.0x */ | ||
180 | |||
181 | -1, /* 0000 -> RESERVED (10.0x) */ | ||
182 | 110, /* 0001 -> 11.0x */ | ||
183 | -1, /* 0010 -> 12.0x */ | ||
184 | -1, /* 0011 -> RESERVED (9.0x)*/ | ||
185 | 105, /* 0100 -> 10.5x */ | ||
186 | 115, /* 0101 -> 11.5x */ | ||
187 | 125, /* 0110 -> 12.5x */ | ||
188 | 135, /* 0111 -> 13.5x */ | ||
189 | 140, /* 1000 -> 14.0x */ | ||
190 | 150, /* 1001 -> 15.0x */ | ||
191 | 160, /* 1010 -> 16.0x */ | ||
192 | 130, /* 1011 -> 13.0x */ | ||
193 | 145, /* 1100 -> 14.5x */ | ||
194 | 155, /* 1101 -> 15.5x */ | ||
195 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
196 | -1, /* 1111 -> RESERVED (12.0x) */ | ||
197 | }; | ||
198 | |||
199 | static const int __cpuinitdata ezrat_eblcr[32] = { | ||
200 | 50, /* 0000 -> 5.0x */ | ||
201 | 30, /* 0001 -> 3.0x */ | ||
202 | 40, /* 0010 -> 4.0x */ | ||
203 | 100, /* 0011 -> 10.0x */ | ||
204 | 55, /* 0100 -> 5.5x */ | ||
205 | 35, /* 0101 -> 3.5x */ | ||
206 | 45, /* 0110 -> 4.5x */ | ||
207 | 95, /* 0111 -> 9.5x */ | ||
208 | 90, /* 1000 -> 9.0x */ | ||
209 | 70, /* 1001 -> 7.0x */ | ||
210 | 80, /* 1010 -> 8.0x */ | ||
211 | 60, /* 1011 -> 6.0x */ | ||
212 | 120, /* 1100 -> 12.0x */ | ||
213 | 75, /* 1101 -> 7.5x */ | ||
214 | 85, /* 1110 -> 8.5x */ | ||
215 | 65, /* 1111 -> 6.5x */ | ||
216 | |||
217 | -1, /* 0000 -> RESERVED (9.0x) */ | ||
218 | 110, /* 0001 -> 11.0x */ | ||
219 | 120, /* 0010 -> 12.0x */ | ||
220 | -1, /* 0011 -> RESERVED (10.0x)*/ | ||
221 | 135, /* 0100 -> 13.5x */ | ||
222 | 115, /* 0101 -> 11.5x */ | ||
223 | 125, /* 0110 -> 12.5x */ | ||
224 | 105, /* 0111 -> 10.5x */ | ||
225 | 130, /* 1000 -> 13.0x */ | ||
226 | 150, /* 1001 -> 15.0x */ | ||
227 | 160, /* 1010 -> 16.0x */ | ||
228 | 140, /* 1011 -> 14.0x */ | ||
229 | -1, /* 1100 -> RESERVED (12.0x) */ | ||
230 | 155, /* 1101 -> 15.5x */ | ||
231 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
232 | 145, /* 1111 -> 14.5x */ | ||
233 | }; | ||
234 | |||
235 | /* | ||
236 | * VIA C3 Nehemiah */ | ||
237 | |||
238 | static const int __cpuinitdata nehemiah_mults[32] = { | ||
239 | 100, /* 0000 -> 10.0x */ | ||
240 | -1, /* 0001 -> 16.0x */ | ||
241 | 40, /* 0010 -> 4.0x */ | ||
242 | 90, /* 0011 -> 9.0x */ | ||
243 | 95, /* 0100 -> 9.5x */ | ||
244 | -1, /* 0101 -> RESERVED */ | ||
245 | 45, /* 0110 -> 4.5x */ | ||
246 | 55, /* 0111 -> 5.5x */ | ||
247 | 60, /* 1000 -> 6.0x */ | ||
248 | 70, /* 1001 -> 7.0x */ | ||
249 | 80, /* 1010 -> 8.0x */ | ||
250 | 50, /* 1011 -> 5.0x */ | ||
251 | 65, /* 1100 -> 6.5x */ | ||
252 | 75, /* 1101 -> 7.5x */ | ||
253 | 85, /* 1110 -> 8.5x */ | ||
254 | 120, /* 1111 -> 12.0x */ | ||
255 | -1, /* 0000 -> 10.0x */ | ||
256 | 110, /* 0001 -> 11.0x */ | ||
257 | -1, /* 0010 -> 12.0x */ | ||
258 | -1, /* 0011 -> 9.0x */ | ||
259 | 105, /* 0100 -> 10.5x */ | ||
260 | 115, /* 0101 -> 11.5x */ | ||
261 | 125, /* 0110 -> 12.5x */ | ||
262 | 135, /* 0111 -> 13.5x */ | ||
263 | 140, /* 1000 -> 14.0x */ | ||
264 | 150, /* 1001 -> 15.0x */ | ||
265 | 160, /* 1010 -> 16.0x */ | ||
266 | 130, /* 1011 -> 13.0x */ | ||
267 | 145, /* 1100 -> 14.5x */ | ||
268 | 155, /* 1101 -> 15.5x */ | ||
269 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
270 | -1, /* 1111 -> 12.0x */ | ||
271 | }; | ||
272 | |||
273 | static const int __cpuinitdata nehemiah_eblcr[32] = { | ||
274 | 50, /* 0000 -> 5.0x */ | ||
275 | 160, /* 0001 -> 16.0x */ | ||
276 | 40, /* 0010 -> 4.0x */ | ||
277 | 100, /* 0011 -> 10.0x */ | ||
278 | 55, /* 0100 -> 5.5x */ | ||
279 | -1, /* 0101 -> RESERVED */ | ||
280 | 45, /* 0110 -> 4.5x */ | ||
281 | 95, /* 0111 -> 9.5x */ | ||
282 | 90, /* 1000 -> 9.0x */ | ||
283 | 70, /* 1001 -> 7.0x */ | ||
284 | 80, /* 1010 -> 8.0x */ | ||
285 | 60, /* 1011 -> 6.0x */ | ||
286 | 120, /* 1100 -> 12.0x */ | ||
287 | 75, /* 1101 -> 7.5x */ | ||
288 | 85, /* 1110 -> 8.5x */ | ||
289 | 65, /* 1111 -> 6.5x */ | ||
290 | 90, /* 0000 -> 9.0x */ | ||
291 | 110, /* 0001 -> 11.0x */ | ||
292 | 120, /* 0010 -> 12.0x */ | ||
293 | 100, /* 0011 -> 10.0x */ | ||
294 | 135, /* 0100 -> 13.5x */ | ||
295 | 115, /* 0101 -> 11.5x */ | ||
296 | 125, /* 0110 -> 12.5x */ | ||
297 | 105, /* 0111 -> 10.5x */ | ||
298 | 130, /* 1000 -> 13.0x */ | ||
299 | 150, /* 1001 -> 15.0x */ | ||
300 | 160, /* 1010 -> 16.0x */ | ||
301 | 140, /* 1011 -> 14.0x */ | ||
302 | 120, /* 1100 -> 12.0x */ | ||
303 | 155, /* 1101 -> 15.5x */ | ||
304 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
305 | 145 /* 1111 -> 14.5x */ | ||
306 | }; | ||
307 | |||
308 | /* | ||
309 | * Voltage scales. Div/Mod by 1000 to get actual voltage. | ||
310 | * Which scale to use depends on the VRM type in use. | ||
311 | */ | ||
312 | |||
313 | struct mV_pos { | ||
314 | unsigned short mV; | ||
315 | unsigned short pos; | ||
316 | }; | ||
317 | |||
318 | static const struct mV_pos __cpuinitdata vrm85_mV[32] = { | ||
319 | {1250, 8}, {1200, 6}, {1150, 4}, {1100, 2}, | ||
320 | {1050, 0}, {1800, 30}, {1750, 28}, {1700, 26}, | ||
321 | {1650, 24}, {1600, 22}, {1550, 20}, {1500, 18}, | ||
322 | {1450, 16}, {1400, 14}, {1350, 12}, {1300, 10}, | ||
323 | {1275, 9}, {1225, 7}, {1175, 5}, {1125, 3}, | ||
324 | {1075, 1}, {1825, 31}, {1775, 29}, {1725, 27}, | ||
325 | {1675, 25}, {1625, 23}, {1575, 21}, {1525, 19}, | ||
326 | {1475, 17}, {1425, 15}, {1375, 13}, {1325, 11} | ||
327 | }; | ||
328 | |||
329 | static const unsigned char __cpuinitdata mV_vrm85[32] = { | ||
330 | 0x04, 0x14, 0x03, 0x13, 0x02, 0x12, 0x01, 0x11, | ||
331 | 0x00, 0x10, 0x0f, 0x1f, 0x0e, 0x1e, 0x0d, 0x1d, | ||
332 | 0x0c, 0x1c, 0x0b, 0x1b, 0x0a, 0x1a, 0x09, 0x19, | ||
333 | 0x08, 0x18, 0x07, 0x17, 0x06, 0x16, 0x05, 0x15 | ||
334 | }; | ||
335 | |||
336 | static const struct mV_pos __cpuinitdata mobilevrm_mV[32] = { | ||
337 | {1750, 31}, {1700, 30}, {1650, 29}, {1600, 28}, | ||
338 | {1550, 27}, {1500, 26}, {1450, 25}, {1400, 24}, | ||
339 | {1350, 23}, {1300, 22}, {1250, 21}, {1200, 20}, | ||
340 | {1150, 19}, {1100, 18}, {1050, 17}, {1000, 16}, | ||
341 | {975, 15}, {950, 14}, {925, 13}, {900, 12}, | ||
342 | {875, 11}, {850, 10}, {825, 9}, {800, 8}, | ||
343 | {775, 7}, {750, 6}, {725, 5}, {700, 4}, | ||
344 | {675, 3}, {650, 2}, {625, 1}, {600, 0} | ||
345 | }; | ||
346 | |||
347 | static const unsigned char __cpuinitdata mV_mobilevrm[32] = { | ||
348 | 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, | ||
349 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, | ||
350 | 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, | ||
351 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 | ||
352 | }; | ||
353 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/longrun.c b/arch/x86/kernel/cpu/cpufreq/longrun.c deleted file mode 100644 index fc09f142d94d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/longrun.c +++ /dev/null | |||
@@ -1,327 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/cpufreq.h> | ||
13 | #include <linux/timex.h> | ||
14 | |||
15 | #include <asm/msr.h> | ||
16 | #include <asm/processor.h> | ||
17 | |||
18 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
19 | "longrun", msg) | ||
20 | |||
21 | static struct cpufreq_driver longrun_driver; | ||
22 | |||
23 | /** | ||
24 | * longrun_{low,high}_freq is needed for the conversion of cpufreq kHz | ||
25 | * values into per cent values. In TMTA microcode, the following is valid: | ||
26 | * performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) | ||
27 | */ | ||
28 | static unsigned int longrun_low_freq, longrun_high_freq; | ||
29 | |||
30 | |||
31 | /** | ||
32 | * longrun_get_policy - get the current LongRun policy | ||
33 | * @policy: struct cpufreq_policy where current policy is written into | ||
34 | * | ||
35 | * Reads the current LongRun policy by access to MSR_TMTA_LONGRUN_FLAGS | ||
36 | * and MSR_TMTA_LONGRUN_CTRL | ||
37 | */ | ||
38 | static void __init longrun_get_policy(struct cpufreq_policy *policy) | ||
39 | { | ||
40 | u32 msr_lo, msr_hi; | ||
41 | |||
42 | rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
43 | dprintk("longrun flags are %x - %x\n", msr_lo, msr_hi); | ||
44 | if (msr_lo & 0x01) | ||
45 | policy->policy = CPUFREQ_POLICY_PERFORMANCE; | ||
46 | else | ||
47 | policy->policy = CPUFREQ_POLICY_POWERSAVE; | ||
48 | |||
49 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
50 | dprintk("longrun ctrl is %x - %x\n", msr_lo, msr_hi); | ||
51 | msr_lo &= 0x0000007F; | ||
52 | msr_hi &= 0x0000007F; | ||
53 | |||
54 | if (longrun_high_freq <= longrun_low_freq) { | ||
55 | /* Assume degenerate Longrun table */ | ||
56 | policy->min = policy->max = longrun_high_freq; | ||
57 | } else { | ||
58 | policy->min = longrun_low_freq + msr_lo * | ||
59 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
60 | policy->max = longrun_low_freq + msr_hi * | ||
61 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
62 | } | ||
63 | policy->cpu = 0; | ||
64 | } | ||
65 | |||
66 | |||
67 | /** | ||
68 | * longrun_set_policy - sets a new CPUFreq policy | ||
69 | * @policy: new policy | ||
70 | * | ||
71 | * Sets a new CPUFreq policy on LongRun-capable processors. This function | ||
72 | * has to be called with cpufreq_driver locked. | ||
73 | */ | ||
74 | static int longrun_set_policy(struct cpufreq_policy *policy) | ||
75 | { | ||
76 | u32 msr_lo, msr_hi; | ||
77 | u32 pctg_lo, pctg_hi; | ||
78 | |||
79 | if (!policy) | ||
80 | return -EINVAL; | ||
81 | |||
82 | if (longrun_high_freq <= longrun_low_freq) { | ||
83 | /* Assume degenerate Longrun table */ | ||
84 | pctg_lo = pctg_hi = 100; | ||
85 | } else { | ||
86 | pctg_lo = (policy->min - longrun_low_freq) / | ||
87 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
88 | pctg_hi = (policy->max - longrun_low_freq) / | ||
89 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
90 | } | ||
91 | |||
92 | if (pctg_hi > 100) | ||
93 | pctg_hi = 100; | ||
94 | if (pctg_lo > pctg_hi) | ||
95 | pctg_lo = pctg_hi; | ||
96 | |||
97 | /* performance or economy mode */ | ||
98 | rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
99 | msr_lo &= 0xFFFFFFFE; | ||
100 | switch (policy->policy) { | ||
101 | case CPUFREQ_POLICY_PERFORMANCE: | ||
102 | msr_lo |= 0x00000001; | ||
103 | break; | ||
104 | case CPUFREQ_POLICY_POWERSAVE: | ||
105 | break; | ||
106 | } | ||
107 | wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
108 | |||
109 | /* lower and upper boundary */ | ||
110 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
111 | msr_lo &= 0xFFFFFF80; | ||
112 | msr_hi &= 0xFFFFFF80; | ||
113 | msr_lo |= pctg_lo; | ||
114 | msr_hi |= pctg_hi; | ||
115 | wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | |||
121 | /** | ||
122 | * longrun_verify_poliy - verifies a new CPUFreq policy | ||
123 | * @policy: the policy to verify | ||
124 | * | ||
125 | * Validates a new CPUFreq policy. This function has to be called with | ||
126 | * cpufreq_driver locked. | ||
127 | */ | ||
128 | static int longrun_verify_policy(struct cpufreq_policy *policy) | ||
129 | { | ||
130 | if (!policy) | ||
131 | return -EINVAL; | ||
132 | |||
133 | policy->cpu = 0; | ||
134 | cpufreq_verify_within_limits(policy, | ||
135 | policy->cpuinfo.min_freq, | ||
136 | policy->cpuinfo.max_freq); | ||
137 | |||
138 | if ((policy->policy != CPUFREQ_POLICY_POWERSAVE) && | ||
139 | (policy->policy != CPUFREQ_POLICY_PERFORMANCE)) | ||
140 | return -EINVAL; | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static unsigned int longrun_get(unsigned int cpu) | ||
146 | { | ||
147 | u32 eax, ebx, ecx, edx; | ||
148 | |||
149 | if (cpu) | ||
150 | return 0; | ||
151 | |||
152 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
153 | dprintk("cpuid eax is %u\n", eax); | ||
154 | |||
155 | return eax * 1000; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * longrun_determine_freqs - determines the lowest and highest possible core frequency | ||
160 | * @low_freq: an int to put the lowest frequency into | ||
161 | * @high_freq: an int to put the highest frequency into | ||
162 | * | ||
163 | * Determines the lowest and highest possible core frequencies on this CPU. | ||
164 | * This is necessary to calculate the performance percentage according to | ||
165 | * TMTA rules: | ||
166 | * performance_pctg = (target_freq - low_freq)/(high_freq - low_freq) | ||
167 | */ | ||
168 | static unsigned int __cpuinit longrun_determine_freqs(unsigned int *low_freq, | ||
169 | unsigned int *high_freq) | ||
170 | { | ||
171 | u32 msr_lo, msr_hi; | ||
172 | u32 save_lo, save_hi; | ||
173 | u32 eax, ebx, ecx, edx; | ||
174 | u32 try_hi; | ||
175 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
176 | |||
177 | if (!low_freq || !high_freq) | ||
178 | return -EINVAL; | ||
179 | |||
180 | if (cpu_has(c, X86_FEATURE_LRTI)) { | ||
181 | /* if the LongRun Table Interface is present, the | ||
182 | * detection is a bit easier: | ||
183 | * For minimum frequency, read out the maximum | ||
184 | * level (msr_hi), write that into "currently | ||
185 | * selected level", and read out the frequency. | ||
186 | * For maximum frequency, read out level zero. | ||
187 | */ | ||
188 | /* minimum */ | ||
189 | rdmsr(MSR_TMTA_LRTI_READOUT, msr_lo, msr_hi); | ||
190 | wrmsr(MSR_TMTA_LRTI_READOUT, msr_hi, msr_hi); | ||
191 | rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); | ||
192 | *low_freq = msr_lo * 1000; /* to kHz */ | ||
193 | |||
194 | /* maximum */ | ||
195 | wrmsr(MSR_TMTA_LRTI_READOUT, 0, msr_hi); | ||
196 | rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); | ||
197 | *high_freq = msr_lo * 1000; /* to kHz */ | ||
198 | |||
199 | dprintk("longrun table interface told %u - %u kHz\n", | ||
200 | *low_freq, *high_freq); | ||
201 | |||
202 | if (*low_freq > *high_freq) | ||
203 | *low_freq = *high_freq; | ||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | /* set the upper border to the value determined during TSC init */ | ||
208 | *high_freq = (cpu_khz / 1000); | ||
209 | *high_freq = *high_freq * 1000; | ||
210 | dprintk("high frequency is %u kHz\n", *high_freq); | ||
211 | |||
212 | /* get current borders */ | ||
213 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
214 | save_lo = msr_lo & 0x0000007F; | ||
215 | save_hi = msr_hi & 0x0000007F; | ||
216 | |||
217 | /* if current perf_pctg is larger than 90%, we need to decrease the | ||
218 | * upper limit to make the calculation more accurate. | ||
219 | */ | ||
220 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
221 | /* try decreasing in 10% steps, some processors react only | ||
222 | * on some barrier values */ | ||
223 | for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) { | ||
224 | /* set to 0 to try_hi perf_pctg */ | ||
225 | msr_lo &= 0xFFFFFF80; | ||
226 | msr_hi &= 0xFFFFFF80; | ||
227 | msr_hi |= try_hi; | ||
228 | wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
229 | |||
230 | /* read out current core MHz and current perf_pctg */ | ||
231 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
232 | |||
233 | /* restore values */ | ||
234 | wrmsr(MSR_TMTA_LONGRUN_CTRL, save_lo, save_hi); | ||
235 | } | ||
236 | dprintk("percentage is %u %%, freq is %u MHz\n", ecx, eax); | ||
237 | |||
238 | /* performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) | ||
239 | * eqals | ||
240 | * low_freq * (1 - perf_pctg) = (cur_freq - high_freq * perf_pctg) | ||
241 | * | ||
242 | * high_freq * perf_pctg is stored tempoarily into "ebx". | ||
243 | */ | ||
244 | ebx = (((cpu_khz / 1000) * ecx) / 100); /* to MHz */ | ||
245 | |||
246 | if ((ecx > 95) || (ecx == 0) || (eax < ebx)) | ||
247 | return -EIO; | ||
248 | |||
249 | edx = ((eax - ebx) * 100) / (100 - ecx); | ||
250 | *low_freq = edx * 1000; /* back to kHz */ | ||
251 | |||
252 | dprintk("low frequency is %u kHz\n", *low_freq); | ||
253 | |||
254 | if (*low_freq > *high_freq) | ||
255 | *low_freq = *high_freq; | ||
256 | |||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | |||
261 | static int __cpuinit longrun_cpu_init(struct cpufreq_policy *policy) | ||
262 | { | ||
263 | int result = 0; | ||
264 | |||
265 | /* capability check */ | ||
266 | if (policy->cpu != 0) | ||
267 | return -ENODEV; | ||
268 | |||
269 | /* detect low and high frequency */ | ||
270 | result = longrun_determine_freqs(&longrun_low_freq, &longrun_high_freq); | ||
271 | if (result) | ||
272 | return result; | ||
273 | |||
274 | /* cpuinfo and default policy values */ | ||
275 | policy->cpuinfo.min_freq = longrun_low_freq; | ||
276 | policy->cpuinfo.max_freq = longrun_high_freq; | ||
277 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
278 | longrun_get_policy(policy); | ||
279 | |||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | |||
284 | static struct cpufreq_driver longrun_driver = { | ||
285 | .flags = CPUFREQ_CONST_LOOPS, | ||
286 | .verify = longrun_verify_policy, | ||
287 | .setpolicy = longrun_set_policy, | ||
288 | .get = longrun_get, | ||
289 | .init = longrun_cpu_init, | ||
290 | .name = "longrun", | ||
291 | .owner = THIS_MODULE, | ||
292 | }; | ||
293 | |||
294 | |||
295 | /** | ||
296 | * longrun_init - initializes the Transmeta Crusoe LongRun CPUFreq driver | ||
297 | * | ||
298 | * Initializes the LongRun support. | ||
299 | */ | ||
300 | static int __init longrun_init(void) | ||
301 | { | ||
302 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
303 | |||
304 | if (c->x86_vendor != X86_VENDOR_TRANSMETA || | ||
305 | !cpu_has(c, X86_FEATURE_LONGRUN)) | ||
306 | return -ENODEV; | ||
307 | |||
308 | return cpufreq_register_driver(&longrun_driver); | ||
309 | } | ||
310 | |||
311 | |||
312 | /** | ||
313 | * longrun_exit - unregisters LongRun support | ||
314 | */ | ||
315 | static void __exit longrun_exit(void) | ||
316 | { | ||
317 | cpufreq_unregister_driver(&longrun_driver); | ||
318 | } | ||
319 | |||
320 | |||
321 | MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); | ||
322 | MODULE_DESCRIPTION("LongRun driver for Transmeta Crusoe and " | ||
323 | "Efficeon processors."); | ||
324 | MODULE_LICENSE("GPL"); | ||
325 | |||
326 | module_init(longrun_init); | ||
327 | module_exit(longrun_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.c b/arch/x86/kernel/cpu/cpufreq/mperf.c deleted file mode 100644 index 911e193018ae..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/mperf.c +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/smp.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/init.h> | ||
5 | #include <linux/cpufreq.h> | ||
6 | #include <linux/slab.h> | ||
7 | |||
8 | #include "mperf.h" | ||
9 | |||
10 | static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf); | ||
11 | |||
12 | /* Called via smp_call_function_single(), on the target CPU */ | ||
13 | static void read_measured_perf_ctrs(void *_cur) | ||
14 | { | ||
15 | struct aperfmperf *am = _cur; | ||
16 | |||
17 | get_aperfmperf(am); | ||
18 | } | ||
19 | |||
20 | /* | ||
21 | * Return the measured active (C0) frequency on this CPU since last call | ||
22 | * to this function. | ||
23 | * Input: cpu number | ||
24 | * Return: Average CPU frequency in terms of max frequency (zero on error) | ||
25 | * | ||
26 | * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance | ||
27 | * over a period of time, while CPU is in C0 state. | ||
28 | * IA32_MPERF counts at the rate of max advertised frequency | ||
29 | * IA32_APERF counts at the rate of actual CPU frequency | ||
30 | * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and | ||
31 | * no meaning should be associated with absolute values of these MSRs. | ||
32 | */ | ||
33 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
34 | unsigned int cpu) | ||
35 | { | ||
36 | struct aperfmperf perf; | ||
37 | unsigned long ratio; | ||
38 | unsigned int retval; | ||
39 | |||
40 | if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1)) | ||
41 | return 0; | ||
42 | |||
43 | ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf); | ||
44 | per_cpu(acfreq_old_perf, cpu) = perf; | ||
45 | |||
46 | retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT; | ||
47 | |||
48 | return retval; | ||
49 | } | ||
50 | EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf); | ||
51 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.h b/arch/x86/kernel/cpu/cpufreq/mperf.h deleted file mode 100644 index 5dbf2950dc22..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/mperf.h +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | /* | ||
2 | * (c) 2010 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | */ | ||
7 | |||
8 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
9 | unsigned int cpu); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c deleted file mode 100644 index bd1cac747f67..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c +++ /dev/null | |||
@@ -1,331 +0,0 @@ | |||
1 | /* | ||
2 | * Pentium 4/Xeon CPU on demand clock modulation/speed scaling | ||
3 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
4 | * (C) 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
5 | * (C) 2002 Arjan van de Ven <arjanv@redhat.com> | ||
6 | * (C) 2002 Tora T. Engstad | ||
7 | * All Rights Reserved | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version | ||
12 | * 2 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * The author(s) of this software shall not be held liable for damages | ||
15 | * of any nature resulting due to the use of this software. This | ||
16 | * software is provided AS-IS with no warranties. | ||
17 | * | ||
18 | * Date Errata Description | ||
19 | * 20020525 N44, O17 12.5% or 25% DC causes lockup | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/smp.h> | ||
27 | #include <linux/cpufreq.h> | ||
28 | #include <linux/cpumask.h> | ||
29 | #include <linux/timex.h> | ||
30 | |||
31 | #include <asm/processor.h> | ||
32 | #include <asm/msr.h> | ||
33 | #include <asm/timer.h> | ||
34 | |||
35 | #include "speedstep-lib.h" | ||
36 | |||
37 | #define PFX "p4-clockmod: " | ||
38 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
39 | "p4-clockmod", msg) | ||
40 | |||
41 | /* | ||
42 | * Duty Cycle (3bits), note DC_DISABLE is not specified in | ||
43 | * intel docs i just use it to mean disable | ||
44 | */ | ||
45 | enum { | ||
46 | DC_RESV, DC_DFLT, DC_25PT, DC_38PT, DC_50PT, | ||
47 | DC_64PT, DC_75PT, DC_88PT, DC_DISABLE | ||
48 | }; | ||
49 | |||
50 | #define DC_ENTRIES 8 | ||
51 | |||
52 | |||
53 | static int has_N44_O17_errata[NR_CPUS]; | ||
54 | static unsigned int stock_freq; | ||
55 | static struct cpufreq_driver p4clockmod_driver; | ||
56 | static unsigned int cpufreq_p4_get(unsigned int cpu); | ||
57 | |||
58 | static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate) | ||
59 | { | ||
60 | u32 l, h; | ||
61 | |||
62 | if (!cpu_online(cpu) || | ||
63 | (newstate > DC_DISABLE) || (newstate == DC_RESV)) | ||
64 | return -EINVAL; | ||
65 | |||
66 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h); | ||
67 | |||
68 | if (l & 0x01) | ||
69 | dprintk("CPU#%d currently thermal throttled\n", cpu); | ||
70 | |||
71 | if (has_N44_O17_errata[cpu] && | ||
72 | (newstate == DC_25PT || newstate == DC_DFLT)) | ||
73 | newstate = DC_38PT; | ||
74 | |||
75 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); | ||
76 | if (newstate == DC_DISABLE) { | ||
77 | dprintk("CPU#%d disabling modulation\n", cpu); | ||
78 | wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l & ~(1<<4), h); | ||
79 | } else { | ||
80 | dprintk("CPU#%d setting duty cycle to %d%%\n", | ||
81 | cpu, ((125 * newstate) / 10)); | ||
82 | /* bits 63 - 5 : reserved | ||
83 | * bit 4 : enable/disable | ||
84 | * bits 3-1 : duty cycle | ||
85 | * bit 0 : reserved | ||
86 | */ | ||
87 | l = (l & ~14); | ||
88 | l = l | (1<<4) | ((newstate & 0x7)<<1); | ||
89 | wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l, h); | ||
90 | } | ||
91 | |||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | |||
96 | static struct cpufreq_frequency_table p4clockmod_table[] = { | ||
97 | {DC_RESV, CPUFREQ_ENTRY_INVALID}, | ||
98 | {DC_DFLT, 0}, | ||
99 | {DC_25PT, 0}, | ||
100 | {DC_38PT, 0}, | ||
101 | {DC_50PT, 0}, | ||
102 | {DC_64PT, 0}, | ||
103 | {DC_75PT, 0}, | ||
104 | {DC_88PT, 0}, | ||
105 | {DC_DISABLE, 0}, | ||
106 | {DC_RESV, CPUFREQ_TABLE_END}, | ||
107 | }; | ||
108 | |||
109 | |||
110 | static int cpufreq_p4_target(struct cpufreq_policy *policy, | ||
111 | unsigned int target_freq, | ||
112 | unsigned int relation) | ||
113 | { | ||
114 | unsigned int newstate = DC_RESV; | ||
115 | struct cpufreq_freqs freqs; | ||
116 | int i; | ||
117 | |||
118 | if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], | ||
119 | target_freq, relation, &newstate)) | ||
120 | return -EINVAL; | ||
121 | |||
122 | freqs.old = cpufreq_p4_get(policy->cpu); | ||
123 | freqs.new = stock_freq * p4clockmod_table[newstate].index / 8; | ||
124 | |||
125 | if (freqs.new == freqs.old) | ||
126 | return 0; | ||
127 | |||
128 | /* notifiers */ | ||
129 | for_each_cpu(i, policy->cpus) { | ||
130 | freqs.cpu = i; | ||
131 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
132 | } | ||
133 | |||
134 | /* run on each logical CPU, | ||
135 | * see section 13.15.3 of IA32 Intel Architecture Software | ||
136 | * Developer's Manual, Volume 3 | ||
137 | */ | ||
138 | for_each_cpu(i, policy->cpus) | ||
139 | cpufreq_p4_setdc(i, p4clockmod_table[newstate].index); | ||
140 | |||
141 | /* notifiers */ | ||
142 | for_each_cpu(i, policy->cpus) { | ||
143 | freqs.cpu = i; | ||
144 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
145 | } | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | |||
151 | static int cpufreq_p4_verify(struct cpufreq_policy *policy) | ||
152 | { | ||
153 | return cpufreq_frequency_table_verify(policy, &p4clockmod_table[0]); | ||
154 | } | ||
155 | |||
156 | |||
157 | static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c) | ||
158 | { | ||
159 | if (c->x86 == 0x06) { | ||
160 | if (cpu_has(c, X86_FEATURE_EST)) | ||
161 | printk(KERN_WARNING PFX "Warning: EST-capable CPU " | ||
162 | "detected. The acpi-cpufreq module offers " | ||
163 | "voltage scaling in addition of frequency " | ||
164 | "scaling. You should use that instead of " | ||
165 | "p4-clockmod, if possible.\n"); | ||
166 | switch (c->x86_model) { | ||
167 | case 0x0E: /* Core */ | ||
168 | case 0x0F: /* Core Duo */ | ||
169 | case 0x16: /* Celeron Core */ | ||
170 | case 0x1C: /* Atom */ | ||
171 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
172 | return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE); | ||
173 | case 0x0D: /* Pentium M (Dothan) */ | ||
174 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
175 | /* fall through */ | ||
176 | case 0x09: /* Pentium M (Banias) */ | ||
177 | return speedstep_get_frequency(SPEEDSTEP_CPU_PM); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | if (c->x86 != 0xF) | ||
182 | return 0; | ||
183 | |||
184 | /* on P-4s, the TSC runs with constant frequency independent whether | ||
185 | * throttling is active or not. */ | ||
186 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
187 | |||
188 | if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) { | ||
189 | printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. " | ||
190 | "The speedstep-ich or acpi cpufreq modules offer " | ||
191 | "voltage scaling in addition of frequency scaling. " | ||
192 | "You should use either one instead of p4-clockmod, " | ||
193 | "if possible.\n"); | ||
194 | return speedstep_get_frequency(SPEEDSTEP_CPU_P4M); | ||
195 | } | ||
196 | |||
197 | return speedstep_get_frequency(SPEEDSTEP_CPU_P4D); | ||
198 | } | ||
199 | |||
200 | |||
201 | |||
202 | static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy) | ||
203 | { | ||
204 | struct cpuinfo_x86 *c = &cpu_data(policy->cpu); | ||
205 | int cpuid = 0; | ||
206 | unsigned int i; | ||
207 | |||
208 | #ifdef CONFIG_SMP | ||
209 | cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); | ||
210 | #endif | ||
211 | |||
212 | /* Errata workaround */ | ||
213 | cpuid = (c->x86 << 8) | (c->x86_model << 4) | c->x86_mask; | ||
214 | switch (cpuid) { | ||
215 | case 0x0f07: | ||
216 | case 0x0f0a: | ||
217 | case 0x0f11: | ||
218 | case 0x0f12: | ||
219 | has_N44_O17_errata[policy->cpu] = 1; | ||
220 | dprintk("has errata -- disabling low frequencies\n"); | ||
221 | } | ||
222 | |||
223 | if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4D && | ||
224 | c->x86_model < 2) { | ||
225 | /* switch to maximum frequency and measure result */ | ||
226 | cpufreq_p4_setdc(policy->cpu, DC_DISABLE); | ||
227 | recalibrate_cpu_khz(); | ||
228 | } | ||
229 | /* get max frequency */ | ||
230 | stock_freq = cpufreq_p4_get_frequency(c); | ||
231 | if (!stock_freq) | ||
232 | return -EINVAL; | ||
233 | |||
234 | /* table init */ | ||
235 | for (i = 1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
236 | if ((i < 2) && (has_N44_O17_errata[policy->cpu])) | ||
237 | p4clockmod_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
238 | else | ||
239 | p4clockmod_table[i].frequency = (stock_freq * i)/8; | ||
240 | } | ||
241 | cpufreq_frequency_table_get_attr(p4clockmod_table, policy->cpu); | ||
242 | |||
243 | /* cpuinfo and default policy values */ | ||
244 | |||
245 | /* the transition latency is set to be 1 higher than the maximum | ||
246 | * transition latency of the ondemand governor */ | ||
247 | policy->cpuinfo.transition_latency = 10000001; | ||
248 | policy->cur = stock_freq; | ||
249 | |||
250 | return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]); | ||
251 | } | ||
252 | |||
253 | |||
254 | static int cpufreq_p4_cpu_exit(struct cpufreq_policy *policy) | ||
255 | { | ||
256 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | static unsigned int cpufreq_p4_get(unsigned int cpu) | ||
261 | { | ||
262 | u32 l, h; | ||
263 | |||
264 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); | ||
265 | |||
266 | if (l & 0x10) { | ||
267 | l = l >> 1; | ||
268 | l &= 0x7; | ||
269 | } else | ||
270 | l = DC_DISABLE; | ||
271 | |||
272 | if (l != DC_DISABLE) | ||
273 | return stock_freq * l / 8; | ||
274 | |||
275 | return stock_freq; | ||
276 | } | ||
277 | |||
278 | static struct freq_attr *p4clockmod_attr[] = { | ||
279 | &cpufreq_freq_attr_scaling_available_freqs, | ||
280 | NULL, | ||
281 | }; | ||
282 | |||
283 | static struct cpufreq_driver p4clockmod_driver = { | ||
284 | .verify = cpufreq_p4_verify, | ||
285 | .target = cpufreq_p4_target, | ||
286 | .init = cpufreq_p4_cpu_init, | ||
287 | .exit = cpufreq_p4_cpu_exit, | ||
288 | .get = cpufreq_p4_get, | ||
289 | .name = "p4-clockmod", | ||
290 | .owner = THIS_MODULE, | ||
291 | .attr = p4clockmod_attr, | ||
292 | }; | ||
293 | |||
294 | |||
295 | static int __init cpufreq_p4_init(void) | ||
296 | { | ||
297 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
298 | int ret; | ||
299 | |||
300 | /* | ||
301 | * THERM_CONTROL is architectural for IA32 now, so | ||
302 | * we can rely on the capability checks | ||
303 | */ | ||
304 | if (c->x86_vendor != X86_VENDOR_INTEL) | ||
305 | return -ENODEV; | ||
306 | |||
307 | if (!test_cpu_cap(c, X86_FEATURE_ACPI) || | ||
308 | !test_cpu_cap(c, X86_FEATURE_ACC)) | ||
309 | return -ENODEV; | ||
310 | |||
311 | ret = cpufreq_register_driver(&p4clockmod_driver); | ||
312 | if (!ret) | ||
313 | printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock " | ||
314 | "Modulation available\n"); | ||
315 | |||
316 | return ret; | ||
317 | } | ||
318 | |||
319 | |||
320 | static void __exit cpufreq_p4_exit(void) | ||
321 | { | ||
322 | cpufreq_unregister_driver(&p4clockmod_driver); | ||
323 | } | ||
324 | |||
325 | |||
326 | MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>"); | ||
327 | MODULE_DESCRIPTION("cpufreq driver for Pentium(TM) 4/Xeon(TM)"); | ||
328 | MODULE_LICENSE("GPL"); | ||
329 | |||
330 | late_initcall(cpufreq_p4_init); | ||
331 | module_exit(cpufreq_p4_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c deleted file mode 100644 index 4f6f679f2799..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.c +++ /dev/null | |||
@@ -1,626 +0,0 @@ | |||
1 | /* | ||
2 | * pcc-cpufreq.c - Processor Clocking Control firmware cpufreq interface | ||
3 | * | ||
4 | * Copyright (C) 2009 Red Hat, Matthew Garrett <mjg@redhat.com> | ||
5 | * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. | ||
6 | * Nagananda Chumbalkar <nagananda.chumbalkar@hp.com> | ||
7 | * | ||
8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; version 2 of the License. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or NON | ||
17 | * INFRINGEMENT. See the GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License along | ||
20 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
21 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | * | ||
23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
24 | */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/smp.h> | ||
30 | #include <linux/sched.h> | ||
31 | #include <linux/cpufreq.h> | ||
32 | #include <linux/compiler.h> | ||
33 | #include <linux/slab.h> | ||
34 | |||
35 | #include <linux/acpi.h> | ||
36 | #include <linux/io.h> | ||
37 | #include <linux/spinlock.h> | ||
38 | #include <linux/uaccess.h> | ||
39 | |||
40 | #include <acpi/processor.h> | ||
41 | |||
42 | #define PCC_VERSION "1.00.00" | ||
43 | #define POLL_LOOPS 300 | ||
44 | |||
45 | #define CMD_COMPLETE 0x1 | ||
46 | #define CMD_GET_FREQ 0x0 | ||
47 | #define CMD_SET_FREQ 0x1 | ||
48 | |||
49 | #define BUF_SZ 4 | ||
50 | |||
51 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
52 | "pcc-cpufreq", msg) | ||
53 | |||
54 | struct pcc_register_resource { | ||
55 | u8 descriptor; | ||
56 | u16 length; | ||
57 | u8 space_id; | ||
58 | u8 bit_width; | ||
59 | u8 bit_offset; | ||
60 | u8 access_size; | ||
61 | u64 address; | ||
62 | } __attribute__ ((packed)); | ||
63 | |||
64 | struct pcc_memory_resource { | ||
65 | u8 descriptor; | ||
66 | u16 length; | ||
67 | u8 space_id; | ||
68 | u8 resource_usage; | ||
69 | u8 type_specific; | ||
70 | u64 granularity; | ||
71 | u64 minimum; | ||
72 | u64 maximum; | ||
73 | u64 translation_offset; | ||
74 | u64 address_length; | ||
75 | } __attribute__ ((packed)); | ||
76 | |||
77 | static struct cpufreq_driver pcc_cpufreq_driver; | ||
78 | |||
79 | struct pcc_header { | ||
80 | u32 signature; | ||
81 | u16 length; | ||
82 | u8 major; | ||
83 | u8 minor; | ||
84 | u32 features; | ||
85 | u16 command; | ||
86 | u16 status; | ||
87 | u32 latency; | ||
88 | u32 minimum_time; | ||
89 | u32 maximum_time; | ||
90 | u32 nominal; | ||
91 | u32 throttled_frequency; | ||
92 | u32 minimum_frequency; | ||
93 | }; | ||
94 | |||
95 | static void __iomem *pcch_virt_addr; | ||
96 | static struct pcc_header __iomem *pcch_hdr; | ||
97 | |||
98 | static DEFINE_SPINLOCK(pcc_lock); | ||
99 | |||
100 | static struct acpi_generic_address doorbell; | ||
101 | |||
102 | static u64 doorbell_preserve; | ||
103 | static u64 doorbell_write; | ||
104 | |||
105 | static u8 OSC_UUID[16] = {0x63, 0x9B, 0x2C, 0x9F, 0x70, 0x91, 0x49, 0x1f, | ||
106 | 0xBB, 0x4F, 0xA5, 0x98, 0x2F, 0xA1, 0xB5, 0x46}; | ||
107 | |||
108 | struct pcc_cpu { | ||
109 | u32 input_offset; | ||
110 | u32 output_offset; | ||
111 | }; | ||
112 | |||
113 | static struct pcc_cpu __percpu *pcc_cpu_info; | ||
114 | |||
115 | static int pcc_cpufreq_verify(struct cpufreq_policy *policy) | ||
116 | { | ||
117 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, | ||
118 | policy->cpuinfo.max_freq); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | static inline void pcc_cmd(void) | ||
123 | { | ||
124 | u64 doorbell_value; | ||
125 | int i; | ||
126 | |||
127 | acpi_read(&doorbell_value, &doorbell); | ||
128 | acpi_write((doorbell_value & doorbell_preserve) | doorbell_write, | ||
129 | &doorbell); | ||
130 | |||
131 | for (i = 0; i < POLL_LOOPS; i++) { | ||
132 | if (ioread16(&pcch_hdr->status) & CMD_COMPLETE) | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | static inline void pcc_clear_mapping(void) | ||
138 | { | ||
139 | if (pcch_virt_addr) | ||
140 | iounmap(pcch_virt_addr); | ||
141 | pcch_virt_addr = NULL; | ||
142 | } | ||
143 | |||
144 | static unsigned int pcc_get_freq(unsigned int cpu) | ||
145 | { | ||
146 | struct pcc_cpu *pcc_cpu_data; | ||
147 | unsigned int curr_freq; | ||
148 | unsigned int freq_limit; | ||
149 | u16 status; | ||
150 | u32 input_buffer; | ||
151 | u32 output_buffer; | ||
152 | |||
153 | spin_lock(&pcc_lock); | ||
154 | |||
155 | dprintk("get: get_freq for CPU %d\n", cpu); | ||
156 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
157 | |||
158 | input_buffer = 0x1; | ||
159 | iowrite32(input_buffer, | ||
160 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
161 | iowrite16(CMD_GET_FREQ, &pcch_hdr->command); | ||
162 | |||
163 | pcc_cmd(); | ||
164 | |||
165 | output_buffer = | ||
166 | ioread32(pcch_virt_addr + pcc_cpu_data->output_offset); | ||
167 | |||
168 | /* Clear the input buffer - we are done with the current command */ | ||
169 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
170 | |||
171 | status = ioread16(&pcch_hdr->status); | ||
172 | if (status != CMD_COMPLETE) { | ||
173 | dprintk("get: FAILED: for CPU %d, status is %d\n", | ||
174 | cpu, status); | ||
175 | goto cmd_incomplete; | ||
176 | } | ||
177 | iowrite16(0, &pcch_hdr->status); | ||
178 | curr_freq = (((ioread32(&pcch_hdr->nominal) * (output_buffer & 0xff)) | ||
179 | / 100) * 1000); | ||
180 | |||
181 | dprintk("get: SUCCESS: (virtual) output_offset for cpu %d is " | ||
182 | "0x%x, contains a value of: 0x%x. Speed is: %d MHz\n", | ||
183 | cpu, (pcch_virt_addr + pcc_cpu_data->output_offset), | ||
184 | output_buffer, curr_freq); | ||
185 | |||
186 | freq_limit = (output_buffer >> 8) & 0xff; | ||
187 | if (freq_limit != 0xff) { | ||
188 | dprintk("get: frequency for cpu %d is being temporarily" | ||
189 | " capped at %d\n", cpu, curr_freq); | ||
190 | } | ||
191 | |||
192 | spin_unlock(&pcc_lock); | ||
193 | return curr_freq; | ||
194 | |||
195 | cmd_incomplete: | ||
196 | iowrite16(0, &pcch_hdr->status); | ||
197 | spin_unlock(&pcc_lock); | ||
198 | return -EINVAL; | ||
199 | } | ||
200 | |||
201 | static int pcc_cpufreq_target(struct cpufreq_policy *policy, | ||
202 | unsigned int target_freq, | ||
203 | unsigned int relation) | ||
204 | { | ||
205 | struct pcc_cpu *pcc_cpu_data; | ||
206 | struct cpufreq_freqs freqs; | ||
207 | u16 status; | ||
208 | u32 input_buffer; | ||
209 | int cpu; | ||
210 | |||
211 | spin_lock(&pcc_lock); | ||
212 | cpu = policy->cpu; | ||
213 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
214 | |||
215 | dprintk("target: CPU %d should go to target freq: %d " | ||
216 | "(virtual) input_offset is 0x%x\n", | ||
217 | cpu, target_freq, | ||
218 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
219 | |||
220 | freqs.new = target_freq; | ||
221 | freqs.cpu = cpu; | ||
222 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
223 | |||
224 | input_buffer = 0x1 | (((target_freq * 100) | ||
225 | / (ioread32(&pcch_hdr->nominal) * 1000)) << 8); | ||
226 | iowrite32(input_buffer, | ||
227 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
228 | iowrite16(CMD_SET_FREQ, &pcch_hdr->command); | ||
229 | |||
230 | pcc_cmd(); | ||
231 | |||
232 | /* Clear the input buffer - we are done with the current command */ | ||
233 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
234 | |||
235 | status = ioread16(&pcch_hdr->status); | ||
236 | if (status != CMD_COMPLETE) { | ||
237 | dprintk("target: FAILED for cpu %d, with status: 0x%x\n", | ||
238 | cpu, status); | ||
239 | goto cmd_incomplete; | ||
240 | } | ||
241 | iowrite16(0, &pcch_hdr->status); | ||
242 | |||
243 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
244 | dprintk("target: was SUCCESSFUL for cpu %d\n", cpu); | ||
245 | spin_unlock(&pcc_lock); | ||
246 | |||
247 | return 0; | ||
248 | |||
249 | cmd_incomplete: | ||
250 | iowrite16(0, &pcch_hdr->status); | ||
251 | spin_unlock(&pcc_lock); | ||
252 | return -EINVAL; | ||
253 | } | ||
254 | |||
255 | static int pcc_get_offset(int cpu) | ||
256 | { | ||
257 | acpi_status status; | ||
258 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
259 | union acpi_object *pccp, *offset; | ||
260 | struct pcc_cpu *pcc_cpu_data; | ||
261 | struct acpi_processor *pr; | ||
262 | int ret = 0; | ||
263 | |||
264 | pr = per_cpu(processors, cpu); | ||
265 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
266 | |||
267 | status = acpi_evaluate_object(pr->handle, "PCCP", NULL, &buffer); | ||
268 | if (ACPI_FAILURE(status)) | ||
269 | return -ENODEV; | ||
270 | |||
271 | pccp = buffer.pointer; | ||
272 | if (!pccp || pccp->type != ACPI_TYPE_PACKAGE) { | ||
273 | ret = -ENODEV; | ||
274 | goto out_free; | ||
275 | }; | ||
276 | |||
277 | offset = &(pccp->package.elements[0]); | ||
278 | if (!offset || offset->type != ACPI_TYPE_INTEGER) { | ||
279 | ret = -ENODEV; | ||
280 | goto out_free; | ||
281 | } | ||
282 | |||
283 | pcc_cpu_data->input_offset = offset->integer.value; | ||
284 | |||
285 | offset = &(pccp->package.elements[1]); | ||
286 | if (!offset || offset->type != ACPI_TYPE_INTEGER) { | ||
287 | ret = -ENODEV; | ||
288 | goto out_free; | ||
289 | } | ||
290 | |||
291 | pcc_cpu_data->output_offset = offset->integer.value; | ||
292 | |||
293 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
294 | memset_io((pcch_virt_addr + pcc_cpu_data->output_offset), 0, BUF_SZ); | ||
295 | |||
296 | dprintk("pcc_get_offset: for CPU %d: pcc_cpu_data " | ||
297 | "input_offset: 0x%x, pcc_cpu_data output_offset: 0x%x\n", | ||
298 | cpu, pcc_cpu_data->input_offset, pcc_cpu_data->output_offset); | ||
299 | out_free: | ||
300 | kfree(buffer.pointer); | ||
301 | return ret; | ||
302 | } | ||
303 | |||
304 | static int __init pcc_cpufreq_do_osc(acpi_handle *handle) | ||
305 | { | ||
306 | acpi_status status; | ||
307 | struct acpi_object_list input; | ||
308 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
309 | union acpi_object in_params[4]; | ||
310 | union acpi_object *out_obj; | ||
311 | u32 capabilities[2]; | ||
312 | u32 errors; | ||
313 | u32 supported; | ||
314 | int ret = 0; | ||
315 | |||
316 | input.count = 4; | ||
317 | input.pointer = in_params; | ||
318 | input.count = 4; | ||
319 | input.pointer = in_params; | ||
320 | in_params[0].type = ACPI_TYPE_BUFFER; | ||
321 | in_params[0].buffer.length = 16; | ||
322 | in_params[0].buffer.pointer = OSC_UUID; | ||
323 | in_params[1].type = ACPI_TYPE_INTEGER; | ||
324 | in_params[1].integer.value = 1; | ||
325 | in_params[2].type = ACPI_TYPE_INTEGER; | ||
326 | in_params[2].integer.value = 2; | ||
327 | in_params[3].type = ACPI_TYPE_BUFFER; | ||
328 | in_params[3].buffer.length = 8; | ||
329 | in_params[3].buffer.pointer = (u8 *)&capabilities; | ||
330 | |||
331 | capabilities[0] = OSC_QUERY_ENABLE; | ||
332 | capabilities[1] = 0x1; | ||
333 | |||
334 | status = acpi_evaluate_object(*handle, "_OSC", &input, &output); | ||
335 | if (ACPI_FAILURE(status)) | ||
336 | return -ENODEV; | ||
337 | |||
338 | if (!output.length) | ||
339 | return -ENODEV; | ||
340 | |||
341 | out_obj = output.pointer; | ||
342 | if (out_obj->type != ACPI_TYPE_BUFFER) { | ||
343 | ret = -ENODEV; | ||
344 | goto out_free; | ||
345 | } | ||
346 | |||
347 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
348 | if (errors) { | ||
349 | ret = -ENODEV; | ||
350 | goto out_free; | ||
351 | } | ||
352 | |||
353 | supported = *((u32 *)(out_obj->buffer.pointer + 4)); | ||
354 | if (!(supported & 0x1)) { | ||
355 | ret = -ENODEV; | ||
356 | goto out_free; | ||
357 | } | ||
358 | |||
359 | kfree(output.pointer); | ||
360 | capabilities[0] = 0x0; | ||
361 | capabilities[1] = 0x1; | ||
362 | |||
363 | status = acpi_evaluate_object(*handle, "_OSC", &input, &output); | ||
364 | if (ACPI_FAILURE(status)) | ||
365 | return -ENODEV; | ||
366 | |||
367 | if (!output.length) | ||
368 | return -ENODEV; | ||
369 | |||
370 | out_obj = output.pointer; | ||
371 | if (out_obj->type != ACPI_TYPE_BUFFER) { | ||
372 | ret = -ENODEV; | ||
373 | goto out_free; | ||
374 | } | ||
375 | |||
376 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
377 | if (errors) { | ||
378 | ret = -ENODEV; | ||
379 | goto out_free; | ||
380 | } | ||
381 | |||
382 | supported = *((u32 *)(out_obj->buffer.pointer + 4)); | ||
383 | if (!(supported & 0x1)) { | ||
384 | ret = -ENODEV; | ||
385 | goto out_free; | ||
386 | } | ||
387 | |||
388 | out_free: | ||
389 | kfree(output.pointer); | ||
390 | return ret; | ||
391 | } | ||
392 | |||
393 | static int __init pcc_cpufreq_probe(void) | ||
394 | { | ||
395 | acpi_status status; | ||
396 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
397 | struct pcc_memory_resource *mem_resource; | ||
398 | struct pcc_register_resource *reg_resource; | ||
399 | union acpi_object *out_obj, *member; | ||
400 | acpi_handle handle, osc_handle, pcch_handle; | ||
401 | int ret = 0; | ||
402 | |||
403 | status = acpi_get_handle(NULL, "\\_SB", &handle); | ||
404 | if (ACPI_FAILURE(status)) | ||
405 | return -ENODEV; | ||
406 | |||
407 | status = acpi_get_handle(handle, "PCCH", &pcch_handle); | ||
408 | if (ACPI_FAILURE(status)) | ||
409 | return -ENODEV; | ||
410 | |||
411 | status = acpi_get_handle(handle, "_OSC", &osc_handle); | ||
412 | if (ACPI_SUCCESS(status)) { | ||
413 | ret = pcc_cpufreq_do_osc(&osc_handle); | ||
414 | if (ret) | ||
415 | dprintk("probe: _OSC evaluation did not succeed\n"); | ||
416 | /* Firmware's use of _OSC is optional */ | ||
417 | ret = 0; | ||
418 | } | ||
419 | |||
420 | status = acpi_evaluate_object(handle, "PCCH", NULL, &output); | ||
421 | if (ACPI_FAILURE(status)) | ||
422 | return -ENODEV; | ||
423 | |||
424 | out_obj = output.pointer; | ||
425 | if (out_obj->type != ACPI_TYPE_PACKAGE) { | ||
426 | ret = -ENODEV; | ||
427 | goto out_free; | ||
428 | } | ||
429 | |||
430 | member = &out_obj->package.elements[0]; | ||
431 | if (member->type != ACPI_TYPE_BUFFER) { | ||
432 | ret = -ENODEV; | ||
433 | goto out_free; | ||
434 | } | ||
435 | |||
436 | mem_resource = (struct pcc_memory_resource *)member->buffer.pointer; | ||
437 | |||
438 | dprintk("probe: mem_resource descriptor: 0x%x," | ||
439 | " length: %d, space_id: %d, resource_usage: %d," | ||
440 | " type_specific: %d, granularity: 0x%llx," | ||
441 | " minimum: 0x%llx, maximum: 0x%llx," | ||
442 | " translation_offset: 0x%llx, address_length: 0x%llx\n", | ||
443 | mem_resource->descriptor, mem_resource->length, | ||
444 | mem_resource->space_id, mem_resource->resource_usage, | ||
445 | mem_resource->type_specific, mem_resource->granularity, | ||
446 | mem_resource->minimum, mem_resource->maximum, | ||
447 | mem_resource->translation_offset, | ||
448 | mem_resource->address_length); | ||
449 | |||
450 | if (mem_resource->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) { | ||
451 | ret = -ENODEV; | ||
452 | goto out_free; | ||
453 | } | ||
454 | |||
455 | pcch_virt_addr = ioremap_nocache(mem_resource->minimum, | ||
456 | mem_resource->address_length); | ||
457 | if (pcch_virt_addr == NULL) { | ||
458 | dprintk("probe: could not map shared mem region\n"); | ||
459 | goto out_free; | ||
460 | } | ||
461 | pcch_hdr = pcch_virt_addr; | ||
462 | |||
463 | dprintk("probe: PCCH header (virtual) addr: 0x%p\n", pcch_hdr); | ||
464 | dprintk("probe: PCCH header is at physical address: 0x%llx," | ||
465 | " signature: 0x%x, length: %d bytes, major: %d, minor: %d," | ||
466 | " supported features: 0x%x, command field: 0x%x," | ||
467 | " status field: 0x%x, nominal latency: %d us\n", | ||
468 | mem_resource->minimum, ioread32(&pcch_hdr->signature), | ||
469 | ioread16(&pcch_hdr->length), ioread8(&pcch_hdr->major), | ||
470 | ioread8(&pcch_hdr->minor), ioread32(&pcch_hdr->features), | ||
471 | ioread16(&pcch_hdr->command), ioread16(&pcch_hdr->status), | ||
472 | ioread32(&pcch_hdr->latency)); | ||
473 | |||
474 | dprintk("probe: min time between commands: %d us," | ||
475 | " max time between commands: %d us," | ||
476 | " nominal CPU frequency: %d MHz," | ||
477 | " minimum CPU frequency: %d MHz," | ||
478 | " minimum CPU frequency without throttling: %d MHz\n", | ||
479 | ioread32(&pcch_hdr->minimum_time), | ||
480 | ioread32(&pcch_hdr->maximum_time), | ||
481 | ioread32(&pcch_hdr->nominal), | ||
482 | ioread32(&pcch_hdr->throttled_frequency), | ||
483 | ioread32(&pcch_hdr->minimum_frequency)); | ||
484 | |||
485 | member = &out_obj->package.elements[1]; | ||
486 | if (member->type != ACPI_TYPE_BUFFER) { | ||
487 | ret = -ENODEV; | ||
488 | goto pcch_free; | ||
489 | } | ||
490 | |||
491 | reg_resource = (struct pcc_register_resource *)member->buffer.pointer; | ||
492 | |||
493 | doorbell.space_id = reg_resource->space_id; | ||
494 | doorbell.bit_width = reg_resource->bit_width; | ||
495 | doorbell.bit_offset = reg_resource->bit_offset; | ||
496 | doorbell.access_width = 64; | ||
497 | doorbell.address = reg_resource->address; | ||
498 | |||
499 | dprintk("probe: doorbell: space_id is %d, bit_width is %d, " | ||
500 | "bit_offset is %d, access_width is %d, address is 0x%llx\n", | ||
501 | doorbell.space_id, doorbell.bit_width, doorbell.bit_offset, | ||
502 | doorbell.access_width, reg_resource->address); | ||
503 | |||
504 | member = &out_obj->package.elements[2]; | ||
505 | if (member->type != ACPI_TYPE_INTEGER) { | ||
506 | ret = -ENODEV; | ||
507 | goto pcch_free; | ||
508 | } | ||
509 | |||
510 | doorbell_preserve = member->integer.value; | ||
511 | |||
512 | member = &out_obj->package.elements[3]; | ||
513 | if (member->type != ACPI_TYPE_INTEGER) { | ||
514 | ret = -ENODEV; | ||
515 | goto pcch_free; | ||
516 | } | ||
517 | |||
518 | doorbell_write = member->integer.value; | ||
519 | |||
520 | dprintk("probe: doorbell_preserve: 0x%llx," | ||
521 | " doorbell_write: 0x%llx\n", | ||
522 | doorbell_preserve, doorbell_write); | ||
523 | |||
524 | pcc_cpu_info = alloc_percpu(struct pcc_cpu); | ||
525 | if (!pcc_cpu_info) { | ||
526 | ret = -ENOMEM; | ||
527 | goto pcch_free; | ||
528 | } | ||
529 | |||
530 | printk(KERN_DEBUG "pcc-cpufreq: (v%s) driver loaded with frequency" | ||
531 | " limits: %d MHz, %d MHz\n", PCC_VERSION, | ||
532 | ioread32(&pcch_hdr->minimum_frequency), | ||
533 | ioread32(&pcch_hdr->nominal)); | ||
534 | kfree(output.pointer); | ||
535 | return ret; | ||
536 | pcch_free: | ||
537 | pcc_clear_mapping(); | ||
538 | out_free: | ||
539 | kfree(output.pointer); | ||
540 | return ret; | ||
541 | } | ||
542 | |||
543 | static int pcc_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
544 | { | ||
545 | unsigned int cpu = policy->cpu; | ||
546 | unsigned int result = 0; | ||
547 | |||
548 | if (!pcch_virt_addr) { | ||
549 | result = -1; | ||
550 | goto out; | ||
551 | } | ||
552 | |||
553 | result = pcc_get_offset(cpu); | ||
554 | if (result) { | ||
555 | dprintk("init: PCCP evaluation failed\n"); | ||
556 | goto out; | ||
557 | } | ||
558 | |||
559 | policy->max = policy->cpuinfo.max_freq = | ||
560 | ioread32(&pcch_hdr->nominal) * 1000; | ||
561 | policy->min = policy->cpuinfo.min_freq = | ||
562 | ioread32(&pcch_hdr->minimum_frequency) * 1000; | ||
563 | policy->cur = pcc_get_freq(cpu); | ||
564 | |||
565 | if (!policy->cur) { | ||
566 | dprintk("init: Unable to get current CPU frequency\n"); | ||
567 | result = -EINVAL; | ||
568 | goto out; | ||
569 | } | ||
570 | |||
571 | dprintk("init: policy->max is %d, policy->min is %d\n", | ||
572 | policy->max, policy->min); | ||
573 | out: | ||
574 | return result; | ||
575 | } | ||
576 | |||
577 | static int pcc_cpufreq_cpu_exit(struct cpufreq_policy *policy) | ||
578 | { | ||
579 | return 0; | ||
580 | } | ||
581 | |||
582 | static struct cpufreq_driver pcc_cpufreq_driver = { | ||
583 | .flags = CPUFREQ_CONST_LOOPS, | ||
584 | .get = pcc_get_freq, | ||
585 | .verify = pcc_cpufreq_verify, | ||
586 | .target = pcc_cpufreq_target, | ||
587 | .init = pcc_cpufreq_cpu_init, | ||
588 | .exit = pcc_cpufreq_cpu_exit, | ||
589 | .name = "pcc-cpufreq", | ||
590 | .owner = THIS_MODULE, | ||
591 | }; | ||
592 | |||
593 | static int __init pcc_cpufreq_init(void) | ||
594 | { | ||
595 | int ret; | ||
596 | |||
597 | if (acpi_disabled) | ||
598 | return 0; | ||
599 | |||
600 | ret = pcc_cpufreq_probe(); | ||
601 | if (ret) { | ||
602 | dprintk("pcc_cpufreq_init: PCCH evaluation failed\n"); | ||
603 | return ret; | ||
604 | } | ||
605 | |||
606 | ret = cpufreq_register_driver(&pcc_cpufreq_driver); | ||
607 | |||
608 | return ret; | ||
609 | } | ||
610 | |||
611 | static void __exit pcc_cpufreq_exit(void) | ||
612 | { | ||
613 | cpufreq_unregister_driver(&pcc_cpufreq_driver); | ||
614 | |||
615 | pcc_clear_mapping(); | ||
616 | |||
617 | free_percpu(pcc_cpu_info); | ||
618 | } | ||
619 | |||
620 | MODULE_AUTHOR("Matthew Garrett, Naga Chumbalkar"); | ||
621 | MODULE_VERSION(PCC_VERSION); | ||
622 | MODULE_DESCRIPTION("Processor Clocking Control interface driver"); | ||
623 | MODULE_LICENSE("GPL"); | ||
624 | |||
625 | late_initcall(pcc_cpufreq_init); | ||
626 | module_exit(pcc_cpufreq_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k6.c b/arch/x86/kernel/cpu/cpufreq/powernow-k6.c deleted file mode 100644 index b3379d6a5c57..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k6.c +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | /* | ||
2 | * This file was based upon code in Powertweak Linux (http://powertweak.sf.net) | ||
3 | * (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä, | ||
4 | * Dominik Brodowski. | ||
5 | * | ||
6 | * Licensed under the terms of the GNU GPL License version 2. | ||
7 | * | ||
8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/cpufreq.h> | ||
15 | #include <linux/ioport.h> | ||
16 | #include <linux/timex.h> | ||
17 | #include <linux/io.h> | ||
18 | |||
19 | #include <asm/msr.h> | ||
20 | |||
21 | #define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long | ||
22 | as it is unused */ | ||
23 | |||
24 | #define PFX "powernow-k6: " | ||
25 | static unsigned int busfreq; /* FSB, in 10 kHz */ | ||
26 | static unsigned int max_multiplier; | ||
27 | |||
28 | |||
29 | /* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */ | ||
30 | static struct cpufreq_frequency_table clock_ratio[] = { | ||
31 | {45, /* 000 -> 4.5x */ 0}, | ||
32 | {50, /* 001 -> 5.0x */ 0}, | ||
33 | {40, /* 010 -> 4.0x */ 0}, | ||
34 | {55, /* 011 -> 5.5x */ 0}, | ||
35 | {20, /* 100 -> 2.0x */ 0}, | ||
36 | {30, /* 101 -> 3.0x */ 0}, | ||
37 | {60, /* 110 -> 6.0x */ 0}, | ||
38 | {35, /* 111 -> 3.5x */ 0}, | ||
39 | {0, CPUFREQ_TABLE_END} | ||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier | ||
45 | * | ||
46 | * Returns the current setting of the frequency multiplier. Core clock | ||
47 | * speed is frequency of the Front-Side Bus multiplied with this value. | ||
48 | */ | ||
49 | static int powernow_k6_get_cpu_multiplier(void) | ||
50 | { | ||
51 | u64 invalue = 0; | ||
52 | u32 msrval; | ||
53 | |||
54 | msrval = POWERNOW_IOPORT + 0x1; | ||
55 | wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ | ||
56 | invalue = inl(POWERNOW_IOPORT + 0x8); | ||
57 | msrval = POWERNOW_IOPORT + 0x0; | ||
58 | wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ | ||
59 | |||
60 | return clock_ratio[(invalue >> 5)&7].index; | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * powernow_k6_set_state - set the PowerNow! multiplier | ||
66 | * @best_i: clock_ratio[best_i] is the target multiplier | ||
67 | * | ||
68 | * Tries to change the PowerNow! multiplier | ||
69 | */ | ||
70 | static void powernow_k6_set_state(unsigned int best_i) | ||
71 | { | ||
72 | unsigned long outvalue = 0, invalue = 0; | ||
73 | unsigned long msrval; | ||
74 | struct cpufreq_freqs freqs; | ||
75 | |||
76 | if (clock_ratio[best_i].index > max_multiplier) { | ||
77 | printk(KERN_ERR PFX "invalid target frequency\n"); | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | freqs.old = busfreq * powernow_k6_get_cpu_multiplier(); | ||
82 | freqs.new = busfreq * clock_ratio[best_i].index; | ||
83 | freqs.cpu = 0; /* powernow-k6.c is UP only driver */ | ||
84 | |||
85 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
86 | |||
87 | /* we now need to transform best_i to the BVC format, see AMD#23446 */ | ||
88 | |||
89 | outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5); | ||
90 | |||
91 | msrval = POWERNOW_IOPORT + 0x1; | ||
92 | wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ | ||
93 | invalue = inl(POWERNOW_IOPORT + 0x8); | ||
94 | invalue = invalue & 0xf; | ||
95 | outvalue = outvalue | invalue; | ||
96 | outl(outvalue , (POWERNOW_IOPORT + 0x8)); | ||
97 | msrval = POWERNOW_IOPORT + 0x0; | ||
98 | wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ | ||
99 | |||
100 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
101 | |||
102 | return; | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * powernow_k6_verify - verifies a new CPUfreq policy | ||
108 | * @policy: new policy | ||
109 | * | ||
110 | * Policy must be within lowest and highest possible CPU Frequency, | ||
111 | * and at least one possible state must be within min and max. | ||
112 | */ | ||
113 | static int powernow_k6_verify(struct cpufreq_policy *policy) | ||
114 | { | ||
115 | return cpufreq_frequency_table_verify(policy, &clock_ratio[0]); | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
120 | * powernow_k6_setpolicy - sets a new CPUFreq policy | ||
121 | * @policy: new policy | ||
122 | * @target_freq: the target frequency | ||
123 | * @relation: how that frequency relates to achieved frequency | ||
124 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
125 | * | ||
126 | * sets a new CPUFreq policy | ||
127 | */ | ||
128 | static int powernow_k6_target(struct cpufreq_policy *policy, | ||
129 | unsigned int target_freq, | ||
130 | unsigned int relation) | ||
131 | { | ||
132 | unsigned int newstate = 0; | ||
133 | |||
134 | if (cpufreq_frequency_table_target(policy, &clock_ratio[0], | ||
135 | target_freq, relation, &newstate)) | ||
136 | return -EINVAL; | ||
137 | |||
138 | powernow_k6_set_state(newstate); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | |||
144 | static int powernow_k6_cpu_init(struct cpufreq_policy *policy) | ||
145 | { | ||
146 | unsigned int i, f; | ||
147 | int result; | ||
148 | |||
149 | if (policy->cpu != 0) | ||
150 | return -ENODEV; | ||
151 | |||
152 | /* get frequencies */ | ||
153 | max_multiplier = powernow_k6_get_cpu_multiplier(); | ||
154 | busfreq = cpu_khz / max_multiplier; | ||
155 | |||
156 | /* table init */ | ||
157 | for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
158 | f = clock_ratio[i].index; | ||
159 | if (f > max_multiplier) | ||
160 | clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
161 | else | ||
162 | clock_ratio[i].frequency = busfreq * f; | ||
163 | } | ||
164 | |||
165 | /* cpuinfo and default policy values */ | ||
166 | policy->cpuinfo.transition_latency = 200000; | ||
167 | policy->cur = busfreq * max_multiplier; | ||
168 | |||
169 | result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio); | ||
170 | if (result) | ||
171 | return result; | ||
172 | |||
173 | cpufreq_frequency_table_get_attr(clock_ratio, policy->cpu); | ||
174 | |||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | |||
179 | static int powernow_k6_cpu_exit(struct cpufreq_policy *policy) | ||
180 | { | ||
181 | unsigned int i; | ||
182 | for (i = 0; i < 8; i++) { | ||
183 | if (i == max_multiplier) | ||
184 | powernow_k6_set_state(i); | ||
185 | } | ||
186 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static unsigned int powernow_k6_get(unsigned int cpu) | ||
191 | { | ||
192 | unsigned int ret; | ||
193 | ret = (busfreq * powernow_k6_get_cpu_multiplier()); | ||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | static struct freq_attr *powernow_k6_attr[] = { | ||
198 | &cpufreq_freq_attr_scaling_available_freqs, | ||
199 | NULL, | ||
200 | }; | ||
201 | |||
202 | static struct cpufreq_driver powernow_k6_driver = { | ||
203 | .verify = powernow_k6_verify, | ||
204 | .target = powernow_k6_target, | ||
205 | .init = powernow_k6_cpu_init, | ||
206 | .exit = powernow_k6_cpu_exit, | ||
207 | .get = powernow_k6_get, | ||
208 | .name = "powernow-k6", | ||
209 | .owner = THIS_MODULE, | ||
210 | .attr = powernow_k6_attr, | ||
211 | }; | ||
212 | |||
213 | |||
214 | /** | ||
215 | * powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver | ||
216 | * | ||
217 | * Initializes the K6 PowerNow! support. Returns -ENODEV on unsupported | ||
218 | * devices, -EINVAL or -ENOMEM on problems during initiatization, and zero | ||
219 | * on success. | ||
220 | */ | ||
221 | static int __init powernow_k6_init(void) | ||
222 | { | ||
223 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
224 | |||
225 | if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) || | ||
226 | ((c->x86_model != 12) && (c->x86_model != 13))) | ||
227 | return -ENODEV; | ||
228 | |||
229 | if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) { | ||
230 | printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n"); | ||
231 | return -EIO; | ||
232 | } | ||
233 | |||
234 | if (cpufreq_register_driver(&powernow_k6_driver)) { | ||
235 | release_region(POWERNOW_IOPORT, 16); | ||
236 | return -EINVAL; | ||
237 | } | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | |||
243 | /** | ||
244 | * powernow_k6_exit - unregisters AMD K6-2+/3+ PowerNow! support | ||
245 | * | ||
246 | * Unregisters AMD K6-2+ / K6-3+ PowerNow! support. | ||
247 | */ | ||
248 | static void __exit powernow_k6_exit(void) | ||
249 | { | ||
250 | cpufreq_unregister_driver(&powernow_k6_driver); | ||
251 | release_region(POWERNOW_IOPORT, 16); | ||
252 | } | ||
253 | |||
254 | |||
255 | MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, " | ||
256 | "Dominik Brodowski <linux@brodo.de>"); | ||
257 | MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors."); | ||
258 | MODULE_LICENSE("GPL"); | ||
259 | |||
260 | module_init(powernow_k6_init); | ||
261 | module_exit(powernow_k6_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c deleted file mode 100644 index 4a45fd6e41ba..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c +++ /dev/null | |||
@@ -1,752 +0,0 @@ | |||
1 | /* | ||
2 | * AMD K7 Powernow driver. | ||
3 | * (C) 2003 Dave Jones on behalf of SuSE Labs. | ||
4 | * (C) 2003-2004 Dave Jones <davej@redhat.com> | ||
5 | * | ||
6 | * Licensed under the terms of the GNU GPL License version 2. | ||
7 | * Based upon datasheets & sample CPUs kindly provided by AMD. | ||
8 | * | ||
9 | * Errata 5: | ||
10 | * CPU may fail to execute a FID/VID change in presence of interrupt. | ||
11 | * - We cli/sti on stepping A0 CPUs around the FID/VID transition. | ||
12 | * Errata 15: | ||
13 | * CPU with half frequency multipliers may hang upon wakeup from disconnect. | ||
14 | * - We disable half multipliers if ACPI is used on A0 stepping CPUs. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/moduleparam.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/cpufreq.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/dmi.h> | ||
25 | #include <linux/timex.h> | ||
26 | #include <linux/io.h> | ||
27 | |||
28 | #include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */ | ||
29 | #include <asm/msr.h> | ||
30 | #include <asm/system.h> | ||
31 | |||
32 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
33 | #include <linux/acpi.h> | ||
34 | #include <acpi/processor.h> | ||
35 | #endif | ||
36 | |||
37 | #include "powernow-k7.h" | ||
38 | |||
39 | #define PFX "powernow: " | ||
40 | |||
41 | |||
42 | struct psb_s { | ||
43 | u8 signature[10]; | ||
44 | u8 tableversion; | ||
45 | u8 flags; | ||
46 | u16 settlingtime; | ||
47 | u8 reserved1; | ||
48 | u8 numpst; | ||
49 | }; | ||
50 | |||
51 | struct pst_s { | ||
52 | u32 cpuid; | ||
53 | u8 fsbspeed; | ||
54 | u8 maxfid; | ||
55 | u8 startvid; | ||
56 | u8 numpstates; | ||
57 | }; | ||
58 | |||
59 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
60 | union powernow_acpi_control_t { | ||
61 | struct { | ||
62 | unsigned long fid:5, | ||
63 | vid:5, | ||
64 | sgtc:20, | ||
65 | res1:2; | ||
66 | } bits; | ||
67 | unsigned long val; | ||
68 | }; | ||
69 | #endif | ||
70 | |||
71 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
72 | /* divide by 1000 to get VCore voltage in V. */ | ||
73 | static const int mobile_vid_table[32] = { | ||
74 | 2000, 1950, 1900, 1850, 1800, 1750, 1700, 1650, | ||
75 | 1600, 1550, 1500, 1450, 1400, 1350, 1300, 0, | ||
76 | 1275, 1250, 1225, 1200, 1175, 1150, 1125, 1100, | ||
77 | 1075, 1050, 1025, 1000, 975, 950, 925, 0, | ||
78 | }; | ||
79 | #endif | ||
80 | |||
81 | /* divide by 10 to get FID. */ | ||
82 | static const int fid_codes[32] = { | ||
83 | 110, 115, 120, 125, 50, 55, 60, 65, | ||
84 | 70, 75, 80, 85, 90, 95, 100, 105, | ||
85 | 30, 190, 40, 200, 130, 135, 140, 210, | ||
86 | 150, 225, 160, 165, 170, 180, -1, -1, | ||
87 | }; | ||
88 | |||
89 | /* This parameter is used in order to force ACPI instead of legacy method for | ||
90 | * configuration purpose. | ||
91 | */ | ||
92 | |||
93 | static int acpi_force; | ||
94 | |||
95 | static struct cpufreq_frequency_table *powernow_table; | ||
96 | |||
97 | static unsigned int can_scale_bus; | ||
98 | static unsigned int can_scale_vid; | ||
99 | static unsigned int minimum_speed = -1; | ||
100 | static unsigned int maximum_speed; | ||
101 | static unsigned int number_scales; | ||
102 | static unsigned int fsb; | ||
103 | static unsigned int latency; | ||
104 | static char have_a0; | ||
105 | |||
106 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
107 | "powernow-k7", msg) | ||
108 | |||
109 | static int check_fsb(unsigned int fsbspeed) | ||
110 | { | ||
111 | int delta; | ||
112 | unsigned int f = fsb / 1000; | ||
113 | |||
114 | delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed; | ||
115 | return delta < 5; | ||
116 | } | ||
117 | |||
118 | static int check_powernow(void) | ||
119 | { | ||
120 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
121 | unsigned int maxei, eax, ebx, ecx, edx; | ||
122 | |||
123 | if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) { | ||
124 | #ifdef MODULE | ||
125 | printk(KERN_INFO PFX "This module only works with " | ||
126 | "AMD K7 CPUs\n"); | ||
127 | #endif | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | /* Get maximum capabilities */ | ||
132 | maxei = cpuid_eax(0x80000000); | ||
133 | if (maxei < 0x80000007) { /* Any powernow info ? */ | ||
134 | #ifdef MODULE | ||
135 | printk(KERN_INFO PFX "No powernow capabilities detected\n"); | ||
136 | #endif | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | if ((c->x86_model == 6) && (c->x86_mask == 0)) { | ||
141 | printk(KERN_INFO PFX "K7 660[A0] core detected, " | ||
142 | "enabling errata workarounds\n"); | ||
143 | have_a0 = 1; | ||
144 | } | ||
145 | |||
146 | cpuid(0x80000007, &eax, &ebx, &ecx, &edx); | ||
147 | |||
148 | /* Check we can actually do something before we say anything.*/ | ||
149 | if (!(edx & (1 << 1 | 1 << 2))) | ||
150 | return 0; | ||
151 | |||
152 | printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: "); | ||
153 | |||
154 | if (edx & 1 << 1) { | ||
155 | printk("frequency"); | ||
156 | can_scale_bus = 1; | ||
157 | } | ||
158 | |||
159 | if ((edx & (1 << 1 | 1 << 2)) == 0x6) | ||
160 | printk(" and "); | ||
161 | |||
162 | if (edx & 1 << 2) { | ||
163 | printk("voltage"); | ||
164 | can_scale_vid = 1; | ||
165 | } | ||
166 | |||
167 | printk(".\n"); | ||
168 | return 1; | ||
169 | } | ||
170 | |||
171 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
172 | static void invalidate_entry(unsigned int entry) | ||
173 | { | ||
174 | powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; | ||
175 | } | ||
176 | #endif | ||
177 | |||
178 | static int get_ranges(unsigned char *pst) | ||
179 | { | ||
180 | unsigned int j; | ||
181 | unsigned int speed; | ||
182 | u8 fid, vid; | ||
183 | |||
184 | powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * | ||
185 | (number_scales + 1)), GFP_KERNEL); | ||
186 | if (!powernow_table) | ||
187 | return -ENOMEM; | ||
188 | |||
189 | for (j = 0 ; j < number_scales; j++) { | ||
190 | fid = *pst++; | ||
191 | |||
192 | powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10; | ||
193 | powernow_table[j].index = fid; /* lower 8 bits */ | ||
194 | |||
195 | speed = powernow_table[j].frequency; | ||
196 | |||
197 | if ((fid_codes[fid] % 10) == 5) { | ||
198 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
199 | if (have_a0 == 1) | ||
200 | invalidate_entry(j); | ||
201 | #endif | ||
202 | } | ||
203 | |||
204 | if (speed < minimum_speed) | ||
205 | minimum_speed = speed; | ||
206 | if (speed > maximum_speed) | ||
207 | maximum_speed = speed; | ||
208 | |||
209 | vid = *pst++; | ||
210 | powernow_table[j].index |= (vid << 8); /* upper 8 bits */ | ||
211 | |||
212 | dprintk(" FID: 0x%x (%d.%dx [%dMHz]) " | ||
213 | "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, | ||
214 | fid_codes[fid] % 10, speed/1000, vid, | ||
215 | mobile_vid_table[vid]/1000, | ||
216 | mobile_vid_table[vid]%1000); | ||
217 | } | ||
218 | powernow_table[number_scales].frequency = CPUFREQ_TABLE_END; | ||
219 | powernow_table[number_scales].index = 0; | ||
220 | |||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | |||
225 | static void change_FID(int fid) | ||
226 | { | ||
227 | union msr_fidvidctl fidvidctl; | ||
228 | |||
229 | rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
230 | if (fidvidctl.bits.FID != fid) { | ||
231 | fidvidctl.bits.SGTC = latency; | ||
232 | fidvidctl.bits.FID = fid; | ||
233 | fidvidctl.bits.VIDC = 0; | ||
234 | fidvidctl.bits.FIDC = 1; | ||
235 | wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | |||
240 | static void change_VID(int vid) | ||
241 | { | ||
242 | union msr_fidvidctl fidvidctl; | ||
243 | |||
244 | rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
245 | if (fidvidctl.bits.VID != vid) { | ||
246 | fidvidctl.bits.SGTC = latency; | ||
247 | fidvidctl.bits.VID = vid; | ||
248 | fidvidctl.bits.FIDC = 0; | ||
249 | fidvidctl.bits.VIDC = 1; | ||
250 | wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | |||
255 | static void change_speed(unsigned int index) | ||
256 | { | ||
257 | u8 fid, vid; | ||
258 | struct cpufreq_freqs freqs; | ||
259 | union msr_fidvidstatus fidvidstatus; | ||
260 | int cfid; | ||
261 | |||
262 | /* fid are the lower 8 bits of the index we stored into | ||
263 | * the cpufreq frequency table in powernow_decode_bios, | ||
264 | * vid are the upper 8 bits. | ||
265 | */ | ||
266 | |||
267 | fid = powernow_table[index].index & 0xFF; | ||
268 | vid = (powernow_table[index].index & 0xFF00) >> 8; | ||
269 | |||
270 | freqs.cpu = 0; | ||
271 | |||
272 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
273 | cfid = fidvidstatus.bits.CFID; | ||
274 | freqs.old = fsb * fid_codes[cfid] / 10; | ||
275 | |||
276 | freqs.new = powernow_table[index].frequency; | ||
277 | |||
278 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
279 | |||
280 | /* Now do the magic poking into the MSRs. */ | ||
281 | |||
282 | if (have_a0 == 1) /* A0 errata 5 */ | ||
283 | local_irq_disable(); | ||
284 | |||
285 | if (freqs.old > freqs.new) { | ||
286 | /* Going down, so change FID first */ | ||
287 | change_FID(fid); | ||
288 | change_VID(vid); | ||
289 | } else { | ||
290 | /* Going up, so change VID first */ | ||
291 | change_VID(vid); | ||
292 | change_FID(fid); | ||
293 | } | ||
294 | |||
295 | |||
296 | if (have_a0 == 1) | ||
297 | local_irq_enable(); | ||
298 | |||
299 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
300 | } | ||
301 | |||
302 | |||
303 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
304 | |||
305 | static struct acpi_processor_performance *acpi_processor_perf; | ||
306 | |||
307 | static int powernow_acpi_init(void) | ||
308 | { | ||
309 | int i; | ||
310 | int retval = 0; | ||
311 | union powernow_acpi_control_t pc; | ||
312 | |||
313 | if (acpi_processor_perf != NULL && powernow_table != NULL) { | ||
314 | retval = -EINVAL; | ||
315 | goto err0; | ||
316 | } | ||
317 | |||
318 | acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance), | ||
319 | GFP_KERNEL); | ||
320 | if (!acpi_processor_perf) { | ||
321 | retval = -ENOMEM; | ||
322 | goto err0; | ||
323 | } | ||
324 | |||
325 | if (!zalloc_cpumask_var(&acpi_processor_perf->shared_cpu_map, | ||
326 | GFP_KERNEL)) { | ||
327 | retval = -ENOMEM; | ||
328 | goto err05; | ||
329 | } | ||
330 | |||
331 | if (acpi_processor_register_performance(acpi_processor_perf, 0)) { | ||
332 | retval = -EIO; | ||
333 | goto err1; | ||
334 | } | ||
335 | |||
336 | if (acpi_processor_perf->control_register.space_id != | ||
337 | ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
338 | retval = -ENODEV; | ||
339 | goto err2; | ||
340 | } | ||
341 | |||
342 | if (acpi_processor_perf->status_register.space_id != | ||
343 | ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
344 | retval = -ENODEV; | ||
345 | goto err2; | ||
346 | } | ||
347 | |||
348 | number_scales = acpi_processor_perf->state_count; | ||
349 | |||
350 | if (number_scales < 2) { | ||
351 | retval = -ENODEV; | ||
352 | goto err2; | ||
353 | } | ||
354 | |||
355 | powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * | ||
356 | (number_scales + 1)), GFP_KERNEL); | ||
357 | if (!powernow_table) { | ||
358 | retval = -ENOMEM; | ||
359 | goto err2; | ||
360 | } | ||
361 | |||
362 | pc.val = (unsigned long) acpi_processor_perf->states[0].control; | ||
363 | for (i = 0; i < number_scales; i++) { | ||
364 | u8 fid, vid; | ||
365 | struct acpi_processor_px *state = | ||
366 | &acpi_processor_perf->states[i]; | ||
367 | unsigned int speed, speed_mhz; | ||
368 | |||
369 | pc.val = (unsigned long) state->control; | ||
370 | dprintk("acpi: P%d: %d MHz %d mW %d uS control %08x SGTC %d\n", | ||
371 | i, | ||
372 | (u32) state->core_frequency, | ||
373 | (u32) state->power, | ||
374 | (u32) state->transition_latency, | ||
375 | (u32) state->control, | ||
376 | pc.bits.sgtc); | ||
377 | |||
378 | vid = pc.bits.vid; | ||
379 | fid = pc.bits.fid; | ||
380 | |||
381 | powernow_table[i].frequency = fsb * fid_codes[fid] / 10; | ||
382 | powernow_table[i].index = fid; /* lower 8 bits */ | ||
383 | powernow_table[i].index |= (vid << 8); /* upper 8 bits */ | ||
384 | |||
385 | speed = powernow_table[i].frequency; | ||
386 | speed_mhz = speed / 1000; | ||
387 | |||
388 | /* processor_perflib will multiply the MHz value by 1000 to | ||
389 | * get a KHz value (e.g. 1266000). However, powernow-k7 works | ||
390 | * with true KHz values (e.g. 1266768). To ensure that all | ||
391 | * powernow frequencies are available, we must ensure that | ||
392 | * ACPI doesn't restrict them, so we round up the MHz value | ||
393 | * to ensure that perflib's computed KHz value is greater than | ||
394 | * or equal to powernow's KHz value. | ||
395 | */ | ||
396 | if (speed % 1000 > 0) | ||
397 | speed_mhz++; | ||
398 | |||
399 | if ((fid_codes[fid] % 10) == 5) { | ||
400 | if (have_a0 == 1) | ||
401 | invalidate_entry(i); | ||
402 | } | ||
403 | |||
404 | dprintk(" FID: 0x%x (%d.%dx [%dMHz]) " | ||
405 | "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, | ||
406 | fid_codes[fid] % 10, speed_mhz, vid, | ||
407 | mobile_vid_table[vid]/1000, | ||
408 | mobile_vid_table[vid]%1000); | ||
409 | |||
410 | if (state->core_frequency != speed_mhz) { | ||
411 | state->core_frequency = speed_mhz; | ||
412 | dprintk(" Corrected ACPI frequency to %d\n", | ||
413 | speed_mhz); | ||
414 | } | ||
415 | |||
416 | if (latency < pc.bits.sgtc) | ||
417 | latency = pc.bits.sgtc; | ||
418 | |||
419 | if (speed < minimum_speed) | ||
420 | minimum_speed = speed; | ||
421 | if (speed > maximum_speed) | ||
422 | maximum_speed = speed; | ||
423 | } | ||
424 | |||
425 | powernow_table[i].frequency = CPUFREQ_TABLE_END; | ||
426 | powernow_table[i].index = 0; | ||
427 | |||
428 | /* notify BIOS that we exist */ | ||
429 | acpi_processor_notify_smm(THIS_MODULE); | ||
430 | |||
431 | return 0; | ||
432 | |||
433 | err2: | ||
434 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | ||
435 | err1: | ||
436 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
437 | err05: | ||
438 | kfree(acpi_processor_perf); | ||
439 | err0: | ||
440 | printk(KERN_WARNING PFX "ACPI perflib can not be used on " | ||
441 | "this platform\n"); | ||
442 | acpi_processor_perf = NULL; | ||
443 | return retval; | ||
444 | } | ||
445 | #else | ||
446 | static int powernow_acpi_init(void) | ||
447 | { | ||
448 | printk(KERN_INFO PFX "no support for ACPI processor found." | ||
449 | " Please recompile your kernel with ACPI processor\n"); | ||
450 | return -EINVAL; | ||
451 | } | ||
452 | #endif | ||
453 | |||
454 | static void print_pst_entry(struct pst_s *pst, unsigned int j) | ||
455 | { | ||
456 | dprintk("PST:%d (@%p)\n", j, pst); | ||
457 | dprintk(" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n", | ||
458 | pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid); | ||
459 | } | ||
460 | |||
461 | static int powernow_decode_bios(int maxfid, int startvid) | ||
462 | { | ||
463 | struct psb_s *psb; | ||
464 | struct pst_s *pst; | ||
465 | unsigned int i, j; | ||
466 | unsigned char *p; | ||
467 | unsigned int etuple; | ||
468 | unsigned int ret; | ||
469 | |||
470 | etuple = cpuid_eax(0x80000001); | ||
471 | |||
472 | for (i = 0xC0000; i < 0xffff0 ; i += 16) { | ||
473 | |||
474 | p = phys_to_virt(i); | ||
475 | |||
476 | if (memcmp(p, "AMDK7PNOW!", 10) == 0) { | ||
477 | dprintk("Found PSB header at %p\n", p); | ||
478 | psb = (struct psb_s *) p; | ||
479 | dprintk("Table version: 0x%x\n", psb->tableversion); | ||
480 | if (psb->tableversion != 0x12) { | ||
481 | printk(KERN_INFO PFX "Sorry, only v1.2 tables" | ||
482 | " supported right now\n"); | ||
483 | return -ENODEV; | ||
484 | } | ||
485 | |||
486 | dprintk("Flags: 0x%x\n", psb->flags); | ||
487 | if ((psb->flags & 1) == 0) | ||
488 | dprintk("Mobile voltage regulator\n"); | ||
489 | else | ||
490 | dprintk("Desktop voltage regulator\n"); | ||
491 | |||
492 | latency = psb->settlingtime; | ||
493 | if (latency < 100) { | ||
494 | printk(KERN_INFO PFX "BIOS set settling time " | ||
495 | "to %d microseconds. " | ||
496 | "Should be at least 100. " | ||
497 | "Correcting.\n", latency); | ||
498 | latency = 100; | ||
499 | } | ||
500 | dprintk("Settling Time: %d microseconds.\n", | ||
501 | psb->settlingtime); | ||
502 | dprintk("Has %d PST tables. (Only dumping ones " | ||
503 | "relevant to this CPU).\n", | ||
504 | psb->numpst); | ||
505 | |||
506 | p += sizeof(struct psb_s); | ||
507 | |||
508 | pst = (struct pst_s *) p; | ||
509 | |||
510 | for (j = 0; j < psb->numpst; j++) { | ||
511 | pst = (struct pst_s *) p; | ||
512 | number_scales = pst->numpstates; | ||
513 | |||
514 | if ((etuple == pst->cpuid) && | ||
515 | check_fsb(pst->fsbspeed) && | ||
516 | (maxfid == pst->maxfid) && | ||
517 | (startvid == pst->startvid)) { | ||
518 | print_pst_entry(pst, j); | ||
519 | p = (char *)pst + sizeof(struct pst_s); | ||
520 | ret = get_ranges(p); | ||
521 | return ret; | ||
522 | } else { | ||
523 | unsigned int k; | ||
524 | p = (char *)pst + sizeof(struct pst_s); | ||
525 | for (k = 0; k < number_scales; k++) | ||
526 | p += 2; | ||
527 | } | ||
528 | } | ||
529 | printk(KERN_INFO PFX "No PST tables match this cpuid " | ||
530 | "(0x%x)\n", etuple); | ||
531 | printk(KERN_INFO PFX "This is indicative of a broken " | ||
532 | "BIOS.\n"); | ||
533 | |||
534 | return -EINVAL; | ||
535 | } | ||
536 | p++; | ||
537 | } | ||
538 | |||
539 | return -ENODEV; | ||
540 | } | ||
541 | |||
542 | |||
543 | static int powernow_target(struct cpufreq_policy *policy, | ||
544 | unsigned int target_freq, | ||
545 | unsigned int relation) | ||
546 | { | ||
547 | unsigned int newstate; | ||
548 | |||
549 | if (cpufreq_frequency_table_target(policy, powernow_table, target_freq, | ||
550 | relation, &newstate)) | ||
551 | return -EINVAL; | ||
552 | |||
553 | change_speed(newstate); | ||
554 | |||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | |||
559 | static int powernow_verify(struct cpufreq_policy *policy) | ||
560 | { | ||
561 | return cpufreq_frequency_table_verify(policy, powernow_table); | ||
562 | } | ||
563 | |||
564 | /* | ||
565 | * We use the fact that the bus frequency is somehow | ||
566 | * a multiple of 100000/3 khz, then we compute sgtc according | ||
567 | * to this multiple. | ||
568 | * That way, we match more how AMD thinks all of that work. | ||
569 | * We will then get the same kind of behaviour already tested under | ||
570 | * the "well-known" other OS. | ||
571 | */ | ||
572 | static int __cpuinit fixup_sgtc(void) | ||
573 | { | ||
574 | unsigned int sgtc; | ||
575 | unsigned int m; | ||
576 | |||
577 | m = fsb / 3333; | ||
578 | if ((m % 10) >= 5) | ||
579 | m += 5; | ||
580 | |||
581 | m /= 10; | ||
582 | |||
583 | sgtc = 100 * m * latency; | ||
584 | sgtc = sgtc / 3; | ||
585 | if (sgtc > 0xfffff) { | ||
586 | printk(KERN_WARNING PFX "SGTC too large %d\n", sgtc); | ||
587 | sgtc = 0xfffff; | ||
588 | } | ||
589 | return sgtc; | ||
590 | } | ||
591 | |||
592 | static unsigned int powernow_get(unsigned int cpu) | ||
593 | { | ||
594 | union msr_fidvidstatus fidvidstatus; | ||
595 | unsigned int cfid; | ||
596 | |||
597 | if (cpu) | ||
598 | return 0; | ||
599 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
600 | cfid = fidvidstatus.bits.CFID; | ||
601 | |||
602 | return fsb * fid_codes[cfid] / 10; | ||
603 | } | ||
604 | |||
605 | |||
606 | static int __cpuinit acer_cpufreq_pst(const struct dmi_system_id *d) | ||
607 | { | ||
608 | printk(KERN_WARNING PFX | ||
609 | "%s laptop with broken PST tables in BIOS detected.\n", | ||
610 | d->ident); | ||
611 | printk(KERN_WARNING PFX | ||
612 | "You need to downgrade to 3A21 (09/09/2002), or try a newer " | ||
613 | "BIOS than 3A71 (01/20/2003)\n"); | ||
614 | printk(KERN_WARNING PFX | ||
615 | "cpufreq scaling has been disabled as a result of this.\n"); | ||
616 | return 0; | ||
617 | } | ||
618 | |||
619 | /* | ||
620 | * Some Athlon laptops have really fucked PST tables. | ||
621 | * A BIOS update is all that can save them. | ||
622 | * Mention this, and disable cpufreq. | ||
623 | */ | ||
624 | static struct dmi_system_id __cpuinitdata powernow_dmi_table[] = { | ||
625 | { | ||
626 | .callback = acer_cpufreq_pst, | ||
627 | .ident = "Acer Aspire", | ||
628 | .matches = { | ||
629 | DMI_MATCH(DMI_SYS_VENDOR, "Insyde Software"), | ||
630 | DMI_MATCH(DMI_BIOS_VERSION, "3A71"), | ||
631 | }, | ||
632 | }, | ||
633 | { } | ||
634 | }; | ||
635 | |||
636 | static int __cpuinit powernow_cpu_init(struct cpufreq_policy *policy) | ||
637 | { | ||
638 | union msr_fidvidstatus fidvidstatus; | ||
639 | int result; | ||
640 | |||
641 | if (policy->cpu != 0) | ||
642 | return -ENODEV; | ||
643 | |||
644 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
645 | |||
646 | recalibrate_cpu_khz(); | ||
647 | |||
648 | fsb = (10 * cpu_khz) / fid_codes[fidvidstatus.bits.CFID]; | ||
649 | if (!fsb) { | ||
650 | printk(KERN_WARNING PFX "can not determine bus frequency\n"); | ||
651 | return -EINVAL; | ||
652 | } | ||
653 | dprintk("FSB: %3dMHz\n", fsb/1000); | ||
654 | |||
655 | if (dmi_check_system(powernow_dmi_table) || acpi_force) { | ||
656 | printk(KERN_INFO PFX "PSB/PST known to be broken. " | ||
657 | "Trying ACPI instead\n"); | ||
658 | result = powernow_acpi_init(); | ||
659 | } else { | ||
660 | result = powernow_decode_bios(fidvidstatus.bits.MFID, | ||
661 | fidvidstatus.bits.SVID); | ||
662 | if (result) { | ||
663 | printk(KERN_INFO PFX "Trying ACPI perflib\n"); | ||
664 | maximum_speed = 0; | ||
665 | minimum_speed = -1; | ||
666 | latency = 0; | ||
667 | result = powernow_acpi_init(); | ||
668 | if (result) { | ||
669 | printk(KERN_INFO PFX | ||
670 | "ACPI and legacy methods failed\n"); | ||
671 | } | ||
672 | } else { | ||
673 | /* SGTC use the bus clock as timer */ | ||
674 | latency = fixup_sgtc(); | ||
675 | printk(KERN_INFO PFX "SGTC: %d\n", latency); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | if (result) | ||
680 | return result; | ||
681 | |||
682 | printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n", | ||
683 | minimum_speed/1000, maximum_speed/1000); | ||
684 | |||
685 | policy->cpuinfo.transition_latency = | ||
686 | cpufreq_scale(2000000UL, fsb, latency); | ||
687 | |||
688 | policy->cur = powernow_get(0); | ||
689 | |||
690 | cpufreq_frequency_table_get_attr(powernow_table, policy->cpu); | ||
691 | |||
692 | return cpufreq_frequency_table_cpuinfo(policy, powernow_table); | ||
693 | } | ||
694 | |||
695 | static int powernow_cpu_exit(struct cpufreq_policy *policy) | ||
696 | { | ||
697 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
698 | |||
699 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
700 | if (acpi_processor_perf) { | ||
701 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | ||
702 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
703 | kfree(acpi_processor_perf); | ||
704 | } | ||
705 | #endif | ||
706 | |||
707 | kfree(powernow_table); | ||
708 | return 0; | ||
709 | } | ||
710 | |||
711 | static struct freq_attr *powernow_table_attr[] = { | ||
712 | &cpufreq_freq_attr_scaling_available_freqs, | ||
713 | NULL, | ||
714 | }; | ||
715 | |||
716 | static struct cpufreq_driver powernow_driver = { | ||
717 | .verify = powernow_verify, | ||
718 | .target = powernow_target, | ||
719 | .get = powernow_get, | ||
720 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
721 | .bios_limit = acpi_processor_get_bios_limit, | ||
722 | #endif | ||
723 | .init = powernow_cpu_init, | ||
724 | .exit = powernow_cpu_exit, | ||
725 | .name = "powernow-k7", | ||
726 | .owner = THIS_MODULE, | ||
727 | .attr = powernow_table_attr, | ||
728 | }; | ||
729 | |||
730 | static int __init powernow_init(void) | ||
731 | { | ||
732 | if (check_powernow() == 0) | ||
733 | return -ENODEV; | ||
734 | return cpufreq_register_driver(&powernow_driver); | ||
735 | } | ||
736 | |||
737 | |||
738 | static void __exit powernow_exit(void) | ||
739 | { | ||
740 | cpufreq_unregister_driver(&powernow_driver); | ||
741 | } | ||
742 | |||
743 | module_param(acpi_force, int, 0444); | ||
744 | MODULE_PARM_DESC(acpi_force, "Force ACPI to be used."); | ||
745 | |||
746 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); | ||
747 | MODULE_DESCRIPTION("Powernow driver for AMD K7 processors."); | ||
748 | MODULE_LICENSE("GPL"); | ||
749 | |||
750 | late_initcall(powernow_init); | ||
751 | module_exit(powernow_exit); | ||
752 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.h b/arch/x86/kernel/cpu/cpufreq/powernow-k7.h deleted file mode 100644 index 35fb4eaf6e1c..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.h +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2003 Dave Jones. | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * AMD-specific information | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | union msr_fidvidctl { | ||
11 | struct { | ||
12 | unsigned FID:5, // 4:0 | ||
13 | reserved1:3, // 7:5 | ||
14 | VID:5, // 12:8 | ||
15 | reserved2:3, // 15:13 | ||
16 | FIDC:1, // 16 | ||
17 | VIDC:1, // 17 | ||
18 | reserved3:2, // 19:18 | ||
19 | FIDCHGRATIO:1, // 20 | ||
20 | reserved4:11, // 31-21 | ||
21 | SGTC:20, // 32:51 | ||
22 | reserved5:12; // 63:52 | ||
23 | } bits; | ||
24 | unsigned long long val; | ||
25 | }; | ||
26 | |||
27 | union msr_fidvidstatus { | ||
28 | struct { | ||
29 | unsigned CFID:5, // 4:0 | ||
30 | reserved1:3, // 7:5 | ||
31 | SFID:5, // 12:8 | ||
32 | reserved2:3, // 15:13 | ||
33 | MFID:5, // 20:16 | ||
34 | reserved3:11, // 31:21 | ||
35 | CVID:5, // 36:32 | ||
36 | reserved4:3, // 39:37 | ||
37 | SVID:5, // 44:40 | ||
38 | reserved5:3, // 47:45 | ||
39 | MVID:5, // 52:48 | ||
40 | reserved6:11; // 63:53 | ||
41 | } bits; | ||
42 | unsigned long long val; | ||
43 | }; | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c deleted file mode 100644 index 491977baf6c0..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c +++ /dev/null | |||
@@ -1,1601 +0,0 @@ | |||
1 | /* | ||
2 | * (c) 2003-2010 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | * | ||
7 | * Support : mark.langsdorf@amd.com | ||
8 | * | ||
9 | * Based on the powernow-k7.c module written by Dave Jones. | ||
10 | * (C) 2003 Dave Jones on behalf of SuSE Labs | ||
11 | * (C) 2004 Dominik Brodowski <linux@brodo.de> | ||
12 | * (C) 2004 Pavel Machek <pavel@ucw.cz> | ||
13 | * Licensed under the terms of the GNU GPL License version 2. | ||
14 | * Based upon datasheets & sample CPUs kindly provided by AMD. | ||
15 | * | ||
16 | * Valuable input gratefully received from Dave Jones, Pavel Machek, | ||
17 | * Dominik Brodowski, Jacob Shin, and others. | ||
18 | * Originally developed by Paul Devriendt. | ||
19 | * Processor information obtained from Chapter 9 (Power and Thermal Management) | ||
20 | * of the "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD | ||
21 | * Opteron Processors" available for download from www.amd.com | ||
22 | * | ||
23 | * Tables for specific CPUs can be inferred from | ||
24 | * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/30430.pdf | ||
25 | */ | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/smp.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/cpufreq.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/cpumask.h> | ||
35 | #include <linux/sched.h> /* for current / set_cpus_allowed() */ | ||
36 | #include <linux/io.h> | ||
37 | #include <linux/delay.h> | ||
38 | |||
39 | #include <asm/msr.h> | ||
40 | |||
41 | #include <linux/acpi.h> | ||
42 | #include <linux/mutex.h> | ||
43 | #include <acpi/processor.h> | ||
44 | |||
45 | #define PFX "powernow-k8: " | ||
46 | #define VERSION "version 2.20.00" | ||
47 | #include "powernow-k8.h" | ||
48 | #include "mperf.h" | ||
49 | |||
50 | /* serialize freq changes */ | ||
51 | static DEFINE_MUTEX(fidvid_mutex); | ||
52 | |||
53 | static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); | ||
54 | |||
55 | static int cpu_family = CPU_OPTERON; | ||
56 | |||
57 | /* core performance boost */ | ||
58 | static bool cpb_capable, cpb_enabled; | ||
59 | static struct msr __percpu *msrs; | ||
60 | |||
61 | static struct cpufreq_driver cpufreq_amd64_driver; | ||
62 | |||
63 | #ifndef CONFIG_SMP | ||
64 | static inline const struct cpumask *cpu_core_mask(int cpu) | ||
65 | { | ||
66 | return cpumask_of(0); | ||
67 | } | ||
68 | #endif | ||
69 | |||
70 | /* Return a frequency in MHz, given an input fid */ | ||
71 | static u32 find_freq_from_fid(u32 fid) | ||
72 | { | ||
73 | return 800 + (fid * 100); | ||
74 | } | ||
75 | |||
76 | /* Return a frequency in KHz, given an input fid */ | ||
77 | static u32 find_khz_freq_from_fid(u32 fid) | ||
78 | { | ||
79 | return 1000 * find_freq_from_fid(fid); | ||
80 | } | ||
81 | |||
82 | static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, | ||
83 | u32 pstate) | ||
84 | { | ||
85 | return data[pstate].frequency; | ||
86 | } | ||
87 | |||
88 | /* Return the vco fid for an input fid | ||
89 | * | ||
90 | * Each "low" fid has corresponding "high" fid, and you can get to "low" fids | ||
91 | * only from corresponding high fids. This returns "high" fid corresponding to | ||
92 | * "low" one. | ||
93 | */ | ||
94 | static u32 convert_fid_to_vco_fid(u32 fid) | ||
95 | { | ||
96 | if (fid < HI_FID_TABLE_BOTTOM) | ||
97 | return 8 + (2 * fid); | ||
98 | else | ||
99 | return fid; | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * Return 1 if the pending bit is set. Unless we just instructed the processor | ||
104 | * to transition to a new state, seeing this bit set is really bad news. | ||
105 | */ | ||
106 | static int pending_bit_stuck(void) | ||
107 | { | ||
108 | u32 lo, hi; | ||
109 | |||
110 | if (cpu_family == CPU_HW_PSTATE) | ||
111 | return 0; | ||
112 | |||
113 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
114 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * Update the global current fid / vid values from the status msr. | ||
119 | * Returns 1 on error. | ||
120 | */ | ||
121 | static int query_current_values_with_pending_wait(struct powernow_k8_data *data) | ||
122 | { | ||
123 | u32 lo, hi; | ||
124 | u32 i = 0; | ||
125 | |||
126 | if (cpu_family == CPU_HW_PSTATE) { | ||
127 | rdmsr(MSR_PSTATE_STATUS, lo, hi); | ||
128 | i = lo & HW_PSTATE_MASK; | ||
129 | data->currpstate = i; | ||
130 | |||
131 | /* | ||
132 | * a workaround for family 11h erratum 311 might cause | ||
133 | * an "out-of-range Pstate if the core is in Pstate-0 | ||
134 | */ | ||
135 | if ((boot_cpu_data.x86 == 0x11) && (i >= data->numps)) | ||
136 | data->currpstate = HW_PSTATE_0; | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | do { | ||
141 | if (i++ > 10000) { | ||
142 | dprintk("detected change pending stuck\n"); | ||
143 | return 1; | ||
144 | } | ||
145 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
146 | } while (lo & MSR_S_LO_CHANGE_PENDING); | ||
147 | |||
148 | data->currvid = hi & MSR_S_HI_CURRENT_VID; | ||
149 | data->currfid = lo & MSR_S_LO_CURRENT_FID; | ||
150 | |||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | /* the isochronous relief time */ | ||
155 | static void count_off_irt(struct powernow_k8_data *data) | ||
156 | { | ||
157 | udelay((1 << data->irt) * 10); | ||
158 | return; | ||
159 | } | ||
160 | |||
161 | /* the voltage stabilization time */ | ||
162 | static void count_off_vst(struct powernow_k8_data *data) | ||
163 | { | ||
164 | udelay(data->vstable * VST_UNITS_20US); | ||
165 | return; | ||
166 | } | ||
167 | |||
168 | /* need to init the control msr to a safe value (for each cpu) */ | ||
169 | static void fidvid_msr_init(void) | ||
170 | { | ||
171 | u32 lo, hi; | ||
172 | u8 fid, vid; | ||
173 | |||
174 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
175 | vid = hi & MSR_S_HI_CURRENT_VID; | ||
176 | fid = lo & MSR_S_LO_CURRENT_FID; | ||
177 | lo = fid | (vid << MSR_C_LO_VID_SHIFT); | ||
178 | hi = MSR_C_HI_STP_GNT_BENIGN; | ||
179 | dprintk("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi); | ||
180 | wrmsr(MSR_FIDVID_CTL, lo, hi); | ||
181 | } | ||
182 | |||
183 | /* write the new fid value along with the other control fields to the msr */ | ||
184 | static int write_new_fid(struct powernow_k8_data *data, u32 fid) | ||
185 | { | ||
186 | u32 lo; | ||
187 | u32 savevid = data->currvid; | ||
188 | u32 i = 0; | ||
189 | |||
190 | if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) { | ||
191 | printk(KERN_ERR PFX "internal error - overflow on fid write\n"); | ||
192 | return 1; | ||
193 | } | ||
194 | |||
195 | lo = fid; | ||
196 | lo |= (data->currvid << MSR_C_LO_VID_SHIFT); | ||
197 | lo |= MSR_C_LO_INIT_FID_VID; | ||
198 | |||
199 | dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n", | ||
200 | fid, lo, data->plllock * PLL_LOCK_CONVERSION); | ||
201 | |||
202 | do { | ||
203 | wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); | ||
204 | if (i++ > 100) { | ||
205 | printk(KERN_ERR PFX | ||
206 | "Hardware error - pending bit very stuck - " | ||
207 | "no further pstate changes possible\n"); | ||
208 | return 1; | ||
209 | } | ||
210 | } while (query_current_values_with_pending_wait(data)); | ||
211 | |||
212 | count_off_irt(data); | ||
213 | |||
214 | if (savevid != data->currvid) { | ||
215 | printk(KERN_ERR PFX | ||
216 | "vid change on fid trans, old 0x%x, new 0x%x\n", | ||
217 | savevid, data->currvid); | ||
218 | return 1; | ||
219 | } | ||
220 | |||
221 | if (fid != data->currfid) { | ||
222 | printk(KERN_ERR PFX | ||
223 | "fid trans failed, fid 0x%x, curr 0x%x\n", fid, | ||
224 | data->currfid); | ||
225 | return 1; | ||
226 | } | ||
227 | |||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | /* Write a new vid to the hardware */ | ||
232 | static int write_new_vid(struct powernow_k8_data *data, u32 vid) | ||
233 | { | ||
234 | u32 lo; | ||
235 | u32 savefid = data->currfid; | ||
236 | int i = 0; | ||
237 | |||
238 | if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) { | ||
239 | printk(KERN_ERR PFX "internal error - overflow on vid write\n"); | ||
240 | return 1; | ||
241 | } | ||
242 | |||
243 | lo = data->currfid; | ||
244 | lo |= (vid << MSR_C_LO_VID_SHIFT); | ||
245 | lo |= MSR_C_LO_INIT_FID_VID; | ||
246 | |||
247 | dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n", | ||
248 | vid, lo, STOP_GRANT_5NS); | ||
249 | |||
250 | do { | ||
251 | wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS); | ||
252 | if (i++ > 100) { | ||
253 | printk(KERN_ERR PFX "internal error - pending bit " | ||
254 | "very stuck - no further pstate " | ||
255 | "changes possible\n"); | ||
256 | return 1; | ||
257 | } | ||
258 | } while (query_current_values_with_pending_wait(data)); | ||
259 | |||
260 | if (savefid != data->currfid) { | ||
261 | printk(KERN_ERR PFX "fid changed on vid trans, old " | ||
262 | "0x%x new 0x%x\n", | ||
263 | savefid, data->currfid); | ||
264 | return 1; | ||
265 | } | ||
266 | |||
267 | if (vid != data->currvid) { | ||
268 | printk(KERN_ERR PFX "vid trans failed, vid 0x%x, " | ||
269 | "curr 0x%x\n", | ||
270 | vid, data->currvid); | ||
271 | return 1; | ||
272 | } | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * Reduce the vid by the max of step or reqvid. | ||
279 | * Decreasing vid codes represent increasing voltages: | ||
280 | * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off. | ||
281 | */ | ||
282 | static int decrease_vid_code_by_step(struct powernow_k8_data *data, | ||
283 | u32 reqvid, u32 step) | ||
284 | { | ||
285 | if ((data->currvid - reqvid) > step) | ||
286 | reqvid = data->currvid - step; | ||
287 | |||
288 | if (write_new_vid(data, reqvid)) | ||
289 | return 1; | ||
290 | |||
291 | count_off_vst(data); | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | /* Change hardware pstate by single MSR write */ | ||
297 | static int transition_pstate(struct powernow_k8_data *data, u32 pstate) | ||
298 | { | ||
299 | wrmsr(MSR_PSTATE_CTRL, pstate, 0); | ||
300 | data->currpstate = pstate; | ||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ | ||
305 | static int transition_fid_vid(struct powernow_k8_data *data, | ||
306 | u32 reqfid, u32 reqvid) | ||
307 | { | ||
308 | if (core_voltage_pre_transition(data, reqvid, reqfid)) | ||
309 | return 1; | ||
310 | |||
311 | if (core_frequency_transition(data, reqfid)) | ||
312 | return 1; | ||
313 | |||
314 | if (core_voltage_post_transition(data, reqvid)) | ||
315 | return 1; | ||
316 | |||
317 | if (query_current_values_with_pending_wait(data)) | ||
318 | return 1; | ||
319 | |||
320 | if ((reqfid != data->currfid) || (reqvid != data->currvid)) { | ||
321 | printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, " | ||
322 | "curr 0x%x 0x%x\n", | ||
323 | smp_processor_id(), | ||
324 | reqfid, reqvid, data->currfid, data->currvid); | ||
325 | return 1; | ||
326 | } | ||
327 | |||
328 | dprintk("transitioned (cpu%d): new fid 0x%x, vid 0x%x\n", | ||
329 | smp_processor_id(), data->currfid, data->currvid); | ||
330 | |||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | /* Phase 1 - core voltage transition ... setup voltage */ | ||
335 | static int core_voltage_pre_transition(struct powernow_k8_data *data, | ||
336 | u32 reqvid, u32 reqfid) | ||
337 | { | ||
338 | u32 rvosteps = data->rvo; | ||
339 | u32 savefid = data->currfid; | ||
340 | u32 maxvid, lo, rvomult = 1; | ||
341 | |||
342 | dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, " | ||
343 | "reqvid 0x%x, rvo 0x%x\n", | ||
344 | smp_processor_id(), | ||
345 | data->currfid, data->currvid, reqvid, data->rvo); | ||
346 | |||
347 | if ((savefid < LO_FID_TABLE_TOP) && (reqfid < LO_FID_TABLE_TOP)) | ||
348 | rvomult = 2; | ||
349 | rvosteps *= rvomult; | ||
350 | rdmsr(MSR_FIDVID_STATUS, lo, maxvid); | ||
351 | maxvid = 0x1f & (maxvid >> 16); | ||
352 | dprintk("ph1 maxvid=0x%x\n", maxvid); | ||
353 | if (reqvid < maxvid) /* lower numbers are higher voltages */ | ||
354 | reqvid = maxvid; | ||
355 | |||
356 | while (data->currvid > reqvid) { | ||
357 | dprintk("ph1: curr 0x%x, req vid 0x%x\n", | ||
358 | data->currvid, reqvid); | ||
359 | if (decrease_vid_code_by_step(data, reqvid, data->vidmvs)) | ||
360 | return 1; | ||
361 | } | ||
362 | |||
363 | while ((rvosteps > 0) && | ||
364 | ((rvomult * data->rvo + data->currvid) > reqvid)) { | ||
365 | if (data->currvid == maxvid) { | ||
366 | rvosteps = 0; | ||
367 | } else { | ||
368 | dprintk("ph1: changing vid for rvo, req 0x%x\n", | ||
369 | data->currvid - 1); | ||
370 | if (decrease_vid_code_by_step(data, data->currvid-1, 1)) | ||
371 | return 1; | ||
372 | rvosteps--; | ||
373 | } | ||
374 | } | ||
375 | |||
376 | if (query_current_values_with_pending_wait(data)) | ||
377 | return 1; | ||
378 | |||
379 | if (savefid != data->currfid) { | ||
380 | printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", | ||
381 | data->currfid); | ||
382 | return 1; | ||
383 | } | ||
384 | |||
385 | dprintk("ph1 complete, currfid 0x%x, currvid 0x%x\n", | ||
386 | data->currfid, data->currvid); | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | /* Phase 2 - core frequency transition */ | ||
392 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid) | ||
393 | { | ||
394 | u32 vcoreqfid, vcocurrfid, vcofiddiff; | ||
395 | u32 fid_interval, savevid = data->currvid; | ||
396 | |||
397 | if (data->currfid == reqfid) { | ||
398 | printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", | ||
399 | data->currfid); | ||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, " | ||
404 | "reqfid 0x%x\n", | ||
405 | smp_processor_id(), | ||
406 | data->currfid, data->currvid, reqfid); | ||
407 | |||
408 | vcoreqfid = convert_fid_to_vco_fid(reqfid); | ||
409 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); | ||
410 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid | ||
411 | : vcoreqfid - vcocurrfid; | ||
412 | |||
413 | if ((reqfid <= LO_FID_TABLE_TOP) && (data->currfid <= LO_FID_TABLE_TOP)) | ||
414 | vcofiddiff = 0; | ||
415 | |||
416 | while (vcofiddiff > 2) { | ||
417 | (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2); | ||
418 | |||
419 | if (reqfid > data->currfid) { | ||
420 | if (data->currfid > LO_FID_TABLE_TOP) { | ||
421 | if (write_new_fid(data, | ||
422 | data->currfid + fid_interval)) | ||
423 | return 1; | ||
424 | } else { | ||
425 | if (write_new_fid | ||
426 | (data, | ||
427 | 2 + convert_fid_to_vco_fid(data->currfid))) | ||
428 | return 1; | ||
429 | } | ||
430 | } else { | ||
431 | if (write_new_fid(data, data->currfid - fid_interval)) | ||
432 | return 1; | ||
433 | } | ||
434 | |||
435 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); | ||
436 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid | ||
437 | : vcoreqfid - vcocurrfid; | ||
438 | } | ||
439 | |||
440 | if (write_new_fid(data, reqfid)) | ||
441 | return 1; | ||
442 | |||
443 | if (query_current_values_with_pending_wait(data)) | ||
444 | return 1; | ||
445 | |||
446 | if (data->currfid != reqfid) { | ||
447 | printk(KERN_ERR PFX | ||
448 | "ph2: mismatch, failed fid transition, " | ||
449 | "curr 0x%x, req 0x%x\n", | ||
450 | data->currfid, reqfid); | ||
451 | return 1; | ||
452 | } | ||
453 | |||
454 | if (savevid != data->currvid) { | ||
455 | printk(KERN_ERR PFX "ph2: vid changed, save 0x%x, curr 0x%x\n", | ||
456 | savevid, data->currvid); | ||
457 | return 1; | ||
458 | } | ||
459 | |||
460 | dprintk("ph2 complete, currfid 0x%x, currvid 0x%x\n", | ||
461 | data->currfid, data->currvid); | ||
462 | |||
463 | return 0; | ||
464 | } | ||
465 | |||
466 | /* Phase 3 - core voltage transition flow ... jump to the final vid. */ | ||
467 | static int core_voltage_post_transition(struct powernow_k8_data *data, | ||
468 | u32 reqvid) | ||
469 | { | ||
470 | u32 savefid = data->currfid; | ||
471 | u32 savereqvid = reqvid; | ||
472 | |||
473 | dprintk("ph3 (cpu%d): starting, currfid 0x%x, currvid 0x%x\n", | ||
474 | smp_processor_id(), | ||
475 | data->currfid, data->currvid); | ||
476 | |||
477 | if (reqvid != data->currvid) { | ||
478 | if (write_new_vid(data, reqvid)) | ||
479 | return 1; | ||
480 | |||
481 | if (savefid != data->currfid) { | ||
482 | printk(KERN_ERR PFX | ||
483 | "ph3: bad fid change, save 0x%x, curr 0x%x\n", | ||
484 | savefid, data->currfid); | ||
485 | return 1; | ||
486 | } | ||
487 | |||
488 | if (data->currvid != reqvid) { | ||
489 | printk(KERN_ERR PFX | ||
490 | "ph3: failed vid transition\n, " | ||
491 | "req 0x%x, curr 0x%x", | ||
492 | reqvid, data->currvid); | ||
493 | return 1; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | if (query_current_values_with_pending_wait(data)) | ||
498 | return 1; | ||
499 | |||
500 | if (savereqvid != data->currvid) { | ||
501 | dprintk("ph3 failed, currvid 0x%x\n", data->currvid); | ||
502 | return 1; | ||
503 | } | ||
504 | |||
505 | if (savefid != data->currfid) { | ||
506 | dprintk("ph3 failed, currfid changed 0x%x\n", | ||
507 | data->currfid); | ||
508 | return 1; | ||
509 | } | ||
510 | |||
511 | dprintk("ph3 complete, currfid 0x%x, currvid 0x%x\n", | ||
512 | data->currfid, data->currvid); | ||
513 | |||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | static void check_supported_cpu(void *_rc) | ||
518 | { | ||
519 | u32 eax, ebx, ecx, edx; | ||
520 | int *rc = _rc; | ||
521 | |||
522 | *rc = -ENODEV; | ||
523 | |||
524 | if (current_cpu_data.x86_vendor != X86_VENDOR_AMD) | ||
525 | return; | ||
526 | |||
527 | eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | ||
528 | if (((eax & CPUID_XFAM) != CPUID_XFAM_K8) && | ||
529 | ((eax & CPUID_XFAM) < CPUID_XFAM_10H)) | ||
530 | return; | ||
531 | |||
532 | if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { | ||
533 | if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || | ||
534 | ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) { | ||
535 | printk(KERN_INFO PFX | ||
536 | "Processor cpuid %x not supported\n", eax); | ||
537 | return; | ||
538 | } | ||
539 | |||
540 | eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); | ||
541 | if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { | ||
542 | printk(KERN_INFO PFX | ||
543 | "No frequency change capabilities detected\n"); | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
548 | if ((edx & P_STATE_TRANSITION_CAPABLE) | ||
549 | != P_STATE_TRANSITION_CAPABLE) { | ||
550 | printk(KERN_INFO PFX | ||
551 | "Power state transitions not supported\n"); | ||
552 | return; | ||
553 | } | ||
554 | } else { /* must be a HW Pstate capable processor */ | ||
555 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
556 | if ((edx & USE_HW_PSTATE) == USE_HW_PSTATE) | ||
557 | cpu_family = CPU_HW_PSTATE; | ||
558 | else | ||
559 | return; | ||
560 | } | ||
561 | |||
562 | *rc = 0; | ||
563 | } | ||
564 | |||
565 | static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, | ||
566 | u8 maxvid) | ||
567 | { | ||
568 | unsigned int j; | ||
569 | u8 lastfid = 0xff; | ||
570 | |||
571 | for (j = 0; j < data->numps; j++) { | ||
572 | if (pst[j].vid > LEAST_VID) { | ||
573 | printk(KERN_ERR FW_BUG PFX "vid %d invalid : 0x%x\n", | ||
574 | j, pst[j].vid); | ||
575 | return -EINVAL; | ||
576 | } | ||
577 | if (pst[j].vid < data->rvo) { | ||
578 | /* vid + rvo >= 0 */ | ||
579 | printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate" | ||
580 | " %d\n", j); | ||
581 | return -ENODEV; | ||
582 | } | ||
583 | if (pst[j].vid < maxvid + data->rvo) { | ||
584 | /* vid + rvo >= maxvid */ | ||
585 | printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate" | ||
586 | " %d\n", j); | ||
587 | return -ENODEV; | ||
588 | } | ||
589 | if (pst[j].fid > MAX_FID) { | ||
590 | printk(KERN_ERR FW_BUG PFX "maxfid exceeded with pstate" | ||
591 | " %d\n", j); | ||
592 | return -ENODEV; | ||
593 | } | ||
594 | if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) { | ||
595 | /* Only first fid is allowed to be in "low" range */ | ||
596 | printk(KERN_ERR FW_BUG PFX "two low fids - %d : " | ||
597 | "0x%x\n", j, pst[j].fid); | ||
598 | return -EINVAL; | ||
599 | } | ||
600 | if (pst[j].fid < lastfid) | ||
601 | lastfid = pst[j].fid; | ||
602 | } | ||
603 | if (lastfid & 1) { | ||
604 | printk(KERN_ERR FW_BUG PFX "lastfid invalid\n"); | ||
605 | return -EINVAL; | ||
606 | } | ||
607 | if (lastfid > LO_FID_TABLE_TOP) | ||
608 | printk(KERN_INFO FW_BUG PFX | ||
609 | "first fid not from lo freq table\n"); | ||
610 | |||
611 | return 0; | ||
612 | } | ||
613 | |||
614 | static void invalidate_entry(struct cpufreq_frequency_table *powernow_table, | ||
615 | unsigned int entry) | ||
616 | { | ||
617 | powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; | ||
618 | } | ||
619 | |||
620 | static void print_basics(struct powernow_k8_data *data) | ||
621 | { | ||
622 | int j; | ||
623 | for (j = 0; j < data->numps; j++) { | ||
624 | if (data->powernow_table[j].frequency != | ||
625 | CPUFREQ_ENTRY_INVALID) { | ||
626 | if (cpu_family == CPU_HW_PSTATE) { | ||
627 | printk(KERN_INFO PFX | ||
628 | " %d : pstate %d (%d MHz)\n", j, | ||
629 | data->powernow_table[j].index, | ||
630 | data->powernow_table[j].frequency/1000); | ||
631 | } else { | ||
632 | printk(KERN_INFO PFX | ||
633 | " %d : fid 0x%x (%d MHz), vid 0x%x\n", | ||
634 | j, | ||
635 | data->powernow_table[j].index & 0xff, | ||
636 | data->powernow_table[j].frequency/1000, | ||
637 | data->powernow_table[j].index >> 8); | ||
638 | } | ||
639 | } | ||
640 | } | ||
641 | if (data->batps) | ||
642 | printk(KERN_INFO PFX "Only %d pstates on battery\n", | ||
643 | data->batps); | ||
644 | } | ||
645 | |||
646 | static u32 freq_from_fid_did(u32 fid, u32 did) | ||
647 | { | ||
648 | u32 mhz = 0; | ||
649 | |||
650 | if (boot_cpu_data.x86 == 0x10) | ||
651 | mhz = (100 * (fid + 0x10)) >> did; | ||
652 | else if (boot_cpu_data.x86 == 0x11) | ||
653 | mhz = (100 * (fid + 8)) >> did; | ||
654 | else | ||
655 | BUG(); | ||
656 | |||
657 | return mhz * 1000; | ||
658 | } | ||
659 | |||
660 | static int fill_powernow_table(struct powernow_k8_data *data, | ||
661 | struct pst_s *pst, u8 maxvid) | ||
662 | { | ||
663 | struct cpufreq_frequency_table *powernow_table; | ||
664 | unsigned int j; | ||
665 | |||
666 | if (data->batps) { | ||
667 | /* use ACPI support to get full speed on mains power */ | ||
668 | printk(KERN_WARNING PFX | ||
669 | "Only %d pstates usable (use ACPI driver for full " | ||
670 | "range\n", data->batps); | ||
671 | data->numps = data->batps; | ||
672 | } | ||
673 | |||
674 | for (j = 1; j < data->numps; j++) { | ||
675 | if (pst[j-1].fid >= pst[j].fid) { | ||
676 | printk(KERN_ERR PFX "PST out of sequence\n"); | ||
677 | return -EINVAL; | ||
678 | } | ||
679 | } | ||
680 | |||
681 | if (data->numps < 2) { | ||
682 | printk(KERN_ERR PFX "no p states to transition\n"); | ||
683 | return -ENODEV; | ||
684 | } | ||
685 | |||
686 | if (check_pst_table(data, pst, maxvid)) | ||
687 | return -EINVAL; | ||
688 | |||
689 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) | ||
690 | * (data->numps + 1)), GFP_KERNEL); | ||
691 | if (!powernow_table) { | ||
692 | printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); | ||
693 | return -ENOMEM; | ||
694 | } | ||
695 | |||
696 | for (j = 0; j < data->numps; j++) { | ||
697 | int freq; | ||
698 | powernow_table[j].index = pst[j].fid; /* lower 8 bits */ | ||
699 | powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */ | ||
700 | freq = find_khz_freq_from_fid(pst[j].fid); | ||
701 | powernow_table[j].frequency = freq; | ||
702 | } | ||
703 | powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; | ||
704 | powernow_table[data->numps].index = 0; | ||
705 | |||
706 | if (query_current_values_with_pending_wait(data)) { | ||
707 | kfree(powernow_table); | ||
708 | return -EIO; | ||
709 | } | ||
710 | |||
711 | dprintk("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); | ||
712 | data->powernow_table = powernow_table; | ||
713 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) | ||
714 | print_basics(data); | ||
715 | |||
716 | for (j = 0; j < data->numps; j++) | ||
717 | if ((pst[j].fid == data->currfid) && | ||
718 | (pst[j].vid == data->currvid)) | ||
719 | return 0; | ||
720 | |||
721 | dprintk("currfid/vid do not match PST, ignoring\n"); | ||
722 | return 0; | ||
723 | } | ||
724 | |||
725 | /* Find and validate the PSB/PST table in BIOS. */ | ||
726 | static int find_psb_table(struct powernow_k8_data *data) | ||
727 | { | ||
728 | struct psb_s *psb; | ||
729 | unsigned int i; | ||
730 | u32 mvs; | ||
731 | u8 maxvid; | ||
732 | u32 cpst = 0; | ||
733 | u32 thiscpuid; | ||
734 | |||
735 | for (i = 0xc0000; i < 0xffff0; i += 0x10) { | ||
736 | /* Scan BIOS looking for the signature. */ | ||
737 | /* It can not be at ffff0 - it is too big. */ | ||
738 | |||
739 | psb = phys_to_virt(i); | ||
740 | if (memcmp(psb, PSB_ID_STRING, PSB_ID_STRING_LEN) != 0) | ||
741 | continue; | ||
742 | |||
743 | dprintk("found PSB header at 0x%p\n", psb); | ||
744 | |||
745 | dprintk("table vers: 0x%x\n", psb->tableversion); | ||
746 | if (psb->tableversion != PSB_VERSION_1_4) { | ||
747 | printk(KERN_ERR FW_BUG PFX "PSB table is not v1.4\n"); | ||
748 | return -ENODEV; | ||
749 | } | ||
750 | |||
751 | dprintk("flags: 0x%x\n", psb->flags1); | ||
752 | if (psb->flags1) { | ||
753 | printk(KERN_ERR FW_BUG PFX "unknown flags\n"); | ||
754 | return -ENODEV; | ||
755 | } | ||
756 | |||
757 | data->vstable = psb->vstable; | ||
758 | dprintk("voltage stabilization time: %d(*20us)\n", | ||
759 | data->vstable); | ||
760 | |||
761 | dprintk("flags2: 0x%x\n", psb->flags2); | ||
762 | data->rvo = psb->flags2 & 3; | ||
763 | data->irt = ((psb->flags2) >> 2) & 3; | ||
764 | mvs = ((psb->flags2) >> 4) & 3; | ||
765 | data->vidmvs = 1 << mvs; | ||
766 | data->batps = ((psb->flags2) >> 6) & 3; | ||
767 | |||
768 | dprintk("ramp voltage offset: %d\n", data->rvo); | ||
769 | dprintk("isochronous relief time: %d\n", data->irt); | ||
770 | dprintk("maximum voltage step: %d - 0x%x\n", mvs, data->vidmvs); | ||
771 | |||
772 | dprintk("numpst: 0x%x\n", psb->num_tables); | ||
773 | cpst = psb->num_tables; | ||
774 | if ((psb->cpuid == 0x00000fc0) || | ||
775 | (psb->cpuid == 0x00000fe0)) { | ||
776 | thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | ||
777 | if ((thiscpuid == 0x00000fc0) || | ||
778 | (thiscpuid == 0x00000fe0)) | ||
779 | cpst = 1; | ||
780 | } | ||
781 | if (cpst != 1) { | ||
782 | printk(KERN_ERR FW_BUG PFX "numpst must be 1\n"); | ||
783 | return -ENODEV; | ||
784 | } | ||
785 | |||
786 | data->plllock = psb->plllocktime; | ||
787 | dprintk("plllocktime: 0x%x (units 1us)\n", psb->plllocktime); | ||
788 | dprintk("maxfid: 0x%x\n", psb->maxfid); | ||
789 | dprintk("maxvid: 0x%x\n", psb->maxvid); | ||
790 | maxvid = psb->maxvid; | ||
791 | |||
792 | data->numps = psb->numps; | ||
793 | dprintk("numpstates: 0x%x\n", data->numps); | ||
794 | return fill_powernow_table(data, | ||
795 | (struct pst_s *)(psb+1), maxvid); | ||
796 | } | ||
797 | /* | ||
798 | * If you see this message, complain to BIOS manufacturer. If | ||
799 | * he tells you "we do not support Linux" or some similar | ||
800 | * nonsense, remember that Windows 2000 uses the same legacy | ||
801 | * mechanism that the old Linux PSB driver uses. Tell them it | ||
802 | * is broken with Windows 2000. | ||
803 | * | ||
804 | * The reference to the AMD documentation is chapter 9 in the | ||
805 | * BIOS and Kernel Developer's Guide, which is available on | ||
806 | * www.amd.com | ||
807 | */ | ||
808 | printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n"); | ||
809 | printk(KERN_ERR PFX "Make sure that your BIOS is up to date" | ||
810 | " and Cool'N'Quiet support is enabled in BIOS setup\n"); | ||
811 | return -ENODEV; | ||
812 | } | ||
813 | |||
814 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, | ||
815 | unsigned int index) | ||
816 | { | ||
817 | u64 control; | ||
818 | |||
819 | if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE)) | ||
820 | return; | ||
821 | |||
822 | control = data->acpi_data.states[index].control; | ||
823 | data->irt = (control >> IRT_SHIFT) & IRT_MASK; | ||
824 | data->rvo = (control >> RVO_SHIFT) & RVO_MASK; | ||
825 | data->exttype = (control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK; | ||
826 | data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; | ||
827 | data->vidmvs = 1 << ((control >> MVS_SHIFT) & MVS_MASK); | ||
828 | data->vstable = (control >> VST_SHIFT) & VST_MASK; | ||
829 | } | ||
830 | |||
831 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | ||
832 | { | ||
833 | struct cpufreq_frequency_table *powernow_table; | ||
834 | int ret_val = -ENODEV; | ||
835 | u64 control, status; | ||
836 | |||
837 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { | ||
838 | dprintk("register performance failed: bad ACPI data\n"); | ||
839 | return -EIO; | ||
840 | } | ||
841 | |||
842 | /* verify the data contained in the ACPI structures */ | ||
843 | if (data->acpi_data.state_count <= 1) { | ||
844 | dprintk("No ACPI P-States\n"); | ||
845 | goto err_out; | ||
846 | } | ||
847 | |||
848 | control = data->acpi_data.control_register.space_id; | ||
849 | status = data->acpi_data.status_register.space_id; | ||
850 | |||
851 | if ((control != ACPI_ADR_SPACE_FIXED_HARDWARE) || | ||
852 | (status != ACPI_ADR_SPACE_FIXED_HARDWARE)) { | ||
853 | dprintk("Invalid control/status registers (%x - %x)\n", | ||
854 | control, status); | ||
855 | goto err_out; | ||
856 | } | ||
857 | |||
858 | /* fill in data->powernow_table */ | ||
859 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) | ||
860 | * (data->acpi_data.state_count + 1)), GFP_KERNEL); | ||
861 | if (!powernow_table) { | ||
862 | dprintk("powernow_table memory alloc failure\n"); | ||
863 | goto err_out; | ||
864 | } | ||
865 | |||
866 | /* fill in data */ | ||
867 | data->numps = data->acpi_data.state_count; | ||
868 | powernow_k8_acpi_pst_values(data, 0); | ||
869 | |||
870 | if (cpu_family == CPU_HW_PSTATE) | ||
871 | ret_val = fill_powernow_table_pstate(data, powernow_table); | ||
872 | else | ||
873 | ret_val = fill_powernow_table_fidvid(data, powernow_table); | ||
874 | if (ret_val) | ||
875 | goto err_out_mem; | ||
876 | |||
877 | powernow_table[data->acpi_data.state_count].frequency = | ||
878 | CPUFREQ_TABLE_END; | ||
879 | powernow_table[data->acpi_data.state_count].index = 0; | ||
880 | data->powernow_table = powernow_table; | ||
881 | |||
882 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) | ||
883 | print_basics(data); | ||
884 | |||
885 | /* notify BIOS that we exist */ | ||
886 | acpi_processor_notify_smm(THIS_MODULE); | ||
887 | |||
888 | if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { | ||
889 | printk(KERN_ERR PFX | ||
890 | "unable to alloc powernow_k8_data cpumask\n"); | ||
891 | ret_val = -ENOMEM; | ||
892 | goto err_out_mem; | ||
893 | } | ||
894 | |||
895 | return 0; | ||
896 | |||
897 | err_out_mem: | ||
898 | kfree(powernow_table); | ||
899 | |||
900 | err_out: | ||
901 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); | ||
902 | |||
903 | /* data->acpi_data.state_count informs us at ->exit() | ||
904 | * whether ACPI was used */ | ||
905 | data->acpi_data.state_count = 0; | ||
906 | |||
907 | return ret_val; | ||
908 | } | ||
909 | |||
910 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, | ||
911 | struct cpufreq_frequency_table *powernow_table) | ||
912 | { | ||
913 | int i; | ||
914 | u32 hi = 0, lo = 0; | ||
915 | rdmsr(MSR_PSTATE_CUR_LIMIT, lo, hi); | ||
916 | data->max_hw_pstate = (lo & HW_PSTATE_MAX_MASK) >> HW_PSTATE_MAX_SHIFT; | ||
917 | |||
918 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
919 | u32 index; | ||
920 | |||
921 | index = data->acpi_data.states[i].control & HW_PSTATE_MASK; | ||
922 | if (index > data->max_hw_pstate) { | ||
923 | printk(KERN_ERR PFX "invalid pstate %d - " | ||
924 | "bad value %d.\n", i, index); | ||
925 | printk(KERN_ERR PFX "Please report to BIOS " | ||
926 | "manufacturer\n"); | ||
927 | invalidate_entry(powernow_table, i); | ||
928 | continue; | ||
929 | } | ||
930 | rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); | ||
931 | if (!(hi & HW_PSTATE_VALID_MASK)) { | ||
932 | dprintk("invalid pstate %d, ignoring\n", index); | ||
933 | invalidate_entry(powernow_table, i); | ||
934 | continue; | ||
935 | } | ||
936 | |||
937 | powernow_table[i].index = index; | ||
938 | |||
939 | /* Frequency may be rounded for these */ | ||
940 | if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) | ||
941 | || boot_cpu_data.x86 == 0x11) { | ||
942 | powernow_table[i].frequency = | ||
943 | freq_from_fid_did(lo & 0x3f, (lo >> 6) & 7); | ||
944 | } else | ||
945 | powernow_table[i].frequency = | ||
946 | data->acpi_data.states[i].core_frequency * 1000; | ||
947 | } | ||
948 | return 0; | ||
949 | } | ||
950 | |||
951 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, | ||
952 | struct cpufreq_frequency_table *powernow_table) | ||
953 | { | ||
954 | int i; | ||
955 | |||
956 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
957 | u32 fid; | ||
958 | u32 vid; | ||
959 | u32 freq, index; | ||
960 | u64 status, control; | ||
961 | |||
962 | if (data->exttype) { | ||
963 | status = data->acpi_data.states[i].status; | ||
964 | fid = status & EXT_FID_MASK; | ||
965 | vid = (status >> VID_SHIFT) & EXT_VID_MASK; | ||
966 | } else { | ||
967 | control = data->acpi_data.states[i].control; | ||
968 | fid = control & FID_MASK; | ||
969 | vid = (control >> VID_SHIFT) & VID_MASK; | ||
970 | } | ||
971 | |||
972 | dprintk(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid); | ||
973 | |||
974 | index = fid | (vid<<8); | ||
975 | powernow_table[i].index = index; | ||
976 | |||
977 | freq = find_khz_freq_from_fid(fid); | ||
978 | powernow_table[i].frequency = freq; | ||
979 | |||
980 | /* verify frequency is OK */ | ||
981 | if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) { | ||
982 | dprintk("invalid freq %u kHz, ignoring\n", freq); | ||
983 | invalidate_entry(powernow_table, i); | ||
984 | continue; | ||
985 | } | ||
986 | |||
987 | /* verify voltage is OK - | ||
988 | * BIOSs are using "off" to indicate invalid */ | ||
989 | if (vid == VID_OFF) { | ||
990 | dprintk("invalid vid %u, ignoring\n", vid); | ||
991 | invalidate_entry(powernow_table, i); | ||
992 | continue; | ||
993 | } | ||
994 | |||
995 | if (freq != (data->acpi_data.states[i].core_frequency * 1000)) { | ||
996 | printk(KERN_INFO PFX "invalid freq entries " | ||
997 | "%u kHz vs. %u kHz\n", freq, | ||
998 | (unsigned int) | ||
999 | (data->acpi_data.states[i].core_frequency | ||
1000 | * 1000)); | ||
1001 | invalidate_entry(powernow_table, i); | ||
1002 | continue; | ||
1003 | } | ||
1004 | } | ||
1005 | return 0; | ||
1006 | } | ||
1007 | |||
1008 | static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) | ||
1009 | { | ||
1010 | if (data->acpi_data.state_count) | ||
1011 | acpi_processor_unregister_performance(&data->acpi_data, | ||
1012 | data->cpu); | ||
1013 | free_cpumask_var(data->acpi_data.shared_cpu_map); | ||
1014 | } | ||
1015 | |||
1016 | static int get_transition_latency(struct powernow_k8_data *data) | ||
1017 | { | ||
1018 | int max_latency = 0; | ||
1019 | int i; | ||
1020 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
1021 | int cur_latency = data->acpi_data.states[i].transition_latency | ||
1022 | + data->acpi_data.states[i].bus_master_latency; | ||
1023 | if (cur_latency > max_latency) | ||
1024 | max_latency = cur_latency; | ||
1025 | } | ||
1026 | if (max_latency == 0) { | ||
1027 | /* | ||
1028 | * Fam 11h and later may return 0 as transition latency. This | ||
1029 | * is intended and means "very fast". While cpufreq core and | ||
1030 | * governors currently can handle that gracefully, better set it | ||
1031 | * to 1 to avoid problems in the future. | ||
1032 | */ | ||
1033 | if (boot_cpu_data.x86 < 0x11) | ||
1034 | printk(KERN_ERR FW_WARN PFX "Invalid zero transition " | ||
1035 | "latency\n"); | ||
1036 | max_latency = 1; | ||
1037 | } | ||
1038 | /* value in usecs, needs to be in nanoseconds */ | ||
1039 | return 1000 * max_latency; | ||
1040 | } | ||
1041 | |||
1042 | /* Take a frequency, and issue the fid/vid transition command */ | ||
1043 | static int transition_frequency_fidvid(struct powernow_k8_data *data, | ||
1044 | unsigned int index) | ||
1045 | { | ||
1046 | u32 fid = 0; | ||
1047 | u32 vid = 0; | ||
1048 | int res, i; | ||
1049 | struct cpufreq_freqs freqs; | ||
1050 | |||
1051 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
1052 | |||
1053 | /* fid/vid correctness check for k8 */ | ||
1054 | /* fid are the lower 8 bits of the index we stored into | ||
1055 | * the cpufreq frequency table in find_psb_table, vid | ||
1056 | * are the upper 8 bits. | ||
1057 | */ | ||
1058 | fid = data->powernow_table[index].index & 0xFF; | ||
1059 | vid = (data->powernow_table[index].index & 0xFF00) >> 8; | ||
1060 | |||
1061 | dprintk("table matched fid 0x%x, giving vid 0x%x\n", fid, vid); | ||
1062 | |||
1063 | if (query_current_values_with_pending_wait(data)) | ||
1064 | return 1; | ||
1065 | |||
1066 | if ((data->currvid == vid) && (data->currfid == fid)) { | ||
1067 | dprintk("target matches current values (fid 0x%x, vid 0x%x)\n", | ||
1068 | fid, vid); | ||
1069 | return 0; | ||
1070 | } | ||
1071 | |||
1072 | dprintk("cpu %d, changing to fid 0x%x, vid 0x%x\n", | ||
1073 | smp_processor_id(), fid, vid); | ||
1074 | freqs.old = find_khz_freq_from_fid(data->currfid); | ||
1075 | freqs.new = find_khz_freq_from_fid(fid); | ||
1076 | |||
1077 | for_each_cpu(i, data->available_cores) { | ||
1078 | freqs.cpu = i; | ||
1079 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
1080 | } | ||
1081 | |||
1082 | res = transition_fid_vid(data, fid, vid); | ||
1083 | freqs.new = find_khz_freq_from_fid(data->currfid); | ||
1084 | |||
1085 | for_each_cpu(i, data->available_cores) { | ||
1086 | freqs.cpu = i; | ||
1087 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
1088 | } | ||
1089 | return res; | ||
1090 | } | ||
1091 | |||
1092 | /* Take a frequency, and issue the hardware pstate transition command */ | ||
1093 | static int transition_frequency_pstate(struct powernow_k8_data *data, | ||
1094 | unsigned int index) | ||
1095 | { | ||
1096 | u32 pstate = 0; | ||
1097 | int res, i; | ||
1098 | struct cpufreq_freqs freqs; | ||
1099 | |||
1100 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
1101 | |||
1102 | /* get MSR index for hardware pstate transition */ | ||
1103 | pstate = index & HW_PSTATE_MASK; | ||
1104 | if (pstate > data->max_hw_pstate) | ||
1105 | return 0; | ||
1106 | freqs.old = find_khz_freq_from_pstate(data->powernow_table, | ||
1107 | data->currpstate); | ||
1108 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
1109 | |||
1110 | for_each_cpu(i, data->available_cores) { | ||
1111 | freqs.cpu = i; | ||
1112 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
1113 | } | ||
1114 | |||
1115 | res = transition_pstate(data, pstate); | ||
1116 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
1117 | |||
1118 | for_each_cpu(i, data->available_cores) { | ||
1119 | freqs.cpu = i; | ||
1120 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
1121 | } | ||
1122 | return res; | ||
1123 | } | ||
1124 | |||
1125 | /* Driver entry point to switch to the target frequency */ | ||
1126 | static int powernowk8_target(struct cpufreq_policy *pol, | ||
1127 | unsigned targfreq, unsigned relation) | ||
1128 | { | ||
1129 | cpumask_var_t oldmask; | ||
1130 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
1131 | u32 checkfid; | ||
1132 | u32 checkvid; | ||
1133 | unsigned int newstate; | ||
1134 | int ret = -EIO; | ||
1135 | |||
1136 | if (!data) | ||
1137 | return -EINVAL; | ||
1138 | |||
1139 | checkfid = data->currfid; | ||
1140 | checkvid = data->currvid; | ||
1141 | |||
1142 | /* only run on specific CPU from here on. */ | ||
1143 | /* This is poor form: use a workqueue or smp_call_function_single */ | ||
1144 | if (!alloc_cpumask_var(&oldmask, GFP_KERNEL)) | ||
1145 | return -ENOMEM; | ||
1146 | |||
1147 | cpumask_copy(oldmask, tsk_cpus_allowed(current)); | ||
1148 | set_cpus_allowed_ptr(current, cpumask_of(pol->cpu)); | ||
1149 | |||
1150 | if (smp_processor_id() != pol->cpu) { | ||
1151 | printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); | ||
1152 | goto err_out; | ||
1153 | } | ||
1154 | |||
1155 | if (pending_bit_stuck()) { | ||
1156 | printk(KERN_ERR PFX "failing targ, change pending bit set\n"); | ||
1157 | goto err_out; | ||
1158 | } | ||
1159 | |||
1160 | dprintk("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", | ||
1161 | pol->cpu, targfreq, pol->min, pol->max, relation); | ||
1162 | |||
1163 | if (query_current_values_with_pending_wait(data)) | ||
1164 | goto err_out; | ||
1165 | |||
1166 | if (cpu_family != CPU_HW_PSTATE) { | ||
1167 | dprintk("targ: curr fid 0x%x, vid 0x%x\n", | ||
1168 | data->currfid, data->currvid); | ||
1169 | |||
1170 | if ((checkvid != data->currvid) || | ||
1171 | (checkfid != data->currfid)) { | ||
1172 | printk(KERN_INFO PFX | ||
1173 | "error - out of sync, fix 0x%x 0x%x, " | ||
1174 | "vid 0x%x 0x%x\n", | ||
1175 | checkfid, data->currfid, | ||
1176 | checkvid, data->currvid); | ||
1177 | } | ||
1178 | } | ||
1179 | |||
1180 | if (cpufreq_frequency_table_target(pol, data->powernow_table, | ||
1181 | targfreq, relation, &newstate)) | ||
1182 | goto err_out; | ||
1183 | |||
1184 | mutex_lock(&fidvid_mutex); | ||
1185 | |||
1186 | powernow_k8_acpi_pst_values(data, newstate); | ||
1187 | |||
1188 | if (cpu_family == CPU_HW_PSTATE) | ||
1189 | ret = transition_frequency_pstate(data, newstate); | ||
1190 | else | ||
1191 | ret = transition_frequency_fidvid(data, newstate); | ||
1192 | if (ret) { | ||
1193 | printk(KERN_ERR PFX "transition frequency failed\n"); | ||
1194 | ret = 1; | ||
1195 | mutex_unlock(&fidvid_mutex); | ||
1196 | goto err_out; | ||
1197 | } | ||
1198 | mutex_unlock(&fidvid_mutex); | ||
1199 | |||
1200 | if (cpu_family == CPU_HW_PSTATE) | ||
1201 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
1202 | newstate); | ||
1203 | else | ||
1204 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1205 | ret = 0; | ||
1206 | |||
1207 | err_out: | ||
1208 | set_cpus_allowed_ptr(current, oldmask); | ||
1209 | free_cpumask_var(oldmask); | ||
1210 | return ret; | ||
1211 | } | ||
1212 | |||
1213 | /* Driver entry point to verify the policy and range of frequencies */ | ||
1214 | static int powernowk8_verify(struct cpufreq_policy *pol) | ||
1215 | { | ||
1216 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
1217 | |||
1218 | if (!data) | ||
1219 | return -EINVAL; | ||
1220 | |||
1221 | return cpufreq_frequency_table_verify(pol, data->powernow_table); | ||
1222 | } | ||
1223 | |||
1224 | struct init_on_cpu { | ||
1225 | struct powernow_k8_data *data; | ||
1226 | int rc; | ||
1227 | }; | ||
1228 | |||
1229 | static void __cpuinit powernowk8_cpu_init_on_cpu(void *_init_on_cpu) | ||
1230 | { | ||
1231 | struct init_on_cpu *init_on_cpu = _init_on_cpu; | ||
1232 | |||
1233 | if (pending_bit_stuck()) { | ||
1234 | printk(KERN_ERR PFX "failing init, change pending bit set\n"); | ||
1235 | init_on_cpu->rc = -ENODEV; | ||
1236 | return; | ||
1237 | } | ||
1238 | |||
1239 | if (query_current_values_with_pending_wait(init_on_cpu->data)) { | ||
1240 | init_on_cpu->rc = -ENODEV; | ||
1241 | return; | ||
1242 | } | ||
1243 | |||
1244 | if (cpu_family == CPU_OPTERON) | ||
1245 | fidvid_msr_init(); | ||
1246 | |||
1247 | init_on_cpu->rc = 0; | ||
1248 | } | ||
1249 | |||
1250 | /* per CPU init entry point to the driver */ | ||
1251 | static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | ||
1252 | { | ||
1253 | static const char ACPI_PSS_BIOS_BUG_MSG[] = | ||
1254 | KERN_ERR FW_BUG PFX "No compatible ACPI _PSS objects found.\n" | ||
1255 | FW_BUG PFX "Try again with latest BIOS.\n"; | ||
1256 | struct powernow_k8_data *data; | ||
1257 | struct init_on_cpu init_on_cpu; | ||
1258 | int rc; | ||
1259 | struct cpuinfo_x86 *c = &cpu_data(pol->cpu); | ||
1260 | |||
1261 | if (!cpu_online(pol->cpu)) | ||
1262 | return -ENODEV; | ||
1263 | |||
1264 | smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1); | ||
1265 | if (rc) | ||
1266 | return -ENODEV; | ||
1267 | |||
1268 | data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); | ||
1269 | if (!data) { | ||
1270 | printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); | ||
1271 | return -ENOMEM; | ||
1272 | } | ||
1273 | |||
1274 | data->cpu = pol->cpu; | ||
1275 | data->currpstate = HW_PSTATE_INVALID; | ||
1276 | |||
1277 | if (powernow_k8_cpu_init_acpi(data)) { | ||
1278 | /* | ||
1279 | * Use the PSB BIOS structure. This is only availabe on | ||
1280 | * an UP version, and is deprecated by AMD. | ||
1281 | */ | ||
1282 | if (num_online_cpus() != 1) { | ||
1283 | printk_once(ACPI_PSS_BIOS_BUG_MSG); | ||
1284 | goto err_out; | ||
1285 | } | ||
1286 | if (pol->cpu != 0) { | ||
1287 | printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " | ||
1288 | "CPU other than CPU0. Complain to your BIOS " | ||
1289 | "vendor.\n"); | ||
1290 | goto err_out; | ||
1291 | } | ||
1292 | rc = find_psb_table(data); | ||
1293 | if (rc) | ||
1294 | goto err_out; | ||
1295 | |||
1296 | /* Take a crude guess here. | ||
1297 | * That guess was in microseconds, so multiply with 1000 */ | ||
1298 | pol->cpuinfo.transition_latency = ( | ||
1299 | ((data->rvo + 8) * data->vstable * VST_UNITS_20US) + | ||
1300 | ((1 << data->irt) * 30)) * 1000; | ||
1301 | } else /* ACPI _PSS objects available */ | ||
1302 | pol->cpuinfo.transition_latency = get_transition_latency(data); | ||
1303 | |||
1304 | /* only run on specific CPU from here on */ | ||
1305 | init_on_cpu.data = data; | ||
1306 | smp_call_function_single(data->cpu, powernowk8_cpu_init_on_cpu, | ||
1307 | &init_on_cpu, 1); | ||
1308 | rc = init_on_cpu.rc; | ||
1309 | if (rc != 0) | ||
1310 | goto err_out_exit_acpi; | ||
1311 | |||
1312 | if (cpu_family == CPU_HW_PSTATE) | ||
1313 | cpumask_copy(pol->cpus, cpumask_of(pol->cpu)); | ||
1314 | else | ||
1315 | cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu)); | ||
1316 | data->available_cores = pol->cpus; | ||
1317 | |||
1318 | if (cpu_family == CPU_HW_PSTATE) | ||
1319 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
1320 | data->currpstate); | ||
1321 | else | ||
1322 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1323 | dprintk("policy current frequency %d kHz\n", pol->cur); | ||
1324 | |||
1325 | /* min/max the cpu is capable of */ | ||
1326 | if (cpufreq_frequency_table_cpuinfo(pol, data->powernow_table)) { | ||
1327 | printk(KERN_ERR FW_BUG PFX "invalid powernow_table\n"); | ||
1328 | powernow_k8_cpu_exit_acpi(data); | ||
1329 | kfree(data->powernow_table); | ||
1330 | kfree(data); | ||
1331 | return -EINVAL; | ||
1332 | } | ||
1333 | |||
1334 | /* Check for APERF/MPERF support in hardware */ | ||
1335 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
1336 | cpufreq_amd64_driver.getavg = cpufreq_get_measured_perf; | ||
1337 | |||
1338 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); | ||
1339 | |||
1340 | if (cpu_family == CPU_HW_PSTATE) | ||
1341 | dprintk("cpu_init done, current pstate 0x%x\n", | ||
1342 | data->currpstate); | ||
1343 | else | ||
1344 | dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n", | ||
1345 | data->currfid, data->currvid); | ||
1346 | |||
1347 | per_cpu(powernow_data, pol->cpu) = data; | ||
1348 | |||
1349 | return 0; | ||
1350 | |||
1351 | err_out_exit_acpi: | ||
1352 | powernow_k8_cpu_exit_acpi(data); | ||
1353 | |||
1354 | err_out: | ||
1355 | kfree(data); | ||
1356 | return -ENODEV; | ||
1357 | } | ||
1358 | |||
1359 | static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol) | ||
1360 | { | ||
1361 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
1362 | |||
1363 | if (!data) | ||
1364 | return -EINVAL; | ||
1365 | |||
1366 | powernow_k8_cpu_exit_acpi(data); | ||
1367 | |||
1368 | cpufreq_frequency_table_put_attr(pol->cpu); | ||
1369 | |||
1370 | kfree(data->powernow_table); | ||
1371 | kfree(data); | ||
1372 | per_cpu(powernow_data, pol->cpu) = NULL; | ||
1373 | |||
1374 | return 0; | ||
1375 | } | ||
1376 | |||
1377 | static void query_values_on_cpu(void *_err) | ||
1378 | { | ||
1379 | int *err = _err; | ||
1380 | struct powernow_k8_data *data = __get_cpu_var(powernow_data); | ||
1381 | |||
1382 | *err = query_current_values_with_pending_wait(data); | ||
1383 | } | ||
1384 | |||
1385 | static unsigned int powernowk8_get(unsigned int cpu) | ||
1386 | { | ||
1387 | struct powernow_k8_data *data = per_cpu(powernow_data, cpu); | ||
1388 | unsigned int khz = 0; | ||
1389 | int err; | ||
1390 | |||
1391 | if (!data) | ||
1392 | return 0; | ||
1393 | |||
1394 | smp_call_function_single(cpu, query_values_on_cpu, &err, true); | ||
1395 | if (err) | ||
1396 | goto out; | ||
1397 | |||
1398 | if (cpu_family == CPU_HW_PSTATE) | ||
1399 | khz = find_khz_freq_from_pstate(data->powernow_table, | ||
1400 | data->currpstate); | ||
1401 | else | ||
1402 | khz = find_khz_freq_from_fid(data->currfid); | ||
1403 | |||
1404 | |||
1405 | out: | ||
1406 | return khz; | ||
1407 | } | ||
1408 | |||
1409 | static void _cpb_toggle_msrs(bool t) | ||
1410 | { | ||
1411 | int cpu; | ||
1412 | |||
1413 | get_online_cpus(); | ||
1414 | |||
1415 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1416 | |||
1417 | for_each_cpu(cpu, cpu_online_mask) { | ||
1418 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1419 | if (t) | ||
1420 | reg->l &= ~BIT(25); | ||
1421 | else | ||
1422 | reg->l |= BIT(25); | ||
1423 | } | ||
1424 | wrmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1425 | |||
1426 | put_online_cpus(); | ||
1427 | } | ||
1428 | |||
1429 | /* | ||
1430 | * Switch on/off core performance boosting. | ||
1431 | * | ||
1432 | * 0=disable | ||
1433 | * 1=enable. | ||
1434 | */ | ||
1435 | static void cpb_toggle(bool t) | ||
1436 | { | ||
1437 | if (!cpb_capable) | ||
1438 | return; | ||
1439 | |||
1440 | if (t && !cpb_enabled) { | ||
1441 | cpb_enabled = true; | ||
1442 | _cpb_toggle_msrs(t); | ||
1443 | printk(KERN_INFO PFX "Core Boosting enabled.\n"); | ||
1444 | } else if (!t && cpb_enabled) { | ||
1445 | cpb_enabled = false; | ||
1446 | _cpb_toggle_msrs(t); | ||
1447 | printk(KERN_INFO PFX "Core Boosting disabled.\n"); | ||
1448 | } | ||
1449 | } | ||
1450 | |||
1451 | static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, | ||
1452 | size_t count) | ||
1453 | { | ||
1454 | int ret = -EINVAL; | ||
1455 | unsigned long val = 0; | ||
1456 | |||
1457 | ret = strict_strtoul(buf, 10, &val); | ||
1458 | if (!ret && (val == 0 || val == 1) && cpb_capable) | ||
1459 | cpb_toggle(val); | ||
1460 | else | ||
1461 | return -EINVAL; | ||
1462 | |||
1463 | return count; | ||
1464 | } | ||
1465 | |||
1466 | static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf) | ||
1467 | { | ||
1468 | return sprintf(buf, "%u\n", cpb_enabled); | ||
1469 | } | ||
1470 | |||
1471 | #define define_one_rw(_name) \ | ||
1472 | static struct freq_attr _name = \ | ||
1473 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
1474 | |||
1475 | define_one_rw(cpb); | ||
1476 | |||
1477 | static struct freq_attr *powernow_k8_attr[] = { | ||
1478 | &cpufreq_freq_attr_scaling_available_freqs, | ||
1479 | &cpb, | ||
1480 | NULL, | ||
1481 | }; | ||
1482 | |||
1483 | static struct cpufreq_driver cpufreq_amd64_driver = { | ||
1484 | .verify = powernowk8_verify, | ||
1485 | .target = powernowk8_target, | ||
1486 | .bios_limit = acpi_processor_get_bios_limit, | ||
1487 | .init = powernowk8_cpu_init, | ||
1488 | .exit = __devexit_p(powernowk8_cpu_exit), | ||
1489 | .get = powernowk8_get, | ||
1490 | .name = "powernow-k8", | ||
1491 | .owner = THIS_MODULE, | ||
1492 | .attr = powernow_k8_attr, | ||
1493 | }; | ||
1494 | |||
1495 | /* | ||
1496 | * Clear the boost-disable flag on the CPU_DOWN path so that this cpu | ||
1497 | * cannot block the remaining ones from boosting. On the CPU_UP path we | ||
1498 | * simply keep the boost-disable flag in sync with the current global | ||
1499 | * state. | ||
1500 | */ | ||
1501 | static int cpb_notify(struct notifier_block *nb, unsigned long action, | ||
1502 | void *hcpu) | ||
1503 | { | ||
1504 | unsigned cpu = (long)hcpu; | ||
1505 | u32 lo, hi; | ||
1506 | |||
1507 | switch (action) { | ||
1508 | case CPU_UP_PREPARE: | ||
1509 | case CPU_UP_PREPARE_FROZEN: | ||
1510 | |||
1511 | if (!cpb_enabled) { | ||
1512 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1513 | lo |= BIT(25); | ||
1514 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1515 | } | ||
1516 | break; | ||
1517 | |||
1518 | case CPU_DOWN_PREPARE: | ||
1519 | case CPU_DOWN_PREPARE_FROZEN: | ||
1520 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1521 | lo &= ~BIT(25); | ||
1522 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1523 | break; | ||
1524 | |||
1525 | default: | ||
1526 | break; | ||
1527 | } | ||
1528 | |||
1529 | return NOTIFY_OK; | ||
1530 | } | ||
1531 | |||
1532 | static struct notifier_block cpb_nb = { | ||
1533 | .notifier_call = cpb_notify, | ||
1534 | }; | ||
1535 | |||
1536 | /* driver entry point for init */ | ||
1537 | static int __cpuinit powernowk8_init(void) | ||
1538 | { | ||
1539 | unsigned int i, supported_cpus = 0, cpu; | ||
1540 | |||
1541 | for_each_online_cpu(i) { | ||
1542 | int rc; | ||
1543 | smp_call_function_single(i, check_supported_cpu, &rc, 1); | ||
1544 | if (rc == 0) | ||
1545 | supported_cpus++; | ||
1546 | } | ||
1547 | |||
1548 | if (supported_cpus != num_online_cpus()) | ||
1549 | return -ENODEV; | ||
1550 | |||
1551 | printk(KERN_INFO PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", | ||
1552 | num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus); | ||
1553 | |||
1554 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1555 | |||
1556 | cpb_capable = true; | ||
1557 | |||
1558 | register_cpu_notifier(&cpb_nb); | ||
1559 | |||
1560 | msrs = msrs_alloc(); | ||
1561 | if (!msrs) { | ||
1562 | printk(KERN_ERR "%s: Error allocating msrs!\n", __func__); | ||
1563 | return -ENOMEM; | ||
1564 | } | ||
1565 | |||
1566 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1567 | |||
1568 | for_each_cpu(cpu, cpu_online_mask) { | ||
1569 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1570 | cpb_enabled |= !(!!(reg->l & BIT(25))); | ||
1571 | } | ||
1572 | |||
1573 | printk(KERN_INFO PFX "Core Performance Boosting: %s.\n", | ||
1574 | (cpb_enabled ? "on" : "off")); | ||
1575 | } | ||
1576 | |||
1577 | return cpufreq_register_driver(&cpufreq_amd64_driver); | ||
1578 | } | ||
1579 | |||
1580 | /* driver entry point for term */ | ||
1581 | static void __exit powernowk8_exit(void) | ||
1582 | { | ||
1583 | dprintk("exit\n"); | ||
1584 | |||
1585 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1586 | msrs_free(msrs); | ||
1587 | msrs = NULL; | ||
1588 | |||
1589 | unregister_cpu_notifier(&cpb_nb); | ||
1590 | } | ||
1591 | |||
1592 | cpufreq_unregister_driver(&cpufreq_amd64_driver); | ||
1593 | } | ||
1594 | |||
1595 | MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and " | ||
1596 | "Mark Langsdorf <mark.langsdorf@amd.com>"); | ||
1597 | MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver."); | ||
1598 | MODULE_LICENSE("GPL"); | ||
1599 | |||
1600 | late_initcall(powernowk8_init); | ||
1601 | module_exit(powernowk8_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h deleted file mode 100644 index df3529b1c02d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h +++ /dev/null | |||
@@ -1,224 +0,0 @@ | |||
1 | /* | ||
2 | * (c) 2003-2006 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | */ | ||
7 | |||
8 | enum pstate { | ||
9 | HW_PSTATE_INVALID = 0xff, | ||
10 | HW_PSTATE_0 = 0, | ||
11 | HW_PSTATE_1 = 1, | ||
12 | HW_PSTATE_2 = 2, | ||
13 | HW_PSTATE_3 = 3, | ||
14 | HW_PSTATE_4 = 4, | ||
15 | HW_PSTATE_5 = 5, | ||
16 | HW_PSTATE_6 = 6, | ||
17 | HW_PSTATE_7 = 7, | ||
18 | }; | ||
19 | |||
20 | struct powernow_k8_data { | ||
21 | unsigned int cpu; | ||
22 | |||
23 | u32 numps; /* number of p-states */ | ||
24 | u32 batps; /* number of p-states supported on battery */ | ||
25 | u32 max_hw_pstate; /* maximum legal hardware pstate */ | ||
26 | |||
27 | /* these values are constant when the PSB is used to determine | ||
28 | * vid/fid pairings, but are modified during the ->target() call | ||
29 | * when ACPI is used */ | ||
30 | u32 rvo; /* ramp voltage offset */ | ||
31 | u32 irt; /* isochronous relief time */ | ||
32 | u32 vidmvs; /* usable value calculated from mvs */ | ||
33 | u32 vstable; /* voltage stabilization time, units 20 us */ | ||
34 | u32 plllock; /* pll lock time, units 1 us */ | ||
35 | u32 exttype; /* extended interface = 1 */ | ||
36 | |||
37 | /* keep track of the current fid / vid or pstate */ | ||
38 | u32 currvid; | ||
39 | u32 currfid; | ||
40 | enum pstate currpstate; | ||
41 | |||
42 | /* the powernow_table includes all frequency and vid/fid pairings: | ||
43 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. | ||
44 | * frequency is in kHz */ | ||
45 | struct cpufreq_frequency_table *powernow_table; | ||
46 | |||
47 | /* the acpi table needs to be kept. it's only available if ACPI was | ||
48 | * used to determine valid frequency/vid/fid states */ | ||
49 | struct acpi_processor_performance acpi_data; | ||
50 | |||
51 | /* we need to keep track of associated cores, but let cpufreq | ||
52 | * handle hotplug events - so just point at cpufreq pol->cpus | ||
53 | * structure */ | ||
54 | struct cpumask *available_cores; | ||
55 | }; | ||
56 | |||
57 | /* processor's cpuid instruction support */ | ||
58 | #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */ | ||
59 | #define CPUID_XFAM 0x0ff00000 /* extended family */ | ||
60 | #define CPUID_XFAM_K8 0 | ||
61 | #define CPUID_XMOD 0x000f0000 /* extended model */ | ||
62 | #define CPUID_XMOD_REV_MASK 0x000c0000 | ||
63 | #define CPUID_XFAM_10H 0x00100000 /* family 0x10 */ | ||
64 | #define CPUID_USE_XFAM_XMOD 0x00000f00 | ||
65 | #define CPUID_GET_MAX_CAPABILITIES 0x80000000 | ||
66 | #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 | ||
67 | #define P_STATE_TRANSITION_CAPABLE 6 | ||
68 | |||
69 | /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */ | ||
70 | /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */ | ||
71 | /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */ | ||
72 | /* the register number is placed in ecx, and the data is returned in edx:eax. */ | ||
73 | |||
74 | #define MSR_FIDVID_CTL 0xc0010041 | ||
75 | #define MSR_FIDVID_STATUS 0xc0010042 | ||
76 | |||
77 | /* Field definitions within the FID VID Low Control MSR : */ | ||
78 | #define MSR_C_LO_INIT_FID_VID 0x00010000 | ||
79 | #define MSR_C_LO_NEW_VID 0x00003f00 | ||
80 | #define MSR_C_LO_NEW_FID 0x0000003f | ||
81 | #define MSR_C_LO_VID_SHIFT 8 | ||
82 | |||
83 | /* Field definitions within the FID VID High Control MSR : */ | ||
84 | #define MSR_C_HI_STP_GNT_TO 0x000fffff | ||
85 | |||
86 | /* Field definitions within the FID VID Low Status MSR : */ | ||
87 | #define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */ | ||
88 | #define MSR_S_LO_MAX_RAMP_VID 0x3f000000 | ||
89 | #define MSR_S_LO_MAX_FID 0x003f0000 | ||
90 | #define MSR_S_LO_START_FID 0x00003f00 | ||
91 | #define MSR_S_LO_CURRENT_FID 0x0000003f | ||
92 | |||
93 | /* Field definitions within the FID VID High Status MSR : */ | ||
94 | #define MSR_S_HI_MIN_WORKING_VID 0x3f000000 | ||
95 | #define MSR_S_HI_MAX_WORKING_VID 0x003f0000 | ||
96 | #define MSR_S_HI_START_VID 0x00003f00 | ||
97 | #define MSR_S_HI_CURRENT_VID 0x0000003f | ||
98 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 | ||
99 | |||
100 | |||
101 | /* Hardware Pstate _PSS and MSR definitions */ | ||
102 | #define USE_HW_PSTATE 0x00000080 | ||
103 | #define HW_PSTATE_MASK 0x00000007 | ||
104 | #define HW_PSTATE_VALID_MASK 0x80000000 | ||
105 | #define HW_PSTATE_MAX_MASK 0x000000f0 | ||
106 | #define HW_PSTATE_MAX_SHIFT 4 | ||
107 | #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */ | ||
108 | #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */ | ||
109 | #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */ | ||
110 | #define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */ | ||
111 | |||
112 | /* define the two driver architectures */ | ||
113 | #define CPU_OPTERON 0 | ||
114 | #define CPU_HW_PSTATE 1 | ||
115 | |||
116 | |||
117 | /* | ||
118 | * There are restrictions frequencies have to follow: | ||
119 | * - only 1 entry in the low fid table ( <=1.4GHz ) | ||
120 | * - lowest entry in the high fid table must be >= 2 * the entry in the | ||
121 | * low fid table | ||
122 | * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry | ||
123 | * in the low fid table | ||
124 | * - the parts can only step at <= 200 MHz intervals, odd fid values are | ||
125 | * supported in revision G and later revisions. | ||
126 | * - lowest frequency must be >= interprocessor hypertransport link speed | ||
127 | * (only applies to MP systems obviously) | ||
128 | */ | ||
129 | |||
130 | /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */ | ||
131 | #define LO_FID_TABLE_TOP 7 /* fid values marking the boundary */ | ||
132 | #define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */ | ||
133 | |||
134 | #define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */ | ||
135 | #define HI_VCOFREQ_TABLE_BOTTOM 1600 | ||
136 | |||
137 | #define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */ | ||
138 | |||
139 | #define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */ | ||
140 | #define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */ | ||
141 | |||
142 | #define MIN_FREQ 800 /* Min and max freqs, per spec */ | ||
143 | #define MAX_FREQ 5000 | ||
144 | |||
145 | #define INVALID_FID_MASK 0xffffffc0 /* not a valid fid if these bits are set */ | ||
146 | #define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */ | ||
147 | |||
148 | #define VID_OFF 0x3f | ||
149 | |||
150 | #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */ | ||
151 | |||
152 | #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */ | ||
153 | |||
154 | #define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */ | ||
155 | #define VST_UNITS_20US 20 /* Voltage Stabilization Time is in units of 20us */ | ||
156 | |||
157 | /* | ||
158 | * Most values of interest are encoded in a single field of the _PSS | ||
159 | * entries: the "control" value. | ||
160 | */ | ||
161 | |||
162 | #define IRT_SHIFT 30 | ||
163 | #define RVO_SHIFT 28 | ||
164 | #define EXT_TYPE_SHIFT 27 | ||
165 | #define PLL_L_SHIFT 20 | ||
166 | #define MVS_SHIFT 18 | ||
167 | #define VST_SHIFT 11 | ||
168 | #define VID_SHIFT 6 | ||
169 | #define IRT_MASK 3 | ||
170 | #define RVO_MASK 3 | ||
171 | #define EXT_TYPE_MASK 1 | ||
172 | #define PLL_L_MASK 0x7f | ||
173 | #define MVS_MASK 3 | ||
174 | #define VST_MASK 0x7f | ||
175 | #define VID_MASK 0x1f | ||
176 | #define FID_MASK 0x1f | ||
177 | #define EXT_VID_MASK 0x3f | ||
178 | #define EXT_FID_MASK 0x3f | ||
179 | |||
180 | |||
181 | /* | ||
182 | * Version 1.4 of the PSB table. This table is constructed by BIOS and is | ||
183 | * to tell the OS's power management driver which VIDs and FIDs are | ||
184 | * supported by this particular processor. | ||
185 | * If the data in the PSB / PST is wrong, then this driver will program the | ||
186 | * wrong values into hardware, which is very likely to lead to a crash. | ||
187 | */ | ||
188 | |||
189 | #define PSB_ID_STRING "AMDK7PNOW!" | ||
190 | #define PSB_ID_STRING_LEN 10 | ||
191 | |||
192 | #define PSB_VERSION_1_4 0x14 | ||
193 | |||
194 | struct psb_s { | ||
195 | u8 signature[10]; | ||
196 | u8 tableversion; | ||
197 | u8 flags1; | ||
198 | u16 vstable; | ||
199 | u8 flags2; | ||
200 | u8 num_tables; | ||
201 | u32 cpuid; | ||
202 | u8 plllocktime; | ||
203 | u8 maxfid; | ||
204 | u8 maxvid; | ||
205 | u8 numps; | ||
206 | }; | ||
207 | |||
208 | /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */ | ||
209 | struct pst_s { | ||
210 | u8 fid; | ||
211 | u8 vid; | ||
212 | }; | ||
213 | |||
214 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k8", msg) | ||
215 | |||
216 | static int core_voltage_pre_transition(struct powernow_k8_data *data, | ||
217 | u32 reqvid, u32 regfid); | ||
218 | static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid); | ||
219 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid); | ||
220 | |||
221 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); | ||
222 | |||
223 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
224 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/sc520_freq.c b/arch/x86/kernel/cpu/cpufreq/sc520_freq.c deleted file mode 100644 index 435a996a613a..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/sc520_freq.c +++ /dev/null | |||
@@ -1,194 +0,0 @@ | |||
1 | /* | ||
2 | * sc520_freq.c: cpufreq driver for the AMD Elan sc520 | ||
3 | * | ||
4 | * Copyright (C) 2005 Sean Young <sean@mess.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * Based on elanfreq.c | ||
12 | * | ||
13 | * 2005-03-30: - initial revision | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/init.h> | ||
19 | |||
20 | #include <linux/delay.h> | ||
21 | #include <linux/cpufreq.h> | ||
22 | #include <linux/timex.h> | ||
23 | #include <linux/io.h> | ||
24 | |||
25 | #include <asm/msr.h> | ||
26 | |||
27 | #define MMCR_BASE 0xfffef000 /* The default base address */ | ||
28 | #define OFFS_CPUCTL 0x2 /* CPU Control Register */ | ||
29 | |||
30 | static __u8 __iomem *cpuctl; | ||
31 | |||
32 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
33 | "sc520_freq", msg) | ||
34 | #define PFX "sc520_freq: " | ||
35 | |||
36 | static struct cpufreq_frequency_table sc520_freq_table[] = { | ||
37 | {0x01, 100000}, | ||
38 | {0x02, 133000}, | ||
39 | {0, CPUFREQ_TABLE_END}, | ||
40 | }; | ||
41 | |||
42 | static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu) | ||
43 | { | ||
44 | u8 clockspeed_reg = *cpuctl; | ||
45 | |||
46 | switch (clockspeed_reg & 0x03) { | ||
47 | default: | ||
48 | printk(KERN_ERR PFX "error: cpuctl register has unexpected " | ||
49 | "value %02x\n", clockspeed_reg); | ||
50 | case 0x01: | ||
51 | return 100000; | ||
52 | case 0x02: | ||
53 | return 133000; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | static void sc520_freq_set_cpu_state(unsigned int state) | ||
58 | { | ||
59 | |||
60 | struct cpufreq_freqs freqs; | ||
61 | u8 clockspeed_reg; | ||
62 | |||
63 | freqs.old = sc520_freq_get_cpu_frequency(0); | ||
64 | freqs.new = sc520_freq_table[state].frequency; | ||
65 | freqs.cpu = 0; /* AMD Elan is UP */ | ||
66 | |||
67 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
68 | |||
69 | dprintk("attempting to set frequency to %i kHz\n", | ||
70 | sc520_freq_table[state].frequency); | ||
71 | |||
72 | local_irq_disable(); | ||
73 | |||
74 | clockspeed_reg = *cpuctl & ~0x03; | ||
75 | *cpuctl = clockspeed_reg | sc520_freq_table[state].index; | ||
76 | |||
77 | local_irq_enable(); | ||
78 | |||
79 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
80 | }; | ||
81 | |||
82 | static int sc520_freq_verify(struct cpufreq_policy *policy) | ||
83 | { | ||
84 | return cpufreq_frequency_table_verify(policy, &sc520_freq_table[0]); | ||
85 | } | ||
86 | |||
87 | static int sc520_freq_target(struct cpufreq_policy *policy, | ||
88 | unsigned int target_freq, | ||
89 | unsigned int relation) | ||
90 | { | ||
91 | unsigned int newstate = 0; | ||
92 | |||
93 | if (cpufreq_frequency_table_target(policy, sc520_freq_table, | ||
94 | target_freq, relation, &newstate)) | ||
95 | return -EINVAL; | ||
96 | |||
97 | sc520_freq_set_cpu_state(newstate); | ||
98 | |||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | |||
103 | /* | ||
104 | * Module init and exit code | ||
105 | */ | ||
106 | |||
107 | static int sc520_freq_cpu_init(struct cpufreq_policy *policy) | ||
108 | { | ||
109 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
110 | int result; | ||
111 | |||
112 | /* capability check */ | ||
113 | if (c->x86_vendor != X86_VENDOR_AMD || | ||
114 | c->x86 != 4 || c->x86_model != 9) | ||
115 | return -ENODEV; | ||
116 | |||
117 | /* cpuinfo and default policy values */ | ||
118 | policy->cpuinfo.transition_latency = 1000000; /* 1ms */ | ||
119 | policy->cur = sc520_freq_get_cpu_frequency(0); | ||
120 | |||
121 | result = cpufreq_frequency_table_cpuinfo(policy, sc520_freq_table); | ||
122 | if (result) | ||
123 | return result; | ||
124 | |||
125 | cpufreq_frequency_table_get_attr(sc520_freq_table, policy->cpu); | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | |||
131 | static int sc520_freq_cpu_exit(struct cpufreq_policy *policy) | ||
132 | { | ||
133 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | |||
138 | static struct freq_attr *sc520_freq_attr[] = { | ||
139 | &cpufreq_freq_attr_scaling_available_freqs, | ||
140 | NULL, | ||
141 | }; | ||
142 | |||
143 | |||
144 | static struct cpufreq_driver sc520_freq_driver = { | ||
145 | .get = sc520_freq_get_cpu_frequency, | ||
146 | .verify = sc520_freq_verify, | ||
147 | .target = sc520_freq_target, | ||
148 | .init = sc520_freq_cpu_init, | ||
149 | .exit = sc520_freq_cpu_exit, | ||
150 | .name = "sc520_freq", | ||
151 | .owner = THIS_MODULE, | ||
152 | .attr = sc520_freq_attr, | ||
153 | }; | ||
154 | |||
155 | |||
156 | static int __init sc520_freq_init(void) | ||
157 | { | ||
158 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
159 | int err; | ||
160 | |||
161 | /* Test if we have the right hardware */ | ||
162 | if (c->x86_vendor != X86_VENDOR_AMD || | ||
163 | c->x86 != 4 || c->x86_model != 9) { | ||
164 | dprintk("no Elan SC520 processor found!\n"); | ||
165 | return -ENODEV; | ||
166 | } | ||
167 | cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1); | ||
168 | if (!cpuctl) { | ||
169 | printk(KERN_ERR "sc520_freq: error: failed to remap memory\n"); | ||
170 | return -ENOMEM; | ||
171 | } | ||
172 | |||
173 | err = cpufreq_register_driver(&sc520_freq_driver); | ||
174 | if (err) | ||
175 | iounmap(cpuctl); | ||
176 | |||
177 | return err; | ||
178 | } | ||
179 | |||
180 | |||
181 | static void __exit sc520_freq_exit(void) | ||
182 | { | ||
183 | cpufreq_unregister_driver(&sc520_freq_driver); | ||
184 | iounmap(cpuctl); | ||
185 | } | ||
186 | |||
187 | |||
188 | MODULE_LICENSE("GPL"); | ||
189 | MODULE_AUTHOR("Sean Young <sean@mess.org>"); | ||
190 | MODULE_DESCRIPTION("cpufreq driver for AMD's Elan sc520 CPU"); | ||
191 | |||
192 | module_init(sc520_freq_init); | ||
193 | module_exit(sc520_freq_exit); | ||
194 | |||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c deleted file mode 100644 index 9b1ff37de46a..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c +++ /dev/null | |||
@@ -1,636 +0,0 @@ | |||
1 | /* | ||
2 | * cpufreq driver for Enhanced SpeedStep, as found in Intel's Pentium | ||
3 | * M (part of the Centrino chipset). | ||
4 | * | ||
5 | * Since the original Pentium M, most new Intel CPUs support Enhanced | ||
6 | * SpeedStep. | ||
7 | * | ||
8 | * Despite the "SpeedStep" in the name, this is almost entirely unlike | ||
9 | * traditional SpeedStep. | ||
10 | * | ||
11 | * Modelled on speedstep.c | ||
12 | * | ||
13 | * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org> | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/cpufreq.h> | ||
20 | #include <linux/sched.h> /* current */ | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/compiler.h> | ||
23 | #include <linux/gfp.h> | ||
24 | |||
25 | #include <asm/msr.h> | ||
26 | #include <asm/processor.h> | ||
27 | #include <asm/cpufeature.h> | ||
28 | |||
29 | #define PFX "speedstep-centrino: " | ||
30 | #define MAINTAINER "cpufreq@vger.kernel.org" | ||
31 | |||
32 | #define dprintk(msg...) \ | ||
33 | cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-centrino", msg) | ||
34 | |||
35 | #define INTEL_MSR_RANGE (0xffff) | ||
36 | |||
37 | struct cpu_id | ||
38 | { | ||
39 | __u8 x86; /* CPU family */ | ||
40 | __u8 x86_model; /* model */ | ||
41 | __u8 x86_mask; /* stepping */ | ||
42 | }; | ||
43 | |||
44 | enum { | ||
45 | CPU_BANIAS, | ||
46 | CPU_DOTHAN_A1, | ||
47 | CPU_DOTHAN_A2, | ||
48 | CPU_DOTHAN_B0, | ||
49 | CPU_MP4HT_D0, | ||
50 | CPU_MP4HT_E0, | ||
51 | }; | ||
52 | |||
53 | static const struct cpu_id cpu_ids[] = { | ||
54 | [CPU_BANIAS] = { 6, 9, 5 }, | ||
55 | [CPU_DOTHAN_A1] = { 6, 13, 1 }, | ||
56 | [CPU_DOTHAN_A2] = { 6, 13, 2 }, | ||
57 | [CPU_DOTHAN_B0] = { 6, 13, 6 }, | ||
58 | [CPU_MP4HT_D0] = {15, 3, 4 }, | ||
59 | [CPU_MP4HT_E0] = {15, 4, 1 }, | ||
60 | }; | ||
61 | #define N_IDS ARRAY_SIZE(cpu_ids) | ||
62 | |||
63 | struct cpu_model | ||
64 | { | ||
65 | const struct cpu_id *cpu_id; | ||
66 | const char *model_name; | ||
67 | unsigned max_freq; /* max clock in kHz */ | ||
68 | |||
69 | struct cpufreq_frequency_table *op_points; /* clock/voltage pairs */ | ||
70 | }; | ||
71 | static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, | ||
72 | const struct cpu_id *x); | ||
73 | |||
74 | /* Operating points for current CPU */ | ||
75 | static DEFINE_PER_CPU(struct cpu_model *, centrino_model); | ||
76 | static DEFINE_PER_CPU(const struct cpu_id *, centrino_cpu); | ||
77 | |||
78 | static struct cpufreq_driver centrino_driver; | ||
79 | |||
80 | #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE | ||
81 | |||
82 | /* Computes the correct form for IA32_PERF_CTL MSR for a particular | ||
83 | frequency/voltage operating point; frequency in MHz, volts in mV. | ||
84 | This is stored as "index" in the structure. */ | ||
85 | #define OP(mhz, mv) \ | ||
86 | { \ | ||
87 | .frequency = (mhz) * 1000, \ | ||
88 | .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \ | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * These voltage tables were derived from the Intel Pentium M | ||
93 | * datasheet, document 25261202.pdf, Table 5. I have verified they | ||
94 | * are consistent with my IBM ThinkPad X31, which has a 1.3GHz Pentium | ||
95 | * M. | ||
96 | */ | ||
97 | |||
98 | /* Ultra Low Voltage Intel Pentium M processor 900MHz (Banias) */ | ||
99 | static struct cpufreq_frequency_table banias_900[] = | ||
100 | { | ||
101 | OP(600, 844), | ||
102 | OP(800, 988), | ||
103 | OP(900, 1004), | ||
104 | { .frequency = CPUFREQ_TABLE_END } | ||
105 | }; | ||
106 | |||
107 | /* Ultra Low Voltage Intel Pentium M processor 1000MHz (Banias) */ | ||
108 | static struct cpufreq_frequency_table banias_1000[] = | ||
109 | { | ||
110 | OP(600, 844), | ||
111 | OP(800, 972), | ||
112 | OP(900, 988), | ||
113 | OP(1000, 1004), | ||
114 | { .frequency = CPUFREQ_TABLE_END } | ||
115 | }; | ||
116 | |||
117 | /* Low Voltage Intel Pentium M processor 1.10GHz (Banias) */ | ||
118 | static struct cpufreq_frequency_table banias_1100[] = | ||
119 | { | ||
120 | OP( 600, 956), | ||
121 | OP( 800, 1020), | ||
122 | OP( 900, 1100), | ||
123 | OP(1000, 1164), | ||
124 | OP(1100, 1180), | ||
125 | { .frequency = CPUFREQ_TABLE_END } | ||
126 | }; | ||
127 | |||
128 | |||
129 | /* Low Voltage Intel Pentium M processor 1.20GHz (Banias) */ | ||
130 | static struct cpufreq_frequency_table banias_1200[] = | ||
131 | { | ||
132 | OP( 600, 956), | ||
133 | OP( 800, 1004), | ||
134 | OP( 900, 1020), | ||
135 | OP(1000, 1100), | ||
136 | OP(1100, 1164), | ||
137 | OP(1200, 1180), | ||
138 | { .frequency = CPUFREQ_TABLE_END } | ||
139 | }; | ||
140 | |||
141 | /* Intel Pentium M processor 1.30GHz (Banias) */ | ||
142 | static struct cpufreq_frequency_table banias_1300[] = | ||
143 | { | ||
144 | OP( 600, 956), | ||
145 | OP( 800, 1260), | ||
146 | OP(1000, 1292), | ||
147 | OP(1200, 1356), | ||
148 | OP(1300, 1388), | ||
149 | { .frequency = CPUFREQ_TABLE_END } | ||
150 | }; | ||
151 | |||
152 | /* Intel Pentium M processor 1.40GHz (Banias) */ | ||
153 | static struct cpufreq_frequency_table banias_1400[] = | ||
154 | { | ||
155 | OP( 600, 956), | ||
156 | OP( 800, 1180), | ||
157 | OP(1000, 1308), | ||
158 | OP(1200, 1436), | ||
159 | OP(1400, 1484), | ||
160 | { .frequency = CPUFREQ_TABLE_END } | ||
161 | }; | ||
162 | |||
163 | /* Intel Pentium M processor 1.50GHz (Banias) */ | ||
164 | static struct cpufreq_frequency_table banias_1500[] = | ||
165 | { | ||
166 | OP( 600, 956), | ||
167 | OP( 800, 1116), | ||
168 | OP(1000, 1228), | ||
169 | OP(1200, 1356), | ||
170 | OP(1400, 1452), | ||
171 | OP(1500, 1484), | ||
172 | { .frequency = CPUFREQ_TABLE_END } | ||
173 | }; | ||
174 | |||
175 | /* Intel Pentium M processor 1.60GHz (Banias) */ | ||
176 | static struct cpufreq_frequency_table banias_1600[] = | ||
177 | { | ||
178 | OP( 600, 956), | ||
179 | OP( 800, 1036), | ||
180 | OP(1000, 1164), | ||
181 | OP(1200, 1276), | ||
182 | OP(1400, 1420), | ||
183 | OP(1600, 1484), | ||
184 | { .frequency = CPUFREQ_TABLE_END } | ||
185 | }; | ||
186 | |||
187 | /* Intel Pentium M processor 1.70GHz (Banias) */ | ||
188 | static struct cpufreq_frequency_table banias_1700[] = | ||
189 | { | ||
190 | OP( 600, 956), | ||
191 | OP( 800, 1004), | ||
192 | OP(1000, 1116), | ||
193 | OP(1200, 1228), | ||
194 | OP(1400, 1308), | ||
195 | OP(1700, 1484), | ||
196 | { .frequency = CPUFREQ_TABLE_END } | ||
197 | }; | ||
198 | #undef OP | ||
199 | |||
200 | #define _BANIAS(cpuid, max, name) \ | ||
201 | { .cpu_id = cpuid, \ | ||
202 | .model_name = "Intel(R) Pentium(R) M processor " name "MHz", \ | ||
203 | .max_freq = (max)*1000, \ | ||
204 | .op_points = banias_##max, \ | ||
205 | } | ||
206 | #define BANIAS(max) _BANIAS(&cpu_ids[CPU_BANIAS], max, #max) | ||
207 | |||
208 | /* CPU models, their operating frequency range, and freq/voltage | ||
209 | operating points */ | ||
210 | static struct cpu_model models[] = | ||
211 | { | ||
212 | _BANIAS(&cpu_ids[CPU_BANIAS], 900, " 900"), | ||
213 | BANIAS(1000), | ||
214 | BANIAS(1100), | ||
215 | BANIAS(1200), | ||
216 | BANIAS(1300), | ||
217 | BANIAS(1400), | ||
218 | BANIAS(1500), | ||
219 | BANIAS(1600), | ||
220 | BANIAS(1700), | ||
221 | |||
222 | /* NULL model_name is a wildcard */ | ||
223 | { &cpu_ids[CPU_DOTHAN_A1], NULL, 0, NULL }, | ||
224 | { &cpu_ids[CPU_DOTHAN_A2], NULL, 0, NULL }, | ||
225 | { &cpu_ids[CPU_DOTHAN_B0], NULL, 0, NULL }, | ||
226 | { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL }, | ||
227 | { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL }, | ||
228 | |||
229 | { NULL, } | ||
230 | }; | ||
231 | #undef _BANIAS | ||
232 | #undef BANIAS | ||
233 | |||
234 | static int centrino_cpu_init_table(struct cpufreq_policy *policy) | ||
235 | { | ||
236 | struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu); | ||
237 | struct cpu_model *model; | ||
238 | |||
239 | for(model = models; model->cpu_id != NULL; model++) | ||
240 | if (centrino_verify_cpu_id(cpu, model->cpu_id) && | ||
241 | (model->model_name == NULL || | ||
242 | strcmp(cpu->x86_model_id, model->model_name) == 0)) | ||
243 | break; | ||
244 | |||
245 | if (model->cpu_id == NULL) { | ||
246 | /* No match at all */ | ||
247 | dprintk("no support for CPU model \"%s\": " | ||
248 | "send /proc/cpuinfo to " MAINTAINER "\n", | ||
249 | cpu->x86_model_id); | ||
250 | return -ENOENT; | ||
251 | } | ||
252 | |||
253 | if (model->op_points == NULL) { | ||
254 | /* Matched a non-match */ | ||
255 | dprintk("no table support for CPU model \"%s\"\n", | ||
256 | cpu->x86_model_id); | ||
257 | dprintk("try using the acpi-cpufreq driver\n"); | ||
258 | return -ENOENT; | ||
259 | } | ||
260 | |||
261 | per_cpu(centrino_model, policy->cpu) = model; | ||
262 | |||
263 | dprintk("found \"%s\": max frequency: %dkHz\n", | ||
264 | model->model_name, model->max_freq); | ||
265 | |||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | #else | ||
270 | static inline int centrino_cpu_init_table(struct cpufreq_policy *policy) | ||
271 | { | ||
272 | return -ENODEV; | ||
273 | } | ||
274 | #endif /* CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE */ | ||
275 | |||
276 | static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, | ||
277 | const struct cpu_id *x) | ||
278 | { | ||
279 | if ((c->x86 == x->x86) && | ||
280 | (c->x86_model == x->x86_model) && | ||
281 | (c->x86_mask == x->x86_mask)) | ||
282 | return 1; | ||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | /* To be called only after centrino_model is initialized */ | ||
287 | static unsigned extract_clock(unsigned msr, unsigned int cpu, int failsafe) | ||
288 | { | ||
289 | int i; | ||
290 | |||
291 | /* | ||
292 | * Extract clock in kHz from PERF_CTL value | ||
293 | * for centrino, as some DSDTs are buggy. | ||
294 | * Ideally, this can be done using the acpi_data structure. | ||
295 | */ | ||
296 | if ((per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_BANIAS]) || | ||
297 | (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_A1]) || | ||
298 | (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_B0])) { | ||
299 | msr = (msr >> 8) & 0xff; | ||
300 | return msr * 100000; | ||
301 | } | ||
302 | |||
303 | if ((!per_cpu(centrino_model, cpu)) || | ||
304 | (!per_cpu(centrino_model, cpu)->op_points)) | ||
305 | return 0; | ||
306 | |||
307 | msr &= 0xffff; | ||
308 | for (i = 0; | ||
309 | per_cpu(centrino_model, cpu)->op_points[i].frequency | ||
310 | != CPUFREQ_TABLE_END; | ||
311 | i++) { | ||
312 | if (msr == per_cpu(centrino_model, cpu)->op_points[i].index) | ||
313 | return per_cpu(centrino_model, cpu)-> | ||
314 | op_points[i].frequency; | ||
315 | } | ||
316 | if (failsafe) | ||
317 | return per_cpu(centrino_model, cpu)->op_points[i-1].frequency; | ||
318 | else | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | /* Return the current CPU frequency in kHz */ | ||
323 | static unsigned int get_cur_freq(unsigned int cpu) | ||
324 | { | ||
325 | unsigned l, h; | ||
326 | unsigned clock_freq; | ||
327 | |||
328 | rdmsr_on_cpu(cpu, MSR_IA32_PERF_STATUS, &l, &h); | ||
329 | clock_freq = extract_clock(l, cpu, 0); | ||
330 | |||
331 | if (unlikely(clock_freq == 0)) { | ||
332 | /* | ||
333 | * On some CPUs, we can see transient MSR values (which are | ||
334 | * not present in _PSS), while CPU is doing some automatic | ||
335 | * P-state transition (like TM2). Get the last freq set | ||
336 | * in PERF_CTL. | ||
337 | */ | ||
338 | rdmsr_on_cpu(cpu, MSR_IA32_PERF_CTL, &l, &h); | ||
339 | clock_freq = extract_clock(l, cpu, 1); | ||
340 | } | ||
341 | return clock_freq; | ||
342 | } | ||
343 | |||
344 | |||
345 | static int centrino_cpu_init(struct cpufreq_policy *policy) | ||
346 | { | ||
347 | struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu); | ||
348 | unsigned freq; | ||
349 | unsigned l, h; | ||
350 | int ret; | ||
351 | int i; | ||
352 | |||
353 | /* Only Intel makes Enhanced Speedstep-capable CPUs */ | ||
354 | if (cpu->x86_vendor != X86_VENDOR_INTEL || | ||
355 | !cpu_has(cpu, X86_FEATURE_EST)) | ||
356 | return -ENODEV; | ||
357 | |||
358 | if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) | ||
359 | centrino_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
360 | |||
361 | if (policy->cpu != 0) | ||
362 | return -ENODEV; | ||
363 | |||
364 | for (i = 0; i < N_IDS; i++) | ||
365 | if (centrino_verify_cpu_id(cpu, &cpu_ids[i])) | ||
366 | break; | ||
367 | |||
368 | if (i != N_IDS) | ||
369 | per_cpu(centrino_cpu, policy->cpu) = &cpu_ids[i]; | ||
370 | |||
371 | if (!per_cpu(centrino_cpu, policy->cpu)) { | ||
372 | dprintk("found unsupported CPU with " | ||
373 | "Enhanced SpeedStep: send /proc/cpuinfo to " | ||
374 | MAINTAINER "\n"); | ||
375 | return -ENODEV; | ||
376 | } | ||
377 | |||
378 | if (centrino_cpu_init_table(policy)) { | ||
379 | return -ENODEV; | ||
380 | } | ||
381 | |||
382 | /* Check to see if Enhanced SpeedStep is enabled, and try to | ||
383 | enable it if not. */ | ||
384 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
385 | |||
386 | if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
387 | l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP; | ||
388 | dprintk("trying to enable Enhanced SpeedStep (%x)\n", l); | ||
389 | wrmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
390 | |||
391 | /* check to see if it stuck */ | ||
392 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
393 | if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
394 | printk(KERN_INFO PFX | ||
395 | "couldn't enable Enhanced SpeedStep\n"); | ||
396 | return -ENODEV; | ||
397 | } | ||
398 | } | ||
399 | |||
400 | freq = get_cur_freq(policy->cpu); | ||
401 | policy->cpuinfo.transition_latency = 10000; | ||
402 | /* 10uS transition latency */ | ||
403 | policy->cur = freq; | ||
404 | |||
405 | dprintk("centrino_cpu_init: cur=%dkHz\n", policy->cur); | ||
406 | |||
407 | ret = cpufreq_frequency_table_cpuinfo(policy, | ||
408 | per_cpu(centrino_model, policy->cpu)->op_points); | ||
409 | if (ret) | ||
410 | return (ret); | ||
411 | |||
412 | cpufreq_frequency_table_get_attr( | ||
413 | per_cpu(centrino_model, policy->cpu)->op_points, policy->cpu); | ||
414 | |||
415 | return 0; | ||
416 | } | ||
417 | |||
418 | static int centrino_cpu_exit(struct cpufreq_policy *policy) | ||
419 | { | ||
420 | unsigned int cpu = policy->cpu; | ||
421 | |||
422 | if (!per_cpu(centrino_model, cpu)) | ||
423 | return -ENODEV; | ||
424 | |||
425 | cpufreq_frequency_table_put_attr(cpu); | ||
426 | |||
427 | per_cpu(centrino_model, cpu) = NULL; | ||
428 | |||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | /** | ||
433 | * centrino_verify - verifies a new CPUFreq policy | ||
434 | * @policy: new policy | ||
435 | * | ||
436 | * Limit must be within this model's frequency range at least one | ||
437 | * border included. | ||
438 | */ | ||
439 | static int centrino_verify (struct cpufreq_policy *policy) | ||
440 | { | ||
441 | return cpufreq_frequency_table_verify(policy, | ||
442 | per_cpu(centrino_model, policy->cpu)->op_points); | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * centrino_setpolicy - set a new CPUFreq policy | ||
447 | * @policy: new policy | ||
448 | * @target_freq: the target frequency | ||
449 | * @relation: how that frequency relates to achieved frequency | ||
450 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
451 | * | ||
452 | * Sets a new CPUFreq policy. | ||
453 | */ | ||
454 | static int centrino_target (struct cpufreq_policy *policy, | ||
455 | unsigned int target_freq, | ||
456 | unsigned int relation) | ||
457 | { | ||
458 | unsigned int newstate = 0; | ||
459 | unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu; | ||
460 | struct cpufreq_freqs freqs; | ||
461 | int retval = 0; | ||
462 | unsigned int j, k, first_cpu, tmp; | ||
463 | cpumask_var_t covered_cpus; | ||
464 | |||
465 | if (unlikely(!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))) | ||
466 | return -ENOMEM; | ||
467 | |||
468 | if (unlikely(per_cpu(centrino_model, cpu) == NULL)) { | ||
469 | retval = -ENODEV; | ||
470 | goto out; | ||
471 | } | ||
472 | |||
473 | if (unlikely(cpufreq_frequency_table_target(policy, | ||
474 | per_cpu(centrino_model, cpu)->op_points, | ||
475 | target_freq, | ||
476 | relation, | ||
477 | &newstate))) { | ||
478 | retval = -EINVAL; | ||
479 | goto out; | ||
480 | } | ||
481 | |||
482 | first_cpu = 1; | ||
483 | for_each_cpu(j, policy->cpus) { | ||
484 | int good_cpu; | ||
485 | |||
486 | /* cpufreq holds the hotplug lock, so we are safe here */ | ||
487 | if (!cpu_online(j)) | ||
488 | continue; | ||
489 | |||
490 | /* | ||
491 | * Support for SMP systems. | ||
492 | * Make sure we are running on CPU that wants to change freq | ||
493 | */ | ||
494 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | ||
495 | good_cpu = cpumask_any_and(policy->cpus, | ||
496 | cpu_online_mask); | ||
497 | else | ||
498 | good_cpu = j; | ||
499 | |||
500 | if (good_cpu >= nr_cpu_ids) { | ||
501 | dprintk("couldn't limit to CPUs in this domain\n"); | ||
502 | retval = -EAGAIN; | ||
503 | if (first_cpu) { | ||
504 | /* We haven't started the transition yet. */ | ||
505 | goto out; | ||
506 | } | ||
507 | break; | ||
508 | } | ||
509 | |||
510 | msr = per_cpu(centrino_model, cpu)->op_points[newstate].index; | ||
511 | |||
512 | if (first_cpu) { | ||
513 | rdmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, &oldmsr, &h); | ||
514 | if (msr == (oldmsr & 0xffff)) { | ||
515 | dprintk("no change needed - msr was and needs " | ||
516 | "to be %x\n", oldmsr); | ||
517 | retval = 0; | ||
518 | goto out; | ||
519 | } | ||
520 | |||
521 | freqs.old = extract_clock(oldmsr, cpu, 0); | ||
522 | freqs.new = extract_clock(msr, cpu, 0); | ||
523 | |||
524 | dprintk("target=%dkHz old=%d new=%d msr=%04x\n", | ||
525 | target_freq, freqs.old, freqs.new, msr); | ||
526 | |||
527 | for_each_cpu(k, policy->cpus) { | ||
528 | if (!cpu_online(k)) | ||
529 | continue; | ||
530 | freqs.cpu = k; | ||
531 | cpufreq_notify_transition(&freqs, | ||
532 | CPUFREQ_PRECHANGE); | ||
533 | } | ||
534 | |||
535 | first_cpu = 0; | ||
536 | /* all but 16 LSB are reserved, treat them with care */ | ||
537 | oldmsr &= ~0xffff; | ||
538 | msr &= 0xffff; | ||
539 | oldmsr |= msr; | ||
540 | } | ||
541 | |||
542 | wrmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, oldmsr, h); | ||
543 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | ||
544 | break; | ||
545 | |||
546 | cpumask_set_cpu(j, covered_cpus); | ||
547 | } | ||
548 | |||
549 | for_each_cpu(k, policy->cpus) { | ||
550 | if (!cpu_online(k)) | ||
551 | continue; | ||
552 | freqs.cpu = k; | ||
553 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
554 | } | ||
555 | |||
556 | if (unlikely(retval)) { | ||
557 | /* | ||
558 | * We have failed halfway through the frequency change. | ||
559 | * We have sent callbacks to policy->cpus and | ||
560 | * MSRs have already been written on coverd_cpus. | ||
561 | * Best effort undo.. | ||
562 | */ | ||
563 | |||
564 | for_each_cpu(j, covered_cpus) | ||
565 | wrmsr_on_cpu(j, MSR_IA32_PERF_CTL, oldmsr, h); | ||
566 | |||
567 | tmp = freqs.new; | ||
568 | freqs.new = freqs.old; | ||
569 | freqs.old = tmp; | ||
570 | for_each_cpu(j, policy->cpus) { | ||
571 | if (!cpu_online(j)) | ||
572 | continue; | ||
573 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
574 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
575 | } | ||
576 | } | ||
577 | retval = 0; | ||
578 | |||
579 | out: | ||
580 | free_cpumask_var(covered_cpus); | ||
581 | return retval; | ||
582 | } | ||
583 | |||
584 | static struct freq_attr* centrino_attr[] = { | ||
585 | &cpufreq_freq_attr_scaling_available_freqs, | ||
586 | NULL, | ||
587 | }; | ||
588 | |||
589 | static struct cpufreq_driver centrino_driver = { | ||
590 | .name = "centrino", /* should be speedstep-centrino, | ||
591 | but there's a 16 char limit */ | ||
592 | .init = centrino_cpu_init, | ||
593 | .exit = centrino_cpu_exit, | ||
594 | .verify = centrino_verify, | ||
595 | .target = centrino_target, | ||
596 | .get = get_cur_freq, | ||
597 | .attr = centrino_attr, | ||
598 | .owner = THIS_MODULE, | ||
599 | }; | ||
600 | |||
601 | |||
602 | /** | ||
603 | * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver | ||
604 | * | ||
605 | * Initializes the Enhanced SpeedStep support. Returns -ENODEV on | ||
606 | * unsupported devices, -ENOENT if there's no voltage table for this | ||
607 | * particular CPU model, -EINVAL on problems during initiatization, | ||
608 | * and zero on success. | ||
609 | * | ||
610 | * This is quite picky. Not only does the CPU have to advertise the | ||
611 | * "est" flag in the cpuid capability flags, we look for a specific | ||
612 | * CPU model and stepping, and we need to have the exact model name in | ||
613 | * our voltage tables. That is, be paranoid about not releasing | ||
614 | * someone's valuable magic smoke. | ||
615 | */ | ||
616 | static int __init centrino_init(void) | ||
617 | { | ||
618 | struct cpuinfo_x86 *cpu = &cpu_data(0); | ||
619 | |||
620 | if (!cpu_has(cpu, X86_FEATURE_EST)) | ||
621 | return -ENODEV; | ||
622 | |||
623 | return cpufreq_register_driver(¢rino_driver); | ||
624 | } | ||
625 | |||
626 | static void __exit centrino_exit(void) | ||
627 | { | ||
628 | cpufreq_unregister_driver(¢rino_driver); | ||
629 | } | ||
630 | |||
631 | MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>"); | ||
632 | MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors."); | ||
633 | MODULE_LICENSE ("GPL"); | ||
634 | |||
635 | late_initcall(centrino_init); | ||
636 | module_exit(centrino_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c b/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c deleted file mode 100644 index 561758e95180..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c +++ /dev/null | |||
@@ -1,452 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2001 Dave Jones, Arjan van de ven. | ||
3 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
4 | * | ||
5 | * Licensed under the terms of the GNU GPL License version 2. | ||
6 | * Based upon reverse engineered information, and on Intel documentation | ||
7 | * for chipsets ICH2-M and ICH3-M. | ||
8 | * | ||
9 | * Many thanks to Ducrot Bruno for finding and fixing the last | ||
10 | * "missing link" for ICH2-M/ICH3-M support, and to Thomas Winkler | ||
11 | * for extensive testing. | ||
12 | * | ||
13 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
14 | */ | ||
15 | |||
16 | |||
17 | /********************************************************************* | ||
18 | * SPEEDSTEP - DEFINITIONS * | ||
19 | *********************************************************************/ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/cpufreq.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/sched.h> | ||
27 | |||
28 | #include "speedstep-lib.h" | ||
29 | |||
30 | |||
31 | /* speedstep_chipset: | ||
32 | * It is necessary to know which chipset is used. As accesses to | ||
33 | * this device occur at various places in this module, we need a | ||
34 | * static struct pci_dev * pointing to that device. | ||
35 | */ | ||
36 | static struct pci_dev *speedstep_chipset_dev; | ||
37 | |||
38 | |||
39 | /* speedstep_processor | ||
40 | */ | ||
41 | static enum speedstep_processor speedstep_processor; | ||
42 | |||
43 | static u32 pmbase; | ||
44 | |||
45 | /* | ||
46 | * There are only two frequency states for each processor. Values | ||
47 | * are in kHz for the time being. | ||
48 | */ | ||
49 | static struct cpufreq_frequency_table speedstep_freqs[] = { | ||
50 | {SPEEDSTEP_HIGH, 0}, | ||
51 | {SPEEDSTEP_LOW, 0}, | ||
52 | {0, CPUFREQ_TABLE_END}, | ||
53 | }; | ||
54 | |||
55 | |||
56 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
57 | "speedstep-ich", msg) | ||
58 | |||
59 | |||
60 | /** | ||
61 | * speedstep_find_register - read the PMBASE address | ||
62 | * | ||
63 | * Returns: -ENODEV if no register could be found | ||
64 | */ | ||
65 | static int speedstep_find_register(void) | ||
66 | { | ||
67 | if (!speedstep_chipset_dev) | ||
68 | return -ENODEV; | ||
69 | |||
70 | /* get PMBASE */ | ||
71 | pci_read_config_dword(speedstep_chipset_dev, 0x40, &pmbase); | ||
72 | if (!(pmbase & 0x01)) { | ||
73 | printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); | ||
74 | return -ENODEV; | ||
75 | } | ||
76 | |||
77 | pmbase &= 0xFFFFFFFE; | ||
78 | if (!pmbase) { | ||
79 | printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); | ||
80 | return -ENODEV; | ||
81 | } | ||
82 | |||
83 | dprintk("pmbase is 0x%x\n", pmbase); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * speedstep_set_state - set the SpeedStep state | ||
89 | * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
90 | * | ||
91 | * Tries to change the SpeedStep state. Can be called from | ||
92 | * smp_call_function_single. | ||
93 | */ | ||
94 | static void speedstep_set_state(unsigned int state) | ||
95 | { | ||
96 | u8 pm2_blk; | ||
97 | u8 value; | ||
98 | unsigned long flags; | ||
99 | |||
100 | if (state > 0x1) | ||
101 | return; | ||
102 | |||
103 | /* Disable IRQs */ | ||
104 | local_irq_save(flags); | ||
105 | |||
106 | /* read state */ | ||
107 | value = inb(pmbase + 0x50); | ||
108 | |||
109 | dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); | ||
110 | |||
111 | /* write new state */ | ||
112 | value &= 0xFE; | ||
113 | value |= state; | ||
114 | |||
115 | dprintk("writing 0x%x to pmbase 0x%x + 0x50\n", value, pmbase); | ||
116 | |||
117 | /* Disable bus master arbitration */ | ||
118 | pm2_blk = inb(pmbase + 0x20); | ||
119 | pm2_blk |= 0x01; | ||
120 | outb(pm2_blk, (pmbase + 0x20)); | ||
121 | |||
122 | /* Actual transition */ | ||
123 | outb(value, (pmbase + 0x50)); | ||
124 | |||
125 | /* Restore bus master arbitration */ | ||
126 | pm2_blk &= 0xfe; | ||
127 | outb(pm2_blk, (pmbase + 0x20)); | ||
128 | |||
129 | /* check if transition was successful */ | ||
130 | value = inb(pmbase + 0x50); | ||
131 | |||
132 | /* Enable IRQs */ | ||
133 | local_irq_restore(flags); | ||
134 | |||
135 | dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); | ||
136 | |||
137 | if (state == (value & 0x1)) | ||
138 | dprintk("change to %u MHz succeeded\n", | ||
139 | speedstep_get_frequency(speedstep_processor) / 1000); | ||
140 | else | ||
141 | printk(KERN_ERR "cpufreq: change failed - I/O error\n"); | ||
142 | |||
143 | return; | ||
144 | } | ||
145 | |||
146 | /* Wrapper for smp_call_function_single. */ | ||
147 | static void _speedstep_set_state(void *_state) | ||
148 | { | ||
149 | speedstep_set_state(*(unsigned int *)_state); | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * speedstep_activate - activate SpeedStep control in the chipset | ||
154 | * | ||
155 | * Tries to activate the SpeedStep status and control registers. | ||
156 | * Returns -EINVAL on an unsupported chipset, and zero on success. | ||
157 | */ | ||
158 | static int speedstep_activate(void) | ||
159 | { | ||
160 | u16 value = 0; | ||
161 | |||
162 | if (!speedstep_chipset_dev) | ||
163 | return -EINVAL; | ||
164 | |||
165 | pci_read_config_word(speedstep_chipset_dev, 0x00A0, &value); | ||
166 | if (!(value & 0x08)) { | ||
167 | value |= 0x08; | ||
168 | dprintk("activating SpeedStep (TM) registers\n"); | ||
169 | pci_write_config_word(speedstep_chipset_dev, 0x00A0, value); | ||
170 | } | ||
171 | |||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | |||
176 | /** | ||
177 | * speedstep_detect_chipset - detect the Southbridge which contains SpeedStep logic | ||
178 | * | ||
179 | * Detects ICH2-M, ICH3-M and ICH4-M so far. The pci_dev points to | ||
180 | * the LPC bridge / PM module which contains all power-management | ||
181 | * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected | ||
182 | * chipset, or zero on failure. | ||
183 | */ | ||
184 | static unsigned int speedstep_detect_chipset(void) | ||
185 | { | ||
186 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
187 | PCI_DEVICE_ID_INTEL_82801DB_12, | ||
188 | PCI_ANY_ID, PCI_ANY_ID, | ||
189 | NULL); | ||
190 | if (speedstep_chipset_dev) | ||
191 | return 4; /* 4-M */ | ||
192 | |||
193 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
194 | PCI_DEVICE_ID_INTEL_82801CA_12, | ||
195 | PCI_ANY_ID, PCI_ANY_ID, | ||
196 | NULL); | ||
197 | if (speedstep_chipset_dev) | ||
198 | return 3; /* 3-M */ | ||
199 | |||
200 | |||
201 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
202 | PCI_DEVICE_ID_INTEL_82801BA_10, | ||
203 | PCI_ANY_ID, PCI_ANY_ID, | ||
204 | NULL); | ||
205 | if (speedstep_chipset_dev) { | ||
206 | /* speedstep.c causes lockups on Dell Inspirons 8000 and | ||
207 | * 8100 which use a pretty old revision of the 82815 | ||
208 | * host brige. Abort on these systems. | ||
209 | */ | ||
210 | static struct pci_dev *hostbridge; | ||
211 | |||
212 | hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
213 | PCI_DEVICE_ID_INTEL_82815_MC, | ||
214 | PCI_ANY_ID, PCI_ANY_ID, | ||
215 | NULL); | ||
216 | |||
217 | if (!hostbridge) | ||
218 | return 2; /* 2-M */ | ||
219 | |||
220 | if (hostbridge->revision < 5) { | ||
221 | dprintk("hostbridge does not support speedstep\n"); | ||
222 | speedstep_chipset_dev = NULL; | ||
223 | pci_dev_put(hostbridge); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | pci_dev_put(hostbridge); | ||
228 | return 2; /* 2-M */ | ||
229 | } | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static void get_freq_data(void *_speed) | ||
235 | { | ||
236 | unsigned int *speed = _speed; | ||
237 | |||
238 | *speed = speedstep_get_frequency(speedstep_processor); | ||
239 | } | ||
240 | |||
241 | static unsigned int speedstep_get(unsigned int cpu) | ||
242 | { | ||
243 | unsigned int speed; | ||
244 | |||
245 | /* You're supposed to ensure CPU is online. */ | ||
246 | if (smp_call_function_single(cpu, get_freq_data, &speed, 1) != 0) | ||
247 | BUG(); | ||
248 | |||
249 | dprintk("detected %u kHz as current frequency\n", speed); | ||
250 | return speed; | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * speedstep_target - set a new CPUFreq policy | ||
255 | * @policy: new policy | ||
256 | * @target_freq: the target frequency | ||
257 | * @relation: how that frequency relates to achieved frequency | ||
258 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
259 | * | ||
260 | * Sets a new CPUFreq policy. | ||
261 | */ | ||
262 | static int speedstep_target(struct cpufreq_policy *policy, | ||
263 | unsigned int target_freq, | ||
264 | unsigned int relation) | ||
265 | { | ||
266 | unsigned int newstate = 0, policy_cpu; | ||
267 | struct cpufreq_freqs freqs; | ||
268 | int i; | ||
269 | |||
270 | if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], | ||
271 | target_freq, relation, &newstate)) | ||
272 | return -EINVAL; | ||
273 | |||
274 | policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); | ||
275 | freqs.old = speedstep_get(policy_cpu); | ||
276 | freqs.new = speedstep_freqs[newstate].frequency; | ||
277 | freqs.cpu = policy->cpu; | ||
278 | |||
279 | dprintk("transiting from %u to %u kHz\n", freqs.old, freqs.new); | ||
280 | |||
281 | /* no transition necessary */ | ||
282 | if (freqs.old == freqs.new) | ||
283 | return 0; | ||
284 | |||
285 | for_each_cpu(i, policy->cpus) { | ||
286 | freqs.cpu = i; | ||
287 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
288 | } | ||
289 | |||
290 | smp_call_function_single(policy_cpu, _speedstep_set_state, &newstate, | ||
291 | true); | ||
292 | |||
293 | for_each_cpu(i, policy->cpus) { | ||
294 | freqs.cpu = i; | ||
295 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
296 | } | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | |||
302 | /** | ||
303 | * speedstep_verify - verifies a new CPUFreq policy | ||
304 | * @policy: new policy | ||
305 | * | ||
306 | * Limit must be within speedstep_low_freq and speedstep_high_freq, with | ||
307 | * at least one border included. | ||
308 | */ | ||
309 | static int speedstep_verify(struct cpufreq_policy *policy) | ||
310 | { | ||
311 | return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); | ||
312 | } | ||
313 | |||
314 | struct get_freqs { | ||
315 | struct cpufreq_policy *policy; | ||
316 | int ret; | ||
317 | }; | ||
318 | |||
319 | static void get_freqs_on_cpu(void *_get_freqs) | ||
320 | { | ||
321 | struct get_freqs *get_freqs = _get_freqs; | ||
322 | |||
323 | get_freqs->ret = | ||
324 | speedstep_get_freqs(speedstep_processor, | ||
325 | &speedstep_freqs[SPEEDSTEP_LOW].frequency, | ||
326 | &speedstep_freqs[SPEEDSTEP_HIGH].frequency, | ||
327 | &get_freqs->policy->cpuinfo.transition_latency, | ||
328 | &speedstep_set_state); | ||
329 | } | ||
330 | |||
331 | static int speedstep_cpu_init(struct cpufreq_policy *policy) | ||
332 | { | ||
333 | int result; | ||
334 | unsigned int policy_cpu, speed; | ||
335 | struct get_freqs gf; | ||
336 | |||
337 | /* only run on CPU to be set, or on its sibling */ | ||
338 | #ifdef CONFIG_SMP | ||
339 | cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); | ||
340 | #endif | ||
341 | policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); | ||
342 | |||
343 | /* detect low and high frequency and transition latency */ | ||
344 | gf.policy = policy; | ||
345 | smp_call_function_single(policy_cpu, get_freqs_on_cpu, &gf, 1); | ||
346 | if (gf.ret) | ||
347 | return gf.ret; | ||
348 | |||
349 | /* get current speed setting */ | ||
350 | speed = speedstep_get(policy_cpu); | ||
351 | if (!speed) | ||
352 | return -EIO; | ||
353 | |||
354 | dprintk("currently at %s speed setting - %i MHz\n", | ||
355 | (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) | ||
356 | ? "low" : "high", | ||
357 | (speed / 1000)); | ||
358 | |||
359 | /* cpuinfo and default policy values */ | ||
360 | policy->cur = speed; | ||
361 | |||
362 | result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); | ||
363 | if (result) | ||
364 | return result; | ||
365 | |||
366 | cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); | ||
367 | |||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | |||
372 | static int speedstep_cpu_exit(struct cpufreq_policy *policy) | ||
373 | { | ||
374 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | static struct freq_attr *speedstep_attr[] = { | ||
379 | &cpufreq_freq_attr_scaling_available_freqs, | ||
380 | NULL, | ||
381 | }; | ||
382 | |||
383 | |||
384 | static struct cpufreq_driver speedstep_driver = { | ||
385 | .name = "speedstep-ich", | ||
386 | .verify = speedstep_verify, | ||
387 | .target = speedstep_target, | ||
388 | .init = speedstep_cpu_init, | ||
389 | .exit = speedstep_cpu_exit, | ||
390 | .get = speedstep_get, | ||
391 | .owner = THIS_MODULE, | ||
392 | .attr = speedstep_attr, | ||
393 | }; | ||
394 | |||
395 | |||
396 | /** | ||
397 | * speedstep_init - initializes the SpeedStep CPUFreq driver | ||
398 | * | ||
399 | * Initializes the SpeedStep support. Returns -ENODEV on unsupported | ||
400 | * devices, -EINVAL on problems during initiatization, and zero on | ||
401 | * success. | ||
402 | */ | ||
403 | static int __init speedstep_init(void) | ||
404 | { | ||
405 | /* detect processor */ | ||
406 | speedstep_processor = speedstep_detect_processor(); | ||
407 | if (!speedstep_processor) { | ||
408 | dprintk("Intel(R) SpeedStep(TM) capable processor " | ||
409 | "not found\n"); | ||
410 | return -ENODEV; | ||
411 | } | ||
412 | |||
413 | /* detect chipset */ | ||
414 | if (!speedstep_detect_chipset()) { | ||
415 | dprintk("Intel(R) SpeedStep(TM) for this chipset not " | ||
416 | "(yet) available.\n"); | ||
417 | return -ENODEV; | ||
418 | } | ||
419 | |||
420 | /* activate speedstep support */ | ||
421 | if (speedstep_activate()) { | ||
422 | pci_dev_put(speedstep_chipset_dev); | ||
423 | return -EINVAL; | ||
424 | } | ||
425 | |||
426 | if (speedstep_find_register()) | ||
427 | return -ENODEV; | ||
428 | |||
429 | return cpufreq_register_driver(&speedstep_driver); | ||
430 | } | ||
431 | |||
432 | |||
433 | /** | ||
434 | * speedstep_exit - unregisters SpeedStep support | ||
435 | * | ||
436 | * Unregisters SpeedStep support. | ||
437 | */ | ||
438 | static void __exit speedstep_exit(void) | ||
439 | { | ||
440 | pci_dev_put(speedstep_chipset_dev); | ||
441 | cpufreq_unregister_driver(&speedstep_driver); | ||
442 | } | ||
443 | |||
444 | |||
445 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>, " | ||
446 | "Dominik Brodowski <linux@brodo.de>"); | ||
447 | MODULE_DESCRIPTION("Speedstep driver for Intel mobile processors on chipsets " | ||
448 | "with ICH-M southbridges."); | ||
449 | MODULE_LICENSE("GPL"); | ||
450 | |||
451 | module_init(speedstep_init); | ||
452 | module_exit(speedstep_exit); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c deleted file mode 100644 index a94ec6be69fa..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c +++ /dev/null | |||
@@ -1,481 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * Library for common functions for Intel SpeedStep v.1 and v.2 support | ||
7 | * | ||
8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/moduleparam.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/cpufreq.h> | ||
16 | |||
17 | #include <asm/msr.h> | ||
18 | #include <asm/tsc.h> | ||
19 | #include "speedstep-lib.h" | ||
20 | |||
21 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
22 | "speedstep-lib", msg) | ||
23 | |||
24 | #define PFX "speedstep-lib: " | ||
25 | |||
26 | #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
27 | static int relaxed_check; | ||
28 | #else | ||
29 | #define relaxed_check 0 | ||
30 | #endif | ||
31 | |||
32 | /********************************************************************* | ||
33 | * GET PROCESSOR CORE SPEED IN KHZ * | ||
34 | *********************************************************************/ | ||
35 | |||
36 | static unsigned int pentium3_get_frequency(enum speedstep_processor processor) | ||
37 | { | ||
38 | /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */ | ||
39 | struct { | ||
40 | unsigned int ratio; /* Frequency Multiplier (x10) */ | ||
41 | u8 bitmap; /* power on configuration bits | ||
42 | [27, 25:22] (in MSR 0x2a) */ | ||
43 | } msr_decode_mult[] = { | ||
44 | { 30, 0x01 }, | ||
45 | { 35, 0x05 }, | ||
46 | { 40, 0x02 }, | ||
47 | { 45, 0x06 }, | ||
48 | { 50, 0x00 }, | ||
49 | { 55, 0x04 }, | ||
50 | { 60, 0x0b }, | ||
51 | { 65, 0x0f }, | ||
52 | { 70, 0x09 }, | ||
53 | { 75, 0x0d }, | ||
54 | { 80, 0x0a }, | ||
55 | { 85, 0x26 }, | ||
56 | { 90, 0x20 }, | ||
57 | { 100, 0x2b }, | ||
58 | { 0, 0xff } /* error or unknown value */ | ||
59 | }; | ||
60 | |||
61 | /* PIII(-M) FSB settings: see table b1-b of 24547206.pdf */ | ||
62 | struct { | ||
63 | unsigned int value; /* Front Side Bus speed in MHz */ | ||
64 | u8 bitmap; /* power on configuration bits [18: 19] | ||
65 | (in MSR 0x2a) */ | ||
66 | } msr_decode_fsb[] = { | ||
67 | { 66, 0x0 }, | ||
68 | { 100, 0x2 }, | ||
69 | { 133, 0x1 }, | ||
70 | { 0, 0xff} | ||
71 | }; | ||
72 | |||
73 | u32 msr_lo, msr_tmp; | ||
74 | int i = 0, j = 0; | ||
75 | |||
76 | /* read MSR 0x2a - we only need the low 32 bits */ | ||
77 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
78 | dprintk("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); | ||
79 | msr_tmp = msr_lo; | ||
80 | |||
81 | /* decode the FSB */ | ||
82 | msr_tmp &= 0x00c0000; | ||
83 | msr_tmp >>= 18; | ||
84 | while (msr_tmp != msr_decode_fsb[i].bitmap) { | ||
85 | if (msr_decode_fsb[i].bitmap == 0xff) | ||
86 | return 0; | ||
87 | i++; | ||
88 | } | ||
89 | |||
90 | /* decode the multiplier */ | ||
91 | if (processor == SPEEDSTEP_CPU_PIII_C_EARLY) { | ||
92 | dprintk("workaround for early PIIIs\n"); | ||
93 | msr_lo &= 0x03c00000; | ||
94 | } else | ||
95 | msr_lo &= 0x0bc00000; | ||
96 | msr_lo >>= 22; | ||
97 | while (msr_lo != msr_decode_mult[j].bitmap) { | ||
98 | if (msr_decode_mult[j].bitmap == 0xff) | ||
99 | return 0; | ||
100 | j++; | ||
101 | } | ||
102 | |||
103 | dprintk("speed is %u\n", | ||
104 | (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100)); | ||
105 | |||
106 | return msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100; | ||
107 | } | ||
108 | |||
109 | |||
110 | static unsigned int pentiumM_get_frequency(void) | ||
111 | { | ||
112 | u32 msr_lo, msr_tmp; | ||
113 | |||
114 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
115 | dprintk("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); | ||
116 | |||
117 | /* see table B-2 of 24547212.pdf */ | ||
118 | if (msr_lo & 0x00040000) { | ||
119 | printk(KERN_DEBUG PFX "PM - invalid FSB: 0x%x 0x%x\n", | ||
120 | msr_lo, msr_tmp); | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | msr_tmp = (msr_lo >> 22) & 0x1f; | ||
125 | dprintk("bits 22-26 are 0x%x, speed is %u\n", | ||
126 | msr_tmp, (msr_tmp * 100 * 1000)); | ||
127 | |||
128 | return msr_tmp * 100 * 1000; | ||
129 | } | ||
130 | |||
131 | static unsigned int pentium_core_get_frequency(void) | ||
132 | { | ||
133 | u32 fsb = 0; | ||
134 | u32 msr_lo, msr_tmp; | ||
135 | int ret; | ||
136 | |||
137 | rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp); | ||
138 | /* see table B-2 of 25366920.pdf */ | ||
139 | switch (msr_lo & 0x07) { | ||
140 | case 5: | ||
141 | fsb = 100000; | ||
142 | break; | ||
143 | case 1: | ||
144 | fsb = 133333; | ||
145 | break; | ||
146 | case 3: | ||
147 | fsb = 166667; | ||
148 | break; | ||
149 | case 2: | ||
150 | fsb = 200000; | ||
151 | break; | ||
152 | case 0: | ||
153 | fsb = 266667; | ||
154 | break; | ||
155 | case 4: | ||
156 | fsb = 333333; | ||
157 | break; | ||
158 | default: | ||
159 | printk(KERN_ERR "PCORE - MSR_FSB_FREQ undefined value"); | ||
160 | } | ||
161 | |||
162 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
163 | dprintk("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", | ||
164 | msr_lo, msr_tmp); | ||
165 | |||
166 | msr_tmp = (msr_lo >> 22) & 0x1f; | ||
167 | dprintk("bits 22-26 are 0x%x, speed is %u\n", | ||
168 | msr_tmp, (msr_tmp * fsb)); | ||
169 | |||
170 | ret = (msr_tmp * fsb); | ||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | |||
175 | static unsigned int pentium4_get_frequency(void) | ||
176 | { | ||
177 | struct cpuinfo_x86 *c = &boot_cpu_data; | ||
178 | u32 msr_lo, msr_hi, mult; | ||
179 | unsigned int fsb = 0; | ||
180 | unsigned int ret; | ||
181 | u8 fsb_code; | ||
182 | |||
183 | /* Pentium 4 Model 0 and 1 do not have the Core Clock Frequency | ||
184 | * to System Bus Frequency Ratio Field in the Processor Frequency | ||
185 | * Configuration Register of the MSR. Therefore the current | ||
186 | * frequency cannot be calculated and has to be measured. | ||
187 | */ | ||
188 | if (c->x86_model < 2) | ||
189 | return cpu_khz; | ||
190 | |||
191 | rdmsr(0x2c, msr_lo, msr_hi); | ||
192 | |||
193 | dprintk("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi); | ||
194 | |||
195 | /* decode the FSB: see IA-32 Intel (C) Architecture Software | ||
196 | * Developer's Manual, Volume 3: System Prgramming Guide, | ||
197 | * revision #12 in Table B-1: MSRs in the Pentium 4 and | ||
198 | * Intel Xeon Processors, on page B-4 and B-5. | ||
199 | */ | ||
200 | fsb_code = (msr_lo >> 16) & 0x7; | ||
201 | switch (fsb_code) { | ||
202 | case 0: | ||
203 | fsb = 100 * 1000; | ||
204 | break; | ||
205 | case 1: | ||
206 | fsb = 13333 * 10; | ||
207 | break; | ||
208 | case 2: | ||
209 | fsb = 200 * 1000; | ||
210 | break; | ||
211 | } | ||
212 | |||
213 | if (!fsb) | ||
214 | printk(KERN_DEBUG PFX "couldn't detect FSB speed. " | ||
215 | "Please send an e-mail to <linux@brodo.de>\n"); | ||
216 | |||
217 | /* Multiplier. */ | ||
218 | mult = msr_lo >> 24; | ||
219 | |||
220 | dprintk("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n", | ||
221 | fsb, mult, (fsb * mult)); | ||
222 | |||
223 | ret = (fsb * mult); | ||
224 | return ret; | ||
225 | } | ||
226 | |||
227 | |||
228 | /* Warning: may get called from smp_call_function_single. */ | ||
229 | unsigned int speedstep_get_frequency(enum speedstep_processor processor) | ||
230 | { | ||
231 | switch (processor) { | ||
232 | case SPEEDSTEP_CPU_PCORE: | ||
233 | return pentium_core_get_frequency(); | ||
234 | case SPEEDSTEP_CPU_PM: | ||
235 | return pentiumM_get_frequency(); | ||
236 | case SPEEDSTEP_CPU_P4D: | ||
237 | case SPEEDSTEP_CPU_P4M: | ||
238 | return pentium4_get_frequency(); | ||
239 | case SPEEDSTEP_CPU_PIII_T: | ||
240 | case SPEEDSTEP_CPU_PIII_C: | ||
241 | case SPEEDSTEP_CPU_PIII_C_EARLY: | ||
242 | return pentium3_get_frequency(processor); | ||
243 | default: | ||
244 | return 0; | ||
245 | }; | ||
246 | return 0; | ||
247 | } | ||
248 | EXPORT_SYMBOL_GPL(speedstep_get_frequency); | ||
249 | |||
250 | |||
251 | /********************************************************************* | ||
252 | * DETECT SPEEDSTEP-CAPABLE PROCESSOR * | ||
253 | *********************************************************************/ | ||
254 | |||
255 | unsigned int speedstep_detect_processor(void) | ||
256 | { | ||
257 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
258 | u32 ebx, msr_lo, msr_hi; | ||
259 | |||
260 | dprintk("x86: %x, model: %x\n", c->x86, c->x86_model); | ||
261 | |||
262 | if ((c->x86_vendor != X86_VENDOR_INTEL) || | ||
263 | ((c->x86 != 6) && (c->x86 != 0xF))) | ||
264 | return 0; | ||
265 | |||
266 | if (c->x86 == 0xF) { | ||
267 | /* Intel Mobile Pentium 4-M | ||
268 | * or Intel Mobile Pentium 4 with 533 MHz FSB */ | ||
269 | if (c->x86_model != 2) | ||
270 | return 0; | ||
271 | |||
272 | ebx = cpuid_ebx(0x00000001); | ||
273 | ebx &= 0x000000FF; | ||
274 | |||
275 | dprintk("ebx value is %x, x86_mask is %x\n", ebx, c->x86_mask); | ||
276 | |||
277 | switch (c->x86_mask) { | ||
278 | case 4: | ||
279 | /* | ||
280 | * B-stepping [M-P4-M] | ||
281 | * sample has ebx = 0x0f, production has 0x0e. | ||
282 | */ | ||
283 | if ((ebx == 0x0e) || (ebx == 0x0f)) | ||
284 | return SPEEDSTEP_CPU_P4M; | ||
285 | break; | ||
286 | case 7: | ||
287 | /* | ||
288 | * C-stepping [M-P4-M] | ||
289 | * needs to have ebx=0x0e, else it's a celeron: | ||
290 | * cf. 25130917.pdf / page 7, footnote 5 even | ||
291 | * though 25072120.pdf / page 7 doesn't say | ||
292 | * samples are only of B-stepping... | ||
293 | */ | ||
294 | if (ebx == 0x0e) | ||
295 | return SPEEDSTEP_CPU_P4M; | ||
296 | break; | ||
297 | case 9: | ||
298 | /* | ||
299 | * D-stepping [M-P4-M or M-P4/533] | ||
300 | * | ||
301 | * this is totally strange: CPUID 0x0F29 is | ||
302 | * used by M-P4-M, M-P4/533 and(!) Celeron CPUs. | ||
303 | * The latter need to be sorted out as they don't | ||
304 | * support speedstep. | ||
305 | * Celerons with CPUID 0x0F29 may have either | ||
306 | * ebx=0x8 or 0xf -- 25130917.pdf doesn't say anything | ||
307 | * specific. | ||
308 | * M-P4-Ms may have either ebx=0xe or 0xf [see above] | ||
309 | * M-P4/533 have either ebx=0xe or 0xf. [25317607.pdf] | ||
310 | * also, M-P4M HTs have ebx=0x8, too | ||
311 | * For now, they are distinguished by the model_id | ||
312 | * string | ||
313 | */ | ||
314 | if ((ebx == 0x0e) || | ||
315 | (strstr(c->x86_model_id, | ||
316 | "Mobile Intel(R) Pentium(R) 4") != NULL)) | ||
317 | return SPEEDSTEP_CPU_P4M; | ||
318 | break; | ||
319 | default: | ||
320 | break; | ||
321 | } | ||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | switch (c->x86_model) { | ||
326 | case 0x0B: /* Intel PIII [Tualatin] */ | ||
327 | /* cpuid_ebx(1) is 0x04 for desktop PIII, | ||
328 | * 0x06 for mobile PIII-M */ | ||
329 | ebx = cpuid_ebx(0x00000001); | ||
330 | dprintk("ebx is %x\n", ebx); | ||
331 | |||
332 | ebx &= 0x000000FF; | ||
333 | |||
334 | if (ebx != 0x06) | ||
335 | return 0; | ||
336 | |||
337 | /* So far all PIII-M processors support SpeedStep. See | ||
338 | * Intel's 24540640.pdf of June 2003 | ||
339 | */ | ||
340 | return SPEEDSTEP_CPU_PIII_T; | ||
341 | |||
342 | case 0x08: /* Intel PIII [Coppermine] */ | ||
343 | |||
344 | /* all mobile PIII Coppermines have FSB 100 MHz | ||
345 | * ==> sort out a few desktop PIIIs. */ | ||
346 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi); | ||
347 | dprintk("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n", | ||
348 | msr_lo, msr_hi); | ||
349 | msr_lo &= 0x00c0000; | ||
350 | if (msr_lo != 0x0080000) | ||
351 | return 0; | ||
352 | |||
353 | /* | ||
354 | * If the processor is a mobile version, | ||
355 | * platform ID has bit 50 set | ||
356 | * it has SpeedStep technology if either | ||
357 | * bit 56 or 57 is set | ||
358 | */ | ||
359 | rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi); | ||
360 | dprintk("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n", | ||
361 | msr_lo, msr_hi); | ||
362 | if ((msr_hi & (1<<18)) && | ||
363 | (relaxed_check ? 1 : (msr_hi & (3<<24)))) { | ||
364 | if (c->x86_mask == 0x01) { | ||
365 | dprintk("early PIII version\n"); | ||
366 | return SPEEDSTEP_CPU_PIII_C_EARLY; | ||
367 | } else | ||
368 | return SPEEDSTEP_CPU_PIII_C; | ||
369 | } | ||
370 | |||
371 | default: | ||
372 | return 0; | ||
373 | } | ||
374 | } | ||
375 | EXPORT_SYMBOL_GPL(speedstep_detect_processor); | ||
376 | |||
377 | |||
378 | /********************************************************************* | ||
379 | * DETECT SPEEDSTEP SPEEDS * | ||
380 | *********************************************************************/ | ||
381 | |||
382 | unsigned int speedstep_get_freqs(enum speedstep_processor processor, | ||
383 | unsigned int *low_speed, | ||
384 | unsigned int *high_speed, | ||
385 | unsigned int *transition_latency, | ||
386 | void (*set_state) (unsigned int state)) | ||
387 | { | ||
388 | unsigned int prev_speed; | ||
389 | unsigned int ret = 0; | ||
390 | unsigned long flags; | ||
391 | struct timeval tv1, tv2; | ||
392 | |||
393 | if ((!processor) || (!low_speed) || (!high_speed) || (!set_state)) | ||
394 | return -EINVAL; | ||
395 | |||
396 | dprintk("trying to determine both speeds\n"); | ||
397 | |||
398 | /* get current speed */ | ||
399 | prev_speed = speedstep_get_frequency(processor); | ||
400 | if (!prev_speed) | ||
401 | return -EIO; | ||
402 | |||
403 | dprintk("previous speed is %u\n", prev_speed); | ||
404 | |||
405 | local_irq_save(flags); | ||
406 | |||
407 | /* switch to low state */ | ||
408 | set_state(SPEEDSTEP_LOW); | ||
409 | *low_speed = speedstep_get_frequency(processor); | ||
410 | if (!*low_speed) { | ||
411 | ret = -EIO; | ||
412 | goto out; | ||
413 | } | ||
414 | |||
415 | dprintk("low speed is %u\n", *low_speed); | ||
416 | |||
417 | /* start latency measurement */ | ||
418 | if (transition_latency) | ||
419 | do_gettimeofday(&tv1); | ||
420 | |||
421 | /* switch to high state */ | ||
422 | set_state(SPEEDSTEP_HIGH); | ||
423 | |||
424 | /* end latency measurement */ | ||
425 | if (transition_latency) | ||
426 | do_gettimeofday(&tv2); | ||
427 | |||
428 | *high_speed = speedstep_get_frequency(processor); | ||
429 | if (!*high_speed) { | ||
430 | ret = -EIO; | ||
431 | goto out; | ||
432 | } | ||
433 | |||
434 | dprintk("high speed is %u\n", *high_speed); | ||
435 | |||
436 | if (*low_speed == *high_speed) { | ||
437 | ret = -ENODEV; | ||
438 | goto out; | ||
439 | } | ||
440 | |||
441 | /* switch to previous state, if necessary */ | ||
442 | if (*high_speed != prev_speed) | ||
443 | set_state(SPEEDSTEP_LOW); | ||
444 | |||
445 | if (transition_latency) { | ||
446 | *transition_latency = (tv2.tv_sec - tv1.tv_sec) * USEC_PER_SEC + | ||
447 | tv2.tv_usec - tv1.tv_usec; | ||
448 | dprintk("transition latency is %u uSec\n", *transition_latency); | ||
449 | |||
450 | /* convert uSec to nSec and add 20% for safety reasons */ | ||
451 | *transition_latency *= 1200; | ||
452 | |||
453 | /* check if the latency measurement is too high or too low | ||
454 | * and set it to a safe value (500uSec) in that case | ||
455 | */ | ||
456 | if (*transition_latency > 10000000 || | ||
457 | *transition_latency < 50000) { | ||
458 | printk(KERN_WARNING PFX "frequency transition " | ||
459 | "measured seems out of range (%u " | ||
460 | "nSec), falling back to a safe one of" | ||
461 | "%u nSec.\n", | ||
462 | *transition_latency, 500000); | ||
463 | *transition_latency = 500000; | ||
464 | } | ||
465 | } | ||
466 | |||
467 | out: | ||
468 | local_irq_restore(flags); | ||
469 | return ret; | ||
470 | } | ||
471 | EXPORT_SYMBOL_GPL(speedstep_get_freqs); | ||
472 | |||
473 | #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
474 | module_param(relaxed_check, int, 0444); | ||
475 | MODULE_PARM_DESC(relaxed_check, | ||
476 | "Don't do all checks for speedstep capability."); | ||
477 | #endif | ||
478 | |||
479 | MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); | ||
480 | MODULE_DESCRIPTION("Library for Intel SpeedStep 1 or 2 cpufreq drivers."); | ||
481 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h deleted file mode 100644 index 70d9cea1219d..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | /* | ||
2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * Library for common functions for Intel SpeedStep v.1 and v.2 support | ||
7 | * | ||
8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
9 | */ | ||
10 | |||
11 | |||
12 | |||
13 | /* processors */ | ||
14 | enum speedstep_processor { | ||
15 | SPEEDSTEP_CPU_PIII_C_EARLY = 0x00000001, /* Coppermine core */ | ||
16 | SPEEDSTEP_CPU_PIII_C = 0x00000002, /* Coppermine core */ | ||
17 | SPEEDSTEP_CPU_PIII_T = 0x00000003, /* Tualatin core */ | ||
18 | SPEEDSTEP_CPU_P4M = 0x00000004, /* P4-M */ | ||
19 | /* the following processors are not speedstep-capable and are not auto-detected | ||
20 | * in speedstep_detect_processor(). However, their speed can be detected using | ||
21 | * the speedstep_get_frequency() call. */ | ||
22 | SPEEDSTEP_CPU_PM = 0xFFFFFF03, /* Pentium M */ | ||
23 | SPEEDSTEP_CPU_P4D = 0xFFFFFF04, /* desktop P4 */ | ||
24 | SPEEDSTEP_CPU_PCORE = 0xFFFFFF05, /* Core */ | ||
25 | }; | ||
26 | |||
27 | /* speedstep states -- only two of them */ | ||
28 | |||
29 | #define SPEEDSTEP_HIGH 0x00000000 | ||
30 | #define SPEEDSTEP_LOW 0x00000001 | ||
31 | |||
32 | |||
33 | /* detect a speedstep-capable processor */ | ||
34 | extern enum speedstep_processor speedstep_detect_processor(void); | ||
35 | |||
36 | /* detect the current speed (in khz) of the processor */ | ||
37 | extern unsigned int speedstep_get_frequency(enum speedstep_processor processor); | ||
38 | |||
39 | |||
40 | /* detect the low and high speeds of the processor. The callback | ||
41 | * set_state"'s first argument is either SPEEDSTEP_HIGH or | ||
42 | * SPEEDSTEP_LOW; the second argument is zero so that no | ||
43 | * cpufreq_notify_transition calls are initiated. | ||
44 | */ | ||
45 | extern unsigned int speedstep_get_freqs(enum speedstep_processor processor, | ||
46 | unsigned int *low_speed, | ||
47 | unsigned int *high_speed, | ||
48 | unsigned int *transition_latency, | ||
49 | void (*set_state) (unsigned int state)); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c b/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c deleted file mode 100644 index 8abd869baabf..000000000000 --- a/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c +++ /dev/null | |||
@@ -1,467 +0,0 @@ | |||
1 | /* | ||
2 | * Intel SpeedStep SMI driver. | ||
3 | * | ||
4 | * (C) 2003 Hiroshi Miura <miura@da-cha.org> | ||
5 | * | ||
6 | * Licensed under the terms of the GNU GPL License version 2. | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | |||
11 | /********************************************************************* | ||
12 | * SPEEDSTEP - DEFINITIONS * | ||
13 | *********************************************************************/ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/moduleparam.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/cpufreq.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <asm/ist.h> | ||
23 | |||
24 | #include "speedstep-lib.h" | ||
25 | |||
26 | /* speedstep system management interface port/command. | ||
27 | * | ||
28 | * These parameters are got from IST-SMI BIOS call. | ||
29 | * If user gives it, these are used. | ||
30 | * | ||
31 | */ | ||
32 | static int smi_port; | ||
33 | static int smi_cmd; | ||
34 | static unsigned int smi_sig; | ||
35 | |||
36 | /* info about the processor */ | ||
37 | static enum speedstep_processor speedstep_processor; | ||
38 | |||
39 | /* | ||
40 | * There are only two frequency states for each processor. Values | ||
41 | * are in kHz for the time being. | ||
42 | */ | ||
43 | static struct cpufreq_frequency_table speedstep_freqs[] = { | ||
44 | {SPEEDSTEP_HIGH, 0}, | ||
45 | {SPEEDSTEP_LOW, 0}, | ||
46 | {0, CPUFREQ_TABLE_END}, | ||
47 | }; | ||
48 | |||
49 | #define GET_SPEEDSTEP_OWNER 0 | ||
50 | #define GET_SPEEDSTEP_STATE 1 | ||
51 | #define SET_SPEEDSTEP_STATE 2 | ||
52 | #define GET_SPEEDSTEP_FREQS 4 | ||
53 | |||
54 | /* how often shall the SMI call be tried if it failed, e.g. because | ||
55 | * of DMA activity going on? */ | ||
56 | #define SMI_TRIES 5 | ||
57 | |||
58 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | ||
59 | "speedstep-smi", msg) | ||
60 | |||
61 | /** | ||
62 | * speedstep_smi_ownership | ||
63 | */ | ||
64 | static int speedstep_smi_ownership(void) | ||
65 | { | ||
66 | u32 command, result, magic, dummy; | ||
67 | u32 function = GET_SPEEDSTEP_OWNER; | ||
68 | unsigned char magic_data[] = "Copyright (c) 1999 Intel Corporation"; | ||
69 | |||
70 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
71 | magic = virt_to_phys(magic_data); | ||
72 | |||
73 | dprintk("trying to obtain ownership with command %x at port %x\n", | ||
74 | command, smi_port); | ||
75 | |||
76 | __asm__ __volatile__( | ||
77 | "push %%ebp\n" | ||
78 | "out %%al, (%%dx)\n" | ||
79 | "pop %%ebp\n" | ||
80 | : "=D" (result), | ||
81 | "=a" (dummy), "=b" (dummy), "=c" (dummy), "=d" (dummy), | ||
82 | "=S" (dummy) | ||
83 | : "a" (command), "b" (function), "c" (0), "d" (smi_port), | ||
84 | "D" (0), "S" (magic) | ||
85 | : "memory" | ||
86 | ); | ||
87 | |||
88 | dprintk("result is %x\n", result); | ||
89 | |||
90 | return result; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * speedstep_smi_get_freqs - get SpeedStep preferred & current freq. | ||
95 | * @low: the low frequency value is placed here | ||
96 | * @high: the high frequency value is placed here | ||
97 | * | ||
98 | * Only available on later SpeedStep-enabled systems, returns false results or | ||
99 | * even hangs [cf. bugme.osdl.org # 1422] on earlier systems. Empirical testing | ||
100 | * shows that the latter occurs if !(ist_info.event & 0xFFFF). | ||
101 | */ | ||
102 | static int speedstep_smi_get_freqs(unsigned int *low, unsigned int *high) | ||
103 | { | ||
104 | u32 command, result = 0, edi, high_mhz, low_mhz, dummy; | ||
105 | u32 state = 0; | ||
106 | u32 function = GET_SPEEDSTEP_FREQS; | ||
107 | |||
108 | if (!(ist_info.event & 0xFFFF)) { | ||
109 | dprintk("bug #1422 -- can't read freqs from BIOS\n"); | ||
110 | return -ENODEV; | ||
111 | } | ||
112 | |||
113 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
114 | |||
115 | dprintk("trying to determine frequencies with command %x at port %x\n", | ||
116 | command, smi_port); | ||
117 | |||
118 | __asm__ __volatile__( | ||
119 | "push %%ebp\n" | ||
120 | "out %%al, (%%dx)\n" | ||
121 | "pop %%ebp" | ||
122 | : "=a" (result), | ||
123 | "=b" (high_mhz), | ||
124 | "=c" (low_mhz), | ||
125 | "=d" (state), "=D" (edi), "=S" (dummy) | ||
126 | : "a" (command), | ||
127 | "b" (function), | ||
128 | "c" (state), | ||
129 | "d" (smi_port), "S" (0), "D" (0) | ||
130 | ); | ||
131 | |||
132 | dprintk("result %x, low_freq %u, high_freq %u\n", | ||
133 | result, low_mhz, high_mhz); | ||
134 | |||
135 | /* abort if results are obviously incorrect... */ | ||
136 | if ((high_mhz + low_mhz) < 600) | ||
137 | return -EINVAL; | ||
138 | |||
139 | *high = high_mhz * 1000; | ||
140 | *low = low_mhz * 1000; | ||
141 | |||
142 | return result; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * speedstep_get_state - set the SpeedStep state | ||
147 | * @state: processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
148 | * | ||
149 | */ | ||
150 | static int speedstep_get_state(void) | ||
151 | { | ||
152 | u32 function = GET_SPEEDSTEP_STATE; | ||
153 | u32 result, state, edi, command, dummy; | ||
154 | |||
155 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
156 | |||
157 | dprintk("trying to determine current setting with command %x " | ||
158 | "at port %x\n", command, smi_port); | ||
159 | |||
160 | __asm__ __volatile__( | ||
161 | "push %%ebp\n" | ||
162 | "out %%al, (%%dx)\n" | ||
163 | "pop %%ebp\n" | ||
164 | : "=a" (result), | ||
165 | "=b" (state), "=D" (edi), | ||
166 | "=c" (dummy), "=d" (dummy), "=S" (dummy) | ||
167 | : "a" (command), "b" (function), "c" (0), | ||
168 | "d" (smi_port), "S" (0), "D" (0) | ||
169 | ); | ||
170 | |||
171 | dprintk("state is %x, result is %x\n", state, result); | ||
172 | |||
173 | return state & 1; | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * speedstep_set_state - set the SpeedStep state | ||
179 | * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
180 | * | ||
181 | */ | ||
182 | static void speedstep_set_state(unsigned int state) | ||
183 | { | ||
184 | unsigned int result = 0, command, new_state, dummy; | ||
185 | unsigned long flags; | ||
186 | unsigned int function = SET_SPEEDSTEP_STATE; | ||
187 | unsigned int retry = 0; | ||
188 | |||
189 | if (state > 0x1) | ||
190 | return; | ||
191 | |||
192 | /* Disable IRQs */ | ||
193 | local_irq_save(flags); | ||
194 | |||
195 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
196 | |||
197 | dprintk("trying to set frequency to state %u " | ||
198 | "with command %x at port %x\n", | ||
199 | state, command, smi_port); | ||
200 | |||
201 | do { | ||
202 | if (retry) { | ||
203 | dprintk("retry %u, previous result %u, waiting...\n", | ||
204 | retry, result); | ||
205 | mdelay(retry * 50); | ||
206 | } | ||
207 | retry++; | ||
208 | __asm__ __volatile__( | ||
209 | "push %%ebp\n" | ||
210 | "out %%al, (%%dx)\n" | ||
211 | "pop %%ebp" | ||
212 | : "=b" (new_state), "=D" (result), | ||
213 | "=c" (dummy), "=a" (dummy), | ||
214 | "=d" (dummy), "=S" (dummy) | ||
215 | : "a" (command), "b" (function), "c" (state), | ||
216 | "d" (smi_port), "S" (0), "D" (0) | ||
217 | ); | ||
218 | } while ((new_state != state) && (retry <= SMI_TRIES)); | ||
219 | |||
220 | /* enable IRQs */ | ||
221 | local_irq_restore(flags); | ||
222 | |||
223 | if (new_state == state) | ||
224 | dprintk("change to %u MHz succeeded after %u tries " | ||
225 | "with result %u\n", | ||
226 | (speedstep_freqs[new_state].frequency / 1000), | ||
227 | retry, result); | ||
228 | else | ||
229 | printk(KERN_ERR "cpufreq: change to state %u " | ||
230 | "failed with new_state %u and result %u\n", | ||
231 | state, new_state, result); | ||
232 | |||
233 | return; | ||
234 | } | ||
235 | |||
236 | |||
237 | /** | ||
238 | * speedstep_target - set a new CPUFreq policy | ||
239 | * @policy: new policy | ||
240 | * @target_freq: new freq | ||
241 | * @relation: | ||
242 | * | ||
243 | * Sets a new CPUFreq policy/freq. | ||
244 | */ | ||
245 | static int speedstep_target(struct cpufreq_policy *policy, | ||
246 | unsigned int target_freq, unsigned int relation) | ||
247 | { | ||
248 | unsigned int newstate = 0; | ||
249 | struct cpufreq_freqs freqs; | ||
250 | |||
251 | if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], | ||
252 | target_freq, relation, &newstate)) | ||
253 | return -EINVAL; | ||
254 | |||
255 | freqs.old = speedstep_freqs[speedstep_get_state()].frequency; | ||
256 | freqs.new = speedstep_freqs[newstate].frequency; | ||
257 | freqs.cpu = 0; /* speedstep.c is UP only driver */ | ||
258 | |||
259 | if (freqs.old == freqs.new) | ||
260 | return 0; | ||
261 | |||
262 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
263 | speedstep_set_state(newstate); | ||
264 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
265 | |||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | |||
270 | /** | ||
271 | * speedstep_verify - verifies a new CPUFreq policy | ||
272 | * @policy: new policy | ||
273 | * | ||
274 | * Limit must be within speedstep_low_freq and speedstep_high_freq, with | ||
275 | * at least one border included. | ||
276 | */ | ||
277 | static int speedstep_verify(struct cpufreq_policy *policy) | ||
278 | { | ||
279 | return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); | ||
280 | } | ||
281 | |||
282 | |||
283 | static int speedstep_cpu_init(struct cpufreq_policy *policy) | ||
284 | { | ||
285 | int result; | ||
286 | unsigned int speed, state; | ||
287 | unsigned int *low, *high; | ||
288 | |||
289 | /* capability check */ | ||
290 | if (policy->cpu != 0) | ||
291 | return -ENODEV; | ||
292 | |||
293 | result = speedstep_smi_ownership(); | ||
294 | if (result) { | ||
295 | dprintk("fails in aquiring ownership of a SMI interface.\n"); | ||
296 | return -EINVAL; | ||
297 | } | ||
298 | |||
299 | /* detect low and high frequency */ | ||
300 | low = &speedstep_freqs[SPEEDSTEP_LOW].frequency; | ||
301 | high = &speedstep_freqs[SPEEDSTEP_HIGH].frequency; | ||
302 | |||
303 | result = speedstep_smi_get_freqs(low, high); | ||
304 | if (result) { | ||
305 | /* fall back to speedstep_lib.c dection mechanism: | ||
306 | * try both states out */ | ||
307 | dprintk("could not detect low and high frequencies " | ||
308 | "by SMI call.\n"); | ||
309 | result = speedstep_get_freqs(speedstep_processor, | ||
310 | low, high, | ||
311 | NULL, | ||
312 | &speedstep_set_state); | ||
313 | |||
314 | if (result) { | ||
315 | dprintk("could not detect two different speeds" | ||
316 | " -- aborting.\n"); | ||
317 | return result; | ||
318 | } else | ||
319 | dprintk("workaround worked.\n"); | ||
320 | } | ||
321 | |||
322 | /* get current speed setting */ | ||
323 | state = speedstep_get_state(); | ||
324 | speed = speedstep_freqs[state].frequency; | ||
325 | |||
326 | dprintk("currently at %s speed setting - %i MHz\n", | ||
327 | (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) | ||
328 | ? "low" : "high", | ||
329 | (speed / 1000)); | ||
330 | |||
331 | /* cpuinfo and default policy values */ | ||
332 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
333 | policy->cur = speed; | ||
334 | |||
335 | result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); | ||
336 | if (result) | ||
337 | return result; | ||
338 | |||
339 | cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); | ||
340 | |||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | static int speedstep_cpu_exit(struct cpufreq_policy *policy) | ||
345 | { | ||
346 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
347 | return 0; | ||
348 | } | ||
349 | |||
350 | static unsigned int speedstep_get(unsigned int cpu) | ||
351 | { | ||
352 | if (cpu) | ||
353 | return -ENODEV; | ||
354 | return speedstep_get_frequency(speedstep_processor); | ||
355 | } | ||
356 | |||
357 | |||
358 | static int speedstep_resume(struct cpufreq_policy *policy) | ||
359 | { | ||
360 | int result = speedstep_smi_ownership(); | ||
361 | |||
362 | if (result) | ||
363 | dprintk("fails in re-aquiring ownership of a SMI interface.\n"); | ||
364 | |||
365 | return result; | ||
366 | } | ||
367 | |||
368 | static struct freq_attr *speedstep_attr[] = { | ||
369 | &cpufreq_freq_attr_scaling_available_freqs, | ||
370 | NULL, | ||
371 | }; | ||
372 | |||
373 | static struct cpufreq_driver speedstep_driver = { | ||
374 | .name = "speedstep-smi", | ||
375 | .verify = speedstep_verify, | ||
376 | .target = speedstep_target, | ||
377 | .init = speedstep_cpu_init, | ||
378 | .exit = speedstep_cpu_exit, | ||
379 | .get = speedstep_get, | ||
380 | .resume = speedstep_resume, | ||
381 | .owner = THIS_MODULE, | ||
382 | .attr = speedstep_attr, | ||
383 | }; | ||
384 | |||
385 | /** | ||
386 | * speedstep_init - initializes the SpeedStep CPUFreq driver | ||
387 | * | ||
388 | * Initializes the SpeedStep support. Returns -ENODEV on unsupported | ||
389 | * BIOS, -EINVAL on problems during initiatization, and zero on | ||
390 | * success. | ||
391 | */ | ||
392 | static int __init speedstep_init(void) | ||
393 | { | ||
394 | speedstep_processor = speedstep_detect_processor(); | ||
395 | |||
396 | switch (speedstep_processor) { | ||
397 | case SPEEDSTEP_CPU_PIII_T: | ||
398 | case SPEEDSTEP_CPU_PIII_C: | ||
399 | case SPEEDSTEP_CPU_PIII_C_EARLY: | ||
400 | break; | ||
401 | default: | ||
402 | speedstep_processor = 0; | ||
403 | } | ||
404 | |||
405 | if (!speedstep_processor) { | ||
406 | dprintk("No supported Intel CPU detected.\n"); | ||
407 | return -ENODEV; | ||
408 | } | ||
409 | |||
410 | dprintk("signature:0x%.8lx, command:0x%.8lx, " | ||
411 | "event:0x%.8lx, perf_level:0x%.8lx.\n", | ||
412 | ist_info.signature, ist_info.command, | ||
413 | ist_info.event, ist_info.perf_level); | ||
414 | |||
415 | /* Error if no IST-SMI BIOS or no PARM | ||
416 | sig= 'ISGE' aka 'Intel Speedstep Gate E' */ | ||
417 | if ((ist_info.signature != 0x47534943) && ( | ||
418 | (smi_port == 0) || (smi_cmd == 0))) | ||
419 | return -ENODEV; | ||
420 | |||
421 | if (smi_sig == 1) | ||
422 | smi_sig = 0x47534943; | ||
423 | else | ||
424 | smi_sig = ist_info.signature; | ||
425 | |||
426 | /* setup smi_port from MODLULE_PARM or BIOS */ | ||
427 | if ((smi_port > 0xff) || (smi_port < 0)) | ||
428 | return -EINVAL; | ||
429 | else if (smi_port == 0) | ||
430 | smi_port = ist_info.command & 0xff; | ||
431 | |||
432 | if ((smi_cmd > 0xff) || (smi_cmd < 0)) | ||
433 | return -EINVAL; | ||
434 | else if (smi_cmd == 0) | ||
435 | smi_cmd = (ist_info.command >> 16) & 0xff; | ||
436 | |||
437 | return cpufreq_register_driver(&speedstep_driver); | ||
438 | } | ||
439 | |||
440 | |||
441 | /** | ||
442 | * speedstep_exit - unregisters SpeedStep support | ||
443 | * | ||
444 | * Unregisters SpeedStep support. | ||
445 | */ | ||
446 | static void __exit speedstep_exit(void) | ||
447 | { | ||
448 | cpufreq_unregister_driver(&speedstep_driver); | ||
449 | } | ||
450 | |||
451 | module_param(smi_port, int, 0444); | ||
452 | module_param(smi_cmd, int, 0444); | ||
453 | module_param(smi_sig, uint, 0444); | ||
454 | |||
455 | MODULE_PARM_DESC(smi_port, "Override the BIOS-given IST port with this value " | ||
456 | "-- Intel's default setting is 0xb2"); | ||
457 | MODULE_PARM_DESC(smi_cmd, "Override the BIOS-given IST command with this value " | ||
458 | "-- Intel's default setting is 0x82"); | ||
459 | MODULE_PARM_DESC(smi_sig, "Set to 1 to fake the IST signature when using the " | ||
460 | "SMI interface."); | ||
461 | |||
462 | MODULE_AUTHOR("Hiroshi Miura"); | ||
463 | MODULE_DESCRIPTION("Speedstep driver for IST applet SMI interface."); | ||
464 | MODULE_LICENSE("GPL"); | ||
465 | |||
466 | module_init(speedstep_init); | ||
467 | module_exit(speedstep_exit); | ||
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index b4389441efbb..1edf5ba4fb2b 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c | |||
@@ -29,10 +29,10 @@ | |||
29 | 29 | ||
30 | static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) | 30 | static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) |
31 | { | 31 | { |
32 | u64 misc_enable; | ||
33 | |||
32 | /* Unmask CPUID levels if masked: */ | 34 | /* Unmask CPUID levels if masked: */ |
33 | if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) { | 35 | if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) { |
34 | u64 misc_enable; | ||
35 | |||
36 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); | 36 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); |
37 | 37 | ||
38 | if (misc_enable & MSR_IA32_MISC_ENABLE_LIMIT_CPUID) { | 38 | if (misc_enable & MSR_IA32_MISC_ENABLE_LIMIT_CPUID) { |
@@ -118,8 +118,6 @@ static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) | |||
118 | * (model 2) with the same problem. | 118 | * (model 2) with the same problem. |
119 | */ | 119 | */ |
120 | if (c->x86 == 15) { | 120 | if (c->x86 == 15) { |
121 | u64 misc_enable; | ||
122 | |||
123 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); | 121 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); |
124 | 122 | ||
125 | if (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING) { | 123 | if (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING) { |
@@ -130,6 +128,19 @@ static void __cpuinit early_init_intel(struct cpuinfo_x86 *c) | |||
130 | } | 128 | } |
131 | } | 129 | } |
132 | #endif | 130 | #endif |
131 | |||
132 | /* | ||
133 | * If fast string is not enabled in IA32_MISC_ENABLE for any reason, | ||
134 | * clear the fast string and enhanced fast string CPU capabilities. | ||
135 | */ | ||
136 | if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) { | ||
137 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable); | ||
138 | if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) { | ||
139 | printk(KERN_INFO "Disabled fast string operations\n"); | ||
140 | setup_clear_cpu_cap(X86_FEATURE_REP_GOOD); | ||
141 | setup_clear_cpu_cap(X86_FEATURE_ERMS); | ||
142 | } | ||
143 | } | ||
133 | } | 144 | } |
134 | 145 | ||
135 | #ifdef CONFIG_X86_32 | 146 | #ifdef CONFIG_X86_32 |
@@ -170,7 +181,7 @@ static void __cpuinit intel_smp_check(struct cpuinfo_x86 *c) | |||
170 | { | 181 | { |
171 | #ifdef CONFIG_SMP | 182 | #ifdef CONFIG_SMP |
172 | /* calling is from identify_secondary_cpu() ? */ | 183 | /* calling is from identify_secondary_cpu() ? */ |
173 | if (c->cpu_index == boot_cpu_id) | 184 | if (!c->cpu_index) |
174 | return; | 185 | return; |
175 | 186 | ||
176 | /* | 187 | /* |
@@ -276,17 +287,14 @@ static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c) | |||
276 | 287 | ||
277 | static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) | 288 | static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) |
278 | { | 289 | { |
279 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) | 290 | #ifdef CONFIG_NUMA |
280 | unsigned node; | 291 | unsigned node; |
281 | int cpu = smp_processor_id(); | 292 | int cpu = smp_processor_id(); |
282 | int apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid; | ||
283 | 293 | ||
284 | /* Don't do the funky fallback heuristics the AMD version employs | 294 | /* Don't do the funky fallback heuristics the AMD version employs |
285 | for now. */ | 295 | for now. */ |
286 | node = apicid_to_node[apicid]; | 296 | node = numa_cpu_node(cpu); |
287 | if (node == NUMA_NO_NODE) | 297 | if (node == NUMA_NO_NODE || !node_online(node)) { |
288 | node = first_node(node_online_map); | ||
289 | else if (!node_online(node)) { | ||
290 | /* reuse the value from init_cpu_to_node() */ | 298 | /* reuse the value from init_cpu_to_node() */ |
291 | node = cpu_to_node(cpu); | 299 | node = cpu_to_node(cpu); |
292 | } | 300 | } |
@@ -403,12 +411,10 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c) | |||
403 | 411 | ||
404 | switch (c->x86_model) { | 412 | switch (c->x86_model) { |
405 | case 5: | 413 | case 5: |
406 | if (c->x86_mask == 0) { | 414 | if (l2 == 0) |
407 | if (l2 == 0) | 415 | p = "Celeron (Covington)"; |
408 | p = "Celeron (Covington)"; | 416 | else if (l2 == 256) |
409 | else if (l2 == 256) | 417 | p = "Mobile Pentium II (Dixon)"; |
410 | p = "Mobile Pentium II (Dixon)"; | ||
411 | } | ||
412 | break; | 418 | break; |
413 | 419 | ||
414 | case 6: | 420 | case 6: |
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c index 3fec7d9bfd62..0bf12644aa73 100644 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c | |||
@@ -17,7 +17,7 @@ | |||
17 | 17 | ||
18 | #include <asm/processor.h> | 18 | #include <asm/processor.h> |
19 | #include <linux/smp.h> | 19 | #include <linux/smp.h> |
20 | #include <asm/k8.h> | 20 | #include <asm/amd_nb.h> |
21 | #include <asm/smp.h> | 21 | #include <asm/smp.h> |
22 | 22 | ||
23 | #define LVL_1_INST 1 | 23 | #define LVL_1_INST 1 |
@@ -45,6 +45,7 @@ static const struct _cache_table __cpuinitconst cache_table[] = | |||
45 | { 0x0a, LVL_1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */ | 45 | { 0x0a, LVL_1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */ |
46 | { 0x0c, LVL_1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */ | 46 | { 0x0c, LVL_1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */ |
47 | { 0x0d, LVL_1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */ | 47 | { 0x0d, LVL_1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */ |
48 | { 0x0e, LVL_1_DATA, 24 }, /* 6-way set assoc, 64 byte line size */ | ||
48 | { 0x21, LVL_2, 256 }, /* 8-way set assoc, 64 byte line size */ | 49 | { 0x21, LVL_2, 256 }, /* 8-way set assoc, 64 byte line size */ |
49 | { 0x22, LVL_3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */ | 50 | { 0x22, LVL_3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */ |
50 | { 0x23, LVL_3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */ | 51 | { 0x23, LVL_3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */ |
@@ -66,6 +67,7 @@ static const struct _cache_table __cpuinitconst cache_table[] = | |||
66 | { 0x45, LVL_2, MB(2) }, /* 4-way set assoc, 32 byte line size */ | 67 | { 0x45, LVL_2, MB(2) }, /* 4-way set assoc, 32 byte line size */ |
67 | { 0x46, LVL_3, MB(4) }, /* 4-way set assoc, 64 byte line size */ | 68 | { 0x46, LVL_3, MB(4) }, /* 4-way set assoc, 64 byte line size */ |
68 | { 0x47, LVL_3, MB(8) }, /* 8-way set assoc, 64 byte line size */ | 69 | { 0x47, LVL_3, MB(8) }, /* 8-way set assoc, 64 byte line size */ |
70 | { 0x48, LVL_2, MB(3) }, /* 12-way set assoc, 64 byte line size */ | ||
69 | { 0x49, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */ | 71 | { 0x49, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */ |
70 | { 0x4a, LVL_3, MB(6) }, /* 12-way set assoc, 64 byte line size */ | 72 | { 0x4a, LVL_3, MB(6) }, /* 12-way set assoc, 64 byte line size */ |
71 | { 0x4b, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */ | 73 | { 0x4b, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */ |
@@ -87,6 +89,7 @@ static const struct _cache_table __cpuinitconst cache_table[] = | |||
87 | { 0x7c, LVL_2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */ | 89 | { 0x7c, LVL_2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */ |
88 | { 0x7d, LVL_2, MB(2) }, /* 8-way set assoc, 64 byte line size */ | 90 | { 0x7d, LVL_2, MB(2) }, /* 8-way set assoc, 64 byte line size */ |
89 | { 0x7f, LVL_2, 512 }, /* 2-way set assoc, 64 byte line size */ | 91 | { 0x7f, LVL_2, 512 }, /* 2-way set assoc, 64 byte line size */ |
92 | { 0x80, LVL_2, 512 }, /* 8-way set assoc, 64 byte line size */ | ||
90 | { 0x82, LVL_2, 256 }, /* 8-way set assoc, 32 byte line size */ | 93 | { 0x82, LVL_2, 256 }, /* 8-way set assoc, 32 byte line size */ |
91 | { 0x83, LVL_2, 512 }, /* 8-way set assoc, 32 byte line size */ | 94 | { 0x83, LVL_2, 512 }, /* 8-way set assoc, 32 byte line size */ |
92 | { 0x84, LVL_2, MB(1) }, /* 8-way set assoc, 32 byte line size */ | 95 | { 0x84, LVL_2, MB(1) }, /* 8-way set assoc, 32 byte line size */ |
@@ -149,8 +152,7 @@ union _cpuid4_leaf_ecx { | |||
149 | }; | 152 | }; |
150 | 153 | ||
151 | struct amd_l3_cache { | 154 | struct amd_l3_cache { |
152 | struct pci_dev *dev; | 155 | struct amd_northbridge *nb; |
153 | bool can_disable; | ||
154 | unsigned indices; | 156 | unsigned indices; |
155 | u8 subcaches[4]; | 157 | u8 subcaches[4]; |
156 | }; | 158 | }; |
@@ -266,7 +268,7 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, | |||
266 | line_size = l2.line_size; | 268 | line_size = l2.line_size; |
267 | lines_per_tag = l2.lines_per_tag; | 269 | lines_per_tag = l2.lines_per_tag; |
268 | /* cpu_data has errata corrections for K7 applied */ | 270 | /* cpu_data has errata corrections for K7 applied */ |
269 | size_in_kb = current_cpu_data.x86_cache_size; | 271 | size_in_kb = __this_cpu_read(cpu_info.x86_cache_size); |
270 | break; | 272 | break; |
271 | case 3: | 273 | case 3: |
272 | if (!l3.val) | 274 | if (!l3.val) |
@@ -288,7 +290,7 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, | |||
288 | eax->split.type = types[leaf]; | 290 | eax->split.type = types[leaf]; |
289 | eax->split.level = levels[leaf]; | 291 | eax->split.level = levels[leaf]; |
290 | eax->split.num_threads_sharing = 0; | 292 | eax->split.num_threads_sharing = 0; |
291 | eax->split.num_cores_on_die = current_cpu_data.x86_max_cores - 1; | 293 | eax->split.num_cores_on_die = __this_cpu_read(cpu_info.x86_max_cores) - 1; |
292 | 294 | ||
293 | 295 | ||
294 | if (assoc == 0xffff) | 296 | if (assoc == 0xffff) |
@@ -302,23 +304,22 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, | |||
302 | 304 | ||
303 | struct _cache_attr { | 305 | struct _cache_attr { |
304 | struct attribute attr; | 306 | struct attribute attr; |
305 | ssize_t (*show)(struct _cpuid4_info *, char *); | 307 | ssize_t (*show)(struct _cpuid4_info *, char *, unsigned int); |
306 | ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count); | 308 | ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count, |
309 | unsigned int); | ||
307 | }; | 310 | }; |
308 | 311 | ||
309 | #ifdef CONFIG_CPU_SUP_AMD | 312 | #ifdef CONFIG_AMD_NB |
310 | 313 | ||
311 | /* | 314 | /* |
312 | * L3 cache descriptors | 315 | * L3 cache descriptors |
313 | */ | 316 | */ |
314 | static struct amd_l3_cache **__cpuinitdata l3_caches; | ||
315 | |||
316 | static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3) | 317 | static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3) |
317 | { | 318 | { |
318 | unsigned int sc0, sc1, sc2, sc3; | 319 | unsigned int sc0, sc1, sc2, sc3; |
319 | u32 val = 0; | 320 | u32 val = 0; |
320 | 321 | ||
321 | pci_read_config_dword(l3->dev, 0x1C4, &val); | 322 | pci_read_config_dword(l3->nb->misc, 0x1C4, &val); |
322 | 323 | ||
323 | /* calculate subcache sizes */ | 324 | /* calculate subcache sizes */ |
324 | l3->subcaches[0] = sc0 = !(val & BIT(0)); | 325 | l3->subcaches[0] = sc0 = !(val & BIT(0)); |
@@ -326,50 +327,17 @@ static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3) | |||
326 | l3->subcaches[2] = sc2 = !(val & BIT(8)) + !(val & BIT(9)); | 327 | l3->subcaches[2] = sc2 = !(val & BIT(8)) + !(val & BIT(9)); |
327 | l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13)); | 328 | l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13)); |
328 | 329 | ||
329 | l3->indices = (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1; | 330 | l3->indices = (max(max3(sc0, sc1, sc2), sc3) << 10) - 1; |
330 | } | ||
331 | |||
332 | static struct amd_l3_cache * __cpuinit amd_init_l3_cache(int node) | ||
333 | { | ||
334 | struct amd_l3_cache *l3; | ||
335 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
336 | |||
337 | l3 = kzalloc(sizeof(struct amd_l3_cache), GFP_ATOMIC); | ||
338 | if (!l3) { | ||
339 | printk(KERN_WARNING "Error allocating L3 struct\n"); | ||
340 | return NULL; | ||
341 | } | ||
342 | |||
343 | l3->dev = dev; | ||
344 | |||
345 | amd_calc_l3_indices(l3); | ||
346 | |||
347 | return l3; | ||
348 | } | 331 | } |
349 | 332 | ||
350 | static void __cpuinit amd_check_l3_disable(struct _cpuid4_info_regs *this_leaf, | 333 | static void __cpuinit amd_init_l3_cache(struct _cpuid4_info_regs *this_leaf, |
351 | int index) | 334 | int index) |
352 | { | 335 | { |
336 | static struct amd_l3_cache *__cpuinitdata l3_caches; | ||
353 | int node; | 337 | int node; |
354 | 338 | ||
355 | if (boot_cpu_data.x86 != 0x10) | 339 | /* only for L3, and not in virtualized environments */ |
356 | return; | 340 | if (index < 3 || amd_nb_num() == 0) |
357 | |||
358 | if (index < 3) | ||
359 | return; | ||
360 | |||
361 | /* see errata #382 and #388 */ | ||
362 | if (boot_cpu_data.x86_model < 0x8) | ||
363 | return; | ||
364 | |||
365 | if ((boot_cpu_data.x86_model == 0x8 || | ||
366 | boot_cpu_data.x86_model == 0x9) | ||
367 | && | ||
368 | boot_cpu_data.x86_mask < 0x1) | ||
369 | return; | ||
370 | |||
371 | /* not in virtualized environments */ | ||
372 | if (num_k8_northbridges == 0) | ||
373 | return; | 341 | return; |
374 | 342 | ||
375 | /* | 343 | /* |
@@ -377,7 +345,7 @@ static void __cpuinit amd_check_l3_disable(struct _cpuid4_info_regs *this_leaf, | |||
377 | * never freed but this is done only on shutdown so it doesn't matter. | 345 | * never freed but this is done only on shutdown so it doesn't matter. |
378 | */ | 346 | */ |
379 | if (!l3_caches) { | 347 | if (!l3_caches) { |
380 | int size = num_k8_northbridges * sizeof(struct amd_l3_cache *); | 348 | int size = amd_nb_num() * sizeof(struct amd_l3_cache); |
381 | 349 | ||
382 | l3_caches = kzalloc(size, GFP_ATOMIC); | 350 | l3_caches = kzalloc(size, GFP_ATOMIC); |
383 | if (!l3_caches) | 351 | if (!l3_caches) |
@@ -386,14 +354,12 @@ static void __cpuinit amd_check_l3_disable(struct _cpuid4_info_regs *this_leaf, | |||
386 | 354 | ||
387 | node = amd_get_nb_id(smp_processor_id()); | 355 | node = amd_get_nb_id(smp_processor_id()); |
388 | 356 | ||
389 | if (!l3_caches[node]) { | 357 | if (!l3_caches[node].nb) { |
390 | l3_caches[node] = amd_init_l3_cache(node); | 358 | l3_caches[node].nb = node_to_amd_nb(node); |
391 | l3_caches[node]->can_disable = true; | 359 | amd_calc_l3_indices(&l3_caches[node]); |
392 | } | 360 | } |
393 | 361 | ||
394 | WARN_ON(!l3_caches[node]); | 362 | this_leaf->l3 = &l3_caches[node]; |
395 | |||
396 | this_leaf->l3 = l3_caches[node]; | ||
397 | } | 363 | } |
398 | 364 | ||
399 | /* | 365 | /* |
@@ -407,7 +373,7 @@ int amd_get_l3_disable_slot(struct amd_l3_cache *l3, unsigned slot) | |||
407 | { | 373 | { |
408 | unsigned int reg = 0; | 374 | unsigned int reg = 0; |
409 | 375 | ||
410 | pci_read_config_dword(l3->dev, 0x1BC + slot * 4, ®); | 376 | pci_read_config_dword(l3->nb->misc, 0x1BC + slot * 4, ®); |
411 | 377 | ||
412 | /* check whether this slot is activated already */ | 378 | /* check whether this slot is activated already */ |
413 | if (reg & (3UL << 30)) | 379 | if (reg & (3UL << 30)) |
@@ -421,7 +387,8 @@ static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, | |||
421 | { | 387 | { |
422 | int index; | 388 | int index; |
423 | 389 | ||
424 | if (!this_leaf->l3 || !this_leaf->l3->can_disable) | 390 | if (!this_leaf->l3 || |
391 | !amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) | ||
425 | return -EINVAL; | 392 | return -EINVAL; |
426 | 393 | ||
427 | index = amd_get_l3_disable_slot(this_leaf->l3, slot); | 394 | index = amd_get_l3_disable_slot(this_leaf->l3, slot); |
@@ -433,7 +400,8 @@ static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, | |||
433 | 400 | ||
434 | #define SHOW_CACHE_DISABLE(slot) \ | 401 | #define SHOW_CACHE_DISABLE(slot) \ |
435 | static ssize_t \ | 402 | static ssize_t \ |
436 | show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf) \ | 403 | show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf, \ |
404 | unsigned int cpu) \ | ||
437 | { \ | 405 | { \ |
438 | return show_cache_disable(this_leaf, buf, slot); \ | 406 | return show_cache_disable(this_leaf, buf, slot); \ |
439 | } | 407 | } |
@@ -456,7 +424,7 @@ static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu, | |||
456 | if (!l3->subcaches[i]) | 424 | if (!l3->subcaches[i]) |
457 | continue; | 425 | continue; |
458 | 426 | ||
459 | pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg); | 427 | pci_write_config_dword(l3->nb->misc, 0x1BC + slot * 4, reg); |
460 | 428 | ||
461 | /* | 429 | /* |
462 | * We need to WBINVD on a core on the node containing the L3 | 430 | * We need to WBINVD on a core on the node containing the L3 |
@@ -466,7 +434,7 @@ static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu, | |||
466 | wbinvd_on_cpu(cpu); | 434 | wbinvd_on_cpu(cpu); |
467 | 435 | ||
468 | reg |= BIT(31); | 436 | reg |= BIT(31); |
469 | pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg); | 437 | pci_write_config_dword(l3->nb->misc, 0x1BC + slot * 4, reg); |
470 | } | 438 | } |
471 | } | 439 | } |
472 | 440 | ||
@@ -485,27 +453,16 @@ int amd_set_l3_disable_slot(struct amd_l3_cache *l3, int cpu, unsigned slot, | |||
485 | { | 453 | { |
486 | int ret = 0; | 454 | int ret = 0; |
487 | 455 | ||
488 | #define SUBCACHE_MASK (3UL << 20) | 456 | /* check if @slot is already used or the index is already disabled */ |
489 | #define SUBCACHE_INDEX 0xfff | ||
490 | |||
491 | /* | ||
492 | * check whether this slot is already used or | ||
493 | * the index is already disabled | ||
494 | */ | ||
495 | ret = amd_get_l3_disable_slot(l3, slot); | 457 | ret = amd_get_l3_disable_slot(l3, slot); |
496 | if (ret >= 0) | 458 | if (ret >= 0) |
497 | return -EINVAL; | 459 | return -EINVAL; |
498 | 460 | ||
499 | /* | 461 | if (index > l3->indices) |
500 | * check whether the other slot has disabled the | ||
501 | * same index already | ||
502 | */ | ||
503 | if (index == amd_get_l3_disable_slot(l3, !slot)) | ||
504 | return -EINVAL; | 462 | return -EINVAL; |
505 | 463 | ||
506 | /* do not allow writes outside of allowed bits */ | 464 | /* check whether the other slot has disabled the same index already */ |
507 | if ((index & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) || | 465 | if (index == amd_get_l3_disable_slot(l3, !slot)) |
508 | ((index & SUBCACHE_INDEX) > l3->indices)) | ||
509 | return -EINVAL; | 466 | return -EINVAL; |
510 | 467 | ||
511 | amd_l3_disable_index(l3, cpu, slot, index); | 468 | amd_l3_disable_index(l3, cpu, slot, index); |
@@ -523,7 +480,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, | |||
523 | if (!capable(CAP_SYS_ADMIN)) | 480 | if (!capable(CAP_SYS_ADMIN)) |
524 | return -EPERM; | 481 | return -EPERM; |
525 | 482 | ||
526 | if (!this_leaf->l3 || !this_leaf->l3->can_disable) | 483 | if (!this_leaf->l3 || |
484 | !amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) | ||
527 | return -EINVAL; | 485 | return -EINVAL; |
528 | 486 | ||
529 | cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | 487 | cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); |
@@ -544,7 +502,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, | |||
544 | #define STORE_CACHE_DISABLE(slot) \ | 502 | #define STORE_CACHE_DISABLE(slot) \ |
545 | static ssize_t \ | 503 | static ssize_t \ |
546 | store_cache_disable_##slot(struct _cpuid4_info *this_leaf, \ | 504 | store_cache_disable_##slot(struct _cpuid4_info *this_leaf, \ |
547 | const char *buf, size_t count) \ | 505 | const char *buf, size_t count, \ |
506 | unsigned int cpu) \ | ||
548 | { \ | 507 | { \ |
549 | return store_cache_disable(this_leaf, buf, count, slot); \ | 508 | return store_cache_disable(this_leaf, buf, count, slot); \ |
550 | } | 509 | } |
@@ -556,25 +515,55 @@ static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644, | |||
556 | static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644, | 515 | static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644, |
557 | show_cache_disable_1, store_cache_disable_1); | 516 | show_cache_disable_1, store_cache_disable_1); |
558 | 517 | ||
559 | #else /* CONFIG_CPU_SUP_AMD */ | 518 | static ssize_t |
560 | static void __cpuinit | 519 | show_subcaches(struct _cpuid4_info *this_leaf, char *buf, unsigned int cpu) |
561 | amd_check_l3_disable(struct _cpuid4_info_regs *this_leaf, int index) | ||
562 | { | 520 | { |
563 | }; | 521 | if (!this_leaf->l3 || !amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) |
564 | #endif /* CONFIG_CPU_SUP_AMD */ | 522 | return -EINVAL; |
523 | |||
524 | return sprintf(buf, "%x\n", amd_get_subcaches(cpu)); | ||
525 | } | ||
526 | |||
527 | static ssize_t | ||
528 | store_subcaches(struct _cpuid4_info *this_leaf, const char *buf, size_t count, | ||
529 | unsigned int cpu) | ||
530 | { | ||
531 | unsigned long val; | ||
532 | |||
533 | if (!capable(CAP_SYS_ADMIN)) | ||
534 | return -EPERM; | ||
535 | |||
536 | if (!this_leaf->l3 || !amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) | ||
537 | return -EINVAL; | ||
538 | |||
539 | if (strict_strtoul(buf, 16, &val) < 0) | ||
540 | return -EINVAL; | ||
541 | |||
542 | if (amd_set_subcaches(cpu, val)) | ||
543 | return -EINVAL; | ||
544 | |||
545 | return count; | ||
546 | } | ||
547 | |||
548 | static struct _cache_attr subcaches = | ||
549 | __ATTR(subcaches, 0644, show_subcaches, store_subcaches); | ||
550 | |||
551 | #else /* CONFIG_AMD_NB */ | ||
552 | #define amd_init_l3_cache(x, y) | ||
553 | #endif /* CONFIG_AMD_NB */ | ||
565 | 554 | ||
566 | static int | 555 | static int |
567 | __cpuinit cpuid4_cache_lookup_regs(int index, | 556 | __cpuinit cpuid4_cache_lookup_regs(int index, |
568 | struct _cpuid4_info_regs *this_leaf) | 557 | struct _cpuid4_info_regs *this_leaf) |
569 | { | 558 | { |
570 | union _cpuid4_leaf_eax eax; | 559 | union _cpuid4_leaf_eax eax; |
571 | union _cpuid4_leaf_ebx ebx; | 560 | union _cpuid4_leaf_ebx ebx; |
572 | union _cpuid4_leaf_ecx ecx; | 561 | union _cpuid4_leaf_ecx ecx; |
573 | unsigned edx; | 562 | unsigned edx; |
574 | 563 | ||
575 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { | 564 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { |
576 | amd_cpuid4(index, &eax, &ebx, &ecx); | 565 | amd_cpuid4(index, &eax, &ebx, &ecx); |
577 | amd_check_l3_disable(this_leaf, index); | 566 | amd_init_l3_cache(this_leaf, index); |
578 | } else { | 567 | } else { |
579 | cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); | 568 | cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); |
580 | } | 569 | } |
@@ -784,11 +773,11 @@ static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index) | |||
784 | struct cpuinfo_x86 *c = &cpu_data(cpu); | 773 | struct cpuinfo_x86 *c = &cpu_data(cpu); |
785 | 774 | ||
786 | if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) { | 775 | if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) { |
787 | for_each_cpu(i, c->llc_shared_map) { | 776 | for_each_cpu(i, cpu_llc_shared_mask(cpu)) { |
788 | if (!per_cpu(ici_cpuid4_info, i)) | 777 | if (!per_cpu(ici_cpuid4_info, i)) |
789 | continue; | 778 | continue; |
790 | this_leaf = CPUID4_INFO_IDX(i, index); | 779 | this_leaf = CPUID4_INFO_IDX(i, index); |
791 | for_each_cpu(sibling, c->llc_shared_map) { | 780 | for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) { |
792 | if (!cpu_online(sibling)) | 781 | if (!cpu_online(sibling)) |
793 | continue; | 782 | continue; |
794 | set_bit(sibling, this_leaf->shared_cpu_map); | 783 | set_bit(sibling, this_leaf->shared_cpu_map); |
@@ -922,8 +911,8 @@ static DEFINE_PER_CPU(struct _index_kobject *, ici_index_kobject); | |||
922 | #define INDEX_KOBJECT_PTR(x, y) (&((per_cpu(ici_index_kobject, x))[y])) | 911 | #define INDEX_KOBJECT_PTR(x, y) (&((per_cpu(ici_index_kobject, x))[y])) |
923 | 912 | ||
924 | #define show_one_plus(file_name, object, val) \ | 913 | #define show_one_plus(file_name, object, val) \ |
925 | static ssize_t show_##file_name \ | 914 | static ssize_t show_##file_name(struct _cpuid4_info *this_leaf, char *buf, \ |
926 | (struct _cpuid4_info *this_leaf, char *buf) \ | 915 | unsigned int cpu) \ |
927 | { \ | 916 | { \ |
928 | return sprintf(buf, "%lu\n", (unsigned long)this_leaf->object + val); \ | 917 | return sprintf(buf, "%lu\n", (unsigned long)this_leaf->object + val); \ |
929 | } | 918 | } |
@@ -934,7 +923,8 @@ show_one_plus(physical_line_partition, ebx.split.physical_line_partition, 1); | |||
934 | show_one_plus(ways_of_associativity, ebx.split.ways_of_associativity, 1); | 923 | show_one_plus(ways_of_associativity, ebx.split.ways_of_associativity, 1); |
935 | show_one_plus(number_of_sets, ecx.split.number_of_sets, 1); | 924 | show_one_plus(number_of_sets, ecx.split.number_of_sets, 1); |
936 | 925 | ||
937 | static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf) | 926 | static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf, |
927 | unsigned int cpu) | ||
938 | { | 928 | { |
939 | return sprintf(buf, "%luK\n", this_leaf->size / 1024); | 929 | return sprintf(buf, "%luK\n", this_leaf->size / 1024); |
940 | } | 930 | } |
@@ -958,17 +948,20 @@ static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf, | |||
958 | return n; | 948 | return n; |
959 | } | 949 | } |
960 | 950 | ||
961 | static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf) | 951 | static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf, |
952 | unsigned int cpu) | ||
962 | { | 953 | { |
963 | return show_shared_cpu_map_func(leaf, 0, buf); | 954 | return show_shared_cpu_map_func(leaf, 0, buf); |
964 | } | 955 | } |
965 | 956 | ||
966 | static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf) | 957 | static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf, |
958 | unsigned int cpu) | ||
967 | { | 959 | { |
968 | return show_shared_cpu_map_func(leaf, 1, buf); | 960 | return show_shared_cpu_map_func(leaf, 1, buf); |
969 | } | 961 | } |
970 | 962 | ||
971 | static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf) | 963 | static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf, |
964 | unsigned int cpu) | ||
972 | { | 965 | { |
973 | switch (this_leaf->eax.split.type) { | 966 | switch (this_leaf->eax.split.type) { |
974 | case CACHE_TYPE_DATA: | 967 | case CACHE_TYPE_DATA: |
@@ -999,30 +992,54 @@ define_one_ro(size); | |||
999 | define_one_ro(shared_cpu_map); | 992 | define_one_ro(shared_cpu_map); |
1000 | define_one_ro(shared_cpu_list); | 993 | define_one_ro(shared_cpu_list); |
1001 | 994 | ||
1002 | #define DEFAULT_SYSFS_CACHE_ATTRS \ | ||
1003 | &type.attr, \ | ||
1004 | &level.attr, \ | ||
1005 | &coherency_line_size.attr, \ | ||
1006 | &physical_line_partition.attr, \ | ||
1007 | &ways_of_associativity.attr, \ | ||
1008 | &number_of_sets.attr, \ | ||
1009 | &size.attr, \ | ||
1010 | &shared_cpu_map.attr, \ | ||
1011 | &shared_cpu_list.attr | ||
1012 | |||
1013 | static struct attribute *default_attrs[] = { | 995 | static struct attribute *default_attrs[] = { |
1014 | DEFAULT_SYSFS_CACHE_ATTRS, | 996 | &type.attr, |
997 | &level.attr, | ||
998 | &coherency_line_size.attr, | ||
999 | &physical_line_partition.attr, | ||
1000 | &ways_of_associativity.attr, | ||
1001 | &number_of_sets.attr, | ||
1002 | &size.attr, | ||
1003 | &shared_cpu_map.attr, | ||
1004 | &shared_cpu_list.attr, | ||
1015 | NULL | 1005 | NULL |
1016 | }; | 1006 | }; |
1017 | 1007 | ||
1018 | static struct attribute *default_l3_attrs[] = { | 1008 | #ifdef CONFIG_AMD_NB |
1019 | DEFAULT_SYSFS_CACHE_ATTRS, | 1009 | static struct attribute ** __cpuinit amd_l3_attrs(void) |
1020 | #ifdef CONFIG_CPU_SUP_AMD | 1010 | { |
1021 | &cache_disable_0.attr, | 1011 | static struct attribute **attrs; |
1022 | &cache_disable_1.attr, | 1012 | int n; |
1013 | |||
1014 | if (attrs) | ||
1015 | return attrs; | ||
1016 | |||
1017 | n = sizeof (default_attrs) / sizeof (struct attribute *); | ||
1018 | |||
1019 | if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) | ||
1020 | n += 2; | ||
1021 | |||
1022 | if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) | ||
1023 | n += 1; | ||
1024 | |||
1025 | attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL); | ||
1026 | if (attrs == NULL) | ||
1027 | return attrs = default_attrs; | ||
1028 | |||
1029 | for (n = 0; default_attrs[n]; n++) | ||
1030 | attrs[n] = default_attrs[n]; | ||
1031 | |||
1032 | if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) { | ||
1033 | attrs[n++] = &cache_disable_0.attr; | ||
1034 | attrs[n++] = &cache_disable_1.attr; | ||
1035 | } | ||
1036 | |||
1037 | if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) | ||
1038 | attrs[n++] = &subcaches.attr; | ||
1039 | |||
1040 | return attrs; | ||
1041 | } | ||
1023 | #endif | 1042 | #endif |
1024 | NULL | ||
1025 | }; | ||
1026 | 1043 | ||
1027 | static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) | 1044 | static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) |
1028 | { | 1045 | { |
@@ -1032,7 +1049,7 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) | |||
1032 | 1049 | ||
1033 | ret = fattr->show ? | 1050 | ret = fattr->show ? |
1034 | fattr->show(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index), | 1051 | fattr->show(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index), |
1035 | buf) : | 1052 | buf, this_leaf->cpu) : |
1036 | 0; | 1053 | 0; |
1037 | return ret; | 1054 | return ret; |
1038 | } | 1055 | } |
@@ -1046,7 +1063,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, | |||
1046 | 1063 | ||
1047 | ret = fattr->store ? | 1064 | ret = fattr->store ? |
1048 | fattr->store(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index), | 1065 | fattr->store(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index), |
1049 | buf, count) : | 1066 | buf, count, this_leaf->cpu) : |
1050 | 0; | 1067 | 0; |
1051 | return ret; | 1068 | return ret; |
1052 | } | 1069 | } |
@@ -1133,11 +1150,11 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) | |||
1133 | 1150 | ||
1134 | this_leaf = CPUID4_INFO_IDX(cpu, i); | 1151 | this_leaf = CPUID4_INFO_IDX(cpu, i); |
1135 | 1152 | ||
1136 | if (this_leaf->l3 && this_leaf->l3->can_disable) | 1153 | ktype_cache.default_attrs = default_attrs; |
1137 | ktype_cache.default_attrs = default_l3_attrs; | 1154 | #ifdef CONFIG_AMD_NB |
1138 | else | 1155 | if (this_leaf->l3) |
1139 | ktype_cache.default_attrs = default_attrs; | 1156 | ktype_cache.default_attrs = amd_l3_attrs(); |
1140 | 1157 | #endif | |
1141 | retval = kobject_init_and_add(&(this_object->kobj), | 1158 | retval = kobject_init_and_add(&(this_object->kobj), |
1142 | &ktype_cache, | 1159 | &ktype_cache, |
1143 | per_cpu(ici_cache_kobject, cpu), | 1160 | per_cpu(ici_cache_kobject, cpu), |
diff --git a/arch/x86/kernel/cpu/mcheck/mce-apei.c b/arch/x86/kernel/cpu/mcheck/mce-apei.c index 8209472b27a5..83930deec3c6 100644 --- a/arch/x86/kernel/cpu/mcheck/mce-apei.c +++ b/arch/x86/kernel/cpu/mcheck/mce-apei.c | |||
@@ -106,24 +106,34 @@ int apei_write_mce(struct mce *m) | |||
106 | ssize_t apei_read_mce(struct mce *m, u64 *record_id) | 106 | ssize_t apei_read_mce(struct mce *m, u64 *record_id) |
107 | { | 107 | { |
108 | struct cper_mce_record rcd; | 108 | struct cper_mce_record rcd; |
109 | ssize_t len; | 109 | int rc, pos; |
110 | 110 | ||
111 | len = erst_read_next(&rcd.hdr, sizeof(rcd)); | 111 | rc = erst_get_record_id_begin(&pos); |
112 | if (len <= 0) | 112 | if (rc) |
113 | return len; | 113 | return rc; |
114 | /* Can not skip other records in storage via ERST unless clear them */ | 114 | retry: |
115 | else if (len != sizeof(rcd) || | 115 | rc = erst_get_record_id_next(&pos, record_id); |
116 | uuid_le_cmp(rcd.hdr.creator_id, CPER_CREATOR_MCE)) { | 116 | if (rc) |
117 | if (printk_ratelimit()) | 117 | goto out; |
118 | pr_warning( | 118 | /* no more record */ |
119 | "MCE-APEI: Can not skip the unknown record in ERST"); | 119 | if (*record_id == APEI_ERST_INVALID_RECORD_ID) |
120 | return -EIO; | 120 | goto out; |
121 | } | 121 | rc = erst_read(*record_id, &rcd.hdr, sizeof(rcd)); |
122 | 122 | /* someone else has cleared the record, try next one */ | |
123 | if (rc == -ENOENT) | ||
124 | goto retry; | ||
125 | else if (rc < 0) | ||
126 | goto out; | ||
127 | /* try to skip other type records in storage */ | ||
128 | else if (rc != sizeof(rcd) || | ||
129 | uuid_le_cmp(rcd.hdr.creator_id, CPER_CREATOR_MCE)) | ||
130 | goto retry; | ||
123 | memcpy(m, &rcd.mce, sizeof(*m)); | 131 | memcpy(m, &rcd.mce, sizeof(*m)); |
124 | *record_id = rcd.hdr.record_id; | 132 | rc = sizeof(*m); |
133 | out: | ||
134 | erst_get_record_id_end(); | ||
125 | 135 | ||
126 | return sizeof(*m); | 136 | return rc; |
127 | } | 137 | } |
128 | 138 | ||
129 | /* Check whether there is record in ERST */ | 139 | /* Check whether there is record in ERST */ |
diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c index e7dbde7bfedb..0ed633c5048b 100644 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c | |||
@@ -25,13 +25,14 @@ | |||
25 | #include <linux/gfp.h> | 25 | #include <linux/gfp.h> |
26 | #include <asm/mce.h> | 26 | #include <asm/mce.h> |
27 | #include <asm/apic.h> | 27 | #include <asm/apic.h> |
28 | #include <asm/nmi.h> | ||
28 | 29 | ||
29 | /* Update fake mce registers on current CPU. */ | 30 | /* Update fake mce registers on current CPU. */ |
30 | static void inject_mce(struct mce *m) | 31 | static void inject_mce(struct mce *m) |
31 | { | 32 | { |
32 | struct mce *i = &per_cpu(injectm, m->extcpu); | 33 | struct mce *i = &per_cpu(injectm, m->extcpu); |
33 | 34 | ||
34 | /* Make sure noone reads partially written injectm */ | 35 | /* Make sure no one reads partially written injectm */ |
35 | i->finished = 0; | 36 | i->finished = 0; |
36 | mb(); | 37 | mb(); |
37 | m->finished = 0; | 38 | m->finished = 0; |
@@ -83,7 +84,7 @@ static int mce_raise_notify(struct notifier_block *self, | |||
83 | struct die_args *args = (struct die_args *)data; | 84 | struct die_args *args = (struct die_args *)data; |
84 | int cpu = smp_processor_id(); | 85 | int cpu = smp_processor_id(); |
85 | struct mce *m = &__get_cpu_var(injectm); | 86 | struct mce *m = &__get_cpu_var(injectm); |
86 | if (val != DIE_NMI_IPI || !cpumask_test_cpu(cpu, mce_inject_cpumask)) | 87 | if (val != DIE_NMI || !cpumask_test_cpu(cpu, mce_inject_cpumask)) |
87 | return NOTIFY_DONE; | 88 | return NOTIFY_DONE; |
88 | cpumask_clear_cpu(cpu, mce_inject_cpumask); | 89 | cpumask_clear_cpu(cpu, mce_inject_cpumask); |
89 | if (m->inject_flags & MCJ_EXCEPTION) | 90 | if (m->inject_flags & MCJ_EXCEPTION) |
@@ -95,7 +96,7 @@ static int mce_raise_notify(struct notifier_block *self, | |||
95 | 96 | ||
96 | static struct notifier_block mce_raise_nb = { | 97 | static struct notifier_block mce_raise_nb = { |
97 | .notifier_call = mce_raise_notify, | 98 | .notifier_call = mce_raise_notify, |
98 | .priority = 1000, | 99 | .priority = NMI_LOCAL_NORMAL_PRIOR, |
99 | }; | 100 | }; |
100 | 101 | ||
101 | /* Inject mce on current CPU */ | 102 | /* Inject mce on current CPU */ |
diff --git a/arch/x86/kernel/cpu/mcheck/mce-severity.c b/arch/x86/kernel/cpu/mcheck/mce-severity.c index 8a85dd1b1aa1..1e8d66c1336a 100644 --- a/arch/x86/kernel/cpu/mcheck/mce-severity.c +++ b/arch/x86/kernel/cpu/mcheck/mce-severity.c | |||
@@ -192,6 +192,7 @@ static const struct file_operations severities_coverage_fops = { | |||
192 | .release = seq_release, | 192 | .release = seq_release, |
193 | .read = seq_read, | 193 | .read = seq_read, |
194 | .write = severities_coverage_write, | 194 | .write = severities_coverage_write, |
195 | .llseek = seq_lseek, | ||
195 | }; | 196 | }; |
196 | 197 | ||
197 | static int __init severities_debugfs_init(void) | 198 | static int __init severities_debugfs_init(void) |
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index ed41562909fe..ff1ae9b6464d 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/percpu.h> | 21 | #include <linux/percpu.h> |
22 | #include <linux/string.h> | 22 | #include <linux/string.h> |
23 | #include <linux/sysdev.h> | 23 | #include <linux/sysdev.h> |
24 | #include <linux/syscore_ops.h> | ||
24 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
25 | #include <linux/ctype.h> | 26 | #include <linux/ctype.h> |
26 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
@@ -104,20 +105,6 @@ static int cpu_missing; | |||
104 | ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain); | 105 | ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain); |
105 | EXPORT_SYMBOL_GPL(x86_mce_decoder_chain); | 106 | EXPORT_SYMBOL_GPL(x86_mce_decoder_chain); |
106 | 107 | ||
107 | static int default_decode_mce(struct notifier_block *nb, unsigned long val, | ||
108 | void *data) | ||
109 | { | ||
110 | pr_emerg(HW_ERR "No human readable MCE decoding support on this CPU type.\n"); | ||
111 | pr_emerg(HW_ERR "Run the message through 'mcelog --ascii' to decode.\n"); | ||
112 | |||
113 | return NOTIFY_STOP; | ||
114 | } | ||
115 | |||
116 | static struct notifier_block mce_dec_nb = { | ||
117 | .notifier_call = default_decode_mce, | ||
118 | .priority = -1, | ||
119 | }; | ||
120 | |||
121 | /* MCA banks polled by the period polling timer for corrected events */ | 108 | /* MCA banks polled by the period polling timer for corrected events */ |
122 | DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = { | 109 | DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = { |
123 | [0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL | 110 | [0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL |
@@ -211,6 +198,8 @@ void mce_log(struct mce *mce) | |||
211 | 198 | ||
212 | static void print_mce(struct mce *m) | 199 | static void print_mce(struct mce *m) |
213 | { | 200 | { |
201 | int ret = 0; | ||
202 | |||
214 | pr_emerg(HW_ERR "CPU %d: Machine Check Exception: %Lx Bank %d: %016Lx\n", | 203 | pr_emerg(HW_ERR "CPU %d: Machine Check Exception: %Lx Bank %d: %016Lx\n", |
215 | m->extcpu, m->mcgstatus, m->bank, m->status); | 204 | m->extcpu, m->mcgstatus, m->bank, m->status); |
216 | 205 | ||
@@ -238,7 +227,11 @@ static void print_mce(struct mce *m) | |||
238 | * Print out human-readable details about the MCE error, | 227 | * Print out human-readable details about the MCE error, |
239 | * (if the CPU has an implementation for that) | 228 | * (if the CPU has an implementation for that) |
240 | */ | 229 | */ |
241 | atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, m); | 230 | ret = atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, m); |
231 | if (ret == NOTIFY_STOP) | ||
232 | return; | ||
233 | |||
234 | pr_emerg_ratelimited(HW_ERR "Run the above through 'mcelog --ascii'\n"); | ||
242 | } | 235 | } |
243 | 236 | ||
244 | #define PANIC_TIMEOUT 5 /* 5 seconds */ | 237 | #define PANIC_TIMEOUT 5 /* 5 seconds */ |
@@ -326,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp) | |||
326 | 319 | ||
327 | static int msr_to_offset(u32 msr) | 320 | static int msr_to_offset(u32 msr) |
328 | { | 321 | { |
329 | unsigned bank = __get_cpu_var(injectm.bank); | 322 | unsigned bank = __this_cpu_read(injectm.bank); |
330 | 323 | ||
331 | if (msr == rip_msr) | 324 | if (msr == rip_msr) |
332 | return offsetof(struct mce, ip); | 325 | return offsetof(struct mce, ip); |
@@ -346,7 +339,7 @@ static u64 mce_rdmsrl(u32 msr) | |||
346 | { | 339 | { |
347 | u64 v; | 340 | u64 v; |
348 | 341 | ||
349 | if (__get_cpu_var(injectm).finished) { | 342 | if (__this_cpu_read(injectm.finished)) { |
350 | int offset = msr_to_offset(msr); | 343 | int offset = msr_to_offset(msr); |
351 | 344 | ||
352 | if (offset < 0) | 345 | if (offset < 0) |
@@ -369,7 +362,7 @@ static u64 mce_rdmsrl(u32 msr) | |||
369 | 362 | ||
370 | static void mce_wrmsrl(u32 msr, u64 v) | 363 | static void mce_wrmsrl(u32 msr, u64 v) |
371 | { | 364 | { |
372 | if (__get_cpu_var(injectm).finished) { | 365 | if (__this_cpu_read(injectm.finished)) { |
373 | int offset = msr_to_offset(msr); | 366 | int offset = msr_to_offset(msr); |
374 | 367 | ||
375 | if (offset >= 0) | 368 | if (offset >= 0) |
@@ -589,7 +582,6 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b) | |||
589 | if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) { | 582 | if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) { |
590 | mce_log(&m); | 583 | mce_log(&m); |
591 | atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, &m); | 584 | atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, &m); |
592 | add_taint(TAINT_MACHINE_CHECK); | ||
593 | } | 585 | } |
594 | 586 | ||
595 | /* | 587 | /* |
@@ -881,7 +873,7 @@ reset: | |||
881 | * Check if the address reported by the CPU is in a format we can parse. | 873 | * Check if the address reported by the CPU is in a format we can parse. |
882 | * It would be possible to add code for most other cases, but all would | 874 | * It would be possible to add code for most other cases, but all would |
883 | * be somewhat complicated (e.g. segment offset would require an instruction | 875 | * be somewhat complicated (e.g. segment offset would require an instruction |
884 | * parser). So only support physical addresses upto page granuality for now. | 876 | * parser). So only support physical addresses up to page granuality for now. |
885 | */ | 877 | */ |
886 | static int mce_usable_address(struct mce *m) | 878 | static int mce_usable_address(struct mce *m) |
887 | { | 879 | { |
@@ -1159,7 +1151,7 @@ static void mce_start_timer(unsigned long data) | |||
1159 | 1151 | ||
1160 | WARN_ON(smp_processor_id() != data); | 1152 | WARN_ON(smp_processor_id() != data); |
1161 | 1153 | ||
1162 | if (mce_available(¤t_cpu_data)) { | 1154 | if (mce_available(__this_cpu_ptr(&cpu_info))) { |
1163 | machine_check_poll(MCP_TIMESTAMP, | 1155 | machine_check_poll(MCP_TIMESTAMP, |
1164 | &__get_cpu_var(mce_poll_banks)); | 1156 | &__get_cpu_var(mce_poll_banks)); |
1165 | } | 1157 | } |
@@ -1625,7 +1617,7 @@ out: | |||
1625 | static unsigned int mce_poll(struct file *file, poll_table *wait) | 1617 | static unsigned int mce_poll(struct file *file, poll_table *wait) |
1626 | { | 1618 | { |
1627 | poll_wait(file, &mce_wait, wait); | 1619 | poll_wait(file, &mce_wait, wait); |
1628 | if (rcu_dereference_check_mce(mcelog.next)) | 1620 | if (rcu_access_index(mcelog.next)) |
1629 | return POLLIN | POLLRDNORM; | 1621 | return POLLIN | POLLRDNORM; |
1630 | if (!mce_apei_read_done && apei_check_mce()) | 1622 | if (!mce_apei_read_done && apei_check_mce()) |
1631 | return POLLIN | POLLRDNORM; | 1623 | return POLLIN | POLLRDNORM; |
@@ -1665,6 +1657,7 @@ struct file_operations mce_chrdev_ops = { | |||
1665 | .read = mce_read, | 1657 | .read = mce_read, |
1666 | .poll = mce_poll, | 1658 | .poll = mce_poll, |
1667 | .unlocked_ioctl = mce_ioctl, | 1659 | .unlocked_ioctl = mce_ioctl, |
1660 | .llseek = no_llseek, | ||
1668 | }; | 1661 | }; |
1669 | EXPORT_SYMBOL_GPL(mce_chrdev_ops); | 1662 | EXPORT_SYMBOL_GPL(mce_chrdev_ops); |
1670 | 1663 | ||
@@ -1720,8 +1713,6 @@ __setup("mce", mcheck_enable); | |||
1720 | 1713 | ||
1721 | int __init mcheck_init(void) | 1714 | int __init mcheck_init(void) |
1722 | { | 1715 | { |
1723 | atomic_notifier_chain_register(&x86_mce_decoder_chain, &mce_dec_nb); | ||
1724 | |||
1725 | mcheck_intel_therm_init(); | 1716 | mcheck_intel_therm_init(); |
1726 | 1717 | ||
1727 | return 0; | 1718 | return 0; |
@@ -1748,14 +1739,14 @@ static int mce_disable_error_reporting(void) | |||
1748 | return 0; | 1739 | return 0; |
1749 | } | 1740 | } |
1750 | 1741 | ||
1751 | static int mce_suspend(struct sys_device *dev, pm_message_t state) | 1742 | static int mce_suspend(void) |
1752 | { | 1743 | { |
1753 | return mce_disable_error_reporting(); | 1744 | return mce_disable_error_reporting(); |
1754 | } | 1745 | } |
1755 | 1746 | ||
1756 | static int mce_shutdown(struct sys_device *dev) | 1747 | static void mce_shutdown(void) |
1757 | { | 1748 | { |
1758 | return mce_disable_error_reporting(); | 1749 | mce_disable_error_reporting(); |
1759 | } | 1750 | } |
1760 | 1751 | ||
1761 | /* | 1752 | /* |
@@ -1763,18 +1754,22 @@ static int mce_shutdown(struct sys_device *dev) | |||
1763 | * Only one CPU is active at this time, the others get re-added later using | 1754 | * Only one CPU is active at this time, the others get re-added later using |
1764 | * CPU hotplug: | 1755 | * CPU hotplug: |
1765 | */ | 1756 | */ |
1766 | static int mce_resume(struct sys_device *dev) | 1757 | static void mce_resume(void) |
1767 | { | 1758 | { |
1768 | __mcheck_cpu_init_generic(); | 1759 | __mcheck_cpu_init_generic(); |
1769 | __mcheck_cpu_init_vendor(¤t_cpu_data); | 1760 | __mcheck_cpu_init_vendor(__this_cpu_ptr(&cpu_info)); |
1770 | |||
1771 | return 0; | ||
1772 | } | 1761 | } |
1773 | 1762 | ||
1763 | static struct syscore_ops mce_syscore_ops = { | ||
1764 | .suspend = mce_suspend, | ||
1765 | .shutdown = mce_shutdown, | ||
1766 | .resume = mce_resume, | ||
1767 | }; | ||
1768 | |||
1774 | static void mce_cpu_restart(void *data) | 1769 | static void mce_cpu_restart(void *data) |
1775 | { | 1770 | { |
1776 | del_timer_sync(&__get_cpu_var(mce_timer)); | 1771 | del_timer_sync(&__get_cpu_var(mce_timer)); |
1777 | if (!mce_available(¤t_cpu_data)) | 1772 | if (!mce_available(__this_cpu_ptr(&cpu_info))) |
1778 | return; | 1773 | return; |
1779 | __mcheck_cpu_init_generic(); | 1774 | __mcheck_cpu_init_generic(); |
1780 | __mcheck_cpu_init_timer(); | 1775 | __mcheck_cpu_init_timer(); |
@@ -1789,7 +1784,7 @@ static void mce_restart(void) | |||
1789 | /* Toggle features for corrected errors */ | 1784 | /* Toggle features for corrected errors */ |
1790 | static void mce_disable_ce(void *all) | 1785 | static void mce_disable_ce(void *all) |
1791 | { | 1786 | { |
1792 | if (!mce_available(¤t_cpu_data)) | 1787 | if (!mce_available(__this_cpu_ptr(&cpu_info))) |
1793 | return; | 1788 | return; |
1794 | if (all) | 1789 | if (all) |
1795 | del_timer_sync(&__get_cpu_var(mce_timer)); | 1790 | del_timer_sync(&__get_cpu_var(mce_timer)); |
@@ -1798,7 +1793,7 @@ static void mce_disable_ce(void *all) | |||
1798 | 1793 | ||
1799 | static void mce_enable_ce(void *all) | 1794 | static void mce_enable_ce(void *all) |
1800 | { | 1795 | { |
1801 | if (!mce_available(¤t_cpu_data)) | 1796 | if (!mce_available(__this_cpu_ptr(&cpu_info))) |
1802 | return; | 1797 | return; |
1803 | cmci_reenable(); | 1798 | cmci_reenable(); |
1804 | cmci_recheck(); | 1799 | cmci_recheck(); |
@@ -1807,9 +1802,6 @@ static void mce_enable_ce(void *all) | |||
1807 | } | 1802 | } |
1808 | 1803 | ||
1809 | static struct sysdev_class mce_sysclass = { | 1804 | static struct sysdev_class mce_sysclass = { |
1810 | .suspend = mce_suspend, | ||
1811 | .shutdown = mce_shutdown, | ||
1812 | .resume = mce_resume, | ||
1813 | .name = "machinecheck", | 1805 | .name = "machinecheck", |
1814 | }; | 1806 | }; |
1815 | 1807 | ||
@@ -2021,7 +2013,7 @@ static void __cpuinit mce_disable_cpu(void *h) | |||
2021 | unsigned long action = *(unsigned long *)h; | 2013 | unsigned long action = *(unsigned long *)h; |
2022 | int i; | 2014 | int i; |
2023 | 2015 | ||
2024 | if (!mce_available(¤t_cpu_data)) | 2016 | if (!mce_available(__this_cpu_ptr(&cpu_info))) |
2025 | return; | 2017 | return; |
2026 | 2018 | ||
2027 | if (!(action & CPU_TASKS_FROZEN)) | 2019 | if (!(action & CPU_TASKS_FROZEN)) |
@@ -2039,7 +2031,7 @@ static void __cpuinit mce_reenable_cpu(void *h) | |||
2039 | unsigned long action = *(unsigned long *)h; | 2031 | unsigned long action = *(unsigned long *)h; |
2040 | int i; | 2032 | int i; |
2041 | 2033 | ||
2042 | if (!mce_available(¤t_cpu_data)) | 2034 | if (!mce_available(__this_cpu_ptr(&cpu_info))) |
2043 | return; | 2035 | return; |
2044 | 2036 | ||
2045 | if (!(action & CPU_TASKS_FROZEN)) | 2037 | if (!(action & CPU_TASKS_FROZEN)) |
@@ -2138,6 +2130,7 @@ static __init int mcheck_init_device(void) | |||
2138 | return err; | 2130 | return err; |
2139 | } | 2131 | } |
2140 | 2132 | ||
2133 | register_syscore_ops(&mce_syscore_ops); | ||
2141 | register_hotcpu_notifier(&mce_cpu_notifier); | 2134 | register_hotcpu_notifier(&mce_cpu_notifier); |
2142 | misc_register(&mce_log_device); | 2135 | misc_register(&mce_log_device); |
2143 | 2136 | ||
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c index 39aaee5c1ab2..bb0adad35143 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c | |||
@@ -31,8 +31,6 @@ | |||
31 | #include <asm/mce.h> | 31 | #include <asm/mce.h> |
32 | #include <asm/msr.h> | 32 | #include <asm/msr.h> |
33 | 33 | ||
34 | #define PFX "mce_threshold: " | ||
35 | #define VERSION "version 1.1.1" | ||
36 | #define NR_BANKS 6 | 34 | #define NR_BANKS 6 |
37 | #define NR_BLOCKS 9 | 35 | #define NR_BLOCKS 9 |
38 | #define THRESHOLD_MAX 0xFFF | 36 | #define THRESHOLD_MAX 0xFFF |
@@ -59,12 +57,6 @@ struct threshold_block { | |||
59 | struct list_head miscj; | 57 | struct list_head miscj; |
60 | }; | 58 | }; |
61 | 59 | ||
62 | /* defaults used early on boot */ | ||
63 | static struct threshold_block threshold_defaults = { | ||
64 | .interrupt_enable = 0, | ||
65 | .threshold_limit = THRESHOLD_MAX, | ||
66 | }; | ||
67 | |||
68 | struct threshold_bank { | 60 | struct threshold_bank { |
69 | struct kobject *kobj; | 61 | struct kobject *kobj; |
70 | struct threshold_block *blocks; | 62 | struct threshold_block *blocks; |
@@ -89,49 +81,101 @@ static void amd_threshold_interrupt(void); | |||
89 | struct thresh_restart { | 81 | struct thresh_restart { |
90 | struct threshold_block *b; | 82 | struct threshold_block *b; |
91 | int reset; | 83 | int reset; |
84 | int set_lvt_off; | ||
85 | int lvt_off; | ||
92 | u16 old_limit; | 86 | u16 old_limit; |
93 | }; | 87 | }; |
94 | 88 | ||
89 | static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi) | ||
90 | { | ||
91 | int msr = (hi & MASK_LVTOFF_HI) >> 20; | ||
92 | |||
93 | if (apic < 0) { | ||
94 | pr_err(FW_BUG "cpu %d, failed to setup threshold interrupt " | ||
95 | "for bank %d, block %d (MSR%08X=0x%x%08x)\n", b->cpu, | ||
96 | b->bank, b->block, b->address, hi, lo); | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | if (apic != msr) { | ||
101 | pr_err(FW_BUG "cpu %d, invalid threshold interrupt offset %d " | ||
102 | "for bank %d, block %d (MSR%08X=0x%x%08x)\n", | ||
103 | b->cpu, apic, b->bank, b->block, b->address, hi, lo); | ||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | return 1; | ||
108 | }; | ||
109 | |||
95 | /* must be called with correct cpu affinity */ | 110 | /* must be called with correct cpu affinity */ |
96 | /* Called via smp_call_function_single() */ | 111 | /* Called via smp_call_function_single() */ |
97 | static void threshold_restart_bank(void *_tr) | 112 | static void threshold_restart_bank(void *_tr) |
98 | { | 113 | { |
99 | struct thresh_restart *tr = _tr; | 114 | struct thresh_restart *tr = _tr; |
100 | u32 mci_misc_hi, mci_misc_lo; | 115 | u32 hi, lo; |
101 | 116 | ||
102 | rdmsr(tr->b->address, mci_misc_lo, mci_misc_hi); | 117 | rdmsr(tr->b->address, lo, hi); |
103 | 118 | ||
104 | if (tr->b->threshold_limit < (mci_misc_hi & THRESHOLD_MAX)) | 119 | if (tr->b->threshold_limit < (hi & THRESHOLD_MAX)) |
105 | tr->reset = 1; /* limit cannot be lower than err count */ | 120 | tr->reset = 1; /* limit cannot be lower than err count */ |
106 | 121 | ||
107 | if (tr->reset) { /* reset err count and overflow bit */ | 122 | if (tr->reset) { /* reset err count and overflow bit */ |
108 | mci_misc_hi = | 123 | hi = |
109 | (mci_misc_hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) | | 124 | (hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) | |
110 | (THRESHOLD_MAX - tr->b->threshold_limit); | 125 | (THRESHOLD_MAX - tr->b->threshold_limit); |
111 | } else if (tr->old_limit) { /* change limit w/o reset */ | 126 | } else if (tr->old_limit) { /* change limit w/o reset */ |
112 | int new_count = (mci_misc_hi & THRESHOLD_MAX) + | 127 | int new_count = (hi & THRESHOLD_MAX) + |
113 | (tr->old_limit - tr->b->threshold_limit); | 128 | (tr->old_limit - tr->b->threshold_limit); |
114 | 129 | ||
115 | mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) | | 130 | hi = (hi & ~MASK_ERR_COUNT_HI) | |
116 | (new_count & THRESHOLD_MAX); | 131 | (new_count & THRESHOLD_MAX); |
117 | } | 132 | } |
118 | 133 | ||
134 | if (tr->set_lvt_off) { | ||
135 | if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) { | ||
136 | /* set new lvt offset */ | ||
137 | hi &= ~MASK_LVTOFF_HI; | ||
138 | hi |= tr->lvt_off << 20; | ||
139 | } | ||
140 | } | ||
141 | |||
119 | tr->b->interrupt_enable ? | 142 | tr->b->interrupt_enable ? |
120 | (mci_misc_hi = (mci_misc_hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) : | 143 | (hi = (hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) : |
121 | (mci_misc_hi &= ~MASK_INT_TYPE_HI); | 144 | (hi &= ~MASK_INT_TYPE_HI); |
122 | 145 | ||
123 | mci_misc_hi |= MASK_COUNT_EN_HI; | 146 | hi |= MASK_COUNT_EN_HI; |
124 | wrmsr(tr->b->address, mci_misc_lo, mci_misc_hi); | 147 | wrmsr(tr->b->address, lo, hi); |
148 | } | ||
149 | |||
150 | static void mce_threshold_block_init(struct threshold_block *b, int offset) | ||
151 | { | ||
152 | struct thresh_restart tr = { | ||
153 | .b = b, | ||
154 | .set_lvt_off = 1, | ||
155 | .lvt_off = offset, | ||
156 | }; | ||
157 | |||
158 | b->threshold_limit = THRESHOLD_MAX; | ||
159 | threshold_restart_bank(&tr); | ||
160 | }; | ||
161 | |||
162 | static int setup_APIC_mce(int reserved, int new) | ||
163 | { | ||
164 | if (reserved < 0 && !setup_APIC_eilvt(new, THRESHOLD_APIC_VECTOR, | ||
165 | APIC_EILVT_MSG_FIX, 0)) | ||
166 | return new; | ||
167 | |||
168 | return reserved; | ||
125 | } | 169 | } |
126 | 170 | ||
127 | /* cpu init entry point, called from mce.c with preempt off */ | 171 | /* cpu init entry point, called from mce.c with preempt off */ |
128 | void mce_amd_feature_init(struct cpuinfo_x86 *c) | 172 | void mce_amd_feature_init(struct cpuinfo_x86 *c) |
129 | { | 173 | { |
174 | struct threshold_block b; | ||
130 | unsigned int cpu = smp_processor_id(); | 175 | unsigned int cpu = smp_processor_id(); |
131 | u32 low = 0, high = 0, address = 0; | 176 | u32 low = 0, high = 0, address = 0; |
132 | unsigned int bank, block; | 177 | unsigned int bank, block; |
133 | struct thresh_restart tr; | 178 | int offset = -1; |
134 | u8 lvt_off; | ||
135 | 179 | ||
136 | for (bank = 0; bank < NR_BANKS; ++bank) { | 180 | for (bank = 0; bank < NR_BANKS; ++bank) { |
137 | for (block = 0; block < NR_BLOCKS; ++block) { | 181 | for (block = 0; block < NR_BLOCKS; ++block) { |
@@ -162,19 +206,16 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c) | |||
162 | if (shared_bank[bank] && c->cpu_core_id) | 206 | if (shared_bank[bank] && c->cpu_core_id) |
163 | break; | 207 | break; |
164 | #endif | 208 | #endif |
165 | lvt_off = setup_APIC_eilvt_mce(THRESHOLD_APIC_VECTOR, | 209 | offset = setup_APIC_mce(offset, |
166 | APIC_EILVT_MSG_FIX, 0); | 210 | (high & MASK_LVTOFF_HI) >> 20); |
167 | 211 | ||
168 | high &= ~MASK_LVTOFF_HI; | 212 | memset(&b, 0, sizeof(b)); |
169 | high |= lvt_off << 20; | 213 | b.cpu = cpu; |
170 | wrmsr(address, low, high); | 214 | b.bank = bank; |
171 | 215 | b.block = block; | |
172 | threshold_defaults.address = address; | 216 | b.address = address; |
173 | tr.b = &threshold_defaults; | ||
174 | tr.reset = 0; | ||
175 | tr.old_limit = 0; | ||
176 | threshold_restart_bank(&tr); | ||
177 | 217 | ||
218 | mce_threshold_block_init(&b, offset); | ||
178 | mce_threshold_vector = amd_threshold_interrupt; | 219 | mce_threshold_vector = amd_threshold_interrupt; |
179 | } | 220 | } |
180 | } | 221 | } |
@@ -277,9 +318,8 @@ store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size) | |||
277 | 318 | ||
278 | b->interrupt_enable = !!new; | 319 | b->interrupt_enable = !!new; |
279 | 320 | ||
321 | memset(&tr, 0, sizeof(tr)); | ||
280 | tr.b = b; | 322 | tr.b = b; |
281 | tr.reset = 0; | ||
282 | tr.old_limit = 0; | ||
283 | 323 | ||
284 | smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); | 324 | smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); |
285 | 325 | ||
@@ -300,10 +340,10 @@ store_threshold_limit(struct threshold_block *b, const char *buf, size_t size) | |||
300 | if (new < 1) | 340 | if (new < 1) |
301 | new = 1; | 341 | new = 1; |
302 | 342 | ||
343 | memset(&tr, 0, sizeof(tr)); | ||
303 | tr.old_limit = b->threshold_limit; | 344 | tr.old_limit = b->threshold_limit; |
304 | b->threshold_limit = new; | 345 | b->threshold_limit = new; |
305 | tr.b = b; | 346 | tr.b = b; |
306 | tr.reset = 0; | ||
307 | 347 | ||
308 | smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); | 348 | smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); |
309 | 349 | ||
@@ -469,6 +509,7 @@ recurse: | |||
469 | out_free: | 509 | out_free: |
470 | if (b) { | 510 | if (b) { |
471 | kobject_put(&b->kobj); | 511 | kobject_put(&b->kobj); |
512 | list_del(&b->miscj); | ||
472 | kfree(b); | 513 | kfree(b); |
473 | } | 514 | } |
474 | return err; | 515 | return err; |
@@ -487,15 +528,12 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) | |||
487 | int i, err = 0; | 528 | int i, err = 0; |
488 | struct threshold_bank *b = NULL; | 529 | struct threshold_bank *b = NULL; |
489 | char name[32]; | 530 | char name[32]; |
490 | #ifdef CONFIG_SMP | ||
491 | struct cpuinfo_x86 *c = &cpu_data(cpu); | ||
492 | #endif | ||
493 | 531 | ||
494 | sprintf(name, "threshold_bank%i", bank); | 532 | sprintf(name, "threshold_bank%i", bank); |
495 | 533 | ||
496 | #ifdef CONFIG_SMP | 534 | #ifdef CONFIG_SMP |
497 | if (cpu_data(cpu).cpu_core_id && shared_bank[bank]) { /* symlink */ | 535 | if (cpu_data(cpu).cpu_core_id && shared_bank[bank]) { /* symlink */ |
498 | i = cpumask_first(c->llc_shared_map); | 536 | i = cpumask_first(cpu_llc_shared_mask(cpu)); |
499 | 537 | ||
500 | /* first core not up yet */ | 538 | /* first core not up yet */ |
501 | if (cpu_data(i).cpu_core_id) | 539 | if (cpu_data(i).cpu_core_id) |
@@ -515,7 +553,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) | |||
515 | if (err) | 553 | if (err) |
516 | goto out; | 554 | goto out; |
517 | 555 | ||
518 | cpumask_copy(b->cpus, c->llc_shared_map); | 556 | cpumask_copy(b->cpus, cpu_llc_shared_mask(cpu)); |
519 | per_cpu(threshold_banks, cpu)[bank] = b; | 557 | per_cpu(threshold_banks, cpu)[bank] = b; |
520 | 558 | ||
521 | goto out; | 559 | goto out; |
@@ -582,9 +620,9 @@ static __cpuinit int threshold_create_device(unsigned int cpu) | |||
582 | continue; | 620 | continue; |
583 | err = threshold_create_bank(cpu, bank); | 621 | err = threshold_create_bank(cpu, bank); |
584 | if (err) | 622 | if (err) |
585 | goto out; | 623 | return err; |
586 | } | 624 | } |
587 | out: | 625 | |
588 | return err; | 626 | return err; |
589 | } | 627 | } |
590 | 628 | ||
diff --git a/arch/x86/kernel/cpu/mcheck/mce_intel.c b/arch/x86/kernel/cpu/mcheck/mce_intel.c index 6fcd0936194f..8694ef56459d 100644 --- a/arch/x86/kernel/cpu/mcheck/mce_intel.c +++ b/arch/x86/kernel/cpu/mcheck/mce_intel.c | |||
@@ -130,7 +130,7 @@ void cmci_recheck(void) | |||
130 | unsigned long flags; | 130 | unsigned long flags; |
131 | int banks; | 131 | int banks; |
132 | 132 | ||
133 | if (!mce_available(¤t_cpu_data) || !cmci_supported(&banks)) | 133 | if (!mce_available(__this_cpu_ptr(&cpu_info)) || !cmci_supported(&banks)) |
134 | return; | 134 | return; |
135 | local_irq_save(flags); | 135 | local_irq_save(flags); |
136 | machine_check_poll(MCP_TIMESTAMP, &__get_cpu_var(mce_banks_owned)); | 136 | machine_check_poll(MCP_TIMESTAMP, &__get_cpu_var(mce_banks_owned)); |
diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c index 169d8804a9f8..27c625178bf1 100644 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c | |||
@@ -53,8 +53,14 @@ struct thermal_state { | |||
53 | struct _thermal_state core_power_limit; | 53 | struct _thermal_state core_power_limit; |
54 | struct _thermal_state package_throttle; | 54 | struct _thermal_state package_throttle; |
55 | struct _thermal_state package_power_limit; | 55 | struct _thermal_state package_power_limit; |
56 | struct _thermal_state core_thresh0; | ||
57 | struct _thermal_state core_thresh1; | ||
56 | }; | 58 | }; |
57 | 59 | ||
60 | /* Callback to handle core threshold interrupts */ | ||
61 | int (*platform_thermal_notify)(__u64 msr_val); | ||
62 | EXPORT_SYMBOL(platform_thermal_notify); | ||
63 | |||
58 | static DEFINE_PER_CPU(struct thermal_state, thermal_state); | 64 | static DEFINE_PER_CPU(struct thermal_state, thermal_state); |
59 | 65 | ||
60 | static atomic_t therm_throt_en = ATOMIC_INIT(0); | 66 | static atomic_t therm_throt_en = ATOMIC_INIT(0); |
@@ -181,8 +187,6 @@ static int therm_throt_process(bool new_event, int event, int level) | |||
181 | this_cpu, | 187 | this_cpu, |
182 | level == CORE_LEVEL ? "Core" : "Package", | 188 | level == CORE_LEVEL ? "Core" : "Package", |
183 | state->count); | 189 | state->count); |
184 | |||
185 | add_taint(TAINT_MACHINE_CHECK); | ||
186 | return 1; | 190 | return 1; |
187 | } | 191 | } |
188 | if (old_event) { | 192 | if (old_event) { |
@@ -200,6 +204,22 @@ static int therm_throt_process(bool new_event, int event, int level) | |||
200 | return 0; | 204 | return 0; |
201 | } | 205 | } |
202 | 206 | ||
207 | static int thresh_event_valid(int event) | ||
208 | { | ||
209 | struct _thermal_state *state; | ||
210 | unsigned int this_cpu = smp_processor_id(); | ||
211 | struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); | ||
212 | u64 now = get_jiffies_64(); | ||
213 | |||
214 | state = (event == 0) ? &pstate->core_thresh0 : &pstate->core_thresh1; | ||
215 | |||
216 | if (time_before64(now, state->next_check)) | ||
217 | return 0; | ||
218 | |||
219 | state->next_check = now + CHECK_INTERVAL; | ||
220 | return 1; | ||
221 | } | ||
222 | |||
203 | #ifdef CONFIG_SYSFS | 223 | #ifdef CONFIG_SYSFS |
204 | /* Add/Remove thermal_throttle interface for CPU device: */ | 224 | /* Add/Remove thermal_throttle interface for CPU device: */ |
205 | static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, | 225 | static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev, |
@@ -313,32 +333,50 @@ device_initcall(thermal_throttle_init_device); | |||
313 | #define PACKAGE_THROTTLED ((__u64)2 << 62) | 333 | #define PACKAGE_THROTTLED ((__u64)2 << 62) |
314 | #define PACKAGE_POWER_LIMIT ((__u64)3 << 62) | 334 | #define PACKAGE_POWER_LIMIT ((__u64)3 << 62) |
315 | 335 | ||
336 | static void notify_thresholds(__u64 msr_val) | ||
337 | { | ||
338 | /* check whether the interrupt handler is defined; | ||
339 | * otherwise simply return | ||
340 | */ | ||
341 | if (!platform_thermal_notify) | ||
342 | return; | ||
343 | |||
344 | /* lower threshold reached */ | ||
345 | if ((msr_val & THERM_LOG_THRESHOLD0) && thresh_event_valid(0)) | ||
346 | platform_thermal_notify(msr_val); | ||
347 | /* higher threshold reached */ | ||
348 | if ((msr_val & THERM_LOG_THRESHOLD1) && thresh_event_valid(1)) | ||
349 | platform_thermal_notify(msr_val); | ||
350 | } | ||
351 | |||
316 | /* Thermal transition interrupt handler */ | 352 | /* Thermal transition interrupt handler */ |
317 | static void intel_thermal_interrupt(void) | 353 | static void intel_thermal_interrupt(void) |
318 | { | 354 | { |
319 | __u64 msr_val; | 355 | __u64 msr_val; |
320 | struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); | ||
321 | 356 | ||
322 | rdmsrl(MSR_IA32_THERM_STATUS, msr_val); | 357 | rdmsrl(MSR_IA32_THERM_STATUS, msr_val); |
323 | 358 | ||
359 | /* Check for violation of core thermal thresholds*/ | ||
360 | notify_thresholds(msr_val); | ||
361 | |||
324 | if (therm_throt_process(msr_val & THERM_STATUS_PROCHOT, | 362 | if (therm_throt_process(msr_val & THERM_STATUS_PROCHOT, |
325 | THERMAL_THROTTLING_EVENT, | 363 | THERMAL_THROTTLING_EVENT, |
326 | CORE_LEVEL) != 0) | 364 | CORE_LEVEL) != 0) |
327 | mce_log_therm_throt_event(CORE_THROTTLED | msr_val); | 365 | mce_log_therm_throt_event(CORE_THROTTLED | msr_val); |
328 | 366 | ||
329 | if (cpu_has(c, X86_FEATURE_PLN)) | 367 | if (this_cpu_has(X86_FEATURE_PLN)) |
330 | if (therm_throt_process(msr_val & THERM_STATUS_POWER_LIMIT, | 368 | if (therm_throt_process(msr_val & THERM_STATUS_POWER_LIMIT, |
331 | POWER_LIMIT_EVENT, | 369 | POWER_LIMIT_EVENT, |
332 | CORE_LEVEL) != 0) | 370 | CORE_LEVEL) != 0) |
333 | mce_log_therm_throt_event(CORE_POWER_LIMIT | msr_val); | 371 | mce_log_therm_throt_event(CORE_POWER_LIMIT | msr_val); |
334 | 372 | ||
335 | if (cpu_has(c, X86_FEATURE_PTS)) { | 373 | if (this_cpu_has(X86_FEATURE_PTS)) { |
336 | rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); | 374 | rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); |
337 | if (therm_throt_process(msr_val & PACKAGE_THERM_STATUS_PROCHOT, | 375 | if (therm_throt_process(msr_val & PACKAGE_THERM_STATUS_PROCHOT, |
338 | THERMAL_THROTTLING_EVENT, | 376 | THERMAL_THROTTLING_EVENT, |
339 | PACKAGE_LEVEL) != 0) | 377 | PACKAGE_LEVEL) != 0) |
340 | mce_log_therm_throt_event(PACKAGE_THROTTLED | msr_val); | 378 | mce_log_therm_throt_event(PACKAGE_THROTTLED | msr_val); |
341 | if (cpu_has(c, X86_FEATURE_PLN)) | 379 | if (this_cpu_has(X86_FEATURE_PLN)) |
342 | if (therm_throt_process(msr_val & | 380 | if (therm_throt_process(msr_val & |
343 | PACKAGE_THERM_STATUS_POWER_LIMIT, | 381 | PACKAGE_THERM_STATUS_POWER_LIMIT, |
344 | POWER_LIMIT_EVENT, | 382 | POWER_LIMIT_EVENT, |
@@ -350,9 +388,8 @@ static void intel_thermal_interrupt(void) | |||
350 | 388 | ||
351 | static void unexpected_thermal_interrupt(void) | 389 | static void unexpected_thermal_interrupt(void) |
352 | { | 390 | { |
353 | printk(KERN_ERR "CPU%d: Unexpected LVT TMR interrupt!\n", | 391 | printk(KERN_ERR "CPU%d: Unexpected LVT thermal interrupt!\n", |
354 | smp_processor_id()); | 392 | smp_processor_id()); |
355 | add_taint(TAINT_MACHINE_CHECK); | ||
356 | } | 393 | } |
357 | 394 | ||
358 | static void (*smp_thermal_vector)(void) = unexpected_thermal_interrupt; | 395 | static void (*smp_thermal_vector)(void) = unexpected_thermal_interrupt; |
@@ -405,18 +442,20 @@ void intel_init_thermal(struct cpuinfo_x86 *c) | |||
405 | */ | 442 | */ |
406 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | 443 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); |
407 | 444 | ||
445 | h = lvtthmr_init; | ||
408 | /* | 446 | /* |
409 | * The initial value of thermal LVT entries on all APs always reads | 447 | * The initial value of thermal LVT entries on all APs always reads |
410 | * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI | 448 | * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI |
411 | * sequence to them and LVT registers are reset to 0s except for | 449 | * sequence to them and LVT registers are reset to 0s except for |
412 | * the mask bits which are set to 1s when APs receive INIT IPI. | 450 | * the mask bits which are set to 1s when APs receive INIT IPI. |
413 | * Always restore the value that BIOS has programmed on AP based on | 451 | * If BIOS takes over the thermal interrupt and sets its interrupt |
414 | * BSP's info we saved since BIOS is always setting the same value | 452 | * delivery mode to SMI (not fixed), it restores the value that the |
415 | * for all threads/cores | 453 | * BIOS has programmed on AP based on BSP's info we saved since BIOS |
454 | * is always setting the same value for all threads/cores. | ||
416 | */ | 455 | */ |
417 | apic_write(APIC_LVTTHMR, lvtthmr_init); | 456 | if ((h & APIC_DM_FIXED_MASK) != APIC_DM_FIXED) |
457 | apic_write(APIC_LVTTHMR, lvtthmr_init); | ||
418 | 458 | ||
419 | h = lvtthmr_init; | ||
420 | 459 | ||
421 | if ((l & MSR_IA32_MISC_ENABLE_TM1) && (h & APIC_DM_SMI)) { | 460 | if ((l & MSR_IA32_MISC_ENABLE_TM1) && (h & APIC_DM_SMI)) { |
422 | printk(KERN_DEBUG | 461 | printk(KERN_DEBUG |
diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c index c5f59d071425..ac140c7be396 100644 --- a/arch/x86/kernel/cpu/mtrr/cleanup.c +++ b/arch/x86/kernel/cpu/mtrr/cleanup.c | |||
@@ -827,7 +827,7 @@ int __init amd_special_default_mtrr(void) | |||
827 | 827 | ||
828 | if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) | 828 | if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) |
829 | return 0; | 829 | return 0; |
830 | if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11) | 830 | if (boot_cpu_data.x86 < 0xf) |
831 | return 0; | 831 | return 0; |
832 | /* In case some hypervisor doesn't pass SYSCFG through: */ | 832 | /* In case some hypervisor doesn't pass SYSCFG through: */ |
833 | if (rdmsr_safe(MSR_K8_SYSCFG, &l, &h) < 0) | 833 | if (rdmsr_safe(MSR_K8_SYSCFG, &l, &h) < 0) |
diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c index 7d28d7d03885..a71efcdbb092 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * This only handles 32bit MTRR on 32bit hosts. This is strictly wrong | 2 | * This only handles 32bit MTRR on 32bit hosts. This is strictly wrong |
3 | * because MTRRs can span upto 40 bits (36bits on most modern x86) | 3 | * because MTRRs can span up to 40 bits (36bits on most modern x86) |
4 | */ | 4 | */ |
5 | #define DEBUG | 5 | #define DEBUG |
6 | 6 | ||
@@ -64,18 +64,59 @@ static inline void k8_check_syscfg_dram_mod_en(void) | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | /* Get the size of contiguous MTRR range */ | ||
68 | static u64 get_mtrr_size(u64 mask) | ||
69 | { | ||
70 | u64 size; | ||
71 | |||
72 | mask >>= PAGE_SHIFT; | ||
73 | mask |= size_or_mask; | ||
74 | size = -mask; | ||
75 | size <<= PAGE_SHIFT; | ||
76 | return size; | ||
77 | } | ||
78 | |||
67 | /* | 79 | /* |
68 | * Returns the effective MTRR type for the region | 80 | * Check and return the effective type for MTRR-MTRR type overlap. |
69 | * Error returns: | 81 | * Returns 1 if the effective type is UNCACHEABLE, else returns 0 |
70 | * - 0xFE - when the range is "not entirely covered" by _any_ var range MTRR | ||
71 | * - 0xFF - when MTRR is not enabled | ||
72 | */ | 82 | */ |
73 | u8 mtrr_type_lookup(u64 start, u64 end) | 83 | static int check_type_overlap(u8 *prev, u8 *curr) |
84 | { | ||
85 | if (*prev == MTRR_TYPE_UNCACHABLE || *curr == MTRR_TYPE_UNCACHABLE) { | ||
86 | *prev = MTRR_TYPE_UNCACHABLE; | ||
87 | *curr = MTRR_TYPE_UNCACHABLE; | ||
88 | return 1; | ||
89 | } | ||
90 | |||
91 | if ((*prev == MTRR_TYPE_WRBACK && *curr == MTRR_TYPE_WRTHROUGH) || | ||
92 | (*prev == MTRR_TYPE_WRTHROUGH && *curr == MTRR_TYPE_WRBACK)) { | ||
93 | *prev = MTRR_TYPE_WRTHROUGH; | ||
94 | *curr = MTRR_TYPE_WRTHROUGH; | ||
95 | } | ||
96 | |||
97 | if (*prev != *curr) { | ||
98 | *prev = MTRR_TYPE_UNCACHABLE; | ||
99 | *curr = MTRR_TYPE_UNCACHABLE; | ||
100 | return 1; | ||
101 | } | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * Error/Semi-error returns: | ||
108 | * 0xFF - when MTRR is not enabled | ||
109 | * *repeat == 1 implies [start:end] spanned across MTRR range and type returned | ||
110 | * corresponds only to [start:*partial_end]. | ||
111 | * Caller has to lookup again for [*partial_end:end]. | ||
112 | */ | ||
113 | static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat) | ||
74 | { | 114 | { |
75 | int i; | 115 | int i; |
76 | u64 base, mask; | 116 | u64 base, mask; |
77 | u8 prev_match, curr_match; | 117 | u8 prev_match, curr_match; |
78 | 118 | ||
119 | *repeat = 0; | ||
79 | if (!mtrr_state_set) | 120 | if (!mtrr_state_set) |
80 | return 0xFF; | 121 | return 0xFF; |
81 | 122 | ||
@@ -126,8 +167,34 @@ u8 mtrr_type_lookup(u64 start, u64 end) | |||
126 | 167 | ||
127 | start_state = ((start & mask) == (base & mask)); | 168 | start_state = ((start & mask) == (base & mask)); |
128 | end_state = ((end & mask) == (base & mask)); | 169 | end_state = ((end & mask) == (base & mask)); |
129 | if (start_state != end_state) | 170 | |
130 | return 0xFE; | 171 | if (start_state != end_state) { |
172 | /* | ||
173 | * We have start:end spanning across an MTRR. | ||
174 | * We split the region into | ||
175 | * either | ||
176 | * (start:mtrr_end) (mtrr_end:end) | ||
177 | * or | ||
178 | * (start:mtrr_start) (mtrr_start:end) | ||
179 | * depending on kind of overlap. | ||
180 | * Return the type for first region and a pointer to | ||
181 | * the start of second region so that caller will | ||
182 | * lookup again on the second region. | ||
183 | * Note: This way we handle multiple overlaps as well. | ||
184 | */ | ||
185 | if (start_state) | ||
186 | *partial_end = base + get_mtrr_size(mask); | ||
187 | else | ||
188 | *partial_end = base; | ||
189 | |||
190 | if (unlikely(*partial_end <= start)) { | ||
191 | WARN_ON(1); | ||
192 | *partial_end = start + PAGE_SIZE; | ||
193 | } | ||
194 | |||
195 | end = *partial_end - 1; /* end is inclusive */ | ||
196 | *repeat = 1; | ||
197 | } | ||
131 | 198 | ||
132 | if ((start & mask) != (base & mask)) | 199 | if ((start & mask) != (base & mask)) |
133 | continue; | 200 | continue; |
@@ -138,21 +205,8 @@ u8 mtrr_type_lookup(u64 start, u64 end) | |||
138 | continue; | 205 | continue; |
139 | } | 206 | } |
140 | 207 | ||
141 | if (prev_match == MTRR_TYPE_UNCACHABLE || | 208 | if (check_type_overlap(&prev_match, &curr_match)) |
142 | curr_match == MTRR_TYPE_UNCACHABLE) { | 209 | return curr_match; |
143 | return MTRR_TYPE_UNCACHABLE; | ||
144 | } | ||
145 | |||
146 | if ((prev_match == MTRR_TYPE_WRBACK && | ||
147 | curr_match == MTRR_TYPE_WRTHROUGH) || | ||
148 | (prev_match == MTRR_TYPE_WRTHROUGH && | ||
149 | curr_match == MTRR_TYPE_WRBACK)) { | ||
150 | prev_match = MTRR_TYPE_WRTHROUGH; | ||
151 | curr_match = MTRR_TYPE_WRTHROUGH; | ||
152 | } | ||
153 | |||
154 | if (prev_match != curr_match) | ||
155 | return MTRR_TYPE_UNCACHABLE; | ||
156 | } | 210 | } |
157 | 211 | ||
158 | if (mtrr_tom2) { | 212 | if (mtrr_tom2) { |
@@ -166,6 +220,36 @@ u8 mtrr_type_lookup(u64 start, u64 end) | |||
166 | return mtrr_state.def_type; | 220 | return mtrr_state.def_type; |
167 | } | 221 | } |
168 | 222 | ||
223 | /* | ||
224 | * Returns the effective MTRR type for the region | ||
225 | * Error return: | ||
226 | * 0xFF - when MTRR is not enabled | ||
227 | */ | ||
228 | u8 mtrr_type_lookup(u64 start, u64 end) | ||
229 | { | ||
230 | u8 type, prev_type; | ||
231 | int repeat; | ||
232 | u64 partial_end; | ||
233 | |||
234 | type = __mtrr_type_lookup(start, end, &partial_end, &repeat); | ||
235 | |||
236 | /* | ||
237 | * Common path is with repeat = 0. | ||
238 | * However, we can have cases where [start:end] spans across some | ||
239 | * MTRR range. Do repeated lookups for that case here. | ||
240 | */ | ||
241 | while (repeat) { | ||
242 | prev_type = type; | ||
243 | start = partial_end; | ||
244 | type = __mtrr_type_lookup(start, end, &partial_end, &repeat); | ||
245 | |||
246 | if (check_type_overlap(&prev_type, &type)) | ||
247 | return type; | ||
248 | } | ||
249 | |||
250 | return type; | ||
251 | } | ||
252 | |||
169 | /* Get the MSR pair relating to a var range */ | 253 | /* Get the MSR pair relating to a var range */ |
170 | static void | 254 | static void |
171 | get_mtrr_var_range(unsigned int index, struct mtrr_var_range *vr) | 255 | get_mtrr_var_range(unsigned int index, struct mtrr_var_range *vr) |
diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c index 01c0f3ee6cc3..929739a653d1 100644 --- a/arch/x86/kernel/cpu/mtrr/main.c +++ b/arch/x86/kernel/cpu/mtrr/main.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <linux/cpu.h> | 45 | #include <linux/cpu.h> |
46 | #include <linux/pci.h> | 46 | #include <linux/pci.h> |
47 | #include <linux/smp.h> | 47 | #include <linux/smp.h> |
48 | #include <linux/syscore_ops.h> | ||
48 | 49 | ||
49 | #include <asm/processor.h> | 50 | #include <asm/processor.h> |
50 | #include <asm/e820.h> | 51 | #include <asm/e820.h> |
@@ -292,14 +293,24 @@ set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type typ | |||
292 | 293 | ||
293 | /* | 294 | /* |
294 | * HACK! | 295 | * HACK! |
295 | * We use this same function to initialize the mtrrs on boot. | 296 | * |
296 | * The state of the boot cpu's mtrrs has been saved, and we want | 297 | * We use this same function to initialize the mtrrs during boot, |
297 | * to replicate across all the APs. | 298 | * resume, runtime cpu online and on an explicit request to set a |
298 | * If we're doing that @reg is set to something special... | 299 | * specific MTRR. |
300 | * | ||
301 | * During boot or suspend, the state of the boot cpu's mtrrs has been | ||
302 | * saved, and we want to replicate that across all the cpus that come | ||
303 | * online (either at the end of boot or resume or during a runtime cpu | ||
304 | * online). If we're doing that, @reg is set to something special and on | ||
305 | * this cpu we still do mtrr_if->set_all(). During boot/resume, this | ||
306 | * is unnecessary if at this point we are still on the cpu that started | ||
307 | * the boot/resume sequence. But there is no guarantee that we are still | ||
308 | * on the same cpu. So we do mtrr_if->set_all() on this cpu aswell to be | ||
309 | * sure that we are in sync with everyone else. | ||
299 | */ | 310 | */ |
300 | if (reg != ~0U) | 311 | if (reg != ~0U) |
301 | mtrr_if->set(reg, base, size, type); | 312 | mtrr_if->set(reg, base, size, type); |
302 | else if (!mtrr_aps_delayed_init) | 313 | else |
303 | mtrr_if->set_all(); | 314 | mtrr_if->set_all(); |
304 | 315 | ||
305 | /* Wait for the others */ | 316 | /* Wait for the others */ |
@@ -630,7 +641,7 @@ struct mtrr_value { | |||
630 | 641 | ||
631 | static struct mtrr_value mtrr_value[MTRR_MAX_VAR_RANGES]; | 642 | static struct mtrr_value mtrr_value[MTRR_MAX_VAR_RANGES]; |
632 | 643 | ||
633 | static int mtrr_save(struct sys_device *sysdev, pm_message_t state) | 644 | static int mtrr_save(void) |
634 | { | 645 | { |
635 | int i; | 646 | int i; |
636 | 647 | ||
@@ -642,7 +653,7 @@ static int mtrr_save(struct sys_device *sysdev, pm_message_t state) | |||
642 | return 0; | 653 | return 0; |
643 | } | 654 | } |
644 | 655 | ||
645 | static int mtrr_restore(struct sys_device *sysdev) | 656 | static void mtrr_restore(void) |
646 | { | 657 | { |
647 | int i; | 658 | int i; |
648 | 659 | ||
@@ -653,12 +664,11 @@ static int mtrr_restore(struct sys_device *sysdev) | |||
653 | mtrr_value[i].ltype); | 664 | mtrr_value[i].ltype); |
654 | } | 665 | } |
655 | } | 666 | } |
656 | return 0; | ||
657 | } | 667 | } |
658 | 668 | ||
659 | 669 | ||
660 | 670 | ||
661 | static struct sysdev_driver mtrr_sysdev_driver = { | 671 | static struct syscore_ops mtrr_syscore_ops = { |
662 | .suspend = mtrr_save, | 672 | .suspend = mtrr_save, |
663 | .resume = mtrr_restore, | 673 | .resume = mtrr_restore, |
664 | }; | 674 | }; |
@@ -793,13 +803,21 @@ void set_mtrr_aps_delayed_init(void) | |||
793 | } | 803 | } |
794 | 804 | ||
795 | /* | 805 | /* |
796 | * MTRR initialization for all AP's | 806 | * Delayed MTRR initialization for all AP's |
797 | */ | 807 | */ |
798 | void mtrr_aps_init(void) | 808 | void mtrr_aps_init(void) |
799 | { | 809 | { |
800 | if (!use_intel()) | 810 | if (!use_intel()) |
801 | return; | 811 | return; |
802 | 812 | ||
813 | /* | ||
814 | * Check if someone has requested the delay of AP MTRR initialization, | ||
815 | * by doing set_mtrr_aps_delayed_init(), prior to this point. If not, | ||
816 | * then we are done. | ||
817 | */ | ||
818 | if (!mtrr_aps_delayed_init) | ||
819 | return; | ||
820 | |||
803 | set_mtrr(~0U, 0, 0, 0); | 821 | set_mtrr(~0U, 0, 0, 0); |
804 | mtrr_aps_delayed_init = false; | 822 | mtrr_aps_delayed_init = false; |
805 | } | 823 | } |
@@ -831,7 +849,7 @@ static int __init mtrr_init_finialize(void) | |||
831 | * TBD: is there any system with such CPU which supports | 849 | * TBD: is there any system with such CPU which supports |
832 | * suspend/resume? If no, we should remove the code. | 850 | * suspend/resume? If no, we should remove the code. |
833 | */ | 851 | */ |
834 | sysdev_driver_register(&cpu_sysdev_class, &mtrr_sysdev_driver); | 852 | register_syscore_ops(&mtrr_syscore_ops); |
835 | 853 | ||
836 | return 0; | 854 | return 0; |
837 | } | 855 | } |
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index 03a5b0385ad6..3a0338b4b179 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include <asm/stacktrace.h> | 30 | #include <asm/stacktrace.h> |
31 | #include <asm/nmi.h> | 31 | #include <asm/nmi.h> |
32 | #include <asm/compat.h> | 32 | #include <asm/compat.h> |
33 | #include <asm/smp.h> | ||
34 | #include <asm/alternative.h> | ||
33 | 35 | ||
34 | #if 0 | 36 | #if 0 |
35 | #undef wrmsrl | 37 | #undef wrmsrl |
@@ -49,7 +51,6 @@ static unsigned long | |||
49 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | 51 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) |
50 | { | 52 | { |
51 | unsigned long offset, addr = (unsigned long)from; | 53 | unsigned long offset, addr = (unsigned long)from; |
52 | int type = in_nmi() ? KM_NMI : KM_IRQ0; | ||
53 | unsigned long size, len = 0; | 54 | unsigned long size, len = 0; |
54 | struct page *page; | 55 | struct page *page; |
55 | void *map; | 56 | void *map; |
@@ -63,9 +64,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | |||
63 | offset = addr & (PAGE_SIZE - 1); | 64 | offset = addr & (PAGE_SIZE - 1); |
64 | size = min(PAGE_SIZE - offset, n - len); | 65 | size = min(PAGE_SIZE - offset, n - len); |
65 | 66 | ||
66 | map = kmap_atomic(page, type); | 67 | map = kmap_atomic(page); |
67 | memcpy(to, map+offset, size); | 68 | memcpy(to, map+offset, size); |
68 | kunmap_atomic(map, type); | 69 | kunmap_atomic(map); |
69 | put_page(page); | 70 | put_page(page); |
70 | 71 | ||
71 | len += size; | 72 | len += size; |
@@ -94,6 +95,8 @@ struct amd_nb { | |||
94 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; | 95 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; |
95 | }; | 96 | }; |
96 | 97 | ||
98 | struct intel_percore; | ||
99 | |||
97 | #define MAX_LBR_ENTRIES 16 | 100 | #define MAX_LBR_ENTRIES 16 |
98 | 101 | ||
99 | struct cpu_hw_events { | 102 | struct cpu_hw_events { |
@@ -129,6 +132,13 @@ struct cpu_hw_events { | |||
129 | struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES]; | 132 | struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES]; |
130 | 133 | ||
131 | /* | 134 | /* |
135 | * Intel percore register state. | ||
136 | * Coordinate shared resources between HT threads. | ||
137 | */ | ||
138 | int percore_used; /* Used by this CPU? */ | ||
139 | struct intel_percore *per_core; | ||
140 | |||
141 | /* | ||
132 | * AMD specific bits | 142 | * AMD specific bits |
133 | */ | 143 | */ |
134 | struct amd_nb *amd_nb; | 144 | struct amd_nb *amd_nb; |
@@ -167,7 +177,7 @@ struct cpu_hw_events { | |||
167 | /* | 177 | /* |
168 | * Constraint on the Event code + UMask | 178 | * Constraint on the Event code + UMask |
169 | */ | 179 | */ |
170 | #define PEBS_EVENT_CONSTRAINT(c, n) \ | 180 | #define INTEL_UEVENT_CONSTRAINT(c, n) \ |
171 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK) | 181 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK) |
172 | 182 | ||
173 | #define EVENT_CONSTRAINT_END \ | 183 | #define EVENT_CONSTRAINT_END \ |
@@ -176,6 +186,28 @@ struct cpu_hw_events { | |||
176 | #define for_each_event_constraint(e, c) \ | 186 | #define for_each_event_constraint(e, c) \ |
177 | for ((e) = (c); (e)->weight; (e)++) | 187 | for ((e) = (c); (e)->weight; (e)++) |
178 | 188 | ||
189 | /* | ||
190 | * Extra registers for specific events. | ||
191 | * Some events need large masks and require external MSRs. | ||
192 | * Define a mapping to these extra registers. | ||
193 | */ | ||
194 | struct extra_reg { | ||
195 | unsigned int event; | ||
196 | unsigned int msr; | ||
197 | u64 config_mask; | ||
198 | u64 valid_mask; | ||
199 | }; | ||
200 | |||
201 | #define EVENT_EXTRA_REG(e, ms, m, vm) { \ | ||
202 | .event = (e), \ | ||
203 | .msr = (ms), \ | ||
204 | .config_mask = (m), \ | ||
205 | .valid_mask = (vm), \ | ||
206 | } | ||
207 | #define INTEL_EVENT_EXTRA_REG(event, msr, vm) \ | ||
208 | EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT, vm) | ||
209 | #define EVENT_EXTRA_END EVENT_EXTRA_REG(0, 0, 0, 0) | ||
210 | |||
179 | union perf_capabilities { | 211 | union perf_capabilities { |
180 | struct { | 212 | struct { |
181 | u64 lbr_format : 6; | 213 | u64 lbr_format : 6; |
@@ -220,6 +252,7 @@ struct x86_pmu { | |||
220 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, | 252 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, |
221 | struct perf_event *event); | 253 | struct perf_event *event); |
222 | struct event_constraint *event_constraints; | 254 | struct event_constraint *event_constraints; |
255 | struct event_constraint *percore_constraints; | ||
223 | void (*quirks)(void); | 256 | void (*quirks)(void); |
224 | int perfctr_second_write; | 257 | int perfctr_second_write; |
225 | 258 | ||
@@ -238,6 +271,7 @@ struct x86_pmu { | |||
238 | * Intel DebugStore bits | 271 | * Intel DebugStore bits |
239 | */ | 272 | */ |
240 | int bts, pebs; | 273 | int bts, pebs; |
274 | int bts_active, pebs_active; | ||
241 | int pebs_record_size; | 275 | int pebs_record_size; |
242 | void (*drain_pebs)(struct pt_regs *regs); | 276 | void (*drain_pebs)(struct pt_regs *regs); |
243 | struct event_constraint *pebs_constraints; | 277 | struct event_constraint *pebs_constraints; |
@@ -247,6 +281,11 @@ struct x86_pmu { | |||
247 | */ | 281 | */ |
248 | unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */ | 282 | unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */ |
249 | int lbr_nr; /* hardware stack size */ | 283 | int lbr_nr; /* hardware stack size */ |
284 | |||
285 | /* | ||
286 | * Extra registers for events | ||
287 | */ | ||
288 | struct extra_reg *extra_regs; | ||
250 | }; | 289 | }; |
251 | 290 | ||
252 | static struct x86_pmu x86_pmu __read_mostly; | 291 | static struct x86_pmu x86_pmu __read_mostly; |
@@ -271,6 +310,10 @@ static u64 __read_mostly hw_cache_event_ids | |||
271 | [PERF_COUNT_HW_CACHE_MAX] | 310 | [PERF_COUNT_HW_CACHE_MAX] |
272 | [PERF_COUNT_HW_CACHE_OP_MAX] | 311 | [PERF_COUNT_HW_CACHE_OP_MAX] |
273 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | 312 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; |
313 | static u64 __read_mostly hw_cache_extra_regs | ||
314 | [PERF_COUNT_HW_CACHE_MAX] | ||
315 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
316 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | ||
274 | 317 | ||
275 | /* | 318 | /* |
276 | * Propagate event elapsed time into the generic event. | 319 | * Propagate event elapsed time into the generic event. |
@@ -298,7 +341,7 @@ x86_perf_event_update(struct perf_event *event) | |||
298 | */ | 341 | */ |
299 | again: | 342 | again: |
300 | prev_raw_count = local64_read(&hwc->prev_count); | 343 | prev_raw_count = local64_read(&hwc->prev_count); |
301 | rdmsrl(hwc->event_base + idx, new_raw_count); | 344 | rdmsrl(hwc->event_base, new_raw_count); |
302 | 345 | ||
303 | if (local64_cmpxchg(&hwc->prev_count, prev_raw_count, | 346 | if (local64_cmpxchg(&hwc->prev_count, prev_raw_count, |
304 | new_raw_count) != prev_raw_count) | 347 | new_raw_count) != prev_raw_count) |
@@ -321,6 +364,55 @@ again: | |||
321 | return new_raw_count; | 364 | return new_raw_count; |
322 | } | 365 | } |
323 | 366 | ||
367 | static inline int x86_pmu_addr_offset(int index) | ||
368 | { | ||
369 | int offset; | ||
370 | |||
371 | /* offset = X86_FEATURE_PERFCTR_CORE ? index << 1 : index */ | ||
372 | alternative_io(ASM_NOP2, | ||
373 | "shll $1, %%eax", | ||
374 | X86_FEATURE_PERFCTR_CORE, | ||
375 | "=a" (offset), | ||
376 | "a" (index)); | ||
377 | |||
378 | return offset; | ||
379 | } | ||
380 | |||
381 | static inline unsigned int x86_pmu_config_addr(int index) | ||
382 | { | ||
383 | return x86_pmu.eventsel + x86_pmu_addr_offset(index); | ||
384 | } | ||
385 | |||
386 | static inline unsigned int x86_pmu_event_addr(int index) | ||
387 | { | ||
388 | return x86_pmu.perfctr + x86_pmu_addr_offset(index); | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * Find and validate any extra registers to set up. | ||
393 | */ | ||
394 | static int x86_pmu_extra_regs(u64 config, struct perf_event *event) | ||
395 | { | ||
396 | struct extra_reg *er; | ||
397 | |||
398 | event->hw.extra_reg = 0; | ||
399 | event->hw.extra_config = 0; | ||
400 | |||
401 | if (!x86_pmu.extra_regs) | ||
402 | return 0; | ||
403 | |||
404 | for (er = x86_pmu.extra_regs; er->msr; er++) { | ||
405 | if (er->event != (config & er->config_mask)) | ||
406 | continue; | ||
407 | if (event->attr.config1 & ~er->valid_mask) | ||
408 | return -EINVAL; | ||
409 | event->hw.extra_reg = er->msr; | ||
410 | event->hw.extra_config = event->attr.config1; | ||
411 | break; | ||
412 | } | ||
413 | return 0; | ||
414 | } | ||
415 | |||
324 | static atomic_t active_events; | 416 | static atomic_t active_events; |
325 | static DEFINE_MUTEX(pmc_reserve_mutex); | 417 | static DEFINE_MUTEX(pmc_reserve_mutex); |
326 | 418 | ||
@@ -330,16 +422,13 @@ static bool reserve_pmc_hardware(void) | |||
330 | { | 422 | { |
331 | int i; | 423 | int i; |
332 | 424 | ||
333 | if (nmi_watchdog == NMI_LOCAL_APIC) | ||
334 | disable_lapic_nmi_watchdog(); | ||
335 | |||
336 | for (i = 0; i < x86_pmu.num_counters; i++) { | 425 | for (i = 0; i < x86_pmu.num_counters; i++) { |
337 | if (!reserve_perfctr_nmi(x86_pmu.perfctr + i)) | 426 | if (!reserve_perfctr_nmi(x86_pmu_event_addr(i))) |
338 | goto perfctr_fail; | 427 | goto perfctr_fail; |
339 | } | 428 | } |
340 | 429 | ||
341 | for (i = 0; i < x86_pmu.num_counters; i++) { | 430 | for (i = 0; i < x86_pmu.num_counters; i++) { |
342 | if (!reserve_evntsel_nmi(x86_pmu.eventsel + i)) | 431 | if (!reserve_evntsel_nmi(x86_pmu_config_addr(i))) |
343 | goto eventsel_fail; | 432 | goto eventsel_fail; |
344 | } | 433 | } |
345 | 434 | ||
@@ -347,16 +436,13 @@ static bool reserve_pmc_hardware(void) | |||
347 | 436 | ||
348 | eventsel_fail: | 437 | eventsel_fail: |
349 | for (i--; i >= 0; i--) | 438 | for (i--; i >= 0; i--) |
350 | release_evntsel_nmi(x86_pmu.eventsel + i); | 439 | release_evntsel_nmi(x86_pmu_config_addr(i)); |
351 | 440 | ||
352 | i = x86_pmu.num_counters; | 441 | i = x86_pmu.num_counters; |
353 | 442 | ||
354 | perfctr_fail: | 443 | perfctr_fail: |
355 | for (i--; i >= 0; i--) | 444 | for (i--; i >= 0; i--) |
356 | release_perfctr_nmi(x86_pmu.perfctr + i); | 445 | release_perfctr_nmi(x86_pmu_event_addr(i)); |
357 | |||
358 | if (nmi_watchdog == NMI_LOCAL_APIC) | ||
359 | enable_lapic_nmi_watchdog(); | ||
360 | 446 | ||
361 | return false; | 447 | return false; |
362 | } | 448 | } |
@@ -366,12 +452,9 @@ static void release_pmc_hardware(void) | |||
366 | int i; | 452 | int i; |
367 | 453 | ||
368 | for (i = 0; i < x86_pmu.num_counters; i++) { | 454 | for (i = 0; i < x86_pmu.num_counters; i++) { |
369 | release_perfctr_nmi(x86_pmu.perfctr + i); | 455 | release_perfctr_nmi(x86_pmu_event_addr(i)); |
370 | release_evntsel_nmi(x86_pmu.eventsel + i); | 456 | release_evntsel_nmi(x86_pmu_config_addr(i)); |
371 | } | 457 | } |
372 | |||
373 | if (nmi_watchdog == NMI_LOCAL_APIC) | ||
374 | enable_lapic_nmi_watchdog(); | ||
375 | } | 458 | } |
376 | 459 | ||
377 | #else | 460 | #else |
@@ -381,7 +464,64 @@ static void release_pmc_hardware(void) {} | |||
381 | 464 | ||
382 | #endif | 465 | #endif |
383 | 466 | ||
384 | static int reserve_ds_buffers(void); | 467 | static bool check_hw_exists(void) |
468 | { | ||
469 | u64 val, val_new = 0; | ||
470 | int i, reg, ret = 0; | ||
471 | |||
472 | /* | ||
473 | * Check to see if the BIOS enabled any of the counters, if so | ||
474 | * complain and bail. | ||
475 | */ | ||
476 | for (i = 0; i < x86_pmu.num_counters; i++) { | ||
477 | reg = x86_pmu_config_addr(i); | ||
478 | ret = rdmsrl_safe(reg, &val); | ||
479 | if (ret) | ||
480 | goto msr_fail; | ||
481 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) | ||
482 | goto bios_fail; | ||
483 | } | ||
484 | |||
485 | if (x86_pmu.num_counters_fixed) { | ||
486 | reg = MSR_ARCH_PERFMON_FIXED_CTR_CTRL; | ||
487 | ret = rdmsrl_safe(reg, &val); | ||
488 | if (ret) | ||
489 | goto msr_fail; | ||
490 | for (i = 0; i < x86_pmu.num_counters_fixed; i++) { | ||
491 | if (val & (0x03 << i*4)) | ||
492 | goto bios_fail; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | /* | ||
497 | * Now write a value and read it back to see if it matches, | ||
498 | * this is needed to detect certain hardware emulators (qemu/kvm) | ||
499 | * that don't trap on the MSR access and always return 0s. | ||
500 | */ | ||
501 | val = 0xabcdUL; | ||
502 | ret = checking_wrmsrl(x86_pmu_event_addr(0), val); | ||
503 | ret |= rdmsrl_safe(x86_pmu_event_addr(0), &val_new); | ||
504 | if (ret || val != val_new) | ||
505 | goto msr_fail; | ||
506 | |||
507 | return true; | ||
508 | |||
509 | bios_fail: | ||
510 | /* | ||
511 | * We still allow the PMU driver to operate: | ||
512 | */ | ||
513 | printk(KERN_CONT "Broken BIOS detected, complain to your hardware vendor.\n"); | ||
514 | printk(KERN_ERR FW_BUG "the BIOS has corrupted hw-PMU resources (MSR %x is %Lx)\n", reg, val); | ||
515 | |||
516 | return true; | ||
517 | |||
518 | msr_fail: | ||
519 | printk(KERN_CONT "Broken PMU hardware detected, using software events only.\n"); | ||
520 | |||
521 | return false; | ||
522 | } | ||
523 | |||
524 | static void reserve_ds_buffers(void); | ||
385 | static void release_ds_buffers(void); | 525 | static void release_ds_buffers(void); |
386 | 526 | ||
387 | static void hw_perf_event_destroy(struct perf_event *event) | 527 | static void hw_perf_event_destroy(struct perf_event *event) |
@@ -399,8 +539,9 @@ static inline int x86_pmu_initialized(void) | |||
399 | } | 539 | } |
400 | 540 | ||
401 | static inline int | 541 | static inline int |
402 | set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr) | 542 | set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event *event) |
403 | { | 543 | { |
544 | struct perf_event_attr *attr = &event->attr; | ||
404 | unsigned int cache_type, cache_op, cache_result; | 545 | unsigned int cache_type, cache_op, cache_result; |
405 | u64 config, val; | 546 | u64 config, val; |
406 | 547 | ||
@@ -427,8 +568,8 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr) | |||
427 | return -EINVAL; | 568 | return -EINVAL; |
428 | 569 | ||
429 | hwc->config |= val; | 570 | hwc->config |= val; |
430 | 571 | attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result]; | |
431 | return 0; | 572 | return x86_pmu_extra_regs(val, event); |
432 | } | 573 | } |
433 | 574 | ||
434 | static int x86_setup_perfctr(struct perf_event *event) | 575 | static int x86_setup_perfctr(struct perf_event *event) |
@@ -437,7 +578,7 @@ static int x86_setup_perfctr(struct perf_event *event) | |||
437 | struct hw_perf_event *hwc = &event->hw; | 578 | struct hw_perf_event *hwc = &event->hw; |
438 | u64 config; | 579 | u64 config; |
439 | 580 | ||
440 | if (!hwc->sample_period) { | 581 | if (!is_sampling_event(event)) { |
441 | hwc->sample_period = x86_pmu.max_period; | 582 | hwc->sample_period = x86_pmu.max_period; |
442 | hwc->last_period = hwc->sample_period; | 583 | hwc->last_period = hwc->sample_period; |
443 | local64_set(&hwc->period_left, hwc->sample_period); | 584 | local64_set(&hwc->period_left, hwc->sample_period); |
@@ -452,11 +593,15 @@ static int x86_setup_perfctr(struct perf_event *event) | |||
452 | return -EOPNOTSUPP; | 593 | return -EOPNOTSUPP; |
453 | } | 594 | } |
454 | 595 | ||
596 | /* | ||
597 | * Do not allow config1 (extended registers) to propagate, | ||
598 | * there's no sane user-space generalization yet: | ||
599 | */ | ||
455 | if (attr->type == PERF_TYPE_RAW) | 600 | if (attr->type == PERF_TYPE_RAW) |
456 | return 0; | 601 | return 0; |
457 | 602 | ||
458 | if (attr->type == PERF_TYPE_HW_CACHE) | 603 | if (attr->type == PERF_TYPE_HW_CACHE) |
459 | return set_ext_hw_attr(hwc, attr); | 604 | return set_ext_hw_attr(hwc, event); |
460 | 605 | ||
461 | if (attr->config >= x86_pmu.max_events) | 606 | if (attr->config >= x86_pmu.max_events) |
462 | return -EINVAL; | 607 | return -EINVAL; |
@@ -475,10 +620,10 @@ static int x86_setup_perfctr(struct perf_event *event) | |||
475 | /* | 620 | /* |
476 | * Branch tracing: | 621 | * Branch tracing: |
477 | */ | 622 | */ |
478 | if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && | 623 | if (attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS && |
479 | (hwc->sample_period == 1)) { | 624 | !attr->freq && hwc->sample_period == 1) { |
480 | /* BTS is not supported by this architecture. */ | 625 | /* BTS is not supported by this architecture. */ |
481 | if (!x86_pmu.bts) | 626 | if (!x86_pmu.bts_active) |
482 | return -EOPNOTSUPP; | 627 | return -EOPNOTSUPP; |
483 | 628 | ||
484 | /* BTS is currently only allowed for user-mode. */ | 629 | /* BTS is currently only allowed for user-mode. */ |
@@ -497,12 +642,13 @@ static int x86_pmu_hw_config(struct perf_event *event) | |||
497 | int precise = 0; | 642 | int precise = 0; |
498 | 643 | ||
499 | /* Support for constant skid */ | 644 | /* Support for constant skid */ |
500 | if (x86_pmu.pebs) | 645 | if (x86_pmu.pebs_active) { |
501 | precise++; | 646 | precise++; |
502 | 647 | ||
503 | /* Support for IP fixup */ | 648 | /* Support for IP fixup */ |
504 | if (x86_pmu.lbr_nr) | 649 | if (x86_pmu.lbr_nr) |
505 | precise++; | 650 | precise++; |
651 | } | ||
506 | 652 | ||
507 | if (event->attr.precise_ip > precise) | 653 | if (event->attr.precise_ip > precise) |
508 | return -EOPNOTSUPP; | 654 | return -EOPNOTSUPP; |
@@ -531,7 +677,7 @@ static int x86_pmu_hw_config(struct perf_event *event) | |||
531 | /* | 677 | /* |
532 | * Setup the hardware configuration for a given attr_type | 678 | * Setup the hardware configuration for a given attr_type |
533 | */ | 679 | */ |
534 | static int __hw_perf_event_init(struct perf_event *event) | 680 | static int __x86_pmu_event_init(struct perf_event *event) |
535 | { | 681 | { |
536 | int err; | 682 | int err; |
537 | 683 | ||
@@ -544,11 +690,8 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
544 | if (atomic_read(&active_events) == 0) { | 690 | if (atomic_read(&active_events) == 0) { |
545 | if (!reserve_pmc_hardware()) | 691 | if (!reserve_pmc_hardware()) |
546 | err = -EBUSY; | 692 | err = -EBUSY; |
547 | else { | 693 | else |
548 | err = reserve_ds_buffers(); | 694 | reserve_ds_buffers(); |
549 | if (err) | ||
550 | release_pmc_hardware(); | ||
551 | } | ||
552 | } | 695 | } |
553 | if (!err) | 696 | if (!err) |
554 | atomic_inc(&active_events); | 697 | atomic_inc(&active_events); |
@@ -576,15 +719,15 @@ static void x86_pmu_disable_all(void) | |||
576 | 719 | ||
577 | if (!test_bit(idx, cpuc->active_mask)) | 720 | if (!test_bit(idx, cpuc->active_mask)) |
578 | continue; | 721 | continue; |
579 | rdmsrl(x86_pmu.eventsel + idx, val); | 722 | rdmsrl(x86_pmu_config_addr(idx), val); |
580 | if (!(val & ARCH_PERFMON_EVENTSEL_ENABLE)) | 723 | if (!(val & ARCH_PERFMON_EVENTSEL_ENABLE)) |
581 | continue; | 724 | continue; |
582 | val &= ~ARCH_PERFMON_EVENTSEL_ENABLE; | 725 | val &= ~ARCH_PERFMON_EVENTSEL_ENABLE; |
583 | wrmsrl(x86_pmu.eventsel + idx, val); | 726 | wrmsrl(x86_pmu_config_addr(idx), val); |
584 | } | 727 | } |
585 | } | 728 | } |
586 | 729 | ||
587 | void hw_perf_disable(void) | 730 | static void x86_pmu_disable(struct pmu *pmu) |
588 | { | 731 | { |
589 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 732 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
590 | 733 | ||
@@ -601,25 +744,30 @@ void hw_perf_disable(void) | |||
601 | x86_pmu.disable_all(); | 744 | x86_pmu.disable_all(); |
602 | } | 745 | } |
603 | 746 | ||
747 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc, | ||
748 | u64 enable_mask) | ||
749 | { | ||
750 | if (hwc->extra_reg) | ||
751 | wrmsrl(hwc->extra_reg, hwc->extra_config); | ||
752 | wrmsrl(hwc->config_base, hwc->config | enable_mask); | ||
753 | } | ||
754 | |||
604 | static void x86_pmu_enable_all(int added) | 755 | static void x86_pmu_enable_all(int added) |
605 | { | 756 | { |
606 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 757 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
607 | int idx; | 758 | int idx; |
608 | 759 | ||
609 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | 760 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
610 | struct perf_event *event = cpuc->events[idx]; | 761 | struct hw_perf_event *hwc = &cpuc->events[idx]->hw; |
611 | u64 val; | ||
612 | 762 | ||
613 | if (!test_bit(idx, cpuc->active_mask)) | 763 | if (!test_bit(idx, cpuc->active_mask)) |
614 | continue; | 764 | continue; |
615 | 765 | ||
616 | val = event->hw.config; | 766 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); |
617 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; | ||
618 | wrmsrl(x86_pmu.eventsel + idx, val); | ||
619 | } | 767 | } |
620 | } | 768 | } |
621 | 769 | ||
622 | static const struct pmu pmu; | 770 | static struct pmu pmu; |
623 | 771 | ||
624 | static inline int is_x86_event(struct perf_event *event) | 772 | static inline int is_x86_event(struct perf_event *event) |
625 | { | 773 | { |
@@ -780,15 +928,10 @@ static inline void x86_assign_hw_event(struct perf_event *event, | |||
780 | hwc->event_base = 0; | 928 | hwc->event_base = 0; |
781 | } else if (hwc->idx >= X86_PMC_IDX_FIXED) { | 929 | } else if (hwc->idx >= X86_PMC_IDX_FIXED) { |
782 | hwc->config_base = MSR_ARCH_PERFMON_FIXED_CTR_CTRL; | 930 | hwc->config_base = MSR_ARCH_PERFMON_FIXED_CTR_CTRL; |
783 | /* | 931 | hwc->event_base = MSR_ARCH_PERFMON_FIXED_CTR0 + (hwc->idx - X86_PMC_IDX_FIXED); |
784 | * We set it so that event_base + idx in wrmsr/rdmsr maps to | ||
785 | * MSR_ARCH_PERFMON_FIXED_CTR0 ... CTR2: | ||
786 | */ | ||
787 | hwc->event_base = | ||
788 | MSR_ARCH_PERFMON_FIXED_CTR0 - X86_PMC_IDX_FIXED; | ||
789 | } else { | 932 | } else { |
790 | hwc->config_base = x86_pmu.eventsel; | 933 | hwc->config_base = x86_pmu_config_addr(hwc->idx); |
791 | hwc->event_base = x86_pmu.perfctr; | 934 | hwc->event_base = x86_pmu_event_addr(hwc->idx); |
792 | } | 935 | } |
793 | } | 936 | } |
794 | 937 | ||
@@ -801,10 +944,10 @@ static inline int match_prev_assignment(struct hw_perf_event *hwc, | |||
801 | hwc->last_tag == cpuc->tags[i]; | 944 | hwc->last_tag == cpuc->tags[i]; |
802 | } | 945 | } |
803 | 946 | ||
804 | static int x86_pmu_start(struct perf_event *event); | 947 | static void x86_pmu_start(struct perf_event *event, int flags); |
805 | static void x86_pmu_stop(struct perf_event *event); | 948 | static void x86_pmu_stop(struct perf_event *event, int flags); |
806 | 949 | ||
807 | void hw_perf_enable(void) | 950 | static void x86_pmu_enable(struct pmu *pmu) |
808 | { | 951 | { |
809 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 952 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
810 | struct perf_event *event; | 953 | struct perf_event *event; |
@@ -840,7 +983,14 @@ void hw_perf_enable(void) | |||
840 | match_prev_assignment(hwc, cpuc, i)) | 983 | match_prev_assignment(hwc, cpuc, i)) |
841 | continue; | 984 | continue; |
842 | 985 | ||
843 | x86_pmu_stop(event); | 986 | /* |
987 | * Ensure we don't accidentally enable a stopped | ||
988 | * counter simply because we rescheduled. | ||
989 | */ | ||
990 | if (hwc->state & PERF_HES_STOPPED) | ||
991 | hwc->state |= PERF_HES_ARCH; | ||
992 | |||
993 | x86_pmu_stop(event, PERF_EF_UPDATE); | ||
844 | } | 994 | } |
845 | 995 | ||
846 | for (i = 0; i < cpuc->n_events; i++) { | 996 | for (i = 0; i < cpuc->n_events; i++) { |
@@ -852,7 +1002,10 @@ void hw_perf_enable(void) | |||
852 | else if (i < n_running) | 1002 | else if (i < n_running) |
853 | continue; | 1003 | continue; |
854 | 1004 | ||
855 | x86_pmu_start(event); | 1005 | if (hwc->state & PERF_HES_ARCH) |
1006 | continue; | ||
1007 | |||
1008 | x86_pmu_start(event, PERF_EF_RELOAD); | ||
856 | } | 1009 | } |
857 | cpuc->n_added = 0; | 1010 | cpuc->n_added = 0; |
858 | perf_events_lapic_init(); | 1011 | perf_events_lapic_init(); |
@@ -864,17 +1017,11 @@ void hw_perf_enable(void) | |||
864 | x86_pmu.enable_all(added); | 1017 | x86_pmu.enable_all(added); |
865 | } | 1018 | } |
866 | 1019 | ||
867 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc, | ||
868 | u64 enable_mask) | ||
869 | { | ||
870 | wrmsrl(hwc->config_base + hwc->idx, hwc->config | enable_mask); | ||
871 | } | ||
872 | |||
873 | static inline void x86_pmu_disable_event(struct perf_event *event) | 1020 | static inline void x86_pmu_disable_event(struct perf_event *event) |
874 | { | 1021 | { |
875 | struct hw_perf_event *hwc = &event->hw; | 1022 | struct hw_perf_event *hwc = &event->hw; |
876 | 1023 | ||
877 | wrmsrl(hwc->config_base + hwc->idx, hwc->config); | 1024 | wrmsrl(hwc->config_base, hwc->config); |
878 | } | 1025 | } |
879 | 1026 | ||
880 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); | 1027 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); |
@@ -927,7 +1074,7 @@ x86_perf_event_set_period(struct perf_event *event) | |||
927 | */ | 1074 | */ |
928 | local64_set(&hwc->prev_count, (u64)-left); | 1075 | local64_set(&hwc->prev_count, (u64)-left); |
929 | 1076 | ||
930 | wrmsrl(hwc->event_base + idx, (u64)(-left) & x86_pmu.cntval_mask); | 1077 | wrmsrl(hwc->event_base, (u64)(-left) & x86_pmu.cntval_mask); |
931 | 1078 | ||
932 | /* | 1079 | /* |
933 | * Due to erratum on certan cpu we need | 1080 | * Due to erratum on certan cpu we need |
@@ -935,7 +1082,7 @@ x86_perf_event_set_period(struct perf_event *event) | |||
935 | * is updated properly | 1082 | * is updated properly |
936 | */ | 1083 | */ |
937 | if (x86_pmu.perfctr_second_write) { | 1084 | if (x86_pmu.perfctr_second_write) { |
938 | wrmsrl(hwc->event_base + idx, | 1085 | wrmsrl(hwc->event_base, |
939 | (u64)(-left) & x86_pmu.cntval_mask); | 1086 | (u64)(-left) & x86_pmu.cntval_mask); |
940 | } | 1087 | } |
941 | 1088 | ||
@@ -946,22 +1093,18 @@ x86_perf_event_set_period(struct perf_event *event) | |||
946 | 1093 | ||
947 | static void x86_pmu_enable_event(struct perf_event *event) | 1094 | static void x86_pmu_enable_event(struct perf_event *event) |
948 | { | 1095 | { |
949 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1096 | if (__this_cpu_read(cpu_hw_events.enabled)) |
950 | if (cpuc->enabled) | ||
951 | __x86_pmu_enable_event(&event->hw, | 1097 | __x86_pmu_enable_event(&event->hw, |
952 | ARCH_PERFMON_EVENTSEL_ENABLE); | 1098 | ARCH_PERFMON_EVENTSEL_ENABLE); |
953 | } | 1099 | } |
954 | 1100 | ||
955 | /* | 1101 | /* |
956 | * activate a single event | 1102 | * Add a single event to the PMU. |
957 | * | 1103 | * |
958 | * The event is added to the group of enabled events | 1104 | * The event is added to the group of enabled events |
959 | * but only if it can be scehduled with existing events. | 1105 | * but only if it can be scehduled with existing events. |
960 | * | ||
961 | * Called with PMU disabled. If successful and return value 1, | ||
962 | * then guaranteed to call perf_enable() and hw_perf_enable() | ||
963 | */ | 1106 | */ |
964 | static int x86_pmu_enable(struct perf_event *event) | 1107 | static int x86_pmu_add(struct perf_event *event, int flags) |
965 | { | 1108 | { |
966 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1109 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
967 | struct hw_perf_event *hwc; | 1110 | struct hw_perf_event *hwc; |
@@ -970,58 +1113,67 @@ static int x86_pmu_enable(struct perf_event *event) | |||
970 | 1113 | ||
971 | hwc = &event->hw; | 1114 | hwc = &event->hw; |
972 | 1115 | ||
1116 | perf_pmu_disable(event->pmu); | ||
973 | n0 = cpuc->n_events; | 1117 | n0 = cpuc->n_events; |
974 | n = collect_events(cpuc, event, false); | 1118 | ret = n = collect_events(cpuc, event, false); |
975 | if (n < 0) | 1119 | if (ret < 0) |
976 | return n; | 1120 | goto out; |
1121 | |||
1122 | hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED; | ||
1123 | if (!(flags & PERF_EF_START)) | ||
1124 | hwc->state |= PERF_HES_ARCH; | ||
977 | 1125 | ||
978 | /* | 1126 | /* |
979 | * If group events scheduling transaction was started, | 1127 | * If group events scheduling transaction was started, |
980 | * skip the schedulability test here, it will be peformed | 1128 | * skip the schedulability test here, it will be performed |
981 | * at commit time(->commit_txn) as a whole | 1129 | * at commit time (->commit_txn) as a whole |
982 | */ | 1130 | */ |
983 | if (cpuc->group_flag & PERF_EVENT_TXN) | 1131 | if (cpuc->group_flag & PERF_EVENT_TXN) |
984 | goto out; | 1132 | goto done_collect; |
985 | 1133 | ||
986 | ret = x86_pmu.schedule_events(cpuc, n, assign); | 1134 | ret = x86_pmu.schedule_events(cpuc, n, assign); |
987 | if (ret) | 1135 | if (ret) |
988 | return ret; | 1136 | goto out; |
989 | /* | 1137 | /* |
990 | * copy new assignment, now we know it is possible | 1138 | * copy new assignment, now we know it is possible |
991 | * will be used by hw_perf_enable() | 1139 | * will be used by hw_perf_enable() |
992 | */ | 1140 | */ |
993 | memcpy(cpuc->assign, assign, n*sizeof(int)); | 1141 | memcpy(cpuc->assign, assign, n*sizeof(int)); |
994 | 1142 | ||
995 | out: | 1143 | done_collect: |
996 | cpuc->n_events = n; | 1144 | cpuc->n_events = n; |
997 | cpuc->n_added += n - n0; | 1145 | cpuc->n_added += n - n0; |
998 | cpuc->n_txn += n - n0; | 1146 | cpuc->n_txn += n - n0; |
999 | 1147 | ||
1000 | return 0; | 1148 | ret = 0; |
1149 | out: | ||
1150 | perf_pmu_enable(event->pmu); | ||
1151 | return ret; | ||
1001 | } | 1152 | } |
1002 | 1153 | ||
1003 | static int x86_pmu_start(struct perf_event *event) | 1154 | static void x86_pmu_start(struct perf_event *event, int flags) |
1004 | { | 1155 | { |
1005 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1156 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
1006 | int idx = event->hw.idx; | 1157 | int idx = event->hw.idx; |
1007 | 1158 | ||
1008 | if (idx == -1) | 1159 | if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED))) |
1009 | return -EAGAIN; | 1160 | return; |
1161 | |||
1162 | if (WARN_ON_ONCE(idx == -1)) | ||
1163 | return; | ||
1164 | |||
1165 | if (flags & PERF_EF_RELOAD) { | ||
1166 | WARN_ON_ONCE(!(event->hw.state & PERF_HES_UPTODATE)); | ||
1167 | x86_perf_event_set_period(event); | ||
1168 | } | ||
1169 | |||
1170 | event->hw.state = 0; | ||
1010 | 1171 | ||
1011 | x86_perf_event_set_period(event); | ||
1012 | cpuc->events[idx] = event; | 1172 | cpuc->events[idx] = event; |
1013 | __set_bit(idx, cpuc->active_mask); | 1173 | __set_bit(idx, cpuc->active_mask); |
1014 | __set_bit(idx, cpuc->running); | 1174 | __set_bit(idx, cpuc->running); |
1015 | x86_pmu.enable(event); | 1175 | x86_pmu.enable(event); |
1016 | perf_event_update_userpage(event); | 1176 | perf_event_update_userpage(event); |
1017 | |||
1018 | return 0; | ||
1019 | } | ||
1020 | |||
1021 | static void x86_pmu_unthrottle(struct perf_event *event) | ||
1022 | { | ||
1023 | int ret = x86_pmu_start(event); | ||
1024 | WARN_ON_ONCE(ret); | ||
1025 | } | 1177 | } |
1026 | 1178 | ||
1027 | void perf_event_print_debug(void) | 1179 | void perf_event_print_debug(void) |
@@ -1057,8 +1209,8 @@ void perf_event_print_debug(void) | |||
1057 | pr_info("CPU#%d: active: %016llx\n", cpu, *(u64 *)cpuc->active_mask); | 1209 | pr_info("CPU#%d: active: %016llx\n", cpu, *(u64 *)cpuc->active_mask); |
1058 | 1210 | ||
1059 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | 1211 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
1060 | rdmsrl(x86_pmu.eventsel + idx, pmc_ctrl); | 1212 | rdmsrl(x86_pmu_config_addr(idx), pmc_ctrl); |
1061 | rdmsrl(x86_pmu.perfctr + idx, pmc_count); | 1213 | rdmsrl(x86_pmu_event_addr(idx), pmc_count); |
1062 | 1214 | ||
1063 | prev_left = per_cpu(pmc_prev_left[idx], cpu); | 1215 | prev_left = per_cpu(pmc_prev_left[idx], cpu); |
1064 | 1216 | ||
@@ -1078,27 +1230,29 @@ void perf_event_print_debug(void) | |||
1078 | local_irq_restore(flags); | 1230 | local_irq_restore(flags); |
1079 | } | 1231 | } |
1080 | 1232 | ||
1081 | static void x86_pmu_stop(struct perf_event *event) | 1233 | static void x86_pmu_stop(struct perf_event *event, int flags) |
1082 | { | 1234 | { |
1083 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1235 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
1084 | struct hw_perf_event *hwc = &event->hw; | 1236 | struct hw_perf_event *hwc = &event->hw; |
1085 | int idx = hwc->idx; | ||
1086 | |||
1087 | if (!__test_and_clear_bit(idx, cpuc->active_mask)) | ||
1088 | return; | ||
1089 | 1237 | ||
1090 | x86_pmu.disable(event); | 1238 | if (__test_and_clear_bit(hwc->idx, cpuc->active_mask)) { |
1091 | 1239 | x86_pmu.disable(event); | |
1092 | /* | 1240 | cpuc->events[hwc->idx] = NULL; |
1093 | * Drain the remaining delta count out of a event | 1241 | WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED); |
1094 | * that we are disabling: | 1242 | hwc->state |= PERF_HES_STOPPED; |
1095 | */ | 1243 | } |
1096 | x86_perf_event_update(event); | ||
1097 | 1244 | ||
1098 | cpuc->events[idx] = NULL; | 1245 | if ((flags & PERF_EF_UPDATE) && !(hwc->state & PERF_HES_UPTODATE)) { |
1246 | /* | ||
1247 | * Drain the remaining delta count out of a event | ||
1248 | * that we are disabling: | ||
1249 | */ | ||
1250 | x86_perf_event_update(event); | ||
1251 | hwc->state |= PERF_HES_UPTODATE; | ||
1252 | } | ||
1099 | } | 1253 | } |
1100 | 1254 | ||
1101 | static void x86_pmu_disable(struct perf_event *event) | 1255 | static void x86_pmu_del(struct perf_event *event, int flags) |
1102 | { | 1256 | { |
1103 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1257 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
1104 | int i; | 1258 | int i; |
@@ -1111,7 +1265,7 @@ static void x86_pmu_disable(struct perf_event *event) | |||
1111 | if (cpuc->group_flag & PERF_EVENT_TXN) | 1265 | if (cpuc->group_flag & PERF_EVENT_TXN) |
1112 | return; | 1266 | return; |
1113 | 1267 | ||
1114 | x86_pmu_stop(event); | 1268 | x86_pmu_stop(event, PERF_EF_UPDATE); |
1115 | 1269 | ||
1116 | for (i = 0; i < cpuc->n_events; i++) { | 1270 | for (i = 0; i < cpuc->n_events; i++) { |
1117 | if (event == cpuc->event_list[i]) { | 1271 | if (event == cpuc->event_list[i]) { |
@@ -1134,7 +1288,6 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1134 | struct perf_sample_data data; | 1288 | struct perf_sample_data data; |
1135 | struct cpu_hw_events *cpuc; | 1289 | struct cpu_hw_events *cpuc; |
1136 | struct perf_event *event; | 1290 | struct perf_event *event; |
1137 | struct hw_perf_event *hwc; | ||
1138 | int idx, handled = 0; | 1291 | int idx, handled = 0; |
1139 | u64 val; | 1292 | u64 val; |
1140 | 1293 | ||
@@ -1142,6 +1295,16 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1142 | 1295 | ||
1143 | cpuc = &__get_cpu_var(cpu_hw_events); | 1296 | cpuc = &__get_cpu_var(cpu_hw_events); |
1144 | 1297 | ||
1298 | /* | ||
1299 | * Some chipsets need to unmask the LVTPC in a particular spot | ||
1300 | * inside the nmi handler. As a result, the unmasking was pushed | ||
1301 | * into all the nmi handlers. | ||
1302 | * | ||
1303 | * This generic handler doesn't seem to have any issues where the | ||
1304 | * unmasking occurs so it was left at the top. | ||
1305 | */ | ||
1306 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
1307 | |||
1145 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | 1308 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
1146 | if (!test_bit(idx, cpuc->active_mask)) { | 1309 | if (!test_bit(idx, cpuc->active_mask)) { |
1147 | /* | 1310 | /* |
@@ -1155,7 +1318,6 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1155 | } | 1318 | } |
1156 | 1319 | ||
1157 | event = cpuc->events[idx]; | 1320 | event = cpuc->events[idx]; |
1158 | hwc = &event->hw; | ||
1159 | 1321 | ||
1160 | val = x86_perf_event_update(event); | 1322 | val = x86_perf_event_update(event); |
1161 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) | 1323 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) |
@@ -1171,7 +1333,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1171 | continue; | 1333 | continue; |
1172 | 1334 | ||
1173 | if (perf_event_overflow(event, 1, &data, regs)) | 1335 | if (perf_event_overflow(event, 1, &data, regs)) |
1174 | x86_pmu_stop(event); | 1336 | x86_pmu_stop(event, 0); |
1175 | } | 1337 | } |
1176 | 1338 | ||
1177 | if (handled) | 1339 | if (handled) |
@@ -1180,25 +1342,6 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1180 | return handled; | 1342 | return handled; |
1181 | } | 1343 | } |
1182 | 1344 | ||
1183 | void smp_perf_pending_interrupt(struct pt_regs *regs) | ||
1184 | { | ||
1185 | irq_enter(); | ||
1186 | ack_APIC_irq(); | ||
1187 | inc_irq_stat(apic_pending_irqs); | ||
1188 | perf_event_do_pending(); | ||
1189 | irq_exit(); | ||
1190 | } | ||
1191 | |||
1192 | void set_perf_event_pending(void) | ||
1193 | { | ||
1194 | #ifdef CONFIG_X86_LOCAL_APIC | ||
1195 | if (!x86_pmu.apic || !x86_pmu_initialized()) | ||
1196 | return; | ||
1197 | |||
1198 | apic->send_IPI_self(LOCAL_PENDING_VECTOR); | ||
1199 | #endif | ||
1200 | } | ||
1201 | |||
1202 | void perf_events_lapic_init(void) | 1345 | void perf_events_lapic_init(void) |
1203 | { | 1346 | { |
1204 | if (!x86_pmu.apic || !x86_pmu_initialized()) | 1347 | if (!x86_pmu.apic || !x86_pmu_initialized()) |
@@ -1230,11 +1373,10 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1230 | 1373 | ||
1231 | switch (cmd) { | 1374 | switch (cmd) { |
1232 | case DIE_NMI: | 1375 | case DIE_NMI: |
1233 | case DIE_NMI_IPI: | ||
1234 | break; | 1376 | break; |
1235 | case DIE_NMIUNKNOWN: | 1377 | case DIE_NMIUNKNOWN: |
1236 | this_nmi = percpu_read(irq_stat.__nmi_count); | 1378 | this_nmi = percpu_read(irq_stat.__nmi_count); |
1237 | if (this_nmi != __get_cpu_var(pmu_nmi).marked) | 1379 | if (this_nmi != __this_cpu_read(pmu_nmi.marked)) |
1238 | /* let the kernel handle the unknown nmi */ | 1380 | /* let the kernel handle the unknown nmi */ |
1239 | return NOTIFY_DONE; | 1381 | return NOTIFY_DONE; |
1240 | /* | 1382 | /* |
@@ -1249,8 +1391,6 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1249 | return NOTIFY_DONE; | 1391 | return NOTIFY_DONE; |
1250 | } | 1392 | } |
1251 | 1393 | ||
1252 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
1253 | |||
1254 | handled = x86_pmu.handle_irq(args->regs); | 1394 | handled = x86_pmu.handle_irq(args->regs); |
1255 | if (!handled) | 1395 | if (!handled) |
1256 | return NOTIFY_DONE; | 1396 | return NOTIFY_DONE; |
@@ -1258,8 +1398,8 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1258 | this_nmi = percpu_read(irq_stat.__nmi_count); | 1398 | this_nmi = percpu_read(irq_stat.__nmi_count); |
1259 | if ((handled > 1) || | 1399 | if ((handled > 1) || |
1260 | /* the next nmi could be a back-to-back nmi */ | 1400 | /* the next nmi could be a back-to-back nmi */ |
1261 | ((__get_cpu_var(pmu_nmi).marked == this_nmi) && | 1401 | ((__this_cpu_read(pmu_nmi.marked) == this_nmi) && |
1262 | (__get_cpu_var(pmu_nmi).handled > 1))) { | 1402 | (__this_cpu_read(pmu_nmi.handled) > 1))) { |
1263 | /* | 1403 | /* |
1264 | * We could have two subsequent back-to-back nmis: The | 1404 | * We could have two subsequent back-to-back nmis: The |
1265 | * first handles more than one counter, the 2nd | 1405 | * first handles more than one counter, the 2nd |
@@ -1270,8 +1410,8 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1270 | * handling more than one counter. We will mark the | 1410 | * handling more than one counter. We will mark the |
1271 | * next (3rd) and then drop it if unhandled. | 1411 | * next (3rd) and then drop it if unhandled. |
1272 | */ | 1412 | */ |
1273 | __get_cpu_var(pmu_nmi).marked = this_nmi + 1; | 1413 | __this_cpu_write(pmu_nmi.marked, this_nmi + 1); |
1274 | __get_cpu_var(pmu_nmi).handled = handled; | 1414 | __this_cpu_write(pmu_nmi.handled, handled); |
1275 | } | 1415 | } |
1276 | 1416 | ||
1277 | return NOTIFY_STOP; | 1417 | return NOTIFY_STOP; |
@@ -1280,7 +1420,7 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1280 | static __read_mostly struct notifier_block perf_event_nmi_notifier = { | 1420 | static __read_mostly struct notifier_block perf_event_nmi_notifier = { |
1281 | .notifier_call = perf_event_nmi_handler, | 1421 | .notifier_call = perf_event_nmi_handler, |
1282 | .next = NULL, | 1422 | .next = NULL, |
1283 | .priority = 1 | 1423 | .priority = NMI_LOCAL_LOW_PRIOR, |
1284 | }; | 1424 | }; |
1285 | 1425 | ||
1286 | static struct event_constraint unconstrained; | 1426 | static struct event_constraint unconstrained; |
@@ -1353,7 +1493,7 @@ static void __init pmu_check_apic(void) | |||
1353 | pr_info("no hardware sampling interrupt available.\n"); | 1493 | pr_info("no hardware sampling interrupt available.\n"); |
1354 | } | 1494 | } |
1355 | 1495 | ||
1356 | void __init init_hw_perf_events(void) | 1496 | static int __init init_hw_perf_events(void) |
1357 | { | 1497 | { |
1358 | struct event_constraint *c; | 1498 | struct event_constraint *c; |
1359 | int err; | 1499 | int err; |
@@ -1368,15 +1508,19 @@ void __init init_hw_perf_events(void) | |||
1368 | err = amd_pmu_init(); | 1508 | err = amd_pmu_init(); |
1369 | break; | 1509 | break; |
1370 | default: | 1510 | default: |
1371 | return; | 1511 | return 0; |
1372 | } | 1512 | } |
1373 | if (err != 0) { | 1513 | if (err != 0) { |
1374 | pr_cont("no PMU driver, software events only.\n"); | 1514 | pr_cont("no PMU driver, software events only.\n"); |
1375 | return; | 1515 | return 0; |
1376 | } | 1516 | } |
1377 | 1517 | ||
1378 | pmu_check_apic(); | 1518 | pmu_check_apic(); |
1379 | 1519 | ||
1520 | /* sanity check that the hardware exists or is emulated */ | ||
1521 | if (!check_hw_exists()) | ||
1522 | return 0; | ||
1523 | |||
1380 | pr_cont("%s PMU driver.\n", x86_pmu.name); | 1524 | pr_cont("%s PMU driver.\n", x86_pmu.name); |
1381 | 1525 | ||
1382 | if (x86_pmu.quirks) | 1526 | if (x86_pmu.quirks) |
@@ -1388,7 +1532,6 @@ void __init init_hw_perf_events(void) | |||
1388 | x86_pmu.num_counters = X86_PMC_MAX_GENERIC; | 1532 | x86_pmu.num_counters = X86_PMC_MAX_GENERIC; |
1389 | } | 1533 | } |
1390 | x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1; | 1534 | x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1; |
1391 | perf_max_events = x86_pmu.num_counters; | ||
1392 | 1535 | ||
1393 | if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) { | 1536 | if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) { |
1394 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", | 1537 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", |
@@ -1424,8 +1567,12 @@ void __init init_hw_perf_events(void) | |||
1424 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_counters_fixed); | 1567 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_counters_fixed); |
1425 | pr_info("... event mask: %016Lx\n", x86_pmu.intel_ctrl); | 1568 | pr_info("... event mask: %016Lx\n", x86_pmu.intel_ctrl); |
1426 | 1569 | ||
1570 | perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW); | ||
1427 | perf_cpu_notifier(x86_pmu_notifier); | 1571 | perf_cpu_notifier(x86_pmu_notifier); |
1572 | |||
1573 | return 0; | ||
1428 | } | 1574 | } |
1575 | early_initcall(init_hw_perf_events); | ||
1429 | 1576 | ||
1430 | static inline void x86_pmu_read(struct perf_event *event) | 1577 | static inline void x86_pmu_read(struct perf_event *event) |
1431 | { | 1578 | { |
@@ -1437,12 +1584,11 @@ static inline void x86_pmu_read(struct perf_event *event) | |||
1437 | * Set the flag to make pmu::enable() not perform the | 1584 | * Set the flag to make pmu::enable() not perform the |
1438 | * schedulability test, it will be performed at commit time | 1585 | * schedulability test, it will be performed at commit time |
1439 | */ | 1586 | */ |
1440 | static void x86_pmu_start_txn(const struct pmu *pmu) | 1587 | static void x86_pmu_start_txn(struct pmu *pmu) |
1441 | { | 1588 | { |
1442 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1589 | perf_pmu_disable(pmu); |
1443 | 1590 | __this_cpu_or(cpu_hw_events.group_flag, PERF_EVENT_TXN); | |
1444 | cpuc->group_flag |= PERF_EVENT_TXN; | 1591 | __this_cpu_write(cpu_hw_events.n_txn, 0); |
1445 | cpuc->n_txn = 0; | ||
1446 | } | 1592 | } |
1447 | 1593 | ||
1448 | /* | 1594 | /* |
@@ -1450,16 +1596,15 @@ static void x86_pmu_start_txn(const struct pmu *pmu) | |||
1450 | * Clear the flag and pmu::enable() will perform the | 1596 | * Clear the flag and pmu::enable() will perform the |
1451 | * schedulability test. | 1597 | * schedulability test. |
1452 | */ | 1598 | */ |
1453 | static void x86_pmu_cancel_txn(const struct pmu *pmu) | 1599 | static void x86_pmu_cancel_txn(struct pmu *pmu) |
1454 | { | 1600 | { |
1455 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1601 | __this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN); |
1456 | |||
1457 | cpuc->group_flag &= ~PERF_EVENT_TXN; | ||
1458 | /* | 1602 | /* |
1459 | * Truncate the collected events. | 1603 | * Truncate the collected events. |
1460 | */ | 1604 | */ |
1461 | cpuc->n_added -= cpuc->n_txn; | 1605 | __this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn)); |
1462 | cpuc->n_events -= cpuc->n_txn; | 1606 | __this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn)); |
1607 | perf_pmu_enable(pmu); | ||
1463 | } | 1608 | } |
1464 | 1609 | ||
1465 | /* | 1610 | /* |
@@ -1467,7 +1612,7 @@ static void x86_pmu_cancel_txn(const struct pmu *pmu) | |||
1467 | * Perform the group schedulability test as a whole | 1612 | * Perform the group schedulability test as a whole |
1468 | * Return 0 if success | 1613 | * Return 0 if success |
1469 | */ | 1614 | */ |
1470 | static int x86_pmu_commit_txn(const struct pmu *pmu) | 1615 | static int x86_pmu_commit_txn(struct pmu *pmu) |
1471 | { | 1616 | { |
1472 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 1617 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
1473 | int assign[X86_PMC_IDX_MAX]; | 1618 | int assign[X86_PMC_IDX_MAX]; |
@@ -1489,22 +1634,10 @@ static int x86_pmu_commit_txn(const struct pmu *pmu) | |||
1489 | memcpy(cpuc->assign, assign, n*sizeof(int)); | 1634 | memcpy(cpuc->assign, assign, n*sizeof(int)); |
1490 | 1635 | ||
1491 | cpuc->group_flag &= ~PERF_EVENT_TXN; | 1636 | cpuc->group_flag &= ~PERF_EVENT_TXN; |
1492 | 1637 | perf_pmu_enable(pmu); | |
1493 | return 0; | 1638 | return 0; |
1494 | } | 1639 | } |
1495 | 1640 | ||
1496 | static const struct pmu pmu = { | ||
1497 | .enable = x86_pmu_enable, | ||
1498 | .disable = x86_pmu_disable, | ||
1499 | .start = x86_pmu_start, | ||
1500 | .stop = x86_pmu_stop, | ||
1501 | .read = x86_pmu_read, | ||
1502 | .unthrottle = x86_pmu_unthrottle, | ||
1503 | .start_txn = x86_pmu_start_txn, | ||
1504 | .cancel_txn = x86_pmu_cancel_txn, | ||
1505 | .commit_txn = x86_pmu_commit_txn, | ||
1506 | }; | ||
1507 | |||
1508 | /* | 1641 | /* |
1509 | * validate that we can schedule this event | 1642 | * validate that we can schedule this event |
1510 | */ | 1643 | */ |
@@ -1579,12 +1712,22 @@ out: | |||
1579 | return ret; | 1712 | return ret; |
1580 | } | 1713 | } |
1581 | 1714 | ||
1582 | const struct pmu *hw_perf_event_init(struct perf_event *event) | 1715 | static int x86_pmu_event_init(struct perf_event *event) |
1583 | { | 1716 | { |
1584 | const struct pmu *tmp; | 1717 | struct pmu *tmp; |
1585 | int err; | 1718 | int err; |
1586 | 1719 | ||
1587 | err = __hw_perf_event_init(event); | 1720 | switch (event->attr.type) { |
1721 | case PERF_TYPE_RAW: | ||
1722 | case PERF_TYPE_HARDWARE: | ||
1723 | case PERF_TYPE_HW_CACHE: | ||
1724 | break; | ||
1725 | |||
1726 | default: | ||
1727 | return -ENOENT; | ||
1728 | } | ||
1729 | |||
1730 | err = __x86_pmu_event_init(event); | ||
1588 | if (!err) { | 1731 | if (!err) { |
1589 | /* | 1732 | /* |
1590 | * we temporarily connect event to its pmu | 1733 | * we temporarily connect event to its pmu |
@@ -1604,37 +1747,31 @@ const struct pmu *hw_perf_event_init(struct perf_event *event) | |||
1604 | if (err) { | 1747 | if (err) { |
1605 | if (event->destroy) | 1748 | if (event->destroy) |
1606 | event->destroy(event); | 1749 | event->destroy(event); |
1607 | return ERR_PTR(err); | ||
1608 | } | 1750 | } |
1609 | 1751 | ||
1610 | return &pmu; | 1752 | return err; |
1611 | } | 1753 | } |
1612 | 1754 | ||
1613 | /* | 1755 | static struct pmu pmu = { |
1614 | * callchain support | 1756 | .pmu_enable = x86_pmu_enable, |
1615 | */ | 1757 | .pmu_disable = x86_pmu_disable, |
1616 | |||
1617 | static inline | ||
1618 | void callchain_store(struct perf_callchain_entry *entry, u64 ip) | ||
1619 | { | ||
1620 | if (entry->nr < PERF_MAX_STACK_DEPTH) | ||
1621 | entry->ip[entry->nr++] = ip; | ||
1622 | } | ||
1623 | 1758 | ||
1624 | static DEFINE_PER_CPU(struct perf_callchain_entry, pmc_irq_entry); | 1759 | .event_init = x86_pmu_event_init, |
1625 | static DEFINE_PER_CPU(struct perf_callchain_entry, pmc_nmi_entry); | ||
1626 | 1760 | ||
1761 | .add = x86_pmu_add, | ||
1762 | .del = x86_pmu_del, | ||
1763 | .start = x86_pmu_start, | ||
1764 | .stop = x86_pmu_stop, | ||
1765 | .read = x86_pmu_read, | ||
1627 | 1766 | ||
1628 | static void | 1767 | .start_txn = x86_pmu_start_txn, |
1629 | backtrace_warning_symbol(void *data, char *msg, unsigned long symbol) | 1768 | .cancel_txn = x86_pmu_cancel_txn, |
1630 | { | 1769 | .commit_txn = x86_pmu_commit_txn, |
1631 | /* Ignore warnings */ | 1770 | }; |
1632 | } | ||
1633 | 1771 | ||
1634 | static void backtrace_warning(void *data, char *msg) | 1772 | /* |
1635 | { | 1773 | * callchain support |
1636 | /* Ignore warnings */ | 1774 | */ |
1637 | } | ||
1638 | 1775 | ||
1639 | static int backtrace_stack(void *data, char *name) | 1776 | static int backtrace_stack(void *data, char *name) |
1640 | { | 1777 | { |
@@ -1645,24 +1782,26 @@ static void backtrace_address(void *data, unsigned long addr, int reliable) | |||
1645 | { | 1782 | { |
1646 | struct perf_callchain_entry *entry = data; | 1783 | struct perf_callchain_entry *entry = data; |
1647 | 1784 | ||
1648 | callchain_store(entry, addr); | 1785 | perf_callchain_store(entry, addr); |
1649 | } | 1786 | } |
1650 | 1787 | ||
1651 | static const struct stacktrace_ops backtrace_ops = { | 1788 | static const struct stacktrace_ops backtrace_ops = { |
1652 | .warning = backtrace_warning, | ||
1653 | .warning_symbol = backtrace_warning_symbol, | ||
1654 | .stack = backtrace_stack, | 1789 | .stack = backtrace_stack, |
1655 | .address = backtrace_address, | 1790 | .address = backtrace_address, |
1656 | .walk_stack = print_context_stack_bp, | 1791 | .walk_stack = print_context_stack_bp, |
1657 | }; | 1792 | }; |
1658 | 1793 | ||
1659 | static void | 1794 | void |
1660 | perf_callchain_kernel(struct pt_regs *regs, struct perf_callchain_entry *entry) | 1795 | perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs) |
1661 | { | 1796 | { |
1662 | callchain_store(entry, PERF_CONTEXT_KERNEL); | 1797 | if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { |
1663 | callchain_store(entry, regs->ip); | 1798 | /* TODO: We don't support guest os callchain now */ |
1799 | return; | ||
1800 | } | ||
1801 | |||
1802 | perf_callchain_store(entry, regs->ip); | ||
1664 | 1803 | ||
1665 | dump_trace(NULL, regs, NULL, regs->bp, &backtrace_ops, entry); | 1804 | dump_trace(NULL, regs, NULL, 0, &backtrace_ops, entry); |
1666 | } | 1805 | } |
1667 | 1806 | ||
1668 | #ifdef CONFIG_COMPAT | 1807 | #ifdef CONFIG_COMPAT |
@@ -1689,7 +1828,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) | |||
1689 | if (fp < compat_ptr(regs->sp)) | 1828 | if (fp < compat_ptr(regs->sp)) |
1690 | break; | 1829 | break; |
1691 | 1830 | ||
1692 | callchain_store(entry, frame.return_address); | 1831 | perf_callchain_store(entry, frame.return_address); |
1693 | fp = compat_ptr(frame.next_frame); | 1832 | fp = compat_ptr(frame.next_frame); |
1694 | } | 1833 | } |
1695 | return 1; | 1834 | return 1; |
@@ -1702,19 +1841,20 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) | |||
1702 | } | 1841 | } |
1703 | #endif | 1842 | #endif |
1704 | 1843 | ||
1705 | static void | 1844 | void |
1706 | perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) | 1845 | perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs) |
1707 | { | 1846 | { |
1708 | struct stack_frame frame; | 1847 | struct stack_frame frame; |
1709 | const void __user *fp; | 1848 | const void __user *fp; |
1710 | 1849 | ||
1711 | if (!user_mode(regs)) | 1850 | if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { |
1712 | regs = task_pt_regs(current); | 1851 | /* TODO: We don't support guest os callchain now */ |
1852 | return; | ||
1853 | } | ||
1713 | 1854 | ||
1714 | fp = (void __user *)regs->bp; | 1855 | fp = (void __user *)regs->bp; |
1715 | 1856 | ||
1716 | callchain_store(entry, PERF_CONTEXT_USER); | 1857 | perf_callchain_store(entry, regs->ip); |
1717 | callchain_store(entry, regs->ip); | ||
1718 | 1858 | ||
1719 | if (perf_callchain_user32(regs, entry)) | 1859 | if (perf_callchain_user32(regs, entry)) |
1720 | return; | 1860 | return; |
@@ -1731,52 +1871,11 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry) | |||
1731 | if ((unsigned long)fp < regs->sp) | 1871 | if ((unsigned long)fp < regs->sp) |
1732 | break; | 1872 | break; |
1733 | 1873 | ||
1734 | callchain_store(entry, frame.return_address); | 1874 | perf_callchain_store(entry, frame.return_address); |
1735 | fp = frame.next_frame; | 1875 | fp = frame.next_frame; |
1736 | } | 1876 | } |
1737 | } | 1877 | } |
1738 | 1878 | ||
1739 | static void | ||
1740 | perf_do_callchain(struct pt_regs *regs, struct perf_callchain_entry *entry) | ||
1741 | { | ||
1742 | int is_user; | ||
1743 | |||
1744 | if (!regs) | ||
1745 | return; | ||
1746 | |||
1747 | is_user = user_mode(regs); | ||
1748 | |||
1749 | if (is_user && current->state != TASK_RUNNING) | ||
1750 | return; | ||
1751 | |||
1752 | if (!is_user) | ||
1753 | perf_callchain_kernel(regs, entry); | ||
1754 | |||
1755 | if (current->mm) | ||
1756 | perf_callchain_user(regs, entry); | ||
1757 | } | ||
1758 | |||
1759 | struct perf_callchain_entry *perf_callchain(struct pt_regs *regs) | ||
1760 | { | ||
1761 | struct perf_callchain_entry *entry; | ||
1762 | |||
1763 | if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { | ||
1764 | /* TODO: We don't support guest os callchain now */ | ||
1765 | return NULL; | ||
1766 | } | ||
1767 | |||
1768 | if (in_nmi()) | ||
1769 | entry = &__get_cpu_var(pmc_nmi_entry); | ||
1770 | else | ||
1771 | entry = &__get_cpu_var(pmc_irq_entry); | ||
1772 | |||
1773 | entry->nr = 0; | ||
1774 | |||
1775 | perf_do_callchain(regs, entry); | ||
1776 | |||
1777 | return entry; | ||
1778 | } | ||
1779 | |||
1780 | unsigned long perf_instruction_pointer(struct pt_regs *regs) | 1879 | unsigned long perf_instruction_pointer(struct pt_regs *regs) |
1781 | { | 1880 | { |
1782 | unsigned long ip; | 1881 | unsigned long ip; |
diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c index c2897b7b4a3b..fe29c1d2219e 100644 --- a/arch/x86/kernel/cpu/perf_event_amd.c +++ b/arch/x86/kernel/cpu/perf_event_amd.c | |||
@@ -1,7 +1,5 @@ | |||
1 | #ifdef CONFIG_CPU_SUP_AMD | 1 | #ifdef CONFIG_CPU_SUP_AMD |
2 | 2 | ||
3 | static DEFINE_RAW_SPINLOCK(amd_nb_lock); | ||
4 | |||
5 | static __initconst const u64 amd_hw_cache_event_ids | 3 | static __initconst const u64 amd_hw_cache_event_ids |
6 | [PERF_COUNT_HW_CACHE_MAX] | 4 | [PERF_COUNT_HW_CACHE_MAX] |
7 | [PERF_COUNT_HW_CACHE_OP_MAX] | 5 | [PERF_COUNT_HW_CACHE_OP_MAX] |
@@ -10,7 +8,7 @@ static __initconst const u64 amd_hw_cache_event_ids | |||
10 | [ C(L1D) ] = { | 8 | [ C(L1D) ] = { |
11 | [ C(OP_READ) ] = { | 9 | [ C(OP_READ) ] = { |
12 | [ C(RESULT_ACCESS) ] = 0x0040, /* Data Cache Accesses */ | 10 | [ C(RESULT_ACCESS) ] = 0x0040, /* Data Cache Accesses */ |
13 | [ C(RESULT_MISS) ] = 0x0041, /* Data Cache Misses */ | 11 | [ C(RESULT_MISS) ] = 0x0141, /* Data Cache Misses */ |
14 | }, | 12 | }, |
15 | [ C(OP_WRITE) ] = { | 13 | [ C(OP_WRITE) ] = { |
16 | [ C(RESULT_ACCESS) ] = 0x0142, /* Data Cache Refills :system */ | 14 | [ C(RESULT_ACCESS) ] = 0x0142, /* Data Cache Refills :system */ |
@@ -52,7 +50,7 @@ static __initconst const u64 amd_hw_cache_event_ids | |||
52 | [ C(DTLB) ] = { | 50 | [ C(DTLB) ] = { |
53 | [ C(OP_READ) ] = { | 51 | [ C(OP_READ) ] = { |
54 | [ C(RESULT_ACCESS) ] = 0x0040, /* Data Cache Accesses */ | 52 | [ C(RESULT_ACCESS) ] = 0x0040, /* Data Cache Accesses */ |
55 | [ C(RESULT_MISS) ] = 0x0046, /* L1 DTLB and L2 DLTB Miss */ | 53 | [ C(RESULT_MISS) ] = 0x0746, /* L1_DTLB_AND_L2_DLTB_MISS.ALL */ |
56 | }, | 54 | }, |
57 | [ C(OP_WRITE) ] = { | 55 | [ C(OP_WRITE) ] = { |
58 | [ C(RESULT_ACCESS) ] = 0, | 56 | [ C(RESULT_ACCESS) ] = 0, |
@@ -66,7 +64,7 @@ static __initconst const u64 amd_hw_cache_event_ids | |||
66 | [ C(ITLB) ] = { | 64 | [ C(ITLB) ] = { |
67 | [ C(OP_READ) ] = { | 65 | [ C(OP_READ) ] = { |
68 | [ C(RESULT_ACCESS) ] = 0x0080, /* Instruction fecthes */ | 66 | [ C(RESULT_ACCESS) ] = 0x0080, /* Instruction fecthes */ |
69 | [ C(RESULT_MISS) ] = 0x0085, /* Instr. fetch ITLB misses */ | 67 | [ C(RESULT_MISS) ] = 0x0385, /* L1_ITLB_AND_L2_ITLB_MISS.ALL */ |
70 | }, | 68 | }, |
71 | [ C(OP_WRITE) ] = { | 69 | [ C(OP_WRITE) ] = { |
72 | [ C(RESULT_ACCESS) ] = -1, | 70 | [ C(RESULT_ACCESS) ] = -1, |
@@ -98,12 +96,14 @@ static __initconst const u64 amd_hw_cache_event_ids | |||
98 | */ | 96 | */ |
99 | static const u64 amd_perfmon_event_map[] = | 97 | static const u64 amd_perfmon_event_map[] = |
100 | { | 98 | { |
101 | [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, | 99 | [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, |
102 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, | 100 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, |
103 | [PERF_COUNT_HW_CACHE_REFERENCES] = 0x0080, | 101 | [PERF_COUNT_HW_CACHE_REFERENCES] = 0x0080, |
104 | [PERF_COUNT_HW_CACHE_MISSES] = 0x0081, | 102 | [PERF_COUNT_HW_CACHE_MISSES] = 0x0081, |
105 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, | 103 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, |
106 | [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, | 104 | [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, |
105 | [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x00d0, /* "Decoder empty" event */ | ||
106 | [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x00d1, /* "Dispatch stalls" event */ | ||
107 | }; | 107 | }; |
108 | 108 | ||
109 | static u64 amd_pmu_event_map(int hw_event) | 109 | static u64 amd_pmu_event_map(int hw_event) |
@@ -129,6 +129,11 @@ static int amd_pmu_hw_config(struct perf_event *event) | |||
129 | /* | 129 | /* |
130 | * AMD64 events are detected based on their event codes. | 130 | * AMD64 events are detected based on their event codes. |
131 | */ | 131 | */ |
132 | static inline unsigned int amd_get_event_code(struct hw_perf_event *hwc) | ||
133 | { | ||
134 | return ((hwc->config >> 24) & 0x0f00) | (hwc->config & 0x00ff); | ||
135 | } | ||
136 | |||
132 | static inline int amd_is_nb_event(struct hw_perf_event *hwc) | 137 | static inline int amd_is_nb_event(struct hw_perf_event *hwc) |
133 | { | 138 | { |
134 | return (hwc->config & 0xe0) == 0xe0; | 139 | return (hwc->config & 0xe0) == 0xe0; |
@@ -275,17 +280,17 @@ done: | |||
275 | return &emptyconstraint; | 280 | return &emptyconstraint; |
276 | } | 281 | } |
277 | 282 | ||
278 | static struct amd_nb *amd_alloc_nb(int cpu, int nb_id) | 283 | static struct amd_nb *amd_alloc_nb(int cpu) |
279 | { | 284 | { |
280 | struct amd_nb *nb; | 285 | struct amd_nb *nb; |
281 | int i; | 286 | int i; |
282 | 287 | ||
283 | nb = kmalloc(sizeof(struct amd_nb), GFP_KERNEL); | 288 | nb = kmalloc_node(sizeof(struct amd_nb), GFP_KERNEL | __GFP_ZERO, |
289 | cpu_to_node(cpu)); | ||
284 | if (!nb) | 290 | if (!nb) |
285 | return NULL; | 291 | return NULL; |
286 | 292 | ||
287 | memset(nb, 0, sizeof(*nb)); | 293 | nb->nb_id = -1; |
288 | nb->nb_id = nb_id; | ||
289 | 294 | ||
290 | /* | 295 | /* |
291 | * initialize all possible NB constraints | 296 | * initialize all possible NB constraints |
@@ -306,7 +311,7 @@ static int amd_pmu_cpu_prepare(int cpu) | |||
306 | if (boot_cpu_data.x86_max_cores < 2) | 311 | if (boot_cpu_data.x86_max_cores < 2) |
307 | return NOTIFY_OK; | 312 | return NOTIFY_OK; |
308 | 313 | ||
309 | cpuc->amd_nb = amd_alloc_nb(cpu, -1); | 314 | cpuc->amd_nb = amd_alloc_nb(cpu); |
310 | if (!cpuc->amd_nb) | 315 | if (!cpuc->amd_nb) |
311 | return NOTIFY_BAD; | 316 | return NOTIFY_BAD; |
312 | 317 | ||
@@ -325,8 +330,6 @@ static void amd_pmu_cpu_starting(int cpu) | |||
325 | nb_id = amd_get_nb_id(cpu); | 330 | nb_id = amd_get_nb_id(cpu); |
326 | WARN_ON_ONCE(nb_id == BAD_APICID); | 331 | WARN_ON_ONCE(nb_id == BAD_APICID); |
327 | 332 | ||
328 | raw_spin_lock(&amd_nb_lock); | ||
329 | |||
330 | for_each_online_cpu(i) { | 333 | for_each_online_cpu(i) { |
331 | nb = per_cpu(cpu_hw_events, i).amd_nb; | 334 | nb = per_cpu(cpu_hw_events, i).amd_nb; |
332 | if (WARN_ON_ONCE(!nb)) | 335 | if (WARN_ON_ONCE(!nb)) |
@@ -341,8 +344,6 @@ static void amd_pmu_cpu_starting(int cpu) | |||
341 | 344 | ||
342 | cpuc->amd_nb->nb_id = nb_id; | 345 | cpuc->amd_nb->nb_id = nb_id; |
343 | cpuc->amd_nb->refcnt++; | 346 | cpuc->amd_nb->refcnt++; |
344 | |||
345 | raw_spin_unlock(&amd_nb_lock); | ||
346 | } | 347 | } |
347 | 348 | ||
348 | static void amd_pmu_cpu_dead(int cpu) | 349 | static void amd_pmu_cpu_dead(int cpu) |
@@ -354,8 +355,6 @@ static void amd_pmu_cpu_dead(int cpu) | |||
354 | 355 | ||
355 | cpuhw = &per_cpu(cpu_hw_events, cpu); | 356 | cpuhw = &per_cpu(cpu_hw_events, cpu); |
356 | 357 | ||
357 | raw_spin_lock(&amd_nb_lock); | ||
358 | |||
359 | if (cpuhw->amd_nb) { | 358 | if (cpuhw->amd_nb) { |
360 | struct amd_nb *nb = cpuhw->amd_nb; | 359 | struct amd_nb *nb = cpuhw->amd_nb; |
361 | 360 | ||
@@ -364,8 +363,6 @@ static void amd_pmu_cpu_dead(int cpu) | |||
364 | 363 | ||
365 | cpuhw->amd_nb = NULL; | 364 | cpuhw->amd_nb = NULL; |
366 | } | 365 | } |
367 | |||
368 | raw_spin_unlock(&amd_nb_lock); | ||
369 | } | 366 | } |
370 | 367 | ||
371 | static __initconst const struct x86_pmu amd_pmu = { | 368 | static __initconst const struct x86_pmu amd_pmu = { |
@@ -395,13 +392,195 @@ static __initconst const struct x86_pmu amd_pmu = { | |||
395 | .cpu_dead = amd_pmu_cpu_dead, | 392 | .cpu_dead = amd_pmu_cpu_dead, |
396 | }; | 393 | }; |
397 | 394 | ||
395 | /* AMD Family 15h */ | ||
396 | |||
397 | #define AMD_EVENT_TYPE_MASK 0x000000F0ULL | ||
398 | |||
399 | #define AMD_EVENT_FP 0x00000000ULL ... 0x00000010ULL | ||
400 | #define AMD_EVENT_LS 0x00000020ULL ... 0x00000030ULL | ||
401 | #define AMD_EVENT_DC 0x00000040ULL ... 0x00000050ULL | ||
402 | #define AMD_EVENT_CU 0x00000060ULL ... 0x00000070ULL | ||
403 | #define AMD_EVENT_IC_DE 0x00000080ULL ... 0x00000090ULL | ||
404 | #define AMD_EVENT_EX_LS 0x000000C0ULL | ||
405 | #define AMD_EVENT_DE 0x000000D0ULL | ||
406 | #define AMD_EVENT_NB 0x000000E0ULL ... 0x000000F0ULL | ||
407 | |||
408 | /* | ||
409 | * AMD family 15h event code/PMC mappings: | ||
410 | * | ||
411 | * type = event_code & 0x0F0: | ||
412 | * | ||
413 | * 0x000 FP PERF_CTL[5:3] | ||
414 | * 0x010 FP PERF_CTL[5:3] | ||
415 | * 0x020 LS PERF_CTL[5:0] | ||
416 | * 0x030 LS PERF_CTL[5:0] | ||
417 | * 0x040 DC PERF_CTL[5:0] | ||
418 | * 0x050 DC PERF_CTL[5:0] | ||
419 | * 0x060 CU PERF_CTL[2:0] | ||
420 | * 0x070 CU PERF_CTL[2:0] | ||
421 | * 0x080 IC/DE PERF_CTL[2:0] | ||
422 | * 0x090 IC/DE PERF_CTL[2:0] | ||
423 | * 0x0A0 --- | ||
424 | * 0x0B0 --- | ||
425 | * 0x0C0 EX/LS PERF_CTL[5:0] | ||
426 | * 0x0D0 DE PERF_CTL[2:0] | ||
427 | * 0x0E0 NB NB_PERF_CTL[3:0] | ||
428 | * 0x0F0 NB NB_PERF_CTL[3:0] | ||
429 | * | ||
430 | * Exceptions: | ||
431 | * | ||
432 | * 0x000 FP PERF_CTL[3], PERF_CTL[5:3] (*) | ||
433 | * 0x003 FP PERF_CTL[3] | ||
434 | * 0x004 FP PERF_CTL[3], PERF_CTL[5:3] (*) | ||
435 | * 0x00B FP PERF_CTL[3] | ||
436 | * 0x00D FP PERF_CTL[3] | ||
437 | * 0x023 DE PERF_CTL[2:0] | ||
438 | * 0x02D LS PERF_CTL[3] | ||
439 | * 0x02E LS PERF_CTL[3,0] | ||
440 | * 0x043 CU PERF_CTL[2:0] | ||
441 | * 0x045 CU PERF_CTL[2:0] | ||
442 | * 0x046 CU PERF_CTL[2:0] | ||
443 | * 0x054 CU PERF_CTL[2:0] | ||
444 | * 0x055 CU PERF_CTL[2:0] | ||
445 | * 0x08F IC PERF_CTL[0] | ||
446 | * 0x187 DE PERF_CTL[0] | ||
447 | * 0x188 DE PERF_CTL[0] | ||
448 | * 0x0DB EX PERF_CTL[5:0] | ||
449 | * 0x0DC LS PERF_CTL[5:0] | ||
450 | * 0x0DD LS PERF_CTL[5:0] | ||
451 | * 0x0DE LS PERF_CTL[5:0] | ||
452 | * 0x0DF LS PERF_CTL[5:0] | ||
453 | * 0x1D6 EX PERF_CTL[5:0] | ||
454 | * 0x1D8 EX PERF_CTL[5:0] | ||
455 | * | ||
456 | * (*) depending on the umask all FPU counters may be used | ||
457 | */ | ||
458 | |||
459 | static struct event_constraint amd_f15_PMC0 = EVENT_CONSTRAINT(0, 0x01, 0); | ||
460 | static struct event_constraint amd_f15_PMC20 = EVENT_CONSTRAINT(0, 0x07, 0); | ||
461 | static struct event_constraint amd_f15_PMC3 = EVENT_CONSTRAINT(0, 0x08, 0); | ||
462 | static struct event_constraint amd_f15_PMC30 = EVENT_CONSTRAINT(0, 0x09, 0); | ||
463 | static struct event_constraint amd_f15_PMC50 = EVENT_CONSTRAINT(0, 0x3F, 0); | ||
464 | static struct event_constraint amd_f15_PMC53 = EVENT_CONSTRAINT(0, 0x38, 0); | ||
465 | |||
466 | static struct event_constraint * | ||
467 | amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *event) | ||
468 | { | ||
469 | struct hw_perf_event *hwc = &event->hw; | ||
470 | unsigned int event_code = amd_get_event_code(hwc); | ||
471 | |||
472 | switch (event_code & AMD_EVENT_TYPE_MASK) { | ||
473 | case AMD_EVENT_FP: | ||
474 | switch (event_code) { | ||
475 | case 0x000: | ||
476 | if (!(hwc->config & 0x0000F000ULL)) | ||
477 | break; | ||
478 | if (!(hwc->config & 0x00000F00ULL)) | ||
479 | break; | ||
480 | return &amd_f15_PMC3; | ||
481 | case 0x004: | ||
482 | if (hweight_long(hwc->config & ARCH_PERFMON_EVENTSEL_UMASK) <= 1) | ||
483 | break; | ||
484 | return &amd_f15_PMC3; | ||
485 | case 0x003: | ||
486 | case 0x00B: | ||
487 | case 0x00D: | ||
488 | return &amd_f15_PMC3; | ||
489 | } | ||
490 | return &amd_f15_PMC53; | ||
491 | case AMD_EVENT_LS: | ||
492 | case AMD_EVENT_DC: | ||
493 | case AMD_EVENT_EX_LS: | ||
494 | switch (event_code) { | ||
495 | case 0x023: | ||
496 | case 0x043: | ||
497 | case 0x045: | ||
498 | case 0x046: | ||
499 | case 0x054: | ||
500 | case 0x055: | ||
501 | return &amd_f15_PMC20; | ||
502 | case 0x02D: | ||
503 | return &amd_f15_PMC3; | ||
504 | case 0x02E: | ||
505 | return &amd_f15_PMC30; | ||
506 | default: | ||
507 | return &amd_f15_PMC50; | ||
508 | } | ||
509 | case AMD_EVENT_CU: | ||
510 | case AMD_EVENT_IC_DE: | ||
511 | case AMD_EVENT_DE: | ||
512 | switch (event_code) { | ||
513 | case 0x08F: | ||
514 | case 0x187: | ||
515 | case 0x188: | ||
516 | return &amd_f15_PMC0; | ||
517 | case 0x0DB ... 0x0DF: | ||
518 | case 0x1D6: | ||
519 | case 0x1D8: | ||
520 | return &amd_f15_PMC50; | ||
521 | default: | ||
522 | return &amd_f15_PMC20; | ||
523 | } | ||
524 | case AMD_EVENT_NB: | ||
525 | /* not yet implemented */ | ||
526 | return &emptyconstraint; | ||
527 | default: | ||
528 | return &emptyconstraint; | ||
529 | } | ||
530 | } | ||
531 | |||
532 | static __initconst const struct x86_pmu amd_pmu_f15h = { | ||
533 | .name = "AMD Family 15h", | ||
534 | .handle_irq = x86_pmu_handle_irq, | ||
535 | .disable_all = x86_pmu_disable_all, | ||
536 | .enable_all = x86_pmu_enable_all, | ||
537 | .enable = x86_pmu_enable_event, | ||
538 | .disable = x86_pmu_disable_event, | ||
539 | .hw_config = amd_pmu_hw_config, | ||
540 | .schedule_events = x86_schedule_events, | ||
541 | .eventsel = MSR_F15H_PERF_CTL, | ||
542 | .perfctr = MSR_F15H_PERF_CTR, | ||
543 | .event_map = amd_pmu_event_map, | ||
544 | .max_events = ARRAY_SIZE(amd_perfmon_event_map), | ||
545 | .num_counters = 6, | ||
546 | .cntval_bits = 48, | ||
547 | .cntval_mask = (1ULL << 48) - 1, | ||
548 | .apic = 1, | ||
549 | /* use highest bit to detect overflow */ | ||
550 | .max_period = (1ULL << 47) - 1, | ||
551 | .get_event_constraints = amd_get_event_constraints_f15h, | ||
552 | /* nortbridge counters not yet implemented: */ | ||
553 | #if 0 | ||
554 | .put_event_constraints = amd_put_event_constraints, | ||
555 | |||
556 | .cpu_prepare = amd_pmu_cpu_prepare, | ||
557 | .cpu_starting = amd_pmu_cpu_starting, | ||
558 | .cpu_dead = amd_pmu_cpu_dead, | ||
559 | #endif | ||
560 | }; | ||
561 | |||
398 | static __init int amd_pmu_init(void) | 562 | static __init int amd_pmu_init(void) |
399 | { | 563 | { |
400 | /* Performance-monitoring supported from K7 and later: */ | 564 | /* Performance-monitoring supported from K7 and later: */ |
401 | if (boot_cpu_data.x86 < 6) | 565 | if (boot_cpu_data.x86 < 6) |
402 | return -ENODEV; | 566 | return -ENODEV; |
403 | 567 | ||
404 | x86_pmu = amd_pmu; | 568 | /* |
569 | * If core performance counter extensions exists, it must be | ||
570 | * family 15h, otherwise fail. See x86_pmu_addr_offset(). | ||
571 | */ | ||
572 | switch (boot_cpu_data.x86) { | ||
573 | case 0x15: | ||
574 | if (!cpu_has_perfctr_core) | ||
575 | return -ENODEV; | ||
576 | x86_pmu = amd_pmu_f15h; | ||
577 | break; | ||
578 | default: | ||
579 | if (cpu_has_perfctr_core) | ||
580 | return -ENODEV; | ||
581 | x86_pmu = amd_pmu; | ||
582 | break; | ||
583 | } | ||
405 | 584 | ||
406 | /* Events are common for all AMDs */ | 585 | /* Events are common for all AMDs */ |
407 | memcpy(hw_cache_event_ids, amd_hw_cache_event_ids, | 586 | memcpy(hw_cache_event_ids, amd_hw_cache_event_ids, |
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c index ee05c90012d2..41178c826c48 100644 --- a/arch/x86/kernel/cpu/perf_event_intel.c +++ b/arch/x86/kernel/cpu/perf_event_intel.c | |||
@@ -1,9 +1,31 @@ | |||
1 | #ifdef CONFIG_CPU_SUP_INTEL | 1 | #ifdef CONFIG_CPU_SUP_INTEL |
2 | 2 | ||
3 | #define MAX_EXTRA_REGS 2 | ||
4 | |||
5 | /* | ||
6 | * Per register state. | ||
7 | */ | ||
8 | struct er_account { | ||
9 | int ref; /* reference count */ | ||
10 | unsigned int extra_reg; /* extra MSR number */ | ||
11 | u64 extra_config; /* extra MSR config */ | ||
12 | }; | ||
13 | |||
14 | /* | ||
15 | * Per core state | ||
16 | * This used to coordinate shared registers for HT threads. | ||
17 | */ | ||
18 | struct intel_percore { | ||
19 | raw_spinlock_t lock; /* protect structure */ | ||
20 | struct er_account regs[MAX_EXTRA_REGS]; | ||
21 | int refcnt; /* number of threads */ | ||
22 | unsigned core_id; | ||
23 | }; | ||
24 | |||
3 | /* | 25 | /* |
4 | * Intel PerfMon, used on Core and later. | 26 | * Intel PerfMon, used on Core and later. |
5 | */ | 27 | */ |
6 | static const u64 intel_perfmon_event_map[] = | 28 | static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly = |
7 | { | 29 | { |
8 | [PERF_COUNT_HW_CPU_CYCLES] = 0x003c, | 30 | [PERF_COUNT_HW_CPU_CYCLES] = 0x003c, |
9 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, | 31 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, |
@@ -14,7 +36,7 @@ static const u64 intel_perfmon_event_map[] = | |||
14 | [PERF_COUNT_HW_BUS_CYCLES] = 0x013c, | 36 | [PERF_COUNT_HW_BUS_CYCLES] = 0x013c, |
15 | }; | 37 | }; |
16 | 38 | ||
17 | static struct event_constraint intel_core_event_constraints[] = | 39 | static struct event_constraint intel_core_event_constraints[] __read_mostly = |
18 | { | 40 | { |
19 | INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */ | 41 | INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */ |
20 | INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */ | 42 | INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */ |
@@ -25,7 +47,7 @@ static struct event_constraint intel_core_event_constraints[] = | |||
25 | EVENT_CONSTRAINT_END | 47 | EVENT_CONSTRAINT_END |
26 | }; | 48 | }; |
27 | 49 | ||
28 | static struct event_constraint intel_core2_event_constraints[] = | 50 | static struct event_constraint intel_core2_event_constraints[] __read_mostly = |
29 | { | 51 | { |
30 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | 52 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
31 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | 53 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ |
@@ -48,7 +70,7 @@ static struct event_constraint intel_core2_event_constraints[] = | |||
48 | EVENT_CONSTRAINT_END | 70 | EVENT_CONSTRAINT_END |
49 | }; | 71 | }; |
50 | 72 | ||
51 | static struct event_constraint intel_nehalem_event_constraints[] = | 73 | static struct event_constraint intel_nehalem_event_constraints[] __read_mostly = |
52 | { | 74 | { |
53 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | 75 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
54 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | 76 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ |
@@ -64,7 +86,19 @@ static struct event_constraint intel_nehalem_event_constraints[] = | |||
64 | EVENT_CONSTRAINT_END | 86 | EVENT_CONSTRAINT_END |
65 | }; | 87 | }; |
66 | 88 | ||
67 | static struct event_constraint intel_westmere_event_constraints[] = | 89 | static struct extra_reg intel_nehalem_extra_regs[] __read_mostly = |
90 | { | ||
91 | INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0xffff), | ||
92 | EVENT_EXTRA_END | ||
93 | }; | ||
94 | |||
95 | static struct event_constraint intel_nehalem_percore_constraints[] __read_mostly = | ||
96 | { | ||
97 | INTEL_EVENT_CONSTRAINT(0xb7, 0), | ||
98 | EVENT_CONSTRAINT_END | ||
99 | }; | ||
100 | |||
101 | static struct event_constraint intel_westmere_event_constraints[] __read_mostly = | ||
68 | { | 102 | { |
69 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | 103 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
70 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | 104 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ |
@@ -76,7 +110,34 @@ static struct event_constraint intel_westmere_event_constraints[] = | |||
76 | EVENT_CONSTRAINT_END | 110 | EVENT_CONSTRAINT_END |
77 | }; | 111 | }; |
78 | 112 | ||
79 | static struct event_constraint intel_gen_event_constraints[] = | 113 | static struct event_constraint intel_snb_event_constraints[] __read_mostly = |
114 | { | ||
115 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | ||
116 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | ||
117 | /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */ | ||
118 | INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.PENDING */ | ||
119 | INTEL_EVENT_CONSTRAINT(0xb7, 0x1), /* OFF_CORE_RESPONSE_0 */ | ||
120 | INTEL_EVENT_CONSTRAINT(0xbb, 0x8), /* OFF_CORE_RESPONSE_1 */ | ||
121 | INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */ | ||
122 | INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */ | ||
123 | EVENT_CONSTRAINT_END | ||
124 | }; | ||
125 | |||
126 | static struct extra_reg intel_westmere_extra_regs[] __read_mostly = | ||
127 | { | ||
128 | INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0xffff), | ||
129 | INTEL_EVENT_EXTRA_REG(0xbb, MSR_OFFCORE_RSP_1, 0xffff), | ||
130 | EVENT_EXTRA_END | ||
131 | }; | ||
132 | |||
133 | static struct event_constraint intel_westmere_percore_constraints[] __read_mostly = | ||
134 | { | ||
135 | INTEL_EVENT_CONSTRAINT(0xb7, 0), | ||
136 | INTEL_EVENT_CONSTRAINT(0xbb, 0), | ||
137 | EVENT_CONSTRAINT_END | ||
138 | }; | ||
139 | |||
140 | static struct event_constraint intel_gen_event_constraints[] __read_mostly = | ||
80 | { | 141 | { |
81 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | 142 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
82 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | 143 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ |
@@ -89,6 +150,103 @@ static u64 intel_pmu_event_map(int hw_event) | |||
89 | return intel_perfmon_event_map[hw_event]; | 150 | return intel_perfmon_event_map[hw_event]; |
90 | } | 151 | } |
91 | 152 | ||
153 | static __initconst const u64 snb_hw_cache_event_ids | ||
154 | [PERF_COUNT_HW_CACHE_MAX] | ||
155 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
156 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | ||
157 | { | ||
158 | [ C(L1D) ] = { | ||
159 | [ C(OP_READ) ] = { | ||
160 | [ C(RESULT_ACCESS) ] = 0xf1d0, /* MEM_UOP_RETIRED.LOADS */ | ||
161 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPLACEMENT */ | ||
162 | }, | ||
163 | [ C(OP_WRITE) ] = { | ||
164 | [ C(RESULT_ACCESS) ] = 0xf2d0, /* MEM_UOP_RETIRED.STORES */ | ||
165 | [ C(RESULT_MISS) ] = 0x0851, /* L1D.ALL_M_REPLACEMENT */ | ||
166 | }, | ||
167 | [ C(OP_PREFETCH) ] = { | ||
168 | [ C(RESULT_ACCESS) ] = 0x0, | ||
169 | [ C(RESULT_MISS) ] = 0x024e, /* HW_PRE_REQ.DL1_MISS */ | ||
170 | }, | ||
171 | }, | ||
172 | [ C(L1I ) ] = { | ||
173 | [ C(OP_READ) ] = { | ||
174 | [ C(RESULT_ACCESS) ] = 0x0, | ||
175 | [ C(RESULT_MISS) ] = 0x0280, /* ICACHE.MISSES */ | ||
176 | }, | ||
177 | [ C(OP_WRITE) ] = { | ||
178 | [ C(RESULT_ACCESS) ] = -1, | ||
179 | [ C(RESULT_MISS) ] = -1, | ||
180 | }, | ||
181 | [ C(OP_PREFETCH) ] = { | ||
182 | [ C(RESULT_ACCESS) ] = 0x0, | ||
183 | [ C(RESULT_MISS) ] = 0x0, | ||
184 | }, | ||
185 | }, | ||
186 | [ C(LL ) ] = { | ||
187 | [ C(OP_READ) ] = { | ||
188 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ | ||
189 | [ C(RESULT_ACCESS) ] = 0x01b7, | ||
190 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | ||
191 | [ C(RESULT_MISS) ] = 0x01b7, | ||
192 | }, | ||
193 | [ C(OP_WRITE) ] = { | ||
194 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ | ||
195 | [ C(RESULT_ACCESS) ] = 0x01b7, | ||
196 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | ||
197 | [ C(RESULT_MISS) ] = 0x01b7, | ||
198 | }, | ||
199 | [ C(OP_PREFETCH) ] = { | ||
200 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ | ||
201 | [ C(RESULT_ACCESS) ] = 0x01b7, | ||
202 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | ||
203 | [ C(RESULT_MISS) ] = 0x01b7, | ||
204 | }, | ||
205 | }, | ||
206 | [ C(DTLB) ] = { | ||
207 | [ C(OP_READ) ] = { | ||
208 | [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOP_RETIRED.ALL_LOADS */ | ||
209 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.CAUSES_A_WALK */ | ||
210 | }, | ||
211 | [ C(OP_WRITE) ] = { | ||
212 | [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOP_RETIRED.ALL_STORES */ | ||
213 | [ C(RESULT_MISS) ] = 0x0149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */ | ||
214 | }, | ||
215 | [ C(OP_PREFETCH) ] = { | ||
216 | [ C(RESULT_ACCESS) ] = 0x0, | ||
217 | [ C(RESULT_MISS) ] = 0x0, | ||
218 | }, | ||
219 | }, | ||
220 | [ C(ITLB) ] = { | ||
221 | [ C(OP_READ) ] = { | ||
222 | [ C(RESULT_ACCESS) ] = 0x1085, /* ITLB_MISSES.STLB_HIT */ | ||
223 | [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.CAUSES_A_WALK */ | ||
224 | }, | ||
225 | [ C(OP_WRITE) ] = { | ||
226 | [ C(RESULT_ACCESS) ] = -1, | ||
227 | [ C(RESULT_MISS) ] = -1, | ||
228 | }, | ||
229 | [ C(OP_PREFETCH) ] = { | ||
230 | [ C(RESULT_ACCESS) ] = -1, | ||
231 | [ C(RESULT_MISS) ] = -1, | ||
232 | }, | ||
233 | }, | ||
234 | [ C(BPU ) ] = { | ||
235 | [ C(OP_READ) ] = { | ||
236 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | ||
237 | [ C(RESULT_MISS) ] = 0x00c5, /* BR_MISP_RETIRED.ALL_BRANCHES */ | ||
238 | }, | ||
239 | [ C(OP_WRITE) ] = { | ||
240 | [ C(RESULT_ACCESS) ] = -1, | ||
241 | [ C(RESULT_MISS) ] = -1, | ||
242 | }, | ||
243 | [ C(OP_PREFETCH) ] = { | ||
244 | [ C(RESULT_ACCESS) ] = -1, | ||
245 | [ C(RESULT_MISS) ] = -1, | ||
246 | }, | ||
247 | }, | ||
248 | }; | ||
249 | |||
92 | static __initconst const u64 westmere_hw_cache_event_ids | 250 | static __initconst const u64 westmere_hw_cache_event_ids |
93 | [PERF_COUNT_HW_CACHE_MAX] | 251 | [PERF_COUNT_HW_CACHE_MAX] |
94 | [PERF_COUNT_HW_CACHE_OP_MAX] | 252 | [PERF_COUNT_HW_CACHE_OP_MAX] |
@@ -124,16 +282,26 @@ static __initconst const u64 westmere_hw_cache_event_ids | |||
124 | }, | 282 | }, |
125 | [ C(LL ) ] = { | 283 | [ C(LL ) ] = { |
126 | [ C(OP_READ) ] = { | 284 | [ C(OP_READ) ] = { |
127 | [ C(RESULT_ACCESS) ] = 0x0324, /* L2_RQSTS.LOADS */ | 285 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
128 | [ C(RESULT_MISS) ] = 0x0224, /* L2_RQSTS.LD_MISS */ | 286 | [ C(RESULT_ACCESS) ] = 0x01b7, |
287 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | ||
288 | [ C(RESULT_MISS) ] = 0x01b7, | ||
129 | }, | 289 | }, |
290 | /* | ||
291 | * Use RFO, not WRITEBACK, because a write miss would typically occur | ||
292 | * on RFO. | ||
293 | */ | ||
130 | [ C(OP_WRITE) ] = { | 294 | [ C(OP_WRITE) ] = { |
131 | [ C(RESULT_ACCESS) ] = 0x0c24, /* L2_RQSTS.RFOS */ | 295 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
132 | [ C(RESULT_MISS) ] = 0x0824, /* L2_RQSTS.RFO_MISS */ | 296 | [ C(RESULT_ACCESS) ] = 0x01b7, |
297 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | ||
298 | [ C(RESULT_MISS) ] = 0x01b7, | ||
133 | }, | 299 | }, |
134 | [ C(OP_PREFETCH) ] = { | 300 | [ C(OP_PREFETCH) ] = { |
135 | [ C(RESULT_ACCESS) ] = 0x4f2e, /* LLC Reference */ | 301 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
136 | [ C(RESULT_MISS) ] = 0x412e, /* LLC Misses */ | 302 | [ C(RESULT_ACCESS) ] = 0x01b7, |
303 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | ||
304 | [ C(RESULT_MISS) ] = 0x01b7, | ||
137 | }, | 305 | }, |
138 | }, | 306 | }, |
139 | [ C(DTLB) ] = { | 307 | [ C(DTLB) ] = { |
@@ -180,6 +348,59 @@ static __initconst const u64 westmere_hw_cache_event_ids | |||
180 | }, | 348 | }, |
181 | }; | 349 | }; |
182 | 350 | ||
351 | /* | ||
352 | * Nehalem/Westmere MSR_OFFCORE_RESPONSE bits; | ||
353 | * See IA32 SDM Vol 3B 30.6.1.3 | ||
354 | */ | ||
355 | |||
356 | #define NHM_DMND_DATA_RD (1 << 0) | ||
357 | #define NHM_DMND_RFO (1 << 1) | ||
358 | #define NHM_DMND_IFETCH (1 << 2) | ||
359 | #define NHM_DMND_WB (1 << 3) | ||
360 | #define NHM_PF_DATA_RD (1 << 4) | ||
361 | #define NHM_PF_DATA_RFO (1 << 5) | ||
362 | #define NHM_PF_IFETCH (1 << 6) | ||
363 | #define NHM_OFFCORE_OTHER (1 << 7) | ||
364 | #define NHM_UNCORE_HIT (1 << 8) | ||
365 | #define NHM_OTHER_CORE_HIT_SNP (1 << 9) | ||
366 | #define NHM_OTHER_CORE_HITM (1 << 10) | ||
367 | /* reserved */ | ||
368 | #define NHM_REMOTE_CACHE_FWD (1 << 12) | ||
369 | #define NHM_REMOTE_DRAM (1 << 13) | ||
370 | #define NHM_LOCAL_DRAM (1 << 14) | ||
371 | #define NHM_NON_DRAM (1 << 15) | ||
372 | |||
373 | #define NHM_ALL_DRAM (NHM_REMOTE_DRAM|NHM_LOCAL_DRAM) | ||
374 | |||
375 | #define NHM_DMND_READ (NHM_DMND_DATA_RD) | ||
376 | #define NHM_DMND_WRITE (NHM_DMND_RFO|NHM_DMND_WB) | ||
377 | #define NHM_DMND_PREFETCH (NHM_PF_DATA_RD|NHM_PF_DATA_RFO) | ||
378 | |||
379 | #define NHM_L3_HIT (NHM_UNCORE_HIT|NHM_OTHER_CORE_HIT_SNP|NHM_OTHER_CORE_HITM) | ||
380 | #define NHM_L3_MISS (NHM_NON_DRAM|NHM_ALL_DRAM|NHM_REMOTE_CACHE_FWD) | ||
381 | #define NHM_L3_ACCESS (NHM_L3_HIT|NHM_L3_MISS) | ||
382 | |||
383 | static __initconst const u64 nehalem_hw_cache_extra_regs | ||
384 | [PERF_COUNT_HW_CACHE_MAX] | ||
385 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
386 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | ||
387 | { | ||
388 | [ C(LL ) ] = { | ||
389 | [ C(OP_READ) ] = { | ||
390 | [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_L3_ACCESS, | ||
391 | [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_L3_MISS, | ||
392 | }, | ||
393 | [ C(OP_WRITE) ] = { | ||
394 | [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_L3_ACCESS, | ||
395 | [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_L3_MISS, | ||
396 | }, | ||
397 | [ C(OP_PREFETCH) ] = { | ||
398 | [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_L3_ACCESS, | ||
399 | [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_L3_MISS, | ||
400 | }, | ||
401 | } | ||
402 | }; | ||
403 | |||
183 | static __initconst const u64 nehalem_hw_cache_event_ids | 404 | static __initconst const u64 nehalem_hw_cache_event_ids |
184 | [PERF_COUNT_HW_CACHE_MAX] | 405 | [PERF_COUNT_HW_CACHE_MAX] |
185 | [PERF_COUNT_HW_CACHE_OP_MAX] | 406 | [PERF_COUNT_HW_CACHE_OP_MAX] |
@@ -187,12 +408,12 @@ static __initconst const u64 nehalem_hw_cache_event_ids | |||
187 | { | 408 | { |
188 | [ C(L1D) ] = { | 409 | [ C(L1D) ] = { |
189 | [ C(OP_READ) ] = { | 410 | [ C(OP_READ) ] = { |
190 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */ | 411 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ |
191 | [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */ | 412 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */ |
192 | }, | 413 | }, |
193 | [ C(OP_WRITE) ] = { | 414 | [ C(OP_WRITE) ] = { |
194 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */ | 415 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ |
195 | [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */ | 416 | [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */ |
196 | }, | 417 | }, |
197 | [ C(OP_PREFETCH) ] = { | 418 | [ C(OP_PREFETCH) ] = { |
198 | [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */ | 419 | [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */ |
@@ -215,16 +436,26 @@ static __initconst const u64 nehalem_hw_cache_event_ids | |||
215 | }, | 436 | }, |
216 | [ C(LL ) ] = { | 437 | [ C(LL ) ] = { |
217 | [ C(OP_READ) ] = { | 438 | [ C(OP_READ) ] = { |
218 | [ C(RESULT_ACCESS) ] = 0x0324, /* L2_RQSTS.LOADS */ | 439 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
219 | [ C(RESULT_MISS) ] = 0x0224, /* L2_RQSTS.LD_MISS */ | 440 | [ C(RESULT_ACCESS) ] = 0x01b7, |
441 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | ||
442 | [ C(RESULT_MISS) ] = 0x01b7, | ||
220 | }, | 443 | }, |
444 | /* | ||
445 | * Use RFO, not WRITEBACK, because a write miss would typically occur | ||
446 | * on RFO. | ||
447 | */ | ||
221 | [ C(OP_WRITE) ] = { | 448 | [ C(OP_WRITE) ] = { |
222 | [ C(RESULT_ACCESS) ] = 0x0c24, /* L2_RQSTS.RFOS */ | 449 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
223 | [ C(RESULT_MISS) ] = 0x0824, /* L2_RQSTS.RFO_MISS */ | 450 | [ C(RESULT_ACCESS) ] = 0x01b7, |
451 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | ||
452 | [ C(RESULT_MISS) ] = 0x01b7, | ||
224 | }, | 453 | }, |
225 | [ C(OP_PREFETCH) ] = { | 454 | [ C(OP_PREFETCH) ] = { |
226 | [ C(RESULT_ACCESS) ] = 0x4f2e, /* LLC Reference */ | 455 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
227 | [ C(RESULT_MISS) ] = 0x412e, /* LLC Misses */ | 456 | [ C(RESULT_ACCESS) ] = 0x01b7, |
457 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | ||
458 | [ C(RESULT_MISS) ] = 0x01b7, | ||
228 | }, | 459 | }, |
229 | }, | 460 | }, |
230 | [ C(DTLB) ] = { | 461 | [ C(DTLB) ] = { |
@@ -649,7 +880,7 @@ static void intel_pmu_enable_event(struct perf_event *event) | |||
649 | struct hw_perf_event *hwc = &event->hw; | 880 | struct hw_perf_event *hwc = &event->hw; |
650 | 881 | ||
651 | if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) { | 882 | if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) { |
652 | if (!__get_cpu_var(cpu_hw_events).enabled) | 883 | if (!__this_cpu_read(cpu_hw_events.enabled)) |
653 | return; | 884 | return; |
654 | 885 | ||
655 | intel_pmu_enable_bts(hwc->config); | 886 | intel_pmu_enable_bts(hwc->config); |
@@ -679,7 +910,7 @@ static int intel_pmu_save_and_restart(struct perf_event *event) | |||
679 | 910 | ||
680 | static void intel_pmu_reset(void) | 911 | static void intel_pmu_reset(void) |
681 | { | 912 | { |
682 | struct debug_store *ds = __get_cpu_var(cpu_hw_events).ds; | 913 | struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds); |
683 | unsigned long flags; | 914 | unsigned long flags; |
684 | int idx; | 915 | int idx; |
685 | 916 | ||
@@ -691,8 +922,8 @@ static void intel_pmu_reset(void) | |||
691 | printk("clearing PMU state on CPU#%d\n", smp_processor_id()); | 922 | printk("clearing PMU state on CPU#%d\n", smp_processor_id()); |
692 | 923 | ||
693 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | 924 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
694 | checking_wrmsrl(x86_pmu.eventsel + idx, 0ull); | 925 | checking_wrmsrl(x86_pmu_config_addr(idx), 0ull); |
695 | checking_wrmsrl(x86_pmu.perfctr + idx, 0ull); | 926 | checking_wrmsrl(x86_pmu_event_addr(idx), 0ull); |
696 | } | 927 | } |
697 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) | 928 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) |
698 | checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); | 929 | checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); |
@@ -713,18 +944,28 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) | |||
713 | struct cpu_hw_events *cpuc; | 944 | struct cpu_hw_events *cpuc; |
714 | int bit, loops; | 945 | int bit, loops; |
715 | u64 status; | 946 | u64 status; |
716 | int handled = 0; | 947 | int handled; |
717 | 948 | ||
718 | perf_sample_data_init(&data, 0); | 949 | perf_sample_data_init(&data, 0); |
719 | 950 | ||
720 | cpuc = &__get_cpu_var(cpu_hw_events); | 951 | cpuc = &__get_cpu_var(cpu_hw_events); |
721 | 952 | ||
953 | /* | ||
954 | * Some chipsets need to unmask the LVTPC in a particular spot | ||
955 | * inside the nmi handler. As a result, the unmasking was pushed | ||
956 | * into all the nmi handlers. | ||
957 | * | ||
958 | * This handler doesn't seem to have any issues with the unmasking | ||
959 | * so it was left at the top. | ||
960 | */ | ||
961 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
962 | |||
722 | intel_pmu_disable_all(); | 963 | intel_pmu_disable_all(); |
723 | intel_pmu_drain_bts_buffer(); | 964 | handled = intel_pmu_drain_bts_buffer(); |
724 | status = intel_pmu_get_status(); | 965 | status = intel_pmu_get_status(); |
725 | if (!status) { | 966 | if (!status) { |
726 | intel_pmu_enable_all(0); | 967 | intel_pmu_enable_all(0); |
727 | return 0; | 968 | return handled; |
728 | } | 969 | } |
729 | 970 | ||
730 | loops = 0; | 971 | loops = 0; |
@@ -763,7 +1004,7 @@ again: | |||
763 | data.period = event->hw.last_period; | 1004 | data.period = event->hw.last_period; |
764 | 1005 | ||
765 | if (perf_event_overflow(event, 1, &data, regs)) | 1006 | if (perf_event_overflow(event, 1, &data, regs)) |
766 | x86_pmu_stop(event); | 1007 | x86_pmu_stop(event, 0); |
767 | } | 1008 | } |
768 | 1009 | ||
769 | /* | 1010 | /* |
@@ -784,6 +1025,9 @@ intel_bts_constraints(struct perf_event *event) | |||
784 | struct hw_perf_event *hwc = &event->hw; | 1025 | struct hw_perf_event *hwc = &event->hw; |
785 | unsigned int hw_event, bts_event; | 1026 | unsigned int hw_event, bts_event; |
786 | 1027 | ||
1028 | if (event->attr.freq) | ||
1029 | return NULL; | ||
1030 | |||
787 | hw_event = hwc->config & INTEL_ARCH_EVENT_MASK; | 1031 | hw_event = hwc->config & INTEL_ARCH_EVENT_MASK; |
788 | bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); | 1032 | bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); |
789 | 1033 | ||
@@ -794,6 +1038,67 @@ intel_bts_constraints(struct perf_event *event) | |||
794 | } | 1038 | } |
795 | 1039 | ||
796 | static struct event_constraint * | 1040 | static struct event_constraint * |
1041 | intel_percore_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | ||
1042 | { | ||
1043 | struct hw_perf_event *hwc = &event->hw; | ||
1044 | unsigned int e = hwc->config & ARCH_PERFMON_EVENTSEL_EVENT; | ||
1045 | struct event_constraint *c; | ||
1046 | struct intel_percore *pc; | ||
1047 | struct er_account *era; | ||
1048 | int i; | ||
1049 | int free_slot; | ||
1050 | int found; | ||
1051 | |||
1052 | if (!x86_pmu.percore_constraints || hwc->extra_alloc) | ||
1053 | return NULL; | ||
1054 | |||
1055 | for (c = x86_pmu.percore_constraints; c->cmask; c++) { | ||
1056 | if (e != c->code) | ||
1057 | continue; | ||
1058 | |||
1059 | /* | ||
1060 | * Allocate resource per core. | ||
1061 | */ | ||
1062 | pc = cpuc->per_core; | ||
1063 | if (!pc) | ||
1064 | break; | ||
1065 | c = &emptyconstraint; | ||
1066 | raw_spin_lock(&pc->lock); | ||
1067 | free_slot = -1; | ||
1068 | found = 0; | ||
1069 | for (i = 0; i < MAX_EXTRA_REGS; i++) { | ||
1070 | era = &pc->regs[i]; | ||
1071 | if (era->ref > 0 && hwc->extra_reg == era->extra_reg) { | ||
1072 | /* Allow sharing same config */ | ||
1073 | if (hwc->extra_config == era->extra_config) { | ||
1074 | era->ref++; | ||
1075 | cpuc->percore_used = 1; | ||
1076 | hwc->extra_alloc = 1; | ||
1077 | c = NULL; | ||
1078 | } | ||
1079 | /* else conflict */ | ||
1080 | found = 1; | ||
1081 | break; | ||
1082 | } else if (era->ref == 0 && free_slot == -1) | ||
1083 | free_slot = i; | ||
1084 | } | ||
1085 | if (!found && free_slot != -1) { | ||
1086 | era = &pc->regs[free_slot]; | ||
1087 | era->ref = 1; | ||
1088 | era->extra_reg = hwc->extra_reg; | ||
1089 | era->extra_config = hwc->extra_config; | ||
1090 | cpuc->percore_used = 1; | ||
1091 | hwc->extra_alloc = 1; | ||
1092 | c = NULL; | ||
1093 | } | ||
1094 | raw_spin_unlock(&pc->lock); | ||
1095 | return c; | ||
1096 | } | ||
1097 | |||
1098 | return NULL; | ||
1099 | } | ||
1100 | |||
1101 | static struct event_constraint * | ||
797 | intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | 1102 | intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) |
798 | { | 1103 | { |
799 | struct event_constraint *c; | 1104 | struct event_constraint *c; |
@@ -806,9 +1111,51 @@ intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event | |||
806 | if (c) | 1111 | if (c) |
807 | return c; | 1112 | return c; |
808 | 1113 | ||
1114 | c = intel_percore_constraints(cpuc, event); | ||
1115 | if (c) | ||
1116 | return c; | ||
1117 | |||
809 | return x86_get_event_constraints(cpuc, event); | 1118 | return x86_get_event_constraints(cpuc, event); |
810 | } | 1119 | } |
811 | 1120 | ||
1121 | static void intel_put_event_constraints(struct cpu_hw_events *cpuc, | ||
1122 | struct perf_event *event) | ||
1123 | { | ||
1124 | struct extra_reg *er; | ||
1125 | struct intel_percore *pc; | ||
1126 | struct er_account *era; | ||
1127 | struct hw_perf_event *hwc = &event->hw; | ||
1128 | int i, allref; | ||
1129 | |||
1130 | if (!cpuc->percore_used) | ||
1131 | return; | ||
1132 | |||
1133 | for (er = x86_pmu.extra_regs; er->msr; er++) { | ||
1134 | if (er->event != (hwc->config & er->config_mask)) | ||
1135 | continue; | ||
1136 | |||
1137 | pc = cpuc->per_core; | ||
1138 | raw_spin_lock(&pc->lock); | ||
1139 | for (i = 0; i < MAX_EXTRA_REGS; i++) { | ||
1140 | era = &pc->regs[i]; | ||
1141 | if (era->ref > 0 && | ||
1142 | era->extra_config == hwc->extra_config && | ||
1143 | era->extra_reg == er->msr) { | ||
1144 | era->ref--; | ||
1145 | hwc->extra_alloc = 0; | ||
1146 | break; | ||
1147 | } | ||
1148 | } | ||
1149 | allref = 0; | ||
1150 | for (i = 0; i < MAX_EXTRA_REGS; i++) | ||
1151 | allref += pc->regs[i].ref; | ||
1152 | if (allref == 0) | ||
1153 | cpuc->percore_used = 0; | ||
1154 | raw_spin_unlock(&pc->lock); | ||
1155 | break; | ||
1156 | } | ||
1157 | } | ||
1158 | |||
812 | static int intel_pmu_hw_config(struct perf_event *event) | 1159 | static int intel_pmu_hw_config(struct perf_event *event) |
813 | { | 1160 | { |
814 | int ret = x86_pmu_hw_config(event); | 1161 | int ret = x86_pmu_hw_config(event); |
@@ -816,6 +1163,32 @@ static int intel_pmu_hw_config(struct perf_event *event) | |||
816 | if (ret) | 1163 | if (ret) |
817 | return ret; | 1164 | return ret; |
818 | 1165 | ||
1166 | if (event->attr.precise_ip && | ||
1167 | (event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) { | ||
1168 | /* | ||
1169 | * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P | ||
1170 | * (0x003c) so that we can use it with PEBS. | ||
1171 | * | ||
1172 | * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't | ||
1173 | * PEBS capable. However we can use INST_RETIRED.ANY_P | ||
1174 | * (0x00c0), which is a PEBS capable event, to get the same | ||
1175 | * count. | ||
1176 | * | ||
1177 | * INST_RETIRED.ANY_P counts the number of cycles that retires | ||
1178 | * CNTMASK instructions. By setting CNTMASK to a value (16) | ||
1179 | * larger than the maximum number of instructions that can be | ||
1180 | * retired per cycle (4) and then inverting the condition, we | ||
1181 | * count all cycles that retire 16 or less instructions, which | ||
1182 | * is every cycle. | ||
1183 | * | ||
1184 | * Thereby we gain a PEBS capable cycle counter. | ||
1185 | */ | ||
1186 | u64 alt_config = 0x108000c0; /* INST_RETIRED.TOTAL_CYCLES */ | ||
1187 | |||
1188 | alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK); | ||
1189 | event->hw.config = alt_config; | ||
1190 | } | ||
1191 | |||
819 | if (event->attr.type != PERF_TYPE_RAW) | 1192 | if (event->attr.type != PERF_TYPE_RAW) |
820 | return 0; | 1193 | return 0; |
821 | 1194 | ||
@@ -854,20 +1227,67 @@ static __initconst const struct x86_pmu core_pmu = { | |||
854 | */ | 1227 | */ |
855 | .max_period = (1ULL << 31) - 1, | 1228 | .max_period = (1ULL << 31) - 1, |
856 | .get_event_constraints = intel_get_event_constraints, | 1229 | .get_event_constraints = intel_get_event_constraints, |
1230 | .put_event_constraints = intel_put_event_constraints, | ||
857 | .event_constraints = intel_core_event_constraints, | 1231 | .event_constraints = intel_core_event_constraints, |
858 | }; | 1232 | }; |
859 | 1233 | ||
1234 | static int intel_pmu_cpu_prepare(int cpu) | ||
1235 | { | ||
1236 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); | ||
1237 | |||
1238 | if (!cpu_has_ht_siblings()) | ||
1239 | return NOTIFY_OK; | ||
1240 | |||
1241 | cpuc->per_core = kzalloc_node(sizeof(struct intel_percore), | ||
1242 | GFP_KERNEL, cpu_to_node(cpu)); | ||
1243 | if (!cpuc->per_core) | ||
1244 | return NOTIFY_BAD; | ||
1245 | |||
1246 | raw_spin_lock_init(&cpuc->per_core->lock); | ||
1247 | cpuc->per_core->core_id = -1; | ||
1248 | return NOTIFY_OK; | ||
1249 | } | ||
1250 | |||
860 | static void intel_pmu_cpu_starting(int cpu) | 1251 | static void intel_pmu_cpu_starting(int cpu) |
861 | { | 1252 | { |
1253 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); | ||
1254 | int core_id = topology_core_id(cpu); | ||
1255 | int i; | ||
1256 | |||
862 | init_debug_store_on_cpu(cpu); | 1257 | init_debug_store_on_cpu(cpu); |
863 | /* | 1258 | /* |
864 | * Deal with CPUs that don't clear their LBRs on power-up. | 1259 | * Deal with CPUs that don't clear their LBRs on power-up. |
865 | */ | 1260 | */ |
866 | intel_pmu_lbr_reset(); | 1261 | intel_pmu_lbr_reset(); |
1262 | |||
1263 | if (!cpu_has_ht_siblings()) | ||
1264 | return; | ||
1265 | |||
1266 | for_each_cpu(i, topology_thread_cpumask(cpu)) { | ||
1267 | struct intel_percore *pc = per_cpu(cpu_hw_events, i).per_core; | ||
1268 | |||
1269 | if (pc && pc->core_id == core_id) { | ||
1270 | kfree(cpuc->per_core); | ||
1271 | cpuc->per_core = pc; | ||
1272 | break; | ||
1273 | } | ||
1274 | } | ||
1275 | |||
1276 | cpuc->per_core->core_id = core_id; | ||
1277 | cpuc->per_core->refcnt++; | ||
867 | } | 1278 | } |
868 | 1279 | ||
869 | static void intel_pmu_cpu_dying(int cpu) | 1280 | static void intel_pmu_cpu_dying(int cpu) |
870 | { | 1281 | { |
1282 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); | ||
1283 | struct intel_percore *pc = cpuc->per_core; | ||
1284 | |||
1285 | if (pc) { | ||
1286 | if (pc->core_id == -1 || --pc->refcnt == 0) | ||
1287 | kfree(pc); | ||
1288 | cpuc->per_core = NULL; | ||
1289 | } | ||
1290 | |||
871 | fini_debug_store_on_cpu(cpu); | 1291 | fini_debug_store_on_cpu(cpu); |
872 | } | 1292 | } |
873 | 1293 | ||
@@ -892,7 +1312,9 @@ static __initconst const struct x86_pmu intel_pmu = { | |||
892 | */ | 1312 | */ |
893 | .max_period = (1ULL << 31) - 1, | 1313 | .max_period = (1ULL << 31) - 1, |
894 | .get_event_constraints = intel_get_event_constraints, | 1314 | .get_event_constraints = intel_get_event_constraints, |
1315 | .put_event_constraints = intel_put_event_constraints, | ||
895 | 1316 | ||
1317 | .cpu_prepare = intel_pmu_cpu_prepare, | ||
896 | .cpu_starting = intel_pmu_cpu_starting, | 1318 | .cpu_starting = intel_pmu_cpu_starting, |
897 | .cpu_dying = intel_pmu_cpu_dying, | 1319 | .cpu_dying = intel_pmu_cpu_dying, |
898 | }; | 1320 | }; |
@@ -913,7 +1335,7 @@ static void intel_clovertown_quirks(void) | |||
913 | * AJ106 could possibly be worked around by not allowing LBR | 1335 | * AJ106 could possibly be worked around by not allowing LBR |
914 | * usage from PEBS, including the fixup. | 1336 | * usage from PEBS, including the fixup. |
915 | * AJ68 could possibly be worked around by always programming | 1337 | * AJ68 could possibly be worked around by always programming |
916 | * a pebs_event_reset[0] value and coping with the lost events. | 1338 | * a pebs_event_reset[0] value and coping with the lost events. |
917 | * | 1339 | * |
918 | * But taken together it might just make sense to not enable PEBS on | 1340 | * But taken together it might just make sense to not enable PEBS on |
919 | * these chips. | 1341 | * these chips. |
@@ -998,6 +1420,7 @@ static __init int intel_pmu_init(void) | |||
998 | intel_pmu_lbr_init_core(); | 1420 | intel_pmu_lbr_init_core(); |
999 | 1421 | ||
1000 | x86_pmu.event_constraints = intel_core2_event_constraints; | 1422 | x86_pmu.event_constraints = intel_core2_event_constraints; |
1423 | x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints; | ||
1001 | pr_cont("Core2 events, "); | 1424 | pr_cont("Core2 events, "); |
1002 | break; | 1425 | break; |
1003 | 1426 | ||
@@ -1006,11 +1429,33 @@ static __init int intel_pmu_init(void) | |||
1006 | case 46: /* 45 nm nehalem-ex, "Beckton" */ | 1429 | case 46: /* 45 nm nehalem-ex, "Beckton" */ |
1007 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, | 1430 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, |
1008 | sizeof(hw_cache_event_ids)); | 1431 | sizeof(hw_cache_event_ids)); |
1432 | memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs, | ||
1433 | sizeof(hw_cache_extra_regs)); | ||
1009 | 1434 | ||
1010 | intel_pmu_lbr_init_nhm(); | 1435 | intel_pmu_lbr_init_nhm(); |
1011 | 1436 | ||
1012 | x86_pmu.event_constraints = intel_nehalem_event_constraints; | 1437 | x86_pmu.event_constraints = intel_nehalem_event_constraints; |
1438 | x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints; | ||
1439 | x86_pmu.percore_constraints = intel_nehalem_percore_constraints; | ||
1013 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; | 1440 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
1441 | x86_pmu.extra_regs = intel_nehalem_extra_regs; | ||
1442 | |||
1443 | /* UOPS_ISSUED.STALLED_CYCLES */ | ||
1444 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e; | ||
1445 | /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */ | ||
1446 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x1803fb1; | ||
1447 | |||
1448 | if (ebx & 0x40) { | ||
1449 | /* | ||
1450 | * Erratum AAJ80 detected, we work it around by using | ||
1451 | * the BR_MISP_EXEC.ANY event. This will over-count | ||
1452 | * branch-misses, but it's still much better than the | ||
1453 | * architectural event which is often completely bogus: | ||
1454 | */ | ||
1455 | intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] = 0x7f89; | ||
1456 | |||
1457 | pr_cont("erratum AAJ80 worked around, "); | ||
1458 | } | ||
1014 | pr_cont("Nehalem events, "); | 1459 | pr_cont("Nehalem events, "); |
1015 | break; | 1460 | break; |
1016 | 1461 | ||
@@ -1021,21 +1466,51 @@ static __init int intel_pmu_init(void) | |||
1021 | intel_pmu_lbr_init_atom(); | 1466 | intel_pmu_lbr_init_atom(); |
1022 | 1467 | ||
1023 | x86_pmu.event_constraints = intel_gen_event_constraints; | 1468 | x86_pmu.event_constraints = intel_gen_event_constraints; |
1469 | x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints; | ||
1024 | pr_cont("Atom events, "); | 1470 | pr_cont("Atom events, "); |
1025 | break; | 1471 | break; |
1026 | 1472 | ||
1027 | case 37: /* 32 nm nehalem, "Clarkdale" */ | 1473 | case 37: /* 32 nm nehalem, "Clarkdale" */ |
1028 | case 44: /* 32 nm nehalem, "Gulftown" */ | 1474 | case 44: /* 32 nm nehalem, "Gulftown" */ |
1475 | case 47: /* 32 nm Xeon E7 */ | ||
1029 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, | 1476 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, |
1030 | sizeof(hw_cache_event_ids)); | 1477 | sizeof(hw_cache_event_ids)); |
1478 | memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs, | ||
1479 | sizeof(hw_cache_extra_regs)); | ||
1031 | 1480 | ||
1032 | intel_pmu_lbr_init_nhm(); | 1481 | intel_pmu_lbr_init_nhm(); |
1033 | 1482 | ||
1034 | x86_pmu.event_constraints = intel_westmere_event_constraints; | 1483 | x86_pmu.event_constraints = intel_westmere_event_constraints; |
1484 | x86_pmu.percore_constraints = intel_westmere_percore_constraints; | ||
1035 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; | 1485 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
1486 | x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints; | ||
1487 | x86_pmu.extra_regs = intel_westmere_extra_regs; | ||
1488 | |||
1489 | /* UOPS_ISSUED.STALLED_CYCLES */ | ||
1490 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e; | ||
1491 | /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */ | ||
1492 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x1803fb1; | ||
1493 | |||
1036 | pr_cont("Westmere events, "); | 1494 | pr_cont("Westmere events, "); |
1037 | break; | 1495 | break; |
1038 | 1496 | ||
1497 | case 42: /* SandyBridge */ | ||
1498 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, | ||
1499 | sizeof(hw_cache_event_ids)); | ||
1500 | |||
1501 | intel_pmu_lbr_init_nhm(); | ||
1502 | |||
1503 | x86_pmu.event_constraints = intel_snb_event_constraints; | ||
1504 | x86_pmu.pebs_constraints = intel_snb_pebs_events; | ||
1505 | |||
1506 | /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ | ||
1507 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e; | ||
1508 | /* UOPS_DISPATCHED.THREAD,c=1,i=1 to count stall cycles*/ | ||
1509 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x18001b1; | ||
1510 | |||
1511 | pr_cont("SandyBridge events, "); | ||
1512 | break; | ||
1513 | |||
1039 | default: | 1514 | default: |
1040 | /* | 1515 | /* |
1041 | * default constraints for v2 and up | 1516 | * default constraints for v2 and up |
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c index 18018d1311cd..bab491b8ee25 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_ds.c +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c | |||
@@ -74,6 +74,107 @@ static void fini_debug_store_on_cpu(int cpu) | |||
74 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); | 74 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); |
75 | } | 75 | } |
76 | 76 | ||
77 | static int alloc_pebs_buffer(int cpu) | ||
78 | { | ||
79 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
80 | int node = cpu_to_node(cpu); | ||
81 | int max, thresh = 1; /* always use a single PEBS record */ | ||
82 | void *buffer; | ||
83 | |||
84 | if (!x86_pmu.pebs) | ||
85 | return 0; | ||
86 | |||
87 | buffer = kmalloc_node(PEBS_BUFFER_SIZE, GFP_KERNEL | __GFP_ZERO, node); | ||
88 | if (unlikely(!buffer)) | ||
89 | return -ENOMEM; | ||
90 | |||
91 | max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size; | ||
92 | |||
93 | ds->pebs_buffer_base = (u64)(unsigned long)buffer; | ||
94 | ds->pebs_index = ds->pebs_buffer_base; | ||
95 | ds->pebs_absolute_maximum = ds->pebs_buffer_base + | ||
96 | max * x86_pmu.pebs_record_size; | ||
97 | |||
98 | ds->pebs_interrupt_threshold = ds->pebs_buffer_base + | ||
99 | thresh * x86_pmu.pebs_record_size; | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static void release_pebs_buffer(int cpu) | ||
105 | { | ||
106 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
107 | |||
108 | if (!ds || !x86_pmu.pebs) | ||
109 | return; | ||
110 | |||
111 | kfree((void *)(unsigned long)ds->pebs_buffer_base); | ||
112 | ds->pebs_buffer_base = 0; | ||
113 | } | ||
114 | |||
115 | static int alloc_bts_buffer(int cpu) | ||
116 | { | ||
117 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
118 | int node = cpu_to_node(cpu); | ||
119 | int max, thresh; | ||
120 | void *buffer; | ||
121 | |||
122 | if (!x86_pmu.bts) | ||
123 | return 0; | ||
124 | |||
125 | buffer = kmalloc_node(BTS_BUFFER_SIZE, GFP_KERNEL | __GFP_ZERO, node); | ||
126 | if (unlikely(!buffer)) | ||
127 | return -ENOMEM; | ||
128 | |||
129 | max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE; | ||
130 | thresh = max / 16; | ||
131 | |||
132 | ds->bts_buffer_base = (u64)(unsigned long)buffer; | ||
133 | ds->bts_index = ds->bts_buffer_base; | ||
134 | ds->bts_absolute_maximum = ds->bts_buffer_base + | ||
135 | max * BTS_RECORD_SIZE; | ||
136 | ds->bts_interrupt_threshold = ds->bts_absolute_maximum - | ||
137 | thresh * BTS_RECORD_SIZE; | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static void release_bts_buffer(int cpu) | ||
143 | { | ||
144 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
145 | |||
146 | if (!ds || !x86_pmu.bts) | ||
147 | return; | ||
148 | |||
149 | kfree((void *)(unsigned long)ds->bts_buffer_base); | ||
150 | ds->bts_buffer_base = 0; | ||
151 | } | ||
152 | |||
153 | static int alloc_ds_buffer(int cpu) | ||
154 | { | ||
155 | int node = cpu_to_node(cpu); | ||
156 | struct debug_store *ds; | ||
157 | |||
158 | ds = kmalloc_node(sizeof(*ds), GFP_KERNEL | __GFP_ZERO, node); | ||
159 | if (unlikely(!ds)) | ||
160 | return -ENOMEM; | ||
161 | |||
162 | per_cpu(cpu_hw_events, cpu).ds = ds; | ||
163 | |||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static void release_ds_buffer(int cpu) | ||
168 | { | ||
169 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
170 | |||
171 | if (!ds) | ||
172 | return; | ||
173 | |||
174 | per_cpu(cpu_hw_events, cpu).ds = NULL; | ||
175 | kfree(ds); | ||
176 | } | ||
177 | |||
77 | static void release_ds_buffers(void) | 178 | static void release_ds_buffers(void) |
78 | { | 179 | { |
79 | int cpu; | 180 | int cpu; |
@@ -82,93 +183,77 @@ static void release_ds_buffers(void) | |||
82 | return; | 183 | return; |
83 | 184 | ||
84 | get_online_cpus(); | 185 | get_online_cpus(); |
85 | |||
86 | for_each_online_cpu(cpu) | 186 | for_each_online_cpu(cpu) |
87 | fini_debug_store_on_cpu(cpu); | 187 | fini_debug_store_on_cpu(cpu); |
88 | 188 | ||
89 | for_each_possible_cpu(cpu) { | 189 | for_each_possible_cpu(cpu) { |
90 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | 190 | release_pebs_buffer(cpu); |
91 | 191 | release_bts_buffer(cpu); | |
92 | if (!ds) | 192 | release_ds_buffer(cpu); |
93 | continue; | ||
94 | |||
95 | per_cpu(cpu_hw_events, cpu).ds = NULL; | ||
96 | |||
97 | kfree((void *)(unsigned long)ds->pebs_buffer_base); | ||
98 | kfree((void *)(unsigned long)ds->bts_buffer_base); | ||
99 | kfree(ds); | ||
100 | } | 193 | } |
101 | |||
102 | put_online_cpus(); | 194 | put_online_cpus(); |
103 | } | 195 | } |
104 | 196 | ||
105 | static int reserve_ds_buffers(void) | 197 | static void reserve_ds_buffers(void) |
106 | { | 198 | { |
107 | int cpu, err = 0; | 199 | int bts_err = 0, pebs_err = 0; |
200 | int cpu; | ||
201 | |||
202 | x86_pmu.bts_active = 0; | ||
203 | x86_pmu.pebs_active = 0; | ||
108 | 204 | ||
109 | if (!x86_pmu.bts && !x86_pmu.pebs) | 205 | if (!x86_pmu.bts && !x86_pmu.pebs) |
110 | return 0; | 206 | return; |
207 | |||
208 | if (!x86_pmu.bts) | ||
209 | bts_err = 1; | ||
210 | |||
211 | if (!x86_pmu.pebs) | ||
212 | pebs_err = 1; | ||
111 | 213 | ||
112 | get_online_cpus(); | 214 | get_online_cpus(); |
113 | 215 | ||
114 | for_each_possible_cpu(cpu) { | 216 | for_each_possible_cpu(cpu) { |
115 | struct debug_store *ds; | 217 | if (alloc_ds_buffer(cpu)) { |
116 | void *buffer; | 218 | bts_err = 1; |
117 | int max, thresh; | 219 | pebs_err = 1; |
220 | } | ||
118 | 221 | ||
119 | err = -ENOMEM; | 222 | if (!bts_err && alloc_bts_buffer(cpu)) |
120 | ds = kzalloc(sizeof(*ds), GFP_KERNEL); | 223 | bts_err = 1; |
121 | if (unlikely(!ds)) | 224 | |
225 | if (!pebs_err && alloc_pebs_buffer(cpu)) | ||
226 | pebs_err = 1; | ||
227 | |||
228 | if (bts_err && pebs_err) | ||
122 | break; | 229 | break; |
123 | per_cpu(cpu_hw_events, cpu).ds = ds; | 230 | } |
124 | |||
125 | if (x86_pmu.bts) { | ||
126 | buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL); | ||
127 | if (unlikely(!buffer)) | ||
128 | break; | ||
129 | |||
130 | max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE; | ||
131 | thresh = max / 16; | ||
132 | |||
133 | ds->bts_buffer_base = (u64)(unsigned long)buffer; | ||
134 | ds->bts_index = ds->bts_buffer_base; | ||
135 | ds->bts_absolute_maximum = ds->bts_buffer_base + | ||
136 | max * BTS_RECORD_SIZE; | ||
137 | ds->bts_interrupt_threshold = ds->bts_absolute_maximum - | ||
138 | thresh * BTS_RECORD_SIZE; | ||
139 | } | ||
140 | 231 | ||
141 | if (x86_pmu.pebs) { | 232 | if (bts_err) { |
142 | buffer = kzalloc(PEBS_BUFFER_SIZE, GFP_KERNEL); | 233 | for_each_possible_cpu(cpu) |
143 | if (unlikely(!buffer)) | 234 | release_bts_buffer(cpu); |
144 | break; | 235 | } |
145 | |||
146 | max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size; | ||
147 | |||
148 | ds->pebs_buffer_base = (u64)(unsigned long)buffer; | ||
149 | ds->pebs_index = ds->pebs_buffer_base; | ||
150 | ds->pebs_absolute_maximum = ds->pebs_buffer_base + | ||
151 | max * x86_pmu.pebs_record_size; | ||
152 | /* | ||
153 | * Always use single record PEBS | ||
154 | */ | ||
155 | ds->pebs_interrupt_threshold = ds->pebs_buffer_base + | ||
156 | x86_pmu.pebs_record_size; | ||
157 | } | ||
158 | 236 | ||
159 | err = 0; | 237 | if (pebs_err) { |
238 | for_each_possible_cpu(cpu) | ||
239 | release_pebs_buffer(cpu); | ||
160 | } | 240 | } |
161 | 241 | ||
162 | if (err) | 242 | if (bts_err && pebs_err) { |
163 | release_ds_buffers(); | 243 | for_each_possible_cpu(cpu) |
164 | else { | 244 | release_ds_buffer(cpu); |
245 | } else { | ||
246 | if (x86_pmu.bts && !bts_err) | ||
247 | x86_pmu.bts_active = 1; | ||
248 | |||
249 | if (x86_pmu.pebs && !pebs_err) | ||
250 | x86_pmu.pebs_active = 1; | ||
251 | |||
165 | for_each_online_cpu(cpu) | 252 | for_each_online_cpu(cpu) |
166 | init_debug_store_on_cpu(cpu); | 253 | init_debug_store_on_cpu(cpu); |
167 | } | 254 | } |
168 | 255 | ||
169 | put_online_cpus(); | 256 | put_online_cpus(); |
170 | |||
171 | return err; | ||
172 | } | 257 | } |
173 | 258 | ||
174 | /* | 259 | /* |
@@ -214,7 +299,7 @@ static void intel_pmu_disable_bts(void) | |||
214 | update_debugctlmsr(debugctlmsr); | 299 | update_debugctlmsr(debugctlmsr); |
215 | } | 300 | } |
216 | 301 | ||
217 | static void intel_pmu_drain_bts_buffer(void) | 302 | static int intel_pmu_drain_bts_buffer(void) |
218 | { | 303 | { |
219 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 304 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
220 | struct debug_store *ds = cpuc->ds; | 305 | struct debug_store *ds = cpuc->ds; |
@@ -231,16 +316,16 @@ static void intel_pmu_drain_bts_buffer(void) | |||
231 | struct pt_regs regs; | 316 | struct pt_regs regs; |
232 | 317 | ||
233 | if (!event) | 318 | if (!event) |
234 | return; | 319 | return 0; |
235 | 320 | ||
236 | if (!ds) | 321 | if (!x86_pmu.bts_active) |
237 | return; | 322 | return 0; |
238 | 323 | ||
239 | at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; | 324 | at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; |
240 | top = (struct bts_record *)(unsigned long)ds->bts_index; | 325 | top = (struct bts_record *)(unsigned long)ds->bts_index; |
241 | 326 | ||
242 | if (top <= at) | 327 | if (top <= at) |
243 | return; | 328 | return 0; |
244 | 329 | ||
245 | ds->bts_index = ds->bts_buffer_base; | 330 | ds->bts_index = ds->bts_buffer_base; |
246 | 331 | ||
@@ -256,7 +341,7 @@ static void intel_pmu_drain_bts_buffer(void) | |||
256 | perf_prepare_sample(&header, &data, event, ®s); | 341 | perf_prepare_sample(&header, &data, event, ®s); |
257 | 342 | ||
258 | if (perf_output_begin(&handle, event, header.size * (top - at), 1, 1)) | 343 | if (perf_output_begin(&handle, event, header.size * (top - at), 1, 1)) |
259 | return; | 344 | return 1; |
260 | 345 | ||
261 | for (; at < top; at++) { | 346 | for (; at < top; at++) { |
262 | data.ip = at->from; | 347 | data.ip = at->from; |
@@ -270,35 +355,76 @@ static void intel_pmu_drain_bts_buffer(void) | |||
270 | /* There's new data available. */ | 355 | /* There's new data available. */ |
271 | event->hw.interrupts++; | 356 | event->hw.interrupts++; |
272 | event->pending_kill = POLL_IN; | 357 | event->pending_kill = POLL_IN; |
358 | return 1; | ||
273 | } | 359 | } |
274 | 360 | ||
275 | /* | 361 | /* |
276 | * PEBS | 362 | * PEBS |
277 | */ | 363 | */ |
364 | static struct event_constraint intel_core2_pebs_event_constraints[] = { | ||
365 | INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY */ | ||
366 | INTEL_UEVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */ | ||
367 | INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */ | ||
368 | INTEL_UEVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */ | ||
369 | INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED.* */ | ||
370 | EVENT_CONSTRAINT_END | ||
371 | }; | ||
372 | |||
373 | static struct event_constraint intel_atom_pebs_event_constraints[] = { | ||
374 | INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY */ | ||
375 | INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* MISPREDICTED_BRANCH_RETIRED */ | ||
376 | INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED.* */ | ||
377 | EVENT_CONSTRAINT_END | ||
378 | }; | ||
379 | |||
380 | static struct event_constraint intel_nehalem_pebs_event_constraints[] = { | ||
381 | INTEL_EVENT_CONSTRAINT(0x0b, 0xf), /* MEM_INST_RETIRED.* */ | ||
382 | INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */ | ||
383 | INTEL_UEVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */ | ||
384 | INTEL_EVENT_CONSTRAINT(0xc0, 0xf), /* INST_RETIRED.ANY */ | ||
385 | INTEL_EVENT_CONSTRAINT(0xc2, 0xf), /* UOPS_RETIRED.* */ | ||
386 | INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */ | ||
387 | INTEL_UEVENT_CONSTRAINT(0x02c5, 0xf), /* BR_MISP_RETIRED.NEAR_CALL */ | ||
388 | INTEL_EVENT_CONSTRAINT(0xc7, 0xf), /* SSEX_UOPS_RETIRED.* */ | ||
389 | INTEL_UEVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */ | ||
390 | INTEL_EVENT_CONSTRAINT(0xcb, 0xf), /* MEM_LOAD_RETIRED.* */ | ||
391 | INTEL_EVENT_CONSTRAINT(0xf7, 0xf), /* FP_ASSIST.* */ | ||
392 | EVENT_CONSTRAINT_END | ||
393 | }; | ||
278 | 394 | ||
279 | static struct event_constraint intel_core_pebs_events[] = { | 395 | static struct event_constraint intel_westmere_pebs_event_constraints[] = { |
280 | PEBS_EVENT_CONSTRAINT(0x00c0, 0x1), /* INSTR_RETIRED.ANY */ | 396 | INTEL_EVENT_CONSTRAINT(0x0b, 0xf), /* MEM_INST_RETIRED.* */ |
281 | PEBS_EVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */ | 397 | INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */ |
282 | PEBS_EVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */ | 398 | INTEL_UEVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */ |
283 | PEBS_EVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */ | 399 | INTEL_EVENT_CONSTRAINT(0xc0, 0xf), /* INSTR_RETIRED.* */ |
284 | PEBS_EVENT_CONSTRAINT(0x01cb, 0x1), /* MEM_LOAD_RETIRED.L1D_MISS */ | 400 | INTEL_EVENT_CONSTRAINT(0xc2, 0xf), /* UOPS_RETIRED.* */ |
285 | PEBS_EVENT_CONSTRAINT(0x02cb, 0x1), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */ | 401 | INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */ |
286 | PEBS_EVENT_CONSTRAINT(0x04cb, 0x1), /* MEM_LOAD_RETIRED.L2_MISS */ | 402 | INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */ |
287 | PEBS_EVENT_CONSTRAINT(0x08cb, 0x1), /* MEM_LOAD_RETIRED.L2_LINE_MISS */ | 403 | INTEL_EVENT_CONSTRAINT(0xc7, 0xf), /* SSEX_UOPS_RETIRED.* */ |
288 | PEBS_EVENT_CONSTRAINT(0x10cb, 0x1), /* MEM_LOAD_RETIRED.DTLB_MISS */ | 404 | INTEL_UEVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */ |
405 | INTEL_EVENT_CONSTRAINT(0xcb, 0xf), /* MEM_LOAD_RETIRED.* */ | ||
406 | INTEL_EVENT_CONSTRAINT(0xf7, 0xf), /* FP_ASSIST.* */ | ||
289 | EVENT_CONSTRAINT_END | 407 | EVENT_CONSTRAINT_END |
290 | }; | 408 | }; |
291 | 409 | ||
292 | static struct event_constraint intel_nehalem_pebs_events[] = { | 410 | static struct event_constraint intel_snb_pebs_events[] = { |
293 | PEBS_EVENT_CONSTRAINT(0x00c0, 0xf), /* INSTR_RETIRED.ANY */ | 411 | INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */ |
294 | PEBS_EVENT_CONSTRAINT(0xfec1, 0xf), /* X87_OPS_RETIRED.ANY */ | 412 | INTEL_UEVENT_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */ |
295 | PEBS_EVENT_CONSTRAINT(0x00c5, 0xf), /* BR_INST_RETIRED.MISPRED */ | 413 | INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */ |
296 | PEBS_EVENT_CONSTRAINT(0x1fc7, 0xf), /* SIMD_INST_RETURED.ANY */ | 414 | INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */ |
297 | PEBS_EVENT_CONSTRAINT(0x01cb, 0xf), /* MEM_LOAD_RETIRED.L1D_MISS */ | 415 | INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */ |
298 | PEBS_EVENT_CONSTRAINT(0x02cb, 0xf), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */ | 416 | INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.* */ |
299 | PEBS_EVENT_CONSTRAINT(0x04cb, 0xf), /* MEM_LOAD_RETIRED.L2_MISS */ | 417 | INTEL_UEVENT_CONSTRAINT(0x11d0, 0xf), /* MEM_UOP_RETIRED.STLB_MISS_LOADS */ |
300 | PEBS_EVENT_CONSTRAINT(0x08cb, 0xf), /* MEM_LOAD_RETIRED.L2_LINE_MISS */ | 418 | INTEL_UEVENT_CONSTRAINT(0x12d0, 0xf), /* MEM_UOP_RETIRED.STLB_MISS_STORES */ |
301 | PEBS_EVENT_CONSTRAINT(0x10cb, 0xf), /* MEM_LOAD_RETIRED.DTLB_MISS */ | 419 | INTEL_UEVENT_CONSTRAINT(0x21d0, 0xf), /* MEM_UOP_RETIRED.LOCK_LOADS */ |
420 | INTEL_UEVENT_CONSTRAINT(0x22d0, 0xf), /* MEM_UOP_RETIRED.LOCK_STORES */ | ||
421 | INTEL_UEVENT_CONSTRAINT(0x41d0, 0xf), /* MEM_UOP_RETIRED.SPLIT_LOADS */ | ||
422 | INTEL_UEVENT_CONSTRAINT(0x42d0, 0xf), /* MEM_UOP_RETIRED.SPLIT_STORES */ | ||
423 | INTEL_UEVENT_CONSTRAINT(0x81d0, 0xf), /* MEM_UOP_RETIRED.ANY_LOADS */ | ||
424 | INTEL_UEVENT_CONSTRAINT(0x82d0, 0xf), /* MEM_UOP_RETIRED.ANY_STORES */ | ||
425 | INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */ | ||
426 | INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */ | ||
427 | INTEL_UEVENT_CONSTRAINT(0x02d4, 0xf), /* MEM_LOAD_UOPS_MISC_RETIRED.LLC_MISS */ | ||
302 | EVENT_CONSTRAINT_END | 428 | EVENT_CONSTRAINT_END |
303 | }; | 429 | }; |
304 | 430 | ||
@@ -491,7 +617,7 @@ static void __intel_pmu_pebs_event(struct perf_event *event, | |||
491 | regs.flags &= ~PERF_EFLAGS_EXACT; | 617 | regs.flags &= ~PERF_EFLAGS_EXACT; |
492 | 618 | ||
493 | if (perf_event_overflow(event, 1, &data, ®s)) | 619 | if (perf_event_overflow(event, 1, &data, ®s)) |
494 | x86_pmu_stop(event); | 620 | x86_pmu_stop(event, 0); |
495 | } | 621 | } |
496 | 622 | ||
497 | static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) | 623 | static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) |
@@ -502,7 +628,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) | |||
502 | struct pebs_record_core *at, *top; | 628 | struct pebs_record_core *at, *top; |
503 | int n; | 629 | int n; |
504 | 630 | ||
505 | if (!ds || !x86_pmu.pebs) | 631 | if (!x86_pmu.pebs_active) |
506 | return; | 632 | return; |
507 | 633 | ||
508 | at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base; | 634 | at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base; |
@@ -544,7 +670,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) | |||
544 | u64 status = 0; | 670 | u64 status = 0; |
545 | int bit, n; | 671 | int bit, n; |
546 | 672 | ||
547 | if (!ds || !x86_pmu.pebs) | 673 | if (!x86_pmu.pebs_active) |
548 | return; | 674 | return; |
549 | 675 | ||
550 | at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base; | 676 | at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base; |
@@ -609,29 +735,25 @@ static void intel_ds_init(void) | |||
609 | printk(KERN_CONT "PEBS fmt0%c, ", pebs_type); | 735 | printk(KERN_CONT "PEBS fmt0%c, ", pebs_type); |
610 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_core); | 736 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_core); |
611 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_core; | 737 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_core; |
612 | x86_pmu.pebs_constraints = intel_core_pebs_events; | ||
613 | break; | 738 | break; |
614 | 739 | ||
615 | case 1: | 740 | case 1: |
616 | printk(KERN_CONT "PEBS fmt1%c, ", pebs_type); | 741 | printk(KERN_CONT "PEBS fmt1%c, ", pebs_type); |
617 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm); | 742 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm); |
618 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm; | 743 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm; |
619 | x86_pmu.pebs_constraints = intel_nehalem_pebs_events; | ||
620 | break; | 744 | break; |
621 | 745 | ||
622 | default: | 746 | default: |
623 | printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type); | 747 | printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type); |
624 | x86_pmu.pebs = 0; | 748 | x86_pmu.pebs = 0; |
625 | break; | ||
626 | } | 749 | } |
627 | } | 750 | } |
628 | } | 751 | } |
629 | 752 | ||
630 | #else /* CONFIG_CPU_SUP_INTEL */ | 753 | #else /* CONFIG_CPU_SUP_INTEL */ |
631 | 754 | ||
632 | static int reserve_ds_buffers(void) | 755 | static void reserve_ds_buffers(void) |
633 | { | 756 | { |
634 | return 0; | ||
635 | } | 757 | } |
636 | 758 | ||
637 | static void release_ds_buffers(void) | 759 | static void release_ds_buffers(void) |
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c index 249015173992..ead584fb6a7d 100644 --- a/arch/x86/kernel/cpu/perf_event_p4.c +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Netburst Perfomance Events (P4, old Xeon) | 2 | * Netburst Performance Events (P4, old Xeon) |
3 | * | 3 | * |
4 | * Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org> | 4 | * Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org> |
5 | * Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com> | 5 | * Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com> |
@@ -18,6 +18,8 @@ | |||
18 | struct p4_event_bind { | 18 | struct p4_event_bind { |
19 | unsigned int opcode; /* Event code and ESCR selector */ | 19 | unsigned int opcode; /* Event code and ESCR selector */ |
20 | unsigned int escr_msr[2]; /* ESCR MSR for this event */ | 20 | unsigned int escr_msr[2]; /* ESCR MSR for this event */ |
21 | unsigned int escr_emask; /* valid ESCR EventMask bits */ | ||
22 | unsigned int shared; /* event is shared across threads */ | ||
21 | char cntr[2][P4_CNTR_LIMIT]; /* counter index (offset), -1 on abscence */ | 23 | char cntr[2][P4_CNTR_LIMIT]; /* counter index (offset), -1 on abscence */ |
22 | }; | 24 | }; |
23 | 25 | ||
@@ -66,231 +68,435 @@ static struct p4_event_bind p4_event_bind_map[] = { | |||
66 | [P4_EVENT_TC_DELIVER_MODE] = { | 68 | [P4_EVENT_TC_DELIVER_MODE] = { |
67 | .opcode = P4_OPCODE(P4_EVENT_TC_DELIVER_MODE), | 69 | .opcode = P4_OPCODE(P4_EVENT_TC_DELIVER_MODE), |
68 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, | 70 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, |
71 | .escr_emask = | ||
72 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, DD) | | ||
73 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, DB) | | ||
74 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, DI) | | ||
75 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, BD) | | ||
76 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, BB) | | ||
77 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, BI) | | ||
78 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, ID), | ||
79 | .shared = 1, | ||
69 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | 80 | .cntr = { {4, 5, -1}, {6, 7, -1} }, |
70 | }, | 81 | }, |
71 | [P4_EVENT_BPU_FETCH_REQUEST] = { | 82 | [P4_EVENT_BPU_FETCH_REQUEST] = { |
72 | .opcode = P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST), | 83 | .opcode = P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST), |
73 | .escr_msr = { MSR_P4_BPU_ESCR0, MSR_P4_BPU_ESCR1 }, | 84 | .escr_msr = { MSR_P4_BPU_ESCR0, MSR_P4_BPU_ESCR1 }, |
85 | .escr_emask = | ||
86 | P4_ESCR_EMASK_BIT(P4_EVENT_BPU_FETCH_REQUEST, TCMISS), | ||
74 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 87 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
75 | }, | 88 | }, |
76 | [P4_EVENT_ITLB_REFERENCE] = { | 89 | [P4_EVENT_ITLB_REFERENCE] = { |
77 | .opcode = P4_OPCODE(P4_EVENT_ITLB_REFERENCE), | 90 | .opcode = P4_OPCODE(P4_EVENT_ITLB_REFERENCE), |
78 | .escr_msr = { MSR_P4_ITLB_ESCR0, MSR_P4_ITLB_ESCR1 }, | 91 | .escr_msr = { MSR_P4_ITLB_ESCR0, MSR_P4_ITLB_ESCR1 }, |
92 | .escr_emask = | ||
93 | P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE, HIT) | | ||
94 | P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE, MISS) | | ||
95 | P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE, HIT_UK), | ||
79 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 96 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
80 | }, | 97 | }, |
81 | [P4_EVENT_MEMORY_CANCEL] = { | 98 | [P4_EVENT_MEMORY_CANCEL] = { |
82 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_CANCEL), | 99 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_CANCEL), |
83 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, | 100 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, |
101 | .escr_emask = | ||
102 | P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_CANCEL, ST_RB_FULL) | | ||
103 | P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_CANCEL, 64K_CONF), | ||
84 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 104 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
85 | }, | 105 | }, |
86 | [P4_EVENT_MEMORY_COMPLETE] = { | 106 | [P4_EVENT_MEMORY_COMPLETE] = { |
87 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_COMPLETE), | 107 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_COMPLETE), |
88 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, | 108 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, |
109 | .escr_emask = | ||
110 | P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_COMPLETE, LSC) | | ||
111 | P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_COMPLETE, SSC), | ||
89 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 112 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
90 | }, | 113 | }, |
91 | [P4_EVENT_LOAD_PORT_REPLAY] = { | 114 | [P4_EVENT_LOAD_PORT_REPLAY] = { |
92 | .opcode = P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY), | 115 | .opcode = P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY), |
93 | .escr_msr = { MSR_P4_SAAT_ESCR0, MSR_P4_SAAT_ESCR1 }, | 116 | .escr_msr = { MSR_P4_SAAT_ESCR0, MSR_P4_SAAT_ESCR1 }, |
117 | .escr_emask = | ||
118 | P4_ESCR_EMASK_BIT(P4_EVENT_LOAD_PORT_REPLAY, SPLIT_LD), | ||
94 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 119 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
95 | }, | 120 | }, |
96 | [P4_EVENT_STORE_PORT_REPLAY] = { | 121 | [P4_EVENT_STORE_PORT_REPLAY] = { |
97 | .opcode = P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY), | 122 | .opcode = P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY), |
98 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, | 123 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, |
124 | .escr_emask = | ||
125 | P4_ESCR_EMASK_BIT(P4_EVENT_STORE_PORT_REPLAY, SPLIT_ST), | ||
99 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 126 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
100 | }, | 127 | }, |
101 | [P4_EVENT_MOB_LOAD_REPLAY] = { | 128 | [P4_EVENT_MOB_LOAD_REPLAY] = { |
102 | .opcode = P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY), | 129 | .opcode = P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY), |
103 | .escr_msr = { MSR_P4_MOB_ESCR0, MSR_P4_MOB_ESCR1 }, | 130 | .escr_msr = { MSR_P4_MOB_ESCR0, MSR_P4_MOB_ESCR1 }, |
131 | .escr_emask = | ||
132 | P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, NO_STA) | | ||
133 | P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, NO_STD) | | ||
134 | P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, PARTIAL_DATA) | | ||
135 | P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, UNALGN_ADDR), | ||
104 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 136 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
105 | }, | 137 | }, |
106 | [P4_EVENT_PAGE_WALK_TYPE] = { | 138 | [P4_EVENT_PAGE_WALK_TYPE] = { |
107 | .opcode = P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE), | 139 | .opcode = P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE), |
108 | .escr_msr = { MSR_P4_PMH_ESCR0, MSR_P4_PMH_ESCR1 }, | 140 | .escr_msr = { MSR_P4_PMH_ESCR0, MSR_P4_PMH_ESCR1 }, |
141 | .escr_emask = | ||
142 | P4_ESCR_EMASK_BIT(P4_EVENT_PAGE_WALK_TYPE, DTMISS) | | ||
143 | P4_ESCR_EMASK_BIT(P4_EVENT_PAGE_WALK_TYPE, ITMISS), | ||
144 | .shared = 1, | ||
109 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 145 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
110 | }, | 146 | }, |
111 | [P4_EVENT_BSQ_CACHE_REFERENCE] = { | 147 | [P4_EVENT_BSQ_CACHE_REFERENCE] = { |
112 | .opcode = P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE), | 148 | .opcode = P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE), |
113 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR1 }, | 149 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR1 }, |
150 | .escr_emask = | ||
151 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS) | | ||
152 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE) | | ||
153 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM) | | ||
154 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS) | | ||
155 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE) | | ||
156 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM) | | ||
157 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS) | | ||
158 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS) | | ||
159 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS), | ||
114 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 160 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
115 | }, | 161 | }, |
116 | [P4_EVENT_IOQ_ALLOCATION] = { | 162 | [P4_EVENT_IOQ_ALLOCATION] = { |
117 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ALLOCATION), | 163 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ALLOCATION), |
118 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 164 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
165 | .escr_emask = | ||
166 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, DEFAULT) | | ||
167 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, ALL_READ) | | ||
168 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, ALL_WRITE) | | ||
169 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_UC) | | ||
170 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WC) | | ||
171 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WT) | | ||
172 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WP) | | ||
173 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WB) | | ||
174 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, OWN) | | ||
175 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, OTHER) | | ||
176 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, PREFETCH), | ||
119 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 177 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
120 | }, | 178 | }, |
121 | [P4_EVENT_IOQ_ACTIVE_ENTRIES] = { /* shared ESCR */ | 179 | [P4_EVENT_IOQ_ACTIVE_ENTRIES] = { /* shared ESCR */ |
122 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES), | 180 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES), |
123 | .escr_msr = { MSR_P4_FSB_ESCR1, MSR_P4_FSB_ESCR1 }, | 181 | .escr_msr = { MSR_P4_FSB_ESCR1, MSR_P4_FSB_ESCR1 }, |
182 | .escr_emask = | ||
183 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, DEFAULT) | | ||
184 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_READ) | | ||
185 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_WRITE) | | ||
186 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_UC) | | ||
187 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WC) | | ||
188 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WT) | | ||
189 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WP) | | ||
190 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WB) | | ||
191 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, OWN) | | ||
192 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, OTHER) | | ||
193 | P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, PREFETCH), | ||
124 | .cntr = { {2, -1, -1}, {3, -1, -1} }, | 194 | .cntr = { {2, -1, -1}, {3, -1, -1} }, |
125 | }, | 195 | }, |
126 | [P4_EVENT_FSB_DATA_ACTIVITY] = { | 196 | [P4_EVENT_FSB_DATA_ACTIVITY] = { |
127 | .opcode = P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY), | 197 | .opcode = P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY), |
128 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 198 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
199 | .escr_emask = | ||
200 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV) | | ||
201 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN) | | ||
202 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OTHER) | | ||
203 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_DRV) | | ||
204 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OWN) | | ||
205 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OTHER), | ||
206 | .shared = 1, | ||
129 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 207 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
130 | }, | 208 | }, |
131 | [P4_EVENT_BSQ_ALLOCATION] = { /* shared ESCR, broken CCCR1 */ | 209 | [P4_EVENT_BSQ_ALLOCATION] = { /* shared ESCR, broken CCCR1 */ |
132 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ALLOCATION), | 210 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ALLOCATION), |
133 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR0 }, | 211 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR0 }, |
212 | .escr_emask = | ||
213 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE0) | | ||
214 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE1) | | ||
215 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_LEN0) | | ||
216 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_LEN1) | | ||
217 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_IO_TYPE) | | ||
218 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_LOCK_TYPE) | | ||
219 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_CACHE_TYPE) | | ||
220 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_SPLIT_TYPE) | | ||
221 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_DEM_TYPE) | | ||
222 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_ORD_TYPE) | | ||
223 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE0) | | ||
224 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE1) | | ||
225 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE2), | ||
134 | .cntr = { {0, -1, -1}, {1, -1, -1} }, | 226 | .cntr = { {0, -1, -1}, {1, -1, -1} }, |
135 | }, | 227 | }, |
136 | [P4_EVENT_BSQ_ACTIVE_ENTRIES] = { /* shared ESCR */ | 228 | [P4_EVENT_BSQ_ACTIVE_ENTRIES] = { /* shared ESCR */ |
137 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES), | 229 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES), |
138 | .escr_msr = { MSR_P4_BSU_ESCR1 , MSR_P4_BSU_ESCR1 }, | 230 | .escr_msr = { MSR_P4_BSU_ESCR1 , MSR_P4_BSU_ESCR1 }, |
231 | .escr_emask = | ||
232 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE0) | | ||
233 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE1) | | ||
234 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN0) | | ||
235 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN1) | | ||
236 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_IO_TYPE) | | ||
237 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LOCK_TYPE) | | ||
238 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_CACHE_TYPE) | | ||
239 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_SPLIT_TYPE) | | ||
240 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_DEM_TYPE) | | ||
241 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_ORD_TYPE) | | ||
242 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE0) | | ||
243 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE1) | | ||
244 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE2), | ||
139 | .cntr = { {2, -1, -1}, {3, -1, -1} }, | 245 | .cntr = { {2, -1, -1}, {3, -1, -1} }, |
140 | }, | 246 | }, |
141 | [P4_EVENT_SSE_INPUT_ASSIST] = { | 247 | [P4_EVENT_SSE_INPUT_ASSIST] = { |
142 | .opcode = P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST), | 248 | .opcode = P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST), |
143 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 249 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
250 | .escr_emask = | ||
251 | P4_ESCR_EMASK_BIT(P4_EVENT_SSE_INPUT_ASSIST, ALL), | ||
252 | .shared = 1, | ||
144 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 253 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
145 | }, | 254 | }, |
146 | [P4_EVENT_PACKED_SP_UOP] = { | 255 | [P4_EVENT_PACKED_SP_UOP] = { |
147 | .opcode = P4_OPCODE(P4_EVENT_PACKED_SP_UOP), | 256 | .opcode = P4_OPCODE(P4_EVENT_PACKED_SP_UOP), |
148 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 257 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
258 | .escr_emask = | ||
259 | P4_ESCR_EMASK_BIT(P4_EVENT_PACKED_SP_UOP, ALL), | ||
260 | .shared = 1, | ||
149 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 261 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
150 | }, | 262 | }, |
151 | [P4_EVENT_PACKED_DP_UOP] = { | 263 | [P4_EVENT_PACKED_DP_UOP] = { |
152 | .opcode = P4_OPCODE(P4_EVENT_PACKED_DP_UOP), | 264 | .opcode = P4_OPCODE(P4_EVENT_PACKED_DP_UOP), |
153 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 265 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
266 | .escr_emask = | ||
267 | P4_ESCR_EMASK_BIT(P4_EVENT_PACKED_DP_UOP, ALL), | ||
268 | .shared = 1, | ||
154 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 269 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
155 | }, | 270 | }, |
156 | [P4_EVENT_SCALAR_SP_UOP] = { | 271 | [P4_EVENT_SCALAR_SP_UOP] = { |
157 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_SP_UOP), | 272 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_SP_UOP), |
158 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 273 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
274 | .escr_emask = | ||
275 | P4_ESCR_EMASK_BIT(P4_EVENT_SCALAR_SP_UOP, ALL), | ||
276 | .shared = 1, | ||
159 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 277 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
160 | }, | 278 | }, |
161 | [P4_EVENT_SCALAR_DP_UOP] = { | 279 | [P4_EVENT_SCALAR_DP_UOP] = { |
162 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_DP_UOP), | 280 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_DP_UOP), |
163 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 281 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
282 | .escr_emask = | ||
283 | P4_ESCR_EMASK_BIT(P4_EVENT_SCALAR_DP_UOP, ALL), | ||
284 | .shared = 1, | ||
164 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 285 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
165 | }, | 286 | }, |
166 | [P4_EVENT_64BIT_MMX_UOP] = { | 287 | [P4_EVENT_64BIT_MMX_UOP] = { |
167 | .opcode = P4_OPCODE(P4_EVENT_64BIT_MMX_UOP), | 288 | .opcode = P4_OPCODE(P4_EVENT_64BIT_MMX_UOP), |
168 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 289 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
290 | .escr_emask = | ||
291 | P4_ESCR_EMASK_BIT(P4_EVENT_64BIT_MMX_UOP, ALL), | ||
292 | .shared = 1, | ||
169 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 293 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
170 | }, | 294 | }, |
171 | [P4_EVENT_128BIT_MMX_UOP] = { | 295 | [P4_EVENT_128BIT_MMX_UOP] = { |
172 | .opcode = P4_OPCODE(P4_EVENT_128BIT_MMX_UOP), | 296 | .opcode = P4_OPCODE(P4_EVENT_128BIT_MMX_UOP), |
173 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 297 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
298 | .escr_emask = | ||
299 | P4_ESCR_EMASK_BIT(P4_EVENT_128BIT_MMX_UOP, ALL), | ||
300 | .shared = 1, | ||
174 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 301 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
175 | }, | 302 | }, |
176 | [P4_EVENT_X87_FP_UOP] = { | 303 | [P4_EVENT_X87_FP_UOP] = { |
177 | .opcode = P4_OPCODE(P4_EVENT_X87_FP_UOP), | 304 | .opcode = P4_OPCODE(P4_EVENT_X87_FP_UOP), |
178 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | 305 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, |
306 | .escr_emask = | ||
307 | P4_ESCR_EMASK_BIT(P4_EVENT_X87_FP_UOP, ALL), | ||
308 | .shared = 1, | ||
179 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 309 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
180 | }, | 310 | }, |
181 | [P4_EVENT_TC_MISC] = { | 311 | [P4_EVENT_TC_MISC] = { |
182 | .opcode = P4_OPCODE(P4_EVENT_TC_MISC), | 312 | .opcode = P4_OPCODE(P4_EVENT_TC_MISC), |
183 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, | 313 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, |
314 | .escr_emask = | ||
315 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_MISC, FLUSH), | ||
184 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | 316 | .cntr = { {4, 5, -1}, {6, 7, -1} }, |
185 | }, | 317 | }, |
186 | [P4_EVENT_GLOBAL_POWER_EVENTS] = { | 318 | [P4_EVENT_GLOBAL_POWER_EVENTS] = { |
187 | .opcode = P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS), | 319 | .opcode = P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS), |
188 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 320 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
321 | .escr_emask = | ||
322 | P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING), | ||
189 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 323 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
190 | }, | 324 | }, |
191 | [P4_EVENT_TC_MS_XFER] = { | 325 | [P4_EVENT_TC_MS_XFER] = { |
192 | .opcode = P4_OPCODE(P4_EVENT_TC_MS_XFER), | 326 | .opcode = P4_OPCODE(P4_EVENT_TC_MS_XFER), |
193 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, | 327 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, |
328 | .escr_emask = | ||
329 | P4_ESCR_EMASK_BIT(P4_EVENT_TC_MS_XFER, CISC), | ||
194 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | 330 | .cntr = { {4, 5, -1}, {6, 7, -1} }, |
195 | }, | 331 | }, |
196 | [P4_EVENT_UOP_QUEUE_WRITES] = { | 332 | [P4_EVENT_UOP_QUEUE_WRITES] = { |
197 | .opcode = P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES), | 333 | .opcode = P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES), |
198 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, | 334 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, |
335 | .escr_emask = | ||
336 | P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_BUILD) | | ||
337 | P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_DELIVER) | | ||
338 | P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES, FROM_ROM), | ||
199 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | 339 | .cntr = { {4, 5, -1}, {6, 7, -1} }, |
200 | }, | 340 | }, |
201 | [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE] = { | 341 | [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE] = { |
202 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE), | 342 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE), |
203 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR0 }, | 343 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR0 }, |
344 | .escr_emask = | ||
345 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CONDITIONAL) | | ||
346 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CALL) | | ||
347 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, RETURN) | | ||
348 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, INDIRECT), | ||
204 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | 349 | .cntr = { {4, 5, -1}, {6, 7, -1} }, |
205 | }, | 350 | }, |
206 | [P4_EVENT_RETIRED_BRANCH_TYPE] = { | 351 | [P4_EVENT_RETIRED_BRANCH_TYPE] = { |
207 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE), | 352 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE), |
208 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR1 }, | 353 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR1 }, |
354 | .escr_emask = | ||
355 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL) | | ||
356 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CALL) | | ||
357 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN) | | ||
358 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT), | ||
209 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | 359 | .cntr = { {4, 5, -1}, {6, 7, -1} }, |
210 | }, | 360 | }, |
211 | [P4_EVENT_RESOURCE_STALL] = { | 361 | [P4_EVENT_RESOURCE_STALL] = { |
212 | .opcode = P4_OPCODE(P4_EVENT_RESOURCE_STALL), | 362 | .opcode = P4_OPCODE(P4_EVENT_RESOURCE_STALL), |
213 | .escr_msr = { MSR_P4_ALF_ESCR0, MSR_P4_ALF_ESCR1 }, | 363 | .escr_msr = { MSR_P4_ALF_ESCR0, MSR_P4_ALF_ESCR1 }, |
364 | .escr_emask = | ||
365 | P4_ESCR_EMASK_BIT(P4_EVENT_RESOURCE_STALL, SBFULL), | ||
214 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 366 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
215 | }, | 367 | }, |
216 | [P4_EVENT_WC_BUFFER] = { | 368 | [P4_EVENT_WC_BUFFER] = { |
217 | .opcode = P4_OPCODE(P4_EVENT_WC_BUFFER), | 369 | .opcode = P4_OPCODE(P4_EVENT_WC_BUFFER), |
218 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, | 370 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, |
371 | .escr_emask = | ||
372 | P4_ESCR_EMASK_BIT(P4_EVENT_WC_BUFFER, WCB_EVICTS) | | ||
373 | P4_ESCR_EMASK_BIT(P4_EVENT_WC_BUFFER, WCB_FULL_EVICTS), | ||
374 | .shared = 1, | ||
219 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | 375 | .cntr = { {8, 9, -1}, {10, 11, -1} }, |
220 | }, | 376 | }, |
221 | [P4_EVENT_B2B_CYCLES] = { | 377 | [P4_EVENT_B2B_CYCLES] = { |
222 | .opcode = P4_OPCODE(P4_EVENT_B2B_CYCLES), | 378 | .opcode = P4_OPCODE(P4_EVENT_B2B_CYCLES), |
223 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 379 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
380 | .escr_emask = 0, | ||
224 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 381 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
225 | }, | 382 | }, |
226 | [P4_EVENT_BNR] = { | 383 | [P4_EVENT_BNR] = { |
227 | .opcode = P4_OPCODE(P4_EVENT_BNR), | 384 | .opcode = P4_OPCODE(P4_EVENT_BNR), |
228 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 385 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
386 | .escr_emask = 0, | ||
229 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 387 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
230 | }, | 388 | }, |
231 | [P4_EVENT_SNOOP] = { | 389 | [P4_EVENT_SNOOP] = { |
232 | .opcode = P4_OPCODE(P4_EVENT_SNOOP), | 390 | .opcode = P4_OPCODE(P4_EVENT_SNOOP), |
233 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 391 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
392 | .escr_emask = 0, | ||
234 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 393 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
235 | }, | 394 | }, |
236 | [P4_EVENT_RESPONSE] = { | 395 | [P4_EVENT_RESPONSE] = { |
237 | .opcode = P4_OPCODE(P4_EVENT_RESPONSE), | 396 | .opcode = P4_OPCODE(P4_EVENT_RESPONSE), |
238 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | 397 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, |
398 | .escr_emask = 0, | ||
239 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | 399 | .cntr = { {0, -1, -1}, {2, -1, -1} }, |
240 | }, | 400 | }, |
241 | [P4_EVENT_FRONT_END_EVENT] = { | 401 | [P4_EVENT_FRONT_END_EVENT] = { |
242 | .opcode = P4_OPCODE(P4_EVENT_FRONT_END_EVENT), | 402 | .opcode = P4_OPCODE(P4_EVENT_FRONT_END_EVENT), |
243 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | 403 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, |
404 | .escr_emask = | ||
405 | P4_ESCR_EMASK_BIT(P4_EVENT_FRONT_END_EVENT, NBOGUS) | | ||
406 | P4_ESCR_EMASK_BIT(P4_EVENT_FRONT_END_EVENT, BOGUS), | ||
244 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 407 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
245 | }, | 408 | }, |
246 | [P4_EVENT_EXECUTION_EVENT] = { | 409 | [P4_EVENT_EXECUTION_EVENT] = { |
247 | .opcode = P4_OPCODE(P4_EVENT_EXECUTION_EVENT), | 410 | .opcode = P4_OPCODE(P4_EVENT_EXECUTION_EVENT), |
248 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | 411 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, |
412 | .escr_emask = | ||
413 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0) | | ||
414 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1) | | ||
415 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2) | | ||
416 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3) | | ||
417 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) | | ||
418 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) | | ||
419 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) | | ||
420 | P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3), | ||
249 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 421 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
250 | }, | 422 | }, |
251 | [P4_EVENT_REPLAY_EVENT] = { | 423 | [P4_EVENT_REPLAY_EVENT] = { |
252 | .opcode = P4_OPCODE(P4_EVENT_REPLAY_EVENT), | 424 | .opcode = P4_OPCODE(P4_EVENT_REPLAY_EVENT), |
253 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | 425 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, |
426 | .escr_emask = | ||
427 | P4_ESCR_EMASK_BIT(P4_EVENT_REPLAY_EVENT, NBOGUS) | | ||
428 | P4_ESCR_EMASK_BIT(P4_EVENT_REPLAY_EVENT, BOGUS), | ||
254 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 429 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
255 | }, | 430 | }, |
256 | [P4_EVENT_INSTR_RETIRED] = { | 431 | [P4_EVENT_INSTR_RETIRED] = { |
257 | .opcode = P4_OPCODE(P4_EVENT_INSTR_RETIRED), | 432 | .opcode = P4_OPCODE(P4_EVENT_INSTR_RETIRED), |
258 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | 433 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, |
434 | .escr_emask = | ||
435 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG) | | ||
436 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSTAG) | | ||
437 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSNTAG) | | ||
438 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSTAG), | ||
259 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 439 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
260 | }, | 440 | }, |
261 | [P4_EVENT_UOPS_RETIRED] = { | 441 | [P4_EVENT_UOPS_RETIRED] = { |
262 | .opcode = P4_OPCODE(P4_EVENT_UOPS_RETIRED), | 442 | .opcode = P4_OPCODE(P4_EVENT_UOPS_RETIRED), |
263 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | 443 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, |
444 | .escr_emask = | ||
445 | P4_ESCR_EMASK_BIT(P4_EVENT_UOPS_RETIRED, NBOGUS) | | ||
446 | P4_ESCR_EMASK_BIT(P4_EVENT_UOPS_RETIRED, BOGUS), | ||
264 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 447 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
265 | }, | 448 | }, |
266 | [P4_EVENT_UOP_TYPE] = { | 449 | [P4_EVENT_UOP_TYPE] = { |
267 | .opcode = P4_OPCODE(P4_EVENT_UOP_TYPE), | 450 | .opcode = P4_OPCODE(P4_EVENT_UOP_TYPE), |
268 | .escr_msr = { MSR_P4_RAT_ESCR0, MSR_P4_RAT_ESCR1 }, | 451 | .escr_msr = { MSR_P4_RAT_ESCR0, MSR_P4_RAT_ESCR1 }, |
452 | .escr_emask = | ||
453 | P4_ESCR_EMASK_BIT(P4_EVENT_UOP_TYPE, TAGLOADS) | | ||
454 | P4_ESCR_EMASK_BIT(P4_EVENT_UOP_TYPE, TAGSTORES), | ||
269 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 455 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
270 | }, | 456 | }, |
271 | [P4_EVENT_BRANCH_RETIRED] = { | 457 | [P4_EVENT_BRANCH_RETIRED] = { |
272 | .opcode = P4_OPCODE(P4_EVENT_BRANCH_RETIRED), | 458 | .opcode = P4_OPCODE(P4_EVENT_BRANCH_RETIRED), |
273 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | 459 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, |
460 | .escr_emask = | ||
461 | P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMNP) | | ||
462 | P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMNM) | | ||
463 | P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMTP) | | ||
464 | P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMTM), | ||
274 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 465 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
275 | }, | 466 | }, |
276 | [P4_EVENT_MISPRED_BRANCH_RETIRED] = { | 467 | [P4_EVENT_MISPRED_BRANCH_RETIRED] = { |
277 | .opcode = P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED), | 468 | .opcode = P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED), |
278 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | 469 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, |
470 | .escr_emask = | ||
471 | P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS), | ||
279 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 472 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
280 | }, | 473 | }, |
281 | [P4_EVENT_X87_ASSIST] = { | 474 | [P4_EVENT_X87_ASSIST] = { |
282 | .opcode = P4_OPCODE(P4_EVENT_X87_ASSIST), | 475 | .opcode = P4_OPCODE(P4_EVENT_X87_ASSIST), |
283 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | 476 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, |
477 | .escr_emask = | ||
478 | P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, FPSU) | | ||
479 | P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, FPSO) | | ||
480 | P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, POAO) | | ||
481 | P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, POAU) | | ||
482 | P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, PREA), | ||
284 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 483 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
285 | }, | 484 | }, |
286 | [P4_EVENT_MACHINE_CLEAR] = { | 485 | [P4_EVENT_MACHINE_CLEAR] = { |
287 | .opcode = P4_OPCODE(P4_EVENT_MACHINE_CLEAR), | 486 | .opcode = P4_OPCODE(P4_EVENT_MACHINE_CLEAR), |
288 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | 487 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, |
488 | .escr_emask = | ||
489 | P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR, CLEAR) | | ||
490 | P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR, MOCLEAR) | | ||
491 | P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR, SMCLEAR), | ||
289 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 492 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
290 | }, | 493 | }, |
291 | [P4_EVENT_INSTR_COMPLETED] = { | 494 | [P4_EVENT_INSTR_COMPLETED] = { |
292 | .opcode = P4_OPCODE(P4_EVENT_INSTR_COMPLETED), | 495 | .opcode = P4_OPCODE(P4_EVENT_INSTR_COMPLETED), |
293 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | 496 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, |
497 | .escr_emask = | ||
498 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_COMPLETED, NBOGUS) | | ||
499 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_COMPLETED, BOGUS), | ||
294 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | 500 | .cntr = { {12, 13, 16}, {14, 15, 17} }, |
295 | }, | 501 | }, |
296 | }; | 502 | }; |
@@ -428,29 +634,73 @@ static u64 p4_pmu_event_map(int hw_event) | |||
428 | return config; | 634 | return config; |
429 | } | 635 | } |
430 | 636 | ||
637 | /* check cpu model specifics */ | ||
638 | static bool p4_event_match_cpu_model(unsigned int event_idx) | ||
639 | { | ||
640 | /* INSTR_COMPLETED event only exist for model 3, 4, 6 (Prescott) */ | ||
641 | if (event_idx == P4_EVENT_INSTR_COMPLETED) { | ||
642 | if (boot_cpu_data.x86_model != 3 && | ||
643 | boot_cpu_data.x86_model != 4 && | ||
644 | boot_cpu_data.x86_model != 6) | ||
645 | return false; | ||
646 | } | ||
647 | |||
648 | /* | ||
649 | * For info | ||
650 | * - IQ_ESCR0, IQ_ESCR1 only for models 1 and 2 | ||
651 | */ | ||
652 | |||
653 | return true; | ||
654 | } | ||
655 | |||
431 | static int p4_validate_raw_event(struct perf_event *event) | 656 | static int p4_validate_raw_event(struct perf_event *event) |
432 | { | 657 | { |
433 | unsigned int v; | 658 | unsigned int v, emask; |
434 | 659 | ||
435 | /* user data may have out-of-bound event index */ | 660 | /* User data may have out-of-bound event index */ |
436 | v = p4_config_unpack_event(event->attr.config); | 661 | v = p4_config_unpack_event(event->attr.config); |
437 | if (v >= ARRAY_SIZE(p4_event_bind_map)) { | 662 | if (v >= ARRAY_SIZE(p4_event_bind_map)) |
438 | pr_warning("P4 PMU: Unknown event code: %d\n", v); | 663 | return -EINVAL; |
664 | |||
665 | /* It may be unsupported: */ | ||
666 | if (!p4_event_match_cpu_model(v)) | ||
439 | return -EINVAL; | 667 | return -EINVAL; |
668 | |||
669 | /* | ||
670 | * NOTE: P4_CCCR_THREAD_ANY has not the same meaning as | ||
671 | * in Architectural Performance Monitoring, it means not | ||
672 | * on _which_ logical cpu to count but rather _when_, ie it | ||
673 | * depends on logical cpu state -- count event if one cpu active, | ||
674 | * none, both or any, so we just allow user to pass any value | ||
675 | * desired. | ||
676 | * | ||
677 | * In turn we always set Tx_OS/Tx_USR bits bound to logical | ||
678 | * cpu without their propagation to another cpu | ||
679 | */ | ||
680 | |||
681 | /* | ||
682 | * if an event is shared across the logical threads | ||
683 | * the user needs special permissions to be able to use it | ||
684 | */ | ||
685 | if (p4_ht_active() && p4_event_bind_map[v].shared) { | ||
686 | if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | ||
687 | return -EACCES; | ||
440 | } | 688 | } |
441 | 689 | ||
690 | /* ESCR EventMask bits may be invalid */ | ||
691 | emask = p4_config_unpack_escr(event->attr.config) & P4_ESCR_EVENTMASK_MASK; | ||
692 | if (emask & ~p4_event_bind_map[v].escr_emask) | ||
693 | return -EINVAL; | ||
694 | |||
442 | /* | 695 | /* |
443 | * it may have some screwed PEBS bits | 696 | * it may have some invalid PEBS bits |
444 | */ | 697 | */ |
445 | if (p4_config_pebs_has(event->attr.config, P4_PEBS_CONFIG_ENABLE)) { | 698 | if (p4_config_pebs_has(event->attr.config, P4_PEBS_CONFIG_ENABLE)) |
446 | pr_warning("P4 PMU: PEBS are not supported yet\n"); | ||
447 | return -EINVAL; | 699 | return -EINVAL; |
448 | } | 700 | |
449 | v = p4_config_unpack_metric(event->attr.config); | 701 | v = p4_config_unpack_metric(event->attr.config); |
450 | if (v >= ARRAY_SIZE(p4_pebs_bind_map)) { | 702 | if (v >= ARRAY_SIZE(p4_pebs_bind_map)) |
451 | pr_warning("P4 PMU: Unknown metric code: %d\n", v); | ||
452 | return -EINVAL; | 703 | return -EINVAL; |
453 | } | ||
454 | 704 | ||
455 | return 0; | 705 | return 0; |
456 | } | 706 | } |
@@ -477,28 +727,30 @@ static int p4_hw_config(struct perf_event *event) | |||
477 | event->hw.config = p4_set_ht_bit(event->hw.config); | 727 | event->hw.config = p4_set_ht_bit(event->hw.config); |
478 | 728 | ||
479 | if (event->attr.type == PERF_TYPE_RAW) { | 729 | if (event->attr.type == PERF_TYPE_RAW) { |
730 | struct p4_event_bind *bind; | ||
731 | unsigned int esel; | ||
732 | /* | ||
733 | * Clear bits we reserve to be managed by kernel itself | ||
734 | * and never allowed from a user space | ||
735 | */ | ||
736 | event->attr.config &= P4_CONFIG_MASK; | ||
480 | 737 | ||
481 | rc = p4_validate_raw_event(event); | 738 | rc = p4_validate_raw_event(event); |
482 | if (rc) | 739 | if (rc) |
483 | goto out; | 740 | goto out; |
484 | 741 | ||
485 | /* | 742 | /* |
486 | * We don't control raw events so it's up to the caller | ||
487 | * to pass sane values (and we don't count the thread number | ||
488 | * on HT machine but allow HT-compatible specifics to be | ||
489 | * passed on) | ||
490 | * | ||
491 | * Note that for RAW events we allow user to use P4_CCCR_RESERVED | 743 | * Note that for RAW events we allow user to use P4_CCCR_RESERVED |
492 | * bits since we keep additional info here (for cache events and etc) | 744 | * bits since we keep additional info here (for cache events and etc) |
493 | * | ||
494 | * XXX: HT wide things should check perf_paranoid_cpu() && | ||
495 | * CAP_SYS_ADMIN | ||
496 | */ | 745 | */ |
497 | event->hw.config |= event->attr.config & | 746 | event->hw.config |= event->attr.config; |
498 | (p4_config_pack_escr(P4_ESCR_MASK_HT) | | 747 | bind = p4_config_get_bind(event->attr.config); |
499 | p4_config_pack_cccr(P4_CCCR_MASK_HT | P4_CCCR_RESERVED)); | 748 | if (!bind) { |
500 | 749 | rc = -EINVAL; | |
501 | event->hw.config &= ~P4_CCCR_FORCE_OVF; | 750 | goto out; |
751 | } | ||
752 | esel = P4_OPCODE_ESEL(bind->opcode); | ||
753 | event->hw.config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel)); | ||
502 | } | 754 | } |
503 | 755 | ||
504 | rc = x86_setup_perfctr(event); | 756 | rc = x86_setup_perfctr(event); |
@@ -509,19 +761,27 @@ out: | |||
509 | 761 | ||
510 | static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) | 762 | static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) |
511 | { | 763 | { |
512 | int overflow = 0; | 764 | u64 v; |
513 | u32 low, high; | ||
514 | |||
515 | rdmsr(hwc->config_base + hwc->idx, low, high); | ||
516 | 765 | ||
517 | /* we need to check high bit for unflagged overflows */ | 766 | /* an official way for overflow indication */ |
518 | if ((low & P4_CCCR_OVF) || !(high & (1 << 31))) { | 767 | rdmsrl(hwc->config_base, v); |
519 | overflow = 1; | 768 | if (v & P4_CCCR_OVF) { |
520 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 769 | wrmsrl(hwc->config_base, v & ~P4_CCCR_OVF); |
521 | ((u64)low) & ~P4_CCCR_OVF); | 770 | return 1; |
522 | } | 771 | } |
523 | 772 | ||
524 | return overflow; | 773 | /* |
774 | * In some circumstances the overflow might issue an NMI but did | ||
775 | * not set P4_CCCR_OVF bit. Because a counter holds a negative value | ||
776 | * we simply check for high bit being set, if it's cleared it means | ||
777 | * the counter has reached zero value and continued counting before | ||
778 | * real NMI signal was received: | ||
779 | */ | ||
780 | rdmsrl(hwc->event_base, v); | ||
781 | if (!(v & ARCH_P4_UNFLAGGED_BIT)) | ||
782 | return 1; | ||
783 | |||
784 | return 0; | ||
525 | } | 785 | } |
526 | 786 | ||
527 | static void p4_pmu_disable_pebs(void) | 787 | static void p4_pmu_disable_pebs(void) |
@@ -531,13 +791,13 @@ static void p4_pmu_disable_pebs(void) | |||
531 | * | 791 | * |
532 | * It's still allowed that two threads setup same cache | 792 | * It's still allowed that two threads setup same cache |
533 | * events so we can't simply clear metrics until we knew | 793 | * events so we can't simply clear metrics until we knew |
534 | * noone is depending on us, so we need kind of counter | 794 | * no one is depending on us, so we need kind of counter |
535 | * for "ReplayEvent" users. | 795 | * for "ReplayEvent" users. |
536 | * | 796 | * |
537 | * What is more complex -- RAW events, if user (for some | 797 | * What is more complex -- RAW events, if user (for some |
538 | * reason) will pass some cache event metric with improper | 798 | * reason) will pass some cache event metric with improper |
539 | * event opcode -- it's fine from hardware point of view | 799 | * event opcode -- it's fine from hardware point of view |
540 | * but completely nonsence from "meaning" of such action. | 800 | * but completely nonsense from "meaning" of such action. |
541 | * | 801 | * |
542 | * So at moment let leave metrics turned on forever -- it's | 802 | * So at moment let leave metrics turned on forever -- it's |
543 | * ok for now but need to be revisited! | 803 | * ok for now but need to be revisited! |
@@ -556,7 +816,7 @@ static inline void p4_pmu_disable_event(struct perf_event *event) | |||
556 | * state we need to clear P4_CCCR_OVF, otherwise interrupt get | 816 | * state we need to clear P4_CCCR_OVF, otherwise interrupt get |
557 | * asserted again and again | 817 | * asserted again and again |
558 | */ | 818 | */ |
559 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 819 | (void)checking_wrmsrl(hwc->config_base, |
560 | (u64)(p4_config_unpack_cccr(hwc->config)) & | 820 | (u64)(p4_config_unpack_cccr(hwc->config)) & |
561 | ~P4_CCCR_ENABLE & ~P4_CCCR_OVF & ~P4_CCCR_RESERVED); | 821 | ~P4_CCCR_ENABLE & ~P4_CCCR_OVF & ~P4_CCCR_RESERVED); |
562 | } | 822 | } |
@@ -626,7 +886,7 @@ static void p4_pmu_enable_event(struct perf_event *event) | |||
626 | p4_pmu_enable_pebs(hwc->config); | 886 | p4_pmu_enable_pebs(hwc->config); |
627 | 887 | ||
628 | (void)checking_wrmsrl(escr_addr, escr_conf); | 888 | (void)checking_wrmsrl(escr_addr, escr_conf); |
629 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 889 | (void)checking_wrmsrl(hwc->config_base, |
630 | (cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE); | 890 | (cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE); |
631 | } | 891 | } |
632 | 892 | ||
@@ -652,8 +912,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) | |||
652 | int idx, handled = 0; | 912 | int idx, handled = 0; |
653 | u64 val; | 913 | u64 val; |
654 | 914 | ||
655 | data.addr = 0; | 915 | perf_sample_data_init(&data, 0); |
656 | data.raw = NULL; | ||
657 | 916 | ||
658 | cpuc = &__get_cpu_var(cpu_hw_events); | 917 | cpuc = &__get_cpu_var(cpu_hw_events); |
659 | 918 | ||
@@ -687,14 +946,23 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) | |||
687 | if (!x86_perf_event_set_period(event)) | 946 | if (!x86_perf_event_set_period(event)) |
688 | continue; | 947 | continue; |
689 | if (perf_event_overflow(event, 1, &data, regs)) | 948 | if (perf_event_overflow(event, 1, &data, regs)) |
690 | p4_pmu_disable_event(event); | 949 | x86_pmu_stop(event, 0); |
691 | } | 950 | } |
692 | 951 | ||
693 | if (handled) { | 952 | if (handled) |
694 | /* p4 quirk: unmask it again */ | ||
695 | apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED); | ||
696 | inc_irq_stat(apic_perf_irqs); | 953 | inc_irq_stat(apic_perf_irqs); |
697 | } | 954 | |
955 | /* | ||
956 | * When dealing with the unmasking of the LVTPC on P4 perf hw, it has | ||
957 | * been observed that the OVF bit flag has to be cleared first _before_ | ||
958 | * the LVTPC can be unmasked. | ||
959 | * | ||
960 | * The reason is the NMI line will continue to be asserted while the OVF | ||
961 | * bit is set. This causes a second NMI to generate if the LVTPC is | ||
962 | * unmasked before the OVF bit is cleared, leading to unknown NMI | ||
963 | * messages. | ||
964 | */ | ||
965 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
698 | 966 | ||
699 | return handled; | 967 | return handled; |
700 | } | 968 | } |
@@ -908,9 +1176,9 @@ static __initconst const struct x86_pmu p4_pmu = { | |||
908 | */ | 1176 | */ |
909 | .num_counters = ARCH_P4_MAX_CCCR, | 1177 | .num_counters = ARCH_P4_MAX_CCCR, |
910 | .apic = 1, | 1178 | .apic = 1, |
911 | .cntval_bits = 40, | 1179 | .cntval_bits = ARCH_P4_CNTRVAL_BITS, |
912 | .cntval_mask = (1ULL << 40) - 1, | 1180 | .cntval_mask = ARCH_P4_CNTRVAL_MASK, |
913 | .max_period = (1ULL << 39) - 1, | 1181 | .max_period = (1ULL << (ARCH_P4_CNTRVAL_BITS - 1)) - 1, |
914 | .hw_config = p4_hw_config, | 1182 | .hw_config = p4_hw_config, |
915 | .schedule_events = p4_pmu_schedule_events, | 1183 | .schedule_events = p4_pmu_schedule_events, |
916 | /* | 1184 | /* |
@@ -928,7 +1196,7 @@ static __init int p4_pmu_init(void) | |||
928 | { | 1196 | { |
929 | unsigned int low, high; | 1197 | unsigned int low, high; |
930 | 1198 | ||
931 | /* If we get stripped -- indexig fails */ | 1199 | /* If we get stripped -- indexing fails */ |
932 | BUILD_BUG_ON(ARCH_P4_MAX_CCCR > X86_PMC_MAX_GENERIC); | 1200 | BUILD_BUG_ON(ARCH_P4_MAX_CCCR > X86_PMC_MAX_GENERIC); |
933 | 1201 | ||
934 | rdmsr(MSR_IA32_MISC_ENABLE, low, high); | 1202 | rdmsr(MSR_IA32_MISC_ENABLE, low, high); |
diff --git a/arch/x86/kernel/cpu/perf_event_p6.c b/arch/x86/kernel/cpu/perf_event_p6.c index 34ba07be2cda..20c097e33860 100644 --- a/arch/x86/kernel/cpu/perf_event_p6.c +++ b/arch/x86/kernel/cpu/perf_event_p6.c | |||
@@ -68,7 +68,7 @@ p6_pmu_disable_event(struct perf_event *event) | |||
68 | if (cpuc->enabled) | 68 | if (cpuc->enabled) |
69 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; | 69 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; |
70 | 70 | ||
71 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, val); | 71 | (void)checking_wrmsrl(hwc->config_base, val); |
72 | } | 72 | } |
73 | 73 | ||
74 | static void p6_pmu_enable_event(struct perf_event *event) | 74 | static void p6_pmu_enable_event(struct perf_event *event) |
@@ -81,7 +81,7 @@ static void p6_pmu_enable_event(struct perf_event *event) | |||
81 | if (cpuc->enabled) | 81 | if (cpuc->enabled) |
82 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; | 82 | val |= ARCH_PERFMON_EVENTSEL_ENABLE; |
83 | 83 | ||
84 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, val); | 84 | (void)checking_wrmsrl(hwc->config_base, val); |
85 | } | 85 | } |
86 | 86 | ||
87 | static __initconst const struct x86_pmu p6_pmu = { | 87 | static __initconst const struct x86_pmu p6_pmu = { |
diff --git a/arch/x86/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c index fb329e9f8494..966512b2cacf 100644 --- a/arch/x86/kernel/cpu/perfctr-watchdog.c +++ b/arch/x86/kernel/cpu/perfctr-watchdog.c | |||
@@ -16,32 +16,12 @@ | |||
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/bitops.h> | 17 | #include <linux/bitops.h> |
18 | #include <linux/smp.h> | 18 | #include <linux/smp.h> |
19 | #include <linux/nmi.h> | 19 | #include <asm/nmi.h> |
20 | #include <linux/kprobes.h> | 20 | #include <linux/kprobes.h> |
21 | 21 | ||
22 | #include <asm/apic.h> | 22 | #include <asm/apic.h> |
23 | #include <asm/perf_event.h> | 23 | #include <asm/perf_event.h> |
24 | 24 | ||
25 | struct nmi_watchdog_ctlblk { | ||
26 | unsigned int cccr_msr; | ||
27 | unsigned int perfctr_msr; /* the MSR to reset in NMI handler */ | ||
28 | unsigned int evntsel_msr; /* the MSR to select the events to handle */ | ||
29 | }; | ||
30 | |||
31 | /* Interface defining a CPU specific perfctr watchdog */ | ||
32 | struct wd_ops { | ||
33 | int (*reserve)(void); | ||
34 | void (*unreserve)(void); | ||
35 | int (*setup)(unsigned nmi_hz); | ||
36 | void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz); | ||
37 | void (*stop)(void); | ||
38 | unsigned perfctr; | ||
39 | unsigned evntsel; | ||
40 | u64 checkbit; | ||
41 | }; | ||
42 | |||
43 | static const struct wd_ops *wd_ops; | ||
44 | |||
45 | /* | 25 | /* |
46 | * this number is calculated from Intel's MSR_P4_CRU_ESCR5 register and it's | 26 | * this number is calculated from Intel's MSR_P4_CRU_ESCR5 register and it's |
47 | * offset from MSR_P4_BSU_ESCR0. | 27 | * offset from MSR_P4_BSU_ESCR0. |
@@ -60,14 +40,14 @@ static const struct wd_ops *wd_ops; | |||
60 | static DECLARE_BITMAP(perfctr_nmi_owner, NMI_MAX_COUNTER_BITS); | 40 | static DECLARE_BITMAP(perfctr_nmi_owner, NMI_MAX_COUNTER_BITS); |
61 | static DECLARE_BITMAP(evntsel_nmi_owner, NMI_MAX_COUNTER_BITS); | 41 | static DECLARE_BITMAP(evntsel_nmi_owner, NMI_MAX_COUNTER_BITS); |
62 | 42 | ||
63 | static DEFINE_PER_CPU(struct nmi_watchdog_ctlblk, nmi_watchdog_ctlblk); | ||
64 | |||
65 | /* converts an msr to an appropriate reservation bit */ | 43 | /* converts an msr to an appropriate reservation bit */ |
66 | static inline unsigned int nmi_perfctr_msr_to_bit(unsigned int msr) | 44 | static inline unsigned int nmi_perfctr_msr_to_bit(unsigned int msr) |
67 | { | 45 | { |
68 | /* returns the bit offset of the performance counter register */ | 46 | /* returns the bit offset of the performance counter register */ |
69 | switch (boot_cpu_data.x86_vendor) { | 47 | switch (boot_cpu_data.x86_vendor) { |
70 | case X86_VENDOR_AMD: | 48 | case X86_VENDOR_AMD: |
49 | if (msr >= MSR_F15H_PERF_CTR) | ||
50 | return (msr - MSR_F15H_PERF_CTR) >> 1; | ||
71 | return msr - MSR_K7_PERFCTR0; | 51 | return msr - MSR_K7_PERFCTR0; |
72 | case X86_VENDOR_INTEL: | 52 | case X86_VENDOR_INTEL: |
73 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) | 53 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) |
@@ -92,6 +72,8 @@ static inline unsigned int nmi_evntsel_msr_to_bit(unsigned int msr) | |||
92 | /* returns the bit offset of the event selection register */ | 72 | /* returns the bit offset of the event selection register */ |
93 | switch (boot_cpu_data.x86_vendor) { | 73 | switch (boot_cpu_data.x86_vendor) { |
94 | case X86_VENDOR_AMD: | 74 | case X86_VENDOR_AMD: |
75 | if (msr >= MSR_F15H_PERF_CTL) | ||
76 | return (msr - MSR_F15H_PERF_CTL) >> 1; | ||
95 | return msr - MSR_K7_EVNTSEL0; | 77 | return msr - MSR_K7_EVNTSEL0; |
96 | case X86_VENDOR_INTEL: | 78 | case X86_VENDOR_INTEL: |
97 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) | 79 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) |
@@ -172,624 +154,3 @@ void release_evntsel_nmi(unsigned int msr) | |||
172 | clear_bit(counter, evntsel_nmi_owner); | 154 | clear_bit(counter, evntsel_nmi_owner); |
173 | } | 155 | } |
174 | EXPORT_SYMBOL(release_evntsel_nmi); | 156 | EXPORT_SYMBOL(release_evntsel_nmi); |
175 | |||
176 | void disable_lapic_nmi_watchdog(void) | ||
177 | { | ||
178 | BUG_ON(nmi_watchdog != NMI_LOCAL_APIC); | ||
179 | |||
180 | if (atomic_read(&nmi_active) <= 0) | ||
181 | return; | ||
182 | |||
183 | on_each_cpu(stop_apic_nmi_watchdog, NULL, 1); | ||
184 | |||
185 | if (wd_ops) | ||
186 | wd_ops->unreserve(); | ||
187 | |||
188 | BUG_ON(atomic_read(&nmi_active) != 0); | ||
189 | } | ||
190 | |||
191 | void enable_lapic_nmi_watchdog(void) | ||
192 | { | ||
193 | BUG_ON(nmi_watchdog != NMI_LOCAL_APIC); | ||
194 | |||
195 | /* are we already enabled */ | ||
196 | if (atomic_read(&nmi_active) != 0) | ||
197 | return; | ||
198 | |||
199 | /* are we lapic aware */ | ||
200 | if (!wd_ops) | ||
201 | return; | ||
202 | if (!wd_ops->reserve()) { | ||
203 | printk(KERN_ERR "NMI watchdog: cannot reserve perfctrs\n"); | ||
204 | return; | ||
205 | } | ||
206 | |||
207 | on_each_cpu(setup_apic_nmi_watchdog, NULL, 1); | ||
208 | touch_nmi_watchdog(); | ||
209 | } | ||
210 | |||
211 | /* | ||
212 | * Activate the NMI watchdog via the local APIC. | ||
213 | */ | ||
214 | |||
215 | static unsigned int adjust_for_32bit_ctr(unsigned int hz) | ||
216 | { | ||
217 | u64 counter_val; | ||
218 | unsigned int retval = hz; | ||
219 | |||
220 | /* | ||
221 | * On Intel CPUs with P6/ARCH_PERFMON only 32 bits in the counter | ||
222 | * are writable, with higher bits sign extending from bit 31. | ||
223 | * So, we can only program the counter with 31 bit values and | ||
224 | * 32nd bit should be 1, for 33.. to be 1. | ||
225 | * Find the appropriate nmi_hz | ||
226 | */ | ||
227 | counter_val = (u64)cpu_khz * 1000; | ||
228 | do_div(counter_val, retval); | ||
229 | if (counter_val > 0x7fffffffULL) { | ||
230 | u64 count = (u64)cpu_khz * 1000; | ||
231 | do_div(count, 0x7fffffffUL); | ||
232 | retval = count + 1; | ||
233 | } | ||
234 | return retval; | ||
235 | } | ||
236 | |||
237 | static void write_watchdog_counter(unsigned int perfctr_msr, | ||
238 | const char *descr, unsigned nmi_hz) | ||
239 | { | ||
240 | u64 count = (u64)cpu_khz * 1000; | ||
241 | |||
242 | do_div(count, nmi_hz); | ||
243 | if (descr) | ||
244 | pr_debug("setting %s to -0x%08Lx\n", descr, count); | ||
245 | wrmsrl(perfctr_msr, 0 - count); | ||
246 | } | ||
247 | |||
248 | static void write_watchdog_counter32(unsigned int perfctr_msr, | ||
249 | const char *descr, unsigned nmi_hz) | ||
250 | { | ||
251 | u64 count = (u64)cpu_khz * 1000; | ||
252 | |||
253 | do_div(count, nmi_hz); | ||
254 | if (descr) | ||
255 | pr_debug("setting %s to -0x%08Lx\n", descr, count); | ||
256 | wrmsr(perfctr_msr, (u32)(-count), 0); | ||
257 | } | ||
258 | |||
259 | /* | ||
260 | * AMD K7/K8/Family10h/Family11h support. | ||
261 | * AMD keeps this interface nicely stable so there is not much variety | ||
262 | */ | ||
263 | #define K7_EVNTSEL_ENABLE (1 << 22) | ||
264 | #define K7_EVNTSEL_INT (1 << 20) | ||
265 | #define K7_EVNTSEL_OS (1 << 17) | ||
266 | #define K7_EVNTSEL_USR (1 << 16) | ||
267 | #define K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING 0x76 | ||
268 | #define K7_NMI_EVENT K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING | ||
269 | |||
270 | static int setup_k7_watchdog(unsigned nmi_hz) | ||
271 | { | ||
272 | unsigned int perfctr_msr, evntsel_msr; | ||
273 | unsigned int evntsel; | ||
274 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
275 | |||
276 | perfctr_msr = wd_ops->perfctr; | ||
277 | evntsel_msr = wd_ops->evntsel; | ||
278 | |||
279 | wrmsrl(perfctr_msr, 0UL); | ||
280 | |||
281 | evntsel = K7_EVNTSEL_INT | ||
282 | | K7_EVNTSEL_OS | ||
283 | | K7_EVNTSEL_USR | ||
284 | | K7_NMI_EVENT; | ||
285 | |||
286 | /* setup the timer */ | ||
287 | wrmsr(evntsel_msr, evntsel, 0); | ||
288 | write_watchdog_counter(perfctr_msr, "K7_PERFCTR0", nmi_hz); | ||
289 | |||
290 | /* initialize the wd struct before enabling */ | ||
291 | wd->perfctr_msr = perfctr_msr; | ||
292 | wd->evntsel_msr = evntsel_msr; | ||
293 | wd->cccr_msr = 0; /* unused */ | ||
294 | |||
295 | /* ok, everything is initialized, announce that we're set */ | ||
296 | cpu_nmi_set_wd_enabled(); | ||
297 | |||
298 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
299 | evntsel |= K7_EVNTSEL_ENABLE; | ||
300 | wrmsr(evntsel_msr, evntsel, 0); | ||
301 | |||
302 | return 1; | ||
303 | } | ||
304 | |||
305 | static void single_msr_stop_watchdog(void) | ||
306 | { | ||
307 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
308 | |||
309 | wrmsr(wd->evntsel_msr, 0, 0); | ||
310 | } | ||
311 | |||
312 | static int single_msr_reserve(void) | ||
313 | { | ||
314 | if (!reserve_perfctr_nmi(wd_ops->perfctr)) | ||
315 | return 0; | ||
316 | |||
317 | if (!reserve_evntsel_nmi(wd_ops->evntsel)) { | ||
318 | release_perfctr_nmi(wd_ops->perfctr); | ||
319 | return 0; | ||
320 | } | ||
321 | return 1; | ||
322 | } | ||
323 | |||
324 | static void single_msr_unreserve(void) | ||
325 | { | ||
326 | release_evntsel_nmi(wd_ops->evntsel); | ||
327 | release_perfctr_nmi(wd_ops->perfctr); | ||
328 | } | ||
329 | |||
330 | static void __kprobes | ||
331 | single_msr_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz) | ||
332 | { | ||
333 | /* start the cycle over again */ | ||
334 | write_watchdog_counter(wd->perfctr_msr, NULL, nmi_hz); | ||
335 | } | ||
336 | |||
337 | static const struct wd_ops k7_wd_ops = { | ||
338 | .reserve = single_msr_reserve, | ||
339 | .unreserve = single_msr_unreserve, | ||
340 | .setup = setup_k7_watchdog, | ||
341 | .rearm = single_msr_rearm, | ||
342 | .stop = single_msr_stop_watchdog, | ||
343 | .perfctr = MSR_K7_PERFCTR0, | ||
344 | .evntsel = MSR_K7_EVNTSEL0, | ||
345 | .checkbit = 1ULL << 47, | ||
346 | }; | ||
347 | |||
348 | /* | ||
349 | * Intel Model 6 (PPro+,P2,P3,P-M,Core1) | ||
350 | */ | ||
351 | #define P6_EVNTSEL0_ENABLE (1 << 22) | ||
352 | #define P6_EVNTSEL_INT (1 << 20) | ||
353 | #define P6_EVNTSEL_OS (1 << 17) | ||
354 | #define P6_EVNTSEL_USR (1 << 16) | ||
355 | #define P6_EVENT_CPU_CLOCKS_NOT_HALTED 0x79 | ||
356 | #define P6_NMI_EVENT P6_EVENT_CPU_CLOCKS_NOT_HALTED | ||
357 | |||
358 | static int setup_p6_watchdog(unsigned nmi_hz) | ||
359 | { | ||
360 | unsigned int perfctr_msr, evntsel_msr; | ||
361 | unsigned int evntsel; | ||
362 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
363 | |||
364 | perfctr_msr = wd_ops->perfctr; | ||
365 | evntsel_msr = wd_ops->evntsel; | ||
366 | |||
367 | /* KVM doesn't implement this MSR */ | ||
368 | if (wrmsr_safe(perfctr_msr, 0, 0) < 0) | ||
369 | return 0; | ||
370 | |||
371 | evntsel = P6_EVNTSEL_INT | ||
372 | | P6_EVNTSEL_OS | ||
373 | | P6_EVNTSEL_USR | ||
374 | | P6_NMI_EVENT; | ||
375 | |||
376 | /* setup the timer */ | ||
377 | wrmsr(evntsel_msr, evntsel, 0); | ||
378 | nmi_hz = adjust_for_32bit_ctr(nmi_hz); | ||
379 | write_watchdog_counter32(perfctr_msr, "P6_PERFCTR0", nmi_hz); | ||
380 | |||
381 | /* initialize the wd struct before enabling */ | ||
382 | wd->perfctr_msr = perfctr_msr; | ||
383 | wd->evntsel_msr = evntsel_msr; | ||
384 | wd->cccr_msr = 0; /* unused */ | ||
385 | |||
386 | /* ok, everything is initialized, announce that we're set */ | ||
387 | cpu_nmi_set_wd_enabled(); | ||
388 | |||
389 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
390 | evntsel |= P6_EVNTSEL0_ENABLE; | ||
391 | wrmsr(evntsel_msr, evntsel, 0); | ||
392 | |||
393 | return 1; | ||
394 | } | ||
395 | |||
396 | static void __kprobes p6_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz) | ||
397 | { | ||
398 | /* | ||
399 | * P6 based Pentium M need to re-unmask | ||
400 | * the apic vector but it doesn't hurt | ||
401 | * other P6 variant. | ||
402 | * ArchPerfom/Core Duo also needs this | ||
403 | */ | ||
404 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
405 | |||
406 | /* P6/ARCH_PERFMON has 32 bit counter write */ | ||
407 | write_watchdog_counter32(wd->perfctr_msr, NULL, nmi_hz); | ||
408 | } | ||
409 | |||
410 | static const struct wd_ops p6_wd_ops = { | ||
411 | .reserve = single_msr_reserve, | ||
412 | .unreserve = single_msr_unreserve, | ||
413 | .setup = setup_p6_watchdog, | ||
414 | .rearm = p6_rearm, | ||
415 | .stop = single_msr_stop_watchdog, | ||
416 | .perfctr = MSR_P6_PERFCTR0, | ||
417 | .evntsel = MSR_P6_EVNTSEL0, | ||
418 | .checkbit = 1ULL << 39, | ||
419 | }; | ||
420 | |||
421 | /* | ||
422 | * Intel P4 performance counters. | ||
423 | * By far the most complicated of all. | ||
424 | */ | ||
425 | #define MSR_P4_MISC_ENABLE_PERF_AVAIL (1 << 7) | ||
426 | #define P4_ESCR_EVENT_SELECT(N) ((N) << 25) | ||
427 | #define P4_ESCR_OS (1 << 3) | ||
428 | #define P4_ESCR_USR (1 << 2) | ||
429 | #define P4_CCCR_OVF_PMI0 (1 << 26) | ||
430 | #define P4_CCCR_OVF_PMI1 (1 << 27) | ||
431 | #define P4_CCCR_THRESHOLD(N) ((N) << 20) | ||
432 | #define P4_CCCR_COMPLEMENT (1 << 19) | ||
433 | #define P4_CCCR_COMPARE (1 << 18) | ||
434 | #define P4_CCCR_REQUIRED (3 << 16) | ||
435 | #define P4_CCCR_ESCR_SELECT(N) ((N) << 13) | ||
436 | #define P4_CCCR_ENABLE (1 << 12) | ||
437 | #define P4_CCCR_OVF (1 << 31) | ||
438 | |||
439 | #define P4_CONTROLS 18 | ||
440 | static unsigned int p4_controls[18] = { | ||
441 | MSR_P4_BPU_CCCR0, | ||
442 | MSR_P4_BPU_CCCR1, | ||
443 | MSR_P4_BPU_CCCR2, | ||
444 | MSR_P4_BPU_CCCR3, | ||
445 | MSR_P4_MS_CCCR0, | ||
446 | MSR_P4_MS_CCCR1, | ||
447 | MSR_P4_MS_CCCR2, | ||
448 | MSR_P4_MS_CCCR3, | ||
449 | MSR_P4_FLAME_CCCR0, | ||
450 | MSR_P4_FLAME_CCCR1, | ||
451 | MSR_P4_FLAME_CCCR2, | ||
452 | MSR_P4_FLAME_CCCR3, | ||
453 | MSR_P4_IQ_CCCR0, | ||
454 | MSR_P4_IQ_CCCR1, | ||
455 | MSR_P4_IQ_CCCR2, | ||
456 | MSR_P4_IQ_CCCR3, | ||
457 | MSR_P4_IQ_CCCR4, | ||
458 | MSR_P4_IQ_CCCR5, | ||
459 | }; | ||
460 | /* | ||
461 | * Set up IQ_COUNTER0 to behave like a clock, by having IQ_CCCR0 filter | ||
462 | * CRU_ESCR0 (with any non-null event selector) through a complemented | ||
463 | * max threshold. [IA32-Vol3, Section 14.9.9] | ||
464 | */ | ||
465 | static int setup_p4_watchdog(unsigned nmi_hz) | ||
466 | { | ||
467 | unsigned int perfctr_msr, evntsel_msr, cccr_msr; | ||
468 | unsigned int evntsel, cccr_val; | ||
469 | unsigned int misc_enable, dummy; | ||
470 | unsigned int ht_num; | ||
471 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
472 | |||
473 | rdmsr(MSR_IA32_MISC_ENABLE, misc_enable, dummy); | ||
474 | if (!(misc_enable & MSR_P4_MISC_ENABLE_PERF_AVAIL)) | ||
475 | return 0; | ||
476 | |||
477 | #ifdef CONFIG_SMP | ||
478 | /* detect which hyperthread we are on */ | ||
479 | if (smp_num_siblings == 2) { | ||
480 | unsigned int ebx, apicid; | ||
481 | |||
482 | ebx = cpuid_ebx(1); | ||
483 | apicid = (ebx >> 24) & 0xff; | ||
484 | ht_num = apicid & 1; | ||
485 | } else | ||
486 | #endif | ||
487 | ht_num = 0; | ||
488 | |||
489 | /* | ||
490 | * performance counters are shared resources | ||
491 | * assign each hyperthread its own set | ||
492 | * (re-use the ESCR0 register, seems safe | ||
493 | * and keeps the cccr_val the same) | ||
494 | */ | ||
495 | if (!ht_num) { | ||
496 | /* logical cpu 0 */ | ||
497 | perfctr_msr = MSR_P4_IQ_PERFCTR0; | ||
498 | evntsel_msr = MSR_P4_CRU_ESCR0; | ||
499 | cccr_msr = MSR_P4_IQ_CCCR0; | ||
500 | cccr_val = P4_CCCR_OVF_PMI0 | P4_CCCR_ESCR_SELECT(4); | ||
501 | |||
502 | /* | ||
503 | * If we're on the kdump kernel or other situation, we may | ||
504 | * still have other performance counter registers set to | ||
505 | * interrupt and they'll keep interrupting forever because | ||
506 | * of the P4_CCCR_OVF quirk. So we need to ACK all the | ||
507 | * pending interrupts and disable all the registers here, | ||
508 | * before reenabling the NMI delivery. Refer to p4_rearm() | ||
509 | * about the P4_CCCR_OVF quirk. | ||
510 | */ | ||
511 | if (reset_devices) { | ||
512 | unsigned int low, high; | ||
513 | int i; | ||
514 | |||
515 | for (i = 0; i < P4_CONTROLS; i++) { | ||
516 | rdmsr(p4_controls[i], low, high); | ||
517 | low &= ~(P4_CCCR_ENABLE | P4_CCCR_OVF); | ||
518 | wrmsr(p4_controls[i], low, high); | ||
519 | } | ||
520 | } | ||
521 | } else { | ||
522 | /* logical cpu 1 */ | ||
523 | perfctr_msr = MSR_P4_IQ_PERFCTR1; | ||
524 | evntsel_msr = MSR_P4_CRU_ESCR0; | ||
525 | cccr_msr = MSR_P4_IQ_CCCR1; | ||
526 | |||
527 | /* Pentium 4 D processors don't support P4_CCCR_OVF_PMI1 */ | ||
528 | if (boot_cpu_data.x86_model == 4 && boot_cpu_data.x86_mask == 4) | ||
529 | cccr_val = P4_CCCR_OVF_PMI0; | ||
530 | else | ||
531 | cccr_val = P4_CCCR_OVF_PMI1; | ||
532 | cccr_val |= P4_CCCR_ESCR_SELECT(4); | ||
533 | } | ||
534 | |||
535 | evntsel = P4_ESCR_EVENT_SELECT(0x3F) | ||
536 | | P4_ESCR_OS | ||
537 | | P4_ESCR_USR; | ||
538 | |||
539 | cccr_val |= P4_CCCR_THRESHOLD(15) | ||
540 | | P4_CCCR_COMPLEMENT | ||
541 | | P4_CCCR_COMPARE | ||
542 | | P4_CCCR_REQUIRED; | ||
543 | |||
544 | wrmsr(evntsel_msr, evntsel, 0); | ||
545 | wrmsr(cccr_msr, cccr_val, 0); | ||
546 | write_watchdog_counter(perfctr_msr, "P4_IQ_COUNTER0", nmi_hz); | ||
547 | |||
548 | wd->perfctr_msr = perfctr_msr; | ||
549 | wd->evntsel_msr = evntsel_msr; | ||
550 | wd->cccr_msr = cccr_msr; | ||
551 | |||
552 | /* ok, everything is initialized, announce that we're set */ | ||
553 | cpu_nmi_set_wd_enabled(); | ||
554 | |||
555 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
556 | cccr_val |= P4_CCCR_ENABLE; | ||
557 | wrmsr(cccr_msr, cccr_val, 0); | ||
558 | return 1; | ||
559 | } | ||
560 | |||
561 | static void stop_p4_watchdog(void) | ||
562 | { | ||
563 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
564 | wrmsr(wd->cccr_msr, 0, 0); | ||
565 | wrmsr(wd->evntsel_msr, 0, 0); | ||
566 | } | ||
567 | |||
568 | static int p4_reserve(void) | ||
569 | { | ||
570 | if (!reserve_perfctr_nmi(MSR_P4_IQ_PERFCTR0)) | ||
571 | return 0; | ||
572 | #ifdef CONFIG_SMP | ||
573 | if (smp_num_siblings > 1 && !reserve_perfctr_nmi(MSR_P4_IQ_PERFCTR1)) | ||
574 | goto fail1; | ||
575 | #endif | ||
576 | if (!reserve_evntsel_nmi(MSR_P4_CRU_ESCR0)) | ||
577 | goto fail2; | ||
578 | /* RED-PEN why is ESCR1 not reserved here? */ | ||
579 | return 1; | ||
580 | fail2: | ||
581 | #ifdef CONFIG_SMP | ||
582 | if (smp_num_siblings > 1) | ||
583 | release_perfctr_nmi(MSR_P4_IQ_PERFCTR1); | ||
584 | fail1: | ||
585 | #endif | ||
586 | release_perfctr_nmi(MSR_P4_IQ_PERFCTR0); | ||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | static void p4_unreserve(void) | ||
591 | { | ||
592 | #ifdef CONFIG_SMP | ||
593 | if (smp_num_siblings > 1) | ||
594 | release_perfctr_nmi(MSR_P4_IQ_PERFCTR1); | ||
595 | #endif | ||
596 | release_evntsel_nmi(MSR_P4_CRU_ESCR0); | ||
597 | release_perfctr_nmi(MSR_P4_IQ_PERFCTR0); | ||
598 | } | ||
599 | |||
600 | static void __kprobes p4_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz) | ||
601 | { | ||
602 | unsigned dummy; | ||
603 | /* | ||
604 | * P4 quirks: | ||
605 | * - An overflown perfctr will assert its interrupt | ||
606 | * until the OVF flag in its CCCR is cleared. | ||
607 | * - LVTPC is masked on interrupt and must be | ||
608 | * unmasked by the LVTPC handler. | ||
609 | */ | ||
610 | rdmsrl(wd->cccr_msr, dummy); | ||
611 | dummy &= ~P4_CCCR_OVF; | ||
612 | wrmsrl(wd->cccr_msr, dummy); | ||
613 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
614 | /* start the cycle over again */ | ||
615 | write_watchdog_counter(wd->perfctr_msr, NULL, nmi_hz); | ||
616 | } | ||
617 | |||
618 | static const struct wd_ops p4_wd_ops = { | ||
619 | .reserve = p4_reserve, | ||
620 | .unreserve = p4_unreserve, | ||
621 | .setup = setup_p4_watchdog, | ||
622 | .rearm = p4_rearm, | ||
623 | .stop = stop_p4_watchdog, | ||
624 | /* RED-PEN this is wrong for the other sibling */ | ||
625 | .perfctr = MSR_P4_BPU_PERFCTR0, | ||
626 | .evntsel = MSR_P4_BSU_ESCR0, | ||
627 | .checkbit = 1ULL << 39, | ||
628 | }; | ||
629 | |||
630 | /* | ||
631 | * Watchdog using the Intel architected PerfMon. | ||
632 | * Used for Core2 and hopefully all future Intel CPUs. | ||
633 | */ | ||
634 | #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL | ||
635 | #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK | ||
636 | |||
637 | static struct wd_ops intel_arch_wd_ops; | ||
638 | |||
639 | static int setup_intel_arch_watchdog(unsigned nmi_hz) | ||
640 | { | ||
641 | unsigned int ebx; | ||
642 | union cpuid10_eax eax; | ||
643 | unsigned int unused; | ||
644 | unsigned int perfctr_msr, evntsel_msr; | ||
645 | unsigned int evntsel; | ||
646 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
647 | |||
648 | /* | ||
649 | * Check whether the Architectural PerfMon supports | ||
650 | * Unhalted Core Cycles Event or not. | ||
651 | * NOTE: Corresponding bit = 0 in ebx indicates event present. | ||
652 | */ | ||
653 | cpuid(10, &(eax.full), &ebx, &unused, &unused); | ||
654 | if ((eax.split.mask_length < | ||
655 | (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) || | ||
656 | (ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT)) | ||
657 | return 0; | ||
658 | |||
659 | perfctr_msr = wd_ops->perfctr; | ||
660 | evntsel_msr = wd_ops->evntsel; | ||
661 | |||
662 | wrmsrl(perfctr_msr, 0UL); | ||
663 | |||
664 | evntsel = ARCH_PERFMON_EVENTSEL_INT | ||
665 | | ARCH_PERFMON_EVENTSEL_OS | ||
666 | | ARCH_PERFMON_EVENTSEL_USR | ||
667 | | ARCH_PERFMON_NMI_EVENT_SEL | ||
668 | | ARCH_PERFMON_NMI_EVENT_UMASK; | ||
669 | |||
670 | /* setup the timer */ | ||
671 | wrmsr(evntsel_msr, evntsel, 0); | ||
672 | nmi_hz = adjust_for_32bit_ctr(nmi_hz); | ||
673 | write_watchdog_counter32(perfctr_msr, "INTEL_ARCH_PERFCTR0", nmi_hz); | ||
674 | |||
675 | wd->perfctr_msr = perfctr_msr; | ||
676 | wd->evntsel_msr = evntsel_msr; | ||
677 | wd->cccr_msr = 0; /* unused */ | ||
678 | |||
679 | /* ok, everything is initialized, announce that we're set */ | ||
680 | cpu_nmi_set_wd_enabled(); | ||
681 | |||
682 | apic_write(APIC_LVTPC, APIC_DM_NMI); | ||
683 | evntsel |= ARCH_PERFMON_EVENTSEL_ENABLE; | ||
684 | wrmsr(evntsel_msr, evntsel, 0); | ||
685 | intel_arch_wd_ops.checkbit = 1ULL << (eax.split.bit_width - 1); | ||
686 | return 1; | ||
687 | } | ||
688 | |||
689 | static struct wd_ops intel_arch_wd_ops __read_mostly = { | ||
690 | .reserve = single_msr_reserve, | ||
691 | .unreserve = single_msr_unreserve, | ||
692 | .setup = setup_intel_arch_watchdog, | ||
693 | .rearm = p6_rearm, | ||
694 | .stop = single_msr_stop_watchdog, | ||
695 | .perfctr = MSR_ARCH_PERFMON_PERFCTR1, | ||
696 | .evntsel = MSR_ARCH_PERFMON_EVENTSEL1, | ||
697 | }; | ||
698 | |||
699 | static void probe_nmi_watchdog(void) | ||
700 | { | ||
701 | switch (boot_cpu_data.x86_vendor) { | ||
702 | case X86_VENDOR_AMD: | ||
703 | if (boot_cpu_data.x86 != 6 && boot_cpu_data.x86 != 15 && | ||
704 | boot_cpu_data.x86 != 16 && boot_cpu_data.x86 != 17) | ||
705 | return; | ||
706 | wd_ops = &k7_wd_ops; | ||
707 | break; | ||
708 | case X86_VENDOR_INTEL: | ||
709 | /* Work around where perfctr1 doesn't have a working enable | ||
710 | * bit as described in the following errata: | ||
711 | * AE49 Core Duo and Intel Core Solo 65 nm | ||
712 | * AN49 Intel Pentium Dual-Core | ||
713 | * AF49 Dual-Core Intel Xeon Processor LV | ||
714 | */ | ||
715 | if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 14) || | ||
716 | ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 15 && | ||
717 | boot_cpu_data.x86_mask == 4))) { | ||
718 | intel_arch_wd_ops.perfctr = MSR_ARCH_PERFMON_PERFCTR0; | ||
719 | intel_arch_wd_ops.evntsel = MSR_ARCH_PERFMON_EVENTSEL0; | ||
720 | } | ||
721 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { | ||
722 | wd_ops = &intel_arch_wd_ops; | ||
723 | break; | ||
724 | } | ||
725 | switch (boot_cpu_data.x86) { | ||
726 | case 6: | ||
727 | if (boot_cpu_data.x86_model > 13) | ||
728 | return; | ||
729 | |||
730 | wd_ops = &p6_wd_ops; | ||
731 | break; | ||
732 | case 15: | ||
733 | wd_ops = &p4_wd_ops; | ||
734 | break; | ||
735 | default: | ||
736 | return; | ||
737 | } | ||
738 | break; | ||
739 | } | ||
740 | } | ||
741 | |||
742 | /* Interface to nmi.c */ | ||
743 | |||
744 | int lapic_watchdog_init(unsigned nmi_hz) | ||
745 | { | ||
746 | if (!wd_ops) { | ||
747 | probe_nmi_watchdog(); | ||
748 | if (!wd_ops) { | ||
749 | printk(KERN_INFO "NMI watchdog: CPU not supported\n"); | ||
750 | return -1; | ||
751 | } | ||
752 | |||
753 | if (!wd_ops->reserve()) { | ||
754 | printk(KERN_ERR | ||
755 | "NMI watchdog: cannot reserve perfctrs\n"); | ||
756 | return -1; | ||
757 | } | ||
758 | } | ||
759 | |||
760 | if (!(wd_ops->setup(nmi_hz))) { | ||
761 | printk(KERN_ERR "Cannot setup NMI watchdog on CPU %d\n", | ||
762 | raw_smp_processor_id()); | ||
763 | return -1; | ||
764 | } | ||
765 | |||
766 | return 0; | ||
767 | } | ||
768 | |||
769 | void lapic_watchdog_stop(void) | ||
770 | { | ||
771 | if (wd_ops) | ||
772 | wd_ops->stop(); | ||
773 | } | ||
774 | |||
775 | unsigned lapic_adjust_nmi_hz(unsigned hz) | ||
776 | { | ||
777 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
778 | if (wd->perfctr_msr == MSR_P6_PERFCTR0 || | ||
779 | wd->perfctr_msr == MSR_ARCH_PERFMON_PERFCTR1) | ||
780 | hz = adjust_for_32bit_ctr(hz); | ||
781 | return hz; | ||
782 | } | ||
783 | |||
784 | int __kprobes lapic_wd_event(unsigned nmi_hz) | ||
785 | { | ||
786 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); | ||
787 | u64 ctr; | ||
788 | |||
789 | rdmsrl(wd->perfctr_msr, ctr); | ||
790 | if (ctr & wd_ops->checkbit) /* perfctr still running? */ | ||
791 | return 0; | ||
792 | |||
793 | wd_ops->rearm(wd, nmi_hz); | ||
794 | return 1; | ||
795 | } | ||
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index d49079515122..c7f64e6f537a 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c | |||
@@ -44,6 +44,12 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c) | |||
44 | { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a, 0 }, | 44 | { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a, 0 }, |
45 | { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a, 0 }, | 45 | { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a, 0 }, |
46 | { X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a, 0 }, | 46 | { X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a, 0 }, |
47 | { X86_FEATURE_TSCRATEMSR, CR_EDX, 4, 0x8000000a, 0 }, | ||
48 | { X86_FEATURE_VMCBCLEAN, CR_EDX, 5, 0x8000000a, 0 }, | ||
49 | { X86_FEATURE_FLUSHBYASID, CR_EDX, 6, 0x8000000a, 0 }, | ||
50 | { X86_FEATURE_DECODEASSISTS, CR_EDX, 7, 0x8000000a, 0 }, | ||
51 | { X86_FEATURE_PAUSEFILTER, CR_EDX,10, 0x8000000a, 0 }, | ||
52 | { X86_FEATURE_PFTHRESHOLD, CR_EDX,12, 0x8000000a, 0 }, | ||
47 | { 0, 0, 0, 0, 0 } | 53 | { 0, 0, 0, 0, 0 } |
48 | }; | 54 | }; |
49 | 55 | ||
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 227b0448960d..d22d0c4edcfd 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c | |||
@@ -86,7 +86,7 @@ static void __init vmware_platform_setup(void) | |||
86 | } | 86 | } |
87 | 87 | ||
88 | /* | 88 | /* |
89 | * While checking the dmi string infomation, just checking the product | 89 | * While checking the dmi string information, just checking the product |
90 | * serial key should be enough, as this will always have a VMware | 90 | * serial key should be enough, as this will always have a VMware |
91 | * specific string when running under VMware hypervisor. | 91 | * specific string when running under VMware hypervisor. |
92 | */ | 92 | */ |