]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/acpi/processor_perflib.c
ACPI: Avoid wiping out pr->performance during preregistering
[net-next-2.6.git] / drivers / acpi / processor_perflib.c
index 846e227592d48770787672223a4c37c37ec6468c..215f1bf7d4c14b1aac0d40e5c0c36b95ee53aea1 100644 (file)
 #include <linux/init.h>
 #include <linux/cpufreq.h>
 
-#ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF
-#include <linux/proc_fs.h>
-#include <linux/seq_file.h>
-#include <linux/mutex.h>
-
-#include <asm/uaccess.h>
-#endif
-
 #ifdef CONFIG_X86
 #include <asm/cpufeature.h>
 #endif
@@ -434,96 +426,6 @@ int acpi_processor_notify_smm(struct module *calling_module)
 
 EXPORT_SYMBOL(acpi_processor_notify_smm);
 
-#ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF
-/* /proc/acpi/processor/../performance interface (DEPRECATED) */
-
-static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file);
-static struct file_operations acpi_processor_perf_fops = {
-       .owner = THIS_MODULE,
-       .open = acpi_processor_perf_open_fs,
-       .read = seq_read,
-       .llseek = seq_lseek,
-       .release = single_release,
-};
-
-static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
-{
-       struct acpi_processor *pr = seq->private;
-       int i;
-
-
-       if (!pr)
-               goto end;
-
-       if (!pr->performance) {
-               seq_puts(seq, "<not supported>\n");
-               goto end;
-       }
-
-       seq_printf(seq, "state count:             %d\n"
-                  "active state:            P%d\n",
-                  pr->performance->state_count, pr->performance->state);
-
-       seq_puts(seq, "states:\n");
-       for (i = 0; i < pr->performance->state_count; i++)
-               seq_printf(seq,
-                          "   %cP%d:                  %d MHz, %d mW, %d uS\n",
-                          (i == pr->performance->state ? '*' : ' '), i,
-                          (u32) pr->performance->states[i].core_frequency,
-                          (u32) pr->performance->states[i].power,
-                          (u32) pr->performance->states[i].transition_latency);
-
-      end:
-       return 0;
-}
-
-static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
-{
-       return single_open(file, acpi_processor_perf_seq_show,
-                          PDE(inode)->data);
-}
-
-static void acpi_cpufreq_add_file(struct acpi_processor *pr)
-{
-       struct acpi_device *device = NULL;
-
-
-       if (acpi_bus_get_device(pr->handle, &device))
-               return;
-
-       /* add file 'performance' [R/W] */
-       proc_create_data(ACPI_PROCESSOR_FILE_PERFORMANCE, S_IFREG | S_IRUGO,
-                        acpi_device_dir(device),
-                        &acpi_processor_perf_fops, acpi_driver_data(device));
-       return;
-}
-
-static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
-{
-       struct acpi_device *device = NULL;
-
-
-       if (acpi_bus_get_device(pr->handle, &device))
-               return;
-
-       /* remove file 'performance' */
-       remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
-                         acpi_device_dir(device));
-
-       return;
-}
-
-#else
-static void acpi_cpufreq_add_file(struct acpi_processor *pr)
-{
-       return;
-}
-static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
-{
-       return;
-}
-#endif                         /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */
-
 static int acpi_processor_get_psd(struct acpi_processor        *pr)
 {
        int result = 0;
@@ -577,6 +479,13 @@ static int acpi_processor_get_psd(struct acpi_processor    *pr)
                goto end;
        }
 
+       if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
+           pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
+           pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
+               printk(KERN_ERR PREFIX "Invalid _PSD:coord_type\n");
+               result = -EFAULT;
+               goto end;
+       }
 end:
        kfree(buffer.pointer);
        return result;
@@ -599,9 +508,10 @@ int acpi_processor_preregister_performance(
 
        mutex_lock(&performance_mutex);
 
-       retval = 0;
-
-       /* Call _PSD for all CPUs */
+       /*
+        * Check if another driver has already registered, and abort before
+        * changing pr->performance if it has. Check input data as well.
+        */
        for_each_possible_cpu(i) {
                pr = per_cpu(processors, i);
                if (!pr) {
@@ -611,13 +521,20 @@ int acpi_processor_preregister_performance(
 
                if (pr->performance) {
                        retval = -EBUSY;
-                       continue;
+                       goto err_out;
                }
 
                if (!performance || !percpu_ptr(performance, i)) {
                        retval = -EINVAL;
-                       continue;
+                       goto err_out;
                }
+       }
+
+       /* Call _PSD for all CPUs */
+       for_each_possible_cpu(i) {
+               pr = per_cpu(processors, i);
+               if (!pr)
+                       continue;
 
                pr->performance = percpu_ptr(performance, i);
                cpumask_set_cpu(i, pr->performance->shared_cpu_map);
@@ -633,26 +550,6 @@ int acpi_processor_preregister_performance(
         * Now that we have _PSD data from all CPUs, lets setup P-state 
         * domain info.
         */
-       for_each_possible_cpu(i) {
-               pr = per_cpu(processors, i);
-               if (!pr)
-                       continue;
-
-               /* Basic validity check for domain info */
-               pdomain = &(pr->performance->domain_info);
-               if ((pdomain->revision != ACPI_PSD_REV0_REVISION) ||
-                   (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES)) {
-                       retval = -EINVAL;
-                       goto err_ret;
-               }
-               if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
-                   pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
-                   pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
-                       retval = -EINVAL;
-                       goto err_ret;
-               }
-       }
-
        cpumask_clear(covered_cpus);
        for_each_possible_cpu(i) {
                pr = per_cpu(processors, i);
@@ -741,20 +638,19 @@ err_ret:
                pr->performance = NULL; /* Will be set for real in register */
        }
 
+err_out:
        mutex_unlock(&performance_mutex);
        free_cpumask_var(covered_cpus);
        return retval;
 }
 EXPORT_SYMBOL(acpi_processor_preregister_performance);
 
-
 int
 acpi_processor_register_performance(struct acpi_processor_performance
                                    *performance, unsigned int cpu)
 {
        struct acpi_processor *pr;
 
-
        if (!(acpi_processor_ppc_status & PPC_REGISTERED))
                return -EINVAL;
 
@@ -781,8 +677,6 @@ acpi_processor_register_performance(struct acpi_processor_performance
                return -EIO;
        }
 
-       acpi_cpufreq_add_file(pr);
-
        mutex_unlock(&performance_mutex);
        return 0;
 }
@@ -795,7 +689,6 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
 {
        struct acpi_processor *pr;
 
-
        mutex_lock(&performance_mutex);
 
        pr = per_cpu(processors, cpu);
@@ -808,8 +701,6 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
                kfree(pr->performance->states);
        pr->performance = NULL;
 
-       acpi_cpufreq_remove_file(pr);
-
        mutex_unlock(&performance_mutex);
 
        return;