// SPDX-License-Identifier: GPL-2.0-only /* * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> * * Library for common functions for Intel SpeedStep v.1 and v.2 support * * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*
*/
/********************************************************************* * GET PROCESSOR CORE SPEED IN KHZ *
*********************************************************************/
/* Pentium 4 Model 0 and 1 do not have the Core Clock Frequency * to System Bus Frequency Ratio Field in the Processor Frequency * Configuration Register of the MSR. Therefore the current * frequency cannot be calculated and has to be measured.
*/ if (c->x86_model < 2) return cpu_khz;
/* Warning: may get called from smp_call_function_single. */ unsignedint speedstep_get_frequency(enum speedstep_processor processor)
{ switch (processor) { case SPEEDSTEP_CPU_PCORE: return pentium_core_get_frequency(); case SPEEDSTEP_CPU_PM: return pentiumM_get_frequency(); case SPEEDSTEP_CPU_P4D: case SPEEDSTEP_CPU_P4M: return pentium4_get_frequency(); case SPEEDSTEP_CPU_PIII_T: case SPEEDSTEP_CPU_PIII_C: case SPEEDSTEP_CPU_PIII_C_EARLY: return pentium3_get_frequency(processor); default: return 0;
} return 0;
}
EXPORT_SYMBOL_GPL(speedstep_get_frequency);
/* Keep in sync with the x86_cpu_id tables in the different modules */ enum speedstep_processor speedstep_detect_processor(void)
{ struct cpuinfo_x86 *c = &cpu_data(0);
u32 ebx, msr_lo, msr_hi;
if (c->x86 == 0xF) { /* Intel Mobile Pentium 4-M
* or Intel Mobile Pentium 4 with 533 MHz FSB */ if (c->x86_model != 2) return 0;
ebx = cpuid_ebx(0x00000001);
ebx &= 0x000000FF;
pr_debug("ebx value is %x, x86_stepping is %x\n", ebx, c->x86_stepping);
switch (c->x86_stepping) { case 4: /* * B-stepping [M-P4-M] * sample has ebx = 0x0f, production has 0x0e.
*/ if ((ebx == 0x0e) || (ebx == 0x0f)) return SPEEDSTEP_CPU_P4M; break; case 7: /* * C-stepping [M-P4-M] * needs to have ebx=0x0e, else it's a celeron: * cf. 25130917.pdf / page 7, footnote 5 even * though 25072120.pdf / page 7 doesn't say * samples are only of B-stepping...
*/ if (ebx == 0x0e) return SPEEDSTEP_CPU_P4M; break; case 9: /* * D-stepping [M-P4-M or M-P4/533] * * this is totally strange: CPUID 0x0F29 is * used by M-P4-M, M-P4/533 and(!) Celeron CPUs. * The latter need to be sorted out as they don't * support speedstep. * Celerons with CPUID 0x0F29 may have either * ebx=0x8 or 0xf -- 25130917.pdf doesn't say anything * specific. * M-P4-Ms may have either ebx=0xe or 0xf [see above] * M-P4/533 have either ebx=0xe or 0xf. [25317607.pdf] * also, M-P4M HTs have ebx=0x8, too * For now, they are distinguished by the model_id * string
*/ if ((ebx == 0x0e) ||
(strstr(c->x86_model_id, "Mobile Intel(R) Pentium(R) 4") != NULL)) return SPEEDSTEP_CPU_P4M; break; default: break;
} return 0;
}
switch (c->x86_model) { case 0x0B: /* Intel PIII [Tualatin] */ /* cpuid_ebx(1) is 0x04 for desktop PIII,
* 0x06 for mobile PIII-M */
ebx = cpuid_ebx(0x00000001);
pr_debug("ebx is %x\n", ebx);
ebx &= 0x000000FF;
if (ebx != 0x06) return 0;
/* So far all PIII-M processors support SpeedStep. See * Intel's 24540640.pdf of June 2003
*/ return SPEEDSTEP_CPU_PIII_T;
case 0x08: /* Intel PIII [Coppermine] */
/* all mobile PIII Coppermines have FSB 100 MHz
* ==> sort out a few desktop PIIIs. */
rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi);
pr_debug("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n",
msr_lo, msr_hi);
msr_lo &= 0x00c0000; if (msr_lo != 0x0080000) return 0;
/* * If the processor is a mobile version, * platform ID has bit 50 set * it has SpeedStep technology if either * bit 56 or 57 is set
*/
rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi);
pr_debug("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n",
msr_lo, msr_hi); if ((msr_hi & (1<<18)) &&
(relaxed_check ? 1 : (msr_hi & (3<<24)))) { if (c->x86_stepping == 0x01) {
pr_debug("early PIII version\n"); return SPEEDSTEP_CPU_PIII_C_EARLY;
} else return SPEEDSTEP_CPU_PIII_C;
}
fallthrough; default: return 0;
}
}
EXPORT_SYMBOL_GPL(speedstep_detect_processor);
if ((!processor) || (!low_speed) || (!high_speed) || (!set_state)) return -EINVAL;
pr_debug("trying to determine both speeds\n");
/* get current speed */
prev_speed = speedstep_get_frequency(processor); if (!prev_speed) return -EIO;
pr_debug("previous speed is %u\n", prev_speed);
preempt_disable();
local_irq_save(flags);
/* switch to low state */
set_state(SPEEDSTEP_LOW);
*low_speed = speedstep_get_frequency(processor); if (!*low_speed) {
ret = -EIO; goto out;
}
pr_debug("low speed is %u\n", *low_speed);
/* start latency measurement */ if (transition_latency)
tv1 = ktime_get();
/* switch to high state */
set_state(SPEEDSTEP_HIGH);
/* end latency measurement */ if (transition_latency)
tv2 = ktime_get();
*high_speed = speedstep_get_frequency(processor); if (!*high_speed) {
ret = -EIO; goto out;
}
pr_debug("high speed is %u\n", *high_speed);
if (*low_speed == *high_speed) {
ret = -ENODEV; goto out;
}
/* switch to previous state, if necessary */ if (*high_speed != prev_speed)
set_state(SPEEDSTEP_LOW);
if (transition_latency) {
*transition_latency = ktime_to_us(ktime_sub(tv2, tv1));
pr_debug("transition latency is %u uSec\n", *transition_latency);
/* convert uSec to nSec and add 20% for safety reasons */
*transition_latency *= 1200;
/* check if the latency measurement is too high or too low * and set it to a safe value (500uSec) in that case
*/ if (*transition_latency > 10000000 ||
*transition_latency < 50000) {
pr_warn("frequency transition measured seems out of range (%u nSec), falling back to a safe one of %u nSec\n",
*transition_latency, 500000);
*transition_latency = 500000;
}
}
#ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK
module_param(relaxed_check, int, 0444);
MODULE_PARM_DESC(relaxed_check, "Don't do all checks for speedstep capability."); #endif
MODULE_AUTHOR("Dominik Brodowski ");
MODULE_DESCRIPTION("Library for Intel SpeedStep 1 or 2 cpufreq drivers.");
MODULE_LICENSE("GPL");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.