/* * sysfs.c - sysfs support * * (C) 2006-2007 Shaohua Li * * This code is licenced under the GPL. */ #include #include #include #include #include #include #include #include #include #include "cpuidle.h" static unsigned int sysfs_switch; static int __init cpuidle_sysfs_setup(char *unused) { sysfs_switch = 1; return 1; } __setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup); static ssize_t show_available_governors(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t i = 0; struct cpuidle_governor *tmp; mutex_lock(&cpuidle_lock); list_for_each_entry(tmp, &cpuidle_governors, governor_list) { if (i >= (ssize_t) ((PAGE_SIZE/sizeof(char)) - CPUIDLE_NAME_LEN - 2)) goto out; i += scnprintf(&buf[i], CPUIDLE_NAME_LEN, "%s ", tmp->name); } out: i+= sprintf(&buf[i], "\n"); mutex_unlock(&cpuidle_lock); return i; } static ssize_t show_current_driver(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t ret; struct cpuidle_driver *drv; spin_lock(&cpuidle_driver_lock); drv = cpuidle_get_driver(); if (drv) ret = sprintf(buf, "%s\n", drv->name); else ret = sprintf(buf, "none\n"); spin_unlock(&cpuidle_driver_lock); return ret; } static ssize_t show_current_governor(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t ret; mutex_lock(&cpuidle_lock); if (cpuidle_curr_governor) ret = sprintf(buf, "%s\n", cpuidle_curr_governor->name); else ret = sprintf(buf, "none\n"); mutex_unlock(&cpuidle_lock); return ret; } static ssize_t store_current_governor(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { char gov_name[CPUIDLE_NAME_LEN]; int ret = -EINVAL; size_t len = count; struct cpuidle_governor *gov; if (!len || len >= sizeof(gov_name)) return -EINVAL; memcpy(gov_name, buf, len); gov_name[len] = '\0'; if (gov_name[len - 1] == '\n') gov_name[--len] = '\0'; mutex_lock(&cpuidle_lock); list_for_each_entry(gov, &cpuidle_governors, governor_list) { if (strlen(gov->name) == len && !strcmp(gov->name, gov_name)) { ret = cpuidle_switch_governor(gov); break; } } mutex_unlock(&cpuidle_lock); if (ret) return ret; else return count; } static DEVICE_ATTR(current_driver, 0444, show_current_driver, NULL); static DEVICE_ATTR(current_governor_ro, 0444, show_current_governor, NULL); static struct attribute *cpuidle_default_attrs[] = { &dev_attr_current_driver.attr, &dev_attr_current_governor_ro.attr, NULL }; static DEVICE_ATTR(available_governors, 0444, show_available_governors, NULL); static DEVICE_ATTR(current_governor, 0644, show_current_governor, store_current_governor); static struct attribute *cpuidle_switch_attrs[] = { &dev_attr_available_governors.attr, &dev_attr_current_driver.attr, &dev_attr_current_governor.attr, NULL }; static struct attribute_group cpuidle_attr_group = { .attrs = cpuidle_default_attrs, .name = "cpuidle", }; /** * cpuidle_add_interface - add CPU global sysfs attributes */ int cpuidle_add_interface(struct device *dev) { if (sysfs_switch) cpuidle_attr_group.attrs = cpuidle_switch_attrs; return sysfs_create_group(&dev->kobj, &cpuidle_attr_group); } /** * cpuidle_remove_interface - remove CPU global sysfs attributes */ void cpuidle_remove_interface(struct device *dev) { sysfs_remove_group(&dev->kobj, &cpuidle_attr_group); } struct cpuidle_attr { struct attribute attr; ssize_t (*show)(struct cpuidle_device *, char *); ssize_t (*store)(struct cpuidle_device *, const char *, size_t count); }; #define define_one_ro(_name, show) \ static struct cpuidle_attr attr_##_name = __ATTR(_name, 0444, show, NULL) #define define_one_rw(_name, show, store) \ static struct cpuidle_attr attr_##_name = __ATTR(_name, 0644, show, store) #define attr_to_cpuidleattr(a) container_of(a, struct cpuidle_attr, attr) struct cpuidle_device_kobj { struct cpuidle_device *dev; struct completion kobj_unregister; struct kobject kobj; }; static inline struct cpuidle_device *to_cpuidle_device(struct kobject *kobj) { struct cpuidle_device_kobj *kdev = container_of(kobj, struct cpuidle_device_kobj, kobj); return kdev->dev; } static ssize_t cpuidle_show(struct kobject *kobj, struct attribute *attr, char *buf) { int ret = -EIO; struct cpuidle_device *dev = to_cpuidle_device(kobj); struct cpuidle_attr *cattr = attr_to_cpuidleattr(attr); if (cattr->show) { mutex_lock(&cpuidle_lock); ret = cattr->show(dev, buf); mutex_unlock(&cpuidle_lock); } return ret; } static ssize_t cpuidle_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) { int ret = -EIO; struct cpuidle_device *dev = to_cpuidle_device(kobj); struct cpuidle_attr *cattr = attr_to_cpuidleattr(attr); if (cattr->store) { mutex_lock(&cpuidle_lock); ret = cattr->store(dev, buf, count); mutex_unlock(&cpuidle_lock); } return ret; } static const struct sysfs_ops cpuidle_sysfs_ops = { .show = cpuidle_show, .store = cpuidle_store, }; static void cpuidle_sysfs_release(struct kobject *kobj) { struct cpuidle_device_kobj *kdev = container_of(kobj, struct cpuidle_device_kobj, kobj); complete(&kdev->kobj_unregister); } static struct kobj_type ktype_cpuidle = { .sysfs_ops = &cpuidle_sysfs_ops, .release = cpuidle_sysfs_release, }; struct cpuidle_state_attr { struct attribute attr; ssize_t (*show)(struct cpuidle_state *, \ struct cpuidle_state_usage *, char *); ssize_t (*store)(struct cpuidle_state *, \ struct cpuidle_state_usage *, const char *, size_t); }; #define define_one_state_ro(_name, show) \ static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL) #define define_one_state_rw(_name, show, store) \ static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store) #define define_show_state_function(_name) \ static ssize_t show_state_##_name(struct cpuidle_state *state, \ struct cpuidle_state_usage *state_usage, char *buf) \ { \ return sprintf(buf, "%u\n", state->_name);\ } #define define_store_state_ull_function(_name) \ static ssize_t store_state_##_name(struct cpuidle_state *state, \ struct cpuidle_state_usage *state_usage, \ const char *buf, size_t size) \ { \ unsigned long long value; \ int err; \ if (!capable(CAP_SYS_ADMIN)) \ return -EPERM; \ err = kstrtoull(buf, 0, &value); \ if (err) \ return err; \ if (value) \ state_usage->_name = 1; \ else \ state_usage->_name = 0; \ return size; \ } #define define_show_state_ull_function(_name) \ static ssize_t show_state_##_name(struct cpuidle_state *state, \ struct cpuidle_state_usage *state_usage, \ char *buf) \ { \ return sprintf(buf, "%llu\n", state_usage->_name);\ } #define define_show_state_str_function(_name) \ static ssize_t show_state_##_name(struct cpuidle_state *state, \ struct cpuidle_state_usage *state_usage, \ char *buf) \ { \ if (state->_name[0] == '\0')\ return sprintf(buf, "\n");\ return sprintf(buf, "%s\n", state->_name);\ } define_show_state_function(exit_latency) define_show_state_function(target_residency) define_show_state_function(power_usage) define_show_state_ull_function(usage) define_show_state_ull_function(time) define_show_state_str_function(name) define_show_state_str_function(desc) define_show_state_ull_function(disable) define_store_state_ull_function(disable) define_show_state_ull_function(above) define_show_state_ull_function(below) define_one_state_ro(name, show_state_name); define_one_state_ro(desc, show_state_desc); define_one_state_ro(latency, show_state_exit_latency); define_one_state_ro(residency, show_state_target_residency); define_one_state_ro(power, show_state_power_usage); define_one_state_ro(usage, show_state_usage); define_one_state_ro(time, show_state_time); define_one_state_rw(disable, show_state_disable, store_state_disable); define_one_state_ro(above, show_state_above); define_one_state_ro(below, show_state_below); static struct attribute *cpuidle_state_default_attrs[] = { &attr_name.attr, &attr_desc.attr, &attr_latency.attr, &attr_residency.attr, &attr_power.attr, &attr_usage.attr, &attr_time.attr, &attr_disable.attr, &attr_above.attr, &attr_below.attr, NULL }; struct cpuidle_state_kobj { struct cpuidle_state *state; struct cpuidle_state_usage *state_usage; struct completion kobj_unregister; struct kobject kobj; }; #ifdef CONFIG_SUSPEND #define define_show_state_s2idle_ull_function(_name) \ static ssize_t show_state_s2idle_##_name(struct cpuidle_state *state, \ struct cpuidle_state_usage *state_usage, \ char *buf) \ { \ return sprintf(buf, "%llu\n", state_usage->s2idle_##_name);\ } define_show_state_s2idle_ull_function(usage); define_show_state_s2idle_ull_function(time); #define define_one_state_s2idle_ro(_name, show) \ static struct cpuidle_state_attr attr_s2idle_##_name = \ __ATTR(_name, 0444, show, NULL) define_one_state_s2idle_ro(usage, show_state_s2idle_usage); define_one_state_s2idle_ro(time, show_state_s2idle_time); static struct attribute *cpuidle_state_s2idle_attrs[] = { &attr_s2idle_usage.attr, &attr_s2idle_time.attr, NULL }; static const struct attribute_group cpuidle_state_s2idle_group = { .name = "s2idle", .attrs = cpuidle_state_s2idle_attrs, }; static void cpuidle_add_s2idle_attr_group(struct cpuidle_state_kobj *kobj) { int ret; if (!kobj->state->enter_s2idle) return; ret = sysfs_create_group(&kobj->kobj, &cpuidle_state_s2idle_group); if (ret) pr_debug("%s: sysfs attribute group not created\n", __func__); } static void cpuidle_remove_s2idle_attr_group(struct cpuidle_state_kobj *kobj) { if (kobj->state->enter_s2idle) sysfs_remove_group(&kobj->kobj, &cpuidle_state_s2idle_group); } #else static inline void cpuidle_add_s2idle_attr_group(struct cpuidle_state_kobj *kobj) { } static inline void cpuidle_remove_s2idle_attr_group(struct cpuidle_state_kobj *kobj) { } #endif /* CONFIG_SUSPEND */ #define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj) #define kobj_to_state(k) (kobj_to_state_obj(k)->state) #define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage) #define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr) static ssize_t cpuidle_state_show(struct kobject *kobj, struct attribute *attr, char * buf) { int ret = -EIO; struct cpuidle_state *state = kobj_to_state(kobj)
 
 INSTALLATION ON THE WIN32 PLATFORM
 ----------------------------------

 Heres a few comments about building OpenSSL in Windows environments. Most of
 this is tested on Win32 but it may also work in Win 3.1 with some
 modification.

 You need Perl for Win32 (available from http://www.activestate.com/ActivePerl)
 and one of the following C compilers:

  * Visual C++
  * Borland C
  * GNU C (Mingw32 or Cygwin32)

 If you want to compile in the assembly language routines with Visual C++ then
 you will need an assembler. This is worth doing because it will result in
 faster code: for example it will typically result in a 2 times speedup in the
 RSA routines. Currently the following assemblers are supported:

  * Microsoft MASM (aka "ml")
  * Free Netwide Assembler NASM.

 MASM was at one point distributed with VC++. It is now distributed with some
 Microsoft DDKs, for example the Windows NT 4.0 DDK and the Windows 98 DDK. If
 you do not have either of these DDKs then you can just download the binaries
 for the Windows 98 DDK and extract and rename the two files XXXXXml.exe and
 XXXXXml.err, to ml.exe and ml.err and install somewhere on your PATH. Both
 DDKs can be downloaded from the Microsoft developers site www.msdn.com.

 NASM is freely available. Version 0.98 was used during testing: other versions
 may also work. It is available from many places, see for example:
 http://www.kernel.org/pub/software/devel/nasm/binaries/win32/
 The NASM binary nasmw.exe needs to be installed anywhere on your PATH.

 If you are compiling from a tarball or a CVS snapshot then the Win32 files
 may well be not up to date. This may mean that some "tweaking" is required to
 get it all to work. See the trouble shooting section later on for if (when?)
 it goes wrong.

 Visual C++
 ----------

 Firstly you should run Configure:

 > perl Configure VC-WIN32

 Next you need to build the Makefiles and optionally the assembly language
 files:

 - If you are using MASM then run:

   > ms\do_masm

 - If you are using NASM then run:

   > ms\do_nasm

 - If you don't want to use the assembly language files at all then run:

   > ms\do_ms

 If you get errors about things not having numbers assigned then check the
 troubleshooting section: you probably won't be able to compile it as it
 stands.

 Then from the VC++ environment at a prompt do:

 > nmake -f ms\ntdll.mak

 If all is well it should compile and you will have some DLLs and executables
 in out32dll. If you want to try the tests then do:
 
 > cd out32dll
 > ..\ms\test

 Tweaks:

 There are various changes you can make to the Win32 compile environment. By
 default the library is not compiled with debugging