13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/errno.h>
18 #include <linux/device.h>
26 #define MODULE_VERS "1.0"
27 #define MODULE_NAME "pseries_energy"
31 static int sysfs_entries;
41 static int check_for_h_best_energy(
void)
44 const char *hypertas, *
s;
59 for (s = hypertas; s < hypertas +
length; s +=
strlen(s) + 1) {
60 if (!
strncmp(
"hcall-best-energy-1", s, 19)) {
71 static u32 cpu_to_drc_index(
int cpu)
104 static int drc_index_to_cpu(
u32 drc_index)
116 goto err_of_node_put;
122 for (i = 0; i < indexes[0]; i++) {
123 if (indexes[i + 1] == drc_index)
144 #define FLAGS_MODE1 0x004E200000080E01
145 #define FLAGS_MODE2 0x004E200000080401
146 #define FLAGS_ACTIVATE 0x100
148 static ssize_t get_best_energy_list(
char *
page,
int activate)
151 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
152 unsigned long flags = 0;
164 rc = plpar_hcall9(H_BEST_ENERGY, retbuf, flags, 0,
__pa(buf_page),
166 if (rc != H_SUCCESS) {
172 for (i = 0; i <
cnt; i++) {
173 cpu = drc_index_to_cpu(buf_page[2*i+1]);
188 char *
page,
int activate)
191 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
192 unsigned long flags = 0;
198 rc = plpar_hcall9(H_BEST_ENERGY, retbuf, flags,
199 cpu_to_drc_index(dev->
id),
200 0, 0, 0, 0, 0, 0, 0);
205 return sprintf(page,
"%lu\n", retbuf[1] >> 32);
210 static ssize_t cpu_activate_hint_list_show(
struct device *dev,
213 return get_best_energy_list(page, 1);
216 static ssize_t cpu_deactivate_hint_list_show(
struct device *dev,
219 return get_best_energy_list(page, 0);
225 return get_best_energy_data(dev, page, 1);
228 static ssize_t percpu_deactivate_hint_show(
struct device *dev,
231 return get_best_energy_data(dev, page, 0);
245 __ATTR(pseries_activate_hint_list, 0444,
246 cpu_activate_hint_list_show,
NULL);
249 __ATTR(pseries_deactivate_hint_list, 0444,
250 cpu_deactivate_hint_list_show,
NULL);
253 __ATTR(pseries_activate_hint, 0444,
254 percpu_activate_hint_show,
NULL);
257 __ATTR(pseries_deactivate_hint, 0444,
258 percpu_deactivate_hint_show,
NULL);
260 static int __init pseries_energy_init(
void)
265 if (!check_for_h_best_energy()) {
271 &attr_cpu_activate_hint_list);
274 &attr_cpu_deactivate_hint_list);
281 &attr_percpu_activate_hint);
285 &attr_percpu_deactivate_hint);
298 static void __exit pseries_energy_cleanup(
void)
313 &attr_percpu_activate_hint.
attr);
315 &attr_percpu_deactivate_hint.
attr);