]> err.no Git - linux-2.6/blobdiff - arch/i386/kernel/cpu/cpufreq/powernow-k8.c
[CPUFREQ] Fix indentation in powernow-k8
[linux-2.6] / arch / i386 / kernel / cpu / cpufreq / powernow-k8.c
index ab6e0611303d4f8b86f694b6c8aaab9e04b2cae3..f44c1b1b04e9719ee901ede6c8cb1f88bbe965d1 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/cpumask.h>
+#include <linux/sched.h>       /* for current / set_cpus_allowed() */
 
 #include <asm/msr.h>
 #include <asm/io.h>
@@ -44,7 +45,7 @@
 
 #define PFX "powernow-k8: "
 #define BFX PFX "BIOS error: "
-#define VERSION "version 1.50.3"
+#define VERSION "version 1.60.0"
 #include "powernow-k8.h"
 
 /* serialize freq changes  */
@@ -111,8 +112,8 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
        u32 i = 0;
 
        do {
-               if (i++ > 0x1000000) {
-                       printk(KERN_ERR PFX "detected change pending stuck\n");
+               if (i++ > 10000) {
+                       dprintk("detected change pending stuck\n");
                        return 1;
                }
                rdmsr(MSR_FIDVID_STATUS, lo, hi);
@@ -159,6 +160,7 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
 {
        u32 lo;
        u32 savevid = data->currvid;
+       u32 i = 0;
 
        if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) {
                printk(KERN_ERR PFX "internal error - overflow on fid write\n");
@@ -170,10 +172,13 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
        dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
                fid, lo, data->plllock * PLL_LOCK_CONVERSION);
 
-       wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
-
-       if (query_current_values_with_pending_wait(data))
-               return 1;
+       do {
+               wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
+               if (i++ > 100) {
+                       printk(KERN_ERR PFX "internal error - pending bit very stuck - no further pstate changes possible\n");
+                       return 1;
+               }                       
+       } while (query_current_values_with_pending_wait(data));
 
        count_off_irt(data);
 
@@ -197,6 +202,7 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
 {
        u32 lo;
        u32 savefid = data->currfid;
+       int i = 0;
 
        if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) {
                printk(KERN_ERR PFX "internal error - overflow on vid write\n");
@@ -208,10 +214,13 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
        dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
                vid, lo, STOP_GRANT_5NS);
 
-       wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
-
-       if (query_current_values_with_pending_wait(data))
-               return 1;
+       do {
+               wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
+               if (i++ > 100) {
+                       printk(KERN_ERR PFX "internal error - pending bit very stuck - no further pstate changes possible\n");
+                       return 1;
+               }
+       } while (query_current_values_with_pending_wait(data));
 
        if (savefid != data->currfid) {
                printk(KERN_ERR PFX "fid changed on vid trans, old 0x%x new 0x%x\n",
@@ -327,7 +336,7 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
 /* Phase 2 - core frequency transition */
 static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
 {
-       u32 vcoreqfid, vcocurrfid, vcofiddiff, savevid = data->currvid;
+       u32 vcoreqfid, vcocurrfid, vcofiddiff, fid_interval, savevid = data->currvid;
 
        if ((reqfid < HI_FID_TABLE_BOTTOM) && (data->currfid < HI_FID_TABLE_BOTTOM)) {
                printk(KERN_ERR PFX "ph2: illegal lo-lo transition 0x%x 0x%x\n",
@@ -350,9 +359,11 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
            : vcoreqfid - vcocurrfid;
 
        while (vcofiddiff > 2) {
+               (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2);
+
                if (reqfid > data->currfid) {
                        if (data->currfid > LO_FID_TABLE_TOP) {
-                               if (write_new_fid(data, data->currfid + 2)) {
+                               if (write_new_fid(data, data->currfid + fid_interval)) {
                                        return 1;
                                }
                        } else {
@@ -362,7 +373,7 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
                                }
                        }
                } else {
-                       if (write_new_fid(data, data->currfid - 2))
+                       if (write_new_fid(data, data->currfid - fid_interval))
                                return 1;
                }
 
@@ -453,10 +464,9 @@ static int check_supported_cpu(unsigned int cpu)
 
        oldmask = current->cpus_allowed;
        set_cpus_allowed(current, cpumask_of_cpu(cpu));
-       schedule();
 
        if (smp_processor_id() != cpu) {
-               printk(KERN_ERR "limiting to cpu %u failed\n", cpu);
+               printk(KERN_ERR PFX "limiting to cpu %u failed\n", cpu);
                goto out;
        }
 
@@ -466,7 +476,7 @@ static int check_supported_cpu(unsigned int cpu)
        eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
        if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) ||
            ((eax & CPUID_XFAM) != CPUID_XFAM_K8) ||
-           ((eax & CPUID_XMOD) > CPUID_XMOD_REV_F)) {
+           ((eax & CPUID_XMOD) > CPUID_XMOD_REV_G)) {
                printk(KERN_INFO PFX "Processor cpuid %x not supported\n", eax);
                goto out;
        }
@@ -488,9 +498,7 @@ static int check_supported_cpu(unsigned int cpu)
 
 out:
        set_cpus_allowed(current, oldmask);
-       schedule();
        return rc;
-
 }
 
 static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid)
@@ -511,22 +519,24 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8
                        printk(KERN_ERR BFX "maxvid exceeded with pstate %d\n", j);
                        return -ENODEV;
                }
-               if ((pst[j].fid > MAX_FID)
-                   || (pst[j].fid & 1)
-                   || (j && (pst[j].fid < HI_FID_TABLE_BOTTOM))) {
+               if (pst[j].fid > MAX_FID) {
+                       printk(KERN_ERR BFX "maxfid exceeded with pstate %d\n", j);
+                       return -ENODEV;
+               }
+               if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) {
                        /* Only first fid is allowed to be in "low" range */
-                       printk(KERN_ERR PFX "two low fids - %d : 0x%x\n", j, pst[j].fid);
+                       printk(KERN_ERR BFX "two low fids - %d : 0x%x\n", j, pst[j].fid);
                        return -EINVAL;
                }
                if (pst[j].fid < lastfid)
                        lastfid = pst[j].fid;
        }
        if (lastfid & 1) {
-               printk(KERN_ERR PFX "lastfid invalid\n");
+               printk(KERN_ERR BFX "lastfid invalid\n");
                return -EINVAL;
        }
        if (lastfid > LO_FID_TABLE_TOP)
-               printk(KERN_INFO PFX  "first fid not from lo freq table\n");
+               printk(KERN_INFO BFX  "first fid not from lo freq table\n");
 
        return 0;
 }
@@ -904,10 +914,9 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
        /* only run on specific CPU from here on */
        oldmask = current->cpus_allowed;
        set_cpus_allowed(current, cpumask_of_cpu(pol->cpu));
-       schedule();
 
        if (smp_processor_id() != pol->cpu) {
-               printk(KERN_ERR "limiting to cpu %u failed\n", pol->cpu);
+               printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
                goto err_out;
        }
 
@@ -959,8 +968,6 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
 
 err_out:
        set_cpus_allowed(current, oldmask);
-       schedule();
-
        return ret;
 }
 
@@ -979,15 +986,17 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
        cpumask_t oldmask = CPU_MASK_ALL;
        int rc, i;
 
+       if (!cpu_online(pol->cpu))
+               return -ENODEV;
+
        if (!check_supported_cpu(pol->cpu))
                return -ENODEV;
 
-       data = kmalloc(sizeof(struct powernow_k8_data), GFP_KERNEL);
+       data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL);
        if (!data) {
                printk(KERN_ERR PFX "unable to alloc powernow_k8_data");
                return -ENOMEM;
        }
-       memset(data,0,sizeof(struct powernow_k8_data));
 
        data->cpu = pol->cpu;
 
@@ -1017,10 +1026,9 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
        /* only run on specific CPU from here on */
        oldmask = current->cpus_allowed;
        set_cpus_allowed(current, cpumask_of_cpu(pol->cpu));
-       schedule();
 
        if (smp_processor_id() != pol->cpu) {
-               printk(KERN_ERR "limiting to cpu %u failed\n", pol->cpu);
+               printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
                goto err_out;
        }
 
@@ -1036,7 +1044,6 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
 
        /* run on any CPU again */
        set_cpus_allowed(current, oldmask);
-       schedule();
 
        pol->governor = CPUFREQ_DEFAULT_GOVERNOR;
        pol->cpus = cpu_core_map[pol->cpu];
@@ -1071,7 +1078,6 @@ static int __init powernowk8_cpu_init(struct cpufreq_policy *pol)
 
 err_out:
        set_cpus_allowed(current, oldmask);
-       schedule();
        powernow_k8_cpu_exit_acpi(data);
 
        kfree(data);
@@ -1107,17 +1113,14 @@ static unsigned int powernowk8_get (unsigned int cpu)
                set_cpus_allowed(current, oldmask);
                return 0;
        }
-       preempt_disable();
-       
+
        if (query_current_values_with_pending_wait(data))
                goto out;
 
        khz = find_khz_freq_from_fid(data->currfid);
 
- out:
-       preempt_enable_no_resched();
+out:
        set_cpus_allowed(current, oldmask);
-
        return khz;
 }
 
@@ -1166,10 +1169,9 @@ static void __exit powernowk8_exit(void)
        cpufreq_unregister_driver(&cpufreq_amd64_driver);
 }
 
-MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and Mark Langsdorf <mark.langsdorf@amd.com.");
+MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and Mark Langsdorf <mark.langsdorf@amd.com>");
 MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver.");
 MODULE_LICENSE("GPL");
 
 late_initcall(powernowk8_init);
 module_exit(powernowk8_exit);
-