Skip to contentSkip to conversation

Share more code between pn-k8 and pn-k8-acpi

PATCH Pavel Machek 1 participant 1 message Mar 5, 2004

lore
Share & tools
lore
#0 lore raw

Hi!

I added struct percpu to powernow-k8 driver, too, and now a lot more code can be easily shared between pn-k8 and pn-k8-acpi drivers. There are about 100 more lines of duplicated code, but those are not so easy to deal with. Rest of driver is reading tables etc, and seems unique to each driver. Plus acpi one includes "ac-power-poller".
Pavel

arch/i386/kernel/cpu/cpufreq/powernow-k8-acpi.c renamed from linux/arch/i386/kernel/cpu/cpufreq/powernow-k8-acpi.c +0 -208
@@ -37,34 +37,11 @@
 #include <asm/delay.h>
 
 #define PFX "powernow-k8-acpi: "
-#define DFX KERN_DEBUG PFX
-#define IFX KERN_INFO  PFX
-#define EFX KERN_ERR   PFX
 
 #undef DEBUG
 #define VERSION "Version 1.20.02a"
 #include "powernow-k8.h"
 
-struct pstate {    /* info on each performance state, per processor */
-	u16 freq;  /* frequency is in megahertz */
-	u8 fid;
-	u8 vid;
-	u8 irt;
-	u8 rvo;
-	u8 plllock;
-	u8 vidmvs;
-	u8 vstable;
-	u8 pad1;
-	u16 pad2;
-};
-
-struct cpu_power {
-	int numps;
-	int cvid;
-	int cfid;
-	struct pstate pst[0];
-};
-
 /*
  * Each processor may have
  * a different number of entries in its array. I.e., processor 0 may have
@@ -139,23 +116,6 @@
 	return (freq - 800) / 100;
 }
 
-static int query_current_values_with_pending_wait(struct cpu_power *perproc)
-{
-	u32 lo = MSR_S_LO_CHANGE_PENDING;
-	u32 hi;
-	u32 i = 0;
-
-	while (lo & MSR_S_LO_CHANGE_PENDING) {
-		if (i++ > 0x1000000) {
-			printk(EFX "change pending stuck\n");
-			return 1;
-		}
-		rdmsr(MSR_FIDVID_STAT, lo, hi);
-	}
-	perproc->cvid = hi & MSR_S_HI_CURRENT_VID;
-	perproc->cfid = lo & MSR_S_LO_CURRENT_FID;
-	return 0;
-}
 
 /* need to init the control msr to a safe value (for each cpu) */
 static void fidvid_msr_init(void)
@@ -213,36 +173,6 @@
 	return 0;
 }
 
-static int write_new_vid(struct cpu_power *perproc, u8 vid)
-{
-	u32 lo;
-	u8 savefid = perproc->cfid;
-
-	if ((savefid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) {
-		printk(EFX "overflow on vid write\n");
-		return 1;
-	}
-
-	lo = perproc->cfid | (vid << MSR_C_LO_VID_SHIFT) | MSR_C_LO_INIT;
-	dprintk(DFX "cpu%d, writing vid %x, lo %x, hi %x\n",
-		smp_processor_id(), vid, lo, STOP_GRANT_5NS);
-	wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
-	if (query_current_values_with_pending_wait(perproc))
-		return 1;
-
-	if (savefid != perproc->cfid) {
-		printk(EFX "fid change on vid trans, old %x new %x\n",
-		       savefid, perproc->cfid);
-		return 1;
-	}
-	if (vid != perproc->cvid) {
-		printk(EFX "vid trans failed, vid %x, cvid %x\n",
-		       vid, perproc->cfid);
-		return 1;
-	}
-	return 0;
-}
-
 static int decrease_vid_code_by_step(struct cpu_power *perproc, u32 idx, u8 reqvid, u8 step)
 {
 	struct pstate *pst;
@@ -309,144 +239,6 @@
 	return 0;
 }
 
-static inline int core_frequency_transition(struct cpu_power *perproc, u32 idx, u8 reqfid)
-{
-	u8 vcoreqfid;
-	u8 vcocurrfid;
-	u8 vcofiddiff;
-	u8 savevid = perproc->cvid;
-
-	if ((reqfid < HI_FID_TABLE_BOTTOM)
-	    && (perproc->cfid < HI_FID_TABLE_BOTTOM)) {
-		printk(EFX "ph2 illegal lo-lo transition %x %x\n",
-		       reqfid, perproc->cfid);
-		return 1;
-	}
-
-	if (perproc->cfid == reqfid) {
-		printk(EFX "ph2 null fid transition %x\n", reqfid );
-		return 0;
-	}
-
-	dprintk(DFX "ph2 start%d, cfid %x, cvid %x, rfid %x\n",
-		smp_processor_id(),
-		perproc->cfid, perproc->cvid, reqfid);
-
-	vcoreqfid = convert_fid_to_vfid(reqfid);
-	vcocurrfid = convert_fid_to_vfid(perproc->cfid);
-	vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid
-						: vcoreqfid - vcocurrfid;
-
-	while (vcofiddiff > FSTEP) {
-		if (reqfid > perproc->cfid) {
-			if (perproc->cfid > LO_FID_TABLE_TOP) {
-				if (write_new_fid(perproc, idx,
-						  perproc->cfid + FSTEP))
-					return 1;
-			} else {
-				if (write_new_fid(perproc, idx, FSTEP +
-				     convert_fid_to_vfid(perproc->cfid)))
-					return 1;
-			}
-		} else {
-			if (write_new_fid(perproc, idx,
-					  perproc->cfid-FSTEP))
-				return 1;
-		}
-
-		vcocurrfid = convert_fid_to_vfid(perproc->cfid);
-		vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid
-						    : vcoreqfid - vcocurrfid;
-	}
-	if (write_new_fid(perproc, idx, reqfid))
-		return 1;
-	if (query_current_values_with_pending_wait(perproc))
-		return 1;
-
-	if (perproc->cfid != reqfid) {
-		printk(EFX "ph2 mismatch, failed transn, curr %x, req %x\n",
-		       perproc->cfid, reqfid);
-		return 1;
-	}
-
-	if (savevid != perproc->cvid) {
-		printk(EFX "ph2 vid changed, save %x, curr %x\n", savevid,
-		       perproc->cvid);
-		return 1;
-	}
-
-	dprintk(DFX "ph2 complete%d, currfid 0x%x, currvid 0x%x\n",
-		smp_processor_id(),
-		perproc->cfid, perproc->cvid);
-	return 0;
-}
-
-static inline int core_voltage_post_transition(struct cpu_power *perproc, u32 idx, u8 reqvid)
-{
-	u8 savefid = perproc->cfid;
-	u8 savereqvid = reqvid;
-
-	dprintk(DFX "ph3 starting%d, cfid 0x%x, cvid 0x%x\n",
-		smp_processor_id(),
-		perproc->cfid, perproc->cvid);
-
-	if (reqvid != perproc->cvid) {
-		if (write_new_vid(perproc, reqvid))
-			return 1;
-
-		if (savefid != perproc->cfid) {
-			printk(EFX "ph3: bad fid change, save %x, curr %x\n",
-			       savefid, perproc->cfid);
-			return 1;
-		}
-
-		if (perproc->cvid != reqvid) {
-			printk(EFX "ph3: failed vid trans\n, req %x, curr %x",
-			       reqvid, perproc->cvid);
-			return 1;
-		}
-	}
-	if (query_current_values_with_pending_wait(perproc))
-		return 1;
-
-	if (savereqvid != perproc->cvid) {
-		dprintk(EFX "ph3 failed, currvid 0x%x\n", perproc->cvid);
-		return 1;
-	}
-
-	if (savefid != perproc->cfid) {
-		dprintk(EFX "ph3 failed, currfid changed 0x%x\n",
-			perproc->cfid);
-		return 1;
-	}
-
-	dprintk(DFX "ph3 done%d, cfid 0x%x, cvid 0x%x\n",
-		smp_processor_id(),
-		perproc->cfid, perproc->cvid);
-	return 0;
-}
-
-static inline int transition_fid_vid(struct cpu_power *perproc, u32 idx, u8 rfid, u8 rvid)
-{
-	if (core_voltage_pre_transition(perproc, idx, rvid))
-		return 1;
-	if (core_frequency_transition(perproc, idx, rfid))
-		return 1;
-	if (core_voltage_post_transition(perproc, idx, rvid))
-		return 1;
-	if (query_current_values_with_pending_wait(perproc))
-		return 1;
-	if ((rfid != perproc->cfid) || (rvid != perproc->cvid)) {
-		printk(EFX "failed%d: req %x %x, curr %x %x\n",
-		       smp_processor_id(), rfid, rvid,
-		       perproc->cfid, perproc->cvid);
-		return 1;
-	}
-	dprintk(IFX "transitioned%d: new fid 0x%x, vid 0x%x\n",
-		smp_processor_id(),
-		perproc->cfid, perproc->cvid);
-	return 0;
-}
 
 /* evaluating this object tells us whether we are using mains or battery */
 static inline int process_psr(acpi_handle objh)
arch/i386/kernel/cpu/cpufreq/powernow-k8.c renamed from linux/arch/i386/kernel/cpu/cpufreq/powernow-k8.c +71 -283

559 lines not on this page · raw message

arch/i386/kernel/cpu/cpufreq/powernow-k8.h renamed from linux/arch/i386/kernel/cpu/cpufreq/powernow-k8.h +222 -0

231 lines not on this page · raw message

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]