diff options
author | Shaohua Li <shaohua.li@intel.com> | 2006-05-08 01:45:57 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-06-21 15:40:48 -0400 |
commit | 670dd90d81f60ef429cbba54ad235e9207f4d444 (patch) | |
tree | 817c62329690f69cb32439d00c25023dfe977402 | |
parent | 1740757e8f94c6899705eb6f5434de9404992778 (diff) |
[PATCH] Driver Core: Allow sysdev_class have attributes
allow sysdev_class adding attribute. Next patch will use the new API to
add an attribute under /sys/device/system/cpu/.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/base/sys.c | 51 | ||||
-rw-r--r-- | include/linux/sysdev.h | 18 |
2 files changed, 67 insertions, 2 deletions
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 6fc23ab127b..6858178b3af 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -80,10 +80,59 @@ void sysdev_remove_file(struct sys_device * s, struct sysdev_attribute * a) | |||
80 | EXPORT_SYMBOL_GPL(sysdev_create_file); | 80 | EXPORT_SYMBOL_GPL(sysdev_create_file); |
81 | EXPORT_SYMBOL_GPL(sysdev_remove_file); | 81 | EXPORT_SYMBOL_GPL(sysdev_remove_file); |
82 | 82 | ||
83 | #define to_sysdev_class(k) container_of(k, struct sysdev_class, kset.kobj) | ||
84 | #define to_sysdev_class_attr(a) container_of(a, \ | ||
85 | struct sysdev_class_attribute, attr) | ||
86 | |||
87 | static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr, | ||
88 | char *buffer) | ||
89 | { | ||
90 | struct sysdev_class * class = to_sysdev_class(kobj); | ||
91 | struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); | ||
92 | |||
93 | if (class_attr->show) | ||
94 | return class_attr->show(class, buffer); | ||
95 | return -EIO; | ||
96 | } | ||
97 | |||
98 | static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr, | ||
99 | const char *buffer, size_t count) | ||
100 | { | ||
101 | struct sysdev_class * class = to_sysdev_class(kobj); | ||
102 | struct sysdev_class_attribute * class_attr = to_sysdev_class_attr(attr); | ||
103 | |||
104 | if (class_attr->store) | ||
105 | return class_attr->store(class, buffer, count); | ||
106 | return -EIO; | ||
107 | } | ||
108 | |||
109 | static struct sysfs_ops sysfs_class_ops = { | ||
110 | .show = sysdev_class_show, | ||
111 | .store = sysdev_class_store, | ||
112 | }; | ||
113 | |||
114 | static struct kobj_type ktype_sysdev_class = { | ||
115 | .sysfs_ops = &sysfs_class_ops, | ||
116 | }; | ||
117 | |||
118 | int sysdev_class_create_file(struct sysdev_class *c, | ||
119 | struct sysdev_class_attribute *a) | ||
120 | { | ||
121 | return sysfs_create_file(&c->kset.kobj, &a->attr); | ||
122 | } | ||
123 | EXPORT_SYMBOL_GPL(sysdev_class_create_file); | ||
124 | |||
125 | void sysdev_class_remove_file(struct sysdev_class *c, | ||
126 | struct sysdev_class_attribute *a) | ||
127 | { | ||
128 | sysfs_remove_file(&c->kset.kobj, &a->attr); | ||
129 | } | ||
130 | EXPORT_SYMBOL_GPL(sysdev_class_remove_file); | ||
131 | |||
83 | /* | 132 | /* |
84 | * declare system_subsys | 133 | * declare system_subsys |
85 | */ | 134 | */ |
86 | static decl_subsys(system, &ktype_sysdev, NULL); | 135 | static decl_subsys(system, &ktype_sysdev_class, NULL); |
87 | 136 | ||
88 | int sysdev_class_register(struct sysdev_class * cls) | 137 | int sysdev_class_register(struct sysdev_class * cls) |
89 | { | 138 | { |
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h index 2a4b432e117..166a2e58c28 100644 --- a/include/linux/sysdev.h +++ b/include/linux/sysdev.h | |||
@@ -37,11 +37,27 @@ struct sysdev_class { | |||
37 | struct kset kset; | 37 | struct kset kset; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | struct sysdev_class_attribute { | ||
41 | struct attribute attr; | ||
42 | ssize_t (*show)(struct sysdev_class *, char *); | ||
43 | ssize_t (*store)(struct sysdev_class *, const char *, size_t); | ||
44 | }; | ||
45 | |||
46 | #define SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \ | ||
47 | struct sysdev_class_attribute attr_##_name = { \ | ||
48 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | ||
49 | .show = _show, \ | ||
50 | .store = _store, \ | ||
51 | }; | ||
52 | |||
40 | 53 | ||
41 | extern int sysdev_class_register(struct sysdev_class *); | 54 | extern int sysdev_class_register(struct sysdev_class *); |
42 | extern void sysdev_class_unregister(struct sysdev_class *); | 55 | extern void sysdev_class_unregister(struct sysdev_class *); |
43 | 56 | ||
44 | 57 | extern int sysdev_class_create_file(struct sysdev_class *, | |
58 | struct sysdev_class_attribute *); | ||
59 | extern void sysdev_class_remove_file(struct sysdev_class *, | ||
60 | struct sysdev_class_attribute *); | ||
45 | /** | 61 | /** |
46 | * Auxillary system device drivers. | 62 | * Auxillary system device drivers. |
47 | */ | 63 | */ |