5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
262 lines
6.5 KiB
C
262 lines
6.5 KiB
C
/*
|
|
* This file was based upon code in Powertweak Linux (http://powertweak.sf.net)
|
|
* (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä,
|
|
* Dominik Brodowski.
|
|
*
|
|
* Licensed under the terms of the GNU GPL License version 2.
|
|
*
|
|
* BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/cpufreq.h>
|
|
#include <linux/ioport.h>
|
|
#include <linux/timex.h>
|
|
#include <linux/io.h>
|
|
|
|
#include <asm/msr.h>
|
|
|
|
#define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long
|
|
as it is unused */
|
|
|
|
#define PFX "powernow-k6: "
|
|
static unsigned int busfreq; /* FSB, in 10 kHz */
|
|
static unsigned int max_multiplier;
|
|
|
|
|
|
/* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */
|
|
static struct cpufreq_frequency_table clock_ratio[] = {
|
|
{45, /* 000 -> 4.5x */ 0},
|
|
{50, /* 001 -> 5.0x */ 0},
|
|
{40, /* 010 -> 4.0x */ 0},
|
|
{55, /* 011 -> 5.5x */ 0},
|
|
{20, /* 100 -> 2.0x */ 0},
|
|
{30, /* 101 -> 3.0x */ 0},
|
|
{60, /* 110 -> 6.0x */ 0},
|
|
{35, /* 111 -> 3.5x */ 0},
|
|
{0, CPUFREQ_TABLE_END}
|
|
};
|
|
|
|
|
|
/**
|
|
* powernow_k6_get_cpu_multiplier - returns the current FSB multiplier
|
|
*
|
|
* Returns the current setting of the frequency multiplier. Core clock
|
|
* speed is frequency of the Front-Side Bus multiplied with this value.
|
|
*/
|
|
static int powernow_k6_get_cpu_multiplier(void)
|
|
{
|
|
u64 invalue = 0;
|
|
u32 msrval;
|
|
|
|
msrval = POWERNOW_IOPORT + 0x1;
|
|
wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
|
|
invalue = inl(POWERNOW_IOPORT + 0x8);
|
|
msrval = POWERNOW_IOPORT + 0x0;
|
|
wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
|
|
|
|
return clock_ratio[(invalue >> 5)&7].index;
|
|
}
|
|
|
|
|
|
/**
|
|
* powernow_k6_set_state - set the PowerNow! multiplier
|
|
* @best_i: clock_ratio[best_i] is the target multiplier
|
|
*
|
|
* Tries to change the PowerNow! multiplier
|
|
*/
|
|
static void powernow_k6_set_state(unsigned int best_i)
|
|
{
|
|
unsigned long outvalue = 0, invalue = 0;
|
|
unsigned long msrval;
|
|
struct cpufreq_freqs freqs;
|
|
|
|
if (clock_ratio[best_i].index > max_multiplier) {
|
|
printk(KERN_ERR PFX "invalid target frequency\n");
|
|
return;
|
|
}
|
|
|
|
freqs.old = busfreq * powernow_k6_get_cpu_multiplier();
|
|
freqs.new = busfreq * clock_ratio[best_i].index;
|
|
freqs.cpu = 0; /* powernow-k6.c is UP only driver */
|
|
|
|
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
|
|
|
|
/* we now need to transform best_i to the BVC format, see AMD#23446 */
|
|
|
|
outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5);
|
|
|
|
msrval = POWERNOW_IOPORT + 0x1;
|
|
wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
|
|
invalue = inl(POWERNOW_IOPORT + 0x8);
|
|
invalue = invalue & 0xf;
|
|
outvalue = outvalue | invalue;
|
|
outl(outvalue , (POWERNOW_IOPORT + 0x8));
|
|
msrval = POWERNOW_IOPORT + 0x0;
|
|
wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
|
|
|
|
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
/**
|
|
* powernow_k6_verify - verifies a new CPUfreq policy
|
|
* @policy: new policy
|
|
*
|
|
* Policy must be within lowest and highest possible CPU Frequency,
|
|
* and at least one possible state must be within min and max.
|
|
*/
|
|
static int powernow_k6_verify(struct cpufreq_policy *policy)
|
|
{
|
|
return cpufreq_frequency_table_verify(policy, &clock_ratio[0]);
|
|
}
|
|
|
|
|
|
/**
|
|
* powernow_k6_setpolicy - sets 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 powernow_k6_target(struct cpufreq_policy *policy,
|
|
unsigned int target_freq,
|
|
unsigned int relation)
|
|
{
|
|
unsigned int newstate = 0;
|
|
|
|
if (cpufreq_frequency_table_target(policy, &clock_ratio[0],
|
|
target_freq, relation, &newstate))
|
|
return -EINVAL;
|
|
|
|
powernow_k6_set_state(newstate);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
|
|
{
|
|
unsigned int i, f;
|
|
int result;
|
|
|
|
if (policy->cpu != 0)
|
|
return -ENODEV;
|
|
|
|
/* get frequencies */
|
|
max_multiplier = powernow_k6_get_cpu_multiplier();
|
|
busfreq = cpu_khz / max_multiplier;
|
|
|
|
/* table init */
|
|
for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
|
|
f = clock_ratio[i].index;
|
|
if (f > max_multiplier)
|
|
clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID;
|
|
else
|
|
clock_ratio[i].frequency = busfreq * f;
|
|
}
|
|
|
|
/* cpuinfo and default policy values */
|
|
policy->cpuinfo.transition_latency = 200000;
|
|
policy->cur = busfreq * max_multiplier;
|
|
|
|
result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio);
|
|
if (result)
|
|
return result;
|
|
|
|
cpufreq_frequency_table_get_attr(clock_ratio, policy->cpu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int powernow_k6_cpu_exit(struct cpufreq_policy *policy)
|
|
{
|
|
unsigned int i;
|
|
for (i = 0; i < 8; i++) {
|
|
if (i == max_multiplier)
|
|
powernow_k6_set_state(i);
|
|
}
|
|
cpufreq_frequency_table_put_attr(policy->cpu);
|
|
return 0;
|
|
}
|
|
|
|
static unsigned int powernow_k6_get(unsigned int cpu)
|
|
{
|
|
unsigned int ret;
|
|
ret = (busfreq * powernow_k6_get_cpu_multiplier());
|
|
return ret;
|
|
}
|
|
|
|
static struct freq_attr *powernow_k6_attr[] = {
|
|
&cpufreq_freq_attr_scaling_available_freqs,
|
|
NULL,
|
|
};
|
|
|
|
static struct cpufreq_driver powernow_k6_driver = {
|
|
.verify = powernow_k6_verify,
|
|
.target = powernow_k6_target,
|
|
.init = powernow_k6_cpu_init,
|
|
.exit = powernow_k6_cpu_exit,
|
|
.get = powernow_k6_get,
|
|
.name = "powernow-k6",
|
|
.owner = THIS_MODULE,
|
|
.attr = powernow_k6_attr,
|
|
};
|
|
|
|
|
|
/**
|
|
* powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver
|
|
*
|
|
* Initializes the K6 PowerNow! support. Returns -ENODEV on unsupported
|
|
* devices, -EINVAL or -ENOMEM on problems during initiatization, and zero
|
|
* on success.
|
|
*/
|
|
static int __init powernow_k6_init(void)
|
|
{
|
|
struct cpuinfo_x86 *c = &cpu_data(0);
|
|
|
|
if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) ||
|
|
((c->x86_model != 12) && (c->x86_model != 13)))
|
|
return -ENODEV;
|
|
|
|
if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) {
|
|
printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n");
|
|
return -EIO;
|
|
}
|
|
|
|
if (cpufreq_register_driver(&powernow_k6_driver)) {
|
|
release_region(POWERNOW_IOPORT, 16);
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/**
|
|
* powernow_k6_exit - unregisters AMD K6-2+/3+ PowerNow! support
|
|
*
|
|
* Unregisters AMD K6-2+ / K6-3+ PowerNow! support.
|
|
*/
|
|
static void __exit powernow_k6_exit(void)
|
|
{
|
|
cpufreq_unregister_driver(&powernow_k6_driver);
|
|
release_region(POWERNOW_IOPORT, 16);
|
|
}
|
|
|
|
|
|
MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, "
|
|
"Dominik Brodowski <linux@brodo.de>");
|
|
MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors.");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
module_init(powernow_k6_init);
|
|
module_exit(powernow_k6_exit);
|