aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2006-06-15 21:39:25 -0400
committerLen Brown <len.brown@intel.com>2006-06-15 21:39:25 -0400
commitd42510a0f58c2583c37c8e9b7548e3a68545863a (patch)
tree9d44b95405b9f0083e911a66cc5512860293f95a /arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
parent8f2ddb37e564a9616c05fa0d5652e0049072a730 (diff)
parent193de0c79da580eb33a66113b62e2378fc1fb629 (diff)
Pull bugzilla-5737 into release branch
Conflicts: arch/x86_64/kernel/acpi/processor.c
Diffstat (limited to 'arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c')
-rw-r--r--arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c250
1 files changed, 184 insertions, 66 deletions
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
index b0ff9075708c..4535ca0fe0cf 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
+++ b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -351,7 +351,36 @@ static unsigned int get_cur_freq(unsigned int cpu)
351 351
352#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI 352#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
353 353
354static struct acpi_processor_performance p; 354static struct acpi_processor_performance *acpi_perf_data[NR_CPUS];
355
356/*
357 * centrino_cpu_early_init_acpi - Do the preregistering with ACPI P-States
358 * library
359 *
360 * Before doing the actual init, we need to do _PSD related setup whenever
361 * supported by the BIOS. These are handled by this early_init routine.
362 */
363static int centrino_cpu_early_init_acpi(void)
364{
365 unsigned int i, j;
366 struct acpi_processor_performance *data;
367
368 for_each_cpu(i) {
369 data = kzalloc(sizeof(struct acpi_processor_performance),
370 GFP_KERNEL);
371 if (!data) {
372 for_each_cpu(j) {
373 kfree(acpi_perf_data[j]);
374 acpi_perf_data[j] = NULL;
375 }
376 return (-ENOMEM);
377 }
378 acpi_perf_data[i] = data;
379 }
380
381 acpi_processor_preregister_performance(acpi_perf_data);
382 return 0;
383}
355 384
356/* 385/*
357 * centrino_cpu_init_acpi - register with ACPI P-States library 386 * centrino_cpu_init_acpi - register with ACPI P-States library
@@ -365,46 +394,51 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
365 unsigned long cur_freq; 394 unsigned long cur_freq;
366 int result = 0, i; 395 int result = 0, i;
367 unsigned int cpu = policy->cpu; 396 unsigned int cpu = policy->cpu;
397 struct acpi_processor_performance *p;
398
399 p = acpi_perf_data[cpu];
368 400
369 /* register with ACPI core */ 401 /* register with ACPI core */
370 if (acpi_processor_register_performance(&p, cpu)) { 402 if (acpi_processor_register_performance(p, cpu)) {
371 dprintk(KERN_INFO PFX "obtaining ACPI data failed\n"); 403 dprintk(KERN_INFO PFX "obtaining ACPI data failed\n");
372 return -EIO; 404 return -EIO;
373 } 405 }
406 policy->cpus = p->shared_cpu_map;
407 policy->shared_type = p->shared_type;
374 408
375 /* verify the acpi_data */ 409 /* verify the acpi_data */
376 if (p.state_count <= 1) { 410 if (p->state_count <= 1) {
377 dprintk("No P-States\n"); 411 dprintk("No P-States\n");
378 result = -ENODEV; 412 result = -ENODEV;
379 goto err_unreg; 413 goto err_unreg;
380 } 414 }
381 415
382 if ((p.control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) || 416 if ((p->control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
383 (p.status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) { 417 (p->status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
384 dprintk("Invalid control/status registers (%x - %x)\n", 418 dprintk("Invalid control/status registers (%x - %x)\n",
385 p.control_register.space_id, p.status_register.space_id); 419 p->control_register.space_id, p->status_register.space_id);
386 result = -EIO; 420 result = -EIO;
387 goto err_unreg; 421 goto err_unreg;
388 } 422 }
389 423
390 for (i=0; i<p.state_count; i++) { 424 for (i=0; i<p->state_count; i++) {
391 if (p.states[i].control != p.states[i].status) { 425 if (p->states[i].control != p->states[i].status) {
392 dprintk("Different control (%llu) and status values (%llu)\n", 426 dprintk("Different control (%llu) and status values (%llu)\n",
393 p.states[i].control, p.states[i].status); 427 p->states[i].control, p->states[i].status);
394 result = -EINVAL; 428 result = -EINVAL;
395 goto err_unreg; 429 goto err_unreg;
396 } 430 }
397 431
398 if (!p.states[i].core_frequency) { 432 if (!p->states[i].core_frequency) {
399 dprintk("Zero core frequency for state %u\n", i); 433 dprintk("Zero core frequency for state %u\n", i);
400 result = -EINVAL; 434 result = -EINVAL;
401 goto err_unreg; 435 goto err_unreg;
402 } 436 }
403 437
404 if (p.states[i].core_frequency > p.states[0].core_frequency) { 438 if (p->states[i].core_frequency > p->states[0].core_frequency) {
405 dprintk("P%u has larger frequency (%llu) than P0 (%llu), skipping\n", i, 439 dprintk("P%u has larger frequency (%llu) than P0 (%llu), skipping\n", i,
406 p.states[i].core_frequency, p.states[0].core_frequency); 440 p->states[i].core_frequency, p->states[0].core_frequency);
407 p.states[i].core_frequency = 0; 441 p->states[i].core_frequency = 0;
408 continue; 442 continue;
409 } 443 }
410 } 444 }
@@ -416,26 +450,26 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
416 } 450 }
417 451
418 centrino_model[cpu]->model_name=NULL; 452 centrino_model[cpu]->model_name=NULL;
419 centrino_model[cpu]->max_freq = p.states[0].core_frequency * 1000; 453 centrino_model[cpu]->max_freq = p->states[0].core_frequency * 1000;
420 centrino_model[cpu]->op_points = kmalloc(sizeof(struct cpufreq_frequency_table) * 454 centrino_model[cpu]->op_points = kmalloc(sizeof(struct cpufreq_frequency_table) *
421 (p.state_count + 1), GFP_KERNEL); 455 (p->state_count + 1), GFP_KERNEL);
422 if (!centrino_model[cpu]->op_points) { 456 if (!centrino_model[cpu]->op_points) {
423 result = -ENOMEM; 457 result = -ENOMEM;
424 goto err_kfree; 458 goto err_kfree;
425 } 459 }
426 460
427 for (i=0; i<p.state_count; i++) { 461 for (i=0; i<p->state_count; i++) {
428 centrino_model[cpu]->op_points[i].index = p.states[i].control; 462 centrino_model[cpu]->op_points[i].index = p->states[i].control;
429 centrino_model[cpu]->op_points[i].frequency = p.states[i].core_frequency * 1000; 463 centrino_model[cpu]->op_points[i].frequency = p->states[i].core_frequency * 1000;
430 dprintk("adding state %i with frequency %u and control value %04x\n", 464 dprintk("adding state %i with frequency %u and control value %04x\n",
431 i, centrino_model[cpu]->op_points[i].frequency, centrino_model[cpu]->op_points[i].index); 465 i, centrino_model[cpu]->op_points[i].frequency, centrino_model[cpu]->op_points[i].index);
432 } 466 }
433 centrino_model[cpu]->op_points[p.state_count].frequency = CPUFREQ_TABLE_END; 467 centrino_model[cpu]->op_points[p->state_count].frequency = CPUFREQ_TABLE_END;
434 468
435 cur_freq = get_cur_freq(cpu); 469 cur_freq = get_cur_freq(cpu);
436 470
437 for (i=0; i<p.state_count; i++) { 471 for (i=0; i<p->state_count; i++) {
438 if (!p.states[i].core_frequency) { 472 if (!p->states[i].core_frequency) {
439 dprintk("skipping state %u\n", i); 473 dprintk("skipping state %u\n", i);
440 centrino_model[cpu]->op_points[i].frequency = CPUFREQ_ENTRY_INVALID; 474 centrino_model[cpu]->op_points[i].frequency = CPUFREQ_ENTRY_INVALID;
441 continue; 475 continue;
@@ -451,7 +485,7 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
451 } 485 }
452 486
453 if (cur_freq == centrino_model[cpu]->op_points[i].frequency) 487 if (cur_freq == centrino_model[cpu]->op_points[i].frequency)
454 p.state = i; 488 p->state = i;
455 } 489 }
456 490
457 /* notify BIOS that we exist */ 491 /* notify BIOS that we exist */
@@ -464,12 +498,13 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
464 err_kfree: 498 err_kfree:
465 kfree(centrino_model[cpu]); 499 kfree(centrino_model[cpu]);
466 err_unreg: 500 err_unreg:
467 acpi_processor_unregister_performance(&p, cpu); 501 acpi_processor_unregister_performance(p, cpu);
468 dprintk(KERN_INFO PFX "invalid ACPI data\n"); 502 dprintk(KERN_INFO PFX "invalid ACPI data\n");
469 return (result); 503 return (result);
470} 504}
471#else 505#else
472static inline int centrino_cpu_init_acpi(struct cpufreq_policy *policy) { return -ENODEV; } 506static inline int centrino_cpu_init_acpi(struct cpufreq_policy *policy) { return -ENODEV; }
507static inline int centrino_cpu_early_init_acpi(void) { return 0; }
473#endif 508#endif
474 509
475static int centrino_cpu_init(struct cpufreq_policy *policy) 510static int centrino_cpu_init(struct cpufreq_policy *policy)
@@ -555,10 +590,15 @@ static int centrino_cpu_exit(struct cpufreq_policy *policy)
555 590
556#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI 591#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
557 if (!centrino_model[cpu]->model_name) { 592 if (!centrino_model[cpu]->model_name) {
558 dprintk("unregistering and freeing ACPI data\n"); 593 static struct acpi_processor_performance *p;
559 acpi_processor_unregister_performance(&p, cpu); 594
560 kfree(centrino_model[cpu]->op_points); 595 if (acpi_perf_data[cpu]) {
561 kfree(centrino_model[cpu]); 596 p = acpi_perf_data[cpu];
597 dprintk("unregistering and freeing ACPI data\n");
598 acpi_processor_unregister_performance(p, cpu);
599 kfree(centrino_model[cpu]->op_points);
600 kfree(centrino_model[cpu]);
601 }
562 } 602 }
563#endif 603#endif
564 604
@@ -592,63 +632,128 @@ static int centrino_target (struct cpufreq_policy *policy,
592 unsigned int relation) 632 unsigned int relation)
593{ 633{
594 unsigned int newstate = 0; 634 unsigned int newstate = 0;
595 unsigned int msr, oldmsr, h, cpu = policy->cpu; 635 unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu;
596 struct cpufreq_freqs freqs; 636 struct cpufreq_freqs freqs;
637 cpumask_t online_policy_cpus;
597 cpumask_t saved_mask; 638 cpumask_t saved_mask;
598 int retval; 639 cpumask_t set_mask;
640 cpumask_t covered_cpus;
641 int retval = 0;
642 unsigned int j, k, first_cpu, tmp;
599 643
600 if (centrino_model[cpu] == NULL) 644 if (unlikely(centrino_model[cpu] == NULL))
601 return -ENODEV; 645 return -ENODEV;
602 646
603 /* 647 if (unlikely(cpufreq_frequency_table_target(policy,
604 * Support for SMP systems. 648 centrino_model[cpu]->op_points,
605 * Make sure we are running on the CPU that wants to change frequency 649 target_freq,
606 */ 650 relation,
607 saved_mask = current->cpus_allowed; 651 &newstate))) {
608 set_cpus_allowed(current, policy->cpus); 652 return -EINVAL;
609 if (!cpu_isset(smp_processor_id(), policy->cpus)) {
610 dprintk("couldn't limit to CPUs in this domain\n");
611 return(-EAGAIN);
612 } 653 }
613 654
614 if (cpufreq_frequency_table_target(policy, centrino_model[cpu]->op_points, target_freq, 655#ifdef CONFIG_HOTPLUG_CPU
615 relation, &newstate)) { 656 /* cpufreq holds the hotplug lock, so we are safe from here on */
616 retval = -EINVAL; 657 cpus_and(online_policy_cpus, cpu_online_map, policy->cpus);
617 goto migrate_end; 658#else
618 } 659 online_policy_cpus = policy->cpus;
660#endif
619 661
620 msr = centrino_model[cpu]->op_points[newstate].index; 662 saved_mask = current->cpus_allowed;
621 rdmsr(MSR_IA32_PERF_CTL, oldmsr, h); 663 first_cpu = 1;
664 cpus_clear(covered_cpus);
665 for_each_cpu_mask(j, online_policy_cpus) {
666 /*
667 * Support for SMP systems.
668 * Make sure we are running on CPU that wants to change freq
669 */
670 cpus_clear(set_mask);
671 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
672 cpus_or(set_mask, set_mask, online_policy_cpus);
673 else
674 cpu_set(j, set_mask);
675
676 set_cpus_allowed(current, set_mask);
677 if (unlikely(!cpu_isset(smp_processor_id(), set_mask))) {
678 dprintk("couldn't limit to CPUs in this domain\n");
679 retval = -EAGAIN;
680 if (first_cpu) {
681 /* We haven't started the transition yet. */
682 goto migrate_end;
683 }
684 break;
685 }
622 686
623 if (msr == (oldmsr & 0xffff)) { 687 msr = centrino_model[cpu]->op_points[newstate].index;
624 retval = 0; 688
625 dprintk("no change needed - msr was and needs to be %x\n", oldmsr); 689 if (first_cpu) {
626 goto migrate_end; 690 rdmsr(MSR_IA32_PERF_CTL, oldmsr, h);
627 } 691 if (msr == (oldmsr & 0xffff)) {
692 dprintk("no change needed - msr was and needs "
693 "to be %x\n", oldmsr);
694 retval = 0;
695 goto migrate_end;
696 }
697
698 freqs.old = extract_clock(oldmsr, cpu, 0);
699 freqs.new = extract_clock(msr, cpu, 0);
700
701 dprintk("target=%dkHz old=%d new=%d msr=%04x\n",
702 target_freq, freqs.old, freqs.new, msr);
703
704 for_each_cpu_mask(k, online_policy_cpus) {
705 freqs.cpu = k;
706 cpufreq_notify_transition(&freqs,
707 CPUFREQ_PRECHANGE);
708 }
709
710 first_cpu = 0;
711 /* all but 16 LSB are reserved, treat them with care */
712 oldmsr &= ~0xffff;
713 msr &= 0xffff;
714 oldmsr |= msr;
715 }
628 716
629 freqs.cpu = cpu; 717 wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
630 freqs.old = extract_clock(oldmsr, cpu, 0); 718 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
631 freqs.new = extract_clock(msr, cpu, 0); 719 break;
632 720
633 dprintk("target=%dkHz old=%d new=%d msr=%04x\n", 721 cpu_set(j, covered_cpus);
634 target_freq, freqs.old, freqs.new, msr); 722 }
635 723
636 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); 724 for_each_cpu_mask(k, online_policy_cpus) {
725 freqs.cpu = k;
726 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
727 }
637 728
638 /* all but 16 LSB are "reserved", so treat them with 729 if (unlikely(retval)) {
639 care */ 730 /*
640 oldmsr &= ~0xffff; 731 * We have failed halfway through the frequency change.
641 msr &= 0xffff; 732 * We have sent callbacks to policy->cpus and
642 oldmsr |= msr; 733 * MSRs have already been written on coverd_cpus.
734 * Best effort undo..
735 */
643 736
644 wrmsr(MSR_IA32_PERF_CTL, oldmsr, h); 737 if (!cpus_empty(covered_cpus)) {
738 for_each_cpu_mask(j, covered_cpus) {
739 set_cpus_allowed(current, cpumask_of_cpu(j));
740 wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
741 }
742 }
645 743
646 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); 744 tmp = freqs.new;
745 freqs.new = freqs.old;
746 freqs.old = tmp;
747 for_each_cpu_mask(j, online_policy_cpus) {
748 freqs.cpu = j;
749 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
750 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
751 }
752 }
647 753
648 retval = 0;
649migrate_end: 754migrate_end:
650 set_cpus_allowed(current, saved_mask); 755 set_cpus_allowed(current, saved_mask);
651 return (retval); 756 return 0;
652} 757}
653 758
654static struct freq_attr* centrino_attr[] = { 759static struct freq_attr* centrino_attr[] = {
@@ -690,12 +795,25 @@ static int __init centrino_init(void)
690 if (!cpu_has(cpu, X86_FEATURE_EST)) 795 if (!cpu_has(cpu, X86_FEATURE_EST))
691 return -ENODEV; 796 return -ENODEV;
692 797
798 centrino_cpu_early_init_acpi();
799
693 return cpufreq_register_driver(&centrino_driver); 800 return cpufreq_register_driver(&centrino_driver);
694} 801}
695 802
696static void __exit centrino_exit(void) 803static void __exit centrino_exit(void)
697{ 804{
805#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
806 unsigned int j;
807#endif
808
698 cpufreq_unregister_driver(&centrino_driver); 809 cpufreq_unregister_driver(&centrino_driver);
810
811#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
812 for_each_cpu(j) {
813 kfree(acpi_perf_data[j]);
814 acpi_perf_data[j] = NULL;
815 }
816#endif
699} 817}
700 818
701MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>"); 819MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>");