public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
@ 2004-05-12 23:56 Tony Lindgren
  2004-05-13 16:26 ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Tony Lindgren @ 2004-05-12 23:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: davej, pavel

[-- Attachment #1: Type: text/plain, Size: 492 bytes --]

Hi,

Following is the updated patch to make the powernow-k8 driver work on 
machines with buggy BIOS, such as emachines m6805.

The patch overrides the PST table only if check_pst_table() fails.

The minimum value for the override is 800MHz, which is the lowest value 
on all x86_64 systems AFAIK. The max value is the current running value.

This patch should be safe to apply, even if Pavel's ACPI table check is
added to the driver. Or does anybody see a problem with it?

Regards,

Tony


[-- Attachment #2: patch-2.6.6-powernow-k8-buggy-bios --]
[-- Type: text/plain, Size: 4073 bytes --]

Amd64 cpufreq driver patch to override a buggy BIOS table with
current running speed as max value, and 800MHz as the low value.
Allows the driver to work on buggy BIOSes, such as m680x laptops.

This patch contains updates to the following files:
   b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c

diff -Nru a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c	Wed May 12 15:42:18 2004
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c	Wed May 12 15:42:18 2004
@@ -42,6 +42,8 @@
 #define VERSION "version 1.00.08b"
 #include "powernow-k8.h"
 
+#define MAX_NR_PST	16
+
 /* serialize freq changes  */
 static DECLARE_MUTEX(fidvid_sem);
 
@@ -482,6 +484,23 @@
 
 }
 
+/*
+ * This is the place to override the buggy BIOS values
+ */
+static int override_pst_table(struct powernow_k8_data *data, struct pst_s *pst) {
+	printk(KERN_INFO PFX "BIOS error: overriding frequency table\n");
+
+	/* Use a safe minimum speed 800MHz */
+	pst[0].fid = 0x00;
+	pst[0].vid = 0x12;
+
+	/* Use current speed as the maximum speed */
+	pst[1].fid = data->currfid;
+	pst[1].vid = data->currvid;
+
+	return 2;
+}
+
 static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid)
 {
 	unsigned int j;
@@ -538,6 +557,7 @@
 {
 	struct cpufreq_frequency_table *powernow_table;
 	unsigned int j;
+	struct pst_s *pst_tmp;
 
 	if (data->batps) {    /* use ACPI support to get full speed on mains power */
 		printk(KERN_WARNING PFX "Only %d pstates usable (use ACPI driver for full range\n", data->batps);
@@ -555,39 +575,49 @@
 		printk(KERN_ERR PFX "no p states to transition\n");
 		return -ENODEV;
 	}
-                                                                                                    
+
+	/* Must have the current values early in case of override_pst_table() */
+	if (query_current_values_with_pending_wait(data))
+		return -EIO;
+
+	/* Copy the BIOS table into a temporary table in case it needs override */
+	pst_tmp = kmalloc(sizeof(struct pst_s) * MAX_NR_PST, GFP_KERNEL);
+	if (!pst_tmp) {
+		printk(KERN_ERR PFX "pst_tmp memory alloc failure\n");
+		return -ENOMEM;
+	}
+	memset(pst_tmp, 0, sizeof(struct pst_s) * MAX_NR_PST);
+	memcpy(pst_tmp, pst, sizeof(struct pst_s) * data->numps);	
+
 	if (check_pst_table(data, pst, maxvid))
-		return -EINVAL;
+		data->numps = override_pst_table(data, pst_tmp);
 
 	powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table)
 		* (data->numps + 1)), GFP_KERNEL);
 	if (!powernow_table) {
 		printk(KERN_ERR PFX "powernow_table memory alloc failure\n");
+		kfree(pst_tmp);
 		return -ENOMEM;
 	}
 
 	for (j = 0; j < data->numps; j++) {
-		powernow_table[j].index = pst[j].fid; /* lower 8 bits */
-		powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */
-		powernow_table[j].frequency = find_khz_freq_from_fid(pst[j].fid);
+		powernow_table[j].index = pst_tmp[j].fid; /* lower 8 bits */
+		powernow_table[j].index |= (pst_tmp[j].vid << 8); /* upper 8 bits */
+		powernow_table[j].frequency = find_khz_freq_from_fid(pst_tmp[j].fid);
 	}
 	powernow_table[data->numps].frequency = CPUFREQ_TABLE_END;
 	powernow_table[data->numps].index = 0;
 
-	if (query_current_values_with_pending_wait(data)) {
-		kfree(powernow_table);
-		return -EIO;
-	}
-
 	dprintk(KERN_INFO PFX "cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid);
 	data->powernow_table = powernow_table;
 	print_basics(data);
 
 	for (j = 0; j < data->numps; j++)
-		if ((pst[j].fid==data->currfid) && (pst[j].vid==data->currvid))
+		if ((pst_tmp[j].fid==data->currfid) && (pst_tmp[j].vid==data->currvid))
 			return 0;
 
 	dprintk(KERN_ERR PFX "currfid/vid do not match PST, ignoring\n");
+	kfree(pst_tmp);
 	return 0;
 }
 
@@ -637,8 +667,8 @@
 
 		dprintk(KERN_DEBUG PFX "numpst: 0x%x\n", psb->numpst);
 		if (psb->numpst != 1) {
-			printk(KERN_ERR BFX "numpst must be 1\n");
-			return -ENODEV;
+			printk(KERN_WARNING BFX "numpst listed as %i "
+			       "should be 1. Ignoring it.\n", psb->numpst);
 		}
 
 		data->plllock = psb->plllocktime;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
  2004-05-12 23:56 [PATCH] Powernow-k8 buggy BIOS override for 2.6.6 Tony Lindgren
@ 2004-05-13 16:26 ` Pavel Machek
  2004-05-13 17:19   ` Tony Lindgren
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2004-05-13 16:26 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-kernel, davej

Hi!

> Following is the updated patch to make the powernow-k8 driver work on 
> machines with buggy BIOS, such as emachines m6805.
> 
> The patch overrides the PST table only if check_pst_table() fails.
> 
> The minimum value for the override is 800MHz, which is the lowest value 
> on all x86_64 systems AFAIK. The max value is the current running value.
> 
> This patch should be safe to apply, even if Pavel's ACPI table check is
> added to the driver. Or does anybody see a problem with it?

Well, there may be problems with that.

BIOSen sometimes run cpu at too high voltage. Plus, for changing
frequency you need to run at even higher voltage... and that may be
too high.

Is there some problem with ACPI on your system?
								Pavel

-- 
Horseback riding is like software...
...vgf orggre jura vgf serr.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
  2004-05-13 16:26 ` Pavel Machek
@ 2004-05-13 17:19   ` Tony Lindgren
  2004-05-13 17:21     ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Tony Lindgren @ 2004-05-13 17:19 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, davej

[-- Attachment #1: Type: text/plain, Size: 1252 bytes --]

* Pavel Machek <pavel@ucw.cz> [040513 09:26]:
> Hi!
> 
> > Following is the updated patch to make the powernow-k8 driver work on 
> > machines with buggy BIOS, such as emachines m6805.
> > 
> > The patch overrides the PST table only if check_pst_table() fails.
> > 
> > The minimum value for the override is 800MHz, which is the lowest value 
> > on all x86_64 systems AFAIK. The max value is the current running value.
> > 
> > This patch should be safe to apply, even if Pavel's ACPI table check is
> > added to the driver. Or does anybody see a problem with it?
> 
> Well, there may be problems with that.

That works good now, see my recent posting to the thread on the cpufreq list
for more details. I had ACPI processor as module, and that made the
powernow-k8 ACPI detection to fail. I fixed it with the following little
patch, attaching it here too for reference.

> BIOSen sometimes run cpu at too high voltage. Plus, for changing
> frequency you need to run at even higher voltage... and that may be
> too high.
> 
> Is there some problem with ACPI on your system?

Works now, from cpufreq point of view. As of 2.6.6 the ACPI processor 
module hangs the system if compiled in. Loading it as module after init 
does not hang.

Regards,

Tony


[-- Attachment #2: patch-2.6.6-powernow-acpi-module --]
[-- Type: text/plain, Size: 1391 bytes --]

diff -Nru a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c	Thu May 13 09:58:24 2004
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c	Thu May 13 09:58:24 2004
@@ -32,7 +32,7 @@
 #include <asm/io.h>
 #include <asm/delay.h>
 
-#ifdef CONFIG_ACPI_PROCESSOR
+#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
 #include <linux/acpi.h>
 #include <acpi/processor.h>
 #endif
@@ -666,7 +696,7 @@
 	return -ENODEV;
 }
 
-#ifdef CONFIG_ACPI_PROCESSOR
+#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
 static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index)
 {
 	if (!data->acpi_data.state_count)
diff -Nru a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h b/arch/i386/kernel/cpu/cpufreq/powernow-k8.h
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h	Thu May 13 09:58:24 2004
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.h	Thu May 13 09:58:24 2004
@@ -29,7 +29,7 @@
 	 * frequency is in kHz */
 	struct cpufreq_frequency_table  *powernow_table;
 
-#ifdef CONFIG_ACPI_PROCESSOR
+#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
 	/* the acpi table needs to be kept. it's only available if ACPI was
 	 * used to determine valid frequency/vid/fid states */
 	struct acpi_processor_performance acpi_data;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
  2004-05-13 17:19   ` Tony Lindgren
@ 2004-05-13 17:21     ` Pavel Machek
  2004-05-13 17:31       ` Tony Lindgren
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2004-05-13 17:21 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-kernel, davej

Hi!

> > > Following is the updated patch to make the powernow-k8 driver work on 
> > > machines with buggy BIOS, such as emachines m6805.
> > > 
> > > The patch overrides the PST table only if check_pst_table() fails.
> > > 
> > > The minimum value for the override is 800MHz, which is the lowest value 
> > > on all x86_64 systems AFAIK. The max value is the current running value.
> > > 
> > > This patch should be safe to apply, even if Pavel's ACPI table check is
> > > added to the driver. Or does anybody see a problem with it?
> > 
> > Well, there may be problems with that.
> 
> That works good now, see my recent posting to the thread on the cpufreq list
> for more details. I had ACPI processor as module, and that made the
> powernow-k8 ACPI detection to fail. I fixed it with the following little
> patch, attaching it here too for reference.

This patch is okay if you insert modules in right order, but not if
you attempt to insert cpufreq before acpi, right?

Please do not make that go in like it is.
								Pavel


> diff -Nru a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
> --- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c	Thu May 13 09:58:24 2004
> +++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c	Thu May 13 09:58:24 2004
> @@ -32,7 +32,7 @@
>  #include <asm/io.h>
>  #include <asm/delay.h>
>  
> -#ifdef CONFIG_ACPI_PROCESSOR
> +#if defined(CONFIG_ACPI_PROCESSOR) || defined(CONFIG_ACPI_PROCESSOR_MODULE)
>  #include <linux/acpi.h>
>  #include <acpi/processor.h>
>  #endif

-- 
Horseback riding is like software...
...vgf orggre jura vgf serr.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
  2004-05-13 17:21     ` Pavel Machek
@ 2004-05-13 17:31       ` Tony Lindgren
  2004-05-13 17:32         ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Tony Lindgren @ 2004-05-13 17:31 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, davej

* Pavel Machek <pavel@ucw.cz> [040513 10:21]:
> 
> This patch is okay if you insert modules in right order, but not if
> you attempt to insert cpufreq before acpi, right?

For me modprobe powernow-k8 automatically also loads processor.

> Please do not make that go in like it is.

What would you suggest?

Tony

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
  2004-05-13 17:31       ` Tony Lindgren
@ 2004-05-13 17:32         ` Pavel Machek
  2004-05-13 17:41           ` Tony Lindgren
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2004-05-13 17:32 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-kernel, davej

Hi!


> > This patch is okay if you insert modules in right order, but not if
> > you attempt to insert cpufreq before acpi, right?
> 
> For me modprobe powernow-k8 automatically also loads processor.
> 
> > Please do not make that go in like it is.
> 
> What would you suggest?

Really? Things might have changed from last time. If it is so, perhaps
patch is okay...
								Pavel
-- 
Horseback riding is like software...
...vgf orggre jura vgf serr.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Powernow-k8 buggy BIOS override for 2.6.6
  2004-05-13 17:32         ` Pavel Machek
@ 2004-05-13 17:41           ` Tony Lindgren
  0 siblings, 0 replies; 7+ messages in thread
From: Tony Lindgren @ 2004-05-13 17:41 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, davej

* Pavel Machek <pavel@ucw.cz> [040513 10:32]:
> Hi!
> 
> 
> > > This patch is okay if you insert modules in right order, but not if
> > > you attempt to insert cpufreq before acpi, right?
> > 
> > For me modprobe powernow-k8 automatically also loads processor.
> > 
> > > Please do not make that go in like it is.
> > 
> > What would you suggest?
> 
> Really? Things might have changed from last time. If it is so, perhaps
> patch is okay...

Yeah, maybe acpi_processor_register_performance() was not exported earlier,
or something.

Tony

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-05-13 17:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-12 23:56 [PATCH] Powernow-k8 buggy BIOS override for 2.6.6 Tony Lindgren
2004-05-13 16:26 ` Pavel Machek
2004-05-13 17:19   ` Tony Lindgren
2004-05-13 17:21     ` Pavel Machek
2004-05-13 17:31       ` Tony Lindgren
2004-05-13 17:32         ` Pavel Machek
2004-05-13 17:41           ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox