Commits

Anonymous committed d56d1da Merge

Merged autothrottle branch.

  • Participants
  • Parent commits c538c7a, c5bfa82
  • Tags working-autothrottle

Comments (0)

Files changed (57)

 *.kext
 .DS_Store
 ._*
+*.orig
+*.pbxuser
+build/*

File ACPICPUThrottle.cpp

-/* ACPICPUThrottle.c: ACPI Processor Performance Control Module for MacOS X
- *
- * Copyright (C) 2006 Niall Douglas <http://www.nedprod.com/>
- * Voltage multiplier support (C) 2008 Prashant Vaibhav <mercurysquad@yahoo.com>
- * AMD direct drive taken from FreeBSD acpi_ppc driver  Copyright (C) 2004,2005 FUKUDA Nobuhiko <nfukuda@spa.is.uec.ac.jp>
- * Intel direct drive taken from EnhancedSpeedStep driver Copyright (C) 2006 keithpk
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Reference:
- *   - ACPI Specification Revision 2.0c, pp.232-236
- *
- * Sysctl:
- *   - kern.cputhrottle_curfreq: Current CPU frequency (in Mhz)
- *   - kern.cputhrottle_verbose: Print lots of debug info to system.log
- *   - kern.cputhrottle_freqs: List of space separated frequencies available (in Mhz)
- *                             Some version text and contact info
- *                             Then a series of Px prefixed available powerstates in the form:
- *                                Px, <clock>Mhz, <power>mW, <cpu latency>us, <bus latency>us (ctrl=0x<reg to write>, status=0x<reg to read>)
- *
- * This module compiles for powerpc but is pretty useless there! :)
- */
-
-/**********************************************************************/
-#include <mach/mach_types.h>
-#include <IOKit/acpi/IOACPIPlatformDevice.h>
-#include <sys/systm.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#include <IOKit/IORegistryEntry.h>
-
-#if defined(__i386__) || defined(__amd64__)
-#include <i386/cpuid.h>
-#include <i386/proc_reg.h>  //for rdmsr64 and friends
-#include <i386/apic.h>
-
-
-/*
- * AMD K8 Cool'n'Quiet
- *
- * Reference:
- *   - BIOS and Kernel Developer's Guide
- *     for the AMD Athlon 64 and AMD Opteron Processors, 26094 Rev.3.12
- *   - linux-2.6.3/arch/i386/kernel/cpu/cpufreq/powernow-k8.[ch]
- *   - acpi_ppc for FreeBSD 5.x and 6.x kernels by FUKUDA Nobuhiko
- */
-
-#define MSR_FIDVID_CTL		0xc0010041
-#define MSR_FIDVID_STATUS	0xc0010042
-
-#define INTEL_MSR_VID_MASK 0x00ff
-#define INTEL_MSR_FID_MASK 0xff00
-
-#define write_control(qw)	wrmsr64(MSR_FIDVID_CTL, (qw))
-#define read_status()		rdmsr64(MSR_FIDVID_STATUS)
-
-#define control_irt(dw)		(((dw) >> 30) & 0x3)
-#define control_rvo(dw)		(((dw) >> 28) & 0x3)
-#define control_pll(dw)		(((dw) >> 20) & 0x7f)
-#define control_mvs(dw)		(((dw) >> 18) & 0x3)
-#define control_vst(dw)		(((dw) >> 11) & 0x7f)
-#define control_vid(dw)		(((dw) >> 6) & 0x1f)
-#define control_fid(dw)		((dw) & 0x3f)
-
-#define status_vid(qw)		(((qw) >> 32) & 0x1f)
-#define status_fid(qw)		((qw) & 0x3f)
-
-#define count_off_irt(irt)	IODelay(10 * (1 << (irt)))
-#define count_off_vst(vst)	IODelay(20 * (vst))
-
-#define FID_TO_VCO_FID(fid)	(((fid) < 8) ? 8 + ((fid) << 1) : (fid))
-
-#define write_fidvid(fid, vid, cnt)	\
-	write_control(((cnt) << 32) | (1ULL << 16) | ((vid) << 8) | (fid))
-#define READ_PENDING_WAIT(qw)	\
-	do { (qw) = read_status(); } while ((qw) & (1ULL << 31))
-
-
-
-// Names and numbers from IA-32 System Programming Guide
-#define MSR_PERF_STATUS		0x198
-#define MSR_PERF_CTL		0x199
-
-#endif
-
-template<typename type> class Ptr
-{
-protected:
-	type *v;
-	Ptr(type *_v=0) : v(_v) { }
-public:
-	~Ptr()
-	{
-		if(v) v->release();
-		v=0;
-	}
-	Ptr &operator=(type *_v)
-	{
-		if(v) v->release();
-		v=_v;
-		return *this;
-	}
-	type *operator->() { return v; }
-	type *operator *() { return v; }
-	const type *operator->() const { return v; }
-	const type *operator *() const { return v; }
-	bool operator!() const { return !v; }
-private:
-	class Tester;
-public:
-	operator Tester *() const
-	{
-		if(v) return (Tester *) 1;
-		return 0;
-	}
-};
-
-class OSObjPtr : public Ptr<OSObject>
-{
-public:
-	OSObjPtr(OSObject *r=0) : Ptr<OSObject>(r) { }
-};
-class IORegPtr : public Ptr<IORegistryEntry>
-{
-public:
-	IORegPtr(IORegistryEntry *r=0) : Ptr<IORegistryEntry>(r) { }
-};
-class IORegIt : public Ptr<IORegistryIterator>
-{
-public:
-	IORegIt(IORegPtr &r, const IORegistryPlane *plane)
-	{
-		v=IORegistryIterator::iterateOver(*r, plane);
-	}
-	IORegIt(IORegistryEntry *r, const IORegistryPlane *plane)
-	{
-		v=IORegistryIterator::iterateOver(r, plane);
-	}
-};
-
-/**********************************************************************/
-
-#pragma pack(1)
-struct ACPIResource
-{
-	unsigned char type;
-	unsigned short dataitemlen;
-	union
-	{
-		struct GenericReg
-		{
-			unsigned char _ASI;		// Address Space ID
-			unsigned char _RBW;		// Register Bit Width
-			unsigned char _RBO;		// Register Bit Offset
-			unsigned char reserved0;
-			IOACPIAddress _ADR;		// Register Address
-		} genericReg;
-	} data;
-};
-#pragma pack()
-
-struct acpi_px_reg
-{
-	IOACPIAddress address;
-	unsigned int bitwidth;
-};
-
-struct PowerState
-{
-	bool active;
-	unsigned int freq, power, tlat, bmlat, control, status, original_control;
-};
-static struct LogicalCPU
-{
-	bool active, useAMDDirectDrive, useIntelDirectDrive;
-	IOACPIPlatformDevice *cpudevice;
-	acpi_px_reg regcontrol, regstatus;
-	PowerState powerStates[16];
-	int maxPowerStates, currentState;
-} logicalCPUs[8];
-
-#ifdef DEBUG
-static int verbose = 1;
-#else
-static int verbose = 1;
-#endif
-static char frequencies[1024] = "";
-static uint32_t baseSystemFreq;
-#define dbg if(verbose) printf
-
-
-/**********************************************************************/
-
-#define ERRH(r) { IOReturn __r=r; if(kIOReturnSuccess!=__r) { dbg("ACPICPUThrottle: Failed with code %d\n", __r); return false; } }
-
-#define dbgPEClock(v) dbg("ACPICPUThrottle:    " #v "=%llu\n", gPEClockFrequencyInfo. v )
-#define abs(v) ((((long)(v))<0) ? -(long)(v) : (long)(v))
-
-// Kernel exports we need but aren't declared in the public header files
-__BEGIN_DECLS
-extern void rtc_clock_stepping(uint32_t new_frequency, uint32_t old_frequency);
-extern void rtc_clock_stepped(uint32_t new_frequency, uint32_t old_frequency);
-__END_DECLS
-
-static void printPEClockFrequencyInfo()
-{
-	dbgPEClock(bus_clock_rate_hz);
-	dbgPEClock(cpu_clock_rate_hz);
-	dbgPEClock(dec_clock_rate_hz);
-	dbgPEClock(bus_clock_rate_num);
-	dbgPEClock(bus_clock_rate_den);
-	dbgPEClock(bus_to_cpu_rate_num);
-	dbgPEClock(bus_to_cpu_rate_den);
-	dbgPEClock(bus_to_dec_rate_num);
-	dbgPEClock(bus_to_dec_rate_den);
-	dbgPEClock(timebase_frequency_hz);
-	dbgPEClock(timebase_frequency_num);
-	dbgPEClock(timebase_frequency_den);
-	dbgPEClock(bus_frequency_hz);
-	dbgPEClock(cpu_frequency_hz);
-}
-
-static void fixupPEClockFrequencyInfo(LogicalCPU &lc)
-{
-	// Setup gPEClockFrequencyInfo which seems to have mostly random values
-	gPEClockFrequencyInfo.timebase_frequency_hz = 1000000000;
-	gPEClockFrequencyInfo.bus_frequency_hz      =  100000000;
-	gPEClockFrequencyInfo.bus_frequency_min_hz = gPEClockFrequencyInfo.bus_frequency_hz;
-	gPEClockFrequencyInfo.bus_frequency_max_hz = gPEClockFrequencyInfo.bus_frequency_hz;
-	gPEClockFrequencyInfo.cpu_frequency_min_hz=lc.powerStates[lc.maxPowerStates-1].freq*1000000ULL;
-	gPEClockFrequencyInfo.cpu_frequency_max_hz=lc.powerStates[0].freq*1000000ULL;
-	gPEClockFrequencyInfo.cpu_frequency_hz=lc.powerStates[lc.currentState].freq*1000000ULL;
-	gPEClockFrequencyInfo.dec_clock_rate_hz = gPEClockFrequencyInfo.timebase_frequency_hz;
-	gPEClockFrequencyInfo.bus_clock_rate_hz = gPEClockFrequencyInfo.bus_frequency_hz;
-	gPEClockFrequencyInfo.cpu_clock_rate_hz = gPEClockFrequencyInfo.cpu_frequency_hz;
-	gPEClockFrequencyInfo.bus_clock_rate_num = gPEClockFrequencyInfo.bus_clock_rate_hz;
-	gPEClockFrequencyInfo.bus_clock_rate_den = 1;
-	gPEClockFrequencyInfo.bus_to_cpu_rate_num = (2 * gPEClockFrequencyInfo.cpu_clock_rate_hz) / gPEClockFrequencyInfo.bus_clock_rate_hz;
-	gPEClockFrequencyInfo.bus_to_cpu_rate_den = 2;
-	gPEClockFrequencyInfo.bus_to_dec_rate_num = 1;
-	gPEClockFrequencyInfo.bus_to_dec_rate_den = gPEClockFrequencyInfo.bus_clock_rate_hz / gPEClockFrequencyInfo.dec_clock_rate_hz;
-	//dbg("ACPICPUThrottle: gPEClockFrequencyInfo after fixup:\n");
-	//printPEClockFrequencyInfo();
-}
-
-static uint32_t determineRTCClockStepping(uint32_t newfreq, uint32_t basefreq)
-{
-	uint64_t rtc_cycle_count=(basefreq*1000000ULL)/20;
-	uint64_t newcount=rtc_cycle_count*newfreq/basefreq;
-	dbg("ACPICPUThrottle: rtc_cycle_count=%llu, newcount=%llu, cutoff=%llu\n", rtc_cycle_count, newcount, (1000000000ULL/20));
-    //return newcount;
-	if(newcount>(1000000000ULL/20))
-	{	// It uses quick algorithm (which works)
-		return newfreq;
-	}
-	else
-	{	// It uses slow algorithm (which does not work). Return the slowest the system can count.
-		return 1000;
-	}
-}
-
-static bool setCPU(LogicalCPU &lc, int powerstate)
-{
-	dbg("ACPICPUThrottle: Setting %s to powerstate %d\n", lc.cpudevice->getName(), powerstate);
-	if(powerstate<0) powerstate=0;
-	if(powerstate>=lc.maxPowerStates) powerstate=lc.maxPowerStates-1;
-	//if(powerstate==lc.currentState) return true;
-	fixupPEClockFrequencyInfo(lc);
-	rtc_clock_stepping(determineRTCClockStepping(lc.powerStates[powerstate].freq, lc.powerStates[0].freq), baseSystemFreq);
-	if(lc.regcontrol.bitwidth)
-	{
-		dbg("ACPICPUThrottle: Writing 0x%x width %u to 0x%llx\n", lc.powerStates[powerstate].control, lc.regcontrol.bitwidth, lc.regcontrol.address.addr64);
-		ERRH(lc.cpudevice->writeAddressSpace(lc.powerStates[powerstate].control, kIOACPIIORange,
-											 lc.regcontrol.address, lc.regcontrol.bitwidth));
-		UInt64 status;
-		for(int n=0; n<100; n++)
-		{
-			status=0;
-			ERRH(lc.cpudevice->readAddressSpace(&status, kIOACPIIORange,
-												lc.regstatus.address, lc.regstatus.bitwidth));
-			if(status==lc.powerStates[powerstate].status)
-			{
-				dbg("ACPICPUThrottle: Throttle succeeded!\n");
-				rtc_clock_stepped(determineRTCClockStepping(lc.powerStates[powerstate].freq, lc.powerStates[0].freq), baseSystemFreq);
-				lc.currentState=powerstate;
-				fixupPEClockFrequencyInfo(lc);
-				return true;
-			}
-			IODelay(10);
-		}
-		printf("ACPICPUThrottle: Throttle failed with status=0x%llx!\n", status);
-	}
-	else if(lc.useAMDDirectDrive)
-	{	// Direct drive. Copied straight from the FreeBSD driver.
-#if defined(__i386__) || defined(__amd64__)
-		int state;
-		u_int irt, rvo, pll, mvs, vst, vid, fid;
-		u_int val, rvo_steps, cur_vid, cur_fid, vco_fid, vco_cur_fid, vco_diff;
-		u_int64_t v64;
-		state = powerstate;
-			
-		v64 = lc.powerStates[state].control;
-		irt = control_irt(v64);
-		rvo = control_rvo(v64);
-		pll = control_pll(v64);
-		mvs = control_mvs(v64);
-		vst = control_vst(v64);
-		vid = control_vid(v64);
-		fid = control_fid(v64);
-			
-		READ_PENDING_WAIT(v64);
-		cur_vid = status_vid(v64);
-		cur_fid = status_fid(v64);
-		dbg("ACPICPUThrottle: Phase 1: cur_vid=0x%x, cur_fid=0x%x, wantvid=0x%x, wantfid=0x%x\n", cur_vid, cur_fid, vid, fid);
-				
-		/* Phase 1 */
-		while (cur_vid > vid) {
-			val = cur_vid - (1 << mvs);
-			write_fidvid(cur_fid, (val > 0) ? val : 0, 1ULL);
-			READ_PENDING_WAIT(v64);
-			cur_vid = status_vid(v64);
-			count_off_vst(vst);
-		}
-			
-		for (rvo_steps = rvo; rvo_steps > 0 && cur_vid > 0; rvo_steps--) {
-			write_fidvid(cur_fid, cur_vid - 1, 1ULL);
-			READ_PENDING_WAIT(v64);
-			cur_vid = status_vid(v64);
-			count_off_vst(vst);
-		}
-		dbg("ACPICPUThrottle: Phase 2: cur_vid=0x%x, cur_fid=0x%x, wantvid=0x%x, wantfid=0x%x\n", cur_vid, cur_fid, vid, fid);
-			
-		/* Phase 2 */
-		if (cur_fid != fid) {
-			vco_fid = FID_TO_VCO_FID(fid);
-			vco_cur_fid = FID_TO_VCO_FID(cur_fid);
-			vco_diff = (vco_cur_fid < vco_fid) ?
-				vco_fid - vco_cur_fid : vco_cur_fid - vco_fid;
-			while (vco_diff > 2) {
-				if (fid > cur_fid) {
-					if (cur_fid > 6)
-						val = cur_fid + 2;
-					else
-						val = FID_TO_VCO_FID(cur_fid) + 2;
-				} else {
-					val = cur_fid - 2;
-				}
-				write_fidvid(val, cur_vid, pll * 200ULL);
-				READ_PENDING_WAIT(v64);
-				cur_fid = status_fid(v64);
-				count_off_irt(irt);
-					
-				vco_cur_fid = FID_TO_VCO_FID(cur_fid);
-				vco_diff = (vco_cur_fid < vco_fid) ?
-					vco_fid - vco_cur_fid : vco_cur_fid - vco_fid;
-			}
-				
-			write_fidvid(fid, cur_vid, pll * 200ULL);
-			READ_PENDING_WAIT(v64);
-			cur_fid = status_fid(v64);
-			count_off_irt(irt);
-		}
-		dbg("ACPICPUThrottle: Phase 3: cur_vid=0x%x, cur_fid=0x%x, wantvid=0x%x, wantfid=0x%x\n", cur_vid, cur_fid, vid, fid);
-			
-		/* Phase 3 */
-		if (cur_vid != vid) {
-			write_fidvid(cur_fid, vid, 1ULL);
-			READ_PENDING_WAIT(v64);
-			cur_vid = status_vid(v64);
-			count_off_vst(vst);
-		}
-		dbg("ACPICPUThrottle: End    : cur_vid=0x%x, cur_fid=0x%x, wantvid=0x%x, wantfid=0x%x\n", cur_vid, cur_fid, vid, fid);
-			
-		/* Done */
-		if (cur_vid == vid && cur_fid == fid)
-		{
-			dbg("ACPICPUThrottle: Throttle succeeded with cur_vid=0x%x, cur_fid=0x%x, wantvid=0x%x, wantfid=0x%x!\n", cur_vid, cur_fid, vid, fid);
-			rtc_clock_stepped(determineRTCClockStepping(lc.powerStates[powerstate].freq, lc.powerStates[0].freq), baseSystemFreq);
-			lc.currentState=powerstate;
-			fixupPEClockFrequencyInfo(lc);
-			return true;
-		}
-		printf("ACPICPUThrottle: Throttle failed with cur_vid=0x%x, cur_fid=0x%x, wantvid=0x%x, wantfid=0x%x!\n", cur_vid, cur_fid, vid, fid);
-#endif	/* __i386__ || __amd64__ */
-	}
-	else if(lc.useIntelDirectDrive)
-	{
-#if defined(__i386__) || defined(__amd64__)
-		// Copied straight from the EnhancedSpeedStep driver
-		uint64_t msr, v64 = lc.powerStates[powerstate].control;
-		msr = rdmsr64(MSR_PERF_CTL);
-		msr = (msr & ~(uint64_t)(0xffff)) | v64;
-		wrmsr64(MSR_PERF_CTL, msr);
-        dbg("ACPICPUThrottle: status = %x", lc.powerStates[powerstate].status);
-		unsigned int inc=lc.powerStates[powerstate].tlat/10;
-		for(unsigned int n=0; n<=lc.powerStates[powerstate].tlat; n+=inc)
-		{
-			IODelay(inc);
-			msr = rdmsr64(MSR_PERF_STATUS) & 0xffff;
-			if(msr == lc.powerStates[powerstate].status)
-				break;
-		}
-		if(msr == lc.powerStates[powerstate].control)
-		{
-			dbg("ACPICPUThrottle: Throttle succeeded with cur_status=0x%x, want_status=0x%x!\n", msr, lc.powerStates[powerstate].status);
-			rtc_clock_stepped(determineRTCClockStepping(lc.powerStates[powerstate].freq, lc.powerStates[0].freq), baseSystemFreq);
-			lc.currentState=powerstate;
-			fixupPEClockFrequencyInfo(lc);
-			return true;
-		}
-		printf("ACPICPUThrottle: Throttle failed with cur_status=0x%x, want_status=0x%x!\n", msr, lc.powerStates[powerstate].status);
-#endif	/* __i386__ || __amd64__ */
-	}
-	return false;
-}
-static bool setCPUs(int powerstate)
-{
-	bool ret=true;
-	for(int n=0; logicalCPUs[n].active; n++)
-	{
-		ret=ret && setCPU(logicalCPUs[n], powerstate);
-	}
-	return ret;
-}
-
-static bool addCPU(LogicalCPU &lc, IOACPIPlatformDevice *cpu)
-{
-	OSObject *result;
-	printf("ACPICPUThrottle: Adding %s\n", cpu->getName());
-	lc.cpudevice=cpu;
-	
-	// Fetch 8.3.3.1 _PCT, returns OSArray
-	ERRH(cpu->evaluateObject("_PCT", &result));
-	if(!result)
-	{
-		printf("ACPICPUThrottle: This ACPI does not permit CPU throttling!\n");
-		return false;
-	}
-	OSObjPtr perfCtrl(result);			// Actually an OSArray
-	
-	// Get Performance Control Register
-	result=((OSArray *) *perfCtrl)->getObject(0);
-	if(!result) return false;
-	{	// Now result points to type OSData
-		OSData *d=(OSData *) result;
-		const ACPIResource *r=(const ACPIResource *) d->getBytesNoCopy();
-		dbg("ACPICPUThrottle: type=%x, datalen=%u, _ASI=%x, _RBW=%x, _RBO=%x, _ADR=%x\n",
-			r->type, r->dataitemlen, r->data.genericReg._ASI, r->data.genericReg._RBW, r->data.genericReg._RBO, r->data.genericReg._ADR);
-		if(!r || /* generic register */0x82!=r->type)
-			return false;
-		if(/* functional fixed hardware */0x7f==r->data.genericReg._ASI)
-		{	// Must direct drive
-			lc.regcontrol.bitwidth=0;
-			dbg("ACPICPUThrottle: ACPI returns no ACPI throttling available\n");
-		}
-		else
-		{
-			memcpy(&lc.regcontrol.address.addr64, &r->data.genericReg._ADR.addr64, 8);
-			memcpy(&lc.regcontrol.bitwidth, &r->data.genericReg._RBW, 2);
-			dbg("ACPICPUThrottle: PCR=0x%x width %u\n", lc.regcontrol.address.addr64, lc.regcontrol.bitwidth);
-		}
-	}
-	
-	// Get Performance Status Register
-	result=((OSArray *) *perfCtrl)->getObject(1);
-	if(!result) return false;
-	{	// Now result points to type OSData
-		OSData *d=(OSData *) result;
-		const ACPIResource *r=(const ACPIResource *) d->getBytesNoCopy();
-		dbg("ACPICPUThrottle: type=%x, datalen=%u, _ASI=%x, _RBW=%x, _RBO=%x, _ADR=%x\n",
-			r->type, r->dataitemlen, r->data.genericReg._ASI, r->data.genericReg._RBW, r->data.genericReg._RBO, r->data.genericReg._ADR);
-		if(!r || 0x82!=r->type) return false;
-		if(/* functional fixed hardware */0x7f==r->data.genericReg._ASI)
-		{	// Must direct drive
-			lc.regcontrol.bitwidth=0;
-			dbg("ACPICPUThrottle: ACPI returns no ACPI throttling available\n");
-		}
-		else
-		{
-			memcpy(&lc.regstatus.address.addr64, &r->data.genericReg._ADR.addr64, 8);
-			memcpy(&lc.regstatus.bitwidth, &r->data.genericReg._RBW, 2);
-			dbg("ACPICPUThrottle: PSR=0x%x width %u\n", lc.regstatus.address.addr64, lc.regstatus.bitwidth);
-		}
-	}
-
-	// Fetch 8.3.3.2 _PSS, returns OSArray
-	ERRH(cpu->evaluateObject("_PSS", &result));
-	if(!result) return false;
-	OSObjPtr perfStates(result);			// Actually an OSArray
-	OSArray *_perfStates=(OSArray *) *perfStates;
-	lc.maxPowerStates=_perfStates->getCount();
-	if(lc.maxPowerStates>sizeof(lc.powerStates)/sizeof(lc.powerStates[0]))
-		lc.maxPowerStates=sizeof(lc.powerStates)/sizeof(lc.powerStates[0]);
-	for(int n=0; n<lc.maxPowerStates; n++)
-	{
-		PowerState &powerState=lc.powerStates[n];
-		OSArray *ps=(OSArray *) _perfStates->getObject(n);
-		powerState.freq   =((OSNumber *) ps->getObject(0))->unsigned32BitValue();
-		powerState.power  =((OSNumber *) ps->getObject(1))->unsigned32BitValue();
-		powerState.tlat   =((OSNumber *) ps->getObject(2))->unsigned32BitValue();
-		powerState.bmlat  =((OSNumber *) ps->getObject(3))->unsigned32BitValue();
-		powerState.control=((OSNumber *) ps->getObject(4))->unsigned32BitValue();
-        powerState.original_control=powerState.control;
-		powerState.status =((OSNumber *) ps->getObject(5))->unsigned32BitValue();
-		
-		if(!powerState.freq)
-		{
-			lc.maxPowerStates=n;
-			break;
-		}
-		powerState.active=true;
-	}
-	// Now cull duplicates
-	for(int n=lc.maxPowerStates-1; n>0; n--)
-	{
-		if(lc.powerStates[n].control==lc.powerStates[n-1].control)
-		{
-			memmove(&lc.powerStates[n-1], &lc.powerStates[n], (lc.maxPowerStates-n)*sizeof(PowerState));
-			lc.maxPowerStates--;
-		}
-	}
-	// Generate sysctl list
-	char *sysctlend=frequencies;
-	int lastActive=lc.maxPowerStates;
-	for(int n=lc.maxPowerStates-1; n>=0; n--)
-	{
-		PowerState &powerState=lc.powerStates[n];
-		if(powerState.freq<=1000)
-		{
-			lastActive=n;
-			powerState.active=false;
-		}
-		else
-		{
-			sprintf(sysctlend, "%d ", lc.powerStates[n].freq);
-			sysctlend=strchr(sysctlend, 0);
-		}
-	}
-	*sysctlend++=10;
-	strcpy(sysctlend, "ACPICPUThrottle v1.1.0 (" __DATE__ ") (C) 2006 Niall Douglas\n"
-					  "(C) 2008 Prashant Vaibhav <mercurysquad@yahoo.com>\n");
-	sysctlend=strchr(sysctlend, 0);
-	for(int n=0; n<lc.maxPowerStates; n++)
-	{
-		PowerState &powerState=lc.powerStates[n];
-		if(!powerState.active)
-			sprintf(sysctlend, "P%u, %uMhz disabled\n", n, powerState.freq);
-		else
-			sprintf(sysctlend, "P%u, %uMhz, %umW, %uus, %uus (ctrl=0x%x, status=0x%x)\n", n,
-					powerState.freq, powerState.power, powerState.tlat, powerState.bmlat,
-					powerState.control, powerState.status);
-		printf("---> %s", sysctlend);
-		sysctlend=strchr(sysctlend, 0);
-	}
-	strcpy(sysctlend, "(CPU Powerstates under 1GHz are not available on MacOS X)\n");
-	lc.maxPowerStates=lastActive;
-	if(1==lc.maxPowerStates)
-	{
-		printf("ACPICPUThrottle: Only one available power state found (all states <=1Ghz are unavailable), exiting!\n");
-		return false;
-	}
-#if 0
-	printf("ACPICPUThrottle: DEBUG VERSION FORCING DIRECT DRIVE!\n");
-	lc.regcontrol.bitwidth=0;
-#endif
-	if(lc.regcontrol.bitwidth)
-	{
-		printf("ACPICPUThrottle: Using ACPI BIOS to throttle CPU\n");
-	}
-	else
-	{	// There are no ACPI throttle control registers. Must therefore direct drive if possible
-#if defined(__i386__) || defined(__amd64__)
-		i386_cpu_info_t *info = cpuid_info();
-		if (strncmp(info->cpuid_vendor, "AuthenticAMD", 12) == 0) {
-			dbg("ACPICPUThrottle: AMD processor detected, family=%x, model=%x\n", info->cpuid_family, info->cpuid_model);
-			if(0xF==info->cpuid_family && info->cpuid_model>=0x4)
-			{
-				u_int regs[4];
-				do_cpuid(0x80000000, regs);
-				if (regs[0] < 0x80000007)	/* EAX[31:0] */
-					return false;
-				do_cpuid(0x80000007, regs);
-				if ((regs[3] & 0x6) != 0x6)	/* EDX[2:1] = 11b */
-					return false;
-				printf("ACPICPUThrottle: Using direct drive of AMD K8 throttling\n");
-				lc.useAMDDirectDrive=true;
-				goto allgood;
-			}
-		}
-		if (strncmp(info->cpuid_vendor, "GenuineIntel", 12) == 0) {
-			dbg("ACPICPUThrottle: Intel processor detected, family=%x, model=%x\n", info->cpuid_family, info->cpuid_model);
-			if(0x6==info->cpuid_family || 0xF==info->cpuid_family)
-			{
-				u_int regs[4];
-				do_cpuid(1, regs);
-				if ((regs[2] & 0x80) == 0)
-					return false;
-				printf("ACPICPUThrottle: Using direct drive of Intel throttling\n");
-				lc.useIntelDirectDrive=true;
-				goto allgood;
-			}
-		}
-#endif	/* __i386__ || __amd64__ */
-		printf("ACPICPUThrottle: No method available to throttle CPU, exiting!\n");
-		return false;
-	}
-allgood:
-	// Determine what the system is currently running at
-	lc.currentState=-1;
-	uint32_t diff=1<<30;
-	for(int n=0; n<sizeof(lc.powerStates)/sizeof(lc.powerStates[0]); n++)
-	{
-		PowerState &powerState=lc.powerStates[n];
-		//printf("diff=%ld\n", abs(powerState.freq-gPEClockFrequencyInfo.cpu_frequency_hz/1000000ULL));
-		if(powerState.freq && abs(powerState.freq-gPEClockFrequencyInfo.cpu_frequency_hz/1000000ULL)<diff)
-		{
-			lc.currentState=n;
-			baseSystemFreq=powerState.freq;
-			diff=abs(powerState.freq-gPEClockFrequencyInfo.cpu_frequency_hz/1000000ULL);
-		}
-	}
-	if(diff>=50) lc.currentState=-1;
-	if(-1==lc.currentState)
-	{
-		printf("ACPICPUThrottle: Failed to determine current system speed (no match to %llu)!\n", gPEClockFrequencyInfo.cpu_frequency_hz/1000000ULL);
-		return false;
-	}
-		
-	if(!setCPU(lc, lc.maxPowerStates-1))
-	{	// Failed to set, so don't activate
-		return true;
-	}
-
-	//dbg("ACPICPUThrottle: first item is metaclass of %s\n", result->getMetaClass()->getClassName());
-	
-	lc.active=true;
-	return true;
-}
-
-int find_closest_pstate(int MHz_wanted) {
-    // finds the P-state which has a frequency closest to the supplied frequency
-    int pstate, bestdiff=1<<30;
-    for(int n=0; n<logicalCPUs[0].maxPowerStates; n++)
-    {
-        PowerState &ps=logicalCPUs[0].powerStates[n];
-        if(abs(MHz_wanted-(int) ps.freq)<bestdiff)
-        {
-            pstate=n;
-            bestdiff=abs(MHz_wanted-(int) ps.freq);
-        }
-    }
-    return pstate;
-}
-
-
-/**********************************************************************/
-
-static int cputhrottle_sysctl_mhz SYSCTL_HANDLER_ARGS
-{
-	int err=0;
-	if(req->newptr)
-	{
-		int pstate, MHz_wanted;
-		err = SYSCTL_IN(req, &MHz_wanted, sizeof(int));
-		if (err)
-			return err;
-		if(MHz_wanted<16)
-		{	// pstate specified directly
-			pstate=MHz_wanted;
-		}
-		else
-		{   // freq in mhz is given, find closest pstate
-            pstate = find_closest_pstate(MHz_wanted);
-		}
-		setCPUs(pstate);
-	}
-	else
-	{
-		int MHz=logicalCPUs[0].powerStates[logicalCPUs[0].currentState].freq;
-		err = SYSCTL_OUT(req, &MHz, sizeof(int));
-	}
-	return err;
-}
-
-void setFIDVID(int FID_wanted, int VID_wanted, bool setCPUAlso) {
-    // modifies the "control" parameter of a pstate to set the given VID for this FID
-    // if setCPUAlso is true, it will also immediately update the current CPU state
-    // find the pstate for this FID.
-    for (int i = 0; i < logicalCPUs[0].maxPowerStates; i++) {
-        PowerState &ps = logicalCPUs[0].powerStates[i];
-        if (FID_wanted == (ps.control & INTEL_MSR_FID_MASK)) {
-            // found the proper pstate, now update its voltage if it's not higher than default
-            if (VID_wanted <= (ps.original_control & INTEL_MSR_VID_MASK))
-            {   // this is fine to set.
-                ps.control = (FID_wanted | VID_wanted);
-                // and now actually set the CPUs
-                dbg("ACPICPUThrottle: FID=%u being set to VID=%u, status=%x\n", FID_wanted >> 8, VID_wanted, ps.status);
-                if (setCPUAlso) setCPUs(find_closest_pstate(ps.freq));
-                break;
-            } else {
-                // this is higher than default, we won't change it
-                dbg("ACPICPUThrottle: VID=%u is higher than default, not changing!\n", VID_wanted);
-            }
-        }
-    }
-    
-}
-
-static int cputhrottle_sysctl_vid SYSCTL_HANDLER_ARGS
-{
-    // For reading/writing the voltage multiplier sysctl on intel
-    if (!logicalCPUs[0].useIntelDirectDrive)
-        return -1; // return with error if it's not intel
-    
-	int err=0;
-	if(req->newptr)
-	{
-        // to set a FID/VID
-        int CTL_wanted = 0, FID_wanted = 0, VID_wanted;
-        err = SYSCTL_IN(req, &CTL_wanted, sizeof(int));
-        FID_wanted = CTL_wanted & INTEL_MSR_FID_MASK;
-        VID_wanted = CTL_wanted & INTEL_MSR_VID_MASK;
-        setFIDVID(FID_wanted, VID_wanted, true);
-	}
-	else
-	{
-        // to get the current FID/VID of the first logical processor
-        int FIDVID=logicalCPUs[0].powerStates[logicalCPUs[0].currentState].control;
-		err = SYSCTL_OUT(req, &FIDVID, sizeof(int));
-	}
-	return err;
-}
-
-/*void load_vidsettings_from_plist() {
-    // this tries to load any VID settings for the pstates by looking in the Info.plist file
-    OSArray* vids = (OSArray*) getProperty("VIDSettings");
-    if (!vids) {
-        dbg("ACPICPUThrottle: No VIDs specified in Info.plist, using safe factory default voltages.\n");
-        return;
-    }
-    
-    int FID, VID;
-    
-    for (int pstate = 0; pstate < (vids->getCount()); pstate++) {
-        uint32_t voltage = ((OSNumber*) vids->getObject(pstate))->unsigned32BitValue();
-        if (!voltage) continue; // if no valid number specified, move on
-        FID = (logicalCPUs[0].powerStates[pstate].control) & INTEL_MSR_FID_MASK;
-        VID = (voltage - 700) / 16; // formula to get VID from voltage [for intel cpus]
-        setFIDVID(FID, VID, false);
-    }
-}*/
-
-SYSCTL_INT(_kern, OID_AUTO, cputhrottle_verbose, CTLFLAG_RW, &verbose,
-		   0, "Log CPU frequency changes");
-SYSCTL_PROC(_kern, OID_AUTO, cputhrottle_curfreq, CTLTYPE_INT | CTLFLAG_RW, 0, 0,
-			&cputhrottle_sysctl_mhz, "I", "Current CPU frequency");
-SYSCTL_PROC(_kern, OID_AUTO, cputhrottle_vid    , CTLTYPE_INT | CTLFLAG_RW, 0, 0,
-            &cputhrottle_sysctl_vid, "I", "Current CPU voltage multiplier");
-SYSCTL_STRING(_kern, OID_AUTO, cputhrottle_freqs, CTLFLAG_RD, frequencies, 0,
-			  "CPU frequencies supported");
-
-extern "C" kern_return_t ACPICPUThrottle_start (kmod_info_t * ki, void * d) {
-	dbg("ACPI CPU Throttle loaded\n");
-	//printPEClockFrequencyInfo();
-	const IORegistryPlane *IODeviceTree=IORegistryEntry::getPlane("IODeviceTree");
-	if(!IODeviceTree) return KERN_FAILURE;
-	
-	// Firstly, let's see what CPUs we have
-	IORegPtr cpus(IORegistryEntry::fromPath("/cpus", IODeviceTree));
-	if(!cpus) return KERN_FAILURE;
-	IORegistryEntry *cpu;
-	int n=0, i=0;
-	for(IORegIt it(cpus, IODeviceTree); cpu=it->getCurrentEntry(); it->getNextObjectFlat(), n++)
-	{	// Sadly OSDynamicCast is not available to us
-		if(n && i<sizeof(logicalCPUs)/sizeof(LogicalCPU))
-		{
-			if(addCPU(logicalCPUs[i], static_cast<IOACPIPlatformDevice *>(cpu)))
-				i++;
-		}
-	}
-	if(!logicalCPUs[0].active)
-	{
-		printf("ACPICPUThrottle: No valid CPUs returned by ACPI! It's possible your BIOS "
-			   "does not think your system should be throttled and therefore did not "
-			   "return any available power states, or maybe your CPU only supports one "
-			   "other power state than maximum which is below 1Ghz!\n");
-		return KERN_FAILURE;
-	}
-
-	/* Register our SYSCTL */
-	sysctl_register_oid(&sysctl__kern_cputhrottle_curfreq); 
-	sysctl_register_oid(&sysctl__kern_cputhrottle_verbose); 
-	sysctl_register_oid(&sysctl__kern_cputhrottle_freqs);
-	sysctl_register_oid(&sysctl__kern_cputhrottle_vid);
-    dbg("ACPICPUThrottle: Loading voltage values from Info.plist\n");
-    /*load_vidsettings_from_plist();*/
-    return KERN_SUCCESS;
-}
-
-
-extern "C" kern_return_t ACPICPUThrottle_stop (kmod_info_t * ki, void * d) {
-	setCPUs(0);
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_curfreq); 
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_verbose); 
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_freqs);
-    sysctl_unregister_oid(&sysctl__kern_cputhrottle_vid);
-	dbg("ACPI CPU Throttle unloaded\n");
-    return KERN_SUCCESS;
-}

File IntelEnhancedSpeedStep/.hgignore

-syntax: glob
-*.kext
-.DS_Store
-.o
-._*
-build/*

File IntelEnhancedSpeedStep/English.lproj/InfoPlist.strings

Binary file removed.

File IntelEnhancedSpeedStep/Info.plist

-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>${EXECUTABLE_NAME}</string>
-	<key>CFBundleName</key>
-	<string>${PRODUCT_NAME}</string>
-	<key>CFBundleIconFile</key>
-	<string></string>
-	<key>CFBundleIdentifier</key>
-	<string>net.mercurysquad.driver.${PRODUCT_NAME:identifier}</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundlePackageType</key>
-	<string>KEXT</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>1.4.0</string>
-	<key>IOKitPersonalities</key>
-	<dict>
-		<key>IntelEnhancedSpeedStep</key>
-		<dict>
-			<key>DebugMessages</key>
-			<false/>
-			<key>KernelFeatures</key>
-			<integer>-1</integer>
-			<key>DefaultPState</key>
-			<integer>-1</integer>
-			<key>PStateTableDisabled</key>
-			<array>
-				<array>
-					<integer>1733</integer>
-					<integer>1100</integer>
-				</array>
-				<array>
-					<integer>1333</integer>
-					<integer>860</integer>
-				</array>
-				<array>
-					<integer>1067</integer>
-					<integer>780</integer>
-				</array>
-				<array>
-					<integer>800</integer>
-					<integer>716</integer>
-				</array>
-			</array>
-			<key>CFBundleIdentifier</key>
-			<string>net.mercurysquad.driver.${PRODUCT_NAME:identifier}</string>
-			<key>IOClass</key>
-			<string>net_mercurysquad_driver_${PRODUCT_NAME:identifier}</string>
-			<key>IOKitDebug</key>
-			<integer>0</integer>
-			<key>IOMatchCategory</key>
-			<string>net_mercurysquad_driver_${PRODUCT_NAME:identifier}</string>
-			<key>IOProviderClass</key>
-			<string>IOResources</string>
-			<key>IOResourceMatch</key>
-			<string>IOKit</string>
-		</dict>
-	</dict>
-	<key>OSBundleLibraries</key>
-	<dict>
-		<key>com.apple.kernel.bsd</key>
-		<string>7.9.9</string>
-		<key>com.apple.kpi.unsupported</key>
-		<string>8.4.1</string>
-		<key>com.apple.kpi.bsd</key>
-		<string>8.4.1</string>
-		<key>com.apple.kernel.mach</key>
-		<string>7.9.9</string>
-		<key>com.apple.kpi.iokit</key>
-		<string>8.4.1</string>
-		<key>com.apple.kpi.libkern</key>
-		<string>8.4.1</string>
-	</dict>
-</dict>
-</plist>

File IntelEnhancedSpeedStep/IntelEnhancedSpeedStep.cpp

-extern "C" {
-#include <pexpert/pexpert.h>
-}
-
-#define super IOService
-
-#include "IntelEnhancedSpeedStep.h"
-#include "Utility.h"
-
-
-OSDefineMetaClassAndStructors(net_mercurysquad_driver_IntelEnhancedSpeedStep, IOService)
-
-
-/**********************************************************************************/
-/* sysctl interface for compatibility with Niall Douglas' ACPICPUThrottle.kext    */
-
-static int iess_handle_curfreq SYSCTL_HANDLER_ARGS
-{
-	int err = 0;
-	if (req->newptr) {
-		// New freq being set
-		int pstate, wantedFreq;
-		err = SYSCTL_IN(req, &wantedFreq, sizeof(int));
-		if (err) return err;
-		
-		if (wantedFreq < 16 && wantedFreq < NumberOfPStates) // pstate specified directly
-			pstate = wantedFreq;
-		else // freq in MHz is given, find closest pstate
-			pstate = FindClosestPState(wantedFreq);
-		
-		dbg("Throttling to PState %d\n", pstate);
-		throttleAllCPUs(PStates[pstate]);
-
-	} else { // just reading
-		int MHz = PStates[FindClosestPState(getCurrentFrequency())].AcpiFreq;
-		err = SYSCTL_OUT(req, &MHz, sizeof(int));
-	}
-	
-	return err;
-}
-
-static int iess_handle_curvolt SYSCTL_HANDLER_ARGS
-{
-	int err = 0;
-	if (req->newptr) {
-		// New voltage being set
-		int wantedvolt;
-		err = SYSCTL_IN(req, &wantedvolt, sizeof(int));
-		if (err) return err;
-		int pstate   = FindClosestPState(getCurrentFrequency());
-		int origvolt = VID_to_mV(PStates[pstate].OriginalVoltage);
-		if (wantedvolt > origvolt+100) {
-			wantedvolt = origvolt;
-			warn("Will not set voltage more than 100 mV higher than factory spec %d mV\n", origvolt);
-		}
-		dbg("Changing voltage of current PState %d to %d mV\n", pstate, wantedvolt);
-		PStates[pstate].Voltage = mV_to_VID(wantedvolt);
-		throttleAllCPUs(PStates[pstate]);
-	
-	} else { // just reading
-		int volt = getCurrentVoltage();
-		err = SYSCTL_OUT(req, &volt, sizeof(int));
-	}
-	
-	return err;
-}
-
-static int iess_handle_ctl SYSCTL_HANDLER_ARGS
-{
-	int err = 0;
-	if (req->newptr) {
-		// new ctl being set
-		warn("Use of kern.cputhrottle_ctl is only for debugging."
-		     "Use wisely - no validation is done!\n");
-		int ctl;
-		err = SYSCTL_IN(req, &ctl, sizeof(int));
-		if (err) return err;
-		dbg("Manual stepping to %xh\n", ctl);
-		
-		PState p; p.Frequency = FID(ctl); p.Voltage = VID(ctl);
-		throttleAllCPUs(p);
-		
-	} else {
-		int ctl = rdmsr64(INTEL_MSR_PERF_STS);
-		ctl &= 0xffff; // only last 32 bits
-		err = SYSCTL_OUT(req, &ctl, sizeof(int));
-	}
-	return err;
-}
-
-SYSCTL_PROC  (_kern, OID_AUTO, cputhrottle_curfreq, CTLTYPE_INT | CTLFLAG_RW, 0, 0, &iess_handle_curfreq, "I", "Current CPU frequency");
-SYSCTL_PROC  (_kern, OID_AUTO, cputhrottle_curvolt, CTLTYPE_INT | CTLFLAG_RW, 0, 0, &iess_handle_curvolt, "I", "Current CPU voltage");
-SYSCTL_PROC  (_kern, OID_AUTO, cputhrottle_ctl,     CTLTYPE_INT | CTLFLAG_RW, 0, 0, &iess_handle_ctl,     "I", "Current MSR status");
-SYSCTL_STRING(_kern, OID_AUTO, cputhrottle_freqs,   CTLFLAG_RD, frequencyList, 0, "CPU frequencies supported");
-SYSCTL_STRING(_kern, OID_AUTO, cputhrottle_factoryvolts, CTLFLAG_RD, originalVoltages, 0, "Factory default voltages for each frequency");
-
-
-/******* Helper functions for sysctl interface *********/
-
-/* Return null terminated list of frequencies */
-char* getFreqList() {
-	// Makes a list of space separated frequencies supported by the CPU
-	// Each frequency can occupy 4 digits, plus a space
-	char* freqs = new char[5 * NumberOfPStates];
-	int c = 0;
-	for (int i = NumberOfPStates-1; i >= 0; i--) {
-		sprintf((freqs + c), "%d ", PStates[i].AcpiFreq);
-		// Advance by 5 places if freq was of 4 digits
-		if (PStates[i].AcpiFreq >= 1000)
-			c += 5;
-		else // otherwise 4 places
-			c += 4;
-	}
-	// Set last char (which would be a space) to null
-	freqs[c] = '\0';
-	return freqs;
-}
-
-/* Return null terminated list of voltages */
-char* getVoltageList(bool originals) {
-	char* volts = new char[5 * NumberOfPStates];
-	int c = 0, svolt = 0;
-	for (int i = NumberOfPStates-1; i >= 0; i--) {
-		svolt = originals ? VID_to_mV(PStates[i].OriginalVoltage) : VID_to_mV(PStates[i].Voltage);
-		sprintf((volts + c), "%d ", svolt);
-		// Advance by 5 places if voltage was of 4 digits
-		if (svolt >= 1000)
-			c += 5;
-		else // otherwise 4 places
-			c += 4;
-	}
-	// Set last char (which would be a space) to null
-	volts[c] = '\0';
-	return volts;
-}
-
-int FindClosestPState(int wantedFreq) {
-	// assume P0 is best
-	int bestpstate = 0;
-	int bestdiff   = abs(PStates[0].AcpiFreq - wantedFreq);
-	
-	// now iterate over others and find the best
-	for (int i = 1; i < NumberOfPStates; i++) {
-		if (abs(PStates[i].AcpiFreq - wantedFreq) < bestdiff) {
-			bestpstate = i;
-			bestdiff = abs(PStates[i].AcpiFreq - wantedFreq);
-		}
-	}
-	
-	return bestpstate;
-}
-
-
-/***************************************************************************************************/
-
-bool net_mercurysquad_driver_IntelEnhancedSpeedStep::init(OSDictionary* dict) {
-	bool res = super::init(dict);
-	info("Initializing version 1.4.0 (C) Prashant Vaibhav <mercurysquad@yahoo.com>\n");
-	/* Allocate our spinlock for later use */
-	Lock = IOSimpleLockAlloc();
-	/* Check for a patched kernel which properly implements rtc_clock_stepped() */
-	uint64_t magic = -1; // means autodetect
-	
-	OSBoolean* debugMsgs = (OSBoolean*) dict->getObject("DebugMessages");
-	if (debugMsgs != 0)
-		DebugOn = debugMsgs->getValue();
-	else
-		DebugOn = false;
-	
-	OSNumber* kernelFeatures = (OSNumber*) dict->getObject("KernelFeatures");
-	if (kernelFeatures != 0)
-		magic = kernelFeatures->unsigned8BitValue();
-	
-	if (magic == 255) nanoseconds_to_absolutetime(~(0), &magic); //255uint = -1 int
-	
-	if (magic == 1) {
-		RtcFixKernel = true;
-		Below1Ghz	= false;
-	} else if (magic == 2) {
-		RtcFixKernel = true;
-		Below1Ghz	= true;
-	} else if (magic == 3) {
-		RtcFixKernel = false;
-		Below1Ghz = true;
-	} else {
-		RtcFixKernel = false;
-		Below1Ghz	= false;
-	}
-	
-	checkForNby2Ratio(); // check and store in global variable before loading pstate override
-	if (getFSB() == false)
-		return false;
-	
-	OSArray* overrideTable = (OSArray*) dict->getObject("PStateTable");
-	if (overrideTable != 0)
-		loadPStateOverride(overrideTable);
-	
-	OSNumber* defaultState = (OSNumber*) dict->getObject("DefaultPState");
-	if (defaultState != 0)
-		DefaultPState = defaultState->unsigned8BitValue();
-	else
-		DefaultPState = -1; // indicate no default state
-
-	OSNumber* maxLatency = (OSNumber*) dict->getObject("Latency");
-	if (maxLatency != 0)
-		MaxLatency = maxLatency->unsigned32BitValue();
-	else
-		MaxLatency = 0; // indicate no default state
-	
-	/* Return whatever the superclass returned */
-	return res;
-}
-
-void net_mercurysquad_driver_IntelEnhancedSpeedStep::free(void) {
-	dbg("Freeing driver resources\n");
-	/* Deallocate the previously allocated spinlock */
-	IOSimpleLockFree(Lock);
-	super::free();
-}
-
-IOService* net_mercurysquad_driver_IntelEnhancedSpeedStep::probe(IOService* provider, SInt32* score) {
-	IOService* res = super::probe(provider, score);
-	dbg("Probing for Intel processor...\n");
-	
-	/* Make preliminary check */
-	if ( (strcmp(cpuid_info()->cpuid_vendor, CPUID_VID_INTEL) == 0) // Check it's actually Intel
-	&& ( cpuid_info()->cpuid_features & CPUID_FEATURE_EST) ) { // Check it supports EST
-		*score += 1000;
-		dbg("Supported Intel processor found on your system\n");
-		res = this;
-	} else {
-		warn("No Intel processor found! You have %s. Kext will not load\n", cpuid_info()->cpuid_vendor);
-		res = NULL;
-	}
-	
-	if (!isConstantTSC()) {
-		ConstantTSC = false;
-		if (RtcFixKernel)
-			info("Your processor doesn't support constant_tsc, but you have a kernel which can compensate for it.\n");
-		else
-			warn("Your processor doesn't support constant_tsc and your kernel doesn't know how to compensate - Expect timing issues or switch to a kernel with RTC fix.\n");
-	} else {
-		ConstantTSC = true;
-		Below1Ghz = true; // blindly, because we're not gonna recalibrate the clock so no fear of panic
-	}
-	
-	return res;
-}
-
-bool net_mercurysquad_driver_IntelEnhancedSpeedStep::start(IOService *provider) {
-	bool res = super::start(provider);
-	if (!res) return false;
-	
-	dbg("Starting\n");
-	
-	/* Create PState tables */
-	if (!createPStateTable(PStates, &NumberOfPStates))
-		return false;
-	
-	// Set the frequency list for sysctl
-	strcpy(frequencyList, getFreqList());
-	strcpy(originalVoltages, getVoltageList(true));
-	
-	sysctl_register_oid(&sysctl__kern_cputhrottle_curfreq); 
-	sysctl_register_oid(&sysctl__kern_cputhrottle_curvolt);
-	sysctl_register_oid(&sysctl__kern_cputhrottle_freqs);
-	sysctl_register_oid(&sysctl__kern_cputhrottle_factoryvolts);
-	sysctl_register_oid(&sysctl__kern_cputhrottle_ctl);
-	
-	if (DefaultPState != -1 && DefaultPState < NumberOfPStates) // If a default Pstate was specified in info.plist
-	{
-		info("Throttling to default PState %d as specified in Info.plist\n", DefaultPState);
-		throttleAllCPUs(PStates[DefaultPState]); // then throttle to that value
-	}
-	
-	// Now turn on our auto-throttler
-	if (Throttler.setup(this) == false)
-		warn("Auto-throttler could not be setup\n");
-	else
-		Throttler.setEnabled(true);
-	
-	return true;
-}
-
-void net_mercurysquad_driver_IntelEnhancedSpeedStep::stop(IOService *provider) {
-	dbg("Shutting down\n");
-	
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_curfreq); 
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_freqs);
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_curvolt);
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_factoryvolts);
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_ctl);	
-	
-	super::stop(provider);
-}
-
-bool isConstantTSC() {
-	/* Check for constant_tsc by getting family, model, stepping */
-	/* Ref http://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits 
-	 * And http://www.intel.com/assets/pdf/appnote/241618.pdf
-	 */
-	uint8_t cpumodel = (cpuid_info()->cpuid_extmodel << 4) + cpuid_info()->cpuid_model;
-	uint8_t cpufamily = cpuid_info()->cpuid_family;
-	dbg("Processor Family %d, Model %d\n", cpufamily, cpumodel);
-	if ((cpufamily == 0x6 && cpumodel < 14) // 13 is pentium M, 14+ is core and above
-	|| ( cpufamily == 0xf && cpumodel < 3)) // 0xF is pentium 4, less than model 3 dont support constant tsc
-		// Ref - http://www.tomshardware.com/forum/128629-28-intel
-		return false;
-	else
-		return true;
-}
-
-void checkForPenryn() {
-	uint8_t cpumodel = (cpuid_info()->cpuid_extmodel << 4) + cpuid_info()->cpuid_model;
-	Is45nmPenryn = (cpuid_info()->cpuid_family == 6) && (cpumodel >= 0x17);
-	if (Is45nmPenryn)
-		info("On your processor, voltages can be changed in 12.5 mV steps\n");
-	else
-		info("On your processor, voltages can be changed in 16 mV steps\n");
-}
-
-void checkForNby2Ratio() {
-	uint64_t sts;
-	sts = rdmsr64(INTEL_MSR_PERF_STS);
-	Nby2Ratio = (sts & 0x400000000000ULL); // bit 46 is set
-}
-
-uint16_t getCurrentVoltage() {
-	// Apple recommends not to return cached value, but to read it from the processor
-	uint64_t msr = rdmsr64(INTEL_MSR_PERF_STS);
-	return VID_to_mV(VID(msr));
-}
-
-uint16_t getCurrentFrequency() {
-	uint64_t msr = rdmsr64(INTEL_MSR_PERF_STS);
-	return FID_to_MHz(FID(msr));
-}
-
-uint16_t VID_to_mV(uint8_t VID) {
-	if (Is45nmPenryn)
-		return (((int)VID * 125) + 7125) / 10; // to avoid using float
-	else
-		return (((int)VID * 16) + 700);
-}
-
-uint8_t mV_to_VID(uint16_t mv) {
-	if (Is45nmPenryn)
-		return ((mv * 10) - 7125) / 125;
-	else
-		return (mv - 700) / 16;
-}
-
-inline uint16_t FID_to_MHz(uint8_t x) {
-	bool nby2 = x & 0x80;
-	uint8_t realfid = x & 0x7f; // removes the bit from 0x80
-	if (nby2)
-		realfid /= 2;
-	return realfid * (FSB / 1000000ULL);
-}
-
-inline uint8_t MHz_to_FID(uint16_t x) {
-	uint8_t realfid = x / (FSB / 1000000ULL);
-	if (Nby2Ratio && x < 1000) // FIXME: use n/2 for only <1ghz frequencies?
-		realfid = (realfid*2) | 0x80;
-	return realfid;
-}
-
-void loadPStateOverride(OSArray* dict) {
-	/* Here we load the override pstate table from the given array */
-	NumberOfPStates = dict->getCount();
-	for (int i = 0; i < NumberOfPStates; i++) {
-		OSArray* onePstate			= (OSArray*) dict->getObject(i);
-		PStates[i].AcpiFreq			= ((OSNumber*) onePstate->getObject(0))->unsigned16BitValue();
-		PStates[i].Frequency		= MHz_to_FID(PStates[i].AcpiFreq); // this accounts for N/2 automatically
-		PStates[i].OriginalVoltage	= mV_to_VID(((OSNumber*) onePstate->getObject(1))->unsigned16BitValue());
-		PStates[i].Voltage			= PStates[i].OriginalVoltage;
-		dbg("P-State %d: %d MHz at %d mV\n", i, PStates[i].AcpiFreq, VID_to_mV(PStates[i].OriginalVoltage));
-	}
-	info("Loaded %d PStates from Info.plist\n", NumberOfPStates);
-}
-
-bool getFSB() {
-	FSB = 0;
-	IORegistryEntry* efi = IORegistryEntry::fromPath("/efi/platform", IORegistryEntry::getPlane("IODeviceTree"));
-	if (efi == 0) {
-		warn("EFI registry entry not found!\n");
-		return false;
-	}
-	OSData* fsb = (OSData*) efi->getProperty("FSBFrequency");
-	if (fsb == 0) {
-		warn("FSB frequency entry not found!\n");
-		return false;
-	}
-	bcopy(fsb->getBytesNoCopy(), &FSB, 8);
-	dbg("FSB = %d MHz\n", FSB/1000000ULL);
-	efi = 0; fsb = 0; // in dono ka kaam khatam	
-	return true;
-}
-
-bool createPStateTable(PState* pS, unsigned int* numStates) {	
-	checkForPenryn(); // early on, so we can display proper mV values
-	
-	/* If the PState table was specified manually, we dont do the rest. Otherwise autodetect */
-	if (NumberOfPStates != 0) {
-		dbg("PState table was already created. No autodetection will be performed\n");
-		return true;
-	}
-	
-	/* Find CPUs in the IODeviceTree plane */
-	IORegistryEntry* ioreg = IORegistryEntry::fromPath("/cpus", IORegistryEntry::getPlane("IODeviceTree"));
-	if (ioreg == 0) {
-		warn("Holy moly we cannot find your CPU!\n");
-		return false;
-	}
-	
-	/* Get the first CPU - we assume all CPUs share the same P-State */
-	IOACPIPlatformDevice* cpu = (IOACPIPlatformDevice*) ioreg->getChildEntry(IORegistryEntry::getPlane("IODeviceTree"));
-	if (cpu == 0) {
-		warn("Um you don't seem to have a CPU o.O\n");
-		ioreg = 0;
-		return false;
-	}
-	
-	dbg("Using data from %s\n", cpu->getName());
-	
-	/* Now try to find the performance state table */
-	OSObject* PSS;
-	cpu->evaluateObject("_PSS", &PSS);
-	if(PSS == 0) {
-		warn("There was an error while getting PState array from ACPI. Please create your P-State table manually.\n");
-		return false;
-	}
-	
-	OSArray* PSSArray = (OSArray*) PSS;
-	NumberOfPStates = PSSArray->getCount();
-	dbg("Found %d P-States\n", NumberOfPStates);
-	OSArray* onestate; uint16_t ctl, acpifreq; uint32_t power, latency;
-	int i = 0, c = 0;
-	
-	while (c < PSSArray->getCount()) {
-		onestate = ( OSArray* )(PSSArray->getObject(c));
-		ctl		 = ((OSNumber*) onestate->getObject(4))->unsigned32BitValue();
-		acpifreq = ((OSNumber*) onestate->getObject(0))->unsigned32BitValue();
-		power	 = ((OSNumber*) onestate->getObject(1))->unsigned32BitValue();
-		latency	 = ((OSNumber*) onestate->getObject(2))->unsigned32BitValue();
-		c++;
-		
-		if (acpifreq - (10 * (acpifreq / 10)) == 1) {
-			// most likely spurious, so skip it
-			warn("** Spurious P-State %d: %d MHz at %d mV, consuming %d W, latency %d usec\n", i, acpifreq, VID_to_mV(ctl), power / 1000, latency);
-			NumberOfPStates--;
-			continue;
-		}
-		
-		if (acpifreq < 1000 && !Below1Ghz) {
-			warn("%d MHz disabled because your processor or kernel doesn's support it.\n");
-			NumberOfPStates--;
-			continue;
-		}
-		
-		PStates[i].AcpiFreq			= acpifreq; // cosmetic only
-		PStates[i].Frequency		= FID(ctl); // if it's N/2 then this will be (x*2 | 80h) already.
-		PStates[i].OriginalVoltage	= VID(ctl);
-		PStates[i].Voltage			= PStates[i].OriginalVoltage; // initially same
-		PStates[i].Latency			= latency;
-		
-		if (latency > MaxLatency) MaxLatency = latency; 
-		
-		dbg("P-State %d: %d MHz at %d mV, consuming %d W, latency %d usec\n", i, PStates[i].AcpiFreq, VID_to_mV(PStates[i].OriginalVoltage), power / 1000, latency);
-		i++;
-	}
-	
-	info("Using %d PStates.\n", NumberOfPStates);
-	
-	ioreg = 0; cpu = 0; PSS = 0; onestate = 0;
-	return true;
-}
-
-/**************************************************************************************************/
-/* Throttling functions */
-
-void throttleAllCPUs(PState p) {
-	dbg("Starting throttle with CTL 0x%x\n", CTL(p.Frequency, p.Voltage));
-	IOSimpleLockLock(Lock);
-	
-	mp_rendezvous(disableInterrupts, throttleCPU, enableInterrupts, &p);
-	
-	IOSimpleLockUnlock(Lock);
-	dbg("Throttle done.\n");
-}
-
-void throttleCPU(void *t) {
-	uint64_t msr;
-	PState p;
-	uint32_t newfreq, oldfreq;
-
-	bcopy(t,&p,sizeof(PState)); // get the ctl we want
-	
-	msr = rdmsr64(INTEL_MSR_PERF_STS); // read current MSR
-	
-	// For clock recalibration
-
-	oldfreq = ((FID(msr)&0x80)?(FID(msr)/2):(FID(msr))) * FSB;
-	msr = (msr & 0xffffffffffff0000ULL) | CTL(p.Frequency, p.Voltage); // blank out last 32 bits and put our ctl there
-	newfreq = ((FID(msr)&0x80)?(FID(msr)/2):(FID(msr))) * FSB; // after setting ctl in msr
-	if (RtcFixKernel && !ConstantTSC) {
-		rtc_clock_stepping(newfreq, oldfreq);
-	}
-	
-	wrmsr64(INTEL_MSR_PERF_CTL, msr); // and write it to the processor
-	
-	if (RtcFixKernel && !ConstantTSC)
-		rtc_clock_stepped(newfreq, oldfreq);
-	
-	IODelay(p.Latency); // maybe wait longer?
-}
-
-void disableInterrupts(__unused void *t) {
-	InterruptsEnabled = ml_set_interrupts_enabled(false);
-}
-
-void enableInterrupts(void *t) {
-	ml_set_interrupts_enabled(InterruptsEnabled);
-}
-
-
-
-
-/**********************************************************************************************************/
-
-static int iess_handle_auto SYSCTL_HANDLER_ARGS
-{
-	int err = 0;
-	if (req->newptr) {
-		// new ctl being set
-		int whetherOn;
-		err = SYSCTL_IN(req, &whetherOn, sizeof(int));
-		if (err) return err;
-		dbg("Setting autothrottle to %d\n", whetherOn);
-		Throttler.setEnabled(whetherOn != 0);
-				
-	} else {
-		int sts = Throttler.getEnabled() ? 1 : 0;
-		err = SYSCTL_OUT(req, &sts, sizeof(int));
-	}
-	return err;
-}
-
-SYSCTL_PROC  (_kern, OID_AUTO, cputhrottle_auto,    CTLTYPE_INT | CTLFLAG_RW, 0, 0, &iess_handle_auto,    "I", "Auto-throttle status");
-
-bool AutoThrottler::setup(OSObject* owner) {
-	if (setupDone) return true;
-	
-	workLoop = IOWorkLoop::workLoop();
-	if (workLoop == 0) return false;
-	
-	perfTimer = IOTimerEventSource::timerEventSource(owner, (IOTimerEventSource::Action) &perfTimerWrapper);
-	if (perfTimer == 0) return false;
-	
-	if (workLoop->addEventSource(perfTimer) != kIOReturnSuccess) return false;
-	currentPState = NumberOfPStates - 1;
-	perfTimer->setTimeoutMS(1024);
-	clock_get_uptime(&lastTime);
-	targetCPULoad = 200; // % x10
-	setupDone = true;
-	sysctl_register_oid(&sysctl__kern_cputhrottle_auto);
-	return true;
-}
-
-
-void AutoThrottler::stop() {
-	enabled = false;
-	perfTimer->cancelTimeout();
-	// Settle time in case we were just stepping
-	IOSleep(1024);
-	if (workLoop) workLoop->removeEventSource(perfTimer);	// Remove our event sources
-	setupDone = false;
-}
-
-void AutoThrottler::setEnabled(bool _enabled) {
-	enabled = _enabled;
-}
-
-bool AutoThrottler::getEnabled() {
-	return enabled;
-}
-
-AutoThrottler::~AutoThrottler() {
-	if (enabled) enabled = false;
-	if (setupDone) stop();
-	sysctl_unregister_oid(&sysctl__kern_cputhrottle_ctl);
-	if (perfTimer) {
-		perfTimer->release();
-		perfTimer = 0;
-	}
-	
-	if (workLoop) {
-		workLoop->release();
-		workLoop = 0;
-	}
-}
-
-
-static void GetCPUTicks(long* idle, long* total) {
-    host_cpu_load_info_data_t loadinfo;
-	static long idle_old, total_old;
-	long total_new;
-	mach_msg_type_number_t count;
-	
-	count = HOST_CPU_LOAD_INFO_COUNT; 
-	host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t) &loadinfo, &count);
-	
-	total_new =  loadinfo.cpu_ticks[CPU_STATE_USER]
-				+loadinfo.cpu_ticks[CPU_STATE_NICE]
-				+loadinfo.cpu_ticks[CPU_STATE_SYSTEM]
-				+loadinfo.cpu_ticks[CPU_STATE_IDLE];
-	
-	if (idle)
-		*idle =	loadinfo.cpu_ticks[CPU_STATE_IDLE] - idle_old;
-	if (total)
-		*total = total_new - total_old;
-	
-	idle_old = loadinfo.cpu_ticks[CPU_STATE_IDLE];
-	total_old = total_new;
-}
-
-
-
-bool perfTimerWrapper(OSObject* owner, IOTimerEventSource* src, int count) {
-	register AutoThrottler* objDriver = (AutoThrottler*) owner;
-	return (objDriver->perfTimerEvent(src, count));
-}
-
-
-bool AutoThrottler::perfTimerEvent(IOTimerEventSource* src, int count) {
-	uint32_t wantspeed,wantstep;
-	long i, idle, used, total;
-	
-	if (!enabled || !setupDone) return false;
-	
-	GetCPUTicks(&idle, &total);
-	
-	// Used = % used x 10
-	used = ((total - idle) * 1000) / total;
-	
-	// If used > 95% we can't really guess how much is needed, so step to highest speed
-	if (used >= 950)
-		wantspeed = PStates[0].AcpiFreq;
-	else // Otherwise wantspeed is the ideal frequency to maintain idle % target
-		wantspeed = (PStates[currentPState].AcpiFreq * (used + 1)) / targetCPULoad;
-	
-	wantstep = FindClosestPState(wantspeed);
-	
-	if (wantstep == currentPState) goto check_soon;
-	
-	currentPState = wantstep; // Assume we got the one we wanted
-	throttleAllCPUs(PStates[currentPState]);
-	
-	perfTimer->setTimeoutMS(512 * (wantstep + 1)); // Make the delay until the next check proportional to the speed we picked
-	return true;
-	
-check_soon:
-	perfTimer->setTimeoutMS(512);
-	return true;
-}
-
-

File IntelEnhancedSpeedStep/IntelEnhancedSpeedStep.h

-#ifndef _INTELENHANCEDSPEEDSTEP_H
-#define _INTELENHANCEDSPEEDSTEP_H
-
-#include <IOKit/IOService.h>
-#include <IOKit/acpi/IOACPIPlatformDevice.h>
-#include <IOKit/IORegistryEntry.h>
-#include <IOKit/IOWorkLoop.h>
-#include <IOKit/IOTimerEventSource.h>
-#include <IOKit/IOLib.h>
-
-#include <i386/proc_reg.h>
-#include <i386/cpuid.h>
-#include <i386/proc_reg.h>
-
-#include <sys/sysctl.h>
-#include <sys/types.h>
-
-#include <mach/mach_interface.h>
-#include <mach/mach_vm.h>
-#include <mach/mach_host.h>
-#include <mach/vm_region.h>
-#include <mach/vm_statistics.h>
-
-/*
- * This class holds information about each throttle state
- */
-class PState {
-public:
-	uint16_t Frequency;			// processor clock speed (FID, not MHz)
-	uint16_t AcpiFreq;			// as reported by ACPI (nice rounded) for display purposes
-	uint16_t Voltage;			// wanted voltage ID while on AC
-	uint16_t OriginalVoltage;	// The factory default voltage ID for this frequency
-	uint32_t Latency;			// how long to wait after writing to msr
-};
-
-
-/*
- * Our auto-throttle controller
- */
-class AutoThrottler {
-private:
-	IOWorkLoop*			workLoop;
-	IOTimerEventSource* perfTimer;
-	bool				setupDone; // setup has been done, ready to throttle
-	bool				enabled; // driver is autothrottling
-	uint8_t				currentPState;
-	uint64_t			lastTime;
-	uint16_t			targetCPULoad;
-	
-public:
-	bool setup(OSObject* owner); // Initialize the throttler
-	void stop();
-	void setEnabled(bool _enabled);
-	bool getEnabled();
-	~AutoThrottler();
-	
-	bool perfTimerEvent(IOTimerEventSource* src, int count);
-};
-
-bool perfTimerWrapper(OSObject* owner, IOTimerEventSource* src, int count);
-static void GetCPUTicks(long* idle, long* total);
-
-/*********************************************************************************************************
-/*
- * The following is used with mp_rendezvous to throttle all CPUs
- */
-void disableInterrupts	(__unused void* t);
-void enableInterrupts	(__unused void* t);
-void throttleCPU		(void* fidvid);
-
-/*
- * Rendezvous
- */
-extern "C" void mp_rendezvous(	void (*setup_func)		(void *),
-								void (*action_func)		(void *),
-								void (*teardown_func)	(void *),
-								void *arg);
-
-/*
- * For timer fix
- */
-__BEGIN_DECLS
-/* The next 2 functions are used for clock recalibration on non-constant tsc */
-extern void rtc_clock_stepping(uint32_t new_frequency, uint32_t old_frequency);
-extern void rtc_clock_stepped (uint32_t new_frequency, uint32_t old_frequency);
-/* The following is our magic function for kernel feature autodetect */
-extern void nanoseconds_to_absolutetime(uint64_t nanoseconds, uint64_t *result);
-__END_DECLS
-
-/*
- * The main throttling function. This sets up mp_rendezvous and provides
- * the proper fid/vid for the given P-State.
- */
-void throttleAllCPUs(PState p);
-
-/*
- * Gets the current core voltage. Only current processor is read
- */
-uint16_t getCurrentVoltage();
-
-/*
- * Returns the current operating frequency in MHz
- */
-uint16_t getCurrentFrequency();
-
-/*
- * Check heuristically whether constant_tsc is supported
- */
-bool isConstantTSC();
-
-/*
- * Check whether CPU supports N/2 fsb ratios
- */
-void checkForNby2Ratio();
-
-/*
- * Create the PState table by getting info from ACPI
- */
-bool createPStateTable(PState* pS, unsigned int* numStates);
-/*
- * Gets the FSB frequency from EFI
- */
-bool getFSB();
-
-/*
- * Loads override PState table from the Info.plist's array
- */
-void loadPStateOverride(OSArray* dict);
-
-/*
- * Convert VID to mV
- */
-uint16_t VID_to_mV(uint8_t VID);
-
-/*
- * Convert mV to VID
- */
-uint8_t mV_to_VID(uint16_t mv);
-
-/*
- * FID to Mhz and vice versa
- */
-uint8_t  MHz_to_FID(uint16_t mhz);
-uint16_t FID_to_MHz(uint8_t fid);
-
-/*
- * Check if we are running on newer core2duo
- */
-void checkForPenryn();
-
-/* Sysctl stuff */
-char*	getFreqList();
-char*	getVoltageList(bool original);
-int		FindClosestPState(int wantedFreq);
-char	frequencyList	[1024] = "";
-char	originalVoltages[1024] = "";
-
-/*
- * Certain (pseudo)global variables
- */
-PState			PStates[16];		// 16 states max
-AutoThrottler	Throttler;			// Our autothrottle controller
-unsigned int	NumberOfPStates;	// How many this processor supports
-IOSimpleLock*	Lock;				// lock to use while throttling
-bool			InterruptsEnabled;	// to save state of interrupts before throttling
-bool			Is45nmPenryn;		// so that we can use proper VID -> mV calculation
-bool			RtcFixKernel;		// to indicate if this kernel has rtc fix
-bool			Below1Ghz;			// whether kernel is patched to support < 1Ghz freqs
-bool			ConstantTSC;		// whether processor supports constant tsc
-bool			Nby2Ratio;			// Whether cpu supports N/2 fsb ratio
-bool			DebugOn;			// whether to print debug messages
-uint64_t		FSB;				// as reported by EFI
-uint32_t		MaxLatency;			// how long to wait after switching pstate
-int				DefaultPState;		// set at startup
-
-/*
- * The IOKit driver class
- */
-class net_mercurysquad_driver_IntelEnhancedSpeedStep : public IOService {
-OSDeclareDefaultStructors(net_mercurysquad_driver_IntelEnhancedSpeedStep)
-	
-private:
-	IOWorkLoop*			workLoop;
-
-public:
-    virtual bool		init	(OSDictionary *dictionary = 0);
-    virtual void		free	(void);
-    virtual IOService*	probe	(IOService *provider, SInt32 *score);
-    virtual bool		start	(IOService *provider);
-    virtual void		stop	(IOService *provider);
-};
-
-#endif // _INTELENHANCEDSPEEDSTEP_H

File IntelEnhancedSpeedStep/IntelEnhancedSpeedStep.xcodeproj/TemplateIcon.tiff

Removed
Old image

File IntelEnhancedSpeedStep/IntelEnhancedSpeedStep.xcodeproj/prashant.mode1v3

-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>ActivePerspectiveName</key>
-	<string>Project</string>
-	<key>AllowedModules</key>
-	<array>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>PBXSmartGroupTreeModule</string>
-			<key>Name</key>
-			<string>Groups and Files Outline View</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>PBXNavigatorGroup</string>
-			<key>Name</key>
-			<string>Editor</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>XCTaskListModule</string>
-			<key>Name</key>
-			<string>Task List</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>XCDetailModule</string>
-			<key>Name</key>
-			<string>File and Smart Group Detail Viewer</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>1</string>
-			<key>Module</key>
-			<string>PBXBuildResultsModule</string>
-			<key>Name</key>
-			<string>Detailed Build Results Viewer</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>1</string>
-			<key>Module</key>
-			<string>PBXProjectFindModule</string>
-			<key>Name</key>
-			<string>Project Batch Find Tool</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>XCProjectFormatConflictsModule</string>
-			<key>Name</key>
-			<string>Project Format Conflicts List</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>PBXBookmarksModule</string>
-			<key>Name</key>
-			<string>Bookmarks Tool</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>PBXClassBrowserModule</string>
-			<key>Name</key>
-			<string>Class Browser</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>PBXCVSModule</string>
-			<key>Name</key>
-			<string>Source Code Control Tool</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>PBXDebugBreakpointsModule</string>
-			<key>Name</key>
-			<string>Debug Breakpoints Tool</string>
-		</dict>
-		<dict>
-			<key>BundleLoadPath</key>
-			<string></string>
-			<key>MaxInstances</key>
-			<string>n</string>
-			<key>Module</key>
-			<string>XCDockableInspector</string>
-			<key>Name</key>
-			<string>Inspector</string>
-		</dict>
-		<dict>