linux/drivers/cpuidle/sysfs.c

/*
 * sysfs.c - sysfs support
 *
 * (C) 2006-2007 Shaohua Li <[email protected]>
 *
 * This code is licenced under the GPL.
 */

#include <linux/kernel.h>
#include <linux/cpuidle.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/cpu.h>
#include <linux/completion.h>
#include <linux/capability.h>
#include <linux/device.h>
#include <linux/kobject.h>

#include "cpuidle.h"

static ssize_t show_available_governors(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{}

static ssize_t show_current_driver(struct device *dev,
				   struct device_attribute *attr,
				   char *buf)
{}

static ssize_t show_current_governor(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{}

static ssize_t store_current_governor(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{}

static DEVICE_ATTR(available_governors, 0444, show_available_governors, NULL);
static DEVICE_ATTR(current_driver, 0444, show_current_driver, NULL);
static DEVICE_ATTR(current_governor, 0644, show_current_governor,
				   store_current_governor);
static DEVICE_ATTR(current_governor_ro, 0444, show_current_governor, NULL);

static struct attribute *cpuidle_attrs[] =;

static struct attribute_group cpuidle_attr_group =;

/**
 * cpuidle_add_interface - add CPU global sysfs attributes
 */
int cpuidle_add_interface(void)
{}

/**
 * cpuidle_remove_interface - remove CPU global sysfs attributes
 * @dev: the target device
 */
void cpuidle_remove_interface(struct device *dev)
{}

struct cpuidle_attr {};

#define attr_to_cpuidleattr(a)

struct cpuidle_device_kobj {};

static inline struct cpuidle_device *to_cpuidle_device(struct kobject *kobj)
{}

static ssize_t cpuidle_show(struct kobject *kobj, struct attribute *attr,
			    char *buf)
{}

static ssize_t cpuidle_store(struct kobject *kobj, struct attribute *attr,
			     const char *buf, size_t count)
{}

static const struct sysfs_ops cpuidle_sysfs_ops =;

static void cpuidle_sysfs_release(struct kobject *kobj)
{}

static const struct kobj_type ktype_cpuidle =;

struct cpuidle_state_attr {};

#define define_one_state_ro(_name, show)

#define define_one_state_rw(_name, show, store)

#define define_show_state_function(_name)

#define define_show_state_ull_function(_name)

#define define_show_state_str_function(_name)

#define define_show_state_time_function(_name)

define_show_state_time_function()
define_show_state_time_function()
define_show_state_function()
define_show_state_ull_function()
define_show_state_ull_function()
define_show_state_str_function()
define_show_state_str_function()
define_show_state_ull_function()
define_show_state_ull_function()

static ssize_t show_state_time(struct cpuidle_state *state,
			       struct cpuidle_state_usage *state_usage,
			       char *buf)
{}

static ssize_t show_state_disable(struct cpuidle_state *state,
				  struct cpuidle_state_usage *state_usage,
				  char *buf)
{}

static ssize_t store_state_disable(struct cpuidle_state *state,
				   struct cpuidle_state_usage *state_usage,
				   const char *buf, size_t size)
{}

static ssize_t show_state_default_status(struct cpuidle_state *state,
					  struct cpuidle_state_usage *state_usage,
					  char *buf)
{}

define_one_state_ro();
define_one_state_ro();
define_one_state_ro();
define_one_state_ro();
define_one_state_ro();
define_one_state_ro();
define_one_state_ro();
define_one_state_ro();
define_one_state_rw();
define_one_state_ro();
define_one_state_ro();
define_one_state_ro();

static struct attribute *cpuidle_state_default_attrs[] =;
ATTRIBUTE_GROUPS();

struct cpuidle_state_kobj {};

#ifdef CONFIG_SUSPEND
#define define_show_state_s2idle_ull_function(_name)

define_show_state_s2idle_ull_function(usage);
define_show_state_s2idle_ull_function(time);

#define define_one_state_s2idle_ro(_name, show)

define_one_state_s2idle_ro();
define_one_state_s2idle_ro();

static struct attribute *cpuidle_state_s2idle_attrs[] =;

static const struct attribute_group cpuidle_state_s2idle_group =;

static void cpuidle_add_s2idle_attr_group(struct cpuidle_state_kobj *kobj)
{}

static void cpuidle_remove_s2idle_attr_group(struct cpuidle_state_kobj *kobj)
{}
#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)
#define kobj_to_state(k)
#define kobj_to_state_usage(k)
#define kobj_to_device(k)
#define attr_to_stateattr(a)

static ssize_t cpuidle_state_show(struct kobject *kobj, struct attribute *attr,
				  char *buf)
{}

static ssize_t cpuidle_state_store(struct kobject *kobj, struct attribute *attr,
				   const char *buf, size_t size)
{}

static const struct sysfs_ops cpuidle_state_sysfs_ops =;

static void cpuidle_state_sysfs_release(struct kobject *kobj)
{}

static const struct kobj_type ktype_state_cpuidle =;

static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
{}

/**
 * cpuidle_add_state_sysfs - adds cpuidle states sysfs attributes
 * @device: the target device
 */
static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
{}

/**
 * cpuidle_remove_state_sysfs - removes the cpuidle states sysfs attributes
 * @device: the target device
 */
static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
{}

#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
#define kobj_to_driver_kobj
#define attr_to_driver_attr

#define define_one_driver_ro

struct cpuidle_driver_kobj {
	struct cpuidle_driver *drv;
	struct completion kobj_unregister;
	struct kobject kobj;
};

struct cpuidle_driver_attr {
	struct attribute attr;
	ssize_t (*show)(struct cpuidle_driver *, char *);
	ssize_t (*store)(struct cpuidle_driver *, const char *, size_t);
};

static ssize_t show_driver_name(struct cpuidle_driver *drv, char *buf)
{
	ssize_t ret;

	spin_lock(&cpuidle_driver_lock);
	ret = sprintf(buf, "%s\n", drv ? drv->name : "none");
	spin_unlock(&cpuidle_driver_lock);

	return ret;
}

static void cpuidle_driver_sysfs_release(struct kobject *kobj)
{
	struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
	complete(&driver_kobj->kobj_unregister);
}

static ssize_t cpuidle_driver_show(struct kobject *kobj, struct attribute *attr,
				   char *buf)
{
	int ret = -EIO;
	struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
	struct cpuidle_driver_attr *dattr = attr_to_driver_attr(attr);

	if (dattr->show)
		ret = dattr->show(driver_kobj->drv, buf);

	return ret;
}

static ssize_t cpuidle_driver_store(struct kobject *kobj, struct attribute *attr,
				    const char *buf, size_t size)
{
	int ret = -EIO;
	struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
	struct cpuidle_driver_attr *dattr = attr_to_driver_attr(attr);

	if (dattr->store)
		ret = dattr->store(driver_kobj->drv, buf, size);

	return ret;
}

define_one_driver_ro(name, show_driver_name);

static const struct sysfs_ops cpuidle_driver_sysfs_ops = {
	.show = cpuidle_driver_show,
	.store = cpuidle_driver_store,
};

static struct attribute *cpuidle_driver_default_attrs[] = {
	&attr_driver_name.attr,
	NULL
};
ATTRIBUTE_GROUPS(cpuidle_driver_default);

static const struct kobj_type ktype_driver_cpuidle = {
	.sysfs_ops = &cpuidle_driver_sysfs_ops,
	.default_groups = cpuidle_driver_default_groups,
	.release = cpuidle_driver_sysfs_release,
};

/**
 * cpuidle_add_driver_sysfs - adds the driver name sysfs attribute
 * @dev: the target device
 */
static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
{
	struct cpuidle_driver_kobj *kdrv;
	struct cpuidle_device_kobj *kdev = dev->kobj_dev;
	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
	int ret;

	kdrv = kzalloc(sizeof(*kdrv), GFP_KERNEL);
	if (!kdrv)
		return -ENOMEM;

	kdrv->drv = drv;
	init_completion(&kdrv->kobj_unregister);

	ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle,
				   &kdev->kobj, "driver");
	if (ret) {
		kobject_put(&kdrv->kobj);
		kfree(kdrv);
		return ret;
	}

	kobject_uevent(&kdrv->kobj, KOBJ_ADD);
	dev->kobj_driver = kdrv;

	return ret;
}

/**
 * cpuidle_remove_driver_sysfs - removes the driver name sysfs attribute
 * @dev: the target device
 */
static void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
{
	struct cpuidle_driver_kobj *kdrv = dev->kobj_driver;
	kobject_put(&kdrv->kobj);
	wait_for_completion(&kdrv->kobj_unregister);
	kfree(kdrv);
}
#else
static inline int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
{}

static inline void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
{}
#endif

/**
 * cpuidle_add_device_sysfs - adds device specific sysfs attributes
 * @device: the target device
 */
int cpuidle_add_device_sysfs(struct cpuidle_device *device)
{}

/**
 * cpuidle_remove_device_sysfs : removes device specific sysfs attributes
 * @device : the target device
 */
void cpuidle_remove_device_sysfs(struct cpuidle_device *device)
{}

/**
 * cpuidle_add_sysfs - creates a sysfs instance for the target device
 * @dev: the target device
 */
int cpuidle_add_sysfs(struct cpuidle_device *dev)
{}

/**
 * cpuidle_remove_sysfs - deletes a sysfs instance on the target device
 * @dev: the target device
 */
void cpuidle_remove_sysfs(struct cpuidle_device *dev)
{}