fbdev: move FBIO_WAITFORVSYNC to linux/fb.h
[safe/jmp/linux-2.6] / drivers / acpi / processor_perflib.c
index b0614f3..ba1bd26 100644 (file)
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/cpufreq.h>
+#include <linux/slab.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
 
 #include <acpi/acpi_bus.h>
+#include <acpi/acpi_drivers.h>
 #include <acpi/processor.h>
 
-#define ACPI_PROCESSOR_COMPONENT       0x01000000
+#define PREFIX "ACPI: "
+
 #define ACPI_PROCESSOR_CLASS           "processor"
 #define ACPI_PROCESSOR_FILE_PERFORMANCE        "performance"
 #define _COMPONENT             ACPI_PROCESSOR_COMPONENT
@@ -127,7 +125,7 @@ static struct notifier_block acpi_ppc_notifier_block = {
 static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
 {
        acpi_status status = 0;
-       unsigned long ppc = 0;
+       unsigned long long ppc = 0;
 
 
        if (!pr)
@@ -155,21 +153,78 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
        return 0;
 }
 
-int acpi_processor_ppc_has_changed(struct acpi_processor *pr)
+#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE      0x80
+/*
+ * acpi_processor_ppc_ost: Notify firmware the _PPC evaluation status
+ * @handle: ACPI processor handle
+ * @status: the status code of _PPC evaluation
+ *     0: success. OSPM is now using the performance state specificed.
+ *     1: failure. OSPM has not changed the number of P-states in use
+ */
+static void acpi_processor_ppc_ost(acpi_handle handle, int status)
+{
+       union acpi_object params[2] = {
+               {.type = ACPI_TYPE_INTEGER,},
+               {.type = ACPI_TYPE_INTEGER,},
+       };
+       struct acpi_object_list arg_list = {2, params};
+       acpi_handle temp;
+
+       params[0].integer.value = ACPI_PROCESSOR_NOTIFY_PERFORMANCE;
+       params[1].integer.value =  status;
+
+       /* when there is no _OST , skip it */
+       if (ACPI_FAILURE(acpi_get_handle(handle, "_OST", &temp)))
+               return;
+
+       acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
+       return;
+}
+
+int acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag)
 {
        int ret;
 
-       if (ignore_ppc)
+       if (ignore_ppc) {
+               /*
+                * Only when it is notification event, the _OST object
+                * will be evaluated. Otherwise it is skipped.
+                */
+               if (event_flag)
+                       acpi_processor_ppc_ost(pr->handle, 1);
                return 0;
+       }
 
        ret = acpi_processor_get_platform_limit(pr);
-
+       /*
+        * Only when it is notification event, the _OST object
+        * will be evaluated. Otherwise it is skipped.
+        */
+       if (event_flag) {
+               if (ret < 0)
+                       acpi_processor_ppc_ost(pr->handle, 1);
+               else
+                       acpi_processor_ppc_ost(pr->handle, 0);
+       }
        if (ret < 0)
                return (ret);
        else
                return cpufreq_update_policy(pr->id);
 }
 
+int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
+{
+       struct acpi_processor *pr;
+
+       pr = per_cpu(processors, cpu);
+       if (!pr || !pr->performance || !pr->performance->state_count)
+               return -ENODEV;
+       *limit = pr->performance->states[pr->performance_platform_limit].
+               core_frequency * 1000;
+       return 0;
+}
+EXPORT_SYMBOL(acpi_processor_get_bios_limit);
+
 void acpi_processor_ppc_init(void)
 {
        if (!cpufreq_register_notifier
@@ -314,9 +369,15 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
                                  (u32) px->bus_master_latency,
                                  (u32) px->control, (u32) px->status));
 
-               if (!px->core_frequency) {
-                       printk(KERN_ERR PREFIX
-                                   "Invalid _PSS data: freq is zero\n");
+               /*
+                * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
+                */
+               if (!px->core_frequency ||
+                   ((u32)(px->core_frequency * 1000) !=
+                    (px->core_frequency * 1000))) {
+                       printk(KERN_ERR FW_BUG PREFIX
+                              "Invalid BIOS _PSS frequency: 0x%llx MHz\n",
+                              px->core_frequency);
                        result = -EFAULT;
                        kfree(pr->performance->states);
                        goto end;
@@ -353,18 +414,24 @@ static int acpi_processor_get_performance_info(struct acpi_processor *pr)
        if (result)
                goto update_bios;
 
-       return 0;
+       /* We need to call _PPC once when cpufreq starts */
+       if (ignore_ppc != 1)
+               result = acpi_processor_get_platform_limit(pr);
+
+       return result;
 
        /*
         * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
         * the BIOS is older than the CPU and does not know its frequencies
         */
  update_bios:
+#ifdef CONFIG_X86
        if (ACPI_SUCCESS(acpi_get_handle(pr->handle, "_PPC", &handle))){
                if(boot_cpu_has(X86_FEATURE_EST))
                        printk(KERN_WARNING FW_BUG "BIOS needs update for CPU "
                               "frequency support\n");
        }
+#endif
        return result;
 }
 
@@ -429,96 +496,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;
@@ -572,28 +549,39 @@ 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;
 }
 
 int acpi_processor_preregister_performance(
-               struct acpi_processor_performance *performance)
+               struct acpi_processor_performance __percpu *performance)
 {
        int count, count_target;
        int retval = 0;
        unsigned int i, j;
-       cpumask_t covered_cpus;
+       cpumask_var_t covered_cpus;
        struct acpi_processor *pr;
        struct acpi_psd_package *pdomain;
        struct acpi_processor *match_pr;
        struct acpi_psd_package *match_pdomain;
 
-       mutex_lock(&performance_mutex);
+       if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))
+               return -ENOMEM;
 
-       retval = 0;
+       mutex_lock(&performance_mutex);
 
-       /* 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) {
@@ -603,16 +591,23 @@ int acpi_processor_preregister_performance(
 
                if (pr->performance) {
                        retval = -EBUSY;
-                       continue;
+                       goto err_out;
                }
 
-               if (!performance || !percpu_ptr(performance, i)) {
+               if (!performance || !per_cpu_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);
-               cpu_set(i, pr->performance->shared_cpu_map);
+               pr->performance = per_cpu_ptr(performance, i);
+               cpumask_set_cpu(i, pr->performance->shared_cpu_map);
                if (acpi_processor_get_psd(pr)) {
                        retval = -EINVAL;
                        continue;
@@ -630,33 +625,12 @@ int acpi_processor_preregister_performance(
                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;
-               }
-       }
-
-       cpus_clear(covered_cpus);
-       for_each_possible_cpu(i) {
-               pr = per_cpu(processors, i);
-               if (!pr)
-                       continue;
-
-               if (cpu_isset(i, covered_cpus))
+               if (cpumask_test_cpu(i, covered_cpus))
                        continue;
 
                pdomain = &(pr->performance->domain_info);
-               cpu_set(i, pr->performance->shared_cpu_map);
-               cpu_set(i, covered_cpus);
+               cpumask_set_cpu(i, pr->performance->shared_cpu_map);
+               cpumask_set_cpu(i, covered_cpus);
                if (pdomain->num_processors <= 1)
                        continue;
 
@@ -694,8 +668,8 @@ int acpi_processor_preregister_performance(
                                goto err_ret;
                        }
 
-                       cpu_set(j, covered_cpus);
-                       cpu_set(j, pr->performance->shared_cpu_map);
+                       cpumask_set_cpu(j, covered_cpus);
+                       cpumask_set_cpu(j, pr->performance->shared_cpu_map);
                        count++;
                }
 
@@ -713,8 +687,8 @@ int acpi_processor_preregister_performance(
 
                        match_pr->performance->shared_type = 
                                        pr->performance->shared_type;
-                       match_pr->performance->shared_cpu_map =
-                               pr->performance->shared_cpu_map;
+                       cpumask_copy(match_pr->performance->shared_cpu_map,
+                                    pr->performance->shared_cpu_map);
                }
        }
 
@@ -726,26 +700,26 @@ err_ret:
 
                /* Assume no coordination on any error parsing domain info */
                if (retval) {
-                       cpus_clear(pr->performance->shared_cpu_map);
-                       cpu_set(i, pr->performance->shared_cpu_map);
+                       cpumask_clear(pr->performance->shared_cpu_map);
+                       cpumask_set_cpu(i, pr->performance->shared_cpu_map);
                        pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
                }
                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;
 
@@ -772,8 +746,6 @@ acpi_processor_register_performance(struct acpi_processor_performance
                return -EIO;
        }
 
-       acpi_cpufreq_add_file(pr);
-
        mutex_unlock(&performance_mutex);
        return 0;
 }
@@ -786,7 +758,6 @@ acpi_processor_unregister_performance(struct acpi_processor_performance
 {
        struct acpi_processor *pr;
 
-
        mutex_lock(&performance_mutex);
 
        pr = per_cpu(processors, cpu);
@@ -799,8 +770,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;