⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 speedstep-centrino.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * centrino_cpu_init_acpi - register with ACPI P-States library * * Register with the ACPI P-States library (part of drivers/acpi/processor.c) * in order to determine correct frequency and voltage pairings by reading * the _PSS of the ACPI DSDT or SSDT tables. */static int centrino_cpu_init_acpi(struct cpufreq_policy *policy){	unsigned long			cur_freq;	int				result = 0, i;	unsigned int			cpu = policy->cpu;	/* register with ACPI core */	if (acpi_processor_register_performance(&p, cpu)) {		dprintk(KERN_INFO PFX "obtaining ACPI data failed\n");		return -EIO;	}	/* verify the acpi_data */	if (p.state_count <= 1) {		dprintk("No P-States\n");		result = -ENODEV;		goto err_unreg;	}	if ((p.control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||	    (p.status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {		dprintk("Invalid control/status registers (%x - %x)\n",			p.control_register.space_id, p.status_register.space_id);		result = -EIO;		goto err_unreg;	}	for (i=0; i<p.state_count; i++) {		if (p.states[i].control != p.states[i].status) {			dprintk("Different control (%llu) and status values (%llu)\n",				p.states[i].control, p.states[i].status);			result = -EINVAL;			goto err_unreg;		}		if (!p.states[i].core_frequency) {			dprintk("Zero core frequency for state %u\n", i);			result = -EINVAL;			goto err_unreg;		}		if (p.states[i].core_frequency > p.states[0].core_frequency) {			dprintk("P%u has larger frequency (%llu) than P0 (%llu), skipping\n", i,				p.states[i].core_frequency, p.states[0].core_frequency);			p.states[i].core_frequency = 0;			continue;		}	}	centrino_model[cpu] = kzalloc(sizeof(struct cpu_model), GFP_KERNEL);	if (!centrino_model[cpu]) {		result = -ENOMEM;		goto err_unreg;	}	centrino_model[cpu]->model_name=NULL;	centrino_model[cpu]->max_freq = p.states[0].core_frequency * 1000;	centrino_model[cpu]->op_points =  kmalloc(sizeof(struct cpufreq_frequency_table) *					     (p.state_count + 1), GFP_KERNEL);        if (!centrino_model[cpu]->op_points) {                result = -ENOMEM;                goto err_kfree;        }        for (i=0; i<p.state_count; i++) {		centrino_model[cpu]->op_points[i].index = p.states[i].control;		centrino_model[cpu]->op_points[i].frequency = p.states[i].core_frequency * 1000;		dprintk("adding state %i with frequency %u and control value %04x\n", 			i, centrino_model[cpu]->op_points[i].frequency, centrino_model[cpu]->op_points[i].index);	}	centrino_model[cpu]->op_points[p.state_count].frequency = CPUFREQ_TABLE_END;	cur_freq = get_cur_freq(cpu);	for (i=0; i<p.state_count; i++) {		if (!p.states[i].core_frequency) {			dprintk("skipping state %u\n", i);			centrino_model[cpu]->op_points[i].frequency = CPUFREQ_ENTRY_INVALID;			continue;		}				if (extract_clock(centrino_model[cpu]->op_points[i].index, cpu, 0) !=		    (centrino_model[cpu]->op_points[i].frequency)) {			dprintk("Invalid encoded frequency (%u vs. %u)\n",				extract_clock(centrino_model[cpu]->op_points[i].index, cpu, 0),				centrino_model[cpu]->op_points[i].frequency);			result = -EINVAL;			goto err_kfree_all;		}		if (cur_freq == centrino_model[cpu]->op_points[i].frequency)			p.state = i;	}	/* notify BIOS that we exist */	acpi_processor_notify_smm(THIS_MODULE);	return 0; err_kfree_all:	kfree(centrino_model[cpu]->op_points); err_kfree:	kfree(centrino_model[cpu]); err_unreg:	acpi_processor_unregister_performance(&p, cpu);	dprintk(KERN_INFO PFX "invalid ACPI data\n");	return (result);}#elsestatic inline int centrino_cpu_init_acpi(struct cpufreq_policy *policy) { return -ENODEV; }#endifstatic int centrino_cpu_init(struct cpufreq_policy *policy){	struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];	unsigned freq;	unsigned l, h;	int ret;	int i;	/* Only Intel makes Enhanced Speedstep-capable CPUs */	if (cpu->x86_vendor != X86_VENDOR_INTEL || !cpu_has(cpu, X86_FEATURE_EST))		return -ENODEV;	if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))		centrino_driver.flags |= CPUFREQ_CONST_LOOPS;	if (centrino_cpu_init_acpi(policy)) {		if (policy->cpu != 0)			return -ENODEV;		for (i = 0; i < N_IDS; i++)			if (centrino_verify_cpu_id(cpu, &cpu_ids[i]))				break;		if (i != N_IDS)			centrino_cpu[policy->cpu] = &cpu_ids[i];		if (!centrino_cpu[policy->cpu]) {			dprintk(KERN_INFO PFX "found unsupported CPU with "			"Enhanced SpeedStep: send /proc/cpuinfo to "			MAINTAINER "\n");			return -ENODEV;		}		if (centrino_cpu_init_table(policy)) {			return -ENODEV;		}	}	/* Check to see if Enhanced SpeedStep is enabled, and try to	   enable it if not. */	rdmsr(MSR_IA32_MISC_ENABLE, l, h);	if (!(l & (1<<16))) {		l |= (1<<16);		dprintk("trying to enable Enhanced SpeedStep (%x)\n", l);		wrmsr(MSR_IA32_MISC_ENABLE, l, h);		/* check to see if it stuck */		rdmsr(MSR_IA32_MISC_ENABLE, l, h);		if (!(l & (1<<16))) {			printk(KERN_INFO PFX "couldn't enable Enhanced SpeedStep\n");			return -ENODEV;		}	}	freq = get_cur_freq(policy->cpu);	policy->governor = CPUFREQ_DEFAULT_GOVERNOR;	policy->cpuinfo.transition_latency = 10000; /* 10uS transition latency */	policy->cur = freq;	dprintk("centrino_cpu_init: cur=%dkHz\n", policy->cur);	ret = cpufreq_frequency_table_cpuinfo(policy, centrino_model[policy->cpu]->op_points);	if (ret)		return (ret);	cpufreq_frequency_table_get_attr(centrino_model[policy->cpu]->op_points, policy->cpu);	return 0;}static int centrino_cpu_exit(struct cpufreq_policy *policy){	unsigned int cpu = policy->cpu;	if (!centrino_model[cpu])		return -ENODEV;	cpufreq_frequency_table_put_attr(cpu);#ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_ACPI	if (!centrino_model[cpu]->model_name) {		dprintk("unregistering and freeing ACPI data\n");		acpi_processor_unregister_performance(&p, cpu);		kfree(centrino_model[cpu]->op_points);		kfree(centrino_model[cpu]);	}#endif	centrino_model[cpu] = NULL;	return 0;}/** * centrino_verify - verifies a new CPUFreq policy * @policy: new policy * * Limit must be within this model's frequency range at least one * border included. */static int centrino_verify (struct cpufreq_policy *policy){	return cpufreq_frequency_table_verify(policy, centrino_model[policy->cpu]->op_points);}/** * centrino_setpolicy - set a new CPUFreq policy * @policy: new policy * @target_freq: the target frequency * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) * * Sets a new CPUFreq policy. */static int centrino_target (struct cpufreq_policy *policy,			    unsigned int target_freq,			    unsigned int relation){	unsigned int    newstate = 0;	unsigned int	msr, oldmsr, h, cpu = policy->cpu;	struct cpufreq_freqs	freqs;	cpumask_t		saved_mask;	int			retval;	if (centrino_model[cpu] == NULL)		return -ENODEV;	/*	 * Support for SMP systems.	 * Make sure we are running on the CPU that wants to change frequency	 */	saved_mask = current->cpus_allowed;	set_cpus_allowed(current, policy->cpus);	if (!cpu_isset(smp_processor_id(), policy->cpus)) {		dprintk("couldn't limit to CPUs in this domain\n");		return(-EAGAIN);	}	if (cpufreq_frequency_table_target(policy, centrino_model[cpu]->op_points, target_freq,					   relation, &newstate)) {		retval = -EINVAL;		goto migrate_end;	}	msr = centrino_model[cpu]->op_points[newstate].index;	rdmsr(MSR_IA32_PERF_CTL, oldmsr, h);	if (msr == (oldmsr & 0xffff)) {		retval = 0;		dprintk("no change needed - msr was and needs to be %x\n", oldmsr);		goto migrate_end;	}	freqs.cpu = cpu;	freqs.old = extract_clock(oldmsr, cpu, 0);	freqs.new = extract_clock(msr, cpu, 0);	dprintk("target=%dkHz old=%d new=%d msr=%04x\n",		target_freq, freqs.old, freqs.new, msr);	cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);	/* all but 16 LSB are "reserved", so treat them with	   care */	oldmsr &= ~0xffff;	msr &= 0xffff;	oldmsr |= msr;	wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);	cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);	retval = 0;migrate_end:	set_cpus_allowed(current, saved_mask);	return (retval);}static struct freq_attr* centrino_attr[] = {	&cpufreq_freq_attr_scaling_available_freqs,	NULL,};static struct cpufreq_driver centrino_driver = {	.name		= "centrino", /* should be speedstep-centrino,					 but there's a 16 char limit */	.init		= centrino_cpu_init,	.exit		= centrino_cpu_exit,	.verify		= centrino_verify,	.target		= centrino_target,	.get		= get_cur_freq,	.attr           = centrino_attr,	.owner		= THIS_MODULE,};/** * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver * * Initializes the Enhanced SpeedStep support. Returns -ENODEV on * unsupported devices, -ENOENT if there's no voltage table for this * particular CPU model, -EINVAL on problems during initiatization, * and zero on success. * * This is quite picky.  Not only does the CPU have to advertise the * "est" flag in the cpuid capability flags, we look for a specific * CPU model and stepping, and we need to have the exact model name in * our voltage tables.  That is, be paranoid about not releasing * someone's valuable magic smoke. */static int __init centrino_init(void){	struct cpuinfo_x86 *cpu = cpu_data;	if (!cpu_has(cpu, X86_FEATURE_EST))		return -ENODEV;	return cpufreq_register_driver(&centrino_driver);}static void __exit centrino_exit(void){	cpufreq_unregister_driver(&centrino_driver);}MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>");MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors.");MODULE_LICENSE ("GPL");late_initcall(centrino_init);module_exit(centrino_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -