]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/edac/edac_mc.c
drivers/edac: split out functions to unique files
[linux-2.6-omap-h63xx.git] / drivers / edac / edac_mc.c
1 /*
2  * edac_mc kernel module
3  * (C) 2005, 2006 Linux Networx (http://lnxi.com)
4  * This file may be distributed under the terms of the
5  * GNU General Public License.
6  *
7  * Written by Thayne Harbaugh
8  * Based on work by Dan Hollis <goemon at anime dot net> and others.
9  *      http://www.anime.net/~goemon/linux-ecc/
10  *
11  * Modified by Dave Peterson and Doug Thompson
12  *
13  */
14
15 #include <linux/module.h>
16 #include <linux/proc_fs.h>
17 #include <linux/kernel.h>
18 #include <linux/types.h>
19 #include <linux/smp.h>
20 #include <linux/init.h>
21 #include <linux/sysctl.h>
22 #include <linux/highmem.h>
23 #include <linux/timer.h>
24 #include <linux/slab.h>
25 #include <linux/jiffies.h>
26 #include <linux/spinlock.h>
27 #include <linux/list.h>
28 #include <linux/sysdev.h>
29 #include <linux/ctype.h>
30 #include <asm/uaccess.h>
31 #include <asm/page.h>
32 #include <asm/edac.h>
33 #include "edac_mc.h"
34 #include "edac_module.h"
35
36
37 /* lock to memory controller's control array */
38 static DECLARE_MUTEX(mem_ctls_mutex);
39 static struct list_head mc_devices = LIST_HEAD_INIT(mc_devices);
40
41 #ifdef CONFIG_EDAC_DEBUG
42
43 static void edac_mc_dump_channel(struct channel_info *chan)
44 {
45         debugf4("\tchannel = %p\n", chan);
46         debugf4("\tchannel->chan_idx = %d\n", chan->chan_idx);
47         debugf4("\tchannel->ce_count = %d\n", chan->ce_count);
48         debugf4("\tchannel->label = '%s'\n", chan->label);
49         debugf4("\tchannel->csrow = %p\n\n", chan->csrow);
50 }
51
52 static void edac_mc_dump_csrow(struct csrow_info *csrow)
53 {
54         debugf4("\tcsrow = %p\n", csrow);
55         debugf4("\tcsrow->csrow_idx = %d\n", csrow->csrow_idx);
56         debugf4("\tcsrow->first_page = 0x%lx\n",
57                 csrow->first_page);
58         debugf4("\tcsrow->last_page = 0x%lx\n", csrow->last_page);
59         debugf4("\tcsrow->page_mask = 0x%lx\n", csrow->page_mask);
60         debugf4("\tcsrow->nr_pages = 0x%x\n", csrow->nr_pages);
61         debugf4("\tcsrow->nr_channels = %d\n",
62                 csrow->nr_channels);
63         debugf4("\tcsrow->channels = %p\n", csrow->channels);
64         debugf4("\tcsrow->mci = %p\n\n", csrow->mci);
65 }
66
67 static void edac_mc_dump_mci(struct mem_ctl_info *mci)
68 {
69         debugf3("\tmci = %p\n", mci);
70         debugf3("\tmci->mtype_cap = %lx\n", mci->mtype_cap);
71         debugf3("\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap);
72         debugf3("\tmci->edac_cap = %lx\n", mci->edac_cap);
73         debugf4("\tmci->edac_check = %p\n", mci->edac_check);
74         debugf3("\tmci->nr_csrows = %d, csrows = %p\n",
75                 mci->nr_csrows, mci->csrows);
76         debugf3("\tdev = %p\n", mci->dev);
77         debugf3("\tmod_name:ctl_name = %s:%s\n",
78                 mci->mod_name, mci->ctl_name);
79         debugf3("\tpvt_info = %p\n\n", mci->pvt_info);
80 }
81
82 #endif  /* CONFIG_EDAC_DEBUG */
83
84 /* 'ptr' points to a possibly unaligned item X such that sizeof(X) is 'size'.
85  * Adjust 'ptr' so that its alignment is at least as stringent as what the
86  * compiler would provide for X and return the aligned result.
87  *
88  * If 'size' is a constant, the compiler will optimize this whole function
89  * down to either a no-op or the addition of a constant to the value of 'ptr'.
90  */
91 static inline char * align_ptr(void *ptr, unsigned size)
92 {
93         unsigned align, r;
94
95         /* Here we assume that the alignment of a "long long" is the most
96          * stringent alignment that the compiler will ever provide by default.
97          * As far as I know, this is a reasonable assumption.
98          */
99         if (size > sizeof(long))
100                 align = sizeof(long long);
101         else if (size > sizeof(int))
102                 align = sizeof(long);
103         else if (size > sizeof(short))
104                 align = sizeof(int);
105         else if (size > sizeof(char))
106                 align = sizeof(short);
107         else
108                 return (char *) ptr;
109
110         r = size % align;
111
112         if (r == 0)
113                 return (char *) ptr;
114
115         return (char *) (((unsigned long) ptr) + align - r);
116 }
117
118 /**
119  * edac_mc_alloc: Allocate a struct mem_ctl_info structure
120  * @size_pvt:   size of private storage needed
121  * @nr_csrows:  Number of CWROWS needed for this MC
122  * @nr_chans:   Number of channels for the MC
123  *
124  * Everything is kmalloc'ed as one big chunk - more efficient.
125  * Only can be used if all structures have the same lifetime - otherwise
126  * you have to allocate and initialize your own structures.
127  *
128  * Use edac_mc_free() to free mc structures allocated by this function.
129  *
130  * Returns:
131  *      NULL allocation failed
132  *      struct mem_ctl_info pointer
133  */
134 struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
135                 unsigned nr_chans)
136 {
137         struct mem_ctl_info *mci;
138         struct csrow_info *csi, *csrow;
139         struct channel_info *chi, *chp, *chan;
140         void *pvt;
141         unsigned size;
142         int row, chn;
143
144         /* Figure out the offsets of the various items from the start of an mc
145          * structure.  We want the alignment of each item to be at least as
146          * stringent as what the compiler would provide if we could simply
147          * hardcode everything into a single struct.
148          */
149         mci = (struct mem_ctl_info *) 0;
150         csi = (struct csrow_info *)align_ptr(&mci[1], sizeof(*csi));
151         chi = (struct channel_info *)
152                         align_ptr(&csi[nr_csrows], sizeof(*chi));
153         pvt = align_ptr(&chi[nr_chans * nr_csrows], sz_pvt);
154         size = ((unsigned long) pvt) + sz_pvt;
155
156         if ((mci = kmalloc(size, GFP_KERNEL)) == NULL)
157                 return NULL;
158
159         /* Adjust pointers so they point within the memory we just allocated
160          * rather than an imaginary chunk of memory located at address 0.
161          */
162         csi = (struct csrow_info *) (((char *) mci) + ((unsigned long) csi));
163         chi = (struct channel_info *) (((char *) mci) + ((unsigned long) chi));
164         pvt = sz_pvt ? (((char *) mci) + ((unsigned long) pvt)) : NULL;
165
166         memset(mci, 0, size);  /* clear all fields */
167         mci->csrows = csi;
168         mci->pvt_info = pvt;
169         mci->nr_csrows = nr_csrows;
170
171         for (row = 0; row < nr_csrows; row++) {
172                 csrow = &csi[row];
173                 csrow->csrow_idx = row;
174                 csrow->mci = mci;
175                 csrow->nr_channels = nr_chans;
176                 chp = &chi[row * nr_chans];
177                 csrow->channels = chp;
178
179                 for (chn = 0; chn < nr_chans; chn++) {
180                         chan = &chp[chn];
181                         chan->chan_idx = chn;
182                         chan->csrow = csrow;
183                 }
184         }
185
186         return mci;
187 }
188 EXPORT_SYMBOL_GPL(edac_mc_alloc);
189
190 /**
191  * edac_mc_free:  Free a previously allocated 'mci' structure
192  * @mci: pointer to a struct mem_ctl_info structure
193  */
194 void edac_mc_free(struct mem_ctl_info *mci)
195 {
196         kfree(mci);
197 }
198 EXPORT_SYMBOL_GPL(edac_mc_free);
199
200 static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
201 {
202         struct mem_ctl_info *mci;
203         struct list_head *item;
204
205         debugf3("%s()\n", __func__);
206
207         list_for_each(item, &mc_devices) {
208                 mci = list_entry(item, struct mem_ctl_info, link);
209
210                 if (mci->dev == dev)
211                         return mci;
212         }
213
214         return NULL;
215 }
216
217 /* Return 0 on success, 1 on failure.
218  * Before calling this function, caller must
219  * assign a unique value to mci->mc_idx.
220  */
221 static int add_mc_to_global_list (struct mem_ctl_info *mci)
222 {
223         struct list_head *item, *insert_before;
224         struct mem_ctl_info *p;
225
226         insert_before = &mc_devices;
227
228         if (unlikely((p = find_mci_by_dev(mci->dev)) != NULL))
229                 goto fail0;
230
231         list_for_each(item, &mc_devices) {
232                 p = list_entry(item, struct mem_ctl_info, link);
233
234                 if (p->mc_idx >= mci->mc_idx) {
235                         if (unlikely(p->mc_idx == mci->mc_idx))
236                                 goto fail1;
237
238                         insert_before = item;
239                         break;
240                 }
241         }
242
243         list_add_tail_rcu(&mci->link, insert_before);
244         return 0;
245
246 fail0:
247         edac_printk(KERN_WARNING, EDAC_MC,
248                     "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
249                     dev_name(p->dev), p->mod_name, p->ctl_name, p->mc_idx);
250         return 1;
251
252 fail1:
253         edac_printk(KERN_WARNING, EDAC_MC,
254                     "bug in low-level driver: attempt to assign\n"
255                     "    duplicate mc_idx %d in %s()\n", p->mc_idx, __func__);
256         return 1;
257 }
258
259 static void complete_mc_list_del(struct rcu_head *head)
260 {
261         struct mem_ctl_info *mci;
262
263         mci = container_of(head, struct mem_ctl_info, rcu);
264         INIT_LIST_HEAD(&mci->link);
265         complete(&mci->complete);
266 }
267
268 static void del_mc_from_global_list(struct mem_ctl_info *mci)
269 {
270         list_del_rcu(&mci->link);
271         init_completion(&mci->complete);
272         call_rcu(&mci->rcu, complete_mc_list_del);
273         wait_for_completion(&mci->complete);
274 }
275
276 /**
277  * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'.
278  *
279  * If found, return a pointer to the structure.
280  * Else return NULL.
281  *
282  * Caller must hold mem_ctls_mutex.
283  */
284 struct mem_ctl_info * edac_mc_find(int idx)
285 {
286         struct list_head *item;
287         struct mem_ctl_info *mci;
288
289         list_for_each(item, &mc_devices) {
290                 mci = list_entry(item, struct mem_ctl_info, link);
291
292                 if (mci->mc_idx >= idx) {
293                         if (mci->mc_idx == idx)
294                                 return mci;
295
296                         break;
297                 }
298         }
299
300         return NULL;
301 }
302 EXPORT_SYMBOL(edac_mc_find);
303
304 /**
305  * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and
306  *                 create sysfs entries associated with mci structure
307  * @mci: pointer to the mci structure to be added to the list
308  * @mc_idx: A unique numeric identifier to be assigned to the 'mci' structure.
309  *
310  * Return:
311  *      0       Success
312  *      !0      Failure
313  */
314
315 /* FIXME - should a warning be printed if no error detection? correction? */
316 int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
317 {
318         debugf0("%s()\n", __func__);
319         mci->mc_idx = mc_idx;
320 #ifdef CONFIG_EDAC_DEBUG
321         if (edac_debug_level >= 3)
322                 edac_mc_dump_mci(mci);
323
324         if (edac_debug_level >= 4) {
325                 int i;
326
327                 for (i = 0; i < mci->nr_csrows; i++) {
328                         int j;
329
330                         edac_mc_dump_csrow(&mci->csrows[i]);
331                         for (j = 0; j < mci->csrows[i].nr_channels; j++)
332                                 edac_mc_dump_channel(
333                                         &mci->csrows[i].channels[j]);
334                 }
335         }
336 #endif
337         down(&mem_ctls_mutex);
338
339         if (add_mc_to_global_list(mci))
340                 goto fail0;
341
342         /* set load time so that error rate can be tracked */
343         mci->start_time = jiffies;
344
345         if (edac_create_sysfs_mci_device(mci)) {
346                 edac_mc_printk(mci, KERN_WARNING,
347                         "failed to create sysfs device\n");
348                 goto fail1;
349         }
350
351         /* Report action taken */
352         edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
353                 mci->mod_name, mci->ctl_name, dev_name(mci->dev));
354
355         up(&mem_ctls_mutex);
356         return 0;
357
358 fail1:
359         del_mc_from_global_list(mci);
360
361 fail0:
362         up(&mem_ctls_mutex);
363         return 1;
364 }
365 EXPORT_SYMBOL_GPL(edac_mc_add_mc);
366
367 /**
368  * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
369  *                 remove mci structure from global list
370  * @pdev: Pointer to 'struct device' representing mci structure to remove.
371  *
372  * Return pointer to removed mci structure, or NULL if device not found.
373  */
374 struct mem_ctl_info * edac_mc_del_mc(struct device *dev)
375 {
376         struct mem_ctl_info *mci;
377
378         debugf0("MC: %s()\n", __func__);
379         down(&mem_ctls_mutex);
380
381         if ((mci = find_mci_by_dev(dev)) == NULL) {
382                 up(&mem_ctls_mutex);
383                 return NULL;
384         }
385
386         edac_remove_sysfs_mci_device(mci);
387         del_mc_from_global_list(mci);
388         up(&mem_ctls_mutex);
389         edac_printk(KERN_INFO, EDAC_MC,
390                 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
391                 mci->mod_name, mci->ctl_name, dev_name(mci->dev));
392         return mci;
393 }
394 EXPORT_SYMBOL_GPL(edac_mc_del_mc);
395
396 static void edac_mc_scrub_block(unsigned long page, unsigned long offset,
397                                 u32 size)
398 {
399         struct page *pg;
400         void *virt_addr;
401         unsigned long flags = 0;
402
403         debugf3("%s()\n", __func__);
404
405         /* ECC error page was not in our memory. Ignore it. */
406         if(!pfn_valid(page))
407                 return;
408
409         /* Find the actual page structure then map it and fix */
410         pg = pfn_to_page(page);
411
412         if (PageHighMem(pg))
413                 local_irq_save(flags);
414
415         virt_addr = kmap_atomic(pg, KM_BOUNCE_READ);
416
417         /* Perform architecture specific atomic scrub operation */
418         atomic_scrub(virt_addr + offset, size);
419
420         /* Unmap and complete */
421         kunmap_atomic(virt_addr, KM_BOUNCE_READ);
422
423         if (PageHighMem(pg))
424                 local_irq_restore(flags);
425 }
426
427 /* FIXME - should return -1 */
428 int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page)
429 {
430         struct csrow_info *csrows = mci->csrows;
431         int row, i;
432
433         debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page);
434         row = -1;
435
436         for (i = 0; i < mci->nr_csrows; i++) {
437                 struct csrow_info *csrow = &csrows[i];
438
439                 if (csrow->nr_pages == 0)
440                         continue;
441
442                 debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) "
443                         "mask(0x%lx)\n", mci->mc_idx, __func__,
444                         csrow->first_page, page, csrow->last_page,
445                         csrow->page_mask);
446
447                 if ((page >= csrow->first_page) &&
448                     (page <= csrow->last_page) &&
449                     ((page & csrow->page_mask) ==
450                      (csrow->first_page & csrow->page_mask))) {
451                         row = i;
452                         break;
453                 }
454         }
455
456         if (row == -1)
457                 edac_mc_printk(mci, KERN_ERR,
458                         "could not look up page error address %lx\n",
459                         (unsigned long) page);
460
461         return row;
462 }
463 EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page);
464
465 /* FIXME - setable log (warning/emerg) levels */
466 /* FIXME - integrate with evlog: http://evlog.sourceforge.net/ */
467 void edac_mc_handle_ce(struct mem_ctl_info *mci,
468                 unsigned long page_frame_number, unsigned long offset_in_page,
469                 unsigned long syndrome, int row, int channel, const char *msg)
470 {
471         unsigned long remapped_page;
472
473         debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
474
475         /* FIXME - maybe make panic on INTERNAL ERROR an option */
476         if (row >= mci->nr_csrows || row < 0) {
477                 /* something is wrong */
478                 edac_mc_printk(mci, KERN_ERR,
479                         "INTERNAL ERROR: row out of range "
480                         "(%d >= %d)\n", row, mci->nr_csrows);
481                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
482                 return;
483         }
484
485         if (channel >= mci->csrows[row].nr_channels || channel < 0) {
486                 /* something is wrong */
487                 edac_mc_printk(mci, KERN_ERR,
488                         "INTERNAL ERROR: channel out of range "
489                         "(%d >= %d)\n", channel,
490                         mci->csrows[row].nr_channels);
491                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
492                 return;
493         }
494
495         if (edac_get_log_ce())
496                 /* FIXME - put in DIMM location */
497                 edac_mc_printk(mci, KERN_WARNING,
498                         "CE page 0x%lx, offset 0x%lx, grain %d, syndrome "
499                         "0x%lx, row %d, channel %d, label \"%s\": %s\n",
500                         page_frame_number, offset_in_page,
501                         mci->csrows[row].grain, syndrome, row, channel,
502                         mci->csrows[row].channels[channel].label, msg);
503
504         mci->ce_count++;
505         mci->csrows[row].ce_count++;
506         mci->csrows[row].channels[channel].ce_count++;
507
508         if (mci->scrub_mode & SCRUB_SW_SRC) {
509                 /*
510                  * Some MC's can remap memory so that it is still available
511                  * at a different address when PCI devices map into memory.
512                  * MC's that can't do this lose the memory where PCI devices
513                  * are mapped.  This mapping is MC dependant and so we call
514                  * back into the MC driver for it to map the MC page to
515                  * a physical (CPU) page which can then be mapped to a virtual
516                  * page - which can then be scrubbed.
517                  */
518                 remapped_page = mci->ctl_page_to_phys ?
519                     mci->ctl_page_to_phys(mci, page_frame_number) :
520                     page_frame_number;
521
522                 edac_mc_scrub_block(remapped_page, offset_in_page,
523                                         mci->csrows[row].grain);
524         }
525 }
526 EXPORT_SYMBOL_GPL(edac_mc_handle_ce);
527
528 void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci, const char *msg)
529 {
530         if (edac_get_log_ce())
531                 edac_mc_printk(mci, KERN_WARNING,
532                         "CE - no information available: %s\n", msg);
533
534         mci->ce_noinfo_count++;
535         mci->ce_count++;
536 }
537 EXPORT_SYMBOL_GPL(edac_mc_handle_ce_no_info);
538
539 void edac_mc_handle_ue(struct mem_ctl_info *mci,
540                 unsigned long page_frame_number, unsigned long offset_in_page,
541                 int row, const char *msg)
542 {
543         int len = EDAC_MC_LABEL_LEN * 4;
544         char labels[len + 1];
545         char *pos = labels;
546         int chan;
547         int chars;
548
549         debugf3("MC%d: %s()\n", mci->mc_idx, __func__);
550
551         /* FIXME - maybe make panic on INTERNAL ERROR an option */
552         if (row >= mci->nr_csrows || row < 0) {
553                 /* something is wrong */
554                 edac_mc_printk(mci, KERN_ERR,
555                         "INTERNAL ERROR: row out of range "
556                         "(%d >= %d)\n", row, mci->nr_csrows);
557                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
558                 return;
559         }
560
561         chars = snprintf(pos, len + 1, "%s",
562                         mci->csrows[row].channels[0].label);
563         len -= chars;
564         pos += chars;
565
566         for (chan = 1; (chan < mci->csrows[row].nr_channels) && (len > 0);
567              chan++) {
568                 chars = snprintf(pos, len + 1, ":%s",
569                                 mci->csrows[row].channels[chan].label);
570                 len -= chars;
571                 pos += chars;
572         }
573
574         if (edac_get_log_ue())
575                 edac_mc_printk(mci, KERN_EMERG,
576                         "UE page 0x%lx, offset 0x%lx, grain %d, row %d, "
577                         "labels \"%s\": %s\n", page_frame_number,
578                         offset_in_page, mci->csrows[row].grain, row, labels,
579                         msg);
580
581         if (edac_get_panic_on_ue())
582                 panic("EDAC MC%d: UE page 0x%lx, offset 0x%lx, grain %d, "
583                         "row %d, labels \"%s\": %s\n", mci->mc_idx,
584                         page_frame_number, offset_in_page,
585                         mci->csrows[row].grain, row, labels, msg);
586
587         mci->ue_count++;
588         mci->csrows[row].ue_count++;
589 }
590 EXPORT_SYMBOL_GPL(edac_mc_handle_ue);
591
592 void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
593 {
594         if (edac_get_panic_on_ue())
595                 panic("EDAC MC%d: Uncorrected Error", mci->mc_idx);
596
597         if (edac_get_log_ue())
598                 edac_mc_printk(mci, KERN_WARNING,
599                         "UE - no information available: %s\n", msg);
600         mci->ue_noinfo_count++;
601         mci->ue_count++;
602 }
603 EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
604
605
606 /*************************************************************
607  * On Fully Buffered DIMM modules, this help function is
608  * called to process UE events
609  */
610 void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
611                                 unsigned int csrow,
612                                 unsigned int channela,
613                                 unsigned int channelb,
614                                 char *msg)
615 {
616         int len = EDAC_MC_LABEL_LEN * 4;
617         char labels[len + 1];
618         char *pos = labels;
619         int chars;
620
621         if (csrow >= mci->nr_csrows) {
622                 /* something is wrong */
623                 edac_mc_printk(mci, KERN_ERR,
624                         "INTERNAL ERROR: row out of range (%d >= %d)\n",
625                         csrow, mci->nr_csrows);
626                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
627                 return;
628         }
629
630         if (channela >= mci->csrows[csrow].nr_channels) {
631                 /* something is wrong */
632                 edac_mc_printk(mci, KERN_ERR,
633                         "INTERNAL ERROR: channel-a out of range "
634                         "(%d >= %d)\n",
635                         channela, mci->csrows[csrow].nr_channels);
636                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
637                 return;
638         }
639
640         if (channelb >= mci->csrows[csrow].nr_channels) {
641                 /* something is wrong */
642                 edac_mc_printk(mci, KERN_ERR,
643                         "INTERNAL ERROR: channel-b out of range "
644                         "(%d >= %d)\n",
645                         channelb, mci->csrows[csrow].nr_channels);
646                 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
647                 return;
648         }
649
650         mci->ue_count++;
651         mci->csrows[csrow].ue_count++;
652
653         /* Generate the DIMM labels from the specified channels */
654         chars = snprintf(pos, len + 1, "%s",
655                          mci->csrows[csrow].channels[channela].label);
656         len -= chars; pos += chars;
657         chars = snprintf(pos, len + 1, "-%s",
658                          mci->csrows[csrow].channels[channelb].label);
659
660         if (edac_get_log_ue())
661                 edac_mc_printk(mci, KERN_EMERG,
662                         "UE row %d, channel-a= %d channel-b= %d "
663                         "labels \"%s\": %s\n", csrow, channela, channelb,
664                         labels, msg);
665
666         if (edac_get_panic_on_ue())
667                 panic("UE row %d, channel-a= %d channel-b= %d "
668                                 "labels \"%s\": %s\n", csrow, channela,
669                                 channelb, labels, msg);
670 }
671 EXPORT_SYMBOL(edac_mc_handle_fbd_ue);
672
673 /*************************************************************
674  * On Fully Buffered DIMM modules, this help function is
675  * called to process CE events
676  */
677 void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
678                            unsigned int csrow,
679                            unsigned int channel,
680                            char *msg)
681 {
682
683         /* Ensure boundary values */
684         if (csrow >= mci->nr_csrows) {
685                 /* something is wrong */
686                 edac_mc_printk(mci, KERN_ERR,
687                         "INTERNAL ERROR: row out of range (%d >= %d)\n",
688                         csrow, mci->nr_csrows);
689                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
690                 return;
691         }
692         if (channel >= mci->csrows[csrow].nr_channels) {
693                 /* something is wrong */
694                 edac_mc_printk(mci, KERN_ERR,
695                         "INTERNAL ERROR: channel out of range (%d >= %d)\n",
696                         channel, mci->csrows[csrow].nr_channels);
697                 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
698                 return;
699         }
700
701         if (edac_get_log_ce())
702                 /* FIXME - put in DIMM location */
703                 edac_mc_printk(mci, KERN_WARNING,
704                         "CE row %d, channel %d, label \"%s\": %s\n",
705                         csrow, channel,
706                         mci->csrows[csrow].channels[channel].label,
707                         msg);
708
709         mci->ce_count++;
710         mci->csrows[csrow].ce_count++;
711         mci->csrows[csrow].channels[channel].ce_count++;
712 }
713 EXPORT_SYMBOL(edac_mc_handle_fbd_ce);
714
715
716 /*
717  * Iterate over all MC instances and check for ECC, et al, errors
718  */
719 void edac_check_mc_devices(void)
720 {
721         struct list_head *item;
722         struct mem_ctl_info *mci;
723
724         debugf3("%s()\n", __func__);
725         down(&mem_ctls_mutex);
726
727         list_for_each(item, &mc_devices) {
728                 mci = list_entry(item, struct mem_ctl_info, link);
729
730                 if (mci->edac_check != NULL)
731                         mci->edac_check(mci);
732         }
733
734         up(&mem_ctls_mutex);
735 }