2 * edac_mc kernel module
3 * (C) 2005-2007 Linux Networx (http://lnxi.com)
5 * This file may be distributed under the terms of the
6 * GNU General Public License.
8 * Written Doug Thompson <norsk5@xmission.com> www.softwarebitmaker.com
12 #include <linux/ctype.h>
13 #include <linux/bug.h>
15 #include "edac_core.h"
16 #include "edac_module.h"
19 /* MC EDAC Controls, setable by module parameter, and sysfs */
20 static int edac_mc_log_ue
= 1;
21 static int edac_mc_log_ce
= 1;
22 static int edac_mc_panic_on_ue
;
23 static int edac_mc_poll_msec
= 1000;
25 /* Getter functions for above */
26 int edac_mc_get_log_ue(void)
28 return edac_mc_log_ue
;
31 int edac_mc_get_log_ce(void)
33 return edac_mc_log_ce
;
36 int edac_mc_get_panic_on_ue(void)
38 return edac_mc_panic_on_ue
;
41 /* this is temporary */
42 int edac_mc_get_poll_msec(void)
44 return edac_mc_poll_msec
;
47 static int edac_set_poll_msec(const char *val
, struct kernel_param
*kp
)
55 ret
= strict_strtol(val
, 0, &l
);
56 if (ret
== -EINVAL
|| ((int)l
!= l
))
58 *((int *)kp
->arg
) = l
;
60 /* notify edac_mc engine to reset the poll period */
61 edac_mc_reset_delay_period(l
);
66 /* Parameter declarations for above */
67 module_param(edac_mc_panic_on_ue
, int, 0644);
68 MODULE_PARM_DESC(edac_mc_panic_on_ue
, "Panic on uncorrected error: 0=off 1=on");
69 module_param(edac_mc_log_ue
, int, 0644);
70 MODULE_PARM_DESC(edac_mc_log_ue
,
71 "Log uncorrectable error to console: 0=off 1=on");
72 module_param(edac_mc_log_ce
, int, 0644);
73 MODULE_PARM_DESC(edac_mc_log_ce
,
74 "Log correctable error to console: 0=off 1=on");
75 module_param_call(edac_mc_poll_msec
, edac_set_poll_msec
, param_get_int
,
76 &edac_mc_poll_msec
, 0644);
77 MODULE_PARM_DESC(edac_mc_poll_msec
, "Polling period in milliseconds");
80 * various constants for Memory Controllers
82 static const char *mem_types
[] = {
83 [MEM_EMPTY
] = "Empty",
84 [MEM_RESERVED
] = "Reserved",
85 [MEM_UNKNOWN
] = "Unknown",
89 [MEM_SDR
] = "Unbuffered-SDR",
90 [MEM_RDR
] = "Registered-SDR",
91 [MEM_DDR
] = "Unbuffered-DDR",
92 [MEM_RDDR
] = "Registered-DDR",
94 [MEM_DDR2
] = "Unbuffered-DDR2",
95 [MEM_FB_DDR2
] = "FullyBuffered-DDR2",
96 [MEM_RDDR2
] = "Registered-DDR2",
100 static const char *dev_types
[] = {
101 [DEV_UNKNOWN
] = "Unknown",
111 static const char *edac_caps
[] = {
112 [EDAC_UNKNOWN
] = "Unknown",
113 [EDAC_NONE
] = "None",
114 [EDAC_RESERVED
] = "Reserved",
115 [EDAC_PARITY
] = "PARITY",
117 [EDAC_SECDED
] = "SECDED",
118 [EDAC_S2ECD2ED
] = "S2ECD2ED",
119 [EDAC_S4ECD4ED
] = "S4ECD4ED",
120 [EDAC_S8ECD8ED
] = "S8ECD8ED",
121 [EDAC_S16ECD16ED
] = "S16ECD16ED"
127 * /sys/devices/system/edac/mc;
128 * data structures and methods
130 static ssize_t
memctrl_int_show(void *ptr
, char *buffer
)
132 int *value
= (int *)ptr
;
133 return sprintf(buffer
, "%u\n", *value
);
136 static ssize_t
memctrl_int_store(void *ptr
, const char *buffer
, size_t count
)
138 int *value
= (int *)ptr
;
140 if (isdigit(*buffer
))
141 *value
= simple_strtoul(buffer
, NULL
, 0);
147 * mc poll_msec time value
149 static ssize_t
poll_msec_int_store(void *ptr
, const char *buffer
, size_t count
)
151 int *value
= (int *)ptr
;
153 if (isdigit(*buffer
)) {
154 *value
= simple_strtoul(buffer
, NULL
, 0);
156 /* notify edac_mc engine to reset the poll period */
157 edac_mc_reset_delay_period(*value
);
164 /* EDAC sysfs CSROW data structures and methods
167 /* Set of more default csrow<id> attribute show/store functions */
168 static ssize_t
csrow_ue_count_show(struct csrow_info
*csrow
, char *data
,
171 return sprintf(data
, "%u\n", csrow
->ue_count
);
174 static ssize_t
csrow_ce_count_show(struct csrow_info
*csrow
, char *data
,
177 return sprintf(data
, "%u\n", csrow
->ce_count
);
180 static ssize_t
csrow_size_show(struct csrow_info
*csrow
, char *data
,
183 return sprintf(data
, "%u\n", PAGES_TO_MiB(csrow
->nr_pages
));
186 static ssize_t
csrow_mem_type_show(struct csrow_info
*csrow
, char *data
,
189 return sprintf(data
, "%s\n", mem_types
[csrow
->mtype
]);
192 static ssize_t
csrow_dev_type_show(struct csrow_info
*csrow
, char *data
,
195 return sprintf(data
, "%s\n", dev_types
[csrow
->dtype
]);
198 static ssize_t
csrow_edac_mode_show(struct csrow_info
*csrow
, char *data
,
201 return sprintf(data
, "%s\n", edac_caps
[csrow
->edac_mode
]);
204 /* show/store functions for DIMM Label attributes */
205 static ssize_t
channel_dimm_label_show(struct csrow_info
*csrow
,
206 char *data
, int channel
)
208 return snprintf(data
, EDAC_MC_LABEL_LEN
, "%s",
209 csrow
->channels
[channel
].label
);
212 static ssize_t
channel_dimm_label_store(struct csrow_info
*csrow
,
214 size_t count
, int channel
)
216 ssize_t max_size
= 0;
218 max_size
= min((ssize_t
) count
, (ssize_t
) EDAC_MC_LABEL_LEN
- 1);
219 strncpy(csrow
->channels
[channel
].label
, data
, max_size
);
220 csrow
->channels
[channel
].label
[max_size
] = '\0';
225 /* show function for dynamic chX_ce_count attribute */
226 static ssize_t
channel_ce_count_show(struct csrow_info
*csrow
,
227 char *data
, int channel
)
229 return sprintf(data
, "%u\n", csrow
->channels
[channel
].ce_count
);
232 /* csrow specific attribute structure */
233 struct csrowdev_attribute
{
234 struct attribute attr
;
235 ssize_t(*show
) (struct csrow_info
*, char *, int);
236 ssize_t(*store
) (struct csrow_info
*, const char *, size_t, int);
240 #define to_csrow(k) container_of(k, struct csrow_info, kobj)
241 #define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
243 /* Set of show/store higher level functions for default csrow attributes */
244 static ssize_t
csrowdev_show(struct kobject
*kobj
,
245 struct attribute
*attr
, char *buffer
)
247 struct csrow_info
*csrow
= to_csrow(kobj
);
248 struct csrowdev_attribute
*csrowdev_attr
= to_csrowdev_attr(attr
);
250 if (csrowdev_attr
->show
)
251 return csrowdev_attr
->show(csrow
,
252 buffer
, csrowdev_attr
->private);
256 static ssize_t
csrowdev_store(struct kobject
*kobj
, struct attribute
*attr
,
257 const char *buffer
, size_t count
)
259 struct csrow_info
*csrow
= to_csrow(kobj
);
260 struct csrowdev_attribute
*csrowdev_attr
= to_csrowdev_attr(attr
);
262 if (csrowdev_attr
->store
)
263 return csrowdev_attr
->store(csrow
,
265 count
, csrowdev_attr
->private);
269 static struct sysfs_ops csrowfs_ops
= {
270 .show
= csrowdev_show
,
271 .store
= csrowdev_store
274 #define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \
275 static struct csrowdev_attribute attr_##_name = { \
276 .attr = {.name = __stringify(_name), .mode = _mode }, \
279 .private = _private, \
282 /* default cwrow<id>/attribute files */
283 CSROWDEV_ATTR(size_mb
, S_IRUGO
, csrow_size_show
, NULL
, 0);
284 CSROWDEV_ATTR(dev_type
, S_IRUGO
, csrow_dev_type_show
, NULL
, 0);
285 CSROWDEV_ATTR(mem_type
, S_IRUGO
, csrow_mem_type_show
, NULL
, 0);
286 CSROWDEV_ATTR(edac_mode
, S_IRUGO
, csrow_edac_mode_show
, NULL
, 0);
287 CSROWDEV_ATTR(ue_count
, S_IRUGO
, csrow_ue_count_show
, NULL
, 0);
288 CSROWDEV_ATTR(ce_count
, S_IRUGO
, csrow_ce_count_show
, NULL
, 0);
290 /* default attributes of the CSROW<id> object */
291 static struct csrowdev_attribute
*default_csrow_attr
[] = {
301 /* possible dynamic channel DIMM Label attribute files */
302 CSROWDEV_ATTR(ch0_dimm_label
, S_IRUGO
| S_IWUSR
,
303 channel_dimm_label_show
, channel_dimm_label_store
, 0);
304 CSROWDEV_ATTR(ch1_dimm_label
, S_IRUGO
| S_IWUSR
,
305 channel_dimm_label_show
, channel_dimm_label_store
, 1);
306 CSROWDEV_ATTR(ch2_dimm_label
, S_IRUGO
| S_IWUSR
,
307 channel_dimm_label_show
, channel_dimm_label_store
, 2);
308 CSROWDEV_ATTR(ch3_dimm_label
, S_IRUGO
| S_IWUSR
,
309 channel_dimm_label_show
, channel_dimm_label_store
, 3);
310 CSROWDEV_ATTR(ch4_dimm_label
, S_IRUGO
| S_IWUSR
,
311 channel_dimm_label_show
, channel_dimm_label_store
, 4);
312 CSROWDEV_ATTR(ch5_dimm_label
, S_IRUGO
| S_IWUSR
,
313 channel_dimm_label_show
, channel_dimm_label_store
, 5);
315 /* Total possible dynamic DIMM Label attribute file table */
316 static struct csrowdev_attribute
*dynamic_csrow_dimm_attr
[] = {
317 &attr_ch0_dimm_label
,
318 &attr_ch1_dimm_label
,
319 &attr_ch2_dimm_label
,
320 &attr_ch3_dimm_label
,
321 &attr_ch4_dimm_label
,
325 /* possible dynamic channel ce_count attribute files */
326 CSROWDEV_ATTR(ch0_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 0);
327 CSROWDEV_ATTR(ch1_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 1);
328 CSROWDEV_ATTR(ch2_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 2);
329 CSROWDEV_ATTR(ch3_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 3);
330 CSROWDEV_ATTR(ch4_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 4);
331 CSROWDEV_ATTR(ch5_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 5);
333 /* Total possible dynamic ce_count attribute file table */
334 static struct csrowdev_attribute
*dynamic_csrow_ce_count_attr
[] = {
343 #define EDAC_NR_CHANNELS 6
345 /* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */
346 static int edac_create_channel_files(struct kobject
*kobj
, int chan
)
350 if (chan
>= EDAC_NR_CHANNELS
)
353 /* create the DIMM label attribute file */
354 err
= sysfs_create_file(kobj
,
356 dynamic_csrow_dimm_attr
[chan
]);
359 /* create the CE Count attribute file */
360 err
= sysfs_create_file(kobj
,
362 dynamic_csrow_ce_count_attr
[chan
]);
364 debugf1("%s() dimm labels and ce_count files created",
371 /* No memory to release for this kobj */
372 static void edac_csrow_instance_release(struct kobject
*kobj
)
374 struct mem_ctl_info
*mci
;
375 struct csrow_info
*cs
;
377 debugf1("%s()\n", __func__
);
379 cs
= container_of(kobj
, struct csrow_info
, kobj
);
382 kobject_put(&mci
->edac_mci_kobj
);
385 /* the kobj_type instance for a CSROW */
386 static struct kobj_type ktype_csrow
= {
387 .release
= edac_csrow_instance_release
,
388 .sysfs_ops
= &csrowfs_ops
,
389 .default_attrs
= (struct attribute
**)default_csrow_attr
,
392 /* Create a CSROW object under specifed edac_mc_device */
393 static int edac_create_csrow_object(struct mem_ctl_info
*mci
,
394 struct csrow_info
*csrow
, int index
)
396 struct kobject
*kobj_mci
= &mci
->edac_mci_kobj
;
397 struct kobject
*kobj
;
401 /* generate ..../edac/mc/mc<id>/csrow<index> */
402 memset(&csrow
->kobj
, 0, sizeof(csrow
->kobj
));
403 csrow
->mci
= mci
; /* include container up link */
405 /* bump the mci instance's kobject's ref count */
406 kobj
= kobject_get(&mci
->edac_mci_kobj
);
412 /* Instanstiate the csrow object */
413 err
= kobject_init_and_add(&csrow
->kobj
, &ktype_csrow
, kobj_mci
,
416 goto err_release_top_kobj
;
418 /* At this point, to release a csrow kobj, one must
419 * call the kobject_put and allow that tear down
420 * to work the releasing
423 /* Create the dyanmic attribute files on this csrow,
424 * namely, the DIMM labels and the channel ce_count
426 for (chan
= 0; chan
< csrow
->nr_channels
; chan
++) {
427 err
= edac_create_channel_files(&csrow
->kobj
, chan
);
429 /* special case the unregister here */
430 kobject_put(&csrow
->kobj
);
434 kobject_uevent(&csrow
->kobj
, KOBJ_ADD
);
437 /* error unwind stack */
438 err_release_top_kobj
:
439 kobject_put(&mci
->edac_mci_kobj
);
445 /* default sysfs methods and data structures for the main MCI kobject */
447 static ssize_t
mci_reset_counters_store(struct mem_ctl_info
*mci
,
448 const char *data
, size_t count
)
452 mci
->ue_noinfo_count
= 0;
453 mci
->ce_noinfo_count
= 0;
457 for (row
= 0; row
< mci
->nr_csrows
; row
++) {
458 struct csrow_info
*ri
= &mci
->csrows
[row
];
463 for (chan
= 0; chan
< ri
->nr_channels
; chan
++)
464 ri
->channels
[chan
].ce_count
= 0;
467 mci
->start_time
= jiffies
;
471 /* memory scrubbing */
472 static ssize_t
mci_sdram_scrub_rate_store(struct mem_ctl_info
*mci
,
473 const char *data
, size_t count
)
477 if (mci
->set_sdram_scrub_rate
) {
479 memctrl_int_store(&bandwidth
, data
, count
);
481 if (!(*mci
->set_sdram_scrub_rate
) (mci
, &bandwidth
)) {
482 edac_printk(KERN_DEBUG
, EDAC_MC
,
483 "Scrub rate set successfully, applied: %d\n",
486 /* FIXME: error codes maybe? */
487 edac_printk(KERN_DEBUG
, EDAC_MC
,
488 "Scrub rate set FAILED, could not apply: %d\n",
492 /* FIXME: produce "not implemented" ERROR for user-side. */
493 edac_printk(KERN_WARNING
, EDAC_MC
,
494 "Memory scrubbing 'set'control is not implemented!\n");
499 static ssize_t
mci_sdram_scrub_rate_show(struct mem_ctl_info
*mci
, char *data
)
503 if (mci
->get_sdram_scrub_rate
) {
504 if (!(*mci
->get_sdram_scrub_rate
) (mci
, &bandwidth
)) {
505 edac_printk(KERN_DEBUG
, EDAC_MC
,
506 "Scrub rate successfully, fetched: %d\n",
509 /* FIXME: error codes maybe? */
510 edac_printk(KERN_DEBUG
, EDAC_MC
,
511 "Scrub rate fetch FAILED, got: %d\n",
515 /* FIXME: produce "not implemented" ERROR for user-side. */
516 edac_printk(KERN_WARNING
, EDAC_MC
,
517 "Memory scrubbing 'get' control is not implemented\n");
519 return sprintf(data
, "%d\n", bandwidth
);
522 /* default attribute files for the MCI object */
523 static ssize_t
mci_ue_count_show(struct mem_ctl_info
*mci
, char *data
)
525 return sprintf(data
, "%d\n", mci
->ue_count
);
528 static ssize_t
mci_ce_count_show(struct mem_ctl_info
*mci
, char *data
)
530 return sprintf(data
, "%d\n", mci
->ce_count
);
533 static ssize_t
mci_ce_noinfo_show(struct mem_ctl_info
*mci
, char *data
)
535 return sprintf(data
, "%d\n", mci
->ce_noinfo_count
);
538 static ssize_t
mci_ue_noinfo_show(struct mem_ctl_info
*mci
, char *data
)
540 return sprintf(data
, "%d\n", mci
->ue_noinfo_count
);
543 static ssize_t
mci_seconds_show(struct mem_ctl_info
*mci
, char *data
)
545 return sprintf(data
, "%ld\n", (jiffies
- mci
->start_time
) / HZ
);
548 static ssize_t
mci_ctl_name_show(struct mem_ctl_info
*mci
, char *data
)
550 return sprintf(data
, "%s\n", mci
->ctl_name
);
553 static ssize_t
mci_size_mb_show(struct mem_ctl_info
*mci
, char *data
)
555 int total_pages
, csrow_idx
;
557 for (total_pages
= csrow_idx
= 0; csrow_idx
< mci
->nr_csrows
;
559 struct csrow_info
*csrow
= &mci
->csrows
[csrow_idx
];
561 if (!csrow
->nr_pages
)
564 total_pages
+= csrow
->nr_pages
;
567 return sprintf(data
, "%u\n", PAGES_TO_MiB(total_pages
));
570 #define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
571 #define to_mcidev_attr(a) container_of(a,struct mcidev_sysfs_attribute,attr)
573 /* MCI show/store functions for top most object */
574 static ssize_t
mcidev_show(struct kobject
*kobj
, struct attribute
*attr
,
577 struct mem_ctl_info
*mem_ctl_info
= to_mci(kobj
);
578 struct mcidev_sysfs_attribute
*mcidev_attr
= to_mcidev_attr(attr
);
580 if (mcidev_attr
->show
)
581 return mcidev_attr
->show(mem_ctl_info
, buffer
);
586 static ssize_t
mcidev_store(struct kobject
*kobj
, struct attribute
*attr
,
587 const char *buffer
, size_t count
)
589 struct mem_ctl_info
*mem_ctl_info
= to_mci(kobj
);
590 struct mcidev_sysfs_attribute
*mcidev_attr
= to_mcidev_attr(attr
);
592 if (mcidev_attr
->store
)
593 return mcidev_attr
->store(mem_ctl_info
, buffer
, count
);
598 /* Intermediate show/store table */
599 static struct sysfs_ops mci_ops
= {
601 .store
= mcidev_store
604 #define MCIDEV_ATTR(_name,_mode,_show,_store) \
605 static struct mcidev_sysfs_attribute mci_attr_##_name = { \
606 .attr = {.name = __stringify(_name), .mode = _mode }, \
611 /* default Control file */
612 MCIDEV_ATTR(reset_counters
, S_IWUSR
, NULL
, mci_reset_counters_store
);
614 /* default Attribute files */
615 MCIDEV_ATTR(mc_name
, S_IRUGO
, mci_ctl_name_show
, NULL
);
616 MCIDEV_ATTR(size_mb
, S_IRUGO
, mci_size_mb_show
, NULL
);
617 MCIDEV_ATTR(seconds_since_reset
, S_IRUGO
, mci_seconds_show
, NULL
);
618 MCIDEV_ATTR(ue_noinfo_count
, S_IRUGO
, mci_ue_noinfo_show
, NULL
);
619 MCIDEV_ATTR(ce_noinfo_count
, S_IRUGO
, mci_ce_noinfo_show
, NULL
);
620 MCIDEV_ATTR(ue_count
, S_IRUGO
, mci_ue_count_show
, NULL
);
621 MCIDEV_ATTR(ce_count
, S_IRUGO
, mci_ce_count_show
, NULL
);
623 /* memory scrubber attribute file */
624 MCIDEV_ATTR(sdram_scrub_rate
, S_IRUGO
| S_IWUSR
, mci_sdram_scrub_rate_show
,
625 mci_sdram_scrub_rate_store
);
627 static struct mcidev_sysfs_attribute
*mci_attr
[] = {
628 &mci_attr_reset_counters
,
631 &mci_attr_seconds_since_reset
,
632 &mci_attr_ue_noinfo_count
,
633 &mci_attr_ce_noinfo_count
,
636 &mci_attr_sdram_scrub_rate
,
642 * Release of a MC controlling instance
644 * each MC control instance has the following resources upon entry:
645 * a) a ref count on the top memctl kobj
646 * b) a ref count on this module
648 * this function must decrement those ref counts and then
649 * issue a free on the instance's memory
651 static void edac_mci_control_release(struct kobject
*kobj
)
653 struct mem_ctl_info
*mci
;
657 debugf0("%s() mci instance idx=%d releasing\n", __func__
, mci
->mc_idx
);
659 /* decrement the module ref count */
660 module_put(mci
->owner
);
662 /* free the mci instance memory here */
666 static struct kobj_type ktype_mci
= {
667 .release
= edac_mci_control_release
,
668 .sysfs_ops
= &mci_ops
,
669 .default_attrs
= (struct attribute
**)mci_attr
,
672 /* show/store, tables, etc for the MC kset */
675 struct memctrl_dev_attribute
{
676 struct attribute attr
;
678 ssize_t(*show
) (void *, char *);
679 ssize_t(*store
) (void *, const char *, size_t);
682 /* Set of show/store abstract level functions for memory control object */
683 static ssize_t
memctrl_dev_show(struct kobject
*kobj
,
684 struct attribute
*attr
, char *buffer
)
686 struct memctrl_dev_attribute
*memctrl_dev
;
687 memctrl_dev
= (struct memctrl_dev_attribute
*)attr
;
689 if (memctrl_dev
->show
)
690 return memctrl_dev
->show(memctrl_dev
->value
, buffer
);
695 static ssize_t
memctrl_dev_store(struct kobject
*kobj
, struct attribute
*attr
,
696 const char *buffer
, size_t count
)
698 struct memctrl_dev_attribute
*memctrl_dev
;
699 memctrl_dev
= (struct memctrl_dev_attribute
*)attr
;
701 if (memctrl_dev
->store
)
702 return memctrl_dev
->store(memctrl_dev
->value
, buffer
, count
);
707 static struct sysfs_ops memctrlfs_ops
= {
708 .show
= memctrl_dev_show
,
709 .store
= memctrl_dev_store
712 #define MEMCTRL_ATTR(_name, _mode, _show, _store) \
713 static struct memctrl_dev_attribute attr_##_name = { \
714 .attr = {.name = __stringify(_name), .mode = _mode }, \
720 #define MEMCTRL_STRING_ATTR(_name, _data, _mode, _show, _store) \
721 static struct memctrl_dev_attribute attr_##_name = { \
722 .attr = {.name = __stringify(_name), .mode = _mode }, \
728 /* csrow<id> control files */
729 MEMCTRL_ATTR(edac_mc_panic_on_ue
,
730 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
732 MEMCTRL_ATTR(edac_mc_log_ue
,
733 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
735 MEMCTRL_ATTR(edac_mc_log_ce
,
736 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
738 MEMCTRL_ATTR(edac_mc_poll_msec
,
739 S_IRUGO
| S_IWUSR
, memctrl_int_show
, poll_msec_int_store
);
741 /* Base Attributes of the memory ECC object */
742 static struct memctrl_dev_attribute
*memctrl_attr
[] = {
743 &attr_edac_mc_panic_on_ue
,
744 &attr_edac_mc_log_ue
,
745 &attr_edac_mc_log_ce
,
746 &attr_edac_mc_poll_msec
,
751 /* the ktype for the mc_kset internal kobj */
752 static struct kobj_type ktype_mc_set_attribs
= {
753 .sysfs_ops
= &memctrlfs_ops
,
754 .default_attrs
= (struct attribute
**)memctrl_attr
,
757 /* EDAC memory controller sysfs kset:
758 * /sys/devices/system/edac/mc
760 static struct kset mc_kset
= {
761 .kobj
= {.ktype
= &ktype_mc_set_attribs
},
766 * edac_mc_register_sysfs_main_kobj
768 * setups and registers the main kobject for each mci
770 int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info
*mci
)
772 struct kobject
*kobj_mci
;
775 debugf1("%s()\n", __func__
);
777 kobj_mci
= &mci
->edac_mci_kobj
;
779 /* Init the mci's kobject */
780 memset(kobj_mci
, 0, sizeof(*kobj_mci
));
782 /* Record which module 'owns' this control structure
783 * and bump the ref count of the module
785 mci
->owner
= THIS_MODULE
;
787 /* bump ref count on this module */
788 if (!try_module_get(mci
->owner
)) {
793 /* this instance become part of the mc_kset */
794 kobj_mci
->kset
= &mc_kset
;
796 /* register the mc<id> kobject to the mc_kset */
797 err
= kobject_init_and_add(kobj_mci
, &ktype_mci
, NULL
,
798 "mc%d", mci
->mc_idx
);
800 debugf1("%s()Failed to register '.../edac/mc%d'\n",
801 __func__
, mci
->mc_idx
);
804 kobject_uevent(kobj_mci
, KOBJ_ADD
);
806 /* At this point, to 'free' the control struct,
807 * edac_mc_unregister_sysfs_main_kobj() must be used
810 debugf1("%s() Registered '.../edac/mc%d' kobject\n",
811 __func__
, mci
->mc_idx
);
815 /* Error exit stack */
818 module_put(mci
->owner
);
825 * edac_mc_register_sysfs_main_kobj
827 * tears down and the main mci kobject from the mc_kset
829 void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info
*mci
)
831 /* delete the kobj from the mc_kset */
832 kobject_put(&mci
->edac_mci_kobj
);
835 #define EDAC_DEVICE_SYMLINK "device"
838 * edac_create_mci_instance_attributes
839 * create MC driver specific attributes at the topmost level
840 * directory of this mci instance.
842 static int edac_create_mci_instance_attributes(struct mem_ctl_info
*mci
)
845 struct mcidev_sysfs_attribute
*sysfs_attrib
;
847 /* point to the start of the array and iterate over it
848 * adding each attribute listed to this mci instance's kobject
850 sysfs_attrib
= mci
->mc_driver_sysfs_attributes
;
852 while (sysfs_attrib
&& sysfs_attrib
->attr
.name
) {
853 err
= sysfs_create_file(&mci
->edac_mci_kobj
,
854 (struct attribute
*) sysfs_attrib
);
866 * edac_remove_mci_instance_attributes
867 * remove MC driver specific attributes at the topmost level
868 * directory of this mci instance.
870 static void edac_remove_mci_instance_attributes(struct mem_ctl_info
*mci
)
872 struct mcidev_sysfs_attribute
*sysfs_attrib
;
874 /* point to the start of the array and iterate over it
875 * adding each attribute listed to this mci instance's kobject
877 sysfs_attrib
= mci
->mc_driver_sysfs_attributes
;
879 /* loop if there are attributes and until we hit a NULL entry */
880 while (sysfs_attrib
&& sysfs_attrib
->attr
.name
) {
881 sysfs_remove_file(&mci
->edac_mci_kobj
,
882 (struct attribute
*) sysfs_attrib
);
889 * Create a new Memory Controller kobject instance,
890 * mc<id> under the 'mc' directory
896 int edac_create_sysfs_mci_device(struct mem_ctl_info
*mci
)
900 struct csrow_info
*csrow
;
901 struct kobject
*kobj_mci
= &mci
->edac_mci_kobj
;
903 debugf0("%s() idx=%d\n", __func__
, mci
->mc_idx
);
905 /* create a symlink for the device */
906 err
= sysfs_create_link(kobj_mci
, &mci
->dev
->kobj
,
907 EDAC_DEVICE_SYMLINK
);
909 debugf1("%s() failure to create symlink\n", __func__
);
913 /* If the low level driver desires some attributes,
914 * then create them now for the driver.
916 if (mci
->mc_driver_sysfs_attributes
) {
917 err
= edac_create_mci_instance_attributes(mci
);
919 debugf1("%s() failure to create mci attributes\n",
925 /* Make directories for each CSROW object under the mc<id> kobject
927 for (i
= 0; i
< mci
->nr_csrows
; i
++) {
928 csrow
= &mci
->csrows
[i
];
930 /* Only expose populated CSROWs */
931 if (csrow
->nr_pages
> 0) {
932 err
= edac_create_csrow_object(mci
, csrow
, i
);
934 debugf1("%s() failure: create csrow %d obj\n",
943 /* CSROW error: backout what has already been registered, */
945 for (i
--; i
>= 0; i
--) {
946 if (csrow
->nr_pages
> 0) {
947 kobject_put(&mci
->csrows
[i
].kobj
);
951 /* remove the mci instance's attributes, if any */
952 edac_remove_mci_instance_attributes(mci
);
954 /* remove the symlink */
955 sysfs_remove_link(kobj_mci
, EDAC_DEVICE_SYMLINK
);
962 * remove a Memory Controller instance
964 void edac_remove_sysfs_mci_device(struct mem_ctl_info
*mci
)
968 debugf0("%s()\n", __func__
);
970 /* remove all csrow kobjects */
971 for (i
= 0; i
< mci
->nr_csrows
; i
++) {
972 if (mci
->csrows
[i
].nr_pages
> 0) {
973 debugf0("%s() unreg csrow-%d\n", __func__
, i
);
974 kobject_put(&mci
->csrows
[i
].kobj
);
978 debugf0("%s() remove_link\n", __func__
);
980 /* remove the symlink */
981 sysfs_remove_link(&mci
->edac_mci_kobj
, EDAC_DEVICE_SYMLINK
);
983 debugf0("%s() remove_mci_instance\n", __func__
);
985 /* remove this mci instance's attribtes */
986 edac_remove_mci_instance_attributes(mci
);
988 debugf0("%s() unregister this mci kobj\n", __func__
);
990 /* unregister this instance's kobject */
991 kobject_put(&mci
->edac_mci_kobj
);
998 * edac_setup_sysfs_mc_kset(void)
1000 * Initialize the mc_kset for the 'mc' entry
1001 * This requires creating the top 'mc' directory with a kset
1002 * and its controls/attributes.
1004 * To this 'mc' kset, instance 'mci' will be grouped as children.
1007 * !0 FAILURE error code
1009 int edac_sysfs_setup_mc_kset(void)
1012 struct sysdev_class
*edac_class
;
1014 debugf1("%s()\n", __func__
);
1016 /* get the /sys/devices/system/edac class reference */
1017 edac_class
= edac_get_edac_class();
1018 if (edac_class
== NULL
) {
1019 debugf1("%s() no edac_class error=%d\n", __func__
, err
);
1023 /* Init the MC's kobject */
1024 kobject_set_name(&mc_kset
.kobj
, "mc");
1025 mc_kset
.kobj
.parent
= &edac_class
->kset
.kobj
;
1027 /* register the mc_kset */
1028 err
= kset_register(&mc_kset
);
1030 debugf1("%s() Failed to register '.../edac/mc'\n", __func__
);
1034 debugf1("%s() Registered '.../edac/mc' kobject\n", __func__
);
1039 /* error unwind stack */
1045 * edac_sysfs_teardown_mc_kset
1047 * deconstruct the mc_ket for memory controllers
1049 void edac_sysfs_teardown_mc_kset(void)
1051 kset_unregister(&mc_kset
);