Commit cb1ddb47 authored by Dave Jones's avatar Dave Jones Committed by Dave Jones

[CPUFREQ] Adding SMP capability to MSR based Enhanced Speedstep.

At present, MSR based Enhanced Speedstep Technology (EST) is handled by
speedstep-centrino.c. The attached patch adds more features to
speedstep-centrino, making it more generic. With these changes, it can
run on SMP systems which supports EST, based on the information provided
by ACPI. The non-ACPI (static table based) driver will still be UP only.

From: "Pallipadi, Venkatesh" <venkatesh.pallipadi@intel.com>
Signed-off-by: default avatarDave Jones <davej@redhat.com>
parent 02bb74dc
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org> * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org>
* *
* WARNING WARNING WARNING * WARNING WARNING WARNING
* *
* This driver manipulates the PERF_CTL MSR, which is only somewhat * This driver manipulates the PERF_CTL MSR, which is only somewhat
* documented. While it seems to work on my laptop, it has not been * documented. While it seems to work on my laptop, it has not been
* tested anywhere else, and it may not work for you, do strange * tested anywhere else, and it may not work for you, do strange
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
#include <linux/cpufreq.h> #include <linux/cpufreq.h>
#include <linux/config.h> #include <linux/config.h>
#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
#include <linux/acpi.h>
#include <acpi/processor.h>
#endif
#include <asm/msr.h> #include <asm/msr.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
...@@ -70,6 +75,7 @@ static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_ ...@@ -70,6 +75,7 @@ static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_
/* Operating points for current CPU */ /* Operating points for current CPU */
static struct cpu_model *centrino_model; static struct cpu_model *centrino_model;
static int centrino_cpu;
#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE
...@@ -270,21 +276,47 @@ static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_ ...@@ -270,21 +276,47 @@ static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, const struct cpu_
return 0; return 0;
} }
/* Extract clock in kHz from PERF_CTL value */ /* To be called only after centrino_model is initialized */
static unsigned extract_clock(unsigned msr) static unsigned extract_clock(unsigned msr)
{ {
msr = (msr >> 8) & 0xff; int i;
return msr * 100000;
/*
* Extract clock in kHz from PERF_CTL value
* for centrino, as some DSDTs are buggy.
* Ideally, this can be done using the acpi_data structure.
*/
if (centrino_cpu) {
msr = (msr >> 8) & 0xff;
return msr * 100000;
}
if ((!centrino_model) || (!centrino_model->op_points))
return 0;
msr &= 0xffff;
for (i = 0;
centrino_model->op_points[i].frequency != CPUFREQ_TABLE_END;
i++) {
if (msr == centrino_model->op_points[i].index)
return centrino_model->op_points[i].frequency;
}
return 0;
} }
/* Return the current CPU frequency in kHz */ /* Return the current CPU frequency in kHz */
static unsigned int get_cur_freq(unsigned int cpu) static unsigned int get_cur_freq(unsigned int cpu)
{ {
unsigned l, h; unsigned l, h;
if (cpu) cpumask_t saved_mask;
saved_mask = current->cpus_allowed;
set_cpus_allowed(current, cpumask_of_cpu(cpu));
if (smp_processor_id() != cpu)
return 0; return 0;
rdmsr(MSR_IA32_PERF_STATUS, l, h); rdmsr(MSR_IA32_PERF_STATUS, l, h);
set_cpus_allowed(current, saved_mask);
return extract_clock(l); return extract_clock(l);
} }
...@@ -293,11 +325,6 @@ static unsigned int get_cur_freq(unsigned int cpu) ...@@ -293,11 +325,6 @@ static unsigned int get_cur_freq(unsigned int cpu)
static struct acpi_processor_performance p; static struct acpi_processor_performance p;
#include <linux/acpi.h>
#include <acpi/processor.h>
#define ACPI_PDC_CAPABILITY_ENHANCED_SPEEDSTEP 0x1
/* /*
* centrino_cpu_init_acpi - register with ACPI P-States library * centrino_cpu_init_acpi - register with ACPI P-States library
* *
...@@ -318,12 +345,12 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy) ...@@ -318,12 +345,12 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
arg0.buffer.pointer = (u8 *) arg0_buf; arg0.buffer.pointer = (u8 *) arg0_buf;
arg0_buf[0] = ACPI_PDC_REVISION_ID; arg0_buf[0] = ACPI_PDC_REVISION_ID;
arg0_buf[1] = 1; arg0_buf[1] = 1;
arg0_buf[2] = ACPI_PDC_CAPABILITY_ENHANCED_SPEEDSTEP; arg0_buf[2] = ACPI_PDC_EST_CAPABILITY_SMP | ACPI_PDC_EST_CAPABILITY_MSR;
p.pdc = &arg_list; p.pdc = &arg_list;
/* register with ACPI core */ /* register with ACPI core */
if (acpi_processor_register_performance(&p, 0)) if (acpi_processor_register_performance(&p, policy->cpu))
return -EIO; return -EIO;
/* verify the acpi_data */ /* verify the acpi_data */
...@@ -358,13 +385,6 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy) ...@@ -358,13 +385,6 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
p.states[i].core_frequency = 0; p.states[i].core_frequency = 0;
continue; continue;
} }
if (extract_clock(p.states[i].control) !=
(p.states[i].core_frequency * 1000)) {
printk(KERN_DEBUG "Invalid encoded frequency\n");
result = -EINVAL;
goto err_unreg;
}
} }
centrino_model = kmalloc(sizeof(struct cpu_model), GFP_KERNEL); centrino_model = kmalloc(sizeof(struct cpu_model), GFP_KERNEL);
...@@ -383,24 +403,36 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy) ...@@ -383,24 +403,36 @@ static int centrino_cpu_init_acpi(struct cpufreq_policy *policy)
goto err_kfree; goto err_kfree;
} }
cur_freq = get_cur_freq(0);
for (i=0; i<p.state_count; i++) { for (i=0; i<p.state_count; i++) {
centrino_model->op_points[i].index = p.states[i].control; centrino_model->op_points[i].index = p.states[i].control;
centrino_model->op_points[i].frequency = p.states[i].core_frequency * 1000; centrino_model->op_points[i].frequency = p.states[i].core_frequency * 1000;
}
centrino_model->op_points[p.state_count].frequency = CPUFREQ_TABLE_END;
cur_freq = get_cur_freq(policy->cpu);
for (i=0; i<p.state_count; i++) {
if (extract_clock(centrino_model->op_points[i].index) !=
(centrino_model->op_points[i].frequency)) {
printk(KERN_DEBUG "Invalid encoded frequency\n");
result = -EINVAL;
goto err_kfree_all;
}
if (cur_freq == centrino_model->op_points[i].frequency) if (cur_freq == centrino_model->op_points[i].frequency)
p.state = i; p.state = i;
if (!p.states[i].core_frequency) if (!p.states[i].core_frequency)
centrino_model->op_points[i].frequency = CPUFREQ_ENTRY_INVALID; centrino_model->op_points[i].frequency = CPUFREQ_ENTRY_INVALID;
} }
centrino_model->op_points[p.state_count].frequency = CPUFREQ_TABLE_END;
return 0; return 0;
err_kfree_all:
kfree(centrino_model->op_points);
err_kfree: err_kfree:
kfree(centrino_model); kfree(centrino_model);
err_unreg: err_unreg:
acpi_processor_unregister_performance(&p, 0); acpi_processor_unregister_performance(&p, policy->cpu);
return (result); return (result);
} }
#else #else
...@@ -415,9 +447,6 @@ static int centrino_cpu_init(struct cpufreq_policy *policy) ...@@ -415,9 +447,6 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
int ret; int ret;
int i; int i;
if (policy->cpu != 0)
return -ENODEV;
/* Only Intel makes Enhanced Speedstep-capable CPUs */ /* Only Intel makes Enhanced Speedstep-capable CPUs */
if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST)) if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST))
return -ENODEV; return -ENODEV;
...@@ -426,13 +455,20 @@ static int centrino_cpu_init(struct cpufreq_policy *policy) ...@@ -426,13 +455,20 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
if (centrino_verify_cpu_id(cpu, &cpu_ids[i])) if (centrino_verify_cpu_id(cpu, &cpu_ids[i]))
break; break;
if (i == N_IDS) { if (i != N_IDS)
printk(KERN_INFO PFX "found unsupported CPU with Enhanced SpeedStep: " centrino_cpu = 1;
"send /proc/cpuinfo to " MAINTAINER "\n");
return -ENODEV;
}
if (centrino_cpu_init_acpi(policy)) { if (centrino_cpu_init_acpi(policy)) {
if (policy->cpu != 0)
return -ENODEV;
if (!centrino_cpu) {
printk(KERN_INFO PFX "found unsupported CPU with "
"Enhanced SpeedStep: send /proc/cpuinfo to "
MAINTAINER "\n");
return -ENODEV;
}
if (centrino_cpu_init_table(policy)) { if (centrino_cpu_init_table(policy)) {
return -ENODEV; return -ENODEV;
} }
...@@ -454,7 +490,7 @@ static int centrino_cpu_init(struct cpufreq_policy *policy) ...@@ -454,7 +490,7 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
} }
} }
freq = get_cur_freq(0); freq = get_cur_freq(policy->cpu);
policy->governor = CPUFREQ_DEFAULT_GOVERNOR; policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
policy->cpuinfo.transition_latency = 10000; /* 10uS transition latency */ policy->cpuinfo.transition_latency = 10000; /* 10uS transition latency */
...@@ -481,7 +517,7 @@ static int centrino_cpu_exit(struct cpufreq_policy *policy) ...@@ -481,7 +517,7 @@ static int centrino_cpu_exit(struct cpufreq_policy *policy)
#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI
if (!centrino_model->model_name) { if (!centrino_model->model_name) {
acpi_processor_unregister_performance(&p, 0); acpi_processor_unregister_performance(&p, policy->cpu);
kfree(centrino_model->op_points); kfree(centrino_model->op_points);
kfree(centrino_model); kfree(centrino_model);
} }
...@@ -519,19 +555,35 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -519,19 +555,35 @@ static int centrino_target (struct cpufreq_policy *policy,
unsigned int newstate = 0; unsigned int newstate = 0;
unsigned int msr, oldmsr, h; unsigned int msr, oldmsr, h;
struct cpufreq_freqs freqs; struct cpufreq_freqs freqs;
cpumask_t saved_mask;
int retval;
if (centrino_model == NULL) if (centrino_model == NULL)
return -ENODEV; return -ENODEV;
/*
* Support for SMP systems.
* Make sure we are running on the CPU that wants to change frequency
*/
saved_mask = current->cpus_allowed;
set_cpus_allowed(current, cpumask_of_cpu(policy->cpu));
if (smp_processor_id() != policy->cpu) {
return(-EAGAIN);
}
if (cpufreq_frequency_table_target(policy, centrino_model->op_points, target_freq, if (cpufreq_frequency_table_target(policy, centrino_model->op_points, target_freq,
relation, &newstate)) relation, &newstate)) {
return -EINVAL; retval = -EINVAL;
goto migrate_end;
}
msr = centrino_model->op_points[newstate].index; msr = centrino_model->op_points[newstate].index;
rdmsr(MSR_IA32_PERF_CTL, oldmsr, h); rdmsr(MSR_IA32_PERF_CTL, oldmsr, h);
if (msr == (oldmsr & 0xffff)) if (msr == (oldmsr & 0xffff)) {
return 0; retval = 0;
goto migrate_end;
}
/* Hm, old frequency can either be the last value we put in /* Hm, old frequency can either be the last value we put in
PERF_CTL, or whatever it is now. The trouble is that TM2 PERF_CTL, or whatever it is now. The trouble is that TM2
...@@ -545,7 +597,7 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -545,7 +597,7 @@ static int centrino_target (struct cpufreq_policy *policy,
TODO: work out how the TCC interrupts work, and try to TODO: work out how the TCC interrupts work, and try to
catch the CPU changing things under us. catch the CPU changing things under us.
*/ */
freqs.cpu = 0; freqs.cpu = policy->cpu;
freqs.old = extract_clock(oldmsr); freqs.old = extract_clock(oldmsr);
freqs.new = extract_clock(msr); freqs.new = extract_clock(msr);
...@@ -564,7 +616,10 @@ static int centrino_target (struct cpufreq_policy *policy, ...@@ -564,7 +616,10 @@ static int centrino_target (struct cpufreq_policy *policy,
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
return 0; retval = 0;
migrate_end:
set_cpus_allowed(current, saved_mask);
return (retval);
} }
static struct freq_attr* centrino_attr[] = { static struct freq_attr* centrino_attr[] = {
......
...@@ -101,6 +101,11 @@ __acpi_release_global_lock (unsigned int *lock) ...@@ -101,6 +101,11 @@ __acpi_release_global_lock (unsigned int *lock)
:"=r"(n_hi), "=r"(n_lo) \ :"=r"(n_hi), "=r"(n_lo) \
:"0"(n_hi), "1"(n_lo)) :"0"(n_hi), "1"(n_lo))
/*
* Refer Intel ACPI _PDC support document for bit definitions
*/
#define ACPI_PDC_EST_CAPABILITY_SMP 0xa
#define ACPI_PDC_EST_CAPABILITY_MSR 0x1
#ifdef CONFIG_ACPI_BOOT #ifdef CONFIG_ACPI_BOOT
extern int acpi_lapic; extern int acpi_lapic;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment