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 /* Parameter declarations for above */
48 module_param(edac_mc_panic_on_ue
, int, 0644);
49 MODULE_PARM_DESC(edac_mc_panic_on_ue
, "Panic on uncorrected error: 0=off 1=on");
50 module_param(edac_mc_log_ue
, int, 0644);
51 MODULE_PARM_DESC(edac_mc_log_ue
,
52 "Log uncorrectable error to console: 0=off 1=on");
53 module_param(edac_mc_log_ce
, int, 0644);
54 MODULE_PARM_DESC(edac_mc_log_ce
,
55 "Log correctable error to console: 0=off 1=on");
56 module_param(edac_mc_poll_msec
, int, 0644);
57 MODULE_PARM_DESC(edac_mc_poll_msec
, "Polling period in milliseconds");
60 * various constants for Memory Controllers
62 static const char *mem_types
[] = {
63 [MEM_EMPTY
] = "Empty",
64 [MEM_RESERVED
] = "Reserved",
65 [MEM_UNKNOWN
] = "Unknown",
69 [MEM_SDR
] = "Unbuffered-SDR",
70 [MEM_RDR
] = "Registered-SDR",
71 [MEM_DDR
] = "Unbuffered-DDR",
72 [MEM_RDDR
] = "Registered-DDR",
74 [MEM_DDR2
] = "Unbuffered-DDR2",
75 [MEM_FB_DDR2
] = "FullyBuffered-DDR2",
76 [MEM_RDDR2
] = "Registered-DDR2"
79 static const char *dev_types
[] = {
80 [DEV_UNKNOWN
] = "Unknown",
90 static const char *edac_caps
[] = {
91 [EDAC_UNKNOWN
] = "Unknown",
93 [EDAC_RESERVED
] = "Reserved",
94 [EDAC_PARITY
] = "PARITY",
96 [EDAC_SECDED
] = "SECDED",
97 [EDAC_S2ECD2ED
] = "S2ECD2ED",
98 [EDAC_S4ECD4ED
] = "S4ECD4ED",
99 [EDAC_S8ECD8ED
] = "S8ECD8ED",
100 [EDAC_S16ECD16ED
] = "S16ECD16ED"
106 * /sys/devices/system/edac/mc;
107 * data structures and methods
109 static ssize_t
memctrl_int_show(void *ptr
, char *buffer
)
111 int *value
= (int *)ptr
;
112 return sprintf(buffer
, "%u\n", *value
);
115 static ssize_t
memctrl_int_store(void *ptr
, const char *buffer
, size_t count
)
117 int *value
= (int *)ptr
;
119 if (isdigit(*buffer
))
120 *value
= simple_strtoul(buffer
, NULL
, 0);
126 /* EDAC sysfs CSROW data structures and methods
129 /* Set of more default csrow<id> attribute show/store functions */
130 static ssize_t
csrow_ue_count_show(struct csrow_info
*csrow
, char *data
,
133 return sprintf(data
, "%u\n", csrow
->ue_count
);
136 static ssize_t
csrow_ce_count_show(struct csrow_info
*csrow
, char *data
,
139 return sprintf(data
, "%u\n", csrow
->ce_count
);
142 static ssize_t
csrow_size_show(struct csrow_info
*csrow
, char *data
,
145 return sprintf(data
, "%u\n", PAGES_TO_MiB(csrow
->nr_pages
));
148 static ssize_t
csrow_mem_type_show(struct csrow_info
*csrow
, char *data
,
151 return sprintf(data
, "%s\n", mem_types
[csrow
->mtype
]);
154 static ssize_t
csrow_dev_type_show(struct csrow_info
*csrow
, char *data
,
157 return sprintf(data
, "%s\n", dev_types
[csrow
->dtype
]);
160 static ssize_t
csrow_edac_mode_show(struct csrow_info
*csrow
, char *data
,
163 return sprintf(data
, "%s\n", edac_caps
[csrow
->edac_mode
]);
166 /* show/store functions for DIMM Label attributes */
167 static ssize_t
channel_dimm_label_show(struct csrow_info
*csrow
,
168 char *data
, int channel
)
170 return snprintf(data
, EDAC_MC_LABEL_LEN
, "%s",
171 csrow
->channels
[channel
].label
);
174 static ssize_t
channel_dimm_label_store(struct csrow_info
*csrow
,
176 size_t count
, int channel
)
178 ssize_t max_size
= 0;
180 max_size
= min((ssize_t
) count
, (ssize_t
) EDAC_MC_LABEL_LEN
- 1);
181 strncpy(csrow
->channels
[channel
].label
, data
, max_size
);
182 csrow
->channels
[channel
].label
[max_size
] = '\0';
187 /* show function for dynamic chX_ce_count attribute */
188 static ssize_t
channel_ce_count_show(struct csrow_info
*csrow
,
189 char *data
, int channel
)
191 return sprintf(data
, "%u\n", csrow
->channels
[channel
].ce_count
);
194 /* csrow specific attribute structure */
195 struct csrowdev_attribute
{
196 struct attribute attr
;
197 ssize_t(*show
) (struct csrow_info
*, char *, int);
198 ssize_t(*store
) (struct csrow_info
*, const char *, size_t, int);
202 #define to_csrow(k) container_of(k, struct csrow_info, kobj)
203 #define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
205 /* Set of show/store higher level functions for default csrow attributes */
206 static ssize_t
csrowdev_show(struct kobject
*kobj
,
207 struct attribute
*attr
, char *buffer
)
209 struct csrow_info
*csrow
= to_csrow(kobj
);
210 struct csrowdev_attribute
*csrowdev_attr
= to_csrowdev_attr(attr
);
212 if (csrowdev_attr
->show
)
213 return csrowdev_attr
->show(csrow
,
214 buffer
, csrowdev_attr
->private);
218 static ssize_t
csrowdev_store(struct kobject
*kobj
, struct attribute
*attr
,
219 const char *buffer
, size_t count
)
221 struct csrow_info
*csrow
= to_csrow(kobj
);
222 struct csrowdev_attribute
*csrowdev_attr
= to_csrowdev_attr(attr
);
224 if (csrowdev_attr
->store
)
225 return csrowdev_attr
->store(csrow
,
227 count
, csrowdev_attr
->private);
231 static struct sysfs_ops csrowfs_ops
= {
232 .show
= csrowdev_show
,
233 .store
= csrowdev_store
236 #define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \
237 static struct csrowdev_attribute attr_##_name = { \
238 .attr = {.name = __stringify(_name), .mode = _mode }, \
241 .private = _private, \
244 /* default cwrow<id>/attribute files */
245 CSROWDEV_ATTR(size_mb
, S_IRUGO
, csrow_size_show
, NULL
, 0);
246 CSROWDEV_ATTR(dev_type
, S_IRUGO
, csrow_dev_type_show
, NULL
, 0);
247 CSROWDEV_ATTR(mem_type
, S_IRUGO
, csrow_mem_type_show
, NULL
, 0);
248 CSROWDEV_ATTR(edac_mode
, S_IRUGO
, csrow_edac_mode_show
, NULL
, 0);
249 CSROWDEV_ATTR(ue_count
, S_IRUGO
, csrow_ue_count_show
, NULL
, 0);
250 CSROWDEV_ATTR(ce_count
, S_IRUGO
, csrow_ce_count_show
, NULL
, 0);
252 /* default attributes of the CSROW<id> object */
253 static struct csrowdev_attribute
*default_csrow_attr
[] = {
263 /* possible dynamic channel DIMM Label attribute files */
264 CSROWDEV_ATTR(ch0_dimm_label
, S_IRUGO
| S_IWUSR
,
265 channel_dimm_label_show
, channel_dimm_label_store
, 0);
266 CSROWDEV_ATTR(ch1_dimm_label
, S_IRUGO
| S_IWUSR
,
267 channel_dimm_label_show
, channel_dimm_label_store
, 1);
268 CSROWDEV_ATTR(ch2_dimm_label
, S_IRUGO
| S_IWUSR
,
269 channel_dimm_label_show
, channel_dimm_label_store
, 2);
270 CSROWDEV_ATTR(ch3_dimm_label
, S_IRUGO
| S_IWUSR
,
271 channel_dimm_label_show
, channel_dimm_label_store
, 3);
272 CSROWDEV_ATTR(ch4_dimm_label
, S_IRUGO
| S_IWUSR
,
273 channel_dimm_label_show
, channel_dimm_label_store
, 4);
274 CSROWDEV_ATTR(ch5_dimm_label
, S_IRUGO
| S_IWUSR
,
275 channel_dimm_label_show
, channel_dimm_label_store
, 5);
277 /* Total possible dynamic DIMM Label attribute file table */
278 static struct csrowdev_attribute
*dynamic_csrow_dimm_attr
[] = {
279 &attr_ch0_dimm_label
,
280 &attr_ch1_dimm_label
,
281 &attr_ch2_dimm_label
,
282 &attr_ch3_dimm_label
,
283 &attr_ch4_dimm_label
,
287 /* possible dynamic channel ce_count attribute files */
288 CSROWDEV_ATTR(ch0_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 0);
289 CSROWDEV_ATTR(ch1_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 1);
290 CSROWDEV_ATTR(ch2_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 2);
291 CSROWDEV_ATTR(ch3_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 3);
292 CSROWDEV_ATTR(ch4_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 4);
293 CSROWDEV_ATTR(ch5_ce_count
, S_IRUGO
| S_IWUSR
, channel_ce_count_show
, NULL
, 5);
295 /* Total possible dynamic ce_count attribute file table */
296 static struct csrowdev_attribute
*dynamic_csrow_ce_count_attr
[] = {
305 #define EDAC_NR_CHANNELS 6
307 /* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */
308 static int edac_create_channel_files(struct kobject
*kobj
, int chan
)
312 if (chan
>= EDAC_NR_CHANNELS
)
315 /* create the DIMM label attribute file */
316 err
= sysfs_create_file(kobj
,
318 dynamic_csrow_dimm_attr
[chan
]);
321 /* create the CE Count attribute file */
322 err
= sysfs_create_file(kobj
,
324 dynamic_csrow_ce_count_attr
[chan
]);
326 debugf1("%s() dimm labels and ce_count files created",
333 /* No memory to release for this kobj */
334 static void edac_csrow_instance_release(struct kobject
*kobj
)
336 struct mem_ctl_info
*mci
;
337 struct csrow_info
*cs
;
339 debugf1("%s()\n", __func__
);
341 cs
= container_of(kobj
, struct csrow_info
, kobj
);
344 kobject_put(&mci
->edac_mci_kobj
);
347 /* the kobj_type instance for a CSROW */
348 static struct kobj_type ktype_csrow
= {
349 .release
= edac_csrow_instance_release
,
350 .sysfs_ops
= &csrowfs_ops
,
351 .default_attrs
= (struct attribute
**)default_csrow_attr
,
354 /* Create a CSROW object under specifed edac_mc_device */
355 static int edac_create_csrow_object(struct mem_ctl_info
*mci
,
356 struct csrow_info
*csrow
, int index
)
358 struct kobject
*kobj_mci
= &mci
->edac_mci_kobj
;
359 struct kobject
*kobj
;
363 /* generate ..../edac/mc/mc<id>/csrow<index> */
364 memset(&csrow
->kobj
, 0, sizeof(csrow
->kobj
));
365 csrow
->mci
= mci
; /* include container up link */
366 csrow
->kobj
.parent
= kobj_mci
;
367 csrow
->kobj
.ktype
= &ktype_csrow
;
369 /* name this instance of csrow<id> */
370 err
= kobject_set_name(&csrow
->kobj
, "csrow%d", index
);
374 /* bump the mci instance's kobject's ref count */
375 kobj
= kobject_get(&mci
->edac_mci_kobj
);
381 /* Instanstiate the csrow object */
382 err
= kobject_register(&csrow
->kobj
);
384 goto err_release_top_kobj
;
386 /* At this point, to release a csrow kobj, one must
387 * call the kobject_unregister and allow that tear down
388 * to work the releasing
391 /* Create the dyanmic attribute files on this csrow,
392 * namely, the DIMM labels and the channel ce_count
394 for (chan
= 0; chan
< csrow
->nr_channels
; chan
++) {
395 err
= edac_create_channel_files(&csrow
->kobj
, chan
);
397 /* special case the unregister here */
398 kobject_unregister(&csrow
->kobj
);
405 /* error unwind stack */
406 err_release_top_kobj
:
407 kobject_put(&mci
->edac_mci_kobj
);
413 /* default sysfs methods and data structures for the main MCI kobject */
415 static ssize_t
mci_reset_counters_store(struct mem_ctl_info
*mci
,
416 const char *data
, size_t count
)
420 mci
->ue_noinfo_count
= 0;
421 mci
->ce_noinfo_count
= 0;
425 for (row
= 0; row
< mci
->nr_csrows
; row
++) {
426 struct csrow_info
*ri
= &mci
->csrows
[row
];
431 for (chan
= 0; chan
< ri
->nr_channels
; chan
++)
432 ri
->channels
[chan
].ce_count
= 0;
435 mci
->start_time
= jiffies
;
439 /* memory scrubbing */
440 static ssize_t
mci_sdram_scrub_rate_store(struct mem_ctl_info
*mci
,
441 const char *data
, size_t count
)
445 if (mci
->set_sdram_scrub_rate
) {
447 memctrl_int_store(&bandwidth
, data
, count
);
449 if (!(*mci
->set_sdram_scrub_rate
) (mci
, &bandwidth
)) {
450 edac_printk(KERN_DEBUG
, EDAC_MC
,
451 "Scrub rate set successfully, applied: %d\n",
454 /* FIXME: error codes maybe? */
455 edac_printk(KERN_DEBUG
, EDAC_MC
,
456 "Scrub rate set FAILED, could not apply: %d\n",
460 /* FIXME: produce "not implemented" ERROR for user-side. */
461 edac_printk(KERN_WARNING
, EDAC_MC
,
462 "Memory scrubbing 'set'control is not implemented!\n");
467 static ssize_t
mci_sdram_scrub_rate_show(struct mem_ctl_info
*mci
, char *data
)
471 if (mci
->get_sdram_scrub_rate
) {
472 if (!(*mci
->get_sdram_scrub_rate
) (mci
, &bandwidth
)) {
473 edac_printk(KERN_DEBUG
, EDAC_MC
,
474 "Scrub rate successfully, fetched: %d\n",
477 /* FIXME: error codes maybe? */
478 edac_printk(KERN_DEBUG
, EDAC_MC
,
479 "Scrub rate fetch FAILED, got: %d\n",
483 /* FIXME: produce "not implemented" ERROR for user-side. */
484 edac_printk(KERN_WARNING
, EDAC_MC
,
485 "Memory scrubbing 'get' control is not implemented\n");
487 return sprintf(data
, "%d\n", bandwidth
);
490 /* default attribute files for the MCI object */
491 static ssize_t
mci_ue_count_show(struct mem_ctl_info
*mci
, char *data
)
493 return sprintf(data
, "%d\n", mci
->ue_count
);
496 static ssize_t
mci_ce_count_show(struct mem_ctl_info
*mci
, char *data
)
498 return sprintf(data
, "%d\n", mci
->ce_count
);
501 static ssize_t
mci_ce_noinfo_show(struct mem_ctl_info
*mci
, char *data
)
503 return sprintf(data
, "%d\n", mci
->ce_noinfo_count
);
506 static ssize_t
mci_ue_noinfo_show(struct mem_ctl_info
*mci
, char *data
)
508 return sprintf(data
, "%d\n", mci
->ue_noinfo_count
);
511 static ssize_t
mci_seconds_show(struct mem_ctl_info
*mci
, char *data
)
513 return sprintf(data
, "%ld\n", (jiffies
- mci
->start_time
) / HZ
);
516 static ssize_t
mci_ctl_name_show(struct mem_ctl_info
*mci
, char *data
)
518 return sprintf(data
, "%s\n", mci
->ctl_name
);
521 static ssize_t
mci_size_mb_show(struct mem_ctl_info
*mci
, char *data
)
523 int total_pages
, csrow_idx
;
525 for (total_pages
= csrow_idx
= 0; csrow_idx
< mci
->nr_csrows
;
527 struct csrow_info
*csrow
= &mci
->csrows
[csrow_idx
];
529 if (!csrow
->nr_pages
)
532 total_pages
+= csrow
->nr_pages
;
535 return sprintf(data
, "%u\n", PAGES_TO_MiB(total_pages
));
538 #define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
539 #define to_mcidev_attr(a) container_of(a,struct mcidev_sysfs_attribute,attr)
541 /* MCI show/store functions for top most object */
542 static ssize_t
mcidev_show(struct kobject
*kobj
, struct attribute
*attr
,
545 struct mem_ctl_info
*mem_ctl_info
= to_mci(kobj
);
546 struct mcidev_sysfs_attribute
*mcidev_attr
= to_mcidev_attr(attr
);
548 if (mcidev_attr
->show
)
549 return mcidev_attr
->show(mem_ctl_info
, buffer
);
554 static ssize_t
mcidev_store(struct kobject
*kobj
, struct attribute
*attr
,
555 const char *buffer
, size_t count
)
557 struct mem_ctl_info
*mem_ctl_info
= to_mci(kobj
);
558 struct mcidev_sysfs_attribute
*mcidev_attr
= to_mcidev_attr(attr
);
560 if (mcidev_attr
->store
)
561 return mcidev_attr
->store(mem_ctl_info
, buffer
, count
);
566 /* Intermediate show/store table */
567 static struct sysfs_ops mci_ops
= {
569 .store
= mcidev_store
572 #define MCIDEV_ATTR(_name,_mode,_show,_store) \
573 static struct mcidev_sysfs_attribute mci_attr_##_name = { \
574 .attr = {.name = __stringify(_name), .mode = _mode }, \
579 /* default Control file */
580 MCIDEV_ATTR(reset_counters
, S_IWUSR
, NULL
, mci_reset_counters_store
);
582 /* default Attribute files */
583 MCIDEV_ATTR(mc_name
, S_IRUGO
, mci_ctl_name_show
, NULL
);
584 MCIDEV_ATTR(size_mb
, S_IRUGO
, mci_size_mb_show
, NULL
);
585 MCIDEV_ATTR(seconds_since_reset
, S_IRUGO
, mci_seconds_show
, NULL
);
586 MCIDEV_ATTR(ue_noinfo_count
, S_IRUGO
, mci_ue_noinfo_show
, NULL
);
587 MCIDEV_ATTR(ce_noinfo_count
, S_IRUGO
, mci_ce_noinfo_show
, NULL
);
588 MCIDEV_ATTR(ue_count
, S_IRUGO
, mci_ue_count_show
, NULL
);
589 MCIDEV_ATTR(ce_count
, S_IRUGO
, mci_ce_count_show
, NULL
);
591 /* memory scrubber attribute file */
592 MCIDEV_ATTR(sdram_scrub_rate
, S_IRUGO
| S_IWUSR
, mci_sdram_scrub_rate_show
,
593 mci_sdram_scrub_rate_store
);
595 static struct mcidev_sysfs_attribute
*mci_attr
[] = {
596 &mci_attr_reset_counters
,
599 &mci_attr_seconds_since_reset
,
600 &mci_attr_ue_noinfo_count
,
601 &mci_attr_ce_noinfo_count
,
604 &mci_attr_sdram_scrub_rate
,
610 * Release of a MC controlling instance
612 * each MC control instance has the following resources upon entry:
613 * a) a ref count on the top memctl kobj
614 * b) a ref count on this module
616 * this function must decrement those ref counts and then
617 * issue a free on the instance's memory
619 static void edac_mci_control_release(struct kobject
*kobj
)
621 struct mem_ctl_info
*mci
;
625 debugf0("%s() mci instance idx=%d releasing\n", __func__
, mci
->mc_idx
);
627 /* decrement the module ref count */
628 module_put(mci
->owner
);
630 /* free the mci instance memory here */
634 static struct kobj_type ktype_mci
= {
635 .release
= edac_mci_control_release
,
636 .sysfs_ops
= &mci_ops
,
637 .default_attrs
= (struct attribute
**)mci_attr
,
640 /* show/store, tables, etc for the MC kset */
643 struct memctrl_dev_attribute
{
644 struct attribute attr
;
646 ssize_t(*show
) (void *, char *);
647 ssize_t(*store
) (void *, const char *, size_t);
650 /* Set of show/store abstract level functions for memory control object */
651 static ssize_t
memctrl_dev_show(struct kobject
*kobj
,
652 struct attribute
*attr
, char *buffer
)
654 struct memctrl_dev_attribute
*memctrl_dev
;
655 memctrl_dev
= (struct memctrl_dev_attribute
*)attr
;
657 if (memctrl_dev
->show
)
658 return memctrl_dev
->show(memctrl_dev
->value
, buffer
);
663 static ssize_t
memctrl_dev_store(struct kobject
*kobj
, struct attribute
*attr
,
664 const char *buffer
, size_t count
)
666 struct memctrl_dev_attribute
*memctrl_dev
;
667 memctrl_dev
= (struct memctrl_dev_attribute
*)attr
;
669 if (memctrl_dev
->store
)
670 return memctrl_dev
->store(memctrl_dev
->value
, buffer
, count
);
675 static struct sysfs_ops memctrlfs_ops
= {
676 .show
= memctrl_dev_show
,
677 .store
= memctrl_dev_store
680 #define MEMCTRL_ATTR(_name, _mode, _show, _store) \
681 static struct memctrl_dev_attribute attr_##_name = { \
682 .attr = {.name = __stringify(_name), .mode = _mode }, \
688 #define MEMCTRL_STRING_ATTR(_name, _data, _mode, _show, _store) \
689 static struct memctrl_dev_attribute attr_##_name = { \
690 .attr = {.name = __stringify(_name), .mode = _mode }, \
696 /* csrow<id> control files */
697 MEMCTRL_ATTR(edac_mc_panic_on_ue
,
698 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
700 MEMCTRL_ATTR(edac_mc_log_ue
,
701 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
703 MEMCTRL_ATTR(edac_mc_log_ce
,
704 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
706 MEMCTRL_ATTR(edac_mc_poll_msec
,
707 S_IRUGO
| S_IWUSR
, memctrl_int_show
, memctrl_int_store
);
709 /* Base Attributes of the memory ECC object */
710 static struct memctrl_dev_attribute
*memctrl_attr
[] = {
711 &attr_edac_mc_panic_on_ue
,
712 &attr_edac_mc_log_ue
,
713 &attr_edac_mc_log_ce
,
714 &attr_edac_mc_poll_msec
,
719 /* the ktype for the mc_kset internal kobj */
720 static struct kobj_type ktype_mc_set_attribs
= {
721 .sysfs_ops
= &memctrlfs_ops
,
722 .default_attrs
= (struct attribute
**)memctrl_attr
,
725 /* EDAC memory controller sysfs kset:
726 * /sys/devices/system/edac/mc
728 static struct kset mc_kset
= {
729 .kobj
= {.name
= "mc", .ktype
= &ktype_mc_set_attribs
},
735 * edac_mc_register_sysfs_main_kobj
737 * setups and registers the main kobject for each mci
739 int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info
*mci
)
741 struct kobject
*kobj_mci
;
744 debugf1("%s()\n", __func__
);
746 kobj_mci
= &mci
->edac_mci_kobj
;
748 /* Init the mci's kobject */
749 memset(kobj_mci
, 0, sizeof(*kobj_mci
));
751 /* this instance become part of the mc_kset */
752 kobj_mci
->kset
= &mc_kset
;
754 /* set the name of the mc<id> object */
755 err
= kobject_set_name(kobj_mci
, "mc%d", mci
->mc_idx
);
759 /* Record which module 'owns' this control structure
760 * and bump the ref count of the module
762 mci
->owner
= THIS_MODULE
;
764 /* bump ref count on this module */
765 if (!try_module_get(mci
->owner
)) {
770 /* register the mc<id> kobject to the mc_kset */
771 err
= kobject_register(kobj_mci
);
773 debugf1("%s()Failed to register '.../edac/mc%d'\n",
774 __func__
, mci
->mc_idx
);
778 /* At this point, to 'free' the control struct,
779 * edac_mc_unregister_sysfs_main_kobj() must be used
782 debugf1("%s() Registered '.../edac/mc%d' kobject\n",
783 __func__
, mci
->mc_idx
);
787 /* Error exit stack */
790 module_put(mci
->owner
);
797 * edac_mc_register_sysfs_main_kobj
799 * tears down and the main mci kobject from the mc_kset
801 void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info
*mci
)
803 /* delete the kobj from the mc_kset */
804 kobject_unregister(&mci
->edac_mci_kobj
);
807 #define EDAC_DEVICE_SYMLINK "device"
810 * edac_create_mci_instance_attributes
811 * create MC driver specific attributes at the topmost level
812 * directory of this mci instance.
814 static int edac_create_mci_instance_attributes(struct mem_ctl_info
*mci
)
817 struct mcidev_sysfs_attribute
*sysfs_attrib
;
819 /* point to the start of the array and iterate over it
820 * adding each attribute listed to this mci instance's kobject
822 sysfs_attrib
= mci
->mc_driver_sysfs_attributes
;
824 while (sysfs_attrib
&& sysfs_attrib
->attr
.name
) {
825 err
= sysfs_create_file(&mci
->edac_mci_kobj
,
826 (struct attribute
*) sysfs_attrib
);
838 * edac_remove_mci_instance_attributes
839 * remove MC driver specific attributes at the topmost level
840 * directory of this mci instance.
842 static void edac_remove_mci_instance_attributes(struct mem_ctl_info
*mci
)
844 struct mcidev_sysfs_attribute
*sysfs_attrib
;
846 /* point to the start of the array and iterate over it
847 * adding each attribute listed to this mci instance's kobject
849 sysfs_attrib
= mci
->mc_driver_sysfs_attributes
;
851 /* loop if there are attributes and until we hit a NULL entry */
852 while (sysfs_attrib
&& sysfs_attrib
->attr
.name
) {
853 sysfs_remove_file(&mci
->edac_mci_kobj
,
854 (struct attribute
*) sysfs_attrib
);
861 * Create a new Memory Controller kobject instance,
862 * mc<id> under the 'mc' directory
868 int edac_create_sysfs_mci_device(struct mem_ctl_info
*mci
)
872 struct csrow_info
*csrow
;
873 struct kobject
*kobj_mci
= &mci
->edac_mci_kobj
;
875 debugf0("%s() idx=%d\n", __func__
, mci
->mc_idx
);
877 /* create a symlink for the device */
878 err
= sysfs_create_link(kobj_mci
, &mci
->dev
->kobj
,
879 EDAC_DEVICE_SYMLINK
);
881 debugf1("%s() failure to create symlink\n", __func__
);
885 /* If the low level driver desires some attributes,
886 * then create them now for the driver.
888 if (mci
->mc_driver_sysfs_attributes
) {
889 err
= edac_create_mci_instance_attributes(mci
);
891 debugf1("%s() failure to create mci attributes\n",
897 /* Make directories for each CSROW object under the mc<id> kobject
899 for (i
= 0; i
< mci
->nr_csrows
; i
++) {
900 csrow
= &mci
->csrows
[i
];
902 /* Only expose populated CSROWs */
903 if (csrow
->nr_pages
> 0) {
904 err
= edac_create_csrow_object(mci
, csrow
, i
);
906 debugf1("%s() failure: create csrow %d obj\n",
915 /* CSROW error: backout what has already been registered, */
917 for (i
--; i
>= 0; i
--) {
918 if (csrow
->nr_pages
> 0) {
919 kobject_unregister(&mci
->csrows
[i
].kobj
);
923 /* remove the mci instance's attributes, if any */
924 edac_remove_mci_instance_attributes(mci
);
926 /* remove the symlink */
927 sysfs_remove_link(kobj_mci
, EDAC_DEVICE_SYMLINK
);
934 * remove a Memory Controller instance
936 void edac_remove_sysfs_mci_device(struct mem_ctl_info
*mci
)
940 debugf0("%s()\n", __func__
);
942 /* remove all csrow kobjects */
943 for (i
= 0; i
< mci
->nr_csrows
; i
++) {
944 if (mci
->csrows
[i
].nr_pages
> 0) {
945 debugf0("%s() unreg csrow-%d\n", __func__
, i
);
946 kobject_unregister(&mci
->csrows
[i
].kobj
);
950 debugf0("%s() remove_link\n", __func__
);
952 /* remove the symlink */
953 sysfs_remove_link(&mci
->edac_mci_kobj
, EDAC_DEVICE_SYMLINK
);
955 debugf0("%s() remove_mci_instance\n", __func__
);
957 /* remove this mci instance's attribtes */
958 edac_remove_mci_instance_attributes(mci
);
960 debugf0("%s() unregister this mci kobj\n", __func__
);
962 /* unregister this instance's kobject */
963 kobject_unregister(&mci
->edac_mci_kobj
);
970 * edac_setup_sysfs_mc_kset(void)
972 * Initialize the mc_kset for the 'mc' entry
973 * This requires creating the top 'mc' directory with a kset
974 * and its controls/attributes.
976 * To this 'mc' kset, instance 'mci' will be grouped as children.
979 * !0 FAILURE error code
981 int edac_sysfs_setup_mc_kset(void)
984 struct sysdev_class
*edac_class
;
986 debugf1("%s()\n", __func__
);
988 /* get the /sys/devices/system/edac class reference */
989 edac_class
= edac_get_edac_class();
990 if (edac_class
== NULL
) {
991 debugf1("%s() no edac_class error=%d\n", __func__
, err
);
995 /* Init the MC's kobject */
996 mc_kset
.kobj
.parent
= &edac_class
->kset
.kobj
;
998 /* register the mc_kset */
999 err
= kset_register(&mc_kset
);
1001 debugf1("%s() Failed to register '.../edac/mc'\n", __func__
);
1005 debugf1("%s() Registered '.../edac/mc' kobject\n", __func__
);
1010 /* error unwind stack */
1016 * edac_sysfs_teardown_mc_kset
1018 * deconstruct the mc_ket for memory controllers
1020 void edac_sysfs_teardown_mc_kset(void)
1022 kset_unregister(&mc_kset
);