1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
package cpufreq;
use common;
use detect_devices;
my %vendor_ids = (
GenuineIntel => "Intel",
AuthenticAMD => "AMD",
CyrixInstead => "Cyrix",
"Geode by NSC" => "NSC",
TransmetaCPU => "Transmeta",
GenuineTMx86 => "Transmeta",
CentaurHauls => "Centaur",
);
sub get_vendor {
my ($cpu) = @_;
$vendor_ids{$cpu->{vendor_id}};
}
sub has_flag {
my ($cpu, $flag) = @_;
$cpu->{flags} =~ /\b$flag\b/;
}
my @cpus;
sub get_cpus() {
@cpus ? @cpus : @cpus = detect_devices::getCPUs();
}
my @pci;
sub pci_probe() {
@pci ? @pci : @pci = detect_devices::pci_probe();
}
sub find_pci_device {
my (@devices) = @_;
any { my $dev = $_; any { $_->{vendor} == $dev->[0] && $_->{id} == $dev->[1] } pci_probe() } @devices;
}
sub probe_acpi_cpufreq() {
any {
get_vendor($_) eq "Intel" &&
$_->{'cpu family'} == 6 &&
(
has_flag($_, 'est') && member($_->{model}, 13, 15)
||
$_->{model} == 11
);
} get_cpus();
}
sub probe_centrino() {
any {
get_vendor($_) eq "Intel" &&
has_flag($_, 'est') && (
$_->{'cpu family'} == 6 && member($_->{model}, 9, 14) ||
$_->{'cpu family'} == 15 && member($_->{model}, 3, 4)
);
} get_cpus();
}
sub probe_ich() { find_pci_device([ 0x8086, 0x244c ], [ 0x8086, 0x24cc ], [ 0x8086, 0x248c ]) }
sub probe_smi() { find_pci_device([ 0x8086, 0x7190 ]) }
sub probe_nforce2() { find_pci_device([ 0x10de, 0x01e0 ]) }
sub probe_gsx() {
any { member(get_vendor($_), "Cyrix", "NSC") } get_cpus() &&
find_pci_device([ 0x1078, 0x0100 ], [ 0x1078, 0x0002 ], [ 0x1078, 0x0000 ]);
}
sub probe_powerpc() {
arch() =~ /ppc/ && any {
member($_->{motherboard}, ('PowerBook3,4', 'PowerBook3,5', 'PowerBook4,1', 'PowerBook3,2', 'MacRISC3')) &&
# Kernel contains a special case for the supported 750FX,
# not sure if the cpu name can be used, so use same test as kernel
first($_->{revision} =~ /\bpvr\s+(\d+)\b/) == 7000;
} get_cpus();
}
sub probe_p4() {
any {
get_vendor($_) eq "Intel" &&
$_->{'cpu family'} == 15;
} get_cpus();
}
sub probe_powernow_k6() {
any {
get_vendor($_) eq "AMD" &&
$_->{'cpu family'} == 5 &&
member($_->{model}, 12, 13);
} get_cpus();
}
sub probe_powernow_k7() {
any {
get_vendor($_) eq "AMD" &&
$_->{'cpu family'} == 6;
} get_cpus();
}
sub probe_powernow_k8() {
any {
get_vendor($_) eq "AMD" &&
$_->{'cpu family'} == 15 &&
($_->{'power management'} =~ /\bfid\b/ || has_flag($_, 'fid')); # frequency ID control
} get_cpus();
}
sub probe_longhaul() {
any {
get_vendor($_) eq "Centaur" &&
$_->{'cpu family'} == 6 &&
member($_->{model}, 6, 7, 8, 9);
} get_cpus();
}
sub probe_longrun() {
any {
get_vendor($_) eq "Transmeta" &&
has_flag($_, 'longrun');
} get_cpus();
}
my @modules = (
[ "acpi-cpufreq", \&probe_acpi_cpufreq ],
# probe centrino first, it will get detected on ICH chipset and
# speedstep-ich doesn't work with it
[ "speedstep-centrino", \&probe_centrino ],
# try to find cpufreq compliant northbridge
[ "speedstep-ich", \&probe_ich ],
[ "speedstep-smi", \&probe_smi ],
[ "cpufreq-nforce2", \&probe_nforce2 ],
[ "gsx-suspmod", \&probe_gsx ],
# try to find a cpufreq compliant processor
[ "p4-clockmod", \&probe_p4 ],
[ "powernow-k6", \&probe_powernow_k6 ],
[ "powernow-k7", \&probe_powernow_k7 ],
[ "powernow-k8", \&probe_powernow_k8 ],
[ "longhaul", \&probe_longhaul ],
[ "longrun", \&probe_longrun ],
);
sub find_driver() {
my $m = find { $_->[1]->() } @modules;
$m && $m->[0];
}
my @governor_modules = map { "cpufreq_$_" } qw(performance powersave conservative ondemand);
sub get_modules() {
my $module;
if (probe_powerpc() || ($module = find_driver())) {
return if_($module, $module), @governor_modules;
}
();
}
1;
|