13 #include <linux/ctype.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
21 #define EDAC_DEVICE_SYMLINK "device"
23 #define to_edacdev(k) container_of(k, struct edac_device_ctl_info, kobj)
24 #define to_edacdev_attr(a) container_of(a, struct edacdev_attribute, attr)
33 *ctl_info,
char *
data)
39 *ctl_info,
const char *
data,
50 *ctl_info,
char *
data)
56 *ctl_info,
const char *
data,
67 *ctl_info,
char *
data)
73 *ctl_info,
const char *
data,
84 *ctl_info,
char *
data)
90 *ctl_info,
const char *
data,
113 #define to_ctl_info(k) container_of(k, struct edac_device_ctl_info, kobj)
114 #define to_ctl_info_attr(a) container_of(a,struct ctl_info_attribute,attr)
123 if (ctl_info_attr->
show)
124 return ctl_info_attr->
show(edac_dev, buffer);
136 if (ctl_info_attr->
store)
137 return ctl_info_attr->
store(edac_dev, buffer, count);
142 static const struct sysfs_ops device_ctl_info_ops = {
143 .show = edac_dev_ctl_info_show,
144 .store = edac_dev_ctl_info_store
147 #define CTL_INFO_ATTR(_name,_mode,_show,_store) \
148 static struct ctl_info_attribute attr_ctl_info_##_name = { \
149 .attr = {.name = __stringify(_name), .mode = _mode }, \
156 edac_device_ctl_log_ue_show, edac_device_ctl_log_ue_store);
158 edac_device_ctl_log_ce_show, edac_device_ctl_log_ce_store);
160 edac_device_ctl_panic_on_ue_show,
161 edac_device_ctl_panic_on_ue_store);
163 edac_device_ctl_poll_msec_show, edac_device_ctl_poll_msec_store);
167 &attr_ctl_info_panic_on_ue,
168 &attr_ctl_info_log_ue,
169 &attr_ctl_info_log_ce,
170 &attr_ctl_info_poll_msec,
201 static void edac_device_ctrl_master_release(
struct kobject *kobj)
208 module_put(edac_dev->
owner);
217 static struct kobj_type ktype_device_ctrl = {
218 .release = edac_device_ctrl_master_release,
219 .sysfs_ops = &device_ctl_info_ops,
220 .default_attrs = (
struct attribute **)device_ctrl_attr,
240 if (edac_subsys ==
NULL) {
241 edac_dbg(1,
"no edac_subsys error\n");
257 if (!try_module_get(edac_dev->
owner)) {
265 "%s", edac_dev->
name);
267 edac_dbg(1,
"Failed to register '.../edac/%s'\n",
277 edac_dbg(4,
"Registered '.../edac/%s' kobject\n", edac_dev->
name);
283 module_put(edac_dev->
owner);
299 edac_dbg(4,
"name of kobject is: %s\n", kobject_name(&dev->
kobj));
329 #define to_instance(k) container_of(k, struct edac_device_instance, kobj)
330 #define to_instance_attr(a) container_of(a,struct instance_attribute,attr)
333 static void edac_device_ctrl_instance_release(
struct kobject *kobj)
360 if (instance_attr->
show)
361 return instance_attr->
show(instance, buffer);
368 const char *buffer,
size_t count)
373 if (instance_attr->
store)
374 return instance_attr->
store(instance, buffer, count);
379 static const struct sysfs_ops device_instance_ops = {
380 .show = edac_dev_instance_show,
381 .store = edac_dev_instance_store
384 #define INSTANCE_ATTR(_name,_mode,_show,_store) \
385 static struct instance_attribute attr_instance_##_name = { \
386 .attr = {.name = __stringify(_name), .mode = _mode }, \
401 &attr_instance_ce_count,
402 &attr_instance_ue_count,
407 static struct kobj_type ktype_instance_ctrl = {
408 .release = edac_device_ctrl_instance_release,
409 .sysfs_ops = &device_instance_ops,
410 .default_attrs = (
struct attribute **)device_instance_attr,
415 #define to_block(k) container_of(k, struct edac_device_block, kobj)
416 #define to_block_attr(a) \
417 container_of(a, struct edac_dev_sysfs_block_attribute, attr)
439 static void edac_device_ctrl_block_release(
struct kobject *kobj)
462 if (block_attr->
show)
463 return block_attr->
show(kobj, attr, buffer);
470 const char *buffer,
size_t count)
476 if (block_attr->
store)
477 return block_attr->
store(kobj, attr, buffer, count);
482 static const struct sysfs_ops device_block_ops = {
483 .show = edac_dev_block_show,
484 .store = edac_dev_block_store
487 #define BLOCK_ATTR(_name,_mode,_show,_store) \
488 static struct edac_dev_sysfs_block_attribute attr_block_##_name = { \
489 .attr = {.name = __stringify(_name), .mode = _mode }, \
499 &attr_block_ce_count,
500 &attr_block_ue_count,
505 static struct kobj_type ktype_block_ctrl = {
506 .release = edac_device_ctrl_block_release,
507 .sysfs_ops = &device_block_ops,
508 .default_attrs = (
struct attribute **)device_block_attr,
525 edac_dbg(4,
"Instance '%s' inst_p=%p block '%s' block_p=%p\n",
526 instance->
name, instance, block->
name, block);
527 edac_dbg(4,
"block kobj=%p block kobj->parent=%p\n",
547 edac_dbg(1,
"Failed to register instance '%s'\n", block->
name);
558 for (i = 0; i < block->
nr_attribs; i++, sysfs_attrib++) {
560 edac_dbg(4,
"creating block attrib='%s' attrib->%p to kobj=%p\n",
561 sysfs_attrib->
attr.name,
562 sysfs_attrib, &block->
kobj);
566 &sysfs_attrib->
attr);
597 for (i = 0; i < block->
nr_attribs; i++, sysfs_attrib++) {
630 instance->
ctl = edac_dev;
643 &edac_dev->
kobj,
"%s", instance->
name);
645 edac_dbg(2,
"Failed to register instance '%s'\n",
651 edac_dbg(4,
"now register '%d' blocks for instance %d\n",
655 for (i = 0; i < instance->
nr_blocks; i++) {
656 err = edac_device_create_block(edac_dev, instance,
660 for (j = 0; j <
i; j++)
661 edac_device_delete_block(edac_dev,
663 goto err_release_instance_kobj;
668 edac_dbg(4,
"Registered instance %d '%s' kobject\n",
669 idx, instance->
name);
674 err_release_instance_kobj:
694 for (i = 0; i < instance->
nr_blocks; i++)
695 edac_device_delete_block(edac_dev, &instance->
blocks[i]);
717 err = edac_device_create_instance(edac_dev, i);
720 for (j = 0; j <
i; j++)
721 edac_device_delete_instance(edac_dev, j);
739 edac_device_delete_instance(edac_dev, i);
748 static int edac_device_add_main_sysfs_attributes(
759 while (sysfs_attrib->
attr.name !=
NULL) {
777 static void edac_device_remove_main_sysfs_attributes(
788 while (sysfs_attrib->
attr.name !=
NULL) {
818 err = edac_device_add_main_sysfs_attributes(edac_dev);
820 edac_dbg(0,
"failed to add sysfs attribs\n");
830 edac_dbg(0,
"sysfs_create_link() returned err= %d\n", err);
831 goto err_remove_main_attribs;
838 err = edac_device_create_instances(edac_dev);
840 edac_dbg(0,
"edac_device_create_instances() returned err= %d\n",
842 goto err_remove_link;
855 err_remove_main_attribs:
856 edac_device_remove_main_sysfs_attributes(edac_dev);
872 edac_device_remove_main_sysfs_attributes(edac_dev);
878 edac_device_delete_instances(edac_dev);