speedstep.c revision 5cff782560a1c3cf913ba5574a5123a299f3315e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/x86_archext.h>
#include <sys/machsystm.h>
#include <sys/speedstep.h>
#include <sys/cpu_acpi.h>
/*
* Error returns
*/
#define ESS_RET_SUCCESS 0x00
#define ESS_RET_NO_PM 0x01
#define ESS_RET_UNSUP_STATE 0x02
/*
* Intel docs indicate that maximum latency of P-state changes should
* be on the order of 10mS. When waiting, wait in 100uS increments.
*/
#define ESS_MAX_LATENCY_MICROSECS 10000
#define ESS_LATENCY_WAIT 100
#define ESS_PDC_REVISION 0x1
#define ESS_PDC_PS_MSR (1<<0)
/*
* MSR registers for changing and reading processor power state.
*/
#define IA32_PERF_STATCPUDRV_MSR 0x198
#define IA32_PERF_CTL_MSR 0x199
#define IA32_CPUID_TSC_CONSTANT 0xF30
#define IA32_MISC_ENABLE_MSR 0x1A0
/*
* Debugging support
*/
#ifdef DEBUG
volatile int ess_debug = 0;
#else
#endif
typedef struct speedstep_state {
volatile int ess_pdccap = 1;
/*
* Read the status register. How it is read, depends upon the _PCT
* APCI object value.
*/
static int
{
int ret = 0;
switch (pct_stat->pc_addrspace_id) {
ret = 0;
break;
case ACPI_ADR_SPACE_SYSTEM_IO:
break;
default:
return (-1);
}
return (ret);
}
/*
* Write the ctrl register. How it is written, depends upon the _PCT
* APCI object value.
*/
static int
{
int ret = 0;
switch (pct_ctrl->pc_addrspace_id) {
/*
* Read current power state because reserved bits must be
* preserved, compose new value, and write it.
*/
ret = 0;
break;
case ACPI_ADR_SPACE_SYSTEM_IO:
break;
default:
return (-1);
}
return (ret);
}
/*
* Transition the current processor to the requested state.
*/
void
{
int i;
/*
* Initiate the processor p-state change.
*/
return;
}
/* Wait until switch is complete, but bound the loop just in case. */
for (i = 0; i < ESS_MAX_LATENCY_MICROSECS; i += ESS_LATENCY_WAIT) {
break;
}
if (i >= ESS_MAX_LATENCY_MICROSECS) {
}
pi->pi_curr_clock =
*ret = ESS_RET_SUCCESS;
}
int
{
int ret;
return (ret);
}
/*
* Validate that this processor supports Speedstep and if so,
* get the P-state data from ACPI and cache it.
*/
int
{
struct cpuid_regs cpu_regs;
int dependency;
ESSDEBUG(("speedstep_init: instance %d\n",
if (x86_vendor != X86_VENDOR_Intel ||
!(x86_feature & X86_CPUID) ||
!(x86_feature & X86_MSR)) {
ESSDEBUG(("Either not Intel or feature not supported.\n"));
return (ESS_RET_NO_PM);
}
/*
* Enhanced Speedstep supported?
*/
(void) __cpuid_insn(&cpu_regs);
ESSDEBUG(("Enhanced Speedstep not supported.\n"));
return (ESS_RET_NO_PM);
}
ESSDEBUG(("Variant TSC not supported.\n"));
return (ESS_RET_NO_PM);
}
/*
* If Enhanced Speedstep has not been enabled on the system,
* then we probably should not override the BIOS setting.
*/
if (! (reg & IA32_MISC_ENABLE_EST)) {
return (ESS_RET_NO_PM);
}
/*
* Enhanced Speedstep requires ACPI support. Get a handle
* to the correct processor object for this dip.
*/
"unable to get ACPI handle",
return (ESS_RET_NO_PM);
}
if (ess_pdccap) {
/*
* _PDC support is optional and the driver should
* function even if the _PDC write fails.
*/
&pdccap) != 0) {
ESSDEBUG(("Failed to write PDC\n"));
}
}
if (cpu_acpi_cache_data(handle) != 0) {
ESSDEBUG(("Failed to cache ACPI data\n"));
return (ESS_RET_NO_PM);
}
switch (pct_stat->pc_addrspace_id) {
ESSDEBUG(("Transitions will use fixed hardware\n"));
break;
case ACPI_ADR_SPACE_SYSTEM_IO:
ESSDEBUG(("Transitions will use system IO\n"));
break;
default:
return (ESS_RET_NO_PM);
}
else {
}
return (ESS_RET_SUCCESS);
}
/*
* Free resources allocated by speedstep_init().
*/
void
{
}