Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 1 | /* |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 2 | * file for managing the edac_device subsystem of devices for EDAC |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 3 | * |
Justin P. Mattock | 631dd1a | 2010-10-18 11:03:14 +0200 | [diff] [blame] | 4 | * (C) 2007 SoftwareBitMaker |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 5 | * |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 6 | * This file may be distributed under the terms of the |
| 7 | * GNU General Public License. |
| 8 | * |
| 9 | * Written Doug Thompson <norsk5@xmission.com> |
| 10 | * |
| 11 | */ |
| 12 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 13 | #include <linux/ctype.h> |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 16 | #include <linux/edac.h> |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include "edac_core.h" |
| 19 | #include "edac_module.h" |
| 20 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 21 | #define EDAC_DEVICE_SYMLINK "device" |
| 22 | |
| 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) |
| 25 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Set of edac_device_ctl_info attribute store/show functions |
| 29 | */ |
| 30 | |
| 31 | /* 'log_ue' */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 32 | static ssize_t edac_device_ctl_log_ue_show(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 33 | *ctl_info, 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, "%u\n", ctl_info->log_ue); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 38 | static ssize_t edac_device_ctl_log_ue_store(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 39 | *ctl_info, const char *data, |
| 40 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 41 | { |
| 42 | /* 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] | 43 | ctl_info->log_ue = (simple_strtoul(data, NULL, 0) != 0); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 44 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 45 | return count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /* 'log_ce' */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 49 | static ssize_t edac_device_ctl_log_ce_show(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 50 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 51 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 52 | return sprintf(data, "%u\n", ctl_info->log_ce); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 55 | static ssize_t edac_device_ctl_log_ce_store(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 56 | *ctl_info, const char *data, |
| 57 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 58 | { |
| 59 | /* 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] | 60 | ctl_info->log_ce = (simple_strtoul(data, NULL, 0) != 0); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 61 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 62 | return count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Stepan Moskovchenko | a8349c1 | 2014-06-10 19:24:50 -0700 | [diff] [blame] | 65 | /* 'panic_on_ce' */ |
| 66 | static ssize_t edac_device_ctl_panic_on_ce_show(struct edac_device_ctl_info |
| 67 | *ctl_info, char *data) |
| 68 | { |
| 69 | return snprintf(data, PAGE_SIZE, "%u\n", ctl_info->panic_on_ce); |
| 70 | } |
| 71 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 72 | /* 'panic_on_ue' */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 73 | static ssize_t edac_device_ctl_panic_on_ue_show(struct edac_device_ctl_info |
| 74 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 75 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 76 | return sprintf(data, "%u\n", ctl_info->panic_on_ue); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Stepan Moskovchenko | a8349c1 | 2014-06-10 19:24:50 -0700 | [diff] [blame] | 79 | static ssize_t edac_device_ctl_panic_on_ce_store(struct edac_device_ctl_info |
| 80 | *ctl_info, const char *data, |
| 81 | size_t count) |
| 82 | { |
| 83 | unsigned long val; |
| 84 | |
| 85 | /* if parameter is zero, turn off flag, if non-zero turn on flag */ |
| 86 | if (kstrtoul(data, 0, &val) < 0) |
| 87 | return -EINVAL; |
| 88 | |
| 89 | ctl_info->panic_on_ce = !!val; |
| 90 | |
| 91 | return count; |
| 92 | } |
| 93 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 94 | static ssize_t edac_device_ctl_panic_on_ue_store(struct edac_device_ctl_info |
| 95 | *ctl_info, const char *data, |
| 96 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 97 | { |
| 98 | /* 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] | 99 | ctl_info->panic_on_ue = (simple_strtoul(data, NULL, 0) != 0); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 100 | |
| 101 | return count; |
| 102 | } |
| 103 | |
| 104 | /* 'poll_msec' show and store functions*/ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 105 | static ssize_t edac_device_ctl_poll_msec_show(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 106 | *ctl_info, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 107 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 108 | return sprintf(data, "%u\n", ctl_info->poll_msec); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 111 | static ssize_t edac_device_ctl_poll_msec_store(struct edac_device_ctl_info |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 112 | *ctl_info, const char *data, |
| 113 | size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 114 | { |
| 115 | unsigned long value; |
| 116 | |
| 117 | /* get the value and enforce that it is non-zero, must be at least |
| 118 | * one millisecond for the delay period, between scans |
| 119 | * Then cancel last outstanding delay for the work request |
| 120 | * and set a new one. |
| 121 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 122 | value = simple_strtoul(data, NULL, 0); |
| 123 | edac_device_reset_delay_period(ctl_info, value); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 124 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 125 | return count; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 128 | /* edac_device_ctl_info specific attribute structure */ |
| 129 | struct ctl_info_attribute { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 130 | struct attribute attr; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 131 | ssize_t(*show) (struct edac_device_ctl_info *, char *); |
| 132 | ssize_t(*store) (struct edac_device_ctl_info *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | #define to_ctl_info(k) container_of(k, struct edac_device_ctl_info, kobj) |
| 136 | #define to_ctl_info_attr(a) container_of(a,struct ctl_info_attribute,attr) |
| 137 | |
| 138 | /* Function to 'show' fields from the edac_dev 'ctl_info' structure */ |
| 139 | static ssize_t edac_dev_ctl_info_show(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 140 | struct attribute *attr, char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 141 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 142 | struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj); |
| 143 | struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 144 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 145 | if (ctl_info_attr->show) |
| 146 | return ctl_info_attr->show(edac_dev, buffer); |
| 147 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* Function to 'store' fields into the edac_dev 'ctl_info' structure */ |
| 151 | static ssize_t edac_dev_ctl_info_store(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 152 | struct attribute *attr, |
| 153 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 154 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 155 | struct edac_device_ctl_info *edac_dev = to_ctl_info(kobj); |
| 156 | struct ctl_info_attribute *ctl_info_attr = to_ctl_info_attr(attr); |
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 | if (ctl_info_attr->store) |
| 159 | return ctl_info_attr->store(edac_dev, buffer, count); |
| 160 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* edac_dev file operations for an 'ctl_info' */ |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 164 | static const struct sysfs_ops device_ctl_info_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 165 | .show = edac_dev_ctl_info_show, |
| 166 | .store = edac_dev_ctl_info_store |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | #define CTL_INFO_ATTR(_name,_mode,_show,_store) \ |
| 170 | static struct ctl_info_attribute attr_ctl_info_##_name = { \ |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 171 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 172 | .show = _show, \ |
| 173 | .store = _store, \ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 176 | /* Declare the various ctl_info attributes here and their respective ops */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 177 | CTL_INFO_ATTR(log_ue, S_IRUGO | S_IWUSR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 178 | edac_device_ctl_log_ue_show, edac_device_ctl_log_ue_store); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 179 | CTL_INFO_ATTR(log_ce, S_IRUGO | S_IWUSR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 180 | edac_device_ctl_log_ce_show, edac_device_ctl_log_ce_store); |
Stepan Moskovchenko | a8349c1 | 2014-06-10 19:24:50 -0700 | [diff] [blame] | 181 | CTL_INFO_ATTR(panic_on_ce, S_IRUGO | S_IWUSR, |
| 182 | edac_device_ctl_panic_on_ce_show, |
| 183 | edac_device_ctl_panic_on_ce_store); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 184 | CTL_INFO_ATTR(panic_on_ue, S_IRUGO | S_IWUSR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 185 | edac_device_ctl_panic_on_ue_show, |
| 186 | edac_device_ctl_panic_on_ue_store); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 187 | CTL_INFO_ATTR(poll_msec, S_IRUGO | S_IWUSR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 188 | edac_device_ctl_poll_msec_show, edac_device_ctl_poll_msec_store); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* Base Attributes of the EDAC_DEVICE ECC object */ |
| 191 | static struct ctl_info_attribute *device_ctrl_attr[] = { |
Stepan Moskovchenko | a8349c1 | 2014-06-10 19:24:50 -0700 | [diff] [blame] | 192 | &attr_ctl_info_panic_on_ce, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 193 | &attr_ctl_info_panic_on_ue, |
| 194 | &attr_ctl_info_log_ue, |
| 195 | &attr_ctl_info_log_ce, |
| 196 | &attr_ctl_info_poll_msec, |
| 197 | NULL, |
| 198 | }; |
| 199 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 200 | /* |
| 201 | * edac_device_ctrl_master_release |
| 202 | * |
| 203 | * called when the reference count for the 'main' kobj |
| 204 | * for a edac_device control struct reaches zero |
| 205 | * |
| 206 | * Reference count model: |
| 207 | * One 'main' kobject for each control structure allocated. |
| 208 | * That main kobj is initially set to one AND |
| 209 | * the reference count for the EDAC 'core' module is |
| 210 | * bumped by one, thus added 'keep in memory' dependency. |
| 211 | * |
| 212 | * Each new internal kobj (in instances and blocks) then |
| 213 | * bumps the 'main' kobject. |
| 214 | * |
| 215 | * When they are released their release functions decrement |
| 216 | * the 'main' kobj. |
| 217 | * |
| 218 | * When the main kobj reaches zero (0) then THIS function |
| 219 | * is called which then decrements the EDAC 'core' module. |
| 220 | * When the module reference count reaches zero then the |
| 221 | * module no longer has dependency on keeping the release |
| 222 | * function code in memory and module can be unloaded. |
| 223 | * |
| 224 | * This will support several control objects as well, each |
| 225 | * with its own 'main' kobj. |
| 226 | */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 227 | static void edac_device_ctrl_master_release(struct kobject *kobj) |
| 228 | { |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 229 | struct edac_device_ctl_info *edac_dev = to_edacdev(kobj); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 230 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 231 | edac_dbg(4, "control index=%d\n", edac_dev->dev_idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 232 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 233 | /* decrement the EDAC CORE module ref count */ |
| 234 | module_put(edac_dev->owner); |
| 235 | |
| 236 | /* free the control struct containing the 'main' kobj |
| 237 | * passed in to this routine |
| 238 | */ |
| 239 | kfree(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 242 | /* ktype for the main (master) kobject */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 243 | static struct kobj_type ktype_device_ctrl = { |
| 244 | .release = edac_device_ctrl_master_release, |
| 245 | .sysfs_ops = &device_ctl_info_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 246 | .default_attrs = (struct attribute **)device_ctrl_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 249 | /* |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 250 | * edac_device_register_sysfs_main_kobj |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 251 | * |
| 252 | * perform the high level setup for the new edac_device instance |
| 253 | * |
| 254 | * Return: 0 SUCCESS |
| 255 | * !0 FAILURE |
| 256 | */ |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 257 | int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 258 | { |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 259 | struct bus_type *edac_subsys; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 260 | int err; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 261 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 262 | edac_dbg(1, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 263 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 264 | /* get the /sys/devices/system/edac reference */ |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 265 | edac_subsys = edac_get_sysfs_subsys(); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 266 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 267 | /* Point to the 'edac_subsys' this instance 'reports' to */ |
| 268 | edac_dev->edac_subsys = edac_subsys; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 269 | |
| 270 | /* Init the devices's kobject */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 271 | memset(&edac_dev->kobj, 0, sizeof(struct kobject)); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 272 | |
| 273 | /* Record which module 'owns' this control structure |
| 274 | * and bump the ref count of the module |
| 275 | */ |
| 276 | edac_dev->owner = THIS_MODULE; |
| 277 | |
| 278 | if (!try_module_get(edac_dev->owner)) { |
| 279 | err = -ENODEV; |
Borislav Petkov | 733476c | 2015-11-27 11:40:43 +0100 | [diff] [blame] | 280 | goto err_out; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* register */ |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 284 | err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl, |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 285 | &edac_subsys->dev_root->kobj, |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 286 | "%s", edac_dev->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 287 | if (err) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 288 | edac_dbg(1, "Failed to register '.../edac/%s'\n", |
| 289 | edac_dev->name); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 290 | goto err_kobj_reg; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 291 | } |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 292 | kobject_uevent(&edac_dev->kobj, KOBJ_ADD); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 293 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 294 | /* At this point, to 'free' the control struct, |
| 295 | * edac_device_unregister_sysfs_main_kobj() must be used |
| 296 | */ |
| 297 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 298 | edac_dbg(4, "Registered '.../edac/%s' kobject\n", edac_dev->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 299 | |
| 300 | return 0; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 301 | |
| 302 | /* Error exit stack */ |
| 303 | err_kobj_reg: |
| 304 | module_put(edac_dev->owner); |
| 305 | |
| 306 | err_out: |
| 307 | return err; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 311 | * edac_device_unregister_sysfs_main_kobj: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 312 | * the '..../edac/<name>' kobject |
| 313 | */ |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 314 | void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 315 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 316 | edac_dbg(0, "\n"); |
| 317 | edac_dbg(4, "name of kobject is: %s\n", kobject_name(&dev->kobj)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 318 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 319 | /* |
| 320 | * Unregister the edac device's kobject and |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 321 | * allow for reference count to reach 0 at which point |
| 322 | * the callback will be called to: |
| 323 | * a) module_put() this module |
| 324 | * b) 'kfree' the memory |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 325 | */ |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 326 | kobject_put(&dev->kobj); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 329 | /* edac_dev -> instance information */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 330 | |
| 331 | /* |
| 332 | * Set of low-level instance attribute show functions |
| 333 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 334 | static ssize_t instance_ue_count_show(struct edac_device_instance *instance, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 335 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 336 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 337 | return sprintf(data, "%u\n", instance->counters.ue_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 340 | static ssize_t instance_ce_count_show(struct edac_device_instance *instance, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 341 | char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 342 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 343 | return sprintf(data, "%u\n", instance->counters.ce_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 346 | #define to_instance(k) container_of(k, struct edac_device_instance, kobj) |
| 347 | #define to_instance_attr(a) container_of(a,struct instance_attribute,attr) |
| 348 | |
| 349 | /* DEVICE instance kobject release() function */ |
| 350 | static void edac_device_ctrl_instance_release(struct kobject *kobj) |
| 351 | { |
| 352 | struct edac_device_instance *instance; |
| 353 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 354 | edac_dbg(1, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 355 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 356 | /* map from this kobj to the main control struct |
| 357 | * and then dec the main kobj count |
| 358 | */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 359 | instance = to_instance(kobj); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 360 | kobject_put(&instance->ctl->kobj); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 363 | /* instance specific attribute structure */ |
| 364 | struct instance_attribute { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 365 | struct attribute attr; |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 366 | ssize_t(*show) (struct edac_device_instance *, char *); |
| 367 | ssize_t(*store) (struct edac_device_instance *, const char *, size_t); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 368 | }; |
| 369 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 370 | /* Function to 'show' fields from the edac_dev 'instance' structure */ |
| 371 | static ssize_t edac_dev_instance_show(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 372 | struct attribute *attr, char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 373 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 374 | struct edac_device_instance *instance = to_instance(kobj); |
| 375 | struct instance_attribute *instance_attr = to_instance_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 376 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 377 | if (instance_attr->show) |
| 378 | return instance_attr->show(instance, buffer); |
| 379 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 382 | /* Function to 'store' fields into the edac_dev 'instance' structure */ |
| 383 | static ssize_t edac_dev_instance_store(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 384 | struct attribute *attr, |
| 385 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 386 | { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 387 | struct edac_device_instance *instance = to_instance(kobj); |
| 388 | struct instance_attribute *instance_attr = to_instance_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 389 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 390 | if (instance_attr->store) |
| 391 | return instance_attr->store(instance, buffer, count); |
| 392 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 395 | /* edac_dev file operations for an 'instance' */ |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 396 | static const struct sysfs_ops device_instance_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 397 | .show = edac_dev_instance_show, |
| 398 | .store = edac_dev_instance_store |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | #define INSTANCE_ATTR(_name,_mode,_show,_store) \ |
| 402 | static struct instance_attribute attr_instance_##_name = { \ |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 403 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 404 | .show = _show, \ |
| 405 | .store = _store, \ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 406 | }; |
| 407 | |
| 408 | /* |
| 409 | * Define attributes visible for the edac_device instance object |
| 410 | * Each contains a pointer to a show and an optional set |
| 411 | * function pointer that does the low level output/input |
| 412 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 413 | INSTANCE_ATTR(ce_count, S_IRUGO, instance_ce_count_show, NULL); |
| 414 | INSTANCE_ATTR(ue_count, S_IRUGO, instance_ue_count_show, NULL); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 415 | |
| 416 | /* list of edac_dev 'instance' attributes */ |
| 417 | static struct instance_attribute *device_instance_attr[] = { |
| 418 | &attr_instance_ce_count, |
| 419 | &attr_instance_ue_count, |
| 420 | NULL, |
| 421 | }; |
| 422 | |
| 423 | /* The 'ktype' for each edac_dev 'instance' */ |
| 424 | static struct kobj_type ktype_instance_ctrl = { |
| 425 | .release = edac_device_ctrl_instance_release, |
| 426 | .sysfs_ops = &device_instance_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 427 | .default_attrs = (struct attribute **)device_instance_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 430 | /* edac_dev -> instance -> block information */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 431 | |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 432 | #define to_block(k) container_of(k, struct edac_device_block, kobj) |
| 433 | #define to_block_attr(a) \ |
| 434 | container_of(a, struct edac_dev_sysfs_block_attribute, attr) |
| 435 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 436 | /* |
| 437 | * Set of low-level block attribute show functions |
| 438 | */ |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 439 | static ssize_t block_ue_count_show(struct kobject *kobj, |
| 440 | struct attribute *attr, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 441 | { |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 442 | struct edac_device_block *block = to_block(kobj); |
| 443 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 444 | return sprintf(data, "%u\n", block->counters.ue_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 447 | static ssize_t block_ce_count_show(struct kobject *kobj, |
| 448 | struct attribute *attr, char *data) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 449 | { |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 450 | struct edac_device_block *block = to_block(kobj); |
| 451 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 452 | return sprintf(data, "%u\n", block->counters.ce_count); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 455 | /* DEVICE block kobject release() function */ |
| 456 | static void edac_device_ctrl_block_release(struct kobject *kobj) |
| 457 | { |
| 458 | struct edac_device_block *block; |
| 459 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 460 | edac_dbg(1, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 461 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 462 | /* get the container of the kobj */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 463 | block = to_block(kobj); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 464 | |
| 465 | /* map from 'block kobj' to 'block->instance->controller->main_kobj' |
| 466 | * now 'release' the block kobject |
| 467 | */ |
| 468 | kobject_put(&block->instance->ctl->kobj); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 471 | |
| 472 | /* Function to 'show' fields from the edac_dev 'block' structure */ |
| 473 | static ssize_t edac_dev_block_show(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 474 | struct attribute *attr, char *buffer) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 475 | { |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 476 | struct edac_dev_sysfs_block_attribute *block_attr = |
| 477 | to_block_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 478 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 479 | if (block_attr->show) |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 480 | return block_attr->show(kobj, attr, buffer); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 481 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 484 | /* Function to 'store' fields into the edac_dev 'block' structure */ |
| 485 | static ssize_t edac_dev_block_store(struct kobject *kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 486 | struct attribute *attr, |
| 487 | const char *buffer, size_t count) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 488 | { |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 489 | struct edac_dev_sysfs_block_attribute *block_attr; |
| 490 | |
| 491 | block_attr = to_block_attr(attr); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 492 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 493 | if (block_attr->store) |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 494 | return block_attr->store(kobj, attr, buffer, count); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 495 | return -EIO; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 498 | /* edac_dev file operations for a 'block' */ |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 499 | static const struct sysfs_ops device_block_ops = { |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 500 | .show = edac_dev_block_show, |
| 501 | .store = edac_dev_block_store |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 502 | }; |
| 503 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 504 | #define BLOCK_ATTR(_name,_mode,_show,_store) \ |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 505 | static struct edac_dev_sysfs_block_attribute attr_block_##_name = { \ |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 506 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 507 | .show = _show, \ |
| 508 | .store = _store, \ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 509 | }; |
| 510 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 511 | BLOCK_ATTR(ce_count, S_IRUGO, block_ce_count_show, NULL); |
| 512 | BLOCK_ATTR(ue_count, S_IRUGO, block_ue_count_show, NULL); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 513 | |
| 514 | /* list of edac_dev 'block' attributes */ |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 515 | static struct edac_dev_sysfs_block_attribute *device_block_attr[] = { |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 516 | &attr_block_ce_count, |
| 517 | &attr_block_ue_count, |
| 518 | NULL, |
| 519 | }; |
| 520 | |
| 521 | /* The 'ktype' for each edac_dev 'block' */ |
| 522 | static struct kobj_type ktype_block_ctrl = { |
| 523 | .release = edac_device_ctrl_block_release, |
| 524 | .sysfs_ops = &device_block_ops, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 525 | .default_attrs = (struct attribute **)device_block_attr, |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 526 | }; |
| 527 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 528 | /* block ctor/dtor code */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 529 | |
| 530 | /* |
| 531 | * edac_device_create_block |
| 532 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 533 | static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 534 | struct edac_device_instance *instance, |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 535 | struct edac_device_block *block) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 536 | { |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 537 | int i; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 538 | int err; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 539 | struct edac_dev_sysfs_block_attribute *sysfs_attrib; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 540 | struct kobject *main_kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 541 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 542 | edac_dbg(4, "Instance '%s' inst_p=%p block '%s' block_p=%p\n", |
| 543 | instance->name, instance, block->name, block); |
| 544 | edac_dbg(4, "block kobj=%p block kobj->parent=%p\n", |
| 545 | &block->kobj, &block->kobj.parent); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* init this block's kobject */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 548 | memset(&block->kobj, 0, sizeof(struct kobject)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 549 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 550 | /* bump the main kobject's reference count for this controller |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 551 | * and this instance is dependent on the main |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 552 | */ |
| 553 | main_kobj = kobject_get(&edac_dev->kobj); |
| 554 | if (!main_kobj) { |
| 555 | err = -ENODEV; |
| 556 | goto err_out; |
| 557 | } |
| 558 | |
| 559 | /* Add this block's kobject */ |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 560 | err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl, |
| 561 | &instance->kobj, |
| 562 | "%s", block->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 563 | if (err) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 564 | edac_dbg(1, "Failed to register instance '%s'\n", block->name); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 565 | kobject_put(main_kobj); |
| 566 | err = -ENODEV; |
| 567 | goto err_out; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 570 | /* If there are driver level block attributes, then added them |
| 571 | * to the block kobject |
| 572 | */ |
| 573 | sysfs_attrib = block->block_attributes; |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 574 | if (sysfs_attrib && block->nr_attribs) { |
| 575 | for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) { |
| 576 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 577 | edac_dbg(4, "creating block attrib='%s' attrib->%p to kobj=%p\n", |
| 578 | sysfs_attrib->attr.name, |
| 579 | sysfs_attrib, &block->kobj); |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 580 | |
| 581 | /* Create each block_attribute file */ |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 582 | err = sysfs_create_file(&block->kobj, |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 583 | &sysfs_attrib->attr); |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 584 | if (err) |
| 585 | goto err_on_attrib; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 588 | kobject_uevent(&block->kobj, KOBJ_ADD); |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 589 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 590 | return 0; |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 591 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 592 | /* Error unwind stack */ |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 593 | err_on_attrib: |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 594 | kobject_put(&block->kobj); |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 595 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 596 | err_out: |
Douglas Thompson | fd309a9d | 2007-07-19 01:50:25 -0700 | [diff] [blame] | 597 | return err; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /* |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 601 | * edac_device_delete_block(edac_dev,block); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 602 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 603 | static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 604 | struct edac_device_block *block) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 605 | { |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 606 | struct edac_dev_sysfs_block_attribute *sysfs_attrib; |
| 607 | int i; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 608 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 609 | /* if this block has 'attributes' then we need to iterate over the list |
| 610 | * and 'remove' the attributes on this block |
| 611 | */ |
| 612 | sysfs_attrib = block->block_attributes; |
| 613 | if (sysfs_attrib && block->nr_attribs) { |
Doug Thompson | b2a4ac0 | 2007-07-19 01:50:33 -0700 | [diff] [blame] | 614 | for (i = 0; i < block->nr_attribs; i++, sysfs_attrib++) { |
| 615 | |
| 616 | /* remove each block_attrib file */ |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 617 | sysfs_remove_file(&block->kobj, |
| 618 | (struct attribute *) sysfs_attrib); |
| 619 | } |
| 620 | } |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 621 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 622 | /* unregister this block's kobject, SEE: |
| 623 | * edac_device_ctrl_block_release() callback operation |
| 624 | */ |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 625 | kobject_put(&block->kobj); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 628 | /* instance ctor/dtor code */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 629 | |
| 630 | /* |
| 631 | * edac_device_create_instance |
| 632 | * create just one instance of an edac_device 'instance' |
| 633 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 634 | static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 635 | int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 636 | { |
| 637 | int i, j; |
| 638 | int err; |
| 639 | struct edac_device_instance *instance; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 640 | struct kobject *main_kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 641 | |
| 642 | instance = &edac_dev->instances[idx]; |
| 643 | |
| 644 | /* Init the instance's kobject */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 645 | memset(&instance->kobj, 0, sizeof(struct kobject)); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 646 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 647 | instance->ctl = edac_dev; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 648 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 649 | /* bump the main kobject's reference count for this controller |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 650 | * and this instance is dependent on the main |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 651 | */ |
| 652 | main_kobj = kobject_get(&edac_dev->kobj); |
| 653 | if (!main_kobj) { |
| 654 | err = -ENODEV; |
| 655 | goto err_out; |
| 656 | } |
| 657 | |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 658 | /* Formally register this instance's kobject under the edac_device */ |
| 659 | err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl, |
| 660 | &edac_dev->kobj, "%s", instance->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 661 | if (err != 0) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 662 | edac_dbg(2, "Failed to register instance '%s'\n", |
| 663 | instance->name); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 664 | kobject_put(main_kobj); |
| 665 | goto err_out; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 668 | edac_dbg(4, "now register '%d' blocks for instance %d\n", |
| 669 | instance->nr_blocks, idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 670 | |
| 671 | /* register all blocks of this instance */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 672 | for (i = 0; i < instance->nr_blocks; i++) { |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 673 | err = edac_device_create_block(edac_dev, instance, |
| 674 | &instance->blocks[i]); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 675 | if (err) { |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 676 | /* If any fail, remove all previous ones */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 677 | for (j = 0; j < i; j++) |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 678 | edac_device_delete_block(edac_dev, |
| 679 | &instance->blocks[j]); |
| 680 | goto err_release_instance_kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 681 | } |
| 682 | } |
Greg Kroah-Hartman | b2ed215 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 683 | kobject_uevent(&instance->kobj, KOBJ_ADD); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 684 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 685 | edac_dbg(4, "Registered instance %d '%s' kobject\n", |
| 686 | idx, instance->name); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 687 | |
| 688 | return 0; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 689 | |
| 690 | /* error unwind stack */ |
| 691 | err_release_instance_kobj: |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 692 | kobject_put(&instance->kobj); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 693 | |
| 694 | err_out: |
| 695 | return err; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /* |
| 699 | * edac_device_remove_instance |
| 700 | * remove an edac_device instance |
| 701 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 702 | static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev, |
| 703 | int idx) |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 704 | { |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 705 | struct edac_device_instance *instance; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 706 | int i; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 707 | |
| 708 | instance = &edac_dev->instances[idx]; |
| 709 | |
| 710 | /* unregister all blocks in this instance */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 711 | for (i = 0; i < instance->nr_blocks; i++) |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 712 | edac_device_delete_block(edac_dev, &instance->blocks[i]); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 713 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 714 | /* unregister this instance's kobject, SEE: |
| 715 | * edac_device_ctrl_instance_release() for callback operation |
| 716 | */ |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 717 | kobject_put(&instance->kobj); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /* |
| 721 | * edac_device_create_instances |
| 722 | * create the first level of 'instances' for this device |
| 723 | * (ie 'cache' might have 'cache0', 'cache1', 'cache2', etc |
| 724 | */ |
| 725 | static int edac_device_create_instances(struct edac_device_ctl_info *edac_dev) |
| 726 | { |
| 727 | int i, j; |
| 728 | int err; |
| 729 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 730 | edac_dbg(0, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 731 | |
| 732 | /* iterate over creation of the instances */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 733 | for (i = 0; i < edac_dev->nr_instances; i++) { |
| 734 | err = edac_device_create_instance(edac_dev, i); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 735 | if (err) { |
| 736 | /* unwind previous instances on error */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 737 | for (j = 0; j < i; j++) |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 738 | edac_device_delete_instance(edac_dev, j); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 739 | return err; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | /* |
| 747 | * edac_device_delete_instances(edac_dev); |
| 748 | * unregister all the kobjects of the instances |
| 749 | */ |
| 750 | static void edac_device_delete_instances(struct edac_device_ctl_info *edac_dev) |
| 751 | { |
| 752 | int i; |
| 753 | |
| 754 | /* iterate over creation of the instances */ |
Douglas Thompson | 52490c8 | 2007-07-19 01:50:20 -0700 | [diff] [blame] | 755 | for (i = 0; i < edac_dev->nr_instances; i++) |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 756 | edac_device_delete_instance(edac_dev, i); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 759 | /* edac_dev sysfs ctor/dtor code */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 760 | |
| 761 | /* |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 762 | * edac_device_add_main_sysfs_attributes |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 763 | * add some attributes to this instance's main kobject |
| 764 | */ |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 765 | static int edac_device_add_main_sysfs_attributes( |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 766 | struct edac_device_ctl_info *edac_dev) |
| 767 | { |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 768 | struct edac_dev_sysfs_attribute *sysfs_attrib; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 769 | int err = 0; |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 770 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 771 | sysfs_attrib = edac_dev->sysfs_attributes; |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 772 | if (sysfs_attrib) { |
| 773 | /* iterate over the array and create an attribute for each |
| 774 | * entry in the list |
| 775 | */ |
| 776 | while (sysfs_attrib->attr.name != NULL) { |
| 777 | err = sysfs_create_file(&edac_dev->kobj, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 778 | (struct attribute*) sysfs_attrib); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 779 | if (err) |
| 780 | goto err_out; |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 781 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 782 | sysfs_attrib++; |
| 783 | } |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 784 | } |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 785 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 786 | err_out: |
| 787 | return err; |
| 788 | } |
| 789 | |
| 790 | /* |
| 791 | * edac_device_remove_main_sysfs_attributes |
| 792 | * remove any attributes to this instance's main kobject |
| 793 | */ |
| 794 | static void edac_device_remove_main_sysfs_attributes( |
| 795 | struct edac_device_ctl_info *edac_dev) |
| 796 | { |
| 797 | struct edac_dev_sysfs_attribute *sysfs_attrib; |
| 798 | |
| 799 | /* if there are main attributes, defined, remove them. First, |
| 800 | * point to the start of the array and iterate over it |
| 801 | * removing each attribute listed from this device's instance's kobject |
| 802 | */ |
| 803 | sysfs_attrib = edac_dev->sysfs_attributes; |
| 804 | if (sysfs_attrib) { |
| 805 | while (sysfs_attrib->attr.name != NULL) { |
| 806 | sysfs_remove_file(&edac_dev->kobj, |
| 807 | (struct attribute *) sysfs_attrib); |
| 808 | sysfs_attrib++; |
| 809 | } |
| 810 | } |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /* |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 814 | * edac_device_create_sysfs() Constructor |
| 815 | * |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 816 | * accept a created edac_device control structure |
| 817 | * and 'export' it to sysfs. The 'main' kobj should already have been |
| 818 | * created. 'instance' and 'block' kobjects should be registered |
| 819 | * along with any 'block' attributes from the low driver. In addition, |
| 820 | * the main attributes (if any) are connected to the main kobject of |
| 821 | * the control structure. |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 822 | * |
| 823 | * Return: |
| 824 | * 0 Success |
| 825 | * !0 Failure |
| 826 | */ |
| 827 | int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev) |
| 828 | { |
| 829 | int err; |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 830 | struct kobject *edac_kobj = &edac_dev->kobj; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 831 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 832 | edac_dbg(0, "idx=%d\n", edac_dev->dev_idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 833 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 834 | /* go create any main attributes callers wants */ |
| 835 | err = edac_device_add_main_sysfs_attributes(edac_dev); |
| 836 | if (err) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 837 | edac_dbg(0, "failed to add sysfs attribs\n"); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 838 | goto err_out; |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 841 | /* create a symlink from the edac device |
| 842 | * to the platform 'device' being used for this |
| 843 | */ |
| 844 | err = sysfs_create_link(edac_kobj, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 845 | &edac_dev->dev->kobj, EDAC_DEVICE_SYMLINK); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 846 | if (err) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 847 | edac_dbg(0, "sysfs_create_link() returned err= %d\n", err); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 848 | goto err_remove_main_attribs; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 851 | /* Create the first level instance directories |
| 852 | * In turn, the nested blocks beneath the instances will |
| 853 | * be registered as well |
| 854 | */ |
| 855 | err = edac_device_create_instances(edac_dev); |
| 856 | if (err) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 857 | edac_dbg(0, "edac_device_create_instances() returned err= %d\n", |
| 858 | err); |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 859 | goto err_remove_link; |
| 860 | } |
| 861 | |
| 862 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 863 | edac_dbg(4, "create-instances done, idx=%d\n", edac_dev->dev_idx); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 864 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 865 | return 0; |
| 866 | |
| 867 | /* Error unwind stack */ |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 868 | err_remove_link: |
| 869 | /* remove the sym link */ |
| 870 | sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 871 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 872 | err_remove_main_attribs: |
| 873 | edac_device_remove_main_sysfs_attributes(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 874 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 875 | err_out: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 876 | return err; |
| 877 | } |
| 878 | |
| 879 | /* |
| 880 | * edac_device_remove_sysfs() destructor |
| 881 | * |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 882 | * given an edac_device struct, tear down the kobject resources |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 883 | */ |
| 884 | void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev) |
| 885 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 886 | edac_dbg(0, "\n"); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 887 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 888 | /* remove any main attributes for this device */ |
| 889 | edac_device_remove_main_sysfs_attributes(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 890 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 891 | /* remove the device sym link */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 892 | sysfs_remove_link(&edac_dev->kobj, EDAC_DEVICE_SYMLINK); |
| 893 | |
Douglas Thompson | 1c3631f | 2007-07-19 01:50:29 -0700 | [diff] [blame] | 894 | /* walk the instance/block kobject tree, deconstructing it */ |
| 895 | edac_device_delete_instances(edac_dev); |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 896 | } |