Merge branch 'drm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[safe/jmp/linux-2.6] / drivers / acpi / processor_perflib.c
index 14a00e5..b477a4b 100644 (file)
 
 #define ACPI_PROCESSOR_COMPONENT       0x01000000
 #define ACPI_PROCESSOR_CLASS           "processor"
-#define ACPI_PROCESSOR_DRIVER_NAME     "ACPI Processor Driver"
 #define ACPI_PROCESSOR_FILE_PERFORMANCE        "performance"
 #define _COMPONENT             ACPI_PROCESSOR_COMPONENT
-ACPI_MODULE_NAME("acpi_processor")
+ACPI_MODULE_NAME("processor_perflib");
 
 static DEFINE_MUTEX(performance_mutex);
 
+/* Use cpufreq debug layer for _PPC changes. */
+#define cpufreq_printk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \
+                                               "cpufreq-core", msg)
+
 /*
  * _PPC support is implemented as a CPUfreq policy notifier:
  * This means each time a CPUfreq driver registered also with
@@ -61,6 +64,11 @@ static DEFINE_MUTEX(performance_mutex);
  * policy is adjusted accordingly.
  */
 
+static unsigned int ignore_ppc = 0;
+module_param(ignore_ppc, uint, 0644);
+MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \
+                "limited by BIOS, this should help");
+
 #define PPC_REGISTERED   1
 #define PPC_IN_USE       2
 
@@ -73,6 +81,9 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb,
        struct acpi_processor *pr;
        unsigned int ppc = 0;
 
+       if (ignore_ppc)
+               return 0;
+
        mutex_lock(&performance_mutex);
 
        if (event != CPUFREQ_INCOMPATIBLE)
@@ -83,10 +94,8 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb,
                goto out;
 
        ppc = (unsigned int)pr->performance_platform_limit;
-       if (!ppc)
-               goto out;
 
-       if (ppc > pr->performance->state_count)
+       if (ppc >= pr->performance->state_count)
                goto out;
 
        cpufreq_verify_within_limits(policy, 0,
@@ -126,6 +135,9 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
                return -ENODEV;
        }
 
+       cpufreq_printk("CPU %d: _PPC is %d - frequency %s limited\n", pr->id,
+                      (int)ppc, ppc ? "" : "not");
+
        pr->performance_platform_limit = (int)ppc;
 
        return 0;
@@ -133,7 +145,13 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
 
 int acpi_processor_ppc_has_changed(struct acpi_processor *pr)
 {
-       int ret = acpi_processor_get_platform_limit(pr);
+       int ret;
+
+       if (ignore_ppc)
+               return 0;
+
+       ret = acpi_processor_get_platform_limit(pr);
+
        if (ret < 0)
                return (ret);
        else
@@ -216,7 +234,7 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
               sizeof(struct acpi_pct_register));
 
       end:
-       acpi_os_free(buffer.pointer);
+       kfree(buffer.pointer);
 
        return result;
 }
@@ -238,7 +256,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
                return -ENODEV;
        }
 
-       pss = (union acpi_object *)buffer.pointer;
+       pss = buffer.pointer;
        if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
                printk(KERN_ERR PREFIX "Invalid _PSS data\n");
                result = -EFAULT;
@@ -294,7 +312,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
        }
 
       end:
-       acpi_os_free(buffer.pointer);
+       kfree(buffer.pointer);
 
        return result;
 }
@@ -324,10 +342,6 @@ static int acpi_processor_get_performance_info(struct acpi_processor *pr)
        if (result)
                return result;
 
-       result = acpi_processor_get_platform_limit(pr);
-       if (result)
-               return result;
-
        return 0;
 }
 
@@ -358,31 +372,24 @@ int acpi_processor_notify_smm(struct module *calling_module)
 
        is_done = -EIO;
 
-       /* Can't write pstate_cnt to smi_cmd if either value is zero */
-       if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n"));
+       /* Can't write pstate_control to smi_command if either value is zero */
+       if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n"));
                module_put(calling_module);
                return 0;
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                         "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]\n",
-                         acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd));
+                         "Writing pstate_control [0x%x] to smi_command [0x%x]\n",
+                         acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command));
 
-       /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use
-        * it anyway, so we need to support it... */
-       if (acpi_fadt_is_v1) {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                 "Using v1.0 FADT reserved value for pstate_cnt\n"));
-       }
-
-       status = acpi_os_write_port(acpi_fadt.smi_cmd,
-                                   (u32) acpi_fadt.pstate_cnt, 8);
+       status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
+                                   (u32) acpi_gbl_FADT.pstate_control, 8);
        if (ACPI_FAILURE(status)) {
                ACPI_EXCEPTION((AE_INFO, status,
-                               "Failed to write pstate_cnt [0x%x] to "
-                               "smi_cmd [0x%x]", acpi_fadt.pstate_cnt,
-                               acpi_fadt.smi_cmd));
+                               "Failed to write pstate_control [0x%x] to "
+                               "smi_command [0x%x]", acpi_gbl_FADT.pstate_control,
+                               acpi_gbl_FADT.smi_command));
                module_put(calling_module);
                return status;
        }
@@ -412,7 +419,7 @@ static struct file_operations acpi_processor_perf_fops = {
 
 static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
 {
-       struct acpi_processor *pr = (struct acpi_processor *)seq->private;
+       struct acpi_processor *pr = seq->private;
        int i;
 
 
@@ -447,49 +454,6 @@ static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
                           PDE(inode)->data);
 }
 
-static ssize_t
-acpi_processor_write_performance(struct file *file,
-                                const char __user * buffer,
-                                size_t count, loff_t * data)
-{
-       int result = 0;
-       struct seq_file *m = (struct seq_file *)file->private_data;
-       struct acpi_processor *pr = (struct acpi_processor *)m->private;
-       struct acpi_processor_performance *perf;
-       char state_string[12] = { '\0' };
-       unsigned int new_state = 0;
-       struct cpufreq_policy policy;
-
-
-       if (!pr || (count > sizeof(state_string) - 1))
-               return -EINVAL;
-
-       perf = pr->performance;
-       if (!perf)
-               return -EINVAL;
-
-       if (copy_from_user(state_string, buffer, count))
-               return -EFAULT;
-
-       state_string[count] = '\0';
-       new_state = simple_strtoul(state_string, NULL, 0);
-
-       if (new_state >= perf->state_count)
-               return -EINVAL;
-
-       cpufreq_get_policy(&policy, pr->id);
-
-       policy.cpu = pr->id;
-       policy.min = perf->states[new_state].core_frequency * 1000;
-       policy.max = perf->states[new_state].core_frequency * 1000;
-
-       result = cpufreq_set_policy(&policy);
-       if (result)
-               return result;
-
-       return count;
-}
-
 static void acpi_cpufreq_add_file(struct acpi_processor *pr)
 {
        struct proc_dir_entry *entry = NULL;
@@ -501,10 +465,9 @@ static void acpi_cpufreq_add_file(struct acpi_processor *pr)
 
        /* add file 'performance' [R/W] */
        entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
-                                 S_IFREG | S_IRUGO | S_IWUSR,
+                                 S_IFREG | S_IRUGO,
                                  acpi_device_dir(device));
        if (entry){
-               acpi_processor_perf_fops.write = acpi_processor_write_performance;
                entry->proc_fops = &acpi_processor_perf_fops;
                entry->data = acpi_driver_data(device);
                entry->owner = THIS_MODULE;
@@ -553,7 +516,7 @@ static int acpi_processor_get_psd(struct acpi_processor     *pr)
                return -ENODEV;
        }
 
-       psd = (union acpi_object *) buffer.pointer;
+       psd = buffer.pointer;
        if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) {
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n"));
                result = -EFAULT;
@@ -592,12 +555,12 @@ static int acpi_processor_get_psd(struct acpi_processor   *pr)
        }
 
 end:
-       acpi_os_free(buffer.pointer);
+       kfree(buffer.pointer);
        return result;
 }
 
 int acpi_processor_preregister_performance(
-               struct acpi_processor_performance **performance)
+               struct acpi_processor_performance *performance)
 {
        int count, count_target;
        int retval = 0;
@@ -625,12 +588,12 @@ int acpi_processor_preregister_performance(
                        continue;
                }
 
-               if (!performance || !performance[i]) {
+               if (!performance || !percpu_ptr(performance, i)) {
                        retval = -EINVAL;
                        continue;
                }
 
-               pr->performance = performance[i];
+               pr->performance = percpu_ptr(performance, i);
                cpu_set(i, pr->performance->shared_cpu_map);
                if (acpi_processor_get_psd(pr)) {
                        retval = -EINVAL;
@@ -738,10 +701,6 @@ int acpi_processor_preregister_performance(
        }
 
 err_ret:
-       if (retval) {
-               ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error while parsing _PSD domain information. Assuming no coordination\n"));
-       }
-
        for_each_possible_cpu(i) {
                pr = processors[i];
                if (!pr || !pr->performance)