Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * file for managing the edac_device class of devices for EDAC |
| 3 | * |
| 4 | * (C) 2007 SoftwareBitMaker(http://www.softwarebitmaker.com) |
| 5 | * This file may be distributed under the terms of the |
| 6 | * GNU General Public License. |
| 7 | * |
| 8 | * Written Doug Thompson <norsk5@xmission.com> |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/sysdev.h> |
| 14 | #include <linux/ctype.h> |
| 15 | |
| 16 | #include "edac_core.h" |
| 17 | #include "edac_module.h" |
| 18 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 19 | #define EDAC_DEVICE_SYMLINK "device" |
| 20 | |
| 21 | #define to_edacdev(k) container_of(k, struct edac_device_ctl_info, kobj) |
| 22 | #define to_edacdev_attr(a) container_of(a, struct edacdev_attribute, attr) |
| 23 | |
| 24 | #ifdef DKT |
| 25 | |
| 26 | static ssize_t edac_dev_ue_count_show(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 27 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 28 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 29 | return sprintf(data, "%d\n", edac_dev->ue_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static ssize_t edac_dev_ce_count_show(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 33 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 34 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 35 | return sprintf(data, "%d\n", edac_dev->ce_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static ssize_t edac_dev_seconds_show(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 39 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 40 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 41 | return sprintf(data, "%ld\n", (jiffies - edac_dev->start_time) / HZ); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static ssize_t edac_dev_ctl_name_show(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 45 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 46 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 47 | return sprintf(data, "%s\n", edac_dev->ctl_name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 50 | struct edacdev_attribute { |
| 51 | struct attribute attr; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 52 | ssize_t(*show) (struct edac_device_ctl_info *, char *); |
| 53 | ssize_t(*store) (struct edac_device_ctl_info *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 56 | /* EDAC DEVICE show/store functions for top most object */ |
| 57 | static ssize_t edacdev_show(struct kobject *kobj, struct attribute *attr, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 58 | char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 59 | { |
| 60 | struct edac_device_ctl_info *edac_dev = to_edacdev(kobj); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 61 | struct edacdev_attribute *edacdev_attr = to_edacdev_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 62 | |
| 63 | if (edacdev_attr->show) |
| 64 | return edacdev_attr->show(edac_dev, buffer); |
| 65 | |
| 66 | return -EIO; |
| 67 | } |
| 68 | |
| 69 | static ssize_t edacdev_store(struct kobject *kobj, struct attribute *attr, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 70 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 71 | { |
| 72 | struct edac_device_ctl_info *edac_dev = to_edacdev(kobj); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 73 | struct edacdev_attribute *edacdev_attr = to_edacdev_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 74 | |
| 75 | if (edacdev_attr->store) |
| 76 | return edacdev_attr->store(edac_dev, buffer, count); |
| 77 | |
| 78 | return -EIO; |
| 79 | } |
| 80 | |
| 81 | static struct sysfs_ops edac_dev_ops = { |
| 82 | .show = edacdev_show, |
| 83 | .store = edacdev_store |
| 84 | }; |
| 85 | |
| 86 | #define EDACDEV_ATTR(_name,_mode,_show,_store) \ |
| 87 | static struct edacdev_attribute edac_dev_attr_##_name = { \ |
| 88 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 89 | .show = _show, \ |
| 90 | .store = _store, \ |
| 91 | }; |
| 92 | |
| 93 | /* default Control file */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 94 | EDACDEV_ATTR(reset_counters, S_IWUSR, NULL, edac_dev_reset_counters_store); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* default Attribute files */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 97 | EDACDEV_ATTR(mc_name, S_IRUGO, edac_dev_ctl_name_show, NULL); |
| 98 | EDACDEV_ATTR(seconds_since_reset, S_IRUGO, edac_dev_seconds_show, NULL); |
| 99 | EDACDEV_ATTR(ue_count, S_IRUGO, edac_dev_ue_count_show, NULL); |
| 100 | EDACDEV_ATTR(ce_count, S_IRUGO, edac_dev_ce_count_show, NULL); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 101 | |
| 102 | static struct edacdev_attribute *edacdev_attr[] = { |
| 103 | &edacdev_attr_reset_counters, |
| 104 | &edacdev_attr_mc_name, |
| 105 | &edacdev_attr_seconds_since_reset, |
| 106 | &edacdev_attr_ue_count, |
| 107 | &edacdev_attr_ce_count, |
| 108 | NULL |
| 109 | }; |
| 110 | |
| 111 | /* |
| 112 | * Release of a Edac Device controlling instance |
| 113 | */ |
| 114 | static void edac_dev_instance_release(struct kobject *kobj) |
| 115 | { |
| 116 | struct edac_device_ctl_info *edac_dev; |
| 117 | |
| 118 | edac_dev = to_edacdev(kobj); |
| 119 | debugf0("%s() idx=%d\n", __func__, edac_dev->dev_idx); |
| 120 | complete(&edac_dev->kobj_complete); |
| 121 | } |
| 122 | |
| 123 | static struct kobj_type ktype_device = { |
| 124 | .release = edac_dev_instance_release, |
| 125 | .sysfs_ops = &edacdev_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 126 | .default_attrs = (struct attribute **)edacdev_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | #endif |
| 130 | |
| 131 | /************************** edac_device sysfs code and data **************/ |
| 132 | |
| 133 | /* |
| 134 | * Set of edac_device_ctl_info attribute store/show functions |
| 135 | */ |
| 136 | |
| 137 | /* 'log_ue' */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 138 | static ssize_t edac_device_ctl_log_ue_show(struct edac_device_ctl_info |
| 139 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 140 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 141 | return sprintf(data, "%u\n", ctl_info->log_ue); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 144 | static ssize_t edac_device_ctl_log_ue_store(struct edac_device_ctl_info |
| 145 | *ctl_info, const char *data, |
| 146 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 147 | { |
| 148 | /* if parameter is zero, turn off flag, if non-zero turn on flag */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 149 | ctl_info->log_ue = (simple_strtoul(data, NULL, 0) != 0); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 150 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 151 | return count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* 'log_ce' */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 155 | static ssize_t edac_device_ctl_log_ce_show(struct edac_device_ctl_info |
| 156 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 157 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 158 | return sprintf(data, "%u\n", ctl_info->log_ce); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 161 | static ssize_t edac_device_ctl_log_ce_store(struct edac_device_ctl_info |
| 162 | *ctl_info, const char *data, |
| 163 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 164 | { |
| 165 | /* if parameter is zero, turn off flag, if non-zero turn on flag */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 166 | ctl_info->log_ce = (simple_strtoul(data, NULL, 0) != 0); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 167 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 168 | return count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 171 | /* 'panic_on_ue' */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 172 | static ssize_t edac_device_ctl_panic_on_ue_show(struct edac_device_ctl_info |
| 173 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 174 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 175 | return sprintf(data, "%u\n", ctl_info->panic_on_ue); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 178 | static ssize_t edac_device_ctl_panic_on_ue_store(struct edac_device_ctl_info |
| 179 | *ctl_info, const char *data, |
| 180 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 181 | { |
| 182 | /* if parameter is zero, turn off flag, if non-zero turn on flag */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 183 | ctl_info->panic_on_ue = (simple_strtoul(data, NULL, 0) != 0); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 184 | |
| 185 | return count; |
| 186 | } |
| 187 | |
| 188 | /* 'poll_msec' show and store functions*/ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 189 | static ssize_t edac_device_ctl_poll_msec_show(struct edac_device_ctl_info |
| 190 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 191 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 192 | return sprintf(data, "%u\n", ctl_info->poll_msec); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 195 | static ssize_t edac_device_ctl_poll_msec_store(struct edac_device_ctl_info |
| 196 | *ctl_info, const char *data, |
| 197 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 198 | { |
| 199 | unsigned long value; |
| 200 | |
| 201 | /* get the value and enforce that it is non-zero, must be at least |
| 202 | * one millisecond for the delay period, between scans |
| 203 | * Then cancel last outstanding delay for the work request |
| 204 | * and set a new one. |
| 205 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 206 | value = simple_strtoul(data, NULL, 0); |
| 207 | edac_device_reset_delay_period(ctl_info, value); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 208 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 209 | return count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 212 | /* edac_device_ctl_info specific attribute structure */ |
| 213 | struct ctl_info_attribute { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 214 | struct attribute attr; |
| 215 | ssize_t(*show) (struct edac_device_ctl_info *, char *); |
| 216 | ssize_t(*store) (struct edac_device_ctl_info *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | #define to_ctl_info(k) container_of(k, struct edac_device_ctl_info, kobj) |
| 220 | #define to_ctl_info_attr(a) container_of(a,struct ctl_info_attribute,attr) |
| 221 | |
| 222 | /* Function to 'show' fields from the edac_dev 'ctl_info' structure */ |
| 223 | static ssize_t edac_dev_ctl_info_show(struct kobject *kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 224 | struct attribute *attr, char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 225 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 226 | struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj); |
| 227 | struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 228 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 229 | if (ctl_info_attr->show) |
| 230 | return ctl_info_attr->show(edac_dev, buffer); |
| 231 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /* Function to 'store' fields into the edac_dev 'ctl_info' structure */ |
| 235 | static ssize_t edac_dev_ctl_info_store(struct kobject *kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 236 | struct attribute *attr, |
| 237 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 238 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 239 | struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj); |
| 240 | struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 241 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 242 | if (ctl_info_attr->store) |
| 243 | return ctl_info_attr->store(edac_dev, buffer, count); |
| 244 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /* edac_dev file operations for an 'ctl_info' */ |
| 248 | static struct sysfs_ops device_ctl_info_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 249 | .show = edac_dev_ctl_info_show, |
| 250 | .store = edac_dev_ctl_info_store |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | #define CTL_INFO_ATTR(_name,_mode,_show,_store) \ |
| 254 | static struct ctl_info_attribute attr_ctl_info_##_name = { \ |
| 255 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 256 | .show = _show, \ |
| 257 | .store = _store, \ |
| 258 | }; |
| 259 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 260 | /* Declare the various ctl_info attributes here and their respective ops */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 261 | CTL_INFO_ATTR(log_ue, S_IRUGO | S_IWUSR, |
| 262 | edac_device_ctl_log_ue_show, edac_device_ctl_log_ue_store); |
| 263 | CTL_INFO_ATTR(log_ce, S_IRUGO | S_IWUSR, |
| 264 | edac_device_ctl_log_ce_show, edac_device_ctl_log_ce_store); |
| 265 | CTL_INFO_ATTR(panic_on_ue, S_IRUGO | S_IWUSR, |
| 266 | edac_device_ctl_panic_on_ue_show, |
| 267 | edac_device_ctl_panic_on_ue_store); |
| 268 | CTL_INFO_ATTR(poll_msec, S_IRUGO | S_IWUSR, |
| 269 | edac_device_ctl_poll_msec_show, edac_device_ctl_poll_msec_store); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 270 | |
| 271 | /* Base Attributes of the EDAC_DEVICE ECC object */ |
| 272 | static struct ctl_info_attribute *device_ctrl_attr[] = { |
| 273 | &attr_ctl_info_panic_on_ue, |
| 274 | &attr_ctl_info_log_ue, |
| 275 | &attr_ctl_info_log_ce, |
| 276 | &attr_ctl_info_poll_msec, |
| 277 | NULL, |
| 278 | }; |
| 279 | |
| 280 | /* Main DEVICE kobject release() function */ |
| 281 | static void edac_device_ctrl_master_release(struct kobject *kobj) |
| 282 | { |
| 283 | struct edac_device_ctl_info *edac_dev; |
| 284 | |
| 285 | edac_dev = to_edacdev(kobj); |
| 286 | |
| 287 | debugf1("%s()\n", __func__); |
| 288 | complete(&edac_dev->kobj_complete); |
| 289 | } |
| 290 | |
| 291 | static struct kobj_type ktype_device_ctrl = { |
| 292 | .release = edac_device_ctrl_master_release, |
| 293 | .sysfs_ops = &device_ctl_info_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 294 | .default_attrs = (struct attribute **)device_ctrl_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 295 | }; |
| 296 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 297 | /**************** edac_device main kobj ctor/dtor code *********************/ |
| 298 | |
| 299 | /* |
| 300 | * edac_device_register_main_kobj |
| 301 | * |
| 302 | * perform the high level setup for the new edac_device instance |
| 303 | * |
| 304 | * Return: 0 SUCCESS |
| 305 | * !0 FAILURE |
| 306 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 307 | static int edac_device_register_main_kobj(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 308 | { |
| 309 | int err = 0; |
| 310 | struct sysdev_class *edac_class; |
| 311 | |
| 312 | debugf1("%s()\n", __func__); |
| 313 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 314 | /* get the /sys/devices/system/edac reference */ |
| 315 | edac_class = edac_get_edac_class(); |
| 316 | if (edac_class == NULL) { |
| 317 | debugf1("%s() no edac_class error=%d\n", __func__, err); |
| 318 | return err; |
| 319 | } |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 320 | |
| 321 | /* Point to the 'edac_class' this instance 'reports' to */ |
| 322 | edac_dev->edac_class = edac_class; |
| 323 | |
| 324 | /* Init the devices's kobject */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 325 | memset(&edac_dev->kobj, 0, sizeof(struct kobject)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 326 | edac_dev->kobj.ktype = &ktype_device_ctrl; |
| 327 | |
| 328 | /* set this new device under the edac_class kobject */ |
| 329 | edac_dev->kobj.parent = &edac_class->kset.kobj; |
| 330 | |
| 331 | /* generate sysfs "..../edac/<name>" */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 332 | debugf1("%s() set name of kobject to: %s\n", __func__, edac_dev->name); |
| 333 | err = kobject_set_name(&edac_dev->kobj, "%s", edac_dev->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 334 | if (err) |
| 335 | return err; |
| 336 | err = kobject_register(&edac_dev->kobj); |
| 337 | if (err) { |
| 338 | debugf1("%s()Failed to register '.../edac/%s'\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 339 | __func__, edac_dev->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 340 | return err; |
| 341 | } |
| 342 | |
| 343 | debugf1("%s() Registered '.../edac/%s' kobject\n", |
| 344 | __func__, edac_dev->name); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * edac_device_unregister_main_kobj: |
| 351 | * the '..../edac/<name>' kobject |
| 352 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 353 | static void edac_device_unregister_main_kobj(struct edac_device_ctl_info |
| 354 | *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 355 | { |
| 356 | debugf0("%s()\n", __func__); |
| 357 | debugf1("%s() name of kobject is: %s\n", |
| 358 | __func__, kobject_name(&edac_dev->kobj)); |
| 359 | |
| 360 | init_completion(&edac_dev->kobj_complete); |
| 361 | |
| 362 | /* |
| 363 | * Unregister the edac device's kobject and |
| 364 | * wait for reference count to reach 0. |
| 365 | */ |
| 366 | kobject_unregister(&edac_dev->kobj); |
| 367 | wait_for_completion(&edac_dev->kobj_complete); |
| 368 | } |
| 369 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 370 | /*************** edac_dev -> instance information ***********/ |
| 371 | |
| 372 | /* |
| 373 | * Set of low-level instance attribute show functions |
| 374 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 375 | static ssize_t instance_ue_count_show(struct edac_device_instance *instance, |
| 376 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 377 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 378 | return sprintf(data, "%u\n", instance->counters.ue_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 381 | static ssize_t instance_ce_count_show(struct edac_device_instance *instance, |
| 382 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 383 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 384 | return sprintf(data, "%u\n", instance->counters.ce_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 387 | #define to_instance(k) container_of(k, struct edac_device_instance, kobj) |
| 388 | #define to_instance_attr(a) container_of(a,struct instance_attribute,attr) |
| 389 | |
| 390 | /* DEVICE instance kobject release() function */ |
| 391 | static void edac_device_ctrl_instance_release(struct kobject *kobj) |
| 392 | { |
| 393 | struct edac_device_instance *instance; |
| 394 | |
| 395 | debugf1("%s()\n", __func__); |
| 396 | |
| 397 | instance = to_instance(kobj); |
| 398 | complete(&instance->kobj_complete); |
| 399 | } |
| 400 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 401 | /* instance specific attribute structure */ |
| 402 | struct instance_attribute { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 403 | struct attribute attr; |
| 404 | ssize_t(*show) (struct edac_device_instance *, char *); |
| 405 | ssize_t(*store) (struct edac_device_instance *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 406 | }; |
| 407 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 408 | /* Function to 'show' fields from the edac_dev 'instance' structure */ |
| 409 | static ssize_t edac_dev_instance_show(struct kobject *kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 410 | struct attribute *attr, char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 411 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 412 | struct edac_device_instance *instance = to_instance(kobj); |
| 413 | struct instance_attribute *instance_attr = to_instance_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 414 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 415 | if (instance_attr->show) |
| 416 | return instance_attr->show(instance, buffer); |
| 417 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 420 | /* Function to 'store' fields into the edac_dev 'instance' structure */ |
| 421 | static ssize_t edac_dev_instance_store(struct kobject *kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 422 | struct attribute *attr, |
| 423 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 424 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 425 | struct edac_device_instance *instance = to_instance(kobj); |
| 426 | struct instance_attribute *instance_attr = to_instance_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 427 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 428 | if (instance_attr->store) |
| 429 | return instance_attr->store(instance, buffer, count); |
| 430 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 433 | /* edac_dev file operations for an 'instance' */ |
| 434 | static struct sysfs_ops device_instance_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 435 | .show = edac_dev_instance_show, |
| 436 | .store = edac_dev_instance_store |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | #define INSTANCE_ATTR(_name,_mode,_show,_store) \ |
| 440 | static struct instance_attribute attr_instance_##_name = { \ |
| 441 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 442 | .show = _show, \ |
| 443 | .store = _store, \ |
| 444 | }; |
| 445 | |
| 446 | /* |
| 447 | * Define attributes visible for the edac_device instance object |
| 448 | * Each contains a pointer to a show and an optional set |
| 449 | * function pointer that does the low level output/input |
| 450 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 451 | INSTANCE_ATTR(ce_count, S_IRUGO, instance_ce_count_show, NULL); |
| 452 | INSTANCE_ATTR(ue_count, S_IRUGO, instance_ue_count_show, NULL); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 453 | |
| 454 | /* list of edac_dev 'instance' attributes */ |
| 455 | static struct instance_attribute *device_instance_attr[] = { |
| 456 | &attr_instance_ce_count, |
| 457 | &attr_instance_ue_count, |
| 458 | NULL, |
| 459 | }; |
| 460 | |
| 461 | /* The 'ktype' for each edac_dev 'instance' */ |
| 462 | static struct kobj_type ktype_instance_ctrl = { |
| 463 | .release = edac_device_ctrl_instance_release, |
| 464 | .sysfs_ops = &device_instance_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 465 | .default_attrs = (struct attribute **)device_instance_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 466 | }; |
| 467 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 468 | /*************** edac_dev -> instance -> block information *********/ |
| 469 | |
| 470 | /* |
| 471 | * Set of low-level block attribute show functions |
| 472 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 473 | static ssize_t block_ue_count_show(struct edac_device_block *block, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 474 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 475 | return sprintf(data, "%u\n", block->counters.ue_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 478 | static ssize_t block_ce_count_show(struct edac_device_block *block, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 479 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 480 | return sprintf(data, "%u\n", block->counters.ce_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 483 | #define to_block(k) container_of(k, struct edac_device_block, kobj) |
| 484 | #define to_block_attr(a) container_of(a,struct block_attribute,attr) |
| 485 | |
| 486 | /* DEVICE block kobject release() function */ |
| 487 | static void edac_device_ctrl_block_release(struct kobject *kobj) |
| 488 | { |
| 489 | struct edac_device_block *block; |
| 490 | |
| 491 | debugf1("%s()\n", __func__); |
| 492 | |
| 493 | block = to_block(kobj); |
| 494 | complete(&block->kobj_complete); |
| 495 | } |
| 496 | |
| 497 | /* block specific attribute structure */ |
| 498 | struct block_attribute { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 499 | struct attribute attr; |
| 500 | ssize_t(*show) (struct edac_device_block *, char *); |
| 501 | ssize_t(*store) (struct edac_device_block *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 502 | }; |
| 503 | |
| 504 | /* Function to 'show' fields from the edac_dev 'block' structure */ |
| 505 | static ssize_t edac_dev_block_show(struct kobject *kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 506 | struct attribute *attr, char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 507 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 508 | struct edac_device_block *block = to_block(kobj); |
| 509 | struct block_attribute *block_attr = to_block_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 510 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 511 | if (block_attr->show) |
| 512 | return block_attr->show(block, buffer); |
| 513 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 516 | /* Function to 'store' fields into the edac_dev 'block' structure */ |
| 517 | static ssize_t edac_dev_block_store(struct kobject *kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 518 | struct attribute *attr, |
| 519 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 520 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 521 | struct edac_device_block *block = to_block(kobj); |
| 522 | struct block_attribute *block_attr = to_block_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 523 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 524 | if (block_attr->store) |
| 525 | return block_attr->store(block, buffer, count); |
| 526 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 529 | /* edac_dev file operations for a 'block' */ |
| 530 | static struct sysfs_ops device_block_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 531 | .show = edac_dev_block_show, |
| 532 | .store = edac_dev_block_store |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 533 | }; |
| 534 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 535 | #define BLOCK_ATTR(_name,_mode,_show,_store) \ |
| 536 | static struct block_attribute attr_block_##_name = { \ |
| 537 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 538 | .show = _show, \ |
| 539 | .store = _store, \ |
| 540 | }; |
| 541 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 542 | BLOCK_ATTR(ce_count, S_IRUGO, block_ce_count_show, NULL); |
| 543 | BLOCK_ATTR(ue_count, S_IRUGO, block_ue_count_show, NULL); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 544 | |
| 545 | /* list of edac_dev 'block' attributes */ |
| 546 | static struct block_attribute *device_block_attr[] = { |
| 547 | &attr_block_ce_count, |
| 548 | &attr_block_ue_count, |
| 549 | NULL, |
| 550 | }; |
| 551 | |
| 552 | /* The 'ktype' for each edac_dev 'block' */ |
| 553 | static struct kobj_type ktype_block_ctrl = { |
| 554 | .release = edac_device_ctrl_block_release, |
| 555 | .sysfs_ops = &device_block_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 556 | .default_attrs = (struct attribute **)device_block_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 557 | }; |
| 558 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 559 | /************** block ctor/dtor code ************/ |
| 560 | |
| 561 | /* |
| 562 | * edac_device_create_block |
| 563 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 564 | static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, |
| 565 | struct edac_device_instance *instance, |
| 566 | int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 567 | { |
| 568 | int err; |
| 569 | struct edac_device_block *block; |
| 570 | |
| 571 | block = &instance->blocks[idx]; |
| 572 | |
| 573 | debugf1("%s() Instance '%s' block[%d] '%s'\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 574 | __func__, instance->name, idx, block->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 575 | |
| 576 | /* init this block's kobject */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 577 | memset(&block->kobj, 0, sizeof(struct kobject)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 578 | block->kobj.parent = &instance->kobj; |
| 579 | block->kobj.ktype = &ktype_block_ctrl; |
| 580 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 581 | err = kobject_set_name(&block->kobj, "%s", block->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 582 | if (err) |
| 583 | return err; |
| 584 | |
| 585 | err = kobject_register(&block->kobj); |
| 586 | if (err) { |
| 587 | debugf1("%s()Failed to register instance '%s'\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 588 | __func__, block->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 589 | return err; |
| 590 | } |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * edac_device_delete_block(edac_dev,j); |
| 597 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 598 | static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev, |
| 599 | struct edac_device_instance *instance, |
| 600 | int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 601 | { |
| 602 | struct edac_device_block *block; |
| 603 | |
| 604 | block = &instance->blocks[idx]; |
| 605 | |
| 606 | /* unregister this block's kobject */ |
| 607 | init_completion(&block->kobj_complete); |
| 608 | kobject_unregister(&block->kobj); |
| 609 | wait_for_completion(&block->kobj_complete); |
| 610 | } |
| 611 | |
| 612 | /************** instance ctor/dtor code ************/ |
| 613 | |
| 614 | /* |
| 615 | * edac_device_create_instance |
| 616 | * create just one instance of an edac_device 'instance' |
| 617 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 618 | static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, |
| 619 | int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 620 | { |
| 621 | int i, j; |
| 622 | int err; |
| 623 | struct edac_device_instance *instance; |
| 624 | |
| 625 | instance = &edac_dev->instances[idx]; |
| 626 | |
| 627 | /* Init the instance's kobject */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 628 | memset(&instance->kobj, 0, sizeof(struct kobject)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 629 | |
| 630 | /* set this new device under the edac_device main kobject */ |
| 631 | instance->kobj.parent = &edac_dev->kobj; |
| 632 | instance->kobj.ktype = &ktype_instance_ctrl; |
| 633 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 634 | err = kobject_set_name(&instance->kobj, "%s", instance->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 635 | if (err) |
| 636 | return err; |
| 637 | |
| 638 | err = kobject_register(&instance->kobj); |
| 639 | if (err != 0) { |
| 640 | debugf2("%s() Failed to register instance '%s'\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 641 | __func__, instance->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 642 | return err; |
| 643 | } |
| 644 | |
| 645 | debugf1("%s() now register '%d' blocks for instance %d\n", |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 646 | __func__, instance->nr_blocks, idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 647 | |
| 648 | /* register all blocks of this instance */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 649 | for (i = 0; i < instance->nr_blocks; i++) { |
| 650 | err = edac_device_create_block(edac_dev, instance, i); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 651 | if (err) { |
| 652 | for (j = 0; j < i; j++) { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 653 | edac_device_delete_block(edac_dev, instance, j); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 654 | } |
| 655 | return err; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | debugf1("%s() Registered instance %d '%s' kobject\n", |
| 660 | __func__, idx, instance->name); |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | /* |
| 666 | * edac_device_remove_instance |
| 667 | * remove an edac_device instance |
| 668 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 669 | static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev, |
| 670 | int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 671 | { |
| 672 | int i; |
| 673 | struct edac_device_instance *instance; |
| 674 | |
| 675 | instance = &edac_dev->instances[idx]; |
| 676 | |
| 677 | /* unregister all blocks in this instance */ |
| 678 | for (i = 0; i < instance->nr_blocks; i++) { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 679 | edac_device_delete_block(edac_dev, instance, i); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /* unregister this instance's kobject */ |
| 683 | init_completion(&instance->kobj_complete); |
| 684 | kobject_unregister(&instance->kobj); |
| 685 | wait_for_completion(&instance->kobj_complete); |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | * edac_device_create_instances |
| 690 | * create the first level of 'instances' for this device |
| 691 | * (ie 'cache' might have 'cache0', 'cache1', 'cache2', etc |
| 692 | */ |
| 693 | static int edac_device_create_instances(struct edac_device_ctl_info *edac_dev) |
| 694 | { |
| 695 | int i, j; |
| 696 | int err; |
| 697 | |
| 698 | debugf0("%s()\n", __func__); |
| 699 | |
| 700 | /* iterate over creation of the instances */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 701 | for (i = 0; i < edac_dev->nr_instances; i++) { |
| 702 | err = edac_device_create_instance(edac_dev, i); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 703 | if (err) { |
| 704 | /* unwind previous instances on error */ |
| 705 | for (j = 0; j < i; j++) { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 706 | edac_device_delete_instance(edac_dev, j); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 707 | } |
| 708 | return err; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * edac_device_delete_instances(edac_dev); |
| 717 | * unregister all the kobjects of the instances |
| 718 | */ |
| 719 | static void edac_device_delete_instances(struct edac_device_ctl_info *edac_dev) |
| 720 | { |
| 721 | int i; |
| 722 | |
| 723 | /* iterate over creation of the instances */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 724 | for (i = 0; i < edac_dev->nr_instances; i++) { |
| 725 | edac_device_delete_instance(edac_dev, i); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | /******************* edac_dev sysfs ctor/dtor code *************/ |
| 730 | |
| 731 | /* |
| 732 | * edac_device_create_sysfs() Constructor |
| 733 | * |
| 734 | * Create a new edac_device kobject instance, |
| 735 | * |
| 736 | * Return: |
| 737 | * 0 Success |
| 738 | * !0 Failure |
| 739 | */ |
| 740 | int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev) |
| 741 | { |
| 742 | int err; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 743 | struct kobject *edac_kobj = &edac_dev->kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 744 | |
| 745 | /* register this instance's main kobj with the edac class kobj */ |
| 746 | err = edac_device_register_main_kobj(edac_dev); |
| 747 | if (err) |
| 748 | return err; |
| 749 | |
| 750 | debugf0("%s() idx=%d\n", __func__, edac_dev->dev_idx); |
| 751 | |
| 752 | /* create a symlink from the edac device |
| 753 | * to the platform 'device' being used for this |
| 754 | */ |
| 755 | err = sysfs_create_link(edac_kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 756 | &edac_dev->dev->kobj, EDAC_DEVICE_SYMLINK); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 757 | if (err) { |
| 758 | debugf0("%s() sysfs_create_link() returned err= %d\n", |
| 759 | __func__, err); |
| 760 | return err; |
| 761 | } |
| 762 | |
| 763 | debugf0("%s() calling create-instances, idx=%d\n", |
| 764 | __func__, edac_dev->dev_idx); |
| 765 | |
| 766 | /* Create the first level instance directories */ |
| 767 | err = edac_device_create_instances(edac_dev); |
| 768 | if (err) { |
| 769 | goto error0; |
| 770 | } |
| 771 | |
| 772 | return 0; |
| 773 | |
| 774 | /* Error unwind stack */ |
| 775 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame^] | 776 | error0: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 777 | edac_device_unregister_main_kobj(edac_dev); |
| 778 | |
| 779 | return err; |
| 780 | } |
| 781 | |
| 782 | /* |
| 783 | * edac_device_remove_sysfs() destructor |
| 784 | * |
| 785 | * remove a edac_device instance |
| 786 | */ |
| 787 | void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev) |
| 788 | { |
| 789 | debugf0("%s()\n", __func__); |
| 790 | |
| 791 | edac_device_delete_instances(edac_dev); |
| 792 | |
| 793 | /* remove the sym link */ |
| 794 | sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK); |
| 795 | |
| 796 | /* unregister the instance's main kobj */ |
| 797 | edac_device_unregister_main_kobj(edac_dev); |
| 798 | } |